@botbotgo/kit 1.0.104

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 (269) hide show
  1. package/README.md +65 -0
  2. package/config/build/build.sh +182 -0
  3. package/config/build/tsconfig.dts.json +34 -0
  4. package/config/build/tsup.config.ts +19 -0
  5. package/config/build/vitest.config.ts +29 -0
  6. package/config/tool.yaml +11 -0
  7. package/dist/agent-context.d.ts +3 -0
  8. package/dist/agent-context.d.ts.map +1 -0
  9. package/dist/api/adapters/LangChainToolsHub.d.ts +35 -0
  10. package/dist/api/adapters/LangChainToolsHub.d.ts.map +1 -0
  11. package/dist/api/createAgentTools.d.ts +52 -0
  12. package/dist/api/createAgentTools.d.ts.map +1 -0
  13. package/dist/api/expose/extension-init/index.d.ts +3 -0
  14. package/dist/api/expose/extension-init/index.d.ts.map +1 -0
  15. package/dist/api/expose/extension-init/initExtension.d.ts +21 -0
  16. package/dist/api/expose/extension-init/initExtension.d.ts.map +1 -0
  17. package/dist/api/expose/index.d.ts +16 -0
  18. package/dist/api/expose/index.d.ts.map +1 -0
  19. package/dist/api/expose/mcp-build/build.d.ts +21 -0
  20. package/dist/api/expose/mcp-build/build.d.ts.map +1 -0
  21. package/dist/api/expose/mcp-build/generator.d.ts +15 -0
  22. package/dist/api/expose/mcp-build/generator.d.ts.map +1 -0
  23. package/dist/api/expose/mcp-build/index.d.ts +8 -0
  24. package/dist/api/expose/mcp-build/index.d.ts.map +1 -0
  25. package/dist/api/expose/mcp-build/init.d.ts +17 -0
  26. package/dist/api/expose/mcp-build/init.d.ts.map +1 -0
  27. package/dist/api/expose/mcp-build/run.d.ts +17 -0
  28. package/dist/api/expose/mcp-build/run.d.ts.map +1 -0
  29. package/dist/api/expose/mcp-build/types.d.ts +25 -0
  30. package/dist/api/expose/mcp-build/types.d.ts.map +1 -0
  31. package/dist/api/expose/mcpServer.d.ts +74 -0
  32. package/dist/api/expose/mcpServer.d.ts.map +1 -0
  33. package/dist/api/expose/openapi.d.ts +23 -0
  34. package/dist/api/expose/openapi.d.ts.map +1 -0
  35. package/dist/api/expose/openapiHttp.d.ts +51 -0
  36. package/dist/api/expose/openapiHttp.d.ts.map +1 -0
  37. package/dist/api/extension/contextRunner.d.ts +10 -0
  38. package/dist/api/extension/contextRunner.d.ts.map +1 -0
  39. package/dist/api/extension/createExtension.d.ts +38 -0
  40. package/dist/api/extension/createExtension.d.ts.map +1 -0
  41. package/dist/api/extension/dynamicImportAdapter.d.ts +25 -0
  42. package/dist/api/extension/dynamicImportAdapter.d.ts.map +1 -0
  43. package/dist/api/extension/generateExtensionManifest.d.ts +29 -0
  44. package/dist/api/extension/generateExtensionManifest.d.ts.map +1 -0
  45. package/dist/api/extension/index.d.ts +23 -0
  46. package/dist/api/extension/index.d.ts.map +1 -0
  47. package/dist/api/extension/loadToolYaml.d.ts +7 -0
  48. package/dist/api/extension/loadToolYaml.d.ts.map +1 -0
  49. package/dist/api/extension/overrideWithConfig.d.ts +2 -0
  50. package/dist/api/extension/overrideWithConfig.d.ts.map +1 -0
  51. package/dist/api/extension/registerExtension.d.ts +32 -0
  52. package/dist/api/extension/registerExtension.d.ts.map +1 -0
  53. package/dist/api/extension/registerFromManifest.d.ts +43 -0
  54. package/dist/api/extension/registerFromManifest.d.ts.map +1 -0
  55. package/dist/api/extension/resolvePackageRoot.d.ts +2 -0
  56. package/dist/api/extension/resolvePackageRoot.d.ts.map +1 -0
  57. package/dist/api/extension/support/groupPrefix.d.ts +21 -0
  58. package/dist/api/extension/support/groupPrefix.d.ts.map +1 -0
  59. package/dist/api/extension/support/types.d.ts +15 -0
  60. package/dist/api/extension/support/types.d.ts.map +1 -0
  61. package/dist/api/register-tools.d.ts +17 -0
  62. package/dist/api/register-tools.d.ts.map +1 -0
  63. package/dist/api/resolveAgentSkillRoots.d.ts +7 -0
  64. package/dist/api/resolveAgentSkillRoots.d.ts.map +1 -0
  65. package/dist/api/runtimeFromConfig.d.ts +20 -0
  66. package/dist/api/runtimeFromConfig.d.ts.map +1 -0
  67. package/dist/api/runtimeFromConfig.helpers.d.ts +12 -0
  68. package/dist/api/runtimeFromConfig.helpers.d.ts.map +1 -0
  69. package/dist/api/runtimeFromConfig.types.d.ts +37 -0
  70. package/dist/api/runtimeFromConfig.types.d.ts.map +1 -0
  71. package/dist/build.cjs +30 -0
  72. package/dist/build.cjs.map +1 -0
  73. package/dist/build.d.ts +13 -0
  74. package/dist/build.d.ts.map +1 -0
  75. package/dist/build.js +5 -0
  76. package/dist/build.js.map +1 -0
  77. package/dist/canonicalCoreSchemas-PHGTNPN5.js +3 -0
  78. package/dist/canonicalCoreSchemas-PHGTNPN5.js.map +1 -0
  79. package/dist/canonicalCoreSchemas-TY7NCWCC.cjs +16 -0
  80. package/dist/canonicalCoreSchemas-TY7NCWCC.cjs.map +1 -0
  81. package/dist/chunk-4OOTCNR7.js +324 -0
  82. package/dist/chunk-4OOTCNR7.js.map +1 -0
  83. package/dist/chunk-AGLGFQUW.cjs +259 -0
  84. package/dist/chunk-AGLGFQUW.cjs.map +1 -0
  85. package/dist/chunk-AZUXVVGV.cjs +1073 -0
  86. package/dist/chunk-AZUXVVGV.cjs.map +1 -0
  87. package/dist/chunk-BDUSB6GT.js +520 -0
  88. package/dist/chunk-BDUSB6GT.js.map +1 -0
  89. package/dist/chunk-BNIE2IKZ.cjs +100 -0
  90. package/dist/chunk-BNIE2IKZ.cjs.map +1 -0
  91. package/dist/chunk-BTHDNP3C.cjs +350 -0
  92. package/dist/chunk-BTHDNP3C.cjs.map +1 -0
  93. package/dist/chunk-GGFAGLDC.js +1049 -0
  94. package/dist/chunk-GGFAGLDC.js.map +1 -0
  95. package/dist/chunk-ITX6A2BT.js +92 -0
  96. package/dist/chunk-ITX6A2BT.js.map +1 -0
  97. package/dist/chunk-IVL4TBFB.js +248 -0
  98. package/dist/chunk-IVL4TBFB.js.map +1 -0
  99. package/dist/chunk-JW4EMVTE.cjs +553 -0
  100. package/dist/chunk-JW4EMVTE.cjs.map +1 -0
  101. package/dist/chunk-LNVK4GO7.cjs +3043 -0
  102. package/dist/chunk-LNVK4GO7.cjs.map +1 -0
  103. package/dist/chunk-NTWOVFEY.js +16 -0
  104. package/dist/chunk-NTWOVFEY.js.map +1 -0
  105. package/dist/chunk-P5XFA3MW.js +3013 -0
  106. package/dist/chunk-P5XFA3MW.js.map +1 -0
  107. package/dist/chunk-UUNG3GL3.cjs +19 -0
  108. package/dist/chunk-UUNG3GL3.cjs.map +1 -0
  109. package/dist/core/registry/ToolRegistry.d.ts +68 -0
  110. package/dist/core/registry/ToolRegistry.d.ts.map +1 -0
  111. package/dist/core/runtime/Budget.d.ts +63 -0
  112. package/dist/core/runtime/Budget.d.ts.map +1 -0
  113. package/dist/core/runtime/Evidence.d.ts +19 -0
  114. package/dist/core/runtime/Evidence.d.ts.map +1 -0
  115. package/dist/core/runtime/PTCRuntime.d.ts +124 -0
  116. package/dist/core/runtime/PTCRuntime.d.ts.map +1 -0
  117. package/dist/core/runtime/PTCRuntimeObservability.d.ts +26 -0
  118. package/dist/core/runtime/PTCRuntimeObservability.d.ts.map +1 -0
  119. package/dist/core/runtime/PTCRuntimePipeline.d.ts +69 -0
  120. package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -0
  121. package/dist/core/runtime/PolicyEngine.d.ts +67 -0
  122. package/dist/core/runtime/PolicyEngine.d.ts.map +1 -0
  123. package/dist/core/runtime/Retry.d.ts +33 -0
  124. package/dist/core/runtime/Retry.d.ts.map +1 -0
  125. package/dist/core/runtime/SchemaValidator.d.ts +42 -0
  126. package/dist/core/runtime/SchemaValidator.d.ts.map +1 -0
  127. package/dist/core/runtime/toolObservation.d.ts +7 -0
  128. package/dist/core/runtime/toolObservation.d.ts.map +1 -0
  129. package/dist/core/types/Events.d.ts +99 -0
  130. package/dist/core/types/Events.d.ts.map +1 -0
  131. package/dist/core/types/ToolIntent.d.ts +40 -0
  132. package/dist/core/types/ToolIntent.d.ts.map +1 -0
  133. package/dist/core/types/ToolResult.d.ts +44 -0
  134. package/dist/core/types/ToolResult.d.ts.map +1 -0
  135. package/dist/core/types/ToolSpec.d.ts +116 -0
  136. package/dist/core/types/ToolSpec.d.ts.map +1 -0
  137. package/dist/core/types/ToolTypeHandler.d.ts +88 -0
  138. package/dist/core/types/ToolTypeHandler.d.ts.map +1 -0
  139. package/dist/core/types/index.d.ts +7 -0
  140. package/dist/core/types/index.d.ts.map +1 -0
  141. package/dist/index.cjs +399 -0
  142. package/dist/index.cjs.map +1 -0
  143. package/dist/index.d.ts +8 -0
  144. package/dist/index.d.ts.map +1 -0
  145. package/dist/index.js +394 -0
  146. package/dist/index.js.map +1 -0
  147. package/dist/observability/EventLog.d.ts +60 -0
  148. package/dist/observability/EventLog.d.ts.map +1 -0
  149. package/dist/observability/Logger.d.ts +33 -0
  150. package/dist/observability/Logger.d.ts.map +1 -0
  151. package/dist/observability/Metrics.d.ts +70 -0
  152. package/dist/observability/Metrics.d.ts.map +1 -0
  153. package/dist/observability/Tracing.d.ts +69 -0
  154. package/dist/observability/Tracing.d.ts.map +1 -0
  155. package/dist/sdk.cjs +493 -0
  156. package/dist/sdk.cjs.map +1 -0
  157. package/dist/sdk.d.ts +17 -0
  158. package/dist/sdk.d.ts.map +1 -0
  159. package/dist/sdk.js +443 -0
  160. package/dist/sdk.js.map +1 -0
  161. package/dist/security/sandbox.d.ts +10 -0
  162. package/dist/security/sandbox.d.ts.map +1 -0
  163. package/dist/security/ssrf.d.ts +24 -0
  164. package/dist/security/ssrf.d.ts.map +1 -0
  165. package/dist/templates/mcp-server.js +48 -0
  166. package/dist/templates/n8n-invoker.js +11 -0
  167. package/dist/templates/skill-invoker.js +11 -0
  168. package/dist/templates/tool-index.js +9 -0
  169. package/dist/tools/discoveryFactory.d.ts +117 -0
  170. package/dist/tools/discoveryFactory.d.ts.map +1 -0
  171. package/dist/tools/function/index.d.ts +10 -0
  172. package/dist/tools/function/index.d.ts.map +1 -0
  173. package/dist/tools/function/scanner.d.ts +29 -0
  174. package/dist/tools/function/scanner.d.ts.map +1 -0
  175. package/dist/tools/function/schemaFromTs.d.ts +16 -0
  176. package/dist/tools/function/schemaFromTs.d.ts.map +1 -0
  177. package/dist/tools/function/types.d.ts +20 -0
  178. package/dist/tools/function/types.d.ts.map +1 -0
  179. package/dist/tools/index.d.ts +13 -0
  180. package/dist/tools/index.d.ts.map +1 -0
  181. package/dist/tools/langchain/LangChainLoader.d.ts +7 -0
  182. package/dist/tools/langchain/LangChainLoader.d.ts.map +1 -0
  183. package/dist/tools/langchain/directoryApply.d.ts +5 -0
  184. package/dist/tools/langchain/directoryApply.d.ts.map +1 -0
  185. package/dist/tools/langchain/directoryLoad.d.ts +13 -0
  186. package/dist/tools/langchain/directoryLoad.d.ts.map +1 -0
  187. package/dist/tools/langchain/index.d.ts +3 -0
  188. package/dist/tools/langchain/index.d.ts.map +1 -0
  189. package/dist/tools/langchain/scanner.d.ts +8 -0
  190. package/dist/tools/langchain/scanner.d.ts.map +1 -0
  191. package/dist/tools/langchain/types.d.ts +5 -0
  192. package/dist/tools/langchain/types.d.ts.map +1 -0
  193. package/dist/tools/mcp/MCPClientAdapter.d.ts +34 -0
  194. package/dist/tools/mcp/MCPClientAdapter.d.ts.map +1 -0
  195. package/dist/tools/mcp/MCPLoader.d.ts +8 -0
  196. package/dist/tools/mcp/MCPLoader.d.ts.map +1 -0
  197. package/dist/tools/mcp/MCPProcessManager.d.ts +29 -0
  198. package/dist/tools/mcp/MCPProcessManager.d.ts.map +1 -0
  199. package/dist/tools/mcp/connectMCP.d.ts +47 -0
  200. package/dist/tools/mcp/connectMCP.d.ts.map +1 -0
  201. package/dist/tools/mcp/directoryApply.d.ts +10 -0
  202. package/dist/tools/mcp/directoryApply.d.ts.map +1 -0
  203. package/dist/tools/mcp/index.d.ts +16 -0
  204. package/dist/tools/mcp/index.d.ts.map +1 -0
  205. package/dist/tools/mcp/mcpSpecToToolSpec.d.ts +8 -0
  206. package/dist/tools/mcp/mcpSpecToToolSpec.d.ts.map +1 -0
  207. package/dist/tools/mcp/registerMCPTools.d.ts +24 -0
  208. package/dist/tools/mcp/registerMCPTools.d.ts.map +1 -0
  209. package/dist/tools/mcp/scanner.d.ts +8 -0
  210. package/dist/tools/mcp/scanner.d.ts.map +1 -0
  211. package/dist/tools/mcp/support/types.d.ts +3 -0
  212. package/dist/tools/mcp/support/types.d.ts.map +1 -0
  213. package/dist/tools/n8n/N8nLoader.d.ts +25 -0
  214. package/dist/tools/n8n/N8nLoader.d.ts.map +1 -0
  215. package/dist/tools/n8n/directoryApply.d.ts +10 -0
  216. package/dist/tools/n8n/directoryApply.d.ts.map +1 -0
  217. package/dist/tools/n8n/index.d.ts +6 -0
  218. package/dist/tools/n8n/index.d.ts.map +1 -0
  219. package/dist/tools/n8n/scanN8n.d.ts +20 -0
  220. package/dist/tools/n8n/scanN8n.d.ts.map +1 -0
  221. package/dist/tools/n8n/types.d.ts +18 -0
  222. package/dist/tools/n8n/types.d.ts.map +1 -0
  223. package/dist/tools/scanPackage.d.ts +42 -0
  224. package/dist/tools/scanPackage.d.ts.map +1 -0
  225. package/dist/tools/skill/SkillLoader.d.ts +20 -0
  226. package/dist/tools/skill/SkillLoader.d.ts.map +1 -0
  227. package/dist/tools/skill/SkillManifest.d.ts +79 -0
  228. package/dist/tools/skill/SkillManifest.d.ts.map +1 -0
  229. package/dist/tools/skill/SkillMdParser.d.ts +31 -0
  230. package/dist/tools/skill/SkillMdParser.d.ts.map +1 -0
  231. package/dist/tools/skill/directoryApply.d.ts +10 -0
  232. package/dist/tools/skill/directoryApply.d.ts.map +1 -0
  233. package/dist/tools/skill/index.d.ts +8 -0
  234. package/dist/tools/skill/index.d.ts.map +1 -0
  235. package/dist/tools/skill/scanSkill.d.ts +20 -0
  236. package/dist/tools/skill/scanSkill.d.ts.map +1 -0
  237. package/dist/tools/skill/types.d.ts +19 -0
  238. package/dist/tools/skill/types.d.ts.map +1 -0
  239. package/dist/tools/util/canonicalCoreSchemas.d.ts +15 -0
  240. package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -0
  241. package/dist/tools/util/index.d.ts +13 -0
  242. package/dist/tools/util/index.d.ts.map +1 -0
  243. package/dist/tools/util/resolveEntry.d.ts +6 -0
  244. package/dist/tools/util/resolveEntry.d.ts.map +1 -0
  245. package/dist/tools/util/scanUtil.d.ts +9 -0
  246. package/dist/tools/util/scanUtil.d.ts.map +1 -0
  247. package/dist/tools/util/toolConfig.d.ts +38 -0
  248. package/dist/tools/util/toolConfig.d.ts.map +1 -0
  249. package/dist/tools/util/toolDescriptor.d.ts +117 -0
  250. package/dist/tools/util/toolDescriptor.d.ts.map +1 -0
  251. package/dist/utils/cli/help.d.ts +2 -0
  252. package/dist/utils/cli/help.d.ts.map +1 -0
  253. package/dist/utils/cli/index.cjs +700 -0
  254. package/dist/utils/cli/index.cjs.map +1 -0
  255. package/dist/utils/cli/index.d.ts +9 -0
  256. package/dist/utils/cli/index.d.ts.map +1 -0
  257. package/dist/utils/cli/index.js +677 -0
  258. package/dist/utils/cli/index.js.map +1 -0
  259. package/dist/utils/cli/toolRuntime.d.ts +19 -0
  260. package/dist/utils/cli/toolRuntime.d.ts.map +1 -0
  261. package/dist/utils/log.d.ts +2 -0
  262. package/dist/utils/log.d.ts.map +1 -0
  263. package/dist/utils/npmCache.d.ts +11 -0
  264. package/dist/utils/npmCache.d.ts.map +1 -0
  265. package/dist/utils/npmVersion.d.ts +10 -0
  266. package/dist/utils/npmVersion.d.ts.map +1 -0
  267. package/dist/utils/overrideWithConfig.d.ts +2 -0
  268. package/dist/utils/overrideWithConfig.d.ts.map +1 -0
  269. package/package.json +125 -0
@@ -0,0 +1,520 @@
1
+ import * as path from 'path';
2
+ import { join } from 'path';
3
+ import * as fs from 'fs';
4
+ import * as ts2 from 'typescript';
5
+ import { readdir } from 'fs/promises';
6
+
7
+ // src/tools/function/scanner.ts
8
+ async function findDirsContainingFile(rootPath, fileName) {
9
+ const found = [];
10
+ await collectDirsWithFile(rootPath, fileName, found);
11
+ return found;
12
+ }
13
+ async function collectDirsWithFile(dir, fileName, acc) {
14
+ let entries;
15
+ try {
16
+ const e = await readdir(dir, { withFileTypes: true });
17
+ entries = e.map((x) => ({
18
+ name: x.name,
19
+ isDirectory: x.isDirectory(),
20
+ isFile: x.isFile()
21
+ }));
22
+ } catch {
23
+ return;
24
+ }
25
+ if (entries.some((x) => x.isFile && x.name === fileName)) acc.push(dir);
26
+ for (const entry of entries) {
27
+ if (!entry.isDirectory || entry.name === "node_modules" || entry.name.startsWith(".")) continue;
28
+ await collectDirsWithFile(join(dir, entry.name), fileName, acc);
29
+ }
30
+ }
31
+ function pathToToolName(sourcePath, programName) {
32
+ const normalized = sourcePath.replace(/\\/g, "/").replace(/\.(ts|tsx|js|mjs|json)$/i, "");
33
+ const segments = normalized.split("/").filter(Boolean);
34
+ return segments.length === 0 ? programName : `${segments.join(".")}.${programName}`;
35
+ }
36
+ function buildOutputSchemaFromReturnType(node, typeChecker, onWarn) {
37
+ const sig = typeChecker.getSignatureFromDeclaration(node);
38
+ if (!sig) {
39
+ onWarn?.("Could not get signature for return type, using object");
40
+ return { type: "object", additionalProperties: true };
41
+ }
42
+ let returnType = typeChecker.getReturnTypeOfSignature(sig);
43
+ if (returnType.getSymbol?.()?.getName() === "Promise") {
44
+ const typeArgs = returnType.typeArguments;
45
+ if (typeArgs?.[0]) returnType = typeArgs[0];
46
+ }
47
+ const schema = typeToJsonSchema(returnType, typeChecker, onWarn);
48
+ const hasProps = typeof schema === "object" && schema.type === "object" && Object.keys(schema.properties ?? {}).length > 0;
49
+ return hasProps ? schema : { type: "object", additionalProperties: true };
50
+ }
51
+ function buildInputSchemaFromParams(node, typeChecker, onWarn) {
52
+ const properties = {};
53
+ const required = [];
54
+ if (!node.parameters.length) {
55
+ return { schema: { type: "object", properties: {} }, required: [] };
56
+ }
57
+ for (const param of node.parameters) {
58
+ const name = param.name.getText();
59
+ if (name.startsWith("_") && name.length <= 2) continue;
60
+ const sym = param.symbol;
61
+ const paramType = sym ? typeChecker.getTypeOfSymbolAtLocation(sym, param) : typeChecker.getTypeAtLocation(param);
62
+ const isOptional = !!param.questionToken || param.initializer !== void 0;
63
+ const propSchema = typeToJsonSchema(paramType, typeChecker, onWarn);
64
+ properties[name] = propSchema;
65
+ if (!isOptional) required.push(name);
66
+ }
67
+ const paramNames = Object.keys(properties);
68
+ if (paramNames.length === 1) {
69
+ const soleName = paramNames[0];
70
+ const inner = properties[soleName];
71
+ if (inner && typeof inner === "object" && inner.type === "object" && inner.properties && typeof inner.properties === "object") {
72
+ return {
73
+ schema: {
74
+ type: "object",
75
+ properties: inner.properties,
76
+ ...Array.isArray(inner.required) && inner.required.length > 0 ? { required: inner.required } : {},
77
+ ...inner.additionalProperties !== void 0 ? { additionalProperties: inner.additionalProperties } : {}
78
+ },
79
+ required: inner.required ?? []
80
+ };
81
+ }
82
+ }
83
+ return {
84
+ schema: {
85
+ type: "object",
86
+ properties,
87
+ ...required.length > 0 ? { required } : {}
88
+ },
89
+ required
90
+ };
91
+ }
92
+ function typeToJsonSchema(type, typeChecker, onWarn) {
93
+ const flags = type.flags;
94
+ if (flags & ts2.TypeFlags.String) return { type: "string" };
95
+ if (flags & ts2.TypeFlags.Number) return { type: "number" };
96
+ if (flags & ts2.TypeFlags.Boolean) return { type: "boolean" };
97
+ if (flags & ts2.TypeFlags.BooleanLiteral) return { type: "boolean" };
98
+ if (flags & ts2.TypeFlags.Null) return { type: "null" };
99
+ if (flags & ts2.TypeFlags.Undefined || flags & ts2.TypeFlags.Void) return {};
100
+ if (flags & ts2.TypeFlags.Any || flags & ts2.TypeFlags.Unknown) {
101
+ onWarn?.(`Unsupported type: any/unknown, using empty schema`);
102
+ return {};
103
+ }
104
+ if (type.isUnion?.()) {
105
+ const union = type;
106
+ const types = union.types;
107
+ const withoutUndef = types.filter(
108
+ (t) => !(t.flags & ts2.TypeFlags.Undefined) && !(t.flags & ts2.TypeFlags.Void)
109
+ );
110
+ if (withoutUndef.length === 1) return typeToJsonSchema(withoutUndef[0], typeChecker, onWarn);
111
+ if (withoutUndef.length === 0) return {};
112
+ const stringEnumValues = [];
113
+ let allStringLiterals = true;
114
+ for (const t of withoutUndef) {
115
+ if (t.flags & ts2.TypeFlags.StringLiteral) {
116
+ const lit = t;
117
+ if (typeof lit.value === "string") stringEnumValues.push(lit.value);
118
+ } else {
119
+ allStringLiterals = false;
120
+ break;
121
+ }
122
+ }
123
+ if (allStringLiterals && stringEnumValues.length > 0) {
124
+ return { type: "string", enum: [...new Set(stringEnumValues)] };
125
+ }
126
+ let allBooleanLiterals = true;
127
+ for (const t of withoutUndef) {
128
+ if (!(t.flags & ts2.TypeFlags.BooleanLiteral)) {
129
+ allBooleanLiterals = false;
130
+ break;
131
+ }
132
+ }
133
+ if (allBooleanLiterals) return { type: "boolean" };
134
+ }
135
+ if (flags & ts2.TypeFlags.StringLiteral) {
136
+ const lit = type;
137
+ if (typeof lit.value === "string") {
138
+ return { type: "string", enum: [lit.value] };
139
+ }
140
+ return { type: "string" };
141
+ }
142
+ if (typeChecker.isArrayType(type)) {
143
+ const typeRef = type;
144
+ const typeArgs = typeRef.typeArguments;
145
+ const itemType = typeArgs?.[0];
146
+ const items = itemType ? typeToJsonSchema(itemType, typeChecker, onWarn) : {};
147
+ return { type: "array", items: Object.keys(items).length ? items : {} };
148
+ }
149
+ const str = typeChecker.typeToString(type);
150
+ if (str === "string") return { type: "string" };
151
+ if (str === "number") return { type: "number" };
152
+ if (str === "boolean") return { type: "boolean" };
153
+ if (str.endsWith("[]")) {
154
+ const inner = str.slice(0, -2).trim();
155
+ const itemType = inner === "string" ? { type: "string" } : inner === "number" ? { type: "number" } : {};
156
+ return { type: "array", items: itemType };
157
+ }
158
+ if (type.getProperties && type.getProperties().length >= 0) {
159
+ const props = type.getProperties();
160
+ const properties = {};
161
+ const required = [];
162
+ for (const p of props) {
163
+ const decl = p.valueDeclaration;
164
+ const propType = decl ? typeChecker.getTypeAtLocation(decl) : typeChecker.getTypeOfSymbolAtLocation(p, p.valueDeclaration);
165
+ const optional = decl && ts2.isPropertySignature(decl) ? !!decl.questionToken : false;
166
+ properties[p.name] = typeToJsonSchema(propType, typeChecker, onWarn);
167
+ if (!optional) required.push(p.name);
168
+ }
169
+ return { type: "object", properties, ...required.length ? { required } : {} };
170
+ }
171
+ onWarn?.(`Unsupported type: ${str}, using object`);
172
+ return { type: "object" };
173
+ }
174
+
175
+ // src/tools/function/types.ts
176
+ var FUNCTION_KIND = "function";
177
+
178
+ // src/core/types/ToolSpec.ts
179
+ function normalizeToolName(name) {
180
+ if (typeof name !== "string" || !name) return name;
181
+ return name.replace(/[^a-zA-Z0-9]/g, ".").replace(/\.+/g, ".");
182
+ }
183
+ var DEFAULT_INPUT_SCHEMA = {
184
+ type: "object",
185
+ additionalProperties: true
186
+ };
187
+ var DEFAULT_OUTPUT_SCHEMA = {
188
+ type: "object",
189
+ additionalProperties: true
190
+ };
191
+ function createToolSpec(opts) {
192
+ const sideEffect = opts.sideEffect ?? "none";
193
+ const name = normalizeToolName(opts.name);
194
+ return {
195
+ name,
196
+ version: opts.version ?? "1.0.0",
197
+ kind: opts.kind,
198
+ description: opts.description,
199
+ tags: opts.tags,
200
+ inputSchema: opts.inputSchema ?? DEFAULT_INPUT_SCHEMA,
201
+ outputSchema: opts.outputSchema ?? DEFAULT_OUTPUT_SCHEMA,
202
+ capabilities: opts.capabilities,
203
+ costHints: opts.costHints,
204
+ _meta: { hitl: { sideEffect } }
205
+ };
206
+ }
207
+
208
+ // src/tools/skill/types.ts
209
+ var SKILL_KIND = "skill";
210
+ var SKILL_DIR_NAME = "skill";
211
+
212
+ // src/tools/n8n/types.ts
213
+ var N8N_KIND = "n8n";
214
+
215
+ // src/tools/mcp/mcpSpecToToolSpec.ts
216
+ var DEFAULT_OUTPUT = { type: "object", additionalProperties: true };
217
+ function mcpSpecToToolSpec(spec, projectPath) {
218
+ const base = {
219
+ name: spec.name,
220
+ version: "1.0.0",
221
+ kind: spec.kind,
222
+ description: spec.description,
223
+ inputSchema: spec.inputSchema ?? DEFAULT_OUTPUT,
224
+ outputSchema: "outputSchema" in spec && spec.outputSchema ? spec.outputSchema : DEFAULT_OUTPUT_SCHEMA,
225
+ capabilities: [],
226
+ _meta: spec._meta,
227
+ ...spec.kind === N8N_KIND && "webhookUrl" in spec && spec.webhookUrl ? { endpoint: spec.webhookUrl } : {}
228
+ };
229
+ if (spec.kind === FUNCTION_KIND && "sourcePath" in spec && "exportName" in spec) {
230
+ base._meta = {
231
+ ...base._meta,
232
+ sourcePath: spec.sourcePath,
233
+ exportName: spec.exportName,
234
+ ...projectPath && { projectPath }
235
+ };
236
+ }
237
+ if (spec.kind === SKILL_KIND && "sourcePath" in spec && projectPath) {
238
+ base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };
239
+ }
240
+ if (spec.kind === N8N_KIND && "sourcePath" in spec && projectPath) {
241
+ base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };
242
+ }
243
+ return base;
244
+ }
245
+
246
+ // src/tools/function/scanner.ts
247
+ var TOOL_TAG = "@tool";
248
+ var EFFECT_VALUES = ["none", "local_write", "external_write", "destructive"];
249
+ function scanForTools(options) {
250
+ const projectPath = path.resolve(options.projectPath);
251
+ const tsconfigPath = options.tsconfigPath ?? path.join(projectPath, "tsconfig.json");
252
+ const include = options.include ?? ["**/*.ts"];
253
+ const errors = [];
254
+ const warnings = [];
255
+ const config = loadParsedCommandLine({
256
+ projectPath,
257
+ tsconfigPath,
258
+ include,
259
+ errors});
260
+ if (!config) return { specs: [], errors, warnings };
261
+ const program = ts2.createProgram(config.fileNames, config.options);
262
+ const typeChecker = program.getTypeChecker();
263
+ const specs = [];
264
+ const configFileSet = new Set(config.fileNames.map((f) => path.resolve(f)));
265
+ collectToolSpecsFromProgram({
266
+ program,
267
+ typeChecker,
268
+ projectPath,
269
+ warnings,
270
+ configFileSet,
271
+ specs
272
+ });
273
+ return { specs, errors, warnings };
274
+ }
275
+ function loadParsedCommandLine(input) {
276
+ let configPathResolved = path.resolve(input.projectPath, input.tsconfigPath);
277
+ if (!fs.existsSync(configPathResolved)) {
278
+ configPathResolved = path.join(input.projectPath, "tsconfig.json");
279
+ }
280
+ if (!fs.existsSync(configPathResolved)) {
281
+ return {
282
+ options: {
283
+ target: ts2.ScriptTarget.ES2022,
284
+ module: ts2.ModuleKind.ESNext,
285
+ moduleResolution: ts2.ModuleResolutionKind.NodeNext,
286
+ strict: true,
287
+ skipLibCheck: true,
288
+ noEmit: true
289
+ },
290
+ fileNames: resolveGlob(input.projectPath, input.include),
291
+ errors: []
292
+ };
293
+ }
294
+ const configFile = ts2.readConfigFile(configPathResolved, ts2.sys.readFile);
295
+ if (configFile.error) {
296
+ input.errors.push({ file: configPathResolved, message: String(configFile.error.messageText) });
297
+ return null;
298
+ }
299
+ const parsed = ts2.parseJsonConfigFileContent(
300
+ configFile.config,
301
+ ts2.sys,
302
+ path.dirname(configPathResolved)
303
+ );
304
+ if (parsed.errors.length === 0) return parsed;
305
+ for (const e of parsed.errors) {
306
+ input.errors.push({ file: e.file?.fileName ?? "tsconfig", message: String(e.messageText) });
307
+ }
308
+ return null;
309
+ }
310
+ function collectToolSpecsFromProgram(input) {
311
+ for (const sourceFile of input.program.getSourceFiles()) {
312
+ const fileName = sourceFile.fileName;
313
+ if (fileName.includes("node_modules") || fileName.endsWith(".d.ts")) continue;
314
+ if (!input.configFileSet.has(path.resolve(fileName))) continue;
315
+ ts2.forEachChild(sourceFile, (node) => {
316
+ const spec = toFunctionToolSpec({
317
+ node,
318
+ fileName,
319
+ projectPath: input.projectPath,
320
+ typeChecker: input.typeChecker,
321
+ warnings: input.warnings
322
+ });
323
+ if (spec) input.specs.push(spec);
324
+ });
325
+ }
326
+ }
327
+ function toFunctionToolSpec(input) {
328
+ const decl = getExportedFunctionDeclaration(input.node);
329
+ if (!decl || !decl.name) return null;
330
+ const host = getJSDocHost(decl.func);
331
+ if (!hasToolTag(host)) return null;
332
+ const jsDoc = getJSDocComments(host);
333
+ const description = getDescription(jsDoc);
334
+ if (!description) {
335
+ input.warnings.push({
336
+ file: input.fileName,
337
+ message: `Tool ${decl.name}: missing description, using humanized name`
338
+ });
339
+ }
340
+ const sideEffect = getEffect(host);
341
+ const onWarn = (msg) => input.warnings.push({ file: input.fileName, message: `${decl.name}: ${msg}` });
342
+ const { schema } = buildInputSchemaFromParams(decl.func, input.typeChecker, onWarn);
343
+ const outputSchema = buildOutputSchemaFromReturnType(decl.func, input.typeChecker, onWarn);
344
+ const sourcePath = path.relative(input.projectPath, input.fileName) || path.basename(input.fileName);
345
+ const toolName = pathToToolName(sourcePath, decl.name);
346
+ return {
347
+ kind: FUNCTION_KIND,
348
+ name: toolName,
349
+ description: description || humanize(decl.name),
350
+ inputSchema: normalizeInputSchema(schema),
351
+ outputSchema,
352
+ _meta: { hitl: { sideEffect } },
353
+ sourcePath,
354
+ exportName: decl.name
355
+ };
356
+ }
357
+ function normalizeInputSchema(schema) {
358
+ return Object.keys(schema.properties ?? {}).length > 0 ? schema : { type: "object", properties: {} };
359
+ }
360
+ function resolveGlob(projectPath, patterns) {
361
+ const result = [];
362
+ const seen = /* @__PURE__ */ new Set();
363
+ const add = (f) => {
364
+ const abs = path.resolve(f);
365
+ if (f.endsWith(".ts") && !f.endsWith(".d.ts") && !seen.has(abs)) {
366
+ seen.add(abs);
367
+ result.push(abs);
368
+ }
369
+ };
370
+ for (const p of patterns) {
371
+ const full = path.join(projectPath, p);
372
+ if (full.includes("*")) {
373
+ const baseDir = full.replace(/\*\*\/.*$/, "").replace(/\*.*$/, "").replace(/\/?$/, "") || ".";
374
+ const dir = path.resolve(projectPath, baseDir);
375
+ if (fs.existsSync(dir)) walk(dir, add);
376
+ } else {
377
+ const resolved = path.resolve(projectPath, full);
378
+ if (fs.existsSync(resolved)) {
379
+ if (fs.statSync(resolved).isFile()) add(resolved);
380
+ else walk(resolved, add);
381
+ }
382
+ }
383
+ }
384
+ if (result.length > 0) return result;
385
+ const srcDir = path.join(projectPath, "src");
386
+ if (fs.existsSync(srcDir)) return walkCollect(srcDir);
387
+ return [];
388
+ }
389
+ function walkCollect(dir) {
390
+ const out = [];
391
+ walk(dir, (fullPath) => {
392
+ if (fullPath.endsWith(".ts") && !fullPath.endsWith(".d.ts")) out.push(path.resolve(fullPath));
393
+ });
394
+ return out;
395
+ }
396
+ var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "generated", "dist"]);
397
+ function walk(dir, visit) {
398
+ try {
399
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
400
+ for (const e of entries) {
401
+ const full = path.join(dir, e.name);
402
+ if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(full, visit);
403
+ else if (e.isFile()) visit(full);
404
+ }
405
+ } catch {
406
+ }
407
+ }
408
+ function getExportedFunctionDeclaration(node, _sourceFile) {
409
+ if (ts2.isFunctionDeclaration(node) && node.name) {
410
+ const exported = (ts2.getModifiers(node) ?? []).some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
411
+ if (exported) return { func: node, name: node.name.getText() };
412
+ return null;
413
+ }
414
+ if (ts2.isVariableStatement(node)) {
415
+ const exported = (ts2.getModifiers(node) ?? []).some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
416
+ if (!exported) return null;
417
+ for (const decl of node.declarationList.declarations) {
418
+ let init = decl.initializer;
419
+ while (init && (ts2.isParenthesizedExpression(init) || ts2.isAsExpression(init)))
420
+ init = init.expression;
421
+ if (init && ts2.isArrowFunction(init)) {
422
+ const name = decl.name.getText();
423
+ return { func: init, name };
424
+ }
425
+ if (init && ts2.isFunctionExpression(init)) {
426
+ const name = decl.name.getText();
427
+ return { func: init, name };
428
+ }
429
+ }
430
+ }
431
+ return null;
432
+ }
433
+ function getJSDocHost(node) {
434
+ const parent = node.parent;
435
+ if (ts2.isVariableDeclaration(parent)) {
436
+ const gp = parent.parent;
437
+ if (ts2.isVariableDeclarationList(gp) && gp.parent && ts2.isVariableStatement(gp.parent)) return gp.parent;
438
+ }
439
+ return node;
440
+ }
441
+ function getJSDocComments(host) {
442
+ const all = ts2.getJSDocCommentsAndTags(host);
443
+ return all.filter((t) => ts2.isJSDoc(t));
444
+ }
445
+ function hasToolTag(host) {
446
+ const tags = ts2.getJSDocTags(host);
447
+ for (const tag of tags) {
448
+ const name = tag.tagName?.getText() ?? "";
449
+ if (name === "tool") return true;
450
+ }
451
+ const all = ts2.getJSDocCommentsAndTags(host);
452
+ for (const t of all) {
453
+ if (ts2.isJSDoc(t)) {
454
+ const full = t.getFullText();
455
+ if (full.includes(TOOL_TAG)) return true;
456
+ }
457
+ }
458
+ return false;
459
+ }
460
+ function getDescription(jsDocs) {
461
+ for (const doc of jsDocs) {
462
+ const comment = doc.comment;
463
+ if (typeof comment === "string") {
464
+ const first = comment.split(/\n/)[0]?.trim() ?? "";
465
+ if (first && !first.startsWith("@")) return first;
466
+ }
467
+ if (Array.isArray(comment)) {
468
+ const first = comment[0];
469
+ if (first && typeof first === "object" && "text" in first) {
470
+ const t = first.text.trim();
471
+ if (t && !t.startsWith("@")) return t;
472
+ }
473
+ }
474
+ const full = doc.getFullText();
475
+ const match = full.match(/\*\s*@tool\s+(.+?)(?=\n|$|\*\/)/s);
476
+ if (match?.[1]) return match[1].trim();
477
+ }
478
+ return "";
479
+ }
480
+ function getEffect(host) {
481
+ const tags = ts2.getJSDocTags(host);
482
+ for (const tag of tags) {
483
+ const name = tag.tagName?.getText() ?? "";
484
+ if (name === "effect") {
485
+ const comment = tag.comment;
486
+ const v = (typeof comment === "string" ? comment : "").trim().toLowerCase();
487
+ if (EFFECT_VALUES.includes(v)) return v;
488
+ }
489
+ }
490
+ const all = ts2.getJSDocCommentsAndTags(host);
491
+ for (const t of all) {
492
+ if (ts2.isJSDoc(t)) {
493
+ const full = t.getFullText();
494
+ const match = full.match(/\*\s*@effect\s+(\w+)/);
495
+ if (match && EFFECT_VALUES.includes(match[1])) return match[1];
496
+ }
497
+ }
498
+ return "none";
499
+ }
500
+ function humanize(name) {
501
+ return name.replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase()).trim();
502
+ }
503
+ function scan(projectPath, options = {}) {
504
+ const root = path.resolve(projectPath);
505
+ const result = scanForTools({
506
+ projectPath: root,
507
+ include: options.include ?? ["**/*.ts"],
508
+ tsconfigPath: options.tsconfigPath
509
+ });
510
+ const specs = result.specs.map((s) => mcpSpecToToolSpec(s, root));
511
+ return Promise.resolve({
512
+ specs,
513
+ errors: result.errors,
514
+ warnings: result.warnings
515
+ });
516
+ }
517
+
518
+ export { FUNCTION_KIND, N8N_KIND, SKILL_DIR_NAME, SKILL_KIND, createToolSpec, findDirsContainingFile, mcpSpecToToolSpec, normalizeToolName, pathToToolName, scan, scanForTools };
519
+ //# sourceMappingURL=chunk-BDUSB6GT.js.map
520
+ //# sourceMappingURL=chunk-BDUSB6GT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tools/util/scanUtil.ts","../src/tools/function/schemaFromTs.ts","../src/tools/function/types.ts","../src/core/types/ToolSpec.ts","../src/tools/skill/types.ts","../src/tools/n8n/types.ts","../src/tools/mcp/mcpSpecToToolSpec.ts","../src/tools/function/scanner.ts"],"names":["ts"],"mappings":";;;;;;;AASA,eAAsB,sBAAA,CACpB,UACA,QAAA,EACmB;AACnB,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,mBAAA,CAAoB,QAAA,EAAU,QAAA,EAAU,KAAK,CAAA;AACnD,EAAA,OAAO,KAAA;AACT;AAEA,eAAe,mBAAA,CACb,GAAA,EACA,QAAA,EACA,GAAA,EACe;AACf,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,IAAI,MAAM,OAAA,CAAQ,KAAK,EAAE,aAAA,EAAe,MAAM,CAAA;AACpD,IAAA,OAAA,GAAU,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,MACtB,MAAM,CAAA,CAAE,IAAA;AAAA,MACR,WAAA,EAAa,EAAE,WAAA,EAAY;AAAA,MA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AAS,KAAA,CAAM,CAAC,CAAe,CAAA,EAAG,OAAO,KAAA,CAAM,CAAC,CAAA;AAAA,IAC7E;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,SAAS,IAAA,EAAsB;AACtC,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,UAAA,EAAY,KAAK,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA,EAAa,EAAE,IAAA,EAAK;AACpF;AAGO,SAAS,IAAA,CACd,WAAA,EACA,OAAA,GAAgC,EAAC,EACH;AAC9B,EAAA,MAAM,IAAA,GAAY,aAAQ,WAAW,CAAA;AACrC,EAAA,MAAM,SAAS,YAAA,CAAa;AAAA,IAC1B,WAAA,EAAa,IAAA;AAAA,IACb,OAAA,EAAS,OAAA,CAAQ,OAAA,IAAW,CAAC,SAAS,CAAA;AAAA,IACtC,cAAc,OAAA,CAAQ;AAAA,GACvB,CAAA;AACD,EAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,KAAM,iBAAA,CAAkB,CAAA,EAAG,IAAI,CAAC,CAAA;AAChE,EAAA,OAAO,QAAQ,OAAA,CAAQ;AAAA,IACrB,KAAA;AAAA,IACA,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,UAAU,MAAA,CAAO;AAAA,GAClB,CAAA;AACH","file":"chunk-BDUSB6GT.js","sourcesContent":["/**\n * Shared scan helpers for tool-type scanners (function, skill, n8n).\n * findDirsContainingFile: recursive dirs that contain a given file name.\n * pathToToolName: build dotted tool name from source path and program name.\n */\n\nimport { readdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nexport async function findDirsContainingFile(\n rootPath: string,\n fileName: string,\n): Promise<string[]> {\n const found: string[] = [];\n await collectDirsWithFile(rootPath, fileName, found);\n return found;\n}\n\nasync function collectDirsWithFile(\n dir: string,\n fileName: string,\n acc: string[],\n): Promise<void> {\n let entries: Array<{ name: string; isDirectory: boolean; isFile: boolean }>;\n try {\n const e = await readdir(dir, { withFileTypes: true });\n entries = e.map((x) => ({\n name: x.name,\n isDirectory: x.isDirectory(),\n isFile: x.isFile(),\n }));\n } catch {\n return;\n }\n if (entries.some((x) => x.isFile && x.name === fileName)) acc.push(dir);\n for (const entry of entries) {\n if (!entry.isDirectory || entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n await collectDirsWithFile(join(dir, entry.name), fileName, acc);\n }\n}\n\n/** Build dotted tool name from source path (extension stripped) and program name. */\nexport function pathToToolName(sourcePath: string, programName: string): string {\n const normalized = sourcePath\n .replace(/\\\\/g, \"/\")\n .replace(/\\.(ts|tsx|js|mjs|json)$/i, \"\");\n const segments = normalized.split(\"/\").filter(Boolean);\n return segments.length === 0 ? programName : `${segments.join(\".\")}.${programName}`;\n}\n","/**\n * Build JSON Schema from TypeScript parameter types using the compiler API.\n * MVP: primitives, optional, array, object. Complex types fallback to {} with warn.\n */\n\nimport * as ts from \"typescript\";\n\n/**\n * Build output JSON Schema from function return type (unwrap Promise if present).\n * Used by scan when auto-deriving schema.\n */\nexport function buildOutputSchemaFromReturnType(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): object {\n const sig = typeChecker.getSignatureFromDeclaration(node as ts.SignatureDeclaration);\n if (!sig) {\n onWarn?.(\"Could not get signature for return type, using object\");\n return { type: \"object\", additionalProperties: true };\n }\n let returnType = typeChecker.getReturnTypeOfSignature(sig);\n // Unwrap Promise<T> to T\n if (returnType.getSymbol?.()?.getName() === \"Promise\") {\n const typeArgs = (returnType as ts.TypeReference).typeArguments;\n if (typeArgs?.[0]) returnType = typeArgs[0];\n }\n const schema = typeToJsonSchema(returnType, typeChecker, onWarn);\n const hasProps =\n typeof schema === \"object\" &&\n (schema as { type?: string; properties?: object }).type === \"object\" &&\n Object.keys((schema as { properties?: object }).properties ?? {}).length > 0;\n return hasProps ? schema : { type: \"object\", additionalProperties: true };\n}\n\n/** Build { type: \"object\", properties, required } from function parameters. */\nexport function buildInputSchemaFromParams(\n node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): { schema: object; required: string[] } {\n const properties: Record<string, object> = {};\n const required: string[] = [];\n\n if (!node.parameters.length) {\n return { schema: { type: \"object\", properties: {} }, required: [] };\n }\n\n for (const param of node.parameters) {\n const name = (param.name as ts.Identifier).getText();\n if (name.startsWith(\"_\") && name.length <= 2) continue;\n const sym = (param as ts.ParameterDeclaration & { symbol?: ts.Symbol }).symbol;\n const paramType = sym\n ? typeChecker.getTypeOfSymbolAtLocation(sym, param)\n : typeChecker.getTypeAtLocation(param);\n const isOptional = !!param.questionToken || param.initializer !== undefined;\n const propSchema = typeToJsonSchema(paramType, typeChecker, onWarn);\n properties[name] = propSchema;\n if (!isOptional) required.push(name);\n }\n\n // Flatten: when there is exactly one parameter and it's an object type, emit that object's\n // schema at top level so agents can pass flat params like { path: \".\" } instead of { args: { path: \".\" } }.\n const paramNames = Object.keys(properties);\n if (paramNames.length === 1) {\n const soleName = paramNames[0]!;\n const inner = properties[soleName] as\n | { type?: string; properties?: Record<string, object>; required?: string[]; additionalProperties?: boolean }\n | undefined;\n if (\n inner &&\n typeof inner === \"object\" &&\n inner.type === \"object\" &&\n inner.properties &&\n typeof inner.properties === \"object\"\n ) {\n return {\n schema: {\n type: \"object\",\n properties: inner.properties,\n ...(Array.isArray(inner.required) && inner.required.length > 0 ? { required: inner.required } : {}),\n ...(inner.additionalProperties !== undefined ? { additionalProperties: inner.additionalProperties } : {}),\n },\n required: inner.required ?? [],\n };\n }\n }\n\n return {\n schema: {\n type: \"object\",\n properties,\n ...(required.length > 0 ? { required } : {}),\n },\n required,\n };\n}\n\nfunction typeToJsonSchema(\n type: ts.Type,\n typeChecker: ts.TypeChecker,\n onWarn?: (message: string) => void,\n): object {\n const flags = type.flags;\n if (flags & ts.TypeFlags.String) return { type: \"string\" };\n if (flags & ts.TypeFlags.Number) return { type: \"number\" };\n if (flags & ts.TypeFlags.Boolean) return { type: \"boolean\" };\n if (flags & ts.TypeFlags.BooleanLiteral) return { type: \"boolean\" };\n if (flags & ts.TypeFlags.Null) return { type: \"null\" };\n if (flags & ts.TypeFlags.Undefined || flags & ts.TypeFlags.Void) return {};\n if (flags & ts.TypeFlags.Any || flags & ts.TypeFlags.Unknown) {\n onWarn?.(`Unsupported type: any/unknown, using empty schema`);\n return {};\n }\n\n if (type.isUnion?.()) {\n const union = type as ts.UnionType;\n const types = union.types;\n const withoutUndef = types.filter(\n (t) => !(t.flags & ts.TypeFlags.Undefined) && !(t.flags & ts.TypeFlags.Void),\n );\n if (withoutUndef.length === 1) return typeToJsonSchema(withoutUndef[0]!, typeChecker, onWarn);\n if (withoutUndef.length === 0) return {};\n // Union of string literals -> { type: \"string\", enum: [...] } so we don't fall through to getProperties() (String prototype).\n const stringEnumValues: string[] = [];\n let allStringLiterals = true;\n for (const t of withoutUndef) {\n if (t.flags & ts.TypeFlags.StringLiteral) {\n const lit = t as ts.StringLiteralType;\n if (typeof lit.value === \"string\") stringEnumValues.push(lit.value);\n } else {\n allStringLiterals = false;\n break;\n }\n }\n if (allStringLiterals && stringEnumValues.length > 0) {\n return { type: \"string\", enum: [...new Set(stringEnumValues)] };\n }\n\n // Union of boolean literals (true | false | undefined) should stay boolean.\n let allBooleanLiterals = true;\n for (const t of withoutUndef) {\n if (!(t.flags & ts.TypeFlags.BooleanLiteral)) {\n allBooleanLiterals = false;\n break;\n }\n }\n if (allBooleanLiterals) return { type: \"boolean\" };\n }\n\n // Single string literal (e.g. type: \"file\") -> { type: \"string\", enum: [\"file\"] }, not object with String methods.\n if (flags & ts.TypeFlags.StringLiteral) {\n const lit = type as ts.StringLiteralType;\n if (typeof lit.value === \"string\") {\n return { type: \"string\", enum: [lit.value] };\n }\n return { type: \"string\" };\n }\n\n if (typeChecker.isArrayType(type)) {\n const typeRef = type as ts.TypeReference;\n const typeArgs = typeRef.typeArguments;\n const itemType = typeArgs?.[0];\n const items = itemType ? typeToJsonSchema(itemType, typeChecker, onWarn) : {};\n return { type: \"array\", items: Object.keys(items).length ? items : {} };\n }\n\n const str = typeChecker.typeToString(type);\n if (str === \"string\") return { type: \"string\" };\n if (str === \"number\") return { type: \"number\" };\n if (str === \"boolean\") return { type: \"boolean\" };\n if (str.endsWith(\"[]\")) {\n const inner = str.slice(0, -2).trim();\n const itemType =\n inner === \"string\" ? { type: \"string\" as const } : inner === \"number\" ? { type: \"number\" as const } : {};\n return { type: \"array\", items: itemType };\n }\n\n if (type.getProperties && type.getProperties().length >= 0) {\n const props = type.getProperties();\n const properties: Record<string, object> = {};\n const required: string[] = [];\n for (const p of props) {\n const decl = p.valueDeclaration;\n const propType = decl\n ? typeChecker.getTypeAtLocation(decl)\n : typeChecker.getTypeOfSymbolAtLocation(p, (p as unknown as { valueDeclaration: ts.Node }).valueDeclaration);\n const optional = decl && ts.isPropertySignature(decl) ? !!decl.questionToken : false;\n properties[p.name] = typeToJsonSchema(propType, typeChecker, onWarn);\n if (!optional) required.push(p.name);\n }\n return { type: \"object\", properties, ...(required.length ? { required } : {}) };\n }\n\n onWarn?.(`Unsupported type: ${str}, using object`);\n return { type: \"object\" };\n}\n","/** HITL side-effect classification. */\nexport type SideEffect = \"none\" | \"local_write\" | \"external_write\" | \"destructive\";\n\n/** Kind for @tool function discovery. */\nexport const FUNCTION_KIND = \"function\" as const;\n\n/** Single tool spec from @tool function. */\nexport interface FunctionToolSpec {\n kind: typeof FUNCTION_KIND;\n name: string;\n description: string;\n inputSchema: object;\n outputSchema?: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n exportName: string;\n}\n","/**\n * Unified tool kinds supported by the tools package.\n */\nexport type ToolKind = \"mcp\" | \"langchain\" | \"n8n\" | \"comfyui\" | \"skill\" | \"function\" | \"core\" | \"example\";\n\n/**\n * Capability declarations for tools.\n * Used by PolicyEngine for permission gating.\n */\nexport type Capability =\n | \"read:web\"\n | \"read:fs\"\n | \"write:fs\"\n | \"read:db\"\n | \"write:db\"\n | \"network\"\n | \"gpu\"\n | \"workflow\"\n | \"danger:destructive\"\n | \"exec\";\n\n/**\n * HITL (Human-in-the-Loop) side-effect classification.\n * Used to gate execution: external_write / destructive require human approval when onApprovalRequired is set.\n */\nexport type HitlSideEffect = \"none\" | \"local_write\" | \"external_write\" | \"destructive\";\n\n/**\n * Cost hints for tools, used by Budget and routing.\n */\nexport interface CostHints {\n latencyMsP50?: number;\n latencyMsP95?: number;\n isAsync?: boolean;\n}\n\n/**\n * Unified tool specification.\n * All tool types (MCP, LangChain, n8n, SKILL) are described by this interface.\n *\n * Safety: each tool declares capabilities (permission gating) and _meta.hitl.sideEffect\n * (HITL approval for external_write/destructive). Caller uses these to decide handling.\n */\nexport interface ToolSpec {\n /** Globally unique name, recommended format: namespace/name */\n name: string;\n /** Semver version */\n version: string;\n /** Tool kind determines which adapter handles execution */\n kind: ToolKind;\n\n description?: string;\n tags?: string[];\n\n /** JSON Schema for input validation */\n inputSchema: object;\n /** JSON Schema for output validation */\n outputSchema: object;\n\n /** Required capabilities for this tool (safety: PolicyEngine gates by ExecContext.permissions) */\n capabilities: Capability[];\n costHints?: CostHints;\n\n /** HITL and adapter-specific metadata. Adapters may use _meta.sourcePath, _meta.exportName, _meta.projectPath (function), etc. */\n _meta?: {\n hitl?: { sideEffect?: HitlSideEffect };\n /** Function kind: path to source file relative to projectPath */\n sourcePath?: string;\n /** Function kind: export name of the handler */\n exportName?: string;\n /** Function/skill kind: project root for resolving sourcePath */\n projectPath?: string;\n /** Extension kind: package root for resolving sourcePath */\n packageRoot?: string;\n };\n\n /** Adapter-specific: endpoint URL (MCP/n8n) */\n endpoint?: string;\n /** Adapter-specific: resource identifier (workflowId, promptId, etc.) */\n resourceId?: string;\n /** Adapter-specific: implementation reference (LangChain Tool instance, skill handler) */\n impl?: unknown;\n}\n\n/**\n * Normalize tool name: only [a-zA-Z0-9] and \".\" allowed; all other characters become \".\".\n * Consecutive dots are collapsed to one. Used for registry lookup and storage.\n */\nexport function normalizeToolName(name: string): string {\n if (typeof name !== \"string\" || !name) return name;\n return name\n .replace(/[^a-zA-Z0-9]/g, \".\")\n .replace(/\\.+/g, \".\");\n}\n\n/** Default permissive input schema when not provided (framework supports auto-derived schema). */\nexport const DEFAULT_INPUT_SCHEMA: object = {\n type: \"object\",\n additionalProperties: true,\n};\n\n/** Default permissive output schema when not provided (framework supports auto-derived schema). */\nexport const DEFAULT_OUTPUT_SCHEMA: object = {\n type: \"object\",\n additionalProperties: true,\n};\n\n/**\n * Minimal options to build a ToolSpec. Use with @effect in JSDoc for HITL sideEffect.\n * Framework fills _meta.hitl.sideEffect from the sideEffect parameter (matches @effect annotation).\n * inputSchema/outputSchema are optional: when omitted, permissive defaults are used (framework supports auto-derived schema at build time in scan/mcp-build).\n */\nexport interface CreateToolSpecOptions {\n name: string;\n version?: string;\n kind: ToolKind;\n description?: string;\n tags?: string[];\n /** Optional: when omitted, DEFAULT_INPUT_SCHEMA is used. Codegen can derive from handler params. */\n inputSchema?: object;\n /** Optional: when omitted, DEFAULT_OUTPUT_SCHEMA is used. Codegen can derive from handler return type. */\n outputSchema?: object;\n capabilities: Capability[];\n costHints?: CostHints;\n /** HITL: from @effect annotation (none | local_write | external_write | destructive). Default \"none\". */\n sideEffect?: HitlSideEffect;\n}\n\n/**\n * Build a ToolSpec from minimal options. Use @effect in handler JSDoc as annotation; pass same value as sideEffect.\n * When inputSchema/outputSchema are omitted, permissive defaults are used (schema can be auto-derived at build time).\n */\nexport function createToolSpec(opts: CreateToolSpecOptions): ToolSpec {\n const sideEffect = opts.sideEffect ?? \"none\";\n const name = normalizeToolName(opts.name);\n return {\n name,\n version: opts.version ?? \"1.0.0\",\n kind: opts.kind,\n description: opts.description,\n tags: opts.tags,\n inputSchema: opts.inputSchema ?? DEFAULT_INPUT_SCHEMA,\n outputSchema: opts.outputSchema ?? DEFAULT_OUTPUT_SCHEMA,\n capabilities: opts.capabilities,\n costHints: opts.costHints,\n _meta: { hitl: { sideEffect } },\n };\n}\n\n/**\n * Unified adapter interface.\n * PTCRuntime looks up adapter by spec.kind and calls adapter.invoke(spec, args, ctx).\n * spec.name is always the single canonical name (the long name); there is no short name.\n */\nexport interface ToolAdapter {\n kind: ToolKind;\n /** Optional: supports dynamic tool discovery */\n listTools?(): Promise<ToolSpec[]>;\n /** Execute the tool with validated args. spec.name is the canonical (long) name. */\n invoke(\n spec: ToolSpec,\n args: unknown,\n ctx: import(\"./ToolIntent.js\").ExecContext,\n ): Promise<{ result: unknown; raw?: unknown }>;\n}\n","import type { SideEffect } from \"../function/types.js\";\n\n/** Kind for SKILL.md discovery. */\nexport const SKILL_KIND = \"skill\" as const;\n\n/** Conventional directory name for skill tools. */\nexport const SKILL_DIR_NAME = \"skill\" as const;\n\n/** Single tool spec from SKILL.md directory. */\nexport interface SkillToolSpec {\n kind: typeof SKILL_KIND;\n name: string;\n description: string;\n inputSchema: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n}\n","import type { SideEffect } from \"../function/types.js\";\n\n/** Kind for n8n workflow.json discovery. */\nexport const N8N_KIND = \"n8n\" as const;\n\n/** Single tool spec from n8n workflow.json directory. */\nexport interface N8nToolSpec {\n kind: typeof N8N_KIND;\n name: string;\n description: string;\n inputSchema: object;\n _meta?: { hitl?: { sideEffect?: SideEffect } };\n sourcePath: string;\n webhookUrl?: string;\n}\n","/**\n * Convert MCPToolSpec (function/skill/n8n scan result) to unified ToolSpec.\n * MCP layer: used by function/skill/n8n scanners when exposing unified ToolSpec.\n */\n\nimport type { ToolSpec } from \"../../core/types/ToolSpec.js\";\nimport { DEFAULT_OUTPUT_SCHEMA } from \"../../core/types/ToolSpec.js\";\nimport type { MCPToolSpec } from \"../discoveryFactory.js\";\nimport { FUNCTION_KIND } from \"../function/types.js\";\nimport { SKILL_KIND } from \"../skill/types.js\";\nimport { N8N_KIND } from \"../n8n/types.js\";\n\nconst DEFAULT_OUTPUT = { type: \"object\" as const, additionalProperties: true };\n\nexport function mcpSpecToToolSpec(spec: MCPToolSpec, projectPath?: string): ToolSpec {\n const base: ToolSpec = {\n name: spec.name,\n version: \"1.0.0\",\n kind: spec.kind,\n description: spec.description,\n inputSchema: spec.inputSchema ?? DEFAULT_OUTPUT,\n outputSchema:\n \"outputSchema\" in spec && spec.outputSchema\n ? spec.outputSchema\n : (DEFAULT_OUTPUT_SCHEMA as object),\n capabilities: [],\n _meta: spec._meta,\n ...(spec.kind === N8N_KIND && \"webhookUrl\" in spec && spec.webhookUrl\n ? { endpoint: spec.webhookUrl }\n : {}),\n };\n if (spec.kind === FUNCTION_KIND && \"sourcePath\" in spec && \"exportName\" in spec) {\n base._meta = {\n ...base._meta,\n sourcePath: spec.sourcePath,\n exportName: spec.exportName,\n ...(projectPath && { projectPath }),\n };\n }\n if (spec.kind === SKILL_KIND && \"sourcePath\" in spec && projectPath) {\n base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };\n }\n if (spec.kind === N8N_KIND && \"sourcePath\" in spec && projectPath) {\n base._meta = { ...base._meta, sourcePath: spec.sourcePath, projectPath };\n }\n return base;\n}\n","/**\n * Scan TypeScript source files for exported functions with @tool JSDoc.\n * Extracts description, @effect, and builds inputSchema from param types.\n * Exposes both scanForTools (raw) and scan (unified DiscoverToolsResult).\n */\n\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport * as ts from \"typescript\";\nimport { pathToToolName } from \"../util/scanUtil.js\";\nimport { buildInputSchemaFromParams, buildOutputSchemaFromReturnType } from \"./schemaFromTs.js\";\nimport type { FunctionToolSpec, SideEffect } from \"./types.js\";\nimport { FUNCTION_KIND } from \"./types.js\";\nimport type { DiscoverToolsOptions, DiscoverToolsResult } from \"../discoveryFactory.js\";\nimport { mcpSpecToToolSpec } from \"../mcp/mcpSpecToToolSpec.js\";\n\nconst TOOL_TAG = \"@tool\";\nconst EFFECT_VALUES: SideEffect[] = [\"none\", \"local_write\", \"external_write\", \"destructive\"];\n\nexport interface ScanResult {\n specs: FunctionToolSpec[];\n errors: Array<{ file: string; message: string }>;\n warnings: Array<{ file: string; message: string }>;\n}\n\n/**\n * Scan a project folder for exported functions annotated with @tool.\n */\nexport function scanForTools(options: {\n projectPath: string;\n include?: string[];\n tsconfigPath?: string;\n}): ScanResult {\n const projectPath = path.resolve(options.projectPath);\n const tsconfigPath =\n options.tsconfigPath ?? path.join(projectPath, \"tsconfig.json\");\n const include = options.include ?? [\"**/*.ts\"];\n const errors: Array<{ file: string; message: string }> = [];\n const warnings: Array<{ file: string; message: string }> = [];\n const config = loadParsedCommandLine({\n projectPath,\n tsconfigPath,\n include,\n errors,\n warnings,\n });\n if (!config) return { specs: [], errors, warnings };\n\n const program = ts.createProgram(config.fileNames, config.options);\n const typeChecker = program.getTypeChecker();\n const specs: FunctionToolSpec[] = [];\n const configFileSet = new Set(config.fileNames.map((f) => path.resolve(f)));\n\n collectToolSpecsFromProgram({\n program,\n typeChecker,\n projectPath,\n warnings,\n configFileSet,\n specs,\n });\n\n return { specs, errors, warnings };\n}\n\nfunction loadParsedCommandLine(input: {\n projectPath: string;\n tsconfigPath: string;\n include: string[];\n errors: Array<{ file: string; message: string }>;\n warnings: Array<{ file: string; message: string }>;\n}): ts.ParsedCommandLine | null {\n let configPathResolved = path.resolve(input.projectPath, input.tsconfigPath);\n if (!fs.existsSync(configPathResolved)) {\n configPathResolved = path.join(input.projectPath, \"tsconfig.json\");\n }\n if (!fs.existsSync(configPathResolved)) {\n return {\n options: {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n strict: true,\n skipLibCheck: true,\n noEmit: true,\n },\n fileNames: resolveGlob(input.projectPath, input.include),\n errors: [],\n } as ts.ParsedCommandLine;\n }\n\n const configFile = ts.readConfigFile(configPathResolved, ts.sys.readFile);\n if (configFile.error) {\n input.errors.push({ file: configPathResolved, message: String(configFile.error.messageText) });\n return null;\n }\n const parsed = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(configPathResolved),\n );\n if (parsed.errors.length === 0) return parsed;\n for (const e of parsed.errors) {\n input.errors.push({ file: e.file?.fileName ?? \"tsconfig\", message: String(e.messageText) });\n }\n return null;\n}\n\nfunction collectToolSpecsFromProgram(input: {\n program: ts.Program;\n typeChecker: ts.TypeChecker;\n projectPath: string;\n warnings: Array<{ file: string; message: string }>;\n configFileSet: Set<string>;\n specs: FunctionToolSpec[];\n}): void {\n for (const sourceFile of input.program.getSourceFiles()) {\n const fileName = sourceFile.fileName;\n if (fileName.includes(\"node_modules\") || fileName.endsWith(\".d.ts\")) continue;\n if (!input.configFileSet.has(path.resolve(fileName))) continue;\n\n ts.forEachChild(sourceFile, (node) => {\n const spec = toFunctionToolSpec({\n node,\n sourceFile,\n fileName,\n projectPath: input.projectPath,\n typeChecker: input.typeChecker,\n warnings: input.warnings,\n });\n if (spec) input.specs.push(spec);\n });\n }\n}\n\nfunction toFunctionToolSpec(input: {\n node: ts.Node;\n sourceFile: ts.SourceFile;\n fileName: string;\n projectPath: string;\n typeChecker: ts.TypeChecker;\n warnings: Array<{ file: string; message: string }>;\n}): FunctionToolSpec | null {\n const decl = getExportedFunctionDeclaration(input.node, input.sourceFile);\n if (!decl || !decl.name) return null;\n const host = getJSDocHost(decl.func);\n if (!hasToolTag(host)) return null;\n const jsDoc = getJSDocComments(host);\n const description = getDescription(jsDoc);\n if (!description) {\n input.warnings.push({\n file: input.fileName,\n message: `Tool ${decl.name}: missing description, using humanized name`,\n });\n }\n const sideEffect = getEffect(host);\n const onWarn = (msg: string) =>\n input.warnings.push({ file: input.fileName, message: `${decl.name}: ${msg}` });\n const { schema } = buildInputSchemaFromParams(decl.func, input.typeChecker, onWarn);\n const outputSchema = buildOutputSchemaFromReturnType(decl.func, input.typeChecker, onWarn);\n const sourcePath = path.relative(input.projectPath, input.fileName) || path.basename(input.fileName);\n const toolName = pathToToolName(sourcePath, decl.name);\n\n return {\n kind: FUNCTION_KIND,\n name: toolName,\n description: description || humanize(decl.name),\n inputSchema: normalizeInputSchema(schema),\n outputSchema,\n _meta: { hitl: { sideEffect } },\n sourcePath,\n exportName: decl.name,\n };\n}\n\nfunction normalizeInputSchema(schema: unknown): object {\n return Object.keys((schema as { properties?: object }).properties ?? {}).length > 0\n ? (schema as object)\n : { type: \"object\", properties: {} };\n}\n\nfunction resolveGlob(projectPath: string, patterns: string[]): string[] {\n const result: string[] = [];\n const seen = new Set<string>();\n const add = (f: string) => {\n const abs = path.resolve(f);\n if (f.endsWith(\".ts\") && !f.endsWith(\".d.ts\") && !seen.has(abs)) {\n seen.add(abs);\n result.push(abs);\n }\n };\n for (const p of patterns) {\n const full = path.join(projectPath, p);\n if (full.includes(\"*\")) {\n const baseDir = full.replace(/\\*\\*\\/.*$/, \"\").replace(/\\*.*$/, \"\").replace(/\\/?$/, \"\") || \".\";\n const dir = path.resolve(projectPath, baseDir);\n if (fs.existsSync(dir)) walk(dir, add);\n } else {\n const resolved = path.resolve(projectPath, full);\n if (fs.existsSync(resolved)) {\n if (fs.statSync(resolved).isFile()) add(resolved);\n else walk(resolved, add);\n }\n }\n }\n if (result.length > 0) return result;\n const srcDir = path.join(projectPath, \"src\");\n if (fs.existsSync(srcDir)) return walkCollect(srcDir);\n return [];\n}\n\nfunction walkCollect(dir: string): string[] {\n const out: string[] = [];\n walk(dir, (fullPath) => {\n if (fullPath.endsWith(\".ts\") && !fullPath.endsWith(\".d.ts\")) out.push(path.resolve(fullPath));\n });\n return out;\n}\n\nconst SKIP_DIRS = new Set([\"node_modules\", \"generated\", \"dist\"]);\n\nfunction walk(dir: string, visit: (fullPath: string) => void): void {\n try {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const e of entries) {\n const full = path.join(dir, e.name);\n if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(full, visit);\n else if (e.isFile()) visit(full);\n }\n } catch {\n // ignore\n }\n}\n\nfunction getExportedFunctionDeclaration(\n node: ts.Node,\n _sourceFile: ts.SourceFile,\n): { func: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression; name: string } | null {\n if (ts.isFunctionDeclaration(node) && node.name) {\n const exported = (ts.getModifiers(node) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n if (exported) return { func: node, name: node.name.getText() };\n return null;\n }\n if (ts.isVariableStatement(node)) {\n const exported = (ts.getModifiers(node) ?? []).some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n if (!exported) return null;\n for (const decl of node.declarationList.declarations) {\n let init = decl.initializer;\n while (init && (ts.isParenthesizedExpression(init) || ts.isAsExpression(init)))\n init = init.expression;\n if (init && ts.isArrowFunction(init)) {\n const name = (decl.name as ts.Identifier).getText();\n return { func: init, name };\n }\n if (init && ts.isFunctionExpression(init)) {\n const name = (decl.name as ts.Identifier).getText();\n return { func: init, name };\n }\n }\n }\n return null;\n}\n\nfunction getJSDocHost(node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression): ts.Node {\n const parent = node.parent;\n if (ts.isVariableDeclaration(parent)) {\n const gp = parent.parent;\n if (ts.isVariableDeclarationList(gp) && gp.parent && ts.isVariableStatement(gp.parent)) return gp.parent;\n }\n return node as ts.Node;\n}\n\nfunction getJSDocComments(host: ts.Node): ts.JSDoc[] {\n const all = ts.getJSDocCommentsAndTags(host);\n return all.filter((t): t is ts.JSDoc => ts.isJSDoc(t));\n}\n\nfunction hasToolTag(host: ts.Node): boolean {\n const tags = ts.getJSDocTags(host);\n for (const tag of tags) {\n const name = (tag as { tagName?: ts.Identifier }).tagName?.getText() ?? \"\";\n if (name === \"tool\") return true;\n }\n const all = ts.getJSDocCommentsAndTags(host);\n for (const t of all) {\n if (ts.isJSDoc(t)) {\n const full = t.getFullText();\n if (full.includes(TOOL_TAG)) return true;\n }\n }\n return false;\n}\n\nfunction getDescription(jsDocs: ts.JSDoc[]): string {\n for (const doc of jsDocs) {\n const comment = doc.comment;\n if (typeof comment === \"string\") {\n const first = comment.split(/\\n/)[0]?.trim() ?? \"\";\n if (first && !first.startsWith(\"@\")) return first;\n }\n if (Array.isArray(comment)) {\n const first = comment[0];\n if (first && typeof first === \"object\" && \"text\" in first) {\n const t = (first as { text: string }).text.trim();\n if (t && !t.startsWith(\"@\")) return t;\n }\n }\n const full = doc.getFullText();\n const match = full.match(/\\*\\s*@tool\\s+(.+?)(?=\\n|$|\\*\\/)/s);\n if (match?.[1]) return match[1].trim();\n }\n return \"\";\n}\n\nfunction getEffect(host: ts.Node): SideEffect {\n const tags = ts.getJSDocTags(host);\n for (const tag of tags) {\n const name = (tag as { tagName?: ts.Identifier }).tagName?.getText() ?? \"\";\n if (name === \"effect\") {\n const comment = (tag as ts.JSDocUnknownTag).comment;\n const v = (typeof comment === \"string\" ? comment : \"\").trim().toLowerCase();\n if (EFFECT_VALUES.includes(v as SideEffect)) return v as SideEffect;\n }\n }\n const all = ts.getJSDocCommentsAndTags(host);\n for (const t of all) {\n if (ts.isJSDoc(t)) {\n const full = t.getFullText();\n const match = full.match(/\\*\\s*@effect\\s+(\\w+)/);\n if (match && EFFECT_VALUES.includes(match[1] as SideEffect)) return match[1] as SideEffect;\n }\n }\n return \"none\";\n}\n\nfunction humanize(name: string): string {\n return name.replace(/([A-Z])/g, \" $1\").replace(/^./, (s) => s.toUpperCase()).trim();\n}\n\n/** Unified scan: (path, options) → DiscoverToolsResult. */\nexport function scan(\n projectPath: string,\n options: DiscoverToolsOptions = {},\n): Promise<DiscoverToolsResult> {\n const root = path.resolve(projectPath);\n const result = scanForTools({\n projectPath: root,\n include: options.include ?? [\"**/*.ts\"],\n tsconfigPath: options.tsconfigPath,\n });\n const specs = result.specs.map((s) => mcpSpecToToolSpec(s, root));\n return Promise.resolve({\n specs,\n errors: result.errors,\n warnings: result.warnings,\n });\n}\n"]}