predicate-skill 1.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/.claude-plugin/plugin.json +24 -0
- package/LICENSE +202 -0
- package/README.md +47 -0
- package/cli.bundle.mjs +324 -0
- package/commands/ask.md +18 -0
- package/commands/doctor.md +14 -0
- package/commands/down.md +11 -0
- package/commands/stats.md +22 -0
- package/commands/up.md +13 -0
- package/compose/docker-compose.yml +25 -0
- package/compose/fuseki/config.ttl +18 -0
- package/hooks/hooks.json +9 -0
- package/hooks/session-start.sh +25 -0
- package/package.json +47 -0
- package/server.bundle.mjs +38038 -0
- package/skills/predicate/SKILL.md +119 -0
- package/skills/predicate-doctor/SKILL.md +28 -0
- package/skills/predicate-stats/SKILL.md +29 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "predicate",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local reasoning knowledge graph (RDF/OWL) for AI agents.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "MX Research"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/mxresearch/predicate#readme",
|
|
9
|
+
"repository": "https://github.com/mxresearch/predicate",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"keywords": ["mcp", "knowledge-graph", "rdf", "owl", "sparql", "reasoning"],
|
|
12
|
+
"mcpServers": {
|
|
13
|
+
"predicate": {
|
|
14
|
+
"command": "node",
|
|
15
|
+
"args": ["${CLAUDE_PLUGIN_ROOT}/server.bundle.mjs"],
|
|
16
|
+
"env": {
|
|
17
|
+
"FUSEKI_URL": "http://localhost:3030",
|
|
18
|
+
"PREDICATE_DATASET": "predicate"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"skills": "./skills/",
|
|
23
|
+
"hooks": "./hooks/hooks.json"
|
|
24
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# predicate-skill
|
|
2
|
+
|
|
3
|
+
Claude Code plugin packaging the Predicate MCP server + SKILL.md + SessionStart
|
|
4
|
+
hook + operator skills. This is the install target for the marketplace path.
|
|
5
|
+
|
|
6
|
+
## Install (via marketplace)
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
/plugin marketplace add mxresearch/predicate
|
|
10
|
+
/plugin install predicate@predicate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
After install, bring Fuseki up:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
predicate up
|
|
17
|
+
predicate doctor
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What's in this directory
|
|
21
|
+
|
|
22
|
+
- `.claude-plugin/plugin.json` — MCP server + skills + hooks registration.
|
|
23
|
+
- `server.bundle.mjs` — bundled MCP server (no `node_modules` required).
|
|
24
|
+
- `cli.bundle.mjs` — bundled `predicate` CLI, surfaced via the package's `bin`.
|
|
25
|
+
- `skills/predicate/SKILL.md` — host-agent contract: triggers, workflow,
|
|
26
|
+
HARD-GATE anti-patterns, four worked examples.
|
|
27
|
+
- `skills/predicate-doctor/SKILL.md`, `skills/predicate-stats/SKILL.md` —
|
|
28
|
+
operator skills.
|
|
29
|
+
- `hooks/hooks.json` + `hooks/session-start.sh` — SessionStart hook that
|
|
30
|
+
surfaces current goal/class counts.
|
|
31
|
+
- `compose/docker-compose.yml`, `compose/fuseki/config.ttl` — Fuseki config
|
|
32
|
+
the CLI launches.
|
|
33
|
+
|
|
34
|
+
## Rebuilding the bundles
|
|
35
|
+
|
|
36
|
+
Bundles are committed so the marketplace install path works without
|
|
37
|
+
`pnpm install`. To rebuild after a source change:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm --filter predicate-skill bundle
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or rebuild everything:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm build
|
|
47
|
+
```
|
package/cli.bundle.mjs
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// ../predicate-cli/src/docker.ts
|
|
7
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
import { resolve, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
function findComposeDir() {
|
|
12
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const candidates = [
|
|
14
|
+
process.env.PREDICATE_COMPOSE_DIR,
|
|
15
|
+
resolve(here, "compose"),
|
|
16
|
+
resolve(here, "..", "compose"),
|
|
17
|
+
resolve(here, "..", "..", "predicate-skill", "compose"),
|
|
18
|
+
resolve(here, "..", "..", "..", "predicate-skill", "compose"),
|
|
19
|
+
resolve(here, "..", "..", "..", "predicate-server")
|
|
20
|
+
].filter((p) => Boolean(p));
|
|
21
|
+
for (const c of candidates) {
|
|
22
|
+
if (c && existsSync(resolve(c, "docker-compose.yml"))) return c;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Could not locate docker-compose.yml. Set PREDICATE_COMPOSE_DIR to the directory containing it, or run from the predicate repo root. Searched: ${candidates.join(", ")}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function dockerAvailable() {
|
|
29
|
+
try {
|
|
30
|
+
execSync("docker version", { stdio: "ignore" });
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function compose(args, cwd) {
|
|
37
|
+
const r = spawnSync("docker", ["compose", ...args], { cwd, stdio: "inherit" });
|
|
38
|
+
return r.status ?? 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ../predicate-cli/src/commands/up.ts
|
|
42
|
+
async function up() {
|
|
43
|
+
if (!dockerAvailable()) {
|
|
44
|
+
console.error("Docker not found. Install Docker Desktop or Docker Engine first.");
|
|
45
|
+
return 2;
|
|
46
|
+
}
|
|
47
|
+
const dir = findComposeDir();
|
|
48
|
+
console.log(`bringing Fuseki up from ${dir}`);
|
|
49
|
+
return compose(["up", "-d"], dir);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../predicate-cli/src/commands/down.ts
|
|
53
|
+
async function down() {
|
|
54
|
+
if (!dockerAvailable()) {
|
|
55
|
+
console.error("Docker not found.");
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
const dir = findComposeDir();
|
|
59
|
+
return compose(["down"], dir);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ../predicate-mcp/src/sparql/client.ts
|
|
63
|
+
function err(status, body) {
|
|
64
|
+
const e = new Error(`SPARQL error ${status}: ${body}`);
|
|
65
|
+
e.status = status;
|
|
66
|
+
e.body = body;
|
|
67
|
+
return e;
|
|
68
|
+
}
|
|
69
|
+
function authHeader() {
|
|
70
|
+
const user = process.env.PREDICATE_ADMIN_USER ?? "admin";
|
|
71
|
+
const pass = process.env.PREDICATE_ADMIN_PASSWORD ?? "changeme";
|
|
72
|
+
return "Basic " + Buffer.from(`${user}:${pass}`).toString("base64");
|
|
73
|
+
}
|
|
74
|
+
var SparqlClient = class {
|
|
75
|
+
constructor(cfg) {
|
|
76
|
+
this.cfg = cfg;
|
|
77
|
+
}
|
|
78
|
+
cfg;
|
|
79
|
+
async select(query) {
|
|
80
|
+
const res = await fetch(this.cfg.queryEndpoint, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/sparql-query",
|
|
84
|
+
"Accept": "application/sparql-results+json",
|
|
85
|
+
"Authorization": authHeader()
|
|
86
|
+
},
|
|
87
|
+
body: query
|
|
88
|
+
});
|
|
89
|
+
if (!res.ok) throw err(res.status, await res.text());
|
|
90
|
+
return await res.json();
|
|
91
|
+
}
|
|
92
|
+
async ask(query) {
|
|
93
|
+
const res = await fetch(this.cfg.queryEndpoint, {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "application/sparql-query",
|
|
97
|
+
"Accept": "application/sparql-results+json",
|
|
98
|
+
"Authorization": authHeader()
|
|
99
|
+
},
|
|
100
|
+
body: query
|
|
101
|
+
});
|
|
102
|
+
if (!res.ok) throw err(res.status, await res.text());
|
|
103
|
+
const json = await res.json();
|
|
104
|
+
return json.boolean;
|
|
105
|
+
}
|
|
106
|
+
async update(query) {
|
|
107
|
+
const res = await fetch(this.cfg.updateEndpoint, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/sparql-update",
|
|
111
|
+
"Authorization": authHeader()
|
|
112
|
+
},
|
|
113
|
+
body: query
|
|
114
|
+
});
|
|
115
|
+
if (!res.ok) throw err(res.status, await res.text());
|
|
116
|
+
}
|
|
117
|
+
async knownGraphs() {
|
|
118
|
+
const r = await this.select(
|
|
119
|
+
'SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } FILTER(STRSTARTS(STR(?g), "kg:")) }'
|
|
120
|
+
);
|
|
121
|
+
return r.results.bindings.map((b) => b.g.value);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// ../predicate-mcp/src/config.ts
|
|
126
|
+
function loadConfig() {
|
|
127
|
+
const raw = process.env.FUSEKI_URL ?? "http://localhost:3030";
|
|
128
|
+
const fusekiUrl = raw.replace(/\/+$/, "");
|
|
129
|
+
const dataset = process.env.PREDICATE_DATASET ?? "predicate";
|
|
130
|
+
return {
|
|
131
|
+
fusekiUrl,
|
|
132
|
+
dataset,
|
|
133
|
+
queryEndpoint: `${fusekiUrl}/${dataset}/query`,
|
|
134
|
+
updateEndpoint: `${fusekiUrl}/${dataset}/update`,
|
|
135
|
+
dataEndpoint: `${fusekiUrl}/${dataset}/data`
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ../predicate-cli/src/commands/doctor.ts
|
|
140
|
+
async function doctor() {
|
|
141
|
+
const cfg = loadConfig();
|
|
142
|
+
const checks = [];
|
|
143
|
+
checks.push({
|
|
144
|
+
name: "docker installed",
|
|
145
|
+
ok: dockerAvailable(),
|
|
146
|
+
detail: dockerAvailable() ? "" : "install Docker Desktop"
|
|
147
|
+
});
|
|
148
|
+
const ping = await fetch(`${cfg.fusekiUrl}/$/ping`).catch(() => null);
|
|
149
|
+
checks.push({
|
|
150
|
+
name: "fuseki reachable",
|
|
151
|
+
ok: Boolean(ping?.ok),
|
|
152
|
+
detail: ping?.ok ? cfg.fusekiUrl : `not reachable at ${cfg.fusekiUrl} \u2014 try 'predicate up'`
|
|
153
|
+
});
|
|
154
|
+
if (ping?.ok) {
|
|
155
|
+
const client = new SparqlClient(cfg);
|
|
156
|
+
const tboxOk = await client.ask(`
|
|
157
|
+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|
158
|
+
ASK { GRAPH <kg:tbox> { ?c a owl:Class } }
|
|
159
|
+
`).catch(() => false);
|
|
160
|
+
checks.push({
|
|
161
|
+
name: "kg:tbox loaded",
|
|
162
|
+
ok: tboxOk,
|
|
163
|
+
detail: tboxOk ? "" : "no classes found \u2014 try 'predicate up' (re-runs bootstrap)"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const width = Math.max(...checks.map((c) => c.name.length));
|
|
167
|
+
for (const c of checks) {
|
|
168
|
+
const mark = c.ok ? "[x]" : "[ ]";
|
|
169
|
+
const name = c.name.padEnd(width);
|
|
170
|
+
const detail = c.detail ? ` \u2014 ${c.detail}` : "";
|
|
171
|
+
console.log(`${mark} ${name}${detail}`);
|
|
172
|
+
}
|
|
173
|
+
return checks.every((c) => c.ok) ? 0 : 1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ../predicate-mcp/src/tools/kg-stats.ts
|
|
177
|
+
async function countGraph(client, graph) {
|
|
178
|
+
const r = await client.select(
|
|
179
|
+
`SELECT (COUNT(*) AS ?n) WHERE { GRAPH <${graph}> { ?s ?p ?o } }`
|
|
180
|
+
);
|
|
181
|
+
return parseInt(r.results.bindings[0].n.value, 10);
|
|
182
|
+
}
|
|
183
|
+
async function countClasses(client) {
|
|
184
|
+
const r = await client.select(`
|
|
185
|
+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|
186
|
+
SELECT (COUNT(DISTINCT ?c) AS ?n) WHERE {
|
|
187
|
+
GRAPH <kg:tbox> { ?c a owl:Class }
|
|
188
|
+
}
|
|
189
|
+
`);
|
|
190
|
+
return parseInt(r.results.bindings[0].n.value, 10);
|
|
191
|
+
}
|
|
192
|
+
async function unusedConceptRatio(client, classCount) {
|
|
193
|
+
if (classCount === 0) return 0;
|
|
194
|
+
const r = await client.select(`
|
|
195
|
+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|
196
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
197
|
+
SELECT (COUNT(DISTINCT ?c) AS ?n) WHERE {
|
|
198
|
+
GRAPH <kg:tbox> { ?c a owl:Class }
|
|
199
|
+
FILTER NOT EXISTS {
|
|
200
|
+
{ GRAPH <kg:abox> { ?x rdf:type ?c } }
|
|
201
|
+
UNION
|
|
202
|
+
{ GRAPH <kg:inferred> { ?x rdf:type ?c } }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
`);
|
|
206
|
+
const unused = parseInt(r.results.bindings[0].n.value, 10);
|
|
207
|
+
return unused / classCount;
|
|
208
|
+
}
|
|
209
|
+
async function materializationLatencyP95(client) {
|
|
210
|
+
const r = await client.select(`
|
|
211
|
+
PREFIX pred: <https://predicate.dev/meta#>
|
|
212
|
+
SELECT ?payload WHERE {
|
|
213
|
+
GRAPH <kg:meta> {
|
|
214
|
+
?e a pred:MaterializationCompleted ;
|
|
215
|
+
pred:payload ?payload .
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
`);
|
|
219
|
+
const values = r.results.bindings.map((b) => {
|
|
220
|
+
const raw = b.payload?.value ?? "";
|
|
221
|
+
const m = raw.match(/"elapsedMs"\s*:\s*(\d+)/);
|
|
222
|
+
return m ? parseInt(m[1], 10) : 0;
|
|
223
|
+
}).filter((n) => Number.isFinite(n) && n > 0);
|
|
224
|
+
if (values.length === 0) return 0;
|
|
225
|
+
values.sort((a, b) => a - b);
|
|
226
|
+
const idx = Math.min(values.length - 1, Math.ceil(values.length * 0.95) - 1);
|
|
227
|
+
return values[Math.max(idx, 0)];
|
|
228
|
+
}
|
|
229
|
+
async function kgStats(client) {
|
|
230
|
+
const [abox, inferred, tbox] = await Promise.all([
|
|
231
|
+
countGraph(client, "kg:abox"),
|
|
232
|
+
countGraph(client, "kg:inferred"),
|
|
233
|
+
countGraph(client, "kg:tbox")
|
|
234
|
+
]);
|
|
235
|
+
const classes = await countClasses(client);
|
|
236
|
+
const triples = abox + inferred + tbox;
|
|
237
|
+
const denom = abox + inferred;
|
|
238
|
+
const inferredRatio = denom === 0 ? 0 : inferred / denom;
|
|
239
|
+
const unused = await unusedConceptRatio(client, classes);
|
|
240
|
+
const p95 = await materializationLatencyP95(client);
|
|
241
|
+
return {
|
|
242
|
+
triples,
|
|
243
|
+
abox,
|
|
244
|
+
inferred,
|
|
245
|
+
tbox,
|
|
246
|
+
classes,
|
|
247
|
+
inferredRatio,
|
|
248
|
+
unusedConceptRatio: unused,
|
|
249
|
+
materializationLatencyMsP95: p95
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ../predicate-cli/src/commands/stats.ts
|
|
254
|
+
async function stats() {
|
|
255
|
+
const client = new SparqlClient(loadConfig());
|
|
256
|
+
const s = await kgStats(client);
|
|
257
|
+
const rows = [
|
|
258
|
+
["triples", s.triples],
|
|
259
|
+
["abox", s.abox],
|
|
260
|
+
["inferred", s.inferred],
|
|
261
|
+
["tbox", s.tbox],
|
|
262
|
+
["classes", s.classes],
|
|
263
|
+
["inferredRatio", s.inferredRatio.toFixed(3)],
|
|
264
|
+
["unusedConceptRatio", s.unusedConceptRatio.toFixed(3)],
|
|
265
|
+
["materializationLatencyMsP95", s.materializationLatencyMsP95]
|
|
266
|
+
];
|
|
267
|
+
const width = Math.max(...rows.map(([k]) => k.length));
|
|
268
|
+
for (const [k, v] of rows) {
|
|
269
|
+
console.log(`${k.padEnd(width)} ${v}`);
|
|
270
|
+
}
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ../predicate-cli/src/index.ts
|
|
275
|
+
var VERSION = "1.0.0";
|
|
276
|
+
function help() {
|
|
277
|
+
console.log(`predicate <command>
|
|
278
|
+
|
|
279
|
+
Commands:
|
|
280
|
+
up Bring Fuseki up (docker compose up -d) and load the seed TBox.
|
|
281
|
+
down Stop Fuseki, preserve the data volume.
|
|
282
|
+
doctor Health checks: docker, fuseki, tbox.
|
|
283
|
+
stats Print kg_stats output for the live graph.
|
|
284
|
+
--version Print the predicate version.
|
|
285
|
+
--help This message.
|
|
286
|
+
|
|
287
|
+
Env:
|
|
288
|
+
FUSEKI_URL http://localhost:3030 (default)
|
|
289
|
+
PREDICATE_DATASET predicate (default)
|
|
290
|
+
PREDICATE_ADMIN_USER admin (default)
|
|
291
|
+
PREDICATE_ADMIN_PASSWORD changeme (default)
|
|
292
|
+
PREDICATE_COMPOSE_DIR override docker-compose.yml location
|
|
293
|
+
`);
|
|
294
|
+
}
|
|
295
|
+
async function main() {
|
|
296
|
+
const cmd = process.argv[2];
|
|
297
|
+
switch (cmd) {
|
|
298
|
+
case "up":
|
|
299
|
+
return up();
|
|
300
|
+
case "down":
|
|
301
|
+
return down();
|
|
302
|
+
case "doctor":
|
|
303
|
+
return doctor();
|
|
304
|
+
case "stats":
|
|
305
|
+
return stats();
|
|
306
|
+
case "--version":
|
|
307
|
+
case "version":
|
|
308
|
+
console.log(VERSION);
|
|
309
|
+
return 0;
|
|
310
|
+
case void 0:
|
|
311
|
+
case "--help":
|
|
312
|
+
case "help":
|
|
313
|
+
help();
|
|
314
|
+
return 0;
|
|
315
|
+
default:
|
|
316
|
+
console.error(`unknown command: ${cmd}`);
|
|
317
|
+
help();
|
|
318
|
+
return 2;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
main().then((code) => process.exit(code)).catch((err2) => {
|
|
322
|
+
console.error(err2);
|
|
323
|
+
process.exit(1);
|
|
324
|
+
});
|
package/commands/ask.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ask
|
|
3
|
+
description: Ask the knowledge graph a structural question. Composes kg_explore_schema → kg_ask → kg_explain.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /predicate:ask <question>
|
|
7
|
+
|
|
8
|
+
Treat the arguments as the user's question. Follow the SKILL.md workflow:
|
|
9
|
+
|
|
10
|
+
1. Call `kg_explore_schema(concept)` for the main subject in the question.
|
|
11
|
+
2. Draft fresh SPARQL against `kg:abox ∪ kg:inferred` using predicates from
|
|
12
|
+
the schema slice.
|
|
13
|
+
3. Call `kg_ask` to execute.
|
|
14
|
+
4. Call `kg_explain` for each load-bearing claim in the answer, with cited
|
|
15
|
+
provenance.
|
|
16
|
+
|
|
17
|
+
Do NOT invent predicates — use only what `kg_explore_schema` returned. If a
|
|
18
|
+
predicate is missing, call `kg_propose_schema` instead of fabricating.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: doctor
|
|
3
|
+
description: Run health checks on the Predicate stack — Docker + Fuseki + TBox.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /predicate:doctor
|
|
7
|
+
|
|
8
|
+
Run the shell command `predicate doctor` for the user. Fallback to
|
|
9
|
+
`node ${CLAUDE_PLUGIN_ROOT}/cli.bundle.mjs doctor` if not on PATH.
|
|
10
|
+
|
|
11
|
+
Read the output. For each `[ ]` (failed) check, give the user the
|
|
12
|
+
one-line fix from the doctor's `— ...` detail field.
|
|
13
|
+
|
|
14
|
+
Then call `kg_stats` via MCP to sanity-check that tools actually respond.
|
package/commands/down.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: down
|
|
3
|
+
description: Stop Fuseki via `predicate down` (preserves the data volume).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /predicate:down
|
|
7
|
+
|
|
8
|
+
Run the shell command `predicate down` for the user. Fallback to
|
|
9
|
+
`node ${CLAUDE_PLUGIN_ROOT}/cli.bundle.mjs down` if not on PATH.
|
|
10
|
+
|
|
11
|
+
Report the exit code.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stats
|
|
3
|
+
description: Show current Predicate graph metrics via `kg_stats`.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /predicate:stats
|
|
7
|
+
|
|
8
|
+
Call the `kg_stats` MCP tool. Format the result as a compact table:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
triples N
|
|
12
|
+
abox N
|
|
13
|
+
inferred N
|
|
14
|
+
tbox N
|
|
15
|
+
classes N
|
|
16
|
+
inferredRatio N.NNN
|
|
17
|
+
unusedConceptRatio N.NNN
|
|
18
|
+
materializationLatencyMsP95 N
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Flag if `unusedConceptRatio > 0.15` (PRD §16 bounded-growth target) — suggest
|
|
22
|
+
`/predicate:maintain` (or `kg_maintain` MCP call) to reclaim space.
|
package/commands/up.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: up
|
|
3
|
+
description: Bring Fuseki up via `predicate up` (Docker Compose + bootstrap graphs + load seed TBox).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /predicate:up
|
|
7
|
+
|
|
8
|
+
Run the shell command `predicate up` for the user.
|
|
9
|
+
|
|
10
|
+
If `predicate` is not on PATH, fall back to:
|
|
11
|
+
`node ${CLAUDE_PLUGIN_ROOT}/cli.bundle.mjs up`
|
|
12
|
+
|
|
13
|
+
Report the exit code. If non-zero, run `predicate doctor` and report what's failing.
|