@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.
- package/CHANGELOG.md +14 -0
- package/bin/harness.js +136 -557
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +2 -13
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +90 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -0
- package/dist/cli/commands/definitions.js +519 -0
- package/dist/cli/commands/definitions.js.map +1 -0
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -25
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +3 -93
- package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +4 -4
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -5
- package/dist/context/index.js.map +1 -1
- package/dist/context/knowledge-injector.d.ts +3 -3
- package/dist/context/knowledge-injector.d.ts.map +1 -1
- package/dist/context/knowledge-injector.js +1 -1
- package/dist/context/session-manager.d.ts +1 -12
- package/dist/context/session-manager.d.ts.map +1 -1
- package/dist/context/session-manager.js +0 -63
- package/dist/context/session-manager.js.map +1 -1
- package/dist/context/types.d.ts +1 -39
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +2 -15
- package/dist/context/types.js.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.d.ts +1 -1
- package/dist/core/constraints/agent-prompt-renderer.js +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +17 -2
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +84 -2
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +3 -17
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +7 -47
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/definitions.d.ts +0 -7
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +1 -8
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.d.ts +0 -2
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/index.d.ts +1 -1
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +2 -3
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/interceptor.d.ts.map +1 -1
- package/dist/core/constraints/interceptor.js +1 -5
- package/dist/core/constraints/interceptor.js.map +1 -1
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +0 -1
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +1 -8
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/dashboard/stats.d.ts.map +1 -1
- package/dist/dashboard/stats.js.map +1 -1
- package/dist/dashboard/types.d.ts +2 -2
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/failure/constraint-handler.d.ts.map +1 -1
- package/dist/failure/constraint-handler.js +0 -2
- package/dist/failure/constraint-handler.js.map +1 -1
- package/dist/gates/acceptance.d.ts +9 -1
- package/dist/gates/acceptance.d.ts.map +1 -1
- package/dist/gates/acceptance.js +21 -0
- package/dist/gates/acceptance.js.map +1 -1
- package/dist/gates/checker-gate.d.ts +23 -0
- package/dist/gates/checker-gate.d.ts.map +1 -0
- package/dist/gates/checker-gate.js +53 -0
- package/dist/gates/checker-gate.js.map +1 -0
- package/dist/gates/command.d.ts +9 -2
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +10 -0
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/contract.d.ts +8 -2
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +9 -0
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/decision.d.ts +17 -0
- package/dist/gates/decision.d.ts.map +1 -0
- package/dist/gates/decision.js +25 -0
- package/dist/gates/decision.js.map +1 -0
- package/dist/gates/definitions.d.ts +63 -0
- package/dist/gates/definitions.d.ts.map +1 -0
- package/dist/gates/definitions.js +160 -0
- package/dist/gates/definitions.js.map +1 -0
- package/dist/gates/effective-gates.d.ts +30 -0
- package/dist/gates/effective-gates.d.ts.map +1 -0
- package/dist/gates/effective-gates.js +85 -0
- package/dist/gates/effective-gates.js.map +1 -0
- package/dist/gates/index.d.ts +25 -1
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +37 -1
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/performance.d.ts +8 -2
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +9 -0
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/registry.d.ts +32 -0
- package/dist/gates/registry.d.ts.map +1 -0
- package/dist/gates/registry.js +90 -0
- package/dist/gates/registry.js.map +1 -0
- package/dist/gates/review.d.ts +8 -2
- package/dist/gates/review.d.ts.map +1 -1
- package/dist/gates/review.js +9 -0
- package/dist/gates/review.js.map +1 -1
- package/dist/gates/runner.d.ts +30 -0
- package/dist/gates/runner.d.ts.map +1 -0
- package/dist/gates/runner.js +38 -0
- package/dist/gates/runner.js.map +1 -0
- package/dist/gates/security.d.ts +8 -2
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +9 -0
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +41 -1
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +0 -2
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/hooks/config.d.ts +26 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +30 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/registry.d.ts +18 -1
- package/dist/hooks/registry.d.ts.map +1 -1
- package/dist/hooks/registry.js +45 -0
- package/dist/hooks/registry.js.map +1 -1
- package/dist/hooks/types.d.ts +20 -0
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -20
- package/dist/index.js.map +1 -1
- package/dist/knowledge/import.d.ts +2 -2
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lifecycle-hooks.d.ts +2 -2
- package/dist/knowledge/lifecycle-hooks.d.ts.map +1 -1
- package/dist/knowledge/types.d.ts +5 -7
- package/dist/knowledge/types.d.ts.map +1 -1
- package/dist/knowledge/types.js +1 -1
- package/dist/knowledge/types.js.map +1 -1
- package/dist/monitoring/constraint-doctor.d.ts +4 -22
- package/dist/monitoring/constraint-doctor.d.ts.map +1 -1
- package/dist/monitoring/constraint-doctor.js +7 -94
- package/dist/monitoring/constraint-doctor.js.map +1 -1
- package/dist/presets/standard.d.ts +1 -1
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +1 -2
- package/dist/presets/standard.js.map +1 -1
- package/dist/spec/annotation-checker.d.ts.map +1 -1
- package/dist/spec/annotation-checker.js +6 -26
- package/dist/spec/annotation-checker.js.map +1 -1
- package/dist/tools/index.d.ts +0 -4
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +0 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/types/constraint.d.ts +1 -12
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +0 -3
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/project-config.d.ts +0 -2
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/utils/file-walk.d.ts +2 -2
- package/dist/utils/file-walk.js +2 -2
- package/package.json +6 -1
- package/src/CONTEXT.md +14 -0
- package/src/__tests__/checker-extra.test.ts +2 -59
- package/src/__tests__/constraint-doctor.test.ts +1 -140
- package/src/__tests__/constraint-handler.test.ts +0 -4
- package/src/__tests__/project-config-loader-extra.test.ts +0 -20
- package/src/__tests__/project-config-loader.test.ts +0 -1
- package/src/cli/commands/CONTEXT.md +15 -7
- package/src/cli/commands/__tests__/check-drift.test.ts +0 -3
- package/src/cli/commands/__tests__/check-skip-output.test.ts +0 -5
- package/src/cli/commands/__tests__/check.test.ts +7 -75
- package/src/cli/commands/__tests__/registry.test.ts +201 -0
- package/src/cli/commands/check.ts +2 -14
- package/src/cli/commands/definitions.ts +593 -0
- package/src/cli/commands/knowledge.ts +3 -3
- package/src/cli/commands/sync-docs/capabilities-syncer.ts +4 -110
- package/src/cli/commands/sync-docs/index.ts +8 -5
- package/src/context/CONTEXT.md +2 -7
- package/src/context/__tests__/session-manager.test.ts +0 -91
- package/src/context/index.ts +1 -5
- package/src/context/knowledge-injector.ts +3 -3
- package/src/context/session-manager.ts +0 -74
- package/src/context/types.ts +2 -63
- package/src/core/constraints/__tests__/interceptor.test.ts +0 -2
- package/src/core/constraints/agent-prompt-renderer.ts +1 -1
- package/src/core/constraints/capabilities-parser.ts +95 -2
- package/src/core/constraints/checker.ts +8 -53
- package/src/core/constraints/definitions.ts +0 -8
- package/src/core/constraints/doc-freshness/runner.ts +1 -2
- package/src/core/constraints/index.ts +1 -2
- package/src/core/constraints/interceptor.ts +1 -6
- package/src/core/effective-constraints.ts +0 -1
- package/src/core/project-config-loader.ts +1 -7
- package/src/dashboard/stats.ts +2 -2
- package/src/dashboard/types.ts +2 -2
- package/src/failure/constraint-handler.ts +0 -2
- package/src/gates/CONTEXT.md +16 -13
- package/src/gates/__tests__/checker-gate.test.ts +45 -0
- package/src/gates/__tests__/contract.test.ts +73 -0
- package/src/gates/__tests__/effective-gates.test.ts +82 -0
- package/src/gates/__tests__/gate-interface.test.ts +202 -0
- package/src/gates/__tests__/registry.test.ts +87 -0
- package/src/gates/__tests__/runner.test.ts +81 -0
- package/src/gates/acceptance.ts +24 -1
- package/src/gates/checker-gate.ts +54 -0
- package/src/gates/command.ts +13 -2
- package/src/gates/contract.ts +12 -2
- package/src/gates/decision.ts +27 -0
- package/src/gates/definitions.ts +207 -0
- package/src/gates/effective-gates.ts +106 -0
- package/src/gates/index.ts +38 -0
- package/src/gates/performance.ts +12 -2
- package/src/gates/registry.ts +107 -0
- package/src/gates/review.ts +12 -2
- package/src/gates/runner.ts +57 -0
- package/src/gates/security.ts +12 -2
- package/src/gates/types.ts +48 -1
- package/src/hooks/CONTEXT.md +12 -2
- package/src/hooks/__tests__/bootstrap.test.ts +0 -1
- package/src/hooks/__tests__/config.test.ts +19 -0
- package/src/hooks/__tests__/pipeline.test.ts +79 -0
- package/src/hooks/__tests__/registry.test.ts +67 -0
- package/src/hooks/bootstrap.ts +0 -2
- package/src/hooks/config.ts +29 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/registry.ts +60 -1
- package/src/hooks/types.ts +21 -0
- package/src/index.ts +5 -22
- package/src/knowledge/import.ts +3 -3
- package/src/knowledge/ingest.ts +4 -4
- package/src/knowledge/lifecycle-hooks.ts +3 -3
- package/src/knowledge/types.ts +5 -8
- package/src/monitoring/constraint-doctor.ts +7 -106
- package/src/presets/__tests__/standard.test.ts +0 -2
- package/src/presets/standard.ts +1 -2
- package/src/spec/__tests__/annotation-checker.test.ts +9 -3
- package/src/spec/annotation-checker.ts +7 -29
- package/src/tools/CONTEXT.md +7 -14
- package/src/tools/index.ts +0 -4
- package/src/types/constraint.ts +1 -14
- package/src/types/project-config.ts +0 -3
- package/src/utils/file-walk.ts +2 -2
- package/dist/architecture/constraint-engine.d.ts +0 -67
- package/dist/architecture/constraint-engine.d.ts.map +0 -1
- package/dist/architecture/constraint-engine.js +0 -295
- package/dist/architecture/constraint-engine.js.map +0 -1
- package/dist/architecture/cross-project-checker.d.ts +0 -54
- package/dist/architecture/cross-project-checker.d.ts.map +0 -1
- package/dist/architecture/cross-project-checker.js +0 -467
- package/dist/architecture/cross-project-checker.js.map +0 -1
- package/dist/cli/commands/index.d.ts +0 -30
- package/dist/cli/commands/index.d.ts.map +0 -1
- package/dist/cli/commands/index.js +0 -91
- package/dist/cli/commands/index.js.map +0 -1
- package/dist/context/file-budget.d.ts +0 -40
- package/dist/context/file-budget.d.ts.map +0 -1
- package/dist/context/file-budget.js +0 -147
- package/dist/context/file-budget.js.map +0 -1
- package/dist/context/progressive-loader.d.ts +0 -109
- package/dist/context/progressive-loader.d.ts.map +0 -1
- package/dist/context/progressive-loader.js +0 -166
- package/dist/context/progressive-loader.js.map +0 -1
- package/dist/context/token-pipeline.d.ts +0 -55
- package/dist/context/token-pipeline.d.ts.map +0 -1
- package/dist/context/token-pipeline.js +0 -220
- package/dist/context/token-pipeline.js.map +0 -1
- package/dist/context/tool-output-budget.d.ts +0 -59
- package/dist/context/tool-output-budget.d.ts.map +0 -1
- package/dist/context/tool-output-budget.js +0 -177
- package/dist/context/tool-output-budget.js.map +0 -1
- package/dist/core/constraints/default-executors.d.ts +0 -10
- package/dist/core/constraints/default-executors.d.ts.map +0 -1
- package/dist/core/constraints/default-executors.js +0 -120
- package/dist/core/constraints/default-executors.js.map +0 -1
- package/dist/llm/adapter.d.ts +0 -36
- package/dist/llm/adapter.d.ts.map +0 -1
- package/dist/llm/adapter.js +0 -118
- package/dist/llm/adapter.js.map +0 -1
- package/dist/llm/index.d.ts +0 -3
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/index.js +0 -19
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/types.d.ts +0 -62
- package/dist/llm/types.d.ts.map +0 -1
- package/dist/llm/types.js +0 -8
- package/dist/llm/types.js.map +0 -1
- package/dist/tools/core/index.d.ts +0 -13
- package/dist/tools/core/index.d.ts.map +0 -1
- package/dist/tools/core/index.js +0 -198
- package/dist/tools/core/index.js.map +0 -1
- package/dist/tools/loader.d.ts +0 -21
- package/dist/tools/loader.d.ts.map +0 -1
- package/dist/tools/loader.js +0 -199
- package/dist/tools/loader.js.map +0 -1
- package/dist/tools/registry.d.ts +0 -59
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/registry.js +0 -115
- package/dist/tools/registry.js.map +0 -1
- package/dist/tools/types.d.ts +0 -38
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js +0 -6
- package/dist/tools/types.js.map +0 -1
- package/src/__tests__/architecture-engine.test.ts +0 -619
- package/src/__tests__/context/progressive-loader.test.ts +0 -131
- package/src/__tests__/cross-project-checker.test.ts +0 -318
- package/src/architecture/CONTEXT.md +0 -22
- package/src/architecture/constraint-engine.ts +0 -351
- package/src/architecture/cross-project-checker.ts +0 -545
- package/src/cli/commands/index.ts +0 -30
- package/src/context/__tests__/file-budget.test.ts +0 -142
- package/src/context/__tests__/progressive-loader.test.ts +0 -264
- package/src/context/__tests__/token-pipeline.test.ts +0 -178
- package/src/context/__tests__/tool-output-budget.test.ts +0 -95
- package/src/context/file-budget.ts +0 -142
- package/src/context/progressive-loader.ts +0 -260
- package/src/context/token-pipeline.ts +0 -265
- package/src/context/tool-output-budget.ts +0 -178
- package/src/core/constraints/__tests__/default-executors.test.ts +0 -57
- package/src/core/constraints/default-executors.ts +0 -92
- package/src/llm/CONTEXT.md +0 -21
- package/src/llm/__tests__/adapter.test.ts +0 -172
- package/src/llm/adapter.ts +0 -149
- package/src/llm/index.ts +0 -2
- package/src/llm/types.ts +0 -81
- package/src/tools/__tests__/loader.test.ts +0 -252
- package/src/tools/__tests__/registry.test.ts +0 -157
- package/src/tools/core/__tests__/core.test.ts +0 -122
- package/src/tools/core/index.ts +0 -201
- package/src/tools/loader.ts +0 -216
- package/src/tools/registry.ts +0 -128
- package/src/tools/types.ts +0 -46
package/src/tools/core/index.ts
DELETED
|
@@ -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
|
-
];
|
package/src/tools/loader.ts
DELETED
|
@@ -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
|
-
}
|
package/src/tools/registry.ts
DELETED
|
@@ -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
|
-
}
|
package/src/tools/types.ts
DELETED
|
@@ -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
|
-
}
|