@autopilot-agent/adapters 0.3.0 → 0.4.0

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/dist/index.mjs CHANGED
@@ -38,9 +38,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
38
38
  mod
39
39
  ));
40
40
 
41
- // node_modules/boolbase/index.js
41
+ // ../../node_modules/boolbase/index.js
42
42
  var require_boolbase = __commonJS({
43
- "node_modules/boolbase/index.js"(exports, module) {
43
+ "../../node_modules/boolbase/index.js"(exports, module) {
44
44
  module.exports = {
45
45
  trueFunc: function trueFunc() {
46
46
  return true;
@@ -52,9 +52,9 @@ var require_boolbase = __commonJS({
52
52
  }
53
53
  });
54
54
 
55
- // node_modules/css-what/lib/commonjs/types.js
55
+ // ../../node_modules/css-what/lib/commonjs/types.js
56
56
  var require_types = __commonJS({
57
- "node_modules/css-what/lib/commonjs/types.js"(exports) {
57
+ "../../node_modules/css-what/lib/commonjs/types.js"(exports) {
58
58
  "use strict";
59
59
  Object.defineProperty(exports, "__esModule", { value: true });
60
60
  exports.AttributeAction = exports.IgnoreCaseMode = exports.SelectorType = void 0;
@@ -92,9 +92,9 @@ var require_types = __commonJS({
92
92
  }
93
93
  });
94
94
 
95
- // node_modules/css-what/lib/commonjs/parse.js
95
+ // ../../node_modules/css-what/lib/commonjs/parse.js
96
96
  var require_parse = __commonJS({
97
- "node_modules/css-what/lib/commonjs/parse.js"(exports) {
97
+ "../../node_modules/css-what/lib/commonjs/parse.js"(exports) {
98
98
  "use strict";
99
99
  Object.defineProperty(exports, "__esModule", { value: true });
100
100
  exports.parse = exports.isTraversal = void 0;
@@ -447,9 +447,9 @@ var require_parse = __commonJS({
447
447
  }
448
448
  });
449
449
 
450
- // node_modules/css-what/lib/commonjs/stringify.js
450
+ // ../../node_modules/css-what/lib/commonjs/stringify.js
451
451
  var require_stringify = __commonJS({
452
- "node_modules/css-what/lib/commonjs/stringify.js"(exports) {
452
+ "../../node_modules/css-what/lib/commonjs/stringify.js"(exports) {
453
453
  "use strict";
454
454
  var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
455
455
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
@@ -571,9 +571,9 @@ var require_stringify = __commonJS({
571
571
  }
572
572
  });
573
573
 
574
- // node_modules/css-what/lib/commonjs/index.js
574
+ // ../../node_modules/css-what/lib/commonjs/index.js
575
575
  var require_commonjs = __commonJS({
576
- "node_modules/css-what/lib/commonjs/index.js"(exports) {
576
+ "../../node_modules/css-what/lib/commonjs/index.js"(exports) {
577
577
  "use strict";
578
578
  var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
579
579
  if (k2 === void 0) k2 = k;
@@ -5422,12 +5422,12 @@ function parseSkillFrontmatter(frontmatter) {
5422
5422
  return void 0;
5423
5423
  }
5424
5424
  }
5425
- function readSkillString(fields, key2) {
5426
- const value = fields[key2];
5425
+ function readSkillString(fields2, key2) {
5426
+ const value = fields2[key2];
5427
5427
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
5428
5428
  }
5429
- function readSkillBoolean(fields, key2) {
5430
- const value = fields[key2];
5429
+ function readSkillBoolean(fields2, key2) {
5430
+ const value = fields2[key2];
5431
5431
  if (typeof value === "boolean") return value;
5432
5432
  if (typeof value !== "string") return void 0;
5433
5433
  const normalized = value.trim().toLocaleLowerCase();
@@ -5435,8 +5435,8 @@ function readSkillBoolean(fields, key2) {
5435
5435
  if (["false", "no", "off", "0"].includes(normalized)) return false;
5436
5436
  return void 0;
5437
5437
  }
5438
- function readSkillTools(fields) {
5439
- const value = fields["allowed-tools"];
5438
+ function readSkillTools(fields2) {
5439
+ const value = fields2["allowed-tools"];
5440
5440
  if (Array.isArray(value) && value.every(function isToolName(item) {
5441
5441
  return typeof item === "string" && item.trim();
5442
5442
  })) {
@@ -5450,9 +5450,9 @@ function readSkillTools(fields) {
5450
5450
  return item.trim();
5451
5451
  }).filter(Boolean);
5452
5452
  }
5453
- function readSkillDescription(fields, markdown) {
5454
- const explicit = readSkillString(fields, "description");
5455
- const whenToUse = readSkillString(fields, "when_to_use") ?? readSkillString(fields, "when-to-use");
5453
+ function readSkillDescription(fields2, markdown) {
5454
+ const explicit = readSkillString(fields2, "description");
5455
+ const whenToUse = readSkillString(fields2, "when_to_use") ?? readSkillString(fields2, "when-to-use");
5456
5456
  const description = explicit ?? markdown.trim().split(/\r?\n\s*\r?\n/u).find(function firstParagraph(paragraph) {
5457
5457
  return paragraph.trim();
5458
5458
  })?.trim();
@@ -5474,18 +5474,18 @@ function parseSkill(filePath, source, root) {
5474
5474
  const content = fs3.readFileSync(filePath, "utf8");
5475
5475
  const match = /^---\r?\n([\s\S]{0,4096}?)\r?\n---\r?\n/.exec(content);
5476
5476
  if (!match) return void 0;
5477
- const fields = parseSkillFrontmatter(match[1]);
5478
- if (!fields) return void 0;
5477
+ const fields2 = parseSkillFrontmatter(match[1]);
5478
+ if (!fields2) return void 0;
5479
5479
  const name = path3.basename(path3.dirname(filePath));
5480
- const description = readSkillDescription(fields, content.slice(match[0].length));
5480
+ const description = readSkillDescription(fields2, content.slice(match[0].length));
5481
5481
  if (!/^[a-z0-9-]{1,64}$/.test(name) || !description) return void 0;
5482
- const declaredName = readSkillString(fields, "name");
5482
+ const declaredName = readSkillString(fields2, "name");
5483
5483
  const displayName = declaredName && declaredName.length <= 64 ? declaredName : name;
5484
- const modelInvocable = !(readSkillBoolean(fields, "disable-model-invocation") ?? false);
5485
- const userInvocable = readSkillBoolean(fields, "user-invocable") ?? true;
5486
- const argumentHint = readSkillString(fields, "argument-hint") ?? readSkillString(fields, "dash-hint");
5487
- const whenToUse = readSkillString(fields, "when_to_use") ?? readSkillString(fields, "when-to-use");
5488
- const allowedTools = readSkillTools(fields);
5484
+ const modelInvocable = !(readSkillBoolean(fields2, "disable-model-invocation") ?? false);
5485
+ const userInvocable = readSkillBoolean(fields2, "user-invocable") ?? true;
5486
+ const argumentHint = readSkillString(fields2, "argument-hint") ?? readSkillString(fields2, "dash-hint");
5487
+ const whenToUse = readSkillString(fields2, "when_to_use") ?? readSkillString(fields2, "when-to-use");
5488
+ const allowedTools = readSkillTools(fields2);
5489
5489
  const canonical = fs3.realpathSync.native(filePath);
5490
5490
  const contentHash = crypto2.createHash("sha256").update(content).digest("hex");
5491
5491
  const skillId = `${source}:${crypto2.createHash("sha256").update(canonical).digest("hex").slice(0, 16)}:${contentHash.slice(0, 16)}`;
@@ -7949,7 +7949,7 @@ var Parser = class {
7949
7949
  }
7950
7950
  };
7951
7951
 
7952
- // ../../node_modules/htmlparser2/node_modules/domelementtype/lib/esm/index.js
7952
+ // ../../node_modules/domelementtype/lib/esm/index.js
7953
7953
  var esm_exports = {};
7954
7954
  __export(esm_exports, {
7955
7955
  CDATA: () => CDATA,
@@ -7965,16 +7965,16 @@ __export(esm_exports, {
7965
7965
  isTag: () => isTag
7966
7966
  });
7967
7967
  var ElementType;
7968
- (function(ElementType3) {
7969
- ElementType3["Root"] = "root";
7970
- ElementType3["Text"] = "text";
7971
- ElementType3["Directive"] = "directive";
7972
- ElementType3["Comment"] = "comment";
7973
- ElementType3["Script"] = "script";
7974
- ElementType3["Style"] = "style";
7975
- ElementType3["Tag"] = "tag";
7976
- ElementType3["CDATA"] = "cdata";
7977
- ElementType3["Doctype"] = "doctype";
7968
+ (function(ElementType2) {
7969
+ ElementType2["Root"] = "root";
7970
+ ElementType2["Text"] = "text";
7971
+ ElementType2["Directive"] = "directive";
7972
+ ElementType2["Comment"] = "comment";
7973
+ ElementType2["Script"] = "script";
7974
+ ElementType2["Style"] = "style";
7975
+ ElementType2["Tag"] = "tag";
7976
+ ElementType2["CDATA"] = "cdata";
7977
+ ElementType2["Doctype"] = "doctype";
7978
7978
  })(ElementType || (ElementType = {}));
7979
7979
  function isTag(elem) {
7980
7980
  return elem.type === ElementType.Tag || elem.type === ElementType.Script || elem.type === ElementType.Style;
@@ -10947,8 +10947,8 @@ var Comment3 = class _Comment extends CharacterData {
10947
10947
  };
10948
10948
 
10949
10949
  // node_modules/domutils/lib/esm/index.js
10950
- var esm_exports5 = {};
10951
- __export(esm_exports5, {
10950
+ var esm_exports4 = {};
10951
+ __export(esm_exports4, {
10952
10952
  DocumentPosition: () => DocumentPosition2,
10953
10953
  append: () => append3,
10954
10954
  appendChild: () => appendChild2,
@@ -10979,7 +10979,7 @@ __export(esm_exports5, {
10979
10979
  isCDATA: () => isCDATA2,
10980
10980
  isComment: () => isComment2,
10981
10981
  isDocument: () => isDocument2,
10982
- isTag: () => isTag4,
10982
+ isTag: () => isTag3,
10983
10983
  isText: () => isText2,
10984
10984
  nextElementSibling: () => nextElementSibling3,
10985
10985
  prepend: () => prepend2,
@@ -10993,47 +10993,21 @@ __export(esm_exports5, {
10993
10993
  uniqueSort: () => uniqueSort2
10994
10994
  });
10995
10995
 
10996
- // node_modules/domelementtype/lib/esm/index.js
10997
- var ElementType2;
10998
- (function(ElementType3) {
10999
- ElementType3["Root"] = "root";
11000
- ElementType3["Text"] = "text";
11001
- ElementType3["Directive"] = "directive";
11002
- ElementType3["Comment"] = "comment";
11003
- ElementType3["Script"] = "script";
11004
- ElementType3["Style"] = "style";
11005
- ElementType3["Tag"] = "tag";
11006
- ElementType3["CDATA"] = "cdata";
11007
- ElementType3["Doctype"] = "doctype";
11008
- })(ElementType2 || (ElementType2 = {}));
11009
- function isTag3(elem) {
11010
- return elem.type === ElementType2.Tag || elem.type === ElementType2.Script || elem.type === ElementType2.Style;
11011
- }
11012
- var Root2 = ElementType2.Root;
11013
- var Text3 = ElementType2.Text;
11014
- var Directive2 = ElementType2.Directive;
11015
- var Comment4 = ElementType2.Comment;
11016
- var Script2 = ElementType2.Script;
11017
- var Style2 = ElementType2.Style;
11018
- var Tag2 = ElementType2.Tag;
11019
- var CDATA3 = ElementType2.CDATA;
11020
- var Doctype2 = ElementType2.Doctype;
11021
-
11022
10996
  // node_modules/domhandler/lib/esm/node.js
11023
- function isTag4(node) {
11024
- return isTag3(node);
10997
+ function isTag3(node) {
10998
+ return isTag(node);
11025
10999
  }
11026
11000
  function isCDATA2(node) {
11027
- return node.type === ElementType2.CDATA;
11001
+ return node.type === ElementType.CDATA;
11028
11002
  }
11029
11003
  function isText2(node) {
11030
- return node.type === ElementType2.Text;
11004
+ return node.type === ElementType.Text;
11031
11005
  }
11032
11006
  function isComment2(node) {
11033
- return node.type === ElementType2.Comment;
11007
+ return node.type === ElementType.Comment;
11034
11008
  }
11035
11009
  function isDocument2(node) {
11036
- return node.type === ElementType2.Root;
11010
+ return node.type === ElementType.Root;
11037
11011
  }
11038
11012
  function hasChildren2(node) {
11039
11013
  return Object.prototype.hasOwnProperty.call(node, "children");
@@ -11720,21 +11694,21 @@ function render2(node, options = {}) {
11720
11694
  var esm_default2 = render2;
11721
11695
  function renderNode2(node, options) {
11722
11696
  switch (node.type) {
11723
- case Root2:
11697
+ case Root:
11724
11698
  return render2(node.children, options);
11725
11699
  // @ts-expect-error We don't use `Doctype` yet
11726
- case Doctype2:
11727
- case Directive2:
11700
+ case Doctype:
11701
+ case Directive:
11728
11702
  return renderDirective2(node);
11729
- case Comment4:
11703
+ case Comment:
11730
11704
  return renderComment2(node);
11731
- case CDATA3:
11705
+ case CDATA:
11732
11706
  return renderCdata2(node);
11733
- case Script2:
11734
- case Style2:
11735
- case Tag2:
11707
+ case Script:
11708
+ case Style:
11709
+ case Tag:
11736
11710
  return renderTag2(node, options);
11737
- case Text3:
11711
+ case Text:
11738
11712
  return renderText2(node, options);
11739
11713
  }
11740
11714
  }
@@ -11815,7 +11789,7 @@ function getInnerHTML2(node, options) {
11815
11789
  function getText2(node) {
11816
11790
  if (Array.isArray(node))
11817
11791
  return node.map(getText2).join("");
11818
- if (isTag4(node))
11792
+ if (isTag3(node))
11819
11793
  return node.name === "br" ? "\n" : getText2(node.children);
11820
11794
  if (isCDATA2(node))
11821
11795
  return getText2(node.children);
@@ -11836,7 +11810,7 @@ function textContent2(node) {
11836
11810
  function innerText2(node) {
11837
11811
  if (Array.isArray(node))
11838
11812
  return node.map(innerText2).join("");
11839
- if (hasChildren2(node) && (node.type === ElementType2.Tag || isCDATA2(node))) {
11813
+ if (hasChildren2(node) && (node.type === ElementType.Tag || isCDATA2(node))) {
11840
11814
  return innerText2(node.children);
11841
11815
  }
11842
11816
  if (isText2(node))
@@ -11879,13 +11853,13 @@ function getName2(elem) {
11879
11853
  }
11880
11854
  function nextElementSibling3(elem) {
11881
11855
  let { next } = elem;
11882
- while (next !== null && !isTag4(next))
11856
+ while (next !== null && !isTag3(next))
11883
11857
  ({ next } = next);
11884
11858
  return next;
11885
11859
  }
11886
11860
  function prevElementSibling2(elem) {
11887
11861
  let { prev } = elem;
11888
- while (prev !== null && !isTag4(prev))
11862
+ while (prev !== null && !isTag3(prev))
11889
11863
  ({ prev } = prev);
11890
11864
  return prev;
11891
11865
  }
@@ -12017,7 +11991,7 @@ function findOne2(test, nodes, recurse = true) {
12017
11991
  const searchedNodes = Array.isArray(nodes) ? nodes : [nodes];
12018
11992
  for (let i = 0; i < searchedNodes.length; i++) {
12019
11993
  const node = searchedNodes[i];
12020
- if (isTag4(node) && test(node)) {
11994
+ if (isTag3(node) && test(node)) {
12021
11995
  return node;
12022
11996
  }
12023
11997
  if (recurse && hasChildren2(node) && node.children.length > 0) {
@@ -12029,7 +12003,7 @@ function findOne2(test, nodes, recurse = true) {
12029
12003
  return null;
12030
12004
  }
12031
12005
  function existsOne2(test, nodes) {
12032
- return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => isTag4(node) && test(node) || hasChildren2(node) && existsOne2(test, node.children));
12006
+ return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => isTag3(node) && test(node) || hasChildren2(node) && existsOne2(test, node.children));
12033
12007
  }
12034
12008
  function findAll2(test, nodes) {
12035
12009
  const result = [];
@@ -12045,7 +12019,7 @@ function findAll2(test, nodes) {
12045
12019
  continue;
12046
12020
  }
12047
12021
  const elem = nodeStack[0][indexStack[0]++];
12048
- if (isTag4(elem) && test(elem))
12022
+ if (isTag3(elem) && test(elem))
12049
12023
  result.push(elem);
12050
12024
  if (hasChildren2(elem) && elem.children.length > 0) {
12051
12025
  indexStack.unshift(0);
@@ -12058,11 +12032,11 @@ function findAll2(test, nodes) {
12058
12032
  var Checks2 = {
12059
12033
  tag_name(name) {
12060
12034
  if (typeof name === "function") {
12061
- return (elem) => isTag4(elem) && name(elem.name);
12035
+ return (elem) => isTag3(elem) && name(elem.name);
12062
12036
  } else if (name === "*") {
12063
- return isTag4;
12037
+ return isTag3;
12064
12038
  }
12065
- return (elem) => isTag4(elem) && elem.name === name;
12039
+ return (elem) => isTag3(elem) && elem.name === name;
12066
12040
  },
12067
12041
  tag_type(type2) {
12068
12042
  if (typeof type2 === "function") {
@@ -12079,9 +12053,9 @@ var Checks2 = {
12079
12053
  };
12080
12054
  function getAttribCheck2(attrib, value) {
12081
12055
  if (typeof value === "function") {
12082
- return (elem) => isTag4(elem) && value(elem.attribs[attrib]);
12056
+ return (elem) => isTag3(elem) && value(elem.attribs[attrib]);
12083
12057
  }
12084
- return (elem) => isTag4(elem) && elem.attribs[attrib] === value;
12058
+ return (elem) => isTag3(elem) && elem.attribs[attrib] === value;
12085
12059
  }
12086
12060
  function combineFuncs2(a, b) {
12087
12061
  return (elem) => a(elem) || b(elem);
@@ -12568,7 +12542,7 @@ var attributeRules = {
12568
12542
  // node_modules/css-select/lib/esm/pseudo-selectors/index.js
12569
12543
  var import_css_what2 = __toESM(require_commonjs(), 1);
12570
12544
 
12571
- // node_modules/nth-check/lib/esm/parse.js
12545
+ // ../../node_modules/nth-check/lib/esm/parse.js
12572
12546
  var whitespace = /* @__PURE__ */ new Set([9, 10, 12, 13, 32]);
12573
12547
  var ZERO = "0".charCodeAt(0);
12574
12548
  var NINE = "9".charCodeAt(0);
@@ -12625,7 +12599,7 @@ function parse(formula) {
12625
12599
  }
12626
12600
  }
12627
12601
 
12628
- // node_modules/nth-check/lib/esm/compile.js
12602
+ // ../../node_modules/nth-check/lib/esm/compile.js
12629
12603
  var import_boolbase2 = __toESM(require_boolbase(), 1);
12630
12604
  function compile(parsed) {
12631
12605
  const a = parsed[0];
@@ -12643,7 +12617,7 @@ function compile(parsed) {
12643
12617
  return a > 1 ? (index) => index >= b && index % absA === bMod : (index) => index <= b && index % absA === bMod;
12644
12618
  }
12645
12619
 
12646
- // node_modules/nth-check/lib/esm/index.js
12620
+ // ../../node_modules/nth-check/lib/esm/index.js
12647
12621
  function nthCheck(formula) {
12648
12622
  return compile(parse(formula));
12649
12623
  }
@@ -13204,13 +13178,13 @@ function reduceRules(a, b) {
13204
13178
  // node_modules/css-select/lib/esm/index.js
13205
13179
  var defaultEquals = (a, b) => a === b;
13206
13180
  var defaultOptions = {
13207
- adapter: esm_exports5,
13181
+ adapter: esm_exports4,
13208
13182
  equals: defaultEquals
13209
13183
  };
13210
13184
  function convertOptionFormats(options) {
13211
13185
  var _a4, _b, _c, _d;
13212
13186
  const opts = options !== null && options !== void 0 ? options : defaultOptions;
13213
- (_a4 = opts.adapter) !== null && _a4 !== void 0 ? _a4 : opts.adapter = esm_exports5;
13187
+ (_a4 = opts.adapter) !== null && _a4 !== void 0 ? _a4 : opts.adapter = esm_exports4;
13214
13188
  (_b = opts.equals) !== null && _b !== void 0 ? _b : opts.equals = (_d = (_c = opts.adapter) === null || _c === void 0 ? void 0 : _c.equals) !== null && _d !== void 0 ? _d : defaultEquals;
13215
13189
  return opts;
13216
13190
  }
@@ -13257,9 +13231,9 @@ function is2(elem, query2, options) {
13257
13231
 
13258
13232
  // node_modules/linkedom/esm/shared/matches.js
13259
13233
  var { isArray } = Array;
13260
- var isTag5 = ({ nodeType }) => nodeType === ELEMENT_NODE;
13234
+ var isTag4 = ({ nodeType }) => nodeType === ELEMENT_NODE;
13261
13235
  var existsOne3 = (test, elements) => elements.some(
13262
- (element) => isTag5(element) && (test(element) || existsOne3(test, getChildren3(element)))
13236
+ (element) => isTag4(element) && (test(element) || existsOne3(test, getChildren3(element)))
13263
13237
  );
13264
13238
  var getAttributeValue3 = (element, name) => name === "class" ? element.classList.value : element.getAttribute(name);
13265
13239
  var getChildren3 = ({ childNodes }) => childNodes;
@@ -13275,7 +13249,7 @@ var getSiblings3 = (element) => {
13275
13249
  var getText3 = (node) => {
13276
13250
  if (isArray(node))
13277
13251
  return node.map(getText3).join("");
13278
- if (isTag5(node))
13252
+ if (isTag4(node))
13279
13253
  return getText3(getChildren3(node));
13280
13254
  if (node.nodeType === TEXT_NODE)
13281
13255
  return node.data;
@@ -13302,7 +13276,7 @@ var removeSubsets3 = (nodes) => {
13302
13276
  var findAll3 = (test, nodes) => {
13303
13277
  const matches3 = [];
13304
13278
  for (const node of nodes) {
13305
- if (isTag5(node)) {
13279
+ if (isTag4(node)) {
13306
13280
  if (test(node))
13307
13281
  matches3.push(node);
13308
13282
  matches3.push(...findAll3(test, getChildren3(node)));
@@ -13317,7 +13291,7 @@ var findOne3 = (test, nodes) => {
13317
13291
  return null;
13318
13292
  };
13319
13293
  var adapter = {
13320
- isTag: isTag5,
13294
+ isTag: isTag4,
13321
13295
  existsOne: existsOne3,
13322
13296
  getAttributeValue: getAttributeValue3,
13323
13297
  getChildren: getChildren3,
@@ -13350,7 +13324,7 @@ var matches = (element, selectors) => is2(
13350
13324
  );
13351
13325
 
13352
13326
  // node_modules/linkedom/esm/interface/text.js
13353
- var Text5 = class _Text extends CharacterData {
13327
+ var Text4 = class _Text extends CharacterData {
13354
13328
  constructor(ownerDocument, data = "") {
13355
13329
  super(ownerDocument, "#text", TEXT_NODE, data);
13356
13330
  }
@@ -13389,7 +13363,7 @@ var insert = (parentNode, child, nodes) => {
13389
13363
  const { ownerDocument } = parentNode;
13390
13364
  for (const node of nodes)
13391
13365
  parentNode.insertBefore(
13392
- isNode(node) ? node : new Text5(ownerDocument, node),
13366
+ isNode(node) ? node : new Text4(ownerDocument, node),
13393
13367
  child
13394
13368
  );
13395
13369
  };
@@ -14200,7 +14174,7 @@ var Element3 = class extends ParentNode {
14200
14174
  set textContent(text) {
14201
14175
  this.replaceChildren();
14202
14176
  if (text != null && text !== "")
14203
- this.appendChild(new Text5(this.ownerDocument, text));
14177
+ this.appendChild(new Text4(this.ownerDocument, text));
14204
14178
  }
14205
14179
  get innerHTML() {
14206
14180
  return getInnerHtml(this);
@@ -14574,11 +14548,11 @@ function CharacterData2() {
14574
14548
  }
14575
14549
  setPrototypeOf(CharacterData2, CharacterData);
14576
14550
  CharacterData2.prototype = CharacterData.prototype;
14577
- function Comment6() {
14551
+ function Comment5() {
14578
14552
  illegalConstructor();
14579
14553
  }
14580
- setPrototypeOf(Comment6, Comment3);
14581
- Comment6.prototype = Comment3.prototype;
14554
+ setPrototypeOf(Comment5, Comment3);
14555
+ Comment5.prototype = Comment3.prototype;
14582
14556
  function DocumentFragment2() {
14583
14557
  illegalConstructor();
14584
14558
  }
@@ -14604,11 +14578,11 @@ function ShadowRoot2() {
14604
14578
  }
14605
14579
  setPrototypeOf(ShadowRoot2, ShadowRoot);
14606
14580
  ShadowRoot2.prototype = ShadowRoot.prototype;
14607
- function Text6() {
14581
+ function Text5() {
14608
14582
  illegalConstructor();
14609
14583
  }
14610
- setPrototypeOf(Text6, Text5);
14611
- Text6.prototype = Text5.prototype;
14584
+ setPrototypeOf(Text5, Text4);
14585
+ Text5.prototype = Text4.prototype;
14612
14586
  function SVGElement2() {
14613
14587
  illegalConstructor();
14614
14588
  }
@@ -14618,13 +14592,13 @@ var Facades = {
14618
14592
  Attr: Attr2,
14619
14593
  CDATASection: CDATASection2,
14620
14594
  CharacterData: CharacterData2,
14621
- Comment: Comment6,
14595
+ Comment: Comment5,
14622
14596
  DocumentFragment: DocumentFragment2,
14623
14597
  DocumentType: DocumentType2,
14624
14598
  Element: Element4,
14625
14599
  Node: Node3,
14626
14600
  ShadowRoot: ShadowRoot2,
14627
- Text: Text6,
14601
+ Text: Text5,
14628
14602
  SVGElement: SVGElement2
14629
14603
  };
14630
14604
 
@@ -16640,7 +16614,7 @@ var Document3 = class extends NonElementParentNode {
16640
16614
  return range;
16641
16615
  }
16642
16616
  createTextNode(textContent3) {
16643
- return new Text5(this, textContent3);
16617
+ return new Text4(this, textContent3);
16644
16618
  }
16645
16619
  createTreeWalker(root, whatToShow = -1) {
16646
16620
  return new TreeWalker(root, whatToShow);
@@ -16989,13 +16963,13 @@ async function validatePublicWebUrl(rawUrl, options = {}) {
16989
16963
  if (value.length > 2e3) throw new Error("URL_TOO_LONG");
16990
16964
  url = new URL(value);
16991
16965
  } catch {
16992
- throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u65E0\u6548");
16966
+ throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u65E0\u6548", void 0, "url_not_allowed");
16993
16967
  }
16994
16968
  if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || !url.hostname) {
16995
- throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
16969
+ throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "url_not_allowed");
16996
16970
  }
16997
16971
  const hostname = normalizeHostname(url.hostname).toLowerCase();
16998
- if (isBlockedHostname(hostname)) throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
16972
+ if (isBlockedHostname(hostname)) throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "url_not_allowed");
16999
16973
  let addresses;
17000
16974
  const literalFamily = isIP(hostname);
17001
16975
  if (literalFamily === 4 || literalFamily === 6) {
@@ -17005,14 +16979,14 @@ async function validatePublicWebUrl(rawUrl, options = {}) {
17005
16979
  addresses = await (options.resolveDns ?? resolveWebFetchDns)(hostname, options.signal);
17006
16980
  } catch (error) {
17007
16981
  if (options.signal?.aborted || error instanceof Error && error.name === "AbortError") throw createAbortError();
17008
- throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25");
16982
+ throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25", void 0, "dns_failed");
17009
16983
  }
17010
16984
  }
17011
- if (addresses.length === 0) throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25");
16985
+ if (addresses.length === 0) throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25", void 0, "dns_failed");
17012
16986
  const unique = /* @__PURE__ */ new Map();
17013
16987
  for (const record of addresses) {
17014
16988
  if (!isPublicWebAddress(record.address, record.family)) {
17015
- throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
16989
+ throw new WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "non_public_address");
17016
16990
  }
17017
16991
  unique.set(`${record.family}:${record.address}`, { address: record.address, family: record.family });
17018
16992
  }
@@ -17221,7 +17195,7 @@ function createSafeWebFetchCapability(options = {}) {
17221
17195
  /** 读取明确 URL;跨域目标和剩余跳数只交给 Core,在审批后续接。 */
17222
17196
  async fetch(input) {
17223
17197
  if (input.redirectsRemaining !== void 0 && (!Number.isInteger(input.redirectsRemaining) || input.redirectsRemaining < 0 || input.redirectsRemaining > MAX_REDIRECTS)) {
17224
- throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u9884\u7B97\u65E0\u6548");
17198
+ throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u9884\u7B97\u65E0\u6548", void 0, "redirect_rejected");
17225
17199
  }
17226
17200
  const original = await validatePublicWebUrl(input.url, { resolveDns, signal: input.signal });
17227
17201
  let current = original;
@@ -17234,19 +17208,19 @@ function createSafeWebFetchCapability(options = {}) {
17234
17208
  const location = readHeader(response.headers, "location");
17235
17209
  if (!location || redirectCount >= redirectLimit) {
17236
17210
  response.abort();
17237
- throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u65E0\u6548\u6216\u8D85\u8FC7\u4E0A\u9650");
17211
+ throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u65E0\u6548\u6216\u8D85\u8FC7\u4E0A\u9650", void 0, "redirect_rejected");
17238
17212
  }
17239
17213
  let redirectUrl;
17240
17214
  try {
17241
17215
  redirectUrl = new URL(location, current.url);
17242
17216
  } catch {
17243
17217
  response.abort();
17244
- throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548");
17218
+ throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548", void 0, "redirect_rejected");
17245
17219
  }
17246
17220
  if (redirectUrl.hostname.toLowerCase() !== current.url.hostname.toLowerCase()) {
17247
17221
  response.abort();
17248
17222
  if (!["http:", "https:"].includes(redirectUrl.protocol) || redirectUrl.username || redirectUrl.password) {
17249
- throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548");
17223
+ throw new WebFetchCapabilityError2("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548", void 0, "redirect_rejected");
17250
17224
  }
17251
17225
  throw new WebFetchCapabilityError2("WEB_REDIRECT_REQUIRES_APPROVAL", "\u7F51\u9875\u91CD\u5B9A\u5411\u9700\u8981\u65B0\u7684\u57DF\u540D\u5BA1\u6279", {
17252
17226
  url: redirectUrl.toString(),
@@ -17351,7 +17325,7 @@ function hostExecutionCapabilityReport() {
17351
17325
  installed: false,
17352
17326
  provisioned: false,
17353
17327
  diagnostics: [
17354
- "Windows \u5BBF\u4E3B\u6267\u884C\u6A21\u5F0F\uFF1A\u8FDB\u7A0B\u6C99\u7BB1\u5DF2\u505C\u7528\uFF0C\u8FDB\u7A0B\u8C03\u7528\u7ECF\u7528\u6237\u9010\u6B21\u5BA1\u6279\u540E\u5728\u5BBF\u4E3B\u4EE5\u5F53\u524D\u7528\u6237\u6743\u9650\u76F4\u63A5\u6267\u884C"
17328
+ "Windows \u5BBF\u4E3B\u6267\u884C\u6A21\u5F0F\uFF1A\u8FDB\u7A0B\u6C99\u7BB1\u5DF2\u505C\u7528\uFF0C\u8C03\u7528\u6309\u6743\u9650\u6A21\u5F0F\u4E0E\u98CE\u9669\u5206\u6D41\uFF0C\u5728\u5BBF\u4E3B\u4EE5\u5F53\u524D\u7528\u6237\u6743\u9650\u76F4\u63A5\u6267\u884C"
17355
17329
  ]
17356
17330
  };
17357
17331
  }
@@ -17512,15 +17486,31 @@ async function acquireProcessLock(filePath, requireExitedOwner = false) {
17512
17486
  }
17513
17487
  }
17514
17488
  }
17515
- function releaseProcessLock(handle) {
17489
+ async function removeOwnedProcessLock(lockPath, ownerId) {
17490
+ const startedAt = Date.now();
17491
+ while (true) {
17492
+ try {
17493
+ const metadata = JSON.parse(await fsp.readFile(lockPath, "utf8"));
17494
+ if (metadata.ownerId !== ownerId) return;
17495
+ await fsp.unlink(lockPath);
17496
+ return;
17497
+ } catch (error) {
17498
+ const code = error.code;
17499
+ if (code === "ENOENT") return;
17500
+ if ((code === "EPERM" || code === "EACCES" || code === "EBUSY") && Date.now() - startedAt < PROCESS_LOCK_TIMEOUT_MS) {
17501
+ await waitForProcessLock();
17502
+ continue;
17503
+ }
17504
+ rememberFileFailure(error, { phase: "cleanup", cleanupFailed: true });
17505
+ throw error;
17506
+ }
17507
+ }
17508
+ }
17509
+ async function releaseProcessLock(handle) {
17516
17510
  try {
17517
17511
  fs5.closeSync(handle.descriptor);
17518
17512
  } finally {
17519
- try {
17520
- const metadata = JSON.parse(fs5.readFileSync(handle.lockPath, "utf8"));
17521
- if (metadata.ownerId === handle.ownerId) fs5.unlinkSync(handle.lockPath);
17522
- } catch {
17523
- }
17513
+ await removeOwnedProcessLock(handle.lockPath, handle.ownerId);
17524
17514
  }
17525
17515
  }
17526
17516
  async function withFileLock(filePath, operation, options) {
@@ -17545,7 +17535,7 @@ async function withFileLock(filePath, operation, options) {
17545
17535
  try {
17546
17536
  return await operation();
17547
17537
  } finally {
17548
- releaseProcessLock(handle);
17538
+ await releaseProcessLock(handle);
17549
17539
  }
17550
17540
  } finally {
17551
17541
  release();
@@ -17585,11 +17575,7 @@ async function releaseAsyncProcessLock(handle) {
17585
17575
  try {
17586
17576
  await handle.descriptor.close();
17587
17577
  } finally {
17588
- try {
17589
- const metadata = JSON.parse(await fsp.readFile(handle.lockPath, "utf8"));
17590
- if (metadata.ownerId === handle.ownerId) await fsp.unlink(handle.lockPath);
17591
- } catch {
17592
- }
17578
+ await removeOwnedProcessLock(handle.lockPath, handle.ownerId);
17593
17579
  }
17594
17580
  }
17595
17581
  async function withAsyncFileLock(filePath, operation) {
@@ -17642,6 +17628,39 @@ function atomicReplace(filePath, content) {
17642
17628
  }
17643
17629
  }
17644
17630
  }
17631
+ async function replaceSessionFile(filePath, content) {
17632
+ if (process.platform !== "win32") return atomicReplace(filePath, content);
17633
+ ensureParentDirectory(filePath);
17634
+ const temporaryPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
17635
+ const delays = [20, 40, 80, 160];
17636
+ let attempts = 0;
17637
+ const started = performance.now();
17638
+ try {
17639
+ await fsp.writeFile(temporaryPath, content, { encoding: "utf8", flag: "wx" });
17640
+ for (; ; ) {
17641
+ attempts++;
17642
+ try {
17643
+ await fsp.rename(temporaryPath, filePath);
17644
+ return;
17645
+ } catch (error) {
17646
+ const delay = delays[attempts - 1];
17647
+ if (!delay || !["EBUSY", "EPERM", "EACCES"].includes(error.code ?? "")) throw error;
17648
+ await new Promise(function backoff(resolve) {
17649
+ setTimeout(resolve, delay);
17650
+ });
17651
+ }
17652
+ }
17653
+ } catch (error) {
17654
+ let cleanupFailed = false;
17655
+ try {
17656
+ await fsp.rm(temporaryPath, { force: true });
17657
+ } catch {
17658
+ cleanupFailed = true;
17659
+ }
17660
+ rememberFileFailure(error, { phase: attempts ? "rename" : "temporary_write", attempts, elapsedMs: Math.round(performance.now() - started), cleanupFailed });
17661
+ throw error;
17662
+ }
17663
+ }
17645
17664
  function safeFilePath(directory, key2, extension) {
17646
17665
  if (!key2 || key2.includes("/") || key2.includes("\\") || key2 === "." || key2 === "..") {
17647
17666
  throw new Error("\u6301\u4E45\u5316 ID \u4E0D\u80FD\u5305\u542B\u8DEF\u5F84\u5206\u9694\u7B26");
@@ -17957,6 +17976,8 @@ function normalizeNodeSession(value, id) {
17957
17976
  const session = value;
17958
17977
  if (session.id !== id || !Number.isFinite(session.createdAt) || !Number.isFinite(session.updatedAt)) throw new NodeStateError("STATE_SESSION_CORRUPTED");
17959
17978
  const source = session.creationSource;
17979
+ const managed = session.managedExecution;
17980
+ if (managed !== void 0 && (!managed || managed.threadPolicy !== "disabled" || typeof managed.hostId !== "string" || !/^[\w-]{1,128}$/.test(managed.hostId) || typeof managed.requestId !== "string" || !/^[\w-]{1,128}$/.test(managed.requestId) || session.productMode !== "work" || session.persistenceMode !== "durable")) throw new NodeStateError("STATE_SESSION_CORRUPTED");
17960
17981
  if (source !== void 0) {
17961
17982
  const actor = source?.actor;
17962
17983
  if (!session.collaborationCreationId || !source || typeof source.requestId !== "string" || !source.requestId || !actor || actor.kind !== "human" && actor.kind !== "thread" || actor.kind === "human" && (typeof actor.principalId !== "string" || !actor.principalId) || actor.kind === "thread" && (typeof actor.threadId !== "string" || !actor.threadId || typeof actor.turnId !== "string" || !actor.turnId)) throw new NodeStateError("STATE_SESSION_CORRUPTED");
@@ -17970,6 +17991,7 @@ function normalizeNodeSession(value, id) {
17970
17991
  return { ...session, productMode: mode };
17971
17992
  }
17972
17993
  function assertNodeSessionIdentity(previous, next) {
17994
+ if (JSON.stringify(previous.managedExecution) !== JSON.stringify(next.managedExecution)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
17973
17995
  if (JSON.stringify(previous.collaborationAllowedTools) !== JSON.stringify(next.collaborationAllowedTools)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
17974
17996
  if (JSON.stringify(previous.creationSource) !== JSON.stringify(next.creationSource)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
17975
17997
  if (previous.collaborationCreationId !== next.collaborationCreationId) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
@@ -19676,7 +19698,7 @@ import fs20 from "node:fs";
19676
19698
  import fs19 from "node:fs";
19677
19699
  var DIRECTORY_FIELDS = /* @__PURE__ */ new Set(["id", "title", "productMode", "projectId", "chatRetrievalMode", "createdAt", "updatedAt", "status", "activeTurnId"]);
19678
19700
  async function readSessionDirectoryRecord(filePath, id) {
19679
- const fields = {};
19701
+ const fields2 = {};
19680
19702
  const stack = [];
19681
19703
  let root = false;
19682
19704
  let finished = false;
@@ -19706,7 +19728,7 @@ async function readSessionDirectoryRecord(filePath, id) {
19706
19728
  const frame = stack[stack.length - 1];
19707
19729
  frame.key = stack.length === 1 ? JSON.parse(text) : void 0;
19708
19730
  frame.expect = "colon";
19709
- } else if (target) fields[target] = JSON.parse(text);
19731
+ } else if (target) fields2[target] = JSON.parse(text);
19710
19732
  token = void 0;
19711
19733
  text = "";
19712
19734
  target = void 0;
@@ -19790,8 +19812,8 @@ async function readSessionDirectoryRecord(filePath, id) {
19790
19812
  }
19791
19813
  }
19792
19814
  if (!finished || token || stack.length) invalid();
19793
- if (fields.title !== void 0 && typeof fields.title !== "string") invalid();
19794
- return normalizeNodeSession(fields, id);
19815
+ if (fields2.title !== void 0 && typeof fields2.title !== "string") invalid();
19816
+ return normalizeNodeSession(fields2, id);
19795
19817
  }
19796
19818
 
19797
19819
  // src/node/stores/node-session-store.ts
@@ -19920,7 +19942,7 @@ function createNodeSessionStore(options) {
19920
19942
  phase = "identity";
19921
19943
  const previous = read(session.id);
19922
19944
  if (previous) assertNodeSessionIdentity(previous, next);
19923
- atomicReplace(filePath(session.id), JSON.stringify(next, null, 2));
19945
+ return replaceSessionFile(filePath(session.id), JSON.stringify(next, null, 2));
19924
19946
  });
19925
19947
  } catch (error) {
19926
19948
  throw toNodeBoundaryError(error, "STATE_STORAGE_UNAVAILABLE", { operation: "session_save", target: "session", phase, ...getFileOperationDiagnostic(error) });
@@ -20775,6 +20797,12 @@ function createNodeRuntimePorts(options) {
20775
20797
  };
20776
20798
  }
20777
20799
 
20800
+ // src/node/runtime-owner.ts
20801
+ import { join } from "node:path";
20802
+ function withNodeRuntimeOwner(stateRoot, operation) {
20803
+ return withFileLock(join(stateRoot, "managed-runtime-owner"), operation, { requireExitedOwner: true });
20804
+ }
20805
+
20778
20806
  // src/node/stores/node-chat-attachment-store.ts
20779
20807
  import fs28 from "node:fs";
20780
20808
  import path22 from "node:path";
@@ -21429,7 +21457,7 @@ function parseConfigValue(key2, rawValue) {
21429
21457
  // src/node/settings/node-user-settings-service.ts
21430
21458
  import { createHash as createHash6 } from "node:crypto";
21431
21459
  import fs30 from "node:fs";
21432
- import { isExternalPermissionDiagnostic, normalizeProviderBaseUrl, resolveAutopilotSettings as resolveAutopilotSettings4 } from "@autopilot-agent/core";
21460
+ import { isExternalPermissionDiagnostic, normalizeProviderBaseUrl, resolveAutopilotSettings as resolveAutopilotSettings4, resolveRouteModelCapability } from "@autopilot-agent/core";
21433
21461
  var RAG_ROLE_CONTRACT = Object.freeze({
21434
21462
  textRerank: { provider: "bailian", key: "RAG_TEXT_RERANK_API_KEY", dimension: false },
21435
21463
  visionRerank: { provider: "bailian", key: "RAG_VISION_RERANK_API_KEY", dimension: false },
@@ -21486,7 +21514,13 @@ function assertRevision(original, revision) {
21486
21514
  }
21487
21515
  function readEnvironmentKey(environment, key2) {
21488
21516
  if (!key2) return void 0;
21489
- return parseApiKey(environment[key2]);
21517
+ return parseApiKey(environment[key2] ?? (key2.startsWith("USER_SETTINGS_") ? environment[key2.slice("USER_SETTINGS_".length)] : void 0));
21518
+ }
21519
+ function readMainCredential(environment, ref, env) {
21520
+ const configured = readEnvironmentKey(environment, ref.key);
21521
+ if (configured || ref.key.startsWith("USER_SETTINGS_")) return configured;
21522
+ const envKey = `${ref.provider.toUpperCase().replace(/[^A-Z0-9_]/gu, "_")}_${ref.key.toUpperCase()}`;
21523
+ return parseApiKey(env[envKey]);
21490
21524
  }
21491
21525
  function collectMainCredentialCandidates(raw, environment) {
21492
21526
  const candidates = [];
@@ -21534,30 +21568,108 @@ function removeLegacyPrimaryRoutes(raw, environment) {
21534
21568
  for (const key2 of removedKeys) if (!hasCredentialReference(raw, key2)) delete environment[key2];
21535
21569
  }
21536
21570
  function normalizeMainInput(input) {
21571
+ const apiProtocol = input.apiProtocol ?? "anthropic-messages";
21537
21572
  const baseUrl = normalizeProviderBaseUrl(input.baseUrl);
21538
21573
  const model = parseSettingString(input.model);
21539
21574
  const apiKey = parseApiKey(input.apiKey);
21540
21575
  const availableModels = input.availableModels?.map(function parseModel(value) {
21541
21576
  return parseSettingString(value);
21542
21577
  });
21543
- if (!baseUrl || !model || input.apiKey !== void 0 && input.apiKey !== "" && !apiKey || availableModels && (availableModels.length === 0 || availableModels.some(function missing(value) {
21578
+ if (!["anthropic-messages", "openai-chat-completions", "openai-responses"].includes(apiProtocol) || input.compatibilityPreset !== void 0 && (apiProtocol === "anthropic-messages" || !["openai", "deepseek", "generic"].includes(input.compatibilityPreset)) || !baseUrl || !model || input.apiKey !== void 0 && input.apiKey !== "" && !apiKey || availableModels && (availableModels.length === 0 || availableModels.some(function missing(value) {
21544
21579
  return !value;
21545
- }) || new Set(availableModels).size !== availableModels.length) || input.effort !== void 0 && !["auto", "low", "medium", "high", "max"].includes(input.effort) || input.maxOutputTokens !== void 0 && (!Number.isInteger(input.maxOutputTokens) || input.maxOutputTokens < 1 || input.maxOutputTokens > 1e6) || input.compactWindow !== void 0 && (!Number.isInteger(input.compactWindow) || input.compactWindow < 1 || input.compactWindow > 1e7) || input.timeoutMs !== void 0 && (!Number.isInteger(input.timeoutMs) || input.timeoutMs < 1e3 || input.timeoutMs > 6e5) || input.alwaysThinkingEnabled !== void 0 && typeof input.alwaysThinkingEnabled !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21580
+ }) || new Set(availableModels).size !== availableModels.length) || input.effort !== void 0 && !["auto", "none", "low", "medium", "high", "xhigh", "max"].includes(input.effort) || input.maxOutputTokens !== void 0 && (!Number.isInteger(input.maxOutputTokens) || input.maxOutputTokens < 1 || input.maxOutputTokens > 1e6) || input.compactWindow !== void 0 && (!Number.isInteger(input.compactWindow) || input.compactWindow < 1 || input.compactWindow > 1e7) || input.timeoutMs !== void 0 && (!Number.isInteger(input.timeoutMs) || input.timeoutMs < 1e3 || input.timeoutMs > 6e5) || input.alwaysThinkingEnabled !== void 0 && typeof input.alwaysThinkingEnabled !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21546
21581
  for (const value of [input.opusModel, input.sonnetModel, input.haikuModel, input.subagentModel]) {
21547
21582
  if (value !== void 0 && !parseSettingString(value)) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21548
21583
  }
21549
- return { ...input, baseUrl, model, ...apiKey ? { apiKey } : {}, ...availableModels ? { availableModels } : {} };
21584
+ return { ...input, apiProtocol, baseUrl, model, ...apiKey ? { apiKey } : {}, ...availableModels ? { availableModels } : {} };
21550
21585
  }
21551
- function applyMainCategory(raw, input) {
21586
+ function createMainRoute(raw, input) {
21587
+ const previous = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21588
+ const selected = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
21589
+ const apiProtocol = input.apiProtocol ?? "anthropic-messages";
21590
+ const sameConnection = selected?.apiProtocol === apiProtocol && selected.baseUrl === input.baseUrl;
21591
+ const matches3 = sameConnection && selected.compatibilityPreset === input.compatibilityPreset;
21592
+ let id = selected?.id ?? "web-main";
21593
+ for (let suffix = 2; !selected && previous.providerRoutes[id]; suffix += 1) id = `web-main-${suffix}`;
21594
+ const ids = [.../* @__PURE__ */ new Set([...input.availableModels ?? (matches3 ? selected.models.map(function modelId(model) {
21595
+ return model.id;
21596
+ }) : []), input.model])];
21597
+ return {
21598
+ id,
21599
+ apiProtocol,
21600
+ baseUrl: input.baseUrl,
21601
+ credentialRef: sameConnection ? selected.credentialRef : { provider: id, key: `USER_SETTINGS_WEB_MAIN_${revisionOf(`${id}/${apiProtocol}/${input.baseUrl}`).slice(0, 16).toUpperCase()}` },
21602
+ ...selected?.displayName ? { displayName: selected.displayName } : {},
21603
+ ...input.compatibilityPreset ? { compatibilityPreset: input.compatibilityPreset } : {},
21604
+ ...matches3 && selected.protocolProfile ? { protocolProfile: selected.protocolProfile } : {},
21605
+ models: ids.map(function modelEntry(modelId) {
21606
+ return matches3 ? selected.models.find(function matchesId(model) {
21607
+ return model.id === modelId;
21608
+ }) ?? { id: modelId } : { id: modelId };
21609
+ })
21610
+ };
21611
+ }
21612
+ function resolveMainCapabilities(route, model) {
21613
+ try {
21614
+ const capability = resolveRouteModelCapability(route, model);
21615
+ return { supportedReasoningEfforts: capability.supportedReasoningEfforts ?? [], supportsToolCalls: capability.supportsToolCalls !== false };
21616
+ } catch {
21617
+ throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21618
+ }
21619
+ }
21620
+ function applyRoutedMainCategory(raw, input, env) {
21621
+ const route = createMainRoute(raw, input);
21622
+ const capabilities = resolveMainCapabilities(route, input.model);
21623
+ if (!capabilities.supportsToolCalls) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID", { scope: "user", code: "MODEL_NOT_SUPPORTED", field: "model" });
21624
+ if (input.effort && input.effort !== "auto" && !capabilities.supportedReasoningEfforts.includes(input.effort)) {
21625
+ throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID", { scope: "user", code: "SETTINGS_EFFORT_INVALID", field: "effortLevel" });
21626
+ }
21627
+ const environment = { ...isRecord4(raw.env) ? raw.env : {} };
21628
+ const previous = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21629
+ const selected = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
21630
+ const sameConnection = selected?.apiProtocol === route.apiProtocol && selected.baseUrl === route.baseUrl;
21631
+ if (!input.apiKey && !sameConnection) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
21632
+ const key2 = input.apiKey ?? readMainCredential(environment, route.credentialRef, env);
21633
+ if (!key2) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
21634
+ if (input.apiKey) environment[route.credentialRef.key] = input.apiKey;
21635
+ delete environment.ANTHROPIC_MODEL;
21636
+ delete environment.CLAUDE_CODE_EFFORT_LEVEL;
21637
+ raw.env = environment;
21638
+ raw.providerRoutes = { ...isRecord4(raw.providerRoutes) ? raw.providerRoutes : {}, [route.id]: route };
21639
+ raw.model = `${route.id}/${input.model}`;
21640
+ if (input.effort && input.effort !== "auto") raw.effortLevel = input.effort;
21641
+ else delete raw.effortLevel;
21642
+ }
21643
+ function applyMainCategory(raw, input, env) {
21552
21644
  const normalized = normalizeMainInput(input);
21645
+ const previous = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21646
+ const previousRoute = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
21647
+ if (normalized.apiProtocol !== "anthropic-messages" || input.apiProtocol !== void 0 && previousRoute) {
21648
+ applyRoutedMainCategory(raw, normalized, env);
21649
+ if (normalized.maxOutputTokens === void 0) delete raw.maxOutputTokens;
21650
+ else raw.maxOutputTokens = normalized.maxOutputTokens;
21651
+ const environment2 = raw.env;
21652
+ const optional2 = {
21653
+ ANTHROPIC_DEFAULT_OPUS_MODEL: normalized.opusModel,
21654
+ ANTHROPIC_DEFAULT_SONNET_MODEL: normalized.sonnetModel,
21655
+ ANTHROPIC_DEFAULT_HAIKU_MODEL: normalized.haikuModel,
21656
+ CLAUDE_CODE_AUTO_COMPACT_WINDOW: normalized.compactWindow?.toString(),
21657
+ API_TIMEOUT_MS: normalized.timeoutMs?.toString(),
21658
+ CLAUDE_CODE_SUBAGENT_MODEL: normalized.subagentModel
21659
+ };
21660
+ for (const [key2, value] of Object.entries(optional2)) {
21661
+ if (value === void 0) delete environment2[key2];
21662
+ else environment2[key2] = value;
21663
+ }
21664
+ if (normalized.apiProtocol === "anthropic-messages" && normalized.alwaysThinkingEnabled !== void 0) raw.alwaysThinkingEnabled = normalized.alwaysThinkingEnabled;
21665
+ return;
21666
+ }
21553
21667
  const environment = { ...isRecord4(raw.env) ? raw.env : {} };
21554
21668
  const candidates = collectMainCredentialCandidates(raw, environment);
21555
21669
  const distinct = [...new Set(candidates.map(function value(candidate) {
21556
21670
  return candidate.value;
21557
21671
  }))];
21558
21672
  if (!normalized.apiKey && distinct.length > 1) throw new NodeUserSettingsError("SETTINGS_MIGRATION_CONFLICT");
21559
- const previous = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21560
- const previousRoute = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
21561
21673
  const previousBaseUrl = normalizeProviderBaseUrl(previousRoute?.baseUrl ?? previous.firstParty.baseUrl);
21562
21674
  const officialDeepSeekMigration = previousBaseUrl === "https://api.deepseek.com" && normalized.baseUrl === "https://api.deepseek.com/anthropic";
21563
21675
  if (!normalized.apiKey && previousBaseUrl !== normalized.baseUrl && !officialDeepSeekMigration) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
@@ -21584,6 +21696,7 @@ function applyMainCategory(raw, input) {
21584
21696
  }
21585
21697
  raw.env = environment;
21586
21698
  delete raw.model;
21699
+ delete raw.effortLevel;
21587
21700
  raw.availableModels = normalized.availableModels ?? [...new Set([normalized.model, normalized.opusModel, normalized.sonnetModel, normalized.haikuModel, normalized.subagentModel].filter(function present(value) {
21588
21701
  return Boolean(value);
21589
21702
  }))];
@@ -21592,7 +21705,7 @@ function applyMainCategory(raw, input) {
21592
21705
  if (normalized.alwaysThinkingEnabled === void 0) delete raw.alwaysThinkingEnabled;
21593
21706
  else raw.alwaysThinkingEnabled = normalized.alwaysThinkingEnabled;
21594
21707
  }
21595
- function applyWebSearch(raw, input) {
21708
+ function applyWebSearch(raw, input, env) {
21596
21709
  if (typeof input.enabled !== "boolean" || typeof input.useMainKey !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21597
21710
  if (!input.enabled) {
21598
21711
  raw.webSearch = false;
@@ -21602,15 +21715,19 @@ function applyWebSearch(raw, input) {
21602
21715
  const baseUrl = normalizeProviderBaseUrl(input.baseUrl);
21603
21716
  const model = parseSettingString(input.model);
21604
21717
  const environment = { ...isRecord4(raw.env) ? raw.env : {} };
21605
- const mainBaseUrl = normalizeProviderBaseUrl(environment.ANTHROPIC_BASE_URL);
21606
- const canReuseMainKey = mainBaseUrl === "https://api.deepseek.com/anthropic" && Boolean(readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY"));
21718
+ const settings = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21719
+ const mainRoute = settings.modelRef && settings.providerRoutes[settings.modelRef.provider];
21720
+ const mainBaseUrl = mainRoute?.baseUrl ?? normalizeProviderBaseUrl(environment.ANTHROPIC_BASE_URL);
21721
+ const mainRef = mainRoute?.credentialRef ?? { provider: "deepseek", key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" };
21722
+ const mainKey = mainRoute ? readMainCredential(environment, mainRef, env) : readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
21723
+ const canReuseMainKey = (!mainRoute || mainRoute.apiProtocol === "anthropic-messages") && mainBaseUrl === "https://api.deepseek.com/anthropic" && Boolean(mainKey);
21607
21724
  if (input.useMainKey) {
21608
21725
  if (!canReuseMainKey) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
21609
21726
  raw.webSearch = {
21610
21727
  provider: "deepseek",
21611
21728
  baseUrl: "https://api.deepseek.com/anthropic",
21612
21729
  model: "deepseek-flash",
21613
- credentialRef: { provider: "deepseek", key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" }
21730
+ credentialRef: mainRef
21614
21731
  };
21615
21732
  return;
21616
21733
  }
@@ -21655,6 +21772,7 @@ function createNodeUserSettingsService(options = {}) {
21655
21772
  const homeDirectory = options.homeDirectory;
21656
21773
  const settingsPath = resolveNodeUserSettingsPath(homeDirectory);
21657
21774
  const fetchImpl = options.fetchImpl ?? fetch;
21775
+ const env = options.env ?? process.env;
21658
21776
  async function save(update2, revision) {
21659
21777
  return withFileLock(settingsPath, function writeSettings() {
21660
21778
  ensureUserConfigDirectory({ ...homeDirectory ? { homeDirectory } : {} });
@@ -21670,6 +21788,11 @@ function createNodeUserSettingsService(options = {}) {
21670
21788
  });
21671
21789
  }
21672
21790
  return {
21791
+ /** 预览草稿模型在当前 route 覆盖下的能力,不读取或返回 API Key。 */
21792
+ getMainModelCapabilities(input) {
21793
+ const normalized = normalizeMainInput(input);
21794
+ return resolveMainCapabilities(createMainRoute(readUserSettings(settingsPath).raw, normalized), normalized.model);
21795
+ },
21673
21796
  /** 用户主动刷新时调用 DeepSeek 官方目录;无凭据、失败或异常响应均使用维护目录。 */
21674
21797
  async refreshMainModelCatalog() {
21675
21798
  const maintained = ["deepseek-v4-pro[1m]", "deepseek-v4-flash"];
@@ -21701,10 +21824,11 @@ function createNodeUserSettingsService(options = {}) {
21701
21824
  const resolved = resolveAutopilotSettings4([{ scope: "user", value: raw }]);
21702
21825
  const { blocking, permissions } = splitDiagnostics(resolved.diagnostics);
21703
21826
  if (blocking.length > 0) throw new NodeUserSettingsError("SETTINGS_INVALID", safeDiagnostic(blocking[0]));
21704
- const mainBaseUrl = resolved.firstParty.baseUrl ?? "https://api.deepseek.com/anthropic";
21827
+ const mainRoute = resolved.modelRef && resolved.providerRoutes[resolved.modelRef.provider];
21828
+ const mainBaseUrl = mainRoute?.baseUrl ?? resolved.firstParty.baseUrl ?? "https://api.deepseek.com/anthropic";
21705
21829
  const mainModel = resolved.modelRef?.modelId ?? "deepseek-v4-flash";
21706
- const mainKey = readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
21707
- const search = resolved.webSearch ?? (!resolved.webSearchDisabled && mainKey && mainBaseUrl === "https://api.deepseek.com/anthropic" ? { provider: "deepseek", baseUrl: "https://api.deepseek.com/anthropic", model: "deepseek-flash", credentialRef: { key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" } } : void 0);
21830
+ const mainKey = mainRoute ? readMainCredential(environment, mainRoute.credentialRef, env) : readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
21831
+ const search = resolved.webSearch ?? (!resolved.webSearchDisabled && !mainRoute && mainKey && mainBaseUrl === "https://api.deepseek.com/anthropic" ? { provider: "deepseek", baseUrl: "https://api.deepseek.com/anthropic", model: "deepseek-flash", credentialRef: { key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" } } : void 0);
21708
21832
  const searchKeyName = search?.credentialRef.key;
21709
21833
  const searchKey = readEnvironmentKey(environment, searchKeyName) ?? (searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" ? mainKey : void 0);
21710
21834
  const rag = {};
@@ -21722,16 +21846,20 @@ function createNodeUserSettingsService(options = {}) {
21722
21846
  return {
21723
21847
  revision: revisionOf(current.original),
21724
21848
  main: {
21725
- provider: mainBaseUrl === "https://api.deepseek.com/anthropic" ? "deepseek" : "custom",
21849
+ provider: mainBaseUrl === "https://api.deepseek.com/anthropic" || mainRoute?.compatibilityPreset === "deepseek" ? "deepseek" : "custom",
21850
+ apiProtocol: mainRoute?.apiProtocol ?? "anthropic-messages",
21851
+ ...mainRoute?.compatibilityPreset ? { compatibilityPreset: mainRoute.compatibilityPreset } : {},
21726
21852
  baseUrl: mainBaseUrl,
21727
21853
  model: mainModel,
21728
21854
  configured: Boolean(mainKey),
21729
- availableModels: resolved.availableModels.length > 0 ? [...resolved.availableModels] : ["deepseek-v4-flash", "deepseek-v4-pro[1m]"],
21855
+ availableModels: mainRoute ? mainRoute.models.map(function modelId(model) {
21856
+ return model.id;
21857
+ }) : resolved.availableModels.length > 0 ? [...resolved.availableModels] : ["deepseek-v4-flash", "deepseek-v4-pro[1m]"],
21730
21858
  opusModel: typeof environment.ANTHROPIC_DEFAULT_OPUS_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_OPUS_MODEL : void 0,
21731
21859
  sonnetModel: typeof environment.ANTHROPIC_DEFAULT_SONNET_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_SONNET_MODEL : void 0,
21732
21860
  haikuModel: typeof environment.ANTHROPIC_DEFAULT_HAIKU_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_HAIKU_MODEL : void 0,
21733
21861
  subagentModel: resolved.firstParty.subagentModelId,
21734
- effort: typeof environment.CLAUDE_CODE_EFFORT_LEVEL === "string" ? environment.CLAUDE_CODE_EFFORT_LEVEL : void 0,
21862
+ effort: resolved.reasoningProfile?.effort ?? "auto",
21735
21863
  maxOutputTokens: resolved.firstParty.maxOutputTokens,
21736
21864
  compactWindow: resolved.firstParty.compactWindow,
21737
21865
  timeoutMs: resolved.firstParty.timeoutMs,
@@ -21739,7 +21867,7 @@ function createNodeUserSettingsService(options = {}) {
21739
21867
  },
21740
21868
  search: {
21741
21869
  enabled: Boolean(search),
21742
- useMainKey: searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN",
21870
+ useMainKey: mainRoute ? mainRoute.apiProtocol === "anthropic-messages" && mainRoute.baseUrl === "https://api.deepseek.com/anthropic" && searchKeyName === mainRoute.credentialRef.key : searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN",
21743
21871
  provider: search?.provider ?? "deepseek",
21744
21872
  baseUrl: search?.baseUrl ?? "https://api.deepseek.com",
21745
21873
  model: search?.model ?? "deepseek-v4-flash",
@@ -21757,7 +21885,7 @@ function createNodeUserSettingsService(options = {}) {
21757
21885
  /** 保存主模型分类并执行旧 route/哈希凭据迁移。 */
21758
21886
  saveMain(input, revision) {
21759
21887
  return save(function updateMain(raw) {
21760
- applyMainCategory(raw, input);
21888
+ applyMainCategory(raw, input, env);
21761
21889
  }, revision);
21762
21890
  },
21763
21891
  /** 原子保存设置中心的主模型分类,包含已经独立化的 Search 连接。 */
@@ -21766,8 +21894,8 @@ function createNodeUserSettingsService(options = {}) {
21766
21894
  return key2 !== "main" && key2 !== "search";
21767
21895
  })) return Promise.reject(new NodeUserSettingsError("SETTINGS_INPUT_INVALID"));
21768
21896
  return save(function updateMainAndSearch(raw) {
21769
- applyMainCategory(raw, input.main);
21770
- applyWebSearch(raw, input.search);
21897
+ applyMainCategory(raw, input.main, env);
21898
+ applyWebSearch(raw, input.search, env);
21771
21899
  }, revision);
21772
21900
  },
21773
21901
  /** 增量保存 RAG 分类;未提交角色保持不变。 */
@@ -22353,6 +22481,11 @@ function createNodeThreadRunner(options) {
22353
22481
  stop,
22354
22482
  kick,
22355
22483
  registerExecution,
22484
+ listExecutions: function listExecutions() {
22485
+ return [...active.values()].map(function identity(record) {
22486
+ return { threadId: record.threadId, turnId: record.turnId };
22487
+ });
22488
+ },
22356
22489
  isRunning: function isRunning() {
22357
22490
  return running;
22358
22491
  },
@@ -22362,6 +22495,64 @@ function createNodeThreadRunner(options) {
22362
22495
  };
22363
22496
  }
22364
22497
 
22498
+ // src/node/desktop-status-protocol.ts
22499
+ var DESKTOP_STATUS_VERSION = 1;
22500
+ var DESKTOP_STATUS_FRAME_BYTES = 64 * 1024;
22501
+ var DESKTOP_STATUS_QUEUE_BYTES = 256 * 1024;
22502
+ function isDesktopStatusId(value) {
22503
+ return typeof value === "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(value);
22504
+ }
22505
+ function fields(value, required, optional = []) {
22506
+ return !!value && typeof value === "object" && !Array.isArray(value) && required.every(function present(key2) {
22507
+ return Object.prototype.hasOwnProperty.call(value, key2);
22508
+ }) && Object.keys(value).every(function allowed(key2) {
22509
+ return required.includes(key2) || optional.includes(key2);
22510
+ });
22511
+ }
22512
+ function optionalEnum(value, values) {
22513
+ return value === void 0 || typeof value === "string" && values.includes(value);
22514
+ }
22515
+ function isDesktopSessionStatus(value) {
22516
+ if (!fields(value, ["sessionId", "selected", "relation", "freshness", "status", "lastSeq"], ["turnId", "execution", "waiting", "result", "interaction", "continuation", "recoverable"])) return false;
22517
+ return isDesktopStatusId(value.sessionId) && (value.turnId === void 0 || isDesktopStatusId(value.turnId)) && typeof value.selected === "boolean" && ["opened", "locallyDriven", "relatedObserved"].includes(value.relation) && ["fresh", "unknown"].includes(value.freshness) && ["idle", "running", "waiting_approval", "waiting_user_input", "completed", "failed", "interrupted"].includes(value.status) && Number.isSafeInteger(value.lastSeq) && value.lastSeq >= 0 && optionalEnum(value.execution, ["active", "inactive", "unconfirmed", "lost"]) && optionalEnum(value.waiting, ["approval", "user_input", "threads"]) && optionalEnum(value.result, ["completed", "failed", "interrupted", "limit_reached"]) && optionalEnum(value.interaction, ["pending", "decided", "expired", "unconfirmed"]) && optionalEnum(value.continuation, ["pending", "applied", "rejected", "claimed", "executing", "completed", "failed"]) && (value.recoverable === void 0 || typeof value.recoverable === "boolean");
22518
+ }
22519
+ function workspace(value) {
22520
+ return fields(value, ["workspaceId", "stateRootId", "projectId", "displayName"]) && isDesktopStatusId(value.workspaceId) && isDesktopStatusId(value.stateRootId) && isDesktopStatusId(value.projectId) && typeof value.displayName === "string" && value.displayName.length <= 80 && !/[\x00-\x1f\x7f/\\]/.test(value.displayName);
22521
+ }
22522
+ function isDesktopStatusFrame(value) {
22523
+ if (!value || typeof value !== "object") return false;
22524
+ const v = value;
22525
+ const common2 = ["protocolVersion", "desktopInstanceId", "paneId", "generation", "apInstanceId", "seq", "type"];
22526
+ if (v.protocolVersion !== 1 || !isDesktopStatusId(v.desktopInstanceId) || !isDesktopStatusId(v.paneId) || !isDesktopStatusId(v.apInstanceId) || !Number.isSafeInteger(v.generation) || v.generation < 1 || !Number.isSafeInteger(v.seq) || v.seq < 1) return false;
22527
+ if (v.type === "hello") return fields(v, [...common2, "token", "cliVersion"]) && typeof v.token === "string" && /^[0-9a-f]{64}$/.test(v.token) && typeof v.cliVersion === "string" && /^\d+\.\d+\.\d+[-\w.]*$/.test(v.cliVersion);
22528
+ if (v.type === "heartbeat" || v.type === "ap_exiting") return fields(v, common2);
22529
+ return v.type === "snapshot" && fields(v, [...common2, "snapshotId", "part", "final", "lifecycle", "sessions"], ["workspace"]) && isDesktopStatusId(v.snapshotId) && Number.isSafeInteger(v.part) && v.part >= 0 && typeof v.final === "boolean" && ["starting", "ready"].includes(v.lifecycle) && (v.workspace === void 0 || workspace(v.workspace)) && (v.lifecycle !== "ready" || v.workspace !== void 0) && Array.isArray(v.sessions) && v.sessions.length <= 128 && v.sessions.every(isDesktopSessionStatus) && (v.lifecycle !== "starting" || v.sessions.length === 0 && v.workspace === void 0);
22530
+ }
22531
+ function isDesktopStatusReply(value) {
22532
+ return fields(value, ["type", "seq"]) && ["accepted", "ack", "resync_required"].includes(value.type) && Number.isSafeInteger(value.seq) && value.seq >= 0;
22533
+ }
22534
+ var DesktopStatusLines = class {
22535
+ constructor() {
22536
+ this.pending = Buffer.alloc(0);
22537
+ }
22538
+ push(chunk) {
22539
+ const values = [];
22540
+ let offset = 0;
22541
+ while (offset < chunk.length) {
22542
+ const newline = chunk.indexOf(10, offset);
22543
+ const end = newline < 0 ? chunk.length : newline;
22544
+ if (this.pending.length + end - offset > DESKTOP_STATUS_FRAME_BYTES) throw new Error("STATUS_FRAME_INVALID");
22545
+ this.pending = Buffer.concat([this.pending, chunk.subarray(offset, end)]);
22546
+ if (newline < 0) break;
22547
+ const line = new TextDecoder("utf-8", { fatal: true }).decode(this.pending);
22548
+ this.pending = Buffer.alloc(0);
22549
+ values.push(JSON.parse(line));
22550
+ offset = newline + 1;
22551
+ }
22552
+ return values;
22553
+ }
22554
+ };
22555
+
22365
22556
  // src/node/thread-handoff.ts
22366
22557
  import { createHash as createHash8 } from "node:crypto";
22367
22558
  import fs34 from "node:fs";
@@ -22426,6 +22617,10 @@ export {
22426
22617
  DEFAULT_COMPACT_TARGET_RATIO,
22427
22618
  DEFAULT_COMPACT_TRIGGER_RATIO,
22428
22619
  DEFAULT_CONTEXT_WINDOW_TOKENS,
22620
+ DESKTOP_STATUS_FRAME_BYTES,
22621
+ DESKTOP_STATUS_QUEUE_BYTES,
22622
+ DESKTOP_STATUS_VERSION,
22623
+ DesktopStatusLines,
22429
22624
  LOCAL_HUMAN_PRINCIPAL_ID,
22430
22625
  NODE_CHAT_KNOWLEDGE_SPACE_ID,
22431
22626
  NODE_STATE_SCHEMA_VERSION,
@@ -22488,6 +22683,10 @@ export {
22488
22683
  getNodeStatePaths,
22489
22684
  getNodeStateSchemaDiagnostic,
22490
22685
  initializeNodeStateRoot,
22686
+ isDesktopSessionStatus,
22687
+ isDesktopStatusFrame,
22688
+ isDesktopStatusId,
22689
+ isDesktopStatusReply,
22491
22690
  isSafeSettingsFile,
22492
22691
  loadMcpConfigFromWorkspace,
22493
22692
  resolveNodeChatStatePaths,
@@ -22497,5 +22696,6 @@ export {
22497
22696
  resolveNodeTrustRoot,
22498
22697
  resolveNodeUserSettingsPath,
22499
22698
  retrieveNodeMemories,
22500
- serializePosixCommand
22699
+ serializePosixCommand,
22700
+ withNodeRuntimeOwner
22501
22701
  };