Skip to content

Implement per-agent extension shims for all five PTY agents #1123

Closed

Description

@malibio

Overview

Build the thin extension shims that register @nodespace/agent-tools functions as native tools in each of the five supported PTY agents: Claude Code (hooks), Codex (plugin), Gemini CLI (tools directory), OpenCode (plugin), and Pi (registerTool()). Each shim is agent-specific glue code; the tool logic lives entirely in @nodespace/agent-tools.

Problem Statement

@nodespace/agent-tools exports the tool functions but agents cannot discover or call them automatically. Each agent has its own extension mechanism: Claude Code uses a hooks system, Gemini CLI reads from a tools directory, Pi has a registerTool() API, and so on. A shim per agent bridges the gap between the agent's native extension API and the shared tool package.

Proposed Solution

One shim per agent, each as minimal as possible. The shim's only job is to translate the agent's native tool-registration API into calls to @nodespace/agent-tools functions. No business logic lives in shims. The GraphContextAssembler writes the appropriate shim activation instructions into the context file (CLAUDE.md / AGENTS.md) at session start so the agent picks up the shim automatically.

Acceptance Criteria

Claude Code shim

  • Hooks-based shim registered in .claude/hooks/ within the session temp directory
  • Agent sees nodespace_search, nodespace_get_node, nodespace_create_node, nodespace_update_node, nodespace_get_children as native tools
  • Tool call from Claude Code reaches nodespaced and returns a result

Codex shim

  • Plugin shim installed in the Codex plugin directory for the session
  • Same five tool names registered
  • Tool call from Codex reaches nodespaced and returns a result

Gemini CLI shim

  • Tool definitions written to Gemini's tools directory for the session
  • Same five tool names registered
  • Tool call from Gemini CLI reaches nodespaced and returns a result

OpenCode shim

  • OpenCode plugin adapter installed for the session
  • Same five tool names registered
  • Tool call from OpenCode reaches nodespaced and returns a result

Pi shim

  • registerTool() adapter calls made at session startup
  • Same five tool names registered
  • Tool call from Pi reaches nodespaced and returns a result

Cross-cutting

  • GraphContextAssembler writes shim activation instructions into context files for all five agents
  • Shim files are written into the session temp directory (not globally installed); cleaned up on session end
  • All shims handle ToolError from @nodespace/agent-tools and surface it as a tool error to the agent
  • Code passes bun run quality:fix

Technical Specifications

Shim location

Each shim lives in packages/agent-tools/shims/<agent-name>/:

packages/agent-tools/shims/
├── claude-code/
│   └── nodespace-hook.ts     # Claude Code hooks shim
├── codex/
│   └── nodespace-plugin.ts   # Codex plugin shim
├── gemini/
│   └── nodespace-tools.json  # Gemini tool definitions + loader
├── opencode/
│   └── nodespace-plugin.ts   # OpenCode plugin shim
└── pi/
    └── nodespace-adapter.ts  # Pi registerTool() adapter

Tool names (consistent across all agents)

nodespace_search_semantic
nodespace_get_node
nodespace_create_node
nodespace_update_node
nodespace_get_children

Claude Code shim pattern

Claude Code's hooks system allows registering tool handlers. The shim file is written to <session_dir>/.claude/hooks/nodespace.ts and activated via a CLAUDE.md directive:

// nodespace-hook.ts
import { searchSemantic, getNode, createNode, updateNode, getChildren }
  from '@nodespace/agent-tools';

// Register via Claude Code hooks API
hook('nodespace_search_semantic', async ({ query, limit }) =>
  JSON.stringify(await searchSemantic(query, limit)));
// ... repeat for other tools

Gemini CLI shim pattern

Gemini reads tool definitions from a directory. The shim writes a JSON tool spec file plus a handler script to the session temp dir and sets the GEMINI_TOOLS_DIR env var before spawning:

// nodespace-tools.json
{
  "tools": [{
    "name": "nodespace_search_semantic",
    "description": "Search the NodeSpace knowledge graph using natural language",
    "parameters": { "query": { "type": "string" }, "limit": { "type": "number" } },
    "handler": "./nodespace-handler.js"
  }]
}

Context file activation

GraphContextAssembler appends shim activation instructions to the context file. For Claude Code (CLAUDE.md):

## NodeSpace Tools

NodeSpace knowledge graph tools are available. Use them to search documentation,
create notes, and update the graph during this session.

Tools available: nodespace_search_semantic, nodespace_get_node, nodespace_create_node,
nodespace_update_node, nodespace_get_children

For other agents (AGENTS.md): equivalent section with tool names and brief descriptions.

Reference files

Dependencies

Non-Goals

  • Tool schema evolution or versioning (shims always use the current @nodespace/agent-tools version from the running daemon install)
  • Supporting agent versions other than current stable releases
  • Shim auto-update (shims are written fresh per session from the installed package)

Activity

  1. self-assigned this
    on May 18, 2026
  2. malibio commented on May 18, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 17 agent-tools tests passed (tools.test.ts: 12, client.test.ts: 4, connection-error.test.ts: 1). TypeScript: clean in agent-tools and desktop-app.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions