@yuaone/tools 0.1.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/LICENSE +663 -0
- package/README.md +15 -0
- package/dist/__tests__/file-edit.test.d.ts +8 -0
- package/dist/__tests__/file-edit.test.d.ts.map +1 -0
- package/dist/__tests__/file-edit.test.js +125 -0
- package/dist/__tests__/file-edit.test.js.map +1 -0
- package/dist/__tests__/registry.test.d.ts +7 -0
- package/dist/__tests__/registry.test.d.ts.map +1 -0
- package/dist/__tests__/registry.test.js +83 -0
- package/dist/__tests__/registry.test.js.map +1 -0
- package/dist/__tests__/validators.test.d.ts +8 -0
- package/dist/__tests__/validators.test.d.ts.map +1 -0
- package/dist/__tests__/validators.test.js +189 -0
- package/dist/__tests__/validators.test.js.map +1 -0
- package/dist/base-tool.d.ts +45 -0
- package/dist/base-tool.d.ts.map +1 -0
- package/dist/base-tool.js +87 -0
- package/dist/base-tool.js.map +1 -0
- package/dist/browser-tool.d.ts +39 -0
- package/dist/browser-tool.d.ts.map +1 -0
- package/dist/browser-tool.js +518 -0
- package/dist/browser-tool.js.map +1 -0
- package/dist/code-search.d.ts +42 -0
- package/dist/code-search.d.ts.map +1 -0
- package/dist/code-search.js +298 -0
- package/dist/code-search.js.map +1 -0
- package/dist/design-tools.d.ts +70 -0
- package/dist/design-tools.d.ts.map +1 -0
- package/dist/design-tools.js +471 -0
- package/dist/design-tools.js.map +1 -0
- package/dist/dev-server-manager.d.ts +32 -0
- package/dist/dev-server-manager.d.ts.map +1 -0
- package/dist/dev-server-manager.js +183 -0
- package/dist/dev-server-manager.js.map +1 -0
- package/dist/file-edit.d.ts +19 -0
- package/dist/file-edit.d.ts.map +1 -0
- package/dist/file-edit.js +217 -0
- package/dist/file-edit.js.map +1 -0
- package/dist/file-read.d.ts +19 -0
- package/dist/file-read.d.ts.map +1 -0
- package/dist/file-read.js +142 -0
- package/dist/file-read.js.map +1 -0
- package/dist/file-write.d.ts +18 -0
- package/dist/file-write.d.ts.map +1 -0
- package/dist/file-write.js +139 -0
- package/dist/file-write.js.map +1 -0
- package/dist/git-ops.d.ts +25 -0
- package/dist/git-ops.d.ts.map +1 -0
- package/dist/git-ops.js +219 -0
- package/dist/git-ops.js.map +1 -0
- package/dist/glob.d.ts +18 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +91 -0
- package/dist/glob.js.map +1 -0
- package/dist/grep.d.ts +19 -0
- package/dist/grep.d.ts.map +1 -0
- package/dist/grep.js +177 -0
- package/dist/grep.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/security-scan.d.ts +62 -0
- package/dist/security-scan.d.ts.map +1 -0
- package/dist/security-scan.js +445 -0
- package/dist/security-scan.js.map +1 -0
- package/dist/shell-exec.d.ts +20 -0
- package/dist/shell-exec.d.ts.map +1 -0
- package/dist/shell-exec.js +206 -0
- package/dist/shell-exec.js.map +1 -0
- package/dist/test-run.d.ts +51 -0
- package/dist/test-run.d.ts.map +1 -0
- package/dist/test-run.js +359 -0
- package/dist/test-run.js.map +1 -0
- package/dist/tool-registry.d.ts +70 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +181 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +57 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +218 -0
- package/dist/validators.js.map +1 -0
- package/package.json +42 -0
package/dist/grep.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yuaone/tools — grep tool
|
|
3
|
+
*
|
|
4
|
+
* Searches file contents using regex patterns.
|
|
5
|
+
* - Node.js built-in implementation (no ripgrep dependency)
|
|
6
|
+
* - Glob-based file filtering
|
|
7
|
+
* - Context lines support
|
|
8
|
+
* - Max 100 result lines
|
|
9
|
+
*/
|
|
10
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
11
|
+
import fg from 'fast-glob';
|
|
12
|
+
import { BaseTool } from './base-tool.js';
|
|
13
|
+
const DEFAULT_MAX_RESULTS = 50;
|
|
14
|
+
const ABSOLUTE_MAX_RESULTS = 100;
|
|
15
|
+
const DEFAULT_CONTEXT = 0;
|
|
16
|
+
export class GrepTool extends BaseTool {
|
|
17
|
+
name = 'grep';
|
|
18
|
+
description = 'Search file contents using a regex pattern. ' +
|
|
19
|
+
'Returns matching lines with file paths and line numbers.';
|
|
20
|
+
riskLevel = 'low';
|
|
21
|
+
parameters = {
|
|
22
|
+
pattern: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Regular expression pattern to search for',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
path: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Search path relative to project root (default: project root)',
|
|
30
|
+
required: false,
|
|
31
|
+
},
|
|
32
|
+
glob: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: 'File pattern filter (e.g., "*.ts", "*.{ts,tsx}")',
|
|
35
|
+
required: false,
|
|
36
|
+
},
|
|
37
|
+
maxResults: {
|
|
38
|
+
type: 'number',
|
|
39
|
+
description: `Maximum results to return (default: ${DEFAULT_MAX_RESULTS}, max: ${ABSOLUTE_MAX_RESULTS})`,
|
|
40
|
+
required: false,
|
|
41
|
+
default: DEFAULT_MAX_RESULTS,
|
|
42
|
+
},
|
|
43
|
+
context: {
|
|
44
|
+
type: 'number',
|
|
45
|
+
description: 'Number of context lines before and after each match (default: 0)',
|
|
46
|
+
required: false,
|
|
47
|
+
default: DEFAULT_CONTEXT,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
async execute(args, workDir) {
|
|
51
|
+
const toolCallId = args._toolCallId ?? '';
|
|
52
|
+
const pattern = args.pattern;
|
|
53
|
+
const searchPath = args.path;
|
|
54
|
+
const globPattern = args.glob;
|
|
55
|
+
const maxResults = Math.min(args.maxResults ?? DEFAULT_MAX_RESULTS, ABSOLUTE_MAX_RESULTS);
|
|
56
|
+
const contextLines = args.context ?? DEFAULT_CONTEXT;
|
|
57
|
+
if (!pattern) {
|
|
58
|
+
return this.fail(toolCallId, 'Missing required parameter: pattern');
|
|
59
|
+
}
|
|
60
|
+
// Compile regex
|
|
61
|
+
let regex;
|
|
62
|
+
try {
|
|
63
|
+
regex = new RegExp(pattern, 'g');
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
return this.fail(toolCallId, `Invalid regex pattern: ${err.message}`);
|
|
67
|
+
}
|
|
68
|
+
// Resolve search path
|
|
69
|
+
let searchDir = workDir;
|
|
70
|
+
if (searchPath) {
|
|
71
|
+
try {
|
|
72
|
+
searchDir = this.validatePath(searchPath, workDir);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return this.fail(toolCallId, err.message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Check if searchDir is a file or directory
|
|
79
|
+
let isFile = false;
|
|
80
|
+
try {
|
|
81
|
+
const s = await stat(searchDir);
|
|
82
|
+
isFile = s.isFile();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return this.fail(toolCallId, `Path not found: ${searchPath ?? '.'}`);
|
|
86
|
+
}
|
|
87
|
+
// Collect files to search
|
|
88
|
+
let files;
|
|
89
|
+
if (isFile) {
|
|
90
|
+
files = [searchDir];
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const fileGlob = globPattern ?? '**/*';
|
|
94
|
+
try {
|
|
95
|
+
files = await fg(fileGlob, {
|
|
96
|
+
cwd: searchDir,
|
|
97
|
+
absolute: true,
|
|
98
|
+
ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**'],
|
|
99
|
+
onlyFiles: true,
|
|
100
|
+
followSymbolicLinks: false,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
return this.fail(toolCallId, `Glob error: ${err.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Search files
|
|
108
|
+
const matches = [];
|
|
109
|
+
let totalMatches = 0;
|
|
110
|
+
for (const filePath of files) {
|
|
111
|
+
if (matches.length >= maxResults)
|
|
112
|
+
break;
|
|
113
|
+
let content;
|
|
114
|
+
try {
|
|
115
|
+
content = await readFile(filePath, 'utf-8');
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
continue; // Skip unreadable files (binary, permissions, etc.)
|
|
119
|
+
}
|
|
120
|
+
const lines = content.split('\n');
|
|
121
|
+
for (let i = 0; i < lines.length; i++) {
|
|
122
|
+
// Reset regex state
|
|
123
|
+
regex.lastIndex = 0;
|
|
124
|
+
if (!regex.test(lines[i]))
|
|
125
|
+
continue;
|
|
126
|
+
totalMatches++;
|
|
127
|
+
if (matches.length >= maxResults)
|
|
128
|
+
continue; // Keep counting but stop collecting
|
|
129
|
+
const relativePath = filePath.startsWith(workDir)
|
|
130
|
+
? filePath.slice(workDir.length + 1)
|
|
131
|
+
: filePath;
|
|
132
|
+
const match = {
|
|
133
|
+
file: relativePath,
|
|
134
|
+
line: i + 1,
|
|
135
|
+
content: lines[i],
|
|
136
|
+
};
|
|
137
|
+
if (contextLines > 0) {
|
|
138
|
+
match.contextBefore = lines.slice(Math.max(0, i - contextLines), i);
|
|
139
|
+
match.contextAfter = lines.slice(i + 1, Math.min(lines.length, i + 1 + contextLines));
|
|
140
|
+
}
|
|
141
|
+
matches.push(match);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const truncated = totalMatches > maxResults;
|
|
145
|
+
// Format output
|
|
146
|
+
const outputLines = [];
|
|
147
|
+
for (const m of matches) {
|
|
148
|
+
if (m.contextBefore && m.contextBefore.length > 0) {
|
|
149
|
+
for (let j = 0; j < m.contextBefore.length; j++) {
|
|
150
|
+
const lineNum = m.line - m.contextBefore.length + j;
|
|
151
|
+
outputLines.push(` ${m.file}:${lineNum}: ${m.contextBefore[j]}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
outputLines.push(`> ${m.file}:${m.line}: ${m.content}`);
|
|
155
|
+
if (m.contextAfter && m.contextAfter.length > 0) {
|
|
156
|
+
for (let j = 0; j < m.contextAfter.length; j++) {
|
|
157
|
+
outputLines.push(` ${m.file}:${m.line + 1 + j}: ${m.contextAfter[j]}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (m.contextBefore || m.contextAfter) {
|
|
161
|
+
outputLines.push('--');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (truncated) {
|
|
165
|
+
outputLines.push(`\n... (showing ${matches.length} of ${totalMatches} total matches)`);
|
|
166
|
+
}
|
|
167
|
+
const output = outputLines.length > 0
|
|
168
|
+
? outputLines.join('\n')
|
|
169
|
+
: `No matches found for pattern: ${pattern}`;
|
|
170
|
+
return this.ok(toolCallId, output, {
|
|
171
|
+
totalMatches,
|
|
172
|
+
matchesReturned: matches.length,
|
|
173
|
+
truncated,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=grep.js.map
|
package/dist/grep.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../src/grep.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,MAAM,OAAO,QAAS,SAAQ,QAAQ;IAC3B,IAAI,GAAG,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,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACxD,IAAI,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC/C,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC1E,CAAC;YACH,CAAC;YACD,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;gBACtC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,WAAW,CAAC,IAAI,CAAC,kBAAkB,OAAO,CAAC,MAAM,OAAO,YAAY,iBAAiB,CAAC,CAAC;QACzF,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC;YACnC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;YACxB,CAAC,CAAC,iCAAiC,OAAO,EAAE,CAAC;QAE/C,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE;YACjC,YAAY;YACZ,eAAe,EAAE,OAAO,CAAC,MAAM;YAC/B,SAAS;SACV,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yuaone/tools — YUAN Agent Tool Implementations
|
|
3
|
+
*
|
|
4
|
+
* Provides the complete tool system for the YUAN coding agent:
|
|
5
|
+
* file_read, file_write, file_edit, shell_exec, grep, glob, git_ops, test_run, code_search, security_scan
|
|
6
|
+
*/
|
|
7
|
+
export type { ToolDefinition, ToolCall, ToolResult, ToolParameterSchema, } from '@yuaone/core';
|
|
8
|
+
export type { ParameterDef, RiskLevel, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, FileEditInput, FileEditOutput, ShellExecInput, ShellExecOutput, GrepInput, GrepMatch, GrepOutput, GlobInput, GlobOutput, GitOperation, GitOpsInput, GitOpsOutput, TestRunInput, TestRunOutput, CodeSearchMode, CodeSearchInput, CodeSearchResult, CodeSearchOutput, } from './types.js';
|
|
9
|
+
export { BaseTool } from './base-tool.js';
|
|
10
|
+
export { FileReadTool } from './file-read.js';
|
|
11
|
+
export { FileWriteTool } from './file-write.js';
|
|
12
|
+
export { FileEditTool } from './file-edit.js';
|
|
13
|
+
export { ShellExecTool } from './shell-exec.js';
|
|
14
|
+
export { GrepTool } from './grep.js';
|
|
15
|
+
export { GlobTool } from './glob.js';
|
|
16
|
+
export { GitOpsTool } from './git-ops.js';
|
|
17
|
+
export { TestRunTool } from './test-run.js';
|
|
18
|
+
export { CodeSearchTool } from './code-search.js';
|
|
19
|
+
export { SecurityScanTool } from './security-scan.js';
|
|
20
|
+
export type { SecurityFinding, SecurityReport, FindingSeverity } from './security-scan.js';
|
|
21
|
+
export { BrowserTool } from './browser-tool.js';
|
|
22
|
+
export { ToolRegistry, createDefaultRegistry, createDesignRegistry } from './tool-registry.js';
|
|
23
|
+
export { DevServerManager } from './dev-server-manager.js';
|
|
24
|
+
export type { DevServerManagerEvents } from './dev-server-manager.js';
|
|
25
|
+
export { DesignSnapshotTool, DesignScreenshotTool, DesignNavigateTool, DesignResizeTool, DesignInspectTool, DesignScrollTool, createDesignTools, setDesignBrowserSession, clearDesignBrowserSession, } from './design-tools.js';
|
|
26
|
+
export { validatePath, validateNoShellMeta, validateCommand, isSensitiveFile, isBinaryFile, isImageFile, truncateOutput, detectLanguage, } from './validators.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.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EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yuaone/tools — YUAN Agent Tool Implementations
|
|
3
|
+
*
|
|
4
|
+
* Provides the complete tool system for the YUAN coding agent:
|
|
5
|
+
* file_read, file_write, file_edit, shell_exec, grep, glob, git_ops, test_run, code_search, security_scan
|
|
6
|
+
*/
|
|
7
|
+
// Base class
|
|
8
|
+
export { BaseTool } from './base-tool.js';
|
|
9
|
+
// Tool implementations
|
|
10
|
+
export { FileReadTool } from './file-read.js';
|
|
11
|
+
export { FileWriteTool } from './file-write.js';
|
|
12
|
+
export { FileEditTool } from './file-edit.js';
|
|
13
|
+
export { ShellExecTool } from './shell-exec.js';
|
|
14
|
+
export { GrepTool } from './grep.js';
|
|
15
|
+
export { GlobTool } from './glob.js';
|
|
16
|
+
export { GitOpsTool } from './git-ops.js';
|
|
17
|
+
export { TestRunTool } from './test-run.js';
|
|
18
|
+
export { CodeSearchTool } from './code-search.js';
|
|
19
|
+
export { SecurityScanTool } from './security-scan.js';
|
|
20
|
+
export { BrowserTool } from './browser-tool.js';
|
|
21
|
+
// Registry
|
|
22
|
+
export { ToolRegistry, createDefaultRegistry, createDesignRegistry } from './tool-registry.js';
|
|
23
|
+
// Dev Server Manager (Design Mode)
|
|
24
|
+
export { DevServerManager } from './dev-server-manager.js';
|
|
25
|
+
// Design Mode Tools
|
|
26
|
+
export { DesignSnapshotTool, DesignScreenshotTool, DesignNavigateTool, DesignResizeTool, DesignInspectTool, DesignScrollTool, createDesignTools, setDesignBrowserSession, clearDesignBrowserSession, } from './design-tools.js';
|
|
27
|
+
// Validators
|
|
28
|
+
export { validatePath, validateNoShellMeta, validateCommand, isSensitiveFile, isBinaryFile, isImageFile, truncateOutput, detectLanguage, } from './validators.js';
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsCH,aAAa;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,uBAAuB;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/F,mCAAmC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,oBAAoB;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,aAAa;AACb,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module security-scan
|
|
3
|
+
* @description Security scanning tool for YUAN agent.
|
|
4
|
+
* Checks for common security vulnerabilities in code:
|
|
5
|
+
* - Hardcoded secrets (API keys, passwords, tokens, AWS keys, private keys)
|
|
6
|
+
* - Dangerous code patterns (eval, innerHTML, SQL injection, command injection)
|
|
7
|
+
* - Dependency vulnerabilities (npm/pnpm audit)
|
|
8
|
+
* - File permission issues
|
|
9
|
+
*
|
|
10
|
+
* No external dependencies -- pure TypeScript + node:fs + node:child_process.
|
|
11
|
+
*/
|
|
12
|
+
import type { ParameterDef, RiskLevel } from './types.js';
|
|
13
|
+
import type { ToolResult } from '@yuaone/core';
|
|
14
|
+
import { BaseTool } from './base-tool.js';
|
|
15
|
+
/** Severity classification for security findings */
|
|
16
|
+
export type FindingSeverity = 'critical' | 'high' | 'medium' | 'low';
|
|
17
|
+
/** A single security finding */
|
|
18
|
+
export interface SecurityFinding {
|
|
19
|
+
/** Category of the finding */
|
|
20
|
+
type: string;
|
|
21
|
+
/** File where the issue was found */
|
|
22
|
+
file: string;
|
|
23
|
+
/** Line number (1-based) */
|
|
24
|
+
line: number;
|
|
25
|
+
/** The offending line (redacted if secret) */
|
|
26
|
+
code: string;
|
|
27
|
+
/** Human-readable description of the issue */
|
|
28
|
+
description: string;
|
|
29
|
+
/** Recommended fix */
|
|
30
|
+
recommendation: string;
|
|
31
|
+
}
|
|
32
|
+
/** Full security scan report */
|
|
33
|
+
export interface SecurityReport {
|
|
34
|
+
/** Security score 0-100 (100 = clean) */
|
|
35
|
+
score: number;
|
|
36
|
+
/** Critical severity findings */
|
|
37
|
+
critical: SecurityFinding[];
|
|
38
|
+
/** High severity findings */
|
|
39
|
+
high: SecurityFinding[];
|
|
40
|
+
/** Medium severity findings */
|
|
41
|
+
medium: SecurityFinding[];
|
|
42
|
+
/** Low severity findings */
|
|
43
|
+
low: SecurityFinding[];
|
|
44
|
+
/** Human-readable summary */
|
|
45
|
+
summary: string;
|
|
46
|
+
}
|
|
47
|
+
export declare class SecurityScanTool extends BaseTool {
|
|
48
|
+
readonly name = "security_scan";
|
|
49
|
+
readonly description: string;
|
|
50
|
+
readonly riskLevel: RiskLevel;
|
|
51
|
+
readonly parameters: Record<string, ParameterDef>;
|
|
52
|
+
execute(args: Record<string, unknown>, workDir: string): Promise<ToolResult>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Run a full security scan on the given directory.
|
|
56
|
+
*
|
|
57
|
+
* @param scanDir - Directory to scan recursively
|
|
58
|
+
* @param skipAudit - If true, skip npm/pnpm audit
|
|
59
|
+
* @returns SecurityReport
|
|
60
|
+
*/
|
|
61
|
+
export declare function runSecurityScan(scanDir: string, skipAudit?: boolean): Promise<SecurityReport>;
|
|
62
|
+
//# sourceMappingURL=security-scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-scan.d.ts","sourceRoot":"","sources":["../src/security-scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAM1C,oDAAoD;AACpD,MAAM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