Skip to content

Commit 587947e

Browse files
committed
init brainkb skills -- to refine
1 parent b212286 commit 587947e

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

brainkb_skills/SKILL.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
name: brainkb
3+
description: >-
4+
Work with a BrainKB knowledge base on the user's behalf: log in with their
5+
credentials, ingest RDF into their workspace (space), check the status of
6+
ingest jobs, read/search the knowledge graphs, and query W3C PROV-O
7+
provenance (including triple-level deltas). Use whenever the user asks to
8+
ingest/upload triples or RDF to BrainKB, create or share a workspace/space
9+
(private/public), search or read BrainKB graphs, check an ingest job's
10+
status, or ask "who/when/what changed" (provenance) about a graph.
11+
---
12+
13+
# BrainKB
14+
15+
Help the user ingest and explore a BrainKB knowledge base through the
16+
`query_service` API. Prefer the **`brainkb` MCP tools** if they are available
17+
(server at `brainkb_mcp/`); otherwise fall back to `curl` (see bottom).
18+
19+
## Credentials & safety
20+
21+
- BrainKB uses JWT auth. Ask the user for their **email**, **password**, and the
22+
**base URL** (default `http://localhost:8010`) if not already provided.
23+
- **Never print, echo, or store the password or the JWT token.** Pass them
24+
straight to the login step. When using curl, read the token into a shell
25+
variable — do not paste it into chat.
26+
- Confirm before mutating actions (creating a space, ingesting, changing
27+
visibility, adding members). Reads are safe.
28+
- Scopes: reads need `read`, ingest / space changes need `write`, arbitrary
29+
SPARQL needs `admin`. If a call returns 403, the user's account lacks the scope
30+
— tell them which scope is required.
31+
32+
## Core concepts (so you pick the right call)
33+
34+
- **Space** = an owner-controlled workspace containing named graphs, with
35+
`visibility` = `private` (members only) or `public` (anyone, even without
36+
logging in, can read). Ingest into a graph requires owner/editor membership of
37+
its space.
38+
- **Ingestion is submit-and-forget**: it returns a `job_id` and runs in the
39+
background. Always poll job status rather than assuming it finished.
40+
- **Provenance** lives natively in the graph DB (PROV-O). Every ingest is an
41+
activity; each job's added triples are a queryable **delta**.
42+
43+
## Workflows
44+
45+
### 1. Log in
46+
Call `brainkb_login(email, password, base_url?)`. Confirm with `brainkb_whoami()`.
47+
48+
### 2. Create / choose a workspace (space)
49+
- New private workspace: `brainkb_create_space(slug, name, "private")`.
50+
- Bind a named graph to it (required before ingesting into that graph):
51+
`brainkb_add_space_graph(slug, graph_iri)``graph_iri` like
52+
`https://brainkb.org/graph/<slug>/`.
53+
- List what the user can see: `brainkb_list_spaces()`.
54+
55+
### 3. Ingest
56+
- Raw text: `brainkb_ingest_text(graph_iri, data)` (Turtle/N-Triples/JSON-LD).
57+
- Files: `brainkb_ingest_files(graph_iri, [paths])`.
58+
- Both return a `job_id`. Tell the user ingestion is running in the background.
59+
60+
### 4. Check ingest status
61+
- `brainkb_job_status(job_id)` → status (`pending`/`running`/`done`/`partial`/
62+
`failed`/`error`), progress %, current file/stage, and per-file failures.
63+
- Poll every few seconds until terminal; report success/failure counts. Use
64+
`brainkb_list_jobs()` to show recent jobs. If a job is stuck/errored, offer
65+
`brainkb_recover_job(job_id)`.
66+
67+
### 5. Read / search
68+
- Search (access-filtered): `brainkb_search(q, space?, limit?)`. Omit `space` for
69+
a full search across everything the user may read.
70+
- Read a whole space's RDF: `brainkb_read_space(slug)`.
71+
- List registered graphs: `brainkb_list_registered_graphs()`.
72+
- Arbitrary SPARQL (admin only): `brainkb_sparql(query)`.
73+
74+
### 6. Provenance
75+
- Whole job: `brainkb_provenance_job(job_id)`.
76+
- A graph's history: `brainkb_provenance_graph(graph_iri)` and
77+
`brainkb_delta_history(graph_iri)`.
78+
- Exactly what a job added: `brainkb_delta(job_id)`.
79+
- Compare two ingests: `brainkb_delta_compare(job_id_a, job_id_b)`.
80+
81+
### 7. Share publicly / manage a workspace
82+
- Publish: `brainkb_set_space_visibility(slug, "public")` (owner). Warn that a
83+
public space is readable by **anyone, including unauthenticated clients**.
84+
- Add teammates: `brainkb_add_space_member(slug, email, "editor"|"viewer")`.
85+
86+
## Typical end-to-end
87+
88+
1. `brainkb_login(...)`
89+
2. `brainkb_create_space("my-lab", "My Lab", "private")`
90+
3. `brainkb_add_space_graph("my-lab", "https://brainkb.org/graph/my-lab/")`
91+
4. `brainkb_ingest_text("https://brainkb.org/graph/my-lab/", "<ttl>")` → job_id
92+
5. poll `brainkb_job_status(job_id)` until `done`
93+
6. `brainkb_search("<term>", space="my-lab")` / `brainkb_provenance_graph(iri)`
94+
7. (optional) `brainkb_set_space_visibility("my-lab", "public")`
95+
96+
## Fallback: curl (no MCP)
97+
98+
Base = the deployment URL (default `http://localhost:8010`).
99+
100+
```bash
101+
# login (capture token into a variable — never print it)
102+
TOKEN=$(curl -s -X POST "$BASE/api/token" -H 'Content-Type: application/json' \
103+
-d '{"email":"'"$EMAIL"'","password":"'"$PASSWORD"'"}' \
104+
| python3 -c 'import sys,json;print(json.load(sys.stdin)["access_token"])')
105+
106+
# create space + bind a graph
107+
curl -s -X POST "$BASE/api/spaces" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
108+
-d '{"slug":"my-lab","name":"My Lab","visibility":"private"}'
109+
curl -s -X POST "$BASE/api/spaces/my-lab/graphs" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
110+
-d '{"named_graph_url":"https://brainkb.org/graph/my-lab/","description":"lab data"}'
111+
112+
# ingest (URL-encode user_id and named_graph_iri)
113+
curl -s -X POST "$BASE/api/insert/raw/knowledge-graph-triples?user_id=$EMAIL&named_graph_iri=https%3A%2F%2Fbrainkb.org%2Fgraph%2Fmy-lab%2F" \
114+
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: text/plain' --data-binary @data.ttl
115+
116+
# job status
117+
curl -s "$BASE/api/insert/user/jobs/detail?user_id=$EMAIL&job_id=<JOB_ID>" -H "Authorization: Bearer $TOKEN"
118+
119+
# search / provenance
120+
curl -s "$BASE/api/search?q=<term>" -H "Authorization: Bearer $TOKEN"
121+
curl -s "$BASE/api/provenance/named-graph?iri=https%3A%2F%2Fbrainkb.org%2Fgraph%2Fmy-lab%2F" -H "Authorization: Bearer $TOKEN"
122+
```
123+
124+
The `user_id` query parameter must equal the logged-in user's email — the server
125+
rejects acting on another user's behalf.

0 commit comments

Comments
 (0)