crewbee 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/opencode-plugin.mjs +634 -127
  2. package/dist/src/adapters/opencode/bootstrap.d.ts.map +1 -1
  3. package/dist/src/adapters/opencode/bootstrap.js +11 -17
  4. package/dist/src/adapters/opencode/bootstrap.js.map +1 -1
  5. package/dist/src/adapters/opencode/coexistence.js +1 -1
  6. package/dist/src/adapters/opencode/coexistence.js.map +1 -1
  7. package/dist/src/adapters/opencode/config-merge.d.ts.map +1 -1
  8. package/dist/src/adapters/opencode/config-merge.js +9 -13
  9. package/dist/src/adapters/opencode/config-merge.js.map +1 -1
  10. package/dist/src/adapters/opencode/ownership.d.ts +12 -0
  11. package/dist/src/adapters/opencode/ownership.d.ts.map +1 -0
  12. package/dist/src/adapters/opencode/ownership.js +29 -0
  13. package/dist/src/adapters/opencode/ownership.js.map +1 -0
  14. package/dist/src/adapters/opencode/plugin.d.ts.map +1 -1
  15. package/dist/src/adapters/opencode/plugin.js +2 -0
  16. package/dist/src/adapters/opencode/plugin.js.map +1 -1
  17. package/dist/src/adapters/opencode/projection.d.ts.map +1 -1
  18. package/dist/src/adapters/opencode/projection.js +6 -1
  19. package/dist/src/adapters/opencode/projection.js.map +1 -1
  20. package/dist/src/update/intent.d.ts +3 -0
  21. package/dist/src/update/intent.d.ts.map +1 -0
  22. package/dist/src/update/intent.js +58 -0
  23. package/dist/src/update/intent.js.map +1 -0
  24. package/dist/src/update/refresh.d.ts +6 -0
  25. package/dist/src/update/refresh.d.ts.map +1 -0
  26. package/dist/src/update/refresh.js +177 -0
  27. package/dist/src/update/refresh.js.map +1 -0
  28. package/dist/src/update/registry.d.ts +6 -0
  29. package/dist/src/update/registry.d.ts.map +1 -0
  30. package/dist/src/update/registry.js +16 -0
  31. package/dist/src/update/registry.js.map +1 -0
  32. package/dist/src/update/state.d.ts +13 -0
  33. package/dist/src/update/state.d.ts.map +1 -0
  34. package/dist/src/update/state.js +60 -0
  35. package/dist/src/update/state.js.map +1 -0
  36. package/dist/src/update/types.d.ts +20 -0
  37. package/dist/src/update/types.d.ts.map +1 -0
  38. package/dist/src/update/types.js +3 -0
  39. package/dist/src/update/types.js.map +1 -0
  40. package/dist/src/update/workspace.d.ts +7 -0
  41. package/dist/src/update/workspace.d.ts.map +1 -0
  42. package/dist/src/update/workspace.js +71 -0
  43. package/dist/src/update/workspace.js.map +1 -0
  44. package/package.json +1 -1
@@ -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;
@@ -11366,6 +11509,32 @@ function createOpenCodePermissionConfig(permissionRules) {
11366
11509
  return permission;
11367
11510
  }
11368
11511
 
11512
+ // src/adapters/opencode/ownership.ts
11513
+ function isRecord4(value) {
11514
+ return typeof value === "object" && value !== null;
11515
+ }
11516
+ function isManagedCrewBeeAgentDefinition(value) {
11517
+ if (!isRecord4(value)) {
11518
+ return false;
11519
+ }
11520
+ const options = value.options;
11521
+ if (!isRecord4(options)) {
11522
+ return false;
11523
+ }
11524
+ const crewbee = options.crewbee;
11525
+ return isRecord4(crewbee) && crewbee.managed === true;
11526
+ }
11527
+ function createManagedCrewBeeAgentOptions(input) {
11528
+ return {
11529
+ ...input.existingOptions ?? {},
11530
+ crewbee: {
11531
+ managed: true,
11532
+ teamId: input.teamId,
11533
+ canonicalAgentId: input.canonicalAgentId
11534
+ }
11535
+ };
11536
+ }
11537
+
11369
11538
  // src/catalog/build-prompt-catalog.ts
11370
11539
  function formatDisplayLabel(key) {
11371
11540
  return key.replace(/_/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
@@ -11382,11 +11551,11 @@ function detectNodeKind(value) {
11382
11551
  }
11383
11552
  return "scalar";
11384
11553
  }
11385
- function buildNode(path6, key, value, order) {
11554
+ function buildNode(path10, key, value, order) {
11386
11555
  const kind = detectNodeKind(value);
11387
11556
  if (kind !== "object") {
11388
11557
  return {
11389
- path: path6,
11558
+ path: path10,
11390
11559
  key,
11391
11560
  label: toTitleLabel(key),
11392
11561
  kind,
@@ -11396,10 +11565,10 @@ function buildNode(path6, key, value, order) {
11396
11565
  };
11397
11566
  }
11398
11567
  const children = Object.entries(value).map(
11399
- ([childKey, childValue], index) => buildNode(`${path6}.${childKey}`, childKey, childValue, index)
11568
+ ([childKey, childValue], index) => buildNode(`${path10}.${childKey}`, childKey, childValue, index)
11400
11569
  );
11401
11570
  return {
11402
- path: path6,
11571
+ path: path10,
11403
11572
  key,
11404
11573
  label: toTitleLabel(key),
11405
11574
  kind,
@@ -11440,7 +11609,7 @@ function buildPromptCatalog(doc) {
11440
11609
  }
11441
11610
 
11442
11611
  // src/normalize/build-agent-prompt-source.ts
11443
- function isRecord4(value) {
11612
+ function isRecord5(value) {
11444
11613
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
11445
11614
  }
11446
11615
  function toSnakeCase2(value) {
@@ -11450,7 +11619,7 @@ function toSnakeCaseValue(value) {
11450
11619
  if (Array.isArray(value)) {
11451
11620
  return value.map((entry) => toSnakeCaseValue(entry));
11452
11621
  }
11453
- if (!isRecord4(value)) {
11622
+ if (!isRecord5(value)) {
11454
11623
  return value;
11455
11624
  }
11456
11625
  return Object.fromEntries(
@@ -11634,13 +11803,13 @@ var AGENT_SECTION_ORDER = [
11634
11803
  "tool_skill_strategy"
11635
11804
  ];
11636
11805
  var TEAM_SECTION_ORDER = ["working_rules", "approval_safety"];
11637
- function sectionRank(kind, path6) {
11806
+ function sectionRank(kind, path10) {
11638
11807
  const list = kind === "team" ? TEAM_SECTION_ORDER : AGENT_SECTION_ORDER;
11639
- const index = list.indexOf(path6);
11808
+ const index = list.indexOf(path10);
11640
11809
  return index === -1 ? Number.POSITIVE_INFINITY : index;
11641
11810
  }
11642
- function resolveSectionTitle(path6, fallback) {
11643
- return CANONICAL_SECTION_TITLES[path6] ?? fallback;
11811
+ function resolveSectionTitle(path10, fallback) {
11812
+ return CANONICAL_SECTION_TITLES[path10] ?? fallback;
11644
11813
  }
11645
11814
  function buildPromptPlan(catalog) {
11646
11815
  return {
@@ -11660,8 +11829,8 @@ function buildPromptPlan(catalog) {
11660
11829
  }
11661
11830
 
11662
11831
  // src/projection/apply-prompt-projection.ts
11663
- function matchesPath(selected, path6) {
11664
- return selected === path6 || path6.startsWith(`${selected}.`);
11832
+ function matchesPath(selected, path10) {
11833
+ return selected === path10 || path10.startsWith(`${selected}.`);
11665
11834
  }
11666
11835
  function isAncestorPath(ancestor, descendant) {
11667
11836
  return descendant === ancestor || descendant.startsWith(`${ancestor}.`);
@@ -11911,7 +12080,11 @@ function createOpenCodeAgentDefinition(agent) {
11911
12080
  variant: agent.resolvedModel?.variant,
11912
12081
  prompt: agent.prompt,
11913
12082
  permission: createOpenCodePermissionConfig(agent.permission),
11914
- options: agent.resolvedModel?.options
12083
+ options: createManagedCrewBeeAgentOptions({
12084
+ teamId: agent.teamId,
12085
+ canonicalAgentId: agent.canonicalAgentId,
12086
+ existingOptions: agent.resolvedModel?.options
12087
+ })
11915
12088
  };
11916
12089
  }
11917
12090
  function createOpenCodeProjectedIdentities(agent) {
@@ -12115,19 +12288,16 @@ function createOpenCodeCapabilityContract() {
12115
12288
  }
12116
12289
 
12117
12290
  // src/adapters/opencode/config-merge.ts
12118
- var CURRENT_PLUGIN_KEY_PREFIX = "crewbee.";
12119
- var LEGACY_PLUGIN_KEY_PREFIX = "agentscroll.";
12120
- function isLegacyCrewBeeOwnedKey(key) {
12121
- return key.startsWith(LEGACY_PLUGIN_KEY_PREFIX);
12122
- }
12123
- function isCrewBeeOwnedKey(key) {
12124
- return key.startsWith(CURRENT_PLUGIN_KEY_PREFIX);
12125
- }
12126
- function isCompatibleCrewBeeOwnedKey(key) {
12127
- return isCrewBeeOwnedKey(key) || isLegacyCrewBeeOwnedKey(key);
12128
- }
12129
12291
  function applyOpenCodeAgentConfigPatch(config2, patch) {
12130
- const nextAgents = { ...config2.agent ?? {} };
12292
+ const patchKeys = new Set(Object.keys(patch.agent));
12293
+ const nextAgents = Object.fromEntries(
12294
+ Object.entries(config2.agent ?? {}).filter(([key, definition]) => {
12295
+ if (isManagedCrewBeeAgentDefinition(definition) && !patchKeys.has(key)) {
12296
+ return false;
12297
+ }
12298
+ return true;
12299
+ })
12300
+ );
12131
12301
  const insertedAgentKeys = [];
12132
12302
  const updatedAgentKeys = [];
12133
12303
  const skippedAgentKeys = [];
@@ -12138,7 +12308,7 @@ function applyOpenCodeAgentConfigPatch(config2, patch) {
12138
12308
  continue;
12139
12309
  }
12140
12310
  const existingDefinition = nextAgents[key];
12141
- if (isCompatibleCrewBeeOwnedKey(key)) {
12311
+ if (isManagedCrewBeeAgentDefinition(existingDefinition)) {
12142
12312
  nextAgents[key] = definition;
12143
12313
  updatedAgentKeys.push(key);
12144
12314
  continue;
@@ -12167,7 +12337,7 @@ function createOpenCodeCoexistencePolicy() {
12167
12337
  dependsOnOhMyOpenCode: false,
12168
12338
  featureDevelopmentMode: "mutually-exclusive",
12169
12339
  safeWhenCoInstalled: true,
12170
- reservedConfigKeyPrefix: "crewbee.",
12340
+ reservedConfigKeyPrefix: "",
12171
12341
  neverMutateForeignAgents: true
12172
12342
  };
12173
12343
  }
@@ -12191,8 +12361,6 @@ function createOpenCodeToolDomainPlan() {
12191
12361
  }
12192
12362
 
12193
12363
  // src/adapters/opencode/bootstrap.ts
12194
- var CURRENT_PLUGIN_KEY_PREFIX2 = "crewbee.";
12195
- var LEGACY_PLUGIN_KEY_PREFIX2 = "agentscroll.";
12196
12364
  function createOpenCodeAdapterDefinition() {
12197
12365
  const coexistence = createOpenCodeCoexistencePolicy();
12198
12366
  return {
@@ -12215,9 +12383,8 @@ function createOpenCodeAdapterDefinition() {
12215
12383
  }
12216
12384
  function resolveBindingAgent(input) {
12217
12385
  if (input.selectedHostAgent) {
12218
- const normalizedHostAgent = input.selectedHostAgent.startsWith(LEGACY_PLUGIN_KEY_PREFIX2) ? `${CURRENT_PLUGIN_KEY_PREFIX2}${input.selectedHostAgent.slice(LEGACY_PLUGIN_KEY_PREFIX2.length)}` : input.selectedHostAgent;
12219
12386
  const hostSelection = resolveProjectedAgentSelection(input.projectedAgents, {
12220
- configKey: normalizedHostAgent
12387
+ configKey: input.selectedHostAgent
12221
12388
  });
12222
12389
  if (hostSelection) {
12223
12390
  return {
@@ -12261,24 +12428,22 @@ function filterSafeProjectedAgents(agents, collisions) {
12261
12428
  return true;
12262
12429
  });
12263
12430
  }
12264
- function isCompatibleCrewBeeOwnedKey2(key) {
12265
- return key.startsWith(CURRENT_PLUGIN_KEY_PREFIX2) || key.startsWith(LEGACY_PLUGIN_KEY_PREFIX2);
12266
- }
12267
12431
  function getForeignCollisionInputs(input) {
12432
+ const fallbackKeys = input.existingConfig?.agent ? Object.keys(input.existingConfig.agent) : input.existingConfigKeys;
12268
12433
  if (!input.existingConfig?.agent) {
12269
12434
  return {
12270
- existingConfigKeys: input.existingConfigKeys
12435
+ existingConfigKeys: fallbackKeys
12271
12436
  };
12272
12437
  }
12273
- const compatibleOwnedConfigKeys = /* @__PURE__ */ new Set();
12274
- for (const [key, definition] of Object.entries(input.existingConfig.agent)) {
12275
- if (!isCompatibleCrewBeeOwnedKey2(key)) {
12276
- continue;
12438
+ const foreignKeys = (fallbackKeys ?? []).filter((key) => {
12439
+ const definition = input.existingConfig?.agent?.[key];
12440
+ if (isManagedCrewBeeAgentDefinition(definition)) {
12441
+ return false;
12277
12442
  }
12278
- compatibleOwnedConfigKeys.add(key);
12279
- }
12443
+ return true;
12444
+ });
12280
12445
  return {
12281
- existingConfigKeys: input.existingConfigKeys?.filter((key) => !compatibleOwnedConfigKeys.has(key))
12446
+ existingConfigKeys: foreignKeys
12282
12447
  };
12283
12448
  }
12284
12449
  function shouldSetDefaultAgent(input) {
@@ -12516,7 +12681,7 @@ function createEventHook(ctx, store) {
12516
12681
 
12517
12682
  // src/adapters/opencode/delegation/store.ts
12518
12683
  import { createHash, randomUUID } from "node:crypto";
12519
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
12684
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
12520
12685
  import path5 from "node:path";
12521
12686
  function createEmptyState() {
12522
12687
  return {
@@ -12633,11 +12798,11 @@ var DelegateStateStore = class {
12633
12798
  if (this.cache) {
12634
12799
  return this.cache;
12635
12800
  }
12636
- if (!existsSync4(this.filePath)) {
12801
+ if (!existsSync5(this.filePath)) {
12637
12802
  this.cache = createEmptyState();
12638
12803
  return this.cache;
12639
12804
  }
12640
- const raw = readFileSync3(this.filePath, "utf8");
12805
+ const raw = readFileSync4(this.filePath, "utf8");
12641
12806
  const parsed = JSON.parse(raw);
12642
12807
  this.cache = {
12643
12808
  version: 1,
@@ -12648,9 +12813,9 @@ var DelegateStateStore = class {
12648
12813
  return this.cache;
12649
12814
  }
12650
12815
  write(state) {
12651
- mkdirSync2(path5.dirname(this.filePath), { recursive: true });
12816
+ mkdirSync3(path5.dirname(this.filePath), { recursive: true });
12652
12817
  this.cache = state;
12653
- writeFileSync2(this.filePath, `${JSON.stringify(state, null, 2)}
12818
+ writeFileSync3(this.filePath, `${JSON.stringify(state, null, 2)}
12654
12819
  `, "utf8");
12655
12820
  }
12656
12821
  };
@@ -13386,10 +13551,10 @@ function mergeDefs(...defs) {
13386
13551
  function cloneDef(schema) {
13387
13552
  return mergeDefs(schema._zod.def);
13388
13553
  }
13389
- function getElementAtPath(obj, path6) {
13390
- if (!path6)
13554
+ function getElementAtPath(obj, path10) {
13555
+ if (!path10)
13391
13556
  return obj;
13392
- return path6.reduce((acc, key) => acc?.[key], obj);
13557
+ return path10.reduce((acc, key) => acc?.[key], obj);
13393
13558
  }
13394
13559
  function promiseAllObject(promisesObj) {
13395
13560
  const keys = Object.keys(promisesObj);
@@ -13750,11 +13915,11 @@ function aborted(x, startIndex = 0) {
13750
13915
  }
13751
13916
  return false;
13752
13917
  }
13753
- function prefixIssues(path6, issues) {
13918
+ function prefixIssues(path10, issues) {
13754
13919
  return issues.map((iss) => {
13755
13920
  var _a;
13756
13921
  (_a = iss).path ?? (_a.path = []);
13757
- iss.path.unshift(path6);
13922
+ iss.path.unshift(path10);
13758
13923
  return iss;
13759
13924
  });
13760
13925
  }
@@ -13922,7 +14087,7 @@ function treeifyError(error45, _mapper) {
13922
14087
  return issue2.message;
13923
14088
  };
13924
14089
  const result = { errors: [] };
13925
- const processError = (error46, path6 = []) => {
14090
+ const processError = (error46, path10 = []) => {
13926
14091
  var _a, _b;
13927
14092
  for (const issue2 of error46.issues) {
13928
14093
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -13932,7 +14097,7 @@ function treeifyError(error45, _mapper) {
13932
14097
  } else if (issue2.code === "invalid_element") {
13933
14098
  processError({ issues: issue2.issues }, issue2.path);
13934
14099
  } else {
13935
- const fullpath = [...path6, ...issue2.path];
14100
+ const fullpath = [...path10, ...issue2.path];
13936
14101
  if (fullpath.length === 0) {
13937
14102
  result.errors.push(mapper(issue2));
13938
14103
  continue;
@@ -13964,8 +14129,8 @@ function treeifyError(error45, _mapper) {
13964
14129
  }
13965
14130
  function toDotPath(_path) {
13966
14131
  const segs = [];
13967
- const path6 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
13968
- for (const seg of path6) {
14132
+ const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
14133
+ for (const seg of path10) {
13969
14134
  if (typeof seg === "number")
13970
14135
  segs.push(`[${seg}]`);
13971
14136
  else if (typeof seg === "symbol")
@@ -25529,6 +25694,347 @@ function createToolExecuteAfterHook() {
25529
25694
  };
25530
25695
  }
25531
25696
 
25697
+ // src/update/refresh.ts
25698
+ import { spawn } from "node:child_process";
25699
+ import { existsSync as existsSync8 } from "node:fs";
25700
+ import path9 from "node:path";
25701
+
25702
+ // src/update/intent.ts
25703
+ import path6 from "node:path";
25704
+ var EXACT_SEMVER_REGEX = /^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
25705
+ var CREWBEE_PACKAGE_NAME2 = "crewbee";
25706
+ function findConfiguredCrewBeeReleaseIntent() {
25707
+ const configPath = resolveOpenCodeConfigPath();
25708
+ const config2 = readOpenCodeConfig(configPath).config;
25709
+ const plugins = Array.isArray(config2.plugin) ? config2.plugin : [];
25710
+ for (const entry of plugins) {
25711
+ if (typeof entry !== "string") {
25712
+ continue;
25713
+ }
25714
+ if (entry === CREWBEE_PACKAGE_NAME2) {
25715
+ return {
25716
+ configPath,
25717
+ entry,
25718
+ packageName: CREWBEE_PACKAGE_NAME2,
25719
+ requestedVersion: "latest",
25720
+ channel: "latest",
25721
+ isPinned: false,
25722
+ workspaceRoot: resolveReleaseWorkspaceRoot(entry)
25723
+ };
25724
+ }
25725
+ if (entry.startsWith(`${CREWBEE_PACKAGE_NAME2}@`)) {
25726
+ const requestedVersion = entry.slice(CREWBEE_PACKAGE_NAME2.length + 1).trim();
25727
+ if (!requestedVersion) {
25728
+ continue;
25729
+ }
25730
+ return {
25731
+ configPath,
25732
+ entry,
25733
+ packageName: CREWBEE_PACKAGE_NAME2,
25734
+ requestedVersion,
25735
+ channel: EXACT_SEMVER_REGEX.test(requestedVersion) ? "latest" : requestedVersion,
25736
+ isPinned: EXACT_SEMVER_REGEX.test(requestedVersion),
25737
+ workspaceRoot: resolveReleaseWorkspaceRoot(entry)
25738
+ };
25739
+ }
25740
+ }
25741
+ return void 0;
25742
+ }
25743
+ function resolveReleaseWorkspaceRoot(entry) {
25744
+ return path6.join(resolveInstallRoot(), "packages", sanitizePackageSpec(entry === CREWBEE_PACKAGE_NAME2 ? "crewbee@latest" : entry));
25745
+ }
25746
+ function sanitizePackageSpec(value) {
25747
+ const illegal = process.platform === "win32" ? /* @__PURE__ */ new Set(["<", ">", ":", '"', "|", "?", "*"]) : void 0;
25748
+ if (!illegal) {
25749
+ return value;
25750
+ }
25751
+ return Array.from(value, (char) => illegal.has(char) || char.charCodeAt(0) < 32 ? "_" : char).join("");
25752
+ }
25753
+
25754
+ // src/update/registry.ts
25755
+ async function fetchTargetVersion(input) {
25756
+ const url2 = `https://registry.npmjs.org/${input.intent.packageName}`;
25757
+ const payload = await input.fetchJson(url2).catch(() => void 0);
25758
+ if (!payload || typeof payload !== "object") {
25759
+ return void 0;
25760
+ }
25761
+ const distTags = "dist-tags" in payload && typeof payload["dist-tags"] === "object" && payload["dist-tags"] !== null ? payload["dist-tags"] : void 0;
25762
+ const candidate = distTags?.[input.intent.channel];
25763
+ return typeof candidate === "string" && candidate.trim().length > 0 ? candidate.trim() : void 0;
25764
+ }
25765
+
25766
+ // src/update/state.ts
25767
+ import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync5, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
25768
+ import path7 from "node:path";
25769
+ function readCrewBeeReleaseState() {
25770
+ const filePath = resolveReleaseStatePath();
25771
+ if (!existsSync6(filePath)) {
25772
+ return {};
25773
+ }
25774
+ try {
25775
+ const parsed = JSON.parse(readFileSync5(filePath, "utf8"));
25776
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
25777
+ } catch {
25778
+ return {};
25779
+ }
25780
+ }
25781
+ function writeCrewBeeReleaseState(state) {
25782
+ const filePath = resolveReleaseStatePath();
25783
+ mkdirSync4(path7.dirname(filePath), { recursive: true });
25784
+ writeFileSync4(filePath, `${JSON.stringify(state, null, 2)}
25785
+ `, "utf8");
25786
+ }
25787
+ function acquireCrewBeeReleaseLock() {
25788
+ const filePath = resolveReleaseLockPath();
25789
+ mkdirSync4(path7.dirname(filePath), { recursive: true });
25790
+ try {
25791
+ writeFileSync4(filePath, String(Date.now()), { encoding: "utf8", flag: "wx" });
25792
+ return true;
25793
+ } catch {
25794
+ return false;
25795
+ }
25796
+ }
25797
+ function releaseCrewBeeReleaseLock() {
25798
+ const filePath = resolveReleaseLockPath();
25799
+ if (!existsSync6(filePath)) {
25800
+ return;
25801
+ }
25802
+ try {
25803
+ unlinkSync(filePath);
25804
+ } catch {
25805
+ }
25806
+ }
25807
+ function resolveReleaseStatePath() {
25808
+ return path7.join(resolveInstallRoot(), "crewbee-release-state.json");
25809
+ }
25810
+ function resolveReleaseLockPath() {
25811
+ return path7.join(resolveInstallRoot(), "crewbee-release-refresh.lock");
25812
+ }
25813
+
25814
+ // src/update/workspace.ts
25815
+ import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync6, rmSync, writeFileSync as writeFileSync5 } from "node:fs";
25816
+ import path8 from "node:path";
25817
+ function readInstalledWorkspaceVersion(workspaceRoot) {
25818
+ const manifestPath = path8.join(workspaceRoot, "node_modules", "crewbee", "package.json");
25819
+ if (!existsSync7(manifestPath)) {
25820
+ return void 0;
25821
+ }
25822
+ try {
25823
+ const parsed = JSON.parse(readFileSync6(manifestPath, "utf8"));
25824
+ return typeof parsed.version === "string" ? parsed.version : void 0;
25825
+ } catch {
25826
+ return void 0;
25827
+ }
25828
+ }
25829
+ function syncWorkspaceDependencyIntent(intent, targetVersion) {
25830
+ const packageJsonPath = path8.join(intent.workspaceRoot, "package.json");
25831
+ const desiredVersion = intent.isPinned ? intent.requestedVersion : targetVersion;
25832
+ const current = readWorkspacePackageJson(packageJsonPath);
25833
+ const next = {
25834
+ ...current,
25835
+ private: true,
25836
+ name: current.name ?? `${intent.packageName}-release-workspace`,
25837
+ version: current.version ?? "0.0.0",
25838
+ dependencies: {
25839
+ ...current.dependencies ?? {},
25840
+ [intent.packageName]: desiredVersion
25841
+ }
25842
+ };
25843
+ const changed = JSON.stringify(current) !== JSON.stringify(next);
25844
+ if (changed) {
25845
+ mkdirSync5(intent.workspaceRoot, { recursive: true });
25846
+ writeFileSync5(packageJsonPath, `${JSON.stringify(next, null, 2)}
25847
+ `, "utf8");
25848
+ }
25849
+ return { changed };
25850
+ }
25851
+ function invalidateWorkspacePackage(intent) {
25852
+ const packageRoot = path8.join(intent.workspaceRoot, "node_modules", intent.packageName);
25853
+ const lockPath = path8.join(intent.workspaceRoot, "package-lock.json");
25854
+ let changed = false;
25855
+ if (existsSync7(packageRoot)) {
25856
+ rmSync(packageRoot, { recursive: true, force: true });
25857
+ changed = true;
25858
+ }
25859
+ if (existsSync7(lockPath)) {
25860
+ rmSync(lockPath, { force: true });
25861
+ changed = true;
25862
+ }
25863
+ return changed;
25864
+ }
25865
+ function readWorkspacePackageJson(packageJsonPath) {
25866
+ if (!existsSync7(packageJsonPath)) {
25867
+ return {};
25868
+ }
25869
+ try {
25870
+ const parsed = JSON.parse(readFileSync6(packageJsonPath, "utf8"));
25871
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
25872
+ } catch {
25873
+ return {};
25874
+ }
25875
+ }
25876
+
25877
+ // src/update/refresh.ts
25878
+ var SUCCESS_RECHECK_MS = 60 * 60 * 1e3;
25879
+ var FAILURE_RECHECK_MS = 30 * 60 * 1e3;
25880
+ function startBackgroundReleaseRefresh(ctx, deps = createDefaultDependencies()) {
25881
+ if (!shouldEnableCrewBeeReleaseRefresh()) {
25882
+ return;
25883
+ }
25884
+ queueMicrotask(() => {
25885
+ void runBackgroundReleaseRefresh(ctx, deps).catch(() => void 0);
25886
+ });
25887
+ }
25888
+ async function runBackgroundReleaseRefresh(ctx, deps) {
25889
+ if (!acquireCrewBeeReleaseLock()) {
25890
+ await logCrewBee(ctx, "CrewBee release refresh skipped because another refresh is already running", void 0, "debug");
25891
+ return { needsRefresh: false, reason: "up-to-date" };
25892
+ }
25893
+ try {
25894
+ const intent = findConfiguredCrewBeeReleaseIntent();
25895
+ if (!intent) {
25896
+ await logCrewBee(ctx, "CrewBee release refresh skipped because plugin is not configured", void 0, "debug");
25897
+ return { needsRefresh: false, reason: "plugin-not-configured" };
25898
+ }
25899
+ const state = readCrewBeeReleaseState();
25900
+ const now = Date.now();
25901
+ const currentVersion = readInstalledWorkspaceVersion(intent.workspaceRoot) ?? state.lastKnownVersion;
25902
+ if (shouldSkipByCooldown(state, now)) {
25903
+ await logCrewBee(ctx, "CrewBee release refresh skipped by cooldown", {
25904
+ currentVersion,
25905
+ lastCheckedAt: state.lastCheckedAt,
25906
+ lastFailureAt: state.lastFailureAt,
25907
+ lastSucceededAt: state.lastSucceededAt
25908
+ }, "debug");
25909
+ return { currentVersion, needsRefresh: false, reason: "up-to-date" };
25910
+ }
25911
+ if (intent.isPinned) {
25912
+ await logCrewBee(ctx, "CrewBee release refresh skipped for pinned version", {
25913
+ entry: intent.entry,
25914
+ pinnedVersion: intent.requestedVersion,
25915
+ currentVersion
25916
+ });
25917
+ return { currentVersion, latestVersion: intent.requestedVersion, needsRefresh: false, reason: "pinned-version" };
25918
+ }
25919
+ const latestVersion = await fetchTargetVersion({ intent, fetchJson: deps.fetchJson });
25920
+ if (!latestVersion) {
25921
+ writeCrewBeeReleaseState({
25922
+ ...state,
25923
+ lastCheckedAt: now
25924
+ });
25925
+ await logCrewBee(ctx, "CrewBee release refresh could not resolve latest version", {
25926
+ entry: intent.entry,
25927
+ channel: intent.channel,
25928
+ currentVersion
25929
+ }, "warn");
25930
+ return { currentVersion, needsRefresh: false, reason: "latest-unavailable" };
25931
+ }
25932
+ if (currentVersion === latestVersion) {
25933
+ writeCrewBeeReleaseState({
25934
+ ...state,
25935
+ lastCheckedAt: now,
25936
+ lastKnownVersion: currentVersion,
25937
+ lastFailure: void 0,
25938
+ lastFailureAt: void 0,
25939
+ lastSucceededAt: now
25940
+ });
25941
+ await logCrewBee(ctx, "CrewBee release refresh found current version already up to date", {
25942
+ currentVersion,
25943
+ latestVersion,
25944
+ workspaceRoot: intent.workspaceRoot
25945
+ }, "debug");
25946
+ return { currentVersion, latestVersion, needsRefresh: false, reason: "up-to-date" };
25947
+ }
25948
+ await logCrewBee(ctx, "CrewBee release refresh found newer version", {
25949
+ currentVersion,
25950
+ latestVersion,
25951
+ workspaceRoot: intent.workspaceRoot,
25952
+ entry: intent.entry
25953
+ });
25954
+ syncWorkspaceDependencyIntent(intent, latestVersion);
25955
+ invalidateWorkspacePackage(intent);
25956
+ const installed = await deps.runInstall(intent.workspaceRoot);
25957
+ if (!installed) {
25958
+ writeCrewBeeReleaseState({
25959
+ ...state,
25960
+ lastCheckedAt: now,
25961
+ lastAttemptedVersion: latestVersion,
25962
+ lastFailure: `Failed to install ${latestVersion}`,
25963
+ lastFailureAt: now,
25964
+ lastKnownVersion: currentVersion
25965
+ });
25966
+ await logCrewBee(ctx, "CrewBee release refresh failed to install latest version", {
25967
+ currentVersion,
25968
+ latestVersion,
25969
+ workspaceRoot: intent.workspaceRoot
25970
+ }, "warn");
25971
+ return { currentVersion, latestVersion, needsRefresh: true, reason: "refresh-required" };
25972
+ }
25973
+ writeCrewBeeReleaseState({
25974
+ lastCheckedAt: now,
25975
+ lastAttemptedVersion: latestVersion,
25976
+ lastKnownVersion: latestVersion,
25977
+ lastFailure: void 0,
25978
+ lastFailureAt: void 0,
25979
+ lastSucceededAt: now
25980
+ });
25981
+ await logCrewBee(ctx, "CrewBee release refresh installed newer version", {
25982
+ currentVersion,
25983
+ latestVersion,
25984
+ workspaceRoot: intent.workspaceRoot
25985
+ });
25986
+ return { currentVersion, latestVersion, needsRefresh: true, reason: "refresh-required" };
25987
+ } finally {
25988
+ releaseCrewBeeReleaseLock();
25989
+ }
25990
+ }
25991
+ function shouldEnableCrewBeeReleaseRefresh(currentPackageRoot = resolveCurrentPackageRoot()) {
25992
+ const override = process.env.CREWBEE_AUTO_UPDATE?.trim().toLowerCase();
25993
+ if (override === "1" || override === "true" || override === "on") {
25994
+ return true;
25995
+ }
25996
+ if (override === "0" || override === "false" || override === "off") {
25997
+ return false;
25998
+ }
25999
+ if (process.env.NODE_ENV === "test") {
26000
+ return false;
26001
+ }
26002
+ return !existsSync8(path9.join(currentPackageRoot, ".git"));
26003
+ }
26004
+ function shouldSkipByCooldown(state, now) {
26005
+ if (state.lastFailureAt && now - state.lastFailureAt < FAILURE_RECHECK_MS) {
26006
+ return true;
26007
+ }
26008
+ if (state.lastSucceededAt && now - state.lastSucceededAt < SUCCESS_RECHECK_MS) {
26009
+ return true;
26010
+ }
26011
+ return false;
26012
+ }
26013
+ function resolveCurrentPackageRoot() {
26014
+ return path9.resolve(__dirname, "../..");
26015
+ }
26016
+ function createDefaultDependencies() {
26017
+ return {
26018
+ async fetchJson(url2) {
26019
+ const response = await fetch(url2);
26020
+ if (!response.ok) {
26021
+ throw new Error(`Failed to fetch ${url2}: ${response.status}`);
26022
+ }
26023
+ return response.json();
26024
+ },
26025
+ async runInstall(workspaceRoot) {
26026
+ return new Promise((resolve) => {
26027
+ const child = spawn("npm", ["install", "--prefix", workspaceRoot, "--no-audit", "--no-fund"], {
26028
+ shell: process.platform === "win32",
26029
+ stdio: "ignore"
26030
+ });
26031
+ child.on("error", () => resolve(false));
26032
+ child.on("exit", (code) => resolve(code === 0));
26033
+ });
26034
+ }
26035
+ };
26036
+ }
26037
+
25532
26038
  // src/adapters/opencode/plugin.ts
25533
26039
  var OpenCodeCrewBeePlugin = async (ctx) => {
25534
26040
  const crewbeeConfigUpdate = ensureCrewBeeConfigFile({
@@ -25551,6 +26057,7 @@ var OpenCodeCrewBeePlugin = async (ctx) => {
25551
26057
  visibleAgentCount: initial.boot.projectedAgents.filter((agent) => !agent.hidden).length,
25552
26058
  defaultAgent: initial.boot.configPatch.defaultAgent
25553
26059
  });
26060
+ startBackgroundReleaseRefresh(ctx);
25554
26061
  let boot = initial.boot;
25555
26062
  let aliasIndex = initial.aliasIndex;
25556
26063
  const bindings = /* @__PURE__ */ new Map();