API reference¶
Command-line interface¶
Command-line interface for packaged research-foundry templates.
Examples:
>>> callable(main)
True
main(argv=None)
¶
Run the research-foundry command-line interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argv
|
Sequence[str] | None
|
Arguments without the executable name, or |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The process exit status. |
Examples:
>>> callable(main)
True
Source code in src/research_foundry/cli.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Templates¶
Read and render the templates shipped by research-foundry.
Examples:
>>> {item.name for item in list_templates()} == set(TEMPLATE_NAMES)
True
FoundryError
¶
Bases: RuntimeError
A requested operation was refused with a corrective message.
Examples:
>>> str(FoundryError("Choose a known template."))
'Choose a known template.'
Source code in src/research_foundry/templates.py
33 34 35 36 37 38 39 | |
HookRefusal
¶
Bases: FoundryError
A template hook refused the selected answers.
Examples:
>>> str(HookRefusal("Choose a compatible component set."))
'Choose a compatible component set.'
Source code in src/research_foundry/templates.py
42 43 44 45 46 47 48 | |
Question
dataclass
¶
One answer accepted by a template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The context key. |
required |
prompt
|
str
|
The text shown to a person. |
required |
default
|
str
|
The non-interactive default. |
required |
choices
|
tuple[str, ...]
|
Allowed values, or an empty tuple for free text. |
required |
Examples:
>>> Question("venue", "Venue", "iclr", ("iclr",)).default
'iclr'
Source code in src/research_foundry/templates.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
as_dict()
¶
Return a JSON-compatible representation.
Returns:
| Type | Description |
|---|---|
dict[str, str | list[str]]
|
The question fields with choices represented as a list. |
Examples:
>>> Question("x", "X", "a", ("a",)).as_dict()["choices"]
['a']
Source code in src/research_foundry/templates.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Template
dataclass
¶
One public project template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The command-line template name. |
required |
title
|
str
|
The human-readable title. |
required |
description
|
str
|
A short explanation of the generated project. |
required |
Examples:
>>> Template("paper", "Paper", "A paper.").name
'paper'
Source code in src/research_foundry/templates.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
as_dict()
¶
Return a JSON-compatible representation.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The template's three public fields. |
Examples:
>>> Template("paper", "Paper", "A paper.").as_dict()["title"]
'Paper'
Source code in src/research_foundry/templates.py
102 103 104 105 106 107 108 109 110 111 112 | |
asked(template, root=None)
¶
Return the public answer names accepted by a template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A name from :func: |
required |
root
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
Returns:
| Type | Description |
|---|---|
set[str]
|
The template's non-private context keys. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template is unknown or malformed. |
Examples:
>>> "project_name" in asked("workspace")
True
Source code in src/research_foundry/templates.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
asked_from_json(text)
¶
Return public answer names from Cookiecutter context JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The complete |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Every non-private top-level key. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the text is not a JSON object. |
Examples:
>>> asked_from_json('{"name": "Example", "_private": "x"}')
{'name'}
Source code in src/research_foundry/templates.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
create_project(template, answers, output_dir, *, source=None, write_cruft=True)
¶
Render one project offline from the packaged templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A name from :func: |
required |
answers
|
Mapping[str, str]
|
Explicit Cookiecutter context overrides. |
required |
output_dir
|
Path
|
Parent directory for the generated project. |
required |
source
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
write_cruft
|
bool
|
Whether to record update metadata. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The generated project directory. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template or an answer is unknown. |
HookRefusal
|
If the template's hook refuses the answer combination. |
Examples:
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as directory:
... made = create_project("workspace", {}, Path(directory),
... write_cruft=False)
... (made / "README.md").is_file()
True
Source code in src/research_foundry/templates.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
describe_questions(template, root=None)
¶
Describe every public answer a template accepts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A name from :func: |
required |
root
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
Returns:
| Type | Description |
|---|---|
list[Question]
|
Questions in Cookiecutter context order. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template is unknown or its context is malformed. |
Examples:
>>> describe_questions("paper")[0].name
'project_name'
Source code in src/research_foundry/templates.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
hook_reason(text)
¶
Extract a generation hook's own refusal reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Cookiecutter's captured standard error. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hook output before Cookiecutter's wrapper message. |
Examples:
>>> hook_reason("choose another value\nStopping generation!")
'choose another value'
Source code in src/research_foundry/templates.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
list_templates(root=None)
¶
List the templates in the root catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
Returns:
| Type | Description |
|---|---|
list[Template]
|
Templates in catalog order. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the installed catalog is malformed. |
Examples:
>>> [item.name for item in list_templates()]
['methodology', 'workspace', 'paper', 'software']
Source code in src/research_foundry/templates.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
plan_project(template, answers, *, source=None)
¶
Validate a project by rendering it and return its file list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A name from :func: |
required |
answers
|
Mapping[str, str]
|
Explicit Cookiecutter context overrides. |
required |
source
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted file paths relative to the generated project. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template or an answer is unknown. |
HookRefusal
|
If the template's hook refuses the answer combination. |
Examples:
>>> "README.md" in plan_project("workspace", {})
True
Source code in src/research_foundry/templates.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
prepared_templates(root=None)
¶
Yield a work copy with each template's shared include restored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path | None
|
The installed or source template tree. |
None
|
Yields:
| Type | Description |
|---|---|
Path
|
A temporary Cookiecutter repository layout. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template catalog is malformed. |
Examples:
>>> with prepared_templates() as work:
... all((work / name / "templates").exists()
... for name in TEMPLATE_NAMES)
True
Source code in src/research_foundry/templates.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
release_commit(repository)
¶
Resolve this release's tag to a full SHA when reachable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository
|
str
|
A Git URL or local repository path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The full tag SHA, or |
Examples:
>>> release_commit("/path/that/does/not/exist") == f"v{__version__}"
True
Source code in src/research_foundry/templates.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
repository_url(environ=None)
¶
Return the update repository, honoring the test/user override.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environ
|
Mapping[str, str] | None
|
An alternate environment mapping. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The configured repository URL or the public repository. |
Examples:
>>> repository_url({REPOSITORY_ENV: "/tmp/foundry"})
'/tmp/foundry'
Source code in src/research_foundry/templates.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
template_root()
¶
Return the installed template tree or source-checkout fallback.
Returns:
| Type | Description |
|---|---|
Path
|
A directory containing the root |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If neither packaged nor source templates exist. |
Examples:
>>> (template_root() / "cookiecutter.json").is_file()
True
Source code in src/research_foundry/templates.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
validate_answers(template, answers, root=None)
¶
Refuse unknown templates and answers before generation writes files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A name from :func: |
required |
answers
|
Mapping[str, str]
|
Explicit Cookiecutter context overrides. |
required |
root
|
Path | None
|
An alternate template tree, mainly for isolated tests. |
None
|
Raises:
| Type | Description |
|---|---|
FoundryError
|
If the template or any answer is unknown. |
Examples:
>>> validate_answers("workspace", {"project_name": "Example"})
Source code in src/research_foundry/templates.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
write_cookiecutter_config(workdir)
¶
Write a Cookiecutter config whose mutable paths stay inside workdir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
Path
|
The temporary directory containing this Cookiecutter run. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The config file path for Cookiecutter or cruft. |
Examples:
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as work:
... config = write_cookiecutter_config(Path(work))
... settings = json.loads(config.read_text())
... Path(settings["replay_dir"]).parent == Path(work).resolve()
True
Source code in src/research_foundry/templates.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
Cruft updates¶
Check and update projects created by research-foundry.
Examples:
>>> callable(check_project) and callable(update_project)
True
check_project(path)
¶
Return whether a project matches the latest template release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The generated project's root directory. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
FoundryError
|
If |
Examples:
>>> callable(check_project)
True
Source code in src/research_foundry/cruft.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
update_project(path, *, yes=False)
¶
Apply the latest template release to a generated project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The generated project's root directory. |
required |
yes
|
bool
|
Apply without cruft's confirmation prompt. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
Cruft's success result. |
Raises:
| Type | Description |
|---|---|
FoundryError
|
If |
Examples:
>>> callable(update_project)
True
Source code in src/research_foundry/cruft.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Model Context Protocol server¶
Model Context Protocol server for research-foundry.
Examples:
>>> server.name
'research-foundry'
ToolResult
¶
Bases: TypedDict
A JSON-compatible success or refusal from an MCP tool.
Examples:
>>> ToolResult(ok=False, error="Fix the request.")["ok"]
False
Source code in src/research_foundry/server.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
check_project(path)
¶
Check whether a generated project is behind its template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The generated project's root directory. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The current/behind result or a corrective refusal. |
Examples:
>>> check_project("/path/that/does/not/exist")["ok"]
False
Source code in src/research_foundry/server.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
create_project(template, answers, output_dir, confirm)
¶
Create a project after explicit confirmation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A template name returned by :func: |
required |
answers
|
dict[str, str]
|
Explicit Cookiecutter context overrides. |
required |
output_dir
|
str
|
Parent directory for the generated project. |
required |
confirm
|
bool
|
Must be |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The created path or a corrective refusal. |
Examples:
>>> create_project("workspace", {}, "/tmp/example", False)["ok"]
False
Source code in src/research_foundry/server.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
describe_questions(template)
¶
Describe a template's public answers, defaults, and choices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A template name returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
Questions on success, or a corrective refusal. |
Examples:
>>> describe_questions("paper")["ok"]
True
Source code in src/research_foundry/server.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
list_templates()
¶
List available templates with their titles and descriptions.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
JSON-compatible template descriptions in catalog order. |
Examples:
>>> list_templates()[0]["name"]
'methodology'
Source code in src/research_foundry/server.py
51 52 53 54 55 56 57 58 59 60 61 62 | |
plan_project(template, answers)
¶
Validate answers by rendering temporarily, then list the files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
str
|
A template name returned by :func: |
required |
answers
|
dict[str, str]
|
Explicit Cookiecutter context overrides. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The generated file list or the hook's corrective refusal reason. |
Examples:
>>> plan_project("workspace", {})["ok"]
True
Source code in src/research_foundry/server.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
run()
¶
Run the server over standard input and output.
Examples:
>>> callable(run)
True
Source code in src/research_foundry/server.py
226 227 228 229 230 231 232 233 | |
update_project(path, confirm)
¶
Update a generated project after explicit confirmation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The generated project's root directory. |
required |
confirm
|
bool
|
Must be |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The update result or a corrective refusal. |
Examples:
>>> update_project("/tmp/example", False)["ok"]
False
Source code in src/research_foundry/server.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
Skills¶
Install research-foundry's maintained agent skills for one user.
Examples:
>>> Report().ok
True
Report
dataclass
¶
Describe the files written, adopted, pending, or refused.
Examples:
>>> Report(missing=["release/SKILL.md"]).ok
False
Source code in src/research_foundry/skills.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
ok
property
¶
Return whether nothing was refused or left to do.
Returns:
| Type | Description |
|---|---|
bool
|
|
Examples:
>>> Report().ok
True
destination(environ=None)
¶
Return where skills are installed for this user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environ
|
Mapping[str, str] | None
|
An alternate environment mapping. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The user's configured skills directory. |
Examples:
>>> destination({"HOME": "/home/example"})
PosixPath('/home/example/.claude/skills')
Source code in src/research_foundry/skills.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
main(argv=None)
¶
Run the skill installer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argv
|
Sequence[str] | None
|
Arguments without the executable name. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Zero on success, one when check finds drift or installation refuses. |
Examples:
>>> callable(main)
True
Source code in src/research_foundry/skills.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
run(mode, source=SKILLS, dest=None)
¶
Install, check, adopt, or force the skills into a destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
One of :data: |
required |
source
|
Path
|
The maintained skill tree. |
SKILLS
|
dest
|
Path | None
|
The user's skills directory; :func: |
None
|
Returns:
| Type | Description |
|---|---|
Report
|
What was written, adopted, pending, or refused. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as temporary:
... root = Path(temporary)
... source = root / "source"
... (source / "demo").mkdir(parents=True)
... _ = (source / "demo" / "SKILL.md").write_text("demo\n")
... run("install", source, root / "dest").ok
True
Source code in src/research_foundry/skills.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
skills_root()
¶
Return the installed skills tree or source-checkout fallback.
Returns:
| Type | Description |
|---|---|
Path
|
A directory containing the maintained skill folders. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If neither packaged nor source skills exist. |
Examples:
>>> (skills_root() / "release" / "SKILL.md").is_file()
True
Source code in src/research_foundry/skills.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |