feat(claw): load skills and subagents and edit the identity files
android / debug (push) Successful in 2m12s
ci / checks (push) Successful in 3m42s
ci / web (push) Successful in 12s
android / release (push) Successful in 2m5s
ci / test (push) Successful in 2m12s
ci / chart (push) Successful in 6s
ci / docker (push) Successful in 1m58s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m55s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 15s
ci / publish-edge-chart (push) Successful in 4s
android / debug (push) Successful in 2m12s
ci / checks (push) Successful in 3m42s
ci / web (push) Successful in 12s
android / release (push) Successful in 2m5s
ci / test (push) Successful in 2m12s
ci / chart (push) Successful in 6s
ci / docker (push) Successful in 1m58s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m55s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 15s
ci / publish-edge-chart (push) Successful in 4s
The claw's agents had no skills and no way to delegate, and the settings
surface could only read a pair of booleans.
Skills now seed the bundled `commit-message` and `unslop` folders into
the global directory, discover the global and workspace tiers on every
dispatch, and list them in the prompt. The settings table owns an off
switch per skill, so the Skills page can hold one back without editing
YAML. The config set is the seed.
Subagents build on `rhema-subagents`. Definitions are `SUBAGENT.md`
folders under the global directory and the workspace tier, and the
parent prompt advertises the `subagent` tool. The wire passes the
parent's skills, environment report, and USER.md to the child, so a
delegated turn knows the same context.
The Bootstrap page reads the three identity files and writes SOUL.md
and USER.md. ENVIRONMENT.md stays read-only because the boot pass
rewrites it. The MCP page reads the client's config through the same
file the shell uses and shows servers, transports, and the daemon's
mute set. It stays read-only: the standalone client owns that file.
`GET` and `PUT /v1/bootstrap/{kind}`, `GET /v1/bootstrap/files`, `GET`
and `PUT /v1/skills`, and `GET /v1/mcp` carry the pages. The config
gains `skills_root`, `skills_disabled`, `subagents_root`, and
`disabled_subagents`.
fmt, clippy with -D warnings over all targets, the 304 lib and 46 HTTP
tests, and nuxt typecheck and build pass.
This commit is contained in:
1 parent
eb9f4e9ec5
commit
829f30d27e
31 files changed
+2604
-102
No files matched your search
Generated
+25
@@ -3092,6 +3092,8 @@ dependencies = [
|
|||||||
"rhema-sandbox",
|
"rhema-sandbox",
|
||||||
"rhema-sandbox-http",
|
"rhema-sandbox-http",
|
||||||
"rhema-sandbox-ssh",
|
"rhema-sandbox-ssh",
|
||||||
|
"rhema-skills",
|
||||||
|
"rhema-subagents",
|
||||||
"rhema-transcript",
|
"rhema-transcript",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3516,6 +3518,29 @@ dependencies = [
|
|||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rhema-subagents"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d30ca7b8ef1e13080eb81929fc9c4b3144965e1fc7ca3b05aa659c7914b24563"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"rhema-bash",
|
||||||
|
"rhema-config",
|
||||||
|
"rhema-core",
|
||||||
|
"rhema-host-agent",
|
||||||
|
"rhema-prompt",
|
||||||
|
"rhema-provider",
|
||||||
|
"rhema-session-store",
|
||||||
|
"rhema-skills",
|
||||||
|
"rhema-submissions",
|
||||||
|
"rhema-transcript",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_yaml",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rhema-submissions"
|
name = "rhema-submissions"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ mock = ["rhema-core/mock"]
|
|||||||
# provider into a host-operating agent (rhema-host-agent)
|
# provider into a host-operating agent (rhema-host-agent)
|
||||||
rhema-bash = "0.5.1"
|
rhema-bash = "0.5.1"
|
||||||
rhema-prompt = "0.5.1"
|
rhema-prompt = "0.5.1"
|
||||||
|
# Skill discovery: the same tiers and frontmatter the reference agent reads
|
||||||
|
rhema-skills = "0.5.1"
|
||||||
|
# The subagent extension: definitions and the `subagent` tool that runs a
|
||||||
|
# fresh agent in the background
|
||||||
|
rhema-subagents = "0.5.1"
|
||||||
rhema-host-agent = "0.5.1"
|
rhema-host-agent = "0.5.1"
|
||||||
rhema-config = "0.5.1"
|
rhema-config = "0.5.1"
|
||||||
rhema-core = "0.5.1"
|
rhema-core = "0.5.1"
|
||||||
|
|||||||
@@ -45,6 +45,30 @@ budget — in a named workspace, with one tool and an `action` argument:
|
|||||||
two agents editing the same files. Across instances, jobs run in
|
two agents editing the same files. Across instances, jobs run in
|
||||||
parallel.
|
parallel.
|
||||||
|
|
||||||
|
### Skills
|
||||||
|
|
||||||
|
The claw ships `commit-message` and `unslop`, seeds them into the
|
||||||
|
global skills directory on boot, and never overwrites an edit. Every
|
||||||
|
agent prompt lists the discovered skills, and the transcript pins the
|
||||||
|
bodies a tool reads. `skills_disabled` holds a name back from the prompt
|
||||||
|
and the transcript; `skills_root` moves the global directory. The web
|
||||||
|
client's Skills page lists what discovery finds, each skill's trigger
|
||||||
|
and path, and flips it on or off. A toggle persists in the daemon's
|
||||||
|
settings table (`skills_disabled` in the config is the seed), so it
|
||||||
|
survives a restart without hand-editing YAML.
|
||||||
|
|
||||||
|
### Subagents
|
||||||
|
|
||||||
|
The claw wires `rhema-subagents`, the same extension the coding agent
|
||||||
|
uses: a `subagent(name, prompt)` tool runs a fresh agent on a fresh
|
||||||
|
session, and its report comes back through the tool. Definitions are
|
||||||
|
`SUBAGENT.md` folders under the global directory (config:
|
||||||
|
`subagents_root`) and the workspace's `.rhema/subagents`; the built-in
|
||||||
|
`general-purpose` definition is always there. `disabled_subagents`
|
||||||
|
holds names back from the tool's catalog. A subagent inherits the
|
||||||
|
parent's skills, environment report, and USER.md, and runs on the
|
||||||
|
session's provider.
|
||||||
|
|
||||||
### The bounded request view
|
### The bounded request view
|
||||||
|
|
||||||
A claw session never ends: the interactive chat is one conversation,
|
A claw session never ends: the interactive chat is one conversation,
|
||||||
@@ -69,6 +93,10 @@ listen: 127.0.0.1:7799
|
|||||||
token: change-me # optional; when set, /v1/* requires it
|
token: change-me # optional; when set, /v1/* requires it
|
||||||
agent_token: change-me-too # the client tools' scoped bearer (rhema-tools)
|
agent_token: change-me-too # the client tools' scoped bearer (rhema-tools)
|
||||||
tools_bin: ~/.local/share/rhema-tools/bin # put the client tools on PATH
|
tools_bin: ~/.local/share/rhema-tools/bin # put the client tools on PATH
|
||||||
|
# skills_root: /home/me/.config/rhema/skills # default; bundled skills seed here
|
||||||
|
# skills_disabled: [unslop] # names held back from prompt and transcript
|
||||||
|
# subagents_root: /home/me/.config/rhema/subagents
|
||||||
|
# disabled_subagents: [reviewer] # names held back from the subagent tool
|
||||||
sandbox: # where bash runs; omit for this host
|
sandbox: # where bash runs; omit for this host
|
||||||
kind: ssh # local (default), http, or ssh
|
kind: ssh # local (default), http, or ssh
|
||||||
host: me@box.example # the ssh destination: an alias or user@host
|
host: me@box.example # the ssh destination: an alias or user@host
|
||||||
@@ -151,6 +179,8 @@ POST /v1/sessions/{key}/resume lift the hold
|
|||||||
POST /v1/sessions/{key}/abort cut the live turn, or drop the queued work
|
POST /v1/sessions/{key}/abort cut the live turn, or drop the queued work
|
||||||
GET /v1/watches POST /v1/watches DELETE /v1/watches/{forge}/{repo}
|
GET /v1/watches POST /v1/watches DELETE /v1/watches/{forge}/{repo}
|
||||||
GET /v1/bootstrap {"soul": bool, "user": bool}
|
GET /v1/bootstrap {"soul": bool, "user": bool}
|
||||||
|
GET /v1/bootstrap/files SOUL.md, USER.md, ENVIRONMENT.md + onboarding status
|
||||||
|
PUT /v1/bootstrap/{kind} {"content"} — save soul or user; environment is refused
|
||||||
POST /v1/ingest {"source","key","payload"} -> 202
|
POST /v1/ingest {"source","key","payload"} -> 202
|
||||||
GET /v1/notifications?device=&since= POST /v1/notifications/{id}/ack
|
GET /v1/notifications?device=&since= POST /v1/notifications/{id}/ack
|
||||||
GET /v1/consents the asks a turn is waiting on
|
GET /v1/consents the asks a turn is waiting on
|
||||||
@@ -161,6 +191,9 @@ GET /v1/phone/commands?device= the device's queued, unconfirmed commands
|
|||||||
POST /v1/phone/commands/{id}/result {"ok", "detail"?} — the device's report
|
POST /v1/phone/commands/{id}/result {"ok", "detail"?} — the device's report
|
||||||
GET /v1/sandbox where the agent's bash runs
|
GET /v1/sandbox where the agent's bash runs
|
||||||
PUT /v1/sandbox {"kind","url"?,"token"?,"host"?,"workspace"?}, switch and persist
|
PUT /v1/sandbox {"kind","url"?,"token"?,"host"?,"workspace"?}, switch and persist
|
||||||
|
GET /v1/skills discovered skills: trigger, path, tier, enabled
|
||||||
|
PUT /v1/skills/{name} {"enabled"} — persist one skill's off switch
|
||||||
|
GET /v1/mcp the client's config path, servers, mute set, notices
|
||||||
GET /v1/providers the backend instances + the active pair
|
GET /v1/providers the backend instances + the active pair
|
||||||
PUT /v1/providers/active {"provider","model"?} — switch, persisted
|
PUT /v1/providers/active {"provider","model"?} — switch, persisted
|
||||||
PUT /v1/providers/{id}/credentials add or replace an instance, persisted
|
PUT /v1/providers/{id}/credentials add or replace an instance, persisted
|
||||||
@@ -189,7 +222,9 @@ from an image you hand it. The same tool is yours to invoke any time
|
|||||||
pages write, so what it sets is what every client renders. Decline
|
pages write, so what it sets is what every client renders. Decline
|
||||||
and it simply keeps offering, never
|
and it simply keeps offering, never
|
||||||
interrogating. Both files stay hand-editable forever; `/v1/bootstrap`
|
interrogating. Both files stay hand-editable forever; `/v1/bootstrap`
|
||||||
lets a UI badge setup state.
|
lets a UI badge setup state, and the Bootstrap settings page edits
|
||||||
|
SOUL.md and USER.md in place. ENVIRONMENT.md stays read-only there:
|
||||||
|
the boot pass overwrites it.
|
||||||
|
|
||||||
SSE frames are `id: <seq>` plus `data: {..}`: `user_message`,
|
SSE frames are `id: <seq>` plus `data: {..}`: `user_message`,
|
||||||
`thinking_delta`, `text_delta`, `tool_start`, `tool_result`,
|
`thinking_delta`, `text_delta`, `tool_start`, `tool_result`,
|
||||||
|
|||||||
@@ -36,6 +36,39 @@ what it is for. The arguments are the JSON schema a call must satisfy.
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if skills %}
|
||||||
|
## Skills
|
||||||
|
|
||||||
|
You have access to the following skills (name | trigger | file). A skill's
|
||||||
|
description is its trigger text. To read any skill's body: `cat <file>`.
|
||||||
|
|
||||||
|
Before you answer, check the skills list below in this priority order.
|
||||||
|
|
||||||
|
- **[PRIORITY 1] Always apply** (match case-insensitively): if a skill's
|
||||||
|
description begins with or contains the exact phrase `Always apply`, load
|
||||||
|
it and apply ALL its rules, no matter what the task is. This overrides
|
||||||
|
the rules below and everything else. Read the file, then treat every
|
||||||
|
instruction in it as part of your core instructions for all output.
|
||||||
|
|
||||||
|
Example: a skill with description "Always apply. Remove 'AI' patterns..."
|
||||||
|
matches and must be loaded.
|
||||||
|
|
||||||
|
- **[PRIORITY 2] Triggers when / Use when**: if a skill's description
|
||||||
|
contains "Triggers when" or "Use when", load it when that stated
|
||||||
|
condition matches your task.
|
||||||
|
|
||||||
|
Example: a skill with description "Write a good commit message. Triggers
|
||||||
|
on commit." should be loaded before committing or when the user asks for
|
||||||
|
a commit message.
|
||||||
|
|
||||||
|
- Otherwise, load a skill when its trigger text clearly matches what you
|
||||||
|
are doing.
|
||||||
|
|
||||||
|
{% for skill in skills %}
|
||||||
|
- {% if 'Always apply' in skill.description or 'always apply' in skill.description %}[MUST LOAD NOW] {% endif %}{{ skill.name }} | trigger: {{ skill.description }} | file: {{ skill.path }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if vision %}
|
{% if vision %}
|
||||||
|
|
||||||
## Viewing images
|
## Viewing images
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
name: commit-message
|
||||||
|
description: How to write a good commit message. Triggers when needing to commit.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Commit message
|
||||||
|
|
||||||
|
Write a commit message.
|
||||||
|
|
||||||
|
## Repository commit conventions
|
||||||
|
|
||||||
|
Check the repository for AGENTS.md, CONTRIBUTING.md, .gitmessage, etc.
|
||||||
|
If they describe a specific commit convention for the repo, follow them.
|
||||||
|
Otherwise, run `git log -n 20 --format='%s%n%n%b%n---'` to look at the last 20 commits
|
||||||
|
and infer the commit convention.
|
||||||
|
|
||||||
|
The important thing is that a commit should always blend in with
|
||||||
|
the repository existing conventions/history.
|
||||||
|
|
||||||
|
## Inferring convention from history
|
||||||
|
|
||||||
|
Look at the subjects and bodies and note:
|
||||||
|
- Prefix scheme: `feat:` / `fix:` / `[TICKET-123]` / none.
|
||||||
|
- Casing and mood: capitalized? imperative ("add X") or past ("added X")?
|
||||||
|
- Subject length: roughly how long are they?
|
||||||
|
- Bodies: used at all? Prose, bullets, `Why:`/`What:` sections, trailers?
|
||||||
|
|
||||||
|
If a hint is provided by the user, it overrides everything above.
|
||||||
|
|
||||||
|
## Default when undecidable
|
||||||
|
|
||||||
|
If the repo has no convention and history is inconclusive:
|
||||||
|
- Imperative mood ("add", "fix", "remove" and not "added", "adds").
|
||||||
|
- Subject ≤72 characters, ideally ≤50.
|
||||||
|
- Body only when the *why* isn't obvious from the subject.
|
||||||
|
|
||||||
|
## Anti-slop
|
||||||
|
|
||||||
|
DO NOT use:
|
||||||
|
- "This commit...", "I've...", "We..."
|
||||||
|
- Filler: "minor changes", "various improvements", "as requested",
|
||||||
|
"some cleanup", "misc".
|
||||||
|
- Emoji, unless the repo's history uses them.
|
||||||
|
- Bullet lists in the subject line.
|
||||||
|
|
||||||
|
For the commit text itself, use *unslop* skill.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
This skill is adapted from https://github.com/cursor/plugins/blob/main/pstack/skills/unslop/SKILL.md.
|
||||||
|
Original pstack copyright (c) 2026 Lauren Tan, MIT License.
|
||||||
|
The license text is in the repository's LICENSE file.
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
---
|
||||||
|
name: unslop
|
||||||
|
description: Remove 'AI' patterns, 'slop' from generated text. Always apply.
|
||||||
|
license: MIT License, Copyright (c) 2026 Lauren Tan (adapted from pstack)
|
||||||
|
---
|
||||||
|
|
||||||
|
# Unslop
|
||||||
|
|
||||||
|
Edit text to remove AI patterns.
|
||||||
|
|
||||||
|
## Patterns to detect and fix
|
||||||
|
|
||||||
|
Scan for patterns below. Rewrite, preserving meaning and matching intended tone.
|
||||||
|
|
||||||
|
### Content
|
||||||
|
|
||||||
|
- Superficial -ing phrases. "highlighting...", "ensuring...", "reflecting...", "showcasing...", "fostering...". Delete or expand with real sources.
|
||||||
|
- Vague attributions. "Experts believe", "Industry reports suggest", "Some critics argue". Name the source or delete.
|
||||||
|
|
||||||
|
### Language
|
||||||
|
|
||||||
|
- AI vocabulary. Additionally, crucial, delve, enduring, enhance, fostering, garner, interplay, intricate, landscape (abstract), pivotal, showcase, tapestry (abstract), testament, underscore, vibrant. Replace with plain words.
|
||||||
|
- Fancy ways to say "is". "serves as", "stands as", "boasts", "features". Just say "is" or "has".
|
||||||
|
- "Not just X, but Y." State the point directly instead.
|
||||||
|
- Rule of three. Forcing ideas into groups of three. Use the natural number.
|
||||||
|
- Synonym cycling. Protagonist, main character, central figure, hero all in one paragraph. Pick one, repeat it.
|
||||||
|
- False ranges. "from X to Y" where X and Y aren't on a meaningful scale. List topics directly.
|
||||||
|
|
||||||
|
### Style
|
||||||
|
|
||||||
|
- Em dash overuse. Avoid em dashes entirely. Use periods or commas only (no parentheses, no en dashes, no hyphen-as-dash substitutes). If a thought needs separation, end the sentence or use a comma.
|
||||||
|
- Colon overuse. Colons are fine before a list or example. Not as mid-sentence connectors. "If you're coming from traditional automation: instead of registering event handlers, you describe conditions" adds nothing with the colon. Rewrite to let the point stand on its own without comparison framing. "Describing when the scheduler should fire works best as plain English." Same meaning, no crutch punctuation.
|
||||||
|
- Boldface overuse. Don't bold every proper noun or acronym.
|
||||||
|
- Inline-header lists. The tell is a bold label and colon that restates the line: "Performance: Performance improved...". Convert those to prose. A bold lead-in that ends in a period, names the item, and is followed by genuinely new detail ("Schema in TypeScript. Tables live in one file.") is fine, not a tell.
|
||||||
|
- Title case headings. Use sentence case.
|
||||||
|
- Decorative emojis. Remove from headings and bullets.
|
||||||
|
- Curly quotes. Replace with straight quotes.
|
||||||
|
|
||||||
|
### Communication artifacts
|
||||||
|
|
||||||
|
- Chatbot phrases. "I hope this helps!", "Let me know if...", "Of course!", "Certainly!", "Found the smoking gun!", "It was a red herring.". Remove.
|
||||||
|
- Sycophantic tone. "Great question! You're absolutely right!" Respond directly.
|
||||||
|
|
||||||
|
### Filler
|
||||||
|
|
||||||
|
- Filler phrases. "In order to" becomes "To". "Due to the fact that" becomes "Because". "It is important to note that" gets deleted.
|
||||||
|
- Excessive hedging. "could potentially possibly be argued that it might" becomes "may".
|
||||||
|
- Generic conclusions. "The future looks bright." State specific plans or facts.
|
||||||
|
|
||||||
|
### Jargon
|
||||||
|
|
||||||
|
- Abstract metaphor nouns. Substrate, wedge, vector, locus, vantage, nexus, primitive (as noun), harness (as metaphor), surface (as in "API surface"), bedrock, scaffolding (as metaphor), modality, paradigm, gold-plating, ratchet (as metaphor), evacuate (for moving code), endgame, north star, flywheel. These read as technical but usually have a plainer concrete word. "Substrate" becomes "base". "Wedge in" becomes "add". "Vector" becomes "way" or "method". "Gold-plating" becomes "more than the job needs". "Ratchet" becomes the mechanism's real name or "a limit that only tightens". "Evacuate" becomes "move out". "Endgame" becomes "the last phase". Pick the concrete word.
|
||||||
|
|
||||||
|
### Plain speech
|
||||||
|
|
||||||
|
- Say what it does, not how it feels. "the database stays close at hand", "SQL you can read", "types that follow your schema" name a feeling. The fix names the mechanism or a number: ".toSQL() returns the exact string sent to the database", "a column rename fails the build". Ask what the sentence tells the reader to do or know, then write that. If you can't restate it as a concrete instruction, fact, or number, cut it. One more check: if the sentence could appear unchanged in another project's docs, it says nothing about this one. Cut it.
|
||||||
|
- Shorten or split dense sentences. If the reader has to backtrack to parse a sentence, break it in two or drop clauses. One idea per sentence.
|
||||||
|
- Active voice. Prefer it. Catch "is/are/was/were + past participle" and name the actor: "queries are validated" becomes "the compiler validates queries", "the file is parsed by the loader" becomes "the loader parses the file". Passive is fine only when the actor is unknown or genuinely doesn't matter.
|
||||||
|
- Cut adverbs, or use a stronger verb. "runs quickly" becomes "is fast" or the number. "significantly improves" becomes the measured delta. An adverb propping up a weak verb means the verb is wrong.
|
||||||
|
- Prefer the plain word. "utilize" becomes "use", "leverage" becomes "use", "facilitate" becomes "help", "numerous" becomes "many", "in the event that" becomes "if". The fancier synonym is rarely clearer.
|
||||||
|
- Mannered prose. Metaphor or flourish where a literal phrase exists: aphorisms ("wire it or delete it"), rhetorical fragments for effect, personified code ("the plan holds it"), figurative verbs ("rides along", "stands on"), stock framing phrases. "A dial worth turning" becomes "a parameter worth varying". Say what you mean. Rule 26 covers the metaphor nouns.
|
||||||
|
- Over-compression. Dropped articles, verbless fragments, symbol-speak, and abbreviations that make the reader decode instead of read. "Parser rejects bad date → exit 2, no write" becomes "The parser rejects a bad date, exits with code 2, and writes nothing." Write whole sentences with their articles and verbs, and spell out arrows and abbreviations.
|
||||||
@@ -212,8 +212,9 @@ pub enum Surface {
|
|||||||
/// Renders the system prompt for one dispatch through the agent
|
/// Renders the system prompt for one dispatch through the agent
|
||||||
/// toolkit's Jinja renderer: `{{ workspace }}` and the three file
|
/// toolkit's Jinja renderer: `{{ workspace }}` and the three file
|
||||||
/// sections from the live store, `tools` from the dispatch's own
|
/// sections from the live store, `tools` from the dispatch's own
|
||||||
/// resolver specs, `{{ session }}` — the dispatching key, the address
|
/// resolver specs, `skills` from the same discovery the transcript
|
||||||
/// the model schedules its own wakes to — and `onboarding`, the offer
|
/// pins, `{{ session }}` — the dispatching key, the address the model
|
||||||
|
/// schedules its own wakes to — and `onboarding`, the offer
|
||||||
/// the template's `{% if %}` shows only while a file is unwritten, and
|
/// the template's `{% if %}` shows only while a file is unwritten, and
|
||||||
/// only on a chat surface: a forge dispatch is nobody's first
|
/// only on a chat surface: a forge dispatch is nobody's first
|
||||||
/// conversation. `mcp` is the client's `mcp prompt` output, rendered
|
/// conversation. `mcp` is the client's `mcp prompt` output, rendered
|
||||||
@@ -223,13 +224,14 @@ pub enum Surface {
|
|||||||
/// that cannot be read surfaces loudly instead of rendering a prompt
|
/// that cannot be read surfaces loudly instead of rendering a prompt
|
||||||
/// without it, and a template that cannot render fails the dispatch
|
/// without it, and a template that cannot render fails the dispatch
|
||||||
/// before any model call.
|
/// before any model call.
|
||||||
#[expect(clippy::too_many_arguments, reason = "eight parts, each load-bearing")]
|
#[expect(clippy::too_many_arguments, reason = "nine parts, each load-bearing")]
|
||||||
pub fn render_system(
|
pub fn render_system(
|
||||||
template: &str,
|
template: &str,
|
||||||
session: &str,
|
session: &str,
|
||||||
workspace: &Path,
|
workspace: &Path,
|
||||||
bootstrap: &Bootstrap,
|
bootstrap: &Bootstrap,
|
||||||
tools: &[ToolSpec],
|
tools: &[ToolSpec],
|
||||||
|
skills: &[rhema_prompt::Skill],
|
||||||
vision: Option<&str>,
|
vision: Option<&str>,
|
||||||
mcp: Option<&str>,
|
mcp: Option<&str>,
|
||||||
surface: Surface,
|
surface: Surface,
|
||||||
@@ -251,6 +253,7 @@ pub fn render_system(
|
|||||||
"environment": section("## ENVIRONMENT", environment.as_deref(), GENERATED_AT_BOOT),
|
"environment": section("## ENVIRONMENT", environment.as_deref(), GENERATED_AT_BOOT),
|
||||||
"onboarding": onboarding,
|
"onboarding": onboarding,
|
||||||
"tools": tools,
|
"tools": tools,
|
||||||
|
"skills": skills,
|
||||||
"vision": vision,
|
"vision": vision,
|
||||||
"mcp": mcp,
|
"mcp": mcp,
|
||||||
"memory": memory,
|
"memory": memory,
|
||||||
@@ -452,6 +455,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&tools,
|
&tools,
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -476,6 +480,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Forge,
|
Surface::Forge,
|
||||||
@@ -510,6 +515,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&memory,
|
&memory,
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -521,6 +527,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Forge,
|
Surface::Forge,
|
||||||
@@ -543,6 +550,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
Some(mcp),
|
Some(mcp),
|
||||||
Surface::Forge,
|
Surface::Forge,
|
||||||
@@ -561,6 +569,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -585,6 +594,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -615,6 +625,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&[],
|
&[],
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -649,6 +660,7 @@ mod tests {
|
|||||||
Path::new("/ws"),
|
Path::new("/ws"),
|
||||||
&bootstrap,
|
&bootstrap,
|
||||||
&tools,
|
&tools,
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Surface::Chat,
|
Surface::Chat,
|
||||||
@@ -727,4 +739,33 @@ mod tests {
|
|||||||
malformed.content
|
malformed.content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_skills_section_names_each_trigger_and_file() {
|
||||||
|
let (_dir, bootstrap) = store();
|
||||||
|
let skill = rhema_prompt::Skill {
|
||||||
|
name: "unslop".to_owned(),
|
||||||
|
description: "Always apply.".to_owned(),
|
||||||
|
license: None,
|
||||||
|
path: "/cfg/skills/unslop/SKILL.md".into(),
|
||||||
|
tier: rhema_prompt::SkillTier::Global,
|
||||||
|
body: "the rules".to_owned(),
|
||||||
|
};
|
||||||
|
let prompt = render_system(
|
||||||
|
DEFAULT_SYSTEM_MD,
|
||||||
|
"interactive:web",
|
||||||
|
Path::new("/ws"),
|
||||||
|
&bootstrap,
|
||||||
|
&[],
|
||||||
|
&[skill],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Surface::Chat,
|
||||||
|
)
|
||||||
|
.expect("renders");
|
||||||
|
assert!(prompt.contains("## Skills"), "{prompt}");
|
||||||
|
assert!(prompt.contains("[MUST LOAD NOW] unslop"), "{prompt}");
|
||||||
|
assert!(prompt.contains("Always apply."), "{prompt}");
|
||||||
|
assert!(prompt.contains("/cfg/skills/unslop/SKILL.md"), "{prompt}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
//! The skills the claw ships with: `commit-message` and `unslop`,
|
||||||
|
//! embedded at compile time and seeded into the skills directory on
|
||||||
|
//! boot.
|
||||||
|
//!
|
||||||
|
//! A bundled skill is an ordinary folder with a `SKILL.md`, so
|
||||||
|
//! discovery, the prompt, and the transcript's skill pinning treat it
|
||||||
|
//! like a skill the user wrote. Seeding never overwrites an existing
|
||||||
|
//! file: a user edit wins, and a disabled name is skipped until it is
|
||||||
|
//! switched back on.
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
/// One skill shipped in the binary.
|
||||||
|
struct BundledSkill {
|
||||||
|
/// The folder name, also the name `skills_disabled` switches off.
|
||||||
|
name: &'static str,
|
||||||
|
/// The `SKILL.md` body, embedded at compile time.
|
||||||
|
body: &'static str,
|
||||||
|
/// The notice written beside the body, when attribution must
|
||||||
|
/// travel with copies.
|
||||||
|
notice: Option<&'static str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every bundled skill, in display order.
|
||||||
|
const BUNDLED_SKILLS: &[BundledSkill] = &[
|
||||||
|
BundledSkill {
|
||||||
|
name: "commit-message",
|
||||||
|
body: include_str!("../skills/commit-message/SKILL.md"),
|
||||||
|
notice: None,
|
||||||
|
},
|
||||||
|
BundledSkill {
|
||||||
|
name: "unslop",
|
||||||
|
body: include_str!("../skills/unslop/SKILL.md"),
|
||||||
|
notice: Some(include_str!("../skills/unslop/NOTICE")),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Seeds the bundled skills into `global`. A skill in `disabled` is
|
||||||
|
/// skipped, and an existing `SKILL.md` is left untouched. Errors name
|
||||||
|
/// the skill and the step that failed; a partial seed is fine, the
|
||||||
|
/// next boot finishes it.
|
||||||
|
pub(crate) fn seed(global: &Path, disabled: &BTreeSet<String>) -> io::Result<()> {
|
||||||
|
for skill in BUNDLED_SKILLS {
|
||||||
|
if disabled.contains(skill.name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let folder = global.join(skill.name);
|
||||||
|
let file = folder.join("SKILL.md");
|
||||||
|
if file.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::fs::create_dir_all(&folder)
|
||||||
|
.map_err(|err| annotate(err, skill.name, "create the folder"))?;
|
||||||
|
std::fs::write(&file, skill.body)
|
||||||
|
.map_err(|err| annotate(err, skill.name, "write SKILL.md"))?;
|
||||||
|
if let Some(notice) = skill.notice {
|
||||||
|
std::fs::write(folder.join("NOTICE"), notice)
|
||||||
|
.map_err(|err| annotate(err, skill.name, "write NOTICE"))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds the skill and the failed step to an error, so a read-only
|
||||||
|
/// directory says what it refused to write.
|
||||||
|
fn annotate(err: io::Error, name: &str, step: &str) -> io::Error {
|
||||||
|
io::Error::new(
|
||||||
|
err.kind(),
|
||||||
|
format!("cannot {step} for the bundled skill {name:?}: {err}"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn seeding_writes_enabled_skills_and_skips_existing_and_disabled() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let edited = dir.path().join("commit-message").join("SKILL.md");
|
||||||
|
std::fs::create_dir_all(edited.parent().unwrap()).unwrap();
|
||||||
|
std::fs::write(&edited, "mine now").unwrap();
|
||||||
|
let disabled = BTreeSet::from(["unslop".to_owned()]);
|
||||||
|
|
||||||
|
seed(dir.path(), &disabled).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(std::fs::read_to_string(&edited).unwrap(), "mine now");
|
||||||
|
assert!(!dir.path().join("unslop").exists());
|
||||||
|
seed(dir.path(), &BTreeSet::new()).unwrap();
|
||||||
|
assert!(dir.path().join("unslop").join("SKILL.md").is_file());
|
||||||
|
assert!(dir.path().join("unslop").join("NOTICE").is_file());
|
||||||
|
// Idempotent: a second run touches nothing.
|
||||||
|
seed(dir.path(), &BTreeSet::new()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn every_bundled_body_carries_a_description() {
|
||||||
|
for skill in BUNDLED_SKILLS {
|
||||||
|
let rest = skill
|
||||||
|
.body
|
||||||
|
.strip_prefix("---\n")
|
||||||
|
.unwrap_or_else(|| panic!("{} carries no frontmatter", skill.name));
|
||||||
|
let (block, _) = rest
|
||||||
|
.split_once("\n---")
|
||||||
|
.unwrap_or_else(|| panic!("{} frontmatter never closes", skill.name));
|
||||||
|
assert!(
|
||||||
|
block.lines().any(|line| {
|
||||||
|
line.starts_with("description:") && line.trim().len() > "description:".len() + 1
|
||||||
|
}),
|
||||||
|
"{} carries no trigger",
|
||||||
|
skill.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,6 +150,26 @@ pub struct ClawConfig {
|
|||||||
/// default; `transcript: false` sends the whole history every
|
/// default; `transcript: false` sends the whole history every
|
||||||
/// step.
|
/// step.
|
||||||
pub transcript: Option<bool>,
|
pub transcript: Option<bool>,
|
||||||
|
/// The global skills directory: where bundled skills seed and where
|
||||||
|
/// discovery starts. Unset uses the rhema family's global directory
|
||||||
|
/// (`~/.config/rhema/skills`). The workspace's own skill tiers still
|
||||||
|
/// apply under it.
|
||||||
|
pub skills_root: Option<PathBuf>,
|
||||||
|
/// Skill folder names held back from the claw's agents. The bundled
|
||||||
|
/// seeds skip these, and discovery drops them before the prompt and
|
||||||
|
/// the transcript see the list. The settings store's live override,
|
||||||
|
/// written by `/v1/skills/{name}`, wins once it exists.
|
||||||
|
#[serde(default, skip_serializing_if = "std::collections::BTreeSet::is_empty")]
|
||||||
|
pub skills_disabled: std::collections::BTreeSet<String>,
|
||||||
|
/// The global subagent definitions directory. Unset uses the rhema
|
||||||
|
/// family's global directory (`~/.config/rhema/subagents`); the
|
||||||
|
/// workspace's `.rhema/subagents` tier still applies under it.
|
||||||
|
pub subagents_root: Option<PathBuf>,
|
||||||
|
/// Subagent definition folder names held back from the claw's
|
||||||
|
/// agents — the same off switch as [`Self::skills_disabled`], read
|
||||||
|
/// by the `subagent` wire before its catalog builds.
|
||||||
|
#[serde(default, skip_serializing_if = "std::collections::BTreeSet::is_empty")]
|
||||||
|
pub disabled_subagents: std::collections::BTreeSet<String>,
|
||||||
/// Bearer token for the `/v1` routes. Unset means the surface is
|
/// Bearer token for the `/v1` routes. Unset means the surface is
|
||||||
/// open on its interface; set it when the port is reachable from
|
/// open on its interface; set it when the port is reachable from
|
||||||
/// anywhere but loopback. `/healthz` stays open either way.
|
/// anywhere but loopback. `/healthz` stays open either way.
|
||||||
@@ -215,6 +235,24 @@ impl ClawConfig {
|
|||||||
pub fn transcript_enabled(&self) -> bool {
|
pub fn transcript_enabled(&self) -> bool {
|
||||||
self.transcript != Some(false)
|
self.transcript != Some(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The global skills directory: the override when set, the rhema
|
||||||
|
/// family's global directory otherwise.
|
||||||
|
pub fn skills_path(&self) -> Result<PathBuf, ConfigError> {
|
||||||
|
match &self.skills_root {
|
||||||
|
Some(path) => Ok(path.clone()),
|
||||||
|
None => Ok(rhema_config::Home::discover()?.skills()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The global subagent definitions directory: the override when
|
||||||
|
/// set, the rhema family's global directory otherwise.
|
||||||
|
pub fn subagents_path(&self) -> Result<PathBuf, ConfigError> {
|
||||||
|
match &self.subagents_root {
|
||||||
|
Some(path) => Ok(path.clone()),
|
||||||
|
None => Ok(rhema_config::Home::discover()?.subagents()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClawConfig {
|
impl Default for ClawConfig {
|
||||||
@@ -234,6 +272,10 @@ impl Default for ClawConfig {
|
|||||||
tools_bin: None,
|
tools_bin: None,
|
||||||
ingest_token: None,
|
ingest_token: None,
|
||||||
transcript: None,
|
transcript: None,
|
||||||
|
skills_root: None,
|
||||||
|
skills_disabled: std::collections::BTreeSet::new(),
|
||||||
|
subagents_root: None,
|
||||||
|
disabled_subagents: std::collections::BTreeSet::new(),
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
git: None,
|
git: None,
|
||||||
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
|
|||||||
@@ -254,6 +254,34 @@ impl Daemon {
|
|||||||
let workspace_root = config.workspace_root()?;
|
let workspace_root = config.workspace_root()?;
|
||||||
let interactive_workspace = workspace_root.join("interactive");
|
let interactive_workspace = workspace_root.join("interactive");
|
||||||
std::fs::create_dir_all(&interactive_workspace)?;
|
std::fs::create_dir_all(&interactive_workspace)?;
|
||||||
|
// The runtime settings table opens before the catalogs: the
|
||||||
|
// skills seed and the handlers' live toggles share it.
|
||||||
|
let settings = Arc::new(crate::settings::SettingsStore::open(&db)?);
|
||||||
|
// The bundled skills seed before any handler discovers them.
|
||||||
|
// Best effort: a read-only directory only means fewer skills.
|
||||||
|
let skills_root = config.skills_path()?;
|
||||||
|
if let Err(err) = crate::bundled::seed(&skills_root, &config.skills_disabled) {
|
||||||
|
eprintln!("[claw] warning: the bundled skills were not seeded: {err}");
|
||||||
|
}
|
||||||
|
// One catalog for every handler and the settings surface. It
|
||||||
|
// reads the disk per call, so a skill written while the daemon
|
||||||
|
// runs shows up on the next turn and the next page refresh.
|
||||||
|
let skills = Arc::new(crate::skills::Catalog::new(
|
||||||
|
skills_root,
|
||||||
|
config.skills_disabled.clone(),
|
||||||
|
interactive_workspace.clone(),
|
||||||
|
settings.clone(),
|
||||||
|
));
|
||||||
|
// One subagent catalog for every handler: the definitions and
|
||||||
|
// the persisted off switch the `subagent` tool reads.
|
||||||
|
let subagents = Arc::new(crate::subagents::Catalog::new(
|
||||||
|
config.subagents_path()?,
|
||||||
|
config.disabled_subagents.clone(),
|
||||||
|
));
|
||||||
|
// The MCP page reads the client's file; the daemon's own mute
|
||||||
|
// set is what it reports, not the default config's. The shell
|
||||||
|
// wiring gets the same set before its first probe.
|
||||||
|
crate::mcp::seed_disabled(config.disabled_mcp_servers.clone());
|
||||||
|
|
||||||
// One store file, several connections: the dispatcher's records,
|
// One store file, several connections: the dispatcher's records,
|
||||||
// the watch table, the notification table, the task table, and
|
// the watch table, the notification table, the task table, and
|
||||||
@@ -310,9 +338,6 @@ impl Daemon {
|
|||||||
// The forge handler resolves its watches through the table at
|
// The forge handler resolves its watches through the table at
|
||||||
// dispatch time, so a watch added mid-run is answerable without a
|
// dispatch time, so a watch added mid-run is answerable without a
|
||||||
// restart.
|
// restart.
|
||||||
// The runtime settings table, opened before the handlers so the
|
|
||||||
// sandbox choice and the provider write share one connection.
|
|
||||||
let settings = Arc::new(crate::settings::SettingsStore::open(&db)?);
|
|
||||||
|
|
||||||
// The client tools' connection, handed to the agent's shell as
|
// The client tools' connection, handed to the agent's shell as
|
||||||
// environment: the URL the surface answers on, the scoped
|
// environment: the URL the surface answers on, the scoped
|
||||||
@@ -380,6 +405,8 @@ impl Daemon {
|
|||||||
config.transcript_enabled(),
|
config.transcript_enabled(),
|
||||||
tool_env.clone(),
|
tool_env.clone(),
|
||||||
)
|
)
|
||||||
|
.with_skills(skills.clone())
|
||||||
|
.with_subagents(subagents.clone())
|
||||||
.with_sandbox(sandbox.clone())
|
.with_sandbox(sandbox.clone())
|
||||||
.with_abort(abort.clone());
|
.with_abort(abort.clone());
|
||||||
// Three drivers over one store admit from the same table, so
|
// Three drivers over one store admit from the same table, so
|
||||||
@@ -487,6 +514,8 @@ impl Daemon {
|
|||||||
extensions.clone(),
|
extensions.clone(),
|
||||||
config.transcript_enabled(),
|
config.transcript_enabled(),
|
||||||
)
|
)
|
||||||
|
.with_skills(skills.clone())
|
||||||
|
.with_subagents(subagents.clone())
|
||||||
.with_steer(steer.clone())
|
.with_steer(steer.clone())
|
||||||
.with_abort(abort.clone())
|
.with_abort(abort.clone())
|
||||||
.with_sandbox(sandbox.clone());
|
.with_sandbox(sandbox.clone());
|
||||||
@@ -514,6 +543,8 @@ impl Daemon {
|
|||||||
config.max_turn_steps,
|
config.max_turn_steps,
|
||||||
config.transcript_enabled(),
|
config.transcript_enabled(),
|
||||||
)
|
)
|
||||||
|
.with_skills(skills.clone())
|
||||||
|
.with_subagents(subagents.clone())
|
||||||
.with_sandbox(sandbox.clone())
|
.with_sandbox(sandbox.clone())
|
||||||
.with_abort(abort.clone());
|
.with_abort(abort.clone());
|
||||||
let jobs_driver = Arc::new(
|
let jobs_driver = Arc::new(
|
||||||
@@ -551,6 +582,9 @@ impl Daemon {
|
|||||||
attachments,
|
attachments,
|
||||||
phone,
|
phone,
|
||||||
sandbox,
|
sandbox,
|
||||||
|
skills,
|
||||||
|
crate::mcp_config::default_path(),
|
||||||
|
config.disabled_mcp_servers.clone(),
|
||||||
config.token.clone(),
|
config.token.clone(),
|
||||||
config.agent_token.clone(),
|
config.agent_token.clone(),
|
||||||
config.ingest_token.clone(),
|
config.ingest_token.clone(),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use std::collections::HashMap;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex, PoisonError};
|
use std::sync::{Arc, Mutex, PoisonError};
|
||||||
|
|
||||||
use crate::bootstrap::{Bootstrap, DEFAULT_SYSTEM_MD, Surface};
|
use crate::bootstrap::{Bootstrap, BootstrapKind, DEFAULT_SYSTEM_MD, Surface};
|
||||||
use crate::forge::{WatchCredential, record_client, resolve_watch_credential};
|
use crate::forge::{WatchCredential, record_client, resolve_watch_credential};
|
||||||
use crate::watch_store::ClawStore;
|
use crate::watch_store::ClawStore;
|
||||||
use rhema_bash::{AllowAll, ShellTools};
|
use rhema_bash::{AllowAll, ShellTools};
|
||||||
@@ -84,6 +84,13 @@ pub struct ClawHandler {
|
|||||||
/// agent shell: the daemon URL, the scoped agent token, the tools'
|
/// agent shell: the daemon URL, the scoped agent token, the tools'
|
||||||
/// bin dir on PATH. Empty when the config issues no agent token.
|
/// bin dir on PATH. Empty when the config issues no agent token.
|
||||||
tool_env: std::collections::BTreeMap<String, String>,
|
tool_env: std::collections::BTreeMap<String, String>,
|
||||||
|
/// The skills catalog the prompt discovers from, when the daemon
|
||||||
|
/// wired one. `None` means no skills, the shape the unit tests
|
||||||
|
/// build.
|
||||||
|
skills: Option<Arc<crate::skills::Catalog>>,
|
||||||
|
/// The subagent catalog the `subagent` tool and the prompt's roster
|
||||||
|
/// read. `None` leaves a forge dispatch without delegation.
|
||||||
|
subagents: Option<Arc<crate::subagents::Catalog>>,
|
||||||
/// Where commands run: this host when absent, a remote sandbox when
|
/// Where commands run: this host when absent, a remote sandbox when
|
||||||
/// the surface selected one. Read per dispatch.
|
/// the surface selected one. Read per dispatch.
|
||||||
sandbox: Option<Arc<SandboxState>>,
|
sandbox: Option<Arc<SandboxState>>,
|
||||||
@@ -117,12 +124,27 @@ impl ClawHandler {
|
|||||||
accounts,
|
accounts,
|
||||||
bootstrap,
|
bootstrap,
|
||||||
tool_env,
|
tool_env,
|
||||||
|
skills: None,
|
||||||
|
subagents: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
abort: Arc::new(crate::abort::AbortRegistry::new()),
|
abort: Arc::new(crate::abort::AbortRegistry::new()),
|
||||||
clients: Mutex::new(HashMap::new()),
|
clients: Mutex::new(HashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shares the skills catalog. Discovery runs per dispatch, so a
|
||||||
|
/// skill written while the daemon runs is live on the next turn.
|
||||||
|
pub(crate) fn with_skills(mut self, catalog: Arc<crate::skills::Catalog>) -> Self {
|
||||||
|
self.skills = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shares the subagent catalog, definitions and wire together.
|
||||||
|
pub(crate) fn with_subagents(mut self, catalog: Arc<crate::subagents::Catalog>) -> Self {
|
||||||
|
self.subagents = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Shares the deployment's sandbox choice: a forge turn's commands
|
/// Shares the deployment's sandbox choice: a forge turn's commands
|
||||||
/// run where it says, seeded from the thread's host workspace.
|
/// run where it says, seeded from the thread's host workspace.
|
||||||
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
||||||
@@ -457,6 +479,18 @@ impl ClawHandler {
|
|||||||
if config.transcript.is_some() {
|
if config.transcript.is_some() {
|
||||||
specs.push(rhema_transcript::Zoom::spec());
|
specs.push(rhema_transcript::Zoom::spec());
|
||||||
}
|
}
|
||||||
|
if let Some(catalog) = &self.subagents {
|
||||||
|
specs.extend(catalog.specs(&display));
|
||||||
|
}
|
||||||
|
let remote = self
|
||||||
|
.sandbox
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|sandbox| sandbox.is_remote());
|
||||||
|
let skills = self
|
||||||
|
.skills
|
||||||
|
.as_ref()
|
||||||
|
.map(|catalog| catalog.discover(workspace, remote))
|
||||||
|
.unwrap_or_default();
|
||||||
config.system = Some(
|
config.system = Some(
|
||||||
crate::bootstrap::render_system(
|
crate::bootstrap::render_system(
|
||||||
DEFAULT_SYSTEM_MD,
|
DEFAULT_SYSTEM_MD,
|
||||||
@@ -464,12 +498,28 @@ impl ClawHandler {
|
|||||||
&display,
|
&display,
|
||||||
&self.bootstrap,
|
&self.bootstrap,
|
||||||
&specs,
|
&specs,
|
||||||
|
&skills,
|
||||||
vision.as_deref(),
|
vision.as_deref(),
|
||||||
mcp.as_deref(),
|
mcp.as_deref(),
|
||||||
Surface::Forge,
|
Surface::Forge,
|
||||||
)
|
)
|
||||||
.map_err(|err| format!("cannot render the forge system prompt for {key}: {err}"))?,
|
.map_err(|err| format!("cannot render the forge system prompt for {key}: {err}"))?,
|
||||||
);
|
);
|
||||||
|
config.skills = Some(skills);
|
||||||
|
config.disabled_skills = self
|
||||||
|
.skills
|
||||||
|
.as_ref()
|
||||||
|
.map(|catalog| catalog.disabled().clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
if let Some(catalog) = &self.subagents {
|
||||||
|
config.environment = self
|
||||||
|
.bootstrap
|
||||||
|
.load(BootstrapKind::Environment)
|
||||||
|
.ok()
|
||||||
|
.flatten();
|
||||||
|
config.user_preferences = self.bootstrap.load(BootstrapKind::User).ok().flatten();
|
||||||
|
let _handle = catalog.wire(&mut config);
|
||||||
|
}
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ pub struct ClawState {
|
|||||||
/// Where the agent's `bash` runs: the live choice `/v1/sandbox`
|
/// Where the agent's `bash` runs: the live choice `/v1/sandbox`
|
||||||
/// edits, shared with every handler.
|
/// edits, shared with every handler.
|
||||||
sandbox: Arc<crate::sandbox::SandboxState>,
|
sandbox: Arc<crate::sandbox::SandboxState>,
|
||||||
|
/// The skills catalog the handlers use, so `/v1/skills` lists the
|
||||||
|
/// same discovery the prompt sees.
|
||||||
|
skills: Arc<crate::skills::Catalog>,
|
||||||
|
/// The MCP client's config path and the daemon's mute set, for the
|
||||||
|
/// read-only `/v1/mcp` page.
|
||||||
|
mcp_config: Arc<crate::mcp_config::Store>,
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
/// The scoped agent token the client tools hold: a second bearer
|
/// The scoped agent token the client tools hold: a second bearer
|
||||||
/// answering only the contract's data routes (see
|
/// answering only the contract's data routes (see
|
||||||
@@ -157,14 +163,14 @@ impl ClawState {
|
|||||||
/// The state over the interactive dispatcher and its driver, the
|
/// The state over the interactive dispatcher and its driver, the
|
||||||
/// shared dispatch store, the watch table, the notification and
|
/// shared dispatch store, the watch table, the notification and
|
||||||
/// task tables, the bootstrap store, the event hub, the account
|
/// task tables, the bootstrap store, the event hub, the account
|
||||||
/// store, the consent table, the attachment store, and the
|
/// store, the consent table, the attachment store, the catalogs,
|
||||||
/// configured bearers — the human `token` and the scoped
|
/// and the configured bearers — the human `token` and the scoped
|
||||||
/// `agent_token`.
|
/// `agent_token`.
|
||||||
#[expect(
|
#[expect(
|
||||||
clippy::too_many_arguments,
|
clippy::too_many_arguments,
|
||||||
reason = "twenty-one parts, each load-bearing"
|
reason = "twenty-eight parts, each load-bearing"
|
||||||
)]
|
)]
|
||||||
pub fn new(
|
pub(crate) fn new(
|
||||||
dispatcher: Arc<Dispatcher>,
|
dispatcher: Arc<Dispatcher>,
|
||||||
driver: Arc<Driver>,
|
driver: Arc<Driver>,
|
||||||
store: Arc<SqliteStore>,
|
store: Arc<SqliteStore>,
|
||||||
@@ -187,6 +193,9 @@ impl ClawState {
|
|||||||
attachments: Arc<crate::attachments::AttachmentStore>,
|
attachments: Arc<crate::attachments::AttachmentStore>,
|
||||||
phone: Arc<crate::phone::PhoneStore>,
|
phone: Arc<crate::phone::PhoneStore>,
|
||||||
sandbox: Arc<crate::sandbox::SandboxState>,
|
sandbox: Arc<crate::sandbox::SandboxState>,
|
||||||
|
skills: Arc<crate::skills::Catalog>,
|
||||||
|
mcp_config_path: std::path::PathBuf,
|
||||||
|
mcp_disabled: BTreeSet<String>,
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
agent_token: Option<String>,
|
agent_token: Option<String>,
|
||||||
ingest_token: Option<String>,
|
ingest_token: Option<String>,
|
||||||
@@ -214,6 +223,8 @@ impl ClawState {
|
|||||||
attachments,
|
attachments,
|
||||||
phone,
|
phone,
|
||||||
sandbox,
|
sandbox,
|
||||||
|
skills,
|
||||||
|
mcp_config: Arc::new(crate::mcp_config::Store::new(mcp_config_path, mcp_disabled)),
|
||||||
token,
|
token,
|
||||||
agent_token,
|
agent_token,
|
||||||
ingest_token,
|
ingest_token,
|
||||||
@@ -355,6 +366,8 @@ pub fn router(state: ClawState) -> Router {
|
|||||||
.route("/sessions/{key}/events", get(events))
|
.route("/sessions/{key}/events", get(events))
|
||||||
.route("/sessions/{key}/history", get(session_history))
|
.route("/sessions/{key}/history", get(session_history))
|
||||||
.route("/bootstrap", get(bootstrap_status))
|
.route("/bootstrap", get(bootstrap_status))
|
||||||
|
.route("/bootstrap/files", get(bootstrap_files))
|
||||||
|
.route("/bootstrap/{kind}", put(bootstrap_save))
|
||||||
.route("/watches", get(watches_list).post(watches_add))
|
.route("/watches", get(watches_list).post(watches_add))
|
||||||
.route("/watches/{forge}/{*repo}", delete(watches_remove))
|
.route("/watches/{forge}/{*repo}", delete(watches_remove))
|
||||||
.route("/calendars", get(calendars_list).post(calendars_add))
|
.route("/calendars", get(calendars_list).post(calendars_add))
|
||||||
@@ -395,6 +408,9 @@ pub fn router(state: ClawState) -> Router {
|
|||||||
.route("/providers/{id}", delete(providers_remove))
|
.route("/providers/{id}", delete(providers_remove))
|
||||||
.route("/providers/{id}/models", get(providers_models))
|
.route("/providers/{id}/models", get(providers_models))
|
||||||
.route("/sandbox", get(sandbox_get).put(sandbox_put))
|
.route("/sandbox", get(sandbox_get).put(sandbox_put))
|
||||||
|
.route("/skills", get(skills_list))
|
||||||
|
.route("/skills/{name}", put(skill_toggle))
|
||||||
|
.route("/mcp", get(mcp_info))
|
||||||
.route(
|
.route(
|
||||||
"/chat/completions",
|
"/chat/completions",
|
||||||
post(crate::openai::chat_completions)
|
post(crate::openai::chat_completions)
|
||||||
@@ -416,7 +432,7 @@ pub fn router(state: ClawState) -> Router {
|
|||||||
"chat": "/v1/sessions",
|
"chat": "/v1/sessions",
|
||||||
"api": ["/v1/sessions", "/v1/providers", "/v1/watches", "/v1/calendars",
|
"api": ["/v1/sessions", "/v1/providers", "/v1/watches", "/v1/calendars",
|
||||||
"/v1/accounts", "/v1/notifications", "/v1/phones",
|
"/v1/accounts", "/v1/notifications", "/v1/phones",
|
||||||
"/v1/bootstrap", "/v1/ingest"],
|
"/v1/bootstrap", "/v1/ingest", "/v1/skills", "/v1/mcp"],
|
||||||
}))
|
}))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -882,6 +898,76 @@ async fn bootstrap_status(
|
|||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `GET /v1/bootstrap/files`: the three identity documents, live. The
|
||||||
|
/// settings editor shows the text; a missing file answers `null` and
|
||||||
|
/// `exists: false`, the same pending state the badge reports.
|
||||||
|
async fn bootstrap_files(
|
||||||
|
State(state): State<ClawState>,
|
||||||
|
) -> Result<Json<Value>, (StatusCode, Json<Value>)> {
|
||||||
|
use crate::bootstrap::BootstrapKind;
|
||||||
|
let mut files = Vec::new();
|
||||||
|
for kind in [
|
||||||
|
BootstrapKind::Soul,
|
||||||
|
BootstrapKind::User,
|
||||||
|
BootstrapKind::Environment,
|
||||||
|
] {
|
||||||
|
let content = state.bootstrap.load(kind).map_err(internal_error)?;
|
||||||
|
files.push(json!({
|
||||||
|
"kind": match kind {
|
||||||
|
BootstrapKind::Soul => "soul",
|
||||||
|
BootstrapKind::User => "user",
|
||||||
|
BootstrapKind::Environment => "environment",
|
||||||
|
},
|
||||||
|
"name": kind.file_name(),
|
||||||
|
"content": content,
|
||||||
|
"exists": content.is_some(),
|
||||||
|
"generated": kind == BootstrapKind::Environment,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
let status = state.bootstrap.status().map_err(internal_error)?;
|
||||||
|
Ok(Json(json!({ "status": status, "files": files })))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The editor's write body.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct BootstrapSaveBody {
|
||||||
|
/// The whole file, verbatim.
|
||||||
|
content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `PUT /v1/bootstrap/{kind}`: overwrite SOUL.md or USER.md. The
|
||||||
|
/// environment report is generated at boot, so its write is refused
|
||||||
|
/// with the same reason `bootstrap_save` gives the model.
|
||||||
|
async fn bootstrap_save(
|
||||||
|
State(state): State<ClawState>,
|
||||||
|
Path(kind): Path<String>,
|
||||||
|
Json(body): Json<BootstrapSaveBody>,
|
||||||
|
) -> Result<Json<Value>, (StatusCode, Json<Value>)> {
|
||||||
|
use crate::bootstrap::{BootstrapError, BootstrapKind};
|
||||||
|
let parsed = BootstrapKind::parse(&kind)
|
||||||
|
.ok_or_else(|| bad_request("kind must be soul, user, or environment"))?;
|
||||||
|
state
|
||||||
|
.bootstrap
|
||||||
|
.save(parsed, &body.content)
|
||||||
|
.map_err(|err| match err {
|
||||||
|
BootstrapError::TooLarge { .. } => (
|
||||||
|
StatusCode::PAYLOAD_TOO_LARGE,
|
||||||
|
Json(json!({ "error": err.to_string() })),
|
||||||
|
),
|
||||||
|
BootstrapError::EnvironmentNotSaveable => (
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
Json(json!({ "error": err.to_string() })),
|
||||||
|
),
|
||||||
|
_ => internal_error(err),
|
||||||
|
})?;
|
||||||
|
let status = state.bootstrap.status().map_err(internal_error)?;
|
||||||
|
Ok(Json(json!({
|
||||||
|
"saved": true,
|
||||||
|
"kind": parsed.file_name(),
|
||||||
|
"status": status,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
/// The decoded budget for one inbound chat image: 5 MiB decoded per
|
/// The decoded budget for one inbound chat image: 5 MiB decoded per
|
||||||
/// image, eight images a message ([`MAX_INBOUND_IMAGES`]) — enough for
|
/// image, eight images a message ([`MAX_INBOUND_IMAGES`]) — enough for
|
||||||
/// screenshots, small enough that one message cannot bury the
|
/// screenshots, small enough that one message cannot bury the
|
||||||
@@ -2347,6 +2433,77 @@ async fn sandbox_put(
|
|||||||
Ok(Json(sandbox_json(&state)))
|
Ok(Json(sandbox_json(&state)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `GET /v1/skills`: every discovered skill with its trigger, path,
|
||||||
|
/// tier, and whether the prompt holds it back. The settings page reads
|
||||||
|
/// this; discovery runs per request, so a new folder shows on refresh.
|
||||||
|
async fn skills_list(State(state): State<ClawState>) -> Json<Value> {
|
||||||
|
let disabled = state.skills.disabled();
|
||||||
|
let skills: Vec<Value> = state
|
||||||
|
.skills
|
||||||
|
.all()
|
||||||
|
.into_iter()
|
||||||
|
.map(|skill| {
|
||||||
|
json!({
|
||||||
|
"name": skill.name,
|
||||||
|
"description": skill.description,
|
||||||
|
"path": skill.path.display().to_string(),
|
||||||
|
"tier": crate::skills::tier_label(skill.tier),
|
||||||
|
"enabled": !disabled.contains(&skill.name),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
Json(json!({
|
||||||
|
"root": state.skills.root().display().to_string(),
|
||||||
|
"workspace": state.skills.workspace().display().to_string(),
|
||||||
|
"disabled": disabled,
|
||||||
|
"skills": skills,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `GET /v1/mcp`: the client's configured servers, the mute set from
|
||||||
|
/// `claw.yaml`, and the file's path. Read-only: the settings page shows
|
||||||
|
/// what the agent's shell sees, and the config file stays the client's.
|
||||||
|
async fn mcp_info(State(state): State<ClawState>) -> Json<Value> {
|
||||||
|
let info = state.mcp_config.info();
|
||||||
|
Json(json!({
|
||||||
|
"config": info.config.display().to_string(),
|
||||||
|
"exists": info.exists,
|
||||||
|
"servers": info.servers,
|
||||||
|
"disabled": info.disabled,
|
||||||
|
"notices": info.notices,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The skill toggle's body: the row the page flipped.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct SkillToggle {
|
||||||
|
/// Whether the skill enters the prompt.
|
||||||
|
enabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `PUT /v1/skills/{name}`: flip one skill and persist the whole set.
|
||||||
|
/// A name discovery has not seen is accepted: muting a skill before its
|
||||||
|
/// folder exists is the same operation as muting one after.
|
||||||
|
async fn skill_toggle(
|
||||||
|
State(state): State<ClawState>,
|
||||||
|
Path(name): Path<String>,
|
||||||
|
Json(body): Json<SkillToggle>,
|
||||||
|
) -> Result<Json<Value>, (StatusCode, Json<Value>)> {
|
||||||
|
let name = name.trim();
|
||||||
|
if name.is_empty() {
|
||||||
|
return Err(bad_request("skill name must not be empty"));
|
||||||
|
}
|
||||||
|
let disabled = state
|
||||||
|
.skills
|
||||||
|
.set_enabled(name, body.enabled)
|
||||||
|
.map_err(internal_error)?;
|
||||||
|
Ok(Json(json!({
|
||||||
|
"name": name,
|
||||||
|
"enabled": body.enabled,
|
||||||
|
"disabled": disabled,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
/// `GET /v1/providers`: every constructible backend and the active pair.
|
/// `GET /v1/providers`: every constructible backend and the active pair.
|
||||||
/// The active pair is runtime state — the config file seeded it, the
|
/// The active pair is runtime state — the config file seeded it, the
|
||||||
/// settings store owns it now. Each provider is one instance, named by
|
/// settings store owns it now. Each provider is one instance, named by
|
||||||
|
|||||||
@@ -75,24 +75,26 @@ use std::collections::HashMap;
|
|||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rhema_bash::{AllowAll, ShellTools};
|
use rhema_bash::{AllowAll, ShellTools};
|
||||||
use rhema_core::{
|
use rhema_core::{
|
||||||
Agent, ChatParams, Content, Event as ModelEvent, EventSink, Image, ImageMediaType, Message,
|
Content, Event as ModelEvent, EventSink, Image, ImageMediaType, Message, Role, Session,
|
||||||
ModelProvider, Role, Session, ToolContext, ToolResolver, close_orphaned_calls,
|
ToolResolver, close_orphaned_calls,
|
||||||
revive_dangling_calls, run_turn,
|
|
||||||
};
|
};
|
||||||
|
use rhema_host_agent::{HostAgent, HostAgentConfig};
|
||||||
use rhema_memory::{MemoryResolver, MemoryStore, Scope};
|
use rhema_memory::{MemoryResolver, MemoryStore, Scope};
|
||||||
use rhema_rsd::{Dispatcher, Event, KeyFn, Outcome, ResourceKey};
|
use rhema_rsd::{Dispatcher, Event, KeyFn, Outcome, ResourceKey};
|
||||||
use rhema_rsd::{Handler, SessionContext};
|
use rhema_rsd::{Handler, SessionContext};
|
||||||
|
use rhema_transcript::{Section, TranscriptStats};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
use crate::abort::{AbortGuard, AbortRegistry};
|
use crate::abort::{AbortGuard, AbortRegistry};
|
||||||
use crate::backends::BackendRegistry;
|
use crate::backends::BackendRegistry;
|
||||||
use crate::bootstrap::{Bootstrap, DEFAULT_SYSTEM_MD, render_system};
|
use crate::bootstrap::{Bootstrap, BootstrapKind, DEFAULT_SYSTEM_MD, render_system};
|
||||||
use crate::hub::{EventHub, TurnEvent, UserImage};
|
use crate::hub::{EventHub, TurnEvent, UserImage};
|
||||||
use crate::notifications::NotificationStore;
|
use crate::notifications::NotificationStore;
|
||||||
use crate::sandbox::SandboxState;
|
use crate::sandbox::SandboxState;
|
||||||
@@ -266,10 +268,18 @@ pub struct InteractiveHandler {
|
|||||||
/// dispatch, in the standard set's order — the same set whose
|
/// dispatch, in the standard set's order — the same set whose
|
||||||
/// sources the daemon's tick drives and whose boot pass runs first.
|
/// sources the daemon's tick drives and whose boot pass runs first.
|
||||||
extensions: Arc<crate::extension::Extensions>,
|
extensions: Arc<crate::extension::Extensions>,
|
||||||
/// The transcript's mirror, when the config has the view on: the
|
/// Whether the sessions run the bounded request view. The host
|
||||||
/// decorator refreshes it per request, `zoom` reads it, and it
|
/// agent builds the view and its `zoom` tool per dispatch; the
|
||||||
/// lives here — the agent rebuilds per dispatch, the log must not.
|
/// committed sections travel in the session, so they outlive the
|
||||||
transcript_mirror: Option<Arc<std::sync::Mutex<rhema_transcript::Transcript>>>,
|
/// agent.
|
||||||
|
transcript: bool,
|
||||||
|
/// The skills catalog the prompt discovers from, when the daemon
|
||||||
|
/// wired one. `None` means no skills.
|
||||||
|
skills: Option<Arc<crate::skills::Catalog>>,
|
||||||
|
/// The subagent catalog the `subagent` tool and the prompt's roster
|
||||||
|
/// read, when the daemon wired one. `None` leaves the dispatcher
|
||||||
|
/// without delegation.
|
||||||
|
subagents: Option<Arc<crate::subagents::Catalog>>,
|
||||||
/// The wired [`vision`](rhema_bash::vision) section for the
|
/// The wired [`vision`](rhema_bash::vision) section for the
|
||||||
/// prompt, when provisioning succeeded — the same wiring whose env
|
/// prompt, when provisioning succeeded — the same wiring whose env
|
||||||
/// map lights the shell's inbox up.
|
/// map lights the shell's inbox up.
|
||||||
@@ -336,16 +346,28 @@ impl InteractiveHandler {
|
|||||||
attachments,
|
attachments,
|
||||||
max_turn_steps,
|
max_turn_steps,
|
||||||
extensions,
|
extensions,
|
||||||
transcript_mirror: transcript.then(|| {
|
transcript,
|
||||||
Arc::new(std::sync::Mutex::new(rhema_transcript::Transcript::new(
|
skills: None,
|
||||||
rhema_transcript::TranscriptSettings::default(),
|
subagents: None,
|
||||||
)))
|
|
||||||
}),
|
|
||||||
vision: vision.map(|wiring| wiring.section.to_owned()),
|
vision: vision.map(|wiring| wiring.section.to_owned()),
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shares the skills catalog. Discovery runs per dispatch, so a
|
||||||
|
/// skill written while the daemon runs is live on the next turn.
|
||||||
|
pub(crate) fn with_skills(mut self, catalog: Arc<crate::skills::Catalog>) -> Self {
|
||||||
|
self.skills = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shares the subagent catalog: definitions, the `subagent` tool,
|
||||||
|
/// and its steering. Discovery runs per dispatch, same as skills.
|
||||||
|
pub(crate) fn with_subagents(mut self, catalog: Arc<crate::subagents::Catalog>) -> Self {
|
||||||
|
self.subagents = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Shares the deployment's sandbox choice: commands run where it
|
/// Shares the deployment's sandbox choice: commands run where it
|
||||||
/// says, and a remote sandbox replaces the host shell for `bash`.
|
/// says, and a remote sandbox replaces the host shell for `bash`.
|
||||||
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
||||||
@@ -353,54 +375,95 @@ impl InteractiveHandler {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The agent for one dispatch: rebuilt per run over the restored
|
/// The host agent a fresh dispatch starts on: no history yet. The
|
||||||
/// session (the engine's own step counter is per-agent; the
|
/// driver rebuilds per dispatch (the engine's own step counter is
|
||||||
/// conversation lives in the session, not the agent). The system
|
/// per-agent; the conversation lives in the session, not the agent),
|
||||||
/// prompt is re-rendered per dispatch, so a SOUL.md or USER.md the
|
/// and the system prompt is re-rendered here, so a SOUL.md or USER.md
|
||||||
/// last turn wrote is live this turn, the onboarding section is
|
/// the last turn wrote is live this turn and the onboarding section
|
||||||
/// gone the moment both files exist, and the tool roster is the
|
/// is gone the moment both files exist. The tool roster is the
|
||||||
/// dispatch chain's own specs — what the prompt lists is what the
|
/// dispatch chain's own specs, what the prompt lists and what the
|
||||||
/// request advertises.
|
/// request advertises.
|
||||||
fn agent(&self, key: &ResourceKey) -> Result<Agent, String> {
|
fn agent(&self, key: &ResourceKey) -> Result<HostAgent, String> {
|
||||||
|
let config = self.agent_config(key)?;
|
||||||
|
HostAgent::new(config).map_err(|err| format!("cannot build the interactive agent: {err}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [`Self::agent`] continuing `session`: the host agent resumes the
|
||||||
|
/// conversation rather than starting a new one.
|
||||||
|
fn resume(&self, key: &ResourceKey, session: Session) -> Result<HostAgent, String> {
|
||||||
|
let config = self.agent_config(key)?;
|
||||||
|
HostAgent::from_session(config, session)
|
||||||
|
.map_err(|err| format!("cannot resume the interactive agent: {err}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The config one dispatch's host agent runs on: the host agent's
|
||||||
|
/// own transcript view, the shell plus the extension side of the
|
||||||
|
/// resolver chain, and the bootstrap prompt rendered over the
|
||||||
|
/// dispatch's own tool specs. The view lives with the agent, so its
|
||||||
|
/// committed sections travel in the session and the next dispatch
|
||||||
|
/// hands them back.
|
||||||
|
fn agent_config(&self, key: &ResourceKey) -> Result<HostAgentConfig, String> {
|
||||||
let (provider, model) = self.backends.current();
|
let (provider, model) = self.backends.current();
|
||||||
// The view rides outside the engine: stubs, whole messages,
|
let shell = self.shell();
|
||||||
// and zoom output all show the text the model would have seen.
|
let extra = Arc::new(ResolverChain::new(self.extra_resolvers(key)));
|
||||||
let provider: Arc<dyn ModelProvider> = match &self.transcript_mirror {
|
|
||||||
Some(mirror) => Arc::new(rhema_transcript::TranscriptView::new(
|
|
||||||
provider,
|
|
||||||
mirror.clone(),
|
|
||||||
)),
|
|
||||||
None => provider,
|
|
||||||
};
|
|
||||||
let resolver = self.resolver(key);
|
|
||||||
let workspace = self.workspace();
|
let workspace = self.workspace();
|
||||||
let vision = if self
|
let remote = self
|
||||||
.sandbox
|
.sandbox
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|sandbox| sandbox.is_remote())
|
.is_some_and(|sandbox| sandbox.is_remote());
|
||||||
{
|
let vision = if remote { None } else { self.vision.as_deref() };
|
||||||
None
|
let mut specs = shell.specs();
|
||||||
} else {
|
specs.extend(extra.specs());
|
||||||
self.vision.as_deref()
|
if self.transcript {
|
||||||
};
|
specs.push(rhema_transcript::Zoom::spec());
|
||||||
|
}
|
||||||
|
if let Some(catalog) = &self.subagents {
|
||||||
|
specs.extend(catalog.specs(&workspace));
|
||||||
|
}
|
||||||
|
let skills = self
|
||||||
|
.skills
|
||||||
|
.as_ref()
|
||||||
|
.map(|catalog| catalog.discover(&self.workspace, remote))
|
||||||
|
.unwrap_or_default();
|
||||||
let system = render_system(
|
let system = render_system(
|
||||||
DEFAULT_SYSTEM_MD,
|
DEFAULT_SYSTEM_MD,
|
||||||
key.as_str(),
|
key.as_str(),
|
||||||
&workspace,
|
&workspace,
|
||||||
&self.bootstrap,
|
&self.bootstrap,
|
||||||
&resolver.specs(),
|
&specs,
|
||||||
|
&skills,
|
||||||
vision,
|
vision,
|
||||||
crate::mcp::section().as_deref(),
|
crate::mcp::section().as_deref(),
|
||||||
crate::bootstrap::Surface::Chat,
|
crate::bootstrap::Surface::Chat,
|
||||||
)
|
)
|
||||||
.map_err(|err| format!("cannot render the bootstrap system prompt: {err}"))?;
|
.map_err(|err| format!("cannot render the bootstrap system prompt: {err}"))?;
|
||||||
Agent::builder()
|
let mut config = HostAgentConfig::new(provider, model, &workspace, AllowAll);
|
||||||
.provider(provider)
|
config.max_turn_steps = self.max_turn_steps;
|
||||||
.resolver(resolver)
|
config.tools = Some(shell);
|
||||||
.system(system)
|
config.extra_resolver = Some(extra);
|
||||||
.params(ChatParams::new(model))
|
config.system = Some(system);
|
||||||
.build()
|
config.transcript = self
|
||||||
.map_err(|err| format!("cannot build the interactive agent: {err}"))
|
.transcript
|
||||||
|
.then(rhema_transcript::TranscriptSettings::default);
|
||||||
|
config.skills = Some(skills);
|
||||||
|
config.disabled_skills = self
|
||||||
|
.skills
|
||||||
|
.as_ref()
|
||||||
|
.map(|catalog| catalog.disabled().clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
if let Some(catalog) = &self.subagents {
|
||||||
|
// The subagent stamp carries the parent's earned context.
|
||||||
|
// The parent's own prompt is verbatim, so these sections
|
||||||
|
// reach only the subagent's default template.
|
||||||
|
config.environment = self
|
||||||
|
.bootstrap
|
||||||
|
.load(BootstrapKind::Environment)
|
||||||
|
.ok()
|
||||||
|
.flatten();
|
||||||
|
config.user_preferences = self.bootstrap.load(BootstrapKind::User).ok().flatten();
|
||||||
|
let _handle = catalog.wire(&mut config);
|
||||||
|
}
|
||||||
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shares `steer` with the HTTP surface: the messages route
|
/// Shares `steer` with the HTTP surface: the messages route
|
||||||
@@ -430,15 +493,10 @@ impl InteractiveHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The resolver chain one dispatch runs under: the core toolsets —
|
/// The shell one dispatch's `bash` runs on: the handler's own, or
|
||||||
/// the shell over the interactive workspace, memory,
|
/// one over the sandbox executor when the surface selected a remote.
|
||||||
/// `bootstrap_save` — then every extension's tools in the standard
|
fn shell(&self) -> Arc<ShellTools> {
|
||||||
/// set's order. The whole chain is cut per dispatch: the
|
match &self.sandbox {
|
||||||
/// key-scoped toolsets (consents, attachments, phone) must bind
|
|
||||||
/// their asks and cards to the session that asked, and the handler
|
|
||||||
/// serves every session.
|
|
||||||
fn resolver(&self, key: &ResourceKey) -> Arc<ResolverChain> {
|
|
||||||
let shell: Arc<dyn rhema_core::ToolResolver> = match &self.sandbox {
|
|
||||||
Some(sandbox) if sandbox.is_remote() => {
|
Some(sandbox) if sandbox.is_remote() => {
|
||||||
let workspace = sandbox.workspace_for(&self.workspace);
|
let workspace = sandbox.workspace_for(&self.workspace);
|
||||||
let tools =
|
let tools =
|
||||||
@@ -447,9 +505,17 @@ impl InteractiveHandler {
|
|||||||
Arc::new(tools)
|
Arc::new(tools)
|
||||||
}
|
}
|
||||||
_ => self.tools.clone(),
|
_ => self.tools.clone(),
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The extension side of one dispatch's chain: memory,
|
||||||
|
/// `bootstrap_save`, then every extension's tools in the standard
|
||||||
|
/// set's order. The whole side is cut per dispatch: the key-scoped
|
||||||
|
/// toolsets (consents, attachments, phone) must bind their asks and
|
||||||
|
/// cards to the session that asked, and the handler serves every
|
||||||
|
/// session.
|
||||||
|
fn extra_resolvers(&self, key: &ResourceKey) -> Vec<Arc<dyn rhema_core::ToolResolver>> {
|
||||||
let mut resolvers: Vec<Arc<dyn rhema_core::ToolResolver>> = vec![
|
let mut resolvers: Vec<Arc<dyn rhema_core::ToolResolver>> = vec![
|
||||||
shell,
|
|
||||||
Arc::new(MemoryResolver::new(
|
Arc::new(MemoryResolver::new(
|
||||||
self.memory.clone(),
|
self.memory.clone(),
|
||||||
Scope::Workspace(self.workspace.clone()),
|
Scope::Workspace(self.workspace.clone()),
|
||||||
@@ -457,11 +523,17 @@ impl InteractiveHandler {
|
|||||||
self.bootstrap_resolver.clone(),
|
self.bootstrap_resolver.clone(),
|
||||||
];
|
];
|
||||||
resolvers.extend(self.extensions.tools(key));
|
resolvers.extend(self.extensions.tools(key));
|
||||||
if let Some(mirror) = &self.transcript_mirror {
|
resolvers
|
||||||
// Unique name, read-only: it shadows nothing and a replay
|
}
|
||||||
// may re-run it after a crash resume.
|
|
||||||
resolvers.push(Arc::new(rhema_transcript::Zoom::new(mirror.clone())));
|
/// The whole chain the prompt previews: the shell, then the
|
||||||
}
|
/// extension side. A dispatch builds the two halves separately, so
|
||||||
|
/// the host agent can install the approval hook on the shell it
|
||||||
|
/// owns; this view exists for the prompt tests and previews.
|
||||||
|
#[cfg(test)]
|
||||||
|
fn resolver(&self, key: &ResourceKey) -> Arc<ResolverChain> {
|
||||||
|
let mut resolvers: Vec<Arc<dyn rhema_core::ToolResolver>> = vec![self.shell()];
|
||||||
|
resolvers.extend(self.extra_resolvers(key));
|
||||||
Arc::new(ResolverChain::new(resolvers))
|
Arc::new(ResolverChain::new(resolvers))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,21 +715,21 @@ impl InteractiveHandler {
|
|||||||
input
|
input
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut session = restore_session(&ctx.session.core.driver_state, &key)?;
|
let mut agent = match &ctx.session.core.driver_state {
|
||||||
let resolver = self.resolver(&ctx.key);
|
// A never-dispatched key carries no stash: start clean.
|
||||||
let mut agent = self.agent(&ctx.key)?;
|
Value::Null => self.agent(&ctx.key)?,
|
||||||
|
stashed => {
|
||||||
|
let session = restore_session(stashed, &key)?;
|
||||||
|
self.resume(&ctx.key, session)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
adopt_transcript(&mut agent);
|
||||||
// Commit-before-execute: the intent is in the store before the
|
// Commit-before-execute: the intent is in the store before the
|
||||||
// first tool runs — and if the lease cannot be committed under
|
// first tool runs — and if the lease cannot be committed under
|
||||||
// (expired, lost), the turn fails before any side effect. A
|
// (expired, lost), the turn fails before any side effect. A
|
||||||
// crash-left dangling call revives first: safe tools re-run, the
|
// crash-left dangling call revives at turn entry: safe tools
|
||||||
// rest report interrupted.
|
// re-run, the rest report interrupted.
|
||||||
agent.set_commit_hook(Some(ctx.commit_hook()));
|
agent.set_commit_hook(Some(ctx.commit_hook()));
|
||||||
let tools = ToolContext {
|
|
||||||
cwd: self.workspace.clone(),
|
|
||||||
run_id: key.clone(),
|
|
||||||
cancelled: Arc::new(AtomicBool::new(false)),
|
|
||||||
};
|
|
||||||
revive_dangling_calls(&mut session, resolver.as_ref(), &tools).await;
|
|
||||||
let mut sink = HubSink {
|
let mut sink = HubSink {
|
||||||
key: ctx.key.clone(),
|
key: ctx.key.clone(),
|
||||||
hub: self.hub.clone(),
|
hub: self.hub.clone(),
|
||||||
@@ -687,14 +759,7 @@ impl InteractiveHandler {
|
|||||||
let mut question = [Message::text_with_images(Role::User, input, core_images)];
|
let mut question = [Message::text_with_images(Role::User, input, core_images)];
|
||||||
crate::paste::annotate(&mut question[0], &pastes);
|
crate::paste::annotate(&mut question[0], &pastes);
|
||||||
let [turn_input] = question;
|
let [turn_input] = question;
|
||||||
let mut turn = Box::pin(run_turn(
|
let mut turn = Box::pin(agent.turn_message(turn_input, &mut sink));
|
||||||
&mut agent,
|
|
||||||
&mut session,
|
|
||||||
turn_input,
|
|
||||||
&mut sink,
|
|
||||||
&tools,
|
|
||||||
self.max_turn_steps,
|
|
||||||
));
|
|
||||||
let mut aborted = false;
|
let mut aborted = false;
|
||||||
let finished = tokio::select! {
|
let finished = tokio::select! {
|
||||||
result = &mut turn => match steer.take() {
|
result = &mut turn => match steer.take() {
|
||||||
@@ -719,12 +784,13 @@ impl InteractiveHandler {
|
|||||||
// results; the repair answers them so the next round's request
|
// results; the repair answers them so the next round's request
|
||||||
// is valid history.
|
// is valid history.
|
||||||
if finished.is_none() {
|
if finished.is_none() {
|
||||||
close_orphaned_calls(&mut session.history);
|
close_orphaned_calls(&mut agent.session_mut().history);
|
||||||
}
|
}
|
||||||
|
save_transcript(&mut agent);
|
||||||
// Stash before anything else: the conversation survives even if
|
// Stash before anything else: the conversation survives even if
|
||||||
// the subscriber never sees the stream — and a steered chain
|
// the subscriber never sees the stream — and a steered chain
|
||||||
// dies between rounds, the steered state is what resumes.
|
// dies between rounds, the steered state is what resumes.
|
||||||
ctx.session.core.driver_state = serde_json::to_value(&session)
|
ctx.session.core.driver_state = serde_json::to_value(agent.session())
|
||||||
.map_err(|err| format!("session for {key} does not serialize: {err}"))?;
|
.map_err(|err| format!("session for {key} does not serialize: {err}"))?;
|
||||||
match finished {
|
match finished {
|
||||||
Some(Ok(output)) => Ok(Round::Done(Ok(final_text(&output.message)))),
|
Some(Ok(output)) => Ok(Round::Done(Ok(final_text(&output.message)))),
|
||||||
@@ -867,6 +933,65 @@ enum Round {
|
|||||||
Idle,
|
Idle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The session driver-state key carrying the transcript's committed
|
||||||
|
/// sections and counters. The host agent builds the view per dispatch,
|
||||||
|
/// so this is what keeps compaction across dispatches and restarts.
|
||||||
|
const TRANSCRIPT_STATE_KEY: &str = "claw_transcript";
|
||||||
|
|
||||||
|
/// The transcript state that travels in the session.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
struct TranscriptSnapshot {
|
||||||
|
/// The benchmark counters, when the view was on.
|
||||||
|
#[serde(default)]
|
||||||
|
stats: Option<TranscriptStats>,
|
||||||
|
/// The committed sections, oldest first.
|
||||||
|
#[serde(default)]
|
||||||
|
sections: Vec<Section>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hands a resumed session's transcript state to the agent before its
|
||||||
|
/// first request. A missing or unparsable snapshot simply starts the
|
||||||
|
/// view fresh; the log rebuilds it on the next request.
|
||||||
|
fn adopt_transcript(agent: &mut HostAgent) {
|
||||||
|
let saved = agent
|
||||||
|
.session()
|
||||||
|
.driver_state
|
||||||
|
.get(TRANSCRIPT_STATE_KEY)
|
||||||
|
.and_then(|value| serde_json::from_value::<TranscriptSnapshot>(value.clone()).ok());
|
||||||
|
let Some(saved) = saved else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if let Some(stats) = &saved.stats {
|
||||||
|
agent.carry_transcript_stats(stats);
|
||||||
|
}
|
||||||
|
agent.adopt_transcript_sections(saved.sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the agent's transcript state back into its session, so the
|
||||||
|
/// stash carries it. With the view off, any old snapshot is removed.
|
||||||
|
fn save_transcript(agent: &mut HostAgent) {
|
||||||
|
let stats = agent.transcript_stats();
|
||||||
|
let sections = agent.transcript_sections();
|
||||||
|
if stats.is_none() && sections.is_empty() {
|
||||||
|
if let Some(state) = agent.session_mut().driver_state.as_object_mut() {
|
||||||
|
state.remove(TRANSCRIPT_STATE_KEY);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Ok(value) = serde_json::to_value(TranscriptSnapshot { stats, sections }) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let state = &mut agent.session_mut().driver_state;
|
||||||
|
if !state.is_object() {
|
||||||
|
if state.is_null() {
|
||||||
|
*state = json!({});
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state[TRANSCRIPT_STATE_KEY] = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// The stashed conversation: a serialized [`Session`], `Null` meaning
|
/// The stashed conversation: a serialized [`Session`], `Null` meaning
|
||||||
/// fresh. A stash that does not parse is loud — silently resetting would
|
/// fresh. A stash that does not parse is loud — silently resetting would
|
||||||
/// re-orient the agent mid-conversation without anyone knowing.
|
/// re-orient the agent mid-conversation without anyone knowing.
|
||||||
@@ -1217,7 +1342,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The transcript wiring: on, the prompt advertises zoom and the
|
/// The transcript wiring: on, the prompt advertises zoom and the
|
||||||
/// mirror exists; off, neither appears and the request rides whole.
|
/// agent carries the view; off, neither appears and the request
|
||||||
|
/// rides whole.
|
||||||
#[test]
|
#[test]
|
||||||
fn the_transcript_joins_zoom_when_on_and_nothing_when_off() {
|
fn the_transcript_joins_zoom_when_on_and_nothing_when_off() {
|
||||||
for on in [true, false] {
|
for on in [true, false] {
|
||||||
@@ -1258,10 +1384,118 @@ mod tests {
|
|||||||
on,
|
on,
|
||||||
"on={on}"
|
"on={on}"
|
||||||
);
|
);
|
||||||
assert_eq!(handler.transcript_mirror.is_some(), on, "on={on}");
|
assert_eq!(agent.transcript_stats().is_some(), on, "on={on}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn discovered_skills_reach_the_prompt() {
|
||||||
|
let workspace = tempfile::tempdir().expect("tempdir");
|
||||||
|
let skills_root = workspace.path().join("skills");
|
||||||
|
let folder = skills_root.join("unslop");
|
||||||
|
std::fs::create_dir_all(&folder).expect("skill folder");
|
||||||
|
std::fs::write(
|
||||||
|
folder.join("SKILL.md"),
|
||||||
|
"---\ndescription: Always apply.\n---\n\nThe rules.\n",
|
||||||
|
)
|
||||||
|
.expect("skill file");
|
||||||
|
let hub = Arc::new(EventHub::default());
|
||||||
|
let store = Arc::new(ClawStore::in_memory().expect("store opens"));
|
||||||
|
let notifications = notifications();
|
||||||
|
let extensions = test_extensions(
|
||||||
|
hub.clone(),
|
||||||
|
store,
|
||||||
|
notifications.clone(),
|
||||||
|
tasks(),
|
||||||
|
jobs(),
|
||||||
|
accounts(),
|
||||||
|
consents(),
|
||||||
|
bridge(),
|
||||||
|
attachments(),
|
||||||
|
phone(),
|
||||||
|
identity(),
|
||||||
|
&workspace.path().join("interactive"),
|
||||||
|
);
|
||||||
|
let handler = InteractiveHandler::new(
|
||||||
|
test_registry(RecordingProvider::new()),
|
||||||
|
workspace.path().join("interactive"),
|
||||||
|
Arc::new(rhema_memory::VolatileStore::new()),
|
||||||
|
Arc::new(Bootstrap::new(workspace.path().join("bootstrap")).expect("store opens")),
|
||||||
|
hub,
|
||||||
|
notifications,
|
||||||
|
attachments(),
|
||||||
|
crate::config::DEFAULT_MAX_TURN_STEPS,
|
||||||
|
extensions,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.with_skills(Arc::new(crate::skills::Catalog::new(
|
||||||
|
skills_root,
|
||||||
|
std::collections::BTreeSet::new(),
|
||||||
|
workspace.path().join("interactive"),
|
||||||
|
Arc::new(crate::settings::SettingsStore::in_memory().unwrap()),
|
||||||
|
)));
|
||||||
|
let agent = handler
|
||||||
|
.agent(&Key::from("interactive:web"))
|
||||||
|
.expect("the agent builds");
|
||||||
|
let prompt = agent.system().expect("a prompt");
|
||||||
|
assert!(prompt.contains("## Skills"), "{prompt}");
|
||||||
|
assert!(prompt.contains("[MUST LOAD NOW] unslop"), "{prompt}");
|
||||||
|
assert!(!prompt.contains("The rules."), "{prompt}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn discovered_subagents_reach_the_prompt() {
|
||||||
|
let workspace = tempfile::tempdir().expect("tempdir");
|
||||||
|
let subagents_root = workspace.path().join("subagents");
|
||||||
|
let folder = subagents_root.join("reviewer");
|
||||||
|
std::fs::create_dir_all(&folder).expect("definition folder");
|
||||||
|
std::fs::write(
|
||||||
|
folder.join(rhema_subagents::def::FILE),
|
||||||
|
"---\ndescription: reviews diffs\n---\n\nReview carefully.\n",
|
||||||
|
)
|
||||||
|
.expect("definition file");
|
||||||
|
let hub = Arc::new(EventHub::default());
|
||||||
|
let store = Arc::new(ClawStore::in_memory().expect("store opens"));
|
||||||
|
let notifications = notifications();
|
||||||
|
let extensions = test_extensions(
|
||||||
|
hub.clone(),
|
||||||
|
store,
|
||||||
|
notifications.clone(),
|
||||||
|
tasks(),
|
||||||
|
jobs(),
|
||||||
|
accounts(),
|
||||||
|
consents(),
|
||||||
|
bridge(),
|
||||||
|
attachments(),
|
||||||
|
phone(),
|
||||||
|
identity(),
|
||||||
|
&workspace.path().join("interactive"),
|
||||||
|
);
|
||||||
|
let handler = InteractiveHandler::new(
|
||||||
|
test_registry(RecordingProvider::new()),
|
||||||
|
workspace.path().join("interactive"),
|
||||||
|
Arc::new(rhema_memory::VolatileStore::new()),
|
||||||
|
Arc::new(Bootstrap::new(workspace.path().join("bootstrap")).expect("store opens")),
|
||||||
|
hub,
|
||||||
|
notifications,
|
||||||
|
attachments(),
|
||||||
|
crate::config::DEFAULT_MAX_TURN_STEPS,
|
||||||
|
extensions,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.with_subagents(Arc::new(crate::subagents::Catalog::new(
|
||||||
|
subagents_root,
|
||||||
|
std::collections::BTreeSet::new(),
|
||||||
|
)));
|
||||||
|
let agent = handler
|
||||||
|
.agent(&Key::from("interactive:web"))
|
||||||
|
.expect("the agent builds with the subagent tool");
|
||||||
|
let prompt = agent.system().expect("a prompt");
|
||||||
|
assert!(prompt.contains("subagent"), "{prompt}");
|
||||||
|
assert!(prompt.contains("reviews diffs"), "{prompt}");
|
||||||
|
assert!(!prompt.contains("Review carefully."), "{prompt}");
|
||||||
|
}
|
||||||
|
|
||||||
/// The environment a paste test drives: the recording provider, the
|
/// The environment a paste test drives: the recording provider, the
|
||||||
/// hub, and a dispatcher wired to one interactive handler over a
|
/// hub, and a dispatcher wired to one interactive handler over a
|
||||||
/// throwaway workspace.
|
/// throwaway workspace.
|
||||||
@@ -1467,6 +1701,7 @@ mod tests {
|
|||||||
Path::new("/state/claw/workspaces/interactive"),
|
Path::new("/state/claw/workspaces/interactive"),
|
||||||
&handler.bootstrap,
|
&handler.bootstrap,
|
||||||
&specs,
|
&specs,
|
||||||
|
&[],
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
crate::bootstrap::Surface::Chat,
|
crate::bootstrap::Surface::Chat,
|
||||||
|
|||||||
@@ -144,6 +144,12 @@ pub struct CodingJobHandler {
|
|||||||
/// Whether the jobs run the bounded request view (the config's
|
/// Whether the jobs run the bounded request view (the config's
|
||||||
/// `transcript`, on unless set false).
|
/// `transcript`, on unless set false).
|
||||||
transcript: bool,
|
transcript: bool,
|
||||||
|
/// The skills catalog the default prompt discovers from, when the
|
||||||
|
/// daemon wired one. `None` leaves the host agent's own discovery.
|
||||||
|
skills: Option<Arc<crate::skills::Catalog>>,
|
||||||
|
/// The subagent catalog the `subagent` tool reads. `None` leaves a
|
||||||
|
/// coding job without delegation.
|
||||||
|
subagents: Option<Arc<crate::subagents::Catalog>>,
|
||||||
/// Where commands run: this host when absent, a remote sandbox when
|
/// Where commands run: this host when absent, a remote sandbox when
|
||||||
/// the surface selected one. Read per job.
|
/// the surface selected one. Read per job.
|
||||||
sandbox: Option<Arc<SandboxState>>,
|
sandbox: Option<Arc<SandboxState>>,
|
||||||
@@ -172,11 +178,25 @@ impl CodingJobHandler {
|
|||||||
notifications,
|
notifications,
|
||||||
max_turn_steps,
|
max_turn_steps,
|
||||||
transcript,
|
transcript,
|
||||||
|
skills: None,
|
||||||
|
subagents: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
abort: Arc::new(crate::abort::AbortRegistry::new()),
|
abort: Arc::new(crate::abort::AbortRegistry::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shares the skills catalog.
|
||||||
|
pub(crate) fn with_skills(mut self, catalog: Arc<crate::skills::Catalog>) -> Self {
|
||||||
|
self.skills = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shares the subagent catalog.
|
||||||
|
pub(crate) fn with_subagents(mut self, catalog: Arc<crate::subagents::Catalog>) -> Self {
|
||||||
|
self.subagents = Some(catalog);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Shares the deployment's sandbox choice: a job's commands run
|
/// Shares the deployment's sandbox choice: a job's commands run
|
||||||
/// where it says, seeded from the instance's host path.
|
/// where it says, seeded from the instance's host path.
|
||||||
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
pub fn with_sandbox(mut self, sandbox: Arc<SandboxState>) -> Self {
|
||||||
@@ -253,6 +273,14 @@ impl CodingJobHandler {
|
|||||||
};
|
};
|
||||||
let mut config = HostAgentConfig::new(provider, model, &display, AllowAll);
|
let mut config = HostAgentConfig::new(provider, model, &display, AllowAll);
|
||||||
config.max_turn_steps = self.max_turn_steps;
|
config.max_turn_steps = self.max_turn_steps;
|
||||||
|
let remote = self
|
||||||
|
.sandbox
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|sandbox| sandbox.is_remote());
|
||||||
|
if let Some(catalog) = &self.skills {
|
||||||
|
config.skills = Some(catalog.discover(&workspace, remote));
|
||||||
|
config.disabled_skills = catalog.disabled().clone();
|
||||||
|
}
|
||||||
// A job's stashed session carries across runs and only ever
|
// A job's stashed session carries across runs and only ever
|
||||||
// grows; the view is what keeps a repeat run's steps cheap.
|
// grows; the view is what keeps a repeat run's steps cheap.
|
||||||
// Write the resolved value, not an override: the coding agent's
|
// Write the resolved value, not an override: the coding agent's
|
||||||
@@ -272,6 +300,9 @@ impl CodingJobHandler {
|
|||||||
crate::mcp::apply(&mut config);
|
crate::mcp::apply(&mut config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(catalog) = &self.subagents {
|
||||||
|
let _handle = catalog.wire(&mut config);
|
||||||
|
}
|
||||||
let stashed = self
|
let stashed = self
|
||||||
.store
|
.store
|
||||||
.session(&instance_name)
|
.session(&instance_name)
|
||||||
|
|||||||
@@ -48,6 +48,9 @@
|
|||||||
//! read, consent-gated control actions the device executes
|
//! read, consent-gated control actions the device executes
|
||||||
//! - [`sandbox`]: where `bash` runs, this host, or a remote daemon
|
//! - [`sandbox`]: where `bash` runs, this host, or a remote daemon
|
||||||
//! speaking the sandbox protocol over HTTP
|
//! speaking the sandbox protocol over HTTP
|
||||||
|
//! - [`skills`] — discovery plus the persisted per-skill off switch
|
||||||
|
//! - [`subagents`] — definition discovery and the `subagent` wire
|
||||||
|
//! - [`mcp`] — the MCP client's prompt section and shell environment
|
||||||
//! - [`watch_tools`] — the agent's watch-management tool set
|
//! - [`watch_tools`] — the agent's watch-management tool set
|
||||||
//! - [`notify_tools`] — the `notify` tool: the queue a device polls
|
//! - [`notify_tools`] — the `notify` tool: the queue a device polls
|
||||||
//! - [`task_tools`] — `schedule_task`, `list_tasks`, `cancel_task`
|
//! - [`task_tools`] — `schedule_task`, `list_tasks`, `cancel_task`
|
||||||
@@ -75,6 +78,7 @@ pub mod accounts_tools;
|
|||||||
pub mod attachments;
|
pub mod attachments;
|
||||||
pub mod backends;
|
pub mod backends;
|
||||||
pub mod bootstrap;
|
pub mod bootstrap;
|
||||||
|
mod bundled;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod consents;
|
pub mod consents;
|
||||||
pub mod daemon;
|
pub mod daemon;
|
||||||
@@ -91,6 +95,7 @@ pub mod job_store;
|
|||||||
pub mod job_tools;
|
pub mod job_tools;
|
||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
pub mod mcp;
|
pub mod mcp;
|
||||||
|
mod mcp_config;
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
pub mod mock;
|
pub mod mock;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
@@ -101,7 +106,9 @@ pub mod pause;
|
|||||||
pub mod phone;
|
pub mod phone;
|
||||||
pub mod sandbox;
|
pub mod sandbox;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
pub(crate) mod skills;
|
||||||
pub mod steer;
|
pub mod steer;
|
||||||
|
pub mod subagents;
|
||||||
pub mod task_source;
|
pub mod task_source;
|
||||||
pub mod task_store;
|
pub mod task_store;
|
||||||
pub mod task_tools;
|
pub mod task_tools;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//! file and lets the client describe what it holds.
|
//! file and lets the client describe what it holds.
|
||||||
//!
|
//!
|
||||||
//! A host session reads `~/.config/rhema/mcp/config.json` and stages
|
//! A host session reads `~/.config/rhema/mcp/config.json` and stages
|
||||||
//! media under `~/.cache/rhema/mcp/media`. The config's
|
//! media under `~/.cache/rhema/mcp/media`. The daemon's
|
||||||
//! `disabled_mcp_servers` rides along as `MCP_DISABLED`, which the
|
//! `disabled_mcp_servers` rides along as `MCP_DISABLED`, which the
|
||||||
//! client filters at `list` and `prompt` time.
|
//! client filters at `list` and `prompt` time.
|
||||||
|
|
||||||
@@ -29,6 +29,29 @@ struct Wired {
|
|||||||
|
|
||||||
static WIRED: OnceLock<Option<Wired>> = OnceLock::new();
|
static WIRED: OnceLock<Option<Wired>> = OnceLock::new();
|
||||||
|
|
||||||
|
/// The daemon's configured mute set, when it seeded one. The lazy
|
||||||
|
/// fallback reads the default `claw.yaml`, so a test or a standalone
|
||||||
|
/// `apply` still finds the reference layout.
|
||||||
|
static SEEDED_DISABLED: OnceLock<BTreeSet<String>> = OnceLock::new();
|
||||||
|
|
||||||
|
/// Seeds the mute set from the daemon's actual config. Called before
|
||||||
|
/// the first dispatch; a later call is a no-op, because the shell env
|
||||||
|
/// is already built.
|
||||||
|
pub(crate) fn seed_disabled(disabled: BTreeSet<String>) {
|
||||||
|
let _ = SEEDED_DISABLED.set(disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The mute set the wiring uses: the seeded one, else the default
|
||||||
|
/// config's, else empty.
|
||||||
|
fn disabled() -> BTreeSet<String> {
|
||||||
|
SEEDED_DISABLED.get().cloned().unwrap_or_else(|| {
|
||||||
|
ClawConfig::default_path()
|
||||||
|
.and_then(|path| ClawConfig::load_from(&path))
|
||||||
|
.map(|config| config.disabled_mcp_servers)
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// The MCP directory pair for the reference layout: the config file
|
/// The MCP directory pair for the reference layout: the config file
|
||||||
/// and the media staging directory.
|
/// and the media staging directory.
|
||||||
fn places(home: &rhema_config::Home) -> (PathBuf, PathBuf) {
|
fn places(home: &rhema_config::Home) -> (PathBuf, PathBuf) {
|
||||||
@@ -66,7 +89,6 @@ fn probe(env: &BTreeMap<String, String>) -> Option<String> {
|
|||||||
fn wired() -> Option<&'static Wired> {
|
fn wired() -> Option<&'static Wired> {
|
||||||
WIRED
|
WIRED
|
||||||
.get_or_init(|| {
|
.get_or_init(|| {
|
||||||
let claw = ClawConfig::load_from(&ClawConfig::default_path().ok()?).ok()?;
|
|
||||||
let home = rhema_config::Home::discover().ok()?;
|
let home = rhema_config::Home::discover().ok()?;
|
||||||
let (config, media) = places(&home);
|
let (config, media) = places(&home);
|
||||||
if !config.is_file() {
|
if !config.is_file() {
|
||||||
@@ -82,7 +104,7 @@ fn wired() -> Option<&'static Wired> {
|
|||||||
"MCP_MEDIA_DIR".to_owned(),
|
"MCP_MEDIA_DIR".to_owned(),
|
||||||
media.to_string_lossy().into_owned(),
|
media.to_string_lossy().into_owned(),
|
||||||
),
|
),
|
||||||
("MCP_DISABLED".to_owned(), join(&claw.disabled_mcp_servers)),
|
("MCP_DISABLED".to_owned(), join(&disabled())),
|
||||||
]);
|
]);
|
||||||
// The installer's install directory, so the client this
|
// The installer's install directory, so the client this
|
||||||
// daemon probes is the one the model's shell resolves.
|
// daemon probes is the one the model's shell resolves.
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
//! The MCP client's config file, read for the settings page.
|
||||||
|
//!
|
||||||
|
//! The file belongs to the standalone `mcp` client: the claw names it
|
||||||
|
//! through `MCP_CONFIG` and lets the client own its schema. This module
|
||||||
|
//! is the read-only reflection the web surface needs — server names,
|
||||||
|
//! descriptions, transport, and the configured mute set — so the page
|
||||||
|
//! can show what the agent's shell sees without duplicating the
|
||||||
|
//! client's validation or ever printing a credential.
|
||||||
|
//!
|
||||||
|
//! Both the `servers` object and Claude's `mcpServers` spelling parse,
|
||||||
|
//! and a flat map of entries parses too: hand-written files are common,
|
||||||
|
//! and refusing one shape would make the page lie about a file the
|
||||||
|
//! client accepts.
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
/// One server row the page shows. Deliberately narrow: no env, no
|
||||||
|
/// headers, and only the program name of a stdio command — arguments
|
||||||
|
/// and URLs can carry credentials.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
||||||
|
pub(crate) struct ServerRow {
|
||||||
|
/// The config key.
|
||||||
|
pub name: String,
|
||||||
|
/// The user-written description, empty when the entry has none.
|
||||||
|
pub description: String,
|
||||||
|
/// `stdio`, `http`, or `unknown` when the entry names neither.
|
||||||
|
pub transport: &'static str,
|
||||||
|
/// The program for a stdio entry; `None` for HTTP and unknown.
|
||||||
|
pub program: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The page's store: the file path and the mute set the daemon was
|
||||||
|
/// configured with.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) struct Store {
|
||||||
|
config: PathBuf,
|
||||||
|
disabled: BTreeSet<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Store {
|
||||||
|
/// A store over `config`, reporting `disabled` as the mute set.
|
||||||
|
pub(crate) fn new(config: PathBuf, disabled: BTreeSet<String>) -> Self {
|
||||||
|
Self { config, disabled }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The page's live state.
|
||||||
|
pub(crate) fn info(&self) -> Info {
|
||||||
|
let exists = self.config.is_file();
|
||||||
|
let mut notices = Vec::new();
|
||||||
|
let mut servers = Vec::new();
|
||||||
|
if exists {
|
||||||
|
match std::fs::read_to_string(&self.config) {
|
||||||
|
Ok(raw) => match serde_json::from_str::<Value>(&raw) {
|
||||||
|
Ok(value) => collect(&value, &mut servers, &mut notices),
|
||||||
|
Err(err) => notices.push(format!("the config is not JSON: {err}")),
|
||||||
|
},
|
||||||
|
Err(err) => notices.push(format!("the config could not be read: {err}")),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
notices.push("no MCP config file; the client has no servers to list".to_owned());
|
||||||
|
}
|
||||||
|
servers.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
Info {
|
||||||
|
config: self.config.clone(),
|
||||||
|
exists,
|
||||||
|
servers,
|
||||||
|
disabled: self.disabled.clone(),
|
||||||
|
notices,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The reference layout: `<config>/rhema/mcp/config.json`.
|
||||||
|
pub(crate) fn default_path() -> PathBuf {
|
||||||
|
rhema_config::Home::discover()
|
||||||
|
.map(|home| home.config.join("mcp").join("config.json"))
|
||||||
|
.unwrap_or_else(|_| PathBuf::from("~/.config/rhema/mcp/config.json"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The page's whole state.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) struct Info {
|
||||||
|
/// The config file the client reads.
|
||||||
|
pub config: PathBuf,
|
||||||
|
/// Whether the file exists.
|
||||||
|
pub exists: bool,
|
||||||
|
/// The rows, name order.
|
||||||
|
pub servers: Vec<ServerRow>,
|
||||||
|
/// The names the claw mutes, from `claw.yaml`.
|
||||||
|
pub disabled: BTreeSet<String>,
|
||||||
|
/// Parse problems worth showing, never secrets.
|
||||||
|
pub notices: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Folds the file's server map into rows, one notice per entry that is
|
||||||
|
/// not an object. The file's shape is the client's; this never rewrites
|
||||||
|
/// it.
|
||||||
|
fn collect(value: &Value, servers: &mut Vec<ServerRow>, notices: &mut Vec<String>) {
|
||||||
|
let Some(map) = value
|
||||||
|
.get("servers")
|
||||||
|
.or_else(|| value.get("mcpServers"))
|
||||||
|
.or_else(|| value.as_object().map(|_| value))
|
||||||
|
.and_then(Value::as_object)
|
||||||
|
else {
|
||||||
|
notices.push("the config holds no servers object".to_owned());
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
for (name, entry) in map {
|
||||||
|
let Some(entry) = entry.as_object() else {
|
||||||
|
notices.push(format!("server `{name}` is not an object"));
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let description = entry
|
||||||
|
.get("description")
|
||||||
|
.and_then(Value::as_str)
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_owned();
|
||||||
|
let url = entry.get("url").and_then(Value::as_str);
|
||||||
|
let command = entry.get("command");
|
||||||
|
let (transport, program) = match (url, command) {
|
||||||
|
(Some(_), _) => ("http", None),
|
||||||
|
(None, Some(Value::String(program))) => ("stdio", Some(program.clone())),
|
||||||
|
(None, Some(Value::Array(argv))) => (
|
||||||
|
"stdio",
|
||||||
|
argv.first().and_then(Value::as_str).map(str::to_owned),
|
||||||
|
),
|
||||||
|
(None, Some(_)) => {
|
||||||
|
notices.push(format!(
|
||||||
|
"server `{name}` has a command that is not a string or array"
|
||||||
|
));
|
||||||
|
("unknown", None)
|
||||||
|
}
|
||||||
|
(None, None) => ("unknown", None),
|
||||||
|
};
|
||||||
|
servers.push(ServerRow {
|
||||||
|
name: name.clone(),
|
||||||
|
description,
|
||||||
|
transport,
|
||||||
|
program,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn both_server_spellings_and_the_flat_map_parse() {
|
||||||
|
let value = serde_json::json!({
|
||||||
|
"servers": {
|
||||||
|
"docs": {"description": "docs", "url": "https://example.test/mcp"},
|
||||||
|
"local": {"command": ["mcp-docs", "--stdio"]}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let mut rows = Vec::new();
|
||||||
|
let mut notices = Vec::new();
|
||||||
|
collect(&value, &mut rows, &mut notices);
|
||||||
|
assert_eq!(rows.len(), 2);
|
||||||
|
assert!(notices.is_empty());
|
||||||
|
assert_eq!(rows[0].transport, "http");
|
||||||
|
assert_eq!(rows[1].program.as_deref(), Some("mcp-docs"));
|
||||||
|
|
||||||
|
let flat = serde_json::json!({"solo": {"command": "solo"}});
|
||||||
|
let mut rows = Vec::new();
|
||||||
|
collect(&flat, &mut rows, &mut notices);
|
||||||
|
assert_eq!(rows.len(), 1);
|
||||||
|
assert_eq!(rows[0].program.as_deref(), Some("solo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_non_object_entry_is_a_notice_not_a_row() {
|
||||||
|
let value = serde_json::json!({"servers": {"broken": "nope"}});
|
||||||
|
let mut rows = Vec::new();
|
||||||
|
let mut notices = Vec::new();
|
||||||
|
collect(&value, &mut rows, &mut notices);
|
||||||
|
assert!(rows.is_empty());
|
||||||
|
assert_eq!(notices.len(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,3 +113,6 @@ impl SettingsStore {
|
|||||||
pub const ACTIVE_PROVIDER_KEY: &str = "active_provider";
|
pub const ACTIVE_PROVIDER_KEY: &str = "active_provider";
|
||||||
/// The persisted active model.
|
/// The persisted active model.
|
||||||
pub const ACTIVE_MODEL_KEY: &str = "active_model";
|
pub const ACTIVE_MODEL_KEY: &str = "active_model";
|
||||||
|
/// The persisted skill off switch: a JSON array of folder names. The
|
||||||
|
/// config's `skills_disabled` seeds it; the first settings write owns it.
|
||||||
|
pub const SKILLS_DISABLED_KEY: &str = "skills_disabled";
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
//! The claw's view of skill discovery.
|
||||||
|
//!
|
||||||
|
//! Discovery itself is [`rhema_skills::discover`]: the global directory,
|
||||||
|
//! the workspace's `.rhema/skills`, and the workspace's `.agents/skills`,
|
||||||
|
//! with the same shadowing order. This module only holds the claw's
|
||||||
|
//! policy around it: the configured root, the disabled names, the
|
||||||
|
//! interactive workspace the settings page lists, and the rule that a
|
||||||
|
//! remote sandbox gets no skills because the prompt would name paths the
|
||||||
|
//! remote shell cannot open.
|
||||||
|
//!
|
||||||
|
//! The unfiltered listing serves the settings surface, which shows the
|
||||||
|
//! disabled rows greyed instead of hiding them. The prompt and the
|
||||||
|
//! transcript see the filtered list.
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use rhema_skills::{Skill, SkillTier};
|
||||||
|
|
||||||
|
use crate::settings::{SKILLS_DISABLED_KEY, SettingsError, SettingsStore};
|
||||||
|
|
||||||
|
/// The global skills root and the policy the claw applies to it. One
|
||||||
|
/// catalog is shared by the handlers, the HTTP surface, and the
|
||||||
|
/// settings page; discovery runs per call, so a skill written while the
|
||||||
|
/// daemon runs is live on the next turn and the next page refresh.
|
||||||
|
pub(crate) struct Catalog {
|
||||||
|
root: PathBuf,
|
||||||
|
/// The config's seed. Once [`SKILLS_DISABLED_KEY`] exists, the
|
||||||
|
/// settings store owns the live set.
|
||||||
|
config_disabled: BTreeSet<String>,
|
||||||
|
/// The interactive workspace whose `.rhema/skills` and
|
||||||
|
/// `.agents/skills` tiers the settings page lists.
|
||||||
|
workspace: PathBuf,
|
||||||
|
/// The settings table the runtime toggles persist to.
|
||||||
|
settings: Arc<SettingsStore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Catalog {
|
||||||
|
/// A catalog over `root`, seeded with `disabled`, listing the
|
||||||
|
/// workspace tiers under `workspace`, persisting toggles in
|
||||||
|
/// `settings`.
|
||||||
|
pub(crate) fn new(
|
||||||
|
root: PathBuf,
|
||||||
|
disabled: BTreeSet<String>,
|
||||||
|
workspace: PathBuf,
|
||||||
|
settings: Arc<SettingsStore>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
root,
|
||||||
|
config_disabled: disabled,
|
||||||
|
workspace,
|
||||||
|
settings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The global skills directory.
|
||||||
|
pub(crate) fn root(&self) -> &Path {
|
||||||
|
&self.root
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The workspace whose tiers the settings listing includes.
|
||||||
|
pub(crate) fn workspace(&self) -> &Path {
|
||||||
|
&self.workspace
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The names held back from the prompt and the transcript: the
|
||||||
|
/// settings store's persisted set when it has one, the config seed
|
||||||
|
/// otherwise. A store that cannot be read falls back to the seed
|
||||||
|
/// rather than silently enabling every skill.
|
||||||
|
pub(crate) fn disabled(&self) -> BTreeSet<String> {
|
||||||
|
match self.stored_disabled() {
|
||||||
|
Ok(Some(disabled)) => disabled,
|
||||||
|
Ok(None) => self.config_disabled.clone(),
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("[claw] warning: the skill toggles were not read: {err}");
|
||||||
|
self.config_disabled.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The persisted off switch, `None` while the config seed still
|
||||||
|
/// owns it.
|
||||||
|
fn stored_disabled(&self) -> Result<Option<BTreeSet<String>>, SettingsError> {
|
||||||
|
let Some(raw) = self.settings.get(SKILLS_DISABLED_KEY)? else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
serde_json::from_str(&raw).map(Some).map_err(|err| {
|
||||||
|
eprintln!("[claw] warning: the stored skill toggles do not parse: {err}");
|
||||||
|
SettingsError::Backend(err.to_string())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flips one skill and persists the whole set. Answers the new set
|
||||||
|
/// so the caller can render it without a second read.
|
||||||
|
pub(crate) fn set_enabled(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
enabled: bool,
|
||||||
|
) -> Result<BTreeSet<String>, SettingsError> {
|
||||||
|
let mut disabled = self.disabled();
|
||||||
|
if enabled {
|
||||||
|
disabled.remove(name);
|
||||||
|
} else {
|
||||||
|
disabled.insert(name.to_owned());
|
||||||
|
}
|
||||||
|
let raw = serde_json::to_string(&disabled)
|
||||||
|
.map_err(|err| SettingsError::Backend(err.to_string()))?;
|
||||||
|
self.settings.set(SKILLS_DISABLED_KEY, &raw)?;
|
||||||
|
Ok(disabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Discovers the skills one dispatch may use, minus the disabled
|
||||||
|
/// names. A remote sandbox returns none.
|
||||||
|
pub(crate) fn discover(&self, workspace: &Path, remote: bool) -> Vec<Skill> {
|
||||||
|
if remote {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
let disabled = self.disabled();
|
||||||
|
let mut skills = self.raw(workspace);
|
||||||
|
skills.retain(|skill| !disabled.contains(&skill.name));
|
||||||
|
skills
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every discovered skill, disabled ones included: the settings
|
||||||
|
/// surface's list.
|
||||||
|
pub(crate) fn all(&self) -> Vec<Skill> {
|
||||||
|
self.raw(&self.workspace)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The unfiltered discovery over one workspace.
|
||||||
|
fn raw(&self, workspace: &Path) -> Vec<Skill> {
|
||||||
|
rhema_skills::discover(None, Some(&self.root), workspace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The tier's short name, for the wire and the page. Discovery owns the
|
||||||
|
/// tier; this only spells it.
|
||||||
|
pub(crate) fn tier_label(tier: SkillTier) -> &'static str {
|
||||||
|
match tier {
|
||||||
|
SkillTier::Workspace => "workspace",
|
||||||
|
SkillTier::Global => "global",
|
||||||
|
SkillTier::WorkspaceAgents => "workspace-agents",
|
||||||
|
SkillTier::HomeAgents => "home-agents",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn write_skill(dir: &Path, name: &str, description: &str) {
|
||||||
|
let folder = dir.join(name);
|
||||||
|
std::fs::create_dir_all(&folder).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
folder.join("SKILL.md"),
|
||||||
|
format!("---\ndescription: {description}\n---\n\nBody.\n"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn discovery_reads_the_global_and_workspace_tiers_and_filters_disabled() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let global = dir.path().join("global");
|
||||||
|
let workspace = dir.path().join("workspace");
|
||||||
|
std::fs::create_dir_all(&global).unwrap();
|
||||||
|
std::fs::create_dir_all(&workspace).unwrap();
|
||||||
|
write_skill(&global, "unslop", "Always apply.");
|
||||||
|
write_skill(&global, "commit-message", "Triggers when committing.");
|
||||||
|
write_skill(
|
||||||
|
&workspace.join(".rhema").join("skills"),
|
||||||
|
"project",
|
||||||
|
"The workspace tier.",
|
||||||
|
);
|
||||||
|
|
||||||
|
let disabled = BTreeSet::from(["unslop".to_owned()]);
|
||||||
|
let catalog = Catalog::new(
|
||||||
|
global,
|
||||||
|
disabled,
|
||||||
|
workspace.clone(),
|
||||||
|
Arc::new(SettingsStore::in_memory().unwrap()),
|
||||||
|
);
|
||||||
|
let names: Vec<_> = catalog
|
||||||
|
.discover(&workspace, false)
|
||||||
|
.into_iter()
|
||||||
|
.map(|skill| skill.name)
|
||||||
|
.collect();
|
||||||
|
assert_eq!(names, ["commit-message", "project"]);
|
||||||
|
|
||||||
|
// The settings listing keeps the disabled row.
|
||||||
|
let all: Vec<_> = catalog.all().into_iter().map(|skill| skill.name).collect();
|
||||||
|
assert_eq!(all, ["commit-message", "project", "unslop"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_remote_sandbox_gets_no_skills() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let global = dir.path().join("global");
|
||||||
|
std::fs::create_dir_all(&global).unwrap();
|
||||||
|
write_skill(&global, "unslop", "Always apply.");
|
||||||
|
let catalog = Catalog::new(
|
||||||
|
global,
|
||||||
|
BTreeSet::new(),
|
||||||
|
dir.path().to_path_buf(),
|
||||||
|
Arc::new(SettingsStore::in_memory().unwrap()),
|
||||||
|
);
|
||||||
|
assert!(catalog.discover(dir.path(), true).is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tiers_spell_their_short_names() {
|
||||||
|
assert_eq!(tier_label(SkillTier::Workspace), "workspace");
|
||||||
|
assert_eq!(tier_label(SkillTier::Global), "global");
|
||||||
|
assert_eq!(tier_label(SkillTier::WorkspaceAgents), "workspace-agents");
|
||||||
|
assert_eq!(tier_label(SkillTier::HomeAgents), "home-agents");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
//! The claw's view of subagent definitions.
|
||||||
|
//!
|
||||||
|
//! Discovery belongs to [`rhema_subagents::discover`]: the built-in
|
||||||
|
//! `general-purpose` definition, the global directory, and the
|
||||||
|
//! workspace's `.rhema/subagents`, with the same shadowing order. This
|
||||||
|
//! module holds the claw's policy around it — the configured root and
|
||||||
|
//! the persisted disabled names — and the two places a frontend meets
|
||||||
|
//! the extension: the prompt's tool specs and the `HostAgentConfig`
|
||||||
|
//! wire.
|
||||||
|
//!
|
||||||
|
//! The wire's own `subagent_base_system` treats a verbatim
|
||||||
|
//! `HostAgentConfig::system` as a total replacement. The claw renders
|
||||||
|
//! its parent prompt that way, so [`Catalog::wire`] clears the field for
|
||||||
|
//! the duration of the wire: a subagent then gets the toolkit's stamped
|
||||||
|
//! prompt, its parent's skills, environment, and user preferences, not
|
||||||
|
//! the parent's chat persona. The parent's prompt is restored before
|
||||||
|
//! the caller sees the config.
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use rhema_core::ToolSpec;
|
||||||
|
use rhema_host_agent::HostAgentConfig;
|
||||||
|
use rhema_subagents::{SubagentDef, SubagentHandle};
|
||||||
|
|
||||||
|
/// The definition root and the names held back from the wire.
|
||||||
|
pub(crate) struct Catalog {
|
||||||
|
root: PathBuf,
|
||||||
|
disabled: BTreeSet<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Catalog {
|
||||||
|
/// A catalog over `root`, holding back `disabled`.
|
||||||
|
pub(crate) fn new(root: PathBuf, disabled: BTreeSet<String>) -> Self {
|
||||||
|
Self { root, disabled }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every discovered definition, disabled ones included: the shape a
|
||||||
|
/// future settings surface lists. Discovery runs per call, so a
|
||||||
|
/// definition written while the daemon runs is live on the next
|
||||||
|
/// turn.
|
||||||
|
pub(crate) fn all(&self, workspace: &Path) -> Vec<SubagentDef> {
|
||||||
|
rhema_subagents::discover(Some(&self.root), workspace)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The definitions one dispatch may use, minus the disabled names.
|
||||||
|
pub(crate) fn discover(&self, workspace: &Path) -> Vec<SubagentDef> {
|
||||||
|
let mut definitions = self.all(workspace);
|
||||||
|
definitions.retain(|definition| !self.disabled.contains(&definition.name));
|
||||||
|
definitions
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `subagent` tool spec the dispatch's prompt must list. Empty
|
||||||
|
/// when every definition, the built-in included, is disabled: the
|
||||||
|
/// wire drops the tool whole in that case, and a prompt that
|
||||||
|
/// advertised it would name a tool the request does not carry.
|
||||||
|
pub(crate) fn specs(&self, workspace: &Path) -> Vec<ToolSpec> {
|
||||||
|
let definitions = self.discover(workspace);
|
||||||
|
if definitions.is_empty() {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
vec![rhema_subagents::SubagentTools::spec(&definitions, &[])]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attaches the `subagent` tool, steering, and shared shell to
|
||||||
|
/// `config`, returning the registry handle. The parent's system
|
||||||
|
/// prompt is parked while the wire stamps the subagent prompt, then
|
||||||
|
/// restored unchanged.
|
||||||
|
pub(crate) fn wire(&self, config: &mut HostAgentConfig) -> SubagentHandle {
|
||||||
|
config.disabled_subagents = self.disabled.clone();
|
||||||
|
let parent = config.system.take();
|
||||||
|
let handle = rhema_subagents::wire_at(Some(&self.root), config);
|
||||||
|
config.system = parent;
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn write_definition(dir: &Path, name: &str, description: &str) {
|
||||||
|
let folder = dir.join(name);
|
||||||
|
std::fs::create_dir_all(&folder).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
folder.join(rhema_subagents::def::FILE),
|
||||||
|
format!("---\ndescription: {description}\n---\n\nBody.\n"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn discovery_reads_the_global_tier_and_filters_disabled() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let root = dir.path().join("subagents");
|
||||||
|
let workspace = dir.path().join("workspace");
|
||||||
|
std::fs::create_dir_all(&root).unwrap();
|
||||||
|
std::fs::create_dir_all(&workspace).unwrap();
|
||||||
|
write_definition(&root, "reviewer", "reviews diffs");
|
||||||
|
|
||||||
|
let catalog = Catalog::new(root, BTreeSet::from(["reviewer".to_owned()]));
|
||||||
|
let names: Vec<_> = catalog
|
||||||
|
.discover(&workspace)
|
||||||
|
.into_iter()
|
||||||
|
.map(|definition| definition.name)
|
||||||
|
.collect();
|
||||||
|
assert_eq!(names, ["general-purpose"]);
|
||||||
|
assert!(
|
||||||
|
catalog.specs(&workspace)[0]
|
||||||
|
.description
|
||||||
|
.contains("general-purpose")
|
||||||
|
);
|
||||||
|
|
||||||
|
// The unfiltered listing keeps the disabled row.
|
||||||
|
let all: Vec<_> = catalog
|
||||||
|
.all(&workspace)
|
||||||
|
.into_iter()
|
||||||
|
.map(|definition| definition.name)
|
||||||
|
.collect();
|
||||||
|
assert_eq!(all, ["general-purpose", "reviewer"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn disabling_everything_leaves_no_spec() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let workspace = dir.path().join("workspace");
|
||||||
|
std::fs::create_dir_all(&workspace).unwrap();
|
||||||
|
let catalog = Catalog::new(
|
||||||
|
dir.path().join("subagents"),
|
||||||
|
BTreeSet::from(["general-purpose".to_owned()]),
|
||||||
|
);
|
||||||
|
assert!(catalog.specs(&workspace).is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,6 +95,10 @@ fn config(dir: &tempfile::TempDir) -> ClawConfig {
|
|||||||
ingest_token: None,
|
ingest_token: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
git: None,
|
git: None,
|
||||||
|
skills_root: Some(dir.path().join("skills")),
|
||||||
|
skills_disabled: std::collections::BTreeSet::new(),
|
||||||
|
subagents_root: None,
|
||||||
|
disabled_subagents: std::collections::BTreeSet::new(),
|
||||||
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ fn config(dir: &tempfile::TempDir) -> ClawConfig {
|
|||||||
ingest_token: None,
|
ingest_token: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
git: None,
|
git: None,
|
||||||
|
skills_root: Some(dir.path().join("skills")),
|
||||||
|
skills_disabled: std::collections::BTreeSet::new(),
|
||||||
|
subagents_root: None,
|
||||||
|
disabled_subagents: std::collections::BTreeSet::new(),
|
||||||
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ fn config(dir: &tempfile::TempDir, token: Option<&str>) -> ClawConfig {
|
|||||||
transcript: None,
|
transcript: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
git: None,
|
git: None,
|
||||||
|
skills_root: Some(dir.path().join("skills")),
|
||||||
|
skills_disabled: std::collections::BTreeSet::new(),
|
||||||
|
subagents_root: None,
|
||||||
|
disabled_subagents: std::collections::BTreeSet::new(),
|
||||||
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2533,6 +2537,239 @@ async fn providers_gain_and_lose_backends_over_the_surface() {
|
|||||||
assert_eq!(gone.status(), 400);
|
assert_eq!(gone.status(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The skills surface: every discovered skill rides the listing with
|
||||||
|
/// its trigger, path, and tier; a disabled name keeps its row and says
|
||||||
|
/// so. Discovery reads the disk per request.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn installed_skills_are_listed_with_their_state() {
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
let mut config = config(&dir, None);
|
||||||
|
let root = config
|
||||||
|
.skills_root
|
||||||
|
.clone()
|
||||||
|
.expect("the test config names a root");
|
||||||
|
let folder = root.join("local-skill");
|
||||||
|
std::fs::create_dir_all(&folder).expect("skill folder");
|
||||||
|
std::fs::write(
|
||||||
|
folder.join("SKILL.md"),
|
||||||
|
"---\ndescription: A local skill.\n---\n\nBody.\n",
|
||||||
|
)
|
||||||
|
.expect("skill file");
|
||||||
|
config.skills_disabled = std::collections::BTreeSet::from(["local-skill".to_owned()]);
|
||||||
|
let daemon = Daemon::build(
|
||||||
|
&config,
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
rhema_rsd::DispatcherConfig::default(),
|
||||||
|
)
|
||||||
|
.expect("the daemon assembles");
|
||||||
|
let base = serve(&daemon).await;
|
||||||
|
let body: Value = reqwest::Client::new()
|
||||||
|
.get(format!("{base}/v1/skills"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the skills read")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the skills parse");
|
||||||
|
|
||||||
|
assert_eq!(body["root"], root.display().to_string());
|
||||||
|
assert_eq!(body["disabled"], json!(["local-skill"]));
|
||||||
|
let skills = body["skills"].as_array().expect("the list reads");
|
||||||
|
let names: Vec<&str> = skills
|
||||||
|
.iter()
|
||||||
|
.filter_map(|skill| skill["name"].as_str())
|
||||||
|
.collect();
|
||||||
|
assert!(names.contains(&"commit-message"), "{names:?}");
|
||||||
|
assert!(names.contains(&"unslop"), "{names:?}");
|
||||||
|
|
||||||
|
let local = skills
|
||||||
|
.iter()
|
||||||
|
.find(|skill| skill["name"] == "local-skill")
|
||||||
|
.expect("the disabled row is kept");
|
||||||
|
assert_eq!(local["description"], "A local skill.");
|
||||||
|
assert_eq!(local["tier"], "global");
|
||||||
|
assert_eq!(local["enabled"], false);
|
||||||
|
assert!(
|
||||||
|
local["path"]
|
||||||
|
.as_str()
|
||||||
|
.is_some_and(|path| path.ends_with("local-skill/SKILL.md")),
|
||||||
|
"{local}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A skill toggle writes the settings table, not claw.yaml: the row
|
||||||
|
/// flips, the seed still lists it, and a rebuilt daemon reads the same
|
||||||
|
/// persisted set.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_skill_toggle_persists_across_a_rebuild() {
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
let config = config(&dir, None);
|
||||||
|
let daemon = Daemon::build(
|
||||||
|
&config,
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
rhema_rsd::DispatcherConfig::default(),
|
||||||
|
)
|
||||||
|
.expect("the daemon assembles");
|
||||||
|
let base = serve(&daemon).await;
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.put(format!("{base}/v1/skills/unslop"))
|
||||||
|
.json(&json!({"enabled": false}))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the toggle goes out");
|
||||||
|
assert_eq!(response.status(), 200);
|
||||||
|
let body: Value = response.json().await.expect("the toggle parses");
|
||||||
|
assert_eq!(body["name"], "unslop");
|
||||||
|
assert_eq!(body["enabled"], false);
|
||||||
|
assert!(
|
||||||
|
body["disabled"]
|
||||||
|
.as_array()
|
||||||
|
.is_some_and(|names| names.iter().any(|name| name == "unslop")),
|
||||||
|
"{body}"
|
||||||
|
);
|
||||||
|
|
||||||
|
let listed: Value = client
|
||||||
|
.get(format!("{base}/v1/skills"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the listing reads")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the listing parses");
|
||||||
|
let unslop = listed["skills"]
|
||||||
|
.as_array()
|
||||||
|
.expect("the list reads")
|
||||||
|
.iter()
|
||||||
|
.find(|skill| skill["name"] == "unslop")
|
||||||
|
.expect("the bundled skill is seeded");
|
||||||
|
assert_eq!(unslop["enabled"], false);
|
||||||
|
drop(daemon);
|
||||||
|
|
||||||
|
// A rebuild over the same database sees the persisted set.
|
||||||
|
let daemon = Daemon::build(
|
||||||
|
&config,
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
rhema_rsd::DispatcherConfig::default(),
|
||||||
|
)
|
||||||
|
.expect("the daemon rebuilds");
|
||||||
|
let base = serve(&daemon).await;
|
||||||
|
let persisted: Value = reqwest::Client::new()
|
||||||
|
.get(format!("{base}/v1/skills"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the second listing reads")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the second listing parses");
|
||||||
|
assert!(
|
||||||
|
persisted["disabled"]
|
||||||
|
.as_array()
|
||||||
|
.is_some_and(|names| names.iter().any(|name| name == "unslop")),
|
||||||
|
"{persisted}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bootstrap editor reads all three documents and writes the two
|
||||||
|
/// editable ones; the generated environment report is refused.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_bootstrap_editor_reads_and_saves_the_identity_files() {
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
let daemon = Daemon::build(
|
||||||
|
&config(&dir, None),
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
rhema_rsd::DispatcherConfig::default(),
|
||||||
|
)
|
||||||
|
.expect("the daemon assembles");
|
||||||
|
let base = serve(&daemon).await;
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
let body: Value = client
|
||||||
|
.get(format!("{base}/v1/bootstrap/files"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the files read")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the files parse");
|
||||||
|
let files = body["files"].as_array().expect("the files list reads");
|
||||||
|
assert_eq!(files.len(), 3);
|
||||||
|
let soul = files
|
||||||
|
.iter()
|
||||||
|
.find(|file| file["kind"] == "soul")
|
||||||
|
.expect("soul is listed");
|
||||||
|
assert_eq!(soul["name"], "SOUL.md");
|
||||||
|
assert_eq!(soul["content"], Value::Null);
|
||||||
|
assert_eq!(soul["generated"], false);
|
||||||
|
let environment = files
|
||||||
|
.iter()
|
||||||
|
.find(|file| file["kind"] == "environment")
|
||||||
|
.expect("environment is listed");
|
||||||
|
assert_eq!(environment["generated"], true);
|
||||||
|
|
||||||
|
let saved = client
|
||||||
|
.put(format!("{base}/v1/bootstrap/soul"))
|
||||||
|
.json(&json!({"content": "I am claw: terse."}))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the write goes out");
|
||||||
|
assert_eq!(saved.status(), 200);
|
||||||
|
|
||||||
|
let after: Value = client
|
||||||
|
.get(format!("{base}/v1/bootstrap/files"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the files re-read")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the files re-parse");
|
||||||
|
let soul = after["files"]
|
||||||
|
.as_array()
|
||||||
|
.expect("the list reads")
|
||||||
|
.iter()
|
||||||
|
.find(|file| file["kind"] == "soul")
|
||||||
|
.expect("soul is listed");
|
||||||
|
assert_eq!(soul["content"], "I am claw: terse.");
|
||||||
|
|
||||||
|
let refused = client
|
||||||
|
.put(format!("{base}/v1/bootstrap/environment"))
|
||||||
|
.json(&json!({"content": "overwritten"}))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the refused write goes out");
|
||||||
|
assert_eq!(refused.status(), 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The MCP page reads the client's file without exposing credentials
|
||||||
|
/// and stays behind the same bearer check as every /v1 route.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_mcp_page_reads_the_client_config() {
|
||||||
|
let dir = tempfile::tempdir().expect("tempdir");
|
||||||
|
let daemon = Daemon::build(
|
||||||
|
&config(&dir, None),
|
||||||
|
mock_registry(Arc::new(MockProvider::new([reply("on it")]))),
|
||||||
|
rhema_rsd::DispatcherConfig::default(),
|
||||||
|
)
|
||||||
|
.expect("the daemon assembles");
|
||||||
|
let base = serve(&daemon).await;
|
||||||
|
let body: Value = reqwest::Client::new()
|
||||||
|
.get(format!("{base}/v1/mcp"))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("the mcp read")
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.expect("the mcp body parses");
|
||||||
|
assert!(
|
||||||
|
body["config"]
|
||||||
|
.as_str()
|
||||||
|
.is_some_and(|path| path.ends_with("mcp/config.json"))
|
||||||
|
);
|
||||||
|
assert!(body["servers"].is_array());
|
||||||
|
assert!(body["notices"].is_array());
|
||||||
|
}
|
||||||
|
|
||||||
/// The sandbox surface: the default is this host, a remote choice
|
/// The sandbox surface: the default is this host, a remote choice
|
||||||
/// persists across a rebuild, the token is write-only, and a choice
|
/// persists across a rebuild, the token is write-only, and a choice
|
||||||
/// without a URL or with an unknown kind is refused.
|
/// without a URL or with an unknown kind is refused.
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ fn config(dir: &tempfile::TempDir) -> ClawConfig {
|
|||||||
ingest_token: None,
|
ingest_token: None,
|
||||||
sandbox: None,
|
sandbox: None,
|
||||||
git: None,
|
git: None,
|
||||||
|
skills_root: Some(dir.path().join("skills")),
|
||||||
|
skills_disabled: std::collections::BTreeSet::new(),
|
||||||
|
subagents_root: None,
|
||||||
|
disabled_subagents: std::collections::BTreeSet::new(),
|
||||||
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
disabled_mcp_servers: std::collections::BTreeSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import { ClawError, clawHealth, isInteractive, isResidentKey, useClaw } from '~/
|
|||||||
import type {
|
import type {
|
||||||
AgentIdentity,
|
AgentIdentity,
|
||||||
AgentImageKind,
|
AgentImageKind,
|
||||||
|
BootstrapFiles,
|
||||||
ClawAccount,
|
ClawAccount,
|
||||||
ClawSession,
|
ClawSession,
|
||||||
ConsentAnswer,
|
ConsentAnswer,
|
||||||
|
McpState,
|
||||||
IdentityTexts,
|
IdentityTexts,
|
||||||
ModelCard,
|
ModelCard,
|
||||||
NewAccount,
|
NewAccount,
|
||||||
@@ -19,6 +21,7 @@ import type {
|
|||||||
ProvidersState,
|
ProvidersState,
|
||||||
SandboxSelection,
|
SandboxSelection,
|
||||||
SandboxState,
|
SandboxState,
|
||||||
|
SkillsState,
|
||||||
StreamStatus,
|
StreamStatus,
|
||||||
} from '~/composables/useClaw'
|
} from '~/composables/useClaw'
|
||||||
import { composeChips, useTranscript } from '~/composables/useTranscript'
|
import { composeChips, useTranscript } from '~/composables/useTranscript'
|
||||||
@@ -56,6 +59,7 @@ const SETTINGS_SECTIONS: { label: string; entries: { id: string; label: string }
|
|||||||
label: 'Agent',
|
label: 'Agent',
|
||||||
entries: [
|
entries: [
|
||||||
{ id: 'agent/general', label: 'General' },
|
{ id: 'agent/general', label: 'General' },
|
||||||
|
{ id: 'agent/bootstrap', label: 'Bootstrap' },
|
||||||
{ id: 'agent/accounts', label: 'Accounts' },
|
{ id: 'agent/accounts', label: 'Accounts' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -63,6 +67,8 @@ const SETTINGS_SECTIONS: { label: string; entries: { id: string; label: string }
|
|||||||
{
|
{
|
||||||
label: 'System',
|
label: 'System',
|
||||||
entries: [
|
entries: [
|
||||||
|
{ id: 'skills', label: 'Skills' },
|
||||||
|
{ id: 'mcp', label: 'MCP' },
|
||||||
{ id: 'sandbox', label: 'Sandbox' },
|
{ id: 'sandbox', label: 'Sandbox' },
|
||||||
{ id: 'about', label: 'About' },
|
{ id: 'about', label: 'About' },
|
||||||
],
|
],
|
||||||
@@ -288,6 +294,14 @@ const accountsLoading = ref(false)
|
|||||||
const mutatingAccounts = ref(false)
|
const mutatingAccounts = ref(false)
|
||||||
const sandboxState = ref<SandboxState | null>(null)
|
const sandboxState = ref<SandboxState | null>(null)
|
||||||
const savingSandbox = ref(false)
|
const savingSandbox = ref(false)
|
||||||
|
const skillsState = ref<SkillsState | null>(null)
|
||||||
|
const skillsLoading = ref(false)
|
||||||
|
const skillsSaving = ref<string | null>(null)
|
||||||
|
const bootstrapFiles = ref<BootstrapFiles | null>(null)
|
||||||
|
const bootstrapLoading = ref(false)
|
||||||
|
const bootstrapSaving = ref<string | null>(null)
|
||||||
|
const mcpState = ref<McpState | null>(null)
|
||||||
|
const mcpLoading = ref(false)
|
||||||
const streamStatus = ref<StreamStatus>('connecting')
|
const streamStatus = ref<StreamStatus>('connecting')
|
||||||
const busy = ref(false)
|
const busy = ref(false)
|
||||||
const authRequired = ref(false)
|
const authRequired = ref(false)
|
||||||
@@ -572,6 +586,70 @@ async function removeProvider(id: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshSkills(): Promise<void> {
|
||||||
|
skillsLoading.value = true
|
||||||
|
try {
|
||||||
|
skillsState.value = await claw.skills()
|
||||||
|
apiError.value = null
|
||||||
|
} catch (err) {
|
||||||
|
noteApiError(err)
|
||||||
|
} finally {
|
||||||
|
skillsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleSkill(name: string, enabled: boolean): Promise<void> {
|
||||||
|
skillsSaving.value = name
|
||||||
|
try {
|
||||||
|
await claw.setSkillEnabled(name, enabled)
|
||||||
|
await refreshSkills()
|
||||||
|
pushNotice(`${name} ${enabled ? 'enabled' : 'disabled'}`)
|
||||||
|
apiError.value = null
|
||||||
|
} catch (err) {
|
||||||
|
noteApiError(err)
|
||||||
|
} finally {
|
||||||
|
skillsSaving.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshBootstrap(): Promise<void> {
|
||||||
|
bootstrapLoading.value = true
|
||||||
|
try {
|
||||||
|
bootstrapFiles.value = await claw.bootstrapFiles()
|
||||||
|
apiError.value = null
|
||||||
|
} catch (err) {
|
||||||
|
noteApiError(err)
|
||||||
|
} finally {
|
||||||
|
bootstrapLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveBootstrapFile(kind: string, content: string): Promise<void> {
|
||||||
|
bootstrapSaving.value = kind
|
||||||
|
try {
|
||||||
|
await claw.saveBootstrap(kind, content)
|
||||||
|
await refreshBootstrap()
|
||||||
|
pushNotice(`${kind === 'soul' ? 'SOUL.md' : 'USER.md'} saved`)
|
||||||
|
apiError.value = null
|
||||||
|
} catch (err) {
|
||||||
|
noteApiError(err)
|
||||||
|
} finally {
|
||||||
|
bootstrapSaving.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshMcp(): Promise<void> {
|
||||||
|
mcpLoading.value = true
|
||||||
|
try {
|
||||||
|
mcpState.value = await claw.mcp()
|
||||||
|
apiError.value = null
|
||||||
|
} catch (err) {
|
||||||
|
noteApiError(err)
|
||||||
|
} finally {
|
||||||
|
mcpLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function refreshSandbox(): Promise<void> {
|
async function refreshSandbox(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
sandboxState.value = await claw.sandbox()
|
sandboxState.value = await claw.sandbox()
|
||||||
@@ -691,6 +769,9 @@ function saveToken(): void {
|
|||||||
void refreshSessions()
|
void refreshSessions()
|
||||||
void refreshIdentity()
|
void refreshIdentity()
|
||||||
void refreshAccounts()
|
void refreshAccounts()
|
||||||
|
void refreshSkills()
|
||||||
|
void refreshBootstrap()
|
||||||
|
void refreshMcp()
|
||||||
void refreshSandbox()
|
void refreshSandbox()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,6 +898,9 @@ onMounted(() => {
|
|||||||
void refreshIdentity()
|
void refreshIdentity()
|
||||||
void refreshProviders()
|
void refreshProviders()
|
||||||
void refreshAccounts()
|
void refreshAccounts()
|
||||||
|
void refreshSkills()
|
||||||
|
void refreshBootstrap()
|
||||||
|
void refreshMcp()
|
||||||
void refreshSandbox()
|
void refreshSandbox()
|
||||||
void refreshSessions()
|
void refreshSessions()
|
||||||
healthTimer = setInterval(checkHealth, 30000)
|
healthTimer = setInterval(checkHealth, 30000)
|
||||||
@@ -954,6 +1038,28 @@ onUnmounted(() => {
|
|||||||
@add="addProvider"
|
@add="addProvider"
|
||||||
@remove="removeProvider"
|
@remove="removeProvider"
|
||||||
/>
|
/>
|
||||||
|
<SettingsSkillsPage
|
||||||
|
v-show="route.section === 'skills'"
|
||||||
|
:state="skillsState"
|
||||||
|
:loading="skillsLoading"
|
||||||
|
:saving="skillsSaving"
|
||||||
|
@refresh="refreshSkills"
|
||||||
|
@toggle="toggleSkill"
|
||||||
|
/>
|
||||||
|
<SettingsBootstrapPage
|
||||||
|
v-show="route.section === 'agent/bootstrap'"
|
||||||
|
:state="bootstrapFiles"
|
||||||
|
:loading="bootstrapLoading"
|
||||||
|
:saving="bootstrapSaving"
|
||||||
|
@refresh="refreshBootstrap"
|
||||||
|
@save="saveBootstrapFile"
|
||||||
|
/>
|
||||||
|
<SettingsMcpPage
|
||||||
|
v-show="route.section === 'mcp'"
|
||||||
|
:state="mcpState"
|
||||||
|
:loading="mcpLoading"
|
||||||
|
@refresh="refreshMcp"
|
||||||
|
/>
|
||||||
<SettingsSandboxPage
|
<SettingsSandboxPage
|
||||||
v-show="route.section === 'sandbox'"
|
v-show="route.section === 'sandbox'"
|
||||||
:state="sandboxState"
|
:state="sandboxState"
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ const routes = [
|
|||||||
{ method: 'PUT', path: '/v1/providers/{kind}/credentials', note: 'add a backend or replace its login' },
|
{ method: 'PUT', path: '/v1/providers/{kind}/credentials', note: 'add a backend or replace its login' },
|
||||||
{ method: 'DELETE', path: '/v1/providers/{kind}', note: 'drop a backend from the roster' },
|
{ method: 'DELETE', path: '/v1/providers/{kind}', note: 'drop a backend from the roster' },
|
||||||
{ method: 'GET', path: '/v1/providers/{kind}/models', note: "a kind's live model listing" },
|
{ method: 'GET', path: '/v1/providers/{kind}/models', note: "a kind's live model listing" },
|
||||||
|
{ method: 'GET', path: '/v1/bootstrap/files', note: 'the identity documents, live' },
|
||||||
|
{ method: 'PUT', path: '/v1/bootstrap/{kind}', note: 'save SOUL.md or USER.md' },
|
||||||
|
{ method: 'GET', path: '/v1/skills', note: "installed skills, triggers, and paths" },
|
||||||
|
{ method: 'PUT', path: '/v1/skills/{name}', note: "flip one skill's off switch" },
|
||||||
|
{ method: 'GET', path: '/v1/mcp', note: "the MCP client's servers and mute set" },
|
||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,204 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// The Bootstrap page: the three identity documents the resident prompt
|
||||||
|
// renders, editable in place. SOUL.md and USER.md save as whole files;
|
||||||
|
// ENVIRONMENT.md is generated at every boot, so its editor is read-only
|
||||||
|
// and says so. Presentational: data flows in as props, intent flows up
|
||||||
|
// as events.
|
||||||
|
import type { BootstrapFile, BootstrapFiles } from '~/composables/useClaw'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
state: BootstrapFiles | null
|
||||||
|
loading: boolean
|
||||||
|
/** The kind whose save is in flight. */
|
||||||
|
saving: string | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
refresh: []
|
||||||
|
save: [kind: string, content: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// 16 KiB, the same cap bootstrap_save enforces in the daemon.
|
||||||
|
const CAP = 16 * 1024
|
||||||
|
|
||||||
|
const drafts = reactive<Record<string, string>>({})
|
||||||
|
|
||||||
|
function sync(): void {
|
||||||
|
const state = props.state
|
||||||
|
if (!state) return
|
||||||
|
for (const file of state.files) {
|
||||||
|
drafts[file.kind] = file.content ?? ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The page's only refresh is explicit, so a state arrival always wins:
|
||||||
|
// there is no background poll that could overwrite a live edit.
|
||||||
|
watch(() => props.state, sync, { immediate: true })
|
||||||
|
|
||||||
|
function dirty(file: BootstrapFile): boolean {
|
||||||
|
return (drafts[file.kind] ?? '') !== (file.content ?? '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function discard(file: BootstrapFile): void {
|
||||||
|
drafts[file.kind] = file.content ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(file: BootstrapFile): void {
|
||||||
|
if (file.generated || props.saving || !dirty(file)) return
|
||||||
|
emit('save', file.kind, drafts[file.kind] ?? '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function size(file: BootstrapFile): number {
|
||||||
|
return new TextEncoder().encode(drafts[file.kind] ?? '').length
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="page">
|
||||||
|
<PageHeader title="Bootstrap" subtitle="The identity files every turn renders.">
|
||||||
|
<template #actions>
|
||||||
|
<button :disabled="loading" @click="$emit('refresh')">
|
||||||
|
{{ loading ? 'Refreshing…' : 'Refresh' }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="scroll">
|
||||||
|
<p v-if="!state" class="muted">loading bootstrap…</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<AppCallout variant="info" title="These files enter every request">
|
||||||
|
SOUL.md is who the agent is; USER.md is who you are. Keep both
|
||||||
|
small — they are read on every turn. ENVIRONMENT.md is written
|
||||||
|
from the machine at boot.
|
||||||
|
</AppCallout>
|
||||||
|
|
||||||
|
<SettingCard
|
||||||
|
v-for="file in state.files"
|
||||||
|
:key="file.kind"
|
||||||
|
:title="file.name"
|
||||||
|
:meta="file.generated ? 'generated at boot' : file.exists ? 'present' : 'missing'"
|
||||||
|
>
|
||||||
|
<div class="editor">
|
||||||
|
<textarea
|
||||||
|
v-model="drafts[file.kind]"
|
||||||
|
class="mono"
|
||||||
|
rows="10"
|
||||||
|
spellcheck="false"
|
||||||
|
:readonly="file.generated"
|
||||||
|
:disabled="saving === file.kind"
|
||||||
|
:aria-label="`${file.name} content`"
|
||||||
|
/>
|
||||||
|
<div class="editor-foot">
|
||||||
|
<span class="hint">
|
||||||
|
<template v-if="file.generated">
|
||||||
|
Rewritten at every boot; edit the template, not this file.
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
{{ size(file) }} of {{ CAP }} bytes
|
||||||
|
<span v-if="size(file) > CAP" class="over">over the cap</span>
|
||||||
|
</template>
|
||||||
|
</span>
|
||||||
|
<span class="actions">
|
||||||
|
<button
|
||||||
|
v-if="!file.generated"
|
||||||
|
:disabled="!dirty(file) || saving === file.kind"
|
||||||
|
@click="discard(file)"
|
||||||
|
>
|
||||||
|
Discard
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="!file.generated"
|
||||||
|
class="primary"
|
||||||
|
:disabled="!dirty(file) || saving === file.kind || size(file) > CAP"
|
||||||
|
@click="save(file)"
|
||||||
|
>
|
||||||
|
{{ saving === file.kind ? 'Saving…' : 'Save' }}
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SettingCard>
|
||||||
|
|
||||||
|
<p class="footnote">
|
||||||
|
The agent can also write SOUL.md and USER.md through its
|
||||||
|
<code>bootstrap_save</code> tool. Both paths land in the same
|
||||||
|
store, so the next turn sees either.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroll {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0 24px 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
max-width: 900px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 180px;
|
||||||
|
resize: vertical;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-size: 12.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea[readonly] {
|
||||||
|
color: var(--text2);
|
||||||
|
background: var(--sunken);
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-foot {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hint {
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.over {
|
||||||
|
color: var(--error);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footnote {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 2px;
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// The MCP page: the standalone client's configured servers and the
|
||||||
|
// names claw.yaml mutes. Read-only by design — the config file belongs
|
||||||
|
// to the client, and the claw only names it through MCP_CONFIG.
|
||||||
|
import type { McpState } from '~/composables/useClaw'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
state: McpState | null
|
||||||
|
loading: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
defineEmits<{ refresh: [] }>()
|
||||||
|
|
||||||
|
// The missing-file line is the callout's job; every other notice is a
|
||||||
|
// parse or shape problem worth its own warn.
|
||||||
|
const notices = computed(() =>
|
||||||
|
(props.state?.notices ?? []).filter((notice) => !notice.startsWith('no MCP config file')),
|
||||||
|
)
|
||||||
|
|
||||||
|
const TRANSPORTS: Record<string, string> = {
|
||||||
|
stdio: 'local process',
|
||||||
|
http: 'HTTP',
|
||||||
|
unknown: 'unrecognized',
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="page">
|
||||||
|
<PageHeader title="MCP" subtitle="Servers the agent's shell can call.">
|
||||||
|
<template #actions>
|
||||||
|
<button :disabled="loading" @click="$emit('refresh')">
|
||||||
|
{{ loading ? 'Refreshing…' : 'Refresh' }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="scroll">
|
||||||
|
<p v-if="!state" class="muted">loading MCP servers…</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<AppCallout v-if="!state.exists" variant="info" title="No MCP config file">
|
||||||
|
The client has no servers configured at
|
||||||
|
<span class="mono">{{ state.config }}</span>. Add a
|
||||||
|
<code>servers</code> object there, then refresh.
|
||||||
|
</AppCallout>
|
||||||
|
|
||||||
|
<AppCallout
|
||||||
|
v-for="notice in notices"
|
||||||
|
:key="notice"
|
||||||
|
variant="warn"
|
||||||
|
title="MCP config"
|
||||||
|
>
|
||||||
|
{{ notice }}
|
||||||
|
</AppCallout>
|
||||||
|
|
||||||
|
<SettingCard
|
||||||
|
title="Servers"
|
||||||
|
:meta="`${state.servers.length} configured${state.disabled.length ? `, ${state.disabled.length} muted` : ''}`"
|
||||||
|
>
|
||||||
|
<p v-if="state.servers.length === 0 && state.exists" class="empty">
|
||||||
|
The config exists but holds no servers.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div v-for="server in state.servers" :key="server.name" class="server">
|
||||||
|
<div class="server-head">
|
||||||
|
<span class="server-name mono">{{ server.name }}</span>
|
||||||
|
<span class="server-transport">{{ TRANSPORTS[server.transport] }}</span>
|
||||||
|
<span class="server-state" :class="{ off: state.disabled.includes(server.name) }">
|
||||||
|
{{ state.disabled.includes(server.name) ? 'muted' : 'active' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p v-if="server.description" class="server-description">{{ server.description }}</p>
|
||||||
|
<p v-if="server.program" class="server-program mono">{{ server.program }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingCard>
|
||||||
|
|
||||||
|
<p class="footnote">
|
||||||
|
Config: <span class="mono">{{ state.config }}</span>.
|
||||||
|
Mutes: <code>disabled_mcp_servers</code> in <code>claw.yaml</code>.
|
||||||
|
The page is read-only; the client owns the file.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroll {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0 24px 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
max-width: 860px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
margin: 0;
|
||||||
|
padding: 13px 16px;
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.server {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-name {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-transport {
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-state {
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--ok);
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-state.off {
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-description {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--text2);
|
||||||
|
font-size: 12.5px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.server-program {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 11.5px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footnote {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 2px;
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// The Skills page: what discovery finds for the chat workspace, what
|
||||||
|
// each skill's trigger is, and its on/off switch. Toggles persist in
|
||||||
|
// the daemon's settings table, so a row flips without editing config.
|
||||||
|
import type { ClawSkill, SkillsState } from '~/composables/useClaw'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
state: SkillsState | null
|
||||||
|
loading: boolean
|
||||||
|
/** The skill whose toggle is in flight. */
|
||||||
|
saving: string | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
defineEmits<{
|
||||||
|
refresh: []
|
||||||
|
toggle: [name: string, enabled: boolean]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const TIERS: Record<ClawSkill['tier'], string> = {
|
||||||
|
workspace: 'workspace',
|
||||||
|
global: 'global',
|
||||||
|
'workspace-agents': 'workspace .agents',
|
||||||
|
'home-agents': 'home .agents',
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="page">
|
||||||
|
<PageHeader title="Skills" subtitle="Instruction files the agent reads on demand.">
|
||||||
|
<template #actions>
|
||||||
|
<button :disabled="loading" @click="$emit('refresh')">
|
||||||
|
{{ loading ? 'Refreshing…' : 'Refresh' }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="scroll">
|
||||||
|
<p v-if="!state" class="muted">loading skills…</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<AppCallout
|
||||||
|
v-if="state.disabled.length"
|
||||||
|
variant="info"
|
||||||
|
title="Some skills are held back"
|
||||||
|
>
|
||||||
|
A disabled skill keeps its files and disappears from the prompt
|
||||||
|
and the transcript. The switch persists across restarts.
|
||||||
|
</AppCallout>
|
||||||
|
|
||||||
|
<SettingCard title="Installed" :meta="`${state.skills.length} found`">
|
||||||
|
<p v-if="state.skills.length === 0" class="empty">
|
||||||
|
No skills found. Put a <code>SKILL.md</code> under a folder in the
|
||||||
|
global directory, or in the workspace's
|
||||||
|
<code>.rhema/skills</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div v-for="skill in state.skills" :key="skill.name" class="skill">
|
||||||
|
<div class="skill-head">
|
||||||
|
<span class="skill-name mono">{{ skill.name }}</span>
|
||||||
|
<span class="skill-tier">{{ TIERS[skill.tier] }}</span>
|
||||||
|
<span class="skill-state" :class="{ off: !skill.enabled }">
|
||||||
|
{{ skill.enabled ? 'enabled' : 'disabled' }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
class="skill-toggle"
|
||||||
|
:disabled="saving === skill.name"
|
||||||
|
:aria-label="`${skill.enabled ? 'Disable' : 'Enable'} ${skill.name}`"
|
||||||
|
@click="$emit('toggle', skill.name, !skill.enabled)"
|
||||||
|
>
|
||||||
|
{{ saving === skill.name ? 'Saving…' : skill.enabled ? 'Disable' : 'Enable' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="skill-trigger">{{ skill.description }}</p>
|
||||||
|
<p class="skill-path mono">{{ skill.path }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingCard>
|
||||||
|
|
||||||
|
<p class="footnote">
|
||||||
|
Discovery reads <span class="mono">{{ state.root }}</span>, then the
|
||||||
|
chat workspace's <code>.rhema/skills</code> and
|
||||||
|
<code>.agents/skills</code> under
|
||||||
|
<span class="mono">{{ state.workspace }}</span>. A skill in a rhema
|
||||||
|
directory shadows the same name in an <code>.agents</code> directory.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scroll {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0 24px 24px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
max-width: 860px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
margin: 0;
|
||||||
|
padding: 13px 16px;
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-name {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-tier {
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-state {
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--ok);
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-state.off {
|
||||||
|
color: var(--text3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-toggle {
|
||||||
|
padding: 2px 9px;
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-trigger {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--text2);
|
||||||
|
font-size: 12.5px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skill-path {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 11.5px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footnote {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 2px;
|
||||||
|
color: var(--text3);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -289,6 +289,63 @@ export interface SandboxSelection {
|
|||||||
workspace?: string
|
workspace?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** One skill `/v1/skills` lists: the folder name, its trigger, the
|
||||||
|
* `SKILL.md` path, the tier discovery read it from, and whether the
|
||||||
|
* prompt holds it back. */
|
||||||
|
export interface ClawSkill {
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
path: string
|
||||||
|
tier: 'workspace' | 'global' | 'workspace-agents' | 'home-agents'
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The skills state `GET /v1/skills` serves: the global root, the
|
||||||
|
* workspace whose tiers were read, the disabled names, and every
|
||||||
|
* discovered skill. */
|
||||||
|
export interface SkillsState {
|
||||||
|
root: string
|
||||||
|
workspace: string
|
||||||
|
disabled: string[]
|
||||||
|
skills: ClawSkill[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One bootstrap document `GET /v1/bootstrap/files` serves. */
|
||||||
|
export interface BootstrapFile {
|
||||||
|
kind: 'soul' | 'user' | 'environment'
|
||||||
|
name: string
|
||||||
|
content: string | null
|
||||||
|
exists: boolean
|
||||||
|
/** ENVIRONMENT.md is written at boot, never through the editor. */
|
||||||
|
generated: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The bootstrap editor's state: the onboarding badge plus the three
|
||||||
|
* documents, live. */
|
||||||
|
export interface BootstrapFiles {
|
||||||
|
status: { soul: boolean; user: boolean }
|
||||||
|
files: BootstrapFile[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One MCP server row `GET /v1/mcp` serves. Narrow by design: command
|
||||||
|
* arguments and URLs can carry credentials and never ride the wire. */
|
||||||
|
export interface McpServer {
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
transport: 'stdio' | 'http' | 'unknown'
|
||||||
|
program: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The MCP page's state: the client's config path, its servers, the
|
||||||
|
* names `claw.yaml` mutes, and parse notices. */
|
||||||
|
export interface McpState {
|
||||||
|
config: string
|
||||||
|
exists: boolean
|
||||||
|
servers: McpServer[]
|
||||||
|
disabled: string[]
|
||||||
|
notices: string[]
|
||||||
|
}
|
||||||
|
|
||||||
/** A failed API call: the status plus the claw's `error` string when it sent one. */
|
/** A failed API call: the status plus the claw's `error` string when it sent one. */
|
||||||
export class ClawError extends Error {
|
export class ClawError extends Error {
|
||||||
/** HTTP status; 0 when the claw was unreachable at all. */
|
/** HTTP status; 0 when the claw was unreachable at all. */
|
||||||
@@ -466,6 +523,17 @@ export interface ClawApi {
|
|||||||
/** `DELETE /v1/providers/{id}` — remove a backend instance; answers
|
/** `DELETE /v1/providers/{id}` — remove a backend instance; answers
|
||||||
* the new providers state. The last backend is refused claw-side. */
|
* the new providers state. The last backend is refused claw-side. */
|
||||||
removeProvider(id: string): Promise<ProvidersState>
|
removeProvider(id: string): Promise<ProvidersState>
|
||||||
|
/** `GET /v1/skills` — installed skills, their triggers, paths, and
|
||||||
|
* whether the prompt currently holds each one back. */
|
||||||
|
skills(): Promise<SkillsState>
|
||||||
|
/** `PUT /v1/skills/{name}` — flip one skill and persist the set. */
|
||||||
|
setSkillEnabled(name: string, enabled: boolean): Promise<{ name: string; enabled: boolean; disabled: string[] }>
|
||||||
|
/** `GET /v1/bootstrap/files` — SOUL.md, USER.md, ENVIRONMENT.md. */
|
||||||
|
bootstrapFiles(): Promise<BootstrapFiles>
|
||||||
|
/** `PUT /v1/bootstrap/{kind}` — overwrite SOUL.md or USER.md. */
|
||||||
|
saveBootstrap(kind: string, content: string): Promise<{ saved: boolean; kind: string }>
|
||||||
|
/** `GET /v1/mcp` — the client's config path, servers, and mute set. */
|
||||||
|
mcp(): Promise<McpState>
|
||||||
/** `GET /v1/sandbox`: where the agent's `bash` runs. */
|
/** `GET /v1/sandbox`: where the agent's `bash` runs. */
|
||||||
sandbox(): Promise<SandboxState>
|
sandbox(): Promise<SandboxState>
|
||||||
/** `PUT /v1/sandbox`: switch the sandbox, persisted claw-side. The
|
/** `PUT /v1/sandbox`: switch the sandbox, persisted claw-side. The
|
||||||
@@ -685,6 +753,37 @@ export function useClaw(token: Ref<string | null>): ClawApi {
|
|||||||
})) as ProvidersState
|
})) as ProvidersState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function skills(): Promise<SkillsState> {
|
||||||
|
return (await get('/v1/skills', token.value)) as SkillsState
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setSkillEnabled(
|
||||||
|
name: string,
|
||||||
|
enabled: boolean,
|
||||||
|
): Promise<{ name: string; enabled: boolean; disabled: string[] }> {
|
||||||
|
return (await send(`/v1/skills/${encodeURIComponent(name)}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json', ...authHeaders(token.value) },
|
||||||
|
body: JSON.stringify({ enabled }),
|
||||||
|
})) as { name: string; enabled: boolean; disabled: string[] }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bootstrapFiles(): Promise<BootstrapFiles> {
|
||||||
|
return (await get('/v1/bootstrap/files', token.value)) as BootstrapFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveBootstrap(kind: string, content: string): Promise<{ saved: boolean; kind: string }> {
|
||||||
|
return (await send(`/v1/bootstrap/${encodeURIComponent(kind)}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json', ...authHeaders(token.value) },
|
||||||
|
body: JSON.stringify({ content }),
|
||||||
|
})) as { saved: boolean; kind: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function mcp(): Promise<McpState> {
|
||||||
|
return (await get('/v1/mcp', token.value)) as McpState
|
||||||
|
}
|
||||||
|
|
||||||
async function sandbox(): Promise<SandboxState> {
|
async function sandbox(): Promise<SandboxState> {
|
||||||
return (await get('/v1/sandbox', token.value)) as SandboxState
|
return (await get('/v1/sandbox', token.value)) as SandboxState
|
||||||
}
|
}
|
||||||
@@ -928,6 +1027,11 @@ export function useClaw(token: Ref<string | null>): ClawApi {
|
|||||||
models,
|
models,
|
||||||
setCredentials,
|
setCredentials,
|
||||||
removeProvider,
|
removeProvider,
|
||||||
|
skills,
|
||||||
|
setSkillEnabled,
|
||||||
|
bootstrapFiles,
|
||||||
|
saveBootstrap,
|
||||||
|
mcp,
|
||||||
sandbox,
|
sandbox,
|
||||||
setSandbox,
|
setSandbox,
|
||||||
accounts,
|
accounts,
|
||||||
|
|||||||
Reference in new issue
Block a user