@xyagent/cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/README.md +860 -0
  2. package/bin/agentlink +8585 -0
  3. package/bin/agentlink-agent +7 -0
  4. package/bin/agentlink-mcp-stdio +173 -0
  5. package/docs/LOGGING.md +159 -0
  6. package/package.json +38 -0
  7. package/src/core.mjs +320 -0
  8. package/src/tunnel.mjs +291 -0
  9. package/src/tunnel_proxy.mjs +913 -0
  10. package/src/tunnel_service.mjs +699 -0
  11. package/src/tunnel_state.mjs +301 -0
  12. package/src/unified_producer.mjs +259 -0
  13. package/src-ext/README.md +75 -0
  14. package/src-ext/bin.mjs +128 -0
  15. package/src-ext/commands/agent.mjs +66 -0
  16. package/src-ext/commands/help.mjs +31 -0
  17. package/src-ext/commands/pair.mjs +455 -0
  18. package/src-ext/commands/reload.mjs +78 -0
  19. package/src-ext/commands/service.mjs +64 -0
  20. package/src-ext/core/accountResolver.mjs +137 -0
  21. package/src-ext/core/activeRuns.mjs +76 -0
  22. package/src-ext/core/agentlinkToolsBootstrap.mjs +75 -0
  23. package/src-ext/core/agentlinkToolsRegistry.mjs +323 -0
  24. package/src-ext/core/agentlinkToolsServer.mjs +109 -0
  25. package/src-ext/core/approvalGateway.mjs +132 -0
  26. package/src-ext/core/attachAuditLog.mjs +79 -0
  27. package/src-ext/core/attachDenylist.mjs +128 -0
  28. package/src-ext/core/autoTunnelDetector.mjs +98 -0
  29. package/src-ext/core/autoTunnelGateway.mjs +393 -0
  30. package/src-ext/core/autoTunnelWiring.mjs +184 -0
  31. package/src-ext/core/boundedMap.mjs +98 -0
  32. package/src-ext/core/bridgeAttachAutoScanner.mjs +237 -0
  33. package/src-ext/core/bridgeHooks.mjs +168 -0
  34. package/src-ext/core/bridgeSelfUninstall.mjs +133 -0
  35. package/src-ext/core/claudeTrust.mjs +74 -0
  36. package/src-ext/core/codexTrust.mjs +77 -0
  37. package/src-ext/core/cosUploadClient.mjs +326 -0
  38. package/src-ext/core/createWorkspace.mjs +170 -0
  39. package/src-ext/core/daemonRestart.mjs +49 -0
  40. package/src-ext/core/defaultWorkspace.mjs +65 -0
  41. package/src-ext/core/ensureGitRepo.mjs +57 -0
  42. package/src-ext/core/hermesProfile.mjs +75 -0
  43. package/src-ext/core/interruptGateway.mjs +119 -0
  44. package/src-ext/core/interruptRunListener.mjs +106 -0
  45. package/src-ext/core/mcpRuntimeFanout.mjs +236 -0
  46. package/src-ext/core/mcpStdioClient.mjs +316 -0
  47. package/src-ext/core/openclawGatewayClient.mjs +230 -0
  48. package/src-ext/core/pairCodeClient.mjs +331 -0
  49. package/src-ext/core/pairInventory.mjs +59 -0
  50. package/src-ext/core/pathExpand.mjs +34 -0
  51. package/src-ext/core/preprocessAttachments.mjs +113 -0
  52. package/src-ext/core/relayWorker.mjs +284 -0
  53. package/src-ext/core/relayWorkerHttp.mjs +58 -0
  54. package/src-ext/core/scanWorkspaces.mjs +842 -0
  55. package/src-ext/core/sessionSlot.mjs +70 -0
  56. package/src-ext/core/stateMachine.mjs +85 -0
  57. package/src-ext/core/toolsServerLifecycle.mjs +169 -0
  58. package/src-ext/core/unifiedDispatchHandler.mjs +439 -0
  59. package/src-ext/core/usageReporter.mjs +207 -0
  60. package/src-ext/openclaw-plugin/envelope-builder.cjs +619 -0
  61. package/src-ext/openclaw-plugin/index.cjs +1919 -0
  62. package/src-ext/openclaw-plugin/openclaw.plugin.json +20 -0
  63. package/src-ext/openclaw-plugin/package.json +12 -0
  64. package/src-ext/openclaw-plugin/relay-defaults.json +3 -0
  65. package/src-ext/openclaw-plugin/todoTranslatorUtils.cjs +101 -0
  66. package/src-ext/runtime/_shared/cliExec.mjs +138 -0
  67. package/src-ext/runtime/_shared/cosTextRefs.mjs +120 -0
  68. package/src-ext/runtime/_shared/fetchAndBase64Encode.mjs +52 -0
  69. package/src-ext/runtime/_shared/relayObjectToBlock.mjs +307 -0
  70. package/src-ext/runtime/_shared/sessionPicker.mjs +418 -0
  71. package/src-ext/runtime/_shared/slashCommandRouter.mjs +1346 -0
  72. package/src-ext/runtime/_shared/todoTranslatorUtils.mjs +94 -0
  73. package/src-ext/runtime/claude/askUserQuestionTranslator.mjs +241 -0
  74. package/src-ext/runtime/claude/customCommandsCollector.mjs +132 -0
  75. package/src-ext/runtime/claude/handleRequest.mjs +1418 -0
  76. package/src-ext/runtime/claude/index.mjs +160 -0
  77. package/src-ext/runtime/claude/internalCommandNames.mjs +58 -0
  78. package/src-ext/runtime/claude/launcher.mjs +313 -0
  79. package/src-ext/runtime/claude/mcpConfigAdapter.mjs +174 -0
  80. package/src-ext/runtime/claude/mcpConfigWriter.mjs +57 -0
  81. package/src-ext/runtime/claude/modelContextWindow.mjs +30 -0
  82. package/src-ext/runtime/claude/modelScanner.mjs +257 -0
  83. package/src-ext/runtime/claude/permissionInterruptBlock.mjs +86 -0
  84. package/src-ext/runtime/claude/permissionPromptServer.mjs +170 -0
  85. package/src-ext/runtime/claude/permissionPromptServerWorker.mjs +214 -0
  86. package/src-ext/runtime/claude/preflight.mjs +62 -0
  87. package/src-ext/runtime/claude/stdoutParser.mjs +365 -0
  88. package/src-ext/runtime/claude/todoTranslator.mjs +66 -0
  89. package/src-ext/runtime/claude/usageProbe.mjs +576 -0
  90. package/src-ext/runtime/claude/usageProbeStrip.mjs +14 -0
  91. package/src-ext/runtime/codex/codexCustomCommandsCollector.mjs +87 -0
  92. package/src-ext/runtime/codex/elicitationHandler.mjs +91 -0
  93. package/src-ext/runtime/codex/eventMapper.mjs +154 -0
  94. package/src-ext/runtime/codex/handleRequest.mjs +1152 -0
  95. package/src-ext/runtime/codex/index.mjs +142 -0
  96. package/src-ext/runtime/codex/mcpConfigAdapter.mjs +155 -0
  97. package/src-ext/runtime/codex/modelScanner.mjs +305 -0
  98. package/src-ext/runtime/codex/planNotificationHandler.mjs +61 -0
  99. package/src-ext/runtime/codex/preflight.mjs +67 -0
  100. package/src-ext/runtime/hermes/commandBackend.mjs +117 -0
  101. package/src-ext/runtime/hermes/envSetup.mjs +229 -0
  102. package/src-ext/runtime/hermes/gatewayManager.mjs +625 -0
  103. package/src-ext/runtime/hermes/handleRequest.mjs +1257 -0
  104. package/src-ext/runtime/hermes/httpBackend.mjs +219 -0
  105. package/src-ext/runtime/hermes/index.mjs +196 -0
  106. package/src-ext/runtime/hermes/mcpConfigAdapter.mjs +189 -0
  107. package/src-ext/runtime/hermes/preflight.mjs +359 -0
  108. package/src-ext/runtime/hermes/responsesBackend.mjs +276 -0
  109. package/src-ext/runtime/hermes/sessionStore.mjs +78 -0
  110. package/src-ext/runtime/hermes/todoTranslator.mjs +90 -0
  111. package/src-ext/runtime/hermes/workspaceRpc.mjs +124 -0
  112. package/src-ext/runtime/openclaw/buildOpenclawDaemonInput.mjs +143 -0
  113. package/src-ext/runtime/openclaw/mcpConfigAdapter.mjs +91 -0
  114. package/src-ext/runtime/openclaw/openclawConfig.mjs +145 -0
  115. package/src-ext/runtime/picoclaw/constants.mjs +39 -0
  116. package/src-ext/runtime/picoclaw/handleRequest.mjs +289 -0
  117. package/src-ext/runtime/picoclaw/index.mjs +314 -0
  118. package/src-ext/runtime/picoclaw/pairFlow.mjs +224 -0
  119. package/src-ext/runtime/picoclaw/state.mjs +78 -0
  120. package/src-ext/runtime/picoclaw/todoTranslator.mjs +67 -0
  121. package/src-ext/runtime/picoclaw/translator.mjs +272 -0
  122. package/src-ext/runtime/picoclaw/wsClient.mjs +129 -0
  123. package/src-ext/service/serviceManager.mjs +521 -0
  124. package/src-shared/README.md +44 -0
  125. package/src-shared/chat_push_normalizer.mjs +113 -0
  126. package/src-shared/correlation.mjs +25 -0
  127. package/src-shared/envelope_builder.mjs +612 -0
  128. package/src-shared/logger.mjs +167 -0
  129. package/src-shared/relay-defaults.json +3 -0
  130. package/src-shared/relay_revoke.mjs +46 -0
  131. package/src-shared/vendor/README.md +60 -0
  132. package/src-shared/vendor/smol-toml/LICENSE +24 -0
  133. package/src-shared/vendor/smol-toml/README.md +236 -0
  134. package/src-shared/vendor/smol-toml/VENDORED.md +37 -0
  135. package/src-shared/vendor/smol-toml/dist/date.d.ts +41 -0
  136. package/src-shared/vendor/smol-toml/dist/date.js +127 -0
  137. package/src-shared/vendor/smol-toml/dist/error.d.ts +38 -0
  138. package/src-shared/vendor/smol-toml/dist/error.js +63 -0
  139. package/src-shared/vendor/smol-toml/dist/extract.d.ts +30 -0
  140. package/src-shared/vendor/smol-toml/dist/extract.js +109 -0
  141. package/src-shared/vendor/smol-toml/dist/index.cjs +900 -0
  142. package/src-shared/vendor/smol-toml/dist/index.d.ts +43 -0
  143. package/src-shared/vendor/smol-toml/dist/index.js +33 -0
  144. package/src-shared/vendor/smol-toml/dist/parse.d.ts +37 -0
  145. package/src-shared/vendor/smol-toml/dist/parse.js +148 -0
  146. package/src-shared/vendor/smol-toml/dist/primitive.d.ts +31 -0
  147. package/src-shared/vendor/smol-toml/dist/primitive.js +178 -0
  148. package/src-shared/vendor/smol-toml/dist/stringify.d.ts +31 -0
  149. package/src-shared/vendor/smol-toml/dist/stringify.js +163 -0
  150. package/src-shared/vendor/smol-toml/dist/struct.d.ts +32 -0
  151. package/src-shared/vendor/smol-toml/dist/struct.js +194 -0
  152. package/src-shared/vendor/smol-toml/dist/util.d.ts +42 -0
  153. package/src-shared/vendor/smol-toml/dist/util.js +100 -0
  154. package/src-shared/vendor/smol-toml/package.json +54 -0
  155. package/src-shared/vendor/yaml/LICENSE +13 -0
  156. package/src-shared/vendor/yaml/README.md +155 -0
  157. package/src-shared/vendor/yaml/VENDORED.md +29 -0
  158. package/src-shared/vendor/yaml/bin.mjs +11 -0
  159. package/src-shared/vendor/yaml/browser/dist/compose/compose-collection.js +88 -0
  160. package/src-shared/vendor/yaml/browser/dist/compose/compose-doc.js +42 -0
  161. package/src-shared/vendor/yaml/browser/dist/compose/compose-node.js +92 -0
  162. package/src-shared/vendor/yaml/browser/dist/compose/compose-scalar.js +80 -0
  163. package/src-shared/vendor/yaml/browser/dist/compose/composer.js +217 -0
  164. package/src-shared/vendor/yaml/browser/dist/compose/resolve-block-map.js +113 -0
  165. package/src-shared/vendor/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  166. package/src-shared/vendor/yaml/browser/dist/compose/resolve-block-seq.js +47 -0
  167. package/src-shared/vendor/yaml/browser/dist/compose/resolve-end.js +37 -0
  168. package/src-shared/vendor/yaml/browser/dist/compose/resolve-flow-collection.js +203 -0
  169. package/src-shared/vendor/yaml/browser/dist/compose/resolve-flow-scalar.js +223 -0
  170. package/src-shared/vendor/yaml/browser/dist/compose/resolve-props.js +148 -0
  171. package/src-shared/vendor/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  172. package/src-shared/vendor/yaml/browser/dist/compose/util-empty-scalar-position.js +27 -0
  173. package/src-shared/vendor/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  174. package/src-shared/vendor/yaml/browser/dist/compose/util-map-includes.js +17 -0
  175. package/src-shared/vendor/yaml/browser/dist/doc/Document.js +334 -0
  176. package/src-shared/vendor/yaml/browser/dist/doc/anchors.js +72 -0
  177. package/src-shared/vendor/yaml/browser/dist/doc/applyReviver.js +55 -0
  178. package/src-shared/vendor/yaml/browser/dist/doc/createNode.js +89 -0
  179. package/src-shared/vendor/yaml/browser/dist/doc/directives.js +176 -0
  180. package/src-shared/vendor/yaml/browser/dist/errors.js +57 -0
  181. package/src-shared/vendor/yaml/browser/dist/index.js +17 -0
  182. package/src-shared/vendor/yaml/browser/dist/log.js +14 -0
  183. package/src-shared/vendor/yaml/browser/dist/nodes/Alias.js +101 -0
  184. package/src-shared/vendor/yaml/browser/dist/nodes/Collection.js +147 -0
  185. package/src-shared/vendor/yaml/browser/dist/nodes/Node.js +38 -0
  186. package/src-shared/vendor/yaml/browser/dist/nodes/Pair.js +36 -0
  187. package/src-shared/vendor/yaml/browser/dist/nodes/Scalar.js +24 -0
  188. package/src-shared/vendor/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  189. package/src-shared/vendor/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  190. package/src-shared/vendor/yaml/browser/dist/nodes/addPairToJSMap.js +104 -0
  191. package/src-shared/vendor/yaml/browser/dist/nodes/identity.js +36 -0
  192. package/src-shared/vendor/yaml/browser/dist/nodes/toJS.js +37 -0
  193. package/src-shared/vendor/yaml/browser/dist/parse/cst-scalar.js +214 -0
  194. package/src-shared/vendor/yaml/browser/dist/parse/cst-stringify.js +61 -0
  195. package/src-shared/vendor/yaml/browser/dist/parse/cst-visit.js +97 -0
  196. package/src-shared/vendor/yaml/browser/dist/parse/cst.js +98 -0
  197. package/src-shared/vendor/yaml/browser/dist/parse/lexer.js +717 -0
  198. package/src-shared/vendor/yaml/browser/dist/parse/line-counter.js +39 -0
  199. package/src-shared/vendor/yaml/browser/dist/parse/parser.js +954 -0
  200. package/src-shared/vendor/yaml/browser/dist/public-api.js +99 -0
  201. package/src-shared/vendor/yaml/browser/dist/schema/Schema.js +38 -0
  202. package/src-shared/vendor/yaml/browser/dist/schema/common/map.js +17 -0
  203. package/src-shared/vendor/yaml/browser/dist/schema/common/null.js +15 -0
  204. package/src-shared/vendor/yaml/browser/dist/schema/common/seq.js +17 -0
  205. package/src-shared/vendor/yaml/browser/dist/schema/common/string.js +14 -0
  206. package/src-shared/vendor/yaml/browser/dist/schema/core/bool.js +19 -0
  207. package/src-shared/vendor/yaml/browser/dist/schema/core/float.js +43 -0
  208. package/src-shared/vendor/yaml/browser/dist/schema/core/int.js +38 -0
  209. package/src-shared/vendor/yaml/browser/dist/schema/core/schema.js +23 -0
  210. package/src-shared/vendor/yaml/browser/dist/schema/json/schema.js +62 -0
  211. package/src-shared/vendor/yaml/browser/dist/schema/tags.js +83 -0
  212. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/binary.js +66 -0
  213. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  214. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  215. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  216. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  217. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  218. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/schema.js +37 -0
  219. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  220. package/src-shared/vendor/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  221. package/src-shared/vendor/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  222. package/src-shared/vendor/yaml/browser/dist/stringify/stringify.js +124 -0
  223. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyCollection.js +143 -0
  224. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  225. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  226. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyNumber.js +24 -0
  227. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  228. package/src-shared/vendor/yaml/browser/dist/stringify/stringifyString.js +328 -0
  229. package/src-shared/vendor/yaml/browser/dist/util.js +11 -0
  230. package/src-shared/vendor/yaml/browser/dist/visit.js +233 -0
  231. package/src-shared/vendor/yaml/browser/index.js +5 -0
  232. package/src-shared/vendor/yaml/browser/package.json +3 -0
  233. package/src-shared/vendor/yaml/dist/cli.d.ts +8 -0
  234. package/src-shared/vendor/yaml/dist/cli.mjs +199 -0
  235. package/src-shared/vendor/yaml/dist/compose/compose-collection.d.ts +11 -0
  236. package/src-shared/vendor/yaml/dist/compose/compose-collection.js +90 -0
  237. package/src-shared/vendor/yaml/dist/compose/compose-doc.d.ts +7 -0
  238. package/src-shared/vendor/yaml/dist/compose/compose-doc.js +44 -0
  239. package/src-shared/vendor/yaml/dist/compose/compose-node.d.ts +28 -0
  240. package/src-shared/vendor/yaml/dist/compose/compose-node.js +95 -0
  241. package/src-shared/vendor/yaml/dist/compose/compose-scalar.d.ts +5 -0
  242. package/src-shared/vendor/yaml/dist/compose/compose-scalar.js +82 -0
  243. package/src-shared/vendor/yaml/dist/compose/composer.d.ts +62 -0
  244. package/src-shared/vendor/yaml/dist/compose/composer.js +221 -0
  245. package/src-shared/vendor/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  246. package/src-shared/vendor/yaml/dist/compose/resolve-block-map.js +115 -0
  247. package/src-shared/vendor/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  248. package/src-shared/vendor/yaml/dist/compose/resolve-block-scalar.js +200 -0
  249. package/src-shared/vendor/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  250. package/src-shared/vendor/yaml/dist/compose/resolve-block-seq.js +49 -0
  251. package/src-shared/vendor/yaml/dist/compose/resolve-end.d.ts +6 -0
  252. package/src-shared/vendor/yaml/dist/compose/resolve-end.js +39 -0
  253. package/src-shared/vendor/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  254. package/src-shared/vendor/yaml/dist/compose/resolve-flow-collection.js +205 -0
  255. package/src-shared/vendor/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  256. package/src-shared/vendor/yaml/dist/compose/resolve-flow-scalar.js +225 -0
  257. package/src-shared/vendor/yaml/dist/compose/resolve-props.d.ts +23 -0
  258. package/src-shared/vendor/yaml/dist/compose/resolve-props.js +150 -0
  259. package/src-shared/vendor/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  260. package/src-shared/vendor/yaml/dist/compose/util-contains-newline.js +36 -0
  261. package/src-shared/vendor/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  262. package/src-shared/vendor/yaml/dist/compose/util-empty-scalar-position.js +29 -0
  263. package/src-shared/vendor/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  264. package/src-shared/vendor/yaml/dist/compose/util-flow-indent-check.js +17 -0
  265. package/src-shared/vendor/yaml/dist/compose/util-map-includes.d.ts +4 -0
  266. package/src-shared/vendor/yaml/dist/compose/util-map-includes.js +19 -0
  267. package/src-shared/vendor/yaml/dist/doc/Document.d.ts +141 -0
  268. package/src-shared/vendor/yaml/dist/doc/Document.js +336 -0
  269. package/src-shared/vendor/yaml/dist/doc/anchors.d.ts +24 -0
  270. package/src-shared/vendor/yaml/dist/doc/anchors.js +77 -0
  271. package/src-shared/vendor/yaml/dist/doc/applyReviver.d.ts +9 -0
  272. package/src-shared/vendor/yaml/dist/doc/applyReviver.js +57 -0
  273. package/src-shared/vendor/yaml/dist/doc/createNode.d.ts +17 -0
  274. package/src-shared/vendor/yaml/dist/doc/createNode.js +91 -0
  275. package/src-shared/vendor/yaml/dist/doc/directives.d.ts +49 -0
  276. package/src-shared/vendor/yaml/dist/doc/directives.js +178 -0
  277. package/src-shared/vendor/yaml/dist/errors.d.ts +21 -0
  278. package/src-shared/vendor/yaml/dist/errors.js +62 -0
  279. package/src-shared/vendor/yaml/dist/index.d.ts +22 -0
  280. package/src-shared/vendor/yaml/dist/index.js +50 -0
  281. package/src-shared/vendor/yaml/dist/log.d.ts +3 -0
  282. package/src-shared/vendor/yaml/dist/log.js +17 -0
  283. package/src-shared/vendor/yaml/dist/nodes/Alias.d.ts +28 -0
  284. package/src-shared/vendor/yaml/dist/nodes/Alias.js +103 -0
  285. package/src-shared/vendor/yaml/dist/nodes/Collection.d.ts +73 -0
  286. package/src-shared/vendor/yaml/dist/nodes/Collection.js +151 -0
  287. package/src-shared/vendor/yaml/dist/nodes/Node.d.ts +47 -0
  288. package/src-shared/vendor/yaml/dist/nodes/Node.js +40 -0
  289. package/src-shared/vendor/yaml/dist/nodes/Pair.d.ts +21 -0
  290. package/src-shared/vendor/yaml/dist/nodes/Pair.js +39 -0
  291. package/src-shared/vendor/yaml/dist/nodes/Scalar.d.ts +42 -0
  292. package/src-shared/vendor/yaml/dist/nodes/Scalar.js +27 -0
  293. package/src-shared/vendor/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  294. package/src-shared/vendor/yaml/dist/nodes/YAMLMap.js +147 -0
  295. package/src-shared/vendor/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  296. package/src-shared/vendor/yaml/dist/nodes/YAMLSeq.js +115 -0
  297. package/src-shared/vendor/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  298. package/src-shared/vendor/yaml/dist/nodes/addPairToJSMap.js +106 -0
  299. package/src-shared/vendor/yaml/dist/nodes/identity.d.ts +23 -0
  300. package/src-shared/vendor/yaml/dist/nodes/identity.js +53 -0
  301. package/src-shared/vendor/yaml/dist/nodes/toJS.d.ts +27 -0
  302. package/src-shared/vendor/yaml/dist/nodes/toJS.js +39 -0
  303. package/src-shared/vendor/yaml/dist/options.d.ts +338 -0
  304. package/src-shared/vendor/yaml/dist/parse/cst-scalar.d.ts +64 -0
  305. package/src-shared/vendor/yaml/dist/parse/cst-scalar.js +218 -0
  306. package/src-shared/vendor/yaml/dist/parse/cst-stringify.d.ts +8 -0
  307. package/src-shared/vendor/yaml/dist/parse/cst-stringify.js +63 -0
  308. package/src-shared/vendor/yaml/dist/parse/cst-visit.d.ts +39 -0
  309. package/src-shared/vendor/yaml/dist/parse/cst-visit.js +99 -0
  310. package/src-shared/vendor/yaml/dist/parse/cst.d.ts +108 -0
  311. package/src-shared/vendor/yaml/dist/parse/cst.js +112 -0
  312. package/src-shared/vendor/yaml/dist/parse/lexer.d.ts +87 -0
  313. package/src-shared/vendor/yaml/dist/parse/lexer.js +719 -0
  314. package/src-shared/vendor/yaml/dist/parse/line-counter.d.ts +22 -0
  315. package/src-shared/vendor/yaml/dist/parse/line-counter.js +41 -0
  316. package/src-shared/vendor/yaml/dist/parse/parser.d.ts +84 -0
  317. package/src-shared/vendor/yaml/dist/parse/parser.js +958 -0
  318. package/src-shared/vendor/yaml/dist/public-api.d.ts +43 -0
  319. package/src-shared/vendor/yaml/dist/public-api.js +104 -0
  320. package/src-shared/vendor/yaml/dist/schema/Schema.d.ts +18 -0
  321. package/src-shared/vendor/yaml/dist/schema/Schema.js +40 -0
  322. package/src-shared/vendor/yaml/dist/schema/common/map.d.ts +2 -0
  323. package/src-shared/vendor/yaml/dist/schema/common/map.js +19 -0
  324. package/src-shared/vendor/yaml/dist/schema/common/null.d.ts +4 -0
  325. package/src-shared/vendor/yaml/dist/schema/common/null.js +17 -0
  326. package/src-shared/vendor/yaml/dist/schema/common/seq.d.ts +2 -0
  327. package/src-shared/vendor/yaml/dist/schema/common/seq.js +19 -0
  328. package/src-shared/vendor/yaml/dist/schema/common/string.d.ts +2 -0
  329. package/src-shared/vendor/yaml/dist/schema/common/string.js +16 -0
  330. package/src-shared/vendor/yaml/dist/schema/core/bool.d.ts +4 -0
  331. package/src-shared/vendor/yaml/dist/schema/core/bool.js +21 -0
  332. package/src-shared/vendor/yaml/dist/schema/core/float.d.ts +4 -0
  333. package/src-shared/vendor/yaml/dist/schema/core/float.js +47 -0
  334. package/src-shared/vendor/yaml/dist/schema/core/int.d.ts +4 -0
  335. package/src-shared/vendor/yaml/dist/schema/core/int.js +42 -0
  336. package/src-shared/vendor/yaml/dist/schema/core/schema.d.ts +1 -0
  337. package/src-shared/vendor/yaml/dist/schema/core/schema.js +25 -0
  338. package/src-shared/vendor/yaml/dist/schema/json/schema.d.ts +2 -0
  339. package/src-shared/vendor/yaml/dist/schema/json/schema.js +64 -0
  340. package/src-shared/vendor/yaml/dist/schema/json-schema.d.ts +69 -0
  341. package/src-shared/vendor/yaml/dist/schema/tags.d.ts +40 -0
  342. package/src-shared/vendor/yaml/dist/schema/tags.js +86 -0
  343. package/src-shared/vendor/yaml/dist/schema/types.d.ts +90 -0
  344. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  345. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/binary.js +68 -0
  346. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  347. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  348. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  349. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/float.js +50 -0
  350. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  351. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/int.js +76 -0
  352. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/omap.d.ts +28 -0
  353. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  354. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  355. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  356. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  357. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/schema.js +39 -0
  358. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  359. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/set.js +96 -0
  360. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  361. package/src-shared/vendor/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  362. package/src-shared/vendor/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  363. package/src-shared/vendor/yaml/dist/stringify/foldFlowLines.js +151 -0
  364. package/src-shared/vendor/yaml/dist/stringify/stringify.d.ts +21 -0
  365. package/src-shared/vendor/yaml/dist/stringify/stringify.js +127 -0
  366. package/src-shared/vendor/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  367. package/src-shared/vendor/yaml/dist/stringify/stringifyCollection.js +145 -0
  368. package/src-shared/vendor/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  369. package/src-shared/vendor/yaml/dist/stringify/stringifyComment.js +24 -0
  370. package/src-shared/vendor/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  371. package/src-shared/vendor/yaml/dist/stringify/stringifyDocument.js +87 -0
  372. package/src-shared/vendor/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  373. package/src-shared/vendor/yaml/dist/stringify/stringifyNumber.js +26 -0
  374. package/src-shared/vendor/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  375. package/src-shared/vendor/yaml/dist/stringify/stringifyPair.js +152 -0
  376. package/src-shared/vendor/yaml/dist/stringify/stringifyString.d.ts +9 -0
  377. package/src-shared/vendor/yaml/dist/stringify/stringifyString.js +330 -0
  378. package/src-shared/vendor/yaml/dist/test-events.d.ts +4 -0
  379. package/src-shared/vendor/yaml/dist/test-events.js +134 -0
  380. package/src-shared/vendor/yaml/dist/util.d.ts +12 -0
  381. package/src-shared/vendor/yaml/dist/util.js +28 -0
  382. package/src-shared/vendor/yaml/dist/visit.d.ts +102 -0
  383. package/src-shared/vendor/yaml/dist/visit.js +236 -0
  384. package/src-shared/vendor/yaml/package.json +96 -0
  385. package/src-shared/vendor/yaml/util.js +2 -0
@@ -0,0 +1,167 @@
1
+ // 结构化 JSON 行日志。契约见 agentlink-cli/docs/LOGGING.md。
2
+ //
3
+ // 使用:
4
+ // import { createLogger } from "../src-shared/logger.mjs";
5
+ // const log = createLogger({ comp: "bridge", rt: "claude" });
6
+ // log.info("bridge.start", "bridge starting", { pid: process.pid });
7
+ // const child = log.child({ session: "agent:u1:::claude-1" });
8
+ //
9
+ // 硬要求:
10
+ // - 任何未 catch 的异常不能阻断日志输出;logger 本身不能 throw。
11
+ // - 敏感字段(token/credential/cookie/secret/password/authorization)
12
+ // 在 `meta` 里遇到则替换为 "<redacted>"。
13
+ // - `text` / `prompt` / `content` 字段长度超 500 → 截断并标记 truncated。
14
+
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+ import os from "node:os";
18
+ import process from "node:process";
19
+
20
+ const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };
21
+
22
+ const SENSITIVE_KEY_RE = /token|credential|cookie|secret|password|authorization|api[_-]?key/i;
23
+ const TRUNCATE_KEYS = new Set(["text", "prompt", "content", "body", "message"]);
24
+ const TRUNCATE_LIMIT = 500;
25
+
26
+ function resolveLevel(raw) {
27
+ const v = String(raw || "").trim().toLowerCase();
28
+ return Object.prototype.hasOwnProperty.call(LEVELS, v) ? v : "info";
29
+ }
30
+
31
+ function resolveLogDir() {
32
+ const override = process.env.AGENTLINK_AGENT_LOG_DIR;
33
+ if (override && override.trim()) return override.trim();
34
+ return path.join(os.homedir(), ".agentlink", "logs");
35
+ }
36
+
37
+ function sanitize(value, keyName) {
38
+ if (value == null) return value;
39
+ if (typeof value === "string") {
40
+ if (keyName && TRUNCATE_KEYS.has(keyName) && value.length > TRUNCATE_LIMIT) {
41
+ return value.slice(0, TRUNCATE_LIMIT);
42
+ }
43
+ return value;
44
+ }
45
+ if (typeof value !== "object") return value;
46
+ if (Array.isArray(value)) return value.map((v) => sanitize(v));
47
+ const out = {};
48
+ for (const [k, v] of Object.entries(value)) {
49
+ if (SENSITIVE_KEY_RE.test(k)) {
50
+ out[k] = "<redacted>";
51
+ continue;
52
+ }
53
+ out[k] = sanitize(v, k);
54
+ if (k && TRUNCATE_KEYS.has(k) && typeof v === "string" && v.length > TRUNCATE_LIMIT) {
55
+ out.text_truncated = true;
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+
61
+ function ensureDir(dir) {
62
+ try {
63
+ fs.mkdirSync(dir, { recursive: true });
64
+ return true;
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ // 日志落盘 —— 用 appendFileSync 而非 createWriteStream,
71
+ // 因为 process.exit() 不会等 stream flush,进程马上死的场景下日志会丢。
72
+ // 日志量低(info 为主),同步 IO 代价可接受。跨平台表现一致。
73
+ //
74
+ // 首次写入时确保目录存在;目录打不开则降级为不落盘(只 stderr)。
75
+
76
+ // 单文件:`agent-YYYYMMDD.log`。runtime 不进文件名,已在每行的 `rt` 字段里。
77
+ // 按日期滚动,查某天的全部 runtime:`jq . agent-YYYYMMDD.log`
78
+ // 过滤某 runtime:`jq 'select(.rt == "claude")' agent-YYYYMMDD.log`
79
+
80
+ let resolvedLogPath = null;
81
+ let fileSinkDisabled = false;
82
+
83
+ function resolveFilePath() {
84
+ if (fileSinkDisabled) return null;
85
+ if (resolvedLogPath) return resolvedLogPath;
86
+ const dir = resolveLogDir();
87
+ if (!ensureDir(dir)) {
88
+ fileSinkDisabled = true;
89
+ return null;
90
+ }
91
+ const ymd = new Date().toISOString().slice(0, 10).replace(/-/g, "");
92
+ resolvedLogPath = path.join(dir, `agent-${ymd}.log`);
93
+ return resolvedLogPath;
94
+ }
95
+
96
+ function writeFile(line) {
97
+ const file = resolveFilePath();
98
+ if (!file) return;
99
+ try {
100
+ fs.appendFileSync(file, line);
101
+ } catch {
102
+ fileSinkDisabled = true;
103
+ }
104
+ }
105
+
106
+ export function createLogger(baseCtx = {}) {
107
+ const threshold = LEVELS[resolveLevel(process.env.AGENTLINK_AGENT_LOG_LEVEL)];
108
+
109
+ function emit(level, event, msg, extra) {
110
+ if (LEVELS[level] < threshold) return;
111
+ const row = {
112
+ ts: new Date().toISOString(),
113
+ level,
114
+ ...baseCtx,
115
+ event: event || "unknown",
116
+ msg: msg || "",
117
+ pid: process.pid,
118
+ ...sanitize(extra || {}),
119
+ };
120
+ let line;
121
+ try {
122
+ line = JSON.stringify(row) + "\n";
123
+ } catch (err) {
124
+ line = JSON.stringify({
125
+ ts: row.ts,
126
+ level: "error",
127
+ comp: baseCtx.comp || "shared",
128
+ event: "logger.serialize_error",
129
+ msg: String(err && err.message ? err.message : err),
130
+ pid: process.pid,
131
+ }) + "\n";
132
+ }
133
+ // 日志一律走 stderr —— stdout 是业务产出通道(help/version/JSON 响应)。
134
+ try {
135
+ process.stderr.write(line);
136
+ } catch {}
137
+ writeFile(line);
138
+ }
139
+
140
+ const self = {
141
+ debug: (event, msg, extra) => emit("debug", event, msg, extra),
142
+ info: (event, msg, extra) => emit("info", event, msg, extra),
143
+ warn: (event, msg, extra) => emit("warn", event, msg, extra),
144
+ error: (event, msg, extra) => emit("error", event, msg, extra),
145
+ child(patch) {
146
+ return createLogger({ ...baseCtx, ...patch });
147
+ },
148
+ context() {
149
+ return { ...baseCtx };
150
+ },
151
+ };
152
+ return self;
153
+ }
154
+
155
+ // 便利方法:logger.safe(() => ...) 包裹任意同步块,异常不冒泡只落日志。
156
+ export function safeRun(logger, where, fn) {
157
+ try {
158
+ return fn();
159
+ } catch (err) {
160
+ logger.error("error.caught", "uncaught exception", {
161
+ where,
162
+ err: err && err.message ? err.message : String(err),
163
+ stack: err && err.stack ? String(err.stack).split("\n").slice(0, 8).join("\n") : undefined,
164
+ });
165
+ return undefined;
166
+ }
167
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "defaultRelayUrl": "https://go-relay.xyagent.com"
3
+ }
@@ -0,0 +1,46 @@
1
+ // relay_revoke —— bridge long-poll「服务端已解绑」自清的纯判定逻辑。
2
+ //
3
+ // 抽成共享纯函数,供 bin/agentlink 的 openclaw/hermes bridge 与单测复用:
4
+ // - 防止有人把 readRelayNextGatewayRequest 的 404 分支「简化」回 fail()
5
+ // (那样本机配对凭证不会被清,服务管理器重拉后陷入 404 崩溃循环,下次 pair
6
+ // 报「本地状态残留」——正是这个模块要守护的回归)。
7
+ // - 删除凭证用 **delete** 语义而非轮换:必须让 relayGatewayId 缺失,否则
8
+ // pair-all 的 readLocalPairState 仍读到残留 gatewayId、探测未绑定、又报残留。
9
+
10
+ /**
11
+ * long-poll 取请求时,哪些 HTTP 状态码代表「该 gateway 已被服务端解绑」、
12
+ * bridge 应当自清本机配对状态:
13
+ * 401 = bridge token 失效 / 无权
14
+ * 404 = gateway session 不存在(典型:App 端移除智能体软删 pair_session)
15
+ * 410 = 资源已 gone
16
+ * 其余(含 5xx)一律不自清,按瞬态 / 其它错误处理。
17
+ *
18
+ * @param {number} status
19
+ * @returns {boolean}
20
+ */
21
+ export function isRevokedPollStatus(status) {
22
+ return status === 401 || status === 404 || status === 410;
23
+ }
24
+
25
+ /**
26
+ * 从 agentlink state 对象就地删除指定 runtime 的 relay 配对凭证(delete 语义)。
27
+ * openclaw / hermes 用不同 key 前缀,二者凭证独立。
28
+ * 非对象入参原样返回(防御)。
29
+ *
30
+ * @param {Record<string, unknown>} state
31
+ * @param {string} runtime 归一化后的 runtime('hermes' 走 hermes 前缀,其余按 openclaw)
32
+ * @returns {Record<string, unknown>} 同一个 state(已就地删除)
33
+ */
34
+ export function deleteRelayPairCredentials(state, runtime) {
35
+ if (!state || typeof state !== "object") return state;
36
+ if (runtime === "hermes") {
37
+ delete state.hermesRelayGatewayId;
38
+ delete state.hermesRelayClientToken;
39
+ delete state.hermesRelayGatewayToken;
40
+ } else {
41
+ delete state.relayGatewayId;
42
+ delete state.relayClientToken;
43
+ delete state.relayGatewayToken;
44
+ }
45
+ return state;
46
+ }
@@ -0,0 +1,60 @@
1
+ # Vendored libraries
2
+
3
+ `npm_cli` deliberately maintains a **zero-dependency** posture (`package.json`'s
4
+ `dependencies: {}`). To preserve this while needing document-preserving YAML and
5
+ TOML round-trip editing for the MCP runtime fanout adapters (Codex
6
+ `~/.codex/config.toml`, Hermes `~/.hermes/config.yaml`), the relevant libraries
7
+ are vendored under this directory.
8
+
9
+ ## Vendored packages
10
+
11
+ | Package | Version | License | Purpose |
12
+ |------------|---------|----------------|-------------------------------------------------|
13
+ | `yaml` | 2.5.1 | ISC | Document-preserving YAML edits (Hermes adapter) |
14
+ | `smol-toml`| 1.4.1 | BSD-3-Clause | TOML round-trip edits (Codex adapter) |
15
+
16
+ Each package directory contains its original `LICENSE`, `package.json`, and
17
+ distribution artifacts (`dist/` etc.), plus a sibling `VENDORED.md` recording
18
+ provenance.
19
+
20
+ ## Importing
21
+
22
+ Use relative paths from the import site, NOT a bare specifier — bare specifiers
23
+ won't resolve since the packages are not in `node_modules`. Examples:
24
+
25
+ ```js
26
+ // from src-ext/runtime/hermes/mcpConfigAdapter.mjs
27
+ import YAML from "../../../src-shared/vendor/yaml/dist/index.js";
28
+
29
+ // from src-ext/runtime/codex/mcpConfigAdapter.mjs
30
+ import { parse, stringify } from "../../../src-shared/vendor/smol-toml/dist/index.js";
31
+ ```
32
+
33
+ The actual entry points come from each package's own `package.json` `main` /
34
+ `exports`; check `yaml/package.json` and `smol-toml/package.json` for the
35
+ authoritative entry. The smoke test at `test/vendor/import.test.mjs` validates
36
+ that both packages import + round-trip a sample doc.
37
+
38
+ ## Refreshing
39
+
40
+ Run the refresh script when a security advisory or upstream patch warrants a
41
+ bump:
42
+
43
+ ```bash
44
+ node scripts/refresh-vendored-libs.mjs --check # verify pinned sha256s
45
+ node scripts/refresh-vendored-libs.mjs --apply # re-download + overwrite
46
+ ```
47
+
48
+ The script pins exact versions and verifies tarball sha256 — it will refuse to
49
+ apply if the upstream hash doesn't match the recorded value. To intentionally
50
+ bump a version, edit the pinned versions in the script *and* update the
51
+ expected sha256s, then run `--apply`.
52
+
53
+ ## Security review notes
54
+
55
+ - Vendoring trades transitive npm supply-chain risk for **manual** review burden.
56
+ Upgrades are explicit, gated, and visible in PR diffs.
57
+ - These two packages have minimal sub-dependencies (smol-toml has zero; yaml has
58
+ zero runtime deps too). Each tarball was inspected for unexpected file
59
+ contents (no postinstall scripts, no native code).
60
+ - Both are MIT-compatible licenses; see each `LICENSE` file.
@@ -0,0 +1,24 @@
1
+ Copyright (c) Squirrel Chat et al., All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. Neither the name of the copyright holder nor the names of its contributors
12
+ may be used to endorse or promote products derived from this software without
13
+ specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,236 @@
1
+ # smol-toml
2
+ [![TOML 1.0.0](https://img.shields.io/badge/TOML-1.0.0-9c4221?style=flat-square)](https://toml.io/en/v1.0.0)
3
+ [![License](https://img.shields.io/github/license/squirrelchat/smol-toml.svg?style=flat-square)](https://github.com/squirrelchat/smol-toml/blob/mistress/LICENSE)
4
+ [![npm](https://img.shields.io/npm/v/smol-toml?style=flat-square)](https://npm.im/smol-toml)
5
+ [![Build](https://img.shields.io/github/actions/workflow/status/squirrelchat/smol-toml/build.yml?style=flat-square&logo=github)](https://github.com/squirrelchat/smol-toml/actions/workflows/build.yml)
6
+
7
+ [![GitHub Sponsors](https://img.shields.io/badge/GitHub%20Sponsors-support%20me-EA4AAA?style=flat-square)](https://github.com/sponsors/cyyynthia)
8
+ [![Weekly downloads](https://img.shields.io/npm/dw/smol-toml?style=flat-square)](https://npm.im/smol-toml)
9
+ [![Monthly downloads](https://img.shields.io/npm/dm/smol-toml?style=flat-square)](https://npm.im/smol-toml)
10
+
11
+ A small, fast, and correct TOML parser and serializer. smol-toml is fully(ish) spec-compliant with TOML v1.0.0.
12
+
13
+ Why yet another TOML parser? Well, the ecosystem of TOML parsers in JavaScript is quite underwhelming, most likely due
14
+ to a lack of interest. With most parsers being outdated, unmaintained, non-compliant, or a combination of these, a new
15
+ parser didn't feel too out of place.
16
+
17
+ *[insert xkcd 927]*
18
+
19
+ Nowadays, smol-toml is the most downloaded TOML parser on npm thanks to its quality. From frameworks to tooling, it
20
+ has been battle-tested and is actively used in production systems.
21
+
22
+ smol-toml passes most of the tests from the [`toml-test` suite](https://github.com/toml-lang/toml-test); use the
23
+ `run-toml-test.bash` script to run the tests. Due to the nature of JavaScript and the limits of the language,
24
+ it doesn't pass certain tests, namely:
25
+ - Invalid UTF-8 strings are not rejected
26
+ - Certain invalid UTF-8 codepoints are not rejected
27
+ - Certain invalid dates are not rejected
28
+ - For instance, `2023-02-30` would be accepted and parsed as `2023-03-02`. While additional checks could be performed
29
+ to reject these, they've not been added for performance reasons.
30
+
31
+ Please also note that by default, the behavior regarding integers doesn't preserve type information, nor does it allow
32
+ deserializing integers larger than 53 bits. See [Integers](#integers).
33
+
34
+ You can see a list of all tests smol-toml fails (and the reason why it fails these) in the list of skipped tests in
35
+ `run-toml-test.bash`. Note that some failures are *not* specification violations per-se. For instance, the TOML spec
36
+ does not require 64-bit integer range support or sub-millisecond time precision, but are included in the `toml-test`
37
+ suite. See https://github.com/toml-lang/toml-test/issues/154 and https://github.com/toml-lang/toml-test/issues/155
38
+
39
+ ## Installation
40
+ ```
41
+ [pnpm | yarn | npm] i smol-toml
42
+ ```
43
+
44
+ ## Usage
45
+ ```js
46
+ import { parse, stringify } from 'smol-toml'
47
+
48
+ const doc = '...'
49
+ const parsed = parse(doc)
50
+ console.log(parsed)
51
+
52
+ const toml = stringify(parsed)
53
+ console.log(toml)
54
+ ```
55
+
56
+ Alternatively, if you prefer something similar to the JSON global, you can import the library as follows
57
+ ```js
58
+ import TOML from 'smol-toml'
59
+
60
+ TOML.stringify({ ... })
61
+ ```
62
+
63
+ A few notes on the `stringify` function:
64
+ - `undefined` and `null` values on objects are ignored (does not produce a key/value).
65
+ - `undefined` and `null` values in arrays are **rejected**.
66
+ - Functions, classes and symbols are **rejected**.
67
+ - By default, floats will be serialized as integers if they don't have a decimal part. See [Integers](#integers)
68
+ - `stringify(parse('a = 1.0')) === 'a = 1'`
69
+ - JS `Date` will be serialized as Offset Date Time
70
+ - Use the [`TomlDate` object](#dates) for representing other types.
71
+
72
+ ### Integers
73
+ When parsing, both integers and floats are read as plain JavaScript numbers, which essentially are floats. This means
74
+ loss of type information, and makes it impossible to safely represent integers beyond 53 bits.
75
+
76
+ When serializing, numbers without a decimal part are serialized as integers. This allows in most cases to preserve
77
+ whether a number is an integer or not, but fails to preserve type information for numbers like `1.0`.
78
+
79
+ #### Enabling BigInt support and type preservation
80
+ To parse integers beyond 53 bits, it's possible to tell the parser to return all integers as BigInt. This will
81
+ therefore preserve the type information at the cost of using a slightly more expensive container.
82
+
83
+ ```js
84
+ import { parse } from 'smol-toml'
85
+
86
+ const doc = '...'
87
+ const parsed = parse(doc, { integersAsBigInt: true })
88
+ ```
89
+
90
+ If you want to keep numbers for integers that can safely be represented as a JavaScript number, you can pass
91
+ `"asNeeded"` instead.
92
+
93
+ To get end-to-end type preservation, you can tell the serializer to always treat numbers as floating point numbers.
94
+ Then, only BigInts will be serialized as integers and numbers without a decimal part will still be serialized as float.
95
+
96
+ ```js
97
+ import { stringify } from 'smol-toml'
98
+
99
+ const obj = { ... }
100
+ const toml = stringify(obj, { numbersAsFloat: true })
101
+ ```
102
+
103
+ ### Dates
104
+ `smol-toml` uses an extended `Date` object to represent all types of TOML Dates. In the future, `smol-toml` will use
105
+ objects from the Temporal proposal, but for now we're stuck with the legacy Date object.
106
+
107
+ ```js
108
+ import { TomlDate } from 'smol-toml'
109
+
110
+ // Offset Date Time
111
+ const date = new TomlDate('1979-05-27T07:32:00.000-08:00')
112
+ console.log(date.isDateTime(), date.isDate(), date.isTime(), date.isLocal()) // ~> true, false, false, false
113
+ console.log(date.toISOString()) // ~> 1979-05-27T07:32:00.000-08:00
114
+
115
+ // Local Date Time
116
+ const date = new TomlDate('1979-05-27T07:32:00.000')
117
+ console.log(date.isDateTime(), date.isDate(), date.isTime(), date.isLocal()) // ~> true, false, false, true
118
+ console.log(date.toISOString()) // ~> 1979-05-27T07:32:00.000
119
+
120
+ // Local Date
121
+ const date = new TomlDate('1979-05-27')
122
+ console.log(date.isDateTime(), date.isDate(), date.isTime(), date.isLocal()) // ~> false, true, false, true
123
+ console.log(date.toISOString()) // ~> 1979-05-27
124
+
125
+ // Local Time
126
+ const date = new TomlDate('07:32:00')
127
+ console.log(date.isDateTime(), date.isDate(), date.isTime(), date.isLocal()) // ~> false, false, true, true
128
+ console.log(date.toISOString()) // ~> 07:32:00.000
129
+ ```
130
+
131
+ You can also wrap a native `Date` object and specify using different methods depending on the type of date you wish
132
+ to represent:
133
+
134
+ ```js
135
+ import { TomlDate } from 'smol-toml'
136
+
137
+ const jsDate = new Date()
138
+
139
+ const offsetDateTime = TomlDate.wrapAsOffsetDateTime(jsDate)
140
+ const localDateTime = TomlDate.wrapAsLocalDateTime(jsDate)
141
+ const localDate = TomlDate.wrapAsLocalDate(jsDate)
142
+ const localTime = TomlDate.wrapAsLocalTime(jsDate)
143
+ ```
144
+
145
+ ## Performance
146
+ > [!NOTE]
147
+ > These benchmarks are starting to get a bit old. They will be updated in the (hopefully near) future to better
148
+ > reflect numbers of the latest version of smol-toml on the latest version of Node.js.
149
+
150
+ A note on these performance numbers: in some highly synthetic tests, other parsers such as `fast-toml` greatly
151
+ outperform other parsers, mostly due to their lack of compliance with the spec. For example, to parse a string,
152
+ `fast-toml` skips the entire string while `smol-toml` does validate the string, costing a fair share of performance.
153
+
154
+ The ~5MB test file used for benchmark here is filled with random data which attempts to be close-ish to reality in
155
+ terms of structure. The idea is to have a file relatively close to a real-world application, with moderately sized
156
+ strings etc.
157
+
158
+ The large TOML generator can be found [here](https://gist.github.com/cyyynthia/e77c744cb6494dabe37d0182506526b9)
159
+
160
+ | **Parse** | smol-toml | @iarna/toml@3.0.0 | @ltd/j-toml | fast-toml |
161
+ |----------------|---------------------|-------------------|-----------------|-----------------|
162
+ | Spec example | **71,356.51 op/s** | 33,629.31 op/s | 16,433.86 op/s | 29,421.60 op/s |
163
+ | ~5MB test file | **3.8091 op/s** | *DNF* | 2.4369 op/s | 2.6078 op/s |
164
+
165
+ | **Stringify** | smol-toml | @iarna/toml@3.0.0 | @ltd/j-toml |
166
+ |----------------|----------------------|-------------------|----------------|
167
+ | Spec example | **195,191.99 op/s** | 46,583.07 op/s | 5,670.12 op/s |
168
+ | ~5MB test file | **14.6709 op/s** | 3.5941 op/s | 0.7856 op/s |
169
+
170
+ <details>
171
+ <summary>Detailed benchmark data</summary>
172
+
173
+ Tests ran using Vitest v0.31.0 on commit f58cb6152e667e9cea09f31c93d90652e3b82bf5
174
+
175
+ CPU: Intel Core i7 7700K (4.2GHz)
176
+
177
+ ```
178
+ RUN v0.31.0
179
+
180
+ ✓ bench/parseSpecExample.bench.ts (4) 2462ms
181
+ name hz min max mean p75 p99 p995 p999 rme samples
182
+ · smol-toml 71,356.51 0.0132 0.2633 0.0140 0.0137 0.0219 0.0266 0.1135 ±0.37% 35679 fastest
183
+ · @iarna/toml 33,629.31 0.0272 0.2629 0.0297 0.0287 0.0571 0.0650 0.1593 ±0.45% 16815
184
+ · @ltd/j-toml 16,433.86 0.0523 1.3088 0.0608 0.0550 0.1140 0.1525 0.7348 ±1.47% 8217 slowest
185
+ · fast-toml 29,421.60 0.0305 0.2995 0.0340 0.0312 0.0618 0.0640 0.1553 ±0.47% 14711
186
+ ✓ bench/parseLargeMixed.bench.ts (3) 16062ms
187
+ name hz min max mean p75 p99 p995 p999 rme samples
188
+ · smol-toml 3.8091 239.60 287.30 262.53 274.17 287.30 287.30 287.30 ±3.66% 10 fastest
189
+ · @ltd/j-toml 2.4369 376.73 493.49 410.35 442.58 493.49 493.49 493.49 ±7.08% 10 slowest
190
+ · fast-toml 2.6078 373.88 412.79 383.47 388.62 412.79 412.79 412.79 ±2.72% 10
191
+ ✓ bench/stringifySpecExample.bench.ts (3) 1886ms
192
+ name hz min max mean p75 p99 p995 p999 rme samples
193
+ · smol-toml 195,191.99 0.0047 0.2704 0.0051 0.0050 0.0099 0.0110 0.0152 ±0.41% 97596 fastest
194
+ · @iarna/toml 46,583.07 0.0197 0.2808 0.0215 0.0208 0.0448 0.0470 0.1704 ±0.47% 23292
195
+ · @ltd/j-toml 5,670.12 0.1613 0.5768 0.1764 0.1726 0.3036 0.3129 0.4324 ±0.56% 2836 slowest
196
+ ✓ bench/stringifyLargeMixed.bench.ts (3) 24057ms
197
+ name hz min max mean p75 p99 p995 p999 rme samples
198
+ · smol-toml 14.6709 65.1071 79.2199 68.1623 67.1088 79.2199 79.2199 79.2199 ±5.25% 10 fastest
199
+ · @iarna/toml 3.5941 266.48 295.24 278.24 290.10 295.24 295.24 295.24 ±2.83% 10
200
+ · @ltd/j-toml 0.7856 1,254.33 1,322.05 1,272.87 1,286.82 1,322.05 1,322.05 1,322.05 ±1.37% 10 slowest
201
+
202
+
203
+ BENCH Summary
204
+
205
+ smol-toml - bench/parseLargeMixed.bench.ts >
206
+ 1.46x faster than fast-toml
207
+ 1.56x faster than @ltd/j-toml
208
+
209
+ smol-toml - bench/parseSpecExample.bench.ts >
210
+ 2.12x faster than @iarna/toml
211
+ 2.43x faster than fast-toml
212
+ 4.34x faster than @ltd/j-toml
213
+
214
+ smol-toml - bench/stringifyLargeMixed.bench.ts >
215
+ 4.00x faster than @iarna/toml
216
+ 18.33x faster than @ltd/j-toml
217
+
218
+ smol-toml - bench/stringifySpecExample.bench.ts >
219
+ 4.19x faster than @iarna/toml
220
+ 34.42x faster than @ltd/j-toml
221
+ ```
222
+
223
+ ---
224
+ Additional notes:
225
+
226
+ I initially tried to benchmark `toml-nodejs`, but the 0.3.0 package is broken.
227
+ I initially reported this to the library author, but the author decided to
228
+ - a) advise to use a custom loader (via *experimental* flag) to circumvent the invalid imports.
229
+ - Said flag, `--experimental-specifier-resolution`, has been removed in Node v20.
230
+ - b) [delete the issue](https://github.com/huan231/toml-nodejs/issues/12) when pointed out links to the Node.js
231
+ documentation about the flag removal and standard resolution algorithm.
232
+
233
+ For the reference anyway, `toml-nodejs` (with proper imports) is ~8x slower on both parse benchmark with:
234
+ - spec example: 7,543.47 op/s
235
+ - 5mb mixed: 0.7006 op/s
236
+ </details>
@@ -0,0 +1,37 @@
1
+ # Vendored: smol-toml@1.4.1
2
+
3
+ | Field | Value |
4
+ |------------------|----------------------------------------------------------------------|
5
+ | Source | https://registry.npmjs.org/smol-toml/-/smol-toml-1.4.1.tgz |
6
+ | Version | 1.4.1 |
7
+ | License | BSD-3-Clause (see `LICENSE`) |
8
+ | Upstream | https://github.com/squirrelchat/smol-toml |
9
+ | Tarball sha256 | 0e66934cd88d0ba679014f5736b91c87fd816e73a965b1870f8b48d3b4bfe77b |
10
+ | Vendored on | 2026-05-21 |
11
+ | Vendor command | `npm pack smol-toml@1.4.1 && tar xzf smol-toml-1.4.1.tgz` |
12
+ | Purpose | TOML round-trip editing for Codex config.toml adapter |
13
+
14
+ ## Trade-off on comment preservation
15
+
16
+ `smol-toml` is a minimal TOML 1.0 parser/serializer. It does NOT preserve user
17
+ comments through parse → modify → stringify. The alternatives `@iarna/toml` and
18
+ `@ltd/j-toml` have heavier comment-preservation but introduce more code.
19
+
20
+ **Decision**: Codex config.toml round-trip via smol-toml; user comments inside
21
+ `[mcp_servers.agentlink]` (if any) are lost on rewrite, BUT comments OUTSIDE
22
+ that section (the rest of the user's Codex config) survive because we only
23
+ write our own section. The Codex adapter SHALL be careful to merge, not full
24
+ rewrite.
25
+
26
+ If user feedback indicates lost comments are a problem, swap to
27
+ `@iarna/toml` later — adapter API is module-internal, callers won't notice.
28
+
29
+ ## What's used
30
+
31
+ The Codex MCP config adapter uses:
32
+ - `parse(text)` — returns `Record<string, any>`
33
+ - `stringify(obj)` — emits canonical TOML
34
+
35
+ ## Why pinned
36
+
37
+ See yaml/VENDORED.md for general policy.
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ export declare class TomlDate extends Date {
29
+ #private;
30
+ constructor(date: string | Date);
31
+ isDateTime(): boolean;
32
+ isLocal(): boolean;
33
+ isDate(): boolean;
34
+ isTime(): boolean;
35
+ isValid(): boolean;
36
+ toISOString(): string;
37
+ static wrapAsOffsetDateTime(jsDate: Date, offset?: string): TomlDate;
38
+ static wrapAsLocalDateTime(jsDate: Date): TomlDate;
39
+ static wrapAsLocalDate(jsDate: Date): TomlDate;
40
+ static wrapAsLocalTime(jsDate: Date): TomlDate;
41
+ }