holycodex 0.10.4 → 0.10.7-dev.30815334981.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cli.js +829 -183
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -614,7 +614,6 @@ var string$1 = (params) => {
|
|
|
614
614
|
};
|
|
615
615
|
var integer = /^-?\d+$/;
|
|
616
616
|
var number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
617
|
-
var boolean$1 = /^(?:true|false)$/i;
|
|
618
617
|
var lowercase = /^[^A-Z]*$/;
|
|
619
618
|
var uppercase = /^[^a-z]*$/;
|
|
620
619
|
//#endregion
|
|
@@ -1409,24 +1408,6 @@ var $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def
|
|
|
1409
1408
|
$ZodCheckNumberFormat.init(inst, def);
|
|
1410
1409
|
$ZodNumber.init(inst, def);
|
|
1411
1410
|
});
|
|
1412
|
-
var $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
|
|
1413
|
-
$ZodType.init(inst, def);
|
|
1414
|
-
inst._zod.pattern = boolean$1;
|
|
1415
|
-
inst._zod.parse = (payload, _ctx) => {
|
|
1416
|
-
if (def.coerce) try {
|
|
1417
|
-
payload.value = Boolean(payload.value);
|
|
1418
|
-
} catch (_) {}
|
|
1419
|
-
const input = payload.value;
|
|
1420
|
-
if (typeof input === "boolean") return payload;
|
|
1421
|
-
payload.issues.push({
|
|
1422
|
-
expected: "boolean",
|
|
1423
|
-
code: "invalid_type",
|
|
1424
|
-
input,
|
|
1425
|
-
inst
|
|
1426
|
-
});
|
|
1427
|
-
return payload;
|
|
1428
|
-
};
|
|
1429
|
-
});
|
|
1430
1411
|
var $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
|
|
1431
1412
|
$ZodType.init(inst, def);
|
|
1432
1413
|
inst._zod.parse = (payload) => payload;
|
|
@@ -2642,13 +2623,6 @@ function _int(Class, params) {
|
|
|
2642
2623
|
});
|
|
2643
2624
|
}
|
|
2644
2625
|
// @__NO_SIDE_EFFECTS__
|
|
2645
|
-
function _boolean(Class, params) {
|
|
2646
|
-
return new Class({
|
|
2647
|
-
type: "boolean",
|
|
2648
|
-
...normalizeParams(params)
|
|
2649
|
-
});
|
|
2650
|
-
}
|
|
2651
|
-
// @__NO_SIDE_EFFECTS__
|
|
2652
2626
|
function _unknown(Class) {
|
|
2653
2627
|
return new Class({ type: "unknown" });
|
|
2654
2628
|
}
|
|
@@ -3194,9 +3168,6 @@ var numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
3194
3168
|
else if (typeof maximum === "number") json.maximum = maximum;
|
|
3195
3169
|
if (typeof multipleOf === "number") json.multipleOf = multipleOf;
|
|
3196
3170
|
};
|
|
3197
|
-
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
3198
|
-
json.type = "boolean";
|
|
3199
|
-
};
|
|
3200
3171
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
3201
3172
|
json.not = {};
|
|
3202
3173
|
};
|
|
@@ -3880,14 +3851,6 @@ var ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def)
|
|
|
3880
3851
|
function int(params) {
|
|
3881
3852
|
return /* @__PURE__ */ _int(ZodNumberFormat, params);
|
|
3882
3853
|
}
|
|
3883
|
-
var ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
|
|
3884
|
-
$ZodBoolean.init(inst, def);
|
|
3885
|
-
ZodType.init(inst, def);
|
|
3886
|
-
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
|
|
3887
|
-
});
|
|
3888
|
-
function boolean(params) {
|
|
3889
|
-
return /* @__PURE__ */ _boolean(ZodBoolean, params);
|
|
3890
|
-
}
|
|
3891
3854
|
var ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
|
|
3892
3855
|
$ZodUnknown.init(inst, def);
|
|
3893
3856
|
ZodType.init(inst, def);
|
|
@@ -4289,7 +4252,7 @@ function superRefine(fn, params) {
|
|
|
4289
4252
|
}
|
|
4290
4253
|
//#endregion
|
|
4291
4254
|
//#region packages/cli/src/catalog.ts
|
|
4292
|
-
var VERSION = "0.10.
|
|
4255
|
+
var VERSION = "0.10.7-dev.30815334981.1";
|
|
4293
4256
|
var SKILLS = [
|
|
4294
4257
|
"ast-grep",
|
|
4295
4258
|
"caveman",
|
|
@@ -4325,7 +4288,8 @@ var ReasoningEffortSchema = _enum([
|
|
|
4325
4288
|
"low",
|
|
4326
4289
|
"medium",
|
|
4327
4290
|
"high",
|
|
4328
|
-
"xhigh"
|
|
4291
|
+
"xhigh",
|
|
4292
|
+
"max"
|
|
4329
4293
|
]);
|
|
4330
4294
|
var FastModeSchema = _enum([
|
|
4331
4295
|
"standard",
|
|
@@ -4370,21 +4334,21 @@ var DEFAULT_PLAN = "plus";
|
|
|
4370
4334
|
var MODEL_ROUTING_PLANS = ModelRoutingPlansSchema.parse({
|
|
4371
4335
|
go: {
|
|
4372
4336
|
root: {
|
|
4373
|
-
model: "gpt-5.6-
|
|
4374
|
-
reasoningEffort: "
|
|
4337
|
+
model: "gpt-5.6-luna",
|
|
4338
|
+
reasoningEffort: "xhigh"
|
|
4375
4339
|
},
|
|
4376
4340
|
agents: {
|
|
4377
4341
|
explorer: {
|
|
4378
|
-
model: "gpt-5.6-
|
|
4379
|
-
reasoningEffort: "
|
|
4342
|
+
model: "gpt-5.6-luna",
|
|
4343
|
+
reasoningEffort: "high"
|
|
4380
4344
|
},
|
|
4381
4345
|
librarian: {
|
|
4382
|
-
model: "gpt-5.6-
|
|
4383
|
-
reasoningEffort: "
|
|
4346
|
+
model: "gpt-5.6-luna",
|
|
4347
|
+
reasoningEffort: "high"
|
|
4384
4348
|
},
|
|
4385
4349
|
worker: {
|
|
4386
|
-
model: "gpt-5.6-
|
|
4387
|
-
reasoningEffort: "
|
|
4350
|
+
model: "gpt-5.6-luna",
|
|
4351
|
+
reasoningEffort: "xhigh"
|
|
4388
4352
|
}
|
|
4389
4353
|
},
|
|
4390
4354
|
usage: {
|
|
@@ -4456,7 +4420,7 @@ var MODEL_ROUTING_PLANS = ModelRoutingPlansSchema.parse({
|
|
|
4456
4420
|
},
|
|
4457
4421
|
worker: {
|
|
4458
4422
|
model: "gpt-5.6-luna",
|
|
4459
|
-
reasoningEffort: "
|
|
4423
|
+
reasoningEffort: "max"
|
|
4460
4424
|
}
|
|
4461
4425
|
},
|
|
4462
4426
|
usage: {
|
|
@@ -4480,7 +4444,7 @@ var MODEL_ROUTING_PLANS = ModelRoutingPlansSchema.parse({
|
|
|
4480
4444
|
},
|
|
4481
4445
|
worker: {
|
|
4482
4446
|
model: "gpt-5.6-luna",
|
|
4483
|
-
reasoningEffort: "
|
|
4447
|
+
reasoningEffort: "max"
|
|
4484
4448
|
}
|
|
4485
4449
|
},
|
|
4486
4450
|
usage: {
|
|
@@ -4496,15 +4460,15 @@ var MODEL_ROUTING_PLANS = ModelRoutingPlansSchema.parse({
|
|
|
4496
4460
|
agents: {
|
|
4497
4461
|
explorer: {
|
|
4498
4462
|
model: "gpt-5.6-luna",
|
|
4499
|
-
reasoningEffort: "
|
|
4463
|
+
reasoningEffort: "max"
|
|
4500
4464
|
},
|
|
4501
4465
|
librarian: {
|
|
4502
4466
|
model: "gpt-5.6-luna",
|
|
4503
|
-
reasoningEffort: "
|
|
4467
|
+
reasoningEffort: "max"
|
|
4504
4468
|
},
|
|
4505
4469
|
worker: {
|
|
4506
4470
|
model: "gpt-5.6-luna",
|
|
4507
|
-
reasoningEffort: "
|
|
4471
|
+
reasoningEffort: "max"
|
|
4508
4472
|
}
|
|
4509
4473
|
},
|
|
4510
4474
|
usage: {
|
|
@@ -4520,14 +4484,23 @@ var LEGACY_MANAGED_AGENT_MODEL_HISTORY = {
|
|
|
4520
4484
|
explorer: [{
|
|
4521
4485
|
model: "gpt-5.6-luna",
|
|
4522
4486
|
reasoningEffort: "low"
|
|
4487
|
+
}, {
|
|
4488
|
+
model: "gpt-5.6-terra",
|
|
4489
|
+
reasoningEffort: "low"
|
|
4523
4490
|
}],
|
|
4524
4491
|
librarian: [{
|
|
4525
4492
|
model: "gpt-5.6-luna",
|
|
4526
4493
|
reasoningEffort: "low"
|
|
4494
|
+
}, {
|
|
4495
|
+
model: "gpt-5.6-terra",
|
|
4496
|
+
reasoningEffort: "low"
|
|
4527
4497
|
}],
|
|
4528
4498
|
worker: [{
|
|
4529
4499
|
model: "gpt-5.6-terra",
|
|
4530
4500
|
reasoningEffort: "low"
|
|
4501
|
+
}, {
|
|
4502
|
+
model: "gpt-5.6-terra",
|
|
4503
|
+
reasoningEffort: "medium"
|
|
4531
4504
|
}]
|
|
4532
4505
|
},
|
|
4533
4506
|
"plus-low": {
|
|
@@ -4690,6 +4663,9 @@ var LEGACY_MANAGED_ROOT_MODEL_HISTORY = {
|
|
|
4690
4663
|
go: [{
|
|
4691
4664
|
model: "gpt-5.6-sol",
|
|
4692
4665
|
reasoningEffort: "low"
|
|
4666
|
+
}, {
|
|
4667
|
+
model: "gpt-5.6-terra",
|
|
4668
|
+
reasoningEffort: "medium"
|
|
4693
4669
|
}],
|
|
4694
4670
|
"plus-low": [],
|
|
4695
4671
|
plus: [],
|
|
@@ -4856,6 +4832,7 @@ async function runManagedProcess(input, runtime = defaultManagedProcessRuntime)
|
|
|
4856
4832
|
detached: input.platform !== "win32"
|
|
4857
4833
|
});
|
|
4858
4834
|
} catch (error) {
|
|
4835
|
+
const code = errorCode(error);
|
|
4859
4836
|
resolve({
|
|
4860
4837
|
exitCode: null,
|
|
4861
4838
|
stdout: "",
|
|
@@ -4863,7 +4840,8 @@ async function runManagedProcess(input, runtime = defaultManagedProcessRuntime)
|
|
|
4863
4840
|
timedOut: false,
|
|
4864
4841
|
matched: false,
|
|
4865
4842
|
outputTruncated: false,
|
|
4866
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4843
|
+
error: error instanceof Error ? error.message : String(error),
|
|
4844
|
+
...code === void 0 ? {} : { errorCode: code }
|
|
4867
4845
|
});
|
|
4868
4846
|
return;
|
|
4869
4847
|
}
|
|
@@ -4896,7 +4874,7 @@ async function runManagedProcess(input, runtime = defaultManagedProcessRuntime)
|
|
|
4896
4874
|
let matched = false;
|
|
4897
4875
|
let settled = false;
|
|
4898
4876
|
let forceKillTimeout;
|
|
4899
|
-
const finish = (exitCode, error) => {
|
|
4877
|
+
const finish = (exitCode, error, errorCode) => {
|
|
4900
4878
|
if (settled) return;
|
|
4901
4879
|
settled = true;
|
|
4902
4880
|
clearTimeout(timeout);
|
|
@@ -4908,7 +4886,8 @@ async function runManagedProcess(input, runtime = defaultManagedProcessRuntime)
|
|
|
4908
4886
|
timedOut,
|
|
4909
4887
|
matched,
|
|
4910
4888
|
outputTruncated: stdout.truncated || stderr.truncated,
|
|
4911
|
-
...error === void 0 ? {} : { error }
|
|
4889
|
+
...error === void 0 ? {} : { error },
|
|
4890
|
+
...errorCode === void 0 ? {} : { errorCode }
|
|
4912
4891
|
});
|
|
4913
4892
|
};
|
|
4914
4893
|
const terminate = () => {
|
|
@@ -4934,7 +4913,7 @@ async function runManagedProcess(input, runtime = defaultManagedProcessRuntime)
|
|
|
4934
4913
|
stderr = appendOutput(stderr, chunk.toString(), input.maxOutputChars);
|
|
4935
4914
|
inspectMatch();
|
|
4936
4915
|
});
|
|
4937
|
-
child.once("error", (error) => finish(null, error.message));
|
|
4916
|
+
child.once("error", (error) => finish(null, error.message, errorCode(error)));
|
|
4938
4917
|
child.once("close", (code) => finish(code));
|
|
4939
4918
|
const timeout = setTimeout(() => {
|
|
4940
4919
|
timedOut = true;
|
|
@@ -4985,6 +4964,11 @@ function appendOutput(state, chunk, limit) {
|
|
|
4985
4964
|
function outputText(state) {
|
|
4986
4965
|
return state.truncated ? `${state.head}${TRUNCATED_MARKER}${state.tail}` : state.head;
|
|
4987
4966
|
}
|
|
4967
|
+
function errorCode(value) {
|
|
4968
|
+
if (typeof value !== "object" || value === null || !("code" in value)) return void 0;
|
|
4969
|
+
const code = value.code;
|
|
4970
|
+
return typeof code === "string" ? code : void 0;
|
|
4971
|
+
}
|
|
4988
4972
|
//#endregion
|
|
4989
4973
|
//#region packages/cli/src/toml.ts
|
|
4990
4974
|
var TOML_TABLE = /^[ \t]*(?:\[[^\]\r\n]+\]|\[\[[^\]\r\n]+\]\])[ \t]*(?:#.*)?$/m;
|
|
@@ -4992,7 +4976,7 @@ var TOML_TABLE = /^[ \t]*(?:\[[^\]\r\n]+\]|\[\[[^\]\r\n]+\]\])[ \t]*(?:#.*)?$/m;
|
|
|
4992
4976
|
function rootTomlString(input, key) {
|
|
4993
4977
|
const table = TOML_TABLE.exec(input);
|
|
4994
4978
|
const root = table === null ? input : input.slice(0, table.index);
|
|
4995
|
-
const match = new RegExp(String.raw`^[ \t]*${escapeRegExp(key)}[ \t]*=[ \t]*(?:"((?:\\.|[^"\\\r\n])*)"|'([^'\r\n]*)')[ \t]*(?:#.*)?$`, "m").exec(root);
|
|
4979
|
+
const match = new RegExp(String.raw`^[ \t]*${escapeRegExp$1(key)}[ \t]*=[ \t]*(?:"((?:\\.|[^"\\\r\n])*)"|'([^'\r\n]*)')[ \t]*(?:#.*)?$`, "m").exec(root);
|
|
4996
4980
|
if (match === null) return void 0;
|
|
4997
4981
|
if (match[2] !== void 0) return match[2];
|
|
4998
4982
|
try {
|
|
@@ -5012,7 +4996,7 @@ function rootTomlStringArraySource(input, key) {
|
|
|
5012
4996
|
function parseRootTomlStringArray(input, key) {
|
|
5013
4997
|
const table = TOML_TABLE.exec(input);
|
|
5014
4998
|
const root = table === null ? input : input.slice(0, table.index);
|
|
5015
|
-
const assignment = new RegExp(String.raw`^[ \t]*${escapeRegExp(key)}[ \t]*=`, "m").exec(root);
|
|
4999
|
+
const assignment = new RegExp(String.raw`^[ \t]*${escapeRegExp$1(key)}[ \t]*=`, "m").exec(root);
|
|
5016
5000
|
if (assignment === null) return void 0;
|
|
5017
5001
|
const start = root.indexOf("[", assignment.index + assignment[0].length);
|
|
5018
5002
|
if (start < 0) return void 0;
|
|
@@ -5066,6 +5050,128 @@ function parseRootTomlStringArray(input, key) {
|
|
|
5066
5050
|
}
|
|
5067
5051
|
}
|
|
5068
5052
|
}
|
|
5053
|
+
function escapeRegExp$1(value) {
|
|
5054
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5055
|
+
}
|
|
5056
|
+
//#endregion
|
|
5057
|
+
//#region packages/cli/src/permission-selection.ts
|
|
5058
|
+
var PERMISSION_KEYS = [
|
|
5059
|
+
"default_permissions",
|
|
5060
|
+
"approval_policy",
|
|
5061
|
+
"approvals_reviewer",
|
|
5062
|
+
"sandbox_mode"
|
|
5063
|
+
];
|
|
5064
|
+
var AUTONOMY_PREFIX = "# holycodex autonomy: ";
|
|
5065
|
+
var ORIGINAL_PERMISSION_PREFIX = "# holycodex original permissions: ";
|
|
5066
|
+
/** Normalizes legacy string callers while preserving an omitted request. */
|
|
5067
|
+
function normalizeRequestedAutonomy(value) {
|
|
5068
|
+
if (value === void 0) return { requested: false };
|
|
5069
|
+
if (typeof value === "string") return {
|
|
5070
|
+
requested: true,
|
|
5071
|
+
mode: value
|
|
5072
|
+
};
|
|
5073
|
+
return value;
|
|
5074
|
+
}
|
|
5075
|
+
/** Reads the raw root permission selection without filling missing values. */
|
|
5076
|
+
function readRawPermissionSelection(input) {
|
|
5077
|
+
const defaultPermissions = rootTomlString(input, "default_permissions");
|
|
5078
|
+
const approvalPolicy = rootTomlString(input, "approval_policy");
|
|
5079
|
+
const approvalsReviewer = rootTomlString(input, "approvals_reviewer");
|
|
5080
|
+
const sandboxMode = rootTomlString(input, "sandbox_mode");
|
|
5081
|
+
return {
|
|
5082
|
+
...defaultPermissions === void 0 ? {} : { defaultPermissions },
|
|
5083
|
+
...approvalPolicy === void 0 ? {} : { approvalPolicy },
|
|
5084
|
+
...approvalsReviewer === void 0 ? {} : { approvalsReviewer },
|
|
5085
|
+
...sandboxMode === void 0 ? {} : { sandboxMode }
|
|
5086
|
+
};
|
|
5087
|
+
}
|
|
5088
|
+
/** Returns root assignment lines for permission keys in source order. */
|
|
5089
|
+
function readPermissionLines(input) {
|
|
5090
|
+
const firstTable = input.search(/^\s*\[/m);
|
|
5091
|
+
const root = firstTable < 0 ? input : input.slice(0, firstTable);
|
|
5092
|
+
const keys = new Set(PERMISSION_KEYS);
|
|
5093
|
+
return root.split(/\r?\n/).filter((line) => {
|
|
5094
|
+
const key = /^\s*([A-Za-z0-9_-]+)\s*=/.exec(line)?.[1];
|
|
5095
|
+
return key !== void 0 && keys.has(key);
|
|
5096
|
+
});
|
|
5097
|
+
}
|
|
5098
|
+
/** Removes all root permission assignment lines while preserving other text. */
|
|
5099
|
+
function removePermissionLines(input) {
|
|
5100
|
+
const firstTable = input.search(/^\s*\[/m);
|
|
5101
|
+
const root = firstTable < 0 ? input : input.slice(0, firstTable);
|
|
5102
|
+
const tables = firstTable < 0 ? "" : input.slice(firstTable);
|
|
5103
|
+
const keys = PERMISSION_KEYS.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
5104
|
+
return `${root.split(/\r?\n/).filter((line) => !new RegExp(`^\\s*(?:${keys.join("|")})\\s*=`).test(line)).join("\n").trim()}${tables ? `\n${tables.trimStart()}` : ""}`.trim();
|
|
5105
|
+
}
|
|
5106
|
+
/** Returns the exact tuple represented by an explicit autonomy mode. */
|
|
5107
|
+
function permissionSelectionForMode(mode) {
|
|
5108
|
+
if (mode === "default") return {
|
|
5109
|
+
approvalPolicy: "on-request",
|
|
5110
|
+
approvalsReviewer: "auto_review",
|
|
5111
|
+
sandboxMode: "workspace-write"
|
|
5112
|
+
};
|
|
5113
|
+
if (mode === "autonomous") return {
|
|
5114
|
+
approvalPolicy: "never",
|
|
5115
|
+
sandboxMode: "workspace-write"
|
|
5116
|
+
};
|
|
5117
|
+
return {
|
|
5118
|
+
approvalPolicy: "never",
|
|
5119
|
+
sandboxMode: "danger-full-access"
|
|
5120
|
+
};
|
|
5121
|
+
}
|
|
5122
|
+
/** Identifies generated tuples from current and historical installers. */
|
|
5123
|
+
function permissionSelectionMatchesMode(selection, mode) {
|
|
5124
|
+
if (permissionSelectionsEqual(selection, permissionSelectionForMode(mode))) return true;
|
|
5125
|
+
return mode === "default" && permissionSelectionsEqual(selection, {
|
|
5126
|
+
approvalPolicy: "on-request",
|
|
5127
|
+
sandboxMode: "workspace-write"
|
|
5128
|
+
});
|
|
5129
|
+
}
|
|
5130
|
+
/** Compares all raw permission fields, including intentional omissions. */
|
|
5131
|
+
function permissionSelectionsEqual(left, right) {
|
|
5132
|
+
return PERMISSION_KEYS.every((key) => {
|
|
5133
|
+
const field = permissionField(key);
|
|
5134
|
+
return left[field] === right[field];
|
|
5135
|
+
});
|
|
5136
|
+
}
|
|
5137
|
+
/** Identifies a historical generated tuple, if one is exact. */
|
|
5138
|
+
function inferAutonomyMode(selection) {
|
|
5139
|
+
for (const mode of [
|
|
5140
|
+
"default",
|
|
5141
|
+
"autonomous",
|
|
5142
|
+
"dangerous"
|
|
5143
|
+
]) if (permissionSelectionMatchesMode(selection, mode)) return mode;
|
|
5144
|
+
return "custom";
|
|
5145
|
+
}
|
|
5146
|
+
/** Reads deterministic autonomy metadata from a managed block. */
|
|
5147
|
+
function readAutonomyMetadata(input) {
|
|
5148
|
+
const value = new RegExp(`^${escapeRegExp(AUTONOMY_PREFIX)}(.+)$`, "m").exec(input)?.[1]?.trim();
|
|
5149
|
+
if (value === "default" || value === "autonomous" || value === "dangerous" || value === "custom") return value;
|
|
5150
|
+
}
|
|
5151
|
+
/** Encodes durable original root permission assignment provenance. */
|
|
5152
|
+
function originalPermissionMetadata(lines) {
|
|
5153
|
+
return `${ORIGINAL_PERMISSION_PREFIX}${lines.length === 0 ? "-" : Buffer.from(lines.join("\n"), "utf8").toString("base64")}\n`;
|
|
5154
|
+
}
|
|
5155
|
+
/** Reads durable original root permission assignment provenance. */
|
|
5156
|
+
function readOriginalPermissionMetadata(input) {
|
|
5157
|
+
const encoded = new RegExp(`^${escapeRegExp(ORIGINAL_PERMISSION_PREFIX)}([A-Za-z0-9+/=_-]+)$`, "m").exec(input)?.[1];
|
|
5158
|
+
if (encoded === void 0) return void 0;
|
|
5159
|
+
if (encoded === "-") return [];
|
|
5160
|
+
return Buffer.from(encoded, "base64").toString("utf8").split(/\r?\n/).filter(Boolean);
|
|
5161
|
+
}
|
|
5162
|
+
/** Returns a generated tuple for an explicit request or preserves a live omitted selection. */
|
|
5163
|
+
function selectPermissionSelection(live, request) {
|
|
5164
|
+
if (request.requested) return permissionSelectionForMode(request.mode);
|
|
5165
|
+
if (Object.keys(live).length > 0) return live;
|
|
5166
|
+
return permissionSelectionForMode("default");
|
|
5167
|
+
}
|
|
5168
|
+
var AUTONOMY_METADATA_PREFIX = AUTONOMY_PREFIX;
|
|
5169
|
+
function permissionField(key) {
|
|
5170
|
+
if (key === "default_permissions") return "defaultPermissions";
|
|
5171
|
+
if (key === "approval_policy") return "approvalPolicy";
|
|
5172
|
+
if (key === "approvals_reviewer") return "approvalsReviewer";
|
|
5173
|
+
return "sandboxMode";
|
|
5174
|
+
}
|
|
5069
5175
|
function escapeRegExp(value) {
|
|
5070
5176
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5071
5177
|
}
|
|
@@ -5078,7 +5184,6 @@ var ORIGINAL_TABLE_KEY = "# holycodex original table key: ";
|
|
|
5078
5184
|
var PLAN_PREFIX = "# holycodex plan: ";
|
|
5079
5185
|
var FAST_MODE_PREFIX = "# holycodex fast: ";
|
|
5080
5186
|
var MAX_SUBAGENTS_PREFIX = "# holycodex max-subagents: ";
|
|
5081
|
-
var MANAGED_PERMISSION_PROFILE = "holycodex-config";
|
|
5082
5187
|
var OLD_NAMESPACES = [
|
|
5083
5188
|
"marketplaces.sisyphuslabs",
|
|
5084
5189
|
"plugins.\"omo@sisyphuslabs\"",
|
|
@@ -5098,13 +5203,35 @@ var OLD_NAMESPACES = [
|
|
|
5098
5203
|
"hooks.state.\"omo@lazycodex",
|
|
5099
5204
|
"hooks.state.\"omo@code-yeongyu-codex-plugins"
|
|
5100
5205
|
];
|
|
5101
|
-
|
|
5102
|
-
|
|
5206
|
+
function readOriginalRootMetadata(input) {
|
|
5207
|
+
const encoded = input.match(/^# holycodex original root: ([A-Za-z0-9+/=]+)$/m)?.[1];
|
|
5208
|
+
return encoded === void 0 ? void 0 : Buffer.from(encoded, "base64").toString("utf8");
|
|
5209
|
+
}
|
|
5210
|
+
function readLegacyGeneratedRoot(input) {
|
|
5211
|
+
const body = input.match(/^# >>> holycodex managed >>>\r?\n([\s\S]*?)^# <<< holycodex managed <<</m)?.[1];
|
|
5212
|
+
if (body === void 0 || readPermissionLines(body).length === 0) return void 0;
|
|
5213
|
+
return inferAutonomyMode(readRawPermissionSelection(body)) === "custom" ? void 0 : body;
|
|
5214
|
+
}
|
|
5215
|
+
/** Removes managed configuration and restores durable original values. */
|
|
5216
|
+
function removeManaged(input, preserveGeneratedPermissions = false) {
|
|
5103
5217
|
const escapedStart = START.replaceAll(">", "\\>");
|
|
5104
5218
|
const escapedEnd = END.replaceAll("<", "\\<");
|
|
5105
5219
|
return input.replace(new RegExp(`${escapedStart}([\\s\\S]*?)${escapedEnd}(?:\\r?\\n){0,2}`, "g"), (_match, body) => {
|
|
5106
|
-
const
|
|
5107
|
-
|
|
5220
|
+
const original = readOriginalRootMetadata(body);
|
|
5221
|
+
const originalPermissions = readOriginalPermissionMetadata(body);
|
|
5222
|
+
const currentPermissions = readPermissionLines(body);
|
|
5223
|
+
const currentSelection = readRawPermissionSelection(body);
|
|
5224
|
+
const metadata = readAutonomyMetadata(body);
|
|
5225
|
+
const expected = metadata === void 0 || metadata === "custom" ? originalPermissions === void 0 ? void 0 : readRawPermissionSelection(originalPermissions.join("\n")) : permissionSelectionForMode(metadata);
|
|
5226
|
+
const generated = metadata !== void 0 && metadata !== "custom" ? permissionSelectionMatchesMode(currentSelection, metadata) : expected !== void 0 ? permissionSelectionsEqual(currentSelection, expected) : metadata === void 0 && [
|
|
5227
|
+
"default",
|
|
5228
|
+
"autonomous",
|
|
5229
|
+
"dangerous"
|
|
5230
|
+
].some((mode) => permissionSelectionMatchesMode(currentSelection, mode));
|
|
5231
|
+
const preserveCurrent = preserveGeneratedPermissions || !generated;
|
|
5232
|
+
if (original !== void 0) return `${preserveCurrent ? `${removePermissionLines(original)}${currentPermissions.length === 0 ? "" : `\n${currentPermissions.join("\n")}`}`.trim() : `${removePermissionLines(original)}${(originalPermissions ?? readPermissionLines(original)).length === 0 ? "" : `\n${(originalPermissions ?? readPermissionLines(original)).join("\n")}`}`.trim()}\n`;
|
|
5233
|
+
if (!preserveCurrent && originalPermissions !== void 0) return `${originalPermissions.join("\n")}\n`;
|
|
5234
|
+
if (preserveCurrent && currentPermissions.length > 0) return `${currentPermissions.join("\n")}\n`;
|
|
5108
5235
|
const tableKeys = [...body.matchAll(/^# holycodex original table key: ([A-Za-z0-9+/=]+)$/gm)].flatMap((match) => match[1] === void 0 ? [] : [match[1]]);
|
|
5109
5236
|
return tableKeys.length === 0 ? "" : `${tableKeys.map((key) => Buffer.from(key, "base64").toString("utf8")).join("\n")}\n`;
|
|
5110
5237
|
}).trim();
|
|
@@ -5228,10 +5355,25 @@ function mergedStatusLine(original) {
|
|
|
5228
5355
|
}
|
|
5229
5356
|
/** Installs config. */
|
|
5230
5357
|
function installConfig(input, mode, _platform, plan = DEFAULT_PLAN, maxSubagents, fastMode = "standard") {
|
|
5231
|
-
const
|
|
5358
|
+
const request = normalizeRequestedAutonomy(mode);
|
|
5359
|
+
const priorAutonomy = readAutonomyMetadata(input);
|
|
5360
|
+
const previousOriginalRoot = readOriginalRootMetadata(input);
|
|
5361
|
+
const legacyGeneratedRoot = readLegacyGeneratedRoot(input);
|
|
5362
|
+
const originalPermissionLines = readOriginalPermissionMetadata(input);
|
|
5363
|
+
const base = preserveManagedRootPreferences(input, removeLegacyOmo(removeManaged(input, !request.requested)));
|
|
5232
5364
|
const firstTable = base.search(/^\s*\[/m);
|
|
5233
5365
|
const root = firstTable < 0 ? base : base.slice(0, firstTable);
|
|
5234
5366
|
const tables = firstTable < 0 ? "" : base.slice(firstTable);
|
|
5367
|
+
const permissions = selectPermissionSelection(readRawPermissionSelection(root), request);
|
|
5368
|
+
const effectiveAutonomy = request.requested ? inferAutonomyMode(permissions) : priorAutonomy ?? inferAutonomyMode(permissions);
|
|
5369
|
+
const rootPermissionLines = [
|
|
5370
|
+
permissions.approvalPolicy === void 0 ? void 0 : `approval_policy = ${JSON.stringify(permissions.approvalPolicy)}`,
|
|
5371
|
+
permissions.approvalsReviewer === void 0 ? void 0 : `approvals_reviewer = ${JSON.stringify(permissions.approvalsReviewer)}`,
|
|
5372
|
+
permissions.sandboxMode === void 0 ? void 0 : `sandbox_mode = ${JSON.stringify(permissions.sandboxMode)}`
|
|
5373
|
+
].filter((line) => line !== void 0);
|
|
5374
|
+
const hadManagedAutonomy = readAutonomyMetadata(input) !== void 0;
|
|
5375
|
+
const hadOriginalRoot = /^# holycodex original root:/m.test(input);
|
|
5376
|
+
const permissionLines = originalPermissionLines ?? (legacyGeneratedRoot !== void 0 && previousOriginalRoot === void 0 ? [] : previousOriginalRoot === void 0 ? hadManagedAutonomy && !hadOriginalRoot ? [] : readPermissionLines(root) : readPermissionLines(previousOriginalRoot));
|
|
5235
5377
|
const controlled = [
|
|
5236
5378
|
"approval_policy",
|
|
5237
5379
|
"approvals_reviewer",
|
|
@@ -5239,7 +5381,8 @@ function installConfig(input, mode, _platform, plan = DEFAULT_PLAN, maxSubagents
|
|
|
5239
5381
|
"max_concurrent_threads_per_session",
|
|
5240
5382
|
"status_line",
|
|
5241
5383
|
"model_verbosity",
|
|
5242
|
-
"service_tier"
|
|
5384
|
+
"service_tier",
|
|
5385
|
+
...request.requested ? ["default_permissions"] : []
|
|
5243
5386
|
].map((key) => rootValue(root, key));
|
|
5244
5387
|
const preservedRoot = [
|
|
5245
5388
|
"approval_policy",
|
|
@@ -5248,7 +5391,8 @@ function installConfig(input, mode, _platform, plan = DEFAULT_PLAN, maxSubagents
|
|
|
5248
5391
|
"max_concurrent_threads_per_session",
|
|
5249
5392
|
"status_line",
|
|
5250
5393
|
"model_verbosity",
|
|
5251
|
-
"service_tier"
|
|
5394
|
+
"service_tier",
|
|
5395
|
+
...request.requested ? ["default_permissions"] : []
|
|
5252
5396
|
].reduce(removeRootKey, root).trim();
|
|
5253
5397
|
const originalControlled = controlled.filter((value) => value !== void 0).sort((left, right) => root.indexOf(left) - root.indexOf(right)).join("\n");
|
|
5254
5398
|
const hasModel = /^\s*model\s*=/m.test(preservedRoot);
|
|
@@ -5257,14 +5401,12 @@ function installConfig(input, mode, _platform, plan = DEFAULT_PLAN, maxSubagents
|
|
|
5257
5401
|
const effectiveMaxSubagents = maxSubagents ?? MODEL_ROUTING_PLANS[plan].usage.maxSubagents;
|
|
5258
5402
|
const model = hasModel ? "" : `model = "${rootRoute.model}"\n`;
|
|
5259
5403
|
const effort = hasEffort ? "" : `model_reasoning_effort = "${rootRoute.reasoningEffort}"\n`;
|
|
5260
|
-
const
|
|
5261
|
-
const
|
|
5262
|
-
const
|
|
5263
|
-
const
|
|
5264
|
-
const rootBlock = `${START}\n${PLAN_PREFIX}${plan}\n${FAST_MODE_PREFIX}${fastMode}\n${
|
|
5404
|
+
const originalSource = previousOriginalRoot === void 0 ? priorAutonomy === void 0 && legacyGeneratedRoot === void 0 ? originalControlled : "" : removePermissionLines(previousOriginalRoot);
|
|
5405
|
+
const original = originalSource ? `${ORIGINAL_ROOT}${Buffer.from(originalSource).toString("base64")}\n` : "";
|
|
5406
|
+
const maxSubagentsMetadata = maxSubagents === void 0 ? "" : `${MAX_SUBAGENTS_PREFIX}${maxSubagents}\n`;
|
|
5407
|
+
const rootServiceTier = fastMode === "fast-all" ? "fast" : "default";
|
|
5408
|
+
const rootBlock = `${START}\n${PLAN_PREFIX}${plan}\n${FAST_MODE_PREFIX}${fastMode}\n${AUTONOMY_METADATA_PREFIX}${effectiveAutonomy}\n${maxSubagentsMetadata}${original}${originalPermissionMetadata(permissionLines)}${model}${effort}model_verbosity = "low"\nservice_tier = "${rootServiceTier}"\n${rootPermissionLines.join("\n")}\nstatus_line = ${mergedStatusLine(rootValue(root, "status_line"))}\n${END}`;
|
|
5265
5409
|
let configured = `${preservedRoot ? `${preservedRoot}\n` : ""}${rootBlock}${tables ? `\n\n${tables}` : ""}`;
|
|
5266
|
-
configured = injectTableKeys(configured, `permissions.${MANAGED_PERMISSION_PROFILE}`, [["description", "\"HolyCodex config.toml permissions.\""], ["extends", "\":workspace\""]]);
|
|
5267
|
-
configured = injectTableKeys(configured, `permissions.${MANAGED_PERMISSION_PROFILE}.network`, [["enabled", "true"]]);
|
|
5268
5410
|
configured = injectTableKeys(configured, "features", [
|
|
5269
5411
|
["default_mode_request_user_input", "true"],
|
|
5270
5412
|
["multi_agent", "true"],
|
|
@@ -5272,8 +5414,8 @@ function installConfig(input, mode, _platform, plan = DEFAULT_PLAN, maxSubagents
|
|
|
5272
5414
|
]);
|
|
5273
5415
|
const usage = MODEL_ROUTING_PLANS[plan].usage;
|
|
5274
5416
|
configured = injectTableKeys(configured, "agents", [["max_threads", String(effectiveMaxSubagents + 1)], ["max_depth", String(usage.maxDepth)]]);
|
|
5275
|
-
if (
|
|
5276
|
-
configured = injectTableKeys(configured, "desktop", [["enabled-reasoning-efforts", "[\"low\", \"medium\", \"high\"]"], ["show-context-window-usage", "true"]]);
|
|
5417
|
+
if (effectiveAutonomy !== "dangerous") configured = injectTableKeys(configured, "sandbox_workspace_write", [["network_access", "true"]]);
|
|
5418
|
+
configured = injectTableKeys(configured, "desktop", [["enabled-reasoning-efforts", "[\"low\", \"medium\", \"high\", \"xhigh\", \"max\"]"], ["show-context-window-usage", "true"]]);
|
|
5277
5419
|
if (_platform === "win32") configured = injectTableKeys(configured, "windows", [["sandbox", "\"unelevated\""]]);
|
|
5278
5420
|
for (const agent of AGENTS) configured = injectTableKeys(configured, `agents.${agent}`, [["config_file", `"holycodex/agents/${agent}.toml"`]]);
|
|
5279
5421
|
const plugin = `${START}\n[plugins."holycodex@holycodex"]\nenabled = true\n${END}`;
|
|
@@ -5467,7 +5609,7 @@ async function doctor(home = process.env.CODEX_HOME ?? join(homedir(), ".codex")
|
|
|
5467
5609
|
checks.push(preset === void 0 || expectedMaxSubagents === void 0 || tableInteger(config, "agents", "max_threads") !== expectedMaxSubagents + 1 || tableInteger(config, "agents", "max_depth") !== preset.usage.maxDepth ? check("agent-usage", "error", "agent-usage-stale", "Agent concurrency configuration does not match the selected routing plan or explicit override.", "Reinstall HolyCodex.") : check("agent-usage", "ok", "agent-usage-ready", `Agent concurrency allows ${expectedMaxSubagents} direct subagent${expectedMaxSubagents === 1 ? "" : "s"}.`));
|
|
5468
5610
|
checks.push(mode === "unknown" ? check("autonomy", "error", "invalid-autonomy-config", "Approval policy, approval reviewer, sandbox, and network settings do not match a supported mode.", "Rerun install with the intended autonomy flag.") : mode === "dangerous" ? check("autonomy", "warning", "dangerous-autonomy", "Explicit dangerous autonomy is active; workspace containment is removed.") : check("autonomy", "ok", `${mode}-ready`, mode === "safe-workspace" ? "Safe workspace autonomy is active." : "Approval-free workspace autonomy is active."));
|
|
5469
5611
|
checks.push(tableBoolean(config, "features", "default_mode_request_user_input") === true ? check("user-input", "ok", "user-input-ready", "default_mode_request_user_input is enabled.") : check("user-input", "error", "user-input-disabled", "default_mode_request_user_input is not enabled.", "Rerun holycodex install."));
|
|
5470
|
-
checks.push(tableStringArray(config, "desktop", "enabled-reasoning-efforts")?.join(",") === "low,medium,high" ? check("desktop-reasoning", "ok", "desktop-reasoning-ready", "Desktop exposes low
|
|
5612
|
+
checks.push(tableStringArray(config, "desktop", "enabled-reasoning-efforts")?.join(",") === "low,medium,high,xhigh,max" ? check("desktop-reasoning", "ok", "desktop-reasoning-ready", "Desktop exposes low through max reasoning efforts.") : check("desktop-reasoning", "error", "desktop-reasoning-stale", "Desktop reasoning choices must include low through max.", "Reinstall HolyCodex."));
|
|
5471
5613
|
checks.push(tableBoolean(config, "desktop", "show-context-window-usage") === true ? check("desktop-context-usage", "ok", "desktop-context-usage-ready", "Desktop context-window usage is visible.") : check("desktop-context-usage", "error", "desktop-context-usage-hidden", "Desktop context-window usage is not enabled.", "Reinstall HolyCodex."));
|
|
5472
5614
|
checks.push(rootTomlStringArray(config, "status_line")?.includes("context-remaining") === true ? check("context-visibility", "warning", "context-visible-support-unverified", "status_line includes context-remaining. Current official Codex config documents this item, but publishes no minimum compatible Codex version.") : check("context-visibility", "error", "context-hidden", "status_line does not include context-remaining.", "Rerun holycodex install."));
|
|
5473
5615
|
const codex = await runtime.command("codex", ["--version"]);
|
|
@@ -5493,60 +5635,292 @@ async function doctor(home = process.env.CODEX_HOME ?? join(homedir(), ".codex")
|
|
|
5493
5635
|
};
|
|
5494
5636
|
}
|
|
5495
5637
|
//#endregion
|
|
5638
|
+
//#region packages/cli/src/codex-launcher.ts
|
|
5639
|
+
var CODEX_PACKAGE_SPEC = "@openai/codex@latest";
|
|
5640
|
+
/** Derives safe process facts for the default installation flow. */
|
|
5641
|
+
function defaultCodexLauncherRuntimeFacts(platform = process.platform, env = process.env) {
|
|
5642
|
+
const bun = typeof process.versions.bun === "string";
|
|
5643
|
+
const allowPackageResolution = env.HOLYCODEX_TEST_SKIP_PACKAGE_RESOLUTION !== "1";
|
|
5644
|
+
const npmExecPath = bun ? void 0 : env.npm_execpath;
|
|
5645
|
+
return {
|
|
5646
|
+
allowPackageResolution,
|
|
5647
|
+
platform,
|
|
5648
|
+
execPath: process.execPath,
|
|
5649
|
+
runtime: bun ? "bun" : "node",
|
|
5650
|
+
...npmExecPath === void 0 ? {} : { npmExecPath },
|
|
5651
|
+
availableRunners: ["npm", "pnpm"],
|
|
5652
|
+
npm: platform === "win32" ? "npm.cmd" : "npm",
|
|
5653
|
+
pnpm: platform === "win32" ? "pnpm.cmd" : "pnpm"
|
|
5654
|
+
};
|
|
5655
|
+
}
|
|
5656
|
+
/** Builds ordered Codex launcher candidates once for an installation. */
|
|
5657
|
+
function createCodexLauncherCandidates(input = {}) {
|
|
5658
|
+
const facts = input.runtimeFacts ?? {};
|
|
5659
|
+
const candidates = [];
|
|
5660
|
+
const injected = input.injected === void 0 ? [] : toArray(input.injected);
|
|
5661
|
+
for (const candidate of injected) {
|
|
5662
|
+
const launcher = normalizeLauncher(candidate, "injected");
|
|
5663
|
+
if (launcher !== void 0) candidates.push(launcher);
|
|
5664
|
+
}
|
|
5665
|
+
const pathLauncher = normalizeLauncher(facts.pathCodex ?? "codex", "path");
|
|
5666
|
+
if (pathLauncher !== void 0) candidates.push(pathLauncher);
|
|
5667
|
+
if (facts.allowPackageResolution === false) return deduplicate(candidates);
|
|
5668
|
+
if ((facts.runtime ?? (typeof process.versions.bun === "string" ? "bun" : "node")) === "bun") {
|
|
5669
|
+
const bunLauncher = normalizeLauncher({
|
|
5670
|
+
command: facts.execPath ?? process.execPath,
|
|
5671
|
+
argsPrefix: ["x", CODEX_PACKAGE_SPEC],
|
|
5672
|
+
source: "bunx"
|
|
5673
|
+
}, "bunx");
|
|
5674
|
+
if (bunLauncher !== void 0) candidates.push(bunLauncher);
|
|
5675
|
+
}
|
|
5676
|
+
const nodeRunner = facts.nodeRunner ?? activeNodeRunner(facts);
|
|
5677
|
+
if (nodeRunner !== void 0) {
|
|
5678
|
+
const launcher = normalizeLauncher(nodeRunner, nodeRunnerSource(nodeRunner));
|
|
5679
|
+
if (launcher !== void 0) candidates.push(launcher);
|
|
5680
|
+
}
|
|
5681
|
+
const availableRunners = facts.availableRunners ?? [];
|
|
5682
|
+
if (facts.npm !== false && (facts.npm !== void 0 || availableRunners.includes("npm"))) candidates.push(packageLauncher(facts.npm, facts.platform, "npm-exec"));
|
|
5683
|
+
if (facts.pnpm !== false && (facts.pnpm !== void 0 || availableRunners.includes("pnpm"))) candidates.push(packageLauncher(facts.pnpm, facts.platform, "pnpm-exec"));
|
|
5684
|
+
return deduplicate(candidates);
|
|
5685
|
+
}
|
|
5686
|
+
/** Appends command arguments to a launcher prefix without mutating either array. */
|
|
5687
|
+
function codexLauncherArgs(launcher, args) {
|
|
5688
|
+
return [...launcher.argsPrefix, ...args];
|
|
5689
|
+
}
|
|
5690
|
+
function activeNodeRunner(facts) {
|
|
5691
|
+
if (facts.npmExecPath === void 0 || facts.execPath === void 0) return void 0;
|
|
5692
|
+
const source = packageRunnerSource(facts.npmExecPath);
|
|
5693
|
+
if (source === void 0) return void 0;
|
|
5694
|
+
return {
|
|
5695
|
+
command: facts.execPath,
|
|
5696
|
+
argsPrefix: source === "npm-exec" ? [
|
|
5697
|
+
facts.npmExecPath,
|
|
5698
|
+
"exec",
|
|
5699
|
+
"--yes",
|
|
5700
|
+
"--package",
|
|
5701
|
+
CODEX_PACKAGE_SPEC,
|
|
5702
|
+
"--",
|
|
5703
|
+
"codex"
|
|
5704
|
+
] : [
|
|
5705
|
+
facts.npmExecPath,
|
|
5706
|
+
"dlx",
|
|
5707
|
+
CODEX_PACKAGE_SPEC
|
|
5708
|
+
],
|
|
5709
|
+
source
|
|
5710
|
+
};
|
|
5711
|
+
}
|
|
5712
|
+
function packageRunnerSource(path) {
|
|
5713
|
+
const basename = path.replaceAll("\\", "/").split("/").pop()?.toLowerCase() ?? "";
|
|
5714
|
+
if ([
|
|
5715
|
+
"npm",
|
|
5716
|
+
"npm.cmd",
|
|
5717
|
+
"npm-cli.js",
|
|
5718
|
+
"npm-cli.cjs"
|
|
5719
|
+
].includes(basename)) return "npm-exec";
|
|
5720
|
+
if ([
|
|
5721
|
+
"pnpm",
|
|
5722
|
+
"pnpm.cmd",
|
|
5723
|
+
"pnpm.js",
|
|
5724
|
+
"pnpm.cjs"
|
|
5725
|
+
].includes(basename)) return "pnpm-exec";
|
|
5726
|
+
}
|
|
5727
|
+
function nodeRunnerSource(value) {
|
|
5728
|
+
if (typeof value === "object" && value !== null && "source" in value) {
|
|
5729
|
+
if (value.source === "pnpm-exec") return "pnpm-exec";
|
|
5730
|
+
if (value.source === "npm-exec") return "npm-exec";
|
|
5731
|
+
}
|
|
5732
|
+
return "npm-exec";
|
|
5733
|
+
}
|
|
5734
|
+
function packageLauncher(command, platform, source) {
|
|
5735
|
+
return {
|
|
5736
|
+
command: typeof command === "string" ? command : source === "npm-exec" ? platform === "win32" ? "npm.cmd" : "npm" : platform === "win32" ? "pnpm.cmd" : "pnpm",
|
|
5737
|
+
argsPrefix: source === "npm-exec" ? [
|
|
5738
|
+
"exec",
|
|
5739
|
+
"--yes",
|
|
5740
|
+
"--package",
|
|
5741
|
+
CODEX_PACKAGE_SPEC,
|
|
5742
|
+
"--",
|
|
5743
|
+
"codex"
|
|
5744
|
+
] : ["dlx", CODEX_PACKAGE_SPEC],
|
|
5745
|
+
source
|
|
5746
|
+
};
|
|
5747
|
+
}
|
|
5748
|
+
function toArray(value) {
|
|
5749
|
+
return Array.isArray(value) ? value : [value];
|
|
5750
|
+
}
|
|
5751
|
+
function normalizeLauncher(value, source) {
|
|
5752
|
+
if (typeof value === "string") {
|
|
5753
|
+
const command = value.trim();
|
|
5754
|
+
return command === "" ? void 0 : {
|
|
5755
|
+
command,
|
|
5756
|
+
argsPrefix: [],
|
|
5757
|
+
source
|
|
5758
|
+
};
|
|
5759
|
+
}
|
|
5760
|
+
if (typeof value !== "object" || value === null || typeof value.command !== "string") return void 0;
|
|
5761
|
+
const command = value.command.trim();
|
|
5762
|
+
if (command === "" || !Array.isArray(value.argsPrefix)) return void 0;
|
|
5763
|
+
if (!value.argsPrefix.every((arg) => typeof arg === "string")) return void 0;
|
|
5764
|
+
return {
|
|
5765
|
+
command,
|
|
5766
|
+
argsPrefix: [...value.argsPrefix],
|
|
5767
|
+
source
|
|
5768
|
+
};
|
|
5769
|
+
}
|
|
5770
|
+
function deduplicate(candidates) {
|
|
5771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5772
|
+
const result = [];
|
|
5773
|
+
for (const candidate of candidates) {
|
|
5774
|
+
const key = JSON.stringify([candidate.command, candidate.argsPrefix]);
|
|
5775
|
+
if (seen.has(key)) continue;
|
|
5776
|
+
seen.add(key);
|
|
5777
|
+
result.push(candidate);
|
|
5778
|
+
}
|
|
5779
|
+
return result;
|
|
5780
|
+
}
|
|
5781
|
+
//#endregion
|
|
5496
5782
|
//#region packages/cli/src/codex-security.ts
|
|
5497
5783
|
var CODEX_SECURITY_PLUGIN = "codex-security@openai-curated";
|
|
5498
|
-
var
|
|
5784
|
+
var CODEX_SECURITY_MARKETPLACE = "openai-curated";
|
|
5785
|
+
var CODEX_PLUGIN_OPERATIONAL_TIMEOUT_MS = 15e3;
|
|
5786
|
+
var CODEX_PACKAGE_BOOTSTRAP_TIMEOUT_MS = 12e4;
|
|
5499
5787
|
var MAX_CODEX_OUTPUT_CHARS = 64 * 1024;
|
|
5500
|
-
var
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5788
|
+
var MAX_JSON_DOCUMENTS = 16;
|
|
5789
|
+
var SPAWN_UNAVAILABLE_CODES = /* @__PURE__ */ new Set([
|
|
5790
|
+
"EACCES",
|
|
5791
|
+
"ENOENT",
|
|
5792
|
+
"EPERM"
|
|
5793
|
+
]);
|
|
5794
|
+
var FATAL_AUTH_CODES = /* @__PURE__ */ new Set([
|
|
5795
|
+
"401",
|
|
5796
|
+
"UNAUTHENTICATED",
|
|
5797
|
+
"AUTHENTICATION_REQUIRED"
|
|
5798
|
+
]);
|
|
5799
|
+
var FATAL_ACCOUNT_CODES = /* @__PURE__ */ new Set(["ACCOUNT_REQUIRED", "ACCOUNT_NOT_FOUND"]);
|
|
5800
|
+
var FATAL_MARKETPLACE_CODES = /* @__PURE__ */ new Set([
|
|
5801
|
+
"502",
|
|
5802
|
+
"503",
|
|
5803
|
+
"504",
|
|
5804
|
+
"MARKETPLACE_UNAVAILABLE",
|
|
5805
|
+
"MARKETPLACE_LOAD_FAILED",
|
|
5806
|
+
"CATALOG_UNAVAILABLE"
|
|
5807
|
+
]);
|
|
5808
|
+
var FATAL_PLUGIN_CODES = /* @__PURE__ */ new Set([
|
|
5809
|
+
"404",
|
|
5810
|
+
"PLUGIN_NOT_FOUND",
|
|
5811
|
+
"PLUGIN_UNAVAILABLE"
|
|
5812
|
+
]);
|
|
5813
|
+
var FATAL_POLICY_CODES = /* @__PURE__ */ new Set([
|
|
5814
|
+
"403",
|
|
5815
|
+
"ACCOUNT_RESTRICTED",
|
|
5816
|
+
"ACCOUNT_UNAVAILABLE",
|
|
5817
|
+
"ACCOUNT_SUSPENDED",
|
|
5818
|
+
"ACCOUNT_DISABLED",
|
|
5819
|
+
"INSTALLATION_REJECTED",
|
|
5820
|
+
"PERMISSION_DENIED",
|
|
5821
|
+
"POLICY_REJECTED"
|
|
5822
|
+
]);
|
|
5510
5823
|
/** Installs or enables the official Codex Security plugin without failing HolyCodex installation. */
|
|
5511
|
-
async function installCodexSecurity(runProcess = runManagedProcess, platform = process.platform, env = process.env) {
|
|
5512
|
-
const
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
const
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5824
|
+
async function installCodexSecurity(runProcess = runManagedProcess, platform = process.platform, env = process.env, options = {}) {
|
|
5825
|
+
const runtimeFacts = options.runtimeFacts ?? (runProcess === runManagedProcess ? defaultCodexLauncherRuntimeFacts(platform) : void 0);
|
|
5826
|
+
const candidates = createCodexLauncherCandidates({
|
|
5827
|
+
...options.injected === void 0 ? {} : { injected: options.injected },
|
|
5828
|
+
...runtimeFacts === void 0 ? {} : { runtimeFacts }
|
|
5829
|
+
});
|
|
5830
|
+
const attemptedLaunchers = [];
|
|
5831
|
+
const fallbackReasons = [];
|
|
5832
|
+
for (const launcher of candidates) {
|
|
5833
|
+
attemptedLaunchers.push(launcher.source);
|
|
5834
|
+
const installedOutcome = inspectListResult(await runCodexPlugin(runProcess, launcher, [
|
|
5835
|
+
"plugin",
|
|
5836
|
+
"list",
|
|
5837
|
+
"--json"
|
|
5838
|
+
], platform, env, "list"), launcher);
|
|
5839
|
+
if (installedOutcome.kind === "fallback") {
|
|
5840
|
+
fallbackReasons.push(installedOutcome.reason);
|
|
5841
|
+
continue;
|
|
5842
|
+
}
|
|
5843
|
+
if (installedOutcome.kind === "fatal") return skipped(installedOutcome.reason, attemptedLaunchers);
|
|
5844
|
+
const installedPlugin = findPlugin(installedOutcome.catalog);
|
|
5845
|
+
if (installedPlugin?.installed === true && installedPlugin.enabled === true) return {
|
|
5846
|
+
status: "already-installed",
|
|
5847
|
+
launcherSource: launcher.source
|
|
5848
|
+
};
|
|
5849
|
+
const wasDisabled = installedPlugin?.installed === true;
|
|
5850
|
+
if (!wasDisabled) {
|
|
5851
|
+
const catalogOutcome = inspectListResult(await runCodexPlugin(runProcess, launcher, [
|
|
5852
|
+
"plugin",
|
|
5853
|
+
"list",
|
|
5854
|
+
"--available",
|
|
5855
|
+
"--json"
|
|
5856
|
+
], platform, env, "list"), launcher);
|
|
5857
|
+
if (catalogOutcome.kind === "fallback") {
|
|
5858
|
+
fallbackReasons.push(catalogOutcome.reason);
|
|
5859
|
+
continue;
|
|
5860
|
+
}
|
|
5861
|
+
if (catalogOutcome.kind === "fatal") return skipped(catalogOutcome.reason, attemptedLaunchers);
|
|
5862
|
+
if (findPlugin(catalogOutcome.catalog) === void 0) {
|
|
5863
|
+
const marketplaceOutcome = inspectMarketplaceResult(await runCodexPlugin(runProcess, launcher, [
|
|
5864
|
+
"plugin",
|
|
5865
|
+
"marketplace",
|
|
5866
|
+
"list",
|
|
5867
|
+
"--json"
|
|
5868
|
+
], platform, env, "list"), launcher);
|
|
5869
|
+
if (marketplaceOutcome.kind === "fallback") {
|
|
5870
|
+
fallbackReasons.push(marketplaceOutcome.reason);
|
|
5871
|
+
continue;
|
|
5872
|
+
}
|
|
5873
|
+
if (marketplaceOutcome.kind === "fatal") return skipped(marketplaceOutcome.reason, attemptedLaunchers);
|
|
5874
|
+
fallbackReasons.push(marketplaceOutcome.marketplaces.includes(CODEX_SECURITY_MARKETPLACE) ? "plugin-not-offered" : "marketplace-unavailable");
|
|
5875
|
+
continue;
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
const addOutcome = inspectAddResult(await runCodexPlugin(runProcess, launcher, [
|
|
5879
|
+
"plugin",
|
|
5880
|
+
"add",
|
|
5881
|
+
CODEX_SECURITY_PLUGIN,
|
|
5882
|
+
"--json"
|
|
5883
|
+
], platform, env, "add"), launcher);
|
|
5884
|
+
if (addOutcome.kind === "fallback") {
|
|
5885
|
+
fallbackReasons.push(addOutcome.reason);
|
|
5886
|
+
continue;
|
|
5887
|
+
}
|
|
5888
|
+
if (addOutcome.kind === "fatal") return skipped(addOutcome.reason, attemptedLaunchers);
|
|
5889
|
+
const verification = inspectListResult(await runCodexPlugin(runProcess, launcher, [
|
|
5890
|
+
"plugin",
|
|
5891
|
+
"list",
|
|
5892
|
+
"--json"
|
|
5893
|
+
], platform, env, "list"), launcher);
|
|
5894
|
+
if (verification.kind === "fallback") {
|
|
5895
|
+
fallbackReasons.push(verification.reason);
|
|
5896
|
+
continue;
|
|
5897
|
+
}
|
|
5898
|
+
if (verification.kind === "fatal") return skipped(verification.reason, attemptedLaunchers);
|
|
5899
|
+
const verifiedPlugin = findPlugin(verification.catalog);
|
|
5900
|
+
if (verifiedPlugin?.installed !== true || verifiedPlugin.enabled !== true) {
|
|
5901
|
+
fallbackReasons.push("verification-failed");
|
|
5902
|
+
continue;
|
|
5903
|
+
}
|
|
5904
|
+
return {
|
|
5905
|
+
status: wasDisabled ? "enabled" : "installed",
|
|
5906
|
+
launcherSource: launcher.source
|
|
5907
|
+
};
|
|
5908
|
+
}
|
|
5909
|
+
return skipped(finalFallbackReason(fallbackReasons), attemptedLaunchers);
|
|
5910
|
+
}
|
|
5911
|
+
async function runCodexPlugin(runProcess, launcher, args, platform, env, operation) {
|
|
5539
5912
|
try {
|
|
5540
5913
|
return await runProcess({
|
|
5541
|
-
command:
|
|
5542
|
-
args,
|
|
5914
|
+
command: launcher.command,
|
|
5915
|
+
args: codexLauncherArgs(launcher, args),
|
|
5543
5916
|
platform,
|
|
5544
|
-
timeoutMs:
|
|
5917
|
+
timeoutMs: timeoutFor(launcher, operation),
|
|
5545
5918
|
maxOutputChars: MAX_CODEX_OUTPUT_CHARS,
|
|
5546
5919
|
env
|
|
5547
5920
|
});
|
|
5548
5921
|
} catch (error) {
|
|
5549
|
-
|
|
5922
|
+
const code = thrownErrorCode(error);
|
|
5923
|
+
if (!isUnavailableThrownError(error) && !(isPackageLauncher(launcher) && isBootstrapThrownError(error))) throw error;
|
|
5550
5924
|
return {
|
|
5551
5925
|
exitCode: null,
|
|
5552
5926
|
stdout: "",
|
|
@@ -5554,53 +5928,291 @@ async function runCodexPlugin(runProcess, args, platform, env) {
|
|
|
5554
5928
|
timedOut: false,
|
|
5555
5929
|
matched: false,
|
|
5556
5930
|
outputTruncated: false,
|
|
5557
|
-
error: "Codex
|
|
5931
|
+
error: "Codex launcher could not be started.",
|
|
5932
|
+
...code === void 0 ? {} : { errorCode: code }
|
|
5558
5933
|
};
|
|
5559
5934
|
}
|
|
5560
5935
|
}
|
|
5561
|
-
function
|
|
5562
|
-
if (result.timedOut) return
|
|
5563
|
-
|
|
5936
|
+
function inspectListResult(result, launcher) {
|
|
5937
|
+
if (result.timedOut) return {
|
|
5938
|
+
kind: "fallback",
|
|
5939
|
+
reason: "timeout"
|
|
5940
|
+
};
|
|
5941
|
+
const failure = classifyFailure(result, launcher);
|
|
5942
|
+
if (failure !== void 0) return failure;
|
|
5943
|
+
const catalog = parsePluginCatalog(result.stdout);
|
|
5944
|
+
if (catalog === void 0) return {
|
|
5945
|
+
kind: "fallback",
|
|
5946
|
+
reason: "invalid-response"
|
|
5947
|
+
};
|
|
5948
|
+
return {
|
|
5949
|
+
kind: "selected",
|
|
5950
|
+
catalog
|
|
5951
|
+
};
|
|
5952
|
+
}
|
|
5953
|
+
function inspectAddResult(result, launcher) {
|
|
5954
|
+
if (result.timedOut) return {
|
|
5955
|
+
kind: "fallback",
|
|
5956
|
+
reason: "timeout"
|
|
5957
|
+
};
|
|
5958
|
+
const failure = classifyFailure(result, launcher);
|
|
5959
|
+
if (failure !== void 0) return failure;
|
|
5960
|
+
return { kind: "added" };
|
|
5961
|
+
}
|
|
5962
|
+
function inspectMarketplaceResult(result, launcher) {
|
|
5963
|
+
if (result.timedOut) return {
|
|
5964
|
+
kind: "fallback",
|
|
5965
|
+
reason: "timeout"
|
|
5966
|
+
};
|
|
5967
|
+
const failure = classifyFailure(result, launcher);
|
|
5968
|
+
if (failure !== void 0) return failure;
|
|
5969
|
+
const marketplaces = parseMarketplaceNames(result.stdout);
|
|
5970
|
+
return marketplaces === void 0 ? {
|
|
5971
|
+
kind: "fallback",
|
|
5972
|
+
reason: "invalid-response"
|
|
5973
|
+
} : {
|
|
5974
|
+
kind: "selected",
|
|
5975
|
+
marketplaces
|
|
5976
|
+
};
|
|
5977
|
+
}
|
|
5978
|
+
function findPlugin(catalog) {
|
|
5979
|
+
return catalog.plugins.find(({ id }) => id === CODEX_SECURITY_PLUGIN);
|
|
5980
|
+
}
|
|
5981
|
+
function classifyFailure(result, launcher) {
|
|
5982
|
+
if (result.error !== void 0) {
|
|
5983
|
+
if (isUnavailableProcessError(result)) return {
|
|
5984
|
+
kind: "fallback",
|
|
5985
|
+
reason: "codex-unavailable"
|
|
5986
|
+
};
|
|
5987
|
+
return {
|
|
5988
|
+
kind: "fallback",
|
|
5989
|
+
reason: isPackageLauncher(launcher) ? "download-failed" : "invalid-response"
|
|
5990
|
+
};
|
|
5991
|
+
}
|
|
5564
5992
|
if (result.exitCode === 0) return void 0;
|
|
5565
|
-
const
|
|
5566
|
-
if (
|
|
5567
|
-
|
|
5993
|
+
const failureReason = classifyFailureReason(structuredErrorCodeFromOutput(result.stderr) ?? structuredErrorCodeFromOutput(result.stdout), sanitizeDiagnostic(result.stderr));
|
|
5994
|
+
if (failureReason === "unauthenticated" || failureReason === "installation-rejected") return {
|
|
5995
|
+
kind: "fatal",
|
|
5996
|
+
reason: failureReason
|
|
5997
|
+
};
|
|
5998
|
+
return {
|
|
5999
|
+
kind: "fallback",
|
|
6000
|
+
reason: failureReason
|
|
6001
|
+
};
|
|
5568
6002
|
}
|
|
5569
|
-
function
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
"
|
|
5574
|
-
"
|
|
5575
|
-
"
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
"
|
|
5583
|
-
|
|
5584
|
-
|
|
6003
|
+
function classifyFailureReason(code, diagnostic) {
|
|
6004
|
+
if (code !== void 0) {
|
|
6005
|
+
if (FATAL_AUTH_CODES.has(code) || FATAL_ACCOUNT_CODES.has(code)) return "unauthenticated";
|
|
6006
|
+
if (FATAL_MARKETPLACE_CODES.has(code)) return "marketplace-unavailable";
|
|
6007
|
+
if (FATAL_PLUGIN_CODES.has(code)) return "plugin-unavailable";
|
|
6008
|
+
if (FATAL_POLICY_CODES.has(code)) return "installation-rejected";
|
|
6009
|
+
if (SPAWN_UNAVAILABLE_CODES.has(code)) return "codex-unavailable";
|
|
6010
|
+
if ([
|
|
6011
|
+
"ETIMEDOUT",
|
|
6012
|
+
"ECONNRESET",
|
|
6013
|
+
"ECONNREFUSED",
|
|
6014
|
+
"EAI_AGAIN",
|
|
6015
|
+
"ENETUNREACH"
|
|
6016
|
+
].includes(code)) return "download-failed";
|
|
6017
|
+
}
|
|
6018
|
+
const lower = diagnostic.toLowerCase();
|
|
6019
|
+
if (/unknown (?:command|subcommand)|unrecognized (?:command|subcommand)|invalid subcommand/.test(lower)) return "unsupported";
|
|
6020
|
+
if (/not supported on (?:this )?platform|unsupported (?:platform|architecture)|no matching (?:binary|package)|platform package|not compatible/.test(lower)) return "unsupported";
|
|
6021
|
+
if (/unauthenticated|authentication required|not logged in|account (?:required|not found)/.test(lower)) return "unauthenticated";
|
|
6022
|
+
if (/account (?:restricted|unavailable|suspended|disabled)/.test(lower)) return "installation-rejected";
|
|
6023
|
+
if (/marketplace|catalog/.test(lower)) return "marketplace-unavailable";
|
|
6024
|
+
if (/eai_again|enetwork|network|timed out|timeout|download|fetch|resolve package/.test(lower)) return "download-failed";
|
|
6025
|
+
if (/plugin (?:not found|unavailable|missing)/.test(lower)) return "plugin-unavailable";
|
|
6026
|
+
if (/permission denied|policy|rejected|forbidden/.test(lower)) return "installation-rejected";
|
|
6027
|
+
return "invalid-response";
|
|
6028
|
+
}
|
|
6029
|
+
function finalFallbackReason(reasons) {
|
|
6030
|
+
if (reasons.length > 0 && reasons.every((reason) => reason === "plugin-not-offered")) return "all-launchers-lacked-plugin";
|
|
6031
|
+
if (reasons.includes("verification-failed")) return "verification-failed";
|
|
6032
|
+
if (reasons.includes("plugin-not-offered")) return "plugin-not-offered";
|
|
6033
|
+
if (reasons.includes("timeout")) return "timeout";
|
|
6034
|
+
if (reasons.includes("unsupported")) return "unsupported";
|
|
6035
|
+
if (reasons.includes("download-failed")) return "download-failed";
|
|
6036
|
+
if (reasons.includes("marketplace-unavailable")) return "marketplace-unavailable";
|
|
6037
|
+
if (reasons.includes("plugin-unavailable")) return "plugin-unavailable";
|
|
6038
|
+
if (reasons.includes("invalid-response")) return "invalid-response";
|
|
6039
|
+
return "codex-unavailable";
|
|
6040
|
+
}
|
|
6041
|
+
function timeoutFor(launcher, operation) {
|
|
6042
|
+
return operation === "list" && isPackageLauncher(launcher) ? CODEX_PACKAGE_BOOTSTRAP_TIMEOUT_MS : CODEX_PLUGIN_OPERATIONAL_TIMEOUT_MS;
|
|
6043
|
+
}
|
|
6044
|
+
function isPackageLauncher(launcher) {
|
|
6045
|
+
return launcher.source === "bunx" || launcher.source === "npm-exec" || launcher.source === "pnpm-exec";
|
|
6046
|
+
}
|
|
6047
|
+
/** Normalizes supported flat and marketplace-oriented Codex catalogs. */
|
|
6048
|
+
function parsePluginCatalog(input) {
|
|
6049
|
+
for (const value of parseJsonDocuments(input) ?? []) {
|
|
6050
|
+
const plugins = parseCatalogValue(value);
|
|
6051
|
+
if (plugins !== void 0) return { plugins };
|
|
6052
|
+
}
|
|
6053
|
+
}
|
|
6054
|
+
function parseMarketplaceNames(input) {
|
|
6055
|
+
for (const value of parseJsonDocuments(input) ?? []) {
|
|
6056
|
+
if (!isRecord(value) || !Array.isArray(value.marketplaces)) continue;
|
|
6057
|
+
const names = [];
|
|
6058
|
+
for (const marketplace of value.marketplaces) {
|
|
6059
|
+
if (!isRecord(marketplace)) {
|
|
6060
|
+
names.length = 0;
|
|
6061
|
+
break;
|
|
6062
|
+
}
|
|
6063
|
+
const name = stringField(marketplace, ["name"]);
|
|
6064
|
+
if (name === void 0) {
|
|
6065
|
+
names.length = 0;
|
|
6066
|
+
break;
|
|
6067
|
+
}
|
|
6068
|
+
names.push(name);
|
|
6069
|
+
}
|
|
6070
|
+
if (names.length > 0 || value.marketplaces.length === 0) return names;
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
function parseCatalogValue(value) {
|
|
6074
|
+
if (Array.isArray(value)) return parseMarketplaceEntries(value);
|
|
6075
|
+
if (!isRecord(value)) return void 0;
|
|
6076
|
+
if ("installed" in value || "available" in value) {
|
|
6077
|
+
if (!Array.isArray(value.installed) || !Array.isArray(value.available)) return void 0;
|
|
6078
|
+
const installed = parsePluginEntries(value.installed, void 0, true);
|
|
6079
|
+
const available = parsePluginEntries(value.available, void 0, false);
|
|
6080
|
+
return installed === void 0 || available === void 0 ? void 0 : [...installed, ...available];
|
|
6081
|
+
}
|
|
6082
|
+
if ("marketplaces" in value) return Array.isArray(value.marketplaces) ? parseMarketplaceEntries(value.marketplaces) : void 0;
|
|
6083
|
+
if ("plugins" in value) return parseMarketplaceEntry(value);
|
|
6084
|
+
}
|
|
6085
|
+
function parseMarketplaceEntries(entries) {
|
|
6086
|
+
const plugins = [];
|
|
6087
|
+
for (const entry of entries) {
|
|
6088
|
+
const parsed = parseMarketplaceEntry(entry);
|
|
6089
|
+
if (parsed === void 0) return void 0;
|
|
6090
|
+
plugins.push(...parsed);
|
|
6091
|
+
}
|
|
6092
|
+
return plugins;
|
|
6093
|
+
}
|
|
6094
|
+
function parseMarketplaceEntry(value) {
|
|
6095
|
+
if (!isRecord(value) || !Array.isArray(value.plugins)) return void 0;
|
|
6096
|
+
const marketplace = stringField(value, [
|
|
6097
|
+
"marketplace",
|
|
6098
|
+
"marketplaceId",
|
|
6099
|
+
"marketplaceName",
|
|
6100
|
+
"id",
|
|
6101
|
+
"name"
|
|
6102
|
+
]);
|
|
6103
|
+
if (marketplace === void 0) return void 0;
|
|
6104
|
+
return parsePluginEntries(value.plugins, marketplace);
|
|
6105
|
+
}
|
|
6106
|
+
function parsePluginEntries(entries, parentMarketplace, defaultInstalled) {
|
|
6107
|
+
const plugins = [];
|
|
6108
|
+
for (const value of entries) {
|
|
6109
|
+
const plugin = parsePluginEntry(value, parentMarketplace, defaultInstalled);
|
|
6110
|
+
if (plugin === void 0) return void 0;
|
|
6111
|
+
plugins.push(plugin);
|
|
6112
|
+
}
|
|
6113
|
+
return plugins;
|
|
6114
|
+
}
|
|
6115
|
+
function parsePluginEntry(value, parentMarketplace, defaultInstalled = false) {
|
|
6116
|
+
if (!isRecord(value)) return void 0;
|
|
6117
|
+
const rawId = stringField(value, [
|
|
6118
|
+
"pluginId",
|
|
6119
|
+
"id",
|
|
6120
|
+
"name"
|
|
6121
|
+
]);
|
|
6122
|
+
if (rawId === void 0) return void 0;
|
|
6123
|
+
const marketplace = stringField(value, [
|
|
6124
|
+
"marketplace",
|
|
6125
|
+
"marketplaceId",
|
|
6126
|
+
"marketplaceName"
|
|
6127
|
+
]) ?? parentMarketplace;
|
|
6128
|
+
const id = rawId.includes("@") ? rawId : marketplace === void 0 ? rawId : `${rawId}@${marketplace}`;
|
|
6129
|
+
const state = stringField(value, [
|
|
6130
|
+
"installationState",
|
|
6131
|
+
"installState",
|
|
6132
|
+
"status",
|
|
6133
|
+
"state"
|
|
6134
|
+
]);
|
|
6135
|
+
const policy = isRecord(value.policy) ? stringField(value.policy, ["installation"]) : void 0;
|
|
6136
|
+
return {
|
|
6137
|
+
id,
|
|
6138
|
+
installed: booleanField(value.installed) ?? installedFromState(state ?? policy) ?? defaultInstalled,
|
|
6139
|
+
enabled: booleanField(value.enabled) ?? enabledFromState(state) ?? false
|
|
6140
|
+
};
|
|
6141
|
+
}
|
|
6142
|
+
function stringField(value, keys) {
|
|
6143
|
+
for (const key of keys) {
|
|
6144
|
+
const candidate = value[key];
|
|
6145
|
+
if (typeof candidate === "string" && candidate.trim() !== "") return candidate.trim();
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
function booleanField(value) {
|
|
6149
|
+
if (typeof value === "boolean") return value;
|
|
6150
|
+
if (typeof value !== "string") return void 0;
|
|
6151
|
+
if (value.toLowerCase() === "true") return true;
|
|
6152
|
+
if (value.toLowerCase() === "false") return false;
|
|
6153
|
+
}
|
|
6154
|
+
function installedFromState(value) {
|
|
6155
|
+
if (value === void 0) return void 0;
|
|
6156
|
+
const state = value.toLowerCase().replaceAll("-", "_");
|
|
5585
6157
|
if ([
|
|
5586
|
-
"
|
|
5587
|
-
"
|
|
5588
|
-
"
|
|
5589
|
-
|
|
6158
|
+
"installed",
|
|
6159
|
+
"enabled",
|
|
6160
|
+
"disabled",
|
|
6161
|
+
"installed_by_default"
|
|
6162
|
+
].includes(state)) return true;
|
|
5590
6163
|
if ([
|
|
5591
|
-
"
|
|
5592
|
-
"
|
|
5593
|
-
"
|
|
5594
|
-
"
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
6164
|
+
"available",
|
|
6165
|
+
"not_installed",
|
|
6166
|
+
"uninstalled",
|
|
6167
|
+
"not_available"
|
|
6168
|
+
].includes(state)) return false;
|
|
6169
|
+
}
|
|
6170
|
+
function enabledFromState(value) {
|
|
6171
|
+
if (value === void 0) return void 0;
|
|
6172
|
+
const state = value.toLowerCase();
|
|
6173
|
+
if (state === "enabled") return true;
|
|
6174
|
+
if (state === "disabled") return false;
|
|
6175
|
+
}
|
|
6176
|
+
function parseJsonDocuments(input) {
|
|
6177
|
+
const wholeDocument = tryParseJson(input);
|
|
6178
|
+
if (wholeDocument !== void 0) return [wholeDocument];
|
|
6179
|
+
const lines = input.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
6180
|
+
if (lines.length === 0) return void 0;
|
|
6181
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
6182
|
+
const document = tryParseJson(lines.slice(index).join("\n"));
|
|
6183
|
+
if (document !== void 0) return [document];
|
|
6184
|
+
}
|
|
6185
|
+
const documents = [];
|
|
6186
|
+
let parsedDocument = false;
|
|
6187
|
+
for (const line of lines) {
|
|
6188
|
+
const document = tryParseJson(line);
|
|
6189
|
+
if (document === void 0) {
|
|
6190
|
+
if (parsedDocument) return void 0;
|
|
6191
|
+
continue;
|
|
6192
|
+
}
|
|
6193
|
+
documents.push(document);
|
|
6194
|
+
if (documents.length > MAX_JSON_DOCUMENTS) return void 0;
|
|
6195
|
+
parsedDocument = true;
|
|
6196
|
+
}
|
|
6197
|
+
return documents.length === 0 ? void 0 : documents;
|
|
6198
|
+
}
|
|
6199
|
+
function tryParseJson(input) {
|
|
6200
|
+
try {
|
|
6201
|
+
return JSON.parse(input);
|
|
6202
|
+
} catch {
|
|
6203
|
+
return;
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
6206
|
+
function structuredErrorCodeFromOutput(input) {
|
|
6207
|
+
for (const value of parseJsonDocuments(input) ?? []) {
|
|
6208
|
+
const code = structuredErrorCode(value);
|
|
6209
|
+
if (code !== void 0) return code;
|
|
6210
|
+
}
|
|
5598
6211
|
}
|
|
5599
6212
|
function structuredErrorCode(value) {
|
|
5600
6213
|
if (!isRecord(value)) return void 0;
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
const nestedCode = structuredErrorCode(nested);
|
|
6214
|
+
if (value.error !== void 0) {
|
|
6215
|
+
const nestedCode = structuredErrorCode(value.error);
|
|
5604
6216
|
if (nestedCode !== void 0) return nestedCode;
|
|
5605
6217
|
}
|
|
5606
6218
|
for (const key of [
|
|
@@ -5612,34 +6224,43 @@ function structuredErrorCode(value) {
|
|
|
5612
6224
|
if (typeof candidate === "string" || typeof candidate === "number") return String(candidate).trim().toUpperCase();
|
|
5613
6225
|
}
|
|
5614
6226
|
}
|
|
5615
|
-
function
|
|
5616
|
-
|
|
5617
|
-
if (value === void 0) return void 0;
|
|
5618
|
-
const parsed = schema.safeParse(value);
|
|
5619
|
-
return parsed.success ? parsed.data : void 0;
|
|
5620
|
-
}
|
|
5621
|
-
function parseUnknownJson(input) {
|
|
5622
|
-
try {
|
|
5623
|
-
return JSON.parse(input);
|
|
5624
|
-
} catch {
|
|
5625
|
-
return;
|
|
5626
|
-
}
|
|
6227
|
+
function sanitizeDiagnostic(input) {
|
|
6228
|
+
return input.replaceAll(/(?:[A-Za-z]:)?[\\/][^\s"']+/g, "<path>").replaceAll(/(token|secret|password|authorization)\s*[:=]\s*[^\s,}]+/gi, "$1=<redacted>").slice(0, 2048);
|
|
5627
6229
|
}
|
|
5628
6230
|
function isRecord(value) {
|
|
5629
6231
|
return typeof value === "object" && value !== null;
|
|
5630
6232
|
}
|
|
5631
|
-
function isUnavailableProcessError(
|
|
5632
|
-
if (
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
6233
|
+
function isUnavailableProcessError(result) {
|
|
6234
|
+
if (result.errorCode !== void 0 && SPAWN_UNAVAILABLE_CODES.has(result.errorCode.toUpperCase())) return true;
|
|
6235
|
+
const error = result.error?.toUpperCase() ?? "";
|
|
6236
|
+
return [...SPAWN_UNAVAILABLE_CODES].some((code) => new RegExp(`(?:^|\\s)${code}(?:$|\\s)`).test(error));
|
|
6237
|
+
}
|
|
6238
|
+
function isUnavailableThrownError(value) {
|
|
6239
|
+
const code = thrownErrorCode(value);
|
|
6240
|
+
return code !== void 0 && SPAWN_UNAVAILABLE_CODES.has(code.toUpperCase());
|
|
6241
|
+
}
|
|
6242
|
+
function isBootstrapThrownError(value) {
|
|
6243
|
+
const code = thrownErrorCode(value)?.toUpperCase();
|
|
6244
|
+
if (code !== void 0 && [
|
|
6245
|
+
"ETIMEDOUT",
|
|
6246
|
+
"ECONNRESET",
|
|
6247
|
+
"ECONNREFUSED",
|
|
6248
|
+
"EAI_AGAIN",
|
|
6249
|
+
"ENETUNREACH"
|
|
6250
|
+
].includes(code)) return true;
|
|
6251
|
+
if (!(value instanceof Error)) return false;
|
|
6252
|
+
return /bootstrap|network|download|fetch|timeout|timed out/i.test(value.message);
|
|
6253
|
+
}
|
|
6254
|
+
function thrownErrorCode(value) {
|
|
6255
|
+
if (typeof value !== "object" || value === null || !("code" in value)) return void 0;
|
|
6256
|
+
const code = value.code;
|
|
6257
|
+
return typeof code === "string" ? code : void 0;
|
|
6258
|
+
}
|
|
6259
|
+
function skipped(reason, attemptedLaunchers) {
|
|
5640
6260
|
return {
|
|
5641
6261
|
status: "skipped",
|
|
5642
|
-
reason
|
|
6262
|
+
reason,
|
|
6263
|
+
attemptedLaunchers: [...attemptedLaunchers]
|
|
5643
6264
|
};
|
|
5644
6265
|
}
|
|
5645
6266
|
//#endregion
|
|
@@ -5778,6 +6399,7 @@ var AGENT_MANAGED_KEYS = /* @__PURE__ */ new Set([
|
|
|
5778
6399
|
"service_tier"
|
|
5779
6400
|
]);
|
|
5780
6401
|
var AGENT_BUNDLED_KEYS = /* @__PURE__ */ new Set(["description", "developer_instructions"]);
|
|
6402
|
+
var COMPACT_WINDOWS_SHELL_POLICY = /^On native Windows, resolve `mcp__git_bash__run` before shell use;[^\r\n]*never use PowerShell\/cmd\.\r?\n\r?\n/m;
|
|
5781
6403
|
async function readAgentPreferences(root, previousPlan) {
|
|
5782
6404
|
const preferences = {};
|
|
5783
6405
|
await Promise.all(AGENTS.map(async (agent) => {
|
|
@@ -5859,7 +6481,7 @@ async function writeInstalledAgents(root, platform, plan, fastMode) {
|
|
|
5859
6481
|
await atomicWrite(path, source);
|
|
5860
6482
|
return;
|
|
5861
6483
|
}
|
|
5862
|
-
await atomicWrite(path, source.replace(`${WINDOWS_SHELL_POLICY}\r\n\r\n`, "").replace(`${WINDOWS_SHELL_POLICY}\n\n`, ""));
|
|
6484
|
+
await atomicWrite(path, source.replace(`${WINDOWS_SHELL_POLICY}\r\n\r\n`, "").replace(`${WINDOWS_SHELL_POLICY}\n\n`, "").replace(COMPACT_WINDOWS_SHELL_POLICY, ""));
|
|
5863
6485
|
}));
|
|
5864
6486
|
}
|
|
5865
6487
|
/** Provides cleanup. */
|
|
@@ -5958,8 +6580,22 @@ function renderCodexSecurity(result) {
|
|
|
5958
6580
|
if (result.codexSecurity.status === "installed") return "\n Installed official Codex Security plugin.";
|
|
5959
6581
|
if (result.codexSecurity.status === "enabled") return "\n Enabled existing official Codex Security plugin.";
|
|
5960
6582
|
if (result.codexSecurity.status === "already-installed") return "\n Official Codex Security plugin is already installed and enabled.";
|
|
5961
|
-
return `\n Skipped official Codex Security plugin: ${result.codexSecurity.reason}
|
|
5962
|
-
}
|
|
6583
|
+
return `\n Skipped official Codex Security plugin: ${CODEX_SECURITY_SKIP_MESSAGES[result.codexSecurity.reason]}`;
|
|
6584
|
+
}
|
|
6585
|
+
var CODEX_SECURITY_SKIP_MESSAGES = {
|
|
6586
|
+
"codex-unavailable": "no usable Codex launcher was found.",
|
|
6587
|
+
unauthenticated: "Codex authentication is required.",
|
|
6588
|
+
"marketplace-unavailable": "the official plugin marketplace was unavailable.",
|
|
6589
|
+
"plugin-not-offered": "the configured marketplace does not offer the official plugin.",
|
|
6590
|
+
"all-launchers-lacked-plugin": "no usable Codex launcher offered the official plugin.",
|
|
6591
|
+
"plugin-unavailable": "the plugin was unavailable from every usable Codex launcher.",
|
|
6592
|
+
"verification-failed": "Codex did not confirm the plugin was installed and enabled.",
|
|
6593
|
+
"installation-rejected": "the account or workspace policy rejected installation.",
|
|
6594
|
+
timeout: "all usable Codex launchers timed out.",
|
|
6595
|
+
"invalid-response": "Codex returned an unsupported or malformed response.",
|
|
6596
|
+
unsupported: "the available Codex launchers do not support plugin installation.",
|
|
6597
|
+
"download-failed": "the latest Codex package could not be downloaded."
|
|
6598
|
+
};
|
|
5963
6599
|
/** Renders notice. */
|
|
5964
6600
|
function renderNotice(kind, message, color) {
|
|
5965
6601
|
return `${paint(color, kind === "warning" ? RED : YELLOW, `! ${kind === "warning" ? "WARNING" : "NOTICE"}`)} ${message}\n`;
|
|
@@ -6012,8 +6648,18 @@ async function main() {
|
|
|
6012
6648
|
process$1.exitCode = 1;
|
|
6013
6649
|
return;
|
|
6014
6650
|
}
|
|
6651
|
+
const autonomy = args.includes("--dangerous-codex-autonomous") ? {
|
|
6652
|
+
requested: true,
|
|
6653
|
+
mode: "dangerous"
|
|
6654
|
+
} : args.includes("--codex-autonomous") ? {
|
|
6655
|
+
requested: true,
|
|
6656
|
+
mode: "autonomous"
|
|
6657
|
+
} : args.includes("--no-codex-autonomous") ? {
|
|
6658
|
+
requested: true,
|
|
6659
|
+
mode: "default"
|
|
6660
|
+
} : { requested: false };
|
|
6015
6661
|
const options = {
|
|
6016
|
-
autonomy
|
|
6662
|
+
autonomy,
|
|
6017
6663
|
json: args.includes("--json"),
|
|
6018
6664
|
fast: args.includes("--fast-all") ? "fast-all" : args.includes("--fast") ? "fast" : "standard",
|
|
6019
6665
|
plan,
|
|
@@ -6025,7 +6671,7 @@ async function main() {
|
|
|
6025
6671
|
if (!result.healthy) process$1.exitCode = 1;
|
|
6026
6672
|
return;
|
|
6027
6673
|
}
|
|
6028
|
-
if (
|
|
6674
|
+
if (autonomy.requested && autonomy.mode === "dangerous") process$1.stderr.write(renderNotice("warning", "Dangerous autonomy disables approvals and filesystem sandboxing.", stderrColor));
|
|
6029
6675
|
const result = command === "install" ? await install(options) : command === "cleanup" ? await cleanup(options) : void 0;
|
|
6030
6676
|
if (result === void 0) {
|
|
6031
6677
|
process$1.stderr.write(renderError(`Unknown command: ${command ?? args[0] ?? ""}`, stderrColor));
|