open-multi-agent-kit 0.97.0 → 0.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +41 -9
  3. package/dist/cli/args.d.ts +2 -3
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +13 -189
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/help.d.ts +3 -0
  8. package/dist/cli/help.d.ts.map +1 -0
  9. package/dist/cli/help.js +194 -0
  10. package/dist/cli/help.js.map +1 -0
  11. package/dist/cli/initial-message.d.ts.map +1 -1
  12. package/dist/cli/initial-message.js +2 -1
  13. package/dist/cli/initial-message.js.map +1 -1
  14. package/dist/cli/resource-paths.d.ts +4 -0
  15. package/dist/cli/resource-paths.d.ts.map +1 -0
  16. package/dist/cli/resource-paths.js +59 -0
  17. package/dist/cli/resource-paths.js.map +1 -0
  18. package/dist/commands/adaptorch-doctor-cli.d.ts +13 -0
  19. package/dist/commands/adaptorch-doctor-cli.d.ts.map +1 -0
  20. package/dist/commands/adaptorch-doctor-cli.js +115 -0
  21. package/dist/commands/adaptorch-doctor-cli.js.map +1 -0
  22. package/dist/commands/resource-doctor-cli.d.ts +4 -0
  23. package/dist/commands/resource-doctor-cli.d.ts.map +1 -1
  24. package/dist/commands/resource-doctor-cli.js +35 -5
  25. package/dist/commands/resource-doctor-cli.js.map +1 -1
  26. package/dist/core/adaptorch-bridge.d.ts +11 -13
  27. package/dist/core/adaptorch-bridge.d.ts.map +1 -1
  28. package/dist/core/adaptorch-bridge.js +11 -13
  29. package/dist/core/adaptorch-bridge.js.map +1 -1
  30. package/dist/core/agent-session-snapshot.d.ts +16 -0
  31. package/dist/core/agent-session-snapshot.d.ts.map +1 -0
  32. package/dist/core/agent-session-snapshot.js +111 -0
  33. package/dist/core/agent-session-snapshot.js.map +1 -0
  34. package/dist/core/agent-session.d.ts +5 -9
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +27 -219
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/agent-tool-settings.d.ts +10 -0
  39. package/dist/core/agent-tool-settings.d.ts.map +1 -1
  40. package/dist/core/agent-tool-settings.js +10 -1
  41. package/dist/core/agent-tool-settings.js.map +1 -1
  42. package/dist/core/compaction/compaction.d.ts +7 -0
  43. package/dist/core/compaction/compaction.d.ts.map +1 -1
  44. package/dist/core/compaction/compaction.js +25 -61
  45. package/dist/core/compaction/compaction.js.map +1 -1
  46. package/dist/core/compaction/index.d.ts +1 -0
  47. package/dist/core/compaction/index.d.ts.map +1 -1
  48. package/dist/core/compaction/index.js +1 -0
  49. package/dist/core/compaction/index.js.map +1 -1
  50. package/dist/core/compaction/knowledge-triage-format.d.ts +9 -0
  51. package/dist/core/compaction/knowledge-triage-format.d.ts.map +1 -0
  52. package/dist/core/compaction/knowledge-triage-format.js +71 -0
  53. package/dist/core/compaction/knowledge-triage-format.js.map +1 -0
  54. package/dist/core/compaction/knowledge-triage-types.d.ts +7 -0
  55. package/dist/core/compaction/knowledge-triage-types.d.ts.map +1 -0
  56. package/dist/core/compaction/knowledge-triage-types.js +2 -0
  57. package/dist/core/compaction/knowledge-triage-types.js.map +1 -0
  58. package/dist/core/compaction/knowledge-triage.d.ts +29 -0
  59. package/dist/core/compaction/knowledge-triage.d.ts.map +1 -0
  60. package/dist/core/compaction/knowledge-triage.js +189 -0
  61. package/dist/core/compaction/knowledge-triage.js.map +1 -0
  62. package/dist/core/compaction/transaction.d.ts.map +1 -1
  63. package/dist/core/compaction/transaction.js +1 -1
  64. package/dist/core/compaction/transaction.js.map +1 -1
  65. package/dist/core/compaction/utils.d.ts +4 -0
  66. package/dist/core/compaction/utils.d.ts.map +1 -1
  67. package/dist/core/compaction/utils.js +37 -0
  68. package/dist/core/compaction/utils.js.map +1 -1
  69. package/dist/core/completion-sound-io.d.ts +14 -0
  70. package/dist/core/completion-sound-io.d.ts.map +1 -0
  71. package/dist/core/completion-sound-io.js +64 -0
  72. package/dist/core/completion-sound-io.js.map +1 -0
  73. package/dist/core/completion-sound.d.ts +4 -10
  74. package/dist/core/completion-sound.d.ts.map +1 -1
  75. package/dist/core/completion-sound.js +28 -58
  76. package/dist/core/completion-sound.js.map +1 -1
  77. package/dist/core/context-budget-relevance.d.ts +15 -2
  78. package/dist/core/context-budget-relevance.d.ts.map +1 -1
  79. package/dist/core/context-budget-relevance.js +21 -9
  80. package/dist/core/context-budget-relevance.js.map +1 -1
  81. package/dist/core/context-budget-system-prompt-items.d.ts +1 -1
  82. package/dist/core/context-budget-system-prompt-items.d.ts.map +1 -1
  83. package/dist/core/context-budget-system-prompt-items.js.map +1 -1
  84. package/dist/core/context-budget-system-prompt.d.ts +1 -1
  85. package/dist/core/context-budget-system-prompt.d.ts.map +1 -1
  86. package/dist/core/context-budget-system-prompt.js.map +1 -1
  87. package/dist/core/context-file.d.ts +23 -0
  88. package/dist/core/context-file.d.ts.map +1 -0
  89. package/dist/core/context-file.js +17 -0
  90. package/dist/core/context-file.js.map +1 -0
  91. package/dist/core/keybindings.d.ts +1 -1
  92. package/dist/core/keybindings.d.ts.map +1 -1
  93. package/dist/core/keybindings.js +6 -1
  94. package/dist/core/keybindings.js.map +1 -1
  95. package/dist/core/model-prompt-policy.d.ts +1 -1
  96. package/dist/core/model-prompt-policy.d.ts.map +1 -1
  97. package/dist/core/model-prompt-policy.js.map +1 -1
  98. package/dist/core/prompt-settlement.d.ts +6 -3
  99. package/dist/core/prompt-settlement.d.ts.map +1 -1
  100. package/dist/core/prompt-settlement.js +10 -14
  101. package/dist/core/prompt-settlement.js.map +1 -1
  102. package/dist/core/reasoning-router-promotion.d.ts +41 -1
  103. package/dist/core/reasoning-router-promotion.d.ts.map +1 -1
  104. package/dist/core/reasoning-router-promotion.js +31 -2
  105. package/dist/core/reasoning-router-promotion.js.map +1 -1
  106. package/dist/core/reasoning-router-replay-stability.d.ts +65 -0
  107. package/dist/core/reasoning-router-replay-stability.d.ts.map +1 -0
  108. package/dist/core/reasoning-router-replay-stability.js +67 -0
  109. package/dist/core/reasoning-router-replay-stability.js.map +1 -0
  110. package/dist/core/reasoning-router-v4-weights.d.ts +6 -6
  111. package/dist/core/reasoning-router-v4-weights.d.ts.map +1 -1
  112. package/dist/core/reasoning-router-v4-weights.js +3 -3
  113. package/dist/core/reasoning-router-v4-weights.js.map +1 -1
  114. package/dist/core/reasoning-router-v4.d.ts.map +1 -1
  115. package/dist/core/reasoning-router-v4.js +6 -6
  116. package/dist/core/reasoning-router-v4.js.map +1 -1
  117. package/dist/core/redaction.d.ts.map +1 -1
  118. package/dist/core/redaction.js +1 -1
  119. package/dist/core/redaction.js.map +1 -1
  120. package/dist/core/resource-admission.d.ts +2 -1
  121. package/dist/core/resource-admission.d.ts.map +1 -1
  122. package/dist/core/resource-admission.js +11 -0
  123. package/dist/core/resource-admission.js.map +1 -1
  124. package/dist/core/resource-governor-format.d.ts +1 -1
  125. package/dist/core/resource-governor-format.d.ts.map +1 -1
  126. package/dist/core/resource-governor-format.js.map +1 -1
  127. package/dist/core/resource-governor-settings.d.ts +6 -12
  128. package/dist/core/resource-governor-settings.d.ts.map +1 -1
  129. package/dist/core/resource-governor-settings.js.map +1 -1
  130. package/dist/core/resource-governor-types.d.ts +24 -0
  131. package/dist/core/resource-governor-types.d.ts.map +1 -0
  132. package/dist/core/resource-governor-types.js +15 -0
  133. package/dist/core/resource-governor-types.js.map +1 -0
  134. package/dist/core/resource-loader.d.ts +1 -7
  135. package/dist/core/resource-loader.d.ts.map +1 -1
  136. package/dist/core/resource-loader.js.map +1 -1
  137. package/dist/core/resource-observation-journal.d.ts +2 -1
  138. package/dist/core/resource-observation-journal.d.ts.map +1 -1
  139. package/dist/core/resource-observation-journal.js +4 -3
  140. package/dist/core/resource-observation-journal.js.map +1 -1
  141. package/dist/core/resource-observation-report-reader.d.ts +7 -0
  142. package/dist/core/resource-observation-report-reader.d.ts.map +1 -0
  143. package/dist/core/resource-observation-report-reader.js +157 -0
  144. package/dist/core/resource-observation-report-reader.js.map +1 -0
  145. package/dist/core/resource-observation-report.d.ts +24 -0
  146. package/dist/core/resource-observation-report.d.ts.map +1 -0
  147. package/dist/core/resource-observation-report.js +101 -0
  148. package/dist/core/resource-observation-report.js.map +1 -0
  149. package/dist/core/router-feedback-collector.d.ts +1 -1
  150. package/dist/core/router-feedback-collector.d.ts.map +1 -1
  151. package/dist/core/router-feedback-collector.js.map +1 -1
  152. package/dist/core/session-failure-cause.d.ts +33 -0
  153. package/dist/core/session-failure-cause.d.ts.map +1 -0
  154. package/dist/core/session-failure-cause.js +141 -0
  155. package/dist/core/session-failure-cause.js.map +1 -0
  156. package/dist/core/session-system-prompt.d.ts +1 -1
  157. package/dist/core/session-system-prompt.d.ts.map +1 -1
  158. package/dist/core/session-system-prompt.js.map +1 -1
  159. package/dist/core/settings-manager.d.ts +1 -1
  160. package/dist/core/settings-manager.d.ts.map +1 -1
  161. package/dist/core/settings-manager.js.map +1 -1
  162. package/dist/core/system-prompt.d.ts +1 -1
  163. package/dist/core/system-prompt.d.ts.map +1 -1
  164. package/dist/core/system-prompt.js.map +1 -1
  165. package/dist/core/tools/bash.d.ts.map +1 -1
  166. package/dist/core/tools/bash.js +7 -7
  167. package/dist/core/tools/bash.js.map +1 -1
  168. package/dist/core/workload-classifier.d.ts +2 -10
  169. package/dist/core/workload-classifier.d.ts.map +1 -1
  170. package/dist/core/workload-classifier.js +17 -0
  171. package/dist/core/workload-classifier.js.map +1 -1
  172. package/dist/core/workload-family-matcher.d.ts +1 -1
  173. package/dist/core/workload-family-matcher.d.ts.map +1 -1
  174. package/dist/core/workload-family-matcher.js.map +1 -1
  175. package/dist/core/workload-shard-execution-types.d.ts +40 -0
  176. package/dist/core/workload-shard-execution-types.d.ts.map +1 -0
  177. package/dist/core/workload-shard-execution-types.js +14 -0
  178. package/dist/core/workload-shard-execution-types.js.map +1 -0
  179. package/dist/core/workload-shard-executor.d.ts +3 -27
  180. package/dist/core/workload-shard-executor.d.ts.map +1 -1
  181. package/dist/core/workload-shard-executor.js.map +1 -1
  182. package/dist/core/workload-shard-runner.d.ts +1 -1
  183. package/dist/core/workload-shard-runner.d.ts.map +1 -1
  184. package/dist/core/workload-shard-runner.js.map +1 -1
  185. package/dist/core/workload-types.d.ts +24 -0
  186. package/dist/core/workload-types.d.ts.map +1 -0
  187. package/dist/core/workload-types.js +15 -0
  188. package/dist/core/workload-types.js.map +1 -0
  189. package/dist/main.d.ts +2 -0
  190. package/dist/main.d.ts.map +1 -1
  191. package/dist/main.js +27 -47
  192. package/dist/main.js.map +1 -1
  193. package/dist/modes/interactive/theme/omk-control-panel.json +1 -1
  194. package/dist/utils/clipboard-image.d.ts.map +1 -1
  195. package/dist/utils/clipboard-image.js +42 -33
  196. package/dist/utils/clipboard-image.js.map +1 -1
  197. package/dist/utils/clipboard.d.ts.map +1 -1
  198. package/dist/utils/clipboard.js +14 -2
  199. package/dist/utils/clipboard.js.map +1 -1
  200. package/docs/adaptorch-preview-spec.md +20 -18
  201. package/docs/adaptorch-preview.md +9 -9
  202. package/docs/compaction.md +24 -3
  203. package/docs/correctness-wall.md +10 -10
  204. package/docs/docs.json +12 -0
  205. package/docs/environment-variables.md +9 -2
  206. package/docs/index.md +3 -0
  207. package/docs/runtime-algorithms.md +359 -0
  208. package/docs/sdk.md +2 -2
  209. package/docs/settings.md +11 -10
  210. package/docs/usage.md +18 -2
  211. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  212. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  213. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  214. package/examples/extensions/gondolin/package-lock.json +2 -2
  215. package/examples/extensions/gondolin/package.json +1 -1
  216. package/examples/extensions/sandbox/package-lock.json +2 -2
  217. package/examples/extensions/sandbox/package.json +1 -1
  218. package/examples/extensions/with-deps/package-lock.json +2 -2
  219. package/examples/extensions/with-deps/package.json +1 -1
  220. package/npm-shrinkwrap.json +18 -18
  221. package/package.json +6 -6
  222. package/dist/core/context-budget-governor.d.ts +0 -67
  223. package/dist/core/context-budget-governor.d.ts.map +0 -1
  224. package/dist/core/context-budget-governor.js +0 -224
  225. package/dist/core/context-budget-governor.js.map +0 -1
  226. package/dist/core/lean-ctx.d.ts +0 -99
  227. package/dist/core/lean-ctx.d.ts.map +0 -1
  228. package/dist/core/lean-ctx.js +0 -225
  229. package/dist/core/lean-ctx.js.map +0 -1
  230. package/dist/core/read-anchors.d.ts +0 -110
  231. package/dist/core/read-anchors.d.ts.map +0 -1
  232. package/dist/core/read-anchors.js +0 -193
  233. package/dist/core/read-anchors.js.map +0 -1
  234. package/dist/core/recovery-checkpoint.d.ts +0 -196
  235. package/dist/core/recovery-checkpoint.d.ts.map +0 -1
  236. package/dist/core/recovery-checkpoint.js +0 -382
  237. package/dist/core/recovery-checkpoint.js.map +0 -1
  238. package/dist/core/sandbox-policy-v2.d.ts +0 -49
  239. package/dist/core/sandbox-policy-v2.d.ts.map +0 -1
  240. package/dist/core/sandbox-policy-v2.js +0 -368
  241. package/dist/core/sandbox-policy-v2.js.map +0 -1
  242. package/dist/guardrails/audit-logger.d.ts +0 -4
  243. package/dist/guardrails/audit-logger.d.ts.map +0 -1
  244. package/dist/guardrails/audit-logger.js +0 -28
  245. package/dist/guardrails/audit-logger.js.map +0 -1
  246. package/dist/guardrails/freedomd-adapter.d.ts +0 -16
  247. package/dist/guardrails/freedomd-adapter.d.ts.map +0 -1
  248. package/dist/guardrails/freedomd-adapter.js +0 -87
  249. package/dist/guardrails/freedomd-adapter.js.map +0 -1
  250. package/dist/orchestration/lane-grant-auditor.d.ts +0 -4
  251. package/dist/orchestration/lane-grant-auditor.d.ts.map +0 -1
  252. package/dist/orchestration/lane-grant-auditor.js +0 -87
  253. package/dist/orchestration/lane-grant-auditor.js.map +0 -1
  254. package/dist/types/guardrails.d.ts +0 -61
  255. package/dist/types/guardrails.d.ts.map +0 -1
  256. package/dist/types/guardrails.js +0 -9
  257. package/dist/types/guardrails.js.map +0 -1
  258. package/dist/types/lane-grant.d.ts +0 -58
  259. package/dist/types/lane-grant.d.ts.map +0 -1
  260. package/dist/types/lane-grant.js +0 -9
  261. package/dist/types/lane-grant.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,0BAA0B,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,CAAU,CAAC;AAEnG,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAC3C,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IAC/E,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAAA,CAC1E;AAED,SAAS,YAAY,CAAC,QAAgB,EAAU;IAC/C,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;AAAA,CA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AC/C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env, inspectProcVersion = true): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\tif (!inspectProcVersion) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `omk-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\tconst hasExplicitEnv = options?.env !== undefined;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env, !hasExplicitEnv);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = await readClipboardImageViaNativeClipboard();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
1
+ {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,0BAA0B,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,CAAU,CAAC;AAEnG,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAC3C,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IAC/E,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAAA,CAC1E;AAED,SAAS,YAAY,CAAC,QAAgB,EAAU;IAC/C,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;AAAA,CAC9E;AAED,MAAM,UAAU,yBAAyB,CAAC,QAAgB,EAAiB;IAC1E,QA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GAAG,EAAE,CAAC;QACpB,KAAK,GAAG,MAAM,gBAAgB,CAAC,4BAA4B,EAAE,CAAC,CAAC;QAC/D,KAAK,KAAK,MAAM,gBAAgB,CAAC,0BAA0B,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;QACnB,KAAK,GAAG,MAAM,gBAAgB,CAAC,+BAA+B,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,KAAK,GAAG,MAAM,gBAAgB,CAAC,MAAM,oCAAoC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { readFileSync, unlinkSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { clipboard } from \"./clipboard-native.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (Buffer.isBuffer(result.stdout)) {\n\t\treturn { ok: true, stdout: result.stdout };\n\t}\n\n\tconst encoding = typeof result.stdout === \"string\" ? \"utf-8\" : undefined;\n\treturn { ok: true, stdout: Buffer.from(result.stdout ?? \"\", encoding) };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env, inspectProcVersion = true): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\tif (!inspectProcVersion) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `omk-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\n/**\n * Normalize one source's read into a supported format, or reject that read.\n *\n * Applied per source rather than once after the chain, because a source can\n * succeed at reading bytes yet still be unusable: WSLg publishes a Windows\n * screenshot as `image/bmp`, which needs conversion. Folding the conversion\n * into the source attempt keeps an unconvertible read from disqualifying the\n * sources behind it — notably the PowerShell reader, which returns PNG\n * directly and needs no converter at all.\n */\nasync function toSupportedImage(image: ClipboardImage | null): Promise<ClipboardImage | null> {\n\tif (!image) {\n\t\treturn null;\n\t}\n\tif (isSupportedImageMimeType(image.mimeType)) {\n\t\treturn image;\n\t}\n\tconst pngBytes = await convertToPng(image.bytes);\n\treturn pngBytes ? { bytes: pngBytes, mimeType: \"image/png\" } : null;\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\tconst hasExplicitEnv = options?.env !== undefined;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tif (platform !== \"linux\") {\n\t\treturn toSupportedImage(await readClipboardImageViaNativeClipboard());\n\t}\n\n\tconst wsl = isWSL(env, !hasExplicitEnv);\n\tconst wayland = isWaylandSession(env);\n\tlet image: ClipboardImage | null = null;\n\n\tif (wayland || wsl) {\n\t\timage = await toSupportedImage(readClipboardImageViaWlPaste());\n\t\timage ??= await toSupportedImage(readClipboardImageViaXclip());\n\t}\n\n\tif (!image && wsl) {\n\t\timage = await toSupportedImage(readClipboardImageViaPowerShell());\n\t}\n\n\tif (!image && !wayland) {\n\t\timage = await toSupportedImage(await readClipboardImageViaNativeClipboard());\n\t}\n\n\treturn image;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAkCA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsGjE","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => resolve(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => resolve(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAkCA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiHjE","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tlet settled = false;\n\t\t\t\t\t\t\t\tconst finish = (code: number) => {\n\t\t\t\t\t\t\t\t\tif (settled) return;\n\t\t\t\t\t\t\t\t\tsettled = true;\n\t\t\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\t\t\tresolve(code);\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tconst timer = setTimeout(() => {\n\t\t\t\t\t\t\t\t\tproc.kill(\"SIGKILL\");\n\t\t\t\t\t\t\t\t\tfinish(1);\n\t\t\t\t\t\t\t\t}, options.timeout);\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => finish(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => finish(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
@@ -83,8 +83,20 @@ export async function copyToClipboard(text) {
83
83
  // failed wl-copy falls through to the xclip/OSC 52 fallbacks.
84
84
  const wlCopyExit = await new Promise((resolve) => {
85
85
  const proc = spawn("wl-copy", [], { stdio: ["pipe", "ignore", "ignore"] });
86
- proc.on("error", () => resolve(1));
87
- proc.on("close", (code) => resolve(code ?? 1));
86
+ let settled = false;
87
+ const finish = (code) => {
88
+ if (settled)
89
+ return;
90
+ settled = true;
91
+ clearTimeout(timer);
92
+ resolve(code);
93
+ };
94
+ const timer = setTimeout(() => {
95
+ proc.kill("SIGKILL");
96
+ finish(1);
97
+ }, options.timeout);
98
+ proc.on("error", () => finish(1));
99
+ proc.on("close", (code) => finish(code ?? 1));
88
100
  proc.stdin.on("error", () => {
89
101
  // Ignore EPIPE errors if wl-copy exits early
90
102
  });
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,O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AAE,CAAC;wBAC1B,kBAAkB,CAAC,OAAO,CAAC,CAAC;wBAC5B,MAAM,GAAG,IAAI,CAAC;oBACf,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;IAED,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,GAAG,MAAM,IAAI,WAAW,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;AAAA,CACD","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => resolve(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => resolve(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\t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andSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead.\n\t\t\t\t\t\t\t// Await the exit code and only claim success on a clean exit, so a\n\t\t\t\t\t\t\t// failed wl-copy falls through to the xclip/OSC 52 fallbacks.\n\t\t\t\t\t\t\tconst wlCopyExit = await new Promise<number>((resolve) => {\n\t\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\t\tlet settled = false;\n\t\t\t\t\t\t\t\tconst finish = (code: number) => {\n\t\t\t\t\t\t\t\t\tif (settled) return;\n\t\t\t\t\t\t\t\t\tsettled = true;\n\t\t\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\t\t\tresolve(code);\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tconst timer = setTimeout(() => {\n\t\t\t\t\t\t\t\t\tproc.kill(\"SIGKILL\");\n\t\t\t\t\t\t\t\t\tfinish(1);\n\t\t\t\t\t\t\t\t}, options.timeout);\n\t\t\t\t\t\t\t\tproc.on(\"error\", () => finish(1));\n\t\t\t\t\t\t\t\tproc.on(\"close\", (code) => finish(code ?? 1));\n\t\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (wlCopyExit === 0) {\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
@@ -1,7 +1,9 @@
1
- # Lane F — AdaptTorch Preview Algorithm (structured spec)
1
+ # Lane F — AdaptOrch Preview Algorithm (structured spec)
2
+
3
+ **Status:** Proposed.
4
+
5
+ **Evidence roots:** `packages/adaptorch-wpl/`, `.omk/runs/adaptorch-native-loop-algorithm-20260701/final-part1-core-algorithm.md`, `packages/coding-agent/src/core/adaptorch-bridge.ts`, `packages/coding-agent/docs/loadout-domains/README.md`.
2
6
 
3
- **Status:** documentation / interface blueprint only.
4
- **Evidence roots:** `packages/adaptorch-wpl/`, `.omk/runs/adaptorch-native-loop-algorithm-20260701/final-part1-core-algorithm.md`, `packages/coding-agent/src/core/adaptorch-bridge.ts`, `packages/coding-agent/docs/loadout-domains/README.md`.
5
7
  **Not a shipped runtime:** this spec describes a **preview** path (planning, routing, and evidence contracts) unless a future implementation lane wires it.
6
8
 
7
9
  ---
@@ -13,13 +15,13 @@
13
15
  | `task_text` | string | user / lane kickoff | Primary routing signal; may be truncated for headroom. |
14
16
  | `path_hints` | string[] | cwd, owned paths, globs | Optional; used for domain triggers and write-scope checks. |
15
17
  | `upstream_tags` | string[] | goal id, lane role, preset | e.g. `grok-adaptorch-prod`, `omk-planner`. |
16
- | `payload_shape` | object | planner / DAG artifact | Sanitized shape for topology preview only **no** raw prompts, secrets, or session ids. |
18
+ | `payload_shape` | object | planner / DAG artifact | Non-empty `subtasks` array plus optional `dependencies`; descriptions are bounded and sanitized, with no secrets or session ids. |
17
19
  | `provider_profile` | enum | session | `xai` \| `default` \| other registered provider. |
18
20
  | `adaptorch_transport` | optional | MCP grant | If absent, preview runs **local-only** (OMK compose + deterministic fallbacks). |
19
21
  | `lane_grants[]` | object[] | root coordinator | Each: scope, authority, skills, MCP, acceptance, evidence path. |
20
22
  | `budget_caps` | object | loop / goal | `max_lanes`, `max_dispatch_preview_calls`, wall-clock cap (immutable per preview instance). |
21
23
 
22
- **Hard input exclusions (never pass into AdaptOrch advisory or preview payloads):** prompt text/hash, file paths as bulk lists, model/provider identifiers in advisory bridge shape, session/user ids, tool names from live turns, hook stderr, credentials, `.env` material.
24
+ **Hard input exclusions (never pass into AdaptOrch advisory or preview payloads):** raw full prompts or hashes, bulk file lists, session/user ids, live-turn tool names, hook stderr, credentials, and `.env` material. `subtasks[].description` contains only the bounded, sanitized task summary needed by the topology router.
23
25
 
24
26
  ---
25
27
 
@@ -47,11 +49,11 @@
47
49
  **Steps:**
48
50
 
49
51
  1. Call `adaptorch_capabilities` once per preview session (cache TTL).
50
- 2. Call `adaptorch_route_topology` with `{ payload_shape }`.
51
- 3. Map classification to one of: `singleton`, `pipeline`, `DAG`, `ensemble` (closed enum).
52
- 4. If transport missing: set `classification = unknown_local` and record `skipped_reason = no_verified_transport`.
52
+ 2. Call `adaptorch_route_topology` with `payload_shape` as the tool's top-level argument object.
53
+ 3. Read `raw.topology` and validate it against `adaptorch_capabilities.topologies`.
54
+ 4. If transport is missing or the value is outside that advertised set, set `topology = null` and record a bounded `skipped_reason`.
53
55
 
54
- **Outputs:** `TopologyPreview { classification, raw_redacted_summary }`.
56
+ **Outputs:** `TopologyPreview { topology: string | null, raw_redacted_summary }`.
55
57
 
56
58
  ---
57
59
 
@@ -61,7 +63,7 @@
61
63
 
62
64
  **Steps:**
63
65
 
64
- 1. If `classification` is `DAG` or `ensemble`, decompose into lane candidates along **write-scope boundaries** (one writer per file).
66
+ 1. Treat topology as advice only. For any proposed parallel lane set, decompose along **write-scope boundaries** (one writer per file) and validate dependencies independently.
65
67
  2. Compose each lane: `scope`, `authority`, `skills[]`, `mcp[]`, relevant hooks, `acceptance`, `evidence_output_path`.
66
68
  3. Run read-only authority stripping and always-on security hooks policy.
67
69
  4. Reject parallel grants that share the same write path.
@@ -78,7 +80,7 @@
78
80
 
79
81
  1. Read `observed_cardinality_mode` if configured (`single_call` \| `fanout_n` \| `uncalibrated`).
80
82
  2. Under `single_call`: `expected_run_ids = 1` per dispatch record.
81
- 3. Under `fanout_n`: derive N from topology template (ensemble = N parallel; pipeline = stage count) **labeled as hypothesis** until calibrated.
83
+ 3. Under `fanout_n`: derive N only from an explicit caller-owned dispatch template; topology names alone do not determine call count. Label the result as a hypothesis until calibrated.
82
84
  4. Flag `cardinality_anomaly` if prior observations disagree with mode.
83
85
 
84
86
  **Outputs:** `DispatchPreview { cardinality_mode, expected_run_ids, anomaly_flag }`.
@@ -123,7 +125,7 @@ function PreviewOrchestrate(inputs):
123
125
  if inputs.adaptorch_transport is granted and inputs.payload_shape is sanitized:
124
126
  B <- StageB_TopologyPreview(inputs.adaptorch_transport, inputs.payload_shape)
125
127
  else:
126
- B <- { classification: unknown_local, skipped_reason: transport_or_shape }
128
+ B <- { topology: null, skipped_reason: transport_or_shape }
127
129
  C <- StageC_ComposeLanes(A, B, inputs.lane_grants, inputs.budget_caps)
128
130
  D <- StageD_DispatchCardinalityPreview(B, loop_config.observed_cardinality_mode)
129
131
  E <- StageE_VerificationPreview(C.default_kind)
@@ -139,12 +141,12 @@ function PreviewOrchestrate(inputs):
139
141
  function TopologyClassifyPreview(transport, payload_shape):
140
142
  caps <- transport.call("adaptorch_capabilities", {})
141
143
  if caps indicates unsupported connector:
142
- return { classification: unknown_local, skipped_reason: capabilities }
143
- raw <- transport.call("adaptorch_route_topology", { payload_shape: payload_shape })
144
- class <- extract_enum(raw.classification, {singleton, pipeline, DAG, ensemble})
145
- if class is missing:
146
- return { classification: unknown_local, skipped_reason: unparseable }
147
- return { classification: class, raw_redacted_summary: redact(raw) }
144
+ return { topology: null, skipped_reason: capabilities }
145
+ raw <- transport.call("adaptorch_route_topology", payload_shape)
146
+ topology <- extract_enum(raw.topology, caps.topologies)
147
+ if topology is missing:
148
+ return { topology: null, skipped_reason: unparseable }
149
+ return { topology: topology, raw_redacted_summary: redact(raw) }
148
150
  ```
149
151
 
150
152
  ---
@@ -1,8 +1,8 @@
1
- # AdaptTorch Preview Algorithm
1
+ # AdaptOrch Preview Algorithm
2
2
 
3
- ## English — AdaptTorch Preview Algorithm
3
+ ## English — AdaptOrch Preview Algorithm
4
4
 
5
- **AdaptTorch Preview** is a **read-first planning pipeline** for OMK sessions that need AdaptOrch-aware routing without prematurely submitting control-plane runs. It composes domain loadout signals, optional local topology classification (`adaptorch_capabilities`, `adaptorch_route_topology`), lane grants with explicit write scopes, dispatch cardinality hypotheses, and adjudicator evidence contracts—then hands a `PreviewResult` to the root coordinator for DAG execution or deterministic fallback.
5
+ **AdaptOrch Preview** is a **documentation blueprint**, not a wired runtime. It describes a read-first planning pipeline that could combine domain signals, optional topology advice (`adaptorch_capabilities`, `adaptorch_route_topology`), scoped lane proposals, dispatch-cardinality hypotheses, and evidence contracts. No default OMK consumer executes a `PreviewResult`.
6
6
 
7
7
  Use preview when:
8
8
 
@@ -14,15 +14,15 @@ Do **not** treat preview output as proof that `adaptorch_run` completed; termina
14
14
 
15
15
  Related packages:
16
16
 
17
- - WPL loop package: `packages/adaptorch-wpl/` (stable since 0.91.0; ships with the CLI as a runtime dependency).
17
+ - WPL primitives: `packages/adaptorch-wpl/` (published runtime dependency; no default end-to-end CLI dispatch loop).
18
18
  - Advisory bridge (default-off): `packages/coding-agent/src/core/adaptorch-bridge.ts`.
19
19
  - Grok + AdaptOrch presets: [grok-harness.md](./grok-harness.md).
20
20
 
21
21
  ---
22
22
 
23
- ## 한국어 — AdaptTorch 프리뷰 알고리즘
23
+ ## 한국어 — AdaptOrch 프리뷰 알고리즘
24
24
 
25
- **AdaptTorch Preview**는 AdaptOrch 제어 평면에 `adaptorch_run`을 **아직 제출하지 않은 상태**에서, OMK가 도메인 신호·토폴로지 분류·레인 그랜트·디스패치 규모 가설·검증 증거 계약을 한 번에 정리하는 **읽기 우선 계획 파이프라인**입니다. 결과 `PreviewResult`는 루트 코디네이터가 DAG 병렬 실행 또는 로컬 폴백을 선택할 때 사용합니다.
25
+ **AdaptOrch Preview**는 배선된 런타임이 아니라 **문서 설계안**입니다. `adaptorch_run` 제출 전에 도메인 신호·토폴로지 자문·레인 제안·디스패치 규모 가설·검증 증거 계약을 정리하는 읽기 우선 파이프라인을 설명합니다. 기본 OMK 런타임은 `PreviewResult`를 실행하지 않습니다.
26
26
 
27
27
  프리뷰를 쓰는 경우:
28
28
 
@@ -34,7 +34,7 @@ Related packages:
34
34
 
35
35
  관련 경로:
36
36
 
37
- - WPL 루프: `packages/adaptorch-wpl/` (0.91.0부터 안정화, CLI 런타임 의존성으로 포함).
37
+ - WPL 프리미티브: `packages/adaptorch-wpl/` (공개 런타임 의존성, 기본 CLI end-to-end dispatch 배선 없음).
38
38
  - 어드바이저리 브리지(기본 비활성): `packages/coding-agent/src/core/adaptorch-bridge.ts`.
39
39
  - Grok 세션: [grok-harness.md](./grok-harness.md).
40
40
 
@@ -44,7 +44,7 @@ Related packages:
44
44
 
45
45
  | Forbidden (do not say without execution evidence) | Allowed (preview / planning) |
46
46
  | --- | --- |
47
- | "AdaptOrch finished the task" / "run succeeded" | "Topology preview classified as DAG" |
47
+ | "AdaptOrch finished the task" / "run succeeded" | "Topology preview returned `hybrid`; no run was submitted" |
48
48
  | "Verified in production" / "deployed via AdaptOrch" | "Lane grants composed; evidence path is …" |
49
49
  | "AdaptOrch proved correctness" | "Skipped AdaptOrch: no verified transport" |
50
50
  | "Automatically executed the loop" | "Preview recommends `adaptorch_route_topology` then local synthesis" |
@@ -67,7 +67,7 @@ Use that file for implementation planning; this page is the operator-facing intr
67
67
 
68
68
  ## OMK positioning
69
69
 
70
- Models execute; **OMK routes, verifies, measures, and controls**. AdaptTorch Preview sits in the **route + verify** layer: it turns ambiguous goals into explicit lane grants and evidence contracts before any model spends write tokens on shared paths. AdaptOrch MCP tools may inform topology, but lane authority, hooks, and success predicates remain OMK-owned unless the user explicitly delegates a mutating control-plane lane.
70
+ Models execute; **OMK routes, verifies, measures, and controls**. AdaptOrch Preview is a route-and-evidence blueprint. AdaptOrch tools may advise topology, but preview output grants no lane authority and proves no execution; an actual caller must define ownership, hooks, and success predicates.
71
71
 
72
72
  ---
73
73
 
@@ -102,9 +102,10 @@ Every compaction and branch-summary LLM call flows through one choke point (`com
102
102
 
103
103
  1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.omk/agent/settings.json` or `<project-dir>/.omk/settings.json`) is reached
104
104
  2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
105
- 3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
106
- 4. **Sanitize and append**: Deterministically redact sensitive values, then save the `CompactionEntry` with its summary and `firstKeptEntryId`. Exact `[REDACTED]` assignment placeholders are valid; appended data and unredacted credential-shaped literals remain rejected.
107
- 5. **Reload**: Session reloads, using summary + messages from `firstKeptEntryId` onwards
105
+ 3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present.
106
+ 4. **Apply knowledge triage**: Strip any model-generated managed-rule section, then append only explicit user-authored rules carried by the deterministic triage layer.
107
+ 5. **Sanitize and append**: Deterministically redact sensitive values, then save the `CompactionEntry` with its summary, preserved-rule details, and `firstKeptEntryId`. Exact `[REDACTED]` assignment placeholders are valid; appended data and unredacted credential-shaped literals remain rejected.
108
+ 6. **Reload**: Session reloads, using summary + messages from `firstKeptEntryId` onwards.
108
109
 
109
110
  ```
110
111
  Before compaction:
@@ -305,6 +306,11 @@ Both compaction and branch summarization use the same structured format:
305
306
  ## Critical Context
306
307
  - [Data needed to continue]
307
308
 
309
+ ## Preserved Rules & Invariants (verbatim)
310
+ <!-- Managed by OMK after model generation; not model-authored evidence. -->
311
+ - [Exact redacted explicit user rule]
312
+ <!-- source-bound metadata -->
313
+
308
314
  <read-files>
309
315
  path/to/file1.ts
310
316
  path/to/file2.ts
@@ -315,6 +321,21 @@ path/to/changed.ts
315
321
  </modified-files>
316
322
  ```
317
323
 
324
+ ### Deterministic rule preservation
325
+
326
+ The default compactor has a conservative Worktree-only knowledge-triage slice:
327
+
328
+ - It inspects direct user-role text only. Assistant/tool text and user messages containing `<file>` or `<stdin>` attachment data cannot become preserved rules.
329
+ - It admits only lines with explicit English markers (`RULE:`, `INVARIANT:`, `CONSTRAINT:`, `REQUIREMENT:`, `MUST`, `NEVER`, `ALWAYS`) or Korean markers (`규칙:`, `불변식:`, `제약:`, `요구사항:`, `반드시`, `절대`).
330
+ - It strips any managed-rule section emitted by the summarization model, then appends a deterministic block after generation.
331
+ - It redacts credential-shaped content before rendering or persistence, rejects controls/reserved markers, and stores at most 64 unique rules of at most 1,000 characters each.
332
+ - Each record carries a user-entry source ID, source line, and digest; the same source metadata is embedded in the managed block.
333
+ - A later default compaction reads prior rules only from validated non-hook details whose canonical block is present in the previous summary, so the block survives repeated compactions byte-identically.
334
+
335
+ This slice intentionally favors precision over recall. Ordinary natural-language constraints still rely on the LLM summary unless the user marks them explicitly. Custom hook summaries and branch summaries remain caller-owned and do not gain trusted-rule status. Source files, receipts, and protocol observations remain stronger evidence than any compaction summary.
336
+
337
+ See `specs/018-type-aware-compaction/spec.md` for scope and prior-art grounding.
338
+
318
339
  ### Message Serialization
319
340
 
320
341
  Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/dmae97/omk/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
@@ -19,7 +19,7 @@ It does **not** prove that code is correct, complete, or safe for production.
19
19
  | **PASS** | Fast wall (and optional OA) found no blocking issues. |
20
20
  | **ADVISORY** | Proceed with caution; preview limits or weak discrimination may apply. |
21
21
  | **INCONCLUSIVE** | Not enough evidence (empty diff, missing fixture, verifier error). |
22
- | **BLOCKED** | Scope, secret heuristic, or OA contradiction do not apply by default. |
22
+ | **BLOCKED** | Scope, secret heuristic, or OA contradiction. `hard` blocks it; `soft` blocks unless overridden; `shadow` records it and proceeds. |
23
23
 
24
24
  Structured next steps on the verdict card: **Apply**, **Deep Check**, **Regenerate** (see `packages/adaptorch-wpl` B2C mapper).
25
25
 
@@ -28,13 +28,13 @@ Structured next steps on the verdict card: **Apply**, **Deep Check**, **Regenera
28
28
  ## Fast wall vs deep wall
29
29
 
30
30
  - **Fast wall (default):** Pure policy — diff paths, scope globs, secret-shaped lines, preview-only limits (`BATCH1_NO_DOCKER_RUNNER`). No Docker runner in batch 1.
31
- - **Deep wall (Pro / future):** Hermetic paired base/patch replay. Today `deepWall: true` returns **unavailable** (evidence-gated: requires a valid execution receipt per ALG-003 strict mode; no Docker runner wired in batch 1).
31
+ - **Proposed deep wall (unavailable):** Hermetic paired base/patch replay. Today `deepWall: true` returns **unavailable** (evidence-gated: requires a valid execution receipt per ALG-003 strict mode; no Docker runner wired in batch 1).
32
32
 
33
- ## Relationship to Adaptorch
33
+ ## Relationship to AdaptOrch
34
34
 
35
- - Hidden engine: `omk-adaptorch-wpl` (`evaluateCorrectnessWall`, outcome adjudicator, repair hints).
35
+ - Library: published `omk-adaptorch-wpl` (`evaluateCorrectnessWall`, outcome adjudicator, repair hints); the extension remains explicit opt-in.
36
36
  - Optional OA path: `runIds` + `previewOnly: false` + in-memory or MCP transport.
37
- - Adaptorch **preview** planning is separate; see [adaptorch-preview.md](./adaptorch-preview.md).
37
+ - AdaptOrch **preview** planning is separate; see [adaptorch-preview.md](./adaptorch-preview.md).
38
38
 
39
39
  ## Operator environment
40
40
 
@@ -72,7 +72,7 @@ The correctness wall is **not** part of the default `omk-core-verified` preset o
72
72
  | **Scope** | `OMK_WALL_SCOPE` — comma-separated path globs that approve write targets in the diff |
73
73
  | **Mode** | `OMK_PATCH_SAFETY_WALL_MODE` — `shadow` \| `soft` \| `hard` (see [Operator environment](#operator-environment)) |
74
74
  | **Role loadouts** | `code` / `executor` lanes still get `pre-shell-guard`, `protect-secrets`, and `typecheck-after-edit`; the wall **adds** a pre-apply policy gate on `edit` / `write` only when the extension is loaded |
75
- | **Domain router** | No dedicated domain profile today; patch-safety work may route to [`ai-agent-ops`](./loadout-domains/ai-agent-ops.md) for harness/eval discipline, but that does **not** auto-load this extension |
75
+ | **Domain router** | The PATCH SAFETY profile routes relevant prompts, but it does **not** auto-load this extension |
76
76
 
77
77
  **Domain router triggers (implemented):** `packages/coding-agent/src/core/domain-loadouts.ts` already contains keyword triggers (`correctness wall`, `patch safety`) and a path trigger (`correctness-wall`) that route to the PATCH SAFETY domain profile. The profile instructs operators to load the correctness-wall extension explicitly (not in default preset) and follow the shadow → soft → hard rollout. Auto-generated docs under `docs/loadout-domains/` should be regenerated via `gen-domain-docs.mjs`, not hand-edited.
78
78
 
@@ -88,7 +88,7 @@ Roll out in **three phases** so telemetry and false positives are understood bef
88
88
  | **2 — Soft** | `soft` | **BLOCKED** verdicts block apply unless `OMK_WALL_OVERRIDE=1` (or `true` / `yes`). **INCONCLUSIVE** still applies in shadow-like fashion for scope tuning. Use for pilot teams with an explicit override path. |
89
89
  | **3 — Hard** | `hard` | **BLOCKED** and **INCONCLUSIVE** both block `edit` / `write`. Reserve for repos with stable scope globs, OA fixtures wired (`OMK_WALL_RUN_IDS` + `OMK_WALL_OA_FIXTURE_PATH`), and acceptable INCONCLUSIVE rate (missing files, empty diff). |
90
90
 
91
- **Checklist between phases**
91
+ ### Checklist between phases
92
92
 
93
93
  1. AC-1 vitest green for `packages/adaptorch-wpl` and regression `018-b2c-correctness-wall`.
94
94
  2. Root `npm run check` green after any source touch (includes unrelated **browser-smoke** esbuild gate — wall work does not require loading the extension in that script).
@@ -112,8 +112,8 @@ Goal orchestration v2 artifacts (planner P3) live beside batch-1 plan files:
112
112
  - ⬜ Lift `BATCH1_NO_DOCKER_RUNNER` for non-preview deep wall — still stub.
113
113
  - ⬜ Preset documentation in `~/.omk/runtime-preset.json` — deferred.
114
114
 
115
- **Wave 3 (productize) — Not started:**
116
- - Publish `omk-adaptorch-wpl` from `dist/` for out-of-monorepo extensions.
115
+ **Wave 3 (productize) — Partial:**
116
+ - `omk-adaptorch-wpl` is published; out-of-monorepo consumers can install the package.
117
117
  - ✅ `domain-loadouts.ts` profile exists; `gen-domain-docs.mjs` regen pending.
118
118
  - ⬜ Default **soft** for internal dogfood presets after Wave 2 evidence.
119
119
 
@@ -122,4 +122,4 @@ Goal orchestration v2 artifacts (planner P3) live beside batch-1 plan files:
122
122
  - [adaptorch-preview.md](./adaptorch-preview.md)
123
123
  - [LOADOUT.md](../examples/extensions/correctness-wall/LOADOUT.md) — copy-paste for `omk-core-verified` sessions
124
124
  - Goal artifacts: `.omk/goals/b2c-correctness-wall-2026-07-08/` (`algorithm-v2.md`, `dag-v2.json`)
125
- - Extension README: `packages/coding-agent/examples/extensions/correctness-wall/README.md`
125
+ - Extension README: `packages/coding-agent/examples/extensions/correctness-wall/README.md`
package/docs/docs.json CHANGED
@@ -118,6 +118,18 @@
118
118
  "title": "Run Protocol & Durable Goals",
119
119
  "path": "run-protocol.md"
120
120
  },
121
+ {
122
+ "title": "Runtime Algorithms & Direction",
123
+ "path": "runtime-algorithms.md"
124
+ },
125
+ {
126
+ "title": "AdaptOrch Preview",
127
+ "path": "adaptorch-preview.md"
128
+ },
129
+ {
130
+ "title": "Correctness Wall",
131
+ "path": "correctness-wall.md"
132
+ },
121
133
  {
122
134
  "title": "RPC Mode",
123
135
  "path": "rpc.md"
@@ -83,19 +83,26 @@ These variables are read by OMK itself. The four built-in harness flags below ar
83
83
  | `OMK_TELEMETRY` | Override install/update telemetry and provider attribution headers: `1`/`true`/`yes` or `0`/`false`/`no` |
84
84
  | `OMK_SHARE_VIEWER_URL` | Override the base URL used by `/share` |
85
85
  | `OMK_HARDWARE_CURSOR` | Set to `1` to show the hardware cursor; see [Terminal setup](terminal-setup.md) |
86
- | `OMK_CONTEXT_GOVERNOR` | Configure the context-budget governor; see `context-budget-*` sources |
86
+ | `OMK_CONTEXT_GOVERNOR` | Context Budget V2 process override: `1` forces it on and `0` forces it off; otherwise the global `contextBudget.enabled` setting applies |
87
+ | `OMK_CONTEXT_GOVERNOR_CACHE` | Set to `memory` to keep representations, negative results, and plans in session memory instead of persisting representations per workspace |
88
+ | `OMK_CONTEXT_GOVERNOR_CACHE_DIR` | Relocate the Context Budget V2 representation snapshot from `.omk/cache/context-budget-v2`; plans remain session-memory-only |
87
89
  | `OMK_VERIFIED_BASH` | Default-on verified bash adapter for AgentSession/CLI bash. Set to `0` to opt out and use the legacy unverified path (see [SDK — Evidence and Verification](sdk.md#evidence-and-verification)) |
88
90
  | `OMK_BASH_SANDBOX` | AgentSession built-in local bash mode. Unset or unknown values select `enforce`: macOS `sandbox-exec` or Linux `bwrap`, workspace/temp writes only, network disabled, and fail closed without a usable backend. Explicit `audit` selects the unwrapped ledger-only path; `0`/`off` disables the preflight. Use `off` only when a verified outer whole-process sandbox owns isolation; it does not isolate OMK by itself |
89
91
  | `LIVE_E2E` | Test-only: keep provider credentials so live-API e2e suites run on purpose (default scrubbed for hermetic tests) |
90
- | `OMK_OMP_SEAMS` | Default-on OMP pure seams for `read`/`grep`. Set to `0` to opt out |
91
92
  | `OMK_IDENTICAL_LOOP` | Default-on consecutive-loop guard. Warns from the third identical `tool+args` call and blocks the sixth. Set a disabling value to opt out |
92
93
  | `OMK_TOOL_PAIR_REPAIR` | Default-on outbound-context repair. Removes unmatched tool-use and tool-result blocks before provider requests without rewriting the transcript. Set a disabling value to opt out |
93
94
  | `OMK_PROMPT_PRESET` | Default-on model-specific guidance for supported Claude/Anthropic, Kimi, GLM/ZAI, and Grok/xAI models. Set a disabling value to opt out |
94
95
  | `OMK_CLAUDE_CONTEXT_FILES` | Claude models omit discovered `AGENTS.md` and `CLAUDE.md` files by default to prevent unrelated context from causing provider false positives. Set to `1`, `true`, `on`, or `yes` to restore them |
95
96
  | `OMK_GOAL_CONTROLLER` | Default-on working-directory `/goal` command and automatic continuation. Goals created by `/goal` use an eight-round cap. Set a disabling value to opt out |
97
+ | `OMK_COMPLETION_SOUND` | Interactive-TTY terminal notification override: `0` disables it and `1` enables it. Sounds never run in RPC, JSON, print mode, or CI |
98
+ | `OMK_YOLO`, `OMK_COMMAND_SAFETY`, `OMK_DISABLE_COMMAND_SAFETY` | Disable the command-safety gate entirely (YOLO mode). `OMK_YOLO` and `OMK_DISABLE_COMMAND_SAFETY` accept `1`, `true`, `yes`, or `on`; `OMK_COMMAND_SAFETY` accepts `0`, `false`, `off`, `disable`, or `disabled`. Every verdict, including block-tier and privilege commands, is skipped in interactive and headless runs. Use only when a verified outer sandbox owns the boundary |
99
+ | `OMK_COMMAND_SAFETY_ASSUME_YES` | `1` or `true` auto-accepts non-privilege confirm-tier commands in interactive **and headless** runs. Privilege confirmation and block-tier commands remain denied. Use only under a trusted outer sandbox when headless auto-accept is intended |
96
100
  | `OMK_GROK_HARNESS` | Default-on native `xai` provider dispatch to the `grok-harness` loadout. `0`, `false`, `off`, or `no` disables it |
97
101
  | `OMK_DOMAIN_ROUTING` | Set to `1` to enable general prompt-based domain routing. Native xAI harness dispatch does not require it |
98
102
  | `VISUAL`, `EDITOR` | External editor fallback when `externalEditor` is unset |
99
103
  | `HTTP_PROXY`, `HTTPS_PROXY` | Proxy outbound HTTP requests |
104
+ | `OMK_RESOURCE_GOVERNOR` | Resource-governor mode: `off`, `observe` (default), `adaptive`, or `strict`. Feeds `/resource [probe\|policy]` and `omk doctor resources [--json]`; see the resource governor section in [Settings](settings.md) |
105
+ | `OMK_TOOL_SCHEDULER` | Tool scheduler override: `dag-v2` or the `waves-v1` rollback path; see also the `agent.toolScheduler` setting |
106
+ | `OMK_TURN_METRICS`, `OMK_TURN_METRICS_DIR` | Turn metrics are written under `.omk/metrics/` as sessions run; set `OMK_TURN_METRICS=0` to disable or `OMK_TURN_METRICS_DIR` to relocate. Aggregate with `omk stats`; see [Metrics](metrics.md) |
100
107
 
101
108
  Provider credentials such as `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, and cloud-provider configuration are listed in [Providers](providers.md).
package/docs/index.md CHANGED
@@ -61,6 +61,9 @@ For the full first-run flow, see [Quickstart](quickstart.md).
61
61
 
62
62
  - [SDK and Session Control](sdk.md) - embed omk, reuse policy helpers, or inspect stored sessions from scripts.
63
63
  - [Run Protocol and Durable Goals](run-protocol.md) - canonical run contracts and the durable-goal lifecycle.
64
+ - [Runtime algorithms and direction](runtime-algorithms.md) - released, opt-in, internal, working-tree, and proposed mechanisms.
65
+ - [AdaptOrch Preview](adaptorch-preview.md) - planning blueprint and claim boundary; not a default runtime path.
66
+ - [Correctness Wall](correctness-wall.md) - opt-in patch-apply safety extension and evidence limits.
64
67
  - [Turn metrics and harness evaluation](metrics.md) - cost, latency, tool reliability, capability baselines, and comparative-claim rules.
65
68
  - [RPC mode](rpc.md) - integrate over stdin/stdout JSONL.
66
69
  - [JSON event stream mode](json.md) - print mode with structured events.