summaryrefslogtreecommitdiff
path: root/examples/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'examples/extensions')
-rw-r--r--examples/extensions/echo.lua8
-rw-r--r--examples/extensions/greet.lua20
2 files changed, 20 insertions, 8 deletions
diff --git a/examples/extensions/echo.lua b/examples/extensions/echo.lua
index 2f2d4de..112ee25 100644
--- a/examples/extensions/echo.lua
+++ b/examples/extensions/echo.lua
@@ -1,9 +1,11 @@
-- A trivial Lua tool that echoes back whatever the LLM asks it to.
-- Useful for exercising the panto CLI's Lua extension path end-to-end.
+--
+-- Single-tool sugar form: return a table with a `handler` and panto
+-- registers it as a tool. Its `name` is the identity gated by the
+-- `[extensions]` allow/deny policy.
-local panto = require("panto")
-
-panto.ext.register_tool {
+return {
name = "echo",
description = "Echo back the given message. Useful for testing whether tools work.",
schema = {
diff --git a/examples/extensions/greet.lua b/examples/extensions/greet.lua
index d74095b..38d8ca0 100644
--- a/examples/extensions/greet.lua
+++ b/examples/extensions/greet.lua
@@ -2,17 +2,27 @@
-- Drop this under .panto/extensions/ (project) or your user config's
-- extensions/ dir, then type `/greet` or `/greet <name>` in the REPL.
--
+-- Extensions return an *entry* `{ name, activate }`. The file is always
+-- eval'd, but `activate()` runs only if `name` is permitted by the
+-- `[extensions]` policy — so registration is deferred into activate().
+-- One entry may register any number of tools/commands.
+--
-- Slash-command handlers run synchronously and act by side effect (here,
-- writing to stdout). `args` is the trimmed text after the command name;
-- it is an empty string when none was given. The return value is ignored.
local panto = require("panto")
-panto.ext.register_command {
+return {
name = "greet",
- description = "Print a greeting. Optional args name who to greet.",
- handler = function(args)
- local who = args ~= "" and args or "world"
- io.write("\n[greet] hello, " .. who .. "!\n")
+ activate = function()
+ panto.ext.register_command {
+ name = "greet",
+ description = "Print a greeting. Optional args name who to greet.",
+ handler = function(args)
+ local who = args ~= "" and args or "world"
+ io.write("\n[greet] hello, " .. who .. "!\n")
+ end,
+ }
end,
}