elanous 0.2.12 → 0.2.13

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 (289) hide show
  1. package/apps/pwa/out/404/index.html +1 -1
  2. package/apps/pwa/out/404.html +1 -1
  3. package/apps/pwa/out/_next/static/chunks/{1394-ee3795b112907122.js → 1394-931c9827067b2276.js} +1 -1
  4. package/apps/pwa/out/_next/static/chunks/{3992-2e522a8ac5f2afde.js → 3992-fe5c06d6b31f8b25.js} +1 -1
  5. package/apps/pwa/out/_next/static/chunks/5250-c78ca295585bbf95.js +1 -0
  6. package/apps/pwa/out/_next/static/chunks/6511-ff8360be3d65aaa4.js +1 -0
  7. package/apps/pwa/out/_next/static/chunks/6588-ba380869b67c4fa7.js +1 -0
  8. package/apps/pwa/out/_next/static/chunks/{7758-0b018a9e4fc56200.js → 7758-85c2b53f731da024.js} +1 -1
  9. package/apps/pwa/out/_next/static/chunks/{8605-0259994816604c49.js → 8605-9da4678f8a310d18.js} +1 -1
  10. package/apps/pwa/out/_next/static/chunks/9906-e7b8b5310a169dfe.js +1 -0
  11. package/apps/pwa/out/_next/static/chunks/app/approvals/{page-cb169620945d1952.js → page-e5b4e1b256f41076.js} +1 -1
  12. package/apps/pwa/out/_next/static/chunks/app/autopilot/{page-cefe8169e36cf62a.js → page-e49b9b76c565a0b1.js} +1 -1
  13. package/apps/pwa/out/_next/static/chunks/app/board/page-b4f032c893b21cc9.js +1 -0
  14. package/apps/pwa/out/_next/static/chunks/app/botlab/page-f14987d5850a31e0.js +1 -0
  15. package/apps/pwa/out/_next/static/chunks/app/bots/page-b433308aad13ceb6.js +1 -0
  16. package/apps/pwa/out/_next/static/chunks/app/chat/{page-813c4a52c9d05ca8.js → page-4c1dbb21861beab2.js} +1 -1
  17. package/apps/pwa/out/_next/static/chunks/app/consult/{page-4731f2c215358937.js → page-c85b816e3b269dbb.js} +1 -1
  18. package/apps/pwa/out/_next/static/chunks/app/control/{page-a022b257950f39e6.js → page-f6bc66b919b2ea7d.js} +1 -1
  19. package/apps/pwa/out/_next/static/chunks/app/design-check/{page-a2ffc717e04b8b0a.js → page-60603c1e056c9b25.js} +1 -1
  20. package/apps/pwa/out/_next/static/chunks/app/editor/{page-b59ee4e70fc18fcf.js → page-a0ea8f5a2341ee6b.js} +1 -1
  21. package/apps/pwa/out/_next/static/chunks/app/exec/page-45c5bf04b4a605e6.js +1 -0
  22. package/apps/pwa/out/_next/static/chunks/app/field/{page-c172dabd796eb7a3.js → page-36c6c4183353ac9e.js} +1 -1
  23. package/apps/pwa/out/_next/static/chunks/app/inside/{page-1efd0cb9e0ed9d13.js → page-cb2eb0fd809980da.js} +1 -1
  24. package/apps/pwa/out/_next/static/chunks/app/intake/{page-d5dc7ff69a37b4cf.js → page-31012264da8a341f.js} +1 -1
  25. package/apps/pwa/out/_next/static/chunks/app/layout-50309aeb0bdd554a.js +1 -0
  26. package/apps/pwa/out/_next/static/chunks/app/live/page-bc00e964e855f4df.js +1 -0
  27. package/apps/pwa/out/_next/static/chunks/app/market/{page-dfca9b7d2de0b135.js → page-0696ee3fac9fe56c.js} +1 -1
  28. package/apps/pwa/out/_next/static/chunks/app/missions/[id]/{page-793fa536b3a6ef37.js → page-66c27608f651b866.js} +1 -1
  29. package/apps/pwa/out/_next/static/chunks/app/morning/{page-6dd3bfbbde2a5c2c.js → page-6ddd2109b7fc3a80.js} +1 -1
  30. package/apps/pwa/out/_next/static/chunks/app/not-found-4e50b7298c1f69a5.js +1 -0
  31. package/apps/pwa/out/_next/static/chunks/app/observatory/{page-77447356baad75d2.js → page-7a2bf830038a2264.js} +1 -1
  32. package/apps/pwa/out/_next/static/chunks/app/ops/checklist/page-1f327f18694fabca.js +1 -0
  33. package/apps/pwa/out/_next/static/chunks/app/ops/release/page-e5cef2fe6e4028df.js +1 -0
  34. package/apps/pwa/out/_next/static/chunks/app/ops/seats/page-cf596128d2b420ba.js +1 -0
  35. package/apps/pwa/out/_next/static/chunks/app/outputs/{page-6d604227e1664b71.js → page-f672536f14f0969f.js} +1 -1
  36. package/apps/pwa/out/_next/static/chunks/app/page-b52365662232db89.js +1 -0
  37. package/apps/pwa/out/_next/static/chunks/app/reflection/{page-4048543b4b7ad5e0.js → page-e7a6c80f288b1948.js} +1 -1
  38. package/apps/pwa/out/_next/static/chunks/app/scheduler/{page-4c3a3126abed551a.js → page-29a709616df9b050.js} +1 -1
  39. package/apps/pwa/out/_next/static/chunks/app/sessions/{page-64b0aecb1ca75e75.js → page-fee842d7c2151129.js} +1 -1
  40. package/apps/pwa/out/_next/static/chunks/app/settings/devices/page-78b40a344ed22f24.js +1 -0
  41. package/apps/pwa/out/_next/static/chunks/app/settings/page-75d199f448171014.js +1 -0
  42. package/apps/pwa/out/_next/static/chunks/app/setup/done/page-a011dd5b0bff29c5.js +1 -0
  43. package/apps/pwa/out/_next/static/chunks/app/setup/{page-9547b5cec7cf76bf.js → page-d92e32d51ab5157e.js} +1 -1
  44. package/apps/pwa/out/_next/static/chunks/app/share/page-5f21aed6932ef375.js +1 -0
  45. package/apps/pwa/out/_next/static/chunks/app/showroom/page-1e1a53946804debf.js +1 -0
  46. package/apps/pwa/out/_next/static/chunks/app/tasks/{page-2cddeb9e2aeedc55.js → page-a1833cd43d832601.js} +1 -1
  47. package/apps/pwa/out/_next/static/chunks/app/term/{page-e297866051595d81.js → page-63d14a4d8fe1e1c1.js} +1 -1
  48. package/apps/pwa/out/_next/static/chunks/app/today/{page-baba2e047872fb0f.js → page-2a511d320f762e06.js} +1 -1
  49. package/apps/pwa/out/_next/static/chunks/app/trace/{page-e895da4ec9cac345.js → page-1c3e03f88dac1e21.js} +1 -1
  50. package/apps/pwa/out/_next/static/chunks/app/vault/page-c4d5289c2ea97a89.js +1 -0
  51. package/apps/pwa/out/_next/static/chunks/app/workflows/chat-ui/page-b91f8952deaeaf27.js +1 -0
  52. package/apps/pwa/out/_next/static/chunks/app/workflows/page-71b43a2588489987.js +1 -0
  53. package/apps/pwa/out/_next/static/chunks/app/workspace/{page-2e9e2fb01c9da1c9.js → page-2b256feed331546f.js} +1 -1
  54. package/apps/pwa/out/_next/static/chunks/app/worktrees/{page-d62ceb13411ebba4.js → page-505bb96d69a8622c.js} +1 -1
  55. package/apps/pwa/out/approvals/index.html +1 -1
  56. package/apps/pwa/out/approvals/index.txt +13 -13
  57. package/apps/pwa/out/autopilot/index.html +1 -1
  58. package/apps/pwa/out/autopilot/index.txt +13 -13
  59. package/apps/pwa/out/board/index.html +1 -1
  60. package/apps/pwa/out/board/index.txt +13 -13
  61. package/apps/pwa/out/botlab/index.html +1 -1
  62. package/apps/pwa/out/botlab/index.txt +13 -13
  63. package/apps/pwa/out/bots/index.html +1 -1
  64. package/apps/pwa/out/bots/index.txt +13 -13
  65. package/apps/pwa/out/chat/index.html +1 -1
  66. package/apps/pwa/out/chat/index.txt +13 -13
  67. package/apps/pwa/out/consult/index.html +1 -1
  68. package/apps/pwa/out/consult/index.txt +13 -13
  69. package/apps/pwa/out/control/index.html +1 -1
  70. package/apps/pwa/out/control/index.txt +13 -13
  71. package/apps/pwa/out/design-check/index.html +1 -1
  72. package/apps/pwa/out/design-check/index.txt +13 -13
  73. package/apps/pwa/out/editor/index.html +1 -1
  74. package/apps/pwa/out/editor/index.txt +13 -13
  75. package/apps/pwa/out/exec/index.html +1 -1
  76. package/apps/pwa/out/exec/index.txt +13 -13
  77. package/apps/pwa/out/field/index.html +1 -1
  78. package/apps/pwa/out/field/index.txt +13 -13
  79. package/apps/pwa/out/healthz +1 -1
  80. package/apps/pwa/out/index.html +1 -1
  81. package/apps/pwa/out/index.txt +13 -13
  82. package/apps/pwa/out/inside/index.html +1 -1
  83. package/apps/pwa/out/inside/index.txt +13 -13
  84. package/apps/pwa/out/intake/index.html +1 -1
  85. package/apps/pwa/out/intake/index.txt +13 -13
  86. package/apps/pwa/out/live/index.html +1 -1
  87. package/apps/pwa/out/live/index.txt +13 -13
  88. package/apps/pwa/out/market/index.html +1 -1
  89. package/apps/pwa/out/market/index.txt +13 -13
  90. package/apps/pwa/out/missions/placeholder/index.html +1 -1
  91. package/apps/pwa/out/missions/placeholder/index.txt +13 -13
  92. package/apps/pwa/out/morning/index.html +1 -1
  93. package/apps/pwa/out/morning/index.txt +13 -13
  94. package/apps/pwa/out/observatory/index.html +1 -1
  95. package/apps/pwa/out/observatory/index.txt +13 -13
  96. package/apps/pwa/out/ops/checklist/index.html +1 -1
  97. package/apps/pwa/out/ops/checklist/index.txt +13 -13
  98. package/apps/pwa/out/ops/release/index.html +1 -1
  99. package/apps/pwa/out/ops/release/index.txt +13 -13
  100. package/apps/pwa/out/ops/seats/index.html +1 -1
  101. package/apps/pwa/out/ops/seats/index.txt +13 -13
  102. package/apps/pwa/out/outputs/index.html +1 -1
  103. package/apps/pwa/out/outputs/index.txt +13 -13
  104. package/apps/pwa/out/reflection/index.html +1 -1
  105. package/apps/pwa/out/reflection/index.txt +14 -14
  106. package/apps/pwa/out/scheduler/index.html +1 -1
  107. package/apps/pwa/out/scheduler/index.txt +13 -13
  108. package/apps/pwa/out/sessions/index.html +1 -1
  109. package/apps/pwa/out/sessions/index.txt +13 -13
  110. package/apps/pwa/out/settings/devices/index.html +1 -1
  111. package/apps/pwa/out/settings/devices/index.txt +13 -13
  112. package/apps/pwa/out/settings/index.html +1 -1
  113. package/apps/pwa/out/settings/index.txt +13 -13
  114. package/apps/pwa/out/setup/done/index.html +1 -1
  115. package/apps/pwa/out/setup/done/index.txt +13 -13
  116. package/apps/pwa/out/setup/index.html +1 -1
  117. package/apps/pwa/out/setup/index.txt +13 -13
  118. package/apps/pwa/out/share/index.html +1 -1
  119. package/apps/pwa/out/share/index.txt +13 -13
  120. package/apps/pwa/out/showroom/index.html +1 -1
  121. package/apps/pwa/out/showroom/index.txt +13 -13
  122. package/apps/pwa/out/tasks/index.html +1 -1
  123. package/apps/pwa/out/tasks/index.txt +13 -13
  124. package/apps/pwa/out/term/index.html +1 -1
  125. package/apps/pwa/out/term/index.txt +13 -13
  126. package/apps/pwa/out/today/index.html +1 -1
  127. package/apps/pwa/out/today/index.txt +13 -13
  128. package/apps/pwa/out/trace/index.html +1 -1
  129. package/apps/pwa/out/trace/index.txt +13 -13
  130. package/apps/pwa/out/vault/index.html +1 -1
  131. package/apps/pwa/out/vault/index.txt +13 -13
  132. package/apps/pwa/out/workflows/chat-ui/index.html +1 -1
  133. package/apps/pwa/out/workflows/chat-ui/index.txt +13 -13
  134. package/apps/pwa/out/workflows/index.html +1 -1
  135. package/apps/pwa/out/workflows/index.txt +13 -13
  136. package/apps/pwa/out/workspace/index.html +1 -1
  137. package/apps/pwa/out/workspace/index.txt +13 -13
  138. package/apps/pwa/out/worktrees/index.html +1 -1
  139. package/apps/pwa/out/worktrees/index.txt +13 -13
  140. package/examples/teams/personas/backend.yaml +4 -0
  141. package/examples/teams/personas/pm.yaml +4 -0
  142. package/examples/teams/personas/qa.yaml +4 -0
  143. package/examples/teams/small-product.yaml +20 -0
  144. package/graphs/lecture/lecture-note.yaml +28 -0
  145. package/graphs/lecture/recipes.yaml +17 -0
  146. package/package.json +2 -1
  147. package/scripts/context-hooks/emit.ts +36 -14
  148. package/scripts/coord-channel-watch.sh +1 -0
  149. package/scripts/discord-seat-probe.ts +144 -0
  150. package/scripts/hq/hq-standby.sh +65 -0
  151. package/scripts/hq/standby-promote.ts +173 -0
  152. package/scripts/hq/standby-role.ts +59 -0
  153. package/scripts/hq/standby-snapshot.ts +226 -0
  154. package/scripts/hq/standby-verify.ts +219 -0
  155. package/scripts/lecture-note/node.ts +256 -0
  156. package/scripts/release-loop/gate-node.ts +53 -15
  157. package/scripts/release-loop/ops-upgrade-node.ts +17 -5
  158. package/scripts/test-deterministic.ts +53 -3
  159. package/skills/omni-crawl/SKILL.md +16 -16
  160. package/skills/omni-crawl/package-lock.json +1 -544
  161. package/skills/omni-crawl/package.json +3 -4
  162. package/skills/omni-crawl/scripts/main.ts +13 -13
  163. package/skills/omni-crawl/scripts/monitor.ts +8 -8
  164. package/skills/omni-crawl/src/apify.ts +13 -2
  165. package/skills/omni-crawl/src/capture.ts +6 -0
  166. package/skills/omni-crawl/src/registry.ts +2 -2
  167. package/skills/omni-crawl/src/stdout-json.ts +4 -0
  168. package/skills/omni-digest/SKILL.md +10 -11
  169. package/skills/omni-digest/package-lock.json +0 -545
  170. package/skills/omni-digest/package.json +2 -5
  171. package/skills/omni-digest/scripts/main.ts +3 -3
  172. package/skills/omni-digest/src/delegate.ts +5 -5
  173. package/skills/omni-digest/src/fetch.ts +2 -2
  174. package/skills/omni-digest/src/media.ts +25 -11
  175. package/skills/omni-digest/src/visual.ts +3 -2
  176. package/skills/omni-market/scripts/main.ts +1 -1
  177. package/skills/omni-market/scripts/stdout-json.ts +4 -0
  178. package/src/agent/identity-env.ts +11 -0
  179. package/src/agent-mission/driver.ts +12 -7
  180. package/src/agent-mission/duo.ts +94 -0
  181. package/src/agent-mission/pty-decision.ts +1 -1
  182. package/src/autopilot/track-agent-shadow.ts +2 -1
  183. package/src/autopilot/track-agent.ts +4 -1
  184. package/src/boot/daemon-prompt-request.ts +3 -0
  185. package/src/boot/daemon-prompt-turn.ts +6 -2
  186. package/src/boot/daemon-runtime.ts +48 -16
  187. package/src/cli/decisions-cli.ts +51 -19
  188. package/src/cli/outputs-cli.ts +92 -0
  189. package/src/cli/persona-cli.ts +29 -0
  190. package/src/cli/pod-cli.ts +10 -3
  191. package/src/cli/pr-cli.ts +15 -1
  192. package/src/cli/release-cli.ts +108 -28
  193. package/src/context-bus/condense.ts +194 -0
  194. package/src/context-bus/context-day.ts +82 -0
  195. package/src/context-bus/context-now-surfaces.ts +15 -2
  196. package/src/context-bus/long-term-memory.ts +118 -22
  197. package/src/context-bus/nightly-condense.ts +1 -1
  198. package/src/decisions/decision-cards.ts +13 -7
  199. package/src/decisions/decision-ledger.ts +43 -17
  200. package/src/graph-kinds/registry.ts +2 -2
  201. package/src/graph-runner/graph-approval-card.ts +2 -2
  202. package/src/graph-runner/graph-grow.ts +64 -11
  203. package/src/graph-runner/graph-tick.ts +9 -2
  204. package/src/graph-runner/runner.ts +81 -17
  205. package/src/harness/harness-cli-command.ts +27 -1
  206. package/src/harness/harness-queue-child.ts +37 -0
  207. package/src/harness/harness-queue.ts +306 -0
  208. package/src/hooks/github-shadow.ts +72 -2
  209. package/src/hooks/receiver.ts +4 -2
  210. package/src/hq/hq.ts +318 -0
  211. package/src/hq/lease.ts +210 -0
  212. package/src/hq/ledger-write-target.ts +41 -0
  213. package/src/index.ts +199 -7
  214. package/src/intake-plane/discord-seat-work.ts +13 -6
  215. package/src/intake-plane/linear-wish.ts +44 -0
  216. package/src/intake-plane/persona-answer.ts +5 -0
  217. package/src/intake-plane/telegram-seat-work.ts +13 -6
  218. package/src/intake-plane/wish-card.ts +1 -1
  219. package/src/loops/checker.ts +178 -0
  220. package/src/loops/loop-cli.ts +37 -3
  221. package/src/loops/observe.ts +49 -0
  222. package/src/loops/orchestrator/overlap.ts +141 -0
  223. package/src/loops/orchestrator/traffic.ts +150 -0
  224. package/src/loops/package/verify.ts +125 -0
  225. package/src/loops/verdict.ts +22 -0
  226. package/src/maturity/feature-maturity.ts +3 -3
  227. package/src/memory.ts +37 -4
  228. package/src/nexus/api/card-followup-route.ts +118 -0
  229. package/src/nexus/api/decisions-route.ts +68 -0
  230. package/src/nexus/api/http-server.ts +47 -0
  231. package/src/nexus/api/personas.ts +2 -1
  232. package/src/nexus/api/skill-exec-route.ts +97 -0
  233. package/src/persona/loader.ts +18 -0
  234. package/src/persona/persona-todo.ts +14 -9
  235. package/src/persona/presets.ts +2 -1
  236. package/src/persona/team.ts +105 -0
  237. package/src/persona/types.ts +4 -0
  238. package/src/pod-lease/host-lease.ts +130 -20
  239. package/src/release-loop/landed-but-yellow.ts +12 -0
  240. package/src/seat-dispatch/seat-ask.ts +57 -12
  241. package/src/seat-loop/seat-loop.ts +90 -16
  242. package/src/seat-loop/seat-pack.ts +127 -0
  243. package/src/self-dev/ask-launch-flow.ts +3 -0
  244. package/src/self-implement/l8-merge-queue.ts +157 -1
  245. package/src/steward/launch.ts +5 -1
  246. package/src/steward/readiness.ts +125 -0
  247. package/src/steward/rescue.ts +75 -0
  248. package/src/steward/triage.ts +48 -9
  249. package/src/task-cards/card-cli.ts +78 -0
  250. package/src/task-orchestrator/surfaces/pod-lease.ts +18 -6
  251. package/src/task-orchestrator/surfaces/pod-pool.ts +27 -10
  252. package/src/task-orchestrator/surfaces/self-implement-pod.ts +38 -8
  253. package/src/telegram-dispatch-forward.ts +1 -1
  254. package/src/telegram-fabric-plan.ts +90 -0
  255. package/src/telegram-project-command.ts +10 -4
  256. package/src/telegram.ts +5 -0
  257. package/src/tool-runtime/elanous-control-runtimes.ts +2 -1
  258. package/src/user-config.ts +94 -10
  259. package/src/version/packed-revision.json +1 -1
  260. package/src/workflow-runtime/executor.ts +4 -0
  261. package/src/workflow-runtime/node-catalog.ts +13 -0
  262. package/src/workflow-runtime/nodes/knowledge.ts +38 -0
  263. package/src/workflow-runtime/schema.ts +17 -1
  264. package/src/workflow-runtime/types.ts +13 -1
  265. package/apps/pwa/out/_next/static/chunks/1147-466ec15afacc1a65.js +0 -1
  266. package/apps/pwa/out/_next/static/chunks/7277-0b2fc7c16ba2d64b.js +0 -1
  267. package/apps/pwa/out/_next/static/chunks/9906-482c6619b3fdda20.js +0 -1
  268. package/apps/pwa/out/_next/static/chunks/9920-5cfdc5e8fd209825.js +0 -1
  269. package/apps/pwa/out/_next/static/chunks/app/board/page-d2e35228bc497119.js +0 -1
  270. package/apps/pwa/out/_next/static/chunks/app/botlab/page-5c05b0da4bc1392c.js +0 -1
  271. package/apps/pwa/out/_next/static/chunks/app/bots/page-e0ccdb576812b523.js +0 -1
  272. package/apps/pwa/out/_next/static/chunks/app/exec/page-a67e11ba962337b5.js +0 -1
  273. package/apps/pwa/out/_next/static/chunks/app/layout-e71c84189e8c683e.js +0 -1
  274. package/apps/pwa/out/_next/static/chunks/app/live/page-1d6a533ce5a6efcb.js +0 -1
  275. package/apps/pwa/out/_next/static/chunks/app/not-found-490653e8d4cc8852.js +0 -1
  276. package/apps/pwa/out/_next/static/chunks/app/ops/checklist/page-29e961191f6057df.js +0 -1
  277. package/apps/pwa/out/_next/static/chunks/app/ops/release/page-c822f55b884d9104.js +0 -1
  278. package/apps/pwa/out/_next/static/chunks/app/ops/seats/page-fa4ccfc432424e52.js +0 -1
  279. package/apps/pwa/out/_next/static/chunks/app/page-9c7e8f744a765daf.js +0 -1
  280. package/apps/pwa/out/_next/static/chunks/app/settings/devices/page-4292d0149020e8a7.js +0 -1
  281. package/apps/pwa/out/_next/static/chunks/app/settings/page-db14d0be7f1c460c.js +0 -1
  282. package/apps/pwa/out/_next/static/chunks/app/setup/done/page-e5d8072cd7cfef73.js +0 -1
  283. package/apps/pwa/out/_next/static/chunks/app/share/page-e6dcb83265530636.js +0 -1
  284. package/apps/pwa/out/_next/static/chunks/app/showroom/page-45248f08d6aecae5.js +0 -1
  285. package/apps/pwa/out/_next/static/chunks/app/vault/page-4344faf20216233b.js +0 -1
  286. package/apps/pwa/out/_next/static/chunks/app/workflows/chat-ui/page-698bb29f11864b89.js +0 -1
  287. package/apps/pwa/out/_next/static/chunks/app/workflows/page-bd6a6dc1ddc273f2.js +0 -1
  288. /package/apps/pwa/out/_next/static/{-6XrAoD3eU7NyMHAE4xPS → D51l8jUBplJrIpWvENsDK}/_buildManifest.js +0 -0
  289. /package/apps/pwa/out/_next/static/{-6XrAoD3eU7NyMHAE4xPS → D51l8jUBplJrIpWvENsDK}/_ssgManifest.js +0 -0
@@ -0,0 +1,105 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { parseDocument } from 'yaml';
4
+ import { parsePersonaYaml } from './loader.js';
5
+
6
+ export interface TeamMember {
7
+ persona: string;
8
+ title: string;
9
+ checklistTemplate: string[];
10
+ }
11
+
12
+ export interface TeamHandoff {
13
+ from: string;
14
+ to: string;
15
+ }
16
+
17
+ export interface TeamDefinition {
18
+ name: string;
19
+ members: TeamMember[];
20
+ handoffs: TeamHandoff[];
21
+ }
22
+
23
+ function mapping(value: unknown): value is Record<string, unknown> {
24
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
25
+ }
26
+
27
+ function fields(value: Record<string, unknown>, required: readonly string[], label: string): void {
28
+ for (const key of required) {
29
+ if (!Object.hasOwn(value, key)) throw new Error(`${label}.${key} is required`);
30
+ }
31
+ for (const key of Object.keys(value)) {
32
+ if (!required.includes(key)) throw new Error(`${label}.${key} is not a team schema field`);
33
+ }
34
+ }
35
+
36
+ function text(value: unknown, label: string): string {
37
+ if (typeof value !== 'string' || !value.trim()) throw new Error(`${label} must be a non-empty string`);
38
+ return value;
39
+ }
40
+
41
+ /** Read-only validation: resolve persona paths relative to the team file, not the caller's cwd. */
42
+ export function validateTeamFile(file: string): TeamDefinition {
43
+ const document = parseDocument(readFileSync(file, 'utf8'), { uniqueKeys: true });
44
+ if (document.errors.length) throw new Error(`invalid team YAML: ${document.errors[0]!.message}`);
45
+ const raw: unknown = document.toJS();
46
+ if (!mapping(raw)) throw new Error('team must be a YAML mapping');
47
+ fields(raw, ['name', 'members', 'handoffs'], 'team');
48
+ const name = text(raw.name, 'team.name');
49
+ if (!Array.isArray(raw.members) || raw.members.length === 0) {
50
+ throw new Error('team.members must be a non-empty list');
51
+ }
52
+ const titles = new Set<string>();
53
+ const personaIds = new Set<string>();
54
+ const members: TeamMember[] = raw.members.map((item: unknown, index: number) => {
55
+ const label = `team.members[${index}]`;
56
+ if (!mapping(item)) throw new Error(`${label} must be a mapping`);
57
+ fields(item, ['persona', 'title', 'checklistTemplate'], label);
58
+ const persona = text(item.persona, `${label}.persona`);
59
+ const title = text(item.title, `${label}.title`);
60
+ if (titles.has(title)) throw new Error(`duplicate team title: ${title}`);
61
+ titles.add(title);
62
+ if (!Array.isArray(item.checklistTemplate) || item.checklistTemplate.length === 0) {
63
+ throw new Error(`${label}.checklistTemplate must be a non-empty list of strings`);
64
+ }
65
+ const checklistTemplate = item.checklistTemplate.map((entry: unknown) => text(entry, `${label}.checklistTemplate item`));
66
+ const personaPath = resolve(dirname(file), persona);
67
+ let yaml: string;
68
+ try {
69
+ yaml = readFileSync(personaPath, 'utf8');
70
+ } catch (error) {
71
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') throw new Error(`persona not found: ${persona} (${title})`);
72
+ throw error;
73
+ }
74
+ const parsed = parsePersonaYaml(yaml, personaPath);
75
+ if (!parsed.ok) throw new Error(`invalid persona ${persona}: ${parsed.error.message}`);
76
+ if (parsed.profile.seat !== title) throw new Error(`persona seat mismatch: ${persona} requires seat ${title}`);
77
+ if (personaIds.has(parsed.profile.personaId)) throw new Error(`duplicate personaId: ${parsed.profile.personaId}`);
78
+ personaIds.add(parsed.profile.personaId);
79
+ return { persona, title, checklistTemplate };
80
+ });
81
+ if (!Array.isArray(raw.handoffs)) throw new Error('team.handoffs must be a list');
82
+ const handoffs: TeamHandoff[] = raw.handoffs.map((item: unknown, index: number) => {
83
+ const label = `team.handoffs[${index}]`;
84
+ if (!mapping(item)) throw new Error(`${label} must be a mapping`);
85
+ fields(item, ['from', 'to'], label);
86
+ const from = text(item.from, `${label}.from`);
87
+ const to = text(item.to, `${label}.to`);
88
+ if (!titles.has(from) || !titles.has(to)) throw new Error(`handoff references missing title: ${from} -> ${to}`);
89
+ return { from, to };
90
+ });
91
+ const edges = new Map([...titles].map((title) => [title, [] as string[]]));
92
+ for (const { from, to } of handoffs) edges.get(from)!.push(to);
93
+ const visiting = new Set<string>();
94
+ const visited = new Set<string>();
95
+ const visit = (title: string): void => {
96
+ if (visiting.has(title)) throw new Error(`handoff cycle at ${title}`);
97
+ if (visited.has(title)) return;
98
+ visiting.add(title);
99
+ for (const next of edges.get(title)!) visit(next);
100
+ visiting.delete(title);
101
+ visited.add(title);
102
+ };
103
+ for (const title of titles) visit(title);
104
+ return { name, members, handoffs };
105
+ }
@@ -19,6 +19,10 @@ export type PersonaBrand =
19
19
  export interface PersonaProfile {
20
20
  readonly personaId: string;
21
21
  readonly displayName: string;
22
+ /** Seat address (title, id or alias) represented by this persona. */
23
+ readonly seat?: string;
24
+ /** Per-persona JSONL todo filename in the state persona directory. */
25
+ readonly todo?: string;
22
26
  readonly description?: string;
23
27
 
24
28
  /** System prompt to prepend in LLM calls. Markdown text. May
@@ -2,12 +2,32 @@
2
2
  // in a per-user directory; a launch is admitted only while live leases stay under the pool's measured total.
3
3
  // Without this, independent CLI processes each measured an empty pool and all launched (review round 2 of #23212).
4
4
  import { spawnSync } from 'node:child_process';
5
- import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
5
+ import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
6
6
  import { tmpdir, userInfo } from 'node:os';
7
7
  import { join } from 'node:path';
8
8
  import { debug } from '../debug/log.js';
9
9
 
10
- export interface HostLeaseRecord { pid: number; startedAt: string; at: string }
10
+ export interface HostLeaseRecord { pid: number; startedAt: string; at: string; stage?: 'authoring' | 'job'; claimed?: boolean; job?: string; context?: string; namespace?: string }
11
+
12
+ export interface PendingJobIdentity { context: string; namespace: string; job: string }
13
+
14
+ /** Only the same cluster, namespace and Job can account for an existing host lease. */
15
+ export function leaseHasPendingPod(lease: HostLeaseRecord, pending: readonly PendingJobIdentity[]): boolean {
16
+ return lease.stage === 'job' && !!lease.context && !!lease.namespace && !!lease.job &&
17
+ pending.some((pod) => pod.context === lease.context && pod.namespace === lease.namespace && pod.job === lease.job);
18
+ }
19
+
20
+ export interface HostLeaseHandle {
21
+ (): void;
22
+ readonly id: string;
23
+ /** Job creation is not release: retain the lease until its Pod is observed Running or terminal. */
24
+ applied: (job: string, context: string, namespace: string) => void;
25
+ }
26
+
27
+ /** A Job without a Running/terminal Pod still occupies a host reservation. */
28
+ export function hostLeaseCounts(records: readonly HostLeaseRecord[]): { reserved: number; waitingJobs: number } {
29
+ return { reserved: records.filter((r) => r.stage !== 'job').length, waitingJobs: records.filter((r) => r.stage === 'job').length };
30
+ }
11
31
 
12
32
  export interface HostPoolLeaseOptions {
13
33
  /** Base directory — default `$TMPDIR/elanous-pod-leases-<uid>` (0700). */
@@ -53,8 +73,42 @@ export class HostPoolLease {
53
73
  this.staleLockMs = options.staleLockMs ?? 10_000;
54
74
  }
55
75
 
76
+ reservationIsOther(id: string): boolean {
77
+ if (!/^[A-Za-z0-9._-]+\.json$/.test(id)) return false;
78
+ try {
79
+ const record = JSON.parse(readFileSync(join(this.dir, id), 'utf8')) as HostLeaseRecord;
80
+ return record.stage === 'authoring' && Number.isSafeInteger(record.pid) && record.pid > 0 &&
81
+ typeof record.startedAt === 'string' && this.processStart(record.pid) === record.startedAt &&
82
+ (record.pid !== this.pid || record.startedAt !== this.selfStart());
83
+ } catch { return false; }
84
+ }
85
+
86
+ /** Transfer a reservation across the authoring → orchestrator process boundary. */
87
+ claim(id: string): HostLeaseHandle | null {
88
+ if (!/^[A-Za-z0-9._-]+\.json$/.test(id)) return null;
89
+ const file = join(this.dir, id);
90
+ const deadline = Date.now() + this.staleLockMs;
91
+ while (!this.lock()) {
92
+ if (Date.now() >= deadline) return null;
93
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
94
+ }
95
+ try {
96
+ if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
97
+ if (!this.ownStart) return null;
98
+ const original = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
99
+ if (original.stage !== 'authoring' || original.claimed || !Number.isSafeInteger(original.pid) || original.pid <= 0 ||
100
+ typeof original.startedAt !== 'string' || this.processStart(original.pid) !== original.startedAt) return null;
101
+ const record: HostLeaseRecord = { ...original, pid: this.pid, startedAt: this.ownStart, claimed: true };
102
+ this.replaceRecord(file, record);
103
+ return this.handle(file, record, id);
104
+ } catch { return null; }
105
+ finally { this.unlock(); }
106
+ }
107
+
56
108
  /** Live leases after removing stale ones (dead pid or a recycled pid whose start time differs). */
57
- live(): HostLeaseRecord[] {
109
+ live(): HostLeaseRecord[] { return this.readLive(false); }
110
+
111
+ private readLive(lockHeld: boolean): HostLeaseRecord[] {
58
112
  const out: HostLeaseRecord[] = [];
59
113
  let names: string[] = [];
60
114
  try { names = readdirSync(this.dir).filter((name) => name.endsWith('.json')); } catch { return out; }
@@ -62,50 +116,106 @@ export class HostPoolLease {
62
116
  const file = join(this.dir, name);
63
117
  let record: HostLeaseRecord | null = null;
64
118
  try { record = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord; } catch { record = null; }
65
- const alive = record && this.processStart(record.pid) === record.startedAt;
119
+ const alive = record && Number.isSafeInteger(record.pid) && record.pid > 0 && typeof record.startedAt === 'string'
120
+ && this.processStart(record.pid) === record.startedAt;
66
121
  if (record && alive) { out.push(record); continue; }
67
- try { unlinkSync(file); } catch { /* another process cleaned it */ }
68
- debug.log('pod.lease', 'host-lease-stale-cleared', { file: name, pid: record?.pid ?? null });
122
+ // A concurrent claim can replace the record while we check the original PID.
123
+ if (!lockHeld && !this.lock()) { if (record) out.push(record); continue; }
124
+ try {
125
+ let current: HostLeaseRecord | null;
126
+ try { current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord; } catch { current = null; }
127
+ if (current && Number.isSafeInteger(current.pid) && current.pid > 0 && typeof current.startedAt === 'string' &&
128
+ this.processStart(current.pid) === current.startedAt) { out.push(current); continue; }
129
+ try { unlinkSync(file); } catch { /* already cleaned */ }
130
+ debug.log('pod.lease', 'host-lease-stale-cleared', { file: name, pid: current?.pid ?? null });
131
+ } finally { if (!lockHeld) this.unlock(); }
69
132
  }
70
133
  return out;
71
134
  }
72
135
 
73
- /** Unapplied leases held by other processes — launches admitted elsewhere whose Job the cluster can't see yet. */
74
- othersPending(): number {
136
+ selfStart(): string | null {
75
137
  if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
76
- return this.live().filter((r) => !(r.pid === this.pid && r.startedAt === this.ownStart)).length;
138
+ return this.ownStart;
139
+ }
140
+
141
+ /** Reservations held by other processes while the cluster cannot yet observe them. */
142
+ othersPending(): number {
143
+ return this.live().filter((r) => !(r.pid === this.pid && r.startedAt === this.selfStart())).length;
77
144
  }
78
145
 
79
146
  /**
80
- * Under the host lock, take a lease only if `allowed(othersPending)` holds — the check and the write are one step,
81
- * so independent processes measuring the same empty pool cannot all pass. Null = refused or lock busy (retry later).
147
+ * Under the host lock, take a lease only if `allowed(pending)` holds — the check and the write are one step.
148
+ * By default pending excludes this process's permits (the local admission gate owns them); includeOwn
149
+ * counts every reservation for independent authoring launches from the same process.
150
+ * Null = refused or lock busy (retry later).
82
151
  */
83
- tryReserve(allowed: (othersPending: number) => boolean): (() => void) | null {
152
+ tryReserve(allowed: (othersPending: number) => boolean, includeOwn = false): HostLeaseHandle | null {
84
153
  try { mkdirSync(this.dir, { recursive: true, mode: 0o700 }); } catch { return null; }
85
154
  if (!this.lock()) return null;
86
155
  try {
87
156
  if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
88
157
  if (!this.ownStart) return null;
89
- const others = this.live().filter((r) => !(r.pid === this.pid && r.startedAt === this.ownStart)).length;
158
+ const others = this.readLive(true).filter((r) => includeOwn || !(r.pid === this.pid && r.startedAt === this.ownStart)).length;
90
159
  if (!allowed(others)) {
91
160
  debug.log('pod.lease', 'host-lease-refused', { othersPending: others });
92
161
  return null;
93
162
  }
94
163
  const file = join(this.dir, `${this.pid}-${this.now()}-${Math.random().toString(36).slice(2, 8)}.json`);
95
- const record: HostLeaseRecord = { pid: this.pid, startedAt: this.ownStart, at: new Date(this.now()).toISOString() };
164
+ const record: HostLeaseRecord = { pid: this.pid, startedAt: this.ownStart, at: new Date(this.now()).toISOString(), stage: 'authoring' };
96
165
  writeFileSync(file, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
97
166
  debug.log('pod.lease', 'host-lease-acquired', { othersPending: others });
98
- let released = false;
99
- return () => {
100
- if (released) return;
101
- released = true;
102
- try { unlinkSync(file); } catch { /* already cleaned */ }
103
- };
167
+ return this.handle(file, record, file.slice(this.dir.length + 1));
104
168
  } finally {
105
169
  this.unlock();
106
170
  }
107
171
  }
108
172
 
173
+ private replaceRecord(file: string, record: HostLeaseRecord): void {
174
+ const temp = `${file}.${this.pid}-${Math.random().toString(36).slice(2)}.tmp`;
175
+ try {
176
+ writeFileSync(temp, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
177
+ renameSync(temp, file);
178
+ } catch (error) {
179
+ try { unlinkSync(temp); } catch { /* already gone */ }
180
+ throw error;
181
+ }
182
+ }
183
+
184
+ private handle(file: string, record: HostLeaseRecord, id: string): HostLeaseHandle {
185
+ let released = false;
186
+ const release = (() => {
187
+ if (released) return;
188
+ // Claim replaces the same file under this lock. An old owner must not unlink a
189
+ // newly transferred reservation between reading and removing its record.
190
+ const deadline = Date.now() + this.staleLockMs;
191
+ while (!this.lock()) {
192
+ if (Date.now() >= deadline) return;
193
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
194
+ }
195
+ try {
196
+ const current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
197
+ if (current.pid === record.pid && current.startedAt === record.startedAt && current.claimed === record.claimed) unlinkSync(file);
198
+ } catch { /* transferred or already cleaned */ }
199
+ finally { released = true; this.unlock(); }
200
+ }) as HostLeaseHandle;
201
+ Object.defineProperty(release, 'id', { value: id });
202
+ release.applied = (job, context, namespace) => {
203
+ if (released) return;
204
+ const deadline = Date.now() + this.staleLockMs;
205
+ while (!this.lock()) {
206
+ if (Date.now() >= deadline) throw new Error('pod lease: cannot update Job reservation');
207
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
208
+ }
209
+ try {
210
+ const current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
211
+ if (current.pid !== record.pid || current.startedAt !== record.startedAt || current.claimed !== record.claimed) throw new Error('pod lease: reservation owner changed');
212
+ if (!job || !context || !namespace) throw new Error('pod lease: Job identity requires context, namespace and name');
213
+ this.replaceRecord(file, { ...record, stage: 'job', job, context, namespace });
214
+ } finally { this.unlock(); }
215
+ };
216
+ return release;
217
+ }
218
+
109
219
  private lockDir(): string { return join(this.dir, '.lock'); }
110
220
 
111
221
  private lock(): boolean {
@@ -11,6 +11,18 @@ export interface LandedButYellowRow {
11
11
  newer: boolean;
12
12
  }
13
13
 
14
+ export function evidencePlan(rows: readonly LandedButYellowRow[]): Array<{ id: string; ref: string }> {
15
+ const seen = new Set<string>();
16
+ return rows.flatMap((row) => row.prs.flatMap((pr, index) => {
17
+ if (pr.basis === 'mention' || row.alreadyInEvidence[index]) return [];
18
+ const ref = `#${pr.number}`;
19
+ const key = JSON.stringify([row.id, ref]);
20
+ if (seen.has(key)) return [];
21
+ seen.add(key);
22
+ return [{ id: row.id, ref }];
23
+ }));
24
+ }
25
+
14
26
  /** Prefer a dedicated body cell line over title evidence; incidental mentions only qualify for long ids. */
15
27
  export function landedButYellow(items: readonly ChecklistItem[], prs: readonly MergedChecklistPr[], { owner }: { owner?: string } = {}): LandedButYellowRow[] {
16
28
  const rows: LandedButYellowRow[] = [];
@@ -1,31 +1,58 @@
1
- import { randomUUID } from 'node:crypto';
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { join } from 'node:path';
2
3
  import { debug } from '../debug/log.js';
3
4
  import { openMsgStore, type MsgStore } from '../msg/msg-store.js';
4
5
  import { dispatchCeoTask, type CeoCommandDeps } from './ceo-commands.js';
6
+ import type { SeatId } from './seat-questions.js';
5
7
 
6
8
  export type AskOrigin =
7
9
  | { channel: 'telegram'; chatId: number | string; messageId: number; threadId?: number; botId?: string }
8
10
  | { channel: 'discord'; channelId: string; messageId: string; threadId?: string }
9
11
  | { channel: 'pwa'; clientId: string };
10
12
 
11
- export const DEFAULT_ASK_TIMEOUT_MS = 30 * 60 * 1000;
13
+ export const DEFAULT_ASK_TIMEOUT_MS = 2 * 60 * 60 * 1000;
12
14
  export const parseSeatAsk = (text: string): string | null => /^\s*CTO\s*에게\s*물어봐\s*[::]\s*(\S[\s\S]*)$/i.exec(text)?.[1]?.trim() ?? null;
13
15
 
14
- interface AskRow { id: string; seat: string; origin: string; deadline: number; timeout_minutes: number }
16
+ interface AskRow { id: string; seat: string; origin: string; deadline: number; timeout_minutes: number; answer: string | null; answered_at: number | null }
15
17
 
16
18
  function createTable(store: MsgStore): void {
17
19
  store.db.exec(`CREATE TABLE IF NOT EXISTS seat_asks (
18
20
  id TEXT PRIMARY KEY, seat TEXT NOT NULL, origin TEXT NOT NULL,
19
- deadline INTEGER NOT NULL, timeout_minutes INTEGER NOT NULL DEFAULT 30, status TEXT NOT NULL DEFAULT 'pending'
21
+ deadline INTEGER NOT NULL, timeout_minutes INTEGER NOT NULL DEFAULT 120, status TEXT NOT NULL DEFAULT 'pending',
22
+ answer TEXT, answered_at INTEGER
20
23
  ); CREATE TABLE IF NOT EXISTS seat_ask_outbox (
21
24
  id TEXT PRIMARY KEY, origin TEXT NOT NULL, text TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending',
22
25
  claim_until INTEGER NOT NULL DEFAULT 0, claim_token TEXT
23
26
  )`);
27
+ const askColumns = store.db.query('PRAGMA table_info(seat_asks)').all() as Array<{ name: string }>;
28
+ if (!askColumns.some(({ name }) => name === 'answer')) store.db.exec('ALTER TABLE seat_asks ADD COLUMN answer TEXT');
29
+ if (!askColumns.some(({ name }) => name === 'answered_at')) store.db.exec('ALTER TABLE seat_asks ADD COLUMN answered_at INTEGER');
24
30
  const columns = store.db.query('PRAGMA table_info(seat_ask_outbox)').all() as Array<{ name: string }>;
25
31
  if (!columns.some(({ name }) => name === 'claim_until')) store.db.exec('ALTER TABLE seat_ask_outbox ADD COLUMN claim_until INTEGER NOT NULL DEFAULT 0');
26
32
  if (!columns.some(({ name }) => name === 'claim_token')) store.db.exec('ALTER TABLE seat_ask_outbox ADD COLUMN claim_token TEXT');
27
33
  }
28
34
 
35
+ export interface SeatAskShadow {
36
+ from: SeatId;
37
+ to: SeatId;
38
+ itemId: string;
39
+ version: string;
40
+ question: string;
41
+ }
42
+
43
+ /** Keep an internal seat-to-seat question in the existing ask ledger, without dispatching or queuing an outbox message. */
44
+ export function recordSeatAskShadow(root: string, ask: SeatAskShadow, now: number): boolean {
45
+ if (ask.from === ask.to || !ask.itemId || !ask.question.trim() || !Number.isFinite(now)) throw new Error('invalid shadow seat ask');
46
+ const id = `seat-loop:${createHash('sha256').update(JSON.stringify([ask.from, ask.to, ask.version, ask.itemId])).digest('hex')}`;
47
+ const store = openMsgStore(join(root, 'msg', 'messages.db'));
48
+ try {
49
+ createTable(store);
50
+ const origin = JSON.stringify({ channel: 'seat-loop', from: ask.from, itemId: ask.itemId, version: ask.version, question: ask.question.trim() });
51
+ return store.db.query("INSERT OR IGNORE INTO seat_asks (id, seat, origin, deadline, timeout_minutes, status) VALUES (?, ?, ?, ?, ?, 'shadow')")
52
+ .run(id, ask.to, origin, now + DEFAULT_ASK_TIMEOUT_MS, Math.ceil(DEFAULT_ASK_TIMEOUT_MS / 60000)).changes === 1;
53
+ } finally { store.close(); }
54
+ }
55
+
29
56
  export interface SeatAskDeps {
30
57
  open?: () => MsgStore;
31
58
  now?: () => number;
@@ -52,7 +79,7 @@ export async function askSeat(text: string, origin: AskOrigin, command: CeoComma
52
79
  .run(id, 'TC', JSON.stringify(origin), (deps.now ?? Date.now)() + timeout, minutes, 'pending');
53
80
  } finally { store.close(); }
54
81
  try {
55
- const result = await (deps.dispatch ?? dispatchCeoTask)('TC', `질문: ${body}\n답장 요청: ${id}\n회신: elanous msg post --from TC --to CEO --kind seat-ask-reply --body '${id}: <답>'`, command,
82
+ const result = await (deps.dispatch ?? dispatchCeoTask)('TC', `질문: ${body}\n답장 요청: ${id}\n회신: elanous seat answer ${id} "<답>"`, command,
56
83
  { via: origin.channel, ref: `ask:${id}` });
57
84
  debug.log('seat.ask', 'sent', { seat: 'TC', id, via: origin.channel, channel: result.channel });
58
85
  return `CTO에게 물었습니다. 답을 기다립니다 (최대 ${minutes}분). 요청: ${id}${result.channel === 'failed' ? ` · 조율 채널 전송 실패: ${result.channelError}` : ''}`;
@@ -64,22 +91,40 @@ export async function askSeat(text: string, origin: AskOrigin, command: CeoComma
64
91
  }
65
92
  }
66
93
 
67
- /** Read the seat mailbox without advancing its cursor (other CEO messages remain untouched). */
94
+ /** Record a seat reply in its original request row; delivery stays with the originating surface's worker. */
95
+ export function answerSeatAsk(id: string, text: string, deps: Pick<SeatAskDeps, 'open' | 'now'> = {}): void {
96
+ const answer = text.trim();
97
+ if (!answer) throw new Error('seat answer must not be empty');
98
+ const store = (deps.open ?? openMsgStore)();
99
+ try {
100
+ createTable(store);
101
+ const now = (deps.now ?? Date.now)();
102
+ const updated = store.db.query(`UPDATE seat_asks SET answer = ?, answered_at = ?
103
+ WHERE id = ? AND seat = 'TC' AND status = 'pending' AND answer IS NULL AND deadline > ?`)
104
+ .run(answer, now, id, now);
105
+ if (updated.changes !== 1) throw new Error(`seat ask not pending or deadline passed: ${id}`);
106
+ debug.log('seat.ask', 'reply-recorded', { seat: 'TC', id });
107
+ } finally { store.close(); }
108
+ }
109
+
110
+ /** Deliver recorded seat answers or expiration notices via the original surface. */
68
111
  export async function deliverSeatAnswers(deps: SeatAskDeps): Promise<void> {
69
112
  const store = (deps.open ?? openMsgStore)();
70
113
  try {
71
114
  createTable(store);
72
- const pending = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes FROM seat_asks WHERE status = 'pending'").all() as AskRow[];
115
+ const pending = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes, answer, answered_at FROM seat_asks WHERE status = 'pending'").all() as AskRow[];
73
116
  const decide = store.db.transaction((id: string, now: number): 'answered' | 'expired' | null => {
74
- const ask = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes FROM seat_asks WHERE id = ? AND status = 'pending'").get(id) as AskRow | null;
117
+ const ask = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes, answer, answered_at FROM seat_asks WHERE id = ? AND status = 'pending'").get(id) as AskRow | null;
75
118
  if (!ask) return null;
76
- const reply = store.db.query("SELECT id, body, created_at FROM msg_messages WHERE recipient = 'CEO' AND kind = 'seat-ask-reply' AND substr(body, 1, ?) = ? AND sender = ? ORDER BY id LIMIT 1")
77
- .get(id.length + 2, `${id}: `, ask.seat) as { id: number; body: string; created_at: string } | null;
78
- const answer = reply && Date.parse(reply.created_at) < ask.deadline ? reply.body.slice(id.length + 2).trim() : '';
119
+ // Retain compatibility with replies already posted to the existing seat mailbox.
120
+ const reply = ask.answer === null ? store.db.query("SELECT id, body, created_at FROM msg_messages WHERE recipient = 'CEO' AND kind = 'seat-ask-reply' AND substr(body, 1, ?) = ? AND sender = ? ORDER BY id LIMIT 1")
121
+ .get(id.length + 2, `${id}: `, ask.seat) as { id: number; body: string; created_at: string } | null : null;
122
+ const answer = ask.answer !== null && ask.answered_at !== null && ask.answered_at < ask.deadline ? ask.answer
123
+ : reply && Date.parse(reply.created_at) < ask.deadline ? reply.body.slice(id.length + 2).trim() : '';
79
124
  const status = answer ? 'answered' : now >= ask.deadline ? 'expired' : null;
80
125
  if (!status) return null;
81
126
  const text = status === 'answered' ? `CTO 답변 (${id}): ${answer}`
82
- : `CTO 미답 (${id}): ${ask.timeout_minutes}분 안에 답이 오지 않았습니다.`;
127
+ : `CTO 미답 (${id}): 아직 답 없음 (${ask.timeout_minutes}분 경과).`;
83
128
  const updated = store.db.query("UPDATE seat_asks SET status = ? WHERE id = ? AND status = 'pending'").run(status, id);
84
129
  if (updated.changes !== 1) return null;
85
130
  store.db.query('INSERT INTO seat_ask_outbox (id, origin, text) VALUES (?, ?, ?)').run(id, ask.origin, text);