| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- // graphify OpenCode plugin
- // Injects a knowledge graph reminder before bash tool calls when the graph exists.
- import { existsSync } from "fs";
- import { join, relative } from "path";
- /** graph.json 可能出现的目录(相对仓库根);CRM 主前端图谱通常在 crm/web/graphify-out */
- function findGraphifyOutRoot(workspaceRoot) {
- const roots = [
- join(workspaceRoot, "graphify-out"),
- join(workspaceRoot, "crm", "web", "graphify-out"),
- join(workspaceRoot, "crm", "graphify-out"),
- join(workspaceRoot, "crm", "backend", "graphify-out"),
- ];
- for (const root of roots) {
- if (existsSync(join(root, "graph.json"))) return root;
- }
- return null;
- }
- export const GraphifyPlugin = async ({ directory }) => {
- let reminded = false;
- return {
- "tool.execute.before": async (input, output) => {
- if (reminded) return;
- const graphifyRoot = findGraphifyOutRoot(directory);
- if (!graphifyRoot) return;
- if (input.tool === "bash") {
- const rel =
- relative(directory, graphifyRoot) || "graphify-out";
- output.args.command =
- `echo "[graphify] Knowledge graph found at ${rel}/. Read ${rel}/GRAPH_REPORT.md for context before wide file search." && ` +
- output.args.command;
- reminded = true;
- }
- },
- };
- };
|