Skip to content

Refactor/coordinator rename manager flag#102

Open
glassBead-tc wants to merge 10 commits intomainfrom
refactor/coordinator-rename-manager-flag
Open

Refactor/coordinator rename manager flag#102
glassBead-tc wants to merge 10 commits intomainfrom
refactor/coordinator-rename-manager-flag

Conversation

@glassBead-tc
Copy link
Member

No description provided.

glassBead-tc and others added 6 commits February 7, 2026 17:24
MANAGER was an orthogonal capability ("can spawn sub-agents") that got
implemented as a mutually exclusive role. Rename to COORDINATOR to
accurately describe the delegation/coordination role, freeing MANAGER
semantics for the upcoming capability flag.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add optional `manager: boolean` field to AgentIdentity. Self-reported
flag indicating the agent can spawn sub-agents. Stored on registration,
returned via whoami. Does not change available operations — signals
capability to other agents and the coordinator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace CommonJS require() with proper ESM imports in storage.ts
(RevisionIndexBuilder) and claude-folder-integration.ts (statSync).
Fixes "require is not defined" warning in ESM context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The priming resource block (mental models for profiled agents) was being
appended to every thought response, causing massive token waste. Added a
sessionsPrimed set to GatewayHandler keyed by agentId:sessionId to ensure
priming is sent only once per session.

Fixes thoughtbox-308

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The last thought had nextThoughtNeeded: false which closed the session
before the test could capture the sessionId, causing all 9 branch
retrieval tests to fail with "No session created".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… bounds validation

The JS falsy check `!data.branchFromThought` treated 0 as missing,
giving agents a misleading "branchId requires branchFromThought" error
instead of the correct "must be >= 1" bounds error. Also fixes wrong
operation names and arg shapes in all 3 hub agent instruction files
that caused agents to call nonexistent operations during demos.

Changes:
- Fix falsy check to use explicit undefined/null comparison
- Add branchFromThought >= 1 bounds validation with clear error message
- Rewrite hub-architect.md Phase 2-3: init→get_state, new_thought→thought,
  create_proposal uses sourceBranch not thoughtRef, post_message uses
  workspaceId+problemId not channelId
- Rewrite hub-debugger.md Phase 2-3: same corrections as architect
- Fix hub-coordinator.md: mark_consensus thoughtRef is a number not object,
  post_message uses workspaceId+problemId, merge_proposal needs workspaceId
- Add 2 test cases for branchFromThought validation
- Reset corrupted .claude/state/memory-calibration.json (gitignored)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@augmentcode
Copy link

augmentcode bot commented Feb 8, 2026

🤖 Augment PR Summary

Summary: This PR renames the hub “MANAGER” role/profile to “COORDINATOR” and tightens hub/gateway behavior around branching and profile priming.

Changes:

  • Renames the Claude agent file and related docs/scripts from hub-manager/MANAGER to hub-coordinator/COORDINATOR.
  • Adds an optional manager boolean flag to hub identity registration and exposes it via whoami.
  • Makes gateway profile priming append only once per (agent, session) instead of on every thought call.
  • Adds validation that branchFromThought must be >= 1 (1-indexed) and improves related test coverage.
  • Removes a dynamic require() in persistence export code in favor of a static import.

Technical Notes: Updates multiple tests to reflect the new coordinator profile name and the once-per-session priming behavior.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

private sessionAgentIds = new Map<string, string>();
private sessionAgentNames = new Map<string, string>();
/** Track sessions that have already received profile priming (once-per-session) */
private sessionsPrimed = new Set<string>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sessionsPrimed will grow for every unique (agentId, sessionId) and is never cleared, which can become an unbounded memory footprint in a long-lived server. Consider adding a cleanup path when sessions are ended/expired (similar to any cleanup for sessionAgentIds/sessionAgentNames).

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

}

// Validate branchFromThought is >= 1 (thoughts are 1-indexed)
if (data.branchFromThought !== undefined && data.branchFromThought !== null && data.branchFromThought < 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the branchFromThought >= 1 check, but branchFromThought still isn’t type-validated; values like NaN/non-numeric strings can slip through and then be treated as a number via casts. Consider explicitly validating typeof data.branchFromThought === 'number' when it’s provided.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

WORKSPACE_DESC="Multi-agent collaboration demo: COORDINATOR decomposes problems, ARCHITECT designs solutions, DEBUGGER investigates bugs"
WORKSPACE_ID_FILE="/tmp/hub-demo-workspace-id.txt"
MANAGER_OUTPUT_FILE="/tmp/hub-demo-manager-output.txt"
COORDINATOR_OUTPUT_FILE="/tmp/hub-demo-manager-output.txt"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COORDINATOR_OUTPUT_FILE still points to /tmp/hub-demo-manager-output.txt, which can overwrite/consume stale “manager” output across runs and is confusing when debugging. Consider renaming the temp filename to match the coordinator terminology.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 8, 2026

Greptile Overview

Greptile Summary

This PR completes a MANAGER → COORDINATOR rename across hub profiles, docs, and tests; introduces a new manager?: boolean capability flag on hub identities; and fixes a couple of ESM/CJS interop issues by replacing runtime require() calls with static imports. It also changes gateway profile priming behavior to be once-per-session (tracked in-memory) and tightens branching validation so branchFromThought: 0 produces a bounds error rather than a missing-field error.

The core runtime impact is in the hub identity layer (register/whoami) and gateway thought handling (profile priming + branching validation).

Confidence Score: 4/5

  • This PR is largely safe to merge, with one correctness issue in the new manager capability flag plumbing.
  • Most changes are straightforward renames and ESM import fixes, plus well-scoped gateway priming and branching validation changes with tests. The main concern is boolean handling for the new manager?: boolean flag: the current truthy checks drop explicit false, which can break downstream logic that distinguishes false vs undefined.
  • src/hub/identity.ts (manager flag persistence/serialization); secondarily confirm expected lifecycle for GatewayHandler.sessionsPrimed in src/gateway/gateway-handler.ts.

Important Files Changed

Filename Overview
.claude/agents/hub-coordinator.md Renamed hub-manager agent doc to hub-coordinator and updated examples/args (workspaceId/problemId, COORDINATOR profile, merge args).
scripts/demo/hub-collab-demo.sh Updated demo orchestrator script from Manager to Coordinator naming and agent invocation; minor variable/file naming inconsistency remains.
src/gateway/gateway-handler.ts Implemented once-per-session profile priming via sessionsPrimed Set keyed by agentId+sessionId.
src/hub/identity.ts Added manager capability flag plumbing to register/whoami; current truthy checks drop explicit false values.
src/persistence/storage.ts Replaced dynamic require of RevisionIndexBuilder with static ESM import.
src/server-factory.ts Updated hub tool description strings for COORDINATOR and added manager?: boolean to register docs.
src/thought-handler.ts Fixed branchId/branchFromThought validation to allow 0 to be caught by bounds error; added explicit branchFromThought >= 1 validation.

Sequence Diagram

sequenceDiagram
  autonumber
  actor Client as MCP Client
  participant Server as Thoughtbox Server
  participant Gateway as GatewayHandler
  participant Thought as ThoughtHandler
  participant Hub as HubHandler
  participant Identity as IdentityManager

  Client->>Server: thoughtbox_hub.register(name, profile, manager?)
  Server->>Hub: handle('register', args)
  Hub->>Identity: register({name, profile, manager?})
  Identity-->>Hub: {agentId, name, role}
  Hub-->>Client: registration result

  Client->>Server: thoughtbox_gateway.thought(args, mcpSessionId)
  Server->>Gateway: handle({operation:'thought', args}, mcpSessionId)
  Gateway->>Thought: processThought({...args, agentId?, agentName?})
  Thought-->>Gateway: result {content[], isError}

  alt result.isError == false AND getAgentProfile available
    Gateway->>Gateway: compute primingKey = agentId + ':' + sessionId
    alt primingKey not in sessionsPrimed
      Gateway->>Hub: getAgentProfile(agentId)
      Hub-->>Gateway: profileName
      Gateway->>Gateway: getProfilePriming(profileName)
      Gateway-->>Client: content + priming resource
      Gateway->>Gateway: sessionsPrimed.add(primingKey)
    else already primed
      Gateway-->>Client: content (no priming)
    end
  else error or no profile
    Gateway-->>Client: content (no priming)
  end

  Note over Thought: branch validation updated:
  Note over Thought: - branchId requires branchFromThought (undefined/null)
  Note over Thought: - branchFromThought must be >= 1

Loading

glassBead-tc and others added 4 commits February 7, 2026 18:28
GATEWAY_DESCRIPTION: add missing operations (read_thoughts, get_structure,
knowledge) and arg summaries for all 15 operations, grouped by stage.

HUB_TOOL_DESCRIPTION: explain manager flag purpose, profile meanings,
mark coordinator-only ops, group by lifecycle stage.

THOUGHTBOX_INSTRUCTIONS: expand hub section with workflow sequence,
profile examples, and manager flag documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 35 to 38
@@ -37,6 +38,7 @@ export function createIdentityManager(storage: HubStorage): IdentityManager {
name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manager flag drops false

register() only persists the manager capability when it’s truthy (...(manager && { manager })), and whoami() only returns it when truthy (if (agent.manager)). This makes an explicit manager: false indistinguishable from undefined, which breaks boolean semantics for a capability flag. Consider checking manager !== undefined / agent.manager !== undefined instead so false round-trips correctly.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hub/identity.ts
Line: 35:38

Comment:
**Manager flag drops false**

`register()` only persists the `manager` capability when it’s truthy (`...(manager && { manager })`), and `whoami()` only returns it when truthy (`if (agent.manager)`). This makes an explicit `manager: false` indistinguishable from `undefined`, which breaks boolean semantics for a capability flag. Consider checking `manager !== undefined` / `agent.manager !== undefined` instead so `false` round-trips correctly.

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant