agentworkshop 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/.AgentWorkShop/prompts/host-tools.json +123 -0
  2. package/.output/.AgentWorkShop/prompts/host-tools.json +123 -0
  3. package/.output/nitro.json +1 -1
  4. package/.output/public/_nuxt/{DJJDigim2.js → -FhgRqJl2.js} +1 -1
  5. package/.output/public/_nuxt/{CGk_VUhO2.js → 0qvcO_KM2.js} +1 -1
  6. package/.output/public/_nuxt/26OL4Ao82.js +1 -0
  7. package/.output/public/_nuxt/{sBDZymdy2.js → 2Kwo_j9G2.js} +1 -1
  8. package/.output/public/_nuxt/{BqYVLAcm.js → 2v5GdspM.js} +1 -1
  9. package/.output/public/_nuxt/{DkQBMVTs2.js → 8M7wFbEN2.js} +1 -1
  10. package/.output/public/_nuxt/{DtiY69xi2.js → 8SZLbrI42.js} +1 -1
  11. package/.output/public/_nuxt/{DF32f5EL2.js → B2NbzUau2.js} +1 -1
  12. package/.output/public/_nuxt/{CwZW1ZCe2.js → B4JlRHBB2.js} +1 -1
  13. package/.output/public/_nuxt/{BQOn0q6Y.js → B6C4WofF.js} +1 -1
  14. package/.output/public/_nuxt/{BC7W6lNm.js → B6UwtJ1a.js} +1 -1
  15. package/.output/public/_nuxt/{BfQ-ptH0.js → B8HFUsMH.js} +1 -1
  16. package/.output/public/_nuxt/{DzBbYWrw2.js → BBB_j2LU2.js} +1 -1
  17. package/.output/public/_nuxt/BCLUwdP52.js +1 -0
  18. package/.output/public/_nuxt/{CLxmY3Rh.js → BK4wbfGS.js} +1 -1
  19. package/.output/public/_nuxt/{BRMVDfPl2.js → BKidykmV2.js} +1 -1
  20. package/.output/public/_nuxt/BPUQZ9Lq2.js +8 -0
  21. package/.output/public/_nuxt/BRYBzVMJ.js +1 -0
  22. package/.output/public/_nuxt/{Bj5sjA5O.js → BRci9D_l.js} +1 -1
  23. package/.output/public/_nuxt/{Dmgqz2np2.js → BVGzwAxr2.js} +1 -1
  24. package/.output/public/_nuxt/BVg2R2VB2.js +1 -0
  25. package/.output/public/_nuxt/{C3aUN4Vp2.js → BW2uTUx52.js} +1 -1
  26. package/.output/public/_nuxt/{B5FKaMM02.js → BY3Lbz3h2.js} +1 -1
  27. package/.output/public/_nuxt/{DIwmMa_7.js → BYzim_Bn.js} +1 -1
  28. package/.output/public/_nuxt/{D8xUsQGt.js → B_Obcbiu.js} +1 -1
  29. package/.output/public/_nuxt/BaYDgyaR.js +3 -0
  30. package/.output/public/_nuxt/{DZJ11BTI.js → BbACaREb.js} +1 -1
  31. package/.output/public/_nuxt/{BJrj5JVe2.js → BcosvNXb2.js} +1 -1
  32. package/.output/public/_nuxt/{B_-vAvzb.js → BfeXib9G.js} +1 -1
  33. package/.output/public/_nuxt/{CeLqojCJ.js → BfgTar9L.js} +1 -1
  34. package/.output/public/_nuxt/BfvuWqSa.js +1 -0
  35. package/.output/public/_nuxt/{D8r8PNQa2.js → BiZWwdcD2.js} +1 -1
  36. package/.output/public/_nuxt/{DIFkTkdS.js → BkEokGX5.js} +1 -1
  37. package/.output/public/_nuxt/{CJSohaqk2.js → BklGqEto2.js} +2 -2
  38. package/.output/public/_nuxt/{DkpmSnHX.js → Bko5adbu.js} +1 -1
  39. package/.output/public/_nuxt/{DTQTGA6v2.js → BmBlIIJo2.js} +1 -1
  40. package/.output/public/_nuxt/{D_NjL-Hz.js → Bmvt9ydE.js} +1 -1
  41. package/.output/public/_nuxt/{Cp4r6Eiz.js → BoyuIoSm.js} +1 -1
  42. package/.output/public/_nuxt/{62J4vljm.js → Bq-tmkst.js} +1 -1
  43. package/.output/public/_nuxt/{BMMoqi94.js → BqFaZ4kS.js} +1 -1
  44. package/.output/public/_nuxt/BsJYieAL2.js +1 -0
  45. package/.output/public/_nuxt/{DD4J2Otc.js → BtZKe9ZV.js} +1 -1
  46. package/.output/public/_nuxt/{BnpY_zNx.js → BtumQhZK.js} +1 -1
  47. package/.output/public/_nuxt/{BjLzqWJH2.js → BwWs9EdO2.js} +1 -1
  48. package/.output/public/_nuxt/{Bx2a9cuY2.js → BxxpJxZf2.js} +1 -1
  49. package/.output/public/_nuxt/{qRXa-PM22.js → ByTnUqFw2.js} +1 -1
  50. package/.output/public/_nuxt/{DvOETuoT2.js → Byiiiwc72.js} +1 -1
  51. package/.output/public/_nuxt/{Car2lkbb.js → C1-SuwUN.js} +1 -1
  52. package/.output/public/_nuxt/{Dg81dOEO.js → C14pM5G4.js} +1 -1
  53. package/.output/public/_nuxt/{MDhaRQq_.js → C2Yp-B8m.js} +1 -1
  54. package/.output/public/_nuxt/{BJ2nJNlK2.js → C4e6_nom2.js} +1 -1
  55. package/.output/public/_nuxt/{CiCEprsp2.js → C5OStZJ62.js} +1 -1
  56. package/.output/public/_nuxt/{ByMj6e7s.js → C6lssmvl.js} +2 -2
  57. package/.output/public/_nuxt/{C6uBP0Xa.js → CC-GEjfN.js} +1 -1
  58. package/.output/public/_nuxt/CC2Pv8VL2.js +1 -0
  59. package/.output/public/_nuxt/{DKiqdYnj.js → CCcMgxV9.js} +1 -1
  60. package/.output/public/_nuxt/{5S26I34j2.js → CDL30A2z2.js} +1 -1
  61. package/.output/public/_nuxt/{B8C-QJB5.js → CDYLasP8.js} +1 -1
  62. package/.output/public/_nuxt/CElzwyXQ.js +1 -0
  63. package/.output/public/_nuxt/{2KE8xGVm.js → CEvJu-xI.js} +1 -1
  64. package/.output/public/_nuxt/{CR612R752.js → CFQRFctQ2.js} +1 -1
  65. package/.output/public/_nuxt/{DnzjxC0u.js → CHk9XxNi.js} +2 -2
  66. package/.output/public/_nuxt/{Bx4MR0jd.js → CLFmtXU7.js} +1 -1
  67. package/.output/public/_nuxt/{DW8k_0dQ.js → CMJi6yYS.js} +1 -1
  68. package/.output/public/_nuxt/{DD-r0S1p.js → CPvFGbr8.js} +1 -1
  69. package/.output/public/_nuxt/{CCgbgkid.js → CQSxS_Ek.js} +2 -2
  70. package/.output/public/_nuxt/{jGxHnjW6.js → CQuo31jF.js} +1 -1
  71. package/.output/public/_nuxt/{SoO2K-di.js → CRCrWy-6.js} +1 -1
  72. package/.output/public/_nuxt/CUCFFL9m.js +84 -0
  73. package/.output/public/_nuxt/CZYNy60j2.js +1 -0
  74. package/.output/public/_nuxt/{WPwdj9pg.js → CZsFf7ck.js} +1 -1
  75. package/.output/public/_nuxt/CfFUK6932.js +2 -0
  76. package/.output/public/_nuxt/{DAsjfdZD.js → CfIbFnJz.js} +1 -1
  77. package/.output/public/_nuxt/{Tk6TQZjU.js → CjF4QY9h.js} +1 -1
  78. package/.output/public/_nuxt/{DlUQa0wn.js → Cjo1t2IF.js} +1 -1
  79. package/.output/public/_nuxt/{CDn0eDn8.js → CmuGMxDP.js} +1 -1
  80. package/.output/public/_nuxt/Cn6EojFe.js +1 -0
  81. package/.output/public/_nuxt/{DLqSQbGv.js → CnYazk8d.js} +1 -1
  82. package/.output/public/_nuxt/{DQfy6R_2.js → CnrGVJIr.js} +1 -1
  83. package/.output/public/_nuxt/{C0YL0HKK.js → CtcBhkci.js} +1 -1
  84. package/.output/public/_nuxt/{h5gsh8E92.js → Cv-Mv7_h2.js} +1 -1
  85. package/.output/public/_nuxt/{vPcnBJsa2.js → CzlZrfq82.js} +1 -1
  86. package/.output/public/_nuxt/{C2YYOgMe.js → CznnUTZx.js} +2 -2
  87. package/.output/public/_nuxt/{csitHKnE2.js → D-80EfyA2.js} +1 -1
  88. package/.output/public/_nuxt/{BRdoISnJ2.js → D1C6qtS12.js} +1 -1
  89. package/.output/public/_nuxt/{Cnrmlixo.js → D1MkndMZ.js} +2 -2
  90. package/.output/public/_nuxt/{BLwDhlaa.js → D37gODe0.js} +1 -1
  91. package/.output/public/_nuxt/{NXY37IO62.js → D6FhDrYe2.js} +1 -1
  92. package/.output/public/_nuxt/{Btx8wL4-.js → D7TZLu4F.js} +1 -1
  93. package/.output/public/_nuxt/{qoUdVDnC.js → D7tEwf-o.js} +3 -3
  94. package/.output/public/_nuxt/D8HQPtm62.js +1 -0
  95. package/.output/public/_nuxt/D9O4L4jK.js +1 -0
  96. package/.output/public/_nuxt/{aQ1B7BZa2.js → D9lL3fJM2.js} +2 -2
  97. package/.output/public/_nuxt/{CT-vTjcG2.js → DC-2eKo62.js} +1 -1
  98. package/.output/public/_nuxt/DF9ETYJ32.js +1 -0
  99. package/.output/public/_nuxt/DGGBrc0q2.js +1 -0
  100. package/.output/public/_nuxt/DGu_fna7.js +1 -0
  101. package/.output/public/_nuxt/{BupBjt6B.js → DKOvbitt.js} +1 -1
  102. package/.output/public/_nuxt/{B1PzYsqN.js → DNxudyND.js} +1 -1
  103. package/.output/public/_nuxt/{BfX6_AjY.js → DOT-XQyi.js} +1 -1
  104. package/.output/public/_nuxt/{BsTZnkVK.js → DPPC9Teq.js} +1 -1
  105. package/.output/public/_nuxt/{HxohXQ_r.js → DRskyE7l.js} +1 -1
  106. package/.output/public/_nuxt/{B-U7E_Mc2.js → DW4ZgInh2.js} +1 -1
  107. package/.output/public/_nuxt/{BErG4kzc2.js → DWe6BMlp2.js} +1 -1
  108. package/.output/public/_nuxt/{BH8RvpVy.js → DWy0AjON.js} +1 -1
  109. package/.output/public/_nuxt/{Bc_k6AVA.js → DXgw1dVL.js} +4 -4
  110. package/.output/public/_nuxt/{C3sWJ8SD2.js → DZsKIzKD2.js} +1 -1
  111. package/.output/public/_nuxt/D_59BNP1.js +14 -0
  112. package/.output/public/_nuxt/{BQIO4MkA2.js → D_FZ3KZI2.js} +1 -1
  113. package/.output/public/_nuxt/{n_Njdwii2.js → D__vJGHF2.js} +1 -1
  114. package/.output/public/_nuxt/{C9gErLQc2.js → DaizNGUm2.js} +1 -1
  115. package/.output/public/_nuxt/{C-MY-JQE.js → DdyE0ylS.js} +1 -1
  116. package/.output/public/_nuxt/DhLlTxQh2.js +1 -0
  117. package/.output/public/_nuxt/{CxVhG0Xx.js → DhW7cFOa.js} +1 -1
  118. package/.output/public/_nuxt/{Rt2i6k7C2.js → DhjgWrB62.js} +1 -1
  119. package/.output/public/_nuxt/{KwT4sN_d.js → DiWcX4gj.js} +1 -1
  120. package/.output/public/_nuxt/DiloA8vK.js +1 -0
  121. package/.output/public/_nuxt/{DX-c5laM2.js → DlS-SkQ42.js} +1 -1
  122. package/.output/public/_nuxt/{D_Zspo1y.js → DmHp9yQ3.js} +1 -1
  123. package/.output/public/_nuxt/{dq1HKoGD.js → DoL9u6wu.js} +1 -1
  124. package/.output/public/_nuxt/{CIvMT5Ic.js → DqxBCeDe.js} +1 -1
  125. package/.output/public/_nuxt/{BnNmkGJS2.js → DrlnrdvY2.js} +3 -3
  126. package/.output/public/_nuxt/{BAcjVcku2.js → Dt8TL8_X2.js} +1 -1
  127. package/.output/public/_nuxt/{BtfwbNC0.js → Du7gS8RU.js} +1 -1
  128. package/.output/public/_nuxt/DuUc4bbY2.js +1 -0
  129. package/.output/public/_nuxt/{DPUXbTg9.js → DudoisLM.js} +1 -1
  130. package/.output/public/_nuxt/{Ce5R-ZGf2.js → DwgVlehj2.js} +1 -1
  131. package/.output/public/_nuxt/Dyxf2xZw.js +1 -0
  132. package/.output/public/_nuxt/Dz9C2pTa.js +1 -0
  133. package/.output/public/_nuxt/{BYxG9Hb2.js → EMbqTHfT.js} +1 -1
  134. package/.output/public/_nuxt/{B1SzppY12.js → FsRVXpyF2.js} +1 -1
  135. package/.output/public/_nuxt/{0MLy6ogg2.js → GQrEW8nk2.js} +1 -1
  136. package/.output/public/_nuxt/{Tuz5LcLM.js → IXR1BWP5.js} +1 -1
  137. package/.output/public/_nuxt/{-jpUnM1I2.js → Iub61dX92.js} +1 -1
  138. package/.output/public/_nuxt/{CQgOzpvI.js → JegDslce.js} +2 -2
  139. package/.output/public/_nuxt/{DrF3TWoj.js → KzK37yIr.js} +1 -1
  140. package/.output/public/_nuxt/{Br3MggOL.js → N-CCmCsX.js} +1 -1
  141. package/.output/public/_nuxt/{DHhmq7s_.js → NfvZ5Lzv.js} +1 -1
  142. package/.output/public/_nuxt/{CzX_kaPL.js → POTcePF_.js} +1 -1
  143. package/.output/public/_nuxt/{D7s96J3r2.js → Q-JpBT032.js} +1 -1
  144. package/.output/public/_nuxt/{DzwIZ81f2.js → R1g64DNi2.js} +1 -1
  145. package/.output/public/_nuxt/{JgheoP3e.js → R5Pz7BqB.js} +1 -1
  146. package/.output/public/_nuxt/{yLyz0-Yz.js → SvjzWbn8.js} +1 -1
  147. package/.output/public/_nuxt/{Dd7MZc_Q.js → XqXoaoDs.js} +1 -1
  148. package/.output/public/_nuxt/{B6jtLy6z.js → YAA98rWJ.js} +11 -11
  149. package/.output/public/_nuxt/{HX4_xnak2.js → YLYSczSq2.js} +1 -1
  150. package/.output/public/_nuxt/{BBw9ylUY2.js → YNhAoK-R2.js} +1 -1
  151. package/.output/public/_nuxt/Zkbt8Uk5.js +1 -0
  152. package/.output/public/_nuxt/aml.PalMp-5n.css +1 -0
  153. package/.output/public/_nuxt/{C41CcsiD.js → b7UcqLKi.js} +1 -1
  154. package/.output/public/_nuxt/builds/latest.json +1 -1
  155. package/.output/public/_nuxt/builds/meta/fa0af8b5-3929-428d-a6de-3b5cc6b8248f.json +1 -0
  156. package/.output/public/_nuxt/{DVkFSOZi.js → cKj4vSo5.js} +1 -1
  157. package/.output/public/_nuxt/{r1CpGsFp.js → dHwWyr6b.js} +1 -1
  158. package/.output/public/_nuxt/{DlcA9Gxl.js → eePbiWEh.js} +1 -1
  159. package/.output/public/_nuxt/{cjRzSvAg2.js → eymRov9Y2.js} +1 -1
  160. package/.output/public/_nuxt/{B8cViLJT.js → geMze5qw.js} +1 -1
  161. package/.output/public/_nuxt/{uu1wfdfR2.js → gh-WMxV_2.js} +1 -1
  162. package/.output/public/_nuxt/{Ce6e1mPk2.js → hCN555XP2.js} +1 -1
  163. package/.output/public/_nuxt/{rdUE8Khf.js → hZG5MLjK.js} +3 -3
  164. package/.output/public/_nuxt/{CcX_jP-d.js → hlfahYxK.js} +1 -1
  165. package/.output/public/_nuxt/{cGSl2GZp2.js → ilJHF1nA2.js} +1 -1
  166. package/.output/public/_nuxt/{D6ZcgHPz.js → jDuiDtGb.js} +1 -1
  167. package/.output/public/_nuxt/{DbeNMehP.js → k9b520K-.js} +1 -1
  168. package/.output/public/_nuxt/ontology.B_3Wn907.css +1 -0
  169. package/.output/public/_nuxt/optimizer.CLA8I1sy.css +1 -0
  170. package/.output/public/_nuxt/{DSORcpTJ.js → rDvMijKA.js} +2 -2
  171. package/.output/public/_nuxt/{CAiHhX8P2.js → rF7mggl72.js} +2 -2
  172. package/.output/public/_nuxt/ri9UF8rk.js +2 -0
  173. package/.output/public/_nuxt/{KgnxOsMr.js → toG_qAMH.js} +1 -1
  174. package/.output/public/_nuxt/{KQZmHR_K.js → u3h4pGpm.js} +2 -2
  175. package/.output/public/_nuxt/{dJ7gK7C2.js → uomnHjhM.js} +1 -1
  176. package/.output/public/_nuxt/{BUTg4W_x2.js → v77qozuJ2.js} +1 -1
  177. package/.output/public/_nuxt/{BcEr7tIB.js → v7cV7hJa.js} +1 -1
  178. package/.output/public/_nuxt/{D25dVZ822.js → vkQoYNQR2.js} +2 -2
  179. package/.output/public/_nuxt/{wR_w07322.js → vp3LtnTz2.js} +1 -1
  180. package/.output/public/_nuxt/{Bnc8HELj2.js → we7-sMSo2.js} +1 -1
  181. package/.output/public/_nuxt/{kN3ZzR1-.js → wxISMS1i.js} +1 -1
  182. package/.output/public/_nuxt/{DGrrucbG.js → zy7efYKR.js} +1 -1
  183. package/.output/server/chunks/_/data-export.mjs +5 -5
  184. package/.output/server/chunks/_/data-query.mjs +2 -2
  185. package/.output/server/chunks/_/eda-run.repo.mjs +2 -2
  186. package/.output/server/chunks/_/features.mjs +4 -4
  187. package/.output/server/chunks/_/golden.mjs +2 -2
  188. package/.output/server/chunks/_/index.mjs +1 -1
  189. package/.output/server/chunks/_/mes-console.mjs +1 -1
  190. package/.output/server/chunks/_/nitro.mjs +2149 -1520
  191. package/.output/server/chunks/_/nitro.mjs.map +1 -1
  192. package/.output/server/chunks/_/spc.mjs +1 -1
  193. package/.output/server/chunks/build/TownView-BWMDbosY.mjs +1 -1
  194. package/.output/server/chunks/build/{_wsId_-BNKrrV1H.mjs → _wsId_-BPy-Aj9L.mjs} +3 -3
  195. package/.output/server/chunks/build/{_wsId_-BNKrrV1H.mjs.map → _wsId_-BPy-Aj9L.mjs.map} +1 -1
  196. package/.output/server/chunks/build/{agents-8tV9xL97.mjs → agents-CpNLdI8E.mjs} +6 -6
  197. package/.output/server/chunks/build/{agents-8tV9xL97.mjs.map → agents-CpNLdI8E.mjs.map} +1 -1
  198. package/.output/server/chunks/build/{aml-BNTEDOsl.mjs → aml-DRAFRcGU.mjs} +15 -12
  199. package/.output/server/chunks/build/{aml-BNTEDOsl.mjs.map → aml-DRAFRcGU.mjs.map} +1 -1
  200. package/.output/server/chunks/build/{channel-templates-Iot9Y3vV.mjs → channel-templates-ByHOQQkO.mjs} +2 -2
  201. package/.output/server/chunks/build/{channel-templates-Iot9Y3vV.mjs.map → channel-templates-ByHOQQkO.mjs.map} +1 -1
  202. package/.output/server/chunks/build/daq-CdxcfY_G.mjs +1 -1
  203. package/.output/server/chunks/build/dcw-BlDQtS4q.mjs +1 -1
  204. package/.output/server/chunks/build/{default-CJkOcmrm.mjs → default-CNWS6NUw.mjs} +4 -4
  205. package/.output/server/chunks/build/{default-CJkOcmrm.mjs.map → default-CNWS6NUw.mjs.map} +1 -1
  206. package/.output/server/chunks/build/{dropdown-CjwsxU39.mjs → dropdown-BNwTVGde.mjs} +2 -2
  207. package/.output/server/chunks/build/{dropdown-CjwsxU39.mjs.map → dropdown-BNwTVGde.mjs.map} +1 -1
  208. package/.output/server/chunks/build/{dropdown-C6YH_kSO.mjs → dropdown-Cd-xPhR6.mjs} +2 -2
  209. package/.output/server/chunks/build/{dropdown-C6YH_kSO.mjs.map → dropdown-Cd-xPhR6.mjs.map} +1 -1
  210. package/.output/server/chunks/build/input-number-BNlNDK7H.mjs +1 -1
  211. package/.output/server/chunks/build/{logs-BTfJQ6vQ.mjs → logs-pRb-TMWa.mjs} +3 -3
  212. package/.output/server/chunks/build/{logs-BTfJQ6vQ.mjs.map → logs-pRb-TMWa.mjs.map} +1 -1
  213. package/.output/server/chunks/build/{monitor-DvaR3yo8.mjs → monitor-Cq6hRFeQ.mjs} +6 -6
  214. package/.output/server/chunks/build/{monitor-DvaR3yo8.mjs.map → monitor-Cq6hRFeQ.mjs.map} +1 -1
  215. package/.output/server/chunks/build/{ontology-C3HS5pMo.mjs → ontology-DK0Mf0zT.mjs} +510 -81
  216. package/.output/server/chunks/build/ontology-DK0Mf0zT.mjs.map +1 -0
  217. package/.output/server/chunks/build/{operations-Cl8nVm9D.mjs → operations-SMQrRAcr.mjs} +3 -3
  218. package/.output/server/chunks/build/{operations-Cl8nVm9D.mjs.map → operations-SMQrRAcr.mjs.map} +1 -1
  219. package/.output/server/chunks/build/optimizer-BlWTsM-W.mjs +202 -0
  220. package/.output/server/chunks/build/optimizer-BlWTsM-W.mjs.map +1 -0
  221. package/.output/server/chunks/build/{pagination-KaIvHBzi.mjs → pagination-DTAconUo.mjs} +2 -2
  222. package/.output/server/chunks/build/{pagination-KaIvHBzi.mjs.map → pagination-DTAconUo.mjs.map} +1 -1
  223. package/.output/server/chunks/build/{permissions-CVTfixZj.mjs → permissions-DgXQZSyx.mjs} +6 -6
  224. package/.output/server/chunks/build/{permissions-CVTfixZj.mjs.map → permissions-DgXQZSyx.mjs.map} +1 -1
  225. package/.output/server/chunks/build/{schedules-BLhn2CLn.mjs → schedules-dSnr8url.mjs} +6 -6
  226. package/.output/server/chunks/build/{schedules-BLhn2CLn.mjs.map → schedules-dSnr8url.mjs.map} +1 -1
  227. package/.output/server/chunks/build/{select--XFl7CtY.mjs → select-B3Dsb9yq.mjs} +3 -3
  228. package/.output/server/chunks/build/{select--XFl7CtY.mjs.map → select-B3Dsb9yq.mjs.map} +1 -1
  229. package/.output/server/chunks/build/{settings-DIf_iYdu.mjs → settings-BrIhnS2Z.mjs} +2 -2
  230. package/.output/server/chunks/build/{settings-DIf_iYdu.mjs.map → settings-BrIhnS2Z.mjs.map} +1 -1
  231. package/.output/server/chunks/build/{table-DIu_YCJN.mjs → table-CmVD-cA9.mjs} +4 -4
  232. package/.output/server/chunks/build/{table-DIu_YCJN.mjs.map → table-CmVD-cA9.mjs.map} +1 -1
  233. package/.output/server/chunks/build/{teams-B2J6ouRY.mjs → teams-B1d32eHK.mjs} +4 -4
  234. package/.output/server/chunks/build/{teams-B2J6ouRY.mjs.map → teams-B1d32eHK.mjs.map} +1 -1
  235. package/.output/server/chunks/build/{tokens-DFQGaN2n.mjs → tokens-GYaGJ35Z.mjs} +6 -6
  236. package/.output/server/chunks/build/{tokens-DFQGaN2n.mjs.map → tokens-GYaGJ35Z.mjs.map} +1 -1
  237. package/.output/server/chunks/build/{tools-DWJFnU_t.mjs → tools-s_9U1Djj.mjs} +6 -6
  238. package/.output/server/chunks/build/{tools-DWJFnU_t.mjs.map → tools-s_9U1Djj.mjs.map} +1 -1
  239. package/.output/server/chunks/build/types-D6J7slEa.mjs +1 -1
  240. package/.output/server/chunks/build/useDaqAddNode-D_Rkju0f.mjs +1 -1
  241. package/.output/server/chunks/build/useDaqDetailNode-DeOsDxK5.mjs +1 -1
  242. package/.output/server/chunks/build/useDaqDetailParams-Cm9a9r5G.mjs +1 -1
  243. package/.output/server/chunks/build/useDaqFilters-CctmO03p.mjs +1 -1
  244. package/.output/server/chunks/build/useDaqStream-B9ZBVQrI.mjs +1 -1
  245. package/.output/server/chunks/build/useDaqTemplates-CK37sMfi.mjs +1 -1
  246. package/.output/server/chunks/build/useDcwAddNode-DACVcEHs.mjs +1 -1
  247. package/.output/server/chunks/build/useDcwStream-Dir5ufAU.mjs +1 -1
  248. package/.output/server/chunks/build/{users-BWw0VCr9.mjs → users-DjiVC_tS.mjs} +6 -6
  249. package/.output/server/chunks/build/{users-BWw0VCr9.mjs.map → users-DjiVC_tS.mjs.map} +1 -1
  250. package/.output/server/chunks/routes/api/mcp/workshop.mjs +1 -1
  251. package/.output/server/chunks/routes/api/system/backup/run.post.mjs +2 -2
  252. package/.output/server/chunks/routes/api/workshop/aml/models/_id_.patch.mjs +7 -1
  253. package/.output/server/chunks/routes/api/workshop/aml/models/_id_.patch.mjs.map +1 -1
  254. package/.output/server/chunks/routes/api/workshop/channel-templates/_id/instantiate.post.mjs +1 -1
  255. package/.output/server/chunks/routes/api/workshop/channels.post.mjs +6 -6
  256. package/.output/server/chunks/routes/api/workshop/daq/_id/ingest.post.mjs +2 -2
  257. package/.output/server/chunks/routes/api/workshop/harnesses/_id/providers.get.mjs +1 -1
  258. package/.output/server/chunks/routes/api/workshop/index.mjs +1 -1
  259. package/.output/server/chunks/routes/api/workshop/index.put.mjs +1 -1
  260. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/autofix.mjs +52 -0
  261. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/autofix.mjs.map +1 -0
  262. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/compile.mjs +1 -1
  263. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/evidence.mjs +1 -1
  264. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/publish.mjs +1 -1
  265. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval-decision.mjs +1 -1
  266. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/approval.mjs +1 -1
  267. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/rules/_ruleId/transition.mjs +1 -1
  268. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/subgraph.mjs +38 -0
  269. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/subgraph.mjs.map +1 -0
  270. package/.output/server/chunks/routes/api/workshop/ontology/drafts/_draftId/validate.mjs +1 -1
  271. package/.output/server/chunks/routes/api/workshop/ontology/export/_ontologyId_.mjs +1 -1
  272. package/.output/server/chunks/routes/api/workshop/ontology/index.mjs +1 -1
  273. package/.output/server/chunks/routes/api/workshop/ontology/scene.mjs +8 -1
  274. package/.output/server/chunks/routes/api/workshop/ontology/scene.mjs.map +1 -1
  275. package/.output/server/chunks/routes/api/workshop/ontology/traces/_ontologyId_.mjs +1 -1
  276. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId/compare.mjs +1 -1
  277. package/.output/server/chunks/routes/api/workshop/ontology/versions/_ontologyId_.mjs +1 -1
  278. package/.output/server/chunks/routes/api/workshop/optimization/capabilities.get.mjs +1 -1
  279. package/.output/server/chunks/routes/api/workshop/optimization/index.mjs +1 -1
  280. package/.output/server/chunks/routes/api/workshop/optimization/index2.mjs +1 -1
  281. package/.output/server/chunks/routes/api/workshop/optimization/profiles/_id/publish.post.mjs +1 -1
  282. package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/crosscheck.post.mjs +1 -1
  283. package/.output/server/chunks/routes/api/workshop/optimization/recommendations/_id/dispatch.post.mjs +1 -1
  284. package/.output/server/chunks/routes/api/workshop/optimization/solve.post.mjs +1 -1
  285. package/.output/server/chunks/routes/api/workshop/plugins/_name/disable.post.mjs +1 -1
  286. package/.output/server/chunks/routes/api/workshop/plugins/_name/enable.post.mjs +1 -1
  287. package/.output/server/chunks/routes/api/workshop/process-model/datasets.post.mjs +1 -1
  288. package/.output/server/chunks/routes/api/workshop/process-model/eligibility.mjs +1 -1
  289. package/.output/server/chunks/routes/api/workshop/process-model/index.mjs +1 -1
  290. package/.output/server/chunks/routes/api/workshop/process-model/specs/_id/publish.post.mjs +1 -1
  291. package/.output/server/chunks/routes/api/workshop/process-model/train.post.mjs +1 -1
  292. package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.delete.mjs +1 -1
  293. package/.output/server/chunks/routes/api/workshop/scene/layouts/_channelId_.put.mjs +1 -1
  294. package/.output/server/chunks/routes/api/workshop/tools/sync.post.mjs +1 -1
  295. package/.output/server/chunks/routes/api/workshop/workspaces/_id/channel-templates/_tplId_.post.mjs +1 -1
  296. package/.output/server/chunks/routes/renderer.mjs +2 -2
  297. package/.output/server/chunks/virtual/entry.mjs +92 -18
  298. package/.output/server/chunks/virtual/precomputed.mjs +1 -1
  299. package/.output/server/package.json +1 -1
  300. package/README-zh.md +5 -4
  301. package/README.md +6 -5
  302. package/app/components/aml/AmlModelsTable.vue +5 -0
  303. package/app/components/ontology/OntologyGraph.vue +356 -0
  304. package/app/pages/aml/styles.css +1 -0
  305. package/app/pages/ontology/index.vue +318 -35
  306. package/app/pages/ontology/types.ts +42 -0
  307. package/app/pages/optimizer/index.vue +21 -4
  308. package/config.yml +1 -1
  309. package/docs/cli.en.md +2 -2
  310. package/docs/cli.md +2 -2
  311. package/docs/plugins.en.md +1 -1
  312. package/docs/plugins.md +1 -1
  313. package/docs/sdk.en.md +1 -1
  314. package/docs/sdk.md +1 -1
  315. package/i18n/locales/en.ts +26 -0
  316. package/i18n/locales/zh-CN.ts +26 -0
  317. package/mcp/aw-mcp-server.mjs +20 -2
  318. package/package.json +1 -1
  319. package/scripts/e2e-direct-rest-simulator-paper.mjs +624 -0
  320. package/scripts/e2e-idd-results.mjs +177 -0
  321. package/scripts/e2e-model-loop-live.mjs +58 -4
  322. package/scripts/e2e-ontology-live.mjs +138 -3
  323. package/scripts/e2e-ontology.mjs +393 -328
  324. package/scripts/e2e-pi-simulator-paper.mjs +2316 -0
  325. package/scripts/e2e-registered-harness-simulator-paper.mjs +1926 -0
  326. package/scripts/e2e-simulator-optimizer-paper.mjs +264 -0
  327. package/scripts/fixtures/omp-paper-harness.mjs +163 -0
  328. package/sdk/context.mjs +6 -0
  329. package/sdk/index.d.mts +2 -0
  330. package/server/api/workshop/aml/models/[id].patch.ts +36 -30
  331. package/server/api/workshop/ontology/drafts/[draftId]/autofix.ts +31 -0
  332. package/server/api/workshop/ontology/drafts/[draftId]/subgraph.ts +24 -0
  333. package/server/api/workshop/ontology/scene.ts +14 -1
  334. package/server/plugins-builtin/diag-bridge/client.mjs +390 -239
  335. package/server/plugins-builtin/diag-bridge/host/helpers.mjs +80 -0
  336. package/server/plugins-builtin/diag-bridge/host/plugin.mjs +264 -2
  337. package/server/plugins-builtin/diag-bridge/i18n.json +84 -4
  338. package/server/services/workshop/agents/adapters/omp-rpc-client/frames.ts +129 -111
  339. package/server/services/workshop/agents/host-tool-bridge/tools/industrial.ts +6 -3
  340. package/server/services/workshop/agents/industrial/aml-job-tools.ts +602 -569
  341. package/server/services/workshop/agents/industrial/grant-guard.ts +15 -1
  342. package/server/services/workshop/agents/industrial/index.ts +2 -2
  343. package/server/services/workshop/agents/industrial/ontology-tools.ts +66 -6
  344. package/server/services/workshop/agents/industrial/ops-tools.ts +54 -16
  345. package/server/services/workshop/agents/industrial/optimizer-tools.ts +2 -0
  346. package/server/services/workshop/agents/industrial/recipe-gate.ts +19 -6
  347. package/server/services/workshop/agents/industrial/recipe-propose-tools.ts +1 -1
  348. package/server/services/workshop/agents/omp-agent/supervision-history.ts +38 -0
  349. package/server/services/workshop/agents/omp-agent/tools-steer.ts +18 -1
  350. package/server/services/workshop/aml/aml.repo.ts +16 -0
  351. package/server/services/workshop/daq/bus/index.ts +12 -5
  352. package/server/services/workshop/db/database/open.ts +97 -97
  353. package/server/services/workshop/db/database/schema.ts +1 -0
  354. package/server/services/workshop/ontology/autofix.ts +198 -0
  355. package/server/services/workshop/ontology/contracts.ts +3 -1
  356. package/server/services/workshop/ontology/index.ts +2 -0
  357. package/server/services/workshop/ontology/ontology.service.ts +46 -0
  358. package/server/services/workshop/ontology/subgraph.core.ts +300 -0
  359. package/server/services/workshop/ontology/subgraph.service.ts +113 -0
  360. package/server/services/workshop/optimization/contracts.ts +2 -0
  361. package/server/services/workshop/optimization/profile-adopt.service.ts +5 -0
  362. package/server/services/workshop/optimization/profile.repo.ts +6 -4
  363. package/.output/public/_nuxt/B3Y5bCrM.js +0 -1
  364. package/.output/public/_nuxt/B8N8nsad2.js +0 -2
  365. package/.output/public/_nuxt/BO0BJx3w2.js +0 -8
  366. package/.output/public/_nuxt/BWn-lfCp2.js +0 -1
  367. package/.output/public/_nuxt/Bcs9zzO62.js +0 -1
  368. package/.output/public/_nuxt/BwO2Y5FH2.js +0 -1
  369. package/.output/public/_nuxt/Byf4IxU2.js +0 -14
  370. package/.output/public/_nuxt/C-LU6xv_.js +0 -1
  371. package/.output/public/_nuxt/CJ0bjZ6v2.js +0 -1
  372. package/.output/public/_nuxt/CJ3Vul2u.js +0 -1
  373. package/.output/public/_nuxt/CNwx04ln.js +0 -84
  374. package/.output/public/_nuxt/CVCscYzb2.js +0 -1
  375. package/.output/public/_nuxt/C_A0MCol2.js +0 -1
  376. package/.output/public/_nuxt/CnP6snIz.js +0 -3
  377. package/.output/public/_nuxt/D0mzKkZr.js +0 -1
  378. package/.output/public/_nuxt/D3buuIkE.js +0 -1
  379. package/.output/public/_nuxt/D4_INWgq.js +0 -1
  380. package/.output/public/_nuxt/D5kCimyw2.js +0 -1
  381. package/.output/public/_nuxt/DBtXLkyA.js +0 -1
  382. package/.output/public/_nuxt/DHURbGkn2.js +0 -1
  383. package/.output/public/_nuxt/DaBzS-iu.js +0 -1
  384. package/.output/public/_nuxt/DnlhV7Xe.js +0 -1
  385. package/.output/public/_nuxt/GtI6PUI32.js +0 -1
  386. package/.output/public/_nuxt/Nw_6OpQZ.js +0 -1
  387. package/.output/public/_nuxt/Y4sMSPrS2.js +0 -1
  388. package/.output/public/_nuxt/aml.CeLxRzvI.css +0 -1
  389. package/.output/public/_nuxt/builds/meta/7a79a7e4-d691-4cf5-ae3a-3b01814479fb.json +0 -1
  390. package/.output/public/_nuxt/goF_oZHF.js +0 -2
  391. package/.output/public/_nuxt/ontology.QMGeh66l.css +0 -1
  392. package/.output/public/_nuxt/optimizer.B8gCbU1b.css +0 -1
  393. package/.output/public/_nuxt/rJ7To74v2.js +0 -1
  394. package/.output/server/chunks/build/ontology-C3HS5pMo.mjs.map +0 -1
  395. package/.output/server/chunks/build/optimizer-BOtGWEtc.mjs +0 -200
  396. package/.output/server/chunks/build/optimizer-BOtGWEtc.mjs.map +0 -1
@@ -0,0 +1,2316 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Bounded integration evidence for AgentWorkShop's registered `pi` harness.
4
+ * Pi receives a deterministic OpenAI-compatible model response from a local
5
+ * loopback fixture; the actual Pi CLI, Pi extension, AgentWorkShop bridge,
6
+ * protected approval API, simulator, device readback, and run-tagged sampling
7
+ * remain in the execution path. No external model or provider is used.
8
+ */
9
+ import { spawn, spawnSync } from 'node:child_process'
10
+ import { createHash, randomBytes } from 'node:crypto'
11
+ import { chmodSync, closeSync, copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from 'node:fs'
12
+ import { createServer } from 'node:net'
13
+ import { createServer as createHttpServer } from 'node:http'
14
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
15
+ import { fileURLToPath } from 'node:url'
16
+ import { setTimeout as delay } from 'node:timers/promises'
17
+ import { resolveRunMode } from '../shared/config/home.mjs'
18
+
19
+ const REPO = resolve(dirname(fileURLToPath(import.meta.url)), '..')
20
+ const AW_PORT = 3997
21
+ const SIM_PORT = 4020
22
+ const MODEL_API_PORT = 4021
23
+ const MQTT_PORT = 18840
24
+ const OFFLINE_TSDB_PORT = 45321
25
+ const OFFLINE_OBJECTSTORE_PORT = 45322
26
+ const OFFLINE_APP_MQTT_QUEUE_PORT = 45323
27
+ const FORBIDDEN_PORT = 4010
28
+ const APP_BASE = `http://127.0.0.1:${AW_PORT}`
29
+ const SIM_BASE = `http://127.0.0.1:${SIM_PORT}`
30
+ const SIM_SOURCE = resolve(REPO, 'plc-node-simulator')
31
+ const VERSION = JSON.parse(readFileSync(join(REPO, 'package.json'), 'utf8')).version
32
+ const TAG = `pi${Date.now().toString(36)}`
33
+ mkdirSync(join(REPO, '.omc'), { recursive: true })
34
+ const ROOT = mkdtempSync(join(REPO, '.omc', 'registered-pi-paper-'))
35
+ const HOME = join(ROOT, 'aw-home')
36
+ const EVIDENCE_PATH = join(ROOT, 'evidence.json')
37
+ const PI_AGENT_DIR = join(HOME, 'pi-agent')
38
+ const OUTPUT_BASE = join(REPO, 'docs', 'audit', 'evidence', '2026-10-25-current-cross-scene')
39
+ const OUTPUT_DIR = join(OUTPUT_BASE, `r23-pi-registered-harness-${new Date().toISOString().replace(/[-:.]/g, '').replace('T', '-').slice(0, 15)}-${randomBytes(3).toString('hex')}`)
40
+ const PI_MODELS_PATH = join(PI_AGENT_DIR, 'models.json')
41
+ const SIM_ROOT = join(ROOT, 'simulator')
42
+ const SIM_LOG = join(ROOT, 'simulator.log')
43
+ const APP_LOG = join(ROOT, 'agentworkshop.log')
44
+ const EMPTY_DOTENV = join(HOME, 'empty.env')
45
+ const ISOLATED_PROMPTS_DIR = join(HOME, 'prompts')
46
+ const NUXT_CLI = join(REPO, 'node_modules', 'nuxt', 'bin', 'nuxt.mjs')
47
+ const RAG_BRIDGE_DISABLED_BASE_URL = 'http://paper-harness-outbound-disabled.invalid'
48
+ const SIM_LOG_FD = openSync(SIM_LOG, 'a')
49
+ const APP_LOG_FD = openSync(APP_LOG, 'a')
50
+ const HARNESS_MODE = 'pi-local-fixture'
51
+ const PI_PROVIDER = 'agentworkshop-local'
52
+ const PI_MODEL = 'aw-deterministic-paper-fixture'
53
+ const PI_COMMAND = join(dirname(process.execPath), 'pi.cmd')
54
+ const PI_CLI_PACKAGE_PATH = join(dirname(process.execPath), 'node_modules', '@mariozechner', 'pi-coding-agent', 'package.json')
55
+ const PI_APPROVAL_TIMEOUT_MS = 180_000
56
+ const PI_TASK_COMPLETION_TIMEOUT_MS = 180_000
57
+ const PI_PROMPT_TIMEOUT_MS = 180_000
58
+ // Keep the shared evidence helpers usable while this runner selects only the
59
+ // local Pi fixture mode; no OMP CLI or external model is invoked.
60
+ const REAL_OMP_PROVIDER = PI_PROVIDER
61
+ const REAL_OMP_MODEL = PI_MODEL
62
+ const REAL_OMP_TRIALS_PER_SCENE = 1
63
+ const REAL_OMP_APPROVAL_TIMEOUT_MS = PI_APPROVAL_TIMEOUT_MS
64
+ const REAL_OMP_TASK_COMPLETION_TIMEOUT_MS = PI_TASK_COMPLETION_TIMEOUT_MS
65
+ const PI_API_TRACE_PATH = join(ROOT, 'pi-model-api-trace.json')
66
+ const piApiTrace = []
67
+ let piFixtureTarget = null
68
+ let piApiServer
69
+
70
+ const evidence = {
71
+ schemaVersion: 1,
72
+ experiment: {
73
+ id: TAG,
74
+ projectVersion: VERSION,
75
+ campaign: 'Pi registered-harness local-fixture cross-scene E2E',
76
+ harnessMode: HARNESS_MODE,
77
+ provider: PI_PROVIDER,
78
+ model: PI_MODEL,
79
+ trialsPerScene: 1,
80
+ runOutcomes: [],
81
+ modelFixture: 'deterministic local OpenAI-compatible streaming API; fixture scripts one recipe_trial call and one complete_task call per scene; no LLM or external provider',
82
+ startedAt: new Date().toISOString(),
83
+ postTrialSnapshotDelaySeconds: 20,
84
+ scenes: [],
85
+ },
86
+ isolation: {
87
+ result: 'pending',
88
+ awHome: 'fresh isolated AW_HOME',
89
+ appBase: APP_BASE,
90
+ simulatorBase: SIM_BASE,
91
+ simulatorMqttLoopbackPort: MQTT_PORT,
92
+ appMqttQueueOfflineProbePort: OFFLINE_APP_MQTT_QUEUE_PORT,
93
+ explicitLoopbackOnly: true,
94
+ externalLlmDisabled: true,
95
+ modelApiBase: `http://127.0.0.1:${MODEL_API_PORT}/v1`,
96
+ forbiddenServicePortExcluded: true,
97
+ checks: [],
98
+ },
99
+ checks: [],
100
+ status: 'running',
101
+ }
102
+
103
+ let appProcess
104
+ let simProcess
105
+ let currentStage = 'preflight'
106
+ let currentScene
107
+ let authToken
108
+ let syntheticAdminId
109
+ let isolatedPluginNames = []
110
+ let expectedPluginNames = []
111
+ const allowedEnabledPluginNames = ['rag-bridge']
112
+ let projectPluginTreeAtPrepare
113
+ let projectPromptTreeAtPrepare
114
+ let promptTreeAtPrepare
115
+ const generatedSessionPassword = randomBytes(32).toString('hex')
116
+ const children = new Set()
117
+ const allocatedDevicePorts = []
118
+ const CHILD_OS_ENV_KEYS = process.platform === 'win32'
119
+ ? ['PATH', 'PATHEXT', 'SystemRoot', 'WINDIR', 'TEMP', 'TMP', 'USERPROFILE', 'APPDATA', 'LOCALAPPDATA', 'HOMEDRIVE', 'HOMEPATH', 'ProgramData']
120
+ : ['PATH', 'HOME', 'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL']
121
+ const CHILD_EXTRA_ENV_KEYS = new Set(['SIM_PORT', 'MQTT_BROKER_PORT'])
122
+ const RELEASE_CHECK_SUFFIXES = ['-process-stopped', '-port-released']
123
+
124
+ function check(id, pass, detail = {}) {
125
+ evidence.checks.push({ id, status: pass ? 'pass' : 'fail', detail })
126
+ if (!pass) throw new Error(`check failed: ${id}`)
127
+ }
128
+
129
+ function noteIsolation(id, pass, detail = {}) {
130
+ evidence.isolation.checks.push({ id, status: pass ? 'pass' : 'fail', detail })
131
+ if (!pass) throw new Error(`isolation preflight failed: ${id}`)
132
+ }
133
+
134
+ function safeText(value, limit = 500) {
135
+ let text = String(value ?? '')
136
+ if (authToken) text = text.split(authToken).join('[REDACTED]')
137
+ text = text.replace(/\but-[a-f\d]{32}\b/gi, '[REDACTED_TOKEN]')
138
+ text = text.replace(/\bBearer\s+[^\s,;]+/gi, 'Bearer [REDACTED]')
139
+ text = text.replace(/\b(?:api[_-]?key|access[_-]?token|client[_-]?secret|password|secret)\s*[:=]\s*["']?[^\s,"'}]+/gi, '[REDACTED_CREDENTIAL]')
140
+ text = text.replace(/\bsk-[A-Za-z0-9_-]{16,}\b/g, '[REDACTED_CREDENTIAL]')
141
+ return text.slice(0, limit)
142
+ }
143
+
144
+ function compactError(error) {
145
+ const message = error instanceof Error ? error.message : String(error)
146
+ return { name: error instanceof Error ? error.name : 'Error', message: safeText(message) }
147
+ }
148
+
149
+ async function readRequestJson(req) {
150
+ const chunks = []
151
+ let bytes = 0
152
+ for await (const chunk of req) {
153
+ bytes += chunk.length
154
+ if (bytes > 2_000_000) throw new Error('model fixture rejected request larger than 2 MB')
155
+ chunks.push(chunk)
156
+ }
157
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'))
158
+ }
159
+
160
+ function sendSse(res, chunks) {
161
+ res.writeHead(200, {
162
+ 'content-type': 'text/event-stream; charset=utf-8',
163
+ 'cache-control': 'no-cache, no-transform',
164
+ connection: 'keep-alive',
165
+ })
166
+ for (const chunk of chunks) res.write(`data: ${JSON.stringify(chunk)}\n\n`)
167
+ res.write('data: [DONE]\n\n')
168
+ res.end()
169
+ }
170
+
171
+ function chatChunk(id, delta, finishReason = null, usage) {
172
+ return {
173
+ id,
174
+ object: 'chat.completion.chunk',
175
+ created: Math.floor(Date.now() / 1000),
176
+ model: PI_MODEL,
177
+ choices: [{ index: 0, delta, finish_reason: finishReason }],
178
+ ...(usage ? { usage } : {}),
179
+ }
180
+ }
181
+
182
+ async function startPiModelFixture() {
183
+ piApiServer = createHttpServer(async (req, res) => {
184
+ if (req.method !== 'POST' || req.url !== '/v1/chat/completions') {
185
+ res.writeHead(404, { 'content-type': 'application/json' })
186
+ res.end(JSON.stringify({ error: 'fixture route not found' }))
187
+ return
188
+ }
189
+ try {
190
+ const body = await readRequestJson(req)
191
+ const target = piFixtureTarget
192
+ const messages = Array.isArray(body.messages) ? body.messages : []
193
+ const toolNames = (Array.isArray(body.tools) ? body.tools : [])
194
+ .map(tool => String(tool?.function?.name ?? ''))
195
+ .filter(Boolean)
196
+ const roles = messages.map(message => String(message?.role ?? ''))
197
+ const toolMessages = messages.filter(message => String(message?.role ?? '') === 'tool')
198
+ const latestToolMessage = toolMessages.at(-1)
199
+ const returnedToolContent = latestToolMessage?.content
200
+ const returnedToolText = typeof returnedToolContent === 'string'
201
+ ? returnedToolContent
202
+ : JSON.stringify(returnedToolContent ?? '')
203
+ const callIndex = target ? piApiTrace.filter(item => item.scene === target.scene).length : 0
204
+ const requestId = `fixture-${target?.scene ?? 'unassigned'}-${callIndex + 1}`
205
+ const requestEvidence = {
206
+ requestId,
207
+ scene: target?.scene ?? null,
208
+ requestModel: safeText(body.model, 120),
209
+ apiPath: req.url,
210
+ loopbackPeer: req.socket.remoteAddress === '127.0.0.1' || req.socket.remoteAddress === '::ffff:127.0.0.1',
211
+ apiKeyMatchesLocalFixture: req.headers.authorization === 'Bearer local-fixture-key-not-a-secret',
212
+ streamRequested: body.stream === true,
213
+ toolNames,
214
+ messageRoles: roles,
215
+ toolResultMessageCount: toolMessages.length,
216
+ toolResultCallId: safeText(latestToolMessage?.tool_call_id ?? '', 120),
217
+ toolResultText: toolMessages.length ? safeText(returnedToolText, 1200) : null,
218
+ response: null,
219
+ }
220
+ if (!target || body.model !== PI_MODEL || !requestEvidence.loopbackPeer || !requestEvidence.apiKeyMatchesLocalFixture || body.stream !== true) {
221
+ throw new Error('model fixture rejected a request outside the expected loopback Pi custom-provider configuration')
222
+ }
223
+ const id = `chatcmpl-${requestId}`
224
+ if (callIndex === 0) {
225
+ const promptText = JSON.stringify(messages)
226
+ if (!toolNames.includes('recipe_trial')
227
+ || roles.includes('tool')
228
+ || !promptText.includes(target.recipeId)
229
+ || !promptText.includes(target.nodeId)
230
+ || !promptText.includes(String(target.value))) {
231
+ throw new Error(`${target.scene} initial Pi request did not include the registered recipe_trial declaration and task identifiers`)
232
+ }
233
+ const args = JSON.stringify({
234
+ recipe_id: target.recipeId,
235
+ params: [{ node_id: target.nodeId, value: target.value }],
236
+ hypothesis: 'Deterministic local fixture selection for a bounded simulator integration check.',
237
+ })
238
+ requestEvidence.response = { type: 'tool_call', toolName: 'recipe_trial', candidate: target.value }
239
+ piApiTrace.push(requestEvidence)
240
+ sendSse(res, [
241
+ chatChunk(id, { role: 'assistant' }),
242
+ chatChunk(id, { tool_calls: [{ index: 0, id: `call-${target.scene}`, type: 'function', function: { name: 'recipe_trial', arguments: args } }] }),
243
+ chatChunk(id, {}, 'tool_calls', { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }),
244
+ ])
245
+ return
246
+ }
247
+ if (callIndex === 1) {
248
+ if (!roles.includes('tool') || !toolNames.includes('recipe_trial')) {
249
+ throw new Error(`${target.scene} Pi follow-up request did not contain the platform tool result`)
250
+ }
251
+ if (toolMessages.length !== 1 || !requestEvidence.toolResultText || requestEvidence.toolResultCallId !== `call-${target.scene}`) {
252
+ throw new Error(`${target.scene} Pi follow-up did not preserve exactly one non-empty platform tool result`)
253
+ }
254
+ requestEvidence.response = { type: 'tool_call', toolName: 'complete_task', taskId: target.taskId }
255
+ piApiTrace.push(requestEvidence)
256
+ sendSse(res, [
257
+ chatChunk(id, { role: 'assistant' }),
258
+ chatChunk(id, { tool_calls: [{ index: 0, id: `complete-${target.scene}`, type: 'function', function: { name: 'complete_task', arguments: JSON.stringify({
259
+ task_id: target.taskId,
260
+ summary: 'Completed the bounded local simulator integration check after the approved recipe trial returned its verified command result.',
261
+ deliverable: `Task ${target.taskId}: the registered Pi host-tool bridge returned the recipe_trial result for candidate ${target.value}; this is integration evidence, not a process-improvement claim.`,
262
+ }) } }] }),
263
+ chatChunk(id, {}, 'tool_calls', { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }),
264
+ ])
265
+ return
266
+ }
267
+ if (callIndex === 2) {
268
+ if (!roles.includes('tool') || toolMessages.length !== 2 || !requestEvidence.toolResultText
269
+ || requestEvidence.toolResultCallId !== `complete-${target.scene}`
270
+ || !/COMPLETED/.test(requestEvidence.toolResultText)) {
271
+ throw new Error(`${target.scene} Pi follow-up did not preserve the successful complete_task result`)
272
+ }
273
+ requestEvidence.response = { type: 'final_text_after_task_completion' }
274
+ piApiTrace.push(requestEvidence)
275
+ sendSse(res, [
276
+ chatChunk(id, { role: 'assistant' }),
277
+ chatChunk(id, { content: 'The bounded simulator integration task is complete. The approved recipe trial returned a verified command result; no process improvement is claimed.' }),
278
+ chatChunk(id, {}, 'stop', { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }),
279
+ ])
280
+ return
281
+ }
282
+ throw new Error(`${target.scene} made an unexpected extra local model request`)
283
+ }
284
+ catch (error) {
285
+ const message = error instanceof Error ? error.message : String(error)
286
+ res.writeHead(400, { 'content-type': 'application/json' })
287
+ res.end(JSON.stringify({ error: { message: safeText(message, 300) } }))
288
+ }
289
+ })
290
+ await new Promise((resolvePromise, reject) => {
291
+ piApiServer.once('error', reject)
292
+ piApiServer.listen(MODEL_API_PORT, '127.0.0.1', resolvePromise)
293
+ })
294
+ const address = piApiServer.address()
295
+ if (!address || typeof address === 'string' || address.address !== '127.0.0.1' || address.port !== MODEL_API_PORT) {
296
+ throw new Error('local Pi model fixture did not bind exactly to the approved IPv4 loopback endpoint')
297
+ }
298
+ noteIsolation('local-pi-model-api-bound-loopback', true, { host: address.address, port: address.port, route: '/v1/chat/completions' })
299
+ }
300
+
301
+ function assertLoopbackUrl(url, expectedPort) {
302
+ const parsed = new URL(url)
303
+ if (parsed.protocol !== 'http:' || parsed.hostname !== '127.0.0.1' || Number(parsed.port) !== expectedPort || Number(parsed.port) === FORBIDDEN_PORT) {
304
+ throw new Error('network boundary rejected a non-approved loopback URL')
305
+ }
306
+ }
307
+
308
+ function fixtureTracePath(sceneId) {
309
+ if (!['cast-film', 'annealing'].includes(sceneId)) throw new Error('fixture trace scene is not approved')
310
+ const root = resolve(ROOT)
311
+ const tracePath = resolve(root, `fixture-${sceneId}.json`)
312
+ const relativePath = relative(root, tracePath)
313
+ if (isAbsolute(relativePath) || relativePath === '..' || relativePath.startsWith(`..${sep}`)) {
314
+ throw new Error('fixture trace path escaped the experiment root')
315
+ }
316
+ return tracePath
317
+ }
318
+
319
+ async function assertFreeLoopback(port, label) {
320
+ if (!Number.isInteger(port) || port < 1024 || port > 65535 || port === FORBIDDEN_PORT) {
321
+ throw new Error(`port allocation rejected for ${label}`)
322
+ }
323
+ const server = createServer()
324
+ await new Promise((resolvePromise, reject) => {
325
+ server.once('error', reject)
326
+ server.listen(port, '127.0.0.1', resolvePromise)
327
+ })
328
+ await new Promise(resolvePromise => server.close(resolvePromise))
329
+ }
330
+
331
+ async function preflight() {
332
+ if (VERSION !== '0.8.0') throw new Error(`expected current package version 0.8.0; found ${safeText(VERSION, 80)}`)
333
+ if (!existsSync(join(SIM_SOURCE, 'src', 'server', 'index.ts')) || !existsSync(join(SIM_SOURCE, 'node_modules')) || !existsSync(NUXT_CLI)
334
+ || !existsSync(PI_COMMAND) || !existsSync(PI_CLI_PACKAGE_PATH)) {
335
+ throw new Error('required registered Pi CLI, AgentWorkShop app, or simulator runtime is missing')
336
+ }
337
+ if (existsSync(HOME)) throw new Error('fresh AW_HOME path unexpectedly exists')
338
+ const mode = resolveRunMode({ cwd: REPO, packageRoot: REPO, env: { AW_HOME: HOME, AW_MODE: 'home' } })
339
+ if (mode.mode !== 'home' || resolve(mode.home) !== resolve(HOME) || resolve(mode.dataDir) !== resolve(join(HOME, 'data'))) {
340
+ throw new Error('AW_HOME did not resolve to a new isolated home-mode data directory')
341
+ }
342
+ noteIsolation('fresh-home-mode-resolution', true, { mode: mode.mode, dataDir: mode.dataDir })
343
+ for (const [label, port] of [['app', AW_PORT], ['simulator-http', SIM_PORT], ['local-model-api', MODEL_API_PORT], ['simulator-mqtt', MQTT_PORT], ['offline-app-mqtt-queue-probe', OFFLINE_APP_MQTT_QUEUE_PORT], ['offline-timescale-probe', OFFLINE_TSDB_PORT], ['offline-objectstore-probe', OFFLINE_OBJECTSTORE_PORT]]) {
344
+ await assertFreeLoopback(port, label)
345
+ noteIsolation(`${label}-free-loopback-port`, true, { port, host: '127.0.0.1' })
346
+ }
347
+ if ([AW_PORT, SIM_PORT, MODEL_API_PORT, MQTT_PORT].includes(FORBIDDEN_PORT)) {
348
+ throw new Error('forbidden service port appeared in explicit service configuration')
349
+ }
350
+ noteIsolation('project-version-and-local-inputs', true, {
351
+ version: VERSION,
352
+ simulatorSourcePresent: true,
353
+ piCommandPresent: true,
354
+ piVersion: JSON.parse(readFileSync(PI_CLI_PACKAGE_PATH, 'utf8')).version,
355
+ modelApiBoundToLoopback: true,
356
+ noExternalModelCredentialsRequired: true,
357
+ nuxtCliPresent: true,
358
+ noUserOrBusinessArchiveInput: true,
359
+ })
360
+ noteIsolation('strict-child-environment-allowlist', true, {
361
+ osKeys: CHILD_OS_ENV_KEYS,
362
+ harnessMode: HARNESS_MODE,
363
+ piAgentDirectoryIsolated: true,
364
+ piOfflineMode: true,
365
+ noStorageServiceEnvironment: true,
366
+ })
367
+ }
368
+
369
+ function cleanChildEnv(extra = {}) {
370
+ const env = {}
371
+ for (const key of CHILD_OS_ENV_KEYS) {
372
+ if (process.env[key] !== undefined) env[key] = process.env[key]
373
+ }
374
+ env.AW_HOME = HOME
375
+ env.AW_MODE = 'home'
376
+ env.AW_PROMPTS_DIR = ISOLATED_PROMPTS_DIR
377
+ env.HOME = HOME
378
+ env.PI_CODING_AGENT_DIR = PI_AGENT_DIR
379
+ env.PI_CODING_AGENT_SESSION_DIR = join(PI_AGENT_DIR, 'sessions')
380
+ env.PI_OFFLINE = '1'
381
+ env.NUXT_SESSION_PASSWORD = generatedSessionPassword
382
+ env.NO_PROXY = '127.0.0.1,localhost'
383
+ env.no_proxy = '127.0.0.1,localhost'
384
+ for (const [key, value] of Object.entries(extra)) {
385
+ if (!CHILD_EXTRA_ENV_KEYS.has(key)) throw new Error(`child environment rejected unsupported override ${key}`)
386
+ env[key] = String(value)
387
+ }
388
+ return env
389
+ }
390
+
391
+ function gitText(cwd, args) {
392
+ const result = spawnSync('git', args, {
393
+ cwd,
394
+ windowsHide: true,
395
+ encoding: 'utf8',
396
+ stdio: ['ignore', 'pipe', 'pipe'],
397
+ env: cleanChildEnv(),
398
+ })
399
+ if (result.error || result.status !== 0) {
400
+ throw new Error(`could not capture source identity: ${safeText(result.stderr || result.error?.message || result.status)}`)
401
+ }
402
+ return String(result.stdout ?? '').trim()
403
+ }
404
+
405
+ function hashGitFiles(cwd, roots) {
406
+ const names = gitText(cwd, ['ls-files', '-co', '--exclude-standard', '--', ...roots])
407
+ .split(/\r?\n/).filter(Boolean).sort()
408
+ if (names.length === 0) throw new Error(`source identity has no files under ${roots.join(', ')}`)
409
+ return hashFileList(cwd, names)
410
+ }
411
+
412
+ function hashFileList(cwd, names) {
413
+ const hash = createHash('sha256')
414
+ for (const name of names) {
415
+ hash.update(name.replaceAll('\\', '/') + '\0')
416
+ hash.update(readFileSync(join(cwd, name)))
417
+ hash.update('\0')
418
+ }
419
+ return { sha256: hash.digest('hex'), fileCount: names.length }
420
+ }
421
+
422
+ function hashDirectoryTree(root) {
423
+ if (!existsSync(root)) return hashFileList(root, [])
424
+ const names = []
425
+ const visit = (directory) => {
426
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
427
+ const absolute = join(directory, entry.name)
428
+ const name = relative(root, absolute).replaceAll('\\', '/')
429
+ if (entry.isSymbolicLink()) throw new Error(`source identity rejected symlink in plugin tree: ${name}`)
430
+ if (entry.isDirectory()) visit(absolute)
431
+ else if (entry.isFile()) names.push(name)
432
+ }
433
+ }
434
+ visit(root)
435
+ names.sort()
436
+ return hashFileList(root, names)
437
+ }
438
+
439
+ function pluginNamesUnder(root) {
440
+ if (!existsSync(root)) return []
441
+ return readdirSync(root, { withFileTypes: true })
442
+ .filter(entry => entry.isDirectory() && existsSync(join(root, entry.name, 'index.mjs')))
443
+ .map(entry => entry.name)
444
+ .sort()
445
+ }
446
+
447
+ function captureSourceIdentity() {
448
+ const appRoots = ['app', 'server', 'shared', 'mcp', 'cli', 'sdk', 'i18n', 'public', 'tsconfig.json', 'package.json', 'pnpm-lock.yaml', 'nuxt.config.ts', 'config.yml']
449
+ const simulatorRoots = ['src', 'package.json', 'package-lock.json']
450
+ const simulatorSourceFiles = gitText(SIM_SOURCE, ['ls-files', '-co', '--exclude-standard', '--', ...simulatorRoots])
451
+ .split(/\r?\n/).filter(Boolean).sort()
452
+ const executedSimulatorFiles = simulatorSourceFiles.filter(name => existsSync(join(SIM_ROOT, name)))
453
+ if (!executedSimulatorFiles.includes('src/server/index.ts') || !executedSimulatorFiles.includes('package.json')) {
454
+ throw new Error('executed simulator copy is missing required source files for provenance')
455
+ }
456
+ const projectPluginTree = hashDirectoryTree(join(REPO, '.AgentWorkShop', 'plugins'))
457
+ if (projectPluginTree.sha256 !== projectPluginTreeAtPrepare?.sha256) {
458
+ throw new Error('project plugin source changed after isolation was prepared')
459
+ }
460
+ const promptTree = hashDirectoryTree(ISOLATED_PROMPTS_DIR)
461
+ if (promptTree.sha256 !== promptTreeAtPrepare?.sha256) {
462
+ throw new Error('isolated prompt assets changed after isolation was prepared')
463
+ }
464
+ const piCliVersion = JSON.parse(readFileSync(PI_CLI_PACKAGE_PATH, 'utf8')).version
465
+ return {
466
+ recordedAt: new Date().toISOString(),
467
+ nodeVersion: process.version,
468
+ platform: process.platform,
469
+ architecture: process.arch,
470
+ app: {
471
+ version: VERSION,
472
+ gitHead: gitText(REPO, ['rev-parse', 'HEAD']),
473
+ sourceTree: hashGitFiles(REPO, appRoots),
474
+ workingTreeStatus: gitText(REPO, ['status', '--porcelain', '--', ...appRoots]),
475
+ packageManifestSha256: createHash('sha256').update(readFileSync(join(REPO, 'package.json'))).digest('hex'),
476
+ lockfileSha256: createHash('sha256').update(readFileSync(join(REPO, 'pnpm-lock.yaml'))).digest('hex'),
477
+ projectPluginTree,
478
+ projectPluginNames: pluginNamesUnder(join(REPO, '.AgentWorkShop', 'plugins')),
479
+ },
480
+ pluginIsolation: {
481
+ disabledNames: isolatedPluginNames,
482
+ enabledAllowlist: allowedEnabledPluginNames,
483
+ setupExpectedForOtherPlugins: false,
484
+ disabledStatePath: 'AW_HOME/plugins-state.json',
485
+ projectPluginNames: pluginNamesUnder(join(REPO, '.AgentWorkShop', 'plugins')),
486
+ projectPluginTree,
487
+ },
488
+ promptIsolation: {
489
+ sourceDirectory: 'repository/.AgentWorkShop/prompts',
490
+ isolatedDirectory: 'AW_HOME/prompts',
491
+ sourceTree: projectPromptTreeAtPrepare,
492
+ runtimeTree: promptTree,
493
+ },
494
+ experimentScriptSha256: createHash('sha256').update(readFileSync(fileURLToPath(import.meta.url))).digest('hex'),
495
+ registeredHarness: {
496
+ mode: HARNESS_MODE,
497
+ harness: 'pi',
498
+ command: PI_COMMAND,
499
+ piCliVersion,
500
+ provider: PI_PROVIDER,
501
+ model: PI_MODEL,
502
+ isolatedModelConfigSha256: createHash('sha256').update(readFileSync(PI_MODELS_PATH)).digest('hex'),
503
+ localModelFixtureSha256: createHash('sha256').update(readFileSync(fileURLToPath(import.meta.url))).digest('hex'),
504
+ externalCredentialsUsed: false,
505
+ },
506
+ simulator: {
507
+ gitlinkHead: gitText(REPO, ['rev-parse', 'HEAD:plc-node-simulator']),
508
+ gitHead: gitText(SIM_SOURCE, ['rev-parse', 'HEAD']),
509
+ sourceTree: hashGitFiles(SIM_SOURCE, simulatorRoots),
510
+ workingTreeStatus: gitText(SIM_SOURCE, ['status', '--porcelain', '--', ...simulatorRoots]),
511
+ executedTree: hashFileList(SIM_ROOT, executedSimulatorFiles),
512
+ lockfileSha256: createHash('sha256').update(readFileSync(join(SIM_SOURCE, 'package-lock.json'))).digest('hex'),
513
+ copyPatch: 'bind copied simulator HTTP and MQTT listeners to 127.0.0.1 and remap only their ports; source script hash records the transformation',
514
+ },
515
+ }
516
+ }
517
+
518
+ function prepareIsolatedHome() {
519
+ mkdirSync(join(HOME, 'data'), { recursive: true })
520
+ mkdirSync(join(PI_AGENT_DIR, 'sessions'), { recursive: true })
521
+ const piModels = {
522
+ providers: {
523
+ [PI_PROVIDER]: {
524
+ name: 'AgentWorkShop loopback deterministic fixture',
525
+ baseUrl: `http://127.0.0.1:${MODEL_API_PORT}/v1`,
526
+ apiKey: 'local-fixture-key-not-a-secret',
527
+ api: 'openai-completions',
528
+ models: [{
529
+ id: PI_MODEL,
530
+ name: 'AgentWorkShop deterministic paper fixture',
531
+ reasoning: false,
532
+ input: ['text'],
533
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
534
+ contextWindow: 64000,
535
+ maxTokens: 2048,
536
+ }],
537
+ },
538
+ },
539
+ }
540
+ writeFileSync(PI_MODELS_PATH, `${JSON.stringify(piModels, null, 2)}\n`, 'utf8')
541
+ assertLoopbackUrl(piModels.providers[PI_PROVIDER].baseUrl, MODEL_API_PORT)
542
+ noteIsolation('pi-custom-provider-isolated-to-local-fixture', true, {
543
+ configPath: 'AW_HOME/pi-agent/models.json',
544
+ provider: PI_PROVIDER,
545
+ model: PI_MODEL,
546
+ api: 'openai-completions',
547
+ baseUrl: piModels.providers[PI_PROVIDER].baseUrl,
548
+ apiKeyValueRecorded: false,
549
+ externalCredentialsUsed: false,
550
+ })
551
+ copyFileSync(join(REPO, 'config.yml'), join(HOME, 'config.yml'))
552
+ const overrides = {
553
+ 'daq.startInfrastructure': 'never',
554
+ 'daq.mqtt.host': '127.0.0.1',
555
+ 'daq.mqtt.port': OFFLINE_APP_MQTT_QUEUE_PORT,
556
+ 'daq.timescale.host': '127.0.0.1',
557
+ 'daq.timescale.port': OFFLINE_TSDB_PORT,
558
+ 'daq.objectstore.host': '127.0.0.1',
559
+ 'daq.objectstore.port': OFFLINE_OBJECTSTORE_PORT,
560
+ 'plugins.rag-bridge.base_url': RAG_BRIDGE_DISABLED_BASE_URL,
561
+ }
562
+ const runtimeSettingsPath = join(HOME, 'runtime-settings.json')
563
+ writeFileSync(runtimeSettingsPath, `${JSON.stringify({ version: 1, updatedAt: new Date().toISOString(), overrides }, null, 2)}\n`, 'utf8')
564
+ const savedOverrides = JSON.parse(readFileSync(runtimeSettingsPath, 'utf8')).overrides
565
+ if (savedOverrides?.['plugins.rag-bridge.base_url'] !== overrides['plugins.rag-bridge.base_url']) {
566
+ throw new Error('isolated runtime settings did not preserve the rag-bridge outbound-disable host guard setting')
567
+ }
568
+ const ragBridgeKvDir = join(HOME, 'data', 'plugins', 'rag-bridge')
569
+ mkdirSync(ragBridgeKvDir, { recursive: true })
570
+ const ragBridgeKvPath = join(ragBridgeKvDir, 'kv.json')
571
+ writeFileSync(ragBridgeKvPath, `${JSON.stringify({ 'kb.base_url': RAG_BRIDGE_DISABLED_BASE_URL }, null, 2)}\n`, 'utf8')
572
+ const savedRagBridgeKv = JSON.parse(readFileSync(ragBridgeKvPath, 'utf8'))
573
+ if (savedRagBridgeKv?.['kb.base_url'] !== RAG_BRIDGE_DISABLED_BASE_URL) {
574
+ throw new Error('isolated rag-bridge KV fallback did not preserve the outbound-disable host guard setting')
575
+ }
576
+ const projectPromptsRoot = join(REPO, '.AgentWorkShop', 'prompts')
577
+ if (!existsSync(projectPromptsRoot)) throw new Error('project prompt source directory is missing')
578
+ cpSync(projectPromptsRoot, ISOLATED_PROMPTS_DIR, { recursive: true })
579
+ projectPromptTreeAtPrepare = hashDirectoryTree(projectPromptsRoot)
580
+ promptTreeAtPrepare = hashDirectoryTree(ISOLATED_PROMPTS_DIR)
581
+ if (projectPromptTreeAtPrepare.sha256 !== promptTreeAtPrepare.sha256) {
582
+ throw new Error('isolated prompt copy differs from the repository prompt source')
583
+ }
584
+ writeFileSync(EMPTY_DOTENV, '', 'utf8')
585
+ const builtinPlugins = pluginNamesUnder(join(REPO, 'server', 'plugins-builtin'))
586
+ const projectPluginsRoot = join(REPO, '.AgentWorkShop', 'plugins')
587
+ const projectPlugins = pluginNamesUnder(projectPluginsRoot)
588
+ const userPlugins = pluginNamesUnder(join(HOME, 'plugins'))
589
+ expectedPluginNames = [...new Set([...builtinPlugins, ...projectPlugins, ...userPlugins])].sort()
590
+ isolatedPluginNames = expectedPluginNames.filter(name => !allowedEnabledPluginNames.includes(name))
591
+ projectPluginTreeAtPrepare = hashDirectoryTree(projectPluginsRoot)
592
+ const pluginStatePath = join(HOME, 'plugins-state.json')
593
+ writeFileSync(pluginStatePath, `${JSON.stringify({ version: 1, updatedAt: new Date().toISOString(), disabled: isolatedPluginNames }, null, 2)}\n`, 'utf8')
594
+ const savedPluginState = JSON.parse(readFileSync(pluginStatePath, 'utf8'))
595
+ if (JSON.stringify([...savedPluginState.disabled].sort()) !== JSON.stringify(isolatedPluginNames)) {
596
+ throw new Error('isolated plugin state did not disable every discovered plugin')
597
+ }
598
+ noteIsolation('isolated-runtime-config', true, {
599
+ configRoot: 'fresh isolated AW_HOME',
600
+ startInfrastructure: overrides['daq.startInfrastructure'],
601
+ simulatorMqttBroker: `127.0.0.1:${MQTT_PORT}`,
602
+ appMqttQueueProbe: `127.0.0.1:${OFFLINE_APP_MQTT_QUEUE_PORT}`,
603
+ offlineTimescaleProbe: `127.0.0.1:${OFFLINE_TSDB_PORT}`,
604
+ offlineObjectstoreProbe: `127.0.0.1:${OFFLINE_OBJECTSTORE_PORT}`,
605
+ ragBridgeOutboundGuardSetting: 'plugins.rag-bridge.base_url',
606
+ ragBridgeOutboundGuardConfigPresent: true,
607
+ ragBridgeOutboundGuardKvFallbackPresent: true,
608
+ emptyDotenv: true,
609
+ repoDotenvBypassed: true,
610
+ })
611
+ noteIsolation('pre-existing-plugin-scopes-disabled', true, {
612
+ builtinNames: builtinPlugins,
613
+ projectNames: projectPlugins,
614
+ userNames: userPlugins,
615
+ disabledStatePath: 'AW_HOME/plugins-state.json',
616
+ projectPluginTreeSha256: projectPluginTreeAtPrepare.sha256,
617
+ enabledPluginAllowlist: allowedEnabledPluginNames,
618
+ })
619
+ noteIsolation('project-prompt-assets-isolated', true, {
620
+ sourceDirectory: 'repository/.AgentWorkShop/prompts',
621
+ isolatedDirectory: 'AW_HOME/prompts',
622
+ sourceTreeSha256: projectPromptTreeAtPrepare.sha256,
623
+ runtimeTreeSha256: promptTreeAtPrepare.sha256,
624
+ awPromptsDir: 'AW_HOME/prompts',
625
+ })
626
+ }
627
+
628
+ async function assertPluginIsolation() {
629
+ const expectedNames = expectedPluginNames
630
+ let plugins = []
631
+ for (let attempt = 0; attempt < 40; attempt++) {
632
+ const result = requireSuccess(await app('GET', '/api/workshop/plugins'), 'isolated plugin manifest')
633
+ plugins = Array.isArray(result.plugins) ? result.plugins : []
634
+ const actualNames = plugins.map(plugin => plugin.name).sort()
635
+ if (JSON.stringify(actualNames) === JSON.stringify(expectedNames)) {
636
+ const enabledNames = plugins.filter(plugin => plugin.enabled === true).map(plugin => plugin.name).sort()
637
+ const enabledMatchesAllowlist = JSON.stringify(enabledNames) === JSON.stringify([...allowedEnabledPluginNames].sort())
638
+ const statesMatchPolicy = plugins.every(plugin => allowedEnabledPluginNames.includes(plugin.name)
639
+ ? plugin.enabled === true
640
+ : plugin.enabled === false)
641
+ check('only-outbound-disabled-rag-bridge-enabled', enabledMatchesAllowlist && statesMatchPolicy, {
642
+ names: actualNames,
643
+ enabledNames,
644
+ disabledNames: plugins.filter(plugin => plugin.enabled === false).map(plugin => plugin.name).sort(),
645
+ invalidStateNames: plugins.filter(plugin => typeof plugin.enabled !== 'boolean').map(plugin => plugin.name),
646
+ })
647
+ return
648
+ }
649
+ await delay(250)
650
+ }
651
+ throw new Error(`isolated plugin manifest differed from the expected built-in/user set: ${plugins.map(plugin => plugin.name).sort().join(', ')}`)
652
+ }
653
+
654
+ function spawnLogged(command, args, { cwd = REPO, env = cleanChildEnv(), logFd, label }) {
655
+ const child = spawn(command, args, {
656
+ cwd,
657
+ env,
658
+ stdio: ['ignore', logFd, logFd],
659
+ windowsHide: true,
660
+ detached: process.platform !== 'win32',
661
+ })
662
+ child.label = label
663
+ children.add(child)
664
+ child.once('exit', () => children.delete(child))
665
+ child.once('error', () => children.delete(child))
666
+ return child
667
+ }
668
+
669
+ async function waitForExit(child, timeoutMs = 8_000) {
670
+ if (!child || child.exitCode !== null || child.signalCode !== null) return
671
+ await Promise.race([
672
+ new Promise(resolvePromise => child.once('exit', resolvePromise)),
673
+ delay(timeoutMs),
674
+ ])
675
+ }
676
+
677
+ function processGroupExists(pid) {
678
+ try {
679
+ process.kill(-pid, 0)
680
+ return true
681
+ }
682
+ catch (error) {
683
+ if (error?.code === 'ESRCH') return false
684
+ if (error?.code === 'EPERM') return true
685
+ throw error
686
+ }
687
+ }
688
+
689
+ function windowsProcessExists(pid) {
690
+ const result = spawnSync('tasklist.exe', ['/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], {
691
+ windowsHide: true,
692
+ encoding: 'utf8',
693
+ stdio: ['ignore', 'pipe', 'ignore'],
694
+ env: cleanChildEnv(),
695
+ })
696
+ if (result.error || result.status !== 0) return null
697
+ return (result.stdout ?? '').split(/\r?\n/).some((line) => {
698
+ const columns = line.match(/^"(?:[^"]|"")*","(\d+)"(?:,|$)/)
699
+ return columns?.[1] === String(pid)
700
+ })
701
+ }
702
+
703
+ async function stopProcessTree(child, label) {
704
+ if (!child?.pid) return false
705
+ const wasAlreadyExited = child.exitCode !== null || child.signalCode !== null
706
+ let terminationStatus = null
707
+ try {
708
+ if (process.platform === 'win32' && child.pid) {
709
+ const result = spawnSync('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore', env: cleanChildEnv() })
710
+ terminationStatus = result.error ? 'spawn-error' : result.status
711
+ }
712
+ else if (process.platform !== 'win32' && child.pid) {
713
+ process.kill(-child.pid, 'SIGTERM')
714
+ }
715
+ }
716
+ catch { /* a process may have already exited */ }
717
+ await waitForExit(child)
718
+ if (process.platform !== 'win32' && processGroupExists(child.pid)) {
719
+ try {
720
+ process.kill(-child.pid, 'SIGKILL')
721
+ terminationStatus = 'SIGKILL'
722
+ }
723
+ catch { /* already gone */ }
724
+ }
725
+ else if (process.platform === 'win32' && windowsProcessExists(child.pid) === true) {
726
+ const result = spawnSync('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore', env: cleanChildEnv() })
727
+ terminationStatus = result.error ? 'spawn-error' : result.status
728
+ }
729
+ await waitForExit(child, 2_000)
730
+ let treePresent
731
+ if (process.platform === 'win32') treePresent = windowsProcessExists(child.pid)
732
+ else {
733
+ const deadline = Date.now() + 3_000
734
+ do {
735
+ treePresent = processGroupExists(child.pid)
736
+ if (!treePresent) break
737
+ await delay(100)
738
+ } while (Date.now() < deadline)
739
+ }
740
+ const pass = !wasAlreadyExited && treePresent === false && (process.platform !== 'win32' || terminationStatus === 0)
741
+ evidence.checks.push({
742
+ id: `${label}-process-stopped`,
743
+ status: pass ? 'pass' : 'fail',
744
+ detail: { pid: child.pid, terminationStatus, processTreePresentAfterCleanup: treePresent, rootWasAlreadyExited: wasAlreadyExited },
745
+ })
746
+ return pass
747
+ }
748
+
749
+ function buildHarnessShim() {
750
+ if (process.platform === 'win32') {
751
+ const compiler = [
752
+ join(process.env.WINDIR || 'C:\\Windows', 'Microsoft.NET', 'Framework64', 'v4.0.30319', 'csc.exe'),
753
+ join(process.env.WINDIR || 'C:\\Windows', 'Microsoft.NET', 'Framework', 'v4.0.30319', 'csc.exe'),
754
+ ].find(existsSync)
755
+ if (!compiler) throw new Error('Windows C# compiler unavailable; cannot safely launch a registered fixture executable')
756
+ const source = join(ROOT, 'omp-fixture-shim.cs')
757
+ wrapperPath = join(ROOT, 'omp-fixture-shim.exe')
758
+ writeFileSync(source, String.raw`using System;
759
+ using System.Diagnostics;
760
+ using System.IO;
761
+ using System.Linq;
762
+ using System.Text;
763
+ using System.Threading;
764
+ class OmpFixtureShim {
765
+ static string Quote(string value) {
766
+ var result = new StringBuilder("\"");
767
+ int backslashes = 0;
768
+ foreach (char c in value) {
769
+ if (c == '\\') { backslashes++; continue; }
770
+ if (c == '"') {
771
+ result.Append('\\', backslashes * 2 + 1);
772
+ result.Append('"');
773
+ }
774
+ else {
775
+ result.Append('\\', backslashes);
776
+ result.Append(c);
777
+ }
778
+ backslashes = 0;
779
+ }
780
+ result.Append('\\', backslashes * 2);
781
+ result.Append('"');
782
+ return result.ToString();
783
+ }
784
+ static void Copy(Stream source, Stream destination) {
785
+ byte[] buffer = new byte[4096];
786
+ int count;
787
+ while ((count = source.Read(buffer, 0, buffer.Length)) > 0) {
788
+ destination.Write(buffer, 0, count);
789
+ destination.Flush();
790
+ }
791
+ }
792
+ static int Main(string[] args) {
793
+ string node = Environment.GetEnvironmentVariable("AW_PAPER_FIXTURE_NODE");
794
+ string script = Environment.GetEnvironmentVariable("AW_PAPER_FIXTURE_SCRIPT");
795
+ if (String.IsNullOrWhiteSpace(node) || String.IsNullOrWhiteSpace(script)) return 125;
796
+ var psi = new ProcessStartInfo(node);
797
+ psi.UseShellExecute = false;
798
+ psi.CreateNoWindow = true;
799
+ psi.RedirectStandardInput = true;
800
+ psi.RedirectStandardOutput = true;
801
+ psi.RedirectStandardError = true;
802
+ psi.Arguments = Quote(script) + " " + String.Join(" ", args.Skip(2).Select(Quote));
803
+ using (var child = Process.Start(psi)) {
804
+ if (child == null) return 126;
805
+ var stdin = new Thread(() => {
806
+ try {
807
+ Copy(Console.OpenStandardInput(), child.StandardInput.BaseStream);
808
+ }
809
+ finally {
810
+ child.StandardInput.Close();
811
+ }
812
+ });
813
+ var stdout = new Thread(() => Copy(child.StandardOutput.BaseStream, Console.OpenStandardOutput()));
814
+ var stderr = new Thread(() => Copy(child.StandardError.BaseStream, Console.OpenStandardError()));
815
+ stdin.IsBackground = true;
816
+ stdout.IsBackground = true;
817
+ stderr.IsBackground = true;
818
+ stdin.Start();
819
+ stdout.Start();
820
+ stderr.Start();
821
+ child.WaitForExit();
822
+ stdout.Join();
823
+ stderr.Join();
824
+ return child.ExitCode;
825
+ }
826
+ }
827
+ }`.replace(/\n/g, '\n'), 'utf8')
828
+ const result = spawnSync(compiler, ['/nologo', '/target:exe', `/out:${wrapperPath}`, source], { cwd: ROOT, windowsHide: true, encoding: 'utf8', timeout: 30_000, env: cleanChildEnv() })
829
+ if (result.error || result.status !== 0 || !existsSync(wrapperPath)) {
830
+ throw new Error(`could not compile isolated OMP fixture shim: ${safeText(result.stderr || result.stdout || result.error?.message || result.status)}`)
831
+ }
832
+ return wrapperPath
833
+ }
834
+ if (process.platform === 'linux' || process.platform === 'darwin') {
835
+ wrapperPath = join(ROOT, 'omp-fixture-shim')
836
+ writeFileSync(wrapperPath, '#!/bin/sh\nshift 2\nexec "$AW_PAPER_FIXTURE_NODE" "$AW_PAPER_FIXTURE_SCRIPT" "$@"\n', 'utf8')
837
+ chmodSync(wrapperPath, 0o755)
838
+ return wrapperPath
839
+ }
840
+ throw new Error(`unsupported fixture shim platform ${process.platform}`)
841
+ }
842
+
843
+ function extractPayload(body) {
844
+ return body && typeof body === 'object' && Object.prototype.hasOwnProperty.call(body, 'data') ? body.data : body
845
+ }
846
+
847
+ async function request(base, expectedPort, method, path, body, { token, timeoutMs = 10_000 } = {}) {
848
+ assertLoopbackUrl(base, expectedPort)
849
+ if (!path.startsWith('/api/')) throw new Error('API path boundary rejected')
850
+ const response = await fetch(`${base}${path}`, {
851
+ method,
852
+ headers: {
853
+ ...(body === undefined ? {} : { 'content-type': 'application/json' }),
854
+ ...(token ? { authorization: `Bearer ${token}` } : {}),
855
+ },
856
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
857
+ signal: AbortSignal.timeout(timeoutMs),
858
+ })
859
+ const parsed = await response.json().catch(() => null)
860
+ return { status: response.status, body: parsed, data: extractPayload(parsed) }
861
+ }
862
+
863
+ const app = (method, path, body, opts = {}) => request(APP_BASE, AW_PORT, method, path, body, { token: opts.token ?? authToken, timeoutMs: opts.timeoutMs })
864
+ const sim = (method, path, body) => request(SIM_BASE, SIM_PORT, method, path, body, { timeoutMs: 8_000 })
865
+
866
+ function requireSuccess(result, label, status = 200) {
867
+ if (result.status !== status) {
868
+ const payload = result.body && typeof result.body === 'object' ? result.body : {}
869
+ throw new Error(`${label} returned HTTP ${result.status}: ${safeText(payload.message || payload.statusMessage || payload.code || 'no response detail')}`)
870
+ }
871
+ return result.data
872
+ }
873
+
874
+ async function bootSimulator() {
875
+ mkdirSync(SIM_ROOT, { recursive: true })
876
+ cpSync(join(SIM_SOURCE, 'src'), join(SIM_ROOT, 'src'), { recursive: true })
877
+ cpSync(join(SIM_SOURCE, 'package.json'), join(SIM_ROOT, 'package.json'))
878
+ const simulatorEntry = join(SIM_ROOT, 'src', 'server', 'index.ts')
879
+ const originalSource = readFileSync(simulatorEntry, 'utf8')
880
+ const listenCall = 'server.listen(PORT, () => resolve())'
881
+ const brokerCall = 'await startBroker(Number(process.env.MQTT_BROKER_PORT ?? 18830))'
882
+ if (originalSource.split(listenCall).length !== 2) throw new Error('simulator copied source did not contain exactly one expected listener call')
883
+ if (originalSource.split(brokerCall).length !== 2) throw new Error('simulator copied source did not contain exactly one expected broker startup call')
884
+ const loopbackListenCall = `server.listen(PORT, '127.0.0.1', () => {
885
+ const boundAddress = server.address()
886
+ if (!boundAddress || typeof boundAddress === 'string' || boundAddress.address !== '127.0.0.1' || boundAddress.port !== PORT) {
887
+ console.error('[paper-isolation] simulator listener address verification failed')
888
+ server.close(() => process.exit(70))
889
+ return
890
+ }
891
+ console.log('[paper-isolation] listener=' + boundAddress.address + ':' + boundAddress.port)
892
+ resolve()
893
+ })`
894
+ const loopbackSource = originalSource
895
+ .replace(listenCall, loopbackListenCall)
896
+ .replace(brokerCall, `await startBroker(Number(process.env.MQTT_BROKER_PORT ?? 18830), '127.0.0.1')`)
897
+ writeFileSync(simulatorEntry, loopbackSource, 'utf8')
898
+ const modules = join(SIM_SOURCE, 'node_modules')
899
+ symlinkSync(modules, join(SIM_ROOT, 'node_modules'), process.platform === 'win32' ? 'junction' : 'dir')
900
+ simProcess = spawnLogged(process.execPath, [join(REPO, 'node_modules', 'tsx', 'dist', 'cli.mjs'), join(SIM_ROOT, 'src', 'server', 'index.ts')], {
901
+ cwd: SIM_ROOT,
902
+ logFd: SIM_LOG_FD,
903
+ label: 'simulator',
904
+ env: cleanChildEnv({ SIM_PORT: String(SIM_PORT), MQTT_BROKER_PORT: String(MQTT_PORT) }),
905
+ })
906
+ for (let i = 0; i < 50; i++) {
907
+ if (simProcess.exitCode !== null) throw new Error(`simulator exited during startup (code ${simProcess.exitCode})`)
908
+ try {
909
+ const result = await sim('GET', '/api/nodes')
910
+ if (result.status === 200) {
911
+ const data = result.data
912
+ const expectedListener = `[paper-isolation] listener=127.0.0.1:${SIM_PORT}`
913
+ const simulatorLog = readFileSync(SIM_LOG, 'utf8')
914
+ const expectedBroker = `[mqtt-broker] 内置 broker 就绪 mqtt://127.0.0.1:${MQTT_PORT}`
915
+ if (!simulatorLog.includes(expectedListener)) throw new Error('simulator did not report the verified 127.0.0.1 HTTP listener address')
916
+ if (!simulatorLog.includes(expectedBroker) || simulatorLog.includes('内置 broker 启动失败')) {
917
+ throw new Error('simulator did not confirm its embedded loopback MQTT broker before application startup')
918
+ }
919
+ noteIsolation('simulator-listener-address-verified', true, { address: '127.0.0.1', port: SIM_PORT, copiedSourceOnly: true })
920
+ noteIsolation('simulator-mqtt-broker-loopback-ready', true, { address: '127.0.0.1', port: MQTT_PORT, brokerStartupConfirmed: true })
921
+ noteIsolation('simulator-local-http-ready', true, { version: 'local repository source', port: SIM_PORT, host: '127.0.0.1' })
922
+ return data
923
+ }
924
+ }
925
+ catch { /* the local simulator is still starting */ }
926
+ await delay(400)
927
+ }
928
+ throw new Error('isolated simulator startup timed out')
929
+ }
930
+
931
+ function normalizeLocalNetworkConfig(value, portMap, key = '') {
932
+ if (Array.isArray(value)) return value.map(item => normalizeLocalNetworkConfig(item, portMap, key))
933
+ if (!value || typeof value !== 'object') {
934
+ if (typeof value !== 'string') return value
935
+ if (/^[a-z][a-z\d+.-]*:\/\//i.test(value)) {
936
+ const parsed = new URL(value)
937
+ if (!['127.0.0.1', 'localhost', '::1'].includes(parsed.hostname)) throw new Error('simulator preset contains a non-loopback endpoint')
938
+ if (parsed.port && portMap.has(Number(parsed.port))) parsed.port = String(portMap.get(Number(parsed.port)))
939
+ parsed.hostname = '127.0.0.1'
940
+ return parsed.toString()
941
+ }
942
+ if (/(?:host|hostname|ip|address)$/i.test(key)) return '127.0.0.1'
943
+ return value
944
+ }
945
+ const out = {}
946
+ for (const [childKey, childValue] of Object.entries(value)) {
947
+ if (/^port$/i.test(childKey) && typeof childValue === 'number' && portMap.has(childValue)) {
948
+ out[childKey] = portMap.get(childValue)
949
+ }
950
+ else if (/(?:host|hostname|ip|address)$/i.test(childKey) && typeof childValue === 'string') {
951
+ out[childKey] = '127.0.0.1'
952
+ }
953
+ else {
954
+ out[childKey] = normalizeLocalNetworkConfig(childValue, portMap, childKey)
955
+ }
956
+ }
957
+ return out
958
+ }
959
+
960
+ async function simulatorScene(scene) {
961
+ const presetResponse = await sim('GET', `/api/presets/${encodeURIComponent(scene.preset)}`)
962
+ const blueprint = requireSuccess(presetResponse, `${scene.id} simulator preset`)
963
+ if (!blueprint?.plantModel || !Array.isArray(blueprint.nodes)) throw new Error(`${scene.id} simulator preset shape is invalid`)
964
+
965
+ const portMapByDeviceId = new Map()
966
+ const toCreate = []
967
+ let nextPort = 44_000 + evidence.experiment.scenes.length * 100
968
+ for (const raw of blueprint.nodes) {
969
+ const node = structuredClone(raw)
970
+ if ((node.protocol && /serial|rtu/i.test(String(node.protocol))) || /serialPort|comPort|devicePath/i.test(JSON.stringify(node.config ?? {}))) continue
971
+ node.config ||= {}
972
+ const oldPort = Number(node.config.port)
973
+ const portMap = new Map()
974
+ if (Number.isInteger(oldPort) && oldPort > 0) {
975
+ while (allocatedDevicePorts.includes(nextPort) || nextPort === FORBIDDEN_PORT) nextPort += 1
976
+ await assertFreeLoopback(nextPort, `${scene.id}-simulator-device`)
977
+ portMap.set(oldPort, nextPort)
978
+ allocatedDevicePorts.push(nextPort)
979
+ noteIsolation(`${scene.id}-device-port-free-loopback`, true, { port: nextPort, host: '127.0.0.1', protocol: node.protocol ?? 'unspecified' })
980
+ node.config.port = nextPort
981
+ nextPort += 1
982
+ }
983
+ node.config = normalizeLocalNetworkConfig(node.config, portMap)
984
+ if (node.protocol === 'mqtt' || /mqtt/i.test(String(node.protocol))) node.config.brokerUrl = `mqtt://127.0.0.1:${MQTT_PORT}`
985
+ portMapByDeviceId.set(node.id, portMap)
986
+ toCreate.push(node)
987
+ }
988
+ if (toCreate.length === 0) throw new Error(`${scene.id} simulator preset has no loopback-safe device nodes`)
989
+
990
+ for (const node of toCreate) {
991
+ const created = await sim('POST', '/api/nodes', node)
992
+ requireSuccess(created, `${scene.id} simulator device ${safeText(node.id, 80)}`)
993
+ }
994
+ const plant = { ...blueprint.plantModel, id: `${TAG}-${scene.id}`, seed: 42, timeScale: 1, truthExport: false }
995
+ const loaded = await sim('PUT', '/api/plant/config', { plantModel: plant, warm: true, upsert: true })
996
+ requireSuccess(loaded, `${scene.id} simulator plant model`)
997
+
998
+ const exports = []
999
+ for (const node of toCreate) {
1000
+ const result = await sim('GET', `/api/nodes/${encodeURIComponent(node.id)}/export`)
1001
+ const data = requireSuccess(result, `${scene.id} simulator export ${safeText(node.id, 80)}`)
1002
+ for (const item of data?.items ?? []) exports.push({ ...item, deviceId: node.id })
1003
+ }
1004
+ for (const item of exports) {
1005
+ item.driverConfig = normalizeLocalNetworkConfig(item.driverConfig ?? {}, portMapByDeviceId.get(item.deviceId) ?? new Map())
1006
+ for (const [key, value] of Object.entries(item.driverConfig)) {
1007
+ if (/^(?:host|hostname|ip|address)$/i.test(key) && !['127.0.0.1', 'localhost', '::1'].includes(String(value))) {
1008
+ throw new Error(`${scene.id} exported driver config escaped loopback boundary`)
1009
+ }
1010
+ }
1011
+ }
1012
+ const mv = exports.find(item => item.deviceId === scene.sourceDevice && item.signal === scene.mvSignal)
1013
+ const cv = exports.find(item => item.signal === scene.cvSignal)
1014
+ if (!mv || !cv) throw new Error(`${scene.id} simulator export lacks required MV/CV signals`)
1015
+ if (!['opcua', 'modbus-tcp'].includes(String(mv.driver))) throw new Error(`${scene.id} MV driver is outside the approved simulator protocol set`)
1016
+ const evidenceSignal = signal => Object.fromEntries(Object.entries(signal).filter(([key]) => key !== 'curl'))
1017
+ return {
1018
+ mv: evidenceSignal(mv),
1019
+ cv: evidenceSignal(cv),
1020
+ plant: { id: plant.id, kind: plant.kind ?? 'simulator', seed: 42, timeScale: 1 },
1021
+ deviceCount: toCreate.length,
1022
+ }
1023
+ }
1024
+
1025
+ async function registerAdmin() {
1026
+ const response = await app('POST', '/api/users/register', {
1027
+ name: `Paper Test ${TAG}`,
1028
+ email: `${TAG}@example.invalid`,
1029
+ password: `Paper-${Date.now()}-safe9`,
1030
+ }, { token: undefined })
1031
+ const data = requireSuccess(response, 'isolated synthetic administrator registration')
1032
+ if (!data?.token || data?.user?.role !== 'admin') throw new Error('fresh-home registration did not return its first administrator token')
1033
+ authToken = String(data.token)
1034
+ syntheticAdminId = String(data.user.id)
1035
+ return { id: syntheticAdminId, role: 'admin' }
1036
+ }
1037
+
1038
+ async function verifyRagBridgeOutboundDisabled() {
1039
+ const ragBridgeHealth = requireSuccess(await app('GET', '/api/plugins/rag-bridge/health'), 'rag-bridge outbound guard health check')
1040
+ const deadline = Date.now() + 3_000
1041
+ let startupLogConfirmed = false
1042
+ while (Date.now() < deadline) {
1043
+ startupLogConfirmed = /\[rag-bridge\].*出站调用已禁用:/.test(readFileSync(APP_LOG, 'utf8'))
1044
+ if (startupLogConfirmed) break
1045
+ await delay(100)
1046
+ }
1047
+ noteIsolation('rag-bridge-outbound-disabled', ragBridgeHealth?.outbound === false && startupLogConfirmed, {
1048
+ setting: 'plugins.rag-bridge.base_url',
1049
+ pluginHealthOutbound: ragBridgeHealth?.outbound ?? null,
1050
+ startupLogConfirmed,
1051
+ })
1052
+ }
1053
+
1054
+ function piFixtureSystemPrompt(scene, recipe, control, decisionStimulus) {
1055
+ const selected = Number(scene.fixtureCandidate)
1056
+ return [
1057
+ 'You are operating AgentWorkShop for a bounded integration test in a local process simulator.',
1058
+ `Process scene: ${scene.processDescription}.`,
1059
+ `Before task submission, the registered drivers measured the control at ${decisionStimulus.controlValue} ${control.unit} and the process variable at ${decisionStimulus.processValue} ${decisionStimulus.processUnit}.`,
1060
+ `The task target band is ${decisionStimulus.targetMin} to ${decisionStimulus.targetMax} ${decisionStimulus.processUnit}.`,
1061
+ `This local deterministic model fixture is configured to test one bounded candidate: ${selected} ${control.unit}. It is the only permitted value for this request.`,
1062
+ `Call recipe_trial exactly once with recipe_id "${recipe.id}", one params entry for node_id "${control.id}" and value ${selected}. State only that this is a deterministic integration fixture in hypothesis.`,
1063
+ 'After receiving the recipe_trial result, call complete_task exactly once on the active root task. Include the selected value and returned command-verification outcome in a concise summary and deliverable.',
1064
+ 'Do not make any other tool calls. Do not retry. Do not create, update, apply, or roll back a recipe. Do not claim that the trial improves or settles the process.',
1065
+ 'After the complete_task result, give a brief factual report and make no further tool calls.',
1066
+ ].join('\n')
1067
+ }
1068
+
1069
+ async function setupScene(scene, simDetails) {
1070
+ currentScene = scene.id
1071
+ currentStage = `${scene.id}:application-setup`
1072
+ const sceneEvidence = {
1073
+ id: scene.id,
1074
+ simulatorPreset: scene.preset,
1075
+ simulator: simDetails,
1076
+ status: 'running',
1077
+ approvals: [],
1078
+ runs: [],
1079
+ }
1080
+ evidence.experiment.scenes.push(sceneEvidence)
1081
+
1082
+ const line = requireSuccess(await app('POST', '/api/workshop/dcw/lines', {
1083
+ name: `${TAG}-${scene.id}`,
1084
+ description: 'Synthetic isolated paper integration run',
1085
+ simulated: true,
1086
+ simSceneId: scene.preset,
1087
+ controlMode: 'manual',
1088
+ }), `${scene.id} line creation`).line
1089
+ const product = requireSuccess(await app('POST', '/api/workshop/dcw/products', {
1090
+ name: `${TAG}-${scene.id}-product`, lineId: line.id,
1091
+ }), `${scene.id} product creation`).product
1092
+ const template = requireSuccess(await app('POST', '/api/workshop/dcw/templates', {
1093
+ name: `${TAG}-${scene.id}-control-template`,
1094
+ unit: simDetails.mv.unit,
1095
+ min: simDetails.mv.min,
1096
+ max: simDetails.mv.max,
1097
+ decimals: simDetails.mv.decimals ?? 0,
1098
+ }), `${scene.id} control template creation`).template
1099
+ const control = requireSuccess(await app('POST', '/api/workshop/dcw', {
1100
+ templateRef: template.key,
1101
+ name: `${TAG}-${scene.id}-control`,
1102
+ driver: simDetails.mv.driver,
1103
+ driverConfig: simDetails.mv.driverConfig,
1104
+ lineId: line.id,
1105
+ min: simDetails.mv.min,
1106
+ max: simDetails.mv.max,
1107
+ unit: simDetails.mv.unit,
1108
+ decimals: simDetails.mv.decimals ?? 0,
1109
+ stepLimit: 30,
1110
+ writeLockSeconds: 0,
1111
+ holdIntervalMs: 0,
1112
+ readIntervalMs: 500,
1113
+ semantics: `Bounded simulated ${scene.mvSignal} setpoint for integration evidence`,
1114
+ }), `${scene.id} control node creation`).node
1115
+ const daq = requireSuccess(await app('POST', '/api/workshop/daq', {
1116
+ templateRef: 'daq-temp-tc',
1117
+ name: `${TAG}-${scene.id}-daq-cv`,
1118
+ driver: simDetails.cv.driver,
1119
+ driverConfig: simDetails.cv.driverConfig,
1120
+ lineId: line.id,
1121
+ min: simDetails.cv.min,
1122
+ max: simDetails.cv.max,
1123
+ unit: simDetails.cv.unit,
1124
+ intervalMs: 1000,
1125
+ publishIntervalMs: 0,
1126
+ semantics: `Bounded simulated ${scene.cvSignal} controlled variable for run-tagged sampling`,
1127
+ }), `${scene.id} DAQ node creation`).node
1128
+ const recipe = requireSuccess(await app('POST', '/api/workshop/dcw/recipes', {
1129
+ name: `${TAG}-${scene.id}-recipe`,
1130
+ productId: product.id,
1131
+ params: [{ nodeId: control.id, templateRef: template.key, value: scene.baseline, min: simDetails.mv.min, max: simDetails.mv.max, stepLimit: 30 }],
1132
+ daqWindows: [{ nodeId: daq.id, min: simDetails.cv.min, max: simDetails.cv.max }],
1133
+ }), `${scene.id} recipe creation`).recipe
1134
+
1135
+ const start = requireSuccess(await app('POST', `/api/workshop/dcw/lines/${encodeURIComponent(line.id)}/start`, { recipeId: recipe.id }), `${scene.id} line start`)
1136
+ const runId = String(start.run?.id ?? '')
1137
+ if (!runId) throw new Error(`${scene.id} line start returned no run identifier`)
1138
+ sceneEvidence.activeRun = { id: runId, status: start.run?.status ?? null, startedAt: start.run?.startedAt ?? null, recipeId: start.run?.recipeId ?? recipe.id }
1139
+
1140
+ let decisionStimulus
1141
+ if (HARNESS_MODE === 'pi-local-fixture') {
1142
+ let controlRead
1143
+ let controlReadAttempts = 0
1144
+ do {
1145
+ controlRead = await app('POST', `/api/workshop/dcw/${encodeURIComponent(control.id)}/read`)
1146
+ controlReadAttempts += 1
1147
+ if (controlRead.status === 409 && controlReadAttempts < 3) await delay(500)
1148
+ } while (controlRead.status === 409 && controlReadAttempts < 3)
1149
+ const controlReadData = requireSuccess(controlRead, `${scene.id} pre-task control read`)
1150
+ const controlData = controlReadData?.outcome ?? controlReadData?.read ?? controlReadData
1151
+ const controlValue = Number(controlData?.value ?? controlData?.data?.value)
1152
+ let processProbeResponse
1153
+ let processProbeAttempts = 0
1154
+ do {
1155
+ processProbeResponse = await app('POST', `/api/workshop/daq/${encodeURIComponent(daq.id)}/test`)
1156
+ processProbeAttempts += 1
1157
+ if (processProbeResponse.status === 409 && processProbeAttempts < 3) await delay(500)
1158
+ } while (processProbeResponse.status === 409 && processProbeAttempts < 3)
1159
+ const processProbe = requireSuccess(processProbeResponse, `${scene.id} pre-task process probe`).test
1160
+ const processValue = Number(processProbe?.sampleValue)
1161
+ if (!Number.isFinite(controlValue) || processProbe?.ok !== true || !Number.isFinite(processValue)) {
1162
+ throw new Error(`${scene.id} pre-task protocol reads did not provide finite control and process values`)
1163
+ }
1164
+ decisionStimulus = {
1165
+ controlValue,
1166
+ processValue,
1167
+ processUnit: simDetails.cv.unit,
1168
+ targetMin: scene.targetMin,
1169
+ targetMax: scene.targetMax,
1170
+ allowedValues: [...scene.candidates],
1171
+ probeDriver: simDetails.cv.driver,
1172
+ probeLatencyMs: Number.isFinite(Number(processProbe.latencyMs)) ? Number(processProbe.latencyMs) : null,
1173
+ controlReadAttempts,
1174
+ processProbeAttempts,
1175
+ measuredAt: new Date().toISOString(),
1176
+ }
1177
+ sceneEvidence.decisionStimulus = decisionStimulus
1178
+ sceneEvidence.simulator.candidateChoices = [...scene.candidates]
1179
+ }
1180
+
1181
+ const channel = requireSuccess(await app('POST', '/api/workshop/channels', {
1182
+ name: `${TAG}-${scene.id}-harness-channel`,
1183
+ description: 'Registered Pi CLI with a local deterministic model API fixture for simulator integration evidence',
1184
+ }), `${scene.id} channel creation`)
1185
+ const agentConfig = {
1186
+ command: PI_COMMAND,
1187
+ cwd: HOME,
1188
+ baseUrl: APP_BASE,
1189
+ provider: PI_PROVIDER,
1190
+ model: PI_MODEL,
1191
+ promptTimeoutMs: PI_PROMPT_TIMEOUT_MS,
1192
+ systemPromptPrefix: piFixtureSystemPrompt(scene, recipe, control, decisionStimulus),
1193
+ }
1194
+ const agent = requireSuccess(await app('POST', `/api/workshop/channels/${encodeURIComponent(channel.channelId)}/agents`, {
1195
+ name: `${TAG}-${scene.id}-pi-local-fixture`,
1196
+ harness: 'pi',
1197
+ role: 'lead',
1198
+ config: agentConfig,
1199
+ }), `${scene.id} registered OMP lead creation`)
1200
+
1201
+ const recipeBinding = requireSuccess(await app('POST', '/api/workshop/agent-tools/bindings', {
1202
+ agentId: agent.id, nodeId: recipe.id, kind: 'recipe',
1203
+ }), `${scene.id} recipe binding`).binding
1204
+ const daqBinding = requireSuccess(await app('POST', '/api/workshop/agent-tools/bindings', {
1205
+ agentId: agent.id, nodeId: daq.id, kind: 'daq', mode: 'auto',
1206
+ }), `${scene.id} DAQ binding`).binding
1207
+ check(`${scene.id}-registered-pi`, agent.harness === 'pi' && Boolean(agent.id), { harness: agent.harness, agentId: agent.id, provider: PI_PROVIDER, model: PI_MODEL })
1208
+ check(`${scene.id}-manual-recipe-binding`, recipeBinding.kind === 'recipe' && recipeBinding.mode === 'manual', { kind: recipeBinding.kind, mode: recipeBinding.mode })
1209
+ check(`${scene.id}-daq-observation-binding`, daqBinding.kind === 'daq', { kind: daqBinding.kind })
1210
+
1211
+ sceneEvidence.entities = { lineId: line.id, productId: product.id, recipeId: recipe.id, controlNodeId: control.id, daqNodeId: daq.id, channelId: channel.channelId, agentId: agent.id }
1212
+ sceneEvidence.bindings = { recipe: { kind: recipeBinding.kind, mode: recipeBinding.mode }, daq: { kind: daqBinding.kind, mode: daqBinding.mode } }
1213
+ sceneEvidence.routePolicy = { tool: 'recipe_trial', emergency: false, cadenceBypass: false, recipeBindingMode: recipeBinding.mode }
1214
+ sceneEvidence.status = 'setup-complete'
1215
+ return { line, product, template, control, daq, recipe, channel, agent, runId, evidence: sceneEvidence }
1216
+ }
1217
+
1218
+ async function submitFixtureTask(context) {
1219
+ currentStage = `${context.evidence.id}:submit-lead-task`
1220
+ const sent = requireSuccess(await app('POST', `/api/workshop/channels/${encodeURIComponent(context.channel.channelId)}/tasks`, {
1221
+ title: `Isolated ${context.evidence.id} recipe_trial verification`,
1222
+ description: [
1223
+ `Execute the preconfigured isolated ${context.evidence.id} recipe_trial candidate exactly once and wait for synthetic human approval.`,
1224
+ 'After the verified recipe_trial result returns, call complete_task exactly once with a concise factual deliverable. Do not claim process improvement.',
1225
+ 'Do not make any other host-tool calls, retry, or create/update/apply/roll back a recipe.',
1226
+ ].join(' '),
1227
+ fromLabel: 'Synthetic isolated test driver',
1228
+ }), `${context.evidence.id} lead task submission`)
1229
+ context.evidence.taskId = sent.id ?? sent.task?.id ?? null
1230
+ if (piFixtureTarget) piFixtureTarget.taskId = context.evidence.taskId
1231
+ }
1232
+
1233
+ async function submitRealOmpTask(context) {
1234
+ currentStage = `${context.evidence.id}:submit-real-omp-task`
1235
+ const sent = requireSuccess(await app('POST', `/api/workshop/channels/${encodeURIComponent(context.channel.channelId)}/tasks`, {
1236
+ title: `R20 ${context.evidence.id} recipe_trial with explicit task closure`,
1237
+ description: [
1238
+ 'Use the measured process context in your registered system prompt to choose one candidate from its prevalidated set.',
1239
+ `Call recipe_trial exactly once with recipe_id ${context.recipe.id} and one params entry for node_id ${context.control.id} using your selected value.`,
1240
+ 'After receiving the recipe_trial result, call complete_task exactly once on the active root task shown in the supervision context. Include the selected value and returned command-verification outcome in a concise summary and deliverable.',
1241
+ 'Do not make any other tool calls. Do not retry, save, update, apply, or roll back a recipe. If no candidate is justified, abstain and explicitly close the task with that limitation.',
1242
+ ].join(' '),
1243
+ fromLabel: 'Synthetic isolated R20 test driver',
1244
+ }), `${context.evidence.id} real OMP lead task submission`)
1245
+ context.evidence.taskId = sent.id ?? sent.task?.id ?? null
1246
+ if (!context.evidence.taskId) throw new Error(`${context.evidence.id} real OMP task submission returned no task identifier`)
1247
+ }
1248
+
1249
+ function taskToolEvents(task) {
1250
+ const events = []
1251
+ for (const message of task?.history ?? []) {
1252
+ for (const part of message?.parts ?? []) {
1253
+ const text = typeof part?.text === 'string' ? part.text : ''
1254
+ const match = text.match(/^🔧\s+([a-z][a-z\d_]*)/i)
1255
+ if (!match) continue
1256
+ events.push({
1257
+ toolName: match[1],
1258
+ phase: /(?:✅\s*完成|❌\s*失败)/.test(text) ? 'result' : 'call',
1259
+ isError: /❌\s*失败/.test(text),
1260
+ messageId: message.messageId ?? null,
1261
+ text,
1262
+ })
1263
+ }
1264
+ }
1265
+ return events
1266
+ }
1267
+
1268
+ async function readRealOmpTask(context) {
1269
+ const result = await app('GET', `/api/workshop/tasks/${encodeURIComponent(context.evidence.taskId)}?channelId=${encodeURIComponent(context.channel.channelId)}`)
1270
+ if (result.status !== 200) throw new Error(`${context.evidence.id} task detail returned HTTP ${result.status}`)
1271
+ return result.data
1272
+ }
1273
+
1274
+ async function waitForRealOmpTaskCompletion(context) {
1275
+ const deadline = Date.now() + REAL_OMP_TASK_COMPLETION_TIMEOUT_MS
1276
+ let latest
1277
+ while (Date.now() < deadline) {
1278
+ latest = await readRealOmpTask(context)
1279
+ if (latest.state === 'COMPLETED') return latest
1280
+ if (['FAILED', 'CANCELED'].includes(latest.state)) {
1281
+ throw new Error(`${context.evidence.id} task reached ${latest.state} before completing the approved operation`)
1282
+ }
1283
+ await delay(500)
1284
+ }
1285
+ throw new Error(`${context.evidence.id} task did not reach COMPLETED within the bounded post-approval window (state=${latest?.state ?? 'unknown'})`)
1286
+ }
1287
+
1288
+ function assertSingleRealOmpCall(context, task) {
1289
+ const events = taskToolEvents(task)
1290
+ const calls = events.filter(event => event.phase === 'call')
1291
+ const recipeCalls = calls.filter(event => event.toolName === 'recipe_trial')
1292
+ const recipeResults = events.filter(event => event.toolName === 'recipe_trial' && event.phase === 'result')
1293
+ const completionCalls = calls.filter(event => event.toolName === 'complete_task')
1294
+ // The active lead turn is journaled through both the task-event mapper and
1295
+ // the supervisor listener. A single host invocation can therefore appear
1296
+ // twice in history; identical start text identifies that mirror. Route
1297
+ // ledgers below remain authoritative for the number of executed trials.
1298
+ const uniqueRecipeCalls = [...new Set(recipeCalls.map(event => event.text))]
1299
+ if (events.some(event => !['recipe_trial', 'complete_task'].includes(event.toolName))
1300
+ || recipeCalls.length < 1 || recipeCalls.length > 2 || uniqueRecipeCalls.length !== 1
1301
+ || recipeResults.length < 1 || recipeResults.length > 2 || recipeResults.some(event => event.isError)
1302
+ || completionCalls.length !== 1) {
1303
+ throw new Error(`${context.evidence.id} OMP task history must show one recipe_trial invocation (allowing its mirrored journal entry), a successful result, and one explicit task-completion call`)
1304
+ }
1305
+ return { events, calls: [recipeCalls[0]], results: [recipeResults[0]], completionCalls }
1306
+ }
1307
+
1308
+ async function approveRealOmpTrial(context) {
1309
+ currentStage = `${context.evidence.id}:await-real-omp-hitl-approval`
1310
+ const deadline = Date.now() + REAL_OMP_APPROVAL_TIMEOUT_MS
1311
+ let pending
1312
+ let latestTask
1313
+ while (Date.now() < deadline) {
1314
+ latestTask = await readRealOmpTask(context)
1315
+ if (['FAILED', 'CANCELED', 'COMPLETED'].includes(latestTask.state)) {
1316
+ throw new Error(`${context.evidence.id} task reached ${latestTask.state} before synthetic approval`)
1317
+ }
1318
+ const result = await app('GET', `/api/workshop/agent-tools/approvals?agentId=${encodeURIComponent(context.agent.id)}&scope=pending`)
1319
+ if (result.status === 200) {
1320
+ const matches = (result.data?.approvals ?? []).filter(item => item.agentId === context.agent.id && item.nodeId === `recipe:${context.recipe.id}` && item.status === 'pending')
1321
+ if (matches.length > 1) throw new Error(`${context.evidence.id} has multiple pending real OMP trial approvals`)
1322
+ if (matches.length === 1) {
1323
+ const payload = matches[0].payload
1324
+ const params = Array.isArray(payload?.params) ? payload.params : []
1325
+ const proposedValue = Number(params[0]?.to)
1326
+ const decisionStimulus = context.evidence.decisionStimulus
1327
+ const allowedValues = decisionStimulus?.allowedValues ?? []
1328
+ const isExpectedTrial = payload?.kind === 'recipe-gate'
1329
+ && payload?.op === 'trial'
1330
+ && payload?.recipeId === context.recipe.id
1331
+ && payload?.emergency !== true
1332
+ && payload?.emergency !== 'true'
1333
+ && params.length === 1
1334
+ && params[0]?.nodeId === context.control.id
1335
+ && Number.isFinite(proposedValue)
1336
+ && allowedValues.includes(proposedValue)
1337
+ && proposedValue >= Number(context.evidence.simulator.mv.min)
1338
+ && proposedValue <= Number(context.evidence.simulator.mv.max)
1339
+ && Math.abs(proposedValue - Number(decisionStimulus.controlValue)) <= 30
1340
+ if (!isExpectedTrial) throw new Error(`${context.evidence.id} refused a pending approval outside the registered recipe_trial candidate set`)
1341
+ context.evidence.simulator.candidate = proposedValue
1342
+ context.evidence.modelDecision = {
1343
+ source: 'registered OMP host-tool proposal, checked against current protocol reads and prevalidated set',
1344
+ controlValue: decisionStimulus.controlValue,
1345
+ processValue: decisionStimulus.processValue,
1346
+ targetBand: [decisionStimulus.targetMin, decisionStimulus.targetMax],
1347
+ allowedValues,
1348
+ selectedValue: proposedValue,
1349
+ selectionRationale: safeText(payload?.hypothesis ?? payload?.rationale ?? '', 400),
1350
+ selectedValueWithinRangeAndStep: true,
1351
+ }
1352
+ pending = matches[0]
1353
+ break
1354
+ }
1355
+ }
1356
+ await delay(500)
1357
+ }
1358
+ if (!pending) throw new Error(`${context.evidence.id} real OMP recipe_trial approval did not appear within the bounded window`)
1359
+ context.evidence.approvals.push({ id: pending.id, statusBeforeDecision: pending.status, nodeId: pending.nodeId, title: pending.title ?? null, candidateValue: context.evidence.simulator.candidate, decision: 'approve' })
1360
+ requireSuccess(await app('POST', `/api/workshop/agent-tools/approvals/${encodeURIComponent(pending.id)}/decide`, {
1361
+ approved: true,
1362
+ comment: 'Approved for the bounded R20 local simulator integration check.',
1363
+ }), `${context.evidence.id} synthetic real OMP HITL approval`)
1364
+ const history = await app('GET', `/api/workshop/agent-tools/approvals?agentId=${encodeURIComponent(context.agent.id)}&scope=history`)
1365
+ const finalApproval = (history.data?.approvals ?? []).find(item => item.id === pending.id)
1366
+ if (history.status !== 200 || finalApproval?.status !== 'approved' || finalApproval?.decidedBy !== syntheticAdminId) {
1367
+ throw new Error(`${context.evidence.id} real OMP HITL history did not confirm the synthetic administrator decision`)
1368
+ }
1369
+ context.evidence.approvals[0] = {
1370
+ ...context.evidence.approvals[0],
1371
+ statusAfterDecision: finalApproval.status,
1372
+ decisionActor: 'synthetic isolated administrator via protected approval API',
1373
+ commentRecorded: finalApproval.comment === 'Approved for the bounded R20 local simulator integration check.',
1374
+ }
1375
+ }
1376
+
1377
+ async function captureRealOmpUsage(context) {
1378
+ const unavailable = {
1379
+ source: 'not exposed by the channel queue endpoint',
1380
+ context: null,
1381
+ requestInputTokens: null,
1382
+ requestOutputTokens: null,
1383
+ costUsd: null,
1384
+ costAvailable: false,
1385
+ }
1386
+ if (!context?.channel?.channelId || !context?.agent?.id) return unavailable
1387
+ try {
1388
+ const queueResult = await app('GET', `/api/workshop/channels/${encodeURIComponent(context.channel.channelId)}/queue`)
1389
+ if (queueResult.status !== 200) return unavailable
1390
+ const queue = extractPayload(queueResult.body)
1391
+ const agentStatus = (Array.isArray(queue) ? queue : []).find(item => item.agentId === context.agent.id)
1392
+ const raw = agentStatus?.context
1393
+ if (!raw) return unavailable
1394
+ return {
1395
+ source: 'channel queue OMP context snapshot (not request-level billing)',
1396
+ context: {
1397
+ usedTokens: Number.isFinite(Number(raw.usedTokens)) ? Number(raw.usedTokens) : null,
1398
+ contextWindow: Number.isFinite(Number(raw.contextWindow)) ? Number(raw.contextWindow) : null,
1399
+ percent: Number.isFinite(Number(raw.percent)) ? Number(raw.percent) : null,
1400
+ compacting: raw.compacting === true,
1401
+ },
1402
+ requestInputTokens: null,
1403
+ requestOutputTokens: null,
1404
+ costUsd: null,
1405
+ costAvailable: false,
1406
+ }
1407
+ }
1408
+ catch { return unavailable }
1409
+ }
1410
+
1411
+ async function approvePendingTrial(context) {
1412
+ currentStage = `${context.evidence.id}:manual-hitl-approval`
1413
+ const deadline = Date.now() + 20_000
1414
+ let pending
1415
+ while (Date.now() < deadline) {
1416
+ const result = await app('GET', `/api/workshop/agent-tools/approvals?agentId=${encodeURIComponent(context.agent.id)}&scope=pending`)
1417
+ if (result.status === 200) {
1418
+ const matches = (result.data?.approvals ?? []).filter(item => item.agentId === context.agent.id && item.nodeId === `recipe:${context.recipe.id}` && item.status === 'pending')
1419
+ if (matches.length > 1) throw new Error(`${context.evidence.id} has multiple pending trial approvals`)
1420
+ if (matches.length === 1) {
1421
+ pending = matches[0]
1422
+ break
1423
+ }
1424
+ }
1425
+ await delay(400)
1426
+ }
1427
+ if (!pending) throw new Error(`${context.evidence.id} manual recipe_trial HITL approval did not appear within the bounded window`)
1428
+ const payload = pending.payload ?? {}
1429
+ const params = Array.isArray(payload.params) ? payload.params : []
1430
+ const proposedValue = Number(params[0]?.to)
1431
+ if (payload.kind !== 'recipe-gate'
1432
+ || payload.op !== 'trial'
1433
+ || payload.recipeId !== context.recipe.id
1434
+ || params.length !== 1
1435
+ || params[0]?.nodeId !== context.control.id
1436
+ || proposedValue !== Number(piFixtureTarget?.value)
1437
+ || payload.emergency === true
1438
+ || payload.emergency === 'true') {
1439
+ throw new Error(`${context.evidence.id} refused a Pi approval outside the scripted bounded recipe_trial request`)
1440
+ }
1441
+ context.evidence.simulator.candidate = proposedValue
1442
+ context.evidence.modelDecision = {
1443
+ source: 'registered Pi host-tool request generated by a deterministic loopback model fixture',
1444
+ controlValue: context.evidence.decisionStimulus?.controlValue ?? null,
1445
+ processValue: context.evidence.decisionStimulus?.processValue ?? null,
1446
+ targetBand: [context.evidence.decisionStimulus?.targetMin, context.evidence.decisionStimulus?.targetMax],
1447
+ allowedValues: context.evidence.decisionStimulus?.allowedValues ?? [],
1448
+ selectedValue: proposedValue,
1449
+ selectionRationale: safeText(payload.hypothesis ?? payload.rationale ?? '', 400),
1450
+ selectedValueWithinRangeAndStep: true,
1451
+ }
1452
+ context.evidence.approvals.push({ id: pending.id, taskId: context.evidence.taskId, statusBeforeDecision: pending.status, nodeId: pending.nodeId, candidateValue: proposedValue, title: pending.title ?? null, decision: 'approve' })
1453
+ const decided = await app('POST', `/api/workshop/agent-tools/approvals/${encodeURIComponent(pending.id)}/decide`, {
1454
+ approved: true,
1455
+ comment: 'Approved for the isolated deterministic simulator integration check.',
1456
+ })
1457
+ requireSuccess(decided, `${context.evidence.id} explicit HITL approval`)
1458
+ const history = await app('GET', `/api/workshop/agent-tools/approvals?agentId=${encodeURIComponent(context.agent.id)}&scope=history`)
1459
+ const finalApproval = (history.data?.approvals ?? []).find(item => item.id === pending.id)
1460
+ if (history.status !== 200 || finalApproval?.status !== 'approved' || finalApproval?.decidedBy !== syntheticAdminId) {
1461
+ throw new Error(`${context.evidence.id} HITL approval history failed to confirm the explicit administrator decision`)
1462
+ }
1463
+ context.evidence.approvals[0] = {
1464
+ ...context.evidence.approvals[0],
1465
+ statusAfterDecision: finalApproval.status,
1466
+ decisionActor: 'synthetic isolated administrator via protected approval API',
1467
+ commentRecorded: finalApproval.comment === 'Approved for the isolated deterministic simulator integration check.',
1468
+ }
1469
+ }
1470
+
1471
+ async function waitForPiTaskCompletion(context) {
1472
+ const deadline = Date.now() + PI_TASK_COMPLETION_TIMEOUT_MS
1473
+ let latest
1474
+ while (Date.now() < deadline) {
1475
+ latest = await readRealOmpTask(context)
1476
+ if (latest.assigneeId !== context.agent.id) {
1477
+ throw new Error(`${context.evidence.id} Pi task was not executed by its registered agent`)
1478
+ }
1479
+ if (latest.state === 'COMPLETED') return latest
1480
+ if (['FAILED', 'CANCELED'].includes(latest.state)) {
1481
+ throw new Error(`${context.evidence.id} Pi task reached ${latest.state} before returning the tool result`)
1482
+ }
1483
+ await delay(300)
1484
+ }
1485
+ throw new Error(`${context.evidence.id} Pi task did not complete within the bounded window (state=${latest?.state ?? 'unknown'})`)
1486
+ }
1487
+
1488
+ async function collectSceneEvidence(context) {
1489
+ currentStage = `${context.evidence.id}:collect-result-and-observations`
1490
+ let trace
1491
+ let toolName
1492
+ let toolText
1493
+ let toolIsError
1494
+ let realTask
1495
+ let realToolEvents
1496
+ if (HARNESS_MODE === 'pi-local-fixture') {
1497
+ const finalTask = await waitForPiTaskCompletion(context)
1498
+ const traceDeadline = Date.now() + 10_000
1499
+ let sceneRequests = piApiTrace.filter(item => item.scene === context.evidence.id)
1500
+ while (sceneRequests.length < 3 && Date.now() < traceDeadline) {
1501
+ await delay(100)
1502
+ sceneRequests = piApiTrace.filter(item => item.scene === context.evidence.id)
1503
+ }
1504
+ const proposal = sceneRequests[0]
1505
+ const recipeResult = sceneRequests[1]
1506
+ const completionResult = sceneRequests[2]
1507
+ const traceChecks = {
1508
+ exactlyThreeModelRequests: sceneRequests.length === 3,
1509
+ recipeTrialCall: proposal?.response?.type === 'tool_call' && proposal?.response?.toolName === 'recipe_trial',
1510
+ approvedCandidateMatches: Number(proposal?.response?.candidate) === Number(context.evidence.simulator.candidate),
1511
+ completionToolAvailable: proposal?.toolNames?.includes('complete_task') === true,
1512
+ recipeResultFollowedByTaskClosure: recipeResult?.response?.type === 'tool_call' && recipeResult?.response?.toolName === 'complete_task',
1513
+ recipeResultReturnedToPi: recipeResult?.toolResultCallId === `call-${context.evidence.id}` && recipeResult?.toolResultMessageCount === 1 && Boolean(recipeResult?.toolResultText),
1514
+ recipeResultWasSuccessful: !/(?:isError\s*[:=]\s*true|❌\s*失败|tool error)/i.test(recipeResult?.toolResultText ?? ''),
1515
+ completeTaskResultReturnedToPi: completionResult?.response?.type === 'final_text_after_task_completion'
1516
+ && completionResult?.toolResultCallId === `complete-${context.evidence.id}`
1517
+ && completionResult?.toolResultMessageCount === 2
1518
+ && /COMPLETED/.test(completionResult?.toolResultText ?? ''),
1519
+ }
1520
+ if (Object.values(traceChecks).some(passed => !passed)) {
1521
+ throw new Error(`${context.evidence.id} Pi model trace check failed: ${JSON.stringify(Object.fromEntries(Object.entries(traceChecks).filter(([, passed]) => !passed)))}`)
1522
+ }
1523
+ toolName = 'recipe_trial'
1524
+ toolText = recipeResult.toolResultText
1525
+ toolIsError = /(?:isError\s*[:=]\s*true|❌\s*失败|tool error)/i.test(toolText)
1526
+ context.evidence.modelExecution = {
1527
+ harness: 'registered Pi CLI adapter',
1528
+ provider: PI_PROVIDER,
1529
+ model: PI_MODEL,
1530
+ modelMode: 'deterministic local OpenAI-compatible fixture; no LLM or external provider',
1531
+ taskId: context.evidence.taskId,
1532
+ taskState: finalTask.state,
1533
+ taskCompleted: finalTask.state === 'COMPLETED',
1534
+ taskAssigneeMatchesRegisteredPi: finalTask.assigneeId === context.agent.id,
1535
+ modelApiRequests: sceneRequests.map(item => ({
1536
+ requestId: item.requestId,
1537
+ requestModel: item.requestModel,
1538
+ loopbackPeer: item.loopbackPeer,
1539
+ apiKeyMatchesLocalFixture: item.apiKeyMatchesLocalFixture,
1540
+ streamRequested: item.streamRequested,
1541
+ toolNames: item.toolNames,
1542
+ messageRoles: item.messageRoles,
1543
+ toolResultMessageCount: item.toolResultMessageCount,
1544
+ response: item.response,
1545
+ })),
1546
+ recipeTrialResultReturnedToPi: recipeResult.toolResultMessageCount === 1,
1547
+ completeTaskCallIssued: recipeResult.response.toolName === 'complete_task',
1548
+ completeTaskResultReturnedToPi: completionResult.toolResultMessageCount === 2,
1549
+ completeTaskResultConfirmed: /COMPLETED/.test(completionResult.toolResultText),
1550
+ }
1551
+ }
1552
+ else if (HARNESS_MODE === 'real-omp') {
1553
+ // The supervisor journals compact host-tool start/result events on the
1554
+ // active root task. Approval and operation ledgers remain authoritative
1555
+ // for the proposal and its execution.
1556
+ realTask = await waitForRealOmpTaskCompletion(context)
1557
+ if (realTask.assigneeId !== context.agent.id) throw new Error(`${context.evidence.id} real OMP task was not executed by its registered lead agent`)
1558
+ realToolEvents = assertSingleRealOmpCall(context, realTask)
1559
+ const channelMessages = requireSuccess(await app('GET', `/api/workshop/channels/${encodeURIComponent(context.channel.channelId)}/messages?limit=500`), `${context.evidence.id} channel task evidence`)
1560
+ const taskMessages = (Array.isArray(channelMessages) ? channelMessages : []).filter(message => message.taskId === context.evidence.taskId)
1561
+ const usage = await captureRealOmpUsage(context)
1562
+ context.evidence.modelExecution = {
1563
+ provider: REAL_OMP_PROVIDER,
1564
+ model: REAL_OMP_MODEL,
1565
+ taskId: context.evidence.taskId,
1566
+ taskState: realTask.state,
1567
+ taskArtifactCount: Array.isArray(realTask.artifacts) ? realTask.artifacts.length : 0,
1568
+ evidenceSource: 'registered OMP task history, approval payload, task state, and route-specific recipe/ACK records',
1569
+ hostToolCallEvents: realToolEvents.calls.length + realToolEvents.completionCalls.length,
1570
+ hostToolResultEvents: realToolEvents.results.length,
1571
+ taskCompletionToolCallEvents: realToolEvents.completionCalls.length,
1572
+ taskToolEvents: realToolEvents.events.map(event => ({ toolName: event.toolName, phase: event.phase, isError: event.isError })),
1573
+ hostToolEventHistoryAvailable: realToolEvents.events.length > 0,
1574
+ approvedProposalValue: context.evidence.modelDecision?.selectedValue ?? null,
1575
+ approvedProposalCount: context.evidence.approvals.length,
1576
+ channelEvidence: {
1577
+ source: 'GET /api/workshop/channels/:id/messages',
1578
+ taskMessageCount: taskMessages.length,
1579
+ agentMessageCount: taskMessages.filter(message => message.fromAgentId === context.agent.id).length,
1580
+ roles: [...new Set(taskMessages.map(message => safeText(message.role, 40)))],
1581
+ },
1582
+ usage,
1583
+ }
1584
+ }
1585
+ else if (HARNESS_MODE === 'fixture') {
1586
+ const tracePath = fixtureTracePath(context.evidence.id)
1587
+ const deadline = Date.now() + 20_000
1588
+ while (Date.now() < deadline) {
1589
+ if (existsSync(tracePath)) {
1590
+ try {
1591
+ trace = JSON.parse(readFileSync(tracePath, 'utf8'))
1592
+ }
1593
+ catch { /* fixture is rewriting a small JSON trace */ }
1594
+ }
1595
+ if (trace?.hostToolResults?.length) break
1596
+ await delay(300)
1597
+ }
1598
+ if (!trace) throw new Error(`${context.evidence.id} deterministic fixture did not create its trace`)
1599
+ if (trace.hostToolCalls?.length !== 1 || trace.hostToolCalls[0]?.toolName !== 'recipe_trial' || trace.hostToolResults?.length !== 1) {
1600
+ throw new Error(`${context.evidence.id} fixture trace did not show exactly one recipe_trial host_tool_call/result`)
1601
+ }
1602
+ const toolResult = trace.hostToolResults[0].result
1603
+ toolText = String(toolResult?.content?.[0]?.text ?? '')
1604
+ toolName = trace.hostToolCalls[0].toolName
1605
+ toolIsError = Boolean(toolResult?.isError)
1606
+ if (toolIsError || !/全部设备证实|下发并全部设备证实/.test(toolText)) {
1607
+ throw new Error(`${context.evidence.id} recipe_trial did not return a fully verified device ACK`)
1608
+ }
1609
+ }
1610
+
1611
+ const readback = await app('POST', `/api/workshop/dcw/${encodeURIComponent(context.control.id)}/read`)
1612
+ requireSuccess(readback, `${context.evidence.id} DCW readback`)
1613
+
1614
+ const runData = await app('GET', `/api/workshop/dcw/runs/${encodeURIComponent(context.runId)}/data`)
1615
+ requireSuccess(runData, `${context.evidence.id} active run data`)
1616
+ const logs = await app('GET', `/api/workshop/ops-logs?scope=line&lineId=${encodeURIComponent(context.line.id)}&recipeId=${encodeURIComponent(context.recipe.id)}&limit=100`)
1617
+ requireSuccess(logs, `${context.evidence.id} recipe operation log`)
1618
+ const recipeRows = (logs.data?.logs ?? [])
1619
+ .filter(row => String(row.action).startsWith('recipe.'))
1620
+ .map((row) => {
1621
+ let detail = row.detail
1622
+ if (!detail || typeof detail !== 'object' || Array.isArray(detail)) {
1623
+ try {
1624
+ const parsed = JSON.parse(String(row.detailJson ?? '{}'))
1625
+ detail = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {}
1626
+ }
1627
+ catch { detail = {} }
1628
+ }
1629
+ return { ...row, detail }
1630
+ })
1631
+ const trialRows = recipeRows.filter(row => row.action === 'recipe.trial')
1632
+ const trialAckRows = recipeRows.filter(row => row.action === 'recipe.dispatch.ack' && row.detail?.trial === true)
1633
+ const trialRow = trialRows[0]
1634
+ const ackRow = trialAckRows[0]
1635
+ const trialRunId = String(ackRow?.detail?.runId ?? '')
1636
+ if (trialRows.length !== 1 || trialAckRows.length !== 1 || !trialRunId || String(trialRow?.detail?.runId ?? '') !== trialRunId) {
1637
+ throw new Error(`${context.evidence.id} recipe log did not contain exactly one matching recipe.trial and trial ACK pair`)
1638
+ }
1639
+ if (HARNESS_MODE === 'real-omp' && context.evidence.approvals.length !== 1) {
1640
+ throw new Error(`${context.evidence.id} expected exactly one approved real OMP proposal`)
1641
+ }
1642
+ const trialRunData = await app('GET', `/api/workshop/dcw/runs/${encodeURIComponent(trialRunId)}/data`)
1643
+ requireSuccess(trialRunData, `${context.evidence.id} trial run data`)
1644
+ const ack = ackRow.detail?.ackSummary ?? null
1645
+ if (!ack || ack.total !== 1 || ack.verified !== 1 || ack.failed !== 0 || ack.unverified !== 0) {
1646
+ throw new Error(`${context.evidence.id} logged trial ACK is not one-of-one verified`)
1647
+ }
1648
+ const returnedTrialRun = trialRunData.data?.run
1649
+ const trialResults = returnedTrialRun?.results
1650
+ if (returnedTrialRun?.id !== trialRunId || !Array.isArray(trialResults) || trialResults.length !== 1 || trialResults[0]?.verify?.verdict !== 'verified' || trialResults[0]?.ok !== true) {
1651
+ throw new Error(`${context.evidence.id} trial run data lacks an independently verified write result`)
1652
+ }
1653
+
1654
+ const snapshotDelayStartedAt = new Date().toISOString()
1655
+ await delay(20_000)
1656
+ const probeStartedAt = new Date().toISOString()
1657
+ const probeResponse = await app('POST', `/api/workshop/daq/${encodeURIComponent(context.daq.id)}/test`)
1658
+ const probe = requireSuccess(probeResponse, `${context.evidence.id} DAQ driver probe`).test
1659
+ const sampleValue = Number(probe?.sampleValue)
1660
+ if (probe?.ok !== true || !Number.isFinite(sampleValue)) {
1661
+ throw new Error(`${context.evidence.id} DAQ driver probe did not return a finite simulator value`)
1662
+ }
1663
+ const probeCompletedAt = new Date().toISOString()
1664
+ const ingestAt = probeCompletedAt
1665
+ const ingest = requireSuccess(await app('POST', `/api/workshop/daq/${encodeURIComponent(context.daq.id)}/ingest`, {
1666
+ at: ingestAt,
1667
+ value: sampleValue,
1668
+ state: 'ok',
1669
+ }), `${context.evidence.id} DAQ snapshot ingest`)
1670
+ if (ingest?.accepted !== true || ingest.nodeId !== context.daq.id || ingest.lineId !== context.line.id) {
1671
+ throw new Error(`${context.evidence.id} DAQ snapshot ingest was not accepted for the expected node and line`)
1672
+ }
1673
+
1674
+ const persistedAt = String(ingest.at ?? ingestAt)
1675
+ const persistedAtMs = Date.parse(persistedAt)
1676
+ if (!Number.isFinite(persistedAtMs)) throw new Error(`${context.evidence.id} DAQ snapshot ingest returned an invalid sample timestamp`)
1677
+ const fromMs = persistedAtMs
1678
+ const toMs = persistedAtMs + 1
1679
+ // Let the in-process queue and SQLite batch flush settle before a fixed-window query;
1680
+ // retries outlast the short query-cache TTL if the first lookup is still empty.
1681
+ await delay(800)
1682
+ const queryDeadline = Date.now() + 12_000
1683
+ let taggedQuery
1684
+ let taggedSeries
1685
+ let snapshotBucketAt
1686
+ while (Date.now() < queryDeadline) {
1687
+ const candidate = await app('GET', `/api/workshop/daq/query?line_id=${encodeURIComponent(context.line.id)}&node_ids=${encodeURIComponent(context.daq.id)}&run_id=${encodeURIComponent(context.runId)}&from=${fromMs}&to=${toMs}&bucket_ms=1000`)
1688
+ if (candidate.status === 200) {
1689
+ taggedQuery = candidate
1690
+ taggedSeries = candidate.data?.series?.find(series => series.nodeId === context.daq.id)
1691
+ const bucketMs = Number(candidate.data?.window?.bucketMs) || 1_000
1692
+ snapshotBucketAt = Math.floor(persistedAtMs / bucketMs) * bucketMs
1693
+ const matchingPoint = taggedSeries?.points?.find(point => Number(point.at) === snapshotBucketAt && Math.abs(Number(point.v) - sampleValue) <= 0.01)
1694
+ if (matchingPoint && candidate.data?.activeRun?.runId === context.runId) break
1695
+ }
1696
+ await delay(300)
1697
+ }
1698
+ if (!taggedQuery || !taggedSeries?.points?.length || taggedQuery.data?.activeRun?.runId !== context.runId) {
1699
+ throw new Error(`${context.evidence.id} platform DAQ query returned no snapshot tagged to the active run`)
1700
+ }
1701
+ const matchingProbePoint = taggedSeries.points.find(point => Number(point.at) === snapshotBucketAt && Math.abs(Number(point.v) - sampleValue) <= 0.01)
1702
+ if (!matchingProbePoint) {
1703
+ throw new Error(`${context.evidence.id} run-tagged DAQ data did not contain the driver-probe snapshot value`)
1704
+ }
1705
+
1706
+ if (HARNESS_MODE === 'real-omp') {
1707
+ const finalTask = await readRealOmpTask(context)
1708
+ context.evidence.hostToolExecution = {
1709
+ provenance: 'registered OMP model proposal → protected synthetic approval → one recipe.trial and one verified DCW receipt',
1710
+ hostToolEventHistoryAvailable: realToolEvents.events.length > 0,
1711
+ taskStateAfterObservation: finalTask.state,
1712
+ taskCompleted: finalTask.state === 'COMPLETED',
1713
+ approvedProposalCount: context.evidence.approvals.length,
1714
+ recipeTrialCount: trialRows.length,
1715
+ recipeTrialAckCount: trialAckRows.length,
1716
+ toolName: 'recipe_trial',
1717
+ resultReceived: ack?.verified === 1 && ack?.failed === 0,
1718
+ }
1719
+ context.evidence.modelExecution.taskStateAfterObservation = finalTask.state
1720
+ context.evidence.modelExecution.taskCompleted = finalTask.state === 'COMPLETED'
1721
+ }
1722
+ else {
1723
+ context.evidence.fixtureTrace = {
1724
+ fixture: HARNESS_MODE === 'pi-local-fixture' ? 'registered Pi CLI with deterministic loopback model fixture' : trace.fixture,
1725
+ decisionSource: HARNESS_MODE === 'pi-local-fixture' ? 'Pi CLI tool call through the AgentWorkShop host-tool bridge' : trace.decisionSource,
1726
+ hostToolCallCount: HARNESS_MODE === 'pi-local-fixture' ? 1 : trace.hostToolCalls.length,
1727
+ toolName,
1728
+ resultReceived: HARNESS_MODE === 'pi-local-fixture' ? Boolean(context.evidence.modelExecution?.recipeTrialResultReturnedToPi) : trace.hostToolResults.length === 1,
1729
+ toolResultText: safeText(toolText, 1200),
1730
+ toolIsError,
1731
+ }
1732
+ }
1733
+ context.evidence.trial = {
1734
+ taskId: context.evidence.taskId,
1735
+ runId: trialRunId,
1736
+ toolName,
1737
+ approvalId: context.evidence.approvals[0].id,
1738
+ ackSummary: ack,
1739
+ resultCount: trialResults.length,
1740
+ resultRows: trialResults,
1741
+ }
1742
+ context.evidence.readback = {
1743
+ expectedCandidate: context.evidence.simulator.candidate,
1744
+ response: readback.data?.outcome ?? readback.data?.read ?? readback.data,
1745
+ resultMatchesCandidate: (() => {
1746
+ const details = readback.data?.outcome ?? readback.data?.read ?? readback.data ?? {}
1747
+ const observed = Number(details.value ?? details.data?.value ?? details.result?.value)
1748
+ return Number.isFinite(observed) && Math.abs(observed - context.evidence.simulator.candidate) <= 0.01
1749
+ })(),
1750
+ }
1751
+ context.evidence.daq = {
1752
+ taskId: context.evidence.taskId,
1753
+ nodeId: context.daq.id,
1754
+ method: 'single driver-probe/ingest snapshot',
1755
+ storageBackend: 'isolated AW_HOME SQLite time-series fallback',
1756
+ postTrialDelaySeconds: 20,
1757
+ snapshotDelayStartedAt,
1758
+ sampleCount: taggedSeries.points.length,
1759
+ runTags: [context.runId],
1760
+ expectedActiveRunId: context.runId,
1761
+ probe: {
1762
+ driver: context.daq.driver,
1763
+ startedAt: probeStartedAt,
1764
+ completedAt: probeCompletedAt,
1765
+ sampleValue,
1766
+ latencyMs: Number.isFinite(Number(probe.latencyMs)) ? Number(probe.latencyMs) : null,
1767
+ },
1768
+ ingest: {
1769
+ accepted: ingest.accepted,
1770
+ at: persistedAt,
1771
+ value: sampleValue,
1772
+ state: 'ok',
1773
+ },
1774
+ taggedQuery: {
1775
+ requestedRunId: context.runId,
1776
+ returnedRunId: taggedQuery.data?.activeRun?.runId ?? null,
1777
+ seriesPointCount: taggedSeries.points.length,
1778
+ probeValueMatched: true,
1779
+ snapshotBucketAt: new Date(snapshotBucketAt).toISOString(),
1780
+ matchingProbePoint,
1781
+ series: taggedSeries.points.slice(-5),
1782
+ },
1783
+ activeRunDataKeys: Object.keys(runData.data ?? {}),
1784
+ }
1785
+ context.evidence.recipeLog = {
1786
+ taskId: context.evidence.taskId,
1787
+ query: 'ops-logs filtered by lineId and recipeId (recipe_log-equivalent audit view)',
1788
+ rowCount: recipeRows.length,
1789
+ trialAction: trialRow.action,
1790
+ trialSummary: safeText(trialRow.summary, 600),
1791
+ ackAction: ackRow.action,
1792
+ ackSummary: safeText(ackRow.summary, 600),
1793
+ trialRunDataKeys: Object.keys(trialRunData.data ?? {}),
1794
+ }
1795
+ context.evidence.status = 'verified'
1796
+ context.evidence.traceability = {
1797
+ taskId: context.evidence.taskId,
1798
+ approvalId: context.evidence.approvals[0].id,
1799
+ recipeId: context.recipe.id,
1800
+ trialRunId,
1801
+ activeRunId: context.runId,
1802
+ daqNodeId: context.daq.id,
1803
+ sampleAt: persistedAt,
1804
+ taskState: context.evidence.modelExecution?.taskState ?? null,
1805
+ taskCompleted: context.evidence.modelExecution?.taskCompleted === true,
1806
+ }
1807
+ }
1808
+
1809
+ async function runScene(scene) {
1810
+ const simDetails = await simulatorScene(scene)
1811
+ const context = await setupScene(scene, { ...simDetails, candidate: scene.candidate })
1812
+ context.evidence.simulator.candidate = scene.candidate
1813
+ context.evidence.simulator.baseline = scene.baseline
1814
+ piFixtureTarget = {
1815
+ scene: context.evidence.id,
1816
+ recipeId: context.recipe.id,
1817
+ nodeId: context.control.id,
1818
+ value: scene.candidate,
1819
+ }
1820
+ await submitFixtureTask(context)
1821
+ await approvePendingTrial(context)
1822
+ await collectSceneEvidence(context)
1823
+ check(`${scene.id}-pi-task-completed`, context.evidence.modelExecution?.taskCompleted === true && context.evidence.modelExecution?.taskAssigneeMatchesRegisteredPi === true, {
1824
+ taskId: context.evidence.taskId,
1825
+ state: context.evidence.modelExecution?.taskState ?? null,
1826
+ assigneeMatchesRegisteredPi: context.evidence.modelExecution?.taskAssigneeMatchesRegisteredPi === true,
1827
+ })
1828
+ const linked = context.evidence.traceability?.taskId === context.evidence.taskId
1829
+ && context.evidence.approvals[0]?.taskId === context.evidence.taskId
1830
+ && context.evidence.trial?.taskId === context.evidence.taskId
1831
+ && context.evidence.daq?.taskId === context.evidence.taskId
1832
+ && context.evidence.traceability?.approvalId === context.evidence.approvals[0]?.id
1833
+ && context.evidence.traceability?.trialRunId === context.evidence.trial?.runId
1834
+ && context.evidence.traceability?.activeRunId === context.evidence.daq?.expectedActiveRunId
1835
+ && context.evidence.daq?.taggedQuery?.returnedRunId === context.evidence.daq?.expectedActiveRunId
1836
+ && Boolean(context.evidence.traceability?.sampleAt)
1837
+ check(`${scene.id}-task-approval-receipt-sample-linked`, linked, context.evidence.traceability)
1838
+ piFixtureTarget = null
1839
+ const stopped = await app('POST', `/api/workshop/dcw/lines/${encodeURIComponent(context.line.id)}/stop`)
1840
+ requireSuccess(stopped, `${scene.id} line stop`)
1841
+ context.evidence.activeRun.endedAt = stopped.data?.run?.endedAt ?? null
1842
+ check(`${scene.id}-host-dispatch-one-call`, context.evidence.fixtureTrace.hostToolCallCount === 1, { tool: context.evidence.fixtureTrace.toolName })
1843
+ check(`${scene.id}-ack-verified`, context.evidence.trial.ackSummary.verified === 1 && context.evidence.trial.ackSummary.failed === 0, context.evidence.trial.ackSummary)
1844
+ check(`${scene.id}-readback-matches`, context.evidence.readback.resultMatchesCandidate, context.evidence.readback)
1845
+ check(`${scene.id}-run-tagged-daq-probe-ingest-snapshot`, context.evidence.daq.taggedQuery.seriesPointCount >= 1 && context.evidence.daq.taggedQuery.probeValueMatched, {
1846
+ method: context.evidence.daq.method,
1847
+ value: context.evidence.daq.probe.sampleValue,
1848
+ runId: context.evidence.daq.expectedActiveRunId,
1849
+ matchingPoint: context.evidence.daq.taggedQuery.matchingProbePoint,
1850
+ })
1851
+ check(`${scene.id}-recipe-log`, context.evidence.recipeLog.rowCount >= 2, { trialAction: context.evidence.recipeLog.trialAction, ackAction: context.evidence.recipeLog.ackAction })
1852
+ }
1853
+
1854
+ async function recoverFailedRealOmpTrial(context, outcome) {
1855
+ const recovery = []
1856
+ if (context?.evidence?.taskId) {
1857
+ try {
1858
+ const task = await readRealOmpTask(context)
1859
+ if (!['COMPLETED', 'FAILED', 'CANCELED'].includes(task.state)) {
1860
+ const canceled = await app('POST', `/api/workshop/tasks/${encodeURIComponent(context.evidence.taskId)}/cancel`)
1861
+ recovery.push({ action: 'cancel-nonterminal-task', status: canceled.status === 200 ? 'completed' : `http-${canceled.status}` })
1862
+ }
1863
+ else recovery.push({ action: 'cancel-nonterminal-task', status: 'not-needed', taskState: task.state })
1864
+ }
1865
+ catch (error) { recovery.push({ action: 'cancel-nonterminal-task', status: 'failed', error: compactError(error) }) }
1866
+ }
1867
+ if (context?.channel?.channelId && context?.agent?.id) {
1868
+ try {
1869
+ const stopped = await app('POST', `/api/workshop/channels/${encodeURIComponent(context.channel.channelId)}/agents/${encodeURIComponent(context.agent.id)}/stop`)
1870
+ recovery.push({ action: 'stop-agent-runtime', status: stopped.status === 200 ? 'completed' : `http-${stopped.status}` })
1871
+ }
1872
+ catch (error) { recovery.push({ action: 'stop-agent-runtime', status: 'failed', error: compactError(error) }) }
1873
+ try {
1874
+ const pendingResult = await app('GET', `/api/workshop/agent-tools/approvals?agentId=${encodeURIComponent(context.agent.id)}&scope=pending`)
1875
+ const pending = pendingResult.status === 200
1876
+ ? (pendingResult.data?.approvals ?? []).filter(item => item.agentId === context.agent.id && item.status === 'pending')
1877
+ : []
1878
+ for (const approval of pending) {
1879
+ const denied = await app('POST', `/api/workshop/agent-tools/approvals/${encodeURIComponent(approval.id)}/decide`, {
1880
+ approved: false,
1881
+ comment: 'Denied during bounded R20 failure cleanup.',
1882
+ })
1883
+ recovery.push({ action: 'deny-pending-agent-approval', approvalId: approval.id, status: denied.status === 200 ? 'completed' : `http-${denied.status}` })
1884
+ }
1885
+ if (pendingResult.status !== 200) recovery.push({ action: 'deny-pending-agent-approval', status: `list-http-${pendingResult.status}` })
1886
+ else if (pending.length === 0) recovery.push({ action: 'deny-pending-agent-approval', status: 'not-needed' })
1887
+ }
1888
+ catch (error) { recovery.push({ action: 'deny-pending-agent-approval', status: 'failed', error: compactError(error) }) }
1889
+ }
1890
+ if (context?.line?.id) {
1891
+ try {
1892
+ const stopped = await app('POST', `/api/workshop/dcw/lines/${encodeURIComponent(context.line.id)}/stop`)
1893
+ recovery.push({ action: 'stop-line', status: stopped.status === 200 ? 'completed' : `http-${stopped.status}` })
1894
+ }
1895
+ catch (error) { recovery.push({ action: 'stop-line', status: 'failed', error: compactError(error) }) }
1896
+ }
1897
+ outcome.recovery = recovery
1898
+ }
1899
+
1900
+ async function runRealOmpScene(baseScene) {
1901
+ currentScene = baseScene.id
1902
+ let simDetails
1903
+ try {
1904
+ currentStage = `${baseScene.id}:simulator-setup-once`
1905
+ simDetails = await simulatorScene(baseScene)
1906
+ if (!Array.isArray(baseScene.candidates) || baseScene.candidates.length !== REAL_OMP_TRIALS_PER_SCENE
1907
+ || baseScene.candidates.some(candidate => !Number.isFinite(candidate)
1908
+ || candidate < Number(simDetails.mv.min)
1909
+ || candidate > Number(simDetails.mv.max)
1910
+ || Math.abs(candidate - baseScene.baseline) > 30)) {
1911
+ throw new Error(`${baseScene.id} real OMP candidates violate the configured count, process range, or 30-unit recipe step limit`)
1912
+ }
1913
+ }
1914
+ catch (error) {
1915
+ for (let repetition = 1; repetition <= REAL_OMP_TRIALS_PER_SCENE; repetition++) {
1916
+ const outcome = {
1917
+ id: `${baseScene.id}-r${repetition}`,
1918
+ scene: baseScene.id,
1919
+ repetition,
1920
+ provider: REAL_OMP_PROVIDER,
1921
+ model: REAL_OMP_MODEL,
1922
+ candidate: baseScene.candidates[repetition - 1],
1923
+ usage: { source: 'not available because simulator setup failed', context: null, requestInputTokens: null, requestOutputTokens: null, costUsd: null, costAvailable: false },
1924
+ costUsd: null,
1925
+ status: 'failed',
1926
+ failure: compactError(error),
1927
+ }
1928
+ evidence.experiment.runOutcomes.push(outcome)
1929
+ }
1930
+ return
1931
+ }
1932
+
1933
+ for (let repetition = 1; repetition <= REAL_OMP_TRIALS_PER_SCENE; repetition++) {
1934
+ const scene = { ...baseScene, id: `${baseScene.id}-r${repetition}` }
1935
+ const outcome = {
1936
+ id: scene.id,
1937
+ scene: baseScene.id,
1938
+ repetition,
1939
+ provider: REAL_OMP_PROVIDER,
1940
+ model: REAL_OMP_MODEL,
1941
+ candidate: null,
1942
+ candidateChoices: [...baseScene.candidates],
1943
+ usage: { source: 'not yet available', context: null, requestInputTokens: null, requestOutputTokens: null, costUsd: null, costAvailable: false },
1944
+ costUsd: null,
1945
+ status: 'running',
1946
+ startedAt: new Date().toISOString(),
1947
+ }
1948
+ evidence.experiment.runOutcomes.push(outcome)
1949
+ let context
1950
+ try {
1951
+ currentScene = scene.id
1952
+ const runSimDetails = { ...simDetails, candidateChoices: [...baseScene.candidates] }
1953
+ context = await setupScene(scene, runSimDetails)
1954
+ context.evidence.simulator.baseline = scene.baseline
1955
+ outcome.entities = context.evidence.entities
1956
+ outcome.runId = context.runId
1957
+ await submitRealOmpTask(context)
1958
+ outcome.taskId = context.evidence.taskId
1959
+ await approveRealOmpTrial(context)
1960
+ outcome.candidate = context.evidence.simulator.candidate
1961
+ outcome.modelDecision = context.evidence.modelDecision
1962
+ await collectSceneEvidence(context)
1963
+ const stopped = await app('POST', `/api/workshop/dcw/lines/${encodeURIComponent(context.line.id)}/stop`)
1964
+ requireSuccess(stopped, `${scene.id} line stop`)
1965
+ context.evidence.activeRun.endedAt = stopped.data?.run?.endedAt ?? null
1966
+ const finalTask = await readRealOmpTask(context)
1967
+ context.evidence.hostToolExecution.taskStateAfterObservation = finalTask.state
1968
+ context.evidence.hostToolExecution.taskCompleted = finalTask.state === 'COMPLETED'
1969
+ context.evidence.modelExecution.taskStateAfterObservation = finalTask.state
1970
+ context.evidence.modelExecution.taskCompleted = finalTask.state === 'COMPLETED'
1971
+ check(`${scene.id}-real-omp-approved-model-proposal`, context.evidence.modelExecution.approvedProposalCount === 1 && context.evidence.modelExecution.approvedProposalValue === context.evidence.simulator.candidate, {
1972
+ provider: REAL_OMP_PROVIDER,
1973
+ model: REAL_OMP_MODEL,
1974
+ selectedValue: context.evidence.modelExecution.approvedProposalValue,
1975
+ toolEventHistoryAvailable: context.evidence.modelExecution.hostToolEventHistoryAvailable,
1976
+ })
1977
+ check(`${scene.id}-real-omp-one-recipe-trial-ledger`, context.evidence.hostToolExecution.recipeTrialCount === 1 && context.evidence.hostToolExecution.recipeTrialAckCount === 1, {
1978
+ recipeTrialCount: context.evidence.hostToolExecution.recipeTrialCount,
1979
+ recipeTrialAckCount: context.evidence.hostToolExecution.recipeTrialAckCount,
1980
+ })
1981
+ check(`${scene.id}-ack-verified`, context.evidence.trial.ackSummary.verified === 1 && context.evidence.trial.ackSummary.failed === 0, context.evidence.trial.ackSummary)
1982
+ check(`${scene.id}-readback-matches`, context.evidence.readback.resultMatchesCandidate, context.evidence.readback)
1983
+ check(`${scene.id}-run-tagged-daq-probe-ingest-snapshot`, context.evidence.daq.taggedQuery.seriesPointCount >= 1 && context.evidence.daq.taggedQuery.probeValueMatched, {
1984
+ method: context.evidence.daq.method,
1985
+ value: context.evidence.daq.probe.sampleValue,
1986
+ runId: context.evidence.daq.expectedActiveRunId,
1987
+ matchingPoint: context.evidence.daq.taggedQuery.matchingProbePoint,
1988
+ })
1989
+ check(`${scene.id}-recipe-log`, context.evidence.recipeLog.rowCount >= 2, { trialAction: context.evidence.recipeLog.trialAction, ackAction: context.evidence.recipeLog.ackAction })
1990
+ check(`${scene.id}-real-omp-task-completed`, context.evidence.hostToolExecution.taskCompleted, {
1991
+ taskState: context.evidence.hostToolExecution.taskStateAfterObservation,
1992
+ })
1993
+ context.evidence.status = 'verified'
1994
+ outcome.status = context.evidence.hostToolExecution.taskCompleted ? 'verified' : 'verified-operation-task-incomplete'
1995
+ outcome.finishedAt = new Date().toISOString()
1996
+ outcome.trialRunId = context.evidence.trial.runId
1997
+ outcome.taskState = context.evidence.hostToolExecution.taskStateAfterObservation
1998
+ outcome.usage = context.evidence.modelExecution.usage
1999
+ outcome.costUsd = null
2000
+ outcome.evidenceSceneId = context.evidence.id
2001
+ }
2002
+ catch (error) {
2003
+ context && (context.evidence.status = 'failed')
2004
+ if (context) context.evidence.failure = compactError(error)
2005
+ outcome.status = 'failed'
2006
+ outcome.failure = compactError(error)
2007
+ outcome.finishedAt = new Date().toISOString()
2008
+ if (context) {
2009
+ outcome.usage = await captureRealOmpUsage(context)
2010
+ await recoverFailedRealOmpTrial(context, outcome)
2011
+ }
2012
+ }
2013
+ }
2014
+ }
2015
+
2016
+ async function startApplication() {
2017
+ currentStage = 'application-startup'
2018
+ await assertFreeLoopback(OFFLINE_APP_MQTT_QUEUE_PORT, 'offline-app-mqtt-queue-probe-before-startup')
2019
+ noteIsolation('offline-app-mqtt-queue-port-free-immediately-before-startup', true, {
2020
+ port: OFFLINE_APP_MQTT_QUEUE_PORT,
2021
+ host: '127.0.0.1',
2022
+ })
2023
+ appProcess = spawnLogged(process.execPath, [NUXT_CLI, 'dev', '--host', '127.0.0.1', '--port', String(AW_PORT), '--dotenv', EMPTY_DOTENV], {
2024
+ cwd: REPO,
2025
+ env: cleanChildEnv(),
2026
+ logFd: APP_LOG_FD,
2027
+ label: 'agentworkshop',
2028
+ })
2029
+ for (let i = 0; i < 90; i++) {
2030
+ if (appProcess.exitCode !== null) throw new Error(`AgentWorkShop startup exited (code ${appProcess.exitCode})`)
2031
+ try {
2032
+ const response = await app('GET', '/api/health', undefined, { token: undefined, timeoutMs: 2_000 })
2033
+ if (response.status === 200 && response.data?.status === 'ok' && response.data?.workshop === 'ready') {
2034
+ if (response.data?.version !== '0.8.0') throw new Error(`server reported unexpected version ${safeText(response.data?.version, 80)}`)
2035
+ noteIsolation('application-loopback-ready', true, { version: response.data.version, workshop: response.data.workshop, port: AW_PORT, host: '127.0.0.1' })
2036
+ return response.data
2037
+ }
2038
+ }
2039
+ catch (error) {
2040
+ if (error?.message?.startsWith('server reported unexpected version')) throw error
2041
+ }
2042
+ await delay(500)
2043
+ }
2044
+ throw new Error('isolated AgentWorkShop startup timed out or workshop manager did not become ready')
2045
+ }
2046
+
2047
+ async function main() {
2048
+ mkdirSync(join(REPO, '.omc'), { recursive: true })
2049
+ if (VERSION !== '0.8.0') throw new Error(`expected current package version 0.8.0; found ${VERSION}`)
2050
+ await preflight()
2051
+ prepareIsolatedHome()
2052
+ if (HARNESS_MODE === 'pi-local-fixture') {
2053
+ await startPiModelFixture()
2054
+ noteIsolation('registered-pi-fixture-configured', true, {
2055
+ command: PI_COMMAND,
2056
+ provider: PI_PROVIDER,
2057
+ model: PI_MODEL,
2058
+ localModelApi: `127.0.0.1:${MODEL_API_PORT}`,
2059
+ noExternalProvider: true,
2060
+ })
2061
+ }
2062
+ else if (HARNESS_MODE === 'fixture') {
2063
+ currentStage = 'compile-local-omp-fixture-shim'
2064
+ wrapperPath = buildHarnessShim()
2065
+ noteIsolation('registered-omp-fixture-launcher-ready', true, { platform: process.platform, wrapper: 'local process shim; fixture is deterministic' })
2066
+ }
2067
+ else {
2068
+ noteIsolation('registered-omp-real-provider-model-declared', true, {
2069
+ command: 'omp from allowlisted PATH',
2070
+ provider: REAL_OMP_PROVIDER,
2071
+ model: REAL_OMP_MODEL,
2072
+ cwd: 'fresh isolated AW_HOME',
2073
+ authSource: 'local OMP auth store; value is not inspected or added to evidence',
2074
+ discoveryDisabled: ['extensions', 'skills', 'rules'],
2075
+ credentialValuesExposedToRunnerOrEvidence: false,
2076
+ })
2077
+ }
2078
+ currentStage = 'simulator-startup'
2079
+ await bootSimulator()
2080
+ const health = await startApplication()
2081
+ evidence.experiment.server = { version: health.version, mode: health.mode, workshop: health.workshop, uptimeMsAtReady: health.uptimeMs }
2082
+ evidence.experiment.sourceIdentity = captureSourceIdentity()
2083
+ const admin = await registerAdmin()
2084
+ evidence.experiment.syntheticAdmin = admin
2085
+ await assertPluginIsolation()
2086
+ await verifyRagBridgeOutboundDisabled()
2087
+ const daqStatus = requireSuccess(await app('GET', '/api/workshop/daq', undefined, { timeoutMs: 45_000 }), 'isolated DAQ backend status')
2088
+ const settings = requireSuccess(await app('GET', '/api/system/settings'), 'effective runtime settings snapshot')
2089
+ const effectiveMqttHost = settings.effective?.['daq.mqtt.host']
2090
+ const effectiveMqttPort = Number(settings.effective?.['daq.mqtt.port'])
2091
+ const effectiveMqttPortSource = settings.sources?.['daq.mqtt.port']
2092
+ const effectiveInfrastructurePolicy = settings.effective?.['daq.startInfrastructure']
2093
+ const effectiveInfrastructurePolicySource = settings.sources?.['daq.startInfrastructure']
2094
+ const runtimeTargetMatches = effectiveMqttHost === '127.0.0.1'
2095
+ && effectiveMqttPort === OFFLINE_APP_MQTT_QUEUE_PORT
2096
+ && effectiveMqttPortSource === 'runtime'
2097
+ && effectiveInfrastructurePolicy === 'never'
2098
+ && effectiveInfrastructurePolicySource === 'runtime'
2099
+ check('runtime-settings-target-offline-loopback-queue', runtimeTargetMatches, {
2100
+ mqttHost: effectiveMqttHost ?? null,
2101
+ mqttPort: effectiveMqttPort,
2102
+ mqttPortSource: effectiveMqttPortSource ?? null,
2103
+ infrastructurePolicy: effectiveInfrastructurePolicy ?? null,
2104
+ infrastructurePolicySource: effectiveInfrastructurePolicySource ?? null,
2105
+ })
2106
+ check('isolated-inproc-queue-and-sqlite-tsdb', runtimeTargetMatches && daqStatus.meta?.queue === 'inproc' && daqStatus.meta?.tsdb === 'sqlite-emulated', {
2107
+ queue: daqStatus.meta?.queue ?? null,
2108
+ tsdb: daqStatus.meta?.tsdb ?? null,
2109
+ effectiveMqttHost,
2110
+ effectiveMqttPort,
2111
+ effectiveMqttPortSource,
2112
+ })
2113
+ noteIsolation('application-message-path-is-inproc', runtimeTargetMatches && daqStatus.meta?.queue === 'inproc', {
2114
+ queue: daqStatus.meta?.queue ?? null,
2115
+ effectiveMqttHost,
2116
+ effectiveMqttPort,
2117
+ effectiveMqttPortSource: effectiveMqttPortSource ?? null,
2118
+ simulatorMqttBrokerRemainsLoopback: `127.0.0.1:${MQTT_PORT}`,
2119
+ })
2120
+ evidence.isolation.result = 'passed'
2121
+ noteIsolation('application-env-and-dotenv-isolation', true, {
2122
+ launch: 'direct Nuxt CLI; dev-guard .env preload bypassed',
2123
+ dotenvFile: EMPTY_DOTENV,
2124
+ childEnvironmentAllowlisted: true,
2125
+ storageEndpointsRestrictedToFreeLoopbackPorts: true,
2126
+ })
2127
+
2128
+ const scenes = [
2129
+ {
2130
+ id: 'cast-film', preset: 'cast-film-physics', sourceDevice: 'dev-extruder-opcua',
2131
+ mvSignal: 'ScrewSpeedSP', cvSignal: 'thick', baseline: 120, fixtureCandidate: 125,
2132
+ processDescription: 'cast-film extrusion; screw speed affects measured film thickness',
2133
+ targetMin: 48, targetMax: 52,
2134
+ candidates: [125, 130, 135],
2135
+ },
2136
+ {
2137
+ id: 'annealing', preset: 'anneal-line', sourceDevice: 'anneal-heating-mbtcp',
2138
+ mvSignal: '均热区3炉温SP', cvSignal: 'StripTemp', baseline: 730, fixtureCandidate: 735,
2139
+ processDescription: 'continuous annealing; zone-3 furnace setpoint affects measured strip temperature',
2140
+ targetMin: 700, targetMax: 760,
2141
+ candidates: [735, 740, 745],
2142
+ },
2143
+ ]
2144
+ if (HARNESS_MODE === 'real-omp') {
2145
+ check('real-omp-six-unique-trials-planned', scenes.length * REAL_OMP_TRIALS_PER_SCENE === 6 && new Set(scenes.flatMap(scene => Array.from({ length: REAL_OMP_TRIALS_PER_SCENE }, (_, index) => `${scene.id}-r${index + 1}`))).size === 6, {
2146
+ scenes: scenes.map(scene => scene.id),
2147
+ repetitionsPerScene: REAL_OMP_TRIALS_PER_SCENE,
2148
+ })
2149
+ for (const scene of scenes) await runRealOmpScene(scene)
2150
+ const failedRuns = evidence.experiment.runOutcomes.filter(outcome => outcome.status !== 'verified')
2151
+ evidence.status = failedRuns.length === 0 ? 'passed' : 'failed'
2152
+ if (failedRuns.length) {
2153
+ evidence.failure = {
2154
+ stage: 'real-omp-trial-set',
2155
+ name: 'RealOmpTrialSetError',
2156
+ message: `${failedRuns.length} of ${evidence.experiment.runOutcomes.length} bounded real OMP trials failed`,
2157
+ failedRunIds: failedRuns.map(outcome => outcome.id),
2158
+ }
2159
+ evidence.isolation.result = 'incomplete'
2160
+ }
2161
+ }
2162
+ else {
2163
+ for (const scene of scenes) await runScene({ ...scene, candidate: scene.fixtureCandidate })
2164
+ evidence.status = 'passed'
2165
+ }
2166
+ }
2167
+
2168
+ async function cleanup() {
2169
+ currentStage = 'cleanup'
2170
+ const processResults = []
2171
+ const processByChild = new Map()
2172
+ if (appProcess) processByChild.set(appProcess, 'agentworkshop')
2173
+ if (simProcess) processByChild.set(simProcess, 'simulator')
2174
+ for (const child of children) if (!processByChild.has(child)) processByChild.set(child, child.label ?? 'child')
2175
+ for (const [child, label] of [...processByChild.entries()].reverse()) {
2176
+ try {
2177
+ const stopped = await stopProcessTree(child, label)
2178
+ processResults.push(stopped)
2179
+ if (!evidence.checks.some(item => item.id === `${label}-process-stopped`)) {
2180
+ evidence.checks.push({ id: `${label}-process-stopped`, status: 'fail', detail: { pid: child.pid ?? null, reason: 'process pid unavailable for termination verification' } })
2181
+ }
2182
+ }
2183
+ catch (error) {
2184
+ evidence.checks.push({ id: `${label}-process-stopped`, status: 'fail', detail: { pid: child.pid ?? null, error: compactError(error) } })
2185
+ processResults.push(false)
2186
+ }
2187
+ }
2188
+ if (piApiServer) {
2189
+ try {
2190
+ await new Promise((resolvePromise, reject) => {
2191
+ piApiServer.close(error => error ? reject(error) : resolvePromise())
2192
+ })
2193
+ piApiServer = null
2194
+ evidence.checks.push({ id: 'local-model-api-process-stopped', status: 'pass', detail: { host: '127.0.0.1', port: MODEL_API_PORT } })
2195
+ }
2196
+ catch (error) {
2197
+ evidence.checks.push({ id: 'local-model-api-process-stopped', status: 'fail', detail: { error: compactError(error) } })
2198
+ processResults.push(false)
2199
+ }
2200
+ }
2201
+ const portResults = []
2202
+ for (const [label, port] of [
2203
+ ['app', AW_PORT],
2204
+ ['simulator-http', SIM_PORT],
2205
+ ['local-model-api', MODEL_API_PORT],
2206
+ ['simulator-mqtt', MQTT_PORT],
2207
+ ['offline-app-mqtt-queue-probe', OFFLINE_APP_MQTT_QUEUE_PORT],
2208
+ ['offline-timescale-probe', OFFLINE_TSDB_PORT],
2209
+ ['offline-objectstore-probe', OFFLINE_OBJECTSTORE_PORT],
2210
+ ...allocatedDevicePorts.map((port, index) => [`simulator-device-${index}`, port]),
2211
+ ]) {
2212
+ try {
2213
+ await assertFreeLoopback(port, label)
2214
+ evidence.checks.push({ id: `${label}-port-released`, status: 'pass', detail: { port, host: '127.0.0.1' } })
2215
+ portResults.push(true)
2216
+ }
2217
+ catch (error) {
2218
+ evidence.checks.push({ id: `${label}-port-released`, status: 'fail', detail: { port, host: '127.0.0.1', error: compactError(error) } })
2219
+ portResults.push(false)
2220
+ }
2221
+ }
2222
+ try {
2223
+ closeSync(SIM_LOG_FD)
2224
+ }
2225
+ catch { /* already closed */ }
2226
+ try {
2227
+ closeSync(APP_LOG_FD)
2228
+ }
2229
+ catch { /* already closed */ }
2230
+ const requiredProcessLabels = evidence.status === 'passed' ? ['agentworkshop', 'simulator'] : [...processByChild.values()]
2231
+ const verifiedProcessLabels = new Set(evidence.checks.filter(item => item.id.endsWith('-process-stopped') && item.status === 'pass').map(item => item.id.replace(/-process-stopped$/, '')))
2232
+ const allRequiredProcessesVerified = requiredProcessLabels.every(label => verifiedProcessLabels.has(label))
2233
+ return processResults.every(Boolean) && portResults.every(Boolean) && allRequiredProcessesVerified
2234
+ }
2235
+
2236
+ try {
2237
+ await main()
2238
+ }
2239
+ catch (error) {
2240
+ const preflightFailed = currentStage === 'preflight' || currentStage === 'compile-local-omp-fixture-shim' || currentStage === 'simulator-startup'
2241
+ evidence.status = preflightFailed ? 'blocked' : 'failed'
2242
+ evidence.failure = { stage: currentStage, scene: currentScene ?? null, ...compactError(error) }
2243
+ if (evidence.isolation.result === 'pending') evidence.isolation.result = preflightFailed ? 'failed' : 'incomplete'
2244
+ }
2245
+ finally {
2246
+ const cleanupPassed = await cleanup()
2247
+ if (!cleanupPassed) {
2248
+ evidence.status = 'failed'
2249
+ evidence.isolation.result = 'failed'
2250
+ evidence.failure ??= { stage: 'cleanup', name: 'CleanupVerificationError', message: 'process stop or loopback port release verification failed' }
2251
+ evidence.failure.cleanupVerificationFailed = true
2252
+ }
2253
+ if (evidence.status === 'passed') {
2254
+ const failedChecks = [...evidence.checks, ...evidence.isolation.checks].filter(item => item.status !== 'pass')
2255
+ const cleanupChecks = evidence.checks.filter(item => RELEASE_CHECK_SUFFIXES.some(suffix => item.id.endsWith(suffix)))
2256
+ if (failedChecks.length || !cleanupChecks.length || cleanupChecks.some(item => item.status !== 'pass')) {
2257
+ evidence.status = 'failed'
2258
+ evidence.isolation.result = 'failed'
2259
+ evidence.failure ??= { stage: 'final-verification', name: 'FinalVerificationError', message: 'not all experiment and cleanup checks passed' }
2260
+ }
2261
+ }
2262
+ evidence.cleanup = { status: cleanupPassed ? 'passed' : 'failed', requiredProcessAndPortChecks: true }
2263
+ evidence.experiment.finishedAt = new Date().toISOString()
2264
+ evidence.experiment.evidencePath = 'evidence.json'
2265
+ evidence.experiment.runtimeLogPaths = { app: 'agentworkshop.log', simulator: 'simulator.log' }
2266
+ evidence.experiment.modelApiTrace = piApiTrace
2267
+ const sanitizeArchiveText = content => content
2268
+ .replaceAll(ROOT, '<isolated-run>')
2269
+ .replaceAll(HOME, '<isolated-home>')
2270
+ .replaceAll(REPO, '<workspace>')
2271
+ .replaceAll(PI_COMMAND, 'pi.cmd')
2272
+ .replace(/[A-Za-z0-9._%+-]+@example\.invalid/gi, '<synthetic-admin>')
2273
+ .replace(/[A-Z]:\\Users\\[^\\\s]+/gi, '<user-home>')
2274
+ try {
2275
+ mkdirSync(OUTPUT_DIR, { recursive: false })
2276
+ writeFileSync(PI_API_TRACE_PATH, `${JSON.stringify(piApiTrace, null, 2)}\n`, 'utf8')
2277
+ const archiveName = OUTPUT_DIR.slice(OUTPUT_DIR.lastIndexOf(sep) + 1)
2278
+ evidence.experiment.archiveDirectory = archiveName
2279
+ const archiveFiles = ['evidence.json', 'agentworkshop.log', 'simulator.log', 'pi-model-api-trace.json', 'e2e-pi-simulator-paper.mjs', 'README.md']
2280
+ evidence.experiment.archiveFiles = archiveFiles
2281
+ writeFileSync(EVIDENCE_PATH, `${JSON.stringify(evidence, null, 2)}\n`, 'utf8')
2282
+ const archivedEvidence = `${sanitizeArchiveText(JSON.stringify(evidence, null, 2))}\n`
2283
+ writeFileSync(join(OUTPUT_DIR, 'evidence.json'), archivedEvidence, 'utf8')
2284
+ writeFileSync(join(OUTPUT_DIR, 'agentworkshop.log'), sanitizeArchiveText(readFileSync(APP_LOG, 'utf8')), 'utf8')
2285
+ writeFileSync(join(OUTPUT_DIR, 'simulator.log'), sanitizeArchiveText(readFileSync(SIM_LOG, 'utf8')), 'utf8')
2286
+ copyFileSync(PI_API_TRACE_PATH, join(OUTPUT_DIR, 'pi-model-api-trace.json'))
2287
+ copyFileSync(fileURLToPath(import.meta.url), join(OUTPUT_DIR, 'e2e-pi-simulator-paper.mjs'))
2288
+ const readme = [
2289
+ '# R23 registered Pi CLI simulator evidence',
2290
+ '',
2291
+ `Run status: **${evidence.status}**.`,
2292
+ '',
2293
+ 'This archive was produced by a bounded local integration run of the registered Pi CLI adapter, its AgentWorkShop host-tool extension, the protected synthetic approval endpoint, and the loopback process simulator. The model endpoint is a deterministic OpenAI-compatible fixture bound to IPv4 loopback; no external model, provider, or service was called.',
2294
+ '',
2295
+ 'The fixture is scripted to issue one bounded `recipe_trial`, pass its returned host-tool result back into Pi, issue one explicit `complete_task`, and pass that result back into Pi. Device acknowledgement, direct readback, run-tagged DAQ sample persistence, task/approval/receipt/sample linkage, and process/port cleanup are recorded in `evidence.json` when observed.',
2296
+ '',
2297
+ 'The archived application and simulator logs contain runtime diagnostics with workspace and temporary-home paths and the synthetic admin email scrubbed. The Pi API trace contains request metadata and bounded tool-result text only; it omits prompts, credentials, session files, and the temporary isolated home.',
2298
+ '',
2299
+ evidence.failure ? `Recorded blocker/failure: ${safeText(evidence.failure.message, 500)} (stage: ${safeText(evidence.failure.stage, 120)}).` : 'No run blocker was recorded.',
2300
+ '',
2301
+ ].join('\n')
2302
+ writeFileSync(join(OUTPUT_DIR, 'README.md'), readme, 'utf8')
2303
+ writeFileSync(EVIDENCE_PATH, `${JSON.stringify(evidence, null, 2)}\n`, 'utf8')
2304
+ writeFileSync(join(OUTPUT_DIR, 'evidence.json'), `${sanitizeArchiveText(JSON.stringify(evidence, null, 2))}\n`, 'utf8')
2305
+ }
2306
+ catch (error) {
2307
+ evidence.status = 'failed'
2308
+ evidence.failure ??= { stage: 'evidence-archive', ...compactError(error) }
2309
+ writeFileSync(EVIDENCE_PATH, `${JSON.stringify(evidence, null, 2)}\n`, 'utf8')
2310
+ }
2311
+ console.log(`REGISTERED_HARNESS_E2E=${evidence.status}`)
2312
+ console.log(`EVIDENCE=${join(OUTPUT_DIR, 'evidence.json')}`)
2313
+ console.log(`STAGE=${evidence.failure?.stage ?? 'complete'}`)
2314
+ }
2315
+
2316
+ if (evidence.status !== 'passed') process.exitCode = evidence.status === 'blocked' ? 2 : 1