lampson 0.3.0 → 0.4.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.
@@ -361,9 +361,11 @@ task hub_routes(w)
361
361
  each m in ["GET", "POST"]
362
362
  set lines to append(lines, " route \"" + m + " /w/" + w["slug"] + "/api/*path\" requires auth\n proxy to \"" + base + "\"")
363
363
  set lines to append(lines, " route \"GET /w/" + w["slug"] + "/approve/*path\"\n proxy to \"" + base + "\"")
364
- -- la API /v1 para apps (lib/api.syn) tampoco: la autentica el proceso del workspace con su API key (Bearer lk_…)
364
+ -- la API /v1 para apps (lib/api.syn) tampoco: la autentica el proceso del workspace con su API key (Bearer lk_…).
365
+ -- POST /v1/messages espera al agente (buzón + turno con tools): sin `timeout` el proxy corta a los 30 s con 504
366
+ -- (visto 2026-10-16 con una ráfaga real); 600 s, como el bash más largo
365
367
  each m in ["GET", "POST"]
366
- set lines to append(lines, " route \"" + m + " /w/" + w["slug"] + "/v1/*path\"\n proxy to \"" + base + "\"")
368
+ set lines to append(lines, " route \"" + m + " /w/" + w["slug"] + "/v1/*path\"\n timeout 600\n proxy to \"" + base + "\"")
367
369
  -- los webhooks de los canales (lib/channels.syn) tampoco: la firma de la plataforma la verifica el plugin
368
370
  each m in ["GET", "POST"]
369
371
  set lines to append(lines, " route \"" + m + " /w/" + w["slug"] + "/ch/*path\"\n proxy to \"" + base + "\"")
@@ -744,6 +746,17 @@ export task should_live(w, hc)
744
746
  -- que el próximo mensaje encuentre un 502 en el hub
745
747
  when api_keys_on_disk(w) > 0
746
748
  give true
749
+ -- con un canal encendido (lib/channels.syn) también: en modo poll se caería el poller, y en modo webhook la
750
+ -- plataforma recibiría un 502 del hub (que no enciende workspaces por un webhook)
751
+ when channels_on_disk(w) > 0
752
+ give true
753
+ -- con un equipo que hace rondas (lib/teams.syn: round_minutes > 0): las rondas corren en el proceso del workspace
754
+ when teams_on_disk(w) > 0
755
+ give true
756
+ -- un objetivo trabajando (o esperando a la persona): apagarlo lo dejaría a mitad de camino
757
+ let tsum be teams_summary(w)
758
+ when tsum["active"] > 0 or tsum["waiting"] > 0
759
+ give true
747
760
  let ih be idle_hours()
748
761
  when ih == 0
749
762
  give true
@@ -751,6 +764,62 @@ export task should_live(w, hc)
751
764
  give now() - last < ih * 3600
752
765
 
753
766
  -- tareas encendidas según el json del workspace (sirve aunque el proceso esté apagado)
767
+ -- canales encendidos en el workspace: plugins encendidos (.lampson/plugins.json del ws) cuyo plugin.json declara
768
+ -- "channel" — globales (plugins/ de la instalación, leídos por el link del ws) o del proyecto (.lampson/plugins/)
769
+ export task channels_on_disk(w)
770
+ let n be 0
771
+ try
772
+ let st be json_decode(read_file(dir_of(w["slug"]) + "/.lampson/plugins.json"))
773
+ let on be when contains(st, "enabled") then st["enabled"] otherwise {}
774
+ each name in keys(on)
775
+ when on[name] == true
776
+ let found be false
777
+ each f in [dir_of(w["slug"]) + "/plugins/" + name + "/plugin.json", dir_of(w["slug"]) + "/workspace/.lampson/plugins/" + name + "/plugin.json"]
778
+ when not found
779
+ try
780
+ when contains(read_file(f), "\"channel\"")
781
+ set found to true
782
+ recover err
783
+ set found to found
784
+ when found
785
+ set n to n + 1
786
+ recover err
787
+ give 0
788
+ give n
789
+
790
+ -- el resumen de equipos y objetivos que escribe el workspace (lib/teamrun.syn) — lo que el hub muestra sin abrir su base
791
+ export task teams_summary(w)
792
+ try
793
+ give json_decode(read_file(dir_of(w["slug"]) + "/.lampson/teams-summary.json"))
794
+ recover err
795
+ give {"teams": [], "objectives": [], "approvals": [], "active": 0, "waiting": 0}
796
+
797
+ -- /w/<nombre> sin el hash: el slug completo si un solo workspace se llama así (si no, nothing)
798
+ export task resolve_slug(name)
799
+ require file(".lampson")
800
+ require file(".lampson/*")
801
+ when get(name) != nothing
802
+ give name
803
+ let hits be where(all(), (w) => starts_with(w["slug"], lower(name) + "-") and length(w["slug"]) == length(name) + 9)
804
+ give when length(hits) == 1 then hits[0]["slug"] otherwise nothing
805
+
806
+ -- equipos con rondas en el proyecto (leídos por el link workspace/ del ws: el hub no tiene permiso sobre el proyecto)
807
+ export task teams_on_disk(w)
808
+ let n be 0
809
+ try
810
+ let d be dir_of(w["slug"]) + "/workspace/.lampson/teams"
811
+ each e in list_dir(d)
812
+ when ends_with(e["name"], ".team.json")
813
+ try
814
+ let t be json_decode(read_file(d + "/" + e["name"]))
815
+ when contains(t, "round_minutes") and t["round_minutes"] != nothing and number(t["round_minutes"]) > 0
816
+ set n to n + 1
817
+ recover err
818
+ set n to n
819
+ recover err
820
+ give 0
821
+ give n
822
+
754
823
  task api_keys_on_disk(w)
755
824
  try
756
825
  give length(json_decode(read_file(dir_of(w["slug"]) + "/.lampson/api_keys.json"))["keys"])
@@ -797,6 +866,11 @@ export task tick()
797
866
  give {"started": started, "stopped": stopped}
798
867
 
799
868
  -- resumen para la UI del hub
869
+ -- contadores para la tarjeta del inicio: equipos, objetivos trabajando, lo que espera a la persona
870
+ task team_counts(w)
871
+ let s be teams_summary(w)
872
+ give {"teams": length(s["teams"]), "active": s["active"], "waiting": s["waiting"]}
873
+
800
874
  export task summary()
801
875
  require exec
802
876
  require time
@@ -811,7 +885,7 @@ export task summary()
811
885
  each e in enumerate(list)
812
886
  let w be e["item"]
813
887
  let hc be hcs[e["index"]]
814
- set out to append(out, {"slug": w["slug"], "name": w["name"], "path": w["path"], "port": w["port"], "policy": when contains(w, "policy") then w["policy"] otherwise "auto", "created": w["created"], "last_used": when hc != nothing and contains(hc, "last_used") and hc["last_used"] != nothing then hc["last_used"] otherwise w["last_used"], "alive": hc != nothing, "paused": contains(w, "paused") and w["paused"] == true, "schedules_on": when hc != nothing and contains(hc, "schedules_on") then hc["schedules_on"] otherwise schedules_on_disk(w), "url": "/w/" + w["slug"]})
888
+ set out to append(out, {"slug": w["slug"], "name": w["name"], "path": w["path"], "port": w["port"], "policy": when contains(w, "policy") then w["policy"] otherwise "auto", "created": w["created"], "last_used": when hc != nothing and contains(hc, "last_used") and hc["last_used"] != nothing then hc["last_used"] otherwise w["last_used"], "alive": hc != nothing, "paused": contains(w, "paused") and w["paused"] == true, "schedules_on": when hc != nothing and contains(hc, "schedules_on") then hc["schedules_on"] otherwise schedules_on_disk(w), "url": "/w/" + w["slug"], "teams": team_counts(w)})
815
889
  share out as "hub:summary"
816
890
  share now() as "hub:summary_at"
817
891
  give out
@@ -0,0 +1,105 @@
1
+ -- lib/worktree.syn — la copia de trabajo de cada agente de un equipo (git worktree)
2
+ --
3
+ -- En un proyecto con git, cada miembro de un equipo trabaja en SU copia: workspace/.lampson/worktrees/<agente>, en
4
+ -- su rama team/<equipo>/<agente> (sale de la rama actual del proyecto), con SU nombre de autor (config de git por
5
+ -- worktree: extensions.worktreeConfig). Así dos agentes no se pisan archivos ni ramas, y el registro de git dice
6
+ -- quién hizo cada commit. La copia principal (la de la persona, con main) no se toca.
7
+ -- * .lampson/ queda en .git/info/exclude (exclusión local: no cambia ningún archivo del repo)
8
+ -- * lib/loop.syn traduce: las tools de archivos y bash del agente operan en su copia; para él es la raíz
9
+ -- * un merge/push que sale de su copia (toca la historia compartida) pide aprobación a la persona (lib/loop.syn)
10
+ use "./tools/common.syn" as c
11
+
12
+ export let DIR be ".lampson/worktrees"
13
+ let G be "git"
14
+
15
+ task git(args, cwd)
16
+ require exec
17
+ require time
18
+ require file("workspace")
19
+ require file("workspace/*")
20
+ try
21
+ let r be run(G, args, 30, {"cwd": cwd})
22
+ give {"ok": r["exit_code"] == 0, "out": trim(r["stdout"] + "\n" + r["stderr"])}
23
+ recover err
24
+ give {"ok": false, "out": text(err)}
25
+
26
+ -- ¿el proyecto es un repo de git (con al menos un commit)?
27
+ export task is_repo()
28
+ require exec
29
+ require time
30
+ require file("workspace")
31
+ require file("workspace/*")
32
+ give git(["rev-parse", "--verify", "HEAD"], c.ROOT)["ok"]
33
+
34
+ -- la copia de `agent` (la crea si falta). → {ok, root, branch, error}; root es relativa al workspace
35
+ export task ensure(team_id, agent, author)
36
+ require exec
37
+ require time
38
+ require file("workspace")
39
+ require file("workspace/*")
40
+ let rel be DIR + "/" + agent
41
+ let branch be "team/" + team_id + "/" + agent
42
+ when not is_repo()
43
+ give {"ok": false, "root": "", "branch": "", "error": "not a git repository (or no commits yet)"}
44
+ when not file_exists(c.ROOT + "/" + rel + "/.git")
45
+ -- .lampson/ fuera de git sin tocar el .gitignore del repo
46
+ let ex be c.ROOT + "/.git/info/exclude"
47
+ let cur be ""
48
+ try
49
+ set cur to read_file(ex)
50
+ recover err
51
+ set cur to ""
52
+ when not contains(cur, "/.lampson/")
53
+ write_file(ex, cur + (when cur == "" or ends_with(cur, "\n") then "" otherwise "\n") + "/.lampson/\n")
54
+ let exists be git(["rev-parse", "--verify", "refs/heads/" + branch], c.ROOT)["ok"]
55
+ let add be git(when exists then ["worktree", "add", rel, branch] otherwise ["worktree", "add", "-b", branch, rel], c.ROOT)
56
+ when not add["ok"]
57
+ give {"ok": false, "root": "", "branch": branch, "error": "git worktree add failed: " + add["out"]}
58
+ -- autor del agente, solo en su copia
59
+ git(["config", "extensions.worktreeConfig", "true"], c.ROOT)
60
+ git(["config", "--worktree", "user.name", author["name"]], c.ROOT + "/" + rel)
61
+ git(["config", "--worktree", "user.email", author["email"]], c.ROOT + "/" + rel)
62
+ give {"ok": true, "root": rel, "branch": branch, "error": ""}
63
+
64
+ -- la rama principal del proyecto (la de la copia de la persona)
65
+ export task main_branch()
66
+ require exec
67
+ require time
68
+ require file("workspace")
69
+ require file("workspace/*")
70
+ let r be git(["rev-parse", "--abbrev-ref", "HEAD"], c.ROOT)
71
+ give when r["ok"] then r["out"] otherwise "main"
72
+
73
+ -- las tools que operan en la copia del agente, y cómo se traducen sus args
74
+ export let FILE_TOOLS be ["read", "write", "edit", "ls", "find", "grep"]
75
+
76
+ export task rooted(name, args, root)
77
+ let a be args
78
+ when name == "bash"
79
+ set a["command"] to "cd \"" + root + "\" && " + text(args["command"])
80
+ give a
81
+ let p be when contains(args, "path") and args["path"] != nothing then replace(text(args["path"]), "\\", "/") otherwise "."
82
+ while starts_with(p, "./")
83
+ set p to slice(p, 2, length(p))
84
+ when p == "." or p == ""
85
+ set a["path"] to root
86
+ otherwise when starts_with(p, root + "/") or p == root or starts_with(p, ".lampson/spill/")
87
+ set a["path"] to p
88
+ otherwise
89
+ set a["path"] to root + "/" + p
90
+ give a
91
+
92
+ -- ¿este comando toca la historia compartida desde una copia de agente? push siempre; merge/rebase/update-ref/branch -f
93
+ -- cuando sale de su copia (-C, cd o ../): adentro de su copia puede traer main a su rama sin pedir nada
94
+ export task touches_shared(command)
95
+ let cmd be " " + lower(replace(text(command), "\n", " ")) + " "
96
+ when not contains(cmd, "git")
97
+ give ""
98
+ when matches(cmd, ".*\\bgit\\b.*\\bpush\\b.*")
99
+ give "git push"
100
+ let leaves be contains(cmd, " -c ") or contains(cmd, "../") or contains(cmd, "..\\") or matches(cmd, ".*\\bcd\\b.*")
101
+ when leaves and matches(cmd, ".*\\bgit\\b.*\\b(merge|rebase|update-ref|cherry-pick|reset)\\b.*")
102
+ give "git merge/rebase/reset outside your working copy"
103
+ when matches(cmd, ".*\\bgit\\b.*\\bbranch\\b.*\\s-(f|d|D)\\b.*") or matches(cmd, ".*\\bgit\\b.*\\bupdate-ref\\b.*")
104
+ give "git branch -f/-d or update-ref"
105
+ give ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lampson",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "A coding agent written in Synsema: terminal + web, tools confined to the mounted project, plugins (your own tools, any language), LSP, MCP, sub-agents. Also an SDK: import { Lampson } from \"lampson\" (server or local mode).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,16 @@
1
+ You can take orders with the `plugin_orders_*` tools. They work the same whether a customer is chatting with you or a system sends you the order.
2
+
3
+ Rules that always apply:
4
+ - Product, price, stock, delivery, hours and payment facts come from `catalog`. What is not there, you don't know. A product with stock 0 is not available: its notes say when it comes back.
5
+ - Every total comes from `quote` (promos, packs and delivery fee applied) — never add up yourself, never invent discounts or order numbers.
6
+ - An order needs: items with quantities, delivery or pickup, the address for delivery (street, number, apartment, a reference), the customer's name, and a payment method from the catalog.
7
+ - `place_order` saves the order and lowers the stock: call it once per order, only when the data is complete and confirmed. If it answers with an error (no stock, missing data), fix the cause — don't retry the same call.
8
+ - A placed order can be changed (`update_order`: add or remove items, delivery, address, payment, time) or cancelled (`cancel_order`) while its status is "new". Change the existing order instead of placing a second one; confirm the new total (from `quote`) before `update_order`, and the cancellation before `cancel_order`. If the store already started it, the tool says so: tell the customer to contact the store.
9
+
10
+ When a customer is chatting with you (they write from their phone, keep each message short):
11
+ 1. Help them choose; if the store is closed now, say when it opens and that you can still take the order for later. Several messages in a row are one message: answer them together.
12
+ 2. Ask only for what is missing, one or two things per message. With a phone number, `find_customer` may already have their address: confirm it instead of asking again.
13
+ 3. Send a short summary (items, delivery or pickup, address, payment, total from `quote`) and ask for confirmation. Place the order ONLY after a clear yes.
14
+ 4. Then give the order number, the total and when it arrives (the catalog's delivery time) or when to pick it up.
15
+
16
+ When a system sends you a complete order (an API call, a script, another agent — nobody to ask): check it with `quote`, place it, and answer with the order number and total; if something is missing or out of stock, answer with exactly what and don't place it.
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "orders",
3
+ "description": "Take orders by chat: catalog, quotes with promos and delivery, orders saved with customer and address (and changed or cancelled while still new), stock kept up to date. Data in .lampson/orders/ of the project.",
4
+ "kind": "syn",
5
+ "entry": "plugin.syn",
6
+ "caps": "file=workspace/.lampson/orders,file=workspace/.lampson/orders/*",
7
+ "timeout": 20,
8
+ "instructions": "INSTRUCTIONS.md",
9
+ "tools": [
10
+ {
11
+ "name": "catalog",
12
+ "description": "The store's catalog: products (sku, name, price, unit, stock, notes, promos), hours, delivery and payment methods. Read it before talking about products, prices, stock, delivery or hours.",
13
+ "parameters": {"type": "object", "properties": {}},
14
+ "readonly": true
15
+ },
16
+ {
17
+ "name": "quote",
18
+ "description": "Prices a cart exactly: lines, promos and packs applied, delivery fee and total, plus any item without enough stock. Use it for every total you tell the customer; never add up yourself.",
19
+ "parameters": {
20
+ "type": "object",
21
+ "properties": {
22
+ "items": {"type": "array", "description": "the cart", "items": {"type": "object", "properties": {"sku": {"type": "string"}, "qty": {"type": "integer", "minimum": 1}}, "required": ["sku", "qty"]}},
23
+ "delivery": {"type": "string", "enum": ["delivery", "pickup"], "description": "delivery to an address, or pickup at the store"}
24
+ },
25
+ "required": ["items"]
26
+ },
27
+ "readonly": true
28
+ },
29
+ {
30
+ "name": "place_order",
31
+ "description": "Places the order once the customer CONFIRMED the summary: saves it with an order number, saves the customer (name, phone, address) and lowers the stock. Prices are computed here again from the catalog.",
32
+ "parameters": {
33
+ "type": "object",
34
+ "properties": {
35
+ "customer": {"type": "object", "properties": {"name": {"type": "string"}, "phone": {"type": "string"}}, "required": ["name"]},
36
+ "items": {"type": "array", "items": {"type": "object", "properties": {"sku": {"type": "string"}, "qty": {"type": "integer", "minimum": 1}}, "required": ["sku", "qty"]}},
37
+ "delivery": {"type": "string", "enum": ["delivery", "pickup"]},
38
+ "address": {"type": "string", "description": "street, number, floor/apartment and any reference — required for delivery"},
39
+ "payment": {"type": "string", "description": "one of the catalog's payment methods"},
40
+ "when": {"type": "string", "description": "when the customer wants it, if they said (e.g. 'today 18 h'); empty = as soon as possible"},
41
+ "notes": {"type": "string", "description": "anything else the store must know"}
42
+ },
43
+ "required": ["customer", "items", "delivery", "payment"]
44
+ }
45
+ },
46
+ {
47
+ "name": "update_order",
48
+ "description": "Changes an order that is still 'new' (the store hasn't started it): the cart, delivery or pickup, address, payment, time or notes. Pass `items` as the WHOLE cart after the change (omit it to keep the cart). Re-prices everything and moves the stock. Only after the customer confirmed the change.",
49
+ "parameters": {
50
+ "type": "object",
51
+ "properties": {
52
+ "order_id": {"type": "string"},
53
+ "items": {"type": "array", "description": "the whole cart after the change", "items": {"type": "object", "properties": {"sku": {"type": "string"}, "qty": {"type": "integer", "minimum": 1}}, "required": ["sku", "qty"]}},
54
+ "delivery": {"type": "string", "enum": ["delivery", "pickup"]},
55
+ "address": {"type": "string"},
56
+ "payment": {"type": "string"},
57
+ "when": {"type": "string"},
58
+ "notes": {"type": "string"}
59
+ },
60
+ "required": ["order_id"]
61
+ }
62
+ },
63
+ {
64
+ "name": "cancel_order",
65
+ "description": "Cancels an order that is still 'new' and puts its stock back. Only after the customer clearly asked to cancel it.",
66
+ "parameters": {"type": "object", "properties": {"order_id": {"type": "string"}, "reason": {"type": "string"}}, "required": ["order_id"]}
67
+ },
68
+ {
69
+ "name": "find_customer",
70
+ "description": "Looks up a returning customer by phone (or by name): saved address and last orders.",
71
+ "parameters": {"type": "object", "properties": {"phone": {"type": "string"}, "name": {"type": "string"}}},
72
+ "readonly": true
73
+ },
74
+ {
75
+ "name": "order_status",
76
+ "description": "An order by its number (e.g. P-0003): items, total, delivery and status.",
77
+ "parameters": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]},
78
+ "readonly": true
79
+ }
80
+ ]
81
+ }