self_agency 0.0.1

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/.github/workflows/deploy-github-pages.yml +40 -0
  4. data/.irbrc +22 -0
  5. data/CHANGELOG.md +5 -0
  6. data/COMMITS.md +196 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +177 -0
  9. data/Rakefile +8 -0
  10. data/docs/api/configuration.md +85 -0
  11. data/docs/api/errors.md +166 -0
  12. data/docs/api/index.md +37 -0
  13. data/docs/api/self-agency-module.md +198 -0
  14. data/docs/architecture/overview.md +181 -0
  15. data/docs/architecture/security.md +101 -0
  16. data/docs/assets/images/self_agency.gif +0 -0
  17. data/docs/assets/images/self_agency.mp4 +0 -0
  18. data/docs/development/contributing.md +45 -0
  19. data/docs/development/setup.md +81 -0
  20. data/docs/development/testing.md +70 -0
  21. data/docs/examples/autonomous-robots.md +109 -0
  22. data/docs/examples/basic-examples.md +237 -0
  23. data/docs/examples/collaborative-robots.md +98 -0
  24. data/docs/examples/full-workflow.md +100 -0
  25. data/docs/examples/index.md +36 -0
  26. data/docs/getting-started/installation.md +71 -0
  27. data/docs/getting-started/quick-start.md +94 -0
  28. data/docs/guide/configuration.md +113 -0
  29. data/docs/guide/generating-methods.md +146 -0
  30. data/docs/guide/how-to-use.md +144 -0
  31. data/docs/guide/lifecycle-hooks.md +86 -0
  32. data/docs/guide/prompt-templates.md +189 -0
  33. data/docs/guide/saving-methods.md +84 -0
  34. data/docs/guide/scopes.md +74 -0
  35. data/docs/guide/source-inspection.md +96 -0
  36. data/docs/index.md +77 -0
  37. data/examples/01_basic_usage.rb +27 -0
  38. data/examples/02_multiple_methods.rb +43 -0
  39. data/examples/03_scopes.rb +40 -0
  40. data/examples/04_source_inspection.rb +46 -0
  41. data/examples/05_lifecycle_hook.rb +55 -0
  42. data/examples/06_configuration.rb +97 -0
  43. data/examples/07_error_handling.rb +103 -0
  44. data/examples/08_class_context.rb +64 -0
  45. data/examples/09_method_override.rb +52 -0
  46. data/examples/10_full_workflow.rb +118 -0
  47. data/examples/11_collaborative_robots/atlas.rb +31 -0
  48. data/examples/11_collaborative_robots/echo.rb +30 -0
  49. data/examples/11_collaborative_robots/main.rb +190 -0
  50. data/examples/11_collaborative_robots/nova.rb +71 -0
  51. data/examples/11_collaborative_robots/robot.rb +119 -0
  52. data/examples/12_autonomous_robots/analyst.rb +193 -0
  53. data/examples/12_autonomous_robots/collector.rb +78 -0
  54. data/examples/12_autonomous_robots/main.rb +166 -0
  55. data/examples/12_autonomous_robots/planner.rb +125 -0
  56. data/examples/12_autonomous_robots/robot.rb +284 -0
  57. data/examples/generated/from_range_class.rb +3 -0
  58. data/examples/generated/mean_instance.rb +4 -0
  59. data/examples/generated/median_instance.rb +15 -0
  60. data/examples/generated/report_singleton.rb +3 -0
  61. data/examples/generated/standard_deviation_instance.rb +8 -0
  62. data/examples/lib/message_bus.rb +57 -0
  63. data/examples/lib/setup.rb +8 -0
  64. data/lib/self_agency/configuration.rb +76 -0
  65. data/lib/self_agency/errors.rb +35 -0
  66. data/lib/self_agency/generator.rb +47 -0
  67. data/lib/self_agency/prompts/generate/system.txt.erb +15 -0
  68. data/lib/self_agency/prompts/generate/user.txt.erb +13 -0
  69. data/lib/self_agency/prompts/shape/system.txt.erb +26 -0
  70. data/lib/self_agency/prompts/shape/user.txt.erb +10 -0
  71. data/lib/self_agency/sandbox.rb +17 -0
  72. data/lib/self_agency/saver.rb +62 -0
  73. data/lib/self_agency/validator.rb +64 -0
  74. data/lib/self_agency/version.rb +5 -0
  75. data/lib/self_agency.rb +315 -0
  76. data/mkdocs.yml +156 -0
  77. data/sig/self_agency.rbs +4 -0
  78. metadata +163 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cacb0b32d94dbd3c8595537fd3f5bf6dd03d3ee8a9c1299c5709fc112cbd0530
4
+ data.tar.gz: aae62a812eb2c391657c4497d62677b5d69ce77fb94cf2f30cccc7df0f167f30
5
+ SHA512:
6
+ metadata.gz: 651663718fe40506c3e176cc9ad01e4809cc1e91d29553ac8b61677f3e54d87dc160c987672332ec64d299ac7b2606798ae19a7230728ddcd219a23ca646d8c5
7
+ data.tar.gz: da53d7bdc15113ed6eef97ee5d7f1cde71caa76fe775b9d92665cc8a498cd56a8a654da58d7cc38f987472b3a0ad252e412d051a07a0c94e37d1c9a7f43d4307
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ export RR=`pwd`
@@ -0,0 +1,40 @@
1
+ name: Deploy Documentation to GitHub Pages
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ paths:
7
+ - "docs/**"
8
+ - "mkdocs.yml"
9
+ - ".github/workflows/deploy-github-pages.yml"
10
+ workflow_dispatch:
11
+
12
+ permissions:
13
+ contents: write
14
+ pages: write
15
+ id-token: write
16
+
17
+ jobs:
18
+ deploy:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - name: Checkout code
22
+ uses: actions/checkout@v4
23
+ with:
24
+ fetch-depth: 0
25
+
26
+ - name: Setup Python
27
+ uses: actions/setup-python@v5
28
+ with:
29
+ python-version: 3.x
30
+
31
+ - name: Install dependencies
32
+ run: pip install mkdocs-material
33
+
34
+ - name: Configure Git
35
+ run: |
36
+ git config --local user.email "action@github.com"
37
+ git config --local user.name "GitHub Action"
38
+
39
+ - name: Deploy to GitHub Pages
40
+ run: mkdocs gh-deploy --force --clean
data/.irbrc ADDED
@@ -0,0 +1,22 @@
1
+ require_relative 'lib/self_agency'
2
+
3
+ SelfAgency.configure do |config|
4
+ config.provider = :ollama
5
+ config.model = "qwen3-coder:30b"
6
+ config.api_base = "http://localhost:11434/v1"
7
+ end
8
+
9
+ class Foo
10
+ include SelfAgency
11
+
12
+ # The original correcy implementation
13
+ def add(a, b)
14
+ a + b
15
+ end
16
+ end
17
+
18
+ class Bar < Foo
19
+ end
20
+
21
+ FOO = Foo.new
22
+ BAR = Bar.new
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-01-30
4
+
5
+ - Initial release
data/COMMITS.md ADDED
@@ -0,0 +1,196 @@
1
+ ---
2
+ url: https://www.conventionalcommits.org/en/v1.0.0/
3
+ title: Conventional Commits
4
+ description: A specification for adding human and machine readable meaning to commit messages
5
+ access_date: 2025-07-31T20:51:29.000Z
6
+ current_date: 2025-07-31T20:51:29.601Z
7
+ ---
8
+
9
+ # Conventional Commits
10
+
11
+ A specification for adding human and machine readable meaning to commit messages
12
+
13
+ Quick Summary Full Specification Contribute
14
+
15
+ # Conventional Commits 1.0.0
16
+
17
+ ## Summary
18
+
19
+ The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
20
+
21
+ The commit message should be structured as follows:
22
+
23
+ ---
24
+
25
+ ```
26
+ <type>[optional scope]: <description>
27
+
28
+ [optional body]
29
+
30
+ [optional footer(s)]
31
+
32
+ ```
33
+
34
+ ---
35
+
36
+ The commit contains the following structural elements, to communicate intent to the consumers of your library:
37
+
38
+ 1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with `PATCH` in Semantic Versioning).
39
+ 2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with `MINOR` in Semantic Versioning).
40
+ 3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
41
+ 4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`,`ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
42
+ 5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
43
+
44
+ Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
45
+
46
+ ## Examples
47
+
48
+ ### Commit message with description and breaking change footer
49
+
50
+ ```
51
+ feat: allow provided config object to extend other configs
52
+
53
+ BREAKING CHANGE: `extends` key in config file is now used for extending other config files
54
+
55
+ ```
56
+
57
+ ### Commit message with `!` to draw attention to breaking change
58
+
59
+ ```
60
+ feat!: send an email to the customer when a product is shipped
61
+
62
+ ```
63
+
64
+ ### Commit message with scope and `!` to draw attention to breaking change
65
+
66
+ ```
67
+ feat(api)!: send an email to the customer when a product is shipped
68
+
69
+ ```
70
+
71
+ ### Commit message with both `!` and BREAKING CHANGE footer
72
+
73
+ ```
74
+ chore!: drop support for Node 6
75
+
76
+ BREAKING CHANGE: use JavaScript features not available in Node 6.
77
+
78
+ ```
79
+
80
+ ### Commit message with no body
81
+
82
+ ```
83
+ docs: correct spelling of CHANGELOG
84
+
85
+ ```
86
+
87
+ ### Commit message with scope
88
+
89
+ ```
90
+ feat(lang): add Polish language
91
+
92
+ ```
93
+
94
+ ### Commit message with multi-paragraph body and multiple footers
95
+
96
+ ```
97
+ fix: prevent racing of requests
98
+
99
+ Introduce a request id and a reference to latest request. Dismiss
100
+ incoming responses other than from latest request.
101
+
102
+ Remove timeouts which were used to mitigate the racing issue but are
103
+ obsolete now.
104
+
105
+ Reviewed-by: Z
106
+ Refs: #123
107
+
108
+ ```
109
+
110
+ ## Specification
111
+
112
+ The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
113
+
114
+ 1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
115
+ 2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
116
+ 3. The type `fix` MUST be used when a commit represents a bug fix for your application.
117
+ 4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
118
+ 5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
119
+ 6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
120
+ 7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
121
+ 8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
122
+ 9. A footer’s token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
123
+ 10. A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
124
+ 11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
125
+ 12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g.,_BREAKING CHANGE: environment variables now take precedence over config files_.
126
+ 13. If included in the type/scope prefix, breaking changes MUST be indicated by a`!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
127
+ 14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
128
+ 15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
129
+ 16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
130
+
131
+ ## Why Use Conventional Commits
132
+
133
+ * Automatically generating CHANGELOGs.
134
+ * Automatically determining a semantic version bump (based on the types of commits landed).
135
+ * Communicating the nature of changes to teammates, the public, and other stakeholders.
136
+ * Triggering build and publish processes.
137
+ * Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
138
+
139
+ ## FAQ
140
+
141
+ ### How should I deal with commit messages in the initial development phase?
142
+
143
+ We recommend that you proceed as if you’ve already released the product. Typically _somebody_, even if it’s your fellow software developers, is using your software. They’ll want to know what’s fixed, what breaks etc.
144
+
145
+ ### Are the types in the commit title uppercase or lowercase?
146
+
147
+ Any casing may be used, but it’s best to be consistent.
148
+
149
+ ### What do I do if the commit conforms to more than one of the commit types?
150
+
151
+ Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
152
+
153
+ ### Doesn’t this discourage rapid development and fast iteration?
154
+
155
+ It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
156
+
157
+ ### Might Conventional Commits lead developers to limit the type of commits they make because they’ll be thinking in the types provided?
158
+
159
+ Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
160
+
161
+ ### How does this relate to SemVer?
162
+
163
+ `fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
164
+
165
+ ### How should I version my extensions to the Conventional Commits Specification, e.g. `@jameswomack/conventional-commit-spec`?
166
+
167
+ We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
168
+
169
+ ### What do I do if I accidentally use the wrong commit type?
170
+
171
+ #### When you used a type that’s of the spec but not the correct type, e.g. `fix` instead of `feat`
172
+
173
+ Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
174
+
175
+ #### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
176
+
177
+ In a worst case scenario, it’s not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
178
+
179
+ ### Do all my contributors need to use the Conventional Commits specification?
180
+
181
+ No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they’re merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
182
+
183
+ ### How does Conventional Commits handle revert commits?
184
+
185
+ Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
186
+
187
+ Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
188
+
189
+ One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
190
+
191
+ ```
192
+ revert: let us never again speak of the noodle incident
193
+
194
+ Refs: 676104e, a215868
195
+
196
+ ```
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Dewayne VanHoozer
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,177 @@
1
+ <div align="center">
2
+ <h1>SelfAgency</h1>
3
+ Describe what you want in plain language, get working methods back.<br/>
4
+ SelfAgency is a mixin module that gives any Ruby class the ability to<br/>
5
+ generate and install methods at runtime via an LLM.<br/>
6
+ <br/>
7
+ <img src="docs/assets/images/self_agency.gif" alt="SelfAgency Demo" width="100%">
8
+ <br/><br/>
9
+ <a href="https://madbomber.github.io/self_agency"><img src="https://img.shields.io/badge/📖_Full_Documentation-madbomber.github.io/self__agency-7C3AED?style=for-the-badge&labelColor=1a1a2e" alt="Full Documentation"></a>
10
+ <br/><br/>
11
+ <h2>Key Features</h2>
12
+ </div>
13
+
14
+ <table>
15
+ <tr>
16
+ <td width="50%" valign="top">
17
+ <ul>
18
+ <li><strong>Natural language to Ruby methods</strong> — describe what you want, get working code</li>
19
+ <li><strong>Multiple methods at once</strong> — generate related methods in a single call</li>
20
+ <li><strong>Three scopes</strong> — instance, singleton, and class methods</li>
21
+ <li><strong>Two-stage LLM pipeline</strong> — shape the prompt, then generate code</li>
22
+ </ul>
23
+ </td>
24
+ <td width="50%" valign="top">
25
+ <ul>
26
+ <li><strong>Security by default</strong> — 26 static patterns + runtime sandbox</li>
27
+ <li><strong>Automatic retries</strong> — self-corrects on validation failure</li>
28
+ <li><strong>Source inspection &amp; versioning</strong> — view code and track history</li>
29
+ <li><strong>Provider agnostic</strong> — any LLM via <a href="https://github.com/crmne/ruby_llm">ruby_llm</a></li>
30
+ </ul>
31
+ </td>
32
+ </tr>
33
+ </table>
34
+
35
+ > [!CAUTION]
36
+ > This is an experiment. It may not be fit for any specific purpose. Its micro-prompting. Instead of asking Claude Code, CodeX or Gemini to create an entire application, you can use SelfAgency to generate individual methods. So far the experiments are showing good success with methods that perform math stuff on its input.
37
+
38
+ ## Installation
39
+
40
+ Add to your Gemfile:
41
+
42
+ ```ruby
43
+ gem "self_agency"
44
+ ```
45
+
46
+ Then run `bundle install`. See the [Installation guide](https://madbomber.github.io/self_agency/getting-started/installation/) for LLM provider setup and requirements.
47
+
48
+ ## Quick Start
49
+
50
+ ```ruby
51
+ require "self_agency"
52
+
53
+ SelfAgency.configure do |config|
54
+ config.provider = :ollama
55
+ config.model = "qwen3-coder:30b"
56
+ config.api_base = "http://localhost:11434/v1"
57
+ end
58
+
59
+ class Foo
60
+ include SelfAgency
61
+ end
62
+
63
+ foo = Foo.new
64
+ foo._("an instance method to add two integers, return the result")
65
+ #=> [:add]
66
+ foo.add(1, 1) #=> 2
67
+ ```
68
+
69
+ See the [Quick Start walkthrough](https://madbomber.github.io/self_agency/getting-started/quick-start/) for a complete step-by-step guide.
70
+
71
+ ## How to Use
72
+
73
+ SelfAgency is a Bottom-Up experimentation tool. Start in IRB, describe the behavior you need in plain language, test it with real inputs, inspect the generated source, and refine until the logic is right. Once your methods are proven, save them and wire them into your larger architecture.
74
+
75
+ ```
76
+ Describe → Generate → Test → Inspect → Refine
77
+ ↑ │
78
+ └──────────────────────────────────────────────┘
79
+ ```
80
+
81
+ Read [How to Use SelfAgency](https://madbomber.github.io/self_agency/guide/how-to-use/) for a deeper discussion of Top-Down vs. Bottom-Up design and where SelfAgency fits in your workflow.
82
+
83
+ ## Features at a Glance
84
+
85
+ ### Generate multiple methods at once
86
+
87
+ ```ruby
88
+ names = foo._("create add, subtract, multiply, and divide methods for two integers")
89
+ #=> [:add, :subtract, :multiply, :divide]
90
+ ```
91
+
92
+ `_()` always returns an Array of Symbol method names. [Full details →](https://madbomber.github.io/self_agency/guide/generating-methods/)
93
+
94
+ ### Scopes
95
+
96
+ Generate instance methods (default), singleton methods, or class methods:
97
+
98
+ ```ruby
99
+ foo._("a method called greet that returns 'hello'", scope: :singleton)
100
+ foo._("a class method called ping that returns 'pong'", scope: :class)
101
+ ```
102
+
103
+ [Full details →](https://madbomber.github.io/self_agency/guide/scopes/)
104
+
105
+ ### Source inspection and version history
106
+
107
+ View the generated source and track changes across regenerations:
108
+
109
+ ```ruby
110
+ puts foo._source_for(:add)
111
+ versions = Foo._source_versions_for(:add)
112
+ ```
113
+
114
+ [Full details →](https://madbomber.github.io/self_agency/guide/source-inspection/)
115
+
116
+ ### Save generated methods to a file
117
+
118
+ Persist proven methods as a subclass in a Ruby source file:
119
+
120
+ ```ruby
121
+ foo._save!(as: :calculator)
122
+ # Writes calculator.rb with class Calculator < Foo
123
+ ```
124
+
125
+ [Full details →](https://madbomber.github.io/self_agency/guide/saving-methods/)
126
+
127
+ ### Lifecycle hooks
128
+
129
+ Override `on_method_generated` to persist or log each generated method:
130
+
131
+ ```ruby
132
+ def on_method_generated(method_name, scope, code)
133
+ File.write("generated/#{method_name}.rb", code)
134
+ end
135
+ ```
136
+
137
+ [Full details →](https://madbomber.github.io/self_agency/guide/lifecycle-hooks/)
138
+
139
+ ### Configuration
140
+
141
+ ```ruby
142
+ SelfAgency.configure do |config|
143
+ config.provider = :ollama
144
+ config.model = "qwen3-coder:30b"
145
+ config.generation_retries = 3
146
+ config.logger = Logger.new($stdout)
147
+ end
148
+ ```
149
+
150
+ [All options →](https://madbomber.github.io/self_agency/guide/configuration/) · [Prompt templates →](https://madbomber.github.io/self_agency/guide/prompt-templates/)
151
+
152
+ ## Architecture
153
+
154
+ A two-stage LLM pipeline: **Shape** rewrites casual English into a precise spec, then **Generate** produces `def...end` blocks. Code passes through sanitization, validation, an optional retry loop, and sandboxed eval. Thread-safe via per-class mutex.
155
+
156
+ [Full architecture overview →](https://madbomber.github.io/self_agency/architecture/overview/) · [Security model →](https://madbomber.github.io/self_agency/architecture/security/)
157
+
158
+ ## Errors
159
+
160
+ | Exception | Meaning |
161
+ |---|---|
162
+ | `SelfAgency::GenerationError` | LLM returned nil or communication failed |
163
+ | `SelfAgency::ValidationError` | Code is empty, malformed, or has syntax errors |
164
+ | `SelfAgency::SecurityError` | Dangerous pattern detected in generated code |
165
+
166
+ [Full error reference →](https://madbomber.github.io/self_agency/api/errors/)
167
+
168
+ ## Development
169
+
170
+ ```bash
171
+ bin/setup
172
+ rake test
173
+ ```
174
+
175
+ ## License
176
+
177
+ MIT License. See [LICENSE.txt](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,85 @@
1
+ # Configuration
2
+
3
+ ## `SelfAgency::Configuration`
4
+
5
+ Holds all configuration options. Created automatically by `SelfAgency.configure`.
6
+
7
+ ### Attributes
8
+
9
+ | Attribute | Type | Default | Description |
10
+ |-----------|------|---------|-------------|
11
+ | `provider` | `Symbol` | `:ollama` | RubyLLM provider name |
12
+ | `model` | `String` | `"qwen3-coder:30b"` | LLM model identifier |
13
+ | `api_base` | `String` | `"http://localhost:11434/v1"` | Provider API endpoint |
14
+ | `request_timeout` | `Integer` | `30` | Request timeout in seconds |
15
+ | `max_retries` | `Integer` | `1` | Number of retries on failure |
16
+ | `retry_interval` | `Float` | `0.5` | Seconds between retries |
17
+ | `template_directory` | `String` | `lib/self_agency/prompts` | Path to ERB prompt templates |
18
+ | `generation_retries` | `Integer` | `3` | Max retry attempts when validation or security checks fail |
19
+ | `logger` | `Proc`, `Logger`, or `nil` | `nil` | Logger for pipeline events (callable or Logger-compatible) |
20
+
21
+ All attributes are read/write via `attr_accessor`.
22
+
23
+ ---
24
+
25
+ ## Module-Level Methods
26
+
27
+ ### `SelfAgency.configure { |config| ... }`
28
+
29
+ Configure SelfAgency. Yields a `Configuration` instance.
30
+
31
+ Internally calls `RubyLLM.configure` and `RubyLLM::Template.configure` with the corresponding settings, then marks the gem as configured.
32
+
33
+ **Returns:** `Configuration`
34
+
35
+ ```ruby
36
+ SelfAgency.configure do |config|
37
+ config.provider = :ollama
38
+ config.model = "qwen3-coder:30b"
39
+ config.api_base = "http://localhost:11434/v1"
40
+ config.request_timeout = 60
41
+ end
42
+ ```
43
+
44
+ ---
45
+
46
+ ### `SelfAgency.configuration`
47
+
48
+ Access the current configuration instance. Creates a default instance if none exists.
49
+
50
+ **Returns:** `Configuration`
51
+
52
+ ```ruby
53
+ cfg = SelfAgency.configuration
54
+ cfg.model #=> "qwen3-coder:30b"
55
+ ```
56
+
57
+ ---
58
+
59
+ ### `SelfAgency.reset!`
60
+
61
+ Restore all configuration to defaults and mark the gem as unconfigured. Subsequent calls to `_()` will raise until `configure` is called again.
62
+
63
+ ```ruby
64
+ SelfAgency.reset!
65
+ ```
66
+
67
+ ---
68
+
69
+ ### `SelfAgency.ensure_configured!`
70
+
71
+ Raise `SelfAgency::Error` if `configure` has not been called.
72
+
73
+ **Raises:** `SelfAgency::Error` with message `"SelfAgency.configure has not been called"`
74
+
75
+ ```ruby
76
+ SelfAgency.ensure_configured!
77
+ ```
78
+
79
+ ---
80
+
81
+ ### `SelfAgency.included(base)`
82
+
83
+ Hook called when a class includes `SelfAgency`. Extends the including class with `SelfAgency::ClassMethods` and initializes a per-class mutex for thread-safe pipeline execution.
84
+
85
+ This is called automatically by Ruby's `include` mechanism; you do not need to call it directly.