dsh-auto-ontology 0.1.0 → 0.2.1

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.
@@ -12,6 +12,12 @@ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
12
12
  const argv = process.argv.slice(2);
13
13
  const [cmd, ...rest] = argv;
14
14
 
15
+ let script_file = "build_ontology.py";
16
+ if (cmd === "eval") {
17
+ script_file = "eval_evidence.py"; // auto-ontology eval --from x.json [--n 20] [--seed 42]
18
+ } else if (cmd === "validate") {
19
+ script_file = "validate_format.py"; // auto-ontology validate ontologies/*.json
20
+ }
15
21
  let pass;
16
22
  if (cmd === "build") {
17
23
  pass = rest;
@@ -25,7 +31,7 @@ const env = {
25
31
  ONTOLOGY_HOME: path.join(process.cwd(), "ontologies"),
26
32
  };
27
33
 
28
- const r = spawnSync("python3", [path.join(root, "scripts", "build_ontology.py"), ...pass], {
34
+ const r = spawnSync("python3", [path.join(root, "scripts", script_file), ...pass], {
29
35
  stdio: "inherit",
30
36
  env,
31
37
  });
package/cordis.patch.yml CHANGED
@@ -1,12 +1,9 @@
1
- # dsh-auto-ontology bundle layer.
1
+ # dsh-auto-ontology bundle layer (0.2.0): a real plugin insert.
2
2
  #
3
- # Deliberately inserts no plugin entry: this bundle is a distribution vehicle —
4
- # a skill (skills/dsh-auto-ontology/SKILL.md, discovered by @deepseek-ai/dsh-skill-filesystem
5
- # from ~/.dsh/skills/ or <project>/.dsh/skills/) and a CLI (`auto-ontology`, npm bin)
6
- # that spawns the bundled Python engine. A cordis plugin import would fail: the
7
- # package ships no plugin module (typed-tools lands in the 0.2.0 track, issue #11).
8
- #
9
- # Install:
10
- # npm i -g dsh-auto-ontology
11
- # ln -s "$(npm root -g)/dsh-auto-ontology/skills/dsh-auto-ontology" ~/.dsh/skills/dsh-auto-ontology
12
- []
3
+ # The patch inserts the plugin into the profile's layer stack; the module
4
+ # (lib/index.js) then registers the agent tools (ontology_build, ontology_query)
5
+ # on ctx.tools via @deepseek-ai/dsh-tools. The skill stays discoverable via
6
+ # dsh-skill-filesystem; the CLI stays on PATH via npm bin.
7
+ - insert:
8
+ - id: dsh-auto-ontology
9
+ name: 'dsh-auto-ontology'
package/lib/index.js ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * dsh-auto-ontology host plugin (0.2.0, issue #11): the ontology engine as typed tools.
3
+ *
4
+ * Registers two agent tools on `ctx.tools` via @deepseek-ai/dsh-tools:
5
+ * ontology_build — two-pass build over a document corpus (evidence on every
6
+ * assertion, type guard, coref, append-only merge)
7
+ * ontology_query — every assertion about a term, with its evidence spans
8
+ *
9
+ * The tools spawn the bundled Python engine; artifacts land under the calling
10
+ * process's cwd (./ontologies/), exactly like the CLI.
11
+ */
12
+ import { spawnSync } from "node:child_process";
13
+ import path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { defineTool } from "@deepseek-ai/dsh-tools";
16
+
17
+ export const name = "auto-ontology";
18
+ export const inject = ["tools"];
19
+
20
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
21
+
22
+ function run(args, timeoutMs = 600_000) {
23
+ const env = { ...process.env,
24
+ ONTOLOGY_HOME: path.join(process.cwd(), "ontologies") };
25
+ const r = spawnSync("python3", [path.join(ROOT, "scripts", "build_ontology.py"), ...args],
26
+ { encoding: "utf8", timeout: timeoutMs, env, maxBuffer: 16 * 1024 * 1024 });
27
+ if (r.error) throw new Error(`build_ontology: ${r.error.message}`);
28
+ if (r.status !== 0) throw new Error(`build_ontology exited ${r.status}: ${(r.stderr || "").slice(-400)}`);
29
+ return (r.stdout || "").trim();
30
+ }
31
+
32
+ const LANG = { type: "string", enum: ["en", "zh"], description: "Output language (default en)." };
33
+
34
+ export async function apply(ctx) {
35
+ ctx.tools.register(defineTool({
36
+ name: "ontology_build",
37
+ description:
38
+ "Build an ontology from a document corpus: a TBox schema from sampled docs, then per-document " +
39
+ "ABox assertions where EVERY entity and relation carries a verbatim evidence quote (no evidence, " +
40
+ "no assertion; unknown types are flagged, never silently dropped). Conservative coreference merges " +
41
+ "certain mentions (aliases recorded); append-only --merge folds new docs into an existing ontology " +
42
+ "without touching prior evidence; the same name under different types becomes a conflict entry " +
43
+ "holding both evidences. Artifacts: typed JSON (+ evidence), SVG cluster graph, markdown digest " +
44
+ "under ./ontologies/. Takes ~10s + ~2s per document.",
45
+ parameters: {
46
+ docs: { type: "string", required: true, description: "Document directory or glob, e.g. 'docs/*.md'." },
47
+ domain: { type: "string", required: true, description: "Corpus domain description for the schema pass." },
48
+ merge: { type: "string", description: "Existing ontology JSON to fold into (append-only), e.g. ontologies/xxx.json." },
49
+ sample: { type: "number", description: "Docs sampled for the schema pass (default 4)." },
50
+ max_calls: { type: "number", description: "Cost guard: abort beyond this many LLM calls." },
51
+ lang: LANG,
52
+ },
53
+ output: {
54
+ schema: { type: "object", additionalProperties: false,
55
+ properties: { summary: { type: "string", required: true } } },
56
+ render: (_args, value) => [{ type: "text", text: value.summary }],
57
+ },
58
+ execute(args) {
59
+ const extra = ["--save",
60
+ ...(args.merge ? ["--merge", args.merge] : []),
61
+ ...(args.sample ? ["--sample", String(args.sample)] : []),
62
+ ...(args.max_calls ? ["--max-calls", String(args.max_calls)] : []),
63
+ ...(args.lang ? ["--lang", args.lang] : [])];
64
+ return { summary: run(["--docs", args.docs, "--domain", args.domain, ...extra]) };
65
+ },
66
+ }));
67
+
68
+ ctx.tools.register(defineTool({
69
+ name: "ontology_query",
70
+ description:
71
+ "Query the newest ontology (or a given one): every entity and relation touching a term — by name, " +
72
+ "alias, or relation endpoint — each with ALL of its evidence spans (verbatim quotes + source docs). " +
73
+ "The audit surface of the evidence-linked ontology.",
74
+ parameters: {
75
+ term: { type: "string", required: true, description: "Entity name, alias, or relation endpoint." },
76
+ from: { type: "string", description: "Ontology JSON path (default: newest under ./ontologies/)." },
77
+ },
78
+ output: {
79
+ schema: { type: "object", additionalProperties: false,
80
+ properties: { result: { type: "string", required: true } } },
81
+ render: (_args, value) => [{ type: "text", text: value.result }],
82
+ },
83
+ execute(args) {
84
+ return { result: run(["--query", args.term, ...(args.from ? ["--from", args.from] : [])], 60_000) };
85
+ },
86
+ }));
87
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-auto-ontology",
3
- "version": "0.1.0",
4
- "description": "Auto ontology construction for DeepSeek Harness — two-pass LLM pipeline (TBox schema from corpus, ABox assertions per document) with an evidence quote on every entity/relation and a type guard against silent drops. Zero-infra stdlib CLI; implements the concept of NVIDIA/auto-ontology, not affiliated.",
3
+ "version": "0.2.1",
4
+ "description": "Auto ontology construction for DeepSeek Harness — two-pass LLM pipeline (TBox schema from corpus, ABox assertions per document) with an evidence quote on every entity/relation, a type guard against silent drops, append-only incremental merge, conservative coreference, JSON-LD export and evidence-span queries. Zero-infra stdlib CLI + typed agent tools.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "auto-ontology": "bin/auto-ontology.js"
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "bin",
23
+ "lib",
23
24
  "skills",
24
25
  "scripts",
25
26
  "cordis.patch.yml",
@@ -45,5 +46,10 @@
45
46
  "url": "https://github.com/vicfei/dsh-auto-ontology/issues"
46
47
  },
47
48
  "license": "MIT",
48
- "author": "vicfei"
49
+ "author": "vicfei",
50
+ "main": "./lib/index.js",
51
+ "peerDependencies": {
52
+ "@deepseek-ai/cordis": "^4.0.0",
53
+ "@deepseek-ai/dsh-tools": ">=0.0.1-rc.1"
54
+ }
49
55
  }