@poa-box/agent 0.1.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 (139) hide show
  1. package/.env.agent.template +20 -0
  2. package/README.md +46 -0
  3. package/brain/Config/agent-config.json +14 -0
  4. package/brain/Config/brain-allowlist.json +20 -0
  5. package/brain/Identity/goals.template.md +23 -0
  6. package/brain/Identity/how-i-think.md +406 -0
  7. package/brain/Identity/who-i-am.template.md +34 -0
  8. package/brain/Knowledge/BOOTSTRAP.md +66 -0
  9. package/brain/Knowledge/audit-corpus-index.json +406 -0
  10. package/brain/Knowledge/discussions.json +245 -0
  11. package/brain/Knowledge/pop.brain.brainstorms.generated.md +48 -0
  12. package/brain/Knowledge/pop.brain.brainstorms.genesis.bin +0 -0
  13. package/brain/Knowledge/pop.brain.heuristics.snapshot.bin +0 -0
  14. package/brain/Knowledge/pop.brain.projects.generated.md +16 -0
  15. package/brain/Knowledge/pop.brain.projects.genesis.bin +0 -0
  16. package/brain/Knowledge/pop.brain.retros.generated.md +91 -0
  17. package/brain/Knowledge/pop.brain.retros.genesis.bin +0 -0
  18. package/brain/Knowledge/pop.brain.shared.generated.md +3811 -0
  19. package/brain/Knowledge/pop.brain.shared.genesis.bin +0 -0
  20. package/brain/Knowledge/projects.md +181 -0
  21. package/brain/Knowledge/risk-framework.md +90 -0
  22. package/brain/Knowledge/shared.md +416 -0
  23. package/brain/Knowledge/sprint-priorities.md +439 -0
  24. package/brain/Memory/.gitkeep +0 -0
  25. package/dist/commands/agent/daily-digest.d.ts +24 -0
  26. package/dist/commands/agent/daily-digest.js +336 -0
  27. package/dist/commands/agent/delegate.d.ts +12 -0
  28. package/dist/commands/agent/delegate.js +91 -0
  29. package/dist/commands/agent/deploy-to-org.d.ts +20 -0
  30. package/dist/commands/agent/deploy-to-org.js +154 -0
  31. package/dist/commands/agent/index.d.ts +2 -0
  32. package/dist/commands/agent/index.js +27 -0
  33. package/dist/commands/agent/init.d.ts +19 -0
  34. package/dist/commands/agent/init.js +303 -0
  35. package/dist/commands/agent/onboard.d.ts +22 -0
  36. package/dist/commands/agent/onboard.js +192 -0
  37. package/dist/commands/agent/paymaster-status.d.ts +14 -0
  38. package/dist/commands/agent/paymaster-status.js +130 -0
  39. package/dist/commands/agent/register.d.ts +21 -0
  40. package/dist/commands/agent/register.js +116 -0
  41. package/dist/commands/agent/setup-sponsorship.d.ts +22 -0
  42. package/dist/commands/agent/setup-sponsorship.js +154 -0
  43. package/dist/commands/agent/status.d.ts +12 -0
  44. package/dist/commands/agent/status.js +171 -0
  45. package/dist/commands/agent/triage.d.ts +12 -0
  46. package/dist/commands/agent/triage.js +503 -0
  47. package/dist/commands/brain/advance-stage.d.ts +42 -0
  48. package/dist/commands/brain/advance-stage.js +206 -0
  49. package/dist/commands/brain/allowlist.d.ts +30 -0
  50. package/dist/commands/brain/allowlist.js +274 -0
  51. package/dist/commands/brain/append-lesson.d.ts +55 -0
  52. package/dist/commands/brain/append-lesson.js +245 -0
  53. package/dist/commands/brain/brainstorm.d.ts +154 -0
  54. package/dist/commands/brain/brainstorm.js +573 -0
  55. package/dist/commands/brain/daemon.d.ts +31 -0
  56. package/dist/commands/brain/daemon.js +348 -0
  57. package/dist/commands/brain/doctor.d.ts +27 -0
  58. package/dist/commands/brain/doctor.js +497 -0
  59. package/dist/commands/brain/edit-lesson.d.ts +51 -0
  60. package/dist/commands/brain/edit-lesson.js +248 -0
  61. package/dist/commands/brain/import-snapshot.d.ts +68 -0
  62. package/dist/commands/brain/import-snapshot.js +177 -0
  63. package/dist/commands/brain/index.d.ts +2 -0
  64. package/dist/commands/brain/index.js +67 -0
  65. package/dist/commands/brain/list.d.ts +21 -0
  66. package/dist/commands/brain/list.js +83 -0
  67. package/dist/commands/brain/migrate-projects.d.ts +44 -0
  68. package/dist/commands/brain/migrate-projects.js +209 -0
  69. package/dist/commands/brain/migrate.d.ts +74 -0
  70. package/dist/commands/brain/migrate.js +306 -0
  71. package/dist/commands/brain/new-project.d.ts +53 -0
  72. package/dist/commands/brain/new-project.js +226 -0
  73. package/dist/commands/brain/read.d.ts +24 -0
  74. package/dist/commands/brain/read.js +81 -0
  75. package/dist/commands/brain/remove-lesson.d.ts +47 -0
  76. package/dist/commands/brain/remove-lesson.js +206 -0
  77. package/dist/commands/brain/remove-project.d.ts +36 -0
  78. package/dist/commands/brain/remove-project.js +177 -0
  79. package/dist/commands/brain/retro-file-tasks.d.ts +84 -0
  80. package/dist/commands/brain/retro-file-tasks.js +372 -0
  81. package/dist/commands/brain/retro-list.d.ts +28 -0
  82. package/dist/commands/brain/retro-list.js +125 -0
  83. package/dist/commands/brain/retro-mark-change.d.ts +58 -0
  84. package/dist/commands/brain/retro-mark-change.js +176 -0
  85. package/dist/commands/brain/retro-remove.d.ts +36 -0
  86. package/dist/commands/brain/retro-remove.js +142 -0
  87. package/dist/commands/brain/retro-respond.d.ts +56 -0
  88. package/dist/commands/brain/retro-respond.js +250 -0
  89. package/dist/commands/brain/retro-show.d.ts +23 -0
  90. package/dist/commands/brain/retro-show.js +100 -0
  91. package/dist/commands/brain/retro-start.d.ts +55 -0
  92. package/dist/commands/brain/retro-start.js +311 -0
  93. package/dist/commands/brain/search.d.ts +48 -0
  94. package/dist/commands/brain/search.js +190 -0
  95. package/dist/commands/brain/snapshot.d.ts +32 -0
  96. package/dist/commands/brain/snapshot.js +243 -0
  97. package/dist/commands/brain/status.d.ts +15 -0
  98. package/dist/commands/brain/status.js +166 -0
  99. package/dist/commands/brain/subscribe.d.ts +28 -0
  100. package/dist/commands/brain/subscribe.js +90 -0
  101. package/dist/commands/brain/tag.d.ts +46 -0
  102. package/dist/commands/brain/tag.js +192 -0
  103. package/dist/index.d.ts +17 -0
  104. package/dist/index.js +22 -0
  105. package/dist/lib/brain-daemon.d.ts +126 -0
  106. package/dist/lib/brain-daemon.js +811 -0
  107. package/dist/lib/brain-membership.d.ts +58 -0
  108. package/dist/lib/brain-membership.js +115 -0
  109. package/dist/lib/brain-migrate-projects.d.ts +43 -0
  110. package/dist/lib/brain-migrate-projects.js +247 -0
  111. package/dist/lib/brain-migrate.d.ts +77 -0
  112. package/dist/lib/brain-migrate.js +328 -0
  113. package/dist/lib/brain-ops.d.ts +271 -0
  114. package/dist/lib/brain-ops.js +571 -0
  115. package/dist/lib/brain-paths.d.ts +15 -0
  116. package/dist/lib/brain-paths.js +33 -0
  117. package/dist/lib/brain-projections.d.ts +216 -0
  118. package/dist/lib/brain-projections.js +829 -0
  119. package/dist/lib/brain-schemas.d.ts +36 -0
  120. package/dist/lib/brain-schemas.js +316 -0
  121. package/dist/lib/brain-signing.d.ts +103 -0
  122. package/dist/lib/brain-signing.js +256 -0
  123. package/dist/lib/brain.d.ts +198 -0
  124. package/dist/lib/brain.js +1057 -0
  125. package/dist/pop-agent.d.ts +1 -0
  126. package/dist/pop-agent.js +18 -0
  127. package/docs/agent.md +126 -0
  128. package/docs/agents/brain-anti-entropy.md +127 -0
  129. package/docs/agents/brain-cross-device-onboarding.md +210 -0
  130. package/docs/agents/brain-cross-machine-smoke.md +241 -0
  131. package/docs/agents/brain-layer-setup.md +725 -0
  132. package/docs/agents/offboarding-protocol.md +188 -0
  133. package/docs/agents/onboarding-protocol.md +243 -0
  134. package/docs/agents/running-an-agent.md +200 -0
  135. package/docs/brain.md +560 -0
  136. package/package.json +61 -0
  137. package/scripts/apply.sh +140 -0
  138. package/scripts/onboard.sh +205 -0
  139. package/scripts/setup-agent.ts +272 -0
@@ -0,0 +1,241 @@
1
+ # Cross-Machine Brain Smoke Test — Runbook
2
+
3
+ *Closes PR #9 cross-machine blocker #5 into a runnable state. The code plumbing from [sprint-3 `386e034`](../../../../ACTIVE_AGENT_BRANCH.md) is in place — this document is the instrument that tells you whether it actually works end-to-end against two real boxes.*
4
+
5
+ **Status — experimental**: the underlying libp2p stack (persistent PeerId + public bootstrap + Circuit Relay v2 + AutoNAT) is wired and unit-tested. What is NOT yet verified is that two agents on separate residential networks can discover each other via the public DHT and propagate a brain change end-to-end. This runbook is what you run when you have a second machine available.
6
+
7
+ For the operator-first setup guide (single-machine boot, persistent-PeerId verification, local write test), see [`docs/agents/brain-layer-setup.md`](./brain-layer-setup.md) first.
8
+
9
+ ---
10
+
11
+ ## Prerequisites
12
+
13
+ Both machines need:
14
+
15
+ - **Repo on `agent/sprint-3`**. Check `ACTIVE_AGENT_BRANCH.md` at the repo root.
16
+ ```bash
17
+ git fetch origin
18
+ git checkout agent/sprint-3
19
+ yarn install
20
+ yarn build
21
+ ```
22
+ - **`POP_PRIVATE_KEY`** — a hex wallet private key that signs the envelope. A throwaway key is fine for testing, but the signing address must be in `agent/brain/Config/brain-allowlist.json` on both machines for the publish side's writes to be ACCEPTED by the subscriber side. Use `pop brain allowlist add --address 0x<publisher-addr>` if needed; that edit only needs to land before the verify step runs.
23
+ - **`POP_BRAIN_HOME`** — distinct per machine (or per terminal session). Default is `~/.pop-agent/brain`. Set it explicitly for each test run so state is isolated:
24
+ ```bash
25
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-A # machine A
26
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-B # machine B
27
+ ```
28
+ - **Node 18+** on both machines.
29
+
30
+ ---
31
+
32
+ ## The script
33
+
34
+ A single parameterized script handles all three roles:
35
+
36
+ ```bash
37
+ node test/scripts/brain-cross-machine-smoke.js
38
+ ```
39
+
40
+ The `ROLE` env var picks behavior:
41
+
42
+ | Role | What it does |
43
+ |---|---|
44
+ | `subscribe` | Boot a brain node, print the listening multiaddrs in copy-paste-ready form, subscribe to `test.xmachine`, wait forever logging inbound announcements. Ctrl-C to exit. |
45
+ | `publish` | Boot a DIFFERENT brain home, optionally dial `SUBSCRIBER_ADDR`, wait for peer discovery, subscribe to the same topic, apply a signed brain change with a **known tag** (`xmachine-<unix>-<hostname>`), linger 15s for Bitswap delivery, exit. |
46
+ | `verify` | Read the local doc, check whether any lesson matching `XMACHINE_TAG` exists. Exit 0 (PASS) or 1 (FAIL). |
47
+
48
+ ---
49
+
50
+ ## Scenario 1: LAN + explicit dial (known-working baseline)
51
+
52
+ This proves the substrate is functional before any WAN scenario. If this doesn't work, nothing else will.
53
+
54
+ **Machine A — subscribe:**
55
+
56
+ ```bash
57
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-A
58
+ export POP_PRIVATE_KEY=0x<A-key>
59
+ ROLE=subscribe node test/scripts/brain-cross-machine-smoke.js
60
+ ```
61
+
62
+ Expected output:
63
+ ```
64
+ [subscribe] role=subscribe doc=test.xmachine home=/tmp/brain-xmachine-A
65
+ [subscribe] local peer: 12D3KooW<...>
66
+ [subscribe] listening multiaddrs — copy the one the peer should dial:
67
+ /ip4/127.0.0.1/tcp/<port>/p2p/12D3KooW<...>
68
+ /ip4/<LAN-addr>/tcp/<port>/p2p/12D3KooW<...>
69
+
70
+ [subscribe] subscribing to brain topic for "test.xmachine" — waiting for announcements...
71
+ ```
72
+
73
+ Copy the `/ip4/<LAN-addr>/...` multiaddr (NOT the 127.0.0.1 one unless both machines are on localhost).
74
+
75
+ **Machine B — publish:**
76
+
77
+ ```bash
78
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-B
79
+ export POP_PRIVATE_KEY=0x<B-key>
80
+ export SUBSCRIBER_ADDR=/ip4/<A-LAN-addr>/tcp/<port>/p2p/12D3KooW<...>
81
+ ROLE=publish node test/scripts/brain-cross-machine-smoke.js
82
+ ```
83
+
84
+ Expected output:
85
+ ```
86
+ [publish] explicit dial to /ip4/.../tcp/.../p2p/...
87
+ [publish] dial succeeded
88
+ [publish] subscribing to test.xmachine topic to form the gossipsub mesh...
89
+ [publish] applying brain change: title=xmachine-<unix>-<hostname>
90
+ [publish] new head CID: bafkrei<...>
91
+ [publish] envelope signer: 0x<B-addr>
92
+ [publish] lingering 15s for bitswap delivery...
93
+ [publish] DONE.
94
+ ```
95
+
96
+ Machine A (subscribe) should log a `head <cid> from <B peerId>` line within ~2 seconds of the publish.
97
+
98
+ **Machine A — verify** (in a separate terminal):
99
+
100
+ ```bash
101
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-A
102
+ export XMACHINE_TAG=xmachine-<unix>-<hostname-from-publish-output>
103
+ ROLE=verify node test/scripts/brain-cross-machine-smoke.js
104
+ ```
105
+
106
+ Expected: `[verify] PASS — cross-machine lesson propagated`.
107
+
108
+ ---
109
+
110
+ ## Scenario 2: LAN + mDNS (known flaky on macOS)
111
+
112
+ Same machines, same network, but **no explicit dial**. This tests whether mDNS can auto-discover peers.
113
+
114
+ **Machine A:** unchanged from scenario 1.
115
+
116
+ **Machine B:** same as scenario 1 but WITHOUT `SUBSCRIBER_ADDR`:
117
+ ```bash
118
+ unset SUBSCRIBER_ADDR
119
+ ROLE=publish node test/scripts/brain-cross-machine-smoke.js
120
+ ```
121
+
122
+ Expected: the publish side prints `[publish] t+3s connected peers: 0 ...` progress lines for up to 30s before giving up. If `connected peers` goes to 1+ within the window, mDNS worked. If it stays at 0 the whole time, mDNS is blocked (common on macOS — this is the documented flaky path).
123
+
124
+ Regardless of mDNS success, the publish will still attempt to apply the change. Whether machine A actually receives it depends on whether gossipsub mesh formed, which depends on whether peer discovery succeeded.
125
+
126
+ **This scenario is NOT expected to work reliably on macOS.** Log the result either way — a pass is newsworthy, a fail is the expected state.
127
+
128
+ ---
129
+
130
+ ## Scenario 3: WAN + bootstrap DHT only (experimental — the main test)
131
+
132
+ This is the one we actually want to work. Two machines on separate residential networks, no direct dial, no mDNS. Both peers need to find each other via the Protocol Labs public IPFS bootstrap peers + libp2p DHT.
133
+
134
+ **Machine A** (may or may not be behind NAT):
135
+ ```bash
136
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-A
137
+ export POP_PRIVATE_KEY=0x<A-key>
138
+ ROLE=subscribe node test/scripts/brain-cross-machine-smoke.js
139
+ ```
140
+
141
+ Let it run for **at least 60 seconds** before introducing machine B — the bootstrap DNS records take time to resolve and the DHT takes time to populate.
142
+
143
+ **Machine B** (no `SUBSCRIBER_ADDR`):
144
+ ```bash
145
+ export POP_BRAIN_HOME=/tmp/brain-xmachine-B
146
+ export POP_PRIVATE_KEY=0x<B-key>
147
+ unset SUBSCRIBER_ADDR
148
+ ROLE=publish node test/scripts/brain-cross-machine-smoke.js
149
+ ```
150
+
151
+ Expected (if it works):
152
+ - `[publish] t+3s connected peers: 0` → `[publish] t+6s connected peers: 1+` within 30 seconds.
153
+ - Machine A logs the head announcement.
154
+ - `ROLE=verify` on A returns PASS.
155
+
156
+ Expected (if it doesn't work — which is honest uncertainty as of sprint-3):
157
+ - `[publish] t+30s connected peers: 0`. No discovery.
158
+ - Publish still completes locally (the brain layer writes are signed and persisted regardless of network state), but the announcement never reaches machine A.
159
+ - `ROLE=verify` on A returns FAIL.
160
+
161
+ If scenario 3 fails, go to the **diagnostic capture** section and grab the evidence.
162
+
163
+ ---
164
+
165
+ ## Scenario 4: WAN + Circuit Relay v2 (NAT hole-punch case)
166
+
167
+ This is the hardest case: both machines behind residential NAT, no direct reachability, must use a public Circuit Relay v2 node as an intermediary. The sprint-3 wiring includes `circuitRelayTransport()` for exactly this.
168
+
169
+ Setup is the same as scenario 3. What differs is the evidence of success:
170
+
171
+ - Machine A's `pop brain status --json` should list at least one `listeningAddrs` entry containing `/p2p-circuit/` within 60-120 seconds of startup. That's the AutoNAT-detected relay-reachable address.
172
+ - Machine B's dial should succeed through the relay without `SUBSCRIBER_ADDR` being set.
173
+
174
+ If `pop brain status --json` on A never shows a `/p2p-circuit/` entry, AutoNAT didn't find a usable relay, and scenario 4 won't work regardless of what B does. Check `POP_BRAIN_DEBUG=1` for warnings.
175
+
176
+ ---
177
+
178
+ ## Diagnostic capture (if any scenario fails)
179
+
180
+ Grab the following from **both** machines and include them in a bug report:
181
+
182
+ ```bash
183
+ # Local state — peer store, listening addrs, topic membership
184
+ pop brain status --json > /tmp/brain-status-<hostname>.json
185
+
186
+ # Local brain doc state
187
+ pop brain list > /tmp/brain-list-<hostname>.txt
188
+ pop brain read --doc test.xmachine --json > /tmp/brain-read-<hostname>.json
189
+
190
+ # libp2p debug logs — re-run the script with this in the environment
191
+ DEBUG='libp2p:*,@chainsafe/libp2p-gossipsub:*' ROLE=... node test/scripts/brain-cross-machine-smoke.js 2>&1 | tee /tmp/libp2p-debug-<hostname>.log
192
+ ```
193
+
194
+ Useful on-host tcpdump (if you have root):
195
+
196
+ ```bash
197
+ # libp2p default TCP port is random; grep it from `pop brain status --json`
198
+ sudo tcpdump -i any -w /tmp/brain-pcap-<hostname>.pcap 'tcp port <port-from-status>'
199
+ ```
200
+
201
+ **The single most useful datum**: `getPeers()` and `getSubscribers(topic)` values from both peers' gossipsub state. If peers see each other in `getPeers()` but NOT in `getSubscribers(topic)`, the gossipsub mesh is failing to form — which was the exact failure mode of the libp2p 3.x + gossipsub 14 silent-break caught in HB#268. If peers don't appear in `getPeers()` at all, discovery is failing upstream.
202
+
203
+ ---
204
+
205
+ ## Known-good verification (what "it works" looks like)
206
+
207
+ All of the following must be true after scenario 3 runs successfully:
208
+
209
+ 1. **Publish side** prints `[publish] new head CID: bafkrei<X>` and exits 0.
210
+ 2. **Subscribe side** prints an incoming `head <X> from <B-peerId>` line within ~5 seconds of the publish (the CID `X` matches).
211
+ 3. **Verify on subscribe side** (`ROLE=verify`) prints `[verify] PASS — cross-machine lesson propagated` with the lesson's `id`, `author`, `ts` in the output, and exits 0.
212
+ 4. `pop brain read --doc test.xmachine --json` on the subscribe side shows the lesson in `doc.lessons[]` with `author=<publish-hostname>` and `title=xmachine-<unix>-<hostname>`.
213
+ 5. The subscribe side's `pop brain list` shows `test.xmachine` with the same head CID as the publish side.
214
+
215
+ If 1–4 all pass but 5 shows a different head, run `pop brain snapshot --doc test.xmachine` and re-check — the manifest may just be stale.
216
+
217
+ ---
218
+
219
+ ## Running the publish + verify loop on a single machine (local sanity)
220
+
221
+ Before sending this runbook to a second-machine operator, sanity-check the script end-to-end on the local machine:
222
+
223
+ ```bash
224
+ yarn build
225
+ yarn test:xmachine-smoke # publish + verify against /tmp/brain-xmachine-loopback
226
+ ```
227
+
228
+ The `test:xmachine-smoke` npm script wraps ROLE=publish and ROLE=verify back-to-back with the same `POP_BRAIN_HOME` (so it's essentially just testing local write + read — NOT cross-machine, but it proves the script's plumbing works before you run it remotely).
229
+
230
+ ---
231
+
232
+ ## What to file if it fails
233
+
234
+ Open a GitHub issue with:
235
+
236
+ - Which scenario (1/2/3/4)
237
+ - Both machines' `brain-status-<hostname>.json` files
238
+ - Both machines' `libp2p-debug-<hostname>.log` files (tail, not full — last 500 lines is plenty)
239
+ - Expected vs actual (success from each side's perspective)
240
+
241
+ If scenario 3 passes, **remove the `experimental` / `untested` tags** from `docs/agents/brain-layer-setup.md` §8 and from this file's header. That flip is the real close of PR #9 cross-machine blocker #5.