lampson 0.2.10 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -1
- package/bin/lampson.js +2 -2
- package/chat.syn +40 -24
- package/cli.syn +6 -3
- package/hub.tpl.syn +15 -0
- package/lampson.ps1 +85 -11
- package/lampson.sh +82 -24
- package/lib/api.syn +292 -0
- package/lib/apikeys.syn +115 -0
- package/lib/approvals.syn +7 -0
- package/lib/channels.syn +340 -0
- package/lib/loop.syn +77 -3
- package/lib/mailbox.syn +440 -0
- package/lib/mcp.syn +128 -9
- package/lib/mcp_server.syn +235 -0
- package/lib/plugins.syn +94 -7
- package/lib/runtime.syn +630 -0
- package/lib/scope.syn +62 -0
- package/lib/session.syn +11 -1
- package/lib/teamrun.syn +142 -0
- package/lib/teams.syn +802 -0
- package/lib/tools.syn +1 -1
- package/lib/workspaces.syn +78 -3
- package/lib/worktree.syn +105 -0
- package/package.json +16 -2
- package/plugins/chatwoot/plugin.json +11 -0
- package/plugins/chatwoot/plugin.syn +143 -0
- package/plugins/orders/INSTRUCTIONS.md +16 -0
- package/plugins/orders/plugin.json +81 -0
- package/plugins/orders/plugin.syn +342 -0
- package/plugins/telegram/plugin.json +11 -0
- package/plugins/telegram/plugin.syn +272 -0
- package/public/css/panel.css +2 -0
- package/public/css/teams.css +159 -0
- package/public/index.html +10 -0
- package/public/js/app.js +1 -1
- package/public/js/engine.js +149 -0
- package/public/js/sessions.js +5 -1
- package/public/js/teams.js +301 -0
- package/public/teams.html +75 -0
- package/run.syn +493 -0
- package/sdk/index.d.ts +94 -0
- package/sdk/index.js +250 -0
- package/sdk/index.mjs +4 -0
- package/web.syn +428 -47
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
-- lib/mcp_server.syn — Lampson COMO servidor MCP (spec/engine.md, fase 3): `lampson mcp serve`
|
|
2
|
+
--
|
|
3
|
+
-- Lo inverso de lib/mcp.syn (que es el CLIENTE): acá Claude Desktop, Cursor u otro agente usan los agentes de
|
|
4
|
+
-- Lampson como tools. Dos transportes, el mismo manejo (handle):
|
|
5
|
+
-- stdio `lampson mcp serve`: JSON-RPC 2.0, un mensaje por línea en stdin, respuestas por stdout (nada más puede
|
|
6
|
+
-- escribir en stdout mientras sirve). El cliente y Lampson en la MISMA máquina.
|
|
7
|
+
-- HTTP POST /w/<slug>/v1/mcp (web.syn, "Streamable HTTP" de MCP, respuestas JSON) con la API key de la API /v1:
|
|
8
|
+
-- desde cualquier lado, con la URL pública de Lampson (--domain, túnel, LAMPSON_PUBLIC_URL). Cada key ve
|
|
9
|
+
-- solo sus agentes; los mensajes pasan por el buzón (lib/mailbox.syn: dos agentes de afuera escribiendo a
|
|
10
|
+
-- la vez en la misma conversación no se pisan).
|
|
11
|
+
--
|
|
12
|
+
-- Tools:
|
|
13
|
+
-- ask(message, agent?, thread?) un mensaje a un agente; mismo thread = misma conversación. Sin thread se crea uno
|
|
14
|
+
-- y se devuelve, para seguir la conversación en la próxima llamada.
|
|
15
|
+
-- agents() los agentes disponibles (con LAMPSON_MCP_AGENTS, solo esos)
|
|
16
|
+
-- history(thread, agent?, limit?) los últimos mensajes (persona/agente) de una conversación — para retomarla
|
|
17
|
+
-- sin haber guardado nada del lado del cliente
|
|
18
|
+
-- Permisos: sin humano delante → el modo del agente, y si no dice, strict (lo peligroso se deniega y el agente lo
|
|
19
|
+
-- informa en su respuesta).
|
|
20
|
+
|
|
21
|
+
use "./runtime.syn" as runtime
|
|
22
|
+
use "./session.syn" as session
|
|
23
|
+
|
|
24
|
+
export let PROTOCOL be "2025-06-18"
|
|
25
|
+
export let SUPPORTED be ["2025-06-18", "2025-03-26", "2024-11-05"]
|
|
26
|
+
|
|
27
|
+
-- los agentes que este servidor ofrece: LAMPSON_MCP_AGENTS ("tienda,plan") o todos los elegibles
|
|
28
|
+
export task offered()
|
|
29
|
+
require env("LAMPSON_*")
|
|
30
|
+
require file.read("workspace")
|
|
31
|
+
require file.read("workspace/*")
|
|
32
|
+
require file.read("agents")
|
|
33
|
+
require file.read("agents/*")
|
|
34
|
+
let want be where(apply((x) => lower(trim(x)), split(env("LAMPSON_MCP_AGENTS", ""), ",")), (x) => x != "")
|
|
35
|
+
when length(want) == 0
|
|
36
|
+
give runtime.names()
|
|
37
|
+
give where(runtime.names(), (n) => contains(want, n))
|
|
38
|
+
|
|
39
|
+
export task tools_list(agents_list)
|
|
40
|
+
let ask_props be {"message": {"type": "string", "description": "What to ask or tell the agent, in plain words."}, "thread": {"type": "string", "description": "Conversation id. Pass the thread returned by a previous ask to continue that conversation; omit it to start a new one."}}
|
|
41
|
+
when length(agents_list) > 1
|
|
42
|
+
set ask_props["agent"] to {"type": "string", "enum": agents_list, "description": "Which Lampson agent answers (see the agents tool). Default: " + agents_list[0] + "."}
|
|
43
|
+
give [
|
|
44
|
+
{"name": "ask", "description": "Send a message to a Lampson agent working in the user's project and get its answer. The agent can use its own tools (read files, run checks…) within its permissions. Same thread = same conversation.", "inputSchema": {"type": "object", "properties": ask_props, "required": ["message"]}},
|
|
45
|
+
{"name": "agents", "description": "List the Lampson agents this server offers, with what each one is for.", "inputSchema": {"type": "object", "properties": {}}},
|
|
46
|
+
{"name": "history", "description": "The last messages of a conversation with a Lampson agent (who said what), to pick it up where it was left.", "inputSchema": {"type": "object", "properties": {"thread": {"type": "string", "description": "The conversation's thread (the one ask returned)."}, "agent": {"type": "string", "description": "Which agent (default: " + agents_list[0] + ")."}, "limit": {"type": "number", "description": "How many messages, newest last (default 20, max 100)."}}, "required": ["thread"]}}
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
task reply(id, result)
|
|
50
|
+
print(json_encode({"jsonrpc": "2.0", "id": id, "result": result}))
|
|
51
|
+
flush()
|
|
52
|
+
|
|
53
|
+
task reply_error(id, code, msg)
|
|
54
|
+
print(json_encode({"jsonrpc": "2.0", "id": id, "error": {"code": code, "message": msg}}))
|
|
55
|
+
flush()
|
|
56
|
+
|
|
57
|
+
task text_result(t, structured, is_error)
|
|
58
|
+
give {"content": [{"type": "text", "text": t}], "structuredContent": structured, "isError": is_error}
|
|
59
|
+
|
|
60
|
+
-- tools/call → resultado MCP (no se llama `call`: taparía al builtin call() que invoca deliver_fn)
|
|
61
|
+
export task run_tool(name, args, agents_list, deliver_fn)
|
|
62
|
+
require net
|
|
63
|
+
require exec
|
|
64
|
+
require time
|
|
65
|
+
require random
|
|
66
|
+
require file(".lampson")
|
|
67
|
+
require file(".lampson/*")
|
|
68
|
+
require file("workspace")
|
|
69
|
+
require file("workspace/*")
|
|
70
|
+
require file.read("skills")
|
|
71
|
+
require file.read("skills/*")
|
|
72
|
+
require file.read("plugins")
|
|
73
|
+
require file.read("plugins/*")
|
|
74
|
+
require file.read("agents")
|
|
75
|
+
require file.read("agents/*")
|
|
76
|
+
require file.read("memory")
|
|
77
|
+
require file.read("memory/*")
|
|
78
|
+
require env("LAMPSON_*")
|
|
79
|
+
require env("OS")
|
|
80
|
+
require secret("LAMPSON_*")
|
|
81
|
+
when name == "agents"
|
|
82
|
+
let rows be apply((n) => {"id": n, "description": runtime.get(n)["description"]}, agents_list)
|
|
83
|
+
let lines be apply((r) => "- " + r["id"] + (when r["description"] != "" then ": " + r["description"] otherwise ""), rows)
|
|
84
|
+
give text_result(join(lines, "\n"), {"agents": rows}, false)
|
|
85
|
+
when name == "history"
|
|
86
|
+
let hth be when contains(args, "thread") and args["thread"] != nothing then text(args["thread"]) otherwise ""
|
|
87
|
+
let hag be when contains(args, "agent") and args["agent"] != nothing and text(args["agent"]) != "" then lower(text(args["agent"])) otherwise agents_list[0]
|
|
88
|
+
when hth == ""
|
|
89
|
+
give text_result("thread is required", {}, true)
|
|
90
|
+
when not contains(agents_list, hag)
|
|
91
|
+
give text_result("no agent named '" + hag + "' here · available: " + join(agents_list, ", "), {}, true)
|
|
92
|
+
let lim be when contains(args, "limit") and args["limit"] != nothing then floor(number(args["limit"])) otherwise 20
|
|
93
|
+
when lim < 1 or lim > 100
|
|
94
|
+
set lim to 20
|
|
95
|
+
let sid be runtime.thread_session(hag, hth)
|
|
96
|
+
when sid == ""
|
|
97
|
+
give text_result("no conversation with " + hag + " in thread '" + hth + "' yet", {"agent": hag, "thread": hth, "messages": []}, false)
|
|
98
|
+
let msgs be []
|
|
99
|
+
each m in session.load(sid)["messages"]
|
|
100
|
+
when (m["role"] == "user" or m["role"] == "assistant") and type_of(m["content"]) == "text" and trim(m["content"]) != "" and not starts_with(m["content"], "[harness]")
|
|
101
|
+
set msgs to append(msgs, {"role": when m["role"] == "user" then "user" otherwise "agent", "text": m["content"]})
|
|
102
|
+
let tail be when length(msgs) > lim then slice(msgs, length(msgs) - lim, length(msgs)) otherwise msgs
|
|
103
|
+
let lines be apply((m) => (when m["role"] == "user" then "USER: " otherwise "AGENT: ") + m["text"], tail)
|
|
104
|
+
give text_result(join(lines, "\n\n"), {"agent": hag, "thread": hth, "session": sid, "messages": tail}, false)
|
|
105
|
+
when name != "ask"
|
|
106
|
+
give text_result("unknown tool '" + text(name) + "'", {}, true)
|
|
107
|
+
let msg be when contains(args, "message") then text(args["message"]) otherwise ""
|
|
108
|
+
when trim(msg) == ""
|
|
109
|
+
give text_result("message is required", {}, true)
|
|
110
|
+
let agent be when contains(args, "agent") and args["agent"] != nothing and text(args["agent"]) != "" then lower(text(args["agent"])) otherwise agents_list[0]
|
|
111
|
+
when not contains(agents_list, agent)
|
|
112
|
+
give text_result("no agent named '" + agent + "' here · available: " + join(agents_list, ", "), {}, true)
|
|
113
|
+
let thread be when contains(args, "thread") and args["thread"] != nothing then text(args["thread"]) otherwise ""
|
|
114
|
+
when thread == ""
|
|
115
|
+
set thread to "mcp:" + slice(token(16), 0, 10)
|
|
116
|
+
let spec be runtime.get(agent)
|
|
117
|
+
let mode be when spec["permission"] != "" then "" otherwise "strict"
|
|
118
|
+
let r be nothing
|
|
119
|
+
try
|
|
120
|
+
set r to call(deliver_fn, {"sobre": {"to": agent, "thread": thread, "session": "", "from": {"id": "", "name": "", "kind": "agent"}, "text": msg, "images": [], "channel": "mcp", "meta": {}}, "mode": mode})
|
|
121
|
+
recover err
|
|
122
|
+
give text_result("error: " + text(err), {"agent": agent, "thread": thread}, true)
|
|
123
|
+
let failed be starts_with(r["stopped"], "error")
|
|
124
|
+
let body be when failed then r["stopped"] otherwise r["text"]
|
|
125
|
+
let footer be "\n\n[lampson · agent " + agent + " · thread " + thread + " — pass this thread to continue the conversation]"
|
|
126
|
+
give text_result(body + footer, {"agent": agent, "thread": thread, "session": r["session"], "text": r["text"], "steps": r["steps"], "stopped": r["stopped"]}, failed)
|
|
127
|
+
|
|
128
|
+
-- un mensaje JSON-RPC → la respuesta (map), o nothing si era una notificación (no se responde)
|
|
129
|
+
export task handle(req, agents_list, deliver_fn)
|
|
130
|
+
require net
|
|
131
|
+
require exec
|
|
132
|
+
require time
|
|
133
|
+
require random
|
|
134
|
+
require file(".lampson")
|
|
135
|
+
require file(".lampson/*")
|
|
136
|
+
require file("workspace")
|
|
137
|
+
require file("workspace/*")
|
|
138
|
+
require file.read("skills")
|
|
139
|
+
require file.read("skills/*")
|
|
140
|
+
require file.read("plugins")
|
|
141
|
+
require file.read("plugins/*")
|
|
142
|
+
require file.read("agents")
|
|
143
|
+
require file.read("agents/*")
|
|
144
|
+
require file.read("memory")
|
|
145
|
+
require file.read("memory/*")
|
|
146
|
+
require env("LAMPSON_*")
|
|
147
|
+
require env("OS")
|
|
148
|
+
require secret("LAMPSON_*")
|
|
149
|
+
when req == nothing or type_of(req) != "map"
|
|
150
|
+
give {"jsonrpc": "2.0", "id": nothing, "error": {"code": -32600, "message": "invalid request"}}
|
|
151
|
+
let id be when contains(req, "id") then req["id"] otherwise nothing
|
|
152
|
+
let method be when contains(req, "method") then text(req["method"]) otherwise ""
|
|
153
|
+
let params be when contains(req, "params") and req["params"] != nothing then req["params"] otherwise {}
|
|
154
|
+
when id == nothing
|
|
155
|
+
give nothing
|
|
156
|
+
when method == "initialize"
|
|
157
|
+
-- la versión que pide el cliente si la hablamos; si no, la nuestra (el cliente decide si sigue)
|
|
158
|
+
let asked be when contains(params, "protocolVersion") then text(params["protocolVersion"]) otherwise PROTOCOL
|
|
159
|
+
let v be when contains(SUPPORTED, asked) then asked otherwise PROTOCOL
|
|
160
|
+
give {"jsonrpc": "2.0", "id": id, "result": {"protocolVersion": v, "capabilities": {"tools": {"listChanged": false}}, "serverInfo": {"name": "lampson", "version": "0.2"}, "instructions": "Lampson agents. Use `agents` to see who is available and `ask` to talk to one; keep the returned thread to continue a conversation."}}
|
|
161
|
+
when method == "ping"
|
|
162
|
+
give {"jsonrpc": "2.0", "id": id, "result": {}}
|
|
163
|
+
when method == "tools/list"
|
|
164
|
+
give {"jsonrpc": "2.0", "id": id, "result": {"tools": tools_list(agents_list)}}
|
|
165
|
+
when method == "tools/call"
|
|
166
|
+
let args be when contains(params, "arguments") and params["arguments"] != nothing then params["arguments"] otherwise {}
|
|
167
|
+
give {"jsonrpc": "2.0", "id": id, "result": run_tool(text(params["name"]), args, agents_list, deliver_fn)}
|
|
168
|
+
give {"jsonrpc": "2.0", "id": id, "error": {"code": -32601, "message": "method not found: " + method}}
|
|
169
|
+
|
|
170
|
+
-- stdio: el turno directo (un solo cliente, un proceso)
|
|
171
|
+
export task deliver_direct(sobre, mode)
|
|
172
|
+
require net
|
|
173
|
+
require exec
|
|
174
|
+
require time
|
|
175
|
+
require random
|
|
176
|
+
require file(".lampson")
|
|
177
|
+
require file(".lampson/*")
|
|
178
|
+
require file("workspace")
|
|
179
|
+
require file("workspace/*")
|
|
180
|
+
require file.read("skills")
|
|
181
|
+
require file.read("skills/*")
|
|
182
|
+
require file.read("plugins")
|
|
183
|
+
require file.read("plugins/*")
|
|
184
|
+
require file.read("agents")
|
|
185
|
+
require file.read("agents/*")
|
|
186
|
+
require file.read("memory")
|
|
187
|
+
require file.read("memory/*")
|
|
188
|
+
require env("LAMPSON_*")
|
|
189
|
+
require env("OS")
|
|
190
|
+
require secret("LAMPSON_*")
|
|
191
|
+
give runtime.deliver(sobre, {"mode": mode, "ask_fn": nothing})
|
|
192
|
+
|
|
193
|
+
-- el loop stdio: hasta EOF
|
|
194
|
+
export task serve()
|
|
195
|
+
require stdin
|
|
196
|
+
require net
|
|
197
|
+
require exec
|
|
198
|
+
require time
|
|
199
|
+
require random
|
|
200
|
+
require file(".lampson")
|
|
201
|
+
require file(".lampson/*")
|
|
202
|
+
require file("workspace")
|
|
203
|
+
require file("workspace/*")
|
|
204
|
+
require file.read("skills")
|
|
205
|
+
require file.read("skills/*")
|
|
206
|
+
require file.read("plugins")
|
|
207
|
+
require file.read("plugins/*")
|
|
208
|
+
require file.read("agents")
|
|
209
|
+
require file.read("agents/*")
|
|
210
|
+
require file.read("memory")
|
|
211
|
+
require file.read("memory/*")
|
|
212
|
+
require env("LAMPSON_*")
|
|
213
|
+
require env("OS")
|
|
214
|
+
require secret("LAMPSON_*")
|
|
215
|
+
let agents_list be offered()
|
|
216
|
+
when length(agents_list) == 0
|
|
217
|
+
give false
|
|
218
|
+
let line be read_line("")
|
|
219
|
+
while line != nothing
|
|
220
|
+
when trim(line) != ""
|
|
221
|
+
let req be nothing
|
|
222
|
+
let bad be false
|
|
223
|
+
try
|
|
224
|
+
set req to json_decode(line)
|
|
225
|
+
recover err
|
|
226
|
+
set bad to true
|
|
227
|
+
when bad
|
|
228
|
+
reply_error(nothing, -32700, "parse error")
|
|
229
|
+
otherwise
|
|
230
|
+
let resp be handle(req, agents_list, deliver_direct)
|
|
231
|
+
when resp != nothing
|
|
232
|
+
print(json_encode(resp))
|
|
233
|
+
flush()
|
|
234
|
+
set line to read_line("")
|
|
235
|
+
give true
|
package/lib/plugins.syn
CHANGED
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
-- "command": "python plugin.py" (kind=exec: cualquier ejecutable — js, py, sh…)
|
|
9
9
|
-- "caps": "file.read=workspace/*" (kind=syn, opcional: techo EXTRA sobre stdout,time,env=PLUGIN_*)
|
|
10
10
|
-- "timeout": 60,
|
|
11
|
-
-- "tools": [{"name", "description", "parameters": {JSON Schema}, "readonly": false}]
|
|
11
|
+
-- "tools": [{"name", "description", "parameters": {JSON Schema}, "readonly": false}],
|
|
12
|
+
-- "config": ["CHATWOOT_TOKEN", …] (opcional: el hijo recibe PLUGIN_<X> = LAMPSON_<X> del .env/entorno;
|
|
13
|
+
-- así un plugin syn con techo env=PLUGIN_* también tiene sus secretos)
|
|
14
|
+
-- "instructions": "INSTRUCTIONS.md" (opcional: cómo usar sus tools — texto, o un .md de su carpeta;
|
|
15
|
+
-- sin el campo, INSTRUCTIONS.md si existe. Va al prompt de cada
|
|
16
|
+
-- agente que tenga alguna de sus tools: el plugin trae su proceso)
|
|
17
|
+
-- "channel": {"agent": "tienda"}} (opcional: un CANAL — lib/channels.syn. Sus acciones `receive` y
|
|
18
|
+
-- `send` no son tools del modelo, así que un canal puede no tener tools)
|
|
12
19
|
--
|
|
13
20
|
-- Cómo corre (patrón "safe runner" de la doc 22-sandbox): cada llamada es UN proceso hijo que termina.
|
|
14
21
|
-- kind=syn → `synsema run --cap-set stdout,time,env=PLUGIN_*[,caps] <entry>`: el techo lo fija el
|
|
@@ -45,6 +52,7 @@ let LEGACY_STATE_FILE be ".lampson/lamps.json"
|
|
|
45
52
|
export let PREFIX be "plugin_"
|
|
46
53
|
export let LEGACY_HINT be "old .lampson/lamps/ folder — rename it to .lampson/plugins/ (and lamp.json to plugin.json)"
|
|
47
54
|
let DEFAULT_TIMEOUT be 60
|
|
55
|
+
let MAX_INSTRUCTIONS be 12000
|
|
48
56
|
let BASE_CAPS be "stdout,time,env=PLUGIN_*,env=LAMP_*"
|
|
49
57
|
|
|
50
58
|
-- nombre de plugin: SIN "_" (el separador de plugin_<plugin>_<tool>); las tools sí pueden llevarlo
|
|
@@ -78,14 +86,37 @@ task read_manifest(dir, name, scope, legacy)
|
|
|
78
86
|
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "kind=syn needs \"entry\" (the .syn file)"}
|
|
79
87
|
when kind == "exec" and not contains(doc, "command")
|
|
80
88
|
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "kind=exec needs \"command\""}
|
|
81
|
-
|
|
89
|
+
-- canal (lib/channels.syn): {"agent": "<id>"} — el agente que atiende si nadie dice otro
|
|
90
|
+
let channel be nothing
|
|
91
|
+
when contains(doc, "channel") and doc["channel"] != nothing
|
|
92
|
+
when type_of(doc["channel"]) != "map"
|
|
93
|
+
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "channel must be an object, e.g. {\"agent\": \"support\"}"}
|
|
94
|
+
set channel to {"agent": when contains(doc["channel"], "agent") and doc["channel"]["agent"] != nothing then lower(text(doc["channel"]["agent"])) otherwise "", "typing": contains(doc["channel"], "typing") and doc["channel"]["typing"] == true, "poll": contains(doc["channel"], "poll") and doc["channel"]["poll"] == true}
|
|
95
|
+
let config be []
|
|
96
|
+
when contains(doc, "config") and doc["config"] != nothing
|
|
97
|
+
each ck in doc["config"]
|
|
98
|
+
when not matches(text(ck), "[A-Z][A-Z0-9_]{0,40}")
|
|
99
|
+
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "config names are UPPER_SNAKE (got '" + text(ck) + "')"}
|
|
100
|
+
set config to append(config, text(ck))
|
|
101
|
+
let raw_tools be when contains(doc, "tools") and doc["tools"] != nothing then doc["tools"] otherwise []
|
|
102
|
+
when length(raw_tools) == 0 and channel == nothing
|
|
82
103
|
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "no tools declared"}
|
|
83
104
|
let tools be []
|
|
84
|
-
each t in
|
|
105
|
+
each t in raw_tools
|
|
85
106
|
when not contains(t, "name") or not valid_tool_name(t["name"])
|
|
86
107
|
give {"ok": false, "name": name, "scope": scope, "legacy": is_legacy, "error": "a tool has no valid name"}
|
|
87
108
|
set tools to append(tools, {"name": text(t["name"]), "description": when contains(t, "description") then text(t["description"]) otherwise "", "parameters": when contains(t, "parameters") then t["parameters"] otherwise {"type": "object", "properties": {}}, "readonly": contains(t, "readonly") and t["readonly"] == true})
|
|
88
|
-
|
|
109
|
+
-- instrucciones: texto en el manifiesto, o un .md de la carpeta (por defecto INSTRUCTIONS.md)
|
|
110
|
+
let instr be ""
|
|
111
|
+
let ifile be when contains(doc, "instructions") and doc["instructions"] != nothing then text(doc["instructions"]) otherwise "INSTRUCTIONS.md"
|
|
112
|
+
when ends_with(lower(ifile), ".md") and not contains(ifile, "/") and not contains(ifile, "\\") and not contains(ifile, "\n")
|
|
113
|
+
when file_exists(dir + "/" + name + "/" + ifile)
|
|
114
|
+
set instr to trim(read_file(dir + "/" + name + "/" + ifile))
|
|
115
|
+
otherwise
|
|
116
|
+
set instr to trim(ifile)
|
|
117
|
+
when length(instr) > MAX_INSTRUCTIONS
|
|
118
|
+
set instr to slice(instr, 0, MAX_INSTRUCTIONS)
|
|
119
|
+
give {"ok": true, "name": name, "scope": scope, "legacy": is_legacy, "plugin": {"instructions": instr,"name": name, "scope": scope, "dir": dir + "/" + name, "kind": kind, "legacy": is_legacy, "description": when contains(doc, "description") then text(doc["description"]) otherwise "", "entry": when contains(doc, "entry") then text(doc["entry"]) otherwise "", "command": when contains(doc, "command") then text(doc["command"]) otherwise "", "caps": when contains(doc, "caps") then text(doc["caps"]) otherwise "", "timeout": when contains(doc, "timeout") then floor(number(doc["timeout"])) otherwise DEFAULT_TIMEOUT, "tools": tools, "channel": channel, "config": config}}
|
|
89
120
|
|
|
90
121
|
task scan(dir, scope, legacy)
|
|
91
122
|
let out be []
|
|
@@ -137,7 +168,7 @@ export task all()
|
|
|
137
168
|
set l["error"] to nothing
|
|
138
169
|
set out to append(out, l)
|
|
139
170
|
otherwise
|
|
140
|
-
set out to append(out, {"name": n, "scope": r["scope"], "dir": "", "kind": "?", "legacy": r["legacy"], "description": "", "entry": "", "command": "", "caps": "", "timeout": 0, "tools": [], "enabled": false, "error": r["error"]})
|
|
171
|
+
set out to append(out, {"name": n, "scope": r["scope"], "dir": "", "kind": "?", "legacy": r["legacy"], "description": "", "entry": "", "command": "", "caps": "", "timeout": 0, "tools": [], "channel": nothing, "config": [], "instructions": "", "enabled": false, "error": r["error"]})
|
|
141
172
|
give out
|
|
142
173
|
|
|
143
174
|
export task enabled()
|
|
@@ -288,11 +319,27 @@ export task call(full_name, args)
|
|
|
288
319
|
let tl be where(l["tools"], (t) => t["name"] == parts["tool"])
|
|
289
320
|
when length(tl) == 0
|
|
290
321
|
give "ERROR: plugin '" + l["name"] + "' has no tool '" + parts["tool"] + "'"
|
|
322
|
+
give invoke(l, parts["tool"], args)
|
|
323
|
+
|
|
324
|
+
-- corre UNA acción de un plugin encendido como proceso hijo: una tool del modelo, o `receive`/`send` de un canal
|
|
325
|
+
export task invoke(l, tool, args)
|
|
326
|
+
require exec
|
|
327
|
+
require time
|
|
328
|
+
require file(".lampson")
|
|
329
|
+
require file(".lampson/*")
|
|
330
|
+
require file.read("plugins")
|
|
331
|
+
require file.read("plugins/*")
|
|
332
|
+
require file("workspace")
|
|
333
|
+
require file("workspace/*")
|
|
334
|
+
require env("LAMPSON_*")
|
|
291
335
|
-- PLUGIN_DIR relativa a la raíz de lampson (cwd del hijo para kind=syn); PLUGIN_WORKSPACE = la ruta real del
|
|
292
336
|
-- proyecto (lampson.ps1 la exporta; sin ella, la junction). LAMP_* = los nombres viejos, por compat.
|
|
293
337
|
let tool_args be json_encode(when args == nothing then {} otherwise args)
|
|
294
338
|
let ws be env("LAMPSON_WORKSPACE", c.ROOT)
|
|
295
|
-
let envs be {"PLUGIN_TOOL":
|
|
339
|
+
let envs be {"PLUGIN_TOOL": tool, "PLUGIN_ARGS": tool_args, "PLUGIN_DIR": l["dir"], "PLUGIN_WORKSPACE": ws, "LAMP_TOOL": tool, "LAMP_ARGS": tool_args, "LAMP_DIR": l["dir"], "LAMP_WORKSPACE": ws}
|
|
340
|
+
-- "config": PLUGIN_<X> = LAMPSON_<X> (secretos y ajustes del plugin, desde el .env de lampson)
|
|
341
|
+
each ck in l["config"]
|
|
342
|
+
set envs["PLUGIN_" + ck] to env("LAMPSON_" + ck, "")
|
|
296
343
|
when l["kind"] == "syn"
|
|
297
344
|
-- techo del manifiesto: el código del plugin no puede pedir más de lo que el humano aprobó
|
|
298
345
|
give c.truncate(run_child(env("LAMPSON_SYNSEMA", "synsema"), ["run", "--cap-set", ceiling_of(l), l["dir"] + "/" + l["entry"]], ".", envs, l["timeout"]), c.MAX_OUTPUT)
|
|
@@ -311,6 +358,46 @@ export task call(full_name, args)
|
|
|
311
358
|
set resolved to append(resolved, tok)
|
|
312
359
|
give c.truncate(run_child(resolved[0], slice(resolved, 1, length(resolved)), c.ROOT, envs, l["timeout"]), c.MAX_OUTPUT)
|
|
313
360
|
|
|
361
|
+
-- las instrucciones de los plugins encendidos que tienen alguna tool en `tool_names` (el catálogo de un agente),
|
|
362
|
+
-- listas para sumar a su prompt. Un agente sin tools del plugin no las recibe.
|
|
363
|
+
export task instructions(tool_names)
|
|
364
|
+
require file(".lampson")
|
|
365
|
+
require file(".lampson/*")
|
|
366
|
+
require file.read("plugins")
|
|
367
|
+
require file.read("plugins/*")
|
|
368
|
+
require file("workspace")
|
|
369
|
+
require file("workspace/*")
|
|
370
|
+
require env("LAMPSON_*")
|
|
371
|
+
let out be ""
|
|
372
|
+
each l in enabled()
|
|
373
|
+
when l["instructions"] != ""
|
|
374
|
+
let mine be where(l["tools"], (t) => contains(tool_names, tool_name(l["name"], t["name"])))
|
|
375
|
+
when length(mine) > 0
|
|
376
|
+
set out to out + "\n\n# Plugin " + l["name"] + "\n" + l["instructions"]
|
|
377
|
+
give out
|
|
378
|
+
|
|
379
|
+
-- los canales encendidos (plugins con "channel"), y uno por nombre
|
|
380
|
+
export task channels()
|
|
381
|
+
require file(".lampson")
|
|
382
|
+
require file(".lampson/*")
|
|
383
|
+
require file.read("plugins")
|
|
384
|
+
require file.read("plugins/*")
|
|
385
|
+
require file("workspace")
|
|
386
|
+
require file("workspace/*")
|
|
387
|
+
require env("LAMPSON_*")
|
|
388
|
+
give where(enabled(), (l) => l["channel"] != nothing)
|
|
389
|
+
|
|
390
|
+
export task channel(name)
|
|
391
|
+
require file(".lampson")
|
|
392
|
+
require file(".lampson/*")
|
|
393
|
+
require file.read("plugins")
|
|
394
|
+
require file.read("plugins/*")
|
|
395
|
+
require file("workspace")
|
|
396
|
+
require file("workspace/*")
|
|
397
|
+
require env("LAMPSON_*")
|
|
398
|
+
let found be where(channels(), (l) => l["name"] == name)
|
|
399
|
+
give when length(found) == 0 then nothing otherwise found[0]
|
|
400
|
+
|
|
314
401
|
-- crear un plugin DEL PROYECTO (workspace/.lampson/plugins/<name>/): escribe plugin.json + el código, revalida el
|
|
315
402
|
-- manifiesto y, si es syn, corre `synsema check` sobre el entry. Como cordis_define en dsh: define y valida,
|
|
316
403
|
-- NO ejecuta ni enciende — encender sigue siendo del humano (set_enabled tras ask).
|
|
@@ -404,5 +491,5 @@ export task summary()
|
|
|
404
491
|
require env("LAMPSON_*")
|
|
405
492
|
let out be []
|
|
406
493
|
each l in all()
|
|
407
|
-
set out to append(out, {"name": l["name"], "scope": l["scope"], "kind": l["kind"], "legacy": l["legacy"], "description": l["description"], "enabled": l["enabled"], "error": l["error"], "caps": when l["kind"] == "syn" and l["error"] == nothing then ceiling_of(l) otherwise "", "command": when l["kind"] == "exec" then l["command"] otherwise "", "tools": apply(l["tools"], (t) => t["name"]), "tool_specs": l["tools"], "dir": l["dir"]})
|
|
494
|
+
set out to append(out, {"name": l["name"], "scope": l["scope"], "kind": l["kind"], "legacy": l["legacy"], "description": l["description"], "enabled": l["enabled"], "error": l["error"], "caps": when l["kind"] == "syn" and l["error"] == nothing then ceiling_of(l) otherwise "", "command": when l["kind"] == "exec" then l["command"] otherwise "", "tools": apply(l["tools"], (t) => t["name"]), "tool_specs": l["tools"], "dir": l["dir"], "channel": l["channel"] != nothing})
|
|
408
495
|
give out
|