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.
In this repository21 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ask-brokSkill
- brok-contextSkill
- code-reviewSkill
- commit-messageSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- grill-with-docsSkill
- implementSkill
- prSkill
- retroSkill
- setup-brokspaceSkill
- tddSkill
- to-specSkill
- to-ticketsSkill
- triageSkill
- write-skillSkill
- grillingSkill
- grill-meSkill
- handoffSkill
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
- Distinctive: line 23
Write down, before coding:
- Very specific: line 29
Least privilege: only the paths it reads, network: false unless it calls a service, only the programs (process) and environment variables …
- Very specific: line 57
Ask the index: client.call::<SearchRequest, SearchResults>(&req, timeout) (add index:search to publishes_to).
≈ “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.
Files
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 processNames: lowercase, digits and dashes, starting with a letter.
2. Decide events and permissions
Write down, before coding:
- Subscribes to: which events trigger work (
file:changedis 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: falseunless 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)(addindex:searchtopublishes_to). - Answer requests with
client.reply(&request_event, &payload); only the requester receives it. - Log to stderr;
brok runprefixes lines with the shard name. - Exit within three seconds of
Shutdown.
4. Test
- Unit-test the pure logic (parsing, matching) without the bus.
- Set
brokinshard.jsonto a range that includes the user's version. - Live:
brok shard install ./<name>, thenbrok runin one terminal andbrok bus tail '<namespace>:*'in another. Inject events withbrok 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.
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
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.

