@foldrun/core 0.2.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.
Files changed (166) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +239 -0
  3. package/dist/index.d.ts +32 -0
  4. package/dist/index.js +43 -0
  5. package/dist/src/agent-tools.d.ts +31 -0
  6. package/dist/src/agent-tools.js +99 -0
  7. package/dist/src/agents-md.d.ts +9 -0
  8. package/dist/src/agents-md.js +83 -0
  9. package/dist/src/api-tools.d.ts +38 -0
  10. package/dist/src/api-tools.js +313 -0
  11. package/dist/src/approvals.d.ts +39 -0
  12. package/dist/src/approvals.js +103 -0
  13. package/dist/src/arrange.d.ts +8 -0
  14. package/dist/src/arrange.js +40 -0
  15. package/dist/src/catalog.d.ts +108 -0
  16. package/dist/src/catalog.js +255 -0
  17. package/dist/src/completions.d.ts +61 -0
  18. package/dist/src/completions.js +578 -0
  19. package/dist/src/confine.d.ts +31 -0
  20. package/dist/src/confine.js +298 -0
  21. package/dist/src/container.d.ts +30 -0
  22. package/dist/src/container.js +172 -0
  23. package/dist/src/context-tools.d.ts +81 -0
  24. package/dist/src/context-tools.js +347 -0
  25. package/dist/src/deploy.d.ts +100 -0
  26. package/dist/src/deploy.js +377 -0
  27. package/dist/src/egress.d.ts +75 -0
  28. package/dist/src/egress.js +133 -0
  29. package/dist/src/evals.d.ts +150 -0
  30. package/dist/src/evals.js +651 -0
  31. package/dist/src/flow-lint.d.ts +16 -0
  32. package/dist/src/flow-lint.js +177 -0
  33. package/dist/src/git-hook.d.ts +1 -0
  34. package/dist/src/git-hook.js +70 -0
  35. package/dist/src/git.d.ts +37 -0
  36. package/dist/src/git.js +101 -0
  37. package/dist/src/gitrepo.d.ts +95 -0
  38. package/dist/src/gitrepo.js +355 -0
  39. package/dist/src/history.d.ts +82 -0
  40. package/dist/src/history.js +259 -0
  41. package/dist/src/kinds.d.ts +95 -0
  42. package/dist/src/kinds.js +421 -0
  43. package/dist/src/library.d.ts +94 -0
  44. package/dist/src/library.js +341 -0
  45. package/dist/src/linkable.d.ts +20 -0
  46. package/dist/src/linkable.js +113 -0
  47. package/dist/src/model-probe.d.ts +21 -0
  48. package/dist/src/model-probe.js +81 -0
  49. package/dist/src/notify.d.ts +61 -0
  50. package/dist/src/notify.js +252 -0
  51. package/dist/src/oauth-presets.d.ts +13 -0
  52. package/dist/src/oauth-presets.js +39 -0
  53. package/dist/src/okf.d.ts +220 -0
  54. package/dist/src/okf.js +656 -0
  55. package/dist/src/openapi.d.ts +66 -0
  56. package/dist/src/openapi.js +342 -0
  57. package/dist/src/paths.d.ts +33 -0
  58. package/dist/src/paths.js +78 -0
  59. package/dist/src/platform.d.ts +32 -0
  60. package/dist/src/platform.js +48 -0
  61. package/dist/src/providers.d.ts +47 -0
  62. package/dist/src/providers.js +114 -0
  63. package/dist/src/refs.d.ts +20 -0
  64. package/dist/src/refs.js +78 -0
  65. package/dist/src/run-container.d.ts +227 -0
  66. package/dist/src/run-container.js +760 -0
  67. package/dist/src/runner.d.ts +241 -0
  68. package/dist/src/runner.js +3215 -0
  69. package/dist/src/runtime.d.ts +41 -0
  70. package/dist/src/runtime.js +357 -0
  71. package/dist/src/script-tools.d.ts +62 -0
  72. package/dist/src/script-tools.js +296 -0
  73. package/dist/src/secret-files.d.ts +12 -0
  74. package/dist/src/secret-files.js +92 -0
  75. package/dist/src/secrets.d.ts +147 -0
  76. package/dist/src/secrets.js +626 -0
  77. package/dist/src/starter.d.ts +21 -0
  78. package/dist/src/starter.js +399 -0
  79. package/dist/src/step-exec.d.ts +136 -0
  80. package/dist/src/step-exec.js +391 -0
  81. package/dist/src/storage.d.ts +123 -0
  82. package/dist/src/storage.js +640 -0
  83. package/dist/src/store.d.ts +1052 -0
  84. package/dist/src/store.js +2378 -0
  85. package/dist/src/tar.d.ts +30 -0
  86. package/dist/src/tar.js +111 -0
  87. package/dist/src/tool-names.d.ts +39 -0
  88. package/dist/src/tool-names.js +79 -0
  89. package/dist/src/tool-programs.d.ts +18 -0
  90. package/dist/src/tool-programs.js +52 -0
  91. package/dist/src/tool-test.d.ts +19 -0
  92. package/dist/src/tool-test.js +335 -0
  93. package/dist/src/translator.d.ts +159 -0
  94. package/dist/src/translator.js +986 -0
  95. package/dist/src/triggers.d.ts +60 -0
  96. package/dist/src/triggers.js +270 -0
  97. package/dist/src/webhook.d.ts +47 -0
  98. package/dist/src/webhook.js +148 -0
  99. package/index.ts +44 -0
  100. package/package.json +64 -0
  101. package/src/agent-tools.ts +138 -0
  102. package/src/agents-md.ts +81 -0
  103. package/src/api-tools.ts +389 -0
  104. package/src/approvals.ts +129 -0
  105. package/src/arrange.ts +42 -0
  106. package/src/catalog.ts +321 -0
  107. package/src/completions.ts +652 -0
  108. package/src/confine.ts +350 -0
  109. package/src/container.ts +220 -0
  110. package/src/context-tools.ts +435 -0
  111. package/src/deploy.ts +458 -0
  112. package/src/egress.ts +176 -0
  113. package/src/evals.ts +812 -0
  114. package/src/flow-lint.ts +215 -0
  115. package/src/git-hook.ts +73 -0
  116. package/src/git.ts +117 -0
  117. package/src/gitrepo.ts +391 -0
  118. package/src/history.ts +329 -0
  119. package/src/kinds.ts +507 -0
  120. package/src/library.ts +419 -0
  121. package/src/linkable.ts +123 -0
  122. package/src/model-probe.ts +112 -0
  123. package/src/notify.ts +281 -0
  124. package/src/oauth-presets.ts +54 -0
  125. package/src/okf.ts +768 -0
  126. package/src/openapi.ts +383 -0
  127. package/src/paths.ts +79 -0
  128. package/src/platform.ts +87 -0
  129. package/src/providers.ts +147 -0
  130. package/src/refs.ts +83 -0
  131. package/src/run-container.ts +883 -0
  132. package/src/runner.ts +3446 -0
  133. package/src/runtime.ts +404 -0
  134. package/src/script-tools.ts +383 -0
  135. package/src/secret-files.ts +101 -0
  136. package/src/secrets.ts +799 -0
  137. package/src/starter.ts +415 -0
  138. package/src/step-exec.ts +498 -0
  139. package/src/storage.ts +771 -0
  140. package/src/store.ts +2985 -0
  141. package/src/tar.ts +124 -0
  142. package/src/tool-names.ts +91 -0
  143. package/src/tool-programs.ts +65 -0
  144. package/src/tool-test.ts +401 -0
  145. package/src/translator.ts +1029 -0
  146. package/src/triggers.ts +287 -0
  147. package/src/webhook.ts +183 -0
  148. package/templates/blog-desk/AGENTS.md +13 -0
  149. package/templates/blog-desk/agents/researcher/agent.md +11 -0
  150. package/templates/blog-desk/agents/writer/agent.md +8 -0
  151. package/templates/blog-desk/evals/writer-quality.md +10 -0
  152. package/templates/blog-desk/flows/publish.md +10 -0
  153. package/templates/blog-desk/knowledge/house-style.md +9 -0
  154. package/templates/blog-desk/knowledge/index.md +9 -0
  155. package/templates/hello/AGENTS.md +18 -0
  156. package/templates/hello/agents/curator/agent.md +32 -0
  157. package/templates/hello/agents/notetaker/agent.md +24 -0
  158. package/templates/hello/evals/house-style.md +16 -0
  159. package/templates/hello/flows/memory-review.md +7 -0
  160. package/templates/hello/flows/note.md +7 -0
  161. package/templates/hello/knowledge/house-style.md +15 -0
  162. package/templates/hello/knowledge/index.md +9 -0
  163. package/templates/hello/skills/plain-english/SKILL.md +11 -0
  164. package/templates/hello/state/publishing.md +7 -0
  165. package/templates/hello/tools/wordcount/run.py +13 -0
  166. package/templates/hello/tools/wordcount/tool.md +22 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 foldrun contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # foldrun
2
+
3
+ **Agents are just folders. Write them, check them, run them.**
4
+
5
+ An agent is a folder. Its instructions, skills, knowledge, memory, tools and
6
+ tests are files you can read, diff and commit. There is no SDK to learn and no
7
+ graph to wire — the runtime reads the folder.
8
+
9
+ ```bash
10
+ npx foldrun init my-desk
11
+ cd my-desk
12
+ foldrun check # validate everything — costs nothing
13
+ foldrun run publish # run the flow
14
+ ```
15
+
16
+ ```
17
+ my-desk/
18
+ ├── AGENTS.md what every agent here should know
19
+ ├── agents/ who does the work
20
+ │ └── writer/agent.md
21
+ ├── flows/ in what order
22
+ │ └── publish.md
23
+ ├── skills/ how a task is done
24
+ ├── knowledge/ what you gave them
25
+ ├── memory/ what they learned
26
+ ├── tools/ what they can call
27
+ ├── scripts/ code
28
+ └── evals/ is it any good
29
+ ```
30
+
31
+ **API reference:** docs/api.md — every route, its methods, and what it takes.
32
+
33
+ ## Built on other people's standards
34
+
35
+ Most of this format is not ours. Where an open standard exists we adopt it
36
+ rather than compete with it:
37
+
38
+ | Layer | Standard | From |
39
+ |---|---|---|
40
+ | `AGENTS.md` | [AGENTS.md](https://agents.md/) | Linux Foundation |
41
+ | `skills/` | [Agent Skills](https://agentskills.io) | Anthropic |
42
+ | documents in `knowledge/`, `memory/` | [Open Knowledge Format v0.2](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf) | Google Cloud |
43
+ | `tools/` | [MCP](https://modelcontextprotocol.io) | Anthropic, adopted broadly |
44
+ | `flows/`, `evals/` | none exists — ours | |
45
+
46
+ A skill written for Claude Code or Cursor runs here unchanged — including one installed in the cross-client `.agents/skills/` directory, which the runtime scans alongside its own `skills/`. A knowledge
47
+ bundle exported by any OKF producer drops straight in. Agent frontmatter also
48
+ accepts Claude Code's subagent fields, so those files mostly run as they are.
49
+
50
+ ## Flows are a numbered list
51
+
52
+ ```markdown
53
+ 1. [[researcher]] — find one topic worth writing about
54
+ 2. [[writer]] — draft it
55
+ 2. [[fixer]] — fix the technical issues, in parallel
56
+ 3. [[editor]] — review both together
57
+ verify: test -s outputs/post.md
58
+ ```
59
+
60
+ Same number runs at the same time; different numbers run in order. Each group
61
+ receives everything the group before it produced. `verify:` means a shell
62
+ command has to exit 0 — *done* should mean a check passed, not that the model
63
+ stopped talking.
64
+
65
+ ## Evals, because prompts regress quietly
66
+
67
+ ```markdown
68
+ ## writes for farmers, not gardeners
69
+ task: Propose a topic and say who it is for.
70
+ expect:
71
+ - not-contains: leverage
72
+ - judge: the intended reader is a working farmer
73
+ ```
74
+
75
+ Deterministic checks run first; a model only judges what survives them.
76
+ `foldrun eval` in CI is how you find out a prompt edit made things worse.
77
+
78
+ Every eval runs after every deploy unless it says otherwise. An eval of a
79
+ whole flow costs a whole run each time — and may touch real systems — so mark
80
+ it `trigger: manual` and it runs only when a person asks — the Run button,
81
+ the API, or `foldrun eval`.
82
+
83
+ ## Which model, and how hard it thinks
84
+
85
+ Two knobs, set anywhere from a whole agent down to one step of one flow —
86
+ nearest wins, and the run trace names the winner:
87
+
88
+ ```yaml
89
+ model: fast # a tier (fast | default | max), an exact id, or "@preset/…"
90
+ effort: high # low | medium | high | xhigh | max
91
+ ```
92
+
93
+ Tiers keep files from rotting when models are renamed; an exact id pins one;
94
+ synonyms all land (`small`, `cheap`, `large`, `best`…). Effort is the
95
+ orthogonal axis — `fast` + `max` is the cheap model told to take its time.
96
+
97
+ A `provider:` block points the runtime at any endpoint speaking the Anthropic
98
+ Messages API — OpenRouter's Anthropic skin runs 400+ models through it, a
99
+ LiteLLM in front covers the rest — and remaps what the tiers mean there:
100
+
101
+ ```yaml
102
+ provider:
103
+ base_url: https://openrouter.ai/api
104
+ token: ${OPENROUTER_API_KEY}
105
+ models:
106
+ fast: google/gemini-2.5-flash
107
+ ```
108
+
109
+ The runtime then asks the gateway what each model can actually do, and uses
110
+ the answer three ways: a step whose agent needs tools fails **at start** on a
111
+ model that can't call them (one line, naming the nearest that can); `effort:`
112
+ is fitted to each model's supported levels, out loud; and step cost is priced
113
+ from the gateway's own rates, not one vendor's table. When a claim needs
114
+ proving, `foldrun probe <model>` runs a real tool loop against it — a nonce
115
+ the model must fetch through a tool and echo back — through your exact
116
+ provider config. The catalogue is the gateway's claim; the probe is ground
117
+ truth.
118
+
119
+ ## The host for markdown agents
120
+
121
+ **foldrun cloud** runs your agents so you don't operate them: scheduled and
122
+ webhook triggers, durable runs with full history, a secret store, team access,
123
+ and containers you never touch. Push the folder, it runs.
124
+
125
+ The format, the CLI and the runtime are open source (Apache-2.0), and the
126
+ hosted platform imports the same core rather than a fork. Writing and checking
127
+ an agent locally costs nothing and needs no account — that is the on-ramp to
128
+ the host, not a competitor to it.
129
+
130
+ Where the two differ is operations, not capability. Locally a run happens in
131
+ your terminal; hosted, it survives a restart, retries a failed step, waits days
132
+ for an approval and tells you what it cost. Nothing is held back from the open
133
+ version to make the hosted one worth buying.
134
+
135
+ ## This repo, and the others
136
+
137
+ This is `foldrun-core`: the runtime, published to npm as `@foldrun/core`.
138
+ Most people want the CLI, not this package — `npm install -g foldrun`.
139
+
140
+ | Path | What |
141
+ |---|---|
142
+ | `src/` | the runtime: parse, run, check, evaluate |
143
+ | `templates/` | starting points for a new workspace — see below |
144
+ | `SPEC.md` | the agent and flow format |
145
+ | `okf/PROFILE.md` | which parts of OKF are implemented |
146
+ | `okf/WHITE-PAPER.md` | hosting OKF: what the spec leaves to hosts |
147
+ | `tests/` | the runtime's tests (`npm test`) |
148
+
149
+ The command-line tool is its own repository,
150
+ [`foldrun-cli`](https://github.com/foldrun-io/foldrun-cli), and depends on
151
+ this package. The reference documentation is at
152
+ [docs.foldrun.io](https://docs.foldrun.io). The hosted platform's own
153
+ repositories are private; see "Hosting it" below.
154
+
155
+ ### Templates and workspaces
156
+
157
+ There is **one** place a workspace lives: wherever you made it. `foldrun init`
158
+ makes one in a directory you name; the hosted platform makes one under
159
+ `data/<tenant>/workspaces/<name>/`, which is gitignored because it holds your
160
+ secrets, run journals and whatever your agents learned.
161
+
162
+ `templates/` is not a second home for workspaces. It holds **starting points**
163
+ — authored, committed, and shipped — and you turn one into a workspace:
164
+
165
+ ```bash
166
+ foldrun init my-desk --from templates/hello
167
+ foldrun check my-desk
168
+ foldrun run note --workspace my-desk
169
+ ```
170
+
171
+ `templates/hello` is the smaller of the two and exercises the whole format: an
172
+ agent, a flow, a skill, a script tool as a folder (`tools/wordcount/` — a
173
+ `tool.md` and the `run.py` it calls), knowledge it may only read, memory it
174
+ writes back, and state it carries to the next run. `templates/blog-desk` is
175
+ the two-agent shape of a real desk: a researcher picks the topic, a writer
176
+ drafts it, over shared house style in `knowledge/` and an eval that holds the
177
+ writer to it.
178
+
179
+ A template ships, so it has to be correct without anyone running it: every
180
+ bundle in `templates/` is checked for conformance on each test run, and its
181
+ generated `index.md` is regenerated and compared against the committed one, so
182
+ a hand-edited template cannot ship an index that disagrees with its own files.
183
+
184
+ ## Hosting it
185
+
186
+ This package is the framework: everything needed to read a workspace and
187
+ run it on the machine you are on. The hosted platform at
188
+ [foldrun.io](https://foldrun.io) — a queue and its worker, one gVisor pod
189
+ per step, a vault, metering, a team — is built on it, in a separate private
190
+ package that plugs in through `src/platform.ts`. Nothing in this repository
191
+ imports it, so what is here is exactly what is open. There is no
192
+ self-hosted platform; `foldrun deploy` and `git push` move a workspace from
193
+ your machine to the hosted one unchanged.
194
+
195
+ ## Requirements
196
+
197
+ Node 22+. Docker or Podman if your agents run scripts. Credentials come from
198
+ `ANTHROPIC_API_KEY` or an existing Claude Code login — `foldrun check` needs
199
+ neither.
200
+
201
+ ## Status
202
+
203
+ v0.1. Local and hosted runs work. Hosted runs go through a durable on-disk
204
+ queue (survives restarts, parks at approval gates), the dashboard has
205
+ accounts and sessions (scrypt + signed cookies; first signup is free, then
206
+ `FOLDRUN_OPEN_SIGNUP=1`), spending lands in an append-only per-account
207
+ ledger (`FOLDRUN_BILLING=1` makes an empty balance refuse new runs), and a
208
+ `notify:` block in AGENTS.md webhooks you when a run fails or waits for
209
+ approval.
210
+
211
+ Teams: an account holds many users, joined by 7-day invite links minted in
212
+ Settings. Webhook URLs rotate per-hook (generation counters — nothing
213
+ secret stored) and every delivery, refused ones included, lands in a log.
214
+ Card top-ups are two Stripe REST calls behind `STRIPE_SECRET_KEY`, writing
215
+ the same ledger entry the manual API does.
216
+
217
+ With `FOLDRUN_RUN_ISOLATION=container` (one box) or `=k8s` (cluster —
218
+ native run pods, gVisor by RuntimeClass, egress-limited by NetworkPolicy)
219
+ every step runs in a hardened throwaway sandbox: workspace copied in,
220
+ events streamed out, changes filtered back so `knowledge/`, secrets and
221
+ run history physically cannot come back modified. The CLI keeps in-process
222
+ runs — on a laptop there is nothing to protect the server process from.
223
+
224
+ Connections cover how services actually hand out credentials: API keys,
225
+ API with base URL + headers, SSH (key or password — materialised as a
226
+ ready-to-run wrapper, `"$NAME" 'uptime'`), browser OAuth with your own
227
+ client, OAuth client-credentials, service accounts (RS256 JWT), and file
228
+ secrets (0600). Values are encrypted at rest and never reach the model.
229
+
230
+ A built-in tools gallery ships platform-maintained scripts — first entry:
231
+ a headless browser (`fetch_rendered`) for pages that render with
232
+ JavaScript. Assigning one copies it into your account library or a
233
+ workspace; agents still opt in explicitly in their own markdown.
234
+
235
+ Known gaps: one platform replica per data directory (the web/worker role
236
+ split needs RWX storage), and the dashboard's run lists re-read run files
237
+ per request (fine to thousands of runs).
238
+
239
+ Apache-2.0.
@@ -0,0 +1,32 @@
1
+ export * from "./src/paths.ts";
2
+ export * from "./src/store.ts";
3
+ export * from "./src/starter.ts";
4
+ export * from "./src/runner.ts";
5
+ export * from "./src/okf.ts";
6
+ export * from "./src/evals.ts";
7
+ export * from "./src/flow-lint.ts";
8
+ export * from "./src/catalog.ts";
9
+ export * from "./src/model-probe.ts";
10
+ export * from "./src/providers.ts";
11
+ export * from "./src/translator.ts";
12
+ export * from "./src/arrange.ts";
13
+ export * from "./src/completions.ts";
14
+ export * from "./src/confine.ts";
15
+ export * from "./src/platform.ts";
16
+ export * from "./src/library.ts";
17
+ export * from "./src/tool-programs.ts";
18
+ export * from "./src/linkable.ts";
19
+ export * from "./src/refs.ts";
20
+ export * from "./src/tool-names.ts";
21
+ export * from "./src/history.ts";
22
+ export * from "./src/gitrepo.ts";
23
+ export * from "./src/storage.ts";
24
+ export * from "./src/secrets.ts";
25
+ export * from "./src/oauth-presets.ts";
26
+ export * from "./src/secret-files.ts";
27
+ export * from "./src/notify.ts";
28
+ export * from "./src/webhook.ts";
29
+ export * from "./src/approvals.ts";
30
+ export * from "./src/deploy.ts";
31
+ export * from "./src/tar.ts";
32
+ export * from "./src/git.ts";
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ // @foldrun/core — the open-source runtime.
2
+ //
3
+ // Everything needed to read a workspace of markdown files and run the agents
4
+ // in it. No server, no database, no account: point it at a folder.
5
+ //
6
+ // The hosted platform imports these same modules. That is deliberate — if the
7
+ // open version were a reduced copy it would rot, and self-hosting would feel
8
+ // like a downgrade instead of a choice. What the platform adds — a queue and
9
+ // its worker, metering and billing, pods on a cluster, per-account keys in a
10
+ // database, previews, share links, tenancy — lives in its own private package
11
+ // and plugs in through platform.ts. Nothing here imports it.
12
+ export * from "./src/paths.js";
13
+ export * from "./src/store.js";
14
+ export * from "./src/starter.js";
15
+ export * from "./src/runner.js";
16
+ export * from "./src/okf.js";
17
+ export * from "./src/evals.js";
18
+ export * from "./src/flow-lint.js";
19
+ export * from "./src/catalog.js";
20
+ export * from "./src/model-probe.js";
21
+ export * from "./src/providers.js";
22
+ export * from "./src/translator.js";
23
+ export * from "./src/arrange.js";
24
+ export * from "./src/completions.js";
25
+ export * from "./src/confine.js";
26
+ export * from "./src/platform.js";
27
+ export * from "./src/library.js";
28
+ export * from "./src/tool-programs.js";
29
+ export * from "./src/linkable.js";
30
+ export * from "./src/refs.js";
31
+ export * from "./src/tool-names.js";
32
+ export * from "./src/history.js";
33
+ export * from "./src/gitrepo.js";
34
+ export * from "./src/storage.js";
35
+ export * from "./src/secrets.js";
36
+ export * from "./src/oauth-presets.js";
37
+ export * from "./src/secret-files.js";
38
+ export * from "./src/notify.js";
39
+ export * from "./src/webhook.js";
40
+ export * from "./src/approvals.js";
41
+ export * from "./src/deploy.js";
42
+ export * from "./src/tar.js";
43
+ export * from "./src/git.js";
@@ -0,0 +1,31 @@
1
+ import { createSdkMcpServer } from "@anthropic-ai/claude-agent-sdk";
2
+ import { type Effort } from "./store.ts";
3
+ export interface ConsultSpec {
4
+ name: string;
5
+ systemPrompt: string;
6
+ model: string;
7
+ /** A colleague answers at its own declared effort, not the caller's — the
8
+ * point of consulting one is that it is configured differently. */
9
+ effort: Effort | null;
10
+ }
11
+ /**
12
+ * Read the consultable colleagues' personas, host-side. Names that don't
13
+ * resolve to an agent are reported, not silently dropped.
14
+ */
15
+ export declare function gatherConsults(workspaceRoot: string, names: unknown): {
16
+ consults: ConsultSpec[];
17
+ missing: string[];
18
+ };
19
+ export interface ConsultToolResult {
20
+ /** Passed to the SDK as an in-process MCP server (the agent just sees tools). */
21
+ server: ReturnType<typeof createSdkMcpServer> | null;
22
+ toolNames: string[];
23
+ /** Model spend by the consults so far — the caller adds it to its step. */
24
+ drainCost: () => number;
25
+ }
26
+ /**
27
+ * The MCP server carrying one consult_<name> tool per colleague. Works in
28
+ * both homes — the server process and the runner container — because it
29
+ * takes values, not stores.
30
+ */
31
+ export declare function buildConsultTools(consults: ConsultSpec[], env: Record<string, string | undefined>, emit: (type: "info" | "error", text: string) => void): ConsultToolResult;
@@ -0,0 +1,99 @@
1
+ // Agent-as-tool: consult a colleague without ending your turn.
2
+ //
3
+ // agents: [researcher] # in agent.md frontmatter
4
+ //
5
+ // gives the agent one tool per named colleague — consult_researcher(question)
6
+ // — that runs that agent's persona as a one-shot, toolless model call and
7
+ // returns its answer inline. "Toolless" is the design, not a shortcut: a
8
+ // consult is asking a specialist what they think, and a consultant who could
9
+ // edit files or call APIs mid-question would be the supervisor pattern the
10
+ // spec rejects, wearing a different hat. Depth is structurally one — the
11
+ // callee is built without an agents server of its own.
12
+ //
13
+ // The flow file still owns the orchestration: who may be consulted is
14
+ // declared per agent, cost lands on the consulting step, and nothing about
15
+ // what runs next is decided by a model.
16
+ import fs from "node:fs";
17
+ import os from "node:os";
18
+ import path from "node:path";
19
+ import matter from "gray-matter";
20
+ import { z } from "zod";
21
+ import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
22
+ import { resolveModel, resolveEffort } from "./store.js";
23
+ import { executeStep } from "./step-exec.js";
24
+ import { refNames } from "./refs.js";
25
+ /**
26
+ * Read the consultable colleagues' personas, host-side. Names that don't
27
+ * resolve to an agent are reported, not silently dropped.
28
+ */
29
+ export function gatherConsults(workspaceRoot, names) {
30
+ const list = refNames(names);
31
+ const consults = [];
32
+ const missing = [];
33
+ for (const name of list) {
34
+ const file = path.join(workspaceRoot, "agents", name, "agent.md");
35
+ if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(name) || !fs.existsSync(file)) {
36
+ missing.push(name);
37
+ continue;
38
+ }
39
+ const parsed = matter(fs.readFileSync(file, "utf8"));
40
+ consults.push({
41
+ name,
42
+ systemPrompt: `${parsed.content.trim()}\n\n` +
43
+ `You are being consulted by another agent mid-task. Answer the question ` +
44
+ `directly and completely in your reply — you have no tools and no files; ` +
45
+ `everything you know is in this prompt and the question.`,
46
+ model: resolveModel(parsed.data.model),
47
+ effort: resolveEffort(parsed.data.effort),
48
+ });
49
+ }
50
+ return { consults, missing };
51
+ }
52
+ /**
53
+ * The MCP server carrying one consult_<name> tool per colleague. Works in
54
+ * both homes — the server process and the runner container — because it
55
+ * takes values, not stores.
56
+ */
57
+ export function buildConsultTools(consults, env, emit) {
58
+ if (consults.length === 0)
59
+ return { server: null, toolNames: [], drainCost: () => 0 };
60
+ let cost = 0;
61
+ const tools = consults.map((c) => tool(`consult_${c.name.replaceAll("-", "_")}`, `Ask ${c.name} — a colleague agent — one question and get their answer inline. ` +
62
+ `They see only your question, not your files or conversation; include everything they need in it.`, { question: z.string().describe("The complete, self-contained question") }, async (args) => {
63
+ const started = Date.now();
64
+ // Toolless and homeless on purpose: the consult reads and writes
65
+ // nothing — cwd is a throwaway so even a confused model call has no
66
+ // tree to touch (and no tools to touch it with).
67
+ const scratch = fs.mkdtempSync(path.join(os.tmpdir(), "foldrun-consult-"));
68
+ try {
69
+ const outcome = await executeStep({
70
+ agentDir: scratch,
71
+ workspaceRoot: scratch,
72
+ libraryRoot: scratch,
73
+ prompt: args.question,
74
+ model: c.model,
75
+ effort: c.effort,
76
+ systemPrompt: c.systemPrompt,
77
+ allowed: [],
78
+ mcpNames: [],
79
+ mcpServers: {},
80
+ env,
81
+ emit: () => { }, // the consult's inner monologue stays its own
82
+ });
83
+ cost += outcome.costUsd ?? 0;
84
+ emit("info", `consult ${c.name} → ${outcome.status} ($${(outcome.costUsd ?? 0).toFixed(4)}, ${Date.now() - started}ms)`);
85
+ return {
86
+ content: [{ type: "text", text: outcome.result ?? "(no answer)" }],
87
+ isError: outcome.status === "failed",
88
+ };
89
+ }
90
+ finally {
91
+ fs.rmSync(scratch, { recursive: true, force: true });
92
+ }
93
+ }));
94
+ return {
95
+ server: createSdkMcpServer({ name: "foldrun_agents", version: "1.0.0", tools }),
96
+ toolNames: consults.map((c) => `mcp__foldrun_agents__consult_${c.name.replaceAll("-", "_")}`),
97
+ drainCost: () => cost,
98
+ };
99
+ }
@@ -0,0 +1,9 @@
1
+ /** The frontmatter of a directory's AGENTS.md (or project.md), or {}. */
2
+ export declare function readAgentsMdKeys(dir: string): Record<string, unknown>;
3
+ /** The text of `content` with each key in `patch` replaced (or removed for
4
+ * null), everything else byte for byte as it was. A file with no
5
+ * frontmatter gets one. */
6
+ export declare function patchFrontmatter(content: string, patch: Record<string, unknown | null>): string;
7
+ /** Apply a frontmatter patch to a directory's AGENTS.md, creating the file
8
+ * when the directory has none. Returns the new content. */
9
+ export declare function setAgentsMdKeys(dir: string, patch: Record<string, unknown | null>): string;