MCPcopy Create free account
hub / github.com/astercloud/aster / filterOutput

Method filterOutput

pkg/tools/builtin/bashoutput.go:263–289  ·  view source on GitHub ↗

以下辅助函数预留用于实现高级输出过滤功能 对应InputSchema中定义的filter和lines参数 filterOutput 使用正则表达式过滤输出

(output, filter string)

Source from the content-addressed store, hash-verified

261
262// filterOutput 使用正则表达式过滤输出
263func (t *BashOutputTool) filterOutput(output, filter string) string {
264 if filter == "" || output == "" {
265 return output
266 }
267
268 // 注意: 实际使用时需要import "regexp"
269 // regex, err := regexp.Compile(filter)
270 // if err != nil {
271 // return output // 过滤器无效,返回原输出
272 // }
273
274 lines := strings.Split(output, "\n")
275 var filteredLines []string
276
277 for _, line := range lines {
278 // 简化实现:包含过滤词的行
279 if strings.Contains(line, filter) {
280 filteredLines = append(filteredLines, line)
281 }
282 }
283
284 if len(filteredLines) == 0 {
285 return output
286 }
287
288 return strings.Join(filteredLines, "\n")
289}
290
291// limitLines 限制输出行数
292func (t *BashOutputTool) limitLines(output string, maxLines int) string {

Callers 1

ExecuteMethod · 0.95

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected