Skip to content

Refactor complex hive-mind spawn handler to resolve CodeFactor complexity warnings - #45

Merged
clduab11 merged 2 commits into
codex/launch-readiness-fixesfrom
copilot/sub-pr-42
Feb 11, 2026
Merged

Refactor complex hive-mind spawn handler to resolve CodeFactor complexity warnings#45
clduab11 merged 2 commits into
codex/launch-readiness-fixesfrom
copilot/sub-pr-42

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

CodeFactor flagged the hive-mind spawn command handler as overly complex (363 lines, deeply nested at 4235-4598, 4429-4597). Refactored into six focused helper functions with JSDoc documentation.

Extracted Functions

  • buildCodexContextForHiveMind — Aggregates agent directives, README excerpts, directory inventory, database metadata
  • executeGoapStrategy — Loads manifest, executes goal, displays artifacts
  • setupWorkflowEventHandlers — Attaches stage event listeners, returns cleanup function
  • displayHiveMindResults — Renders execution summary, code artifacts, ToT plans, system metrics
  • prepareResultData — Aggregates telemetry for YAML output
  • executeClassicOrchestration — Runs orchestration phases, executes task with timeout, handles consensus

Impact

Main action handler reduced from 363 to 151 lines (58% reduction). No functional changes.

// Before: 363-line monolithic handler with nested complexity

// After: Clean delegation to focused helpers
await useSystem('hive-mind spawn', async (system) => {
  const restoreLogging = configureLogStreaming(streamLogs, effectiveLogLevel);
  try {
    await executeClassicOrchestration(
      system, prompt, originalPrompt, config, options,
      codexContext, codexEnvelope
    );
  } finally {
    restoreLogging();
  }
});

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Continue Tasks: ▶️ 5 queued — View all

@clduab11 clduab11 changed the title [WIP] Enhance OpenAI diagnostics and CLI session management [WIP] Enhance OpenAI diagnostics and CLI session management [PAP-17] Feb 11, 2026
@notion-workspace

Copy link
Copy Markdown

🧬 codex-synaptic

@clduab11 clduab11 added documentation Improvements or additions to documentation enhancement New feature or request general improvements General QOL improvements and random small bug fixex and patches p2-medium (Linear) Medium priority stack feature Feature of the repo size-m and removed size-m labels Feb 11, 2026
Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance OpenAI diagnostics and CLI session management [PAP-17] Refactor complex hive-mind spawn handler to resolve CodeFactor complexity warnings Feb 11, 2026
Copilot AI requested a review from clduab11 February 11, 2026 19:08
@clduab11
clduab11 marked this pull request as ready for review February 11, 2026 19:51
@clduab11
clduab11 merged commit d237fd7 into codex/launch-readiness-fixes Feb 11, 2026
@clduab11
clduab11 deleted the copilot/sub-pr-42 branch February 11, 2026 20:10
clduab11 added a commit that referenced this pull request Feb 11, 2026
… status reporting [PAP-17] (#42)

* Fix codex-synaptic launch blockers

* Document launch readiness fixes

* Update docs/runbooks/autoscaler-daemon-coordination.md

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update src/cli/index.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Add JSDoc documentation to CLI lifecycle functions (#43)

* Initial plan

* Initial plan for adding docstrings

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Add JSDoc docstrings for CLI functions

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Consolidate docstring for resolveCliAutoShutdown

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Add JSDoc documentation to satisfy 80% docstring coverage threshold (#44)

* Initial plan

* Add comprehensive JSDoc documentation to CLI functions

- Added 45+ JSDoc docstrings to previously undocumented functions
- Documented all lifecycle functions (loadEnvFile, bootstrapCliEnv, etc.)
- Documented all rendering functions (renderAgentTable, renderMeshStatus, etc.)
- Documented all interactive menu functions (interactiveSystemMenu, etc.)
- Documented all utility functions (parseInteger, formatBytes, tokenizeCliArgs, etc.)
- Documented helper functions (shouldAutoAttachCodexContext, shouldRequireConsensus, etc.)
- All docstrings follow JSDoc format with @param, @returns, and @remarks tags
- Improves docstring coverage toward 80% threshold requirement

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Add JSDoc documentation to OpenAI and core utility functions

- Added docstrings to OpenAI credential resolution functions
- Added docstrings to model catalog functions (getStaticOpenAIModelCatalog, mergeModelInventory)
- Added docstrings to inference functions (inferModalitiesFromIdentifier, inferCapabilitiesFromIdentifier)
- Added docstrings to core system helper functions (cloneCodexContext, cloneCodexEnvelope, cloneFileTreeNode)
- All docstrings follow JSDoc format with @param, @returns, and @remarks tags
- Further improves docstring coverage across modified files

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Refactor complex hive-mind spawn handler to resolve CodeFactor complexity warnings (#45)

* Initial plan

* Refactor complex hive-mind spawn command into helper functions

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>

* Update src/cli/index.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Chris Dukes <chrisdukes@iMac.attlocal.net>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request feature Feature of the repo general improvements General QOL improvements and random small bug fixex and patches p2-medium (Linear) Medium priority stack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants