@promptframe/creation 0.3.0 → 0.3.1
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +52 -2
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -3
- package/dist/cli.mjs +1052 -644
- package/docs/development.md +6 -2
- package/docs/install-guidance.json +3 -3
- package/docs/installing.md +4 -4
- package/docs/releases/0.3.1.md +7 -0
- package/lib/claude-hook-definition.mjs +11 -0
- package/lib/claude-hook-registration.mjs +66 -0
- package/lib/claude-host-process.mjs +48 -0
- package/lib/claude-host-session.mjs +150 -0
- package/lib/claude-installation.mjs +5 -1
- package/lib/claude-mcp-installation.mjs +3 -0
- package/lib/cli.mjs +8 -3
- package/lib/host-context.mjs +43 -16
- package/lib/host-identity.mjs +5 -6
- package/lib/runtime-launch.mjs +1 -1
- package/lib/version.mjs +1 -1
- package/package.json +1 -1
- package/skills/creation-setup/SKILL.md +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -407,11 +407,11 @@ var require_codegen = __commonJS({
|
|
|
407
407
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
408
408
|
return `${varKind} ${this.name}${rhs};` + _n2;
|
|
409
409
|
}
|
|
410
|
-
optimizeNames(names,
|
|
410
|
+
optimizeNames(names, constants4) {
|
|
411
411
|
if (!names[this.name.str])
|
|
412
412
|
return;
|
|
413
413
|
if (this.rhs)
|
|
414
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
414
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
415
415
|
return this;
|
|
416
416
|
}
|
|
417
417
|
get names() {
|
|
@@ -428,10 +428,10 @@ var require_codegen = __commonJS({
|
|
|
428
428
|
render({ _n: _n2 }) {
|
|
429
429
|
return `${this.lhs} = ${this.rhs};` + _n2;
|
|
430
430
|
}
|
|
431
|
-
optimizeNames(names,
|
|
431
|
+
optimizeNames(names, constants4) {
|
|
432
432
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
|
|
433
433
|
return;
|
|
434
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
434
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
435
435
|
return this;
|
|
436
436
|
}
|
|
437
437
|
get names() {
|
|
@@ -470,9 +470,9 @@ var require_codegen = __commonJS({
|
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
472
|
var Throw = class extends Node {
|
|
473
|
-
constructor(
|
|
473
|
+
constructor(error4) {
|
|
474
474
|
super();
|
|
475
|
-
this.error =
|
|
475
|
+
this.error = error4;
|
|
476
476
|
}
|
|
477
477
|
render({ _n: _n2 }) {
|
|
478
478
|
return `throw ${this.error};` + _n2;
|
|
@@ -492,8 +492,8 @@ var require_codegen = __commonJS({
|
|
|
492
492
|
optimizeNodes() {
|
|
493
493
|
return `${this.code}` ? this : void 0;
|
|
494
494
|
}
|
|
495
|
-
optimizeNames(names,
|
|
496
|
-
this.code = optimizeExpr(this.code, names,
|
|
495
|
+
optimizeNames(names, constants4) {
|
|
496
|
+
this.code = optimizeExpr(this.code, names, constants4);
|
|
497
497
|
return this;
|
|
498
498
|
}
|
|
499
499
|
get names() {
|
|
@@ -522,12 +522,12 @@ var require_codegen = __commonJS({
|
|
|
522
522
|
}
|
|
523
523
|
return nodes.length > 0 ? this : void 0;
|
|
524
524
|
}
|
|
525
|
-
optimizeNames(names,
|
|
525
|
+
optimizeNames(names, constants4) {
|
|
526
526
|
const { nodes } = this;
|
|
527
527
|
let i = nodes.length;
|
|
528
528
|
while (i--) {
|
|
529
529
|
const n = nodes[i];
|
|
530
|
-
if (n.optimizeNames(names,
|
|
530
|
+
if (n.optimizeNames(names, constants4))
|
|
531
531
|
continue;
|
|
532
532
|
subtractNames(names, n.names);
|
|
533
533
|
nodes.splice(i, 1);
|
|
@@ -580,12 +580,12 @@ var require_codegen = __commonJS({
|
|
|
580
580
|
return void 0;
|
|
581
581
|
return this;
|
|
582
582
|
}
|
|
583
|
-
optimizeNames(names,
|
|
583
|
+
optimizeNames(names, constants4) {
|
|
584
584
|
var _a3;
|
|
585
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
586
|
-
if (!(super.optimizeNames(names,
|
|
585
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants4);
|
|
586
|
+
if (!(super.optimizeNames(names, constants4) || this.else))
|
|
587
587
|
return;
|
|
588
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
588
|
+
this.condition = optimizeExpr(this.condition, names, constants4);
|
|
589
589
|
return this;
|
|
590
590
|
}
|
|
591
591
|
get names() {
|
|
@@ -608,10 +608,10 @@ var require_codegen = __commonJS({
|
|
|
608
608
|
render(opts) {
|
|
609
609
|
return `for(${this.iteration})` + super.render(opts);
|
|
610
610
|
}
|
|
611
|
-
optimizeNames(names,
|
|
612
|
-
if (!super.optimizeNames(names,
|
|
611
|
+
optimizeNames(names, constants4) {
|
|
612
|
+
if (!super.optimizeNames(names, constants4))
|
|
613
613
|
return;
|
|
614
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
614
|
+
this.iteration = optimizeExpr(this.iteration, names, constants4);
|
|
615
615
|
return this;
|
|
616
616
|
}
|
|
617
617
|
get names() {
|
|
@@ -647,10 +647,10 @@ var require_codegen = __commonJS({
|
|
|
647
647
|
render(opts) {
|
|
648
648
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
649
649
|
}
|
|
650
|
-
optimizeNames(names,
|
|
651
|
-
if (!super.optimizeNames(names,
|
|
650
|
+
optimizeNames(names, constants4) {
|
|
651
|
+
if (!super.optimizeNames(names, constants4))
|
|
652
652
|
return;
|
|
653
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
653
|
+
this.iterable = optimizeExpr(this.iterable, names, constants4);
|
|
654
654
|
return this;
|
|
655
655
|
}
|
|
656
656
|
get names() {
|
|
@@ -692,11 +692,11 @@ var require_codegen = __commonJS({
|
|
|
692
692
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
693
693
|
return this;
|
|
694
694
|
}
|
|
695
|
-
optimizeNames(names,
|
|
695
|
+
optimizeNames(names, constants4) {
|
|
696
696
|
var _a3, _b;
|
|
697
|
-
super.optimizeNames(names,
|
|
698
|
-
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
699
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names,
|
|
697
|
+
super.optimizeNames(names, constants4);
|
|
698
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants4);
|
|
699
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants4);
|
|
700
700
|
return this;
|
|
701
701
|
}
|
|
702
702
|
get names() {
|
|
@@ -709,9 +709,9 @@ var require_codegen = __commonJS({
|
|
|
709
709
|
}
|
|
710
710
|
};
|
|
711
711
|
var Catch = class extends BlockNode {
|
|
712
|
-
constructor(
|
|
712
|
+
constructor(error4) {
|
|
713
713
|
super();
|
|
714
|
-
this.error =
|
|
714
|
+
this.error = error4;
|
|
715
715
|
}
|
|
716
716
|
render(opts) {
|
|
717
717
|
return `catch(${this.error})` + super.render(opts);
|
|
@@ -902,9 +902,9 @@ var require_codegen = __commonJS({
|
|
|
902
902
|
this._blockNode(node2);
|
|
903
903
|
this.code(tryBody);
|
|
904
904
|
if (catchCode) {
|
|
905
|
-
const
|
|
906
|
-
this._currNode = node2.catch = new Catch(
|
|
907
|
-
catchCode(
|
|
905
|
+
const error4 = this.name("e");
|
|
906
|
+
this._currNode = node2.catch = new Catch(error4);
|
|
907
|
+
catchCode(error4);
|
|
908
908
|
}
|
|
909
909
|
if (finallyCode) {
|
|
910
910
|
this._currNode = node2.finally = new Finally();
|
|
@@ -913,8 +913,8 @@ var require_codegen = __commonJS({
|
|
|
913
913
|
return this._endBlockNode(Catch, Finally);
|
|
914
914
|
}
|
|
915
915
|
// `throw` statement
|
|
916
|
-
throw(
|
|
917
|
-
return this._leafNode(new Throw(
|
|
916
|
+
throw(error4) {
|
|
917
|
+
return this._leafNode(new Throw(error4));
|
|
918
918
|
}
|
|
919
919
|
// start self-balancing block
|
|
920
920
|
block(body, nodeCount) {
|
|
@@ -997,7 +997,7 @@ var require_codegen = __commonJS({
|
|
|
997
997
|
function addExprNames(names, from) {
|
|
998
998
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
999
999
|
}
|
|
1000
|
-
function optimizeExpr(expr, names,
|
|
1000
|
+
function optimizeExpr(expr, names, constants4) {
|
|
1001
1001
|
if (expr instanceof code_1.Name)
|
|
1002
1002
|
return replaceName(expr);
|
|
1003
1003
|
if (!canOptimize(expr))
|
|
@@ -1012,14 +1012,14 @@ var require_codegen = __commonJS({
|
|
|
1012
1012
|
return items;
|
|
1013
1013
|
}, []));
|
|
1014
1014
|
function replaceName(n) {
|
|
1015
|
-
const c =
|
|
1015
|
+
const c = constants4[n.str];
|
|
1016
1016
|
if (c === void 0 || names[n.str] !== 1)
|
|
1017
1017
|
return n;
|
|
1018
1018
|
delete names[n.str];
|
|
1019
1019
|
return c;
|
|
1020
1020
|
}
|
|
1021
1021
|
function canOptimize(e) {
|
|
1022
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
1022
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants4[c.str] !== void 0);
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
1025
|
function subtractNames(names, from) {
|
|
@@ -1058,10 +1058,10 @@ var require_util = __commonJS({
|
|
|
1058
1058
|
var codegen_1 = require_codegen();
|
|
1059
1059
|
var code_1 = require_code();
|
|
1060
1060
|
function toHash(arr) {
|
|
1061
|
-
const
|
|
1061
|
+
const hash6 = {};
|
|
1062
1062
|
for (const item of arr)
|
|
1063
|
-
|
|
1064
|
-
return
|
|
1063
|
+
hash6[item] = true;
|
|
1064
|
+
return hash6;
|
|
1065
1065
|
}
|
|
1066
1066
|
exports.toHash = toHash;
|
|
1067
1067
|
function alwaysValidSchema(it2, schema) {
|
|
@@ -1270,10 +1270,10 @@ var require_errors = __commonJS({
|
|
|
1270
1270
|
exports.keyword$DataError = {
|
|
1271
1271
|
message: ({ keyword, schemaType }) => schemaType ? (0, codegen_1.str)`"${keyword}" keyword must be ${schemaType} ($data)` : (0, codegen_1.str)`"${keyword}" keyword is invalid ($data)`
|
|
1272
1272
|
};
|
|
1273
|
-
function reportError(cxt,
|
|
1273
|
+
function reportError(cxt, error4 = exports.keywordError, errorPaths, overrideAllErrors) {
|
|
1274
1274
|
const { it: it2 } = cxt;
|
|
1275
1275
|
const { gen, compositeRule, allErrors } = it2;
|
|
1276
|
-
const errObj = errorObjectCode(cxt,
|
|
1276
|
+
const errObj = errorObjectCode(cxt, error4, errorPaths);
|
|
1277
1277
|
if (overrideAllErrors !== null && overrideAllErrors !== void 0 ? overrideAllErrors : compositeRule || allErrors) {
|
|
1278
1278
|
addError(gen, errObj);
|
|
1279
1279
|
} else {
|
|
@@ -1281,10 +1281,10 @@ var require_errors = __commonJS({
|
|
|
1281
1281
|
}
|
|
1282
1282
|
}
|
|
1283
1283
|
exports.reportError = reportError;
|
|
1284
|
-
function reportExtraError(cxt,
|
|
1284
|
+
function reportExtraError(cxt, error4 = exports.keywordError, errorPaths) {
|
|
1285
1285
|
const { it: it2 } = cxt;
|
|
1286
1286
|
const { gen, compositeRule, allErrors } = it2;
|
|
1287
|
-
const errObj = errorObjectCode(cxt,
|
|
1287
|
+
const errObj = errorObjectCode(cxt, error4, errorPaths);
|
|
1288
1288
|
addError(gen, errObj);
|
|
1289
1289
|
if (!(compositeRule || allErrors)) {
|
|
1290
1290
|
returnErrors(it2, names_1.default.vErrors);
|
|
@@ -1335,19 +1335,19 @@ var require_errors = __commonJS({
|
|
|
1335
1335
|
schema: new codegen_1.Name("schema"),
|
|
1336
1336
|
parentSchema: new codegen_1.Name("parentSchema")
|
|
1337
1337
|
};
|
|
1338
|
-
function errorObjectCode(cxt,
|
|
1338
|
+
function errorObjectCode(cxt, error4, errorPaths) {
|
|
1339
1339
|
const { createErrors } = cxt.it;
|
|
1340
1340
|
if (createErrors === false)
|
|
1341
1341
|
return (0, codegen_1._)`{}`;
|
|
1342
|
-
return errorObject(cxt,
|
|
1342
|
+
return errorObject(cxt, error4, errorPaths);
|
|
1343
1343
|
}
|
|
1344
|
-
function errorObject(cxt,
|
|
1344
|
+
function errorObject(cxt, error4, errorPaths = {}) {
|
|
1345
1345
|
const { gen, it: it2 } = cxt;
|
|
1346
1346
|
const keyValues = [
|
|
1347
1347
|
errorInstancePath(it2, errorPaths),
|
|
1348
1348
|
errorSchemaPath(cxt, errorPaths)
|
|
1349
1349
|
];
|
|
1350
|
-
extraErrorProps(cxt,
|
|
1350
|
+
extraErrorProps(cxt, error4, keyValues);
|
|
1351
1351
|
return gen.object(...keyValues);
|
|
1352
1352
|
}
|
|
1353
1353
|
function errorInstancePath({ errorPath }, { instancePath }) {
|
|
@@ -3259,8 +3259,8 @@ var require_utils = __commonJS({
|
|
|
3259
3259
|
}
|
|
3260
3260
|
return ind;
|
|
3261
3261
|
}
|
|
3262
|
-
function removeDotSegments(
|
|
3263
|
-
let input =
|
|
3262
|
+
function removeDotSegments(path14) {
|
|
3263
|
+
let input = path14;
|
|
3264
3264
|
const output = [];
|
|
3265
3265
|
let nextSlash = -1;
|
|
3266
3266
|
let len = 0;
|
|
@@ -3349,9 +3349,9 @@ var require_utils = __commonJS({
|
|
|
3349
3349
|
let output = "";
|
|
3350
3350
|
for (let i = 0; i < input.length; i++) {
|
|
3351
3351
|
if (input[i] === "%" && i + 2 < input.length) {
|
|
3352
|
-
const
|
|
3353
|
-
if (isHexPair(
|
|
3354
|
-
const normalizedHex =
|
|
3352
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3353
|
+
if (isHexPair(hex2)) {
|
|
3354
|
+
const normalizedHex = hex2.toUpperCase();
|
|
3355
3355
|
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
3356
3356
|
if (decodeUnreserved && isUnreserved(decoded)) {
|
|
3357
3357
|
output += decoded;
|
|
@@ -3371,9 +3371,9 @@ var require_utils = __commonJS({
|
|
|
3371
3371
|
for (let i = 0; i < input.length; i++) {
|
|
3372
3372
|
const ch = input[i];
|
|
3373
3373
|
if (ch === "%" && i + 2 < input.length) {
|
|
3374
|
-
const
|
|
3375
|
-
if (isHexPair(
|
|
3376
|
-
const normalizedHex =
|
|
3374
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3375
|
+
if (isHexPair(hex2)) {
|
|
3376
|
+
const normalizedHex = hex2.toUpperCase();
|
|
3377
3377
|
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
3378
3378
|
if (decoded !== "." && isUnreserved(decoded)) {
|
|
3379
3379
|
output += decoded;
|
|
@@ -3413,9 +3413,9 @@ var require_utils = __commonJS({
|
|
|
3413
3413
|
for (let i = 0; i < input.length; i++) {
|
|
3414
3414
|
const ch = input[i];
|
|
3415
3415
|
if (ch === "%" && i + 2 < input.length) {
|
|
3416
|
-
const
|
|
3417
|
-
if (isHexPair(
|
|
3418
|
-
output += "%" +
|
|
3416
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3417
|
+
if (isHexPair(hex2)) {
|
|
3418
|
+
output += "%" + hex2.toUpperCase();
|
|
3419
3419
|
i += 2;
|
|
3420
3420
|
continue;
|
|
3421
3421
|
}
|
|
@@ -3451,9 +3451,9 @@ var require_utils = __commonJS({
|
|
|
3451
3451
|
for (let i = 0; i < input.length; i++) {
|
|
3452
3452
|
const ch = input[i];
|
|
3453
3453
|
if (ch === "%" && i + 2 < input.length) {
|
|
3454
|
-
const
|
|
3455
|
-
if (isHexPair(
|
|
3456
|
-
output += "%" +
|
|
3454
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3455
|
+
if (isHexPair(hex2)) {
|
|
3456
|
+
output += "%" + hex2.toUpperCase();
|
|
3457
3457
|
i += 2;
|
|
3458
3458
|
continue;
|
|
3459
3459
|
}
|
|
@@ -3498,9 +3498,9 @@ var require_utils = __commonJS({
|
|
|
3498
3498
|
for (let i = 0; i < input.length; i++) {
|
|
3499
3499
|
const ch = input[i];
|
|
3500
3500
|
if (ch === "%" && i + 2 < input.length) {
|
|
3501
|
-
const
|
|
3502
|
-
if (isHexPair(
|
|
3503
|
-
const normalizedHex =
|
|
3501
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3502
|
+
if (isHexPair(hex2)) {
|
|
3503
|
+
const normalizedHex = hex2.toUpperCase();
|
|
3504
3504
|
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
3505
3505
|
if (isUnreserved(decoded)) {
|
|
3506
3506
|
output += decoded;
|
|
@@ -3538,9 +3538,9 @@ var require_utils = __commonJS({
|
|
|
3538
3538
|
let output = "";
|
|
3539
3539
|
for (let i = 0; i < input.length; i++) {
|
|
3540
3540
|
if (input[i] === "%" && i + 2 < input.length) {
|
|
3541
|
-
const
|
|
3542
|
-
if (isHexPair(
|
|
3543
|
-
output += "%" +
|
|
3541
|
+
const hex2 = input.slice(i + 1, i + 3);
|
|
3542
|
+
if (isHexPair(hex2)) {
|
|
3543
|
+
output += "%" + hex2.toUpperCase();
|
|
3544
3544
|
i += 2;
|
|
3545
3545
|
continue;
|
|
3546
3546
|
}
|
|
@@ -3669,8 +3669,8 @@ var require_schemes = __commonJS({
|
|
|
3669
3669
|
}
|
|
3670
3670
|
if (wsComponent.resourceName) {
|
|
3671
3671
|
const queryIndex = wsComponent.resourceName.indexOf("?");
|
|
3672
|
-
const
|
|
3673
|
-
wsComponent.path =
|
|
3672
|
+
const path14 = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
|
|
3673
|
+
wsComponent.path = path14 && path14 !== "/" ? path14 : void 0;
|
|
3674
3674
|
wsComponent.query = queryIndex === -1 ? void 0 : wsComponent.resourceName.slice(queryIndex + 1);
|
|
3675
3675
|
wsComponent.resourceName = void 0;
|
|
3676
3676
|
}
|
|
@@ -5012,7 +5012,7 @@ var require_limitNumber = __commonJS({
|
|
|
5012
5012
|
exclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
|
|
5013
5013
|
exclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE }
|
|
5014
5014
|
};
|
|
5015
|
-
var
|
|
5015
|
+
var error4 = {
|
|
5016
5016
|
message: ({ keyword, schemaCode }) => (0, codegen_1.str)`must be ${KWDs[keyword].okStr} ${schemaCode}`,
|
|
5017
5017
|
params: ({ keyword, schemaCode }) => (0, codegen_1._)`{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`
|
|
5018
5018
|
};
|
|
@@ -5021,7 +5021,7 @@ var require_limitNumber = __commonJS({
|
|
|
5021
5021
|
type: "number",
|
|
5022
5022
|
schemaType: "number",
|
|
5023
5023
|
$data: true,
|
|
5024
|
-
error:
|
|
5024
|
+
error: error4,
|
|
5025
5025
|
code(cxt) {
|
|
5026
5026
|
const { keyword, data, schemaCode } = cxt;
|
|
5027
5027
|
cxt.fail$data((0, codegen_1._)`${data} ${KWDs[keyword].fail} ${schemaCode} || isNaN(${data})`);
|
|
@@ -5037,7 +5037,7 @@ var require_multipleOf = __commonJS({
|
|
|
5037
5037
|
"use strict";
|
|
5038
5038
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5039
5039
|
var codegen_1 = require_codegen();
|
|
5040
|
-
var
|
|
5040
|
+
var error4 = {
|
|
5041
5041
|
message: ({ schemaCode }) => (0, codegen_1.str)`must be multiple of ${schemaCode}`,
|
|
5042
5042
|
params: ({ schemaCode }) => (0, codegen_1._)`{multipleOf: ${schemaCode}}`
|
|
5043
5043
|
};
|
|
@@ -5046,7 +5046,7 @@ var require_multipleOf = __commonJS({
|
|
|
5046
5046
|
type: "number",
|
|
5047
5047
|
schemaType: "number",
|
|
5048
5048
|
$data: true,
|
|
5049
|
-
error:
|
|
5049
|
+
error: error4,
|
|
5050
5050
|
code(cxt) {
|
|
5051
5051
|
const { gen, data, schemaCode, it: it2 } = cxt;
|
|
5052
5052
|
const prec = it2.opts.multipleOfPrecision;
|
|
@@ -5093,7 +5093,7 @@ var require_limitLength = __commonJS({
|
|
|
5093
5093
|
var codegen_1 = require_codegen();
|
|
5094
5094
|
var util_1 = require_util();
|
|
5095
5095
|
var ucs2length_1 = require_ucs2length();
|
|
5096
|
-
var
|
|
5096
|
+
var error4 = {
|
|
5097
5097
|
message({ keyword, schemaCode }) {
|
|
5098
5098
|
const comp = keyword === "maxLength" ? "more" : "fewer";
|
|
5099
5099
|
return (0, codegen_1.str)`must NOT have ${comp} than ${schemaCode} characters`;
|
|
@@ -5105,7 +5105,7 @@ var require_limitLength = __commonJS({
|
|
|
5105
5105
|
type: "string",
|
|
5106
5106
|
schemaType: "number",
|
|
5107
5107
|
$data: true,
|
|
5108
|
-
error:
|
|
5108
|
+
error: error4,
|
|
5109
5109
|
code(cxt) {
|
|
5110
5110
|
const { keyword, data, schemaCode, it: it2 } = cxt;
|
|
5111
5111
|
const op = keyword === "maxLength" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
@@ -5125,7 +5125,7 @@ var require_pattern = __commonJS({
|
|
|
5125
5125
|
var code_1 = require_code2();
|
|
5126
5126
|
var util_1 = require_util();
|
|
5127
5127
|
var codegen_1 = require_codegen();
|
|
5128
|
-
var
|
|
5128
|
+
var error4 = {
|
|
5129
5129
|
message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
|
|
5130
5130
|
params: ({ schemaCode }) => (0, codegen_1._)`{pattern: ${schemaCode}}`
|
|
5131
5131
|
};
|
|
@@ -5134,7 +5134,7 @@ var require_pattern = __commonJS({
|
|
|
5134
5134
|
type: "string",
|
|
5135
5135
|
schemaType: "string",
|
|
5136
5136
|
$data: true,
|
|
5137
|
-
error:
|
|
5137
|
+
error: error4,
|
|
5138
5138
|
code(cxt) {
|
|
5139
5139
|
const { gen, data, $data, schema, schemaCode, it: it2 } = cxt;
|
|
5140
5140
|
const u2 = it2.opts.unicodeRegExp ? "u" : "";
|
|
@@ -5160,7 +5160,7 @@ var require_limitProperties = __commonJS({
|
|
|
5160
5160
|
"use strict";
|
|
5161
5161
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5162
5162
|
var codegen_1 = require_codegen();
|
|
5163
|
-
var
|
|
5163
|
+
var error4 = {
|
|
5164
5164
|
message({ keyword, schemaCode }) {
|
|
5165
5165
|
const comp = keyword === "maxProperties" ? "more" : "fewer";
|
|
5166
5166
|
return (0, codegen_1.str)`must NOT have ${comp} than ${schemaCode} properties`;
|
|
@@ -5172,7 +5172,7 @@ var require_limitProperties = __commonJS({
|
|
|
5172
5172
|
type: "object",
|
|
5173
5173
|
schemaType: "number",
|
|
5174
5174
|
$data: true,
|
|
5175
|
-
error:
|
|
5175
|
+
error: error4,
|
|
5176
5176
|
code(cxt) {
|
|
5177
5177
|
const { keyword, data, schemaCode } = cxt;
|
|
5178
5178
|
const op = keyword === "maxProperties" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
@@ -5191,7 +5191,7 @@ var require_required = __commonJS({
|
|
|
5191
5191
|
var code_1 = require_code2();
|
|
5192
5192
|
var codegen_1 = require_codegen();
|
|
5193
5193
|
var util_1 = require_util();
|
|
5194
|
-
var
|
|
5194
|
+
var error4 = {
|
|
5195
5195
|
message: ({ params: { missingProperty } }) => (0, codegen_1.str)`must have required property '${missingProperty}'`,
|
|
5196
5196
|
params: ({ params: { missingProperty } }) => (0, codegen_1._)`{missingProperty: ${missingProperty}}`
|
|
5197
5197
|
};
|
|
@@ -5200,7 +5200,7 @@ var require_required = __commonJS({
|
|
|
5200
5200
|
type: "object",
|
|
5201
5201
|
schemaType: "array",
|
|
5202
5202
|
$data: true,
|
|
5203
|
-
error:
|
|
5203
|
+
error: error4,
|
|
5204
5204
|
code(cxt) {
|
|
5205
5205
|
const { gen, schema, schemaCode, data, $data, it: it2 } = cxt;
|
|
5206
5206
|
const { opts } = it2;
|
|
@@ -5271,7 +5271,7 @@ var require_limitItems = __commonJS({
|
|
|
5271
5271
|
"use strict";
|
|
5272
5272
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5273
5273
|
var codegen_1 = require_codegen();
|
|
5274
|
-
var
|
|
5274
|
+
var error4 = {
|
|
5275
5275
|
message({ keyword, schemaCode }) {
|
|
5276
5276
|
const comp = keyword === "maxItems" ? "more" : "fewer";
|
|
5277
5277
|
return (0, codegen_1.str)`must NOT have ${comp} than ${schemaCode} items`;
|
|
@@ -5283,7 +5283,7 @@ var require_limitItems = __commonJS({
|
|
|
5283
5283
|
type: "array",
|
|
5284
5284
|
schemaType: "number",
|
|
5285
5285
|
$data: true,
|
|
5286
|
-
error:
|
|
5286
|
+
error: error4,
|
|
5287
5287
|
code(cxt) {
|
|
5288
5288
|
const { keyword, data, schemaCode } = cxt;
|
|
5289
5289
|
const op = keyword === "maxItems" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
@@ -5314,7 +5314,7 @@ var require_uniqueItems = __commonJS({
|
|
|
5314
5314
|
var codegen_1 = require_codegen();
|
|
5315
5315
|
var util_1 = require_util();
|
|
5316
5316
|
var equal_1 = require_equal();
|
|
5317
|
-
var
|
|
5317
|
+
var error4 = {
|
|
5318
5318
|
message: ({ params: { i, j: j2 } }) => (0, codegen_1.str)`must NOT have duplicate items (items ## ${j2} and ${i} are identical)`,
|
|
5319
5319
|
params: ({ params: { i, j: j2 } }) => (0, codegen_1._)`{i: ${i}, j: ${j2}}`
|
|
5320
5320
|
};
|
|
@@ -5323,7 +5323,7 @@ var require_uniqueItems = __commonJS({
|
|
|
5323
5323
|
type: "array",
|
|
5324
5324
|
schemaType: "boolean",
|
|
5325
5325
|
$data: true,
|
|
5326
|
-
error:
|
|
5326
|
+
error: error4,
|
|
5327
5327
|
code(cxt) {
|
|
5328
5328
|
const { gen, data, $data, schema, parentSchema, schemaCode, it: it2 } = cxt;
|
|
5329
5329
|
if (!$data && !schema)
|
|
@@ -5380,14 +5380,14 @@ var require_const = __commonJS({
|
|
|
5380
5380
|
var codegen_1 = require_codegen();
|
|
5381
5381
|
var util_1 = require_util();
|
|
5382
5382
|
var equal_1 = require_equal();
|
|
5383
|
-
var
|
|
5383
|
+
var error4 = {
|
|
5384
5384
|
message: "must be equal to constant",
|
|
5385
5385
|
params: ({ schemaCode }) => (0, codegen_1._)`{allowedValue: ${schemaCode}}`
|
|
5386
5386
|
};
|
|
5387
5387
|
var def = {
|
|
5388
5388
|
keyword: "const",
|
|
5389
5389
|
$data: true,
|
|
5390
|
-
error:
|
|
5390
|
+
error: error4,
|
|
5391
5391
|
code(cxt) {
|
|
5392
5392
|
const { gen, data, $data, schemaCode, schema } = cxt;
|
|
5393
5393
|
if ($data || schema && typeof schema == "object") {
|
|
@@ -5409,7 +5409,7 @@ var require_enum = __commonJS({
|
|
|
5409
5409
|
var codegen_1 = require_codegen();
|
|
5410
5410
|
var util_1 = require_util();
|
|
5411
5411
|
var equal_1 = require_equal();
|
|
5412
|
-
var
|
|
5412
|
+
var error4 = {
|
|
5413
5413
|
message: "must be equal to one of the allowed values",
|
|
5414
5414
|
params: ({ schemaCode }) => (0, codegen_1._)`{allowedValues: ${schemaCode}}`
|
|
5415
5415
|
};
|
|
@@ -5417,7 +5417,7 @@ var require_enum = __commonJS({
|
|
|
5417
5417
|
keyword: "enum",
|
|
5418
5418
|
schemaType: "array",
|
|
5419
5419
|
$data: true,
|
|
5420
|
-
error:
|
|
5420
|
+
error: error4,
|
|
5421
5421
|
code(cxt) {
|
|
5422
5422
|
const { gen, data, $data, schema, schemaCode, it: it2 } = cxt;
|
|
5423
5423
|
if (!$data && schema.length === 0)
|
|
@@ -5496,7 +5496,7 @@ var require_additionalItems = __commonJS({
|
|
|
5496
5496
|
exports.validateAdditionalItems = void 0;
|
|
5497
5497
|
var codegen_1 = require_codegen();
|
|
5498
5498
|
var util_1 = require_util();
|
|
5499
|
-
var
|
|
5499
|
+
var error4 = {
|
|
5500
5500
|
message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
|
|
5501
5501
|
params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
|
|
5502
5502
|
};
|
|
@@ -5505,7 +5505,7 @@ var require_additionalItems = __commonJS({
|
|
|
5505
5505
|
type: "array",
|
|
5506
5506
|
schemaType: ["boolean", "object"],
|
|
5507
5507
|
before: "uniqueItems",
|
|
5508
|
-
error:
|
|
5508
|
+
error: error4,
|
|
5509
5509
|
code(cxt) {
|
|
5510
5510
|
const { parentSchema, it: it2 } = cxt;
|
|
5511
5511
|
const { items } = parentSchema;
|
|
@@ -5624,7 +5624,7 @@ var require_items2020 = __commonJS({
|
|
|
5624
5624
|
var util_1 = require_util();
|
|
5625
5625
|
var code_1 = require_code2();
|
|
5626
5626
|
var additionalItems_1 = require_additionalItems();
|
|
5627
|
-
var
|
|
5627
|
+
var error4 = {
|
|
5628
5628
|
message: ({ params: { len } }) => (0, codegen_1.str)`must NOT have more than ${len} items`,
|
|
5629
5629
|
params: ({ params: { len } }) => (0, codegen_1._)`{limit: ${len}}`
|
|
5630
5630
|
};
|
|
@@ -5633,7 +5633,7 @@ var require_items2020 = __commonJS({
|
|
|
5633
5633
|
type: "array",
|
|
5634
5634
|
schemaType: ["object", "boolean"],
|
|
5635
5635
|
before: "uniqueItems",
|
|
5636
|
-
error:
|
|
5636
|
+
error: error4,
|
|
5637
5637
|
code(cxt) {
|
|
5638
5638
|
const { schema, parentSchema, it: it2 } = cxt;
|
|
5639
5639
|
const { prefixItems } = parentSchema;
|
|
@@ -5657,7 +5657,7 @@ var require_contains = __commonJS({
|
|
|
5657
5657
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5658
5658
|
var codegen_1 = require_codegen();
|
|
5659
5659
|
var util_1 = require_util();
|
|
5660
|
-
var
|
|
5660
|
+
var error4 = {
|
|
5661
5661
|
message: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1.str)`must contain at least ${min} valid item(s)` : (0, codegen_1.str)`must contain at least ${min} and no more than ${max} valid item(s)`,
|
|
5662
5662
|
params: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1._)`{minContains: ${min}}` : (0, codegen_1._)`{minContains: ${min}, maxContains: ${max}}`
|
|
5663
5663
|
};
|
|
@@ -5667,7 +5667,7 @@ var require_contains = __commonJS({
|
|
|
5667
5667
|
schemaType: ["object", "boolean"],
|
|
5668
5668
|
before: "uniqueItems",
|
|
5669
5669
|
trackErrors: true,
|
|
5670
|
-
error:
|
|
5670
|
+
error: error4,
|
|
5671
5671
|
code(cxt) {
|
|
5672
5672
|
const { gen, schema, parentSchema, data, it: it2 } = cxt;
|
|
5673
5673
|
let min;
|
|
@@ -5845,7 +5845,7 @@ var require_propertyNames = __commonJS({
|
|
|
5845
5845
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5846
5846
|
var codegen_1 = require_codegen();
|
|
5847
5847
|
var util_1 = require_util();
|
|
5848
|
-
var
|
|
5848
|
+
var error4 = {
|
|
5849
5849
|
message: "property name must be valid",
|
|
5850
5850
|
params: ({ params }) => (0, codegen_1._)`{propertyName: ${params.propertyName}}`
|
|
5851
5851
|
};
|
|
@@ -5853,7 +5853,7 @@ var require_propertyNames = __commonJS({
|
|
|
5853
5853
|
keyword: "propertyNames",
|
|
5854
5854
|
type: "object",
|
|
5855
5855
|
schemaType: ["object", "boolean"],
|
|
5856
|
-
error:
|
|
5856
|
+
error: error4,
|
|
5857
5857
|
code(cxt) {
|
|
5858
5858
|
const { gen, schema, data, it: it2 } = cxt;
|
|
5859
5859
|
if ((0, util_1.alwaysValidSchema)(it2, schema))
|
|
@@ -5890,7 +5890,7 @@ var require_additionalProperties = __commonJS({
|
|
|
5890
5890
|
var codegen_1 = require_codegen();
|
|
5891
5891
|
var names_1 = require_names();
|
|
5892
5892
|
var util_1 = require_util();
|
|
5893
|
-
var
|
|
5893
|
+
var error4 = {
|
|
5894
5894
|
message: "must NOT have additional properties",
|
|
5895
5895
|
params: ({ params }) => (0, codegen_1._)`{additionalProperty: ${params.additionalProperty}}`
|
|
5896
5896
|
};
|
|
@@ -5900,7 +5900,7 @@ var require_additionalProperties = __commonJS({
|
|
|
5900
5900
|
schemaType: ["boolean", "object"],
|
|
5901
5901
|
allowUndefined: true,
|
|
5902
5902
|
trackErrors: true,
|
|
5903
|
-
error:
|
|
5903
|
+
error: error4,
|
|
5904
5904
|
code(cxt) {
|
|
5905
5905
|
const { gen, schema, parentSchema, data, errsCount, it: it2 } = cxt;
|
|
5906
5906
|
if (!errsCount)
|
|
@@ -6174,7 +6174,7 @@ var require_oneOf = __commonJS({
|
|
|
6174
6174
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6175
6175
|
var codegen_1 = require_codegen();
|
|
6176
6176
|
var util_1 = require_util();
|
|
6177
|
-
var
|
|
6177
|
+
var error4 = {
|
|
6178
6178
|
message: "must match exactly one schema in oneOf",
|
|
6179
6179
|
params: ({ params }) => (0, codegen_1._)`{passingSchemas: ${params.passing}}`
|
|
6180
6180
|
};
|
|
@@ -6182,7 +6182,7 @@ var require_oneOf = __commonJS({
|
|
|
6182
6182
|
keyword: "oneOf",
|
|
6183
6183
|
schemaType: "array",
|
|
6184
6184
|
trackErrors: true,
|
|
6185
|
-
error:
|
|
6185
|
+
error: error4,
|
|
6186
6186
|
code(cxt) {
|
|
6187
6187
|
const { gen, schema, parentSchema, it: it2 } = cxt;
|
|
6188
6188
|
if (!Array.isArray(schema))
|
|
@@ -6259,7 +6259,7 @@ var require_if = __commonJS({
|
|
|
6259
6259
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6260
6260
|
var codegen_1 = require_codegen();
|
|
6261
6261
|
var util_1 = require_util();
|
|
6262
|
-
var
|
|
6262
|
+
var error4 = {
|
|
6263
6263
|
message: ({ params }) => (0, codegen_1.str)`must match "${params.ifClause}" schema`,
|
|
6264
6264
|
params: ({ params }) => (0, codegen_1._)`{failingKeyword: ${params.ifClause}}`
|
|
6265
6265
|
};
|
|
@@ -6267,7 +6267,7 @@ var require_if = __commonJS({
|
|
|
6267
6267
|
keyword: "if",
|
|
6268
6268
|
schemaType: ["object", "boolean"],
|
|
6269
6269
|
trackErrors: true,
|
|
6270
|
-
error:
|
|
6270
|
+
error: error4,
|
|
6271
6271
|
code(cxt) {
|
|
6272
6272
|
const { gen, parentSchema, it: it2 } = cxt;
|
|
6273
6273
|
if (parentSchema.then === void 0 && parentSchema.else === void 0) {
|
|
@@ -6393,7 +6393,7 @@ var require_format = __commonJS({
|
|
|
6393
6393
|
"use strict";
|
|
6394
6394
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6395
6395
|
var codegen_1 = require_codegen();
|
|
6396
|
-
var
|
|
6396
|
+
var error4 = {
|
|
6397
6397
|
message: ({ schemaCode }) => (0, codegen_1.str)`must match format "${schemaCode}"`,
|
|
6398
6398
|
params: ({ schemaCode }) => (0, codegen_1._)`{format: ${schemaCode}}`
|
|
6399
6399
|
};
|
|
@@ -6402,7 +6402,7 @@ var require_format = __commonJS({
|
|
|
6402
6402
|
type: ["number", "string"],
|
|
6403
6403
|
schemaType: "string",
|
|
6404
6404
|
$data: true,
|
|
6405
|
-
error:
|
|
6405
|
+
error: error4,
|
|
6406
6406
|
code(cxt, ruleType) {
|
|
6407
6407
|
const { gen, data, $data, schema, schemaCode, it: it2 } = cxt;
|
|
6408
6408
|
const { opts, errSchemaPath, schemaEnv, self } = it2;
|
|
@@ -6557,7 +6557,7 @@ var require_discriminator = __commonJS({
|
|
|
6557
6557
|
var compile_1 = require_compile();
|
|
6558
6558
|
var ref_error_1 = require_ref_error();
|
|
6559
6559
|
var util_1 = require_util();
|
|
6560
|
-
var
|
|
6560
|
+
var error4 = {
|
|
6561
6561
|
message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag ? `tag "${tagName}" must be string` : `value of tag "${tagName}" must be in oneOf`,
|
|
6562
6562
|
params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._)`{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`
|
|
6563
6563
|
};
|
|
@@ -6565,7 +6565,7 @@ var require_discriminator = __commonJS({
|
|
|
6565
6565
|
keyword: "discriminator",
|
|
6566
6566
|
type: "object",
|
|
6567
6567
|
schemaType: "object",
|
|
6568
|
-
error:
|
|
6568
|
+
error: error4,
|
|
6569
6569
|
code(cxt) {
|
|
6570
6570
|
const { gen, data, schema, parentSchema, it: it2 } = cxt;
|
|
6571
6571
|
const { oneOf } = parentSchema;
|
|
@@ -7097,7 +7097,7 @@ var require_limit = __commonJS({
|
|
|
7097
7097
|
formatExclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
|
|
7098
7098
|
formatExclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE }
|
|
7099
7099
|
};
|
|
7100
|
-
var
|
|
7100
|
+
var error4 = {
|
|
7101
7101
|
message: ({ keyword, schemaCode }) => (0, codegen_1.str)`should be ${KWDs[keyword].okStr} ${schemaCode}`,
|
|
7102
7102
|
params: ({ keyword, schemaCode }) => (0, codegen_1._)`{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`
|
|
7103
7103
|
};
|
|
@@ -7106,7 +7106,7 @@ var require_limit = __commonJS({
|
|
|
7106
7106
|
type: "string",
|
|
7107
7107
|
schemaType: "string",
|
|
7108
7108
|
$data: true,
|
|
7109
|
-
error:
|
|
7109
|
+
error: error4,
|
|
7110
7110
|
code(cxt) {
|
|
7111
7111
|
const { gen, data, schemaCode, keyword, it: it2 } = cxt;
|
|
7112
7112
|
const { opts, self } = it2;
|
|
@@ -7301,11 +7301,11 @@ var require_content_type = __commonJS({
|
|
|
7301
7301
|
});
|
|
7302
7302
|
|
|
7303
7303
|
// lib/version.mjs
|
|
7304
|
-
var CLIENT_VERSION = "0.3.
|
|
7304
|
+
var CLIENT_VERSION = "0.3.1";
|
|
7305
7305
|
var CLIENT_PROTOCOL = "creation-client/v1";
|
|
7306
7306
|
|
|
7307
7307
|
// lib/cli.mjs
|
|
7308
|
-
import { randomBytes as
|
|
7308
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
7309
7309
|
import { spawn as spawn2 } from "node:child_process";
|
|
7310
7310
|
|
|
7311
7311
|
// node_modules/zod/v4/core/util.js
|
|
@@ -7545,10 +7545,10 @@ function mergeDefs(...defs) {
|
|
|
7545
7545
|
function cloneDef(schema) {
|
|
7546
7546
|
return mergeDefs(schema._zod.def);
|
|
7547
7547
|
}
|
|
7548
|
-
function getElementAtPath(obj,
|
|
7549
|
-
if (!
|
|
7548
|
+
function getElementAtPath(obj, path14) {
|
|
7549
|
+
if (!path14)
|
|
7550
7550
|
return obj;
|
|
7551
|
-
return
|
|
7551
|
+
return path14.reduce((acc, key) => acc?.[key], obj);
|
|
7552
7552
|
}
|
|
7553
7553
|
function promiseAllObject(promisesObj) {
|
|
7554
7554
|
const keys = Object.keys(promisesObj);
|
|
@@ -7888,11 +7888,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
7888
7888
|
}
|
|
7889
7889
|
return false;
|
|
7890
7890
|
}
|
|
7891
|
-
function prefixIssues(
|
|
7891
|
+
function prefixIssues(path14, issues) {
|
|
7892
7892
|
return issues.map((iss) => {
|
|
7893
7893
|
var _a3;
|
|
7894
7894
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
7895
|
-
iss.path.unshift(
|
|
7895
|
+
iss.path.unshift(path14);
|
|
7896
7896
|
return iss;
|
|
7897
7897
|
});
|
|
7898
7898
|
}
|
|
@@ -8032,8 +8032,8 @@ function base64urlToUint8Array(base64url2) {
|
|
|
8032
8032
|
function uint8ArrayToBase64url(bytes2) {
|
|
8033
8033
|
return uint8ArrayToBase64(bytes2).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
8034
8034
|
}
|
|
8035
|
-
function hexToUint8Array(
|
|
8036
|
-
const cleanHex =
|
|
8035
|
+
function hexToUint8Array(hex2) {
|
|
8036
|
+
const cleanHex = hex2.replace(/^0x/, "");
|
|
8037
8037
|
if (cleanHex.length % 2 !== 0) {
|
|
8038
8038
|
throw new Error("Invalid hex string length");
|
|
8039
8039
|
}
|
|
@@ -8339,10 +8339,10 @@ function node(obj, key, make) {
|
|
|
8339
8339
|
}
|
|
8340
8340
|
return obj[key];
|
|
8341
8341
|
}
|
|
8342
|
-
function flattenError(
|
|
8342
|
+
function flattenError(error4, mapper = (issue2) => issue2.message) {
|
|
8343
8343
|
const fieldErrors = {};
|
|
8344
8344
|
const formErrors = [];
|
|
8345
|
-
for (const sub of
|
|
8345
|
+
for (const sub of error4.issues) {
|
|
8346
8346
|
if (sub.path.length > 0) {
|
|
8347
8347
|
node(fieldErrors, sub.path[0], () => []).push(mapper(sub));
|
|
8348
8348
|
} else {
|
|
@@ -8351,18 +8351,18 @@ function flattenError(error3, mapper = (issue2) => issue2.message) {
|
|
|
8351
8351
|
}
|
|
8352
8352
|
return { formErrors, fieldErrors };
|
|
8353
8353
|
}
|
|
8354
|
-
function formatError(
|
|
8354
|
+
function formatError(error4, mapper = (issue2) => issue2.message) {
|
|
8355
8355
|
const fieldErrors = { _errors: [] };
|
|
8356
|
-
const processError = (
|
|
8357
|
-
for (const issue2 of
|
|
8356
|
+
const processError = (error5, path14 = []) => {
|
|
8357
|
+
for (const issue2 of error5.issues) {
|
|
8358
8358
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
8359
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
8359
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
8360
8360
|
} else if (issue2.code === "invalid_key") {
|
|
8361
|
-
processError({ issues: issue2.issues }, [...
|
|
8361
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
8362
8362
|
} else if (issue2.code === "invalid_element") {
|
|
8363
|
-
processError({ issues: issue2.issues }, [...
|
|
8363
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
8364
8364
|
} else {
|
|
8365
|
-
const fullpath = [...
|
|
8365
|
+
const fullpath = [...path14, ...issue2.path];
|
|
8366
8366
|
if (fullpath.length === 0) {
|
|
8367
8367
|
fieldErrors._errors.push(mapper(issue2));
|
|
8368
8368
|
} else {
|
|
@@ -8396,7 +8396,7 @@ function formatError(error3, mapper = (issue2) => issue2.message) {
|
|
|
8396
8396
|
}
|
|
8397
8397
|
}
|
|
8398
8398
|
};
|
|
8399
|
-
processError(
|
|
8399
|
+
processError(error4);
|
|
8400
8400
|
return fieldErrors;
|
|
8401
8401
|
}
|
|
8402
8402
|
|
|
@@ -8445,19 +8445,19 @@ var _safeParse = (_Err) => (schema, value2, _ctx) => {
|
|
|
8445
8445
|
};
|
|
8446
8446
|
var safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
8447
8447
|
function failure(Err, issues, ctx) {
|
|
8448
|
-
let
|
|
8448
|
+
let error4;
|
|
8449
8449
|
return {
|
|
8450
8450
|
success: false,
|
|
8451
8451
|
get error() {
|
|
8452
|
-
if (!
|
|
8453
|
-
|
|
8452
|
+
if (!error4) {
|
|
8453
|
+
error4 = new Err(issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
8454
8454
|
issues = void 0;
|
|
8455
8455
|
ctx = void 0;
|
|
8456
8456
|
}
|
|
8457
|
-
return
|
|
8457
|
+
return error4;
|
|
8458
8458
|
},
|
|
8459
8459
|
set error(e) {
|
|
8460
|
-
|
|
8460
|
+
error4 = e;
|
|
8461
8461
|
issues = void 0;
|
|
8462
8462
|
ctx = void 0;
|
|
8463
8463
|
}
|
|
@@ -15598,8 +15598,8 @@ var Protocol = class {
|
|
|
15598
15598
|
resolver(message);
|
|
15599
15599
|
} else {
|
|
15600
15600
|
const errorMessage = message;
|
|
15601
|
-
const
|
|
15602
|
-
resolver(
|
|
15601
|
+
const error4 = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
|
|
15602
|
+
resolver(error4);
|
|
15603
15603
|
}
|
|
15604
15604
|
} else {
|
|
15605
15605
|
const messageType = queuedMessage.type === "response" ? "Response" : "Error";
|
|
@@ -15643,8 +15643,8 @@ var Protocol = class {
|
|
|
15643
15643
|
nextCursor,
|
|
15644
15644
|
_meta: {}
|
|
15645
15645
|
};
|
|
15646
|
-
} catch (
|
|
15647
|
-
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${
|
|
15646
|
+
} catch (error4) {
|
|
15647
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error4 instanceof Error ? error4.message : String(error4)}`);
|
|
15648
15648
|
}
|
|
15649
15649
|
});
|
|
15650
15650
|
this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
|
|
@@ -15666,11 +15666,11 @@ var Protocol = class {
|
|
|
15666
15666
|
_meta: {},
|
|
15667
15667
|
...cancelledTask
|
|
15668
15668
|
};
|
|
15669
|
-
} catch (
|
|
15670
|
-
if (
|
|
15671
|
-
throw
|
|
15669
|
+
} catch (error4) {
|
|
15670
|
+
if (error4 instanceof McpError) {
|
|
15671
|
+
throw error4;
|
|
15672
15672
|
}
|
|
15673
|
-
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${
|
|
15673
|
+
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error4 instanceof Error ? error4.message : String(error4)}`);
|
|
15674
15674
|
}
|
|
15675
15675
|
});
|
|
15676
15676
|
}
|
|
@@ -15731,9 +15731,9 @@ var Protocol = class {
|
|
|
15731
15731
|
this._onclose();
|
|
15732
15732
|
};
|
|
15733
15733
|
const _onerror = this.transport?.onerror;
|
|
15734
|
-
this._transport.onerror = (
|
|
15735
|
-
_onerror?.(
|
|
15736
|
-
this._onerror(
|
|
15734
|
+
this._transport.onerror = (error4) => {
|
|
15735
|
+
_onerror?.(error4);
|
|
15736
|
+
this._onerror(error4);
|
|
15737
15737
|
};
|
|
15738
15738
|
const _onmessage = this._transport?.onmessage;
|
|
15739
15739
|
this._transport.onmessage = (message, extra) => {
|
|
@@ -15764,22 +15764,22 @@ var Protocol = class {
|
|
|
15764
15764
|
controller.abort();
|
|
15765
15765
|
}
|
|
15766
15766
|
this._requestHandlerAbortControllers.clear();
|
|
15767
|
-
const
|
|
15767
|
+
const error4 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
15768
15768
|
this._transport = void 0;
|
|
15769
15769
|
this.onclose?.();
|
|
15770
15770
|
for (const handler of responseHandlers.values()) {
|
|
15771
|
-
handler(
|
|
15771
|
+
handler(error4);
|
|
15772
15772
|
}
|
|
15773
15773
|
}
|
|
15774
|
-
_onerror(
|
|
15775
|
-
this.onerror?.(
|
|
15774
|
+
_onerror(error4) {
|
|
15775
|
+
this.onerror?.(error4);
|
|
15776
15776
|
}
|
|
15777
15777
|
_onnotification(notification) {
|
|
15778
15778
|
const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
|
|
15779
15779
|
if (handler === void 0) {
|
|
15780
15780
|
return;
|
|
15781
15781
|
}
|
|
15782
|
-
Promise.resolve().then(() => handler(notification)).catch((
|
|
15782
|
+
Promise.resolve().then(() => handler(notification)).catch((error4) => this._onerror(new Error(`Uncaught error in notification handler: ${error4}`)));
|
|
15783
15783
|
}
|
|
15784
15784
|
_onrequest(request, extra) {
|
|
15785
15785
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
@@ -15809,15 +15809,15 @@ var Protocol = class {
|
|
|
15809
15809
|
};
|
|
15810
15810
|
if (relatedTaskId && relatedTaskLookup) {
|
|
15811
15811
|
const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
|
|
15812
|
-
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((
|
|
15812
|
+
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error4) => this._onerror(new Error(`Failed to send an error response: ${error4}`)));
|
|
15813
15813
|
} else if (relatedTaskId && this._taskMessageQueue) {
|
|
15814
15814
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
15815
15815
|
type: "error",
|
|
15816
15816
|
message: errorResponse,
|
|
15817
15817
|
timestamp: Date.now()
|
|
15818
|
-
}, capturedTransport?.sessionId).catch((
|
|
15818
|
+
}, capturedTransport?.sessionId).catch((error4) => this._onerror(new Error(`Failed to enqueue error response: ${error4}`)));
|
|
15819
15819
|
} else {
|
|
15820
|
-
capturedTransport?.send(errorResponse).catch((
|
|
15820
|
+
capturedTransport?.send(errorResponse).catch((error4) => this._onerror(new Error(`Failed to send an error response: ${error4}`)));
|
|
15821
15821
|
}
|
|
15822
15822
|
return;
|
|
15823
15823
|
}
|
|
@@ -15886,7 +15886,7 @@ var Protocol = class {
|
|
|
15886
15886
|
} else {
|
|
15887
15887
|
await capturedTransport?.send(response);
|
|
15888
15888
|
}
|
|
15889
|
-
}, async (
|
|
15889
|
+
}, async (error4) => {
|
|
15890
15890
|
if (abortController.signal.aborted) {
|
|
15891
15891
|
return;
|
|
15892
15892
|
}
|
|
@@ -15894,9 +15894,9 @@ var Protocol = class {
|
|
|
15894
15894
|
jsonrpc: "2.0",
|
|
15895
15895
|
id: request.id,
|
|
15896
15896
|
error: {
|
|
15897
|
-
code: Number.isSafeInteger(
|
|
15898
|
-
message:
|
|
15899
|
-
...
|
|
15897
|
+
code: Number.isSafeInteger(error4["code"]) ? error4["code"] : ErrorCode.InternalError,
|
|
15898
|
+
message: error4.message ?? "Internal error",
|
|
15899
|
+
...error4["data"] !== void 0 && { data: error4["data"] }
|
|
15900
15900
|
}
|
|
15901
15901
|
};
|
|
15902
15902
|
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
@@ -15908,7 +15908,7 @@ var Protocol = class {
|
|
|
15908
15908
|
} else {
|
|
15909
15909
|
await capturedTransport?.send(errorResponse);
|
|
15910
15910
|
}
|
|
15911
|
-
}).catch((
|
|
15911
|
+
}).catch((error4) => this._onerror(new Error(`Failed to send response: ${error4}`))).finally(() => {
|
|
15912
15912
|
if (this._requestHandlerAbortControllers.get(request.id) === abortController) {
|
|
15913
15913
|
this._requestHandlerAbortControllers.delete(request.id);
|
|
15914
15914
|
}
|
|
@@ -15927,11 +15927,11 @@ var Protocol = class {
|
|
|
15927
15927
|
if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) {
|
|
15928
15928
|
try {
|
|
15929
15929
|
this._resetTimeout(messageId);
|
|
15930
|
-
} catch (
|
|
15930
|
+
} catch (error4) {
|
|
15931
15931
|
this._responseHandlers.delete(messageId);
|
|
15932
15932
|
this._progressHandlers.delete(messageId);
|
|
15933
15933
|
this._cleanupTimeout(messageId);
|
|
15934
|
-
responseHandler(
|
|
15934
|
+
responseHandler(error4);
|
|
15935
15935
|
return;
|
|
15936
15936
|
}
|
|
15937
15937
|
}
|
|
@@ -15945,8 +15945,8 @@ var Protocol = class {
|
|
|
15945
15945
|
if (isJSONRPCResultResponse(response)) {
|
|
15946
15946
|
resolver(response);
|
|
15947
15947
|
} else {
|
|
15948
|
-
const
|
|
15949
|
-
resolver(
|
|
15948
|
+
const error4 = new McpError(response.error.code, response.error.message, response.error.data);
|
|
15949
|
+
resolver(error4);
|
|
15950
15950
|
}
|
|
15951
15951
|
return;
|
|
15952
15952
|
}
|
|
@@ -15974,8 +15974,8 @@ var Protocol = class {
|
|
|
15974
15974
|
if (isJSONRPCResultResponse(response)) {
|
|
15975
15975
|
handler(response);
|
|
15976
15976
|
} else {
|
|
15977
|
-
const
|
|
15978
|
-
handler(
|
|
15977
|
+
const error4 = McpError.fromError(response.error.code, response.error.message, response.error.data);
|
|
15978
|
+
handler(error4);
|
|
15979
15979
|
}
|
|
15980
15980
|
}
|
|
15981
15981
|
get transport() {
|
|
@@ -16020,10 +16020,10 @@ var Protocol = class {
|
|
|
16020
16020
|
try {
|
|
16021
16021
|
const result = await this.request(request, resultSchema, options);
|
|
16022
16022
|
yield { type: "result", result };
|
|
16023
|
-
} catch (
|
|
16023
|
+
} catch (error4) {
|
|
16024
16024
|
yield {
|
|
16025
16025
|
type: "error",
|
|
16026
|
-
error:
|
|
16026
|
+
error: error4 instanceof McpError ? error4 : new McpError(ErrorCode.InternalError, String(error4))
|
|
16027
16027
|
};
|
|
16028
16028
|
}
|
|
16029
16029
|
return;
|
|
@@ -16066,10 +16066,10 @@ var Protocol = class {
|
|
|
16066
16066
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
16067
16067
|
options?.signal?.throwIfAborted();
|
|
16068
16068
|
}
|
|
16069
|
-
} catch (
|
|
16069
|
+
} catch (error4) {
|
|
16070
16070
|
yield {
|
|
16071
16071
|
type: "error",
|
|
16072
|
-
error:
|
|
16072
|
+
error: error4 instanceof McpError ? error4 : new McpError(ErrorCode.InternalError, String(error4))
|
|
16073
16073
|
};
|
|
16074
16074
|
}
|
|
16075
16075
|
}
|
|
@@ -16081,8 +16081,8 @@ var Protocol = class {
|
|
|
16081
16081
|
request(request, resultSchema, options) {
|
|
16082
16082
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
16083
16083
|
return new Promise((resolve, reject) => {
|
|
16084
|
-
const earlyReject = (
|
|
16085
|
-
reject(
|
|
16084
|
+
const earlyReject = (error4) => {
|
|
16085
|
+
reject(error4);
|
|
16086
16086
|
};
|
|
16087
16087
|
if (!this._transport) {
|
|
16088
16088
|
earlyReject(new Error("Not connected"));
|
|
@@ -16142,9 +16142,9 @@ var Protocol = class {
|
|
|
16142
16142
|
requestId: messageId,
|
|
16143
16143
|
reason: String(reason)
|
|
16144
16144
|
}
|
|
16145
|
-
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
16146
|
-
const
|
|
16147
|
-
reject(
|
|
16145
|
+
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error5) => this._onerror(new Error(`Failed to send cancellation: ${error5}`)));
|
|
16146
|
+
const error4 = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason));
|
|
16147
|
+
reject(error4);
|
|
16148
16148
|
};
|
|
16149
16149
|
this._responseHandlers.set(messageId, (response) => {
|
|
16150
16150
|
if (options?.signal?.aborted) {
|
|
@@ -16160,8 +16160,8 @@ var Protocol = class {
|
|
|
16160
16160
|
} else {
|
|
16161
16161
|
resolve(parseResult.data);
|
|
16162
16162
|
}
|
|
16163
|
-
} catch (
|
|
16164
|
-
reject(
|
|
16163
|
+
} catch (error4) {
|
|
16164
|
+
reject(error4);
|
|
16165
16165
|
}
|
|
16166
16166
|
});
|
|
16167
16167
|
options?.signal?.addEventListener("abort", () => {
|
|
@@ -16185,14 +16185,14 @@ var Protocol = class {
|
|
|
16185
16185
|
type: "request",
|
|
16186
16186
|
message: jsonrpcRequest,
|
|
16187
16187
|
timestamp: Date.now()
|
|
16188
|
-
}).catch((
|
|
16188
|
+
}).catch((error4) => {
|
|
16189
16189
|
this._cleanupTimeout(messageId);
|
|
16190
|
-
reject(
|
|
16190
|
+
reject(error4);
|
|
16191
16191
|
});
|
|
16192
16192
|
} else {
|
|
16193
|
-
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
16193
|
+
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error4) => {
|
|
16194
16194
|
this._cleanupTimeout(messageId);
|
|
16195
|
-
reject(
|
|
16195
|
+
reject(error4);
|
|
16196
16196
|
});
|
|
16197
16197
|
}
|
|
16198
16198
|
});
|
|
@@ -16285,7 +16285,7 @@ var Protocol = class {
|
|
|
16285
16285
|
}
|
|
16286
16286
|
};
|
|
16287
16287
|
}
|
|
16288
|
-
this._transport?.send(jsonrpcNotification2, options).catch((
|
|
16288
|
+
this._transport?.send(jsonrpcNotification2, options).catch((error4) => this._onerror(error4));
|
|
16289
16289
|
});
|
|
16290
16290
|
return;
|
|
16291
16291
|
}
|
|
@@ -17139,11 +17139,11 @@ var Server = class extends Protocol {
|
|
|
17139
17139
|
if (!validationResult.valid) {
|
|
17140
17140
|
throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
|
|
17141
17141
|
}
|
|
17142
|
-
} catch (
|
|
17143
|
-
if (
|
|
17144
|
-
throw
|
|
17142
|
+
} catch (error4) {
|
|
17143
|
+
if (error4 instanceof McpError) {
|
|
17144
|
+
throw error4;
|
|
17145
17145
|
}
|
|
17146
|
-
throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${
|
|
17146
|
+
throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error4 instanceof Error ? error4.message : String(error4)}`);
|
|
17147
17147
|
}
|
|
17148
17148
|
}
|
|
17149
17149
|
return result;
|
|
@@ -17255,14 +17255,14 @@ var StdioServerTransport = class {
|
|
|
17255
17255
|
try {
|
|
17256
17256
|
this._readBuffer.append(chunk);
|
|
17257
17257
|
this.processReadBuffer();
|
|
17258
|
-
} catch (
|
|
17259
|
-
this.onerror?.(
|
|
17258
|
+
} catch (error4) {
|
|
17259
|
+
this.onerror?.(error4);
|
|
17260
17260
|
this.close().catch(() => {
|
|
17261
17261
|
});
|
|
17262
17262
|
}
|
|
17263
17263
|
};
|
|
17264
|
-
this._onerror = (
|
|
17265
|
-
this.onerror?.(
|
|
17264
|
+
this._onerror = (error4) => {
|
|
17265
|
+
this.onerror?.(error4);
|
|
17266
17266
|
};
|
|
17267
17267
|
this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
|
|
17268
17268
|
}
|
|
@@ -17285,8 +17285,8 @@ var StdioServerTransport = class {
|
|
|
17285
17285
|
break;
|
|
17286
17286
|
}
|
|
17287
17287
|
this.onmessage?.(message);
|
|
17288
|
-
} catch (
|
|
17289
|
-
this.onerror?.(
|
|
17288
|
+
} catch (error4) {
|
|
17289
|
+
this.onerror?.(error4);
|
|
17290
17290
|
}
|
|
17291
17291
|
}
|
|
17292
17292
|
}
|
|
@@ -17358,9 +17358,9 @@ var secure = async (file, directory = false) => {
|
|
|
17358
17358
|
let info5;
|
|
17359
17359
|
try {
|
|
17360
17360
|
info5 = await lstat(file);
|
|
17361
|
-
} catch (
|
|
17362
|
-
if (
|
|
17363
|
-
throw
|
|
17361
|
+
} catch (error4) {
|
|
17362
|
+
if (error4.code === "ENOENT") return null;
|
|
17363
|
+
throw error4;
|
|
17364
17364
|
}
|
|
17365
17365
|
if (info5.isSymbolicLink() || !(directory ? info5.isDirectory() : info5.isFile()) || info5.uid !== process.getuid?.() || (info5.mode & 63) !== 0)
|
|
17366
17366
|
throw new CreationClientError("credentials.private_owner_required");
|
|
@@ -17393,8 +17393,8 @@ async function writeCredentials(value2, file = credentialsPath()) {
|
|
|
17393
17393
|
});
|
|
17394
17394
|
await rename(temporary, file);
|
|
17395
17395
|
} finally {
|
|
17396
|
-
await unlink(temporary).catch((
|
|
17397
|
-
if (
|
|
17396
|
+
await unlink(temporary).catch((error4) => {
|
|
17397
|
+
if (error4.code !== "ENOENT") throw error4;
|
|
17398
17398
|
});
|
|
17399
17399
|
}
|
|
17400
17400
|
}
|
|
@@ -17470,14 +17470,14 @@ var ExperimentalClientTasks = class {
|
|
|
17470
17470
|
};
|
|
17471
17471
|
return;
|
|
17472
17472
|
}
|
|
17473
|
-
} catch (
|
|
17474
|
-
if (
|
|
17475
|
-
yield { type: "error", error:
|
|
17473
|
+
} catch (error4) {
|
|
17474
|
+
if (error4 instanceof McpError) {
|
|
17475
|
+
yield { type: "error", error: error4 };
|
|
17476
17476
|
return;
|
|
17477
17477
|
}
|
|
17478
17478
|
yield {
|
|
17479
17479
|
type: "error",
|
|
17480
|
-
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${
|
|
17480
|
+
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error4 instanceof Error ? error4.message : String(error4)}`)
|
|
17481
17481
|
};
|
|
17482
17482
|
return;
|
|
17483
17483
|
}
|
|
@@ -17790,9 +17790,9 @@ var Client = class extends Protocol {
|
|
|
17790
17790
|
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
17791
17791
|
this._pendingListChangedConfig = void 0;
|
|
17792
17792
|
}
|
|
17793
|
-
} catch (
|
|
17793
|
+
} catch (error4) {
|
|
17794
17794
|
void this.close();
|
|
17795
|
-
throw
|
|
17795
|
+
throw error4;
|
|
17796
17796
|
}
|
|
17797
17797
|
}
|
|
17798
17798
|
/**
|
|
@@ -17962,11 +17962,11 @@ var Client = class extends Protocol {
|
|
|
17962
17962
|
if (!validationResult.valid) {
|
|
17963
17963
|
throw new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`);
|
|
17964
17964
|
}
|
|
17965
|
-
} catch (
|
|
17966
|
-
if (
|
|
17967
|
-
throw
|
|
17965
|
+
} catch (error4) {
|
|
17966
|
+
if (error4 instanceof McpError) {
|
|
17967
|
+
throw error4;
|
|
17968
17968
|
}
|
|
17969
|
-
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${
|
|
17969
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error4 instanceof Error ? error4.message : String(error4)}`);
|
|
17970
17970
|
}
|
|
17971
17971
|
}
|
|
17972
17972
|
}
|
|
@@ -18041,8 +18041,8 @@ var Client = class extends Protocol {
|
|
|
18041
18041
|
const items = await fetcher();
|
|
18042
18042
|
onChanged(null, items);
|
|
18043
18043
|
} catch (e) {
|
|
18044
|
-
const
|
|
18045
|
-
onChanged(
|
|
18044
|
+
const error4 = e instanceof Error ? e : new Error(String(e));
|
|
18045
|
+
onChanged(error4, null);
|
|
18046
18046
|
}
|
|
18047
18047
|
};
|
|
18048
18048
|
const handler = () => {
|
|
@@ -18183,8 +18183,8 @@ async function random(size) {
|
|
|
18183
18183
|
const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % mask.length;
|
|
18184
18184
|
let result = "";
|
|
18185
18185
|
while (result.length < size) {
|
|
18186
|
-
const
|
|
18187
|
-
for (const randomByte of
|
|
18186
|
+
const randomBytes8 = await getRandomValues(size - result.length);
|
|
18187
|
+
for (const randomByte of randomBytes8) {
|
|
18188
18188
|
if (randomByte < evenDistCutoff) {
|
|
18189
18189
|
result += mask[randomByte % mask.length];
|
|
18190
18190
|
}
|
|
@@ -18549,12 +18549,12 @@ async function parseErrorResponse(input) {
|
|
|
18549
18549
|
const body = input instanceof Response ? await input.text() : input;
|
|
18550
18550
|
try {
|
|
18551
18551
|
const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
|
|
18552
|
-
const { error:
|
|
18553
|
-
const errorClass = OAUTH_ERRORS[
|
|
18552
|
+
const { error: error4, error_description, error_uri } = result;
|
|
18553
|
+
const errorClass = OAUTH_ERRORS[error4] || ServerError;
|
|
18554
18554
|
return new errorClass(error_description || "", error_uri);
|
|
18555
|
-
} catch (
|
|
18555
|
+
} catch (error4) {
|
|
18556
18556
|
const redirect = input instanceof Response ? unfollowedRedirect(input, input.url) : void 0;
|
|
18557
|
-
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${
|
|
18557
|
+
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${error4}. Raw body: ${body}`}`;
|
|
18558
18558
|
return new ServerError(errorMessage);
|
|
18559
18559
|
}
|
|
18560
18560
|
}
|
|
@@ -18581,15 +18581,15 @@ function boundElsewhereError(stored, issuer) {
|
|
|
18581
18581
|
async function auth(provider, options) {
|
|
18582
18582
|
try {
|
|
18583
18583
|
return await authInternal(provider, options);
|
|
18584
|
-
} catch (
|
|
18585
|
-
if (
|
|
18584
|
+
} catch (error4) {
|
|
18585
|
+
if (error4 instanceof InvalidClientError || error4 instanceof UnauthorizedClientError) {
|
|
18586
18586
|
await provider.invalidateCredentials?.("all");
|
|
18587
18587
|
return await authInternal(provider, options);
|
|
18588
|
-
} else if (
|
|
18588
|
+
} else if (error4 instanceof InvalidGrantError) {
|
|
18589
18589
|
await provider.invalidateCredentials?.("tokens");
|
|
18590
18590
|
return await authInternal(provider, options);
|
|
18591
18591
|
}
|
|
18592
|
-
throw
|
|
18592
|
+
throw error4;
|
|
18593
18593
|
}
|
|
18594
18594
|
}
|
|
18595
18595
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
@@ -18705,10 +18705,10 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
18705
18705
|
await bindClientInformation();
|
|
18706
18706
|
await provider.saveTokens({ ...newTokens, issuer });
|
|
18707
18707
|
return "AUTHORIZED";
|
|
18708
|
-
} catch (
|
|
18709
|
-
if (!(
|
|
18708
|
+
} catch (error4) {
|
|
18709
|
+
if (!(error4 instanceof OAuthError) || error4 instanceof ServerError) {
|
|
18710
18710
|
} else {
|
|
18711
|
-
throw
|
|
18711
|
+
throw error4;
|
|
18712
18712
|
}
|
|
18713
18713
|
}
|
|
18714
18714
|
}
|
|
@@ -18766,11 +18766,11 @@ function extractWWWAuthenticateParams(res) {
|
|
|
18766
18766
|
}
|
|
18767
18767
|
}
|
|
18768
18768
|
const scope = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
18769
|
-
const
|
|
18769
|
+
const error4 = extractFieldFromWwwAuth(res, "error") || void 0;
|
|
18770
18770
|
return {
|
|
18771
18771
|
resourceMetadataUrl,
|
|
18772
18772
|
scope,
|
|
18773
|
-
error:
|
|
18773
|
+
error: error4
|
|
18774
18774
|
};
|
|
18775
18775
|
}
|
|
18776
18776
|
function extractFieldFromWwwAuth(response, fieldName) {
|
|
@@ -18803,15 +18803,15 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn =
|
|
|
18803
18803
|
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
18804
18804
|
try {
|
|
18805
18805
|
return await fetchWithinOrigin(fetchFn)(url2, { headers });
|
|
18806
|
-
} catch (
|
|
18807
|
-
if (
|
|
18806
|
+
} catch (error4) {
|
|
18807
|
+
if (error4 instanceof TypeError) {
|
|
18808
18808
|
if (headers) {
|
|
18809
18809
|
return fetchWithCorsRetry(url2, void 0, fetchFn);
|
|
18810
18810
|
} else {
|
|
18811
18811
|
return void 0;
|
|
18812
18812
|
}
|
|
18813
18813
|
}
|
|
18814
|
-
throw
|
|
18814
|
+
throw error4;
|
|
18815
18815
|
}
|
|
18816
18816
|
}
|
|
18817
18817
|
function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
@@ -19260,8 +19260,8 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
19260
19260
|
onEvent: (event) => {
|
|
19261
19261
|
controller.enqueue(event);
|
|
19262
19262
|
},
|
|
19263
|
-
onError(
|
|
19264
|
-
typeof onError == "function" && onError(
|
|
19263
|
+
onError(error4) {
|
|
19264
|
+
typeof onError == "function" && onError(error4), (onError === "terminate" || error4.type === "max-buffer-size-exceeded") && controller.error(error4);
|
|
19265
19265
|
},
|
|
19266
19266
|
onRetry,
|
|
19267
19267
|
onComment,
|
|
@@ -19323,9 +19323,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
19323
19323
|
scope: this._scope,
|
|
19324
19324
|
fetchFn: this._fetchWithInit
|
|
19325
19325
|
});
|
|
19326
|
-
} catch (
|
|
19327
|
-
this.onerror?.(
|
|
19328
|
-
throw
|
|
19326
|
+
} catch (error4) {
|
|
19327
|
+
this.onerror?.(error4);
|
|
19328
|
+
throw error4;
|
|
19329
19329
|
}
|
|
19330
19330
|
if (result !== "AUTHORIZED") {
|
|
19331
19331
|
throw new UnauthorizedError();
|
|
@@ -19378,9 +19378,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
19378
19378
|
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
19379
19379
|
}
|
|
19380
19380
|
this._handleSseStream(response.body, options, true);
|
|
19381
|
-
} catch (
|
|
19382
|
-
this.onerror?.(
|
|
19383
|
-
throw
|
|
19381
|
+
} catch (error4) {
|
|
19382
|
+
this.onerror?.(error4);
|
|
19383
|
+
throw error4;
|
|
19384
19384
|
}
|
|
19385
19385
|
}
|
|
19386
19386
|
/**
|
|
@@ -19412,8 +19412,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
19412
19412
|
}
|
|
19413
19413
|
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
19414
19414
|
this._reconnectionTimeout = setTimeout(() => {
|
|
19415
|
-
this._startOrAuthSse(options).catch((
|
|
19416
|
-
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${
|
|
19415
|
+
this._startOrAuthSse(options).catch((error4) => {
|
|
19416
|
+
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error4 instanceof Error ? error4.message : String(error4)}`));
|
|
19417
19417
|
this._scheduleReconnection(options, attemptCount + 1);
|
|
19418
19418
|
});
|
|
19419
19419
|
}, delay);
|
|
@@ -19456,8 +19456,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
19456
19456
|
}
|
|
19457
19457
|
}
|
|
19458
19458
|
this.onmessage?.(message);
|
|
19459
|
-
} catch (
|
|
19460
|
-
this.onerror?.(
|
|
19459
|
+
} catch (error4) {
|
|
19460
|
+
this.onerror?.(error4);
|
|
19461
19461
|
}
|
|
19462
19462
|
}
|
|
19463
19463
|
}
|
|
@@ -19470,8 +19470,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
19470
19470
|
replayMessageId
|
|
19471
19471
|
}, 0);
|
|
19472
19472
|
}
|
|
19473
|
-
} catch (
|
|
19474
|
-
this.onerror?.(new Error(`SSE stream disconnected: ${
|
|
19473
|
+
} catch (error4) {
|
|
19474
|
+
this.onerror?.(new Error(`SSE stream disconnected: ${error4}`));
|
|
19475
19475
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
19476
19476
|
const needsReconnect = canResume && !receivedResponse;
|
|
19477
19477
|
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
@@ -19481,8 +19481,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
19481
19481
|
onresumptiontoken,
|
|
19482
19482
|
replayMessageId
|
|
19483
19483
|
}, 0);
|
|
19484
|
-
} catch (
|
|
19485
|
-
this.onerror?.(new Error(`Failed to reconnect: ${
|
|
19484
|
+
} catch (error5) {
|
|
19485
|
+
this.onerror?.(new Error(`Failed to reconnect: ${error5 instanceof Error ? error5.message : String(error5)}`));
|
|
19486
19486
|
}
|
|
19487
19487
|
}
|
|
19488
19488
|
}
|
|
@@ -19565,8 +19565,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
19565
19565
|
return this.send(message);
|
|
19566
19566
|
}
|
|
19567
19567
|
if (response.status === 403 && this._authProvider) {
|
|
19568
|
-
const { resourceMetadataUrl, scope, error:
|
|
19569
|
-
if (
|
|
19568
|
+
const { resourceMetadataUrl, scope, error: error4 } = extractWWWAuthenticateParams(response);
|
|
19569
|
+
if (error4 === "insufficient_scope") {
|
|
19570
19570
|
const wwwAuthHeader = response.headers.get("WWW-Authenticate");
|
|
19571
19571
|
if (this._lastUpscopingHeader === wwwAuthHeader) {
|
|
19572
19572
|
throw new StreamableHTTPError(403, "Server returned 403 after trying upscoping");
|
|
@@ -19621,9 +19621,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
19621
19621
|
} else {
|
|
19622
19622
|
await response.body?.cancel();
|
|
19623
19623
|
}
|
|
19624
|
-
} catch (
|
|
19625
|
-
this.onerror?.(
|
|
19626
|
-
throw
|
|
19624
|
+
} catch (error4) {
|
|
19625
|
+
this.onerror?.(error4);
|
|
19626
|
+
throw error4;
|
|
19627
19627
|
}
|
|
19628
19628
|
}
|
|
19629
19629
|
get sessionId() {
|
|
@@ -19658,9 +19658,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
19658
19658
|
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
19659
19659
|
}
|
|
19660
19660
|
this._sessionId = void 0;
|
|
19661
|
-
} catch (
|
|
19662
|
-
this.onerror?.(
|
|
19663
|
-
throw
|
|
19661
|
+
} catch (error4) {
|
|
19662
|
+
this.onerror?.(error4);
|
|
19663
|
+
throw error4;
|
|
19664
19664
|
}
|
|
19665
19665
|
}
|
|
19666
19666
|
setProtocolVersion(version3) {
|
|
@@ -19685,18 +19685,15 @@ var StreamableHTTPClientTransport = class {
|
|
|
19685
19685
|
};
|
|
19686
19686
|
|
|
19687
19687
|
// lib/host-identity.mjs
|
|
19688
|
-
import { randomUUID } from "node:crypto";
|
|
19689
19688
|
function hostClientName(savedName, host) {
|
|
19690
19689
|
return ["Codex PromptFrame", "Claude Code PromptFrame"].includes(savedName) ? host.kind === "claude-code" ? "Claude Code PromptFrame" : "Codex PromptFrame" : savedName;
|
|
19691
19690
|
}
|
|
19692
19691
|
var threadFormat = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19693
|
-
function resolveHostIdentity({ host, env = process.env
|
|
19692
|
+
function resolveHostIdentity({ host, env = process.env } = {}) {
|
|
19694
19693
|
const kind = host ?? (env.CLAUDECODE === "1" ? "claude-code" : "codex");
|
|
19695
19694
|
if (!["codex", "claude-code"].includes(kind)) throw new CreationClientError("creation.host_unsupported");
|
|
19696
19695
|
if (kind === "codex") return Object.freeze({ kind });
|
|
19697
|
-
|
|
19698
|
-
if (typeof threadId !== "string" || !threadFormat.test(threadId)) throw new CreationClientError("creation.host_identity_invalid");
|
|
19699
|
-
return Object.freeze({ kind, threadId: threadId.toLowerCase() });
|
|
19696
|
+
return Object.freeze({ kind });
|
|
19700
19697
|
}
|
|
19701
19698
|
function hostParameters(params, host, access2) {
|
|
19702
19699
|
const meta2 = params._meta ?? {};
|
|
@@ -19704,6 +19701,10 @@ function hostParameters(params, host, access2) {
|
|
|
19704
19701
|
throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
19705
19702
|
if (host.kind === "claude-code") {
|
|
19706
19703
|
if (Object.hasOwn(meta2, "threadId")) throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
19704
|
+
if (!host.threadId) {
|
|
19705
|
+
if (access2 === "independent-read") return params;
|
|
19706
|
+
throw new CreationClientError("creation.host_identity_unavailable");
|
|
19707
|
+
}
|
|
19707
19708
|
return { ...params, _meta: { ...meta2, threadId: host.threadId } };
|
|
19708
19709
|
}
|
|
19709
19710
|
if (meta2.threadId === void 0) {
|
|
@@ -19771,7 +19772,7 @@ var BridgeCompatibilityError = class extends CreationClientError {
|
|
|
19771
19772
|
});
|
|
19772
19773
|
}
|
|
19773
19774
|
};
|
|
19774
|
-
var bridgeErrorDetails = (
|
|
19775
|
+
var bridgeErrorDetails = (error4) => error4 instanceof BridgeCompatibilityError ? error4.bridgeFacts : void 0;
|
|
19775
19776
|
function declaredHostContentCapabilities(capabilities) {
|
|
19776
19777
|
const requested = capabilities?.experimental?.["promptframe.contentTypes"];
|
|
19777
19778
|
if (!Array.isArray(requested) || requested.length > CONTENT_TYPES.length || requested.some((type) => !CONTENT_TYPES.includes(type))) return { types: ["text"], source: "text-fallback" };
|
|
@@ -19814,38 +19815,306 @@ async function connectPlatform(credentials, { host = resolveHostIdentity(), cont
|
|
|
19814
19815
|
if (enforceMinimum) assertBridgeCompatible(client.getServerCapabilities(), CLIENT_VERSION);
|
|
19815
19816
|
else readPlatformBridgePolicy(client.getServerCapabilities());
|
|
19816
19817
|
return client;
|
|
19817
|
-
} catch (
|
|
19818
|
+
} catch (error4) {
|
|
19818
19819
|
await client.close().catch(() => {
|
|
19819
19820
|
});
|
|
19820
|
-
throw
|
|
19821
|
+
throw error4;
|
|
19821
19822
|
}
|
|
19822
19823
|
}
|
|
19823
19824
|
|
|
19824
19825
|
// lib/host-context.mjs
|
|
19826
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
19827
|
+
|
|
19828
|
+
// lib/claude-host-session.mjs
|
|
19829
|
+
import { constants } from "node:fs";
|
|
19830
|
+
import { open as open2, mkdir as mkdir2, lstat as lstat2, rename as rename2, unlink as unlink2, rmdir } from "node:fs/promises";
|
|
19831
|
+
import path3 from "node:path";
|
|
19832
|
+
import { homedir as homedir3 } from "node:os";
|
|
19833
|
+
import { createHash as createHash2, randomBytes as randomBytes2 } from "node:crypto";
|
|
19834
|
+
|
|
19835
|
+
// lib/claude-host-process.mjs
|
|
19836
|
+
import { readFile as readFile2, readlink, stat } from "node:fs/promises";
|
|
19837
|
+
import path2 from "node:path";
|
|
19838
|
+
import { homedir as homedir2 } from "node:os";
|
|
19825
19839
|
import { createHash } from "node:crypto";
|
|
19826
|
-
var
|
|
19827
|
-
var
|
|
19828
|
-
|
|
19840
|
+
var hash = (value2) => createHash("sha256").update(JSON.stringify(value2)).digest("hex");
|
|
19841
|
+
var bounded = async (file) => {
|
|
19842
|
+
const value2 = await readFile2(file);
|
|
19843
|
+
if (value2.length > 65536) throw Error("host_process_invalid");
|
|
19844
|
+
return value2;
|
|
19845
|
+
};
|
|
19846
|
+
async function processBirth(pid) {
|
|
19847
|
+
const data = (await bounded(`/proc/${pid}/stat`)).toString(), end = data.lastIndexOf(")"), fields = data.slice(end + 2).split(" ");
|
|
19848
|
+
if (end < 0 || fields.length < 20 || !/^\d+$/.test(fields[19])) throw Error("host_process_invalid");
|
|
19849
|
+
const info5 = await stat(`/proc/${pid}`), exe = await stat(`/proc/${pid}/exe`), name = await readlink(`/proc/${pid}/exe`);
|
|
19850
|
+
return { pid, ppid: Number(fields[1]), birth: fields[19], uid: info5.uid, device: exe.dev, inode: exe.ino, exe: name };
|
|
19851
|
+
}
|
|
19852
|
+
async function claudeHostProcess({
|
|
19853
|
+
pid = process.pid,
|
|
19854
|
+
env = process.env,
|
|
19855
|
+
home = homedir2(),
|
|
19856
|
+
readBirth = processBirth,
|
|
19857
|
+
readExecutable = stat,
|
|
19858
|
+
readBoot = async () => (await bounded("/proc/sys/kernel/random/boot_id")).toString().trim(),
|
|
19859
|
+
purpose = "bridge",
|
|
19860
|
+
entryFile = process.argv[1],
|
|
19861
|
+
readCommand = async (pid2) => (await bounded(`/proc/${pid2}/cmdline`)).toString().split("\0")
|
|
19862
|
+
} = {}) {
|
|
19863
|
+
if (process.platform !== "linux" || env.CLAUDECODE !== "1") return null;
|
|
19864
|
+
try {
|
|
19865
|
+
const uid = process.getuid(), boot = await readBoot();
|
|
19866
|
+
let child = await readBirth(pid), visited = /* @__PURE__ */ new Set();
|
|
19867
|
+
for (let depth = 0; depth < 32 && child.ppid > 1; depth++) {
|
|
19868
|
+
if (visited.has(child.ppid)) return null;
|
|
19869
|
+
visited.add(child.ppid);
|
|
19870
|
+
const host = await readBirth(child.ppid);
|
|
19871
|
+
const roots2 = [path2.join(home, ".claude", "remote", "ccd-cli"), path2.join(home, ".local", "share", "claude", "versions")];
|
|
19872
|
+
if (roots2.some((root) => path2.dirname(host.exe) === root)) {
|
|
19873
|
+
const executable = await readExecutable(host.exe);
|
|
19874
|
+
if (host.uid !== uid || ![uid, 0].includes(executable.uid) || !executable.isFile() || executable.mode & 18 || host.inode !== executable.ino || host.device !== executable.dev) return null;
|
|
19875
|
+
if (purpose === "hook") {
|
|
19876
|
+
const command2 = await readCommand(child.pid);
|
|
19877
|
+
if (!entryFile || !command2.some((arg) => arg.includes(entryFile)) || !command2.some((arg) => arg === "claude-host-hook" || arg.includes(" claude-host-hook"))) return null;
|
|
19878
|
+
}
|
|
19879
|
+
const binding = { pid: host.pid, birth: host.birth, uid, device: host.device, inode: host.inode, exe: host.exe, boot };
|
|
19880
|
+
const digest4 = hash(binding);
|
|
19881
|
+
return { binding, digest: digest4, eventOrder: { birth: child.birth, pid: child.pid }, async isCurrent() {
|
|
19882
|
+
try {
|
|
19883
|
+
const current = await readBirth(binding.pid);
|
|
19884
|
+
return current.birth === binding.birth && current.uid === uid && current.device === binding.device && current.inode === binding.inode && current.exe === binding.exe && await readBoot() === boot;
|
|
19885
|
+
} catch {
|
|
19886
|
+
return false;
|
|
19887
|
+
}
|
|
19888
|
+
} };
|
|
19889
|
+
}
|
|
19890
|
+
child = host;
|
|
19891
|
+
}
|
|
19892
|
+
} catch {
|
|
19893
|
+
}
|
|
19894
|
+
return null;
|
|
19895
|
+
}
|
|
19896
|
+
|
|
19897
|
+
// lib/claude-host-session.mjs
|
|
19898
|
+
var CLAUDE_HOST_PROOF = "_promptframeHostProof";
|
|
19899
|
+
var uuid2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19900
|
+
var hex = /^[0-9a-f]{64}$/;
|
|
19901
|
+
var error2 = (code) => new CreationClientError("creation." + code);
|
|
19829
19902
|
var canonical = (value2) => {
|
|
19830
19903
|
if (value2 === null || typeof value2 === "string" || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2)) return JSON.stringify(value2);
|
|
19831
19904
|
if (Array.isArray(value2)) return "[" + value2.map(canonical).join(",") + "]";
|
|
19832
19905
|
if (value2 && typeof value2 === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(value2)))
|
|
19833
19906
|
return "{" + Object.keys(value2).sort().map((key) => JSON.stringify(key) + ":" + canonical(value2[key])).join(",") + "}";
|
|
19907
|
+
throw error2("request_invalid");
|
|
19908
|
+
};
|
|
19909
|
+
var digest = (value2) => createHash2("sha256").update(canonical(value2)).digest("hex");
|
|
19910
|
+
var withoutProof = (args2) => Object.fromEntries(Object.entries(args2 ?? {}).filter(([key]) => key !== CLAUDE_HOST_PROOF));
|
|
19911
|
+
var later = (a, b2) => BigInt(a.birth) > BigInt(b2.birth) || a.birth === b2.birth && a.pid > b2.pid;
|
|
19912
|
+
async function privateDirectory(directory) {
|
|
19913
|
+
try {
|
|
19914
|
+
await mkdir2(directory, { mode: 448 });
|
|
19915
|
+
} catch (e) {
|
|
19916
|
+
if (e.code !== "EEXIST") throw e;
|
|
19917
|
+
}
|
|
19918
|
+
const info5 = await lstat2(directory);
|
|
19919
|
+
if (!info5.isDirectory() || info5.isSymbolicLink() || info5.uid !== process.getuid?.() || info5.mode & 63) throw error2("host_identity_unavailable");
|
|
19920
|
+
}
|
|
19921
|
+
async function privateRead(file) {
|
|
19922
|
+
let handle;
|
|
19923
|
+
try {
|
|
19924
|
+
handle = await open2(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
19925
|
+
const info5 = await handle.stat();
|
|
19926
|
+
if (!info5.isFile() || info5.uid !== process.getuid?.() || info5.mode & 63 || info5.size > 196608) throw error2("host_identity_unavailable");
|
|
19927
|
+
return JSON.parse(await handle.readFile("utf8"));
|
|
19928
|
+
} catch (e) {
|
|
19929
|
+
if (e.code === "ENOENT") return null;
|
|
19930
|
+
throw e;
|
|
19931
|
+
} finally {
|
|
19932
|
+
await handle?.close();
|
|
19933
|
+
}
|
|
19934
|
+
}
|
|
19935
|
+
async function createClaudeHostSession({ configFile: configFile2, env = process.env, root, association, hookProcess = false } = {}) {
|
|
19936
|
+
const owner = association === void 0 ? await claudeHostProcess({ env, purpose: hookProcess ? "hook" : "bridge" }) : association;
|
|
19937
|
+
const base = root ?? path3.join(env.CLAUDE_CONFIG_DIR ?? path3.join(homedir3(), ".claude"), "promptframe-host-sessions");
|
|
19938
|
+
const namespace = owner ? path3.join(base, digest([owner.digest, path3.resolve(configFile2)])) : null;
|
|
19939
|
+
const stateFile = namespace && path3.join(namespace, "state.json");
|
|
19940
|
+
async function state() {
|
|
19941
|
+
if (!owner || !await owner.isCurrent()) return null;
|
|
19942
|
+
const value2 = await privateRead(stateFile);
|
|
19943
|
+
if (!value2) return null;
|
|
19944
|
+
if (value2.contractVersion !== "claude-host-session/v1" || value2.binding !== owner.digest || !Number.isSafeInteger(value2.epoch) || value2.epoch < 1 || !value2.order || !/^\d+$/.test(value2.order.birth) || !Number.isSafeInteger(value2.order.pid) || value2.sessionId !== null && !uuid2.test(value2.sessionId) || !value2.tickets || typeof value2.tickets !== "object" || Array.isArray(value2.tickets) || Object.keys(value2.tickets).length > 128) throw error2("host_identity_unavailable");
|
|
19945
|
+
return value2;
|
|
19946
|
+
}
|
|
19947
|
+
async function transaction(work) {
|
|
19948
|
+
if (!owner || !await owner.isCurrent()) throw error2("host_identity_unavailable");
|
|
19949
|
+
await privateDirectory(base);
|
|
19950
|
+
await privateDirectory(namespace);
|
|
19951
|
+
const lock = path3.join(namespace, "write.lock");
|
|
19952
|
+
let acquired = false;
|
|
19953
|
+
for (let count = 0; count < 100; count++) try {
|
|
19954
|
+
await mkdir2(lock, { mode: 448 });
|
|
19955
|
+
acquired = true;
|
|
19956
|
+
break;
|
|
19957
|
+
} catch (e) {
|
|
19958
|
+
if (e.code !== "EEXIST") throw e;
|
|
19959
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
19960
|
+
}
|
|
19961
|
+
if (!acquired) throw error2("host_identity_unavailable");
|
|
19962
|
+
let temporary;
|
|
19963
|
+
try {
|
|
19964
|
+
if (!await owner.isCurrent()) throw error2("host_identity_unavailable");
|
|
19965
|
+
const current = await state(), next = await work(current);
|
|
19966
|
+
if (next === void 0) return;
|
|
19967
|
+
if (next === null) {
|
|
19968
|
+
if (current) await unlink2(stateFile);
|
|
19969
|
+
return;
|
|
19970
|
+
}
|
|
19971
|
+
const body = JSON.stringify(next);
|
|
19972
|
+
if (Buffer.byteLength(body) > 196608) throw error2("host_identity_unavailable");
|
|
19973
|
+
temporary = path3.join(namespace, "state-" + randomBytes2(16).toString("hex") + ".partial");
|
|
19974
|
+
const file = await open2(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
19975
|
+
try {
|
|
19976
|
+
await file.writeFile(body);
|
|
19977
|
+
await file.sync();
|
|
19978
|
+
} finally {
|
|
19979
|
+
await file.close();
|
|
19980
|
+
}
|
|
19981
|
+
if (!await owner.isCurrent()) throw error2("host_identity_unavailable");
|
|
19982
|
+
await rename2(temporary, stateFile);
|
|
19983
|
+
temporary = void 0;
|
|
19984
|
+
const directory = await open2(namespace, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
19985
|
+
try {
|
|
19986
|
+
await directory.sync();
|
|
19987
|
+
} finally {
|
|
19988
|
+
await directory.close();
|
|
19989
|
+
}
|
|
19990
|
+
} finally {
|
|
19991
|
+
if (temporary) await unlink2(temporary).catch(() => {
|
|
19992
|
+
});
|
|
19993
|
+
await rmdir(lock);
|
|
19994
|
+
}
|
|
19995
|
+
}
|
|
19996
|
+
async function begin(raw) {
|
|
19997
|
+
const proof = raw.arguments?.[CLAUDE_HOST_PROOF], args2 = withoutProof(raw.arguments);
|
|
19998
|
+
if (proof === void 0) return { host: { kind: "claude-code" }, assertCurrent: async () => {
|
|
19999
|
+
}, arguments: args2 };
|
|
20000
|
+
if (typeof proof !== "string" || !hex.test(proof)) throw error2("host_identity_invalid");
|
|
20001
|
+
let accepted;
|
|
20002
|
+
try {
|
|
20003
|
+
await transaction((current) => {
|
|
20004
|
+
const ticket = current?.tickets[proof];
|
|
20005
|
+
if (!current?.sessionId || !ticket || ticket.epoch !== current.epoch || ticket.sessionId !== current.sessionId || ticket.digest !== digest([raw.name, args2])) throw error2("host_identity_invalid");
|
|
20006
|
+
accepted = { threadId: current.sessionId, epoch: current.epoch };
|
|
20007
|
+
delete current.tickets[proof];
|
|
20008
|
+
return current;
|
|
20009
|
+
});
|
|
20010
|
+
} catch (e) {
|
|
20011
|
+
if (e instanceof CreationClientError) throw e;
|
|
20012
|
+
throw error2("host_identity_unavailable");
|
|
20013
|
+
}
|
|
20014
|
+
return { host: { kind: "claude-code", threadId: accepted.threadId }, arguments: args2, epoch: accepted.epoch, async assertCurrent() {
|
|
20015
|
+
try {
|
|
20016
|
+
const current = await state();
|
|
20017
|
+
if (current?.epoch !== accepted.epoch || current.sessionId !== accepted.threadId)
|
|
20018
|
+
throw error2("host_session_changed");
|
|
20019
|
+
} catch (e) {
|
|
20020
|
+
if (e instanceof CreationClientError) throw e;
|
|
20021
|
+
throw error2("host_identity_unavailable");
|
|
20022
|
+
}
|
|
20023
|
+
} };
|
|
20024
|
+
}
|
|
20025
|
+
async function hook(input) {
|
|
20026
|
+
const event = input?.hook_event_name;
|
|
20027
|
+
if (!["SessionStart", "PreToolUse", "SessionEnd"].includes(event)) throw error2("host_identity_invalid");
|
|
20028
|
+
const valid = typeof input.session_id === "string" && uuid2.test(input.session_id), sessionId = valid ? input.session_id.toLowerCase() : null;
|
|
20029
|
+
const rawArgs = input.tool_input;
|
|
20030
|
+
if (event === "PreToolUse" && (!rawArgs || typeof rawArgs !== "object" || Array.isArray(rawArgs) || typeof input.tool_name !== "string" || !/^mcp__[A-Za-z0-9_.:-]+__[A-Za-z0-9_.:-]+$/.test(input.tool_name))) throw error2("host_identity_invalid");
|
|
20031
|
+
if (!owner) return event === "PreToolUse" && Object.hasOwn(rawArgs, CLAUDE_HOST_PROOF) ? { hookSpecificOutput: { hookEventName: event, updatedInput: withoutProof(rawArgs) } } : {};
|
|
20032
|
+
let result = {};
|
|
20033
|
+
await transaction((current) => {
|
|
20034
|
+
if (current && later(current.order, owner.eventOrder)) return void 0;
|
|
20035
|
+
if (event === "SessionEnd") {
|
|
20036
|
+
if (current?.sessionId === sessionId && ["prompt_input_exit", "logout", "other", "bypass_permissions_disabled"].includes(input.reason)) return null;
|
|
20037
|
+
if (!current || current.sessionId !== sessionId) return void 0;
|
|
20038
|
+
}
|
|
20039
|
+
if (event === "SessionStart" && !["startup", "resume", "fork", "clear", "compact"].includes(input.source)) throw error2("host_identity_invalid");
|
|
20040
|
+
const inconsistent = event === "PreToolUse" && current?.sessionId !== sessionId || event === "SessionStart" && input.source === "compact" && current?.sessionId !== sessionId || event === "SessionStart" && input.source === "startup" && current?.sessionId && current.sessionId !== sessionId;
|
|
20041
|
+
const nextId = event === "SessionEnd" || inconsistent ? null : sessionId;
|
|
20042
|
+
const same2 = current && current.sessionId === nextId;
|
|
20043
|
+
const next = {
|
|
20044
|
+
contractVersion: "claude-host-session/v1",
|
|
20045
|
+
binding: owner.digest,
|
|
20046
|
+
epoch: (current?.epoch ?? 0) + (same2 ? 0 : 1),
|
|
20047
|
+
order: owner.eventOrder,
|
|
20048
|
+
sessionId: nextId,
|
|
20049
|
+
tickets: same2 ? current.tickets : {}
|
|
20050
|
+
};
|
|
20051
|
+
if (event !== "PreToolUse") return next;
|
|
20052
|
+
const args2 = withoutProof(rawArgs), tool = input.tool_name.slice(input.tool_name.lastIndexOf("__") + 2), key = digest([tool, args2]);
|
|
20053
|
+
if (!nextId) {
|
|
20054
|
+
result = { hookSpecificOutput: { hookEventName: event, updatedInput: args2 } };
|
|
20055
|
+
return next;
|
|
20056
|
+
}
|
|
20057
|
+
const existing = rawArgs[CLAUDE_HOST_PROOF], prior = typeof existing === "string" && next.tickets[existing];
|
|
20058
|
+
if (prior && prior.digest === key && prior.epoch === next.epoch && prior.sessionId === nextId) {
|
|
20059
|
+
result = {};
|
|
20060
|
+
return next;
|
|
20061
|
+
}
|
|
20062
|
+
if (Object.keys(next.tickets).length >= 128) delete next.tickets[Object.keys(next.tickets)[0]];
|
|
20063
|
+
const token = randomBytes2(32).toString("hex");
|
|
20064
|
+
next.tickets[token] = { digest: key, epoch: next.epoch, sessionId: nextId };
|
|
20065
|
+
result = { hookSpecificOutput: { hookEventName: event, updatedInput: { ...args2, [CLAUDE_HOST_PROOF]: token } } };
|
|
20066
|
+
return next;
|
|
20067
|
+
});
|
|
20068
|
+
if (event === "SessionEnd") try {
|
|
20069
|
+
await rmdir(namespace);
|
|
20070
|
+
} catch (e) {
|
|
20071
|
+
if (!["ENOTEMPTY", "ENOENT"].includes(e.code)) throw e;
|
|
20072
|
+
}
|
|
20073
|
+
return result;
|
|
20074
|
+
}
|
|
20075
|
+
return { begin, hook };
|
|
20076
|
+
}
|
|
20077
|
+
async function readClaudeHookInput(input) {
|
|
20078
|
+
const chunks = [];
|
|
20079
|
+
let bytes2 = 0;
|
|
20080
|
+
for await (const value2 of input) {
|
|
20081
|
+
const chunk = Buffer.isBuffer(value2) ? value2 : Buffer.from(value2);
|
|
20082
|
+
bytes2 += chunk.length;
|
|
20083
|
+
if (bytes2 > 2 * 1024 * 1024 + 65536) throw error2("host_identity_invalid");
|
|
20084
|
+
chunks.push(chunk);
|
|
20085
|
+
}
|
|
20086
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks, bytes2)));
|
|
20087
|
+
}
|
|
20088
|
+
async function runClaudeHostHook({ configFile: configFile2, input = process.stdin, output = process.stdout, env = process.env } = {}) {
|
|
20089
|
+
const body = await readClaudeHookInput(input);
|
|
20090
|
+
const store = await createClaudeHostSession({ configFile: configFile2, env, hookProcess: true });
|
|
20091
|
+
output.write(JSON.stringify(await store.hook(body)) + "\n");
|
|
20092
|
+
}
|
|
20093
|
+
|
|
20094
|
+
// lib/host-context.mjs
|
|
20095
|
+
var digestPattern = /^sha256:[a-f0-9]{64}$/;
|
|
20096
|
+
var accesses = /* @__PURE__ */ new Set(["independent-read", "controlled", "authority"]);
|
|
20097
|
+
var digest2 = (value2) => "sha256:" + createHash3("sha256").update(value2).digest("hex");
|
|
20098
|
+
var canonical2 = (value2) => {
|
|
20099
|
+
if (value2 === null || typeof value2 === "string" || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2)) return JSON.stringify(value2);
|
|
20100
|
+
if (Array.isArray(value2)) return "[" + value2.map(canonical2).join(",") + "]";
|
|
20101
|
+
if (value2 && typeof value2 === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(value2)))
|
|
20102
|
+
return "{" + Object.keys(value2).sort().map((key) => JSON.stringify(key) + ":" + canonical2(value2[key])).join(",") + "}";
|
|
19834
20103
|
throw new CreationClientError("creation.request_invalid");
|
|
19835
20104
|
};
|
|
19836
|
-
var argumentsDigest = (value2) =>
|
|
20105
|
+
var argumentsDigest = (value2) => digest2(canonical2(value2));
|
|
19837
20106
|
var boundedSet = (map, key, value2) => {
|
|
19838
20107
|
if (!map.has(key) && map.size >= 1024) map.delete(map.keys().next().value);
|
|
19839
20108
|
map.set(key, value2);
|
|
19840
20109
|
};
|
|
19841
|
-
function createHostCallBridge(client, { credentials, host = resolveHostIdentity(), onCatalogChange = () => {
|
|
20110
|
+
function createHostCallBridge(client, { credentials, host = resolveHostIdentity(), hostSession, onCatalogChange = () => {
|
|
19842
20111
|
}, onKnowledgeChange = () => {
|
|
19843
20112
|
} } = {}) {
|
|
19844
20113
|
if (!credentials?.endpoint || !credentials.clientId) throw new CreationClientError("creation.bridge_identity_required");
|
|
19845
|
-
const installationDigest =
|
|
20114
|
+
const installationDigest = digest2(credentials.clientId);
|
|
19846
20115
|
const versions = /* @__PURE__ */ new Map(), controllers = /* @__PURE__ */ new Map(), catalogs = /* @__PURE__ */ new Map(), inflight = /* @__PURE__ */ new Map();
|
|
19847
20116
|
const knowledgeVersions = /* @__PURE__ */ new Map(), upstream = client.getServerCapabilities?.() ?? {};
|
|
19848
|
-
let platformDigest, accountDigest, directory, directoryRead, sequence = 0;
|
|
20117
|
+
let platformDigest, accountDigest, directory, directoryRead, sequence = 0, hostEpoch;
|
|
19849
20118
|
function catalog(channel, version3, order) {
|
|
19850
20119
|
if (typeof version3 !== "string" || !digestPattern.test(version3)) return;
|
|
19851
20120
|
const old = catalogs.get(channel);
|
|
@@ -19862,7 +20131,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
19862
20131
|
const v2 = result?._meta?.["promptframe.creation"];
|
|
19863
20132
|
if (!v2 || v2.contractVersion !== "creation-transport-metadata/v1" || !digestPattern.test(v2.platformDigest) || platformDigest && v2.platformDigest !== platformDigest || v2.installationDigest !== installationDigest || !digestPattern.test(v2.accountDigest) || !digestPattern.test(v2.controllerDigest)) return null;
|
|
19864
20133
|
const thread = params._meta?.threadId?.toLowerCase();
|
|
19865
|
-
if (thread ? v2.host?.kind !== host.kind || v2.host.threadDigest !==
|
|
20134
|
+
if (thread ? v2.host?.kind !== host.kind || v2.host.threadDigest !== digest2(thread) : v2.host?.kind !== "legacy") return null;
|
|
19866
20135
|
for (const field of ["projectId", "sessionId"]) if (params.arguments?.[field] !== void 0 && v2[field] !== params.arguments[field]) return null;
|
|
19867
20136
|
if (accountDigest && accountDigest !== v2.accountDigest) return null;
|
|
19868
20137
|
const controllerKey = thread ?? "legacy", prior = controllers.get(controllerKey);
|
|
@@ -19889,8 +20158,10 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
19889
20158
|
}
|
|
19890
20159
|
return v2;
|
|
19891
20160
|
}
|
|
19892
|
-
async function send(params) {
|
|
20161
|
+
async function send(params, binding) {
|
|
20162
|
+
await binding?.assertCurrent();
|
|
19893
20163
|
const order = ++sequence, result = assertMcpResponseBudget(await client.callTool(params, void 0, { timeout: 6e4 }));
|
|
20164
|
+
await binding?.assertCurrent();
|
|
19894
20165
|
return { result, trusted: remember(params, result, order) };
|
|
19895
20166
|
}
|
|
19896
20167
|
async function listTools() {
|
|
@@ -19900,9 +20171,10 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
19900
20171
|
catalog("outer", result._meta?.["promptframe.catalogVersion"], order);
|
|
19901
20172
|
return { ...result, tools: result.tools.map((tool) => {
|
|
19902
20173
|
const p2 = tool.inputSchema.properties;
|
|
19903
|
-
|
|
19904
|
-
|
|
19905
|
-
|
|
20174
|
+
const { controlVersion: _managed, ...properties } = p2 ?? {};
|
|
20175
|
+
return { ...tool, inputSchema: { ...tool.inputSchema, properties: { ...properties, ...host.kind === "claude-code" ? {
|
|
20176
|
+
[CLAUDE_HOST_PROOF]: { type: "string", pattern: "^[a-f0-9]{64}$", description: "\u7531\u5F53\u524D\u5BBF\u4E3Bhook\u586B\u5165\u7684\u5355\u6B21\u8EAB\u4EFD\u51ED\u8BC1\uFF1B\u8BF7\u4FDD\u7559\uFF0C\u4E0D\u81EA\u884C\u586B\u5199\u3002" }
|
|
20177
|
+
} : {} }, ...tool.inputSchema.required ? { required: tool.inputSchema.required.filter((name) => name !== "controlVersion") } : {} } };
|
|
19906
20178
|
}) };
|
|
19907
20179
|
}
|
|
19908
20180
|
async function ensureDirectory() {
|
|
@@ -19918,21 +20190,24 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
19918
20190
|
if (found.length !== 1) throw new CreationClientError("creation.upgrade_required");
|
|
19919
20191
|
return found[0].name;
|
|
19920
20192
|
}
|
|
19921
|
-
async function controlRead(params, key) {
|
|
19922
|
-
if (!inflight.has(key))
|
|
19923
|
-
|
|
19924
|
-
|
|
19925
|
-
|
|
19926
|
-
|
|
19927
|
-
|
|
19928
|
-
|
|
20193
|
+
async function controlRead(params, key, binding) {
|
|
20194
|
+
if (!inflight.has(key)) {
|
|
20195
|
+
const pending = send({
|
|
20196
|
+
name: role("control-read"),
|
|
20197
|
+
_meta: params._meta,
|
|
20198
|
+
arguments: { projectId: params.arguments.projectId, sessionId: params.arguments.sessionId, pageSize: 1 }
|
|
20199
|
+
}, binding).finally(() => {
|
|
20200
|
+
if (inflight.get(key) === pending) inflight.delete(key);
|
|
20201
|
+
});
|
|
20202
|
+
inflight.set(key, pending);
|
|
20203
|
+
}
|
|
19929
20204
|
const observation = await inflight.get(key);
|
|
19930
20205
|
if (observation.result.isError) return observation.result;
|
|
19931
20206
|
if (!observation.trusted || !versions.has(key) || versions.get(key).needsRead) throw new CreationClientError("creation.control_unverified");
|
|
19932
20207
|
}
|
|
19933
20208
|
async function knowledgeRead(kind, method, raw = {}) {
|
|
19934
20209
|
if (!upstream[kind]) throw new CreationClientError("creation.knowledge_unsupported");
|
|
19935
|
-
const params = hostParameters(raw, host, "independent-read"), order = ++sequence;
|
|
20210
|
+
const params = hostParameters(raw, host.kind === "claude-code" ? { kind: host.kind } : host, "independent-read"), order = ++sequence;
|
|
19936
20211
|
const result = assertMcpResponseBudget(await client[method](params, void 0, { timeout: 6e4 }));
|
|
19937
20212
|
const version3 = result._meta?.[kind === "resources" && method === "listResources" ? "promptframe.guideDirectoryVersion" : "promptframe.guideVersion"];
|
|
19938
20213
|
const key = JSON.stringify([kind, method, raw.uri ?? raw.arguments?.projectId ?? null]);
|
|
@@ -19960,46 +20235,70 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
19960
20235
|
async call(raw) {
|
|
19961
20236
|
for (const field of ["threadId", "controller", "clientDigest", "token", "controlVersion"]) if (Object.hasOwn(raw.arguments ?? {}, field))
|
|
19962
20237
|
throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
20238
|
+
let binding = { host, arguments: raw.arguments, assertCurrent: async () => {
|
|
20239
|
+
} };
|
|
20240
|
+
if (host.kind === "claude-code") {
|
|
20241
|
+
if (hostSession) binding = await hostSession.begin(raw);
|
|
20242
|
+
else if (raw.arguments?.[CLAUDE_HOST_PROOF] !== void 0) throw new CreationClientError("creation.host_identity_invalid");
|
|
20243
|
+
else binding = { host: { kind: "claude-code" }, arguments: raw.arguments, assertCurrent: async () => {
|
|
20244
|
+
} };
|
|
20245
|
+
if (binding.epoch !== hostEpoch) {
|
|
20246
|
+
versions.clear();
|
|
20247
|
+
controllers.clear();
|
|
20248
|
+
inflight.clear();
|
|
20249
|
+
hostEpoch = binding.epoch;
|
|
20250
|
+
}
|
|
20251
|
+
} else if (Object.hasOwn(raw.arguments ?? {}, CLAUDE_HOST_PROOF)) throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
20252
|
+
raw = { ...raw, arguments: binding.arguments };
|
|
19963
20253
|
await ensureDirectory();
|
|
20254
|
+
await binding.assertCurrent();
|
|
19964
20255
|
const definition = directory.tools.get(raw.name);
|
|
19965
20256
|
if (!definition) throw new CreationClientError("creation.tool_unavailable");
|
|
19966
20257
|
const access2 = definition._meta["promptframe.access"], managed = Object.hasOwn(definition.inputSchema.properties ?? {}, "controlVersion");
|
|
19967
|
-
const params = hostParameters(raw, host,
|
|
19968
|
-
let effectiveAccess = access2;
|
|
20258
|
+
const params = hostParameters(raw, binding.host, "independent-read");
|
|
20259
|
+
let effectiveAccess = access2, resolvedControl;
|
|
19969
20260
|
if (definition._meta["promptframe.resolveAccess"] === "target") {
|
|
19970
20261
|
const { projectId, sessionId, tool, arguments: input } = params.arguments ?? {};
|
|
19971
20262
|
if (typeof tool !== "string" || !input || typeof input !== "object" || Array.isArray(input)) throw new CreationClientError("creation.request_invalid");
|
|
19972
|
-
const observed = await send({ name: role("describe-target"), _meta: params._meta, arguments: { projectId, sessionId, tool, arguments: input } });
|
|
20263
|
+
const observed = await send({ name: role("describe-target"), _meta: params._meta, arguments: { projectId, sessionId, tool, arguments: input } }, binding);
|
|
19973
20264
|
if (observed.result.isError) return observed.result;
|
|
19974
20265
|
const resolved = observed.trusted?.resolvedAccess;
|
|
19975
20266
|
if (resolved?.tool !== tool || resolved.argumentsDigest !== argumentsDigest(input) || !accesses.has(resolved.access)) throw new CreationClientError("creation.access_unverified");
|
|
19976
20267
|
effectiveAccess = resolved.access;
|
|
20268
|
+
resolvedControl = observed.trusted?.control;
|
|
19977
20269
|
}
|
|
20270
|
+
hostParameters(raw, binding.host, effectiveAccess);
|
|
19978
20271
|
const key = keyFor(params);
|
|
19979
20272
|
let outgoing = params;
|
|
19980
20273
|
if (managed) {
|
|
19981
|
-
if (!key)
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
19986
|
-
entry = versions.get(key);
|
|
20274
|
+
if (!key) {
|
|
20275
|
+
if (effectiveAccess !== "independent-read" || !Number.isSafeInteger(resolvedControl?.controlVersion) || resolvedControl.controlVersion <= 0)
|
|
20276
|
+
throw new CreationClientError("creation.control_unverified");
|
|
20277
|
+
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: resolvedControl.controlVersion } };
|
|
20278
|
+
} else {
|
|
20279
|
+
let entry = versions.get(key);
|
|
20280
|
+
if (!entry || entry.needsRead) {
|
|
20281
|
+
const denied = await controlRead(params, key, binding);
|
|
20282
|
+
if (denied) return denied;
|
|
20283
|
+
entry = versions.get(key);
|
|
20284
|
+
}
|
|
20285
|
+
if (effectiveAccess !== "independent-read" && !entry.owned) throw new CreationClientError("creation.editor_not_current");
|
|
20286
|
+
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: entry.version } };
|
|
19987
20287
|
}
|
|
19988
|
-
if (effectiveAccess !== "independent-read" && !entry.owned) throw new CreationClientError("creation.editor_not_current");
|
|
19989
|
-
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: entry.version } };
|
|
19990
20288
|
}
|
|
19991
20289
|
const dispatched = key && versions.get(key);
|
|
19992
20290
|
const invalidate = () => {
|
|
20291
|
+
if (host.kind === "claude-code" && binding.epoch !== hostEpoch) return;
|
|
19993
20292
|
const current = key && versions.get(key);
|
|
19994
20293
|
if (dispatched && current && current.version <= dispatched.version)
|
|
19995
20294
|
boundedSet(versions, key, { ...current, needsRead: true, invalidatedAt: ++sequence });
|
|
19996
20295
|
};
|
|
19997
20296
|
let response;
|
|
19998
20297
|
try {
|
|
19999
|
-
response = await send(outgoing);
|
|
20000
|
-
} catch (
|
|
20298
|
+
response = await send(outgoing, binding);
|
|
20299
|
+
} catch (error4) {
|
|
20001
20300
|
invalidate();
|
|
20002
|
-
throw
|
|
20301
|
+
throw error4;
|
|
20003
20302
|
}
|
|
20004
20303
|
if (response.result.isError) invalidate();
|
|
20005
20304
|
return response.result;
|
|
@@ -20008,7 +20307,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
20008
20307
|
}
|
|
20009
20308
|
|
|
20010
20309
|
// lib/runtime-bootstrap.mjs
|
|
20011
|
-
import { createHash as
|
|
20310
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "node:crypto";
|
|
20012
20311
|
import { gunzipSync } from "node:zlib";
|
|
20013
20312
|
|
|
20014
20313
|
// node_modules/tar/dist/esm/index.min.js
|
|
@@ -22981,18 +23280,18 @@ var To = (s3) => {
|
|
|
22981
23280
|
};
|
|
22982
23281
|
|
|
22983
23282
|
// lib/runtime-bootstrap.mjs
|
|
22984
|
-
import { lstat as
|
|
23283
|
+
import { lstat as lstat4, mkdir as mkdir3, open as open3, readFile as readFile4, readdir as readdir2, rename as rename3, rm, statfs } from "node:fs/promises";
|
|
22985
23284
|
import { execFile } from "node:child_process";
|
|
22986
23285
|
import { promisify } from "node:util";
|
|
22987
|
-
import
|
|
23286
|
+
import path5 from "node:path";
|
|
22988
23287
|
|
|
22989
23288
|
// lib/runtime-package.mjs
|
|
22990
|
-
import { lstat as
|
|
22991
|
-
import { createHash as
|
|
22992
|
-
import
|
|
23289
|
+
import { lstat as lstat3, readdir, readFile as readFile3 } from "node:fs/promises";
|
|
23290
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
23291
|
+
import path4 from "node:path";
|
|
22993
23292
|
var RUNTIME_PACKAGE_ENTRIES = Object.freeze(["package.json", "README.md", "LICENSE", "bin", "dist", "lib", "skills", "docs", ".codex-plugin", ".mcp.json"]);
|
|
22994
23293
|
var OPTIONAL_HOST_ENTRIES = Object.freeze([".claude-plugin", ".claude-mcp.json"]);
|
|
22995
|
-
var
|
|
23294
|
+
var hash2 = (b2) => createHash4("sha256").update(b2).digest("hex");
|
|
22996
23295
|
var invalid = (code) => {
|
|
22997
23296
|
throw new CreationClientError("installation." + code);
|
|
22998
23297
|
};
|
|
@@ -23001,7 +23300,7 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23001
23300
|
entries = [...RUNTIME_PACKAGE_ENTRIES];
|
|
23002
23301
|
for (const name of OPTIONAL_HOST_ENTRIES) {
|
|
23003
23302
|
try {
|
|
23004
|
-
await
|
|
23303
|
+
await lstat3(path4.join(root, name));
|
|
23005
23304
|
entries.push(name);
|
|
23006
23305
|
} catch (e) {
|
|
23007
23306
|
if (e.code !== "ENOENT") throw e;
|
|
@@ -23013,22 +23312,22 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23013
23312
|
async function walk(relative) {
|
|
23014
23313
|
let s3;
|
|
23015
23314
|
try {
|
|
23016
|
-
s3 = await
|
|
23017
|
-
} catch (
|
|
23018
|
-
if (
|
|
23315
|
+
s3 = await lstat3(path4.join(root, relative));
|
|
23316
|
+
} catch (error4) {
|
|
23317
|
+
if (error4.code !== "ENOENT") throw error4;
|
|
23019
23318
|
}
|
|
23020
23319
|
if (!s3 || s3.isSymbolicLink()) invalid("package_file_invalid");
|
|
23021
23320
|
if (s3.isDirectory()) {
|
|
23022
|
-
for (const name of (await readdir(
|
|
23321
|
+
for (const name of (await readdir(path4.join(root, relative))).sort()) {
|
|
23023
23322
|
if (name === "node_modules" || name === "credentials.json" || name.startsWith(".env")) invalid("package_file_invalid");
|
|
23024
|
-
await walk(
|
|
23323
|
+
await walk(path4.join(relative, name));
|
|
23025
23324
|
}
|
|
23026
23325
|
} else if (s3.isFile()) {
|
|
23027
23326
|
if (s3.size > 32 * 1024 * 1024) invalid("package_too_large");
|
|
23028
|
-
const body = await
|
|
23327
|
+
const body = await readFile3(path4.join(root, relative));
|
|
23029
23328
|
bytes2 += body.length;
|
|
23030
23329
|
if (files.length >= 1024 || bytes2 > 32 * 1024 * 1024) invalid("package_too_large");
|
|
23031
|
-
files.push({ path: relative, bytes: body.length, sha256:
|
|
23330
|
+
files.push({ path: relative, bytes: body.length, sha256: hash2(body), body });
|
|
23032
23331
|
} else invalid("package_file_invalid");
|
|
23033
23332
|
}
|
|
23034
23333
|
for (const name of entries) await walk(name);
|
|
@@ -23042,7 +23341,7 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23042
23341
|
files,
|
|
23043
23342
|
version: pkg.version,
|
|
23044
23343
|
hosts: claude ? ["codex", "claude-code"] : ["codex"],
|
|
23045
|
-
payloadDigest:
|
|
23344
|
+
payloadDigest: hash2(JSON.stringify(files.map(({ path: path14, bytes: bytes3, sha256 }) => ({ path: path14, bytes: bytes3, sha256 }))))
|
|
23046
23345
|
};
|
|
23047
23346
|
}
|
|
23048
23347
|
|
|
@@ -23052,9 +23351,9 @@ var REGISTRY = "https://registry.npmjs.org";
|
|
|
23052
23351
|
var MAX_ARCHIVE = 8 * 1024 * 1024;
|
|
23053
23352
|
var MAX_PAYLOAD = 32 * 1024 * 1024;
|
|
23054
23353
|
var MAX_TAR = 36 * 1024 * 1024;
|
|
23055
|
-
var
|
|
23354
|
+
var hash3 = (b2) => createHash5("sha256").update(b2).digest("hex");
|
|
23056
23355
|
var execute = promisify(execFile);
|
|
23057
|
-
var
|
|
23356
|
+
var error3 = (code) => new CreationClientError("creation." + code);
|
|
23058
23357
|
var version2 = (v2) => {
|
|
23059
23358
|
compareBridgeVersions(v2, v2);
|
|
23060
23359
|
return v2;
|
|
@@ -23072,34 +23371,34 @@ var RuntimeSelectionError = class extends CreationClientError {
|
|
|
23072
23371
|
});
|
|
23073
23372
|
}
|
|
23074
23373
|
};
|
|
23075
|
-
var runtimeErrorDetails = (
|
|
23374
|
+
var runtimeErrorDetails = (error4) => error4 instanceof RuntimeSelectionError ? error4.runtimeFacts : void 0;
|
|
23076
23375
|
var snapshot = (payload) => ({
|
|
23077
23376
|
version: payload.version,
|
|
23078
23377
|
hosts: payload.hosts,
|
|
23079
23378
|
payloadDigest: payload.payloadDigest,
|
|
23080
|
-
files: payload.files.map(({ path:
|
|
23379
|
+
files: payload.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))
|
|
23081
23380
|
});
|
|
23082
23381
|
async function info(file) {
|
|
23083
23382
|
try {
|
|
23084
|
-
return await
|
|
23383
|
+
return await lstat4(file);
|
|
23085
23384
|
} catch (e) {
|
|
23086
23385
|
if (e.code === "ENOENT") return null;
|
|
23087
23386
|
throw e;
|
|
23088
23387
|
}
|
|
23089
23388
|
}
|
|
23090
|
-
async function
|
|
23091
|
-
await
|
|
23092
|
-
const s3 = await
|
|
23093
|
-
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw
|
|
23389
|
+
async function privateDirectory2(dir) {
|
|
23390
|
+
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
23391
|
+
const s3 = await lstat4(dir);
|
|
23392
|
+
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw error3("runtime_cache_owner_invalid");
|
|
23094
23393
|
}
|
|
23095
23394
|
async function privateJSON(file) {
|
|
23096
23395
|
const s3 = await info(file);
|
|
23097
23396
|
if (!s3) return null;
|
|
23098
|
-
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) throw
|
|
23099
|
-
return JSON.parse(await
|
|
23397
|
+
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) throw error3("runtime_cache_invalid");
|
|
23398
|
+
return JSON.parse(await readFile4(file, "utf8"));
|
|
23100
23399
|
}
|
|
23101
23400
|
async function syncDirectory(dir) {
|
|
23102
|
-
const fd = await
|
|
23401
|
+
const fd = await open3(dir, "r");
|
|
23103
23402
|
try {
|
|
23104
23403
|
await fd.sync();
|
|
23105
23404
|
} finally {
|
|
@@ -23107,7 +23406,7 @@ async function syncDirectory(dir) {
|
|
|
23107
23406
|
}
|
|
23108
23407
|
}
|
|
23109
23408
|
async function exclusiveJSON(file, value2) {
|
|
23110
|
-
const fd = await
|
|
23409
|
+
const fd = await open3(file, "wx", 384);
|
|
23111
23410
|
try {
|
|
23112
23411
|
await fd.writeFile(JSON.stringify(value2) + "\n");
|
|
23113
23412
|
await fd.sync();
|
|
@@ -23119,9 +23418,9 @@ function checkedRuntimeMetadata(value2, expectedVersion) {
|
|
|
23119
23418
|
version2(expectedVersion);
|
|
23120
23419
|
const tarball = REGISTRY + "/@promptframe/creation/-/creation-" + expectedVersion + ".tgz";
|
|
23121
23420
|
if (value2?.name !== PACKAGE || value2.version !== expectedVersion || value2.dist?.tarball !== tarball || typeof value2.dist.integrity !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(value2.dist.integrity))
|
|
23122
|
-
throw
|
|
23421
|
+
throw error3("runtime_registry_identity_invalid");
|
|
23123
23422
|
const encoded = value2.dist.integrity.slice(7);
|
|
23124
|
-
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw
|
|
23423
|
+
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw error3("runtime_registry_identity_invalid");
|
|
23125
23424
|
return { version: expectedVersion, integrity: value2.dist.integrity, tarball };
|
|
23126
23425
|
}
|
|
23127
23426
|
async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs }) {
|
|
@@ -23131,12 +23430,12 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs
|
|
|
23131
23430
|
let response;
|
|
23132
23431
|
try {
|
|
23133
23432
|
response = await fetchImpl(url2, { signal: controller.signal, redirect: "error" });
|
|
23134
|
-
if (response.status !== 200 || Number(response.headers.get("content-length") ?? 0) > maxBytes || !response.body) throw
|
|
23433
|
+
if (response.status !== 200 || Number(response.headers.get("content-length") ?? 0) > maxBytes || !response.body) throw error3("runtime_fetch_unavailable");
|
|
23135
23434
|
const chunks = [];
|
|
23136
23435
|
let count = 0;
|
|
23137
23436
|
for await (const chunk of response.body) {
|
|
23138
23437
|
count += chunk.length;
|
|
23139
|
-
if (count > maxBytes) throw
|
|
23438
|
+
if (count > maxBytes) throw error3("runtime_download_capacity");
|
|
23140
23439
|
chunks.push(Buffer.from(chunk));
|
|
23141
23440
|
}
|
|
23142
23441
|
return Buffer.concat(chunks, count);
|
|
@@ -23144,68 +23443,68 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs
|
|
|
23144
23443
|
await response?.body?.cancel().catch(() => {
|
|
23145
23444
|
});
|
|
23146
23445
|
if (e instanceof CreationClientError) throw e;
|
|
23147
|
-
throw
|
|
23446
|
+
throw error3("runtime_fetch_unavailable");
|
|
23148
23447
|
} finally {
|
|
23149
23448
|
clearTimeout(timer);
|
|
23150
23449
|
signal?.removeEventListener("abort", abort);
|
|
23151
23450
|
}
|
|
23152
23451
|
}
|
|
23153
23452
|
async function readRuntimeArchive(archive, metadata) {
|
|
23154
|
-
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" +
|
|
23453
|
+
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" + createHash5("sha512").update(archive).digest("base64") !== metadata.integrity) throw error3("runtime_integrity_invalid");
|
|
23155
23454
|
let raw;
|
|
23156
23455
|
try {
|
|
23157
23456
|
raw = gunzipSync(archive, { maxOutputLength: MAX_TAR });
|
|
23158
23457
|
} catch {
|
|
23159
|
-
throw
|
|
23458
|
+
throw error3("runtime_archive_invalid");
|
|
23160
23459
|
}
|
|
23161
23460
|
const files = [], names = /* @__PURE__ */ new Set();
|
|
23162
23461
|
let total = 0, entries = 0, failure2;
|
|
23163
23462
|
const parser = Ct({ strict: true, onReadEntry: (entry) => {
|
|
23164
23463
|
const name = entry.path;
|
|
23165
|
-
if (++entries > 2048 || !["File", "Directory"].includes(entry.type) || !Number.isSafeInteger(entry.size) || entry.size < 0 || entry.size > MAX_PAYLOAD || typeof name !== "string" || name.length > 240 || !name.startsWith("package/") || name.includes("\\") || /[\x00-\x1f\x7f]/.test(name)) failure2 =
|
|
23464
|
+
if (++entries > 2048 || !["File", "Directory"].includes(entry.type) || !Number.isSafeInteger(entry.size) || entry.size < 0 || entry.size > MAX_PAYLOAD || typeof name !== "string" || name.length > 240 || !name.startsWith("package/") || name.includes("\\") || /[\x00-\x1f\x7f]/.test(name)) failure2 = error3("runtime_archive_invalid");
|
|
23166
23465
|
const relative = name.slice(8).replace(/\/$/, "");
|
|
23167
23466
|
if (relative && (relative.normalize("NFC") !== relative || /[<>:"|?*]/.test(relative) || relative.split("/").some((p2) => !p2 || p2 === "." || p2 === ".." || /[. ]$/.test(p2) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(p2) || p2 === "node_modules" || p2 === "credentials.json" || p2.startsWith(".env")) || !roots.has(relative.split("/")[0])))
|
|
23168
|
-
failure2 =
|
|
23467
|
+
failure2 = error3("runtime_archive_invalid");
|
|
23169
23468
|
const portableName = relative.toLowerCase();
|
|
23170
|
-
if (names.has(portableName)) failure2 =
|
|
23469
|
+
if (names.has(portableName)) failure2 = error3("runtime_archive_invalid");
|
|
23171
23470
|
names.add(portableName);
|
|
23172
23471
|
if (entry.type === "Directory") {
|
|
23173
|
-
if (entry.size !== 0) failure2 =
|
|
23472
|
+
if (entry.size !== 0) failure2 = error3("runtime_archive_invalid");
|
|
23174
23473
|
return;
|
|
23175
23474
|
}
|
|
23176
23475
|
total += entry.size;
|
|
23177
|
-
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative) failure2 =
|
|
23476
|
+
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative) failure2 = error3("runtime_archive_capacity");
|
|
23178
23477
|
const chunks = [];
|
|
23179
23478
|
let bytes2 = 0;
|
|
23180
23479
|
entry.on("data", (chunk) => {
|
|
23181
23480
|
bytes2 += chunk.length;
|
|
23182
|
-
if (bytes2 > entry.size) failure2 =
|
|
23481
|
+
if (bytes2 > entry.size) failure2 = error3("runtime_archive_invalid");
|
|
23183
23482
|
if (!failure2) chunks.push(Buffer.from(chunk));
|
|
23184
23483
|
});
|
|
23185
23484
|
entry.on("end", () => {
|
|
23186
|
-
if (bytes2 !== entry.size) failure2 =
|
|
23485
|
+
if (bytes2 !== entry.size) failure2 = error3("runtime_archive_invalid");
|
|
23187
23486
|
if (!failure2) files.push({ path: relative, body: Buffer.concat(chunks, bytes2) });
|
|
23188
23487
|
});
|
|
23189
23488
|
} });
|
|
23190
23489
|
await new Promise((resolve, reject) => {
|
|
23191
|
-
parser.once("error", () => reject(
|
|
23490
|
+
parser.once("error", () => reject(error3("runtime_archive_invalid")));
|
|
23192
23491
|
parser.once("end", resolve);
|
|
23193
23492
|
parser.end(raw);
|
|
23194
23493
|
});
|
|
23195
23494
|
if (failure2) throw failure2;
|
|
23196
|
-
if (!files.length || files.length > 1024) throw
|
|
23495
|
+
if (!files.length || files.length > 1024) throw error3("runtime_archive_invalid");
|
|
23197
23496
|
return files;
|
|
23198
23497
|
}
|
|
23199
23498
|
async function cacheLock(root, signal) {
|
|
23200
|
-
const name =
|
|
23499
|
+
const name = path5.join(root, "prepare.lock"), end = Date.now() + 5e3;
|
|
23201
23500
|
let fd;
|
|
23202
23501
|
while (!fd) {
|
|
23203
23502
|
signal?.throwIfAborted();
|
|
23204
23503
|
try {
|
|
23205
|
-
fd = await
|
|
23504
|
+
fd = await open3(name, "wx", 384);
|
|
23206
23505
|
} catch (e) {
|
|
23207
23506
|
if (e.code !== "EEXIST") throw e;
|
|
23208
|
-
if (Date.now() >= end) throw
|
|
23507
|
+
if (Date.now() >= end) throw error3("runtime_cache_busy");
|
|
23209
23508
|
await pause(50);
|
|
23210
23509
|
}
|
|
23211
23510
|
}
|
|
@@ -23223,51 +23522,51 @@ async function cacheLock(root, signal) {
|
|
|
23223
23522
|
return async () => {
|
|
23224
23523
|
const now = await info(name);
|
|
23225
23524
|
await fd.close();
|
|
23226
|
-
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw
|
|
23525
|
+
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw error3("runtime_lock_changed");
|
|
23227
23526
|
await rm(name);
|
|
23228
23527
|
};
|
|
23229
23528
|
}
|
|
23230
23529
|
async function verifyCached(target, metadata, hostKind) {
|
|
23231
23530
|
if (!await info(target)) return null;
|
|
23232
|
-
await
|
|
23233
|
-
const manifest = await privateJSON(
|
|
23531
|
+
await privateDirectory2(target);
|
|
23532
|
+
const manifest = await privateJSON(path5.join(target, "runtime.json"));
|
|
23234
23533
|
if (!manifest || manifest.contractVersion !== "creation-verified-runtime/v1" || manifest.version !== metadata.version || manifest.integrity !== metadata.integrity)
|
|
23235
|
-
throw
|
|
23534
|
+
throw error3("runtime_cache_invalid");
|
|
23236
23535
|
const names = (await readdir2(target)).filter((name) => name !== "runtime.json").sort();
|
|
23237
|
-
if (names.some((name) => !roots.has(name)) || RUNTIME_PACKAGE_ENTRIES.some((name) => !names.includes(name))) throw
|
|
23536
|
+
if (names.some((name) => !roots.has(name)) || RUNTIME_PACKAGE_ENTRIES.some((name) => !names.includes(name))) throw error3("runtime_cache_invalid");
|
|
23238
23537
|
const payload = await inspectRuntimePackage(target, { entries: names });
|
|
23239
|
-
if (!payload.hosts.includes(hostKind)) throw
|
|
23240
|
-
if (JSON.stringify(snapshot(payload)) !== JSON.stringify(manifest.payload)) throw
|
|
23538
|
+
if (!payload.hosts.includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23539
|
+
if (JSON.stringify(snapshot(payload)) !== JSON.stringify(manifest.payload)) throw error3("runtime_cache_invalid");
|
|
23241
23540
|
return { version: payload.version, root: target, integrity: metadata.integrity, reused: true };
|
|
23242
23541
|
}
|
|
23243
23542
|
async function checkedVersionIndex(cacheRoot, metadata) {
|
|
23244
|
-
const old = await privateJSON(
|
|
23245
|
-
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw
|
|
23543
|
+
const old = await privateJSON(path5.join(cacheRoot, "version-" + metadata.version + ".json"));
|
|
23544
|
+
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw error3("runtime_registry_identity_conflict");
|
|
23246
23545
|
return old;
|
|
23247
23546
|
}
|
|
23248
23547
|
async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
23249
|
-
if (!["codex", "claude-code"].includes(hostKind)) throw
|
|
23250
|
-
if (!
|
|
23548
|
+
if (!["codex", "claude-code"].includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23549
|
+
if (!path5.isAbsolute(cacheRoot ?? "")) throw error3("runtime_cache_owner_invalid");
|
|
23251
23550
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: metadata.version, dist: metadata }, metadata.version);
|
|
23252
|
-
await
|
|
23551
|
+
await privateDirectory2(cacheRoot);
|
|
23253
23552
|
await checkedVersionIndex(cacheRoot, metadata);
|
|
23254
|
-
const target =
|
|
23553
|
+
const target = path5.join(cacheRoot, metadata.version + "-" + hash3(metadata.integrity)), existing = await verifyCached(target, metadata, hostKind);
|
|
23255
23554
|
if (existing) return existing;
|
|
23256
23555
|
const archive = await boundedGet(metadata.tarball, { fetchImpl, signal, maxBytes: MAX_ARCHIVE, timeoutMs: 15e3 });
|
|
23257
23556
|
const files = await readRuntimeArchive(archive, metadata), release = await cacheLock(cacheRoot, signal);
|
|
23258
|
-
const temporary =
|
|
23557
|
+
const temporary = path5.join(cacheRoot, ".partial-" + randomBytes3(12).toString("hex"));
|
|
23259
23558
|
try {
|
|
23260
23559
|
const index = await checkedVersionIndex(cacheRoot, metadata);
|
|
23261
23560
|
const found = await verifyCached(target, metadata, hostKind);
|
|
23262
23561
|
if (found) return found;
|
|
23263
23562
|
const space = await statfs(cacheRoot, { bigint: true }), needed = BigInt(files.reduce((n, f2) => n + f2.body.length, 0) + 4 * 1024 * 1024);
|
|
23264
|
-
if (space.bavail * space.bsize < needed) throw
|
|
23265
|
-
await
|
|
23563
|
+
if (space.bavail * space.bsize < needed) throw error3("runtime_cache_capacity");
|
|
23564
|
+
await mkdir3(temporary, { mode: 448 });
|
|
23266
23565
|
for (const file of files) {
|
|
23267
23566
|
signal?.throwIfAborted();
|
|
23268
|
-
const dest =
|
|
23269
|
-
await
|
|
23270
|
-
const fd = await
|
|
23567
|
+
const dest = path5.join(temporary, ...file.path.split("/"));
|
|
23568
|
+
await mkdir3(path5.dirname(dest), { recursive: true, mode: 448 });
|
|
23569
|
+
const fd = await open3(dest, "wx", 384);
|
|
23271
23570
|
try {
|
|
23272
23571
|
await fd.writeFile(file.body);
|
|
23273
23572
|
await fd.sync();
|
|
@@ -23276,26 +23575,26 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23276
23575
|
}
|
|
23277
23576
|
}
|
|
23278
23577
|
const entries = [...new Set(files.map((file) => file.path.split("/")[0]))].sort();
|
|
23279
|
-
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !entries.includes(name))) throw
|
|
23578
|
+
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !entries.includes(name))) throw error3("runtime_package_incomplete");
|
|
23280
23579
|
const payload = await inspectRuntimePackage(temporary, { entries });
|
|
23281
|
-
if (!payload.hosts.includes(hostKind)) throw
|
|
23282
|
-
if (payload.version !== metadata.version) throw
|
|
23580
|
+
if (!payload.hosts.includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23581
|
+
if (payload.version !== metadata.version) throw error3("runtime_package_version_invalid");
|
|
23283
23582
|
const pkg = JSON.parse(payload.files.find((f2) => f2.path === "package.json").body);
|
|
23284
|
-
if (pkg.repository?.url !== "git+https://github.com/ty-teams/promptframe-creation.git" || pkg.private === true) throw
|
|
23583
|
+
if (pkg.repository?.url !== "git+https://github.com/ty-teams/promptframe-creation.git" || pkg.private === true) throw error3("runtime_package_identity_invalid");
|
|
23285
23584
|
if (checkRuntime) await checkRuntime(temporary, metadata.version);
|
|
23286
23585
|
else {
|
|
23287
23586
|
const result = await execute(
|
|
23288
23587
|
process.execPath,
|
|
23289
|
-
[
|
|
23588
|
+
[path5.join(temporary, "bin/promptframe-creation.mjs"), "--version"],
|
|
23290
23589
|
{ timeout: 5e3, maxBuffer: 65536, windowsHide: true, signal, env: {
|
|
23291
23590
|
...process.env,
|
|
23292
|
-
PROMPTFRAME_CREATION_CONFIG:
|
|
23591
|
+
PROMPTFRAME_CREATION_CONFIG: path5.join(temporary, "no-credentials.json")
|
|
23293
23592
|
} }
|
|
23294
23593
|
);
|
|
23295
|
-
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw
|
|
23594
|
+
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw error3("runtime_package_version_invalid");
|
|
23296
23595
|
}
|
|
23297
23596
|
signal?.throwIfAborted();
|
|
23298
|
-
await exclusiveJSON(
|
|
23597
|
+
await exclusiveJSON(path5.join(temporary, "runtime.json"), {
|
|
23299
23598
|
contractVersion: "creation-verified-runtime/v1",
|
|
23300
23599
|
version: metadata.version,
|
|
23301
23600
|
integrity: metadata.integrity,
|
|
@@ -23303,10 +23602,10 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23303
23602
|
});
|
|
23304
23603
|
await syncDirectory(temporary);
|
|
23305
23604
|
if (!index) {
|
|
23306
|
-
await exclusiveJSON(
|
|
23605
|
+
await exclusiveJSON(path5.join(cacheRoot, "version-" + metadata.version + ".json"), metadata);
|
|
23307
23606
|
await syncDirectory(cacheRoot);
|
|
23308
23607
|
}
|
|
23309
|
-
await
|
|
23608
|
+
await rename3(temporary, target);
|
|
23310
23609
|
await syncDirectory(cacheRoot);
|
|
23311
23610
|
return { version: metadata.version, root: target, integrity: metadata.integrity, reused: false };
|
|
23312
23611
|
} finally {
|
|
@@ -23320,7 +23619,7 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23320
23619
|
async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, resolvedVersion, cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
23321
23620
|
version2(currentVersion);
|
|
23322
23621
|
if (lockedVersion !== void 0) version2(lockedVersion);
|
|
23323
|
-
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw
|
|
23622
|
+
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw error3("runtime_selection_identity_invalid");
|
|
23324
23623
|
if (!policy) throw new RuntimeSelectionError(
|
|
23325
23624
|
"platform_bridge_policy_unavailable",
|
|
23326
23625
|
currentVersion,
|
|
@@ -23339,13 +23638,13 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
23339
23638
|
return { version: currentVersion, current: true, locked: lockedVersion !== void 0, status: "current" };
|
|
23340
23639
|
}
|
|
23341
23640
|
try {
|
|
23342
|
-
await
|
|
23641
|
+
await privateDirectory2(cacheRoot);
|
|
23343
23642
|
let metadata, metadataSource = "registry";
|
|
23344
23643
|
try {
|
|
23345
23644
|
const raw = await boundedGet(REGISTRY + "/@promptframe%2fcreation/" + target, { fetchImpl, signal, maxBytes: 256 * 1024, timeoutMs: 5e3 });
|
|
23346
23645
|
metadata = checkedRuntimeMetadata(JSON.parse(raw), target);
|
|
23347
23646
|
} catch (e) {
|
|
23348
|
-
const prior = await privateJSON(
|
|
23647
|
+
const prior = await privateJSON(path5.join(cacheRoot, "version-" + target + ".json"));
|
|
23349
23648
|
if (!prior) throw e;
|
|
23350
23649
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: target, dist: prior }, target);
|
|
23351
23650
|
metadataSource = "previously-verified-cache";
|
|
@@ -23358,29 +23657,29 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
23358
23657
|
metadataSource
|
|
23359
23658
|
};
|
|
23360
23659
|
} catch (e) {
|
|
23361
|
-
if (signal?.aborted) throw
|
|
23660
|
+
if (signal?.aborted) throw error3("runtime_selection_interrupted");
|
|
23362
23661
|
if (lockedVersion !== void 0)
|
|
23363
23662
|
throw new RuntimeSelectionError("bridge_locked_version_unavailable", currentVersion, lockedVersion, policy, "retry_same_fixed_version_in_new_session");
|
|
23364
23663
|
if (policy && compareBridgeVersions(currentVersion, policy.minBridge) >= 0)
|
|
23365
23664
|
return { version: currentVersion, current: true, locked: false, status: "update_unavailable_current_compatible" };
|
|
23366
23665
|
if (policy) assertBridgeCompatible({ experimental: { "promptframe.creation": policy } }, currentVersion);
|
|
23367
23666
|
if (e instanceof CreationClientError) throw e;
|
|
23368
|
-
throw
|
|
23667
|
+
throw error3("runtime_selection_unavailable");
|
|
23369
23668
|
}
|
|
23370
23669
|
}
|
|
23371
23670
|
|
|
23372
23671
|
// lib/runtime-launch.mjs
|
|
23373
23672
|
import { spawn } from "node:child_process";
|
|
23374
|
-
import
|
|
23673
|
+
import path6 from "node:path";
|
|
23375
23674
|
async function launchSelectedBridge(selection, { host, configFile: configFile2, spawnImpl = spawn, env = process.env } = {}) {
|
|
23376
|
-
if (!
|
|
23675
|
+
if (!path6.isAbsolute(selection.root ?? "") || !path6.isAbsolute(configFile2 ?? "") || !["codex", "claude-code"].includes(host?.kind))
|
|
23377
23676
|
throw new CreationClientError("creation.runtime_launch_invalid");
|
|
23378
23677
|
let child;
|
|
23379
23678
|
try {
|
|
23380
23679
|
child = spawnImpl(
|
|
23381
23680
|
process.execPath,
|
|
23382
23681
|
[
|
|
23383
|
-
|
|
23682
|
+
path6.join(selection.root, "bin/promptframe-creation.mjs"),
|
|
23384
23683
|
"bridge",
|
|
23385
23684
|
"--config",
|
|
23386
23685
|
configFile2,
|
|
@@ -23392,7 +23691,7 @@ async function launchSelectedBridge(selection, { host, configFile: configFile2,
|
|
|
23392
23691
|
{ stdio: "inherit", windowsHide: true, env: {
|
|
23393
23692
|
...env,
|
|
23394
23693
|
PROMPTFRAME_CREATION_CONFIG: configFile2,
|
|
23395
|
-
...host.kind === "claude-code" ? { CLAUDECODE: "1"
|
|
23694
|
+
...host.kind === "claude-code" ? { CLAUDECODE: "1" } : {}
|
|
23396
23695
|
} }
|
|
23397
23696
|
);
|
|
23398
23697
|
} catch {
|
|
@@ -23422,10 +23721,10 @@ async function launchSelectedBridge(selection, { host, configFile: configFile2,
|
|
|
23422
23721
|
// lib/user-installation.mjs
|
|
23423
23722
|
import { execFile as execFile2 } from "node:child_process";
|
|
23424
23723
|
import { promisify as promisify2 } from "node:util";
|
|
23425
|
-
import { createHash as
|
|
23426
|
-
import { lstat as
|
|
23427
|
-
import { homedir as
|
|
23428
|
-
import
|
|
23724
|
+
import { createHash as createHash6, randomBytes as randomBytes4 } from "node:crypto";
|
|
23725
|
+
import { lstat as lstat5, mkdir as mkdir4, readdir as readdir3, readFile as readFile5, writeFile as writeFile2, rename as rename4, rm as rm2, open as open4 } from "node:fs/promises";
|
|
23726
|
+
import { homedir as homedir4 } from "node:os";
|
|
23727
|
+
import path7 from "node:path";
|
|
23429
23728
|
|
|
23430
23729
|
// node_modules/smol-toml/dist/error.js
|
|
23431
23730
|
function getLineColFromPtr(string4, ptr) {
|
|
@@ -23517,14 +23816,14 @@ function parseString(ctx) {
|
|
|
23517
23816
|
let value2 = 0;
|
|
23518
23817
|
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
23519
23818
|
for (let j2 = 0; j2 < len; j2++, ctx.p++) {
|
|
23520
|
-
let
|
|
23819
|
+
let hex2 = ctx.s.charCodeAt(ctx.p);
|
|
23521
23820
|
let digit = (
|
|
23522
23821
|
/* 0-9 */
|
|
23523
|
-
|
|
23822
|
+
hex2 >= 48 && hex2 <= 57 ? hex2 - 48 : (
|
|
23524
23823
|
/* A-F */
|
|
23525
|
-
|
|
23824
|
+
hex2 >= 65 && hex2 <= 70 ? hex2 - 65 + 10 : (
|
|
23526
23825
|
/* a-f */
|
|
23527
|
-
|
|
23826
|
+
hex2 >= 97 && hex2 <= 102 ? hex2 - 97 + 10 : -1
|
|
23528
23827
|
)
|
|
23529
23828
|
)
|
|
23530
23829
|
);
|
|
@@ -24187,7 +24486,7 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
24187
24486
|
|
|
24188
24487
|
// lib/user-installation.mjs
|
|
24189
24488
|
var execute2 = promisify2(execFile2);
|
|
24190
|
-
var
|
|
24489
|
+
var hash4 = (b2) => createHash6("sha256").update(b2).digest("hex");
|
|
24191
24490
|
var InstallationError = class extends CreationClientError {
|
|
24192
24491
|
constructor(code, details) {
|
|
24193
24492
|
super("installation." + code);
|
|
@@ -24197,7 +24496,7 @@ var InstallationError = class extends CreationClientError {
|
|
|
24197
24496
|
var fail = (code, details) => {
|
|
24198
24497
|
throw new InstallationError(code, details);
|
|
24199
24498
|
};
|
|
24200
|
-
var installationErrorDetails = (
|
|
24499
|
+
var installationErrorDetails = (error4) => error4 instanceof InstallationError ? error4.details : void 0;
|
|
24201
24500
|
function compareVersions(a, b2) {
|
|
24202
24501
|
const left = a.split(".").map(BigInt), right = b2.split(".").map(BigInt);
|
|
24203
24502
|
for (let i = 0; i < 3; i++) {
|
|
@@ -24218,7 +24517,7 @@ function pinnedGitSource(source) {
|
|
|
24218
24517
|
const refKind = /^[a-f0-9]{40}$/i.test(ref) ? "commit" : /^(?:refs\/tags\/)?creation-v\d+\.\d+\.\d+$/.test(ref) ? "tag" : null;
|
|
24219
24518
|
return refKind ? { refName: ref, refKind } : null;
|
|
24220
24519
|
}
|
|
24221
|
-
var json = async (file) => JSON.parse(await
|
|
24520
|
+
var json = async (file) => JSON.parse(await readFile5(file, "utf8"));
|
|
24222
24521
|
var pause2 = (ms2) => new Promise((r) => setTimeout(r, ms2));
|
|
24223
24522
|
function validProfile(profile) {
|
|
24224
24523
|
if (typeof profile !== "string" || !/^[a-z][a-z0-9-]{0,31}$/.test(profile)) fail("profile_invalid");
|
|
@@ -24226,8 +24525,8 @@ function validProfile(profile) {
|
|
|
24226
24525
|
}
|
|
24227
24526
|
function profileCredentialsPath(profile = "default", env = process.env) {
|
|
24228
24527
|
validProfile(profile);
|
|
24229
|
-
return profile === "default" ? credentialsPath(env) :
|
|
24230
|
-
env.XDG_CONFIG_HOME ??
|
|
24528
|
+
return profile === "default" ? credentialsPath(env) : path7.resolve(
|
|
24529
|
+
env.XDG_CONFIG_HOME ?? path7.join(homedir4(), ".config"),
|
|
24231
24530
|
"promptframe-creation",
|
|
24232
24531
|
"profiles",
|
|
24233
24532
|
profile,
|
|
@@ -24236,18 +24535,18 @@ function profileCredentialsPath(profile = "default", env = process.env) {
|
|
|
24236
24535
|
}
|
|
24237
24536
|
async function info2(file) {
|
|
24238
24537
|
try {
|
|
24239
|
-
return await
|
|
24538
|
+
return await lstat5(file);
|
|
24240
24539
|
} catch (e) {
|
|
24241
24540
|
if (e.code === "ENOENT") return null;
|
|
24242
24541
|
throw e;
|
|
24243
24542
|
}
|
|
24244
24543
|
}
|
|
24245
|
-
async function
|
|
24246
|
-
await
|
|
24247
|
-
const s3 = await
|
|
24544
|
+
async function privateDirectory3(dir) {
|
|
24545
|
+
await mkdir4(dir, { recursive: true, mode: 448 });
|
|
24546
|
+
const s3 = await lstat5(dir);
|
|
24248
24547
|
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) fail("private_owner_required");
|
|
24249
24548
|
}
|
|
24250
|
-
async function
|
|
24549
|
+
async function privateRead2(file) {
|
|
24251
24550
|
const s3 = await info2(file);
|
|
24252
24551
|
if (!s3) return null;
|
|
24253
24552
|
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) fail("state_invalid");
|
|
@@ -24259,20 +24558,20 @@ async function packageJSON(file) {
|
|
|
24259
24558
|
return json(file);
|
|
24260
24559
|
}
|
|
24261
24560
|
function sameTransport(actual, expected) {
|
|
24262
|
-
return actual?.type === "stdio" && actual.command === expected.command && typeof actual.cwd === "string" &&
|
|
24561
|
+
return actual?.type === "stdio" && actual.command === expected.command && typeof actual.cwd === "string" && path7.resolve(actual.cwd) === path7.resolve(expected.cwd) && JSON.stringify(actual.args) === JSON.stringify(expected.args) && JSON.stringify(actual.env_vars ?? []) === JSON.stringify(expected.env_vars ?? []) && !Object.keys(actual.env ?? {}).length;
|
|
24263
24562
|
}
|
|
24264
24563
|
async function managedTransport(installed, versions, serverName, profile, configFile2) {
|
|
24265
24564
|
if (!installed) return null;
|
|
24266
24565
|
const root = installed.source?.path;
|
|
24267
|
-
if (installed.source?.source !== "local" || typeof root !== "string" || !/^\d+\.\d+\.\d+$/.test(installed.version ?? "") || root !==
|
|
24268
|
-
const directory = await info2(root), definition = await info2(
|
|
24566
|
+
if (installed.source?.source !== "local" || typeof root !== "string" || !/^\d+\.\d+\.\d+$/.test(installed.version ?? "") || root !== path7.join(versions, installed.version)) fail("existing_registration_requires_review");
|
|
24567
|
+
const directory = await info2(root), definition = await info2(path7.join(root, ".mcp.json"));
|
|
24269
24568
|
if (!directory?.isDirectory() || directory.isSymbolicLink() || !definition?.isFile() || definition.isSymbolicLink()) fail("installed_files_invalid");
|
|
24270
|
-
const ready = await
|
|
24569
|
+
const ready = await privateRead2(path7.join(root, "installation.json"));
|
|
24271
24570
|
if (!ready || ready.profile !== profile || ready.configFile !== configFile2 || ready.version !== installed.version) fail("existing_registration_requires_review");
|
|
24272
|
-
const bytes2 = await
|
|
24273
|
-
if (!entry || entry.bytes !== bytes2.length || entry.sha256 !==
|
|
24571
|
+
const bytes2 = await readFile5(path7.join(root, ".mcp.json")), entry = ready.files?.find((x) => x.path === ".mcp.json");
|
|
24572
|
+
if (!entry || entry.bytes !== bytes2.length || entry.sha256 !== hash4(bytes2)) fail("installed_files_invalid");
|
|
24274
24573
|
const mcp = JSON.parse(bytes2).mcpServers?.[serverName];
|
|
24275
|
-
if (!mcp || typeof mcp.command !== "string" || !mcp.command || mcp.cwd !== root || JSON.stringify(mcp.args) !== JSON.stringify([
|
|
24574
|
+
if (!mcp || typeof mcp.command !== "string" || !mcp.command || mcp.cwd !== root || JSON.stringify(mcp.args) !== JSON.stringify([path7.join(root, "bin/promptframe-creation.mjs"), "bridge", "--config", configFile2])) fail("existing_registration_requires_review");
|
|
24276
24575
|
return mcp;
|
|
24277
24576
|
}
|
|
24278
24577
|
async function officialNpmInstallation(installed, servers, env, profile, configFile2) {
|
|
@@ -24280,12 +24579,12 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
24280
24579
|
const candidates = installed.filter((p3) => p3.enabled === true && p3.name === "promptframe-creation" && p3.pluginId === "promptframe-creation@" + p3.marketplaceName && /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(p3.marketplaceName ?? "") && /^\d+\.\d+\.\d+$/.test(p3.version ?? "") && p3.source?.source === "npm" && p3.source.package === "@promptframe/creation" && p3.source.version === p3.version && ["https://registry.npmjs.org", "https://registry.npmjs.org/"].includes(p3.source.registry));
|
|
24281
24580
|
if (candidates.length > 1) fail("existing_registration_requires_review");
|
|
24282
24581
|
if (!candidates.length) return null;
|
|
24283
|
-
const p2 = candidates[0], root =
|
|
24582
|
+
const p2 = candidates[0], root = path7.join(path7.resolve(env.CODEX_HOME ?? path7.join(homedir4(), ".codex")), "plugins/cache", p2.marketplaceName, p2.name, p2.version);
|
|
24284
24583
|
const directory = await info2(root);
|
|
24285
24584
|
if (!directory?.isDirectory() || directory.isSymbolicLink()) fail("installed_files_invalid");
|
|
24286
|
-
const pkg = await packageJSON(
|
|
24585
|
+
const pkg = await packageJSON(path7.join(root, "package.json")), manifest = await packageJSON(path7.join(root, ".codex-plugin/plugin.json"));
|
|
24287
24586
|
if (pkg.name !== "@promptframe/creation" || pkg.version !== p2.version || manifest.name !== p2.name || manifest.version !== p2.version) fail("installed_files_invalid");
|
|
24288
|
-
const definition = (await packageJSON(
|
|
24587
|
+
const definition = (await packageJSON(path7.join(root, ".mcp.json"))).mcpServers?.promptframe;
|
|
24289
24588
|
if (!definition || definition.command !== "node" || definition.cwd !== "." || JSON.stringify(definition.args) !== JSON.stringify(["bin/promptframe-creation.mjs", "bridge"]) || JSON.stringify(definition.env_vars) !== JSON.stringify(["PROMPTFRAME_CREATION_CONFIG", "XDG_CONFIG_HOME"])) fail("legacy_mcp_entry_requires_review");
|
|
24290
24589
|
if (servers.length !== 1 || servers[0].enabled !== true || !sameTransport(servers[0].transport, { ...definition, cwd: root }) || JSON.stringify(servers[0].transport.env_vars) !== JSON.stringify(definition.env_vars)) fail("legacy_mcp_entry_requires_review");
|
|
24291
24590
|
return {
|
|
@@ -24302,17 +24601,17 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
24302
24601
|
};
|
|
24303
24602
|
}
|
|
24304
24603
|
async function atomicJSON(file, value2) {
|
|
24305
|
-
const temp = file + "." +
|
|
24604
|
+
const temp = file + "." + randomBytes4(12).toString("hex") + ".tmp";
|
|
24306
24605
|
try {
|
|
24307
|
-
const out = await
|
|
24606
|
+
const out = await open4(temp, "wx", 384);
|
|
24308
24607
|
try {
|
|
24309
24608
|
await out.writeFile(JSON.stringify(value2, null, 2) + "\n");
|
|
24310
24609
|
await out.sync();
|
|
24311
24610
|
} finally {
|
|
24312
24611
|
await out.close();
|
|
24313
24612
|
}
|
|
24314
|
-
await
|
|
24315
|
-
const directory = await
|
|
24613
|
+
await rename4(temp, file);
|
|
24614
|
+
const directory = await open4(path7.dirname(file), "r");
|
|
24316
24615
|
try {
|
|
24317
24616
|
await directory.sync();
|
|
24318
24617
|
} finally {
|
|
@@ -24323,13 +24622,13 @@ async function atomicJSON(file, value2) {
|
|
|
24323
24622
|
}
|
|
24324
24623
|
}
|
|
24325
24624
|
async function acquire(root, signal) {
|
|
24326
|
-
const lock =
|
|
24625
|
+
const lock = path7.join(root, "install.lock");
|
|
24327
24626
|
const end = Date.now() + 3e4;
|
|
24328
24627
|
let owned = false;
|
|
24329
24628
|
while (!owned) {
|
|
24330
24629
|
signal?.throwIfAborted();
|
|
24331
24630
|
try {
|
|
24332
|
-
await
|
|
24631
|
+
await mkdir4(lock, { mode: 448 });
|
|
24333
24632
|
owned = true;
|
|
24334
24633
|
} catch (e) {
|
|
24335
24634
|
if (e.code !== "EEXIST") throw e;
|
|
@@ -24338,7 +24637,7 @@ async function acquire(root, signal) {
|
|
|
24338
24637
|
}
|
|
24339
24638
|
}
|
|
24340
24639
|
try {
|
|
24341
|
-
await writeFile2(
|
|
24640
|
+
await writeFile2(path7.join(lock, "owner.json"), JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() }), { flag: "wx", mode: 384 });
|
|
24342
24641
|
} catch (e) {
|
|
24343
24642
|
await rm2(lock, { recursive: true, force: true });
|
|
24344
24643
|
throw e;
|
|
@@ -24379,12 +24678,12 @@ async function codexJSON(runCodex, args2) {
|
|
|
24379
24678
|
}
|
|
24380
24679
|
}
|
|
24381
24680
|
async function relatedPlugins(runCodex, pluginName, env) {
|
|
24382
|
-
const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), pinnedMarketplaces = /* @__PURE__ */ new Map(), config2 =
|
|
24681
|
+
const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), pinnedMarketplaces = /* @__PURE__ */ new Map(), config2 = path7.join(path7.resolve(env.CODEX_HOME ?? path7.join(homedir4(), ".codex")), "config.toml");
|
|
24383
24682
|
try {
|
|
24384
24683
|
const s3 = await info2(config2);
|
|
24385
24684
|
if (s3) {
|
|
24386
24685
|
if (!s3.isFile() || s3.isSymbolicLink() || s3.size > 2 * 1024 * 1024) throw Error();
|
|
24387
|
-
const plugins = parse3(await
|
|
24686
|
+
const plugins = parse3(await readFile5(config2, "utf8")).plugins ?? {};
|
|
24388
24687
|
if (!plugins || typeof plugins !== "object" || Array.isArray(plugins) || Object.keys(plugins).length > 1024) throw Error();
|
|
24389
24688
|
for (const id of Object.keys(plugins)) if (id.startsWith(pluginName + "@")) {
|
|
24390
24689
|
const market = id.slice(pluginName.length + 1);
|
|
@@ -24399,10 +24698,10 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
24399
24698
|
const state = await codexJSON(runCodex, ["plugin", "marketplace", "list", "--json"]);
|
|
24400
24699
|
if (!Array.isArray(state?.marketplaces) || state.marketplaces.length > 128) fail("local_catalog_unconfirmed");
|
|
24401
24700
|
for (const market of state.marketplaces) {
|
|
24402
|
-
if (typeof market.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name) || typeof market.root !== "string" || !
|
|
24701
|
+
if (typeof market.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name) || typeof market.root !== "string" || !path7.isAbsolute(market.root)) fail("local_catalog_unconfirmed");
|
|
24403
24702
|
let catalog;
|
|
24404
24703
|
try {
|
|
24405
|
-
catalog = await packageJSON(
|
|
24704
|
+
catalog = await packageJSON(path7.join(market.root, ".agents/plugins/marketplace.json"));
|
|
24406
24705
|
} catch {
|
|
24407
24706
|
fail("local_catalog_unconfirmed", { phase: "local_check", commandKind: "marketplace_read", localRegistrationState: "unknown", action: "restore_local_marketplace_catalog" });
|
|
24408
24707
|
}
|
|
@@ -24433,7 +24732,7 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
24433
24732
|
}
|
|
24434
24733
|
async function runNode(root, version3) {
|
|
24435
24734
|
try {
|
|
24436
|
-
const result = await execute2(process.execPath, [
|
|
24735
|
+
const result = await execute2(process.execPath, [path7.join(root, "bin/promptframe-creation.mjs"), "--version"], { encoding: "utf8", timeout: 1e4, maxBuffer: 8192 });
|
|
24437
24736
|
if (result.stdout.trim() !== version3) fail("runtime_version_mismatch");
|
|
24438
24737
|
} catch (e) {
|
|
24439
24738
|
if (e instanceof CreationClientError) throw e;
|
|
@@ -24447,7 +24746,7 @@ async function checkInstalledRuntime(root, version3, command2, { env = process.e
|
|
|
24447
24746
|
if (!major || Number(major[1]) < 20) throw Error("unsupported_node");
|
|
24448
24747
|
const result = await execute2(
|
|
24449
24748
|
command2,
|
|
24450
|
-
[
|
|
24749
|
+
[path7.join(root, "bin/promptframe-creation.mjs"), "--version"],
|
|
24451
24750
|
{ env, encoding: "utf8", timeout: 1e4, maxBuffer: 8192 }
|
|
24452
24751
|
);
|
|
24453
24752
|
if (result.stdout.trim() !== version3) throw Error("wrong_version");
|
|
@@ -24461,8 +24760,8 @@ async function checkInstalledRuntime(root, version3, command2, { env = process.e
|
|
|
24461
24760
|
}
|
|
24462
24761
|
var installationFiles = Object.freeze({
|
|
24463
24762
|
info: info2,
|
|
24464
|
-
privateDirectory:
|
|
24465
|
-
privateRead,
|
|
24763
|
+
privateDirectory: privateDirectory3,
|
|
24764
|
+
privateRead: privateRead2,
|
|
24466
24765
|
atomicJSON,
|
|
24467
24766
|
acquire,
|
|
24468
24767
|
runNode,
|
|
@@ -24484,21 +24783,21 @@ async function installForUser({
|
|
|
24484
24783
|
const versionOutput = await runCodex(["--version"]);
|
|
24485
24784
|
const match = versionOutput.match(/codex-cli (\d+)\.(\d+)\.(\d+)/);
|
|
24486
24785
|
if (!match || Number(match[1]) === 0 && Number(match[2]) < 160) fail("codex_0160_required");
|
|
24487
|
-
const payload = await inspectRuntimePackage(
|
|
24488
|
-
const root =
|
|
24489
|
-
await
|
|
24786
|
+
const payload = await inspectRuntimePackage(path7.resolve(sourceRoot));
|
|
24787
|
+
const root = path7.resolve(env.XDG_DATA_HOME ?? path7.join(homedir4(), ".local/share"), "promptframe-creation", profile);
|
|
24788
|
+
await privateDirectory3(root);
|
|
24490
24789
|
const release = await acquire(root, signal);
|
|
24491
|
-
const versions =
|
|
24492
|
-
const marketplaceFile =
|
|
24790
|
+
const versions = path7.join(root, "versions"), currentFile = path7.join(root, "current.json"), pendingFile = path7.join(root, "registration-pending.json");
|
|
24791
|
+
const marketplaceFile = path7.join(root, ".agents/plugins/marketplace.json");
|
|
24493
24792
|
const pluginName = "promptframe-creation" + (profile === "default" ? "" : "-" + profile), marketplace = "promptframe-creation-user" + (profile === "default" ? "" : "-" + profile);
|
|
24494
24793
|
const pluginId = pluginName + "@" + marketplace;
|
|
24495
|
-
const versionRoot =
|
|
24794
|
+
const versionRoot = path7.join(versions, payload.version), temporary = path7.join(versions, ".partial-" + randomBytes4(12).toString("hex"));
|
|
24496
24795
|
let previous, registrationStarted = false, newFiles = 0;
|
|
24497
24796
|
try {
|
|
24498
24797
|
signal?.throwIfAborted();
|
|
24499
|
-
await
|
|
24500
|
-
await
|
|
24501
|
-
previous = await
|
|
24798
|
+
await privateDirectory3(versions);
|
|
24799
|
+
await privateDirectory3(path7.dirname(marketplaceFile));
|
|
24800
|
+
previous = await privateRead2(currentFile);
|
|
24502
24801
|
if (previous && (previous.profile !== profile || previous.pluginId !== pluginId || previous.configFile !== configFile2)) fail("profile_binding_conflict");
|
|
24503
24802
|
const state = { installed: await relatedPlugins(runCodex, pluginName, env) };
|
|
24504
24803
|
const installed = state.installed.find((x) => x.pluginId === pluginId);
|
|
@@ -24506,14 +24805,14 @@ async function installForUser({
|
|
|
24506
24805
|
if (!Array.isArray(legacy)) fail("local_registration_unconfirmed");
|
|
24507
24806
|
const serverName = "promptframe" + (profile === "default" ? "" : "-" + profile);
|
|
24508
24807
|
const servers = legacy.filter((x) => x.name === serverName);
|
|
24509
|
-
const pending = await
|
|
24808
|
+
const pending = await privateRead2(pendingFile);
|
|
24510
24809
|
if (pending) {
|
|
24511
|
-
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !==
|
|
24810
|
+
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !== path7.join(versions, pending.version)) fail("profile_binding_conflict");
|
|
24512
24811
|
if (installed?.version !== pending.version || installed.enabled !== true || installed.source?.path !== pending.versionRoot)
|
|
24513
24812
|
fail("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
24514
24813
|
const transport2 = await managedTransport(installed, versions, serverName, profile, configFile2);
|
|
24515
24814
|
if (servers.length !== 1 || servers[0].enabled === false || !sameTransport(servers[0].transport, transport2)) fail("registration_unconfirmed_keep_existing");
|
|
24516
|
-
const ready = await
|
|
24815
|
+
const ready = await privateRead2(path7.join(pending.versionRoot, "installation.json"));
|
|
24517
24816
|
if (ready?.payloadDigest !== pending.payloadDigest) fail("installed_files_invalid");
|
|
24518
24817
|
previous = pending;
|
|
24519
24818
|
await atomicJSON(currentFile, pending);
|
|
@@ -24568,43 +24867,43 @@ async function installForUser({
|
|
|
24568
24867
|
const target = await info2(versionRoot);
|
|
24569
24868
|
if (target) {
|
|
24570
24869
|
if (!target.isDirectory() || target.isSymbolicLink()) fail("version_content_conflict");
|
|
24571
|
-
const ready = await
|
|
24870
|
+
const ready = await privateRead2(path7.join(versionRoot, "installation.json"));
|
|
24572
24871
|
if (!ready || ready.payloadDigest !== payload.payloadDigest || ready.profile !== profile || ready.configFile !== configFile2) fail("version_content_conflict");
|
|
24573
24872
|
for (const f2 of ready.files) {
|
|
24574
24873
|
if (!payload.files.some((p2) => p2.path === f2.path)) fail("installed_files_invalid");
|
|
24575
|
-
const file =
|
|
24576
|
-
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size !== f2.bytes ||
|
|
24874
|
+
const file = path7.join(versionRoot, f2.path), s3 = await info2(file);
|
|
24875
|
+
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size !== f2.bytes || hash4(await readFile5(file)) !== f2.sha256) fail("installed_files_invalid");
|
|
24577
24876
|
}
|
|
24578
24877
|
if (ready.files.length !== payload.files.length) fail("installed_files_invalid");
|
|
24579
24878
|
} else {
|
|
24580
|
-
await
|
|
24879
|
+
await mkdir4(temporary, { mode: 448 });
|
|
24581
24880
|
for (const f2 of payload.files) {
|
|
24582
24881
|
signal?.throwIfAborted();
|
|
24583
|
-
await
|
|
24584
|
-
await writeFile2(
|
|
24882
|
+
await mkdir4(path7.dirname(path7.join(temporary, f2.path)), { recursive: true, mode: 448 });
|
|
24883
|
+
await writeFile2(path7.join(temporary, f2.path), f2.body, { flag: "wx", mode: 384 });
|
|
24585
24884
|
}
|
|
24586
|
-
const manifest = await json(
|
|
24885
|
+
const manifest = await json(path7.join(temporary, ".codex-plugin/plugin.json"));
|
|
24587
24886
|
manifest.name = pluginName;
|
|
24588
|
-
await writeFile2(
|
|
24887
|
+
await writeFile2(path7.join(temporary, ".codex-plugin/plugin.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
24589
24888
|
const mcp = { mcpServers: { ["promptframe" + (profile === "default" ? "" : "-" + profile)]: {
|
|
24590
24889
|
command: process.execPath,
|
|
24591
|
-
args: [
|
|
24890
|
+
args: [path7.join(versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", configFile2],
|
|
24592
24891
|
cwd: versionRoot
|
|
24593
24892
|
} } };
|
|
24594
|
-
await writeFile2(
|
|
24893
|
+
await writeFile2(path7.join(temporary, ".mcp.json"), JSON.stringify(mcp, null, 2) + "\n");
|
|
24595
24894
|
await checkRuntime(temporary, payload.version);
|
|
24596
24895
|
const files = [];
|
|
24597
24896
|
for (const f2 of payload.files) {
|
|
24598
|
-
const body = await
|
|
24599
|
-
files.push({ path: f2.path, bytes: body.length, sha256:
|
|
24897
|
+
const body = await readFile5(path7.join(temporary, f2.path));
|
|
24898
|
+
files.push({ path: f2.path, bytes: body.length, sha256: hash4(body) });
|
|
24600
24899
|
}
|
|
24601
|
-
await atomicJSON(
|
|
24900
|
+
await atomicJSON(path7.join(temporary, "installation.json"), { version: payload.version, profile, configFile: configFile2, payloadDigest: payload.payloadDigest, files });
|
|
24602
24901
|
signal?.throwIfAborted();
|
|
24603
|
-
await
|
|
24902
|
+
await rename4(temporary, versionRoot);
|
|
24604
24903
|
newFiles = payload.files.length;
|
|
24605
24904
|
}
|
|
24606
24905
|
if (newFiles === 0) {
|
|
24607
|
-
const launch = (await json(
|
|
24906
|
+
const launch = (await json(path7.join(versionRoot, ".mcp.json"))).mcpServers?.[serverName];
|
|
24608
24907
|
await verifyInstalledRuntime(versionRoot, payload.version, launch.command, { env });
|
|
24609
24908
|
}
|
|
24610
24909
|
const complete = { version: payload.version, profile, configFile: configFile2, pluginId, versionRoot, payloadDigest: payload.payloadDigest };
|
|
@@ -24643,16 +24942,16 @@ async function installForUser({
|
|
|
24643
24942
|
reloadRequired: !already,
|
|
24644
24943
|
recordedRuntimeRetained: Boolean(already && recorded && recorded.command !== process.execPath)
|
|
24645
24944
|
};
|
|
24646
|
-
} catch (
|
|
24945
|
+
} catch (error4) {
|
|
24647
24946
|
if (registrationStarted) {
|
|
24648
24947
|
fail("registration_unconfirmed_keep_existing", {
|
|
24649
|
-
...installationErrorDetails(
|
|
24948
|
+
...installationErrorDetails(error4),
|
|
24650
24949
|
phase: "registration_observation",
|
|
24651
24950
|
localRegistrationState: "unknown",
|
|
24652
24951
|
action: "inspect_same_registration_no_second_add"
|
|
24653
24952
|
});
|
|
24654
24953
|
}
|
|
24655
|
-
if (
|
|
24954
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
24656
24955
|
if (signal?.aborted) fail("interrupted_keep_existing");
|
|
24657
24956
|
fail("failed_keep_existing");
|
|
24658
24957
|
} finally {
|
|
@@ -24662,18 +24961,36 @@ async function installForUser({
|
|
|
24662
24961
|
}
|
|
24663
24962
|
|
|
24664
24963
|
// lib/claude-installation.mjs
|
|
24665
|
-
import { createHash as
|
|
24666
|
-
import { mkdir as
|
|
24667
|
-
import { homedir as
|
|
24668
|
-
import
|
|
24964
|
+
import { createHash as createHash9, randomBytes as randomBytes6 } from "node:crypto";
|
|
24965
|
+
import { mkdir as mkdir6, open as open7, readFile as readFile8, rename as rename6, rm as rm5 } from "node:fs/promises";
|
|
24966
|
+
import { homedir as homedir9 } from "node:os";
|
|
24967
|
+
import path12 from "node:path";
|
|
24968
|
+
|
|
24969
|
+
// lib/claude-hook-definition.mjs
|
|
24970
|
+
function claudeHostHooks({ pluginName = "promptframe-creation", serverName, configFile: configFile2, nodeCommand = "node", runtimeRoot = "${CLAUDE_PLUGIN_ROOT}" } = {}) {
|
|
24971
|
+
const escaped = pluginName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24972
|
+
const command2 = { type: "command", command: nodeCommand, args: [
|
|
24973
|
+
runtimeRoot + "/bin/promptframe-creation.mjs",
|
|
24974
|
+
"claude-host-hook",
|
|
24975
|
+
...configFile2 ? ["--config", configFile2] : []
|
|
24976
|
+
], timeout: 5 };
|
|
24977
|
+
return {
|
|
24978
|
+
SessionStart: [{ matcher: "startup|resume|fork|clear|compact", hooks: [{ ...command2 }] }],
|
|
24979
|
+
PreToolUse: [{
|
|
24980
|
+
matcher: serverName ? "^mcp__" + serverName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "__.*" : "^mcp__plugin_" + escaped + "_.*",
|
|
24981
|
+
hooks: [{ ...command2, onFailure: "block" }]
|
|
24982
|
+
}],
|
|
24983
|
+
SessionEnd: [{ hooks: [{ ...command2 }] }]
|
|
24984
|
+
};
|
|
24985
|
+
}
|
|
24669
24986
|
|
|
24670
24987
|
// lib/claude-command.mjs
|
|
24671
24988
|
import { execFile as execFile3 } from "node:child_process";
|
|
24672
24989
|
import { promisify as promisify3 } from "node:util";
|
|
24673
|
-
import { access, lstat as
|
|
24674
|
-
import { constants } from "node:fs";
|
|
24675
|
-
import { homedir as
|
|
24676
|
-
import
|
|
24990
|
+
import { access, lstat as lstat6, readdir as readdir4 } from "node:fs/promises";
|
|
24991
|
+
import { constants as constants2 } from "node:fs";
|
|
24992
|
+
import { homedir as homedir5 } from "node:os";
|
|
24993
|
+
import path8 from "node:path";
|
|
24677
24994
|
var execute3 = promisify3(execFile3);
|
|
24678
24995
|
var ClaudeCommandError = class extends CreationClientError {
|
|
24679
24996
|
constructor(code, details) {
|
|
@@ -24681,24 +24998,24 @@ var ClaudeCommandError = class extends CreationClientError {
|
|
|
24681
24998
|
this.details = details;
|
|
24682
24999
|
}
|
|
24683
25000
|
};
|
|
24684
|
-
var claudeErrorDetails = (
|
|
24685
|
-
async function resolveClaudeCommand({ env = process.env, homeDirectory =
|
|
25001
|
+
var claudeErrorDetails = (error4) => error4 instanceof ClaudeCommandError ? error4.details : void 0;
|
|
25002
|
+
async function resolveClaudeCommand({ env = process.env, homeDirectory = homedir5(), executable } = {}) {
|
|
24686
25003
|
const selected = executable ?? env.PROMPTFRAME_CLAUDE_BIN;
|
|
24687
25004
|
if (selected) {
|
|
24688
|
-
if (!
|
|
24689
|
-
await access(selected,
|
|
25005
|
+
if (!path8.isAbsolute(selected)) throw new CreationClientError("installation.claude_executable_invalid");
|
|
25006
|
+
await access(selected, constants2.X_OK);
|
|
24690
25007
|
return selected;
|
|
24691
25008
|
}
|
|
24692
|
-
for (const directory of (env.PATH ?? "").split(
|
|
24693
|
-
const file =
|
|
25009
|
+
for (const directory of (env.PATH ?? "").split(path8.delimiter).filter(path8.isAbsolute)) {
|
|
25010
|
+
const file = path8.join(directory, process.platform === "win32" ? "claude.exe" : "claude");
|
|
24694
25011
|
try {
|
|
24695
|
-
await access(file,
|
|
25012
|
+
await access(file, constants2.X_OK);
|
|
24696
25013
|
return file;
|
|
24697
25014
|
} catch (e) {
|
|
24698
25015
|
if (!["ENOENT", "EACCES", "ENOTDIR"].includes(e.code)) throw e;
|
|
24699
25016
|
}
|
|
24700
25017
|
}
|
|
24701
|
-
const root =
|
|
25018
|
+
const root = path8.join(homeDirectory, ".claude/remote/ccd-cli");
|
|
24702
25019
|
let entries;
|
|
24703
25020
|
try {
|
|
24704
25021
|
entries = await readdir4(root);
|
|
@@ -24711,9 +25028,9 @@ async function resolveClaudeCommand({ env = process.env, homeDirectory = homedir
|
|
|
24711
25028
|
for (const name of entries) {
|
|
24712
25029
|
const match = name.match(/^(\d+)\.(\d+)\.(\d+)-[a-f0-9]{6,40}$/);
|
|
24713
25030
|
if (!match) continue;
|
|
24714
|
-
const file =
|
|
25031
|
+
const file = path8.join(root, name), s3 = await lstat6(file);
|
|
24715
25032
|
if (s3.isFile() && !s3.isSymbolicLink() && s3.uid === process.getuid?.()) {
|
|
24716
|
-
await access(file,
|
|
25033
|
+
await access(file, constants2.X_OK);
|
|
24717
25034
|
candidates.push({ file, version: match.slice(1).map(Number) });
|
|
24718
25035
|
}
|
|
24719
25036
|
}
|
|
@@ -24749,17 +25066,17 @@ function createClaudeRunner({ env = process.env, executable, signal, resolve = r
|
|
|
24749
25066
|
}
|
|
24750
25067
|
|
|
24751
25068
|
// lib/claude-local-state.mjs
|
|
24752
|
-
import { readFile as
|
|
24753
|
-
import { homedir as
|
|
24754
|
-
import
|
|
25069
|
+
import { readFile as readFile6, lstat as lstat7 } from "node:fs/promises";
|
|
25070
|
+
import { homedir as homedir6 } from "node:os";
|
|
25071
|
+
import path9 from "node:path";
|
|
24755
25072
|
function claudeConfigRoot(env = process.env) {
|
|
24756
|
-
return
|
|
25073
|
+
return path9.resolve(env.CLAUDE_CONFIG_DIR ?? path9.join(homedir6(), ".claude"));
|
|
24757
25074
|
}
|
|
24758
25075
|
async function readClaudeUserServer(serverName, env = process.env) {
|
|
24759
|
-
const file = env.CLAUDE_CONFIG_DIR ?
|
|
25076
|
+
const file = env.CLAUDE_CONFIG_DIR ? path9.join(claudeConfigRoot(env), ".claude.json") : path9.join(homedir6(), ".claude.json");
|
|
24760
25077
|
let info5;
|
|
24761
25078
|
try {
|
|
24762
|
-
info5 = await
|
|
25079
|
+
info5 = await lstat7(file);
|
|
24763
25080
|
} catch (e) {
|
|
24764
25081
|
if (e.code === "ENOENT") return null;
|
|
24765
25082
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
@@ -24768,7 +25085,7 @@ async function readClaudeUserServer(serverName, env = process.env) {
|
|
|
24768
25085
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
24769
25086
|
let state;
|
|
24770
25087
|
try {
|
|
24771
|
-
state = JSON.parse(await
|
|
25088
|
+
state = JSON.parse(await readFile6(file, "utf8"));
|
|
24772
25089
|
} catch {
|
|
24773
25090
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
24774
25091
|
}
|
|
@@ -24779,28 +25096,110 @@ async function readClaudeUserServer(serverName, env = process.env) {
|
|
|
24779
25096
|
}
|
|
24780
25097
|
|
|
24781
25098
|
// lib/claude-mcp-installation.mjs
|
|
24782
|
-
import { createHash as
|
|
24783
|
-
import { mkdir as
|
|
24784
|
-
import { homedir as
|
|
24785
|
-
import
|
|
24786
|
-
|
|
24787
|
-
|
|
25099
|
+
import { createHash as createHash8, randomBytes as randomBytes5 } from "node:crypto";
|
|
25100
|
+
import { mkdir as mkdir5, open as open6, readFile as readFile7, readdir as readdir5, rename as rename5, rm as rm4, lstat as lstat8 } from "node:fs/promises";
|
|
25101
|
+
import { homedir as homedir8 } from "node:os";
|
|
25102
|
+
import path11 from "node:path";
|
|
25103
|
+
|
|
25104
|
+
// lib/claude-hook-registration.mjs
|
|
25105
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
25106
|
+
import { open as open5, rm as rm3 } from "node:fs/promises";
|
|
25107
|
+
import { constants as constants3 } from "node:fs";
|
|
25108
|
+
import path10 from "node:path";
|
|
25109
|
+
import { homedir as homedir7 } from "node:os";
|
|
25110
|
+
var { privateDirectory: privateDirectory4, privateRead: privateRead3, atomicJSON: atomicJSON2, acquire: acquire2 } = installationFiles;
|
|
25111
|
+
var digest3 = (value2) => createHash7("sha256").update(JSON.stringify(value2)).digest("hex");
|
|
25112
|
+
var fail2 = () => {
|
|
25113
|
+
throw new CreationClientError("installation.claude_hooks_require_review");
|
|
25114
|
+
};
|
|
25115
|
+
async function settings(file) {
|
|
25116
|
+
let handle;
|
|
25117
|
+
try {
|
|
25118
|
+
handle = await open5(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
25119
|
+
const info5 = await handle.stat();
|
|
25120
|
+
if (!info5.isFile() || info5.uid !== process.getuid?.() || info5.size > 512 * 1024) fail2();
|
|
25121
|
+
const value2 = JSON.parse(await handle.readFile("utf8"));
|
|
25122
|
+
if (!value2 || typeof value2 !== "object" || Array.isArray(value2) || value2.hooks !== void 0 && (!value2.hooks || typeof value2.hooks !== "object" || Array.isArray(value2.hooks))) fail2();
|
|
25123
|
+
return value2;
|
|
25124
|
+
} catch (e) {
|
|
25125
|
+
if (e.code === "ENOENT") return {};
|
|
25126
|
+
throw e;
|
|
25127
|
+
} finally {
|
|
25128
|
+
await handle?.close();
|
|
25129
|
+
}
|
|
25130
|
+
}
|
|
25131
|
+
var contains = (value2, entries) => Object.entries(entries).every(([event, wanted]) => Array.isArray(value2.hooks?.[event]) && wanted.every((entry) => value2.hooks[event].filter((actual) => digest3(actual) === digest3(entry)).length === 1));
|
|
25132
|
+
async function verifyClaudeFallbackHooks(record2, env) {
|
|
25133
|
+
if (!record2?.settingsFile || record2.settingsFile !== path10.join(claudeConfigRoot(env), "settings.json") || !record2.entries) fail2();
|
|
25134
|
+
if (!contains(await settings(record2.settingsFile), record2.entries)) fail2();
|
|
25135
|
+
return true;
|
|
25136
|
+
}
|
|
25137
|
+
async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCommand, signal }) {
|
|
25138
|
+
const directory = claudeConfigRoot(env), file = path10.join(directory, "settings.json");
|
|
25139
|
+
const guard = path10.resolve(
|
|
25140
|
+
env.XDG_DATA_HOME ?? path10.join(homedir7(), ".local/share"),
|
|
25141
|
+
"promptframe-creation",
|
|
25142
|
+
"claude-hook-writer-" + digest3(directory)
|
|
25143
|
+
);
|
|
25144
|
+
await privateDirectory4(guard);
|
|
25145
|
+
const release = await acquire2(guard, signal);
|
|
25146
|
+
const markerFile = path10.join(root, "hooks-current.json"), pendingFile = path10.join(root, "hooks-pending.json");
|
|
25147
|
+
try {
|
|
25148
|
+
await privateDirectory4(directory);
|
|
25149
|
+
const entries = claudeHostHooks({ serverName: record2.serverName, configFile: record2.configFile, nodeCommand, runtimeRoot: record2.versionRoot });
|
|
25150
|
+
const expected = { contractVersion: "creation-claude-hooks/v1", settingsFile: file, profile: record2.profile, entries };
|
|
25151
|
+
const pending = await privateRead3(pendingFile), previous = await privateRead3(markerFile), before = await settings(file);
|
|
25152
|
+
if (pending) {
|
|
25153
|
+
if (digest3(pending) !== digest3(expected) || !contains(before, entries)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
25154
|
+
await atomicJSON2(markerFile, expected);
|
|
25155
|
+
await rm3(pendingFile);
|
|
25156
|
+
return expected;
|
|
25157
|
+
}
|
|
25158
|
+
if (previous) {
|
|
25159
|
+
if (previous.contractVersion !== expected.contractVersion || previous.profile !== record2.profile || previous.settingsFile !== file) fail2();
|
|
25160
|
+
await verifyClaudeFallbackHooks(previous, env);
|
|
25161
|
+
if (digest3(previous) === digest3(expected)) return previous;
|
|
25162
|
+
}
|
|
25163
|
+
const next = { ...before, hooks: { ...before.hooks } };
|
|
25164
|
+
for (const [event, wanted] of Object.entries(entries)) {
|
|
25165
|
+
const actual = next.hooks[event] ?? [];
|
|
25166
|
+
if (!Array.isArray(actual)) fail2();
|
|
25167
|
+
const owned = new Set((previous?.entries[event] ?? []).map(digest3));
|
|
25168
|
+
if (wanted.some((entry) => actual.some((value2) => digest3(value2) === digest3(entry)) && !owned.has(digest3(entry)))) fail2();
|
|
25169
|
+
next.hooks[event] = [...actual.filter((entry) => !owned.has(digest3(entry))), ...wanted];
|
|
25170
|
+
}
|
|
25171
|
+
signal?.throwIfAborted();
|
|
25172
|
+
await atomicJSON2(pendingFile, expected);
|
|
25173
|
+
if (digest3(await settings(file)) !== digest3(before)) fail2();
|
|
25174
|
+
await atomicJSON2(file, next);
|
|
25175
|
+
if (!contains(await settings(file), entries)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
25176
|
+
await atomicJSON2(markerFile, expected);
|
|
25177
|
+
await rm3(pendingFile);
|
|
25178
|
+
return expected;
|
|
25179
|
+
} finally {
|
|
25180
|
+
await release();
|
|
25181
|
+
}
|
|
25182
|
+
}
|
|
25183
|
+
|
|
25184
|
+
// lib/claude-mcp-installation.mjs
|
|
25185
|
+
var { info: info3, privateDirectory: privateDirectory5, privateRead: privateRead4, atomicJSON: atomicJSON3, acquire: acquire3, compareVersions: compareVersions2 } = installationFiles;
|
|
25186
|
+
var hash5 = (body) => createHash8("sha256").update(body).digest("hex");
|
|
24788
25187
|
var FallbackError = class extends CreationClientError {
|
|
24789
25188
|
constructor(code, details) {
|
|
24790
25189
|
super("installation." + code);
|
|
24791
25190
|
this.details = details;
|
|
24792
25191
|
}
|
|
24793
25192
|
};
|
|
24794
|
-
var fallbackErrorDetails = (
|
|
24795
|
-
var
|
|
25193
|
+
var fallbackErrorDetails = (error4) => error4 instanceof FallbackError ? error4.details : void 0;
|
|
25194
|
+
var fail3 = (code, details) => {
|
|
24796
25195
|
throw new FallbackError(code, details);
|
|
24797
25196
|
};
|
|
24798
25197
|
async function claimSkillDirectory(root) {
|
|
24799
25198
|
try {
|
|
24800
|
-
await
|
|
24801
|
-
} catch (
|
|
24802
|
-
if (
|
|
24803
|
-
throw
|
|
25199
|
+
await mkdir5(root, { mode: 448 });
|
|
25200
|
+
} catch (error4) {
|
|
25201
|
+
if (error4.code === "EEXIST") fail3("claude_skill_requires_review");
|
|
25202
|
+
throw error4;
|
|
24804
25203
|
}
|
|
24805
25204
|
}
|
|
24806
25205
|
function same(a, b2, depth = 0) {
|
|
@@ -24810,62 +25209,62 @@ function same(a, b2, depth = 0) {
|
|
|
24810
25209
|
return left.length <= 256 && left.length === right.length && left.every((key, i) => key === right[i] && same(a[key], b2[key], depth + 1));
|
|
24811
25210
|
}
|
|
24812
25211
|
async function atomicText(file, body) {
|
|
24813
|
-
const temporary = file + "." +
|
|
25212
|
+
const temporary = file + "." + randomBytes5(12).toString("hex") + ".tmp";
|
|
24814
25213
|
try {
|
|
24815
|
-
const fd = await
|
|
25214
|
+
const fd = await open6(temporary, "wx", 384);
|
|
24816
25215
|
try {
|
|
24817
25216
|
await fd.writeFile(body);
|
|
24818
25217
|
await fd.sync();
|
|
24819
25218
|
} finally {
|
|
24820
25219
|
await fd.close();
|
|
24821
25220
|
}
|
|
24822
|
-
await
|
|
24823
|
-
const dir = await
|
|
25221
|
+
await rename5(temporary, file);
|
|
25222
|
+
const dir = await open6(path11.dirname(file), "r");
|
|
24824
25223
|
try {
|
|
24825
25224
|
await dir.sync();
|
|
24826
25225
|
} finally {
|
|
24827
25226
|
await dir.close();
|
|
24828
25227
|
}
|
|
24829
25228
|
} finally {
|
|
24830
|
-
if (await info3(temporary)) await
|
|
25229
|
+
if (await info3(temporary)) await rm4(temporary);
|
|
24831
25230
|
}
|
|
24832
25231
|
}
|
|
24833
25232
|
async function verifyVersion(root, record2) {
|
|
24834
25233
|
const directory = await info3(root);
|
|
24835
|
-
if (!directory?.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63)
|
|
24836
|
-
const marker = await
|
|
24837
|
-
if (!marker || marker.host !== "claude-code" || marker.mode !== "mcp-and-skills" || marker.profile !== record2.profile || marker.configFile !== record2.configFile || marker.version !== record2.version || marker.payloadDigest !== record2.payloadDigest || payload.payloadDigest !== marker.payloadDigest || !
|
|
25234
|
+
if (!directory?.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63) fail3("claude_installed_files_invalid");
|
|
25235
|
+
const marker = await privateRead4(path11.join(root, "installation.json")), payload = await inspectRuntimePackage(root);
|
|
25236
|
+
if (!marker || marker.host !== "claude-code" || marker.mode !== "mcp-and-skills" || marker.profile !== record2.profile || marker.configFile !== record2.configFile || marker.version !== record2.version || marker.payloadDigest !== record2.payloadDigest || payload.payloadDigest !== marker.payloadDigest || !path11.isAbsolute(marker.nodeCommand ?? "")) fail3("claude_installed_files_invalid");
|
|
24838
25237
|
return marker;
|
|
24839
25238
|
}
|
|
24840
25239
|
function mcpDefinition(record2, nodeCommand) {
|
|
24841
25240
|
return {
|
|
24842
25241
|
type: "stdio",
|
|
24843
25242
|
command: nodeCommand,
|
|
24844
|
-
args: [
|
|
25243
|
+
args: [path11.join(record2.versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", record2.configFile, "--host", "claude-code"]
|
|
24845
25244
|
};
|
|
24846
25245
|
}
|
|
24847
25246
|
function skillBody(payload, sourceName, name) {
|
|
24848
25247
|
const file = payload.files.find((f2) => f2.path === "skills/" + sourceName + "/SKILL.md");
|
|
24849
|
-
if (!file)
|
|
25248
|
+
if (!file) fail3("package_incomplete");
|
|
24850
25249
|
const body = file.body.toString("utf8");
|
|
24851
|
-
if (!body.startsWith("---\n") || !body.includes("\nname: " + sourceName + "\n"))
|
|
25250
|
+
if (!body.startsWith("---\n") || !body.includes("\nname: " + sourceName + "\n")) fail3("package_incomplete");
|
|
24852
25251
|
return body.replace("\nname: " + sourceName + "\n", "\nname: " + name + "\n");
|
|
24853
25252
|
}
|
|
24854
25253
|
async function observedSkill(plan, record2, { allowBefore = false } = {}) {
|
|
24855
25254
|
const directory = await info3(plan.root);
|
|
24856
25255
|
if (!directory) return false;
|
|
24857
|
-
if (!directory.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63)
|
|
25256
|
+
if (!directory.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63) fail3("claude_skill_requires_review");
|
|
24858
25257
|
const names = await readdir5(plan.root);
|
|
24859
|
-
if (names.some((n) => !["SKILL.md", "promptframe-installation.json"].includes(n)))
|
|
24860
|
-
const marker = await
|
|
25258
|
+
if (names.some((n) => !["SKILL.md", "promptframe-installation.json"].includes(n))) fail3("claude_skill_requires_review");
|
|
25259
|
+
const marker = await privateRead4(path11.join(plan.root, "promptframe-installation.json")), file = path11.join(plan.root, "SKILL.md"), s3 = await info3(file);
|
|
24861
25260
|
if (!marker || marker.host !== "claude-code" || marker.profile !== record2.profile || marker.configFile !== record2.configFile || marker.name !== plan.name)
|
|
24862
|
-
|
|
25261
|
+
fail3("claude_skill_requires_review");
|
|
24863
25262
|
if (!s3 && allowBefore && plan.beforeSHA === null && marker.sha256 === null) return false;
|
|
24864
|
-
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size > 256 * 1024)
|
|
24865
|
-
const
|
|
24866
|
-
if (
|
|
24867
|
-
if (allowBefore && (
|
|
24868
|
-
|
|
25263
|
+
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size > 256 * 1024) fail3("claude_skill_requires_review");
|
|
25264
|
+
const digest4 = hash5(await readFile7(file));
|
|
25265
|
+
if (digest4 === plan.sha256 && marker.sha256 === plan.sha256) return true;
|
|
25266
|
+
if (allowBefore && (digest4 === plan.beforeSHA || digest4 === plan.sha256) && marker.sha256 === plan.beforeSHA) return false;
|
|
25267
|
+
fail3("claude_skill_requires_review");
|
|
24869
25268
|
}
|
|
24870
25269
|
async function installClaudeMcpFallback({
|
|
24871
25270
|
sourceRoot,
|
|
@@ -24879,47 +25278,48 @@ async function installClaudeMcpFallback({
|
|
|
24879
25278
|
nodeCommand,
|
|
24880
25279
|
writeSkill = atomicText
|
|
24881
25280
|
}) {
|
|
24882
|
-
const payload = await inspectRuntimePackage(
|
|
24883
|
-
await
|
|
24884
|
-
const release = await
|
|
25281
|
+
const payload = await inspectRuntimePackage(path11.resolve(sourceRoot)), suffix = profile === "default" ? "" : "-" + profile, serverName = "promptframe" + suffix, root = path11.resolve(env.XDG_DATA_HOME ?? path11.join(homedir8(), ".local/share"), "promptframe-creation", profile, "claude-code-mcp");
|
|
25282
|
+
await privateDirectory5(root);
|
|
25283
|
+
const release = await acquire3(root, signal), versions = path11.join(root, "versions"), currentFile = path11.join(root, "current.json"), pendingFile = path11.join(root, "registration-pending.json"), versionRoot = path11.join(versions, payload.version), temporary = path11.join(versions, ".partial-" + randomBytes5(12).toString("hex"));
|
|
24885
25284
|
let writeStarted = false, newFiles = 0;
|
|
24886
25285
|
const complete = { host: "claude-code", mode: "mcp-and-skills", profile, configFile: configFile2, serverName, version: payload.version, versionRoot, payloadDigest: payload.payloadDigest };
|
|
24887
25286
|
const checkBinding = (record2) => {
|
|
24888
|
-
if (record2 && (record2.host !== "claude-code" || record2.mode !== "mcp-and-skills" || record2.profile !== profile || record2.configFile !== configFile2 || record2.serverName !== serverName || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !==
|
|
25287
|
+
if (record2 && (record2.host !== "claude-code" || record2.mode !== "mcp-and-skills" || record2.profile !== profile || record2.configFile !== configFile2 || record2.serverName !== serverName || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !== path11.join(versions, record2.version))) fail3("profile_binding_conflict");
|
|
24889
25288
|
};
|
|
24890
25289
|
try {
|
|
24891
|
-
await
|
|
24892
|
-
let previous = await
|
|
25290
|
+
await privateDirectory5(versions);
|
|
25291
|
+
let previous = await privateRead4(currentFile), pending = await privateRead4(pendingFile);
|
|
24893
25292
|
checkBinding(previous);
|
|
24894
25293
|
checkBinding(pending);
|
|
24895
25294
|
let saved = await readClaudeUserServer(serverName, env);
|
|
24896
25295
|
complete.beforeServer = pending?.beforeServer ?? saved;
|
|
24897
25296
|
const settled = async (record2) => {
|
|
24898
25297
|
const ready2 = await verifyVersion(record2.versionRoot, record2);
|
|
24899
|
-
if (!same(record2.server, mcpDefinition(record2, ready2.nodeCommand)))
|
|
25298
|
+
if (!same(record2.server, mcpDefinition(record2, ready2.nodeCommand))) fail3("claude_installed_files_invalid");
|
|
24900
25299
|
if (!same(saved, record2.server)) return false;
|
|
24901
|
-
if (
|
|
25300
|
+
if (compareVersions2(record2.version, "0.3.1") >= 0) await verifyClaudeFallbackHooks(record2.hostHooks, env);
|
|
25301
|
+
if (!Array.isArray(record2.skills) || record2.skills.length !== 2) fail3("claude_skill_requires_review");
|
|
24902
25302
|
for (const [i, skill] of record2.skills.entries()) {
|
|
24903
25303
|
const name = ["creation-setup", "video-creation"][i] + suffix;
|
|
24904
|
-
if (skill.name !== name || skill.root !==
|
|
24905
|
-
|
|
25304
|
+
if (skill.name !== name || skill.root !== path11.join(claudeConfigRoot(env), "skills", name) || !/^[a-f0-9]{64}$/.test(skill.sha256 ?? ""))
|
|
25305
|
+
fail3("claude_skill_requires_review");
|
|
24906
25306
|
if (!await observedSkill(skill, record2)) return false;
|
|
24907
25307
|
}
|
|
24908
25308
|
return true;
|
|
24909
25309
|
};
|
|
24910
25310
|
if (pending) {
|
|
24911
25311
|
writeStarted = true;
|
|
24912
|
-
if (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest)
|
|
25312
|
+
if (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest) fail3("registration_unconfirmed_keep_existing");
|
|
24913
25313
|
if (pending.phase === "mcp") {
|
|
24914
|
-
if (!await settled(pending))
|
|
24915
|
-
await
|
|
24916
|
-
await
|
|
25314
|
+
if (!await settled(pending)) fail3("registration_unconfirmed_keep_existing");
|
|
25315
|
+
await atomicJSON3(currentFile, pending);
|
|
25316
|
+
await rm4(pendingFile);
|
|
24917
25317
|
previous = pending;
|
|
24918
25318
|
pending = null;
|
|
24919
|
-
} else if (pending.phase !== "skills" || !same(saved, pending.beforeServer))
|
|
25319
|
+
} else if (pending.phase !== "skills" || !same(saved, pending.beforeServer)) fail3("registration_unconfirmed_keep_existing");
|
|
24920
25320
|
}
|
|
24921
25321
|
if (previous && !pending) {
|
|
24922
|
-
if (!await settled(previous))
|
|
25322
|
+
if (!await settled(previous)) fail3("claude_local_registration_unconfirmed");
|
|
24923
25323
|
if (compareVersions2(previous.version, payload.version) >= 0) {
|
|
24924
25324
|
const ready2 = await verifyVersion(previous.versionRoot, previous);
|
|
24925
25325
|
await verifyInstalledRuntime(previous.versionRoot, previous.version, ready2.nodeCommand, { env });
|
|
@@ -24938,15 +25338,15 @@ async function installClaudeMcpFallback({
|
|
|
24938
25338
|
recordedRuntimeRetained: ready2.nodeCommand !== nodeCommand
|
|
24939
25339
|
};
|
|
24940
25340
|
}
|
|
24941
|
-
} else if (saved && !pending)
|
|
25341
|
+
} else if (saved && !pending) fail3("legacy_mcp_entry_requires_review");
|
|
24942
25342
|
if (await info3(versionRoot)) await verifyVersion(versionRoot, complete);
|
|
24943
25343
|
else {
|
|
24944
|
-
await
|
|
25344
|
+
await mkdir5(temporary, { mode: 448 });
|
|
24945
25345
|
for (const file of payload.files) {
|
|
24946
25346
|
signal?.throwIfAborted();
|
|
24947
|
-
const dest =
|
|
24948
|
-
await
|
|
24949
|
-
const fd = await
|
|
25347
|
+
const dest = path11.join(temporary, file.path);
|
|
25348
|
+
await mkdir5(path11.dirname(dest), { recursive: true, mode: 448 });
|
|
25349
|
+
const fd = await open6(dest, "wx", 384);
|
|
24950
25350
|
try {
|
|
24951
25351
|
await fd.writeFile(file.body);
|
|
24952
25352
|
await fd.sync();
|
|
@@ -24955,33 +25355,33 @@ async function installClaudeMcpFallback({
|
|
|
24955
25355
|
}
|
|
24956
25356
|
}
|
|
24957
25357
|
await checkRuntime(temporary, payload.version);
|
|
24958
|
-
await
|
|
25358
|
+
await atomicJSON3(path11.join(temporary, "installation.json"), { ...complete, nodeCommand });
|
|
24959
25359
|
signal?.throwIfAborted();
|
|
24960
|
-
await
|
|
25360
|
+
await rename5(temporary, versionRoot);
|
|
24961
25361
|
newFiles = payload.files.length;
|
|
24962
25362
|
}
|
|
24963
25363
|
const ready = await verifyVersion(versionRoot, complete);
|
|
24964
25364
|
complete.server = mcpDefinition(complete, ready.nodeCommand);
|
|
24965
25365
|
if (newFiles === 0) await verifyInstalledRuntime(versionRoot, payload.version, ready.nodeCommand, { env });
|
|
24966
|
-
const skillRoot =
|
|
24967
|
-
await
|
|
24968
|
-
const parent = await
|
|
24969
|
-
if (!parent.isDirectory() || parent.isSymbolicLink() || parent.uid !== process.getuid?.())
|
|
25366
|
+
const skillRoot = path11.join(claudeConfigRoot(env), "skills");
|
|
25367
|
+
await mkdir5(skillRoot, { recursive: true, mode: 448 });
|
|
25368
|
+
const parent = await lstat8(skillRoot);
|
|
25369
|
+
if (!parent.isDirectory() || parent.isSymbolicLink() || parent.uid !== process.getuid?.()) fail3("claude_skill_requires_review");
|
|
24970
25370
|
const plans = [];
|
|
24971
25371
|
for (const sourceName of ["creation-setup", "video-creation"]) {
|
|
24972
|
-
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root:
|
|
25372
|
+
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root: path11.join(skillRoot, name), sha256: hash5(body) };
|
|
24973
25373
|
if (pending) {
|
|
24974
25374
|
const old = pending.skills?.find((s3) => s3.name === name);
|
|
24975
|
-
if (!old || old.root !== skill.root || old.sha256 !== skill.sha256)
|
|
25375
|
+
if (!old || old.root !== skill.root || old.sha256 !== skill.sha256) fail3("registration_unconfirmed_keep_existing");
|
|
24976
25376
|
plans.push({ ...old, body });
|
|
24977
25377
|
} else {
|
|
24978
25378
|
const existing = await info3(skill.root);
|
|
24979
25379
|
let beforeSHA = null;
|
|
24980
25380
|
if (existing) {
|
|
24981
|
-
const marker = await
|
|
24982
|
-
if (!marker || marker.profile !== profile || marker.configFile !== configFile2 || marker.name !== name)
|
|
25381
|
+
const marker = await privateRead4(path11.join(skill.root, "promptframe-installation.json"));
|
|
25382
|
+
if (!marker || marker.profile !== profile || marker.configFile !== configFile2 || marker.name !== name) fail3("claude_skill_requires_review");
|
|
24983
25383
|
const old = { ...skill, sha256: marker.sha256 };
|
|
24984
|
-
if (!await observedSkill(old, complete))
|
|
25384
|
+
if (!await observedSkill(old, complete)) fail3("claude_skill_requires_review");
|
|
24985
25385
|
beforeSHA = marker.sha256;
|
|
24986
25386
|
}
|
|
24987
25387
|
plans.push({ ...skill, beforeSHA, body });
|
|
@@ -24989,7 +25389,7 @@ async function installClaudeMcpFallback({
|
|
|
24989
25389
|
}
|
|
24990
25390
|
complete.skills = plans.map(({ body, ...p2 }) => p2);
|
|
24991
25391
|
if (!pending) {
|
|
24992
|
-
await
|
|
25392
|
+
await atomicJSON3(pendingFile, { ...complete, phase: "skills" });
|
|
24993
25393
|
writeStarted = true;
|
|
24994
25394
|
}
|
|
24995
25395
|
for (const plan of plans) {
|
|
@@ -24997,22 +25397,23 @@ async function installClaudeMcpFallback({
|
|
|
24997
25397
|
if (await info3(plan.root)) {
|
|
24998
25398
|
if (await observedSkill(plan, complete, { allowBefore: true })) continue;
|
|
24999
25399
|
} else {
|
|
25000
|
-
if (plan.beforeSHA !== null)
|
|
25400
|
+
if (plan.beforeSHA !== null) fail3("claude_skill_requires_review");
|
|
25001
25401
|
await claimSkillDirectory(plan.root);
|
|
25002
|
-
await
|
|
25402
|
+
await atomicJSON3(path11.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: null });
|
|
25003
25403
|
}
|
|
25004
|
-
await writeSkill(
|
|
25005
|
-
await
|
|
25404
|
+
await writeSkill(path11.join(plan.root, "SKILL.md"), plan.body);
|
|
25405
|
+
await atomicJSON3(path11.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: plan.sha256 });
|
|
25006
25406
|
}
|
|
25007
25407
|
signal?.throwIfAborted();
|
|
25008
|
-
if (
|
|
25009
|
-
await
|
|
25408
|
+
if (compareVersions2(payload.version, "0.3.1") >= 0) complete.hostHooks = await registerClaudeFallbackHooks({ record: complete, root, env, nodeCommand: ready.nodeCommand, signal });
|
|
25409
|
+
if (!same(await readClaudeUserServer(serverName, env), complete.beforeServer)) fail3("claude_local_registration_changed");
|
|
25410
|
+
await atomicJSON3(pendingFile, { ...complete, phase: "mcp" });
|
|
25010
25411
|
writeStarted = true;
|
|
25011
25412
|
await runClaude(["mcp", "add-json", "--scope", "user", serverName, JSON.stringify(complete.server)]);
|
|
25012
25413
|
saved = await readClaudeUserServer(serverName, env);
|
|
25013
|
-
if (!await settled(complete))
|
|
25014
|
-
await
|
|
25015
|
-
await
|
|
25414
|
+
if (!await settled(complete)) fail3("registration_unconfirmed_keep_existing");
|
|
25415
|
+
await atomicJSON3(currentFile, complete);
|
|
25416
|
+
await rm4(pendingFile);
|
|
25016
25417
|
return {
|
|
25017
25418
|
...complete,
|
|
25018
25419
|
currentFile,
|
|
@@ -25026,18 +25427,18 @@ async function installClaudeMcpFallback({
|
|
|
25026
25427
|
requestedVersion: payload.version,
|
|
25027
25428
|
versionStatus: "current"
|
|
25028
25429
|
};
|
|
25029
|
-
} catch (
|
|
25030
|
-
if (writeStarted)
|
|
25031
|
-
if (
|
|
25032
|
-
|
|
25430
|
+
} catch (error4) {
|
|
25431
|
+
if (writeStarted) fail3("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
25432
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
25433
|
+
fail3(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
25033
25434
|
} finally {
|
|
25034
|
-
await
|
|
25435
|
+
await rm4(temporary, { recursive: true, force: true });
|
|
25035
25436
|
await release();
|
|
25036
25437
|
}
|
|
25037
25438
|
}
|
|
25038
25439
|
|
|
25039
25440
|
// lib/claude-installation.mjs
|
|
25040
|
-
var { info: info4, privateDirectory:
|
|
25441
|
+
var { info: info4, privateDirectory: privateDirectory6, privateRead: privateRead5, atomicJSON: atomicJSON4, acquire: acquire4, runNode: runNode2, checkInstalledRuntime: checkInstalledRuntime2, compareVersions: compareVersions3, validProfile: validProfile2 } = installationFiles;
|
|
25041
25442
|
var effectiveRoot = (plugin) => plugin.readFromFolder ?? plugin.installPath;
|
|
25042
25443
|
var ClaudeInstallationError = class extends CreationClientError {
|
|
25043
25444
|
constructor(code, details) {
|
|
@@ -25045,8 +25446,8 @@ var ClaudeInstallationError = class extends CreationClientError {
|
|
|
25045
25446
|
this.details = details;
|
|
25046
25447
|
}
|
|
25047
25448
|
};
|
|
25048
|
-
var claudeInstallationDetails = (
|
|
25049
|
-
var
|
|
25449
|
+
var claudeInstallationDetails = (error4) => error4 instanceof ClaudeInstallationError ? error4.details : void 0;
|
|
25450
|
+
var fail4 = (code, details) => {
|
|
25050
25451
|
throw new ClaudeInstallationError(code, details);
|
|
25051
25452
|
};
|
|
25052
25453
|
async function jsonCommand(run, args2) {
|
|
@@ -25056,9 +25457,9 @@ async function jsonCommand(run, args2) {
|
|
|
25056
25457
|
if (typeof body !== "string" || Buffer.byteLength(body) > 2 * 1024 * 1024) throw Error();
|
|
25057
25458
|
value2 = JSON.parse(body);
|
|
25058
25459
|
} catch {
|
|
25059
|
-
|
|
25460
|
+
fail4("claude_local_registration_unconfirmed");
|
|
25060
25461
|
}
|
|
25061
|
-
if (!Array.isArray(value2) || value2.length > 1024)
|
|
25462
|
+
if (!Array.isArray(value2) || value2.length > 1024) fail4("claude_local_registration_unconfirmed");
|
|
25062
25463
|
return value2;
|
|
25063
25464
|
}
|
|
25064
25465
|
async function registrations(run, pluginName, marketplace, root) {
|
|
@@ -25067,17 +25468,17 @@ async function registrations(run, pluginName, marketplace, root) {
|
|
|
25067
25468
|
jsonCommand(run, ["plugin", "marketplace", "list", "--json"])
|
|
25068
25469
|
]);
|
|
25069
25470
|
if (plugins.some((p2) => !p2 || typeof p2.id !== "string" || !p2.id || p2.id.length > 256 || typeof p2.scope !== "string" || typeof p2.version !== "string" || typeof p2.enabled !== "boolean" || typeof p2.installPath !== "string") || markets.some((p2) => !p2 || typeof p2.name !== "string" || !p2.name || typeof p2.source !== "string"))
|
|
25070
|
-
|
|
25471
|
+
fail4("claude_local_registration_unconfirmed");
|
|
25071
25472
|
const related = plugins.filter((p2) => typeof p2?.id === "string" && p2.id.startsWith(pluginName + "@"));
|
|
25072
|
-
if (related.length > 1 || related.some((p2) => p2.id !== pluginName + "@" + marketplace || p2.scope !== "user" || typeof p2.enabled !== "boolean" || !/^\d+\.\d+\.\d+$/.test(p2.version ?? "") || !
|
|
25073
|
-
|
|
25473
|
+
if (related.length > 1 || related.some((p2) => p2.id !== pluginName + "@" + marketplace || p2.scope !== "user" || typeof p2.enabled !== "boolean" || !/^\d+\.\d+\.\d+$/.test(p2.version ?? "") || !path12.isAbsolute(p2.installPath ?? "") || p2.readFromFolder !== void 0 && (!path12.isAbsolute(p2.readFromFolder) || p2.folderVersion !== p2.version)))
|
|
25474
|
+
fail4("claude_existing_registration_requires_review");
|
|
25074
25475
|
const found = markets.filter((p2) => p2?.name === marketplace);
|
|
25075
25476
|
if (found.length > 1 || found.some((p2) => p2.source !== "directory" || p2.path !== root || p2.installLocation !== root))
|
|
25076
|
-
|
|
25477
|
+
fail4("claude_existing_registration_requires_review");
|
|
25077
25478
|
return { plugin: related[0], market: found[0] };
|
|
25078
25479
|
}
|
|
25079
25480
|
async function legacyUserMcp(env, serverName) {
|
|
25080
|
-
if (await readClaudeUserServer(serverName, env))
|
|
25481
|
+
if (await readClaudeUserServer(serverName, env)) fail4("legacy_mcp_entry_requires_review");
|
|
25081
25482
|
}
|
|
25082
25483
|
function transport(serverName, configFile2, command2 = process.execPath) {
|
|
25083
25484
|
return { mcpServers: { [serverName]: {
|
|
@@ -25088,30 +25489,32 @@ function transport(serverName, configFile2, command2 = process.execPath) {
|
|
|
25088
25489
|
async function verifyVersion2(root, { version: version3, profile, configFile: configFile2, payloadDigest, pluginName, serverName }) {
|
|
25089
25490
|
const directory = await info4(root);
|
|
25090
25491
|
if (!directory?.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63)
|
|
25091
|
-
|
|
25092
|
-
const ready = await
|
|
25093
|
-
if (!ready || ready.host !== "claude-code" || ready.version !== version3 || ready.profile !== profile || ready.configFile !== configFile2 || ready.payloadDigest !== payloadDigest || !Array.isArray(ready.files) || ready.files.length > 1024)
|
|
25492
|
+
fail4("claude_installed_files_invalid");
|
|
25493
|
+
const ready = await privateRead5(path12.join(root, "installation.json"));
|
|
25494
|
+
if (!ready || ready.host !== "claude-code" || ready.version !== version3 || ready.profile !== profile || ready.configFile !== configFile2 || ready.payloadDigest !== payloadDigest || !Array.isArray(ready.files) || ready.files.length > 1024) fail4("claude_installed_files_invalid");
|
|
25094
25495
|
const actual = await inspectRuntimePackage(root);
|
|
25095
|
-
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path:
|
|
25096
|
-
|
|
25097
|
-
const manifest = JSON.parse(await
|
|
25496
|
+
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))) !== JSON.stringify(ready.files))
|
|
25497
|
+
fail4("claude_installed_files_invalid");
|
|
25498
|
+
const manifest = JSON.parse(await readFile8(path12.join(root, ".claude-plugin/plugin.json"), "utf8"));
|
|
25098
25499
|
if (manifest.name !== pluginName || manifest.version !== version3 || manifest.skills !== "./skills/" || manifest.mcpServers !== "./.claude-mcp.json")
|
|
25099
|
-
|
|
25500
|
+
fail4("claude_installed_files_invalid");
|
|
25100
25501
|
let runtimeCommand;
|
|
25101
25502
|
for (const file of [".mcp.json", ".claude-mcp.json"]) {
|
|
25102
|
-
const mcp = JSON.parse(await
|
|
25503
|
+
const mcp = JSON.parse(await readFile8(path12.join(root, file), "utf8"));
|
|
25103
25504
|
const command2 = mcp.mcpServers?.[serverName]?.command;
|
|
25104
|
-
if (!
|
|
25505
|
+
if (!path12.isAbsolute(command2 ?? "") || runtimeCommand !== void 0 && command2 !== runtimeCommand || JSON.stringify(mcp) !== JSON.stringify(transport(serverName, configFile2, command2))) fail4("claude_installed_files_invalid");
|
|
25105
25506
|
runtimeCommand = command2;
|
|
25106
25507
|
}
|
|
25508
|
+
if (compareVersions3(version3, "0.3.1") >= 0 && JSON.stringify(manifest.hooks) !== JSON.stringify(claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand: runtimeCommand })))
|
|
25509
|
+
fail4("claude_installed_files_invalid");
|
|
25107
25510
|
return { ...ready, runtimeCommand };
|
|
25108
25511
|
}
|
|
25109
25512
|
async function installForClaudeUser(options = {}) {
|
|
25110
25513
|
const profile = options.profile ?? "default", env = options.env ?? process.env;
|
|
25111
25514
|
validProfile2(profile);
|
|
25112
|
-
const modeRoot =
|
|
25113
|
-
await
|
|
25114
|
-
const release = await
|
|
25515
|
+
const modeRoot = path12.resolve(env.XDG_DATA_HOME ?? path12.join(homedir9(), ".local/share"), "promptframe-creation", profile, "claude-code-mode");
|
|
25516
|
+
await privateDirectory6(modeRoot);
|
|
25517
|
+
const release = await acquire4(modeRoot, options.signal);
|
|
25115
25518
|
try {
|
|
25116
25519
|
return await installClaudeUserLocked(options);
|
|
25117
25520
|
} finally {
|
|
@@ -25131,37 +25534,37 @@ async function installClaudeUserLocked({
|
|
|
25131
25534
|
nodeCommand = process.execPath
|
|
25132
25535
|
} = {}) {
|
|
25133
25536
|
validProfile2(profile);
|
|
25134
|
-
if (!
|
|
25537
|
+
if (!path12.isAbsolute(nodeCommand)) fail4("runtime_command_invalid");
|
|
25135
25538
|
const hostVersion = (await runClaude(["--version"])).trim().match(/^(\d+\.\d+\.\d+) \(Claude Code\)$/);
|
|
25136
|
-
if (!hostVersion || compareVersions3(hostVersion[1], "2.
|
|
25539
|
+
if (!hostVersion || compareVersions3(hostVersion[1], "2.1.295") < 0) fail4("claude_21295_required");
|
|
25137
25540
|
const help = await runClaude(["--help"]);
|
|
25138
|
-
if (typeof help !== "string" || Buffer.byteLength(help) > 128 * 1024)
|
|
25541
|
+
if (typeof help !== "string" || Buffer.byteLength(help) > 128 * 1024) fail4("claude_capabilities_unconfirmed");
|
|
25139
25542
|
const hasPlugin = /^\s+plugin(?:\|plugins)?\s/m.test(help), hasMcp = /^\s+mcp\s/m.test(help);
|
|
25140
|
-
const base =
|
|
25141
|
-
const pluginPending = await info4(
|
|
25142
|
-
if ((!hasPlugin || fallbackState) && (pluginPending || pluginCurrent))
|
|
25543
|
+
const base = path12.resolve(env.XDG_DATA_HOME ?? path12.join(homedir9(), ".local/share"), "promptframe-creation", profile), fallbackRoot = path12.join(base, "claude-code-mcp"), pluginRoot = path12.join(base, "claude-code");
|
|
25544
|
+
const pluginPending = await info4(path12.join(pluginRoot, "registration-pending.json")), pluginCurrent = await info4(path12.join(pluginRoot, "current.json")), fallbackState = await info4(path12.join(fallbackRoot, "current.json")) || await info4(path12.join(fallbackRoot, "registration-pending.json"));
|
|
25545
|
+
if ((!hasPlugin || fallbackState) && (pluginPending || pluginCurrent)) fail4("registration_unconfirmed_keep_existing");
|
|
25143
25546
|
if (!hasPlugin || fallbackState) {
|
|
25144
|
-
if (!hasMcp)
|
|
25547
|
+
if (!hasMcp) fail4("claude_capabilities_unconfirmed");
|
|
25145
25548
|
return installClaudeMcpFallback({ sourceRoot, profile, env, configFile: configFile2, signal, runClaude, checkRuntime, verifyInstalledRuntime, nodeCommand });
|
|
25146
25549
|
}
|
|
25147
|
-
const payload = await inspectRuntimePackage(
|
|
25550
|
+
const payload = await inspectRuntimePackage(path12.resolve(sourceRoot));
|
|
25148
25551
|
if (!payload.files.some((f2) => f2.path === ".claude-plugin/plugin.json") || !payload.files.some((f2) => f2.path === ".claude-mcp.json"))
|
|
25149
|
-
|
|
25150
|
-
const root =
|
|
25151
|
-
await
|
|
25152
|
-
const release = await
|
|
25552
|
+
fail4("claude_package_incomplete");
|
|
25553
|
+
const root = path12.resolve(env.XDG_DATA_HOME ?? path12.join(homedir9(), ".local/share"), "promptframe-creation", profile, "claude-code");
|
|
25554
|
+
await privateDirectory6(root);
|
|
25555
|
+
const release = await acquire4(root, signal);
|
|
25153
25556
|
const suffix = profile === "default" ? "" : "-" + profile, pluginName = "promptframe-creation" + suffix, marketplace = "promptframe-creation-user" + suffix, pluginId = pluginName + "@" + marketplace, serverName = "promptframe" + suffix;
|
|
25154
|
-
const versions =
|
|
25557
|
+
const versions = path12.join(root, "versions"), currentFile = path12.join(root, "current.json"), pendingFile = path12.join(root, "registration-pending.json"), catalogFile = path12.join(root, ".claude-plugin/marketplace.json"), versionRoot = path12.join(versions, payload.version), temporary = path12.join(versions, ".partial-" + randomBytes6(12).toString("hex"));
|
|
25155
25558
|
let registrationStarted = false, newFiles = 0;
|
|
25156
25559
|
try {
|
|
25157
25560
|
signal?.throwIfAborted();
|
|
25158
|
-
await
|
|
25159
|
-
await
|
|
25561
|
+
await privateDirectory6(versions);
|
|
25562
|
+
await privateDirectory6(path12.dirname(catalogFile));
|
|
25160
25563
|
await legacyUserMcp(env, serverName);
|
|
25161
|
-
let previous = await
|
|
25564
|
+
let previous = await privateRead5(currentFile), pending = await privateRead5(pendingFile), state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25162
25565
|
const binding = { profile, configFile: configFile2, pluginId, pluginName, serverName, host: "claude-code" };
|
|
25163
25566
|
const checkBinding = (record2) => {
|
|
25164
|
-
if (record2 && (record2.profile !== profile || record2.configFile !== configFile2 || record2.pluginId !== pluginId || record2.host !== "claude-code" || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !==
|
|
25567
|
+
if (record2 && (record2.profile !== profile || record2.configFile !== configFile2 || record2.pluginId !== pluginId || record2.host !== "claude-code" || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !== path12.join(versions, record2.version))) fail4("profile_binding_conflict");
|
|
25165
25568
|
};
|
|
25166
25569
|
checkBinding(previous);
|
|
25167
25570
|
checkBinding(pending);
|
|
@@ -25174,15 +25577,15 @@ async function installClaudeUserLocked({
|
|
|
25174
25577
|
};
|
|
25175
25578
|
if (pending) {
|
|
25176
25579
|
if (await observed(pending)) {
|
|
25177
|
-
await
|
|
25178
|
-
await
|
|
25580
|
+
await atomicJSON4(currentFile, pending);
|
|
25581
|
+
await rm5(pendingFile);
|
|
25179
25582
|
previous = pending;
|
|
25180
25583
|
pending = null;
|
|
25181
25584
|
} else if (pending.phase !== "marketplace" || !state.market || state.plugin)
|
|
25182
|
-
|
|
25585
|
+
fail4("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
25183
25586
|
}
|
|
25184
|
-
if (state.plugin && !previous && !pending)
|
|
25185
|
-
if (previous && !await observed(previous) && !pending)
|
|
25587
|
+
if (state.plugin && !previous && !pending) fail4("claude_existing_registration_requires_review");
|
|
25588
|
+
if (previous && !await observed(previous) && !pending) fail4("claude_local_registration_unconfirmed");
|
|
25186
25589
|
if (previous && compareVersions3(previous.version, payload.version) > 0) {
|
|
25187
25590
|
const recorded = runtimeCommands.get(previous.versionRoot);
|
|
25188
25591
|
await verifyInstalledRuntime(previous.versionRoot, previous.version, recorded, { env });
|
|
@@ -25200,17 +25603,17 @@ async function installClaudeUserLocked({
|
|
|
25200
25603
|
}
|
|
25201
25604
|
const complete = { ...binding, version: payload.version, versionRoot, payloadDigest: payload.payloadDigest };
|
|
25202
25605
|
if (pending && (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest))
|
|
25203
|
-
|
|
25606
|
+
fail4("registration_unconfirmed_keep_existing");
|
|
25204
25607
|
if (await info4(versionRoot)) {
|
|
25205
25608
|
const ready = await verifyVersion2(versionRoot, { ...complete, pluginName, serverName });
|
|
25206
25609
|
runtimeCommands.set(versionRoot, ready.runtimeCommand);
|
|
25207
25610
|
} else {
|
|
25208
|
-
await
|
|
25611
|
+
await mkdir6(temporary, { mode: 448 });
|
|
25209
25612
|
for (const file of payload.files) {
|
|
25210
25613
|
signal?.throwIfAborted();
|
|
25211
|
-
const dest =
|
|
25212
|
-
await
|
|
25213
|
-
const fd = await
|
|
25614
|
+
const dest = path12.join(temporary, file.path);
|
|
25615
|
+
await mkdir6(path12.dirname(dest), { recursive: true, mode: 448 });
|
|
25616
|
+
const fd = await open7(dest, "wx", 384);
|
|
25214
25617
|
try {
|
|
25215
25618
|
await fd.writeFile(file.body);
|
|
25216
25619
|
await fd.sync();
|
|
@@ -25218,41 +25621,42 @@ async function installClaudeUserLocked({
|
|
|
25218
25621
|
await fd.close();
|
|
25219
25622
|
}
|
|
25220
25623
|
}
|
|
25221
|
-
const manifest = JSON.parse(await
|
|
25624
|
+
const manifest = JSON.parse(await readFile8(path12.join(temporary, ".claude-plugin/plugin.json"), "utf8"));
|
|
25222
25625
|
manifest.name = pluginName;
|
|
25223
|
-
|
|
25224
|
-
|
|
25626
|
+
if (manifest.hooks) manifest.hooks = claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand });
|
|
25627
|
+
await atomicJSON4(path12.join(temporary, ".claude-plugin/plugin.json"), manifest);
|
|
25628
|
+
for (const file of [".mcp.json", ".claude-mcp.json"]) await atomicJSON4(path12.join(temporary, file), transport(serverName, configFile2, nodeCommand));
|
|
25225
25629
|
await checkRuntime(temporary, payload.version);
|
|
25226
25630
|
const installed = await inspectRuntimePackage(temporary);
|
|
25227
|
-
await
|
|
25631
|
+
await atomicJSON4(path12.join(temporary, "installation.json"), {
|
|
25228
25632
|
...binding,
|
|
25229
25633
|
version: payload.version,
|
|
25230
25634
|
payloadDigest: payload.payloadDigest,
|
|
25231
|
-
files: installed.files.map(({ path:
|
|
25635
|
+
files: installed.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))
|
|
25232
25636
|
});
|
|
25233
25637
|
signal?.throwIfAborted();
|
|
25234
|
-
await
|
|
25638
|
+
await rename6(temporary, versionRoot);
|
|
25235
25639
|
newFiles = payload.files.length;
|
|
25236
25640
|
}
|
|
25237
25641
|
if (newFiles === 0) await verifyInstalledRuntime(versionRoot, payload.version, runtimeCommands.get(versionRoot), { env });
|
|
25238
25642
|
const already = previous?.version === payload.version && previous.payloadDigest === payload.payloadDigest && await observed(complete);
|
|
25239
25643
|
if (!already) {
|
|
25240
|
-
await
|
|
25644
|
+
await atomicJSON4(catalogFile, { name: marketplace, owner: { name: "PromptFrame" }, plugins: [{ name: pluginName, source: "./versions/" + payload.version }] });
|
|
25241
25645
|
if (!state.market) {
|
|
25242
|
-
if (pending)
|
|
25243
|
-
await
|
|
25646
|
+
if (pending) fail4("registration_unconfirmed_keep_existing");
|
|
25647
|
+
await atomicJSON4(pendingFile, { ...complete, phase: "marketplace" });
|
|
25244
25648
|
registrationStarted = true;
|
|
25245
25649
|
await runClaude(["plugin", "marketplace", "add", root, "--scope", "user", "--json"]);
|
|
25246
25650
|
state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25247
|
-
if (!state.market)
|
|
25651
|
+
if (!state.market) fail4("claude_registration_unconfirmed");
|
|
25248
25652
|
}
|
|
25249
|
-
await
|
|
25653
|
+
await atomicJSON4(pendingFile, { ...complete, phase: "plugin" });
|
|
25250
25654
|
registrationStarted = true;
|
|
25251
25655
|
await runClaude(["plugin", "install", pluginId, "--scope", "user", "--json"]);
|
|
25252
25656
|
state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25253
|
-
if (!await observed(complete))
|
|
25254
|
-
await
|
|
25255
|
-
await
|
|
25657
|
+
if (!await observed(complete)) fail4("claude_registration_unconfirmed");
|
|
25658
|
+
await atomicJSON4(currentFile, complete);
|
|
25659
|
+
await rm5(pendingFile);
|
|
25256
25660
|
}
|
|
25257
25661
|
return {
|
|
25258
25662
|
...complete,
|
|
@@ -25266,24 +25670,24 @@ async function installClaudeUserLocked({
|
|
|
25266
25670
|
requestedVersion: payload.version,
|
|
25267
25671
|
recordedRuntimeRetained: runtimeCommands.has(versionRoot) && runtimeCommands.get(versionRoot) !== nodeCommand
|
|
25268
25672
|
};
|
|
25269
|
-
} catch (
|
|
25270
|
-
if (registrationStarted)
|
|
25271
|
-
...claudeErrorDetails(
|
|
25673
|
+
} catch (error4) {
|
|
25674
|
+
if (registrationStarted) fail4("registration_unconfirmed_keep_existing", {
|
|
25675
|
+
...claudeErrorDetails(error4),
|
|
25272
25676
|
phase: "registration_observation",
|
|
25273
25677
|
localRegistrationState: "unknown",
|
|
25274
25678
|
action: "inspect_same_registration_no_second_add"
|
|
25275
25679
|
});
|
|
25276
|
-
if (
|
|
25277
|
-
|
|
25680
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
25681
|
+
fail4(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
25278
25682
|
} finally {
|
|
25279
|
-
await
|
|
25683
|
+
await rm5(temporary, { recursive: true, force: true });
|
|
25280
25684
|
await release();
|
|
25281
25685
|
}
|
|
25282
25686
|
}
|
|
25283
25687
|
|
|
25284
25688
|
// lib/cli.mjs
|
|
25285
25689
|
import { fileURLToPath } from "node:url";
|
|
25286
|
-
import
|
|
25690
|
+
import path13 from "node:path";
|
|
25287
25691
|
var args = process.argv.slice(2);
|
|
25288
25692
|
var command = args.shift();
|
|
25289
25693
|
var value = (key) => {
|
|
@@ -25291,7 +25695,7 @@ var value = (key) => {
|
|
|
25291
25695
|
return i < 0 ? void 0 : args[i + 1];
|
|
25292
25696
|
};
|
|
25293
25697
|
var log = (value2) => process.stdout.write(JSON.stringify(value2) + "\n");
|
|
25294
|
-
var configFile = () => value("--config") ?
|
|
25698
|
+
var configFile = () => value("--config") ? path13.resolve(value("--config")) : profileCredentialsPath(value("--profile") ?? "default");
|
|
25295
25699
|
async function probe(credentials) {
|
|
25296
25700
|
const client = await connectPlatform(credentials, { host: resolveHostIdentity({ host: value("--host") }) });
|
|
25297
25701
|
try {
|
|
@@ -25396,7 +25800,7 @@ async function setup({ silent = false } = {}) {
|
|
|
25396
25800
|
version: 1,
|
|
25397
25801
|
endpoint,
|
|
25398
25802
|
token,
|
|
25399
|
-
clientId: existing?.clientId ??
|
|
25803
|
+
clientId: existing?.clientId ?? randomBytes7(24).toString("base64url"),
|
|
25400
25804
|
clientName: value("--name") ?? existing?.clientName ?? (resolveHostIdentity({ host: value("--host") }).kind === "claude-code" ? "Claude Code PromptFrame" : "Codex PromptFrame"),
|
|
25401
25805
|
createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
25402
25806
|
};
|
|
@@ -25431,14 +25835,14 @@ async function bridge() {
|
|
|
25431
25835
|
resolvedVersion: value("--resolved-runtime-version"),
|
|
25432
25836
|
signal: startup.signal,
|
|
25433
25837
|
hostKind: identity.kind,
|
|
25434
|
-
cacheRoot:
|
|
25838
|
+
cacheRoot: path13.join(path13.dirname(configFile()), "runtime-cache")
|
|
25435
25839
|
});
|
|
25436
25840
|
startup.signal.throwIfAborted();
|
|
25437
|
-
} catch (
|
|
25841
|
+
} catch (error4) {
|
|
25438
25842
|
await client?.close().catch(() => {
|
|
25439
25843
|
});
|
|
25440
25844
|
if (startup.signal.aborted) throw new CreationClientError("creation.runtime_selection_interrupted");
|
|
25441
|
-
throw
|
|
25845
|
+
throw error4;
|
|
25442
25846
|
} finally {
|
|
25443
25847
|
process.removeListener("SIGINT", abort);
|
|
25444
25848
|
process.removeListener("SIGTERM", abort);
|
|
@@ -25449,6 +25853,7 @@ async function bridge() {
|
|
|
25449
25853
|
process.exitCode = result.code;
|
|
25450
25854
|
return;
|
|
25451
25855
|
}
|
|
25856
|
+
const hostSession = identity.kind === "claude-code" ? await createClaudeHostSession({ configFile: configFile() }) : void 0;
|
|
25452
25857
|
const server = new Server(
|
|
25453
25858
|
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
25454
25859
|
{ capabilities: {
|
|
@@ -25463,6 +25868,7 @@ async function bridge() {
|
|
|
25463
25868
|
), host = createHostCallBridge(client, {
|
|
25464
25869
|
credentials,
|
|
25465
25870
|
host: identity,
|
|
25871
|
+
hostSession,
|
|
25466
25872
|
onCatalogChange: () => server.sendToolListChanged(),
|
|
25467
25873
|
onKnowledgeChange: (kind) => kind === "resources" ? server.sendResourceListChanged() : server.sendPromptListChanged()
|
|
25468
25874
|
});
|
|
@@ -25474,11 +25880,11 @@ async function bridge() {
|
|
|
25474
25880
|
const knowledgeHandler = (schema, method) => server.setRequestHandler(schema, async (request) => {
|
|
25475
25881
|
try {
|
|
25476
25882
|
return await host[method](request.params ?? {});
|
|
25477
|
-
} catch (
|
|
25478
|
-
const remote =
|
|
25479
|
-
const code =
|
|
25480
|
-
const knownRemote = typeof remote === "string" && code === remote && typeof
|
|
25481
|
-
throw new McpError(knownRemote ?
|
|
25883
|
+
} catch (error4) {
|
|
25884
|
+
const remote = error4?.data?.errorCode;
|
|
25885
|
+
const code = error4 instanceof CreationClientError ? error4.message : typeof remote === "string" && /^(?:creation|creative_skill)\.[a-z0-9_.:-]{1,160}$/.test(remote) ? remote : "creation.connection_unresolved";
|
|
25886
|
+
const knownRemote = typeof remote === "string" && code === remote && typeof error4.code === "number" && Object.values(ErrorCode).includes(error4.code);
|
|
25887
|
+
throw new McpError(knownRemote ? error4.code : error4 instanceof CreationClientError ? ErrorCode.InvalidParams : ErrorCode.InternalError, code, { errorCode: code });
|
|
25482
25888
|
}
|
|
25483
25889
|
});
|
|
25484
25890
|
if (upstream.resources) {
|
|
@@ -25500,7 +25906,7 @@ async function bridge() {
|
|
|
25500
25906
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
25501
25907
|
try {
|
|
25502
25908
|
return await host.call(request.params);
|
|
25503
|
-
} catch (
|
|
25909
|
+
} catch (error4) {
|
|
25504
25910
|
return {
|
|
25505
25911
|
isError: true,
|
|
25506
25912
|
content: [
|
|
@@ -25508,8 +25914,9 @@ async function bridge() {
|
|
|
25508
25914
|
type: "text",
|
|
25509
25915
|
text: JSON.stringify({
|
|
25510
25916
|
success: false,
|
|
25511
|
-
errorCode:
|
|
25512
|
-
|
|
25917
|
+
errorCode: error4 instanceof CreationClientError ? error4.message : "creation.connection_unresolved",
|
|
25918
|
+
...error4 instanceof CreationClientError && error4.message === "creation.host_session_changed" ? { effectStatus: "unknown", automaticReplayAllowed: false } : {},
|
|
25919
|
+
action: error4 instanceof CreationClientError ? error4.message === "creation.host_session_changed" ? "read_original_task_without_replaying_business" : error4.message.startsWith("creation.host_") ? "use_supported_host_with_session_identity" : error4.message === "creation.editor_not_current" ? "request_control_and_confirm_in_studio" : "read_current_platform_facts_without_replaying_business" : "read_original_task_or_retry_same_idempotency_key"
|
|
25513
25920
|
})
|
|
25514
25921
|
}
|
|
25515
25922
|
]
|
|
@@ -25578,6 +25985,7 @@ try {
|
|
|
25578
25985
|
process.removeListener("SIGTERM", abort);
|
|
25579
25986
|
}
|
|
25580
25987
|
} else if (command === "bridge") await bridge();
|
|
25988
|
+
else if (command === "claude-host-hook") await runClaudeHostHook({ configFile: configFile() });
|
|
25581
25989
|
else if (command === "--version") process.stdout.write(CLIENT_VERSION + "\n");
|
|
25582
25990
|
else if (command === "status") {
|
|
25583
25991
|
const saved = await readCredentials(configFile());
|
|
@@ -25589,19 +25997,19 @@ try {
|
|
|
25589
25997
|
});
|
|
25590
25998
|
} else if (command === "help" || command === "--help" || !command) {
|
|
25591
25999
|
process.stdout.write(
|
|
25592
|
-
"promptframe-creation connect --endpoint <platform-api-base> [--host codex|claude-code] [--profile <environment-account>] [--claude-bin <absolute-file>] [--no-open]\npromptframe-creation setup --endpoint <platform-api-base> [--host codex|claude-code] [--no-open] [--replace] [--name <client-name>]\npromptframe-creation status [--profile <environment-account>] [--host codex|claude-code]\npromptframe-creation bridge [--config <private-file>] [--host codex|claude-code] [--bridge-version <X.Y.Z>]\npromptframe-creation --version\nNode.js >=20 is required. Plugin installation supports Codex >=0.160.0 or Claude Code >=2.
|
|
26000
|
+
"promptframe-creation connect --endpoint <platform-api-base> [--host codex|claude-code] [--profile <environment-account>] [--claude-bin <absolute-file>] [--no-open]\npromptframe-creation setup --endpoint <platform-api-base> [--host codex|claude-code] [--no-open] [--replace] [--name <client-name>]\npromptframe-creation status [--profile <environment-account>] [--host codex|claude-code]\npromptframe-creation bridge [--config <private-file>] [--host codex|claude-code] [--bridge-version <X.Y.Z>]\npromptframe-creation --version\nNode.js >=20 is required. Plugin installation supports Codex >=0.160.0 or Claude Code >=2.1.295 with its structured plugin commands. Token input is masked in a terminal or accepted through --token-stdin; never use a Token command argument.\nBridge startup checks the platform minimum/recommended version. --bridge-version locks one exact compatible version for this new session; active bridges are not replaced.\n"
|
|
25593
26001
|
);
|
|
25594
26002
|
} else throw new CreationClientError("command.unknown");
|
|
25595
|
-
} catch (
|
|
26003
|
+
} catch (error4) {
|
|
25596
26004
|
process.stderr.write(
|
|
25597
26005
|
JSON.stringify({
|
|
25598
|
-
...installationErrorDetails(
|
|
25599
|
-
...claudeInstallationDetails(
|
|
25600
|
-
...claudeErrorDetails(
|
|
25601
|
-
...fallbackErrorDetails(
|
|
25602
|
-
...bridgeErrorDetails(
|
|
25603
|
-
...runtimeErrorDetails(
|
|
25604
|
-
error:
|
|
26006
|
+
...installationErrorDetails(error4),
|
|
26007
|
+
...claudeInstallationDetails(error4),
|
|
26008
|
+
...claudeErrorDetails(error4),
|
|
26009
|
+
...fallbackErrorDetails(error4),
|
|
26010
|
+
...bridgeErrorDetails(error4),
|
|
26011
|
+
...runtimeErrorDetails(error4),
|
|
26012
|
+
error: error4 instanceof CreationClientError ? error4.message : "creation.connection_failed"
|
|
25605
26013
|
}) + "\n"
|
|
25606
26014
|
);
|
|
25607
26015
|
process.exitCode = 1;
|