lampson 0.4.1 → 0.5.1

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.
Files changed (69) hide show
  1. package/README.md +19 -0
  2. package/chat.syn +1 -1
  3. package/hub.tpl.syn +55 -12
  4. package/lampson.ps1 +13 -6
  5. package/lampson.sh +11 -5
  6. package/lib/api.syn +224 -9
  7. package/lib/apikeys.syn +42 -9
  8. package/lib/apptools.syn +549 -0
  9. package/lib/diagnose.syn +142 -0
  10. package/lib/loop.syn +27 -0
  11. package/lib/mailbox.syn +24 -10
  12. package/lib/mcp_server.syn +6 -5
  13. package/lib/permission.syn +22 -1
  14. package/lib/plugins.syn +6 -4
  15. package/lib/provider.syn +16 -13
  16. package/lib/remotetools.syn +76 -0
  17. package/lib/runtime.syn +213 -9
  18. package/lib/schedule.syn +40 -2
  19. package/lib/sdktools.syn +73 -0
  20. package/lib/session.syn +8 -0
  21. package/lib/teamrun.syn +42 -5
  22. package/lib/teams.syn +397 -24
  23. package/lib/tools/common.syn +5 -0
  24. package/lib/tools/url.syn +82 -9
  25. package/lib/workspaces.syn +87 -3
  26. package/lib/worktree.syn +108 -0
  27. package/package.json +2 -2
  28. package/plugins/example-hello/plugin.json +1 -0
  29. package/public/css/chat.css +9 -8
  30. package/public/css/hub.css +69 -16
  31. package/public/css/layout.css +12 -4
  32. package/public/css/login.css +1 -1
  33. package/public/css/mobile.css +2 -2
  34. package/public/css/panel.css +18 -7
  35. package/public/css/sidebar.css +1 -1
  36. package/public/css/teams.css +701 -55
  37. package/public/css/tokens.css +36 -12
  38. package/public/css/views.css +124 -0
  39. package/public/hub.html +17 -9
  40. package/public/index.html +5 -2
  41. package/public/js/app.js +2 -2
  42. package/public/js/approvals.js +1 -1
  43. package/public/js/apptools.js +63 -0
  44. package/public/js/core.js +5 -2
  45. package/public/js/flow.js +187 -0
  46. package/public/js/hub.js +131 -31
  47. package/public/js/navtabs.js +23 -0
  48. package/public/js/objdiag.js +90 -0
  49. package/public/js/objlive.js +393 -0
  50. package/public/js/panel.js +3 -2
  51. package/public/js/plugins-home.js +59 -0
  52. package/public/js/plugins.js +40 -18
  53. package/public/js/schedules.js +5 -0
  54. package/public/js/sidebar.js +6 -4
  55. package/public/js/tasks-home.js +104 -0
  56. package/public/js/teams-home.js +64 -15
  57. package/public/js/teams.js +927 -202
  58. package/public/js/terminal.js +8 -2
  59. package/public/js/workspaces.js +6 -3
  60. package/public/plugins-home.html +32 -0
  61. package/public/tasks-home.html +31 -0
  62. package/public/teams-home.html +5 -2
  63. package/public/teams.html +33 -46
  64. package/public/vendor/xterm-addon-webgl.js +2 -0
  65. package/run.syn +87 -6
  66. package/sdk/index.d.ts +64 -3
  67. package/sdk/index.js +253 -11
  68. package/skills/lampson/SKILL.md +15 -0
  69. package/web.syn +91 -12
@@ -115,6 +115,21 @@ the terminal button and run `npm run dev`), then tell me the URL".
115
115
  - Save what you would otherwise rediscover: how to run/test, env quirks, decisions, where things live,
116
116
  root causes of bugs. Update notes instead of contradicting them. The user can read and edit them.
117
117
 
118
+ ## App tools (`.lampson/tools/*.syn`) — when the user asks you to write one
119
+ - One file per tool in `workspace/.lampson/tools/<name>.syn`: an `intent: "…"` line (the description the model
120
+ sees), its `require` lines AT THE TOP (all it can touch: `net("api.x.com")`, `env("STRIPE_KEY")`…) and
121
+ `export task <name>(…)` with the file's name. A default makes a parameter optional. Helpers start with `_`.
122
+ - `env(…)` only with exact names; `LAMPSON_*` is Lampson's, except `env("LAMPSON_CTX")`, which gives the trusted
123
+ context (`from`, `thread`, `meta`…) that the app set — use it to decide what each customer may see, never trust
124
+ an id the model wrote in the arguments.
125
+ - Writing anywhere under `.lampson/` asks the user (in `strict` it is denied). And a tool only runs once the
126
+ USER approved that exact content (`lampson tools approve` or *herramientas* in the web header): after you
127
+ write or change one, tell them to review and approve it — any unapproved `.syn` in the folder stops all of
128
+ them. Never try to approve it yourself or touch `apptools_approved.json`.
129
+ - No links to other folders inside it; limits: 1 MB per file, 5 MB in total, 500 `.syn`.
130
+ - Test it with `synsema test .lampson/tools/<name>.syn` (its `test` blocks). Paths ending in `.` or a space,
131
+ with `~` + digit, or with `:` are rejected by the file tools (Windows aliases): use the plain name.
132
+
118
133
  ## Sessions and memory
119
134
  - The whole history — including every tool result, error and DENIED message — is persisted in
120
135
  `.lampson/sessions/<id>.json` and resent to you each turn, so you know exactly what happened.
package/web.syn CHANGED
@@ -30,6 +30,8 @@ require random
30
30
  require env("LAMPSON_*")
31
31
  require env("OS")
32
32
  require secret("LAMPSON_*")
33
+ -- firmar los pedidos a las funciones de la app en modo servidor (lib/remotetools.syn, http_sign RFC 9421)
34
+ require sign("LAMPSON_TOOLS")
33
35
  require db(".lampson/teams.db")
34
36
  require judge
35
37
  require file("workspace")
@@ -61,6 +63,7 @@ use "./lib/settings.syn" as settings
61
63
  use "./lib/trace.syn" as trace
62
64
  use "./lib/mcp.syn" as mcp
63
65
  use "./lib/plugins.syn" as plugins
66
+ use "./lib/apptools.syn" as apptools
64
67
  use "./lib/lsp.syn" as lsp
65
68
  use "./lib/tools/todo.syn" as todo
66
69
  use "./lib/schedule.syn" as schedule
@@ -152,6 +155,13 @@ mcp.start_all(8)
152
155
  share {"id": text(now())} as "lampson:run"
153
156
  share {"kind": "web"} as "lampson:ui"
154
157
 
158
+ -- la pantalla de equipos (public/teams.html) en cualquiera de sus rutas; abierta por el puerto de este proceso, al hub
159
+ task teams_page(request, slug, rest)
160
+ let h be headers of request
161
+ when env("LAMPSON_WS", "") != "" and not contains(h, "x-forwarded-host")
162
+ give redirect("http://127.0.0.1:8080/w/" + slug + rest)
163
+ give html(read_file("public/teams.html"))
164
+
155
165
  serve on 8080
156
166
  -- el proxy del hub (y nada más) conecta por loopback: sus X-Forwarded-* traen la origin real (check_client).
157
167
  -- Acá y no como flag de start_ws: el web.syn se copia al arrancar, y un hub viejo en memoria lo lanzaba sin el
@@ -164,7 +174,7 @@ serve on 8080
164
174
  describe
165
175
  about: "Lampson API — agents of this workspace for your apps, channels and other agents"
166
176
  version: "1.0.0"
167
- api: ["POST /w/:slug/v1/messages -- send a message to an agent and get its answer (JSON); with \"callback\", 202 now and the answer POSTed later. Body: {to, thread, text, images?, from?, meta?, sent_at?, session?, callback?}", "POST /w/:slug/v1/messages/stream -- the same, as Server-Sent Events: session, the agent's steps, done", "GET /w/:slug/v1/agents -- the agents this API key can use", "GET /w/:slug/v1/jobs/:id -- status and result of a message sent with a callback", "POST /w/:slug/v1/mcp -- Model Context Protocol (Streamable HTTP, JSON responses): tools ask, agents and history, for other AI agents", "POST /w/:slug/v1/mcp/stream -- the same MCP server answering with Server-Sent Events: with params._meta.progressToken, each step of the agent arrives as notifications/progress before the result", "GET /w/:slug/v1/mcp -- 405: this MCP server opens no server-to-client stream", "POST /w/:slug/v1/objectives -- give an agent (or a team) an objective to work on by itself until done; it plans on a board, works in rounds and asks before anything irreversible. Body: {text, agent? | team?, budget_tokens?, round_seconds?}", "GET /w/:slug/v1/objectives -- the objectives this API key can see", "GET /w/:slug/v1/objectives/:id -- one objective: status, last report, question or approval it waits for, result, board and record", "POST /w/:slug/v1/objectives/:id/reply -- answer its question, or approve/deny what it asked: {text?, approved?}", "POST /w/:slug/v1/objectives/:id/cancel -- stop it"]
177
+ api: ["POST /w/:slug/v1/messages -- send a message to an agent and get its answer (JSON); with \"callback\", 202 now and the answer POSTed later. Body: {to, thread, text, images?, from?, meta?, sent_at?, session?, callback?, tools?, tools_url?} — tools: your app's functions [{name, description, parameters, timeout?}], called with a signed POST to tools_url", "POST /w/:slug/v1/messages/stream -- the same, as Server-Sent Events: session, the agent's steps, done", "GET /w/:slug/v1/agents -- the agents this API key can use", "GET /w/:slug/v1/jobs/:id -- status and result of a message sent with a callback", "POST /w/:slug/v1/mcp -- Model Context Protocol (Streamable HTTP, JSON responses): tools ask, agents and history, for other AI agents", "POST /w/:slug/v1/mcp/stream -- the same MCP server answering with Server-Sent Events: with params._meta.progressToken, each step of the agent arrives as notifications/progress before the result", "GET /w/:slug/v1/mcp -- 405: this MCP server opens no server-to-client stream", "POST /w/:slug/v1/objectives -- give an agent (or a team) an objective to work on by itself until done; it plans on a board, works in rounds and asks before anything irreversible. Body: {text, agent? | team?, budget_tokens?, round_seconds?}", "GET /w/:slug/v1/objectives -- the objectives this API key can see", "GET /w/:slug/v1/objectives/:id -- one objective: status, last report, question or approval it waits for, result, board and record", "POST /w/:slug/v1/objectives/:id/reply -- answer its question, or approve/deny what it asked: {text?, approved?}", "POST /w/:slug/v1/objectives/:id/cancel -- stop it"]
168
178
 
169
179
  -- la UI vive bajo /w/<slug> (BASE en js/core.js); si alguien entra por el puerto del proceso, es lo mismo
170
180
  -- Acceso DIRECTO por el puerto del proceso (sin X-Forwarded-Host, que solo agrega el hub al proxyear): la UI se
@@ -436,6 +446,29 @@ serve on 8080
436
446
  recover err
437
447
  give fail(400, text(err))
438
448
 
449
+ -- herramientas .syn del proyecto (lib/apptools.syn): ver cada archivo, su código y su techo, y aprobarlo. Solo la
450
+ -- persona: el agente no tiene ninguna tool que llegue acá
451
+ route "GET /w/:slug/api/apptools" requires auth
452
+ private
453
+ give apptools.summary()
454
+
455
+ route "GET /w/:slug/api/apptools/source" requires auth
456
+ private
457
+ let f be when contains(query, "file") then text(query.file) otherwise ""
458
+ try
459
+ give {"file": f, "text": apptools.source(f)}
460
+ recover err
461
+ give fail(400, text(err))
462
+
463
+ route "POST /w/:slug/api/apptools/approve" requires auth
464
+ private
465
+ let b be json of request
466
+ let n be when contains(b, "name") then text(b["name"]) otherwise ""
467
+ try
468
+ give {"ok": true, "approved": apptools.approve(n), "summary": apptools.summary()}
469
+ recover err
470
+ give fail(400, text(err))
471
+
439
472
  route "POST /w/:slug/api/plugins/toggle" requires auth
440
473
  private
441
474
  expect body {name: text}
@@ -458,7 +491,7 @@ serve on 8080
458
491
  private
459
492
  stream
460
493
  state_set("lampson:last_used", now())
461
- let sub be bus_subscribe(["proc.*", "subagent.*", "mcp.*", "approval.*", "schedule.*"], {"max_queue": 512})
494
+ let sub be bus_subscribe(["proc.*", "subagent.*", "mcp.*", "approval.*", "schedule.*", "team.*"], {"max_queue": 512})
462
495
  let open be true
463
496
  while open
464
497
  let ev be bus_recv(sub, 25)
@@ -615,7 +648,7 @@ serve on 8080
615
648
 
616
649
  route "GET /w/:slug/api/approvals" requires auth
617
650
  private
618
- give {"approvals": approvals.list(), "public_url": approvals.public_url(), "webhook": approvals.webhook_url() != ""}
651
+ give {"approvals": api.approvals_view(approvals.list()), "public_url": approvals.public_url(), "webhook": approvals.webhook_url() != ""}
619
652
 
620
653
  -- link de decisión (PÚBLICO a propósito: lo abre el humano desde el teléfono; el token de un solo uso es la
621
654
  -- autorización, como en el `approve` nativo de Synsema bajo serve). GET porque un link en un chat es un GET.
@@ -834,7 +867,7 @@ serve on 8080
834
867
  let offered be apply((x) => x["id"], api.agents_for(a["key"]))
835
868
  when length(offered) == 0
836
869
  give fail(403, "this API key has no agents")
837
- let resp be mcp_server.handle(json of request, offered, api.mcp_deliver)
870
+ let resp be mcp_server.handle(json of request, offered, api.mcp_deliver, api.space_of(a["key"]))
838
871
  when resp == nothing
839
872
  give respond("", "application/json", 202)
840
873
  give resp
@@ -875,14 +908,14 @@ serve on 8080
875
908
  set result to r
876
909
  state_delete("mb:res:" + mid)
877
910
  bus_unsubscribe(sub)
878
- give when result == nothing then {"agent": sobre["to"], "thread": sobre["thread"], "session": "", "text": "", "steps": 0, "usage": {"input": 0, "output": 0, "cached": 0}, "stopped": "error: timed out"} otherwise result
911
+ give when result == nothing then {"agent": sobre["to"], "thread": get(sobre, "shown_thread", sobre["thread"]), "session": "", "text": "", "steps": 0, "usage": {"input": 0, "output": 0, "cached": 0}, "stopped": "error: timed out"} otherwise result
879
912
  when not a["ok"]
880
913
  send {"jsonrpc": "2.0", "id": nothing, "error": {"code": -32001, "message": a["error"]}} as "message"
881
914
  otherwise when length(offered) == 0
882
915
  send {"jsonrpc": "2.0", "id": nothing, "error": {"code": -32001, "message": "this API key has no agents"}} as "message"
883
916
  otherwise
884
917
  state_set("lampson:last_used", now())
885
- let resp be mcp_server.handle(req, offered, deliver_sse)
918
+ let resp be mcp_server.handle(req, offered, deliver_sse, api.space_of(a["key"]))
886
919
  when resp != nothing
887
920
  send resp as "message"
888
921
 
@@ -893,15 +926,18 @@ serve on 8080
893
926
  -- ---------- EQUIPOS Y OBJETIVOS: su pantalla propia (public/teams.html) y la API privada que la alimenta ----------
894
927
  route "GET /w/:slug/equipos"
895
928
  private
896
- let h be headers of request
897
- when env("LAMPSON_WS", "") != "" and not contains(h, "x-forwarded-host")
898
- give redirect("http://127.0.0.1:8080/w/" + params.slug + "/equipos")
899
- give html(read_file("public/teams.html"))
929
+ give teams_page(request, params.slug, "/equipos")
930
+ route "GET /w/:slug/equipos/*rest"
931
+ private
932
+ give teams_page(request, params.slug, "/equipos/" + params.rest)
933
+ route "GET /w/:slug/objetivos/*rest"
934
+ private
935
+ give teams_page(request, params.slug, "/objetivos/" + params.rest)
900
936
 
901
937
  route "GET /w/:slug/api/objectives" requires auth
902
938
  private
903
- let rows be apply(teams.obj_list(), (o) => {"id": o["id"], "ref": "O-" + text(o["id"]), "agent": o["agent"], "team": o["team"], "text": o["text"], "status": o["status"], "progress": o["progress"], "question": o["question"], "question_kind": o["question_kind"], "turns": o["turns"], "spent": o["spent"], "budget_tokens": o["budget_tokens"], "updated_at": o["updated_at"], "working": mailbox.working(o["agent"], teams.obj_scope(o))})
904
- give {"objectives": rows, "teams": apply(teams.all(), (t) => {"id": t["id"], "lead": teams.lead_of(t), "description": t["description"]}), "agents": apply(where(runtime.names(), (n) => not runtime.get(n)["builtin"]), (n) => {"id": n, "description": runtime.get(n)["description"]})}
939
+ let rows be apply(teams.obj_list(), (o) => {"id": o["id"], "ref": "O-" + text(o["id"]), "agent": o["agent"], "team": o["team"], "text": o["text"], "status": o["status"], "progress": o["progress"], "question": o["question"], "question_kind": o["question_kind"], "turns": o["turns"], "spent": o["spent"], "budget_tokens": o["budget_tokens"], "updated_at": o["updated_at"], "created_at": o["created_at"], "created_by": o["created_by"], "from_obj": o["from_obj"], "pass_pending": o["pass_pending"] != "", "working": mailbox.working(o["agent"], teams.obj_scope(o))})
940
+ give {"objectives": rows, "teams": apply(teams.all(), (t) => {"id": t["id"], "name": t["name"], "lead": teams.lead_of(t), "description": t["description"]}), "agents": apply(where(runtime.names(), (n) => not runtime.get(n)["builtin"]), (n) => {"id": n, "description": runtime.get(n)["description"]})}
905
941
 
906
942
  route "GET /w/:slug/api/objectives/:id" requires auth
907
943
  private
@@ -928,6 +964,33 @@ serve on 8080
928
964
  recover err
929
965
  give fail(409, regex_replace(text(err), "^.*?:\\d+:\\d+: ", ""))
930
966
 
967
+ route "GET /w/:slug/api/objectives/:id/facts" requires auth
968
+ private
969
+ let o be teams.obj_get(floor(number(params.id)))
970
+ when o == nothing
971
+ give fail(404, "no such objective")
972
+ give {"facts": api.obj_facts(o)}
973
+
974
+ route "POST /w/:slug/api/objectives/:id/diagnose" requires auth
975
+ private
976
+ let o be teams.obj_get(floor(number(params.id)))
977
+ when o == nothing
978
+ give fail(404, "no such objective")
979
+ let r be api.obj_analyze(o)
980
+ when not r["ok"]
981
+ give fail(502, r["error"])
982
+ give r
983
+
984
+ route "POST /w/:slug/api/objectives/:id/act" requires auth
985
+ private
986
+ let o be teams.obj_get(floor(number(params.id)))
987
+ when o == nothing
988
+ give fail(404, "no such objective")
989
+ let r be api.obj_act(o, json of request)
990
+ when not r["ok"]
991
+ give fail(400, r["error"])
992
+ give r
993
+
931
994
  route "POST /w/:slug/api/objectives/:id/cancel" requires auth
932
995
  private
933
996
  give api.objective_view(teams.obj_cancel(floor(number(params.id)), "person"))
@@ -943,6 +1006,22 @@ serve on 8080
943
1006
  give fail(400, r["error"])
944
1007
  give api.teams_view()
945
1008
 
1009
+ route "POST /w/:slug/api/teams/seat-tokens" requires auth
1010
+ private
1011
+ expect body {agent: text}
1012
+ let r be api.seat_tokens(json of request)
1013
+ when not r["ok"]
1014
+ give fail(400, r["error"])
1015
+ give r
1016
+
1017
+ route "POST /w/:slug/api/teams/delete" requires auth
1018
+ private
1019
+ expect body {id: text}
1020
+ let r be api.delete_team(json of request)
1021
+ when not r["ok"]
1022
+ give fail(400, r["error"])
1023
+ give r
1024
+
946
1025
  route "GET /w/:slug/api/keys" requires auth
947
1026
  private
948
1027
  let pub be approvals.public_url()