toolbase 0.8.1__tar.gz → 0.9.0__tar.gz

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 (67) hide show
  1. {toolbase-0.8.1 → toolbase-0.9.0}/CHANGELOG.md +10 -0
  2. {toolbase-0.8.1 → toolbase-0.9.0}/PKG-INFO +3 -3
  3. {toolbase-0.8.1 → toolbase-0.9.0}/pyproject.toml +18 -5
  4. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/cli.py +126 -19
  5. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/orchestral.py +69 -6
  6. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/orchestrator.py +115 -16
  7. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/validation.py +4 -2
  8. {toolbase-0.8.1 → toolbase-0.9.0}/LICENSE +0 -0
  9. {toolbase-0.8.1 → toolbase-0.9.0}/MANIFEST.in +0 -0
  10. {toolbase-0.8.1 → toolbase-0.9.0}/README.md +0 -0
  11. {toolbase-0.8.1 → toolbase-0.9.0}/setup.cfg +0 -0
  12. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/__init__.py +0 -0
  13. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/_setup_host.py +0 -0
  14. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/_toolkit_host.py +0 -0
  15. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/astro.py +0 -0
  16. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/auth.py +0 -0
  17. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/config.py +0 -0
  18. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/__init__.py +0 -0
  19. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/base.py +0 -0
  20. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/claude_code.py +0 -0
  21. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/codex.py +0 -0
  22. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/connect/opencode.py +0 -0
  23. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/__init__.py +0 -0
  24. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/bundle_deps.py +0 -0
  25. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/cache.py +0 -0
  26. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/config.py +0 -0
  27. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/discovery.py +0 -0
  28. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/manifest.py +0 -0
  29. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/paths.py +0 -0
  30. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/envs/schema.py +0 -0
  31. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/hep.py +0 -0
  32. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/ingest.py +0 -0
  33. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/logging/__init__.py +0 -0
  34. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/logging/logger.py +0 -0
  35. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/naming.py +0 -0
  36. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/neutrino.py +0 -0
  37. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/quantum.py +0 -0
  38. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/__init__.py +0 -0
  39. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/bundles.py +0 -0
  40. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/config.py +0 -0
  41. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/profile_scaffold.py +0 -0
  42. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/profiles.py +0 -0
  43. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/serve/proxy_tool.py +0 -0
  44. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/__init__.py +0 -0
  45. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/_rpc.py +0 -0
  46. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/context.py +0 -0
  47. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/declarative.py +0 -0
  48. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/downloads.py +0 -0
  49. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/prompts.py +0 -0
  50. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/runner.py +0 -0
  51. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/schema.py +0 -0
  52. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/storage.py +0 -0
  53. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/setup/validate_cache.py +0 -0
  54. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/skills.py +0 -0
  55. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/Dockerfile.template +0 -0
  56. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/README.md.template +0 -0
  57. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/__init__.py.template +0 -0
  58. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/mcp/__init__.py.template +0 -0
  59. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/mcp/server_stdio.py.template +0 -0
  60. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/requirements.txt.template +0 -0
  61. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/setup.py.template +0 -0
  62. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/skills/example_skill.md +0 -0
  63. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/tool_example.py +0 -0
  64. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/templates/toolkit.yaml.template +0 -0
  65. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/toolkit.py +0 -0
  66. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase/versioning.py +0 -0
  67. {toolbase-0.8.1 → toolbase-0.9.0}/toolbase.egg-info/SOURCES.txt +0 -0
@@ -8,6 +8,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.9.0] — 2026-07-29
12
+
13
+ ### Changed
14
+
15
+ - **Toolkit hosts now run on MCP SDK 2.x.** The `mcp` dependency moved from `>=1.0,<2` to `>=2` and `orchestral-ai` from `>=1.4` to `>=1.10`, in both toolbase's own dependencies and the `HOST_RUNTIME_REQUIREMENTS` installed into every toolkit venv. toolbase never imports the SDK itself — it reaches it only through `orchestral.mcp` — so the major orchestral targets is the major toolbase needs, and the two bounds only make sense as a pair. orchestral 1.10 is a clean port to the 2.x API with no 1.x compatibility path and refuses to start against an older SDK; conversely orchestral <1.10 is built on the decorator API (`Server.list_tools` / `Server.call_tool`) that 2.0 removed. Since orchestral-ai declares no `mcp` constraint of its own, pinning both ends is what keeps pip off a mismatched pair.
16
+
17
+ **Existing toolkit venvs were built against mcp 1.x and need `tb install <toolkit> --rebuild`** to pick up the new pair; until then their hosts fail at startup with `'Server' object has no attribute 'list_tools'`, surfacing as `mcp connect failed: unhandled errors in a TaskGroup`.
18
+
19
+ - Toolkit validation now names `orchestral-ai>=1.10.0` as the floor a toolkit's `requirements.txt` should declare. The check itself is unchanged (still presence-only, not a version comparison).
20
+
11
21
  ## [0.8.1] — 2026-07-27
12
22
 
13
23
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolbase
3
- Version: 0.8.1
3
+ Version: 0.9.0
4
4
  Summary: The community registry and CLI for AI agent toolkits - discover, share, and serve tools to AI agents over MCP
5
5
  Author-email: Alex Roman <toolbase.dev@gmail.com>
6
6
  License: MIT
@@ -27,8 +27,8 @@ Requires-Dist: ruamel.yaml>=0.18
27
27
  Requires-Dist: rich>=13.0
28
28
  Requires-Dist: pydantic>=2.0
29
29
  Requires-Dist: email-validator>=2.0
30
- Requires-Dist: orchestral-ai>=1.4
31
- Requires-Dist: mcp>=1.0
30
+ Requires-Dist: orchestral-ai>=1.10
31
+ Requires-Dist: mcp>=2
32
32
  Requires-Dist: tomlkit>=0.12
33
33
  Provides-Extra: dev
34
34
  Requires-Dist: pytest>=7.0; extra == "dev"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "toolbase"
7
- version = "0.8.1"
7
+ version = "0.9.0"
8
8
  description = "The community registry and CLI for AI agent toolkits - discover, share, and serve tools to AI agents over MCP"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -36,10 +36,23 @@ dependencies = [
36
36
  "pydantic>=2.0",
37
37
  # Required by Pydantic's EmailStr at runtime; not imported directly.
38
38
  "email-validator>=2.0",
39
- # 1.4 introduced the `state=[...]` decorator argument that the
40
- # Phase 3C-1 setup system relies on for state-field declaration.
41
- "orchestral-ai>=1.4",
42
- "mcp>=1.0",
39
+ # 1.4 introduced the `state=[...]` decorator argument that the Phase 3C-1
40
+ # setup system relies on for state-field declaration; 1.10 is the first
41
+ # release whose orchestral.mcp is built on MCP SDK 2.x.
42
+ "orchestral-ai>=1.10",
43
+ # We never import the SDK ourselves — the host reaches it only through
44
+ # `orchestral.mcp` — so the major orchestral targets is the major we need,
45
+ # and these two bounds only make sense as a pair. orchestral >=1.10 ported
46
+ # to 2.x with no 1.x compatibility path and refuses to start against an
47
+ # older SDK; orchestral <1.10 is built on the decorator API
48
+ # (`Server.list_tools` / `Server.call_tool`) that 2.0 removed, and dies at
49
+ # startup with `'Server' object has no attribute 'list_tools'` — which
50
+ # reaches the user only as `mcp connect failed: unhandled errors in a
51
+ # TaskGroup`. orchestral-ai declares no mcp constraint of its own, so
52
+ # nothing but this pin keeps pip off a mismatched pair.
53
+ # Keep in sync with HOST_RUNTIME_REQUIREMENTS in cli.py, which applies the
54
+ # same pair to each toolkit's venv.
55
+ "mcp>=2",
43
56
  # Round-trips ~/.codex/config.toml for `tb connect codex` while preserving
44
57
  # the user's comments + formatting. The stdlib only reads TOML (tomllib);
45
58
  # tomlkit is the writer (same role ruamel.yaml plays for our YAML).
@@ -25,6 +25,29 @@ from .config import _api_url
25
25
  console = Console()
26
26
 
27
27
 
28
+ # The runtime every per-toolkit venv needs so ``toolbase._toolkit_host`` can
29
+ # start inside it: orchestral supplies ``@define_tool`` and the tool plumbing,
30
+ # mcp is the wire the host speaks to the orchestrator.
31
+ #
32
+ # Both bounds are load-bearing, not cosmetic, and they have to move as a pair.
33
+ # ``orchestral-ai`` declares no mcp constraint of its own, so pip is free to
34
+ # pick a combination neither side supports:
35
+ #
36
+ # * orchestral <1.10 is written against MCP SDK 1.x. With mcp 2.x resolved,
37
+ # the host dies at startup with `'Server' object has no attribute
38
+ # 'list_tools'` (2.0 dropped the decorator API), which the orchestrator can
39
+ # only report as the opaque `mcp connect failed: unhandled errors in a
40
+ # TaskGroup`.
41
+ # * orchestral >=1.10 is a clean port to 2.x with no 1.x compatibility path.
42
+ # Paired with mcp 1.x its ``_check_mcp_installed`` refuses to start.
43
+ #
44
+ # Either way the venv is born broken and the failure has nothing to do with
45
+ # what the user was doing. Pinning both ends is what keeps that from happening.
46
+ #
47
+ # Keep in sync with the ``orchestral-ai`` and ``mcp`` pins in pyproject.toml.
48
+ HOST_RUNTIME_REQUIREMENTS = ["orchestral-ai>=1.10", "mcp>=2"]
49
+
50
+
28
51
  # ── Agent-friendliness: --yes / --no / --no-input across all commands ──────
29
52
  #
30
53
  # Per STATUS.md §"Named principles" (flag-equivalence) and the Tier-1 polish
@@ -3221,11 +3244,10 @@ def setup_venv_environment(
3221
3244
  )
3222
3245
  console.print("[green]✓ Bundle dependencies installed[/green]")
3223
3246
 
3224
- # Install orchestral-ai + mcp SDK. Both are required: orchestral provides
3225
- # the @define_tool decorator and tool plumbing; mcp is what the per-toolkit
3226
- # subprocess (toolbase serve's host) uses to expose tools over HTTP.
3247
+ # Install the host runtime (orchestral + a compatible mcp) into the venv.
3248
+ # See HOST_RUNTIME_REQUIREMENTS for why the mcp bound matters.
3227
3249
  _run_pip_with_progress(
3228
- [str(pip_path), 'install', 'orchestral-ai', 'mcp'],
3250
+ [str(pip_path), 'install', *HOST_RUNTIME_REQUIREMENTS],
3229
3251
  console,
3230
3252
  "Installing orchestral-ai and mcp",
3231
3253
  )
@@ -3351,7 +3373,7 @@ def setup_conda_environment(
3351
3373
  try:
3352
3374
  _run_pip_with_progress(
3353
3375
  [conda_cmd, 'run', '-n', env_name, 'pip', 'install',
3354
- 'orchestral-ai', 'mcp'],
3376
+ *HOST_RUNTIME_REQUIREMENTS],
3355
3377
  console,
3356
3378
  f"Installing orchestral + mcp in '{env_name}'",
3357
3379
  )
@@ -7015,7 +7037,7 @@ def _unsurface_skills_for_connect(adapter) -> None:
7015
7037
  help='List supported harnesses and detection status, then exit.')
7016
7038
  @click.option('--out', 'out_path', default=None, metavar='PATH',
7017
7039
  help='(orchestral) Path for the generated agent script '
7018
- '(default: .toolbase/orchestral.py).')
7040
+ '(default: .toolbase/agent.py).')
7019
7041
  @click.option('--force', 'force', is_flag=True, default=False,
7020
7042
  help='(orchestral) Overwrite an existing generated script.')
7021
7043
  @click.option('--no-skills', 'no_skills', is_flag=True, default=False,
@@ -7036,8 +7058,8 @@ def connect(harness, global_scope, local_scope, profile_name, remove, dry_run,
7036
7058
  tb connect claude-code -g # user: ~/.claude.json (every session)
7037
7059
  tb connect claude-code --profile paper
7038
7060
  tb connect claude-code --remove
7039
- tb connect orchestral # write .toolbase/orchestral.py
7040
- tb connect orchestral --profile paper --out agent.py
7061
+ tb connect orchestral # write .toolbase/agent.py
7062
+ tb connect orchestral --profile paper --out my_agent.py
7041
7063
  tb connect --list # where is toolbase wired?
7042
7064
  tb connect --harnesses # which harnesses are supported?
7043
7065
  """
@@ -7218,32 +7240,75 @@ def _connect_print_status(adapters, project_root) -> None:
7218
7240
  )
7219
7241
 
7220
7242
 
7221
- def _orchestral_script_path(out=None):
7243
+ def _orchestral_script_path(out=None, *, accept_legacy=False):
7222
7244
  """Resolve the orchestral launcher path: ``--out`` if given, else
7223
- ``<project-root>/.toolbase/orchestral.py`` (project discovered by walking
7224
- up from the cwd; falls back to the cwd when not in a project)."""
7245
+ ``<project-root>/.toolbase/agent.py`` (project discovered by walking
7246
+ up from the cwd; falls back to the cwd when not in a project).
7247
+
7248
+ ``accept_legacy`` is for the read side (``tb orchestral``, ``--remove``):
7249
+ when the current default doesn't exist but an older
7250
+ ``.toolbase/orchestral.py`` does, return that instead so an existing
7251
+ checkout keeps working. The write side never uses it -- new scaffolds
7252
+ always take the current name (the legacy one shadows the ``orchestral``
7253
+ package; see ``connect/orchestral.py``).
7254
+ """
7225
7255
  from pathlib import Path as _Path
7226
- from .connect.orchestral import DEFAULT_SCRIPT_NAME
7256
+ from .connect.orchestral import DEFAULT_SCRIPT_NAME, LEGACY_SCRIPT_NAME
7227
7257
  from .envs import find_project_root
7228
7258
 
7229
7259
  if out:
7230
7260
  return _Path(out)
7231
7261
  root = find_project_root() or _Path.cwd()
7232
- return root / ".toolbase" / DEFAULT_SCRIPT_NAME
7262
+ path = root / ".toolbase" / DEFAULT_SCRIPT_NAME
7263
+ if accept_legacy and not path.exists():
7264
+ legacy = root / ".toolbase" / LEGACY_SCRIPT_NAME
7265
+ if legacy.exists():
7266
+ return legacy
7267
+ return path
7268
+
7269
+
7270
+ def _warn_if_profile_selects_nothing(profile_name) -> None:
7271
+ """Warn at connect time if the profile the scaffold will serve is empty.
7272
+
7273
+ Without this the user only finds out at launch, as a bare
7274
+ ``RuntimeError: no toolkits could be started`` from deep inside the
7275
+ orchestrator. Best-effort: an unresolvable profile is not a reason to
7276
+ refuse to write the scaffold, so any failure here is silent.
7277
+ """
7278
+ from pathlib import Path as _Path
7279
+ from .envs import find_project_root
7280
+ from .serve.profiles import resolve_profile
7281
+
7282
+ try:
7283
+ root = find_project_root() or _Path.cwd()
7284
+ profile = resolve_profile(root, cli_profile=profile_name)
7285
+ except Exception:
7286
+ return
7287
+ if profile.toolkits:
7288
+ return
7289
+ console.print(
7290
+ f"[yellow]Note: profile '{profile.name}' currently serves no "
7291
+ "toolkits[/yellow] — the agent would start with zero tools."
7292
+ )
7293
+ console.print(
7294
+ " [dim]Activate one with[/dim] [cyan]tb activate <toolkit>[/cyan]"
7295
+ "[dim], then check with[/dim] [cyan]tb serve --dry-run[/cyan][dim].[/dim]"
7296
+ )
7233
7297
 
7234
7298
 
7235
7299
  def _connect_orchestral(*, profile_name, out, force, dry_run, remove) -> None:
7236
7300
  """Handle `tb connect orchestral`: write (or remove) a runnable agent
7237
- script at ``<project>/.toolbase/orchestral.py``. Orchestral is a library
7301
+ script at ``<project>/.toolbase/agent.py``. Orchestral is a library
7238
7302
  harness, not a config-file one, so "connecting" means scaffolding the code
7239
7303
  that hands toolbase's tools to an orchestral Agent -- the user owns the
7240
7304
  agent (LLM, prompt, launch modality). Launch it with `tb orchestral`.
7241
7305
  """
7242
7306
  from .connect.orchestral import (
7243
7307
  agent_script, is_orchestral_available, GENERATED_MARKER,
7308
+ LEGACY_SCRIPT_NAME,
7244
7309
  )
7245
7310
 
7246
- path = _orchestral_script_path(out)
7311
+ path = _orchestral_script_path(out, accept_legacy=remove)
7247
7312
 
7248
7313
  if remove:
7249
7314
  if not path.exists():
@@ -7280,11 +7345,37 @@ def _connect_orchestral(*, profile_name, out, force, dry_run, remove) -> None:
7280
7345
  path.parent.mkdir(parents=True, exist_ok=True)
7281
7346
  path.write_text(content, encoding="utf-8")
7282
7347
  console.print(f"[green]✓[/green] Wrote orchestral agent scaffold to {path}.")
7348
+
7349
+ # A scaffold from 0.8.1 or earlier next to the new one is not just
7350
+ # clutter: it is named `orchestral.py`, sits in the same directory, and
7351
+ # that directory heads `sys.path` at launch -- so it shadows the
7352
+ # `orchestral` package the new script imports. Retire it (marker-checked,
7353
+ # same rule as --remove).
7354
+ legacy = path.parent / LEGACY_SCRIPT_NAME
7355
+ if legacy.exists() and legacy != path:
7356
+ try:
7357
+ first = legacy.read_text(encoding="utf-8").split("\n", 1)[0]
7358
+ except OSError:
7359
+ first = ""
7360
+ if first.startswith(GENERATED_MARKER):
7361
+ legacy.unlink()
7362
+ console.print(
7363
+ f" [dim]Removed the superseded {legacy.name} (it shadowed "
7364
+ "the orchestral package).[/dim]"
7365
+ )
7366
+ else:
7367
+ console.print(
7368
+ f"[yellow]Warning: {legacy} is not toolbase-generated, so it "
7369
+ "was left alone — but it shadows the orchestral package and "
7370
+ "will break this script. Rename it.[/yellow]"
7371
+ )
7372
+
7283
7373
  if not is_orchestral_available():
7284
7374
  console.print(
7285
7375
  "[yellow]Note: the orchestral package isn't importable here; "
7286
7376
  "the script needs it (and an LLM API key) at runtime.[/yellow]"
7287
7377
  )
7378
+ _warn_if_profile_selects_nothing(profile_name)
7288
7379
  console.print(
7289
7380
  "[dim]Configure orchestral (LLM + API key), then launch with "
7290
7381
  "[cyan]tb orchestral[/cyan].[/dim]"
@@ -7356,28 +7447,44 @@ def disconnect(harness, global_scope, local_scope, all_scopes):
7356
7447
 
7357
7448
  @main.command()
7358
7449
  @click.option('--script', 'script', default=None, metavar='PATH',
7359
- help='Path to the agent script (default: .toolbase/orchestral.py).')
7450
+ help='Path to the agent script (default: .toolbase/agent.py).')
7360
7451
  def orchestral(script):
7361
7452
  """Launch your orchestral agent script (the one `tb connect orchestral`
7362
- wrote). This just runs `python .toolbase/orchestral.py` -- the script owns
7453
+ wrote). This just runs `python .toolbase/agent.py` -- the script owns
7363
7454
  the agent (LLM, prompt, launch modality); toolbase only runs it.
7364
7455
 
7365
7456
  \b
7366
7457
  Examples:
7367
- tb connect orchestral # scaffold .toolbase/orchestral.py
7458
+ tb connect orchestral # scaffold .toolbase/agent.py
7368
7459
  tb orchestral # run it
7369
7460
  """
7370
7461
  import subprocess
7371
7462
  from pathlib import Path as _Path
7372
7463
  from .envs import find_project_root
7373
7464
 
7374
- path = _orchestral_script_path(script)
7465
+ from .connect.orchestral import LEGACY_SCRIPT_NAME
7466
+
7467
+ path = _orchestral_script_path(script, accept_legacy=True)
7375
7468
  if not path.exists():
7376
7469
  console.print(
7377
7470
  f"[red]No agent script at {path}.[/red] Create one with "
7378
7471
  "[cyan]tb connect orchestral[/cyan] first."
7379
7472
  )
7380
7473
  sys.exit(1)
7474
+ if path.name == LEGACY_SCRIPT_NAME:
7475
+ # Older scaffold: its own directory heads sys.path at launch, so the
7476
+ # file shadows the `orchestral` package it imports and the run dies
7477
+ # on `from orchestral import Agent`. Say so before it happens.
7478
+ console.print(
7479
+ f"[yellow]{path} is an older scaffold whose filename shadows the "
7480
+ "orchestral package; it cannot import it.[/yellow]"
7481
+ )
7482
+ console.print(
7483
+ " [dim]Re-scaffold with[/dim] [cyan]tb connect orchestral "
7484
+ "--force[/cyan][dim] (your old file is removed) or copy your "
7485
+ "edits into .toolbase/agent.py.[/dim]"
7486
+ )
7487
+ sys.exit(1)
7381
7488
  # Run with the interpreter toolbase runs under (toolbase + orchestral live
7382
7489
  # there), cwd = the project root so the script resolves the active profile
7383
7490
  # and orchestral persists its conversation under the project.
@@ -43,8 +43,16 @@ from ..serve.orchestrator import DEFAULT_CALL_TIMEOUT_S, Orchestrator
43
43
  # The scaffold ``tb connect orchestral`` writes, relative to a project root.
44
44
  # It lives under ``.toolbase/`` (alongside manifest.yaml / serve.yaml) and is
45
45
  # launched by ``tb orchestral``.
46
- DEFAULT_SCRIPT_NAME = "orchestral.py"
47
- DEFAULT_SCRIPT_RELPATH = ".toolbase/orchestral.py"
46
+ #
47
+ # NOT named ``orchestral.py``: Python puts a script's own directory at the
48
+ # head of ``sys.path``, so a file by that name shadows the ``orchestral``
49
+ # package it imports and every launch dies with "cannot import name 'Agent'
50
+ # from partially initialized module 'orchestral'". That was the 0.8.1 and
51
+ # earlier default; ``LEGACY_SCRIPT_NAME`` exists so the runner and
52
+ # ``--remove`` still find those files.
53
+ DEFAULT_SCRIPT_NAME = "agent.py"
54
+ DEFAULT_SCRIPT_RELPATH = ".toolbase/agent.py"
55
+ LEGACY_SCRIPT_NAME = "orchestral.py"
48
56
 
49
57
  # First line of every generated scaffold. ``tb connect orchestral --remove``
50
58
  # only deletes a file carrying this marker, so it never removes a script the
@@ -183,10 +191,23 @@ def agent_script(profile: Optional[str] = None) -> str:
183
191
  launch modalities -- terminal UI, headless, web GUI -- with the terminal
184
192
  UI active and the other two commented out. The user edits to switch.
185
193
 
194
+ Two things the scaffold does deliberately, because getting them wrong is
195
+ the difference between a working agent and a confusing one:
196
+
197
+ - **One workspace.** A single ``WORKSPACE`` dir is passed to
198
+ ``toolbase_tools(config_overrides=...)`` *and* to orchestral's own file
199
+ tools, so every tool resolves relative paths against the same root.
200
+ Without it, toolbase-served tools write wherever
201
+ ``~/.toolbase/config/<toolkit>.yaml`` points and the agent cannot read
202
+ back its own output.
203
+ - **File tools.** Served toolkits are domain tools; on their own the agent
204
+ has no way to open the files they produce. The scaffold pairs them with
205
+ orchestral's read/write/edit/search/run tools, all scoped to WORKSPACE.
206
+
186
207
  Configuring orchestral (the LLM, API keys) is the user's job; the scaffold
187
208
  just shows where their LLM plugs in.
188
209
  """
189
- profile_arg = f'profile="{profile}"' if profile else ""
210
+ profile_arg = f'profile="{profile}", ' if profile else ""
190
211
  profile_note = (
191
212
  f'serving the "{profile}" profile'
192
213
  if profile
@@ -201,16 +222,57 @@ def agent_script(profile: Optional[str] = None) -> str:
201
222
  # Run it: tb orchestral (or: python {DEFAULT_SCRIPT_RELPATH})
202
223
  """Launch an orchestral agent wired with your toolbase tools."""
203
224
 
204
- from toolbase.connect.orchestral import toolbase_tools
225
+ import os
226
+ import sys
227
+ from pathlib import Path
228
+
229
+ # Python puts this script's own directory at the head of `sys.path`, so a
230
+ # sibling module named after a package we import (`orchestral.py`, say) would
231
+ # shadow the real package. Demote our directory to the end: site-packages wins,
232
+ # but local imports still resolve. Drop these lines if you move this script
233
+ # somewhere its directory must take import priority.
234
+ _here = os.path.dirname(os.path.abspath(__file__))
235
+ if sys.path and os.path.abspath(sys.path[0] or ".") == _here:
236
+ sys.path.append(sys.path.pop(0))
237
+
205
238
  from orchestral import Agent
206
239
  from orchestral.llm import Claude # swap for GPT, Gemini, ... as you like
240
+ from orchestral.tools import (
241
+ EditFileTool, FileSearchTool, FindFilesTool, ReadFileTool,
242
+ RunCommandTool, RunPythonTool, WriteFileTool,
243
+ )
244
+
245
+ from toolbase.connect.orchestral import toolbase_tools
246
+
247
+ # The one directory every tool works in -- both the toolbase-served toolkits
248
+ # and the orchestral file tools below. Keeping them on the same root is what
249
+ # lets the agent read back the files its own tools write. Point it anywhere.
250
+ WORKSPACE = Path(__file__).resolve().parent.parent / "workspace"
207
251
 
208
252
 
209
253
  def main():
254
+ WORKSPACE.mkdir(parents=True, exist_ok=True)
255
+
210
256
  # `toolbase_tools` spins up one subprocess per served toolkit ({profile_note})
211
257
  # and yields the tools as orchestral BaseTool instances. They are torn
212
- # down when the `with` block exits.
213
- with toolbase_tools({profile_arg}) as tools:
258
+ # down when the `with` block exits. `config_overrides` scopes every served
259
+ # toolkit to WORKSPACE, overriding the `base_directory` in
260
+ # ~/.toolbase/config/<toolkit>.yaml for this run only.
261
+ with toolbase_tools(
262
+ {profile_arg}config_overrides={{"base_directory": str(WORKSPACE)}},
263
+ ) as served:
264
+ tools = [
265
+ # General-purpose tools, scoped to the same workspace.
266
+ ReadFileTool(base_directory=str(WORKSPACE), show_line_numbers=True),
267
+ WriteFileTool(base_directory=str(WORKSPACE)),
268
+ EditFileTool(base_directory=str(WORKSPACE)),
269
+ FindFilesTool(base_directory=str(WORKSPACE)),
270
+ FileSearchTool(base_directory=str(WORKSPACE)),
271
+ RunCommandTool(base_directory=str(WORKSPACE)),
272
+ RunPythonTool(base_directory=str(WORKSPACE)),
273
+ # Your toolbase toolkits.
274
+ *served,
275
+ ]
214
276
  agent = Agent(llm=Claude(), tools=tools)
215
277
 
216
278
  # -- Pick a launch modality: one is active, the others are commented. --
@@ -238,5 +300,6 @@ __all__ = [
238
300
  "is_orchestral_available",
239
301
  "DEFAULT_SCRIPT_NAME",
240
302
  "DEFAULT_SCRIPT_RELPATH",
303
+ "LEGACY_SCRIPT_NAME",
241
304
  "GENERATED_MARKER",
242
305
  ]
@@ -50,7 +50,7 @@ from typing import Any, Dict, List, Optional, Tuple
50
50
 
51
51
  from rich.console import Console
52
52
 
53
- from ..config import LOGS_DIR, TOOLKITS_DIR
53
+ from ..config import CONFIG_DIR, LOGS_DIR, TOOLKITS_DIR
54
54
  from ..envs.cache import LEGACY_META_FILE
55
55
  from ..logging.logger import ToolLogger, get_logger
56
56
 
@@ -326,6 +326,7 @@ def _legacy_discover_toolkits(toolkits_dir: Path) -> List[ToolkitDiscovery]:
326
326
 
327
327
  def _resolve_state_config(
328
328
  disc: ToolkitDiscovery,
329
+ overrides: Optional[Dict[str, Any]] = None,
329
330
  ) -> Tuple[Optional[Dict[str, Any]], Optional[str]]:
330
331
  """Validate the toolkit's stored config against its declared schema.
331
332
 
@@ -339,6 +340,13 @@ def _resolve_state_config(
339
340
  user hasn't filled in, or stored values fail validation. The
340
341
  orchestrator skips this toolkit with ``reason`` in the banner.
341
342
 
343
+ ``overrides`` is the embedder's ``config_overrides`` (see
344
+ ``Orchestrator.__init__``). A field the embedder supplies counts as
345
+ filled in: it satisfies a required field and clears a stored-but-
346
+ invalid one, because the override is what the host will actually
347
+ receive. Without this a caller could pass the exact value a toolkit
348
+ demands and still watch it get skipped for lacking that value.
349
+
342
350
  Imports the setup module lazily so a malformed ``config:`` block
343
351
  in some other toolkit can't take down the whole orchestrator
344
352
  startup. Per-toolkit failures stay per-toolkit.
@@ -388,6 +396,17 @@ def _resolve_state_config(
388
396
  resolution = load_state_config(
389
397
  disc.name, schema, project_root=project_root,
390
398
  )
399
+ if overrides:
400
+ # Anything the embedder supplies is going to reach the host, so
401
+ # it can't also be "missing" or "invalid". Drop those complaints
402
+ # before the go/no-go check.
403
+ supplied = set(overrides)
404
+ resolution.missing_required = [
405
+ n for n in resolution.missing_required if n not in supplied
406
+ ]
407
+ resolution.invalid = [
408
+ (n, e) for (n, e) in resolution.invalid if n not in supplied
409
+ ]
391
410
  if not resolution.ok:
392
411
  return None, "config incomplete — " + (resolution.skip_reason() or "unknown")
393
412
  state_config = dict(resolution.state_config)
@@ -584,6 +603,7 @@ def _tool_yaml_name_to_mcp_name(class_name: str) -> str:
584
603
 
585
604
  def _resolve_bundle_availability(
586
605
  disc: "ToolkitDiscovery",
606
+ overrides: Optional[Dict[str, Any]] = None,
587
607
  ) -> Tuple[Any, Dict[str, List[str]]]:
588
608
  """Evaluate this toolkit's ``bundles:`` against its resolved config.
589
609
 
@@ -599,6 +619,12 @@ def _resolve_bundle_availability(
599
619
  VALUE>`` sentinel counts as unset, matching the existing
600
620
  state-config gate semantics one level up.
601
621
 
622
+ ``overrides`` (the embedder's ``config_overrides``) is merged last,
623
+ for the same reason the state-config gate honors it: a bundle whose
624
+ ``requires:`` key the embedder supplies in-process is satisfied, so
625
+ gating it on the stored file alone would hide tools the caller just
626
+ configured.
627
+
602
628
  On any read failure (no toolkit.yaml, malformed file, etc.),
603
629
  returns an empty availability that gates nothing — pass-through
604
630
  behavior so a broken yaml doesn't take down all toolkits.
@@ -632,6 +658,9 @@ def _resolve_bundle_availability(
632
658
  # startup over a config-resolution glitch.
633
659
  resolved_config = {}
634
660
 
661
+ if overrides:
662
+ resolved_config = {**resolved_config, **overrides}
663
+
635
664
  availability = evaluate_bundles(bundles_block, resolved_config)
636
665
  return availability, name_to_bundles
637
666
 
@@ -738,6 +767,73 @@ def _strip_caller_env_activation(env: Dict[str, str]) -> Dict[str, str]:
738
767
  return env
739
768
 
740
769
 
770
+ def _toolbase_package_dir() -> Path:
771
+ """Absolute path of the running ``toolbase`` package directory."""
772
+ import toolbase as _tb
773
+ _tb_file = getattr(_tb, "__file__", None)
774
+ if _tb_file:
775
+ return Path(_tb_file).resolve().parent
776
+ # Namespace-package / some editable layouts leave ``__file__`` None;
777
+ # ``__path__`` still points at the package dir.
778
+ return Path(next(iter(_tb.__path__))).resolve()
779
+
780
+
781
+ def _staged_toolbase_path() -> Optional[Path]:
782
+ """Return a directory whose ONLY importable entry is ``toolbase``.
783
+
784
+ This is what the per-toolkit host gets on ``PYTHONPATH``, and the
785
+ "only" is the entire point. ``PYTHONPATH`` entries land ahead of the
786
+ toolkit venv's ``site-packages``, so handing over the directory that
787
+ merely *contains* toolbase means the whole serving environment
788
+ shadows the toolkit's own: under a normal (non-editable) install
789
+ that directory is ``site-packages``, and ``mcp``, ``numpy``,
790
+ ``pydantic`` and ``orchestral`` all resolve to the orchestrator's
791
+ copies instead of the venv's. The per-toolkit venv then supplies only
792
+ what the serving env happens to lack and never wins a conflict --
793
+ which defeats the isolation the subprocess design exists to provide,
794
+ and makes a toolkit's behavior depend on whichever machine serves it.
795
+
796
+ A directory holding a single ``toolbase`` symlink gives the host what
797
+ it needs and nothing more. That is affordable because the host's
798
+ dependency footprint on the toolbase side is pure-Python and tiny:
799
+ ``_toolkit_host`` imports the stdlib, ``orchestral``, and
800
+ ``toolbase.naming`` (via ``toolbase/__init__``) -- no third-party
801
+ package. ``orchestral`` and ``mcp`` come from the venv, where
802
+ ``tb install`` puts them on purpose.
803
+
804
+ Staged under ``~/.toolbase/hostpath/<hash of the package path>`` so
805
+ two toolbase installs (an editable checkout and a released one, say)
806
+ never collide. The symlink is revalidated on every call and replaced
807
+ atomically, so an upgraded or moved install self-heals.
808
+
809
+ Returns ``None`` if the staging directory can't be created (a
810
+ filesystem without symlinks, a read-only home); the caller then falls
811
+ back to the historical leaky-but-working behavior rather than failing
812
+ to serve.
813
+ """
814
+ import hashlib
815
+
816
+ pkg_dir = _toolbase_package_dir()
817
+ key = hashlib.sha256(str(pkg_dir).encode("utf-8")).hexdigest()[:12]
818
+ stage = CONFIG_DIR / "hostpath" / key
819
+ link = stage / "toolbase"
820
+ try:
821
+ # Fast path: already staged and still pointing where we think.
822
+ if link.is_symlink() and Path(os.readlink(link)) == pkg_dir:
823
+ return stage
824
+ stage.mkdir(parents=True, exist_ok=True)
825
+ # Build beside the target and rename over it, so a concurrent serve
826
+ # either sees the old link or the new one -- never a missing one.
827
+ tmp = stage / f".toolbase.{os.getpid()}"
828
+ if tmp.is_symlink() or tmp.exists():
829
+ tmp.unlink()
830
+ tmp.symlink_to(pkg_dir, target_is_directory=True)
831
+ os.replace(tmp, link)
832
+ return stage
833
+ except (OSError, NotImplementedError):
834
+ return None
835
+
836
+
741
837
  def _build_host_env(toolkit_path: Path, toolkit_name: str,
742
838
  *, venv_bin: Optional[str] = None) -> Dict[str, str]:
743
839
  """Compose the subprocess environment for the per-toolkit host.
@@ -748,8 +844,10 @@ def _build_host_env(toolkit_path: Path, toolkit_name: str,
748
844
 
749
845
  The toolkit's interpreter doesn't have ``toolbase`` installed, only
750
846
  ``orchestral-ai`` and ``mcp``. We need ``toolbase._toolkit_host`` to
751
- be importable, so we point ``PYTHONPATH`` at the parent package
752
- location of the running orchestrator.
847
+ be importable, so ``PYTHONPATH`` carries a staged directory holding
848
+ nothing but a ``toolbase`` symlink -- see ``_staged_toolbase_path``
849
+ for why exposing the package's real parent directory instead leaks
850
+ the entire serving environment into the toolkit's venv.
753
851
 
754
852
  The caller's activated-conda/venv pollution is first stripped (see
755
853
  ``_strip_caller_env_activation``) so the toolkit's isolated env is
@@ -764,16 +862,11 @@ def _build_host_env(toolkit_path: Path, toolkit_name: str,
764
862
  plumbing.
765
863
  """
766
864
  env = _strip_caller_env_activation(os.environ.copy())
767
- # Find the directory that contains the ``toolbase`` package.
768
- import toolbase as _tb
769
- _tb_file = getattr(_tb, "__file__", None)
770
- if _tb_file:
771
- pkg_parent = str(Path(_tb_file).resolve().parent.parent)
772
- else:
773
- # Namespace-package / some editable layouts leave ``__file__`` None;
774
- # ``__path__`` still points at the package dir, so its parent is the
775
- # directory that contains the ``toolbase`` package.
776
- pkg_parent = str(Path(next(iter(_tb.__path__))).resolve().parent)
865
+ staged = _staged_toolbase_path()
866
+ # Fall back to the package's real parent when staging is unavailable.
867
+ # That re-leaks the serving env, but a leaky serve beats no serve.
868
+ pkg_parent = str(staged if staged is not None
869
+ else _toolbase_package_dir().parent)
777
870
  existing = env.get("PYTHONPATH", "")
778
871
  env["PYTHONPATH"] = (
779
872
  pkg_parent + (os.pathsep + existing if existing else "")
@@ -1235,7 +1328,9 @@ class Orchestrator:
1235
1328
  """
1236
1329
  # Resolve declarative state-config first. A missing-required-
1237
1330
  # field condition means we never spawn.
1238
- state_config, config_err = _resolve_state_config(disc)
1331
+ state_config, config_err = _resolve_state_config(
1332
+ disc, self._config_overrides,
1333
+ )
1239
1334
  if config_err is not None:
1240
1335
  self.console.print(
1241
1336
  f" [red]✗[/red] [dim]{disc.name:<18}[/dim] "
@@ -1314,7 +1409,9 @@ class Orchestrator:
1314
1409
  message=note, level="warn",
1315
1410
  )
1316
1411
 
1317
- availability, name_to_bundles = _resolve_bundle_availability(disc)
1412
+ availability, name_to_bundles = _resolve_bundle_availability(
1413
+ disc, self._config_overrides,
1414
+ )
1318
1415
  if availability.dropped_bundles:
1319
1416
  for bname, missing in availability.dropped_bundles.items():
1320
1417
  line = format_skip_log_line(disc.name, bname, missing)
@@ -1609,7 +1706,9 @@ class Orchestrator:
1609
1706
  # config file between sessions (the file is canonical; we always
1610
1707
  # read fresh). Same shape as initial launch: a config error here
1611
1708
  # marks the toolkit failed for this restart attempt.
1612
- state_config, config_err = _resolve_state_config(rt.discovery)
1709
+ state_config, config_err = _resolve_state_config(
1710
+ rt.discovery, self._config_overrides,
1711
+ )
1613
1712
  if config_err is not None:
1614
1713
  rt.restart_attempts = attempt
1615
1714
  rt.last_error = config_err
@@ -804,8 +804,10 @@ def validate_toolkit(toolkit_path: Path) -> ValidationResult:
804
804
  ):
805
805
  result.is_valid = False
806
806
  result.errors.append(
807
- "requirements.txt must include 'orchestral-ai>=1.0.0' "
808
- "(required for Orchestral tool framework)"
807
+ "requirements.txt must include 'orchestral-ai>=1.10.0' "
808
+ "(required for Orchestral tool framework; 1.10 is the "
809
+ "first release built on MCP SDK 2.x, which is what the "
810
+ "toolkit host speaks)"
809
811
  )
810
812
 
811
813
  except Exception as e:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes