Skip to content

Latest commit

 

History

History
279 lines (202 loc) · 26.3 KB

CONTRIBUTE.md

File metadata and controls

279 lines (202 loc) · 26.3 KB

Contribute to Frodo CLI (frodo-cli)

Any direct commits to the repository are not allowed. Pull requests (PR) are most welcome. Please fork this repo and develop and test in that fork. Once you feel ready, please create a PR. For any major changes, please open an issue first to discuss what and why you'd like to change.

Developing

Forking this repo

Please refer to these couple of excellent resources for getting started with forking the repo and contributing to github open source projects in general. These are great reads not only for someone new to this, even regular github contributors may find some great tidbits of information.

OR

Prerequisites

  • Node.js 26 or later. Developing this CLI requires Node.js 26: the full build (npm run build) produces the platform binary, which needs Node 26 for the SEA packaging step (--build-sea), and package.json declares engines.node >= 26.
  • npm (included with Node.js)
  • A GUI editor is highly recommended. The current developers use VSCode, but you are welcome to others, like Atom or Sublime too. The repository contains configuration files for VSCode's ESLint and prettier add-ons, which will automatically lint the code and apply coding styles when using VSCode. The same files may work for other editors with similar add-ons, but this has not been tested.

Clone the repo and install dependencies

git clone https://github.com/rockcarver/frodo-cli.git
cd frodo-cli
npm ci

Build and install

For how the build toolchain works — what each tool does and why, bundler configuration details, binary packaging and signing — see BUILD-ENV.md.

Adding a package? Read this first. This CLI ships as a zero-dependency package: package.json's dependencies field stays empty on purpose, and every package imported by shipped code — including runtime prompt/library code — goes in devDependencies. The bundler (tsdown; tsup had the same default) inlines devDependencies into the bundle and externalizes anything listed under dependencies — which breaks the SEA binary at runtime (no node_modules inside the binary) and reopens the npm audit surface we deliberately keep empty. Details and the verification one-liner: BUILD-ENV.md §2.2.1.

Full build (npm bundle + platform binary)

The following command builds the CLI and creates a native SEA binary for your platform (requires Node.js 26; on macOS the binary is automatically signed with an ad-hoc certificate so it runs immediately):

npm run build

Build only, don't create platform binary

The following command builds the CLI but does not create a binary. It is faster (and helpful when you only need the npm/Docker build — but it still expects Node.js 26, per engines):

npm run build:only

Develop

Frodo CLI-only Development

To automatically build as you develop, use:

npm run dev

Frodo Library & CLI Development

If you are adding new capabilities to the CLI, chance are you will also need to extend the library. In that case, you will want to link your local develipment version of the library to your development version of the CLI. The Frodo team assumes that you will have cloned both projects into the same parent folder, thus frodo-lib and frodo-cli folders being siblings in the same location.

In this setup, link your frodo-cli to your frodo-lib:

npm run link
npm run dev

Please note that in case you make library changes, you will need to manually rebuild the CLI, as the npm run dev command will NOT pick up on compiles of the library.

Run Frodo CLI

Running the npm version

You can run frodo from anywhere on your system if you install it globally after building:

npm i -g
Running the binary version

The frodo binary (frodo.exe on Windows) is self contained and statically linked, so no dependencies are needed. After a full build (npm run build), it is at dist-sea/frodo and can be run as:

/path/to/frodo-cli/dist-sea/frodo

Add the binary to your system path to make it easier to call from your terminal without switching directories

Before submitting a PR

Before you submit a PR, make sure your code follows the frodo code formatting conventions, type checks, and all the existing and your new tests are passing.

npm run lint
npx tsc --noEmit
npm run build:only
npm test

npm test runs the full test suite against the npm build of this checkout (node dist/launch.cjs, started through the shim in test/e2e/shims). The test scripts do not build or rebuild it: run npm run build:only (or npx tsdown, about 2 seconds) first, and again after every change to src/, or the CLI-level tests (client_cli, e2e, PTY) run the old code. CI additionally runs the same suite against the platform binary (npm run test:binary, which builds dist-sea/frodo if it is missing); if your change touches the binary packaging or startup path, you can run that locally too:

npm run test:binary

Merging

PRs merge into main through ordinary pull requests once the required CI checks pass; the previous integration batch-merge workflow has been retired.

Do not edit CHANGELOG.md in a PR. It is generated at release time from what merged since the last release (the Generate and promote AI changelog step of .github/workflows/pipeline.yml), so give the PR a clear title and description. npm run check (and the Lint step of the Build job) fails a branch that changes the file, committed or not, and prints how to undo it. Only a commit of the shape of the release commit passes, whoever wrote it; how the check decides is in PIPELINE.md, and the rule is in https://github.com/rockcarver/frodo-cli/blob/main/docs/decisions/core/0005-releases-are-started-by-a-maintainer-through-the-pipeline.md (nobody edits CHANGELOG.md in a pull request). When a change removes or renames a command, alias or option, add it to MIGRATION.md (see "Maintaining This Guide" there).

Code structure and conventions

The library is the brain and the CLI is a thin wrapper: new capability goes into frodo-lib behind the frodo facade first, and the CLI wraps it for the terminal (parsing, prompts, output, files and stdin, exit codes). The library stays free of anything tied to one interface, such as a terminal; interface-specific stacks (interactive mode, the MCP server, the frodo shell) legitimately live in the CLI. A workflow that only composes existing library functions (the order of the steps, work across connections, defaults, confirmation, dry run, progress) is the CLI's own work. See core 0001 The library is the brain, the CLI is a thin wrapper and 0036 The library holds the common functions and the CLI composes them into commands.

Frodo CLI adheres to the following folder and file structure:

├── dist                      Build output (generated, gitignored). The bundled
│                             CommonJS files; the entry point is dist/launch.cjs.
├── dist-sea                  The native binary (generated, gitignored; npm run build).
├── docs                      Documentation files.
├── resources                 Resource files.
├── scripts                   Build scripts (the native binary build).
├── src                       Source files.
│   ├── app.ts                The root program: registers the command groups.
│   ├── cli                   CLI command files, one folder per command group.
│   │   ├── _template         Templates for new CLI commands.
│   ├── configManagerOps      Operations behind the config-manager commands.
│   ├── help                  Sample values for the usage examples (SampleData.ts).
│   ├── ops                   Ops layer modules. They adapt frodo-lib for the
│   │   │                     terminal: argument mapping, output formatting,
│   │   │                     file and stdin handling, exit codes. Business
│   │   │                     logic belongs in frodo-lib.
│   │   ├── classic           Ops modules for classic deployments only.
│   │   ├── cloud             Ops modules for cloud deployments only.
│   │   ├── templates         Templates of different object types and schema.
│   │   └── utils             Ops layer utility modules.
│   └── utils                 Shared utility modules.
│       └── interactive       Prompt components and pickers (the interactive layer).
├── test                      Tests and test resources.
│   ├── client_cli            CLI output tests.
│   │   └── en                English output tests.
│   │       ├── __snapshots__ English output test snapshots.
│   ├── e2e                   End-to-end tests.
│   │   ├── __snapshots__     End-to-end test snapshots.
│   │   ├── env               Test environment files.
│   │   ├── exports           Export data for import tests.
│   │   ├── mocks             Mock recordings (Polly.js).
│   │   ├── shims             The frodo launcher the tests put on PATH (runs dist/).
│   │   ├── test-data         Test data files.
│   │   └── utils             Test utilities.
│   ├── fs_tmp                Temp file directory for running tests.
│   ├── unit                  Unit tests, PTY tests and the usage-examples check.
│   └── utils                 Test harness for PTY tests.
└── tools                     Test and release tooling.

src/ops adapts the library for the terminal and composes its functions into workflows; business logic that another consumer would also need belongs in frodo-lib behind the frodo facade (0036 The library holds the common functions and the CLI composes them into commands, core 0001 The library is the brain, the CLI is a thin wrapper).

Code conventions

Most of Frodo CLI's functionality is manipulating configuration of a Ping (formerly: ForgeRock) Identity Platform instance. Most of the configuration is stored in configuration and other objects, which can be managed individually.

To create a good and consistent developer experience for other CLI developers, follow these conventions:

Managing objects - CRUDQ

Adopt CRUDQ naming for object manipulation:

Action Examples Comments
create createJourney Create should fail if object already exists.
read readJourney readJourneys Read one or all objects of a kind.
update updateJourney Update object if it already exists, create it otherwise.
delete deleteJourney, deleteJourneys Delete one or all objects of a kind.
query queryJourneys Query objects.
Managing properties

Use getters and setters for property manipulation.

Action Examples Comments
get getJourneyDescription Retrieve an individual property of an object.
set setJourneyDescription Set the value of an individual property of an object.
Managing status

Some objects support status. Avoid using getters and setters for status if possible.

Action Examples Comments
enable enableJourney Enable a configuration.
disable disableJourney Disable a configuration
Everything else

Pick meaningful function names. It's OK for them to be long, as long as they convey their purpose.

Writing a command

  1. Start from the template. Copy src/cli/_template/something.ts (the command group) and the verb files you need (something-list.ts, -describe, -export, -import, -delete), rename them and delete what you do not need.
  2. Use the usual verbs and options. One kind of configuration artifact is one group with list, describe, export, import and delete. Export commands almost all use -i, --<thing>-id, -f, --file, -a, --all, -A, --all-separate and -N, --no-metadata; copy a neighbouring command rather than inventing new spellings.
  3. Keep the command file thin. A command is a FrodoCommand('frodo <group> <verb>'). Its action calls command.handleDefaultArgsAndOpts(...), logs in with getTokens(), calls an ops function in src/ops/ and sets process.exitCode = 1 when the operation fails. Print through src/utils/Console.ts (printMessage, verboseMessage, printError) and take colors from src/utils/ColorTheme.ts. If the command performs several operations (the items of a bulk, the steps of an "all" command, a loop over the items of a kind), follow record 0040: call .multiOp() on the command, which adds the shared --allow-failures option, pass options.allowFailures to the ops function, and run the operations in the ops function through OperationRun (src/utils/OperationRun.ts). It runs every operation, prints one summary of what failed and tells the command whether to set exit code 1. src/configManagerOps/FrConfigAllOps.ts (pull all) is the example.
  4. Register it. Add program.addCommand(XxxCmd().name('xxx')) to the group file (see src/cli/journey/journey.ts). A new group is imported and added in src/app.ts. Add an alias with withAlias(name) (a second spelling that stays) or, for the old name of a renamed command, withAlias(old, 'transition'); never with .alias(), which lint rejects in src/cli. The help names the preferred name only and ends the description with (alias: a) or (formerly: old), and typing a transition alias prints a one-line notice on stderr. The old name stays until a major release removes it, and the rename goes into MIGRATION.md (record 0049). An option that selects one object in a config-manager command is -i, --<type>-id for an identifier or -n, --<type>-name for a name that can change, declared mutually exclusive when a command has both (options of the configuration commands). Make the option with selectorOption(flags, description, aliases) from src/cli/SelectorOption.ts: it refuses an empty value while the command line is parsed, so that an empty variable never selects all objects. -n, --name stays as a permanent alias on the commands that took it: pass ['-n', '--name'] as aliases (the helper withOptionAlias in src/cli/OptionAlias.ts does the aliasing), which ends the description with (alias: -n, --name), and never declare a second option on -n.
  5. Add usage examples. Every command has a Usage Examples: block, which -hhh shows. Add it with .addHelpText('after', ...) in the style of frodo info (src/cli/info/info.ts) and frodo conn save (src/cli/conn/conn-save.ts): one sentence saying what the example does, then the command, with one example per mode or option that matters and login variants (credentials, connection profile). Take the values from src/help/SampleData.ts and add constants there when you need them. Run every example against a build before you submit. An example must run as written and open no picker or editor: operands are positional, so with a user name the realm comes second (<amBaseUrl> <realm> <username> '<password>'; otherwise the user name is read as the realm and the password as the user name); name the target (-i, -a, ...) of a command that picks an entity and one member of every requireOneOf group; use only flags the command defines and close every quote. A command that asks for confirmation by design (frodo journey prune) is the one exception, and the sentence above its example says so. test/unit/UsageExamples.test.js fails for a command without examples and test/unit/UsageExampleOperands.test.js for an example that breaks these rules; what predates them is frozen in test/unit/UsageExamplesLegacyExceptions.js and test/unit/UsageExampleOperandsLegacyExceptions.js, lists that only shrink: never add to them, and delete the line of what you fix.
  6. Add tests. test/client_cli/en/<group>-<verb>.test.js snapshots the -h output. A command that talks to a tenant also gets test/e2e/<group>-<verb>.e2e.test.js with recordings; see test/e2e/README.md. Logic in src/ops/ that can be tested without a tenant gets a unit test in test/unit.
  7. Document breaking changes in MIGRATION.md.

A configuration type that frodo-lib handles in its own module has one owner in the CLI too: a command for it belongs to that type's one command family, and the generic commands of its family (frodo agent ...) do not list, export or delete it. config-manager gives the type one kind; the generic kinds skip the type, name the owning kind and report the skip, not a failure (core 0022 A configuration type has one owner in every layer). The CLI has not fully caught up with this: while the record has a Known deviations section, it names the generic commands and kinds that still handle such a type, so read it before you add or change one of them.

If your command prompts the user, read "Layering: where interactive code lives" in INTERACTIVE-COMMANDS.md first.

Moving a configuration type to the library: the CLI half

A configuration type that frodo-lib turns into a file set (core 0028, the library turns configuration into file sets through the type's own read and write) gets its config pull and config push commands, and its steps of pull all, pull all-static and push all-static, from two functions of the library, pull<Type>Config and push<Type>Config. The CLI half is the last of the steps of the order that the record fixes (the library function, a release, the pin, then the command line, which deletes its own copy in the same pull request). src/ops/FileSetRuns.ts is the one place that carries a pull to a folder and a push from a folder: pullToFolder(pull, what) and pushFromFolder(push, what). The KBA configuration is the first type that uses it, and its pull request is the example.

  1. Pin the library that has the type's pull and push with the pin-the-library skill, in a pull request of its own. A pin is never changed in the pull request that uses it.
  2. Write the characterization test first, in its own commit, green on the code of main. The real CLI against the fake tenant (test/utils/FakeAm.mjs): the requests of a pull and a push as a literal list, the bytes of the files, -D, a file that is already there, a second pull, every failure as exit code 1 with one header, and a canary that the value of a placeholder is in no output (test/unit/ConfigManagerKbaFakeTenant.test.js). The move then has to keep every row, except the ones that the record names as differences, and those change in the commit that moves the type.
  3. Make one runner call in each of the two command files: pullToFolder(() => frodo.idm.config.pullXxxConfig(), 'Xxx') and pushFromFolder((reader) => frodo.idm.config.pushXxxConfig(reader), 'Xxx'), keeping the login, the verboseMessage line and if (!outcome) process.exitCode = 1;. The runner returns a boolean and never exits or sets the exit code (code sets the exit code and returns instead of exiting).
  4. Change the step lines in src/configManagerOps/FrConfigAllOps.ts to the same two calls, with the order of the steps and reads as they were. A recording replays the same whichever place a step has, so the position of the step is pinned by a test (test/unit/FileSetRuns.test.js), and the shared spy of test/unit/ConfigManagerPushAllStatic.test.js finds the call of a type by its label.
  5. Delete src/configManagerOps/FrConfig<Type>Ops.ts with its import, its row in GATE_CALLS of test/unit/ConfigManagerPullWriteSites.test.js and its call in the table of test/unit/ConfigManagerPushAllStatic.test.js. No new module goes into src/configManagerOps/ (config-manager has its own layer outside ops).
  6. Build no path from an id, show no id raw and print no error as an object. The library names every file, a push never reads a file name, and the writer and the reader of src/utils/FsFileSet*.ts are the only code that touches the folder. An id from a tenant is shown with shownIdInSingleQuotes, and an error goes through printError (its message and its causes), never through JSON.stringify, inspect, toJSON or String, because the request of a failed call can hold a value that a placeholder was filled with.
  7. The exit code is the runner's boolean (a command that runs many operations runs them all, then fails if any failed). An outcome with an error, a file that cannot be written and a finding that is a collision, a refused or an unreadable entry fail the run, and the rest of the file set is still written. A not-of-type finding is a notice and does not. A finding is printed before the write.
  8. No progress code and no per-object callback in the CLI. The library reports progress through the progress indicators that FrodoCommand.ts plugs in for every command, and a type that reports progress shows it with no change here.
  9. Recordings replay unchanged. No recording and no snapshot is edited or recorded again for a move. A replay proves that the new requests are a subset of the recorded ones, so the characterization test carries the claim that the requests and their order are the same.
  10. Put each difference that a user can see into MIGRATION.md, one sentence each, as the record asks.
  11. Nothing for the MCP server goes into the CLI: the library marks the verbs it does not offer there.
  12. Before the pull request: npm run test:guidance, npm run check, npx tsc --noEmit, npx tsdown and the whole suite. The text of the pull request says which differences the files meet, quotes records as full links with a few words, and carries Part of lines.

Recording decisions

When you decide something that will outlive your change (a rule contributors must follow, a behaviour users rely on, a design principle), record it in docs/decisions/ in the same pull request. Accepted records are binding until a newer record supersedes them, and a pull request that changes a decided behaviour adds or supersedes one. How to write a record, and the index of the existing ones, is in docs/decisions/README.md. A decision that also binds frodo-lib is a core record: the same file in docs/decisions/core/ of both repositories (core 0018).

Working with coding agents

AGENTS.md at the repository root and the files in .github/instructions/ give coding agents (GitHub Copilot and others) the short version of this guide: build and test commands, the hard rules, and checklists that load when a matching file is edited. They link back here; when a convention changes, change it here first and keep those files short.

AGENTS.md opens with the five laws that get broken most, each with its reason and the check that catches it, and stays short; what matters for part of the code goes into a file of .github/instructions/. Claude Code does not read that folder: it reads .claude/rules/, which is generated from it (core 0026). After you change an instruction file, run npm run generate:claude-rules and commit the result; never edit a file of .claude/rules/ by hand. npm run generate:claude-rules -- --check lists what differs, and test/unit/ClaudeRules.test.js fails for it. To see which instruction files a Claude Code session loaded at launch, run /context all and read the memory files; to see which rules it has loaded since, ask the session. A source in a subfolder of .github/instructions/ keeps its path in .claude/rules/.

Step-by-step procedures for recurring tasks (adding a command, recording a decision, building the CLI and the binary, creating test recordings, reviewing an agent's pull request, pinning the library, releasing the CLI) are skills in .claude/skills/, which Claude Code and the GitHub Copilot cloud agent load on demand. A skill links the rules it must obey and does not restate them.