You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit dfe9025
Browse filesBrowse the repository at this point in the historyBrowse files
* feat: add variables and when conditions
Adds the variable core resource and when conditions on resources, templates
and variables.
- variable block (name, valueType text | number | boolean | enum | multiEnum,
description, options, default, sensitive, when). Asked on every run and
never saved.
- ${{ name }} references in resource parameters, defaults and the variables
passed to templates. Exact references keep their type, $${{ }} escapes.
References without a declaration are asked as text and shown as a plan
warning.
- when: keys are variable names; value = equals (multiEnum: includes),
list = one of, { not } = opposite, any = alternatives. Conditions may only
reference declared variables.
- Variables are scoped to their file. Templates are expanded in rounds: the
variables of a file are asked first, templates whose when doesn't match
are never loaded, and values can be passed to a template's variables.
- --var name=value / template.name=value on plan, apply, destroy, refresh,
import and test. Values are forwarded to the codify test VM and accepted
from the dashboard through the private values file (never logged).
GET /capabilities tells the dashboard that variables are supported.
- Refresh and import resolve the variables of the project file, skip
resources whose when doesn't match, match with values and keep the
references and when in the file.
- Sensitive variables are masked in the plan.
- Prompts for the default (Ink), plain, json and stub reporters.
Uses @codifycli/schemas from the codify-schemas branch until 1.5.0 is
published.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
* chore: point the lockfile to the rebased codify-schemas branch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
* chore: use @codifycli/schemas 1.5.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
* feat: show the label of variables when asking for them
Variables get an optional label again (codify-schemas 1.6.0): the question
shown when asking for the value. The name stays the identifier used by
references, conditions and --var, and is shown next to the label. The
description is the help text under it.
Uses the codify-schemas branch until 1.6.0 is published.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
* chore: use @codifycli/schemas 1.6.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
* test: wait for the enum variable prompt before pressing enter
The select registers its input handler after it renders. On slow CI
machines enter was written before that and dropped, so the test saw the
previous answer. Wait for the prompt and send enter until it is handled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016QnBk5xkqnrsLyn9Eco1yn
---------
Co-authored-by: Claude <noreply@anthropic.com>
-`codify apply <template>` is a project with a single template declaration (the resolver's fetched template is seeded into the loader).
227
227
-`import`/`refresh`/`edit` do not expand templates: template blocks are left untouched in files.
228
228
229
+
## Variables and Conditions Architecture
230
+
231
+
`{ "type": "variable", "name": "siteType", "valueType": "enum", "options": [...], "default"?, "label"?, "description"?, "sensitive"?, "when"? }` is a core config block (`ConfigType.VARIABLE`, `src/entities/variable-config.ts`, validated against `VariableSchema`). It is never sent to a plugin. `valueType` is `text` (default), `number`, `boolean`, `enum` or `multiEnum`. Values are asked on every run and never saved. `name` is the identifier (`[\w-]+`) used by references, conditions and `--var`; `label` (any text, defaults to the name) is the question shown when asking and `description` the help text under it, so wording can change without breaking references.
232
+
233
+
-**References**: `${{ name }}` in resource parameters, in variable defaults and in the `variables` passed to templates (`src/variables/substitution.ts`). A string that is exactly one reference gets the typed value (number, boolean, list); otherwise the value is interpolated as text. `$${{ name }}` is an escaped literal. Not allowed in `template.source`. A reference without a variable block is an implicit `text` variable: it is asked as well and shown as a plan warning (`Project.implicitVariables`).
234
+
-**Conditions** (`when` on resources, templates and variables, `src/variables/condition.ts`): keys are variable names and must all match. A value means equals (multiEnum: includes), a list means one of, `{ "not": ... }` the opposite, `any` is a list of alternatives. A variable without a value (its own `when` didn't match) never matches. Conditions may only reference declared variables (`VariableError` otherwise). `os`/`distro` stay separate fields.
235
+
-**`VariableResolver.resolveScope()`** (`src/variables/variable-resolver.ts`) handles one file: validates, orders the variables (stable sort on `when`/`default` dependencies, cycles are errors), asks for each one (`Reporter.promptVariable`, asked again with `error` until valid), removes declarations whose `when` doesn't match, asks for implicit variables, then replaces the references (`ResourceConfig.setParameter`, `TemplateConfig.resolvedVariables`). Parameters that use a `sensitive` variable go into `ResourceConfig.sensitiveParameterKeys` and are masked in the plan.
236
+
-**Scopes**: variables are scoped to their file. `TemplateExpander.flatten()` resolves a file's scope before expanding its templates, so the questions come in rounds and templates whose `when` doesn't match are never loaded. A template's scope is labelled by its declaration name or the last part of its source (`astro-blog`, repeated labels get `-2`). Qualified names (`astro-blog.projectName`) are used by `--var` and in prompts. A template included again with different `resolvedVariables` is expanded again (`instanceKey`).
237
+
-**Values instead of asking**: values passed by the template declaration > `--var name=value` / `--var template.name=value` (`src/common/variable-flags.ts`) > the values file (`CODIFY_PARAMETER_VALUES_FILE`, now `{ parameters, variables }`, the old list format is still read). `codify test` expands templates on the host and forwards every value to the VM. `codify connect` writes the `variables` of the request body to the values file (`src/connect/variable-values.ts`), never on the command line or in logs. `GET /capabilities` tells the dashboard that the CLI supports variables.
238
+
-**Pipeline**: `PluginInitOrchestrator` resolves variables right after parsing, before plugin initialization: `expandTemplates` (plan, apply, destroy, test) uses the expander, `resolveVariables` (import, refresh) uses `TemplateExpander.resolveProjectVariables()` for the project file only. Resources removed by a condition prune `dependsOn` like the os filter (`Project.removeConditionalDeclarations`).
239
+
-**Import / refresh write-back**: refresh imports only the resources whose `when` matches, with their values. `ImportOrchestrator.updateExistingFiles` passes the resolved project to `FileModificationCalculator` for its own file, so matching uses values while the file is written from its contents: `${{ }}` references and core properties (`name`, `dependsOn`, `os`, `distro`, `when`) are kept (`src/generators/preserve-existing-values.ts`). Block positions are counted from the file, so variable blocks count.
240
+
-`validate` and `init` do not resolve variables.
241
+
229
242
## Plugin Error Handling Architecture
230
243
231
244
Plugin errors flow as structured `PluginErrorData` over IPC and are caught as `PluginError` instances on the CLI side:
0 commit comments