@contextos/cli 0.2.2 → 0.3.0

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.
Files changed (2) hide show
  1. package/dist/index.js +100 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command14 } from "commander";
4
+ import { Command as Command15 } from "commander";
5
5
  import { join as join7 } from "path";
6
6
  import { existsSync as existsSync4, mkdirSync as mkdirSync3, appendFileSync } from "fs";
7
7
 
@@ -1920,6 +1920,103 @@ function registerCloudCommands(program2) {
1920
1920
  });
1921
1921
  }
1922
1922
 
1923
+ // src/commands/generate.ts
1924
+ import { Command as Command14 } from "commander";
1925
+ import chalk17 from "chalk";
1926
+ import ora16 from "ora";
1927
+ import { createAIGenerator, isInitialized } from "@contextos/core";
1928
+ var generateCommand = new Command14("generate").description("Generate code using AI").argument("<prompt>", "What to generate").option("--dry-run", "Preview what would be generated without writing files").option("--model <model>", "AI model to use (gemini, openai)", "auto").option("--no-backup", "Skip backup before overwriting files").option("--max-files <n>", "Maximum number of files to generate", "20").action(async (prompt, options) => {
1929
+ console.log(chalk17.cyan.bold("\n\u{1F916} AI Code Generator\n"));
1930
+ if (!isInitialized()) {
1931
+ console.log(chalk17.yellow('\u26A0\uFE0F ContextOS not initialized. Run "ctx init" first.\n'));
1932
+ process.exit(1);
1933
+ }
1934
+ const spinner = ora16("Initializing AI...").start();
1935
+ try {
1936
+ const generator = createAIGenerator();
1937
+ await generator.initialize();
1938
+ spinner.text = "Generating code...";
1939
+ const result = await generator.generate(prompt, {
1940
+ dryRun: options.dryRun,
1941
+ model: options.model,
1942
+ backupBeforeOverwrite: options.backup !== false,
1943
+ maxFiles: parseInt(options.maxFiles)
1944
+ });
1945
+ if (!result.success) {
1946
+ spinner.fail("Generation failed");
1947
+ console.error(chalk17.red("\nError:"), result.error);
1948
+ process.exit(1);
1949
+ }
1950
+ spinner.succeed("Generation complete");
1951
+ console.log();
1952
+ console.log(chalk17.gray("Generated Files:"));
1953
+ if (result.files.length === 0) {
1954
+ console.log(chalk17.yellow(" No files generated. AI may not have understood the request."));
1955
+ } else {
1956
+ for (const file of result.files) {
1957
+ const icon = file.isNew ? chalk17.green("+ NEW") : chalk17.yellow("~ MOD");
1958
+ console.log(` ${icon} ${chalk17.white(file.path)}`);
1959
+ }
1960
+ }
1961
+ console.log();
1962
+ console.log(chalk17.gray(`Tokens used: ${result.tokensUsed}`));
1963
+ if (options.dryRun) {
1964
+ console.log(chalk17.yellow("\n\u26A0\uFE0F Dry run mode - no files were written."));
1965
+ console.log(chalk17.gray("Run without --dry-run to write files.\n"));
1966
+ } else {
1967
+ console.log(chalk17.green(`
1968
+ \u2705 ${result.files.length} file(s) generated successfully!
1969
+ `));
1970
+ }
1971
+ } catch (error) {
1972
+ spinner.fail("Generation failed");
1973
+ console.error(chalk17.red("\nError:"), error instanceof Error ? error.message : error);
1974
+ process.exit(1);
1975
+ }
1976
+ });
1977
+ var fixCommand = new Command14("fix").description("Fix code issues using AI").argument("<prompt>", "What to fix").option("--file <path>", "Specific file to fix").option("--dry-run", "Preview without applying changes").action(async (prompt, options) => {
1978
+ console.log(chalk17.cyan.bold("\n\u{1F527} AI Code Fixer\n"));
1979
+ if (!isInitialized()) {
1980
+ console.log(chalk17.yellow('\u26A0\uFE0F ContextOS not initialized. Run "ctx init" first.\n'));
1981
+ process.exit(1);
1982
+ }
1983
+ const spinner = ora16("Analyzing and fixing...").start();
1984
+ try {
1985
+ const generator = createAIGenerator();
1986
+ await generator.initialize();
1987
+ const fixPrompt = options.file ? `Fix this issue in ${options.file}: ${prompt}` : `Fix this issue in the codebase: ${prompt}`;
1988
+ const result = await generator.generate(fixPrompt, {
1989
+ dryRun: options.dryRun,
1990
+ backupBeforeOverwrite: true
1991
+ });
1992
+ if (!result.success) {
1993
+ spinner.fail("Fix failed");
1994
+ console.error(chalk17.red("\nError:"), result.error);
1995
+ process.exit(1);
1996
+ }
1997
+ spinner.succeed("Fix complete");
1998
+ console.log();
1999
+ for (const file of result.files) {
2000
+ console.log(` ${chalk17.green("\u2713")} ${file.path}`);
2001
+ }
2002
+ if (options.dryRun) {
2003
+ console.log(chalk17.yellow("\n\u26A0\uFE0F Dry run - no changes applied.\n"));
2004
+ } else {
2005
+ console.log(chalk17.green(`
2006
+ \u2705 Fixed ${result.files.length} file(s)!
2007
+ `));
2008
+ }
2009
+ } catch (error) {
2010
+ spinner.fail("Fix failed");
2011
+ console.error(chalk17.red("\nError:"), error instanceof Error ? error.message : error);
2012
+ process.exit(1);
2013
+ }
2014
+ });
2015
+ function registerGenerateCommands(program2) {
2016
+ program2.addCommand(generateCommand);
2017
+ program2.addCommand(fixCommand);
2018
+ }
2019
+
1923
2020
  // src/index.ts
1924
2021
  var crashLogDir = join7(process.cwd(), ".contextos");
1925
2022
  if (!existsSync4(crashLogDir)) {
@@ -1956,7 +2053,7 @@ process.on("multipleResolves", (type, promise) => {
1956
2053
  process.on("warning", (warning) => {
1957
2054
  console.warn("\u26A0\uFE0F PROCESS WARNING:", warning.name, warning.message);
1958
2055
  });
1959
- var program = new Command14();
2056
+ var program = new Command15();
1960
2057
  program.name("ctx").description("ContextOS - The Context Server Protocol for AI Coding").version("0.1.0").option("-v, --verbose", "Enable verbose output");
1961
2058
  program.addCommand(initCommand);
1962
2059
  program.addCommand(indexCommand);
@@ -1974,4 +2071,5 @@ program.addCommand(traceCommand);
1974
2071
  registerPluginCommand(program);
1975
2072
  registerFinetuneCommand(program);
1976
2073
  registerCloudCommands(program);
2074
+ registerGenerateCommands(program);
1977
2075
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contextos/cli",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for ContextOS - The Context Server Protocol for AI Coding",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  "inquirer": "^9.2.0",
17
17
  "ora": "^8.0.0",
18
18
  "yaml": "^2.4.0",
19
- "@contextos/core": "0.2.2"
19
+ "@contextos/core": "0.3.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/inquirer": "^9.0.7",