Skip to content

Support dynamic config loading or a CLI command to set user config #96

@mayashavin

Description

@mayashavin

Description

Currently the config is loaded from a static polira.config.ts file in the project root. Users should be able to configure Polira more flexibly — either by loading config dynamically from multiple sources or via a dedicated CLI command to initialize/update their config.

Config Precedence (highest to lowest)

  1. CLI flags (e.g. --mode, --size, --save) — per-invocation overrides, already partially exists
  2. Environment variables (POLIRA_* prefix) — useful for CI/CD and Docker
  3. Config file (polira.config.ts) — project-level settings, already works
  4. Defaults (DEFAULT_CONFIG + zod .default() values) — zero-config baseline

Environment Variable Mapping

Flat POLIRA_* naming convention maps to nested config paths:

POLIRA_AI_TEXT_MODEL=gpt-4o-mini      → ai.textModel
POLIRA_AI_IMAGE_MODEL=dall-e-3        → ai.imageModel
POLIRA_IMAGE_SIZE=1024x1024           → image.size
POLIRA_IMAGE_STYLE="watercolor"       → image.style
POLIRA_STORAGE_PROVIDER=cloudinary    → storage.provider
POLIRA_WRITING_MODE=strong            → writing.defaultMode
POLIRA_MARKDOWN_COVER_FIELD=heroImage → markdown.coverField

Note: credential env vars (OPENAI_API_KEY, CLOUDINARY_*) stay as-is — they're secrets, not config. POLIRA_* vars are for behavioral settings only.

CLI Flags

Already partially exists (--mode, --size, --save, --upload). These overrides are applied per-command in each action handler. The gap is that they're applied inconsistently and not all config fields have corresponding flags.

Tasks

  • Add POLIRA_* environment variable support to loadConfig() with deep-merge over config file
  • Standardize CLI flag overrides across all commands (consistent pattern for applying flag → config)
  • Add a polira config init command to interactively scaffold a config file
  • Add a polira config set <key> <value> command to update individual config values
  • Add a polira config show command to display the fully resolved config (all layers merged)
  • Support global config at ~/.config/polira/config.ts as fallback (before defaults, after project config)
  • Add config file auto-discovery (walk up directory tree to find nearest polira.config.ts)

Files

  • src/core/config.ts — config loading logic, env var parsing, multi-source merge
  • src/cli/commands/config.ts — new CLI command (init, set, show)
  • src/cli/index.ts — register new command
  • src/cli/commands/*.ts — standardize flag override pattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions