Просмотр исходного кода

Restrict installer presets to generated configs

Alvin Unreal 3 месяцев назад
Родитель
Сommit
2ce6713c8b
5 измененных файлов с 32 добавлено и 13 удалено
  1. 1 1
      docs/installation.md
  2. 1 1
      src/cli/codemap.md
  3. 4 4
      src/cli/index.ts
  4. 12 0
      src/cli/providers.test.ts
  5. 14 7
      src/cli/providers.ts

+ 1 - 1
docs/installation.md

@@ -34,7 +34,7 @@ The installer supports the following options:
 | Option | Description |
 |--------|-------------|
 | `--skills=yes|no` | Install recommended and bundled skills (default: yes) |
-| `--preset=<name>` | Active generated config preset: `openai`, `opencode-go`, `kimi`, `copilot`, or `zai-plan` (default: `openai`) |
+| `--preset=<name>` | Active generated config preset: `openai` or `opencode-go` (default: `openai`) |
 | `--no-tui` | Non-interactive mode |
 | `--dry-run` | Simulate install without writing files |
 | `--reset` | Force overwrite of existing configuration |

+ 1 - 1
src/cli/codemap.md

@@ -57,7 +57,7 @@ CLI install command
 
 - sets `$schema`, a selected `preset` that defaults to `openai`
 - always materializes generated presets `openai` and `opencode-go`
-- materializes other selected built-in presets when explicitly requested
+- install-time `--preset` only selects between generated presets
 - maps each built-in agent name to provider-specific model/variant
 - injects skill list from recommended + custom skill registries and ensures `agent-browser` for designer
 - injects default MCP sets from `DEFAULT_AGENT_MCPS`

+ 4 - 4
src/cli/index.ts

@@ -1,6 +1,6 @@
 #!/usr/bin/env bun
 import { install } from './install';
-import { getPresetNames, isPresetName } from './providers';
+import { getGeneratedPresetNames, isGeneratedPresetName } from './providers';
 import type { BooleanArg, InstallArgs } from './types';
 
 function parseArgs(args: string[]): InstallArgs {
@@ -16,9 +16,9 @@ function parseArgs(args: string[]): InstallArgs {
       result.skills = arg.split('=')[1] as BooleanArg;
     } else if (arg.startsWith('--preset=')) {
       const preset = arg.split('=')[1];
-      if (!isPresetName(preset)) {
+      if (!isGeneratedPresetName(preset)) {
         console.error(
-          `Unsupported preset: ${preset}. Available presets: ${getPresetNames().join(', ')}`,
+          `Unsupported preset: ${preset}. Available presets: ${getGeneratedPresetNames().join(', ')}`,
         );
         process.exit(1);
       }
@@ -50,7 +50,7 @@ Options:
   --reset                Force overwrite of existing configuration
   -h, --help             Show this help message
 
-Available presets: ${getPresetNames().join(', ')}
+Available presets: ${getGeneratedPresetNames().join(', ')}
 
 The installer generates OpenAI and OpenCode Go presets by default.
 OpenAI is active unless --preset selects another generated preset.

+ 12 - 0
src/cli/providers.test.ts

@@ -95,6 +95,18 @@ describe('providers', () => {
     ).toThrow('Unsupported preset "not-real"');
   });
 
+  test('generateLiteConfig rejects non-generated model mappings as active presets', () => {
+    expect(() =>
+      generateLiteConfig({
+        hasTmux: false,
+        installSkills: false,
+        installCustomSkills: false,
+        preset: 'kimi',
+        reset: false,
+      }),
+    ).toThrow('Unsupported preset "kimi"');
+  });
+
   test('generateLiteConfig rejects inherited property names as presets', () => {
     expect(() =>
       generateLiteConfig({

+ 14 - 7
src/cli/providers.ts

@@ -6,7 +6,7 @@ import type { InstallConfig } from './types';
 const SCHEMA_URL =
   'https://unpkg.com/oh-my-opencode-slim@latest/oh-my-opencode-slim.schema.json';
 
-const GENERATED_PRESETS = ['openai', 'opencode-go'] as const;
+export const GENERATED_PRESETS = ['openai', 'opencode-go'] as const;
 
 // Model mappings by provider/preset.
 export const MODEL_MAPPINGS = {
@@ -57,6 +57,7 @@ export const MODEL_MAPPINGS = {
 } as const;
 
 export type PresetName = keyof typeof MODEL_MAPPINGS;
+export type GeneratedPresetName = (typeof GENERATED_PRESETS)[number];
 
 export function isPresetName(value: string): value is PresetName {
   return Object.hasOwn(MODEL_MAPPINGS, value);
@@ -66,13 +67,23 @@ export function getPresetNames(): PresetName[] {
   return Object.keys(MODEL_MAPPINGS) as PresetName[];
 }
 
+export function isGeneratedPresetName(
+  value: string,
+): value is GeneratedPresetName {
+  return GENERATED_PRESETS.includes(value as GeneratedPresetName);
+}
+
+export function getGeneratedPresetNames(): GeneratedPresetName[] {
+  return [...GENERATED_PRESETS];
+}
+
 export function generateLiteConfig(
   installConfig: InstallConfig,
 ): Record<string, unknown> {
   const preset = installConfig.preset ?? 'openai';
-  if (!isPresetName(preset)) {
+  if (!isGeneratedPresetName(preset)) {
     throw new Error(
-      `Unsupported preset "${preset}". Available presets: ${getPresetNames().join(', ')}`,
+      `Unsupported preset "${preset}". Available generated presets: ${getGeneratedPresetNames().join(', ')}`,
     );
   }
 
@@ -131,10 +142,6 @@ export function generateLiteConfig(
     presets[presetName] = buildPreset(presetName);
   }
 
-  if (!presets[preset]) {
-    presets[preset] = buildPreset(preset);
-  }
-
   if (installConfig.hasTmux) {
     config.tmux = {
       enabled: true,