apcore-cli (Rust)
Terminal adapter for apcore. Execute AI-Perceivable modules from the command line.
| Rust SDK | github.com/aipartnerup/apcore-cli-rust |
| Python SDK | github.com/aipartnerup/apcore-cli-python |
| Spec repo | github.com/aipartnerup/apcore-cli |
| apcore core | github.com/aipartnerup/apcore |
apcore-cli turns any apcore-based project into a fully featured CLI tool -- with zero code changes to your existing modules.
┌──────────────────┐
│ your-apcore │ <- your existing apcore project (unchanged)
│ ... │
└────────┬─────────┘
│ extensions directory
v
┌──────────────────┐
│ apcore-cli │ <- just install & point to extensions dir
└───┬──────────┬───┘
│ │
v v
Terminal Unix
Commands Pipes
Design Philosophy
- Zero intrusion -- your apcore project needs no code changes, no imports, no dependencies on apcore-cli
- Zero configuration -- point to an extensions directory, everything is auto-discovered
- Pure adapter -- apcore-cli reads from the apcore Registry; it never modifies your modules
- Unix-native -- JSON output for pipes, rich tables for terminals, STDIN input, shell completions
Installation
Requires Rust 1.75+ and apcore >= 0.13.0.
Quick Start
Try it now
The repo includes 8 example modules you can run immediately:
# Add .bin to PATH for this session
# Run a module
# {"sum": 15}
# Or use the exec subcommand
# List all modules
# Run all examples
Note: If you have the Python version of
apcore-cliinstalled,make buildplaces the Rust binary at.bin/apcore-cli. Prepend.binto your PATH (as shown above) to use the Rust version in this project.
See Examples for the full list of example modules and usage patterns.
Zero-code approach
If you already have an apcore-based project with an extensions directory:
# Execute a module
# Or set the env var once
All modules are auto-discovered. CLI flags are auto-generated from each module's JSON Schema.
Integration with Existing Projects
Typical apcore project structure
your-project/
├── extensions/ <- modules live here
│ ├── math/
│ │ └── add.rs
│ ├── text/
│ │ └── upper.rs
│ └── ...
├── your_app.rs <- your existing code (untouched)
└── ...
Adding CLI support
No changes to your project. Just install and run:
STDIN piping (Unix pipes)
# Pipe JSON input
|
# {"sum": 300}
# CLI flags override STDIN values
|
# {"sum": 1001}
# Chain with other tools
|
CLI Reference
apcore-cli [OPTIONS] COMMAND [ARGS]
Global Options
| Option | Default | Description |
|---|---|---|
--extensions-dir |
./extensions |
Path to apcore extensions directory |
--log-level |
WARNING |
Logging: DEBUG, INFO, WARNING, ERROR |
--version |
Show version and exit | |
--help |
Show help and exit |
Built-in Commands
| Command | Description |
|---|---|
exec <module_id> |
Execute a module by ID (with --input, --yes, --format, --sandbox flags) |
list |
List available modules with optional tag filtering |
describe <module_id> |
Show full module metadata and schemas |
completion <shell> |
Generate shell completion script (bash/zsh/fish/elvish/powershell) |
man <command> |
Generate man page in roff format |
Module Execution Options
When executing a module (e.g. apcore-cli math.add or apcore-cli exec math.add), these built-in options are always available:
| Option | Description |
|---|---|
--input - |
Read JSON input from STDIN |
--yes / -y |
Bypass approval prompts |
--large-input |
Allow STDIN input larger than 10MB |
--format |
Output format: json or table |
--sandbox |
Run module in subprocess sandbox |
Schema-generated flags (e.g. --a, --b) are added automatically from the module's input_schema.
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Module execution error |
2 |
Invalid CLI input |
44 |
Module not found / disabled / load error |
45 |
Schema validation error |
46 |
Approval denied or timed out |
47 |
Configuration error |
48 |
Schema circular reference |
77 |
ACL denied |
130 |
Execution cancelled (Ctrl+C) |
Configuration
apcore-cli uses a 4-tier configuration precedence:
- CLI flag (highest):
--extensions-dir ./custom - Environment variable:
APCORE_EXTENSIONS_ROOT=./custom - Config file:
apcore.yaml - Default (lowest):
./extensions
Environment Variables
| Variable | Description | Default |
|---|---|---|
APCORE_EXTENSIONS_ROOT |
Path to extensions directory | ./extensions |
APCORE_CLI_AUTO_APPROVE |
Set to 1 to bypass all approval prompts |
(unset) |
APCORE_CLI_LOGGING_LEVEL |
CLI-specific log level (takes priority over APCORE_LOGGING_LEVEL) |
WARNING |
APCORE_LOGGING_LEVEL |
Global apcore log level (fallback when APCORE_CLI_LOGGING_LEVEL is unset) |
WARNING |
APCORE_AUTH_API_KEY |
API key for remote registry authentication | (unset) |
APCORE_CLI_SANDBOX |
Set to 1 to enable subprocess sandboxing |
(unset) |
Config File (apcore.yaml)
extensions:
root: ./extensions
logging:
level: DEBUG
sandbox:
enabled: false
Features
- Auto-discovery -- all modules in the extensions directory are found and exposed as CLI commands
- Auto-generated flags -- JSON Schema
input_schemais converted to--flag valueCLI options with type validation - Boolean flag pairs --
--verbose/--no-verbosefrom"type": "boolean"schema properties - Enum choices --
"enum": ["json", "csv"]becomes--format jsonwith clap validation - STDIN piping --
--input -reads JSON from STDIN, CLI flags override for duplicate keys - TTY-adaptive output -- comfy-table for terminals, JSON for pipes (configurable via
--format) - Approval gate -- TTY-aware HITL prompts for modules with
requires_approval: true, with--yesbypass and 60s timeout - Schema validation -- inputs validated against JSON Schema before execution, with
$ref/allOf/anyOf/oneOfresolution - Security -- API key auth (keyring + AES-256-GCM), append-only audit logging, subprocess sandboxing
- Shell completions --
apcore-cli completion bash|zsh|fish|elvish|powershellgenerates completion scripts - Man pages --
apcore-cli man <command>generates roff-formatted man pages - Audit logging -- all executions logged to
~/.apcore-cli/audit.jsonlwith SHA-256 input hashing
How It Works
Mapping: apcore to CLI
| apcore | CLI |
|---|---|
module_id (math.add) |
Command name (apcore-cli math.add or apcore-cli exec math.add) |
description |
--help text |
input_schema.properties |
CLI flags (--a, --b) |
input_schema.required |
Validated post-collection (required fields shown as [required] in --help) |
annotations.requires_approval |
HITL approval prompt |
Architecture
User / AI Agent (terminal)
|
v
apcore-cli (the adapter)
|
+-- ConfigResolver 4-tier config precedence
+-- LazyModuleGroup Dynamic clap command generation
+-- SchemaParser JSON Schema -> clap options
+-- RefResolver $ref / allOf / anyOf / oneOf
+-- ApprovalGate TTY-aware HITL approval (tokio::select!)
+-- OutputFormatter TTY-adaptive JSON/table output (comfy-table)
+-- AuditLogger JSON Lines execution logging
+-- Sandbox tokio subprocess isolation
|
v
apcore Registry + Executor (your modules, unchanged)
Development
Getting Started
# use Rust version in this session
Daily Workflow
# Build and run
# Run all checks (same as pre-commit hook: fmt + clippy + tests)
# Run individual steps
Adding a New Module Descriptor
Each module is discovered via a module.json file in the extensions directory:
extensions/
└── math/
└── add/
└── module.json <- descriptor file
The CLI auto-discovers all module.json files recursively under --extensions-dir.
Key Dependencies
| Crate | Purpose |
|---|---|
clap 4 |
CLI framework (derive + env + string) |
tokio 1 |
Async runtime (process, signal, time) |
serde / serde_json / serde_yaml |
Serialization |
comfy-table 6 |
Terminal table rendering |
aes-gcm / sha2 / pbkdf2 |
Cryptography |
keyring 2 |
OS keyring access |
clap_complete 4 |
Shell completion generation |
thiserror / anyhow |
Error handling |
tracing |
Structured logging |
Examples
The repo includes 8 runnable example modules and a guide for writing your own.
&&
See examples/README.md for the full module list, authoring guide, and STDIN piping patterns.
License
Apache-2.0