ccjk 13.6.4 → 13.6.5

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.
@@ -1,5 +1,5 @@
1
1
  import a from './index5.mjs';
2
- import { t as taskPersistence } from '../shared/ccjk.DwSebGy0.mjs';
2
+ import { t as taskPersistence } from '../shared/ccjk.BOO14f66.mjs';
3
3
  import '../shared/ccjk.BAGoDD49.mjs';
4
4
  import 'node:fs';
5
5
  import 'better-sqlite3';
@@ -1,10 +1,10 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
- import { CCJK_CONFIG_DIR } from './constants.mjs';
4
+ import { CCJK_CONFIG_DIR, CODE_TOOL_INFO } from './constants.mjs';
5
5
  import { writeJsonConfig } from './json-config.mjs';
6
6
  import { j as join } from '../shared/ccjk.bQ7Dh1g4.mjs';
7
- import { g as getPlatform } from './platform.mjs';
7
+ import { g as getPlatform, e as commandExists } from './platform.mjs';
8
8
  import { s as scanProject } from '../shared/ccjk.DJuyfrlL.mjs';
9
9
 
10
10
  const ORCHESTRATION_LEVELS = ["off", "minimal", "standard", "max"];
@@ -89,7 +89,7 @@ class SmartDefaultsDetector {
89
89
  const platform = getPlatform();
90
90
  const apiKey = this.detectApiKey();
91
91
  const apiProvider = this.detectApiProvider(apiKey);
92
- const ccVersion = this.detectClaudeCodeVersion();
92
+ const ccVersion = await this.detectClaudeCodeVersion();
93
93
  const projectContext = scanProject(cwd);
94
94
  return {
95
95
  // Environment detection
@@ -142,17 +142,28 @@ class SmartDefaultsDetector {
142
142
  /**
143
143
  * Detect installed Claude Code version
144
144
  */
145
- detectClaudeCodeVersion() {
146
- try {
147
- const output = execSync('claude --version 2>/dev/null || echo ""', {
148
- encoding: "utf-8",
149
- timeout: 5e3
150
- }).trim();
151
- const match = output.match(/(\d+\.\d+\.\d+)/);
152
- return match ? match[1] : void 0;
153
- } catch {
154
- return void 0;
145
+ async detectClaudeCodeVersion() {
146
+ const candidateCommands = [
147
+ CODE_TOOL_INFO["claude-code"].runtimeCommand,
148
+ CODE_TOOL_INFO.myclaude.runtimeCommand
149
+ ];
150
+ for (const command of candidateCommands) {
151
+ try {
152
+ if (!await commandExists(command)) {
153
+ continue;
154
+ }
155
+ const output = execSync(`${command} --version 2>/dev/null || echo ""`, {
156
+ encoding: "utf-8",
157
+ timeout: 5e3
158
+ }).trim();
159
+ const match = output.match(/(\d+\.\d+\.\d+)/);
160
+ if (match) {
161
+ return match[1];
162
+ }
163
+ } catch {
164
+ }
155
165
  }
166
+ return void 0;
156
167
  }
157
168
  /**
158
169
  * Detect which Claude Code native features are available
@@ -235,6 +246,23 @@ class SmartDefaultsDetector {
235
246
  * This is a static method so it can be called without instantiating the full detector.
236
247
  */
237
248
  static detectCodeToolType() {
249
+ const myclaudeMarkers = [
250
+ join(homedir(), ".claude.json"),
251
+ join(homedir(), ".claude", "config.json")
252
+ ];
253
+ try {
254
+ if (myclaudeMarkers.some((p) => existsSync(p))) {
255
+ const globalConfigPath = join(homedir(), ".claude.json");
256
+ if (existsSync(globalConfigPath)) {
257
+ const configContent = readFileSync(globalConfigPath, "utf-8");
258
+ const config = JSON.parse(configContent);
259
+ if (config.myclaudeActiveProviderProfileId || config.myclaudeProviderProfiles) {
260
+ return "myclaude";
261
+ }
262
+ }
263
+ }
264
+ } catch {
265
+ }
238
266
  const claudeCodePaths = [
239
267
  join(homedir(), ".claude"),
240
268
  join(homedir(), ".config", "claude")
@@ -3,7 +3,7 @@ import { i as inquirer } from './index6.mjs';
3
3
  import { ZCF_CONFIG_FILE, DEFAULT_CODE_TOOL_TYPE, isCodeToolType } from './constants.mjs';
4
4
  import { i18n, ensureI18nInitialized, resolveSupportedLanguage } from './index2.mjs';
5
5
  import { readZcfConfig } from './ccjk-config.mjs';
6
- import { r as resolveCodeType } from '../shared/ccjk.CiKtBUW_.mjs';
6
+ import { r as resolveCodeType } from '../shared/ccjk.yYQMbHH3.mjs';
7
7
  import { a as handleExitPromptError, h as handleGeneralError } from '../shared/ccjk.DGllfVCZ.mjs';
8
8
  import { a as addNumbersToChoices } from '../shared/ccjk.BFQ7yr5S.mjs';
9
9
  import { p as promptBoolean } from '../shared/ccjk.DZ2LLOa-.mjs';
package/dist/cli.mjs CHANGED
@@ -461,6 +461,34 @@ const COMMANDS = [
461
461
  };
462
462
  }
463
463
  },
464
+ {
465
+ name: "research <action> [...args]",
466
+ description: "Run focused autoresearch-style experiments",
467
+ tier: "extended",
468
+ options: [
469
+ { flags: "--name <name>", description: "Experiment name" },
470
+ { flags: "--cmd <command>", description: "Shell command to execute" },
471
+ { flags: "--metric <name>", description: "Metric name to parse from output" },
472
+ { flags: "--budget-ms <ms>", description: "Execution budget in milliseconds" },
473
+ { flags: "--cwd <path>", description: "Working directory for the command" },
474
+ { flags: "--limit <n>", description: "Number of sessions to list" }
475
+ ],
476
+ loader: async () => {
477
+ return async (options, action, args) => {
478
+ const actionStr = action;
479
+ const argsArr = args;
480
+ const { researchCommand } = await import('./chunks/research.mjs');
481
+ await researchCommand(actionStr || "help", argsArr, {
482
+ name: options.name,
483
+ cmd: options.cmd,
484
+ metric: options.metric,
485
+ budgetMs: options.budgetMs ? Number(options.budgetMs) : void 0,
486
+ cwd: options.cwd,
487
+ limit: options.limit ? Number(options.limit) : void 0
488
+ });
489
+ };
490
+ }
491
+ },
464
492
  // ==================== New v8.0.0 Commands ====================
465
493
  // Note: task, keybinding, and history commands use Commander.js subcommand pattern
466
494
  // They are registered via registerSpecialCommands() instead of lazy loading
package/dist/index.d.mts CHANGED
@@ -5002,7 +5002,7 @@ declare function findRealCommandPath(command: string): Promise<string | null>;
5002
5002
  * Get recommended install methods for a code tool based on current platform
5003
5003
  * Returns methods in priority order (most recommended first)
5004
5004
  */
5005
- type CodeType = 'claude-code' | 'codex';
5005
+ type CodeType = 'claude-code' | 'myclaude' | 'codex';
5006
5006
  type InstallMethod = 'npm' | 'homebrew' | 'curl' | 'powershell' | 'cmd' | 'npm-global' | 'native';
5007
5007
  declare function getRecommendedInstallMethods(codeType: CodeType): InstallMethod[];
5008
5008
 
package/dist/index.d.ts CHANGED
@@ -5002,7 +5002,7 @@ declare function findRealCommandPath(command: string): Promise<string | null>;
5002
5002
  * Get recommended install methods for a code tool based on current platform
5003
5003
  * Returns methods in priority order (most recommended first)
5004
5004
  */
5005
- type CodeType = 'claude-code' | 'codex';
5005
+ type CodeType = 'claude-code' | 'myclaude' | 'codex';
5006
5006
  type InstallMethod = 'npm' | 'homebrew' | 'curl' | 'powershell' | 'cmd' | 'npm-global' | 'native';
5007
5007
  declare function getRecommendedInstallMethods(codeType: CodeType): InstallMethod[];
5008
5008
 
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { CLOUD_ENDPOINTS } from './chunks/constants.mjs';
5
5
  export { C as CloudError, a as CloudErrorCode, b as CloudErrorFactory, f as formatErrorForLogging, g as getRetryDelay, h as handleCloudError, i as isAuthError, c as isRateLimitError, d as isRetryableError, e as isRetryableErrorCode } from './shared/ccjk.vO3d1ABk.mjs';
6
6
  import { e as extractString } from './shared/ccjk.C2jHOZVP.mjs';
7
7
  export { a as extractDisplayName, i as i18nHelpers, n as normalizeRecommendation, b as normalizeRecommendations } from './shared/ccjk.C2jHOZVP.mjs';
8
- import { exec, execSync, spawn } from 'node:child_process';
8
+ import { exec, execSync } from 'node:child_process';
9
9
  import { promises, existsSync, readdirSync, readFileSync, statSync, createReadStream } from 'node:fs';
10
10
  import * as os from 'node:os';
11
11
  import { homedir } from 'node:os';
@@ -14,6 +14,7 @@ import { promisify } from 'node:util';
14
14
  import a from './chunks/index5.mjs';
15
15
  import { g as getRuntimeVersion } from './shared/ccjk.gDEDGD_t.mjs';
16
16
  import { j as join$1 } from './shared/ccjk.bQ7Dh1g4.mjs';
17
+ import { b as buildCommand, c as commandExists, a as escapeArgument, e as executeCommand, d as executeCommandParallel, f as executeCommandSequence, g as executeCommandStream, h as getCommandPath, i as getCommandVersion, p as parseVersion } from './shared/ccjk.BnsY5WxD.mjs';
17
18
  export { j as config } from './chunks/config.mjs';
18
19
  export { a as loggerUtils } from './shared/ccjk.8oaxX4iR.mjs';
19
20
  export { p as platform } from './chunks/platform.mjs';
@@ -1036,7 +1037,7 @@ const userSkillsApi = {
1036
1037
  sortByLastUsed
1037
1038
  };
1038
1039
 
1039
- const execAsync$1 = promisify(exec);
1040
+ const execAsync = promisify(exec);
1040
1041
  class BaseCodeTool {
1041
1042
  config;
1042
1043
  configPath;
@@ -1061,7 +1062,7 @@ class BaseCodeTool {
1061
1062
  async isInstalled() {
1062
1063
  try {
1063
1064
  const command = this.getInstallCheckCommand();
1064
- const { stdout, stderr } = await execAsync$1(command);
1065
+ const { stdout, stderr } = await execAsync(command);
1065
1066
  const version = this.parseVersion(stdout || stderr);
1066
1067
  return {
1067
1068
  installed: true,
@@ -1081,7 +1082,7 @@ class BaseCodeTool {
1081
1082
  async install() {
1082
1083
  try {
1083
1084
  const command = this.getInstallCommand();
1084
- const { stdout, stderr } = await execAsync$1(command);
1085
+ const { stdout, stderr } = await execAsync(command);
1085
1086
  return {
1086
1087
  success: true,
1087
1088
  output: stdout || stderr,
@@ -1101,7 +1102,7 @@ class BaseCodeTool {
1101
1102
  async uninstall() {
1102
1103
  try {
1103
1104
  const command = this.getUninstallCommand();
1104
- const { stdout, stderr } = await execAsync$1(command);
1105
+ const { stdout, stderr } = await execAsync(command);
1105
1106
  await this.removeConfigFile();
1106
1107
  return {
1107
1108
  success: true,
@@ -1163,7 +1164,7 @@ class BaseCodeTool {
1163
1164
  async execute(command, args = []) {
1164
1165
  try {
1165
1166
  const fullCommand = this.buildCommand(command, args);
1166
- const { stdout, stderr } = await execAsync$1(fullCommand, {
1167
+ const { stdout, stderr } = await execAsync(fullCommand, {
1167
1168
  env: { ...process.env, ...this.config.env }
1168
1169
  });
1169
1170
  return {
@@ -1258,7 +1259,7 @@ class BaseCodeTool {
1258
1259
  */
1259
1260
  async findToolPath() {
1260
1261
  try {
1261
- const { stdout } = await execAsync$1(`which ${this.getMetadata().name}`);
1262
+ const { stdout } = await execAsync(`which ${this.getMetadata().name}`);
1262
1263
  return stdout.trim();
1263
1264
  } catch (_error) {
1264
1265
  return void 0;
@@ -2726,173 +2727,6 @@ function generateRecommendations(scanResult) {
2726
2727
  return recommendations;
2727
2728
  }
2728
2729
 
2729
- const execAsync = promisify(exec);
2730
- async function executeCommand(command, args = [], options = {}) {
2731
- try {
2732
- const fullCommand = buildCommand(command, args);
2733
- const execOptions = {
2734
- cwd: options.cwd,
2735
- env: { ...process.env, ...options.env },
2736
- timeout: options.timeout,
2737
- shell: typeof options.shell === "string" ? options.shell : options.shell ? "/bin/sh" : void 0,
2738
- encoding: options.encoding || "utf8",
2739
- maxBuffer: options.maxBuffer || 1024 * 1024 * 10
2740
- // 10MB default
2741
- };
2742
- const { stdout, stderr } = await execAsync(fullCommand, execOptions);
2743
- return {
2744
- success: true,
2745
- stdout: stdout.toString().trim(),
2746
- stderr: stderr.toString().trim(),
2747
- exitCode: 0
2748
- };
2749
- } catch (error) {
2750
- return {
2751
- success: false,
2752
- stdout: error.stdout?.toString().trim() || "",
2753
- stderr: error.stderr?.toString().trim() || "",
2754
- exitCode: error.code || 1,
2755
- error: error.message
2756
- };
2757
- }
2758
- }
2759
- function executeCommandStream(command, args = [], options = {}) {
2760
- return new Promise((resolve) => {
2761
- const spawnOptions = {
2762
- cwd: options.cwd,
2763
- env: { ...process.env, ...options.env },
2764
- shell: options.shell !== false
2765
- };
2766
- const child = spawn(command, args, spawnOptions);
2767
- let stdout = "";
2768
- let stderr = "";
2769
- child.stdout?.on("data", (data) => {
2770
- const text = data.toString();
2771
- stdout += text;
2772
- if (options.onStdout) {
2773
- options.onStdout(text);
2774
- }
2775
- });
2776
- child.stderr?.on("data", (data) => {
2777
- const text = data.toString();
2778
- stderr += text;
2779
- if (options.onStderr) {
2780
- options.onStderr(text);
2781
- }
2782
- });
2783
- child.on("close", (code) => {
2784
- resolve({
2785
- success: code === 0,
2786
- stdout: stdout.trim(),
2787
- stderr: stderr.trim(),
2788
- exitCode: code || 0,
2789
- error: code !== 0 ? `Command exited with code ${code}` : void 0
2790
- });
2791
- });
2792
- child.on("error", (error) => {
2793
- resolve({
2794
- success: false,
2795
- stdout: stdout.trim(),
2796
- stderr: stderr.trim(),
2797
- exitCode: 1,
2798
- error: error.message
2799
- });
2800
- });
2801
- if (options.timeout) {
2802
- setTimeout(() => {
2803
- child.kill();
2804
- resolve({
2805
- success: false,
2806
- stdout: stdout.trim(),
2807
- stderr: stderr.trim(),
2808
- exitCode: 1,
2809
- error: `Command timed out after ${options.timeout}ms`
2810
- });
2811
- }, options.timeout);
2812
- }
2813
- });
2814
- }
2815
- function buildCommand(command, args) {
2816
- const escapedArgs = args.map(escapeArgument);
2817
- return [command, ...escapedArgs].join(" ");
2818
- }
2819
- function escapeArgument(arg) {
2820
- if (/[\s"'`$&|;<>(){}[\]\\]/.test(arg)) {
2821
- const escaped = arg.replace(/"/g, '\\"');
2822
- return `"${escaped}"`;
2823
- }
2824
- return arg;
2825
- }
2826
- async function commandExists(command) {
2827
- const isWindows = process.platform === "win32";
2828
- const checkCommand = isWindows ? "where" : "which";
2829
- try {
2830
- const result = await executeCommand(checkCommand, [command]);
2831
- return result.success;
2832
- } catch {
2833
- return false;
2834
- }
2835
- }
2836
- async function getCommandPath(command) {
2837
- const isWindows = process.platform === "win32";
2838
- const checkCommand = isWindows ? "where" : "which";
2839
- try {
2840
- const result = await executeCommand(checkCommand, [command]);
2841
- if (result.success) {
2842
- return result.stdout.split("\n")[0].trim();
2843
- }
2844
- return null;
2845
- } catch {
2846
- return null;
2847
- }
2848
- }
2849
- function parseVersion(output) {
2850
- const patterns = [
2851
- /version\s+v?(\d+\.\d+\.\d+)/i,
2852
- /v?(\d+\.\d+\.\d+)/,
2853
- /(\d+\.\d+\.\d+)/
2854
- ];
2855
- for (const pattern of patterns) {
2856
- const match = output.match(pattern);
2857
- if (match) {
2858
- return match[1];
2859
- }
2860
- }
2861
- return null;
2862
- }
2863
- async function getCommandVersion(command, versionFlag = "--version") {
2864
- try {
2865
- const result = await executeCommand(command, [versionFlag]);
2866
- if (result.success) {
2867
- return parseVersion(result.stdout || result.stderr);
2868
- }
2869
- return null;
2870
- } catch {
2871
- return null;
2872
- }
2873
- }
2874
- async function executeCommandSequence(commands) {
2875
- const results = [];
2876
- for (const cmd of commands) {
2877
- const result = await executeCommand(
2878
- cmd.command,
2879
- cmd.args || [],
2880
- cmd.options || {}
2881
- );
2882
- results.push(result);
2883
- if (!result.success) {
2884
- break;
2885
- }
2886
- }
2887
- return results;
2888
- }
2889
- async function executeCommandParallel(commands) {
2890
- const promises = commands.map(
2891
- (cmd) => executeCommand(cmd.command, cmd.args || [], cmd.options || {})
2892
- );
2893
- return Promise.all(promises);
2894
- }
2895
-
2896
2730
  const index$4 = {
2897
2731
  __proto__: null,
2898
2732
  buildCommand: buildCommand,
@@ -597,4 +597,4 @@ class TaskPersistence {
597
597
  }
598
598
  const taskPersistence = new TaskPersistence();
599
599
 
600
- export { taskPersistence as t };
600
+ export { TaskPersistence as T, taskPersistence as t };
@@ -0,0 +1,171 @@
1
+ import { exec, spawn } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+
4
+ const execAsync = promisify(exec);
5
+ async function executeCommand(command, args = [], options = {}) {
6
+ try {
7
+ const fullCommand = buildCommand(command, args);
8
+ const execOptions = {
9
+ cwd: options.cwd,
10
+ env: { ...process.env, ...options.env },
11
+ timeout: options.timeout,
12
+ shell: typeof options.shell === "string" ? options.shell : options.shell ? "/bin/sh" : void 0,
13
+ encoding: options.encoding || "utf8",
14
+ maxBuffer: options.maxBuffer || 1024 * 1024 * 10
15
+ // 10MB default
16
+ };
17
+ const { stdout, stderr } = await execAsync(fullCommand, execOptions);
18
+ return {
19
+ success: true,
20
+ stdout: stdout.toString().trim(),
21
+ stderr: stderr.toString().trim(),
22
+ exitCode: 0
23
+ };
24
+ } catch (error) {
25
+ return {
26
+ success: false,
27
+ stdout: error.stdout?.toString().trim() || "",
28
+ stderr: error.stderr?.toString().trim() || "",
29
+ exitCode: error.code || 1,
30
+ error: error.message
31
+ };
32
+ }
33
+ }
34
+ function executeCommandStream(command, args = [], options = {}) {
35
+ return new Promise((resolve) => {
36
+ const spawnOptions = {
37
+ cwd: options.cwd,
38
+ env: { ...process.env, ...options.env },
39
+ shell: options.shell !== false
40
+ };
41
+ const child = spawn(command, args, spawnOptions);
42
+ let stdout = "";
43
+ let stderr = "";
44
+ child.stdout?.on("data", (data) => {
45
+ const text = data.toString();
46
+ stdout += text;
47
+ if (options.onStdout) {
48
+ options.onStdout(text);
49
+ }
50
+ });
51
+ child.stderr?.on("data", (data) => {
52
+ const text = data.toString();
53
+ stderr += text;
54
+ if (options.onStderr) {
55
+ options.onStderr(text);
56
+ }
57
+ });
58
+ child.on("close", (code) => {
59
+ resolve({
60
+ success: code === 0,
61
+ stdout: stdout.trim(),
62
+ stderr: stderr.trim(),
63
+ exitCode: code || 0,
64
+ error: code !== 0 ? `Command exited with code ${code}` : void 0
65
+ });
66
+ });
67
+ child.on("error", (error) => {
68
+ resolve({
69
+ success: false,
70
+ stdout: stdout.trim(),
71
+ stderr: stderr.trim(),
72
+ exitCode: 1,
73
+ error: error.message
74
+ });
75
+ });
76
+ if (options.timeout) {
77
+ setTimeout(() => {
78
+ child.kill();
79
+ resolve({
80
+ success: false,
81
+ stdout: stdout.trim(),
82
+ stderr: stderr.trim(),
83
+ exitCode: 1,
84
+ error: `Command timed out after ${options.timeout}ms`
85
+ });
86
+ }, options.timeout);
87
+ }
88
+ });
89
+ }
90
+ function buildCommand(command, args) {
91
+ const escapedArgs = args.map(escapeArgument);
92
+ return [command, ...escapedArgs].join(" ");
93
+ }
94
+ function escapeArgument(arg) {
95
+ if (/[\s"'`$&|;<>(){}[\]\\]/.test(arg)) {
96
+ const escaped = arg.replace(/"/g, '\\"');
97
+ return `"${escaped}"`;
98
+ }
99
+ return arg;
100
+ }
101
+ async function commandExists(command) {
102
+ const isWindows = process.platform === "win32";
103
+ const checkCommand = isWindows ? "where" : "which";
104
+ try {
105
+ const result = await executeCommand(checkCommand, [command]);
106
+ return result.success;
107
+ } catch {
108
+ return false;
109
+ }
110
+ }
111
+ async function getCommandPath(command) {
112
+ const isWindows = process.platform === "win32";
113
+ const checkCommand = isWindows ? "where" : "which";
114
+ try {
115
+ const result = await executeCommand(checkCommand, [command]);
116
+ if (result.success) {
117
+ return result.stdout.split("\n")[0].trim();
118
+ }
119
+ return null;
120
+ } catch {
121
+ return null;
122
+ }
123
+ }
124
+ function parseVersion(output) {
125
+ const patterns = [
126
+ /version\s+v?(\d+\.\d+\.\d+)/i,
127
+ /v?(\d+\.\d+\.\d+)/,
128
+ /(\d+\.\d+\.\d+)/
129
+ ];
130
+ for (const pattern of patterns) {
131
+ const match = output.match(pattern);
132
+ if (match) {
133
+ return match[1];
134
+ }
135
+ }
136
+ return null;
137
+ }
138
+ async function getCommandVersion(command, versionFlag = "--version") {
139
+ try {
140
+ const result = await executeCommand(command, [versionFlag]);
141
+ if (result.success) {
142
+ return parseVersion(result.stdout || result.stderr);
143
+ }
144
+ return null;
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+ async function executeCommandSequence(commands) {
150
+ const results = [];
151
+ for (const cmd of commands) {
152
+ const result = await executeCommand(
153
+ cmd.command,
154
+ cmd.args || [],
155
+ cmd.options || {}
156
+ );
157
+ results.push(result);
158
+ if (!result.success) {
159
+ break;
160
+ }
161
+ }
162
+ return results;
163
+ }
164
+ async function executeCommandParallel(commands) {
165
+ const promises = commands.map(
166
+ (cmd) => executeCommand(cmd.command, cmd.args || [], cmd.options || {})
167
+ );
168
+ return Promise.all(promises);
169
+ }
170
+
171
+ export { escapeArgument as a, buildCommand as b, commandExists as c, executeCommandParallel as d, executeCommand as e, executeCommandSequence as f, executeCommandStream as g, getCommandPath as h, getCommandVersion as i, parseVersion as p };
@@ -0,0 +1,115 @@
1
+ import { i as inquirer } from '../chunks/index6.mjs';
2
+ import { a as detectCodeToolType } from '../chunks/smart-defaults.mjs';
3
+ import { CODE_TOOL_ALIASES, DEFAULT_CODE_TOOL_TYPE, isCodeToolType } from '../chunks/constants.mjs';
4
+ import { i18n } from '../chunks/index2.mjs';
5
+ import { readZcfConfigAsync, updateZcfConfig } from '../chunks/ccjk-config.mjs';
6
+
7
+ const CODE_TYPE_ABBREVIATIONS = {
8
+ cc: "claude-code",
9
+ mc: "myclaude",
10
+ mycode: "myclaude",
11
+ cx: "codex"
12
+ };
13
+ const STARTUP_CODE_TOOL_CHOICES = ["myclaude", "claude-code", "codex"];
14
+ async function resolveCodeType(codeTypeParam) {
15
+ if (codeTypeParam) {
16
+ const normalizedParam = codeTypeParam.toLowerCase().trim();
17
+ if (normalizedParam in CODE_TYPE_ABBREVIATIONS) {
18
+ return CODE_TYPE_ABBREVIATIONS[normalizedParam];
19
+ }
20
+ if (normalizedParam in CODE_TOOL_ALIASES) {
21
+ return CODE_TOOL_ALIASES[normalizedParam];
22
+ }
23
+ if (isValidCodeType(normalizedParam)) {
24
+ return normalizedParam;
25
+ }
26
+ const validAbbreviations = Object.keys(CODE_TYPE_ABBREVIATIONS);
27
+ const validFullTypes = Object.values(CODE_TYPE_ABBREVIATIONS);
28
+ const validOptions = [...validAbbreviations, ...validFullTypes].join(", ");
29
+ let defaultValue = DEFAULT_CODE_TOOL_TYPE;
30
+ try {
31
+ const config = await readZcfConfigAsync();
32
+ if (config?.codeToolType && isValidCodeType(config.codeToolType)) {
33
+ defaultValue = config.codeToolType;
34
+ }
35
+ } catch {
36
+ }
37
+ throw new Error(
38
+ i18n.t("errors:invalidCodeType", { value: codeTypeParam, validOptions, defaultValue })
39
+ );
40
+ }
41
+ const storedType = await getStoredCodeType();
42
+ if (storedType) {
43
+ return storedType;
44
+ }
45
+ try {
46
+ const freshDetected = detectCodeToolType();
47
+ if (isValidCodeType(freshDetected)) {
48
+ return freshDetected;
49
+ }
50
+ } catch {
51
+ }
52
+ return DEFAULT_CODE_TOOL_TYPE;
53
+ }
54
+ function isValidCodeType(value) {
55
+ return isCodeToolType(value);
56
+ }
57
+ async function getStoredCodeType() {
58
+ try {
59
+ const config = await readZcfConfigAsync();
60
+ if (config?.codeToolType && isValidCodeType(config.codeToolType)) {
61
+ return config.codeToolType;
62
+ }
63
+ } catch {
64
+ }
65
+ return null;
66
+ }
67
+ function persistCodeType(codeToolType) {
68
+ updateZcfConfig({ codeToolType });
69
+ }
70
+ async function promptStartupCodeType() {
71
+ const isZh = i18n.language === "zh-CN";
72
+ const { codeToolType } = await inquirer.prompt({
73
+ type: "list",
74
+ name: "codeToolType",
75
+ message: isZh ? "\u9009\u62E9\u4EE3\u7801\u5DE5\u5177" : "Choose your code tool",
76
+ choices: STARTUP_CODE_TOOL_CHOICES.map((tool) => {
77
+ if (tool === "myclaude") {
78
+ return {
79
+ name: isZh ? `${tool} - Provider-first \u63A7\u5236\u4E2D\u5FC3\uFF08\u9ED8\u8BA4\u63A8\u8350\uFF09` : `${tool} - Provider-first control center (recommended default)`,
80
+ value: tool
81
+ };
82
+ }
83
+ if (tool === "claude-code") {
84
+ return {
85
+ name: isZh ? "Claude Code - Claude \u5BB6\u65CF\u7ECF\u5178\u63A7\u5236\u4E2D\u5FC3" : "Claude Code - Classic Claude-family control center",
86
+ value: tool
87
+ };
88
+ }
89
+ return {
90
+ name: isZh ? "Codex - Codex \u4E13\u5C5E\u63A7\u5236\u4E2D\u5FC3\u3001Provider / MCP / Memory \u914D\u7F6E" : "Codex - Codex-specific control center for provider, MCP, and memory setup",
91
+ value: tool
92
+ };
93
+ }),
94
+ default: 0
95
+ });
96
+ persistCodeType(codeToolType);
97
+ return codeToolType;
98
+ }
99
+ async function resolveStartupCodeType(options = {}) {
100
+ if (options.codeTypeParam) {
101
+ const resolvedType = await resolveCodeType(options.codeTypeParam);
102
+ persistCodeType(resolvedType);
103
+ return resolvedType;
104
+ }
105
+ const storedType = await getStoredCodeType();
106
+ if (storedType) {
107
+ return storedType;
108
+ }
109
+ if (options.interactive) {
110
+ return await promptStartupCodeType();
111
+ }
112
+ return await resolveCodeType();
113
+ }
114
+
115
+ export { STARTUP_CODE_TOOL_CHOICES as S, resolveStartupCodeType as a, resolveCodeType as r };