Add comprehensive logging and enable AI section creation
Features: - IAs can now create NEW sections if they think they're needed - Complete document content logging (before/after each modification) - Detailed AI thinking and reasoning in logs - Distinguish between 'MODIFIED' and 'CREATED NEW SECTION' actions - Full round-by-round visibility in logs This allows AI agents to be more creative and add new architectural sections when they identify missing requirements or design gaps. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c5f7806718
commit
68cf310f0c
@ -50,6 +50,7 @@ class CollaborativeOrchestrator {
|
||||
)
|
||||
const result = stmt.run(initialPrompt, documentFormat, 'created')
|
||||
const sessionId = result.lastInsertRowid
|
||||
console.log(`[Session ${sessionId}] Created with ${agentCount} agents, format: ${documentFormat}`)
|
||||
|
||||
// Generate random names for agents
|
||||
const agentNames = getRandomNames(Math.min(agentCount, 50))
|
||||
@ -88,7 +89,10 @@ class CollaborativeOrchestrator {
|
||||
const session = this.activeSessions.get(sessionId)
|
||||
if (!session || session.started) return
|
||||
|
||||
console.log(`[Session ${sessionId}] Starting session with ${session.agents.length} agents: ${session.agents.join(', ')}`)
|
||||
|
||||
const firstAgent = session.agents[0]
|
||||
console.log(`[Session ${sessionId}] ${firstAgent} creating initial document...`)
|
||||
|
||||
// Generate initial document
|
||||
const initialResponse = await generateAgentResponseSync(
|
||||
@ -116,6 +120,11 @@ class CollaborativeOrchestrator {
|
||||
const updateStmt = db.prepare('UPDATE collaborative_sessions SET status = ? WHERE id = ?')
|
||||
updateStmt.run('ongoing', sessionId)
|
||||
|
||||
console.log(`[Session ${sessionId}] Initial document created (${initialDocument.length} chars)`)
|
||||
console.log(`[Session ${sessionId}] ===== INITIAL DOCUMENT =====`)
|
||||
console.log(initialDocument)
|
||||
console.log(`[Session ${sessionId}] ===== END INITIAL DOCUMENT =====`)
|
||||
|
||||
// Broadcast initial document
|
||||
this.broadcast(sessionId, {
|
||||
type: 'initial_document_created',
|
||||
@ -125,6 +134,7 @@ class CollaborativeOrchestrator {
|
||||
roundNumber: 0
|
||||
})
|
||||
|
||||
console.log(`[Session ${sessionId}] Scheduling first round in 2s...`)
|
||||
// Auto-start first round
|
||||
setTimeout(() => this.runRound(sessionId), 2000)
|
||||
} catch (error) {
|
||||
@ -148,10 +158,14 @@ class CollaborativeOrchestrator {
|
||||
const agentsInRound = session.agents
|
||||
const modifiedAgents = []
|
||||
|
||||
console.log(`[Session ${sessionId}] ===== ROUND ${roundNumber} START =====`)
|
||||
|
||||
// Each agent reviews the document
|
||||
for (let i = 0; i < agentsInRound.length; i++) {
|
||||
const agentName = agentsInRound[i]
|
||||
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber}: ${agentName} reviewing...`)
|
||||
|
||||
// Broadcast that this agent is working
|
||||
this.broadcast(sessionId, {
|
||||
type: 'agent_working',
|
||||
@ -169,6 +183,13 @@ class CollaborativeOrchestrator {
|
||||
const thinking = extractThinking(response)
|
||||
const section = extractSection(response)
|
||||
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber}: ${agentName} response received (${response.length} chars)`)
|
||||
console.log(`[Session ${sessionId}] --- THINKING ---`)
|
||||
console.log(thinking)
|
||||
console.log(`[Session ${sessionId}] --- SECTION ---`)
|
||||
console.log(section)
|
||||
console.log(`[Session ${sessionId}] --- END RESPONSE ---`)
|
||||
|
||||
// Broadcast agent's thinking in real-time
|
||||
this.broadcast(sessionId, {
|
||||
type: 'agent_thinking',
|
||||
@ -180,6 +201,7 @@ class CollaborativeOrchestrator {
|
||||
// Check if agent made changes
|
||||
if (section !== 'Section is good, no changes needed' && !section.includes('no changes needed')) {
|
||||
// Merge section into document
|
||||
const docBefore = session.currentDocument
|
||||
const updatedDocument = this.mergeSection(session.currentDocument, section)
|
||||
|
||||
if (updatedDocument !== session.currentDocument) {
|
||||
@ -187,6 +209,19 @@ class CollaborativeOrchestrator {
|
||||
session.versionNumber++
|
||||
modifiedAgents.push(agentName)
|
||||
|
||||
// Check if it's a new section or modification
|
||||
const sectionHeader = section.match(/^(#+)\s+(.+)/m)
|
||||
const headerText = sectionHeader ? sectionHeader[2] : 'Unknown'
|
||||
const isNewSection = !docBefore.includes(headerText)
|
||||
const action = isNewSection ? 'CREATED NEW SECTION' : 'MODIFIED'
|
||||
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber}: ${agentName} ${action}: "${headerText}" (v${session.versionNumber})`)
|
||||
console.log(`[Session ${sessionId}] ===== DOCUMENT BEFORE (v${session.versionNumber - 1}) =====`)
|
||||
console.log(docBefore)
|
||||
console.log(`[Session ${sessionId}] ===== DOCUMENT AFTER (v${session.versionNumber}) =====`)
|
||||
console.log(updatedDocument)
|
||||
console.log(`[Session ${sessionId}] ===== END DOCUMENT =====`)
|
||||
|
||||
// Save version to DB
|
||||
const insertStmt = db.prepare(
|
||||
'INSERT INTO document_versions (session_id, version_number, content, modified_by, modification_reason, round_number) VALUES (?, ?, ?, ?, ?, ?)'
|
||||
@ -208,7 +243,11 @@ class CollaborativeOrchestrator {
|
||||
section,
|
||||
roundNumber
|
||||
})
|
||||
} else {
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber}: ${agentName} - section proposed but no actual changes merged`)
|
||||
}
|
||||
} else {
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber}: ${agentName} - no changes needed`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error with agent ${agentName}:`, error)
|
||||
@ -222,6 +261,8 @@ class CollaborativeOrchestrator {
|
||||
session.consecutiveNoChanges = 0
|
||||
}
|
||||
|
||||
console.log(`[Session ${sessionId}] Round ${roundNumber} complete: ${modifiedAgents.length}/${agentsInRound.length} agents modified (consecutive no-change: ${session.consecutiveNoChanges}/${session.agentCount})`)
|
||||
|
||||
// Save round to DB
|
||||
const roundStmt = db.prepare(
|
||||
'INSERT INTO document_rounds (session_id, round_number, agents_in_round, agents_made_changes) VALUES (?, ?, ?, ?)'
|
||||
@ -252,8 +293,10 @@ class CollaborativeOrchestrator {
|
||||
|
||||
// Auto-schedule next round if not converged
|
||||
if (!hasConverged && session.consecutiveNoChanges < session.agentCount) {
|
||||
console.log(`[Session ${sessionId}] Scheduling round ${roundNumber + 1} in 2s...`)
|
||||
setTimeout(() => this.runRound(sessionId), 2000)
|
||||
} else if (hasConverged) {
|
||||
console.log(`[Session ${sessionId}] CONVERGED! All ${session.agentCount} agents made no changes in consecutive rounds`)
|
||||
// All agents agreed, auto-complete
|
||||
setTimeout(() => this.completeSession(sessionId), 2000)
|
||||
}
|
||||
@ -308,6 +351,7 @@ class CollaborativeOrchestrator {
|
||||
const session = this.activeSessions.get(sessionId)
|
||||
if (session) {
|
||||
stmt.run('completed', session.currentDocument, sessionId)
|
||||
console.log(`[Session ${sessionId}] SESSION COMPLETED - Final document: ${session.currentDocument.length} chars, ${session.versionNumber} versions, ${session.conversationHistory.length} rounds`)
|
||||
}
|
||||
|
||||
this.broadcast(sessionId, {
|
||||
|
||||
@ -14,23 +14,26 @@ function getAgentPrompt(agentName) {
|
||||
|
||||
Your responsibilities:
|
||||
1. Review the current document structure
|
||||
2. Select ONE section to improve or modify (identified by #, ##, ###, #### headers)
|
||||
2. Either:
|
||||
a) Modify ONE existing section (identified by #, ##, ###, #### headers), OR
|
||||
b) Create a NEW section if you think it's needed
|
||||
3. Provide your thinking process and reasoning
|
||||
4. Return ONLY the modified section with its header, or confirm it's good as-is
|
||||
4. Return ONLY the section (modified or new) with its header, or confirm it's good as-is
|
||||
|
||||
IMPORTANT RULES:
|
||||
- Only modify ONE section header and its content
|
||||
- Work on exactly ONE section only
|
||||
- Never modify the entire document
|
||||
- Return only the section you're working on, not the whole document
|
||||
- You CAN create a new section if you think the document is missing important content
|
||||
- If section is good, respond: "Section is good, no changes needed"
|
||||
- Think step-by-step about what could be improved
|
||||
- Share your reasoning process
|
||||
|
||||
Format your response as:
|
||||
THINKING: [Your analysis and reasoning]
|
||||
DECISION: [What you'll modify or if keeping as-is]
|
||||
DECISION: [What you'll modify, create, or if keeping as-is]
|
||||
SECTION:
|
||||
[The modified or confirmed section with header]`
|
||||
[The modified section, new section, or confirmation that all is good]`
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user