backpack-ontology 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/bin/init.d.ts +3 -0
- package/dist/bin/init.d.ts.map +1 -0
- package/dist/bin/init.js +94 -0
- package/dist/bin/init.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +9 -1
- package/dist/mcp/server.js.map +1 -1
- package/hooks/auto-capture-prompt.md +40 -0
- package/hooks/hooks.json +29 -0
- package/hooks/suggest-viewer.sh +4 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -109,6 +109,12 @@ await backpack.initialize();
|
|
|
109
109
|
await backpack.createOntology("my-graph", "A knowledge graph");
|
|
110
110
|
const node = await backpack.addNode("my-graph", "Person", { name: "Alice" });
|
|
111
111
|
await backpack.addEdge("my-graph", "KNOWS", node.id, otherNodeId);
|
|
112
|
+
|
|
113
|
+
// Search across all node properties (case-insensitive)
|
|
114
|
+
const results = await backpack.searchNodes("my-graph", "alice");
|
|
115
|
+
|
|
116
|
+
// BFS traversal from a node (depth 1–3)
|
|
117
|
+
const neighbors = await backpack.getNeighbors("my-graph", node.id, undefined, "both", 2);
|
|
112
118
|
```
|
|
113
119
|
|
|
114
120
|
### Pluggable Storage
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/bin/init.ts"],"names":[],"mappings":""}
|
package/dist/bin/init.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
/** Check if a hook rule array already contains a backpack-originated rule. */
|
|
6
|
+
function hasBackpackRule(rules) {
|
|
7
|
+
return rules.some((r) => r.hooks?.some((h) => (h.prompt && h.prompt.includes("Backpack")) ||
|
|
8
|
+
(h.command && h.command.includes("backpack"))) ?? false);
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
const projectDir = process.cwd();
|
|
12
|
+
const claudeDir = path.join(projectDir, ".claude");
|
|
13
|
+
const settingsPath = path.join(claudeDir, "settings.json");
|
|
14
|
+
// Load the hooks configuration shipped with backpack-ontology
|
|
15
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
16
|
+
const packageRoot = path.resolve(path.dirname(thisFile), "..", "..");
|
|
17
|
+
const hooksJsonPath = path.join(packageRoot, "hooks", "hooks.json");
|
|
18
|
+
let hooksConfig;
|
|
19
|
+
try {
|
|
20
|
+
const raw = await fs.readFile(hooksJsonPath, "utf-8");
|
|
21
|
+
hooksConfig = JSON.parse(raw);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
console.error("Error: could not read hooks configuration from backpack-ontology package.");
|
|
25
|
+
console.error(`Expected at: ${hooksJsonPath}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
// Ensure .claude directory exists
|
|
29
|
+
await fs.mkdir(claudeDir, { recursive: true });
|
|
30
|
+
// Read existing settings or start fresh
|
|
31
|
+
let settings = {};
|
|
32
|
+
try {
|
|
33
|
+
const raw = await fs.readFile(settingsPath, "utf-8");
|
|
34
|
+
settings = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// File doesn't exist or isn't valid JSON — start fresh
|
|
38
|
+
}
|
|
39
|
+
// Merge hooks — backpack hooks are added alongside any existing hooks
|
|
40
|
+
if (!settings.hooks) {
|
|
41
|
+
settings.hooks = {};
|
|
42
|
+
}
|
|
43
|
+
const existingHooks = settings.hooks;
|
|
44
|
+
const newHooks = (hooksConfig.hooks ?? {});
|
|
45
|
+
let alreadyConfigured = false;
|
|
46
|
+
for (const [event, rules] of Object.entries(newHooks)) {
|
|
47
|
+
if (!existingHooks[event]) {
|
|
48
|
+
existingHooks[event] = rules;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const existing = existingHooks[event];
|
|
52
|
+
if (Array.isArray(existing) && hasBackpackRule(existing)) {
|
|
53
|
+
// Backpack hooks already present for this event — skip to avoid duplicates
|
|
54
|
+
alreadyConfigured = true;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// Append backpack hook rules to existing event rules
|
|
58
|
+
if (Array.isArray(existing) && Array.isArray(rules)) {
|
|
59
|
+
existingHooks[event] = [...existing, ...rules];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
existingHooks[event] = rules;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (alreadyConfigured) {
|
|
67
|
+
console.log("");
|
|
68
|
+
console.log(" Backpack hooks are already configured in: " + settingsPath);
|
|
69
|
+
console.log(" No changes made. To reconfigure, remove the existing backpack hooks first.");
|
|
70
|
+
console.log("");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
settings.hooks = existingHooks;
|
|
74
|
+
// Write settings
|
|
75
|
+
await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
76
|
+
console.log("");
|
|
77
|
+
console.log(" Backpack hooks configured successfully!");
|
|
78
|
+
console.log("");
|
|
79
|
+
console.log(" Enabled in: " + settingsPath);
|
|
80
|
+
console.log("");
|
|
81
|
+
console.log(" What's enabled:");
|
|
82
|
+
console.log(" - Auto-capture: a background agent reviews your Claude conversations");
|
|
83
|
+
console.log(" and automatically builds knowledge graphs from meaningful discussions.");
|
|
84
|
+
console.log(" - Viewer suggestions: after ontology updates, you'll be reminded to");
|
|
85
|
+
console.log(" visualize your knowledge graph with `npx backpack-viewer`.");
|
|
86
|
+
console.log("");
|
|
87
|
+
console.log(" To disable, remove the backpack hooks from .claude/settings.json");
|
|
88
|
+
console.log("");
|
|
89
|
+
}
|
|
90
|
+
main().catch((error) => {
|
|
91
|
+
console.error("Error:", error.message ?? error);
|
|
92
|
+
process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C,gBAAgB,GAAG,YAAY,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,0EAA0E,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,CAAC,8EAA8E,CAAC,CAAC;IAC5F,OAAO,CAAC,GAAG,CAAC,yEAAyE,CAAC,CAAC;IACvF,OAAO,CAAC,GAAG,CAAC,kEAAkE,CAAC,CAAC;IAChF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/mcp/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQvD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQvD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,SAAS,CAAC,CA+BpB"}
|
package/dist/mcp/server.js
CHANGED
|
@@ -23,7 +23,15 @@ export async function createMcpServer(storage) {
|
|
|
23
23
|
catch { /* noop */ }
|
|
24
24
|
const server = new McpServer({
|
|
25
25
|
name: "backpack",
|
|
26
|
-
version: "0.
|
|
26
|
+
version: "0.2.0",
|
|
27
|
+
}, {
|
|
28
|
+
instructions: `Backpack is a persistent knowledge graph that remembers what matters across conversations.
|
|
29
|
+
|
|
30
|
+
When you learn something meaningful — a business relationship, a technical decision, a process, a domain concept — consider adding it to backpack. Use backpack_list to see what ontologies exist and backpack_describe to understand their structure before adding to them. Create a new ontology when the topic is distinct from existing ones.
|
|
31
|
+
|
|
32
|
+
After updating an ontology, let the user know they can visualize their knowledge graph by running: npx backpack-viewer (opens http://localhost:5173)
|
|
33
|
+
|
|
34
|
+
Be selective — not every conversation needs to be captured. Focus on knowledge with lasting value: relationships, decisions, architecture, processes, domain concepts, conventions.`,
|
|
27
35
|
});
|
|
28
36
|
// Register all tool groups
|
|
29
37
|
registerOntologyTools(server, backpack);
|
package/dist/mcp/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB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M,aAAa,CAAC,QAAQ,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EAAE;;;;;;oLAMgK;KAC/K,CACF,CAAC;IAEF,2BAA2B;IAC3B,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEpC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
You are a knowledge-capture agent for Backpack, a knowledge graph system. Your job is to review the conversation that just happened and decide whether meaningful knowledge should be preserved in an ontology.
|
|
2
|
+
|
|
3
|
+
## Instructions
|
|
4
|
+
|
|
5
|
+
1. **Review the conversation transcript** — understand what was discussed, decided, or worked on.
|
|
6
|
+
|
|
7
|
+
2. **Decide if anything is worth capturing.** Look for:
|
|
8
|
+
- **Business knowledge**: client details, vendor info, pricing, partnerships, workflows
|
|
9
|
+
- **Technical knowledge**: architecture, APIs, data flows, integrations, design decisions
|
|
10
|
+
- **Domain knowledge**: industry concepts, terminology, regulations, best practices
|
|
11
|
+
- **Operational knowledge**: decisions made, problems solved, processes established, conventions agreed upon
|
|
12
|
+
- **Relationships**: how people, systems, concepts, or processes connect to each other
|
|
13
|
+
|
|
14
|
+
3. **Skip trivial interactions.** Do NOT capture:
|
|
15
|
+
- Simple Q&A with no lasting value
|
|
16
|
+
- Debugging sessions that led nowhere
|
|
17
|
+
- Casual conversation or greetings
|
|
18
|
+
- Knowledge that was already captured in a previous pass
|
|
19
|
+
- Temporary state or in-progress work that will change
|
|
20
|
+
|
|
21
|
+
4. **If there IS something worth capturing:**
|
|
22
|
+
a. Call `backpack_list` to see existing ontologies
|
|
23
|
+
b. Call `backpack_describe` on relevant ontologies to check what's already there
|
|
24
|
+
c. Decide: update an existing ontology (if the topic fits) or create a new one (if the topic is distinct)
|
|
25
|
+
d. Use `backpack_import_nodes` for efficient bulk node creation
|
|
26
|
+
e. Use `backpack_add_edge` to create relationships between nodes
|
|
27
|
+
f. Use clear, descriptive node types and edge types that make the graph readable
|
|
28
|
+
|
|
29
|
+
5. **If there is NOTHING worth capturing**, simply stop. Do not force it.
|
|
30
|
+
|
|
31
|
+
6. **After making updates**, briefly tell the user what was added to their knowledge graph and suggest they can visualize it:
|
|
32
|
+
> "Your backpack knowledge graph was updated with [brief summary]. View it by running `npx backpack-viewer` and opening http://localhost:5173"
|
|
33
|
+
|
|
34
|
+
## Guidelines for good ontology entries
|
|
35
|
+
|
|
36
|
+
- **Node types** should be clear nouns: `Person`, `Company`, `API`, `Decision`, `Process`, `Concept`, `Tool`, `Service`, `Regulation`, etc.
|
|
37
|
+
- **Edge types** should be clear relationships: `WORKS_WITH`, `DEPENDS_ON`, `DECIDED_TO`, `MANAGES`, `IMPLEMENTS`, `RELATES_TO`, etc.
|
|
38
|
+
- **Properties** should include enough context to be useful later: names, descriptions, dates, reasons, status.
|
|
39
|
+
- **Be selective but thorough** — capture the important things well rather than everything poorly.
|
|
40
|
+
- **Prefer updating existing nodes** over creating duplicates. Check if a concept already exists before adding it.
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"Stop": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "agent",
|
|
9
|
+
"prompt": "You are a knowledge-capture agent for Backpack, a knowledge graph system. Review the conversation that just happened and decide whether meaningful knowledge should be preserved in an ontology.\n\n## What to capture\n- Business knowledge: client details, vendor info, pricing, partnerships, workflows\n- Technical knowledge: architecture, APIs, data flows, integrations, design decisions\n- Domain knowledge: industry concepts, terminology, regulations, best practices\n- Operational knowledge: decisions made, problems solved, processes established, conventions\n- Relationships: how people, systems, concepts, or processes connect\n\n## What to skip\n- Simple Q&A with no lasting value\n- Debugging that led nowhere\n- Casual conversation or greetings\n- Knowledge already captured in a previous pass\n- Temporary or in-progress state\n\n## If there IS something worth capturing\n1. Call `backpack_list` to see existing ontologies\n2. Call `backpack_describe` on relevant ones to check existing content\n3. Decide: update an existing ontology (if topic fits) or create a new one (if distinct)\n4. Use `backpack_import_nodes` for bulk node creation\n5. Use `backpack_add_edge` to create relationships\n6. Use clear node types (Person, Company, API, Decision, Process, Concept, Tool, Service) and edge types (WORKS_WITH, DEPENDS_ON, DECIDED_TO, MANAGES, IMPLEMENTS, RELATES_TO)\n\n## If NOTHING is worth capturing, just stop.\n\n## After updates, tell the user:\n\"Your backpack knowledge graph was updated with [brief summary]. View it by running `npx backpack-viewer` (http://localhost:5173)\"",
|
|
10
|
+
"timeout": 120,
|
|
11
|
+
"async": true
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"PostToolUse": [
|
|
17
|
+
{
|
|
18
|
+
"matcher": "backpack_create|backpack_add_node|backpack_update_node|backpack_import_nodes|backpack_add_edge",
|
|
19
|
+
"hooks": [
|
|
20
|
+
{
|
|
21
|
+
"type": "command",
|
|
22
|
+
"command": "echo 'The user'\"'\"'s backpack ontology was just updated. Let the user know they can visualize their knowledge graph by running: npx backpack-viewer (opens http://localhost:5173)'",
|
|
23
|
+
"timeout": 5
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# PostToolUse hook: suggest the viewer after backpack write operations.
|
|
3
|
+
# Output is injected into Claude's context as additional information.
|
|
4
|
+
echo 'The user'\''s backpack ontology was just updated. Let the user know they can visualize their knowledge graph by running: npx backpack-viewer (opens http://localhost:5173)'
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backpack-ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A persistent ontology engine for Claude Code via MCP — progressive discovery of structured knowledge graphs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Noah Irzinger",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
|
-
"backpack": "./dist/bin/backpack.js"
|
|
9
|
+
"backpack": "./dist/bin/backpack.js",
|
|
10
|
+
"backpack-init": "./dist/bin/init.js"
|
|
10
11
|
},
|
|
11
12
|
"main": "./dist/index.js",
|
|
12
13
|
"types": "./dist/index.d.ts",
|
|
13
14
|
"files": [
|
|
14
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"hooks"
|
|
15
17
|
],
|
|
16
18
|
"scripts": {
|
|
17
19
|
"build": "tsc",
|