From 23a055eb7100acfcb269c4c740587cc3cf5062f2 Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 26 Jul 2026 20:47:14 +0000 Subject: [PATCH 1/4] refactor(opencode): remove Graphify integration Remove the Graphify plugin, instruction, and skill from the shared runtime. Update the release bundle contract, documentation, and smoke tests so Graphify paths cannot be shipped again. Refresh the shared OpenCode submodule to its latest release. --- .oc_local/rules/project-release-source.md | 3 +- .oc_local/rules/readme-release.md | 4 +- INDEX.md | 5 +- README.md | 6 +- README_release.md | 26 +- Taskfile.yml | 4 +- commands/add-agent-kit.md | 4 +- opencode.json | 6 +- plugin/graphify.js | 40 - plugin/graphify.md | 21 - rules/devcontainer-tools.md | 2 - skills/graphify/SKILL.md | 1281 --------------------- tests/release-copy.sh | 11 +- 13 files changed, 23 insertions(+), 1390 deletions(-) delete mode 100644 plugin/graphify.js delete mode 100644 plugin/graphify.md delete mode 100644 skills/graphify/SKILL.md diff --git a/.oc_local/rules/project-release-source.md b/.oc_local/rules/project-release-source.md index 79099d1..87f3b34 100644 --- a/.oc_local/rules/project-release-source.md +++ b/.oc_local/rules/project-release-source.md @@ -10,7 +10,6 @@ release that consuming repositories mount at `.opencode/`. - Shared commands belong in `commands/`. - Shared skills belong in `skills/`. - Shared helper scripts belong in `ai-scripts/`. -- Shared plugin source belongs in `plugin/`. - Shared MCP runtime config belongs in root release paths such as `playwright-mcp.json` when `opencode.json` references it. - Release documentation source belongs in `README_release.md` when it is meant @@ -23,7 +22,7 @@ release that consuming repositories mount at `.opencode/`. - Do not add or update `.opencode/rules/*`, `.opencode/commands/*`, `.opencode/skills/*`, or `.opencode/ai-scripts/*` unless the task explicitly targets the release/submodule state. -- When a shared rule, command, skill, script, or plugin changes, make the source +- When a shared rule, command, skill, or script changes, make the source change in the matching root directory and let the release workflow propagate it to `.opencode/`. diff --git a/.oc_local/rules/readme-release.md b/.oc_local/rules/readme-release.md index eded757..d439c00 100644 --- a/.oc_local/rules/readme-release.md +++ b/.oc_local/rules/readme-release.md @@ -22,14 +22,12 @@ Use this rule when creating or updating `README_release.md`. release changes setup, commands, rule loading, submodule expectations, local overlays, or workflow contracts. - The upstream workflow for adding generic shared commands, rules, skills, - scripts, plugin files, or release documentation to this agent kit. + scripts, config files, or release documentation to this agent kit. - Agent startup guidance that applies inside consuming repositories. - High-value shared commands that consumers should prefer for git, memory, task, submodule, and release-related workflows. - Commit, git safety, GitHub CLI, documentation, memory, and local-rule guidance that consumers need immediately. -- Optional subsystem notes, such as Graphify, when they affect how consumers - should use the released workspace. - Maintainer notes for this source repository only when they explain how the release branch is generated, tested, or synchronized. - Troubleshooting entries for common release-submodule issues. diff --git a/INDEX.md b/INDEX.md index c52886e..456238a 100644 --- a/INDEX.md +++ b/INDEX.md @@ -5,7 +5,7 @@ Agent-owned navigation map for the shared OpenCode workspace. ## When To Read This - Read this when starting work in the shared agent kit or when looking for the - right command, rule, skill, or plugin file. + right command, rule, or skill file. - In this source repository and consuming repositories, `opencode.json` loads this as the repository-root `INDEX.md`. @@ -15,12 +15,11 @@ Agent-owned navigation map for the shared OpenCode workspace. - `commands/` - reusable slash-command workflow definitions. - `rules/` - durable instructions loaded by `opencode.json`. - `skills/` - specialized workflows that can be loaded on demand. -- `plugin/` - optional Graphify OpenCode integration. - `docs/tasks/` - source-repository task guide and local implementation specs for accepted work. - `.github/workflows/ci.yml` - read-only contributor CI that runs `task test`. - `opencode.json` - runtime configuration that loads shared instructions, - plugins, MCP servers, and permissions. + MCP servers, and permissions. - `playwright-mcp.json` - Playwright MCP browser launch configuration copied into the generated release bundle. - `README.md` - source-repository overview for maintainers. diff --git a/README.md b/README.md index 2f1f29b..34bc0df 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,7 @@ multiple repositories via a checked-out `.opencode/` directory. Consuming repositories should add the generated `release` branch as their `.opencode` submodule. The release branch contains only the files needed at runtime: `.gitignore`, `LICENSE`, `README.md`, `opencode.json`, -`playwright-mcp.json`, `ai-scripts/`, `commands/`, `rules/`, `skills/`, and -`plugin/`. +`playwright-mcp.json`, `ai-scripts/`, `commands/`, `rules/`, and `skills/`. ```bash git submodule add -b release .opencode @@ -110,8 +109,7 @@ analysis flows should live in local overlays such as: - Commands: see `commands/README.md` - Rules: see `rules/README.md` - Skills: currently `skills/gh-auth/SKILL.md`, - `skills/commit-message-guard/SKILL.md`, and - `skills/graphify/SKILL.md` + `skills/commit-message-guard/SKILL.md` - Directory indexes: `rules/directory-index.md` defines agent-owned `INDEX.md` files for navigable local context in large directories. A repository-root `INDEX.md` lists known directory indexes and is loaded by `opencode.json` diff --git a/README_release.md b/README_release.md index 01f2b66..896af75 100644 --- a/README_release.md +++ b/README_release.md @@ -2,12 +2,12 @@ This repository provides a reusable OpenCode workspace that consuming git repositories mount as a `.opencode` submodule. It gives an LLM coding agent a -shared set of rules, commands, skills, helper scripts, and OpenCode plugin +shared set of rules, commands, skills, helper scripts, and OpenCode runtime configuration while leaving project-specific behavior in the consuming repo. ## What This Submodule Provides -- `opencode.json` loads the shared instructions, MCP servers, plugin files, and +- `opencode.json` loads the shared instructions, MCP servers, and external-directory permissions expected by OpenCode. - `opencode.json` can load a repository-root `INDEX.md` owned by the consuming repository; the shared `.opencode` submodule does not ship that file. @@ -18,12 +18,10 @@ configuration while leaving project-specific behavior in the consuming repo. - `commands/` contains reusable slash-command workflows such as `/save`, `/commit`, `/learn`, `/update-chat`, `/git-sync`, `/rebase`, `/task`, `/update-index`, and `/update-submodules`. -- `skills/` contains targeted reusable workflows, currently `gh-auth`, - `commit-message-guard`, and `graphify`. +- `skills/` contains targeted reusable workflows, currently `gh-auth` and + `commit-message-guard`. - `ai-scripts/` contains helper scripts used by the commands and skills, such as `commit-message-guard.sh`. -- `plugin/` contains Graphify OpenCode integration files. Graphify is optional - and should only build or update graphs when the user explicitly asks for it. - `playwright-mcp.json` contains shared browser launch settings used by the `playwright` MCP server in `opencode.json`. - `LICENSE` carries the Zero-Clause BSD terms for Codegeist-owned material in @@ -33,7 +31,7 @@ The generated `release` branch is intentionally minimal. During release copy, this source file is renamed from `README_release.md` to `README.md`. The release branch should contain only runtime files needed by consuming repositories: `.gitignore`, `LICENSE`, `README.md`, `opencode.json`, `playwright-mcp.json`, -`ai-scripts/`, `commands/`, `rules/`, `skills/`, and `plugin/`. +`ai-scripts/`, `commands/`, `rules/`, and `skills/`. ## Changelog @@ -48,6 +46,8 @@ branch should contain only runtime files needed by consuming repositories: - Moved Playwright MCP snapshots, console logs, screenshots, and related output under the workspace-local ignored `.chrome/playwright-mcp/` directory instead of creating `.playwright-mcp/` at the workspace root. +- Removed the Graphify OpenCode plugin, instruction, and skill from the shared + runtime bundle. - Explicitly pass Playwright MCP's `--sandbox` CLI override in addition to the browser launch option so current `@playwright/mcp@latest` releases no longer add the unsupported `--no-sandbox` Chrome argument during config merging. @@ -262,7 +262,7 @@ Expected autonomous workflow for the agent: create it as root-owned and unwritable to the workspace user. 3. Implement the requested shared `command`, `rule`, `skill`, or `config` in the source paths of that temporary checkout: `commands/`, `rules/`, `skills/`, - `ai-scripts/`, `plugin/`, `opencode.json`, `playwright-mcp.json`, and + `ai-scripts/`, `opencode.json`, `playwright-mcp.json`, and `README_release.md` as applicable. For `move`, start only from the explicitly selected `.oc_local/commands/`, `.oc_local/rules/`, or `.oc_local/skills/` overlays @@ -387,16 +387,6 @@ authentication. - Use `/learn` for reusable guidance that should become a durable rule. - Prefer updating an existing rule over adding broad or duplicative guidance. -## Graphify Notes - -Graphify is available as an optional OpenCode aid. For normal coding tasks: - -- Read existing graph reports under `docs/graphify/` when they are relevant. -- Prefer graph queries only when a matching existing `graph.json` is available. -- Do not run graph-building commands such as `graphify install`, - `graphify update`, or `graphify extract` unless the user explicitly requests - graph generation. - ## Maintaining This Shared Repository The source repository contains development-only files that are not part of the diff --git a/Taskfile.yml b/Taskfile.yml index 4dc149b..2299818 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -21,7 +21,7 @@ # # Related files: # - README_release.md copied as README.md, LICENSE, opencode.json, -# playwright-mcp.json, ai-scripts/, commands/, rules/, skills/, plugin/ +# playwright-mcp.json, ai-scripts/, commands/, rules/, skills/ # - INDEX.md is intentionally excluded from RELEASE_PATHS because it belongs to # the consuming repository root, not the generated .opencode submodule. @@ -32,7 +32,7 @@ vars: RELEASE_REMOTE: '{{default "origin" .RELEASE_REMOTE}}' RELEASE_SOURCE: '{{default "HEAD" .RELEASE_SOURCE}}' RELEASE_WORKTREE: '{{default ".release-build" .RELEASE_WORKTREE}}' - RELEASE_PATHS: README_release.md LICENSE opencode.json playwright-mcp.json ai-scripts commands rules skills plugin + RELEASE_PATHS: README_release.md LICENSE opencode.json playwright-mcp.json ai-scripts commands rules skills TEST_RELEASE_DIR: '{{default "" .TEST_RELEASE_DIR}}' tasks: diff --git a/commands/add-agent-kit.md b/commands/add-agent-kit.md index e3fef09..ab300ac 100644 --- a/commands/add-agent-kit.md +++ b/commands/add-agent-kit.md @@ -82,8 +82,8 @@ Then perform the upstream source workflow autonomously: create it as root-owned and unwritable to the workspace user. 2. In the temporary source checkout, implement the smallest correct shared change in the source paths: `commands/`, `rules/`, `skills/`, `ai-scripts/`, - `plugin/`, `opencode.json`, `playwright-mcp.json`, and - `README_release.md` as applicable. For `move`, copy and generalize the local + `opencode.json`, `playwright-mcp.json`, and `README_release.md` as applicable. + For `move`, copy and generalize the local overlay content into the matching source path instead of keeping consumer-specific assumptions. 3. Keep all durable repository text, command text, rule text, comments, commit diff --git a/opencode.json b/opencode.json index bbbab76..277bcc4 100644 --- a/opencode.json +++ b/opencode.json @@ -22,8 +22,7 @@ ".opencode/rules/software-tests.md", ".opencode/rules/task-workflow.md", ".opencode/rules/taskfile-and-script-creation.md", - ".opencode/README.md", - "plugin/graphify.md" + ".opencode/README.md" ], "watcher": { "ignore": [ @@ -86,9 +85,6 @@ ] } }, - "plugin": [ - "plugin/graphify.js" - ], "permission": { "external_directory": { "/tmp/**": "allow" diff --git a/plugin/graphify.js b/plugin/graphify.js deleted file mode 100644 index e030b27..0000000 --- a/plugin/graphify.js +++ /dev/null @@ -1,40 +0,0 @@ -// graphify.js - OpenCode reminder for existing docs/graphify results. -// -// Why this exists: -// - This repo uses .opencode as a release submodule, so project-specific -// OpenCode plugins must live outside that release checkout. -// - Graphify should not be executed automatically. The plugin only reminds the -// session to use already generated graph outputs under docs/graphify. -// -// Related files: -// - plugin/graphify.md -// - opencode.json - -import { existsSync } from "fs"; -import { join } from "path"; - -const GRAPH_LOCATIONS = [ - "docs/graphify/current/graphify-out", - "docs/graphify/graphify-out", -]; - -export const GraphifyPlugin = async ({ directory }) => { - let reminded = false; - - return { - "tool.execute.before": async (input, output) => { - if (reminded) return; - if (input.tool !== "bash") return; - - const graphDir = GRAPH_LOCATIONS.find((path) => - existsSync(join(directory, path, "graph.json")), - ); - if (!graphDir) return; - - output.args.command = - `printf '[graphify] Existing graph available at ${graphDir}. Read ${graphDir}/GRAPH_REPORT.md before architecture searches.\\n' && ` + - output.args.command; - reminded = true; - }, - }; -}; diff --git a/plugin/graphify.md b/plugin/graphify.md deleted file mode 100644 index 336c7f5..0000000 --- a/plugin/graphify.md +++ /dev/null @@ -1,21 +0,0 @@ -# Graphify For OpenCode - -Use Graphify only as an optional OpenCode aid for existing knowledge graph -results. Do not create or update graphs automatically during normal tasks. - -## Scope - -- Keep Graphify configuration in the root-owned `plugin/` directory, not in the - shared `.opencode/` release submodule. -- Do not create a root `AGENTS.md` for Graphify instructions. -- Store any future Graphify analysis output under `docs/graphify/` so multiple - project graphs can be kept in a consistent documentation location. - -## Usage - -- If a relevant graph already exists under `docs/graphify/`, read its - `GRAPH_REPORT.md` before answering architecture or cross-module questions. -- Prefer `graphify query`, `graphify path`, or `graphify explain` only when a - matching existing `graph.json` is available. -- Do not run `graphify install`, `graphify update`, `graphify extract`, or other - graph-building commands unless the user explicitly asks for graph generation. diff --git a/rules/devcontainer-tools.md b/rules/devcontainer-tools.md index acdeb55..d00b624 100644 --- a/rules/devcontainer-tools.md +++ b/rules/devcontainer-tools.md @@ -45,8 +45,6 @@ the smallest direct way to inspect, edit, build, test, or document the repo. ## AI And Research Helpers - `opencode-ai` provides the OpenCode CLI runtime used by this workspace. -- `graphifyy` supports knowledge-graph extraction and analysis when graph work - is explicitly requested. - `ddgr` performs DuckDuckGo searches from the command line. - `trafilatura` extracts main text content from web pages and HTML documents. - `lxml_html_clean` supports HTML cleaning workflows used by Python tooling. diff --git a/skills/graphify/SKILL.md b/skills/graphify/SKILL.md deleted file mode 100644 index f5e8ad9..0000000 --- a/skills/graphify/SKILL.md +++ /dev/null @@ -1,1281 +0,0 @@ ---- -name: graphify -description: any input (code, docs, papers, images) → knowledge graph → clustered communities → HTML + JSON + audit report -trigger: /graphify ---- - -# /graphify - -Turn any folder of files into a navigable knowledge graph with community detection, an honest audit trail, and three outputs: interactive HTML, GraphRAG-ready JSON, and a plain-language GRAPH_REPORT.md. - -## Usage - -``` -/graphify # full pipeline on current directory → Obsidian vault -/graphify # full pipeline on specific path -/graphify --mode deep # thorough extraction, richer INFERRED edges -/graphify --update # incremental - re-extract only new/changed files -/graphify --cluster-only # rerun clustering on existing graph -/graphify --no-viz # skip visualization, just report + JSON -/graphify --html # (HTML is generated by default - this flag is a no-op) -/graphify --svg # also export graph.svg (embeds in Notion, GitHub) -/graphify --graphml # export graph.graphml (Gephi, yEd) -/graphify --neo4j # generate graphify-out/cypher.txt for Neo4j -/graphify --neo4j-push bolt://localhost:7687 # push directly to Neo4j -/graphify --mcp # start MCP stdio server for agent access -/graphify --watch # watch folder, auto-rebuild on code changes (no LLM needed) -/graphify add # fetch URL, save to ./raw, update graph -/graphify add --author "Name" # tag who wrote it -/graphify add --contributor "Name" # tag who added it to the corpus -/graphify query "" # BFS traversal - broad context -/graphify query "" --dfs # DFS - trace a specific path -/graphify path "AuthModule" "Database" # shortest path between two concepts -/graphify explain "SwinTransformer" # plain-language explanation of a node -``` - -## What graphify is for - -graphify is built around Andrej Karpathy's /raw folder workflow: drop anything into a folder - papers, tweets, screenshots, code, notes - and get a structured knowledge graph that shows you what you didn't know was connected. - -Three things it does that your AI assistant alone cannot: -1. **Persistent graph** - relationships are stored in `graphify-out/graph.json` and survive across sessions. Ask questions weeks later without re-reading everything. -2. **Honest audit trail** - every edge is tagged EXTRACTED, INFERRED, or AMBIGUOUS. You know what was found vs invented. -3. **Cross-document surprise** - community detection finds connections between concepts in different files that you would never think to ask about directly. - -Use it for: -- A codebase you're new to (understand architecture before touching anything) -- A reading list (papers + tweets + notes → one navigable graph) -- A research corpus (citation graph + concept graph in one) -- Your personal /raw folder (drop everything in, let it grow, query it) - -## What You Must Do When Invoked - -If no path was given, use `.` (current directory). Do not ask the user for a path. - -Follow these steps in order. Do not skip steps. - -### Step 1 - Ensure graphify is installed - -```bash -# Detect the correct Python interpreter (handles pipx, venv, system installs) -GRAPHIFY_BIN=$(which graphify 2>/dev/null) -if [ -n "$GRAPHIFY_BIN" ]; then - PYTHON=$(head -1 "$GRAPHIFY_BIN" | tr -d '#!') - case "$PYTHON" in - *[!a-zA-Z0-9/_.-]*) PYTHON="python3" ;; - esac -else - PYTHON="python3" -fi -"$PYTHON" -c "import graphify" 2>/dev/null || "$PYTHON" -m pip install graphifyy -q 2>/dev/null || "$PYTHON" -m pip install graphifyy -q --break-system-packages 2>&1 | tail -3 -# Write interpreter path for all subsequent steps -mkdir -p graphify-out -"$PYTHON" -c "import sys; open('graphify-out/.graphify_python', 'w').write(sys.executable)" -# Force UTF-8 I/O on Windows (prevents garbled CJK/non-ASCII output) -export PYTHONUTF8=1 -``` - -If the import succeeds, print nothing and move straight to Step 2. - -**In every subsequent bash block, replace `python3` with `$(cat graphify-out/.graphify_python)` to use the correct interpreter.** - -### Step 2 - Detect files - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.detect import detect -from pathlib import Path -result = detect(Path('INPUT_PATH')) -print(json.dumps(result)) -" > graphify-out/.graphify_detect.json -``` - -Replace INPUT_PATH with the actual path the user provided. Do NOT cat or print the JSON - read it silently and present a clean summary instead: - -``` -Corpus: X files · ~Y words - code: N files (.py .ts .go ...) - docs: N files (.md .txt ...) - papers: N files (.pdf ...) - images: N files - video: N files (.mp4 .mp3 ...) -``` - -Omit any category with 0 files from the summary. - -Then act on it: -- If `total_files` is 0: stop with "No supported files found in [path]." -- If `skipped_sensitive` is non-empty: mention file count skipped, not the file names. -- Proceed directly to Step 2.5 if video files were detected, or Step 3 if not. - -### Step 2.5 - Transcribe video / audio files (only if video files detected) - -Skip this step entirely if `detect` returned zero `video` files. - -Video and audio files cannot be read directly. Transcribe them to text first, then treat the transcripts as doc files in Step 3. - -**Strategy:** Read the god nodes from the detect output or analysis file. You are already a language model - write a one-sentence domain hint yourself from those labels. Then pass it to Whisper as the initial prompt. No separate API call needed. - -**However**, if the corpus has *only* video files and no other docs/code, use the generic fallback prompt: `"Use proper punctuation and paragraph breaks."` - -**Step 1 - Write the Whisper prompt yourself.** - -Read the top god node labels from detect output or analysis, then compose a short domain hint sentence, for example: - -- Labels: `transformer, attention, encoder, decoder` -> `"Machine learning research on transformer architectures and attention mechanisms. Use proper punctuation and paragraph breaks."` -- Labels: `kubernetes, deployment, pod, helm` -> `"DevOps discussion about Kubernetes deployments and Helm charts. Use proper punctuation and paragraph breaks."` - -Set it as `GRAPHIFY_WHISPER_PROMPT` in the environment before running the transcription command. - -**Step 2 - Transcribe:** - -```bash -$(cat graphify-out/.graphify_python) -c " -import json, os -from pathlib import Path -from graphify.transcribe import transcribe_all - -detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -video_files = detect.get('files', {}).get('video', []) -prompt = os.environ.get('GRAPHIFY_WHISPER_PROMPT', 'Use proper punctuation and paragraph breaks.') - -transcript_paths = transcribe_all(video_files, initial_prompt=prompt) -print(json.dumps(transcript_paths)) -" > graphify-out/.graphify_transcripts.json -``` - -After transcription: -- Read the transcript paths from `graphify-out/.graphify_transcripts.json` -- Add them to the docs list before dispatching semantic subagents in Step 3B -- Print how many transcripts were created: `Transcribed N video file(s) -> treating as docs` -- If transcription fails for a file, print a warning and continue with the rest - -**Whisper model:** Default is `base`. If the user passed `--whisper-model `, set `GRAPHIFY_WHISPER_MODEL=` in the environment before running the command above. - -### Step 3 - Extract entities and relationships - -**Before starting:** note whether `--mode deep` was given. You must pass `DEEP_MODE=true` to every subagent in Step B2 if it was. Track this from the original invocation - do not lose it. - -This step has two parts: **structural extraction** (deterministic, free) and **semantic extraction** (your AI model, costs tokens). - -**Run Part A (AST) and Part B (semantic) in parallel. Dispatch all semantic subagents AND start AST extraction in the same message. Both can run simultaneously since they operate on different file types. Merge results in Part C as before.** - -Note: Parallelizing AST + semantic saves 5-15s on large corpora. AST is deterministic and fast; start it while subagents are processing docs/papers. - -#### Part A - Structural extraction for code files - -For any code files detected, run AST extraction in parallel with Part B subagents: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.extract import collect_files, extract -from pathlib import Path -import json - -code_files = [] -detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -for f in detect.get('files', {}).get('code', []): - code_files.extend(collect_files(Path(f)) if Path(f).is_dir() else [Path(f)]) - -if code_files: - result = extract(code_files) - Path('graphify-out/.graphify_ast.json').write_text(json.dumps(result, indent=2)) - print(f'AST: {len(result[\"nodes\"])} nodes, {len(result[\"edges\"])} edges') -else: - Path('graphify-out/.graphify_ast.json').write_text(json.dumps({'nodes':[],'edges':[],'input_tokens':0,'output_tokens':0})) - print('No code files - skipping AST extraction') -" -``` - -#### Part B - Semantic extraction (parallel subagents) - -**Fast path:** If detection found zero docs, papers, and images (code-only corpus), skip Part B entirely and go straight to Part C. AST handles code - there is nothing for semantic subagents to do. - -**MANDATORY: You MUST use the Agent tool here. Reading files yourself one-by-one is forbidden - it is 5-10x slower. If you do not use the Agent tool you are doing this wrong.** - -Before dispatching subagents, print a timing estimate: -- Load `total_words` and file counts from `graphify-out/.graphify_detect.json` -- Estimate agents needed from the number and size of uncached non-code files. -- Estimate time from the number of planned agent batches. -- Print: "Semantic extraction: ~N files → X agents, estimated ~Ys" - -**Step B0 - Check extraction cache first** - -Before dispatching any subagents, check which files already have cached extraction results: - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.cache import check_semantic_cache -from pathlib import Path - -detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -all_files = [f for files in detect['files'].values() for f in files] - -cached_nodes, cached_edges, cached_hyperedges, uncached = check_semantic_cache(all_files) - -if cached_nodes or cached_edges or cached_hyperedges: - Path('graphify-out/.graphify_cached.json').write_text(json.dumps({'nodes': cached_nodes, 'edges': cached_edges, 'hyperedges': cached_hyperedges})) -Path('graphify-out/.graphify_uncached.txt').write_text('\n'.join(uncached)) -print(f'Cache: {len(all_files)-len(uncached)} files hit, {len(uncached)} files need extraction') -" -``` - -Only dispatch subagents for files listed in `graphify-out/.graphify_uncached.txt`. If all files are cached, skip to Part C directly. - -**Step B1 - Split into chunks** - -Load files from `graphify-out/.graphify_uncached.txt`. Split them into chunks that fit the current agent context and preserve related artifacts together. Each image can get its own chunk when vision context needs separation. When splitting, group files from the same directory together so related artifacts land in the same chunk and cross-file relationships are more likely to be extracted. - -**Step B2 - Dispatch ALL subagents in a single message (OpenCode)** - -> **OpenCode platform:** Uses `@mention` dispatch instead of the Agent tool. All mentions in a single message run in parallel. - -Dispatch one `@mention` per chunk — ALL in the same response: - -``` -@agent Chunk CHUNK_NUM of TOTAL_CHUNKS: [extraction prompt below with FILE_LIST, CHUNK_NUM, TOTAL_CHUNKS, DEEP_MODE substituted] - -@agent Chunk 2 of TOTAL_CHUNKS: [next chunk] -``` - -Wait for all agents to return. Parse each response as JSON. Accumulate nodes/edges/hyperedges across all results and write to `graphify-out/.graphify_semantic_new.json`. - -The extraction prompt each agent receives (substitute FILE_LIST, CHUNK_NUM, TOTAL_CHUNKS, DEEP_MODE): - -``` -You are a graphify extraction subagent. Read the files listed and extract a knowledge graph fragment. -Output ONLY valid JSON matching the schema below - no explanation, no markdown fences, no preamble. - -Files (chunk CHUNK_NUM of TOTAL_CHUNKS): -FILE_LIST - -Rules: -- EXTRACTED: relationship explicit in source (import, call, citation, "see §3.2") -- INFERRED: reasonable inference (shared data structure, implied dependency) -- AMBIGUOUS: uncertain - flag for review, do not omit - -Code files: focus on semantic edges AST cannot find (call relationships, shared data, arch patterns). - Do not re-extract imports - AST already has those. -Doc/paper files: extract named concepts, entities, citations. For rationale (WHY decisions were made, trade-offs, design intent): store as a `rationale` attribute on the relevant concept node — do NOT create a separate rationale node or fragment node. Only create a node for something that is itself a named entity or concept. Use `file_type:"rationale"` for concept-like nodes (ideas, principles, mechanisms, design patterns). Do NOT invent file_types like `concept` — valid values are only `code|document|paper|image|rationale`. -Code files: when adding `calls` edges, source MUST be the caller (the function/class doing the calling), target MUST be the callee. Never reverse this direction. -Image files: use vision to understand what the image IS - do not just OCR. - UI screenshot: layout patterns, design decisions, key elements, purpose. - Chart: metric, trend/insight, data source. - Tweet/post: claim as node, author, concepts mentioned. - Diagram: components and connections. - Research figure: what it demonstrates, method, result. - Handwritten/whiteboard: ideas and arrows, mark uncertain readings AMBIGUOUS. - -DEEP_MODE (if --mode deep was given): be aggressive with INFERRED edges - indirect deps, - shared assumptions, latent couplings. Mark uncertain ones AMBIGUOUS instead of omitting. - -Semantic similarity: if two concepts in this chunk solve the same problem or represent the same idea without any structural link (no import, no call, no citation), add a `semantically_similar_to` edge marked INFERRED with a confidence_score reflecting how similar they are (0.6-0.95). Examples: -- Two functions that both validate user input but never call each other -- A class in code and a concept in a paper that describe the same algorithm -- Two error types that handle the same failure mode differently -Only add these when the similarity is genuinely non-obvious and cross-cutting. Do not add them for trivially similar things. - -Hyperedges: if multiple nodes clearly participate together in a shared concept, flow, or pattern that is not captured by pairwise edges alone, add a hyperedge to a top-level `hyperedges` array. Examples: -- All classes that implement a common protocol or interface -- All functions in an authentication flow (even if they don't all call each other) -- All concepts from a paper section that form one coherent idea -Use sparingly — only when the group relationship adds information beyond the pairwise edges. - -If a file has YAML frontmatter (--- ... ---), copy source_url, captured_at, author, - contributor onto every node from that file. - -confidence_score is REQUIRED on every edge - never omit it, never use 0.5 as a default: -- EXTRACTED edges: confidence_score = 1.0 always -- INFERRED edges: reason about each edge individually. - Direct structural evidence (shared data structure, clear dependency): 0.8-0.9. - Reasonable inference with some uncertainty: 0.6-0.7. - Weak or speculative: 0.4-0.5. Most edges should be 0.6-0.9, not 0.5. -- AMBIGUOUS edges: 0.1-0.3 - -Output exactly this JSON (no other text): -{"nodes":[{"id":"filestem_entityname","label":"Human Readable Name","file_type":"code|document|paper|image|rationale","source_file":"relative/path","source_location":null,"source_url":null,"captured_at":null,"author":null,"contributor":null}],"edges":[{"source":"node_id","target":"node_id","relation":"calls|implements|references|cites|conceptually_related_to|shares_data_with|semantically_similar_to|rationale_for","confidence":"EXTRACTED|INFERRED|AMBIGUOUS","confidence_score":1.0,"source_file":"relative/path","source_location":null,"weight":1.0}],"hyperedges":[{"id":"snake_case_id","label":"Human Readable Label","nodes":["node_id1","node_id2","node_id3"],"relation":"participate_in|implement|form","confidence":"EXTRACTED|INFERRED","confidence_score":0.75,"source_file":"relative/path"}],"input_tokens":0,"output_tokens":0} -``` - -**Step B3 - Collect, cache, and merge** - -Wait for all subagents. For each result: -- Check that `graphify-out/.graphify_chunk_NN.json` exists on disk — this is the success signal -- If the file exists and contains valid JSON with `nodes` and `edges`, include it and save to cache -- If the file is missing, the subagent was likely dispatched as read-only (Explore type) — print a warning: "chunk N missing from disk — subagent may have been read-only. Re-run with general-purpose agent." Do not silently skip. -- If a subagent failed or returned invalid JSON, print a warning and skip that chunk - do not abort - -If chunks failed or are missing, report the affected chunks and continue with the valid chunk files that were produced. - -Merge all chunk files into `.graphify_semantic_new.json`. **After each Agent call completes, read the real token counts from the Agent tool result's `usage` field and write them back into the chunk JSON before merging** — the chunk JSON itself always has placeholder zeros. Then run: -```bash -$(cat graphify-out/.graphify_python) -c " -import json, glob -from pathlib import Path - -chunks = sorted(glob.glob('graphify-out/.graphify_chunk_*.json')) -all_nodes, all_edges, all_hyperedges = [], [], [] -total_in, total_out = 0, 0 -for c in chunks: - d = json.loads(Path(c).read_text()) - all_nodes += d.get('nodes', []) - all_edges += d.get('edges', []) - all_hyperedges += d.get('hyperedges', []) - total_in += d.get('input_tokens', 0) - total_out += d.get('output_tokens', 0) -Path('graphify-out/.graphify_semantic_new.json').write_text(json.dumps({ - 'nodes': all_nodes, 'edges': all_edges, 'hyperedges': all_hyperedges, - 'input_tokens': total_in, 'output_tokens': total_out, -}, indent=2)) -print(f'Merged {len(chunks)} chunks: {total_in:,} in / {total_out:,} out tokens') -" -``` - -Save new results to cache: -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.cache import save_semantic_cache -from pathlib import Path - -new = json.loads(Path('graphify-out/.graphify_semantic_new.json').read_text()) if Path('graphify-out/.graphify_semantic_new.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]} -saved = save_semantic_cache(new.get('nodes', []), new.get('edges', []), new.get('hyperedges', [])) -print(f'Cached {saved} files') -" -``` - -Merge cached + new results into `graphify-out/.graphify_semantic.json`: -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from pathlib import Path - -cached = json.loads(Path('graphify-out/.graphify_cached.json').read_text()) if Path('graphify-out/.graphify_cached.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]} -new = json.loads(Path('graphify-out/.graphify_semantic_new.json').read_text()) if Path('graphify-out/.graphify_semantic_new.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]} - -all_nodes = cached['nodes'] + new.get('nodes', []) -all_edges = cached['edges'] + new.get('edges', []) -all_hyperedges = cached.get('hyperedges', []) + new.get('hyperedges', []) -seen = set() -deduped = [] -for n in all_nodes: - if n['id'] not in seen: - seen.add(n['id']) - deduped.append(n) - -merged = { - 'nodes': deduped, - 'edges': all_edges, - 'hyperedges': all_hyperedges, - 'input_tokens': new.get('input_tokens', 0), - 'output_tokens': new.get('output_tokens', 0), -} -Path('graphify-out/.graphify_semantic.json').write_text(json.dumps(merged, indent=2)) -print(f'Extraction complete - {len(deduped)} nodes, {len(all_edges)} edges ({len(cached[\"nodes\"])} from cache, {len(new.get(\"nodes\",[]))} new)') -" -``` -Clean up temp files: `rm -f graphify-out/.graphify_cached.json graphify-out/.graphify_uncached.txt graphify-out/.graphify_semantic_new.json` - -#### Part C - Merge AST + semantic into final extraction - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from pathlib import Path - -ast = json.loads(Path('graphify-out/.graphify_ast.json').read_text()) -sem = json.loads(Path('graphify-out/.graphify_semantic.json').read_text()) - -# Merge: AST nodes first, semantic nodes deduplicated by id -seen = {n['id'] for n in ast['nodes']} -merged_nodes = list(ast['nodes']) -for n in sem['nodes']: - if n['id'] not in seen: - merged_nodes.append(n) - seen.add(n['id']) - -merged_edges = ast['edges'] + sem['edges'] -merged_hyperedges = sem.get('hyperedges', []) -merged = { - 'nodes': merged_nodes, - 'edges': merged_edges, - 'hyperedges': merged_hyperedges, - 'input_tokens': sem.get('input_tokens', 0), - 'output_tokens': sem.get('output_tokens', 0), -} -Path('graphify-out/.graphify_extract.json').write_text(json.dumps(merged, indent=2)) -total = len(merged_nodes) -edges = len(merged_edges) -print(f'Merged: {total} nodes, {edges} edges ({len(ast[\"nodes\"])} AST + {len(sem[\"nodes\"])} semantic)') -" -``` - -### Step 4 - Build graph, cluster, analyze, generate outputs - -```bash -mkdir -p graphify-out -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.cluster import cluster, score_all -from graphify.analyze import god_nodes, surprising_connections, suggest_questions -from graphify.report import generate -from graphify.export import to_json -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -detection = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) - -G = build_from_json(extraction) -communities = cluster(G) -cohesion = score_all(G, communities) -tokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)} -gods = god_nodes(G) -surprises = surprising_connections(G, communities) -labels = {cid: 'Community ' + str(cid) for cid in communities} -# Placeholder questions - regenerated with real labels in Step 5 -questions = suggest_questions(G, communities, labels) - -report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, 'INPUT_PATH', suggested_questions=questions) -Path('graphify-out/GRAPH_REPORT.md').write_text(report) -to_json(G, communities, 'graphify-out/graph.json') - -analysis = { - 'communities': {str(k): v for k, v in communities.items()}, - 'cohesion': {str(k): v for k, v in cohesion.items()}, - 'gods': gods, - 'surprises': surprises, - 'questions': questions, -} -Path('graphify-out/.graphify_analysis.json').write_text(json.dumps(analysis, indent=2)) -if G.number_of_nodes() == 0: - print('ERROR: Graph is empty - extraction produced no nodes.') - print('Possible causes: all files were skipped, binary-only corpus, or extraction failed.') - raise SystemExit(1) -print(f'Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges, {len(communities)} communities') -" -``` - -If this step prints `ERROR: Graph is empty`, stop and tell the user what happened - do not proceed to labeling or visualization. - -Replace INPUT_PATH with the actual path. - -### Step 5 - Label communities - -Read `graphify-out/.graphify_analysis.json`. For each community key, look at its node labels and write a 2-5 word plain-language name (e.g. "Attention Mechanism", "Training Pipeline", "Data Loading"). - -Then regenerate the report and save the labels for the visualizer: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.cluster import score_all -from graphify.analyze import god_nodes, surprising_connections, suggest_questions -from graphify.report import generate -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -detection = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} -cohesion = {int(k): v for k, v in analysis['cohesion'].items()} -tokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)} - -# LABELS - replace these with the names you chose above -labels = LABELS_DICT - -# Regenerate questions with real community labels (labels affect question phrasing) -questions = suggest_questions(G, communities, labels) - -report = generate(G, communities, cohesion, labels, analysis['gods'], analysis['surprises'], detection, tokens, 'INPUT_PATH', suggested_questions=questions) -Path('graphify-out/GRAPH_REPORT.md').write_text(report) -Path('graphify-out/.graphify_labels.json').write_text(json.dumps({str(k): v for k, v in labels.items()})) -print('Report updated with community labels') -" -``` - -Replace `LABELS_DICT` with the actual dict you constructed (e.g. `{0: "Attention Mechanism", 1: "Training Pipeline"}`). -Replace INPUT_PATH with the actual path. - -### Step 6 - Generate Obsidian vault (opt-in) + HTML - -**Generate HTML always** (unless `--no-viz`). **Obsidian vault only if `--obsidian` was explicitly given** — skip it otherwise, it generates one file per node. - -If `--obsidian` was given: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.export import to_obsidian, to_canvas -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) -labels_raw = json.loads(Path('graphify-out/.graphify_labels.json').read_text()) if Path('graphify-out/.graphify_labels.json').exists() else {} - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} -cohesion = {int(k): v for k, v in analysis['cohesion'].items()} -labels = {int(k): v for k, v in labels_raw.items()} - -n = to_obsidian(G, communities, 'graphify-out/obsidian', community_labels=labels or None, cohesion=cohesion) -print(f'Obsidian vault: {n} notes in graphify-out/obsidian/') - -to_canvas(G, communities, 'graphify-out/obsidian/graph.canvas', community_labels=labels or None) -print('Canvas: graphify-out/obsidian/graph.canvas - open in Obsidian for structured community layout') -print() -print('Open graphify-out/obsidian/ as a vault in Obsidian.') -print(' Graph view - nodes colored by community (set automatically)') -print(' graph.canvas - structured layout with communities as groups') -print(' _COMMUNITY_* - overview notes with cohesion scores and dataview queries') -" -``` - -Generate the HTML graph (always, unless `--no-viz`): - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.export import to_html -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) -labels_raw = json.loads(Path('graphify-out/.graphify_labels.json').read_text()) if Path('graphify-out/.graphify_labels.json').exists() else {} - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} -labels = {int(k): v for k, v in labels_raw.items()} - -to_html(G, communities, 'graphify-out/graph.html', community_labels=labels or None) -print('graph.html written - open in any browser, no server needed') -" -``` - -### Step 6b - Wiki (only if --wiki flag) - -**Only run this step if `--wiki` was explicitly given in the original command.** - -Run this before Step 9 (cleanup) so `graphify-out/.graphify_labels.json` is still available. - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.build import build_from_json -from graphify.wiki import to_wiki -from graphify.analyze import god_nodes -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) -labels_raw = json.loads(Path('graphify-out/.graphify_labels.json').read_text()) if Path('graphify-out/.graphify_labels.json').exists() else {} - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} -cohesion = {int(k): v for k, v in analysis['cohesion'].items()} -labels = {int(k): v for k, v in labels_raw.items()} -gods = god_nodes(G) - -n = to_wiki(G, communities, 'graphify-out/wiki', community_labels=labels or None, cohesion=cohesion, god_nodes_data=gods) -print(f'Wiki: {n} articles written to graphify-out/wiki/') -print(' graphify-out/wiki/index.md -> agent entry point') -" -``` - -### Step 7 - Neo4j export (only if --neo4j or --neo4j-push flag) - -**If `--neo4j`** - generate a Cypher file for manual import: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.export import to_cypher -from pathlib import Path - -G = build_from_json(json.loads(Path('graphify-out/.graphify_extract.json').read_text())) -to_cypher(G, 'graphify-out/cypher.txt') -print('cypher.txt written - import with: cypher-shell < graphify-out/cypher.txt') -" -``` - -**If `--neo4j-push `** - push directly to a running Neo4j instance. Ask the user for credentials if not provided: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.cluster import cluster -from graphify.export import push_to_neo4j -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} - -result = push_to_neo4j(G, uri='NEO4J_URI', user='NEO4J_USER', password='NEO4J_PASSWORD', communities=communities) -print(f'Pushed to Neo4j: {result[\"nodes\"]} nodes, {result[\"edges\"]} edges') -" -``` - -Replace `NEO4J_URI`, `NEO4J_USER`, `NEO4J_PASSWORD` with actual values. Default URI is `bolt://localhost:7687`, default user is `neo4j`. Uses MERGE - safe to re-run without creating duplicates. - -### Step 7b - SVG export (only if --svg flag) - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.export import to_svg -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) -labels_raw = json.loads(Path('graphify-out/.graphify_labels.json').read_text()) if Path('graphify-out/.graphify_labels.json').exists() else {} - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} -labels = {int(k): v for k, v in labels_raw.items()} - -to_svg(G, communities, 'graphify-out/graph.svg', community_labels=labels or None) -print('graph.svg written - embeds in Obsidian, Notion, GitHub READMEs') -" -``` - -### Step 7c - GraphML export (only if --graphml flag) - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.build import build_from_json -from graphify.export import to_graphml -from pathlib import Path - -extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text()) - -G = build_from_json(extraction) -communities = {int(k): v for k, v in analysis['communities'].items()} - -to_graphml(G, communities, 'graphify-out/graph.graphml') -print('graph.graphml written - open in Gephi, yEd, or any GraphML tool') -" -``` - -### Step 7d - MCP server (only if --mcp flag) - -```bash -python3 -m graphify.serve graphify-out/graph.json -``` - -This starts a stdio MCP server that exposes tools: `query_graph`, `get_node`, `get_neighbors`, `get_community`, `god_nodes`, `graph_stats`, `shortest_path`. Add to Claude Desktop or any MCP-compatible agent orchestrator so other agents can query the graph live. - -To configure in Claude Desktop, add to `claude_desktop_config.json`: -```json -{ - "mcpServers": { - "graphify": { - "command": "python3", - "args": ["-m", "graphify.serve", "/absolute/path/to/graphify-out/graph.json"] - } - } -} -``` - -### Step 8 - Token reduction benchmark - -Run the token reduction benchmark: - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.benchmark import run_benchmark, print_benchmark -from pathlib import Path - -detection = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -result = run_benchmark('graphify-out/graph.json', corpus_words=detection['total_words']) -print_benchmark(result) -" -``` - -Print the output directly in chat. - ---- - -### Step 9 - Save manifest, update cost tracker, clean up, and report - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from pathlib import Path -from datetime import datetime, timezone -from graphify.detect import save_manifest - -# Save manifest for --update -detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text()) -save_manifest(detect['files']) - -# Update cumulative cost tracker -extract = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -input_tok = extract.get('input_tokens', 0) -output_tok = extract.get('output_tokens', 0) - -cost_path = Path('graphify-out/cost.json') -if cost_path.exists(): - cost = json.loads(cost_path.read_text()) -else: - cost = {'runs': [], 'total_input_tokens': 0, 'total_output_tokens': 0} - -cost['runs'].append({ - 'date': datetime.now(timezone.utc).isoformat(), - 'input_tokens': input_tok, - 'output_tokens': output_tok, - 'files': detect.get('total_files', 0), -}) -cost['total_input_tokens'] += input_tok -cost['total_output_tokens'] += output_tok -cost_path.write_text(json.dumps(cost, indent=2)) - -print(f'This run: {input_tok:,} input tokens, {output_tok:,} output tokens') -print(f'All time: {cost[\"total_input_tokens\"]:,} input, {cost[\"total_output_tokens\"]:,} output ({len(cost[\"runs\"])} runs)') -" -rm -f graphify-out/.graphify_detect.json graphify-out/.graphify_extract.json graphify-out/.graphify_ast.json graphify-out/.graphify_semantic.json graphify-out/.graphify_analysis.json graphify-out/.graphify_labels.json graphify-out/.graphify_chunk_*.json -rm -f graphify-out/.needs_update 2>/dev/null || true -``` - -Tell the user (omit the obsidian line unless --obsidian was given): -``` -Graph complete. Outputs in PATH_TO_DIR/graphify-out/ - - graph.html - interactive graph, open in browser - GRAPH_REPORT.md - audit report - graph.json - raw graph data - obsidian/ - Obsidian vault (only if --obsidian was given) -``` - -If graphify saved you time, consider supporting it: https://github.com/sponsors/safishamsi - -Replace PATH_TO_DIR with the actual absolute path of the directory that was processed. - -Then paste these sections from GRAPH_REPORT.md directly into the chat: -- God Nodes -- Surprising Connections -- Suggested Questions - -Do NOT paste the full report - just those three sections. Keep it concise. - -Then immediately offer to explore. Pick the single most interesting suggested question from the report - the one that crosses the most community boundaries or has the most surprising bridge node - and ask: - -> "The most interesting question this graph can answer: **[question]**. Want me to trace it?" - -If the user says yes, run `/graphify query "[question]"` on the graph and walk them through the answer using the graph structure - which nodes connect, which community boundaries get crossed, what the path reveals. Keep going as long as they want to explore. Each answer should end with a natural follow-up ("this connects to X - want to go deeper?") so the session feels like navigation, not a one-shot report. - -The graph is the map. Your job after the pipeline is to be the guide. - ---- - -## For --update (incremental re-extraction) - -Use when you've added or modified files since the last run. Only re-extracts changed files - saves tokens and time. - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.detect import detect_incremental, save_manifest -from pathlib import Path - -result = detect_incremental(Path('INPUT_PATH')) -new_total = result.get('new_total', 0) -print(json.dumps(result, indent=2)) -Path('graphify-out/.graphify_incremental.json').write_text(json.dumps(result)) -if new_total == 0: - print('No files changed since last run. Nothing to update.') - raise SystemExit(0) -print(f'{new_total} new/changed file(s) to re-extract.') -" -``` - -If new files exist, first check whether all changed files are code files: - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from pathlib import Path - -result = json.loads(open('graphify-out/.graphify_incremental.json').read()) if Path('graphify-out/.graphify_incremental.json').exists() else {} -code_exts = {'.py','.ts','.js','.go','.rs','.java','.cpp','.c','.rb','.swift','.kt','.cs','.scala','.php','.cc','.cxx','.hpp','.h','.kts'} -new_files = result.get('new_files', {}) -all_changed = [f for files in new_files.values() for f in files] -code_only = all(Path(f).suffix.lower() in code_exts for f in all_changed) -print('code_only:', code_only) -" -``` - -If `code_only` is True: print `[graphify update] Code-only changes detected - skipping semantic extraction (no LLM needed)`, run only Step 3A (AST) on the changed files, skip Step 3B entirely (no subagents), then go straight to merge and Steps 4–8. - -If `code_only` is False (any changed file is a doc/paper/image): run the full Steps 3A–3C pipeline as normal. - -Then: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.build import build_from_json -from graphify.export import to_json -from networkx.readwrite import json_graph -import networkx as nx -from pathlib import Path - -# Load existing graph -existing_data = json.loads(Path('graphify-out/graph.json').read_text()) -G_existing = json_graph.node_link_graph(existing_data, edges='links') - -# Load new extraction -new_extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -G_new = build_from_json(new_extraction) - -# Merge: new nodes/edges into existing graph -G_existing.update(G_new) -print(f'Merged: {G_existing.number_of_nodes()} nodes, {G_existing.number_of_edges()} edges') -" -``` - -Then run Steps 4–8 on the merged graph as normal. - -After Step 4, show the graph diff: - -```bash -$(cat graphify-out/.graphify_python) -c " -import json -from graphify.analyze import graph_diff -from graphify.build import build_from_json -from networkx.readwrite import json_graph -import networkx as nx -from pathlib import Path - -# Load old graph (before update) from backup written before merge -old_data = json.loads(Path('graphify-out/.graphify_old.json').read_text()) if Path('graphify-out/.graphify_old.json').exists() else None -new_extract = json.loads(Path('graphify-out/.graphify_extract.json').read_text()) -G_new = build_from_json(new_extract) - -if old_data: - G_old = json_graph.node_link_graph(old_data, edges='links') - diff = graph_diff(G_old, G_new) - print(diff['summary']) - if diff['new_nodes']: - print('New nodes:', ', '.join(n['label'] for n in diff['new_nodes'][:5])) - if diff['new_edges']: - print('New edges:', len(diff['new_edges'])) -" -``` - -Before the merge step, save the old graph: `cp graphify-out/graph.json graphify-out/.graphify_old.json` -Clean up after: `rm -f graphify-out/.graphify_old.json` - ---- - -## For --cluster-only - -Skip Steps 1–3. Load the existing graph from `graphify-out/graph.json` and re-run clustering: - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from graphify.cluster import cluster, score_all -from graphify.analyze import god_nodes, surprising_connections -from graphify.report import generate -from graphify.export import to_json -from networkx.readwrite import json_graph -import networkx as nx -from pathlib import Path - -data = json.loads(Path('graphify-out/graph.json').read_text()) -G = json_graph.node_link_graph(data, edges='links') - -detection = {'total_files': 0, 'total_words': 99999, 'needs_graph': True, 'warning': None, - 'files': {'code': [], 'document': [], 'paper': []}} -tokens = {'input': 0, 'output': 0} - -communities = cluster(G) -cohesion = score_all(G, communities) -gods = god_nodes(G) -surprises = surprising_connections(G, communities) -labels = {cid: 'Community ' + str(cid) for cid in communities} - -report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, '.') -Path('graphify-out/GRAPH_REPORT.md').write_text(report) -to_json(G, communities, 'graphify-out/graph.json') - -analysis = { - 'communities': {str(k): v for k, v in communities.items()}, - 'cohesion': {str(k): v for k, v in cohesion.items()}, - 'gods': gods, - 'surprises': surprises, -} -Path('graphify-out/.graphify_analysis.json').write_text(json.dumps(analysis, indent=2)) -print(f'Re-clustered: {len(communities)} communities') -" -``` - -Then run Steps 5–9 as normal (label communities, generate viz, benchmark, clean up, report). - ---- - -## For /graphify query - -Two traversal modes - choose based on the question: - -| Mode | Flag | Best for | -|------|------|----------| -| BFS (default) | _(none)_ | "What is X connected to?" - broad context, nearest neighbors first | -| DFS | `--dfs` | "How does X reach Y?" - trace a specific chain or dependency path | - -First check the graph exists: -```bash -$(cat graphify-out/.graphify_python) -c " -from pathlib import Path -if not Path('graphify-out/graph.json').exists(): - print('ERROR: No graph found. Run /graphify first to build the graph.') - raise SystemExit(1) -" -``` -If it fails, stop and tell the user to run `/graphify ` first. - -Load `graphify-out/graph.json`, then: - -1. Find the nodes whose label best matches key terms in the question. -2. Run the appropriate traversal from each starting node. -3. Read the subgraph - node labels, edge relations, confidence tags, source locations. -4. Answer using **only** what the graph contains. Quote `source_location` when citing a specific fact. -5. If the graph lacks enough information, say so - do not hallucinate edges. - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys, json -from networkx.readwrite import json_graph -import networkx as nx -from pathlib import Path - -data = json.loads(Path('graphify-out/graph.json').read_text()) -G = json_graph.node_link_graph(data, edges='links') - -question = 'QUESTION' -mode = 'MODE' # 'bfs' or 'dfs' -terms = [t.lower() for t in question.split() if len(t) > 3] - -# Find best-matching start nodes -scored = [] -for nid, ndata in G.nodes(data=True): - label = ndata.get('label', '').lower() - score = sum(1 for t in terms if t in label) - if score > 0: - scored.append((score, nid)) -scored.sort(reverse=True) -start_nodes = [nid for _, nid in scored] - -if not start_nodes: - print('No matching nodes found for query terms:', terms) - sys.exit(0) - -subgraph_nodes = set() -subgraph_edges = [] - -if mode == 'dfs': - # DFS: follow one path as deep as possible before backtracking. - visited = set() - stack = [(n, 0) for n in reversed(start_nodes)] - while stack: - node, depth = stack.pop() - if node in visited: - continue - visited.add(node) - subgraph_nodes.add(node) - for neighbor in G.neighbors(node): - if neighbor not in visited: - stack.append((neighbor, depth + 1)) - subgraph_edges.append((node, neighbor)) -else: - # BFS: explore all neighbors layer by layer. - frontier = set(start_nodes) - subgraph_nodes = set(start_nodes) - while frontier: - next_frontier = set() - for n in frontier: - for neighbor in G.neighbors(n): - if neighbor not in subgraph_nodes: - next_frontier.add(neighbor) - subgraph_edges.append((n, neighbor)) - subgraph_nodes.update(next_frontier) - frontier = next_frontier - -# Score each node by term overlap for ranked output -def relevance(nid): - label = G.nodes[nid].get('label', '').lower() - return sum(1 for t in terms if t in label) - -ranked_nodes = sorted(subgraph_nodes, key=relevance, reverse=True) - -lines = [f'Traversal: {mode.upper()} | Start: {[G.nodes[n].get(\"label\",n) for n in start_nodes]} | {len(subgraph_nodes)} nodes'] -for nid in ranked_nodes: - d = G.nodes[nid] - lines.append(f' NODE {d.get(\"label\", nid)} [src={d.get(\"source_file\",\"\")} loc={d.get(\"source_location\",\"\")}]') -for u, v in subgraph_edges: - if u in subgraph_nodes and v in subgraph_nodes: - d = G.edges[u, v] - lines.append(f' EDGE {G.nodes[u].get(\"label\",u)} --{d.get(\"relation\",\"\")} [{d.get(\"confidence\",\"\")}]--> {G.nodes[v].get(\"label\",v)}') - -output = '\n'.join(lines) -print(output) -" -``` - -Replace `QUESTION` with the user's actual question and `MODE` with `bfs` or `dfs`. Then answer based on the subgraph output above. - -After writing the answer, save it back into the graph so it improves future queries: - -```bash -$(cat graphify-out/.graphify_python) -m graphify save-result --question "QUESTION" --answer "ANSWER" --type query --nodes NODE1 NODE2 -``` - -Replace `QUESTION` with the question, `ANSWER` with your full answer text, `SOURCE_NODES` with the list of node labels you cited. This closes the feedback loop: the next `--update` will extract this Q&A as a node in the graph. - ---- - -## For /graphify path - -Find the shortest path between two named concepts in the graph. - -First check the graph exists: -```bash -$(cat graphify-out/.graphify_python) -c " -from pathlib import Path -if not Path('graphify-out/graph.json').exists(): - print('ERROR: No graph found. Run /graphify first to build the graph.') - raise SystemExit(1) -" -``` -If it fails, stop and tell the user to run `/graphify ` first. - -```bash -$(cat graphify-out/.graphify_python) -c " -import json, sys -import networkx as nx -from networkx.readwrite import json_graph -from pathlib import Path - -data = json.loads(Path('graphify-out/graph.json').read_text()) -G = json_graph.node_link_graph(data, edges='links') - -a_term = 'NODE_A' -b_term = 'NODE_B' - -def find_node(term): - term = term.lower() - scored = sorted( - [(sum(1 for w in term.split() if w in G.nodes[n].get('label','').lower()), n) - for n in G.nodes()], - reverse=True - ) - return scored[0][1] if scored and scored[0][0] > 0 else None - -src = find_node(a_term) -tgt = find_node(b_term) - -if not src or not tgt: - print(f'Could not find nodes matching: {a_term!r} or {b_term!r}') - sys.exit(0) - -try: - path = nx.shortest_path(G, src, tgt) - print(f'Shortest path ({len(path)-1} hops):') - for i, nid in enumerate(path): - label = G.nodes[nid].get('label', nid) - if i < len(path) - 1: - edge = G.edges[nid, path[i+1]] - rel = edge.get('relation', '') - conf = edge.get('confidence', '') - print(f' {label} --{rel}--> [{conf}]') - else: - print(f' {label}') -except nx.NetworkXNoPath: - print(f'No path found between {a_term!r} and {b_term!r}') -except nx.NodeNotFound as e: - print(f'Node not found: {e}') -" -``` - -Replace `NODE_A` and `NODE_B` with the actual concept names from the user. Then explain the path in plain language - what each hop means, why it's significant. - -After writing the explanation, save it back: - -```bash -$(cat graphify-out/.graphify_python) -m graphify save-result --question "Path from NODE_A to NODE_B" --answer "ANSWER" --type path_query --nodes NODE_A NODE_B -``` - ---- - -## For /graphify explain - -Give a plain-language explanation of a single node - everything connected to it. - -First check the graph exists: -```bash -$(cat graphify-out/.graphify_python) -c " -from pathlib import Path -if not Path('graphify-out/graph.json').exists(): - print('ERROR: No graph found. Run /graphify first to build the graph.') - raise SystemExit(1) -" -``` -If it fails, stop and tell the user to run `/graphify ` first. - -```bash -$(cat graphify-out/.graphify_python) -c " -import json, sys -import networkx as nx -from networkx.readwrite import json_graph -from pathlib import Path - -data = json.loads(Path('graphify-out/graph.json').read_text()) -G = json_graph.node_link_graph(data, edges='links') - -term = 'NODE_NAME' -term_lower = term.lower() - -# Find best matching node -scored = sorted( - [(sum(1 for w in term_lower.split() if w in G.nodes[n].get('label','').lower()), n) - for n in G.nodes()], - reverse=True -) -if not scored or scored[0][0] == 0: - print(f'No node matching {term!r}') - sys.exit(0) - -nid = scored[0][1] -data_n = G.nodes[nid] -print(f'NODE: {data_n.get(\"label\", nid)}') -print(f' source: {data_n.get(\"source_file\",\"unknown\")}') -print(f' type: {data_n.get(\"file_type\",\"unknown\")}') -print(f' degree: {G.degree(nid)}') -print() -print('CONNECTIONS:') -for neighbor in G.neighbors(nid): - edge = G.edges[nid, neighbor] - nlabel = G.nodes[neighbor].get('label', neighbor) - rel = edge.get('relation', '') - conf = edge.get('confidence', '') - src_file = G.nodes[neighbor].get('source_file', '') - print(f' --{rel}--> {nlabel} [{conf}] ({src_file})') -" -``` - -Replace `NODE_NAME` with the concept the user asked about. Then explain what this node is, what it connects to, and why those connections are significant. Use the source locations as citations. - -After writing the explanation, save it back: - -```bash -$(cat graphify-out/.graphify_python) -m graphify save-result --question "Explain NODE_NAME" --answer "ANSWER" --type explain --nodes NODE_NAME -``` - ---- - -## For /graphify add - -Fetch a URL and add it to the corpus, then update the graph. - -```bash -$(cat graphify-out/.graphify_python) -c " -import sys -from graphify.ingest import ingest -from pathlib import Path - -try: - out = ingest('URL', Path('./raw'), author='AUTHOR', contributor='CONTRIBUTOR') - print(f'Saved to {out}') -except ValueError as e: - print(f'error: {e}', file=sys.stderr) - sys.exit(1) -except RuntimeError as e: - print(f'error: {e}', file=sys.stderr) - sys.exit(1) -" -``` - -Replace `URL` with the actual URL, `AUTHOR` with the user's name if provided, `CONTRIBUTOR` likewise. If the command exits with an error, tell the user what went wrong - do not silently continue. After a successful save, automatically run the `--update` pipeline on `./raw` to merge the new file into the existing graph. - -Supported URL types (auto-detected): -- Twitter/X → fetched via oEmbed, saved as `.md` with tweet text and author -- arXiv → abstract + metadata saved as `.md` -- PDF → downloaded as `.pdf` -- Images (.png/.jpg/.webp) → downloaded, vision extraction runs on next build -- Any webpage → converted to markdown via html2text - ---- - -## For --watch - -Start a background watcher that monitors a folder and auto-updates the graph when files change. - -```bash -python3 -m graphify.watch INPUT_PATH --debounce 3 -``` - -Replace INPUT_PATH with the folder to watch. Behavior depends on what changed: - -- **Code files only (.py, .ts, .go, etc.):** re-runs AST extraction + rebuild + cluster immediately, no LLM needed. `graph.json` and `GRAPH_REPORT.md` are updated automatically. -- **Docs, papers, or images:** writes a `graphify-out/needs_update` flag and prints a notification to run `/graphify --update` (LLM semantic re-extraction required). - -Debounce (default 3s): waits until file activity stops before triggering, so a wave of parallel agent writes doesn't trigger a rebuild per file. - -Press Ctrl+C to stop. - -For agentic workflows: run `--watch` in a background terminal. Code changes from agent waves are picked up automatically between waves. If agents are also writing docs or notes, you'll need a manual `/graphify --update` after those waves. - ---- - -## For git commit hook - -Install a post-commit hook that auto-rebuilds the graph after every commit. No background process needed - triggers once per commit, works with any editor. - -```bash -graphify hook install # install -graphify hook uninstall # remove -graphify hook status # check -``` - -After every `git commit`, the hook detects which code files changed (via `git diff HEAD~1`), re-runs AST extraction on those files, and rebuilds `graph.json` and `GRAPH_REPORT.md`. Doc/image changes are ignored by the hook - run `/graphify --update` manually for those. - -If a post-commit hook already exists, graphify appends to it rather than replacing it. - ---- - -## For native CLAUDE.md integration - -Run once per project to make graphify always-on in Claude Code sessions: - -```bash -graphify claude install -``` - -This writes a `## graphify` section to the local `CLAUDE.md` that instructs Claude to check the graph before answering codebase questions and rebuild it after code changes. No manual `/graphify` needed in future sessions. - -```bash -graphify claude uninstall # remove the section -``` - ---- - -## Honesty Rules - -- Never invent an edge. If unsure, use AMBIGUOUS. -- Always show token cost in the report. -- Never hide cohesion scores behind symbols - show the raw number. diff --git a/tests/release-copy.sh b/tests/release-copy.sh index 778bce2..796a9a2 100755 --- a/tests/release-copy.sh +++ b/tests/release-copy.sh @@ -48,13 +48,10 @@ assert_file "LICENSE" assert_file "README.md" assert_file "opencode.json" assert_file "playwright-mcp.json" -assert_file "plugin/graphify.js" -assert_file "plugin/graphify.md" assert_dir "ai-scripts" assert_dir "commands" assert_dir "rules" assert_dir "skills" -assert_dir "plugin" assert_absent ".git" assert_absent ".gitmodules" @@ -75,6 +72,8 @@ assert_absent "commands/solve-task.md" assert_absent "commands/finalize-task.md" assert_absent "commands/work-task.md" assert_absent "rules/task-phases.md" +assert_absent "plugin" +assert_absent "skills/graphify" cmp "LICENSE" "${target}/LICENSE" \ || fail "release LICENSE content mismatch" @@ -96,8 +95,8 @@ jq -e ' ((.instructions | index(".opencode/INDEX.md")) | not) and ((.instructions | index(".opencode/rules/task-phases.md")) | not) and (.instructions | index(".opencode/rules/tools.md")) and - (.instructions | index("plugin/graphify.md")) and - (.plugin | index("plugin/graphify.js")) and + ((.instructions | map(select(test("graphify"; "i"))) | length) == 0) and + ((has("plugin")) | not) and (.permission.external_directory["/tmp/**"] == "allow") and (.mcp.context7.type == "local") and (.mcp.playwright.type == "local") and @@ -119,8 +118,6 @@ jq -e ' (.browser.contextOptions | not) ' "${target}/playwright-mcp.json" >/dev/null \ || fail "release playwright-mcp.json is missing expected browser config" -node --check "${target}/plugin/graphify.js" >/dev/null \ - || fail "release graphify plugin has invalid syntax" if ! grep -F 'mktemp -d "${TMPDIR:-/tmp}/opencode-agent-kit.XXXXXX"' \ "${target}/commands/add-agent-kit.md" >/dev/null; then fail "add-agent-kit command must recommend a user-owned temp source checkout" From 91d30e01df4ace461970508bd8edd05e00d0a5b0 Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 26 Jul 2026 22:42:35 +0000 Subject: [PATCH 2/4] chore(release): publish Graphify removal Advance the shared OpenCode submodule to release 1563274. Document the restart and migration guidance for consumers after the Graphify integration is removed. --- .opencode | 2 +- README_release.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.opencode b/.opencode index ffed253..965aca5 160000 --- a/.opencode +++ b/.opencode @@ -1 +1 @@ -Subproject commit ffed2531cca01342266e5e61bf9a142c45191734 +Subproject commit 965aca5fc6f50ea9d35e0d045910fbe1d20a08e9 diff --git a/README_release.md b/README_release.md index 896af75..e191903 100644 --- a/README_release.md +++ b/README_release.md @@ -48,6 +48,9 @@ branch should contain only runtime files needed by consuming repositories: of creating `.playwright-mcp/` at the workspace root. - Removed the Graphify OpenCode plugin, instruction, and skill from the shared runtime bundle. +- Consumer action: after updating `.opencode`, restart OpenCode. Consumers that + relied on Graphify must move that behavior to a repo-local overlay or external + tool; consumers that did not use Graphify require no migration. - Explicitly pass Playwright MCP's `--sandbox` CLI override in addition to the browser launch option so current `@playwright/mcp@latest` releases no longer add the unsupported `--no-sandbox` Chrome argument during config merging. From a41fe9fc0437a7fd4043960463a34c7e3f3ca870 Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 9 Aug 2026 10:10:54 +0000 Subject: [PATCH 3/4] feat(opencode): improve reviewability guidance Require contract-level comments, linked Markdown context, and operation-boundary logs that humans, LLMs, and automation can review. Remove the shared Repomix MCP while retaining the CLI, strengthen release smoke coverage, and advance .opencode to release 965aca5. --- README_release.md | 19 +++++++++++--- commands/create-ai-script.md | 6 +++-- commands/task.md | 7 ++++-- commands/update-documentation.md | 8 ++++-- commands/verify-documentation.md | 12 ++++++--- opencode.json | 9 ------- rules/README.md | 8 +++--- rules/ai-ready-documentation.md | 41 ++++++++++++++++++++++--------- rules/bash-scripts.md | 25 +++++++++++++++++-- rules/devcontainer-tools.md | 2 +- rules/scripting-best-practices.md | 26 +++++++++++++++++--- rules/software-documentation.md | 10 ++++++++ tests/release-copy.sh | 10 +++++++- 13 files changed, 138 insertions(+), 45 deletions(-) diff --git a/README_release.md b/README_release.md index e191903..1a989de 100644 --- a/README_release.md +++ b/README_release.md @@ -43,6 +43,21 @@ branch should contain only runtime files needed by consuming repositories: - Added the canonical `0BSD` `LICENSE` to generated release bundles so the distributed Codegeist-owned runtime content carries its license. No consumer action is required beyond receiving a future submodule update. +- Removed the shared `repomix` MCP server while keeping the Repomix CLI + available as a standalone analysis tool. +- Consumer action: after updating `.opencode`, restart OpenCode. Workflows that + relied on Repomix MCP tools must use the CLI or a repo-local MCP configuration; + standalone Repomix CLI usage is unchanged. +- Expanded AI-ready source guidance so non-trivial modules, classes, functions, + and blocks carry contract-level comments or docstrings and may link to focused + repo-owned Markdown documentation for deeper context. +- Added operation-boundary logging guidance for scripts and source code, with + stable structured events, separate diagnostic and payload streams, and + explicit requirements for output evaluated by LLMs or automation. +- Consumer action: after updating `.opencode`, restart OpenCode so coding agents + load the new reviewability rules. No repository migration is required; apply + the comment, documentation, and logging contract when creating or changing + non-trivial behavior. - Moved Playwright MCP snapshots, console logs, screenshots, and related output under the workspace-local ignored `.chrome/playwright-mcp/` directory instead of creating `.playwright-mcp/` at the workspace root. @@ -65,10 +80,6 @@ branch should contain only runtime files needed by consuming repositories: - Kept the narrow `/save` safety rule for rebased feature branches: use `--force-with-lease` only for the current non-base branch after fetching its upstream, and only when a rebase rewrote commits already present upstream. -- Updated shared AI-ready documentation guidance to prefer detailed explanatory - class and function comments when they help later coding agents understand - behavior, inputs, outputs, side effects, failure paths, constraints, and major - branches. - Added a shared `playwright` MCP server that starts `@playwright/mcp@latest` through `npx` and loads `.opencode/playwright-mcp.json` for browser launch settings. diff --git a/commands/create-ai-script.md b/commands/create-ai-script.md index 4dbb865..c925d80 100644 --- a/commands/create-ai-script.md +++ b/commands/create-ai-script.md @@ -16,8 +16,10 @@ Then: rule, or built-in tool. 2. If a script is justified, create the smallest useful implementation under `.opencode/ai-scripts/`. -3. Keep the script non-interactive by default and make its output structured and - easy for future AI sessions to scan. +3. Keep the script non-interactive by default. Emit stable structured logs for + start, important decisions, side effects, completion, and failures so future + AI sessions can reconstruct the run; keep parseable payloads separate from + diagnostics. 4. Add or update `.opencode/ai-scripts/README.md` when the directory changes. 5. Refresh `@.opencode/rules/ai-scripts.md` if the new script changes durable guidance. diff --git a/commands/task.md b/commands/task.md index 6d8d01b..eaf40bd 100644 --- a/commands/task.md +++ b/commands/task.md @@ -88,8 +88,11 @@ implementation pass. 5. Outside plan mode, implement the smallest correct change. Every line of code must earn its place; avoid speculative abstractions, boilerplate, and broad rewrites. -6. Document why non-obvious code changes exist in task notes or nearby durable - docs. Add code comments only when they materially improve understanding. +6. Make changed behavior reviewable as required by the documentation and + scripting rules. Add or update contract-level comments and docstrings for + non-trivial modules, classes, functions, and blocks; link focused repo-owned + Markdown docs for deeper context; and add meaningful operation-boundary logs + where runtime behavior must be reconstructed by humans, LLMs, or automation. 7. Update tests, documentation, task status, and implementation notes according to the task's acceptance criteria and repo rules. 8. Run enough verification to prove the acceptance criteria. At minimum, run: diff --git a/commands/update-documentation.md b/commands/update-documentation.md index f3545c7..c40791f 100644 --- a/commands/update-documentation.md +++ b/commands/update-documentation.md @@ -20,9 +20,13 @@ Then: directly affected docs under `docs/` if that tree exists. 3. Refresh counts, command lists, and file-path references when they are now stale. -4. Keep documentation proportional; do not create a large new docs structure +4. Create a focused Markdown document when rationale, diagrams, examples, log + fields, or operational detail would overload source comments. Add stable + repository-relative links from the source and a backlink to the relevant + implementation files. +5. Keep documentation proportional; do not create a large new docs structure unless the change truly requires it. -5. Report which files were updated, what changed, and any remaining manual +6. Report which files were updated, what changed, and any remaining manual follow-up. Do not rewrite unrelated documentation just to make it look uniform. diff --git a/commands/verify-documentation.md b/commands/verify-documentation.md index 3badf6f..3c27c7f 100644 --- a/commands/verify-documentation.md +++ b/commands/verify-documentation.md @@ -13,13 +13,17 @@ $ARGUMENTS Then: 1. Inventory the repo's current documentation surface, including `README.md`, - any project-memory file such as `docs/memory-bank/chat.md`, `.opencode/rules/*.md`, + source comments and docstrings, any project-memory file such as + `docs/memory-bank/chat.md`, `.opencode/rules/*.md`, `.opencode/commands/*.md`, and `docs/` content if present. -2. Verify that command and rule references point to real files. +2. Verify that command, rule, source-comment, and Markdown references point to + real files and useful sections. 3. Check that command lists, file counts, and workflow descriptions still match the repo. -4. Flag stale references, broken paths, contradictory guidance, and obvious - language-policy violations. +4. Flag stale references, broken paths, contradictory guidance, missing + contract-level source context, unclear operation-boundary diagnostics, and + obvious language-policy violations. Pay particular attention to output that + an LLM or automation must evaluate. 5. Report the result as a concise verification summary with concrete file paths for any issues. diff --git a/opencode.json b/opencode.json index 277bcc4..e16d71a 100644 --- a/opencode.json +++ b/opencode.json @@ -74,15 +74,6 @@ ], "enabled": true, "timeout": 15000 - }, - "repomix": { - "type": "local", - "command": [ - "npx", - "-y", - "repomix", - "--mcp" - ] } }, "permission": { diff --git a/rules/README.md b/rules/README.md index 45d203b..eafbbdc 100644 --- a/rules/README.md +++ b/rules/README.md @@ -29,9 +29,11 @@ Shared AI rules intended to work across repos. `INDEX.md` navigation files for large directories, outside shared `.opencode` release content. - `language-policy.md` - English for code and durable repo text. -- `ai-ready-documentation.md` - documentation standards for non-trivial files. -- `bash-scripts.md` - minimal Bash style for repo-owned shell scripts. -- `scripting-best-practices.md` - shell and automation guidance. +- `ai-ready-documentation.md` - source comments, diagnostics, and documentation + standards for reviewable non-trivial behavior. +- `bash-scripts.md` - direct, documented, and observable Bash style. +- `scripting-best-practices.md` - shell automation and structured logging + guidance, including output consumed by LLMs. - `software-documentation.md` - how repo-local software documentation should be structured and maintained. - `software-tests.md` - how to write, update, and verify software tests. diff --git a/rules/ai-ready-documentation.md b/rules/ai-ready-documentation.md index 034c1de..350ead0 100644 --- a/rules/ai-ready-documentation.md +++ b/rules/ai-ready-documentation.md @@ -1,11 +1,12 @@ # AI-Ready Documentation -Write repo-owned docs and comments so a later AI session can recover context -quickly. +Write repo-owned docs, comments, and diagnostics so a later human or AI session +can recover context and review behavior quickly. ## Apply To - Non-trivial scripts owned by the repo. +- Non-trivial source files, modules, classes, and functions. - Workflow rules and config files with behavior impact. - Tests with non-obvious setup or safety constraints. - Files that connect several entrypoints, services, or mounted paths. @@ -14,20 +15,36 @@ quickly. - Start non-trivial scripts or config files with a short header that explains purpose, key inputs, important side effects, and related files. -- For source code, prefer explanatory class and function comments when they help - a later coding agent understand behavior quickly. Explain what the class or - function does, important inputs, returned values, side effects, failure paths, - constraints, and major branches when those details are not immediately obvious. -- Detailed explanatory comments are acceptable when they make non-trivial code - easier to modify safely. Keep them accurate and update them in the same task - when the described behavior changes. -- Still avoid comments that merely restate one obvious statement at a time; make - comments useful at the class, function, block, or contract level. +- Document non-trivial modules, classes, and functions with comments or + docstrings that let a reviewer establish the contract without reconstructing + it from the implementation. Cover purpose, important inputs and outputs, + side effects, failure paths, invariants, constraints, and major branches. +- Add block comments around important state transitions, external side effects, + destructive actions, compatibility constraints, and decisions whose rationale + is not visible from the statements alone. +- Keep explanatory comments accurate and update them in the same task whenever + the documented behavior changes. Do not omit contract context merely because + the code appears self-explanatory to its current author. +- Avoid comments that only restate one obvious statement at a time. Comments + should explain a module, class, function, block, contract, decision, or sharp + edge. +- A comment may point to a repo-owned Markdown file and section for deeper + rationale, examples, diagrams, or operational detail. Use a stable + repository-relative path, summarize the locally relevant contract in the + comment, and update the comment and document together. +- Make runtime behavior reviewable with meaningful logs at operation boundaries, + including start, important decisions, externally visible side effects, + completion, and failure. Pure helpers and trivial accessors do not need + entry-and-exit logging. +- When logs are intended for an LLM or other automation, use stable event names, + explicit fields, and concise result or failure summaries so the execution can + be understood without parsing incidental prose. - Name related entrypoints explicitly when they matter, for example `run.sh`, `build.sh`, `test.sh`, or `scripts/common.sh`. - Keep destructive or environment-sensitive behavior documented close to the code that triggers it. -- Keep documentation proportional; tiny files do not need large comment blocks. +- Scale detail to the risk and complexity of the behavior, but keep enough local + context for a reviewer to understand the contract and find deeper docs. ## Suggested Header diff --git a/rules/bash-scripts.md b/rules/bash-scripts.md index 57ebe6c..08f221e 100644 --- a/rules/bash-scripts.md +++ b/rules/bash-scripts.md @@ -7,6 +7,8 @@ Use these rules whenever you create or update repo-owned Bash scripts. - Keep Bash scripts short, direct, and easy to scan. - Prefer a straight execution path over defensive boilerplate. - Treat the expected runtime environment as part of the script contract. +- Make important execution decisions and side effects reviewable from comments + and logs without requiring a reader to reconstruct the whole script. ## Defaults @@ -44,11 +46,30 @@ Use these rules whenever you create or update repo-owned Bash scripts. ## Comments - Keep comments in English. -- Comment why something exists or what sharp edge matters. +- Give non-trivial scripts a short header that explains purpose, inputs, side + effects, failure behavior, and related entrypoints or docs. +- Comment the contract of non-trivial functions and explain why important + branches, destructive actions, or sharp edges exist. +- Link to a repo-owned Markdown file and section when deeper rationale, + diagrams, or operational instructions would otherwise overload the script. + Keep a concise local summary beside the link. - Do not narrate obvious shell syntax line by line. +## Logging + +- Emit logs at meaningful operation boundaries: start, selected non-secret + inputs or targets, important decisions, side effects, completion, and failure. +- Prefer stable one-line records with explicit fields and shared logging helpers. + Use JSON when it is the established machine-readable contract. +- Send diagnostics to stderr and keep stdout available for documented payloads. +- Make LLM-facing output deterministic and easy to scan: use stable event names, + explicit status values, useful paths or counts, and actionable failure detail. +- Avoid per-line or per-iteration noise, interactive spinners, ANSI-only state, + secrets, credentials, and unbounded dumps. + ## Review - Remove validation or structure that does not add real safety. - Prefer the smallest script that still makes the contract clear. -- When in doubt, delete boilerplate before adding more. +- Remove boilerplate that obscures the contract, but retain the explanatory + comments and operation-boundary logs needed to review behavior safely. diff --git a/rules/devcontainer-tools.md b/rules/devcontainer-tools.md index d00b624..c891f48 100644 --- a/rules/devcontainer-tools.md +++ b/rules/devcontainer-tools.md @@ -39,7 +39,7 @@ the smallest direct way to inspect, edit, build, test, or document the repo. - `ast-grep` from `@ast-grep/cli` performs syntax-aware code search and rewrite work when text search is not precise enough. - `scc` summarizes code size, languages, and file statistics. -- `repomix` packages local or remote codebases for AI analysis and MCP use. +- `repomix` packages local or remote codebases for AI analysis. - `tiktoken-cli` estimates token usage for prompts, docs, or packed code. ## AI And Research Helpers diff --git a/rules/scripting-best-practices.md b/rules/scripting-best-practices.md index 964765b..68ae077 100644 --- a/rules/scripting-best-practices.md +++ b/rules/scripting-best-practices.md @@ -42,12 +42,29 @@ Guidance for repo-owned automation scripts and shell entrypoints. ## Comments And Logging -- Comments stay in English and explain why or sharp edges, not obvious shell - syntax. +- Comments stay in English and explain the script contract, important branches, + rationale, or sharp edges rather than narrating obvious shell syntax. +- Non-trivial scripts and functions should name related repo-owned Markdown docs + when those files contain deeper workflow, safety, or operational context. Keep + a concise local summary beside the relevant code. - Reuse shared logging or helper libraries when the repo already has them instead of creating one-off wrappers. +- Emit meaningful logs at each operation boundary: start, selected non-secret + inputs or targets, important decisions, externally visible side effects, + completion summary, and failures with actionable context. +- Prefer stable, line-oriented records with explicit fields such as + `level=info event=release_copy status=started target=...`. Use JSON when it is + the established downstream contract. +- When an LLM or automation will inspect output, use stable event names, preserve + expected-versus-actual values on failures, and include useful paths, counts, + and result summaries. Avoid spinners, ANSI-only state, and transient progress + output that cannot be reviewed later. +- Send diagnostic logs to stderr and reserve stdout for the command's documented + payload when callers may parse it. - Keep raw `printf` only for exact command output, help text, or machine-readable data that must stay unprefixed. +- Do not log every loop iteration or trivial helper call. Log enough operation + boundaries to reconstruct what ran and why without producing noise. - Never print secrets or credentials. ## Script Review @@ -63,9 +80,12 @@ Guidance for repo-owned automation scripts and shell entrypoints. copied across multiple scripts. - Review whether repo shell scripts use the available shared helpers instead of custom status output. +- Review whether the logs make the successful path, selected branches, side + effects, and failure point understandable without reading the implementation. ## Verification - Re-run the affected repo script after changing it. - Prefer short assertions over broad environment dumps. -- Keep output easy to scan and focused on the contract being verified. +- Keep output structured, easy to scan, and focused on the contract being + verified. diff --git a/rules/software-documentation.md b/rules/software-documentation.md index f121d54..4289c2a 100644 --- a/rules/software-documentation.md +++ b/rules/software-documentation.md @@ -17,6 +17,8 @@ documentation. - Important entrypoints, commands, file paths, and related files. - Inputs, outputs, dependencies, and relevant configuration. - Constraints, failure modes, and operational sharp edges. +- Important runtime events, log fields, and diagnostic conventions when + operators, tests, LLMs, or automation depend on them. - Real workflows or examples when they make usage clearer. ## Recommended Structure @@ -26,6 +28,11 @@ documentation. - Use short command examples or file references when they improve clarity. - Name related files and entrypoints explicitly when readers need to move between them. +- Use stable repository-relative links and section anchors when source comments + or other docs need deeper rationale, diagrams, examples, or operational detail. +- Prefer a focused Markdown document when the explanation would make source + comments hard to scan. Keep a short contract summary in the source and link + the document back to the relevant implementation files. - Keep background material short unless it changes implementation or usage. ## Diagrams @@ -47,6 +54,8 @@ documentation. - Document the current truth, not an aspirational future state. - Prefer concise, high-signal sections over long prose. - Explain why and constraints; avoid paraphrasing obvious code. +- Make source-to-document relationships explicit enough that a reviewer can + move in either direction without searching by guesswork. - Rewrite stale sections instead of appending contradictory updates. - Keep examples minimal and realistic. - Call out assumptions or open gaps explicitly when they still matter. @@ -56,6 +65,7 @@ documentation. - Update documentation in the same task when behavior changes. - Remove or rewrite obsolete statements promptly. - Keep documentation proportional to the complexity of the software. +- Validate repo-relative source and documentation links when either side moves. - Refresh related diagrams when the documented architecture or behavior changes. - Follow repo-local path, structure, and language rules when a repo defines them. diff --git a/tests/release-copy.sh b/tests/release-copy.sh index 796a9a2..4f3275f 100755 --- a/tests/release-copy.sh +++ b/tests/release-copy.sh @@ -52,6 +52,14 @@ assert_dir "ai-scripts" assert_dir "commands" assert_dir "rules" assert_dir "skills" +assert_file "commands/create-ai-script.md" +assert_file "commands/task.md" +assert_file "commands/update-documentation.md" +assert_file "commands/verify-documentation.md" +assert_file "rules/ai-ready-documentation.md" +assert_file "rules/bash-scripts.md" +assert_file "rules/scripting-best-practices.md" +assert_file "rules/software-documentation.md" assert_absent ".git" assert_absent ".gitmodules" @@ -105,7 +113,7 @@ jq -e ' ((.mcp.playwright.environment.PLAYWRIGHT_MCP_USER_DATA_DIR | contains("/mnt/codegeist")) | not) and (.mcp.grep_app.type == "remote") and (.mcp.fetch.type == "local") and - (.mcp.repomix.type == "local") + ((.mcp | has("repomix")) | not) ' "${target}/opencode.json" >/dev/null \ || fail "release opencode.json is missing expected OpenCode config" jq -e ' From 922850836017a822679728b4fbf6dd7905eaed5e Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 9 Aug 2026 10:14:39 +0000 Subject: [PATCH 4/4] chore(submodules): refresh devcontainer release Restore the configured .devcontainer release gitlink after rebasing main onto the updated upstream. --- .devcontainer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer b/.devcontainer index e675a32..262fed7 160000 --- a/.devcontainer +++ b/.devcontainer @@ -1 +1 @@ -Subproject commit e675a322df8689e2f4a371d3aebf0726dff9a9d5 +Subproject commit 262fed71163b71242b74532a075f456ba7214887