Skip to content

Commit 27292d8

Browse files
committed
fix: resolve ci lint and smart search tests
1 parent 65e0744 commit 27292d8

8 files changed

Lines changed: 50 additions & 49 deletions

File tree

server/src/mcp-server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ async function bootstrap() {
3131
name: 'secbot-mcp',
3232
version: '1.0.0',
3333
});
34-
const registerTool = (server as any).registerTool.bind(server) as any;
35-
3634
for (const tool of toolsService.getAllTools()) {
3735
if (tool.sensitive && !allowSensitive) {
3836
continue;
3937
}
4038

41-
registerTool(
39+
server.registerTool(
4240
tool.name,
4341
{
4442
title: tool.name,

server/src/modules/agents/core/explore-agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface ExploreArgs {
6666
intent?: IntentDecision;
6767
contextBlock?: string;
6868
onEvent?: OnEventCallback;
69-
/** 默认 3 */
69+
/** 默认 12,可用 SECBOT_EXPLORE_MAX_ITERS 覆盖 */
7070
maxIterations?: number;
7171
}
7272

@@ -101,7 +101,7 @@ export class ExploreAgent extends BaseAgent {
101101
async explore(args: ExploreArgs): Promise<ContextPatch> {
102102
const { userInput, intent, contextBlock, onEvent } = args;
103103
const defaultMax = resolveDefaultMaxIterations();
104-
const maxIterations = args.maxIterations ?? Infinity;
104+
const maxIterations = args.maxIterations ?? defaultMax;
105105

106106
/** 为本次 explore 生成独立的虚拟浏览器 session_id,结束时主动关闭 */
107107
const browserSessionId = `expl-${Date.now().toString(36)}-${Math.random()

server/src/modules/agents/core/intent-router.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class IntentRouter {
141141
} catch {
142142
/* LLM 不可用 / 解析失败:走启发式 */
143143
}
144-
return this.fallback(args.userInput, heuristic, args);
144+
return this.fallback(heuristic);
145145
}
146146

147147
private parse(raw: string): IntentDecision | null {
@@ -191,11 +191,7 @@ export class IntentRouter {
191191
};
192192
}
193193

194-
private fallback(
195-
userInput: string,
196-
heuristic: ReturnType<IntentRouter['heuristic']>,
197-
args: IntentRouteArgs,
198-
): IntentDecision {
194+
private fallback(heuristic: ReturnType<IntentRouter['heuristic']>): IntentDecision {
199195
let intent: Intent = 'qa';
200196
if (heuristic.isSmallTalk) intent = 'small_talk';
201197
else if (heuristic.isMeta) intent = 'meta';

server/src/modules/chat/chat.service.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ export class ChatService {
6161
body: ChatRequestDto,
6262
onSSEEvent?: (eventName: string, data: Record<string, unknown>) => void,
6363
): Promise<string> {
64-
const { message, mode, agent: agentType, client_shell: clientShell, model: modelName } = body;
65-
const forceQA = message.trim().startsWith('/ask ');
66-
const forceAgent = mode === 'agent' || message.trim().startsWith('/agent ');
64+
const { message, agent: agentType, client_shell: clientShell, model: modelName } = body;
6765
const sessionId = (body.session_id ?? '').trim() || this.defaultSessionId;
6866
this.getOrCreateSession(sessionId, agentType);
6967
this.appendSessionMessage(sessionId, MessageRole.USER, message);
@@ -78,14 +76,11 @@ export class ChatService {
7876
try {
7977
return await this._handleMessageCore({
8078
message,
81-
mode,
8279
agentType,
8380
clientShell,
8481
modelName,
8582
sessionId,
8683
session,
87-
forceQA,
88-
forceAgent,
8984
emit,
9085
});
9186
} catch (error) {
@@ -98,27 +93,14 @@ export class ChatService {
9893

9994
private async _handleMessageCore(params: {
10095
message: string;
101-
mode?: string;
10296
agentType?: string;
10397
clientShell?: ChatRequestDto['client_shell'];
10498
modelName?: string;
10599
sessionId: string;
106100
session: Session;
107-
forceQA: boolean;
108-
forceAgent: boolean;
109101
emit: (name: string, data: Record<string, unknown>) => void;
110102
}): Promise<string> {
111-
const {
112-
message,
113-
agentType,
114-
clientShell,
115-
modelName,
116-
sessionId,
117-
session,
118-
forceQA,
119-
forceAgent,
120-
emit,
121-
} = params;
103+
const { message, agentType, clientShell, modelName, sessionId, session, emit } = params;
122104

123105
/** 1) 启发式 focus 即时更新(IP/CVE/域名/URL/协议词) */
124106
this.contextAssembler.updateFocusFromInput(sessionId, message);
@@ -193,7 +175,7 @@ export class ChatService {
193175

194176
/** 5) 组装最终上下文(按当前模型预算 + focus 加权 + pinned 优先级) */
195177
const selectedAgent = this.agents[agentType ?? 'hackbot'] ?? this.agents['hackbot'];
196-
const effectiveModelName = modelName || (selectedAgent as any).llm?.model || undefined;
178+
const effectiveModelName = modelName || resolveAgentModelName(selectedAgent);
197179
const context = await this.contextAssembler.build({
198180
query: message,
199181
session,
@@ -408,7 +390,7 @@ export class ChatService {
408390
return {
409391
handled: true,
410392
result: (async () => {
411-
const qaModelName = modelName || (this.qaAgent as any).llm?.model || undefined;
393+
const qaModelName = modelName || resolveAgentModelName(this.qaAgent);
412394
const ctx = await this.contextAssembler.build({
413395
query: message,
414396
session,
@@ -498,3 +480,20 @@ export class ChatService {
498480
}
499481
}
500482
}
483+
484+
function resolveAgentModelName(agent: unknown): string | undefined {
485+
if (!agent || typeof agent !== 'object' || !('llm' in agent)) {
486+
return undefined;
487+
}
488+
489+
try {
490+
const llm = (agent as { llm?: unknown }).llm;
491+
if (!llm || typeof llm !== 'object' || !('model' in llm)) {
492+
return undefined;
493+
}
494+
const model = (llm as { model?: unknown }).model;
495+
return typeof model === 'string' && model.trim() ? model : undefined;
496+
} catch {
497+
return undefined;
498+
}
499+
}

server/src/modules/skills/skills.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { CreateSkillRequestDto, SkillDetailDto, SkillSummaryDto } from './dto/sk
55
import { SkillFrontmatter, SkillRecord } from './skills.types';
66

77
const FRONTMATTER_BOUNDARY = '---';
8-
const DEFAULT_BODY = '# Overview\n\nDescribe what this skill does and when to use it.\n';
98
const DEFAULT_DESCRIPTION = 'Custom Secbot skill.';
109
const DEFAULT_AUTHOR = 'Secbot';
1110
const DEFAULT_VERSION = '1.0.0';

server/src/modules/tools/protocol/ldap-enum.tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class LdapEnumTool extends BaseTool {
2323
result: {
2424
host,
2525
port,
26+
base_dn: baseDn || undefined,
2627
reachable: true,
2728
banner_bytes: banner.length,
2829
anonymous_bind: anonBind.success,

server/src/modules/tools/security/sniff.tool.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ export class SniffTool extends BaseTool {
121121
: err.message,
122122
});
123123
});
124-
child.on('close', () => {
124+
child.on('close', (code) => {
125125
if (done) return;
126126
done = true;
127127
clearTimeout(timer);
128+
if (code && code !== 0) {
129+
resolve({ stdout, error: stderr.trim() || `tshark 退出码 ${code}` });
130+
return;
131+
}
128132
resolve({ stdout });
129133
});
130134
});

server/src/modules/tools/web-research/smart-search.tool.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,28 @@ export class SmartSearchTool extends BaseTool {
132132

133133
private async searchDDGHtml(query: string, maxResults: number): Promise<SearchResult[]> {
134134
const url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
135-
try {
136-
const html = await this.fetchWithRetry(url, { headers: { 'User-Agent': BROWSER_UA } });
137-
if (!html) return [];
138-
return this.parseDDGHtml(html, maxResults);
139-
} catch {
140-
return [];
141-
}
135+
const html = await this.fetchWithRetry(
136+
url,
137+
{ headers: { 'User-Agent': BROWSER_UA } },
138+
0,
139+
SEARCH_TIMEOUT_MS,
140+
);
141+
if (!html) return [];
142+
const htmlResults = this.parseDDGHtml(html, maxResults);
143+
if (htmlResults.length > 0) return htmlResults;
144+
return this.parseDuckDuckGoLite(html, maxResults);
142145
}
143146

144147
private async searchDDGLite(query: string, maxResults: number): Promise<SearchResult[]> {
145148
const url = `https://lite.duckduckgo.com/lite/?q=${encodeURIComponent(query)}`;
146-
try {
147-
const html = await this.fetchWithRetry(url, { headers: { 'User-Agent': BROWSER_UA } });
148-
if (!html) return [];
149-
return this.parseDuckDuckGoLite(html, maxResults);
150-
} catch {
151-
return [];
152-
}
149+
const html = await this.fetchWithRetry(
150+
url,
151+
{ headers: { 'User-Agent': BROWSER_UA } },
152+
0,
153+
SEARCH_TIMEOUT_MS,
154+
);
155+
if (!html) return [];
156+
return this.parseDuckDuckGoLite(html, maxResults);
153157
}
154158

155159
private parseDDGHtml(html: string, maxResults: number): SearchResult[] {

0 commit comments

Comments
 (0)