diff --git a/application/basic_demo/fatfs_image/skills/cap_lua_skills.md b/application/basic_demo/fatfs_image/skills/cap_lua_run.md similarity index 100% rename from application/basic_demo/fatfs_image/skills/cap_lua_skills.md rename to application/basic_demo/fatfs_image/skills/cap_lua_run.md diff --git a/application/basic_demo/fatfs_image/skills/lua_module_delay.md b/application/basic_demo/fatfs_image/skills/lua_module_delay.md new file mode 100644 index 0000000..a186617 --- /dev/null +++ b/application/basic_demo/fatfs_image/skills/lua_module_delay.md @@ -0,0 +1,14 @@ +# Lua Delay + +This skill describes how to correctly use delay when writing Lua scripts. + +## How to call +- Import it with `local delay = require("delay")` +- Call `delay.delay_ms(ms)` to sleep for a number of milliseconds +- `ms` should be an integer greater than or equal to `0` + +## Example +```lua +local delay = require("delay") +delay.delay_ms(500) +``` diff --git a/application/basic_demo/fatfs_image/skills/lua_module_event_publisher.md b/application/basic_demo/fatfs_image/skills/lua_module_event_publisher.md new file mode 100644 index 0000000..6e1010c --- /dev/null +++ b/application/basic_demo/fatfs_image/skills/lua_module_event_publisher.md @@ -0,0 +1,21 @@ +# Lua Event Publisher + +This skill describes how to correctly use event_publisher when writing Lua scripts. + +## How to call +- Import it with `local event_publisher = require("event_publisher")` +- Call `event_publisher.publish_message({...})` to publish a message event +- Call `event_publisher.publish_trigger({...})` to publish a trigger event +- Call `event_publisher.publish({...})` to publish a full custom event + +## Example +```lua +local event_publisher = require("event_publisher") + +event_publisher.publish_message({ + source_cap = "lua_script", + channel = "custom", + chat_id = "demo", + text = "hello" +}) +``` diff --git a/application/basic_demo/fatfs_image/skills/lua_module_gpio.md b/application/basic_demo/fatfs_image/skills/lua_module_gpio.md new file mode 100644 index 0000000..ec5361e --- /dev/null +++ b/application/basic_demo/fatfs_image/skills/lua_module_gpio.md @@ -0,0 +1,16 @@ +# Lua GPIO + +This skill describes how to correctly use gpio when writing Lua scripts. + +## How to call +- Import it with `local gpio = require("gpio")` +- Call `gpio.set_direction(pin, mode)` to set pin mode +- Call `gpio.set_level(pin, level)` to set output level +- Call `gpio.get_level(pin)` to read pin level + +## Example +```lua +local gpio = require("gpio") +gpio.set_direction(2, "output") +gpio.set_level(2, 1) +``` diff --git a/application/basic_demo/fatfs_image/skills/lua_module_led_strip.md b/application/basic_demo/fatfs_image/skills/lua_module_led_strip.md new file mode 100644 index 0000000..8bbe88d --- /dev/null +++ b/application/basic_demo/fatfs_image/skills/lua_module_led_strip.md @@ -0,0 +1,19 @@ +# Lua LED Strip + +This skill describes how to correctly use led_strip when writing Lua scripts. + +## How to call +- Import it with `local led_strip = require("led_strip")` +- Call `local strip = led_strip.new(gpio, max_leds)` to create a strip handle +- Call `strip:set_pixel(index, r, g, b)` to set one pixel +- Call `strip:refresh()` to apply changes +- Call `strip:clear()` or `strip:close()` when needed + +## Example +```lua +local led_strip = require("led_strip") + +local strip = led_strip.new(8, 1) +strip:set_pixel(0, 255, 0, 0) +strip:refresh() +``` diff --git a/application/basic_demo/fatfs_image/skills/lua_module_storage.md b/application/basic_demo/fatfs_image/skills/lua_module_storage.md new file mode 100644 index 0000000..ecd9746 --- /dev/null +++ b/application/basic_demo/fatfs_image/skills/lua_module_storage.md @@ -0,0 +1,18 @@ +# Lua Storage + +This skill describes how to correctly use storage when writing Lua scripts. + +## How to call +- Import it with `local storage = require("storage")` +- Call `storage.mkdir(path)` to create a directory +- Call `storage.write_file(path, content)` to write a file +- Call `storage.read_file(path)` to read a file + +## Example +```lua +local storage = require("storage") + +storage.mkdir("/fatfs/data/demo") +storage.write_file("/fatfs/data/demo/test.txt", "hello") +local text = storage.read_file("/fatfs/data/demo/test.txt") +``` diff --git a/application/basic_demo/fatfs_image/skills/skills_list.json b/application/basic_demo/fatfs_image/skills/skills_list.json index 9522794..331ed07 100644 --- a/application/basic_demo/fatfs_image/skills/skills_list.json +++ b/application/basic_demo/fatfs_image/skills/skills_list.json @@ -1,49 +1,94 @@ { "skills": [ { - "id": "cap_im_feishu_skill", - "file": "cap_im_feishu_skill.md", - "title": "cap_im_feishu_skill", + "id": "cap_im_feishu", + "file": "cap_im_feishu.md", + "title": "cap_im_feishu", "summary": "How to reply and send text, images, and files through Feishu capabilities.", "cap_groups": [ "cap_im_feishu" ] }, { - "id": "cap_im_qq_skill", - "file": "cap_im_qq_skill.md", - "title": "cap_im_qq_skill", + "id": "cap_im_qq", + "file": "cap_im_qq.md", + "title": "cap_im_qq", "summary": "Reply in the QQ conversation or send local files back to QQ", "cap_groups": [ "cap_im_qq" ] }, { - "id": "cap_im_tg_skill", - "file": "cap_im_tg_skill.md", - "title": "cap_im_tg_skill", + "id": "cap_im_tg", + "file": "cap_im_tg.md", + "title": "cap_im_tg", "summary": "How to reply and send text, images, and files through Telegram capabilities.", "cap_groups": [ "cap_im_tg" ] }, { - "id": "cap_im_wechat_skill", - "file": "cap_im_wechat_skill.md", - "title": "cap_im_wechat_skill", + "id": "cap_im_wechat", + "file": "cap_im_wechat.md", + "title": "cap_im_wechat", "summary": "How to send text and images through WeChat capabilities.", "cap_groups": [ "cap_im_wechat" ] }, { - "id": "cap_lua_skills", - "file": "cap_lua_skills.md", - "title": "cap_lua_skills", + "id": "cap_lua_run", + "file": "cap_lua_run.md", + "title": "cap_lua_run", "summary": "This Files describes how to correctly use Lua scripts.", "cap_groups": [ "cap_lua" ] + }, + { + "id": "lua_module_delay", + "file": "lua_module_delay.md", + "title": "lua_module_delay", + "summary": "How to call delay.delay_ms(ms) from Lua after loading the delay module.", + "cap_groups": [ + "cap_lua" + ] + }, + { + "id": "lua_module_event_publisher", + "file": "lua_module_event_publisher.md", + "title": "lua_module_event_publisher", + "summary": "How to publish message, trigger, and custom events from Lua.", + "cap_groups": [ + "cap_lua" + ] + }, + { + "id": "lua_module_gpio", + "file": "lua_module_gpio.md", + "title": "lua_module_gpio", + "summary": "How to set GPIO direction, write level, and read level from Lua.", + "cap_groups": [ + "cap_lua" + ] + }, + { + "id": "lua_module_led_strip", + "file": "lua_module_led_strip.md", + "title": "lua_module_led_strip", + "summary": "How to create and control an LED strip from Lua.", + "cap_groups": [ + "cap_lua" + ] + }, + { + "id": "lua_module_storage", + "file": "lua_module_storage.md", + "title": "lua_module_storage", + "summary": "How to create directories and read or write files from Lua.", + "cap_groups": [ + "cap_lua" + ] } ] } diff --git a/components/claw_capabilities/cap_lua/skills/cap_lua_edit.md b/components/claw_capabilities/cap_lua/skills/cap_lua_edit.md new file mode 100644 index 0000000..0af9d47 --- /dev/null +++ b/components/claw_capabilities/cap_lua/skills/cap_lua_edit.md @@ -0,0 +1,25 @@ +# Lua Script Editing + +Use this skill when the user wants to create or modify a Lua script. + +## Module Rule +- Before writing Lua code, first activate all available `lua_module_xxx` skills. +- Read those skills to learn which Lua modules are available and how to call them. +- Treat the activated `lua_module_xxx` skills as the source of truth for usable Lua modules in this firmware. + +## Import Rule +- Only use Lua modules that are described by the activated `lua_module_xxx` skills. +- Do not use `require(...)` for any module outside that set. +- Do not assume standard Lua libraries or third-party Lua modules are available unless they are explicitly described by an activated `lua_module_xxx` skill. +- If a needed capability is not covered by the activated `lua_module_xxx` skills, do not invent an API. Change the script design to use only the available modules. + +## Writing Rule +- Prefer small, direct scripts that only depend on the available Lua modules. +- When using a module, follow the exact import name and function names documented by its `lua_module_xxx` skill. +- If the user asks for behavior that depends on GPIO, delay, storage, LED strip, or event publishing, activate the matching module skills first and then write the script. + +## Workflow +1. Activate all `lua_module_xxx` skills. +2. Check which modules and functions are available. +3. Write or update the Lua script using only those modules. +4. Save the script through the Lua authoring capability flow. diff --git a/components/claw_modules/claw_skill/src/claw_skill.c b/components/claw_modules/claw_skill/src/claw_skill.c index ee93d05..1041286 100644 --- a/components/claw_modules/claw_skill/src/claw_skill.c +++ b/components/claw_modules/claw_skill/src/claw_skill.c @@ -19,7 +19,7 @@ static const char *TAG = "claw_skill"; static const char *SKILLS_LIST_FILE = "skills_list.json"; -#define CLAW_SKILL_DEFAULT_MAX_FILES 32 +#define CLAW_SKILL_DEFAULT_MAX_FILES 64 #define CLAW_SKILL_DEFAULT_MAX_BYTES 2048 #define CLAW_SKILL_MAX_PATH 192 diff --git a/components/lua_modules/lua_module_delay/skills/lua_module_delay.md b/components/lua_modules/lua_module_delay/skills/lua_module_delay.md new file mode 100644 index 0000000..a186617 --- /dev/null +++ b/components/lua_modules/lua_module_delay/skills/lua_module_delay.md @@ -0,0 +1,14 @@ +# Lua Delay + +This skill describes how to correctly use delay when writing Lua scripts. + +## How to call +- Import it with `local delay = require("delay")` +- Call `delay.delay_ms(ms)` to sleep for a number of milliseconds +- `ms` should be an integer greater than or equal to `0` + +## Example +```lua +local delay = require("delay") +delay.delay_ms(500) +``` diff --git a/components/lua_modules/lua_module_delay/skills/skills_list.json b/components/lua_modules/lua_module_delay/skills/skills_list.json new file mode 100644 index 0000000..e8452ab --- /dev/null +++ b/components/lua_modules/lua_module_delay/skills/skills_list.json @@ -0,0 +1,13 @@ +{ + "skills": [ + { + "id": "lua_module_delay", + "file": "lua_module_delay.md", + "title": "lua_module_delay", + "summary": "How to call delay.delay_ms(ms) from Lua after loading the delay module.", + "cap_groups": [ + "cap_lua" + ] + } + ] +} diff --git a/components/lua_modules/lua_module_event_publisher/skills/lua_module_event_publisher.md b/components/lua_modules/lua_module_event_publisher/skills/lua_module_event_publisher.md new file mode 100644 index 0000000..6e1010c --- /dev/null +++ b/components/lua_modules/lua_module_event_publisher/skills/lua_module_event_publisher.md @@ -0,0 +1,21 @@ +# Lua Event Publisher + +This skill describes how to correctly use event_publisher when writing Lua scripts. + +## How to call +- Import it with `local event_publisher = require("event_publisher")` +- Call `event_publisher.publish_message({...})` to publish a message event +- Call `event_publisher.publish_trigger({...})` to publish a trigger event +- Call `event_publisher.publish({...})` to publish a full custom event + +## Example +```lua +local event_publisher = require("event_publisher") + +event_publisher.publish_message({ + source_cap = "lua_script", + channel = "custom", + chat_id = "demo", + text = "hello" +}) +``` diff --git a/components/lua_modules/lua_module_event_publisher/skills/skills_list.json b/components/lua_modules/lua_module_event_publisher/skills/skills_list.json new file mode 100644 index 0000000..a332ab5 --- /dev/null +++ b/components/lua_modules/lua_module_event_publisher/skills/skills_list.json @@ -0,0 +1,13 @@ +{ + "skills": [ + { + "id": "lua_module_event_publisher", + "file": "lua_module_event_publisher.md", + "title": "lua_module_event_publisher", + "summary": "How to publish message, trigger, and custom events from Lua.", + "cap_groups": [ + "cap_lua" + ] + } + ] +} diff --git a/components/lua_modules/lua_module_gpio/skills/lua_module_gpio.md b/components/lua_modules/lua_module_gpio/skills/lua_module_gpio.md new file mode 100644 index 0000000..ec5361e --- /dev/null +++ b/components/lua_modules/lua_module_gpio/skills/lua_module_gpio.md @@ -0,0 +1,16 @@ +# Lua GPIO + +This skill describes how to correctly use gpio when writing Lua scripts. + +## How to call +- Import it with `local gpio = require("gpio")` +- Call `gpio.set_direction(pin, mode)` to set pin mode +- Call `gpio.set_level(pin, level)` to set output level +- Call `gpio.get_level(pin)` to read pin level + +## Example +```lua +local gpio = require("gpio") +gpio.set_direction(2, "output") +gpio.set_level(2, 1) +``` diff --git a/components/lua_modules/lua_module_gpio/skills/skills_list.json b/components/lua_modules/lua_module_gpio/skills/skills_list.json new file mode 100644 index 0000000..f0ede28 --- /dev/null +++ b/components/lua_modules/lua_module_gpio/skills/skills_list.json @@ -0,0 +1,13 @@ +{ + "skills": [ + { + "id": "lua_module_gpio", + "file": "lua_module_gpio.md", + "title": "lua_module_gpio", + "summary": "How to set GPIO direction, write level, and read level from Lua.", + "cap_groups": [ + "cap_lua" + ] + } + ] +} diff --git a/components/lua_modules/lua_module_led_strip/skills/lua_module_led_strip.md b/components/lua_modules/lua_module_led_strip/skills/lua_module_led_strip.md new file mode 100644 index 0000000..8bbe88d --- /dev/null +++ b/components/lua_modules/lua_module_led_strip/skills/lua_module_led_strip.md @@ -0,0 +1,19 @@ +# Lua LED Strip + +This skill describes how to correctly use led_strip when writing Lua scripts. + +## How to call +- Import it with `local led_strip = require("led_strip")` +- Call `local strip = led_strip.new(gpio, max_leds)` to create a strip handle +- Call `strip:set_pixel(index, r, g, b)` to set one pixel +- Call `strip:refresh()` to apply changes +- Call `strip:clear()` or `strip:close()` when needed + +## Example +```lua +local led_strip = require("led_strip") + +local strip = led_strip.new(8, 1) +strip:set_pixel(0, 255, 0, 0) +strip:refresh() +``` diff --git a/components/lua_modules/lua_module_led_strip/skills/skills_list.json b/components/lua_modules/lua_module_led_strip/skills/skills_list.json new file mode 100644 index 0000000..920f71a --- /dev/null +++ b/components/lua_modules/lua_module_led_strip/skills/skills_list.json @@ -0,0 +1,13 @@ +{ + "skills": [ + { + "id": "lua_module_led_strip", + "file": "lua_module_led_strip.md", + "title": "lua_module_led_strip", + "summary": "How to create and control an LED strip from Lua.", + "cap_groups": [ + "cap_lua" + ] + } + ] +} diff --git a/components/lua_modules/lua_module_storage/skills/lua_module_storage.md b/components/lua_modules/lua_module_storage/skills/lua_module_storage.md new file mode 100644 index 0000000..ecd9746 --- /dev/null +++ b/components/lua_modules/lua_module_storage/skills/lua_module_storage.md @@ -0,0 +1,18 @@ +# Lua Storage + +This skill describes how to correctly use storage when writing Lua scripts. + +## How to call +- Import it with `local storage = require("storage")` +- Call `storage.mkdir(path)` to create a directory +- Call `storage.write_file(path, content)` to write a file +- Call `storage.read_file(path)` to read a file + +## Example +```lua +local storage = require("storage") + +storage.mkdir("/fatfs/data/demo") +storage.write_file("/fatfs/data/demo/test.txt", "hello") +local text = storage.read_file("/fatfs/data/demo/test.txt") +``` diff --git a/components/lua_modules/lua_module_storage/skills/skills_list.json b/components/lua_modules/lua_module_storage/skills/skills_list.json new file mode 100644 index 0000000..549deb3 --- /dev/null +++ b/components/lua_modules/lua_module_storage/skills/skills_list.json @@ -0,0 +1,13 @@ +{ + "skills": [ + { + "id": "lua_module_storage", + "file": "lua_module_storage.md", + "title": "lua_module_storage", + "summary": "How to create directories and read or write files from Lua.", + "cap_groups": [ + "cap_lua" + ] + } + ] +}