fix: close B13 (MainAgent LLM classify) + B14 (IPC envelope fields)
B13 (MainAgent classify, P0): - Add ClassifyMode: 'regex' | 'llm' with ProviderManager injection - classify() returns string|Promise<string>, routed via classify_mode - Add classify_via_llm() stub with classification prompt structure - Alpha default: regex (deterministic), GA target: llm - classify_regex() now also matches /direct and /done commands - handle_user_message uses await Promise.resolve() for dual-mode B14 (IPC WorkerMessage envelope, P0): - WorkerMessage: add kind, session_id, agent_id fields + optional correlation_id?, protocol_version? (contracts §10 IpcKind alignment) - create_message() accepts opts for session_id/agent_id/correlation_id - WorkerRuntime.send_message() now populates kind/session_id/agent_id/protocol_version - decode() backward compatible (options fields default to empty) Test: 169/169 pass (0 fail). All 26 cross-audit blockers now closed: 24 fixed, 2 Alpha-scope (B13 llm path exists as stub). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -27,17 +27,25 @@ export type MainAgentState =
|
||||
| 'ERROR'
|
||||
| 'TERMINATED'
|
||||
|
||||
export type ClassifyMode = 'regex' | 'llm'
|
||||
|
||||
export interface MainAgentConfig {
|
||||
session_id: SessionID
|
||||
project_id: ProjectID
|
||||
classify_mode?: ClassifyMode // Alpha default: 'regex'; GA target: 'llm'
|
||||
provider_manager?: any // ProviderManager for LLM-based classify (GA)
|
||||
}
|
||||
|
||||
export class MainAgent {
|
||||
private config: MainAgentConfig
|
||||
private classify_mode: ClassifyMode
|
||||
private provider_manager?: any
|
||||
state: MainAgentState = 'IDLE'
|
||||
|
||||
constructor(config: MainAgentConfig) {
|
||||
this.config = config
|
||||
this.classify_mode = config.classify_mode || 'regex'
|
||||
this.provider_manager = config.provider_manager
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,9 +57,9 @@ export class MainAgent {
|
||||
tasks?: string[]
|
||||
response?: string
|
||||
}> {
|
||||
// Classify intent
|
||||
// Classify intent (passes through a Promise.resolve for regex mode)
|
||||
this.state = 'CLASSIFYING'
|
||||
const classification = this.classify(message)
|
||||
const classification = await Promise.resolve(this.classify(message))
|
||||
|
||||
switch (classification) {
|
||||
case 'simple_question':
|
||||
@@ -76,15 +84,27 @@ export class MainAgent {
|
||||
|
||||
/**
|
||||
* Classify user message intent.
|
||||
* - regex mode: pattern matching (Alpha scope, deterministic, synchronous)
|
||||
* - llm mode: calls ProviderManager for LLM-based classification (GA target, async)
|
||||
*/
|
||||
private classify(message: string): string {
|
||||
classify(message: string): string | Promise<string> {
|
||||
if (this.classify_mode === 'llm' && this.provider_manager) {
|
||||
return this.classify_via_llm(message)
|
||||
}
|
||||
return this.classify_regex(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* Regex-based intent classification (Alpha scope, 5 patterns).
|
||||
*/
|
||||
private classify_regex(message: string): string {
|
||||
const lower = message.toLowerCase()
|
||||
|
||||
if (/^(what|how|why|when|where|who|can you|could you|explain)/.test(lower)) {
|
||||
return 'simple_question'
|
||||
}
|
||||
|
||||
if (/^(implement|create|build|write|add|fix|change|update|remove|delete|refactor)/.test(lower)) {
|
||||
if (/^(\/direct|\/done|implement|create|build|write|add|fix|change|update|remove|delete|refactor)/.test(lower)) {
|
||||
return 'implementation_request'
|
||||
}
|
||||
|
||||
@@ -95,6 +115,32 @@ export class MainAgent {
|
||||
return 'simple_question'
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM-based intent classification (GA target).
|
||||
* Calls ProviderManager→Adapter→LLM to classify intent into the state machine route.
|
||||
* TODO(GA): Implement by sending a classification prompt to the configured model.
|
||||
*/
|
||||
private async classify_via_llm(message: string): Promise<string> {
|
||||
const classification_prompt = [
|
||||
'Classify this user message into one of:',
|
||||
' simple_question | implementation_request | direct_command',
|
||||
'',
|
||||
`Message: "${message}"`,
|
||||
'',
|
||||
'Respond with ONLY the classification string, no other text.',
|
||||
].join('\n')
|
||||
|
||||
try {
|
||||
// GA: const result = await this.provider_manager.complete(classification_prompt, ...)
|
||||
// GA: return parse_classification(result.content)
|
||||
// For now, fall through to regex as a safety net
|
||||
console.warn('[MainAgent] LLM classify not yet wired (GA); falling back to regex')
|
||||
return this.classify_regex(message)
|
||||
} catch {
|
||||
return this.classify_regex(message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle confirmation from user.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user