# Action command schema

Status: **design direction**

This document describes the proposed pack-side action/command shape and the matching destination-level usage configuration.

## 1. Compact authoring style

Small declarative objects should normally use YAML flow style:

```yaml
plugins:
  - { name: handlebars, extensions: [.hbs] }

inputs:
  package_name: { type: string, required: true }

needs:
  schema.validation: required
  schema.persistence: required

choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }
```

This is a documentation/style preference only. Flow and block forms have identical semantics.

Normal pack examples place `actions` last.

## 2. Choice groups

Related multi-candidate actions may share one explicit tool choice:

```yaml
choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }
```

The first option is the pack default.

Choice groups choose between explicit command candidates. They never contain hidden command recipes.

## 3. Actions are an ordered flat registry

```yaml
actions:
  format:
    stage: files
    ...

  install:
    stage: final
    ...
  typecheck:
    stage: final
    ...
```

The action ID is the mapping key. Do not repeat `id:`.

The retained stages are:

- `files` — staged generated files before compare/write;
- `final` — the generated unit after workspace write.

Known action IDs may omit repetitive human metadata:

```text
format
install
typecheck
analyze
test
build
```

`install-dev` is deliberately absent. `dev` is a dependency scope inside `install`.

Custom action IDs remain valid.

## 4. Action fields

An action may contain:

```text
name
description
extensions
dependencies
after
commands
```

`commands` is optional when the pack can explain the required work but cannot safely provide a project-specific implementation.

## 5. Command candidates

A normal command candidate is exact argv:

```yaml
commands:
  - run: [npm, install]
```

`run` is never a shell string.

Candidate `id` remains optional for an individual candidate when `run[0]` is not a useful stable key.

## 6. Grouped run alternatives

Repeated candidates with the same argv structure may be compressed:

```yaml
commands:
  - run: [(pnpm|bun|yarn), add]
  - run: [npm, install]
```

The grouped token expands positionally:

```text
[pnpm, add]
[bun, add]
[yarn, add]
[npm, install]
```

When several argv positions contain grouped alternatives, expansion is zipped by index:

```yaml
- run: [(a|b|c), (x|y|z), common]
```

expands to:

```text
[a, x, common]
[b, y, common]
[c, z, common]
```

Rules:

- expansion is never Cartesian;
- all grouped tokens inside one `run` must have the same arity;
- grouped syntax is recognized only when the whole argv item has the form `(a|b|c)`;
- every other argv string is literal;
- ungrouped argv tokens are shared by every expanded candidate;
- only genuinely identical command shapes should be grouped;
- a command with a different argv shape gets its own `run`.

Grouped runs are syntax compression only. The Engine expands them to ordinary explicit candidates before selection and planning.

## 7. Candidate keys

After grouped-run expansion, the candidate key is:

```text
candidate.id when present
otherwise expanded run[0]
```

Therefore:

```yaml
commands:
  - run: [(pnpm|bun|yarn), add]
  - run: [npm, install]
```

provides:

```text
pnpm
bun
yarn
npm
```

for a choice group such as:

```yaml
choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }
```

Candidate declaration order does not need to repeat the choice-group option order. The group itself owns the default.

Grouped candidates normally derive their keys from the expanded first argv token. If an explicit `id` is needed, author the candidate individually rather than hiding several alternatives behind one ID.

## 8. File actions and extensions

```yaml
format:
  extensions: [.ts, .tsx]
  commands:
    - run: [(pnpm|yarn), exec, prettier, --write, $(files)]
    - run: [npm, exec, --, prettier, --write, $(files)]
    - run: [bun, x, prettier, --write, $(files)]
```

`$(files)` expands to staged generated files as separate argv items.

When same-ID file actions batch:

1. each contributing pack filters its own generated files by its own `extensions`;
2. Dryv unions those filtered sets;
3. Dryv sorts the resolved staged paths;
4. the union is supplied to the selected command.

An empty final file set skips the invocation.

## 9. Dependency requirements versus dependency argv

Top-level dependencies remain structured requirements:

```yaml
dependencies:
  runtime:
    typeorm: ^0.3
    reflect-metadata: ^0.2

  dev:
    prettier: ^3
    typescript: ^5.8
```

Action-local `dependencies.args` describes how those scopes become argv:

```yaml
install:
  dependencies:
    args:
      - dev: { (pnpm|yarn): [-D], bun: [--dev], npm: [--save-dev] }
      - $(name)@$(version)

  commands:
    - run: [(pnpm|bun|yarn), add]
    - run: [npm, install]
```

The two structures answer different questions:

```text
top-level dependencies
  -> what generated code requires

action dependencies.args
  -> how dependency scopes are expressed in argv
```

## 10. Ordered dependency args

`dependencies.args` is an ordered list. List order is argv order.

A plain item applies to every dependency scope:

```yaml
- $(name)@$(version)
```

A scope mapping applies only to that scope:

```yaml
- dev: { (pnpm|yarn): [-D], bun: [--dev], npm: [--save-dev] }
```

The scoped mapping's inner keys are candidate keys. A grouped key such as `(pnpm|yarn)` applies the same argv to each listed candidate.

Missing scope configuration means no extra scope-specific argv. Do not write:

```yaml
runtime: {}
```

unless a future real use case gives that mapping additional meaning.

For each non-empty dependency scope, Dryv produces one invocation from:

```text
selected command argv
+ ordered dependency args for that scope/candidate
```

A plain `$(name)@$(version)` item expands once per dependency in the current scope.

Dependency ordering is deterministic before expansion.

## 11. One install action, multiple invocations

`install` is the logical action.

`runtime` and `dev` are dependency scopes.

Therefore this:

```text
install
install-dev
```

is replaced by:

```text
install
  runtime invocation when runtime dependencies exist
  dev invocation when dev dependencies exist
```

For pnpm:

```text
pnpm add typeorm@^0.3 reflect-metadata@^0.2
pnpm add -D prettier@^3 typescript@^5.8
```

For npm:

```text
npm install typeorm@^0.3 reflect-metadata@^0.2
npm install --save-dev prettier@^3 typescript@^5.8
```

An empty scope produces no invocation.

This establishes:

```text
logical action != process invocation
```

An action may resolve to zero, one or several exact argv invocations.

## 12. Managed package install

If dependencies are already rendered into a Dryv-managed package manifest:

```yaml
install:
  commands:
    - run: [(dart|flutter), pub, get]
```

No dependency argv expansion belongs on that action.

Editable/scaffold manifests instead use explicit dependency argv expansion to let the selected project tool update the user-owned manifest and lockfile.

The exact managed-manifest detection contract remains a separate open design point.

## 13. Ordering

Use `after` only when an ordering relationship must survive cross-pack merging:

```yaml
typecheck:
  after: [install]
```

Rules:

- `after` refers only to action IDs in the same stage;
- it may refer to an action contributed by another pack;
- unknown targets are planning errors;
- cycles are planning errors.

Because dev dependencies are part of `install`, a consumer that requires all installed dependencies simply uses `after: [install]`.

## 14. Destination usage

Project environment configuration belongs to `destinations.code.<unit>`:

```yaml
destinations:
  backend:
    path: apps/backend
    choose: { js.package_manager: pnpm }

    actions:
      files:
        format:
          commands:
            - run: [pnpm, exec, biome, format, --write, $(files)]

      final:
        typecheck: { disable: true }
```

A destination can select one shared tool option, replace an action command, explicitly override supported action fields, or disable an action.

Destination overrides change only fields they set. Omitted fields remain inherited from the merged pack action.

## 15. Full TypeScript action example

```yaml
dependencies:
  runtime:
    typeorm: ^0.3
    reflect-metadata: ^0.2

  dev:
    prettier: ^3
    typescript: ^5.8

choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }

actions:
  format:
    stage: files
    extensions: [.ts]
    commands:
      - run: [(pnpm|yarn), exec, prettier, --write, $(files)]
      - run: [npm, exec, --, prettier, --write, $(files)]
      - run: [bun, x, prettier, --write, $(files)]

  install:
    stage: final
    dependencies:
      args:
        - dev: { (pnpm|yarn): [-D], bun: [--dev], npm: [--save-dev] }
        - $(name)@$(version)
    commands:
      - run: [(pnpm|bun|yarn), add]
      - run: [npm, install]

  typecheck:
    stage: final
    after: [install]
    commands:
      - run: [(pnpm|yarn), exec, tsc, --noEmit]
      - run: [npm, exec, --, tsc, --noEmit]
      - run: [bun, x, tsc, --noEmit]
```

## 16. Full Dart package action example

```yaml
choose:
  dart.sdk: { options: [dart, flutter] }

actions:
  format:
    stage: files
    extensions: [.dart]
    commands:
      - run: [dart, format, $(files)]

  install:
    stage: final
    commands:
      - run: [(dart|flutter), pub, get]

  build-runner:
    stage: final
    name: Generate serializers
    description: Run json_serializable companion generation.
    after: [install]
    commands:
      - run: [dart, run, build_runner, build, --delete-conflicting-outputs]

  analyze:
    stage: final
    after: [build-runner]
    commands:
      - run: [(dart|flutter), analyze]
```

`format` and `build-runner` have one candidate. The `dart.sdk` choice affects only the grouped multi-candidate actions.
