caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

106 lines
2.8 KiB
Go

package dolt
import (
"context"
"encoding/json"
"fmt"
)
// SlotSet sets a key-value pair in the issue's metadata JSON.
// If the issue has no metadata, a new JSON object is created.
// If the key already exists, its value is overwritten.
func (s *DoltStore) SlotSet(ctx context.Context, issueID, key, value, actor string) error {
issue, err := s.GetIssue(ctx, issueID)
if err != nil {
return fmt.Errorf("getting issue %s: %w", issueID, err)
}
metadata := make(map[string]interface{})
if len(issue.Metadata) > 0 {
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
return fmt.Errorf("parsing metadata for %s: %w", issueID, err)
}
}
metadata[key] = value
raw, err := json.Marshal(metadata)
if err != nil {
return fmt.Errorf("marshaling metadata for %s: %w", issueID, err)
}
updates := map[string]interface{}{
"metadata": string(raw),
}
return s.UpdateIssue(ctx, issueID, updates, actor)
}
// SlotGet retrieves the value of a metadata key from an issue.
// Returns an error if the issue has no metadata or the key is not found.
func (s *DoltStore) SlotGet(ctx context.Context, issueID, key string) (string, error) {
issue, err := s.GetIssue(ctx, issueID)
if err != nil {
return "", fmt.Errorf("getting issue %s: %w", issueID, err)
}
if len(issue.Metadata) == 0 {
return "", fmt.Errorf("no slot %q on %s: no metadata", key, issueID)
}
metadata := make(map[string]interface{})
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
return "", fmt.Errorf("parsing metadata for %s: %w", issueID, err)
}
val, ok := metadata[key]
if !ok {
return "", fmt.Errorf("no slot %q on %s: key not found", key, issueID)
}
switch v := val.(type) {
case string:
return v, nil
default:
// Non-string values are returned as JSON
raw, err := json.Marshal(v)
if err != nil {
return "", fmt.Errorf("marshaling slot value for %s.%s: %w", issueID, key, err)
}
return string(raw), nil
}
}
// SlotClear removes a metadata key from an issue.
// It is not an error to clear a key that doesn't exist.
func (s *DoltStore) SlotClear(ctx context.Context, issueID, key, actor string) error {
issue, err := s.GetIssue(ctx, issueID)
if err != nil {
return fmt.Errorf("getting issue %s: %w", issueID, err)
}
if len(issue.Metadata) == 0 {
return nil // No metadata, nothing to clear
}
metadata := make(map[string]interface{})
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
return fmt.Errorf("parsing metadata for %s: %w", issueID, err)
}
if _, ok := metadata[key]; !ok {
return nil // Key doesn't exist, nothing to clear
}
delete(metadata, key)
raw, err := json.Marshal(metadata)
if err != nil {
return fmt.Errorf("marshaling metadata for %s: %w", issueID, err)
}
updates := map[string]interface{}{
"metadata": string(raw),
}
return s.UpdateIssue(ctx, issueID, updates, actor)
}