Vibe-coded SB v2 Git plugin -_-||

As a novice in Lua, I constructed — guided solely by logical reasoning and a touch of “vibe coding” — an SB v2 Git synchronization sequence. GPT-5 has already given it a scathing review, labeling it a “code monstrosity.” :slight_smile:

Even so, each operation is clearly traceable (through editor.flashNotifications), and synchronization has been achieved reliably across 3 instances: local Windows, a read-only and a read-write Fly.io Linux instance.

This means the functionality is, in principle, secure — though recommend creating backups before use.

Compared with the official version, my implementation adds two commands: one for force-pushing to the origin as the initial commit, and another for force-pulling from the remote back to the local repository.

While I feel that my aesthetic judgment and logical reasoning are sound, I have not invested sufficient time to master Lua. I hope this plugin can offer some insights to others.

If needed, I am willing to share my Fly.io configurations, including the fly.toml, Dockerfile, and init.sh files.

manual/periodic/event-driven sync


image

commit (manual)

image

force pull (manual)

force push (manual)


image

Here’s the code: GitHub - ChenZhu-Xie/SB_git.md: manual/periodic/event-driven sync + basic git functional plugin for SilverBullet v2

As is my experience writing code with AI agents, this is a lot of code. I wanted to quickly read it, but… it’s a lot to evaluate. But you know, if it works for you it’s great!

1 Like
git = {}
gitConfig = config.get("git", {})
git.autoSync = gitConfig.autoSync or true
git.autoCommitMinutes = gitConfig.autoCommitMinutes or 5
git.autoSyncDelay = gitConfig.autoSyncDelay or 60
git.skipInitialSync = gitConfig.skipInitialSync or false

function git.commit(message)
  message = message or "Snapshot"
  print "Comitting..."
  local ok, message = pcall(function()
    shell.run("git", {"add", "./*"})
    shell.run("git", {"commit", "-a", "-m", message})
  end)
  if not ok then
    print("Git commit failed: " .. message)
  end
end

function git.sync()
  git.commit()
  print "Pulling..."
  shell.run("git", {"pull"})
  print "Pushing..."
  shell.run("git", {"push"})
end

command.define {
  name = "Git: Commit",
  run = function()
    local message = editor.prompt "Commit message:"
    git.commit(message)
  end
}

command.define {
  name = "Git: Sync",
  run = function()
    git.sync()
    editor.flashNotification "Done!"
  end
}

if git.autoSync then
  if git.skipInitialSync then
    git.previousCommit = os.time()
  end
  
  event.listen {
    name = "cron:secondPassed",
    run = function()
      local currentTime = os.time()
    
      if currentTime - git.previousCheck > git.autoSyncDelay then
        git.previousCheck = currentTime
        local elapsedMinutes = (currentTime - git.previousCommit) / 60
        
        if elapsedMinutes > git.autoCommitMinutes then
          git.previousCommit = os.time()
          editor.flashNotification "Starting git autosync."
          system.invokeCommand('Git: Sync')
        end
      end
    end
  }
else
  print("Git autoSync is not enabled.")
end

thanks to @zef. Feel free to share and merge your improments

1 Like

@malys yes @ChenZhu-Xie knows about it, this is a “fork”:

2 Likes

my read-only instance https://enlarge-the-percentage.fly.dev/ is under construction, and welcome to visit! Take a seat!

(post deleted by author)