Skip to content

Conversation

@EdSDR
Copy link
Member

@EdSDR EdSDR commented Jan 4, 2026

Summary by CodeRabbit

Release Notes

  • New Features
    • Added Sub-Agents Graph visualization on agent detail pages, displaying filtered agent connections.
    • Agent cards now display subagent count badges for whitelisted agents.
    • ForceGraph component supports contained (non-fullscreen) rendering mode.

✏️ Tip: You can customize this high-level summary in your review settings.

@EdSDR EdSDR requested a review from a team as a code owner January 4, 2026 14:17
@vercel
Copy link

vercel bot commented Jan 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
prediction-swarm Ready Ready Preview, Comment Jan 4, 2026 2:19pm
torus-bridge Ready Ready Preview, Comment Jan 4, 2026 2:19pm
torus-governance Ready Ready Preview, Comment Jan 4, 2026 2:19pm
torus-page Ready Ready Preview, Comment Jan 4, 2026 2:19pm
torus-portal Ready Ready Preview, Comment Jan 4, 2026 2:19pm
torus-wallet Ready Ready Preview, Comment Jan 4, 2026 2:19pm

@EdSDR
Copy link
Member Author

EdSDR commented Jan 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

Walkthrough

This PR extends the force graph component with a contained (non-fullscreen) mode and introduces agent-specific subgraph visualization. It adds a new backend query to compute subagent and parent counts, which are then propagated through the agent card components to display a subagent count badge for whitelisted agents. The AgentConnectionsGraph component filters the overall graph to show only connections relevant to a specific agent.

Changes

Cohort / File(s) Summary
Force Graph Enhancement
apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
Added contained?: boolean property to ForceGraph2DProps to toggle between fullscreen and container-bound PIXI rendering modes.
Agent Connections Visualization
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx, apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
Introduced new AgentConnectionsGraph component that filters and displays agent-specific subgraph with connected nodes; integrated into agent detail page as "Sub-Agents Graph" section.
Subagent Count Prop Propagation
apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx, apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx, packages/ui/src/components/agent-card/agent-card.tsx, packages/ui/src/components/agent-card/agent-card-header.tsx
Added subagentCount?: number prop flowing through agent card hierarchy; AgentCardHeader now displays subagent count badge for whitelisted agents with non-zero subagent counts.
Backend Agent Connection Query
packages/api/src/router/agent/agent.ts
New agentConnectionCounts public procedure computes subagent and parent counts via graph traversal across permissions, namespace permissions, and emission targets; builds adjacency structures and runs BFS for subagent computation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

A graph takes form with agents bound,
Connected nodes dance all around,
New badges bloom to count their crew,
Subagents shine in fullscreen view! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: display subagents on root allocator card' accurately summarizes the main feature added across the changeset.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
packages/api/src/router/agent/agent.ts (2)

421-470: Consider parallelizing database queries for better performance.

The four sequential database queries (basePermissions, namespaceRelations, emissionTargets, whitelistedAgents) are independent and could be executed in parallel using Promise.all to reduce overall latency.

🔎 Proposed parallel fetch
-    // 1. Fetch all relationships from multiple sources
-    // Source 1: Base permissions (grantorAccountId -> granteeAccountId)
-    const basePermissions = await ctx.db
-      .select({
-        grantor: permissionsSchema.grantorAccountId,
-        grantee: permissionsSchema.granteeAccountId,
-      })
-      .from(permissionsSchema)
-      .where(isNull(permissionsSchema.deletedAt));
-
-    // Source 2: Namespace permissions (grantor -> recipient)
-    const namespaceRelations = await ctx.db
-      .select({
-        grantor: permissionsSchema.grantorAccountId,
-        grantee: namespacePermissionsSchema.recipient,
-      })
-      .from(namespacePermissionsSchema)
-      .innerJoin(
-        permissionsSchema,
-        eq(
-          namespacePermissionsSchema.permissionId,
-          permissionsSchema.permissionId,
-        ),
-      )
-      .where(isNull(permissionsSchema.deletedAt));
-
-    // Source 3: Emission distribution targets (grantor -> targetAccountId)
-    const emissionTargets = await ctx.db
-      .select({
-        grantor: permissionsSchema.grantorAccountId,
-        grantee: emissionDistributionTargetsSchema.targetAccountId,
-      })
-      .from(emissionDistributionTargetsSchema)
-      .innerJoin(
-        permissionsSchema,
-        eq(
-          emissionDistributionTargetsSchema.permissionId,
-          permissionsSchema.permissionId,
-        ),
-      )
-      .where(isNull(permissionsSchema.deletedAt));
-
-    // 2. Fetch whitelisted (root) agents
-    const whitelistedAgents = await ctx.db
-      .select({ key: agentSchema.key })
-      .from(agentSchema)
-      .where(
-        and(eq(agentSchema.isWhitelisted, true), isNull(agentSchema.deletedAt)),
-      );
+    // 1. Fetch all relationships and whitelisted agents in parallel
+    const [basePermissions, namespaceRelations, emissionTargets, whitelistedAgents] = await Promise.all([
+      // Source 1: Base permissions (grantorAccountId -> granteeAccountId)
+      ctx.db
+        .select({
+          grantor: permissionsSchema.grantorAccountId,
+          grantee: permissionsSchema.granteeAccountId,
+        })
+        .from(permissionsSchema)
+        .where(isNull(permissionsSchema.deletedAt)),
+
+      // Source 2: Namespace permissions (grantor -> recipient)
+      ctx.db
+        .select({
+          grantor: permissionsSchema.grantorAccountId,
+          grantee: namespacePermissionsSchema.recipient,
+        })
+        .from(namespacePermissionsSchema)
+        .innerJoin(
+          permissionsSchema,
+          eq(
+            namespacePermissionsSchema.permissionId,
+            permissionsSchema.permissionId,
+          ),
+        )
+        .where(isNull(permissionsSchema.deletedAt)),
+
+      // Source 3: Emission distribution targets (grantor -> targetAccountId)
+      ctx.db
+        .select({
+          grantor: permissionsSchema.grantorAccountId,
+          grantee: emissionDistributionTargetsSchema.targetAccountId,
+        })
+        .from(emissionDistributionTargetsSchema)
+        .innerJoin(
+          permissionsSchema,
+          eq(
+            emissionDistributionTargetsSchema.permissionId,
+            permissionsSchema.permissionId,
+          ),
+        )
+        .where(isNull(permissionsSchema.deletedAt)),
+
+      // Whitelisted (root) agents
+      ctx.db
+        .select({ key: agentSchema.key })
+        .from(agentSchema)
+        .where(
+          and(eq(agentSchema.isWhitelisted, true), isNull(agentSchema.deletedAt)),
+        ),
+    ]);

514-527: Minor: BFS uses shift() which is O(n) per operation.

For large agent networks, using queue.shift() in a loop can become a bottleneck since it's O(n). Consider using an index pointer for O(1) dequeue operations.

🔎 Proposed optimization
     for (const rootKey of whitelistedSet) {
       const visited = new Set<string>();
       const queue = [rootKey];
+      let queueIndex = 0;

-      while (queue.length > 0) {
-        const current = queue.shift();
+      while (queueIndex < queue.length) {
+        const current = queue[queueIndex++];
         if (!current || visited.has(current)) continue;
         visited.add(current);

         const neighbors = adjacencyList.get(current);
         if (neighbors) {
           for (const neighbor of neighbors) {
             if (!visited.has(neighbor)) {
               queue.push(neighbor);
             }
           }
         }
       }
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx (3)

40-54: Consider extracting link ID resolution logic.

The type narrowing for link.source and link.target is repeated and verbose. Extracting this to a small helper function would improve readability.

🔎 Suggested refactor

Add a helper function before the component:

/**
 * Extracts the ID from a link source or target, which can be either
 * a string ID or an object containing an ID property.
 */
function getLinkNodeId(node: string | { id: string }): string {
  return typeof node === "string" ? node : node.id;
}

Then simplify the filtering logic:

     const filteredLinks = graphData.links.filter((link) => {
-      const sourceId =
-        typeof link.source === "string"
-          ? link.source
-          : (link.source as { id: string }).id;
-      const targetId =
-        typeof link.target === "string"
-          ? link.target
-          : (link.target as { id: string }).id;
+      const sourceId = getLinkNodeId(link.source);
+      const targetId = getLinkNodeId(link.target);
       return (
         connectedNodeIds.has(sourceId) &&
         connectedNodeIds.has(targetId) &&
         sourceId !== allocatorAddress &&
         targetId !== allocatorAddress
       );
     });

86-94: Remove or document the empty click handler.

The onNodeClick prop is passed an empty function with a comment. If node clicking is not needed, consider omitting the prop entirely, or if it's required by the API, add a JSDoc comment explaining why it's intentionally empty.

🔎 Suggested changes

If the prop is optional, remove it:

       <ForceGraphCanvas2D
         graphData={filteredGraphData}
-        onNodeClick={() => {
-          /* empty */
-        }}
         allocatorAddress={allocatorAddress}
         swarmCenterNodeId={agentKey}
         contained
       />

Or if it's required, document why:

+        // Node clicks are intentionally disabled in the agent-specific view
         onNodeClick={() => {
           /* empty */
         }}

68-85: Consider extracting height constants.

The container heights (400px and 200px) are hardcoded in multiple places. Extracting these to named constants would improve maintainability.

🔎 Suggested refactor

Add constants at the top of the file:

const GRAPH_HEIGHT = 400;
const EMPTY_STATE_HEIGHT = 200;

Then use them in the JSX:

-      <div className="flex h-[400px] items-center justify-center ...">
+      <div className={`flex h-[${GRAPH_HEIGHT}px] items-center justify-center ...`}>

Or use inline styles if Tailwind JIT doesn't support dynamic values:

-      <div className="flex h-[400px] items-center ...">
+      <div className="flex items-center ..." style={{ height: GRAPH_HEIGHT }}>
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6a819ff and 4d01e67.

📒 Files selected for processing (8)
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
  • packages/api/src/router/agent/agent.ts
  • packages/ui/src/components/agent-card/agent-card-header.tsx
  • packages/ui/src/components/agent-card/agent-card.tsx
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Follow JSDoc standards as defined in @docs/DOCUMENTATION_STYLE.md for all code documentation
Never use // eslint-disable or // eslint-disable-next-line to suppress linting errors; fix the root cause by refactoring code instead
Never instantiate stateful singleton objects at module top level; use lazy initialization patterns instead (exception: tRPC clients initialized via useState)

Files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • packages/ui/src/components/agent-card/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • packages/ui/src/components/agent-card/agent-card-header.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
apps/**/*.{tsx,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Never use emojis in UI/UX components unless explicitly requested by the engineer in the prompt

Files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: NEVER use the non-null assertion operator (!) in TypeScript; instead use assert() from tsafe with a descriptive message
When accessing Drizzle schema properties, use camelCase property names (e.g., grantorKey) not snake_case (e.g., grantor_key)
Use rustie utilities (match, if_let, etc.) instead of switch statements or type casts when working with rustie Enum types
Use the canonical Result<T,E> handling pattern with destructuring: const [error, data] = await someFunction() followed by error check
Use Substrate H256 hash (66 chars) for permission IDs in external APIs and reference permission_id (Substrate hash) not internal UUIDs in foreign keys

Files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • packages/ui/src/components/agent-card/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • packages/ui/src/components/agent-card/agent-card-header.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
!(node_modules|packages/torus-utils)/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

NEVER use raw try-catch blocks in application code; instead use error handling abstractions from @torus-network/torus-utils/try-catch (trySync, tryAsync, trySyncStr, tryAsyncStr)

Files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • packages/ui/src/components/agent-card/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • packages/ui/src/components/agent-card/agent-card-header.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
🧠 Learnings (19)
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement agent name resolution to convert SS58 addresses to agent names for namespace path generation

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:34:38.334Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: apps/prediction-swarm/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:34:38.334Z
Learning: Applies to apps/prediction-swarm/src/app/(pages)/(expanded-pages)/**/*.tsx : Create new pages in src/app/(pages)/(expanded-pages)/[name]/page.tsx following the App Router directory structure

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement connection pooling for RPC endpoints to support scalable blockchain communication

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Use automatic namespace path generation following the format `agent.<agent_name>.<endpoint_name>` by default, with option for custom paths

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
📚 Learning: 2025-11-24T17:34:38.334Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: apps/prediction-swarm/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:34:38.334Z
Learning: Applies to apps/prediction-swarm/src/app/_components/navigation-items.tsx : Add navigation items to src/app/_components/navigation-items.tsx when creating new pages

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
📚 Learning: 2025-11-24T17:34:38.334Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: apps/prediction-swarm/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:34:38.334Z
Learning: Applies to apps/prediction-swarm/src/app/_components/main-page/**/*.{ts,tsx} : Use React Three Fiber and Three.js for 3D graphics on the landing page

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx
  • apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Collect metrics for monitoring namespace permission check performance

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-12-15T20:29:08.848Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-15T20:29:08.848Z
Learning: Applies to services/torus-worker/src/workers/agent-fetcher.ts : Agent-fetcher worker at `services/torus-worker/src/workers/agent-fetcher.ts` synchronizes blockchain data; when modifying permission transforms, update `permissionContractToDatabase()`, `upsertPermissions()`, and `runPermissionsFetch()` functions

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement RPC integration for actual blockchain calls to verify namespace permissions against the Torus blockchain

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Cache permission results to reduce blockchain queries and improve performance

Applied to files:

  • apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-12-15T20:29:08.848Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-15T20:29:08.848Z
Learning: When updating permission schema, ensure agent-fetcher transformation logic in `services/torus-worker/src/workers/agent-fetcher.ts` is updated accordingly

Applied to files:

  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.{ts,tsx} : Include `_protocol_metadata` with version info in JWT tokens for protocol version compatibility validation

Applied to files:

  • packages/api/src/router/agent/agent.ts
  • packages/ui/src/components/agent-card/agent-card-header.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement circuit breakers for RPC failures to maintain service availability

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/**/*.{test,spec}.ts : Cover namespace permission scenarios in tests including valid and invalid access attempts

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:35:10.841Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/agent.ts : Configure namespace permissions at the per-endpoint level with `namespace` configuration object containing `enabled`, `path`, and `rpcUrls` properties

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:35:26.128Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/chain/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:26.128Z
Learning: Applies to packages/torus-sdk-ts/src/chain/src/**/*.ts : Use Zod schemas with `sb_` prefixed utilities for Substrate type parsing

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:34:38.333Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: apps/prediction-swarm/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:34:38.333Z
Learning: tRPC routes are defined in the torus-ts/api package

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:35:26.128Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/chain/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:26.128Z
Learning: Applies to packages/torus-sdk-ts/src/chain/src/**/torus0/ : Organize Torus0 pallet module files by domain: agents.ts, namespace.ts, staking.ts with index.ts re-exports

Applied to files:

  • packages/api/src/router/agent/agent.ts
📚 Learning: 2025-11-24T17:34:38.334Z
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: apps/prediction-swarm/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:34:38.334Z
Learning: Applies to apps/prediction-swarm/**/*.{ts,tsx} : Query the Torus Cache layer for blockchain data including block data, transaction history, agent metadata, and permission data

Applied to files:

  • packages/api/src/router/agent/agent.ts
  • apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx
🧬 Code graph analysis (4)
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx (1)
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx (1)
  • AgentConnectionsGraph (13-97)
packages/api/src/router/agent/agent.ts (1)
packages/db/src/schema/base.ts (4)
  • permissionsSchema (544-607)
  • namespacePermissionsSchema (887-894)
  • emissionDistributionTargetsSchema (810-835)
  • agentSchema (78-109)
packages/ui/src/components/agent-card/agent-card-header.tsx (2)
packages/ui/src/components/agent-card/agent-card-socials-info.tsx (1)
  • AgentCardSocialsInfo (61-81)
packages/ui/src/components/badge.tsx (1)
  • Badge (36-36)
apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx (1)
packages/db/drizzle/schema.ts (1)
  • agent (44-64)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: typecheck
🔇 Additional comments (8)
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsx (1)

164-168: LGTM!

The new "Sub-Agents Graph" section is well-integrated into the agent page layout. The AgentConnectionsGraph component handles its own loading and empty states internally (as seen in the relevant code snippet showing loading spinner and "No network connections found" fallback).

apps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsx (1)

21-23: LGTM!

Clean addition of the subagentCount prop with appropriate JSDoc documentation. The prop is correctly forwarded to the underlying UI component.

apps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsx (1)

48-65: LGTM with minor observation.

The memoized lookup function is a clean pattern. The agentConnectionCounts query runs independently and gracefully handles the loading state by returning undefined for subagent counts until data is available.

One consideration: this query fetches connection counts for all agents upfront, which is efficient for the current use case where counts are displayed on multiple cards. If the dataset grows significantly, consider whether server-side pagination or filtering might be needed.

apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsx (2)

463-467: Verify: contained prop not in useEffect dependencies.

The props.contained value is used inside runForceGraph2D (line 171) but isn't listed in the effect's dependency array (line 463-467). If contained were to change dynamically, the graph wouldn't reinitialize with the new resize behavior. This is likely intentional since contained is typically set at mount time, but worth confirming this is the expected behavior.


44-46: LGTM!

The contained prop addition is well-documented and correctly implements two rendering modes: fullscreen (default) with fixed positioning and contained mode that respects parent container bounds.

packages/ui/src/components/agent-card/agent-card.tsx (1)

80-82: LGTM!

Consistent prop addition matching the pattern established in the portal layer. The JSDoc comment maintains documentation consistency across the component hierarchy.

packages/ui/src/components/agent-card/agent-card-header.tsx (1)

89-98: LGTM!

The subagent badge implementation is clean with:

  • Correct conditional rendering (only for whitelisted agents with subagents)
  • Proper pluralization logic
  • Appropriate whitespace-nowrap to prevent text wrapping
  • Good layout integration alongside the socials info
packages/api/src/router/agent/agent.ts (1)

448-461: Fix the join condition to follow the schema relationship chain.

The emissionDistributionTargetsSchema has a foreign key constraint that references emissionPermissionsSchema.permissionId, not permissionsSchema.permissionId directly. The join should include emissionPermissionsSchema as an intermediate table. The current join skips this relationship and directly connects to permissionsSchema, which does not align with the schema's defined foreign key constraints:

emissionDistributionTargetsSchema.permissionId 
  → emissionPermissionsSchema.permissionId (via FK)
  → permissionsSchema.permissionId (via FK)

Update the join to include the intermediate table:

Suggested fix
const emissionTargets = await ctx.db
  .select({
    grantor: permissionsSchema.grantorAccountId,
    grantee: emissionDistributionTargetsSchema.targetAccountId,
  })
  .from(emissionDistributionTargetsSchema)
  .innerJoin(
    emissionPermissionsSchema,
    eq(
      emissionDistributionTargetsSchema.permissionId,
      emissionPermissionsSchema.permissionId,
    ),
  )
  .innerJoin(
    permissionsSchema,
    eq(
      emissionPermissionsSchema.permissionId,
      permissionsSchema.permissionId,
    ),
  )
  .where(isNull(permissionsSchema.deletedAt));
⛔ Skipped due to learnings
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-15T20:29:08.848Z
Learning: When updating permission schema, ensure agent-fetcher transformation logic in `services/torus-worker/src/workers/agent-fetcher.ts` is updated accordingly
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement agent name resolution to convert SS58 addresses to agent names for namespace path generation
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-15T20:29:08.848Z
Learning: Applies to services/torus-worker/src/workers/agent-fetcher.ts : Agent-fetcher worker at `services/torus-worker/src/workers/agent-fetcher.ts` synchronizes blockchain data; when modifying permission transforms, update `permissionContractToDatabase()`, `upsertPermissions()`, and `runPermissionsFetch()` functions
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement RPC integration for actual blockchain calls to verify namespace permissions against the Torus blockchain
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement connection pooling for RPC endpoints to support scalable blockchain communication
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Collect metrics for monitoring namespace permission check performance
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Provide clear error messages that include context about permission requirements when namespace access is denied
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Cache permission results to reduce blockchain queries and improve performance
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/**/*.{test,spec}.ts : Cover namespace permission scenarios in tests including valid and invalid access attempts
Learnt from: CR
Repo: renlabs-dev/torus-ts PR: 0
File: packages/torus-sdk-ts/src/agent/CLAUDE.md:0-0
Timestamp: 2025-11-24T17:35:10.841Z
Learning: Applies to packages/torus-sdk-ts/src/agent/src/agent/**/*.ts : Implement circuit breakers for RPC failures to maintain service availability

Comment on lines +9 to +11
interface AgentConnectionsGraphProps {
agentKey: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add JSDoc documentation for the interface.

The interface lacks JSDoc documentation. Per coding guidelines, all code documentation must follow JSDoc standards as defined in @docs/DOCUMENTATION_STYLE.md.

🔎 Suggested JSDoc documentation
+/**
+ * Props for the AgentConnectionsGraph component.
+ */
 interface AgentConnectionsGraphProps {
+  /** The unique key/address of the agent to display connections for */
   agentKey: string;
 }

Based on coding guidelines: Follow JSDoc standards for all code documentation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
interface AgentConnectionsGraphProps {
agentKey: string;
}
/**
* Props for the AgentConnectionsGraph component.
*/
interface AgentConnectionsGraphProps {
/** The unique key/address of the agent to display connections for */
agentKey: string;
}
🤖 Prompt for AI Agents
In
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
around lines 9 to 11, the AgentConnectionsGraphProps interface is missing JSDoc;
add a JSDoc block immediately above the interface that describes the interface
purpose and documents the agentKey property (type string) with a concise
description per @docs/DOCUMENTATION_STYLE.md conventions (one-line summary,
@property or @param tag for agentKey, and any relevant usage notes).

Comment on lines +13 to +16
export function AgentConnectionsGraph({
agentKey,
}: AgentConnectionsGraphProps) {
const { graphData, isLoading, allocatorAddress } = useGraphData();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add JSDoc documentation for the component.

The component function lacks JSDoc documentation explaining its purpose and behavior.

🔎 Suggested JSDoc documentation
+/**
+ * Renders a filtered force-directed graph showing only nodes and links
+ * connected to the specified agent. Excludes the root allocator node from
+ * the visualization.
+ *
+ * @param props - Component props
+ * @returns A force graph visualization or loading/empty states
+ */
 export function AgentConnectionsGraph({
   agentKey,
 }: AgentConnectionsGraphProps) {

Based on coding guidelines: Follow JSDoc standards for all code documentation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function AgentConnectionsGraph({
agentKey,
}: AgentConnectionsGraphProps) {
const { graphData, isLoading, allocatorAddress } = useGraphData();
/**
* Renders a filtered force-directed graph showing only nodes and links
* connected to the specified agent. Excludes the root allocator node from
* the visualization.
*
* @param props - Component props
* @returns A force graph visualization or loading/empty states
*/
export function AgentConnectionsGraph({
agentKey,
}: AgentConnectionsGraphProps) {
const { graphData, isLoading, allocatorAddress } = useGraphData();
🤖 Prompt for AI Agents
In
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsx
around lines 13 to 16, the AgentConnectionsGraph component is missing JSDoc; add
a JSDoc block immediately above the function that briefly describes the
component's purpose (renders a graph of agent connections), documents the
agentKey prop with @param including its type and meaning, notes any important
behavior (e.g., it uses useGraphData to fetch
graphData/isLoading/allocatorAddress), and adds an @returns describing the
rendered React element; keep the description concise and follow standard JSDoc
tags and formatting.

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.

2 participants