personal-bot 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +191 -65
- package/README.zh-CN.md +189 -63
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +3 -4
- package/docs/hosts/antigravity.md +4 -2
- package/docs/hosts/pi.md +4 -15
- package/docs/maintainers/release.md +2 -2
- package/lib/antigravity-plugin/lib/extension/cli.js +1392 -1493
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +1 -1
- package/lib/extension/cli.js +1392 -1493
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +1 -1
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
- package/package.json +1 -1
- package/src/extension/cli/commands/install.ts +77 -0
- package/src/extension/cli/index.ts +3 -4
- package/src/integrations/installation/installers/antigravity.ts +49 -0
- package/src/integrations/installation/installers/claude.ts +30 -0
- package/src/integrations/installation/installers/codex.ts +56 -0
- package/src/integrations/installation/installers/dsh.ts +25 -0
- package/src/integrations/installation/installers/pi.ts +26 -0
- package/src/integrations/installation/installers/qoder.ts +49 -0
- package/src/integrations/installation/installers/registry.ts +48 -0
- package/src/integrations/installation/processes.ts +2 -41
- package/src/model/installation.ts +28 -36
- package/src/services/installation/install-service.ts +107 -0
- package/lib/common/package-source.js +0 -16
- package/lib/extension/setup/guard.js +0 -11
- package/lib/integrations/installation/pi-bridge.js +0 -131
- package/lib/model/installation.js +0 -1
- package/resources/installer/plugins.json +0 -16
- package/src/extension/cli/commands/setup.ts +0 -159
- package/src/extension/setup/guard.ts +0 -12
- package/src/integrations/installation/pi-bridge.ts +0 -109
- package/src/integrations/installation/pi-setup.ts +0 -165
- package/src/services/installation/setup-service.ts +0 -91
- package/src/ui/setup.ts +0 -40
package/lib/extension/cli.js
CHANGED
|
@@ -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
|
|
527
|
+
var valid16 = (version, options) => {
|
|
528
528
|
const v = parse(version, options);
|
|
529
529
|
return v ? v.version : null;
|
|
530
530
|
};
|
|
531
|
-
module.exports =
|
|
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
|
|
884
|
+
var constants4 = require_constants();
|
|
885
885
|
var SemVer = require_semver();
|
|
886
886
|
var truncate = (version, truncation, options) => {
|
|
887
|
-
if (!
|
|
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
|
|
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
|
|
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:
|
|
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:
|
|
2021
|
-
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(
|
|
7921
|
-
return Span(
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
12541
|
-
this.code = optimizeExpr(this.code, names,
|
|
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,
|
|
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,
|
|
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,
|
|
12628
|
+
optimizeNames(names, constants4) {
|
|
12629
12629
|
var _a;
|
|
12630
|
-
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names,
|
|
12631
|
-
if (!(super.optimizeNames(names,
|
|
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,
|
|
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,
|
|
12657
|
-
if (!super.optimizeNames(names,
|
|
12656
|
+
optimizeNames(names, constants4) {
|
|
12657
|
+
if (!super.optimizeNames(names, constants4))
|
|
12658
12658
|
return;
|
|
12659
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
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,
|
|
12696
|
-
if (!super.optimizeNames(names,
|
|
12695
|
+
optimizeNames(names, constants4) {
|
|
12696
|
+
if (!super.optimizeNames(names, constants4))
|
|
12697
12697
|
return;
|
|
12698
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
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,
|
|
12740
|
+
optimizeNames(names, constants4) {
|
|
12741
12741
|
var _a, _b;
|
|
12742
|
-
super.optimizeNames(names,
|
|
12743
|
-
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names,
|
|
12744
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names,
|
|
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,
|
|
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 =
|
|
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 &&
|
|
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,
|
|
13449
|
+
function boolOrEmptySchema(it, valid16) {
|
|
13450
13450
|
const { gen, schema: schema2 } = it;
|
|
13451
13451
|
if (schema2 === false) {
|
|
13452
|
-
gen.var(
|
|
13452
|
+
gen.var(valid16, false);
|
|
13453
13453
|
falseSchemaError(it);
|
|
13454
13454
|
} else {
|
|
13455
|
-
gen.var(
|
|
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
|
|
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(
|
|
13842
|
+
gen.var(valid16, true);
|
|
13843
13843
|
validateItems(() => gen.break());
|
|
13844
|
-
return
|
|
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
|
-
},
|
|
13853
|
-
gen.if((0, codegen_1.not)(
|
|
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
|
|
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(
|
|
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)(
|
|
13876
|
+
gen.if((0, codegen_1.not)(valid16));
|
|
13877
13877
|
}));
|
|
13878
|
-
cxt.result(
|
|
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
|
|
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
|
-
},
|
|
13908
|
-
cxt.pass(
|
|
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
|
|
13918
|
-
cxt.block$data(
|
|
13919
|
-
cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a :
|
|
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(
|
|
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(
|
|
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 :
|
|
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
|
|
13989
|
-
if (!
|
|
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,
|
|
14449
|
+
function subschemaCode(it, valid16) {
|
|
14450
14450
|
if (isSchemaObj(it)) {
|
|
14451
14451
|
checkKeywords(it);
|
|
14452
14452
|
if (schemaCxtHasRules(it)) {
|
|
14453
|
-
subSchemaObjCode(it,
|
|
14453
|
+
subSchemaObjCode(it, valid16);
|
|
14454
14454
|
return;
|
|
14455
14455
|
}
|
|
14456
14456
|
}
|
|
14457
|
-
(0, boolSchema_1.boolOrEmptySchema)(it,
|
|
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,
|
|
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(
|
|
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(
|
|
14745
|
+
block$data(valid16, codeBlock, $dataValid = codegen_1.nil) {
|
|
14746
14746
|
this.gen.block(() => {
|
|
14747
|
-
this.check$data(
|
|
14747
|
+
this.check$data(valid16, $dataValid);
|
|
14748
14748
|
codeBlock();
|
|
14749
14749
|
});
|
|
14750
14750
|
}
|
|
14751
|
-
check$data(
|
|
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 (
|
|
14757
|
-
gen.assign(
|
|
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 (
|
|
14762
|
-
gen.assign(
|
|
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,
|
|
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,
|
|
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,
|
|
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(
|
|
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 =
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
16498
|
+
const valid16 = v(data);
|
|
16499
16499
|
if (!("$async" in v))
|
|
16500
16500
|
this.errors = v.errors;
|
|
16501
|
-
return
|
|
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
|
|
16599
|
-
if (!
|
|
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
|
|
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
|
|
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
|
-
},
|
|
17006
|
+
}, valid16);
|
|
17007
17007
|
cxt.mergeEvaluated(schCxt);
|
|
17008
|
-
cxt.ok(
|
|
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
|
|
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(
|
|
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(
|
|
17038
|
+
gen.assign(valid16, false);
|
|
17039
17039
|
});
|
|
17040
|
-
cxt.ok(
|
|
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
|
|
17246
|
-
gen.try(() => gen.assign(
|
|
17247
|
-
cxt.fail$data((0, codegen_1._)`!${
|
|
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
|
|
17339
|
-
cxt.block$data(
|
|
17340
|
-
cxt.ok(
|
|
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,
|
|
17353
|
+
function loopUntilMissing(missing, valid16) {
|
|
17354
17354
|
cxt.setParams({ missingProperty: missing });
|
|
17355
17355
|
gen.forOf(missing, schemaCode, () => {
|
|
17356
|
-
gen.assign(
|
|
17357
|
-
gen.if((0, codegen_1.not)(
|
|
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
|
|
17432
|
+
const valid16 = gen.let("valid");
|
|
17433
17433
|
const itemTypes = parentSchema.items ? (0, dataType_1.getSchemaTypes)(parentSchema.items) : [];
|
|
17434
|
-
cxt.block$data(
|
|
17435
|
-
cxt.ok(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
17529
|
+
let valid16;
|
|
17530
17530
|
if (useLoop || $data) {
|
|
17531
|
-
|
|
17532
|
-
cxt.block$data(
|
|
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
|
-
|
|
17537
|
+
valid16 = (0, codegen_1.or)(...schema2.map((_x, i) => equalCode(vSchema, i)));
|
|
17538
17538
|
}
|
|
17539
|
-
cxt.pass(
|
|
17539
|
+
cxt.pass(valid16);
|
|
17540
17540
|
function loopEnum() {
|
|
17541
|
-
gen.assign(
|
|
17542
|
-
gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v})`, () => gen.assign(
|
|
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
|
|
17629
|
-
gen.if((0, codegen_1.not)(
|
|
17630
|
-
cxt.ok(
|
|
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(
|
|
17632
|
+
function validateItems(valid16) {
|
|
17633
17633
|
gen.forRange("i", items.length, len, (i) => {
|
|
17634
|
-
cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num },
|
|
17634
|
+
cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num }, valid16);
|
|
17635
17635
|
if (!it.allErrors)
|
|
17636
|
-
gen.if((0, codegen_1.not)(
|
|
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
|
|
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
|
-
},
|
|
17685
|
-
cxt.ok(
|
|
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
|
|
17802
|
+
const valid16 = gen.name("valid");
|
|
17803
17803
|
if (max === void 0 && min === 1) {
|
|
17804
|
-
validateItems(
|
|
17804
|
+
validateItems(valid16, () => gen.if(valid16, () => gen.break()));
|
|
17805
17805
|
} else if (min === 0) {
|
|
17806
|
-
gen.let(
|
|
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(
|
|
17810
|
+
gen.let(valid16, false);
|
|
17811
17811
|
validateItemsWithCount();
|
|
17812
17812
|
}
|
|
17813
|
-
cxt.result(
|
|
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(
|
|
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(
|
|
17835
|
+
gen.if((0, codegen_1._)`${count} > ${max}`, () => gen.assign(valid16, false).break());
|
|
17836
17836
|
if (min === 1)
|
|
17837
|
-
gen.assign(
|
|
17837
|
+
gen.assign(valid16, true);
|
|
17838
17838
|
else
|
|
17839
|
-
gen.if((0, codegen_1._)`${count} >= ${min}`, () => gen.assign(
|
|
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
|
|
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 },
|
|
17929
|
-
cxt.mergeValidEvaluated(schCxt,
|
|
17928
|
+
const schCxt = cxt.subschema({ keyword, schemaProp: prop }, valid16);
|
|
17929
|
+
cxt.mergeValidEvaluated(schCxt, valid16);
|
|
17930
17930
|
},
|
|
17931
|
-
() => gen.var(
|
|
17931
|
+
() => gen.var(valid16, true)
|
|
17932
17932
|
// TODO var
|
|
17933
17933
|
);
|
|
17934
|
-
cxt.ok(
|
|
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
|
|
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
|
-
},
|
|
17972
|
-
gen.if((0, codegen_1.not)(
|
|
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(
|
|
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
|
|
18056
|
+
const valid16 = gen.name("valid");
|
|
18057
18057
|
if (opts.removeAdditional === "failing") {
|
|
18058
|
-
applyAdditionalSchema(key,
|
|
18059
|
-
gen.if((0, codegen_1.not)(
|
|
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,
|
|
18064
|
+
applyAdditionalSchema(key, valid16);
|
|
18065
18065
|
if (!allErrors)
|
|
18066
|
-
gen.if((0, codegen_1.not)(
|
|
18066
|
+
gen.if((0, codegen_1.not)(valid16), () => gen.break());
|
|
18067
18067
|
}
|
|
18068
18068
|
}
|
|
18069
18069
|
}
|
|
18070
|
-
function applyAdditionalSchema(key,
|
|
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,
|
|
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
|
|
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(
|
|
18127
|
+
gen.else().var(valid16, true);
|
|
18128
18128
|
gen.endIf();
|
|
18129
18129
|
}
|
|
18130
18130
|
cxt.it.definedProperties.add(prop);
|
|
18131
|
-
cxt.ok(
|
|
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
|
-
},
|
|
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
|
|
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(
|
|
18184
|
+
gen.var(valid16, true);
|
|
18185
18185
|
validateProperties(pat);
|
|
18186
|
-
gen.if(
|
|
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
|
-
},
|
|
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)(
|
|
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
|
|
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
|
-
},
|
|
18246
|
-
cxt.failResult(
|
|
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
|
|
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(
|
|
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} && ${
|
|
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(
|
|
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
|
|
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 },
|
|
18347
|
-
cxt.ok(
|
|
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
|
|
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(
|
|
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(
|
|
18408
|
-
cxt.mergeValidEvaluated(schCxt,
|
|
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
|
|
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(
|
|
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(
|
|
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 });
|
|
@@ -19509,7 +19509,7 @@ var init_command = __esm({
|
|
|
19509
19509
|
});
|
|
19510
19510
|
|
|
19511
19511
|
// src/extension/cli/index.ts
|
|
19512
|
-
var
|
|
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/
|
|
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/
|
|
19974
|
+
// src/integrations/installation/installers/registry.ts
|
|
19978
19975
|
init_validation();
|
|
19979
19976
|
|
|
19980
|
-
// src/integrations/
|
|
19977
|
+
// src/integrations/installation/installers/antigravity.ts
|
|
19978
|
+
var import_semver2 = __toESM(require_semver2(), 1);
|
|
19981
19979
|
init_json();
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
19986
|
-
|
|
19987
|
-
|
|
19988
|
-
|
|
19989
|
-
|
|
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
|
|
19991
|
+
var antigravityInstaller = {
|
|
20071
19992
|
host: "antigravity",
|
|
20072
|
-
|
|
20073
|
-
|
|
20074
|
-
|
|
20075
|
-
|
|
20076
|
-
|
|
20077
|
-
|
|
20078
|
-
|
|
20079
|
-
|
|
20080
|
-
|
|
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
|
-
|
|
20101
|
-
|
|
20102
|
-
|
|
20103
|
-
|
|
20104
|
-
|
|
20105
|
-
|
|
20106
|
-
|
|
20107
|
-
|
|
20108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20125
|
-
|
|
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/
|
|
20135
|
-
|
|
20136
|
-
|
|
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/
|
|
20054
|
+
// src/integrations/installation/installers/codex.ts
|
|
20055
|
+
var import_semver3 = __toESM(require_semver2(), 1);
|
|
20139
20056
|
init_json();
|
|
20140
|
-
|
|
20141
|
-
import {
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
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
|
|
20163
|
-
|
|
20164
|
-
|
|
20165
|
-
const
|
|
20166
|
-
if (!
|
|
20167
|
-
|
|
20168
|
-
|
|
20169
|
-
|
|
20170
|
-
|
|
20171
|
-
|
|
20172
|
-
|
|
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
|
-
|
|
20175
|
-
|
|
20176
|
-
|
|
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
|
-
|
|
20179
|
-
|
|
20180
|
-
|
|
20181
|
-
|
|
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
|
-
|
|
20186
|
-
|
|
20187
|
-
|
|
20188
|
-
|
|
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
|
-
|
|
20194
|
-
|
|
20195
|
-
|
|
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/
|
|
20206
|
-
var
|
|
20207
|
-
|
|
20208
|
-
async
|
|
20209
|
-
|
|
20210
|
-
|
|
20211
|
-
|
|
20212
|
-
|
|
20213
|
-
|
|
20214
|
-
|
|
20215
|
-
|
|
20216
|
-
|
|
20217
|
-
|
|
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
|
-
|
|
20233
|
-
|
|
20234
|
-
|
|
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/
|
|
20238
|
-
var
|
|
20239
|
-
host: "
|
|
20240
|
-
|
|
20241
|
-
|
|
20242
|
-
|
|
20243
|
-
|
|
20244
|
-
|
|
20245
|
-
|
|
20246
|
-
|
|
20247
|
-
|
|
20248
|
-
|
|
20249
|
-
|
|
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/
|
|
20253
|
-
var
|
|
20254
|
-
|
|
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
|
-
|
|
20257
|
-
|
|
20258
|
-
|
|
20259
|
-
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
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/
|
|
20270
|
-
var
|
|
20271
|
-
#
|
|
20206
|
+
// src/integrations/installation/installers/registry.ts
|
|
20207
|
+
var HostInstallerRegistry = class {
|
|
20208
|
+
#installers = /* @__PURE__ */ new Map();
|
|
20272
20209
|
constructor(initial = []) {
|
|
20273
|
-
for (const
|
|
20210
|
+
for (const installer of initial) this.register(installer);
|
|
20274
20211
|
}
|
|
20275
|
-
register(
|
|
20276
|
-
requireThat(typeof
|
|
20277
|
-
this.#
|
|
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.#
|
|
20218
|
+
return this.#installers.delete(host);
|
|
20282
20219
|
}
|
|
20283
20220
|
get(host) {
|
|
20284
|
-
return this.#
|
|
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.#
|
|
20224
|
+
return [...this.#installers.keys()];
|
|
20293
20225
|
}
|
|
20294
20226
|
};
|
|
20295
|
-
var
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20299
|
-
|
|
20300
|
-
|
|
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/
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
import {
|
|
20308
|
-
|
|
20309
|
-
|
|
20310
|
-
|
|
20311
|
-
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20404
|
-
|
|
20405
|
-
|
|
20406
|
-
|
|
20407
|
-
|
|
20408
|
-
|
|
20409
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
20624
|
-
import { join as
|
|
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
|
|
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(
|
|
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
|
|
21148
|
+
let text = await readFile8(join21(resourceRoot, "agents", agent + ".md"), "utf8");
|
|
20640
21149
|
if (agent === "coordinator") {
|
|
20641
|
-
text += "\n\n" + await
|
|
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;
|
|
@@ -20663,9 +21172,9 @@ async function loadWorkspaceContext(options) {
|
|
|
20663
21172
|
notices = []
|
|
20664
21173
|
} = options;
|
|
20665
21174
|
const [workspace, roleText, rootAgents] = includePrompts ? await Promise.all([
|
|
20666
|
-
|
|
21175
|
+
readFile8(join21(resourceRoot, "prompts/workspace.md"), "utf8"),
|
|
20667
21176
|
localRoleOnly ? readLocalRole(role, root) : agentText(role, root, coordinatorPrompt),
|
|
20668
|
-
includeRootAgents ? readOptionalFile(
|
|
21177
|
+
includeRootAgents ? readOptionalFile(join21(root, "AGENTS.md")) : Promise.resolve("")
|
|
20669
21178
|
]) : ["", "", ""];
|
|
20670
21179
|
const skillsSection = formatWorkspaceSkills(workspaceSkills);
|
|
20671
21180
|
const noticesSection = notices.length ? "## \u542F\u52A8\u63D0\u793A\n\n" + notices.map((item) => `- ${item}`).join("\n") : "";
|
|
@@ -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
|
-
|
|
20955
|
-
|
|
20956
|
-
|
|
20957
|
-
|
|
20958
|
-
|
|
20959
|
-
|
|
20960
|
-
|
|
20961
|
-
|
|
20962
|
-
|
|
20963
|
-
|
|
20964
|
-
|
|
20965
|
-
|
|
20966
|
-
|
|
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
|
-
|
|
20970
|
-
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
20974
|
-
|
|
20975
|
-
|
|
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
|
|
21016
|
-
|
|
21017
|
-
if (
|
|
21018
|
-
|
|
21019
|
-
|
|
21020
|
-
|
|
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/
|
|
21024
|
-
|
|
21281
|
+
// src/extension/hosts/plugin-runtime.ts
|
|
21282
|
+
init_summary_runner();
|
|
21283
|
+
init_workspace_config2();
|
|
21025
21284
|
|
|
21026
|
-
// src/
|
|
21027
|
-
|
|
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
|
-
|
|
21035
|
-
import {
|
|
21036
|
-
|
|
21037
|
-
|
|
21038
|
-
|
|
21039
|
-
|
|
21040
|
-
|
|
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
|
|
21057
|
-
|
|
21058
|
-
|
|
21059
|
-
|
|
21060
|
-
|
|
21061
|
-
|
|
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
|
-
|
|
21121
|
-
|
|
21122
|
-
|
|
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/
|
|
21159
|
-
|
|
21160
|
-
|
|
21161
|
-
|
|
21162
|
-
|
|
21163
|
-
|
|
21164
|
-
|
|
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
|
-
|
|
21195
|
-
}
|
|
21196
|
-
|
|
21197
|
-
|
|
21198
|
-
|
|
21199
|
-
|
|
21200
|
-
|
|
21201
|
-
|
|
21202
|
-
|
|
21203
|
-
const
|
|
21204
|
-
if (!
|
|
21205
|
-
const
|
|
21206
|
-
|
|
21207
|
-
|
|
21208
|
-
|
|
21209
|
-
|
|
21210
|
-
|
|
21211
|
-
|
|
21212
|
-
|
|
21213
|
-
|
|
21214
|
-
|
|
21215
|
-
|
|
21216
|
-
|
|
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
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
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
|
-
|
|
21325
|
-
|
|
21326
|
-
|
|
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
|
|
21366
|
-
|
|
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
|
|
21382
|
-
|
|
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
|
-
|
|
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
|
-
|
|
21399
|
-
|
|
21400
|
-
return { results };
|
|
21370
|
+
if (error.code === "ENOENT") return [];
|
|
21371
|
+
throw error;
|
|
21401
21372
|
}
|
|
21402
|
-
|
|
21403
|
-
|
|
21404
|
-
|
|
21405
|
-
|
|
21406
|
-
|
|
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
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
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
|
-
|
|
21391
|
+
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
21392
|
+
return results;
|
|
21435
21393
|
}
|
|
21436
21394
|
|
|
21437
|
-
// src/
|
|
21438
|
-
|
|
21439
|
-
|
|
21440
|
-
|
|
21441
|
-
|
|
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
|
-
|
|
21444
|
-
|
|
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
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
|
|
21450
|
-
|
|
21451
|
-
|
|
21452
|
-
|
|
21453
|
-
|
|
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
|
|
21456
|
-
|
|
21457
|
-
|
|
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
|
-
|
|
21464
|
-
|
|
21465
|
-
|
|
21466
|
-
|
|
21467
|
-
|
|
21468
|
-
|
|
21469
|
-
|
|
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
|
-
|
|
21473
|
-
|
|
21474
|
-
|
|
21475
|
-
|
|
21476
|
-
|
|
21477
|
-
|
|
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/
|
|
21488
|
-
|
|
21489
|
-
|
|
21490
|
-
|
|
21491
|
-
|
|
21492
|
-
|
|
21493
|
-
|
|
21494
|
-
|
|
21495
|
-
|
|
21496
|
-
|
|
21497
|
-
|
|
21498
|
-
|
|
21499
|
-
|
|
21500
|
-
|
|
21501
|
-
|
|
21502
|
-
const
|
|
21503
|
-
|
|
21504
|
-
|
|
21505
|
-
|
|
21506
|
-
|
|
21507
|
-
|
|
21508
|
-
|
|
21509
|
-
|
|
21510
|
-
|
|
21511
|
-
|
|
21512
|
-
|
|
21513
|
-
|
|
21514
|
-
|
|
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
|
|
21510
|
+
var import_semver13 = __toESM(require_semver2(), 1);
|
|
21626
21511
|
init_json();
|
|
21627
|
-
import { readFile as
|
|
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
|
|
21535
|
+
var import_semver6 = __toESM(require_semver2(), 1);
|
|
21636
21536
|
init_json();
|
|
21637
|
-
import { readFile as
|
|
21537
|
+
import { readFile as readFile11 } from "node:fs/promises";
|
|
21638
21538
|
import { join as join25 } from "node:path";
|
|
21639
|
-
async function
|
|
21539
|
+
async function readManifestVersion4(path) {
|
|
21640
21540
|
try {
|
|
21641
|
-
const data = JSON.parse(await
|
|
21642
|
-
return object(data) && typeof data.version === "string" && (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,
|
|
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
|
|
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,
|
|
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
|
|
21602
|
+
var import_semver7 = __toESM(require_semver2(), 1);
|
|
21703
21603
|
init_json();
|
|
21704
|
-
import { realpath as
|
|
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
|
|
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,
|
|
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
|
|
21714
|
+
var import_semver8 = __toESM(require_semver2(), 1);
|
|
21815
21715
|
init_json();
|
|
21816
|
-
import { readFile as
|
|
21716
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
21817
21717
|
import { join as join26 } from "node:path";
|
|
21818
|
-
async function
|
|
21718
|
+
async function readManifestVersion5(path) {
|
|
21819
21719
|
try {
|
|
21820
|
-
const data = JSON.parse(await
|
|
21821
|
-
return object(data) && typeof data.version === "string" && (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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
21847
|
+
var import_semver10 = __toESM(require_semver2(), 1);
|
|
21948
21848
|
init_json();
|
|
21949
|
-
import { readFile as
|
|
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
|
|
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
|
|
21974
|
-
return object(data) && data.name === "personal-bot" && typeof data.version === "string" && (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,
|
|
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
|
|
21928
|
+
var import_semver11 = __toESM(require_semver2(), 1);
|
|
22029
21929
|
init_json();
|
|
22030
|
-
import { readFile as
|
|
21930
|
+
import { readFile as readFile14 } from "node:fs/promises";
|
|
22031
21931
|
import { join as join28 } from "node:path";
|
|
22032
|
-
async function
|
|
21932
|
+
async function readManifestVersion6(path) {
|
|
22033
21933
|
try {
|
|
22034
|
-
const data = JSON.parse(await
|
|
22035
|
-
return object(data) && typeof data.version === "string" && (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,
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
22253
|
-
if (object(manifest2) && manifest2.name === "personal-bot" && typeof manifest2.version === "string" && (0,
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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);
|