@promptframe/creation 0.3.0 → 0.3.2
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 +1060 -646
- package/docs/development.md +7 -3
- package/docs/install-guidance.json +3 -3
- package/docs/installing.md +4 -4
- package/docs/releases/0.3.1.md +7 -0
- package/docs/releases/0.3.2.md +5 -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 +8 -3
- package/lib/claude-mcp-installation.mjs +3 -0
- package/lib/cli.mjs +8 -3
- package/lib/host-context.mjs +50 -17
- 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.2";
|
|
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,75 @@ 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
|
-
|
|
19968
|
-
let effectiveAccess = access2;
|
|
20258
|
+
let 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
|
+
const defaults = resolved?.scopeDefaults ?? {};
|
|
20267
|
+
if (!defaults || typeof defaults !== "object" || Array.isArray(defaults) || Object.entries(defaults).some(([key2, value2]) => !["projectId", "sessionId"].includes(key2) || value2 !== params.arguments[key2] || Object.hasOwn(input, key2)))
|
|
20268
|
+
throw new CreationClientError("creation.access_unverified");
|
|
20269
|
+
const normalized = { ...input, ...defaults };
|
|
20270
|
+
if (resolved?.tool !== tool || resolved.argumentsDigest !== argumentsDigest(normalized) || !accesses.has(resolved.access)) throw new CreationClientError("creation.access_unverified");
|
|
20271
|
+
params = { ...params, arguments: { ...params.arguments, arguments: normalized } };
|
|
19976
20272
|
effectiveAccess = resolved.access;
|
|
20273
|
+
resolvedControl = observed.trusted?.control;
|
|
19977
20274
|
}
|
|
20275
|
+
hostParameters(raw, binding.host, effectiveAccess);
|
|
19978
20276
|
const key = keyFor(params);
|
|
19979
20277
|
let outgoing = params;
|
|
19980
20278
|
if (managed) {
|
|
19981
|
-
if (!key)
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
19986
|
-
entry = versions.get(key);
|
|
20279
|
+
if (!key) {
|
|
20280
|
+
if (effectiveAccess !== "independent-read" || !Number.isSafeInteger(resolvedControl?.controlVersion) || resolvedControl.controlVersion <= 0)
|
|
20281
|
+
throw new CreationClientError("creation.control_unverified");
|
|
20282
|
+
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: resolvedControl.controlVersion } };
|
|
20283
|
+
} else {
|
|
20284
|
+
let entry = versions.get(key);
|
|
20285
|
+
if (!entry || entry.needsRead) {
|
|
20286
|
+
const denied = await controlRead(params, key, binding);
|
|
20287
|
+
if (denied) return denied;
|
|
20288
|
+
entry = versions.get(key);
|
|
20289
|
+
}
|
|
20290
|
+
if (effectiveAccess !== "independent-read" && !entry.owned) throw new CreationClientError("creation.editor_not_current");
|
|
20291
|
+
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: entry.version } };
|
|
19987
20292
|
}
|
|
19988
|
-
if (effectiveAccess !== "independent-read" && !entry.owned) throw new CreationClientError("creation.editor_not_current");
|
|
19989
|
-
outgoing = { ...params, arguments: { ...params.arguments, controlVersion: entry.version } };
|
|
19990
20293
|
}
|
|
19991
20294
|
const dispatched = key && versions.get(key);
|
|
19992
20295
|
const invalidate = () => {
|
|
20296
|
+
if (host.kind === "claude-code" && binding.epoch !== hostEpoch) return;
|
|
19993
20297
|
const current = key && versions.get(key);
|
|
19994
20298
|
if (dispatched && current && current.version <= dispatched.version)
|
|
19995
20299
|
boundedSet(versions, key, { ...current, needsRead: true, invalidatedAt: ++sequence });
|
|
19996
20300
|
};
|
|
19997
20301
|
let response;
|
|
19998
20302
|
try {
|
|
19999
|
-
response = await send(outgoing);
|
|
20000
|
-
} catch (
|
|
20303
|
+
response = await send(outgoing, binding);
|
|
20304
|
+
} catch (error4) {
|
|
20001
20305
|
invalidate();
|
|
20002
|
-
throw
|
|
20306
|
+
throw error4;
|
|
20003
20307
|
}
|
|
20004
20308
|
if (response.result.isError) invalidate();
|
|
20005
20309
|
return response.result;
|
|
@@ -20008,7 +20312,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
20008
20312
|
}
|
|
20009
20313
|
|
|
20010
20314
|
// lib/runtime-bootstrap.mjs
|
|
20011
|
-
import { createHash as
|
|
20315
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "node:crypto";
|
|
20012
20316
|
import { gunzipSync } from "node:zlib";
|
|
20013
20317
|
|
|
20014
20318
|
// node_modules/tar/dist/esm/index.min.js
|
|
@@ -22981,18 +23285,18 @@ var To = (s3) => {
|
|
|
22981
23285
|
};
|
|
22982
23286
|
|
|
22983
23287
|
// lib/runtime-bootstrap.mjs
|
|
22984
|
-
import { lstat as
|
|
23288
|
+
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
23289
|
import { execFile } from "node:child_process";
|
|
22986
23290
|
import { promisify } from "node:util";
|
|
22987
|
-
import
|
|
23291
|
+
import path5 from "node:path";
|
|
22988
23292
|
|
|
22989
23293
|
// lib/runtime-package.mjs
|
|
22990
|
-
import { lstat as
|
|
22991
|
-
import { createHash as
|
|
22992
|
-
import
|
|
23294
|
+
import { lstat as lstat3, readdir, readFile as readFile3 } from "node:fs/promises";
|
|
23295
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
23296
|
+
import path4 from "node:path";
|
|
22993
23297
|
var RUNTIME_PACKAGE_ENTRIES = Object.freeze(["package.json", "README.md", "LICENSE", "bin", "dist", "lib", "skills", "docs", ".codex-plugin", ".mcp.json"]);
|
|
22994
23298
|
var OPTIONAL_HOST_ENTRIES = Object.freeze([".claude-plugin", ".claude-mcp.json"]);
|
|
22995
|
-
var
|
|
23299
|
+
var hash2 = (b2) => createHash4("sha256").update(b2).digest("hex");
|
|
22996
23300
|
var invalid = (code) => {
|
|
22997
23301
|
throw new CreationClientError("installation." + code);
|
|
22998
23302
|
};
|
|
@@ -23001,7 +23305,7 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23001
23305
|
entries = [...RUNTIME_PACKAGE_ENTRIES];
|
|
23002
23306
|
for (const name of OPTIONAL_HOST_ENTRIES) {
|
|
23003
23307
|
try {
|
|
23004
|
-
await
|
|
23308
|
+
await lstat3(path4.join(root, name));
|
|
23005
23309
|
entries.push(name);
|
|
23006
23310
|
} catch (e) {
|
|
23007
23311
|
if (e.code !== "ENOENT") throw e;
|
|
@@ -23013,22 +23317,22 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23013
23317
|
async function walk(relative) {
|
|
23014
23318
|
let s3;
|
|
23015
23319
|
try {
|
|
23016
|
-
s3 = await
|
|
23017
|
-
} catch (
|
|
23018
|
-
if (
|
|
23320
|
+
s3 = await lstat3(path4.join(root, relative));
|
|
23321
|
+
} catch (error4) {
|
|
23322
|
+
if (error4.code !== "ENOENT") throw error4;
|
|
23019
23323
|
}
|
|
23020
23324
|
if (!s3 || s3.isSymbolicLink()) invalid("package_file_invalid");
|
|
23021
23325
|
if (s3.isDirectory()) {
|
|
23022
|
-
for (const name of (await readdir(
|
|
23326
|
+
for (const name of (await readdir(path4.join(root, relative))).sort()) {
|
|
23023
23327
|
if (name === "node_modules" || name === "credentials.json" || name.startsWith(".env")) invalid("package_file_invalid");
|
|
23024
|
-
await walk(
|
|
23328
|
+
await walk(path4.join(relative, name));
|
|
23025
23329
|
}
|
|
23026
23330
|
} else if (s3.isFile()) {
|
|
23027
23331
|
if (s3.size > 32 * 1024 * 1024) invalid("package_too_large");
|
|
23028
|
-
const body = await
|
|
23332
|
+
const body = await readFile3(path4.join(root, relative));
|
|
23029
23333
|
bytes2 += body.length;
|
|
23030
23334
|
if (files.length >= 1024 || bytes2 > 32 * 1024 * 1024) invalid("package_too_large");
|
|
23031
|
-
files.push({ path: relative, bytes: body.length, sha256:
|
|
23335
|
+
files.push({ path: relative, bytes: body.length, sha256: hash2(body), body });
|
|
23032
23336
|
} else invalid("package_file_invalid");
|
|
23033
23337
|
}
|
|
23034
23338
|
for (const name of entries) await walk(name);
|
|
@@ -23042,7 +23346,7 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
23042
23346
|
files,
|
|
23043
23347
|
version: pkg.version,
|
|
23044
23348
|
hosts: claude ? ["codex", "claude-code"] : ["codex"],
|
|
23045
|
-
payloadDigest:
|
|
23349
|
+
payloadDigest: hash2(JSON.stringify(files.map(({ path: path14, bytes: bytes3, sha256 }) => ({ path: path14, bytes: bytes3, sha256 }))))
|
|
23046
23350
|
};
|
|
23047
23351
|
}
|
|
23048
23352
|
|
|
@@ -23052,9 +23356,9 @@ var REGISTRY = "https://registry.npmjs.org";
|
|
|
23052
23356
|
var MAX_ARCHIVE = 8 * 1024 * 1024;
|
|
23053
23357
|
var MAX_PAYLOAD = 32 * 1024 * 1024;
|
|
23054
23358
|
var MAX_TAR = 36 * 1024 * 1024;
|
|
23055
|
-
var
|
|
23359
|
+
var hash3 = (b2) => createHash5("sha256").update(b2).digest("hex");
|
|
23056
23360
|
var execute = promisify(execFile);
|
|
23057
|
-
var
|
|
23361
|
+
var error3 = (code) => new CreationClientError("creation." + code);
|
|
23058
23362
|
var version2 = (v2) => {
|
|
23059
23363
|
compareBridgeVersions(v2, v2);
|
|
23060
23364
|
return v2;
|
|
@@ -23072,34 +23376,34 @@ var RuntimeSelectionError = class extends CreationClientError {
|
|
|
23072
23376
|
});
|
|
23073
23377
|
}
|
|
23074
23378
|
};
|
|
23075
|
-
var runtimeErrorDetails = (
|
|
23379
|
+
var runtimeErrorDetails = (error4) => error4 instanceof RuntimeSelectionError ? error4.runtimeFacts : void 0;
|
|
23076
23380
|
var snapshot = (payload) => ({
|
|
23077
23381
|
version: payload.version,
|
|
23078
23382
|
hosts: payload.hosts,
|
|
23079
23383
|
payloadDigest: payload.payloadDigest,
|
|
23080
|
-
files: payload.files.map(({ path:
|
|
23384
|
+
files: payload.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))
|
|
23081
23385
|
});
|
|
23082
23386
|
async function info(file) {
|
|
23083
23387
|
try {
|
|
23084
|
-
return await
|
|
23388
|
+
return await lstat4(file);
|
|
23085
23389
|
} catch (e) {
|
|
23086
23390
|
if (e.code === "ENOENT") return null;
|
|
23087
23391
|
throw e;
|
|
23088
23392
|
}
|
|
23089
23393
|
}
|
|
23090
|
-
async function
|
|
23091
|
-
await
|
|
23092
|
-
const s3 = await
|
|
23093
|
-
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw
|
|
23394
|
+
async function privateDirectory2(dir) {
|
|
23395
|
+
await mkdir3(dir, { recursive: true, mode: 448 });
|
|
23396
|
+
const s3 = await lstat4(dir);
|
|
23397
|
+
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw error3("runtime_cache_owner_invalid");
|
|
23094
23398
|
}
|
|
23095
23399
|
async function privateJSON(file) {
|
|
23096
23400
|
const s3 = await info(file);
|
|
23097
23401
|
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
|
|
23402
|
+
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) throw error3("runtime_cache_invalid");
|
|
23403
|
+
return JSON.parse(await readFile4(file, "utf8"));
|
|
23100
23404
|
}
|
|
23101
23405
|
async function syncDirectory(dir) {
|
|
23102
|
-
const fd = await
|
|
23406
|
+
const fd = await open3(dir, "r");
|
|
23103
23407
|
try {
|
|
23104
23408
|
await fd.sync();
|
|
23105
23409
|
} finally {
|
|
@@ -23107,7 +23411,7 @@ async function syncDirectory(dir) {
|
|
|
23107
23411
|
}
|
|
23108
23412
|
}
|
|
23109
23413
|
async function exclusiveJSON(file, value2) {
|
|
23110
|
-
const fd = await
|
|
23414
|
+
const fd = await open3(file, "wx", 384);
|
|
23111
23415
|
try {
|
|
23112
23416
|
await fd.writeFile(JSON.stringify(value2) + "\n");
|
|
23113
23417
|
await fd.sync();
|
|
@@ -23119,9 +23423,9 @@ function checkedRuntimeMetadata(value2, expectedVersion) {
|
|
|
23119
23423
|
version2(expectedVersion);
|
|
23120
23424
|
const tarball = REGISTRY + "/@promptframe/creation/-/creation-" + expectedVersion + ".tgz";
|
|
23121
23425
|
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
|
|
23426
|
+
throw error3("runtime_registry_identity_invalid");
|
|
23123
23427
|
const encoded = value2.dist.integrity.slice(7);
|
|
23124
|
-
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw
|
|
23428
|
+
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw error3("runtime_registry_identity_invalid");
|
|
23125
23429
|
return { version: expectedVersion, integrity: value2.dist.integrity, tarball };
|
|
23126
23430
|
}
|
|
23127
23431
|
async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs }) {
|
|
@@ -23131,12 +23435,12 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs
|
|
|
23131
23435
|
let response;
|
|
23132
23436
|
try {
|
|
23133
23437
|
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
|
|
23438
|
+
if (response.status !== 200 || Number(response.headers.get("content-length") ?? 0) > maxBytes || !response.body) throw error3("runtime_fetch_unavailable");
|
|
23135
23439
|
const chunks = [];
|
|
23136
23440
|
let count = 0;
|
|
23137
23441
|
for await (const chunk of response.body) {
|
|
23138
23442
|
count += chunk.length;
|
|
23139
|
-
if (count > maxBytes) throw
|
|
23443
|
+
if (count > maxBytes) throw error3("runtime_download_capacity");
|
|
23140
23444
|
chunks.push(Buffer.from(chunk));
|
|
23141
23445
|
}
|
|
23142
23446
|
return Buffer.concat(chunks, count);
|
|
@@ -23144,68 +23448,68 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes, timeoutMs
|
|
|
23144
23448
|
await response?.body?.cancel().catch(() => {
|
|
23145
23449
|
});
|
|
23146
23450
|
if (e instanceof CreationClientError) throw e;
|
|
23147
|
-
throw
|
|
23451
|
+
throw error3("runtime_fetch_unavailable");
|
|
23148
23452
|
} finally {
|
|
23149
23453
|
clearTimeout(timer);
|
|
23150
23454
|
signal?.removeEventListener("abort", abort);
|
|
23151
23455
|
}
|
|
23152
23456
|
}
|
|
23153
23457
|
async function readRuntimeArchive(archive, metadata) {
|
|
23154
|
-
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" +
|
|
23458
|
+
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" + createHash5("sha512").update(archive).digest("base64") !== metadata.integrity) throw error3("runtime_integrity_invalid");
|
|
23155
23459
|
let raw;
|
|
23156
23460
|
try {
|
|
23157
23461
|
raw = gunzipSync(archive, { maxOutputLength: MAX_TAR });
|
|
23158
23462
|
} catch {
|
|
23159
|
-
throw
|
|
23463
|
+
throw error3("runtime_archive_invalid");
|
|
23160
23464
|
}
|
|
23161
23465
|
const files = [], names = /* @__PURE__ */ new Set();
|
|
23162
23466
|
let total = 0, entries = 0, failure2;
|
|
23163
23467
|
const parser = Ct({ strict: true, onReadEntry: (entry) => {
|
|
23164
23468
|
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 =
|
|
23469
|
+
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
23470
|
const relative = name.slice(8).replace(/\/$/, "");
|
|
23167
23471
|
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 =
|
|
23472
|
+
failure2 = error3("runtime_archive_invalid");
|
|
23169
23473
|
const portableName = relative.toLowerCase();
|
|
23170
|
-
if (names.has(portableName)) failure2 =
|
|
23474
|
+
if (names.has(portableName)) failure2 = error3("runtime_archive_invalid");
|
|
23171
23475
|
names.add(portableName);
|
|
23172
23476
|
if (entry.type === "Directory") {
|
|
23173
|
-
if (entry.size !== 0) failure2 =
|
|
23477
|
+
if (entry.size !== 0) failure2 = error3("runtime_archive_invalid");
|
|
23174
23478
|
return;
|
|
23175
23479
|
}
|
|
23176
23480
|
total += entry.size;
|
|
23177
|
-
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative) failure2 =
|
|
23481
|
+
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative) failure2 = error3("runtime_archive_capacity");
|
|
23178
23482
|
const chunks = [];
|
|
23179
23483
|
let bytes2 = 0;
|
|
23180
23484
|
entry.on("data", (chunk) => {
|
|
23181
23485
|
bytes2 += chunk.length;
|
|
23182
|
-
if (bytes2 > entry.size) failure2 =
|
|
23486
|
+
if (bytes2 > entry.size) failure2 = error3("runtime_archive_invalid");
|
|
23183
23487
|
if (!failure2) chunks.push(Buffer.from(chunk));
|
|
23184
23488
|
});
|
|
23185
23489
|
entry.on("end", () => {
|
|
23186
|
-
if (bytes2 !== entry.size) failure2 =
|
|
23490
|
+
if (bytes2 !== entry.size) failure2 = error3("runtime_archive_invalid");
|
|
23187
23491
|
if (!failure2) files.push({ path: relative, body: Buffer.concat(chunks, bytes2) });
|
|
23188
23492
|
});
|
|
23189
23493
|
} });
|
|
23190
23494
|
await new Promise((resolve, reject) => {
|
|
23191
|
-
parser.once("error", () => reject(
|
|
23495
|
+
parser.once("error", () => reject(error3("runtime_archive_invalid")));
|
|
23192
23496
|
parser.once("end", resolve);
|
|
23193
23497
|
parser.end(raw);
|
|
23194
23498
|
});
|
|
23195
23499
|
if (failure2) throw failure2;
|
|
23196
|
-
if (!files.length || files.length > 1024) throw
|
|
23500
|
+
if (!files.length || files.length > 1024) throw error3("runtime_archive_invalid");
|
|
23197
23501
|
return files;
|
|
23198
23502
|
}
|
|
23199
23503
|
async function cacheLock(root, signal) {
|
|
23200
|
-
const name =
|
|
23504
|
+
const name = path5.join(root, "prepare.lock"), end = Date.now() + 5e3;
|
|
23201
23505
|
let fd;
|
|
23202
23506
|
while (!fd) {
|
|
23203
23507
|
signal?.throwIfAborted();
|
|
23204
23508
|
try {
|
|
23205
|
-
fd = await
|
|
23509
|
+
fd = await open3(name, "wx", 384);
|
|
23206
23510
|
} catch (e) {
|
|
23207
23511
|
if (e.code !== "EEXIST") throw e;
|
|
23208
|
-
if (Date.now() >= end) throw
|
|
23512
|
+
if (Date.now() >= end) throw error3("runtime_cache_busy");
|
|
23209
23513
|
await pause(50);
|
|
23210
23514
|
}
|
|
23211
23515
|
}
|
|
@@ -23223,51 +23527,51 @@ async function cacheLock(root, signal) {
|
|
|
23223
23527
|
return async () => {
|
|
23224
23528
|
const now = await info(name);
|
|
23225
23529
|
await fd.close();
|
|
23226
|
-
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw
|
|
23530
|
+
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw error3("runtime_lock_changed");
|
|
23227
23531
|
await rm(name);
|
|
23228
23532
|
};
|
|
23229
23533
|
}
|
|
23230
23534
|
async function verifyCached(target, metadata, hostKind) {
|
|
23231
23535
|
if (!await info(target)) return null;
|
|
23232
|
-
await
|
|
23233
|
-
const manifest = await privateJSON(
|
|
23536
|
+
await privateDirectory2(target);
|
|
23537
|
+
const manifest = await privateJSON(path5.join(target, "runtime.json"));
|
|
23234
23538
|
if (!manifest || manifest.contractVersion !== "creation-verified-runtime/v1" || manifest.version !== metadata.version || manifest.integrity !== metadata.integrity)
|
|
23235
|
-
throw
|
|
23539
|
+
throw error3("runtime_cache_invalid");
|
|
23236
23540
|
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
|
|
23541
|
+
if (names.some((name) => !roots.has(name)) || RUNTIME_PACKAGE_ENTRIES.some((name) => !names.includes(name))) throw error3("runtime_cache_invalid");
|
|
23238
23542
|
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
|
|
23543
|
+
if (!payload.hosts.includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23544
|
+
if (JSON.stringify(snapshot(payload)) !== JSON.stringify(manifest.payload)) throw error3("runtime_cache_invalid");
|
|
23241
23545
|
return { version: payload.version, root: target, integrity: metadata.integrity, reused: true };
|
|
23242
23546
|
}
|
|
23243
23547
|
async function checkedVersionIndex(cacheRoot, metadata) {
|
|
23244
|
-
const old = await privateJSON(
|
|
23245
|
-
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw
|
|
23548
|
+
const old = await privateJSON(path5.join(cacheRoot, "version-" + metadata.version + ".json"));
|
|
23549
|
+
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw error3("runtime_registry_identity_conflict");
|
|
23246
23550
|
return old;
|
|
23247
23551
|
}
|
|
23248
23552
|
async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
23249
|
-
if (!["codex", "claude-code"].includes(hostKind)) throw
|
|
23250
|
-
if (!
|
|
23553
|
+
if (!["codex", "claude-code"].includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23554
|
+
if (!path5.isAbsolute(cacheRoot ?? "")) throw error3("runtime_cache_owner_invalid");
|
|
23251
23555
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: metadata.version, dist: metadata }, metadata.version);
|
|
23252
|
-
await
|
|
23556
|
+
await privateDirectory2(cacheRoot);
|
|
23253
23557
|
await checkedVersionIndex(cacheRoot, metadata);
|
|
23254
|
-
const target =
|
|
23558
|
+
const target = path5.join(cacheRoot, metadata.version + "-" + hash3(metadata.integrity)), existing = await verifyCached(target, metadata, hostKind);
|
|
23255
23559
|
if (existing) return existing;
|
|
23256
23560
|
const archive = await boundedGet(metadata.tarball, { fetchImpl, signal, maxBytes: MAX_ARCHIVE, timeoutMs: 15e3 });
|
|
23257
23561
|
const files = await readRuntimeArchive(archive, metadata), release = await cacheLock(cacheRoot, signal);
|
|
23258
|
-
const temporary =
|
|
23562
|
+
const temporary = path5.join(cacheRoot, ".partial-" + randomBytes3(12).toString("hex"));
|
|
23259
23563
|
try {
|
|
23260
23564
|
const index = await checkedVersionIndex(cacheRoot, metadata);
|
|
23261
23565
|
const found = await verifyCached(target, metadata, hostKind);
|
|
23262
23566
|
if (found) return found;
|
|
23263
23567
|
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
|
|
23568
|
+
if (space.bavail * space.bsize < needed) throw error3("runtime_cache_capacity");
|
|
23569
|
+
await mkdir3(temporary, { mode: 448 });
|
|
23266
23570
|
for (const file of files) {
|
|
23267
23571
|
signal?.throwIfAborted();
|
|
23268
|
-
const dest =
|
|
23269
|
-
await
|
|
23270
|
-
const fd = await
|
|
23572
|
+
const dest = path5.join(temporary, ...file.path.split("/"));
|
|
23573
|
+
await mkdir3(path5.dirname(dest), { recursive: true, mode: 448 });
|
|
23574
|
+
const fd = await open3(dest, "wx", 384);
|
|
23271
23575
|
try {
|
|
23272
23576
|
await fd.writeFile(file.body);
|
|
23273
23577
|
await fd.sync();
|
|
@@ -23276,26 +23580,26 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23276
23580
|
}
|
|
23277
23581
|
}
|
|
23278
23582
|
const entries = [...new Set(files.map((file) => file.path.split("/")[0]))].sort();
|
|
23279
|
-
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !entries.includes(name))) throw
|
|
23583
|
+
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !entries.includes(name))) throw error3("runtime_package_incomplete");
|
|
23280
23584
|
const payload = await inspectRuntimePackage(temporary, { entries });
|
|
23281
|
-
if (!payload.hosts.includes(hostKind)) throw
|
|
23282
|
-
if (payload.version !== metadata.version) throw
|
|
23585
|
+
if (!payload.hosts.includes(hostKind)) throw error3("runtime_host_unsupported");
|
|
23586
|
+
if (payload.version !== metadata.version) throw error3("runtime_package_version_invalid");
|
|
23283
23587
|
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
|
|
23588
|
+
if (pkg.repository?.url !== "git+https://github.com/ty-teams/promptframe-creation.git" || pkg.private === true) throw error3("runtime_package_identity_invalid");
|
|
23285
23589
|
if (checkRuntime) await checkRuntime(temporary, metadata.version);
|
|
23286
23590
|
else {
|
|
23287
23591
|
const result = await execute(
|
|
23288
23592
|
process.execPath,
|
|
23289
|
-
[
|
|
23593
|
+
[path5.join(temporary, "bin/promptframe-creation.mjs"), "--version"],
|
|
23290
23594
|
{ timeout: 5e3, maxBuffer: 65536, windowsHide: true, signal, env: {
|
|
23291
23595
|
...process.env,
|
|
23292
|
-
PROMPTFRAME_CREATION_CONFIG:
|
|
23596
|
+
PROMPTFRAME_CREATION_CONFIG: path5.join(temporary, "no-credentials.json")
|
|
23293
23597
|
} }
|
|
23294
23598
|
);
|
|
23295
|
-
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw
|
|
23599
|
+
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw error3("runtime_package_version_invalid");
|
|
23296
23600
|
}
|
|
23297
23601
|
signal?.throwIfAborted();
|
|
23298
|
-
await exclusiveJSON(
|
|
23602
|
+
await exclusiveJSON(path5.join(temporary, "runtime.json"), {
|
|
23299
23603
|
contractVersion: "creation-verified-runtime/v1",
|
|
23300
23604
|
version: metadata.version,
|
|
23301
23605
|
integrity: metadata.integrity,
|
|
@@ -23303,10 +23607,10 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23303
23607
|
});
|
|
23304
23608
|
await syncDirectory(temporary);
|
|
23305
23609
|
if (!index) {
|
|
23306
|
-
await exclusiveJSON(
|
|
23610
|
+
await exclusiveJSON(path5.join(cacheRoot, "version-" + metadata.version + ".json"), metadata);
|
|
23307
23611
|
await syncDirectory(cacheRoot);
|
|
23308
23612
|
}
|
|
23309
|
-
await
|
|
23613
|
+
await rename3(temporary, target);
|
|
23310
23614
|
await syncDirectory(cacheRoot);
|
|
23311
23615
|
return { version: metadata.version, root: target, integrity: metadata.integrity, reused: false };
|
|
23312
23616
|
} finally {
|
|
@@ -23320,7 +23624,7 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
23320
23624
|
async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, resolvedVersion, cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
23321
23625
|
version2(currentVersion);
|
|
23322
23626
|
if (lockedVersion !== void 0) version2(lockedVersion);
|
|
23323
|
-
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw
|
|
23627
|
+
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw error3("runtime_selection_identity_invalid");
|
|
23324
23628
|
if (!policy) throw new RuntimeSelectionError(
|
|
23325
23629
|
"platform_bridge_policy_unavailable",
|
|
23326
23630
|
currentVersion,
|
|
@@ -23339,13 +23643,13 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
23339
23643
|
return { version: currentVersion, current: true, locked: lockedVersion !== void 0, status: "current" };
|
|
23340
23644
|
}
|
|
23341
23645
|
try {
|
|
23342
|
-
await
|
|
23646
|
+
await privateDirectory2(cacheRoot);
|
|
23343
23647
|
let metadata, metadataSource = "registry";
|
|
23344
23648
|
try {
|
|
23345
23649
|
const raw = await boundedGet(REGISTRY + "/@promptframe%2fcreation/" + target, { fetchImpl, signal, maxBytes: 256 * 1024, timeoutMs: 5e3 });
|
|
23346
23650
|
metadata = checkedRuntimeMetadata(JSON.parse(raw), target);
|
|
23347
23651
|
} catch (e) {
|
|
23348
|
-
const prior = await privateJSON(
|
|
23652
|
+
const prior = await privateJSON(path5.join(cacheRoot, "version-" + target + ".json"));
|
|
23349
23653
|
if (!prior) throw e;
|
|
23350
23654
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: target, dist: prior }, target);
|
|
23351
23655
|
metadataSource = "previously-verified-cache";
|
|
@@ -23358,29 +23662,29 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
23358
23662
|
metadataSource
|
|
23359
23663
|
};
|
|
23360
23664
|
} catch (e) {
|
|
23361
|
-
if (signal?.aborted) throw
|
|
23665
|
+
if (signal?.aborted) throw error3("runtime_selection_interrupted");
|
|
23362
23666
|
if (lockedVersion !== void 0)
|
|
23363
23667
|
throw new RuntimeSelectionError("bridge_locked_version_unavailable", currentVersion, lockedVersion, policy, "retry_same_fixed_version_in_new_session");
|
|
23364
23668
|
if (policy && compareBridgeVersions(currentVersion, policy.minBridge) >= 0)
|
|
23365
23669
|
return { version: currentVersion, current: true, locked: false, status: "update_unavailable_current_compatible" };
|
|
23366
23670
|
if (policy) assertBridgeCompatible({ experimental: { "promptframe.creation": policy } }, currentVersion);
|
|
23367
23671
|
if (e instanceof CreationClientError) throw e;
|
|
23368
|
-
throw
|
|
23672
|
+
throw error3("runtime_selection_unavailable");
|
|
23369
23673
|
}
|
|
23370
23674
|
}
|
|
23371
23675
|
|
|
23372
23676
|
// lib/runtime-launch.mjs
|
|
23373
23677
|
import { spawn } from "node:child_process";
|
|
23374
|
-
import
|
|
23678
|
+
import path6 from "node:path";
|
|
23375
23679
|
async function launchSelectedBridge(selection, { host, configFile: configFile2, spawnImpl = spawn, env = process.env } = {}) {
|
|
23376
|
-
if (!
|
|
23680
|
+
if (!path6.isAbsolute(selection.root ?? "") || !path6.isAbsolute(configFile2 ?? "") || !["codex", "claude-code"].includes(host?.kind))
|
|
23377
23681
|
throw new CreationClientError("creation.runtime_launch_invalid");
|
|
23378
23682
|
let child;
|
|
23379
23683
|
try {
|
|
23380
23684
|
child = spawnImpl(
|
|
23381
23685
|
process.execPath,
|
|
23382
23686
|
[
|
|
23383
|
-
|
|
23687
|
+
path6.join(selection.root, "bin/promptframe-creation.mjs"),
|
|
23384
23688
|
"bridge",
|
|
23385
23689
|
"--config",
|
|
23386
23690
|
configFile2,
|
|
@@ -23392,7 +23696,7 @@ async function launchSelectedBridge(selection, { host, configFile: configFile2,
|
|
|
23392
23696
|
{ stdio: "inherit", windowsHide: true, env: {
|
|
23393
23697
|
...env,
|
|
23394
23698
|
PROMPTFRAME_CREATION_CONFIG: configFile2,
|
|
23395
|
-
...host.kind === "claude-code" ? { CLAUDECODE: "1"
|
|
23699
|
+
...host.kind === "claude-code" ? { CLAUDECODE: "1" } : {}
|
|
23396
23700
|
} }
|
|
23397
23701
|
);
|
|
23398
23702
|
} catch {
|
|
@@ -23422,10 +23726,10 @@ async function launchSelectedBridge(selection, { host, configFile: configFile2,
|
|
|
23422
23726
|
// lib/user-installation.mjs
|
|
23423
23727
|
import { execFile as execFile2 } from "node:child_process";
|
|
23424
23728
|
import { promisify as promisify2 } from "node:util";
|
|
23425
|
-
import { createHash as
|
|
23426
|
-
import { lstat as
|
|
23427
|
-
import { homedir as
|
|
23428
|
-
import
|
|
23729
|
+
import { createHash as createHash6, randomBytes as randomBytes4 } from "node:crypto";
|
|
23730
|
+
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";
|
|
23731
|
+
import { homedir as homedir4 } from "node:os";
|
|
23732
|
+
import path7 from "node:path";
|
|
23429
23733
|
|
|
23430
23734
|
// node_modules/smol-toml/dist/error.js
|
|
23431
23735
|
function getLineColFromPtr(string4, ptr) {
|
|
@@ -23517,14 +23821,14 @@ function parseString(ctx) {
|
|
|
23517
23821
|
let value2 = 0;
|
|
23518
23822
|
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
23519
23823
|
for (let j2 = 0; j2 < len; j2++, ctx.p++) {
|
|
23520
|
-
let
|
|
23824
|
+
let hex2 = ctx.s.charCodeAt(ctx.p);
|
|
23521
23825
|
let digit = (
|
|
23522
23826
|
/* 0-9 */
|
|
23523
|
-
|
|
23827
|
+
hex2 >= 48 && hex2 <= 57 ? hex2 - 48 : (
|
|
23524
23828
|
/* A-F */
|
|
23525
|
-
|
|
23829
|
+
hex2 >= 65 && hex2 <= 70 ? hex2 - 65 + 10 : (
|
|
23526
23830
|
/* a-f */
|
|
23527
|
-
|
|
23831
|
+
hex2 >= 97 && hex2 <= 102 ? hex2 - 97 + 10 : -1
|
|
23528
23832
|
)
|
|
23529
23833
|
)
|
|
23530
23834
|
);
|
|
@@ -24187,7 +24491,7 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
24187
24491
|
|
|
24188
24492
|
// lib/user-installation.mjs
|
|
24189
24493
|
var execute2 = promisify2(execFile2);
|
|
24190
|
-
var
|
|
24494
|
+
var hash4 = (b2) => createHash6("sha256").update(b2).digest("hex");
|
|
24191
24495
|
var InstallationError = class extends CreationClientError {
|
|
24192
24496
|
constructor(code, details) {
|
|
24193
24497
|
super("installation." + code);
|
|
@@ -24197,7 +24501,7 @@ var InstallationError = class extends CreationClientError {
|
|
|
24197
24501
|
var fail = (code, details) => {
|
|
24198
24502
|
throw new InstallationError(code, details);
|
|
24199
24503
|
};
|
|
24200
|
-
var installationErrorDetails = (
|
|
24504
|
+
var installationErrorDetails = (error4) => error4 instanceof InstallationError ? error4.details : void 0;
|
|
24201
24505
|
function compareVersions(a, b2) {
|
|
24202
24506
|
const left = a.split(".").map(BigInt), right = b2.split(".").map(BigInt);
|
|
24203
24507
|
for (let i = 0; i < 3; i++) {
|
|
@@ -24218,7 +24522,7 @@ function pinnedGitSource(source) {
|
|
|
24218
24522
|
const refKind = /^[a-f0-9]{40}$/i.test(ref) ? "commit" : /^(?:refs\/tags\/)?creation-v\d+\.\d+\.\d+$/.test(ref) ? "tag" : null;
|
|
24219
24523
|
return refKind ? { refName: ref, refKind } : null;
|
|
24220
24524
|
}
|
|
24221
|
-
var json = async (file) => JSON.parse(await
|
|
24525
|
+
var json = async (file) => JSON.parse(await readFile5(file, "utf8"));
|
|
24222
24526
|
var pause2 = (ms2) => new Promise((r) => setTimeout(r, ms2));
|
|
24223
24527
|
function validProfile(profile) {
|
|
24224
24528
|
if (typeof profile !== "string" || !/^[a-z][a-z0-9-]{0,31}$/.test(profile)) fail("profile_invalid");
|
|
@@ -24226,8 +24530,8 @@ function validProfile(profile) {
|
|
|
24226
24530
|
}
|
|
24227
24531
|
function profileCredentialsPath(profile = "default", env = process.env) {
|
|
24228
24532
|
validProfile(profile);
|
|
24229
|
-
return profile === "default" ? credentialsPath(env) :
|
|
24230
|
-
env.XDG_CONFIG_HOME ??
|
|
24533
|
+
return profile === "default" ? credentialsPath(env) : path7.resolve(
|
|
24534
|
+
env.XDG_CONFIG_HOME ?? path7.join(homedir4(), ".config"),
|
|
24231
24535
|
"promptframe-creation",
|
|
24232
24536
|
"profiles",
|
|
24233
24537
|
profile,
|
|
@@ -24236,18 +24540,18 @@ function profileCredentialsPath(profile = "default", env = process.env) {
|
|
|
24236
24540
|
}
|
|
24237
24541
|
async function info2(file) {
|
|
24238
24542
|
try {
|
|
24239
|
-
return await
|
|
24543
|
+
return await lstat5(file);
|
|
24240
24544
|
} catch (e) {
|
|
24241
24545
|
if (e.code === "ENOENT") return null;
|
|
24242
24546
|
throw e;
|
|
24243
24547
|
}
|
|
24244
24548
|
}
|
|
24245
|
-
async function
|
|
24246
|
-
await
|
|
24247
|
-
const s3 = await
|
|
24549
|
+
async function privateDirectory3(dir) {
|
|
24550
|
+
await mkdir4(dir, { recursive: true, mode: 448 });
|
|
24551
|
+
const s3 = await lstat5(dir);
|
|
24248
24552
|
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) fail("private_owner_required");
|
|
24249
24553
|
}
|
|
24250
|
-
async function
|
|
24554
|
+
async function privateRead2(file) {
|
|
24251
24555
|
const s3 = await info2(file);
|
|
24252
24556
|
if (!s3) return null;
|
|
24253
24557
|
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) fail("state_invalid");
|
|
@@ -24259,20 +24563,20 @@ async function packageJSON(file) {
|
|
|
24259
24563
|
return json(file);
|
|
24260
24564
|
}
|
|
24261
24565
|
function sameTransport(actual, expected) {
|
|
24262
|
-
return actual?.type === "stdio" && actual.command === expected.command && typeof actual.cwd === "string" &&
|
|
24566
|
+
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
24567
|
}
|
|
24264
24568
|
async function managedTransport(installed, versions, serverName, profile, configFile2) {
|
|
24265
24569
|
if (!installed) return null;
|
|
24266
24570
|
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(
|
|
24571
|
+
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");
|
|
24572
|
+
const directory = await info2(root), definition = await info2(path7.join(root, ".mcp.json"));
|
|
24269
24573
|
if (!directory?.isDirectory() || directory.isSymbolicLink() || !definition?.isFile() || definition.isSymbolicLink()) fail("installed_files_invalid");
|
|
24270
|
-
const ready = await
|
|
24574
|
+
const ready = await privateRead2(path7.join(root, "installation.json"));
|
|
24271
24575
|
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 !==
|
|
24576
|
+
const bytes2 = await readFile5(path7.join(root, ".mcp.json")), entry = ready.files?.find((x) => x.path === ".mcp.json");
|
|
24577
|
+
if (!entry || entry.bytes !== bytes2.length || entry.sha256 !== hash4(bytes2)) fail("installed_files_invalid");
|
|
24274
24578
|
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([
|
|
24579
|
+
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
24580
|
return mcp;
|
|
24277
24581
|
}
|
|
24278
24582
|
async function officialNpmInstallation(installed, servers, env, profile, configFile2) {
|
|
@@ -24280,12 +24584,12 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
24280
24584
|
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
24585
|
if (candidates.length > 1) fail("existing_registration_requires_review");
|
|
24282
24586
|
if (!candidates.length) return null;
|
|
24283
|
-
const p2 = candidates[0], root =
|
|
24587
|
+
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
24588
|
const directory = await info2(root);
|
|
24285
24589
|
if (!directory?.isDirectory() || directory.isSymbolicLink()) fail("installed_files_invalid");
|
|
24286
|
-
const pkg = await packageJSON(
|
|
24590
|
+
const pkg = await packageJSON(path7.join(root, "package.json")), manifest = await packageJSON(path7.join(root, ".codex-plugin/plugin.json"));
|
|
24287
24591
|
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(
|
|
24592
|
+
const definition = (await packageJSON(path7.join(root, ".mcp.json"))).mcpServers?.promptframe;
|
|
24289
24593
|
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
24594
|
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
24595
|
return {
|
|
@@ -24302,17 +24606,17 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
24302
24606
|
};
|
|
24303
24607
|
}
|
|
24304
24608
|
async function atomicJSON(file, value2) {
|
|
24305
|
-
const temp = file + "." +
|
|
24609
|
+
const temp = file + "." + randomBytes4(12).toString("hex") + ".tmp";
|
|
24306
24610
|
try {
|
|
24307
|
-
const out = await
|
|
24611
|
+
const out = await open4(temp, "wx", 384);
|
|
24308
24612
|
try {
|
|
24309
24613
|
await out.writeFile(JSON.stringify(value2, null, 2) + "\n");
|
|
24310
24614
|
await out.sync();
|
|
24311
24615
|
} finally {
|
|
24312
24616
|
await out.close();
|
|
24313
24617
|
}
|
|
24314
|
-
await
|
|
24315
|
-
const directory = await
|
|
24618
|
+
await rename4(temp, file);
|
|
24619
|
+
const directory = await open4(path7.dirname(file), "r");
|
|
24316
24620
|
try {
|
|
24317
24621
|
await directory.sync();
|
|
24318
24622
|
} finally {
|
|
@@ -24323,13 +24627,13 @@ async function atomicJSON(file, value2) {
|
|
|
24323
24627
|
}
|
|
24324
24628
|
}
|
|
24325
24629
|
async function acquire(root, signal) {
|
|
24326
|
-
const lock =
|
|
24630
|
+
const lock = path7.join(root, "install.lock");
|
|
24327
24631
|
const end = Date.now() + 3e4;
|
|
24328
24632
|
let owned = false;
|
|
24329
24633
|
while (!owned) {
|
|
24330
24634
|
signal?.throwIfAborted();
|
|
24331
24635
|
try {
|
|
24332
|
-
await
|
|
24636
|
+
await mkdir4(lock, { mode: 448 });
|
|
24333
24637
|
owned = true;
|
|
24334
24638
|
} catch (e) {
|
|
24335
24639
|
if (e.code !== "EEXIST") throw e;
|
|
@@ -24338,7 +24642,7 @@ async function acquire(root, signal) {
|
|
|
24338
24642
|
}
|
|
24339
24643
|
}
|
|
24340
24644
|
try {
|
|
24341
|
-
await writeFile2(
|
|
24645
|
+
await writeFile2(path7.join(lock, "owner.json"), JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() }), { flag: "wx", mode: 384 });
|
|
24342
24646
|
} catch (e) {
|
|
24343
24647
|
await rm2(lock, { recursive: true, force: true });
|
|
24344
24648
|
throw e;
|
|
@@ -24379,12 +24683,12 @@ async function codexJSON(runCodex, args2) {
|
|
|
24379
24683
|
}
|
|
24380
24684
|
}
|
|
24381
24685
|
async function relatedPlugins(runCodex, pluginName, env) {
|
|
24382
|
-
const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), pinnedMarketplaces = /* @__PURE__ */ new Map(), config2 =
|
|
24686
|
+
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
24687
|
try {
|
|
24384
24688
|
const s3 = await info2(config2);
|
|
24385
24689
|
if (s3) {
|
|
24386
24690
|
if (!s3.isFile() || s3.isSymbolicLink() || s3.size > 2 * 1024 * 1024) throw Error();
|
|
24387
|
-
const plugins = parse3(await
|
|
24691
|
+
const plugins = parse3(await readFile5(config2, "utf8")).plugins ?? {};
|
|
24388
24692
|
if (!plugins || typeof plugins !== "object" || Array.isArray(plugins) || Object.keys(plugins).length > 1024) throw Error();
|
|
24389
24693
|
for (const id of Object.keys(plugins)) if (id.startsWith(pluginName + "@")) {
|
|
24390
24694
|
const market = id.slice(pluginName.length + 1);
|
|
@@ -24399,10 +24703,10 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
24399
24703
|
const state = await codexJSON(runCodex, ["plugin", "marketplace", "list", "--json"]);
|
|
24400
24704
|
if (!Array.isArray(state?.marketplaces) || state.marketplaces.length > 128) fail("local_catalog_unconfirmed");
|
|
24401
24705
|
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" || !
|
|
24706
|
+
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
24707
|
let catalog;
|
|
24404
24708
|
try {
|
|
24405
|
-
catalog = await packageJSON(
|
|
24709
|
+
catalog = await packageJSON(path7.join(market.root, ".agents/plugins/marketplace.json"));
|
|
24406
24710
|
} catch {
|
|
24407
24711
|
fail("local_catalog_unconfirmed", { phase: "local_check", commandKind: "marketplace_read", localRegistrationState: "unknown", action: "restore_local_marketplace_catalog" });
|
|
24408
24712
|
}
|
|
@@ -24433,7 +24737,7 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
24433
24737
|
}
|
|
24434
24738
|
async function runNode(root, version3) {
|
|
24435
24739
|
try {
|
|
24436
|
-
const result = await execute2(process.execPath, [
|
|
24740
|
+
const result = await execute2(process.execPath, [path7.join(root, "bin/promptframe-creation.mjs"), "--version"], { encoding: "utf8", timeout: 1e4, maxBuffer: 8192 });
|
|
24437
24741
|
if (result.stdout.trim() !== version3) fail("runtime_version_mismatch");
|
|
24438
24742
|
} catch (e) {
|
|
24439
24743
|
if (e instanceof CreationClientError) throw e;
|
|
@@ -24447,7 +24751,7 @@ async function checkInstalledRuntime(root, version3, command2, { env = process.e
|
|
|
24447
24751
|
if (!major || Number(major[1]) < 20) throw Error("unsupported_node");
|
|
24448
24752
|
const result = await execute2(
|
|
24449
24753
|
command2,
|
|
24450
|
-
[
|
|
24754
|
+
[path7.join(root, "bin/promptframe-creation.mjs"), "--version"],
|
|
24451
24755
|
{ env, encoding: "utf8", timeout: 1e4, maxBuffer: 8192 }
|
|
24452
24756
|
);
|
|
24453
24757
|
if (result.stdout.trim() !== version3) throw Error("wrong_version");
|
|
@@ -24461,8 +24765,8 @@ async function checkInstalledRuntime(root, version3, command2, { env = process.e
|
|
|
24461
24765
|
}
|
|
24462
24766
|
var installationFiles = Object.freeze({
|
|
24463
24767
|
info: info2,
|
|
24464
|
-
privateDirectory:
|
|
24465
|
-
privateRead,
|
|
24768
|
+
privateDirectory: privateDirectory3,
|
|
24769
|
+
privateRead: privateRead2,
|
|
24466
24770
|
atomicJSON,
|
|
24467
24771
|
acquire,
|
|
24468
24772
|
runNode,
|
|
@@ -24484,21 +24788,21 @@ async function installForUser({
|
|
|
24484
24788
|
const versionOutput = await runCodex(["--version"]);
|
|
24485
24789
|
const match = versionOutput.match(/codex-cli (\d+)\.(\d+)\.(\d+)/);
|
|
24486
24790
|
if (!match || Number(match[1]) === 0 && Number(match[2]) < 160) fail("codex_0160_required");
|
|
24487
|
-
const payload = await inspectRuntimePackage(
|
|
24488
|
-
const root =
|
|
24489
|
-
await
|
|
24791
|
+
const payload = await inspectRuntimePackage(path7.resolve(sourceRoot));
|
|
24792
|
+
const root = path7.resolve(env.XDG_DATA_HOME ?? path7.join(homedir4(), ".local/share"), "promptframe-creation", profile);
|
|
24793
|
+
await privateDirectory3(root);
|
|
24490
24794
|
const release = await acquire(root, signal);
|
|
24491
|
-
const versions =
|
|
24492
|
-
const marketplaceFile =
|
|
24795
|
+
const versions = path7.join(root, "versions"), currentFile = path7.join(root, "current.json"), pendingFile = path7.join(root, "registration-pending.json");
|
|
24796
|
+
const marketplaceFile = path7.join(root, ".agents/plugins/marketplace.json");
|
|
24493
24797
|
const pluginName = "promptframe-creation" + (profile === "default" ? "" : "-" + profile), marketplace = "promptframe-creation-user" + (profile === "default" ? "" : "-" + profile);
|
|
24494
24798
|
const pluginId = pluginName + "@" + marketplace;
|
|
24495
|
-
const versionRoot =
|
|
24799
|
+
const versionRoot = path7.join(versions, payload.version), temporary = path7.join(versions, ".partial-" + randomBytes4(12).toString("hex"));
|
|
24496
24800
|
let previous, registrationStarted = false, newFiles = 0;
|
|
24497
24801
|
try {
|
|
24498
24802
|
signal?.throwIfAborted();
|
|
24499
|
-
await
|
|
24500
|
-
await
|
|
24501
|
-
previous = await
|
|
24803
|
+
await privateDirectory3(versions);
|
|
24804
|
+
await privateDirectory3(path7.dirname(marketplaceFile));
|
|
24805
|
+
previous = await privateRead2(currentFile);
|
|
24502
24806
|
if (previous && (previous.profile !== profile || previous.pluginId !== pluginId || previous.configFile !== configFile2)) fail("profile_binding_conflict");
|
|
24503
24807
|
const state = { installed: await relatedPlugins(runCodex, pluginName, env) };
|
|
24504
24808
|
const installed = state.installed.find((x) => x.pluginId === pluginId);
|
|
@@ -24506,14 +24810,14 @@ async function installForUser({
|
|
|
24506
24810
|
if (!Array.isArray(legacy)) fail("local_registration_unconfirmed");
|
|
24507
24811
|
const serverName = "promptframe" + (profile === "default" ? "" : "-" + profile);
|
|
24508
24812
|
const servers = legacy.filter((x) => x.name === serverName);
|
|
24509
|
-
const pending = await
|
|
24813
|
+
const pending = await privateRead2(pendingFile);
|
|
24510
24814
|
if (pending) {
|
|
24511
|
-
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !==
|
|
24815
|
+
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !== path7.join(versions, pending.version)) fail("profile_binding_conflict");
|
|
24512
24816
|
if (installed?.version !== pending.version || installed.enabled !== true || installed.source?.path !== pending.versionRoot)
|
|
24513
24817
|
fail("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
24514
24818
|
const transport2 = await managedTransport(installed, versions, serverName, profile, configFile2);
|
|
24515
24819
|
if (servers.length !== 1 || servers[0].enabled === false || !sameTransport(servers[0].transport, transport2)) fail("registration_unconfirmed_keep_existing");
|
|
24516
|
-
const ready = await
|
|
24820
|
+
const ready = await privateRead2(path7.join(pending.versionRoot, "installation.json"));
|
|
24517
24821
|
if (ready?.payloadDigest !== pending.payloadDigest) fail("installed_files_invalid");
|
|
24518
24822
|
previous = pending;
|
|
24519
24823
|
await atomicJSON(currentFile, pending);
|
|
@@ -24568,43 +24872,43 @@ async function installForUser({
|
|
|
24568
24872
|
const target = await info2(versionRoot);
|
|
24569
24873
|
if (target) {
|
|
24570
24874
|
if (!target.isDirectory() || target.isSymbolicLink()) fail("version_content_conflict");
|
|
24571
|
-
const ready = await
|
|
24875
|
+
const ready = await privateRead2(path7.join(versionRoot, "installation.json"));
|
|
24572
24876
|
if (!ready || ready.payloadDigest !== payload.payloadDigest || ready.profile !== profile || ready.configFile !== configFile2) fail("version_content_conflict");
|
|
24573
24877
|
for (const f2 of ready.files) {
|
|
24574
24878
|
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 ||
|
|
24879
|
+
const file = path7.join(versionRoot, f2.path), s3 = await info2(file);
|
|
24880
|
+
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size !== f2.bytes || hash4(await readFile5(file)) !== f2.sha256) fail("installed_files_invalid");
|
|
24577
24881
|
}
|
|
24578
24882
|
if (ready.files.length !== payload.files.length) fail("installed_files_invalid");
|
|
24579
24883
|
} else {
|
|
24580
|
-
await
|
|
24884
|
+
await mkdir4(temporary, { mode: 448 });
|
|
24581
24885
|
for (const f2 of payload.files) {
|
|
24582
24886
|
signal?.throwIfAborted();
|
|
24583
|
-
await
|
|
24584
|
-
await writeFile2(
|
|
24887
|
+
await mkdir4(path7.dirname(path7.join(temporary, f2.path)), { recursive: true, mode: 448 });
|
|
24888
|
+
await writeFile2(path7.join(temporary, f2.path), f2.body, { flag: "wx", mode: 384 });
|
|
24585
24889
|
}
|
|
24586
|
-
const manifest = await json(
|
|
24890
|
+
const manifest = await json(path7.join(temporary, ".codex-plugin/plugin.json"));
|
|
24587
24891
|
manifest.name = pluginName;
|
|
24588
|
-
await writeFile2(
|
|
24892
|
+
await writeFile2(path7.join(temporary, ".codex-plugin/plugin.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
24589
24893
|
const mcp = { mcpServers: { ["promptframe" + (profile === "default" ? "" : "-" + profile)]: {
|
|
24590
24894
|
command: process.execPath,
|
|
24591
|
-
args: [
|
|
24895
|
+
args: [path7.join(versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", configFile2],
|
|
24592
24896
|
cwd: versionRoot
|
|
24593
24897
|
} } };
|
|
24594
|
-
await writeFile2(
|
|
24898
|
+
await writeFile2(path7.join(temporary, ".mcp.json"), JSON.stringify(mcp, null, 2) + "\n");
|
|
24595
24899
|
await checkRuntime(temporary, payload.version);
|
|
24596
24900
|
const files = [];
|
|
24597
24901
|
for (const f2 of payload.files) {
|
|
24598
|
-
const body = await
|
|
24599
|
-
files.push({ path: f2.path, bytes: body.length, sha256:
|
|
24902
|
+
const body = await readFile5(path7.join(temporary, f2.path));
|
|
24903
|
+
files.push({ path: f2.path, bytes: body.length, sha256: hash4(body) });
|
|
24600
24904
|
}
|
|
24601
|
-
await atomicJSON(
|
|
24905
|
+
await atomicJSON(path7.join(temporary, "installation.json"), { version: payload.version, profile, configFile: configFile2, payloadDigest: payload.payloadDigest, files });
|
|
24602
24906
|
signal?.throwIfAborted();
|
|
24603
|
-
await
|
|
24907
|
+
await rename4(temporary, versionRoot);
|
|
24604
24908
|
newFiles = payload.files.length;
|
|
24605
24909
|
}
|
|
24606
24910
|
if (newFiles === 0) {
|
|
24607
|
-
const launch = (await json(
|
|
24911
|
+
const launch = (await json(path7.join(versionRoot, ".mcp.json"))).mcpServers?.[serverName];
|
|
24608
24912
|
await verifyInstalledRuntime(versionRoot, payload.version, launch.command, { env });
|
|
24609
24913
|
}
|
|
24610
24914
|
const complete = { version: payload.version, profile, configFile: configFile2, pluginId, versionRoot, payloadDigest: payload.payloadDigest };
|
|
@@ -24643,16 +24947,16 @@ async function installForUser({
|
|
|
24643
24947
|
reloadRequired: !already,
|
|
24644
24948
|
recordedRuntimeRetained: Boolean(already && recorded && recorded.command !== process.execPath)
|
|
24645
24949
|
};
|
|
24646
|
-
} catch (
|
|
24950
|
+
} catch (error4) {
|
|
24647
24951
|
if (registrationStarted) {
|
|
24648
24952
|
fail("registration_unconfirmed_keep_existing", {
|
|
24649
|
-
...installationErrorDetails(
|
|
24953
|
+
...installationErrorDetails(error4),
|
|
24650
24954
|
phase: "registration_observation",
|
|
24651
24955
|
localRegistrationState: "unknown",
|
|
24652
24956
|
action: "inspect_same_registration_no_second_add"
|
|
24653
24957
|
});
|
|
24654
24958
|
}
|
|
24655
|
-
if (
|
|
24959
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
24656
24960
|
if (signal?.aborted) fail("interrupted_keep_existing");
|
|
24657
24961
|
fail("failed_keep_existing");
|
|
24658
24962
|
} finally {
|
|
@@ -24662,18 +24966,36 @@ async function installForUser({
|
|
|
24662
24966
|
}
|
|
24663
24967
|
|
|
24664
24968
|
// lib/claude-installation.mjs
|
|
24665
|
-
import { createHash as
|
|
24666
|
-
import { mkdir as
|
|
24667
|
-
import { homedir as
|
|
24668
|
-
import
|
|
24969
|
+
import { createHash as createHash9, randomBytes as randomBytes6 } from "node:crypto";
|
|
24970
|
+
import { mkdir as mkdir6, open as open7, readFile as readFile8, rename as rename6, rm as rm5 } from "node:fs/promises";
|
|
24971
|
+
import { homedir as homedir9 } from "node:os";
|
|
24972
|
+
import path12 from "node:path";
|
|
24973
|
+
|
|
24974
|
+
// lib/claude-hook-definition.mjs
|
|
24975
|
+
function claudeHostHooks({ pluginName = "promptframe-creation", serverName, configFile: configFile2, nodeCommand = "node", runtimeRoot = "${CLAUDE_PLUGIN_ROOT}" } = {}) {
|
|
24976
|
+
const escaped = pluginName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24977
|
+
const command2 = { type: "command", command: nodeCommand, args: [
|
|
24978
|
+
runtimeRoot + "/bin/promptframe-creation.mjs",
|
|
24979
|
+
"claude-host-hook",
|
|
24980
|
+
...configFile2 ? ["--config", configFile2] : []
|
|
24981
|
+
], timeout: 5 };
|
|
24982
|
+
return {
|
|
24983
|
+
SessionStart: [{ matcher: "startup|resume|fork|clear|compact", hooks: [{ ...command2 }] }],
|
|
24984
|
+
PreToolUse: [{
|
|
24985
|
+
matcher: serverName ? "^mcp__" + serverName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "__.*" : "^mcp__plugin_" + escaped + "_.*",
|
|
24986
|
+
hooks: [{ ...command2, onFailure: "block" }]
|
|
24987
|
+
}],
|
|
24988
|
+
SessionEnd: [{ hooks: [{ ...command2 }] }]
|
|
24989
|
+
};
|
|
24990
|
+
}
|
|
24669
24991
|
|
|
24670
24992
|
// lib/claude-command.mjs
|
|
24671
24993
|
import { execFile as execFile3 } from "node:child_process";
|
|
24672
24994
|
import { promisify as promisify3 } from "node:util";
|
|
24673
|
-
import { access, lstat as
|
|
24674
|
-
import { constants } from "node:fs";
|
|
24675
|
-
import { homedir as
|
|
24676
|
-
import
|
|
24995
|
+
import { access, lstat as lstat6, readdir as readdir4 } from "node:fs/promises";
|
|
24996
|
+
import { constants as constants2 } from "node:fs";
|
|
24997
|
+
import { homedir as homedir5 } from "node:os";
|
|
24998
|
+
import path8 from "node:path";
|
|
24677
24999
|
var execute3 = promisify3(execFile3);
|
|
24678
25000
|
var ClaudeCommandError = class extends CreationClientError {
|
|
24679
25001
|
constructor(code, details) {
|
|
@@ -24681,24 +25003,24 @@ var ClaudeCommandError = class extends CreationClientError {
|
|
|
24681
25003
|
this.details = details;
|
|
24682
25004
|
}
|
|
24683
25005
|
};
|
|
24684
|
-
var claudeErrorDetails = (
|
|
24685
|
-
async function resolveClaudeCommand({ env = process.env, homeDirectory =
|
|
25006
|
+
var claudeErrorDetails = (error4) => error4 instanceof ClaudeCommandError ? error4.details : void 0;
|
|
25007
|
+
async function resolveClaudeCommand({ env = process.env, homeDirectory = homedir5(), executable } = {}) {
|
|
24686
25008
|
const selected = executable ?? env.PROMPTFRAME_CLAUDE_BIN;
|
|
24687
25009
|
if (selected) {
|
|
24688
|
-
if (!
|
|
24689
|
-
await access(selected,
|
|
25010
|
+
if (!path8.isAbsolute(selected)) throw new CreationClientError("installation.claude_executable_invalid");
|
|
25011
|
+
await access(selected, constants2.X_OK);
|
|
24690
25012
|
return selected;
|
|
24691
25013
|
}
|
|
24692
|
-
for (const directory of (env.PATH ?? "").split(
|
|
24693
|
-
const file =
|
|
25014
|
+
for (const directory of (env.PATH ?? "").split(path8.delimiter).filter(path8.isAbsolute)) {
|
|
25015
|
+
const file = path8.join(directory, process.platform === "win32" ? "claude.exe" : "claude");
|
|
24694
25016
|
try {
|
|
24695
|
-
await access(file,
|
|
25017
|
+
await access(file, constants2.X_OK);
|
|
24696
25018
|
return file;
|
|
24697
25019
|
} catch (e) {
|
|
24698
25020
|
if (!["ENOENT", "EACCES", "ENOTDIR"].includes(e.code)) throw e;
|
|
24699
25021
|
}
|
|
24700
25022
|
}
|
|
24701
|
-
const root =
|
|
25023
|
+
const root = path8.join(homeDirectory, ".claude/remote/ccd-cli");
|
|
24702
25024
|
let entries;
|
|
24703
25025
|
try {
|
|
24704
25026
|
entries = await readdir4(root);
|
|
@@ -24711,9 +25033,9 @@ async function resolveClaudeCommand({ env = process.env, homeDirectory = homedir
|
|
|
24711
25033
|
for (const name of entries) {
|
|
24712
25034
|
const match = name.match(/^(\d+)\.(\d+)\.(\d+)-[a-f0-9]{6,40}$/);
|
|
24713
25035
|
if (!match) continue;
|
|
24714
|
-
const file =
|
|
25036
|
+
const file = path8.join(root, name), s3 = await lstat6(file);
|
|
24715
25037
|
if (s3.isFile() && !s3.isSymbolicLink() && s3.uid === process.getuid?.()) {
|
|
24716
|
-
await access(file,
|
|
25038
|
+
await access(file, constants2.X_OK);
|
|
24717
25039
|
candidates.push({ file, version: match.slice(1).map(Number) });
|
|
24718
25040
|
}
|
|
24719
25041
|
}
|
|
@@ -24749,17 +25071,17 @@ function createClaudeRunner({ env = process.env, executable, signal, resolve = r
|
|
|
24749
25071
|
}
|
|
24750
25072
|
|
|
24751
25073
|
// lib/claude-local-state.mjs
|
|
24752
|
-
import { readFile as
|
|
24753
|
-
import { homedir as
|
|
24754
|
-
import
|
|
25074
|
+
import { readFile as readFile6, lstat as lstat7 } from "node:fs/promises";
|
|
25075
|
+
import { homedir as homedir6 } from "node:os";
|
|
25076
|
+
import path9 from "node:path";
|
|
24755
25077
|
function claudeConfigRoot(env = process.env) {
|
|
24756
|
-
return
|
|
25078
|
+
return path9.resolve(env.CLAUDE_CONFIG_DIR ?? path9.join(homedir6(), ".claude"));
|
|
24757
25079
|
}
|
|
24758
25080
|
async function readClaudeUserServer(serverName, env = process.env) {
|
|
24759
|
-
const file = env.CLAUDE_CONFIG_DIR ?
|
|
25081
|
+
const file = env.CLAUDE_CONFIG_DIR ? path9.join(claudeConfigRoot(env), ".claude.json") : path9.join(homedir6(), ".claude.json");
|
|
24760
25082
|
let info5;
|
|
24761
25083
|
try {
|
|
24762
|
-
info5 = await
|
|
25084
|
+
info5 = await lstat7(file);
|
|
24763
25085
|
} catch (e) {
|
|
24764
25086
|
if (e.code === "ENOENT") return null;
|
|
24765
25087
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
@@ -24768,7 +25090,7 @@ async function readClaudeUserServer(serverName, env = process.env) {
|
|
|
24768
25090
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
24769
25091
|
let state;
|
|
24770
25092
|
try {
|
|
24771
|
-
state = JSON.parse(await
|
|
25093
|
+
state = JSON.parse(await readFile6(file, "utf8"));
|
|
24772
25094
|
} catch {
|
|
24773
25095
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
24774
25096
|
}
|
|
@@ -24779,28 +25101,110 @@ async function readClaudeUserServer(serverName, env = process.env) {
|
|
|
24779
25101
|
}
|
|
24780
25102
|
|
|
24781
25103
|
// lib/claude-mcp-installation.mjs
|
|
24782
|
-
import { createHash as
|
|
24783
|
-
import { mkdir as
|
|
24784
|
-
import { homedir as
|
|
24785
|
-
import
|
|
24786
|
-
|
|
24787
|
-
|
|
25104
|
+
import { createHash as createHash8, randomBytes as randomBytes5 } from "node:crypto";
|
|
25105
|
+
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";
|
|
25106
|
+
import { homedir as homedir8 } from "node:os";
|
|
25107
|
+
import path11 from "node:path";
|
|
25108
|
+
|
|
25109
|
+
// lib/claude-hook-registration.mjs
|
|
25110
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
25111
|
+
import { open as open5, rm as rm3 } from "node:fs/promises";
|
|
25112
|
+
import { constants as constants3 } from "node:fs";
|
|
25113
|
+
import path10 from "node:path";
|
|
25114
|
+
import { homedir as homedir7 } from "node:os";
|
|
25115
|
+
var { privateDirectory: privateDirectory4, privateRead: privateRead3, atomicJSON: atomicJSON2, acquire: acquire2 } = installationFiles;
|
|
25116
|
+
var digest3 = (value2) => createHash7("sha256").update(JSON.stringify(value2)).digest("hex");
|
|
25117
|
+
var fail2 = () => {
|
|
25118
|
+
throw new CreationClientError("installation.claude_hooks_require_review");
|
|
25119
|
+
};
|
|
25120
|
+
async function settings(file) {
|
|
25121
|
+
let handle;
|
|
25122
|
+
try {
|
|
25123
|
+
handle = await open5(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
25124
|
+
const info5 = await handle.stat();
|
|
25125
|
+
if (!info5.isFile() || info5.uid !== process.getuid?.() || info5.size > 512 * 1024) fail2();
|
|
25126
|
+
const value2 = JSON.parse(await handle.readFile("utf8"));
|
|
25127
|
+
if (!value2 || typeof value2 !== "object" || Array.isArray(value2) || value2.hooks !== void 0 && (!value2.hooks || typeof value2.hooks !== "object" || Array.isArray(value2.hooks))) fail2();
|
|
25128
|
+
return value2;
|
|
25129
|
+
} catch (e) {
|
|
25130
|
+
if (e.code === "ENOENT") return {};
|
|
25131
|
+
throw e;
|
|
25132
|
+
} finally {
|
|
25133
|
+
await handle?.close();
|
|
25134
|
+
}
|
|
25135
|
+
}
|
|
25136
|
+
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));
|
|
25137
|
+
async function verifyClaudeFallbackHooks(record2, env) {
|
|
25138
|
+
if (!record2?.settingsFile || record2.settingsFile !== path10.join(claudeConfigRoot(env), "settings.json") || !record2.entries) fail2();
|
|
25139
|
+
if (!contains(await settings(record2.settingsFile), record2.entries)) fail2();
|
|
25140
|
+
return true;
|
|
25141
|
+
}
|
|
25142
|
+
async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCommand, signal }) {
|
|
25143
|
+
const directory = claudeConfigRoot(env), file = path10.join(directory, "settings.json");
|
|
25144
|
+
const guard = path10.resolve(
|
|
25145
|
+
env.XDG_DATA_HOME ?? path10.join(homedir7(), ".local/share"),
|
|
25146
|
+
"promptframe-creation",
|
|
25147
|
+
"claude-hook-writer-" + digest3(directory)
|
|
25148
|
+
);
|
|
25149
|
+
await privateDirectory4(guard);
|
|
25150
|
+
const release = await acquire2(guard, signal);
|
|
25151
|
+
const markerFile = path10.join(root, "hooks-current.json"), pendingFile = path10.join(root, "hooks-pending.json");
|
|
25152
|
+
try {
|
|
25153
|
+
await privateDirectory4(directory);
|
|
25154
|
+
const entries = claudeHostHooks({ serverName: record2.serverName, configFile: record2.configFile, nodeCommand, runtimeRoot: record2.versionRoot });
|
|
25155
|
+
const expected = { contractVersion: "creation-claude-hooks/v1", settingsFile: file, profile: record2.profile, entries };
|
|
25156
|
+
const pending = await privateRead3(pendingFile), previous = await privateRead3(markerFile), before = await settings(file);
|
|
25157
|
+
if (pending) {
|
|
25158
|
+
if (digest3(pending) !== digest3(expected) || !contains(before, entries)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
25159
|
+
await atomicJSON2(markerFile, expected);
|
|
25160
|
+
await rm3(pendingFile);
|
|
25161
|
+
return expected;
|
|
25162
|
+
}
|
|
25163
|
+
if (previous) {
|
|
25164
|
+
if (previous.contractVersion !== expected.contractVersion || previous.profile !== record2.profile || previous.settingsFile !== file) fail2();
|
|
25165
|
+
await verifyClaudeFallbackHooks(previous, env);
|
|
25166
|
+
if (digest3(previous) === digest3(expected)) return previous;
|
|
25167
|
+
}
|
|
25168
|
+
const next = { ...before, hooks: { ...before.hooks } };
|
|
25169
|
+
for (const [event, wanted] of Object.entries(entries)) {
|
|
25170
|
+
const actual = next.hooks[event] ?? [];
|
|
25171
|
+
if (!Array.isArray(actual)) fail2();
|
|
25172
|
+
const owned = new Set((previous?.entries[event] ?? []).map(digest3));
|
|
25173
|
+
if (wanted.some((entry) => actual.some((value2) => digest3(value2) === digest3(entry)) && !owned.has(digest3(entry)))) fail2();
|
|
25174
|
+
next.hooks[event] = [...actual.filter((entry) => !owned.has(digest3(entry))), ...wanted];
|
|
25175
|
+
}
|
|
25176
|
+
signal?.throwIfAborted();
|
|
25177
|
+
await atomicJSON2(pendingFile, expected);
|
|
25178
|
+
if (digest3(await settings(file)) !== digest3(before)) fail2();
|
|
25179
|
+
await atomicJSON2(file, next);
|
|
25180
|
+
if (!contains(await settings(file), entries)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
25181
|
+
await atomicJSON2(markerFile, expected);
|
|
25182
|
+
await rm3(pendingFile);
|
|
25183
|
+
return expected;
|
|
25184
|
+
} finally {
|
|
25185
|
+
await release();
|
|
25186
|
+
}
|
|
25187
|
+
}
|
|
25188
|
+
|
|
25189
|
+
// lib/claude-mcp-installation.mjs
|
|
25190
|
+
var { info: info3, privateDirectory: privateDirectory5, privateRead: privateRead4, atomicJSON: atomicJSON3, acquire: acquire3, compareVersions: compareVersions2 } = installationFiles;
|
|
25191
|
+
var hash5 = (body) => createHash8("sha256").update(body).digest("hex");
|
|
24788
25192
|
var FallbackError = class extends CreationClientError {
|
|
24789
25193
|
constructor(code, details) {
|
|
24790
25194
|
super("installation." + code);
|
|
24791
25195
|
this.details = details;
|
|
24792
25196
|
}
|
|
24793
25197
|
};
|
|
24794
|
-
var fallbackErrorDetails = (
|
|
24795
|
-
var
|
|
25198
|
+
var fallbackErrorDetails = (error4) => error4 instanceof FallbackError ? error4.details : void 0;
|
|
25199
|
+
var fail3 = (code, details) => {
|
|
24796
25200
|
throw new FallbackError(code, details);
|
|
24797
25201
|
};
|
|
24798
25202
|
async function claimSkillDirectory(root) {
|
|
24799
25203
|
try {
|
|
24800
|
-
await
|
|
24801
|
-
} catch (
|
|
24802
|
-
if (
|
|
24803
|
-
throw
|
|
25204
|
+
await mkdir5(root, { mode: 448 });
|
|
25205
|
+
} catch (error4) {
|
|
25206
|
+
if (error4.code === "EEXIST") fail3("claude_skill_requires_review");
|
|
25207
|
+
throw error4;
|
|
24804
25208
|
}
|
|
24805
25209
|
}
|
|
24806
25210
|
function same(a, b2, depth = 0) {
|
|
@@ -24810,62 +25214,62 @@ function same(a, b2, depth = 0) {
|
|
|
24810
25214
|
return left.length <= 256 && left.length === right.length && left.every((key, i) => key === right[i] && same(a[key], b2[key], depth + 1));
|
|
24811
25215
|
}
|
|
24812
25216
|
async function atomicText(file, body) {
|
|
24813
|
-
const temporary = file + "." +
|
|
25217
|
+
const temporary = file + "." + randomBytes5(12).toString("hex") + ".tmp";
|
|
24814
25218
|
try {
|
|
24815
|
-
const fd = await
|
|
25219
|
+
const fd = await open6(temporary, "wx", 384);
|
|
24816
25220
|
try {
|
|
24817
25221
|
await fd.writeFile(body);
|
|
24818
25222
|
await fd.sync();
|
|
24819
25223
|
} finally {
|
|
24820
25224
|
await fd.close();
|
|
24821
25225
|
}
|
|
24822
|
-
await
|
|
24823
|
-
const dir = await
|
|
25226
|
+
await rename5(temporary, file);
|
|
25227
|
+
const dir = await open6(path11.dirname(file), "r");
|
|
24824
25228
|
try {
|
|
24825
25229
|
await dir.sync();
|
|
24826
25230
|
} finally {
|
|
24827
25231
|
await dir.close();
|
|
24828
25232
|
}
|
|
24829
25233
|
} finally {
|
|
24830
|
-
if (await info3(temporary)) await
|
|
25234
|
+
if (await info3(temporary)) await rm4(temporary);
|
|
24831
25235
|
}
|
|
24832
25236
|
}
|
|
24833
25237
|
async function verifyVersion(root, record2) {
|
|
24834
25238
|
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 || !
|
|
25239
|
+
if (!directory?.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63) fail3("claude_installed_files_invalid");
|
|
25240
|
+
const marker = await privateRead4(path11.join(root, "installation.json")), payload = await inspectRuntimePackage(root);
|
|
25241
|
+
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
25242
|
return marker;
|
|
24839
25243
|
}
|
|
24840
25244
|
function mcpDefinition(record2, nodeCommand) {
|
|
24841
25245
|
return {
|
|
24842
25246
|
type: "stdio",
|
|
24843
25247
|
command: nodeCommand,
|
|
24844
|
-
args: [
|
|
25248
|
+
args: [path11.join(record2.versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", record2.configFile, "--host", "claude-code"]
|
|
24845
25249
|
};
|
|
24846
25250
|
}
|
|
24847
25251
|
function skillBody(payload, sourceName, name) {
|
|
24848
25252
|
const file = payload.files.find((f2) => f2.path === "skills/" + sourceName + "/SKILL.md");
|
|
24849
|
-
if (!file)
|
|
25253
|
+
if (!file) fail3("package_incomplete");
|
|
24850
25254
|
const body = file.body.toString("utf8");
|
|
24851
|
-
if (!body.startsWith("---\n") || !body.includes("\nname: " + sourceName + "\n"))
|
|
25255
|
+
if (!body.startsWith("---\n") || !body.includes("\nname: " + sourceName + "\n")) fail3("package_incomplete");
|
|
24852
25256
|
return body.replace("\nname: " + sourceName + "\n", "\nname: " + name + "\n");
|
|
24853
25257
|
}
|
|
24854
25258
|
async function observedSkill(plan, record2, { allowBefore = false } = {}) {
|
|
24855
25259
|
const directory = await info3(plan.root);
|
|
24856
25260
|
if (!directory) return false;
|
|
24857
|
-
if (!directory.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63)
|
|
25261
|
+
if (!directory.isDirectory() || directory.isSymbolicLink() || directory.uid !== process.getuid?.() || directory.mode & 63) fail3("claude_skill_requires_review");
|
|
24858
25262
|
const names = await readdir5(plan.root);
|
|
24859
|
-
if (names.some((n) => !["SKILL.md", "promptframe-installation.json"].includes(n)))
|
|
24860
|
-
const marker = await
|
|
25263
|
+
if (names.some((n) => !["SKILL.md", "promptframe-installation.json"].includes(n))) fail3("claude_skill_requires_review");
|
|
25264
|
+
const marker = await privateRead4(path11.join(plan.root, "promptframe-installation.json")), file = path11.join(plan.root, "SKILL.md"), s3 = await info3(file);
|
|
24861
25265
|
if (!marker || marker.host !== "claude-code" || marker.profile !== record2.profile || marker.configFile !== record2.configFile || marker.name !== plan.name)
|
|
24862
|
-
|
|
25266
|
+
fail3("claude_skill_requires_review");
|
|
24863
25267
|
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
|
-
|
|
25268
|
+
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size > 256 * 1024) fail3("claude_skill_requires_review");
|
|
25269
|
+
const digest4 = hash5(await readFile7(file));
|
|
25270
|
+
if (digest4 === plan.sha256 && marker.sha256 === plan.sha256) return true;
|
|
25271
|
+
if (allowBefore && (digest4 === plan.beforeSHA || digest4 === plan.sha256) && marker.sha256 === plan.beforeSHA) return false;
|
|
25272
|
+
fail3("claude_skill_requires_review");
|
|
24869
25273
|
}
|
|
24870
25274
|
async function installClaudeMcpFallback({
|
|
24871
25275
|
sourceRoot,
|
|
@@ -24879,47 +25283,48 @@ async function installClaudeMcpFallback({
|
|
|
24879
25283
|
nodeCommand,
|
|
24880
25284
|
writeSkill = atomicText
|
|
24881
25285
|
}) {
|
|
24882
|
-
const payload = await inspectRuntimePackage(
|
|
24883
|
-
await
|
|
24884
|
-
const release = await
|
|
25286
|
+
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");
|
|
25287
|
+
await privateDirectory5(root);
|
|
25288
|
+
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
25289
|
let writeStarted = false, newFiles = 0;
|
|
24886
25290
|
const complete = { host: "claude-code", mode: "mcp-and-skills", profile, configFile: configFile2, serverName, version: payload.version, versionRoot, payloadDigest: payload.payloadDigest };
|
|
24887
25291
|
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 !==
|
|
25292
|
+
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
25293
|
};
|
|
24890
25294
|
try {
|
|
24891
|
-
await
|
|
24892
|
-
let previous = await
|
|
25295
|
+
await privateDirectory5(versions);
|
|
25296
|
+
let previous = await privateRead4(currentFile), pending = await privateRead4(pendingFile);
|
|
24893
25297
|
checkBinding(previous);
|
|
24894
25298
|
checkBinding(pending);
|
|
24895
25299
|
let saved = await readClaudeUserServer(serverName, env);
|
|
24896
25300
|
complete.beforeServer = pending?.beforeServer ?? saved;
|
|
24897
25301
|
const settled = async (record2) => {
|
|
24898
25302
|
const ready2 = await verifyVersion(record2.versionRoot, record2);
|
|
24899
|
-
if (!same(record2.server, mcpDefinition(record2, ready2.nodeCommand)))
|
|
25303
|
+
if (!same(record2.server, mcpDefinition(record2, ready2.nodeCommand))) fail3("claude_installed_files_invalid");
|
|
24900
25304
|
if (!same(saved, record2.server)) return false;
|
|
24901
|
-
if (
|
|
25305
|
+
if (compareVersions2(record2.version, "0.3.1") >= 0) await verifyClaudeFallbackHooks(record2.hostHooks, env);
|
|
25306
|
+
if (!Array.isArray(record2.skills) || record2.skills.length !== 2) fail3("claude_skill_requires_review");
|
|
24902
25307
|
for (const [i, skill] of record2.skills.entries()) {
|
|
24903
25308
|
const name = ["creation-setup", "video-creation"][i] + suffix;
|
|
24904
|
-
if (skill.name !== name || skill.root !==
|
|
24905
|
-
|
|
25309
|
+
if (skill.name !== name || skill.root !== path11.join(claudeConfigRoot(env), "skills", name) || !/^[a-f0-9]{64}$/.test(skill.sha256 ?? ""))
|
|
25310
|
+
fail3("claude_skill_requires_review");
|
|
24906
25311
|
if (!await observedSkill(skill, record2)) return false;
|
|
24907
25312
|
}
|
|
24908
25313
|
return true;
|
|
24909
25314
|
};
|
|
24910
25315
|
if (pending) {
|
|
24911
25316
|
writeStarted = true;
|
|
24912
|
-
if (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest)
|
|
25317
|
+
if (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest) fail3("registration_unconfirmed_keep_existing");
|
|
24913
25318
|
if (pending.phase === "mcp") {
|
|
24914
|
-
if (!await settled(pending))
|
|
24915
|
-
await
|
|
24916
|
-
await
|
|
25319
|
+
if (!await settled(pending)) fail3("registration_unconfirmed_keep_existing");
|
|
25320
|
+
await atomicJSON3(currentFile, pending);
|
|
25321
|
+
await rm4(pendingFile);
|
|
24917
25322
|
previous = pending;
|
|
24918
25323
|
pending = null;
|
|
24919
|
-
} else if (pending.phase !== "skills" || !same(saved, pending.beforeServer))
|
|
25324
|
+
} else if (pending.phase !== "skills" || !same(saved, pending.beforeServer)) fail3("registration_unconfirmed_keep_existing");
|
|
24920
25325
|
}
|
|
24921
25326
|
if (previous && !pending) {
|
|
24922
|
-
if (!await settled(previous))
|
|
25327
|
+
if (!await settled(previous)) fail3("claude_local_registration_unconfirmed");
|
|
24923
25328
|
if (compareVersions2(previous.version, payload.version) >= 0) {
|
|
24924
25329
|
const ready2 = await verifyVersion(previous.versionRoot, previous);
|
|
24925
25330
|
await verifyInstalledRuntime(previous.versionRoot, previous.version, ready2.nodeCommand, { env });
|
|
@@ -24938,15 +25343,15 @@ async function installClaudeMcpFallback({
|
|
|
24938
25343
|
recordedRuntimeRetained: ready2.nodeCommand !== nodeCommand
|
|
24939
25344
|
};
|
|
24940
25345
|
}
|
|
24941
|
-
} else if (saved && !pending)
|
|
25346
|
+
} else if (saved && !pending) fail3("legacy_mcp_entry_requires_review");
|
|
24942
25347
|
if (await info3(versionRoot)) await verifyVersion(versionRoot, complete);
|
|
24943
25348
|
else {
|
|
24944
|
-
await
|
|
25349
|
+
await mkdir5(temporary, { mode: 448 });
|
|
24945
25350
|
for (const file of payload.files) {
|
|
24946
25351
|
signal?.throwIfAborted();
|
|
24947
|
-
const dest =
|
|
24948
|
-
await
|
|
24949
|
-
const fd = await
|
|
25352
|
+
const dest = path11.join(temporary, file.path);
|
|
25353
|
+
await mkdir5(path11.dirname(dest), { recursive: true, mode: 448 });
|
|
25354
|
+
const fd = await open6(dest, "wx", 384);
|
|
24950
25355
|
try {
|
|
24951
25356
|
await fd.writeFile(file.body);
|
|
24952
25357
|
await fd.sync();
|
|
@@ -24955,33 +25360,33 @@ async function installClaudeMcpFallback({
|
|
|
24955
25360
|
}
|
|
24956
25361
|
}
|
|
24957
25362
|
await checkRuntime(temporary, payload.version);
|
|
24958
|
-
await
|
|
25363
|
+
await atomicJSON3(path11.join(temporary, "installation.json"), { ...complete, nodeCommand });
|
|
24959
25364
|
signal?.throwIfAborted();
|
|
24960
|
-
await
|
|
25365
|
+
await rename5(temporary, versionRoot);
|
|
24961
25366
|
newFiles = payload.files.length;
|
|
24962
25367
|
}
|
|
24963
25368
|
const ready = await verifyVersion(versionRoot, complete);
|
|
24964
25369
|
complete.server = mcpDefinition(complete, ready.nodeCommand);
|
|
24965
25370
|
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?.())
|
|
25371
|
+
const skillRoot = path11.join(claudeConfigRoot(env), "skills");
|
|
25372
|
+
await mkdir5(skillRoot, { recursive: true, mode: 448 });
|
|
25373
|
+
const parent = await lstat8(skillRoot);
|
|
25374
|
+
if (!parent.isDirectory() || parent.isSymbolicLink() || parent.uid !== process.getuid?.()) fail3("claude_skill_requires_review");
|
|
24970
25375
|
const plans = [];
|
|
24971
25376
|
for (const sourceName of ["creation-setup", "video-creation"]) {
|
|
24972
|
-
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root:
|
|
25377
|
+
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root: path11.join(skillRoot, name), sha256: hash5(body) };
|
|
24973
25378
|
if (pending) {
|
|
24974
25379
|
const old = pending.skills?.find((s3) => s3.name === name);
|
|
24975
|
-
if (!old || old.root !== skill.root || old.sha256 !== skill.sha256)
|
|
25380
|
+
if (!old || old.root !== skill.root || old.sha256 !== skill.sha256) fail3("registration_unconfirmed_keep_existing");
|
|
24976
25381
|
plans.push({ ...old, body });
|
|
24977
25382
|
} else {
|
|
24978
25383
|
const existing = await info3(skill.root);
|
|
24979
25384
|
let beforeSHA = null;
|
|
24980
25385
|
if (existing) {
|
|
24981
|
-
const marker = await
|
|
24982
|
-
if (!marker || marker.profile !== profile || marker.configFile !== configFile2 || marker.name !== name)
|
|
25386
|
+
const marker = await privateRead4(path11.join(skill.root, "promptframe-installation.json"));
|
|
25387
|
+
if (!marker || marker.profile !== profile || marker.configFile !== configFile2 || marker.name !== name) fail3("claude_skill_requires_review");
|
|
24983
25388
|
const old = { ...skill, sha256: marker.sha256 };
|
|
24984
|
-
if (!await observedSkill(old, complete))
|
|
25389
|
+
if (!await observedSkill(old, complete)) fail3("claude_skill_requires_review");
|
|
24985
25390
|
beforeSHA = marker.sha256;
|
|
24986
25391
|
}
|
|
24987
25392
|
plans.push({ ...skill, beforeSHA, body });
|
|
@@ -24989,7 +25394,7 @@ async function installClaudeMcpFallback({
|
|
|
24989
25394
|
}
|
|
24990
25395
|
complete.skills = plans.map(({ body, ...p2 }) => p2);
|
|
24991
25396
|
if (!pending) {
|
|
24992
|
-
await
|
|
25397
|
+
await atomicJSON3(pendingFile, { ...complete, phase: "skills" });
|
|
24993
25398
|
writeStarted = true;
|
|
24994
25399
|
}
|
|
24995
25400
|
for (const plan of plans) {
|
|
@@ -24997,22 +25402,23 @@ async function installClaudeMcpFallback({
|
|
|
24997
25402
|
if (await info3(plan.root)) {
|
|
24998
25403
|
if (await observedSkill(plan, complete, { allowBefore: true })) continue;
|
|
24999
25404
|
} else {
|
|
25000
|
-
if (plan.beforeSHA !== null)
|
|
25405
|
+
if (plan.beforeSHA !== null) fail3("claude_skill_requires_review");
|
|
25001
25406
|
await claimSkillDirectory(plan.root);
|
|
25002
|
-
await
|
|
25407
|
+
await atomicJSON3(path11.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: null });
|
|
25003
25408
|
}
|
|
25004
|
-
await writeSkill(
|
|
25005
|
-
await
|
|
25409
|
+
await writeSkill(path11.join(plan.root, "SKILL.md"), plan.body);
|
|
25410
|
+
await atomicJSON3(path11.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: plan.sha256 });
|
|
25006
25411
|
}
|
|
25007
25412
|
signal?.throwIfAborted();
|
|
25008
|
-
if (
|
|
25009
|
-
await
|
|
25413
|
+
if (compareVersions2(payload.version, "0.3.1") >= 0) complete.hostHooks = await registerClaudeFallbackHooks({ record: complete, root, env, nodeCommand: ready.nodeCommand, signal });
|
|
25414
|
+
if (!same(await readClaudeUserServer(serverName, env), complete.beforeServer)) fail3("claude_local_registration_changed");
|
|
25415
|
+
await atomicJSON3(pendingFile, { ...complete, phase: "mcp" });
|
|
25010
25416
|
writeStarted = true;
|
|
25011
25417
|
await runClaude(["mcp", "add-json", "--scope", "user", serverName, JSON.stringify(complete.server)]);
|
|
25012
25418
|
saved = await readClaudeUserServer(serverName, env);
|
|
25013
|
-
if (!await settled(complete))
|
|
25014
|
-
await
|
|
25015
|
-
await
|
|
25419
|
+
if (!await settled(complete)) fail3("registration_unconfirmed_keep_existing");
|
|
25420
|
+
await atomicJSON3(currentFile, complete);
|
|
25421
|
+
await rm4(pendingFile);
|
|
25016
25422
|
return {
|
|
25017
25423
|
...complete,
|
|
25018
25424
|
currentFile,
|
|
@@ -25026,27 +25432,28 @@ async function installClaudeMcpFallback({
|
|
|
25026
25432
|
requestedVersion: payload.version,
|
|
25027
25433
|
versionStatus: "current"
|
|
25028
25434
|
};
|
|
25029
|
-
} catch (
|
|
25030
|
-
if (writeStarted)
|
|
25031
|
-
if (
|
|
25032
|
-
|
|
25435
|
+
} catch (error4) {
|
|
25436
|
+
if (writeStarted) fail3("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
25437
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
25438
|
+
fail3(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
25033
25439
|
} finally {
|
|
25034
|
-
await
|
|
25440
|
+
await rm4(temporary, { recursive: true, force: true });
|
|
25035
25441
|
await release();
|
|
25036
25442
|
}
|
|
25037
25443
|
}
|
|
25038
25444
|
|
|
25039
25445
|
// lib/claude-installation.mjs
|
|
25040
|
-
var { info: info4, privateDirectory:
|
|
25446
|
+
var { info: info4, privateDirectory: privateDirectory6, privateRead: privateRead5, atomicJSON: atomicJSON4, acquire: acquire4, runNode: runNode2, checkInstalledRuntime: checkInstalledRuntime2, compareVersions: compareVersions3, validProfile: validProfile2 } = installationFiles;
|
|
25041
25447
|
var effectiveRoot = (plugin) => plugin.readFromFolder ?? plugin.installPath;
|
|
25448
|
+
var effectiveVersion = (plugin) => plugin.readFromFolder !== void 0 ? plugin.folderVersion : plugin.version;
|
|
25042
25449
|
var ClaudeInstallationError = class extends CreationClientError {
|
|
25043
25450
|
constructor(code, details) {
|
|
25044
25451
|
super("installation." + code);
|
|
25045
25452
|
this.details = details;
|
|
25046
25453
|
}
|
|
25047
25454
|
};
|
|
25048
|
-
var claudeInstallationDetails = (
|
|
25049
|
-
var
|
|
25455
|
+
var claudeInstallationDetails = (error4) => error4 instanceof ClaudeInstallationError ? error4.details : void 0;
|
|
25456
|
+
var fail4 = (code, details) => {
|
|
25050
25457
|
throw new ClaudeInstallationError(code, details);
|
|
25051
25458
|
};
|
|
25052
25459
|
async function jsonCommand(run, args2) {
|
|
@@ -25056,9 +25463,9 @@ async function jsonCommand(run, args2) {
|
|
|
25056
25463
|
if (typeof body !== "string" || Buffer.byteLength(body) > 2 * 1024 * 1024) throw Error();
|
|
25057
25464
|
value2 = JSON.parse(body);
|
|
25058
25465
|
} catch {
|
|
25059
|
-
|
|
25466
|
+
fail4("claude_local_registration_unconfirmed");
|
|
25060
25467
|
}
|
|
25061
|
-
if (!Array.isArray(value2) || value2.length > 1024)
|
|
25468
|
+
if (!Array.isArray(value2) || value2.length > 1024) fail4("claude_local_registration_unconfirmed");
|
|
25062
25469
|
return value2;
|
|
25063
25470
|
}
|
|
25064
25471
|
async function registrations(run, pluginName, marketplace, root) {
|
|
@@ -25067,17 +25474,17 @@ async function registrations(run, pluginName, marketplace, root) {
|
|
|
25067
25474
|
jsonCommand(run, ["plugin", "marketplace", "list", "--json"])
|
|
25068
25475
|
]);
|
|
25069
25476
|
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
|
-
|
|
25477
|
+
fail4("claude_local_registration_unconfirmed");
|
|
25071
25478
|
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
|
-
|
|
25479
|
+
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) || !/^\d+\.\d+\.\d+$/.test(p2.folderVersion ?? ""))))
|
|
25480
|
+
fail4("claude_existing_registration_requires_review");
|
|
25074
25481
|
const found = markets.filter((p2) => p2?.name === marketplace);
|
|
25075
25482
|
if (found.length > 1 || found.some((p2) => p2.source !== "directory" || p2.path !== root || p2.installLocation !== root))
|
|
25076
|
-
|
|
25483
|
+
fail4("claude_existing_registration_requires_review");
|
|
25077
25484
|
return { plugin: related[0], market: found[0] };
|
|
25078
25485
|
}
|
|
25079
25486
|
async function legacyUserMcp(env, serverName) {
|
|
25080
|
-
if (await readClaudeUserServer(serverName, env))
|
|
25487
|
+
if (await readClaudeUserServer(serverName, env)) fail4("legacy_mcp_entry_requires_review");
|
|
25081
25488
|
}
|
|
25082
25489
|
function transport(serverName, configFile2, command2 = process.execPath) {
|
|
25083
25490
|
return { mcpServers: { [serverName]: {
|
|
@@ -25088,30 +25495,32 @@ function transport(serverName, configFile2, command2 = process.execPath) {
|
|
|
25088
25495
|
async function verifyVersion2(root, { version: version3, profile, configFile: configFile2, payloadDigest, pluginName, serverName }) {
|
|
25089
25496
|
const directory = await info4(root);
|
|
25090
25497
|
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)
|
|
25498
|
+
fail4("claude_installed_files_invalid");
|
|
25499
|
+
const ready = await privateRead5(path12.join(root, "installation.json"));
|
|
25500
|
+
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
25501
|
const actual = await inspectRuntimePackage(root);
|
|
25095
|
-
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path:
|
|
25096
|
-
|
|
25097
|
-
const manifest = JSON.parse(await
|
|
25502
|
+
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))) !== JSON.stringify(ready.files))
|
|
25503
|
+
fail4("claude_installed_files_invalid");
|
|
25504
|
+
const manifest = JSON.parse(await readFile8(path12.join(root, ".claude-plugin/plugin.json"), "utf8"));
|
|
25098
25505
|
if (manifest.name !== pluginName || manifest.version !== version3 || manifest.skills !== "./skills/" || manifest.mcpServers !== "./.claude-mcp.json")
|
|
25099
|
-
|
|
25506
|
+
fail4("claude_installed_files_invalid");
|
|
25100
25507
|
let runtimeCommand;
|
|
25101
25508
|
for (const file of [".mcp.json", ".claude-mcp.json"]) {
|
|
25102
|
-
const mcp = JSON.parse(await
|
|
25509
|
+
const mcp = JSON.parse(await readFile8(path12.join(root, file), "utf8"));
|
|
25103
25510
|
const command2 = mcp.mcpServers?.[serverName]?.command;
|
|
25104
|
-
if (!
|
|
25511
|
+
if (!path12.isAbsolute(command2 ?? "") || runtimeCommand !== void 0 && command2 !== runtimeCommand || JSON.stringify(mcp) !== JSON.stringify(transport(serverName, configFile2, command2))) fail4("claude_installed_files_invalid");
|
|
25105
25512
|
runtimeCommand = command2;
|
|
25106
25513
|
}
|
|
25514
|
+
if (compareVersions3(version3, "0.3.1") >= 0 && JSON.stringify(manifest.hooks) !== JSON.stringify(claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand: runtimeCommand })))
|
|
25515
|
+
fail4("claude_installed_files_invalid");
|
|
25107
25516
|
return { ...ready, runtimeCommand };
|
|
25108
25517
|
}
|
|
25109
25518
|
async function installForClaudeUser(options = {}) {
|
|
25110
25519
|
const profile = options.profile ?? "default", env = options.env ?? process.env;
|
|
25111
25520
|
validProfile2(profile);
|
|
25112
|
-
const modeRoot =
|
|
25113
|
-
await
|
|
25114
|
-
const release = await
|
|
25521
|
+
const modeRoot = path12.resolve(env.XDG_DATA_HOME ?? path12.join(homedir9(), ".local/share"), "promptframe-creation", profile, "claude-code-mode");
|
|
25522
|
+
await privateDirectory6(modeRoot);
|
|
25523
|
+
const release = await acquire4(modeRoot, options.signal);
|
|
25115
25524
|
try {
|
|
25116
25525
|
return await installClaudeUserLocked(options);
|
|
25117
25526
|
} finally {
|
|
@@ -25131,58 +25540,58 @@ async function installClaudeUserLocked({
|
|
|
25131
25540
|
nodeCommand = process.execPath
|
|
25132
25541
|
} = {}) {
|
|
25133
25542
|
validProfile2(profile);
|
|
25134
|
-
if (!
|
|
25543
|
+
if (!path12.isAbsolute(nodeCommand)) fail4("runtime_command_invalid");
|
|
25135
25544
|
const hostVersion = (await runClaude(["--version"])).trim().match(/^(\d+\.\d+\.\d+) \(Claude Code\)$/);
|
|
25136
|
-
if (!hostVersion || compareVersions3(hostVersion[1], "2.
|
|
25545
|
+
if (!hostVersion || compareVersions3(hostVersion[1], "2.1.295") < 0) fail4("claude_21295_required");
|
|
25137
25546
|
const help = await runClaude(["--help"]);
|
|
25138
|
-
if (typeof help !== "string" || Buffer.byteLength(help) > 128 * 1024)
|
|
25547
|
+
if (typeof help !== "string" || Buffer.byteLength(help) > 128 * 1024) fail4("claude_capabilities_unconfirmed");
|
|
25139
25548
|
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))
|
|
25549
|
+
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");
|
|
25550
|
+
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"));
|
|
25551
|
+
if ((!hasPlugin || fallbackState) && (pluginPending || pluginCurrent)) fail4("registration_unconfirmed_keep_existing");
|
|
25143
25552
|
if (!hasPlugin || fallbackState) {
|
|
25144
|
-
if (!hasMcp)
|
|
25553
|
+
if (!hasMcp) fail4("claude_capabilities_unconfirmed");
|
|
25145
25554
|
return installClaudeMcpFallback({ sourceRoot, profile, env, configFile: configFile2, signal, runClaude, checkRuntime, verifyInstalledRuntime, nodeCommand });
|
|
25146
25555
|
}
|
|
25147
|
-
const payload = await inspectRuntimePackage(
|
|
25556
|
+
const payload = await inspectRuntimePackage(path12.resolve(sourceRoot));
|
|
25148
25557
|
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
|
|
25558
|
+
fail4("claude_package_incomplete");
|
|
25559
|
+
const root = path12.resolve(env.XDG_DATA_HOME ?? path12.join(homedir9(), ".local/share"), "promptframe-creation", profile, "claude-code");
|
|
25560
|
+
await privateDirectory6(root);
|
|
25561
|
+
const release = await acquire4(root, signal);
|
|
25153
25562
|
const suffix = profile === "default" ? "" : "-" + profile, pluginName = "promptframe-creation" + suffix, marketplace = "promptframe-creation-user" + suffix, pluginId = pluginName + "@" + marketplace, serverName = "promptframe" + suffix;
|
|
25154
|
-
const versions =
|
|
25563
|
+
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
25564
|
let registrationStarted = false, newFiles = 0;
|
|
25156
25565
|
try {
|
|
25157
25566
|
signal?.throwIfAborted();
|
|
25158
|
-
await
|
|
25159
|
-
await
|
|
25567
|
+
await privateDirectory6(versions);
|
|
25568
|
+
await privateDirectory6(path12.dirname(catalogFile));
|
|
25160
25569
|
await legacyUserMcp(env, serverName);
|
|
25161
|
-
let previous = await
|
|
25570
|
+
let previous = await privateRead5(currentFile), pending = await privateRead5(pendingFile), state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25162
25571
|
const binding = { profile, configFile: configFile2, pluginId, pluginName, serverName, host: "claude-code" };
|
|
25163
25572
|
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 !==
|
|
25573
|
+
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
25574
|
};
|
|
25166
25575
|
checkBinding(previous);
|
|
25167
25576
|
checkBinding(pending);
|
|
25168
25577
|
const runtimeCommands = /* @__PURE__ */ new Map();
|
|
25169
25578
|
const observed = async (record2) => {
|
|
25170
|
-
if (!state.market || !state.plugin || state.plugin.enabled !== true || state.plugin
|
|
25579
|
+
if (!state.market || !state.plugin || state.plugin.enabled !== true || effectiveVersion(state.plugin) !== record2.version || effectiveRoot(state.plugin) !== record2.versionRoot) return false;
|
|
25171
25580
|
const ready = await verifyVersion2(record2.versionRoot, { ...record2, pluginName, serverName });
|
|
25172
25581
|
runtimeCommands.set(record2.versionRoot, ready.runtimeCommand);
|
|
25173
25582
|
return true;
|
|
25174
25583
|
};
|
|
25175
25584
|
if (pending) {
|
|
25176
25585
|
if (await observed(pending)) {
|
|
25177
|
-
await
|
|
25178
|
-
await
|
|
25586
|
+
await atomicJSON4(currentFile, pending);
|
|
25587
|
+
await rm5(pendingFile);
|
|
25179
25588
|
previous = pending;
|
|
25180
25589
|
pending = null;
|
|
25181
25590
|
} else if (pending.phase !== "marketplace" || !state.market || state.plugin)
|
|
25182
|
-
|
|
25591
|
+
fail4("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
25183
25592
|
}
|
|
25184
|
-
if (state.plugin && !previous && !pending)
|
|
25185
|
-
if (previous && !await observed(previous) && !pending)
|
|
25593
|
+
if (state.plugin && !previous && !pending) fail4("claude_existing_registration_requires_review");
|
|
25594
|
+
if (previous && !await observed(previous) && !pending) fail4("claude_local_registration_unconfirmed");
|
|
25186
25595
|
if (previous && compareVersions3(previous.version, payload.version) > 0) {
|
|
25187
25596
|
const recorded = runtimeCommands.get(previous.versionRoot);
|
|
25188
25597
|
await verifyInstalledRuntime(previous.versionRoot, previous.version, recorded, { env });
|
|
@@ -25200,17 +25609,17 @@ async function installClaudeUserLocked({
|
|
|
25200
25609
|
}
|
|
25201
25610
|
const complete = { ...binding, version: payload.version, versionRoot, payloadDigest: payload.payloadDigest };
|
|
25202
25611
|
if (pending && (pending.version !== complete.version || pending.payloadDigest !== complete.payloadDigest))
|
|
25203
|
-
|
|
25612
|
+
fail4("registration_unconfirmed_keep_existing");
|
|
25204
25613
|
if (await info4(versionRoot)) {
|
|
25205
25614
|
const ready = await verifyVersion2(versionRoot, { ...complete, pluginName, serverName });
|
|
25206
25615
|
runtimeCommands.set(versionRoot, ready.runtimeCommand);
|
|
25207
25616
|
} else {
|
|
25208
|
-
await
|
|
25617
|
+
await mkdir6(temporary, { mode: 448 });
|
|
25209
25618
|
for (const file of payload.files) {
|
|
25210
25619
|
signal?.throwIfAborted();
|
|
25211
|
-
const dest =
|
|
25212
|
-
await
|
|
25213
|
-
const fd = await
|
|
25620
|
+
const dest = path12.join(temporary, file.path);
|
|
25621
|
+
await mkdir6(path12.dirname(dest), { recursive: true, mode: 448 });
|
|
25622
|
+
const fd = await open7(dest, "wx", 384);
|
|
25214
25623
|
try {
|
|
25215
25624
|
await fd.writeFile(file.body);
|
|
25216
25625
|
await fd.sync();
|
|
@@ -25218,41 +25627,42 @@ async function installClaudeUserLocked({
|
|
|
25218
25627
|
await fd.close();
|
|
25219
25628
|
}
|
|
25220
25629
|
}
|
|
25221
|
-
const manifest = JSON.parse(await
|
|
25630
|
+
const manifest = JSON.parse(await readFile8(path12.join(temporary, ".claude-plugin/plugin.json"), "utf8"));
|
|
25222
25631
|
manifest.name = pluginName;
|
|
25223
|
-
|
|
25224
|
-
|
|
25632
|
+
if (manifest.hooks) manifest.hooks = claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand });
|
|
25633
|
+
await atomicJSON4(path12.join(temporary, ".claude-plugin/plugin.json"), manifest);
|
|
25634
|
+
for (const file of [".mcp.json", ".claude-mcp.json"]) await atomicJSON4(path12.join(temporary, file), transport(serverName, configFile2, nodeCommand));
|
|
25225
25635
|
await checkRuntime(temporary, payload.version);
|
|
25226
25636
|
const installed = await inspectRuntimePackage(temporary);
|
|
25227
|
-
await
|
|
25637
|
+
await atomicJSON4(path12.join(temporary, "installation.json"), {
|
|
25228
25638
|
...binding,
|
|
25229
25639
|
version: payload.version,
|
|
25230
25640
|
payloadDigest: payload.payloadDigest,
|
|
25231
|
-
files: installed.files.map(({ path:
|
|
25641
|
+
files: installed.files.map(({ path: path14, bytes: bytes2, sha256 }) => ({ path: path14, bytes: bytes2, sha256 }))
|
|
25232
25642
|
});
|
|
25233
25643
|
signal?.throwIfAborted();
|
|
25234
|
-
await
|
|
25644
|
+
await rename6(temporary, versionRoot);
|
|
25235
25645
|
newFiles = payload.files.length;
|
|
25236
25646
|
}
|
|
25237
25647
|
if (newFiles === 0) await verifyInstalledRuntime(versionRoot, payload.version, runtimeCommands.get(versionRoot), { env });
|
|
25238
25648
|
const already = previous?.version === payload.version && previous.payloadDigest === payload.payloadDigest && await observed(complete);
|
|
25239
25649
|
if (!already) {
|
|
25240
|
-
await
|
|
25650
|
+
await atomicJSON4(catalogFile, { name: marketplace, owner: { name: "PromptFrame" }, plugins: [{ name: pluginName, source: "./versions/" + payload.version }] });
|
|
25241
25651
|
if (!state.market) {
|
|
25242
|
-
if (pending)
|
|
25243
|
-
await
|
|
25652
|
+
if (pending) fail4("registration_unconfirmed_keep_existing");
|
|
25653
|
+
await atomicJSON4(pendingFile, { ...complete, phase: "marketplace" });
|
|
25244
25654
|
registrationStarted = true;
|
|
25245
25655
|
await runClaude(["plugin", "marketplace", "add", root, "--scope", "user", "--json"]);
|
|
25246
25656
|
state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25247
|
-
if (!state.market)
|
|
25657
|
+
if (!state.market) fail4("claude_registration_unconfirmed");
|
|
25248
25658
|
}
|
|
25249
|
-
await
|
|
25659
|
+
await atomicJSON4(pendingFile, { ...complete, phase: "plugin" });
|
|
25250
25660
|
registrationStarted = true;
|
|
25251
25661
|
await runClaude(["plugin", "install", pluginId, "--scope", "user", "--json"]);
|
|
25252
25662
|
state = await registrations(runClaude, pluginName, marketplace, root);
|
|
25253
|
-
if (!await observed(complete))
|
|
25254
|
-
await
|
|
25255
|
-
await
|
|
25663
|
+
if (!await observed(complete)) fail4("claude_registration_unconfirmed");
|
|
25664
|
+
await atomicJSON4(currentFile, complete);
|
|
25665
|
+
await rm5(pendingFile);
|
|
25256
25666
|
}
|
|
25257
25667
|
return {
|
|
25258
25668
|
...complete,
|
|
@@ -25266,24 +25676,24 @@ async function installClaudeUserLocked({
|
|
|
25266
25676
|
requestedVersion: payload.version,
|
|
25267
25677
|
recordedRuntimeRetained: runtimeCommands.has(versionRoot) && runtimeCommands.get(versionRoot) !== nodeCommand
|
|
25268
25678
|
};
|
|
25269
|
-
} catch (
|
|
25270
|
-
if (registrationStarted)
|
|
25271
|
-
...claudeErrorDetails(
|
|
25679
|
+
} catch (error4) {
|
|
25680
|
+
if (registrationStarted) fail4("registration_unconfirmed_keep_existing", {
|
|
25681
|
+
...claudeErrorDetails(error4),
|
|
25272
25682
|
phase: "registration_observation",
|
|
25273
25683
|
localRegistrationState: "unknown",
|
|
25274
25684
|
action: "inspect_same_registration_no_second_add"
|
|
25275
25685
|
});
|
|
25276
|
-
if (
|
|
25277
|
-
|
|
25686
|
+
if (error4 instanceof CreationClientError) throw error4;
|
|
25687
|
+
fail4(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
25278
25688
|
} finally {
|
|
25279
|
-
await
|
|
25689
|
+
await rm5(temporary, { recursive: true, force: true });
|
|
25280
25690
|
await release();
|
|
25281
25691
|
}
|
|
25282
25692
|
}
|
|
25283
25693
|
|
|
25284
25694
|
// lib/cli.mjs
|
|
25285
25695
|
import { fileURLToPath } from "node:url";
|
|
25286
|
-
import
|
|
25696
|
+
import path13 from "node:path";
|
|
25287
25697
|
var args = process.argv.slice(2);
|
|
25288
25698
|
var command = args.shift();
|
|
25289
25699
|
var value = (key) => {
|
|
@@ -25291,7 +25701,7 @@ var value = (key) => {
|
|
|
25291
25701
|
return i < 0 ? void 0 : args[i + 1];
|
|
25292
25702
|
};
|
|
25293
25703
|
var log = (value2) => process.stdout.write(JSON.stringify(value2) + "\n");
|
|
25294
|
-
var configFile = () => value("--config") ?
|
|
25704
|
+
var configFile = () => value("--config") ? path13.resolve(value("--config")) : profileCredentialsPath(value("--profile") ?? "default");
|
|
25295
25705
|
async function probe(credentials) {
|
|
25296
25706
|
const client = await connectPlatform(credentials, { host: resolveHostIdentity({ host: value("--host") }) });
|
|
25297
25707
|
try {
|
|
@@ -25396,7 +25806,7 @@ async function setup({ silent = false } = {}) {
|
|
|
25396
25806
|
version: 1,
|
|
25397
25807
|
endpoint,
|
|
25398
25808
|
token,
|
|
25399
|
-
clientId: existing?.clientId ??
|
|
25809
|
+
clientId: existing?.clientId ?? randomBytes7(24).toString("base64url"),
|
|
25400
25810
|
clientName: value("--name") ?? existing?.clientName ?? (resolveHostIdentity({ host: value("--host") }).kind === "claude-code" ? "Claude Code PromptFrame" : "Codex PromptFrame"),
|
|
25401
25811
|
createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
25402
25812
|
};
|
|
@@ -25431,14 +25841,14 @@ async function bridge() {
|
|
|
25431
25841
|
resolvedVersion: value("--resolved-runtime-version"),
|
|
25432
25842
|
signal: startup.signal,
|
|
25433
25843
|
hostKind: identity.kind,
|
|
25434
|
-
cacheRoot:
|
|
25844
|
+
cacheRoot: path13.join(path13.dirname(configFile()), "runtime-cache")
|
|
25435
25845
|
});
|
|
25436
25846
|
startup.signal.throwIfAborted();
|
|
25437
|
-
} catch (
|
|
25847
|
+
} catch (error4) {
|
|
25438
25848
|
await client?.close().catch(() => {
|
|
25439
25849
|
});
|
|
25440
25850
|
if (startup.signal.aborted) throw new CreationClientError("creation.runtime_selection_interrupted");
|
|
25441
|
-
throw
|
|
25851
|
+
throw error4;
|
|
25442
25852
|
} finally {
|
|
25443
25853
|
process.removeListener("SIGINT", abort);
|
|
25444
25854
|
process.removeListener("SIGTERM", abort);
|
|
@@ -25449,6 +25859,7 @@ async function bridge() {
|
|
|
25449
25859
|
process.exitCode = result.code;
|
|
25450
25860
|
return;
|
|
25451
25861
|
}
|
|
25862
|
+
const hostSession = identity.kind === "claude-code" ? await createClaudeHostSession({ configFile: configFile() }) : void 0;
|
|
25452
25863
|
const server = new Server(
|
|
25453
25864
|
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
25454
25865
|
{ capabilities: {
|
|
@@ -25463,6 +25874,7 @@ async function bridge() {
|
|
|
25463
25874
|
), host = createHostCallBridge(client, {
|
|
25464
25875
|
credentials,
|
|
25465
25876
|
host: identity,
|
|
25877
|
+
hostSession,
|
|
25466
25878
|
onCatalogChange: () => server.sendToolListChanged(),
|
|
25467
25879
|
onKnowledgeChange: (kind) => kind === "resources" ? server.sendResourceListChanged() : server.sendPromptListChanged()
|
|
25468
25880
|
});
|
|
@@ -25474,11 +25886,11 @@ async function bridge() {
|
|
|
25474
25886
|
const knowledgeHandler = (schema, method) => server.setRequestHandler(schema, async (request) => {
|
|
25475
25887
|
try {
|
|
25476
25888
|
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 ?
|
|
25889
|
+
} catch (error4) {
|
|
25890
|
+
const remote = error4?.data?.errorCode;
|
|
25891
|
+
const code = error4 instanceof CreationClientError ? error4.message : typeof remote === "string" && /^(?:creation|creative_skill)\.[a-z0-9_.:-]{1,160}$/.test(remote) ? remote : "creation.connection_unresolved";
|
|
25892
|
+
const knownRemote = typeof remote === "string" && code === remote && typeof error4.code === "number" && Object.values(ErrorCode).includes(error4.code);
|
|
25893
|
+
throw new McpError(knownRemote ? error4.code : error4 instanceof CreationClientError ? ErrorCode.InvalidParams : ErrorCode.InternalError, code, { errorCode: code });
|
|
25482
25894
|
}
|
|
25483
25895
|
});
|
|
25484
25896
|
if (upstream.resources) {
|
|
@@ -25500,7 +25912,7 @@ async function bridge() {
|
|
|
25500
25912
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
25501
25913
|
try {
|
|
25502
25914
|
return await host.call(request.params);
|
|
25503
|
-
} catch (
|
|
25915
|
+
} catch (error4) {
|
|
25504
25916
|
return {
|
|
25505
25917
|
isError: true,
|
|
25506
25918
|
content: [
|
|
@@ -25508,8 +25920,9 @@ async function bridge() {
|
|
|
25508
25920
|
type: "text",
|
|
25509
25921
|
text: JSON.stringify({
|
|
25510
25922
|
success: false,
|
|
25511
|
-
errorCode:
|
|
25512
|
-
|
|
25923
|
+
errorCode: error4 instanceof CreationClientError ? error4.message : "creation.connection_unresolved",
|
|
25924
|
+
...error4 instanceof CreationClientError && error4.message === "creation.host_session_changed" ? { effectStatus: "unknown", automaticReplayAllowed: false } : {},
|
|
25925
|
+
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
25926
|
})
|
|
25514
25927
|
}
|
|
25515
25928
|
]
|
|
@@ -25578,6 +25991,7 @@ try {
|
|
|
25578
25991
|
process.removeListener("SIGTERM", abort);
|
|
25579
25992
|
}
|
|
25580
25993
|
} else if (command === "bridge") await bridge();
|
|
25994
|
+
else if (command === "claude-host-hook") await runClaudeHostHook({ configFile: configFile() });
|
|
25581
25995
|
else if (command === "--version") process.stdout.write(CLIENT_VERSION + "\n");
|
|
25582
25996
|
else if (command === "status") {
|
|
25583
25997
|
const saved = await readCredentials(configFile());
|
|
@@ -25589,19 +26003,19 @@ try {
|
|
|
25589
26003
|
});
|
|
25590
26004
|
} else if (command === "help" || command === "--help" || !command) {
|
|
25591
26005
|
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.
|
|
26006
|
+
"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
26007
|
);
|
|
25594
26008
|
} else throw new CreationClientError("command.unknown");
|
|
25595
|
-
} catch (
|
|
26009
|
+
} catch (error4) {
|
|
25596
26010
|
process.stderr.write(
|
|
25597
26011
|
JSON.stringify({
|
|
25598
|
-
...installationErrorDetails(
|
|
25599
|
-
...claudeInstallationDetails(
|
|
25600
|
-
...claudeErrorDetails(
|
|
25601
|
-
...fallbackErrorDetails(
|
|
25602
|
-
...bridgeErrorDetails(
|
|
25603
|
-
...runtimeErrorDetails(
|
|
25604
|
-
error:
|
|
26012
|
+
...installationErrorDetails(error4),
|
|
26013
|
+
...claudeInstallationDetails(error4),
|
|
26014
|
+
...claudeErrorDetails(error4),
|
|
26015
|
+
...fallbackErrorDetails(error4),
|
|
26016
|
+
...bridgeErrorDetails(error4),
|
|
26017
|
+
...runtimeErrorDetails(error4),
|
|
26018
|
+
error: error4 instanceof CreationClientError ? error4.message : "creation.connection_failed"
|
|
25605
26019
|
}) + "\n"
|
|
25606
26020
|
);
|
|
25607
26021
|
process.exitCode = 1;
|