Skip to content

Commit 5df321e

Browse files
committed
new: nerve namespaces command
1 parent 024a760 commit 5df321e

File tree

12 files changed

+64
-11
lines changed

12 files changed

+64
-11
lines changed

docs/assets/make_ns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
module = __import__(f"nerve.tools.namespaces.{modname}", fromlist=[""])
2020

2121
doc = module.__doc__ or ""
22-
print(f"## {modname}")
22+
print(f"## {module.EMOJI} {modname}")
2323
print()
2424

2525
if hasattr(module, "OPTIONAL_FEATURE"):

docs/namespaces.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Nerve offers a rich set of predefined tools, organized in namespaces, that the agent can import [via the `using` directive](index.md#usage). This page contains the list of namespaces available in Nerve, with the descriptive prompt that will be provided to the model.
44

5-
## anytool
5+
## 🔧 anytool
66

77
Let the agent create its own tools in Python.
88

@@ -19,7 +19,7 @@ Let the agent create its own tools in Python.
1919
* `code` <i>(<class 'str'>)</i>: The Python code to create the tool.
2020
</details>
2121

22-
## computer
22+
## 💻 computer
2323

2424
> [!IMPORTANT]
2525
> This namespace is not available by default and requires the `computer_use` optional feature.
@@ -94,7 +94,7 @@ Computer use primitives for mouse, keyboard, and screen.
9494

9595
</details>
9696

97-
## filesystem
97+
## 📂 filesystem
9898

9999
Read-only access primitives to the local filesystem.
100100

@@ -117,7 +117,7 @@ Read-only access primitives to the local filesystem.
117117
* `path` <i>(<class 'str'>)</i>: The path to the file to read
118118
</details>
119119

120-
## inquire
120+
## 💬 inquire
121121

122122
Let the agent interactively ask questions to the user in a structured way.
123123

@@ -157,7 +157,7 @@ Let the agent interactively ask questions to the user in a structured way.
157157
* `question` <i>(<class 'str'>)</i>: The question to ask the user.
158158
</details>
159159

160-
## reasoning
160+
## 🧠 reasoning
161161

162162
Simulates the reasoning process at runtime.
163163

@@ -199,7 +199,7 @@ Simulates the reasoning process at runtime.
199199
* `thought` <i>(<class 'str'>)</i>: A thought to think about
200200
</details>
201201

202-
## shell
202+
## 💻 shell
203203

204204
Let the agent execute shell commands.
205205

@@ -215,7 +215,7 @@ Let the agent execute shell commands.
215215
* `command` <i>(<class 'str'>)</i>: The shell command to execute
216216
</details>
217217

218-
## task
218+
## task
219219

220220
Let the agent autonomously set the task as complete or failed.
221221

@@ -238,7 +238,7 @@ Let the agent autonomously set the task as complete or failed.
238238
* `reason` <i>(<class 'str'>)</i>: The reason why the task is impossible
239239
</details>
240240

241-
## time
241+
## 🕒 time
242242

243243
Provides tools for getting the current date and time and waiting for a given number of seconds.
244244

nerve/cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import nerve
44
from nerve.cli.agents import cli as agents_cli
55
from nerve.cli.create import cli as create_cli
6+
from nerve.cli.namespaces import cli as namespaces_cli
67
from nerve.cli.replay import cli as replay_cli
78
from nerve.cli.run import cli as run_cli
89

@@ -16,8 +17,7 @@
1617
cli.add_typer(create_cli)
1718
cli.add_typer(run_cli)
1819
cli.add_typer(replay_cli)
19-
20-
# TODO: namespaces command
20+
cli.add_typer(namespaces_cli)
2121

2222

2323
@cli.command(

nerve/cli/namespaces.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pkgutil
2+
3+
import typer
4+
from termcolor import colored
5+
6+
import nerve
7+
import nerve.tools.namespaces as ns_pkg
8+
9+
cli = typer.Typer(
10+
no_args_is_help=True,
11+
pretty_exceptions_enable=False,
12+
context_settings={"help_option_names": ["-h", "--help"]},
13+
)
14+
15+
16+
@cli.command(
17+
context_settings={"help_option_names": ["-h", "--help"]},
18+
help="List all the available tools namespaces.",
19+
)
20+
def namespaces() -> None:
21+
print(f"🧠 nerve v{nerve.__version__}")
22+
print()
23+
24+
for _, modname, _ in pkgutil.iter_modules(ns_pkg.__path__):
25+
if modname[0] != "_" and not modname.startswith("test_"):
26+
module = __import__(f"nerve.tools.namespaces.{modname}", fromlist=[""])
27+
28+
doc = module.__doc__ or ""
29+
print(f"{module.EMOJI} {colored(modname, 'magenta')} - {colored(doc.strip(), 'dark_grey')}")

nerve/tools/namespaces/anytool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from nerve.runtime import state
1212
from nerve.tools.compiler import wrap_tool_function
1313

14+
# for docs
15+
EMOJI = "🔧"
16+
1417

1518
def create_tool(
1619
code: Annotated[

nerve/tools/namespaces/computer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
# this is an extra feature, so we need to indicate it
1313
OPTIONAL_FEATURE = "computer_use"
14+
# for docs
15+
EMOJI = "💻"
16+
1417
# max screenshot width
1518
MAX_WIDTH = 1280
1619
# typing delay in ms

nerve/tools/namespaces/filesystem.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from pathlib import Path
77
from typing import Annotated
88

9+
# for docs
10+
EMOJI = "📂"
11+
912
# if set, the agent will only have access to these paths
1013
jail: list[str] = []
1114

nerve/tools/namespaces/inquire.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import inquirer # type: ignore
88
from pydantic import Field
99

10+
# for docs
11+
EMOJI = "💬"
12+
1013

1114
def ask_question(
1215
question: Annotated[

nerve/tools/namespaces/reasoning.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import nerve.runtime.state as state
88

9+
# for docs
10+
EMOJI = "🧠"
11+
912

1013
def think(thought: Annotated[str, "A thought to think about"]) -> None:
1114
"""

nerve/tools/namespaces/shell.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import subprocess
66
from typing import Annotated
77

8+
# for docs
9+
EMOJI = "💻"
10+
811

912
def _maybe_text(output: bytes) -> str | bytes:
1013
try:

0 commit comments

Comments
 (0)