Skip to content

Audit: ./src/tui #407

Description

@avoidwork

Audit Table

File Type Severity Summary
app.js bug high CommandParser instantiated on every render (line 57) without memoization
app.js bug high Massive code duplication: streaming callbacks and auto-continue logic duplicated ~4 times across handleCommand and handleChat
app.js performance medium 10+ functions (handleSubmit, handleCommand, handleChat, handleQuit, handleInterrupt, shouldAbort, handleNewSession, processOnboardingInput, getTimestamp, addMessage) defined inline without useCallback, causing recreation on every render
app.js performance medium Token calculation logic duplicated in 3 places (lines 79-91, 567-577, 877-887)
app.js bug medium Deeply nested React.createElement calls in render method (lines 1160-1213) — consider extracting sub-components
contextTokens.js bug medium enc.free() only called in success path; encoder leaked if enc.encode() throws (line 30-41)
markdownText.js performance medium new RegExp(STREAMING_CURSOR, "g") created on every render of MarkdownTextInner (line 150) — should be module-level constant
memoryPanel.js style low Uses JSX syntax in .js file (not .jsx)
skillsPanel.js style low Uses JSX syntax in .js file (not .jsx)
settingsPanel.js style low Uses JSX syntax in .js file (not .jsx)
hooks.js performance low createPanelState creates new object on every call with no caching
components.js Simple re-export file, no issues
index.js Barrel export file, no issues
panels.js Simple utility, no issues
messages.js Simple utility, no issues
banner.js Simple component, no issues
inputPanel.js Simple component, no issues
statusBar.js Simple component, no issues
onboardingPanel.js Simple component, no issues

Audit Findings

Current Architecture

  • File: src/tools/subAgent.js — SubAgents are spawned as separate node index.js processes (line 113). Each subAgent is a full madz instance that reads its own config.yaml.
  • File: src/provider/openai.js — Temperature is passed to ChatOpenAI at model creation time (line 24). Currently reads from provider config only.
  • File: config.yaml — Temperature is configured at providers.openai.temperature (line 9). SubAgent config lives under process.subAgent (lines 84-89) but has no temperature field.

Integration Points

  1. src/tools/subAgent.js:113spawnSubAgentProcess() spawns the child process. This is where temperature would need to be passed (env var or CLI arg).
  2. src/tools/subAgent.js:258-274resolveTimeout() shows the existing pattern: per-call > env var > config default. Temperature resolution should follow the same hierarchy.
  3. src/provider/openai.js:21-32createChatModel() accepts temperature from config. The spawned process would need to override this with the subAgent-specific value.
  4. config.yaml:84-89process.subAgent section is the natural home for subAgent-specific config including temperature.

Proposed Implementation Path

  1. Add temperature field to process.subAgent in config.yaml (e.g., 0.7)
  2. Pass temperature to spawned process via MADZ_SUBAGENT_TEMPERATURE env var in spawnSubAgentProcess()
  3. In the spawned process, override provider temperature if MADZ_SUBAGENT_TEMPERATURE is set
  4. Follow the same resolution pattern as timeout: per-call > env var > config default > provider default
  5. Add temperature to the subAgent tool schema (optional per-call override)

Config Schema Change

process:
  subAgent:
    timeout: 600000
    maxConcurrent: 4
    sessionMode: isolated
    defaultStrategy: parallel
    defaultOnError: continue
    temperature: 0.7  # NEW — subAgent temperature (0-2, follows OpenAI spec)

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedAn identifier for Madz to take action.auditAutomated code audit findings

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions