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

111 lines
3.3 KiB
Go

package main
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/spf13/cobra"
)
// mailCmd delegates to an external mail provider.
// This enables agents to use 'bd mail' consistently, while the actual
// mail implementation is provided by the orchestrator.
var mailCmd = &cobra.Command{
Use: "mail [subcommand] [args...]",
Short: "Delegate to mail provider (e.g., gt mail)",
Long: `Delegates mail operations to an external mail provider.
Agents often type 'bd mail' when working with beads, but mail functionality
is typically provided by the orchestrator. This command bridges that gap
by delegating to the configured mail provider.
Configuration (checked in order):
1. BEADS_MAIL_DELEGATE or BD_MAIL_DELEGATE environment variable
2. 'mail.delegate' config setting (bd config set mail.delegate "gt mail")
Examples:
# Configure delegation (one-time setup)
export BEADS_MAIL_DELEGATE="gt mail"
# or
bd config set mail.delegate "gt mail"
# Then use bd mail as if it were gt mail
bd mail inbox # Lists inbox
bd mail send mayor/ -s "Hi" # Sends mail
bd mail read msg-123 # Reads a message`,
DisableFlagParsing: true, // Pass all args through to delegate
Run: func(cmd *cobra.Command, args []string) {
// Handle --help and -h ourselves since flag parsing is disabled
for _, arg := range args {
if arg == "--help" || arg == "-h" {
_ = cmd.Help() // Help() always returns nil for cobra commands
return
}
}
// Find the mail delegate command
delegate := findMailDelegate()
if delegate == "" {
fmt.Fprintf(os.Stderr, "Error: no mail delegate configured\n\n")
fmt.Fprintf(os.Stderr, "bd mail delegates to an external mail provider.\n")
fmt.Fprintf(os.Stderr, "Configure one of:\n")
fmt.Fprintf(os.Stderr, " export BEADS_MAIL_DELEGATE=\"gt mail\" # Environment variable\n")
fmt.Fprintf(os.Stderr, " bd config set mail.delegate \"gt mail\" # Per-project config\n")
os.Exit(1)
}
// Parse the delegate command (e.g., "gt mail" -> ["gt", "mail"])
parts := strings.Fields(delegate)
if len(parts) == 0 {
FatalError("invalid mail delegate: %q", delegate)
}
// Build the full command with our args appended
cmdName := parts[0]
cmdArgs := append(parts[1:], args...)
// Execute the delegate command
// #nosec G204 - cmdName comes from user configuration (mail_delegate setting)
execCmd := exec.Command(cmdName, cmdArgs...)
execCmd.Stdin = os.Stdin
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
if err := execCmd.Run(); err != nil {
// Try to preserve the exit code
if exitErr, ok := err.(*exec.ExitError); ok {
os.Exit(exitErr.ExitCode())
}
FatalError("running %s: %v", delegate, err)
}
},
}
// findMailDelegate checks for mail delegation configuration
// Priority: env vars > bd config
func findMailDelegate() string {
// Check environment variables first
if delegate := os.Getenv("BEADS_MAIL_DELEGATE"); delegate != "" {
return delegate
}
if delegate := os.Getenv("BD_MAIL_DELEGATE"); delegate != "" {
return delegate
}
// Check bd config (requires database)
// This works even without a database connection since we use direct mode
if store != nil {
if delegate, err := store.GetConfig(rootCtx, "mail.delegate"); err == nil && delegate != "" {
return delegate
}
}
return ""
}
func init() {
rootCmd.AddCommand(mailCmd)
}