agentleFS
brokspacebrokspace/brok/skills/engineering/write-shard/SKILL.md

write-shard

Skill12 starsChanged 28 days agoApache-2.0View on GitHub

Build a Brokspace shard: a small process on the local event bus that reacts to workspace events. Use when the user wants to automate something on file changes, add a custom agent or integration to Brokspace, edit a shard.json, or work with brok-sdk.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write down, before coding:

    line 23
  2. Very specific:

    Least privilege: only the paths it reads, network: false unless it calls a service, only the programs (process) and environment variables …

    line 29
  3. Very specific:

    Ask the index: client.call::<SearchRequest, SearchResults>(&req, timeout) (add index:search to publishes_to).

    line 57

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Write a shard

A shard is a standalone program that brok run starts, connects to the local event bus and restricts to the topics its shard.json declares. Most shards are under 200 lines of Rust with brok-sdk.

1. Scaffold

brok shard new <name>            # Rust project: Cargo.toml, shard.json, src/main.rs
brok shard new <name> --skills-only   # only agent skills, no process

Names: lowercase, digits and dashes, starting with a letter.

2. Decide events and permissions

Write down, before coding:

  • Subscribes to: which events trigger work (file:changed is the usual one). Use exact topics; wildcards only when needed.
  • Publishes to: your own namespace, named after the shard (license:violation). system:* is reserved.
  • Least privilege: only the paths it reads, network: false unless it calls a service, only the programs (process) and environment variables (env, e.g. MY_TOOL_*) it needs. Users see these at install time.

See MANIFEST.md for an annotated shard.json.

3. Code the loop

use brok_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), ClientError> {
    let (client, mut inbox) = BrokClient::connect_from_env("my-shard", env!("CARGO_PKG_VERSION")).await?;
    client.subscribe([TopicPattern::new("file:changed")?]).await?;
    while let Some(event) = inbox.recv().await {
        if event.is::<Shutdown>() { break; }
        if let Ok(change) = event.decode::<FileChanged>() {
            // inspect change.changed (workspace-relative paths, `/` separators)
            // client.emit(&MyFinding { .. }).await?;
        }
    }
    Ok(())
}
  • Define your payloads as serde structs implementing brok_sdk::Payload (const TOPIC: &'static str = "my-shard:finding";).
  • Ask the index: client.call::<SearchRequest, SearchResults>(&req, timeout) (add index:search to publishes_to).
  • Answer requests with client.reply(&request_event, &payload); only the requester receives it.
  • Log to stderr; brok run prefixes lines with the shard name.
  • Exit within three seconds of Shutdown.

4. Test

  • Unit-test the pure logic (parsing, matching) without the bus.
  • Set brok in shard.json to a range that includes the user's version.
  • Live: brok shard install ./<name>, then brok run in one terminal and brok bus tail '<namespace>:*' in another. Inject events with brok bus emit file:changed '{"changed":["src/main.rs"],"deleted":[]}'.
  • Logs: .brokspace/logs/<name>.log.

A reply sent with client.reply reaches only the requester, so it does not show in bus tail. After a change, reinstall with --force and brok restart. The full walkthrough is docs/shard-tutorial.md in the brok repository.

5. Release

Tag a version, build binaries per platform (the template repo's release workflow does this), and add each to shard.json releases with its SHA-256 so users install a verified binary instead of building from source. Publish the repository; users install with brok shard install <git-url> --tag vX.Y.Z.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.