3.3 KiB
3.3 KiB
KBot C++ Port Plan (WIP Scaffolding)
This document outlines the scaffolding steps to port the TypeScript kbot implementation (both AI tools and the project runner) over to the C++ polymech-cli application.
1. CLI Scaffolding (main.cpp & cmd_kbot)
The C++ port will introduce a new kbot subcommand tree loosely mimicking the existing TypeScript entry points (zod_schema.ts).
- Target Files:
src/main.cpp(Register the command)src/cmd_kbot.h(Declarations & Options Structs)src/cmd_kbot.cpp(Implementation)
Subcommand ai
This command replaces the standard OptionsSchema from zod_schema.ts.
- Using
CLI::App* ai_cmd = kbot_cmd->add_subcommand("ai", "Run KBot AI workflows"); - Arguments to Map via
CLI11:--path(default.)--prompt(string)--output(string)--dst(string)--append(enum:concat,merge,replace)--wrap(enum:meta,none)--each(Glob pattern / list / JSON)--disable,--disableTools,--tools--include,--exclude,--globExtension--model,--router,--mode(enum:completion,tools,assistant,responses,custom)- Flags:
--stream,--dry,--alt - Advanced:
--baseURL,--config,--dump,--preferences,--logs,--env
Subcommand run
This command replaces commons/src/lib/run.ts which spawns debug configurations.
- Using
CLI::App* run_cmd = kbot_cmd->add_subcommand("run", "Run a launch.json configuration"); - Arguments to Map:
--config(defaultdefault)--dry(flag)--list(flag)--projectPath(defaultprocess.cwd())--logFilePath(defaultlog-configuration.json)
2. Multithreading & Execution Pattern
Referencing cmd_gridsearch.h, the port will leverage tf::Taskflow and tf::Executor along with moodycamel::ConcurrentQueue for processing parallel tasks (like running a prompt against multiple items via --each).
- Architecture Details:
- Config Loading: Read preferences/configs (using
tomlplusplusorrapidjson). - Globbing / Resolution: Resolve paths using
--include/--exclude/--each. - Task Queueing: For every item resolved by
--each, queue a task. - Task Execution (Stubbed): The concurrent thread handles creating the LLM request.
- Streaming / Output: Results stream back (or are written to
--dst), potentially emitting events over an IPC channel or tostdoutdepending on daemon mode setups.
- Config Loading: Read preferences/configs (using
3. Testing Setup
We'll replicate the testing approach found in tests/ utilizing Catch2 for BDD/TDD styled tests.
- Target Files:
tests/test_cmd_kbot.cpptests/test_kbot_run.cpp
- Cases to cover:
- Validation of CLI argument defaults against
zod_schema.ts. - Behavior of
kbot run --listcorrectly interpreting a mock.vscode/launch.json. - Dry run of the
--eachpipeline ensuring tasks get initialized properly.
- Validation of CLI argument defaults against
Next Steps (Scaffolding Phase)
- Add
cmd_kbot.h/cppwith the CLI schema variables. - Hook up the subcommands in
main.cpp. - Stub the execution functions (
run_cmd_kbot_aiandrun_cmd_kbot_run) just to print out the parsed JSON representing the state. - Add the targets to
CMakeLists.txtand verify the build passes. - Create initial Catch2 tests just to ensure the flags parse correctly without crashing.