Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions cmd/rememberize/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main

import (
"fmt"
"io"
"os"
"strings"

"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add <content>",
Short: "Create a new memory",
Long: "Create a new memory. Pass content as an argument, or use \"-\" to read from stdin.",
Args: cobra.MinimumNArgs(1),
RunE: runAdd,
}

var (
addNamespace string
addType string
addMeta string
addExpires string
)

func init() {
addCmd.Flags().StringVar(&addNamespace, "ns", "", "namespace (default: from config)")
addCmd.Flags().StringVar(&addType, "type", "", "memory type: semantic, episodic, procedural (default: from config)")
addCmd.Flags().StringVar(&addMeta, "meta", "", "metadata as JSON string")
addCmd.Flags().StringVar(&addExpires, "expires", "", "expiration time (RFC3339)")
}

func runAdd(cmd *cobra.Command, args []string) error {
cfg := loadConfig()
client := NewClient()

var content string
if args[0] == "-" {
data, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("read stdin: %w", err)
}
content = strings.TrimSpace(string(data))
} else {
content = strings.Join(args, " ")
}

if content == "" {
return fmt.Errorf("content cannot be empty")
}

ns := addNamespace
if ns == "" {
ns = cfg.Defaults.Namespace
}
mt := addType
if mt == "" {
mt = cfg.Defaults.Type
}

var metaPtr *string
if addMeta != "" {
metaPtr = &addMeta
}
var expiresPtr *string
if addExpires != "" {
expiresPtr = &addExpires
}

mem, err := client.CreateMemory(content, ns, mt, metaPtr, expiresPtr)
if err != nil {
return err
}

if jsonOutput {
return printJSON(mem)
}

fmt.Fprintf(os.Stdout, "Created memory %s\n", mem.ID)
fmt.Fprintf(os.Stdout, " namespace: %s\n", mem.Namespace)
fmt.Fprintf(os.Stdout, " type: %s\n", mem.Type)
fmt.Fprintf(os.Stdout, " content: %s\n", truncate(mem.Content, 80))
return nil
}
59 changes: 59 additions & 0 deletions cmd/rememberize/audit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/spf13/cobra"
)

var auditCmd = &cobra.Command{
Use: "audit",
Short: "View audit log",
RunE: runAudit,
}

var (
auditLimit int
auditAction string
auditConnectionID string
)

func init() {
auditCmd.Flags().IntVar(&auditLimit, "limit", 20, "max entries to return")
auditCmd.Flags().StringVar(&auditAction, "action", "", "filter by action")
auditCmd.Flags().StringVar(&auditConnectionID, "connection-id", "", "filter by connection ID")
}

func runAudit(cmd *cobra.Command, args []string) error {
client := NewClient()

entries, err := client.ListAudit(auditLimit, auditAction, auditConnectionID)
if err != nil {
return err
}

if jsonOutput {
return printJSON(entries)
}

if len(entries) == 0 {
fmt.Fprintln(os.Stdout, "No audit entries found.")
return nil
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "ID\tACTION\tCONNECTION\tMEMORY\tCREATED")
for _, e := range entries {
memID := "-"
if e.MemoryID != nil {
memID = *e.MemoryID
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
e.ID, e.Action, e.ConnectionID, memID, e.CreatedAt,
)
}
w.Flush()
return nil
}
69 changes: 69 additions & 0 deletions cmd/rememberize/configcmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
)

var configCmd = &cobra.Command{
Use: "config",
Short: "Show or update CLI configuration",
Long: "Show current configuration, or use 'config set <key> <value>' to update.",
RunE: runConfigShow,
}

var configSetCmd = &cobra.Command{
Use: "set <key> <value>",
Short: "Set a config value",
Long: "Set a config value. Keys: auth.api_url, auth.api_key, defaults.namespace, defaults.type, defaults.format",
Args: cobra.ExactArgs(2),
RunE: runConfigSet,
}

func init() {
configCmd.AddCommand(configSetCmd)
}

func runConfigShow(cmd *cobra.Command, args []string) error {
cfg := loadConfig()

if jsonOutput {
return printJSON(cfg)
}

fmt.Fprintf(os.Stdout, "Config file: %s\n\n", configPath())
fmt.Fprintln(os.Stdout, "[auth]")
fmt.Fprintf(os.Stdout, " api_url = %s\n", cfg.Auth.APIURL)
if cfg.Auth.APIKey != "" {
masked := strings.Repeat("*", max(0, len(cfg.Auth.APIKey)-4)) + cfg.Auth.APIKey[max(0, len(cfg.Auth.APIKey)-4):]
fmt.Fprintf(os.Stdout, " api_key = %s\n", masked)
} else {
fmt.Fprintln(os.Stdout, " api_key = (not set)")
}
fmt.Fprintln(os.Stdout)
fmt.Fprintln(os.Stdout, "[defaults]")
fmt.Fprintf(os.Stdout, " namespace = %s\n", cfg.Defaults.Namespace)
fmt.Fprintf(os.Stdout, " type = %s\n", cfg.Defaults.Type)
fmt.Fprintf(os.Stdout, " format = %s\n", cfg.Defaults.Format)

return nil
}

func runConfigSet(cmd *cobra.Command, args []string) error {
cfg := loadConfig()

key, value := args[0], args[1]
if err := setConfigValue(cfg, key, value); err != nil {
return err
}

if err := saveConfig(cfg); err != nil {
return err
}

fmt.Fprintf(os.Stdout, "Set %s = %s\n", key, value)
return nil
}
47 changes: 47 additions & 0 deletions cmd/rememberize/connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/spf13/cobra"
)

var connectionsCmd = &cobra.Command{
Use: "connections",
Short: "List connections",
RunE: runConnections,
}

func runConnections(cmd *cobra.Command, args []string) error {
client := NewClient()

connections, err := client.ListConnections()
if err != nil {
return err
}

if jsonOutput {
return printJSON(connections)
}

if len(connections) == 0 {
fmt.Fprintln(os.Stdout, "No connections found.")
return nil
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tTYPE\tACTIVE\tLAST SEEN\tCREATED")
for _, c := range connections {
active := "no"
if c.IsActive {
active = "yes"
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
c.ID, c.Name, c.Type, active, c.LastSeen, c.CreatedAt,
)
}
w.Flush()
return nil
}
68 changes: 68 additions & 0 deletions cmd/rememberize/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
)

var exportCmd = &cobra.Command{
Use: "export",
Short: "Export memories to a file",
Long: "Export memories as Claude MEMORY.md, JSON, or CSV",
RunE: runExport,
}

var (
exportFormat string
exportNamespace string
exportOutput string
)

func init() {
exportCmd.Flags().StringVar(&exportFormat, "format", "json", "Export format (memory-md, json, csv)")
exportCmd.Flags().StringVar(&exportNamespace, "namespace", "", "Export only this namespace")
exportCmd.Flags().StringVar(&exportOutput, "output", "", "Output file path (defaults to stdout)")
}

func runExport(cmd *cobra.Command, args []string) error {
client := NewClient()

url := "/api/export?format=" + exportFormat
if exportNamespace != "" {
url += "&namespace=" + exportNamespace
}

req, err := client.newRequest("GET", url, nil)
if err != nil {
return err
}

resp, err := client.HTTP.Do(req)
if err != nil {
return fmt.Errorf("export request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
respBody, _ := io.ReadAll(resp.Body)
return fmt.Errorf("export failed (HTTP %d): %s", resp.StatusCode, respBody)
}

data, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("read response: %w", err)
}

if exportOutput != "" {
if err := os.WriteFile(exportOutput, data, 0644); err != nil {
return fmt.Errorf("write file: %w", err)
}
fmt.Printf("Exported to %s\n", exportOutput)
} else {
_, _ = os.Stdout.Write(data)
}
return nil
}
46 changes: 46 additions & 0 deletions cmd/rememberize/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var getCmd = &cobra.Command{
Use: "get <id>",
Short: "Get a single memory by ID",
Args: cobra.ExactArgs(1),
RunE: runGet,
}

func runGet(cmd *cobra.Command, args []string) error {
client := NewClient()

mem, err := client.GetMemory(args[0])
if err != nil {
return err
}

if jsonOutput {
return printJSON(mem)
}

fmt.Fprintf(os.Stdout, "ID: %s\n", mem.ID)
fmt.Fprintf(os.Stdout, "Namespace: %s\n", mem.Namespace)
fmt.Fprintf(os.Stdout, "Type: %s\n", mem.Type)
fmt.Fprintf(os.Stdout, "Version: %d\n", mem.Version)
fmt.Fprintf(os.Stdout, "Created: %s\n", mem.CreatedAt)
fmt.Fprintf(os.Stdout, "Updated: %s\n", mem.UpdatedAt)
if mem.ExpiresAt != nil {
fmt.Fprintf(os.Stdout, "Expires: %s\n", *mem.ExpiresAt)
}
if mem.Metadata != nil {
fmt.Fprintf(os.Stdout, "Metadata: %s\n", *mem.Metadata)
}
if mem.SourceID != nil {
fmt.Fprintf(os.Stdout, "Source ID: %s\n", *mem.SourceID)
}
fmt.Fprintf(os.Stdout, "\n%s\n", mem.Content)
return nil
}
Loading
Loading