mildred 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de56f48260541ab8a7a5640f9018068a3773d7b4f4b749655ab8a07721a99beb
4
+ data.tar.gz: ae48b95cf7970981c92667b0cd62c2c7c9e66a6000a9c5789134ea333af8b855
5
+ SHA512:
6
+ metadata.gz: 3071f33fb3167174a0c66d62aa2778ec7e2c0060bcc61f246d431bcc6e19d5177622f2d771f4681b03b764320d5b4c1d634cf9cc433a0e04e68213b60d0828d0
7
+ data.tar.gz: 5b013bd30c7888d2b2ab75ccfa404709544b6f03ffbcda957b678f98a832410a262da51360ec9374527ba44293854dd8a12c8cedcf2291e9f16c3b6ac8bd846c
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-02-14
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Sam McClenaghan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Mildred
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mildred`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mildred. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/mildred/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Mildred project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mildred/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/exe/mildred ADDED
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "optparse"
5
+ require "fileutils"
6
+ require "yaml"
7
+ require "mildred"
8
+ require "gum"
9
+
10
+ Mildred.configure!
11
+
12
+ SAMPLE_RULES = <<~YAML
13
+ jobs:
14
+ - name: Clean Downloads
15
+ directory: ~/Downloads
16
+ tasks:
17
+ - Delete duplicate files
18
+ - Remove files older than 30 days
19
+
20
+ - name: Organize Documents
21
+ directory: ~/Documents
22
+ destinations:
23
+ - ~/Documents/PDFs
24
+ - ~/Documents/Spreadsheets
25
+ tasks:
26
+ - Move PDF files to the PDFs folder
27
+ - Move spreadsheet files to the Spreadsheets folder
28
+ YAML
29
+
30
+ SAMPLE_CONFIG = <<~YAML
31
+ # Mildred configuration
32
+ # Provider: ollama, openai, or openrouter
33
+ provider: ollama
34
+ model: llama3.1:8b
35
+
36
+ # Ollama settings
37
+ ollama_url: http://localhost:11434/v1
38
+
39
+ # OpenAI settings
40
+ # openai_api_key: sk-...
41
+
42
+ # OpenRouter settings
43
+ # openrouter_api_key: sk-or-...
44
+ YAML
45
+
46
+ MILDRED_DIR = File.join(Dir.home, ".mildred")
47
+ LOG_PATH = File.join(MILDRED_DIR, "mildred.log")
48
+
49
+ DEFAULT_MODELS = {
50
+ "ollama" => "llama3.1:8b",
51
+ "openai" => "gpt-4o",
52
+ "openrouter" => "anthropic/claude-sonnet-4"
53
+ }.freeze
54
+
55
+ command = ARGV.shift
56
+
57
+ case command
58
+ when "clean"
59
+ rules_path = Mildred::Runner::DEFAULT_RULES_PATH
60
+ noop = false
61
+ silent = false
62
+
63
+ parser = OptionParser.new do |opts|
64
+ opts.banner = "Usage: mildred clean [options]"
65
+
66
+ opts.on("-n", "--noop", "Dry run — no changes will be made") do
67
+ noop = true
68
+ end
69
+
70
+ opts.on("-r", "--rules FILE", "Use a custom rules file") do |file|
71
+ rules_path = file
72
+ end
73
+
74
+ opts.on("-s", "--silent", "Suppress output") do
75
+ silent = true
76
+ end
77
+ end
78
+
79
+ parser.parse!(ARGV)
80
+
81
+ unless File.exist?(rules_path)
82
+ puts Gum.style("Error: Rules file not found: #{rules_path}", foreground: "196")
83
+ exit 1
84
+ end
85
+
86
+ runner = Mildred::Runner.new(path: rules_path, noop: noop)
87
+ runner.run
88
+
89
+ when "version"
90
+ puts Mildred::VERSION
91
+
92
+ when "setup"
93
+ puts Gum.style("Mildred Setup", foreground: "212", bold: true)
94
+ puts
95
+
96
+ provider = Gum.choose("ollama", "openai", "openrouter", header: "Choose a provider:")
97
+
98
+ unless provider
99
+ puts Gum.style("Setup cancelled.", foreground: "196")
100
+ exit 1
101
+ end
102
+
103
+ model = Gum.input(
104
+ placeholder: DEFAULT_MODELS[provider],
105
+ value: DEFAULT_MODELS[provider],
106
+ header: "Model:"
107
+ )
108
+
109
+ unless model && !model.empty?
110
+ puts Gum.style("Setup cancelled.", foreground: "196")
111
+ exit 1
112
+ end
113
+
114
+ config = { "provider" => provider, "model" => model }
115
+
116
+ case provider
117
+ when "ollama"
118
+ url = Gum.input(
119
+ placeholder: "http://localhost:11434/v1",
120
+ value: "http://localhost:11434/v1",
121
+ header: "Ollama URL:"
122
+ )
123
+ config["ollama_url"] = url if url && !url.empty?
124
+ when "openai"
125
+ key = Gum.input(header: "OpenAI API key:", password: true)
126
+ unless key && !key.empty?
127
+ puts Gum.style("API key is required.", foreground: "196")
128
+ exit 1
129
+ end
130
+ config["openai_api_key"] = key
131
+ when "openrouter"
132
+ key = Gum.input(header: "OpenRouter API key:", password: true)
133
+ unless key && !key.empty?
134
+ puts Gum.style("API key is required.", foreground: "196")
135
+ exit 1
136
+ end
137
+ config["openrouter_api_key"] = key
138
+ end
139
+
140
+ config_dir = Mildred::Configuration::CONFIG_DIR
141
+ FileUtils.mkdir_p(config_dir)
142
+ File.write(Mildred::Configuration::CONFIG_PATH, YAML.dump(config))
143
+ puts Gum.style(" ✓ Config written to #{Mildred::Configuration::CONFIG_PATH}", foreground: "46")
144
+
145
+ FileUtils.mkdir_p(MILDRED_DIR)
146
+ rules_path = Mildred::Runner::DEFAULT_RULES_PATH
147
+ unless File.exist?(rules_path)
148
+ File.write(rules_path, SAMPLE_RULES)
149
+ puts Gum.style(" ✓ Sample rules written to #{rules_path}", foreground: "46")
150
+ end
151
+
152
+ puts
153
+ puts Gum.style("Ready! Run `mildred clean` to get started.", foreground: "212", bold: true)
154
+
155
+ when "sample"
156
+ FileUtils.mkdir_p(MILDRED_DIR)
157
+
158
+ rules_sample = File.join(MILDRED_DIR, "rules.sample.yml")
159
+ File.write(rules_sample, SAMPLE_RULES)
160
+ puts Gum.style(" ✓ #{rules_sample}", foreground: "46")
161
+
162
+ config_sample = File.join(MILDRED_DIR, "config.sample.yml")
163
+ File.write(config_sample, SAMPLE_CONFIG)
164
+ puts Gum.style(" ✓ #{config_sample}", foreground: "46")
165
+
166
+ when "logs"
167
+ path_only = false
168
+ tail = false
169
+
170
+ parser = OptionParser.new do |opts|
171
+ opts.banner = "Usage: mildred logs [options]"
172
+
173
+ opts.on("-p", "--path", "Show log file path") do
174
+ path_only = true
175
+ end
176
+
177
+ opts.on("-t", "--tail", "Tail the log file") do
178
+ tail = true
179
+ end
180
+ end
181
+
182
+ parser.parse!(ARGV)
183
+
184
+ if tail
185
+ exec "tail", "-f", LOG_PATH
186
+ elsif path_only
187
+ puts LOG_PATH
188
+ else
189
+ unless File.exist?(LOG_PATH)
190
+ puts Gum.style("No log file found at #{LOG_PATH}", foreground: "196")
191
+ exit 1
192
+ end
193
+ Gum.pager(File.read(LOG_PATH), show_line_numbers: true, soft_wrap: true)
194
+ end
195
+
196
+ else
197
+ header = Gum.style("Mildred - AI-powered file organizer", foreground: "212", bold: true)
198
+ puts header
199
+ puts
200
+ puts "Commands:"
201
+ puts " clean Organize files using rules"
202
+ puts " setup Interactive first-time setup"
203
+ puts " sample Generate sample config and rules files"
204
+ puts " logs Show or tail the log file"
205
+ puts " version Show version"
206
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "ruby_llm"
5
+
6
+ module Mildred
7
+ class Agent < RubyLLM::Agent
8
+ instructions <<~PROMPT
9
+ You are Mildred, an autonomous file organization agent.
10
+ You execute file organization tasks without asking questions or waiting for confirmation.
11
+
12
+ When given tasks, you should:
13
+ 1. List and inspect the files in the target directory
14
+ 2. Analyze file types, names, dates, and sizes
15
+ 3. Execute the requested tasks immediately using your tools
16
+
17
+ Do not ask for confirmation. Do not propose plans. Just execute.
18
+ PROMPT
19
+
20
+ tools Mildred::Tools::RunCommand
21
+
22
+ def self.build
23
+ model_id = Mildred.configuration.model
24
+ provider = Mildred.configuration.provider.to_sym
25
+
26
+ chat = RubyLLM.chat(
27
+ model: model_id,
28
+ provider: provider,
29
+ assume_model_exists: true
30
+ )
31
+
32
+ new(chat: chat)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Mildred
6
+ class Configuration
7
+ DEFAULTS = {
8
+ "provider" => "ollama",
9
+ "model" => "llama3.1:8b",
10
+ "ollama_url" => "http://localhost:11434/v1"
11
+ }.freeze
12
+
13
+ CONFIG_DIR = File.join(Dir.home, ".mildred")
14
+ CONFIG_PATH = File.join(CONFIG_DIR, "config.yml")
15
+
16
+ attr_reader :provider, :model, :settings
17
+
18
+ def initialize
19
+ @settings = load_config
20
+ @provider = @settings["provider"]
21
+ @model = @settings["model"]
22
+ end
23
+
24
+ def apply!
25
+ config_data = @settings
26
+
27
+ RubyLLM.configure do |config|
28
+ case @provider
29
+ when "ollama"
30
+ config.ollama_api_base = config_data["ollama_url"]
31
+ when "openai"
32
+ config.openai_api_key = config_data["openai_api_key"]
33
+ when "openrouter"
34
+ config.openrouter_api_key = config_data["openrouter_api_key"]
35
+ end
36
+
37
+ config.default_model = @model
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def load_config
44
+ if File.exist?(CONFIG_PATH)
45
+ DEFAULTS.merge(YAML.safe_load_file(CONFIG_PATH) || {})
46
+ else
47
+ DEFAULTS.dup
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "securerandom"
5
+
6
+ module Mildred
7
+ class Container
8
+ class Error < StandardError; end
9
+
10
+ IMAGE = "mildred-sandbox:latest"
11
+
12
+ CONTAINERFILE = <<~DOCKERFILE
13
+ FROM alpine:3.20
14
+ RUN apk add --no-cache bash coreutils findutils
15
+ DOCKERFILE
16
+
17
+ attr_reader :id
18
+
19
+ def initialize(job:)
20
+ @job = job
21
+ @id = nil
22
+ end
23
+
24
+ def start
25
+ ensure_mount_paths_exist
26
+ @id = run_container
27
+ end
28
+
29
+ def stop
30
+ return unless @id
31
+
32
+ run_cli("container", "stop", @id)
33
+ run_cli("container", "rm", @id)
34
+ @id = nil
35
+ end
36
+
37
+ def self.ensure_image
38
+ return if image_exists?
39
+
40
+ build_image
41
+ end
42
+
43
+ def self.cleanup_stale
44
+ ids = stale_container_ids
45
+ return if ids.empty?
46
+
47
+ ids.each do |id|
48
+ Open3.capture3("container", "stop", id)
49
+ Open3.capture3("container", "rm", id)
50
+ end
51
+ end
52
+
53
+ class << self
54
+ private
55
+
56
+ def image_exists?
57
+ stdout, _, status = Open3.capture3("container", "image", "list", "--format", "json")
58
+ return false unless status.success?
59
+
60
+ images = JSON.parse(stdout)
61
+ images.any? { |img| img["reference"]&.end_with?(IMAGE) }
62
+ end
63
+
64
+ def build_image
65
+ Dir.mktmpdir do |dir|
66
+ File.write(File.join(dir, "Containerfile"), CONTAINERFILE)
67
+
68
+ _stdout, stderr, status = Open3.capture3(
69
+ "container", "build", "-t", IMAGE, dir
70
+ )
71
+ raise Error, "Failed to build image: #{stderr}" unless status.success?
72
+ end
73
+ end
74
+
75
+ def stale_container_ids
76
+ stdout, _, status = Open3.capture3("container", "ls", "-a", "--quiet")
77
+ return [] unless status.success?
78
+
79
+ stdout.lines.map(&:strip).select { |id| id.start_with?("mildred-") }
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def ensure_mount_paths_exist
86
+ paths = ([@job.directory] + @job.destinations).uniq
87
+ paths.each { |path| FileUtils.mkdir_p(path) }
88
+ end
89
+
90
+ def run_container
91
+ name = "mildred-#{Process.pid}-#{SecureRandom.hex(4)}"
92
+
93
+ args = ["container", "run", "-d", "--name", name]
94
+ args.concat(mount_args)
95
+ args.concat([IMAGE, "sleep", "infinity"])
96
+
97
+ _stdout, stderr, status = Open3.capture3(*args)
98
+ raise Error, "Failed to start container: #{stderr}" unless status.success?
99
+
100
+ name
101
+ end
102
+
103
+ def mount_args
104
+ paths = ([@job.directory] + @job.destinations).uniq
105
+ paths.flat_map { |path| ["-v", "#{path}:#{path}"] }
106
+ end
107
+
108
+ def run_cli(*args)
109
+ Open3.capture3(*args)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/current_attributes"
5
+
6
+ module Mildred
7
+ class Current < ActiveSupport::CurrentAttributes
8
+ attribute :container_id, :noop, :job_name
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Mildred
6
+ class Job
7
+ class ParseError < StandardError; end
8
+
9
+ attr_reader :name, :directory, :destinations, :tasks
10
+
11
+ def self.from_yaml(path)
12
+ data = YAML.safe_load_file(path) || {}
13
+
14
+ raise ParseError, "Missing 'jobs' key" unless data.is_a?(Hash) && data.key?("jobs")
15
+
16
+ data["jobs"].map { |entry| parse_job(entry) }
17
+ end
18
+
19
+ def self.parse_job(entry)
20
+ raise ParseError, "Job is missing 'name'" unless entry["name"]
21
+ raise ParseError, "Job is missing 'directory'" unless entry["directory"]
22
+ raise ParseError, "Job is missing 'tasks'" unless entry["tasks"]
23
+ raise ParseError, "Job 'tasks' cannot be empty" if entry["tasks"].empty?
24
+
25
+ new(
26
+ name: entry["name"],
27
+ directory: File.expand_path(entry["directory"]),
28
+ destinations: (entry["destinations"] || []).map { |d| File.expand_path(d) },
29
+ tasks: entry["tasks"]
30
+ )
31
+ end
32
+ private_class_method :parse_job
33
+
34
+ private
35
+
36
+ def initialize(name:, directory:, destinations:, tasks:)
37
+ @name = name
38
+ @directory = directory
39
+ @destinations = destinations
40
+ @tasks = tasks
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Mildred
6
+ class Logger
7
+ LOG_DIR = File.join(Dir.home, ".mildred")
8
+ LOG_PATH = File.join(LOG_DIR, "mildred.log")
9
+
10
+ attr_reader :entries
11
+
12
+ def initialize
13
+ @entries = []
14
+ end
15
+
16
+ def log(command, stdout, stderr, exit_code)
17
+ @entries << {
18
+ command: command,
19
+ stdout: stdout,
20
+ stderr: stderr,
21
+ exit_code: exit_code
22
+ }
23
+
24
+ fields = { event: "exec", command: command, exit_code: exit_code }
25
+ fields[:stdout] = truncate(stdout) unless stdout.empty?
26
+ fields[:stderr] = truncate(stderr) unless stderr.empty?
27
+ write(**fields)
28
+ end
29
+
30
+ def log_job_start(job_name)
31
+ write(event: "started", job: job_name)
32
+ end
33
+
34
+ def log_job_end(job_name, success:, error: nil)
35
+ status = success ? "success" : "error"
36
+ fields = { event: "completed", job: job_name, status: status }
37
+ fields[:error] = error if error
38
+ write(**fields)
39
+ end
40
+
41
+ def clear
42
+ @entries = []
43
+ end
44
+
45
+ private
46
+
47
+ def write(**fields)
48
+ FileUtils.mkdir_p(LOG_DIR)
49
+
50
+ job = fields.delete(:job) || Mildred::Current.job_name
51
+ timestamp = Time.now.iso8601
52
+
53
+ parts = ["[#{timestamp}]"]
54
+ parts << "job=#{quote(job)}" if job
55
+ fields.each { |k, v| parts << "#{k}=#{quote(v)}" }
56
+
57
+ File.open(LOG_PATH, "a") { |f| f.puts(parts.join(" ")) }
58
+ end
59
+
60
+ def truncate(value, max: 200)
61
+ value = value.to_s.strip.gsub("\n", "\\n")
62
+ value.length > max ? "#{value[0, max]}..." : value
63
+ end
64
+
65
+ def quote(value)
66
+ value = value.to_s
67
+ value.include?(" ") ? "\"#{value}\"" : value
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gum"
4
+
5
+ module Mildred
6
+ class Runner
7
+ DEFAULT_RULES_PATH = File.join(Dir.home, ".mildred", "rules.yml")
8
+
9
+ attr_reader :jobs, :noop
10
+
11
+ def initialize(path: DEFAULT_RULES_PATH, noop: false)
12
+ @jobs = Job.from_yaml(path)
13
+ @noop = noop
14
+ end
15
+
16
+ def run
17
+ if @noop
18
+ puts Gum.style("▸ Dry run — no changes will be made", foreground: "220", bold: true)
19
+ puts
20
+ else
21
+ Gum.spin("Cleaning up stale containers...", spinner: :dot) { Container.cleanup_stale }
22
+ Gum.spin("Ensuring sandbox image...", spinner: :dot) { Container.ensure_image }
23
+ puts
24
+ end
25
+
26
+ results = @jobs.map do |job|
27
+ puts Gum.style("▸ #{job.name}", foreground: "212", bold: true)
28
+
29
+ result = Gum.spin("Running #{job.name}...", spinner: :dot) do
30
+ execute_job(job)
31
+ end
32
+
33
+ if result == true
34
+ puts Gum.style(" ✓ Done", foreground: "46")
35
+ else
36
+ puts Gum.style(" ✗ Failed", foreground: "196")
37
+ puts Gum.style(" #{result.message}", foreground: "196", faint: true) if result.is_a?(StandardError)
38
+ end
39
+
40
+ result == true
41
+ end
42
+
43
+ passed = results.count { |r| r }
44
+ total = results.length
45
+ puts
46
+ if passed == total
47
+ puts Gum.style("✓ #{passed}/#{total} jobs completed", foreground: "46", bold: true)
48
+ else
49
+ puts Gum.style("⚠ #{passed}/#{total} jobs completed", foreground: "220", bold: true)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ MAX_RETRIES = 2
56
+
57
+ def execute_job(job)
58
+ Mildred::Current.job_name = job.name
59
+ Mildred.logger.log_job_start(job.name)
60
+
61
+ if @noop
62
+ Mildred::Current.noop = true
63
+ else
64
+ container = Container.new(job: job)
65
+ container.start
66
+ Mildred::Current.container_id = container.id
67
+ end
68
+
69
+ run_agent(job)
70
+
71
+ Mildred.logger.log_job_end(job.name, success: true)
72
+ true
73
+ rescue StandardError => e
74
+ Mildred.logger.log_job_end(job.name, success: false, error: e.message)
75
+ e
76
+ ensure
77
+ Mildred::Current.reset
78
+ container&.stop unless @noop
79
+ end
80
+
81
+ def run_agent(job, attempt: 1)
82
+ agent = Agent.build
83
+ prompt = build_prompt(job)
84
+ agent.ask(prompt)
85
+ rescue StandardError => e
86
+ raise unless attempt < MAX_RETRIES
87
+
88
+ Mildred.logger.log(
89
+ "retry", "[attempt #{attempt} failed: #{e.message}]", "", 0
90
+ )
91
+ run_agent(job, attempt: attempt + 1)
92
+ end
93
+
94
+ def build_prompt(job)
95
+ lines = []
96
+ lines << "You are organizing the directory: #{job.directory}"
97
+
98
+ lines << "Available destinations: #{job.destinations.join(", ")}" unless job.destinations.empty?
99
+
100
+ lines << ""
101
+ lines << "Complete the following tasks:"
102
+ job.tasks.each_with_index do |task, i|
103
+ lines << "#{i + 1}. #{task}"
104
+ end
105
+
106
+ lines << ""
107
+ lines << "Do not ask questions. Execute each task using your tools."
108
+
109
+ lines.join("\n")
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gum"
4
+ require "open3"
5
+
6
+ module Mildred
7
+ module Tools
8
+ class RunCommand < RubyLLM::Tool
9
+ description "Executes a shell command and returns its output. Use this to organize, move, delete, and inspect files."
10
+
11
+ param :command, desc: "The shell command to execute"
12
+
13
+ def execute(command:)
14
+ if Mildred::Current.noop
15
+ Mildred.logger.log(command, "[noop]", "", 0)
16
+ puts Gum.style(" → #{command}", foreground: "220")
17
+ return { stdout: "[noop] would execute: #{command}", stderr: "", exit_code: 0 }
18
+ end
19
+
20
+ container_id = Mildred::Current.container_id
21
+
22
+ stdout, stderr, status = if container_id
23
+ Open3.capture3("container", "exec", container_id, "bash", "-c", command)
24
+ else
25
+ Open3.capture3("bash", "-c", command)
26
+ end
27
+
28
+ Mildred.logger.log(command, stdout, stderr, status.exitstatus)
29
+
30
+ {
31
+ stdout: stdout,
32
+ stderr: stderr,
33
+ exit_code: status.exitstatus
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mildred
4
+ VERSION = "0.1.0"
5
+ end
data/lib/mildred.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby_llm"
4
+
5
+ require_relative "mildred/version"
6
+ require_relative "mildred/configuration"
7
+ require_relative "mildred/current"
8
+ require_relative "mildred/logger"
9
+ require_relative "mildred/job"
10
+ require_relative "mildred/container"
11
+ require_relative "mildred/tools/run_command"
12
+ require_relative "mildred/agent"
13
+ require_relative "mildred/runner"
14
+
15
+ module Mildred
16
+ class << self
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def configure!
22
+ @configuration = Configuration.new
23
+ configuration.apply!
24
+ end
25
+
26
+ def logger
27
+ @logger ||= Logger.new
28
+ end
29
+ end
30
+ end
data/sig/mildred.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Mildred
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mildred
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam McClenaghan
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '8.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '8.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: gum
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.3'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.3'
40
+ - !ruby/object:Gem::Dependency
41
+ name: ruby_llm
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.9'
54
+ description: Mildred power organizer
55
+ email:
56
+ - sam@aream.ca
57
+ executables:
58
+ - mildred
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rubocop.yml"
63
+ - CHANGELOG.md
64
+ - CODE_OF_CONDUCT.md
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - exe/mildred
69
+ - lib/mildred.rb
70
+ - lib/mildred/agent.rb
71
+ - lib/mildred/configuration.rb
72
+ - lib/mildred/container.rb
73
+ - lib/mildred/current.rb
74
+ - lib/mildred/job.rb
75
+ - lib/mildred/logger.rb
76
+ - lib/mildred/runner.rb
77
+ - lib/mildred/tools/run_command.rb
78
+ - lib/mildred/version.rb
79
+ - sig/mildred.rbs
80
+ homepage: https://rubygems.org/gems/mildred
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: https://rubygems.org/gems/mildred
85
+ source_code_uri: https://github.com/sammcclenaghan/mildred
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.1.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.6.9
101
+ specification_version: 4
102
+ summary: Mildred summary
103
+ test_files: []