@promptframe/creation 0.3.10 → 0.3.12
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 +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +7 -1
- package/dist/cli.mjs +1266 -687
- package/docs/development.md +1 -0
- package/docs/install-guidance.json +1 -1
- package/docs/installing.md +3 -3
- package/docs/local-account-directory.md +51 -0
- package/docs/releases/0.3.11.md +9 -0
- package/lib/account-bridge.mjs +132 -0
- package/lib/cli.mjs +48 -15
- package/lib/connection.mjs +32 -1
- package/lib/host-context.mjs +19 -6
- package/lib/local-accounts.mjs +291 -0
- package/lib/version.mjs +1 -1
- package/package.json +2 -2
- 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, constants8) {
|
|
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, constants8);
|
|
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, constants8) {
|
|
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, constants8);
|
|
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(error5) {
|
|
474
474
|
super();
|
|
475
|
-
this.error =
|
|
475
|
+
this.error = error5;
|
|
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, constants8) {
|
|
496
|
+
this.code = optimizeExpr(this.code, names, constants8);
|
|
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, constants8) {
|
|
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, constants8))
|
|
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, constants8) {
|
|
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, constants8);
|
|
586
|
+
if (!(super.optimizeNames(names, constants8) || this.else))
|
|
587
587
|
return;
|
|
588
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
588
|
+
this.condition = optimizeExpr(this.condition, names, constants8);
|
|
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, constants8) {
|
|
612
|
+
if (!super.optimizeNames(names, constants8))
|
|
613
613
|
return;
|
|
614
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
614
|
+
this.iteration = optimizeExpr(this.iteration, names, constants8);
|
|
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, constants8) {
|
|
651
|
+
if (!super.optimizeNames(names, constants8))
|
|
652
652
|
return;
|
|
653
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
653
|
+
this.iterable = optimizeExpr(this.iterable, names, constants8);
|
|
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, constants8) {
|
|
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, constants8);
|
|
698
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants8);
|
|
699
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants8);
|
|
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(error5) {
|
|
713
713
|
super();
|
|
714
|
-
this.error =
|
|
714
|
+
this.error = error5;
|
|
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 error5 = this.name("e");
|
|
906
|
+
this._currNode = node2.catch = new Catch(error5);
|
|
907
|
+
catchCode(error5);
|
|
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(error5) {
|
|
917
|
+
return this._leafNode(new Throw(error5));
|
|
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, constants8) {
|
|
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 = constants8[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 && constants8[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 hash7 = {};
|
|
1062
1062
|
for (const item of arr)
|
|
1063
|
-
|
|
1064
|
-
return
|
|
1063
|
+
hash7[item] = true;
|
|
1064
|
+
return hash7;
|
|
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, error5 = 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, error5, 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, error5 = 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, error5, 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, error5, 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, error5, errorPaths);
|
|
1343
1343
|
}
|
|
1344
|
-
function errorObject(cxt,
|
|
1344
|
+
function errorObject(cxt, error5, 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, error5, 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(path21) {
|
|
3263
|
+
let input = path21;
|
|
3264
3264
|
const output = [];
|
|
3265
3265
|
let nextSlash = -1;
|
|
3266
3266
|
let len = 0;
|
|
@@ -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 path21 = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
|
|
3673
|
+
wsComponent.path = path21 && path21 !== "/" ? path21 : 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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
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 error5 = {
|
|
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: error5,
|
|
6569
6569
|
code(cxt) {
|
|
6570
6570
|
const { gen, data, schema, parentSchema, it: it2 } = cxt;
|
|
6571
6571
|
const { oneOf } = parentSchema;
|
|
@@ -6890,7 +6890,7 @@ var require_formats = __commonJS({
|
|
|
6890
6890
|
}
|
|
6891
6891
|
exports.fullFormats = {
|
|
6892
6892
|
// date: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
6893
|
-
date: fmtDef(
|
|
6893
|
+
date: fmtDef(date5, compareDate),
|
|
6894
6894
|
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
6895
6895
|
time: fmtDef(getTime(true), compareTime),
|
|
6896
6896
|
"date-time": fmtDef(getDateTime(true), compareDateTime),
|
|
@@ -6956,7 +6956,7 @@ var require_formats = __commonJS({
|
|
|
6956
6956
|
}
|
|
6957
6957
|
var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
6958
6958
|
var DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6959
|
-
function
|
|
6959
|
+
function date5(str) {
|
|
6960
6960
|
const matches = DATE.exec(str);
|
|
6961
6961
|
if (!matches)
|
|
6962
6962
|
return false;
|
|
@@ -7025,7 +7025,7 @@ var require_formats = __commonJS({
|
|
|
7025
7025
|
const time3 = getTime(strictTimeZone);
|
|
7026
7026
|
return function date_time(str) {
|
|
7027
7027
|
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
7028
|
-
return dateTime.length === 2 &&
|
|
7028
|
+
return dateTime.length === 2 && date5(dateTime[0]) && time3(dateTime[1]);
|
|
7029
7029
|
};
|
|
7030
7030
|
}
|
|
7031
7031
|
function compareDateTime(dt1, dt2) {
|
|
@@ -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 error5 = {
|
|
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: error5,
|
|
7110
7110
|
code(cxt) {
|
|
7111
7111
|
const { gen, data, schemaCode, keyword, it: it2 } = cxt;
|
|
7112
7112
|
const { opts, self } = it2;
|
|
@@ -7347,15 +7347,15 @@ function normalizeEndpoint(input) {
|
|
|
7347
7347
|
if (base.endsWith("/api")) return base + "/mcp";
|
|
7348
7348
|
throw new CreationClientError("endpoint.api_base_required");
|
|
7349
7349
|
}
|
|
7350
|
-
var secure = async (file,
|
|
7350
|
+
var secure = async (file, directory3 = false) => {
|
|
7351
7351
|
let info5;
|
|
7352
7352
|
try {
|
|
7353
7353
|
info5 = await lstat(file);
|
|
7354
|
-
} catch (
|
|
7355
|
-
if (
|
|
7356
|
-
throw
|
|
7354
|
+
} catch (error5) {
|
|
7355
|
+
if (error5.code === "ENOENT") return null;
|
|
7356
|
+
throw error5;
|
|
7357
7357
|
}
|
|
7358
|
-
if (info5.isSymbolicLink() || !(
|
|
7358
|
+
if (info5.isSymbolicLink() || !(directory3 ? info5.isDirectory() : info5.isFile()) || info5.uid !== process.getuid?.() || (info5.mode & 63) !== 0)
|
|
7359
7359
|
throw new CreationClientError("credentials.private_owner_required");
|
|
7360
7360
|
return info5;
|
|
7361
7361
|
};
|
|
@@ -7374,9 +7374,9 @@ async function readCredentials(file = credentialsPath()) {
|
|
|
7374
7374
|
return { ...value2, endpoint: normalizeEndpoint(value2.endpoint) };
|
|
7375
7375
|
}
|
|
7376
7376
|
async function writeCredentials(value2, file = credentialsPath()) {
|
|
7377
|
-
const
|
|
7378
|
-
await mkdir(
|
|
7379
|
-
await secure(
|
|
7377
|
+
const directory3 = path.dirname(file);
|
|
7378
|
+
await mkdir(directory3, { recursive: true, mode: 448 });
|
|
7379
|
+
await secure(directory3, true);
|
|
7380
7380
|
await secure(file);
|
|
7381
7381
|
const temporary = file + "." + randomBytes(12).toString("hex") + ".tmp";
|
|
7382
7382
|
try {
|
|
@@ -7386,8 +7386,8 @@ async function writeCredentials(value2, file = credentialsPath()) {
|
|
|
7386
7386
|
});
|
|
7387
7387
|
await rename(temporary, file);
|
|
7388
7388
|
} finally {
|
|
7389
|
-
await unlink(temporary).catch((
|
|
7390
|
-
if (
|
|
7389
|
+
await unlink(temporary).catch((error5) => {
|
|
7390
|
+
if (error5.code !== "ENOENT") throw error5;
|
|
7391
7391
|
});
|
|
7392
7392
|
}
|
|
7393
7393
|
}
|
|
@@ -7420,8 +7420,8 @@ async function openLocalUploadFile(selectedPath, { maxBytes: maxBytes2 = LOCAL_U
|
|
|
7420
7420
|
let handle;
|
|
7421
7421
|
try {
|
|
7422
7422
|
handle = await open(selected, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
7423
|
-
} catch (
|
|
7424
|
-
throw failure(
|
|
7423
|
+
} catch (error5) {
|
|
7424
|
+
throw failure(error5.code === "ELOOP" ? "file_not_regular" : error5.code === "EACCES" || error5.code === "EPERM" ? "file_read_denied" : "file_not_on_bridge_host");
|
|
7425
7425
|
}
|
|
7426
7426
|
const abort = new AbortController(), streams = /* @__PURE__ */ new Map(), reads = /* @__PURE__ */ new Set();
|
|
7427
7427
|
let closing = false, closed = false, original, closePromise;
|
|
@@ -7446,8 +7446,8 @@ async function openLocalUploadFile(selectedPath, { maxBytes: maxBytes2 = LOCAL_U
|
|
|
7446
7446
|
try {
|
|
7447
7447
|
const [current, named] = await Promise.all([handle.stat({ bigint: true }), lstat2(selected, { bigint: true })]);
|
|
7448
7448
|
if (!current.isFile() || !named.isFile() || !equal(original, fingerprint(current)) || !equal(original, fingerprint(named))) throw failure("file_changed");
|
|
7449
|
-
} catch (
|
|
7450
|
-
if (
|
|
7449
|
+
} catch (error5) {
|
|
7450
|
+
if (error5 instanceof CreationClientError) throw error5;
|
|
7451
7451
|
throw failure("file_changed");
|
|
7452
7452
|
}
|
|
7453
7453
|
};
|
|
@@ -7466,17 +7466,17 @@ async function openLocalUploadFile(selectedPath, { maxBytes: maxBytes2 = LOCAL_U
|
|
|
7466
7466
|
if (stat3.size <= 0n || stat3.size > BigInt(maxBytes2)) throw failure("file_size_limit");
|
|
7467
7467
|
original = fingerprint(stat3);
|
|
7468
7468
|
await assertUnchanged();
|
|
7469
|
-
const
|
|
7469
|
+
const hash7 = createHash("sha256"), buffer = Buffer.allocUnsafe(LOCAL_UPLOAD_READ_BYTES);
|
|
7470
7470
|
for (let position = 0; position < original.sizeBytes; ) {
|
|
7471
7471
|
checkSignal();
|
|
7472
7472
|
const length = Math.min(buffer.length, original.sizeBytes - position);
|
|
7473
7473
|
const { bytesRead } = await read2(buffer, 0, length, position);
|
|
7474
7474
|
if (bytesRead === 0) throw failure("file_changed");
|
|
7475
|
-
|
|
7475
|
+
hash7.update(buffer.subarray(0, bytesRead));
|
|
7476
7476
|
position += bytesRead;
|
|
7477
7477
|
}
|
|
7478
7478
|
await assertUnchanged();
|
|
7479
|
-
const checksum = "sha256:" +
|
|
7479
|
+
const checksum = "sha256:" + hash7.digest("hex");
|
|
7480
7480
|
return {
|
|
7481
7481
|
name,
|
|
7482
7482
|
sizeBytes: original.sizeBytes,
|
|
@@ -7509,9 +7509,9 @@ async function openLocalUploadFile(selectedPath, { maxBytes: maxBytes2 = LOCAL_U
|
|
|
7509
7509
|
return stream;
|
|
7510
7510
|
}
|
|
7511
7511
|
};
|
|
7512
|
-
} catch (
|
|
7512
|
+
} catch (error5) {
|
|
7513
7513
|
await close();
|
|
7514
|
-
if (
|
|
7514
|
+
if (error5 instanceof CreationClientError) throw error5;
|
|
7515
7515
|
throw failure("file_read_failed");
|
|
7516
7516
|
}
|
|
7517
7517
|
}
|
|
@@ -7547,13 +7547,13 @@ var causes = /* @__PURE__ */ new Set([
|
|
|
7547
7547
|
"validation_refused",
|
|
7548
7548
|
"stream_unconfirmed"
|
|
7549
7549
|
]);
|
|
7550
|
-
var localCause = (
|
|
7550
|
+
var localCause = (error5) => error5 instanceof CreationClientError ? {
|
|
7551
7551
|
"creation.local_upload.file_read_failed": "local_read_failed",
|
|
7552
7552
|
"creation.local_upload.file_changed": "local_file_changed",
|
|
7553
7553
|
"creation.local_upload.file_read_cancelled": "local_read_cancelled"
|
|
7554
|
-
}[
|
|
7555
|
-
var networkCause = (
|
|
7556
|
-
const code = typeof
|
|
7554
|
+
}[error5.message] : void 0;
|
|
7555
|
+
var networkCause = (error5) => {
|
|
7556
|
+
const code = typeof error5?.cause?.code === "string" ? error5.cause.code : error5?.code;
|
|
7557
7557
|
if (["ENOTFOUND", "EAI_AGAIN"].includes(code)) return "dns_failure";
|
|
7558
7558
|
if (code === "ECONNREFUSED") return "connection_refused";
|
|
7559
7559
|
if (["ECONNRESET", "EPIPE", "UND_ERR_SOCKET"].includes(code)) return "connection_interrupted";
|
|
@@ -7624,9 +7624,9 @@ async function transferGrantedPart(file, authorization, grant, {
|
|
|
7624
7624
|
report("checking_file", { bytesRead: 0 });
|
|
7625
7625
|
try {
|
|
7626
7626
|
await file.assertUnchanged();
|
|
7627
|
-
} catch (
|
|
7628
|
-
report("checking_file", { causeCode: localCause(
|
|
7629
|
-
throw
|
|
7627
|
+
} catch (error5) {
|
|
7628
|
+
report("checking_file", { causeCode: localCause(error5) ?? "local_read_failed" });
|
|
7629
|
+
throw error5;
|
|
7630
7630
|
}
|
|
7631
7631
|
if (signal?.aborted) fail("transfer_cancelled");
|
|
7632
7632
|
const controller = new AbortController();
|
|
@@ -7665,12 +7665,12 @@ async function transferGrantedPart(file, authorization, grant, {
|
|
|
7665
7665
|
yield chunk;
|
|
7666
7666
|
}
|
|
7667
7667
|
report("awaiting_response", { bytesRead });
|
|
7668
|
-
} catch (
|
|
7668
|
+
} catch (error5) {
|
|
7669
7669
|
if (!reason && !closing) {
|
|
7670
7670
|
streamFailure = true;
|
|
7671
|
-
report("streaming", { bytesRead, causeCode: localCause(
|
|
7671
|
+
report("streaming", { bytesRead, causeCode: localCause(error5) ?? (["EIO", "EACCES", "EPERM", "ESTALE", "EBADF"].includes(error5?.code) ? "local_read_failed" : "stream_unconfirmed") });
|
|
7672
7672
|
}
|
|
7673
|
-
throw
|
|
7673
|
+
throw error5;
|
|
7674
7674
|
}
|
|
7675
7675
|
}
|
|
7676
7676
|
try {
|
|
@@ -7698,9 +7698,9 @@ async function transferGrantedPart(file, authorization, grant, {
|
|
|
7698
7698
|
report("checking_file", { bytesRead });
|
|
7699
7699
|
try {
|
|
7700
7700
|
await file.assertUnchanged();
|
|
7701
|
-
} catch (
|
|
7702
|
-
report("checking_file", { bytesRead, causeCode: localCause(
|
|
7703
|
-
throw
|
|
7701
|
+
} catch (error5) {
|
|
7702
|
+
report("checking_file", { bytesRead, causeCode: localCause(error5) ?? "local_read_failed" });
|
|
7703
|
+
throw error5;
|
|
7704
7704
|
}
|
|
7705
7705
|
report("reading_receipt", { bytesRead });
|
|
7706
7706
|
const etag = response.headers.get("etag");
|
|
@@ -7709,13 +7709,13 @@ async function transferGrantedPart(file, authorization, grant, {
|
|
|
7709
7709
|
fail("part_receipt_unconfirmed");
|
|
7710
7710
|
}
|
|
7711
7711
|
return { partNumber: grant.partNumber, etag, sizeBytes };
|
|
7712
|
-
} catch (
|
|
7712
|
+
} catch (error5) {
|
|
7713
7713
|
if (reason) fail(reason);
|
|
7714
|
-
if (
|
|
7715
|
-
if (localCause(
|
|
7716
|
-
throw
|
|
7714
|
+
if (error5 instanceof CreationClientError) {
|
|
7715
|
+
if (localCause(error5)) onTransferState({ causeCode: localCause(error5) });
|
|
7716
|
+
throw error5;
|
|
7717
7717
|
}
|
|
7718
|
-
if (!streamFailure) onTransferState({ causeCode: networkCause(
|
|
7718
|
+
if (!streamFailure) onTransferState({ causeCode: networkCause(error5) });
|
|
7719
7719
|
fail("part_transfer_unconfirmed");
|
|
7720
7720
|
} finally {
|
|
7721
7721
|
closing = true;
|
|
@@ -7733,8 +7733,8 @@ async function transferGrantedPart(file, authorization, grant, {
|
|
|
7733
7733
|
}
|
|
7734
7734
|
var effects = /* @__PURE__ */ new WeakMap();
|
|
7735
7735
|
var diagnostics = /* @__PURE__ */ new WeakMap();
|
|
7736
|
-
var readPartTransferEffect = (
|
|
7737
|
-
var readPartTransferDiagnostic = (
|
|
7736
|
+
var readPartTransferEffect = (error5) => error5 && typeof error5 === "object" ? effects.get(error5) : void 0;
|
|
7737
|
+
var readPartTransferDiagnostic = (error5) => error5 && typeof error5 === "object" ? diagnostics.get(error5) : void 0;
|
|
7738
7738
|
async function uploadGrantedPart(file, authorization, grant, options = {}) {
|
|
7739
7739
|
let dispatched = false, state = { stage: "validating", bytesRead: 0 };
|
|
7740
7740
|
const monotonic = options.monotonicNow ?? (() => performance2.now()), started = monotonic();
|
|
@@ -7745,15 +7745,15 @@ async function uploadGrantedPart(file, authorization, grant, options = {}) {
|
|
|
7745
7745
|
dispatched = true;
|
|
7746
7746
|
return (options.fetch ?? globalThis.fetch)(...args2);
|
|
7747
7747
|
} });
|
|
7748
|
-
} catch (
|
|
7749
|
-
if (
|
|
7750
|
-
if (
|
|
7748
|
+
} catch (error5) {
|
|
7749
|
+
if (error5 && typeof error5 === "object") effects.set(error5, dispatched ? "unknown" : "not_dispatched");
|
|
7750
|
+
if (error5 && typeof error5 === "object") diagnostics.set(error5, safePartTransferDiagnostic({
|
|
7751
7751
|
...state,
|
|
7752
7752
|
requestId: options.requestId,
|
|
7753
|
-
causeCode: state.causeCode ?? (!dispatched && state.stage === "validating" ? "validation_refused" : networkCause(
|
|
7753
|
+
causeCode: state.causeCode ?? (!dispatched && state.stage === "validating" ? "validation_refused" : networkCause(error5)),
|
|
7754
7754
|
elapsedMs: Math.max(0, Math.floor(monotonic() - started))
|
|
7755
7755
|
}));
|
|
7756
|
-
throw
|
|
7756
|
+
throw error5;
|
|
7757
7757
|
}
|
|
7758
7758
|
}
|
|
7759
7759
|
|
|
@@ -7979,7 +7979,7 @@ var digest = (value2) => createHash2("sha256").update(JSON.stringify(value2)).di
|
|
|
7979
7979
|
var fail3 = (code) => {
|
|
7980
7980
|
throw new CreationClientError("creation.local_upload." + code);
|
|
7981
7981
|
};
|
|
7982
|
-
var knownError = (
|
|
7982
|
+
var knownError = (error5) => error5 instanceof CreationClientError && /^creation\.[a-z0-9_.:-]{1,180}$/.test(error5.message) ? error5.message : "creation.local_upload.control_unconfirmed";
|
|
7983
7983
|
var createRefusal = (code) => /^creation\.direct_object_upload\.(?:size_limit_exceeded|pending_bytes_quota_exceeded|concurrent_multipart_quota_exceeded|daily_bytes_quota_exceeded|durable_storage_quota_exceeded|capacity_unavailable|admission_facts_unavailable)$/.test(code);
|
|
7984
7984
|
var typeByExtension = {
|
|
7985
7985
|
".png": ["image", "image/png"],
|
|
@@ -8214,14 +8214,14 @@ function createLocalUploadManager({ stateRoot, fetch: fetch2 = globalThis.fetch,
|
|
|
8214
8214
|
job.progress = progress.bytesRead;
|
|
8215
8215
|
}
|
|
8216
8216
|
});
|
|
8217
|
-
} catch (
|
|
8218
|
-
const diagnostic = readPartTransferDiagnostic(
|
|
8217
|
+
} catch (error5) {
|
|
8218
|
+
const diagnostic = readPartTransferDiagnostic(error5);
|
|
8219
8219
|
if (diagnostic) state.lastTransferDiagnostic = diagnostic;
|
|
8220
|
-
if (readPartTransferEffect(
|
|
8220
|
+
if (readPartTransferEffect(error5) === "not_dispatched") {
|
|
8221
8221
|
delete state.pendingPart;
|
|
8222
8222
|
await save();
|
|
8223
8223
|
}
|
|
8224
|
-
throw
|
|
8224
|
+
throw error5;
|
|
8225
8225
|
}
|
|
8226
8226
|
state.parts.push(part);
|
|
8227
8227
|
state.parts.sort((a, b2) => a.partNumber - b2.partNumber);
|
|
@@ -8348,11 +8348,11 @@ function createLocalUploadManager({ stateRoot, fetch: fetch2 = globalThis.fetch,
|
|
|
8348
8348
|
let created;
|
|
8349
8349
|
try {
|
|
8350
8350
|
created = await rpc(send, { action: "create", request: state.request });
|
|
8351
|
-
} catch (
|
|
8352
|
-
const code = knownError(
|
|
8351
|
+
} catch (error5) {
|
|
8352
|
+
const code = knownError(error5);
|
|
8353
8353
|
state.createDisposition = createRefusal(code) ? "rejected" : "unconfirmed";
|
|
8354
8354
|
if (createRefusal(code)) state.createErrorCode = code;
|
|
8355
|
-
throw
|
|
8355
|
+
throw error5;
|
|
8356
8356
|
}
|
|
8357
8357
|
authorization = created.authorization;
|
|
8358
8358
|
const session = authorization?.session;
|
|
@@ -8370,9 +8370,9 @@ function createLocalUploadManager({ stateRoot, fetch: fetch2 = globalThis.fetch,
|
|
|
8370
8370
|
job = { state, file, abort, progress: 0, save: () => persistence.write(key, state) };
|
|
8371
8371
|
jobs.set(key, job);
|
|
8372
8372
|
file = void 0;
|
|
8373
|
-
job.done = Promise.resolve().then(() => transfer(job, authorization, (transfer2, options) => send(transfer2, { signal: abort.signal, ...options }), binding)).catch(async (
|
|
8373
|
+
job.done = Promise.resolve().then(() => transfer(job, authorization, (transfer2, options) => send(transfer2, { signal: abort.signal, ...options }), binding)).catch(async (error5) => {
|
|
8374
8374
|
state.phase = "paused";
|
|
8375
|
-
state.errorCode = abort.signal.aborted ? "creation.local_upload.transfer_cancelled" : knownError(
|
|
8375
|
+
state.errorCode = abort.signal.aborted ? "creation.local_upload.transfer_cancelled" : knownError(error5);
|
|
8376
8376
|
await job.save();
|
|
8377
8377
|
}).finally(async () => {
|
|
8378
8378
|
try {
|
|
@@ -8388,13 +8388,13 @@ function createLocalUploadManager({ stateRoot, fetch: fetch2 = globalThis.fetch,
|
|
|
8388
8388
|
job.done.catch(() => {
|
|
8389
8389
|
});
|
|
8390
8390
|
return view(state, job);
|
|
8391
|
-
} catch (
|
|
8391
|
+
} catch (error5) {
|
|
8392
8392
|
if (state) {
|
|
8393
8393
|
state.phase = state.createDisposition === "rejected" && !state.uploadId ? "create_rejected" : "paused";
|
|
8394
|
-
state.errorCode = knownError(
|
|
8394
|
+
state.errorCode = knownError(error5);
|
|
8395
8395
|
await persistence.write(key, state);
|
|
8396
8396
|
}
|
|
8397
|
-
throw
|
|
8397
|
+
throw error5;
|
|
8398
8398
|
} finally {
|
|
8399
8399
|
if (!jobs.has(key)) {
|
|
8400
8400
|
await file?.close();
|
|
@@ -8429,7 +8429,7 @@ function createLocalUploadManager({ stateRoot, fetch: fetch2 = globalThis.fetch,
|
|
|
8429
8429
|
}
|
|
8430
8430
|
|
|
8431
8431
|
// lib/version.mjs
|
|
8432
|
-
var CLIENT_VERSION = "0.3.
|
|
8432
|
+
var CLIENT_VERSION = "0.3.12";
|
|
8433
8433
|
var CLIENT_PROTOCOL = "creation-client/v1";
|
|
8434
8434
|
|
|
8435
8435
|
// lib/cli.mjs
|
|
@@ -8532,9 +8532,9 @@ function assertNever(_x) {
|
|
|
8532
8532
|
}
|
|
8533
8533
|
function assert(_2) {
|
|
8534
8534
|
}
|
|
8535
|
-
function getEnumValues(
|
|
8536
|
-
const numericValues = Object.values(
|
|
8537
|
-
const values = Object.entries(
|
|
8535
|
+
function getEnumValues(entries2) {
|
|
8536
|
+
const numericValues = Object.values(entries2).filter((v2) => typeof v2 === "number");
|
|
8537
|
+
const values = Object.entries(entries2).filter(([k2, _2]) => numericValues.indexOf(+k2) === -1).map(([_2, v2]) => v2);
|
|
8538
8538
|
return values;
|
|
8539
8539
|
}
|
|
8540
8540
|
function joinValues(array2, separator = "|") {
|
|
@@ -8673,10 +8673,10 @@ function mergeDefs(...defs) {
|
|
|
8673
8673
|
function cloneDef(schema) {
|
|
8674
8674
|
return mergeDefs(schema._zod.def);
|
|
8675
8675
|
}
|
|
8676
|
-
function getElementAtPath(obj,
|
|
8677
|
-
if (!
|
|
8676
|
+
function getElementAtPath(obj, path21) {
|
|
8677
|
+
if (!path21)
|
|
8678
8678
|
return obj;
|
|
8679
|
-
return
|
|
8679
|
+
return path21.reduce((acc, key) => acc?.[key], obj);
|
|
8680
8680
|
}
|
|
8681
8681
|
function promiseAllObject(promisesObj) {
|
|
8682
8682
|
const keys = Object.keys(promisesObj);
|
|
@@ -9016,11 +9016,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
9016
9016
|
}
|
|
9017
9017
|
return false;
|
|
9018
9018
|
}
|
|
9019
|
-
function prefixIssues(
|
|
9019
|
+
function prefixIssues(path21, issues) {
|
|
9020
9020
|
return issues.map((iss) => {
|
|
9021
9021
|
var _a3;
|
|
9022
9022
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
9023
|
-
iss.path.unshift(
|
|
9023
|
+
iss.path.unshift(path21);
|
|
9024
9024
|
return iss;
|
|
9025
9025
|
});
|
|
9026
9026
|
}
|
|
@@ -9467,10 +9467,10 @@ function node(obj, key, make) {
|
|
|
9467
9467
|
}
|
|
9468
9468
|
return obj[key];
|
|
9469
9469
|
}
|
|
9470
|
-
function flattenError(
|
|
9470
|
+
function flattenError(error5, mapper = (issue2) => issue2.message) {
|
|
9471
9471
|
const fieldErrors = {};
|
|
9472
9472
|
const formErrors = [];
|
|
9473
|
-
for (const sub of
|
|
9473
|
+
for (const sub of error5.issues) {
|
|
9474
9474
|
if (sub.path.length > 0) {
|
|
9475
9475
|
node(fieldErrors, sub.path[0], () => []).push(mapper(sub));
|
|
9476
9476
|
} else {
|
|
@@ -9479,18 +9479,18 @@ function flattenError(error4, mapper = (issue2) => issue2.message) {
|
|
|
9479
9479
|
}
|
|
9480
9480
|
return { formErrors, fieldErrors };
|
|
9481
9481
|
}
|
|
9482
|
-
function formatError(
|
|
9482
|
+
function formatError(error5, mapper = (issue2) => issue2.message) {
|
|
9483
9483
|
const fieldErrors = { _errors: [] };
|
|
9484
|
-
const processError = (
|
|
9485
|
-
for (const issue2 of
|
|
9484
|
+
const processError = (error6, path21 = []) => {
|
|
9485
|
+
for (const issue2 of error6.issues) {
|
|
9486
9486
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
9487
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
9487
|
+
issue2.errors.map((issues) => processError({ issues }, [...path21, ...issue2.path]));
|
|
9488
9488
|
} else if (issue2.code === "invalid_key") {
|
|
9489
|
-
processError({ issues: issue2.issues }, [...
|
|
9489
|
+
processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
|
|
9490
9490
|
} else if (issue2.code === "invalid_element") {
|
|
9491
|
-
processError({ issues: issue2.issues }, [...
|
|
9491
|
+
processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
|
|
9492
9492
|
} else {
|
|
9493
|
-
const fullpath = [...
|
|
9493
|
+
const fullpath = [...path21, ...issue2.path];
|
|
9494
9494
|
if (fullpath.length === 0) {
|
|
9495
9495
|
fieldErrors._errors.push(mapper(issue2));
|
|
9496
9496
|
} else {
|
|
@@ -9524,7 +9524,7 @@ function formatError(error4, mapper = (issue2) => issue2.message) {
|
|
|
9524
9524
|
}
|
|
9525
9525
|
}
|
|
9526
9526
|
};
|
|
9527
|
-
processError(
|
|
9527
|
+
processError(error5);
|
|
9528
9528
|
return fieldErrors;
|
|
9529
9529
|
}
|
|
9530
9530
|
|
|
@@ -9573,19 +9573,19 @@ var _safeParse = (_Err) => (schema, value2, _ctx) => {
|
|
|
9573
9573
|
};
|
|
9574
9574
|
var safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
9575
9575
|
function failure2(Err, issues, ctx) {
|
|
9576
|
-
let
|
|
9576
|
+
let error5;
|
|
9577
9577
|
return {
|
|
9578
9578
|
success: false,
|
|
9579
9579
|
get error() {
|
|
9580
|
-
if (!
|
|
9581
|
-
|
|
9580
|
+
if (!error5) {
|
|
9581
|
+
error5 = new Err(issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
9582
9582
|
issues = void 0;
|
|
9583
9583
|
ctx = void 0;
|
|
9584
9584
|
}
|
|
9585
|
-
return
|
|
9585
|
+
return error5;
|
|
9586
9586
|
},
|
|
9587
9587
|
set error(e) {
|
|
9588
|
-
|
|
9588
|
+
error5 = e;
|
|
9589
9589
|
issues = void 0;
|
|
9590
9590
|
ctx = void 0;
|
|
9591
9591
|
}
|
|
@@ -14837,10 +14837,10 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
14837
14837
|
};
|
|
14838
14838
|
});
|
|
14839
14839
|
function _enum(values, params) {
|
|
14840
|
-
const
|
|
14840
|
+
const entries2 = Array.isArray(values) ? Object.fromEntries(values.map((v2) => [v2, v2])) : values;
|
|
14841
14841
|
return new ZodEnum({
|
|
14842
14842
|
type: "enum",
|
|
14843
|
-
entries,
|
|
14843
|
+
entries: entries2,
|
|
14844
14844
|
...util_exports.normalizeParams(params)
|
|
14845
14845
|
});
|
|
14846
14846
|
}
|
|
@@ -16726,8 +16726,8 @@ var Protocol = class {
|
|
|
16726
16726
|
resolver(message);
|
|
16727
16727
|
} else {
|
|
16728
16728
|
const errorMessage = message;
|
|
16729
|
-
const
|
|
16730
|
-
resolver(
|
|
16729
|
+
const error5 = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
|
|
16730
|
+
resolver(error5);
|
|
16731
16731
|
}
|
|
16732
16732
|
} else {
|
|
16733
16733
|
const messageType = queuedMessage.type === "response" ? "Response" : "Error";
|
|
@@ -16771,8 +16771,8 @@ var Protocol = class {
|
|
|
16771
16771
|
nextCursor,
|
|
16772
16772
|
_meta: {}
|
|
16773
16773
|
};
|
|
16774
|
-
} catch (
|
|
16775
|
-
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${
|
|
16774
|
+
} catch (error5) {
|
|
16775
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error5 instanceof Error ? error5.message : String(error5)}`);
|
|
16776
16776
|
}
|
|
16777
16777
|
});
|
|
16778
16778
|
this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
|
|
@@ -16794,11 +16794,11 @@ var Protocol = class {
|
|
|
16794
16794
|
_meta: {},
|
|
16795
16795
|
...cancelledTask
|
|
16796
16796
|
};
|
|
16797
|
-
} catch (
|
|
16798
|
-
if (
|
|
16799
|
-
throw
|
|
16797
|
+
} catch (error5) {
|
|
16798
|
+
if (error5 instanceof McpError) {
|
|
16799
|
+
throw error5;
|
|
16800
16800
|
}
|
|
16801
|
-
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${
|
|
16801
|
+
throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error5 instanceof Error ? error5.message : String(error5)}`);
|
|
16802
16802
|
}
|
|
16803
16803
|
});
|
|
16804
16804
|
}
|
|
@@ -16859,9 +16859,9 @@ var Protocol = class {
|
|
|
16859
16859
|
this._onclose();
|
|
16860
16860
|
};
|
|
16861
16861
|
const _onerror = this.transport?.onerror;
|
|
16862
|
-
this._transport.onerror = (
|
|
16863
|
-
_onerror?.(
|
|
16864
|
-
this._onerror(
|
|
16862
|
+
this._transport.onerror = (error5) => {
|
|
16863
|
+
_onerror?.(error5);
|
|
16864
|
+
this._onerror(error5);
|
|
16865
16865
|
};
|
|
16866
16866
|
const _onmessage = this._transport?.onmessage;
|
|
16867
16867
|
this._transport.onmessage = (message, extra) => {
|
|
@@ -16892,22 +16892,22 @@ var Protocol = class {
|
|
|
16892
16892
|
controller.abort();
|
|
16893
16893
|
}
|
|
16894
16894
|
this._requestHandlerAbortControllers.clear();
|
|
16895
|
-
const
|
|
16895
|
+
const error5 = McpError.fromError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
16896
16896
|
this._transport = void 0;
|
|
16897
16897
|
this.onclose?.();
|
|
16898
16898
|
for (const handler of responseHandlers.values()) {
|
|
16899
|
-
handler(
|
|
16899
|
+
handler(error5);
|
|
16900
16900
|
}
|
|
16901
16901
|
}
|
|
16902
|
-
_onerror(
|
|
16903
|
-
this.onerror?.(
|
|
16902
|
+
_onerror(error5) {
|
|
16903
|
+
this.onerror?.(error5);
|
|
16904
16904
|
}
|
|
16905
16905
|
_onnotification(notification) {
|
|
16906
16906
|
const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
|
|
16907
16907
|
if (handler === void 0) {
|
|
16908
16908
|
return;
|
|
16909
16909
|
}
|
|
16910
|
-
Promise.resolve().then(() => handler(notification)).catch((
|
|
16910
|
+
Promise.resolve().then(() => handler(notification)).catch((error5) => this._onerror(new Error(`Uncaught error in notification handler: ${error5}`)));
|
|
16911
16911
|
}
|
|
16912
16912
|
_onrequest(request, extra) {
|
|
16913
16913
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
@@ -16937,15 +16937,15 @@ var Protocol = class {
|
|
|
16937
16937
|
};
|
|
16938
16938
|
if (relatedTaskId && relatedTaskLookup) {
|
|
16939
16939
|
const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
|
|
16940
|
-
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((
|
|
16940
|
+
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error5) => this._onerror(new Error(`Failed to send an error response: ${error5}`)));
|
|
16941
16941
|
} else if (relatedTaskId && this._taskMessageQueue) {
|
|
16942
16942
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
16943
16943
|
type: "error",
|
|
16944
16944
|
message: errorResponse,
|
|
16945
16945
|
timestamp: Date.now()
|
|
16946
|
-
}, capturedTransport?.sessionId).catch((
|
|
16946
|
+
}, capturedTransport?.sessionId).catch((error5) => this._onerror(new Error(`Failed to enqueue error response: ${error5}`)));
|
|
16947
16947
|
} else {
|
|
16948
|
-
capturedTransport?.send(errorResponse).catch((
|
|
16948
|
+
capturedTransport?.send(errorResponse).catch((error5) => this._onerror(new Error(`Failed to send an error response: ${error5}`)));
|
|
16949
16949
|
}
|
|
16950
16950
|
return;
|
|
16951
16951
|
}
|
|
@@ -17014,7 +17014,7 @@ var Protocol = class {
|
|
|
17014
17014
|
} else {
|
|
17015
17015
|
await capturedTransport?.send(response);
|
|
17016
17016
|
}
|
|
17017
|
-
}, async (
|
|
17017
|
+
}, async (error5) => {
|
|
17018
17018
|
if (abortController.signal.aborted) {
|
|
17019
17019
|
return;
|
|
17020
17020
|
}
|
|
@@ -17022,9 +17022,9 @@ var Protocol = class {
|
|
|
17022
17022
|
jsonrpc: "2.0",
|
|
17023
17023
|
id: request.id,
|
|
17024
17024
|
error: {
|
|
17025
|
-
code: Number.isSafeInteger(
|
|
17026
|
-
message:
|
|
17027
|
-
...
|
|
17025
|
+
code: Number.isSafeInteger(error5["code"]) ? error5["code"] : ErrorCode.InternalError,
|
|
17026
|
+
message: error5.message ?? "Internal error",
|
|
17027
|
+
...error5["data"] !== void 0 && { data: error5["data"] }
|
|
17028
17028
|
}
|
|
17029
17029
|
};
|
|
17030
17030
|
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
@@ -17036,7 +17036,7 @@ var Protocol = class {
|
|
|
17036
17036
|
} else {
|
|
17037
17037
|
await capturedTransport?.send(errorResponse);
|
|
17038
17038
|
}
|
|
17039
|
-
}).catch((
|
|
17039
|
+
}).catch((error5) => this._onerror(new Error(`Failed to send response: ${error5}`))).finally(() => {
|
|
17040
17040
|
if (this._requestHandlerAbortControllers.get(request.id) === abortController) {
|
|
17041
17041
|
this._requestHandlerAbortControllers.delete(request.id);
|
|
17042
17042
|
}
|
|
@@ -17055,11 +17055,11 @@ var Protocol = class {
|
|
|
17055
17055
|
if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) {
|
|
17056
17056
|
try {
|
|
17057
17057
|
this._resetTimeout(messageId);
|
|
17058
|
-
} catch (
|
|
17058
|
+
} catch (error5) {
|
|
17059
17059
|
this._responseHandlers.delete(messageId);
|
|
17060
17060
|
this._progressHandlers.delete(messageId);
|
|
17061
17061
|
this._cleanupTimeout(messageId);
|
|
17062
|
-
responseHandler(
|
|
17062
|
+
responseHandler(error5);
|
|
17063
17063
|
return;
|
|
17064
17064
|
}
|
|
17065
17065
|
}
|
|
@@ -17073,8 +17073,8 @@ var Protocol = class {
|
|
|
17073
17073
|
if (isJSONRPCResultResponse(response)) {
|
|
17074
17074
|
resolver(response);
|
|
17075
17075
|
} else {
|
|
17076
|
-
const
|
|
17077
|
-
resolver(
|
|
17076
|
+
const error5 = new McpError(response.error.code, response.error.message, response.error.data);
|
|
17077
|
+
resolver(error5);
|
|
17078
17078
|
}
|
|
17079
17079
|
return;
|
|
17080
17080
|
}
|
|
@@ -17102,8 +17102,8 @@ var Protocol = class {
|
|
|
17102
17102
|
if (isJSONRPCResultResponse(response)) {
|
|
17103
17103
|
handler(response);
|
|
17104
17104
|
} else {
|
|
17105
|
-
const
|
|
17106
|
-
handler(
|
|
17105
|
+
const error5 = McpError.fromError(response.error.code, response.error.message, response.error.data);
|
|
17106
|
+
handler(error5);
|
|
17107
17107
|
}
|
|
17108
17108
|
}
|
|
17109
17109
|
get transport() {
|
|
@@ -17148,10 +17148,10 @@ var Protocol = class {
|
|
|
17148
17148
|
try {
|
|
17149
17149
|
const result = await this.request(request, resultSchema, options);
|
|
17150
17150
|
yield { type: "result", result };
|
|
17151
|
-
} catch (
|
|
17151
|
+
} catch (error5) {
|
|
17152
17152
|
yield {
|
|
17153
17153
|
type: "error",
|
|
17154
|
-
error:
|
|
17154
|
+
error: error5 instanceof McpError ? error5 : new McpError(ErrorCode.InternalError, String(error5))
|
|
17155
17155
|
};
|
|
17156
17156
|
}
|
|
17157
17157
|
return;
|
|
@@ -17194,10 +17194,10 @@ var Protocol = class {
|
|
|
17194
17194
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
17195
17195
|
options?.signal?.throwIfAborted();
|
|
17196
17196
|
}
|
|
17197
|
-
} catch (
|
|
17197
|
+
} catch (error5) {
|
|
17198
17198
|
yield {
|
|
17199
17199
|
type: "error",
|
|
17200
|
-
error:
|
|
17200
|
+
error: error5 instanceof McpError ? error5 : new McpError(ErrorCode.InternalError, String(error5))
|
|
17201
17201
|
};
|
|
17202
17202
|
}
|
|
17203
17203
|
}
|
|
@@ -17209,8 +17209,8 @@ var Protocol = class {
|
|
|
17209
17209
|
request(request, resultSchema, options) {
|
|
17210
17210
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
17211
17211
|
return new Promise((resolve, reject) => {
|
|
17212
|
-
const earlyReject = (
|
|
17213
|
-
reject(
|
|
17212
|
+
const earlyReject = (error5) => {
|
|
17213
|
+
reject(error5);
|
|
17214
17214
|
};
|
|
17215
17215
|
if (!this._transport) {
|
|
17216
17216
|
earlyReject(new Error("Not connected"));
|
|
@@ -17270,9 +17270,9 @@ var Protocol = class {
|
|
|
17270
17270
|
requestId: messageId,
|
|
17271
17271
|
reason: String(reason)
|
|
17272
17272
|
}
|
|
17273
|
-
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
17274
|
-
const
|
|
17275
|
-
reject(
|
|
17273
|
+
}, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error6) => this._onerror(new Error(`Failed to send cancellation: ${error6}`)));
|
|
17274
|
+
const error5 = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason));
|
|
17275
|
+
reject(error5);
|
|
17276
17276
|
};
|
|
17277
17277
|
this._responseHandlers.set(messageId, (response) => {
|
|
17278
17278
|
if (options?.signal?.aborted) {
|
|
@@ -17288,8 +17288,8 @@ var Protocol = class {
|
|
|
17288
17288
|
} else {
|
|
17289
17289
|
resolve(parseResult.data);
|
|
17290
17290
|
}
|
|
17291
|
-
} catch (
|
|
17292
|
-
reject(
|
|
17291
|
+
} catch (error5) {
|
|
17292
|
+
reject(error5);
|
|
17293
17293
|
}
|
|
17294
17294
|
});
|
|
17295
17295
|
options?.signal?.addEventListener("abort", () => {
|
|
@@ -17313,14 +17313,14 @@ var Protocol = class {
|
|
|
17313
17313
|
type: "request",
|
|
17314
17314
|
message: jsonrpcRequest,
|
|
17315
17315
|
timestamp: Date.now()
|
|
17316
|
-
}).catch((
|
|
17316
|
+
}).catch((error5) => {
|
|
17317
17317
|
this._cleanupTimeout(messageId);
|
|
17318
|
-
reject(
|
|
17318
|
+
reject(error5);
|
|
17319
17319
|
});
|
|
17320
17320
|
} else {
|
|
17321
|
-
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((
|
|
17321
|
+
this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error5) => {
|
|
17322
17322
|
this._cleanupTimeout(messageId);
|
|
17323
|
-
reject(
|
|
17323
|
+
reject(error5);
|
|
17324
17324
|
});
|
|
17325
17325
|
}
|
|
17326
17326
|
});
|
|
@@ -17413,7 +17413,7 @@ var Protocol = class {
|
|
|
17413
17413
|
}
|
|
17414
17414
|
};
|
|
17415
17415
|
}
|
|
17416
|
-
this._transport?.send(jsonrpcNotification2, options).catch((
|
|
17416
|
+
this._transport?.send(jsonrpcNotification2, options).catch((error5) => this._onerror(error5));
|
|
17417
17417
|
});
|
|
17418
17418
|
return;
|
|
17419
17419
|
}
|
|
@@ -18267,11 +18267,11 @@ var Server = class extends Protocol {
|
|
|
18267
18267
|
if (!validationResult.valid) {
|
|
18268
18268
|
throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
|
|
18269
18269
|
}
|
|
18270
|
-
} catch (
|
|
18271
|
-
if (
|
|
18272
|
-
throw
|
|
18270
|
+
} catch (error5) {
|
|
18271
|
+
if (error5 instanceof McpError) {
|
|
18272
|
+
throw error5;
|
|
18273
18273
|
}
|
|
18274
|
-
throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${
|
|
18274
|
+
throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error5 instanceof Error ? error5.message : String(error5)}`);
|
|
18275
18275
|
}
|
|
18276
18276
|
}
|
|
18277
18277
|
return result;
|
|
@@ -18383,14 +18383,14 @@ var StdioServerTransport = class {
|
|
|
18383
18383
|
try {
|
|
18384
18384
|
this._readBuffer.append(chunk);
|
|
18385
18385
|
this.processReadBuffer();
|
|
18386
|
-
} catch (
|
|
18387
|
-
this.onerror?.(
|
|
18386
|
+
} catch (error5) {
|
|
18387
|
+
this.onerror?.(error5);
|
|
18388
18388
|
this.close().catch(() => {
|
|
18389
18389
|
});
|
|
18390
18390
|
}
|
|
18391
18391
|
};
|
|
18392
|
-
this._onerror = (
|
|
18393
|
-
this.onerror?.(
|
|
18392
|
+
this._onerror = (error5) => {
|
|
18393
|
+
this.onerror?.(error5);
|
|
18394
18394
|
};
|
|
18395
18395
|
this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
|
|
18396
18396
|
}
|
|
@@ -18413,8 +18413,8 @@ var StdioServerTransport = class {
|
|
|
18413
18413
|
break;
|
|
18414
18414
|
}
|
|
18415
18415
|
this.onmessage?.(message);
|
|
18416
|
-
} catch (
|
|
18417
|
-
this.onerror?.(
|
|
18416
|
+
} catch (error5) {
|
|
18417
|
+
this.onerror?.(error5);
|
|
18418
18418
|
}
|
|
18419
18419
|
}
|
|
18420
18420
|
}
|
|
@@ -18511,14 +18511,14 @@ var ExperimentalClientTasks = class {
|
|
|
18511
18511
|
};
|
|
18512
18512
|
return;
|
|
18513
18513
|
}
|
|
18514
|
-
} catch (
|
|
18515
|
-
if (
|
|
18516
|
-
yield { type: "error", error:
|
|
18514
|
+
} catch (error5) {
|
|
18515
|
+
if (error5 instanceof McpError) {
|
|
18516
|
+
yield { type: "error", error: error5 };
|
|
18517
18517
|
return;
|
|
18518
18518
|
}
|
|
18519
18519
|
yield {
|
|
18520
18520
|
type: "error",
|
|
18521
|
-
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${
|
|
18521
|
+
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error5 instanceof Error ? error5.message : String(error5)}`)
|
|
18522
18522
|
};
|
|
18523
18523
|
return;
|
|
18524
18524
|
}
|
|
@@ -18831,9 +18831,9 @@ var Client = class extends Protocol {
|
|
|
18831
18831
|
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
18832
18832
|
this._pendingListChangedConfig = void 0;
|
|
18833
18833
|
}
|
|
18834
|
-
} catch (
|
|
18834
|
+
} catch (error5) {
|
|
18835
18835
|
void this.close();
|
|
18836
|
-
throw
|
|
18836
|
+
throw error5;
|
|
18837
18837
|
}
|
|
18838
18838
|
}
|
|
18839
18839
|
/**
|
|
@@ -19003,11 +19003,11 @@ var Client = class extends Protocol {
|
|
|
19003
19003
|
if (!validationResult.valid) {
|
|
19004
19004
|
throw new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`);
|
|
19005
19005
|
}
|
|
19006
|
-
} catch (
|
|
19007
|
-
if (
|
|
19008
|
-
throw
|
|
19006
|
+
} catch (error5) {
|
|
19007
|
+
if (error5 instanceof McpError) {
|
|
19008
|
+
throw error5;
|
|
19009
19009
|
}
|
|
19010
|
-
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${
|
|
19010
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error5 instanceof Error ? error5.message : String(error5)}`);
|
|
19011
19011
|
}
|
|
19012
19012
|
}
|
|
19013
19013
|
}
|
|
@@ -19082,8 +19082,8 @@ var Client = class extends Protocol {
|
|
|
19082
19082
|
const items = await fetcher();
|
|
19083
19083
|
onChanged(null, items);
|
|
19084
19084
|
} catch (e) {
|
|
19085
|
-
const
|
|
19086
|
-
onChanged(
|
|
19085
|
+
const error5 = e instanceof Error ? e : new Error(String(e));
|
|
19086
|
+
onChanged(error5, null);
|
|
19087
19087
|
}
|
|
19088
19088
|
};
|
|
19089
19089
|
const handler = () => {
|
|
@@ -19590,12 +19590,12 @@ async function parseErrorResponse(input) {
|
|
|
19590
19590
|
const body = input instanceof Response ? await input.text() : input;
|
|
19591
19591
|
try {
|
|
19592
19592
|
const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
|
|
19593
|
-
const { error:
|
|
19594
|
-
const errorClass = OAUTH_ERRORS[
|
|
19593
|
+
const { error: error5, error_description, error_uri } = result;
|
|
19594
|
+
const errorClass = OAUTH_ERRORS[error5] || ServerError;
|
|
19595
19595
|
return new errorClass(error_description || "", error_uri);
|
|
19596
|
-
} catch (
|
|
19596
|
+
} catch (error5) {
|
|
19597
19597
|
const redirect = input instanceof Response ? unfollowedRedirect(input, input.url) : void 0;
|
|
19598
|
-
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${
|
|
19598
|
+
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${error5}. Raw body: ${body}`}`;
|
|
19599
19599
|
return new ServerError(errorMessage);
|
|
19600
19600
|
}
|
|
19601
19601
|
}
|
|
@@ -19622,15 +19622,15 @@ function boundElsewhereError(stored, issuer) {
|
|
|
19622
19622
|
async function auth(provider, options) {
|
|
19623
19623
|
try {
|
|
19624
19624
|
return await authInternal(provider, options);
|
|
19625
|
-
} catch (
|
|
19626
|
-
if (
|
|
19625
|
+
} catch (error5) {
|
|
19626
|
+
if (error5 instanceof InvalidClientError || error5 instanceof UnauthorizedClientError) {
|
|
19627
19627
|
await provider.invalidateCredentials?.("all");
|
|
19628
19628
|
return await authInternal(provider, options);
|
|
19629
|
-
} else if (
|
|
19629
|
+
} else if (error5 instanceof InvalidGrantError) {
|
|
19630
19630
|
await provider.invalidateCredentials?.("tokens");
|
|
19631
19631
|
return await authInternal(provider, options);
|
|
19632
19632
|
}
|
|
19633
|
-
throw
|
|
19633
|
+
throw error5;
|
|
19634
19634
|
}
|
|
19635
19635
|
}
|
|
19636
19636
|
async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
|
|
@@ -19746,10 +19746,10 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
19746
19746
|
await bindClientInformation();
|
|
19747
19747
|
await provider.saveTokens({ ...newTokens, issuer });
|
|
19748
19748
|
return "AUTHORIZED";
|
|
19749
|
-
} catch (
|
|
19750
|
-
if (!(
|
|
19749
|
+
} catch (error5) {
|
|
19750
|
+
if (!(error5 instanceof OAuthError) || error5 instanceof ServerError) {
|
|
19751
19751
|
} else {
|
|
19752
|
-
throw
|
|
19752
|
+
throw error5;
|
|
19753
19753
|
}
|
|
19754
19754
|
}
|
|
19755
19755
|
}
|
|
@@ -19807,11 +19807,11 @@ function extractWWWAuthenticateParams(res) {
|
|
|
19807
19807
|
}
|
|
19808
19808
|
}
|
|
19809
19809
|
const scope = extractFieldFromWwwAuth(res, "scope") || void 0;
|
|
19810
|
-
const
|
|
19810
|
+
const error5 = extractFieldFromWwwAuth(res, "error") || void 0;
|
|
19811
19811
|
return {
|
|
19812
19812
|
resourceMetadataUrl,
|
|
19813
19813
|
scope,
|
|
19814
|
-
error:
|
|
19814
|
+
error: error5
|
|
19815
19815
|
};
|
|
19816
19816
|
}
|
|
19817
19817
|
function extractFieldFromWwwAuth(response, fieldName) {
|
|
@@ -19844,15 +19844,15 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn =
|
|
|
19844
19844
|
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
19845
19845
|
try {
|
|
19846
19846
|
return await fetchWithinOrigin(fetchFn)(url2, { headers });
|
|
19847
|
-
} catch (
|
|
19848
|
-
if (
|
|
19847
|
+
} catch (error5) {
|
|
19848
|
+
if (error5 instanceof TypeError) {
|
|
19849
19849
|
if (headers) {
|
|
19850
19850
|
return fetchWithCorsRetry(url2, void 0, fetchFn);
|
|
19851
19851
|
} else {
|
|
19852
19852
|
return void 0;
|
|
19853
19853
|
}
|
|
19854
19854
|
}
|
|
19855
|
-
throw
|
|
19855
|
+
throw error5;
|
|
19856
19856
|
}
|
|
19857
19857
|
}
|
|
19858
19858
|
function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
@@ -20301,8 +20301,8 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
20301
20301
|
onEvent: (event) => {
|
|
20302
20302
|
controller.enqueue(event);
|
|
20303
20303
|
},
|
|
20304
|
-
onError(
|
|
20305
|
-
typeof onError == "function" && onError(
|
|
20304
|
+
onError(error5) {
|
|
20305
|
+
typeof onError == "function" && onError(error5), (onError === "terminate" || error5.type === "max-buffer-size-exceeded") && controller.error(error5);
|
|
20306
20306
|
},
|
|
20307
20307
|
onRetry,
|
|
20308
20308
|
onComment,
|
|
@@ -20364,9 +20364,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
20364
20364
|
scope: this._scope,
|
|
20365
20365
|
fetchFn: this._fetchWithInit
|
|
20366
20366
|
});
|
|
20367
|
-
} catch (
|
|
20368
|
-
this.onerror?.(
|
|
20369
|
-
throw
|
|
20367
|
+
} catch (error5) {
|
|
20368
|
+
this.onerror?.(error5);
|
|
20369
|
+
throw error5;
|
|
20370
20370
|
}
|
|
20371
20371
|
if (result !== "AUTHORIZED") {
|
|
20372
20372
|
throw new UnauthorizedError();
|
|
@@ -20419,9 +20419,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
20419
20419
|
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
20420
20420
|
}
|
|
20421
20421
|
this._handleSseStream(response.body, options, true);
|
|
20422
|
-
} catch (
|
|
20423
|
-
this.onerror?.(
|
|
20424
|
-
throw
|
|
20422
|
+
} catch (error5) {
|
|
20423
|
+
this.onerror?.(error5);
|
|
20424
|
+
throw error5;
|
|
20425
20425
|
}
|
|
20426
20426
|
}
|
|
20427
20427
|
/**
|
|
@@ -20453,8 +20453,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
20453
20453
|
}
|
|
20454
20454
|
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
20455
20455
|
this._reconnectionTimeout = setTimeout(() => {
|
|
20456
|
-
this._startOrAuthSse(options).catch((
|
|
20457
|
-
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${
|
|
20456
|
+
this._startOrAuthSse(options).catch((error5) => {
|
|
20457
|
+
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error5 instanceof Error ? error5.message : String(error5)}`));
|
|
20458
20458
|
this._scheduleReconnection(options, attemptCount + 1);
|
|
20459
20459
|
});
|
|
20460
20460
|
}, delay);
|
|
@@ -20497,8 +20497,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
20497
20497
|
}
|
|
20498
20498
|
}
|
|
20499
20499
|
this.onmessage?.(message);
|
|
20500
|
-
} catch (
|
|
20501
|
-
this.onerror?.(
|
|
20500
|
+
} catch (error5) {
|
|
20501
|
+
this.onerror?.(error5);
|
|
20502
20502
|
}
|
|
20503
20503
|
}
|
|
20504
20504
|
}
|
|
@@ -20511,8 +20511,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
20511
20511
|
replayMessageId
|
|
20512
20512
|
}, 0);
|
|
20513
20513
|
}
|
|
20514
|
-
} catch (
|
|
20515
|
-
this.onerror?.(new Error(`SSE stream disconnected: ${
|
|
20514
|
+
} catch (error5) {
|
|
20515
|
+
this.onerror?.(new Error(`SSE stream disconnected: ${error5}`));
|
|
20516
20516
|
const canResume = isReconnectable || hasPrimingEvent;
|
|
20517
20517
|
const needsReconnect = canResume && !receivedResponse;
|
|
20518
20518
|
if (needsReconnect && this._abortController && !this._abortController.signal.aborted) {
|
|
@@ -20522,8 +20522,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
20522
20522
|
onresumptiontoken,
|
|
20523
20523
|
replayMessageId
|
|
20524
20524
|
}, 0);
|
|
20525
|
-
} catch (
|
|
20526
|
-
this.onerror?.(new Error(`Failed to reconnect: ${
|
|
20525
|
+
} catch (error6) {
|
|
20526
|
+
this.onerror?.(new Error(`Failed to reconnect: ${error6 instanceof Error ? error6.message : String(error6)}`));
|
|
20527
20527
|
}
|
|
20528
20528
|
}
|
|
20529
20529
|
}
|
|
@@ -20606,8 +20606,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
20606
20606
|
return this.send(message);
|
|
20607
20607
|
}
|
|
20608
20608
|
if (response.status === 403 && this._authProvider) {
|
|
20609
|
-
const { resourceMetadataUrl, scope, error:
|
|
20610
|
-
if (
|
|
20609
|
+
const { resourceMetadataUrl, scope, error: error5 } = extractWWWAuthenticateParams(response);
|
|
20610
|
+
if (error5 === "insufficient_scope") {
|
|
20611
20611
|
const wwwAuthHeader = response.headers.get("WWW-Authenticate");
|
|
20612
20612
|
if (this._lastUpscopingHeader === wwwAuthHeader) {
|
|
20613
20613
|
throw new StreamableHTTPError(403, "Server returned 403 after trying upscoping");
|
|
@@ -20662,9 +20662,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
20662
20662
|
} else {
|
|
20663
20663
|
await response.body?.cancel();
|
|
20664
20664
|
}
|
|
20665
|
-
} catch (
|
|
20666
|
-
this.onerror?.(
|
|
20667
|
-
throw
|
|
20665
|
+
} catch (error5) {
|
|
20666
|
+
this.onerror?.(error5);
|
|
20667
|
+
throw error5;
|
|
20668
20668
|
}
|
|
20669
20669
|
}
|
|
20670
20670
|
get sessionId() {
|
|
@@ -20699,9 +20699,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
20699
20699
|
throw new StreamableHTTPError(response.status, `Failed to terminate session: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
20700
20700
|
}
|
|
20701
20701
|
this._sessionId = void 0;
|
|
20702
|
-
} catch (
|
|
20703
|
-
this.onerror?.(
|
|
20704
|
-
throw
|
|
20702
|
+
} catch (error5) {
|
|
20703
|
+
this.onerror?.(error5);
|
|
20704
|
+
throw error5;
|
|
20705
20705
|
}
|
|
20706
20706
|
}
|
|
20707
20707
|
setProtocolVersion(version3) {
|
|
@@ -20815,7 +20815,7 @@ var BridgeCompatibilityError = class extends CreationClientError {
|
|
|
20815
20815
|
});
|
|
20816
20816
|
}
|
|
20817
20817
|
};
|
|
20818
|
-
var bridgeErrorDetails = (
|
|
20818
|
+
var bridgeErrorDetails = (error5) => error5 instanceof BridgeCompatibilityError ? error5.bridgeFacts : void 0;
|
|
20819
20819
|
function declaredHostContentCapabilities(capabilities, { initialized = false, standardContent = false } = {}) {
|
|
20820
20820
|
const requested = capabilities?.experimental?.["promptframe.contentTypes"];
|
|
20821
20821
|
if (requested === void 0 && initialized && standardContent)
|
|
@@ -20825,8 +20825,358 @@ function declaredHostContentCapabilities(capabilities, { initialized = false, st
|
|
|
20825
20825
|
}
|
|
20826
20826
|
var declaredHostContentTypes = (capabilities) => declaredHostContentCapabilities(capabilities).types;
|
|
20827
20827
|
|
|
20828
|
+
// lib/local-accounts.mjs
|
|
20829
|
+
import { constants as constants3 } from "node:fs";
|
|
20830
|
+
import { open as open4, lstat as lstat4, mkdir as mkdir3, rename as rename3, unlink as unlink3, opendir, link } from "node:fs/promises";
|
|
20831
|
+
import { homedir as homedir2 } from "node:os";
|
|
20832
|
+
import path5 from "node:path";
|
|
20833
|
+
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
20834
|
+
var LOCAL_ACCOUNT_DIRECTORY_VERSION = "promptframe-local-account-directory/v1";
|
|
20835
|
+
var LOCAL_AGENT_ACCOUNT_VERSION = "promptframe-local-agent-account/v1";
|
|
20836
|
+
var clients = ["creation", "component-cli"];
|
|
20837
|
+
var digestFormat = /^sha256:[a-f0-9]{64}$/;
|
|
20838
|
+
var hexFormat = /^[a-f0-9]{64}$/;
|
|
20839
|
+
var recordLimit = 16 * 1024;
|
|
20840
|
+
var hash = (value2) => "sha256:" + createHash3("sha256").update(value2).digest("hex");
|
|
20841
|
+
var failure3 = (code) => new CreationClientError("accounts." + code);
|
|
20842
|
+
var plain = (value2) => value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
20843
|
+
var date4 = (value2) => typeof value2 === "string" && Number.isFinite(Date.parse(value2));
|
|
20844
|
+
function localAccountsRoot(env = process.env) {
|
|
20845
|
+
return path5.resolve(env.PROMPTFRAME_ACCOUNT_DIRECTORY ?? path5.join(
|
|
20846
|
+
env.XDG_CONFIG_HOME ?? path5.join(homedir2(), ".config"),
|
|
20847
|
+
"promptframe",
|
|
20848
|
+
"accounts",
|
|
20849
|
+
"v1"
|
|
20850
|
+
));
|
|
20851
|
+
}
|
|
20852
|
+
function parseAccountIdentity(value2) {
|
|
20853
|
+
if (!plain(value2) || Object.keys(value2).length !== 3 || value2.contractVersion !== "promptframe-account-identity/v1" || !digestFormat.test(value2.platformDigest ?? "") || !digestFormat.test(value2.accountDigest ?? ""))
|
|
20854
|
+
throw failure3("identity_invalid");
|
|
20855
|
+
return { contractVersion: value2.contractVersion, platformDigest: value2.platformDigest, accountDigest: value2.accountDigest };
|
|
20856
|
+
}
|
|
20857
|
+
function localAccountKey(identity) {
|
|
20858
|
+
const value2 = parseAccountIdentity(identity);
|
|
20859
|
+
return value2.platformDigest.slice(7) + "-" + value2.accountDigest.slice(7);
|
|
20860
|
+
}
|
|
20861
|
+
function localReferenceId(client, configFile2) {
|
|
20862
|
+
if (!clients.includes(client) || typeof configFile2 !== "string" || !path5.isAbsolute(configFile2))
|
|
20863
|
+
throw failure3("reference_invalid");
|
|
20864
|
+
return hash(JSON.stringify([client, path5.resolve(configFile2)]));
|
|
20865
|
+
}
|
|
20866
|
+
function localCredentialDigest(token) {
|
|
20867
|
+
if (typeof token !== "string" || !token || token.length > 4096) throw failure3("reference_invalid");
|
|
20868
|
+
return hash(token);
|
|
20869
|
+
}
|
|
20870
|
+
function privateOwner(info5, directory3 = false) {
|
|
20871
|
+
const uid = process.getuid?.();
|
|
20872
|
+
if (uid === void 0 || info5.uid !== uid || (info5.mode & 63) !== 0 || info5.isSymbolicLink() || !(directory3 ? info5.isDirectory() : info5.isFile()))
|
|
20873
|
+
throw failure3("private_storage_required");
|
|
20874
|
+
}
|
|
20875
|
+
async function directory2(file, create = false) {
|
|
20876
|
+
if (create) await mkdir3(file, { recursive: true, mode: 448 });
|
|
20877
|
+
try {
|
|
20878
|
+
privateOwner(await lstat4(file), true);
|
|
20879
|
+
return true;
|
|
20880
|
+
} catch (error5) {
|
|
20881
|
+
if (!create && error5.code === "ENOENT") return false;
|
|
20882
|
+
throw error5;
|
|
20883
|
+
}
|
|
20884
|
+
}
|
|
20885
|
+
async function ownedPath(root, segments, create = false) {
|
|
20886
|
+
if (!await directory2(root, create)) return void 0;
|
|
20887
|
+
let current = root;
|
|
20888
|
+
for (const segment of segments) {
|
|
20889
|
+
current = path5.join(current, segment);
|
|
20890
|
+
if (!await directory2(current, create)) return void 0;
|
|
20891
|
+
}
|
|
20892
|
+
return current;
|
|
20893
|
+
}
|
|
20894
|
+
async function readJson(file) {
|
|
20895
|
+
let fd;
|
|
20896
|
+
try {
|
|
20897
|
+
fd = await open4(file, constants3.O_RDONLY | constants3.O_NOFOLLOW | (constants3.O_NONBLOCK ?? 0));
|
|
20898
|
+
const before = await fd.stat();
|
|
20899
|
+
privateOwner(before);
|
|
20900
|
+
if (before.size > recordLimit) throw failure3("record_too_large");
|
|
20901
|
+
const buffer = Buffer.alloc(recordLimit + 1);
|
|
20902
|
+
const { bytesRead } = await fd.read(buffer, 0, buffer.length, 0);
|
|
20903
|
+
const after = await fd.stat(), current = await lstat4(file);
|
|
20904
|
+
if (bytesRead !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || current.dev !== before.dev || current.ino !== before.ino) throw failure3("reference_changed");
|
|
20905
|
+
try {
|
|
20906
|
+
return JSON.parse(buffer.subarray(0, bytesRead).toString("utf8"));
|
|
20907
|
+
} catch {
|
|
20908
|
+
throw failure3("record_invalid");
|
|
20909
|
+
}
|
|
20910
|
+
} catch (error5) {
|
|
20911
|
+
if (error5.code === "ENOENT") return void 0;
|
|
20912
|
+
if (error5.code === "ELOOP") throw failure3("private_storage_required");
|
|
20913
|
+
throw error5;
|
|
20914
|
+
} finally {
|
|
20915
|
+
await fd?.close();
|
|
20916
|
+
}
|
|
20917
|
+
}
|
|
20918
|
+
async function writeJson(directoryPath, name, value2) {
|
|
20919
|
+
const payload = JSON.stringify(value2) + "\n";
|
|
20920
|
+
if (Buffer.byteLength(payload) > recordLimit) throw failure3("record_too_large");
|
|
20921
|
+
const parent = await open4(directoryPath, constants3.O_RDONLY | constants3.O_DIRECTORY | constants3.O_NOFOLLOW);
|
|
20922
|
+
const temporary = path5.join(directoryPath, "." + randomUUID() + ".tmp");
|
|
20923
|
+
try {
|
|
20924
|
+
const owner = await parent.stat();
|
|
20925
|
+
privateOwner(owner, true);
|
|
20926
|
+
const fd = await open4(temporary, constants3.O_WRONLY | constants3.O_CREAT | constants3.O_EXCL | constants3.O_NOFOLLOW, 384);
|
|
20927
|
+
try {
|
|
20928
|
+
await fd.writeFile(payload);
|
|
20929
|
+
await fd.sync();
|
|
20930
|
+
} finally {
|
|
20931
|
+
await fd.close();
|
|
20932
|
+
}
|
|
20933
|
+
const current = await lstat4(directoryPath);
|
|
20934
|
+
if (current.dev !== owner.dev || current.ino !== owner.ino) throw failure3("reference_changed");
|
|
20935
|
+
try {
|
|
20936
|
+
privateOwner(await lstat4(path5.join(directoryPath, name)));
|
|
20937
|
+
} catch (error5) {
|
|
20938
|
+
if (error5.code !== "ENOENT") throw error5;
|
|
20939
|
+
}
|
|
20940
|
+
await rename3(temporary, path5.join(directoryPath, name));
|
|
20941
|
+
await parent.sync();
|
|
20942
|
+
} finally {
|
|
20943
|
+
await parent.close();
|
|
20944
|
+
await unlink3(temporary).catch((error5) => {
|
|
20945
|
+
if (error5.code !== "ENOENT") throw error5;
|
|
20946
|
+
});
|
|
20947
|
+
}
|
|
20948
|
+
}
|
|
20949
|
+
function referencePath(identity, client) {
|
|
20950
|
+
const value2 = parseAccountIdentity(identity);
|
|
20951
|
+
if (!clients.includes(client)) throw failure3("reference_invalid");
|
|
20952
|
+
return ["identities", value2.platformDigest.slice(7), value2.accountDigest.slice(7), client];
|
|
20953
|
+
}
|
|
20954
|
+
function parseReference(value2, identity, client, id) {
|
|
20955
|
+
const fields = [
|
|
20956
|
+
"contractVersion",
|
|
20957
|
+
"identity",
|
|
20958
|
+
"client",
|
|
20959
|
+
"referenceId",
|
|
20960
|
+
"configFile",
|
|
20961
|
+
"endpoint",
|
|
20962
|
+
"credentialDigest",
|
|
20963
|
+
"observedAt",
|
|
20964
|
+
"expiresAt",
|
|
20965
|
+
"profile",
|
|
20966
|
+
"scopes"
|
|
20967
|
+
];
|
|
20968
|
+
if (!plain(value2) || Object.keys(value2).some((key) => !fields.includes(key)) || value2.contractVersion !== LOCAL_ACCOUNT_DIRECTORY_VERSION || value2.client !== client || value2.referenceId !== id || localAccountKey(value2.identity) !== localAccountKey(identity) || typeof value2.configFile !== "string" || value2.configFile.length > 4096 || localReferenceId(client, value2.configFile) !== id || !digestFormat.test(value2.credentialDigest ?? "") || !date4(value2.observedAt) || value2.expiresAt !== void 0 && !date4(value2.expiresAt) || value2.profile !== void 0 && (typeof value2.profile !== "string" || !/^[A-Za-z0-9._-]{1,80}$/.test(value2.profile)) || value2.scopes !== void 0 && (!Array.isArray(value2.scopes) || value2.scopes.length > 20 || value2.scopes.some((scope) => typeof scope !== "string" || !/^[a-z0-9_.:-]{1,100}$/.test(scope))))
|
|
20969
|
+
throw failure3("record_invalid");
|
|
20970
|
+
let endpoint;
|
|
20971
|
+
try {
|
|
20972
|
+
endpoint = new URL(value2.endpoint);
|
|
20973
|
+
} catch {
|
|
20974
|
+
throw failure3("record_invalid");
|
|
20975
|
+
}
|
|
20976
|
+
if (typeof value2.endpoint !== "string" || value2.endpoint.length > 500 || endpoint.username || endpoint.password || endpoint.search || endpoint.hash || endpoint.protocol !== "https:" && !(endpoint.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(endpoint.hostname)))
|
|
20977
|
+
throw failure3("record_invalid");
|
|
20978
|
+
return value2;
|
|
20979
|
+
}
|
|
20980
|
+
async function recordAuthorization({
|
|
20981
|
+
root = localAccountsRoot(),
|
|
20982
|
+
identity,
|
|
20983
|
+
client,
|
|
20984
|
+
configFile: configFile2,
|
|
20985
|
+
endpoint,
|
|
20986
|
+
token,
|
|
20987
|
+
observedAt = (/* @__PURE__ */ new Date()).toISOString(),
|
|
20988
|
+
expiresAt,
|
|
20989
|
+
profile,
|
|
20990
|
+
scopes
|
|
20991
|
+
}) {
|
|
20992
|
+
identity = parseAccountIdentity(identity);
|
|
20993
|
+
if (typeof configFile2 !== "string" || !path5.isAbsolute(configFile2)) throw failure3("reference_invalid");
|
|
20994
|
+
configFile2 = path5.resolve(configFile2);
|
|
20995
|
+
const referenceId = localReferenceId(client, configFile2);
|
|
20996
|
+
const record2 = parseReference({
|
|
20997
|
+
contractVersion: LOCAL_ACCOUNT_DIRECTORY_VERSION,
|
|
20998
|
+
identity,
|
|
20999
|
+
client,
|
|
21000
|
+
referenceId,
|
|
21001
|
+
configFile: configFile2,
|
|
21002
|
+
endpoint,
|
|
21003
|
+
credentialDigest: localCredentialDigest(token),
|
|
21004
|
+
observedAt,
|
|
21005
|
+
...expiresAt !== void 0 ? { expiresAt } : {},
|
|
21006
|
+
...profile !== void 0 ? { profile } : {},
|
|
21007
|
+
...scopes !== void 0 ? { scopes } : {}
|
|
21008
|
+
}, identity, client, referenceId);
|
|
21009
|
+
const parent = await ownedPath(root, referencePath(identity, client), true);
|
|
21010
|
+
await writeJson(parent, referenceId.slice(7) + ".json", record2);
|
|
21011
|
+
return { identityKey: localAccountKey(identity), referenceId };
|
|
21012
|
+
}
|
|
21013
|
+
async function readAuthorization({ root = localAccountsRoot(), identity, client, referenceId }) {
|
|
21014
|
+
if (!digestFormat.test(referenceId ?? "")) throw failure3("reference_invalid");
|
|
21015
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
21016
|
+
const value2 = parent ? await readJson(path5.join(parent, referenceId.slice(7) + ".json")) : void 0;
|
|
21017
|
+
return value2 === void 0 ? void 0 : parseReference(value2, identity, client, referenceId);
|
|
21018
|
+
}
|
|
21019
|
+
async function readAuthorizations({ root = localAccountsRoot(), identity, client }) {
|
|
21020
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
21021
|
+
if (!parent) return [];
|
|
21022
|
+
const records = [];
|
|
21023
|
+
for (const entry of await entries(parent)) {
|
|
21024
|
+
if (!/^[a-f0-9]{64}\.json$/.test(entry.name)) throw failure3("record_invalid");
|
|
21025
|
+
const value2 = await readLocalAuthorization({ root, identity, client, referenceId: "sha256:" + entry.name.slice(0, -5) });
|
|
21026
|
+
if (value2) records.push(value2);
|
|
21027
|
+
}
|
|
21028
|
+
return records.sort((a, b2) => a.referenceId.localeCompare(b2.referenceId));
|
|
21029
|
+
}
|
|
21030
|
+
async function entries(file) {
|
|
21031
|
+
const output = [];
|
|
21032
|
+
const handle = await opendir(file);
|
|
21033
|
+
for await (const entry of handle) {
|
|
21034
|
+
if (entry.name.startsWith(".")) continue;
|
|
21035
|
+
if (output.length === 256) throw failure3("listing_limit");
|
|
21036
|
+
output.push(entry);
|
|
21037
|
+
}
|
|
21038
|
+
return output;
|
|
21039
|
+
}
|
|
21040
|
+
async function listAccounts({ root = localAccountsRoot(), now = Date.now() } = {}) {
|
|
21041
|
+
const base = await ownedPath(root, ["identities"]);
|
|
21042
|
+
if (!base) return { accounts: [], complete: true };
|
|
21043
|
+
const accounts = [];
|
|
21044
|
+
for (const platform2 of await entries(base)) {
|
|
21045
|
+
if (!hexFormat.test(platform2.name)) throw failure3("record_invalid");
|
|
21046
|
+
const platformPath = await ownedPath(root, ["identities", platform2.name]);
|
|
21047
|
+
for (const account of await entries(platformPath)) {
|
|
21048
|
+
if (!hexFormat.test(account.name) || accounts.length === 256) throw failure3("listing_limit");
|
|
21049
|
+
const identity = {
|
|
21050
|
+
contractVersion: "promptframe-account-identity/v1",
|
|
21051
|
+
platformDigest: "sha256:" + platform2.name,
|
|
21052
|
+
accountDigest: "sha256:" + account.name
|
|
21053
|
+
};
|
|
21054
|
+
const grants = {};
|
|
21055
|
+
for (const client of clients) {
|
|
21056
|
+
grants[client] = [];
|
|
21057
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
21058
|
+
if (!parent) continue;
|
|
21059
|
+
for (const entry of await entries(parent)) {
|
|
21060
|
+
if (!/^[a-f0-9]{64}\.json$/.test(entry.name)) throw failure3("record_invalid");
|
|
21061
|
+
const ref = await readLocalAuthorization({ root, identity, client, referenceId: "sha256:" + entry.name.slice(0, -5) });
|
|
21062
|
+
if (!ref) continue;
|
|
21063
|
+
grants[client].push({
|
|
21064
|
+
referenceId: ref.referenceId,
|
|
21065
|
+
...ref.profile ? { profile: ref.profile } : {},
|
|
21066
|
+
status: ref.expiresAt && Date.parse(ref.expiresAt) <= now ? "expired" : "stored",
|
|
21067
|
+
observedAt: ref.observedAt,
|
|
21068
|
+
...ref.expiresAt ? { expiresAt: ref.expiresAt } : {}
|
|
21069
|
+
});
|
|
21070
|
+
}
|
|
21071
|
+
}
|
|
21072
|
+
accounts.push({
|
|
21073
|
+
identityKey: localAccountKey(identity),
|
|
21074
|
+
identity,
|
|
21075
|
+
grants,
|
|
21076
|
+
missingClients: clients.filter((client) => !grants[client].some((ref) => ref.status === "stored"))
|
|
21077
|
+
});
|
|
21078
|
+
}
|
|
21079
|
+
}
|
|
21080
|
+
return { accounts, complete: true };
|
|
21081
|
+
}
|
|
21082
|
+
function localAgentDigest(agent) {
|
|
21083
|
+
if (!agent || !["codex", "claude-code"].includes(agent.kind) || typeof agent.sessionId !== "string" || !threadFormat.test(agent.sessionId)) throw failure3("agent_required");
|
|
21084
|
+
return hash(JSON.stringify([agent.kind, agent.sessionId.toLowerCase()]));
|
|
21085
|
+
}
|
|
21086
|
+
async function selectAccount({ root = localAccountsRoot(), agent, identity }) {
|
|
21087
|
+
const agentDigest = localAgentDigest(agent);
|
|
21088
|
+
const parent = await ownedPath(root, ["selections"], true);
|
|
21089
|
+
const value2 = {
|
|
21090
|
+
contractVersion: LOCAL_AGENT_ACCOUNT_VERSION,
|
|
21091
|
+
agentKind: agent.kind,
|
|
21092
|
+
agentDigest,
|
|
21093
|
+
generation: randomUUID(),
|
|
21094
|
+
identity: parseAccountIdentity(identity),
|
|
21095
|
+
selectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
21096
|
+
};
|
|
21097
|
+
await writeJson(parent, agent.kind + "-" + agentDigest.slice(7) + ".json", value2);
|
|
21098
|
+
return value2;
|
|
21099
|
+
}
|
|
21100
|
+
async function readSelectedAccount({ root = localAccountsRoot(), agent }) {
|
|
21101
|
+
const agentDigest = localAgentDigest(agent), parent = await ownedPath(root, ["selections"]);
|
|
21102
|
+
const value2 = parent ? await readJson(path5.join(parent, agent.kind + "-" + agentDigest.slice(7) + ".json")) : void 0;
|
|
21103
|
+
if (value2 === void 0) return void 0;
|
|
21104
|
+
if (!plain(value2) || Object.keys(value2).length !== 6 || value2.contractVersion !== LOCAL_AGENT_ACCOUNT_VERSION || value2.agentKind !== agent.kind || value2.agentDigest !== agentDigest || !threadFormat.test(value2.generation ?? "") || !date4(value2.selectedAt)) throw failure3("record_invalid");
|
|
21105
|
+
return { ...value2, identity: parseAccountIdentity(value2.identity) };
|
|
21106
|
+
}
|
|
21107
|
+
var accountIO = (operation) => async (...args2) => {
|
|
21108
|
+
try {
|
|
21109
|
+
return await operation(...args2);
|
|
21110
|
+
} catch (cause) {
|
|
21111
|
+
if (cause instanceof CreationClientError) throw cause;
|
|
21112
|
+
throw failure3(["EACCES", "EPERM", "ENOTDIR", "ELOOP"].includes(cause?.code) ? "private_storage_required" : "storage_unavailable");
|
|
21113
|
+
}
|
|
21114
|
+
};
|
|
21115
|
+
var recordLocalAuthorization = accountIO(recordAuthorization);
|
|
21116
|
+
var readLocalAuthorization = accountIO(readAuthorization);
|
|
21117
|
+
var readLocalAuthorizations = accountIO(readAuthorizations);
|
|
21118
|
+
var listLocalAccounts = accountIO(listAccounts);
|
|
21119
|
+
var selectLocalAccount = accountIO(selectAccount);
|
|
21120
|
+
var readSelectedLocalAccount = accountIO(readSelectedAccount);
|
|
21121
|
+
async function clientObservationInstance({ root = localAccountsRoot(), identity, configFile: configFile2 }) {
|
|
21122
|
+
identity = parseAccountIdentity(identity);
|
|
21123
|
+
if (typeof configFile2 !== "string" || !path5.isAbsolute(configFile2)) throw failure3("reference_invalid");
|
|
21124
|
+
const parent = await ownedPath(root, ["client-observations", "v1", identity.platformDigest.slice(7), identity.accountDigest.slice(7)], true);
|
|
21125
|
+
const file = path5.join(parent, localReferenceId("creation", path5.resolve(configFile2)).slice(7) + ".json");
|
|
21126
|
+
const parse4 = (value3) => {
|
|
21127
|
+
if (!plain(value3) || Object.keys(value3).sort().join(",") !== "contractVersion,instanceId" || value3.contractVersion !== "promptframe-client-instance/v1" || typeof value3.instanceId !== "string" || !/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(value3.instanceId)) throw failure3("record_invalid");
|
|
21128
|
+
return value3.instanceId;
|
|
21129
|
+
};
|
|
21130
|
+
const existing = await readJson(file);
|
|
21131
|
+
if (existing) return parse4(existing);
|
|
21132
|
+
const value2 = { contractVersion: "promptframe-client-instance/v1", instanceId: randomUUID() };
|
|
21133
|
+
const temporary = path5.join(parent, "." + randomUUID() + ".tmp");
|
|
21134
|
+
let fd;
|
|
21135
|
+
try {
|
|
21136
|
+
fd = await open4(temporary, constants3.O_WRONLY | constants3.O_CREAT | constants3.O_EXCL | constants3.O_NOFOLLOW, 384);
|
|
21137
|
+
await fd.writeFile(JSON.stringify(value2) + "\n");
|
|
21138
|
+
await fd.sync();
|
|
21139
|
+
await fd.close();
|
|
21140
|
+
fd = void 0;
|
|
21141
|
+
await link(temporary, file);
|
|
21142
|
+
const directoryHandle = await open4(parent, constants3.O_RDONLY | constants3.O_DIRECTORY | constants3.O_NOFOLLOW);
|
|
21143
|
+
try {
|
|
21144
|
+
privateOwner(await directoryHandle.stat(), true);
|
|
21145
|
+
await directoryHandle.sync();
|
|
21146
|
+
} finally {
|
|
21147
|
+
await directoryHandle.close();
|
|
21148
|
+
}
|
|
21149
|
+
return value2.instanceId;
|
|
21150
|
+
} catch (error5) {
|
|
21151
|
+
if (error5.code === "EEXIST") return parse4(await readJson(file));
|
|
21152
|
+
throw error5;
|
|
21153
|
+
} finally {
|
|
21154
|
+
await fd?.close();
|
|
21155
|
+
await unlink3(temporary).catch((error5) => {
|
|
21156
|
+
if (error5.code !== "ENOENT") throw error5;
|
|
21157
|
+
});
|
|
21158
|
+
}
|
|
21159
|
+
}
|
|
21160
|
+
var localClientObservationInstance = accountIO(clientObservationInstance);
|
|
21161
|
+
|
|
20828
21162
|
// lib/connection.mjs
|
|
20829
|
-
|
|
21163
|
+
import path6 from "node:path";
|
|
21164
|
+
function connectionAccountIdentity(client, expected) {
|
|
21165
|
+
const raw = client.getServerCapabilities()?.experimental?.["promptframe.accountIdentity"];
|
|
21166
|
+
if (raw === void 0) {
|
|
21167
|
+
if (expected) throw new CreationClientError("accounts.identity_unavailable");
|
|
21168
|
+
return void 0;
|
|
21169
|
+
}
|
|
21170
|
+
const actual = parseAccountIdentity(raw);
|
|
21171
|
+
if (expected) {
|
|
21172
|
+
expected = parseAccountIdentity(expected);
|
|
21173
|
+
if (actual.platformDigest !== expected.platformDigest) throw new CreationClientError("accounts.platform_mismatch");
|
|
21174
|
+
if (actual.accountDigest !== expected.accountDigest) throw new CreationClientError("accounts.account_mismatch");
|
|
21175
|
+
}
|
|
21176
|
+
return actual;
|
|
21177
|
+
}
|
|
21178
|
+
async function connectPlatform(credentials, { host = resolveHostIdentity(), contentTypes = () => ["text"], contentSource = () => "text-fallback", enforceMinimum = true, signal, expectedIdentity, clientConfigFile, observationRoot } = {}) {
|
|
21179
|
+
let observation;
|
|
20830
21180
|
const client = new Client(
|
|
20831
21181
|
{ name: "promptframe-creation-bridge", version: CLIENT_VERSION },
|
|
20832
21182
|
{ capabilities: {} }
|
|
@@ -20839,6 +21189,7 @@ async function connectPlatform(credentials, { host = resolveHostIdentity(), cont
|
|
|
20839
21189
|
const types = declaredHostContentTypes({ experimental: { "promptframe.contentTypes": contentTypes() } });
|
|
20840
21190
|
headers.set("X-PromptFrame-Content-Types", JSON.stringify(types));
|
|
20841
21191
|
headers.set("X-PromptFrame-Content-Source", contentSource());
|
|
21192
|
+
if (observation) headers.set("X-PromptFrame-Client-Observation", encodeURIComponent(JSON.stringify(observation)));
|
|
20842
21193
|
return fetch(url2, { ...init, headers, ...signal ? { signal: init?.signal ? AbortSignal.any([init.signal, signal]) : signal } : {} });
|
|
20843
21194
|
},
|
|
20844
21195
|
requestInit: {
|
|
@@ -20857,32 +21208,52 @@ async function connectPlatform(credentials, { host = resolveHostIdentity(), cont
|
|
|
20857
21208
|
);
|
|
20858
21209
|
try {
|
|
20859
21210
|
await client.connect(transport2, signal ? { signal } : void 0);
|
|
21211
|
+
const identity = connectionAccountIdentity(client, expectedIdentity);
|
|
21212
|
+
if (identity && clientConfigFile) try {
|
|
21213
|
+
const instanceId = await localClientObservationInstance({
|
|
21214
|
+
identity,
|
|
21215
|
+
configFile: clientConfigFile,
|
|
21216
|
+
root: observationRoot ?? path6.join(path6.dirname(clientConfigFile), "client-observations")
|
|
21217
|
+
});
|
|
21218
|
+
const systemFamily = process.platform === "win32" ? "Windows" : process.platform === "darwin" ? "macOS" : process.platform === "linux" ? process.env.WSL_INTEROP || process.env.WSL_DISTRO_NAME ? "WSL" : "Linux" : "unknown";
|
|
21219
|
+
observation = {
|
|
21220
|
+
contractVersion: "promptframe-client-observation/v1",
|
|
21221
|
+
instanceId,
|
|
21222
|
+
systemFamily,
|
|
21223
|
+
application: host.kind === "claude-code" ? "Claude Code" : host.kind === "codex" ? "Codex" : "Creation",
|
|
21224
|
+
applicationVersion: CLIENT_VERSION
|
|
21225
|
+
};
|
|
21226
|
+
} catch {
|
|
21227
|
+
}
|
|
20860
21228
|
if (enforceMinimum) assertBridgeCompatible(client.getServerCapabilities(), CLIENT_VERSION);
|
|
20861
21229
|
else readPlatformBridgePolicy(client.getServerCapabilities());
|
|
20862
21230
|
return client;
|
|
20863
|
-
} catch (
|
|
21231
|
+
} catch (error5) {
|
|
20864
21232
|
await client.close().catch(() => {
|
|
20865
21233
|
});
|
|
20866
|
-
throw
|
|
21234
|
+
throw error5;
|
|
20867
21235
|
}
|
|
20868
21236
|
}
|
|
20869
21237
|
|
|
21238
|
+
// lib/account-bridge.mjs
|
|
21239
|
+
import path10 from "node:path";
|
|
21240
|
+
|
|
20870
21241
|
// lib/host-context.mjs
|
|
20871
|
-
import { createHash as
|
|
21242
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
20872
21243
|
|
|
20873
21244
|
// lib/claude-host-session.mjs
|
|
20874
|
-
import { constants as
|
|
20875
|
-
import { open as
|
|
20876
|
-
import
|
|
20877
|
-
import { homedir as
|
|
20878
|
-
import { createHash as
|
|
21245
|
+
import { constants as constants4 } from "node:fs";
|
|
21246
|
+
import { open as open5, mkdir as mkdir4, lstat as lstat5, rename as rename4, unlink as unlink4, rmdir as rmdir2 } from "node:fs/promises";
|
|
21247
|
+
import path8 from "node:path";
|
|
21248
|
+
import { homedir as homedir4 } from "node:os";
|
|
21249
|
+
import { createHash as createHash5, randomBytes as randomBytes3 } from "node:crypto";
|
|
20879
21250
|
|
|
20880
21251
|
// lib/claude-host-process.mjs
|
|
20881
21252
|
import { readFile as readFile3, readlink, stat } from "node:fs/promises";
|
|
20882
|
-
import
|
|
20883
|
-
import { homedir as
|
|
20884
|
-
import { createHash as
|
|
20885
|
-
var
|
|
21253
|
+
import path7 from "node:path";
|
|
21254
|
+
import { homedir as homedir3 } from "node:os";
|
|
21255
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
21256
|
+
var hash2 = (value2) => createHash4("sha256").update(JSON.stringify(value2)).digest("hex");
|
|
20886
21257
|
var bounded = async (file) => {
|
|
20887
21258
|
const value2 = await readFile3(file);
|
|
20888
21259
|
if (value2.length > 65536) throw Error("host_process_invalid");
|
|
@@ -20897,7 +21268,7 @@ async function processBirth(pid) {
|
|
|
20897
21268
|
async function claudeHostProcess({
|
|
20898
21269
|
pid = process.pid,
|
|
20899
21270
|
env = process.env,
|
|
20900
|
-
home =
|
|
21271
|
+
home = homedir3(),
|
|
20901
21272
|
readBirth = processBirth,
|
|
20902
21273
|
readExecutable = stat,
|
|
20903
21274
|
readBoot = async () => (await bounded("/proc/sys/kernel/random/boot_id")).toString().trim(),
|
|
@@ -20913,8 +21284,8 @@ async function claudeHostProcess({
|
|
|
20913
21284
|
if (visited.has(child.ppid)) return null;
|
|
20914
21285
|
visited.add(child.ppid);
|
|
20915
21286
|
const host = await readBirth(child.ppid);
|
|
20916
|
-
const roots2 = [
|
|
20917
|
-
if (roots2.some((root) =>
|
|
21287
|
+
const roots2 = [path7.join(home, ".claude", "remote", "ccd-cli"), path7.join(home, ".local", "share", "claude", "versions")];
|
|
21288
|
+
if (roots2.some((root) => path7.dirname(host.exe) === root)) {
|
|
20918
21289
|
const executable = await readExecutable(host.exe);
|
|
20919
21290
|
if (host.uid !== uid || ![uid, 0].includes(executable.uid) || !executable.isFile() || executable.mode & 18 || host.inode !== executable.ino || host.device !== executable.dev) return null;
|
|
20920
21291
|
if (purpose === "hook") {
|
|
@@ -20922,7 +21293,7 @@ async function claudeHostProcess({
|
|
|
20922
21293
|
if (!entryFile || !command2.some((arg) => arg.includes(entryFile)) || !command2.some((arg) => arg === "claude-host-hook" || arg.includes(" claude-host-hook"))) return null;
|
|
20923
21294
|
}
|
|
20924
21295
|
const binding = { pid: host.pid, birth: host.birth, uid, device: host.device, inode: host.inode, exe: host.exe, boot };
|
|
20925
|
-
const digest5 =
|
|
21296
|
+
const digest5 = hash2(binding);
|
|
20926
21297
|
return { binding, digest: digest5, eventOrder: { birth: child.birth, pid: child.pid }, async isCurrent() {
|
|
20927
21298
|
try {
|
|
20928
21299
|
const current = await readBirth(binding.pid);
|
|
@@ -20951,22 +21322,22 @@ var canonical = (value2) => {
|
|
|
20951
21322
|
return "{" + Object.keys(value2).sort().map((key) => JSON.stringify(key) + ":" + canonical(value2[key])).join(",") + "}";
|
|
20952
21323
|
throw error2("request_invalid");
|
|
20953
21324
|
};
|
|
20954
|
-
var digest2 = (value2) =>
|
|
21325
|
+
var digest2 = (value2) => createHash5("sha256").update(canonical(value2)).digest("hex");
|
|
20955
21326
|
var withoutProof = (args2) => Object.fromEntries(Object.entries(args2 ?? {}).filter(([key]) => key !== CLAUDE_HOST_PROOF));
|
|
20956
21327
|
var later = (a, b2) => BigInt(a.birth) > BigInt(b2.birth) || a.birth === b2.birth && a.pid > b2.pid;
|
|
20957
|
-
async function privateDirectory(
|
|
21328
|
+
async function privateDirectory(directory3) {
|
|
20958
21329
|
try {
|
|
20959
|
-
await
|
|
21330
|
+
await mkdir4(directory3, { mode: 448 });
|
|
20960
21331
|
} catch (e) {
|
|
20961
21332
|
if (e.code !== "EEXIST") throw e;
|
|
20962
21333
|
}
|
|
20963
|
-
const info5 = await
|
|
21334
|
+
const info5 = await lstat5(directory3);
|
|
20964
21335
|
if (!info5.isDirectory() || info5.isSymbolicLink() || info5.uid !== process.getuid?.() || info5.mode & 63) throw error2("host_identity_unavailable");
|
|
20965
21336
|
}
|
|
20966
21337
|
async function privateRead(file) {
|
|
20967
21338
|
let handle;
|
|
20968
21339
|
try {
|
|
20969
|
-
handle = await
|
|
21340
|
+
handle = await open5(file, constants4.O_RDONLY | constants4.O_NOFOLLOW);
|
|
20970
21341
|
const info5 = await handle.stat();
|
|
20971
21342
|
if (!info5.isFile() || info5.uid !== process.getuid?.() || info5.mode & 63 || info5.size > 196608) throw error2("host_identity_unavailable");
|
|
20972
21343
|
return JSON.parse(await handle.readFile("utf8"));
|
|
@@ -20979,9 +21350,9 @@ async function privateRead(file) {
|
|
|
20979
21350
|
}
|
|
20980
21351
|
async function createClaudeHostSession({ configFile: configFile2, env = process.env, root, association, hookProcess = false } = {}) {
|
|
20981
21352
|
const owner = association === void 0 ? await claudeHostProcess({ env, purpose: hookProcess ? "hook" : "bridge" }) : association;
|
|
20982
|
-
const base = root ??
|
|
20983
|
-
const namespace = owner ?
|
|
20984
|
-
const stateFile = namespace &&
|
|
21353
|
+
const base = root ?? path8.join(env.CLAUDE_CONFIG_DIR ?? path8.join(homedir4(), ".claude"), "promptframe-host-sessions");
|
|
21354
|
+
const namespace = owner ? path8.join(base, digest2([owner.digest, path8.resolve(configFile2)])) : null;
|
|
21355
|
+
const stateFile = namespace && path8.join(namespace, "state.json");
|
|
20985
21356
|
async function state() {
|
|
20986
21357
|
if (!owner || !await owner.isCurrent()) return null;
|
|
20987
21358
|
const value2 = await privateRead(stateFile);
|
|
@@ -20993,10 +21364,10 @@ async function createClaudeHostSession({ configFile: configFile2, env = process.
|
|
|
20993
21364
|
if (!owner || !await owner.isCurrent()) throw error2("host_identity_unavailable");
|
|
20994
21365
|
await privateDirectory(base);
|
|
20995
21366
|
await privateDirectory(namespace);
|
|
20996
|
-
const lock =
|
|
21367
|
+
const lock = path8.join(namespace, "write.lock");
|
|
20997
21368
|
let acquired = false;
|
|
20998
21369
|
for (let count = 0; count < 100; count++) try {
|
|
20999
|
-
await
|
|
21370
|
+
await mkdir4(lock, { mode: 448 });
|
|
21000
21371
|
acquired = true;
|
|
21001
21372
|
break;
|
|
21002
21373
|
} catch (e) {
|
|
@@ -21010,13 +21381,13 @@ async function createClaudeHostSession({ configFile: configFile2, env = process.
|
|
|
21010
21381
|
const current = await state(), next = await work(current);
|
|
21011
21382
|
if (next === void 0) return;
|
|
21012
21383
|
if (next === null) {
|
|
21013
|
-
if (current) await
|
|
21384
|
+
if (current) await unlink4(stateFile);
|
|
21014
21385
|
return;
|
|
21015
21386
|
}
|
|
21016
21387
|
const body = JSON.stringify(next);
|
|
21017
21388
|
if (Buffer.byteLength(body) > 196608) throw error2("host_identity_unavailable");
|
|
21018
|
-
temporary =
|
|
21019
|
-
const file = await
|
|
21389
|
+
temporary = path8.join(namespace, "state-" + randomBytes3(16).toString("hex") + ".partial");
|
|
21390
|
+
const file = await open5(temporary, constants4.O_WRONLY | constants4.O_CREAT | constants4.O_EXCL | constants4.O_NOFOLLOW, 384);
|
|
21020
21391
|
try {
|
|
21021
21392
|
await file.writeFile(body);
|
|
21022
21393
|
await file.sync();
|
|
@@ -21024,16 +21395,16 @@ async function createClaudeHostSession({ configFile: configFile2, env = process.
|
|
|
21024
21395
|
await file.close();
|
|
21025
21396
|
}
|
|
21026
21397
|
if (!await owner.isCurrent()) throw error2("host_identity_unavailable");
|
|
21027
|
-
await
|
|
21398
|
+
await rename4(temporary, stateFile);
|
|
21028
21399
|
temporary = void 0;
|
|
21029
|
-
const
|
|
21400
|
+
const directory3 = await open5(namespace, constants4.O_RDONLY | constants4.O_DIRECTORY | constants4.O_NOFOLLOW);
|
|
21030
21401
|
try {
|
|
21031
|
-
await
|
|
21402
|
+
await directory3.sync();
|
|
21032
21403
|
} finally {
|
|
21033
|
-
await
|
|
21404
|
+
await directory3.close();
|
|
21034
21405
|
}
|
|
21035
21406
|
} finally {
|
|
21036
|
-
if (temporary) await
|
|
21407
|
+
if (temporary) await unlink4(temporary).catch(() => {
|
|
21037
21408
|
});
|
|
21038
21409
|
await rmdir2(lock);
|
|
21039
21410
|
}
|
|
@@ -21137,18 +21508,18 @@ async function runClaudeHostHook({ configFile: configFile2, input = process.stdi
|
|
|
21137
21508
|
}
|
|
21138
21509
|
|
|
21139
21510
|
// lib/development-pairing.mjs
|
|
21140
|
-
import { open as
|
|
21141
|
-
import { constants as
|
|
21142
|
-
import
|
|
21511
|
+
import { open as open6, stat as stat2 } from "node:fs/promises";
|
|
21512
|
+
import { constants as constants5 } from "node:fs";
|
|
21513
|
+
import path9 from "node:path";
|
|
21143
21514
|
async function readDevelopmentPairingFile(filePath, { signal } = {}) {
|
|
21144
21515
|
const fail8 = () => {
|
|
21145
21516
|
throw new CreationClientError("creation.development_pairing.private_file_unavailable");
|
|
21146
21517
|
};
|
|
21147
|
-
if (typeof filePath !== "string" || filePath.length > 4096 || !
|
|
21518
|
+
if (typeof filePath !== "string" || filePath.length > 4096 || !path9.isAbsolute(filePath)) fail8();
|
|
21148
21519
|
let file;
|
|
21149
21520
|
try {
|
|
21150
21521
|
signal?.throwIfAborted();
|
|
21151
|
-
file = await
|
|
21522
|
+
file = await open6(filePath, constants5.O_RDONLY | constants5.O_NOFOLLOW | constants5.O_NONBLOCK);
|
|
21152
21523
|
const before = await file.stat();
|
|
21153
21524
|
if (!before.isFile() || before.size < 2 || before.size > 8192 || process.platform !== "win32" && ((before.mode & 63) !== 0 || before.uid !== process.getuid())) fail8();
|
|
21154
21525
|
const bytes2 = Buffer.alloc(before.size);
|
|
@@ -21175,7 +21546,7 @@ async function readDevelopmentPairingFile(filePath, { signal } = {}) {
|
|
|
21175
21546
|
// lib/host-context.mjs
|
|
21176
21547
|
var digestPattern = /^sha256:[a-f0-9]{64}$/;
|
|
21177
21548
|
var accesses = /* @__PURE__ */ new Set(["independent-read", "controlled", "authority"]);
|
|
21178
|
-
var digest3 = (value2) => "sha256:" +
|
|
21549
|
+
var digest3 = (value2) => "sha256:" + createHash6("sha256").update(value2).digest("hex");
|
|
21179
21550
|
var canonical2 = (value2) => {
|
|
21180
21551
|
if (value2 === null || typeof value2 === "string" || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2)) return JSON.stringify(value2);
|
|
21181
21552
|
if (Array.isArray(value2)) return "[" + value2.map(canonical2).join(",") + "]";
|
|
@@ -21188,6 +21559,20 @@ var boundedSet = (map, key, value2) => {
|
|
|
21188
21559
|
if (!map.has(key) && map.size >= 1024) map.delete(map.keys().next().value);
|
|
21189
21560
|
map.set(key, value2);
|
|
21190
21561
|
};
|
|
21562
|
+
async function resolveHostCallBinding(raw, { host = resolveHostIdentity(), hostSession } = {}) {
|
|
21563
|
+
for (const field of ["threadId", "controller", "clientDigest", "token", "controlVersion", "developmentPairing"]) if (Object.hasOwn(raw.arguments ?? {}, field))
|
|
21564
|
+
throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
21565
|
+
if (host.kind === "claude-code") {
|
|
21566
|
+
if (hostSession) return hostSession.begin(raw);
|
|
21567
|
+
if (raw.arguments?.[CLAUDE_HOST_PROOF] !== void 0) throw new CreationClientError("creation.host_identity_invalid");
|
|
21568
|
+
return { host: { kind: "claude-code" }, arguments: raw.arguments, assertCurrent: async () => {
|
|
21569
|
+
} };
|
|
21570
|
+
}
|
|
21571
|
+
if (Object.hasOwn(raw.arguments ?? {}, CLAUDE_HOST_PROOF)) throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
21572
|
+
hostParameters(raw, host, "independent-read");
|
|
21573
|
+
return { host, arguments: raw.arguments, assertCurrent: async () => {
|
|
21574
|
+
} };
|
|
21575
|
+
}
|
|
21191
21576
|
function createHostCallBridge(client, { credentials, host = resolveHostIdentity(), hostSession, localUploads, onCatalogChange = () => {
|
|
21192
21577
|
}, onKnowledgeChange = () => {
|
|
21193
21578
|
} } = {}) {
|
|
@@ -21195,7 +21580,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21195
21580
|
const installationDigest = digest3(credentials.clientId);
|
|
21196
21581
|
const versions = /* @__PURE__ */ new Map(), controllers = /* @__PURE__ */ new Map(), catalogs = /* @__PURE__ */ new Map(), inflight = /* @__PURE__ */ new Map();
|
|
21197
21582
|
const knowledgeVersions = /* @__PURE__ */ new Map(), upstream = client.getServerCapabilities?.() ?? {};
|
|
21198
|
-
let platformDigest, accountDigest,
|
|
21583
|
+
let platformDigest, accountDigest, directory3, directoryRead, sequence = 0, hostEpoch;
|
|
21199
21584
|
function catalog(channel, version3, order) {
|
|
21200
21585
|
if (typeof version3 !== "string" || !digestPattern.test(version3)) return;
|
|
21201
21586
|
const old = catalogs.get(channel);
|
|
@@ -21230,7 +21615,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21230
21615
|
const key = keyFor(target), c = v2.control;
|
|
21231
21616
|
if (!key || !c || !Number.isSafeInteger(c.controlVersion) || c.controlVersion <= 0 || !["web", "client"].includes(c.editor?.kind) || typeof c.editor.isCurrentClient !== "boolean" || c.editor.kind === "web" && c.editor.isCurrentClient) return v2;
|
|
21232
21617
|
const old = versions.get(key), version3 = c.controlVersion, owned = c.editor.kind === "client" && c.editor.isCurrentClient;
|
|
21233
|
-
const authorityRead =
|
|
21618
|
+
const authorityRead = directory3?.tools.get(params.name)?._meta?.["promptframe.role"] === "control-read";
|
|
21234
21619
|
if (!old || version3 > old.version) boundedSet(versions, key, { version: version3, owned, needsRead: false, authorityOrder: order });
|
|
21235
21620
|
else if (version3 === old.version && order >= (old.authorityOrder ?? 0)) {
|
|
21236
21621
|
const freshRead = !result.isError && authorityRead && order > (old.invalidatedAt ?? 0);
|
|
@@ -21248,7 +21633,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21248
21633
|
async function listTools() {
|
|
21249
21634
|
const order = ++sequence, result = assertMcpResponseBudget(await client.listTools());
|
|
21250
21635
|
if (result.tools.some((tool) => !accesses.has(tool._meta?.["promptframe.access"]))) throw new CreationClientError("creation.upgrade_required");
|
|
21251
|
-
if (!
|
|
21636
|
+
if (!directory3 || order >= directory3.order) directory3 = { tools: new Map(result.tools.map((t) => [t.name, t])), order };
|
|
21252
21637
|
catalog("outer", result._meta?.["promptframe.catalogVersion"], order);
|
|
21253
21638
|
return { ...result, tools: result.tools.map((tool) => {
|
|
21254
21639
|
const local = tool._meta?.["promptframe.localFileUpload"];
|
|
@@ -21262,7 +21647,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21262
21647
|
}) };
|
|
21263
21648
|
}
|
|
21264
21649
|
async function ensureDirectory() {
|
|
21265
|
-
if (!
|
|
21650
|
+
if (!directory3) {
|
|
21266
21651
|
directoryRead ??= listTools().finally(() => {
|
|
21267
21652
|
directoryRead = void 0;
|
|
21268
21653
|
});
|
|
@@ -21270,7 +21655,7 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21270
21655
|
}
|
|
21271
21656
|
}
|
|
21272
21657
|
function role(name) {
|
|
21273
|
-
const found = [...
|
|
21658
|
+
const found = [...directory3.tools.values()].filter((t) => t._meta?.["promptframe.role"] === name);
|
|
21274
21659
|
if (found.length !== 1) throw new CreationClientError("creation.upgrade_required");
|
|
21275
21660
|
return found[0].name;
|
|
21276
21661
|
}
|
|
@@ -21317,27 +21702,23 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21317
21702
|
listPrompts: (params) => knowledgeRead("prompts", "listPrompts", params),
|
|
21318
21703
|
getPrompt: (params) => knowledgeRead("prompts", "getPrompt", params),
|
|
21319
21704
|
close: () => localUploads?.close(),
|
|
21320
|
-
async call(raw, { signal } = {}) {
|
|
21705
|
+
async call(raw, { signal, resolvedBinding } = {}) {
|
|
21321
21706
|
for (const field of ["threadId", "controller", "clientDigest", "token", "controlVersion", "developmentPairing"]) if (Object.hasOwn(raw.arguments ?? {}, field))
|
|
21322
21707
|
throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
21323
|
-
|
|
21324
|
-
|
|
21708
|
+
const binding = resolvedBinding ?? await resolveHostCallBinding(raw, { host, hostSession });
|
|
21709
|
+
if (binding.host.kind !== host.kind) throw new CreationClientError("creation.host_identity_invalid");
|
|
21325
21710
|
if (host.kind === "claude-code") {
|
|
21326
|
-
if (hostSession) binding = await hostSession.begin(raw);
|
|
21327
|
-
else if (raw.arguments?.[CLAUDE_HOST_PROOF] !== void 0) throw new CreationClientError("creation.host_identity_invalid");
|
|
21328
|
-
else binding = { host: { kind: "claude-code" }, arguments: raw.arguments, assertCurrent: async () => {
|
|
21329
|
-
} };
|
|
21330
21711
|
if (binding.epoch !== hostEpoch) {
|
|
21331
21712
|
versions.clear();
|
|
21332
21713
|
controllers.clear();
|
|
21333
21714
|
inflight.clear();
|
|
21334
21715
|
hostEpoch = binding.epoch;
|
|
21335
21716
|
}
|
|
21336
|
-
}
|
|
21717
|
+
}
|
|
21337
21718
|
raw = { ...raw, arguments: binding.arguments };
|
|
21338
21719
|
await ensureDirectory();
|
|
21339
21720
|
await binding.assertCurrent();
|
|
21340
|
-
const definition =
|
|
21721
|
+
const definition = directory3.tools.get(raw.name);
|
|
21341
21722
|
if (!definition) throw new CreationClientError("creation.tool_unavailable");
|
|
21342
21723
|
const access2 = definition._meta["promptframe.access"], managed = Object.hasOwn(definition.inputSchema.properties ?? {}, "controlVersion");
|
|
21343
21724
|
let params = hostParameters(raw, binding.host, "independent-read");
|
|
@@ -21418,9 +21799,9 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21418
21799
|
let response;
|
|
21419
21800
|
try {
|
|
21420
21801
|
response = await send(outgoing, binding);
|
|
21421
|
-
} catch (
|
|
21802
|
+
} catch (error5) {
|
|
21422
21803
|
invalidate();
|
|
21423
|
-
throw
|
|
21804
|
+
throw error5;
|
|
21424
21805
|
}
|
|
21425
21806
|
if (response.result.isError) invalidate();
|
|
21426
21807
|
return response.result;
|
|
@@ -21428,8 +21809,168 @@ function createHostCallBridge(client, { credentials, host = resolveHostIdentity(
|
|
|
21428
21809
|
};
|
|
21429
21810
|
}
|
|
21430
21811
|
|
|
21812
|
+
// lib/account-bridge.mjs
|
|
21813
|
+
var listName = "promptframe_local_accounts";
|
|
21814
|
+
var selectName = "promptframe_local_select_account";
|
|
21815
|
+
var error3 = (code) => new CreationClientError("accounts." + code);
|
|
21816
|
+
var sameIdentity = (a, b2) => a && b2 && localAccountKey(a) === localAccountKey(b2);
|
|
21817
|
+
function identityFromKey(key) {
|
|
21818
|
+
if (typeof key !== "string" || !/^[a-f0-9]{64}-[a-f0-9]{64}$/.test(key)) throw error3("identity_invalid");
|
|
21819
|
+
return {
|
|
21820
|
+
contractVersion: "promptframe-account-identity/v1",
|
|
21821
|
+
platformDigest: "sha256:" + key.slice(0, 64),
|
|
21822
|
+
accountDigest: "sha256:" + key.slice(65)
|
|
21823
|
+
};
|
|
21824
|
+
}
|
|
21825
|
+
function localTool(name, host) {
|
|
21826
|
+
const properties = name === selectName ? {
|
|
21827
|
+
identityKey: { type: "string", pattern: "^[a-f0-9]{64}-[a-f0-9]{64}$" },
|
|
21828
|
+
referenceId: { type: "string", pattern: "^sha256:[a-f0-9]{64}$", description: "\u540C\u4E00\u8D26\u53F7\u6709\u591A\u4EFD\u521B\u4F5C\u6388\u6743\u65F6\u53EF\u660E\u786E\u9009\u62E9\u5217\u8868\u4E2D\u7684\u5F15\u7528\u3002" }
|
|
21829
|
+
} : {};
|
|
21830
|
+
if (host.kind === "claude-code") properties[CLAUDE_HOST_PROOF] = { type: "string", pattern: "^[a-f0-9]{64}$", description: "\u7531\u5F53\u524D\u5BBF\u4E3Bhook\u586B\u5165\uFF0C\u4FDD\u7559\u539F\u503C\u3002" };
|
|
21831
|
+
return {
|
|
21832
|
+
name,
|
|
21833
|
+
description: name === listName ? "\u5217\u51FA\u672C\u673A\u5DF2\u767B\u8BB0\u8D26\u53F7\u7684\u5B89\u5168\u6458\u8981\u548C\u7F3A\u5C11\u7684\u6388\u6743\u7C7B\u578B\uFF0C\u4E0D\u8FD4\u56DE\u51ED\u636E\u6216\u672C\u673A\u8DEF\u5F84\u3002" : "\u53EA\u4E3A\u5F53\u524D\u5BBF\u4E3B\u4F1A\u8BDD\u9009\u62E9\u672C\u673A\u5DF2\u6388\u6743\u8D26\u53F7\uFF1B\u4E0D\u5207\u6362\u5176\u5B83Agent\uFF0C\u4E0D\u7533\u8BF7\u7F16\u8F91\u6743\u6216\u91CD\u653E\u4E1A\u52A1\u3002",
|
|
21834
|
+
inputSchema: { type: "object", properties, additionalProperties: false, ...name === selectName ? { required: ["identityKey"] } : {} },
|
|
21835
|
+
annotations: { readOnlyHint: name === listName, destructiveHint: false, openWorldHint: false }
|
|
21836
|
+
};
|
|
21837
|
+
}
|
|
21838
|
+
function createAccountAwareBridge(defaultClient, {
|
|
21839
|
+
credentials,
|
|
21840
|
+
configFile: configFile2,
|
|
21841
|
+
host,
|
|
21842
|
+
hostSession,
|
|
21843
|
+
root = localAccountsRoot(),
|
|
21844
|
+
connect = connectPlatform,
|
|
21845
|
+
connectionOptions = {},
|
|
21846
|
+
localUploads,
|
|
21847
|
+
createLocalUploads,
|
|
21848
|
+
onCatalogChange = () => {
|
|
21849
|
+
},
|
|
21850
|
+
onKnowledgeChange = () => {
|
|
21851
|
+
}
|
|
21852
|
+
} = {}) {
|
|
21853
|
+
const primaryIdentity = connectionAccountIdentity(defaultClient), contexts = /* @__PURE__ */ new Map(), preferences = /* @__PURE__ */ new Map();
|
|
21854
|
+
let switched = false;
|
|
21855
|
+
const makeBridge = (client, creds, uploads) => createHostCallBridge(client, {
|
|
21856
|
+
credentials: creds,
|
|
21857
|
+
host,
|
|
21858
|
+
localUploads: uploads,
|
|
21859
|
+
onCatalogChange,
|
|
21860
|
+
onKnowledgeChange
|
|
21861
|
+
});
|
|
21862
|
+
const primary = { client: defaultClient, bridge: makeBridge(defaultClient, credentials, localUploads), identity: primaryIdentity, owned: false };
|
|
21863
|
+
function caller(raw, binding, required2 = false) {
|
|
21864
|
+
const params = { ...raw, arguments: binding.arguments };
|
|
21865
|
+
hostParameters(params, binding.host, required2 ? "authority" : "independent-read");
|
|
21866
|
+
const sessionId = binding.host.kind === "claude-code" ? binding.host.threadId : params._meta?.threadId;
|
|
21867
|
+
return sessionId ? { kind: binding.host.kind, sessionId } : void 0;
|
|
21868
|
+
}
|
|
21869
|
+
async function context(identity, agent, referenceId) {
|
|
21870
|
+
if (sameIdentity(identity, primaryIdentity) && (!referenceId || referenceId === localReferenceId("creation", path10.resolve(configFile2)))) return primary;
|
|
21871
|
+
const refs = await readLocalAuthorizations({ root, identity, client: "creation" });
|
|
21872
|
+
if (!refs.length) throw error3("creation_authorization_missing");
|
|
21873
|
+
let ref = referenceId ? refs.find((value2) => value2.referenceId === referenceId) : refs.length === 1 ? refs[0] : void 0;
|
|
21874
|
+
if (!ref) throw error3(referenceId ? "reference_unavailable" : "authorization_ambiguous");
|
|
21875
|
+
if (ref.expiresAt && Date.parse(ref.expiresAt) <= Date.now()) throw error3("authorization_expired");
|
|
21876
|
+
const key = [localAccountKey(identity), ref.referenceId, localAgentDigest(agent)].join("|");
|
|
21877
|
+
if (!contexts.has(key)) {
|
|
21878
|
+
const pending = (async () => {
|
|
21879
|
+
const saved = await readCredentials(ref.configFile);
|
|
21880
|
+
if (!saved || localCredentialDigest(saved.token) !== ref.credentialDigest || normalizeEndpoint(saved.endpoint) !== normalizeEndpoint(ref.endpoint)) throw error3("reference_changed");
|
|
21881
|
+
const client = await connect(saved, { ...connectionOptions, host, expectedIdentity: identity, clientConfigFile: ref.configFile });
|
|
21882
|
+
try {
|
|
21883
|
+
connectionAccountIdentity(client, identity);
|
|
21884
|
+
return { client, bridge: makeBridge(client, saved, createLocalUploads?.({ identity, agent, configFile: ref.configFile })), identity, owned: true };
|
|
21885
|
+
} catch (cause) {
|
|
21886
|
+
await client.close().catch(() => {
|
|
21887
|
+
});
|
|
21888
|
+
throw cause;
|
|
21889
|
+
}
|
|
21890
|
+
})();
|
|
21891
|
+
contexts.set(key, pending);
|
|
21892
|
+
pending.catch(() => {
|
|
21893
|
+
if (contexts.get(key) === pending) contexts.delete(key);
|
|
21894
|
+
});
|
|
21895
|
+
}
|
|
21896
|
+
return contexts.get(key);
|
|
21897
|
+
}
|
|
21898
|
+
async function selected(raw, binding) {
|
|
21899
|
+
const agent = caller(raw, binding);
|
|
21900
|
+
if (!agent) {
|
|
21901
|
+
if (switched) throw new CreationClientError("creation.host_identity_required");
|
|
21902
|
+
return { entry: primary };
|
|
21903
|
+
}
|
|
21904
|
+
const choice = await readSelectedLocalAccount({ root, agent });
|
|
21905
|
+
if (!choice) return { entry: primary, agent };
|
|
21906
|
+
const preference = preferences.get(localAgentDigest(agent));
|
|
21907
|
+
const referenceId = preference?.generation === choice.generation ? preference.referenceId : void 0;
|
|
21908
|
+
return { entry: await context(choice.identity, agent, referenceId), agent, choice };
|
|
21909
|
+
}
|
|
21910
|
+
async function knowledge(method, raw = {}) {
|
|
21911
|
+
const binding = await resolveHostCallBinding(raw, { host, hostSession });
|
|
21912
|
+
await binding.assertCurrent();
|
|
21913
|
+
const { entry } = await selected(raw, binding);
|
|
21914
|
+
return entry.bridge[method]({ ...raw, arguments: binding.arguments });
|
|
21915
|
+
}
|
|
21916
|
+
return {
|
|
21917
|
+
knowledgeCapabilities: primary.bridge.knowledgeCapabilities,
|
|
21918
|
+
async listTools(raw = {}) {
|
|
21919
|
+
let entry = primary;
|
|
21920
|
+
if (host.kind === "codex" && raw._meta?.threadId) {
|
|
21921
|
+
const binding = await resolveHostCallBinding(raw, { host, hostSession });
|
|
21922
|
+
entry = (await selected(raw, binding)).entry;
|
|
21923
|
+
}
|
|
21924
|
+
const directory3 = await entry.bridge.listTools();
|
|
21925
|
+
if (directory3.tools.some((tool) => [listName, selectName].includes(tool.name))) throw error3("tool_name_conflict");
|
|
21926
|
+
return { ...directory3, tools: [...directory3.tools, localTool(listName, host), localTool(selectName, host)] };
|
|
21927
|
+
},
|
|
21928
|
+
listResources: (raw) => knowledge("listResources", raw),
|
|
21929
|
+
listResourceTemplates: (raw) => knowledge("listResourceTemplates", raw),
|
|
21930
|
+
readResource: (raw) => knowledge("readResource", raw),
|
|
21931
|
+
listPrompts: (raw) => knowledge("listPrompts", raw),
|
|
21932
|
+
getPrompt: (raw) => knowledge("getPrompt", raw),
|
|
21933
|
+
async call(raw, options = {}) {
|
|
21934
|
+
const binding = await resolveHostCallBinding(raw, { host, hostSession });
|
|
21935
|
+
await binding.assertCurrent();
|
|
21936
|
+
if (raw.name === listName || raw.name === selectName) {
|
|
21937
|
+
const input = binding.arguments ?? {}, allowed = raw.name === selectName ? ["identityKey", "referenceId"] : [];
|
|
21938
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some((key) => !allowed.includes(key))) throw error3("request_invalid");
|
|
21939
|
+
let value2;
|
|
21940
|
+
if (raw.name === listName) value2 = await listLocalAccounts({ root });
|
|
21941
|
+
else {
|
|
21942
|
+
const agent = caller(raw, binding, true), identity = identityFromKey(input.identityKey);
|
|
21943
|
+
if (!agent) throw error3("agent_required");
|
|
21944
|
+
if (input.referenceId !== void 0 && (typeof input.referenceId !== "string" || !/^sha256:[a-f0-9]{64}$/.test(input.referenceId))) throw error3("reference_invalid");
|
|
21945
|
+
await context(identity, agent, input.referenceId);
|
|
21946
|
+
await binding.assertCurrent();
|
|
21947
|
+
const choice = await selectLocalAccount({ root, agent, identity });
|
|
21948
|
+
await binding.assertCurrent();
|
|
21949
|
+
preferences.set(localAgentDigest(agent), { generation: choice.generation, referenceId: input.referenceId });
|
|
21950
|
+
switched = true;
|
|
21951
|
+
Promise.resolve().then(onCatalogChange).catch(() => {
|
|
21952
|
+
});
|
|
21953
|
+
value2 = { selected: true, identityKey: localAccountKey(identity), identity, generation: choice.generation, otherAgentsChanged: 0 };
|
|
21954
|
+
}
|
|
21955
|
+
return { content: [{ type: "text", text: JSON.stringify(value2) }] };
|
|
21956
|
+
}
|
|
21957
|
+
const { entry } = await selected(raw, binding);
|
|
21958
|
+
await binding.assertCurrent();
|
|
21959
|
+
return entry.bridge.call({ ...raw, arguments: binding.arguments }, { ...options, resolvedBinding: binding });
|
|
21960
|
+
},
|
|
21961
|
+
async close() {
|
|
21962
|
+
await primary.bridge.close();
|
|
21963
|
+
for (const result of await Promise.allSettled(contexts.values())) if (result.status === "fulfilled") {
|
|
21964
|
+
await result.value.bridge.close();
|
|
21965
|
+
await result.value.client.close().catch(() => {
|
|
21966
|
+
});
|
|
21967
|
+
}
|
|
21968
|
+
}
|
|
21969
|
+
};
|
|
21970
|
+
}
|
|
21971
|
+
|
|
21431
21972
|
// lib/runtime-bootstrap.mjs
|
|
21432
|
-
import { createHash as
|
|
21973
|
+
import { createHash as createHash8, randomBytes as randomBytes4 } from "node:crypto";
|
|
21433
21974
|
import { gunzipSync } from "node:zlib";
|
|
21434
21975
|
|
|
21435
21976
|
// node_modules/tar/dist/esm/index.min.js
|
|
@@ -24402,28 +24943,28 @@ var To = (s3) => {
|
|
|
24402
24943
|
};
|
|
24403
24944
|
|
|
24404
24945
|
// lib/runtime-bootstrap.mjs
|
|
24405
|
-
import { lstat as
|
|
24946
|
+
import { lstat as lstat7, mkdir as mkdir5, open as open7, readFile as readFile5, readdir as readdir3, rename as rename5, rm, statfs } from "node:fs/promises";
|
|
24406
24947
|
import { execFile } from "node:child_process";
|
|
24407
24948
|
import { promisify } from "node:util";
|
|
24408
|
-
import
|
|
24949
|
+
import path12 from "node:path";
|
|
24409
24950
|
|
|
24410
24951
|
// lib/runtime-package.mjs
|
|
24411
|
-
import { lstat as
|
|
24412
|
-
import { createHash as
|
|
24413
|
-
import
|
|
24952
|
+
import { lstat as lstat6, readdir as readdir2, readFile as readFile4 } from "node:fs/promises";
|
|
24953
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
24954
|
+
import path11 from "node:path";
|
|
24414
24955
|
var RUNTIME_PACKAGE_ENTRIES = Object.freeze(["package.json", "README.md", "LICENSE", "bin", "dist", "lib", "skills", "docs", ".codex-plugin", ".mcp.json"]);
|
|
24415
24956
|
var OPTIONAL_HOST_ENTRIES = Object.freeze([".claude-plugin", ".claude-mcp.json"]);
|
|
24416
|
-
var
|
|
24957
|
+
var hash3 = (b2) => createHash7("sha256").update(b2).digest("hex");
|
|
24417
24958
|
var invalid = (code) => {
|
|
24418
24959
|
throw new CreationClientError("installation." + code);
|
|
24419
24960
|
};
|
|
24420
|
-
async function inspectRuntimePackage(root, { entries } = {}) {
|
|
24421
|
-
if (!
|
|
24422
|
-
|
|
24961
|
+
async function inspectRuntimePackage(root, { entries: entries2 } = {}) {
|
|
24962
|
+
if (!entries2) {
|
|
24963
|
+
entries2 = [...RUNTIME_PACKAGE_ENTRIES];
|
|
24423
24964
|
for (const name of OPTIONAL_HOST_ENTRIES) {
|
|
24424
24965
|
try {
|
|
24425
|
-
await
|
|
24426
|
-
|
|
24966
|
+
await lstat6(path11.join(root, name));
|
|
24967
|
+
entries2.push(name);
|
|
24427
24968
|
} catch (e) {
|
|
24428
24969
|
if (e.code !== "ENOENT") throw e;
|
|
24429
24970
|
}
|
|
@@ -24434,25 +24975,25 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
24434
24975
|
async function walk(relative) {
|
|
24435
24976
|
let s3;
|
|
24436
24977
|
try {
|
|
24437
|
-
s3 = await
|
|
24438
|
-
} catch (
|
|
24439
|
-
if (
|
|
24978
|
+
s3 = await lstat6(path11.join(root, relative));
|
|
24979
|
+
} catch (error5) {
|
|
24980
|
+
if (error5.code !== "ENOENT") throw error5;
|
|
24440
24981
|
}
|
|
24441
24982
|
if (!s3 || s3.isSymbolicLink()) invalid("package_file_invalid");
|
|
24442
24983
|
if (s3.isDirectory()) {
|
|
24443
|
-
for (const name of (await readdir2(
|
|
24984
|
+
for (const name of (await readdir2(path11.join(root, relative))).sort()) {
|
|
24444
24985
|
if (name === "node_modules" || name === "credentials.json" || name.startsWith(".env")) invalid("package_file_invalid");
|
|
24445
|
-
await walk(
|
|
24986
|
+
await walk(path11.join(relative, name));
|
|
24446
24987
|
}
|
|
24447
24988
|
} else if (s3.isFile()) {
|
|
24448
24989
|
if (s3.size > 32 * 1024 * 1024) invalid("package_too_large");
|
|
24449
|
-
const body = await readFile4(
|
|
24990
|
+
const body = await readFile4(path11.join(root, relative));
|
|
24450
24991
|
bytes2 += body.length;
|
|
24451
24992
|
if (files.length >= 1024 || bytes2 > 32 * 1024 * 1024) invalid("package_too_large");
|
|
24452
|
-
files.push({ path: relative, bytes: body.length, sha256:
|
|
24993
|
+
files.push({ path: relative, bytes: body.length, sha256: hash3(body), body });
|
|
24453
24994
|
} else invalid("package_file_invalid");
|
|
24454
24995
|
}
|
|
24455
|
-
for (const name of
|
|
24996
|
+
for (const name of entries2) await walk(name);
|
|
24456
24997
|
for (const name of ["dist/cli.mjs", "dist/THIRD_PARTY_NOTICES.txt", "skills/creation-setup/SKILL.md", "skills/video-creation/SKILL.md"])
|
|
24457
24998
|
if (!files.some((f2) => f2.path === name)) invalid("package_incomplete");
|
|
24458
24999
|
const pkg = JSON.parse(files.find((f2) => f2.path === "package.json").body), plugin = JSON.parse(files.find((f2) => f2.path === ".codex-plugin/plugin.json").body);
|
|
@@ -24463,7 +25004,7 @@ async function inspectRuntimePackage(root, { entries } = {}) {
|
|
|
24463
25004
|
files,
|
|
24464
25005
|
version: pkg.version,
|
|
24465
25006
|
hosts: claude ? ["codex", "claude-code"] : ["codex"],
|
|
24466
|
-
payloadDigest:
|
|
25007
|
+
payloadDigest: hash3(JSON.stringify(files.map(({ path: path21, bytes: bytes3, sha256 }) => ({ path: path21, bytes: bytes3, sha256 }))))
|
|
24467
25008
|
};
|
|
24468
25009
|
}
|
|
24469
25010
|
|
|
@@ -24473,9 +25014,9 @@ var REGISTRY = "https://registry.npmjs.org";
|
|
|
24473
25014
|
var MAX_ARCHIVE = 8 * 1024 * 1024;
|
|
24474
25015
|
var MAX_PAYLOAD = 32 * 1024 * 1024;
|
|
24475
25016
|
var MAX_TAR = 36 * 1024 * 1024;
|
|
24476
|
-
var
|
|
25017
|
+
var hash4 = (b2) => createHash8("sha256").update(b2).digest("hex");
|
|
24477
25018
|
var execute = promisify(execFile);
|
|
24478
|
-
var
|
|
25019
|
+
var error4 = (code) => new CreationClientError("creation." + code);
|
|
24479
25020
|
var version2 = (v2) => {
|
|
24480
25021
|
compareBridgeVersions(v2, v2);
|
|
24481
25022
|
return v2;
|
|
@@ -24493,34 +25034,34 @@ var RuntimeSelectionError = class extends CreationClientError {
|
|
|
24493
25034
|
});
|
|
24494
25035
|
}
|
|
24495
25036
|
};
|
|
24496
|
-
var runtimeErrorDetails = (
|
|
25037
|
+
var runtimeErrorDetails = (error5) => error5 instanceof RuntimeSelectionError ? error5.runtimeFacts : void 0;
|
|
24497
25038
|
var snapshot = (payload) => ({
|
|
24498
25039
|
version: payload.version,
|
|
24499
25040
|
hosts: payload.hosts,
|
|
24500
25041
|
payloadDigest: payload.payloadDigest,
|
|
24501
|
-
files: payload.files.map(({ path:
|
|
25042
|
+
files: payload.files.map(({ path: path21, bytes: bytes2, sha256 }) => ({ path: path21, bytes: bytes2, sha256 }))
|
|
24502
25043
|
});
|
|
24503
25044
|
async function info(file) {
|
|
24504
25045
|
try {
|
|
24505
|
-
return await
|
|
25046
|
+
return await lstat7(file);
|
|
24506
25047
|
} catch (e) {
|
|
24507
25048
|
if (e.code === "ENOENT") return null;
|
|
24508
25049
|
throw e;
|
|
24509
25050
|
}
|
|
24510
25051
|
}
|
|
24511
25052
|
async function privateDirectory2(dir) {
|
|
24512
|
-
await
|
|
24513
|
-
const s3 = await
|
|
24514
|
-
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw
|
|
25053
|
+
await mkdir5(dir, { recursive: true, mode: 448 });
|
|
25054
|
+
const s3 = await lstat7(dir);
|
|
25055
|
+
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) throw error4("runtime_cache_owner_invalid");
|
|
24515
25056
|
}
|
|
24516
25057
|
async function privateJSON(file) {
|
|
24517
25058
|
const s3 = await info(file);
|
|
24518
25059
|
if (!s3) return null;
|
|
24519
|
-
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) throw
|
|
25060
|
+
if (!s3.isFile() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63 || s3.size > 512 * 1024) throw error4("runtime_cache_invalid");
|
|
24520
25061
|
return JSON.parse(await readFile5(file, "utf8"));
|
|
24521
25062
|
}
|
|
24522
25063
|
async function syncDirectory2(dir) {
|
|
24523
|
-
const fd = await
|
|
25064
|
+
const fd = await open7(dir, "r");
|
|
24524
25065
|
try {
|
|
24525
25066
|
await fd.sync();
|
|
24526
25067
|
} finally {
|
|
@@ -24528,7 +25069,7 @@ async function syncDirectory2(dir) {
|
|
|
24528
25069
|
}
|
|
24529
25070
|
}
|
|
24530
25071
|
async function exclusiveJSON(file, value2) {
|
|
24531
|
-
const fd = await
|
|
25072
|
+
const fd = await open7(file, "wx", 384);
|
|
24532
25073
|
try {
|
|
24533
25074
|
await fd.writeFile(JSON.stringify(value2) + "\n");
|
|
24534
25075
|
await fd.sync();
|
|
@@ -24540,9 +25081,9 @@ function checkedRuntimeMetadata(value2, expectedVersion) {
|
|
|
24540
25081
|
version2(expectedVersion);
|
|
24541
25082
|
const tarball = REGISTRY + "/@promptframe/creation/-/creation-" + expectedVersion + ".tgz";
|
|
24542
25083
|
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))
|
|
24543
|
-
throw
|
|
25084
|
+
throw error4("runtime_registry_identity_invalid");
|
|
24544
25085
|
const encoded = value2.dist.integrity.slice(7);
|
|
24545
|
-
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw
|
|
25086
|
+
if (Buffer.from(encoded, "base64").toString("base64") !== encoded) throw error4("runtime_registry_identity_invalid");
|
|
24546
25087
|
return { version: expectedVersion, integrity: value2.dist.integrity, tarball };
|
|
24547
25088
|
}
|
|
24548
25089
|
async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes: maxBytes2, timeoutMs }) {
|
|
@@ -24552,12 +25093,12 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes: maxBytes2
|
|
|
24552
25093
|
let response;
|
|
24553
25094
|
try {
|
|
24554
25095
|
response = await fetchImpl(url2, { signal: controller.signal, redirect: "error" });
|
|
24555
|
-
if (response.status !== 200 || Number(response.headers.get("content-length") ?? 0) > maxBytes2 || !response.body) throw
|
|
25096
|
+
if (response.status !== 200 || Number(response.headers.get("content-length") ?? 0) > maxBytes2 || !response.body) throw error4("runtime_fetch_unavailable");
|
|
24556
25097
|
const chunks = [];
|
|
24557
25098
|
let count = 0;
|
|
24558
25099
|
for await (const chunk of response.body) {
|
|
24559
25100
|
count += chunk.length;
|
|
24560
|
-
if (count > maxBytes2) throw
|
|
25101
|
+
if (count > maxBytes2) throw error4("runtime_download_capacity");
|
|
24561
25102
|
chunks.push(Buffer.from(chunk));
|
|
24562
25103
|
}
|
|
24563
25104
|
return Buffer.concat(chunks, count);
|
|
@@ -24565,68 +25106,68 @@ async function boundedGet(url2, { fetchImpl = fetch, signal, maxBytes: maxBytes2
|
|
|
24565
25106
|
await response?.body?.cancel().catch(() => {
|
|
24566
25107
|
});
|
|
24567
25108
|
if (e instanceof CreationClientError) throw e;
|
|
24568
|
-
throw
|
|
25109
|
+
throw error4("runtime_fetch_unavailable");
|
|
24569
25110
|
} finally {
|
|
24570
25111
|
clearTimeout(timer);
|
|
24571
25112
|
signal?.removeEventListener("abort", abort);
|
|
24572
25113
|
}
|
|
24573
25114
|
}
|
|
24574
25115
|
async function readRuntimeArchive(archive, metadata) {
|
|
24575
|
-
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" +
|
|
25116
|
+
if (!Buffer.isBuffer(archive) || archive.length > MAX_ARCHIVE || "sha512-" + createHash8("sha512").update(archive).digest("base64") !== metadata.integrity) throw error4("runtime_integrity_invalid");
|
|
24576
25117
|
let raw;
|
|
24577
25118
|
try {
|
|
24578
25119
|
raw = gunzipSync(archive, { maxOutputLength: MAX_TAR });
|
|
24579
25120
|
} catch {
|
|
24580
|
-
throw
|
|
25121
|
+
throw error4("runtime_archive_invalid");
|
|
24581
25122
|
}
|
|
24582
25123
|
const files = [], names = /* @__PURE__ */ new Set();
|
|
24583
|
-
let total = 0,
|
|
25124
|
+
let total = 0, entries2 = 0, failure4;
|
|
24584
25125
|
const parser = Ct({ strict: true, onReadEntry: (entry) => {
|
|
24585
25126
|
const name = entry.path;
|
|
24586
|
-
if (++
|
|
25127
|
+
if (++entries2 > 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)) failure4 = error4("runtime_archive_invalid");
|
|
24587
25128
|
const relative = name.slice(8).replace(/\/$/, "");
|
|
24588
25129
|
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])))
|
|
24589
|
-
|
|
25130
|
+
failure4 = error4("runtime_archive_invalid");
|
|
24590
25131
|
const portableName = relative.toLowerCase();
|
|
24591
|
-
if (names.has(portableName))
|
|
25132
|
+
if (names.has(portableName)) failure4 = error4("runtime_archive_invalid");
|
|
24592
25133
|
names.add(portableName);
|
|
24593
25134
|
if (entry.type === "Directory") {
|
|
24594
|
-
if (entry.size !== 0)
|
|
25135
|
+
if (entry.size !== 0) failure4 = error4("runtime_archive_invalid");
|
|
24595
25136
|
return;
|
|
24596
25137
|
}
|
|
24597
25138
|
total += entry.size;
|
|
24598
|
-
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative)
|
|
25139
|
+
if (total > MAX_PAYLOAD || files.length >= 1024 || !relative) failure4 = error4("runtime_archive_capacity");
|
|
24599
25140
|
const chunks = [];
|
|
24600
25141
|
let bytes2 = 0;
|
|
24601
25142
|
entry.on("data", (chunk) => {
|
|
24602
25143
|
bytes2 += chunk.length;
|
|
24603
|
-
if (bytes2 > entry.size)
|
|
24604
|
-
if (!
|
|
25144
|
+
if (bytes2 > entry.size) failure4 = error4("runtime_archive_invalid");
|
|
25145
|
+
if (!failure4) chunks.push(Buffer.from(chunk));
|
|
24605
25146
|
});
|
|
24606
25147
|
entry.on("end", () => {
|
|
24607
|
-
if (bytes2 !== entry.size)
|
|
24608
|
-
if (!
|
|
25148
|
+
if (bytes2 !== entry.size) failure4 = error4("runtime_archive_invalid");
|
|
25149
|
+
if (!failure4) files.push({ path: relative, body: Buffer.concat(chunks, bytes2) });
|
|
24609
25150
|
});
|
|
24610
25151
|
} });
|
|
24611
25152
|
await new Promise((resolve, reject) => {
|
|
24612
|
-
parser.once("error", () => reject(
|
|
25153
|
+
parser.once("error", () => reject(error4("runtime_archive_invalid")));
|
|
24613
25154
|
parser.once("end", resolve);
|
|
24614
25155
|
parser.end(raw);
|
|
24615
25156
|
});
|
|
24616
|
-
if (
|
|
24617
|
-
if (!files.length || files.length > 1024) throw
|
|
25157
|
+
if (failure4) throw failure4;
|
|
25158
|
+
if (!files.length || files.length > 1024) throw error4("runtime_archive_invalid");
|
|
24618
25159
|
return files;
|
|
24619
25160
|
}
|
|
24620
25161
|
async function cacheLock(root, signal) {
|
|
24621
|
-
const name =
|
|
25162
|
+
const name = path12.join(root, "prepare.lock"), end = Date.now() + 5e3;
|
|
24622
25163
|
let fd;
|
|
24623
25164
|
while (!fd) {
|
|
24624
25165
|
signal?.throwIfAborted();
|
|
24625
25166
|
try {
|
|
24626
|
-
fd = await
|
|
25167
|
+
fd = await open7(name, "wx", 384);
|
|
24627
25168
|
} catch (e) {
|
|
24628
25169
|
if (e.code !== "EEXIST") throw e;
|
|
24629
|
-
if (Date.now() >= end) throw
|
|
25170
|
+
if (Date.now() >= end) throw error4("runtime_cache_busy");
|
|
24630
25171
|
await pause(50);
|
|
24631
25172
|
}
|
|
24632
25173
|
}
|
|
@@ -24644,51 +25185,51 @@ async function cacheLock(root, signal) {
|
|
|
24644
25185
|
return async () => {
|
|
24645
25186
|
const now = await info(name);
|
|
24646
25187
|
await fd.close();
|
|
24647
|
-
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw
|
|
25188
|
+
if (!now || now.dev !== owned.dev || now.ino !== owned.ino) throw error4("runtime_lock_changed");
|
|
24648
25189
|
await rm(name);
|
|
24649
25190
|
};
|
|
24650
25191
|
}
|
|
24651
25192
|
async function verifyCached(target, metadata, hostKind) {
|
|
24652
25193
|
if (!await info(target)) return null;
|
|
24653
25194
|
await privateDirectory2(target);
|
|
24654
|
-
const manifest = await privateJSON(
|
|
25195
|
+
const manifest = await privateJSON(path12.join(target, "runtime.json"));
|
|
24655
25196
|
if (!manifest || manifest.contractVersion !== "creation-verified-runtime/v1" || manifest.version !== metadata.version || manifest.integrity !== metadata.integrity)
|
|
24656
|
-
throw
|
|
25197
|
+
throw error4("runtime_cache_invalid");
|
|
24657
25198
|
const names = (await readdir3(target)).filter((name) => name !== "runtime.json").sort();
|
|
24658
|
-
if (names.some((name) => !roots.has(name)) || RUNTIME_PACKAGE_ENTRIES.some((name) => !names.includes(name))) throw
|
|
25199
|
+
if (names.some((name) => !roots.has(name)) || RUNTIME_PACKAGE_ENTRIES.some((name) => !names.includes(name))) throw error4("runtime_cache_invalid");
|
|
24659
25200
|
const payload = await inspectRuntimePackage(target, { entries: names });
|
|
24660
|
-
if (!payload.hosts.includes(hostKind)) throw
|
|
24661
|
-
if (JSON.stringify(snapshot(payload)) !== JSON.stringify(manifest.payload)) throw
|
|
25201
|
+
if (!payload.hosts.includes(hostKind)) throw error4("runtime_host_unsupported");
|
|
25202
|
+
if (JSON.stringify(snapshot(payload)) !== JSON.stringify(manifest.payload)) throw error4("runtime_cache_invalid");
|
|
24662
25203
|
return { version: payload.version, root: target, integrity: metadata.integrity, reused: true };
|
|
24663
25204
|
}
|
|
24664
25205
|
async function checkedVersionIndex(cacheRoot, metadata) {
|
|
24665
|
-
const old = await privateJSON(
|
|
24666
|
-
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw
|
|
25206
|
+
const old = await privateJSON(path12.join(cacheRoot, "version-" + metadata.version + ".json"));
|
|
25207
|
+
if (old && JSON.stringify(old) !== JSON.stringify(metadata)) throw error4("runtime_registry_identity_conflict");
|
|
24667
25208
|
return old;
|
|
24668
25209
|
}
|
|
24669
25210
|
async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
24670
|
-
if (!["codex", "claude-code"].includes(hostKind)) throw
|
|
24671
|
-
if (!
|
|
25211
|
+
if (!["codex", "claude-code"].includes(hostKind)) throw error4("runtime_host_unsupported");
|
|
25212
|
+
if (!path12.isAbsolute(cacheRoot ?? "")) throw error4("runtime_cache_owner_invalid");
|
|
24672
25213
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: metadata.version, dist: metadata }, metadata.version);
|
|
24673
25214
|
await privateDirectory2(cacheRoot);
|
|
24674
25215
|
await checkedVersionIndex(cacheRoot, metadata);
|
|
24675
|
-
const target =
|
|
25216
|
+
const target = path12.join(cacheRoot, metadata.version + "-" + hash4(metadata.integrity)), existing = await verifyCached(target, metadata, hostKind);
|
|
24676
25217
|
if (existing) return existing;
|
|
24677
25218
|
const archive = await boundedGet(metadata.tarball, { fetchImpl, signal, maxBytes: MAX_ARCHIVE, timeoutMs: 15e3 });
|
|
24678
25219
|
const files = await readRuntimeArchive(archive, metadata), release = await cacheLock(cacheRoot, signal);
|
|
24679
|
-
const temporary =
|
|
25220
|
+
const temporary = path12.join(cacheRoot, ".partial-" + randomBytes4(12).toString("hex"));
|
|
24680
25221
|
try {
|
|
24681
25222
|
const index = await checkedVersionIndex(cacheRoot, metadata);
|
|
24682
25223
|
const found = await verifyCached(target, metadata, hostKind);
|
|
24683
25224
|
if (found) return found;
|
|
24684
25225
|
const space = await statfs(cacheRoot, { bigint: true }), needed = BigInt(files.reduce((n, f2) => n + f2.body.length, 0) + 4 * 1024 * 1024);
|
|
24685
|
-
if (space.bavail * space.bsize < needed) throw
|
|
24686
|
-
await
|
|
25226
|
+
if (space.bavail * space.bsize < needed) throw error4("runtime_cache_capacity");
|
|
25227
|
+
await mkdir5(temporary, { mode: 448 });
|
|
24687
25228
|
for (const file of files) {
|
|
24688
25229
|
signal?.throwIfAborted();
|
|
24689
|
-
const dest =
|
|
24690
|
-
await
|
|
24691
|
-
const fd = await
|
|
25230
|
+
const dest = path12.join(temporary, ...file.path.split("/"));
|
|
25231
|
+
await mkdir5(path12.dirname(dest), { recursive: true, mode: 448 });
|
|
25232
|
+
const fd = await open7(dest, "wx", 384);
|
|
24692
25233
|
try {
|
|
24693
25234
|
await fd.writeFile(file.body);
|
|
24694
25235
|
await fd.sync();
|
|
@@ -24696,27 +25237,27 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
24696
25237
|
await fd.close();
|
|
24697
25238
|
}
|
|
24698
25239
|
}
|
|
24699
|
-
const
|
|
24700
|
-
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !
|
|
24701
|
-
const payload = await inspectRuntimePackage(temporary, { entries });
|
|
24702
|
-
if (!payload.hosts.includes(hostKind)) throw
|
|
24703
|
-
if (payload.version !== metadata.version) throw
|
|
25240
|
+
const entries2 = [...new Set(files.map((file) => file.path.split("/")[0]))].sort();
|
|
25241
|
+
if (RUNTIME_PACKAGE_ENTRIES.some((name) => !entries2.includes(name))) throw error4("runtime_package_incomplete");
|
|
25242
|
+
const payload = await inspectRuntimePackage(temporary, { entries: entries2 });
|
|
25243
|
+
if (!payload.hosts.includes(hostKind)) throw error4("runtime_host_unsupported");
|
|
25244
|
+
if (payload.version !== metadata.version) throw error4("runtime_package_version_invalid");
|
|
24704
25245
|
const pkg = JSON.parse(payload.files.find((f2) => f2.path === "package.json").body);
|
|
24705
|
-
if (pkg.repository?.url !== "git+https://github.com/ty-teams/promptframe-creation.git" || pkg.private === true) throw
|
|
25246
|
+
if (pkg.repository?.url !== "git+https://github.com/ty-teams/promptframe-creation.git" || pkg.private === true) throw error4("runtime_package_identity_invalid");
|
|
24706
25247
|
if (checkRuntime) await checkRuntime(temporary, metadata.version);
|
|
24707
25248
|
else {
|
|
24708
25249
|
const result = await execute(
|
|
24709
25250
|
process.execPath,
|
|
24710
|
-
[
|
|
25251
|
+
[path12.join(temporary, "bin/promptframe-creation.mjs"), "--version"],
|
|
24711
25252
|
{ timeout: 5e3, maxBuffer: 65536, windowsHide: true, signal, env: {
|
|
24712
25253
|
...process.env,
|
|
24713
|
-
PROMPTFRAME_CREATION_CONFIG:
|
|
25254
|
+
PROMPTFRAME_CREATION_CONFIG: path12.join(temporary, "no-credentials.json")
|
|
24714
25255
|
} }
|
|
24715
25256
|
);
|
|
24716
|
-
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw
|
|
25257
|
+
if (result.stdout.trim() !== metadata.version || result.stderr.trim()) throw error4("runtime_package_version_invalid");
|
|
24717
25258
|
}
|
|
24718
25259
|
signal?.throwIfAborted();
|
|
24719
|
-
await exclusiveJSON(
|
|
25260
|
+
await exclusiveJSON(path12.join(temporary, "runtime.json"), {
|
|
24720
25261
|
contractVersion: "creation-verified-runtime/v1",
|
|
24721
25262
|
version: metadata.version,
|
|
24722
25263
|
integrity: metadata.integrity,
|
|
@@ -24724,10 +25265,10 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
24724
25265
|
});
|
|
24725
25266
|
await syncDirectory2(temporary);
|
|
24726
25267
|
if (!index) {
|
|
24727
|
-
await exclusiveJSON(
|
|
25268
|
+
await exclusiveJSON(path12.join(cacheRoot, "version-" + metadata.version + ".json"), metadata);
|
|
24728
25269
|
await syncDirectory2(cacheRoot);
|
|
24729
25270
|
}
|
|
24730
|
-
await
|
|
25271
|
+
await rename5(temporary, target);
|
|
24731
25272
|
await syncDirectory2(cacheRoot);
|
|
24732
25273
|
return { version: metadata.version, root: target, integrity: metadata.integrity, reused: false };
|
|
24733
25274
|
} finally {
|
|
@@ -24741,7 +25282,7 @@ async function prepareVerifiedRuntime(metadata, { cacheRoot, fetchImpl = fetch,
|
|
|
24741
25282
|
async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, resolvedVersion, cacheRoot, fetchImpl = fetch, signal, checkRuntime, hostKind = "codex" } = {}) {
|
|
24742
25283
|
version2(currentVersion);
|
|
24743
25284
|
if (lockedVersion !== void 0) version2(lockedVersion);
|
|
24744
|
-
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw
|
|
25285
|
+
if (resolvedVersion !== void 0 && resolvedVersion !== currentVersion) throw error4("runtime_selection_identity_invalid");
|
|
24745
25286
|
if (!policy) throw new RuntimeSelectionError(
|
|
24746
25287
|
"platform_bridge_policy_unavailable",
|
|
24747
25288
|
currentVersion,
|
|
@@ -24766,7 +25307,7 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
24766
25307
|
const raw = await boundedGet(REGISTRY + "/@promptframe%2fcreation/" + target, { fetchImpl, signal, maxBytes: 256 * 1024, timeoutMs: 5e3 });
|
|
24767
25308
|
metadata = checkedRuntimeMetadata(JSON.parse(raw), target);
|
|
24768
25309
|
} catch (e) {
|
|
24769
|
-
const prior = await privateJSON(
|
|
25310
|
+
const prior = await privateJSON(path12.join(cacheRoot, "version-" + target + ".json"));
|
|
24770
25311
|
if (!prior) throw e;
|
|
24771
25312
|
metadata = checkedRuntimeMetadata({ name: PACKAGE, version: target, dist: prior }, target);
|
|
24772
25313
|
metadataSource = "previously-verified-cache";
|
|
@@ -24779,29 +25320,29 @@ async function selectBridgeRuntime({ policy, currentVersion, lockedVersion, reso
|
|
|
24779
25320
|
metadataSource
|
|
24780
25321
|
};
|
|
24781
25322
|
} catch (e) {
|
|
24782
|
-
if (signal?.aborted) throw
|
|
25323
|
+
if (signal?.aborted) throw error4("runtime_selection_interrupted");
|
|
24783
25324
|
if (lockedVersion !== void 0)
|
|
24784
25325
|
throw new RuntimeSelectionError("bridge_locked_version_unavailable", currentVersion, lockedVersion, policy, "retry_same_fixed_version_in_new_session");
|
|
24785
25326
|
if (policy && compareBridgeVersions(currentVersion, policy.minBridge) >= 0)
|
|
24786
25327
|
return { version: currentVersion, current: true, locked: false, status: "update_unavailable_current_compatible" };
|
|
24787
25328
|
if (policy) assertBridgeCompatible({ experimental: { "promptframe.creation": policy } }, currentVersion);
|
|
24788
25329
|
if (e instanceof CreationClientError) throw e;
|
|
24789
|
-
throw
|
|
25330
|
+
throw error4("runtime_selection_unavailable");
|
|
24790
25331
|
}
|
|
24791
25332
|
}
|
|
24792
25333
|
|
|
24793
25334
|
// lib/runtime-launch.mjs
|
|
24794
25335
|
import { spawn } from "node:child_process";
|
|
24795
|
-
import
|
|
25336
|
+
import path13 from "node:path";
|
|
24796
25337
|
async function launchSelectedBridge(selection, { host, configFile: configFile2, spawnImpl = spawn, env = process.env } = {}) {
|
|
24797
|
-
if (!
|
|
25338
|
+
if (!path13.isAbsolute(selection.root ?? "") || !path13.isAbsolute(configFile2 ?? "") || !["codex", "claude-code"].includes(host?.kind))
|
|
24798
25339
|
throw new CreationClientError("creation.runtime_launch_invalid");
|
|
24799
25340
|
let child;
|
|
24800
25341
|
try {
|
|
24801
25342
|
child = spawnImpl(
|
|
24802
25343
|
process.execPath,
|
|
24803
25344
|
[
|
|
24804
|
-
|
|
25345
|
+
path13.join(selection.root, "bin/promptframe-creation.mjs"),
|
|
24805
25346
|
"bridge",
|
|
24806
25347
|
"--config",
|
|
24807
25348
|
configFile2,
|
|
@@ -24843,10 +25384,10 @@ async function launchSelectedBridge(selection, { host, configFile: configFile2,
|
|
|
24843
25384
|
// lib/user-installation.mjs
|
|
24844
25385
|
import { execFile as execFile2 } from "node:child_process";
|
|
24845
25386
|
import { promisify as promisify2 } from "node:util";
|
|
24846
|
-
import { createHash as
|
|
24847
|
-
import { lstat as
|
|
24848
|
-
import { homedir as
|
|
24849
|
-
import
|
|
25387
|
+
import { createHash as createHash9, randomBytes as randomBytes5 } from "node:crypto";
|
|
25388
|
+
import { lstat as lstat8, mkdir as mkdir6, readdir as readdir4, readFile as readFile6, writeFile as writeFile2, rename as rename6, rm as rm2, open as open8 } from "node:fs/promises";
|
|
25389
|
+
import { homedir as homedir5 } from "node:os";
|
|
25390
|
+
import path14 from "node:path";
|
|
24850
25391
|
|
|
24851
25392
|
// node_modules/smol-toml/dist/error.js
|
|
24852
25393
|
function getLineColFromPtr(string4, ptr) {
|
|
@@ -24999,55 +25540,55 @@ var TomlDate = class _TomlDate extends Date {
|
|
|
24999
25540
|
#hasDate = false;
|
|
25000
25541
|
#hasTime = false;
|
|
25001
25542
|
#offset = null;
|
|
25002
|
-
constructor(
|
|
25543
|
+
constructor(date5, fasttype, unsafeDelim) {
|
|
25003
25544
|
let hasDate = true;
|
|
25004
25545
|
let hasTime = true;
|
|
25005
25546
|
let offset = "Z";
|
|
25006
25547
|
let c;
|
|
25007
|
-
if (typeof
|
|
25548
|
+
if (typeof date5 === "string") {
|
|
25008
25549
|
if (fasttype)
|
|
25009
25550
|
prep: {
|
|
25010
25551
|
if (fasttype < 3) {
|
|
25011
|
-
if (+
|
|
25012
|
-
|
|
25552
|
+
if (+date5.slice(11, 13) > 23) {
|
|
25553
|
+
date5 = "";
|
|
25013
25554
|
break prep;
|
|
25014
25555
|
}
|
|
25015
25556
|
if (fasttype === 2) {
|
|
25016
25557
|
offset = null;
|
|
25017
|
-
|
|
25018
|
-
} else if ((c =
|
|
25019
|
-
offset =
|
|
25558
|
+
date5 += "Z";
|
|
25559
|
+
} else if ((c = date5.charCodeAt(date5.length - 1)) !== 90 && c !== 122) {
|
|
25560
|
+
offset = date5.slice(date5.length - 6);
|
|
25020
25561
|
}
|
|
25021
25562
|
if (unsafeDelim)
|
|
25022
|
-
|
|
25563
|
+
date5 = date5.slice(0, 10) + "T" + date5.slice(11);
|
|
25023
25564
|
} else if (fasttype === 4) {
|
|
25024
|
-
|
|
25565
|
+
date5 = +date5.slice(0, 2) > 23 ? "" : `0000-01-01T${date5}Z`;
|
|
25025
25566
|
}
|
|
25026
25567
|
hasDate = fasttype !== 4;
|
|
25027
25568
|
hasTime = fasttype !== 3;
|
|
25028
25569
|
}
|
|
25029
25570
|
else {
|
|
25030
|
-
let match =
|
|
25571
|
+
let match = date5.match(DATE_TIME_RE);
|
|
25031
25572
|
if (match) {
|
|
25032
25573
|
if (!match[1]) {
|
|
25033
25574
|
hasDate = false;
|
|
25034
|
-
|
|
25575
|
+
date5 = `0000-01-01T${date5}`;
|
|
25035
25576
|
}
|
|
25036
25577
|
hasTime = !!match[2];
|
|
25037
|
-
hasTime &&
|
|
25578
|
+
hasTime && date5[10] === " " && (date5 = date5.replace(" ", "T"));
|
|
25038
25579
|
if (match[2] && +match[2] > 23) {
|
|
25039
|
-
|
|
25580
|
+
date5 = "";
|
|
25040
25581
|
} else {
|
|
25041
25582
|
offset = match[3] || null;
|
|
25042
25583
|
if (!offset && hasTime)
|
|
25043
|
-
|
|
25584
|
+
date5 += "Z";
|
|
25044
25585
|
}
|
|
25045
25586
|
} else {
|
|
25046
|
-
|
|
25587
|
+
date5 = "";
|
|
25047
25588
|
}
|
|
25048
25589
|
}
|
|
25049
25590
|
}
|
|
25050
|
-
super(
|
|
25591
|
+
super(date5);
|
|
25051
25592
|
if (!isNaN(this.getTime())) {
|
|
25052
25593
|
this.#hasDate = hasDate;
|
|
25053
25594
|
this.#hasTime = hasTime;
|
|
@@ -25085,26 +25626,26 @@ var TomlDate = class _TomlDate extends Date {
|
|
|
25085
25626
|
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
25086
25627
|
}
|
|
25087
25628
|
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
25088
|
-
let
|
|
25089
|
-
|
|
25090
|
-
return
|
|
25629
|
+
let date5 = new _TomlDate(jsDate);
|
|
25630
|
+
date5.#offset = offset;
|
|
25631
|
+
return date5;
|
|
25091
25632
|
}
|
|
25092
25633
|
static wrapAsLocalDateTime(jsDate) {
|
|
25093
|
-
let
|
|
25094
|
-
|
|
25095
|
-
return
|
|
25634
|
+
let date5 = new _TomlDate(jsDate);
|
|
25635
|
+
date5.#offset = null;
|
|
25636
|
+
return date5;
|
|
25096
25637
|
}
|
|
25097
25638
|
static wrapAsLocalDate(jsDate) {
|
|
25098
|
-
let
|
|
25099
|
-
|
|
25100
|
-
|
|
25101
|
-
return
|
|
25639
|
+
let date5 = new _TomlDate(jsDate);
|
|
25640
|
+
date5.#hasTime = false;
|
|
25641
|
+
date5.#offset = null;
|
|
25642
|
+
return date5;
|
|
25102
25643
|
}
|
|
25103
25644
|
static wrapAsLocalTime(jsDate) {
|
|
25104
|
-
let
|
|
25105
|
-
|
|
25106
|
-
|
|
25107
|
-
return
|
|
25645
|
+
let date5 = new _TomlDate(jsDate);
|
|
25646
|
+
date5.#hasDate = false;
|
|
25647
|
+
date5.#offset = null;
|
|
25648
|
+
return date5;
|
|
25108
25649
|
}
|
|
25109
25650
|
};
|
|
25110
25651
|
|
|
@@ -25294,10 +25835,10 @@ function parseTime(ctx, c, endChr) {
|
|
|
25294
25835
|
}
|
|
25295
25836
|
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
25296
25837
|
if (ctx.ld) {
|
|
25297
|
-
let
|
|
25298
|
-
if (!
|
|
25838
|
+
let date5 = new TomlDate(str, type, unsafeDelim);
|
|
25839
|
+
if (!date5.isValid())
|
|
25299
25840
|
TomlError.x("invalid date", ctx, errPtr);
|
|
25300
|
-
return
|
|
25841
|
+
return date5;
|
|
25301
25842
|
}
|
|
25302
25843
|
try {
|
|
25303
25844
|
if (temporalSuffix)
|
|
@@ -25608,7 +26149,7 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
25608
26149
|
|
|
25609
26150
|
// lib/user-installation.mjs
|
|
25610
26151
|
var execute2 = promisify2(execFile2);
|
|
25611
|
-
var
|
|
26152
|
+
var hash5 = (b2) => createHash9("sha256").update(b2).digest("hex");
|
|
25612
26153
|
var InstallationError = class extends CreationClientError {
|
|
25613
26154
|
constructor(code, details) {
|
|
25614
26155
|
super("installation." + code);
|
|
@@ -25618,7 +26159,7 @@ var InstallationError = class extends CreationClientError {
|
|
|
25618
26159
|
var fail4 = (code, details) => {
|
|
25619
26160
|
throw new InstallationError(code, details);
|
|
25620
26161
|
};
|
|
25621
|
-
var installationErrorDetails = (
|
|
26162
|
+
var installationErrorDetails = (error5) => error5 instanceof InstallationError ? error5.details : void 0;
|
|
25622
26163
|
function compareVersions(a, b2) {
|
|
25623
26164
|
const left = a.split(".").map(BigInt), right = b2.split(".").map(BigInt);
|
|
25624
26165
|
for (let i = 0; i < 3; i++) {
|
|
@@ -25647,8 +26188,8 @@ function validProfile(profile) {
|
|
|
25647
26188
|
}
|
|
25648
26189
|
function profileCredentialsPath(profile = "default", env = process.env) {
|
|
25649
26190
|
validProfile(profile);
|
|
25650
|
-
return profile === "default" ? credentialsPath(env) :
|
|
25651
|
-
env.XDG_CONFIG_HOME ??
|
|
26191
|
+
return profile === "default" ? credentialsPath(env) : path14.resolve(
|
|
26192
|
+
env.XDG_CONFIG_HOME ?? path14.join(homedir5(), ".config"),
|
|
25652
26193
|
"promptframe-creation",
|
|
25653
26194
|
"profiles",
|
|
25654
26195
|
profile,
|
|
@@ -25657,15 +26198,15 @@ function profileCredentialsPath(profile = "default", env = process.env) {
|
|
|
25657
26198
|
}
|
|
25658
26199
|
async function info2(file) {
|
|
25659
26200
|
try {
|
|
25660
|
-
return await
|
|
26201
|
+
return await lstat8(file);
|
|
25661
26202
|
} catch (e) {
|
|
25662
26203
|
if (e.code === "ENOENT") return null;
|
|
25663
26204
|
throw e;
|
|
25664
26205
|
}
|
|
25665
26206
|
}
|
|
25666
26207
|
async function privateDirectory3(dir) {
|
|
25667
|
-
await
|
|
25668
|
-
const s3 = await
|
|
26208
|
+
await mkdir6(dir, { recursive: true, mode: 448 });
|
|
26209
|
+
const s3 = await lstat8(dir);
|
|
25669
26210
|
if (!s3.isDirectory() || s3.isSymbolicLink() || s3.uid !== process.getuid?.() || s3.mode & 63) fail4("private_owner_required");
|
|
25670
26211
|
}
|
|
25671
26212
|
async function privateRead2(file) {
|
|
@@ -25680,20 +26221,20 @@ async function packageJSON(file) {
|
|
|
25680
26221
|
return json(file);
|
|
25681
26222
|
}
|
|
25682
26223
|
function sameTransport(actual, expected) {
|
|
25683
|
-
return actual?.type === "stdio" && actual.command === expected.command && typeof actual.cwd === "string" &&
|
|
26224
|
+
return actual?.type === "stdio" && actual.command === expected.command && typeof actual.cwd === "string" && path14.resolve(actual.cwd) === path14.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;
|
|
25684
26225
|
}
|
|
25685
26226
|
async function managedTransport(installed, versions, serverName, profile, configFile2) {
|
|
25686
26227
|
if (!installed) return null;
|
|
25687
26228
|
const root = installed.source?.path;
|
|
25688
|
-
if (installed.source?.source !== "local" || typeof root !== "string" || !/^\d+\.\d+\.\d+$/.test(installed.version ?? "") || root !==
|
|
25689
|
-
const
|
|
25690
|
-
if (!
|
|
25691
|
-
const ready = await privateRead2(
|
|
26229
|
+
if (installed.source?.source !== "local" || typeof root !== "string" || !/^\d+\.\d+\.\d+$/.test(installed.version ?? "") || root !== path14.join(versions, installed.version)) fail4("existing_registration_requires_review");
|
|
26230
|
+
const directory3 = await info2(root), definition = await info2(path14.join(root, ".mcp.json"));
|
|
26231
|
+
if (!directory3?.isDirectory() || directory3.isSymbolicLink() || !definition?.isFile() || definition.isSymbolicLink()) fail4("installed_files_invalid");
|
|
26232
|
+
const ready = await privateRead2(path14.join(root, "installation.json"));
|
|
25692
26233
|
if (!ready || ready.profile !== profile || ready.configFile !== configFile2 || ready.version !== installed.version) fail4("existing_registration_requires_review");
|
|
25693
|
-
const bytes2 = await readFile6(
|
|
25694
|
-
if (!entry || entry.bytes !== bytes2.length || entry.sha256 !==
|
|
26234
|
+
const bytes2 = await readFile6(path14.join(root, ".mcp.json")), entry = ready.files?.find((x) => x.path === ".mcp.json");
|
|
26235
|
+
if (!entry || entry.bytes !== bytes2.length || entry.sha256 !== hash5(bytes2)) fail4("installed_files_invalid");
|
|
25695
26236
|
const mcp = JSON.parse(bytes2).mcpServers?.[serverName];
|
|
25696
|
-
if (!mcp || typeof mcp.command !== "string" || !mcp.command || mcp.cwd !== root || JSON.stringify(mcp.args) !== JSON.stringify([
|
|
26237
|
+
if (!mcp || typeof mcp.command !== "string" || !mcp.command || mcp.cwd !== root || JSON.stringify(mcp.args) !== JSON.stringify([path14.join(root, "bin/promptframe-creation.mjs"), "bridge", "--config", configFile2])) fail4("existing_registration_requires_review");
|
|
25697
26238
|
return mcp;
|
|
25698
26239
|
}
|
|
25699
26240
|
async function officialNpmInstallation(installed, servers, env, profile, configFile2) {
|
|
@@ -25701,12 +26242,12 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
25701
26242
|
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));
|
|
25702
26243
|
if (candidates.length > 1) fail4("existing_registration_requires_review");
|
|
25703
26244
|
if (!candidates.length) return null;
|
|
25704
|
-
const p2 = candidates[0], root =
|
|
25705
|
-
const
|
|
25706
|
-
if (!
|
|
25707
|
-
const pkg = await packageJSON(
|
|
26245
|
+
const p2 = candidates[0], root = path14.join(path14.resolve(env.CODEX_HOME ?? path14.join(homedir5(), ".codex")), "plugins/cache", p2.marketplaceName, p2.name, p2.version);
|
|
26246
|
+
const directory3 = await info2(root);
|
|
26247
|
+
if (!directory3?.isDirectory() || directory3.isSymbolicLink()) fail4("installed_files_invalid");
|
|
26248
|
+
const pkg = await packageJSON(path14.join(root, "package.json")), manifest = await packageJSON(path14.join(root, ".codex-plugin/plugin.json"));
|
|
25708
26249
|
if (pkg.name !== "@promptframe/creation" || pkg.version !== p2.version || manifest.name !== p2.name || manifest.version !== p2.version) fail4("installed_files_invalid");
|
|
25709
|
-
const definition = (await packageJSON(
|
|
26250
|
+
const definition = (await packageJSON(path14.join(root, ".mcp.json"))).mcpServers?.promptframe;
|
|
25710
26251
|
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"])) fail4("legacy_mcp_entry_requires_review");
|
|
25711
26252
|
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)) fail4("legacy_mcp_entry_requires_review");
|
|
25712
26253
|
return {
|
|
@@ -25725,32 +26266,32 @@ async function officialNpmInstallation(installed, servers, env, profile, configF
|
|
|
25725
26266
|
async function atomicJSON(file, value2) {
|
|
25726
26267
|
const temp = file + "." + randomBytes5(12).toString("hex") + ".tmp";
|
|
25727
26268
|
try {
|
|
25728
|
-
const out = await
|
|
26269
|
+
const out = await open8(temp, "wx", 384);
|
|
25729
26270
|
try {
|
|
25730
26271
|
await out.writeFile(JSON.stringify(value2, null, 2) + "\n");
|
|
25731
26272
|
await out.sync();
|
|
25732
26273
|
} finally {
|
|
25733
26274
|
await out.close();
|
|
25734
26275
|
}
|
|
25735
|
-
await
|
|
25736
|
-
const
|
|
26276
|
+
await rename6(temp, file);
|
|
26277
|
+
const directory3 = await open8(path14.dirname(file), "r");
|
|
25737
26278
|
try {
|
|
25738
|
-
await
|
|
26279
|
+
await directory3.sync();
|
|
25739
26280
|
} finally {
|
|
25740
|
-
await
|
|
26281
|
+
await directory3.close();
|
|
25741
26282
|
}
|
|
25742
26283
|
} finally {
|
|
25743
26284
|
await rm2(temp, { force: true });
|
|
25744
26285
|
}
|
|
25745
26286
|
}
|
|
25746
26287
|
async function acquire(root, signal) {
|
|
25747
|
-
const lock =
|
|
26288
|
+
const lock = path14.join(root, "install.lock");
|
|
25748
26289
|
const end = Date.now() + 3e4;
|
|
25749
26290
|
let owned = false;
|
|
25750
26291
|
while (!owned) {
|
|
25751
26292
|
signal?.throwIfAborted();
|
|
25752
26293
|
try {
|
|
25753
|
-
await
|
|
26294
|
+
await mkdir6(lock, { mode: 448 });
|
|
25754
26295
|
owned = true;
|
|
25755
26296
|
} catch (e) {
|
|
25756
26297
|
if (e.code !== "EEXIST") throw e;
|
|
@@ -25759,7 +26300,7 @@ async function acquire(root, signal) {
|
|
|
25759
26300
|
}
|
|
25760
26301
|
}
|
|
25761
26302
|
try {
|
|
25762
|
-
await writeFile2(
|
|
26303
|
+
await writeFile2(path14.join(lock, "owner.json"), JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() }), { flag: "wx", mode: 384 });
|
|
25763
26304
|
} catch (e) {
|
|
25764
26305
|
await rm2(lock, { recursive: true, force: true });
|
|
25765
26306
|
throw e;
|
|
@@ -25800,7 +26341,7 @@ async function codexJSON(runCodex, args2) {
|
|
|
25800
26341
|
}
|
|
25801
26342
|
}
|
|
25802
26343
|
async function relatedPlugins(runCodex, pluginName, env) {
|
|
25803
|
-
const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), pinnedMarketplaces = /* @__PURE__ */ new Map(), config2 =
|
|
26344
|
+
const related = /* @__PURE__ */ new Set(), registered = /* @__PURE__ */ new Set(), pinnedMarketplaces = /* @__PURE__ */ new Map(), config2 = path14.join(path14.resolve(env.CODEX_HOME ?? path14.join(homedir5(), ".codex")), "config.toml");
|
|
25804
26345
|
try {
|
|
25805
26346
|
const s3 = await info2(config2);
|
|
25806
26347
|
if (s3) {
|
|
@@ -25820,10 +26361,10 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
25820
26361
|
const state = await codexJSON(runCodex, ["plugin", "marketplace", "list", "--json"]);
|
|
25821
26362
|
if (!Array.isArray(state?.marketplaces) || state.marketplaces.length > 128) fail4("local_catalog_unconfirmed");
|
|
25822
26363
|
for (const market of state.marketplaces) {
|
|
25823
|
-
if (typeof market.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name) || typeof market.root !== "string" || !
|
|
26364
|
+
if (typeof market.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name) || typeof market.root !== "string" || !path14.isAbsolute(market.root)) fail4("local_catalog_unconfirmed");
|
|
25824
26365
|
let catalog;
|
|
25825
26366
|
try {
|
|
25826
|
-
catalog = await packageJSON(
|
|
26367
|
+
catalog = await packageJSON(path14.join(market.root, ".agents/plugins/marketplace.json"));
|
|
25827
26368
|
} catch {
|
|
25828
26369
|
fail4("local_catalog_unconfirmed", { phase: "local_check", commandKind: "marketplace_read", localRegistrationState: "unknown", action: "restore_local_marketplace_catalog" });
|
|
25829
26370
|
}
|
|
@@ -25854,7 +26395,7 @@ async function relatedPlugins(runCodex, pluginName, env) {
|
|
|
25854
26395
|
}
|
|
25855
26396
|
async function runNode(root, version3) {
|
|
25856
26397
|
try {
|
|
25857
|
-
const result = await execute2(process.execPath, [
|
|
26398
|
+
const result = await execute2(process.execPath, [path14.join(root, "bin/promptframe-creation.mjs"), "--version"], { encoding: "utf8", timeout: 1e4, maxBuffer: 8192 });
|
|
25858
26399
|
if (result.stdout.trim() !== version3) fail4("runtime_version_mismatch");
|
|
25859
26400
|
} catch (e) {
|
|
25860
26401
|
if (e instanceof CreationClientError) throw e;
|
|
@@ -25868,7 +26409,7 @@ async function checkInstalledRuntime(root, version3, command2, { env = process.e
|
|
|
25868
26409
|
if (!major || Number(major[1]) < 20) throw Error("unsupported_node");
|
|
25869
26410
|
const result = await execute2(
|
|
25870
26411
|
command2,
|
|
25871
|
-
[
|
|
26412
|
+
[path14.join(root, "bin/promptframe-creation.mjs"), "--version"],
|
|
25872
26413
|
{ env, encoding: "utf8", timeout: 1e4, maxBuffer: 8192 }
|
|
25873
26414
|
);
|
|
25874
26415
|
if (result.stdout.trim() !== version3) throw Error("wrong_version");
|
|
@@ -25905,20 +26446,20 @@ async function installForUser({
|
|
|
25905
26446
|
const versionOutput = await runCodex(["--version"]);
|
|
25906
26447
|
const match = versionOutput.match(/codex-cli (\d+)\.(\d+)\.(\d+)/);
|
|
25907
26448
|
if (!match || Number(match[1]) === 0 && Number(match[2]) < 160) fail4("codex_0160_required");
|
|
25908
|
-
const payload = await inspectRuntimePackage(
|
|
25909
|
-
const root =
|
|
26449
|
+
const payload = await inspectRuntimePackage(path14.resolve(sourceRoot));
|
|
26450
|
+
const root = path14.resolve(env.XDG_DATA_HOME ?? path14.join(homedir5(), ".local/share"), "promptframe-creation", profile);
|
|
25910
26451
|
await privateDirectory3(root);
|
|
25911
26452
|
const release = await acquire(root, signal);
|
|
25912
|
-
const versions =
|
|
25913
|
-
const marketplaceFile =
|
|
26453
|
+
const versions = path14.join(root, "versions"), currentFile = path14.join(root, "current.json"), pendingFile = path14.join(root, "registration-pending.json");
|
|
26454
|
+
const marketplaceFile = path14.join(root, ".agents/plugins/marketplace.json");
|
|
25914
26455
|
const pluginName = "promptframe-creation" + (profile === "default" ? "" : "-" + profile), marketplace = "promptframe-creation-user" + (profile === "default" ? "" : "-" + profile);
|
|
25915
26456
|
const pluginId = pluginName + "@" + marketplace;
|
|
25916
|
-
const versionRoot =
|
|
26457
|
+
const versionRoot = path14.join(versions, payload.version), temporary = path14.join(versions, ".partial-" + randomBytes5(12).toString("hex"));
|
|
25917
26458
|
let previous, registrationStarted = false, newFiles = 0;
|
|
25918
26459
|
try {
|
|
25919
26460
|
signal?.throwIfAborted();
|
|
25920
26461
|
await privateDirectory3(versions);
|
|
25921
|
-
await privateDirectory3(
|
|
26462
|
+
await privateDirectory3(path14.dirname(marketplaceFile));
|
|
25922
26463
|
previous = await privateRead2(currentFile);
|
|
25923
26464
|
if (previous && (previous.profile !== profile || previous.pluginId !== pluginId || previous.configFile !== configFile2)) fail4("profile_binding_conflict");
|
|
25924
26465
|
const state = { installed: await relatedPlugins(runCodex, pluginName, env) };
|
|
@@ -25929,12 +26470,12 @@ async function installForUser({
|
|
|
25929
26470
|
const servers = legacy.filter((x) => x.name === serverName);
|
|
25930
26471
|
const pending = await privateRead2(pendingFile);
|
|
25931
26472
|
if (pending) {
|
|
25932
|
-
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !==
|
|
26473
|
+
if (pending.profile !== profile || pending.pluginId !== pluginId || pending.configFile !== configFile2 || pending.versionRoot !== path14.join(versions, pending.version)) fail4("profile_binding_conflict");
|
|
25933
26474
|
if (installed?.version !== pending.version || installed.enabled !== true || installed.source?.path !== pending.versionRoot)
|
|
25934
26475
|
fail4("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
25935
26476
|
const transport2 = await managedTransport(installed, versions, serverName, profile, configFile2);
|
|
25936
26477
|
if (servers.length !== 1 || servers[0].enabled === false || !sameTransport(servers[0].transport, transport2)) fail4("registration_unconfirmed_keep_existing");
|
|
25937
|
-
const ready = await privateRead2(
|
|
26478
|
+
const ready = await privateRead2(path14.join(pending.versionRoot, "installation.json"));
|
|
25938
26479
|
if (ready?.payloadDigest !== pending.payloadDigest) fail4("installed_files_invalid");
|
|
25939
26480
|
previous = pending;
|
|
25940
26481
|
await atomicJSON(currentFile, pending);
|
|
@@ -25989,43 +26530,43 @@ async function installForUser({
|
|
|
25989
26530
|
const target = await info2(versionRoot);
|
|
25990
26531
|
if (target) {
|
|
25991
26532
|
if (!target.isDirectory() || target.isSymbolicLink()) fail4("version_content_conflict");
|
|
25992
|
-
const ready = await privateRead2(
|
|
26533
|
+
const ready = await privateRead2(path14.join(versionRoot, "installation.json"));
|
|
25993
26534
|
if (!ready || ready.payloadDigest !== payload.payloadDigest || ready.profile !== profile || ready.configFile !== configFile2) fail4("version_content_conflict");
|
|
25994
26535
|
for (const f2 of ready.files) {
|
|
25995
26536
|
if (!payload.files.some((p2) => p2.path === f2.path)) fail4("installed_files_invalid");
|
|
25996
|
-
const file =
|
|
25997
|
-
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size !== f2.bytes ||
|
|
26537
|
+
const file = path14.join(versionRoot, f2.path), s3 = await info2(file);
|
|
26538
|
+
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size !== f2.bytes || hash5(await readFile6(file)) !== f2.sha256) fail4("installed_files_invalid");
|
|
25998
26539
|
}
|
|
25999
26540
|
if (ready.files.length !== payload.files.length) fail4("installed_files_invalid");
|
|
26000
26541
|
} else {
|
|
26001
|
-
await
|
|
26542
|
+
await mkdir6(temporary, { mode: 448 });
|
|
26002
26543
|
for (const f2 of payload.files) {
|
|
26003
26544
|
signal?.throwIfAborted();
|
|
26004
|
-
await
|
|
26005
|
-
await writeFile2(
|
|
26545
|
+
await mkdir6(path14.dirname(path14.join(temporary, f2.path)), { recursive: true, mode: 448 });
|
|
26546
|
+
await writeFile2(path14.join(temporary, f2.path), f2.body, { flag: "wx", mode: 384 });
|
|
26006
26547
|
}
|
|
26007
|
-
const manifest = await json(
|
|
26548
|
+
const manifest = await json(path14.join(temporary, ".codex-plugin/plugin.json"));
|
|
26008
26549
|
manifest.name = pluginName;
|
|
26009
|
-
await writeFile2(
|
|
26550
|
+
await writeFile2(path14.join(temporary, ".codex-plugin/plugin.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
26010
26551
|
const mcp = { mcpServers: { ["promptframe" + (profile === "default" ? "" : "-" + profile)]: {
|
|
26011
26552
|
command: process.execPath,
|
|
26012
|
-
args: [
|
|
26553
|
+
args: [path14.join(versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", configFile2],
|
|
26013
26554
|
cwd: versionRoot
|
|
26014
26555
|
} } };
|
|
26015
|
-
await writeFile2(
|
|
26556
|
+
await writeFile2(path14.join(temporary, ".mcp.json"), JSON.stringify(mcp, null, 2) + "\n");
|
|
26016
26557
|
await checkRuntime(temporary, payload.version);
|
|
26017
26558
|
const files = [];
|
|
26018
26559
|
for (const f2 of payload.files) {
|
|
26019
|
-
const body = await readFile6(
|
|
26020
|
-
files.push({ path: f2.path, bytes: body.length, sha256:
|
|
26560
|
+
const body = await readFile6(path14.join(temporary, f2.path));
|
|
26561
|
+
files.push({ path: f2.path, bytes: body.length, sha256: hash5(body) });
|
|
26021
26562
|
}
|
|
26022
|
-
await atomicJSON(
|
|
26563
|
+
await atomicJSON(path14.join(temporary, "installation.json"), { version: payload.version, profile, configFile: configFile2, payloadDigest: payload.payloadDigest, files });
|
|
26023
26564
|
signal?.throwIfAborted();
|
|
26024
|
-
await
|
|
26565
|
+
await rename6(temporary, versionRoot);
|
|
26025
26566
|
newFiles = payload.files.length;
|
|
26026
26567
|
}
|
|
26027
26568
|
if (newFiles === 0) {
|
|
26028
|
-
const launch = (await json(
|
|
26569
|
+
const launch = (await json(path14.join(versionRoot, ".mcp.json"))).mcpServers?.[serverName];
|
|
26029
26570
|
await verifyInstalledRuntime(versionRoot, payload.version, launch.command, { env });
|
|
26030
26571
|
}
|
|
26031
26572
|
const complete = { version: payload.version, profile, configFile: configFile2, pluginId, versionRoot, payloadDigest: payload.payloadDigest };
|
|
@@ -26064,16 +26605,16 @@ async function installForUser({
|
|
|
26064
26605
|
reloadRequired: !already,
|
|
26065
26606
|
recordedRuntimeRetained: Boolean(already && recorded && recorded.command !== process.execPath)
|
|
26066
26607
|
};
|
|
26067
|
-
} catch (
|
|
26608
|
+
} catch (error5) {
|
|
26068
26609
|
if (registrationStarted) {
|
|
26069
26610
|
fail4("registration_unconfirmed_keep_existing", {
|
|
26070
|
-
...installationErrorDetails(
|
|
26611
|
+
...installationErrorDetails(error5),
|
|
26071
26612
|
phase: "registration_observation",
|
|
26072
26613
|
localRegistrationState: "unknown",
|
|
26073
26614
|
action: "inspect_same_registration_no_second_add"
|
|
26074
26615
|
});
|
|
26075
26616
|
}
|
|
26076
|
-
if (
|
|
26617
|
+
if (error5 instanceof CreationClientError) throw error5;
|
|
26077
26618
|
if (signal?.aborted) fail4("interrupted_keep_existing");
|
|
26078
26619
|
fail4("failed_keep_existing");
|
|
26079
26620
|
} finally {
|
|
@@ -26083,10 +26624,10 @@ async function installForUser({
|
|
|
26083
26624
|
}
|
|
26084
26625
|
|
|
26085
26626
|
// lib/claude-installation.mjs
|
|
26086
|
-
import { createHash as
|
|
26087
|
-
import { mkdir as
|
|
26088
|
-
import { homedir as
|
|
26089
|
-
import
|
|
26627
|
+
import { createHash as createHash12, randomBytes as randomBytes7 } from "node:crypto";
|
|
26628
|
+
import { mkdir as mkdir8, open as open11, readFile as readFile9, rename as rename8, rm as rm5 } from "node:fs/promises";
|
|
26629
|
+
import { homedir as homedir10 } from "node:os";
|
|
26630
|
+
import path19 from "node:path";
|
|
26090
26631
|
|
|
26091
26632
|
// lib/claude-hook-definition.mjs
|
|
26092
26633
|
function claudeHostHooks({ pluginName = "promptframe-creation", serverName, configFile: configFile2, nodeCommand = "node", runtimeRoot = "${CLAUDE_PLUGIN_ROOT}" } = {}) {
|
|
@@ -26109,10 +26650,10 @@ function claudeHostHooks({ pluginName = "promptframe-creation", serverName, conf
|
|
|
26109
26650
|
// lib/claude-command.mjs
|
|
26110
26651
|
import { execFile as execFile3 } from "node:child_process";
|
|
26111
26652
|
import { promisify as promisify3 } from "node:util";
|
|
26112
|
-
import { access, lstat as
|
|
26113
|
-
import { constants as
|
|
26114
|
-
import { homedir as
|
|
26115
|
-
import
|
|
26653
|
+
import { access, lstat as lstat9, readdir as readdir5 } from "node:fs/promises";
|
|
26654
|
+
import { constants as constants6 } from "node:fs";
|
|
26655
|
+
import { homedir as homedir6 } from "node:os";
|
|
26656
|
+
import path15 from "node:path";
|
|
26116
26657
|
var execute3 = promisify3(execFile3);
|
|
26117
26658
|
var ClaudeCommandError = class extends CreationClientError {
|
|
26118
26659
|
constructor(code, details) {
|
|
@@ -26120,39 +26661,39 @@ var ClaudeCommandError = class extends CreationClientError {
|
|
|
26120
26661
|
this.details = details;
|
|
26121
26662
|
}
|
|
26122
26663
|
};
|
|
26123
|
-
var claudeErrorDetails = (
|
|
26124
|
-
async function resolveClaudeCommand({ env = process.env, homeDirectory =
|
|
26664
|
+
var claudeErrorDetails = (error5) => error5 instanceof ClaudeCommandError ? error5.details : void 0;
|
|
26665
|
+
async function resolveClaudeCommand({ env = process.env, homeDirectory = homedir6(), executable } = {}) {
|
|
26125
26666
|
const selected = executable ?? env.PROMPTFRAME_CLAUDE_BIN;
|
|
26126
26667
|
if (selected) {
|
|
26127
|
-
if (!
|
|
26128
|
-
await access(selected,
|
|
26668
|
+
if (!path15.isAbsolute(selected)) throw new CreationClientError("installation.claude_executable_invalid");
|
|
26669
|
+
await access(selected, constants6.X_OK);
|
|
26129
26670
|
return selected;
|
|
26130
26671
|
}
|
|
26131
|
-
for (const
|
|
26132
|
-
const file =
|
|
26672
|
+
for (const directory3 of (env.PATH ?? "").split(path15.delimiter).filter(path15.isAbsolute)) {
|
|
26673
|
+
const file = path15.join(directory3, process.platform === "win32" ? "claude.exe" : "claude");
|
|
26133
26674
|
try {
|
|
26134
|
-
await access(file,
|
|
26675
|
+
await access(file, constants6.X_OK);
|
|
26135
26676
|
return file;
|
|
26136
26677
|
} catch (e) {
|
|
26137
26678
|
if (!["ENOENT", "EACCES", "ENOTDIR"].includes(e.code)) throw e;
|
|
26138
26679
|
}
|
|
26139
26680
|
}
|
|
26140
|
-
const root =
|
|
26141
|
-
let
|
|
26681
|
+
const root = path15.join(homeDirectory, ".claude/remote/ccd-cli");
|
|
26682
|
+
let entries2;
|
|
26142
26683
|
try {
|
|
26143
|
-
|
|
26684
|
+
entries2 = await readdir5(root);
|
|
26144
26685
|
} catch (e) {
|
|
26145
26686
|
if (e.code === "ENOENT") throw new CreationClientError("installation.claude_required");
|
|
26146
26687
|
throw e;
|
|
26147
26688
|
}
|
|
26148
|
-
if (
|
|
26689
|
+
if (entries2.length > 32) throw new CreationClientError("installation.claude_executable_unconfirmed");
|
|
26149
26690
|
const candidates = [];
|
|
26150
|
-
for (const name of
|
|
26691
|
+
for (const name of entries2) {
|
|
26151
26692
|
const match = name.match(/^(\d+)\.(\d+)\.(\d+)-[a-f0-9]{6,40}$/);
|
|
26152
26693
|
if (!match) continue;
|
|
26153
|
-
const file =
|
|
26694
|
+
const file = path15.join(root, name), s3 = await lstat9(file);
|
|
26154
26695
|
if (s3.isFile() && !s3.isSymbolicLink() && s3.uid === process.getuid?.()) {
|
|
26155
|
-
await access(file,
|
|
26696
|
+
await access(file, constants6.X_OK);
|
|
26156
26697
|
candidates.push({ file, version: match.slice(1).map(Number) });
|
|
26157
26698
|
}
|
|
26158
26699
|
}
|
|
@@ -26188,17 +26729,17 @@ function createClaudeRunner({ env = process.env, executable, signal, resolve = r
|
|
|
26188
26729
|
}
|
|
26189
26730
|
|
|
26190
26731
|
// lib/claude-local-state.mjs
|
|
26191
|
-
import { readFile as readFile7, lstat as
|
|
26192
|
-
import { homedir as
|
|
26193
|
-
import
|
|
26732
|
+
import { readFile as readFile7, lstat as lstat10 } from "node:fs/promises";
|
|
26733
|
+
import { homedir as homedir7 } from "node:os";
|
|
26734
|
+
import path16 from "node:path";
|
|
26194
26735
|
function claudeConfigRoot(env = process.env) {
|
|
26195
|
-
return
|
|
26736
|
+
return path16.resolve(env.CLAUDE_CONFIG_DIR ?? path16.join(homedir7(), ".claude"));
|
|
26196
26737
|
}
|
|
26197
26738
|
async function readClaudeUserServer(serverName, env = process.env) {
|
|
26198
|
-
const file = env.CLAUDE_CONFIG_DIR ?
|
|
26739
|
+
const file = env.CLAUDE_CONFIG_DIR ? path16.join(claudeConfigRoot(env), ".claude.json") : path16.join(homedir7(), ".claude.json");
|
|
26199
26740
|
let info5;
|
|
26200
26741
|
try {
|
|
26201
|
-
info5 = await
|
|
26742
|
+
info5 = await lstat10(file);
|
|
26202
26743
|
} catch (e) {
|
|
26203
26744
|
if (e.code === "ENOENT") return null;
|
|
26204
26745
|
throw new CreationClientError("installation.claude_local_registration_unconfirmed");
|
|
@@ -26218,26 +26759,26 @@ async function readClaudeUserServer(serverName, env = process.env) {
|
|
|
26218
26759
|
}
|
|
26219
26760
|
|
|
26220
26761
|
// lib/claude-mcp-installation.mjs
|
|
26221
|
-
import { createHash as
|
|
26222
|
-
import { mkdir as
|
|
26223
|
-
import { homedir as
|
|
26224
|
-
import
|
|
26762
|
+
import { createHash as createHash11, randomBytes as randomBytes6 } from "node:crypto";
|
|
26763
|
+
import { mkdir as mkdir7, open as open10, readFile as readFile8, readdir as readdir6, rename as rename7, rm as rm4, lstat as lstat11 } from "node:fs/promises";
|
|
26764
|
+
import { homedir as homedir9 } from "node:os";
|
|
26765
|
+
import path18 from "node:path";
|
|
26225
26766
|
|
|
26226
26767
|
// lib/claude-hook-registration.mjs
|
|
26227
|
-
import { createHash as
|
|
26228
|
-
import { open as
|
|
26229
|
-
import { constants as
|
|
26230
|
-
import
|
|
26231
|
-
import { homedir as
|
|
26768
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
26769
|
+
import { open as open9, rm as rm3 } from "node:fs/promises";
|
|
26770
|
+
import { constants as constants7 } from "node:fs";
|
|
26771
|
+
import path17 from "node:path";
|
|
26772
|
+
import { homedir as homedir8 } from "node:os";
|
|
26232
26773
|
var { privateDirectory: privateDirectory4, privateRead: privateRead3, atomicJSON: atomicJSON2, acquire: acquire2 } = installationFiles;
|
|
26233
|
-
var digest4 = (value2) =>
|
|
26774
|
+
var digest4 = (value2) => createHash10("sha256").update(JSON.stringify(value2)).digest("hex");
|
|
26234
26775
|
var fail5 = () => {
|
|
26235
26776
|
throw new CreationClientError("installation.claude_hooks_require_review");
|
|
26236
26777
|
};
|
|
26237
26778
|
async function settings(file) {
|
|
26238
26779
|
let handle;
|
|
26239
26780
|
try {
|
|
26240
|
-
handle = await
|
|
26781
|
+
handle = await open9(file, constants7.O_RDONLY | constants7.O_NOFOLLOW);
|
|
26241
26782
|
const info5 = await handle.stat();
|
|
26242
26783
|
if (!info5.isFile() || info5.uid !== process.getuid?.() || info5.size > 512 * 1024) fail5();
|
|
26243
26784
|
const value2 = JSON.parse(await handle.readFile("utf8"));
|
|
@@ -26250,29 +26791,29 @@ async function settings(file) {
|
|
|
26250
26791
|
await handle?.close();
|
|
26251
26792
|
}
|
|
26252
26793
|
}
|
|
26253
|
-
var contains = (value2,
|
|
26794
|
+
var contains = (value2, entries2) => Object.entries(entries2).every(([event, wanted]) => Array.isArray(value2.hooks?.[event]) && wanted.every((entry) => value2.hooks[event].filter((actual) => digest4(actual) === digest4(entry)).length === 1));
|
|
26254
26795
|
async function verifyClaudeFallbackHooks(record2, env) {
|
|
26255
|
-
if (!record2?.settingsFile || record2.settingsFile !==
|
|
26796
|
+
if (!record2?.settingsFile || record2.settingsFile !== path17.join(claudeConfigRoot(env), "settings.json") || !record2.entries) fail5();
|
|
26256
26797
|
if (!contains(await settings(record2.settingsFile), record2.entries)) fail5();
|
|
26257
26798
|
return true;
|
|
26258
26799
|
}
|
|
26259
26800
|
async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCommand, signal }) {
|
|
26260
|
-
const
|
|
26261
|
-
const guard =
|
|
26262
|
-
env.XDG_DATA_HOME ??
|
|
26801
|
+
const directory3 = claudeConfigRoot(env), file = path17.join(directory3, "settings.json");
|
|
26802
|
+
const guard = path17.resolve(
|
|
26803
|
+
env.XDG_DATA_HOME ?? path17.join(homedir8(), ".local/share"),
|
|
26263
26804
|
"promptframe-creation",
|
|
26264
|
-
"claude-hook-writer-" + digest4(
|
|
26805
|
+
"claude-hook-writer-" + digest4(directory3)
|
|
26265
26806
|
);
|
|
26266
26807
|
await privateDirectory4(guard);
|
|
26267
26808
|
const release = await acquire2(guard, signal);
|
|
26268
|
-
const markerFile =
|
|
26809
|
+
const markerFile = path17.join(root, "hooks-current.json"), pendingFile = path17.join(root, "hooks-pending.json");
|
|
26269
26810
|
try {
|
|
26270
|
-
await privateDirectory4(
|
|
26271
|
-
const
|
|
26272
|
-
const expected = { contractVersion: "creation-claude-hooks/v1", settingsFile: file, profile: record2.profile, entries };
|
|
26811
|
+
await privateDirectory4(directory3);
|
|
26812
|
+
const entries2 = claudeHostHooks({ serverName: record2.serverName, configFile: record2.configFile, nodeCommand, runtimeRoot: record2.versionRoot });
|
|
26813
|
+
const expected = { contractVersion: "creation-claude-hooks/v1", settingsFile: file, profile: record2.profile, entries: entries2 };
|
|
26273
26814
|
const pending = await privateRead3(pendingFile), previous = await privateRead3(markerFile), before = await settings(file);
|
|
26274
26815
|
if (pending) {
|
|
26275
|
-
if (digest4(pending) !== digest4(expected) || !contains(before,
|
|
26816
|
+
if (digest4(pending) !== digest4(expected) || !contains(before, entries2)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
26276
26817
|
await atomicJSON2(markerFile, expected);
|
|
26277
26818
|
await rm3(pendingFile);
|
|
26278
26819
|
return expected;
|
|
@@ -26283,7 +26824,7 @@ async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCom
|
|
|
26283
26824
|
if (digest4(previous) === digest4(expected)) return previous;
|
|
26284
26825
|
}
|
|
26285
26826
|
const next = { ...before, hooks: { ...before.hooks } };
|
|
26286
|
-
for (const [event, wanted] of Object.entries(
|
|
26827
|
+
for (const [event, wanted] of Object.entries(entries2)) {
|
|
26287
26828
|
const actual = next.hooks[event] ?? [];
|
|
26288
26829
|
if (!Array.isArray(actual)) fail5();
|
|
26289
26830
|
const owned = new Set((previous?.entries[event] ?? []).map(digest4));
|
|
@@ -26294,7 +26835,7 @@ async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCom
|
|
|
26294
26835
|
await atomicJSON2(pendingFile, expected);
|
|
26295
26836
|
if (digest4(await settings(file)) !== digest4(before)) fail5();
|
|
26296
26837
|
await atomicJSON2(file, next);
|
|
26297
|
-
if (!contains(await settings(file),
|
|
26838
|
+
if (!contains(await settings(file), entries2)) throw new CreationClientError("installation.registration_unconfirmed_keep_existing");
|
|
26298
26839
|
await atomicJSON2(markerFile, expected);
|
|
26299
26840
|
await rm3(pendingFile);
|
|
26300
26841
|
return expected;
|
|
@@ -26305,23 +26846,23 @@ async function registerClaudeFallbackHooks({ record: record2, root, env, nodeCom
|
|
|
26305
26846
|
|
|
26306
26847
|
// lib/claude-mcp-installation.mjs
|
|
26307
26848
|
var { info: info3, privateDirectory: privateDirectory5, privateRead: privateRead4, atomicJSON: atomicJSON3, acquire: acquire3, compareVersions: compareVersions2 } = installationFiles;
|
|
26308
|
-
var
|
|
26849
|
+
var hash6 = (body) => createHash11("sha256").update(body).digest("hex");
|
|
26309
26850
|
var FallbackError = class extends CreationClientError {
|
|
26310
26851
|
constructor(code, details) {
|
|
26311
26852
|
super("installation." + code);
|
|
26312
26853
|
this.details = details;
|
|
26313
26854
|
}
|
|
26314
26855
|
};
|
|
26315
|
-
var fallbackErrorDetails = (
|
|
26856
|
+
var fallbackErrorDetails = (error5) => error5 instanceof FallbackError ? error5.details : void 0;
|
|
26316
26857
|
var fail6 = (code, details) => {
|
|
26317
26858
|
throw new FallbackError(code, details);
|
|
26318
26859
|
};
|
|
26319
26860
|
async function claimSkillDirectory(root) {
|
|
26320
26861
|
try {
|
|
26321
|
-
await
|
|
26322
|
-
} catch (
|
|
26323
|
-
if (
|
|
26324
|
-
throw
|
|
26862
|
+
await mkdir7(root, { mode: 448 });
|
|
26863
|
+
} catch (error5) {
|
|
26864
|
+
if (error5.code === "EEXIST") fail6("claude_skill_requires_review");
|
|
26865
|
+
throw error5;
|
|
26325
26866
|
}
|
|
26326
26867
|
}
|
|
26327
26868
|
function same(a, b2, depth = 0) {
|
|
@@ -26333,15 +26874,15 @@ function same(a, b2, depth = 0) {
|
|
|
26333
26874
|
async function atomicText(file, body) {
|
|
26334
26875
|
const temporary = file + "." + randomBytes6(12).toString("hex") + ".tmp";
|
|
26335
26876
|
try {
|
|
26336
|
-
const fd = await
|
|
26877
|
+
const fd = await open10(temporary, "wx", 384);
|
|
26337
26878
|
try {
|
|
26338
26879
|
await fd.writeFile(body);
|
|
26339
26880
|
await fd.sync();
|
|
26340
26881
|
} finally {
|
|
26341
26882
|
await fd.close();
|
|
26342
26883
|
}
|
|
26343
|
-
await
|
|
26344
|
-
const dir = await
|
|
26884
|
+
await rename7(temporary, file);
|
|
26885
|
+
const dir = await open10(path18.dirname(file), "r");
|
|
26345
26886
|
try {
|
|
26346
26887
|
await dir.sync();
|
|
26347
26888
|
} finally {
|
|
@@ -26352,17 +26893,17 @@ async function atomicText(file, body) {
|
|
|
26352
26893
|
}
|
|
26353
26894
|
}
|
|
26354
26895
|
async function verifyVersion(root, record2) {
|
|
26355
|
-
const
|
|
26356
|
-
if (!
|
|
26357
|
-
const marker = await privateRead4(
|
|
26358
|
-
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 || !
|
|
26896
|
+
const directory3 = await info3(root);
|
|
26897
|
+
if (!directory3?.isDirectory() || directory3.isSymbolicLink() || directory3.uid !== process.getuid?.() || directory3.mode & 63) fail6("claude_installed_files_invalid");
|
|
26898
|
+
const marker = await privateRead4(path18.join(root, "installation.json")), payload = await inspectRuntimePackage(root);
|
|
26899
|
+
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 || !path18.isAbsolute(marker.nodeCommand ?? "")) fail6("claude_installed_files_invalid");
|
|
26359
26900
|
return marker;
|
|
26360
26901
|
}
|
|
26361
26902
|
function mcpDefinition(record2, nodeCommand) {
|
|
26362
26903
|
return {
|
|
26363
26904
|
type: "stdio",
|
|
26364
26905
|
command: nodeCommand,
|
|
26365
|
-
args: [
|
|
26906
|
+
args: [path18.join(record2.versionRoot, "bin/promptframe-creation.mjs"), "bridge", "--config", record2.configFile, "--host", "claude-code"]
|
|
26366
26907
|
};
|
|
26367
26908
|
}
|
|
26368
26909
|
function skillBody(payload, sourceName, name) {
|
|
@@ -26373,17 +26914,17 @@ function skillBody(payload, sourceName, name) {
|
|
|
26373
26914
|
return body.replace("\nname: " + sourceName + "\n", "\nname: " + name + "\n");
|
|
26374
26915
|
}
|
|
26375
26916
|
async function observedSkill(plan, record2, { allowBefore = false } = {}) {
|
|
26376
|
-
const
|
|
26377
|
-
if (!
|
|
26378
|
-
if (!
|
|
26917
|
+
const directory3 = await info3(plan.root);
|
|
26918
|
+
if (!directory3) return false;
|
|
26919
|
+
if (!directory3.isDirectory() || directory3.isSymbolicLink() || directory3.uid !== process.getuid?.() || directory3.mode & 63) fail6("claude_skill_requires_review");
|
|
26379
26920
|
const names = await readdir6(plan.root);
|
|
26380
26921
|
if (names.some((n) => !["SKILL.md", "promptframe-installation.json"].includes(n))) fail6("claude_skill_requires_review");
|
|
26381
|
-
const marker = await privateRead4(
|
|
26922
|
+
const marker = await privateRead4(path18.join(plan.root, "promptframe-installation.json")), file = path18.join(plan.root, "SKILL.md"), s3 = await info3(file);
|
|
26382
26923
|
if (!marker || marker.host !== "claude-code" || marker.profile !== record2.profile || marker.configFile !== record2.configFile || marker.name !== plan.name)
|
|
26383
26924
|
fail6("claude_skill_requires_review");
|
|
26384
26925
|
if (!s3 && allowBefore && plan.beforeSHA === null && marker.sha256 === null) return false;
|
|
26385
26926
|
if (!s3?.isFile() || s3.isSymbolicLink() || s3.size > 256 * 1024) fail6("claude_skill_requires_review");
|
|
26386
|
-
const digest5 =
|
|
26927
|
+
const digest5 = hash6(await readFile8(file));
|
|
26387
26928
|
if (digest5 === plan.sha256 && marker.sha256 === plan.sha256) return true;
|
|
26388
26929
|
if (allowBefore && (digest5 === plan.beforeSHA || digest5 === plan.sha256) && marker.sha256 === plan.beforeSHA) return false;
|
|
26389
26930
|
fail6("claude_skill_requires_review");
|
|
@@ -26400,13 +26941,13 @@ async function installClaudeMcpFallback({
|
|
|
26400
26941
|
nodeCommand,
|
|
26401
26942
|
writeSkill = atomicText
|
|
26402
26943
|
}) {
|
|
26403
|
-
const payload = await inspectRuntimePackage(
|
|
26944
|
+
const payload = await inspectRuntimePackage(path18.resolve(sourceRoot)), suffix = profile === "default" ? "" : "-" + profile, serverName = "promptframe" + suffix, root = path18.resolve(env.XDG_DATA_HOME ?? path18.join(homedir9(), ".local/share"), "promptframe-creation", profile, "claude-code-mcp");
|
|
26404
26945
|
await privateDirectory5(root);
|
|
26405
|
-
const release = await acquire3(root, signal), versions =
|
|
26946
|
+
const release = await acquire3(root, signal), versions = path18.join(root, "versions"), currentFile = path18.join(root, "current.json"), pendingFile = path18.join(root, "registration-pending.json"), versionRoot = path18.join(versions, payload.version), temporary = path18.join(versions, ".partial-" + randomBytes6(12).toString("hex"));
|
|
26406
26947
|
let writeStarted = false, newFiles = 0;
|
|
26407
26948
|
const complete = { host: "claude-code", mode: "mcp-and-skills", profile, configFile: configFile2, serverName, version: payload.version, versionRoot, payloadDigest: payload.payloadDigest };
|
|
26408
26949
|
const checkBinding = (record2) => {
|
|
26409
|
-
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 !==
|
|
26950
|
+
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 !== path18.join(versions, record2.version))) fail6("profile_binding_conflict");
|
|
26410
26951
|
};
|
|
26411
26952
|
try {
|
|
26412
26953
|
await privateDirectory5(versions);
|
|
@@ -26423,7 +26964,7 @@ async function installClaudeMcpFallback({
|
|
|
26423
26964
|
if (!Array.isArray(record2.skills) || record2.skills.length !== 2) fail6("claude_skill_requires_review");
|
|
26424
26965
|
for (const [i, skill] of record2.skills.entries()) {
|
|
26425
26966
|
const name = ["creation-setup", "video-creation"][i] + suffix;
|
|
26426
|
-
if (skill.name !== name || skill.root !==
|
|
26967
|
+
if (skill.name !== name || skill.root !== path18.join(claudeConfigRoot(env), "skills", name) || !/^[a-f0-9]{64}$/.test(skill.sha256 ?? ""))
|
|
26427
26968
|
fail6("claude_skill_requires_review");
|
|
26428
26969
|
if (!await observedSkill(skill, record2)) return false;
|
|
26429
26970
|
}
|
|
@@ -26463,12 +27004,12 @@ async function installClaudeMcpFallback({
|
|
|
26463
27004
|
} else if (saved && !pending) fail6("legacy_mcp_entry_requires_review");
|
|
26464
27005
|
if (await info3(versionRoot)) await verifyVersion(versionRoot, complete);
|
|
26465
27006
|
else {
|
|
26466
|
-
await
|
|
27007
|
+
await mkdir7(temporary, { mode: 448 });
|
|
26467
27008
|
for (const file of payload.files) {
|
|
26468
27009
|
signal?.throwIfAborted();
|
|
26469
|
-
const dest =
|
|
26470
|
-
await
|
|
26471
|
-
const fd = await
|
|
27010
|
+
const dest = path18.join(temporary, file.path);
|
|
27011
|
+
await mkdir7(path18.dirname(dest), { recursive: true, mode: 448 });
|
|
27012
|
+
const fd = await open10(dest, "wx", 384);
|
|
26472
27013
|
try {
|
|
26473
27014
|
await fd.writeFile(file.body);
|
|
26474
27015
|
await fd.sync();
|
|
@@ -26477,21 +27018,21 @@ async function installClaudeMcpFallback({
|
|
|
26477
27018
|
}
|
|
26478
27019
|
}
|
|
26479
27020
|
await checkRuntime(temporary, payload.version);
|
|
26480
|
-
await atomicJSON3(
|
|
27021
|
+
await atomicJSON3(path18.join(temporary, "installation.json"), { ...complete, nodeCommand });
|
|
26481
27022
|
signal?.throwIfAborted();
|
|
26482
|
-
await
|
|
27023
|
+
await rename7(temporary, versionRoot);
|
|
26483
27024
|
newFiles = payload.files.length;
|
|
26484
27025
|
}
|
|
26485
27026
|
const ready = await verifyVersion(versionRoot, complete);
|
|
26486
27027
|
complete.server = mcpDefinition(complete, ready.nodeCommand);
|
|
26487
27028
|
if (newFiles === 0) await verifyInstalledRuntime(versionRoot, payload.version, ready.nodeCommand, { env });
|
|
26488
|
-
const skillRoot =
|
|
26489
|
-
await
|
|
26490
|
-
const parent = await
|
|
27029
|
+
const skillRoot = path18.join(claudeConfigRoot(env), "skills");
|
|
27030
|
+
await mkdir7(skillRoot, { recursive: true, mode: 448 });
|
|
27031
|
+
const parent = await lstat11(skillRoot);
|
|
26491
27032
|
if (!parent.isDirectory() || parent.isSymbolicLink() || parent.uid !== process.getuid?.()) fail6("claude_skill_requires_review");
|
|
26492
27033
|
const plans = [];
|
|
26493
27034
|
for (const sourceName of ["creation-setup", "video-creation"]) {
|
|
26494
|
-
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root:
|
|
27035
|
+
const name = sourceName + suffix, body = skillBody(payload, sourceName, name), skill = { name, root: path18.join(skillRoot, name), sha256: hash6(body) };
|
|
26495
27036
|
if (pending) {
|
|
26496
27037
|
const old = pending.skills?.find((s3) => s3.name === name);
|
|
26497
27038
|
if (!old || old.root !== skill.root || old.sha256 !== skill.sha256) fail6("registration_unconfirmed_keep_existing");
|
|
@@ -26500,7 +27041,7 @@ async function installClaudeMcpFallback({
|
|
|
26500
27041
|
const existing = await info3(skill.root);
|
|
26501
27042
|
let beforeSHA = null;
|
|
26502
27043
|
if (existing) {
|
|
26503
|
-
const marker = await privateRead4(
|
|
27044
|
+
const marker = await privateRead4(path18.join(skill.root, "promptframe-installation.json"));
|
|
26504
27045
|
if (!marker || marker.profile !== profile || marker.configFile !== configFile2 || marker.name !== name) fail6("claude_skill_requires_review");
|
|
26505
27046
|
const old = { ...skill, sha256: marker.sha256 };
|
|
26506
27047
|
if (!await observedSkill(old, complete)) fail6("claude_skill_requires_review");
|
|
@@ -26521,10 +27062,10 @@ async function installClaudeMcpFallback({
|
|
|
26521
27062
|
} else {
|
|
26522
27063
|
if (plan.beforeSHA !== null) fail6("claude_skill_requires_review");
|
|
26523
27064
|
await claimSkillDirectory(plan.root);
|
|
26524
|
-
await atomicJSON3(
|
|
27065
|
+
await atomicJSON3(path18.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: null });
|
|
26525
27066
|
}
|
|
26526
|
-
await writeSkill(
|
|
26527
|
-
await atomicJSON3(
|
|
27067
|
+
await writeSkill(path18.join(plan.root, "SKILL.md"), plan.body);
|
|
27068
|
+
await atomicJSON3(path18.join(plan.root, "promptframe-installation.json"), { host: "claude-code", profile, configFile: configFile2, name: plan.name, sha256: plan.sha256 });
|
|
26528
27069
|
}
|
|
26529
27070
|
signal?.throwIfAborted();
|
|
26530
27071
|
if (compareVersions2(payload.version, "0.3.1") >= 0) complete.hostHooks = await registerClaudeFallbackHooks({ record: complete, root, env, nodeCommand: ready.nodeCommand, signal });
|
|
@@ -26549,9 +27090,9 @@ async function installClaudeMcpFallback({
|
|
|
26549
27090
|
requestedVersion: payload.version,
|
|
26550
27091
|
versionStatus: "current"
|
|
26551
27092
|
};
|
|
26552
|
-
} catch (
|
|
27093
|
+
} catch (error5) {
|
|
26553
27094
|
if (writeStarted) fail6("registration_unconfirmed_keep_existing", { phase: "registration_observation", localRegistrationState: "unknown", action: "inspect_same_registration_no_second_add" });
|
|
26554
|
-
if (
|
|
27095
|
+
if (error5 instanceof CreationClientError) throw error5;
|
|
26555
27096
|
fail6(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
26556
27097
|
} finally {
|
|
26557
27098
|
await rm4(temporary, { recursive: true, force: true });
|
|
@@ -26569,7 +27110,7 @@ var ClaudeInstallationError = class extends CreationClientError {
|
|
|
26569
27110
|
this.details = details;
|
|
26570
27111
|
}
|
|
26571
27112
|
};
|
|
26572
|
-
var claudeInstallationDetails = (
|
|
27113
|
+
var claudeInstallationDetails = (error5) => error5 instanceof ClaudeInstallationError ? error5.details : void 0;
|
|
26573
27114
|
var fail7 = (code, details) => {
|
|
26574
27115
|
throw new ClaudeInstallationError(code, details);
|
|
26575
27116
|
};
|
|
@@ -26593,7 +27134,7 @@ async function registrations(run, pluginName, marketplace, root) {
|
|
|
26593
27134
|
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"))
|
|
26594
27135
|
fail7("claude_local_registration_unconfirmed");
|
|
26595
27136
|
const related = plugins.filter((p2) => typeof p2?.id === "string" && p2.id.startsWith(pluginName + "@"));
|
|
26596
|
-
if (related.length > 1 || related.some((p2) => p2.id !== pluginName + "@" + marketplace || p2.scope !== "user" || typeof p2.enabled !== "boolean" || !/^\d+\.\d+\.\d+$/.test(p2.version ?? "") || !
|
|
27137
|
+
if (related.length > 1 || related.some((p2) => p2.id !== pluginName + "@" + marketplace || p2.scope !== "user" || typeof p2.enabled !== "boolean" || !/^\d+\.\d+\.\d+$/.test(p2.version ?? "") || !path19.isAbsolute(p2.installPath ?? "") || p2.readFromFolder !== void 0 && (!path19.isAbsolute(p2.readFromFolder) || !/^\d+\.\d+\.\d+$/.test(p2.folderVersion ?? ""))))
|
|
26597
27138
|
fail7("claude_existing_registration_requires_review");
|
|
26598
27139
|
const found = markets.filter((p2) => p2?.name === marketplace);
|
|
26599
27140
|
if (found.length > 1 || found.some((p2) => p2.source !== "directory" || p2.path !== root || p2.installLocation !== root))
|
|
@@ -26610,22 +27151,22 @@ function transport(serverName, configFile2, command2 = process.execPath) {
|
|
|
26610
27151
|
} } };
|
|
26611
27152
|
}
|
|
26612
27153
|
async function verifyVersion2(root, { version: version3, profile, configFile: configFile2, payloadDigest, pluginName, serverName }) {
|
|
26613
|
-
const
|
|
26614
|
-
if (!
|
|
27154
|
+
const directory3 = await info4(root);
|
|
27155
|
+
if (!directory3?.isDirectory() || directory3.isSymbolicLink() || directory3.uid !== process.getuid?.() || directory3.mode & 63)
|
|
26615
27156
|
fail7("claude_installed_files_invalid");
|
|
26616
|
-
const ready = await privateRead5(
|
|
27157
|
+
const ready = await privateRead5(path19.join(root, "installation.json"));
|
|
26617
27158
|
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) fail7("claude_installed_files_invalid");
|
|
26618
27159
|
const actual = await inspectRuntimePackage(root);
|
|
26619
|
-
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path:
|
|
27160
|
+
if (actual.version !== version3 || JSON.stringify(actual.files.map(({ path: path21, bytes: bytes2, sha256 }) => ({ path: path21, bytes: bytes2, sha256 }))) !== JSON.stringify(ready.files))
|
|
26620
27161
|
fail7("claude_installed_files_invalid");
|
|
26621
|
-
const manifest = JSON.parse(await readFile9(
|
|
27162
|
+
const manifest = JSON.parse(await readFile9(path19.join(root, ".claude-plugin/plugin.json"), "utf8"));
|
|
26622
27163
|
if (manifest.name !== pluginName || manifest.version !== version3 || manifest.skills !== "./skills/" || manifest.mcpServers !== "./.claude-mcp.json")
|
|
26623
27164
|
fail7("claude_installed_files_invalid");
|
|
26624
27165
|
let runtimeCommand;
|
|
26625
27166
|
for (const file of [".mcp.json", ".claude-mcp.json"]) {
|
|
26626
|
-
const mcp = JSON.parse(await readFile9(
|
|
27167
|
+
const mcp = JSON.parse(await readFile9(path19.join(root, file), "utf8"));
|
|
26627
27168
|
const command2 = mcp.mcpServers?.[serverName]?.command;
|
|
26628
|
-
if (!
|
|
27169
|
+
if (!path19.isAbsolute(command2 ?? "") || runtimeCommand !== void 0 && command2 !== runtimeCommand || JSON.stringify(mcp) !== JSON.stringify(transport(serverName, configFile2, command2))) fail7("claude_installed_files_invalid");
|
|
26629
27170
|
runtimeCommand = command2;
|
|
26630
27171
|
}
|
|
26631
27172
|
if (compareVersions3(version3, "0.3.1") >= 0 && JSON.stringify(manifest.hooks) !== JSON.stringify(claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand: runtimeCommand })))
|
|
@@ -26635,7 +27176,7 @@ async function verifyVersion2(root, { version: version3, profile, configFile: co
|
|
|
26635
27176
|
async function installForClaudeUser(options = {}) {
|
|
26636
27177
|
const profile = options.profile ?? "default", env = options.env ?? process.env;
|
|
26637
27178
|
validProfile2(profile);
|
|
26638
|
-
const modeRoot =
|
|
27179
|
+
const modeRoot = path19.resolve(env.XDG_DATA_HOME ?? path19.join(homedir10(), ".local/share"), "promptframe-creation", profile, "claude-code-mode");
|
|
26639
27180
|
await privateDirectory6(modeRoot);
|
|
26640
27181
|
const release = await acquire4(modeRoot, options.signal);
|
|
26641
27182
|
try {
|
|
@@ -26657,37 +27198,37 @@ async function installClaudeUserLocked({
|
|
|
26657
27198
|
nodeCommand = process.execPath
|
|
26658
27199
|
} = {}) {
|
|
26659
27200
|
validProfile2(profile);
|
|
26660
|
-
if (!
|
|
27201
|
+
if (!path19.isAbsolute(nodeCommand)) fail7("runtime_command_invalid");
|
|
26661
27202
|
const hostVersion = (await runClaude(["--version"])).trim().match(/^(\d+\.\d+\.\d+) \(Claude Code\)$/);
|
|
26662
27203
|
if (!hostVersion || compareVersions3(hostVersion[1], "2.1.295") < 0) fail7("claude_21295_required");
|
|
26663
27204
|
const help = await runClaude(["--help"]);
|
|
26664
27205
|
if (typeof help !== "string" || Buffer.byteLength(help) > 128 * 1024) fail7("claude_capabilities_unconfirmed");
|
|
26665
27206
|
const hasPlugin = /^\s+plugin(?:\|plugins)?\s/m.test(help), hasMcp = /^\s+mcp\s/m.test(help);
|
|
26666
|
-
const base =
|
|
26667
|
-
const pluginPending = await info4(
|
|
27207
|
+
const base = path19.resolve(env.XDG_DATA_HOME ?? path19.join(homedir10(), ".local/share"), "promptframe-creation", profile), fallbackRoot = path19.join(base, "claude-code-mcp"), pluginRoot = path19.join(base, "claude-code");
|
|
27208
|
+
const pluginPending = await info4(path19.join(pluginRoot, "registration-pending.json")), pluginCurrent = await info4(path19.join(pluginRoot, "current.json")), fallbackState = await info4(path19.join(fallbackRoot, "current.json")) || await info4(path19.join(fallbackRoot, "registration-pending.json"));
|
|
26668
27209
|
if ((!hasPlugin || fallbackState) && (pluginPending || pluginCurrent)) fail7("registration_unconfirmed_keep_existing");
|
|
26669
27210
|
if (!hasPlugin || fallbackState) {
|
|
26670
27211
|
if (!hasMcp) fail7("claude_capabilities_unconfirmed");
|
|
26671
27212
|
return installClaudeMcpFallback({ sourceRoot, profile, env, configFile: configFile2, signal, runClaude, checkRuntime, verifyInstalledRuntime, nodeCommand });
|
|
26672
27213
|
}
|
|
26673
|
-
const payload = await inspectRuntimePackage(
|
|
27214
|
+
const payload = await inspectRuntimePackage(path19.resolve(sourceRoot));
|
|
26674
27215
|
if (!payload.files.some((f2) => f2.path === ".claude-plugin/plugin.json") || !payload.files.some((f2) => f2.path === ".claude-mcp.json"))
|
|
26675
27216
|
fail7("claude_package_incomplete");
|
|
26676
|
-
const root =
|
|
27217
|
+
const root = path19.resolve(env.XDG_DATA_HOME ?? path19.join(homedir10(), ".local/share"), "promptframe-creation", profile, "claude-code");
|
|
26677
27218
|
await privateDirectory6(root);
|
|
26678
27219
|
const release = await acquire4(root, signal);
|
|
26679
27220
|
const suffix = profile === "default" ? "" : "-" + profile, pluginName = "promptframe-creation" + suffix, marketplace = "promptframe-creation-user" + suffix, pluginId = pluginName + "@" + marketplace, serverName = "promptframe" + suffix;
|
|
26680
|
-
const versions =
|
|
27221
|
+
const versions = path19.join(root, "versions"), currentFile = path19.join(root, "current.json"), pendingFile = path19.join(root, "registration-pending.json"), catalogFile = path19.join(root, ".claude-plugin/marketplace.json"), versionRoot = path19.join(versions, payload.version), temporary = path19.join(versions, ".partial-" + randomBytes7(12).toString("hex"));
|
|
26681
27222
|
let registrationStarted = false, newFiles = 0;
|
|
26682
27223
|
try {
|
|
26683
27224
|
signal?.throwIfAborted();
|
|
26684
27225
|
await privateDirectory6(versions);
|
|
26685
|
-
await privateDirectory6(
|
|
27226
|
+
await privateDirectory6(path19.dirname(catalogFile));
|
|
26686
27227
|
await legacyUserMcp(env, serverName);
|
|
26687
27228
|
let previous = await privateRead5(currentFile), pending = await privateRead5(pendingFile), state = await registrations(runClaude, pluginName, marketplace, root);
|
|
26688
27229
|
const binding = { profile, configFile: configFile2, pluginId, pluginName, serverName, host: "claude-code" };
|
|
26689
27230
|
const checkBinding = (record2) => {
|
|
26690
|
-
if (record2 && (record2.profile !== profile || record2.configFile !== configFile2 || record2.pluginId !== pluginId || record2.host !== "claude-code" || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !==
|
|
27231
|
+
if (record2 && (record2.profile !== profile || record2.configFile !== configFile2 || record2.pluginId !== pluginId || record2.host !== "claude-code" || !/^\d+\.\d+\.\d+$/.test(record2.version ?? "") || record2.versionRoot !== path19.join(versions, record2.version))) fail7("profile_binding_conflict");
|
|
26691
27232
|
};
|
|
26692
27233
|
checkBinding(previous);
|
|
26693
27234
|
checkBinding(pending);
|
|
@@ -26731,12 +27272,12 @@ async function installClaudeUserLocked({
|
|
|
26731
27272
|
const ready = await verifyVersion2(versionRoot, { ...complete, pluginName, serverName });
|
|
26732
27273
|
runtimeCommands.set(versionRoot, ready.runtimeCommand);
|
|
26733
27274
|
} else {
|
|
26734
|
-
await
|
|
27275
|
+
await mkdir8(temporary, { mode: 448 });
|
|
26735
27276
|
for (const file of payload.files) {
|
|
26736
27277
|
signal?.throwIfAborted();
|
|
26737
|
-
const dest =
|
|
26738
|
-
await
|
|
26739
|
-
const fd = await
|
|
27278
|
+
const dest = path19.join(temporary, file.path);
|
|
27279
|
+
await mkdir8(path19.dirname(dest), { recursive: true, mode: 448 });
|
|
27280
|
+
const fd = await open11(dest, "wx", 384);
|
|
26740
27281
|
try {
|
|
26741
27282
|
await fd.writeFile(file.body);
|
|
26742
27283
|
await fd.sync();
|
|
@@ -26744,21 +27285,21 @@ async function installClaudeUserLocked({
|
|
|
26744
27285
|
await fd.close();
|
|
26745
27286
|
}
|
|
26746
27287
|
}
|
|
26747
|
-
const manifest = JSON.parse(await readFile9(
|
|
27288
|
+
const manifest = JSON.parse(await readFile9(path19.join(temporary, ".claude-plugin/plugin.json"), "utf8"));
|
|
26748
27289
|
manifest.name = pluginName;
|
|
26749
27290
|
if (manifest.hooks) manifest.hooks = claudeHostHooks({ pluginName, configFile: configFile2, nodeCommand });
|
|
26750
|
-
await atomicJSON4(
|
|
26751
|
-
for (const file of [".mcp.json", ".claude-mcp.json"]) await atomicJSON4(
|
|
27291
|
+
await atomicJSON4(path19.join(temporary, ".claude-plugin/plugin.json"), manifest);
|
|
27292
|
+
for (const file of [".mcp.json", ".claude-mcp.json"]) await atomicJSON4(path19.join(temporary, file), transport(serverName, configFile2, nodeCommand));
|
|
26752
27293
|
await checkRuntime(temporary, payload.version);
|
|
26753
27294
|
const installed = await inspectRuntimePackage(temporary);
|
|
26754
|
-
await atomicJSON4(
|
|
27295
|
+
await atomicJSON4(path19.join(temporary, "installation.json"), {
|
|
26755
27296
|
...binding,
|
|
26756
27297
|
version: payload.version,
|
|
26757
27298
|
payloadDigest: payload.payloadDigest,
|
|
26758
|
-
files: installed.files.map(({ path:
|
|
27299
|
+
files: installed.files.map(({ path: path21, bytes: bytes2, sha256 }) => ({ path: path21, bytes: bytes2, sha256 }))
|
|
26759
27300
|
});
|
|
26760
27301
|
signal?.throwIfAborted();
|
|
26761
|
-
await
|
|
27302
|
+
await rename8(temporary, versionRoot);
|
|
26762
27303
|
newFiles = payload.files.length;
|
|
26763
27304
|
}
|
|
26764
27305
|
if (newFiles === 0) await verifyInstalledRuntime(versionRoot, payload.version, runtimeCommands.get(versionRoot), { env });
|
|
@@ -26793,14 +27334,14 @@ async function installClaudeUserLocked({
|
|
|
26793
27334
|
requestedVersion: payload.version,
|
|
26794
27335
|
recordedRuntimeRetained: runtimeCommands.has(versionRoot) && runtimeCommands.get(versionRoot) !== nodeCommand
|
|
26795
27336
|
};
|
|
26796
|
-
} catch (
|
|
27337
|
+
} catch (error5) {
|
|
26797
27338
|
if (registrationStarted) fail7("registration_unconfirmed_keep_existing", {
|
|
26798
|
-
...claudeErrorDetails(
|
|
27339
|
+
...claudeErrorDetails(error5),
|
|
26799
27340
|
phase: "registration_observation",
|
|
26800
27341
|
localRegistrationState: "unknown",
|
|
26801
27342
|
action: "inspect_same_registration_no_second_add"
|
|
26802
27343
|
});
|
|
26803
|
-
if (
|
|
27344
|
+
if (error5 instanceof CreationClientError) throw error5;
|
|
26804
27345
|
fail7(signal?.aborted ? "interrupted_keep_existing" : "failed_keep_existing");
|
|
26805
27346
|
} finally {
|
|
26806
27347
|
await rm5(temporary, { recursive: true, force: true });
|
|
@@ -26810,7 +27351,7 @@ async function installClaudeUserLocked({
|
|
|
26810
27351
|
|
|
26811
27352
|
// lib/cli.mjs
|
|
26812
27353
|
import { fileURLToPath } from "node:url";
|
|
26813
|
-
import
|
|
27354
|
+
import path20 from "node:path";
|
|
26814
27355
|
var args = process.argv.slice(2);
|
|
26815
27356
|
var command = args.shift();
|
|
26816
27357
|
var value = (key) => {
|
|
@@ -26818,15 +27359,31 @@ var value = (key) => {
|
|
|
26818
27359
|
return i < 0 ? void 0 : args[i + 1];
|
|
26819
27360
|
};
|
|
26820
27361
|
var log = (value2) => process.stdout.write(JSON.stringify(value2) + "\n");
|
|
26821
|
-
var configFile = () => value("--config") ?
|
|
27362
|
+
var configFile = () => value("--config") ? path20.resolve(value("--config")) : profileCredentialsPath(value("--profile") ?? "default");
|
|
26822
27363
|
async function probe(credentials) {
|
|
26823
|
-
const client = await connectPlatform(credentials, { host: resolveHostIdentity({ host: value("--host") }) });
|
|
27364
|
+
const client = await connectPlatform(credentials, { host: resolveHostIdentity({ host: value("--host") }), clientConfigFile: configFile() });
|
|
26824
27365
|
try {
|
|
26825
|
-
return (await client.listTools()).tools.length;
|
|
27366
|
+
return { tools: (await client.listTools()).tools.length, accountIdentity: connectionAccountIdentity(client) };
|
|
26826
27367
|
} finally {
|
|
26827
27368
|
await client.close();
|
|
26828
27369
|
}
|
|
26829
27370
|
}
|
|
27371
|
+
async function rememberAuthorization(credentials, file, accountIdentity) {
|
|
27372
|
+
if (!accountIdentity) return;
|
|
27373
|
+
try {
|
|
27374
|
+
await recordLocalAuthorization({
|
|
27375
|
+
identity: accountIdentity,
|
|
27376
|
+
client: "creation",
|
|
27377
|
+
configFile: file,
|
|
27378
|
+
endpoint: credentials.endpoint,
|
|
27379
|
+
token: credentials.token,
|
|
27380
|
+
profile: value("--profile") ?? "default"
|
|
27381
|
+
});
|
|
27382
|
+
return { status: "recorded" };
|
|
27383
|
+
} catch (error5) {
|
|
27384
|
+
return { status: "unavailable", reasonCode: error5 instanceof CreationClientError ? error5.message : "accounts.storage_unavailable" };
|
|
27385
|
+
}
|
|
27386
|
+
}
|
|
26830
27387
|
async function tokenInput() {
|
|
26831
27388
|
if (args.includes("--token-stdin")) {
|
|
26832
27389
|
let text = "";
|
|
@@ -26888,8 +27445,9 @@ async function setup({ silent = false } = {}) {
|
|
|
26888
27445
|
);
|
|
26889
27446
|
if (existing && !args.includes("--replace")) {
|
|
26890
27447
|
try {
|
|
26891
|
-
const tools2 = await probe(existing);
|
|
26892
|
-
const
|
|
27448
|
+
const { tools: tools2, accountIdentity: accountIdentity2 } = await probe(existing);
|
|
27449
|
+
const accountDirectory2 = await rememberAuthorization(existing, file, accountIdentity2);
|
|
27450
|
+
const result2 = { connected: true, reused: true, endpoint, tools: tools2, ...accountIdentity2 ? { accountIdentity: accountIdentity2, accountDirectory: accountDirectory2 } : {} };
|
|
26893
27451
|
if (!silent) log(result2);
|
|
26894
27452
|
return result2;
|
|
26895
27453
|
} catch {
|
|
@@ -26927,9 +27485,10 @@ async function setup({ silent = false } = {}) {
|
|
|
26927
27485
|
clientName: value("--name") ?? existing?.clientName ?? (resolveHostIdentity({ host: value("--host") }).kind === "claude-code" ? "Claude Code PromptFrame" : "Codex PromptFrame"),
|
|
26928
27486
|
createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
26929
27487
|
};
|
|
26930
|
-
const tools = await probe(credentials);
|
|
27488
|
+
const { tools, accountIdentity } = await probe(credentials);
|
|
26931
27489
|
await writeCredentials(credentials, file);
|
|
26932
|
-
const
|
|
27490
|
+
const accountDirectory = await rememberAuthorization(credentials, file, accountIdentity);
|
|
27491
|
+
const result = { connected: true, reused: false, endpoint, tools, ...accountIdentity ? { accountIdentity, accountDirectory } : {} };
|
|
26933
27492
|
if (!silent) log(result);
|
|
26934
27493
|
return result;
|
|
26935
27494
|
}
|
|
@@ -26947,7 +27506,8 @@ async function bridge() {
|
|
|
26947
27506
|
contentTypes: () => contentTypes,
|
|
26948
27507
|
contentSource: () => contentSource,
|
|
26949
27508
|
enforceMinimum: false,
|
|
26950
|
-
signal: startup.signal
|
|
27509
|
+
signal: startup.signal,
|
|
27510
|
+
clientConfigFile: configFile()
|
|
26951
27511
|
});
|
|
26952
27512
|
upstream = client.getServerCapabilities() ?? {};
|
|
26953
27513
|
policy = readPlatformBridgePolicy(upstream);
|
|
@@ -26958,14 +27518,14 @@ async function bridge() {
|
|
|
26958
27518
|
resolvedVersion: value("--resolved-runtime-version"),
|
|
26959
27519
|
signal: startup.signal,
|
|
26960
27520
|
hostKind: identity.kind,
|
|
26961
|
-
cacheRoot:
|
|
27521
|
+
cacheRoot: path20.join(path20.dirname(configFile()), "runtime-cache")
|
|
26962
27522
|
});
|
|
26963
27523
|
startup.signal.throwIfAborted();
|
|
26964
|
-
} catch (
|
|
27524
|
+
} catch (error5) {
|
|
26965
27525
|
await client?.close().catch(() => {
|
|
26966
27526
|
});
|
|
26967
27527
|
if (startup.signal.aborted) throw new CreationClientError("creation.runtime_selection_interrupted");
|
|
26968
|
-
throw
|
|
27528
|
+
throw error5;
|
|
26969
27529
|
} finally {
|
|
26970
27530
|
process.removeListener("SIGINT", abort);
|
|
26971
27531
|
process.removeListener("SIGTERM", abort);
|
|
@@ -26976,6 +27536,7 @@ async function bridge() {
|
|
|
26976
27536
|
process.exitCode = result.code;
|
|
26977
27537
|
return;
|
|
26978
27538
|
}
|
|
27539
|
+
await rememberAuthorization(credentials, configFile(), connectionAccountIdentity(client));
|
|
26979
27540
|
const hostSession = identity.kind === "claude-code" ? await createClaudeHostSession({ configFile: configFile() }) : void 0;
|
|
26980
27541
|
const server = new Server(
|
|
26981
27542
|
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
@@ -26985,14 +27546,20 @@ async function bridge() {
|
|
|
26985
27546
|
...upstream.prompts ? { prompts: { listChanged: true } } : {},
|
|
26986
27547
|
experimental: {
|
|
26987
27548
|
...policy ? { "promptframe.creation": policy } : {},
|
|
26988
|
-
"promptframe.runtime": { version: selection.version, locked: selection.locked, status: selection.status }
|
|
27549
|
+
"promptframe.runtime": { version: selection.version, locked: selection.locked, status: selection.status },
|
|
27550
|
+
"promptframe.localAccounts": { contractVersion: "promptframe-local-account-directory/v1", selectionScope: "host-session" }
|
|
26989
27551
|
}
|
|
26990
27552
|
} }
|
|
26991
|
-
), host =
|
|
27553
|
+
), host = createAccountAwareBridge(client, {
|
|
26992
27554
|
credentials,
|
|
27555
|
+
configFile: configFile(),
|
|
26993
27556
|
host: identity,
|
|
26994
27557
|
hostSession,
|
|
26995
|
-
|
|
27558
|
+
connectionOptions: { contentTypes: () => contentTypes, contentSource: () => contentSource },
|
|
27559
|
+
createLocalUploads: ({ identity: account, agent, configFile: file }) => createLocalUploadManager({
|
|
27560
|
+
stateRoot: path20.join(path20.dirname(file), "local-upload-state", "accounts", localAccountKey(account), localAgentDigest(agent).slice(7))
|
|
27561
|
+
}),
|
|
27562
|
+
localUploads: createLocalUploadManager({ stateRoot: path20.join(path20.dirname(configFile()), "local-upload-state") }),
|
|
26996
27563
|
onCatalogChange: () => server.sendToolListChanged(),
|
|
26997
27564
|
onKnowledgeChange: (kind) => kind === "resources" ? server.sendResourceListChanged() : server.sendPromptListChanged()
|
|
26998
27565
|
});
|
|
@@ -27007,11 +27574,11 @@ async function bridge() {
|
|
|
27007
27574
|
const knowledgeHandler = (schema, method) => server.setRequestHandler(schema, async (request) => {
|
|
27008
27575
|
try {
|
|
27009
27576
|
return await host[method](request.params ?? {});
|
|
27010
|
-
} catch (
|
|
27011
|
-
const remote =
|
|
27012
|
-
const code =
|
|
27013
|
-
const knownRemote = typeof remote === "string" && code === remote && typeof
|
|
27014
|
-
throw new McpError(knownRemote ?
|
|
27577
|
+
} catch (error5) {
|
|
27578
|
+
const remote = error5?.data?.errorCode;
|
|
27579
|
+
const code = error5 instanceof CreationClientError ? error5.message : typeof remote === "string" && /^(?:creation|creative_skill)\.[a-z0-9_.:-]{1,160}$/.test(remote) ? remote : "creation.connection_unresolved";
|
|
27580
|
+
const knownRemote = typeof remote === "string" && code === remote && typeof error5.code === "number" && Object.values(ErrorCode).includes(error5.code);
|
|
27581
|
+
throw new McpError(knownRemote ? error5.code : error5 instanceof CreationClientError ? ErrorCode.InvalidParams : ErrorCode.InternalError, code, { errorCode: code });
|
|
27015
27582
|
}
|
|
27016
27583
|
});
|
|
27017
27584
|
if (upstream.resources) {
|
|
@@ -27023,9 +27590,9 @@ async function bridge() {
|
|
|
27023
27590
|
knowledgeHandler(ListPromptsRequestSchema, "listPrompts");
|
|
27024
27591
|
knowledgeHandler(GetPromptRequestSchema, "getPrompt");
|
|
27025
27592
|
}
|
|
27026
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
27593
|
+
server.setRequestHandler(ListToolsRequestSchema, async (request) => {
|
|
27027
27594
|
try {
|
|
27028
|
-
return await host.listTools();
|
|
27595
|
+
return await host.listTools(request.params ?? {});
|
|
27029
27596
|
} catch {
|
|
27030
27597
|
throw new Error("creation.connection_unresolved");
|
|
27031
27598
|
}
|
|
@@ -27033,7 +27600,7 @@ async function bridge() {
|
|
|
27033
27600
|
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
27034
27601
|
try {
|
|
27035
27602
|
return await host.call(request.params, { signal: extra.signal });
|
|
27036
|
-
} catch (
|
|
27603
|
+
} catch (error5) {
|
|
27037
27604
|
return {
|
|
27038
27605
|
isError: true,
|
|
27039
27606
|
content: [
|
|
@@ -27041,9 +27608,9 @@ async function bridge() {
|
|
|
27041
27608
|
type: "text",
|
|
27042
27609
|
text: JSON.stringify({
|
|
27043
27610
|
success: false,
|
|
27044
|
-
errorCode:
|
|
27045
|
-
...
|
|
27046
|
-
action:
|
|
27611
|
+
errorCode: error5 instanceof CreationClientError ? error5.message : "creation.connection_unresolved",
|
|
27612
|
+
...error5 instanceof CreationClientError && error5.message === "creation.host_session_changed" ? { effectStatus: "unknown", automaticReplayAllowed: false } : {},
|
|
27613
|
+
action: error5 instanceof CreationClientError ? error5.message === "creation.host_session_changed" ? "read_original_task_without_replaying_business" : error5.message.startsWith("creation.host_") ? "use_supported_host_with_session_identity" : error5.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"
|
|
27047
27614
|
})
|
|
27048
27615
|
}
|
|
27049
27616
|
]
|
|
@@ -27115,29 +27682,41 @@ try {
|
|
|
27115
27682
|
} else if (command === "bridge") await bridge();
|
|
27116
27683
|
else if (command === "claude-host-hook") await runClaudeHostHook({ configFile: configFile() });
|
|
27117
27684
|
else if (command === "--version") process.stdout.write(CLIENT_VERSION + "\n");
|
|
27118
|
-
else if (command === "
|
|
27685
|
+
else if (command === "accounts") {
|
|
27686
|
+
if (args[0] === "refresh") {
|
|
27687
|
+
const file = configFile(), saved = await readCredentials(file);
|
|
27688
|
+
if (!saved) throw new CreationClientError("setup.required");
|
|
27689
|
+
const { accountIdentity } = await probe(saved);
|
|
27690
|
+
if (!accountIdentity) throw new CreationClientError("accounts.identity_unavailable");
|
|
27691
|
+
const accountDirectory = await rememberAuthorization(saved, file, accountIdentity);
|
|
27692
|
+
if (accountDirectory.status !== "recorded") throw new CreationClientError(accountDirectory.reasonCode);
|
|
27693
|
+
log({ accountIdentity, accountDirectory });
|
|
27694
|
+
} else if (args[0] === void 0 || args[0] === "list") log(await listLocalAccounts());
|
|
27695
|
+
else throw new CreationClientError("command.unknown");
|
|
27696
|
+
} else if (command === "status") {
|
|
27119
27697
|
const saved = await readCredentials(configFile());
|
|
27120
27698
|
if (!saved) throw new CreationClientError("setup.required");
|
|
27699
|
+
const observation = await probe(saved);
|
|
27121
27700
|
log({
|
|
27122
27701
|
connected: true,
|
|
27123
27702
|
endpoint: saved.endpoint,
|
|
27124
|
-
|
|
27703
|
+
...observation
|
|
27125
27704
|
});
|
|
27126
27705
|
} else if (command === "help" || command === "--help" || !command) {
|
|
27127
27706
|
process.stdout.write(
|
|
27128
|
-
"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"
|
|
27707
|
+
"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 accounts list\npromptframe-creation accounts refresh [--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"
|
|
27129
27708
|
);
|
|
27130
27709
|
} else throw new CreationClientError("command.unknown");
|
|
27131
|
-
} catch (
|
|
27710
|
+
} catch (error5) {
|
|
27132
27711
|
process.stderr.write(
|
|
27133
27712
|
JSON.stringify({
|
|
27134
|
-
...installationErrorDetails(
|
|
27135
|
-
...claudeInstallationDetails(
|
|
27136
|
-
...claudeErrorDetails(
|
|
27137
|
-
...fallbackErrorDetails(
|
|
27138
|
-
...bridgeErrorDetails(
|
|
27139
|
-
...runtimeErrorDetails(
|
|
27140
|
-
error:
|
|
27713
|
+
...installationErrorDetails(error5),
|
|
27714
|
+
...claudeInstallationDetails(error5),
|
|
27715
|
+
...claudeErrorDetails(error5),
|
|
27716
|
+
...fallbackErrorDetails(error5),
|
|
27717
|
+
...bridgeErrorDetails(error5),
|
|
27718
|
+
...runtimeErrorDetails(error5),
|
|
27719
|
+
error: error5 instanceof CreationClientError ? error5.message : "creation.connection_failed"
|
|
27141
27720
|
}) + "\n"
|
|
27142
27721
|
);
|
|
27143
27722
|
process.exitCode = 1;
|