@covro/covro 0.9.1-dev.5 → 0.9.1-dev.7

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 (122) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +3 -3
  3. package/bin/process-darwin.js +192 -0
  4. package/bin/process-windows.ps1 +385 -0
  5. package/dist/codex/adapter.js +11 -0
  6. package/dist/codex/adapter.js.map +2 -2
  7. package/dist/codex/mapping.js +3 -5
  8. package/dist/codex/mapping.js.map +2 -2
  9. package/dist/codex/transport.js +1 -1
  10. package/dist/codex/transport.js.map +2 -2
  11. package/dist/server/http.js +40 -7
  12. package/dist/server/http.js.map +2 -2
  13. package/dist/server/main.js +36 -5
  14. package/dist/server/main.js.map +3 -3
  15. package/dist/server/preview/discovery.js +178 -0
  16. package/dist/server/preview/discovery.js.map +7 -0
  17. package/dist/server/preview/processes.js +199 -0
  18. package/dist/server/preview/processes.js.map +7 -0
  19. package/dist/server/preview/proxy.js +509 -0
  20. package/dist/server/preview/proxy.js.map +7 -0
  21. package/dist/server/preview/vite.js +552 -0
  22. package/dist/server/preview/vite.js.map +7 -0
  23. package/dist/server/preview/websockets.js +42 -0
  24. package/dist/server/preview/websockets.js.map +7 -0
  25. package/dist/server/preview/windows.js +222 -0
  26. package/dist/server/preview/windows.js.map +7 -0
  27. package/dist/server/service.js +25 -0
  28. package/dist/server/service.js.map +2 -2
  29. package/dist/shared/dev-preview.js +1 -0
  30. package/dist/shared/dev-preview.js.map +7 -0
  31. package/dist/shared/images.js +1 -9
  32. package/dist/shared/images.js.map +2 -2
  33. package/dist/shared/validation.js +2 -5
  34. package/dist/shared/validation.js.map +2 -2
  35. package/dist/web/assets/{abnfDiagram-WEYOIA3C-BBiv1f8v.js → abnfDiagram-WEYOIA3C-CHGfAjv6.js} +1 -1
  36. package/dist/web/assets/{arc-B0rlYjy6.js → arc-DJpI1IYs.js} +1 -1
  37. package/dist/web/assets/{architecture-WOLXFQ4H-goVkAf7a.js → architecture-WOLXFQ4H-DjAKKzT3.js} +1 -1
  38. package/dist/web/assets/{architectureDiagram-ZHVYKT53-CbgfFLcv.js → architectureDiagram-ZHVYKT53-CMO0IV8k.js} +1 -1
  39. package/dist/web/assets/{blockDiagram-RJAE7QA3-Ctbiu8c-.js → blockDiagram-RJAE7QA3-BgedNizy.js} +1 -1
  40. package/dist/web/assets/{c4Diagram-XDPPPE54-B707Q01X.js → c4Diagram-XDPPPE54-BpMidFMi.js} +1 -1
  41. package/dist/web/assets/channel-CSNXPgOa.js +1 -0
  42. package/dist/web/assets/{chunk-2E7WHVMD-ChUHcM-C.js → chunk-2E7WHVMD-BKRox4t-.js} +1 -1
  43. package/dist/web/assets/{chunk-4EMNKR2T-Cu6EQNcd.js → chunk-4EMNKR2T-ChhNCs1i.js} +1 -1
  44. package/dist/web/assets/{chunk-55XCU76K-BeSsXOjW.js → chunk-55XCU76K-BD-l1Tqy.js} +1 -1
  45. package/dist/web/assets/{chunk-7S6XSTFO-DKe5ojs-.js → chunk-7S6XSTFO-zt4UyG-J.js} +1 -1
  46. package/dist/web/assets/{chunk-AQDTSKZB-D2YU8x1E.js → chunk-AQDTSKZB-CXHcThzc.js} +1 -1
  47. package/dist/web/assets/{chunk-DSNLSHJZ-DyrPtMC-.js → chunk-DSNLSHJZ-DniRm3PO.js} +1 -1
  48. package/dist/web/assets/{chunk-HAGFOTED-BjsSVLT7.js → chunk-HAGFOTED-B4HHuYDL.js} +1 -1
  49. package/dist/web/assets/{chunk-HNE4Q36P-sprGs6sO.js → chunk-HNE4Q36P-ClHxhnNv.js} +1 -1
  50. package/dist/web/assets/{chunk-NQOKRVIF-BBJsUa0U.js → chunk-NQOKRVIF-Dif6SmUn.js} +1 -1
  51. package/dist/web/assets/{chunk-UHW7PFBP-tmTLG_lO.js → chunk-UHW7PFBP-Bwya0bo4.js} +1 -1
  52. package/dist/web/assets/{chunk-VQ5W62QI-CDKqdT_H.js → chunk-VQ5W62QI-D1BUpHO0.js} +1 -1
  53. package/dist/web/assets/{chunk-WQQL4CDK-BUshYxzd.js → chunk-WQQL4CDK-BEli-XYj.js} +1 -1
  54. package/dist/web/assets/{chunk-XXDRQBXY-DxJ56aAn.js → chunk-XXDRQBXY-rEcmeSVN.js} +1 -1
  55. package/dist/web/assets/{chunk-YZO67HFG-DGSBRQTW.js → chunk-YZO67HFG-BiyPfsjP.js} +1 -1
  56. package/dist/web/assets/{chunk-ZAUX2LTX-C-rgmqAx.js → chunk-ZAUX2LTX-9jrg_PBi.js} +1 -1
  57. package/dist/web/assets/{chunk-ZCHMQSOR-6Z2VPPl8.js → chunk-ZCHMQSOR-D6GD-IwA.js} +1 -1
  58. package/dist/web/assets/{classDiagram-v2-4MYWR3UA-akbIlLBv.js → classDiagram-v2-4MYWR3UA-DSaiNGAQ.js} +1 -1
  59. package/dist/web/assets/{cose-bilkent-JH36ORCC-U_Tv0K8m.js → cose-bilkent-JH36ORCC-CZ7fTVm6.js} +1 -1
  60. package/dist/web/assets/{cynefin-EF2NZ3EQ-BXB22y-W.js → cynefin-EF2NZ3EQ-BPCu20F8.js} +1 -1
  61. package/dist/web/assets/{cynefinDiagram-WF24UDRP-B9awMEeO.js → cynefinDiagram-WF24UDRP-C5P5QCVX.js} +1 -1
  62. package/dist/web/assets/{dagre-NK4GIZVX-DcS7FQT1.js → dagre-NK4GIZVX-z3YiAM0q.js} +1 -1
  63. package/dist/web/assets/{diagram-CBK3MWTC-DXwZQlMZ.js → diagram-CBK3MWTC-B-WhQdud.js} +1 -1
  64. package/dist/web/assets/{diagram-I5XIIV2D-CbhJZET1.js → diagram-I5XIIV2D-UEis_uQk.js} +1 -1
  65. package/dist/web/assets/{diagram-ODIL2UCW-CW2vzljs.js → diagram-ODIL2UCW-DiPx-4VZ.js} +1 -1
  66. package/dist/web/assets/{diagram-PFBEJUXE-CwopuVXe.js → diagram-PFBEJUXE-CYbBqLGP.js} +1 -1
  67. package/dist/web/assets/{diagram-RJA3I4VV-CGdcC1Lf.js → diagram-RJA3I4VV-Dt0NBTxu.js} +1 -1
  68. package/dist/web/assets/{diagram-TYUNFSNR-DCIuCUPZ.js → diagram-TYUNFSNR-DcC4GfC7.js} +1 -1
  69. package/dist/web/assets/{dist-C7wSSMaP.js → dist-BG6q-vl0.js} +1 -1
  70. package/dist/web/assets/{ebnfDiagram-V4P3TTPT-siHMLY5w.js → ebnfDiagram-V4P3TTPT-CAeb45Fr.js} +1 -1
  71. package/dist/web/assets/{elk-QONTBCTQ-BOlh-Urp.js → elk-QONTBCTQ-ab6Dq9I_.js} +1 -1
  72. package/dist/web/assets/{erDiagram-KYQIGQAA-u3rvrNNw.js → erDiagram-KYQIGQAA-ek-WnB6h.js} +1 -1
  73. package/dist/web/assets/{eventmodeling-K75KTNOO-eTPWHctK.js → eventmodeling-K75KTNOO-CHMXScY8.js} +1 -1
  74. package/dist/web/assets/flowDiagram-IUGLLWBU-wTK--SBO.js +1 -0
  75. package/dist/web/assets/{ganttDiagram-R7GPNTJY-X-5zRYiY.js → ganttDiagram-R7GPNTJY-BX8g0eO6.js} +1 -1
  76. package/dist/web/assets/{gitGraph-VSP46ZUC-BSDcI6zU.js → gitGraph-VSP46ZUC-DilpLMWy.js} +1 -1
  77. package/dist/web/assets/{gitGraphDiagram-PDYL7XHY-L_MOjo5v.js → gitGraphDiagram-PDYL7XHY-4tNl_3TA.js} +1 -1
  78. package/dist/web/assets/index-CBuODDCH.js +163 -0
  79. package/dist/web/assets/index-DcnXpHTD.css +1 -0
  80. package/dist/web/assets/{info-OHQRW6UA-HmHWnJIr.js → info-OHQRW6UA-BijRa20N.js} +1 -1
  81. package/dist/web/assets/{infoDiagram-MVDRKAX5-BkwJ8flk.js → infoDiagram-MVDRKAX5-CiPtyIRi.js} +1 -1
  82. package/dist/web/assets/{ishikawaDiagram-HPEHV2GE-Z2W5nUnD.js → ishikawaDiagram-HPEHV2GE-DYeIyyWs.js} +1 -1
  83. package/dist/web/assets/{journeyDiagram-BOSHW7O7-Bubkw1Zk.js → journeyDiagram-BOSHW7O7-CclDLdh5.js} +1 -1
  84. package/dist/web/assets/{kanban-definition-FNSA4HC5-DKvb7gco.js → kanban-definition-FNSA4HC5-BWUYWDuu.js} +1 -1
  85. package/dist/web/assets/{line-CMHyDiXM.js → line-Vva1bNhd.js} +1 -1
  86. package/dist/web/assets/{linear-DNsnBSmG.js → linear-C4Icgp0n.js} +1 -1
  87. package/dist/web/assets/{mermaid-parser.core-BMuKc5Ei.js → mermaid-parser.core-DPEPD1w0.js} +3 -3
  88. package/dist/web/assets/{mermaid.core-Dy2mpZ9E.js → mermaid.core-B847LfPl.js} +4 -4
  89. package/dist/web/assets/{mindmap-definition-6OY57UG3-D_pWpR0k.js → mindmap-definition-6OY57UG3-D8ZjuOhp.js} +1 -1
  90. package/dist/web/assets/{packet-JDAUHWVQ-BRLHLRBx.js → packet-JDAUHWVQ-1SWVWoVF.js} +1 -1
  91. package/dist/web/assets/{pegDiagram-ECIUJNBX-DkowYnT9.js → pegDiagram-ECIUJNBX-Bfsrg9yb.js} +1 -1
  92. package/dist/web/assets/{pie-XZMESJXO-BSYL2anB.js → pie-XZMESJXO-DLkLd_PY.js} +1 -1
  93. package/dist/web/assets/{pieDiagram-GNMPY74T-DyJLtExB.js → pieDiagram-GNMPY74T-BzU5Bxuh.js} +1 -1
  94. package/dist/web/assets/{quadrantDiagram-D57K4MC3-CNd5Ix--.js → quadrantDiagram-D57K4MC3-D8SBJpj9.js} +1 -1
  95. package/dist/web/assets/{radar-ABXABTNO-BP6462pW.js → radar-ABXABTNO-f1Vn3UyY.js} +1 -1
  96. package/dist/web/assets/{railroad-I3PHUGI6-GNdY9CjM.js → railroad-I3PHUGI6-DWLW9YST.js} +1 -1
  97. package/dist/web/assets/{railroad-abnf-LNEFI6M7-NZJKBBFx.js → railroad-abnf-LNEFI6M7-CWax04CS.js} +1 -1
  98. package/dist/web/assets/{railroad-ebnf-DWYD2UWJ-Bg12qvy8.js → railroad-ebnf-DWYD2UWJ-CcdoSrJU.js} +1 -1
  99. package/dist/web/assets/{railroad-peg-JR7BVNR7-ovPPHubp.js → railroad-peg-JR7BVNR7-B7_IGGWo.js} +1 -1
  100. package/dist/web/assets/{railroadDiagram-Y72NRBL7-3Yt4dZco.js → railroadDiagram-Y72NRBL7-BHNszMMH.js} +1 -1
  101. package/dist/web/assets/{requirementDiagram-EQYSW5RA-2uOMs75p.js → requirementDiagram-EQYSW5RA-VpR2McnE.js} +1 -1
  102. package/dist/web/assets/{sankeyDiagram-SY24JHO5-BVJ1-8W-.js → sankeyDiagram-SY24JHO5-C236Abx9.js} +1 -1
  103. package/dist/web/assets/{sequenceDiagram-BLEHNHQU-CCzBhfiJ.js → sequenceDiagram-BLEHNHQU-Bq80eolQ.js} +1 -1
  104. package/dist/web/assets/{src-Di0AoT-h.js → src-BMY2sE7X.js} +1 -1
  105. package/dist/web/assets/{stateDiagram-v2-A6IESKWZ-CXGDpFP6.js → stateDiagram-v2-A6IESKWZ-DcJXqUGS.js} +1 -1
  106. package/dist/web/assets/{swimlanes-B3ENRKFQ-BVFjP3x6.js → swimlanes-B3ENRKFQ-BmHhISp4.js} +1 -1
  107. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-DY2h9v2C.js +8 -0
  108. package/dist/web/assets/{timeline-definition-JXYKGLGB-hwXJeQmN.js → timeline-definition-JXYKGLGB-L6ZPgwGu.js} +1 -1
  109. package/dist/web/assets/{treeView-D4JQ5SDB-Dy7IQhAw.js → treeView-D4JQ5SDB-DRaK-ac0.js} +1 -1
  110. package/dist/web/assets/{treemap-SAJKECNS-_iDh5k0q.js → treemap-SAJKECNS-IDYB0yda.js} +1 -1
  111. package/dist/web/assets/{usecaseDiagram-WPOLBNNX-C90wGkut.js → usecaseDiagram-WPOLBNNX-N_233c9z.js} +1 -1
  112. package/dist/web/assets/{vennDiagram-Q3Y3IDCW-DqT1gc7d.js → vennDiagram-Q3Y3IDCW-DqYT5ejF.js} +1 -1
  113. package/dist/web/assets/{wardley-7MLQ67FV-OFJocMhL.js → wardley-7MLQ67FV-DG7J5a7V.js} +1 -1
  114. package/dist/web/assets/{wardleyDiagram-IVAIDKWA-DC4etOXS.js → wardleyDiagram-IVAIDKWA-CD1vWfZ3.js} +1 -1
  115. package/dist/web/assets/{xychartDiagram-4URNHDU4-sBgVfV5J.js → xychartDiagram-4URNHDU4-CyqC1p9t.js} +1 -1
  116. package/dist/web/index.html +2 -2
  117. package/package.json +7 -3
  118. package/dist/web/assets/channel-D_J5Q0fs.js +0 -1
  119. package/dist/web/assets/flowDiagram-IUGLLWBU-4GMof9_3.js +0 -1
  120. package/dist/web/assets/index-BLRNzJuV.css +0 -1
  121. package/dist/web/assets/index-yhnui6_i.js +0 -163
  122. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-qEIvZazI.js +0 -8
package/README.md CHANGED
@@ -29,9 +29,9 @@
29
29
 
30
30
  ## ✨ What you can do
31
31
 
32
- - 📱 **Follow tasks from any device.** Review changes, handle approvals, answer questions, and check [account quotas](docs/account-usage.md) and [session context usage](docs/runtime-settings.md#会话上下文与-token266) on desktop or mobile. Tasks keep running when you close the page; adjust session settings while work continues.
32
+ - 📱 **Follow tasks from any device.** Send screenshots, review changes, handle approvals, answer questions, and check [account quotas](docs/account-usage.md) and [session context usage](docs/runtime-settings.md#会话上下文与-token266) on desktop or mobile. Tasks keep running when you close the page; adjust session settings while work continues.
33
33
  - 🗂️ **Keep projects and conversations together.** Start without a project, track parallel tasks, resume or fork your Codex CLI conversations, and reference server workspace files with [@](docs/file-references.md) or skills with [$](docs/skills.md). Agents in managed sessions can start a new task in a registered project through Covro.
34
- - 📖 **Read results while you chat.** Preview documents, diagrams, and code changes beside the conversation on desktop, or full-screen on mobile. Submitted messages stay visible during context compaction, and loaded history stays complete as new responses stream in.
34
+ - 📖 **Read results while you chat.** Preview documents, diagrams, and code changes beside the conversation on desktop, or full-screen on mobile; on macOS, Linux and Windows x64 hosts, opt into the [development preview proxy](docs/dev-preview.md) to open session services in isolated tabs. Submitted messages stay visible during context compaction, and loaded history stays complete as new responses stream in.
35
35
  - 🔔 **Know when your attention is needed.** Enable browser notifications for completed work, questions, and approvals in a supported desktop or Android browser. Keep the page online; notifications are not pushed while it is frozen or closed.
36
36
 
37
37
  Find controls, shortcuts, and supported commands in the [usage guide · 中文](docs/usage.zh-CN.md), [command guide](docs/slash-commands.md), and [setting timing](docs/session-live-settings.md).
@@ -95,7 +95,7 @@ The host computer must stay awake and online. When adding projects remotely, ent
95
95
 
96
96
  ## Updates and release channels
97
97
 
98
- Choose stable, beta, or dev in the update panel or with `covro update`. Managed upgrades support **macOS and Linux npm global installations**; other installations use their original update method. Updates can also switch to a supported default Node environment with an existing global Covro installation, including the same Covro version. Compatibility checks use the Codex launch source for the target restart environment, while the panel keeps the running Codex version separate. Automatic installation is off by default and requires verified Codex compatibility; unverified combinations need explicit confirmation. While waiting for idle, automatic updates follow the latest eligible channel candidate and can be cancelled from the panel. Covro does not upgrade Codex CLI. See [updates and recovery](docs/distribution.md).
98
+ Choose stable, beta, or dev in the update panel or with `covro update`. Managed upgrades support **macOS and Linux npm global installations**; other installations use their original update method. Updates can also switch to a supported default Node environment with an existing global Covro installation, including the same Covro version. Automatic installation is off by default and requires verified Codex compatibility; unverified combinations need explicit confirmation. Covro does not upgrade Codex CLI. See [updates and recovery](docs/distribution.md).
99
99
 
100
100
  ## Your computer, your workspace
101
101
 
package/README.zh-CN.md CHANGED
@@ -29,9 +29,9 @@
29
29
 
30
30
  ## ✨ 你可以做什么
31
31
 
32
- - 📱 **随时随地跟进任务。** 用电脑或手机查看改动、[账户额度](docs/account-usage.md)与[会话上下文用量](docs/runtime-settings.md#会话上下文与-token266)、处理审批和回答问题。关闭页面,任务仍会继续;执行中也能调整会话配置。
32
+ - 📱 **随时随地跟进任务。** 用电脑或手机发送截图、查看改动、[账户额度](docs/account-usage.md)与[会话上下文用量](docs/runtime-settings.md#会话上下文与-token266)、处理审批和回答问题。关闭页面,任务仍会继续;执行中也能调整会话配置。
33
33
  - 🗂️ **集中管理项目与会话。** 无需项目即可开始任务,在一个工作台查看并行进展,接续或 Fork Codex CLI 会话,并用 [@](docs/file-references.md) 引用服务器工作区文件、用 [$](docs/skills.md) 引用技能。托管会话中的代理也能通过 Covro 在已注册项目中创建新任务。
34
- - 📖 **一边看产出,一边讨论。** 电脑上将文档、图表和代码变更与会话并排阅读,手机上使用全屏阅读器。上下文压缩期间仍可查看已提交消息,新回复实时到达时,已加载的历史正文保持完整。
34
+ - 📖 **一边看产出,一边讨论。** 电脑上将文档、图表和代码变更与会话并排阅读,手机上使用全屏阅读器;macOS、Linux 和 Windows x64 主机还可按需启用[开发预览代理](docs/dev-preview.zh-CN.md),在隔离标签页中打开会话的开发服务。上下文压缩期间仍可查看已提交消息,新回复实时到达时,已加载的历史正文保持完整。
35
35
  - 🔔 **及时收到待办提醒。** 在支持通知的桌面或 Android 浏览器中,接收工作结束、需要回答或审批的提醒。需保持页面在线;页面冻结或关闭期间不推送通知。
36
36
 
37
37
  操作、快捷键和命令用法见[使用指南](docs/usage.zh-CN.md)、[Slash 命令说明](docs/slash-commands.md)和[配置生效时机](docs/session-live-settings.md)。
@@ -95,7 +95,7 @@ pnpm start -- --config ./config.local.json
95
95
 
96
96
  ## 更新与版本渠道
97
97
 
98
- 在更新面板或通过 `covro update` 选择稳定、预览或开发渠道。受管升级支持 **macOS 和 Linux 的 npm 全局安装**,其他安装方式沿用原更新方法。默认 Node 变更后,可切换到已安装全局 Covro 的受支持环境,Covro 同版本也可迁移。兼容性按目标重启环境的 Codex 启动来源检查,面板单独保留正在运行的 Codex 版本。自动安装默认关闭,且只接受已验证的 Codex 组合;未验证组合需明确确认。自动升级在等待空闲期间跟随渠道最新合格候选,可从面板取消。Covro 不会升级 Codex CLI。详见[更新与恢复](docs/distribution.md)。
98
+ 在更新面板或通过 `covro update` 选择稳定、预览或开发渠道。受管升级支持 **macOS 和 Linux 的 npm 全局安装**,其他安装方式沿用原更新方法。默认 Node 变更后,可切换到已安装全局 Covro 的受支持环境,Covro 同版本也可迁移。自动安装默认关闭,且只接受已验证的 Codex 组合;未验证组合需明确确认。Covro 不会升级 Codex CLI。详见[更新与恢复](docs/distribution.md)。
99
99
 
100
100
  ## 你的电脑,你的工作台
101
101
 
@@ -0,0 +1,192 @@
1
+ /* Read-only JavaScript for macOS's system JXA runtime; no Apple Events or UI APIs.
2
+ * Darwin's 64-bit public proc_info ABI is shared by arm64 and x86_64.
3
+ * Only process identity, cwd and the two execution markers leave this process. */
4
+ ObjC.import('Foundation');
5
+ ObjC.import('stdlib');
6
+ ObjC.bindFunction('dlopen', ['void *', ['char *', 'int']]);
7
+ ObjC.bindFunction('calloc', ['unsigned char *', ['unsigned long', 'unsigned long']]);
8
+ ObjC.bindFunction('free', ['void', ['void *']]);
9
+ ObjC.bindFunction('memset', ['void *', ['void *', 'int', 'unsigned long']]);
10
+ if (Ref.equals($.dlopen('/usr/lib/libproc.dylib', 2), null)) unavailable();
11
+ ObjC.bindFunction('proc_listallpids', ['int', ['void *', 'int']]);
12
+ ObjC.bindFunction('proc_pidinfo', ['int', ['int', 'int', 'unsigned long long', 'void *', 'int']]);
13
+ ObjC.bindFunction('sysctl', [
14
+ 'int',
15
+ ['void *', 'unsigned int', 'void *', 'void *', 'void *', 'unsigned long'],
16
+ ]);
17
+
18
+ function unavailable() {
19
+ throw new Error('Process metadata is unavailable');
20
+ }
21
+ function allocate(size) {
22
+ let buffer = $.calloc(size, 1);
23
+ if (Ref.equals(buffer, null)) unavailable();
24
+ return buffer;
25
+ }
26
+ function u32(buffer, offset) {
27
+ return (
28
+ Number(buffer[offset]) +
29
+ Number(buffer[offset + 1]) * 256 +
30
+ Number(buffer[offset + 2]) * 65536 +
31
+ Number(buffer[offset + 3]) * 16777216
32
+ );
33
+ }
34
+ function put32(buffer, offset, value) {
35
+ for (let i = 0; i < 4; i++) buffer[offset + i] = Math.floor(value / Math.pow(256, i)) % 256;
36
+ }
37
+ function u64(buffer, offset) {
38
+ let value = u32(buffer, offset) + u32(buffer, offset + 4) * 4294967296;
39
+ if (!Number.isSafeInteger(value)) unavailable();
40
+ return value;
41
+ }
42
+ function info(pid, buffer) {
43
+ if ($.proc_pidinfo(pid, 3, 0, buffer, 136) !== 136 || u32(buffer, 12) !== pid) return null;
44
+ let seconds = u64(buffer, 120),
45
+ micros = u64(buffer, 128);
46
+ if (seconds < 1 || micros >= 1000000) unavailable();
47
+ return {
48
+ pid: pid,
49
+ parent: u32(buffer, 16),
50
+ birth: String(seconds) + '.' + ('000000' + String(micros)).slice(-6),
51
+ };
52
+ }
53
+ function same(a, b) {
54
+ return Boolean(a && b && a.pid === b.pid && a.birth === b.birth);
55
+ }
56
+ function endOfString(buffer, offset, size) {
57
+ for (let i = offset; i < size; i++) if (Number(buffer[i]) === 0) return i;
58
+ unavailable();
59
+ }
60
+ function environment(pid) {
61
+ let limit = 1048576,
62
+ buffer = allocate(limit),
63
+ mib = allocate(12),
64
+ size = Ref('unsigned long');
65
+ try {
66
+ put32(mib, 0, 1);
67
+ put32(mib, 4, 49);
68
+ put32(mib, 8, pid);
69
+ size[0] = limit;
70
+ if ($.sysctl(mib, 3, buffer, size, null, 0) !== 0 || size[0] < 4 || size[0] > limit)
71
+ unavailable();
72
+ let length = Number(size[0]),
73
+ argc = u32(buffer, 0);
74
+ if (argc < 1 || argc > 65536) unavailable();
75
+ let offset = endOfString(buffer, 4, length);
76
+ while (offset < length && Number(buffer[offset]) === 0) offset++;
77
+ for (let i = 0; i < argc; i++) {
78
+ if (offset >= length) unavailable();
79
+ offset = endOfString(buffer, offset, length) + 1;
80
+ }
81
+ let markers = {},
82
+ keys = ['CODEX_THREAD_ID=', 'CODEX_TOOL_CALL_ID='];
83
+ while (offset < length && Number(buffer[offset]) !== 0) {
84
+ let end = endOfString(buffer, offset, length);
85
+ for (let k = 0; k < keys.length; k++) {
86
+ let key = keys[k],
87
+ matches = end - offset >= key.length;
88
+ for (let j = 0; matches && j < key.length; j++)
89
+ matches = Number(buffer[offset + j]) === key.charCodeAt(j);
90
+ if (!matches) continue;
91
+ if (
92
+ markers[key] !== undefined ||
93
+ end - offset - key.length < 1 ||
94
+ end - offset - key.length > 160
95
+ )
96
+ unavailable();
97
+ let value = '';
98
+ for (let j = offset + key.length; j < end; j++)
99
+ value += String.fromCharCode(Number(buffer[j]));
100
+ if (!/^[a-zA-Z0-9_-]{1,160}$/.test(value)) unavailable();
101
+ markers[key] = value;
102
+ }
103
+ offset = end + 1;
104
+ }
105
+ if (!markers[keys[0]] || !markers[keys[1]]) unavailable();
106
+ return { thread: markers[keys[0]], call: markers[keys[1]] };
107
+ } finally {
108
+ $.memset(buffer, 0, limit);
109
+ $.free(buffer);
110
+ $.free(mib);
111
+ }
112
+ }
113
+ function cwd(pid) {
114
+ let buffer = allocate(2352);
115
+ try {
116
+ if ($.proc_pidinfo(pid, 9, 0, buffer, 2352) !== 2352) unavailable();
117
+ let start = 152,
118
+ end = endOfString(buffer, start, start + 1024),
119
+ text = '';
120
+ for (let i = start; i < end; i++)
121
+ text += '%' + ('0' + Number(buffer[i]).toString(16)).slice(-2);
122
+ let path = decodeURIComponent(text);
123
+ if (path[0] !== '/') unavailable();
124
+ return path;
125
+ } finally {
126
+ $.free(buffer);
127
+ }
128
+ }
129
+ function number(value) {
130
+ if (!/^[1-9][0-9]{0,9}$/.test(value) || Number(value) > 2147483647) unavailable();
131
+ return Number(value);
132
+ }
133
+ function identity(pid, buffer) {
134
+ const before = info(pid, buffer);
135
+ if (!before) unavailable();
136
+ const markers = environment(pid);
137
+ const path = cwd(pid);
138
+ if (!same(before, info(pid, buffer))) unavailable();
139
+ return {
140
+ pid: before.pid,
141
+ parent: before.parent,
142
+ birth: before.birth,
143
+ cwd: path,
144
+ thread: markers.thread,
145
+ call: markers.call,
146
+ };
147
+ }
148
+ /* exported run */
149
+ function run(argv) {
150
+ if (argv.length !== 2 || ['table', 'identity', 'identities'].indexOf(argv[0]) === -1)
151
+ unavailable();
152
+ const buffer = allocate(136);
153
+ let pids = null;
154
+ try {
155
+ if (argv[0] === 'identities') {
156
+ const ids = argv[1].split(',').map(number);
157
+ if (ids.length > 256 || new Set(ids).size !== ids.length) unavailable();
158
+ const result = [];
159
+ for (const pid of ids) {
160
+ try {
161
+ result.push(identity(pid, buffer));
162
+ } catch {
163
+ /* Exited or unmarked: no positive evidence. */
164
+ }
165
+ }
166
+ return JSON.stringify(result);
167
+ }
168
+ const pid = number(argv[1]);
169
+ if (argv[0] === 'identity') return JSON.stringify(identity(pid, buffer));
170
+ const before = info(pid, buffer);
171
+ if (!before) unavailable();
172
+ let count = $.proc_listallpids(null, 0);
173
+ if (count < 1 || count > 131072) unavailable();
174
+ const capacity = count + 1024;
175
+ pids = allocate(capacity * 4);
176
+ count = $.proc_listallpids(pids, capacity * 4);
177
+ if (count < 1 || count >= capacity) unavailable();
178
+ const result = [];
179
+ for (let i = 0; i < count; i++) {
180
+ const id = u32(pids, i * 4);
181
+ if (id > 0 && id <= 2147483647) {
182
+ const row = info(id, buffer);
183
+ if (row) result.push(row);
184
+ }
185
+ }
186
+ if (!same(before, info(pid, buffer))) unavailable();
187
+ return JSON.stringify(result);
188
+ } finally {
189
+ $.free(buffer);
190
+ if (pids) $.free(pids);
191
+ }
192
+ }
@@ -0,0 +1,385 @@
1
+ # Read-only x64 Windows probe. Uses system DLLs through in-memory P/Invoke metadata.
2
+ # No Add-Type, compiler, saved assembly, elevation, debug privilege or policy changes.
3
+ $ErrorActionPreference = 'Stop'
4
+ $ProgressPreference = 'SilentlyContinue'
5
+ Set-StrictMode -Version Latest
6
+ $script:ProbeStage = 'startup'
7
+ [Console]::InputEncoding = New-Object Text.UTF8Encoding($false)
8
+ [Console]::OutputEncoding = New-Object Text.UTF8Encoding($false)
9
+
10
+ function Fail-Query { throw 'Windows process metadata is unavailable' }
11
+ function Native([string]$name, [object[]]$values) {
12
+ return $script:NativeApi.GetMethod($name).Invoke($null, $values)
13
+ }
14
+ function Bind-Native([string]$name, [string]$library, [Type]$result, [Type[]]$parameters) {
15
+ $dll = [IO.Path]::Combine([Environment]::SystemDirectory, $library)
16
+ $method = $script:NativeBuilder.DefinePInvokeMethod(
17
+ $name, $dll, $name,
18
+ [Reflection.MethodAttributes]'Public,Static,PinvokeImpl',
19
+ [Reflection.CallingConventions]::Standard, $result, $parameters,
20
+ [Runtime.InteropServices.CallingConvention]::Winapi,
21
+ [Runtime.InteropServices.CharSet]::None)
22
+ $method.SetImplementationFlags([Reflection.MethodImplAttributes]::PreserveSig)
23
+ }
24
+ function Allocate([int]$size) {
25
+ if ($size -lt 1 -or $size -gt 16777216) { Fail-Query }
26
+ $memory = [Runtime.InteropServices.Marshal]::AllocHGlobal($size)
27
+ [Runtime.InteropServices.Marshal]::Copy((New-Object byte[] $size), 0, $memory, $size)
28
+ return $memory
29
+ }
30
+ function Free-Memory([IntPtr]$memory) {
31
+ if ($memory -ne [IntPtr]::Zero) { [Runtime.InteropServices.Marshal]::FreeHGlobal($memory) }
32
+ }
33
+ function Pointer([long]$address) {
34
+ if ($address -lt 65536 -or $address -gt 140737488355327) { Fail-Query }
35
+ return [IntPtr]$address
36
+ }
37
+ function Alive([IntPtr]$handle) { return (Native 'WaitForSingleObject' @($handle, [uint32]0)) -eq 258 }
38
+ function Birth([IntPtr]$handle) {
39
+ $memory = Allocate 32
40
+ try {
41
+ if (-not (Native 'GetProcessTimes' @($handle, $memory, [IntPtr]::Add($memory,8), [IntPtr]::Add($memory,16), [IntPtr]::Add($memory,24)))) { Fail-Query }
42
+ $ticks = [Runtime.InteropServices.Marshal]::ReadInt64($memory,0)
43
+ if ($ticks -lt 1 -or -not (Alive $handle)) { Fail-Query }
44
+ return $ticks
45
+ } finally { Free-Memory $memory }
46
+ }
47
+ function Open-Identity([int]$targetId, [uint32]$access) {
48
+ $handle = Native 'OpenProcess' @($access, $false, [uint32]$targetId)
49
+ if ($handle -eq [IntPtr]::Zero) { Fail-Query }
50
+ try { return @{ Handle=$handle; Birth=(Birth $handle) } }
51
+ catch { $null = Native 'CloseHandle' @($handle); throw }
52
+ }
53
+ function Parent-Table {
54
+ $snapshot = Native 'CreateToolhelp32Snapshot' @([uint32]2, [uint32]0)
55
+ if ($snapshot -eq [IntPtr](-1)) { Fail-Query }
56
+ $memory = Allocate 568 # PROCESSENTRY32W, x64
57
+ try {
58
+ $rows = @{}
59
+ [Runtime.InteropServices.Marshal]::WriteInt32($memory,568)
60
+ $next = Native 'Process32FirstW' @($snapshot,$memory)
61
+ if (-not $next) { Fail-Query }
62
+ while ($next) {
63
+ $targetId = [Runtime.InteropServices.Marshal]::ReadInt32($memory,8)
64
+ $parentId = [Runtime.InteropServices.Marshal]::ReadInt32($memory,32)
65
+ if ($targetId -gt 0 -and $parentId -ge 0) { $rows[$targetId] = $parentId }
66
+ if ($rows.Count -gt 131072) { Fail-Query }
67
+ $next = Native 'Process32NextW' @($snapshot,$memory)
68
+ }
69
+ return $rows
70
+ } finally { Free-Memory $memory; $null = Native 'CloseHandle' @($snapshot) }
71
+ }
72
+ function Is-Descendant([int]$targetId, [int]$rootId, $parents) {
73
+ $visited = New-Object 'Collections.Generic.HashSet[int]'
74
+ while ($targetId -gt 0 -and $visited.Add($targetId)) {
75
+ if ($targetId -eq $rootId) { return $true }
76
+ if (-not $parents.ContainsKey($targetId)) { return $false }
77
+ $targetId = $parents[$targetId]
78
+ }
79
+ return $false
80
+ }
81
+ function U16([byte[]]$bytes, [int]$offset) { return [BitConverter]::ToUInt16($bytes,$offset) }
82
+ function Address([byte[]]$bytes, [int]$offset) { return [BitConverter]::ToInt64($bytes,$offset) }
83
+ function Read-Remote([IntPtr]$handle, [long]$address, [int]$size) {
84
+ $contextStage=$script:ProbeStage; $script:ProbeStage='remote_pointer'
85
+ $pointer = Pointer $address
86
+ if ($size -lt 1 -or $size -gt 65536) { Fail-Query }
87
+ $memory = Allocate $size
88
+ $count = Allocate 8
89
+ try {
90
+ $script:ProbeStage='remote_read'
91
+ if (-not (Native 'ReadProcessMemory' @($handle,$pointer,$memory,[UIntPtr]::new([uint64]$size),$count))) { Fail-Query }
92
+ $script:ProbeStage='remote_count'
93
+ if ([Runtime.InteropServices.Marshal]::ReadInt64($count) -ne $size) { Fail-Query }
94
+ $bytes = New-Object byte[] $size
95
+ [Runtime.InteropServices.Marshal]::Copy($memory,$bytes,0,$size)
96
+ $script:ProbeStage=$contextStage
97
+ return ,$bytes
98
+ } finally {
99
+ [Runtime.InteropServices.Marshal]::Copy((New-Object byte[] $size),0,$memory,$size)
100
+ Free-Memory $memory; Free-Memory $count
101
+ }
102
+ }
103
+ function Read-Environment([IntPtr]$handle, [long]$address) {
104
+ $script:ProbeStage = 'environment'
105
+ $null = Pointer $address
106
+ if (($address % 2) -ne 0) { Fail-Query }
107
+ $bytes = New-Object byte[] 1048576
108
+ $characters = $null
109
+ $region = Allocate 48 # MEMORY_BASIC_INFORMATION, x64
110
+ try {
111
+ $total = 0; $end = -1; $previousZero = $false
112
+ while ($total -lt $bytes.Length -and $end -lt 0) {
113
+ $cursor = $address + $total
114
+ $size = Native 'VirtualQueryEx' @($handle,(Pointer $cursor),$region,[UIntPtr]::new([uint64]48))
115
+ if ($size.ToUInt64() -ne 48) { Fail-Query }
116
+ $base = [Runtime.InteropServices.Marshal]::ReadInt64($region,0)
117
+ $length = [Runtime.InteropServices.Marshal]::ReadInt64($region,24)
118
+ $state = [Runtime.InteropServices.Marshal]::ReadInt32($region,32)
119
+ $protect = [Runtime.InteropServices.Marshal]::ReadInt32($region,36)
120
+ if ($state -ne 4096 -or ($protect -band 257) -ne 0 -or $length -lt 1 -or $base -gt $cursor -or $base + $length -le $cursor) { Fail-Query }
121
+ $part = [int][Math]::Min(4096,[Math]::Min($bytes.Length-$total,$base+$length-$cursor))
122
+ $part -= $part % 2
123
+ if ($part -lt 2) { Fail-Query }
124
+ $chunk = Read-Remote $handle $cursor $part
125
+ try { [Array]::Copy($chunk,0,$bytes,$total,$part) }
126
+ finally { [Array]::Clear($chunk,0,$chunk.Length) }
127
+ $units=New-Object char[] ($part/2)
128
+ try {
129
+ [Buffer]::BlockCopy($bytes,$total,$units,0,$part)
130
+ for ($index=0; $index -lt $units.Length; $index++) {
131
+ $zero = $units[$index] -eq [char]0
132
+ if ($zero -and $previousZero) { $end=$total+$index*2+2; break }
133
+ $previousZero = $zero
134
+ }
135
+ } finally { [Array]::Clear($units,0,$units.Length) }
136
+ $total += $part
137
+ }
138
+ if ($end -lt 0) { Fail-Query }
139
+ $markers = @{}
140
+ # Mutable UTF-16 units keep unrelated environment values out of strings.
141
+ # Array.IndexOf scans NUL boundaries in the system runtime, not PS functions.
142
+ $characters=New-Object char[] ($end/2)
143
+ [Buffer]::BlockCopy($bytes,0,$characters,0,$end)
144
+ $keys = @('CODEX_THREAD_ID=','CODEX_TOOL_CALL_ID=')
145
+ $offset = 0
146
+ while ($offset -lt $characters.Length -and $characters[$offset] -ne [char]0) {
147
+ $entryEnd = [Array]::IndexOf([Array]$characters,[char]0,$offset)
148
+ if ($entryEnd -lt $offset) { Fail-Query }
149
+ foreach ($key in $keys) {
150
+ $matches = $entryEnd-$offset -ge $key.Length
151
+ for ($index=0; $matches -and $index -lt $key.Length; $index++) { $matches = $characters[$offset+$index] -ceq $key[$index] }
152
+ if (-not $matches) { continue }
153
+ $count = $entryEnd-$offset-$key.Length
154
+ if ($markers.ContainsKey($key) -or $count -lt 1 -or $count -gt 160) { Fail-Query }
155
+ $value = New-Object Text.StringBuilder
156
+ for ($index=$offset+$key.Length; $index -lt $entryEnd; $index++) {
157
+ $character = [int]$characters[$index]
158
+ if (-not (($character -ge 48 -and $character -le 57) -or ($character -ge 65 -and $character -le 90) -or ($character -ge 97 -and $character -le 122) -or $character -eq 45 -or $character -eq 95)) { Fail-Query }
159
+ $null = $value.Append([char]$character)
160
+ }
161
+ $markers[$key] = $value.ToString()
162
+ }
163
+ $offset = $entryEnd+1
164
+ }
165
+ if ($markers.Count -ne 2) { Fail-Query }
166
+ return @{ thread=$markers[$keys[0]]; call=$markers[$keys[1]] }
167
+ } finally {
168
+ if ($null -ne $characters) { [Array]::Clear($characters,0,$characters.Length) }
169
+ [Array]::Clear($bytes,0,$bytes.Length); Free-Memory $region
170
+ }
171
+ }
172
+ function Equal-Bytes([byte[]]$left,[byte[]]$right) {
173
+ if ($left.Length -ne $right.Length) { return $false }
174
+ for ($index=0; $index -lt $left.Length; $index++) { if ($left[$index] -ne $right[$index]) { return $false } }
175
+ return $true
176
+ }
177
+ function Current-Directory([IntPtr]$processHandle,[long]$rawHandle) {
178
+ $script:ProbeStage = 'cwd_duplicate'
179
+ # RTL curdir reserves the low two handle bits for flags.
180
+ $rawHandle = $rawHandle -band (-4L)
181
+ if ($rawHandle -le 0) { Fail-Query }
182
+ $duplicate = Allocate 8; $memory = Allocate 65536; $attributes = Allocate 24
183
+ $directory = [IntPtr]::Zero
184
+ try {
185
+ if (-not (Native 'DuplicateHandle' @($processHandle,[IntPtr]$rawHandle,(Native 'GetCurrentProcess' @()),$duplicate,[uint32]0,$false,[uint32]2))) { Fail-Query }
186
+ $directory = [Runtime.InteropServices.Marshal]::ReadIntPtr($duplicate)
187
+ $script:ProbeStage = 'cwd_attributes'
188
+ # The inherited curdir handle need not grant FILE_READ_ATTRIBUTES.
189
+ # FileStandardInfo only requires an open handle, unlike FileBasicInfo.
190
+ if (-not (Native 'GetFileInformationByHandleEx' @($directory,[int]1,$attributes,[uint32]24))) { Fail-Query }
191
+ if ([Runtime.InteropServices.Marshal]::ReadByte($attributes,21) -ne 1 -or [Runtime.InteropServices.Marshal]::ReadByte($attributes,20) -ne 0) { Fail-Query }
192
+ $script:ProbeStage = 'cwd_path'
193
+ $size = Native 'GetFinalPathNameByHandleW' @($directory,$memory,[uint32]32768,[uint32]0)
194
+ if ($size -lt 1 -or $size -ge 32768) { Fail-Query }
195
+ $path = [Runtime.InteropServices.Marshal]::PtrToStringUni($memory,[int]$size)
196
+ if ($path.StartsWith('\\?\')) { $path=$path.Substring(4) }
197
+ if ($path -notmatch '^[A-Za-z]:\\') { Fail-Query }
198
+ $drive = [Runtime.InteropServices.Marshal]::StringToHGlobalUni($path.Substring(0,3))
199
+ try { $kind = Native 'GetDriveTypeW' @($drive) } finally { Free-Memory $drive }
200
+ if ($kind -notin @(2,3,6)) { Fail-Query } # Local drive letters only; no UNC/network probing.
201
+ return $path
202
+ } finally {
203
+ if ($directory -ne [IntPtr]::Zero) { $null=Native 'CloseHandle' @($directory) }
204
+ Free-Memory $duplicate; Free-Memory $memory; Free-Memory $attributes
205
+ }
206
+ }
207
+ function Process-Identity([int]$targetId,[int]$parentId) {
208
+ $script:ProbeStage = 'process_open'
209
+ $opened=Open-Identity $targetId ([uint32]0x00100450) # query + VM read + duplicate handle + synchronize
210
+ $basic=Allocate 48; $size=Allocate 4; $machines=Allocate 4
211
+ try {
212
+ $script:ProbeStage = 'process_arch'
213
+ if (-not (Native 'IsWow64Process2' @($opened.Handle,$machines,[IntPtr]::Add($machines,2))) -or [Runtime.InteropServices.Marshal]::ReadInt16($machines,0) -ne 0 -or ([Runtime.InteropServices.Marshal]::ReadInt16($machines,2) -band 65535) -ne 0x8664) { Fail-Query }
214
+ if ((Native 'NtQueryInformationProcess' @($opened.Handle,[int]0,$basic,[uint32]48,$size)) -ne 0 -or [Runtime.InteropServices.Marshal]::ReadInt32($size) -ne 48 -or [Runtime.InteropServices.Marshal]::ReadInt64($basic,32) -ne $targetId -or [Runtime.InteropServices.Marshal]::ReadInt64($basic,40) -ne $parentId) { Fail-Query }
215
+ $script:ProbeStage = 'process_parameters'
216
+ $peb=[Runtime.InteropServices.Marshal]::ReadInt64($basic,8)
217
+ $pebPointer=Read-Remote $opened.Handle ($peb+32) 8
218
+ $parameters=Address $pebPointer 0
219
+ $script:ProbeStage = 'parameters_read'
220
+ $before=Read-Remote $opened.Handle $parameters 144
221
+ $maximum=[BitConverter]::ToUInt32($before,0); $length=[BitConverter]::ToUInt32($before,4)
222
+ $script:ProbeStage = 'parameters_length'
223
+ if ($length -lt 136 -or $maximum -lt $length -or $maximum -gt 1048576) { Fail-Query }
224
+ $script:ProbeStage = 'parameters_flags'
225
+ if (([BitConverter]::ToUInt32($before,8) -band 1) -ne 1) { Fail-Query }
226
+ $script:ProbeStage = 'parameters_cwd'
227
+ if ((U16 $before 56) -gt (U16 $before 58) -or ((U16 $before 56) % 2) -ne 0) { Fail-Query }
228
+ $markers=Read-Environment $opened.Handle (Address $before 128)
229
+ $cwd=Current-Directory $opened.Handle (Address $before 72)
230
+ $script:ProbeStage = 'process_stability'
231
+ $after=Read-Remote $opened.Handle $parameters 144
232
+ $afterPointer=Read-Remote $opened.Handle ($peb+32) 8
233
+ if (-not (Equal-Bytes $before $after) -or -not (Equal-Bytes $pebPointer $afterPointer) -or (Birth $opened.Handle) -ne $opened.Birth) { Fail-Query }
234
+ return @{pid=$targetId;parent=$parentId;birth=$opened.Birth.ToString([Globalization.CultureInfo]::InvariantCulture);cwd=$cwd;thread=$markers.thread;call=$markers.call}
235
+ } finally {
236
+ $null=Native 'CloseHandle' @($opened.Handle)
237
+ Free-Memory $basic; Free-Memory $size; Free-Memory $machines
238
+ }
239
+ }
240
+ function Tcp-Rows([int]$ownerId,[int]$requiredState) {
241
+ $script:ProbeStage='tcp'
242
+ $tableClass=3 # TCP_TABLE_OWNER_PID_LISTENER
243
+ if ($requiredState -eq 5) { $tableClass=4 } # TCP_TABLE_OWNER_PID_CONNECTIONS
244
+ foreach ($family in @(2,23)) {
245
+ $size=Allocate 4; $memory=[IntPtr]::Zero
246
+ try {
247
+ $status=Native 'GetExtendedTcpTable' @([IntPtr]::Zero,$size,$false,[uint32]$family,$tableClass,[uint32]0)
248
+ if ($family -eq 23 -and $status -eq 50) { continue }
249
+ if ($status -ne 122) { Fail-Query }
250
+ $success=$false
251
+ for ($attempt=0; $attempt -lt 3; $attempt++) {
252
+ $capacity=[Runtime.InteropServices.Marshal]::ReadInt32($size)
253
+ if ($capacity -lt 4 -or $capacity -gt 16777216) { Fail-Query }
254
+ Free-Memory $memory; $memory=Allocate $capacity
255
+ $status=Native 'GetExtendedTcpTable' @($memory,$size,$false,[uint32]$family,$tableClass,[uint32]0)
256
+ if ($status -eq 0) { $success=$true; break }
257
+ if ($status -ne 122) { Fail-Query }
258
+ }
259
+ if (-not $success) { Fail-Query }
260
+ $count=[Runtime.InteropServices.Marshal]::ReadInt32($memory)
261
+ $rowSize=24; if ($family -eq 23) { $rowSize=56 }
262
+ if ($count -lt 0 -or $count -gt 131072 -or 4+$count*$rowSize -gt $capacity) { Fail-Query }
263
+ for ($index=0; $index -lt $count; $index++) {
264
+ $row=[IntPtr]::Add($memory,4+$index*$rowSize)
265
+ $localOffset=4; $remoteOffset=12; $portOffset=8; $remotePortOffset=16; $stateOffset=0; $ownerOffset=20; $addressSize=4
266
+ if ($family -eq 23) { $localOffset=0; $remoteOffset=24; $portOffset=20; $remotePortOffset=44; $stateOffset=48; $ownerOffset=52; $addressSize=16 }
267
+ $state=[Runtime.InteropServices.Marshal]::ReadInt32($row,$stateOffset)
268
+ $targetId=[Runtime.InteropServices.Marshal]::ReadInt32($row,$ownerOffset)
269
+ if ($state -ne $requiredState -or ($ownerId -gt 0 -and $targetId -ne $ownerId)) { continue }
270
+ $local=New-Object byte[] $addressSize; $remote=New-Object byte[] $addressSize
271
+ [Runtime.InteropServices.Marshal]::Copy([IntPtr]::Add($row,$localOffset),$local,0,$addressSize)
272
+ [Runtime.InteropServices.Marshal]::Copy([IntPtr]::Add($row,$remoteOffset),$remote,0,$addressSize)
273
+ $localIp=[Net.IPAddress]::new([byte[]]$local); $remoteIp=[Net.IPAddress]::new([byte[]]$remote)
274
+ if ($localIp.IsIPv4MappedToIPv6) { $localIp=$localIp.MapToIPv4() }
275
+ if ($remoteIp.IsIPv4MappedToIPv6) { $remoteIp=$remoteIp.MapToIPv4() }
276
+ $hostAddress=$localIp.ToString(); $remoteAddress=$remoteIp.ToString()
277
+ if ($hostAddress -notin @('0.0.0.0','::','127.0.0.1','::1')) { continue }
278
+ $port=[int][Runtime.InteropServices.Marshal]::ReadByte($row,$portOffset)*256+[int][Runtime.InteropServices.Marshal]::ReadByte($row,$portOffset+1)
279
+ $remotePort=[int][Runtime.InteropServices.Marshal]::ReadByte($row,$remotePortOffset)*256+[int][Runtime.InteropServices.Marshal]::ReadByte($row,$remotePortOffset+1)
280
+ @{pid=$targetId;host=$hostAddress;remote=$remoteAddress;port=$port;remotePort=$remotePort;state=$state}
281
+ }
282
+ } finally { Free-Memory $size; Free-Memory $memory }
283
+ }
284
+ }
285
+ function Snapshot([int]$rootId) {
286
+ $script:ProbeStage = 'snapshot'
287
+ $handles=@{}
288
+ function Cached([int]$targetId) {
289
+ if (-not $handles.ContainsKey($targetId)) { $handles[$targetId]=Open-Identity $targetId ([uint32]0x00101000) }
290
+ return $handles[$targetId]
291
+ }
292
+ try {
293
+ $root=Cached $rootId
294
+ $parents=Parent-Table
295
+ $tcp=@(Tcp-Rows 0 2 | Where-Object { $_.pid -ne $rootId -and (Is-Descendant $_.pid $rootId $parents) })
296
+ if ($tcp.Count -gt 4096) { Fail-Query }
297
+ $identities=@{}; $diagnostics=@{}
298
+ foreach ($targetId in @($tcp | ForEach-Object {$_.pid} | Select-Object -Unique)) {
299
+ if ($identities.Count -ge 256) { Fail-Query }
300
+ try {
301
+ $script:ProbeStage = 'ancestry'
302
+ $current=[int]$targetId; $childBirth=[long]::MaxValue
303
+ while ($current -ne $rootId) {
304
+ $entry=Cached $current
305
+ if ($entry.Birth -gt $childBirth -or -not (Alive $entry.Handle)) { Fail-Query }
306
+ $childBirth=$entry.Birth; $current=$parents[$current]
307
+ }
308
+ if ($root.Birth -gt $childBirth) { Fail-Query }
309
+ $identity=Process-Identity $targetId $parents[$targetId]
310
+ if ([long]::Parse($identity.birth) -ne (Cached $targetId).Birth) { Fail-Query }
311
+ # Select-Object can wrap numeric keys in PSObject; keep kernel IDs Int32.
312
+ $identities[[int]$targetId]=$identity
313
+ } catch { # Only fixed stage codes, never an exception message or raw environment.
314
+ if (-not $diagnostics.ContainsKey($script:ProbeStage)) { $diagnostics[$script:ProbeStage]=0 }
315
+ $diagnostics[$script:ProbeStage]++
316
+ }
317
+ }
318
+ foreach ($entry in $handles.Values) { if (-not (Alive $entry.Handle)) { Fail-Query } }
319
+ $listeners=@(foreach ($row in $tcp) {
320
+ if ($identities.ContainsKey([int]$row.pid)) {
321
+ $hostAddress=$row.host
322
+ if ($hostAddress -eq '0.0.0.0') {$hostAddress='127.0.0.1'}
323
+ if ($hostAddress -eq '::') {$hostAddress='::1'}
324
+ @{pid=$row.pid;port=$row.port;host=$hostAddress}
325
+ }
326
+ })
327
+ return @{root=$rootId;rootBirth=$root.Birth.ToString([Globalization.CultureInfo]::InvariantCulture);processes=@($identities.Values);listeners=$listeners;diagnostics=$diagnostics}
328
+ } finally { foreach ($entry in $handles.Values) { $null=Native 'CloseHandle' @($entry.Handle) } }
329
+ }
330
+ function Connected([int]$targetId,[int]$port,[int]$clientPort,[string]$hostAddress) {
331
+ $opened=Open-Identity $targetId ([uint32]0x00101000)
332
+ try {
333
+ $matches=@(Tcp-Rows $targetId 5 | Where-Object { $_.port -eq $port -and $_.remotePort -eq $clientPort -and $_.host -eq $hostAddress -and $_.remote -eq $hostAddress })
334
+ return @{connected=($matches.Count -gt 0 -and (Birth $opened.Handle) -eq $opened.Birth)}
335
+ } finally { $null=Native 'CloseHandle' @($opened.Handle) }
336
+ }
337
+ try {
338
+ if ([IntPtr]::Size -ne 8 -or $ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') { Fail-Query }
339
+ $assemblyName=New-Object Reflection.AssemblyName('CovroPreviewNative')
340
+ $assembly=[AppDomain]::CurrentDomain.DefineDynamicAssembly($assemblyName,[Reflection.Emit.AssemblyBuilderAccess]::Run)
341
+ $module=$assembly.DefineDynamicModule('api')
342
+ $script:NativeBuilder=$module.DefineType('CovroPreviewNative',[Reflection.TypeAttributes]'Public,Sealed,Abstract')
343
+ Bind-Native 'OpenProcess' 'kernel32.dll' ([IntPtr]) @([uint32],[bool],[uint32])
344
+ Bind-Native 'CloseHandle' 'kernel32.dll' ([bool]) @([IntPtr])
345
+ Bind-Native 'WaitForSingleObject' 'kernel32.dll' ([uint32]) @([IntPtr],[uint32])
346
+ Bind-Native 'GetCurrentProcess' 'kernel32.dll' ([IntPtr]) @()
347
+ Bind-Native 'GetProcessTimes' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr],[IntPtr],[IntPtr],[IntPtr])
348
+ Bind-Native 'CreateToolhelp32Snapshot' 'kernel32.dll' ([IntPtr]) @([uint32],[uint32])
349
+ Bind-Native 'Process32FirstW' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr])
350
+ Bind-Native 'Process32NextW' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr])
351
+ Bind-Native 'ReadProcessMemory' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr],[IntPtr],[UIntPtr],[IntPtr])
352
+ Bind-Native 'VirtualQueryEx' 'kernel32.dll' ([UIntPtr]) @([IntPtr],[IntPtr],[IntPtr],[UIntPtr])
353
+ Bind-Native 'IsWow64Process2' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr],[IntPtr])
354
+ Bind-Native 'DuplicateHandle' 'kernel32.dll' ([bool]) @([IntPtr],[IntPtr],[IntPtr],[IntPtr],[uint32],[bool],[uint32])
355
+ Bind-Native 'GetFileInformationByHandleEx' 'kernel32.dll' ([bool]) @([IntPtr],[int],[IntPtr],[uint32])
356
+ Bind-Native 'GetFinalPathNameByHandleW' 'kernel32.dll' ([uint32]) @([IntPtr],[IntPtr],[uint32],[uint32])
357
+ Bind-Native 'GetDriveTypeW' 'kernel32.dll' ([uint32]) @([IntPtr])
358
+ Bind-Native 'NtQueryInformationProcess' 'ntdll.dll' ([int]) @([IntPtr],[int],[IntPtr],[uint32],[IntPtr])
359
+ Bind-Native 'GetExtendedTcpTable' 'iphlpapi.dll' ([uint32]) @([IntPtr],[IntPtr],[bool],[uint32],[int],[uint32])
360
+ $script:NativeApi=$script:NativeBuilder.CreateType()
361
+ [Console]::Out.WriteLine('{"ready":true}')
362
+ while ($null -ne ($lineText=[Console]::ReadLine())) {
363
+ $requestId=0
364
+ try {
365
+ if ($lineText.Length -gt 4096) { Fail-Query }
366
+ $requestRecord=ConvertFrom-Json $lineText
367
+ $requestId=[int]$requestRecord.id
368
+ if ($requestId -lt 1) { Fail-Query }
369
+ if ($requestRecord.method -eq 'snapshot') {
370
+ $rootId=[int]$requestRecord.root
371
+ if ($rootId -lt 1) { Fail-Query }
372
+ $result=Snapshot $rootId
373
+ } elseif ($requestRecord.method -eq 'connected') {
374
+ $targetId=[int]$requestRecord.pid; $port=[int]$requestRecord.port; $clientPort=[int]$requestRecord.clientPort
375
+ $hostAddress=[string]$requestRecord.host
376
+ if ($targetId -lt 1 -or $port -lt 1 -or $port -gt 65535 -or $clientPort -lt 1 -or $clientPort -gt 65535 -or $hostAddress -notin @('127.0.0.1','::1')) { Fail-Query }
377
+ $result=Connected $targetId $port $clientPort $hostAddress
378
+ } else { Fail-Query }
379
+ [Console]::Out.WriteLine((ConvertTo-Json -Depth 8 -Compress @{id=$requestId;ok=$true;result=$result}))
380
+ } catch { [Console]::Out.WriteLine((ConvertTo-Json -Compress @{id=$requestId;ok=$false;error='query_failed';stage=$script:ProbeStage})) }
381
+ }
382
+ } catch {
383
+ [Console]::Out.WriteLine('{"ready":false}')
384
+ exit 1
385
+ }
@@ -1301,6 +1301,17 @@ class CodexAdapter {
1301
1301
  break;
1302
1302
  case "item/started":
1303
1303
  case "item/completed":
1304
+ if (event.params.item.type === "commandExecution") {
1305
+ const item = event.params.item;
1306
+ this.emit({
1307
+ type: "previewExecution",
1308
+ threadId: event.params.threadId,
1309
+ itemId: item.id,
1310
+ cwd: item.cwd,
1311
+ command: item.command,
1312
+ source: item.source
1313
+ });
1314
+ }
1304
1315
  if (event.params.item.type === "contextCompaction") {
1305
1316
  this.tokenUsage.compacted(event.params.threadId, event.params.turnId);
1306
1317
  this.totalTokenUsage.compacted(event.params.threadId, event.params.turnId);