List available graph endpoints
What Programming Language Powers the Hivemind Graph Module?
The graph module in the Hivemind repository is implemented entirely in TypeScript, compiled to JavaScript for execution according to the project's tsconfig.json configuration.
The Hivemind project by ActiveLoop provides a sophisticated graph-based memory system for AI applications. The graph module, which handles virtual filesystem operations and command parsing for navigating code relationships, is written in TypeScript to ensure type safety across the entire codebase. This article examines the source code in activeloopai/hivemind to demonstrate how TypeScript powers the graph subsystem.
TypeScript Configuration and Project Structure
The presence of a top-level tsconfig.json file confirms that TypeScript is the primary language for the entire project, including the graph module. This configuration file governs how the TypeScript compiler transforms source code into executable JavaScript, providing strict type checking for all graph operations.
Core graph files reside in the src/graph/ directory and carry the .ts extension. For example, src/graph/graph-command.ts contains typical TypeScript syntax including ES module imports (import { … } from "./vfs-handler.js") and strict type annotations (e.g., string | null).
Core Graph Implementation Files
Virtual Filesystem Handler
The src/graph/vfs-handler.ts file implements the core virtual filesystem logic that renders graph views. This TypeScript module exports the handleGraphVfs function, which synthesizes textual responses for graph queries on the fly by processing virtual paths like /graph/find/AuthService.
Command Parser
Located at src/graph/graph-command.ts, this file defines parseReadTargetPath, a TypeScript function that parses shell-like commands and extracts virtual graph paths. The function processes inputs such as cat "/graph/find/AuthService" and returns standardized path strings with proper type safety.
Type Definitions
The src/graph/types.ts file contains TypeScript interfaces and type definitions for graph snapshots, nodes, and edges. These type definitions ensure compile-time safety when manipulating graph structures throughout the module.
Working with the Graph Module
Querying the Graph via CLI
The TypeScript implementation exposes a virtual filesystem interface accessible through standard shell commands. The underlying TypeScript handler processes these commands and returns synthesized content.
# List available graph endpoints
cat ~/.deeplake/memory/graph/index.md
# Search for a symbol named "AuthService"
cat ~/.deeplake/memory/graph/find/AuthService
# Show details for the first match returned by the previous find
cat ~/.deeplake/memory/graph/show/1
These commands trigger the TypeScript-based virtual-filesystem handler (src/graph/vfs-handler.ts) that synthesizes textual responses on the fly.
Programmatic Access in Node.js
You can import the graph module directly into Node.js applications after the TypeScript compilation step. The following example demonstrates how to use the handleGraphVfs function:
import { handleGraphVfs } from "./src/graph/vfs-handler.js";
const cwd = process.cwd(); // Current working directory
const result = handleGraphVfs("index.md", cwd);
if (result.kind === "ok") {
console.log("Graph index:\n", result.body);
} else {
console.error("Error:", result.message);
}
This snippet imports the exported handleGraphVfs function (written in TypeScript) and calls it directly, demonstrating how the same logic can be reused in custom tooling.
Extending the Graph Command Parser
Developers can leverage the parseReadTargetPath function to build custom command-line tools that interface with the graph system:
import { parseReadTargetPath } from "./src/graph/graph-command.js";
const cmd = 'cat "/graph/find/AuthService"';
const path = parseReadTargetPath(cmd);
console.log("Parsed virtual path:", path);
// → "/graph/find/AuthService"
The parseReadTargetPath function—also implemented in TypeScript—parses shell-like commands and extracts the virtual graph path.
Summary
- The graph module in Hivemind is implemented in TypeScript, as evidenced by the
tsconfig.jsonconfiguration and.tsfile extensions throughoutsrc/graph/. - Key files include
src/graph/vfs-handler.tsfor virtual filesystem operations andsrc/graph/graph-command.tsfor command parsing. - The module exposes both CLI interfaces and programmatic APIs through functions like
handleGraphVfsandparseReadTargetPath. - Type definitions in
src/graph/types.tsprovide compile-time safety for graph data structures.
Frequently Asked Questions
Is the Hivemind graph module written in JavaScript or TypeScript?
The graph module is written in TypeScript. While it compiles to JavaScript for execution, the source code in src/graph/ uses TypeScript-specific features like static type annotations and interfaces defined in src/graph/types.ts.
Where is the TypeScript configuration for the graph module located?
The TypeScript configuration is located at the repository root in tsconfig.json. This project-wide configuration governs compilation for all TypeScript files, including those in the src/graph/ directory.
How does the graph module handle virtual filesystem operations?
The graph module uses the handleGraphVfs function exported from src/graph/vfs-handler.ts. This TypeScript function processes virtual paths (such as /graph/find/AuthService) and returns synthesized content or error responses with proper type safety.
Can I use the graph module functions in my own Node.js project?
Yes. After compiling the TypeScript source, you can import functions like handleGraphVfs and parseReadTargetPath directly from the compiled output. The module uses standard ES module syntax (import/export) compatible with Node.js applications.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →