@jaromil/gestalt 0.20.2 → 0.20.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,6 +81,12 @@ Use `gestalt cli --skill-profile NAME` to select a saved profile directly or
81
81
  `gestalt cli --no-skill-profile` to use the native Codex selection. Piped and
82
82
  administrative commands run without the picker.
83
83
 
84
+ Use `gestalt cli --cwd DIR` to open the picker and start Codex in that workspace.
85
+ On Unix, loading profiles removes group and other write permission from the
86
+ user's own `~/.gestalt` and `~/.gestalt/skill-profiles` directories when needed.
87
+ `gestalt doctor` reports the offending path and mode without changing either
88
+ directory. A custom `GESTALT_HOME` requires manual permission changes.
89
+
84
90
  Update the npm-installed command with:
85
91
 
86
92
  ```sh
package/lib/gestalt.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // GESTALT_CLI_VERSION='0.20.2'
2
+ // GESTALT_CLI_VERSION='0.20.4'
3
3
  // GESTALT_UPDATED_MANAGER_API='1'
4
4
  /*! tuiuiu.js
5
5
  MIT License
@@ -1155,11 +1155,11 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1155
1155
  }
1156
1156
  function scratchWorkspacePublication(workspace, publish) {
1157
1157
  scratchStableNamespace(workspace);
1158
- const path31 = scratchPath.join(workspace, ".gestalt-scratch-lock");
1158
+ const path32 = scratchPath.join(workspace, ".gestalt-scratch-lock");
1159
1159
  let claimed = false;
1160
1160
  for (let attempt = 0; attempt < 100; attempt++) {
1161
1161
  try {
1162
- scratchFs.mkdirSync(path31, { mode: 448 });
1162
+ scratchFs.mkdirSync(path32, { mode: 448 });
1163
1163
  claimed = true;
1164
1164
  break;
1165
1165
  } catch (error) {
@@ -1168,8 +1168,8 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1168
1168
  }
1169
1169
  }
1170
1170
  if (!claimed) throw Error("SESSION_SCRATCH_BUSY");
1171
- scratchPrivate(path31);
1172
- const fd = scratchOpenDirectory(path31);
1171
+ scratchPrivate(path32);
1172
+ const fd = scratchOpenDirectory(path32);
1173
1173
  const held = scratchDirectoryStat(fd);
1174
1174
  try {
1175
1175
  const parents = scratchManagedAncestors(workspace).map((ancestor) => ancestor.context.workspacePath);
@@ -1179,9 +1179,9 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1179
1179
  return result;
1180
1180
  } finally {
1181
1181
  try {
1182
- const current = scratchFs.lstatSync(path31, { bigint: true });
1182
+ const current = scratchFs.lstatSync(path32, { bigint: true });
1183
1183
  scratchAssert(current.isDirectory() && !current.isSymbolicLink() && current.dev === held.dev && current.ino === held.ino && current.birthtimeNs === held.birthtimeNs);
1184
- scratchFs.rmdirSync(path31);
1184
+ scratchFs.rmdirSync(path32);
1185
1185
  } finally {
1186
1186
  scratchCloseDirectory(fd);
1187
1187
  }
@@ -1373,10 +1373,10 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1373
1373
  const context = scratchOwnerContext(workspace, ownerId);
1374
1374
  const ancestor = scratchAncestorOwner(context);
1375
1375
  scratchAssert(scratchJson3(context.markerPath).ownerKind === "mobile-session");
1376
- const path31 = scratchPath.join(context.directory, ".containment-lock");
1377
- const expected = scratchDirectoryIdentity(path31);
1378
- scratchPrivate(path31);
1379
- scratchAssert(scratchFs.readdirSync(path31).length === 0);
1376
+ const path32 = scratchPath.join(context.directory, ".containment-lock");
1377
+ const expected = scratchDirectoryIdentity(path32);
1378
+ scratchPrivate(path32);
1379
+ scratchAssert(scratchFs.readdirSync(path32).length === 0);
1380
1380
  for (const name2 of [".controller-lock", ".association-lock"]) {
1381
1381
  try {
1382
1382
  scratchFs.lstatSync(scratchPath.join(context.directory, name2));
@@ -1393,7 +1393,7 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1393
1393
  leases: scratchFs.existsSync(scratchPath.join(context.directory, "leases")) ? scratchLeaseRecords(context).sort((left, right) => left.leaseId.localeCompare(right.leaseId)) : [],
1394
1394
  lockIdentity: expected
1395
1395
  }, (_, value) => typeof value === "bigint" ? value.toString() : value)).digest("hex");
1396
- return { context, ancestor, path: path31, expected, token };
1396
+ return { context, ancestor, path: path32, expected, token };
1397
1397
  }
1398
1398
  function scratchRecoverContainment(workspace, ownerId, token) {
1399
1399
  scratchAssert(typeof token === "string" && /^[a-f0-9]{64}$/.test(token));
@@ -1430,8 +1430,8 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1430
1430
  const leases = scratchLeaseRecords(context).sort((a, b) => a.leaseId.localeCompare(b.leaseId));
1431
1431
  const active = leases.filter((lease) => lease.state === "active");
1432
1432
  scratchAssert(active.length > 0 && active.every((lease) => lease.consumers.length === 1 && ["serena-mcp", "playwright-mcp"].includes(lease.consumers[0])));
1433
- const fileIdentity = (path31) => {
1434
- const info = scratchFs.lstatSync(path31, { bigint: true });
1433
+ const fileIdentity = (path32) => {
1434
+ const info = scratchFs.lstatSync(path32, { bigint: true });
1435
1435
  return { dev: info.dev, ino: info.ino, birth: info.birthtimeNs };
1436
1436
  };
1437
1437
  const token = scratchCrypto.createHash("sha256").update(JSON.stringify({
@@ -1460,10 +1460,10 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1460
1460
  }
1461
1461
  function scratchPublicationSnapshot(workspace) {
1462
1462
  scratchCanonical(workspace);
1463
- const path31 = scratchPath.join(workspace, ".gestalt-scratch-lock");
1464
- scratchPrivate(path31);
1465
- scratchAssert(scratchFs.readdirSync(path31).length === 0);
1466
- const expected = scratchDirectoryIdentity(path31);
1463
+ const path32 = scratchPath.join(workspace, ".gestalt-scratch-lock");
1464
+ scratchPrivate(path32);
1465
+ scratchAssert(scratchFs.readdirSync(path32).length === 0);
1466
+ const expected = scratchDirectoryIdentity(path32);
1467
1467
  const token = scratchCrypto.createHash("sha256").update(JSON.stringify({
1468
1468
  workspace: scratchDirectoryIdentity(workspace),
1469
1469
  lock: expected,
@@ -1473,7 +1473,7 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1473
1473
  leases: scratchFs.existsSync(scratchPath.join(ancestor.context.directory, "leases")) ? scratchLeaseRecords(ancestor.context).sort((a, b) => a.leaseId.localeCompare(b.leaseId)) : []
1474
1474
  }))
1475
1475
  }, (_, value) => typeof value === "bigint" ? value.toString() : value)).digest("hex");
1476
- return { path: path31, expected, token };
1476
+ return { path: path32, expected, token };
1477
1477
  }
1478
1478
  function scratchRecoverPublication(workspace, token) {
1479
1479
  scratchAssert(typeof token === "string" && /^[a-f0-9]{64}$/.test(token));
@@ -1539,17 +1539,17 @@ function createScratchOwner(privateProbe = scratchPath.join(scratchPath.dirname(
1539
1539
  const selected = scratchDirectoryIdentity(workspace), ancestors = scratchManagedAncestors(workspace), claims = [];
1540
1540
  try {
1541
1541
  for (const ancestor of ancestors) {
1542
- const path31 = scratchPath.join(ancestor.context.directory, ".containment-lock");
1542
+ const path32 = scratchPath.join(ancestor.context.directory, ".containment-lock");
1543
1543
  try {
1544
- scratchFs.mkdirSync(path31, { mode: 448 });
1544
+ scratchFs.mkdirSync(path32, { mode: 448 });
1545
1545
  } catch (error) {
1546
1546
  if (error.code === "EEXIST") throw new Error("SESSION_SCRATCH_CONTAINMENT_BUSY");
1547
1547
  throw error;
1548
1548
  }
1549
- const claim = { path: path31, identity: scratchDirectoryIdentity(path31), fd: void 0 };
1549
+ const claim = { path: path32, identity: scratchDirectoryIdentity(path32), fd: void 0 };
1550
1550
  claims.push(claim);
1551
- scratchPrivate(path31);
1552
- claim.fd = scratchOpenDirectory(path31);
1551
+ scratchPrivate(path32);
1552
+ claim.fd = scratchOpenDirectory(path32);
1553
1553
  const held = scratchDirectoryStat(claim.fd);
1554
1554
  scratchAssert(scratchSameDirectory(claim.identity, { dev: held.dev, ino: held.ino, birth: held.birthtimeNs }));
1555
1555
  scratchRevalidateAncestor(ancestor);
@@ -2818,8 +2818,44 @@ var init_child = __esm({
2818
2818
  }
2819
2819
  });
2820
2820
 
2821
- // src/cli/skill-profiles/model.ts
2821
+ // src/cli/skill-profiles/directories.ts
2822
+ import { constants as constants6 } from "node:fs";
2823
+ import { open as open5 } from "node:fs/promises";
2822
2824
  import path26 from "node:path";
2825
+ async function checkSkillProfileDirectories(gestaltHome, repairOwnedModes = false) {
2826
+ for (const directory of [gestaltHome, path26.join(gestaltHome, "skill-profiles")]) {
2827
+ const info = await optionalStat(directory);
2828
+ if (!info) continue;
2829
+ if (info.isSymbolicLink()) throw new Error(`Skill profiles require a directory, but ${directory} is a symbolic link.`);
2830
+ if (!info.isDirectory()) throw new Error(`Skill profiles require a directory at ${directory}.`);
2831
+ if (!process.getuid) continue;
2832
+ const uid = process.getuid();
2833
+ if (info.uid !== uid) throw new Error(`Skill profile directory ${directory} is owned by UID ${info.uid}, expected UID ${uid}.`);
2834
+ if (!(info.mode & 18)) continue;
2835
+ const mode = (info.mode & 4095).toString(8);
2836
+ const diagnostic = `Skill profile directory ${directory} has mode ${mode}. Remove group and other write access with chmod go-w on this directory.`;
2837
+ if (!repairOwnedModes) throw new Error(diagnostic);
2838
+ const handle = await open5(directory, constants6.O_RDONLY | constants6.O_DIRECTORY | constants6.O_NOFOLLOW);
2839
+ try {
2840
+ const current = await handle.stat();
2841
+ if (current.dev !== info.dev || current.ino !== info.ino || current.uid !== uid)
2842
+ throw new Error(`Skill profile directory changed during startup: ${directory}`);
2843
+ await handle.chmod(current.mode & 4095 & ~18);
2844
+ const checked = await optionalStat(directory);
2845
+ if (!checked || checked.ino !== current.ino || checked.dev !== current.dev || checked.uid !== uid || checked.mode & 18) throw new Error(diagnostic);
2846
+ } finally {
2847
+ await handle.close();
2848
+ }
2849
+ }
2850
+ }
2851
+ var init_directories = __esm({
2852
+ "src/cli/skill-profiles/directories.ts"() {
2853
+ init_context();
2854
+ }
2855
+ });
2856
+
2857
+ // src/cli/skill-profiles/model.ts
2858
+ import path27 from "node:path";
2823
2859
  function profileName2(value) {
2824
2860
  const name2 = value.trim().toLowerCase().replace(/[\s_]+/g, "-");
2825
2861
  if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(name2) || process.platform === "win32" && /^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])$/.test(name2))
@@ -2827,19 +2863,19 @@ function profileName2(value) {
2827
2863
  return name2;
2828
2864
  }
2829
2865
  function skillKey(value) {
2830
- return process.platform === "win32" ? path26.win32.normalize(value).toLowerCase() : path26.normalize(value);
2866
+ return process.platform === "win32" ? path27.win32.normalize(value).toLowerCase() : path27.normalize(value);
2831
2867
  }
2832
2868
  function durableKey(value) {
2833
- const components = skillKey(value).split(path26.sep);
2869
+ const components = skillKey(value).split(path27.sep);
2834
2870
  const index = components.lastIndexOf("plugins");
2835
2871
  if (index < 0 || components[index + 1] !== "cache" || components[index + 5] !== "skills") return;
2836
- return [...components.slice(0, index + 4), ...components.slice(index + 5)].join(path26.sep);
2872
+ return [...components.slice(0, index + 4), ...components.slice(index + 5)].join(path27.sep);
2837
2873
  }
2838
2874
  function record(value) {
2839
2875
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
2840
2876
  }
2841
2877
  function validSkillPath(value) {
2842
- return typeof value === "string" && path26.isAbsolute(value) && path26.normalize(value) === value && !/[\x00-\x1f\x7f]/.test(value);
2878
+ return typeof value === "string" && path27.isAbsolute(value) && path27.normalize(value) === value && !/[\x00-\x1f\x7f]/.test(value);
2843
2879
  }
2844
2880
  function decodeProfile(value) {
2845
2881
  const input = record(value);
@@ -2873,7 +2909,7 @@ function profileDocument(profile) {
2873
2909
  return {
2874
2910
  version: profile.browser === void 0 ? 1 : 2,
2875
2911
  name: profile.name,
2876
- skills: profile.skills.map(({ path: path31, name: name2, enabled }) => ({ name: name2, path: path31, enabled })),
2912
+ skills: profile.skills.map(({ path: path32, name: name2, enabled }) => ({ name: name2, path: path32, enabled })),
2877
2913
  ...profile.browser === void 0 ? {} : { capabilities: { playwright: { enabled: profile.browser } } }
2878
2914
  };
2879
2915
  }
@@ -2905,7 +2941,7 @@ function profileSkillRules(catalog, selection) {
2905
2941
  if (selection === void 0) return { rules: catalog.map((skill) => ({ path: skill.path, enabled: mandatory(skill) })), missing: [] };
2906
2942
  const { skills, missing } = reconcileSkills(catalog, selection);
2907
2943
  const fixed = catalog.filter(mandatory);
2908
- const rules = [...skills.map(({ path: path31, enabled }) => ({ path: path31, enabled })), ...fixed.map(({ path: path31 }) => ({ path: path31, enabled: true }))];
2944
+ const rules = [...skills.map(({ path: path32, enabled }) => ({ path: path32, enabled })), ...fixed.map(({ path: path32 }) => ({ path: path32, enabled: true }))];
2909
2945
  return { rules, missing };
2910
2946
  }
2911
2947
  var managedSkill;
@@ -2919,7 +2955,7 @@ var init_model = __esm({
2919
2955
  import { spawn as spawn3 } from "node:child_process";
2920
2956
  import { createInterface as createInterface3 } from "node:readline";
2921
2957
  import { realpath as realpath11 } from "node:fs/promises";
2922
- import path27 from "node:path";
2958
+ import path28 from "node:path";
2923
2959
  function skillCatalog(result, cwd) {
2924
2960
  const data = record(result)?.data;
2925
2961
  const entry = Array.isArray(data) && data.map(record).find((item) => typeof item?.cwd === "string" && skillKey(item.cwd) === skillKey(cwd));
@@ -3019,10 +3055,10 @@ async function discoverSkills(invocation, streams, args) {
3019
3055
  if (await manageSkills(context, "status", "json") !== 0) return catalog;
3020
3056
  const status = record(JSON.parse(report));
3021
3057
  if (status?.verifiedSource !== true || typeof status.managedRoot !== "string") return catalog;
3022
- const root = path27.join(status.managedRoot, "skills");
3058
+ const root = path28.join(status.managedRoot, "skills");
3023
3059
  return { ...catalog, skills: await Promise.all(catalog.skills.map(async (skill) => {
3024
3060
  const actual = await realpath11(skill.path).catch(() => skill.path);
3025
- const parts = path27.relative(root, actual).split(path27.sep);
3061
+ const parts = path28.relative(root, actual).split(path28.sep);
3026
3062
  return { ...skill, verified: parts.length === 2 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(parts[0] ?? "") && parts[1] === "SKILL.md" };
3027
3063
  })) };
3028
3064
  }
@@ -3115,17 +3151,17 @@ var require_visit = __commonJS({
3115
3151
  visit.BREAK = BREAK;
3116
3152
  visit.SKIP = SKIP;
3117
3153
  visit.REMOVE = REMOVE;
3118
- function visit_(key, node, visitor, path31) {
3119
- const ctrl = callVisitor(key, node, visitor, path31);
3154
+ function visit_(key, node, visitor, path32) {
3155
+ const ctrl = callVisitor(key, node, visitor, path32);
3120
3156
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
3121
- replaceNode(key, path31, ctrl);
3122
- return visit_(key, ctrl, visitor, path31);
3157
+ replaceNode(key, path32, ctrl);
3158
+ return visit_(key, ctrl, visitor, path32);
3123
3159
  }
3124
3160
  if (typeof ctrl !== "symbol") {
3125
3161
  if (identity.isCollection(node)) {
3126
- path31 = Object.freeze(path31.concat(node));
3162
+ path32 = Object.freeze(path32.concat(node));
3127
3163
  for (let i = 0; i < node.items.length; ++i) {
3128
- const ci = visit_(i, node.items[i], visitor, path31);
3164
+ const ci = visit_(i, node.items[i], visitor, path32);
3129
3165
  if (typeof ci === "number")
3130
3166
  i = ci - 1;
3131
3167
  else if (ci === BREAK)
@@ -3136,13 +3172,13 @@ var require_visit = __commonJS({
3136
3172
  }
3137
3173
  }
3138
3174
  } else if (identity.isPair(node)) {
3139
- path31 = Object.freeze(path31.concat(node));
3140
- const ck = visit_("key", node.key, visitor, path31);
3175
+ path32 = Object.freeze(path32.concat(node));
3176
+ const ck = visit_("key", node.key, visitor, path32);
3141
3177
  if (ck === BREAK)
3142
3178
  return BREAK;
3143
3179
  else if (ck === REMOVE)
3144
3180
  node.key = null;
3145
- const cv = visit_("value", node.value, visitor, path31);
3181
+ const cv = visit_("value", node.value, visitor, path32);
3146
3182
  if (cv === BREAK)
3147
3183
  return BREAK;
3148
3184
  else if (cv === REMOVE)
@@ -3163,17 +3199,17 @@ var require_visit = __commonJS({
3163
3199
  visitAsync.BREAK = BREAK;
3164
3200
  visitAsync.SKIP = SKIP;
3165
3201
  visitAsync.REMOVE = REMOVE;
3166
- async function visitAsync_(key, node, visitor, path31) {
3167
- const ctrl = await callVisitor(key, node, visitor, path31);
3202
+ async function visitAsync_(key, node, visitor, path32) {
3203
+ const ctrl = await callVisitor(key, node, visitor, path32);
3168
3204
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
3169
- replaceNode(key, path31, ctrl);
3170
- return visitAsync_(key, ctrl, visitor, path31);
3205
+ replaceNode(key, path32, ctrl);
3206
+ return visitAsync_(key, ctrl, visitor, path32);
3171
3207
  }
3172
3208
  if (typeof ctrl !== "symbol") {
3173
3209
  if (identity.isCollection(node)) {
3174
- path31 = Object.freeze(path31.concat(node));
3210
+ path32 = Object.freeze(path32.concat(node));
3175
3211
  for (let i = 0; i < node.items.length; ++i) {
3176
- const ci = await visitAsync_(i, node.items[i], visitor, path31);
3212
+ const ci = await visitAsync_(i, node.items[i], visitor, path32);
3177
3213
  if (typeof ci === "number")
3178
3214
  i = ci - 1;
3179
3215
  else if (ci === BREAK)
@@ -3184,13 +3220,13 @@ var require_visit = __commonJS({
3184
3220
  }
3185
3221
  }
3186
3222
  } else if (identity.isPair(node)) {
3187
- path31 = Object.freeze(path31.concat(node));
3188
- const ck = await visitAsync_("key", node.key, visitor, path31);
3223
+ path32 = Object.freeze(path32.concat(node));
3224
+ const ck = await visitAsync_("key", node.key, visitor, path32);
3189
3225
  if (ck === BREAK)
3190
3226
  return BREAK;
3191
3227
  else if (ck === REMOVE)
3192
3228
  node.key = null;
3193
- const cv = await visitAsync_("value", node.value, visitor, path31);
3229
+ const cv = await visitAsync_("value", node.value, visitor, path32);
3194
3230
  if (cv === BREAK)
3195
3231
  return BREAK;
3196
3232
  else if (cv === REMOVE)
@@ -3217,23 +3253,23 @@ var require_visit = __commonJS({
3217
3253
  }
3218
3254
  return visitor;
3219
3255
  }
3220
- function callVisitor(key, node, visitor, path31) {
3256
+ function callVisitor(key, node, visitor, path32) {
3221
3257
  if (typeof visitor === "function")
3222
- return visitor(key, node, path31);
3258
+ return visitor(key, node, path32);
3223
3259
  if (identity.isMap(node))
3224
- return visitor.Map?.(key, node, path31);
3260
+ return visitor.Map?.(key, node, path32);
3225
3261
  if (identity.isSeq(node))
3226
- return visitor.Seq?.(key, node, path31);
3262
+ return visitor.Seq?.(key, node, path32);
3227
3263
  if (identity.isPair(node))
3228
- return visitor.Pair?.(key, node, path31);
3264
+ return visitor.Pair?.(key, node, path32);
3229
3265
  if (identity.isScalar(node))
3230
- return visitor.Scalar?.(key, node, path31);
3266
+ return visitor.Scalar?.(key, node, path32);
3231
3267
  if (identity.isAlias(node))
3232
- return visitor.Alias?.(key, node, path31);
3268
+ return visitor.Alias?.(key, node, path32);
3233
3269
  return void 0;
3234
3270
  }
3235
- function replaceNode(key, path31, node) {
3236
- const parent = path31[path31.length - 1];
3271
+ function replaceNode(key, path32, node) {
3272
+ const parent = path32[path32.length - 1];
3237
3273
  if (identity.isCollection(parent)) {
3238
3274
  parent.items[key] = node;
3239
3275
  } else if (identity.isPair(parent)) {
@@ -3843,10 +3879,10 @@ var require_Collection = __commonJS({
3843
3879
  var createNode = require_createNode();
3844
3880
  var identity = require_identity();
3845
3881
  var Node = require_Node();
3846
- function collectionFromPath(schema, path31, value) {
3882
+ function collectionFromPath(schema, path32, value) {
3847
3883
  let v = value;
3848
- for (let i = path31.length - 1; i >= 0; --i) {
3849
- const k = path31[i];
3884
+ for (let i = path32.length - 1; i >= 0; --i) {
3885
+ const k = path32[i];
3850
3886
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
3851
3887
  const a = [];
3852
3888
  a[k] = v;
@@ -3865,7 +3901,7 @@ var require_Collection = __commonJS({
3865
3901
  sourceObjects: /* @__PURE__ */ new Map()
3866
3902
  });
3867
3903
  }
3868
- var isEmptyPath = (path31) => path31 == null || typeof path31 === "object" && !!path31[Symbol.iterator]().next().done;
3904
+ var isEmptyPath = (path32) => path32 == null || typeof path32 === "object" && !!path32[Symbol.iterator]().next().done;
3869
3905
  var Collection = class extends Node.NodeBase {
3870
3906
  constructor(type, schema) {
3871
3907
  super(type);
@@ -3895,11 +3931,11 @@ var require_Collection = __commonJS({
3895
3931
  * be a Pair instance or a `{ key, value }` object, which may not have a key
3896
3932
  * that already exists in the map.
3897
3933
  */
3898
- addIn(path31, value) {
3899
- if (isEmptyPath(path31))
3934
+ addIn(path32, value) {
3935
+ if (isEmptyPath(path32))
3900
3936
  this.add(value);
3901
3937
  else {
3902
- const [key, ...rest] = path31;
3938
+ const [key, ...rest] = path32;
3903
3939
  const node = this.get(key, true);
3904
3940
  if (identity.isCollection(node))
3905
3941
  node.addIn(rest, value);
@@ -3913,8 +3949,8 @@ var require_Collection = __commonJS({
3913
3949
  * Removes a value from the collection.
3914
3950
  * @returns `true` if the item was found and removed.
3915
3951
  */
3916
- deleteIn(path31) {
3917
- const [key, ...rest] = path31;
3952
+ deleteIn(path32) {
3953
+ const [key, ...rest] = path32;
3918
3954
  if (rest.length === 0)
3919
3955
  return this.delete(key);
3920
3956
  const node = this.get(key, true);
@@ -3928,8 +3964,8 @@ var require_Collection = __commonJS({
3928
3964
  * scalar values from their surrounding node; to disable set `keepScalar` to
3929
3965
  * `true` (collections are always returned intact).
3930
3966
  */
3931
- getIn(path31, keepScalar) {
3932
- const [key, ...rest] = path31;
3967
+ getIn(path32, keepScalar) {
3968
+ const [key, ...rest] = path32;
3933
3969
  const node = this.get(key, true);
3934
3970
  if (rest.length === 0)
3935
3971
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -3947,8 +3983,8 @@ var require_Collection = __commonJS({
3947
3983
  /**
3948
3984
  * Checks if the collection includes a value with the key `key`.
3949
3985
  */
3950
- hasIn(path31) {
3951
- const [key, ...rest] = path31;
3986
+ hasIn(path32) {
3987
+ const [key, ...rest] = path32;
3952
3988
  if (rest.length === 0)
3953
3989
  return this.has(key);
3954
3990
  const node = this.get(key, true);
@@ -3958,8 +3994,8 @@ var require_Collection = __commonJS({
3958
3994
  * Sets a value in this collection. For `!!set`, `value` needs to be a
3959
3995
  * boolean to add/remove the item from the set.
3960
3996
  */
3961
- setIn(path31, value) {
3962
- const [key, ...rest] = path31;
3997
+ setIn(path32, value) {
3998
+ const [key, ...rest] = path32;
3963
3999
  if (rest.length === 0) {
3964
4000
  this.set(key, value);
3965
4001
  } else {
@@ -6474,9 +6510,9 @@ var require_Document = __commonJS({
6474
6510
  this.contents.add(value);
6475
6511
  }
6476
6512
  /** Adds a value to the document. */
6477
- addIn(path31, value) {
6513
+ addIn(path32, value) {
6478
6514
  if (assertCollection(this.contents))
6479
- this.contents.addIn(path31, value);
6515
+ this.contents.addIn(path32, value);
6480
6516
  }
6481
6517
  /**
6482
6518
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -6551,14 +6587,14 @@ var require_Document = __commonJS({
6551
6587
  * Removes a value from the document.
6552
6588
  * @returns `true` if the item was found and removed.
6553
6589
  */
6554
- deleteIn(path31) {
6555
- if (Collection.isEmptyPath(path31)) {
6590
+ deleteIn(path32) {
6591
+ if (Collection.isEmptyPath(path32)) {
6556
6592
  if (this.contents == null)
6557
6593
  return false;
6558
6594
  this.contents = null;
6559
6595
  return true;
6560
6596
  }
6561
- return assertCollection(this.contents) ? this.contents.deleteIn(path31) : false;
6597
+ return assertCollection(this.contents) ? this.contents.deleteIn(path32) : false;
6562
6598
  }
6563
6599
  /**
6564
6600
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -6573,10 +6609,10 @@ var require_Document = __commonJS({
6573
6609
  * scalar values from their surrounding node; to disable set `keepScalar` to
6574
6610
  * `true` (collections are always returned intact).
6575
6611
  */
6576
- getIn(path31, keepScalar) {
6577
- if (Collection.isEmptyPath(path31))
6612
+ getIn(path32, keepScalar) {
6613
+ if (Collection.isEmptyPath(path32))
6578
6614
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
6579
- return identity.isCollection(this.contents) ? this.contents.getIn(path31, keepScalar) : void 0;
6615
+ return identity.isCollection(this.contents) ? this.contents.getIn(path32, keepScalar) : void 0;
6580
6616
  }
6581
6617
  /**
6582
6618
  * Checks if the document includes a value with the key `key`.
@@ -6587,10 +6623,10 @@ var require_Document = __commonJS({
6587
6623
  /**
6588
6624
  * Checks if the document includes a value at `path`.
6589
6625
  */
6590
- hasIn(path31) {
6591
- if (Collection.isEmptyPath(path31))
6626
+ hasIn(path32) {
6627
+ if (Collection.isEmptyPath(path32))
6592
6628
  return this.contents !== void 0;
6593
- return identity.isCollection(this.contents) ? this.contents.hasIn(path31) : false;
6629
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path32) : false;
6594
6630
  }
6595
6631
  /**
6596
6632
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -6607,13 +6643,13 @@ var require_Document = __commonJS({
6607
6643
  * Sets a value in this document. For `!!set`, `value` needs to be a
6608
6644
  * boolean to add/remove the item from the set.
6609
6645
  */
6610
- setIn(path31, value) {
6611
- if (Collection.isEmptyPath(path31)) {
6646
+ setIn(path32, value) {
6647
+ if (Collection.isEmptyPath(path32)) {
6612
6648
  this.contents = value;
6613
6649
  } else if (this.contents == null) {
6614
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path31), value);
6650
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path32), value);
6615
6651
  } else if (assertCollection(this.contents)) {
6616
- this.contents.setIn(path31, value);
6652
+ this.contents.setIn(path32, value);
6617
6653
  }
6618
6654
  }
6619
6655
  /**
@@ -8573,9 +8609,9 @@ var require_cst_visit = __commonJS({
8573
8609
  visit.BREAK = BREAK;
8574
8610
  visit.SKIP = SKIP;
8575
8611
  visit.REMOVE = REMOVE;
8576
- visit.itemAtPath = (cst, path31) => {
8612
+ visit.itemAtPath = (cst, path32) => {
8577
8613
  let item = cst;
8578
- for (const [field2, index] of path31) {
8614
+ for (const [field2, index] of path32) {
8579
8615
  const tok = item?.[field2];
8580
8616
  if (tok && "items" in tok) {
8581
8617
  item = tok.items[index];
@@ -8584,23 +8620,23 @@ var require_cst_visit = __commonJS({
8584
8620
  }
8585
8621
  return item;
8586
8622
  };
8587
- visit.parentCollection = (cst, path31) => {
8588
- const parent = visit.itemAtPath(cst, path31.slice(0, -1));
8589
- const field2 = path31[path31.length - 1][0];
8623
+ visit.parentCollection = (cst, path32) => {
8624
+ const parent = visit.itemAtPath(cst, path32.slice(0, -1));
8625
+ const field2 = path32[path32.length - 1][0];
8590
8626
  const coll = parent?.[field2];
8591
8627
  if (coll && "items" in coll)
8592
8628
  return coll;
8593
8629
  throw new Error("Parent collection not found");
8594
8630
  };
8595
- function _visit(path31, item, visitor) {
8596
- let ctrl = visitor(item, path31);
8631
+ function _visit(path32, item, visitor) {
8632
+ let ctrl = visitor(item, path32);
8597
8633
  if (typeof ctrl === "symbol")
8598
8634
  return ctrl;
8599
8635
  for (const field2 of ["key", "value"]) {
8600
8636
  const token = item[field2];
8601
8637
  if (token && "items" in token) {
8602
8638
  for (let i = 0; i < token.items.length; ++i) {
8603
- const ci = _visit(Object.freeze(path31.concat([[field2, i]])), token.items[i], visitor);
8639
+ const ci = _visit(Object.freeze(path32.concat([[field2, i]])), token.items[i], visitor);
8604
8640
  if (typeof ci === "number")
8605
8641
  i = ci - 1;
8606
8642
  else if (ci === BREAK)
@@ -8611,10 +8647,10 @@ var require_cst_visit = __commonJS({
8611
8647
  }
8612
8648
  }
8613
8649
  if (typeof ctrl === "function" && field2 === "key")
8614
- ctrl = ctrl(item, path31);
8650
+ ctrl = ctrl(item, path32);
8615
8651
  }
8616
8652
  }
8617
- return typeof ctrl === "function" ? ctrl(item, path31) : ctrl;
8653
+ return typeof ctrl === "function" ? ctrl(item, path32) : ctrl;
8618
8654
  }
8619
8655
  exports.visit = visit;
8620
8656
  }
@@ -10385,26 +10421,27 @@ var init_yaml = __esm({
10385
10421
  // src/cli/skill-profiles/store.ts
10386
10422
  import { randomUUID as randomUUID10 } from "node:crypto";
10387
10423
  import { mkdir as mkdir7, readFile as readFile11, readdir as readdir3, rename as rename7, rm as rm6, writeFile as writeFile4 } from "node:fs/promises";
10388
- import path28 from "node:path";
10424
+ import path29 from "node:path";
10389
10425
  var FileSkillProfiles;
10390
10426
  var init_store = __esm({
10391
10427
  "src/cli/skill-profiles/store.ts"() {
10392
10428
  init_context();
10429
+ init_directories();
10393
10430
  init_model();
10394
10431
  init_yaml();
10395
10432
  FileSkillProfiles = class {
10433
+ root;
10434
+ context;
10396
10435
  constructor(context) {
10397
10436
  this.context = context;
10398
- this.root = path28.join(context.paths.gestaltHome, "skill-profiles");
10437
+ this.root = path29.join(context.paths.gestaltHome, "skill-profiles");
10399
10438
  }
10400
- context;
10401
- root;
10402
- async checkRoot() {
10403
- for (const directory of [this.context.paths.gestaltHome, this.root]) {
10404
- const info = await optionalStat(directory);
10405
- if (info && (!info.isDirectory() || info.isSymbolicLink() || process.getuid && (info.uid !== process.getuid() || (info.mode & 18) !== 0)))
10406
- throw new Error(`Skill profiles need an owned directory: ${directory}`);
10407
- }
10439
+ checkRoot() {
10440
+ const { gestaltHome, userHome } = this.context.paths;
10441
+ const defaultHome = path29.join(userHome, ".gestalt");
10442
+ const configuredHome = this.context.invocation.environment.GESTALT_HOME || defaultHome;
10443
+ const repair = gestaltHome === defaultHome && configuredHome === defaultHome;
10444
+ return checkSkillProfileDirectories(gestaltHome, repair);
10408
10445
  }
10409
10446
  /** Ignore missing documents, preserving parse failures as named diagnostics. */
10410
10447
  async read(file) {
@@ -10424,7 +10461,7 @@ var init_store = __esm({
10424
10461
  for (const file of files.sort()) {
10425
10462
  if (!file.endsWith(".yml") || file.startsWith(".")) continue;
10426
10463
  try {
10427
- const selected = await this.read(path28.join(this.root, file));
10464
+ const selected = await this.read(path29.join(this.root, file));
10428
10465
  if (!selected) continue;
10429
10466
  if (`${selected.name}.yml` !== file) throw new Error("Profile name differs from its filename.");
10430
10467
  profiles.push(selected);
@@ -10435,14 +10472,14 @@ var init_store = __esm({
10435
10472
  return { profiles, warnings };
10436
10473
  }
10437
10474
  async defaults(workspace) {
10438
- return this.read(path28.join(workspace, "gestalt-skills.yml"));
10475
+ return this.read(path29.join(workspace, "gestalt-skills.yml"));
10439
10476
  }
10440
10477
  /** Atomically replace the named profile without exposing a partially written YAML file. */
10441
10478
  async save(profile) {
10442
10479
  const bytes = Buffer.from(serializeProfileYaml(profile));
10443
10480
  if (bytes.length > 64 * 1024) throw new Error("The skill profile exceeds 64 KiB.");
10444
10481
  await this.checkRoot();
10445
- const file = path28.join(this.root, `${profileName2(profile.name)}.yml`);
10482
+ const file = path29.join(this.root, `${profileName2(profile.name)}.yml`);
10446
10483
  const previous = await optionalStat(file);
10447
10484
  if (previous && (!previous.isFile() || previous.nlink !== 1)) throw new Error("Refusing to overwrite a linked or special profile file.");
10448
10485
  if (process.platform === "win32") {
@@ -10453,7 +10490,7 @@ var init_store = __esm({
10453
10490
  }
10454
10491
  await mkdir7(this.root, { recursive: true, mode: 448 });
10455
10492
  await this.checkRoot();
10456
- const temporary = path28.join(this.root, `.profile-${randomUUID10()}.tmp`);
10493
+ const temporary = path29.join(this.root, `.profile-${randomUUID10()}.tmp`);
10457
10494
  await writeFile4(temporary, bytes, { flag: "wx", mode: 384 });
10458
10495
  try {
10459
10496
  await rename7(temporary, file);
@@ -10463,7 +10500,7 @@ var init_store = __esm({
10463
10500
  }
10464
10501
  async delete(name2) {
10465
10502
  await this.checkRoot();
10466
- const file = path28.join(this.root, `${profileName2(name2)}.yml`);
10503
+ const file = path29.join(this.root, `${profileName2(name2)}.yml`);
10467
10504
  const current = await optionalStat(file);
10468
10505
  if (!current) return false;
10469
10506
  if (!current.isFile() || current.nlink !== 1) throw new Error("Refusing to delete a linked or special profile file.");
@@ -10479,13 +10516,13 @@ var init_store = __esm({
10479
10516
  });
10480
10517
 
10481
10518
  // src/cli/skill-profiles/launch-options.ts
10482
- import path29 from "node:path";
10519
+ import path30 from "node:path";
10483
10520
  function skillLaunchOptions(input, cwd) {
10484
10521
  const args = input[0] === "--" ? input.slice(1) : input;
10485
10522
  const argv = [], discovery = [];
10486
10523
  let profile, skip = false, native = false, explicitSkills = false, position;
10487
10524
  for (let index = 0; index < args.length; index++) {
10488
- const argument = args[index];
10525
+ let argument = args[index];
10489
10526
  if (argument === "--") {
10490
10527
  argv.push(...args.slice(index));
10491
10528
  break;
@@ -10500,12 +10537,16 @@ function skillLaunchOptions(input, cwd) {
10500
10537
  if (!profile || profile.startsWith("-")) throw new Error("--skill-profile requires a saved profile name.");
10501
10538
  continue;
10502
10539
  }
10540
+ if (!position || !nativeCommands.has(position)) {
10541
+ if (argument === "--cwd") argument = "--cd";
10542
+ else if (argument.startsWith("--cwd=")) argument = "--cd=" + argument.slice("--cwd=".length);
10543
+ }
10503
10544
  const pair = ["-C", "--cd", "-p", "--profile", "-c", "--config", "--enable", "--disable"].includes(argument);
10504
10545
  const next = pair || valueFlags.has(argument) || argument === "--remote" ? args[++index] : void 0;
10505
10546
  argv.push(argument, ...next === void 0 ? [] : [next]);
10506
10547
  const option = (short, long) => argument === short || argument === long ? next : argument.startsWith(`${long}=`) ? argument.slice(long.length + 1) : argument.startsWith(short) && argument.length > short.length ? argument.slice(short.length) : void 0;
10507
10548
  const directory = option("-C", "--cd");
10508
- if (directory !== void 0) cwd = path29.resolve(cwd, directory);
10549
+ if (directory !== void 0) cwd = path30.resolve(cwd, directory);
10509
10550
  const codexProfile = option("-p", "--profile");
10510
10551
  if (codexProfile !== void 0) discovery.push("--profile", codexProfile);
10511
10552
  const config = option("-c", "--config");
@@ -14596,10 +14637,10 @@ var init_graphics = __esm({
14596
14637
  /**
14597
14638
  * Display image from file path (if accessible to terminal)
14598
14639
  */
14599
- displayFile(path31, options = {}) {
14640
+ displayFile(path32, options = {}) {
14600
14641
  const width = options.width ? `width=${options.width}` : "width=auto";
14601
14642
  const height = options.height ? `height=${options.height}` : "height=auto";
14602
- const encodedPath = Buffer.from(path31).toString("base64");
14643
+ const encodedPath = Buffer.from(path32).toString("base64");
14603
14644
  return `\x1B]1337;File=inline=1;${width};${height}:${encodedPath}\x07`;
14604
14645
  }
14605
14646
  };
@@ -15158,8 +15199,8 @@ function getCommonMistakeDocsPath(code) {
15158
15199
  return `docs/resources/common-mistakes.md#${getCommonMistake(code).anchor}`;
15159
15200
  }
15160
15201
  function getCommonMistakeReference(code) {
15161
- const path31 = getCommonMistakeDocsPath(code);
15162
- return `See ${path31} or tuiuiu://guide/common-mistakes.`;
15202
+ const path32 = getCommonMistakeDocsPath(code);
15203
+ return `See ${path32} or tuiuiu://guide/common-mistakes.`;
15163
15204
  }
15164
15205
  var commonMistakes;
15165
15206
  var init_common_mistakes = __esm({
@@ -15328,26 +15369,26 @@ Computed(() => {
15328
15369
  });
15329
15370
 
15330
15371
  // node_modules/tuiuiu.js/dist/core/dev-warnings.js
15331
- import path30 from "node:path";
15372
+ import path31 from "node:path";
15332
15373
  import { fileURLToPath as fileURLToPath5 } from "node:url";
15333
15374
  function isDevWarningEnabled() {
15334
15375
  return process.env.NODE_ENV !== "production";
15335
15376
  }
15336
15377
  function normalizeMaybeFileUrl(value) {
15337
15378
  if (value.startsWith("file://")) {
15338
- return path30.normalize(fileURLToPath5(value));
15379
+ return path31.normalize(fileURLToPath5(value));
15339
15380
  }
15340
- return path30.normalize(value);
15381
+ return path31.normalize(value);
15341
15382
  }
15342
15383
  function isInternalLibraryPath(filePath) {
15343
- const normalized = path30.normalize(filePath);
15384
+ const normalized = path31.normalize(filePath);
15344
15385
  if (!normalized.startsWith(packageRoot)) {
15345
15386
  return false;
15346
15387
  }
15347
- return normalized.includes(`${path30.sep}src${path30.sep}`) || normalized.includes(`${path30.sep}dist${path30.sep}`);
15388
+ return normalized.includes(`${path31.sep}src${path31.sep}`) || normalized.includes(`${path31.sep}dist${path31.sep}`);
15348
15389
  }
15349
15390
  function formatDisplayPath(site) {
15350
- const relative = path30.relative(process.cwd(), site.filePath);
15391
+ const relative = path31.relative(process.cwd(), site.filePath);
15351
15392
  const displayPath = relative && !relative.startsWith("..") ? relative : site.filePath;
15352
15393
  if (site.line === void 0) {
15353
15394
  return displayPath;
@@ -15423,9 +15464,9 @@ var init_dev_warnings = __esm({
15423
15464
  init_common_mistakes();
15424
15465
  init_context2();
15425
15466
  warnedKeys = /* @__PURE__ */ new Set();
15426
- currentFilePath = path30.normalize(fileURLToPath5(import.meta.url));
15427
- srcRoot = path30.dirname(path30.dirname(currentFilePath));
15428
- packageRoot = path30.dirname(srcRoot);
15467
+ currentFilePath = path31.normalize(fileURLToPath5(import.meta.url));
15468
+ srcRoot = path31.dirname(path31.dirname(currentFilePath));
15469
+ packageRoot = path31.dirname(srcRoot);
15429
15470
  signalCreationSuppressionDepth = 0;
15430
15471
  }
15431
15472
  });
@@ -36866,7 +36907,7 @@ function permissionConfiguration(source, homeReadRoots, temporaryRoot = "/tmp",
36866
36907
  'default_permissions = "workspace-git"'
36867
36908
  ];
36868
36909
  const writeRoots = /* @__PURE__ */ new Set([temporaryRoot, ...cacheRoots]);
36869
- for (const path31 of homeReadRoots) writeRoots.delete(path31);
36910
+ for (const path32 of homeReadRoots) writeRoots.delete(path32);
36870
36911
  const profile = [
36871
36912
  "[permissions.workspace-git]",
36872
36913
  'description = "Workspace and Git writable with local test support"',
@@ -36878,8 +36919,8 @@ function permissionConfiguration(source, homeReadRoots, temporaryRoot = "/tmp",
36878
36919
  "allow_local_binding = true",
36879
36920
  "",
36880
36921
  "[permissions.workspace-git.filesystem]",
36881
- ...[...writeRoots].map((path31) => `${JSON.stringify(path31)} = "write"`),
36882
- ...homeReadRoots.map((path31) => `${JSON.stringify(path31)} = "read"`),
36922
+ ...[...writeRoots].map((path32) => `${JSON.stringify(path32)} = "write"`),
36923
+ ...homeReadRoots.map((path32) => `${JSON.stringify(path32)} = "read"`),
36883
36924
  "",
36884
36925
  '[permissions.workspace-git.filesystem.":workspace_roots"]',
36885
36926
  '"." = "write"',
@@ -36898,27 +36939,27 @@ function approvalConfiguration(source, managerPath, codexHome) {
36898
36939
  const config = parse(source);
36899
36940
  const expected = managedMcpApprovals(config, { manager: managerPath, codexHome });
36900
36941
  const changes = [];
36901
- const changed = (before, after, path31 = []) => {
36942
+ const changed = (before, after, path32 = []) => {
36902
36943
  for (const [key, value] of Object.entries(after ?? {})) {
36903
- if (value && typeof value === "object" && !Array.isArray(value)) changed(before?.[key], value, [...path31, key]);
36904
- else if (JSON.stringify(before?.[key]) !== JSON.stringify(value) && ["default_tools_approval_mode", "approval_mode", "env_vars"].includes(key)) changes.push([...path31, key]);
36944
+ if (value && typeof value === "object" && !Array.isArray(value)) changed(before?.[key], value, [...path32, key]);
36945
+ else if (JSON.stringify(before?.[key]) !== JSON.stringify(value) && ["default_tools_approval_mode", "approval_mode", "env_vars"].includes(key)) changes.push([...path32, key]);
36905
36946
  }
36906
36947
  };
36907
36948
  changed(config, expected);
36908
36949
  if (!changes.length) return source;
36909
36950
  let output = source;
36910
36951
  for (const fullPath of changes) {
36911
- const path31 = fullPath.slice(0, -1), key = fullPath.at(-1);
36952
+ const path32 = fullPath.slice(0, -1), key = fullPath.at(-1);
36912
36953
  const value = fullPath.reduce((item, key2) => item[key2], expected);
36913
36954
  const rendered = stringify({ [key]: value }).trimEnd();
36914
- const header2 = "[" + path31.map((key2) => JSON.stringify(key2)).join(".") + "]";
36955
+ const header2 = "[" + path32.map((key2) => JSON.stringify(key2)).join(".") + "]";
36915
36956
  let inserted = false;
36916
36957
  output = output.split(/(?=^[ \t]*\[)/m).map((section) => {
36917
36958
  const line = section.split("\n")[0];
36918
36959
  if (inserted || line.trimStart().startsWith("[[")) return section;
36919
36960
  try {
36920
36961
  let table = parse(line + "\n__gestalt_marker = true");
36921
- for (const key2 of path31) table = table?.[key2];
36962
+ for (const key2 of path32) table = table?.[key2];
36922
36963
  if (table?.__gestalt_marker !== true) return section;
36923
36964
  inserted = true;
36924
36965
  const assignment = new RegExp("^[ \\t]*" + key + "[ \\t]*=[^\\n]*", "m");
@@ -37514,37 +37555,37 @@ import { isAbsolute } from "node:path";
37514
37555
  function retireManagedConfiguration(selectedCodex, selectedHome, manager) {
37515
37556
  const notices = /* @__PURE__ */ new Set();
37516
37557
  const notice = (kind) => notices.add(kind);
37517
- const exists = (path31) => {
37558
+ const exists = (path32) => {
37518
37559
  try {
37519
- return lstatSync2(path31);
37560
+ return lstatSync2(path32);
37520
37561
  } catch (error) {
37521
37562
  if (error.code === "ENOENT") return null;
37522
37563
  throw error;
37523
37564
  }
37524
37565
  };
37525
- const canonical = (path31) => {
37566
+ const canonical = (path32) => {
37526
37567
  try {
37527
- return realpathSync(path31);
37568
+ return realpathSync(path32);
37528
37569
  } catch {
37529
37570
  return null;
37530
37571
  }
37531
37572
  };
37532
37573
  const codex = canonical(selectedCodex), home = canonical(selectedHome), executable = canonical(manager);
37533
- const plain = (path31) => {
37534
- const info = exists(path31);
37574
+ const plain = (path32) => {
37575
+ const info = exists(path32);
37535
37576
  return info?.isFile() && info.nlink === 1 && (!process.getuid || info.uid === process.getuid()) ? info : null;
37536
37577
  };
37537
37578
  const owned = (server) => server && !server.url && typeof server.command === "string" && isAbsolute(server.command) && canonical(server.command) === executable && Array.isArray(server.args) && JSON.stringify(server.args) === '["xerj","mcp"]';
37538
37579
  const related = (name2, server) => /xerj/i.test(name2) || server?.args?.[0] === "xerj";
37539
37580
  const stable = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
37540
- function migrate(path31) {
37541
- if (!exists(path31)) return;
37542
- const info = plain(path31);
37581
+ function migrate(path32) {
37582
+ if (!exists(path32)) return;
37583
+ const info = plain(path32);
37543
37584
  if (!info) {
37544
37585
  notice("configuration");
37545
37586
  return;
37546
37587
  }
37547
- const bytes = readFileSync(path31, "utf8");
37588
+ const bytes = readFileSync(path32, "utf8");
37548
37589
  let config;
37549
37590
  try {
37550
37591
  config = parse(bytes);
@@ -37583,7 +37624,7 @@ function retireManagedConfiguration(selectedCodex, selectedHome, manager) {
37583
37624
  return;
37584
37625
  }
37585
37626
  if (bytes === output) return;
37586
- const temporary = join2(dirname(path31), ".gestalt-retirement-" + randomBytes2(12).toString("hex"));
37627
+ const temporary = join2(dirname(path32), ".gestalt-retirement-" + randomBytes2(12).toString("hex"));
37587
37628
  let handle;
37588
37629
  try {
37589
37630
  handle = openSync2(temporary, "wx", 384);
@@ -37592,10 +37633,10 @@ function retireManagedConfiguration(selectedCodex, selectedHome, manager) {
37592
37633
  fsyncSync(handle);
37593
37634
  closeSync2(handle);
37594
37635
  handle = void 0;
37595
- const current = plain(path31);
37596
- if (!current || current.dev !== info.dev || current.ino !== info.ino || readFileSync(path31, "utf8") !== bytes)
37636
+ const current = plain(path32);
37637
+ if (!current || current.dev !== info.dev || current.ino !== info.ino || readFileSync(path32, "utf8") !== bytes)
37597
37638
  throw new Error("configuration changed during Xerj retirement; retry update");
37598
- renameSync(temporary, path31);
37639
+ renameSync(temporary, path32);
37599
37640
  } finally {
37600
37641
  if (handle !== void 0) closeSync2(handle);
37601
37642
  try {
@@ -38513,7 +38554,7 @@ async function readArchive(file) {
38513
38554
  }
38514
38555
  var NativeArchives = class {
38515
38556
  async list(archive) {
38516
- return (await readArchive(archive)).map(({ path: path31, kind }) => ({ path: path31, kind }));
38557
+ return (await readArchive(archive)).map(({ path: path32, kind }) => ({ path: path32, kind }));
38517
38558
  }
38518
38559
  async extract(archive, stagingDirectory, expectedRoot) {
38519
38560
  const entries = await readArchive(archive), root = name(expectedRoot);
@@ -39475,12 +39516,12 @@ async function launchCapabilities(commands, invocation, manager) {
39475
39516
  const diagnoseSerena = (reason) => process2.stderr.write(`gestalt: serena unavailable (${reason}); continuing with native code tools
39476
39517
  `);
39477
39518
  const usableGuidance = async (entry) => {
39478
- const path31 = await realpath10(entry.path);
39479
- const manifest = JSON.parse(await readFile10(resolve(path31, "../../../.codex-plugin/plugin.json"), "utf8"));
39519
+ const path32 = await realpath10(entry.path);
39520
+ const manifest = JSON.parse(await readFile10(resolve(path32, "../../../.codex-plugin/plugin.json"), "utf8"));
39480
39521
  const nativeVersion = /(?:codex[^0-9]*)?0\.(\d+)\./.exec(state.version);
39481
39522
  if (manifest.name !== "gestalt" || manifest.skills !== "./skills/" || !nativeVersion || Number(nativeVersion[1]) < 160)
39482
39523
  throw new Error("incompatible-runtime");
39483
- return await readFile10(path31, "utf8");
39524
+ return await readFile10(path32, "utf8");
39484
39525
  };
39485
39526
  const common = state && !remote && state.config?.skills?.include_instructions !== false && state.config?.features?.hooks === true;
39486
39527
  const startupNotice = (reason) => process2.stderr.write(`gestalt: startup guidance unavailable (${reason}); retaining legacy instructions
@@ -39546,7 +39587,7 @@ async function launchCapabilities(commands, invocation, manager) {
39546
39587
  throw error;
39547
39588
  }
39548
39589
  for (const name2 of names.filter((name3) => name3.endsWith(".toml")).sort()) {
39549
- const path31 = resolve(folder, name2), text = await readFile10(path31, "utf8");
39590
+ const path32 = resolve(folder, name2), text = await readFile10(path32, "utf8");
39550
39591
  const role = parse(text);
39551
39592
  if (typeof role.name !== "string" || typeof role.developer_instructions !== "string") continue;
39552
39593
  let action = "append";
@@ -39556,7 +39597,7 @@ async function launchCapabilities(commands, invocation, manager) {
39556
39597
  } catch {
39557
39598
  action = "migration-required";
39558
39599
  }
39559
- const policy = { path: path31, digest: createHash4("sha256").update(text).digest("hex"), action };
39600
+ const policy = { path: path32, digest: createHash4("sha256").update(text).digest("hex"), action };
39560
39601
  rolePolicies[role.name] = rolePolicies[role.name] ? { action: "ambiguous-role" } : policy;
39561
39602
  }
39562
39603
  }
@@ -39853,6 +39894,8 @@ function selectInteractiveRuntime(artifacts) {
39853
39894
  }
39854
39895
 
39855
39896
  // src/cli/main.ts
39897
+ init_context();
39898
+ init_directories();
39856
39899
  var SESSION_SCRATCH_API_VERSION = 1;
39857
39900
  var UPDATED_MANAGER_API_VERSION = 1;
39858
39901
  var UPDATED_MANAGER_API_CAPABILITIES = ["host-filesystem-v1", "async-owned-commands-v1", "cancellation-v1"];
@@ -39862,7 +39905,7 @@ function packagedWindowsHelper() {
39862
39905
  async function continueUpdatedManager(invocation, streams, options) {
39863
39906
  if (options.commands?.apiVersion !== 1 || typeof options.commands.launch !== "function" || !options.signal || invocation.argv[0] !== "__updated-manager") throw new Error("invalid managed updated-manager handoff");
39864
39907
  let unknown = false;
39865
- const metadata = { version: "0.20.2", help: "Usage: gestalt <command> [options]\n\nManage Gestalt Agents and Gestalt Mobile in isolated, user-owned directories.\n\nCommands:\n install [--extra-skills] Install or reconcile Agents, optional skills, and Mobile.\n agents install, update Install or reconcile Agents and context-mode only.\n update [COMPONENT] [--extra-skills]\n Update all installed managed components (default).\n update-restart [COMPONENT] [--extra-skills]\n Update from a live Mobile session, then restart Mobile.\n cli [--] [args...] Start Codex with ~/.codex-gestalt as CODEX_HOME.\n mobile [--] [args...] Start the managed Gestalt Mobile executable.\n Workspace defaults to ~/gestalt; override with --cwd ROOT.\n mobile reset-passkeys --public-origin ORIGIN --confirm\n Reset the local Mobile passkeys and browser sessions for a new hostname.\n scratch inspect --cwd ROOT --owner ID\n Inspect an empty Mobile containment fence (read-only).\n scratch recover --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent\n Offline recovery after all owner processes have stopped.\n playwright install [VERSION] Install MCP; add missing system Chrome on Debian amd64.\n playwright update [VERSION] Stage, verify and activate an explicit package update.\n playwright version [--json] Read versioned installation metadata.\n playwright doctor [--json] [--launch] [--executable-path PATH] Check package and Chrome; optionally test a local page.\n playwright mcp --cwd ROOT Managed headless stdio (workspace profile).\n serena install Install private uv, Python 3.13 and tested Serena.\n serena update [VERSION] Validate and activate a release; retain prior tooling.\n serena version, -V Read installed package metadata without creating state.\n serena doctor [--cwd ROOT] Check install, sandbox, MCP tools and optional language readiness.\n serena index --cwd ROOT Explicit native symbol/cache warmup for one project.\n serena mcp --cwd ROOT Confined workspace MCP; always Codex context and editing mode.\n path [NAME|--json] Print managed executable and runtime paths.\n skills install, update Maintain the optional Dyne.org skill collection only.\n skills status [--json] Read installed version, revision and integrity.\n skills-export [ARCHIVE] Export installed skills and skill profiles.\n skills-import ARCHIVE Import a skills archive into this installation.\n doctor [--cwd ROOT] Check prerequisites and installation.\n version Print manager and detected component versions.\n help Show this help.\n\nUpdate components (also accepted as --component COMPONENT):\n all Gestalt core plus installed Serena and Playwright (default).\n gestalt Manager, Agents, Mobile, and context-mode runtime.\n serena Latest stable Serena and its private uv/Python tooling.\n playwright Stable Playwright MCP package; Chrome is externally maintained.\n\nOptional components absent from this installation are skipped by 'all'.\nSelecting serena or playwright explicitly installs or updates that component only.\n--extra-skills applies only to all or gestalt; it adds curated third-party skills.\nNode, npm, Codex, Kimi, and system language servers are externally maintained.\n\nEnvironment:\n CODEX_HOME Isolated Codex home (default: ~/.codex-gestalt).\n GESTALT_HOME Runtime and Mobile root (default: ~/.gestalt).\n GESTALT_INSTALL_BASE_URL Manager update source (default: https://dyne.github.io/gestalt).\n GESTALT_MARKETPLACE Marketplace source (default: dyne/gestalt-agents).\n GESTALT_MARKETPLACE_NAME Codex checkout name (default: dyne-gestalt-agents).\n GESTALT_MOBILE_VERSION npm version or tag (default: latest).\n GESTALT_SKILLS_SOURCE Collection source override (always unverified).\n GESTALT_SKILLS_REF Collection Git ref or immutable revision (default: main).\n" };
39908
+ const metadata = { version: "0.20.4", help: "Usage: gestalt <command> [options]\n\nManage Gestalt Agents and Gestalt Mobile in isolated, user-owned directories.\n\nCommands:\n install [--extra-skills] Install or reconcile Agents, optional skills, and Mobile.\n agents install, update Install or reconcile Agents and context-mode only.\n update [COMPONENT] [--extra-skills]\n Update all installed managed components (default).\n update-restart [COMPONENT] [--extra-skills]\n Update from a live Mobile session, then restart Mobile.\n cli [--] [args...] Start Codex with ~/.codex-gestalt as CODEX_HOME.\n mobile [--] [args...] Start the managed Gestalt Mobile executable.\n Workspace defaults to ~/gestalt; override with --cwd ROOT.\n mobile reset-passkeys --public-origin ORIGIN --confirm\n Reset the local Mobile passkeys and browser sessions for a new hostname.\n scratch inspect --cwd ROOT --owner ID\n Inspect an empty Mobile containment fence (read-only).\n scratch recover --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent\n Offline recovery after all owner processes have stopped.\n playwright install [VERSION] Install MCP; add missing system Chrome on Debian amd64.\n playwright update [VERSION] [--prune-offline]\n Reuse a matching release; prune older ones after browser shutdown.\n playwright version [--json] Read versioned installation metadata.\n playwright doctor [--json] [--launch] [--executable-path PATH] Check package and Chrome; optionally test a local page.\n playwright mcp --cwd ROOT Managed headless stdio (workspace profile).\n serena install Install private uv, Python 3.13 and tested Serena.\n serena update [VERSION] [--prune-offline]\n Update Serena; optionally remove inactive releases after shutdown.\n serena version, -V Read installed package metadata without creating state.\n serena doctor [--cwd ROOT] Check install, sandbox, MCP tools and optional language readiness.\n serena index --cwd ROOT Explicit native symbol/cache warmup for one project.\n serena mcp --cwd ROOT Confined workspace MCP; always Codex context and editing mode.\n path [NAME|--json] Print managed executable and runtime paths.\n skills install, update Maintain the optional Dyne.org skill collection only.\n skills status [--json] Read installed version, revision and integrity.\n skills-export [ARCHIVE] Export installed skills and skill profiles.\n skills-import ARCHIVE Import a skills archive into this installation.\n doctor [--cwd ROOT] Check prerequisites and installation.\n version Print manager and detected component versions.\n help Show this help.\n\nUpdate components (also accepted as --component COMPONENT):\n all Gestalt core plus installed Serena and Playwright (default).\n gestalt Manager, Agents, Mobile, and context-mode runtime.\n serena Latest stable Serena and its private uv/Python tooling.\n playwright Stable Playwright MCP package; Chrome is externally maintained.\n\nOptional components absent from this installation are skipped by 'all'.\nSelecting serena or playwright explicitly installs or updates that component only.\n--extra-skills applies only to all or gestalt; it adds curated third-party skills.\nNode, npm, Codex, Kimi, and system language servers are externally maintained.\n\nEnvironment:\n CODEX_HOME Isolated Codex home (default: ~/.codex-gestalt).\n GESTALT_HOME Runtime and Mobile root (default: ~/.gestalt).\n GESTALT_INSTALL_BASE_URL Manager update source (default: https://dyne.github.io/gestalt).\n GESTALT_MARKETPLACE Marketplace source (default: dyne/gestalt-agents).\n GESTALT_MARKETPLACE_NAME Codex checkout name (default: dyne-gestalt-agents).\n GESTALT_MOBILE_VERSION npm version or tag (default: latest).\n GESTALT_SKILLS_SOURCE Collection source override (always unverified).\n GESTALT_SKILLS_REF Collection Git ref or immutable revision (default: main).\n" };
39866
39909
  const status = await runCli(
39867
39910
  { argv: [...invocation.argv], cwd: invocation.cwd, environment: { ...invocation.environment } },
39868
39911
  streams,
@@ -39896,6 +39939,10 @@ async function main2() {
39896
39939
  let argv = process.argv.slice(2);
39897
39940
  const environment = { ...process.env };
39898
39941
  delete environment.GESTALT_LAUNCH_SKILL_RULES;
39942
+ if (subcommand === "doctor") {
39943
+ const paths2 = await setupPaths(environment);
39944
+ await checkSkillProfileDirectories(paths2.gestaltHome);
39945
+ }
39899
39946
  if (subcommand === "skill-profiles" || subcommand === "cli") {
39900
39947
  const { manageSkillProfiles: manageSkillProfiles2, prepareProfileLaunch: prepareProfileLaunch2 } = await Promise.resolve().then(() => (init_commands2(), commands_exports));
39901
39948
  const request = { argv: argv.slice(1), cwd: process.cwd(), environment };
@@ -39909,7 +39956,7 @@ async function main2() {
39909
39956
  const selected = selectInteractiveRuntime({ legacyManager: fileURLToPath7(new URL("./legacy/gestalt", import.meta.url)) });
39910
39957
  if (selected.kind === "unix-compatibility") selected.exec({ argv, cwd: process.cwd(), environment });
39911
39958
  }
39912
- const metadata = { version: "0.20.2", help: "Usage: gestalt <command> [options]\n\nManage Gestalt Agents and Gestalt Mobile in isolated, user-owned directories.\n\nCommands:\n install [--extra-skills] Install or reconcile Agents, optional skills, and Mobile.\n agents install, update Install or reconcile Agents and context-mode only.\n update [COMPONENT] [--extra-skills]\n Update all installed managed components (default).\n update-restart [COMPONENT] [--extra-skills]\n Update from a live Mobile session, then restart Mobile.\n cli [--] [args...] Start Codex with ~/.codex-gestalt as CODEX_HOME.\n mobile [--] [args...] Start the managed Gestalt Mobile executable.\n Workspace defaults to ~/gestalt; override with --cwd ROOT.\n mobile reset-passkeys --public-origin ORIGIN --confirm\n Reset the local Mobile passkeys and browser sessions for a new hostname.\n scratch inspect --cwd ROOT --owner ID\n Inspect an empty Mobile containment fence (read-only).\n scratch recover --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent\n Offline recovery after all owner processes have stopped.\n playwright install [VERSION] Install MCP; add missing system Chrome on Debian amd64.\n playwright update [VERSION] Stage, verify and activate an explicit package update.\n playwright version [--json] Read versioned installation metadata.\n playwright doctor [--json] [--launch] [--executable-path PATH] Check package and Chrome; optionally test a local page.\n playwright mcp --cwd ROOT Managed headless stdio (workspace profile).\n serena install Install private uv, Python 3.13 and tested Serena.\n serena update [VERSION] Validate and activate a release; retain prior tooling.\n serena version, -V Read installed package metadata without creating state.\n serena doctor [--cwd ROOT] Check install, sandbox, MCP tools and optional language readiness.\n serena index --cwd ROOT Explicit native symbol/cache warmup for one project.\n serena mcp --cwd ROOT Confined workspace MCP; always Codex context and editing mode.\n path [NAME|--json] Print managed executable and runtime paths.\n skills install, update Maintain the optional Dyne.org skill collection only.\n skills status [--json] Read installed version, revision and integrity.\n skills-export [ARCHIVE] Export installed skills and skill profiles.\n skills-import ARCHIVE Import a skills archive into this installation.\n doctor [--cwd ROOT] Check prerequisites and installation.\n version Print manager and detected component versions.\n help Show this help.\n\nUpdate components (also accepted as --component COMPONENT):\n all Gestalt core plus installed Serena and Playwright (default).\n gestalt Manager, Agents, Mobile, and context-mode runtime.\n serena Latest stable Serena and its private uv/Python tooling.\n playwright Stable Playwright MCP package; Chrome is externally maintained.\n\nOptional components absent from this installation are skipped by 'all'.\nSelecting serena or playwright explicitly installs or updates that component only.\n--extra-skills applies only to all or gestalt; it adds curated third-party skills.\nNode, npm, Codex, Kimi, and system language servers are externally maintained.\n\nEnvironment:\n CODEX_HOME Isolated Codex home (default: ~/.codex-gestalt).\n GESTALT_HOME Runtime and Mobile root (default: ~/.gestalt).\n GESTALT_INSTALL_BASE_URL Manager update source (default: https://dyne.github.io/gestalt).\n GESTALT_MARKETPLACE Marketplace source (default: dyne/gestalt-agents).\n GESTALT_MARKETPLACE_NAME Codex checkout name (default: dyne-gestalt-agents).\n GESTALT_MOBILE_VERSION npm version or tag (default: latest).\n GESTALT_SKILLS_SOURCE Collection source override (always unverified).\n GESTALT_SKILLS_REF Collection Git ref or immutable revision (default: main).\n" };
39959
+ const metadata = { version: "0.20.4", help: "Usage: gestalt <command> [options]\n\nManage Gestalt Agents and Gestalt Mobile in isolated, user-owned directories.\n\nCommands:\n install [--extra-skills] Install or reconcile Agents, optional skills, and Mobile.\n agents install, update Install or reconcile Agents and context-mode only.\n update [COMPONENT] [--extra-skills]\n Update all installed managed components (default).\n update-restart [COMPONENT] [--extra-skills]\n Update from a live Mobile session, then restart Mobile.\n cli [--] [args...] Start Codex with ~/.codex-gestalt as CODEX_HOME.\n mobile [--] [args...] Start the managed Gestalt Mobile executable.\n Workspace defaults to ~/gestalt; override with --cwd ROOT.\n mobile reset-passkeys --public-origin ORIGIN --confirm\n Reset the local Mobile passkeys and browser sessions for a new hostname.\n scratch inspect --cwd ROOT --owner ID\n Inspect an empty Mobile containment fence (read-only).\n scratch recover --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent\n Offline recovery after all owner processes have stopped.\n playwright install [VERSION] Install MCP; add missing system Chrome on Debian amd64.\n playwright update [VERSION] [--prune-offline]\n Reuse a matching release; prune older ones after browser shutdown.\n playwright version [--json] Read versioned installation metadata.\n playwright doctor [--json] [--launch] [--executable-path PATH] Check package and Chrome; optionally test a local page.\n playwright mcp --cwd ROOT Managed headless stdio (workspace profile).\n serena install Install private uv, Python 3.13 and tested Serena.\n serena update [VERSION] [--prune-offline]\n Update Serena; optionally remove inactive releases after shutdown.\n serena version, -V Read installed package metadata without creating state.\n serena doctor [--cwd ROOT] Check install, sandbox, MCP tools and optional language readiness.\n serena index --cwd ROOT Explicit native symbol/cache warmup for one project.\n serena mcp --cwd ROOT Confined workspace MCP; always Codex context and editing mode.\n path [NAME|--json] Print managed executable and runtime paths.\n skills install, update Maintain the optional Dyne.org skill collection only.\n skills status [--json] Read installed version, revision and integrity.\n skills-export [ARCHIVE] Export installed skills and skill profiles.\n skills-import ARCHIVE Import a skills archive into this installation.\n doctor [--cwd ROOT] Check prerequisites and installation.\n version Print manager and detected component versions.\n help Show this help.\n\nUpdate components (also accepted as --component COMPONENT):\n all Gestalt core plus installed Serena and Playwright (default).\n gestalt Manager, Agents, Mobile, and context-mode runtime.\n serena Latest stable Serena and its private uv/Python tooling.\n playwright Stable Playwright MCP package; Chrome is externally maintained.\n\nOptional components absent from this installation are skipped by 'all'.\nSelecting serena or playwright explicitly installs or updates that component only.\n--extra-skills applies only to all or gestalt; it adds curated third-party skills.\nNode, npm, Codex, Kimi, and system language servers are externally maintained.\n\nEnvironment:\n CODEX_HOME Isolated Codex home (default: ~/.codex-gestalt).\n GESTALT_HOME Runtime and Mobile root (default: ~/.gestalt).\n GESTALT_INSTALL_BASE_URL Manager update source (default: https://dyne.github.io/gestalt).\n GESTALT_MARKETPLACE Marketplace source (default: dyne/gestalt-agents).\n GESTALT_MARKETPLACE_NAME Codex checkout name (default: dyne-gestalt-agents).\n GESTALT_MOBILE_VERSION npm version or tag (default: latest).\n GESTALT_SKILLS_SOURCE Collection source override (always unverified).\n GESTALT_SKILLS_REF Collection Git ref or immutable revision (default: main).\n" };
39913
39960
  const ownershipHelper = packagedWindowsHelper();
39914
39961
  return runCli(
39915
39962
  { argv, cwd: process.cwd(), environment },
@@ -3,7 +3,7 @@
3
3
  set -Eeuo pipefail
4
4
  IFS=$'\n\t'
5
5
 
6
- readonly GESTALT_CLI_VERSION='0.20.2'
6
+ readonly GESTALT_CLI_VERSION='0.20.4'
7
7
  readonly DEFAULT_INSTALL_BASE_URL='https://dyne.github.io/gestalt'
8
8
  readonly DEFAULT_MARKETPLACE='dyne/gestalt-agents'
9
9
  readonly DEFAULT_MARKETPLACE_NAME='dyne-gestalt-agents'
@@ -844,12 +844,14 @@ Commands:
844
844
  scratch recover --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent
845
845
  Offline recovery after all owner processes have stopped.
846
846
  playwright install [VERSION] Install MCP; add missing system Chrome on Debian amd64.
847
- playwright update [VERSION] Stage, verify and activate an explicit package update.
847
+ playwright update [VERSION] [--prune-offline]
848
+ Reuse a matching release; prune older ones after browser shutdown.
848
849
  playwright version [--json] Read versioned installation metadata.
849
850
  playwright doctor [--json] [--launch] [--executable-path PATH] Check package and Chrome; optionally test a local page.
850
851
  playwright mcp --cwd ROOT Managed headless stdio (workspace profile).
851
852
  serena install Install private uv, Python 3.13 and tested Serena.
852
- serena update [VERSION] Validate and activate a release; retain prior tooling.
853
+ serena update [VERSION] [--prune-offline]
854
+ Update Serena; optionally remove inactive releases after shutdown.
853
855
  serena version, -V Read installed package metadata without creating state.
854
856
  serena doctor [--cwd ROOT] Check install, sandbox, MCP tools and optional language readiness.
855
857
  serena index --cwd ROOT Explicit native symbol/cache warmup for one project.
@@ -1163,7 +1165,7 @@ JS
1163
1165
  }
1164
1166
 
1165
1167
  install_serena() {
1166
- local version=${1:-$MANAGED_SERENA_VERSION} os cpu target asset base expected actual listing candidate
1168
+ local version=${1:-$MANAGED_SERENA_VERSION} prune=${2:-false} os cpu target asset base expected actual listing candidate
1167
1169
  [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die 'Serena release must be a stable VERSION (major.minor.patch)'
1168
1170
  require_command node
1169
1171
  require_command curl
@@ -1189,6 +1191,11 @@ install_serena() {
1189
1191
  serena_install_lock=$gestalt_home/serena/.install-lock
1190
1192
  trap 'exit 130' INT
1191
1193
  trap 'exit 143' TERM
1194
+ if [[ $# -gt 0 ]] && serena_install_valid "$version" "$MANAGED_UV_VERSION"; then
1195
+ log "Serena $version already installed and validated"
1196
+ if [[ $prune == true ]]; then prune_serena_releases; fi
1197
+ return
1198
+ fi
1192
1199
  # Construct at the final path: uv environments contain absolute interpreter paths.
1193
1200
  serena_install_candidate=$(mktemp -d "$gestalt_home/serena/release-$version.XXXXXXXX")
1194
1201
  candidate=$serena_install_candidate
@@ -1299,6 +1306,31 @@ PYTHON
1299
1306
  rm -rf -- "$candidate/probe" "$candidate/probe-workspace" "${candidate:?}/home" "$candidate/tmp" "$candidate/cache"
1300
1307
  rm -f -- "$candidate/uv.tar.gz" "$candidate/uv.sha256"
1301
1308
  log "installed Serena $version with uv $MANAGED_UV_VERSION and Python 3.13"
1309
+ if [[ $prune == true ]]; then prune_serena_releases; fi
1310
+ }
1311
+
1312
+ # Called only with the installation lock and explicit offline authorization.
1313
+ prune_serena_releases() {
1314
+ node - "$gestalt_home/serena" <<'JS'
1315
+ const fs = require('node:fs'), path = require('node:path');
1316
+ const root = process.argv[2], pattern = /^release-\d+\.\d+\.\d+\.[A-Za-z0-9]{8}$/;
1317
+ const active = JSON.parse(fs.readFileSync(path.join(root, 'active.json'), 'utf8'));
1318
+ const release = path.dirname(path.dirname(active.executable));
1319
+ if (path.dirname(release) !== root || !pattern.test(path.basename(release)) ||
1320
+ !fs.lstatSync(release).isDirectory() ||
1321
+ ![[active.executable, 'bin/serena'], [active.python, 'tools/serena-agent/bin/python'],
1322
+ [active.uv, 'bin/uv'], [active.pythonInstallDir, 'python']].every(([value, relative]) =>
1323
+ value === path.join(release, relative) &&
1324
+ fs.realpathSync(value).startsWith(fs.realpathSync(release) + path.sep))) {
1325
+ throw new Error('cannot identify the active managed Serena release for pruning');
1326
+ }
1327
+ for (const entry of fs.readdirSync(root, {withFileTypes: true})) {
1328
+ const candidate = path.join(root, entry.name);
1329
+ if (candidate === release || !entry.isDirectory() || !pattern.test(entry.name)) continue;
1330
+ fs.rmSync(candidate, {recursive: true});
1331
+ console.error('gestalt: removed inactive Serena release ' + entry.name);
1332
+ }
1333
+ JS
1302
1334
  }
1303
1335
 
1304
1336
  # Embedded to preserve the manager's single-file distribution contract.
@@ -1649,13 +1681,62 @@ async function catalog(executable) {
1649
1681
  send({jsonrpc:'2.0',id:1,method:'initialize',params:{protocolVersion:'2024-11-05',capabilities:{},clientInfo:{name:'gestalt-install-probe',version:'1'}}});
1650
1682
  });
1651
1683
  }
1652
- async function install(version) {
1684
+ // Called under .install-lock. Only --prune-offline authorizes removal.
1685
+ function checkInactiveReleases(prune) {
1686
+ const active = installed();
1687
+ let retained = 0;
1688
+ for (const entry of fs.readdirSync(root,{withFileTypes:true})) {
1689
+ const match = /^release-(\d+\.\d+\.\d+)-[A-Za-z0-9]{6}$/.exec(entry.name);
1690
+ const candidate = path.join(root,entry.name);
1691
+ if (!match || !entry.isDirectory() || candidate === active.release) continue;
1692
+ // Historical releases have no per-release descriptor. Recognize their
1693
+ // private manifest, installed package and pinned npm lock before removal.
1694
+ try {
1695
+ const info = fs.lstatSync(candidate);
1696
+ if ((process.getuid && info.uid !== process.getuid()) || (info.mode & 0o077)) continue;
1697
+ const manifest = json(path.join(candidate,'package.json'));
1698
+ const pkg = json(path.join(candidate,'node_modules/@playwright/mcp/package.json'));
1699
+ const pin = json(path.join(candidate,'package-lock.json'),4*1024*1024).packages?.['node_modules/@playwright/mcp'];
1700
+ if (manifest.private !== true || manifest.dependencies?.['@playwright/mcp'] !== match[1] ||
1701
+ pkg.version !== match[1] || pin?.version !== match[1] || !integrity.test(pin.integrity)) continue;
1702
+ } catch { continue; }
1703
+ if (!prune) { retained++; continue; }
1704
+ try { fs.rmSync(candidate,{recursive:true}); }
1705
+ catch { fail('Playwright release is active, but inactive release cleanup failed: '+entry.name); }
1706
+ console.error('gestalt: removed inactive Playwright release '+entry.name);
1707
+ }
1708
+ if (retained) {
1709
+ const noun = retained === 1 ? 'release' : 'releases';
1710
+ console.error(`gestalt: keeping ${retained} inactive Playwright ${noun} for existing clients. After stopping managed browsers, run gestalt playwright update ${active.version} --prune-offline`);
1711
+ }
1712
+ }
1713
+ async function reusePlaywright(version, expectedIntegrity) {
1714
+ try {
1715
+ const active = installed();
1716
+ if (active.version !== version || (expectedIntegrity && active.integrity !== expectedIntegrity)) return false;
1717
+ // The pinned entry point can still be intact after a dependency was removed.
1718
+ await validatePlaywrightCli(active.executable);
1719
+ } catch { return false; }
1720
+ console.error('gestalt: reusing validated Playwright '+version);
1721
+ return true;
1722
+ }
1723
+ async function validatePlaywrightCli(executable) {
1724
+ const help = await run(process.execPath,[executable,'--help']);
1725
+ for (const option of ['--headless','--user-data-dir','--executable-path','--no-webmcp'])
1726
+ if (!help.includes(option)) fail('incompatible upstream CLI');
1727
+ }
1728
+ async function install(version, prune) {
1653
1729
  if (version && !stable.test(version)) fail('Playwright version must be stable major.minor.patch');
1654
1730
  if (Number(process.versions.node.split('.')[0]) < 20) fail('Playwright requires Node >=20');
1655
1731
  if (!['linux','darwin'].includes(process.platform)) fail('Playwright supports Linux and macOS');
1656
1732
  directory(root);
1657
1733
  lock = path.join(root,'.install-lock');
1658
1734
  try {fs.mkdirSync(lock,{mode:0o700});} catch {lock=null;fail('Playwright install already running; verify installer exited before removing stale .install-lock');}
1735
+ const requestedVersion = version;
1736
+ if (requestedVersion && await reusePlaywright(requestedVersion)) {
1737
+ checkInactiveReleases(prune);
1738
+ return;
1739
+ }
1659
1740
  stage = fs.mkdtempSync(path.join(root,'release-'+(version || 'stable')+'-'));
1660
1741
  fs.writeFileSync(path.join(stage,'npmrc'),'',{mode:0o600});
1661
1742
  const npmEnv = {...runtimeEnv(),npm_config_cache:path.join(stage,'cache'),npm_config_userconfig:path.join(stage,'npmrc'),npm_config_globalconfig:'/dev/null',npm_config_registry:'https://registry.npmjs.org/',npm_config_engine_strict:'true',npm_config_ignore_scripts:'true',npm_config_update_notifier:'false'};
@@ -1663,6 +1744,10 @@ async function install(version) {
1663
1744
  const release = JSON.parse(await npm(['view','@playwright/mcp@'+(version || 'latest'),'--json']));
1664
1745
  if (!stable.test(release.version) || (version && release.version !== version) || !integrity.test(release.dist?.integrity)) fail('invalid stable release metadata');
1665
1746
  version=release.version;
1747
+ if (!requestedVersion && await reusePlaywright(version,release.dist.integrity)) {
1748
+ checkInactiveReleases(prune);
1749
+ return;
1750
+ }
1666
1751
  // Use a version-bearing final location before generating lock metadata.
1667
1752
  const finalStage=path.join(root,'release-'+version+'-'+path.basename(stage).split('-').at(-1));
1668
1753
  if (finalStage !== stage) {fs.renameSync(stage,finalStage);stage=finalStage;npmEnv.npm_config_cache=path.join(stage,'cache');npmEnv.npm_config_userconfig=path.join(stage,'npmrc');}
@@ -1676,8 +1761,7 @@ async function install(version) {
1676
1761
  const executable=path.join(stage,'node_modules/@playwright/mcp/cli.js');
1677
1762
  const pkg=json(path.join(stage,'node_modules/@playwright/mcp/package.json'));
1678
1763
  if(pkg.version!==version) fail('package version mismatch');
1679
- const help=await run(process.execPath,[executable,'--help']);
1680
- for(const option of ['--headless','--user-data-dir','--executable-path','--no-webmcp']) if(!help.includes(option)) fail('incompatible upstream CLI');
1764
+ await validatePlaywrightCli(executable);
1681
1765
  const toolSchemas=await catalog(executable),tools=toolSchemas.map(t=>t.name);
1682
1766
  const descriptor={schemaVersion:1,contractVersion:1,version,integrity:release.dist.integrity,node:'>=20',release:stage,
1683
1767
  lockSha256:hash(fs.readFileSync(packageLock)),executableSha256:hash(fs.readFileSync(executable)),tools,toolSchemas};
@@ -1686,14 +1770,17 @@ async function install(version) {
1686
1770
  fs.writeFileSync(staged,JSON.stringify(descriptor)+'\n',{mode:0o600});
1687
1771
  fs.renameSync(staged,path.join(root,'active.json'));
1688
1772
  stage=null; console.error('gestalt: installed Playwright '+version+' (Chrome externally maintained)');
1773
+ checkInactiveReleases(prune);
1689
1774
  }
1690
1775
  (async()=>{
1691
1776
  safe(root);
1692
- if (['help','-h','--help'].includes(action)) { console.log('Usage: gestalt playwright install [VERSION] | update [VERSION] | version [--json] | doctor [--json] [--launch] [--cwd ROOT] [--executable-path PATH] | mcp --cwd ROOT [--executable-path PATH]\nInstall adds missing system Chrome on Debian amd64. Chrome is externally maintained; update, startup and doctor never download it. --launch tests a disposable local page.'); return; }
1777
+ if (['help','-h','--help'].includes(action)) { console.log('Usage: gestalt playwright install [VERSION] | update [VERSION] [--prune-offline] | version [--json] | doctor [--json] [--launch] [--cwd ROOT] [--executable-path PATH] | mcp --cwd ROOT [--executable-path PATH]\nStop all managed Playwright clients before using --prune-offline to keep only the active release. Install adds missing system Chrome on Debian amd64. Chrome is externally maintained; update, startup and doctor never download it. --launch tests a disposable local page.'); return; }
1693
1778
  if (['install','update'].includes(action)) {
1694
- if(args.length>1)fail('usage: gestalt playwright '+action+' [VERSION]');
1779
+ const prune = action === 'update' && args.at(-1) === '--prune-offline';
1780
+ if (prune) args.pop();
1781
+ if(args.length>1)fail('usage: gestalt playwright '+action+' [VERSION]'+(action==='update'?' [--prune-offline]':''));
1695
1782
  if(action==='install' && !args.length) {try {installed(); console.error('gestalt: Playwright already installed and validated');return;}catch{}}
1696
- await install(args[0] || (action === 'install' ? '0.0.83' : undefined));return;
1783
+ await install(args[0] || (action === 'install' ? '0.0.83' : undefined),prune);return;
1697
1784
  }
1698
1785
  if(action==='version') {
1699
1786
  if(args.length && !(args.length===1 && args[0]==='--json')) fail('usage: gestalt playwright version [--json]');
@@ -1874,7 +1961,8 @@ Usage: gestalt serena <command> [options]
1874
1961
 
1875
1962
  Commands:
1876
1963
  install Install private uv, Python 3.13 and tested Serena.
1877
- update [VERSION] Validate and activate a release; retain prior tooling.
1964
+ update [VERSION] [--prune-offline]
1965
+ Update Serena; remove inactive releases only after shutdown.
1878
1966
  version Read the installed version without starting Serena.
1879
1967
  doctor [--cwd ROOT] [--json] Check installation and optional workspace readiness.
1880
1968
  index --cwd ROOT Warm symbol and language caches for a project.
@@ -1895,7 +1983,12 @@ EOF
1895
1983
  fi
1896
1984
  ;;
1897
1985
  update)
1898
- (($# <= 1)) || die 'usage: gestalt serena update [VERSION]'
1986
+ local prune=false
1987
+ if [[ ${!#} == --prune-offline ]]; then
1988
+ prune=true
1989
+ set -- "${@:1:$#-1}"
1990
+ fi
1991
+ (($# <= 1)) || die 'usage: gestalt serena update [VERSION] [--prune-offline]'
1899
1992
  local version=${1:-latest}
1900
1993
  if [[ $version == latest ]]; then
1901
1994
  require_command curl
@@ -1905,7 +1998,7 @@ EOF
1905
1998
  node -e 'let s=""; process.stdin.on("data",b=>s+=b); process.stdin.on("end",()=>{const d=JSON.parse(s);const versions=Object.keys(d.releases??{}).filter(v=>/^\d+\.\d+\.\d+$/.test(v)&&d.releases[v]?.some(f=>!f.yanked)).sort((a,b)=>{const x=a.split(".").map(Number),y=b.split(".").map(Number);return x[0]-y[0]||x[1]-y[1]||x[2]-y[2];});if(!versions.length)process.exit(1);process.stdout.write(versions.at(-1));});') ||
1906
1999
  die 'could not resolve the latest stable Serena release; prior installation preserved'
1907
2000
  fi
1908
- install_serena "$version"
2001
+ install_serena "$version" "$prune"
1909
2002
  ;;
1910
2003
  mcp)
1911
2004
  [[ $# == 2 && $1 == --cwd && -n $2 ]] || die 'usage: gestalt serena mcp --cwd ROOT; context, mode and project cannot be overridden'
@@ -1933,16 +2026,18 @@ EOF
1933
2026
  [[ $action != index || -n $workspace ]] || die 'usage: gestalt serena index --cwd ROOT'
1934
2027
  serena_operator "$action" "$workspace" "$json_output"
1935
2028
  ;;
1936
- *) die 'usage: gestalt serena install | update [VERSION] | version | doctor [--cwd ROOT] | index --cwd ROOT | mcp --cwd ROOT' ;;
2029
+ *) die 'usage: gestalt serena install | update [VERSION] [--prune-offline] | version | doctor [--cwd ROOT] | index --cwd ROOT | mcp --cwd ROOT' ;;
1937
2030
  esac
1938
2031
  }
1939
2032
 
1940
2033
  serena_install_valid() {
1941
2034
  require_command node
1942
- node - "$gestalt_home/serena/active.json" <<'JS'
2035
+ node - "$gestalt_home/serena/active.json" "${1:-}" "${2:-}" <<'JS'
1943
2036
  const fs = require('node:fs'), {spawnSync} = require('node:child_process');
1944
2037
  try {
1945
2038
  const d = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
2039
+ const [, , , expectedVersion, expectedUv] = process.argv;
2040
+ if (expectedVersion && d.version !== expectedVersion) process.exit(1);
1946
2041
  if (d.schemaVersion !== 1 || (d.contractVersion !== 1 && d.version !== '1.7.0') || !Array.isArray(d.tools) ||
1947
2042
  !['get_symbols_overview', 'find_symbol', 'replace_symbol_body'].every(n => d.tools.some(t => t.name === n && t.inputSchema))) process.exit(1);
1948
2043
  for (const p of [d.executable, d.python, d.uv]) fs.accessSync(p, fs.constants.X_OK);
@@ -1950,6 +2045,10 @@ try {
1950
2045
  const result = spawnSync(d.python, ['-I', '-B', '-c', 'import importlib.metadata; print(importlib.metadata.version("serena-agent"))'],
1951
2046
  {encoding: 'utf8', timeout: 5000});
1952
2047
  if (result.status !== 0 || result.stdout.trim() !== d.version) process.exit(1);
2048
+ if (expectedUv) {
2049
+ const uv = spawnSync(d.uv, ['--version'], {encoding: 'utf8', timeout: 5000});
2050
+ if (uv.status !== 0 || uv.stdout.trim().split(/\s+/).slice(0, 2).join(' ') !== 'uv ' + expectedUv) process.exit(1);
2051
+ }
1953
2052
  } catch { process.exit(1); }
1954
2053
  JS
1955
2054
  }
@@ -3543,7 +3642,7 @@ NODE
3543
3642
  install_mobile() {
3544
3643
  check_node_version
3545
3644
  require_command npm
3546
- mkdir -p -- "$mobile_root"
3645
+ (umask 077; mkdir -p -- "$mobile_root")
3547
3646
  log "installing gestalt-mobile@${mobile_version} under $mobile_root"
3548
3647
  npm install \
3549
3648
  --prefix "$mobile_root" \
@@ -5270,7 +5369,7 @@ prepare_codex_approval_launcher() {
5270
5369
  done
5271
5370
  native_codex=$(PATH="$native_path" command -v codex) || die 'native Codex executable is missing'
5272
5371
  [[ $native_codex == /* && -x $native_codex ]] || die 'native Codex executable must have an absolute path'
5273
- mkdir -p -- "$gestalt_home/run"
5372
+ (umask 077; mkdir -p -- "$gestalt_home/run")
5274
5373
  launcher_root=$(mktemp -d "$gestalt_home/run/codex-approval.XXXXXXXX")
5275
5374
  codex_approval_launcher=$launcher_root/bin
5276
5375
  mkdir -m 700 -- "$codex_approval_launcher"
@@ -2,7 +2,7 @@
2
2
  "source": "src/cli/platform/native/owned-process.c",
3
3
  "license": "MIT (full license in source)",
4
4
  "sourceSha256": "8b8499245e4213e3e842497f815d4b0d19685bcd806b461fdacb66119500ad58",
5
- "artifactSha256": "33299d7332e29adc9068a19ebd394c34cf1b9eb3c55d0229c902848d50e52d34",
5
+ "artifactSha256": "f3609b67bcdad6750f6d35de82acb4b688927702be56d7be504b2cf748fd4be6",
6
6
  "platform": "win32",
7
7
  "architecture": "x64",
8
8
  "node": "v24.22.3",
@@ -23,7 +23,7 @@
23
23
  "advapi32.lib",
24
24
  "netapi32.lib"
25
25
  ],
26
- "observedAt": "2026-11-25T21:04:26.231Z",
26
+ "observedAt": "2026-12-04T17:22:43.258Z",
27
27
  "sourceInputs": [
28
28
  {
29
29
  "path": "src/cli/platform/native/owned-process.c",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jaromil/gestalt",
3
3
  "type": "module",
4
- "version": "0.20.2",
4
+ "version": "0.20.4",
5
5
  "description": "Manage Gestalt's isolated Codex profile, agent skills and Mobile installation",
6
6
  "license": "AGPL-3.0-or-later",
7
7
  "author": "Dyne.org foundation",
@@ -44,5 +44,5 @@
44
44
  "access": "public",
45
45
  "registry": "https://registry.npmjs.org/"
46
46
  },
47
- "gitHead": "89db02fb605dfc9660276865c018db7f124a6239"
47
+ "gitHead": "61f44a8c79a9447330dffddad710604ea225be2e"
48
48
  }