Plugin architecture
The APX plugin uses the exact version of @syntax-syllogism/apx-core pinned in package.json. Each command adapts Salesforce CLI flags to a core use case and presents the rendered result. Core owns generation, dead-code analysis, option schemas, validation, and result text. This repository owns the Salesforce CLI interface.
Where changes belong
| Area | Owner |
|---|---|
Use cases (plan/apply, run), option schemas and validation messages, and renderers for generation results and the dead-code report | apx-core |
| Describe conversion, naming, path layout, plan builders, templates, generation engine, and generation model types | apx-core |
| Output-base and API-version helpers, shared defaults and validators | apx-core |
| Class inventory, binding scans, dependency graph, entry-point detection, classification, and destructive manifest rendering/writing | apx-core |
| Flag → option mapping, connection selection, dry-run mapping, and CLI output routing | src/adapters/ and src/commands/apx/ |
| Salesforce CLI flags and message loading | src/aep/flags.ts and messages/ |
| Interactive input, confirmation, TTY checks, and CLI required-input checks | src/aep/interactive.ts, src/aep/prompting.ts, and src/aep/commandSupport.ts |
| Core error translation and compatibility wrappers | src/aep/apxCommand.ts and src/aep/errors.ts |
The former plugin directories src/aep/{describe,engine,model,naming,paths,plan,templates} and src/dead/ have been removed. Change shared behavior in core, release it, and deliberately upgrade the plugin’s exact dependency pin and lockfile. The core package’s README describes its public exports; templates are internal to core.
CLI boundary
Commands own Org resolution, authentication refresh, and connection selection. Core accepts caller-supplied connections and does not authenticate. The describe commands refresh auth before obtaining the selected connection; dead also refreshes before querying. Service generation can run without an org. See Command details for API-version precedence.
The plugin calls core’s output-base helper without an explicit project root: relative output paths resolve against the current Salesforce project, while absolute paths are used directly. Generation commands call runGeneration (src/adapters/generation.ts): it maps flags with toOptions (src/adapters/options.ts), validates them with the use case’s schema, connects only when the descriptor’s requiresOrg allows it, and calls plan. --dry-run maps the plan to wouldCreate (absolute paths) without writing; otherwise apply runs with overwrite: 'overwrite'. Core also supports 'skip', but the CLI does not expose it. Human output comes from renderGenerationResult.
toOptions keeps three CLI rules out of core: --at4dx/--fflib map to flavor through requireExactlyOneFlavor and resolveFlavor, --fields is split on commas, and generate action keeps its 10.2 order default. test/adapters/parity.test.ts fails when a schema key has no flag or an option flag has no schema key.
All commands extend ApxCommand, whose catch handler translates intentional core errors to the CLI’s previous error shapes. toCliError preserves messages, maps the test-pairing invariant to SfError, and otherwise restores plain errors or original describe causes as appropriate. Core error codes and structured data are not generally exposed as new CLI JSON fields.
Core validates options with zod. parseOptionsForCli turns the first validation issue into the SfError the CLI printed before. Two more wrappers preserve details that core would otherwise change:
withCliDescribeErrorswraps the connection passed to a use case, capturesdescribeSObjectfailures, and rethrows the original Salesforce API failure, includingNOT_FOUNDpayloads, because core’s not-found error omits the original cause. Successful describe conversion still runs in core.writeDeadCodeManifestForCliunwraps core’swrite-failedcause so manifest filesystem failures retain their previous CLI error details.
Keep these adapters in mind when upgrading core; removing them requires checking human and JSON error compatibility. apx dead (src/commands/apx/dead.ts) runs core’s dead use case. With --destructive-manifest it writes the manifest through writeDeadCodeManifestForCli, and --dry-run passes through so nothing is written. Human output comes from core’s typed renderDeadCodeReportBlocks: each block’s kind picks the channel, so warning blocks go to this.warn (stderr) and every other block goes to this.log. The plugin does not parse report text. Its safety rules are described in Dead-code analysis.
Compatibility checks
The plugin retains golden-plan and formatting tests in test/aep/planBuilders.test.ts and test/aep/apexFormatting.test.ts, with unchanged fixtures under test/fixtures/aep/golden/. Domain unit tests for naming, templates, the engine, and classification live in core.
Plugin boundary coverage includes test/adapters/ for option mapping and descriptor/flag parity, test/commands/apx/core-cutover.test.ts for auth/connection ordering and API versions, test/aep/errors.test.ts for CLI error translation, test/commands/apx/dead.test.ts for dead-report routing, command tests under test/commands/apx/, and interactive tests. Run the relevant tests for a boundary change and yarn test for the plugin gate. yarn test also runs the command-snapshot check and the README drift check. For command/help changes, yarn run version regenerates README and CLI references, and yarn docs:cli-reference regenerates only the CLI reference. Both need docs-site installed (npm --prefix docs-site ci).
The sf-smoke-tests project runs end-to-end and live-org checks of the installed plugin. This repository runs unit and command-level tests with stubbed connections, and CI smoke-tests the built CLI with node bin/run.js apx --help to catch command-loading failures.
The repository root has no .npmrc, so installing, building, and testing the plugin resolves @syntax-syllogism/apx-core from public npm and needs no registry token. The docs theme (@syntax-syllogism/docs-theme) is a dependency of docs-site only. docs-site/.npmrc maps the @syntax-syllogism scope to GitHub Packages, so installing the docs site needs a read token. The CLI reference check runs in CI’s docs job with APX_REQUIRE_CLI_REFERENCE=1, and is skipped locally when docs-site is not installed.