@dommaker/harness 0.19.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/bin/harness.js +136 -557
  3. package/dist/cli/commands/check.d.ts.map +1 -1
  4. package/dist/cli/commands/check.js +2 -13
  5. package/dist/cli/commands/check.js.map +1 -1
  6. package/dist/cli/commands/definitions.d.ts +90 -0
  7. package/dist/cli/commands/definitions.d.ts.map +1 -0
  8. package/dist/cli/commands/definitions.js +519 -0
  9. package/dist/cli/commands/definitions.js.map +1 -0
  10. package/dist/cli/commands/knowledge.js.map +1 -1
  11. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -25
  12. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
  13. package/dist/cli/commands/sync-docs/capabilities-syncer.js +3 -93
  14. package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
  15. package/dist/cli/commands/sync-docs/index.d.ts +1 -1
  16. package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
  17. package/dist/cli/commands/sync-docs/index.js +4 -4
  18. package/dist/cli/commands/sync-docs/index.js.map +1 -1
  19. package/dist/context/index.d.ts +1 -5
  20. package/dist/context/index.d.ts.map +1 -1
  21. package/dist/context/index.js +1 -5
  22. package/dist/context/index.js.map +1 -1
  23. package/dist/context/knowledge-injector.d.ts +3 -3
  24. package/dist/context/knowledge-injector.d.ts.map +1 -1
  25. package/dist/context/knowledge-injector.js +1 -1
  26. package/dist/context/session-manager.d.ts +1 -12
  27. package/dist/context/session-manager.d.ts.map +1 -1
  28. package/dist/context/session-manager.js +0 -63
  29. package/dist/context/session-manager.js.map +1 -1
  30. package/dist/context/types.d.ts +1 -39
  31. package/dist/context/types.d.ts.map +1 -1
  32. package/dist/context/types.js +2 -15
  33. package/dist/context/types.js.map +1 -1
  34. package/dist/core/constraints/agent-prompt-renderer.d.ts +1 -1
  35. package/dist/core/constraints/agent-prompt-renderer.js +1 -1
  36. package/dist/core/constraints/capabilities-parser.d.ts +17 -2
  37. package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
  38. package/dist/core/constraints/capabilities-parser.js +84 -2
  39. package/dist/core/constraints/capabilities-parser.js.map +1 -1
  40. package/dist/core/constraints/checker.d.ts +3 -17
  41. package/dist/core/constraints/checker.d.ts.map +1 -1
  42. package/dist/core/constraints/checker.js +7 -47
  43. package/dist/core/constraints/checker.js.map +1 -1
  44. package/dist/core/constraints/definitions.d.ts +0 -7
  45. package/dist/core/constraints/definitions.d.ts.map +1 -1
  46. package/dist/core/constraints/definitions.js +1 -8
  47. package/dist/core/constraints/definitions.js.map +1 -1
  48. package/dist/core/constraints/doc-freshness/runner.d.ts +0 -2
  49. package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
  50. package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
  51. package/dist/core/constraints/index.d.ts +1 -1
  52. package/dist/core/constraints/index.d.ts.map +1 -1
  53. package/dist/core/constraints/index.js +2 -3
  54. package/dist/core/constraints/index.js.map +1 -1
  55. package/dist/core/constraints/interceptor.d.ts.map +1 -1
  56. package/dist/core/constraints/interceptor.js +1 -5
  57. package/dist/core/constraints/interceptor.js.map +1 -1
  58. package/dist/core/effective-constraints.d.ts.map +1 -1
  59. package/dist/core/effective-constraints.js +0 -1
  60. package/dist/core/effective-constraints.js.map +1 -1
  61. package/dist/core/project-config-loader.d.ts.map +1 -1
  62. package/dist/core/project-config-loader.js +1 -8
  63. package/dist/core/project-config-loader.js.map +1 -1
  64. package/dist/dashboard/stats.d.ts.map +1 -1
  65. package/dist/dashboard/stats.js.map +1 -1
  66. package/dist/dashboard/types.d.ts +2 -2
  67. package/dist/dashboard/types.d.ts.map +1 -1
  68. package/dist/failure/constraint-handler.d.ts.map +1 -1
  69. package/dist/failure/constraint-handler.js +0 -2
  70. package/dist/failure/constraint-handler.js.map +1 -1
  71. package/dist/gates/acceptance.d.ts +9 -1
  72. package/dist/gates/acceptance.d.ts.map +1 -1
  73. package/dist/gates/acceptance.js +21 -0
  74. package/dist/gates/acceptance.js.map +1 -1
  75. package/dist/gates/checker-gate.d.ts +23 -0
  76. package/dist/gates/checker-gate.d.ts.map +1 -0
  77. package/dist/gates/checker-gate.js +53 -0
  78. package/dist/gates/checker-gate.js.map +1 -0
  79. package/dist/gates/command.d.ts +9 -2
  80. package/dist/gates/command.d.ts.map +1 -1
  81. package/dist/gates/command.js +10 -0
  82. package/dist/gates/command.js.map +1 -1
  83. package/dist/gates/contract.d.ts +8 -2
  84. package/dist/gates/contract.d.ts.map +1 -1
  85. package/dist/gates/contract.js +9 -0
  86. package/dist/gates/contract.js.map +1 -1
  87. package/dist/gates/decision.d.ts +17 -0
  88. package/dist/gates/decision.d.ts.map +1 -0
  89. package/dist/gates/decision.js +25 -0
  90. package/dist/gates/decision.js.map +1 -0
  91. package/dist/gates/definitions.d.ts +63 -0
  92. package/dist/gates/definitions.d.ts.map +1 -0
  93. package/dist/gates/definitions.js +160 -0
  94. package/dist/gates/definitions.js.map +1 -0
  95. package/dist/gates/effective-gates.d.ts +30 -0
  96. package/dist/gates/effective-gates.d.ts.map +1 -0
  97. package/dist/gates/effective-gates.js +85 -0
  98. package/dist/gates/effective-gates.js.map +1 -0
  99. package/dist/gates/index.d.ts +25 -1
  100. package/dist/gates/index.d.ts.map +1 -1
  101. package/dist/gates/index.js +37 -1
  102. package/dist/gates/index.js.map +1 -1
  103. package/dist/gates/performance.d.ts +8 -2
  104. package/dist/gates/performance.d.ts.map +1 -1
  105. package/dist/gates/performance.js +9 -0
  106. package/dist/gates/performance.js.map +1 -1
  107. package/dist/gates/registry.d.ts +32 -0
  108. package/dist/gates/registry.d.ts.map +1 -0
  109. package/dist/gates/registry.js +90 -0
  110. package/dist/gates/registry.js.map +1 -0
  111. package/dist/gates/review.d.ts +8 -2
  112. package/dist/gates/review.d.ts.map +1 -1
  113. package/dist/gates/review.js +9 -0
  114. package/dist/gates/review.js.map +1 -1
  115. package/dist/gates/runner.d.ts +30 -0
  116. package/dist/gates/runner.d.ts.map +1 -0
  117. package/dist/gates/runner.js +38 -0
  118. package/dist/gates/runner.js.map +1 -0
  119. package/dist/gates/security.d.ts +8 -2
  120. package/dist/gates/security.d.ts.map +1 -1
  121. package/dist/gates/security.js +9 -0
  122. package/dist/gates/security.js.map +1 -1
  123. package/dist/gates/types.d.ts +41 -1
  124. package/dist/gates/types.d.ts.map +1 -1
  125. package/dist/hooks/bootstrap.d.ts.map +1 -1
  126. package/dist/hooks/bootstrap.js +0 -2
  127. package/dist/hooks/bootstrap.js.map +1 -1
  128. package/dist/hooks/config.d.ts +26 -0
  129. package/dist/hooks/config.d.ts.map +1 -0
  130. package/dist/hooks/config.js +30 -0
  131. package/dist/hooks/config.js.map +1 -0
  132. package/dist/hooks/index.d.ts +2 -1
  133. package/dist/hooks/index.d.ts.map +1 -1
  134. package/dist/hooks/index.js +4 -1
  135. package/dist/hooks/index.js.map +1 -1
  136. package/dist/hooks/registry.d.ts +18 -1
  137. package/dist/hooks/registry.d.ts.map +1 -1
  138. package/dist/hooks/registry.js +45 -0
  139. package/dist/hooks/registry.js.map +1 -1
  140. package/dist/hooks/types.d.ts +20 -0
  141. package/dist/hooks/types.d.ts.map +1 -1
  142. package/dist/index.d.ts +4 -8
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +5 -20
  145. package/dist/index.js.map +1 -1
  146. package/dist/knowledge/import.d.ts +2 -2
  147. package/dist/knowledge/import.d.ts.map +1 -1
  148. package/dist/knowledge/ingest.js.map +1 -1
  149. package/dist/knowledge/lifecycle-hooks.d.ts +2 -2
  150. package/dist/knowledge/lifecycle-hooks.d.ts.map +1 -1
  151. package/dist/knowledge/types.d.ts +5 -7
  152. package/dist/knowledge/types.d.ts.map +1 -1
  153. package/dist/knowledge/types.js +1 -1
  154. package/dist/knowledge/types.js.map +1 -1
  155. package/dist/monitoring/constraint-doctor.d.ts +4 -22
  156. package/dist/monitoring/constraint-doctor.d.ts.map +1 -1
  157. package/dist/monitoring/constraint-doctor.js +7 -94
  158. package/dist/monitoring/constraint-doctor.js.map +1 -1
  159. package/dist/presets/standard.d.ts +1 -1
  160. package/dist/presets/standard.d.ts.map +1 -1
  161. package/dist/presets/standard.js +1 -2
  162. package/dist/presets/standard.js.map +1 -1
  163. package/dist/spec/annotation-checker.d.ts.map +1 -1
  164. package/dist/spec/annotation-checker.js +6 -26
  165. package/dist/spec/annotation-checker.js.map +1 -1
  166. package/dist/tools/index.d.ts +0 -4
  167. package/dist/tools/index.d.ts.map +1 -1
  168. package/dist/tools/index.js +0 -4
  169. package/dist/tools/index.js.map +1 -1
  170. package/dist/types/constraint.d.ts +1 -12
  171. package/dist/types/constraint.d.ts.map +1 -1
  172. package/dist/types/constraint.js +0 -3
  173. package/dist/types/constraint.js.map +1 -1
  174. package/dist/types/project-config.d.ts +0 -2
  175. package/dist/types/project-config.d.ts.map +1 -1
  176. package/dist/utils/file-walk.d.ts +2 -2
  177. package/dist/utils/file-walk.js +2 -2
  178. package/package.json +6 -1
  179. package/src/CONTEXT.md +14 -0
  180. package/src/__tests__/checker-extra.test.ts +2 -59
  181. package/src/__tests__/constraint-doctor.test.ts +1 -140
  182. package/src/__tests__/constraint-handler.test.ts +0 -4
  183. package/src/__tests__/project-config-loader-extra.test.ts +0 -20
  184. package/src/__tests__/project-config-loader.test.ts +0 -1
  185. package/src/cli/commands/CONTEXT.md +15 -7
  186. package/src/cli/commands/__tests__/check-drift.test.ts +0 -3
  187. package/src/cli/commands/__tests__/check-skip-output.test.ts +0 -5
  188. package/src/cli/commands/__tests__/check.test.ts +7 -75
  189. package/src/cli/commands/__tests__/registry.test.ts +201 -0
  190. package/src/cli/commands/check.ts +2 -14
  191. package/src/cli/commands/definitions.ts +593 -0
  192. package/src/cli/commands/knowledge.ts +3 -3
  193. package/src/cli/commands/sync-docs/capabilities-syncer.ts +4 -110
  194. package/src/cli/commands/sync-docs/index.ts +8 -5
  195. package/src/context/CONTEXT.md +2 -7
  196. package/src/context/__tests__/session-manager.test.ts +0 -91
  197. package/src/context/index.ts +1 -5
  198. package/src/context/knowledge-injector.ts +3 -3
  199. package/src/context/session-manager.ts +0 -74
  200. package/src/context/types.ts +2 -63
  201. package/src/core/constraints/__tests__/interceptor.test.ts +0 -2
  202. package/src/core/constraints/agent-prompt-renderer.ts +1 -1
  203. package/src/core/constraints/capabilities-parser.ts +95 -2
  204. package/src/core/constraints/checker.ts +8 -53
  205. package/src/core/constraints/definitions.ts +0 -8
  206. package/src/core/constraints/doc-freshness/runner.ts +1 -2
  207. package/src/core/constraints/index.ts +1 -2
  208. package/src/core/constraints/interceptor.ts +1 -6
  209. package/src/core/effective-constraints.ts +0 -1
  210. package/src/core/project-config-loader.ts +1 -7
  211. package/src/dashboard/stats.ts +2 -2
  212. package/src/dashboard/types.ts +2 -2
  213. package/src/failure/constraint-handler.ts +0 -2
  214. package/src/gates/CONTEXT.md +16 -13
  215. package/src/gates/__tests__/checker-gate.test.ts +45 -0
  216. package/src/gates/__tests__/contract.test.ts +73 -0
  217. package/src/gates/__tests__/effective-gates.test.ts +82 -0
  218. package/src/gates/__tests__/gate-interface.test.ts +202 -0
  219. package/src/gates/__tests__/registry.test.ts +87 -0
  220. package/src/gates/__tests__/runner.test.ts +81 -0
  221. package/src/gates/acceptance.ts +24 -1
  222. package/src/gates/checker-gate.ts +54 -0
  223. package/src/gates/command.ts +13 -2
  224. package/src/gates/contract.ts +12 -2
  225. package/src/gates/decision.ts +27 -0
  226. package/src/gates/definitions.ts +207 -0
  227. package/src/gates/effective-gates.ts +106 -0
  228. package/src/gates/index.ts +38 -0
  229. package/src/gates/performance.ts +12 -2
  230. package/src/gates/registry.ts +107 -0
  231. package/src/gates/review.ts +12 -2
  232. package/src/gates/runner.ts +57 -0
  233. package/src/gates/security.ts +12 -2
  234. package/src/gates/types.ts +48 -1
  235. package/src/hooks/CONTEXT.md +12 -2
  236. package/src/hooks/__tests__/bootstrap.test.ts +0 -1
  237. package/src/hooks/__tests__/config.test.ts +19 -0
  238. package/src/hooks/__tests__/pipeline.test.ts +79 -0
  239. package/src/hooks/__tests__/registry.test.ts +67 -0
  240. package/src/hooks/bootstrap.ts +0 -2
  241. package/src/hooks/config.ts +29 -0
  242. package/src/hooks/index.ts +2 -1
  243. package/src/hooks/registry.ts +60 -1
  244. package/src/hooks/types.ts +21 -0
  245. package/src/index.ts +5 -22
  246. package/src/knowledge/import.ts +3 -3
  247. package/src/knowledge/ingest.ts +4 -4
  248. package/src/knowledge/lifecycle-hooks.ts +3 -3
  249. package/src/knowledge/types.ts +5 -8
  250. package/src/monitoring/constraint-doctor.ts +7 -106
  251. package/src/presets/__tests__/standard.test.ts +0 -2
  252. package/src/presets/standard.ts +1 -2
  253. package/src/spec/__tests__/annotation-checker.test.ts +9 -3
  254. package/src/spec/annotation-checker.ts +7 -29
  255. package/src/tools/CONTEXT.md +7 -14
  256. package/src/tools/index.ts +0 -4
  257. package/src/types/constraint.ts +1 -14
  258. package/src/types/project-config.ts +0 -3
  259. package/src/utils/file-walk.ts +2 -2
  260. package/dist/architecture/constraint-engine.d.ts +0 -67
  261. package/dist/architecture/constraint-engine.d.ts.map +0 -1
  262. package/dist/architecture/constraint-engine.js +0 -295
  263. package/dist/architecture/constraint-engine.js.map +0 -1
  264. package/dist/architecture/cross-project-checker.d.ts +0 -54
  265. package/dist/architecture/cross-project-checker.d.ts.map +0 -1
  266. package/dist/architecture/cross-project-checker.js +0 -467
  267. package/dist/architecture/cross-project-checker.js.map +0 -1
  268. package/dist/cli/commands/index.d.ts +0 -30
  269. package/dist/cli/commands/index.d.ts.map +0 -1
  270. package/dist/cli/commands/index.js +0 -91
  271. package/dist/cli/commands/index.js.map +0 -1
  272. package/dist/context/file-budget.d.ts +0 -40
  273. package/dist/context/file-budget.d.ts.map +0 -1
  274. package/dist/context/file-budget.js +0 -147
  275. package/dist/context/file-budget.js.map +0 -1
  276. package/dist/context/progressive-loader.d.ts +0 -109
  277. package/dist/context/progressive-loader.d.ts.map +0 -1
  278. package/dist/context/progressive-loader.js +0 -166
  279. package/dist/context/progressive-loader.js.map +0 -1
  280. package/dist/context/token-pipeline.d.ts +0 -55
  281. package/dist/context/token-pipeline.d.ts.map +0 -1
  282. package/dist/context/token-pipeline.js +0 -220
  283. package/dist/context/token-pipeline.js.map +0 -1
  284. package/dist/context/tool-output-budget.d.ts +0 -59
  285. package/dist/context/tool-output-budget.d.ts.map +0 -1
  286. package/dist/context/tool-output-budget.js +0 -177
  287. package/dist/context/tool-output-budget.js.map +0 -1
  288. package/dist/core/constraints/default-executors.d.ts +0 -10
  289. package/dist/core/constraints/default-executors.d.ts.map +0 -1
  290. package/dist/core/constraints/default-executors.js +0 -120
  291. package/dist/core/constraints/default-executors.js.map +0 -1
  292. package/dist/llm/adapter.d.ts +0 -36
  293. package/dist/llm/adapter.d.ts.map +0 -1
  294. package/dist/llm/adapter.js +0 -118
  295. package/dist/llm/adapter.js.map +0 -1
  296. package/dist/llm/index.d.ts +0 -3
  297. package/dist/llm/index.d.ts.map +0 -1
  298. package/dist/llm/index.js +0 -19
  299. package/dist/llm/index.js.map +0 -1
  300. package/dist/llm/types.d.ts +0 -62
  301. package/dist/llm/types.d.ts.map +0 -1
  302. package/dist/llm/types.js +0 -8
  303. package/dist/llm/types.js.map +0 -1
  304. package/dist/tools/core/index.d.ts +0 -13
  305. package/dist/tools/core/index.d.ts.map +0 -1
  306. package/dist/tools/core/index.js +0 -198
  307. package/dist/tools/core/index.js.map +0 -1
  308. package/dist/tools/loader.d.ts +0 -21
  309. package/dist/tools/loader.d.ts.map +0 -1
  310. package/dist/tools/loader.js +0 -199
  311. package/dist/tools/loader.js.map +0 -1
  312. package/dist/tools/registry.d.ts +0 -59
  313. package/dist/tools/registry.d.ts.map +0 -1
  314. package/dist/tools/registry.js +0 -115
  315. package/dist/tools/registry.js.map +0 -1
  316. package/dist/tools/types.d.ts +0 -38
  317. package/dist/tools/types.d.ts.map +0 -1
  318. package/dist/tools/types.js +0 -6
  319. package/dist/tools/types.js.map +0 -1
  320. package/src/__tests__/architecture-engine.test.ts +0 -619
  321. package/src/__tests__/context/progressive-loader.test.ts +0 -131
  322. package/src/__tests__/cross-project-checker.test.ts +0 -318
  323. package/src/architecture/CONTEXT.md +0 -22
  324. package/src/architecture/constraint-engine.ts +0 -351
  325. package/src/architecture/cross-project-checker.ts +0 -545
  326. package/src/cli/commands/index.ts +0 -30
  327. package/src/context/__tests__/file-budget.test.ts +0 -142
  328. package/src/context/__tests__/progressive-loader.test.ts +0 -264
  329. package/src/context/__tests__/token-pipeline.test.ts +0 -178
  330. package/src/context/__tests__/tool-output-budget.test.ts +0 -95
  331. package/src/context/file-budget.ts +0 -142
  332. package/src/context/progressive-loader.ts +0 -260
  333. package/src/context/token-pipeline.ts +0 -265
  334. package/src/context/tool-output-budget.ts +0 -178
  335. package/src/core/constraints/__tests__/default-executors.test.ts +0 -57
  336. package/src/core/constraints/default-executors.ts +0 -92
  337. package/src/llm/CONTEXT.md +0 -21
  338. package/src/llm/__tests__/adapter.test.ts +0 -172
  339. package/src/llm/adapter.ts +0 -149
  340. package/src/llm/index.ts +0 -2
  341. package/src/llm/types.ts +0 -81
  342. package/src/tools/__tests__/loader.test.ts +0 -252
  343. package/src/tools/__tests__/registry.test.ts +0 -157
  344. package/src/tools/core/__tests__/core.test.ts +0 -122
  345. package/src/tools/core/index.ts +0 -201
  346. package/src/tools/loader.ts +0 -216
  347. package/src/tools/registry.ts +0 -128
  348. package/src/tools/types.ts +0 -46
@@ -1,201 +0,0 @@
1
- /**
2
- * 核心工具定义
3
- *
4
- * 内置工具:file / git / npm / shell
5
- */
6
-
7
- import type { ToolDefinition } from '../types';
8
-
9
- export const FILE_TOOLS: ToolDefinition[] = [
10
- {
11
- id: 'read_file',
12
- name: 'Read File',
13
- description: '读取文件内容',
14
- category: 'core',
15
- parameters: {
16
- type: 'object',
17
- properties: {
18
- path: { type: 'string', description: '文件路径' },
19
- offset: { type: 'number', description: '起始行号' },
20
- limit: { type: 'number', description: '读取行数' },
21
- },
22
- required: ['path'],
23
- },
24
- sandboxLevel: 1,
25
- },
26
- {
27
- id: 'write_file',
28
- name: 'Write File',
29
- description: '写入文件内容',
30
- category: 'core',
31
- parameters: {
32
- type: 'object',
33
- properties: {
34
- path: { type: 'string', description: '文件路径' },
35
- content: { type: 'string', description: '文件内容' },
36
- },
37
- required: ['path', 'content'],
38
- },
39
- sandboxLevel: 3,
40
- },
41
- {
42
- id: 'edit_file',
43
- name: 'Edit File',
44
- description: '编辑文件(精确替换)',
45
- category: 'core',
46
- parameters: {
47
- type: 'object',
48
- properties: {
49
- path: { type: 'string', description: '文件路径' },
50
- old_string: { type: 'string', description: '要替换的文本' },
51
- new_string: { type: 'string', description: '替换后的文本' },
52
- },
53
- required: ['path', 'old_string', 'new_string'],
54
- },
55
- sandboxLevel: 3,
56
- },
57
- {
58
- id: 'list_directory',
59
- name: 'List Directory',
60
- description: '列出目录内容',
61
- category: 'core',
62
- parameters: {
63
- type: 'object',
64
- properties: {
65
- path: { type: 'string', description: '目录路径' },
66
- },
67
- required: ['path'],
68
- },
69
- sandboxLevel: 1,
70
- },
71
- ];
72
-
73
- export const GIT_TOOLS: ToolDefinition[] = [
74
- {
75
- id: 'git_status',
76
- name: 'Git Status',
77
- description: '查看 git 工作区状态',
78
- category: 'core',
79
- parameters: { type: 'object', properties: {} },
80
- sandboxLevel: 1,
81
- },
82
- {
83
- id: 'git_diff',
84
- name: 'Git Diff',
85
- description: '查看 git 差异',
86
- category: 'core',
87
- parameters: {
88
- type: 'object',
89
- properties: {
90
- staged: { type: 'boolean', description: '是否查看暂存区' },
91
- file: { type: 'string', description: '指定文件' },
92
- },
93
- },
94
- sandboxLevel: 1,
95
- },
96
- {
97
- id: 'git_commit',
98
- name: 'Git Commit',
99
- description: '创建 git 提交',
100
- category: 'core',
101
- parameters: {
102
- type: 'object',
103
- properties: {
104
- message: { type: 'string', description: '提交信息' },
105
- files: { type: 'array', items: { type: 'string' }, description: '要提交的文件' },
106
- },
107
- required: ['message'],
108
- },
109
- sandboxLevel: 3,
110
- requiresConfirmation: true,
111
- },
112
- {
113
- id: 'git_log',
114
- name: 'Git Log',
115
- description: '查看 git 提交历史',
116
- category: 'core',
117
- parameters: {
118
- type: 'object',
119
- properties: {
120
- limit: { type: 'number', description: '显示条数' },
121
- file: { type: 'string', description: '指定文件' },
122
- },
123
- },
124
- sandboxLevel: 1,
125
- },
126
- ];
127
-
128
- export const NPM_TOOLS: ToolDefinition[] = [
129
- {
130
- id: 'npm_install',
131
- name: 'NPM Install',
132
- description: '安装依赖',
133
- category: 'core',
134
- parameters: {
135
- type: 'object',
136
- properties: {
137
- packages: { type: 'array', items: { type: 'string' }, description: '包名列表' },
138
- dev: { type: 'boolean', description: '是否为开发依赖' },
139
- },
140
- },
141
- sandboxLevel: 3,
142
- rateLimit: 10,
143
- },
144
- {
145
- id: 'npm_run',
146
- name: 'NPM Run',
147
- description: '执行 npm 脚本',
148
- category: 'core',
149
- parameters: {
150
- type: 'object',
151
- properties: {
152
- script: { type: 'string', description: '脚本名称' },
153
- args: { type: 'array', items: { type: 'string' }, description: '参数' },
154
- },
155
- required: ['script'],
156
- },
157
- sandboxLevel: 3,
158
- },
159
- {
160
- id: 'npm_test',
161
- name: 'NPM Test',
162
- description: '运行测试',
163
- category: 'core',
164
- parameters: {
165
- type: 'object',
166
- properties: {
167
- pattern: { type: 'string', description: '测试文件匹配模式' },
168
- coverage: { type: 'boolean', description: '是否生成覆盖率报告' },
169
- },
170
- },
171
- sandboxLevel: 3,
172
- },
173
- ];
174
-
175
- export const SHELL_TOOLS: ToolDefinition[] = [
176
- {
177
- id: 'shell_exec',
178
- name: 'Shell Execute',
179
- description: '执行 shell 命令',
180
- category: 'core',
181
- parameters: {
182
- type: 'object',
183
- properties: {
184
- command: { type: 'string', description: '命令' },
185
- cwd: { type: 'string', description: '工作目录' },
186
- timeout: { type: 'number', description: '超时(ms)' },
187
- },
188
- required: ['command'],
189
- },
190
- sandboxLevel: 3,
191
- rateLimit: 30,
192
- },
193
- ];
194
-
195
- /** 所有核心工具 */
196
- export const CORE_TOOLS: ToolDefinition[] = [
197
- ...FILE_TOOLS,
198
- ...GIT_TOOLS,
199
- ...NPM_TOOLS,
200
- ...SHELL_TOOLS,
201
- ];
@@ -1,216 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as yaml from 'js-yaml';
4
- import { ToolDefinition, ToolCategory } from './types';
5
-
6
- // Maps the type strings found in tool YAMLs to JSON Schema types
7
- const TYPE_MAP: Record<string, string> = {
8
- string: 'string',
9
- path: 'string',
10
- integer: 'integer',
11
- number: 'number',
12
- boolean: 'boolean',
13
- array: 'array',
14
- object: 'object',
15
- };
16
-
17
- interface RawToolYaml {
18
- id?: string;
19
- name?: string;
20
- description?: string;
21
- category?: string;
22
- stage?: string;
23
- input?: Record<string, {
24
- type?: string;
25
- required?: boolean;
26
- description?: string;
27
- default?: unknown;
28
- items?: unknown;
29
- enum?: unknown[];
30
- }>;
31
- inputs?: Array<{
32
- name: string;
33
- type?: string;
34
- required?: boolean;
35
- description?: string;
36
- default?: unknown;
37
- }> | Record<string, {
38
- type?: string;
39
- required?: boolean;
40
- description?: string;
41
- default?: unknown;
42
- }>;
43
- output?: unknown;
44
- outputs?: unknown;
45
- script?: string;
46
- prompt?: string;
47
- agent?: string;
48
- tools?: unknown;
49
- execute?: unknown;
50
- handler?: string;
51
- temperature?: number;
52
- timeout?: number;
53
- }
54
-
55
- function buildJsonSchema(params: Record<string, { type?: string; required?: boolean; description?: string; default?: unknown; items?: unknown; enum?: unknown[] }>): Record<string, unknown> {
56
- const properties: Record<string, unknown> = {};
57
- const required: string[] = [];
58
-
59
- for (const [key, def] of Object.entries(params)) {
60
- const prop: Record<string, unknown> = {};
61
- const schemaType = TYPE_MAP[def.type ?? 'string'] ?? 'string';
62
- prop.type = schemaType;
63
- if (def.description) prop.description = def.description;
64
- if (def.default !== undefined) prop.default = def.default;
65
- if (def.items) prop.items = def.items;
66
- if (def.enum) prop.enum = def.enum;
67
- properties[key] = prop;
68
- if (def.required) required.push(key);
69
- }
70
-
71
- const schema: Record<string, unknown> = {
72
- type: 'object',
73
- properties,
74
- };
75
- if (required.length > 0) schema.required = required;
76
- return schema;
77
- }
78
-
79
- function normalizeInputs(raw: RawToolYaml): Record<string, { type?: string; required?: boolean; description?: string; default?: unknown; items?: unknown; enum?: unknown[] }> {
80
- // Pattern A: `input` is a map (core/ext tools)
81
- if (raw.input && typeof raw.input === 'object' && !Array.isArray(raw.input)) {
82
- return raw.input;
83
- }
84
-
85
- // Pattern B: `inputs` is a list (some std tools)
86
- if (Array.isArray(raw.inputs)) {
87
- const result: Record<string, { type?: string; required?: boolean; description?: string; default?: unknown }> = {};
88
- for (const item of raw.inputs) {
89
- if (item.name) {
90
- result[item.name] = {
91
- type: item.type,
92
- required: item.required,
93
- description: item.description,
94
- default: item.default,
95
- };
96
- }
97
- }
98
- return result;
99
- }
100
-
101
- // Pattern C: `inputs` is a map (some std tools)
102
- if (raw.inputs && typeof raw.inputs === 'object' && !Array.isArray(raw.inputs)) {
103
- return raw.inputs as Record<string, { type?: string; required?: boolean; description?: string; default?: unknown }>;
104
- }
105
-
106
- return {};
107
- }
108
-
109
- function deriveToolId(filePath: string, definitionsDir: string): string {
110
- // Convert file path to ID: definitions/std/quick/implement.yml → std/quick/implement
111
- const relative = path.relative(definitionsDir, filePath);
112
- const withoutExt = relative.replace(/\.yml$/, '').replace(/\.yaml$/, '');
113
- return withoutExt;
114
- }
115
-
116
- function detectCategory(filePath: string, definitionsDir: string): ToolCategory {
117
- const relative = path.relative(definitionsDir, filePath);
118
- const topDir = relative.split(path.sep)[0];
119
- if (topDir === 'core') return 'core';
120
- if (topDir === 'ext') return 'ext';
121
- return 'std';
122
- }
123
-
124
- /**
125
- * Parse a single YAML file into a ToolDefinition.
126
- */
127
- export function parseToolYaml(yamlContent: string, filePath: string, definitionsDir: string): ToolDefinition {
128
- const raw = yaml.load(yamlContent) as RawToolYaml;
129
-
130
- const id = raw.id || deriveToolId(filePath, definitionsDir);
131
- const name = raw.name || id;
132
- const description = raw.description || '';
133
- const category = detectCategory(filePath, definitionsDir);
134
- const params = normalizeInputs(raw);
135
- const parameters = buildJsonSchema(params);
136
-
137
- const def: ToolDefinition = {
138
- id,
139
- name,
140
- description,
141
- category,
142
- parameters,
143
- };
144
-
145
- return def;
146
- }
147
-
148
- /**
149
- * Scan a directory recursively for .yml/.yaml files and return all file paths.
150
- */
151
- function findYamlFiles(dir: string): string[] {
152
- const results: string[] = [];
153
- if (!fs.existsSync(dir)) return results;
154
-
155
- const entries = fs.readdirSync(dir, { withFileTypes: true });
156
- for (const entry of entries) {
157
- const fullPath = path.join(dir, entry.name);
158
- if (entry.isDirectory()) {
159
- results.push(...findYamlFiles(fullPath));
160
- } else if (entry.isFile() && (entry.name.endsWith('.yml') || entry.name.endsWith('.yaml'))) {
161
- results.push(fullPath);
162
- }
163
- }
164
- return results;
165
- }
166
-
167
- /**
168
- * Load all tool definitions from the definitions directory (core/, std/, ext/).
169
- */
170
- export function loadToolsFromDir(definitionsDir: string): ToolDefinition[] {
171
- const tools: ToolDefinition[] = [];
172
-
173
- for (const category of ['core', 'std', 'ext'] as ToolCategory[]) {
174
- const categoryDir = path.join(definitionsDir, category);
175
- const yamlFiles = findYamlFiles(categoryDir);
176
-
177
- for (const filePath of yamlFiles) {
178
- try {
179
- const content = fs.readFileSync(filePath, 'utf-8');
180
- const tool = parseToolYaml(content, filePath, definitionsDir);
181
- tools.push(tool);
182
- } catch (err) {
183
- // Skip files that fail to parse
184
- console.warn(`[harness] Failed to load tool YAML: ${filePath}`, err);
185
- }
186
- }
187
- }
188
-
189
- return tools;
190
- }
191
-
192
- /**
193
- * Load the registry.json and fix absolute paths to relative (from definitions dir).
194
- * Filters out workflow entries, keeping only tool entries.
195
- */
196
- export function loadRegistry(registryPath: string): Array<{
197
- name: string;
198
- category: string;
199
- type: string;
200
- description: string;
201
- path: string;
202
- }> {
203
- const content = fs.readFileSync(registryPath, 'utf-8');
204
- const registry = JSON.parse(content);
205
- const definitionsDir = path.dirname(registryPath);
206
-
207
- if (!Array.isArray(registry.tools)) return [];
208
-
209
- return registry.tools
210
- .filter((entry: { type?: string }) => entry.type === 'tool')
211
- .map((entry: { name: string; category: string; type: string; description: string; path: string }) => ({
212
- ...entry,
213
- // Fix absolute paths to relative (from definitions dir); keep already-relative paths as-is
214
- path: path.isAbsolute(entry.path) ? path.relative(definitionsDir, entry.path) : entry.path,
215
- }));
216
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * 工具注册表
3
- *
4
- * 工具注册/发现/执行
5
- */
6
-
7
- import type { ToolDefinition, ToolCategory, ToolResult } from './types';
8
-
9
- export class ToolRegistry {
10
- private tools: Map<string, ToolDefinition>;
11
-
12
- constructor() {
13
- this.tools = new Map();
14
- }
15
-
16
- /**
17
- * 注册工具
18
- */
19
- register(tool: ToolDefinition): void {
20
- this.tools.set(tool.id, tool);
21
- }
22
-
23
- /**
24
- * 批量注册
25
- */
26
- registerAll(tools: ToolDefinition[]): void {
27
- for (const tool of tools) {
28
- this.register(tool);
29
- }
30
- }
31
-
32
- /**
33
- * 获取工具
34
- */
35
- get(id: string): ToolDefinition | undefined {
36
- return this.tools.get(id);
37
- }
38
-
39
- /**
40
- * 获取所有工具
41
- */
42
- getAll(): ToolDefinition[] {
43
- return Array.from(this.tools.values());
44
- }
45
-
46
- /**
47
- * 按分类获取
48
- */
49
- getByCategory(category: ToolCategory): ToolDefinition[] {
50
- return this.getAll().filter(t => t.category === category);
51
- }
52
-
53
- /**
54
- * 搜索工具(名称/描述模糊匹配)
55
- */
56
- search(query: string): ToolDefinition[] {
57
- const lower = query.toLowerCase();
58
- return this.getAll().filter(t =>
59
- t.name.toLowerCase().includes(lower) ||
60
- t.description.toLowerCase().includes(lower) ||
61
- t.id.toLowerCase().includes(lower),
62
- );
63
- }
64
-
65
- /**
66
- * 执行工具
67
- */
68
- async execute(id: string, params: Record<string, unknown>): Promise<ToolResult> {
69
- const tool = this.tools.get(id);
70
- if (!tool) {
71
- return {
72
- success: false,
73
- output: '',
74
- error: `工具未找到: ${id}`,
75
- };
76
- }
77
-
78
- if (!tool.handler) {
79
- return {
80
- success: false,
81
- output: '',
82
- error: `工具 ${id} 未注册处理函数`,
83
- };
84
- }
85
-
86
- try {
87
- return await tool.handler(params);
88
- } catch (error) {
89
- return {
90
- success: false,
91
- output: '',
92
- error: `工具执行失败: ${error instanceof Error ? error.message : String(error)}`,
93
- };
94
- }
95
- }
96
-
97
- /**
98
- * 移除工具
99
- */
100
- remove(id: string): boolean {
101
- return this.tools.delete(id);
102
- }
103
-
104
- /**
105
- * 工具数量
106
- */
107
- size(): number {
108
- return this.tools.size;
109
- }
110
-
111
- /**
112
- * 检查工具是否存在
113
- */
114
- has(id: string): boolean {
115
- return this.tools.has(id);
116
- }
117
-
118
- /**
119
- * 导出为 tool definitions(用于 LLM function calling)
120
- */
121
- toToolDefinitions(): Array<{ name: string; description: string; parameters: Record<string, unknown> }> {
122
- return this.getAll().map(t => ({
123
- name: t.id,
124
- description: t.description,
125
- parameters: t.parameters,
126
- }));
127
- }
128
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * 工具注册表类型定义
3
- */
4
-
5
- // ── 工具定义 ─────────────────────────────────────────────
6
-
7
- export type ToolCategory = 'core' | 'std' | 'ext';
8
-
9
- export interface ToolDefinition {
10
- /** 工具唯一 ID */
11
- id: string;
12
- /** 工具名称 */
13
- name: string;
14
- /** 工具描述 */
15
- description: string;
16
- /** 工具分类 */
17
- category: ToolCategory;
18
- /** 参数 schema (JSON Schema) */
19
- parameters: Record<string, unknown>;
20
- /** 所需 sandbox 级别 */
21
- sandboxLevel?: 1 | 2 | 3 | 4;
22
- /** 是否需要确认 */
23
- requiresConfirmation?: boolean;
24
- /** 速率限制(每分钟) */
25
- rateLimit?: number;
26
- /** 工具处理函数 */
27
- handler?: ToolHandler;
28
- }
29
-
30
- export type ToolHandler = (params: Record<string, unknown>) => Promise<ToolResult>;
31
-
32
- export interface ToolResult {
33
- success: boolean;
34
- output: string;
35
- error?: string;
36
- metadata?: Record<string, unknown>;
37
- }
38
-
39
- // ── 注册表配置 ───────────────────────────────────────────
40
-
41
- export interface ToolRegistryConfig {
42
- /** 自动注册核心工具 */
43
- autoRegisterCore?: boolean;
44
- /** 工具搜索路径 */
45
- searchPaths?: string[];
46
- }