terminal-pilot 0.0.34 → 0.0.35
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/dist/cli.d.ts +4 -1
- package/dist/cli.js +576 -181
- package/dist/cli.js.map +4 -4
- package/dist/commands/daemon-runtime.d.ts +4 -0
- package/dist/commands/daemon-runtime.js +1944 -0
- package/dist/commands/daemon-runtime.js.map +7 -0
- package/dist/testing/cli-repl.js +587 -191
- package/dist/testing/cli-repl.js.map +4 -4
- package/dist/testing/qa-cli.js +599 -203
- package/dist/testing/qa-cli.js.map +4 -4
- package/node_modules/toolcraft-design/dist/explorer/layout.js +5 -3
- package/node_modules/toolcraft-design/dist/explorer/reducer.js +22 -6
- package/node_modules/toolcraft-design/dist/explorer/render/detail.js +19 -6
- package/node_modules/toolcraft-design/dist/explorer/render/list.js +28 -9
- package/node_modules/toolcraft-design/dist/explorer/render/pane.d.ts +5 -0
- package/node_modules/toolcraft-design/dist/explorer/render/pane.js +30 -0
- package/node_modules/toolcraft-design/dist/explorer/runtime.js +22 -4
- package/package.json +1 -1
package/dist/testing/cli-repl.js
CHANGED
|
@@ -4,6 +4,10 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
// src/testing/cli-repl.ts
|
|
8
|
+
import path26 from "node:path";
|
|
9
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
10
|
+
|
|
7
11
|
// src/ansi.ts
|
|
8
12
|
var ESC = 27;
|
|
9
13
|
var BEL = 7;
|
|
@@ -79,7 +83,7 @@ function consumeTerminatedString(input, index, allowBellTerminator) {
|
|
|
79
83
|
|
|
80
84
|
// src/cli.ts
|
|
81
85
|
import { realpath as realpath3 } from "node:fs/promises";
|
|
82
|
-
import
|
|
86
|
+
import path25 from "node:path";
|
|
83
87
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
84
88
|
|
|
85
89
|
// ../toolcraft/src/cli.ts
|
|
@@ -2818,17 +2822,17 @@ function validate(schema, value) {
|
|
|
2818
2822
|
}
|
|
2819
2823
|
return { ok: true, value: result.present ? result.value : void 0 };
|
|
2820
2824
|
}
|
|
2821
|
-
function walkSchema(schema, value,
|
|
2825
|
+
function walkSchema(schema, value, path27, state) {
|
|
2822
2826
|
if (schema.kind === "optional") {
|
|
2823
|
-
return walkOptional(schema, value,
|
|
2827
|
+
return walkOptional(schema, value, path27, state);
|
|
2824
2828
|
}
|
|
2825
2829
|
if (value === missingValue) {
|
|
2826
2830
|
addIssue(
|
|
2827
2831
|
state,
|
|
2828
|
-
|
|
2832
|
+
path27,
|
|
2829
2833
|
expectedFor(schema),
|
|
2830
2834
|
"missing",
|
|
2831
|
-
`Expected ${expectedFor(schema)} at ${formatPath(
|
|
2835
|
+
`Expected ${expectedFor(schema)} at ${formatPath(path27)}`
|
|
2832
2836
|
);
|
|
2833
2837
|
return { present: false };
|
|
2834
2838
|
}
|
|
@@ -2837,149 +2841,149 @@ function walkSchema(schema, value, path25, state) {
|
|
|
2837
2841
|
}
|
|
2838
2842
|
switch (schema.kind) {
|
|
2839
2843
|
case "string":
|
|
2840
|
-
return walkString(schema, value,
|
|
2844
|
+
return walkString(schema, value, path27, state);
|
|
2841
2845
|
case "number":
|
|
2842
|
-
return walkNumber(schema, value,
|
|
2846
|
+
return walkNumber(schema, value, path27, state);
|
|
2843
2847
|
case "boolean":
|
|
2844
|
-
return walkBoolean(value,
|
|
2848
|
+
return walkBoolean(value, path27, state);
|
|
2845
2849
|
case "enum":
|
|
2846
|
-
return walkEnum(schema, value,
|
|
2850
|
+
return walkEnum(schema, value, path27, state);
|
|
2847
2851
|
case "array":
|
|
2848
|
-
return walkArray(schema, value,
|
|
2852
|
+
return walkArray(schema, value, path27, state);
|
|
2849
2853
|
case "object":
|
|
2850
|
-
return walkObject(schema, value,
|
|
2854
|
+
return walkObject(schema, value, path27, state);
|
|
2851
2855
|
case "oneOf":
|
|
2852
|
-
return walkOneOf(schema, value,
|
|
2856
|
+
return walkOneOf(schema, value, path27, state);
|
|
2853
2857
|
case "union":
|
|
2854
|
-
return walkUnion(schema, value,
|
|
2858
|
+
return walkUnion(schema, value, path27, state);
|
|
2855
2859
|
case "record":
|
|
2856
|
-
return walkRecord(schema, value,
|
|
2860
|
+
return walkRecord(schema, value, path27, state);
|
|
2857
2861
|
case "json":
|
|
2858
|
-
return walkJson(value,
|
|
2862
|
+
return walkJson(value, path27, state);
|
|
2859
2863
|
}
|
|
2860
2864
|
}
|
|
2861
|
-
function walkOptional(schema, value,
|
|
2865
|
+
function walkOptional(schema, value, path27, state) {
|
|
2862
2866
|
if (value === missingValue || value === void 0) {
|
|
2863
2867
|
const defaultValue = getDefault(schema.inner);
|
|
2864
2868
|
if (defaultValue.present) {
|
|
2865
|
-
return walkSchema(schema.inner, cloneDefault(defaultValue.value),
|
|
2869
|
+
return walkSchema(schema.inner, cloneDefault(defaultValue.value), path27, state);
|
|
2866
2870
|
}
|
|
2867
2871
|
return { present: false };
|
|
2868
2872
|
}
|
|
2869
|
-
return walkSchema(schema.inner, value,
|
|
2873
|
+
return walkSchema(schema.inner, value, path27, state);
|
|
2870
2874
|
}
|
|
2871
|
-
function walkString(schema, value,
|
|
2875
|
+
function walkString(schema, value, path27, state) {
|
|
2872
2876
|
if (typeof value !== "string") {
|
|
2873
|
-
addExpectedIssue(state,
|
|
2877
|
+
addExpectedIssue(state, path27, "string", value);
|
|
2874
2878
|
return { present: true, value };
|
|
2875
2879
|
}
|
|
2876
2880
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
2877
2881
|
const expected = `string with length at least ${schema.minLength}`;
|
|
2878
2882
|
addIssue(
|
|
2879
2883
|
state,
|
|
2880
|
-
|
|
2884
|
+
path27,
|
|
2881
2885
|
expected,
|
|
2882
2886
|
`string with length ${value.length}`,
|
|
2883
|
-
`Expected ${expected} at ${formatPath(
|
|
2887
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
2884
2888
|
);
|
|
2885
2889
|
}
|
|
2886
2890
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
2887
2891
|
const expected = `string with length at most ${schema.maxLength}`;
|
|
2888
2892
|
addIssue(
|
|
2889
2893
|
state,
|
|
2890
|
-
|
|
2894
|
+
path27,
|
|
2891
2895
|
expected,
|
|
2892
2896
|
`string with length ${value.length}`,
|
|
2893
|
-
`Expected ${expected} at ${formatPath(
|
|
2897
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
2894
2898
|
);
|
|
2895
2899
|
}
|
|
2896
2900
|
if (schema.pattern !== void 0) {
|
|
2897
2901
|
const pattern = compilePattern(schema.pattern);
|
|
2898
2902
|
if (pattern === void 0 || !pattern.test(value)) {
|
|
2899
2903
|
const expected = `string matching pattern ${schema.pattern}`;
|
|
2900
|
-
addIssue(state,
|
|
2904
|
+
addIssue(state, path27, expected, value, `Expected ${expected} at ${formatPath(path27)}`);
|
|
2901
2905
|
}
|
|
2902
2906
|
}
|
|
2903
2907
|
return { present: true, value };
|
|
2904
2908
|
}
|
|
2905
|
-
function walkNumber(schema, value,
|
|
2909
|
+
function walkNumber(schema, value, path27, state) {
|
|
2906
2910
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
2907
|
-
addExpectedIssue(state,
|
|
2911
|
+
addExpectedIssue(state, path27, schema.jsonType === "integer" ? "integer" : "number", value);
|
|
2908
2912
|
return { present: true, value };
|
|
2909
2913
|
}
|
|
2910
2914
|
if (schema.jsonType === "integer" && !Number.isInteger(value)) {
|
|
2911
|
-
addExpectedIssue(state,
|
|
2915
|
+
addExpectedIssue(state, path27, "integer", value);
|
|
2912
2916
|
}
|
|
2913
2917
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
2914
2918
|
const expected = `number greater than or equal to ${schema.minimum}`;
|
|
2915
|
-
addIssue(state,
|
|
2919
|
+
addIssue(state, path27, expected, String(value), `Expected ${expected} at ${formatPath(path27)}`);
|
|
2916
2920
|
}
|
|
2917
2921
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
2918
2922
|
const expected = `number less than or equal to ${schema.maximum}`;
|
|
2919
|
-
addIssue(state,
|
|
2923
|
+
addIssue(state, path27, expected, String(value), `Expected ${expected} at ${formatPath(path27)}`);
|
|
2920
2924
|
}
|
|
2921
2925
|
return { present: true, value };
|
|
2922
2926
|
}
|
|
2923
|
-
function walkBoolean(value,
|
|
2927
|
+
function walkBoolean(value, path27, state) {
|
|
2924
2928
|
if (typeof value !== "boolean") {
|
|
2925
|
-
addExpectedIssue(state,
|
|
2929
|
+
addExpectedIssue(state, path27, "boolean", value);
|
|
2926
2930
|
}
|
|
2927
2931
|
return { present: true, value };
|
|
2928
2932
|
}
|
|
2929
|
-
function walkEnum(schema, value,
|
|
2933
|
+
function walkEnum(schema, value, path27, state) {
|
|
2930
2934
|
if (!schema.values.includes(value)) {
|
|
2931
2935
|
const expected = `one of ${schema.values.join(", ")}`;
|
|
2932
2936
|
addIssue(
|
|
2933
2937
|
state,
|
|
2934
|
-
|
|
2938
|
+
path27,
|
|
2935
2939
|
expected,
|
|
2936
2940
|
receivedValue(value),
|
|
2937
|
-
`Expected ${expected} at ${formatPath(
|
|
2941
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
2938
2942
|
);
|
|
2939
2943
|
}
|
|
2940
2944
|
return { present: true, value };
|
|
2941
2945
|
}
|
|
2942
|
-
function walkArray(schema, value,
|
|
2946
|
+
function walkArray(schema, value, path27, state) {
|
|
2943
2947
|
if (!Array.isArray(value)) {
|
|
2944
|
-
addExpectedIssue(state,
|
|
2948
|
+
addExpectedIssue(state, path27, "array", value);
|
|
2945
2949
|
return { present: true, value };
|
|
2946
2950
|
}
|
|
2947
2951
|
if (schema.minItems !== void 0 && value.length < schema.minItems) {
|
|
2948
2952
|
const expected = `array with at least ${schema.minItems} items`;
|
|
2949
2953
|
addIssue(
|
|
2950
2954
|
state,
|
|
2951
|
-
|
|
2955
|
+
path27,
|
|
2952
2956
|
expected,
|
|
2953
2957
|
`array with ${value.length} items`,
|
|
2954
|
-
`Expected ${expected} at ${formatPath(
|
|
2958
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
2955
2959
|
);
|
|
2956
2960
|
}
|
|
2957
2961
|
if (schema.maxItems !== void 0 && value.length > schema.maxItems) {
|
|
2958
2962
|
const expected = `array with at most ${schema.maxItems} items`;
|
|
2959
2963
|
addIssue(
|
|
2960
2964
|
state,
|
|
2961
|
-
|
|
2965
|
+
path27,
|
|
2962
2966
|
expected,
|
|
2963
2967
|
`array with ${value.length} items`,
|
|
2964
|
-
`Expected ${expected} at ${formatPath(
|
|
2968
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
2965
2969
|
);
|
|
2966
2970
|
}
|
|
2967
2971
|
const nextValue = value.map((item, index) => {
|
|
2968
|
-
const result = walkSchema(schema.item, item, [...
|
|
2972
|
+
const result = walkSchema(schema.item, item, [...path27, String(index)], state);
|
|
2969
2973
|
return result.present ? result.value : item;
|
|
2970
2974
|
});
|
|
2971
2975
|
return { present: true, value: nextValue };
|
|
2972
2976
|
}
|
|
2973
|
-
function walkObject(schema, value,
|
|
2977
|
+
function walkObject(schema, value, path27, state, injectedProperties = {}) {
|
|
2974
2978
|
if (!isPlainRecord(value)) {
|
|
2975
|
-
addExpectedIssue(state,
|
|
2979
|
+
addExpectedIssue(state, path27, "object", value);
|
|
2976
2980
|
return { present: true, value };
|
|
2977
2981
|
}
|
|
2978
2982
|
const nextValue = {};
|
|
2979
2983
|
const allowedKeys = /* @__PURE__ */ new Set([...Object.keys(schema.shape), ...Object.keys(injectedProperties)]);
|
|
2980
2984
|
for (const [key2, propertySchema] of Object.entries(schema.shape)) {
|
|
2981
2985
|
const propertyValue = Object.hasOwn(value, key2) ? value[key2] : missingValue;
|
|
2982
|
-
const result = walkSchema(propertySchema, propertyValue, [...
|
|
2986
|
+
const result = walkSchema(propertySchema, propertyValue, [...path27, key2], state);
|
|
2983
2987
|
if (result.present) {
|
|
2984
2988
|
setOwnValue(nextValue, key2, result.value);
|
|
2985
2989
|
}
|
|
@@ -2998,18 +3002,18 @@ function walkObject(schema, value, path25, state, injectedProperties = {}) {
|
|
|
2998
3002
|
if (schema.additionalProperties === true) {
|
|
2999
3003
|
setOwnValue(nextValue, key2, propertyValue);
|
|
3000
3004
|
} else {
|
|
3001
|
-
addUnexpectedPropertyIssue(state, [...
|
|
3005
|
+
addUnexpectedPropertyIssue(state, [...path27, key2]);
|
|
3002
3006
|
}
|
|
3003
3007
|
}
|
|
3004
3008
|
return { present: true, value: nextValue };
|
|
3005
3009
|
}
|
|
3006
|
-
function walkOneOf(schema, value,
|
|
3010
|
+
function walkOneOf(schema, value, path27, state) {
|
|
3007
3011
|
if (!isPlainRecord(value)) {
|
|
3008
|
-
addExpectedIssue(state,
|
|
3012
|
+
addExpectedIssue(state, path27, "object", value);
|
|
3009
3013
|
return { present: true, value };
|
|
3010
3014
|
}
|
|
3011
3015
|
const discriminatorValue = value[schema.discriminator];
|
|
3012
|
-
const discriminatorPath = [...
|
|
3016
|
+
const discriminatorPath = [...path27, schema.discriminator];
|
|
3013
3017
|
const branchValues = Object.keys(schema.branches);
|
|
3014
3018
|
const expected = `one of ${branchValues.join(", ")}`;
|
|
3015
3019
|
if (!Object.hasOwn(value, schema.discriminator)) {
|
|
@@ -3018,7 +3022,7 @@ function walkOneOf(schema, value, path25, state) {
|
|
|
3018
3022
|
discriminatorPath,
|
|
3019
3023
|
expected,
|
|
3020
3024
|
"missing",
|
|
3021
|
-
`Missing discriminator "${schema.discriminator}" at ${formatPath(
|
|
3025
|
+
`Missing discriminator "${schema.discriminator}" at ${formatPath(path27)}. Expected one of: ${branchValues.join(", ")}.`
|
|
3022
3026
|
);
|
|
3023
3027
|
return { present: true, value };
|
|
3024
3028
|
}
|
|
@@ -3032,21 +3036,21 @@ function walkOneOf(schema, value, path25, state) {
|
|
|
3032
3036
|
);
|
|
3033
3037
|
return { present: true, value };
|
|
3034
3038
|
}
|
|
3035
|
-
return walkObject(schema.branches[discriminatorValue], value,
|
|
3039
|
+
return walkObject(schema.branches[discriminatorValue], value, path27, state, {
|
|
3036
3040
|
[schema.discriminator]: discriminatorValue
|
|
3037
3041
|
});
|
|
3038
3042
|
}
|
|
3039
|
-
function walkUnion(schema, value,
|
|
3043
|
+
function walkUnion(schema, value, path27, state) {
|
|
3040
3044
|
if (isPlainRecord(value)) {
|
|
3041
3045
|
const candidateBranches = schema.branches.filter((branch) => hasRequiredKeys(branch, value));
|
|
3042
3046
|
if (candidateBranches.length === 1) {
|
|
3043
|
-
return walkObject(candidateBranches[0], value,
|
|
3047
|
+
return walkObject(candidateBranches[0], value, path27, state);
|
|
3044
3048
|
}
|
|
3045
3049
|
}
|
|
3046
3050
|
const matches = [];
|
|
3047
3051
|
for (const branch of schema.branches) {
|
|
3048
3052
|
const branchState = { issues: [] };
|
|
3049
|
-
const result = walkObject(branch, value,
|
|
3053
|
+
const result = walkObject(branch, value, path27, branchState);
|
|
3050
3054
|
if (branchState.issues.length === 0 && result.present) {
|
|
3051
3055
|
matches.push({ fingerprint: getRequiredKeyFingerprint(branch), value: result.value });
|
|
3052
3056
|
}
|
|
@@ -3058,19 +3062,19 @@ function walkUnion(schema, value, path25, state) {
|
|
|
3058
3062
|
const branchDescriptions = schema.branches.map((branch) => getRequiredKeyFingerprint(branch));
|
|
3059
3063
|
addIssueWithMessage(
|
|
3060
3064
|
state,
|
|
3061
|
-
|
|
3065
|
+
path27,
|
|
3062
3066
|
"exactly one union branch",
|
|
3063
3067
|
"0 matching branches",
|
|
3064
|
-
`No union branch matched at ${formatPath(
|
|
3068
|
+
`No union branch matched at ${formatPath(path27)}. Tried ${schema.branches.length} branches. Expected one of: ${branchDescriptions.join(" | ")}.`
|
|
3065
3069
|
);
|
|
3066
3070
|
return { present: true, value };
|
|
3067
3071
|
}
|
|
3068
3072
|
addIssueWithMessage(
|
|
3069
3073
|
state,
|
|
3070
|
-
|
|
3074
|
+
path27,
|
|
3071
3075
|
"exactly one union branch",
|
|
3072
3076
|
`${matches.length} matching branches`,
|
|
3073
|
-
`Expected exactly one union branch at ${formatPath(
|
|
3077
|
+
`Expected exactly one union branch at ${formatPath(path27)}, but matched more than one branch: ${matches.map((match) => match.fingerprint).join(" | ")}`
|
|
3074
3078
|
);
|
|
3075
3079
|
return { present: true, value };
|
|
3076
3080
|
}
|
|
@@ -3082,25 +3086,25 @@ function hasRequiredKeys(schema, value) {
|
|
|
3082
3086
|
}
|
|
3083
3087
|
return true;
|
|
3084
3088
|
}
|
|
3085
|
-
function walkRecord(schema, value,
|
|
3089
|
+
function walkRecord(schema, value, path27, state) {
|
|
3086
3090
|
if (!isPlainRecord(value)) {
|
|
3087
|
-
addExpectedIssue(state,
|
|
3091
|
+
addExpectedIssue(state, path27, "object", value);
|
|
3088
3092
|
return { present: true, value };
|
|
3089
3093
|
}
|
|
3090
3094
|
const nextValue = {};
|
|
3091
3095
|
for (const [key2, propertyValue] of Object.entries(value)) {
|
|
3092
|
-
const result = walkSchema(schema.value, propertyValue, [...
|
|
3096
|
+
const result = walkSchema(schema.value, propertyValue, [...path27, key2], state);
|
|
3093
3097
|
if (result.present) {
|
|
3094
3098
|
setOwnValue(nextValue, key2, result.value);
|
|
3095
3099
|
}
|
|
3096
3100
|
}
|
|
3097
3101
|
return { present: true, value: nextValue };
|
|
3098
3102
|
}
|
|
3099
|
-
function walkJson(value,
|
|
3103
|
+
function walkJson(value, path27, state) {
|
|
3100
3104
|
if (isJsonValue(value)) {
|
|
3101
3105
|
return { present: true, value };
|
|
3102
3106
|
}
|
|
3103
|
-
addExpectedIssue(state,
|
|
3107
|
+
addExpectedIssue(state, path27, "JSON value", value);
|
|
3104
3108
|
return { present: true, value };
|
|
3105
3109
|
}
|
|
3106
3110
|
function getDefault(schema) {
|
|
@@ -3178,45 +3182,45 @@ function expectedFor(schema) {
|
|
|
3178
3182
|
return expectedFor(schema.inner);
|
|
3179
3183
|
}
|
|
3180
3184
|
}
|
|
3181
|
-
function addExpectedIssue(state,
|
|
3185
|
+
function addExpectedIssue(state, path27, expected, value) {
|
|
3182
3186
|
addIssue(
|
|
3183
3187
|
state,
|
|
3184
|
-
|
|
3188
|
+
path27,
|
|
3185
3189
|
expected,
|
|
3186
3190
|
receivedType(value),
|
|
3187
|
-
`Expected ${expected} at ${formatPath(
|
|
3191
|
+
`Expected ${expected} at ${formatPath(path27)}`
|
|
3188
3192
|
);
|
|
3189
3193
|
}
|
|
3190
|
-
function addUnexpectedPropertyIssue(state,
|
|
3194
|
+
function addUnexpectedPropertyIssue(state, path27) {
|
|
3191
3195
|
addIssue(
|
|
3192
3196
|
state,
|
|
3193
|
-
|
|
3197
|
+
path27,
|
|
3194
3198
|
"no additional properties",
|
|
3195
3199
|
"unknown property",
|
|
3196
|
-
`Unexpected property ${formatPath(
|
|
3200
|
+
`Unexpected property ${formatPath(path27)}`
|
|
3197
3201
|
);
|
|
3198
3202
|
}
|
|
3199
|
-
function addIssue(state,
|
|
3203
|
+
function addIssue(state, path27, expected, received, _message) {
|
|
3200
3204
|
state.issues.push({
|
|
3201
|
-
path:
|
|
3205
|
+
path: path27,
|
|
3202
3206
|
expected,
|
|
3203
3207
|
received,
|
|
3204
|
-
message: formatIssueMessage(expected,
|
|
3208
|
+
message: formatIssueMessage(expected, path27, received)
|
|
3205
3209
|
});
|
|
3206
3210
|
}
|
|
3207
|
-
function addIssueWithMessage(state,
|
|
3211
|
+
function addIssueWithMessage(state, path27, expected, received, message2) {
|
|
3208
3212
|
state.issues.push({
|
|
3209
|
-
path:
|
|
3213
|
+
path: path27,
|
|
3210
3214
|
expected,
|
|
3211
3215
|
received,
|
|
3212
3216
|
message: message2
|
|
3213
3217
|
});
|
|
3214
3218
|
}
|
|
3215
|
-
function formatIssueMessage(expected,
|
|
3216
|
-
return `Expected ${expected} at ${formatPath(
|
|
3219
|
+
function formatIssueMessage(expected, path27, received) {
|
|
3220
|
+
return `Expected ${expected} at ${formatPath(path27)}, got ${received}`;
|
|
3217
3221
|
}
|
|
3218
|
-
function formatPath(
|
|
3219
|
-
return
|
|
3222
|
+
function formatPath(path27) {
|
|
3223
|
+
return path27.length === 0 ? "value" : path27.join(".");
|
|
3220
3224
|
}
|
|
3221
3225
|
function compilePattern(pattern) {
|
|
3222
3226
|
try {
|
|
@@ -7896,13 +7900,13 @@ function formatAvailableApprovalCommandPaths(root) {
|
|
|
7896
7900
|
}
|
|
7897
7901
|
function enumerateApprovalCommandPaths(root) {
|
|
7898
7902
|
const paths = [];
|
|
7899
|
-
const visit = (node,
|
|
7903
|
+
const visit = (node, path27) => {
|
|
7900
7904
|
if (node.kind === "command") {
|
|
7901
|
-
paths.push(
|
|
7905
|
+
paths.push(path27.join("."));
|
|
7902
7906
|
return;
|
|
7903
7907
|
}
|
|
7904
7908
|
for (const child of getVisibleCliChildren(node)) {
|
|
7905
|
-
visit(child, [...
|
|
7909
|
+
visit(child, [...path27, child.name]);
|
|
7906
7910
|
}
|
|
7907
7911
|
};
|
|
7908
7912
|
if (root.kind === "command") {
|
|
@@ -7939,21 +7943,21 @@ function createHandlerContext(command, params17) {
|
|
|
7939
7943
|
}
|
|
7940
7944
|
function createFs() {
|
|
7941
7945
|
return {
|
|
7942
|
-
readFile: async (
|
|
7943
|
-
writeFile: async (
|
|
7944
|
-
await writeFile2(
|
|
7946
|
+
readFile: async (path27, encoding = "utf8") => readFile3(path27, { encoding }),
|
|
7947
|
+
writeFile: async (path27, contents, options) => {
|
|
7948
|
+
await writeFile2(path27, contents, options);
|
|
7945
7949
|
},
|
|
7946
|
-
exists: async (
|
|
7950
|
+
exists: async (path27) => {
|
|
7947
7951
|
try {
|
|
7948
|
-
await access(
|
|
7952
|
+
await access(path27);
|
|
7949
7953
|
return true;
|
|
7950
7954
|
} catch {
|
|
7951
7955
|
return false;
|
|
7952
7956
|
}
|
|
7953
7957
|
},
|
|
7954
|
-
lstat: async (
|
|
7958
|
+
lstat: async (path27) => lstat(path27),
|
|
7955
7959
|
rename: async (fromPath, toPath) => rename(fromPath, toPath),
|
|
7956
|
-
unlink: async (
|
|
7960
|
+
unlink: async (path27) => unlink(path27)
|
|
7957
7961
|
};
|
|
7958
7962
|
}
|
|
7959
7963
|
function createEnv(values = process.env) {
|
|
@@ -11948,13 +11952,13 @@ function convertJsonSchema(schema) {
|
|
|
11948
11952
|
}
|
|
11949
11953
|
return convertSchema(schema, schema, []);
|
|
11950
11954
|
}
|
|
11951
|
-
function convertSchema(schema, root,
|
|
11952
|
-
const resolvedSchema = resolveReferencedSchema(schema, root,
|
|
11955
|
+
function convertSchema(schema, root, path27) {
|
|
11956
|
+
const resolvedSchema = resolveReferencedSchema(schema, root, path27);
|
|
11953
11957
|
const normalizedSchema = normalizeNullability(resolvedSchema);
|
|
11954
11958
|
const composition = getComposition(normalizedSchema.schema);
|
|
11955
11959
|
if (Array.isArray(normalizedSchema.schema.type)) {
|
|
11956
11960
|
throw new Error(
|
|
11957
|
-
`JSON Schema "${formatJsonSchemaPath(
|
|
11961
|
+
`JSON Schema "${formatJsonSchemaPath(path27)}" has an unsupported type "${formatJsonSchemaType(
|
|
11958
11962
|
normalizedSchema.schema.type
|
|
11959
11963
|
)}". Supported: string, number, integer, boolean, array, object.`
|
|
11960
11964
|
);
|
|
@@ -11966,13 +11970,13 @@ function convertSchema(schema, root, path25) {
|
|
|
11966
11970
|
return convertEnumSchema(resolvedSchema, normalizedSchema.nullable);
|
|
11967
11971
|
}
|
|
11968
11972
|
if (composition !== void 0) {
|
|
11969
|
-
return convertCompositionSchema(normalizedSchema.schema, root, normalizedSchema.nullable,
|
|
11973
|
+
return convertCompositionSchema(normalizedSchema.schema, root, normalizedSchema.nullable, path27);
|
|
11970
11974
|
}
|
|
11971
11975
|
if (isRecordSchema(normalizedSchema.schema)) {
|
|
11972
11976
|
return applyMetadata(
|
|
11973
11977
|
S.Record(
|
|
11974
11978
|
convertSchema(normalizedSchema.schema.additionalProperties, root, [
|
|
11975
|
-
...
|
|
11979
|
+
...path27,
|
|
11976
11980
|
"additionalProperties"
|
|
11977
11981
|
])
|
|
11978
11982
|
),
|
|
@@ -12021,12 +12025,12 @@ function convertSchema(schema, root, path25) {
|
|
|
12021
12025
|
if (normalizedSchema.schema.items === void 0) {
|
|
12022
12026
|
throw new Error(
|
|
12023
12027
|
`JSON Schema "${formatJsonSchemaPath(
|
|
12024
|
-
|
|
12028
|
+
path27
|
|
12025
12029
|
)}" is an array but is missing the "items" field. Add "items": { ... } to declare the element type.`
|
|
12026
12030
|
);
|
|
12027
12031
|
}
|
|
12028
12032
|
return S.Array(
|
|
12029
|
-
convertSchema(normalizedSchema.schema.items, root, [...
|
|
12033
|
+
convertSchema(normalizedSchema.schema.items, root, [...path27, "items"]),
|
|
12030
12034
|
createCommonOptions(
|
|
12031
12035
|
normalizedSchema.schema,
|
|
12032
12036
|
normalizedSchema.nullable,
|
|
@@ -12036,7 +12040,7 @@ function convertSchema(schema, root, path25) {
|
|
|
12036
12040
|
case "object":
|
|
12037
12041
|
return convertObjectSchema(normalizedSchema.schema, root, {
|
|
12038
12042
|
nullable: normalizedSchema.nullable,
|
|
12039
|
-
path:
|
|
12043
|
+
path: path27
|
|
12040
12044
|
});
|
|
12041
12045
|
case "null":
|
|
12042
12046
|
return applyMetadata(S.Json(), normalizedSchema.schema, {
|
|
@@ -12051,12 +12055,12 @@ function convertSchema(schema, root, path25) {
|
|
|
12051
12055
|
}
|
|
12052
12056
|
throw new Error(
|
|
12053
12057
|
`JSON Schema "${formatJsonSchemaPath(
|
|
12054
|
-
|
|
12058
|
+
path27
|
|
12055
12059
|
)}" must declare one of: "type", "enum", "const", "oneOf", "anyOf", or "allOf".`
|
|
12056
12060
|
);
|
|
12057
12061
|
}
|
|
12058
12062
|
throw new Error(
|
|
12059
|
-
`JSON Schema "${formatJsonSchemaPath(
|
|
12063
|
+
`JSON Schema "${formatJsonSchemaPath(path27)}" has an unsupported type "${formatJsonSchemaType(
|
|
12060
12064
|
normalizedSchema.schema.type
|
|
12061
12065
|
)}". Supported: string, number, integer, boolean, array, object.`
|
|
12062
12066
|
);
|
|
@@ -12100,21 +12104,21 @@ function convertEnumSchema(schema, nullable) {
|
|
|
12100
12104
|
)
|
|
12101
12105
|
});
|
|
12102
12106
|
}
|
|
12103
|
-
function convertCompositionSchema(schema, root, nullable,
|
|
12107
|
+
function convertCompositionSchema(schema, root, nullable, path27) {
|
|
12104
12108
|
const composition = getComposition(schema);
|
|
12105
12109
|
const branchSchemas = composition?.branches ?? [];
|
|
12106
12110
|
const keyword = composition?.keyword ?? "oneOf";
|
|
12107
12111
|
const branches = branchSchemas.map(
|
|
12108
|
-
(branch, index) => resolveReferencedSchema(branch, root, [...
|
|
12112
|
+
(branch, index) => resolveReferencedSchema(branch, root, [...path27, keyword, String(index)])
|
|
12109
12113
|
);
|
|
12110
|
-
const discriminator = findDiscriminator(branches, root,
|
|
12114
|
+
const discriminator = findDiscriminator(branches, root, path27);
|
|
12111
12115
|
if (discriminator !== void 0) {
|
|
12112
12116
|
const convertedBranches = Object.fromEntries(
|
|
12113
12117
|
branches.map((branch, index) => [
|
|
12114
12118
|
getDiscriminatorLiteral(branch, discriminator, root),
|
|
12115
12119
|
convertObjectSchema(branch, root, {
|
|
12116
12120
|
omitProperty: discriminator,
|
|
12117
|
-
path: [...
|
|
12121
|
+
path: [...path27, keyword, String(index)]
|
|
12118
12122
|
})
|
|
12119
12123
|
])
|
|
12120
12124
|
);
|
|
@@ -12133,7 +12137,7 @@ function convertCompositionSchema(schema, root, nullable, path25) {
|
|
|
12133
12137
|
S.Union(
|
|
12134
12138
|
branches.map(
|
|
12135
12139
|
(branch, index) => convertObjectSchema(branch, root, {
|
|
12136
|
-
path: [...
|
|
12140
|
+
path: [...path27, keyword, String(index)]
|
|
12137
12141
|
})
|
|
12138
12142
|
)
|
|
12139
12143
|
),
|
|
@@ -12247,11 +12251,11 @@ function getComposition(schema) {
|
|
|
12247
12251
|
}
|
|
12248
12252
|
return void 0;
|
|
12249
12253
|
}
|
|
12250
|
-
function formatJsonSchemaPath(
|
|
12251
|
-
if (
|
|
12254
|
+
function formatJsonSchemaPath(path27) {
|
|
12255
|
+
if (path27.length === 0) {
|
|
12252
12256
|
return "#";
|
|
12253
12257
|
}
|
|
12254
|
-
return `#/${
|
|
12258
|
+
return `#/${path27.map(escapeJsonPointerSegment).join("/")}`;
|
|
12255
12259
|
}
|
|
12256
12260
|
function formatJsonSchemaType(type2) {
|
|
12257
12261
|
return Array.isArray(type2) ? JSON.stringify(type2) : String(type2);
|
|
@@ -12267,11 +12271,11 @@ function isRecordSchema(schema) {
|
|
|
12267
12271
|
const propertyKeys = Object.keys(schema.properties ?? {});
|
|
12268
12272
|
return schema.type === "object" && propertyKeys.length === 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null;
|
|
12269
12273
|
}
|
|
12270
|
-
function findDiscriminator(branches, root,
|
|
12274
|
+
function findDiscriminator(branches, root, path27) {
|
|
12271
12275
|
const [firstBranch] = branches;
|
|
12272
12276
|
if (firstBranch === void 0) {
|
|
12273
12277
|
throw new Error(
|
|
12274
|
-
`JSON Schema "${formatJsonSchemaPath(
|
|
12278
|
+
`JSON Schema "${formatJsonSchemaPath(path27)}" uses oneOf/anyOf/allOf but has no branches.`
|
|
12275
12279
|
);
|
|
12276
12280
|
}
|
|
12277
12281
|
const candidateKeys = Object.keys(firstBranch.properties ?? {});
|
|
@@ -12311,19 +12315,19 @@ function getDiscriminatorLiteral(branch, key2, root) {
|
|
|
12311
12315
|
}
|
|
12312
12316
|
return void 0;
|
|
12313
12317
|
}
|
|
12314
|
-
function resolveReferencedSchema(schema, root,
|
|
12318
|
+
function resolveReferencedSchema(schema, root, path27) {
|
|
12315
12319
|
if (schema.$ref === void 0) {
|
|
12316
12320
|
return schema;
|
|
12317
12321
|
}
|
|
12318
12322
|
const resolvedTarget = resolveLocalRef(root, schema.$ref);
|
|
12319
12323
|
if (resolvedTarget === void 0) {
|
|
12320
12324
|
throw new Error(
|
|
12321
|
-
`JSON Schema "${formatJsonSchemaPath(
|
|
12325
|
+
`JSON Schema "${formatJsonSchemaPath(path27)}" uses "$ref": ${schema.$ref}. toolcraft only supports internal refs like "#/components/schemas/Foo".`
|
|
12322
12326
|
);
|
|
12323
12327
|
}
|
|
12324
12328
|
const { $ref: ignoredRef, ...siblingKeywords } = schema;
|
|
12325
12329
|
void ignoredRef;
|
|
12326
|
-
const resolvedSchema = resolveReferencedSchema(resolvedTarget, root,
|
|
12330
|
+
const resolvedSchema = resolveReferencedSchema(resolvedTarget, root, path27);
|
|
12327
12331
|
if (Object.keys(siblingKeywords).length === 0) {
|
|
12328
12332
|
return resolvedSchema;
|
|
12329
12333
|
}
|
|
@@ -12347,9 +12351,9 @@ function mergeJsonSchemas(base, overlay) {
|
|
|
12347
12351
|
...mergedRequired === void 0 ? {} : { required: mergedRequired }
|
|
12348
12352
|
};
|
|
12349
12353
|
}
|
|
12350
|
-
function hasSelfReferencingRef(schema, root,
|
|
12354
|
+
function hasSelfReferencingRef(schema, root, path27 = "#", activePaths = /* @__PURE__ */ new Set()) {
|
|
12351
12355
|
const nextActivePaths = new Set(activePaths);
|
|
12352
|
-
nextActivePaths.add(
|
|
12356
|
+
nextActivePaths.add(path27);
|
|
12353
12357
|
const localRefPath = getLocalRefPath(schema.$ref);
|
|
12354
12358
|
if (localRefPath !== void 0) {
|
|
12355
12359
|
if (nextActivePaths.has(localRefPath)) {
|
|
@@ -12360,13 +12364,13 @@ function hasSelfReferencingRef(schema, root, path25 = "#", activePaths = /* @__P
|
|
|
12360
12364
|
return true;
|
|
12361
12365
|
}
|
|
12362
12366
|
}
|
|
12363
|
-
if (schema.items !== void 0 && hasSelfReferencingRef(schema.items, root, `${
|
|
12367
|
+
if (schema.items !== void 0 && hasSelfReferencingRef(schema.items, root, `${path27}/items`, nextActivePaths)) {
|
|
12364
12368
|
return true;
|
|
12365
12369
|
}
|
|
12366
12370
|
if (typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && hasSelfReferencingRef(
|
|
12367
12371
|
schema.additionalProperties,
|
|
12368
12372
|
root,
|
|
12369
|
-
`${
|
|
12373
|
+
`${path27}/additionalProperties`,
|
|
12370
12374
|
nextActivePaths
|
|
12371
12375
|
)) {
|
|
12372
12376
|
return true;
|
|
@@ -12375,7 +12379,7 @@ function hasSelfReferencingRef(schema, root, path25 = "#", activePaths = /* @__P
|
|
|
12375
12379
|
if (hasSelfReferencingRef(
|
|
12376
12380
|
childSchema,
|
|
12377
12381
|
root,
|
|
12378
|
-
`${
|
|
12382
|
+
`${path27}/properties/${escapeJsonPointerSegment(key2)}`,
|
|
12379
12383
|
nextActivePaths
|
|
12380
12384
|
)) {
|
|
12381
12385
|
return true;
|
|
@@ -12385,24 +12389,24 @@ function hasSelfReferencingRef(schema, root, path25 = "#", activePaths = /* @__P
|
|
|
12385
12389
|
if (hasSelfReferencingRef(
|
|
12386
12390
|
childSchema,
|
|
12387
12391
|
root,
|
|
12388
|
-
`${
|
|
12392
|
+
`${path27}/$defs/${escapeJsonPointerSegment(key2)}`,
|
|
12389
12393
|
nextActivePaths
|
|
12390
12394
|
)) {
|
|
12391
12395
|
return true;
|
|
12392
12396
|
}
|
|
12393
12397
|
}
|
|
12394
12398
|
for (const [index, childSchema] of (schema.oneOf ?? []).entries()) {
|
|
12395
|
-
if (hasSelfReferencingRef(childSchema, root, `${
|
|
12399
|
+
if (hasSelfReferencingRef(childSchema, root, `${path27}/oneOf/${index}`, nextActivePaths)) {
|
|
12396
12400
|
return true;
|
|
12397
12401
|
}
|
|
12398
12402
|
}
|
|
12399
12403
|
for (const [index, childSchema] of (schema.anyOf ?? []).entries()) {
|
|
12400
|
-
if (hasSelfReferencingRef(childSchema, root, `${
|
|
12404
|
+
if (hasSelfReferencingRef(childSchema, root, `${path27}/anyOf/${index}`, nextActivePaths)) {
|
|
12401
12405
|
return true;
|
|
12402
12406
|
}
|
|
12403
12407
|
}
|
|
12404
12408
|
for (const [index, childSchema] of (schema.allOf ?? []).entries()) {
|
|
12405
|
-
if (hasSelfReferencingRef(childSchema, root, `${
|
|
12409
|
+
if (hasSelfReferencingRef(childSchema, root, `${path27}/allOf/${index}`, nextActivePaths)) {
|
|
12406
12410
|
return true;
|
|
12407
12411
|
}
|
|
12408
12412
|
}
|
|
@@ -12418,14 +12422,14 @@ function getLocalRefPath(ref) {
|
|
|
12418
12422
|
return ref.startsWith("#/") ? ref : void 0;
|
|
12419
12423
|
}
|
|
12420
12424
|
function resolveLocalRef(root, ref) {
|
|
12421
|
-
const
|
|
12422
|
-
if (
|
|
12425
|
+
const path27 = getLocalRefPath(ref);
|
|
12426
|
+
if (path27 === void 0) {
|
|
12423
12427
|
return void 0;
|
|
12424
12428
|
}
|
|
12425
|
-
if (
|
|
12429
|
+
if (path27 === "#") {
|
|
12426
12430
|
return root;
|
|
12427
12431
|
}
|
|
12428
|
-
const segments =
|
|
12432
|
+
const segments = path27.slice(2).split("/").map(unescapeJsonPointerSegment);
|
|
12429
12433
|
let current = root;
|
|
12430
12434
|
for (const segment of segments) {
|
|
12431
12435
|
if (Array.isArray(current)) {
|
|
@@ -13566,23 +13570,23 @@ function extractFieldErrors(body) {
|
|
|
13566
13570
|
const flattened = candidates.flatMap((candidate) => flattenFieldErrors(candidate, []));
|
|
13567
13571
|
return flattened.length === 0 ? void 0 : flattened;
|
|
13568
13572
|
}
|
|
13569
|
-
function flattenFieldErrors(value,
|
|
13573
|
+
function flattenFieldErrors(value, path27) {
|
|
13570
13574
|
if (typeof value === "string") {
|
|
13571
|
-
return [{ path: formatPath2(
|
|
13575
|
+
return [{ path: formatPath2(path27), message: value }];
|
|
13572
13576
|
}
|
|
13573
13577
|
if (Array.isArray(value)) {
|
|
13574
13578
|
if (value.every((entry) => typeof entry === "string")) {
|
|
13575
|
-
return value.map((message2) => ({ path: formatPath2(
|
|
13579
|
+
return value.map((message2) => ({ path: formatPath2(path27), message: message2 }));
|
|
13576
13580
|
}
|
|
13577
|
-
return value.flatMap((entry, index) => flattenFieldErrors(entry, [...
|
|
13581
|
+
return value.flatMap((entry, index) => flattenFieldErrors(entry, [...path27, String(index)]));
|
|
13578
13582
|
}
|
|
13579
13583
|
if (!isPlainObject4(value)) {
|
|
13580
13584
|
return [];
|
|
13581
13585
|
}
|
|
13582
|
-
return Object.entries(value).flatMap(([key2, nested]) => flattenFieldErrors(nested, [...
|
|
13586
|
+
return Object.entries(value).flatMap(([key2, nested]) => flattenFieldErrors(nested, [...path27, key2]));
|
|
13583
13587
|
}
|
|
13584
|
-
function formatPath2(
|
|
13585
|
-
return
|
|
13588
|
+
function formatPath2(path27) {
|
|
13589
|
+
return path27.length === 0 ? "error" : path27.join(".");
|
|
13586
13590
|
}
|
|
13587
13591
|
function extractFirstString(body, fields) {
|
|
13588
13592
|
if (!isPlainObject4(body)) {
|
|
@@ -14152,11 +14156,11 @@ function formatSegment(segment, casing) {
|
|
|
14152
14156
|
const separator = casing === "snake" ? "_" : "-";
|
|
14153
14157
|
return splitWords3(segment).join(separator);
|
|
14154
14158
|
}
|
|
14155
|
-
function toOptionFlag(
|
|
14156
|
-
return `--${
|
|
14159
|
+
function toOptionFlag(path27, casing) {
|
|
14160
|
+
return `--${path27.map((segment) => formatSegment(segment, casing)).join(".")}`;
|
|
14157
14161
|
}
|
|
14158
|
-
function toOptionAttribute(
|
|
14159
|
-
return
|
|
14162
|
+
function toOptionAttribute(path27, casing) {
|
|
14163
|
+
return path27.map((segment) => {
|
|
14160
14164
|
const formatted = formatSegment(segment, casing);
|
|
14161
14165
|
if (casing === "snake") {
|
|
14162
14166
|
return formatted;
|
|
@@ -14167,23 +14171,23 @@ function toOptionAttribute(path25, casing) {
|
|
|
14167
14171
|
).join("");
|
|
14168
14172
|
}).join(".");
|
|
14169
14173
|
}
|
|
14170
|
-
function toDisplayPath(
|
|
14171
|
-
return
|
|
14174
|
+
function toDisplayPath(path27) {
|
|
14175
|
+
return path27.join(".");
|
|
14172
14176
|
}
|
|
14173
|
-
function toUnionKindControlPath(
|
|
14174
|
-
if (
|
|
14177
|
+
function toUnionKindControlPath(path27) {
|
|
14178
|
+
if (path27.length === 0) {
|
|
14175
14179
|
return ["kind"];
|
|
14176
14180
|
}
|
|
14177
|
-
const head =
|
|
14178
|
-
const tail =
|
|
14181
|
+
const head = path27.slice(0, -1);
|
|
14182
|
+
const tail = path27[path27.length - 1] ?? "";
|
|
14179
14183
|
return [...head, `${tail}Kind`];
|
|
14180
14184
|
}
|
|
14181
|
-
function toUnionKindDisplayPath(
|
|
14182
|
-
if (
|
|
14185
|
+
function toUnionKindDisplayPath(path27) {
|
|
14186
|
+
if (path27.length === 0) {
|
|
14183
14187
|
return "kind";
|
|
14184
14188
|
}
|
|
14185
|
-
const head =
|
|
14186
|
-
const tail =
|
|
14189
|
+
const head = path27.slice(0, -1);
|
|
14190
|
+
const tail = path27[path27.length - 1] ?? "";
|
|
14187
14191
|
return [...head, `${tail}-kind`].join(".");
|
|
14188
14192
|
}
|
|
14189
14193
|
function createSyntheticEnumSchema(values) {
|
|
@@ -14199,14 +14203,14 @@ function getRequiredBranchFingerprint(branch, casing) {
|
|
|
14199
14203
|
const requiredKeys = Object.entries(branch.shape).filter(([, schema]) => schema.kind !== "optional").map(([key2]) => formatSegment(key2, casing)).sort();
|
|
14200
14204
|
return requiredKeys.join("+");
|
|
14201
14205
|
}
|
|
14202
|
-
function collectFields(schema, casing, globalLongOptionFlags,
|
|
14206
|
+
function collectFields(schema, casing, globalLongOptionFlags, path27 = [], inheritedOptional = false, variantContext) {
|
|
14203
14207
|
const collected = {
|
|
14204
14208
|
dynamicFields: [],
|
|
14205
14209
|
fields: [],
|
|
14206
14210
|
variants: []
|
|
14207
14211
|
};
|
|
14208
14212
|
for (const [key2, rawChildSchema] of Object.entries(schema.shape)) {
|
|
14209
|
-
const nextPath = [...
|
|
14213
|
+
const nextPath = [...path27, key2];
|
|
14210
14214
|
const runtimeOptional = inheritedOptional || rawChildSchema.kind === "optional";
|
|
14211
14215
|
const childSchema = unwrapOptional2(rawChildSchema);
|
|
14212
14216
|
const requiredWhenActive = rawChildSchema.kind !== "optional" && childSchema.default === void 0;
|
|
@@ -14392,9 +14396,9 @@ function collectFields(schema, casing, globalLongOptionFlags, path25 = [], inher
|
|
|
14392
14396
|
}
|
|
14393
14397
|
return collected;
|
|
14394
14398
|
}
|
|
14395
|
-
function toCommanderOptionAttribute(
|
|
14396
|
-
const optionAttribute = toOptionAttribute(
|
|
14397
|
-
const optionFlag = toOptionFlag(
|
|
14399
|
+
function toCommanderOptionAttribute(path27, casing, globalLongOptionFlags) {
|
|
14400
|
+
const optionAttribute = toOptionAttribute(path27, casing);
|
|
14401
|
+
const optionFlag = toOptionFlag(path27, casing);
|
|
14398
14402
|
if (!globalLongOptionFlags.has(optionFlag)) {
|
|
14399
14403
|
return optionAttribute;
|
|
14400
14404
|
}
|
|
@@ -15724,10 +15728,10 @@ function writeCLIDiagnosticEvent(event) {
|
|
|
15724
15728
|
process.stderr.write(`${event.message}
|
|
15725
15729
|
`);
|
|
15726
15730
|
}
|
|
15727
|
-
function setNestedValue(target,
|
|
15731
|
+
function setNestedValue(target, path27, value) {
|
|
15728
15732
|
let cursor2 = target;
|
|
15729
|
-
for (let index = 0; index <
|
|
15730
|
-
const segment =
|
|
15733
|
+
for (let index = 0; index < path27.length - 1; index += 1) {
|
|
15734
|
+
const segment = path27[index] ?? "";
|
|
15731
15735
|
const existing = Object.prototype.hasOwnProperty.call(cursor2, segment) ? cursor2[segment] : void 0;
|
|
15732
15736
|
if (typeof existing === "object" && existing !== null) {
|
|
15733
15737
|
cursor2 = existing;
|
|
@@ -15742,7 +15746,7 @@ function setNestedValue(target, path25, value) {
|
|
|
15742
15746
|
});
|
|
15743
15747
|
cursor2 = next;
|
|
15744
15748
|
}
|
|
15745
|
-
const leaf =
|
|
15749
|
+
const leaf = path27[path27.length - 1];
|
|
15746
15750
|
if (leaf !== void 0) {
|
|
15747
15751
|
Object.defineProperty(cursor2, leaf, {
|
|
15748
15752
|
value,
|
|
@@ -15890,21 +15894,21 @@ async function withOutputFormat2(output, fn) {
|
|
|
15890
15894
|
}
|
|
15891
15895
|
function createFs2() {
|
|
15892
15896
|
return {
|
|
15893
|
-
readFile: async (
|
|
15894
|
-
writeFile: async (
|
|
15895
|
-
await writeFile5(
|
|
15897
|
+
readFile: async (path27, encoding = "utf8") => readFile5(path27, { encoding }),
|
|
15898
|
+
writeFile: async (path27, contents, options) => {
|
|
15899
|
+
await writeFile5(path27, contents, options);
|
|
15896
15900
|
},
|
|
15897
|
-
exists: async (
|
|
15901
|
+
exists: async (path27) => {
|
|
15898
15902
|
try {
|
|
15899
|
-
await access2(
|
|
15903
|
+
await access2(path27);
|
|
15900
15904
|
return true;
|
|
15901
15905
|
} catch {
|
|
15902
15906
|
return false;
|
|
15903
15907
|
}
|
|
15904
15908
|
},
|
|
15905
|
-
lstat: async (
|
|
15909
|
+
lstat: async (path27) => lstat3(path27),
|
|
15906
15910
|
rename: async (fromPath, toPath) => rename3(fromPath, toPath),
|
|
15907
|
-
unlink: async (
|
|
15911
|
+
unlink: async (path27) => unlink3(path27)
|
|
15908
15912
|
};
|
|
15909
15913
|
}
|
|
15910
15914
|
function createEnv2(values = process.env) {
|
|
@@ -15920,9 +15924,9 @@ function isPlainObject5(value) {
|
|
|
15920
15924
|
function hasFieldValue(value) {
|
|
15921
15925
|
return value !== void 0;
|
|
15922
15926
|
}
|
|
15923
|
-
function hasNestedField(fields,
|
|
15927
|
+
function hasNestedField(fields, path27) {
|
|
15924
15928
|
return fields.some(
|
|
15925
|
-
(field) =>
|
|
15929
|
+
(field) => path27.length < field.path.length && path27.every((segment, index) => field.path[index] === segment)
|
|
15926
15930
|
);
|
|
15927
15931
|
}
|
|
15928
15932
|
function describeExpectedPresetValue(schema) {
|
|
@@ -16051,9 +16055,9 @@ async function loadPresetValues(fields, presetPath) {
|
|
|
16051
16055
|
}
|
|
16052
16056
|
const fieldByPath = new Map(fields.map((field) => [field.displayPath, field]));
|
|
16053
16057
|
const presetValues = {};
|
|
16054
|
-
function visitObject(current,
|
|
16058
|
+
function visitObject(current, path27) {
|
|
16055
16059
|
for (const [key2, value] of Object.entries(current)) {
|
|
16056
|
-
const nextPath = [...
|
|
16060
|
+
const nextPath = [...path27, key2];
|
|
16057
16061
|
const displayPath = toDisplayPath(nextPath);
|
|
16058
16062
|
const field = fieldByPath.get(displayPath);
|
|
16059
16063
|
if (field !== void 0) {
|
|
@@ -16446,8 +16450,8 @@ function validateServices(services) {
|
|
|
16446
16450
|
}
|
|
16447
16451
|
}
|
|
16448
16452
|
}
|
|
16449
|
-
function getNestedValue(target,
|
|
16450
|
-
return
|
|
16453
|
+
function getNestedValue(target, path27) {
|
|
16454
|
+
return path27.reduce(
|
|
16451
16455
|
(current, segment) => current !== null && typeof current === "object" ? current[segment] : void 0,
|
|
16452
16456
|
target
|
|
16453
16457
|
);
|
|
@@ -19306,13 +19310,6 @@ function createTerminalPilotRuntime(options = {}) {
|
|
|
19306
19310
|
}
|
|
19307
19311
|
};
|
|
19308
19312
|
}
|
|
19309
|
-
async function closeSharedTerminalPilotRuntime() {
|
|
19310
|
-
if (sharedRuntime === void 0) {
|
|
19311
|
-
return;
|
|
19312
|
-
}
|
|
19313
|
-
await sharedRuntime.close();
|
|
19314
|
-
sharedRuntime = void 0;
|
|
19315
|
-
}
|
|
19316
19313
|
|
|
19317
19314
|
// src/commands/close-session.ts
|
|
19318
19315
|
var params = S.Object({
|
|
@@ -19902,22 +19899,22 @@ function prune(obj, shape) {
|
|
|
19902
19899
|
}
|
|
19903
19900
|
return { changed, result };
|
|
19904
19901
|
}
|
|
19905
|
-
function modifyAtPath(content,
|
|
19902
|
+
function modifyAtPath(content, path27, value) {
|
|
19906
19903
|
const indent = detectIndent(content);
|
|
19907
19904
|
const formattingOptions = {
|
|
19908
19905
|
tabSize: indent === " " ? 1 : indent.length,
|
|
19909
19906
|
insertSpaces: indent !== " ",
|
|
19910
19907
|
eol: "\n"
|
|
19911
19908
|
};
|
|
19912
|
-
const edits = jsonc.modify(content,
|
|
19909
|
+
const edits = jsonc.modify(content, path27, value, { formattingOptions });
|
|
19913
19910
|
let result = jsonc.applyEdits(content, edits);
|
|
19914
19911
|
if (!result.endsWith("\n")) {
|
|
19915
19912
|
result += "\n";
|
|
19916
19913
|
}
|
|
19917
19914
|
return result;
|
|
19918
19915
|
}
|
|
19919
|
-
function removeAtPath(content,
|
|
19920
|
-
return modifyAtPath(content,
|
|
19916
|
+
function removeAtPath(content, path27) {
|
|
19917
|
+
return modifyAtPath(content, path27, void 0);
|
|
19921
19918
|
}
|
|
19922
19919
|
function serializeUpdate(content, current, next) {
|
|
19923
19920
|
let result = content || "{}";
|
|
@@ -19927,15 +19924,15 @@ function serializeUpdate(content, current, next) {
|
|
|
19927
19924
|
}
|
|
19928
19925
|
return result;
|
|
19929
19926
|
}
|
|
19930
|
-
function applyObjectUpdate(content,
|
|
19927
|
+
function applyObjectUpdate(content, path27, current, next) {
|
|
19931
19928
|
let result = content;
|
|
19932
19929
|
for (const key2 of Object.keys(current)) {
|
|
19933
19930
|
if (!hasConfigEntry(next, key2)) {
|
|
19934
|
-
result = removeAtPath(result, [...
|
|
19931
|
+
result = removeAtPath(result, [...path27, key2]);
|
|
19935
19932
|
}
|
|
19936
19933
|
}
|
|
19937
19934
|
for (const [key2, nextValue] of Object.entries(next)) {
|
|
19938
|
-
const nextPath = [...
|
|
19935
|
+
const nextPath = [...path27, key2];
|
|
19939
19936
|
const hasCurrent = hasConfigEntry(current, key2);
|
|
19940
19937
|
const currentValue = hasCurrent ? current[key2] : void 0;
|
|
19941
19938
|
if (hasCurrent && isConfigObject(currentValue) && isConfigObject(nextValue)) {
|
|
@@ -20135,16 +20132,16 @@ function getConfigFormat(pathOrFormat) {
|
|
|
20135
20132
|
}
|
|
20136
20133
|
return formatRegistry[formatName];
|
|
20137
20134
|
}
|
|
20138
|
-
function detectFormat(
|
|
20139
|
-
const ext = getExtension(
|
|
20135
|
+
function detectFormat(path27) {
|
|
20136
|
+
const ext = getExtension(path27);
|
|
20140
20137
|
return extensionMap[ext];
|
|
20141
20138
|
}
|
|
20142
|
-
function getExtension(
|
|
20143
|
-
const lastDot =
|
|
20139
|
+
function getExtension(path27) {
|
|
20140
|
+
const lastDot = path27.lastIndexOf(".");
|
|
20144
20141
|
if (lastDot === -1) {
|
|
20145
20142
|
return "";
|
|
20146
20143
|
}
|
|
20147
|
-
return
|
|
20144
|
+
return path27.slice(lastDot).toLowerCase();
|
|
20148
20145
|
}
|
|
20149
20146
|
|
|
20150
20147
|
// ../config-mutations/src/execution/path-utils.ts
|
|
@@ -22762,6 +22759,394 @@ function createTerminalPilotGroup() {
|
|
|
22762
22759
|
}
|
|
22763
22760
|
var terminalPilotGroup = Object.freeze(createTerminalPilotGroup());
|
|
22764
22761
|
|
|
22762
|
+
// src/commands/daemon-runtime.ts
|
|
22763
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
22764
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
22765
|
+
import { mkdir as mkdir3, unlink as unlink4 } from "node:fs/promises";
|
|
22766
|
+
import net from "node:net";
|
|
22767
|
+
import os4 from "node:os";
|
|
22768
|
+
import path24 from "node:path";
|
|
22769
|
+
var RUNTIME_DIR_ENV = "TERMINAL_PILOT_RUNTIME_DIR";
|
|
22770
|
+
var DAEMON_ARG = "__daemon";
|
|
22771
|
+
var START_TIMEOUT_MS = 5e3;
|
|
22772
|
+
var IDLE_SHUTDOWN_MS = 1e3;
|
|
22773
|
+
function isTerminalPilotDaemonArgv(argv) {
|
|
22774
|
+
return argv[2] === DAEMON_ARG;
|
|
22775
|
+
}
|
|
22776
|
+
async function runTerminalPilotDaemon() {
|
|
22777
|
+
const runtime = createTerminalPilotRuntime();
|
|
22778
|
+
const socketPath = resolveSocketPath(process.env);
|
|
22779
|
+
await mkdir3(path24.dirname(socketPath), { recursive: true });
|
|
22780
|
+
if (process.platform !== "win32") {
|
|
22781
|
+
await unlink4(socketPath).catch(() => void 0);
|
|
22782
|
+
}
|
|
22783
|
+
let idleTimer;
|
|
22784
|
+
const server = net.createServer((socket) => {
|
|
22785
|
+
let buffer = "";
|
|
22786
|
+
socket.setEncoding("utf8");
|
|
22787
|
+
socket.on("data", (chunk) => {
|
|
22788
|
+
buffer += chunk;
|
|
22789
|
+
while (true) {
|
|
22790
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
22791
|
+
if (newlineIndex < 0) {
|
|
22792
|
+
break;
|
|
22793
|
+
}
|
|
22794
|
+
const line = buffer.slice(0, newlineIndex);
|
|
22795
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
22796
|
+
void handleRequestLine(runtime, line).then((response) => {
|
|
22797
|
+
socket.write(`${JSON.stringify(response)}
|
|
22798
|
+
`);
|
|
22799
|
+
scheduleIdleShutdown();
|
|
22800
|
+
});
|
|
22801
|
+
}
|
|
22802
|
+
});
|
|
22803
|
+
});
|
|
22804
|
+
async function shutdown() {
|
|
22805
|
+
if (idleTimer !== void 0) {
|
|
22806
|
+
clearTimeout(idleTimer);
|
|
22807
|
+
idleTimer = void 0;
|
|
22808
|
+
}
|
|
22809
|
+
await runtime.close();
|
|
22810
|
+
await new Promise((resolve) => {
|
|
22811
|
+
server.close(() => resolve());
|
|
22812
|
+
});
|
|
22813
|
+
if (process.platform !== "win32") {
|
|
22814
|
+
await unlink4(socketPath).catch(() => void 0);
|
|
22815
|
+
}
|
|
22816
|
+
}
|
|
22817
|
+
async function scheduleIdleShutdown() {
|
|
22818
|
+
if (idleTimer !== void 0) {
|
|
22819
|
+
clearTimeout(idleTimer);
|
|
22820
|
+
idleTimer = void 0;
|
|
22821
|
+
}
|
|
22822
|
+
const sessions = await runtime.listSessions();
|
|
22823
|
+
if (sessions.length > 0) {
|
|
22824
|
+
return;
|
|
22825
|
+
}
|
|
22826
|
+
idleTimer = setTimeout(() => {
|
|
22827
|
+
void shutdown().then(() => {
|
|
22828
|
+
process.exit(0);
|
|
22829
|
+
});
|
|
22830
|
+
}, IDLE_SHUTDOWN_MS);
|
|
22831
|
+
}
|
|
22832
|
+
await new Promise((resolve, reject) => {
|
|
22833
|
+
server.once("error", reject);
|
|
22834
|
+
server.listen(socketPath, () => {
|
|
22835
|
+
server.off("error", reject);
|
|
22836
|
+
resolve();
|
|
22837
|
+
});
|
|
22838
|
+
});
|
|
22839
|
+
}
|
|
22840
|
+
function createDaemonTerminalPilotRuntime() {
|
|
22841
|
+
let nextId = 1;
|
|
22842
|
+
async function request(method, params17) {
|
|
22843
|
+
await ensureDaemon();
|
|
22844
|
+
return sendRequest(method, params17, nextId++);
|
|
22845
|
+
}
|
|
22846
|
+
function proxySession(name, info2) {
|
|
22847
|
+
return {
|
|
22848
|
+
id: info2.id,
|
|
22849
|
+
command: info2.command,
|
|
22850
|
+
pid: info2.pid,
|
|
22851
|
+
exitCode: info2.exitCode,
|
|
22852
|
+
fill: async (text4) => {
|
|
22853
|
+
await request("sessionAction", { name, action: "fill", args: [text4] });
|
|
22854
|
+
},
|
|
22855
|
+
type: async (text4) => {
|
|
22856
|
+
await request("sessionAction", { name, action: "type", args: [text4] });
|
|
22857
|
+
},
|
|
22858
|
+
press: async (key2) => {
|
|
22859
|
+
await request("sessionAction", { name, action: "press", args: [key2] });
|
|
22860
|
+
},
|
|
22861
|
+
signal: async (signal) => {
|
|
22862
|
+
await request("sessionAction", { name, action: "signal", args: [signal] });
|
|
22863
|
+
},
|
|
22864
|
+
waitFor: async (pattern, options) => request("sessionAction", {
|
|
22865
|
+
name,
|
|
22866
|
+
action: "waitFor",
|
|
22867
|
+
args: [serializePattern(pattern), options]
|
|
22868
|
+
}),
|
|
22869
|
+
waitForExit: async (options) => request("sessionAction", { name, action: "waitForExit", args: [options] }),
|
|
22870
|
+
screen: async () => request("sessionAction", { name, action: "screen", args: [] }),
|
|
22871
|
+
history: async (options) => request("sessionAction", { name, action: "history", args: [options] }),
|
|
22872
|
+
resize: async (cols, rows) => {
|
|
22873
|
+
await request("sessionAction", { name, action: "resize", args: [cols, rows] });
|
|
22874
|
+
},
|
|
22875
|
+
close: async () => {
|
|
22876
|
+
const result = await request("closeSession", { name });
|
|
22877
|
+
return result.exitCode;
|
|
22878
|
+
}
|
|
22879
|
+
};
|
|
22880
|
+
}
|
|
22881
|
+
return {
|
|
22882
|
+
async createSession(params17, env) {
|
|
22883
|
+
const result = await request("createSession", {
|
|
22884
|
+
params: params17,
|
|
22885
|
+
envSession: env?.get(SESSION_ENV_VAR)
|
|
22886
|
+
});
|
|
22887
|
+
return { name: result.name, session: proxySession(result.name, result.session) };
|
|
22888
|
+
},
|
|
22889
|
+
async resolveSession(name, env) {
|
|
22890
|
+
const result = await request("resolveSession", {
|
|
22891
|
+
name,
|
|
22892
|
+
envSession: env?.get(SESSION_ENV_VAR)
|
|
22893
|
+
});
|
|
22894
|
+
return { name: result.name, session: proxySession(result.name, result.session) };
|
|
22895
|
+
},
|
|
22896
|
+
async closeSession(name, env) {
|
|
22897
|
+
return request("closeSession", {
|
|
22898
|
+
name,
|
|
22899
|
+
envSession: env?.get(SESSION_ENV_VAR)
|
|
22900
|
+
});
|
|
22901
|
+
},
|
|
22902
|
+
async listSessions() {
|
|
22903
|
+
const sessions = await request("listSessions");
|
|
22904
|
+
return sessions.map((entry) => ({
|
|
22905
|
+
name: entry.name,
|
|
22906
|
+
session: proxySession(entry.name, entry.session)
|
|
22907
|
+
}));
|
|
22908
|
+
},
|
|
22909
|
+
async close() {
|
|
22910
|
+
await request("shutdown").catch(() => void 0);
|
|
22911
|
+
}
|
|
22912
|
+
};
|
|
22913
|
+
}
|
|
22914
|
+
async function handleRequestLine(runtime, line) {
|
|
22915
|
+
let request;
|
|
22916
|
+
try {
|
|
22917
|
+
request = JSON.parse(line);
|
|
22918
|
+
} catch (error3) {
|
|
22919
|
+
return {
|
|
22920
|
+
id: 0,
|
|
22921
|
+
ok: false,
|
|
22922
|
+
error: { message: error3 instanceof Error ? error3.message : "Invalid request" }
|
|
22923
|
+
};
|
|
22924
|
+
}
|
|
22925
|
+
try {
|
|
22926
|
+
const result = await handleRequest(runtime, request);
|
|
22927
|
+
return { id: request.id, ok: true, result };
|
|
22928
|
+
} catch (error3) {
|
|
22929
|
+
return {
|
|
22930
|
+
id: request.id,
|
|
22931
|
+
ok: false,
|
|
22932
|
+
error: { message: error3 instanceof Error ? error3.message : String(error3) }
|
|
22933
|
+
};
|
|
22934
|
+
}
|
|
22935
|
+
}
|
|
22936
|
+
async function handleRequest(runtime, request) {
|
|
22937
|
+
const params17 = isRecord6(request.params) ? request.params : {};
|
|
22938
|
+
if (request.method === "ping") {
|
|
22939
|
+
return { ok: true };
|
|
22940
|
+
}
|
|
22941
|
+
if (request.method === "createSession") {
|
|
22942
|
+
const createParams = isRecord6(params17.params) ? params17.params : {};
|
|
22943
|
+
const namedSession = await runtime.createSession(
|
|
22944
|
+
createParams,
|
|
22945
|
+
envFromValue(params17.envSession)
|
|
22946
|
+
);
|
|
22947
|
+
return formatNamedSession(namedSession);
|
|
22948
|
+
}
|
|
22949
|
+
if (request.method === "resolveSession") {
|
|
22950
|
+
const namedSession = await runtime.resolveSession(
|
|
22951
|
+
optionalString2(params17.name),
|
|
22952
|
+
envFromValue(params17.envSession)
|
|
22953
|
+
);
|
|
22954
|
+
return formatNamedSession(namedSession);
|
|
22955
|
+
}
|
|
22956
|
+
if (request.method === "listSessions") {
|
|
22957
|
+
const sessions = await runtime.listSessions();
|
|
22958
|
+
return sessions.map(formatNamedSession);
|
|
22959
|
+
}
|
|
22960
|
+
if (request.method === "closeSession") {
|
|
22961
|
+
return runtime.closeSession(optionalString2(params17.name), envFromValue(params17.envSession));
|
|
22962
|
+
}
|
|
22963
|
+
if (request.method === "sessionAction") {
|
|
22964
|
+
return runSessionAction(runtime, params17);
|
|
22965
|
+
}
|
|
22966
|
+
if (request.method === "shutdown") {
|
|
22967
|
+
await runtime.close();
|
|
22968
|
+
process.exit(0);
|
|
22969
|
+
}
|
|
22970
|
+
throw new UserError(`Unknown terminal-pilot daemon method: ${request.method}`);
|
|
22971
|
+
}
|
|
22972
|
+
async function runSessionAction(runtime, params17) {
|
|
22973
|
+
const name = optionalString2(params17.name);
|
|
22974
|
+
const action = optionalString2(params17.action);
|
|
22975
|
+
const args = Array.isArray(params17.args) ? params17.args : [];
|
|
22976
|
+
const namedSession = await runtime.resolveSession(name);
|
|
22977
|
+
const session = namedSession.session;
|
|
22978
|
+
if (action === "fill") {
|
|
22979
|
+
await session.fill(String(args[0] ?? ""));
|
|
22980
|
+
return void 0;
|
|
22981
|
+
}
|
|
22982
|
+
if (action === "type") {
|
|
22983
|
+
await session.type(String(args[0] ?? ""));
|
|
22984
|
+
return void 0;
|
|
22985
|
+
}
|
|
22986
|
+
if (action === "press") {
|
|
22987
|
+
await session.press(String(args[0] ?? ""));
|
|
22988
|
+
return void 0;
|
|
22989
|
+
}
|
|
22990
|
+
if (action === "signal") {
|
|
22991
|
+
await session.signal(String(args[0] ?? ""));
|
|
22992
|
+
return void 0;
|
|
22993
|
+
}
|
|
22994
|
+
if (action === "waitFor") {
|
|
22995
|
+
return session.waitFor(deserializePattern(args[0]), optionalRecord(args[1]));
|
|
22996
|
+
}
|
|
22997
|
+
if (action === "waitForExit") {
|
|
22998
|
+
return session.waitForExit(optionalRecord(args[0]));
|
|
22999
|
+
}
|
|
23000
|
+
if (action === "screen") {
|
|
23001
|
+
const screen = await session.screen();
|
|
23002
|
+
return {
|
|
23003
|
+
lines: [...screen.lines],
|
|
23004
|
+
rawLines: [...screen.rawLines],
|
|
23005
|
+
cursor: { ...screen.cursor },
|
|
23006
|
+
size: { ...screen.size }
|
|
23007
|
+
};
|
|
23008
|
+
}
|
|
23009
|
+
if (action === "history") {
|
|
23010
|
+
return session.history(optionalRecord(args[0]));
|
|
23011
|
+
}
|
|
23012
|
+
if (action === "resize") {
|
|
23013
|
+
await session.resize(Number(args[0]), Number(args[1]));
|
|
23014
|
+
return void 0;
|
|
23015
|
+
}
|
|
23016
|
+
throw new UserError(`Unknown terminal-pilot session action: ${action ?? "<missing>"}`);
|
|
23017
|
+
}
|
|
23018
|
+
async function ensureDaemon() {
|
|
23019
|
+
try {
|
|
23020
|
+
await sendRequest("ping", void 0, 0, { start: false });
|
|
23021
|
+
return;
|
|
23022
|
+
} catch {
|
|
23023
|
+
}
|
|
23024
|
+
const socketPath = resolveSocketPath(process.env);
|
|
23025
|
+
await mkdir3(path24.dirname(socketPath), { recursive: true });
|
|
23026
|
+
if (process.platform !== "win32") {
|
|
23027
|
+
await unlink4(socketPath).catch(() => void 0);
|
|
23028
|
+
}
|
|
23029
|
+
const entryPoint = process.argv[1];
|
|
23030
|
+
if (typeof entryPoint !== "string" || entryPoint.length === 0) {
|
|
23031
|
+
throw new UserError("Cannot start terminal-pilot daemon: entrypoint is unknown.");
|
|
23032
|
+
}
|
|
23033
|
+
const child = spawn7(process.execPath, [...process.execArgv, entryPoint, DAEMON_ARG], {
|
|
23034
|
+
detached: true,
|
|
23035
|
+
stdio: "ignore",
|
|
23036
|
+
env: process.env
|
|
23037
|
+
});
|
|
23038
|
+
child.unref();
|
|
23039
|
+
const startedAt = Date.now();
|
|
23040
|
+
while (Date.now() - startedAt <= START_TIMEOUT_MS) {
|
|
23041
|
+
try {
|
|
23042
|
+
await sendRequest("ping", void 0, 0, { start: false });
|
|
23043
|
+
return;
|
|
23044
|
+
} catch {
|
|
23045
|
+
await sleep2(50);
|
|
23046
|
+
}
|
|
23047
|
+
}
|
|
23048
|
+
throw new UserError("Timed out waiting for terminal-pilot daemon to start.");
|
|
23049
|
+
}
|
|
23050
|
+
function sendRequest(method, params17, id, options = {}) {
|
|
23051
|
+
const socketPath = resolveSocketPath(process.env);
|
|
23052
|
+
return new Promise((resolve, reject) => {
|
|
23053
|
+
const socket = net.createConnection(socketPath);
|
|
23054
|
+
let buffer = "";
|
|
23055
|
+
socket.setEncoding("utf8");
|
|
23056
|
+
socket.on("connect", () => {
|
|
23057
|
+
const request = { id, method, params: params17 };
|
|
23058
|
+
socket.write(`${JSON.stringify(request)}
|
|
23059
|
+
`);
|
|
23060
|
+
});
|
|
23061
|
+
socket.on("data", (chunk) => {
|
|
23062
|
+
buffer += chunk;
|
|
23063
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
23064
|
+
if (newlineIndex < 0) {
|
|
23065
|
+
return;
|
|
23066
|
+
}
|
|
23067
|
+
const line = buffer.slice(0, newlineIndex);
|
|
23068
|
+
socket.end();
|
|
23069
|
+
try {
|
|
23070
|
+
const response = JSON.parse(line);
|
|
23071
|
+
if (response.ok) {
|
|
23072
|
+
resolve(response.result);
|
|
23073
|
+
} else {
|
|
23074
|
+
reject(new UserError(response.error.message));
|
|
23075
|
+
}
|
|
23076
|
+
} catch (error3) {
|
|
23077
|
+
reject(error3);
|
|
23078
|
+
}
|
|
23079
|
+
});
|
|
23080
|
+
socket.on("error", (error3) => {
|
|
23081
|
+
if (options.start === false) {
|
|
23082
|
+
reject(error3);
|
|
23083
|
+
return;
|
|
23084
|
+
}
|
|
23085
|
+
reject(new UserError(error3.message));
|
|
23086
|
+
});
|
|
23087
|
+
});
|
|
23088
|
+
}
|
|
23089
|
+
function resolveSocketPath(env) {
|
|
23090
|
+
const runtimeDir = env[RUNTIME_DIR_ENV] ?? path24.join(os4.tmpdir(), `terminal-pilot-${process.getuid?.() ?? "user"}`);
|
|
23091
|
+
if (process.platform === "win32") {
|
|
23092
|
+
const hash = createHash5("sha256").update(runtimeDir).digest("hex").slice(0, 16);
|
|
23093
|
+
return `\\\\.\\pipe\\terminal-pilot-${hash}`;
|
|
23094
|
+
}
|
|
23095
|
+
return path24.join(runtimeDir, "daemon.sock");
|
|
23096
|
+
}
|
|
23097
|
+
function formatNamedSession(namedSession) {
|
|
23098
|
+
return {
|
|
23099
|
+
name: namedSession.name,
|
|
23100
|
+
session: formatSession(namedSession.session)
|
|
23101
|
+
};
|
|
23102
|
+
}
|
|
23103
|
+
function formatSession(session) {
|
|
23104
|
+
return {
|
|
23105
|
+
id: session.id,
|
|
23106
|
+
command: session.command,
|
|
23107
|
+
pid: session.pid,
|
|
23108
|
+
exitCode: session.exitCode
|
|
23109
|
+
};
|
|
23110
|
+
}
|
|
23111
|
+
function envFromValue(value) {
|
|
23112
|
+
const sessionName = optionalString2(value);
|
|
23113
|
+
if (sessionName === void 0) {
|
|
23114
|
+
return void 0;
|
|
23115
|
+
}
|
|
23116
|
+
return {
|
|
23117
|
+
get(key2) {
|
|
23118
|
+
return key2 === SESSION_ENV_VAR ? sessionName : void 0;
|
|
23119
|
+
}
|
|
23120
|
+
};
|
|
23121
|
+
}
|
|
23122
|
+
function serializePattern(pattern) {
|
|
23123
|
+
if (typeof pattern === "string") {
|
|
23124
|
+
return { kind: "literal", value: pattern };
|
|
23125
|
+
}
|
|
23126
|
+
return { kind: "regex", source: pattern.source, flags: pattern.flags };
|
|
23127
|
+
}
|
|
23128
|
+
function deserializePattern(value) {
|
|
23129
|
+
if (!isRecord6(value)) {
|
|
23130
|
+
return String(value ?? "");
|
|
23131
|
+
}
|
|
23132
|
+
if (value.kind === "regex") {
|
|
23133
|
+
return new RegExp(String(value.source ?? ""), String(value.flags ?? ""));
|
|
23134
|
+
}
|
|
23135
|
+
return String(value.value ?? "");
|
|
23136
|
+
}
|
|
23137
|
+
function optionalRecord(value) {
|
|
23138
|
+
return isRecord6(value) ? value : void 0;
|
|
23139
|
+
}
|
|
23140
|
+
function optionalString2(value) {
|
|
23141
|
+
return typeof value === "string" ? value : void 0;
|
|
23142
|
+
}
|
|
23143
|
+
function isRecord6(value) {
|
|
23144
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23145
|
+
}
|
|
23146
|
+
function sleep2(ms) {
|
|
23147
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
23148
|
+
}
|
|
23149
|
+
|
|
22765
23150
|
// src/cli.ts
|
|
22766
23151
|
configureTheme({ brand: "green", label: "Terminal Pilot" });
|
|
22767
23152
|
function normalizeArgv(argv) {
|
|
@@ -22770,11 +23155,18 @@ function normalizeArgv(argv) {
|
|
|
22770
23155
|
}
|
|
22771
23156
|
return argv;
|
|
22772
23157
|
}
|
|
22773
|
-
async function main(argv = process.argv) {
|
|
23158
|
+
async function main(argv = process.argv, options = {}) {
|
|
23159
|
+
if (isTerminalPilotDaemonArgv(argv)) {
|
|
23160
|
+
await runTerminalPilotDaemon();
|
|
23161
|
+
return;
|
|
23162
|
+
}
|
|
22774
23163
|
const originalArgv = process.argv;
|
|
22775
23164
|
process.argv = normalizeArgv(argv);
|
|
22776
23165
|
try {
|
|
22777
23166
|
await runCLI(createTerminalPilotGroup(), {
|
|
23167
|
+
services: {
|
|
23168
|
+
terminalPilotRuntime: options.terminalPilotRuntime ?? createDaemonTerminalPilotRuntime()
|
|
23169
|
+
},
|
|
22778
23170
|
controls: {
|
|
22779
23171
|
debug: true,
|
|
22780
23172
|
output: true,
|
|
@@ -22794,7 +23186,7 @@ async function isDirectExecution(argv) {
|
|
|
22794
23186
|
try {
|
|
22795
23187
|
const modulePath = fileURLToPath5(import.meta.url);
|
|
22796
23188
|
const [resolvedEntryPoint, resolvedModulePath] = await Promise.all([
|
|
22797
|
-
realpath3(
|
|
23189
|
+
realpath3(path25.resolve(entryPoint)),
|
|
22798
23190
|
realpath3(modulePath)
|
|
22799
23191
|
]);
|
|
22800
23192
|
return resolvedEntryPoint === resolvedModulePath;
|
|
@@ -22807,6 +23199,7 @@ if (await isDirectExecution(process.argv)) {
|
|
|
22807
23199
|
}
|
|
22808
23200
|
|
|
22809
23201
|
// src/testing/cli-repl.ts
|
|
23202
|
+
var cliPath = path26.join(path26.dirname(fileURLToPath6(import.meta.url)), "..", "cli.ts");
|
|
22810
23203
|
function appendJsonOutputFlag(args) {
|
|
22811
23204
|
if (args.includes("--json") || args.includes("--output") || args.some((arg) => arg.startsWith("--output="))) {
|
|
22812
23205
|
return [...args];
|
|
@@ -22841,6 +23234,7 @@ function canParseJson(text4) {
|
|
|
22841
23234
|
}
|
|
22842
23235
|
}
|
|
22843
23236
|
function createTerminalPilotCliRepl() {
|
|
23237
|
+
const terminalPilotRuntime = createTerminalPilotRuntime();
|
|
22844
23238
|
return {
|
|
22845
23239
|
async run(args) {
|
|
22846
23240
|
const stdoutChunks = [];
|
|
@@ -22862,7 +23256,7 @@ function createTerminalPilotCliRepl() {
|
|
|
22862
23256
|
return true;
|
|
22863
23257
|
});
|
|
22864
23258
|
try {
|
|
22865
|
-
await main(["node",
|
|
23259
|
+
await main(["node", cliPath, ...args], { terminalPilotRuntime });
|
|
22866
23260
|
} finally {
|
|
22867
23261
|
process.stdout.write = originalStdoutWrite;
|
|
22868
23262
|
process.stderr.write = originalStderrWrite;
|
|
@@ -22891,7 +23285,9 @@ function createTerminalPilotCliRepl() {
|
|
|
22891
23285
|
};
|
|
22892
23286
|
}
|
|
22893
23287
|
if (result.stdout.length === 0) {
|
|
22894
|
-
throw new Error(
|
|
23288
|
+
throw new Error(
|
|
23289
|
+
`Expected JSON output for terminal-pilot ${args.join(" ")}, but stdout was empty.`
|
|
23290
|
+
);
|
|
22895
23291
|
}
|
|
22896
23292
|
return {
|
|
22897
23293
|
exitCode: result.exitCode,
|
|
@@ -22900,7 +23296,7 @@ function createTerminalPilotCliRepl() {
|
|
|
22900
23296
|
};
|
|
22901
23297
|
},
|
|
22902
23298
|
async close() {
|
|
22903
|
-
await
|
|
23299
|
+
await terminalPilotRuntime.close();
|
|
22904
23300
|
}
|
|
22905
23301
|
};
|
|
22906
23302
|
}
|