lampson 0.2.9 → 0.3.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 +16 -0
- package/bin/lampson.js +2 -2
- package/chat.syn +39 -24
- package/cli.syn +6 -3
- package/hub.tpl.syn +4 -0
- package/lampson.ps1 +48 -6
- package/lampson.sh +69 -24
- package/lib/api.syn +153 -0
- package/lib/apikeys.syn +115 -0
- package/lib/channels.syn +340 -0
- package/lib/loop.syn +27 -1
- package/lib/mailbox.syn +418 -0
- package/lib/mcp.syn +128 -9
- package/lib/mcp_server.syn +235 -0
- package/lib/plugins.syn +62 -7
- package/lib/runtime.syn +572 -0
- package/lib/scope.syn +62 -0
- package/lib/session.syn +11 -1
- package/lib/tools.syn +1 -1
- package/lib/workspaces.syn +29 -3
- package/package.json +16 -2
- package/plugins/chatwoot/plugin.json +11 -0
- package/plugins/chatwoot/plugin.syn +143 -0
- package/plugins/telegram/plugin.json +11 -0
- package/plugins/telegram/plugin.syn +272 -0
- package/public/css/mobile.css +95 -0
- package/public/css/panel.css +2 -0
- package/public/index.html +12 -1
- package/public/js/app.js +1 -1
- package/public/js/engine.js +149 -0
- package/public/js/mobile.js +122 -0
- package/public/js/sessions.js +3 -1
- package/public/js/terminal.js +1 -1
- package/run.syn +394 -0
- package/sdk/index.d.ts +94 -0
- package/sdk/index.js +250 -0
- package/sdk/index.mjs +4 -0
- package/web.syn +315 -47
package/README.md
CHANGED
|
@@ -94,6 +94,22 @@ Plugins are yours and local: any language, no sandbox unless you write them in S
|
|
|
94
94
|
[lamps.sh](https://lamps.sh): `lamp add <ref>`, then `lamp mcp` as an MCP server in Lampson. (Until 0.2.6
|
|
95
95
|
plugins were called *lamps*; old `.lampson/lamps/` folders and `LAMP_*` variables still work for now.)
|
|
96
96
|
|
|
97
|
+
## Use it from your app
|
|
98
|
+
|
|
99
|
+
Lampson also runs **headless**, as the engine behind something else — a bot that answers your shop's
|
|
100
|
+
messages, a script that asks it about a database, another agent that delegates to it:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
lampson run "summarize what changed today" # prints the answer
|
|
104
|
+
echo "do you have whole-wheat bread?" | lampson run --agent shop --thread whatsapp:+5491122334455 --json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
An agent is a file: `.lampson/agents/shop.agent.json` in your project, with its own prompt, the exact tools it
|
|
108
|
+
may use and its permissions (`strict` by default when nobody is there to approve). Same `--thread` → same
|
|
109
|
+
conversation, so each customer keeps their own history. `--json` streams every step as JSON lines.
|
|
110
|
+
Details in [guide.md](guide.md#headless-lampson-run); where this is going (HTTP API, MCP server, channels,
|
|
111
|
+
agent teams) in [spec/engine.md](spec/engine.md).
|
|
112
|
+
|
|
97
113
|
## Also in the box
|
|
98
114
|
|
|
99
115
|
Sub-agents that work in parallel · skills (`SKILL.md` procedures, anything on [skills.sh](https://skills.sh)
|
package/bin/lampson.js
CHANGED
|
@@ -22,7 +22,7 @@ const home = process.env.LAMPSON_HOME || path.join(os.homedir(), 'lampson');
|
|
|
22
22
|
const marker = path.join(home, '.npm-installed');
|
|
23
23
|
|
|
24
24
|
// what gets copied into the home: the runtime, never state. Keep in sync with "files" in package.json.
|
|
25
|
-
const CODE = ['lib', 'public', 'skills', 'chat.syn', 'web.syn', 'hub.tpl.syn', 'edge.syn', 'cli.syn', 'lampson.ps1', 'lampson.sh', 'lampson.cmd', '.env.example', 'README.md', 'LICENSE'];
|
|
25
|
+
const CODE = ['lib', 'public', 'skills', 'chat.syn', 'run.syn', 'web.syn', 'hub.tpl.syn', 'edge.syn', 'cli.syn', 'lampson.ps1', 'lampson.sh', 'lampson.cmd', '.env.example', 'README.md', 'LICENSE'];
|
|
26
26
|
|
|
27
27
|
// copia un archivo; en unix, los scripts de shell y los .syn salen con LF aunque el paquete se haya armado
|
|
28
28
|
// en Windows (un CRLF en lampson.sh rompe bash: "set: pipefail\r: invalid option")
|
|
@@ -47,7 +47,7 @@ function sync() {
|
|
|
47
47
|
fs.mkdirSync(home, { recursive: true });
|
|
48
48
|
// the folders every workspace links to (lib/workspaces.syn LINKS): if `memory/` does not exist when the
|
|
49
49
|
// link is made, the link is born dangling and memory(write) fails with "No such file or directory"
|
|
50
|
-
for (const d of ['memory', 'plugins']) fs.mkdirSync(path.join(home, d), { recursive: true });
|
|
50
|
+
for (const d of ['memory', 'plugins', 'agents']) fs.mkdirSync(path.join(home, d), { recursive: true });
|
|
51
51
|
for (const item of CODE) {
|
|
52
52
|
const src = path.join(pkgDir, item);
|
|
53
53
|
if (!fs.existsSync(src)) continue;
|
package/chat.syn
CHANGED
|
@@ -25,6 +25,8 @@ require file.read("skills")
|
|
|
25
25
|
require file.read("skills/*")
|
|
26
26
|
require file.read("plugins")
|
|
27
27
|
require file.read("plugins/*")
|
|
28
|
+
require file.read("agents")
|
|
29
|
+
require file.read("agents/*")
|
|
28
30
|
require file("memory")
|
|
29
31
|
require file("memory/*")
|
|
30
32
|
require file(".lampson")
|
|
@@ -58,6 +60,7 @@ use "./lib/sched_run.syn" as sched_run
|
|
|
58
60
|
use "./lib/approvals.syn" as approvals
|
|
59
61
|
use "./lib/computer.syn" as computer
|
|
60
62
|
use "./lib/judge.syn" as jdg
|
|
63
|
+
use "./lib/runtime.syn" as runtime
|
|
61
64
|
|
|
62
65
|
-- ---------- UI de terminal ----------
|
|
63
66
|
-- Colores ANSI (Windows Terminal, PowerShell 7, cualquier terminal moderna). LAMPSON_NO_COLOR=1 los apaga.
|
|
@@ -255,8 +258,8 @@ task busy_off()
|
|
|
255
258
|
set waited to waited + 1
|
|
256
259
|
|
|
257
260
|
-- tag = "" para el agente principal; los subagentes en background NO pasan por acá (escriben su log)
|
|
261
|
+
-- el runtime (runtime.turn) ya trazó cada evento en .lampson/trace/<sid>.log: acá solo se dibuja
|
|
258
262
|
task on_event(kind, data, tag)
|
|
259
|
-
trace.event(sid, kind, data, tag)
|
|
260
263
|
when kind == "busy"
|
|
261
264
|
busy_on(data["label"], data["kind"])
|
|
262
265
|
otherwise when kind == "idle"
|
|
@@ -435,8 +438,8 @@ task complete_args(cmd, head, last)
|
|
|
435
438
|
give []
|
|
436
439
|
give apply((s) => s["id"], schedule.summary())
|
|
437
440
|
when cmd == "/agent"
|
|
438
|
-
--
|
|
439
|
-
give
|
|
441
|
+
-- los elegibles por el usuario (integrados + workspace/.lampson/agents): `worker` es interno de delegate
|
|
442
|
+
give runtime.names()
|
|
440
443
|
give []
|
|
441
444
|
|
|
442
445
|
-- rutas del workspace que empiezan con el prefijo escrito (directorios con "/" final para seguir completando)
|
|
@@ -549,7 +552,7 @@ task show_config(cfg, ws, profile, mode, opts)
|
|
|
549
552
|
print("")
|
|
550
553
|
print(" proveedor " + cfg["provider"] + " (" + cfg["wire"] + " → " + cfg["base_url"] + ")")
|
|
551
554
|
print(" modelo " + cfg["model"] + " max_tokens " + text(cfg["max_tokens"]) + " timeout " + text(floor(cfg["timeout"])) + "s")
|
|
552
|
-
print(" agente " + profile + " tools: " + join(agents.tool_names(
|
|
555
|
+
print(" agente " + profile + " tools: " + join(agents.tool_names(runtime.get(profile)), ", "))
|
|
553
556
|
print(" permisos " + mode)
|
|
554
557
|
print(" límites " + text(opts["max_steps"]) + " pasos/turno · " + text(floor(opts["budget_tokens"])) + " tokens/turno · compacta a " + text(floor(opts["compact_at_tokens"])))
|
|
555
558
|
print(" workspace " + ws)
|
|
@@ -864,16 +867,27 @@ when not provider.configured() and cfg["provider"] != "ollama"
|
|
|
864
867
|
let env_info be agents.env_info(cfg)
|
|
865
868
|
let profile be lower(env("LAMPSON_AGENT", "build"))
|
|
866
869
|
-- `--agent worker` (o cualquier nombre desconocido): worker es interno de delegate, no un perfil de sesión
|
|
867
|
-
when not contains(
|
|
868
|
-
print("agente '" + profile + "' no disponible · disponibles: " + join(
|
|
870
|
+
when not contains(runtime.names(), profile)
|
|
871
|
+
print("agente '" + profile + "' no disponible · disponibles: " + join(runtime.names(), ", ") + " · uso build")
|
|
869
872
|
set profile to "build"
|
|
873
|
+
-- un agente del proyecto con "model" propio corre con ese modelo (los integrados y los que no dicen, con el configurado).
|
|
874
|
+
-- /model lo cambia para la sesión, como siempre.
|
|
875
|
+
task cfg_for_agent(p)
|
|
876
|
+
let spec be runtime.get(p)
|
|
877
|
+
when spec != nothing and (spec["model"]["provider"] != "" or spec["model"]["model"] != "")
|
|
878
|
+
give provider.config_for(spec["model"]["provider"], spec["model"]["model"])
|
|
879
|
+
give provider.config()
|
|
880
|
+
set cfg to cfg_for_agent(profile)
|
|
881
|
+
set env_info to agents.env_info(cfg)
|
|
882
|
+
-- agentes por lib/runtime.syn (integrados y los del proyecto): el system prompt se arma una vez por sesión/cambio
|
|
883
|
+
-- de agente (prompt cache); las opts en cada turno (catálogo fresco)
|
|
870
884
|
task system_for(p)
|
|
871
|
-
give
|
|
885
|
+
give runtime.system_for(p, cfg)
|
|
872
886
|
task opts_for(p, mode)
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
give
|
|
887
|
+
give runtime.opts_for(p, mode, ask_user)
|
|
888
|
+
-- lo que runtime.turn / runtime.save necesitan de esta terminal: agente, cfg, opts y la sesión actual
|
|
889
|
+
task turn_ctx()
|
|
890
|
+
give {"ctx": {"cfg": cfg, "opts": opts, "agent": profile}, "session": sid, "thread": ""}
|
|
877
891
|
|
|
878
892
|
-- Subagente en background: `agent Child` (lib/agents.syn) corre en un hilo con intérprete propio y solo
|
|
879
893
|
-- puede llamar tasks TOP-LEVEL de este programa — esta es su única puerta de entrada al harness.
|
|
@@ -901,6 +915,8 @@ agent Sched
|
|
|
901
915
|
require file.read("skills/*")
|
|
902
916
|
require file.read("plugins")
|
|
903
917
|
require file.read("plugins/*")
|
|
918
|
+
require file.read("agents")
|
|
919
|
+
require file.read("agents/*")
|
|
904
920
|
require file("memory")
|
|
905
921
|
require file("memory/*")
|
|
906
922
|
require file(".lampson")
|
|
@@ -1042,14 +1058,11 @@ while running
|
|
|
1042
1058
|
print("")
|
|
1043
1059
|
print(" " + cyan("✉ " + first_line(m, 140)))
|
|
1044
1060
|
set messages to append(messages, {"role": "user", "content": m})
|
|
1045
|
-
trace.user(sid, "(turno automático por aviso de subagente)", profile, mode, cfg["model"])
|
|
1046
1061
|
set opts to opts_for(profile, mode)
|
|
1047
|
-
let result be
|
|
1048
|
-
trace.turn_end(sid, result)
|
|
1062
|
+
let result be runtime.turn(turn_ctx(), messages, "(turno automático por aviso de subagente)", {"on_event": on_event})
|
|
1049
1063
|
set messages to result["messages"]
|
|
1050
1064
|
set total_usage to {"input": total_usage["input"] + result["usage"]["input"], "output": total_usage["output"] + result["usage"]["output"]}
|
|
1051
1065
|
print(dim(" ─── " + text(result["steps"]) + " pasos · " + fmt_tokens(result["usage"]["input"] + result["usage"]["output"]) + " tokens · turno automático por subagente"))
|
|
1052
|
-
session.save(sid, messages, {"title": session.title_of(messages)})
|
|
1053
1066
|
flush()
|
|
1054
1067
|
otherwise
|
|
1055
1068
|
let saved be settings.load()
|
|
@@ -1449,16 +1462,21 @@ while running
|
|
|
1449
1462
|
otherwise when starts_with(input, "/agent")
|
|
1450
1463
|
let want be trim(slice(input, 6, length(input)))
|
|
1451
1464
|
when want == ""
|
|
1452
|
-
print("agente=" + profile + " · disponibles: " + join(
|
|
1453
|
-
otherwise when contains(
|
|
1465
|
+
print("agente=" + profile + " · disponibles: " + join(runtime.names(), ", "))
|
|
1466
|
+
otherwise when contains(runtime.names(), want)
|
|
1454
1467
|
set profile to want
|
|
1468
|
+
let prev_model be cfg["provider"] + "/" + cfg["model"]
|
|
1469
|
+
set cfg to cfg_for_agent(profile)
|
|
1470
|
+
set env_info to agents.env_info(cfg)
|
|
1471
|
+
when cfg["provider"] + "/" + cfg["model"] != prev_model
|
|
1472
|
+
print("modelo=" + cfg["provider"] + "/" + cfg["model"] + " (el del agente " + profile + ")")
|
|
1455
1473
|
set system_msg to system_for(profile)
|
|
1456
1474
|
set opts to opts_for(profile, mode)
|
|
1457
1475
|
-- el system prompt cambia con el perfil; el historial se conserva (cambiar de agente no borra la conversación)
|
|
1458
1476
|
set messages to [system_msg] + slice(messages, 1, length(messages))
|
|
1459
|
-
print("agente=" + profile + " · tools: " + join(
|
|
1477
|
+
print("agente=" + profile + " · tools: " + join(runtime.get(profile)["tools"], ", "))
|
|
1460
1478
|
otherwise
|
|
1461
|
-
print("no existe el agente " + want + " · disponibles: " + join(
|
|
1479
|
+
print("no existe el agente " + want + " · disponibles: " + join(runtime.names(), ", "))
|
|
1462
1480
|
otherwise when starts_with(input, "/")
|
|
1463
1481
|
print(" " + suggest(input))
|
|
1464
1482
|
otherwise when starts_with(input, "!")
|
|
@@ -1471,20 +1489,18 @@ while running
|
|
|
1471
1489
|
flush()
|
|
1472
1490
|
let out be run_interactive(cmd)
|
|
1473
1491
|
set messages to append(messages, {"role": "user", "content": "[The user ran this command in the shell themselves]\n$ " + cmd + "\n" + tools.truncate(out, 6000)})
|
|
1474
|
-
|
|
1492
|
+
runtime.save(turn_ctx(), messages)
|
|
1475
1493
|
otherwise
|
|
1476
1494
|
when length(pending_images) > 0
|
|
1477
1495
|
set messages to append(messages, {"role": "user", "content": input, "images": pending_images})
|
|
1478
1496
|
set pending_images to []
|
|
1479
1497
|
otherwise
|
|
1480
1498
|
set messages to append(messages, {"role": "user", "content": input})
|
|
1481
|
-
trace.user(sid, input, profile, mode, cfg["model"])
|
|
1482
1499
|
-- catálogo fresco por turno: si el turno anterior conectó/quitó un server MCP, sus tools
|
|
1483
1500
|
-- entran/salen acá (con los mismos servers el catálogo es idéntico → el prompt cache no se corta)
|
|
1484
1501
|
set opts to opts_for(profile, mode)
|
|
1485
1502
|
let t0 be now()
|
|
1486
|
-
let result be
|
|
1487
|
-
trace.turn_end(sid, result)
|
|
1503
|
+
let result be runtime.turn(turn_ctx(), messages, input, {"on_event": on_event})
|
|
1488
1504
|
set messages to result["messages"]
|
|
1489
1505
|
set total_usage to {"input": total_usage["input"] + result["usage"]["input"], "output": total_usage["output"] + result["usage"]["output"]}
|
|
1490
1506
|
let summary be text(result["steps"]) + (when result["steps"] == 1 then " paso" otherwise " pasos") + " · " + fmt_tokens(result["usage"]["input"] + result["usage"]["output"]) + " tokens · " + ui.fmt_duration(now() - t0)
|
|
@@ -1503,7 +1519,6 @@ while running
|
|
|
1503
1519
|
print(dim(" ─── " + summary))
|
|
1504
1520
|
otherwise
|
|
1505
1521
|
print(dim(" ─── " + summary))
|
|
1506
|
-
session.save(sid, messages, {"title": session.title_of(messages)})
|
|
1507
1522
|
flush()
|
|
1508
1523
|
-- los procesos gestionados (servidores) y los subagentes en background mueren con lampson
|
|
1509
1524
|
share true as "lampson:spinner:stop"
|
package/cli.syn
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
--
|
|
3
3
|
-- LAMPSON_CMD=ensure LAMPSON_WORKSPACE=<ruta> synsema run cli.syn
|
|
4
4
|
-- registra/prepara el workspace, asegura el hub y su proceso → imprime UNA línea JSON {slug, port, dir, url, alive}
|
|
5
|
+
-- LAMPSON_CMD=prepare LAMPSON_WORKSPACE=<ruta> lo mismo que ensure SIN hub ni proceso web: solo la carpeta del
|
|
6
|
+
-- workspace (lo que usan `lampson run`, `run --stdio`, `key`, `channel` y `mcp serve`, que no necesitan servidor)
|
|
5
7
|
-- LAMPSON_CMD=hub-status → {alive}
|
|
6
8
|
-- LAMPSON_CMD=hub-start | hub-stop | hub-reboot (stop + start: hub y workspaces; lo lanza ⚙ → Apagar o reiniciar)
|
|
7
9
|
-- LAMPSON_CMD=list
|
|
@@ -23,6 +25,7 @@ require file(".lampson/*")
|
|
|
23
25
|
require file.read("web.syn")
|
|
24
26
|
require file.read(".env")
|
|
25
27
|
require file.read("chat.syn")
|
|
28
|
+
require file.read("run.syn")
|
|
26
29
|
require file.read("hub.tpl.syn")
|
|
27
30
|
require file("hub.syn")
|
|
28
31
|
|
|
@@ -31,15 +34,15 @@ use "./lib/settings.syn" as settings
|
|
|
31
34
|
|
|
32
35
|
let cmd be env("LAMPSON_CMD", "ensure")
|
|
33
36
|
|
|
34
|
-
when cmd == "ensure"
|
|
37
|
+
when cmd == "ensure" or cmd == "prepare"
|
|
35
38
|
let path be env("LAMPSON_WORKSPACE", "")
|
|
36
39
|
when path == ""
|
|
37
40
|
raise("LAMPSON_WORKSPACE required")
|
|
38
41
|
let w be ws.ensure(path)
|
|
39
|
-
when not ws.hub_alive()
|
|
42
|
+
when cmd == "ensure" and not ws.hub_alive()
|
|
40
43
|
ws.start_hub()
|
|
41
44
|
let hc be ws.health(w)
|
|
42
|
-
when hc == nothing
|
|
45
|
+
when cmd == "ensure" and hc == nothing
|
|
43
46
|
ws.start_ws(w)
|
|
44
47
|
ws.wait_ready(w, 10)
|
|
45
48
|
set hc to ws.health(w)
|
package/hub.tpl.syn
CHANGED
|
@@ -27,6 +27,7 @@ require file(".lampson/*")
|
|
|
27
27
|
require file.read("web.syn")
|
|
28
28
|
require file.read(".env")
|
|
29
29
|
require file.read("chat.syn")
|
|
30
|
+
require file.read("run.syn")
|
|
30
31
|
require file.read("hub.tpl.syn")
|
|
31
32
|
require file("hub.syn")
|
|
32
33
|
require file.read("public")
|
|
@@ -73,6 +74,9 @@ serve on 8080
|
|
|
73
74
|
max_streams 200
|
|
74
75
|
auth with check_client
|
|
75
76
|
static "./public"
|
|
77
|
+
-- el hub es la UI y el manejo de workspaces: nada que publicar (/openapi.json, /llms.txt, /docs → 404). La API
|
|
78
|
+
-- para apps vive en cada workspace: /w/<slug>/v1/openapi.json
|
|
79
|
+
private
|
|
76
80
|
|
|
77
81
|
route "GET /"
|
|
78
82
|
when not page_allowed(request)
|
package/lampson.ps1
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
# lampson --domain lampson.midominio.com --email vos@midominio.com # HTTPS con tu dominio (opcional) · --domain off
|
|
9
9
|
# lampson --pair [https://tu-dominio] # QR en la terminal para emparejar el celular
|
|
10
10
|
# lampson --agent plan · --yolo|--strict|--ask · --update · --help
|
|
11
|
+
# lampson run [--agent ID] [--thread T | --session ID] [--json] [--yolo|--strict|--ask] "mensaje" # sin interfaz
|
|
12
|
+
# lampson run --stdio # modo local: un proceso abierto, un pedido JSON por línea (lo usa el SDK)
|
|
13
|
+
# lampson key add [--agent ID[,ID]] [--name NOMBRE] [--rate N] [--callback URL] · key list · key remove <id> # API keys /v1
|
|
14
|
+
# lampson mcp serve [--agent ID[,ID]] [--workspace RUTA] # Lampson como servidor MCP (stdio) para otros agentes
|
|
15
|
+
# lampson channel list · channel on|off <canal> · channel setup <canal> # canales (Telegram, Chatwoot…)
|
|
11
16
|
#
|
|
12
17
|
# Cómo funciona (ver SPEC-WORKSPACES.md): .lampson\ws\<slug>\ es el cwd del proceso del workspace, con una junction
|
|
13
18
|
# `workspace` al proyecto y junctions a lib/public/skills/plugins/memory de esta instalación. El registro y los procesos
|
|
@@ -18,7 +23,16 @@ $caller = (Get-Location).Path
|
|
|
18
23
|
|
|
19
24
|
# --- args: acepta --flag y -Flag, sin distinguir mayúsculas ---
|
|
20
25
|
$Workspace = ""; $Web = $false; $Agent = ""; $Perm = ""; $Hub = ""; $Install = ""; $Domain = $null; $Email = ""; $Pair = $null
|
|
26
|
+
$Run = $false; $Message = @(); $Thread = ""; $Session = ""; $Json = $false; $Key = ""; $KeyName = ""; $KeyId = ""; $McpServe = $false; $ChannelCmd = ""; $ChannelName = ""; $Stdio = $false; $KeyRate = ""; $KeyCallbacks = @()
|
|
21
27
|
$i = 0
|
|
28
|
+
# `lampson run …`: subcomando sin interfaz (run.syn, spec/engine.md); las palabras sueltas son el mensaje
|
|
29
|
+
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "run") { $Run = $true; $i = 1 }
|
|
30
|
+
# `lampson key add|list|remove …`: API keys (también corre run.syn, con LAMPSON_KEY_CMD)
|
|
31
|
+
# `lampson mcp serve …`: servidor MCP por stdio (run.syn con LAMPSON_MCP_SERVE)
|
|
32
|
+
if ($args.Count -gt 1 -and ([string]$args[0]).ToLower() -eq "mcp" -and ([string]$args[1]).ToLower() -eq "serve") { $Run = $true; $McpServe = $true; $i = 2 }
|
|
33
|
+
# `lampson channel list|on|off|setup <canal>` (run.syn con LAMPSON_CHANNEL_CMD)
|
|
34
|
+
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "channel") { $Run = $true; $ChannelCmd = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "list" }); $i = 2 }
|
|
35
|
+
if ($args.Count -gt 0 -and ([string]$args[0]).ToLower() -eq "key") { $Run = $true; $Key = $(if ($args.Count -gt 1) { ([string]$args[1]).ToLower() } else { "help" }); $i = 2 }
|
|
22
36
|
while ($i -lt $args.Count) {
|
|
23
37
|
$a = [string]$args[$i]
|
|
24
38
|
switch -Regex ($a.ToLower()) {
|
|
@@ -35,9 +49,16 @@ while ($i -lt $args.Count) {
|
|
|
35
49
|
'^--?(strict|s)$' { $Perm = "strict" }
|
|
36
50
|
'^--?(ask)$' { $Perm = "ask" }
|
|
37
51
|
'^--?(permission|p)$' { $i++; $Perm = ([string]$args[$i]).ToLower() }
|
|
52
|
+
'^--?thread$' { $i++; $Thread = [string]$args[$i] }
|
|
53
|
+
'^--?session$' { $i++; $Session = [string]$args[$i] }
|
|
54
|
+
'^--?json$' { $Json = $true }
|
|
55
|
+
'^--?stdio$' { $Stdio = $true }
|
|
56
|
+
'^--?name$' { $i++; $KeyName = [string]$args[$i] }
|
|
57
|
+
'^--?rate$' { $i++; $KeyRate = [string]$args[$i] }
|
|
58
|
+
'^--?callback$' { $i++; $KeyCallbacks += [string]$args[$i] }
|
|
38
59
|
'^--?(update|u)$' { Write-Host "actualizando Lampson en $here"; git -C $here pull --ff-only origin main; Write-Host ("lampson " + (git -C $here rev-parse --short HEAD)); exit $LASTEXITCODE }
|
|
39
|
-
'^--?(help|h|\?)$' { Get-Content $PSCommandPath | Select-Object -Skip 1 -First
|
|
40
|
-
default { if ($Workspace -eq "" -and -not $a.StartsWith("-")) { $Workspace = $a } else { Write-Error "argumento desconocido: $a (probá lampson --help)"; exit 1 } }
|
|
60
|
+
'^--?(help|h|\?)$' { Get-Content $PSCommandPath | Select-Object -Skip 1 -First 9 | ForEach-Object { $_.TrimStart('#',' ') }; exit 0 }
|
|
61
|
+
default { if ($ChannelCmd -ne "" -and -not $a.StartsWith("-")) { $ChannelName = $a } elseif ($Key -ne "" -and -not $a.StartsWith("-")) { $KeyId = $a } elseif ($Run -and -not $a.StartsWith("-")) { $Message += $a } elseif ($Workspace -eq "" -and -not $a.StartsWith("-")) { $Workspace = $a } else { Write-Error "argumento desconocido: $a (probá lampson --help)"; exit 1 } }
|
|
41
62
|
}
|
|
42
63
|
$i++
|
|
43
64
|
}
|
|
@@ -73,7 +94,8 @@ function Invoke-Cli([string]$cmd, [string]$ws) {
|
|
|
73
94
|
$out = & synsema run cli.syn 2>&1
|
|
74
95
|
if ($LASTEXITCODE -ne 0) { $out | ForEach-Object { Write-Host $_ }; throw "cli.syn falló ($cmd)" }
|
|
75
96
|
$lines = @($out | ForEach-Object { [string]$_ })
|
|
76
|
-
|
|
97
|
+
# en `lampson run` la salida es del programa que llama (JSONL): lo informativo va a stderr
|
|
98
|
+
$lines | Select-Object -SkipLast 1 | ForEach-Object { if ($Run) { [Console]::Error.WriteLine($_) } else { Write-Host $_ } }
|
|
77
99
|
return ($lines[-1] | ConvertFrom-Json)
|
|
78
100
|
}
|
|
79
101
|
|
|
@@ -139,7 +161,8 @@ try {
|
|
|
139
161
|
if ($target -eq $here) { Write-Error "no montes el propio directorio de lampson como workspace"; exit 1 }
|
|
140
162
|
|
|
141
163
|
# registrar/preparar el workspace y asegurar hub + proceso
|
|
142
|
-
|
|
164
|
+
# `run`, `key`, `channel` y `mcp serve` no necesitan servidor: solo la carpeta del workspace (sin hub)
|
|
165
|
+
$r = Invoke-Cli $(if ($Run) { "prepare" } else { "ensure" }) $target
|
|
143
166
|
$wsDir = Join-Path $here ($r.dir -replace '/', '\')
|
|
144
167
|
if ($Web) {
|
|
145
168
|
Write-Host ("Lampson web · " + $r.url + " (workspace " + $r.slug + $(if ($r.alive) { " ● vivo" } else { " ○ arrancando" }) + ")")
|
|
@@ -157,9 +180,28 @@ try {
|
|
|
157
180
|
if ($r.judge_model) { $env:SYNSEMA_JUDGE_MODEL = $r.judge_model }
|
|
158
181
|
if ($r.judge_key) { $env:TYPESAFE_API_KEY = $r.judge_key }
|
|
159
182
|
$envFile = Join-Path $here ".env"
|
|
160
|
-
|
|
161
|
-
|
|
183
|
+
$entry = "chat.syn"
|
|
184
|
+
if ($Run) {
|
|
185
|
+
# sin interfaz: los permisos los fija el flag, o el agente (run.syn: strict si el agente no dice nada)
|
|
186
|
+
$entry = "run.syn"
|
|
187
|
+
$env:LAMPSON_MESSAGE = ($Message -join " "); $env:LAMPSON_RUN_PERMISSION = $Perm
|
|
188
|
+
$env:LAMPSON_THREAD = $Thread; $env:LAMPSON_SESSION = $Session; $env:LAMPSON_RUN_JSON = $(if ($Json) { "1" } else { "" })
|
|
189
|
+
$env:LAMPSON_KEY_CMD = $Key; $env:LAMPSON_KEY_NAME = $KeyName; $env:LAMPSON_KEY_ID = $KeyId; $env:LAMPSON_KEY_AGENTS = $Agent
|
|
190
|
+
$env:LAMPSON_KEY_RATE = $KeyRate; $env:LAMPSON_KEY_CALLBACKS = ($KeyCallbacks -join ",")
|
|
191
|
+
$env:LAMPSON_MCP_SERVE = $(if ($McpServe) { "1" } else { "" }); $env:LAMPSON_MCP_AGENTS = $(if ($McpServe) { $Agent } else { "" })
|
|
192
|
+
$env:LAMPSON_CHANNEL_CMD = $ChannelCmd; $env:LAMPSON_CHANNEL_NAME = $ChannelName
|
|
193
|
+
$env:LAMPSON_RUN_STDIO = $(if ($Stdio) { "1" } else { "" })
|
|
194
|
+
}
|
|
195
|
+
if (Test-Path -LiteralPath $envFile) { synsema run --env-file $envFile $entry } else { synsema run $entry }
|
|
196
|
+
$exitCode = $LASTEXITCODE
|
|
197
|
+
} finally {
|
|
198
|
+
Pop-Location
|
|
199
|
+
# `lampson` corre este script dentro de TU sesión de PowerShell: lo de `run`/`key` no debe quedar en el entorno
|
|
200
|
+
# (un LAMPSON_SESSION que queda haría que el próximo `lampson` retome esa sesión sin pedirlo)
|
|
201
|
+
if ($Run) { foreach ($v in "LAMPSON_MESSAGE","LAMPSON_RUN_PERMISSION","LAMPSON_THREAD","LAMPSON_SESSION","LAMPSON_RUN_JSON","LAMPSON_KEY_CMD","LAMPSON_KEY_NAME","LAMPSON_KEY_ID","LAMPSON_KEY_AGENTS","LAMPSON_MCP_SERVE","LAMPSON_MCP_AGENTS","LAMPSON_CHANNEL_CMD","LAMPSON_CHANNEL_NAME","LAMPSON_RUN_STDIO","LAMPSON_KEY_RATE","LAMPSON_KEY_CALLBACKS") { Remove-Item "Env:$v" -ErrorAction SilentlyContinue } }
|
|
202
|
+
}
|
|
162
203
|
} finally {
|
|
163
204
|
Pop-Location
|
|
164
205
|
try { [Console]::OutputEncoding = $prevOutEnc } catch {}
|
|
165
206
|
}
|
|
207
|
+
if ($Run) { exit $exitCode }
|
package/lampson.sh
CHANGED
|
@@ -6,10 +6,26 @@
|
|
|
6
6
|
# lampson --domain lampson.midominio.com --email vos@midominio.com # HTTPS propio (opcional) · --domain off
|
|
7
7
|
# lampson --pair [https://tu-dominio] # QR en la terminal para emparejar el celular
|
|
8
8
|
# lampson --workspace /ruta [--agent plan] [--yolo|--strict|--ask] · --update
|
|
9
|
+
# lampson run [--agent ID] [--thread T | --session ID] [--json] [--yolo|--strict|--ask] "mensaje" # sin interfaz
|
|
10
|
+
# (sin mensaje lo lee de stdin; --json = eventos JSONL; ver spec/engine.md y run.syn)
|
|
11
|
+
# lampson run --stdio # modo local: un proceso abierto, un pedido JSON por línea (lo usa el SDK)
|
|
12
|
+
# lampson key add [--agent ID[,ID]] [--name NOMBRE] [--rate N] [--callback URL] · key list · key remove <id> # API keys /v1
|
|
13
|
+
# lampson mcp serve [--agent ID[,ID]] [--workspace RUTA] # Lampson como servidor MCP (stdio) para otros agentes
|
|
14
|
+
# lampson channel list · channel on|off <canal> · channel setup <canal> # canales (Telegram, Chatwoot…)
|
|
9
15
|
set -euo pipefail
|
|
10
|
-
|
|
16
|
+
# se lo llama por el symlink `lampson` (~/.local/bin): la carpeta es donde vive el script de verdad
|
|
17
|
+
here="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
|
11
18
|
caller="$(pwd)"
|
|
12
19
|
ws=""; web=0; hub=""; install=""; domain="-"; email=""; pair_url="-"
|
|
20
|
+
run=0; msg=""; perm_flag=""; key=""; key_name=""; key_id=""; mcp_serve=""; ch_cmd=""; ch_name=""
|
|
21
|
+
# `lampson run …`: subcomando sin interfaz (run.syn); las palabras sueltas son el mensaje, no el workspace
|
|
22
|
+
if [ "${1:-}" = run ]; then run=1; shift; fi
|
|
23
|
+
# `lampson key add|list|remove …`: API keys (también corre run.syn, con LAMPSON_KEY_CMD)
|
|
24
|
+
# `lampson mcp serve …`: servidor MCP por stdio (run.syn con LAMPSON_MCP_SERVE)
|
|
25
|
+
if [ "${1:-}" = mcp ] && [ "${2:-}" = serve ]; then run=1; mcp_serve=1; shift 2; fi
|
|
26
|
+
# `lampson channel list|on|off|setup <canal>` (run.syn con LAMPSON_CHANNEL_CMD)
|
|
27
|
+
if [ "${1:-}" = channel ]; then run=1; ch_cmd="${2:-list}"; shift; [ $# -gt 0 ] && shift; fi
|
|
28
|
+
if [ "${1:-}" = key ]; then run=1; key="${2:-help}"; shift; [ $# -gt 0 ] && shift; fi
|
|
13
29
|
while [ $# -gt 0 ]; do
|
|
14
30
|
case "$1" in
|
|
15
31
|
--web) web=1 ;;
|
|
@@ -21,12 +37,19 @@ while [ $# -gt 0 ]; do
|
|
|
21
37
|
--uninstall) install=uninstall ;;
|
|
22
38
|
--workspace) shift; ws="$1" ;;
|
|
23
39
|
--agent) shift; export LAMPSON_AGENT="$1" ;;
|
|
24
|
-
--yolo|--dangerously-skip-permissions) export LAMPSON_PERMISSION=yolo ;;
|
|
25
|
-
--strict) export LAMPSON_PERMISSION=strict ;;
|
|
26
|
-
--ask) export LAMPSON_PERMISSION=ask ;;
|
|
40
|
+
--yolo|--dangerously-skip-permissions) export LAMPSON_PERMISSION=yolo; perm_flag=yolo ;;
|
|
41
|
+
--strict) export LAMPSON_PERMISSION=strict; perm_flag=strict ;;
|
|
42
|
+
--ask) export LAMPSON_PERMISSION=ask; perm_flag=ask ;;
|
|
43
|
+
--thread) shift; export LAMPSON_THREAD="$1" ;;
|
|
44
|
+
--session) shift; export LAMPSON_SESSION="$1" ;;
|
|
45
|
+
--json) export LAMPSON_RUN_JSON=1 ;;
|
|
46
|
+
--stdio) export LAMPSON_RUN_STDIO=1 ;;
|
|
47
|
+
--name) shift; key_name="$1" ;;
|
|
48
|
+
--rate) shift; export LAMPSON_KEY_RATE="$1" ;;
|
|
49
|
+
--callback) shift; export LAMPSON_KEY_CALLBACKS="${LAMPSON_KEY_CALLBACKS:+$LAMPSON_KEY_CALLBACKS,}$1" ;;
|
|
27
50
|
--update) echo "actualizando Lampson en $here"; git -C "$here" pull --ff-only origin main; echo "lampson $(git -C "$here" rev-parse --short HEAD)"; exit $? ;;
|
|
28
|
-
-*) echo "uso: lampson [--web] [--hub start|stop|status|logs|restart] [--domain DOMINIO|off [--email EMAIL]] [--pair [URL]] [--install|--uninstall] [--workspace RUTA] [--agent PERFIL] [--yolo|--strict|--ask] [--update]" >&2; exit 1 ;;
|
|
29
|
-
*) ws="$1" ;;
|
|
51
|
+
-*) echo "uso: lampson run [--agent ID] [--thread T|--session ID] [--json] [--yolo|--strict|--ask] [mensaje]" >&2; echo "uso: lampson [--web] [--hub start|stop|status|logs|restart] [--domain DOMINIO|off [--email EMAIL]] [--pair [URL]] [--install|--uninstall] [--workspace RUTA] [--agent PERFIL] [--yolo|--strict|--ask] [--update]" >&2; exit 1 ;;
|
|
52
|
+
*) if [ -n "$ch_cmd" ]; then ch_name="$1"; elif [ -n "$key" ]; then key_id="$1"; elif [ "$run" = 1 ]; then msg="${msg:+$msg }$1"; else ws="$1"; fi ;;
|
|
30
53
|
esac
|
|
31
54
|
shift
|
|
32
55
|
done
|
|
@@ -56,6 +79,33 @@ cli() { # última línea = JSON
|
|
|
56
79
|
echo "$out" | tail -n 1
|
|
57
80
|
}
|
|
58
81
|
json() { node -e "const j=JSON.parse(process.argv[1]);const v=j[process.argv[2]];console.log(typeof v==='object'?JSON.stringify(v):v)" "$1" "$2" 2>/dev/null || python3 -c "import json,sys;print(json.loads(sys.argv[1])[sys.argv[2]])" "$1" "$2"; }
|
|
82
|
+
unit="$HOME/.config/systemd/user/lampson-hub.service"
|
|
83
|
+
# systemd no hereda el PATH de la sesión (~/.local/bin, donde se instala synsema, no está): sin estas dos líneas el hub
|
|
84
|
+
# arranca pero no puede encender ningún workspace ni los agentes encuentran node, git, claude…
|
|
85
|
+
write_unit() {
|
|
86
|
+
mkdir -p "$(dirname "$unit")"
|
|
87
|
+
cat > "$unit" <<EOF
|
|
88
|
+
[Unit]
|
|
89
|
+
Description=Lampson hub (workspaces, tareas programadas, proxy)
|
|
90
|
+
After=network.target
|
|
91
|
+
[Service]
|
|
92
|
+
WorkingDirectory=$here
|
|
93
|
+
Environment=LAMPSON_HOME=$here
|
|
94
|
+
Environment="LAMPSON_SYNSEMA=$(command -v synsema)"
|
|
95
|
+
Environment="PATH=$(dirname "$(command -v synsema)"):$PATH"
|
|
96
|
+
ExecStart=$(command -v synsema) serve hub.syn
|
|
97
|
+
Restart=always
|
|
98
|
+
RestartSec=3
|
|
99
|
+
TimeoutStopSec=20
|
|
100
|
+
[Install]
|
|
101
|
+
WantedBy=default.target
|
|
102
|
+
EOF
|
|
103
|
+
}
|
|
104
|
+
# una unit de antes de ese arreglo se reescribe sola (una vez) y el hub se reinicia con el PATH bueno
|
|
105
|
+
if [ "$install" = "" ] && [ -f "$unit" ] && ! grep -q LAMPSON_SYNSEMA "$unit"; then
|
|
106
|
+
write_unit
|
|
107
|
+
systemctl --user daemon-reload && systemctl --user restart lampson-hub.service && echo "lampson: servicio del hub actualizado (PATH del motor)" >&2 || true
|
|
108
|
+
fi
|
|
59
109
|
# dominio propio (opcional): HTTPS automático con Let's Encrypt delante del hub
|
|
60
110
|
if [ "$domain" != "-" ]; then
|
|
61
111
|
(cd "$here" && LAMPSON_CMD=domain LAMPSON_DOMAIN="$domain" LAMPSON_EMAIL="$email" synsema run cli.syn | sed '$d')
|
|
@@ -90,33 +140,20 @@ if [ -n "$hub" ]; then
|
|
|
90
140
|
exit 0
|
|
91
141
|
fi
|
|
92
142
|
if [ "$install" = install ]; then
|
|
93
|
-
|
|
94
|
-
cat > "$unit" <<EOF
|
|
95
|
-
[Unit]
|
|
96
|
-
Description=Lampson hub (workspaces, tareas programadas, proxy)
|
|
97
|
-
After=network.target
|
|
98
|
-
[Service]
|
|
99
|
-
WorkingDirectory=$here
|
|
100
|
-
Environment=LAMPSON_HOME=$here
|
|
101
|
-
ExecStart=$(command -v synsema) serve hub.syn
|
|
102
|
-
Restart=always
|
|
103
|
-
RestartSec=3
|
|
104
|
-
TimeoutStopSec=20
|
|
105
|
-
[Install]
|
|
106
|
-
WantedBy=default.target
|
|
107
|
-
EOF
|
|
143
|
+
write_unit
|
|
108
144
|
(cd "$here" && LAMPSON_CMD=hub-stop synsema run cli.syn >/dev/null 2>&1 || true)
|
|
109
145
|
systemctl --user daemon-reload && systemctl --user enable --now lampson-hub.service && echo "instalado: systemd --user lampson-hub.service (arranca con tu sesión; 'loginctl enable-linger $USER' para que viva sin sesión abierta)"
|
|
110
146
|
exit 0
|
|
111
147
|
fi
|
|
112
|
-
if [ "$install" = uninstall ]; then systemctl --user disable --now lampson-hub.service || true; rm -f "$
|
|
148
|
+
if [ "$install" = uninstall ]; then systemctl --user disable --now lampson-hub.service || true; rm -f "$unit"; systemctl --user daemon-reload; echo "quitado"; exit 0; fi
|
|
113
149
|
# --- proyecto ---
|
|
114
150
|
[ -z "$ws" ] && [ "$caller" != "$here" ] && ws="$caller"
|
|
115
151
|
[ -n "$ws" ] || { echo "corré lampson desde la carpeta del proyecto, o --workspace /ruta (lampson --hub status lista los workspaces)" >&2; exit 1; }
|
|
116
152
|
[ -d "$ws" ] || { echo "el workspace no existe o no es un directorio: $ws" >&2; exit 1; }
|
|
117
153
|
ws="$(cd "$ws" && pwd -P)"
|
|
118
154
|
[ "$ws" = "$HOME" ] || [ "$ws" = "/" ] && { echo "'$ws' no es un proyecto" >&2; exit 1; }
|
|
119
|
-
|
|
155
|
+
# `run`, `key`, `channel` y `mcp serve` no necesitan servidor: solo la carpeta del workspace (sin hub)
|
|
156
|
+
r="$(cli "$([ "$run" = 1 ] && echo prepare || echo ensure)" "$ws")"
|
|
120
157
|
slug="$(json "$r" slug)"; port="$(json "$r" port)"; url="$(json "$r" url)"; dir="$(json "$r" dir)"
|
|
121
158
|
if [ "$web" = 1 ]; then
|
|
122
159
|
echo "Lampson web · $url (workspace $slug)"
|
|
@@ -130,4 +167,12 @@ jp="$(json "$r" judge_provider)"; jm="$(json "$r" judge_model)"; jk="$(json "$r"
|
|
|
130
167
|
[ -n "$jp" ] && export SYNSEMA_JUDGE_PROVIDER="$jp"
|
|
131
168
|
[ -n "$jm" ] && export SYNSEMA_JUDGE_MODEL="$jm"
|
|
132
169
|
[ -n "$jk" ] && export TYPESAFE_API_KEY="$jk"
|
|
133
|
-
|
|
170
|
+
entry=chat.syn
|
|
171
|
+
if [ "$run" = 1 ]; then
|
|
172
|
+
# sin interfaz: los permisos los fija el flag, o el agente (run.syn: strict si el agente no dice nada)
|
|
173
|
+
entry=run.syn; export LAMPSON_MESSAGE="$msg" LAMPSON_RUN_PERMISSION="$perm_flag"
|
|
174
|
+
export LAMPSON_KEY_CMD="$key" LAMPSON_KEY_NAME="$key_name" LAMPSON_KEY_ID="$key_id" LAMPSON_KEY_AGENTS="${LAMPSON_AGENT:-}"
|
|
175
|
+
export LAMPSON_CHANNEL_CMD="$ch_cmd" LAMPSON_CHANNEL_NAME="$ch_name"
|
|
176
|
+
export LAMPSON_MCP_SERVE="$mcp_serve" LAMPSON_MCP_AGENTS="$([ -n "$mcp_serve" ] && echo "${LAMPSON_AGENT:-}")"
|
|
177
|
+
fi
|
|
178
|
+
if [ -f "$here/.env" ]; then exec synsema run --env-file "$here/.env" "$entry"; else exec synsema run "$entry"; fi
|