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>
85 lines
2.5 KiB
Go
85 lines
2.5 KiB
Go
package fix
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
)
|
|
|
|
// Permissions fixes file permission issues in the .beads directory
|
|
func Permissions(path string) error {
|
|
dirs, err := resolveWorkspaceBeadsDirs(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
beadsDirResolved := dirs.resolved
|
|
beadsDir := dirs.local
|
|
|
|
// Check if .beads/ directory exists
|
|
// Use Lstat to detect symlinks - we shouldn't chmod symlinked directories
|
|
// as this would change the target's permissions (problematic on NixOS).
|
|
info, err := os.Lstat(beadsDir)
|
|
if err != nil {
|
|
if !os.IsNotExist(err) {
|
|
return fmt.Errorf("failed to stat .beads directory: %w", err)
|
|
}
|
|
beadsDir = beadsDirResolved
|
|
info, err = os.Lstat(beadsDir)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to stat .beads directory: %w", err)
|
|
}
|
|
}
|
|
|
|
// Skip permission fixes for symlinked .beads directories (common on NixOS with home-manager)
|
|
if info.Mode()&os.ModeSymlink != 0 {
|
|
return nil // Symlink permissions are not meaningful on Unix
|
|
}
|
|
|
|
// Ensure .beads directory has exactly 0700 permissions (owner rwx only)
|
|
expectedDirMode := os.FileMode(0700)
|
|
if info.Mode().Perm() != expectedDirMode {
|
|
if err := os.Chmod(beadsDir, expectedDirMode); err != nil {
|
|
return fmt.Errorf("failed to fix .beads directory permissions: %w", err)
|
|
}
|
|
}
|
|
|
|
// Fix permissions on database file/directory if it exists
|
|
// Resolve the actual database path from config (supports both SQLite and Dolt)
|
|
var dbPath string
|
|
if cfg, err := configfile.Load(beadsDirResolved); err == nil && cfg != nil {
|
|
dbPath = cfg.DatabasePath(beadsDirResolved)
|
|
} else {
|
|
dbPath = filepath.Join(beadsDirResolved, "beads.db")
|
|
}
|
|
|
|
// Use Lstat to detect symlinks - skip chmod for symlinked database files
|
|
if dbInfo, err := os.Lstat(dbPath); err == nil {
|
|
// Skip permission fixes for symlinked database files (NixOS)
|
|
if dbInfo.Mode()&os.ModeSymlink != 0 {
|
|
return nil
|
|
}
|
|
|
|
if dbInfo.IsDir() {
|
|
// Dolt backend: database is a directory, ensure 0700 (owner rwx)
|
|
expectedDirMode := os.FileMode(0700)
|
|
if dbInfo.Mode().Perm() != expectedDirMode {
|
|
if err := os.Chmod(dbPath, expectedDirMode); err != nil {
|
|
return fmt.Errorf("failed to fix database directory permissions: %w", err)
|
|
}
|
|
}
|
|
} else {
|
|
// SQLite backend: database is a file, ensure 0600 (owner rw)
|
|
expectedFileMode := os.FileMode(0600)
|
|
if dbInfo.Mode().Perm() != expectedFileMode {
|
|
if err := os.Chmod(dbPath, expectedFileMode); err != nil {
|
|
return fmt.Errorf("failed to fix database permissions: %w", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|