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
package/lib/scope.syn
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
-- lib/scope.syn — alcance por ruta de las tools de archivos (opcional, por agente; spec/engine.md)
|
|
2
|
+
--
|
|
3
|
+
-- Un agente del proyecto puede limitar una tool de archivos a ciertas rutas del workspace:
|
|
4
|
+
-- "tools": ["read"] -- todo el workspace (lo de siempre)
|
|
5
|
+
-- "tools": [{"name": "read", "paths": [".lampson/tienda/*"]}] -- solo eso
|
|
6
|
+
-- Patrones, relativos a la raíz del workspace: "dir/*" (o "dir/**") = la carpeta y todo lo de adentro;
|
|
7
|
+
-- "a/b.json" = ese archivo; "*" = todo el workspace. Sin comodines en otro lugar (nada de "*.json").
|
|
8
|
+
--
|
|
9
|
+
-- Lo hace cumplir loop.execute ANTES de correr la tool (opts["scopes"] = {tool: [patrones]}), con el mismo
|
|
10
|
+
-- c.ws() que usan las tools para resolver la ruta: lo que se compara es la ruta real, no el texto del modelo.
|
|
11
|
+
-- Una tool que lee cualquier archivo por otro camino (bash, process, delegate, lsp, computer_use) no puede
|
|
12
|
+
-- convivir con tools limitadas en el mismo agente: lo rechaza runtime.validate.
|
|
13
|
+
|
|
14
|
+
use "./tools/common.syn" as c
|
|
15
|
+
|
|
16
|
+
export let SCOPABLE be ["read", "write", "edit", "ls", "find", "grep"]
|
|
17
|
+
export let ESCAPES be ["bash", "process", "delegate", "lsp", "computer_use"]
|
|
18
|
+
|
|
19
|
+
-- {ok, real, recursive, error}
|
|
20
|
+
export task norm(pattern)
|
|
21
|
+
let p be trim(replace(text(pattern), "\\", "/"))
|
|
22
|
+
let recursive be false
|
|
23
|
+
when p == "*" or p == "**"
|
|
24
|
+
give {"ok": true, "real": c.ROOT, "recursive": true, "error": ""}
|
|
25
|
+
when c.ends_with(p, "/**")
|
|
26
|
+
set p to slice(p, 0, length(p) - 3)
|
|
27
|
+
set recursive to true
|
|
28
|
+
otherwise when c.ends_with(p, "/*")
|
|
29
|
+
set p to slice(p, 0, length(p) - 2)
|
|
30
|
+
set recursive to true
|
|
31
|
+
when p == "" or contains(p, "*")
|
|
32
|
+
give {"ok": false, "real": "", "recursive": false, "error": "path pattern '" + text(pattern) + "': use 'dir/*' (a folder and everything in it), an exact file, or '*' (whole workspace)"}
|
|
33
|
+
try
|
|
34
|
+
give {"ok": true, "real": c.ws(p), "recursive": recursive, "error": ""}
|
|
35
|
+
recover err
|
|
36
|
+
give {"ok": false, "real": "", "recursive": false, "error": "path pattern '" + text(pattern) + "' escapes the workspace"}
|
|
37
|
+
|
|
38
|
+
task covers(n, real)
|
|
39
|
+
when n["recursive"]
|
|
40
|
+
give real == n["real"] or starts_with(real, n["real"] + "/")
|
|
41
|
+
give real == n["real"]
|
|
42
|
+
|
|
43
|
+
-- "" si la llamada entra en el alcance; si no, el motivo (lo ve el modelo)
|
|
44
|
+
export task violation(name, args, patterns)
|
|
45
|
+
let raw be nothing
|
|
46
|
+
when contains(args, "path")
|
|
47
|
+
set raw to args["path"]
|
|
48
|
+
let real be ""
|
|
49
|
+
try
|
|
50
|
+
set real to c.ws(raw)
|
|
51
|
+
recover err
|
|
52
|
+
give "path outside the workspace"
|
|
53
|
+
-- resultados largos guardados por el propio loop (.lampson/spill): ya pasaron por este alcance
|
|
54
|
+
when starts_with(real, ".lampson/spill/")
|
|
55
|
+
give ""
|
|
56
|
+
each p in patterns
|
|
57
|
+
let n be norm(p)
|
|
58
|
+
when n["ok"]
|
|
59
|
+
when covers(n, real)
|
|
60
|
+
give ""
|
|
61
|
+
let shown be when raw == nothing or text(raw) == "" then "." otherwise text(raw)
|
|
62
|
+
give "this agent's " + name + " is limited to " + join(patterns, ", ") + " — '" + shown + "' is outside"
|
package/lib/session.syn
CHANGED
|
@@ -80,7 +80,17 @@ export task list()
|
|
|
80
80
|
set out to out
|
|
81
81
|
recover err
|
|
82
82
|
give []
|
|
83
|
-
give sort_by(out, (s) => 0 -
|
|
83
|
+
give sort_by(out, (s) => 0 - id_key(s["id"]))
|
|
84
|
+
|
|
85
|
+
-- orden de los ids: YYYYMMDD-HHMMSS (terminal, web) y YYYYMMDD-HHMMSS-NNNN (lib/runtime.syn: dos threads en el mismo
|
|
86
|
+
-- segundo). 18 dígitos no entran exactos en un float → int, con el timestamp × 10000 + sufijo para que viejos y
|
|
87
|
+
-- nuevos queden en orden de creación. Un id que no es de dígitos (test-…) va al final.
|
|
88
|
+
export task id_key(id)
|
|
89
|
+
let d be replace(replace(id, "-", ""), "test", "")
|
|
90
|
+
when not matches(d, "[0-9]+") or length(d) < 14
|
|
91
|
+
give 0
|
|
92
|
+
let suffix be slice(d, 14, length(d))
|
|
93
|
+
give int(slice(d, 0, 14)) * 10000 + (when suffix == "" then 0 otherwise int(slice(suffix, 0, 4)))
|
|
84
94
|
|
|
85
95
|
-- Búsqueda de texto en las sesiones de ESTE proyecto (título y contenido de los mensajes user/assistant):
|
|
86
96
|
-- [{id, updated, title, snippet}] — snippet = el primer trozo donde aparece `q`. Vacío = todas (sin snippet).
|
package/lib/teamrun.syn
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
-- lib/teamrun.syn — el pulso de los equipos: entrega los mensajes entre agentes y lanza las rondas
|
|
2
|
+
--
|
|
3
|
+
-- Corre en el proceso del workspace (web.syn, cron cada TICK_SECONDS). Todo entra al agente por el BUZÓN
|
|
4
|
+
-- (lib/mailbox.syn), como un mensaje de un cliente: una conversación por agente y equipo (thread "team:<id>"),
|
|
5
|
+
-- nunca dos turnos a la vez, ráfagas juntas. Cada turno arranca con lo que llegó + lo que pasó en el equipo desde su
|
|
6
|
+
-- último turno + sus tareas (teams.turn_text).
|
|
7
|
+
-- * mensajes: los que `send` dejó pendientes en la base → al buzón del destinatario
|
|
8
|
+
-- * rondas: un agente con trabajo (novedades de otros o tareas suyas abiertas) cada round_minutes del equipo
|
|
9
|
+
-- * presupuesto: un agente que pasó su tope diario no recibe turnos (sus mensajes esperan al día siguiente);
|
|
10
|
+
-- queda UNA entrada en el registro por día
|
|
11
|
+
use "./teams.syn" as teams
|
|
12
|
+
use "./mailbox.syn" as mailbox
|
|
13
|
+
use "./runtime.syn" as runtime
|
|
14
|
+
|
|
15
|
+
export let TICK_SECONDS be 3
|
|
16
|
+
export let ROUND_TEXT be "[round] Your periodic round: look at your open tasks and the team's news above, and move your work forward. If there is nothing for you to do, reply with one short line and stop — don't invent work."
|
|
17
|
+
|
|
18
|
+
task flag_budget(team, agent)
|
|
19
|
+
require db(".lampson/teams.db")
|
|
20
|
+
require file(".lampson")
|
|
21
|
+
require file(".lampson/*")
|
|
22
|
+
require time
|
|
23
|
+
let k be "teams:budget:" + team["id"] + ":" + agent + ":" + format_time(now(), "%Y-%m-%d")
|
|
24
|
+
when state_get(k) == nothing
|
|
25
|
+
state_set(k, true)
|
|
26
|
+
teams.log("team:" + team["id"], agent, "budget", "", "daily budget reached (" + text(team["budget_daily_tokens"]) + " tokens): no more turns today")
|
|
27
|
+
|
|
28
|
+
-- un turno para `agent` en su conversación del equipo
|
|
29
|
+
export task deliver_to(team, agent, sender, head)
|
|
30
|
+
require db(".lampson/teams.db")
|
|
31
|
+
require time
|
|
32
|
+
require random
|
|
33
|
+
require file(".lampson")
|
|
34
|
+
require file(".lampson/*")
|
|
35
|
+
require file.read("workspace")
|
|
36
|
+
require file.read("workspace/*")
|
|
37
|
+
require file.read("agents")
|
|
38
|
+
require file.read("agents/*")
|
|
39
|
+
let spec be runtime.get(agent)
|
|
40
|
+
when spec == nothing
|
|
41
|
+
teams.log("team:" + team["id"], "lampson", "error", "", "no agent file for '" + agent + "' — create .lampson/agents/" + agent + ".agent.json")
|
|
42
|
+
give false
|
|
43
|
+
let sobre be {"to": agent, "thread": "team:" + team["id"], "session": "", "from": sender, "text": teams.turn_text(team, agent, head), "images": [], "channel": "team", "meta": {"team": team["id"], "from": sender}}
|
|
44
|
+
mailbox.submit(sobre, {"mode": when spec["permission"] != "" then "" otherwise "strict", "buffer": mailbox.buffer_of(spec, false)})
|
|
45
|
+
give true
|
|
46
|
+
|
|
47
|
+
-- un turno del objetivo `o` en su conversación (thread objective:<id>)
|
|
48
|
+
export task deliver_objective(o)
|
|
49
|
+
require db(".lampson/teams.db")
|
|
50
|
+
require time
|
|
51
|
+
require random
|
|
52
|
+
require file(".lampson")
|
|
53
|
+
require file(".lampson/*")
|
|
54
|
+
require file.read("workspace")
|
|
55
|
+
require file.read("workspace/*")
|
|
56
|
+
require file.read("agents")
|
|
57
|
+
require file.read("agents/*")
|
|
58
|
+
let spec be runtime.get(o["agent"])
|
|
59
|
+
when spec == nothing
|
|
60
|
+
teams.obj_set(o["id"], {"status": "failed", "result": "no agent file for '" + o["agent"] + "'"})
|
|
61
|
+
give false
|
|
62
|
+
-- objetivo de equipo: el turno es del líder, en la conversación del equipo (con sus novedades y el tablero del equipo)
|
|
63
|
+
when o["team"] != ""
|
|
64
|
+
let tm be teams.get(o["team"])
|
|
65
|
+
when tm == nothing
|
|
66
|
+
teams.obj_set(o["id"], {"status": "failed", "result": "team '" + o["team"] + "' no longer exists"})
|
|
67
|
+
give false
|
|
68
|
+
let head be teams.obj_head(o)
|
|
69
|
+
teams.obj_set(o["id"], {"last_start": now(), "turns": o["turns"] + 1, "reply": ""})
|
|
70
|
+
give deliver_to(tm, o["agent"], "lampson", head)
|
|
71
|
+
let txt be teams.obj_turn_text(o)
|
|
72
|
+
teams.obj_set(o["id"], {"last_start": now(), "turns": o["turns"] + 1, "reply": ""})
|
|
73
|
+
let sobre be {"to": o["agent"], "thread": "objective:" + text(o["id"]), "session": "", "from": "lampson", "text": txt, "images": [], "channel": "objective", "meta": {"objective": o["id"]}}
|
|
74
|
+
mailbox.submit(sobre, {"mode": when spec["permission"] != "" then "" otherwise "strict", "buffer": mailbox.buffer_of(spec, false)})
|
|
75
|
+
give true
|
|
76
|
+
|
|
77
|
+
-- ¿le toca un turno? activo, el anterior terminó y pasaron round_seconds (el primero, enseguida; una respuesta de la
|
|
78
|
+
-- persona, enseguida también)
|
|
79
|
+
export task objective_due(o)
|
|
80
|
+
require db(".lampson/teams.db")
|
|
81
|
+
require file(".lampson")
|
|
82
|
+
require file(".lampson/*")
|
|
83
|
+
require time
|
|
84
|
+
when o["status"] != "active"
|
|
85
|
+
give false
|
|
86
|
+
when o["turns"] == 0
|
|
87
|
+
give true
|
|
88
|
+
-- el turno anterior sigue (o murió sin cerrar: a los 15 min se da por perdido y se sigue)
|
|
89
|
+
when o["last_end"] < o["last_start"] and now() - o["last_start"] < 900
|
|
90
|
+
give false
|
|
91
|
+
when o["reply"] != ""
|
|
92
|
+
give true
|
|
93
|
+
when now() - o["last_end"] < o["round_seconds"]
|
|
94
|
+
give false
|
|
95
|
+
-- en un equipo, el líder solo hace ronda si algo cambió o tiene tareas propias (si no, está esperando a los demás)
|
|
96
|
+
when o["team"] != ""
|
|
97
|
+
give teams.has_work("team:" + o["team"], o["agent"])
|
|
98
|
+
give true
|
|
99
|
+
|
|
100
|
+
export task tick()
|
|
101
|
+
require db(".lampson/teams.db")
|
|
102
|
+
require time
|
|
103
|
+
require random
|
|
104
|
+
require file(".lampson")
|
|
105
|
+
require file(".lampson/*")
|
|
106
|
+
require file.read("workspace")
|
|
107
|
+
require file.read("workspace/*")
|
|
108
|
+
require file.read("agents")
|
|
109
|
+
require file.read("agents/*")
|
|
110
|
+
let n be 0
|
|
111
|
+
each o in teams.obj_list()
|
|
112
|
+
when objective_due(o)
|
|
113
|
+
when deliver_objective(o)
|
|
114
|
+
set n to n + 1
|
|
115
|
+
let teams_now be teams.all()
|
|
116
|
+
when length(teams_now) == 0
|
|
117
|
+
give n
|
|
118
|
+
each m in teams.pending()
|
|
119
|
+
let tid be slice(m["scope"], 5, length(m["scope"]))
|
|
120
|
+
let found be where(teams_now, (t) => t["id"] == tid)
|
|
121
|
+
when length(found) == 0
|
|
122
|
+
teams.mark(m["id"], "dropped")
|
|
123
|
+
otherwise
|
|
124
|
+
let team be found[0]
|
|
125
|
+
when teams.over_budget(team, m["recipient"])
|
|
126
|
+
flag_budget(team, m["recipient"])
|
|
127
|
+
otherwise
|
|
128
|
+
let who be teams.member(team, m["sender"])
|
|
129
|
+
let head be "[message from " + m["sender"] + (when who != nothing then " (" + who["role"] + ")" otherwise "") + "]\n" + m["text"]
|
|
130
|
+
when deliver_to(team, m["recipient"], m["sender"], head)
|
|
131
|
+
teams.mark(m["id"], "delivered")
|
|
132
|
+
set n to n + 1
|
|
133
|
+
otherwise
|
|
134
|
+
teams.mark(m["id"], "failed")
|
|
135
|
+
each team in teams_now
|
|
136
|
+
each mem in team["members"]
|
|
137
|
+
when teams.over_budget(team, mem["agent"])
|
|
138
|
+
flag_budget(team, mem["agent"])
|
|
139
|
+
otherwise when teams.round_due(team, mem["agent"])
|
|
140
|
+
deliver_to(team, mem["agent"], "lampson", ROUND_TEXT)
|
|
141
|
+
set n to n + 1
|
|
142
|
+
give n
|