@femtomc/mu-agent 26.2.97 → 26.2.99

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.
@@ -0,0 +1,171 @@
1
+ ---
2
+ name: setup-telegram
3
+ description: "Sets up the Telegram messaging adapter with agent-first webhook, config, reload, verification, and identity linking steps. Use when onboarding or repairing Telegram channel integration."
4
+ ---
5
+
6
+ # setup-telegram
7
+
8
+ Use this skill when the user asks to set up Telegram messaging for `mu`.
9
+
10
+ Goal: get Telegram bot ingress and reply delivery working with minimal user-side actions.
11
+
12
+ ## Contents
13
+
14
+ - [Required user-provided inputs](#required-user-provided-inputs)
15
+ - [Agent-first workflow](#agent-first-workflow)
16
+ - [Evaluation scenarios](#evaluation-scenarios)
17
+ - [Safety requirements](#safety-requirements)
18
+
19
+ ## Required user-provided inputs
20
+
21
+ - Public webhook base URL reachable by Telegram (for example `https://mu.example.com`)
22
+ - Telegram bot token (from BotFather)
23
+
24
+ Optional (agent can usually discover):
25
+ - Bot username
26
+
27
+ ## Agent-first workflow
28
+
29
+ ### 0) Verify local prerequisites (agent)
30
+
31
+ ```bash
32
+ command -v mu >/dev/null && echo "mu: ok"
33
+ command -v python3 >/dev/null && echo "python3: ok (required for config patching)"
34
+ command -v curl >/dev/null && echo "curl: ok (required for Telegram API + channel checks)"
35
+ command -v jq >/dev/null && echo "jq: ok (required for filtered JSON checks)"
36
+ ```
37
+
38
+ If any required command is missing, stop and ask the user to install it before proceeding.
39
+
40
+ ### 1) Preflight local state
41
+
42
+ ```bash
43
+ mu control status --pretty
44
+ mu store paths --pretty
45
+ mu control identities --all --pretty
46
+ ```
47
+
48
+ If no running server is available, ask user to start `mu serve` in another terminal before reload/route checks.
49
+
50
+ ### 2) Generate webhook secret and discover bot username
51
+
52
+ Generate a strong webhook secret (do not expose it in final summaries).
53
+
54
+ If outbound network is available, discover bot username:
55
+
56
+ ```bash
57
+ curl -sS "https://api.telegram.org/bot<bot-token>/getMe"
58
+ ```
59
+
60
+ Extract `result.username` when present.
61
+
62
+ ### 3) Configure Telegram webhook (agent does this when possible)
63
+
64
+ Set webhook to `https://<public-base>/webhooks/telegram` with secret token:
65
+
66
+ ```bash
67
+ curl -sS "https://api.telegram.org/bot<bot-token>/setWebhook" \
68
+ --data-urlencode "url=https://<public-base>/webhooks/telegram" \
69
+ --data-urlencode "secret_token=<webhook-secret>"
70
+ ```
71
+
72
+ If the agent cannot reach Telegram APIs from its environment, give user this exact command and continue once they confirm success.
73
+
74
+ ### 4) Patch mu config
75
+
76
+ Use this canonical patch snippet (preserves unrelated keys):
77
+
78
+ ```bash
79
+ export MU_TELEGRAM_WEBHOOK_SECRET='<TELEGRAM_WEBHOOK_SECRET>'
80
+ export MU_TELEGRAM_BOT_TOKEN='<TELEGRAM_BOT_TOKEN>'
81
+ export MU_TELEGRAM_BOT_USERNAME='<TELEGRAM_BOT_USERNAME_OR_EMPTY>'
82
+ config_path="$(mu control status --json | python3 -c 'import json,sys; print(json.load(sys.stdin)["config_path"])')"
83
+
84
+ python3 - "$config_path" <<'PY'
85
+ import json
86
+ import os
87
+ import sys
88
+ from pathlib import Path
89
+
90
+ path = Path(sys.argv[1])
91
+ if path.exists():
92
+ data = json.loads(path.read_text())
93
+ else:
94
+ data = {"version": 1, "control_plane": {}}
95
+
96
+ cp = data.setdefault("control_plane", {})
97
+ adapters = cp.setdefault("adapters", {})
98
+ telegram = adapters.setdefault("telegram", {})
99
+ telegram["webhook_secret"] = os.environ["MU_TELEGRAM_WEBHOOK_SECRET"]
100
+ telegram["bot_token"] = os.environ["MU_TELEGRAM_BOT_TOKEN"]
101
+ username = os.environ.get("MU_TELEGRAM_BOT_USERNAME", "").strip()
102
+ telegram["bot_username"] = username or None
103
+
104
+ path.parent.mkdir(parents=True, exist_ok=True)
105
+ path.write_text(json.dumps(data, indent=2) + "\n")
106
+ PY
107
+ ```
108
+
109
+ Replace placeholder values with secrets from the user.
110
+ If bot username is unknown, leave `MU_TELEGRAM_BOT_USERNAME` empty.
111
+ Then `unset MU_TELEGRAM_WEBHOOK_SECRET MU_TELEGRAM_BOT_TOKEN MU_TELEGRAM_BOT_USERNAME` after patching.
112
+
113
+ ### 5) Reload and verify
114
+
115
+ ```bash
116
+ mu control reload
117
+ mu control status --json --pretty
118
+ curl -sS http://localhost:3000/api/control-plane/channels | jq '.channels[] | select(.channel=="telegram")'
119
+ ```
120
+
121
+ Verify:
122
+ - `configured: true`
123
+ - `active: true` (with running server)
124
+ - route `/webhooks/telegram`
125
+
126
+ ### 6) Identity link using audit-derived chat id
127
+
128
+ Preferred flow:
129
+ 1. Ask user to send one message to the bot.
130
+ 2. Extract latest Telegram audit row.
131
+ 3. Link actor chat id to tenant `telegram-bot`.
132
+
133
+ ```bash
134
+ mu store tail cp_adapter_audit --limit 50 --json \
135
+ | jq -r '[.[] | select(.channel=="telegram")] | last | "actor=\(.actor_id)"'
136
+
137
+ mu control link --channel telegram --actor-id <chat-id> --tenant-id telegram-bot --role operator
138
+ mu control identities --pretty
139
+ ```
140
+
141
+ If audit is unavailable, ask user for the chat id explicitly.
142
+
143
+ ### 7) Smoke + delivery checks
144
+
145
+ ```bash
146
+ mu control status --pretty
147
+ mu store tail cp_adapter_audit --limit 20 --pretty
148
+ mu store tail cp_outbox --limit 20 --pretty
149
+ ```
150
+
151
+ Ask user to send `/mu status` (or plain status text) and verify response delivery.
152
+
153
+ ## Evaluation scenarios
154
+
155
+ 1. **Happy path with API reachability**
156
+ - Inputs: valid bot token, reachable public webhook base URL, working `setWebhook` call.
157
+ - Expected: Telegram channel reports `configured=true` + `active=true`; inbound message gets reply.
158
+
159
+ 2. **Network-restricted agent environment**
160
+ - Inputs: agent cannot reach `api.telegram.org`.
161
+ - Expected: skill hands user exact `setWebhook` command, resumes after confirmation, and still completes local config/reload verification.
162
+
163
+ 3. **Unknown bot username fallback**
164
+ - Inputs: `getMe` unavailable or username omitted.
165
+ - Expected: config stores `bot_username: null` (or omitted equivalent), adapter still activates, and identity link can proceed from audit chat id.
166
+
167
+ ## Safety requirements
168
+
169
+ - Treat bot token and webhook secret as sensitive; do not echo full values in summaries.
170
+ - Keep user prompts focused on the few actions the agent cannot do (BotFather + optional network-restricted webhook call).
171
+ - Report concrete reason codes when attachment/media delivery fails.
@@ -1,27 +1,53 @@
1
1
  ---
2
2
  name: subagents
3
- description: Orchestrate issue-driven subagent work with heartbeat supervision and tmux worker fan-out.
3
+ description: "Orchestrates issue-driven subagent execution with heartbeat supervision and tmux fan-out. Use when work should progress through durable parallel subagent loops."
4
4
  ---
5
5
 
6
6
  # Subagents
7
7
 
8
+ ## Contents
9
+
10
+ - [Purpose (what this skill is for)](#purpose-what-this-skill-is-for)
11
+ - [Shared protocol dependency](#shared-protocol-dependency)
12
+ - [When to use](#when-to-use)
13
+ - [Success condition](#success-condition)
14
+ - [Dispatch modes](#dispatch-modes)
15
+ - [Orchestration loops](#orchestration-loops)
16
+ - [Bootstrap and queue targeting](#bootstrap-and-queue-targeting)
17
+ - [Dispatch templates](#dispatch-templates)
18
+ - [Subagents HUD](#subagents-hud)
19
+ - [Evaluation scenarios](#evaluation-scenarios)
20
+ - [Reconciliation](#reconciliation)
21
+ - [Safety](#safety)
22
+
8
23
  ## Purpose (what this skill is for)
9
24
 
10
- Use this skill for **durable multi-agent orchestration**: work that must keep moving over time, not just one-shot execution.
25
+ Use this skill for **durable multi-agent orchestration**: work that must keep moving
26
+ over time, not just one-shot execution.
11
27
 
12
- This skill combines `mu` primitives into one orchestration model:
28
+ This skill is execution-supervision focused:
13
29
 
14
- - `mu issues` = executable DAG, dependencies, lifecycle state
15
- - `mu forum` = durable task/result packets
16
30
  - `mu heartbeats` / `mu cron` = orchestrator wake cadence
17
31
  - `tmux` + `mu exec` = parallel worker execution
18
- - subagents HUD = observability/control board
32
+ - subagents HUD = operator observability/control board
33
+
34
+ Source of truth remains in `mu issues` + `mu forum`.
35
+
36
+ ## Shared protocol dependency
37
+
38
+ This skill executes DAG work defined by **`hierarchical-work-protocol`**.
19
39
 
20
- Protocol truth lives in **issues + forum**. HUD/tmux are execution and visibility surfaces.
40
+ Before orchestration begins, load that skill and enforce:
41
+
42
+ - Protocol ID/tag: `hierarchical-work.protocol/v1` + `proto:hierarchical-work-v1`
43
+ - Canonical node kinds, context tags, and invariants
44
+ - Primitive semantics (`read_tree`, `claim`, `spawn`, `fork`, `ask`, `expand`, `complete`, `serial`)
45
+
46
+ Do not run subagent orchestration against alternate protocol tags.
21
47
 
22
48
  ## When to use
23
49
 
24
- - Work can be represented as issue-scoped deliverables with explicit outcomes.
50
+ - Work is represented as issue-scoped deliverables with explicit outcomes.
25
51
  - Dependencies may unblock over time.
26
52
  - You want unattended progress between manual check-ins.
27
53
 
@@ -35,152 +61,45 @@ Protocol truth lives in **issues + forum**. HUD/tmux are execution and visibilit
35
61
 
36
62
  ### 1) Heartbeat dispatch (orchestrator cadence)
37
63
 
38
- Use when you want the orchestration loop to keep running over time.
64
+ Use when you want orchestration to continue over time.
39
65
 
40
- Each heartbeat tick should run **one bounded control-loop pass**:
66
+ Each heartbeat tick runs **one bounded orchestration pass**:
41
67
 
42
68
  1. Read queue/tree state.
43
- 2. Choose one primitive (`ask`, `expand`, `complete`, etc.).
44
- 3. Apply one action.
69
+ 2. Select one protocol primitive/action.
70
+ 3. Apply one bounded action.
45
71
  4. Verify state + log progress.
46
72
  5. Exit.
47
73
 
48
- Heartbeat dispatch is the **orchestrator clock**. It should supervise/advance the graph, not run unbounded worker sessions.
74
+ Heartbeat dispatch is the orchestrator clock. It should supervise/advance the graph,
75
+ not run unbounded worker sessions.
49
76
 
50
77
  ### 2) tmux dispatch (parallel workers)
51
78
 
52
- Use when multiple ready leaves should execute concurrently now.
53
-
54
- Spawn one tmux session per ready issue. Each worker should claim one issue, run one full issue loop, then exit.
55
-
56
- ## Protocol: `subagents.protocol/v1` (how the skill executes)
57
-
58
- ### Primitive: `read_tree`
59
-
60
- Before every mutation, inspect root + local node state:
61
-
62
- ```bash
63
- mu issues get <issue-id> --pretty
64
- mu issues children <issue-id> --pretty
65
- mu issues ready --root <root-id> --tag proto:subagents-v1 --pretty
66
- mu forum read issue:<issue-id> --limit 20 --pretty
67
- ```
68
-
69
- ### Primitive: `claim`
70
-
71
- Claim before doing work on an executable issue:
72
-
73
- ```bash
74
- mu issues claim <issue-id>
75
- mu forum post issue:<issue-id> -m "START: <plan for this pass>" --author operator
76
- ```
77
-
78
- ### Primitive: `spawn` (clean-context child)
79
-
80
- Create independent child tasks with scoped context:
81
-
82
- ```bash
83
- child_json="$(mu issues create "<title>" \
84
- --parent <issue-id> \
85
- --body "<prompt + acceptance criteria>" \
86
- --tag proto:subagents-v1 \
87
- --tag kind:spawn \
88
- --tag ctx:clean \
89
- --priority 2 \
90
- --json)"
91
- child_id="$(echo "$child_json" | jq -r '.id')"
92
- mu forum post issue:"$child_id" -m "<task packet>" --author operator
93
- ```
94
-
95
- Use dependencies to control timing:
96
-
97
- ```bash
98
- mu issues dep <blocker-id> blocks <child-id>
99
- ```
100
-
101
- ### Primitive: `fork` (inherited-context child)
102
-
103
- Create analysis/synthesis children that depend on sibling outputs.
104
- Before creation, summarize dependency results from `mu forum read issue:<dep-id>`.
105
- Then create with `kind:fork` + `ctx:inherit`.
79
+ Use when several ready leaves should execute concurrently now.
106
80
 
107
- ### Primitive: `ask` (human input node)
81
+ Spawn one tmux session per ready issue. Each worker claims one issue, executes one
82
+ full issue loop, then exits.
108
83
 
109
- Represent user questions as first-class nodes:
84
+ ## Orchestration loops
110
85
 
111
- ```bash
112
- ask_json="$(mu issues create "Question: <question>" \
113
- --parent <issue-id> \
114
- --tag proto:subagents-v1 \
115
- --priority 1 \
116
- --json)"
117
- ask_id="$(echo "$ask_json" | jq -r '.id')"
118
- mu issues update "$ask_id" \
119
- --remove-tag node:agent \
120
- --add-tag kind:ask \
121
- --add-tag ctx:human \
122
- --add-tag actor:user
123
- mu forum post issue:"$ask_id" \
124
- -m "QUESTION: <question>\nOPTIONS: <list or free-form>\nReply in this topic, then close this issue." \
125
- --author operator
126
- ```
127
-
128
- If downstream work depends on the answer:
129
-
130
- ```bash
131
- mu issues dep <ask-id> blocks <child-id>
132
- ```
133
-
134
- ### Primitive: `complete`
135
-
136
- Always write a result packet, then close the issue:
137
-
138
- ```bash
139
- mu forum post issue:<issue-id> -m "RESULT:\n<result>" --author operator
140
- mu issues close <issue-id> --outcome success
141
- ```
142
-
143
- Use explicit non-success outcomes when needed (`failure`, `needs_work`, `skipped`).
144
-
145
- ### Primitive: `expand`
146
-
147
- When decomposition is needed:
148
-
149
- 1. Create child work nodes via `spawn` / `fork`.
150
- 2. Create one synthesis child (`kind:synth`, `ctx:inherit`) blocked by all child work nodes.
151
- 3. Close current node with `mu issues close <issue-id> --outcome expanded`.
86
+ ### Orchestrator heartbeat tick loop
152
87
 
153
- This encodes decompose→synthesize as explicit DAG nodes.
154
-
155
- ### Primitive: `serial`
88
+ For root `<root-id>`:
156
89
 
157
- Encode ordered execution with dependency edges:
90
+ 1. Inspect queue and local protocol state:
158
91
 
159
92
  ```bash
160
- mu issues dep <step-a> blocks <step-b>
93
+ mu issues get <root-id> --pretty
94
+ mu issues ready --root <root-id> --tag proto:hierarchical-work-v1 --pretty
95
+ mu forum read issue:<root-id> --limit 20 --pretty
161
96
  ```
162
97
 
163
- ## Required invariants
164
-
165
- - **Read-before-act-verify:** every write is followed by a re-read.
166
- - **Claim-before-work:** claim executable issues before file/work execution.
167
- - **Scoped authority:** mutate only current issue + descendants.
168
- - **Container hygiene:** remove `node:agent` from non-executable root/ask/container nodes.
169
- - **Idempotent logging:** forum updates should be append-only and resumable.
170
- - **Explicit outcomes:** every executable issue closes with concrete outcome.
171
-
172
- ## Control loops
173
-
174
- ### Orchestrator heartbeat tick loop (bounded)
175
-
176
- For root `<root-id>`:
177
-
178
- 1. `read_tree` at root/selected node
179
- 2. Choose exactly one primitive to apply
180
- 3. Apply it
181
- 4. Verify state (`mu issues get`, `children`, `ready`, `validate`)
182
- 5. Post concise progress to forum
183
- 6. Exit tick
98
+ 2. Choose exactly one action/primitive from `hierarchical-work-protocol`.
99
+ 3. Apply it.
100
+ 4. Verify (`get`, `children`, `ready`, `validate`).
101
+ 5. Post concise progress to forum.
102
+ 6. Exit tick.
184
103
 
185
104
  Stop automation when `mu issues validate <root-id>` returns final.
186
105
 
@@ -188,34 +107,26 @@ Stop automation when `mu issues validate <root-id>` returns final.
188
107
 
189
108
  For claimed issue `<issue-id>` under `<root-id>`:
190
109
 
191
- 1. `read_tree`
110
+ 1. Run `read_tree`.
192
111
  2. Choose one primitive:
193
112
  - missing input -> `ask`
194
113
  - needs decomposition -> `expand`
195
114
  - directly solvable -> `complete`
196
- 3. Apply primitive
197
- 4. Verify state
198
- 5. Post concise progress to `issue:<issue-id>`
115
+ 3. Apply primitive.
116
+ 4. Verify state.
117
+ 5. Post concise progress to `issue:<issue-id>`.
118
+
119
+ Repeat bounded passes until issue closes.
199
120
 
200
- Repeat until issue closes.
121
+ ## Bootstrap and queue targeting
201
122
 
202
- ## Bootstrap template
123
+ If root DAG does not yet exist, create it using the
124
+ `hierarchical-work-protocol` bootstrap template first.
125
+
126
+ During orchestration, always scope queue reads with protocol tag:
203
127
 
204
128
  ```bash
205
- root_json="$(mu issues create "Root: <goal>" --tag node:root --tag proto:subagents-v1 --json)"
206
- root_id="$(echo "$root_json" | jq -r '.id')"
207
- mu issues update "$root_id" --remove-tag node:agent
208
-
209
- goal_json="$(mu issues create "Goal execution" \
210
- --parent "$root_id" \
211
- --tag proto:subagents-v1 \
212
- --tag kind:goal \
213
- --tag ctx:clean \
214
- --priority 2 \
215
- --json)"
216
- goal_id="$(echo "$goal_json" | jq -r '.id')"
217
-
218
- mu forum post issue:"$goal_id" -m "<goal brief + acceptance criteria>" --author operator
129
+ mu issues ready --root <root-id> --tag proto:hierarchical-work-v1 --pretty
219
130
  ```
220
131
 
221
132
  ## Dispatch templates
@@ -224,32 +135,32 @@ mu forum post issue:"$goal_id" -m "<goal brief + acceptance criteria>" --author
224
135
 
225
136
  ```bash
226
137
  mu heartbeats create \
227
- --title "subagents-v1 <root-id>" \
228
- --reason subagents_protocol_v1 \
138
+ --title "hierarchical-work-v1 <root-id>" \
139
+ --reason hierarchical_work_protocol_v1 \
229
140
  --every-ms 15000 \
230
- --prompt "Use skill subagents for root <root-id>. Run exactly one bounded orchestration pass: claim/work one ready proto:subagents-v1 issue (or perform one orchestration action), verify state, and report status. Stop when 'mu issues validate <root-id>' is final."
141
+ --prompt "Use skills subagents and hierarchical-work-protocol for root <root-id>. Run exactly one bounded orchestration pass: claim/work one ready proto:hierarchical-work-v1 issue (or perform one orchestration action), verify state, and report status. Stop when 'mu issues validate <root-id>' is final."
231
142
  ```
232
143
 
233
144
  ### B) tmux fan-out (parallel workers)
234
145
 
235
146
  ```bash
236
147
  run_id="$(date +%Y%m%d-%H%M%S)"
237
- for issue_id in $(mu issues ready --root <root-id> --tag proto:subagents-v1 --json | jq -r '.[].id' | head -n 3); do
148
+ for issue_id in $(mu issues ready --root <root-id> --tag proto:hierarchical-work-v1 --json | jq -r '.[].id' | head -n 3); do
238
149
  session="mu-sub-${run_id}-${issue_id}"
239
150
  tmux new-session -d -s "$session" \
240
- "cd '$PWD' && mu exec 'Work issue ${issue_id} using subagents.protocol/v1. Claim first, then run one full control loop.' ; rc=\$?; echo __MU_DONE__:\$rc"
151
+ "cd '$PWD' && mu exec 'Use skills subagents and hierarchical-work-protocol. Work issue ${issue_id} using hierarchical-work.protocol/v1. Claim first, then run one full control loop.' ; rc=\$?; echo __MU_DONE__:\$rc"
241
152
  done
242
153
  ```
243
154
 
244
155
  ## Subagents HUD
245
156
 
246
- Use HUD to communicate with your user for visibility. Truth should still live entirely in issues/forum.
157
+ Use HUD for user visibility. Truth still lives in issues/forum.
247
158
 
248
159
  ```text
249
160
  /mu subagents on
250
161
  /mu subagents prefix mu-sub-
251
162
  /mu subagents root <root-id>
252
- /mu subagents tag proto:subagents-v1
163
+ /mu subagents tag proto:hierarchical-work-v1
253
164
  /mu subagents mode operator
254
165
  /mu subagents refresh
255
166
  /mu subagents snapshot
@@ -257,13 +168,29 @@ Use HUD to communicate with your user for visibility. Truth should still live en
257
168
 
258
169
  Tool: `mu_subagents_hud`
259
170
 
260
- - Actions: `status`, `snapshot`, `on`, `off`, `toggle`, `refresh`, `set_prefix`, `set_root`, `set_tag`, `set_mode`, `set_refresh_interval`, `set_stale_after`, `set_spawn_paused`, `update`, `spawn`
171
+ - Actions: `status`, `snapshot`, `on`, `off`, `toggle`, `refresh`,
172
+ `set_prefix`, `set_root`, `set_tag`, `set_mode`, `set_refresh_interval`,
173
+ `set_stale_after`, `set_spawn_paused`, `update`, `spawn`
174
+
175
+ ## Evaluation scenarios
176
+
177
+ 1. **Heartbeat bounded-orchestration tick**
178
+ - Setup: root issue with multiple ready leaves tagged `proto:hierarchical-work-v1`.
179
+ - Expected: one heartbeat tick performs exactly one bounded orchestration action, verifies state, posts concise progress, and exits.
180
+
181
+ 2. **tmux fan-out on ready leaves**
182
+ - Setup: at least three independent ready issues under one root.
183
+ - Expected: one worker session per issue is spawned, each worker claims before work, and each writes `START`/`RESULT` packets to `issue:<id>`.
184
+
185
+ 3. **Human-question blocking flow (`ask`)**
186
+ - Setup: worker encounters missing critical input.
187
+ - Expected: skill applies protocol `ask` semantics, creates a human-input node, and downstream work remains blocked until the answer issue closes.
261
188
 
262
189
  ## Reconciliation
263
190
 
264
191
  - Run `mu issues validate <root-id>` before declaring completion.
265
192
  - Merge synth-node outputs into one final user-facing result.
266
- - Convert unresolved gaps into new child issues tagged `proto:subagents-v1`.
193
+ - Convert unresolved gaps into new child issues tagged `proto:hierarchical-work-v1`.
267
194
  - Tear down temporary tmux sessions.
268
195
 
269
196
  ## Safety