Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,26 @@ meson setup build/esp32s3-qemu/meson --cross-file build/esp32s3-qemu/cross.ini
meson compile -C build/esp32s3-qemu/meson
```

## Configuration (env vars)
## Configuration

All platforms support environment variables for credentials (read at build time):
All rt-claw business config (AI, Feishu, tuning) lives in `claw_config.h` (project root).
Credentials are set via Meson or environment variables — NOT in vendor SDK configs.

```bash
# Environment variables (read at Meson configure time)
export RTCLAW_AI_API_KEY='sk-...' # AI API key
export RTCLAW_AI_API_URL='https://...' # API endpoint
export RTCLAW_AI_MODEL='claude-sonnet-4-6' # Model name
export RTCLAW_FEISHU_APP_ID='cli_...' # Feishu App ID
export RTCLAW_FEISHU_APP_SECRET='...' # Feishu App Secret

# Or Meson options
meson configure build/<platform>/meson -Dai_api_key='sk-...'
```

Priority: meson option (`-Dai_api_key=...`) > env var > ESP-IDF menuconfig/sdkconfig > `claw_config.h` default.
Priority: meson option (`-Dai_api_key=...`) > env var (`RTCLAW_AI_API_KEY`) > `claw_config.h` default.

Meson generates `claw_config_generated.h` in the build directory with the resolved values.

## Run

Expand Down Expand Up @@ -121,7 +128,7 @@ No unit test framework yet. Verify changes by:
|------|---------|
| `Makefile` | Unified build entry point |
| `meson.build` | Root Meson project (cross-compiles claw/ + osal/) |
| `meson_options.txt` | Build options (osal backend, feature flags) |
| `meson_options.txt` | Build options (osal backend, feature flags, AI/Feishu config) |
| `build/<platform>/` | Build outputs (gitignored) |
| `include/` | Unified public headers (claw_os.h, claw_net.h, claw_board.h, etc.) |
| `include/drivers/` | Driver public headers (mirror of drivers/ structure) |
Expand All @@ -136,7 +143,8 @@ No unit test framework yet. Verify changes by:
| `vendor/os/freertos/` | FreeRTOS-Kernel (submodule) |
| `vendor/os/rt-thread/` | RT-Thread (submodule) |
| `claw/claw_init.c` | Boot entry point |
| `include/claw/claw_config.h` | Compile-time constants (platform-independent) |
| `claw_config.h` | Unified compile-time configuration (project root) |
| `claw_config_generated.h.in` | Meson template for generated config header |
| `claw/core/gateway.c` | Message router |
| `claw/services/{ai,net,swarm,im}/` | Service modules |
| `claw/tools/` | Tool Use framework |
Expand Down
2 changes: 1 addition & 1 deletion claw/claw_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "claw/claw_init.h"
#include "claw/core/claw_service.h"
#include "claw/core/gateway.h"
Expand Down
2 changes: 1 addition & 1 deletion claw/core/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "claw/core/heartbeat.h"
#include "claw/core/scheduler.h"
#include "claw/services/ai/ai_engine.h"
Expand Down
2 changes: 1 addition & 1 deletion claw/core/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "claw/core/scheduler.h"

#include <string.h>
Expand Down
4 changes: 2 additions & 2 deletions claw/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ if get_option('heartbeat')
endif

rtclaw_lib = static_library('rtclaw', src_files,
include_directories: [claw_inc] + platform_incs,
include_directories: [claw_root_inc, claw_inc] + platform_incs,
dependencies: [osal_dep, cjson_dep],
c_args: feature_defs,
)

rtclaw_dep = declare_dependency(
link_with: rtclaw_lib,
include_directories: claw_inc,
include_directories: [claw_root_inc, claw_inc],
)
2 changes: 1 addition & 1 deletion claw/services/ai/ai_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "osal/claw_net.h"
#include "claw/services/ai/ai_engine.h"
#include "claw/services/ai/ai_memory.h"
Expand Down
2 changes: 1 addition & 1 deletion claw/services/ai/ai_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "claw/services/ai/ai_memory.h"

#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion claw/services/swarm/swarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "osal/claw_net.h"
#include "claw/services/swarm/swarm.h"
#include "claw/tools/claw_tools.h"
Expand Down
2 changes: 1 addition & 1 deletion claw/tools/claw_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

#include "claw/tools/claw_tools.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#ifdef CONFIG_RTCLAW_SKILL_ENABLE
#include "claw/services/ai/ai_skill.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion claw/tools/tool_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "claw/tools/claw_tools.h"
#include "claw/claw_config.h"
#include "claw_config.h"

#include <string.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion claw/tools/tool_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "claw/tools/claw_tools.h"
#include "claw/claw_config.h"
#include "claw_config.h"
#include "claw/services/ai/ai_memory.h"

#include <stdio.h>
Expand Down
95 changes: 95 additions & 0 deletions claw_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2026, Chao Liu <chao.liu.zevorn@gmail.com>
* SPDX-License-Identifier: MIT
*
* Global compile-time configuration for rt-claw.
*
* This is the single source of truth for all rt-claw business configuration.
* Credentials and tunable parameters are set by the Meson build system
* (via meson options or environment variables) and written into
* claw_config_generated.h. The #ifndef guards below provide defaults
* when a value is not set by the build system.
*
* Configuration methods (priority high to low):
* 1. Meson option: meson setup ... -Dai_api_key='sk-...'
* 2. Environment var: export RTCLAW_AI_API_KEY='sk-...'
* 3. Defaults below
*
* Feature flags (CONFIG_RTCLAW_*_ENABLE, CONFIG_RTCLAW_TOOL_*) are set
* per-platform:
* - ESP-IDF: Kconfig -> sdkconfig -> compiler flags
* - RT-Thread: CFLAGS in rtconfig.py
*/

#ifndef CLAW_CONFIG_H
#define CLAW_CONFIG_H

/*
* Include build-system generated overrides.
* This header is produced by Meson's configure_file() and lives in the
* build directory. Values set here take precedence over the #ifndef
* defaults below.
*/
#ifdef CLAW_HAS_GENERATED_CONFIG
#include "claw_config_generated.h"
#endif

#define RT_CLAW_VERSION "0.1.0"

/* ---- Gateway ---- */
#define CLAW_GW_MSG_POOL_SIZE 16
#define CLAW_GW_MSG_MAX_LEN 256
#define CLAW_GW_THREAD_STACK 4096
#define CLAW_GW_THREAD_PRIO 15

/* ---- Swarm ---- */
#define CLAW_SWARM_MAX_NODES 32
#define CLAW_SWARM_HEARTBEAT_MS 5000
#define CLAW_SWARM_TIMEOUT_MS 15000
#define CLAW_SWARM_PORT 5300
#define CLAW_SWARM_THREAD_STACK 4096
#define CLAW_SWARM_THREAD_PRIO 12

/* ---- Scheduler ---- */
#define CLAW_SCHED_MAX_TASKS 8
#define CLAW_SCHED_TICK_MS 1000
#define CLAW_SCHED_THREAD_STACK 8192
#define CLAW_SCHED_THREAD_PRIO 10

/* ---- Heartbeat (periodic AI check-in) ---- */
#define CLAW_HEARTBEAT_INTERVAL_MS 300000 /* 5 minutes */
#define CLAW_HEARTBEAT_MAX_EVENTS 8
#define CLAW_HEARTBEAT_MSG_MAX 128
#define CLAW_HEARTBEAT_PROMPT_MAX 1024
#define CLAW_HEARTBEAT_REPLY_MAX 512
#define CLAW_HEARTBEAT_THREAD_STACK 8192

/* ---- AI Engine ---- */
#ifndef CONFIG_RTCLAW_AI_API_KEY
#define CONFIG_RTCLAW_AI_API_KEY ""
#endif
#ifndef CONFIG_RTCLAW_AI_API_URL
#define CONFIG_RTCLAW_AI_API_URL "http://10.0.2.2:8888/v1/messages"
#endif
#ifndef CONFIG_RTCLAW_AI_MODEL
#define CONFIG_RTCLAW_AI_MODEL "claude-opus-4-6"
#endif
#ifndef CONFIG_RTCLAW_AI_MAX_TOKENS
#define CONFIG_RTCLAW_AI_MAX_TOKENS 1024
#endif
#ifndef CONFIG_RTCLAW_AI_CONTEXT_SIZE
#define CONFIG_RTCLAW_AI_CONTEXT_SIZE 8192
#endif
#ifndef CONFIG_RTCLAW_AI_MEMORY_MAX_MSGS
#define CONFIG_RTCLAW_AI_MEMORY_MAX_MSGS 20
#endif

/* ---- Feishu (Lark) IM ---- */
#ifndef CONFIG_RTCLAW_FEISHU_APP_ID
#define CONFIG_RTCLAW_FEISHU_APP_ID ""
#endif
#ifndef CONFIG_RTCLAW_FEISHU_APP_SECRET
#define CONFIG_RTCLAW_FEISHU_APP_SECRET ""
#endif

#endif /* CLAW_CONFIG_H */
25 changes: 25 additions & 0 deletions claw_config_generated.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Auto-generated by Meson build system — do not edit.
*
* Values come from: meson options (-Dai_api_key=...) or
* environment variables (RTCLAW_AI_API_KEY=...).
*
* Undefined entries fall through to claw_config.h defaults.
*/

#ifndef CLAW_CONFIG_GENERATED_H
#define CLAW_CONFIG_GENERATED_H

/* AI Engine */
#mesondefine CONFIG_RTCLAW_AI_API_KEY
#mesondefine CONFIG_RTCLAW_AI_API_URL
#mesondefine CONFIG_RTCLAW_AI_MODEL
#mesondefine CONFIG_RTCLAW_AI_MAX_TOKENS
#mesondefine CONFIG_RTCLAW_AI_CONTEXT_SIZE
#mesondefine CONFIG_RTCLAW_AI_MEMORY_MAX_MSGS

/* Feishu (Lark) IM */
#mesondefine CONFIG_RTCLAW_FEISHU_APP_ID
#mesondefine CONFIG_RTCLAW_FEISHU_APP_SECRET

#endif /* CLAW_CONFIG_GENERATED_H */
2 changes: 1 addition & 1 deletion include/claw/core/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLAW_CORE_GATEWAY_H

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"

enum gateway_msg_type {
GW_MSG_DATA = 0,
Expand Down
2 changes: 1 addition & 1 deletion include/claw/core/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLAW_SCHEDULER_H

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"

typedef void (*sched_callback_t)(void *arg);

Expand Down
2 changes: 1 addition & 1 deletion include/claw/services/swarm/swarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLAW_SERVICES_SWARM_H

#include "osal/claw_os.h"
#include "claw/claw_config.h"
#include "claw_config.h"

enum swarm_node_state {
SWARM_NODE_OFFLINE = 0,
Expand Down
72 changes: 54 additions & 18 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,76 @@ elif osal_backend == 'freertos'
platform_defs += ['-DCLAW_PLATFORM_ESP_IDF']
endif

# Runtime config overrides.
# Priority: meson option (-Dai_api_key=...) > env var (RTCLAW_*) > claw_config.h default.
# ---- Unified configuration via claw_config_generated.h ----
#
# For ESP-IDF (freertos): env vars are handled by gen-esp32*-cross.py which
# generates an env_override.h included AFTER sdkconfig.h — no -D conflict.
# Meson options still work for all platforms via -D flags below.
# All rt-claw credentials and tunable parameters are configured here,
# NOT in vendor SDK configs (ESP-IDF Kconfig, RT-Thread rtconfig).
#
# Each entry: [env_var_name, config_macro_name]
_env_overrides = {
# Priority: meson option (-Dai_api_key=...) > env var (RTCLAW_AI_API_KEY)
# > claw_config.h #ifndef default.
#
# String config: [meson_option, env_var_name, config_macro_name]
_str_overrides = {
'ai_api_key': ['RTCLAW_AI_API_KEY', 'CONFIG_RTCLAW_AI_API_KEY'],
'ai_api_url': ['RTCLAW_AI_API_URL', 'CONFIG_RTCLAW_AI_API_URL'],
'ai_model': ['RTCLAW_AI_MODEL', 'CONFIG_RTCLAW_AI_MODEL'],
'feishu_app_id': ['RTCLAW_FEISHU_APP_ID', 'CONFIG_RTCLAW_FEISHU_APP_ID'],
'feishu_app_secret':['RTCLAW_FEISHU_APP_SECRET','CONFIG_RTCLAW_FEISHU_APP_SECRET'],
}

foreach opt_name, pair : _env_overrides
# Integer config: [meson_option, env_var_name, config_macro_name]
_int_overrides = {
'ai_max_tokens': ['RTCLAW_AI_MAX_TOKENS', 'CONFIG_RTCLAW_AI_MAX_TOKENS'],
'ai_context_size': ['RTCLAW_AI_CONTEXT_SIZE', 'CONFIG_RTCLAW_AI_CONTEXT_SIZE'],
'ai_memory_max_msgs': ['RTCLAW_AI_MEMORY_MAX_MSGS', 'CONFIG_RTCLAW_AI_MEMORY_MAX_MSGS'],
}

conf_data = configuration_data()
_has_any = false

foreach opt_name, pair : _str_overrides
_val = get_option(opt_name)
if _val == ''
# For freertos (ESP-IDF), env vars are injected via cross.ini
# override header; only read env here for non-ESP platforms.
if osal_backend != 'freertos'
_r = run_command('sh', '-c', 'printf "%s" "${' + pair[0] + ':-}"',
check: false)
_val = _r.stdout().strip()
endif
_r = run_command('sh', '-c',
'printf "%s" "${' + pair[0] + ':-}"', check: false)
_val = _r.stdout().strip()
endif
if _val != ''
_macro = pair[1]
platform_defs += ['-U' + _macro, '-D' + _macro + '="' + _val + '"']
conf_data.set_quoted(pair[1], _val)
_has_any = true
endif
endforeach

# Unified header directory for all rt-claw public headers
foreach opt_name, pair : _int_overrides
_val = get_option(opt_name)
if _val > 0
conf_data.set(pair[1], _val)
_has_any = true
else
_r = run_command('sh', '-c',
'printf "%s" "${' + pair[0] + ':-}"', check: false)
_env = _r.stdout().strip()
if _env != ''
conf_data.set(pair[1], _env.to_int())
_has_any = true
endif
endif
endforeach

claw_config_gen = configure_file(
input: 'claw_config_generated.h.in',
output: 'claw_config_generated.h',
configuration: conf_data,
)

# Tell claw_config.h to include the generated header
platform_defs += ['-DCLAW_HAS_GENERATED_CONFIG']

# Unified header directories:
# - project root: claw_config.h
# - include/: all other public headers
# - build dir: claw_config_generated.h (added implicitly by Meson)
claw_root_inc = include_directories('.')
claw_inc = include_directories('include')

subdir('vendor/lib/cjson')
Expand Down
Loading
Loading