docdex 0.2.16 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ # Docdex Agent Usage Instructions
2
+
3
+ > Context for AI Agents: Docdex is your local-first Dual-Lobe Memory and Code Intelligence daemon. Unlike simple vector stores, it provides structural understanding of code (AST/Graph), persistent behavioral profiles (Agent Memory), and gated web enrichment, all strictly scoped to the local machine.
4
+
5
+ ## Identity & Architecture
6
+
7
+ Docdex (Documentation Indexer) serves as your persistent "brain" on the user's machine. It operates on a Waterfall Retrieval model:
8
+
9
+ 1. Local First (Tier 1): Instant search of repo code, symbols, and ingested library documentation.
10
+ 2. Web Enrichment (Tier 2): Gated fallback to DuckDuckGo/Headless Chrome only when local confidence is low or explicitly requested.
11
+ 3. Cognition (Tier 3): Local LLM inference (Ollama) with context assembly.
12
+
13
+ Key Constraints:
14
+
15
+ - Repo Isolation: Data never bleeds between repositories. You must identify the active repo for every operation.
16
+ - Hierarchy of Truth: Technical Truth (Code/Repo Memory) > Behavioral Truth (Profile Memory).
17
+ - Privacy: Code is never uploaded to a cloud vector store.
18
+
19
+ ## The Dual-Lobe Memory System
20
+
21
+ Docdex v2.1 introduces a strict separation between "facts" and "preferences." Use the correct lobe for the task.
22
+
23
+ ### 1. Repo Memory (The Hippocampus)
24
+
25
+ - Scope: Project-bound. Specific to the current repository.
26
+ - Content: Technical facts, architectural decisions, logic locations.
27
+ - Example: "The calculateTax function is located in utils/money.ts."
28
+ - Tools: docdex_memory_save, docdex_memory_recall
29
+
30
+ ### 2. Profile Memory (The Neocortex)
31
+
32
+ - Scope: Global / agent-bound. Persists across all projects.
33
+ - Content: Your persona, user preferences, coding style, tooling constraints.
34
+ - Example: "Always use Zod for validation," or "User prefers strict TypeScript types."
35
+ - Tools: docdex_save_preference, docdex_get_profile
36
+ - Usage: Use this to "learn" from corrections. If a user corrects your style, save it here so you do not repeat the mistake in a different repo.
37
+
38
+ ## Tool Capabilities (MCP & HTTP)
39
+
40
+ ### A. Semantic Search & Web (Waterfall)
41
+
42
+ Standard retrieval. The daemon automatically handles the waterfall (Local -> Web).
43
+
44
+ | MCP Tool | Purpose |
45
+ | --- | --- |
46
+ | docdex_search | Search code, docs, and ingested libraries. Returns ranked snippets. |
47
+ | docdex_web_research | Explicitly trigger Tier 2 web discovery (DDG + Headless Chrome). Use when you need external docs not present locally. |
48
+
49
+ ### B. Code Intelligence (AST & Graph)
50
+
51
+ Precision tools for structural analysis. Do not rely on text search for definitions or dependencies.
52
+
53
+ | MCP Tool | Purpose |
54
+ | --- | --- |
55
+ | docdex_symbols | Get exact definitions/signatures for a file. |
56
+ | docdex_ast | Specific AST nodes (e.g., "Find all class definitions"). |
57
+ | docdex_impact_diagnostics | Check for broken/dynamic imports. |
58
+ | HTTP /v1/graph/impact | Impact Analysis: "What breaks if I change this?" Returns inbound/outbound dependencies. |
59
+
60
+ ### C. Memory Operations
61
+
62
+ | MCP Tool | Purpose |
63
+ | --- | --- |
64
+ | docdex_memory_save | Store a technical fact about the current repo. |
65
+ | docdex_memory_recall | Retrieve technical facts about the current repo. |
66
+ | docdex_save_preference | Store a global user preference (Style, Tooling, Constraint). |
67
+ | docdex_get_profile | Retrieve global preferences. |
68
+
69
+ ## Interaction Patterns
70
+
71
+ ### 1. Reasoning Workflow
72
+
73
+ When answering a complex coding query, follow this "Reasoning Trace":
74
+
75
+ 1. Retrieve Profile: Call docdex_get_profile to load user style/constraints (e.g., "Use functional components").
76
+ 2. Search Code: Call docdex_search or docdex_symbols to find the relevant code.
77
+ 3. Check Memory: Call docdex_memory_recall for project-specific caveats (e.g., "Auth logic was refactored last week").
78
+ 4. Synthesize: Generate code that matches the Repo Truth while adhering to the Profile Style.
79
+
80
+ ### 2. Handling Corrections (Learning)
81
+
82
+ If the user says: "I told you, we do not use Moment.js here, use date-fns!"
83
+
84
+ - Action: Call docdex_save_preference
85
+ - category: "constraint"
86
+ - content: "Do not use Moment.js; prefer date-fns."
87
+ - agent_id: "default" (or active agent ID)
88
+
89
+ ### 3. Impact Analysis
90
+
91
+ If the user asks: "Safe to delete getUser?"
92
+
93
+ - Action: Call GET /v1/graph/impact?file=src/user.ts
94
+ - Output: Analyze the inbound edges. If the list is not empty, it is unsafe.
95
+
96
+ ## Operational Context
97
+
98
+ ### Repository Identification
99
+
100
+ Docdex is multi-tenant via isolation.
101
+
102
+ - HTTP: Send x-docdex-repo-id header or repo_id query param if communicating with the singleton daemon.
103
+ - MCP: Ensure project_root or repo_path is passed in tool arguments if the session is not pinned.
104
+
105
+ ### Error Codes
106
+
107
+ - missing_repo: You failed to specify which repo to query.
108
+ - rate_limited: Back off. The system protects the web scraper and LLM.
109
+ - stale_index: The AST parser drifted. Suggest running docdexd index.
110
+ - memory_disabled: The user has explicitly disabled memory features.
111
+
112
+ ### Hardware Awareness
113
+
114
+ Docdex adapts to the host.
115
+
116
+ - Project Mapping: On constrained hardware, docdex uses a "Spotlight Heuristic" to show you only a skeletal file tree based on your role keywords, rather than the full file system.
117
+ - LLM: It may be running a quantized model (e.g., phi3.5) or a heavy model (llama3.1:70b) depending on VRAM. Trust the daemon's token limits; it handles truncation.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+ const { spawn } = require("node:child_process");
7
+
8
+ const {
9
+ detectPlatformKey,
10
+ targetTripleForPlatformKey,
11
+ assetPatternForPlatformKey,
12
+ UnsupportedPlatformError
13
+ } = require("../lib/platform");
14
+
15
+ function run() {
16
+ let platformKey;
17
+ try {
18
+ platformKey = detectPlatformKey();
19
+ } catch (err) {
20
+ if (err instanceof UnsupportedPlatformError) {
21
+ const detected = `${err.details?.platform ?? process.platform}/${err.details?.arch ?? process.arch}`;
22
+ const libc = err.details?.libc ? `/${err.details.libc}` : "";
23
+ console.error(`[docdex] unsupported platform (${detected}${libc})`);
24
+ console.error(`[docdex] error code: ${err.code}`);
25
+ console.error("[docdex] No download/run was attempted for this platform.");
26
+ if (Array.isArray(err.details?.supportedPlatformKeys) && err.details.supportedPlatformKeys.length) {
27
+ console.error(`[docdex] Supported platforms: ${err.details.supportedPlatformKeys.join(", ")}`);
28
+ }
29
+ if (typeof err.details?.candidatePlatformKey === "string") {
30
+ console.error(`[docdex] Asset naming pattern: ${assetPatternForPlatformKey(err.details.candidatePlatformKey)}`);
31
+ }
32
+ console.error("[docdex] Next steps: use a supported platform or build from source (Rust).");
33
+ process.exit(err.exitCode || 3);
34
+ return;
35
+ }
36
+ console.error(`[docdex] failed to detect platform: ${err?.message || String(err)}`);
37
+ process.exit(1);
38
+ return;
39
+ }
40
+
41
+ const basePath = path.join(__dirname, "..", "dist", platformKey);
42
+ const binaryPath = path.join(
43
+ basePath,
44
+ process.platform === "win32" ? "docdex-mcp-server.exe" : "docdex-mcp-server"
45
+ );
46
+
47
+ if (!fs.existsSync(binaryPath)) {
48
+ console.error(
49
+ `[docdex] Missing MCP server binary for ${platformKey}. Try reinstalling or set DOCDEX_MCP_SERVER_BIN.`
50
+ );
51
+ try {
52
+ console.error(`[docdex] Expected target triple: ${targetTripleForPlatformKey(platformKey)}`);
53
+ console.error(`[docdex] Asset naming pattern: ${assetPatternForPlatformKey(platformKey)}`);
54
+ } catch {}
55
+ process.exit(1);
56
+ }
57
+
58
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
59
+ child.on("exit", (code) => process.exit(code ?? 1));
60
+ child.on("error", (err) => {
61
+ console.error(`[docdex] failed to launch MCP server: ${err.message}`);
62
+ process.exit(1);
63
+ });
64
+ }
65
+
66
+ run();
package/bin/docdex.js CHANGED
@@ -27,6 +27,24 @@ function printLines(lines, { stderr } = {}) {
27
27
  }
28
28
  }
29
29
 
30
+ function readInstallMetadata({ fsModule, pathModule, basePath }) {
31
+ if (!fsModule || typeof fsModule.readFileSync !== "function") return null;
32
+ const metadataPath = pathModule.join(basePath, "docdexd-install.json");
33
+ try {
34
+ const raw = fsModule.readFileSync(metadataPath, "utf8");
35
+ return JSON.parse(raw);
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ function formatInstallSource(meta) {
42
+ const source = meta?.archive?.source;
43
+ if (!source || typeof source !== "string") return "unknown";
44
+ if (source === "local") return "local binary";
45
+ return `release (${source})`;
46
+ }
47
+
30
48
  function runDoctor() {
31
49
  const platform = process.platform;
32
50
  const arch = process.arch;
@@ -55,6 +73,9 @@ function runDoctor() {
55
73
  const targetTriple = targetTripleForPlatformKey(platformKey);
56
74
  const expectedAssetName = artifactName(platformKey);
57
75
  const expectedAssetPattern = assetPatternForPlatformKey(platformKey, { exampleAssetName: expectedAssetName });
76
+ const basePath = path.join(__dirname, "..", "dist", platformKey);
77
+ const installMeta = readInstallMetadata({ fsModule: fs, pathModule: path, basePath });
78
+ const installSource = formatInstallSource(installMeta);
58
79
 
59
80
  report = {
60
81
  exitCode: 0,
@@ -66,7 +87,8 @@ function runDoctor() {
66
87
  `[docdex] Platform key: ${platformKey}`,
67
88
  `[docdex] Expected target triple: ${targetTriple}`,
68
89
  `[docdex] Expected release asset: ${expectedAssetName}`,
69
- `[docdex] Asset naming pattern: ${expectedAssetPattern}`
90
+ `[docdex] Asset naming pattern: ${expectedAssetPattern}`,
91
+ `[docdex] Install source: ${installSource}`
70
92
  ]
71
93
  };
72
94
  } catch (err) {
@@ -152,6 +174,10 @@ function run() {
152
174
  basePath,
153
175
  process.platform === "win32" ? "docdexd.exe" : "docdexd"
154
176
  );
177
+ const mcpBinaryPath = path.join(
178
+ basePath,
179
+ process.platform === "win32" ? "docdex-mcp-server.exe" : "docdex-mcp-server"
180
+ );
155
181
 
156
182
  if (!fs.existsSync(binaryPath)) {
157
183
  console.error(`[docdex] Missing binary for ${platformKey}. Try reinstalling or set DOCDEX_DOWNLOAD_REPO to a repo with release assets.`);
@@ -162,7 +188,11 @@ function run() {
162
188
  process.exit(1);
163
189
  }
164
190
 
165
- const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
191
+ const env = { ...process.env };
192
+ if (!env.DOCDEX_MCP_SERVER_BIN && fs.existsSync(mcpBinaryPath)) {
193
+ env.DOCDEX_MCP_SERVER_BIN = mcpBinaryPath;
194
+ }
195
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit", env });
166
196
  child.on("exit", (code) => process.exit(code ?? 1));
167
197
  child.on("error", (err) => {
168
198
  console.error(`[docdex] failed to launch binary: ${err.message}`);