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.
@@ -7,8 +7,12 @@ var __export = (target, all) => {
7
7
  // src/testing/qa-cli.ts
8
8
  import assert from "node:assert/strict";
9
9
  import { rm as rm2 } from "node:fs/promises";
10
- import os4 from "node:os";
11
- import path25 from "node:path";
10
+ import os5 from "node:os";
11
+ import path27 from "node:path";
12
+ import { fileURLToPath as fileURLToPath7 } from "node:url";
13
+
14
+ // src/testing/cli-repl.ts
15
+ import path26 from "node:path";
12
16
  import { fileURLToPath as fileURLToPath6 } from "node:url";
13
17
 
14
18
  // src/ansi.ts
@@ -86,7 +90,7 @@ function consumeTerminatedString(input, index, allowBellTerminator) {
86
90
 
87
91
  // src/cli.ts
88
92
  import { realpath as realpath3 } from "node:fs/promises";
89
- import path24 from "node:path";
93
+ import path25 from "node:path";
90
94
  import { fileURLToPath as fileURLToPath5 } from "node:url";
91
95
 
92
96
  // ../toolcraft/src/cli.ts
@@ -2825,17 +2829,17 @@ function validate(schema, value) {
2825
2829
  }
2826
2830
  return { ok: true, value: result.present ? result.value : void 0 };
2827
2831
  }
2828
- function walkSchema(schema, value, path26, state) {
2832
+ function walkSchema(schema, value, path28, state) {
2829
2833
  if (schema.kind === "optional") {
2830
- return walkOptional(schema, value, path26, state);
2834
+ return walkOptional(schema, value, path28, state);
2831
2835
  }
2832
2836
  if (value === missingValue) {
2833
2837
  addIssue(
2834
2838
  state,
2835
- path26,
2839
+ path28,
2836
2840
  expectedFor(schema),
2837
2841
  "missing",
2838
- `Expected ${expectedFor(schema)} at ${formatPath(path26)}`
2842
+ `Expected ${expectedFor(schema)} at ${formatPath(path28)}`
2839
2843
  );
2840
2844
  return { present: false };
2841
2845
  }
@@ -2844,149 +2848,149 @@ function walkSchema(schema, value, path26, state) {
2844
2848
  }
2845
2849
  switch (schema.kind) {
2846
2850
  case "string":
2847
- return walkString(schema, value, path26, state);
2851
+ return walkString(schema, value, path28, state);
2848
2852
  case "number":
2849
- return walkNumber(schema, value, path26, state);
2853
+ return walkNumber(schema, value, path28, state);
2850
2854
  case "boolean":
2851
- return walkBoolean(value, path26, state);
2855
+ return walkBoolean(value, path28, state);
2852
2856
  case "enum":
2853
- return walkEnum(schema, value, path26, state);
2857
+ return walkEnum(schema, value, path28, state);
2854
2858
  case "array":
2855
- return walkArray(schema, value, path26, state);
2859
+ return walkArray(schema, value, path28, state);
2856
2860
  case "object":
2857
- return walkObject(schema, value, path26, state);
2861
+ return walkObject(schema, value, path28, state);
2858
2862
  case "oneOf":
2859
- return walkOneOf(schema, value, path26, state);
2863
+ return walkOneOf(schema, value, path28, state);
2860
2864
  case "union":
2861
- return walkUnion(schema, value, path26, state);
2865
+ return walkUnion(schema, value, path28, state);
2862
2866
  case "record":
2863
- return walkRecord(schema, value, path26, state);
2867
+ return walkRecord(schema, value, path28, state);
2864
2868
  case "json":
2865
- return walkJson(value, path26, state);
2869
+ return walkJson(value, path28, state);
2866
2870
  }
2867
2871
  }
2868
- function walkOptional(schema, value, path26, state) {
2872
+ function walkOptional(schema, value, path28, state) {
2869
2873
  if (value === missingValue || value === void 0) {
2870
2874
  const defaultValue = getDefault(schema.inner);
2871
2875
  if (defaultValue.present) {
2872
- return walkSchema(schema.inner, cloneDefault(defaultValue.value), path26, state);
2876
+ return walkSchema(schema.inner, cloneDefault(defaultValue.value), path28, state);
2873
2877
  }
2874
2878
  return { present: false };
2875
2879
  }
2876
- return walkSchema(schema.inner, value, path26, state);
2880
+ return walkSchema(schema.inner, value, path28, state);
2877
2881
  }
2878
- function walkString(schema, value, path26, state) {
2882
+ function walkString(schema, value, path28, state) {
2879
2883
  if (typeof value !== "string") {
2880
- addExpectedIssue(state, path26, "string", value);
2884
+ addExpectedIssue(state, path28, "string", value);
2881
2885
  return { present: true, value };
2882
2886
  }
2883
2887
  if (schema.minLength !== void 0 && value.length < schema.minLength) {
2884
2888
  const expected = `string with length at least ${schema.minLength}`;
2885
2889
  addIssue(
2886
2890
  state,
2887
- path26,
2891
+ path28,
2888
2892
  expected,
2889
2893
  `string with length ${value.length}`,
2890
- `Expected ${expected} at ${formatPath(path26)}`
2894
+ `Expected ${expected} at ${formatPath(path28)}`
2891
2895
  );
2892
2896
  }
2893
2897
  if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
2894
2898
  const expected = `string with length at most ${schema.maxLength}`;
2895
2899
  addIssue(
2896
2900
  state,
2897
- path26,
2901
+ path28,
2898
2902
  expected,
2899
2903
  `string with length ${value.length}`,
2900
- `Expected ${expected} at ${formatPath(path26)}`
2904
+ `Expected ${expected} at ${formatPath(path28)}`
2901
2905
  );
2902
2906
  }
2903
2907
  if (schema.pattern !== void 0) {
2904
2908
  const pattern = compilePattern(schema.pattern);
2905
2909
  if (pattern === void 0 || !pattern.test(value)) {
2906
2910
  const expected = `string matching pattern ${schema.pattern}`;
2907
- addIssue(state, path26, expected, value, `Expected ${expected} at ${formatPath(path26)}`);
2911
+ addIssue(state, path28, expected, value, `Expected ${expected} at ${formatPath(path28)}`);
2908
2912
  }
2909
2913
  }
2910
2914
  return { present: true, value };
2911
2915
  }
2912
- function walkNumber(schema, value, path26, state) {
2916
+ function walkNumber(schema, value, path28, state) {
2913
2917
  if (typeof value !== "number" || !Number.isFinite(value)) {
2914
- addExpectedIssue(state, path26, schema.jsonType === "integer" ? "integer" : "number", value);
2918
+ addExpectedIssue(state, path28, schema.jsonType === "integer" ? "integer" : "number", value);
2915
2919
  return { present: true, value };
2916
2920
  }
2917
2921
  if (schema.jsonType === "integer" && !Number.isInteger(value)) {
2918
- addExpectedIssue(state, path26, "integer", value);
2922
+ addExpectedIssue(state, path28, "integer", value);
2919
2923
  }
2920
2924
  if (schema.minimum !== void 0 && value < schema.minimum) {
2921
2925
  const expected = `number greater than or equal to ${schema.minimum}`;
2922
- addIssue(state, path26, expected, String(value), `Expected ${expected} at ${formatPath(path26)}`);
2926
+ addIssue(state, path28, expected, String(value), `Expected ${expected} at ${formatPath(path28)}`);
2923
2927
  }
2924
2928
  if (schema.maximum !== void 0 && value > schema.maximum) {
2925
2929
  const expected = `number less than or equal to ${schema.maximum}`;
2926
- addIssue(state, path26, expected, String(value), `Expected ${expected} at ${formatPath(path26)}`);
2930
+ addIssue(state, path28, expected, String(value), `Expected ${expected} at ${formatPath(path28)}`);
2927
2931
  }
2928
2932
  return { present: true, value };
2929
2933
  }
2930
- function walkBoolean(value, path26, state) {
2934
+ function walkBoolean(value, path28, state) {
2931
2935
  if (typeof value !== "boolean") {
2932
- addExpectedIssue(state, path26, "boolean", value);
2936
+ addExpectedIssue(state, path28, "boolean", value);
2933
2937
  }
2934
2938
  return { present: true, value };
2935
2939
  }
2936
- function walkEnum(schema, value, path26, state) {
2940
+ function walkEnum(schema, value, path28, state) {
2937
2941
  if (!schema.values.includes(value)) {
2938
2942
  const expected = `one of ${schema.values.join(", ")}`;
2939
2943
  addIssue(
2940
2944
  state,
2941
- path26,
2945
+ path28,
2942
2946
  expected,
2943
2947
  receivedValue(value),
2944
- `Expected ${expected} at ${formatPath(path26)}`
2948
+ `Expected ${expected} at ${formatPath(path28)}`
2945
2949
  );
2946
2950
  }
2947
2951
  return { present: true, value };
2948
2952
  }
2949
- function walkArray(schema, value, path26, state) {
2953
+ function walkArray(schema, value, path28, state) {
2950
2954
  if (!Array.isArray(value)) {
2951
- addExpectedIssue(state, path26, "array", value);
2955
+ addExpectedIssue(state, path28, "array", value);
2952
2956
  return { present: true, value };
2953
2957
  }
2954
2958
  if (schema.minItems !== void 0 && value.length < schema.minItems) {
2955
2959
  const expected = `array with at least ${schema.minItems} items`;
2956
2960
  addIssue(
2957
2961
  state,
2958
- path26,
2962
+ path28,
2959
2963
  expected,
2960
2964
  `array with ${value.length} items`,
2961
- `Expected ${expected} at ${formatPath(path26)}`
2965
+ `Expected ${expected} at ${formatPath(path28)}`
2962
2966
  );
2963
2967
  }
2964
2968
  if (schema.maxItems !== void 0 && value.length > schema.maxItems) {
2965
2969
  const expected = `array with at most ${schema.maxItems} items`;
2966
2970
  addIssue(
2967
2971
  state,
2968
- path26,
2972
+ path28,
2969
2973
  expected,
2970
2974
  `array with ${value.length} items`,
2971
- `Expected ${expected} at ${formatPath(path26)}`
2975
+ `Expected ${expected} at ${formatPath(path28)}`
2972
2976
  );
2973
2977
  }
2974
2978
  const nextValue = value.map((item, index) => {
2975
- const result = walkSchema(schema.item, item, [...path26, String(index)], state);
2979
+ const result = walkSchema(schema.item, item, [...path28, String(index)], state);
2976
2980
  return result.present ? result.value : item;
2977
2981
  });
2978
2982
  return { present: true, value: nextValue };
2979
2983
  }
2980
- function walkObject(schema, value, path26, state, injectedProperties = {}) {
2984
+ function walkObject(schema, value, path28, state, injectedProperties = {}) {
2981
2985
  if (!isPlainRecord(value)) {
2982
- addExpectedIssue(state, path26, "object", value);
2986
+ addExpectedIssue(state, path28, "object", value);
2983
2987
  return { present: true, value };
2984
2988
  }
2985
2989
  const nextValue = {};
2986
2990
  const allowedKeys = /* @__PURE__ */ new Set([...Object.keys(schema.shape), ...Object.keys(injectedProperties)]);
2987
2991
  for (const [key2, propertySchema] of Object.entries(schema.shape)) {
2988
2992
  const propertyValue = Object.hasOwn(value, key2) ? value[key2] : missingValue;
2989
- const result = walkSchema(propertySchema, propertyValue, [...path26, key2], state);
2993
+ const result = walkSchema(propertySchema, propertyValue, [...path28, key2], state);
2990
2994
  if (result.present) {
2991
2995
  setOwnValue(nextValue, key2, result.value);
2992
2996
  }
@@ -3005,18 +3009,18 @@ function walkObject(schema, value, path26, state, injectedProperties = {}) {
3005
3009
  if (schema.additionalProperties === true) {
3006
3010
  setOwnValue(nextValue, key2, propertyValue);
3007
3011
  } else {
3008
- addUnexpectedPropertyIssue(state, [...path26, key2]);
3012
+ addUnexpectedPropertyIssue(state, [...path28, key2]);
3009
3013
  }
3010
3014
  }
3011
3015
  return { present: true, value: nextValue };
3012
3016
  }
3013
- function walkOneOf(schema, value, path26, state) {
3017
+ function walkOneOf(schema, value, path28, state) {
3014
3018
  if (!isPlainRecord(value)) {
3015
- addExpectedIssue(state, path26, "object", value);
3019
+ addExpectedIssue(state, path28, "object", value);
3016
3020
  return { present: true, value };
3017
3021
  }
3018
3022
  const discriminatorValue = value[schema.discriminator];
3019
- const discriminatorPath = [...path26, schema.discriminator];
3023
+ const discriminatorPath = [...path28, schema.discriminator];
3020
3024
  const branchValues = Object.keys(schema.branches);
3021
3025
  const expected = `one of ${branchValues.join(", ")}`;
3022
3026
  if (!Object.hasOwn(value, schema.discriminator)) {
@@ -3025,7 +3029,7 @@ function walkOneOf(schema, value, path26, state) {
3025
3029
  discriminatorPath,
3026
3030
  expected,
3027
3031
  "missing",
3028
- `Missing discriminator "${schema.discriminator}" at ${formatPath(path26)}. Expected one of: ${branchValues.join(", ")}.`
3032
+ `Missing discriminator "${schema.discriminator}" at ${formatPath(path28)}. Expected one of: ${branchValues.join(", ")}.`
3029
3033
  );
3030
3034
  return { present: true, value };
3031
3035
  }
@@ -3039,21 +3043,21 @@ function walkOneOf(schema, value, path26, state) {
3039
3043
  );
3040
3044
  return { present: true, value };
3041
3045
  }
3042
- return walkObject(schema.branches[discriminatorValue], value, path26, state, {
3046
+ return walkObject(schema.branches[discriminatorValue], value, path28, state, {
3043
3047
  [schema.discriminator]: discriminatorValue
3044
3048
  });
3045
3049
  }
3046
- function walkUnion(schema, value, path26, state) {
3050
+ function walkUnion(schema, value, path28, state) {
3047
3051
  if (isPlainRecord(value)) {
3048
3052
  const candidateBranches = schema.branches.filter((branch) => hasRequiredKeys(branch, value));
3049
3053
  if (candidateBranches.length === 1) {
3050
- return walkObject(candidateBranches[0], value, path26, state);
3054
+ return walkObject(candidateBranches[0], value, path28, state);
3051
3055
  }
3052
3056
  }
3053
3057
  const matches = [];
3054
3058
  for (const branch of schema.branches) {
3055
3059
  const branchState = { issues: [] };
3056
- const result = walkObject(branch, value, path26, branchState);
3060
+ const result = walkObject(branch, value, path28, branchState);
3057
3061
  if (branchState.issues.length === 0 && result.present) {
3058
3062
  matches.push({ fingerprint: getRequiredKeyFingerprint(branch), value: result.value });
3059
3063
  }
@@ -3065,19 +3069,19 @@ function walkUnion(schema, value, path26, state) {
3065
3069
  const branchDescriptions = schema.branches.map((branch) => getRequiredKeyFingerprint(branch));
3066
3070
  addIssueWithMessage(
3067
3071
  state,
3068
- path26,
3072
+ path28,
3069
3073
  "exactly one union branch",
3070
3074
  "0 matching branches",
3071
- `No union branch matched at ${formatPath(path26)}. Tried ${schema.branches.length} branches. Expected one of: ${branchDescriptions.join(" | ")}.`
3075
+ `No union branch matched at ${formatPath(path28)}. Tried ${schema.branches.length} branches. Expected one of: ${branchDescriptions.join(" | ")}.`
3072
3076
  );
3073
3077
  return { present: true, value };
3074
3078
  }
3075
3079
  addIssueWithMessage(
3076
3080
  state,
3077
- path26,
3081
+ path28,
3078
3082
  "exactly one union branch",
3079
3083
  `${matches.length} matching branches`,
3080
- `Expected exactly one union branch at ${formatPath(path26)}, but matched more than one branch: ${matches.map((match) => match.fingerprint).join(" | ")}`
3084
+ `Expected exactly one union branch at ${formatPath(path28)}, but matched more than one branch: ${matches.map((match) => match.fingerprint).join(" | ")}`
3081
3085
  );
3082
3086
  return { present: true, value };
3083
3087
  }
@@ -3089,25 +3093,25 @@ function hasRequiredKeys(schema, value) {
3089
3093
  }
3090
3094
  return true;
3091
3095
  }
3092
- function walkRecord(schema, value, path26, state) {
3096
+ function walkRecord(schema, value, path28, state) {
3093
3097
  if (!isPlainRecord(value)) {
3094
- addExpectedIssue(state, path26, "object", value);
3098
+ addExpectedIssue(state, path28, "object", value);
3095
3099
  return { present: true, value };
3096
3100
  }
3097
3101
  const nextValue = {};
3098
3102
  for (const [key2, propertyValue] of Object.entries(value)) {
3099
- const result = walkSchema(schema.value, propertyValue, [...path26, key2], state);
3103
+ const result = walkSchema(schema.value, propertyValue, [...path28, key2], state);
3100
3104
  if (result.present) {
3101
3105
  setOwnValue(nextValue, key2, result.value);
3102
3106
  }
3103
3107
  }
3104
3108
  return { present: true, value: nextValue };
3105
3109
  }
3106
- function walkJson(value, path26, state) {
3110
+ function walkJson(value, path28, state) {
3107
3111
  if (isJsonValue(value)) {
3108
3112
  return { present: true, value };
3109
3113
  }
3110
- addExpectedIssue(state, path26, "JSON value", value);
3114
+ addExpectedIssue(state, path28, "JSON value", value);
3111
3115
  return { present: true, value };
3112
3116
  }
3113
3117
  function getDefault(schema) {
@@ -3185,45 +3189,45 @@ function expectedFor(schema) {
3185
3189
  return expectedFor(schema.inner);
3186
3190
  }
3187
3191
  }
3188
- function addExpectedIssue(state, path26, expected, value) {
3192
+ function addExpectedIssue(state, path28, expected, value) {
3189
3193
  addIssue(
3190
3194
  state,
3191
- path26,
3195
+ path28,
3192
3196
  expected,
3193
3197
  receivedType(value),
3194
- `Expected ${expected} at ${formatPath(path26)}`
3198
+ `Expected ${expected} at ${formatPath(path28)}`
3195
3199
  );
3196
3200
  }
3197
- function addUnexpectedPropertyIssue(state, path26) {
3201
+ function addUnexpectedPropertyIssue(state, path28) {
3198
3202
  addIssue(
3199
3203
  state,
3200
- path26,
3204
+ path28,
3201
3205
  "no additional properties",
3202
3206
  "unknown property",
3203
- `Unexpected property ${formatPath(path26)}`
3207
+ `Unexpected property ${formatPath(path28)}`
3204
3208
  );
3205
3209
  }
3206
- function addIssue(state, path26, expected, received, _message) {
3210
+ function addIssue(state, path28, expected, received, _message) {
3207
3211
  state.issues.push({
3208
- path: path26,
3212
+ path: path28,
3209
3213
  expected,
3210
3214
  received,
3211
- message: formatIssueMessage(expected, path26, received)
3215
+ message: formatIssueMessage(expected, path28, received)
3212
3216
  });
3213
3217
  }
3214
- function addIssueWithMessage(state, path26, expected, received, message2) {
3218
+ function addIssueWithMessage(state, path28, expected, received, message2) {
3215
3219
  state.issues.push({
3216
- path: path26,
3220
+ path: path28,
3217
3221
  expected,
3218
3222
  received,
3219
3223
  message: message2
3220
3224
  });
3221
3225
  }
3222
- function formatIssueMessage(expected, path26, received) {
3223
- return `Expected ${expected} at ${formatPath(path26)}, got ${received}`;
3226
+ function formatIssueMessage(expected, path28, received) {
3227
+ return `Expected ${expected} at ${formatPath(path28)}, got ${received}`;
3224
3228
  }
3225
- function formatPath(path26) {
3226
- return path26.length === 0 ? "value" : path26.join(".");
3229
+ function formatPath(path28) {
3230
+ return path28.length === 0 ? "value" : path28.join(".");
3227
3231
  }
3228
3232
  function compilePattern(pattern) {
3229
3233
  try {
@@ -7903,13 +7907,13 @@ function formatAvailableApprovalCommandPaths(root) {
7903
7907
  }
7904
7908
  function enumerateApprovalCommandPaths(root) {
7905
7909
  const paths = [];
7906
- const visit = (node, path26) => {
7910
+ const visit = (node, path28) => {
7907
7911
  if (node.kind === "command") {
7908
- paths.push(path26.join("."));
7912
+ paths.push(path28.join("."));
7909
7913
  return;
7910
7914
  }
7911
7915
  for (const child of getVisibleCliChildren(node)) {
7912
- visit(child, [...path26, child.name]);
7916
+ visit(child, [...path28, child.name]);
7913
7917
  }
7914
7918
  };
7915
7919
  if (root.kind === "command") {
@@ -7946,21 +7950,21 @@ function createHandlerContext(command, params17) {
7946
7950
  }
7947
7951
  function createFs() {
7948
7952
  return {
7949
- readFile: async (path26, encoding = "utf8") => readFile3(path26, { encoding }),
7950
- writeFile: async (path26, contents, options) => {
7951
- await writeFile2(path26, contents, options);
7953
+ readFile: async (path28, encoding = "utf8") => readFile3(path28, { encoding }),
7954
+ writeFile: async (path28, contents, options) => {
7955
+ await writeFile2(path28, contents, options);
7952
7956
  },
7953
- exists: async (path26) => {
7957
+ exists: async (path28) => {
7954
7958
  try {
7955
- await access(path26);
7959
+ await access(path28);
7956
7960
  return true;
7957
7961
  } catch {
7958
7962
  return false;
7959
7963
  }
7960
7964
  },
7961
- lstat: async (path26) => lstat(path26),
7965
+ lstat: async (path28) => lstat(path28),
7962
7966
  rename: async (fromPath, toPath) => rename(fromPath, toPath),
7963
- unlink: async (path26) => unlink(path26)
7967
+ unlink: async (path28) => unlink(path28)
7964
7968
  };
7965
7969
  }
7966
7970
  function createEnv(values = process.env) {
@@ -11955,13 +11959,13 @@ function convertJsonSchema(schema) {
11955
11959
  }
11956
11960
  return convertSchema(schema, schema, []);
11957
11961
  }
11958
- function convertSchema(schema, root, path26) {
11959
- const resolvedSchema = resolveReferencedSchema(schema, root, path26);
11962
+ function convertSchema(schema, root, path28) {
11963
+ const resolvedSchema = resolveReferencedSchema(schema, root, path28);
11960
11964
  const normalizedSchema = normalizeNullability(resolvedSchema);
11961
11965
  const composition = getComposition(normalizedSchema.schema);
11962
11966
  if (Array.isArray(normalizedSchema.schema.type)) {
11963
11967
  throw new Error(
11964
- `JSON Schema "${formatJsonSchemaPath(path26)}" has an unsupported type "${formatJsonSchemaType(
11968
+ `JSON Schema "${formatJsonSchemaPath(path28)}" has an unsupported type "${formatJsonSchemaType(
11965
11969
  normalizedSchema.schema.type
11966
11970
  )}". Supported: string, number, integer, boolean, array, object.`
11967
11971
  );
@@ -11973,13 +11977,13 @@ function convertSchema(schema, root, path26) {
11973
11977
  return convertEnumSchema(resolvedSchema, normalizedSchema.nullable);
11974
11978
  }
11975
11979
  if (composition !== void 0) {
11976
- return convertCompositionSchema(normalizedSchema.schema, root, normalizedSchema.nullable, path26);
11980
+ return convertCompositionSchema(normalizedSchema.schema, root, normalizedSchema.nullable, path28);
11977
11981
  }
11978
11982
  if (isRecordSchema(normalizedSchema.schema)) {
11979
11983
  return applyMetadata(
11980
11984
  S.Record(
11981
11985
  convertSchema(normalizedSchema.schema.additionalProperties, root, [
11982
- ...path26,
11986
+ ...path28,
11983
11987
  "additionalProperties"
11984
11988
  ])
11985
11989
  ),
@@ -12028,12 +12032,12 @@ function convertSchema(schema, root, path26) {
12028
12032
  if (normalizedSchema.schema.items === void 0) {
12029
12033
  throw new Error(
12030
12034
  `JSON Schema "${formatJsonSchemaPath(
12031
- path26
12035
+ path28
12032
12036
  )}" is an array but is missing the "items" field. Add "items": { ... } to declare the element type.`
12033
12037
  );
12034
12038
  }
12035
12039
  return S.Array(
12036
- convertSchema(normalizedSchema.schema.items, root, [...path26, "items"]),
12040
+ convertSchema(normalizedSchema.schema.items, root, [...path28, "items"]),
12037
12041
  createCommonOptions(
12038
12042
  normalizedSchema.schema,
12039
12043
  normalizedSchema.nullable,
@@ -12043,7 +12047,7 @@ function convertSchema(schema, root, path26) {
12043
12047
  case "object":
12044
12048
  return convertObjectSchema(normalizedSchema.schema, root, {
12045
12049
  nullable: normalizedSchema.nullable,
12046
- path: path26
12050
+ path: path28
12047
12051
  });
12048
12052
  case "null":
12049
12053
  return applyMetadata(S.Json(), normalizedSchema.schema, {
@@ -12058,12 +12062,12 @@ function convertSchema(schema, root, path26) {
12058
12062
  }
12059
12063
  throw new Error(
12060
12064
  `JSON Schema "${formatJsonSchemaPath(
12061
- path26
12065
+ path28
12062
12066
  )}" must declare one of: "type", "enum", "const", "oneOf", "anyOf", or "allOf".`
12063
12067
  );
12064
12068
  }
12065
12069
  throw new Error(
12066
- `JSON Schema "${formatJsonSchemaPath(path26)}" has an unsupported type "${formatJsonSchemaType(
12070
+ `JSON Schema "${formatJsonSchemaPath(path28)}" has an unsupported type "${formatJsonSchemaType(
12067
12071
  normalizedSchema.schema.type
12068
12072
  )}". Supported: string, number, integer, boolean, array, object.`
12069
12073
  );
@@ -12107,21 +12111,21 @@ function convertEnumSchema(schema, nullable) {
12107
12111
  )
12108
12112
  });
12109
12113
  }
12110
- function convertCompositionSchema(schema, root, nullable, path26) {
12114
+ function convertCompositionSchema(schema, root, nullable, path28) {
12111
12115
  const composition = getComposition(schema);
12112
12116
  const branchSchemas = composition?.branches ?? [];
12113
12117
  const keyword = composition?.keyword ?? "oneOf";
12114
12118
  const branches = branchSchemas.map(
12115
- (branch, index) => resolveReferencedSchema(branch, root, [...path26, keyword, String(index)])
12119
+ (branch, index) => resolveReferencedSchema(branch, root, [...path28, keyword, String(index)])
12116
12120
  );
12117
- const discriminator = findDiscriminator(branches, root, path26);
12121
+ const discriminator = findDiscriminator(branches, root, path28);
12118
12122
  if (discriminator !== void 0) {
12119
12123
  const convertedBranches = Object.fromEntries(
12120
12124
  branches.map((branch, index) => [
12121
12125
  getDiscriminatorLiteral(branch, discriminator, root),
12122
12126
  convertObjectSchema(branch, root, {
12123
12127
  omitProperty: discriminator,
12124
- path: [...path26, keyword, String(index)]
12128
+ path: [...path28, keyword, String(index)]
12125
12129
  })
12126
12130
  ])
12127
12131
  );
@@ -12140,7 +12144,7 @@ function convertCompositionSchema(schema, root, nullable, path26) {
12140
12144
  S.Union(
12141
12145
  branches.map(
12142
12146
  (branch, index) => convertObjectSchema(branch, root, {
12143
- path: [...path26, keyword, String(index)]
12147
+ path: [...path28, keyword, String(index)]
12144
12148
  })
12145
12149
  )
12146
12150
  ),
@@ -12254,11 +12258,11 @@ function getComposition(schema) {
12254
12258
  }
12255
12259
  return void 0;
12256
12260
  }
12257
- function formatJsonSchemaPath(path26) {
12258
- if (path26.length === 0) {
12261
+ function formatJsonSchemaPath(path28) {
12262
+ if (path28.length === 0) {
12259
12263
  return "#";
12260
12264
  }
12261
- return `#/${path26.map(escapeJsonPointerSegment).join("/")}`;
12265
+ return `#/${path28.map(escapeJsonPointerSegment).join("/")}`;
12262
12266
  }
12263
12267
  function formatJsonSchemaType(type2) {
12264
12268
  return Array.isArray(type2) ? JSON.stringify(type2) : String(type2);
@@ -12274,11 +12278,11 @@ function isRecordSchema(schema) {
12274
12278
  const propertyKeys = Object.keys(schema.properties ?? {});
12275
12279
  return schema.type === "object" && propertyKeys.length === 0 && typeof schema.additionalProperties === "object" && schema.additionalProperties !== null;
12276
12280
  }
12277
- function findDiscriminator(branches, root, path26) {
12281
+ function findDiscriminator(branches, root, path28) {
12278
12282
  const [firstBranch] = branches;
12279
12283
  if (firstBranch === void 0) {
12280
12284
  throw new Error(
12281
- `JSON Schema "${formatJsonSchemaPath(path26)}" uses oneOf/anyOf/allOf but has no branches.`
12285
+ `JSON Schema "${formatJsonSchemaPath(path28)}" uses oneOf/anyOf/allOf but has no branches.`
12282
12286
  );
12283
12287
  }
12284
12288
  const candidateKeys = Object.keys(firstBranch.properties ?? {});
@@ -12318,19 +12322,19 @@ function getDiscriminatorLiteral(branch, key2, root) {
12318
12322
  }
12319
12323
  return void 0;
12320
12324
  }
12321
- function resolveReferencedSchema(schema, root, path26) {
12325
+ function resolveReferencedSchema(schema, root, path28) {
12322
12326
  if (schema.$ref === void 0) {
12323
12327
  return schema;
12324
12328
  }
12325
12329
  const resolvedTarget = resolveLocalRef(root, schema.$ref);
12326
12330
  if (resolvedTarget === void 0) {
12327
12331
  throw new Error(
12328
- `JSON Schema "${formatJsonSchemaPath(path26)}" uses "$ref": ${schema.$ref}. toolcraft only supports internal refs like "#/components/schemas/Foo".`
12332
+ `JSON Schema "${formatJsonSchemaPath(path28)}" uses "$ref": ${schema.$ref}. toolcraft only supports internal refs like "#/components/schemas/Foo".`
12329
12333
  );
12330
12334
  }
12331
12335
  const { $ref: ignoredRef, ...siblingKeywords } = schema;
12332
12336
  void ignoredRef;
12333
- const resolvedSchema = resolveReferencedSchema(resolvedTarget, root, path26);
12337
+ const resolvedSchema = resolveReferencedSchema(resolvedTarget, root, path28);
12334
12338
  if (Object.keys(siblingKeywords).length === 0) {
12335
12339
  return resolvedSchema;
12336
12340
  }
@@ -12354,9 +12358,9 @@ function mergeJsonSchemas(base, overlay) {
12354
12358
  ...mergedRequired === void 0 ? {} : { required: mergedRequired }
12355
12359
  };
12356
12360
  }
12357
- function hasSelfReferencingRef(schema, root, path26 = "#", activePaths = /* @__PURE__ */ new Set()) {
12361
+ function hasSelfReferencingRef(schema, root, path28 = "#", activePaths = /* @__PURE__ */ new Set()) {
12358
12362
  const nextActivePaths = new Set(activePaths);
12359
- nextActivePaths.add(path26);
12363
+ nextActivePaths.add(path28);
12360
12364
  const localRefPath = getLocalRefPath(schema.$ref);
12361
12365
  if (localRefPath !== void 0) {
12362
12366
  if (nextActivePaths.has(localRefPath)) {
@@ -12367,13 +12371,13 @@ function hasSelfReferencingRef(schema, root, path26 = "#", activePaths = /* @__P
12367
12371
  return true;
12368
12372
  }
12369
12373
  }
12370
- if (schema.items !== void 0 && hasSelfReferencingRef(schema.items, root, `${path26}/items`, nextActivePaths)) {
12374
+ if (schema.items !== void 0 && hasSelfReferencingRef(schema.items, root, `${path28}/items`, nextActivePaths)) {
12371
12375
  return true;
12372
12376
  }
12373
12377
  if (typeof schema.additionalProperties === "object" && schema.additionalProperties !== null && hasSelfReferencingRef(
12374
12378
  schema.additionalProperties,
12375
12379
  root,
12376
- `${path26}/additionalProperties`,
12380
+ `${path28}/additionalProperties`,
12377
12381
  nextActivePaths
12378
12382
  )) {
12379
12383
  return true;
@@ -12382,7 +12386,7 @@ function hasSelfReferencingRef(schema, root, path26 = "#", activePaths = /* @__P
12382
12386
  if (hasSelfReferencingRef(
12383
12387
  childSchema,
12384
12388
  root,
12385
- `${path26}/properties/${escapeJsonPointerSegment(key2)}`,
12389
+ `${path28}/properties/${escapeJsonPointerSegment(key2)}`,
12386
12390
  nextActivePaths
12387
12391
  )) {
12388
12392
  return true;
@@ -12392,24 +12396,24 @@ function hasSelfReferencingRef(schema, root, path26 = "#", activePaths = /* @__P
12392
12396
  if (hasSelfReferencingRef(
12393
12397
  childSchema,
12394
12398
  root,
12395
- `${path26}/$defs/${escapeJsonPointerSegment(key2)}`,
12399
+ `${path28}/$defs/${escapeJsonPointerSegment(key2)}`,
12396
12400
  nextActivePaths
12397
12401
  )) {
12398
12402
  return true;
12399
12403
  }
12400
12404
  }
12401
12405
  for (const [index, childSchema] of (schema.oneOf ?? []).entries()) {
12402
- if (hasSelfReferencingRef(childSchema, root, `${path26}/oneOf/${index}`, nextActivePaths)) {
12406
+ if (hasSelfReferencingRef(childSchema, root, `${path28}/oneOf/${index}`, nextActivePaths)) {
12403
12407
  return true;
12404
12408
  }
12405
12409
  }
12406
12410
  for (const [index, childSchema] of (schema.anyOf ?? []).entries()) {
12407
- if (hasSelfReferencingRef(childSchema, root, `${path26}/anyOf/${index}`, nextActivePaths)) {
12411
+ if (hasSelfReferencingRef(childSchema, root, `${path28}/anyOf/${index}`, nextActivePaths)) {
12408
12412
  return true;
12409
12413
  }
12410
12414
  }
12411
12415
  for (const [index, childSchema] of (schema.allOf ?? []).entries()) {
12412
- if (hasSelfReferencingRef(childSchema, root, `${path26}/allOf/${index}`, nextActivePaths)) {
12416
+ if (hasSelfReferencingRef(childSchema, root, `${path28}/allOf/${index}`, nextActivePaths)) {
12413
12417
  return true;
12414
12418
  }
12415
12419
  }
@@ -12425,14 +12429,14 @@ function getLocalRefPath(ref) {
12425
12429
  return ref.startsWith("#/") ? ref : void 0;
12426
12430
  }
12427
12431
  function resolveLocalRef(root, ref) {
12428
- const path26 = getLocalRefPath(ref);
12429
- if (path26 === void 0) {
12432
+ const path28 = getLocalRefPath(ref);
12433
+ if (path28 === void 0) {
12430
12434
  return void 0;
12431
12435
  }
12432
- if (path26 === "#") {
12436
+ if (path28 === "#") {
12433
12437
  return root;
12434
12438
  }
12435
- const segments = path26.slice(2).split("/").map(unescapeJsonPointerSegment);
12439
+ const segments = path28.slice(2).split("/").map(unescapeJsonPointerSegment);
12436
12440
  let current = root;
12437
12441
  for (const segment of segments) {
12438
12442
  if (Array.isArray(current)) {
@@ -13573,23 +13577,23 @@ function extractFieldErrors(body) {
13573
13577
  const flattened = candidates.flatMap((candidate) => flattenFieldErrors(candidate, []));
13574
13578
  return flattened.length === 0 ? void 0 : flattened;
13575
13579
  }
13576
- function flattenFieldErrors(value, path26) {
13580
+ function flattenFieldErrors(value, path28) {
13577
13581
  if (typeof value === "string") {
13578
- return [{ path: formatPath2(path26), message: value }];
13582
+ return [{ path: formatPath2(path28), message: value }];
13579
13583
  }
13580
13584
  if (Array.isArray(value)) {
13581
13585
  if (value.every((entry) => typeof entry === "string")) {
13582
- return value.map((message2) => ({ path: formatPath2(path26), message: message2 }));
13586
+ return value.map((message2) => ({ path: formatPath2(path28), message: message2 }));
13583
13587
  }
13584
- return value.flatMap((entry, index) => flattenFieldErrors(entry, [...path26, String(index)]));
13588
+ return value.flatMap((entry, index) => flattenFieldErrors(entry, [...path28, String(index)]));
13585
13589
  }
13586
13590
  if (!isPlainObject4(value)) {
13587
13591
  return [];
13588
13592
  }
13589
- return Object.entries(value).flatMap(([key2, nested]) => flattenFieldErrors(nested, [...path26, key2]));
13593
+ return Object.entries(value).flatMap(([key2, nested]) => flattenFieldErrors(nested, [...path28, key2]));
13590
13594
  }
13591
- function formatPath2(path26) {
13592
- return path26.length === 0 ? "error" : path26.join(".");
13595
+ function formatPath2(path28) {
13596
+ return path28.length === 0 ? "error" : path28.join(".");
13593
13597
  }
13594
13598
  function extractFirstString(body, fields) {
13595
13599
  if (!isPlainObject4(body)) {
@@ -14159,11 +14163,11 @@ function formatSegment(segment, casing) {
14159
14163
  const separator = casing === "snake" ? "_" : "-";
14160
14164
  return splitWords3(segment).join(separator);
14161
14165
  }
14162
- function toOptionFlag(path26, casing) {
14163
- return `--${path26.map((segment) => formatSegment(segment, casing)).join(".")}`;
14166
+ function toOptionFlag(path28, casing) {
14167
+ return `--${path28.map((segment) => formatSegment(segment, casing)).join(".")}`;
14164
14168
  }
14165
- function toOptionAttribute(path26, casing) {
14166
- return path26.map((segment) => {
14169
+ function toOptionAttribute(path28, casing) {
14170
+ return path28.map((segment) => {
14167
14171
  const formatted = formatSegment(segment, casing);
14168
14172
  if (casing === "snake") {
14169
14173
  return formatted;
@@ -14174,23 +14178,23 @@ function toOptionAttribute(path26, casing) {
14174
14178
  ).join("");
14175
14179
  }).join(".");
14176
14180
  }
14177
- function toDisplayPath(path26) {
14178
- return path26.join(".");
14181
+ function toDisplayPath(path28) {
14182
+ return path28.join(".");
14179
14183
  }
14180
- function toUnionKindControlPath(path26) {
14181
- if (path26.length === 0) {
14184
+ function toUnionKindControlPath(path28) {
14185
+ if (path28.length === 0) {
14182
14186
  return ["kind"];
14183
14187
  }
14184
- const head = path26.slice(0, -1);
14185
- const tail = path26[path26.length - 1] ?? "";
14188
+ const head = path28.slice(0, -1);
14189
+ const tail = path28[path28.length - 1] ?? "";
14186
14190
  return [...head, `${tail}Kind`];
14187
14191
  }
14188
- function toUnionKindDisplayPath(path26) {
14189
- if (path26.length === 0) {
14192
+ function toUnionKindDisplayPath(path28) {
14193
+ if (path28.length === 0) {
14190
14194
  return "kind";
14191
14195
  }
14192
- const head = path26.slice(0, -1);
14193
- const tail = path26[path26.length - 1] ?? "";
14196
+ const head = path28.slice(0, -1);
14197
+ const tail = path28[path28.length - 1] ?? "";
14194
14198
  return [...head, `${tail}-kind`].join(".");
14195
14199
  }
14196
14200
  function createSyntheticEnumSchema(values) {
@@ -14206,14 +14210,14 @@ function getRequiredBranchFingerprint(branch, casing) {
14206
14210
  const requiredKeys = Object.entries(branch.shape).filter(([, schema]) => schema.kind !== "optional").map(([key2]) => formatSegment(key2, casing)).sort();
14207
14211
  return requiredKeys.join("+");
14208
14212
  }
14209
- function collectFields(schema, casing, globalLongOptionFlags, path26 = [], inheritedOptional = false, variantContext) {
14213
+ function collectFields(schema, casing, globalLongOptionFlags, path28 = [], inheritedOptional = false, variantContext) {
14210
14214
  const collected = {
14211
14215
  dynamicFields: [],
14212
14216
  fields: [],
14213
14217
  variants: []
14214
14218
  };
14215
14219
  for (const [key2, rawChildSchema] of Object.entries(schema.shape)) {
14216
- const nextPath = [...path26, key2];
14220
+ const nextPath = [...path28, key2];
14217
14221
  const runtimeOptional = inheritedOptional || rawChildSchema.kind === "optional";
14218
14222
  const childSchema = unwrapOptional2(rawChildSchema);
14219
14223
  const requiredWhenActive = rawChildSchema.kind !== "optional" && childSchema.default === void 0;
@@ -14399,9 +14403,9 @@ function collectFields(schema, casing, globalLongOptionFlags, path26 = [], inher
14399
14403
  }
14400
14404
  return collected;
14401
14405
  }
14402
- function toCommanderOptionAttribute(path26, casing, globalLongOptionFlags) {
14403
- const optionAttribute = toOptionAttribute(path26, casing);
14404
- const optionFlag = toOptionFlag(path26, casing);
14406
+ function toCommanderOptionAttribute(path28, casing, globalLongOptionFlags) {
14407
+ const optionAttribute = toOptionAttribute(path28, casing);
14408
+ const optionFlag = toOptionFlag(path28, casing);
14405
14409
  if (!globalLongOptionFlags.has(optionFlag)) {
14406
14410
  return optionAttribute;
14407
14411
  }
@@ -15731,10 +15735,10 @@ function writeCLIDiagnosticEvent(event) {
15731
15735
  process.stderr.write(`${event.message}
15732
15736
  `);
15733
15737
  }
15734
- function setNestedValue(target, path26, value) {
15738
+ function setNestedValue(target, path28, value) {
15735
15739
  let cursor2 = target;
15736
- for (let index = 0; index < path26.length - 1; index += 1) {
15737
- const segment = path26[index] ?? "";
15740
+ for (let index = 0; index < path28.length - 1; index += 1) {
15741
+ const segment = path28[index] ?? "";
15738
15742
  const existing = Object.prototype.hasOwnProperty.call(cursor2, segment) ? cursor2[segment] : void 0;
15739
15743
  if (typeof existing === "object" && existing !== null) {
15740
15744
  cursor2 = existing;
@@ -15749,7 +15753,7 @@ function setNestedValue(target, path26, value) {
15749
15753
  });
15750
15754
  cursor2 = next;
15751
15755
  }
15752
- const leaf = path26[path26.length - 1];
15756
+ const leaf = path28[path28.length - 1];
15753
15757
  if (leaf !== void 0) {
15754
15758
  Object.defineProperty(cursor2, leaf, {
15755
15759
  value,
@@ -15897,21 +15901,21 @@ async function withOutputFormat2(output, fn) {
15897
15901
  }
15898
15902
  function createFs2() {
15899
15903
  return {
15900
- readFile: async (path26, encoding = "utf8") => readFile5(path26, { encoding }),
15901
- writeFile: async (path26, contents, options) => {
15902
- await writeFile5(path26, contents, options);
15904
+ readFile: async (path28, encoding = "utf8") => readFile5(path28, { encoding }),
15905
+ writeFile: async (path28, contents, options) => {
15906
+ await writeFile5(path28, contents, options);
15903
15907
  },
15904
- exists: async (path26) => {
15908
+ exists: async (path28) => {
15905
15909
  try {
15906
- await access2(path26);
15910
+ await access2(path28);
15907
15911
  return true;
15908
15912
  } catch {
15909
15913
  return false;
15910
15914
  }
15911
15915
  },
15912
- lstat: async (path26) => lstat3(path26),
15916
+ lstat: async (path28) => lstat3(path28),
15913
15917
  rename: async (fromPath, toPath) => rename3(fromPath, toPath),
15914
- unlink: async (path26) => unlink3(path26)
15918
+ unlink: async (path28) => unlink3(path28)
15915
15919
  };
15916
15920
  }
15917
15921
  function createEnv2(values = process.env) {
@@ -15927,9 +15931,9 @@ function isPlainObject5(value) {
15927
15931
  function hasFieldValue(value) {
15928
15932
  return value !== void 0;
15929
15933
  }
15930
- function hasNestedField(fields, path26) {
15934
+ function hasNestedField(fields, path28) {
15931
15935
  return fields.some(
15932
- (field) => path26.length < field.path.length && path26.every((segment, index) => field.path[index] === segment)
15936
+ (field) => path28.length < field.path.length && path28.every((segment, index) => field.path[index] === segment)
15933
15937
  );
15934
15938
  }
15935
15939
  function describeExpectedPresetValue(schema) {
@@ -16058,9 +16062,9 @@ async function loadPresetValues(fields, presetPath) {
16058
16062
  }
16059
16063
  const fieldByPath = new Map(fields.map((field) => [field.displayPath, field]));
16060
16064
  const presetValues = {};
16061
- function visitObject(current, path26) {
16065
+ function visitObject(current, path28) {
16062
16066
  for (const [key2, value] of Object.entries(current)) {
16063
- const nextPath = [...path26, key2];
16067
+ const nextPath = [...path28, key2];
16064
16068
  const displayPath = toDisplayPath(nextPath);
16065
16069
  const field = fieldByPath.get(displayPath);
16066
16070
  if (field !== void 0) {
@@ -16453,8 +16457,8 @@ function validateServices(services) {
16453
16457
  }
16454
16458
  }
16455
16459
  }
16456
- function getNestedValue(target, path26) {
16457
- return path26.reduce(
16460
+ function getNestedValue(target, path28) {
16461
+ return path28.reduce(
16458
16462
  (current, segment) => current !== null && typeof current === "object" ? current[segment] : void 0,
16459
16463
  target
16460
16464
  );
@@ -19313,13 +19317,6 @@ function createTerminalPilotRuntime(options = {}) {
19313
19317
  }
19314
19318
  };
19315
19319
  }
19316
- async function closeSharedTerminalPilotRuntime() {
19317
- if (sharedRuntime === void 0) {
19318
- return;
19319
- }
19320
- await sharedRuntime.close();
19321
- sharedRuntime = void 0;
19322
- }
19323
19320
 
19324
19321
  // src/commands/close-session.ts
19325
19322
  var params = S.Object({
@@ -19909,22 +19906,22 @@ function prune(obj, shape) {
19909
19906
  }
19910
19907
  return { changed, result };
19911
19908
  }
19912
- function modifyAtPath(content, path26, value) {
19909
+ function modifyAtPath(content, path28, value) {
19913
19910
  const indent = detectIndent(content);
19914
19911
  const formattingOptions = {
19915
19912
  tabSize: indent === " " ? 1 : indent.length,
19916
19913
  insertSpaces: indent !== " ",
19917
19914
  eol: "\n"
19918
19915
  };
19919
- const edits = jsonc.modify(content, path26, value, { formattingOptions });
19916
+ const edits = jsonc.modify(content, path28, value, { formattingOptions });
19920
19917
  let result = jsonc.applyEdits(content, edits);
19921
19918
  if (!result.endsWith("\n")) {
19922
19919
  result += "\n";
19923
19920
  }
19924
19921
  return result;
19925
19922
  }
19926
- function removeAtPath(content, path26) {
19927
- return modifyAtPath(content, path26, void 0);
19923
+ function removeAtPath(content, path28) {
19924
+ return modifyAtPath(content, path28, void 0);
19928
19925
  }
19929
19926
  function serializeUpdate(content, current, next) {
19930
19927
  let result = content || "{}";
@@ -19934,15 +19931,15 @@ function serializeUpdate(content, current, next) {
19934
19931
  }
19935
19932
  return result;
19936
19933
  }
19937
- function applyObjectUpdate(content, path26, current, next) {
19934
+ function applyObjectUpdate(content, path28, current, next) {
19938
19935
  let result = content;
19939
19936
  for (const key2 of Object.keys(current)) {
19940
19937
  if (!hasConfigEntry(next, key2)) {
19941
- result = removeAtPath(result, [...path26, key2]);
19938
+ result = removeAtPath(result, [...path28, key2]);
19942
19939
  }
19943
19940
  }
19944
19941
  for (const [key2, nextValue] of Object.entries(next)) {
19945
- const nextPath = [...path26, key2];
19942
+ const nextPath = [...path28, key2];
19946
19943
  const hasCurrent = hasConfigEntry(current, key2);
19947
19944
  const currentValue = hasCurrent ? current[key2] : void 0;
19948
19945
  if (hasCurrent && isConfigObject(currentValue) && isConfigObject(nextValue)) {
@@ -20142,16 +20139,16 @@ function getConfigFormat(pathOrFormat) {
20142
20139
  }
20143
20140
  return formatRegistry[formatName];
20144
20141
  }
20145
- function detectFormat(path26) {
20146
- const ext = getExtension(path26);
20142
+ function detectFormat(path28) {
20143
+ const ext = getExtension(path28);
20147
20144
  return extensionMap[ext];
20148
20145
  }
20149
- function getExtension(path26) {
20150
- const lastDot = path26.lastIndexOf(".");
20146
+ function getExtension(path28) {
20147
+ const lastDot = path28.lastIndexOf(".");
20151
20148
  if (lastDot === -1) {
20152
20149
  return "";
20153
20150
  }
20154
- return path26.slice(lastDot).toLowerCase();
20151
+ return path28.slice(lastDot).toLowerCase();
20155
20152
  }
20156
20153
 
20157
20154
  // ../config-mutations/src/execution/path-utils.ts
@@ -22769,6 +22766,394 @@ function createTerminalPilotGroup() {
22769
22766
  }
22770
22767
  var terminalPilotGroup = Object.freeze(createTerminalPilotGroup());
22771
22768
 
22769
+ // src/commands/daemon-runtime.ts
22770
+ import { spawn as spawn7 } from "node:child_process";
22771
+ import { createHash as createHash5 } from "node:crypto";
22772
+ import { mkdir as mkdir3, unlink as unlink4 } from "node:fs/promises";
22773
+ import net from "node:net";
22774
+ import os4 from "node:os";
22775
+ import path24 from "node:path";
22776
+ var RUNTIME_DIR_ENV = "TERMINAL_PILOT_RUNTIME_DIR";
22777
+ var DAEMON_ARG = "__daemon";
22778
+ var START_TIMEOUT_MS = 5e3;
22779
+ var IDLE_SHUTDOWN_MS = 1e3;
22780
+ function isTerminalPilotDaemonArgv(argv) {
22781
+ return argv[2] === DAEMON_ARG;
22782
+ }
22783
+ async function runTerminalPilotDaemon() {
22784
+ const runtime = createTerminalPilotRuntime();
22785
+ const socketPath = resolveSocketPath(process.env);
22786
+ await mkdir3(path24.dirname(socketPath), { recursive: true });
22787
+ if (process.platform !== "win32") {
22788
+ await unlink4(socketPath).catch(() => void 0);
22789
+ }
22790
+ let idleTimer;
22791
+ const server = net.createServer((socket) => {
22792
+ let buffer = "";
22793
+ socket.setEncoding("utf8");
22794
+ socket.on("data", (chunk) => {
22795
+ buffer += chunk;
22796
+ while (true) {
22797
+ const newlineIndex = buffer.indexOf("\n");
22798
+ if (newlineIndex < 0) {
22799
+ break;
22800
+ }
22801
+ const line = buffer.slice(0, newlineIndex);
22802
+ buffer = buffer.slice(newlineIndex + 1);
22803
+ void handleRequestLine(runtime, line).then((response) => {
22804
+ socket.write(`${JSON.stringify(response)}
22805
+ `);
22806
+ scheduleIdleShutdown();
22807
+ });
22808
+ }
22809
+ });
22810
+ });
22811
+ async function shutdown() {
22812
+ if (idleTimer !== void 0) {
22813
+ clearTimeout(idleTimer);
22814
+ idleTimer = void 0;
22815
+ }
22816
+ await runtime.close();
22817
+ await new Promise((resolve) => {
22818
+ server.close(() => resolve());
22819
+ });
22820
+ if (process.platform !== "win32") {
22821
+ await unlink4(socketPath).catch(() => void 0);
22822
+ }
22823
+ }
22824
+ async function scheduleIdleShutdown() {
22825
+ if (idleTimer !== void 0) {
22826
+ clearTimeout(idleTimer);
22827
+ idleTimer = void 0;
22828
+ }
22829
+ const sessions = await runtime.listSessions();
22830
+ if (sessions.length > 0) {
22831
+ return;
22832
+ }
22833
+ idleTimer = setTimeout(() => {
22834
+ void shutdown().then(() => {
22835
+ process.exit(0);
22836
+ });
22837
+ }, IDLE_SHUTDOWN_MS);
22838
+ }
22839
+ await new Promise((resolve, reject) => {
22840
+ server.once("error", reject);
22841
+ server.listen(socketPath, () => {
22842
+ server.off("error", reject);
22843
+ resolve();
22844
+ });
22845
+ });
22846
+ }
22847
+ function createDaemonTerminalPilotRuntime() {
22848
+ let nextId = 1;
22849
+ async function request(method, params17) {
22850
+ await ensureDaemon();
22851
+ return sendRequest(method, params17, nextId++);
22852
+ }
22853
+ function proxySession(name, info2) {
22854
+ return {
22855
+ id: info2.id,
22856
+ command: info2.command,
22857
+ pid: info2.pid,
22858
+ exitCode: info2.exitCode,
22859
+ fill: async (text4) => {
22860
+ await request("sessionAction", { name, action: "fill", args: [text4] });
22861
+ },
22862
+ type: async (text4) => {
22863
+ await request("sessionAction", { name, action: "type", args: [text4] });
22864
+ },
22865
+ press: async (key2) => {
22866
+ await request("sessionAction", { name, action: "press", args: [key2] });
22867
+ },
22868
+ signal: async (signal) => {
22869
+ await request("sessionAction", { name, action: "signal", args: [signal] });
22870
+ },
22871
+ waitFor: async (pattern, options) => request("sessionAction", {
22872
+ name,
22873
+ action: "waitFor",
22874
+ args: [serializePattern(pattern), options]
22875
+ }),
22876
+ waitForExit: async (options) => request("sessionAction", { name, action: "waitForExit", args: [options] }),
22877
+ screen: async () => request("sessionAction", { name, action: "screen", args: [] }),
22878
+ history: async (options) => request("sessionAction", { name, action: "history", args: [options] }),
22879
+ resize: async (cols, rows) => {
22880
+ await request("sessionAction", { name, action: "resize", args: [cols, rows] });
22881
+ },
22882
+ close: async () => {
22883
+ const result = await request("closeSession", { name });
22884
+ return result.exitCode;
22885
+ }
22886
+ };
22887
+ }
22888
+ return {
22889
+ async createSession(params17, env) {
22890
+ const result = await request("createSession", {
22891
+ params: params17,
22892
+ envSession: env?.get(SESSION_ENV_VAR)
22893
+ });
22894
+ return { name: result.name, session: proxySession(result.name, result.session) };
22895
+ },
22896
+ async resolveSession(name, env) {
22897
+ const result = await request("resolveSession", {
22898
+ name,
22899
+ envSession: env?.get(SESSION_ENV_VAR)
22900
+ });
22901
+ return { name: result.name, session: proxySession(result.name, result.session) };
22902
+ },
22903
+ async closeSession(name, env) {
22904
+ return request("closeSession", {
22905
+ name,
22906
+ envSession: env?.get(SESSION_ENV_VAR)
22907
+ });
22908
+ },
22909
+ async listSessions() {
22910
+ const sessions = await request("listSessions");
22911
+ return sessions.map((entry) => ({
22912
+ name: entry.name,
22913
+ session: proxySession(entry.name, entry.session)
22914
+ }));
22915
+ },
22916
+ async close() {
22917
+ await request("shutdown").catch(() => void 0);
22918
+ }
22919
+ };
22920
+ }
22921
+ async function handleRequestLine(runtime, line) {
22922
+ let request;
22923
+ try {
22924
+ request = JSON.parse(line);
22925
+ } catch (error3) {
22926
+ return {
22927
+ id: 0,
22928
+ ok: false,
22929
+ error: { message: error3 instanceof Error ? error3.message : "Invalid request" }
22930
+ };
22931
+ }
22932
+ try {
22933
+ const result = await handleRequest(runtime, request);
22934
+ return { id: request.id, ok: true, result };
22935
+ } catch (error3) {
22936
+ return {
22937
+ id: request.id,
22938
+ ok: false,
22939
+ error: { message: error3 instanceof Error ? error3.message : String(error3) }
22940
+ };
22941
+ }
22942
+ }
22943
+ async function handleRequest(runtime, request) {
22944
+ const params17 = isRecord6(request.params) ? request.params : {};
22945
+ if (request.method === "ping") {
22946
+ return { ok: true };
22947
+ }
22948
+ if (request.method === "createSession") {
22949
+ const createParams = isRecord6(params17.params) ? params17.params : {};
22950
+ const namedSession = await runtime.createSession(
22951
+ createParams,
22952
+ envFromValue(params17.envSession)
22953
+ );
22954
+ return formatNamedSession(namedSession);
22955
+ }
22956
+ if (request.method === "resolveSession") {
22957
+ const namedSession = await runtime.resolveSession(
22958
+ optionalString2(params17.name),
22959
+ envFromValue(params17.envSession)
22960
+ );
22961
+ return formatNamedSession(namedSession);
22962
+ }
22963
+ if (request.method === "listSessions") {
22964
+ const sessions = await runtime.listSessions();
22965
+ return sessions.map(formatNamedSession);
22966
+ }
22967
+ if (request.method === "closeSession") {
22968
+ return runtime.closeSession(optionalString2(params17.name), envFromValue(params17.envSession));
22969
+ }
22970
+ if (request.method === "sessionAction") {
22971
+ return runSessionAction(runtime, params17);
22972
+ }
22973
+ if (request.method === "shutdown") {
22974
+ await runtime.close();
22975
+ process.exit(0);
22976
+ }
22977
+ throw new UserError(`Unknown terminal-pilot daemon method: ${request.method}`);
22978
+ }
22979
+ async function runSessionAction(runtime, params17) {
22980
+ const name = optionalString2(params17.name);
22981
+ const action = optionalString2(params17.action);
22982
+ const args = Array.isArray(params17.args) ? params17.args : [];
22983
+ const namedSession = await runtime.resolveSession(name);
22984
+ const session = namedSession.session;
22985
+ if (action === "fill") {
22986
+ await session.fill(String(args[0] ?? ""));
22987
+ return void 0;
22988
+ }
22989
+ if (action === "type") {
22990
+ await session.type(String(args[0] ?? ""));
22991
+ return void 0;
22992
+ }
22993
+ if (action === "press") {
22994
+ await session.press(String(args[0] ?? ""));
22995
+ return void 0;
22996
+ }
22997
+ if (action === "signal") {
22998
+ await session.signal(String(args[0] ?? ""));
22999
+ return void 0;
23000
+ }
23001
+ if (action === "waitFor") {
23002
+ return session.waitFor(deserializePattern(args[0]), optionalRecord(args[1]));
23003
+ }
23004
+ if (action === "waitForExit") {
23005
+ return session.waitForExit(optionalRecord(args[0]));
23006
+ }
23007
+ if (action === "screen") {
23008
+ const screen = await session.screen();
23009
+ return {
23010
+ lines: [...screen.lines],
23011
+ rawLines: [...screen.rawLines],
23012
+ cursor: { ...screen.cursor },
23013
+ size: { ...screen.size }
23014
+ };
23015
+ }
23016
+ if (action === "history") {
23017
+ return session.history(optionalRecord(args[0]));
23018
+ }
23019
+ if (action === "resize") {
23020
+ await session.resize(Number(args[0]), Number(args[1]));
23021
+ return void 0;
23022
+ }
23023
+ throw new UserError(`Unknown terminal-pilot session action: ${action ?? "<missing>"}`);
23024
+ }
23025
+ async function ensureDaemon() {
23026
+ try {
23027
+ await sendRequest("ping", void 0, 0, { start: false });
23028
+ return;
23029
+ } catch {
23030
+ }
23031
+ const socketPath = resolveSocketPath(process.env);
23032
+ await mkdir3(path24.dirname(socketPath), { recursive: true });
23033
+ if (process.platform !== "win32") {
23034
+ await unlink4(socketPath).catch(() => void 0);
23035
+ }
23036
+ const entryPoint = process.argv[1];
23037
+ if (typeof entryPoint !== "string" || entryPoint.length === 0) {
23038
+ throw new UserError("Cannot start terminal-pilot daemon: entrypoint is unknown.");
23039
+ }
23040
+ const child = spawn7(process.execPath, [...process.execArgv, entryPoint, DAEMON_ARG], {
23041
+ detached: true,
23042
+ stdio: "ignore",
23043
+ env: process.env
23044
+ });
23045
+ child.unref();
23046
+ const startedAt = Date.now();
23047
+ while (Date.now() - startedAt <= START_TIMEOUT_MS) {
23048
+ try {
23049
+ await sendRequest("ping", void 0, 0, { start: false });
23050
+ return;
23051
+ } catch {
23052
+ await sleep2(50);
23053
+ }
23054
+ }
23055
+ throw new UserError("Timed out waiting for terminal-pilot daemon to start.");
23056
+ }
23057
+ function sendRequest(method, params17, id, options = {}) {
23058
+ const socketPath = resolveSocketPath(process.env);
23059
+ return new Promise((resolve, reject) => {
23060
+ const socket = net.createConnection(socketPath);
23061
+ let buffer = "";
23062
+ socket.setEncoding("utf8");
23063
+ socket.on("connect", () => {
23064
+ const request = { id, method, params: params17 };
23065
+ socket.write(`${JSON.stringify(request)}
23066
+ `);
23067
+ });
23068
+ socket.on("data", (chunk) => {
23069
+ buffer += chunk;
23070
+ const newlineIndex = buffer.indexOf("\n");
23071
+ if (newlineIndex < 0) {
23072
+ return;
23073
+ }
23074
+ const line = buffer.slice(0, newlineIndex);
23075
+ socket.end();
23076
+ try {
23077
+ const response = JSON.parse(line);
23078
+ if (response.ok) {
23079
+ resolve(response.result);
23080
+ } else {
23081
+ reject(new UserError(response.error.message));
23082
+ }
23083
+ } catch (error3) {
23084
+ reject(error3);
23085
+ }
23086
+ });
23087
+ socket.on("error", (error3) => {
23088
+ if (options.start === false) {
23089
+ reject(error3);
23090
+ return;
23091
+ }
23092
+ reject(new UserError(error3.message));
23093
+ });
23094
+ });
23095
+ }
23096
+ function resolveSocketPath(env) {
23097
+ const runtimeDir = env[RUNTIME_DIR_ENV] ?? path24.join(os4.tmpdir(), `terminal-pilot-${process.getuid?.() ?? "user"}`);
23098
+ if (process.platform === "win32") {
23099
+ const hash = createHash5("sha256").update(runtimeDir).digest("hex").slice(0, 16);
23100
+ return `\\\\.\\pipe\\terminal-pilot-${hash}`;
23101
+ }
23102
+ return path24.join(runtimeDir, "daemon.sock");
23103
+ }
23104
+ function formatNamedSession(namedSession) {
23105
+ return {
23106
+ name: namedSession.name,
23107
+ session: formatSession(namedSession.session)
23108
+ };
23109
+ }
23110
+ function formatSession(session) {
23111
+ return {
23112
+ id: session.id,
23113
+ command: session.command,
23114
+ pid: session.pid,
23115
+ exitCode: session.exitCode
23116
+ };
23117
+ }
23118
+ function envFromValue(value) {
23119
+ const sessionName = optionalString2(value);
23120
+ if (sessionName === void 0) {
23121
+ return void 0;
23122
+ }
23123
+ return {
23124
+ get(key2) {
23125
+ return key2 === SESSION_ENV_VAR ? sessionName : void 0;
23126
+ }
23127
+ };
23128
+ }
23129
+ function serializePattern(pattern) {
23130
+ if (typeof pattern === "string") {
23131
+ return { kind: "literal", value: pattern };
23132
+ }
23133
+ return { kind: "regex", source: pattern.source, flags: pattern.flags };
23134
+ }
23135
+ function deserializePattern(value) {
23136
+ if (!isRecord6(value)) {
23137
+ return String(value ?? "");
23138
+ }
23139
+ if (value.kind === "regex") {
23140
+ return new RegExp(String(value.source ?? ""), String(value.flags ?? ""));
23141
+ }
23142
+ return String(value.value ?? "");
23143
+ }
23144
+ function optionalRecord(value) {
23145
+ return isRecord6(value) ? value : void 0;
23146
+ }
23147
+ function optionalString2(value) {
23148
+ return typeof value === "string" ? value : void 0;
23149
+ }
23150
+ function isRecord6(value) {
23151
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23152
+ }
23153
+ function sleep2(ms) {
23154
+ return new Promise((resolve) => setTimeout(resolve, ms));
23155
+ }
23156
+
22772
23157
  // src/cli.ts
22773
23158
  configureTheme({ brand: "green", label: "Terminal Pilot" });
22774
23159
  function normalizeArgv(argv) {
@@ -22777,11 +23162,18 @@ function normalizeArgv(argv) {
22777
23162
  }
22778
23163
  return argv;
22779
23164
  }
22780
- async function main(argv = process.argv) {
23165
+ async function main(argv = process.argv, options = {}) {
23166
+ if (isTerminalPilotDaemonArgv(argv)) {
23167
+ await runTerminalPilotDaemon();
23168
+ return;
23169
+ }
22781
23170
  const originalArgv = process.argv;
22782
23171
  process.argv = normalizeArgv(argv);
22783
23172
  try {
22784
23173
  await runCLI(createTerminalPilotGroup(), {
23174
+ services: {
23175
+ terminalPilotRuntime: options.terminalPilotRuntime ?? createDaemonTerminalPilotRuntime()
23176
+ },
22785
23177
  controls: {
22786
23178
  debug: true,
22787
23179
  output: true,
@@ -22801,7 +23193,7 @@ async function isDirectExecution(argv) {
22801
23193
  try {
22802
23194
  const modulePath = fileURLToPath5(import.meta.url);
22803
23195
  const [resolvedEntryPoint, resolvedModulePath] = await Promise.all([
22804
- realpath3(path24.resolve(entryPoint)),
23196
+ realpath3(path25.resolve(entryPoint)),
22805
23197
  realpath3(modulePath)
22806
23198
  ]);
22807
23199
  return resolvedEntryPoint === resolvedModulePath;
@@ -22814,6 +23206,7 @@ if (await isDirectExecution(process.argv)) {
22814
23206
  }
22815
23207
 
22816
23208
  // src/testing/cli-repl.ts
23209
+ var cliPath = path26.join(path26.dirname(fileURLToPath6(import.meta.url)), "..", "cli.ts");
22817
23210
  function appendJsonOutputFlag(args) {
22818
23211
  if (args.includes("--json") || args.includes("--output") || args.some((arg) => arg.startsWith("--output="))) {
22819
23212
  return [...args];
@@ -22848,6 +23241,7 @@ function canParseJson(text4) {
22848
23241
  }
22849
23242
  }
22850
23243
  function createTerminalPilotCliRepl() {
23244
+ const terminalPilotRuntime = createTerminalPilotRuntime();
22851
23245
  return {
22852
23246
  async run(args) {
22853
23247
  const stdoutChunks = [];
@@ -22869,7 +23263,7 @@ function createTerminalPilotCliRepl() {
22869
23263
  return true;
22870
23264
  });
22871
23265
  try {
22872
- await main(["node", "terminal-pilot", ...args]);
23266
+ await main(["node", cliPath, ...args], { terminalPilotRuntime });
22873
23267
  } finally {
22874
23268
  process.stdout.write = originalStdoutWrite;
22875
23269
  process.stderr.write = originalStderrWrite;
@@ -22898,7 +23292,9 @@ function createTerminalPilotCliRepl() {
22898
23292
  };
22899
23293
  }
22900
23294
  if (result.stdout.length === 0) {
22901
- throw new Error(`Expected JSON output for terminal-pilot ${args.join(" ")}, but stdout was empty.`);
23295
+ throw new Error(
23296
+ `Expected JSON output for terminal-pilot ${args.join(" ")}, but stdout was empty.`
23297
+ );
22902
23298
  }
22903
23299
  return {
22904
23300
  exitCode: result.exitCode,
@@ -22907,19 +23303,19 @@ function createTerminalPilotCliRepl() {
22907
23303
  };
22908
23304
  },
22909
23305
  async close() {
22910
- await closeSharedTerminalPilotRuntime();
23306
+ await terminalPilotRuntime.close();
22911
23307
  }
22912
23308
  };
22913
23309
  }
22914
23310
 
22915
23311
  // src/testing/qa-cli.ts
22916
- var testingDirectory = path25.dirname(fileURLToPath6(import.meta.url));
22917
- var repoRoot = path25.resolve(testingDirectory, "../../../..");
22918
- var tsxPath = path25.join(repoRoot, "node_modules", ".bin", "tsx");
22919
- var testCliPath = path25.join(repoRoot, "packages/terminal-pilot/src/testing/test-cli.js");
22920
- var menuCliPath = path25.join(repoRoot, "packages/terminal-pilot/src/testing/menu-cli.js");
22921
- var vimSavedFile = path25.join(os4.tmpdir(), "terminal-pilot-qa-test.txt");
22922
- var vimDiscardFile = path25.join(os4.tmpdir(), "terminal-pilot-qa-discard.txt");
23312
+ var testingDirectory = path27.dirname(fileURLToPath7(import.meta.url));
23313
+ var repoRoot = path27.resolve(testingDirectory, "../../../..");
23314
+ var tsxPath = path27.join(repoRoot, "node_modules", ".bin", "tsx");
23315
+ var testCliPath = path27.join(repoRoot, "packages/terminal-pilot/src/testing/test-cli.js");
23316
+ var menuCliPath = path27.join(repoRoot, "packages/terminal-pilot/src/testing/menu-cli.js");
23317
+ var vimSavedFile = path27.join(os5.tmpdir(), "terminal-pilot-qa-test.txt");
23318
+ var vimDiscardFile = path27.join(os5.tmpdir(), "terminal-pilot-qa-discard.txt");
22923
23319
  var QaContext = class {
22924
23320
  repl = createTerminalPilotCliRepl();
22925
23321
  async close() {
@@ -23665,7 +24061,7 @@ var cases = [
23665
24061
  "VIM",
23666
24062
  "-t",
23667
24063
  "5000",
23668
- path25.basename(vimSavedFile)
24064
+ path27.basename(vimSavedFile)
23669
24065
  ]);
23670
24066
  await ctx.expectOk(["press-key", "-s", "VIM", "i"]);
23671
24067
  await ctx.expectOk(["type", "-s", "VIM", "hello from terminal-pilot"]);
@@ -23720,7 +24116,7 @@ var cases = [
23720
24116
  "VIM2",
23721
24117
  "-t",
23722
24118
  "5000",
23723
- path25.basename(vimDiscardFile)
24119
+ path27.basename(vimDiscardFile)
23724
24120
  ]);
23725
24121
  await ctx.expectOk(["press-key", "-s", "VIM2", "i"]);
23726
24122
  await ctx.expectOk(["type", "-s", "VIM2", "this should not be saved"]);
@@ -23818,7 +24214,7 @@ Summary: ${cases.filter((entry) => !entry.skipped).length - failures.length} pas
23818
24214
  process.exitCode = 1;
23819
24215
  }
23820
24216
  }
23821
- if (process.argv[1] === fileURLToPath6(import.meta.url)) {
24217
+ if (process.argv[1] === fileURLToPath7(import.meta.url)) {
23822
24218
  await main2();
23823
24219
  }
23824
24220
  export {