Skip to Content
Mind Palace 0.3.1-alpha is out. Check it out →
ReferencePublic API

Public API

Mind Palace provides public Go packages that external tools can import to interact with workspace memory and corridors.

Installation

go get github.com/koksalmehmet/mind-palace/apps/cli/pkg/memory go get github.com/koksalmehmet/mind-palace/apps/cli/pkg/corridor go get github.com/koksalmehmet/mind-palace/apps/cli/pkg/types

Packages

PackageDescription
pkg/typesShared type definitions and constants
pkg/memoryWorkspace session memory API
pkg/corridorGlobal corridor (cross-workspace) API

pkg/types

Shared type definitions used across memory and corridor packages.

Types

import "github.com/koksalmehmet/mind-palace/apps/cli/pkg/types" // Session represents an agent work session type Session struct { ID string AgentType string // "claude-code", "cursor", "aider", etc. AgentID string // Unique agent instance identifier Goal string // What the agent is trying to accomplish StartedAt time.Time LastActivity time.Time State string // "active", "completed", "abandoned" Summary string } // Activity represents an action taken during a session type Activity struct { ID string SessionID string Kind string // "file_read", "file_edit", "search", "command" Target string // File path or search query Details string // JSON with specifics Timestamp time.Time Outcome string // "success", "failure", "unknown" } // Learning represents an emerged pattern or heuristic type Learning struct { ID string SessionID string // Optional Scope string // "file", "room", "palace", "corridor" ScopePath string // e.g., "auth/login.go" or "auth" Content string // The learning itself Confidence float64 // 0.0-1.0 Source string // "agent", "user", "inferred" CreatedAt time.Time LastUsed time.Time UseCount int } // FileIntel represents intelligence about a file type FileIntel struct { Path string EditCount int LastEdited time.Time LastEditor string FailureCount int Learnings []string }

Constants

// Activity kinds const ( ActivityFileRead = "file_read" ActivityFileEdit = "file_edit" ActivitySearch = "search" ActivityCommand = "command" ) // Session states const ( SessionActive = "active" SessionCompleted = "completed" SessionAbandoned = "abandoned" ) // Learning scopes const ( ScopeFile = "file" ScopeRoom = "room" ScopePalace = "palace" ScopeCorridor = "corridor" )

pkg/memory

Workspace session memory API. Tracks sessions, activities, learnings, and file intelligence.

Opening Memory

import "github.com/koksalmehmet/mind-palace/apps/cli/pkg/memory" // Open workspace memory (creates .palace/memory.db if needed) mem, err := memory.Open("/path/to/workspace") if err != nil { log.Fatal(err) } defer mem.Close()

Sessions

// Start a new session session, err := mem.StartSession("my-agent", "instance-123", "Implement authentication") // Get session by ID session, err := mem.GetSession(sessionID) // List sessions sessions, err := mem.ListSessions(true, 10) // activeOnly=true, limit=10 // End session err := mem.EndSession(sessionID, memory.SessionCompleted, "Authentication implemented")

Activities

// Log an activity err := mem.LogActivity(session.ID, memory.Activity{ Kind: memory.ActivityFileEdit, Target: "auth/login.go", Details: `{"lines_changed": 45}`, Outcome: memory.OutcomeSuccess, }) // Get activities for a session activities, err := mem.GetActivities(sessionID, "", 50) // Get activities for a specific file activities, err := mem.GetActivities("", "auth/login.go", 50)

Learnings

// Add a learning id, err := mem.AddLearning(memory.Learning{ Scope: memory.ScopeFile, ScopePath: "auth/login.go", Content: "Always validate JWT expiration before processing", Confidence: 0.8, Source: memory.SourceAgent, }) // Get learnings by scope learnings, err := mem.GetLearnings("file", "auth/login.go", 10) // Search learnings by content learnings, err := mem.SearchLearnings("authentication", 10) // Reinforce a learning (increase confidence) err := mem.ReinforceLearning(learningID)

File Intelligence

// Record a file edit err := mem.RecordFileEdit("auth/login.go", "claude-code") // Record a failure related to a file err := mem.RecordFileFailure("auth/login.go") // Get file intelligence intel, err := mem.GetFileIntel("auth/login.go") fmt.Printf("Edit count: %d, Failures: %d\n", intel.EditCount, intel.FailureCount) // Get file hotspots (most edited files) hotspots, err := mem.GetFileHotspots(10)

Conflict Detection

// Check if another agent is working on the same file conflict, err := mem.CheckConflict(mySessionID, "auth/login.go") if conflict != nil { fmt.Printf("Warning: %s is also editing this file\n", conflict.OtherAgent) }

pkg/corridor

Global corridor API for cross-workspace knowledge sharing.

Opening Corridor

import "github.com/koksalmehmet/mind-palace/apps/cli/pkg/corridor" // Open global corridor (~/.palace/corridors/personal.db) cor, err := corridor.OpenGlobal() if err != nil { log.Fatal(err) } defer cor.Close()

Personal Learnings

// Add a personal learning (available across all workspaces) err := cor.AddPersonalLearning(corridor.PersonalLearning{ Content: "Always use context.Context for cancellation", Confidence: 0.9, Source: "promoted", OriginWorkspace: "api-service", Tags: []string{"go", "best-practice"}, }) // Get personal learnings learnings, err := cor.GetPersonalLearnings("", 20) // query="", limit=20 // Search personal learnings learnings, err := cor.GetPersonalLearnings("context", 10)
// Link another workspace err := cor.Link("api-service", "/home/user/api-service") // List linked workspaces links, err := cor.GetLinks() for _, link := range links { fmt.Printf("%s -> %s\n", link.Name, link.Path) } // Get learnings from a specific linked workspace learnings, err := cor.GetLinkedLearnings("api-service", 10) // Unlink a workspace err := cor.Unlink("api-service")

Complete Example

package main import ( "fmt" "log" "github.com/koksalmehmet/mind-palace/apps/cli/pkg/memory" ) func main() { // Open workspace memory mem, err := memory.Open("/home/user/myproject") if err != nil { log.Fatal(err) } defer mem.Close() // Start a session session, err := mem.StartSession("my-agent", "agent-001", "Fix authentication bug") if err != nil { log.Fatal(err) } fmt.Printf("Started session: %s\n", session.ID) // Log reading a file mem.LogActivity(session.ID, memory.Activity{ Kind: memory.ActivityFileRead, Target: "auth/jwt.go", Outcome: memory.OutcomeSuccess, }) // Check for conflicts before editing conflict, _ := mem.CheckConflict(session.ID, "auth/jwt.go") if conflict != nil { fmt.Printf("Warning: %s is working on this file\n", conflict.OtherAgent) } // Add a learning mem.AddLearning(memory.Learning{ Scope: memory.ScopeFile, ScopePath: "auth/jwt.go", Content: "JWT secret must be at least 256 bits", Confidence: 0.9, Source: memory.SourceAgent, }) // End session mem.EndSession(session.ID, memory.SessionCompleted, "Fixed JWT validation bug") }
Last updated on