-
Notifications
You must be signed in to change notification settings - Fork 453
[ENG-2691] Language selection 5/5 — brv config set/get + release notes + ship gate #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import {Args, Command, Flags} from '@oclif/core' | ||
|
|
||
| import type {BrvConfig} from '../../../server/core/domain/entities/brv-config.js' | ||
|
|
||
| import {ProjectConfigStore} from '../../../server/infra/config/file-config-store.js' | ||
| import {resolveProjectRoot} from '../../lib/curate-session.js' | ||
| import {writeJsonResponse} from '../../lib/json-response.js' | ||
|
|
||
| /** | ||
| * `brv config get <key>` — read one field from `.brv/config.json`. | ||
| * | ||
| * Returns the stored value, or "(not set)" when the field is absent. Keyed | ||
| * by the same string map as `config set` so symmetry is preserved. | ||
| */ | ||
| export default class ConfigGet extends Command { | ||
| public static args = { | ||
| key: Args.string({description: 'Project config key (e.g. language.mode, language.code)', required: true}), | ||
| } | ||
| public static description = 'Read a project configuration value from .brv/config.json' | ||
| public static examples = [ | ||
| '<%= config.bin %> <%= command.id %> language.mode', | ||
| '<%= config.bin %> <%= command.id %> language.code', | ||
| '<%= config.bin %> <%= command.id %> language.mode --format json', | ||
| ] | ||
| public static flags = { | ||
| format: Flags.string({ | ||
| default: 'text', | ||
| description: 'Output format (text or json)', | ||
| options: ['text', 'json'], | ||
| }), | ||
| } | ||
|
|
||
| public async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(ConfigGet) | ||
| const format = flags.format as 'json' | 'text' | ||
|
|
||
| const projectRoot = resolveProjectRoot() | ||
| const config = await new ProjectConfigStore().read(projectRoot) | ||
|
|
||
| if (config === undefined) { | ||
| this.fail(format, 'no-config', `No .brv/config.json found at ${projectRoot}.`) | ||
| return | ||
| } | ||
|
|
||
| const result = applyConfigGet(config, args.key) | ||
| if (result.kind === 'error') { | ||
| this.fail(format, result.code, result.message) | ||
| return | ||
| } | ||
|
|
||
| if (format === 'json') { | ||
| writeJsonResponse({command: 'config get', data: {key: args.key, value: result.value}, success: true}) | ||
| } else { | ||
| this.log(result.value ?? '(not set)') | ||
| } | ||
| } | ||
|
|
||
| private fail(format: 'json' | 'text', code: string, message: string): void { | ||
| process.exitCode = 1 | ||
| if (format === 'json') { | ||
| writeJsonResponse({command: 'config get', data: {error: {code, message}}, success: false}) | ||
| } else { | ||
| this.log(message) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export type ConfigGetResult = | ||
| | {readonly code: string; readonly kind: 'error'; readonly message: string} | ||
| | {readonly kind: 'ok'; readonly value: string | undefined} | ||
|
|
||
| type ConfigGetter = (config: BrvConfig) => string | undefined | ||
|
|
||
| const GETTERS: Record<string, ConfigGetter> = { | ||
| 'language.code': (config) => config.language?.code, | ||
| 'language.mode': (config) => config.language?.mode, | ||
| } | ||
|
|
||
| /** | ||
| * Pure dispatcher mirroring `applyConfigSet` so the CLI and unit tests | ||
| * share one read-side path. | ||
| */ | ||
| export function applyConfigGet(config: BrvConfig, key: string): ConfigGetResult { | ||
| const getter = GETTERS[key] | ||
| if (getter === undefined) { | ||
| const supported = Object.keys(GETTERS).sort().join(', ') | ||
| return { | ||
| code: 'unknown-key', | ||
| kind: 'error', | ||
| message: `Unknown config key '${key}'. Supported keys: ${supported}.`, | ||
| } | ||
| } | ||
|
|
||
| return {kind: 'ok', value: getter(config)} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import {Args, Command, Flags} from '@oclif/core' | ||
|
|
||
| import type {BrvConfig, BrvConfigLanguage} from '../../../server/core/domain/entities/brv-config.js' | ||
|
|
||
| import {LANGUAGE_NAMES} from '../../../server/core/domain/render/language-clause.js' | ||
| import {ProjectConfigStore} from '../../../server/infra/config/file-config-store.js' | ||
| import {resolveProjectRoot} from '../../lib/curate-session.js' | ||
| import {writeJsonResponse} from '../../lib/json-response.js' | ||
|
|
||
| /** | ||
| * `brv config set <key> <value>` — mutate one field in `.brv/config.json`. | ||
| * | ||
| * Today only the language-selection keys are handled (`language.mode` and | ||
| * `language.code`); the dispatcher is keyed by string so adding the next | ||
| * project-config key is a one-line addition to `SETTERS`. | ||
| * | ||
| * Daemon-side runtime settings (`agentPool.maxSize`, `llm.iterationBudgetMs`, | ||
| * etc.) live behind `brv settings set` instead — those are mutable at | ||
| * runtime via transport events. Project config is a flat-file mutation; | ||
| * there is no daemon involvement. | ||
| */ | ||
| export default class ConfigSet extends Command { | ||
| public static args = { | ||
| key: Args.string({description: 'Project config key (e.g. language.mode, language.code)', required: true}), | ||
| value: Args.string({description: 'New value', required: true}), | ||
| } | ||
| public static description = 'Set a project configuration value in .brv/config.json' | ||
| public static examples = [ | ||
| '# Force the calling agent\'s LLM to author in Russian on every curate', | ||
| '<%= config.bin %> <%= command.id %> language.code ru', | ||
| '<%= config.bin %> <%= command.id %> language.mode fixed', | ||
| '', | ||
| '# Restore auto-detect (the default — match the user\'s input language)', | ||
| '<%= config.bin %> <%= command.id %> language.mode auto', | ||
| '', | ||
| '# Read in JSON for scripting', | ||
| '<%= config.bin %> <%= command.id %> language.code ja --format json', | ||
| ] | ||
| public static flags = { | ||
| format: Flags.string({ | ||
| default: 'text', | ||
| description: 'Output format (text or json)', | ||
| options: ['text', 'json'], | ||
| }), | ||
| } | ||
|
|
||
| public async run(): Promise<void> { | ||
| const {args, flags} = await this.parse(ConfigSet) | ||
| const format = flags.format as 'json' | 'text' | ||
|
|
||
| const projectRoot = resolveProjectRoot() | ||
| const store = new ProjectConfigStore() | ||
| const current = await store.read(projectRoot) | ||
|
|
||
| if (current === undefined) { | ||
| this.fail( | ||
| format, | ||
| 'no-config', | ||
| `No .brv/config.json found at ${projectRoot}. Run \`brv init\` (or any \`brv\` command in this project) to create one.`, | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| const result = applyConfigSet(current, args.key, args.value) | ||
| if (result.kind === 'error') { | ||
| this.fail(format, result.code, result.message) | ||
| return | ||
| } | ||
|
|
||
| await store.write(result.config, projectRoot) | ||
| this.success(format, args.key, args.value) | ||
| } | ||
|
|
||
| private fail(format: 'json' | 'text', code: string, message: string): void { | ||
| process.exitCode = 1 | ||
| if (format === 'json') { | ||
| writeJsonResponse({command: 'config set', data: {error: {code, message}}, success: false}) | ||
| } else { | ||
| this.log(message) | ||
| } | ||
| } | ||
|
|
||
| private success(format: 'json' | 'text', key: string, value: string): void { | ||
| if (format === 'json') { | ||
| writeJsonResponse({command: 'config set', data: {key, value}, success: true}) | ||
| } else { | ||
| this.log(`Setting saved: ${key} = ${value}.`) | ||
| } | ||
| } | ||
|
danhdoan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export type ConfigSetResult = | ||
| | {readonly code: string; readonly kind: 'error'; readonly message: string} | ||
| | {readonly config: BrvConfig; readonly kind: 'ok'} | ||
|
|
||
| type ConfigSetter = (config: BrvConfig, value: string) => ConfigSetResult | ||
|
|
||
| const SETTERS: Record<string, ConfigSetter> = { | ||
| 'language.code': setLanguageCode, | ||
| 'language.mode': setLanguageMode, | ||
| } | ||
|
|
||
| /** | ||
| * Dispatch a `<key> <value>` set onto a loaded BrvConfig. Pure function so | ||
| * the CLI command and the unit tests share one validation path — no | ||
| * filesystem or oclif coupling here. | ||
| */ | ||
| export function applyConfigSet(config: BrvConfig, key: string, value: string): ConfigSetResult { | ||
| const setter = SETTERS[key] | ||
| if (setter === undefined) { | ||
| const supported = Object.keys(SETTERS).sort().join(', ') | ||
| return { | ||
| code: 'unknown-key', | ||
| kind: 'error', | ||
| message: `Unknown config key '${key}'. Supported keys: ${supported}.`, | ||
| } | ||
| } | ||
|
|
||
| return setter(config, value) | ||
| } | ||
|
|
||
| function setLanguageMode(config: BrvConfig, value: string): ConfigSetResult { | ||
| if (value !== 'auto' && value !== 'fixed') { | ||
| return { | ||
| code: 'invalid-value', | ||
| kind: 'error', | ||
| message: `language.mode must be 'auto' or 'fixed', got '${value}'.`, | ||
| } | ||
| } | ||
|
|
||
| // Reject `fixed` without a code so the on-disk config can never reach an | ||
| // invalid intermediate state (`{mode: 'fixed'}` would be rejected by | ||
| // `isBrvConfigJson` on next load). Point the user at the unblocking step. | ||
| if (value === 'fixed' && config.language?.code === undefined) { | ||
| return { | ||
| code: 'missing-language-code', | ||
| kind: 'error', | ||
| message: | ||
| 'language.mode \'fixed\' requires language.code to be set first. Run: brv config set language.code <iso>', | ||
|
danhdoan marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| const next: BrvConfigLanguage = | ||
| value === 'fixed' | ||
| ? {code: config.language!.code!, mode: 'fixed'} | ||
| : config.language?.code === undefined | ||
| ? {mode: 'auto'} | ||
| : {code: config.language.code, mode: 'auto'} | ||
|
danhdoan marked this conversation as resolved.
|
||
|
|
||
| return {config: config.withLanguage(next), kind: 'ok'} | ||
| } | ||
|
|
||
| function setLanguageCode(config: BrvConfig, code: string): ConfigSetResult { | ||
| if (!(code in LANGUAGE_NAMES)) { | ||
| const supported = Object.keys(LANGUAGE_NAMES).sort().join(', ') | ||
| return { | ||
| code: 'unknown-iso-code', | ||
| kind: 'error', | ||
| message: `Unknown ISO 639-1 code '${code}'. Supported codes: ${supported}.`, | ||
| } | ||
| } | ||
|
|
||
| // Preserve mode if already set; default to auto when language is being | ||
| // initialized for the first time. The combination `{mode: 'auto', code}` | ||
| // is intentional — code is vestigial in auto mode but harmless, and | ||
| // makes the eventual `set language.mode fixed` a no-roundtrip activation. | ||
| const mode = config.language?.mode ?? 'auto' | ||
| return {config: config.withLanguage({code, mode}), kind: 'ok'} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.