[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CS3HBSQ9SX4M2P2KE94XZ5":3,"skill-same:01M6CS3HBSQ9SX4M2P2KE94XZ5":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":33,"linkOnly":34,"markdownContent":35,"markdownBody":36,"frontMatter":37,"refName":38,"commitSha":39,"skillDirectory":40,"forksCount":41,"repositoryHtmlUrl":42,"repositoryHomepageUrl":6,"ownerHtmlUrl":43,"ownerBlogUrl":44,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M6CS3HBSQ9SX4M2P2KE94XZ5","lua-scripting",null,"Ghost's Lua scripting layer internals. MUST READ before modifying anything in src\u002Fscripting\u002F, prompts\u002Fstdlib\u002F, prompts\u002Fagents\u002F*\u002Fagent.lua, or agent hook logic. Covers: ScriptHost VM lifecycle, sandbox, host globals, ctx bindings, nudge library, template module, custom tools, type stubs, and the PreTurnState contract.","mrtolkien\u002FGHOST","mrtolkien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F8489650?v=4","01M6CS32Q934XBQQE8BDV5Z6W2","Tolki","01M6CS32VBCD47F5E27WF9W6FC",5,"MIT","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Flua-scripting\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32],"scripting","lua","lua scripting","sandbox","vm","library","Tools","lifecycle","nudge","ghost","src","template","read","prompts","2026-11-10 10:12:30",false,"---\nname: lua-scripting\ndescription: >-\n  Ghost's Lua scripting layer internals. MUST READ before modifying anything in\n  src\u002Fscripting\u002F, prompts\u002Fstdlib\u002F, prompts\u002Fagents\u002F*\u002Fagent.lua, or agent hook logic.\n  Covers: ScriptHost VM lifecycle, sandbox, host globals, ctx bindings, nudge library,\n  template module, custom tools, type stubs, and the PreTurnState contract.\n---\n\n# Lua Scripting Layer\n\nGhost agents are configured via `agent.lua` files executed in a sandboxed Lua 5.4 VM\n(mlua). This skill documents the **Rust ↔ Lua boundary** for developers working on the\nscripting layer.\n\n## Architecture\n\n```\nsrc\u002Fscripting\u002F\n├── mod.rs        # barrel — re-exports ScriptHost + types\n├── host.rs       # ScriptHost: VM lifecycle, sandbox, hook execution\n├── bindings.rs   # AgentContext (ctx userdata) — DB queries, spawn, resume\n├── types.rs      # AgentConfig, PreTurnState, BuildResult, NudgeResult, LuaToolDef\n└── custom_tools.rs  # Custom tool dispatch (Lua handler → JSON result)\n\nprompts\u002F\n├── stdlib\u002F\n│   ├── nudges.lua   # ghost.nudges module (composable pre_turn\u002Fon_end_turn hooks)\n│   └── template.lua # ghost.template module (mustache-style {{var}} rendering)\n├── types\u002F\n│   └── ghost.lua    # LuaLS type stubs (installed to agents\u002F.types\u002F)\n└── agents\u002F*\u002Fagent.lua  # Agent definitions\n```\n\n## ScriptHost Lifecycle\n\n1. `ScriptHost::new(agent_dir, workspace)` — creates Lua VM, sandboxes it, registers\n   stdlib modules and host globals (`read_file`, `load_skill`, `json`, `print`)\n2. `load_config()` — executes `agent.lua`, extracts the returned table into\n   `AgentConfig`\n3. Hook calls: `call_build()`, `call_pre_turn()`, `call_on_end_turn()`,\n   `call_post_completion()`, `call_on_resume()` — invoke Lua functions via registry keys\n4. `call_custom_tool()` — dispatches a tool call to the Lua handler function\n\nThe VM is dropped when the `ScriptHost` is dropped. For `load_agent()` (config-only),\nthe VM is immediately discarded. For `load_agent_with_host()`, it lives for the agent\nsession's duration.\n\n## Sandbox\n\n`sandbox_lua()` in `host.rs` removes dangerous globals:\n\n- Removed: `os.execute`, `os.remove`, `os.rename`, `os.tmpname`, `os.exit`, `io`,\n  `loadfile`, `dofile`, `debug`\n- Kept: `os.date`, `os.time`, `os.clock`, `os.difftime`\n- `require()` is replaced with a custom loader that only resolves `ghost.*` modules\n\n## Host Globals\n\nInjected by `ScriptHost::new()`, available in all agent.lua files:\n\n| Global             | Signature         | Description                                             |\n| ------------------ | ----------------- | ------------------------------------------------------- |\n| `read_file(path)`  | `string → string` | Read file relative to agent dir, sandboxed to workspace |\n| `load_skill(name)` | `string → string` | Read `skills\u002F{name}\u002Fskill.md`, strips YAML frontmatter  |\n| `json.encode(val)` | `any → string`    | Serialize Lua value to JSON                             |\n| `json.decode(str)` | `string → any`    | Parse JSON string to Lua value                          |\n| `print(...)`       | `...any → ()`     | Prints to stdout (sandboxed)                            |\n\n## ctx Bindings (AgentContext userdata)\n\nRegistered via `register_ctx()` when an agent has a database connection. Available in\n`build()`, `post_completion()`, `on_resume()`, and custom tool handlers.\n\n### Fields (get\u002Fset)\n\n| Field                    | Type         | Notes                         |\n| ------------------------ | ------------ | ----------------------------- |\n| `ctx.session_id`         | `string`     | Read-only                     |\n| `ctx.agent_slug`         | `string`     | Read-only                     |\n| `ctx.trigger_session_id` | `string?`    | Read-only                     |\n| `ctx.workspace`          | `string`     | Read-only                     |\n| `ctx.system_prompt`      | `string?`    | Read\u002Fwrite — `on_resume` hook |\n| `ctx.messages`           | `Message[]?` | Read\u002Fwrite — `on_resume` hook |\n\n### Async Methods\n\n| Method                                   | Signature                           | Description                                              |\n| ---------------------------------------- | ----------------------------------- | -------------------------------------------------------- |\n| `ctx:get(key)`                           | `→ string?`                         | Get agent state KV                                       |\n| `ctx:set(key, value)`                    | `→ ()`                              | Set agent state KV                                       |\n| `ctx:delete(key)`                        | `→ ()`                              | Delete agent state KV                                    |\n| `ctx:count_messages_since(sid, rfc3339)` | `→ integer`                         | Count messages after timestamp                           |\n| `ctx:list_interface_sessions()`          | `→ {interface, session_id}[]`       | All interface sessions                                   |\n| `ctx:filter_transcript(sid)`             | `→ string`                          | Filtered transcript for session                          |\n| `ctx:list_messages(sid)`                 | `→ {role, content, created_at}[]`   | All messages in session                                  |\n| `ctx:curate_web_cache(sid?)`             | `string? → {moved, deleted, edges}` | Classify + move web cache (defaults to current session)  |\n| `ctx:send_to_session(sid, content)`      | `→ ()`                              | Inject system message + notify-only event in one session |\n| `ctx:notify_active_sessions(content)`    | `→ ()`                              | Send to all sessions that have an active interface       |\n\n### Sync Methods\n\n| Method                        | Signature   | Description             |\n| ----------------------------- | ----------- | ----------------------- |\n| `ctx:load_diary_today()`      | `→ string?` | Today's diary entry     |\n| `ctx:spawn_agent(name, args)` | `→ ()`      | Queue child agent spawn |\n\n## AgentConfig Extraction\n\n`load_config()` reads the table returned by `agent.lua` and maps it to `AgentConfig`:\n\n- `name`, `description` — required strings\n- `model` — optional string (nil = default)\n- `reasoning_effort` — optional \"low\"\u002F\"medium\"\u002F\"high\"\n- `max_iterations` — integer, default 50\n- `tools` — string array of built-in tool names\n- `skills` — string array of skill names to inject\n- `custom_tools` — array of tool definition tables (see custom_tools.rs)\n- Hook presence: `has_build`, `has_pre_turn`, `has_on_end_turn`, `has_post_completion`,\n  `has_on_resume` — set by checking if the function exists\n- `compaction` — optional `AgentCompactionOverrides` table (fields: `threshold`,\n  `mask_preview_chars`, `instructions`)\n\nHook functions are stored as Lua registry keys, not extracted as values.\n\n## PreTurnState Contract\n\nThe `PreTurnState` struct is converted to a Lua table via `IntoLua` (types.rs) and\npassed to `pre_turn(state)` and `on_end_turn(state)`:\n\n```lua\n{\n    iteration = 5,          -- current iteration (1-based)\n    max_iterations = 30,    -- configured maximum\n    remaining = 25,         -- max_iterations - iteration\n    elapsed_seconds = 120,  -- wall clock since agent start\n    tool_counts = { web_search = 3, file_read = 7 },\n    last_input_tokens = 5000,\n    context_window = 128000,\n    todo_summary = { total = 5, completed = 2, incomplete = 3 },  -- or nil\n    todo_text = \"- [x] Step 1\\n- [ ] Step 2\",                     -- or nil\n    temporal_fire_count = 0,\n    context_pressure_fired = false,\n}\n```\n\n## NudgeResult Contract\n\n`call_pre_turn()` expects the Lua function to return either:\n\n- `nil` — no nudge\n- A string — nudge text only\n- A table `{ text, temporal_fired, context_pressure_fired }` — full result\n\nThe Rust side maps this to `NudgeResult` (types.rs).\n\n## Custom Tools\n\nDefined in `custom_tools` array in agent.lua:\n\n```lua\ncustom_tools = {\n    {\n        name = \"my_tool\",\n        description = \"What it does\",\n        parameters = {\n            { name = \"input\", type = \"string\", description = \"The input\", required = true },\n        },\n        terminal = false,  -- if true, tool result ends the session\n        handler = function(ctx, args)\n            return \"tool result string\"\n        end,\n    },\n}\n```\n\nHandler functions are stored as registry keys. `call_custom_tool()` looks up the key by\nindex, converts JSON args to a Lua table, calls the handler, and returns the string\nresult.\n\n## Stdlib Modules\n\n### ghost.nudges\n\nPreloaded from `prompts\u002Fstdlib\u002Fnudges.lua`. Provides composable nudge factories:\n\n- `compose(...)` — combine multiple nudges, returns a function\n- `iteration_countdown(thresholds)` — warn at iteration milestones\n- `temporal(config)` — warn after elapsed time, supports escalating messages\n- `context_pressure(config)` — warn when context window usage exceeds threshold\n- `progress_gate(config)` — reject end-turn if TODO items incomplete\n- `todo_list()` — inject current TODO state\n- `tool_count(config)` — warn based on tool usage counts\n- `recency(config)` — warn based on recent tool activity\n\n### ghost.template\n\nPreloaded from `prompts\u002Fstdlib\u002Ftemplate.lua`. Provides:\n\n- `render(text, vars)` — replace `{{key}}` with values from vars table\n\n## Type Stubs\n\nLuaLS type annotations live in `prompts\u002Ftypes\u002Fghost.lua` (embedded in binary, installed\nto `agents\u002F.types\u002Fghost.lua`). These provide autocompletion for agent developers.\n\nUpdate the stubs when modifying any host global or ctx binding.\n\n## Delivering Agent Output to the OPERATOR\n\nAgents that produce a result (briefings, summaries, alerts) should deliver it in\n`post_completion` using `ctx:notify_active_sessions`. This sends the LLM's final\nassistant message to every active interface session (e.g. Discord) as a system message,\ntriggering a `notify_only` event so the runtime delivers it without starting a new chat\nturn.\n\nPattern for a briefing-style agent (e.g. morning-briefing):\n\n```lua\npost_completion = function(ctx)\n    local messages = ctx:list_messages(ctx.session_id)\n    local last = messages[#messages]\n    if not last or last.role ~= \"assistant\" then return end\n\n    local content = last.content or \"\"\n\n    -- Deliver briefing to user via all active interface sessions (e.g. Discord)\n    ctx:notify_active_sessions(content)\n\n    -- ... agent-specific bookkeeping (seen URLs, timestamps, etc.) ...\nend,\n```\n\nUse `ctx:send_to_session(session_id, content)` instead when you need to target a single\nknown session (e.g. the `trigger_session_id` that spawned the agent).\n\n**Note**: `morning-briefing` is a user-created agent (not bundled in `assets\u002Fagents\u002F`)\nand lives only in the deployed GHOST workspace. Apply the pattern above to its\n`post_completion` hook when updating the workspace.\n\n## Centralized Scheduling (crontab.lua)\n\n`assets\u002Fagents\u002Fcrontab.lua` defines which agents run on schedules. It returns a table of\nentries, each with either `cron` (cron expression) or `idle_minutes` (idle trigger):\n\n```lua\nreturn {\n    { idle_minutes = 30, run = \"chat-reflection\" },\n    { cron = \"0 3 * * *\", run = \"daily-summary\" },\n}\n```\n\n**Cron expressions are evaluated in UTC**, not the system timezone. Users must convert\nmanually (e.g. `0 3 * * *` = 3:00 AM UTC).\n\n## Key Patterns\n\n- **Registry keys over closures**: Hook functions are stored as `LuaRegistryKey` in the\n  VM, not as Rust closures. This avoids lifetime issues with mlua.\n- **handler_key_index**: Custom tool handlers use a usize index into\n  `ScriptHost.tool_handler_keys` so `LuaToolDef` stays `Send+Sync`.\n- **Arc\u003CMutex\u003C>> for shared state**: `spawn_requests`, `system_prompt`,\n  `resume_messages` use Arc\u003CMutex\u003C>> so ctx can be cloned across async boundaries.\n","# Lua Scripting Layer\n\nGhost agents are configured via `agent.lua` files executed in a sandboxed Lua 5.4 VM\n(mlua). This skill documents the **Rust ↔ Lua boundary** for developers working on the\nscripting layer.\n\n## Architecture\n\n```\nsrc\u002Fscripting\u002F\n├── mod.rs        # barrel — re-exports ScriptHost + types\n├── host.rs       # ScriptHost: VM lifecycle, sandbox, hook execution\n├── bindings.rs   # AgentContext (ctx userdata) — DB queries, spawn, resume\n├── types.rs      # AgentConfig, PreTurnState, BuildResult, NudgeResult, LuaToolDef\n└── custom_tools.rs  # Custom tool dispatch (Lua handler → JSON result)\n\nprompts\u002F\n├── stdlib\u002F\n│   ├── nudges.lua   # ghost.nudges module (composable pre_turn\u002Fon_end_turn hooks)\n│   └── template.lua # ghost.template module (mustache-style {{var}} rendering)\n├── types\u002F\n│   └── ghost.lua    # LuaLS type stubs (installed to agents\u002F.types\u002F)\n└── agents\u002F*\u002Fagent.lua  # Agent definitions\n```\n\n## ScriptHost Lifecycle\n\n1. `ScriptHost::new(agent_dir, workspace)` — creates Lua VM, sandboxes it, registers\n   stdlib modules and host globals (`read_file`, `load_skill`, `json`, `print`)\n2. `load_config()` — executes `agent.lua`, extracts the returned table into\n   `AgentConfig`\n3. Hook calls: `call_build()`, `call_pre_turn()`, `call_on_end_turn()`,\n   `call_post_completion()`, `call_on_resume()` — invoke Lua functions via registry keys\n4. `call_custom_tool()` — dispatches a tool call to the Lua handler function\n\nThe VM is dropped when the `ScriptHost` is dropped. For `load_agent()` (config-only),\nthe VM is immediately discarded. For `load_agent_with_host()`, it lives for the agent\nsession's duration.\n\n## Sandbox\n\n`sandbox_lua()` in `host.rs` removes dangerous globals:\n\n- Removed: `os.execute`, `os.remove`, `os.rename`, `os.tmpname`, `os.exit`, `io`,\n  `loadfile`, `dofile`, `debug`\n- Kept: `os.date`, `os.time`, `os.clock`, `os.difftime`\n- `require()` is replaced with a custom loader that only resolves `ghost.*` modules\n\n## Host Globals\n\nInjected by `ScriptHost::new()`, available in all agent.lua files:\n\n| Global             | Signature         | Description                                             |\n| ------------------ | ----------------- | ------------------------------------------------------- |\n| `read_file(path)`  | `string → string` | Read file relative to agent dir, sandboxed to workspace |\n| `load_skill(name)` | `string → string` | Read `skills\u002F{name}\u002Fskill.md`, strips YAML frontmatter  |\n| `json.encode(val)` | `any → string`    | Serialize Lua value to JSON                             |\n| `json.decode(str)` | `string → any`    | Parse JSON string to Lua value                          |\n| `print(...)`       | `...any → ()`     | Prints to stdout (sandboxed)                            |\n\n## ctx Bindings (AgentContext userdata)\n\nRegistered via `register_ctx()` when an agent has a database connection. Available in\n`build()`, `post_completion()`, `on_resume()`, and custom tool handlers.\n\n### Fields (get\u002Fset)\n\n| Field                    | Type         | Notes                         |\n| ------------------------ | ------------ | ----------------------------- |\n| `ctx.session_id`         | `string`     | Read-only                     |\n| `ctx.agent_slug`         | `string`     | Read-only                     |\n| `ctx.trigger_session_id` | `string?`    | Read-only                     |\n| `ctx.workspace`          | `string`     | Read-only                     |\n| `ctx.system_prompt`      | `string?`    | Read\u002Fwrite — `on_resume` hook |\n| `ctx.messages`           | `Message[]?` | Read\u002Fwrite — `on_resume` hook |\n\n### Async Methods\n\n| Method                                   | Signature                           | Description                                              |\n| ---------------------------------------- | ----------------------------------- | -------------------------------------------------------- |\n| `ctx:get(key)`                           | `→ string?`                         | Get agent state KV                                       |\n| `ctx:set(key, value)`                    | `→ ()`                              | Set agent state KV                                       |\n| `ctx:delete(key)`                        | `→ ()`                              | Delete agent state KV                                    |\n| `ctx:count_messages_since(sid, rfc3339)` | `→ integer`                         | Count messages after timestamp                           |\n| `ctx:list_interface_sessions()`          | `→ {interface, session_id}[]`       | All interface sessions                                   |\n| `ctx:filter_transcript(sid)`             | `→ string`                          | Filtered transcript for session                          |\n| `ctx:list_messages(sid)`                 | `→ {role, content, created_at}[]`   | All messages in session                                  |\n| `ctx:curate_web_cache(sid?)`             | `string? → {moved, deleted, edges}` | Classify + move web cache (defaults to current session)  |\n| `ctx:send_to_session(sid, content)`      | `→ ()`                              | Inject system message + notify-only event in one session |\n| `ctx:notify_active_sessions(content)`    | `→ ()`                              | Send to all sessions that have an active interface       |\n\n### Sync Methods\n\n| Method                        | Signature   | Description             |\n| ----------------------------- | ----------- | ----------------------- |\n| `ctx:load_diary_today()`      | `→ string?` | Today's diary entry     |\n| `ctx:spawn_agent(name, args)` | `→ ()`      | Queue child agent spawn |\n\n## AgentConfig Extraction\n\n`load_config()` reads the table returned by `agent.lua` and maps it to `AgentConfig`:\n\n- `name`, `description` — required strings\n- `model` — optional string (nil = default)\n- `reasoning_effort` — optional \"low\"\u002F\"medium\"\u002F\"high\"\n- `max_iterations` — integer, default 50\n- `tools` — string array of built-in tool names\n- `skills` — string array of skill names to inject\n- `custom_tools` — array of tool definition tables (see custom_tools.rs)\n- Hook presence: `has_build`, `has_pre_turn`, `has_on_end_turn`, `has_post_completion`,\n  `has_on_resume` — set by checking if the function exists\n- `compaction` — optional `AgentCompactionOverrides` table (fields: `threshold`,\n  `mask_preview_chars`, `instructions`)\n\nHook functions are stored as Lua registry keys, not extracted as values.\n\n## PreTurnState Contract\n\nThe `PreTurnState` struct is converted to a Lua table via `IntoLua` (types.rs) and\npassed to `pre_turn(state)` and `on_end_turn(state)`:\n\n```lua\n{\n    iteration = 5,          -- current iteration (1-based)\n    max_iterations = 30,    -- configured maximum\n    remaining = 25,         -- max_iterations - iteration\n    elapsed_seconds = 120,  -- wall clock since agent start\n    tool_counts = { web_search = 3, file_read = 7 },\n    last_input_tokens = 5000,\n    context_window = 128000,\n    todo_summary = { total = 5, completed = 2, incomplete = 3 },  -- or nil\n    todo_text = \"- [x] Step 1\\n- [ ] Step 2\",                     -- or nil\n    temporal_fire_count = 0,\n    context_pressure_fired = false,\n}\n```\n\n## NudgeResult Contract\n\n`call_pre_turn()` expects the Lua function to return either:\n\n- `nil` — no nudge\n- A string — nudge text only\n- A table `{ text, temporal_fired, context_pressure_fired }` — full result\n\nThe Rust side maps this to `NudgeResult` (types.rs).\n\n## Custom Tools\n\nDefined in `custom_tools` array in agent.lua:\n\n```lua\ncustom_tools = {\n    {\n        name = \"my_tool\",\n        description = \"What it does\",\n        parameters = {\n            { name = \"input\", type = \"string\", description = \"The input\", required = true },\n        },\n        terminal = false,  -- if true, tool result ends the session\n        handler = function(ctx, args)\n            return \"tool result string\"\n        end,\n    },\n}\n```\n\nHandler functions are stored as registry keys. `call_custom_tool()` looks up the key by\nindex, converts JSON args to a Lua table, calls the handler, and returns the string\nresult.\n\n## Stdlib Modules\n\n### ghost.nudges\n\nPreloaded from `prompts\u002Fstdlib\u002Fnudges.lua`. Provides composable nudge factories:\n\n- `compose(...)` — combine multiple nudges, returns a function\n- `iteration_countdown(thresholds)` — warn at iteration milestones\n- `temporal(config)` — warn after elapsed time, supports escalating messages\n- `context_pressure(config)` — warn when context window usage exceeds threshold\n- `progress_gate(config)` — reject end-turn if TODO items incomplete\n- `todo_list()` — inject current TODO state\n- `tool_count(config)` — warn based on tool usage counts\n- `recency(config)` — warn based on recent tool activity\n\n### ghost.template\n\nPreloaded from `prompts\u002Fstdlib\u002Ftemplate.lua`. Provides:\n\n- `render(text, vars)` — replace `{{key}}` with values from vars table\n\n## Type Stubs\n\nLuaLS type annotations live in `prompts\u002Ftypes\u002Fghost.lua` (embedded in binary, installed\nto `agents\u002F.types\u002Fghost.lua`). These provide autocompletion for agent developers.\n\nUpdate the stubs when modifying any host global or ctx binding.\n\n## Delivering Agent Output to the OPERATOR\n\nAgents that produce a result (briefings, summaries, alerts) should deliver it in\n`post_completion` using `ctx:notify_active_sessions`. This sends the LLM's final\nassistant message to every active interface session (e.g. Discord) as a system message,\ntriggering a `notify_only` event so the runtime delivers it without starting a new chat\nturn.\n\nPattern for a briefing-style agent (e.g. morning-briefing):\n\n```lua\npost_completion = function(ctx)\n    local messages = ctx:list_messages(ctx.session_id)\n    local last = messages[#messages]\n    if not last or last.role ~= \"assistant\" then return end\n\n    local content = last.content or \"\"\n\n    -- Deliver briefing to user via all active interface sessions (e.g. Discord)\n    ctx:notify_active_sessions(content)\n\n    -- ... agent-specific bookkeeping (seen URLs, timestamps, etc.) ...\nend,\n```\n\nUse `ctx:send_to_session(session_id, content)` instead when you need to target a single\nknown session (e.g. the `trigger_session_id` that spawned the agent).\n\n**Note**: `morning-briefing` is a user-created agent (not bundled in `assets\u002Fagents\u002F`)\nand lives only in the deployed GHOST workspace. Apply the pattern above to its\n`post_completion` hook when updating the workspace.\n\n## Centralized Scheduling (crontab.lua)\n\n`assets\u002Fagents\u002Fcrontab.lua` defines which agents run on schedules. It returns a table of\nentries, each with either `cron` (cron expression) or `idle_minutes` (idle trigger):\n\n```lua\nreturn {\n    { idle_minutes = 30, run = \"chat-reflection\" },\n    { cron = \"0 3 * * *\", run = \"daily-summary\" },\n}\n```\n\n**Cron expressions are evaluated in UTC**, not the system timezone. Users must convert\nmanually (e.g. `0 3 * * *` = 3:00 AM UTC).\n\n## Key Patterns\n\n- **Registry keys over closures**: Hook functions are stored as `LuaRegistryKey` in the\n  VM, not as Rust closures. This avoids lifetime issues with mlua.\n- **handler_key_index**: Custom tool handlers use a usize index into\n  `ScriptHost.tool_handler_keys` so `LuaToolDef` stays `Send+Sync`.\n- **Arc\u003CMutex\u003C>> for shared state**: `spawn_requests`, `system_prompt`,\n  `resume_messages` use Arc\u003CMutex\u003C>> so ctx can be cloned across async boundaries.\n",{"name":5,"description":7},"main","083d96429a2d05526f8a294b83c74f0336670def",".agents\u002Fskills\u002Flua-scripting",0,"https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST","https:\u002F\u002Fgithub.com\u002Fmrtolkien","https:\u002F\u002Fblog.tolki.dev","Data Engineer \u002F Esports \u002F Keyboards","2026-04-24 15:41:08",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add mrtolkien\u002FGHOST --skill lua-scripting",{"tool":53,"command":54},"bunx","bunx skills add mrtolkien\u002FGHOST --skill lua-scripting",{"tool":56,"command":57},"pnpm","pnpm dlx skills add mrtolkien\u002FGHOST --skill lua-scripting","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Flua-scripting\u002FSKILL.md",true,[],[62,88,101,117,126,136],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":33},"01M6CS613RWD9CFJ3KFX47V1DS","system-management","Use when reading or changing GHOST configuration (providers, models, timing, compaction, services, any config.toml key), adding or switching LLM providers, answering questions about GHOST's own features or capabilities, a CLI tool is missing or \"not found\", services need starting\u002Fstopping\u002Fdebugging, updating GHOST to a newer version, managing the Nix shell environment, or troubleshooting GHOST setup.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsystem-management\u002Fskill.md",[],[69,70,71,72,73,74,75,76,77,78,79,80,28,81,82,83,84,85,86,87],"system management","management","system","shell","cli","nix","config","setup","debugging","capabilities","services","Providers","tool","troubleshooting","environment","use","version","models","configuration",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":33},"01M6CS5XTK2884R9HE15YR8YZM","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fwriting-skills\u002Fskill.md",[],[95,96,97,98,99,84,100],"writing skills","writing","coding","work","editing","deployment",{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":33},"01M6CS5V737R1DVB3TZEK0C6WT","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code. Write comprehensive implementation plans assuming the engineer has zero context for our codebase and questionable taste.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fwriting-plans\u002Fskill.md",[],[108,96,109,110,111,97,112,113,84,114,115,116],"writing plans","spec","code","ZeRO","write","context","engineer","implementation","task",{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":123,"publishedAt":33},"01M6CS5S5S0YY56686G5CQ0WMP","verification","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs. Requires running verification commands and confirming output before making any success claims. Evidence before assertions, always.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fverification\u002Fskill.md",[],[119,97,98,84,124,125],"evidence","claim",{"skillNo":127,"name":128,"nameZh":6,"description":129,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":33},"01M6CS5PD2ZSFWYRDZSACNTAJY","tdd","Use when implementing any feature or bugfix, before writing implementation code. Write the test first. Watch it fail. Write minimal code to pass.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Ftdd\u002Fskill.md",[],[128,96,110,133,97,112,84,134,115,135],"first","minimal","test",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":33},"01M6CS5K5WE2SHF1YV8D9C4C77","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fsystematic-debugging\u002Fskill.md",[],[143,77,144,84,97,135,145],"systematic debugging","behavior","bug"]