lampson 0.4.1 → 0.5.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.
Files changed (52) hide show
  1. package/README.md +4 -0
  2. package/chat.syn +1 -1
  3. package/hub.tpl.syn +55 -12
  4. package/lib/api.syn +178 -7
  5. package/lib/diagnose.syn +142 -0
  6. package/lib/loop.syn +14 -0
  7. package/lib/plugins.syn +6 -4
  8. package/lib/provider.syn +16 -13
  9. package/lib/runtime.syn +56 -0
  10. package/lib/schedule.syn +40 -2
  11. package/lib/teamrun.syn +42 -5
  12. package/lib/teams.syn +397 -24
  13. package/lib/workspaces.syn +58 -0
  14. package/lib/worktree.syn +108 -0
  15. package/package.json +1 -1
  16. package/plugins/example-hello/plugin.json +1 -0
  17. package/public/css/chat.css +9 -8
  18. package/public/css/hub.css +69 -16
  19. package/public/css/layout.css +12 -4
  20. package/public/css/login.css +1 -1
  21. package/public/css/mobile.css +2 -2
  22. package/public/css/panel.css +16 -7
  23. package/public/css/sidebar.css +1 -1
  24. package/public/css/teams.css +701 -55
  25. package/public/css/tokens.css +36 -12
  26. package/public/css/views.css +124 -0
  27. package/public/hub.html +17 -9
  28. package/public/index.html +3 -2
  29. package/public/js/app.js +2 -2
  30. package/public/js/approvals.js +1 -1
  31. package/public/js/core.js +5 -2
  32. package/public/js/flow.js +187 -0
  33. package/public/js/hub.js +131 -31
  34. package/public/js/navtabs.js +23 -0
  35. package/public/js/objdiag.js +90 -0
  36. package/public/js/objlive.js +393 -0
  37. package/public/js/panel.js +2 -1
  38. package/public/js/plugins-home.js +59 -0
  39. package/public/js/plugins.js +40 -18
  40. package/public/js/schedules.js +5 -0
  41. package/public/js/sidebar.js +6 -4
  42. package/public/js/tasks-home.js +104 -0
  43. package/public/js/teams-home.js +64 -15
  44. package/public/js/teams.js +927 -202
  45. package/public/js/terminal.js +8 -2
  46. package/public/js/workspaces.js +6 -3
  47. package/public/plugins-home.html +32 -0
  48. package/public/tasks-home.html +31 -0
  49. package/public/teams-home.html +5 -2
  50. package/public/teams.html +33 -46
  51. package/public/vendor/xterm-addon-webgl.js +2 -0
  52. package/web.syn +61 -8
package/lib/provider.syn CHANGED
@@ -26,16 +26,18 @@ use "./settings.syn" as settings
26
26
 
27
27
  let ANTHROPIC_VERSION be "2023-06-01"
28
28
 
29
- -- Tabla base URL por proveedor
29
+ -- Tabla base URL por proveedor. Modelos por defecto revisados 2026-10-18 contra la doc de cada uno: el más
30
+ -- nuevo de uso general (no el más caro). deepseek-flash es el alias que DeepSeek mueve a su último Flash
31
+ -- (hoy V4.1-Flash-1017); kimi-k2-* se retiró el 2026-05-25; en Groq gpt-oss-120b es el que mejor usa tools.
30
32
  export let PRESETS be {
31
- "openai": {"wire": "openai", "base_url": "https://api.openai.com/v1", "model": "gpt-4o"},
32
- "deepseek": {"wire": "openai", "base_url": "https://api.deepseek.com/v1", "model": "deepseek-v4-flash"},
33
- "kimi": {"wire": "openai", "base_url": "https://api.moonshot.ai/v1", "model": "kimi-k2-0711-preview"},
34
- "groq": {"wire": "openai", "base_url": "https://api.groq.com/openai/v1", "model": "llama-3.3-70b-versatile"},
35
- "grok": {"wire": "openai", "base_url": "https://api.x.ai/v1", "model": "grok-3"},
36
- "openrouter": {"wire": "openai", "base_url": "https://openrouter.ai/api/v1", "model": "deepseek/deepseek-chat"},
37
- "ollama": {"wire": "openai", "base_url": "http://127.0.0.1:11434/v1", "model": "qwen2.5-coder"},
38
- "anthropic": {"wire": "anthropic", "base_url": "https://api.anthropic.com/v1", "model": "claude-sonnet-4-6"},
33
+ "openai": {"wire": "openai", "base_url": "https://api.openai.com/v1", "model": "gpt-6.1-sol"},
34
+ "deepseek": {"wire": "openai", "base_url": "https://api.deepseek.com/v1", "model": "deepseek-flash"},
35
+ "kimi": {"wire": "openai", "base_url": "https://api.moonshot.ai/v1", "model": "kimi-k3"},
36
+ "groq": {"wire": "openai", "base_url": "https://api.groq.com/openai/v1", "model": "openai/gpt-oss-120b"},
37
+ "grok": {"wire": "openai", "base_url": "https://api.x.ai/v1", "model": "grok-4.7"},
38
+ "openrouter": {"wire": "openai", "base_url": "https://openrouter.ai/api/v1", "model": "deepseek/deepseek-v4.1-flash"},
39
+ "ollama": {"wire": "openai", "base_url": "http://127.0.0.1:11434/v1", "model": "qwen3-coder"},
40
+ "anthropic": {"wire": "anthropic", "base_url": "https://api.anthropic.com/v1", "model": "claude-sonnet-5-5"},
39
41
  "minimax": {"wire": "anthropic", "base_url": "https://api.minimax.io/anthropic/v1", "model": "MiniMax-M3"},
40
42
  -- Z.ai (Zhipu), API compatible con OpenAI, dos presets con la MISMA key (es la misma cuenta):
41
43
  -- `glm` = pago por uso (saldo prepago); `glm-coding` = GLM Coding Plan (suscripción), que solo vale
@@ -284,12 +286,13 @@ export task supports_vision(cfg)
284
286
  give true
285
287
  when p == "groq"
286
288
  give contains(m, "llama-4") or contains(m, "vision")
289
+ -- DeepSeek V4.1-Flash (2026-09-10) es multimodal nativo; deepseek-v4-flash quedó como alias que va a él
287
290
  when p == "deepseek"
288
- give contains(m, "vision")
291
+ give contains(m, "vision") or contains(m, "flash")
289
292
  when p == "openai"
290
- give starts_with(m, "gpt-4o") or starts_with(m, "gpt-4.1") or starts_with(m, "gpt-5") or starts_with(m, "o1") or starts_with(m, "o3") or starts_with(m, "o4")
293
+ give starts_with(m, "gpt-4o") or starts_with(m, "gpt-4.1") or starts_with(m, "gpt-5") or starts_with(m, "gpt-6") or starts_with(m, "o1") or starts_with(m, "o3") or starts_with(m, "o4")
291
294
  when p == "openrouter" or p == "ollama"
292
- give contains(m, "vision") or contains(m, "vl") or contains(m, "gpt-4o") or contains(m, "gpt-5") or contains(m, "claude") or contains(m, "gemini") or contains(m, "llava") or contains(m, "pixtral") or contains(m, "qwen2.5vl") or contains(m, "qwen3-vl")
295
+ give contains(m, "vision") or contains(m, "vl") or contains(m, "gpt-4o") or contains(m, "gpt-5") or contains(m, "gpt-6") or contains(m, "claude") or contains(m, "gemini") or contains(m, "llava") or contains(m, "pixtral") or contains(m, "qwen2.5vl") or contains(m, "qwen3-vl")
293
296
  when p == "grok"
294
297
  give contains(m, "vision") or starts_with(m, "grok-4")
295
298
  when p == "kimi"
@@ -307,7 +310,7 @@ task image_note(m)
307
310
  each e in enumerate(m["images"])
308
311
  let im be e["item"]
309
312
  let dims be when contains(im, "w") then " " + text(floor(im["w"])) + "x" + text(floor(im["h"])) + "px" otherwise ""
310
- set notes to append(notes, "[Image " + text(e["index"] + 1) + dims + " attached, but this model does not accept image input — tell the user to switch to a vision model (e.g. anthropic or gpt-4o) if they need it read]")
313
+ set notes to append(notes, "[Image " + text(e["index"] + 1) + dims + " attached, but this model does not accept image input — tell the user to switch to a vision model (e.g. anthropic or gpt-6.1-sol) if they need it read]")
311
314
  give m["content"] + "\n" + join(notes, "\n")
312
315
 
313
316
  -- Handle textual junto a cada imagen (patrón de hermes/deepseek): el modelo sabe cuántas hay y de qué tamaño.
package/lib/runtime.syn CHANGED
@@ -447,6 +447,13 @@ export task thread_session(agent, thread)
447
447
  give ""
448
448
  give ""
449
449
 
450
+ -- la próxima entrega a (agente, thread) arranca una conversación nueva
451
+ export task forget_thread(agent, thread)
452
+ require time
453
+ require file(".lampson")
454
+ require file(".lampson/*")
455
+ remember_thread(agent, thread, "")
456
+
450
457
  task remember_thread(agent, thread, sid)
451
458
  require time
452
459
  require file(".lampson")
@@ -509,6 +516,11 @@ export task open(sobre, hooks)
509
516
  -- en un equipo con git, cada agente en su copia (lib/worktree.syn); "worktrees": false en el equipo lo apaga
510
517
  when starts_with(thread, "team:")
511
518
  let tm be teams.get(slice(thread, 5, length(thread)))
519
+ -- un asiento que no es el líder no le abre aprobaciones a la persona: van a su jefe (lib/loop.syn)
520
+ when tm != nothing
521
+ let mine be teams.member(tm, ctx["agent"])
522
+ when mine != nothing and ctx["agent"] != teams.lead_of(tm) and mine["reports_to"] != ""
523
+ set copts["escalate_to"] to mine["reports_to"]
512
524
  when tm != nothing and tm["worktrees"]
513
525
  let me be teams.member(tm, ctx["agent"])
514
526
  let wt be worktree.ensure(tm["id"], ctx["agent"], {"name": (when me != nothing and me["role"] != ctx["agent"] then me["role"] + " · " + ctx["agent"] otherwise ctx["agent"]) + " (Lampson)", "email": ctx["agent"] + "@lampson.local"})
@@ -539,6 +551,35 @@ export task save(o, messages)
539
551
  session.save(o["session"], messages, {"title": session.title_of(messages), "agent": o["ctx"]["agent"], "thread": o["thread"]})
540
552
  remember_thread(o["ctx"]["agent"], o["thread"], o["session"])
541
553
 
554
+ -- la vista en vivo de un objetivo (public/js/objlive.js): cada paso de un asiento de equipo u objetivo sale al bus
555
+ -- ("team.step") en el momento, compacto — el detalle completo sigue en la traza
556
+ task live(th, agent, kind, data)
557
+ require time
558
+ when not (starts_with(th, "team:") or starts_with(th, "objective:"))
559
+ give false
560
+ let d be nothing
561
+ when kind == "busy"
562
+ set d to {"label": slice(text(field(data, "label", "")), 0, 200), "what": field(data, "kind", ""), "name": field(data, "name", "")}
563
+ otherwise when kind == "tool_call"
564
+ set d to {"name": data["name"], "args": slice(json_encode(data["args"]), 0, 1500)}
565
+ otherwise when kind == "tool_result"
566
+ let out be text(data["output"])
567
+ set d to {"name": data["call"]["name"], "ok": not (starts_with(out, "ERROR") or starts_with(out, "DENIED") or starts_with(out, "NOT RUN")), "out": slice(out, 0, 200)}
568
+ otherwise when kind == "tool_denied"
569
+ set d to {"name": data["call"]["name"], "reason": slice(text(data["reason"]), 0, 200)}
570
+ otherwise when kind == "assistant"
571
+ set d to {"text": slice(text(data), 0, 400)}
572
+ otherwise when kind == "usage"
573
+ let u be data["usage"]
574
+ let cached be field(u, "cached", 0)
575
+ set d to {"cost": u["input"] - cached + floor(cached / 10) + u["output"]}
576
+ otherwise when kind == "turn_start" or kind == "turn_end" or kind == "idle"
577
+ set d to {}
578
+ when d == nothing
579
+ give false
580
+ bus_publish("team.step", {"scope": th, "agent": agent, "kind": kind, "data": d, "at": now()})
581
+ give true
582
+
542
583
  -- corre UN turno sobre mensajes ya armados (el del usuario ya agregado): traza, run_turn, guarda.
543
584
  -- o: {ctx: {cfg, opts, agent}, session, thread} — lo que devuelve open(), o lo que arma la terminal.
544
585
  -- label: lo que se anota como turno del usuario en la traza ("" = el último mensaje de usuario).
@@ -565,8 +606,11 @@ export task turn(o, messages, label, hooks)
565
606
  require secret("LAMPSON_*")
566
607
  let sid be o["session"]
567
608
  let user_cb be field(hooks, "on_event", nothing)
609
+ let th0 be text(field(o, "thread", ""))
610
+ let me be o["ctx"]["agent"]
568
611
  task on_event(kind, data, tag)
569
612
  trace.event(sid, kind, data, tag)
613
+ live(th0, me, kind, data)
570
614
  when user_cb != nothing
571
615
  call(user_cb, {"kind": kind, "data": data, "tag": tag})
572
616
  let said be label
@@ -576,14 +620,21 @@ export task turn(o, messages, label, hooks)
576
620
  set said to text(m["content"])
577
621
  let cfg be o["ctx"]["cfg"]
578
622
  trace.user(sid, said, o["ctx"]["agent"], o["ctx"]["opts"]["permission_mode"], cfg["model"])
623
+ live(th0, me, "turn_start", nothing)
624
+ when starts_with(th0, "team:")
625
+ let oid be teams.objective_of_scope(th0)
626
+ when oid != 0
627
+ teams.seat_session(oid, me, sid)
579
628
  let result be loop.run_turn(cfg, messages, o["ctx"]["opts"], on_event)
580
629
  trace.turn_end(sid, result)
630
+ live(th0, me, "turn_end", nothing)
581
631
  -- presupuesto de equipos: lo que gastó este turno (los cacheados pesan 10%, como en el loop)
582
632
  let cost be result["usage"]["input"] - result["usage"]["cached"] + floor(result["usage"]["cached"] / 10) + result["usage"]["output"]
583
633
  let th be text(field(o, "thread", ""))
584
634
  when starts_with(th, "team:")
585
635
  teams.record_spend(o["ctx"]["agent"], cost)
586
636
  teams.team_turn_end(slice(th, 5, length(th)), o["ctx"]["agent"], cost)
637
+ teams.seat_turn_end(slice(th, 5, length(th)), o["ctx"]["agent"], field(result, "stopped", "done"), field(result, "text", ""))
587
638
  when starts_with(th, "objective:")
588
639
  teams.obj_turn_end(floor(number(slice(th, 10, length(th)))), cost)
589
640
  save(o, result["messages"])
@@ -626,5 +677,10 @@ export task deliver(sobre, hooks)
626
677
  let images be field(sobre, "images", [])
627
678
  when length(images) > 0
628
679
  set umsg to {"role": "user", "content": msg, "images": images}
680
+ let t0 be now()
629
681
  let result be turn(o, append(o["messages"], umsg), msg, hooks)
682
+ -- en un equipo, la respuesta final no la lee nadie: si el asiento no mandó nada, se le reenvía a quien lo despertó
683
+ let th be text(o["thread"])
684
+ when starts_with(th, "team:")
685
+ teams.forward_final(slice(th, 5, length(th)), o["ctx"]["agent"], text(field(field(sobre, "meta", {}), "from", "")), field(result, "stopped", "done"), field(result, "text", ""), t0, msg)
630
686
  give {"agent": o["ctx"]["agent"], "thread": o["thread"], "session": sid, "text": result["text"], "steps": result["steps"], "usage": result["usage"], "stopped": result["stopped"]}
package/lib/schedule.syn CHANGED
@@ -1,6 +1,9 @@
1
1
  -- lib/schedule.syn — tareas programadas: "cada 6 h", "todos los días a las 9", "lunes 8:30"
2
2
  --
3
3
  -- Qué se programa (action.type):
4
+ -- objective → una RUTINA de un equipo: {team, text, budget_tokens?, round_seconds?}. Cada vez que le toca crea un
5
+ -- objetivo normal para el líder del equipo (created_by = "rutina:<id de la tarea>": así se ven sus
6
+ -- ejecuciones). Si la ejecución anterior sigue abierta, esta se saltea — no se amontonan objetivos.
4
7
  -- plugin → una tool de un plugin ENCENDIDO: {plugin, tool, args}. Encenderlo ya fue la autorización.
5
8
  -- bash → un comando fijo desde el workspace: {command, timeout}. Aprobado UNA vez, al crear la tarea.
6
9
  -- prompt → una corrida completa del agente con un texto: {prompt, agent}. Sin humano al lado: corre con el
@@ -28,6 +31,7 @@ use "./permission.syn" as permission
28
31
  use "./tools/common.syn" as c
29
32
  use "./tools/memo.syn" as memo
30
33
  use "./settings.syn" as settings
34
+ use "./teams.syn" as teams
31
35
 
32
36
  export let FILE be ".lampson/schedules.json"
33
37
  export let LOG_DIR be ".lampson/schedules"
@@ -380,11 +384,18 @@ task slug(name)
380
384
  -- valida y normaliza la acción → {ok, action, error}
381
385
  task check_action(action)
382
386
  when action == nothing or not contains(action, "type")
383
- give {"ok": false, "error": "action needs a type: plugin | bash | prompt"}
387
+ give {"ok": false, "error": "action needs a type: objective | plugin | bash | prompt"}
384
388
  let kind be lower(text(action["type"]))
385
389
  when kind == "lamp"
386
390
  -- compat: "lamp" era el nombre de "plugin" hasta 2026-09 (tareas guardadas, JSON escrito a mano)
387
391
  set kind to "plugin"
392
+ when kind == "objective"
393
+ let tid be lower(text(when contains(action, "team") then action["team"] otherwise ""))
394
+ when tid == "" or teams.get(tid) == nothing
395
+ give {"ok": false, "error": "action objective needs the id of a team of this project (got '" + tid + "')"}
396
+ when not contains(action, "text") or trim(text(action["text"])) == ""
397
+ give {"ok": false, "error": "action objective needs the text of the objective"}
398
+ give {"ok": true, "action": {"type": "objective", "team": tid, "text": trim(text(action["text"])), "budget_tokens": floor(number(when contains(action, "budget_tokens") and action["budget_tokens"] != nothing then action["budget_tokens"] otherwise 600000)), "round_seconds": floor(number(when contains(action, "round_seconds") and action["round_seconds"] != nothing then action["round_seconds"] otherwise 60)), "pass_ask": when contains(action, "pass_ask") then action["pass_ask"] == true otherwise false}}
388
399
  when kind == "plugin"
389
400
  let pname be plugin_of(action)
390
401
  when pname == "" or not contains(action, "tool")
@@ -409,7 +420,7 @@ task check_action(action)
409
420
  when not contains(["build", "plan", "review", "explore"], agent)
410
421
  give {"ok": false, "error": "agent must be build | plan | review | explore"}
411
422
  give {"ok": true, "action": {"type": "prompt", "prompt": text(action["prompt"]), "agent": agent}}
412
- give {"ok": false, "error": "unknown action type '" + kind + "' (plugin | bash | prompt)"}
423
+ give {"ok": false, "error": "unknown action type '" + kind + "' (objective | plugin | bash | prompt)"}
413
424
 
414
425
  -- crear: spec = {name, when, action, permission?, approval_timeout?, notify?} → la tarea (raise si es inválida)
415
426
  export task add(spec)
@@ -466,6 +477,9 @@ task is_plugin_action(a)
466
477
  give a["type"] == "plugin" or a["type"] == "lamp"
467
478
 
468
479
  task default_name(action)
480
+ when action["type"] == "objective"
481
+ let o be replace(action["text"], "\n", " ")
482
+ give when length(o) > 40 then slice(o, 0, 40) + "…" otherwise o
469
483
  when is_plugin_action(action)
470
484
  give plugin_of(action) + " " + action["tool"]
471
485
  when action["type"] == "bash"
@@ -561,6 +575,8 @@ export task run_simple(t)
561
575
  require file("workspace")
562
576
  require file("workspace/*")
563
577
  let a be t["action"]
578
+ when a["type"] == "objective"
579
+ give run_routine(t)
564
580
  when is_plugin_action(a)
565
581
  give plugins.call(plugins.tool_name(plugin_of(a), a["tool"]), a["args"])
566
582
  when a["type"] == "bash"
@@ -653,8 +669,30 @@ export task log_tail(id, n)
653
669
  recover err
654
670
  give ""
655
671
 
672
+ -- una ejecución de una rutina: un objetivo para el líder del equipo, salvo que la anterior siga abierta
673
+ export let ROUTINE_PREFIX be "rutina:"
674
+ export task run_routine(t)
675
+ require db(".lampson/teams.db")
676
+ require time
677
+ require file(".lampson")
678
+ require file(".lampson/*")
679
+ require file.read("workspace")
680
+ require file.read("workspace/*")
681
+ let a be t["action"]
682
+ let tm be teams.get(a["team"])
683
+ when tm == nothing
684
+ give "ERROR: team '" + a["team"] + "' no longer exists in this project"
685
+ let mine be ROUTINE_PREFIX + t["id"]
686
+ let still be where(teams.obj_list(), (o) => o["created_by"] == mine and contains(["active", "waiting", "paused"], o["status"]))
687
+ when length(still) > 0
688
+ give "SKIPPED: the previous run (O-" + text(still[0]["id"]) + ") is still open"
689
+ let id be teams.obj_create(teams.lead_of(tm), a["text"], {"team": tm["id"], "budget_tokens": a["budget_tokens"], "round_seconds": a["round_seconds"], "created_by": mine, "pass_ask": when contains(a, "pass_ask") then a["pass_ask"] == true otherwise false})
690
+ give "O-" + text(id) + " → team " + tm["id"]
691
+
656
692
  -- descripción de la acción (una línea) para previews y listados
657
693
  export task describe_action(a)
694
+ when a["type"] == "objective"
695
+ give "objective for team " + a["team"] + ": " + one_line(a["text"], 140)
658
696
  when is_plugin_action(a)
659
697
  give "plugin " + plugin_of(a) + "." + a["tool"] + (when length(keys(a["args"])) > 0 then " " + one_line(json_encode(a["args"]), 80) otherwise "")
660
698
  when a["type"] == "bash"
package/lib/teamrun.syn CHANGED
@@ -26,7 +26,7 @@ task flag_budget(team, agent)
26
26
  let k be "teams:budget:" + team["id"] + ":" + agent + ":" + format_time(now(), "%Y-%m-%d")
27
27
  when state_get(k) == nothing
28
28
  state_set(k, true)
29
- teams.log("team:" + team["id"], agent, "budget", "", "daily budget reached (" + text(team["budget_daily_tokens"]) + " tokens): no more turns today")
29
+ teams.log("team:" + team["id"], agent, "budget", "", "daily budget reached (" + text(teams.cap_of(team, agent)) + " tokens): no more turns today")
30
30
 
31
31
  -- un turno para `agent` en su conversación del equipo
32
32
  export task deliver_to(team, agent, sender, head)
@@ -43,7 +43,18 @@ export task deliver_to(team, agent, sender, head)
43
43
  when spec == nothing
44
44
  teams.log("team:" + team["id"], "lampson", "error", "", "no agent file for '" + agent + "' — create .lampson/agents/" + agent + ".agent.json")
45
45
  give false
46
- 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}}
46
+ -- su primer turno en un objetivo: conversación nueva (el tablero, el registro y git ya cuentan lo anterior)
47
+ let oid be teams.objective_of_scope("team:" + team["id"])
48
+ when oid != 0 and teams.seat_session_of(oid, agent) == ""
49
+ runtime.forget_thread(agent, "team:" + team["id"])
50
+ -- quién está en medio de un turno: sus mensajes le llegan cuando termina. (Visto 2026-10-17: el CEO le preguntó
51
+ -- tres veces al CMO, que estaba documentando, no le contestó, y le pasó su tarea al CTO: los dos hicieron lo mismo.)
52
+ let busy be []
53
+ each m in team["members"]
54
+ when m["agent"] != agent and mailbox.working(m["agent"], "team:" + team["id"])
55
+ set busy to append(busy, m["agent"])
56
+ let now_line be when length(busy) == 0 then "" otherwise "\nWorking right now (your messages reach them when their turn ends — wait for them, don't reassign their tasks): " + join(busy, ", ")
57
+ let sobre be {"to": agent, "thread": "team:" + team["id"], "session": "", "from": sender, "text": teams.turn_text(team, agent, head) + now_line, "images": [], "channel": "team", "meta": {"team": team["id"], "from": sender}}
47
58
  mailbox.submit(sobre, {"mode": when spec["permission"] != "" then "" otherwise "strict", "buffer": mailbox.buffer_of(spec, false)})
48
59
  give true
49
60
 
@@ -97,9 +108,34 @@ export task objective_due(o)
97
108
  give false
98
109
  -- en un equipo, el líder solo hace ronda si algo cambió o tiene tareas propias (si no, está esperando a los demás)
99
110
  when o["team"] != ""
100
- give teams.has_work("team:" + o["team"], o["agent"])
111
+ when teams.has_work("team:" + o["team"], o["agent"])
112
+ give true
113
+ -- nadie se mueve hace rato: el líder recibe UNA ronda para destrabar (y otra si sigue igual, STALL_SECONDS después)
114
+ when stalled(o)
115
+ teams.obj_set(o["id"], {"reply": STALL_TEXT})
116
+ give true
117
+ give false
101
118
  give true
102
119
 
120
+ export let STALL_SECONDS be 600
121
+ export let STALL_TEXT be "[stalled] Nothing has moved in the team for 10 minutes and nobody is working. Look at the board: is someone waiting for something, or did someone stop without saying? Unblock it (`send` them what they need; reassign only if they said they are blocked) or, if the team can't go on, ask the person with `objective` ask."
122
+
123
+ -- ¿el equipo de un objetivo está quieto? nadie trabajando, ningún mensaje por entregar y nada en el registro hace rato
124
+ task stalled(o)
125
+ require db(".lampson/teams.db")
126
+ require file(".lampson")
127
+ require file(".lampson/*")
128
+ require file.read("workspace")
129
+ require file.read("workspace/*")
130
+ require time
131
+ let tm be teams.get(o["team"])
132
+ when tm == nothing or now() - o["last_end"] < STALL_SECONDS
133
+ give false
134
+ each m in tm["members"]
135
+ when mailbox.working(m["agent"], "team:" + tm["id"])
136
+ give false
137
+ give teams.quiet_for("team:" + tm["id"]) >= STALL_SECONDS
138
+
103
139
  -- escribe el resumen si cambió: equipos, objetivos abiertos (y los últimos cerrados) y aprobaciones pendientes
104
140
  export task write_summary()
105
141
  require db(".lampson/teams.db")
@@ -110,7 +146,8 @@ export task write_summary()
110
146
  require file(".lampson/*")
111
147
  require file.read("workspace")
112
148
  require file.read("workspace/*")
113
- let ts be apply(teams.all(), (t) => {"id": t["id"], "description": t["description"], "members": length(t["members"]), "lead": teams.lead_of(t)})
149
+ -- roles: lo que /equipos del hub muestra de cada equipo (el rol, o el id del agente si no tiene)
150
+ let ts be apply(teams.all(), (t) => {"id": t["id"], "name": t["name"], "description": t["description"], "members": length(t["members"]), "lead": teams.lead_of(t), "roles": apply(t["members"], (m) => when contains(m, "role") and m["role"] != nothing and text(m["role"]) != "" then text(m["role"]) otherwise text(m["agent"]))})
114
151
  let objs be teams.obj_list()
115
152
  let open_o be where(objs, (o) => contains(["active", "waiting", "paused"], o["status"]))
116
153
  let closed be slice(where(objs, (o) => not contains(["active", "waiting", "paused"], o["status"])), 0, 5)
@@ -163,7 +200,7 @@ export task tick()
163
200
  flag_budget(team, m["recipient"])
164
201
  otherwise
165
202
  let who be teams.member(team, m["sender"])
166
- let head be "[message from " + m["sender"] + (when who != nothing then " (" + who["role"] + ")" otherwise "") + "]\n" + m["text"]
203
+ let head be when m["sender"] == "person" then "[message from the person who owns this team — act on it]\n" + m["text"] otherwise "[message from " + m["sender"] + (when who != nothing then " (" + who["role"] + ")" otherwise "") + "]\n" + m["text"]
167
204
  when deliver_to(team, m["recipient"], m["sender"], head)
168
205
  teams.mark(m["id"], "delivered")
169
206
  set n to n + 1