personal-bot 0.3.5 → 0.3.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 (86) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +191 -65
  4. package/README.zh-CN.md +189 -63
  5. package/docs/README.md +2 -2
  6. package/docs/architecture/design.md +3 -4
  7. package/docs/architecture/model-context.md +1 -2
  8. package/docs/guides/capabilities.md +4 -8
  9. package/docs/hosts/antigravity.md +4 -2
  10. package/docs/hosts/pi.md +4 -15
  11. package/docs/maintainers/release.md +2 -2
  12. package/lib/antigravity-plugin/lib/extension/acp-worker.js +2 -2
  13. package/lib/antigravity-plugin/lib/extension/cli.js +1403 -1504
  14. package/lib/antigravity-plugin/lib/extension/mcp.js +66 -49
  15. package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
  16. package/lib/antigravity-plugin/package.json +1 -1
  17. package/lib/antigravity-plugin/plugin.json +1 -1
  18. package/lib/antigravity-plugin/resources/agents/coordinator.md +3 -7
  19. package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
  20. package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
  21. package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
  22. package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
  23. package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
  24. package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
  25. package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
  26. package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
  27. package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
  28. package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
  29. package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +2 -2
  30. package/lib/extension/acp-worker.js +2 -2
  31. package/lib/extension/cli.js +1403 -1504
  32. package/lib/extension/mcp/tool-contract.js +49 -55
  33. package/lib/extension/mcp/workers.d.ts +6 -0
  34. package/lib/extension/mcp/workers.js +25 -8
  35. package/lib/extension/mcp.js +66 -49
  36. package/lib/integrations/agent-resources.js +2 -2
  37. package/lib/qoder-plugin/.mcp.json +2 -2
  38. package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
  39. package/lib/qoder-plugin/hooks/hooks.json +3 -3
  40. package/lib/qoder-plugin/skills/pbot/SKILL.md +2 -2
  41. package/lib/tools/history/contract.js +12 -12
  42. package/package.json +1 -1
  43. package/resources/agents/coordinator.md +3 -7
  44. package/resources/agents/general-purpose.md +3 -3
  45. package/resources/antigravity/skills/pbot/SKILL.md +14 -6
  46. package/resources/claude/skills/pbot/SKILL.md +14 -6
  47. package/resources/plugin/skills/pbot/SKILL.md +2 -2
  48. package/resources/prompts/history-coordinator.md +1 -2
  49. package/resources/prompts/plugin-coordinator.md +1 -2
  50. package/resources/prompts/workspace.md +12 -16
  51. package/resources/skills/provider-connections/SKILL.md +7 -6
  52. package/resources/templates/workspace-agents.md +0 -4
  53. package/src/extension/cli/commands/install.ts +77 -0
  54. package/src/extension/cli/index.ts +3 -4
  55. package/src/extension/mcp/tool-contract.ts +49 -55
  56. package/src/extension/mcp/workers.ts +32 -10
  57. package/src/integrations/agent-resources.ts +2 -2
  58. package/src/integrations/installation/installers/antigravity.ts +49 -0
  59. package/src/integrations/installation/installers/claude.ts +30 -0
  60. package/src/integrations/installation/installers/codex.ts +56 -0
  61. package/src/integrations/installation/installers/dsh.ts +25 -0
  62. package/src/integrations/installation/installers/pi.ts +26 -0
  63. package/src/integrations/installation/installers/qoder.ts +49 -0
  64. package/src/integrations/installation/installers/registry.ts +48 -0
  65. package/src/integrations/installation/processes.ts +2 -41
  66. package/src/model/installation.ts +28 -36
  67. package/src/pbot.ts +1 -1
  68. package/src/services/installation/install-service.ts +107 -0
  69. package/src/tools/history/contract.ts +12 -12
  70. package/lib/antigravity-plugin/resources/references/compute-finance.md +0 -22
  71. package/lib/antigravity-plugin/resources/references/compute.md +0 -16
  72. package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
  73. package/lib/common/package-source.js +0 -16
  74. package/lib/extension/setup/guard.js +0 -11
  75. package/lib/integrations/installation/pi-bridge.js +0 -131
  76. package/lib/model/installation.js +0 -1
  77. package/resources/installer/plugins.json +0 -16
  78. package/resources/references/compute-finance.md +0 -22
  79. package/resources/references/compute.md +0 -16
  80. package/resources/references/task-conductor.md +0 -25
  81. package/src/extension/cli/commands/setup.ts +0 -159
  82. package/src/extension/setup/guard.ts +0 -12
  83. package/src/integrations/installation/pi-bridge.ts +0 -109
  84. package/src/integrations/installation/pi-setup.ts +0 -165
  85. package/src/services/installation/setup-service.ts +0 -91
  86. package/src/ui/setup.ts +0 -40
@@ -524,11 +524,11 @@ var require_valid = __commonJS({
524
524
  "node_modules/semver/functions/valid.js"(exports, module) {
525
525
  "use strict";
526
526
  var parse = require_parse();
527
- var valid13 = (version, options) => {
527
+ var valid16 = (version, options) => {
528
528
  const v = parse(version, options);
529
529
  return v ? v.version : null;
530
530
  };
531
- module.exports = valid13;
531
+ module.exports = valid16;
532
532
  }
533
533
  });
534
534
 
@@ -881,10 +881,10 @@ var require_truncate = __commonJS({
881
881
  "node_modules/semver/functions/truncate.js"(exports, module) {
882
882
  "use strict";
883
883
  var parse = require_parse();
884
- var constants5 = require_constants();
884
+ var constants4 = require_constants();
885
885
  var SemVer = require_semver();
886
886
  var truncate = (version, truncation, options) => {
887
- if (!constants5.RELEASE_TYPES.includes(truncation)) {
887
+ if (!constants4.RELEASE_TYPES.includes(truncation)) {
888
888
  return null;
889
889
  }
890
890
  const clonedVersion = cloneInputVersion(version, options);
@@ -1933,11 +1933,11 @@ var require_semver2 = __commonJS({
1933
1933
  "node_modules/semver/index.js"(exports, module) {
1934
1934
  "use strict";
1935
1935
  var internalRe = require_re();
1936
- var constants5 = require_constants();
1936
+ var constants4 = require_constants();
1937
1937
  var SemVer = require_semver();
1938
1938
  var identifiers = require_identifiers();
1939
1939
  var parse = require_parse();
1940
- var valid13 = require_valid();
1940
+ var valid16 = require_valid();
1941
1941
  var clean = require_clean();
1942
1942
  var inc = require_inc();
1943
1943
  var diff = require_diff();
@@ -1976,7 +1976,7 @@ var require_semver2 = __commonJS({
1976
1976
  var subset = require_subset();
1977
1977
  module.exports = {
1978
1978
  parse,
1979
- valid: valid13,
1979
+ valid: valid16,
1980
1980
  clean,
1981
1981
  inc,
1982
1982
  diff,
@@ -2017,8 +2017,8 @@ var require_semver2 = __commonJS({
2017
2017
  re: internalRe.re,
2018
2018
  src: internalRe.src,
2019
2019
  tokens: internalRe.t,
2020
- SEMVER_SPEC_VERSION: constants5.SEMVER_SPEC_VERSION,
2021
- RELEASE_TYPES: constants5.RELEASE_TYPES,
2020
+ SEMVER_SPEC_VERSION: constants4.SEMVER_SPEC_VERSION,
2021
+ RELEASE_TYPES: constants4.RELEASE_TYPES,
2022
2022
  compareIdentifiers: identifiers.compareIdentifiers,
2023
2023
  rcompareIdentifiers: identifiers.rcompareIdentifiers
2024
2024
  };
@@ -7917,8 +7917,8 @@ var init_span = __esm({
7917
7917
  function TakeInitial2(quotes, input) {
7918
7918
  return Take(quotes, input);
7919
7919
  }
7920
- function TakeSpan(quote2, input) {
7921
- return Span(quote2, quote2, false, input);
7920
+ function TakeSpan(quote, input) {
7921
+ return Span(quote, quote, false, input);
7922
7922
  }
7923
7923
  function TakeString(quotes, input) {
7924
7924
  return Match2(TakeInitial2(quotes, input), (Initial2, InitialRest) => TakeSpan(Initial2, `${Initial2}${InitialRest}`), () => []);
@@ -12452,11 +12452,11 @@ var require_codegen = __commonJS({
12452
12452
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
12453
12453
  return `${varKind} ${this.name}${rhs};` + _n;
12454
12454
  }
12455
- optimizeNames(names, constants5) {
12455
+ optimizeNames(names, constants4) {
12456
12456
  if (!names[this.name.str])
12457
12457
  return;
12458
12458
  if (this.rhs)
12459
- this.rhs = optimizeExpr(this.rhs, names, constants5);
12459
+ this.rhs = optimizeExpr(this.rhs, names, constants4);
12460
12460
  return this;
12461
12461
  }
12462
12462
  get names() {
@@ -12473,10 +12473,10 @@ var require_codegen = __commonJS({
12473
12473
  render({ _n }) {
12474
12474
  return `${this.lhs} = ${this.rhs};` + _n;
12475
12475
  }
12476
- optimizeNames(names, constants5) {
12476
+ optimizeNames(names, constants4) {
12477
12477
  if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
12478
12478
  return;
12479
- this.rhs = optimizeExpr(this.rhs, names, constants5);
12479
+ this.rhs = optimizeExpr(this.rhs, names, constants4);
12480
12480
  return this;
12481
12481
  }
12482
12482
  get names() {
@@ -12537,8 +12537,8 @@ var require_codegen = __commonJS({
12537
12537
  optimizeNodes() {
12538
12538
  return `${this.code}` ? this : void 0;
12539
12539
  }
12540
- optimizeNames(names, constants5) {
12541
- this.code = optimizeExpr(this.code, names, constants5);
12540
+ optimizeNames(names, constants4) {
12541
+ this.code = optimizeExpr(this.code, names, constants4);
12542
12542
  return this;
12543
12543
  }
12544
12544
  get names() {
@@ -12567,12 +12567,12 @@ var require_codegen = __commonJS({
12567
12567
  }
12568
12568
  return nodes.length > 0 ? this : void 0;
12569
12569
  }
12570
- optimizeNames(names, constants5) {
12570
+ optimizeNames(names, constants4) {
12571
12571
  const { nodes } = this;
12572
12572
  let i = nodes.length;
12573
12573
  while (i--) {
12574
12574
  const n = nodes[i];
12575
- if (n.optimizeNames(names, constants5))
12575
+ if (n.optimizeNames(names, constants4))
12576
12576
  continue;
12577
12577
  subtractNames(names, n.names);
12578
12578
  nodes.splice(i, 1);
@@ -12625,12 +12625,12 @@ var require_codegen = __commonJS({
12625
12625
  return void 0;
12626
12626
  return this;
12627
12627
  }
12628
- optimizeNames(names, constants5) {
12628
+ optimizeNames(names, constants4) {
12629
12629
  var _a;
12630
- this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants5);
12631
- if (!(super.optimizeNames(names, constants5) || this.else))
12630
+ this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants4);
12631
+ if (!(super.optimizeNames(names, constants4) || this.else))
12632
12632
  return;
12633
- this.condition = optimizeExpr(this.condition, names, constants5);
12633
+ this.condition = optimizeExpr(this.condition, names, constants4);
12634
12634
  return this;
12635
12635
  }
12636
12636
  get names() {
@@ -12653,10 +12653,10 @@ var require_codegen = __commonJS({
12653
12653
  render(opts) {
12654
12654
  return `for(${this.iteration})` + super.render(opts);
12655
12655
  }
12656
- optimizeNames(names, constants5) {
12657
- if (!super.optimizeNames(names, constants5))
12656
+ optimizeNames(names, constants4) {
12657
+ if (!super.optimizeNames(names, constants4))
12658
12658
  return;
12659
- this.iteration = optimizeExpr(this.iteration, names, constants5);
12659
+ this.iteration = optimizeExpr(this.iteration, names, constants4);
12660
12660
  return this;
12661
12661
  }
12662
12662
  get names() {
@@ -12692,10 +12692,10 @@ var require_codegen = __commonJS({
12692
12692
  render(opts) {
12693
12693
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
12694
12694
  }
12695
- optimizeNames(names, constants5) {
12696
- if (!super.optimizeNames(names, constants5))
12695
+ optimizeNames(names, constants4) {
12696
+ if (!super.optimizeNames(names, constants4))
12697
12697
  return;
12698
- this.iterable = optimizeExpr(this.iterable, names, constants5);
12698
+ this.iterable = optimizeExpr(this.iterable, names, constants4);
12699
12699
  return this;
12700
12700
  }
12701
12701
  get names() {
@@ -12737,11 +12737,11 @@ var require_codegen = __commonJS({
12737
12737
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
12738
12738
  return this;
12739
12739
  }
12740
- optimizeNames(names, constants5) {
12740
+ optimizeNames(names, constants4) {
12741
12741
  var _a, _b;
12742
- super.optimizeNames(names, constants5);
12743
- (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants5);
12744
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants5);
12742
+ super.optimizeNames(names, constants4);
12743
+ (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants4);
12744
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants4);
12745
12745
  return this;
12746
12746
  }
12747
12747
  get names() {
@@ -13042,7 +13042,7 @@ var require_codegen = __commonJS({
13042
13042
  function addExprNames(names, from) {
13043
13043
  return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
13044
13044
  }
13045
- function optimizeExpr(expr, names, constants5) {
13045
+ function optimizeExpr(expr, names, constants4) {
13046
13046
  if (expr instanceof code_1.Name)
13047
13047
  return replaceName(expr);
13048
13048
  if (!canOptimize(expr))
@@ -13057,14 +13057,14 @@ var require_codegen = __commonJS({
13057
13057
  return items;
13058
13058
  }, []));
13059
13059
  function replaceName(n) {
13060
- const c = constants5[n.str];
13060
+ const c = constants4[n.str];
13061
13061
  if (c === void 0 || names[n.str] !== 1)
13062
13062
  return n;
13063
13063
  delete names[n.str];
13064
13064
  return c;
13065
13065
  }
13066
13066
  function canOptimize(e) {
13067
- return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants5[c.str] !== void 0);
13067
+ return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants4[c.str] !== void 0);
13068
13068
  }
13069
13069
  }
13070
13070
  function subtractNames(names, from) {
@@ -13446,13 +13446,13 @@ var require_boolSchema = __commonJS({
13446
13446
  }
13447
13447
  }
13448
13448
  exports.topBoolOrEmptySchema = topBoolOrEmptySchema;
13449
- function boolOrEmptySchema(it, valid13) {
13449
+ function boolOrEmptySchema(it, valid16) {
13450
13450
  const { gen, schema: schema2 } = it;
13451
13451
  if (schema2 === false) {
13452
- gen.var(valid13, false);
13452
+ gen.var(valid16, false);
13453
13453
  falseSchemaError(it);
13454
13454
  } else {
13455
- gen.var(valid13, true);
13455
+ gen.var(valid16, true);
13456
13456
  }
13457
13457
  }
13458
13458
  exports.boolOrEmptySchema = boolOrEmptySchema;
@@ -13833,15 +13833,15 @@ var require_code2 = __commonJS({
13833
13833
  exports.usePattern = usePattern;
13834
13834
  function validateArray(cxt) {
13835
13835
  const { gen, data, keyword, it } = cxt;
13836
- const valid13 = gen.name("valid");
13836
+ const valid16 = gen.name("valid");
13837
13837
  if (it.allErrors) {
13838
13838
  const validArr = gen.let("valid", true);
13839
13839
  validateItems(() => gen.assign(validArr, false));
13840
13840
  return validArr;
13841
13841
  }
13842
- gen.var(valid13, true);
13842
+ gen.var(valid16, true);
13843
13843
  validateItems(() => gen.break());
13844
- return valid13;
13844
+ return valid16;
13845
13845
  function validateItems(notValid) {
13846
13846
  const len = gen.const("len", (0, codegen_1._)`${data}.length`);
13847
13847
  gen.forRange("i", 0, len, (i) => {
@@ -13849,8 +13849,8 @@ var require_code2 = __commonJS({
13849
13849
  keyword,
13850
13850
  dataProp: i,
13851
13851
  dataPropType: util_1.Type.Num
13852
- }, valid13);
13853
- gen.if((0, codegen_1.not)(valid13), notValid);
13852
+ }, valid16);
13853
+ gen.if((0, codegen_1.not)(valid16), notValid);
13854
13854
  });
13855
13855
  }
13856
13856
  }
@@ -13862,7 +13862,7 @@ var require_code2 = __commonJS({
13862
13862
  const alwaysValid = schema2.some((sch) => (0, util_1.alwaysValidSchema)(it, sch));
13863
13863
  if (alwaysValid && !it.opts.unevaluated)
13864
13864
  return;
13865
- const valid13 = gen.let("valid", false);
13865
+ const valid16 = gen.let("valid", false);
13866
13866
  const schValid = gen.name("_valid");
13867
13867
  gen.block(() => schema2.forEach((_sch, i) => {
13868
13868
  const schCxt = cxt.subschema({
@@ -13870,12 +13870,12 @@ var require_code2 = __commonJS({
13870
13870
  schemaProp: i,
13871
13871
  compositeRule: true
13872
13872
  }, schValid);
13873
- gen.assign(valid13, (0, codegen_1._)`${valid13} || ${schValid}`);
13873
+ gen.assign(valid16, (0, codegen_1._)`${valid16} || ${schValid}`);
13874
13874
  const merged = cxt.mergeValidEvaluated(schCxt, schValid);
13875
13875
  if (!merged)
13876
- gen.if((0, codegen_1.not)(valid13));
13876
+ gen.if((0, codegen_1.not)(valid16));
13877
13877
  }));
13878
- cxt.result(valid13, () => cxt.reset(), () => cxt.error(true));
13878
+ cxt.result(valid16, () => cxt.reset(), () => cxt.error(true));
13879
13879
  }
13880
13880
  exports.validateUnion = validateUnion;
13881
13881
  }
@@ -13897,15 +13897,15 @@ var require_keyword = __commonJS({
13897
13897
  const schemaRef = useKeyword(gen, keyword, macroSchema);
13898
13898
  if (it.opts.validateSchema !== false)
13899
13899
  it.self.validateSchema(macroSchema, true);
13900
- const valid13 = gen.name("valid");
13900
+ const valid16 = gen.name("valid");
13901
13901
  cxt.subschema({
13902
13902
  schema: macroSchema,
13903
13903
  schemaPath: codegen_1.nil,
13904
13904
  errSchemaPath: `${it.errSchemaPath}/${keyword}`,
13905
13905
  topSchemaRef: schemaRef,
13906
13906
  compositeRule: true
13907
- }, valid13);
13908
- cxt.pass(valid13, () => cxt.error(true));
13907
+ }, valid16);
13908
+ cxt.pass(valid16, () => cxt.error(true));
13909
13909
  }
13910
13910
  exports.macroKeywordCode = macroKeywordCode;
13911
13911
  function funcKeywordCode(cxt, def) {
@@ -13914,9 +13914,9 @@ var require_keyword = __commonJS({
13914
13914
  checkAsyncKeyword(it, def);
13915
13915
  const validate = !$data && def.compile ? def.compile.call(it.self, schema2, parentSchema, it) : def.validate;
13916
13916
  const validateRef = useKeyword(gen, keyword, validate);
13917
- const valid13 = gen.let("valid");
13918
- cxt.block$data(valid13, validateKeyword);
13919
- cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid13);
13917
+ const valid16 = gen.let("valid");
13918
+ cxt.block$data(valid16, validateKeyword);
13919
+ cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid16);
13920
13920
  function validateKeyword() {
13921
13921
  if (def.errors === false) {
13922
13922
  assignValid();
@@ -13932,7 +13932,7 @@ var require_keyword = __commonJS({
13932
13932
  }
13933
13933
  function validateAsync() {
13934
13934
  const ruleErrs = gen.let("ruleErrs", null);
13935
- gen.try(() => assignValid((0, codegen_1._)`await `), (e) => gen.assign(valid13, false).if((0, codegen_1._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._)`${e}.errors`), () => gen.throw(e)));
13935
+ gen.try(() => assignValid((0, codegen_1._)`await `), (e) => gen.assign(valid16, false).if((0, codegen_1._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._)`${e}.errors`), () => gen.throw(e)));
13936
13936
  return ruleErrs;
13937
13937
  }
13938
13938
  function validateSync() {
@@ -13944,11 +13944,11 @@ var require_keyword = __commonJS({
13944
13944
  function assignValid(_await = def.async ? (0, codegen_1._)`await ` : codegen_1.nil) {
13945
13945
  const passCxt = it.opts.passContext ? names_1.default.this : names_1.default.self;
13946
13946
  const passSchema = !("compile" in def && !$data || def.schema === false);
13947
- gen.assign(valid13, (0, codegen_1._)`${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
13947
+ gen.assign(valid16, (0, codegen_1._)`${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
13948
13948
  }
13949
13949
  function reportErrs(errors) {
13950
13950
  var _a2;
13951
- gen.if((0, codegen_1.not)((_a2 = def.valid) !== null && _a2 !== void 0 ? _a2 : valid13), errors);
13951
+ gen.if((0, codegen_1.not)((_a2 = def.valid) !== null && _a2 !== void 0 ? _a2 : valid16), errors);
13952
13952
  }
13953
13953
  }
13954
13954
  exports.funcKeywordCode = funcKeywordCode;
@@ -13985,8 +13985,8 @@ var require_keyword = __commonJS({
13985
13985
  throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`);
13986
13986
  }
13987
13987
  if (def.validateSchema) {
13988
- const valid13 = def.validateSchema(schema2[keyword]);
13989
- if (!valid13) {
13988
+ const valid16 = def.validateSchema(schema2[keyword]);
13989
+ if (!valid16) {
13990
13990
  const msg = `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def.validateSchema.errors);
13991
13991
  if (opts.validateSchema === "log")
13992
13992
  self.logger.error(msg);
@@ -14446,15 +14446,15 @@ var require_validate = __commonJS({
14446
14446
  const schId = typeof schema2 == "object" && schema2[opts.schemaId];
14447
14447
  return schId && (opts.code.source || opts.code.process) ? (0, codegen_1._)`/*# sourceURL=${schId} */` : codegen_1.nil;
14448
14448
  }
14449
- function subschemaCode(it, valid13) {
14449
+ function subschemaCode(it, valid16) {
14450
14450
  if (isSchemaObj(it)) {
14451
14451
  checkKeywords(it);
14452
14452
  if (schemaCxtHasRules(it)) {
14453
- subSchemaObjCode(it, valid13);
14453
+ subSchemaObjCode(it, valid16);
14454
14454
  return;
14455
14455
  }
14456
14456
  }
14457
- (0, boolSchema_1.boolOrEmptySchema)(it, valid13);
14457
+ (0, boolSchema_1.boolOrEmptySchema)(it, valid16);
14458
14458
  }
14459
14459
  function schemaCxtHasRules({ schema: schema2, self }) {
14460
14460
  if (typeof schema2 == "boolean")
@@ -14467,7 +14467,7 @@ var require_validate = __commonJS({
14467
14467
  function isSchemaObj(it) {
14468
14468
  return typeof it.schema != "boolean";
14469
14469
  }
14470
- function subSchemaObjCode(it, valid13) {
14470
+ function subSchemaObjCode(it, valid16) {
14471
14471
  const { schema: schema2, gen, opts } = it;
14472
14472
  if (opts.$comment && schema2.$comment)
14473
14473
  commentKeyword(it);
@@ -14475,7 +14475,7 @@ var require_validate = __commonJS({
14475
14475
  checkAsyncSchema(it);
14476
14476
  const errsCount = gen.const("_errs", names_1.default.errors);
14477
14477
  typeAndKeywords(it, errsCount);
14478
- gen.var(valid13, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
14478
+ gen.var(valid16, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
14479
14479
  }
14480
14480
  function checkKeywords(it) {
14481
14481
  (0, util_1.checkUnknownRules)(it);
@@ -14742,24 +14742,24 @@ var require_validate = __commonJS({
14742
14742
  else
14743
14743
  this.params = obj;
14744
14744
  }
14745
- block$data(valid13, codeBlock, $dataValid = codegen_1.nil) {
14745
+ block$data(valid16, codeBlock, $dataValid = codegen_1.nil) {
14746
14746
  this.gen.block(() => {
14747
- this.check$data(valid13, $dataValid);
14747
+ this.check$data(valid16, $dataValid);
14748
14748
  codeBlock();
14749
14749
  });
14750
14750
  }
14751
- check$data(valid13 = codegen_1.nil, $dataValid = codegen_1.nil) {
14751
+ check$data(valid16 = codegen_1.nil, $dataValid = codegen_1.nil) {
14752
14752
  if (!this.$data)
14753
14753
  return;
14754
14754
  const { gen, schemaCode, schemaType, def } = this;
14755
14755
  gen.if((0, codegen_1.or)((0, codegen_1._)`${schemaCode} === undefined`, $dataValid));
14756
- if (valid13 !== codegen_1.nil)
14757
- gen.assign(valid13, true);
14756
+ if (valid16 !== codegen_1.nil)
14757
+ gen.assign(valid16, true);
14758
14758
  if (schemaType.length || def.validateSchema) {
14759
14759
  gen.elseIf(this.invalid$data());
14760
14760
  this.$dataError();
14761
- if (valid13 !== codegen_1.nil)
14762
- gen.assign(valid13, false);
14761
+ if (valid16 !== codegen_1.nil)
14762
+ gen.assign(valid16, false);
14763
14763
  }
14764
14764
  gen.else();
14765
14765
  }
@@ -14783,12 +14783,12 @@ var require_validate = __commonJS({
14783
14783
  return codegen_1.nil;
14784
14784
  }
14785
14785
  }
14786
- subschema(appl, valid13) {
14786
+ subschema(appl, valid16) {
14787
14787
  const subschema = (0, subschema_1.getSubschema)(this.it, appl);
14788
14788
  (0, subschema_1.extendSubschemaData)(subschema, this.it, appl);
14789
14789
  (0, subschema_1.extendSubschemaMode)(subschema, appl);
14790
14790
  const nextContext = { ...this.it, ...subschema, items: void 0, props: void 0 };
14791
- subschemaCode(nextContext, valid13);
14791
+ subschemaCode(nextContext, valid16);
14792
14792
  return nextContext;
14793
14793
  }
14794
14794
  mergeEvaluated(schemaCxt, toName) {
@@ -14802,10 +14802,10 @@ var require_validate = __commonJS({
14802
14802
  it.items = util_1.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
14803
14803
  }
14804
14804
  }
14805
- mergeValidEvaluated(schemaCxt, valid13) {
14805
+ mergeValidEvaluated(schemaCxt, valid16) {
14806
14806
  const { it, gen } = this;
14807
14807
  if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
14808
- gen.if(valid13, () => this.mergeEvaluated(schemaCxt, codegen_1.Name));
14808
+ gen.if(valid16, () => this.mergeEvaluated(schemaCxt, codegen_1.Name));
14809
14809
  return true;
14810
14810
  }
14811
14811
  }
@@ -15026,7 +15026,7 @@ var require_compile = __commonJS({
15026
15026
  const schOrFunc = root.refs[ref];
15027
15027
  if (schOrFunc)
15028
15028
  return schOrFunc;
15029
- let _sch = resolve12.call(this, root, ref);
15029
+ let _sch = resolve11.call(this, root, ref);
15030
15030
  if (_sch === void 0) {
15031
15031
  const schema2 = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
15032
15032
  const { schemaId } = this.opts;
@@ -15053,7 +15053,7 @@ var require_compile = __commonJS({
15053
15053
  function sameSchemaEnv(s1, s2) {
15054
15054
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
15055
15055
  }
15056
- function resolve12(root, ref) {
15056
+ function resolve11(root, ref) {
15057
15057
  let sch;
15058
15058
  while (typeof (sch = this.refs[ref]) == "string")
15059
15059
  ref = sch;
@@ -15917,7 +15917,7 @@ var require_fast_uri = __commonJS({
15917
15917
  }
15918
15918
  return uri;
15919
15919
  }
15920
- function resolve12(baseURI, relativeURI, options) {
15920
+ function resolve11(baseURI, relativeURI, options) {
15921
15921
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
15922
15922
  const {
15923
15923
  parsed: baseParsed,
@@ -16308,7 +16308,7 @@ var require_fast_uri = __commonJS({
16308
16308
  var fastUri = {
16309
16309
  SCHEMES,
16310
16310
  normalize,
16311
- resolve: resolve12,
16311
+ resolve: resolve11,
16312
16312
  resolveComponent,
16313
16313
  equal,
16314
16314
  serialize,
@@ -16495,10 +16495,10 @@ var require_core = __commonJS({
16495
16495
  } else {
16496
16496
  v = this.compile(schemaKeyRef);
16497
16497
  }
16498
- const valid13 = v(data);
16498
+ const valid16 = v(data);
16499
16499
  if (!("$async" in v))
16500
16500
  this.errors = v.errors;
16501
- return valid13;
16501
+ return valid16;
16502
16502
  }
16503
16503
  compile(schema2, _meta) {
16504
16504
  const sch = this._addSchema(schema2, _meta);
@@ -16595,15 +16595,15 @@ var require_core = __commonJS({
16595
16595
  this.errors = null;
16596
16596
  return true;
16597
16597
  }
16598
- const valid13 = this.validate($schema, schema2);
16599
- if (!valid13 && throwOrLogError) {
16598
+ const valid16 = this.validate($schema, schema2);
16599
+ if (!valid16 && throwOrLogError) {
16600
16600
  const message = "schema is invalid: " + this.errorsText();
16601
16601
  if (this.opts.validateSchema === "log")
16602
16602
  this.logger.error(message);
16603
16603
  else
16604
16604
  throw new Error(message);
16605
16605
  }
16606
- return valid13;
16606
+ return valid16;
16607
16607
  }
16608
16608
  // Get compiled schema by `key` or `ref`.
16609
16609
  // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)
@@ -16996,16 +16996,16 @@ var require_ref = __commonJS({
16996
16996
  }
16997
16997
  function inlineRefSchema(sch) {
16998
16998
  const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
16999
- const valid13 = gen.name("valid");
16999
+ const valid16 = gen.name("valid");
17000
17000
  const schCxt = cxt.subschema({
17001
17001
  schema: sch,
17002
17002
  dataTypes: [],
17003
17003
  schemaPath: codegen_1.nil,
17004
17004
  topSchemaRef: schName,
17005
17005
  errSchemaPath: $ref
17006
- }, valid13);
17006
+ }, valid16);
17007
17007
  cxt.mergeEvaluated(schCxt);
17008
- cxt.ok(valid13);
17008
+ cxt.ok(valid16);
17009
17009
  }
17010
17010
  }
17011
17011
  };
@@ -17025,19 +17025,19 @@ var require_ref = __commonJS({
17025
17025
  function callAsyncRef() {
17026
17026
  if (!env.$async)
17027
17027
  throw new Error("async schema referenced by sync schema");
17028
- const valid13 = gen.let("valid");
17028
+ const valid16 = gen.let("valid");
17029
17029
  gen.try(() => {
17030
17030
  gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt, v, passCxt)}`);
17031
17031
  addEvaluatedFrom(v);
17032
17032
  if (!allErrors)
17033
- gen.assign(valid13, true);
17033
+ gen.assign(valid16, true);
17034
17034
  }, (e) => {
17035
17035
  gen.if((0, codegen_1._)`!(${e} instanceof ${it.ValidationError})`, () => gen.throw(e));
17036
17036
  addErrorsFrom(e);
17037
17037
  if (!allErrors)
17038
- gen.assign(valid13, false);
17038
+ gen.assign(valid16, false);
17039
17039
  });
17040
- cxt.ok(valid13);
17040
+ cxt.ok(valid16);
17041
17041
  }
17042
17042
  function callSyncRef() {
17043
17043
  cxt.result((0, code_1.callValidateCode)(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
@@ -17242,9 +17242,9 @@ var require_pattern = __commonJS({
17242
17242
  if ($data) {
17243
17243
  const { regExp } = it.opts.code;
17244
17244
  const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._)`new RegExp` : (0, util_1.useFunc)(gen, regExp);
17245
- const valid13 = gen.let("valid");
17246
- gen.try(() => gen.assign(valid13, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid13, false));
17247
- cxt.fail$data((0, codegen_1._)`!${valid13}`);
17245
+ const valid16 = gen.let("valid");
17246
+ gen.try(() => gen.assign(valid16, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid16, false));
17247
+ cxt.fail$data((0, codegen_1._)`!${valid16}`);
17248
17248
  } else {
17249
17249
  const regExp = (0, code_1.usePattern)(cxt, schema2);
17250
17250
  cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
@@ -17335,9 +17335,9 @@ var require_required = __commonJS({
17335
17335
  function exitOnErrorMode() {
17336
17336
  const missing = gen.let("missing");
17337
17337
  if (useLoop || $data) {
17338
- const valid13 = gen.let("valid", true);
17339
- cxt.block$data(valid13, () => loopUntilMissing(missing, valid13));
17340
- cxt.ok(valid13);
17338
+ const valid16 = gen.let("valid", true);
17339
+ cxt.block$data(valid16, () => loopUntilMissing(missing, valid16));
17340
+ cxt.ok(valid16);
17341
17341
  } else {
17342
17342
  gen.if((0, code_1.checkMissingProp)(cxt, schema2, missing));
17343
17343
  (0, code_1.reportMissingProp)(cxt, missing);
@@ -17350,11 +17350,11 @@ var require_required = __commonJS({
17350
17350
  gen.if((0, code_1.noPropertyInData)(gen, data, prop, opts.ownProperties), () => cxt.error());
17351
17351
  });
17352
17352
  }
17353
- function loopUntilMissing(missing, valid13) {
17353
+ function loopUntilMissing(missing, valid16) {
17354
17354
  cxt.setParams({ missingProperty: missing });
17355
17355
  gen.forOf(missing, schemaCode, () => {
17356
- gen.assign(valid13, (0, code_1.propertyInData)(gen, data, missing, opts.ownProperties));
17357
- gen.if((0, codegen_1.not)(valid13), () => {
17356
+ gen.assign(valid16, (0, code_1.propertyInData)(gen, data, missing, opts.ownProperties));
17357
+ gen.if((0, codegen_1.not)(valid16), () => {
17358
17358
  cxt.error();
17359
17359
  gen.break();
17360
17360
  });
@@ -17429,15 +17429,15 @@ var require_uniqueItems = __commonJS({
17429
17429
  const { gen, data, $data, schema: schema2, parentSchema, schemaCode, it } = cxt;
17430
17430
  if (!$data && !schema2)
17431
17431
  return;
17432
- const valid13 = gen.let("valid");
17432
+ const valid16 = gen.let("valid");
17433
17433
  const itemTypes = parentSchema.items ? (0, dataType_1.getSchemaTypes)(parentSchema.items) : [];
17434
- cxt.block$data(valid13, validateUniqueItems, (0, codegen_1._)`${schemaCode} === false`);
17435
- cxt.ok(valid13);
17434
+ cxt.block$data(valid16, validateUniqueItems, (0, codegen_1._)`${schemaCode} === false`);
17435
+ cxt.ok(valid16);
17436
17436
  function validateUniqueItems() {
17437
17437
  const i = gen.let("i", (0, codegen_1._)`${data}.length`);
17438
17438
  const j = gen.let("j");
17439
17439
  cxt.setParams({ i, j });
17440
- gen.assign(valid13, true);
17440
+ gen.assign(valid16, true);
17441
17441
  gen.if((0, codegen_1._)`${i} > 1`, () => (canOptimize() ? loopN : loopN2)(i, j));
17442
17442
  }
17443
17443
  function canOptimize() {
@@ -17455,7 +17455,7 @@ var require_uniqueItems = __commonJS({
17455
17455
  gen.if((0, codegen_1._)`typeof ${indices}[${item}] == "number"`, () => {
17456
17456
  gen.assign(j, (0, codegen_1._)`${indices}[${item}]`);
17457
17457
  cxt.error();
17458
- gen.assign(valid13, false).break();
17458
+ gen.assign(valid16, false).break();
17459
17459
  }).code((0, codegen_1._)`${indices}[${item}] = ${i}`);
17460
17460
  });
17461
17461
  }
@@ -17464,7 +17464,7 @@ var require_uniqueItems = __commonJS({
17464
17464
  const outer = gen.name("outer");
17465
17465
  gen.label(outer).for((0, codegen_1._)`;${i}--;`, () => gen.for((0, codegen_1._)`${j} = ${i}; ${j}--;`, () => gen.if((0, codegen_1._)`${eql}(${data}[${i}], ${data}[${j}])`, () => {
17466
17466
  cxt.error();
17467
- gen.assign(valid13, false).break(outer);
17467
+ gen.assign(valid16, false).break(outer);
17468
17468
  })));
17469
17469
  }
17470
17470
  }
@@ -17526,20 +17526,20 @@ var require_enum = __commonJS({
17526
17526
  const useLoop = schema2.length >= it.opts.loopEnum;
17527
17527
  let eql;
17528
17528
  const getEql = () => eql !== null && eql !== void 0 ? eql : eql = (0, util_1.useFunc)(gen, equal_1.default);
17529
- let valid13;
17529
+ let valid16;
17530
17530
  if (useLoop || $data) {
17531
- valid13 = gen.let("valid");
17532
- cxt.block$data(valid13, loopEnum);
17531
+ valid16 = gen.let("valid");
17532
+ cxt.block$data(valid16, loopEnum);
17533
17533
  } else {
17534
17534
  if (!Array.isArray(schema2))
17535
17535
  throw new Error("ajv implementation error");
17536
17536
  const vSchema = gen.const("vSchema", schemaCode);
17537
- valid13 = (0, codegen_1.or)(...schema2.map((_x, i) => equalCode(vSchema, i)));
17537
+ valid16 = (0, codegen_1.or)(...schema2.map((_x, i) => equalCode(vSchema, i)));
17538
17538
  }
17539
- cxt.pass(valid13);
17539
+ cxt.pass(valid16);
17540
17540
  function loopEnum() {
17541
- gen.assign(valid13, false);
17542
- gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v})`, () => gen.assign(valid13, true).break()));
17541
+ gen.assign(valid16, false);
17542
+ gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v})`, () => gen.assign(valid16, true).break()));
17543
17543
  }
17544
17544
  function equalCode(vSchema, i) {
17545
17545
  const sch = schema2[i];
@@ -17625,15 +17625,15 @@ var require_additionalItems = __commonJS({
17625
17625
  cxt.setParams({ len: items.length });
17626
17626
  cxt.pass((0, codegen_1._)`${len} <= ${items.length}`);
17627
17627
  } else if (typeof schema2 == "object" && !(0, util_1.alwaysValidSchema)(it, schema2)) {
17628
- const valid13 = gen.var("valid", (0, codegen_1._)`${len} <= ${items.length}`);
17629
- gen.if((0, codegen_1.not)(valid13), () => validateItems(valid13));
17630
- cxt.ok(valid13);
17628
+ const valid16 = gen.var("valid", (0, codegen_1._)`${len} <= ${items.length}`);
17629
+ gen.if((0, codegen_1.not)(valid16), () => validateItems(valid16));
17630
+ cxt.ok(valid16);
17631
17631
  }
17632
- function validateItems(valid13) {
17632
+ function validateItems(valid16) {
17633
17633
  gen.forRange("i", items.length, len, (i) => {
17634
- cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num }, valid13);
17634
+ cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num }, valid16);
17635
17635
  if (!it.allErrors)
17636
- gen.if((0, codegen_1.not)(valid13), () => gen.break());
17636
+ gen.if((0, codegen_1.not)(valid16), () => gen.break());
17637
17637
  });
17638
17638
  }
17639
17639
  }
@@ -17672,7 +17672,7 @@ var require_items = __commonJS({
17672
17672
  if (it.opts.unevaluated && schArr.length && it.items !== true) {
17673
17673
  it.items = util_1.mergeEvaluated.items(gen, schArr.length, it.items);
17674
17674
  }
17675
- const valid13 = gen.name("valid");
17675
+ const valid16 = gen.name("valid");
17676
17676
  const len = gen.const("len", (0, codegen_1._)`${data}.length`);
17677
17677
  schArr.forEach((sch, i) => {
17678
17678
  if ((0, util_1.alwaysValidSchema)(it, sch))
@@ -17681,8 +17681,8 @@ var require_items = __commonJS({
17681
17681
  keyword,
17682
17682
  schemaProp: i,
17683
17683
  dataProp: i
17684
- }, valid13));
17685
- cxt.ok(valid13);
17684
+ }, valid16));
17685
+ cxt.ok(valid16);
17686
17686
  });
17687
17687
  function checkStrictTuple(sch) {
17688
17688
  const { opts, errSchemaPath } = it;
@@ -17799,18 +17799,18 @@ var require_contains = __commonJS({
17799
17799
  return;
17800
17800
  }
17801
17801
  it.items = true;
17802
- const valid13 = gen.name("valid");
17802
+ const valid16 = gen.name("valid");
17803
17803
  if (max === void 0 && min === 1) {
17804
- validateItems(valid13, () => gen.if(valid13, () => gen.break()));
17804
+ validateItems(valid16, () => gen.if(valid16, () => gen.break()));
17805
17805
  } else if (min === 0) {
17806
- gen.let(valid13, true);
17806
+ gen.let(valid16, true);
17807
17807
  if (max !== void 0)
17808
17808
  gen.if((0, codegen_1._)`${data}.length > 0`, validateItemsWithCount);
17809
17809
  } else {
17810
- gen.let(valid13, false);
17810
+ gen.let(valid16, false);
17811
17811
  validateItemsWithCount();
17812
17812
  }
17813
- cxt.result(valid13, () => cxt.reset());
17813
+ cxt.result(valid16, () => cxt.reset());
17814
17814
  function validateItemsWithCount() {
17815
17815
  const schValid = gen.name("_valid");
17816
17816
  const count = gen.let("count", 0);
@@ -17830,13 +17830,13 @@ var require_contains = __commonJS({
17830
17830
  function checkLimits(count) {
17831
17831
  gen.code((0, codegen_1._)`${count}++`);
17832
17832
  if (max === void 0) {
17833
- gen.if((0, codegen_1._)`${count} >= ${min}`, () => gen.assign(valid13, true).break());
17833
+ gen.if((0, codegen_1._)`${count} >= ${min}`, () => gen.assign(valid16, true).break());
17834
17834
  } else {
17835
- gen.if((0, codegen_1._)`${count} > ${max}`, () => gen.assign(valid13, false).break());
17835
+ gen.if((0, codegen_1._)`${count} > ${max}`, () => gen.assign(valid16, false).break());
17836
17836
  if (min === 1)
17837
- gen.assign(valid13, true);
17837
+ gen.assign(valid16, true);
17838
17838
  else
17839
- gen.if((0, codegen_1._)`${count} >= ${min}`, () => gen.assign(valid13, true));
17839
+ gen.if((0, codegen_1._)`${count} >= ${min}`, () => gen.assign(valid16, true));
17840
17840
  }
17841
17841
  }
17842
17842
  }
@@ -17918,20 +17918,20 @@ var require_dependencies = __commonJS({
17918
17918
  exports.validatePropertyDeps = validatePropertyDeps;
17919
17919
  function validateSchemaDeps(cxt, schemaDeps = cxt.schema) {
17920
17920
  const { gen, data, keyword, it } = cxt;
17921
- const valid13 = gen.name("valid");
17921
+ const valid16 = gen.name("valid");
17922
17922
  for (const prop in schemaDeps) {
17923
17923
  if ((0, util_1.alwaysValidSchema)(it, schemaDeps[prop]))
17924
17924
  continue;
17925
17925
  gen.if(
17926
17926
  (0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties),
17927
17927
  () => {
17928
- const schCxt = cxt.subschema({ keyword, schemaProp: prop }, valid13);
17929
- cxt.mergeValidEvaluated(schCxt, valid13);
17928
+ const schCxt = cxt.subschema({ keyword, schemaProp: prop }, valid16);
17929
+ cxt.mergeValidEvaluated(schCxt, valid16);
17930
17930
  },
17931
- () => gen.var(valid13, true)
17931
+ () => gen.var(valid16, true)
17932
17932
  // TODO var
17933
17933
  );
17934
- cxt.ok(valid13);
17934
+ cxt.ok(valid16);
17935
17935
  }
17936
17936
  }
17937
17937
  exports.validateSchemaDeps = validateSchemaDeps;
@@ -17959,7 +17959,7 @@ var require_propertyNames = __commonJS({
17959
17959
  const { gen, schema: schema2, data, it } = cxt;
17960
17960
  if ((0, util_1.alwaysValidSchema)(it, schema2))
17961
17961
  return;
17962
- const valid13 = gen.name("valid");
17962
+ const valid16 = gen.name("valid");
17963
17963
  gen.forIn("key", data, (key) => {
17964
17964
  cxt.setParams({ propertyName: key });
17965
17965
  cxt.subschema({
@@ -17968,14 +17968,14 @@ var require_propertyNames = __commonJS({
17968
17968
  dataTypes: ["string"],
17969
17969
  propertyName: key,
17970
17970
  compositeRule: true
17971
- }, valid13);
17972
- gen.if((0, codegen_1.not)(valid13), () => {
17971
+ }, valid16);
17972
+ gen.if((0, codegen_1.not)(valid16), () => {
17973
17973
  cxt.error(true);
17974
17974
  if (!it.allErrors)
17975
17975
  gen.break();
17976
17976
  });
17977
17977
  });
17978
- cxt.ok(valid13);
17978
+ cxt.ok(valid16);
17979
17979
  }
17980
17980
  };
17981
17981
  exports.default = def;
@@ -18053,21 +18053,21 @@ var require_additionalProperties = __commonJS({
18053
18053
  return;
18054
18054
  }
18055
18055
  if (typeof schema2 == "object" && !(0, util_1.alwaysValidSchema)(it, schema2)) {
18056
- const valid13 = gen.name("valid");
18056
+ const valid16 = gen.name("valid");
18057
18057
  if (opts.removeAdditional === "failing") {
18058
- applyAdditionalSchema(key, valid13, false);
18059
- gen.if((0, codegen_1.not)(valid13), () => {
18058
+ applyAdditionalSchema(key, valid16, false);
18059
+ gen.if((0, codegen_1.not)(valid16), () => {
18060
18060
  cxt.reset();
18061
18061
  deleteAdditional(key);
18062
18062
  });
18063
18063
  } else {
18064
- applyAdditionalSchema(key, valid13);
18064
+ applyAdditionalSchema(key, valid16);
18065
18065
  if (!allErrors)
18066
- gen.if((0, codegen_1.not)(valid13), () => gen.break());
18066
+ gen.if((0, codegen_1.not)(valid16), () => gen.break());
18067
18067
  }
18068
18068
  }
18069
18069
  }
18070
- function applyAdditionalSchema(key, valid13, errors) {
18070
+ function applyAdditionalSchema(key, valid16, errors) {
18071
18071
  const subschema = {
18072
18072
  keyword: "additionalProperties",
18073
18073
  dataProp: key,
@@ -18080,7 +18080,7 @@ var require_additionalProperties = __commonJS({
18080
18080
  allErrors: false
18081
18081
  });
18082
18082
  }
18083
- cxt.subschema(subschema, valid13);
18083
+ cxt.subschema(subschema, valid16);
18084
18084
  }
18085
18085
  }
18086
18086
  };
@@ -18116,7 +18116,7 @@ var require_properties = __commonJS({
18116
18116
  const properties = allProps.filter((p) => !(0, util_1.alwaysValidSchema)(it, schema2[p]));
18117
18117
  if (properties.length === 0)
18118
18118
  return;
18119
- const valid13 = gen.name("valid");
18119
+ const valid16 = gen.name("valid");
18120
18120
  for (const prop of properties) {
18121
18121
  if (hasDefault(prop)) {
18122
18122
  applyPropertySchema(prop);
@@ -18124,11 +18124,11 @@ var require_properties = __commonJS({
18124
18124
  gen.if((0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties));
18125
18125
  applyPropertySchema(prop);
18126
18126
  if (!it.allErrors)
18127
- gen.else().var(valid13, true);
18127
+ gen.else().var(valid16, true);
18128
18128
  gen.endIf();
18129
18129
  }
18130
18130
  cxt.it.definedProperties.add(prop);
18131
- cxt.ok(valid13);
18131
+ cxt.ok(valid16);
18132
18132
  }
18133
18133
  function hasDefault(prop) {
18134
18134
  return it.opts.useDefaults && !it.compositeRule && schema2[prop].default !== void 0;
@@ -18138,7 +18138,7 @@ var require_properties = __commonJS({
18138
18138
  keyword: "properties",
18139
18139
  schemaProp: prop,
18140
18140
  dataProp: prop
18141
- }, valid13);
18141
+ }, valid16);
18142
18142
  }
18143
18143
  }
18144
18144
  };
@@ -18168,7 +18168,7 @@ var require_patternProperties = __commonJS({
18168
18168
  return;
18169
18169
  }
18170
18170
  const checkProperties = opts.strictSchema && !opts.allowMatchingProperties && parentSchema.properties;
18171
- const valid13 = gen.name("valid");
18171
+ const valid16 = gen.name("valid");
18172
18172
  if (it.props !== true && !(it.props instanceof codegen_1.Name)) {
18173
18173
  it.props = (0, util_2.evaluatedPropsToName)(gen, it.props);
18174
18174
  }
@@ -18181,9 +18181,9 @@ var require_patternProperties = __commonJS({
18181
18181
  if (it.allErrors) {
18182
18182
  validateProperties(pat);
18183
18183
  } else {
18184
- gen.var(valid13, true);
18184
+ gen.var(valid16, true);
18185
18185
  validateProperties(pat);
18186
- gen.if(valid13);
18186
+ gen.if(valid16);
18187
18187
  }
18188
18188
  }
18189
18189
  }
@@ -18204,12 +18204,12 @@ var require_patternProperties = __commonJS({
18204
18204
  schemaProp: pat,
18205
18205
  dataProp: key,
18206
18206
  dataPropType: util_2.Type.Str
18207
- }, valid13);
18207
+ }, valid16);
18208
18208
  }
18209
18209
  if (it.opts.unevaluated && props !== true) {
18210
18210
  gen.assign((0, codegen_1._)`${props}[${key}]`, true);
18211
18211
  } else if (!alwaysValid && !it.allErrors) {
18212
- gen.if((0, codegen_1.not)(valid13), () => gen.break());
18212
+ gen.if((0, codegen_1.not)(valid16), () => gen.break());
18213
18213
  }
18214
18214
  });
18215
18215
  });
@@ -18236,14 +18236,14 @@ var require_not = __commonJS({
18236
18236
  cxt.fail();
18237
18237
  return;
18238
18238
  }
18239
- const valid13 = gen.name("valid");
18239
+ const valid16 = gen.name("valid");
18240
18240
  cxt.subschema({
18241
18241
  keyword: "not",
18242
18242
  compositeRule: true,
18243
18243
  createErrors: false,
18244
18244
  allErrors: false
18245
- }, valid13);
18246
- cxt.failResult(valid13, () => cxt.reset(), () => cxt.error());
18245
+ }, valid16);
18246
+ cxt.failResult(valid16, () => cxt.reset(), () => cxt.error());
18247
18247
  },
18248
18248
  error: { message: "must NOT be valid" }
18249
18249
  };
@@ -18291,12 +18291,12 @@ var require_oneOf = __commonJS({
18291
18291
  if (it.opts.discriminator && parentSchema.discriminator)
18292
18292
  return;
18293
18293
  const schArr = schema2;
18294
- const valid13 = gen.let("valid", false);
18294
+ const valid16 = gen.let("valid", false);
18295
18295
  const passing = gen.let("passing", null);
18296
18296
  const schValid = gen.name("_valid");
18297
18297
  cxt.setParams({ passing });
18298
18298
  gen.block(validateOneOf);
18299
- cxt.result(valid13, () => cxt.reset(), () => cxt.error(true));
18299
+ cxt.result(valid16, () => cxt.reset(), () => cxt.error(true));
18300
18300
  function validateOneOf() {
18301
18301
  schArr.forEach((sch, i) => {
18302
18302
  let schCxt;
@@ -18310,10 +18310,10 @@ var require_oneOf = __commonJS({
18310
18310
  }, schValid);
18311
18311
  }
18312
18312
  if (i > 0) {
18313
- gen.if((0, codegen_1._)`${schValid} && ${valid13}`).assign(valid13, false).assign(passing, (0, codegen_1._)`[${passing}, ${i}]`).else();
18313
+ gen.if((0, codegen_1._)`${schValid} && ${valid16}`).assign(valid16, false).assign(passing, (0, codegen_1._)`[${passing}, ${i}]`).else();
18314
18314
  }
18315
18315
  gen.if(schValid, () => {
18316
- gen.assign(valid13, true);
18316
+ gen.assign(valid16, true);
18317
18317
  gen.assign(passing, i);
18318
18318
  if (schCxt)
18319
18319
  cxt.mergeEvaluated(schCxt, codegen_1.Name);
@@ -18339,12 +18339,12 @@ var require_allOf = __commonJS({
18339
18339
  const { gen, schema: schema2, it } = cxt;
18340
18340
  if (!Array.isArray(schema2))
18341
18341
  throw new Error("ajv implementation error");
18342
- const valid13 = gen.name("valid");
18342
+ const valid16 = gen.name("valid");
18343
18343
  schema2.forEach((sch, i) => {
18344
18344
  if ((0, util_1.alwaysValidSchema)(it, sch))
18345
18345
  return;
18346
- const schCxt = cxt.subschema({ keyword: "allOf", schemaProp: i }, valid13);
18347
- cxt.ok(valid13);
18346
+ const schCxt = cxt.subschema({ keyword: "allOf", schemaProp: i }, valid16);
18347
+ cxt.ok(valid16);
18348
18348
  cxt.mergeEvaluated(schCxt);
18349
18349
  });
18350
18350
  }
@@ -18378,7 +18378,7 @@ var require_if = __commonJS({
18378
18378
  const hasElse = hasSchema(it, "else");
18379
18379
  if (!hasThen && !hasElse)
18380
18380
  return;
18381
- const valid13 = gen.let("valid", true);
18381
+ const valid16 = gen.let("valid", true);
18382
18382
  const schValid = gen.name("_valid");
18383
18383
  validateIf();
18384
18384
  cxt.reset();
@@ -18391,7 +18391,7 @@ var require_if = __commonJS({
18391
18391
  } else {
18392
18392
  gen.if((0, codegen_1.not)(schValid), validateClause("else"));
18393
18393
  }
18394
- cxt.pass(valid13, () => cxt.error(true));
18394
+ cxt.pass(valid16, () => cxt.error(true));
18395
18395
  function validateIf() {
18396
18396
  const schCxt = cxt.subschema({
18397
18397
  keyword: "if",
@@ -18404,8 +18404,8 @@ var require_if = __commonJS({
18404
18404
  function validateClause(keyword, ifClause) {
18405
18405
  return () => {
18406
18406
  const schCxt = cxt.subschema({ keyword }, schValid);
18407
- gen.assign(valid13, schValid);
18408
- cxt.mergeValidEvaluated(schCxt, valid13);
18407
+ gen.assign(valid16, schValid);
18408
+ cxt.mergeValidEvaluated(schCxt, valid16);
18409
18409
  if (ifClause)
18410
18410
  gen.assign(ifClause, (0, codegen_1._)`${keyword}`);
18411
18411
  else
@@ -18680,16 +18680,16 @@ var require_discriminator = __commonJS({
18680
18680
  throw new Error("discriminator: mapping is not supported");
18681
18681
  if (!oneOf)
18682
18682
  throw new Error("discriminator: requires oneOf keyword");
18683
- const valid13 = gen.let("valid", false);
18683
+ const valid16 = gen.let("valid", false);
18684
18684
  const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
18685
18685
  gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt.error(false, { discrError: types_1.DiscrError.Tag, tag, tagName }));
18686
- cxt.ok(valid13);
18686
+ cxt.ok(valid16);
18687
18687
  function validateMapping() {
18688
18688
  const mapping = getMapping();
18689
18689
  gen.if(false);
18690
18690
  for (const tagValue in mapping) {
18691
18691
  gen.elseIf((0, codegen_1._)`${tag} === ${tagValue}`);
18692
- gen.assign(valid13, applyTagSchema(mapping[tagValue]));
18692
+ gen.assign(valid16, applyTagSchema(mapping[tagValue]));
18693
18693
  }
18694
18694
  gen.else();
18695
18695
  cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
@@ -19421,18 +19421,18 @@ var init_contract = __esm({
19421
19421
  });
19422
19422
  historyParameters = typebox_exports.Object({
19423
19423
  action: typebox_exports.Union([typebox_exports.Literal("search"), typebox_exports.Literal("read")], {
19424
- description: "search \u641C\u7D22\u6216\u5217\u4F1A\u8BDD\uFF1Bread \u8BFB\u53D6\u6307\u5B9A\u8282\u70B9\u6B63\u6587\u4E0E\u4E0A\u4E0B\u7EA7\u3002\u5404\u52A8\u4F5C\u4EC5\u8BFB\u53D6\u81EA\u8EAB\u5B57\u6BB5\uFF0C\u5176\u4F59\u5B57\u6BB5\u5FFD\u7565\u3002"
19424
+ description: "search \u641C\u7D22\u6216\u5217\u8868\uFF1Bread \u6309 id \u8BFB\u53D6\u6B63\u6587\u4E0E\u4E0A\u4E0B\u7EA7\u3002\u4EC5\u8BFB\u53D6\u5BF9\u5E94\u52A8\u4F5C\u53C2\u6570\uFF0C\u5176\u4F59\u5FFD\u7565\u3002"
19425
19425
  }),
19426
- host: nullable(typebox_exports.String({ pattern: historyIdentifierPattern.source, description: "\u53EF\u9009\u6765\u6E90\u7B5B\u9009\uFF08\u5982 pi\u3001dsh\u3001claude\u3001antigravity\uFF09\u3002" })),
19427
- dimension: nullable(typebox_exports.String({ pattern: historyIdentifierPattern.source, description: "\u4EC5 search\uFF1A\u53EF\u9009\u8303\u56F4\u7B5B\u9009\uFF08raw \u8868\u793A\u4EC5\u539F\u6587\uFF0C\u6216\u6307\u5B9A\u6458\u8981\u7EF4\u5EA6\u5982 monthly\u3001session\uFF1B\u7701\u7565\u67E5\u5168\u90E8\uFF09\u3002" })),
19428
- query: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1A\u4E0D\u533A\u5206\u5927\u5C0F\u5199\u7684\u8FDE\u7EED\u5173\u952E\u8BCD\uFF1B\u7701\u7565\u65F6\u5217\u51FA\u5404\u4F1A\u8BDD\uFF08\u6216\u6307\u5B9A\u7EF4\u5EA6\u6458\u8981\uFF09\u3002" })),
19429
- sessionId: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1A\u9650\u5B9A\u5728\u6307\u5B9A\u4F1A\u8BDD ID \u5185\u641C\u7D22\u3002" })),
19426
+ host: nullable(typebox_exports.String({ pattern: historyIdentifierPattern.source, description: "\u6765\u6E90\u5BBF\u4E3B\u7B5B\u9009\uFF08\u5982 pi\u3001dsh\u3001claude\u3001antigravity\u3001codex\u3001qoder\uFF09\uFF1B\u7701\u7565\u67E5\u5168\u90E8\u3002" })),
19427
+ dimension: nullable(typebox_exports.String({ pattern: historyIdentifierPattern.source, description: "\u4EC5 search\uFF1Araw \u4EC5\u539F\u6587\uFF0C\u6216\u6307\u5B9A\u6458\u8981\u7EF4\u5EA6\uFF08\u5982 monthly\u3001session\uFF09\uFF1B\u7701\u7565\u67E5\u5168\u90E8\u3002" })),
19428
+ query: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1A\u8FDE\u7EED\u5173\u952E\u8BCD\uFF08\u4E0D\u533A\u5206\u5927\u5C0F\u5199\uFF09\uFF1B\u7701\u7565\u5217\u4F1A\u8BDD\u6216\u6307\u5B9A\u7EF4\u5EA6\u6458\u8981\u3002" })),
19429
+ sessionId: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1A\u9650\u5B9A\u5728\u6307\u5B9A\u539F\u59CB\u4F1A\u8BDD ID \u5185\u641C\u7D22\u3002" })),
19430
19430
  from: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1AISO \u65E5\u671F\u6216\u65F6\u95F4\u4E0B\u754C\u3002" })),
19431
19431
  to: nullable(typebox_exports.String({ description: "\u4EC5 search\uFF1AISO \u65E5\u671F\u6216\u65F6\u95F4\u4E0A\u754C\u3002" })),
19432
- id: nullable(typebox_exports.String({ description: "\u4EC5 read\uFF0C\u5FC5\u586B\uFF1Asearch \u6216\u4E0A\u4E0B\u7EA7\u8FD4\u56DE\u7684\u8282\u70B9 id\u3002" })),
19433
- offset: nullable(typebox_exports.Integer({ minimum: 0, description: "search\uFF1A\u5339\u914D\u7ED3\u679C\u504F\u79FB\uFF1Bread\uFF1A\u6B63\u6587\u5B57\u7B26\u504F\u79FB\u3002\u9ED8\u8BA4 0\u3002" })),
19434
- limit: nullable(typebox_exports.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search\uFF1A\u6700\u591A\u8FD4\u56DE\u6761\u6570\uFF08\u9ED8\u8BA4 ${historyPageLimits.search.default}\uFF0C\u4E0A\u9650 ${historyPageLimits.search.max}\uFF09\uFF1Bread\uFF1A\u6B63\u6587\u5B57\u7B26\u6570\uFF08\u9ED8\u8BA4 ${historyPageLimits.read.default}\uFF09\u3002` })),
19435
- childrenOffset: nullable(typebox_exports.Integer({ minimum: 0, description: "\u4EC5 read\uFF1A\u5B50\u8282\u70B9\u5217\u8868\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\uFF1B\u7EED\u8BFB\u4F20\u4E0A\u9875 nextChildrenOffset\u3002" }))
19432
+ id: nullable(typebox_exports.String({ description: "\u4EC5 read\uFF0C\u5FC5\u586B\uFF1A\u8282\u70B9 id\uFF08\u6765\u81EA search \u6216\u4E0A\u4E0B\u7EA7\uFF09\u3002" })),
19433
+ offset: nullable(typebox_exports.Integer({ minimum: 0, description: "search \u4E3A\u7ED3\u679C\u504F\u79FB\uFF0Cread \u4E3A\u6B63\u6587\u5B57\u7B26\u504F\u79FB\uFF1B\u9ED8\u8BA4 0\u3002" })),
19434
+ limit: nullable(typebox_exports.Integer({ minimum: 1, maximum: historyPageLimits.read.max, description: `search\uFF1A\u8FD4\u56DE\u6761\u6570\uFF081\u2013${historyPageLimits.search.max}\uFF0C\u9ED8\u8BA4 ${historyPageLimits.search.default}\uFF09\uFF1Bread\uFF1A\u6B63\u6587\u5B57\u7B26\u6570\uFF08\u9ED8\u8BA4 ${historyPageLimits.read.default}\uFF09\u3002` })),
19435
+ childrenOffset: nullable(typebox_exports.Integer({ minimum: 0, description: "\u4EC5 read\uFF1A\u5B50\u8282\u70B9\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\uFF1B\u7EED\u8BFB\u4F20\u4E0A\u6B21 nextChildrenOffset\u3002" }))
19436
19436
  }, { additionalProperties: false });
19437
19437
  valid2 = schema(historyParameters);
19438
19438
  }
@@ -19509,7 +19509,7 @@ var init_command = __esm({
19509
19509
  });
19510
19510
 
19511
19511
  // src/extension/cli/index.ts
19512
- var import_semver11 = __toESM(require_semver2(), 1);
19512
+ var import_semver14 = __toESM(require_semver2(), 1);
19513
19513
  import { realpathSync as realpathSync4 } from "node:fs";
19514
19514
  import { pathToFileURL as pathToFileURL2 } from "node:url";
19515
19515
 
@@ -19968,456 +19968,965 @@ var historyCommand = {
19968
19968
  }
19969
19969
  };
19970
19970
 
19971
- // src/extension/cli/commands/mcp.ts
19971
+ // src/extension/cli/commands/install.ts
19972
19972
  init_paths();
19973
- import { spawnSync as spawnSync2 } from "node:child_process";
19974
- import { existsSync as existsSync2 } from "node:fs";
19975
- import { join as join17 } from "node:path";
19976
19973
 
19977
- // src/integrations/hosts/plugin-registry.ts
19974
+ // src/integrations/installation/installers/registry.ts
19978
19975
  init_validation();
19979
19976
 
19980
- // src/integrations/hosts/antigravity/adapter.ts
19977
+ // src/integrations/installation/installers/antigravity.ts
19978
+ var import_semver2 = __toESM(require_semver2(), 1);
19981
19979
  init_json();
19982
- init_paths();
19983
- init_validation();
19984
- import { readFile as readFile3, realpath as realpath3, stat as stat3 } from "node:fs/promises";
19985
- import { dirname as dirname6, isAbsolute as isAbsolute3, join as join15, relative as relative3, resolve as resolve8, sep } from "node:path";
19986
- var supportedEvents = ["SessionStart", "PreToolUse", "Stop"];
19987
- function cleanUserRequest(content) {
19988
- const match = content.match(/<USER_REQUEST>\s*([\s\S]*?)\s*<\/USER_REQUEST>/);
19989
- return (match ? match[1] : content).trim();
19990
- }
19991
- function projectAntigravityTranscript(sessionId, content, terminationReason) {
19992
- const exchanges = [];
19993
- const lines = content.split(/\r?\n/);
19994
- let users = [];
19995
- let answer;
19996
- const finish = (completed2) => {
19997
- if (!users.length) return;
19998
- const entryIds = [...users.map((u) => u.id), ...answer ? [answer.id] : []];
19999
- const from = users[0].time;
20000
- const to = answer?.time ?? users.at(-1).time;
20001
- const text = users.map((u) => "\u7528\u6237\uFF1A\n" + u.text).join("\n\n") + (answer ? "\n\n\u52A9\u624B\uFF1A\n" + answer.text : "");
20002
- exchanges.push({ entryIds, from, to, completed: completed2, text });
20003
- users = [];
20004
- answer = void 0;
20005
- };
20006
- for (const line of lines) {
20007
- const trimmed = line.trim();
20008
- if (!trimmed) continue;
20009
- let entry;
20010
- try {
20011
- entry = JSON.parse(trimmed);
20012
- } catch {
20013
- continue;
20014
- }
20015
- if (!object(entry) || typeof entry.type !== "string") continue;
20016
- const stepIndex = typeof entry.step_index === "number" ? entry.step_index : exchanges.length;
20017
- const time = typeof entry.created_at === "string" && entry.created_at ? entry.created_at : (/* @__PURE__ */ new Date()).toISOString();
20018
- if (entry.type === "USER_INPUT" && typeof entry.content === "string") {
20019
- if (answer) finish(true);
20020
- const cleaned = cleanUserRequest(entry.content);
20021
- if (cleaned) users.push({ id: `agy:${stepIndex}`, text: cleaned, time });
20022
- } else if (entry.type === "PLANNER_RESPONSE" && users.length) {
20023
- const hasToolCalls = Array.isArray(entry.tool_calls) && entry.tool_calls.length > 0;
20024
- const text = typeof entry.content === "string" ? entry.content.trim() : "";
20025
- if (!hasToolCalls && text) {
20026
- answer = { id: `agy:${stepIndex}`, text, time };
20027
- }
20028
- }
20029
- }
20030
- const completed = Boolean(answer) && (!terminationReason || terminationReason === "NO_TOOL_CALL");
20031
- finish(completed);
20032
- return { sessionId, name: "", branches: exchanges.length ? [exchanges] : [] };
20033
- }
20034
- async function readAntigravityTranscript(transcriptPath) {
20035
- const fullPath = join15(dirname6(transcriptPath), "transcript_full.jsonl");
20036
- for (const path of [fullPath, transcriptPath]) {
20037
- try {
20038
- return await readFile3(path, "utf8");
20039
- } catch (error) {
20040
- if (error.code !== "ENOENT") throw error;
20041
- }
20042
- }
20043
- return void 0;
20044
- }
20045
- function workspaceFromPayload(cwd, payload) {
20046
- if (object(payload) && Array.isArray(payload.workspacePaths)) {
20047
- const first = payload.workspacePaths.find((value) => typeof value === "string" && value.length > 0);
20048
- if (typeof first === "string") return first;
19980
+ import { readFile as readFile3 } from "node:fs/promises";
19981
+ import { join as join15 } from "node:path";
19982
+ async function readManifestVersion(path) {
19983
+ try {
19984
+ const data = JSON.parse(await readFile3(path, "utf8"));
19985
+ return object(data) && typeof data.version === "string" && (0, import_semver2.valid)(data.version) ? data.version : void 0;
19986
+ } catch (error) {
19987
+ if (error.code === "ENOENT") return void 0;
19988
+ throw error;
20049
19989
  }
20050
- return cwd;
20051
- }
20052
- function skillFromReadPath(targetPath, pluginRoot = process.env.PLUGIN_ROOT || resolve8(resourceRoot, "..")) {
20053
- const skillsRoot = resolve8(pluginRoot, "skills");
20054
- const rel = relative3(skillsRoot, resolve8(targetPath));
20055
- if (!rel || rel.startsWith("..") || isAbsolute3(rel)) return void 0;
20056
- const skill = rel.split(sep)[0];
20057
- if (!skill || skill === "pbot") return void 0;
20058
- return skill;
20059
- }
20060
- function isPreToolUse(payload) {
20061
- return object(payload) && payload.hookEventName === "PreToolUse";
20062
- }
20063
- async function antigravityWorkspaceRoot(cwd, payload) {
20064
- const directory = workspaceFromPayload(cwd, payload);
20065
- requireThat(isAbsolute3(directory), "Antigravity \u5DE5\u4F5C\u533A\u9700\u8981\u7EDD\u5BF9\u8DEF\u5F84\u3002");
20066
- const root = await realpath3(directory);
20067
- requireThat((await stat3(root)).isDirectory(), "Antigravity \u5DE5\u4F5C\u533A\u9700\u8981\u76EE\u5F55\u3002");
20068
- return root;
20069
19990
  }
20070
- var antigravityAdapter = {
19991
+ var antigravityInstaller = {
20071
19992
  host: "antigravity",
20072
- nativeRootAgents: true,
20073
- nativeWorkspaceSkills: true,
20074
- coordinatorPrompt: "plugin-coordinator.md",
20075
- initCommandHint: "/pbot init",
20076
- usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/plugin.js antigravity init|status",
20077
- resolveRoot(cwd, rawPayload) {
20078
- return antigravityWorkspaceRoot(cwd, rawPayload);
20079
- },
20080
- parseEvent(value) {
20081
- requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook \u8F93\u5165\u65E0\u6548\u3002");
20082
- const event = value.hookEventName;
20083
- requireThat(supportedEvents.includes(event), "Antigravity hook \u4E8B\u4EF6\u672A\u652F\u6301\u3002");
20084
- const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
20085
- requireThat(cwd, "Antigravity hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20086
- if (event === "SessionStart") {
20087
- return { kind: "inject-context", role: "coordinator", isSessionStart: true, cwd, raw: value };
20088
- }
20089
- if (event === "Stop") {
20090
- return { kind: "record-history", cwd, raw: value };
20091
- }
20092
- if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
20093
- return { kind: "ignore" };
20094
- }
20095
- const { name, args } = value.toolCall;
20096
- if (name === "read_file" && typeof args.Path === "string") {
20097
- const skill = skillFromReadPath(args.Path);
20098
- if (skill) return { kind: "check-skill", skill, cwd, raw: value };
19993
+ async install(context) {
19994
+ const agy = context.env.PBOT_AGY_COMMAND || await context.findExecutable("agy");
19995
+ if (!agy) {
19996
+ return {
19997
+ host: this.host,
19998
+ state: context.explicit ? "failed" : "skipped",
19999
+ scope: "user",
20000
+ detail: "\u672A\u627E\u5230 Antigravity CLI\uFF08agy\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 agy \u540E\u91CD\u8BD5\u3002"
20001
+ };
20099
20002
  }
20100
- return { kind: "ignore" };
20101
- },
20102
- async extractHistory(event) {
20103
- if (event.kind !== "record-history" || !object(event.raw)) return void 0;
20104
- const sessionId = typeof event.raw.conversationId === "string" ? event.raw.conversationId.trim() : "";
20105
- if (!sessionId) return void 0;
20106
- const terminationReason = typeof event.raw.terminationReason === "string" ? event.raw.terminationReason : void 0;
20107
- const transcriptPath = typeof event.raw.transcriptPath === "string" ? event.raw.transcriptPath.trim() : "";
20108
- if (transcriptPath) {
20109
- const content = await readAntigravityTranscript(transcriptPath);
20110
- if (content) {
20111
- const session = projectAntigravityTranscript(sessionId, content, terminationReason);
20112
- if (session.branches.length) return { kind: "session", session };
20113
- }
20003
+ const pluginDir = join15(context.packageRoot, "lib", "antigravity-plugin");
20004
+ const bundledVersion = await readManifestVersion(join15(pluginDir, "plugin.json"));
20005
+ if (!bundledVersion) {
20006
+ return {
20007
+ host: this.host,
20008
+ state: "failed",
20009
+ scope: "user",
20010
+ detail: `\u7F3A\u5C11 Antigravity \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${pluginDir}\u3002\u8BF7\u5148\u8FD0\u884C npm run build\u3002`
20011
+ };
20114
20012
  }
20115
- const lastUserInput = typeof event.raw.lastUserInput === "string" ? event.raw.lastUserInput.trim() : "";
20116
- if (lastUserInput) return { kind: "input", sessionId, text: lastUserInput };
20117
- return void 0;
20118
- },
20119
- formatPass(payload) {
20120
- return isPreToolUse(payload) ? { decision: "allow" } : {};
20121
- },
20122
- formatContext(_event, context) {
20013
+ await context.run(agy, ["plugin", "install", pluginDir], context.workspace);
20123
20014
  return {
20124
- injectSteps: [
20125
- { systemMessage: { systemMessage: context.text } }
20126
- ]
20015
+ host: this.host,
20016
+ state: "installed",
20017
+ version: bundledVersion,
20018
+ scope: "user",
20019
+ detail: `\u5DF2\u901A\u8FC7 agy plugin install \u5B89\u88C5 Antigravity \u63D2\u4EF6\uFF08${bundledVersion}\uFF09\u3002`,
20020
+ nextStep: "\u5728 Antigravity \u76EE\u6807\u5DE5\u4F5C\u533A\u6267\u884C /pbot init \u542F\u7528 Personal Bot\u3002"
20127
20021
  };
20128
- },
20129
- formatDeny(_event, reason) {
20130
- return { decision: "deny", reason };
20131
20022
  }
20132
20023
  };
20133
20024
 
20134
- // src/integrations/hosts/claude/adapter.ts
20135
- init_json();
20136
- init_validation();
20025
+ // src/integrations/installation/installers/claude.ts
20026
+ var claudeMarketplace = "realqiyan/personal-bot";
20027
+ var claudeInstaller = {
20028
+ host: "claude",
20029
+ async install(context) {
20030
+ const claude = context.env.PBOT_CLAUDE_COMMAND || await context.findExecutable("claude");
20031
+ if (!claude) {
20032
+ return {
20033
+ host: this.host,
20034
+ state: context.explicit ? "failed" : "skipped",
20035
+ scope: "user",
20036
+ detail: "\u672A\u627E\u5230 Claude Code CLI\uFF08claude\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 Claude Code \u540E\u91CD\u8BD5\u3002"
20037
+ };
20038
+ }
20039
+ await context.run(
20040
+ claude,
20041
+ ["plugin", "install", "personal-bot", "--marketplace", claudeMarketplace, "--yes"],
20042
+ context.workspace
20043
+ );
20044
+ return {
20045
+ host: this.host,
20046
+ state: "installed",
20047
+ scope: "user",
20048
+ detail: `\u5DF2\u901A\u8FC7 claude plugin install \u4ECE ${claudeMarketplace} \u5B89\u88C5 personal-bot\u3002`,
20049
+ nextStep: "\u5728 Claude Code \u76EE\u6807\u5DE5\u4F5C\u533A\u6267\u884C /personal-bot:pbot init \u542F\u7528 Personal Bot\u3002"
20050
+ };
20051
+ }
20052
+ };
20137
20053
 
20138
- // src/integrations/hosts/prompt-hooks.ts
20054
+ // src/integrations/installation/installers/codex.ts
20055
+ var import_semver3 = __toESM(require_semver2(), 1);
20139
20056
  init_json();
20140
- init_validation();
20141
- import { realpath as realpath4, stat as stat4 } from "node:fs/promises";
20142
- import { isAbsolute as isAbsolute4 } from "node:path";
20143
- async function pluginWorkspaceRoot(directory) {
20144
- requireThat(isAbsolute4(directory), "\u63D2\u4EF6\u5DE5\u4F5C\u533A\u9700\u8981\u7EDD\u5BF9\u8DEF\u5F84\u3002");
20145
- const root = await realpath4(directory);
20146
- requireThat((await stat4(root)).isDirectory(), "\u63D2\u4EF6\u5DE5\u4F5C\u533A\u9700\u8981\u76EE\u5F55\u3002");
20147
- return root;
20148
- }
20149
- function parsePromptEvent(value) {
20150
- requireThat(object(value), "\u63D2\u4EF6 hook \u8F93\u5165\u65E0\u6548\u3002");
20151
- const name = value.hook_event_name;
20152
- if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart") return { kind: "ignore" };
20153
- if (typeof value.agent_id === "string") return { kind: "ignore" };
20154
- requireThat(typeof value.cwd === "string", "\u63D2\u4EF6 hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20155
- if (name === "Stop") return { kind: "record-history", cwd: value.cwd, raw: value };
20156
- if (name === "SessionStart") {
20157
- if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
20158
- return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
20057
+ import { readFile as readFile4 } from "node:fs/promises";
20058
+ import { join as join16 } from "node:path";
20059
+ async function readManifestVersion2(path) {
20060
+ try {
20061
+ const data = JSON.parse(await readFile4(path, "utf8"));
20062
+ return object(data) && typeof data.version === "string" && (0, import_semver3.valid)(data.version) ? data.version : void 0;
20063
+ } catch (error) {
20064
+ if (error.code === "ENOENT") return void 0;
20065
+ throw error;
20159
20066
  }
20160
- return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
20161
20067
  }
20162
- var promptHooks = {
20163
- async extractHistory(event) {
20164
- if (!object(event.raw)) return void 0;
20165
- const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
20166
- if (!sessionId) return void 0;
20167
- const turnId = typeof event.raw.turn_id === "string" ? event.raw.turn_id.trim() : "";
20168
- const identity2 = turnId ? { sessionId, turnId } : { sessionId };
20169
- if (event.raw.hook_event_name === "UserPromptSubmit") {
20170
- const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
20171
- if (!text && !turnId) return void 0;
20172
- return { kind: "input", ...identity2, text };
20068
+ var codexInstaller = {
20069
+ host: "codex",
20070
+ async install(context) {
20071
+ const codex = context.env.PBOT_CODEX_COMMAND || await context.findExecutable("codex");
20072
+ if (!codex) {
20073
+ return {
20074
+ host: this.host,
20075
+ state: context.explicit ? "failed" : "skipped",
20076
+ scope: "user",
20077
+ detail: "\u672A\u627E\u5230 Codex CLI\uFF08codex\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 Codex CLI \u540E\u91CD\u8BD5\u3002"
20078
+ };
20173
20079
  }
20174
- if (event.raw.hook_event_name === "Stop") {
20175
- const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
20176
- if (!assistantText) return void 0;
20080
+ const marketplaceDir = join16(context.packageRoot, "lib", "codex-marketplace");
20081
+ const bundledVersion = await readManifestVersion2(
20082
+ join16(marketplaceDir, "plugins", "personal-bot", ".codex-plugin", "plugin.json")
20083
+ );
20084
+ if (!bundledVersion) {
20177
20085
  return {
20178
- kind: "answer",
20179
- ...identity2,
20180
- assistantText,
20181
- completed: true,
20182
- ...event.raw.stop_hook_active === true ? { isContinuation: true } : {}
20086
+ host: this.host,
20087
+ state: "failed",
20088
+ scope: "user",
20089
+ detail: `\u7F3A\u5C11 Codex \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${marketplaceDir}\u3002\u8BF7\u5148\u8FD0\u884C npm run build\u3002`
20183
20090
  };
20184
20091
  }
20185
- return void 0;
20186
- },
20187
- formatPass() {
20188
- return {};
20189
- },
20190
- formatContext(event, context) {
20191
- const raw = event.raw;
20092
+ try {
20093
+ await context.run(codex, ["plugin", "marketplace", "add", marketplaceDir], context.workspace);
20094
+ } catch {
20095
+ }
20096
+ await context.run(codex, ["plugin", "add", "personal-bot@pbot-local"], context.workspace);
20192
20097
  return {
20193
- hookSpecificOutput: {
20194
- hookEventName: raw.hook_event_name,
20195
- additionalContext: context.text
20196
- }
20098
+ host: this.host,
20099
+ state: "installed",
20100
+ version: bundledVersion,
20101
+ scope: "user",
20102
+ detail: `\u5DF2\u901A\u8FC7 codex plugin add \u5B89\u88C5 Codex \u63D2\u4EF6\uFF08${bundledVersion}\uFF09\u3002`,
20103
+ nextStep: "\u5728 Codex \u7684 /hooks \u4E2D\u6838\u5BF9\u5E76\u4FE1\u4EFB Personal Bot hooks\uFF0C\u7136\u540E\u6267\u884C pbot plugin codex init \u542F\u7528\u5DE5\u4F5C\u533A\u3002"
20197
20104
  };
20198
- },
20199
- formatDeny(event, reason) {
20200
- const raw = event.raw;
20201
- return raw.hook_event_name === "UserPromptExpansion" ? { decision: "block", reason } : { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
20202
20105
  }
20203
20106
  };
20204
20107
 
20205
- // src/integrations/hosts/claude/adapter.ts
20206
- var supportedEvents2 = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
20207
- var boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
20208
- async function claudeWorkspaceRoot(cwd, projectDirectory = boundWorkspaceRoot()) {
20209
- return pluginWorkspaceRoot(projectDirectory || cwd);
20210
- }
20211
- var claudeAdapter = {
20212
- host: "claude",
20213
- nativeRootAgents: false,
20214
- nativeWorkspaceSkills: false,
20215
- coordinatorPrompt: "plugin-coordinator.md",
20216
- initCommandHint: "/personal-bot:pbot init",
20217
- usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/claude.js init|status",
20218
- boundWorkspaceRoot,
20219
- resolveRoot(cwd) {
20220
- return claudeWorkspaceRoot(cwd);
20221
- },
20222
- parseEvent(value) {
20223
- requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook \u8F93\u5165\u65E0\u6548\u3002");
20224
- const event = value.hook_event_name;
20225
- requireThat(supportedEvents2.includes(event), "Claude hook \u4E8B\u4EF6\u672A\u652F\u6301\u3002");
20226
- if (event === "PreToolUse" || event === "UserPromptExpansion") {
20227
- const skill = event === "UserPromptExpansion" ? value.expansion_type === "slash_command" ? value.command_name : void 0 : value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : void 0;
20228
- if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot") return { kind: "ignore" };
20229
- requireThat(typeof value.cwd === "string", "Claude hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20230
- return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
20108
+ // src/integrations/installation/installers/dsh.ts
20109
+ var dshInstaller = {
20110
+ host: "dsh",
20111
+ async install(context) {
20112
+ const profile = context.options.dshProfile || "pbot";
20113
+ const dsh = context.env.PBOT_DSH_COMMAND || await context.findExecutable("dsh");
20114
+ if (!dsh) {
20115
+ return {
20116
+ host: this.host,
20117
+ state: context.explicit ? "failed" : "skipped",
20118
+ scope: `profile:${profile}`,
20119
+ detail: "\u672A\u627E\u5230 dsh CLI\uFF08dsh\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 @deepseek-ai/dsh \u540E\u91CD\u8BD5\u3002"
20120
+ };
20231
20121
  }
20232
- return parsePromptEvent(value);
20233
- },
20234
- ...promptHooks
20122
+ await context.run(dsh, ["plugin", "--profile", profile, "add", "personal-bot@latest"], context.workspace);
20123
+ return {
20124
+ host: this.host,
20125
+ state: "installed",
20126
+ scope: `profile:${profile}`,
20127
+ detail: `\u5DF2\u901A\u8FC7 dsh plugin --profile ${profile} add \u5B89\u88C5 personal-bot\u3002`,
20128
+ nextStep: `\u542F\u52A8 dsh --profile ${profile} \u5E76\u5728\u5DE5\u4F5C\u533A\u6267\u884C /pbot init \u542F\u7528 Personal Bot\u3002`
20129
+ };
20130
+ }
20235
20131
  };
20236
20132
 
20237
- // src/integrations/hosts/codex/adapter.ts
20238
- var codexAdapter = {
20239
- host: "codex",
20240
- nativeRootAgents: true,
20241
- nativeWorkspaceSkills: true,
20242
- indexBundledSkills: true,
20243
- initCommandHint: "pbot plugin codex init",
20244
- usage: "\u7528\u6CD5\uFF1Apbot plugin codex init|status",
20245
- resolveRoot(cwd) {
20246
- return pluginWorkspaceRoot(cwd);
20247
- },
20248
- parseEvent: parsePromptEvent,
20249
- ...promptHooks
20133
+ // src/integrations/installation/installers/pi.ts
20134
+ var piInstaller = {
20135
+ host: "pi",
20136
+ async install(context) {
20137
+ const pi = context.env.PBOT_PI_COMMAND || await context.findExecutable("pi");
20138
+ if (!pi) {
20139
+ return {
20140
+ host: this.host,
20141
+ state: context.explicit ? "failed" : "skipped",
20142
+ scope: "local",
20143
+ detail: "\u672A\u627E\u5230 Pi CLI\uFF08pi\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 Pi \u540E\u91CD\u8BD5\u3002"
20144
+ };
20145
+ }
20146
+ await context.run(pi, ["install", "--local", "npm:personal-bot"], context.workspace);
20147
+ return {
20148
+ host: this.host,
20149
+ state: "installed",
20150
+ version: packageVersion,
20151
+ scope: "local",
20152
+ detail: "\u5DF2\u901A\u8FC7 pi install --local \u5B89\u88C5\u5DE5\u4F5C\u533A personal-bot\u3002",
20153
+ nextStep: "\u542F\u52A8 Pi \u5E76\u5728\u5DE5\u4F5C\u533A\u6267\u884C /pbot init \u542F\u7528 Personal Bot\u3002"
20154
+ };
20155
+ }
20250
20156
  };
20251
20157
 
20252
- // src/integrations/hosts/qoder/adapter.ts
20253
- var boundWorkspaceRoot2 = () => process.env.QODER_PROJECT_DIR || process.env.PBOT_WORKSPACE_ROOT;
20254
- var qoderAdapter = {
20158
+ // src/integrations/installation/installers/qoder.ts
20159
+ var import_semver4 = __toESM(require_semver2(), 1);
20160
+ init_json();
20161
+ import { readFile as readFile5 } from "node:fs/promises";
20162
+ import { join as join17 } from "node:path";
20163
+ async function readManifestVersion3(path) {
20164
+ try {
20165
+ const data = JSON.parse(await readFile5(path, "utf8"));
20166
+ return object(data) && typeof data.version === "string" && (0, import_semver4.valid)(data.version) ? data.version : void 0;
20167
+ } catch (error) {
20168
+ if (error.code === "ENOENT") return void 0;
20169
+ throw error;
20170
+ }
20171
+ }
20172
+ var qoderInstaller = {
20255
20173
  host: "qoder",
20256
- nativeRootAgents: true,
20257
- nativeWorkspaceSkills: true,
20258
- indexBundledSkills: true,
20259
- initCommandHint: "pbot plugin qoder init",
20260
- usage: "\u7528\u6CD5\uFF1Apbot plugin qoder init|status",
20261
- boundWorkspaceRoot: boundWorkspaceRoot2,
20262
- resolveRoot(cwd) {
20263
- return pluginWorkspaceRoot(boundWorkspaceRoot2() || cwd);
20264
- },
20265
- parseEvent: parsePromptEvent,
20266
- ...promptHooks
20174
+ async install(context) {
20175
+ const qodercli = context.env.PBOT_QODER_COMMAND || await context.findExecutable("qodercli");
20176
+ if (!qodercli) {
20177
+ return {
20178
+ host: this.host,
20179
+ state: context.explicit ? "failed" : "skipped",
20180
+ scope: "user",
20181
+ detail: "\u672A\u627E\u5230 Qoder CLI\uFF08qodercli\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 Qoder CLI \u540E\u91CD\u8BD5\u3002"
20182
+ };
20183
+ }
20184
+ const pluginDir = join17(context.packageRoot, "lib", "qoder-plugin");
20185
+ const bundledVersion = await readManifestVersion3(join17(pluginDir, ".qoder-plugin", "plugin.json"));
20186
+ if (!bundledVersion) {
20187
+ return {
20188
+ host: this.host,
20189
+ state: "failed",
20190
+ scope: "user",
20191
+ detail: `\u7F3A\u5C11 Qoder CLI \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${pluginDir}\u3002\u8BF7\u5148\u8FD0\u884C npm run build\u3002`
20192
+ };
20193
+ }
20194
+ await context.run(qodercli, ["plugin", "install", pluginDir], context.workspace);
20195
+ return {
20196
+ host: this.host,
20197
+ state: "installed",
20198
+ version: bundledVersion,
20199
+ scope: "user",
20200
+ detail: `\u5DF2\u901A\u8FC7 qodercli plugin install \u5B89\u88C5 Qoder CLI \u63D2\u4EF6\uFF08${bundledVersion}\uFF09\u3002`,
20201
+ nextStep: "\u5728\u76EE\u6807\u5DE5\u4F5C\u533A\u6267\u884C pbot plugin qoder init \u542F\u7528 Personal Bot\u3002"
20202
+ };
20203
+ }
20267
20204
  };
20268
20205
 
20269
- // src/integrations/hosts/plugin-registry.ts
20270
- var PluginHostRegistry = class {
20271
- #adapters = /* @__PURE__ */ new Map();
20206
+ // src/integrations/installation/installers/registry.ts
20207
+ var HostInstallerRegistry = class {
20208
+ #installers = /* @__PURE__ */ new Map();
20272
20209
  constructor(initial = []) {
20273
- for (const adapter of initial) this.register(adapter);
20210
+ for (const installer of initial) this.register(installer);
20274
20211
  }
20275
- register(adapter) {
20276
- requireThat(typeof adapter.host === "string" && adapter.host.length > 0, "\u63D2\u4EF6\u5BBF\u4E3B\u6807\u8BC6\u65E0\u6548\u3002");
20277
- this.#adapters.set(adapter.host, adapter);
20212
+ register(installer) {
20213
+ requireThat(typeof installer.host === "string" && installer.host.length > 0, "\u5BBF\u4E3B\u5B89\u88C5\u9002\u914D\u5668\u6807\u8BC6\u65E0\u6548\u3002");
20214
+ this.#installers.set(installer.host, installer);
20278
20215
  return this;
20279
20216
  }
20280
20217
  unregister(host) {
20281
- return this.#adapters.delete(host);
20218
+ return this.#installers.delete(host);
20282
20219
  }
20283
20220
  get(host) {
20284
- return this.#adapters.get(host);
20285
- }
20286
- require(host) {
20287
- const adapter = this.#adapters.get(host);
20288
- requireThat(adapter, `\u672A\u6CE8\u518C\u7684\u63D2\u4EF6\u5BBF\u4E3B\uFF1A${host}\u3002\u53EF\u7528\u5BBF\u4E3B\uFF1A${this.list().join(", ")}`);
20289
- return adapter;
20221
+ return this.#installers.get(host);
20290
20222
  }
20291
20223
  list() {
20292
- return [...this.#adapters.keys()];
20224
+ return [...this.#installers.keys()];
20293
20225
  }
20294
20226
  };
20295
- var pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter, codexAdapter, qoderAdapter]);
20296
- var getPluginHost = (host) => pluginHosts.get(host);
20297
- var listPluginHosts = () => pluginHosts.list();
20298
- function pluginMcpWorkspaceRoot() {
20299
- const adapter = process.env.PBOT_HOST ? pluginHosts.get(process.env.PBOT_HOST) : claudeAdapter;
20300
- return adapter?.boundWorkspaceRoot?.() || process.env.PBOT_WORKSPACE_ROOT;
20301
- }
20227
+ var hostInstallers = new HostInstallerRegistry([
20228
+ piInstaller,
20229
+ dshInstaller,
20230
+ claudeInstaller,
20231
+ antigravityInstaller,
20232
+ codexInstaller,
20233
+ qoderInstaller
20234
+ ]);
20235
+ var getHostInstaller = (host) => hostInstallers.get(host);
20236
+ var listHostInstallers = () => hostInstallers.list();
20302
20237
 
20303
- // src/services/workspace/workspace-mcp.ts
20304
- init_json();
20305
- init_validation();
20306
- init_atomic_json();
20307
- import { mkdir as mkdir3, readFile as readFile4 } from "node:fs/promises";
20308
- import { dirname as dirname7, join as join16, resolve as resolve9 } from "node:path";
20309
- var serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
20310
- var reservedServerNames = /* @__PURE__ */ new Set(["pbot"]);
20311
- var stdioKeys = /* @__PURE__ */ new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
20312
- var httpKeys = /* @__PURE__ */ new Set(["url", "headers", "description", "timeout", "enabled"]);
20313
- var envPattern = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
20314
- function validateStringRecord(value, label) {
20315
- requireThat(object(value), `${label} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6620\u5C04\u3002`);
20316
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
20317
- requireThat(
20318
- key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"),
20319
- `${label}.${key} \u5FC5\u987B\u662F\u975E\u7A7A\u952E\u4E0E\u65E0\u7A7A\u5B57\u8282\u5B57\u7B26\u4E32\u503C\u3002`
20320
- );
20321
- return [key, entry];
20322
- }));
20323
- }
20324
- function validateWorkspaceMcpServer(name, value) {
20325
- requireThat(serverNamePattern.test(name), `MCP \u670D\u52A1\u540D\u65E0\u6548\uFF1A${name}\uFF08\u9700\u5339\u914D [A-Za-z0-9][A-Za-z0-9_-]{0,31}\uFF09\u3002`);
20326
- requireThat(!reservedServerNames.has(name.toLowerCase()), `MCP \u670D\u52A1\u540D "${name}" \u4E3A Personal Bot \u4FDD\u7559\u540D\u79F0\u3002`);
20327
- requireThat(object(value), `MCP \u670D\u52A1 "${name}" \u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002`);
20328
- const hasCommand = value.command !== void 0;
20329
- const hasUrl = value.url !== void 0;
20330
- requireThat(hasCommand !== hasUrl, `MCP \u670D\u52A1 "${name}" \u5FC5\u987B\u4E14\u53EA\u80FD\u58F0\u660E command\uFF08stdio\uFF09\u6216 url\uFF08Streamable HTTP\uFF09\u4E4B\u4E00\u3002`);
20331
- const allowed = hasCommand ? stdioKeys : httpKeys;
20332
- const unknown = Object.keys(value).filter((key) => !allowed.has(key));
20333
- requireThat(unknown.length === 0, `MCP \u670D\u52A1 "${name}" \u5305\u542B\u672A\u77E5\u5B57\u6BB5\uFF1A${unknown.join(", ")}\u3002`);
20334
- if (value.description !== void 0) {
20335
- requireThat(
20336
- typeof value.description === "string" && !value.description.includes("\0"),
20337
- `MCP \u670D\u52A1 "${name}" \u7684 description \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002`
20338
- );
20339
- }
20340
- if (value.timeout !== void 0) {
20341
- requireThat(
20342
- typeof value.timeout === "number" && Number.isInteger(value.timeout) && value.timeout >= 1 && value.timeout <= 3600,
20343
- `MCP \u670D\u52A1 "${name}" \u7684 timeout \u5FC5\u987B\u662F 1\u20133600 \u7684\u6574\u6570\u79D2\u3002`
20344
- );
20345
- }
20346
- if (value.enabled !== void 0) {
20347
- requireThat(typeof value.enabled === "boolean", `MCP \u670D\u52A1 "${name}" \u7684 enabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002`);
20348
- }
20349
- const base = {
20350
- ...value.description !== void 0 ? { description: value.description } : {},
20351
- ...value.timeout !== void 0 ? { timeout: value.timeout } : {},
20352
- ...value.enabled !== void 0 ? { enabled: value.enabled } : {}
20353
- };
20354
- if (hasCommand) {
20355
- requireThat(
20356
- typeof value.command === "string" && value.command.trim().length > 0 && !value.command.includes("\0"),
20357
- `MCP \u670D\u52A1 "${name}" \u7684 command \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20358
- );
20359
- let args;
20360
- if (value.args !== void 0) {
20361
- requireThat(
20362
- Array.isArray(value.args) && value.args.every((item) => typeof item === "string" && !item.includes("\0")),
20363
- `MCP \u670D\u52A1 "${name}" \u7684 args \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4\u3002`
20364
- );
20365
- args = [...value.args];
20366
- }
20367
- const env = value.env !== void 0 ? validateStringRecord(value.env, `MCP \u670D\u52A1 "${name}" \u7684 env`) : void 0;
20368
- let cwd;
20369
- if (value.cwd !== void 0) {
20370
- requireThat(
20371
- typeof value.cwd === "string" && value.cwd.trim().length > 0 && !value.cwd.includes("\0"),
20372
- `MCP \u670D\u52A1 "${name}" \u7684 cwd \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20373
- );
20374
- cwd = value.cwd;
20238
+ // src/integrations/installation/processes.ts
20239
+ import { spawn as spawn2 } from "node:child_process";
20240
+ import { access, realpath as realpath3, stat as stat3 } from "node:fs/promises";
20241
+ import { constants as constants3 } from "node:fs";
20242
+ import { delimiter as delimiter2, isAbsolute as isAbsolute3, resolve as resolve8 } from "node:path";
20243
+ async function findExecutable(name, env = process.env) {
20244
+ const directories2 = (env.PATH ?? "").split(delimiter2).filter(Boolean);
20245
+ for (const directory of directories2) {
20246
+ const path = resolve8(directory, name);
20247
+ if (name === "pi" && path.split(/[\\/]/).includes("_npx")) continue;
20248
+ try {
20249
+ await access(path, constants3.X_OK);
20250
+ if (!(await stat3(path)).isFile()) continue;
20251
+ const target = await realpath3(path);
20252
+ if (name === "pi" && target.split(/[\\/]/).includes("_npx")) continue;
20253
+ return path;
20254
+ } catch (error) {
20255
+ if (!["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? "")) throw error;
20375
20256
  }
20376
- const entry2 = {
20377
- command: value.command,
20378
- ...args ? { args } : {},
20379
- ...env ? { env } : {},
20380
- ...cwd ? { cwd } : {},
20381
- ...base
20382
- };
20383
- return entry2;
20384
20257
  }
20385
- requireThat(
20386
- typeof value.url === "string" && value.url.trim().length > 0 && !value.url.includes("\0"),
20387
- `MCP \u670D\u52A1 "${name}" \u7684 url \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20388
- );
20389
- const rawUrl = value.url.trim();
20390
- requireThat(
20391
- /^https?:\/\/.+/.test(rawUrl) || envPattern.test(rawUrl),
20392
- `MCP \u670D\u52A1 "${name}" \u7684 url \u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934\u3002`
20393
- );
20394
- envPattern.lastIndex = 0;
20395
- const headers = value.headers !== void 0 ? validateStringRecord(value.headers, `MCP \u670D\u52A1 "${name}" \u7684 headers`) : void 0;
20396
- const entry = {
20397
- url: rawUrl,
20398
- ...headers ? { headers } : {},
20399
- ...base
20400
- };
20401
- return entry;
20258
+ return void 0;
20402
20259
  }
20403
- function validateMcpFile(value) {
20404
- requireThat(object(value), "\u5DE5\u4F5C\u533A MCP \u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002");
20405
- const rawServers = value.mcpServers;
20406
- requireThat(rawServers !== void 0 && object(rawServers), "\u5DE5\u4F5C\u533A MCP \u914D\u7F6E\u9700\u8981 mcpServers \u5BF9\u8C61\u3002");
20407
- const servers = {};
20408
- for (const [name, entry] of Object.entries(rawServers)) {
20409
- servers[name] = validateWorkspaceMcpServer(name, entry);
20260
+ var SetupProcesses = class {
20261
+ constructor(signal, env = process.env) {
20262
+ this.signal = signal;
20263
+ this.env = env;
20264
+ }
20265
+ async run(command, args, cwd, options = {}) {
20266
+ this.signal.throwIfAborted();
20267
+ if (!isAbsolute3(cwd)) throw new Error("\u8FDB\u7A0B\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84\u3002");
20268
+ const interactive = options.interactive ?? false;
20269
+ const timeoutMs = options.timeoutMs ?? (interactive ? 15 * 6e4 : 6e4);
20270
+ return new Promise((resolveResult, reject) => {
20271
+ const child = spawn2(command, args, {
20272
+ cwd,
20273
+ env: this.env,
20274
+ shell: false,
20275
+ detached: !interactive,
20276
+ stdio: interactive ? "inherit" : ["pipe", "pipe", "pipe"]
20277
+ });
20278
+ const stdout = [], stderr = [];
20279
+ let bytes = 0, failure, escalation;
20280
+ const kill = (signal) => {
20281
+ if (!child.pid) return;
20282
+ try {
20283
+ if (interactive) child.kill(signal);
20284
+ else process.kill(-child.pid, signal);
20285
+ } catch {
20286
+ }
20287
+ };
20288
+ const stop = (reason) => {
20289
+ if (failure) return;
20290
+ failure = reason;
20291
+ kill("SIGTERM");
20292
+ escalation = setTimeout(() => kill("SIGKILL"), 2e3);
20293
+ };
20294
+ const cancel = () => stop(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
20295
+ const timer = timeoutMs > 0 ? setTimeout(() => stop(new Error(`\u547D\u4EE4\u8D85\u65F6\uFF1A${command}`)), timeoutMs) : void 0;
20296
+ this.signal.addEventListener("abort", cancel, { once: true });
20297
+ const collect = (chunks) => (chunk) => {
20298
+ bytes += chunk.length;
20299
+ if (bytes > 2 * 1024 * 1024) stop(new Error(`\u547D\u4EE4\u8F93\u51FA\u8D85\u8FC7\u9650\u5236\uFF1A${command}`));
20300
+ else chunks.push(chunk);
20301
+ };
20302
+ child.stdout?.on("data", collect(stdout));
20303
+ child.stderr?.on("data", collect(stderr));
20304
+ child.stdin?.on("error", () => {
20305
+ });
20306
+ child.on("error", (error) => {
20307
+ failure = error;
20308
+ });
20309
+ child.on("close", (code, exitSignal) => {
20310
+ clearTimeout(timer);
20311
+ clearTimeout(escalation);
20312
+ this.signal.removeEventListener("abort", cancel);
20313
+ if (this.signal.aborted) return reject(this.signal.reason);
20314
+ if (failure) return reject(failure);
20315
+ if (code !== 0) return reject(new Error(`${command} \u5931\u8D25 (${exitSignal ?? code})
20316
+ ${Buffer.concat(stderr).toString("utf8").slice(-8e3)}`));
20317
+ resolveResult(Buffer.concat(stdout).toString("utf8").trim());
20318
+ });
20319
+ child.stdin?.end(options.input);
20320
+ if (this.signal.aborted) cancel();
20321
+ });
20322
+ }
20323
+ };
20324
+
20325
+ // src/services/installation/install-service.ts
20326
+ init_validation();
20327
+ function formatInstallUsage(hosts) {
20328
+ return `\u7528\u6CD5\uFF1Apbot install <${hosts.join("|")}|all> [--workspace <\u76EE\u5F55>] [--dsh-profile <\u540D\u79F0>] [--json]
20329
+ \u4E3A\u6307\u5B9A\u5BBF\u4E3B\u5B89\u88C5 Personal Bot \u63D2\u4EF6\uFF1B\u4F20\u5165 all \u65F6\u4E3A\u672C\u673A\u5DF2\u5B89\u88C5\u7684\u5404\u5BBF\u4E3B\u7EDF\u4E00\u5B89\u88C5\u3002`;
20330
+ }
20331
+ function parseInstallArgs(args, hosts) {
20332
+ const usage = formatInstallUsage(hosts);
20333
+ let target;
20334
+ let workspace;
20335
+ let dshProfile;
20336
+ let json = false;
20337
+ for (let index = 0; index < args.length; index++) {
20338
+ const token = args[index];
20339
+ if (token === "--help" || token === "-h") return { help: true, json: false };
20340
+ if (token === "--json") {
20341
+ json = true;
20342
+ continue;
20343
+ }
20344
+ if (token === "--workspace" || token.startsWith("--workspace=")) {
20345
+ requireThat(workspace === void 0, "--workspace \u53EA\u80FD\u6307\u5B9A\u4E00\u6B21\u3002");
20346
+ workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
20347
+ requireThat(workspace && !workspace.startsWith("-"), "--workspace \u9700\u8981\u76EE\u5F55\u3002");
20348
+ continue;
20349
+ }
20350
+ if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
20351
+ requireThat(dshProfile === void 0, "--dsh-profile \u53EA\u80FD\u6307\u5B9A\u4E00\u6B21\u3002");
20352
+ dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
20353
+ requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile \u9700\u8981 profile \u540D\u79F0\u3002");
20354
+ continue;
20355
+ }
20356
+ if (token.startsWith("-")) {
20357
+ throw new Error(`\u4E0D\u652F\u6301\u7684\u53C2\u6570\uFF1A${token}
20358
+ ${usage}`);
20359
+ }
20360
+ requireThat(target === void 0, `\u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A\u5B89\u88C5\u76EE\u6807\uFF0C\u6536\u5230\u591A\u4F59\u53C2\u6570\uFF1A${token}
20361
+ ${usage}`);
20362
+ target = token.trim().toLowerCase();
20363
+ }
20364
+ requireThat(target && target.length > 0, `\u7F3A\u5C11\u5B89\u88C5\u76EE\u6807\u3002
20365
+ ${usage}`);
20366
+ requireThat(target === "all" || hosts.includes(target), `\u672A\u77E5\u5BBF\u4E3B\uFF1A${target}\u3002
20367
+ ${usage}`);
20368
+ return {
20369
+ help: false,
20370
+ target,
20371
+ ...workspace !== void 0 ? { workspace } : {},
20372
+ ...dshProfile !== void 0 ? { dshProfile } : {},
20373
+ json
20374
+ };
20375
+ }
20376
+ async function executeHostInstall(input) {
20377
+ const explicit = input.target !== "all";
20378
+ const targets = explicit ? [input.target] : [...input.hosts];
20379
+ const results = [];
20380
+ for (const host of targets) {
20381
+ input.signal.throwIfAborted();
20382
+ const installer = input.resolveInstaller(host);
20383
+ let result;
20384
+ if (!installer) {
20385
+ result = {
20386
+ host,
20387
+ state: explicit ? "failed" : "skipped",
20388
+ detail: "\u672A\u6CE8\u518C\u8BE5\u5BBF\u4E3B\u7684\u5B89\u88C5\u9002\u914D\u5668\u3002"
20389
+ };
20390
+ } else {
20391
+ try {
20392
+ result = await installer.install(input.createContext(host, explicit));
20393
+ } catch (error) {
20394
+ input.signal.throwIfAborted();
20395
+ result = {
20396
+ host,
20397
+ state: "failed",
20398
+ detail: error instanceof Error ? error.message : String(error)
20399
+ };
20400
+ }
20401
+ }
20402
+ results.push(result);
20403
+ input.onResult?.(result);
20404
+ }
20405
+ const ok = !results.some((item) => item.state === "failed");
20406
+ return {
20407
+ workspaceRoot: input.workspaceRoot,
20408
+ target: input.target,
20409
+ results,
20410
+ ok
20411
+ };
20412
+ }
20413
+
20414
+ // src/extension/cli/commands/install.ts
20415
+ function formatLine(result) {
20416
+ const scope = result.scope ? ` (${result.scope})` : "";
20417
+ const version = result.version ? ` ${result.version}` : "";
20418
+ const head = `[${result.state}] ${result.host}${scope}${version}: ${result.detail}`;
20419
+ return result.nextStep ? `${head}
20420
+ \u4E0B\u4E00\u6B65\uFF1A${result.nextStep}` : head;
20421
+ }
20422
+ function printHumanSummary(summary) {
20423
+ console.log(`\u5DE5\u4F5C\u533A\uFF1A${summary.workspaceRoot}`);
20424
+ for (const result of summary.results) console.log(formatLine(result));
20425
+ }
20426
+ var installCommand = {
20427
+ name: "install",
20428
+ summary: "\u4E3A\u6307\u5B9A\u5BBF\u4E3B\u6216\u672C\u673A\u5168\u90E8\u5DF2\u5B89\u88C5\u5BBF\u4E3B\u5B89\u88C5\u63D2\u4EF6\uFF08pbot install <host|all>\uFF09",
20429
+ get usage() {
20430
+ return formatInstallUsage(listHostInstallers());
20431
+ },
20432
+ updatePolicy: "none",
20433
+ supportsWorkspaceFlag: true,
20434
+ supportsJsonFlag: true,
20435
+ async run(ctx) {
20436
+ const hosts = listHostInstallers();
20437
+ let parsed;
20438
+ try {
20439
+ parsed = parseInstallArgs(ctx.args, hosts);
20440
+ } catch (error) {
20441
+ throw new CliError(error instanceof Error ? error.message : String(error), 2);
20442
+ }
20443
+ if (parsed.help) {
20444
+ console.log(formatInstallUsage(hosts));
20445
+ return 0;
20446
+ }
20447
+ const workspaceArg = ctx.workspace ?? parsed.workspace;
20448
+ const json = ctx.json || parsed.json;
20449
+ const outcome = await withSignals(
20450
+ async (controller) => {
20451
+ const workspace = await resolveCliWorkspace(workspaceArg, ctx.cwd);
20452
+ const processes = new SetupProcesses(controller.signal, process.env);
20453
+ const summary = await executeHostInstall({
20454
+ workspaceRoot: workspace,
20455
+ target: parsed.target,
20456
+ hosts,
20457
+ resolveInstaller: getHostInstaller,
20458
+ createContext: (_host, explicit) => ({
20459
+ workspace,
20460
+ packageRoot,
20461
+ explicit,
20462
+ env: process.env,
20463
+ signal: controller.signal,
20464
+ options: { dshProfile: parsed.dshProfile },
20465
+ run: (command, args, runCwd, runOptions) => processes.run(command, args, runCwd, runOptions),
20466
+ findExecutable: (name) => findExecutable(name, process.env)
20467
+ }),
20468
+ signal: controller.signal
20469
+ });
20470
+ if (json) console.log(JSON.stringify(summary, null, 2));
20471
+ else printHumanSummary(summary);
20472
+ return summary.ok ? 0 : 1;
20473
+ },
20474
+ () => console.error("\u5B89\u88C5\u5DF2\u53D6\u6D88\u3002")
20475
+ );
20476
+ return outcome.ok ? outcome.value : outcome.exitCode;
20477
+ }
20478
+ };
20479
+
20480
+ // src/extension/cli/commands/mcp.ts
20481
+ init_paths();
20482
+ import { spawnSync as spawnSync2 } from "node:child_process";
20483
+ import { existsSync as existsSync2 } from "node:fs";
20484
+ import { join as join20 } from "node:path";
20485
+
20486
+ // src/integrations/hosts/plugin-registry.ts
20487
+ init_validation();
20488
+
20489
+ // src/integrations/hosts/antigravity/adapter.ts
20490
+ init_json();
20491
+ init_paths();
20492
+ init_validation();
20493
+ import { readFile as readFile6, realpath as realpath4, stat as stat4 } from "node:fs/promises";
20494
+ import { dirname as dirname6, isAbsolute as isAbsolute4, join as join18, relative as relative3, resolve as resolve9, sep } from "node:path";
20495
+ var supportedEvents = ["SessionStart", "PreToolUse", "Stop"];
20496
+ function cleanUserRequest(content) {
20497
+ const match = content.match(/<USER_REQUEST>\s*([\s\S]*?)\s*<\/USER_REQUEST>/);
20498
+ return (match ? match[1] : content).trim();
20499
+ }
20500
+ function projectAntigravityTranscript(sessionId, content, terminationReason) {
20501
+ const exchanges = [];
20502
+ const lines = content.split(/\r?\n/);
20503
+ let users = [];
20504
+ let answer;
20505
+ const finish = (completed2) => {
20506
+ if (!users.length) return;
20507
+ const entryIds = [...users.map((u) => u.id), ...answer ? [answer.id] : []];
20508
+ const from = users[0].time;
20509
+ const to = answer?.time ?? users.at(-1).time;
20510
+ const text = users.map((u) => "\u7528\u6237\uFF1A\n" + u.text).join("\n\n") + (answer ? "\n\n\u52A9\u624B\uFF1A\n" + answer.text : "");
20511
+ exchanges.push({ entryIds, from, to, completed: completed2, text });
20512
+ users = [];
20513
+ answer = void 0;
20514
+ };
20515
+ for (const line of lines) {
20516
+ const trimmed = line.trim();
20517
+ if (!trimmed) continue;
20518
+ let entry;
20519
+ try {
20520
+ entry = JSON.parse(trimmed);
20521
+ } catch {
20522
+ continue;
20523
+ }
20524
+ if (!object(entry) || typeof entry.type !== "string") continue;
20525
+ const stepIndex = typeof entry.step_index === "number" ? entry.step_index : exchanges.length;
20526
+ const time = typeof entry.created_at === "string" && entry.created_at ? entry.created_at : (/* @__PURE__ */ new Date()).toISOString();
20527
+ if (entry.type === "USER_INPUT" && typeof entry.content === "string") {
20528
+ if (answer) finish(true);
20529
+ const cleaned = cleanUserRequest(entry.content);
20530
+ if (cleaned) users.push({ id: `agy:${stepIndex}`, text: cleaned, time });
20531
+ } else if (entry.type === "PLANNER_RESPONSE" && users.length) {
20532
+ const hasToolCalls = Array.isArray(entry.tool_calls) && entry.tool_calls.length > 0;
20533
+ const text = typeof entry.content === "string" ? entry.content.trim() : "";
20534
+ if (!hasToolCalls && text) {
20535
+ answer = { id: `agy:${stepIndex}`, text, time };
20536
+ }
20537
+ }
20538
+ }
20539
+ const completed = Boolean(answer) && (!terminationReason || terminationReason === "NO_TOOL_CALL");
20540
+ finish(completed);
20541
+ return { sessionId, name: "", branches: exchanges.length ? [exchanges] : [] };
20542
+ }
20543
+ async function readAntigravityTranscript(transcriptPath) {
20544
+ const fullPath = join18(dirname6(transcriptPath), "transcript_full.jsonl");
20545
+ for (const path of [fullPath, transcriptPath]) {
20546
+ try {
20547
+ return await readFile6(path, "utf8");
20548
+ } catch (error) {
20549
+ if (error.code !== "ENOENT") throw error;
20550
+ }
20551
+ }
20552
+ return void 0;
20553
+ }
20554
+ function workspaceFromPayload(cwd, payload) {
20555
+ if (object(payload) && Array.isArray(payload.workspacePaths)) {
20556
+ const first = payload.workspacePaths.find((value) => typeof value === "string" && value.length > 0);
20557
+ if (typeof first === "string") return first;
20558
+ }
20559
+ return cwd;
20560
+ }
20561
+ function skillFromReadPath(targetPath, pluginRoot = process.env.PLUGIN_ROOT || resolve9(resourceRoot, "..")) {
20562
+ const skillsRoot = resolve9(pluginRoot, "skills");
20563
+ const rel = relative3(skillsRoot, resolve9(targetPath));
20564
+ if (!rel || rel.startsWith("..") || isAbsolute4(rel)) return void 0;
20565
+ const skill = rel.split(sep)[0];
20566
+ if (!skill || skill === "pbot") return void 0;
20567
+ return skill;
20568
+ }
20569
+ function isPreToolUse(payload) {
20570
+ return object(payload) && payload.hookEventName === "PreToolUse";
20571
+ }
20572
+ async function antigravityWorkspaceRoot(cwd, payload) {
20573
+ const directory = workspaceFromPayload(cwd, payload);
20574
+ requireThat(isAbsolute4(directory), "Antigravity \u5DE5\u4F5C\u533A\u9700\u8981\u7EDD\u5BF9\u8DEF\u5F84\u3002");
20575
+ const root = await realpath4(directory);
20576
+ requireThat((await stat4(root)).isDirectory(), "Antigravity \u5DE5\u4F5C\u533A\u9700\u8981\u76EE\u5F55\u3002");
20577
+ return root;
20578
+ }
20579
+ var antigravityAdapter = {
20580
+ host: "antigravity",
20581
+ nativeRootAgents: true,
20582
+ nativeWorkspaceSkills: true,
20583
+ coordinatorPrompt: "plugin-coordinator.md",
20584
+ initCommandHint: "/pbot init",
20585
+ usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/plugin.js antigravity init|status",
20586
+ resolveRoot(cwd, rawPayload) {
20587
+ return antigravityWorkspaceRoot(cwd, rawPayload);
20588
+ },
20589
+ parseEvent(value) {
20590
+ requireThat(object(value) && typeof value.hookEventName === "string", "Antigravity hook \u8F93\u5165\u65E0\u6548\u3002");
20591
+ const event = value.hookEventName;
20592
+ requireThat(supportedEvents.includes(event), "Antigravity hook \u4E8B\u4EF6\u672A\u652F\u6301\u3002");
20593
+ const cwd = typeof value.cwd === "string" && value.cwd ? value.cwd : workspaceFromPayload("", value);
20594
+ requireThat(cwd, "Antigravity hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20595
+ if (event === "SessionStart") {
20596
+ return { kind: "inject-context", role: "coordinator", isSessionStart: true, cwd, raw: value };
20597
+ }
20598
+ if (event === "Stop") {
20599
+ return { kind: "record-history", cwd, raw: value };
20600
+ }
20601
+ if (!object(value.toolCall) || typeof value.toolCall.name !== "string" || !object(value.toolCall.args)) {
20602
+ return { kind: "ignore" };
20603
+ }
20604
+ const { name, args } = value.toolCall;
20605
+ if (name === "read_file" && typeof args.Path === "string") {
20606
+ const skill = skillFromReadPath(args.Path);
20607
+ if (skill) return { kind: "check-skill", skill, cwd, raw: value };
20608
+ }
20609
+ return { kind: "ignore" };
20610
+ },
20611
+ async extractHistory(event) {
20612
+ if (event.kind !== "record-history" || !object(event.raw)) return void 0;
20613
+ const sessionId = typeof event.raw.conversationId === "string" ? event.raw.conversationId.trim() : "";
20614
+ if (!sessionId) return void 0;
20615
+ const terminationReason = typeof event.raw.terminationReason === "string" ? event.raw.terminationReason : void 0;
20616
+ const transcriptPath = typeof event.raw.transcriptPath === "string" ? event.raw.transcriptPath.trim() : "";
20617
+ if (transcriptPath) {
20618
+ const content = await readAntigravityTranscript(transcriptPath);
20619
+ if (content) {
20620
+ const session = projectAntigravityTranscript(sessionId, content, terminationReason);
20621
+ if (session.branches.length) return { kind: "session", session };
20622
+ }
20623
+ }
20624
+ const lastUserInput = typeof event.raw.lastUserInput === "string" ? event.raw.lastUserInput.trim() : "";
20625
+ if (lastUserInput) return { kind: "input", sessionId, text: lastUserInput };
20626
+ return void 0;
20627
+ },
20628
+ formatPass(payload) {
20629
+ return isPreToolUse(payload) ? { decision: "allow" } : {};
20630
+ },
20631
+ formatContext(_event, context) {
20632
+ return {
20633
+ injectSteps: [
20634
+ { systemMessage: { systemMessage: context.text } }
20635
+ ]
20636
+ };
20637
+ },
20638
+ formatDeny(_event, reason) {
20639
+ return { decision: "deny", reason };
20640
+ }
20641
+ };
20642
+
20643
+ // src/integrations/hosts/claude/adapter.ts
20644
+ init_json();
20645
+ init_validation();
20646
+
20647
+ // src/integrations/hosts/prompt-hooks.ts
20648
+ init_json();
20649
+ init_validation();
20650
+ import { realpath as realpath5, stat as stat5 } from "node:fs/promises";
20651
+ import { isAbsolute as isAbsolute5 } from "node:path";
20652
+ async function pluginWorkspaceRoot(directory) {
20653
+ requireThat(isAbsolute5(directory), "\u63D2\u4EF6\u5DE5\u4F5C\u533A\u9700\u8981\u7EDD\u5BF9\u8DEF\u5F84\u3002");
20654
+ const root = await realpath5(directory);
20655
+ requireThat((await stat5(root)).isDirectory(), "\u63D2\u4EF6\u5DE5\u4F5C\u533A\u9700\u8981\u76EE\u5F55\u3002");
20656
+ return root;
20657
+ }
20658
+ function parsePromptEvent(value) {
20659
+ requireThat(object(value), "\u63D2\u4EF6 hook \u8F93\u5165\u65E0\u6548\u3002");
20660
+ const name = value.hook_event_name;
20661
+ if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart") return { kind: "ignore" };
20662
+ if (typeof value.agent_id === "string") return { kind: "ignore" };
20663
+ requireThat(typeof value.cwd === "string", "\u63D2\u4EF6 hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20664
+ if (name === "Stop") return { kind: "record-history", cwd: value.cwd, raw: value };
20665
+ if (name === "SessionStart") {
20666
+ if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
20667
+ return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
20668
+ }
20669
+ return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
20670
+ }
20671
+ var promptHooks = {
20672
+ async extractHistory(event) {
20673
+ if (!object(event.raw)) return void 0;
20674
+ const sessionId = typeof event.raw.session_id === "string" ? event.raw.session_id.trim() : "";
20675
+ if (!sessionId) return void 0;
20676
+ const turnId = typeof event.raw.turn_id === "string" ? event.raw.turn_id.trim() : "";
20677
+ const identity2 = turnId ? { sessionId, turnId } : { sessionId };
20678
+ if (event.raw.hook_event_name === "UserPromptSubmit") {
20679
+ const text = typeof event.raw.prompt === "string" ? event.raw.prompt.trim() : "";
20680
+ if (!text && !turnId) return void 0;
20681
+ return { kind: "input", ...identity2, text };
20682
+ }
20683
+ if (event.raw.hook_event_name === "Stop") {
20684
+ const assistantText = typeof event.raw.last_assistant_message === "string" ? event.raw.last_assistant_message.trim() : "";
20685
+ if (!assistantText) return void 0;
20686
+ return {
20687
+ kind: "answer",
20688
+ ...identity2,
20689
+ assistantText,
20690
+ completed: true,
20691
+ ...event.raw.stop_hook_active === true ? { isContinuation: true } : {}
20692
+ };
20693
+ }
20694
+ return void 0;
20695
+ },
20696
+ formatPass() {
20697
+ return {};
20698
+ },
20699
+ formatContext(event, context) {
20700
+ const raw = event.raw;
20701
+ return {
20702
+ hookSpecificOutput: {
20703
+ hookEventName: raw.hook_event_name,
20704
+ additionalContext: context.text
20705
+ }
20706
+ };
20707
+ },
20708
+ formatDeny(event, reason) {
20709
+ const raw = event.raw;
20710
+ return raw.hook_event_name === "UserPromptExpansion" ? { decision: "block", reason } : { hookSpecificOutput: { hookEventName: raw.hook_event_name, permissionDecision: "deny", permissionDecisionReason: reason } };
20711
+ }
20712
+ };
20713
+
20714
+ // src/integrations/hosts/claude/adapter.ts
20715
+ var supportedEvents2 = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
20716
+ var boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
20717
+ async function claudeWorkspaceRoot(cwd, projectDirectory = boundWorkspaceRoot()) {
20718
+ return pluginWorkspaceRoot(projectDirectory || cwd);
20719
+ }
20720
+ var claudeAdapter = {
20721
+ host: "claude",
20722
+ nativeRootAgents: false,
20723
+ nativeWorkspaceSkills: false,
20724
+ coordinatorPrompt: "plugin-coordinator.md",
20725
+ initCommandHint: "/personal-bot:pbot init",
20726
+ usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/claude.js init|status",
20727
+ boundWorkspaceRoot,
20728
+ resolveRoot(cwd) {
20729
+ return claudeWorkspaceRoot(cwd);
20730
+ },
20731
+ parseEvent(value) {
20732
+ requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook \u8F93\u5165\u65E0\u6548\u3002");
20733
+ const event = value.hook_event_name;
20734
+ requireThat(supportedEvents2.includes(event), "Claude hook \u4E8B\u4EF6\u672A\u652F\u6301\u3002");
20735
+ if (event === "PreToolUse" || event === "UserPromptExpansion") {
20736
+ const skill = event === "UserPromptExpansion" ? value.expansion_type === "slash_command" ? value.command_name : void 0 : value.tool_name === "Skill" && object(value.tool_input) ? value.tool_input.skill : void 0;
20737
+ if (typeof skill !== "string" || !skill.startsWith("personal-bot:") || skill === "personal-bot:pbot") return { kind: "ignore" };
20738
+ requireThat(typeof value.cwd === "string", "Claude hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
20739
+ return { kind: "check-skill", skill, cwd: value.cwd, raw: value };
20740
+ }
20741
+ return parsePromptEvent(value);
20742
+ },
20743
+ ...promptHooks
20744
+ };
20745
+
20746
+ // src/integrations/hosts/codex/adapter.ts
20747
+ var codexAdapter = {
20748
+ host: "codex",
20749
+ nativeRootAgents: true,
20750
+ nativeWorkspaceSkills: true,
20751
+ indexBundledSkills: true,
20752
+ initCommandHint: "pbot plugin codex init",
20753
+ usage: "\u7528\u6CD5\uFF1Apbot plugin codex init|status",
20754
+ resolveRoot(cwd) {
20755
+ return pluginWorkspaceRoot(cwd);
20756
+ },
20757
+ parseEvent: parsePromptEvent,
20758
+ ...promptHooks
20759
+ };
20760
+
20761
+ // src/integrations/hosts/qoder/adapter.ts
20762
+ var boundWorkspaceRoot2 = () => process.env.QODER_PROJECT_DIR || process.env.PBOT_WORKSPACE_ROOT;
20763
+ var qoderAdapter = {
20764
+ host: "qoder",
20765
+ nativeRootAgents: true,
20766
+ nativeWorkspaceSkills: true,
20767
+ indexBundledSkills: true,
20768
+ initCommandHint: "pbot plugin qoder init",
20769
+ usage: "\u7528\u6CD5\uFF1Apbot plugin qoder init|status",
20770
+ boundWorkspaceRoot: boundWorkspaceRoot2,
20771
+ resolveRoot(cwd) {
20772
+ return pluginWorkspaceRoot(boundWorkspaceRoot2() || cwd);
20773
+ },
20774
+ parseEvent: parsePromptEvent,
20775
+ ...promptHooks
20776
+ };
20777
+
20778
+ // src/integrations/hosts/plugin-registry.ts
20779
+ var PluginHostRegistry = class {
20780
+ #adapters = /* @__PURE__ */ new Map();
20781
+ constructor(initial = []) {
20782
+ for (const adapter of initial) this.register(adapter);
20783
+ }
20784
+ register(adapter) {
20785
+ requireThat(typeof adapter.host === "string" && adapter.host.length > 0, "\u63D2\u4EF6\u5BBF\u4E3B\u6807\u8BC6\u65E0\u6548\u3002");
20786
+ this.#adapters.set(adapter.host, adapter);
20787
+ return this;
20788
+ }
20789
+ unregister(host) {
20790
+ return this.#adapters.delete(host);
20791
+ }
20792
+ get(host) {
20793
+ return this.#adapters.get(host);
20794
+ }
20795
+ require(host) {
20796
+ const adapter = this.#adapters.get(host);
20797
+ requireThat(adapter, `\u672A\u6CE8\u518C\u7684\u63D2\u4EF6\u5BBF\u4E3B\uFF1A${host}\u3002\u53EF\u7528\u5BBF\u4E3B\uFF1A${this.list().join(", ")}`);
20798
+ return adapter;
20799
+ }
20800
+ list() {
20801
+ return [...this.#adapters.keys()];
20802
+ }
20803
+ };
20804
+ var pluginHosts = new PluginHostRegistry([claudeAdapter, antigravityAdapter, codexAdapter, qoderAdapter]);
20805
+ var getPluginHost = (host) => pluginHosts.get(host);
20806
+ var listPluginHosts = () => pluginHosts.list();
20807
+ function pluginMcpWorkspaceRoot() {
20808
+ const adapter = process.env.PBOT_HOST ? pluginHosts.get(process.env.PBOT_HOST) : claudeAdapter;
20809
+ return adapter?.boundWorkspaceRoot?.() || process.env.PBOT_WORKSPACE_ROOT;
20810
+ }
20811
+
20812
+ // src/services/workspace/workspace-mcp.ts
20813
+ init_json();
20814
+ init_validation();
20815
+ init_atomic_json();
20816
+ import { mkdir as mkdir3, readFile as readFile7 } from "node:fs/promises";
20817
+ import { dirname as dirname7, join as join19, resolve as resolve10 } from "node:path";
20818
+ var serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
20819
+ var reservedServerNames = /* @__PURE__ */ new Set(["pbot"]);
20820
+ var stdioKeys = /* @__PURE__ */ new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
20821
+ var httpKeys = /* @__PURE__ */ new Set(["url", "headers", "description", "timeout", "enabled"]);
20822
+ var envPattern = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
20823
+ function validateStringRecord(value, label) {
20824
+ requireThat(object(value), `${label} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6620\u5C04\u3002`);
20825
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
20826
+ requireThat(
20827
+ key.length > 0 && !key.includes("\0") && typeof entry === "string" && !entry.includes("\0"),
20828
+ `${label}.${key} \u5FC5\u987B\u662F\u975E\u7A7A\u952E\u4E0E\u65E0\u7A7A\u5B57\u8282\u5B57\u7B26\u4E32\u503C\u3002`
20829
+ );
20830
+ return [key, entry];
20831
+ }));
20832
+ }
20833
+ function validateWorkspaceMcpServer(name, value) {
20834
+ requireThat(serverNamePattern.test(name), `MCP \u670D\u52A1\u540D\u65E0\u6548\uFF1A${name}\uFF08\u9700\u5339\u914D [A-Za-z0-9][A-Za-z0-9_-]{0,31}\uFF09\u3002`);
20835
+ requireThat(!reservedServerNames.has(name.toLowerCase()), `MCP \u670D\u52A1\u540D "${name}" \u4E3A Personal Bot \u4FDD\u7559\u540D\u79F0\u3002`);
20836
+ requireThat(object(value), `MCP \u670D\u52A1 "${name}" \u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002`);
20837
+ const hasCommand = value.command !== void 0;
20838
+ const hasUrl = value.url !== void 0;
20839
+ requireThat(hasCommand !== hasUrl, `MCP \u670D\u52A1 "${name}" \u5FC5\u987B\u4E14\u53EA\u80FD\u58F0\u660E command\uFF08stdio\uFF09\u6216 url\uFF08Streamable HTTP\uFF09\u4E4B\u4E00\u3002`);
20840
+ const allowed = hasCommand ? stdioKeys : httpKeys;
20841
+ const unknown = Object.keys(value).filter((key) => !allowed.has(key));
20842
+ requireThat(unknown.length === 0, `MCP \u670D\u52A1 "${name}" \u5305\u542B\u672A\u77E5\u5B57\u6BB5\uFF1A${unknown.join(", ")}\u3002`);
20843
+ if (value.description !== void 0) {
20844
+ requireThat(
20845
+ typeof value.description === "string" && !value.description.includes("\0"),
20846
+ `MCP \u670D\u52A1 "${name}" \u7684 description \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002`
20847
+ );
20848
+ }
20849
+ if (value.timeout !== void 0) {
20850
+ requireThat(
20851
+ typeof value.timeout === "number" && Number.isInteger(value.timeout) && value.timeout >= 1 && value.timeout <= 3600,
20852
+ `MCP \u670D\u52A1 "${name}" \u7684 timeout \u5FC5\u987B\u662F 1\u20133600 \u7684\u6574\u6570\u79D2\u3002`
20853
+ );
20854
+ }
20855
+ if (value.enabled !== void 0) {
20856
+ requireThat(typeof value.enabled === "boolean", `MCP \u670D\u52A1 "${name}" \u7684 enabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002`);
20857
+ }
20858
+ const base = {
20859
+ ...value.description !== void 0 ? { description: value.description } : {},
20860
+ ...value.timeout !== void 0 ? { timeout: value.timeout } : {},
20861
+ ...value.enabled !== void 0 ? { enabled: value.enabled } : {}
20862
+ };
20863
+ if (hasCommand) {
20864
+ requireThat(
20865
+ typeof value.command === "string" && value.command.trim().length > 0 && !value.command.includes("\0"),
20866
+ `MCP \u670D\u52A1 "${name}" \u7684 command \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20867
+ );
20868
+ let args;
20869
+ if (value.args !== void 0) {
20870
+ requireThat(
20871
+ Array.isArray(value.args) && value.args.every((item) => typeof item === "string" && !item.includes("\0")),
20872
+ `MCP \u670D\u52A1 "${name}" \u7684 args \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4\u3002`
20873
+ );
20874
+ args = [...value.args];
20875
+ }
20876
+ const env = value.env !== void 0 ? validateStringRecord(value.env, `MCP \u670D\u52A1 "${name}" \u7684 env`) : void 0;
20877
+ let cwd;
20878
+ if (value.cwd !== void 0) {
20879
+ requireThat(
20880
+ typeof value.cwd === "string" && value.cwd.trim().length > 0 && !value.cwd.includes("\0"),
20881
+ `MCP \u670D\u52A1 "${name}" \u7684 cwd \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20882
+ );
20883
+ cwd = value.cwd;
20884
+ }
20885
+ const entry2 = {
20886
+ command: value.command,
20887
+ ...args ? { args } : {},
20888
+ ...env ? { env } : {},
20889
+ ...cwd ? { cwd } : {},
20890
+ ...base
20891
+ };
20892
+ return entry2;
20893
+ }
20894
+ requireThat(
20895
+ typeof value.url === "string" && value.url.trim().length > 0 && !value.url.includes("\0"),
20896
+ `MCP \u670D\u52A1 "${name}" \u7684 url \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`
20897
+ );
20898
+ const rawUrl = value.url.trim();
20899
+ requireThat(
20900
+ /^https?:\/\/.+/.test(rawUrl) || envPattern.test(rawUrl),
20901
+ `MCP \u670D\u52A1 "${name}" \u7684 url \u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934\u3002`
20902
+ );
20903
+ envPattern.lastIndex = 0;
20904
+ const headers = value.headers !== void 0 ? validateStringRecord(value.headers, `MCP \u670D\u52A1 "${name}" \u7684 headers`) : void 0;
20905
+ const entry = {
20906
+ url: rawUrl,
20907
+ ...headers ? { headers } : {},
20908
+ ...base
20909
+ };
20910
+ return entry;
20911
+ }
20912
+ function validateMcpFile(value) {
20913
+ requireThat(object(value), "\u5DE5\u4F5C\u533A MCP \u914D\u7F6E\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u3002");
20914
+ const rawServers = value.mcpServers;
20915
+ requireThat(rawServers !== void 0 && object(rawServers), "\u5DE5\u4F5C\u533A MCP \u914D\u7F6E\u9700\u8981 mcpServers \u5BF9\u8C61\u3002");
20916
+ const servers = {};
20917
+ for (const [name, entry] of Object.entries(rawServers)) {
20918
+ servers[name] = validateWorkspaceMcpServer(name, entry);
20410
20919
  }
20411
20920
  return { ...value, mcpServers: servers };
20412
20921
  }
20413
20922
  function workspaceMcpPath(root) {
20414
- return join16(root, ".pbot", "mcp.json");
20923
+ return join19(root, ".pbot", "mcp.json");
20415
20924
  }
20416
20925
  async function readWorkspaceMcpConfig(root) {
20417
20926
  const path = workspaceMcpPath(root);
20418
20927
  let content;
20419
20928
  try {
20420
- content = await readFile4(path, "utf8");
20929
+ content = await readFile7(path, "utf8");
20421
20930
  } catch (error) {
20422
20931
  if (error.code === "ENOENT") return { path, present: false, servers: {} };
20423
20932
  return { path, present: true, servers: {}, error: `\u65E0\u6CD5\u8BFB\u53D6\u5DE5\u4F5C\u533A MCP \u914D\u7F6E ${path}: ${String(error)}` };
@@ -20460,7 +20969,7 @@ async function removeWorkspaceMcpServer(root, name) {
20460
20969
  // src/extension/cli/commands/mcp.ts
20461
20970
  var mcpUsage = "\u7528\u6CD5\uFF1A\n pbot mcp\n pbot mcp list [--workspace <\u76EE\u5F55>] [--json]\n pbot mcp add <name> --url <url> [--header K=V]... [--description <\u8BF4\u660E>] [--timeout <\u79D2>] [--disabled] [--workspace <\u76EE\u5F55>]\n pbot mcp add <name> [--env K=V]... [--cwd <\u76EE\u5F55>] [--description <\u8BF4\u660E>] [--timeout <\u79D2>] [--disabled] [--workspace <\u76EE\u5F55>] -- <command> [args...]\n pbot mcp remove <name> [--workspace <\u76EE\u5F55>]\n\n\u65E0\u53C2\u6570\u65F6\u542F\u52A8\u7EDF\u4E00 stdio MCP \u670D\u52A1\uFF08\u66B4\u9732 worker_* \u4E0E workspace_mcp_*\uFF09\uFF1B\u5E26 list/add/remove \u65F6\u7BA1\u7406\u5DE5\u4F5C\u533A .pbot/mcp.json\u3002";
20462
20971
  async function runMcpServer() {
20463
- const entry = join17(packageRoot, "lib/extension/mcp.js");
20972
+ const entry = join20(packageRoot, "lib/extension/mcp.js");
20464
20973
  if (!existsSync2(entry)) {
20465
20974
  console.error("\u7F3A\u5C11 MCP \u6784\u5EFA\u4EA7\u7269\uFF1A" + entry + "\u3002\u8BF7\u5148\u8FD0\u884C npm run build\u3002");
20466
20975
  return 1;
@@ -20614,31 +21123,31 @@ init_validation();
20614
21123
 
20615
21124
  // src/extension/hosts/plugin-runtime.ts
20616
21125
  init_paths();
20617
- import { join as join21 } from "node:path";
21126
+ import { join as join24 } from "node:path";
20618
21127
  init_validation();
20619
21128
 
20620
21129
  // src/integrations/agent-resources.ts
20621
21130
  init_paths();
20622
21131
  init_validation();
20623
- import { readFile as readFile5 } from "node:fs/promises";
20624
- import { join as join18 } from "node:path";
21132
+ import { readFile as readFile8 } from "node:fs/promises";
21133
+ import { join as join21 } from "node:path";
20625
21134
  async function readOptionalFile(path) {
20626
21135
  try {
20627
- return await readFile5(path, "utf8");
21136
+ return await readFile8(path, "utf8");
20628
21137
  } catch (error) {
20629
21138
  if (error.code === "ENOENT") return "";
20630
21139
  throw error;
20631
21140
  }
20632
21141
  }
20633
21142
  async function readLocalRole(agent, root) {
20634
- const local = await readOptionalFile(join18(root, "agents", agent + ".md"));
21143
+ const local = await readOptionalFile(join21(root, "agents", agent + ".md"));
20635
21144
  return local.trim() ? "\u5DE5\u4F5C\u533A\u804C\u8D23\u8865\u5145\uFF1A\n" + local : "";
20636
21145
  }
20637
21146
  async function agentText(agent, root, coordinatorPrompt = "plugin-coordinator.md") {
20638
21147
  requireThat(agent === "coordinator" || agent === "general-purpose", "\u672A\u77E5\u804C\u8D23\u3002");
20639
- let text = await readFile5(join18(resourceRoot, "agents", agent + ".md"), "utf8");
21148
+ let text = await readFile8(join21(resourceRoot, "agents", agent + ".md"), "utf8");
20640
21149
  if (agent === "coordinator") {
20641
- text += "\n\n" + await readFile5(join18(resourceRoot, "prompts", coordinatorPrompt), "utf8");
21150
+ text += "\n\n" + await readFile8(join21(resourceRoot, "prompts", coordinatorPrompt), "utf8");
20642
21151
  }
20643
21152
  const local = await readLocalRole(agent, root);
20644
21153
  if (local) text += "\n\n" + local;
@@ -20648,7 +21157,7 @@ async function agentText(agent, root, coordinatorPrompt = "plugin-coordinator.md
20648
21157
  function formatWorkspaceSkills(skills) {
20649
21158
  if (!skills.length) return "";
20650
21159
  const lines = skills.map((skill) => `- **${skill.name}**\uFF08\`${skill.path}\`\uFF09\uFF1A${skill.description}`);
20651
- return "## \u5DE5\u4F5C\u533A\u6280\u80FD\n\n\u5339\u914D\u4EFB\u52A1\u65F6\u6309\u9700\u8BFB\u53D6\u5BF9\u5E94 `SKILL.md` \u6B63\u6587\uFF1A\n" + lines.join("\n");
21160
+ return "## \u53EF\u7528\u6280\u80FD\n\n\u4EFB\u52A1\u5339\u914D\u65F6\u6309\u9700\u8BFB\u53D6\u5BF9\u5E94 `SKILL.md` \u6B63\u6587\uFF1A\n" + lines.join("\n");
20652
21161
  }
20653
21162
  async function loadWorkspaceContext(options) {
20654
21163
  const {
@@ -20663,12 +21172,12 @@ async function loadWorkspaceContext(options) {
20663
21172
  notices = []
20664
21173
  } = options;
20665
21174
  const [workspace, roleText, rootAgents] = includePrompts ? await Promise.all([
20666
- readFile5(join18(resourceRoot, "prompts/workspace.md"), "utf8"),
21175
+ readFile8(join21(resourceRoot, "prompts/workspace.md"), "utf8"),
20667
21176
  localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
20668
- includeRootAgents ? readOptionalFile(join18(root, "AGENTS.md")) : Promise.resolve("")
21177
+ includeRootAgents ? readOptionalFile(join21(root, "AGENTS.md")) : Promise.resolve("")
20669
21178
  ]) : ["", "", ""];
20670
21179
  const skillsSection = formatWorkspaceSkills(workspaceSkills);
20671
- const noticesSection = notices.length ? "## \u542F\u52A8\u63D0\u793A\n\n" + notices.map((item) => `- ${item}`).join("\n") : "";
21180
+ const noticesSection = notices.length ? "## \u542F\u52A8\u63D0\u793A\n\n\u4EE5\u4E0B\u4E3A\u5DE5\u4F5C\u533A\u7EF4\u62A4\u63D0\u9192\uFF0C\u9002\u65F6\u987A\u5E26\u544A\u77E5\u7528\u6237\u5373\u53EF\uFF0C\u52FF\u672A\u7ECF\u7528\u6237\u8981\u6C42\u81EA\u884C\u6267\u884C\uFF1A\n" + notices.map((item) => `- ${item}`).join("\n") : "";
20672
21181
  const environment = { host, workspaceRoot: root, resourceRoot };
20673
21182
  const text = [
20674
21183
  workspace,
@@ -20716,930 +21225,321 @@ function buildSession(host, capture, previous) {
20716
21225
  const turn = turnEntry ? branch.find((item) => item.entryIds.includes(turnEntry)) : void 0;
20717
21226
  const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID3().slice(0, 8)}`;
20718
21227
  if (capture.kind === "input") {
20719
- const text = capture.text.trim();
20720
- if (!text && !turnEntry) return void 0;
20721
- const input = "\u7528\u6237\uFF1A\n" + (text || "\uFF08\u65E0\u6587\u672C\u8F93\u5165\uFF09");
20722
- if (turn) {
20723
- turn.text += "\n\n" + input;
20724
- turn.to = timestamp;
20725
- turn.completed = false;
20726
- } else {
20727
- branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
20728
- }
20729
- return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
20730
- }
20731
- const assistantText = capture.assistantText.trim();
20732
- if (!assistantText) return void 0;
20733
- const target = turnEntry ? turn : branch.at(-1);
20734
- if (target && (turnEntry || !target.completed || capture.isContinuation)) {
20735
- const updated = turnEntry && !target.completed ? target.text + "\n\n\u52A9\u624B\uFF1A\n" + assistantText : replaceAssistantSuffix(target.text, assistantText);
20736
- if (target.text === updated && target.completed === capture.completed) return void 0;
20737
- target.text = updated;
20738
- target.to = timestamp;
20739
- target.completed = capture.completed;
20740
- } else {
20741
- const userText = capture.userText?.trim();
20742
- branch.push({
20743
- entryIds: [entryId()],
20744
- text: userText ? `\u7528\u6237\uFF1A
20745
- ${userText}
20746
-
20747
- \u52A9\u624B\uFF1A
20748
- ${assistantText}` : `\u52A9\u624B\uFF1A
20749
- ${assistantText}`,
20750
- from: timestamp,
20751
- to: timestamp,
20752
- completed: capture.completed
20753
- });
20754
- }
20755
- return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
20756
- }
20757
- function recordHistoryCapture(root, host, capture) {
20758
- const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
20759
- if (!sessionId) return;
20760
- const files = workspaceHistoryFiles(root, host);
20761
- files.control(() => {
20762
- const previous = files.listRaw(host).find((raw2) => raw2.sessionId === sessionId);
20763
- if (!previous && files.rawWarnings.length) return;
20764
- const session = buildSession(host, capture, previous);
20765
- if (!session || !session.branches.length) return;
20766
- const raw = indexHistory(session, previous, host);
20767
- if (isDeepStrictEqual3(raw, previous)) return;
20768
- files.saveRaw(raw);
20769
- });
20770
- }
20771
-
20772
- // src/extension/hosts/plugin-runtime.ts
20773
- init_summary_runner();
20774
- init_workspace_config2();
20775
-
20776
- // src/services/workspace/workspace-preparation.ts
20777
- init_validation();
20778
- init_paths();
20779
- init_workspace_config2();
20780
- import { lstat as lstat2, mkdir as mkdir4, readFile as readFile6, writeFile as writeFile2 } from "node:fs/promises";
20781
- import { join as join19 } from "node:path";
20782
- async function initializeWorkspace(root) {
20783
- const configuration = await readWorkspaceConfig(root);
20784
- if (configuration.error) throw new Error(configuration.error);
20785
- await prepareWorkspace(root);
20786
- await initializeWorkspaceConfig(root);
20787
- }
20788
- var directories = ["areas", "projects", "knowledge", "providers", "scratch", "agents"];
20789
- async function prepareWorkspace(root) {
20790
- for (const part of directories) {
20791
- const path = join19(root, part);
20792
- await mkdir4(path, { mode: 448 }).catch((error) => {
20793
- if (error.code !== "EEXIST") throw error;
20794
- });
20795
- const entry = await lstat2(path);
20796
- requireThat(entry.isDirectory() && !entry.isSymbolicLink(), "\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u80FD\u4F7F\u7528\u7B26\u53F7\u94FE\u63A5\uFF1A" + path);
20797
- }
20798
- const agents = await readFile6(join19(resourceRoot, "templates/workspace-agents.md"), "utf8");
20799
- await writeFile2(join19(root, "AGENTS.md"), agents, { flag: "wx" }).catch((error) => {
20800
- if (error.code !== "EEXIST") throw error;
20801
- });
20802
- }
20803
-
20804
- // src/services/workspace/workspace-skills.ts
20805
- import { readdir, readFile as readFile7 } from "node:fs/promises";
20806
- import { join as join20 } from "node:path";
20807
- function unquoteYaml(value) {
20808
- const trimmed = value.trim();
20809
- if (trimmed.length >= 2 && (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'"))) {
20810
- return trimmed.slice(1, -1).trim();
20811
- }
20812
- return trimmed;
20813
- }
20814
- function parseSkillFrontmatter(content) {
20815
- const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
20816
- if (!match) return void 0;
20817
- const lines = match[1].split(/\r?\n/);
20818
- const fields2 = {};
20819
- for (let i = 0; i < lines.length; i++) {
20820
- const line = lines[i];
20821
- const pair = line.match(/^([A-Za-z0-9_-]+)\s*:\s*(.*)$/);
20822
- if (!pair) continue;
20823
- const key = pair[1];
20824
- const raw = pair[2].trim();
20825
- if (/^[>|][+-]?$/.test(raw)) {
20826
- const folded = raw.startsWith(">");
20827
- const block = [];
20828
- let indent;
20829
- while (i + 1 < lines.length) {
20830
- const next = lines[i + 1];
20831
- if (!next.trim()) {
20832
- block.push("");
20833
- i++;
20834
- continue;
20835
- }
20836
- const leading = next.match(/^\s+/)?.[0].length ?? 0;
20837
- if (leading === 0) break;
20838
- indent ??= leading;
20839
- block.push(next.slice(Math.min(indent, leading)).trimEnd());
20840
- i++;
20841
- }
20842
- const joined = folded ? block.map((item) => item.trim()).filter(Boolean).join(" ") : block.join("\n").trim();
20843
- fields2[key] = joined;
20844
- } else if (raw) {
20845
- fields2[key] = unquoteYaml(raw);
20846
- }
20847
- }
20848
- return {
20849
- ...fields2.name ? { name: fields2.name } : {},
20850
- ...fields2.description ? { description: fields2.description } : {}
20851
- };
20852
- }
20853
- async function discoverWorkspaceSkills(root) {
20854
- return discoverSkills(join20(root, ".agents", "skills"), ".agents/skills");
20855
- }
20856
- async function discoverSkills(skillsDir, indexPath) {
20857
- let entries;
20858
- try {
20859
- entries = await readdir(skillsDir, { withFileTypes: true });
20860
- } catch (error) {
20861
- if (error.code === "ENOENT") return [];
20862
- throw error;
20863
- }
20864
- const results = [];
20865
- for (const entry of entries) {
20866
- if (entry.name.startsWith(".") || !entry.isDirectory() && !entry.isSymbolicLink()) continue;
20867
- const filePath = join20(skillsDir, entry.name, "SKILL.md");
20868
- let content;
20869
- try {
20870
- content = await readFile7(filePath, "utf8");
20871
- } catch {
20872
- continue;
20873
- }
20874
- const meta = parseSkillFrontmatter(content);
20875
- if (!meta?.name || !meta.description) continue;
20876
- results.push({
20877
- name: meta.name,
20878
- description: meta.description,
20879
- path: join20(indexPath, entry.name, "SKILL.md")
20880
- });
20881
- }
20882
- results.sort((a, b) => a.name.localeCompare(b.name));
20883
- return results;
20884
- }
20885
-
20886
- // src/extension/hosts/plugin-runtime.ts
20887
- function disabledMessage(adapter, configuration) {
20888
- return configuration.error ?? `Personal Bot \u672A\u5728\u6B64\u5DE5\u4F5C\u533A\u542F\u7528\u3002\u8FD0\u884C ${adapter.initCommandHint}\uFF1B\u914D\u7F6E\u6587\u4EF6\uFF1A${configuration.path}`;
20889
- }
20890
- async function pluginCommand(adapter, args, cwd) {
20891
- const root = await adapter.resolveRoot(cwd);
20892
- const action = args.join(" ");
20893
- requireThat(["init", "status"].includes(action), adapter.usage);
20894
- if (action === "init") {
20895
- await initializeWorkspace(root);
20896
- bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
20897
- }
20898
- const configuration = await readWorkspaceConfig(root);
20899
- return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
20900
- }
20901
- async function runPluginHost(adapter, args, replay) {
20902
- if (args[0] === "hook") {
20903
- let input = "";
20904
- process.stdin.setEncoding("utf8");
20905
- for await (const chunk of process.stdin) input += String(chunk);
20906
- const result = await pluginHook(adapter, JSON.parse(input), replay && ((root) => replay(root, input)));
20907
- if (typeof result === "number") process.exitCode = result;
20908
- else process.stdout.write(JSON.stringify(result) + "\n");
20909
- } else {
20910
- process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
20911
- }
20912
- }
20913
- async function pluginHook(adapter, payload, replay) {
20914
- if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
20915
- const event = adapter.parseEvent(payload);
20916
- if (event.kind === "ignore") return adapter.formatPass(payload);
20917
- const root = await adapter.resolveRoot(event.cwd, event.raw);
20918
- const configuration = await readWorkspaceConfig(root);
20919
- if (configuration.enabled && replay) {
20920
- const code = await replay(root);
20921
- if (code !== void 0) return code;
20922
- }
20923
- const features = workspaceFeatures(configuration);
20924
- if (event.kind === "check-skill") {
20925
- if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
20926
- if (!features.skills) return adapter.formatDeny(event, `Personal Bot \u5DE5\u4F5C\u533A\u6280\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.skills: false\uFF09\u3002`);
20927
- return adapter.formatPass(payload);
20928
- }
20929
- if (!configuration.enabled) return adapter.formatPass(payload);
20930
- if (event.kind === "inject-context") bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
20931
- if (features.history && adapter.extractHistory) {
20932
- try {
20933
- const capture = await adapter.extractHistory(event);
20934
- if (capture) recordHistoryCapture(root, adapter.host, capture);
20935
- } catch {
20936
- }
20937
- }
20938
- if (event.kind === "record-history") return adapter.formatPass(payload);
20939
- const includePrompts = features.prompts && !event.noticesOnly;
20940
- const includeSkills = features.skills && !event.noticesOnly;
20941
- const workspaceSkills = includeSkills && !adapter.nativeWorkspaceSkills ? await discoverWorkspaceSkills(root) : [];
20942
- if (includeSkills && adapter.indexBundledSkills) {
20943
- const directory = join21(resourceRoot, "skills");
20944
- workspaceSkills.push(...await discoverSkills(directory, directory));
20945
- }
20946
- const notices = event.isSessionStart && features.history ? [...historyStartupNotices(root)] : [];
20947
- if (event.isSessionStart) {
20948
- const drift = workspacePluginDrift(workspacePluginReleases(root));
20949
- if (drift.outOfSync) {
20950
- const summary = Object.entries(drift.versions).map(([host, version]) => `${host}=${version}`).join(", ");
20951
- notices.push(`\u68C0\u6D4B\u5230\u5F53\u524D\u5DE5\u4F5C\u533A\u5404\u5BBF\u4E3B Personal Bot \u63D2\u4EF6\u7248\u672C\u4E0D\u4E00\u81F4\uFF08${summary}\uFF09\uFF0C\u53EF\u5728\u7EC8\u7AEF\u8FD0\u884C pbot upgrade \u7EDF\u4E00\u5347\u7EA7\u3002`);
21228
+ const text = capture.text.trim();
21229
+ if (!text && !turnEntry) return void 0;
21230
+ const input = "\u7528\u6237\uFF1A\n" + (text || "\uFF08\u65E0\u6587\u672C\u8F93\u5165\uFF09");
21231
+ if (turn) {
21232
+ turn.text += "\n\n" + input;
21233
+ turn.to = timestamp;
21234
+ turn.completed = false;
21235
+ } else {
21236
+ branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
20952
21237
  }
21238
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
20953
21239
  }
20954
- if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
20955
- const context = await loadWorkspaceContext({
20956
- host: adapter.host,
20957
- root,
20958
- role: event.role,
20959
- ...adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {},
20960
- includePrompts,
20961
- includeRootAgents: includePrompts && !adapter.nativeRootAgents,
20962
- ...event.localRoleOnly ? { localRoleOnly: true } : {},
20963
- workspaceSkills,
20964
- notices
20965
- });
20966
- return adapter.formatContext(event, context);
20967
- }
21240
+ const assistantText = capture.assistantText.trim();
21241
+ if (!assistantText) return void 0;
21242
+ const target = turnEntry ? turn : branch.at(-1);
21243
+ if (target && (turnEntry || !target.completed || capture.isContinuation)) {
21244
+ const updated = turnEntry && !target.completed ? target.text + "\n\n\u52A9\u624B\uFF1A\n" + assistantText : replaceAssistantSuffix(target.text, assistantText);
21245
+ if (target.text === updated && target.completed === capture.completed) return void 0;
21246
+ target.text = updated;
21247
+ target.to = timestamp;
21248
+ target.completed = capture.completed;
21249
+ } else {
21250
+ const userText = capture.userText?.trim();
21251
+ branch.push({
21252
+ entryIds: [entryId()],
21253
+ text: userText ? `\u7528\u6237\uFF1A
21254
+ ${userText}
20968
21255
 
20969
- // src/extension/cli/commands/plugin.ts
20970
- function pluginUsage() {
20971
- return `\u7528\u6CD5\uFF1Apbot plugin <${listPluginHosts().join("|")}> hook|init|status
20972
- \u8FD0\u884C\u63D2\u4EF6\u5BBF\u4E3B\u547D\u4EE4\u6216\u65E0\u72B6\u6001 hook\u3002`;
20973
- }
20974
- var pluginCommand2 = {
20975
- name: "plugin",
20976
- summary: "\u8FD0\u884C\u63D2\u4EF6\u5BBF\u4E3B\u547D\u4EE4\uFF08hook / init / status\uFF09",
20977
- get usage() {
20978
- return pluginUsage();
20979
- },
20980
- updatePolicy: (ctx) => ctx.args[1] === "hook" ? "hook" : "workspace",
20981
- allowUninitializedUpdate: (ctx) => ctx.args[1] === "init" && ctx.args.length === 2,
20982
- async resolveWorkspaceRoot(ctx) {
20983
- const host = ctx.args[0];
20984
- const resolved = host ? await getPluginHost(host)?.resolveRoot(ctx.cwd) : void 0;
20985
- return resolveCliWorkspace(resolved ?? ctx.cwd, ctx.cwd);
20986
- },
20987
- async run(ctx, helpers) {
20988
- const [host, ...rest] = ctx.args;
20989
- const adapter = host ? pluginHosts.get(host) : void 0;
20990
- requireThat(adapter, pluginUsage());
20991
- const previousCode = process.exitCode;
20992
- process.exitCode = void 0;
20993
- await runPluginHost(adapter, rest, (root, input) => helpers.updateForWorkspace(root, ctx.rawArgs, input));
20994
- const exitCode = typeof process.exitCode === "number" ? process.exitCode : 0;
20995
- process.exitCode = previousCode;
20996
- return exitCode;
21256
+ \u52A9\u624B\uFF1A
21257
+ ${assistantText}` : `\u52A9\u624B\uFF1A
21258
+ ${assistantText}`,
21259
+ from: timestamp,
21260
+ to: timestamp,
21261
+ completed: capture.completed
21262
+ });
20997
21263
  }
20998
- };
20999
-
21000
- // src/extension/cli/commands/setup.ts
21001
- import { spawnSync as spawnSync3 } from "node:child_process";
21002
- import { existsSync as existsSync4 } from "node:fs";
21003
- import { mkdir as mkdir5, readFile as readFile9, realpath as realpath7 } from "node:fs/promises";
21004
- import { join as join24 } from "node:path";
21005
-
21006
- // src/common/package-source.ts
21007
- var import_semver2 = __toESM(require_semver2(), 1);
21008
- function npmName(source) {
21009
- return /^npm:((?:@[a-z0-9._-]+\/)?[a-z0-9._-]+)(?:@[^\s]+)?$/.exec(source)?.[1];
21010
- }
21011
- function ordinaryNpm(source) {
21012
- const name = npmName(source);
21013
- return name !== void 0 && (source === `npm:${name}` || source === `npm:${name}@latest`);
21264
+ return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
21014
21265
  }
21015
- function checkStableVersion(version, nodeRange) {
21016
- if (!(0, import_semver2.valid)(version) || (0, import_semver2.prerelease)(version)) throw new Error(`latest \u4E0D\u662F\u7A33\u5B9A\u7248\u672C\uFF1A${version}`);
21017
- if (nodeRange && !(0, import_semver2.satisfies)(process.versions.node, nodeRange)) {
21018
- throw new Error(`\u76EE\u6807\u7248\u672C\u8981\u6C42 Node.js ${nodeRange}\uFF0C\u5F53\u524D\u4E3A ${process.versions.node}\u3002\u8BF7\u5148\u5347\u7EA7 Node.js\u3002`);
21019
- }
21020
- return version;
21266
+ function recordHistoryCapture(root, host, capture) {
21267
+ const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
21268
+ if (!sessionId) return;
21269
+ const files = workspaceHistoryFiles(root, host);
21270
+ files.control(() => {
21271
+ const previous = files.listRaw(host).find((raw2) => raw2.sessionId === sessionId);
21272
+ if (!previous && files.rawWarnings.length) return;
21273
+ const session = buildSession(host, capture, previous);
21274
+ if (!session || !session.branches.length) return;
21275
+ const raw = indexHistory(session, previous, host);
21276
+ if (isDeepStrictEqual3(raw, previous)) return;
21277
+ files.saveRaw(raw);
21278
+ });
21021
21279
  }
21022
21280
 
21023
- // src/extension/cli/commands/setup.ts
21024
- init_paths();
21281
+ // src/extension/hosts/plugin-runtime.ts
21282
+ init_summary_runner();
21283
+ init_workspace_config2();
21025
21284
 
21026
- // src/integrations/installation/pi-setup.ts
21027
- import { access as access2, readFile as readFile8, realpath as realpath6 } from "node:fs/promises";
21028
- import { constants as constants4, existsSync as existsSync3 } from "node:fs";
21029
- import { dirname as dirname8, join as join23, resolve as resolve11 } from "node:path";
21030
- import { homedir as homedir4 } from "node:os";
21031
- import { fileURLToPath as fileURLToPath2 } from "node:url";
21285
+ // src/services/workspace/workspace-preparation.ts
21286
+ init_validation();
21032
21287
  init_paths();
21033
-
21034
- // src/integrations/installation/processes.ts
21035
- import { spawn as spawn2 } from "node:child_process";
21036
- import { access, realpath as realpath5, stat as stat5 } from "node:fs/promises";
21037
- import { constants as constants3 } from "node:fs";
21038
- import { delimiter as delimiter2, isAbsolute as isAbsolute5, join as join22, resolve as resolve10 } from "node:path";
21039
- async function findExecutable(name, env = process.env) {
21040
- const directories2 = (env.PATH ?? "").split(delimiter2).filter(Boolean);
21041
- for (const directory of directories2) {
21042
- const path = resolve10(directory, name);
21043
- if (name === "pi" && path.split(/[\\/]/).includes("_npx")) continue;
21044
- try {
21045
- await access(path, constants3.X_OK);
21046
- if (!(await stat5(path)).isFile()) continue;
21047
- const target = await realpath5(path);
21048
- if (name === "pi" && target.split(/[\\/]/).includes("_npx")) continue;
21049
- return path;
21050
- } catch (error) {
21051
- if (!["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? "")) throw error;
21052
- }
21053
- }
21054
- return void 0;
21288
+ init_workspace_config2();
21289
+ import { lstat as lstat2, mkdir as mkdir4, readFile as readFile9, writeFile as writeFile2 } from "node:fs/promises";
21290
+ import { join as join22 } from "node:path";
21291
+ async function initializeWorkspace(root) {
21292
+ const configuration = await readWorkspaceConfig(root);
21293
+ if (configuration.error) throw new Error(configuration.error);
21294
+ await prepareWorkspace(root);
21295
+ await initializeWorkspaceConfig(root);
21055
21296
  }
21056
- var SetupProcesses = class {
21057
- constructor(signal, env = process.env) {
21058
- this.signal = signal;
21059
- this.env = env;
21060
- }
21061
- async run(command, args, cwd, options = {}) {
21062
- this.signal.throwIfAborted();
21063
- if (!isAbsolute5(cwd)) throw new Error("\u8FDB\u7A0B\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84\u3002");
21064
- const interactive = options.interactive ?? false;
21065
- const timeoutMs = options.timeoutMs ?? (interactive ? 15 * 6e4 : 6e4);
21066
- return new Promise((resolveResult, reject) => {
21067
- const child = spawn2(command, args, {
21068
- cwd,
21069
- env: this.env,
21070
- shell: false,
21071
- detached: !interactive,
21072
- stdio: interactive ? "inherit" : ["pipe", "pipe", "pipe"]
21073
- });
21074
- const stdout = [], stderr = [];
21075
- let bytes = 0, failure, escalation;
21076
- const kill = (signal) => {
21077
- if (!child.pid) return;
21078
- try {
21079
- if (interactive) child.kill(signal);
21080
- else process.kill(-child.pid, signal);
21081
- } catch {
21082
- }
21083
- };
21084
- const stop = (reason) => {
21085
- if (failure) return;
21086
- failure = reason;
21087
- kill("SIGTERM");
21088
- escalation = setTimeout(() => kill("SIGKILL"), 2e3);
21089
- };
21090
- const cancel = () => stop(new Error("\u5B89\u88C5\u5DF2\u53D6\u6D88\u3002"));
21091
- const timer = timeoutMs > 0 ? setTimeout(() => stop(new Error(`\u547D\u4EE4\u8D85\u65F6\uFF1A${command}`)), timeoutMs) : void 0;
21092
- this.signal.addEventListener("abort", cancel, { once: true });
21093
- const collect = (chunks) => (chunk) => {
21094
- bytes += chunk.length;
21095
- if (bytes > 2 * 1024 * 1024) stop(new Error(`\u547D\u4EE4\u8F93\u51FA\u8D85\u8FC7\u9650\u5236\uFF1A${command}`));
21096
- else chunks.push(chunk);
21097
- };
21098
- child.stdout?.on("data", collect(stdout));
21099
- child.stderr?.on("data", collect(stderr));
21100
- child.stdin?.on("error", () => {
21101
- });
21102
- child.on("error", (error) => {
21103
- failure = error;
21104
- });
21105
- child.on("close", (code, exitSignal) => {
21106
- clearTimeout(timer);
21107
- clearTimeout(escalation);
21108
- this.signal.removeEventListener("abort", cancel);
21109
- if (this.signal.aborted) return reject(this.signal.reason);
21110
- if (failure) return reject(failure);
21111
- if (code !== 0) return reject(new Error(`${command} \u5931\u8D25 (${exitSignal ?? code})
21112
- ${Buffer.concat(stderr).toString("utf8").slice(-8e3)}`));
21113
- resolveResult(Buffer.concat(stdout).toString("utf8").trim());
21114
- });
21115
- child.stdin?.end(options.input);
21116
- if (this.signal.aborted) cancel();
21297
+ var directories = ["areas", "projects", "knowledge", "providers", "scratch", "agents"];
21298
+ async function prepareWorkspace(root) {
21299
+ for (const part of directories) {
21300
+ const path = join22(root, part);
21301
+ await mkdir4(path, { mode: 448 }).catch((error) => {
21302
+ if (error.code !== "EEXIST") throw error;
21117
21303
  });
21304
+ const entry = await lstat2(path);
21305
+ requireThat(entry.isDirectory() && !entry.isSymbolicLink(), "\u5DE5\u4F5C\u533A\u76EE\u5F55\u4E0D\u80FD\u4F7F\u7528\u7B26\u53F7\u94FE\u63A5\uFF1A" + path);
21118
21306
  }
21119
- };
21120
- function tmuxInstallCommand(platform, commands2, root) {
21121
- let command, args;
21122
- if (platform === "darwin") {
21123
- command = commands2.get("brew");
21124
- args = ["install", "tmux"];
21125
- } else {
21126
- const manager = ["apt-get", "dnf", "pacman", "zypper", "apk"].find((name) => commands2.has(name));
21127
- command = manager ? commands2.get(manager) : void 0;
21128
- args = manager === "apt-get" ? ["install", "-y", "tmux"] : manager === "dnf" ? ["install", "-y", "tmux"] : manager === "pacman" ? ["-S", "--needed", "--noconfirm", "tmux"] : manager === "zypper" ? ["--non-interactive", "install", "tmux"] : ["add", "tmux"];
21129
- if (command && !root) {
21130
- const sudo = commands2.get("sudo");
21131
- if (!sudo) throw new Error("\u5B89\u88C5 tmux \u9700\u8981\u7BA1\u7406\u5458\u6743\u9650\uFF1B\u8BF7\u624B\u52A8\u5B89\u88C5 tmux \u540E\u91CD\u65B0\u8FD0\u884C setup\u3002");
21132
- return { command: sudo, args: [command, ...args] };
21133
- }
21134
- }
21135
- if (!command) throw new Error(platform === "darwin" ? "\u672A\u627E\u5230 Homebrew\u3002\u8BF7\u5148\u901A\u8FC7\u73B0\u6709\u73AF\u5883\u5B89\u88C5 tmux\uFF0C\u518D\u8FD0\u884C setup\u3002" : "\u672A\u627E\u5230\u652F\u6301\u7684\u7CFB\u7EDF\u5305\u7BA1\u7406\u5668\u3002\u8BF7\u624B\u52A8\u5B89\u88C5 tmux\uFF0C\u518D\u8FD0\u884C setup\u3002");
21136
- return { command, args };
21137
- }
21138
- async function inspectSystem(processes, cwd) {
21139
- if (!["linux", "darwin"].includes(process.platform)) throw new Error("setup \u652F\u6301 Linux \u548C macOS\uFF1BWindows \u8BF7\u4F7F\u7528 WSL\u3002");
21140
- const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
21141
- if (major < 22 || major === 22 && minor < 19) throw new Error("\u9700\u8981 Node.js 22.19 \u6216\u66F4\u9AD8\u7248\u672C\u3002");
21142
- const npm = await findExecutable("npm", processes.env);
21143
- if (!npm) throw new Error("\u672A\u627E\u5230 npm\u3002\u8BF7\u5148\u5B89\u88C5 Node.js/npm\u3002");
21144
- const tmux = await findExecutable("tmux", processes.env);
21145
- if (tmux) {
21146
- await processes.run(tmux, ["-V"], cwd);
21147
- return { npm };
21148
- }
21149
- const names = process.platform === "darwin" ? ["brew"] : ["apt-get", "dnf", "pacman", "zypper", "apk", "sudo"];
21150
- const entries = await Promise.all(names.map(async (name) => [name, await findExecutable(name, processes.env)]));
21151
- const commands2 = new Map(entries.filter((entry) => entry[1] !== void 0));
21152
- return { npm, tmux: tmuxInstallCommand(process.platform, commands2, process.getuid?.() === 0) };
21153
- }
21154
- function npmGlobalBinary(prefix) {
21155
- return join22(prefix, "bin", "pi");
21307
+ const agents = await readFile9(join22(resourceRoot, "templates/workspace-agents.md"), "utf8");
21308
+ await writeFile2(join22(root, "AGENTS.md"), agents, { flag: "wx" }).catch((error) => {
21309
+ if (error.code !== "EEXIST") throw error;
21310
+ });
21156
21311
  }
21157
21312
 
21158
- // src/integrations/installation/pi-setup.ts
21159
- var piPackageName = "@earendil-works/pi-coding-agent";
21160
- var PiBootstrapRequired = class extends Error {
21161
- };
21162
- var localBridge = fileURLToPath2(new URL("./pi-bridge.js", import.meta.url));
21163
- var bridge = existsSync3(localBridge) ? localBridge : join23(packageRoot, "lib/integrations/installation/pi-bridge.js");
21164
- var localGuard = fileURLToPath2(new URL("../../extension/setup/guard.js", import.meta.url));
21165
- var guard = existsSync3(localGuard) ? localGuard : join23(packageRoot, "lib/extension/setup/guard.js");
21166
- async function packageRoot2(command, version, env) {
21167
- const resolved = await realpath6(command);
21168
- let directory = dirname8(resolved);
21169
- while (true) {
21170
- try {
21171
- const pkg = JSON.parse(await readFile8(join23(directory, "package.json"), "utf8"));
21172
- if (pkg.name === piPackageName && pkg.version === version) return directory;
21173
- } catch (error) {
21174
- if (error.code !== "ENOENT") throw error;
21175
- }
21176
- const parent = dirname8(directory);
21177
- if (parent === directory) break;
21178
- directory = parent;
21179
- }
21180
- const roots = [join23(dirname8(dirname8(resolved)), "install"), env.PI_MANAGED_INSTALL_ROOT].filter((root) => !!root);
21181
- for (const root of roots) {
21182
- try {
21183
- const launcher = await realpath6(join23(dirname8(root), "bin/pi"));
21184
- if (launcher !== resolved) continue;
21185
- const current = (await readFile8(join23(root, "current-version"), "utf8")).trim();
21186
- if (current !== version || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(current)) continue;
21187
- const candidate = join23(root, "releases", current, "node_modules", piPackageName);
21188
- const pkg = JSON.parse(await readFile8(join23(candidate, "package.json"), "utf8"));
21189
- if (pkg.name === piPackageName && pkg.version === version) return candidate;
21190
- } catch (error) {
21191
- if (error.code !== "ENOENT") throw error;
21192
- }
21313
+ // src/services/workspace/workspace-skills.ts
21314
+ import { readdir, readFile as readFile10 } from "node:fs/promises";
21315
+ import { join as join23 } from "node:path";
21316
+ function unquoteYaml(value) {
21317
+ const trimmed = value.trim();
21318
+ if (trimmed.length >= 2 && (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'"))) {
21319
+ return trimmed.slice(1, -1).trim();
21193
21320
  }
21194
- throw new Error(`\u65E0\u6CD5\u5B9A\u4F4D ${command} \u5BF9\u5E94\u7684 Pi \u5305\u3002\u8BF7\u5148\u6309\u6B64 Pi \u7684\u539F\u751F\u5B89\u88C5\u65B9\u5F0F\u4FEE\u590D\uFF0C\u4E0D\u4F1A\u8986\u76D6\u8BE5\u547D\u4EE4\u3002`);
21195
- }
21196
- var PiSetup = class {
21197
- constructor(processes, npm, cwd) {
21198
- this.processes = processes;
21199
- this.npm = npm;
21200
- this.cwd = cwd;
21201
- }
21202
- async inspectPi(command) {
21203
- const executable = command ?? await findExecutable("pi", this.processes.env);
21204
- if (!executable) return void 0;
21205
- const version = await this.processes.run(executable, ["--version"], this.cwd);
21206
- if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(version)) throw new Error(`PATH \u4E2D\u7684 ${executable} \u4E0D\u662F\u53EF\u8BC6\u522B\u7684 Pi\u3002`);
21207
- return { command: executable, version, root: await packageRoot2(executable, version, this.processes.env) };
21208
- }
21209
- async latest(name) {
21210
- const text = await this.processes.run(this.npm, [
21211
- "view",
21212
- `${name}@latest`,
21213
- "version",
21214
- "engines",
21215
- "--json",
21216
- "--fetch-retries=0",
21217
- "--fetch-timeout=15000"
21218
- ], this.cwd);
21219
- const value = JSON.parse(text);
21220
- if (typeof value.version !== "string") throw new Error(`\u65E0\u6CD5\u53D6\u5F97 ${name} \u7684\u6700\u65B0\u7248\u672C\u3002`);
21221
- return checkStableVersion(value.version, value.engines?.node);
21222
- }
21223
- async inspectPackages(pi, workspace) {
21224
- if (!pi) {
21225
- const agentDir = this.processes.env.PI_CODING_AGENT_DIR ?? join23(this.processes.env.HOME ?? homedir4(), ".pi/agent");
21226
- for (const file of [join23(agentDir, "settings.json"), join23(workspace, ".pi/settings.json")]) {
21227
- try {
21228
- const settings2 = JSON.parse(await readFile8(file, "utf8"));
21229
- if (!settings2 || typeof settings2 !== "object" || Array.isArray(settings2)) throw new Error(`\u65E0\u6548\u7684 Pi \u914D\u7F6E\uFF1A${file}`);
21230
- const packages = settings2.packages;
21231
- if (packages !== void 0 && !Array.isArray(packages)) throw new Error(`packages \u5FC5\u987B\u662F\u6570\u7EC4\uFF1A${file}`);
21232
- if (Array.isArray(packages) && packages.length > 0) {
21233
- throw new PiBootstrapRequired(`\u5DF2\u6709\u63D2\u4EF6\u914D\u7F6E\u4F46\u672A\u627E\u5230 Pi\uFF1A${file}`);
21234
- }
21235
- } catch (error) {
21236
- if (error.code !== "ENOENT") throw error;
21321
+ return trimmed;
21322
+ }
21323
+ function parseSkillFrontmatter(content) {
21324
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
21325
+ if (!match) return void 0;
21326
+ const lines = match[1].split(/\r?\n/);
21327
+ const fields2 = {};
21328
+ for (let i = 0; i < lines.length; i++) {
21329
+ const line = lines[i];
21330
+ const pair = line.match(/^([A-Za-z0-9_-]+)\s*:\s*(.*)$/);
21331
+ if (!pair) continue;
21332
+ const key = pair[1];
21333
+ const raw = pair[2].trim();
21334
+ if (/^[>|][+-]?$/.test(raw)) {
21335
+ const folded = raw.startsWith(">");
21336
+ const block = [];
21337
+ let indent;
21338
+ while (i + 1 < lines.length) {
21339
+ const next = lines[i + 1];
21340
+ if (!next.trim()) {
21341
+ block.push("");
21342
+ i++;
21343
+ continue;
21237
21344
  }
21238
- }
21239
- return [];
21240
- }
21241
- const data = await this.processes.run(process.execPath, [bridge, "inspect", pi.root, workspace], this.cwd);
21242
- return JSON.parse(data);
21243
- }
21244
- async installTmux(command) {
21245
- await this.processes.run(command.command, command.args, this.cwd, { interactive: true });
21246
- const tmux = await findExecutable("tmux", this.processes.env);
21247
- if (!tmux) throw new Error("tmux \u5B89\u88C5\u540E\u4ECD\u4E0D\u5728 PATH \u4E2D\uFF0C\u8BF7\u4FEE\u590D PATH \u540E\u91CD\u8BD5\u3002");
21248
- await this.processes.run(tmux, ["-V"], this.cwd);
21249
- }
21250
- async ensurePi(existing, version) {
21251
- if (existing) {
21252
- if (existing.version !== version) await this.processes.run(existing.command, ["update"], this.cwd, { interactive: true });
21253
- const installed2 = await this.inspectPi(existing.command);
21254
- if (!installed2 || installed2.version !== version) throw new Error(`Pi \u5B9E\u9645\u7248\u672C ${installed2?.version ?? "\u672A\u77E5"} \u4E0E\u76EE\u6807 ${version} \u4E0D\u540C\u3002\u8BF7\u7528\u539F\u5B89\u88C5\u65B9\u5F0F\u66F4\u65B0\u540E\u91CD\u8BD5\u3002`);
21255
- return installed2;
21256
- }
21257
- const prefix = await this.processes.run(this.npm, ["prefix", "--global"], this.cwd);
21258
- if (!prefix || !prefix.startsWith("/")) throw new Error("\u65E0\u6CD5\u786E\u5B9A npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u3002");
21259
- try {
21260
- await access2(prefix, constants4.W_OK);
21261
- } catch {
21262
- throw new Error(`npm \u5168\u5C40\u76EE\u5F55\u4E0D\u53EF\u5199\uFF1A${prefix}\u3002\u8BF7\u5148\u914D\u7F6E\u5F53\u524D\u7528\u6237\u7684 npm prefix \u6216 Node.js \u7248\u672C\u7BA1\u7406\u5668\u3002`);
21263
- }
21264
- await this.processes.run(this.npm, [
21265
- "install",
21266
- "--global",
21267
- "--ignore-scripts",
21268
- "--engine-strict",
21269
- `${piPackageName}@${version}`
21270
- ], this.cwd, { interactive: true });
21271
- const installed = await this.inspectPi(npmGlobalBinary(prefix));
21272
- if (!installed || installed.version !== version) throw new Error("Pi \u5B89\u88C5\u7248\u672C\u9A8C\u8BC1\u5931\u8D25\u3002");
21273
- const onPath = await findExecutable("pi", this.processes.env);
21274
- if (!onPath || await realpath6(onPath) !== await realpath6(installed.command)) {
21275
- throw new Error(`Pi \u5DF2\u5B89\u88C5\u5230 ${installed.command}\uFF0C\u8BF7\u628A ${join23(prefix, "bin")} \u52A0\u5165 PATH \u540E\u91CD\u65B0\u8FD0\u884C setup\u3002`);
21276
- }
21277
- return installed;
21278
- }
21279
- async verifyKeptPackage(pi, workspace, choice) {
21280
- const old = choice.existing[0];
21281
- if (choice.existing.length !== 1 || !old) throw new Error("\u4FDD\u7559\u6765\u6E90\u4E0D\u53EF\u7528\u6216\u5B58\u5728\u591A\u4EFD\u6765\u6E90\uFF0C\u8BF7\u5148\u901A\u8FC7 pi config \u5904\u7406\u3002");
21282
- const current = (await this.inspectPackages(pi, workspace)).find((pkg) => pkg.source === old.source && pkg.scope === old.scope);
21283
- if (!current?.installedPath || current.name !== npmName(choice.plugin.source) || JSON.stringify(current.entry) !== JSON.stringify(old.entry)) {
21284
- throw new Error("\u4FDD\u7559\u6765\u6E90\u5DF2\u53D8\u5316\u6216\u4E0D\u53EF\u8BFB\u53D6\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C setup\u3002");
21285
- }
21286
- return current.source;
21287
- }
21288
- async installPackage(pi, workspace, choice) {
21289
- const name = npmName(choice.plugin.source);
21290
- if (!name || !choice.target) throw new Error("\u7F3A\u5C11\u76EE\u6807\u5305\u6216\u76EE\u6807\u7248\u672C\u3002");
21291
- const current = (await this.inspectPackages(pi, workspace)).filter((pkg) => pkg.name === name);
21292
- for (const old of choice.existing) {
21293
- const actual = current.find((pkg) => pkg.scope === old.scope && pkg.source === old.source);
21294
- if (!actual || JSON.stringify(actual.entry) !== JSON.stringify(old.entry)) throw new Error(`${name} \u914D\u7F6E\u5DF2\u6539\u53D8\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C setup\u3002`);
21295
- }
21296
- if (current.some((pkg) => !choice.existing.some((old) => old.scope === pkg.scope && old.source === pkg.source) && !(pkg.scope === "user" && npmName(pkg.source) && choice.existing.some((old) => old.scope === "project" && npmName(old.source))))) {
21297
- throw new Error(`${name} \u51FA\u73B0\u65B0\u7684\u6765\u6E90\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C setup\u3002`);
21298
- }
21299
- const otherSources = choice.existing.filter((pkg) => !npmName(pkg.source));
21300
- if (otherSources.length > 1 || otherSources.some((pkg) => pkg.scope === "user")) {
21301
- throw new Error("\u5B58\u5728\u4E0D\u540C\u8EAB\u4EFD\u7684\u5168\u5C40\u6765\u6E90\u6216\u591A\u4EFD\u81EA\u5B9A\u4E49\u6765\u6E90\u3002\u8BF7\u5148\u7528 pi config \u8C03\u6574\u52A0\u8F7D\u8303\u56F4\u540E\u91CD\u8BD5\u3002");
21302
- }
21303
- const globals = choice.existing.filter((pkg) => pkg.scope === "user" && npmName(pkg.source));
21304
- if (globals.length > 1 && globals.some((pkg) => pkg.filtered)) throw new Error("\u5B58\u5728\u591A\u4EFD\u5168\u5C40 npm \u8D44\u6E90\u8FC7\u6EE4\uFF0C\u8BF7\u5148\u7528 pi config \u8C03\u6574\u540E\u91CD\u8BD5\u3002");
21305
- const template = otherSources[0] ?? globals.find((pkg) => pkg.filtered);
21306
- const target = `npm:${name}@latest`;
21307
- await this.processes.run(pi.command, ["install", "--local", target], workspace, { interactive: true });
21308
- const records = await this.inspectPackages(pi, workspace);
21309
- const installed = records.find((pkg) => pkg.scope === "project" && pkg.source === target);
21310
- if (!installed?.installedPath || installed.version !== choice.target) {
21311
- throw new Error(`${name} \u5B9E\u9645\u7248\u672C ${installed?.version ?? "\u672A\u77E5"} \u4E0E\u76EE\u6807 ${choice.target} \u4E0D\u540C\uFF0C\u8BF7\u68C0\u67E5 registry \u540E\u91CD\u8BD5\u3002`);
21312
- }
21313
- if (template) {
21314
- await this.processes.run(process.execPath, [
21315
- bridge,
21316
- "replace",
21317
- pi.root,
21318
- workspace,
21319
- JSON.stringify({ old: template, target })
21320
- ], this.cwd);
21345
+ const leading = next.match(/^\s+/)?.[0].length ?? 0;
21346
+ if (leading === 0) break;
21347
+ indent ??= leading;
21348
+ block.push(next.slice(Math.min(indent, leading)).trimEnd());
21349
+ i++;
21350
+ }
21351
+ const joined = folded ? block.map((item) => item.trim()).filter(Boolean).join(" ") : block.join("\n").trim();
21352
+ fields2[key] = joined;
21353
+ } else if (raw) {
21354
+ fields2[key] = unquoteYaml(raw);
21321
21355
  }
21322
- return installed.version;
21323
21356
  }
21324
- async start(pi, workspace) {
21325
- await access2(guard, constants4.R_OK);
21326
- await this.processes.run(pi.command, ["--extension", guard, "/pbot init"], resolve11(workspace), { interactive: true, timeoutMs: 0 });
21327
- }
21328
- };
21329
-
21330
- // src/services/installation/setup-service.ts
21331
- var pbotPackage = {
21332
- id: "pbot",
21333
- label: "Personal Bot",
21334
- description: "\u5DE5\u4F5C\u533A\u4E2A\u4EBA\u52A9\u624B",
21335
- source: "npm:personal-bot",
21336
- defaultSelected: true
21337
- };
21338
- function parseCatalog(value) {
21339
- if (!Array.isArray(value)) throw new Error("\u63D2\u4EF6\u6E05\u5355\u5FC5\u987B\u662F\u6570\u7EC4\u3002");
21340
- const ids = /* @__PURE__ */ new Set(["pbot"]), names = /* @__PURE__ */ new Set(["personal-bot"]);
21341
- return value.map((item) => {
21342
- if (!item || typeof item !== "object") throw new Error("\u65E0\u6548\u63D2\u4EF6\u6E05\u5355\u9879\u3002");
21343
- const entry = item;
21344
- for (const field of ["id", "label", "description", "source"]) {
21345
- if (typeof entry[field] !== "string" || !entry[field].trim() || /[\x00-\x1f\x7f]/.test(entry[field])) {
21346
- throw new Error(`\u65E0\u6548\u63D2\u4EF6\u5B57\u6BB5\uFF1A${field}`);
21347
- }
21348
- }
21349
- const plugin = entry;
21350
- const name = npmName(plugin.source);
21351
- if (!/^[a-z0-9-]+$/.test(plugin.id) || !name || !ordinaryNpm(plugin.source) || typeof plugin.defaultSelected !== "boolean" || ids.has(plugin.id) || names.has(name)) {
21352
- throw new Error(`\u65E0\u6548\u6216\u91CD\u590D\u7684\u63D2\u4EF6\uFF1A${plugin.id}`);
21353
- }
21354
- ids.add(plugin.id);
21355
- names.add(name);
21356
- return {
21357
- id: plugin.id,
21358
- label: plugin.label,
21359
- description: plugin.description,
21360
- source: `npm:${name}`,
21361
- defaultSelected: plugin.defaultSelected
21362
- };
21363
- });
21357
+ return {
21358
+ ...fields2.name ? { name: fields2.name } : {},
21359
+ ...fields2.description ? { description: fields2.description } : {}
21360
+ };
21364
21361
  }
21365
- function packageChoices(catalog, installed) {
21366
- const first = !installed.some((pkg) => pkg.name === "personal-bot");
21367
- return [pbotPackage, ...catalog].map((plugin) => {
21368
- const matches = installed.filter((pkg) => pkg.name === npmName(plugin.source));
21369
- const localNpm = matches.some((pkg) => pkg.scope === "project" && npmName(pkg.source));
21370
- const existing = matches.filter((pkg) => !(localNpm && pkg.scope === "user" && npmName(pkg.source)));
21371
- const custom = existing.some((pkg) => !ordinaryNpm(pkg.source));
21372
- return {
21373
- plugin,
21374
- required: plugin.id === "pbot",
21375
- existing,
21376
- selected: plugin.id === "pbot" || (first ? plugin.defaultSelected : existing.length > 0),
21377
- keep: custom
21378
- };
21379
- });
21362
+ async function discoverWorkspaceSkills(root) {
21363
+ return discoverSkills(join23(root, ".agents", "skills"), ".agents/skills");
21380
21364
  }
21381
- async function executeSetup(plan, operations, report, signal) {
21382
- const results = [];
21383
- const add = (result) => {
21384
- results.push(result);
21385
- report(result);
21386
- };
21387
- let pi;
21365
+ async function discoverSkills(skillsDir, indexPath) {
21366
+ let entries;
21388
21367
  try {
21389
- signal.throwIfAborted();
21390
- if (plan.tmux) {
21391
- await operations.installTmux(plan.tmux);
21392
- add({ name: "tmux", state: "done", detail: "\u5DF2\u5B89\u88C5" });
21393
- }
21394
- signal.throwIfAborted();
21395
- pi = await operations.ensurePi(plan.pi, plan.piVersion);
21396
- add({ name: "Pi", state: "done", detail: pi.version });
21368
+ entries = await readdir(skillsDir, { withFileTypes: true });
21397
21369
  } catch (error) {
21398
- signal.throwIfAborted();
21399
- add({ name: "\u8FD0\u884C\u73AF\u5883", state: "failed", detail: String(error) });
21400
- return { results };
21370
+ if (error.code === "ENOENT") return [];
21371
+ throw error;
21401
21372
  }
21402
- for (const choice of plan.packages) {
21403
- signal.throwIfAborted();
21404
- const name = choice.plugin.label;
21405
- if (!choice.selected) {
21406
- add({ name, state: "skipped", detail: "\u672C\u6B21\u4E0D\u5904\u7406" });
21407
- continue;
21408
- }
21409
- if (choice.error) {
21410
- add({ name, state: "failed", detail: choice.error });
21411
- if (choice.required) return { results };
21412
- continue;
21413
- }
21414
- if (choice.keep) {
21415
- try {
21416
- const source = await operations.verifyKeptPackage(pi, plan.workspace, choice);
21417
- add({ name, state: "kept", detail: source });
21418
- } catch (error) {
21419
- signal.throwIfAborted();
21420
- add({ name, state: "failed", detail: String(error) });
21421
- if (choice.required) return { results };
21422
- }
21423
- continue;
21424
- }
21373
+ const results = [];
21374
+ for (const entry of entries) {
21375
+ if (entry.name.startsWith(".") || !entry.isDirectory() && !entry.isSymbolicLink()) continue;
21376
+ const filePath = join23(skillsDir, entry.name, "SKILL.md");
21377
+ let content;
21425
21378
  try {
21426
- const version = await operations.installPackage(pi, plan.workspace, choice);
21427
- add({ name, state: "done", detail: version });
21428
- } catch (error) {
21429
- signal.throwIfAborted();
21430
- add({ name, state: "failed", detail: String(error) });
21431
- if (choice.required) return { results };
21379
+ content = await readFile10(filePath, "utf8");
21380
+ } catch {
21381
+ continue;
21432
21382
  }
21383
+ const meta = parseSkillFrontmatter(content);
21384
+ if (!meta?.name || !meta.description) continue;
21385
+ results.push({
21386
+ name: meta.name,
21387
+ description: meta.description,
21388
+ path: join23(indexPath, entry.name, "SKILL.md")
21389
+ });
21433
21390
  }
21434
- return { pi, results };
21391
+ results.sort((a, b) => a.name.localeCompare(b.name));
21392
+ return results;
21435
21393
  }
21436
21394
 
21437
- // src/ui/setup.ts
21438
- import { createInterface } from "node:readline/promises";
21439
- var SetupUI = class {
21440
- constructor(controller) {
21441
- this.controller = controller;
21395
+ // src/extension/hosts/plugin-runtime.ts
21396
+ function disabledMessage(adapter, configuration) {
21397
+ return configuration.error ?? `Personal Bot \u672A\u5728\u6B64\u5DE5\u4F5C\u533A\u542F\u7528\u3002\u8FD0\u884C ${adapter.initCommandHint}\uFF1B\u914D\u7F6E\u6587\u4EF6\uFF1A${configuration.path}`;
21398
+ }
21399
+ async function pluginCommand(adapter, args, cwd) {
21400
+ const root = await adapter.resolveRoot(cwd);
21401
+ const action = args.join(" ");
21402
+ requireThat(["init", "status"].includes(action), adapter.usage);
21403
+ if (action === "init") {
21404
+ await initializeWorkspace(root);
21405
+ bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
21406
+ }
21407
+ const configuration = await readWorkspaceConfig(root);
21408
+ return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
21409
+ }
21410
+ async function runPluginHost(adapter, args, replay) {
21411
+ if (args[0] === "hook") {
21412
+ let input = "";
21413
+ process.stdin.setEncoding("utf8");
21414
+ for await (const chunk of process.stdin) input += String(chunk);
21415
+ const result = await pluginHook(adapter, JSON.parse(input), replay && ((root) => replay(root, input)));
21416
+ if (typeof result === "number") process.exitCode = result;
21417
+ else process.stdout.write(JSON.stringify(result) + "\n");
21418
+ } else {
21419
+ process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
21442
21420
  }
21443
- text(value) {
21444
- console.log(value);
21421
+ }
21422
+ async function pluginHook(adapter, payload, replay) {
21423
+ if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
21424
+ const event = adapter.parseEvent(payload);
21425
+ if (event.kind === "ignore") return adapter.formatPass(payload);
21426
+ const root = await adapter.resolveRoot(event.cwd, event.raw);
21427
+ const configuration = await readWorkspaceConfig(root);
21428
+ if (configuration.enabled && replay) {
21429
+ const code = await replay(root);
21430
+ if (code !== void 0) return code;
21445
21431
  }
21446
- async ask(label, fallback = "") {
21447
- this.controller.signal.throwIfAborted();
21448
- const reader = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
21449
- reader.on("SIGINT", () => this.controller.abort(new Error("\u5B89\u88C5\u5DF2\u53D6\u6D88\u3002")));
21450
- reader.on("close", () => {
21451
- if (!answered) this.controller.abort(new Error("\u8F93\u5165\u5DF2\u5173\u95ED\u3002"));
21452
- });
21453
- let answered = false;
21432
+ const features = workspaceFeatures(configuration);
21433
+ if (event.kind === "check-skill") {
21434
+ if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
21435
+ if (!features.skills) return adapter.formatDeny(event, `Personal Bot \u5DE5\u4F5C\u533A\u6280\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.skills: false\uFF09\u3002`);
21436
+ return adapter.formatPass(payload);
21437
+ }
21438
+ if (!configuration.enabled) return adapter.formatPass(payload);
21439
+ if (event.kind === "inject-context") bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
21440
+ if (features.history && adapter.extractHistory) {
21454
21441
  try {
21455
- const value = await reader.question(label + (fallback ? " [" + fallback + "]" : "") + ": ", { signal: this.controller.signal });
21456
- answered = true;
21457
- return value.trim() || fallback;
21458
- } finally {
21459
- answered = true;
21460
- reader.close();
21442
+ const capture = await adapter.extractHistory(event);
21443
+ if (capture) recordHistoryCapture(root, adapter.host, capture);
21444
+ } catch {
21461
21445
  }
21462
21446
  }
21463
- async confirm(label, fallback = true) {
21464
- while (true) {
21465
- const answer = (await this.ask(label + (fallback ? " [Y/n]" : " [y/N]"))).toLowerCase();
21466
- if (!answer) return fallback;
21467
- if (["y", "yes", "\u662F"].includes(answer)) return true;
21468
- if (["n", "no", "\u5426"].includes(answer)) return false;
21469
- this.text("\u8BF7\u8F93\u5165 y \u6216 n\u3002");
21470
- }
21447
+ if (event.kind === "record-history") return adapter.formatPass(payload);
21448
+ const includePrompts = features.prompts && !event.noticesOnly;
21449
+ const includeSkills = features.skills && !event.noticesOnly;
21450
+ const workspaceSkills = includeSkills && !adapter.nativeWorkspaceSkills ? await discoverWorkspaceSkills(root) : [];
21451
+ if (includeSkills && adapter.indexBundledSkills) {
21452
+ const directory = join24(resourceRoot, "skills");
21453
+ workspaceSkills.push(...await discoverSkills(directory, directory));
21471
21454
  }
21472
- async selectMany(labels, defaults) {
21473
- labels.forEach((label, index) => this.text(" " + (defaults.includes(index) ? "[x] " : "[ ] ") + (index + 1) + ". " + label));
21474
- while (true) {
21475
- const answer = await this.ask("\u9009\u62E9\u63D2\u4EF6\u7F16\u53F7\uFF08\u9017\u53F7\u5206\u9694\uFF0C\u56DE\u8F66\u4FDD\u7559\u9ED8\u8BA4\uFF0C0 \u4E0D\u9009\uFF09");
21476
- if (!answer) return defaults;
21477
- if (answer === "0") return [];
21478
- const parts = answer.split(/[,,\s]+/);
21479
- if (parts.every((part) => /^\d+$/.test(part) && Number(part) >= 1 && Number(part) <= labels.length)) {
21480
- return [...new Set(parts.map((part) => Number(part) - 1))];
21481
- }
21482
- this.text("\u8BF7\u8F93\u5165\u5217\u8868\u4E2D\u7684\u7F16\u53F7\u3002");
21455
+ const notices = event.isSessionStart && features.history ? [...historyStartupNotices(root)] : [];
21456
+ if (event.isSessionStart) {
21457
+ const drift = workspacePluginDrift(workspacePluginReleases(root));
21458
+ if (drift.outOfSync) {
21459
+ const summary = Object.entries(drift.versions).map(([host, version]) => `${host}=${version}`).join(", ");
21460
+ notices.push(`\u68C0\u6D4B\u5230\u5F53\u524D\u5DE5\u4F5C\u533A\u5404\u5BBF\u4E3B Personal Bot \u63D2\u4EF6\u7248\u672C\u4E0D\u4E00\u81F4\uFF08${summary}\uFF09\uFF0C\u53EF\u5728\u7EC8\u7AEF\u8FD0\u884C pbot upgrade \u7EDF\u4E00\u5347\u7EA7\u3002`);
21483
21461
  }
21484
21462
  }
21485
- };
21463
+ if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
21464
+ const context = await loadWorkspaceContext({
21465
+ host: adapter.host,
21466
+ root,
21467
+ role: event.role,
21468
+ ...adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {},
21469
+ includePrompts,
21470
+ includeRootAgents: includePrompts && !adapter.nativeRootAgents,
21471
+ ...event.localRoleOnly ? { localRoleOnly: true } : {},
21472
+ workspaceSkills,
21473
+ notices
21474
+ });
21475
+ return adapter.formatContext(event, context);
21476
+ }
21486
21477
 
21487
- // src/extension/cli/commands/setup.ts
21488
- var quote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
21489
- var setupUsage = "\u7528\u6CD5\uFF1Apbot setup [--workspace <\u76EE\u5F55>]\n\u5B89\u88C5\u6216\u5347\u7EA7 Pi\u3001Personal Bot \u548C\u9009\u4E2D\u7684\u914D\u5957\u63D2\u4EF6\uFF0C\u7136\u540E\u542F\u52A8 Pi \u6267\u884C /pbot init\u3002";
21490
- var installAntigravityUsage = "\u7528\u6CD5\uFF1Apbot install-antigravity\n\u901A\u8FC7\u539F\u751F agy plugin install \u5B89\u88C5\u6216\u66F4\u65B0 Antigravity \u63D2\u4EF6\u3002";
21491
- var setupCommand = {
21492
- name: "setup",
21493
- summary: "\u4EA4\u4E92\u5F0F\u5B89\u88C5\u6216\u5347\u7EA7 Pi \u4E0E\u5DE5\u4F5C\u533A\u63D2\u4EF6",
21494
- usage: setupUsage,
21495
- updatePolicy: "none",
21496
- supportsWorkspaceFlag: true,
21497
- async run(ctx) {
21498
- requireNoExtraArgs(ctx.args, setupUsage);
21499
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
21500
- throw new CliError("setup \u9700\u8981\u4EA4\u4E92\u7EC8\u7AEF\u3002\u8BF7\u5728\u7EC8\u7AEF\u8FD0\u884C npx personal-bot@latest setup\u3002", 2);
21501
- }
21502
- const outcome = await withSignals(
21503
- async (controller) => {
21504
- const ui = new SetupUI(controller);
21505
- const processes = new SetupProcesses(controller.signal);
21506
- const cwd = ctx.cwd;
21507
- ui.text("Personal Bot " + packageVersion + " \u2014 \u5B89\u88C5\u4E0E\u5347\u7EA7\n\u6B63\u5728\u68C0\u67E5 Node/npm \u548C tmux\u2026");
21508
- const system = await inspectSystem(processes, cwd);
21509
- const supplied = ctx.workspace ?? await ui.ask("\u5DE5\u4F5C\u533A\u76EE\u5F55\uFF08\u5F53\u524D\u3001\u5DF2\u6709\u6216\u65B0\u5EFA\u76EE\u5F55\uFF09", cwd);
21510
- const workspace = await resolveCliWorkspace(supplied, cwd);
21511
- const host = new PiSetup(processes, system.npm, cwd);
21512
- let pi = await host.inspectPi();
21513
- let installed;
21514
- try {
21515
- installed = await host.inspectPackages(pi, workspace);
21516
- } catch (error) {
21517
- if (!(error instanceof PiBootstrapRequired)) throw error;
21518
- const version = await host.latest(piPackageName);
21519
- ui.text(error.message + "\n\u9700\u5148\u5B89\u88C5 Pi \u624D\u80FD\u4F7F\u7528\u5176\u539F\u751F\u63A5\u53E3\u6838\u5BF9\u8FD9\u4E9B\u6765\u6E90\u3002\u76EE\u6807\u7248\u672C\uFF1A" + version);
21520
- if (!await ui.confirm("\u5148\u901A\u8FC7 npm \u5B89\u88C5 Pi\uFF0C\u518D\u7EE7\u7EED\u9009\u62E9\u5DE5\u4F5C\u533A\u63D2\u4EF6")) return 130;
21521
- pi = await host.ensurePi(void 0, version);
21522
- installed = await host.inspectPackages(pi, workspace);
21523
- }
21524
- const catalog = parseCatalog(JSON.parse(await readFile9(join24(packageRoot, "resources/installer/plugins.json"), "utf8")));
21525
- const choices = packageChoices(catalog, installed);
21526
- const optional2 = choices.filter((choice) => !choice.required);
21527
- ui.text("\nPersonal Bot \u5FC5\u88C5\u3002\u9009\u62E9\u914D\u5957\u63D2\u4EF6\uFF08\u53D6\u6D88\u52FE\u9009\u4E0D\u4F1A\u5378\u8F7D\u5DF2\u6709\u63D2\u4EF6\uFF09\uFF1A");
21528
- const selected = await ui.selectMany(
21529
- optional2.map((choice) => choice.plugin.label + " \u2014 " + choice.plugin.description),
21530
- optional2.flatMap((choice, index) => choice.selected ? [index] : [])
21531
- );
21532
- optional2.forEach((choice, index) => {
21533
- choice.selected = selected.includes(index);
21534
- });
21535
- for (const choice of choices.filter((item) => item.selected)) {
21536
- if (choice.existing.some((pkg) => !ordinaryNpm(pkg.source))) {
21537
- ui.text("\n" + choice.plugin.label + " \u7684\u5DF2\u6709\u6765\u6E90\uFF1A\n" + choice.existing.map((pkg) => " " + pkg.scope + ": " + pkg.source + " (" + (pkg.version ?? "\u7248\u672C\u672A\u77E5") + ")").join("\n"));
21538
- choice.keep = !await ui.confirm("\u5207\u6362\u5230 npm \u6700\u65B0\u7A33\u5B9A\u7248", false);
21539
- }
21540
- if (choice.keep) {
21541
- if (choice.existing.length !== 1 || !choice.existing[0]?.installedPath) {
21542
- choice.error = "\u4FDD\u7559\u6765\u6E90\u672A\u5B89\u88C5\u6216\u5B58\u5728\u591A\u4EFD\u6765\u6E90\uFF0C\u8BF7\u5148\u901A\u8FC7 Pi \u539F\u751F\u914D\u7F6E\u5904\u7406\u3002";
21543
- }
21544
- } else {
21545
- const others = choice.existing.filter((pkg) => !npmName(pkg.source));
21546
- if (others.length > 1 || others.some((pkg) => pkg.scope === "user")) {
21547
- choice.error = "\u8BF7\u5148\u7528 pi config \u8C03\u6574\u5168\u5C40\u6216\u91CD\u590D\u6765\u6E90\u7684\u52A0\u8F7D\u8303\u56F4\uFF0C\u518D\u5207\u6362\u5230 npm\u3002";
21548
- } else {
21549
- try {
21550
- choice.target = await host.latest(npmName(choice.plugin.source));
21551
- } catch (error) {
21552
- controller.signal.throwIfAborted();
21553
- choice.error = String(error);
21554
- }
21555
- }
21556
- }
21557
- }
21558
- const plan = {
21559
- workspace,
21560
- piVersion: await host.latest(piPackageName),
21561
- packages: choices,
21562
- ...pi ? { pi } : {},
21563
- ...system.tmux ? { tmux: system.tmux } : {}
21564
- };
21565
- ui.text("\n\u5B89\u88C5\u8BA1\u5212\n\u5DE5\u4F5C\u533A\uFF1A" + workspace + "\nPi\uFF1A" + (pi ? pi.command + " (" + pi.version + ")" : "\u901A\u8FC7 npm \u5168\u5C40\u5B89\u88C5") + " \u2192 " + plan.piVersion);
21566
- if (system.tmux) ui.text("tmux\uFF1A" + [system.tmux.command, ...system.tmux.args].map(quote).join(" "));
21567
- for (const choice of choices) {
21568
- ui.text(" " + choice.plugin.label + ": " + (!choice.selected ? "\u672C\u6B21\u8DF3\u8FC7" : choice.error ?? (choice.keep ? "\u4FDD\u7559 " + choice.existing[0]?.source : (choice.existing.map((pkg) => pkg.version ?? "\u672A\u77E5").join(", ") || "\u672A\u5B89\u88C5") + " \u2192 " + choice.target)));
21569
- if (choice.selected && choice.existing.some((pkg) => pkg.filtered)) {
21570
- ui.text(" \u4FDD\u7559\u5DF2\u6709\u8D44\u6E90\u8FC7\u6EE4\uFF1B\u5982 pbot \u88AB\u7981\u7528\uFF0C\u8BF7\u901A\u8FC7 pi config --local \u542F\u7528\u3002");
21571
- }
21572
- }
21573
- const blocking = choices.find((choice) => choice.required && choice.error);
21574
- if (blocking) throw new Error(blocking.error);
21575
- ui.text("\u5347\u7EA7\u524D\u8BF7\u505C\u6B62\u6D3B\u52A8 pbot \u5B50\u4F1A\u8BDD\u3002Pi \u4E3A\u5F53\u524D\u7528\u6237\u5171\u7528\uFF0C\u63D2\u4EF6\u53EA\u5904\u7406\u6B64\u5DE5\u4F5C\u533A\u3002");
21576
- if (!await ui.confirm("\u6267\u884C\u4EE5\u4E0A\u8BA1\u5212")) return 130;
21577
- await mkdir5(workspace, { recursive: true });
21578
- if (await realpath7(workspace) !== workspace) throw new Error("\u5DE5\u4F5C\u533A\u8DEF\u5F84\u5DF2\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C setup\u3002");
21579
- const result = await executeSetup(plan, host, (item) => ui.text("[" + item.state + "] " + item.name + ": " + item.detail), controller.signal);
21580
- const failed = result.results.some((item) => item.state === "failed");
21581
- if (!result.pi) return 1;
21582
- ui.text("\n\u8F6F\u4EF6\u5B89\u88C5\u9636\u6BB5\u7ED3\u675F\u3002\u5DE5\u4F5C\u533A\u521D\u59CB\u5316\u548C\u5916\u90E8\u670D\u52A1\u7684\u72B6\u6001\u7531 Pi/pbot/\u63D2\u4EF6\u5206\u522B\u62A5\u544A\u3002");
21583
- if (await ui.confirm(failed ? "\u90E8\u5206\u63D2\u4EF6\u5931\u8D25\uFF0C\u662F\u5426\u4ECD\u542F\u52A8 Pi \u5E76\u521D\u59CB\u5316\u542F\u7528\u5DE5\u4F5C\u533A" : "\u542F\u52A8 Pi \u5E76\u521D\u59CB\u5316\u542F\u7528\u5DE5\u4F5C\u533A", !failed)) {
21584
- process.stdin.pause();
21585
- await host.start(result.pi, workspace);
21586
- } else {
21587
- ui.text("\u7A0D\u540E\u6267\u884C\uFF1A\ncd " + quote(workspace) + "\n" + quote(result.pi.command) + " --extension " + quote(join24(packageRoot, "lib/extension/setup/guard.js")) + " '/pbot init'");
21588
- }
21589
- return failed ? 1 : 0;
21590
- },
21591
- () => console.error("\u5B89\u88C5\u5DF2\u53D6\u6D88\uFF1B\u5DF2\u5B8C\u6210\u7684\u6B65\u9AA4\u4FDD\u7559\u3002")
21592
- );
21593
- return outcome.ok ? outcome.value : outcome.exitCode;
21594
- }
21595
- };
21596
- var installAntigravityCommand = {
21597
- name: "install-antigravity",
21598
- summary: "\u5B89\u88C5\u6216\u66F4\u65B0 Antigravity \u63D2\u4EF6",
21599
- usage: installAntigravityUsage,
21600
- updatePolicy: "none",
21601
- async run(ctx) {
21602
- requireNoExtraArgs(ctx.args, installAntigravityUsage);
21603
- const pluginDir = join24(packageRoot, "lib/antigravity-plugin");
21604
- if (!existsSync4(join24(pluginDir, "plugin.json"))) {
21605
- console.error("\u7F3A\u5C11 Antigravity \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A" + pluginDir + "\u3002\u8BF7\u5148\u8FD0\u884C npm run build\u3002");
21606
- return 1;
21607
- }
21608
- const agy = process.env.PBOT_AGY_COMMAND || await findExecutable("agy", process.env);
21609
- if (!agy) {
21610
- console.error("\u672A\u627E\u5230 Antigravity CLI\uFF08agy\uFF09\u3002\u8BF7\u5148\u5B89\u88C5 agy\uFF0C\u7136\u540E\u8FD0\u884C\uFF1A\n agy plugin install " + quote(pluginDir));
21611
- return 1;
21612
- }
21613
- const installed = spawnSync3(agy, ["plugin", "install", pluginDir], { stdio: "inherit" });
21614
- if (installed.error) {
21615
- console.error(String(installed.error));
21616
- return 1;
21617
- }
21618
- if (installed.status !== 0) return installed.status ?? 1;
21619
- console.log("Antigravity \u63D2\u4EF6\u5DF2\u5B89\u88C5\u3002\u5728\u76EE\u6807\u5DE5\u4F5C\u533A\u8FD0\u884C /pbot init \u542F\u7528 Personal Bot\u3002");
21620
- return 0;
21478
+ // src/extension/cli/commands/plugin.ts
21479
+ function pluginUsage() {
21480
+ return `\u7528\u6CD5\uFF1Apbot plugin <${listPluginHosts().join("|")}> hook|init|status
21481
+ \u8FD0\u884C\u63D2\u4EF6\u5BBF\u4E3B\u547D\u4EE4\u6216\u65E0\u72B6\u6001 hook\u3002`;
21482
+ }
21483
+ var pluginCommand2 = {
21484
+ name: "plugin",
21485
+ summary: "\u8FD0\u884C\u63D2\u4EF6\u5BBF\u4E3B\u547D\u4EE4\uFF08hook / init / status\uFF09",
21486
+ get usage() {
21487
+ return pluginUsage();
21488
+ },
21489
+ updatePolicy: (ctx) => ctx.args[1] === "hook" ? "hook" : "workspace",
21490
+ allowUninitializedUpdate: (ctx) => ctx.args[1] === "init" && ctx.args.length === 2,
21491
+ async resolveWorkspaceRoot(ctx) {
21492
+ const host = ctx.args[0];
21493
+ const resolved = host ? await getPluginHost(host)?.resolveRoot(ctx.cwd) : void 0;
21494
+ return resolveCliWorkspace(resolved ?? ctx.cwd, ctx.cwd);
21495
+ },
21496
+ async run(ctx, helpers) {
21497
+ const [host, ...rest] = ctx.args;
21498
+ const adapter = host ? pluginHosts.get(host) : void 0;
21499
+ requireThat(adapter, pluginUsage());
21500
+ const previousCode = process.exitCode;
21501
+ process.exitCode = void 0;
21502
+ await runPluginHost(adapter, rest, (root, input) => helpers.updateForWorkspace(root, ctx.rawArgs, input));
21503
+ const exitCode = typeof process.exitCode === "number" ? process.exitCode : 0;
21504
+ process.exitCode = previousCode;
21505
+ return exitCode;
21621
21506
  }
21622
21507
  };
21623
21508
 
21624
21509
  // src/extension/cli/commands/upgrade.ts
21625
- var import_semver10 = __toESM(require_semver2(), 1);
21510
+ var import_semver13 = __toESM(require_semver2(), 1);
21626
21511
  init_json();
21627
- import { readFile as readFile14 } from "node:fs/promises";
21512
+ import { readFile as readFile15 } from "node:fs/promises";
21628
21513
  import { join as join29 } from "node:path";
21514
+
21515
+ // src/common/package-source.ts
21516
+ var import_semver5 = __toESM(require_semver2(), 1);
21517
+ function npmName(source) {
21518
+ return /^npm:((?:@[a-z0-9._-]+\/)?[a-z0-9._-]+)(?:@[^\s]+)?$/.exec(source)?.[1];
21519
+ }
21520
+ function checkStableVersion(version, nodeRange) {
21521
+ if (!(0, import_semver5.valid)(version) || (0, import_semver5.prerelease)(version)) throw new Error(`latest \u4E0D\u662F\u7A33\u5B9A\u7248\u672C\uFF1A${version}`);
21522
+ if (nodeRange && !(0, import_semver5.satisfies)(process.versions.node, nodeRange)) {
21523
+ throw new Error(`\u76EE\u6807\u7248\u672C\u8981\u6C42 Node.js ${nodeRange}\uFF0C\u5F53\u524D\u4E3A ${process.versions.node}\u3002\u8BF7\u5148\u5347\u7EA7 Node.js\u3002`);
21524
+ }
21525
+ return version;
21526
+ }
21527
+
21528
+ // src/extension/cli/commands/upgrade.ts
21629
21529
  init_paths();
21630
21530
 
21631
21531
  // src/integrations/installation/upgraders/registry.ts
21632
21532
  init_validation();
21633
21533
 
21634
21534
  // src/integrations/installation/upgraders/antigravity.ts
21635
- var import_semver3 = __toESM(require_semver2(), 1);
21535
+ var import_semver6 = __toESM(require_semver2(), 1);
21636
21536
  init_json();
21637
- import { readFile as readFile10 } from "node:fs/promises";
21537
+ import { readFile as readFile11 } from "node:fs/promises";
21638
21538
  import { join as join25 } from "node:path";
21639
- async function readManifestVersion(path) {
21539
+ async function readManifestVersion4(path) {
21640
21540
  try {
21641
- const data = JSON.parse(await readFile10(path, "utf8"));
21642
- return object(data) && typeof data.version === "string" && (0, import_semver3.valid)(data.version) ? data.version : void 0;
21541
+ const data = JSON.parse(await readFile11(path, "utf8"));
21542
+ return object(data) && typeof data.version === "string" && (0, import_semver6.valid)(data.version) ? data.version : void 0;
21643
21543
  } catch (error) {
21644
21544
  if (error.code === "ENOENT") return void 0;
21645
21545
  throw error;
@@ -21648,7 +21548,7 @@ async function readManifestVersion(path) {
21648
21548
  var antigravityUpgrader = {
21649
21549
  host: "antigravity",
21650
21550
  async upgrade(context) {
21651
- if (context.currentVersion && (0, import_semver3.valid)(context.currentVersion) && (0, import_semver3.gte)(context.currentVersion, context.targetVersion)) {
21551
+ if (context.currentVersion && (0, import_semver6.valid)(context.currentVersion) && (0, import_semver6.gte)(context.currentVersion, context.targetVersion)) {
21652
21552
  return {
21653
21553
  host: this.host,
21654
21554
  state: "up-to-date",
@@ -21659,7 +21559,7 @@ var antigravityUpgrader = {
21659
21559
  };
21660
21560
  }
21661
21561
  const pluginDir = join25(context.packageRoot, "lib", "antigravity-plugin");
21662
- const bundledVersion = await readManifestVersion(join25(pluginDir, "plugin.json"));
21562
+ const bundledVersion = await readManifestVersion4(join25(pluginDir, "plugin.json"));
21663
21563
  if (!bundledVersion) {
21664
21564
  return {
21665
21565
  host: this.host,
@@ -21668,7 +21568,7 @@ var antigravityUpgrader = {
21668
21568
  detail: `\u7F3A\u5C11 Antigravity \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${pluginDir}`
21669
21569
  };
21670
21570
  }
21671
- if ((0, import_semver3.lt)(bundledVersion, context.targetVersion)) {
21571
+ if ((0, import_semver6.lt)(bundledVersion, context.targetVersion)) {
21672
21572
  return {
21673
21573
  host: this.host,
21674
21574
  state: "skipped",
@@ -21699,9 +21599,9 @@ var antigravityUpgrader = {
21699
21599
  };
21700
21600
 
21701
21601
  // src/integrations/installation/upgraders/claude.ts
21702
- var import_semver4 = __toESM(require_semver2(), 1);
21602
+ var import_semver7 = __toESM(require_semver2(), 1);
21703
21603
  init_json();
21704
- import { realpath as realpath8 } from "node:fs/promises";
21604
+ import { realpath as realpath6 } from "node:fs/promises";
21705
21605
  function parsePluginList(raw) {
21706
21606
  const parsed = JSON.parse(raw);
21707
21607
  const items = Array.isArray(parsed) ? parsed : object(parsed) && Array.isArray(parsed.plugins) ? parsed.plugins : [];
@@ -21721,7 +21621,7 @@ function parsePluginList(raw) {
21721
21621
  }
21722
21622
  async function resolvePathSafe(value) {
21723
21623
  try {
21724
- return await realpath8(value);
21624
+ return await realpath6(value);
21725
21625
  } catch {
21726
21626
  return value;
21727
21627
  }
@@ -21777,7 +21677,7 @@ var claudeUpgrader = {
21777
21677
  }
21778
21678
  const installedVersion = entry.version ?? context.currentVersion;
21779
21679
  const scope = entry.scope ?? "user";
21780
- if (installedVersion && (0, import_semver4.valid)(installedVersion) && (0, import_semver4.gte)(installedVersion, context.targetVersion)) {
21680
+ if (installedVersion && (0, import_semver7.valid)(installedVersion) && (0, import_semver7.gte)(installedVersion, context.targetVersion)) {
21781
21681
  return {
21782
21682
  host: this.host,
21783
21683
  state: "up-to-date",
@@ -21811,14 +21711,14 @@ var claudeUpgrader = {
21811
21711
  };
21812
21712
 
21813
21713
  // src/integrations/installation/upgraders/codex.ts
21814
- var import_semver5 = __toESM(require_semver2(), 1);
21714
+ var import_semver8 = __toESM(require_semver2(), 1);
21815
21715
  init_json();
21816
- import { readFile as readFile11 } from "node:fs/promises";
21716
+ import { readFile as readFile12 } from "node:fs/promises";
21817
21717
  import { join as join26 } from "node:path";
21818
- async function readManifestVersion2(path) {
21718
+ async function readManifestVersion5(path) {
21819
21719
  try {
21820
- const data = JSON.parse(await readFile11(path, "utf8"));
21821
- return object(data) && typeof data.version === "string" && (0, import_semver5.valid)(data.version) ? data.version : void 0;
21720
+ const data = JSON.parse(await readFile12(path, "utf8"));
21721
+ return object(data) && typeof data.version === "string" && (0, import_semver8.valid)(data.version) ? data.version : void 0;
21822
21722
  } catch (error) {
21823
21723
  if (error.code === "ENOENT") return void 0;
21824
21724
  throw error;
@@ -21827,7 +21727,7 @@ async function readManifestVersion2(path) {
21827
21727
  var codexUpgrader = {
21828
21728
  host: "codex",
21829
21729
  async upgrade(context) {
21830
- if (context.currentVersion && (0, import_semver5.valid)(context.currentVersion) && (0, import_semver5.gte)(context.currentVersion, context.targetVersion)) {
21730
+ if (context.currentVersion && (0, import_semver8.valid)(context.currentVersion) && (0, import_semver8.gte)(context.currentVersion, context.targetVersion)) {
21831
21731
  return {
21832
21732
  host: this.host,
21833
21733
  state: "up-to-date",
@@ -21838,7 +21738,7 @@ var codexUpgrader = {
21838
21738
  };
21839
21739
  }
21840
21740
  const marketplaceDir = join26(context.packageRoot, "lib", "codex-marketplace");
21841
- const bundledVersion = await readManifestVersion2(join26(marketplaceDir, "plugins", "personal-bot", ".codex-plugin", "plugin.json"));
21741
+ const bundledVersion = await readManifestVersion5(join26(marketplaceDir, "plugins", "personal-bot", ".codex-plugin", "plugin.json"));
21842
21742
  if (!bundledVersion) {
21843
21743
  return {
21844
21744
  host: this.host,
@@ -21847,7 +21747,7 @@ var codexUpgrader = {
21847
21747
  detail: `\u7F3A\u5C11 Codex \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${marketplaceDir}`
21848
21748
  };
21849
21749
  }
21850
- if ((0, import_semver5.lt)(bundledVersion, context.targetVersion)) {
21750
+ if ((0, import_semver8.lt)(bundledVersion, context.targetVersion)) {
21851
21751
  return {
21852
21752
  host: this.host,
21853
21753
  state: "skipped",
@@ -21882,7 +21782,7 @@ var codexUpgrader = {
21882
21782
  };
21883
21783
 
21884
21784
  // src/integrations/installation/upgraders/dsh.ts
21885
- var import_semver6 = __toESM(require_semver2(), 1);
21785
+ var import_semver9 = __toESM(require_semver2(), 1);
21886
21786
  function inferDshProfile(bindingPath) {
21887
21787
  if (!bindingPath) return void 0;
21888
21788
  const normalized = bindingPath.replaceAll("\\", "/");
@@ -21892,7 +21792,7 @@ function inferDshProfile(bindingPath) {
21892
21792
  var dshUpgrader = {
21893
21793
  host: "dsh",
21894
21794
  async upgrade(context) {
21895
- if (context.currentVersion && (0, import_semver6.valid)(context.currentVersion) && (0, import_semver6.gte)(context.currentVersion, context.targetVersion)) {
21795
+ if (context.currentVersion && (0, import_semver9.valid)(context.currentVersion) && (0, import_semver9.gte)(context.currentVersion, context.targetVersion)) {
21896
21796
  return {
21897
21797
  host: this.host,
21898
21798
  state: "up-to-date",
@@ -21944,9 +21844,9 @@ var dshUpgrader = {
21944
21844
  };
21945
21845
 
21946
21846
  // src/integrations/installation/upgraders/pi.ts
21947
- var import_semver7 = __toESM(require_semver2(), 1);
21847
+ var import_semver10 = __toESM(require_semver2(), 1);
21948
21848
  init_json();
21949
- import { readFile as readFile12 } from "node:fs/promises";
21849
+ import { readFile as readFile13 } from "node:fs/promises";
21950
21850
  import { join as join27 } from "node:path";
21951
21851
  function packageSource(entry) {
21952
21852
  if (typeof entry === "string") return entry;
@@ -21956,7 +21856,7 @@ function packageSource(entry) {
21956
21856
  async function hasCustomOnlySource(workspace) {
21957
21857
  const settingsPath = join27(workspace, ".pi", "settings.json");
21958
21858
  try {
21959
- const data = JSON.parse(await readFile12(settingsPath, "utf8"));
21859
+ const data = JSON.parse(await readFile13(settingsPath, "utf8"));
21960
21860
  if (!object(data) || !Array.isArray(data.packages)) return false;
21961
21861
  const sources = data.packages.map(packageSource).filter((value) => value !== void 0);
21962
21862
  const matches = sources.filter((source) => source.includes("personal-bot"));
@@ -21970,8 +21870,8 @@ async function hasCustomOnlySource(workspace) {
21970
21870
  async function readLocalPiVersion(workspace) {
21971
21871
  const manifestPath = join27(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
21972
21872
  try {
21973
- const data = JSON.parse(await readFile12(manifestPath, "utf8"));
21974
- return object(data) && data.name === "personal-bot" && typeof data.version === "string" && (0, import_semver7.valid)(data.version) ? data.version : void 0;
21873
+ const data = JSON.parse(await readFile13(manifestPath, "utf8"));
21874
+ return object(data) && data.name === "personal-bot" && typeof data.version === "string" && (0, import_semver10.valid)(data.version) ? data.version : void 0;
21975
21875
  } catch (error) {
21976
21876
  if (error.code === "ENOENT") return void 0;
21977
21877
  throw error;
@@ -21981,7 +21881,7 @@ var piUpgrader = {
21981
21881
  host: "pi",
21982
21882
  async upgrade(context) {
21983
21883
  const current = await readLocalPiVersion(context.workspace) ?? context.currentVersion;
21984
- if (current && (0, import_semver7.valid)(current) && (0, import_semver7.gte)(current, context.targetVersion)) {
21884
+ if (current && (0, import_semver10.valid)(current) && (0, import_semver10.gte)(current, context.targetVersion)) {
21985
21885
  return {
21986
21886
  host: this.host,
21987
21887
  state: "up-to-date",
@@ -22025,14 +21925,14 @@ var piUpgrader = {
22025
21925
  };
22026
21926
 
22027
21927
  // src/integrations/installation/upgraders/qoder.ts
22028
- var import_semver8 = __toESM(require_semver2(), 1);
21928
+ var import_semver11 = __toESM(require_semver2(), 1);
22029
21929
  init_json();
22030
- import { readFile as readFile13 } from "node:fs/promises";
21930
+ import { readFile as readFile14 } from "node:fs/promises";
22031
21931
  import { join as join28 } from "node:path";
22032
- async function readManifestVersion3(path) {
21932
+ async function readManifestVersion6(path) {
22033
21933
  try {
22034
- const data = JSON.parse(await readFile13(path, "utf8"));
22035
- return object(data) && typeof data.version === "string" && (0, import_semver8.valid)(data.version) ? data.version : void 0;
21934
+ const data = JSON.parse(await readFile14(path, "utf8"));
21935
+ return object(data) && typeof data.version === "string" && (0, import_semver11.valid)(data.version) ? data.version : void 0;
22036
21936
  } catch (error) {
22037
21937
  if (error.code === "ENOENT") return void 0;
22038
21938
  throw error;
@@ -22041,7 +21941,7 @@ async function readManifestVersion3(path) {
22041
21941
  var qoderUpgrader = {
22042
21942
  host: "qoder",
22043
21943
  async upgrade(context) {
22044
- if (context.currentVersion && (0, import_semver8.valid)(context.currentVersion) && (0, import_semver8.gte)(context.currentVersion, context.targetVersion)) {
21944
+ if (context.currentVersion && (0, import_semver11.valid)(context.currentVersion) && (0, import_semver11.gte)(context.currentVersion, context.targetVersion)) {
22045
21945
  return {
22046
21946
  host: this.host,
22047
21947
  state: "up-to-date",
@@ -22052,7 +21952,7 @@ var qoderUpgrader = {
22052
21952
  };
22053
21953
  }
22054
21954
  const pluginDir = join28(context.packageRoot, "lib", "qoder-plugin");
22055
- const bundledVersion = await readManifestVersion3(join28(pluginDir, ".qoder-plugin", "plugin.json"));
21955
+ const bundledVersion = await readManifestVersion6(join28(pluginDir, ".qoder-plugin", "plugin.json"));
22056
21956
  if (!bundledVersion) {
22057
21957
  return {
22058
21958
  host: this.host,
@@ -22061,7 +21961,7 @@ var qoderUpgrader = {
22061
21961
  detail: `\u7F3A\u5C11 Qoder CLI \u63D2\u4EF6\u6784\u5EFA\u4EA7\u7269\uFF1A${pluginDir}`
22062
21962
  };
22063
21963
  }
22064
- if ((0, import_semver8.lt)(bundledVersion, context.targetVersion)) {
21964
+ if ((0, import_semver11.lt)(bundledVersion, context.targetVersion)) {
22065
21965
  return {
22066
21966
  host: this.host,
22067
21967
  state: "skipped",
@@ -22123,7 +22023,7 @@ var hostUpgraders = new HostUpgraderRegistry([
22123
22023
  var getHostUpgrader = (host) => hostUpgraders.get(host);
22124
22024
 
22125
22025
  // src/services/installation/upgrade-service.ts
22126
- var import_semver9 = __toESM(require_semver2(), 1);
22026
+ var import_semver12 = __toESM(require_semver2(), 1);
22127
22027
  init_validation();
22128
22028
  var upgradeUsage = "\u7528\u6CD5\uFF1Apbot upgrade|update [--workspace <\u76EE\u5F55>] [--version <MAJOR.MINOR.PATCH>] [--hosts <h1,h2>] [--dsh-profile <\u540D\u79F0>] [--json]\n\u5C06\u5168\u5C40 CLI \u4E0E\u5F53\u524D\u5DE5\u4F5C\u533A\u5DF2\u7ED1\u5B9A\u7684\u5404\u5BBF\u4E3B\u63D2\u4EF6\u7EDF\u4E00\u5347\u7EA7\u5230 npm \u6700\u65B0\u7A33\u5B9A\u7248\uFF08\u6216\u6307\u5B9A\u7248\u672C\uFF09\u3002";
22129
22029
  function parseUpgradeArgs(args) {
@@ -22149,7 +22049,7 @@ function parseUpgradeArgs(args) {
22149
22049
  requireThat(version === void 0, "--version \u53EA\u80FD\u6307\u5B9A\u4E00\u6B21\u3002");
22150
22050
  version = token === "--version" ? args[++index] : token.slice("--version=".length);
22151
22051
  requireThat(
22152
- version && (0, import_semver9.valid)(version) && /^[0-9]/.test(version) && version === version.trim(),
22052
+ version && (0, import_semver12.valid)(version) && /^[0-9]/.test(version) && version === version.trim(),
22153
22053
  "--version \u9700\u8981\u5408\u6CD5\u7684 MAJOR.MINOR.PATCH \u7248\u672C\u53F7\u3002"
22154
22054
  );
22155
22055
  continue;
@@ -22249,8 +22149,8 @@ async function discoverWorkspaceTargets(workspace, requestedHosts) {
22249
22149
  if (!byHost.has("pi")) {
22250
22150
  const localPiManifest = join29(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
22251
22151
  try {
22252
- const manifest2 = JSON.parse(await readFile14(localPiManifest, "utf8"));
22253
- if (object(manifest2) && manifest2.name === "personal-bot" && typeof manifest2.version === "string" && (0, import_semver10.valid)(manifest2.version)) {
22152
+ const manifest2 = JSON.parse(await readFile15(localPiManifest, "utf8"));
22153
+ if (object(manifest2) && manifest2.name === "personal-bot" && typeof manifest2.version === "string" && (0, import_semver13.valid)(manifest2.version)) {
22254
22154
  byHost.set("pi", { host: "pi", currentVersion: manifest2.version, bindingPath: localPiManifest });
22255
22155
  }
22256
22156
  } catch (error) {
@@ -22262,14 +22162,14 @@ async function discoverWorkspaceTargets(workspace, requestedHosts) {
22262
22162
  }
22263
22163
  return [...byHost.values()].sort((a, b) => a.host.localeCompare(b.host));
22264
22164
  }
22265
- function formatLine(result) {
22165
+ function formatLine2(result) {
22266
22166
  const transition = result.previousVersion && result.version && result.previousVersion !== result.version ? `${result.previousVersion} \u2192 ${result.version}` : result.version ?? result.previousVersion ?? "";
22267
22167
  const scope = result.scope ? ` (${result.scope})` : "";
22268
22168
  const head = `[${result.state}] ${result.host}${scope}${transition ? " " + transition : ""}: ${result.detail}`;
22269
22169
  return result.nextStep ? `${head}
22270
22170
  \u4E0B\u4E00\u6B65\uFF1A${result.nextStep}` : head;
22271
22171
  }
22272
- function printHumanSummary(summary) {
22172
+ function printHumanSummary2(summary) {
22273
22173
  console.log(`\u5DE5\u4F5C\u533A\uFF1A${summary.workspaceRoot}`);
22274
22174
  console.log(`\u76EE\u6807\u7248\u672C\uFF1A${summary.targetVersion}`);
22275
22175
  console.log(`[${summary.cli.state}] cli ${summary.cli.previousVersion} \u2192 ${summary.cli.version}: ${summary.cli.detail}`);
@@ -22277,7 +22177,7 @@ function printHumanSummary(summary) {
22277
22177
  console.log("\u5F53\u524D\u5DE5\u4F5C\u533A\u5C1A\u672A\u7ED1\u5B9A\u4EFB\u4F55\u5BBF\u4E3B\u63D2\u4EF6\u3002\u5982\u9700\u6307\u5B9A\u5BBF\u4E3B\uFF0C\u53EF\u4F20\u5165 --hosts <\u5BBF\u4E3B\u5217\u8868>\u3002");
22278
22178
  return;
22279
22179
  }
22280
- for (const result of summary.results) console.log(formatLine(result));
22180
+ for (const result of summary.results) console.log(formatLine2(result));
22281
22181
  }
22282
22182
  var upgradeCommand = {
22283
22183
  name: "upgrade",
@@ -22348,7 +22248,7 @@ var upgradeCommand = {
22348
22248
  signal: controller.signal
22349
22249
  });
22350
22250
  if (json) console.log(JSON.stringify(summary, null, 2));
22351
- else printHumanSummary(summary);
22251
+ else printHumanSummary2(summary);
22352
22252
  return summary.ok ? 0 : 1;
22353
22253
  },
22354
22254
  () => console.error("\u5347\u7EA7\u5DF2\u53D6\u6D88\u3002")
@@ -22359,7 +22259,7 @@ var upgradeCommand = {
22359
22259
 
22360
22260
  // src/extension/cli/commands/workspace.ts
22361
22261
  init_validation();
22362
- import { mkdir as mkdir6, stat as stat6 } from "node:fs/promises";
22262
+ import { mkdir as mkdir5, stat as stat6 } from "node:fs/promises";
22363
22263
  init_workspace_config2();
22364
22264
  var initUsage = "\u7528\u6CD5\uFF1Apbot init [--workspace <\u76EE\u5F55>] [--json]\n\u521D\u59CB\u5316\u5171\u4EAB\u5DE5\u4F5C\u533A\u8D44\u6599\u5E76\u542F\u7528 Personal Bot\u3002";
22365
22265
  var statusUsage = "\u7528\u6CD5\uFF1Apbot status [--workspace <\u76EE\u5F55>] [--json]\n\u67E5\u770B\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u3001CLI \u7248\u672C\u3001\u5404\u5BBF\u4E3B\u63D2\u4EF6\u7248\u672C\u3001\u540C\u6B65\u72B6\u6001\u4E0E\u914D\u7F6E\u3002";
@@ -22396,7 +22296,7 @@ var initCommand = {
22396
22296
  const root = await resolveCliWorkspace(ctx.workspace, ctx.cwd);
22397
22297
  const existing = await readWorkspaceConfig(root);
22398
22298
  if (existing.error) throw new Error(existing.error);
22399
- await mkdir6(root, { recursive: true });
22299
+ await mkdir5(root, { recursive: true });
22400
22300
  await initializeWorkspace(root);
22401
22301
  requireThat((await stat6(root)).isDirectory(), "\u5DE5\u4F5C\u533A\u5FC5\u987B\u662F\u76EE\u5F55\u3002");
22402
22302
  return reportWorkspaceStatus(root, ctx.json, true);
@@ -22424,12 +22324,11 @@ var statusCommand = {
22424
22324
  var commands = [
22425
22325
  initCommand,
22426
22326
  statusCommand,
22427
- historyCommand,
22327
+ installCommand,
22428
22328
  upgradeCommand,
22329
+ historyCommand,
22429
22330
  mcpCommand,
22430
- pluginCommand2,
22431
- setupCommand,
22432
- installAntigravityCommand
22331
+ pluginCommand2
22433
22332
  ];
22434
22333
  var commandIndex = /* @__PURE__ */ new Map();
22435
22334
  for (const command of commands) {
@@ -22497,10 +22396,10 @@ async function main(args) {
22497
22396
  try {
22498
22397
  if (args[0] === "--at-least") {
22499
22398
  const version = args[1];
22500
- if (args.length !== 2 || !version || !(0, import_semver11.valid)(version)) {
22399
+ if (args.length !== 2 || !version || !(0, import_semver14.valid)(version)) {
22501
22400
  throw new CliError("\u7528\u6CD5\uFF1Apbot --at-least <MAJOR.MINOR.PATCH>", 1);
22502
22401
  }
22503
- return (0, import_semver11.gte)(packageVersion, version) ? 0 : 1;
22402
+ return (0, import_semver14.gte)(packageVersion, version) ? 0 : 1;
22504
22403
  }
22505
22404
  if (args.length === 1 && (args[0] === "--version" || args[0] === "-v")) {
22506
22405
  console.log(packageVersion);