-
Notifications
You must be signed in to change notification settings - Fork 1
feat: display subagents on root allocator card #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
WalkthroughThis 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this 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.allto 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 usesshift()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.sourceandlink.targetis 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
onNodeClickprop 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 (
400pxand200px) 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.
📒 Files selected for processing (8)
apps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/infinite-agent-list.tsxpackages/api/src/router/agent/agent.tspackages/ui/src/components/agent-card/agent-card-header.tsxpackages/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-disableor// eslint-disable-next-lineto 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 viauseState)
Files:
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsxapps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxpackages/ui/src/components/agent-card/agent-card.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tspackages/ui/src/components/agent-card/agent-card-header.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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.tsxapps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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 useassert()fromtsafewith 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 referencepermission_id(Substrate hash) not internal UUIDs in foreign keys
Files:
apps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/page.tsxapps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxpackages/ui/src/components/agent-card/agent-card.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tspackages/ui/src/components/agent-card/agent-card-header.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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-catchblocks 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.tsxapps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxpackages/ui/src/components/agent-card/agent-card.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tspackages/ui/src/components/agent-card/agent-card-header.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tsapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tsapps/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.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxpackages/api/src/router/agent/agent.tsapps/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.tsxapps/torus-portal/src/app/(pages)/portal/_components/force-graph-2d/force-graph-2d.tsxapps/torus-portal/src/app/(pages)/root-allocator/(expanded-pages)/agent/[slug]/components/agent-connections-graph.tsxapps/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.tsxpackages/api/src/router/agent/agent.tsapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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.tsxpackages/api/src/router/agent/agent.tsapps/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.tsxpackages/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.tsxpackages/api/src/router/agent/agent.tsapps/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.tsapps/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.tspackages/ui/src/components/agent-card/agent-card-header.tsxapps/torus-portal/src/app/(pages)/root-allocator/_components/agent-card.tsxapps/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.tsapps/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
AgentConnectionsGraphcomponent 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
subagentCountprop 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
agentConnectionCountsquery runs independently and gracefully handles the loading state by returningundefinedfor 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:containedprop not in useEffect dependencies.The
props.containedvalue is used insiderunForceGraph2D(line 171) but isn't listed in the effect's dependency array (line 463-467). Ifcontainedwere to change dynamically, the graph wouldn't reinitialize with the new resize behavior. This is likely intentional sincecontainedis typically set at mount time, but worth confirming this is the expected behavior.
44-46: LGTM!The
containedprop 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-nowrapto 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
emissionDistributionTargetsSchemahas a foreign key constraint that referencesemissionPermissionsSchema.permissionId, notpermissionsSchema.permissionIddirectly. The join should includeemissionPermissionsSchemaas an intermediate table. The current join skips this relationship and directly connects topermissionsSchema, 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 accordinglyLearnt 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 generationLearnt 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()` functionsLearnt 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 blockchainLearnt 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 communicationLearnt 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 performanceLearnt 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 deniedLearnt 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 performanceLearnt 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 attemptsLearnt 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
| interface AgentConnectionsGraphProps { | ||
| agentKey: string; | ||
| } |
There was a problem hiding this comment.
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.
| 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).
| export function AgentConnectionsGraph({ | ||
| agentKey, | ||
| }: AgentConnectionsGraphProps) { | ||
| const { graphData, isLoading, allocatorAddress } = useGraphData(); |
There was a problem hiding this comment.
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.
| 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.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.