Class: RailsAgents::LocalSync Deprecated
- Inherits:
-
Object
- Object
- RailsAgents::LocalSync
- Defined in:
- lib/rails_agents/local_sync.rb
Overview
Deprecated.
Cloud-to-local authoring pull. Build agents locally (see AGENTS.md) and use
rails-agents sync to push files to the cloud. This class remains for CLI compatibility.
Pulls agent files from Rails Agent Cloud and writes them under app/agents/
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(client: Client.new, root: nil) ⇒ LocalSync
constructor
A new instance of LocalSync.
-
#pull!(agent_id) ⇒ Object
agent_id: cloud agent id (agt_…) or slug/name accepted by the API.
Constructor Details
Instance Method Details
#pull!(agent_id) ⇒ Object
agent_id: cloud agent id (agt_…) or slug/name accepted by the API
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rails_agents/local_sync.rb', line 20 def pull!(agent_id) raise Error, "Not connected — run handshake or set RAILS_AGENTS_API_KEY" unless RailsAgents.config.configured? agent = fetch_agent(agent_id) slug = present(agent["slug"]) || slugify(agent["name"]) || slugify(agent_id) raise Error, "Could not resolve agent slug for #{agent_id}" unless present(slug) files_payload = @client.list_files(agent: agent["id"] || agent_id) files = normalize_files_list(files_payload) written = [] deleted = [] agent_dir = @root.join("app/agents", slug) FileUtils.mkdir_p(agent_dir) files.each do |file| rel = normalize_relative_path(file["path"] || file[:path], slug) abs = @root.join(rel) ensure_inside_agents!(abs, slug) content = file["content"] || file[:content] if content.nil? next end FileUtils.mkdir_p(abs.dirname) File.write(abs, content) written << rel.to_s end { "ok" => true, "agent_id" => agent["id"] || agent_id, "slug" => slug, "written" => written, "deleted" => deleted, "count" => written.size } end |