cli-shell
How choliba's command line is built — the composition root in main.ts, the shell's container and command table, one ShellModule per package, ShellIo for arguments and exit codes, and how to add a command or an agent provider and test it with runShell. Use when creating or changing a command, a service, a shell module or an agent provider, or when asked where that code goes.
- License 许可
- MIT
- 所属仓库
- choliba/choliba
- 最近更新
- 2026-10-25
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- cli-shell
- description
- How choliba's command line is built — the composition root in main.ts, the shell's container and command table, one ShellModule per package, ShellIo for arguments and exit codes, and how to add a command or an agent provider and test it with runShell. Use when creating or changing a command, a service, a shell module or an agent provider, or when asked where that code goes.
- argument-hint
- What you are building (command, service, provider...) and in which package.
- user-invocable
- true
- disable-model-invocation
- false
02 资源文件 1
- 参考文档references/testing.md1.5 KB
03 SKILL.md 正文
The shell
packages/choliba/src/main.ts is the composition root. It reads the process and Bun into a Platform and a
Runtime, strips the global flags, and runs createCholibaShell(platform, runtime).run(). There is no HTTP and
no decorator. The workspace stays packages/*: each package exports one ShellModule, and the app lists them.
Names, layers and which folder is a module: the code-standard skill. What the user sees (flags, stdout, exit
codes, pt-BR): cli-guidelines.
Where code goes
- One feature per folder.
<feature>.service.ts(a plain class), one<action>.command.tsper command (its pt-BRCommandEntryinside it),dto/<action>.dto.ts(a class with a constructor, neverfield!),interfaces/*.interface.ts,<feature>.constants.ts(tokens fromtoken<T>()). The domain logic stays in plain functions; the service calls them. The package's<feature>-shell.tsregisters the factories and lists the commands. - One entry per package.
@choliba/<pkg>(src/index.ts) exports the functions, the types, the tokens and theShellModule. The Playwright runner loads that entry with its own Babel, which rejects a parameter decorator, so the barrel has none. The runner's typecheck also has no Bun types: a function that wrapsBun.spawntakes a structural type, and the realBun.spawnis read only inmain.ts. - Another package is reached only through
.. Never through a folder, and a package never imports its own entry from inside. A folder is reached only through itsindex.ts.
What every command uses (@choliba/shell and @choliba/kernel)
PLATFORM(@choliba/kernel): the process, registered bycreateShellfrom whatmain.tsbuilt (argv already without--no-color, cwd, env, stdout, stderr, clock, signals, spawn, which, git). Onlymain.tsreads Bun andprocess. Jest runs on Node, so nothing else may.CONFIGandTHEME(@choliba/shell): aConfigServiceand aThemeService, registered bybaseShellfromPLATFORM. Another package's factory asks for them withcontainer.get(CONFIG).RUNTIME: the app's own token (packages/choliba), registered bycholibaShell. It is howcheck,lint,formatandsetuprun ESLint, Prettier and the deferred setup step.ShellIo: the arguments as typed (io.args('projects', 'list')), stdout (write,printHelp), stderr (fail,usageError) and the exit code (exit). A command reads its own words; it does not reparse the global flags, whichmain.tsalready removed.ShellCommand:name(the first word), optionalaliases,help(container)(the root entries, omitted when the command stays out of--help) andrun(container, io). Withverb(run,new,list),nameis the type after the verb ({ verb: 'run', name: 'agent' }ischoliba run agent), andhelpgives its entry in the verb's help.
Steps for a new command
- Read
cli-guidelinesand write the failing spec first (references/testing.md). - The logic as plain functions in the feature folder. The service calls them with what its factory reads from the container.
- The command object:
helpreturns aCommandEntry(name, the line--helplists, group, spec).runreadsio.args('<name>'), calls the service, thenio.exit(code),io.fail(message)orio.usageError(message, program). Its own--helpprintsentryHelp(entry). - Register the service with
container.provide(TOKEN, (container) => new Service(...))in the package'sShellModule, and add the command to that module'scommands. The root lists it fromhelpwith no change to the app, in the order ofCHOLIBA_ORDERwhen the name is there. A command that is one more type of a verb (something to run, create or list) takes thatverbinstead of a new first word (cli-guidelines, rule 16). A command with nohelpdoes not appear in--help(terminal). bun run check. After a tool config change,bash .agents/skills/quality-gates/scripts/verify.sh.
Adding an agent provider
packages/providers/src/<provider>/<id>-agent.provider.ts: a plain classextends AgentProviderwithid,binaries,autoPriority,buildArgs,createParser(and the optional hooks), exported fromproviders/index.ts.- Add an instance to the list
agentsShellbuildsAGENT_PROVIDERSfrom (choliba/src/agents/agents/agents-shell.ts):--provider <id>,--<id>,auto's order and completion follow with no other change. - Specs: its args and parser, and the registry spec, which the new provider must not break.
The root and the verbs
At most one module has root (the app's cholibaShell): empty line and help print the sorted help,
help <words…> the help of the command they name, version prints version(), and __complete, __describe and
__entries answer before any command lookup. shell.has('__complete') stays false: those words are not
ShellCommands.
The root declares its verbs (CHOLIBA_VERBS: run, new, list, each with its line in --help). The shell
builds each verb from the commands that name it: choliba run --help lists their entries, choliba run agent …
runs the agent type with io.args('run', 'agent'), and a missing or unknown type is a usage error that suggests
the closest one. A first word that is neither a command nor a verb is a usage error with a suggestion too; there
is no fallback. Two roots, a verb that is also a command, a command under a verb the root does not declare, or two
commands claiming one word (or one type of a verb) throw when the shell is built.
A spec that runs a package's verb commands without the app adds VERBS_ROOT from @choliba/shell/testing.
Tests
references/testing.md: runShell([module], fakePlatform({ argv })) for a command line, new Service(...) for
a service, @choliba/kernel/testing and @choliba/shell/testing for internal fakes. The installed
choliba/core/testing facade combines them. Never bun test.
04 同仓库更多 Skills
dummy-skill
Skill de teste, usada pelo agente echo das fixtures.
dummy-skill
Skill de teste, usada pelo agente echo das fixtures.
playwright-trace
Inspect Playwright trace files from the command line — list actions, view requests, console, errors, snapshots and screenshots.
playwright-component-testing
Set up component testing with Playwright using a story gallery — scaffold stories and a gallery dev page driven by the built-in mount fixture, no dedicated component-testing runtime. Use when asked to test React or Vue components in isolation with Playwright, or to migrate off @playwright/experimental-ct-react / -vue.
playwright-cli
Automate browser interactions, test web pages and work with Playwright tests.
quality-gates
暂无简介