crewbee 0.1.5 → 0.1.6

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.
@@ -1,4 +1,4 @@
1
- import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
1
+ import { createRequire as __createRequire } from 'node:module'; import { fileURLToPath as __fileURLToPath } from 'node:url'; import { dirname as __pathDirname } from 'node:path'; const require = __createRequire(import.meta.url); const __dirname = __pathDirname(__fileURLToPath(import.meta.url));
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -112,17 +112,17 @@ var require_visit = __commonJS({
112
112
  visit.BREAK = BREAK;
113
113
  visit.SKIP = SKIP;
114
114
  visit.REMOVE = REMOVE;
115
- function visit_(key, node, visitor, path6) {
116
- const ctrl = callVisitor(key, node, visitor, path6);
115
+ function visit_(key, node, visitor, path10) {
116
+ const ctrl = callVisitor(key, node, visitor, path10);
117
117
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
118
- replaceNode(key, path6, ctrl);
119
- return visit_(key, ctrl, visitor, path6);
118
+ replaceNode(key, path10, ctrl);
119
+ return visit_(key, ctrl, visitor, path10);
120
120
  }
121
121
  if (typeof ctrl !== "symbol") {
122
122
  if (identity.isCollection(node)) {
123
- path6 = Object.freeze(path6.concat(node));
123
+ path10 = Object.freeze(path10.concat(node));
124
124
  for (let i = 0; i < node.items.length; ++i) {
125
- const ci = visit_(i, node.items[i], visitor, path6);
125
+ const ci = visit_(i, node.items[i], visitor, path10);
126
126
  if (typeof ci === "number")
127
127
  i = ci - 1;
128
128
  else if (ci === BREAK)
@@ -133,13 +133,13 @@ var require_visit = __commonJS({
133
133
  }
134
134
  }
135
135
  } else if (identity.isPair(node)) {
136
- path6 = Object.freeze(path6.concat(node));
137
- const ck = visit_("key", node.key, visitor, path6);
136
+ path10 = Object.freeze(path10.concat(node));
137
+ const ck = visit_("key", node.key, visitor, path10);
138
138
  if (ck === BREAK)
139
139
  return BREAK;
140
140
  else if (ck === REMOVE)
141
141
  node.key = null;
142
- const cv = visit_("value", node.value, visitor, path6);
142
+ const cv = visit_("value", node.value, visitor, path10);
143
143
  if (cv === BREAK)
144
144
  return BREAK;
145
145
  else if (cv === REMOVE)
@@ -160,17 +160,17 @@ var require_visit = __commonJS({
160
160
  visitAsync.BREAK = BREAK;
161
161
  visitAsync.SKIP = SKIP;
162
162
  visitAsync.REMOVE = REMOVE;
163
- async function visitAsync_(key, node, visitor, path6) {
164
- const ctrl = await callVisitor(key, node, visitor, path6);
163
+ async function visitAsync_(key, node, visitor, path10) {
164
+ const ctrl = await callVisitor(key, node, visitor, path10);
165
165
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
166
- replaceNode(key, path6, ctrl);
167
- return visitAsync_(key, ctrl, visitor, path6);
166
+ replaceNode(key, path10, ctrl);
167
+ return visitAsync_(key, ctrl, visitor, path10);
168
168
  }
169
169
  if (typeof ctrl !== "symbol") {
170
170
  if (identity.isCollection(node)) {
171
- path6 = Object.freeze(path6.concat(node));
171
+ path10 = Object.freeze(path10.concat(node));
172
172
  for (let i = 0; i < node.items.length; ++i) {
173
- const ci = await visitAsync_(i, node.items[i], visitor, path6);
173
+ const ci = await visitAsync_(i, node.items[i], visitor, path10);
174
174
  if (typeof ci === "number")
175
175
  i = ci - 1;
176
176
  else if (ci === BREAK)
@@ -181,13 +181,13 @@ var require_visit = __commonJS({
181
181
  }
182
182
  }
183
183
  } else if (identity.isPair(node)) {
184
- path6 = Object.freeze(path6.concat(node));
185
- const ck = await visitAsync_("key", node.key, visitor, path6);
184
+ path10 = Object.freeze(path10.concat(node));
185
+ const ck = await visitAsync_("key", node.key, visitor, path10);
186
186
  if (ck === BREAK)
187
187
  return BREAK;
188
188
  else if (ck === REMOVE)
189
189
  node.key = null;
190
- const cv = await visitAsync_("value", node.value, visitor, path6);
190
+ const cv = await visitAsync_("value", node.value, visitor, path10);
191
191
  if (cv === BREAK)
192
192
  return BREAK;
193
193
  else if (cv === REMOVE)
@@ -214,23 +214,23 @@ var require_visit = __commonJS({
214
214
  }
215
215
  return visitor;
216
216
  }
217
- function callVisitor(key, node, visitor, path6) {
217
+ function callVisitor(key, node, visitor, path10) {
218
218
  if (typeof visitor === "function")
219
- return visitor(key, node, path6);
219
+ return visitor(key, node, path10);
220
220
  if (identity.isMap(node))
221
- return visitor.Map?.(key, node, path6);
221
+ return visitor.Map?.(key, node, path10);
222
222
  if (identity.isSeq(node))
223
- return visitor.Seq?.(key, node, path6);
223
+ return visitor.Seq?.(key, node, path10);
224
224
  if (identity.isPair(node))
225
- return visitor.Pair?.(key, node, path6);
225
+ return visitor.Pair?.(key, node, path10);
226
226
  if (identity.isScalar(node))
227
- return visitor.Scalar?.(key, node, path6);
227
+ return visitor.Scalar?.(key, node, path10);
228
228
  if (identity.isAlias(node))
229
- return visitor.Alias?.(key, node, path6);
229
+ return visitor.Alias?.(key, node, path10);
230
230
  return void 0;
231
231
  }
232
- function replaceNode(key, path6, node) {
233
- const parent = path6[path6.length - 1];
232
+ function replaceNode(key, path10, node) {
233
+ const parent = path10[path10.length - 1];
234
234
  if (identity.isCollection(parent)) {
235
235
  parent.items[key] = node;
236
236
  } else if (identity.isPair(parent)) {
@@ -838,10 +838,10 @@ var require_Collection = __commonJS({
838
838
  var createNode = require_createNode();
839
839
  var identity = require_identity();
840
840
  var Node = require_Node();
841
- function collectionFromPath(schema, path6, value) {
841
+ function collectionFromPath(schema, path10, value) {
842
842
  let v = value;
843
- for (let i = path6.length - 1; i >= 0; --i) {
844
- const k = path6[i];
843
+ for (let i = path10.length - 1; i >= 0; --i) {
844
+ const k = path10[i];
845
845
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
846
846
  const a = [];
847
847
  a[k] = v;
@@ -860,7 +860,7 @@ var require_Collection = __commonJS({
860
860
  sourceObjects: /* @__PURE__ */ new Map()
861
861
  });
862
862
  }
863
- var isEmptyPath = (path6) => path6 == null || typeof path6 === "object" && !!path6[Symbol.iterator]().next().done;
863
+ var isEmptyPath = (path10) => path10 == null || typeof path10 === "object" && !!path10[Symbol.iterator]().next().done;
864
864
  var Collection = class extends Node.NodeBase {
865
865
  constructor(type, schema) {
866
866
  super(type);
@@ -890,11 +890,11 @@ var require_Collection = __commonJS({
890
890
  * be a Pair instance or a `{ key, value }` object, which may not have a key
891
891
  * that already exists in the map.
892
892
  */
893
- addIn(path6, value) {
894
- if (isEmptyPath(path6))
893
+ addIn(path10, value) {
894
+ if (isEmptyPath(path10))
895
895
  this.add(value);
896
896
  else {
897
- const [key, ...rest] = path6;
897
+ const [key, ...rest] = path10;
898
898
  const node = this.get(key, true);
899
899
  if (identity.isCollection(node))
900
900
  node.addIn(rest, value);
@@ -908,8 +908,8 @@ var require_Collection = __commonJS({
908
908
  * Removes a value from the collection.
909
909
  * @returns `true` if the item was found and removed.
910
910
  */
911
- deleteIn(path6) {
912
- const [key, ...rest] = path6;
911
+ deleteIn(path10) {
912
+ const [key, ...rest] = path10;
913
913
  if (rest.length === 0)
914
914
  return this.delete(key);
915
915
  const node = this.get(key, true);
@@ -923,8 +923,8 @@ var require_Collection = __commonJS({
923
923
  * scalar values from their surrounding node; to disable set `keepScalar` to
924
924
  * `true` (collections are always returned intact).
925
925
  */
926
- getIn(path6, keepScalar) {
927
- const [key, ...rest] = path6;
926
+ getIn(path10, keepScalar) {
927
+ const [key, ...rest] = path10;
928
928
  const node = this.get(key, true);
929
929
  if (rest.length === 0)
930
930
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -942,8 +942,8 @@ var require_Collection = __commonJS({
942
942
  /**
943
943
  * Checks if the collection includes a value with the key `key`.
944
944
  */
945
- hasIn(path6) {
946
- const [key, ...rest] = path6;
945
+ hasIn(path10) {
946
+ const [key, ...rest] = path10;
947
947
  if (rest.length === 0)
948
948
  return this.has(key);
949
949
  const node = this.get(key, true);
@@ -953,8 +953,8 @@ var require_Collection = __commonJS({
953
953
  * Sets a value in this collection. For `!!set`, `value` needs to be a
954
954
  * boolean to add/remove the item from the set.
955
955
  */
956
- setIn(path6, value) {
957
- const [key, ...rest] = path6;
956
+ setIn(path10, value) {
957
+ const [key, ...rest] = path10;
958
958
  if (rest.length === 0) {
959
959
  this.set(key, value);
960
960
  } else {
@@ -3458,9 +3458,9 @@ var require_Document = __commonJS({
3458
3458
  this.contents.add(value);
3459
3459
  }
3460
3460
  /** Adds a value to the document. */
3461
- addIn(path6, value) {
3461
+ addIn(path10, value) {
3462
3462
  if (assertCollection(this.contents))
3463
- this.contents.addIn(path6, value);
3463
+ this.contents.addIn(path10, value);
3464
3464
  }
3465
3465
  /**
3466
3466
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3535,14 +3535,14 @@ var require_Document = __commonJS({
3535
3535
  * Removes a value from the document.
3536
3536
  * @returns `true` if the item was found and removed.
3537
3537
  */
3538
- deleteIn(path6) {
3539
- if (Collection.isEmptyPath(path6)) {
3538
+ deleteIn(path10) {
3539
+ if (Collection.isEmptyPath(path10)) {
3540
3540
  if (this.contents == null)
3541
3541
  return false;
3542
3542
  this.contents = null;
3543
3543
  return true;
3544
3544
  }
3545
- return assertCollection(this.contents) ? this.contents.deleteIn(path6) : false;
3545
+ return assertCollection(this.contents) ? this.contents.deleteIn(path10) : false;
3546
3546
  }
3547
3547
  /**
3548
3548
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3557,10 +3557,10 @@ var require_Document = __commonJS({
3557
3557
  * scalar values from their surrounding node; to disable set `keepScalar` to
3558
3558
  * `true` (collections are always returned intact).
3559
3559
  */
3560
- getIn(path6, keepScalar) {
3561
- if (Collection.isEmptyPath(path6))
3560
+ getIn(path10, keepScalar) {
3561
+ if (Collection.isEmptyPath(path10))
3562
3562
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3563
- return identity.isCollection(this.contents) ? this.contents.getIn(path6, keepScalar) : void 0;
3563
+ return identity.isCollection(this.contents) ? this.contents.getIn(path10, keepScalar) : void 0;
3564
3564
  }
3565
3565
  /**
3566
3566
  * Checks if the document includes a value with the key `key`.
@@ -3571,10 +3571,10 @@ var require_Document = __commonJS({
3571
3571
  /**
3572
3572
  * Checks if the document includes a value at `path`.
3573
3573
  */
3574
- hasIn(path6) {
3575
- if (Collection.isEmptyPath(path6))
3574
+ hasIn(path10) {
3575
+ if (Collection.isEmptyPath(path10))
3576
3576
  return this.contents !== void 0;
3577
- return identity.isCollection(this.contents) ? this.contents.hasIn(path6) : false;
3577
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path10) : false;
3578
3578
  }
3579
3579
  /**
3580
3580
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3591,13 +3591,13 @@ var require_Document = __commonJS({
3591
3591
  * Sets a value in this document. For `!!set`, `value` needs to be a
3592
3592
  * boolean to add/remove the item from the set.
3593
3593
  */
3594
- setIn(path6, value) {
3595
- if (Collection.isEmptyPath(path6)) {
3594
+ setIn(path10, value) {
3595
+ if (Collection.isEmptyPath(path10)) {
3596
3596
  this.contents = value;
3597
3597
  } else if (this.contents == null) {
3598
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path6), value);
3598
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path10), value);
3599
3599
  } else if (assertCollection(this.contents)) {
3600
- this.contents.setIn(path6, value);
3600
+ this.contents.setIn(path10, value);
3601
3601
  }
3602
3602
  }
3603
3603
  /**
@@ -5549,9 +5549,9 @@ var require_cst_visit = __commonJS({
5549
5549
  visit.BREAK = BREAK;
5550
5550
  visit.SKIP = SKIP;
5551
5551
  visit.REMOVE = REMOVE;
5552
- visit.itemAtPath = (cst, path6) => {
5552
+ visit.itemAtPath = (cst, path10) => {
5553
5553
  let item = cst;
5554
- for (const [field, index] of path6) {
5554
+ for (const [field, index] of path10) {
5555
5555
  const tok = item?.[field];
5556
5556
  if (tok && "items" in tok) {
5557
5557
  item = tok.items[index];
@@ -5560,23 +5560,23 @@ var require_cst_visit = __commonJS({
5560
5560
  }
5561
5561
  return item;
5562
5562
  };
5563
- visit.parentCollection = (cst, path6) => {
5564
- const parent = visit.itemAtPath(cst, path6.slice(0, -1));
5565
- const field = path6[path6.length - 1][0];
5563
+ visit.parentCollection = (cst, path10) => {
5564
+ const parent = visit.itemAtPath(cst, path10.slice(0, -1));
5565
+ const field = path10[path10.length - 1][0];
5566
5566
  const coll = parent?.[field];
5567
5567
  if (coll && "items" in coll)
5568
5568
  return coll;
5569
5569
  throw new Error("Parent collection not found");
5570
5570
  };
5571
- function _visit(path6, item, visitor) {
5572
- let ctrl = visitor(item, path6);
5571
+ function _visit(path10, item, visitor) {
5572
+ let ctrl = visitor(item, path10);
5573
5573
  if (typeof ctrl === "symbol")
5574
5574
  return ctrl;
5575
5575
  for (const field of ["key", "value"]) {
5576
5576
  const token = item[field];
5577
5577
  if (token && "items" in token) {
5578
5578
  for (let i = 0; i < token.items.length; ++i) {
5579
- const ci = _visit(Object.freeze(path6.concat([[field, i]])), token.items[i], visitor);
5579
+ const ci = _visit(Object.freeze(path10.concat([[field, i]])), token.items[i], visitor);
5580
5580
  if (typeof ci === "number")
5581
5581
  i = ci - 1;
5582
5582
  else if (ci === BREAK)
@@ -5587,10 +5587,10 @@ var require_cst_visit = __commonJS({
5587
5587
  }
5588
5588
  }
5589
5589
  if (typeof ctrl === "function" && field === "key")
5590
- ctrl = ctrl(item, path6);
5590
+ ctrl = ctrl(item, path10);
5591
5591
  }
5592
5592
  }
5593
- return typeof ctrl === "function" ? ctrl(item, path6) : ctrl;
5593
+ return typeof ctrl === "function" ? ctrl(item, path10) : ctrl;
5594
5594
  }
5595
5595
  exports.visit = visit;
5596
5596
  }
@@ -9669,6 +9669,18 @@ function resolveOpenCodeConfigRoot(configPath) {
9669
9669
  }
9670
9670
  return crossPlatformRoot;
9671
9671
  }
9672
+ function resolveOpenCodeConfigPath(configPath) {
9673
+ if (configPath) {
9674
+ return path2.resolve(configPath);
9675
+ }
9676
+ const configRoot = resolveOpenCodeConfigRoot();
9677
+ const jsoncPath = path2.join(configRoot, "opencode.jsonc");
9678
+ const jsonPath = path2.join(configRoot, "opencode.json");
9679
+ if (existsSync2(jsoncPath)) {
9680
+ return jsoncPath;
9681
+ }
9682
+ return jsonPath;
9683
+ }
9672
9684
  function resolveInstallRoot(installRoot) {
9673
9685
  if (installRoot) {
9674
9686
  return path2.resolve(installRoot);
@@ -9733,9 +9745,9 @@ function normalizeProjectionPathList(value, label) {
9733
9745
  if (!normalized) {
9734
9746
  return void 0;
9735
9747
  }
9736
- for (const path6 of normalized) {
9737
- if (!isSnakeCasePath(path6)) {
9738
- throw new Error(`${label} only supports snake_case paths. Migrate '${path6}' to snake_case.`);
9748
+ for (const path10 of normalized) {
9749
+ if (!isSnakeCasePath(path10)) {
9750
+ throw new Error(`${label} only supports snake_case paths. Migrate '${path10}' to snake_case.`);
9739
9751
  }
9740
9752
  }
9741
9753
  return normalized;
@@ -11097,6 +11109,137 @@ function loadEmbeddedTeam(source) {
11097
11109
  };
11098
11110
  }
11099
11111
 
11112
+ // src/install/config-writer.ts
11113
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
11114
+
11115
+ // src/install/jsonc.ts
11116
+ function parseJsoncText(text) {
11117
+ const stripped = stripJsonComments(text);
11118
+ const normalized = stripTrailingCommas(stripped).trim();
11119
+ if (normalized.length === 0) {
11120
+ return {};
11121
+ }
11122
+ const parsed = JSON.parse(normalized);
11123
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
11124
+ throw new Error("OpenCode config must be a JSON object.");
11125
+ }
11126
+ return parsed;
11127
+ }
11128
+ function stripJsonComments(text) {
11129
+ let result = "";
11130
+ let inString = false;
11131
+ let escaped = false;
11132
+ let lineComment = false;
11133
+ let blockComment = false;
11134
+ for (let index = 0; index < text.length; index += 1) {
11135
+ const current = text[index];
11136
+ const next = text[index + 1];
11137
+ if (lineComment) {
11138
+ if (current === "\n") {
11139
+ lineComment = false;
11140
+ result += current;
11141
+ }
11142
+ continue;
11143
+ }
11144
+ if (blockComment) {
11145
+ if (current === "*" && next === "/") {
11146
+ blockComment = false;
11147
+ index += 1;
11148
+ }
11149
+ continue;
11150
+ }
11151
+ if (inString) {
11152
+ result += current;
11153
+ if (escaped) {
11154
+ escaped = false;
11155
+ continue;
11156
+ }
11157
+ if (current === "\\") {
11158
+ escaped = true;
11159
+ continue;
11160
+ }
11161
+ if (current === '"') {
11162
+ inString = false;
11163
+ }
11164
+ continue;
11165
+ }
11166
+ if (current === '"') {
11167
+ inString = true;
11168
+ result += current;
11169
+ continue;
11170
+ }
11171
+ if (current === "/" && next === "/") {
11172
+ lineComment = true;
11173
+ index += 1;
11174
+ continue;
11175
+ }
11176
+ if (current === "/" && next === "*") {
11177
+ blockComment = true;
11178
+ index += 1;
11179
+ continue;
11180
+ }
11181
+ result += current;
11182
+ }
11183
+ return result;
11184
+ }
11185
+ function stripTrailingCommas(text) {
11186
+ let result = "";
11187
+ let inString = false;
11188
+ let escaped = false;
11189
+ for (let index = 0; index < text.length; index += 1) {
11190
+ const current = text[index];
11191
+ if (inString) {
11192
+ result += current;
11193
+ if (escaped) {
11194
+ escaped = false;
11195
+ continue;
11196
+ }
11197
+ if (current === "\\") {
11198
+ escaped = true;
11199
+ continue;
11200
+ }
11201
+ if (current === '"') {
11202
+ inString = false;
11203
+ }
11204
+ continue;
11205
+ }
11206
+ if (current === '"') {
11207
+ inString = true;
11208
+ result += current;
11209
+ continue;
11210
+ }
11211
+ if (current === "," && findNextNonWhitespaceCharacter(text, index + 1)?.match(/[}\]]/)) {
11212
+ continue;
11213
+ }
11214
+ result += current;
11215
+ }
11216
+ return result;
11217
+ }
11218
+ function findNextNonWhitespaceCharacter(text, startIndex) {
11219
+ for (let index = startIndex; index < text.length; index += 1) {
11220
+ if (!/\s/.test(text[index])) {
11221
+ return text[index];
11222
+ }
11223
+ }
11224
+ return void 0;
11225
+ }
11226
+
11227
+ // src/install/config-writer.ts
11228
+ function readOpenCodeConfig(configPath) {
11229
+ if (!existsSync4(configPath)) {
11230
+ return {
11231
+ config: {},
11232
+ existed: false,
11233
+ path: configPath
11234
+ };
11235
+ }
11236
+ return {
11237
+ config: parseJsoncText(readFileSync3(configPath, "utf8")),
11238
+ existed: true,
11239
+ path: configPath
11240
+ };
11241
+ }
11242
+
11100
11243
  // src/runtime/team-library-projection.ts
11101
11244
  function isLeaderAgent(team, agent) {
11102
11245
  return team.manifest.leader.agentRef === agent.metadata.id;
@@ -11382,11 +11525,11 @@ function detectNodeKind(value) {
11382
11525
  }
11383
11526
  return "scalar";
11384
11527
  }
11385
- function buildNode(path6, key, value, order) {
11528
+ function buildNode(path10, key, value, order) {
11386
11529
  const kind = detectNodeKind(value);
11387
11530
  if (kind !== "object") {
11388
11531
  return {
11389
- path: path6,
11532
+ path: path10,
11390
11533
  key,
11391
11534
  label: toTitleLabel(key),
11392
11535
  kind,
@@ -11396,10 +11539,10 @@ function buildNode(path6, key, value, order) {
11396
11539
  };
11397
11540
  }
11398
11541
  const children = Object.entries(value).map(
11399
- ([childKey, childValue], index) => buildNode(`${path6}.${childKey}`, childKey, childValue, index)
11542
+ ([childKey, childValue], index) => buildNode(`${path10}.${childKey}`, childKey, childValue, index)
11400
11543
  );
11401
11544
  return {
11402
- path: path6,
11545
+ path: path10,
11403
11546
  key,
11404
11547
  label: toTitleLabel(key),
11405
11548
  kind,
@@ -11634,13 +11777,13 @@ var AGENT_SECTION_ORDER = [
11634
11777
  "tool_skill_strategy"
11635
11778
  ];
11636
11779
  var TEAM_SECTION_ORDER = ["working_rules", "approval_safety"];
11637
- function sectionRank(kind, path6) {
11780
+ function sectionRank(kind, path10) {
11638
11781
  const list = kind === "team" ? TEAM_SECTION_ORDER : AGENT_SECTION_ORDER;
11639
- const index = list.indexOf(path6);
11782
+ const index = list.indexOf(path10);
11640
11783
  return index === -1 ? Number.POSITIVE_INFINITY : index;
11641
11784
  }
11642
- function resolveSectionTitle(path6, fallback) {
11643
- return CANONICAL_SECTION_TITLES[path6] ?? fallback;
11785
+ function resolveSectionTitle(path10, fallback) {
11786
+ return CANONICAL_SECTION_TITLES[path10] ?? fallback;
11644
11787
  }
11645
11788
  function buildPromptPlan(catalog) {
11646
11789
  return {
@@ -11660,8 +11803,8 @@ function buildPromptPlan(catalog) {
11660
11803
  }
11661
11804
 
11662
11805
  // src/projection/apply-prompt-projection.ts
11663
- function matchesPath(selected, path6) {
11664
- return selected === path6 || path6.startsWith(`${selected}.`);
11806
+ function matchesPath(selected, path10) {
11807
+ return selected === path10 || path10.startsWith(`${selected}.`);
11665
11808
  }
11666
11809
  function isAncestorPath(ancestor, descendant) {
11667
11810
  return descendant === ancestor || descendant.startsWith(`${ancestor}.`);
@@ -12516,7 +12659,7 @@ function createEventHook(ctx, store) {
12516
12659
 
12517
12660
  // src/adapters/opencode/delegation/store.ts
12518
12661
  import { createHash, randomUUID } from "node:crypto";
12519
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
12662
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
12520
12663
  import path5 from "node:path";
12521
12664
  function createEmptyState() {
12522
12665
  return {
@@ -12633,11 +12776,11 @@ var DelegateStateStore = class {
12633
12776
  if (this.cache) {
12634
12777
  return this.cache;
12635
12778
  }
12636
- if (!existsSync4(this.filePath)) {
12779
+ if (!existsSync5(this.filePath)) {
12637
12780
  this.cache = createEmptyState();
12638
12781
  return this.cache;
12639
12782
  }
12640
- const raw = readFileSync3(this.filePath, "utf8");
12783
+ const raw = readFileSync4(this.filePath, "utf8");
12641
12784
  const parsed = JSON.parse(raw);
12642
12785
  this.cache = {
12643
12786
  version: 1,
@@ -12648,9 +12791,9 @@ var DelegateStateStore = class {
12648
12791
  return this.cache;
12649
12792
  }
12650
12793
  write(state) {
12651
- mkdirSync2(path5.dirname(this.filePath), { recursive: true });
12794
+ mkdirSync3(path5.dirname(this.filePath), { recursive: true });
12652
12795
  this.cache = state;
12653
- writeFileSync2(this.filePath, `${JSON.stringify(state, null, 2)}
12796
+ writeFileSync3(this.filePath, `${JSON.stringify(state, null, 2)}
12654
12797
  `, "utf8");
12655
12798
  }
12656
12799
  };
@@ -13386,10 +13529,10 @@ function mergeDefs(...defs) {
13386
13529
  function cloneDef(schema) {
13387
13530
  return mergeDefs(schema._zod.def);
13388
13531
  }
13389
- function getElementAtPath(obj, path6) {
13390
- if (!path6)
13532
+ function getElementAtPath(obj, path10) {
13533
+ if (!path10)
13391
13534
  return obj;
13392
- return path6.reduce((acc, key) => acc?.[key], obj);
13535
+ return path10.reduce((acc, key) => acc?.[key], obj);
13393
13536
  }
13394
13537
  function promiseAllObject(promisesObj) {
13395
13538
  const keys = Object.keys(promisesObj);
@@ -13750,11 +13893,11 @@ function aborted(x, startIndex = 0) {
13750
13893
  }
13751
13894
  return false;
13752
13895
  }
13753
- function prefixIssues(path6, issues) {
13896
+ function prefixIssues(path10, issues) {
13754
13897
  return issues.map((iss) => {
13755
13898
  var _a;
13756
13899
  (_a = iss).path ?? (_a.path = []);
13757
- iss.path.unshift(path6);
13900
+ iss.path.unshift(path10);
13758
13901
  return iss;
13759
13902
  });
13760
13903
  }
@@ -13922,7 +14065,7 @@ function treeifyError(error45, _mapper) {
13922
14065
  return issue2.message;
13923
14066
  };
13924
14067
  const result = { errors: [] };
13925
- const processError = (error46, path6 = []) => {
14068
+ const processError = (error46, path10 = []) => {
13926
14069
  var _a, _b;
13927
14070
  for (const issue2 of error46.issues) {
13928
14071
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -13932,7 +14075,7 @@ function treeifyError(error45, _mapper) {
13932
14075
  } else if (issue2.code === "invalid_element") {
13933
14076
  processError({ issues: issue2.issues }, issue2.path);
13934
14077
  } else {
13935
- const fullpath = [...path6, ...issue2.path];
14078
+ const fullpath = [...path10, ...issue2.path];
13936
14079
  if (fullpath.length === 0) {
13937
14080
  result.errors.push(mapper(issue2));
13938
14081
  continue;
@@ -13964,8 +14107,8 @@ function treeifyError(error45, _mapper) {
13964
14107
  }
13965
14108
  function toDotPath(_path) {
13966
14109
  const segs = [];
13967
- const path6 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
13968
- for (const seg of path6) {
14110
+ const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14111
+ for (const seg of path10) {
13969
14112
  if (typeof seg === "number")
13970
14113
  segs.push(`[${seg}]`);
13971
14114
  else if (typeof seg === "symbol")
@@ -25529,6 +25672,347 @@ function createToolExecuteAfterHook() {
25529
25672
  };
25530
25673
  }
25531
25674
 
25675
+ // src/update/refresh.ts
25676
+ import { spawn } from "node:child_process";
25677
+ import { existsSync as existsSync8 } from "node:fs";
25678
+ import path9 from "node:path";
25679
+
25680
+ // src/update/intent.ts
25681
+ import path6 from "node:path";
25682
+ var EXACT_SEMVER_REGEX = /^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
25683
+ var CREWBEE_PACKAGE_NAME2 = "crewbee";
25684
+ function findConfiguredCrewBeeReleaseIntent() {
25685
+ const configPath = resolveOpenCodeConfigPath();
25686
+ const config2 = readOpenCodeConfig(configPath).config;
25687
+ const plugins = Array.isArray(config2.plugin) ? config2.plugin : [];
25688
+ for (const entry of plugins) {
25689
+ if (typeof entry !== "string") {
25690
+ continue;
25691
+ }
25692
+ if (entry === CREWBEE_PACKAGE_NAME2) {
25693
+ return {
25694
+ configPath,
25695
+ entry,
25696
+ packageName: CREWBEE_PACKAGE_NAME2,
25697
+ requestedVersion: "latest",
25698
+ channel: "latest",
25699
+ isPinned: false,
25700
+ workspaceRoot: resolveReleaseWorkspaceRoot(entry)
25701
+ };
25702
+ }
25703
+ if (entry.startsWith(`${CREWBEE_PACKAGE_NAME2}@`)) {
25704
+ const requestedVersion = entry.slice(CREWBEE_PACKAGE_NAME2.length + 1).trim();
25705
+ if (!requestedVersion) {
25706
+ continue;
25707
+ }
25708
+ return {
25709
+ configPath,
25710
+ entry,
25711
+ packageName: CREWBEE_PACKAGE_NAME2,
25712
+ requestedVersion,
25713
+ channel: EXACT_SEMVER_REGEX.test(requestedVersion) ? "latest" : requestedVersion,
25714
+ isPinned: EXACT_SEMVER_REGEX.test(requestedVersion),
25715
+ workspaceRoot: resolveReleaseWorkspaceRoot(entry)
25716
+ };
25717
+ }
25718
+ }
25719
+ return void 0;
25720
+ }
25721
+ function resolveReleaseWorkspaceRoot(entry) {
25722
+ return path6.join(resolveInstallRoot(), "packages", sanitizePackageSpec(entry === CREWBEE_PACKAGE_NAME2 ? "crewbee@latest" : entry));
25723
+ }
25724
+ function sanitizePackageSpec(value) {
25725
+ const illegal = process.platform === "win32" ? /* @__PURE__ */ new Set(["<", ">", ":", '"', "|", "?", "*"]) : void 0;
25726
+ if (!illegal) {
25727
+ return value;
25728
+ }
25729
+ return Array.from(value, (char) => illegal.has(char) || char.charCodeAt(0) < 32 ? "_" : char).join("");
25730
+ }
25731
+
25732
+ // src/update/registry.ts
25733
+ async function fetchTargetVersion(input) {
25734
+ const url2 = `https://registry.npmjs.org/${input.intent.packageName}`;
25735
+ const payload = await input.fetchJson(url2).catch(() => void 0);
25736
+ if (!payload || typeof payload !== "object") {
25737
+ return void 0;
25738
+ }
25739
+ const distTags = "dist-tags" in payload && typeof payload["dist-tags"] === "object" && payload["dist-tags"] !== null ? payload["dist-tags"] : void 0;
25740
+ const candidate = distTags?.[input.intent.channel];
25741
+ return typeof candidate === "string" && candidate.trim().length > 0 ? candidate.trim() : void 0;
25742
+ }
25743
+
25744
+ // src/update/state.ts
25745
+ import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync5, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
25746
+ import path7 from "node:path";
25747
+ function readCrewBeeReleaseState() {
25748
+ const filePath = resolveReleaseStatePath();
25749
+ if (!existsSync6(filePath)) {
25750
+ return {};
25751
+ }
25752
+ try {
25753
+ const parsed = JSON.parse(readFileSync5(filePath, "utf8"));
25754
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
25755
+ } catch {
25756
+ return {};
25757
+ }
25758
+ }
25759
+ function writeCrewBeeReleaseState(state) {
25760
+ const filePath = resolveReleaseStatePath();
25761
+ mkdirSync4(path7.dirname(filePath), { recursive: true });
25762
+ writeFileSync4(filePath, `${JSON.stringify(state, null, 2)}
25763
+ `, "utf8");
25764
+ }
25765
+ function acquireCrewBeeReleaseLock() {
25766
+ const filePath = resolveReleaseLockPath();
25767
+ mkdirSync4(path7.dirname(filePath), { recursive: true });
25768
+ try {
25769
+ writeFileSync4(filePath, String(Date.now()), { encoding: "utf8", flag: "wx" });
25770
+ return true;
25771
+ } catch {
25772
+ return false;
25773
+ }
25774
+ }
25775
+ function releaseCrewBeeReleaseLock() {
25776
+ const filePath = resolveReleaseLockPath();
25777
+ if (!existsSync6(filePath)) {
25778
+ return;
25779
+ }
25780
+ try {
25781
+ unlinkSync(filePath);
25782
+ } catch {
25783
+ }
25784
+ }
25785
+ function resolveReleaseStatePath() {
25786
+ return path7.join(resolveInstallRoot(), "crewbee-release-state.json");
25787
+ }
25788
+ function resolveReleaseLockPath() {
25789
+ return path7.join(resolveInstallRoot(), "crewbee-release-refresh.lock");
25790
+ }
25791
+
25792
+ // src/update/workspace.ts
25793
+ import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync6, rmSync, writeFileSync as writeFileSync5 } from "node:fs";
25794
+ import path8 from "node:path";
25795
+ function readInstalledWorkspaceVersion(workspaceRoot) {
25796
+ const manifestPath = path8.join(workspaceRoot, "node_modules", "crewbee", "package.json");
25797
+ if (!existsSync7(manifestPath)) {
25798
+ return void 0;
25799
+ }
25800
+ try {
25801
+ const parsed = JSON.parse(readFileSync6(manifestPath, "utf8"));
25802
+ return typeof parsed.version === "string" ? parsed.version : void 0;
25803
+ } catch {
25804
+ return void 0;
25805
+ }
25806
+ }
25807
+ function syncWorkspaceDependencyIntent(intent, targetVersion) {
25808
+ const packageJsonPath = path8.join(intent.workspaceRoot, "package.json");
25809
+ const desiredVersion = intent.isPinned ? intent.requestedVersion : targetVersion;
25810
+ const current = readWorkspacePackageJson(packageJsonPath);
25811
+ const next = {
25812
+ ...current,
25813
+ private: true,
25814
+ name: current.name ?? `${intent.packageName}-release-workspace`,
25815
+ version: current.version ?? "0.0.0",
25816
+ dependencies: {
25817
+ ...current.dependencies ?? {},
25818
+ [intent.packageName]: desiredVersion
25819
+ }
25820
+ };
25821
+ const changed = JSON.stringify(current) !== JSON.stringify(next);
25822
+ if (changed) {
25823
+ mkdirSync5(intent.workspaceRoot, { recursive: true });
25824
+ writeFileSync5(packageJsonPath, `${JSON.stringify(next, null, 2)}
25825
+ `, "utf8");
25826
+ }
25827
+ return { changed };
25828
+ }
25829
+ function invalidateWorkspacePackage(intent) {
25830
+ const packageRoot = path8.join(intent.workspaceRoot, "node_modules", intent.packageName);
25831
+ const lockPath = path8.join(intent.workspaceRoot, "package-lock.json");
25832
+ let changed = false;
25833
+ if (existsSync7(packageRoot)) {
25834
+ rmSync(packageRoot, { recursive: true, force: true });
25835
+ changed = true;
25836
+ }
25837
+ if (existsSync7(lockPath)) {
25838
+ rmSync(lockPath, { force: true });
25839
+ changed = true;
25840
+ }
25841
+ return changed;
25842
+ }
25843
+ function readWorkspacePackageJson(packageJsonPath) {
25844
+ if (!existsSync7(packageJsonPath)) {
25845
+ return {};
25846
+ }
25847
+ try {
25848
+ const parsed = JSON.parse(readFileSync6(packageJsonPath, "utf8"));
25849
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
25850
+ } catch {
25851
+ return {};
25852
+ }
25853
+ }
25854
+
25855
+ // src/update/refresh.ts
25856
+ var SUCCESS_RECHECK_MS = 60 * 60 * 1e3;
25857
+ var FAILURE_RECHECK_MS = 30 * 60 * 1e3;
25858
+ function startBackgroundReleaseRefresh(ctx, deps = createDefaultDependencies()) {
25859
+ if (!shouldEnableCrewBeeReleaseRefresh()) {
25860
+ return;
25861
+ }
25862
+ queueMicrotask(() => {
25863
+ void runBackgroundReleaseRefresh(ctx, deps).catch(() => void 0);
25864
+ });
25865
+ }
25866
+ async function runBackgroundReleaseRefresh(ctx, deps) {
25867
+ if (!acquireCrewBeeReleaseLock()) {
25868
+ await logCrewBee(ctx, "CrewBee release refresh skipped because another refresh is already running", void 0, "debug");
25869
+ return { needsRefresh: false, reason: "up-to-date" };
25870
+ }
25871
+ try {
25872
+ const intent = findConfiguredCrewBeeReleaseIntent();
25873
+ if (!intent) {
25874
+ await logCrewBee(ctx, "CrewBee release refresh skipped because plugin is not configured", void 0, "debug");
25875
+ return { needsRefresh: false, reason: "plugin-not-configured" };
25876
+ }
25877
+ const state = readCrewBeeReleaseState();
25878
+ const now = Date.now();
25879
+ const currentVersion = readInstalledWorkspaceVersion(intent.workspaceRoot) ?? state.lastKnownVersion;
25880
+ if (shouldSkipByCooldown(state, now)) {
25881
+ await logCrewBee(ctx, "CrewBee release refresh skipped by cooldown", {
25882
+ currentVersion,
25883
+ lastCheckedAt: state.lastCheckedAt,
25884
+ lastFailureAt: state.lastFailureAt,
25885
+ lastSucceededAt: state.lastSucceededAt
25886
+ }, "debug");
25887
+ return { currentVersion, needsRefresh: false, reason: "up-to-date" };
25888
+ }
25889
+ if (intent.isPinned) {
25890
+ await logCrewBee(ctx, "CrewBee release refresh skipped for pinned version", {
25891
+ entry: intent.entry,
25892
+ pinnedVersion: intent.requestedVersion,
25893
+ currentVersion
25894
+ });
25895
+ return { currentVersion, latestVersion: intent.requestedVersion, needsRefresh: false, reason: "pinned-version" };
25896
+ }
25897
+ const latestVersion = await fetchTargetVersion({ intent, fetchJson: deps.fetchJson });
25898
+ if (!latestVersion) {
25899
+ writeCrewBeeReleaseState({
25900
+ ...state,
25901
+ lastCheckedAt: now
25902
+ });
25903
+ await logCrewBee(ctx, "CrewBee release refresh could not resolve latest version", {
25904
+ entry: intent.entry,
25905
+ channel: intent.channel,
25906
+ currentVersion
25907
+ }, "warn");
25908
+ return { currentVersion, needsRefresh: false, reason: "latest-unavailable" };
25909
+ }
25910
+ if (currentVersion === latestVersion) {
25911
+ writeCrewBeeReleaseState({
25912
+ ...state,
25913
+ lastCheckedAt: now,
25914
+ lastKnownVersion: currentVersion,
25915
+ lastFailure: void 0,
25916
+ lastFailureAt: void 0,
25917
+ lastSucceededAt: now
25918
+ });
25919
+ await logCrewBee(ctx, "CrewBee release refresh found current version already up to date", {
25920
+ currentVersion,
25921
+ latestVersion,
25922
+ workspaceRoot: intent.workspaceRoot
25923
+ }, "debug");
25924
+ return { currentVersion, latestVersion, needsRefresh: false, reason: "up-to-date" };
25925
+ }
25926
+ await logCrewBee(ctx, "CrewBee release refresh found newer version", {
25927
+ currentVersion,
25928
+ latestVersion,
25929
+ workspaceRoot: intent.workspaceRoot,
25930
+ entry: intent.entry
25931
+ });
25932
+ syncWorkspaceDependencyIntent(intent, latestVersion);
25933
+ invalidateWorkspacePackage(intent);
25934
+ const installed = await deps.runInstall(intent.workspaceRoot);
25935
+ if (!installed) {
25936
+ writeCrewBeeReleaseState({
25937
+ ...state,
25938
+ lastCheckedAt: now,
25939
+ lastAttemptedVersion: latestVersion,
25940
+ lastFailure: `Failed to install ${latestVersion}`,
25941
+ lastFailureAt: now,
25942
+ lastKnownVersion: currentVersion
25943
+ });
25944
+ await logCrewBee(ctx, "CrewBee release refresh failed to install latest version", {
25945
+ currentVersion,
25946
+ latestVersion,
25947
+ workspaceRoot: intent.workspaceRoot
25948
+ }, "warn");
25949
+ return { currentVersion, latestVersion, needsRefresh: true, reason: "refresh-required" };
25950
+ }
25951
+ writeCrewBeeReleaseState({
25952
+ lastCheckedAt: now,
25953
+ lastAttemptedVersion: latestVersion,
25954
+ lastKnownVersion: latestVersion,
25955
+ lastFailure: void 0,
25956
+ lastFailureAt: void 0,
25957
+ lastSucceededAt: now
25958
+ });
25959
+ await logCrewBee(ctx, "CrewBee release refresh installed newer version", {
25960
+ currentVersion,
25961
+ latestVersion,
25962
+ workspaceRoot: intent.workspaceRoot
25963
+ });
25964
+ return { currentVersion, latestVersion, needsRefresh: true, reason: "refresh-required" };
25965
+ } finally {
25966
+ releaseCrewBeeReleaseLock();
25967
+ }
25968
+ }
25969
+ function shouldEnableCrewBeeReleaseRefresh(currentPackageRoot = resolveCurrentPackageRoot()) {
25970
+ const override = process.env.CREWBEE_AUTO_UPDATE?.trim().toLowerCase();
25971
+ if (override === "1" || override === "true" || override === "on") {
25972
+ return true;
25973
+ }
25974
+ if (override === "0" || override === "false" || override === "off") {
25975
+ return false;
25976
+ }
25977
+ if (process.env.NODE_ENV === "test") {
25978
+ return false;
25979
+ }
25980
+ return !existsSync8(path9.join(currentPackageRoot, ".git"));
25981
+ }
25982
+ function shouldSkipByCooldown(state, now) {
25983
+ if (state.lastFailureAt && now - state.lastFailureAt < FAILURE_RECHECK_MS) {
25984
+ return true;
25985
+ }
25986
+ if (state.lastSucceededAt && now - state.lastSucceededAt < SUCCESS_RECHECK_MS) {
25987
+ return true;
25988
+ }
25989
+ return false;
25990
+ }
25991
+ function resolveCurrentPackageRoot() {
25992
+ return path9.resolve(__dirname, "../..");
25993
+ }
25994
+ function createDefaultDependencies() {
25995
+ return {
25996
+ async fetchJson(url2) {
25997
+ const response = await fetch(url2);
25998
+ if (!response.ok) {
25999
+ throw new Error(`Failed to fetch ${url2}: ${response.status}`);
26000
+ }
26001
+ return response.json();
26002
+ },
26003
+ async runInstall(workspaceRoot) {
26004
+ return new Promise((resolve) => {
26005
+ const child = spawn("npm", ["install", "--prefix", workspaceRoot, "--no-audit", "--no-fund"], {
26006
+ shell: process.platform === "win32",
26007
+ stdio: "ignore"
26008
+ });
26009
+ child.on("error", () => resolve(false));
26010
+ child.on("exit", (code) => resolve(code === 0));
26011
+ });
26012
+ }
26013
+ };
26014
+ }
26015
+
25532
26016
  // src/adapters/opencode/plugin.ts
25533
26017
  var OpenCodeCrewBeePlugin = async (ctx) => {
25534
26018
  const crewbeeConfigUpdate = ensureCrewBeeConfigFile({
@@ -25551,6 +26035,7 @@ var OpenCodeCrewBeePlugin = async (ctx) => {
25551
26035
  visibleAgentCount: initial.boot.projectedAgents.filter((agent) => !agent.hidden).length,
25552
26036
  defaultAgent: initial.boot.configPatch.defaultAgent
25553
26037
  });
26038
+ startBackgroundReleaseRefresh(ctx);
25554
26039
  let boot = initial.boot;
25555
26040
  let aliasIndex = initial.aliasIndex;
25556
26041
  const bindings = /* @__PURE__ */ new Map();