debug-ledger-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hi0001234d
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # debug-ledger
2
+
3
+ *AI should debug with memory, not amnesia.*
4
+
5
+ `debug-ledger` exists because AI-assisted debugging repeatedly breaks old fixes, removes “weird” code that exists for a reason, and reintroduces bugs teams already paid for in the past. Code survives. Debug context doesn’t. This project preserves that lost memory in a form AI tools can actually see.
6
+
7
+ ---
8
+
9
+ ## Example: AI Debug With Memory
10
+ ![Example: AI Debug With Memory](./example-ai-debug-with-memory.gif)
11
+
12
+ **Note:** Do not forget to add this line **"Before starting, call the list_ledger_files MCP tool and show me the output."** at last in every prompt when you want to apply your project constraint or debug memory.
13
+
14
+ ---
15
+
16
+ ## The Problem
17
+
18
+ AI tools are very good at understanding code as it exists today.
19
+ They are very bad at understanding *why* code exists the way it does.
20
+
21
+ In real, long-lived software:
22
+ - Bugs repeat
23
+ - Fixes regress
24
+ - Tests look unnecessary but are critical
25
+ - “Ugly” code often protects against past failures
26
+
27
+ Humans remember this history.
28
+ AI does not.
29
+
30
+ So AI:
31
+ - Suggests fixes that already failed before
32
+ - Cleans up code that hides old landmines
33
+ - Breaks systems in ways that feel _obviously avoidable_ to maintainers
34
+
35
+ This isn’t a model intelligence problem.
36
+ It’s a *missing memory problem*.
37
+
38
+ ---
39
+
40
+ ## What `debug-ledger` Is
41
+
42
+ `debug-ledger` is a *read-only, repo-local debug memory*.
43
+
44
+ It is a small, human-written ledger that documents:
45
+ - Past incidents that mattered
46
+ - Fixes that were tried and rejected
47
+ - Regressions that came back
48
+ - Constraints that must not be violated again
49
+
50
+ This ledger lives *inside the repository*, versioned with the code, and is exposed to AI tools so they can *see historical truth before suggesting changes*.
51
+
52
+ It does not tell AI _what to do_.
53
+ It reminds AI _what already happened_.
54
+
55
+ ---
56
+
57
+ ## What `debug-ledger` Is NOT
58
+
59
+ `debug-ledger` is *not*:
60
+ - An error tracker
61
+ - An observability system
62
+ - A test framework
63
+ - A policy engine
64
+ - An autonomous agent
65
+ - A bug-fixing tool
66
+
67
+ It does not:
68
+ - Enforce rules
69
+ - Block changes
70
+ - Decide correctness
71
+ - Automate debugging
72
+
73
+ It only preserves memory.
74
+
75
+ ---
76
+
77
+ ## How It Fits Into AI Editors & MCP
78
+
79
+ AI editors already read your code.
80
+ `debug-ledger` lets them read your *debug history*.
81
+
82
+ Using MCP (Model Context Protocol), the ledger is exposed as *read-only context* that AI tools can consult *before* proposing fixes or refactors.
83
+
84
+ The flow is simple:
85
+ 1. Developer asks AI to debug or change code
86
+ 2. MCP surfaces relevant ledger entries (if any exist)
87
+ 3. AI responds with awareness of past failures and constraints
88
+
89
+ If no historical context exists, nothing changes.
90
+ MCP is a delivery mechanism — not the product.
91
+
92
+ ---
93
+
94
+ ## Why It’s Intentionally Simple
95
+
96
+ Most valuable maintenance knowledge is:
97
+ - Sparse
98
+ - Expensive to learn
99
+ - Easy to forget
100
+ - Hard to rediscover
101
+
102
+ So `debug-ledger` is deliberately simple:
103
+ - Plain text
104
+ - Human-written
105
+ - Read-only for AI
106
+ - No automation
107
+ - No inference
108
+ - No hidden logic
109
+
110
+ If it becomes clever, it becomes fragile.
111
+ If it becomes heavy, people stop using it.
112
+ Simplicity is the feature.
113
+
114
+ ---
115
+
116
+ ## How to Try It (Conceptually)
117
+
118
+ You don’t need new workflows.
119
+ 1. Add a ledger entry after a painful bug or incident.
120
+ Create the entry inside the `debug_ledger` folder in the cloned MCP project.
121
+ Create a new `.md` file with a meaningful name for your entry and add it there. The file name must start with one of the supported prefixes: `constraints`, `incidents`, `regressions`, or `rejected_fixes`.
122
+ 2. Keep your entry short and factual
123
+ 3. Explain what failed and what must not be repeated
124
+ 4. Let AI tools see it during future debugging sessions
125
+
126
+ If nothing painful happened, don’t write anything.
127
+ The ledger grows slowly — only when reality demands it.
128
+
129
+ ---
130
+
131
+ ## Quick Start
132
+
133
+ ## Installation
134
+
135
+ 1. Open your project in VS Code.
136
+
137
+ 2. Clone the debug-ledger repository from GitHub using the following command.
138
+
139
+ ```bash
140
+ git clone https://github.com/bhavnesh75/debug-ledger.git
141
+ ```
142
+
143
+ 3. Open the terminal.
144
+
145
+ ```bash
146
+ cd debug-ledger
147
+ npm install
148
+ npm run build
149
+ ```
150
+
151
+ 4. After running the above commands, the build file will be available in your project at:
152
+
153
+ ```
154
+ debug-ledger/dist/mcp/server.js
155
+ ```
156
+
157
+ 5. Open your editor MCP settings file.
158
+ (If you are using editors like Kilo Code, Cursor, or any other editor that supports MCP.)
159
+ Add the following MCP configuration in your project MCP settings:
160
+
161
+ ```json
162
+ {
163
+ "mcpServers": {
164
+ "debug-ledger": {
165
+ "command": "node",
166
+ "args": ["dist/mcp/server.js"],
167
+ "cwd": "your debug-ledger repo path"
168
+ }
169
+ }
170
+ }
171
+ ```
172
+ 6. Replace your `debug-ledger repo path` with the actual path of your `debug-ledger` folder.
173
+
174
+ **Note:** Do not forget to add this line **"Before starting, call the list_ledger_files MCP tool and show me the output."** at last in every prompt when you want to apply your project constraint or debug memory.
175
+
176
+ ---
177
+
178
+ ## Contributing
179
+
180
+ We welcome contributions! Please see:
181
+ - **[Contributing Guide](CONTRIBUTING.md)** - How to contribute
182
+
183
+ ---
184
+
185
+ ## Kill Criteria
186
+
187
+ This experiment should be considered a failure if:
188
+ - Developers don’t recognize the problem immediately
189
+ - The ledger fills with low-value noise
190
+ - People ask for automation before understanding the idea
191
+ - It turns into governance, enforcement, or policy
192
+ - It only makes sense with MCP and nowhere else
193
+
194
+ Killing this early is a valid outcome.
195
+
196
+ ---
197
+
198
+ *Code shows what exists.
199
+ Debug ledger explains why it must stay that way.*
@@ -0,0 +1,24 @@
1
+ /**
2
+ POLICY = prefix based configuration
3
+ * NO filenames here
4
+ * ONLY category prefixes
5
+ */
6
+ export const CONTEXT_POLICY = {
7
+ minimal: [
8
+ "constraints-",
9
+ ],
10
+ normal: [
11
+ "constraints-",
12
+ "regressions-",
13
+ ],
14
+ deep: [
15
+ "constraints-",
16
+ "regressions-",
17
+ "incidents-",
18
+ "rejected_fixes-",
19
+ ],
20
+ };
21
+ export const DEFAULT_CONTEXT_LEVEL = "normal";
22
+ export function isValidContextLevel(level) {
23
+ return level === "minimal" || level === "normal" || level === "deep";
24
+ }
@@ -0,0 +1,54 @@
1
+ import { readLedgerFile } from "./ledgerReader.js";
2
+ /**
3
+ * C3 — Context Assembly
4
+ * Handles:
5
+ * - Single file
6
+ * - Multiple files
7
+ * - Separators: , | space \n \t
8
+ * - Returns structured AI-ready context
9
+ */
10
+ export function assembleLedgerContext(input) {
11
+ if (!input || typeof input !== "string") {
12
+ throw new Error("Invalid file input");
13
+ }
14
+ // Normalize separators:
15
+ // Replace , | newline tab multiple spaces with single comma
16
+ // const normalized = input
17
+ // .replace(/\|/g, ",")
18
+ // .replace(/\n/g, ",")
19
+ // .replace(/\t/g, ",")
20
+ // .replace(/\s+/g, ",")
21
+ // .split(",")
22
+ // .map((f) => f.trim())
23
+ // .filter((f) => f.length > 0);
24
+ const rawFiles = input
25
+ .toLowerCase()
26
+ .replace(/["']/g, "")
27
+ .replace(/\(.*?\)/g, "")
28
+ .replace(/\band\b/g, ",")
29
+ .replace(/&/g, ",")
30
+ .replace(/^- /gm, "")
31
+ .replace(/^• /gm, "")
32
+ .replace(/\bfiles?:/g, "")
33
+ .replace(/[\r\n\t|;]+/g, ",")
34
+ .replace(/\s+/g, ",")
35
+ .split(",")
36
+ .map((f) => f.trim())
37
+ .filter(Boolean)
38
+ .map((f) => f.replace(/[^a-z0-9._-]/gi, ""));
39
+ // Remove duplicate filenames
40
+ const uniqueFiles = [...new Set(rawFiles)];
41
+ let finalContext = "";
42
+ for (const fileName of uniqueFiles) {
43
+ try {
44
+ const content = readLedgerFile(fileName);
45
+ finalContext += `\n=== ${fileName} ===\n`;
46
+ finalContext += content + "\n";
47
+ }
48
+ catch (error) {
49
+ finalContext += `\n=== ${fileName} ===\n`;
50
+ finalContext += `Error reading file: ${error.message}\n`;
51
+ }
52
+ }
53
+ return finalContext.trim();
54
+ }
@@ -0,0 +1,24 @@
1
+ import { CONTEXT_POLICY, DEFAULT_CONTEXT_LEVEL, isValidContextLevel, } from "./context-policy.js";
2
+ import { listLedgerFiles } from "./ledgerIndexer.js";
3
+ /**
4
+ * C2 — Context Selection Engine
5
+ *
6
+ * 1. Reads available ledger files (B1)
7
+ * 2. Applies prefix policy
8
+ * 3. Returns matching filenames
9
+ */
10
+ export function selectContextFiles(requestedLevel) {
11
+ let level = DEFAULT_CONTEXT_LEVEL;
12
+ if (requestedLevel && isValidContextLevel(requestedLevel)) {
13
+ level = requestedLevel;
14
+ }
15
+ // prefixes allowed for this level
16
+ const allowedPrefixes = CONTEXT_POLICY[level];
17
+ // get all ledger files (from B1)
18
+ const files = listLedgerFiles();
19
+ // filter by prefix
20
+ const selectedFiles = files
21
+ .map((f) => f.name)
22
+ .filter((fileName) => allowedPrefixes.some((prefix) => fileName.startsWith(prefix)));
23
+ return selectedFiles;
24
+ }
@@ -0,0 +1,26 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ /**
4
+ * Absolute path to debug_ledger folder
5
+ * (server.ts થી run થાય ત્યારે correct resolve થાય)
6
+ */
7
+ const LEDGER_DIR = path.resolve(process.cwd(), "debug_ledger");
8
+ /**
9
+ * B1 — List all ledger files
10
+ * ONLY discovery logic (no parsing, no filtering)
11
+ */
12
+ export function listLedgerFiles() {
13
+ // check folder exists
14
+ if (!fs.existsSync(LEDGER_DIR)) {
15
+ throw new Error("debug_ledger folder not found");
16
+ }
17
+ const files = fs.readdirSync(LEDGER_DIR);
18
+ // only markdown files
19
+ const ledgerFiles = files
20
+ .filter((file) => file.endsWith(".md") && file !== "README.md")
21
+ .map((file) => ({
22
+ name: file,
23
+ path: path.join(LEDGER_DIR, file),
24
+ }));
25
+ return ledgerFiles;
26
+ }
@@ -0,0 +1,43 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ const LEDGER_DIR = path.resolve(process.cwd(), "debug_ledger");
4
+ /**
5
+ * Normalize incoming filename string
6
+ * Supports multiple separators
7
+ */
8
+ function extractFileNames(input) {
9
+ return input
10
+ .split(/[,|\s;\n]+/) // comma | pipe | space | newline | semicolon
11
+ .map((f) => f.trim())
12
+ .filter((f) => f.length > 0);
13
+ }
14
+ /**
15
+ * Read single ledger file safely
16
+ */
17
+ function readSingleFile(fileName) {
18
+ if (!fileName.endsWith(".md")) {
19
+ throw new Error(`Invalid file type: ${fileName}`);
20
+ }
21
+ const filePath = path.join(LEDGER_DIR, fileName);
22
+ if (!fs.existsSync(filePath)) {
23
+ throw new Error(`Ledger file not found: ${fileName}`);
24
+ }
25
+ return fs.readFileSync(filePath, "utf-8");
26
+ }
27
+ /**
28
+ * B2 — Multi-file supported reader
29
+ */
30
+ export function readLedgerFile(input) {
31
+ const fileNames = extractFileNames(input);
32
+ if (fileNames.length === 0) {
33
+ throw new Error("No valid ledger file provided");
34
+ }
35
+ let finalOutput = "";
36
+ for (const file of fileNames) {
37
+ const content = readSingleFile(file);
38
+ finalOutput +=
39
+ `===== ${file} =====\n` +
40
+ `${content}\n\n`;
41
+ }
42
+ return finalOutput.trim();
43
+ }
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { ListToolsRequestSchema, CallToolRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import { assembleLedgerContext } from "./contextAssembler.js";
6
+ /**
7
+ * debug-ledger MCP server
8
+ *
9
+ * NOTE:
10
+ * - This file defines ONLY structure and boundaries
11
+ * - Business logic is intentionally NOT implemented here
12
+ * - All real logic must come via PRs
13
+ */
14
+ const server = new Server({
15
+ name: "debug-ledger",
16
+ version: "0.1.0",
17
+ }, {
18
+ capabilities: {
19
+ tools: {},
20
+ },
21
+ });
22
+ import { listLedgerFiles } from "./ledgerIndexer.js";
23
+ const files = listLedgerFiles();
24
+ /**
25
+ * Tool registry
26
+ * These describe WHAT the server exposes, not HOW it works
27
+ */
28
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
29
+ return {
30
+ tools: [
31
+ {
32
+ name: "list_ledger_files",
33
+ description: "List available debug ledger files",
34
+ inputSchema: {
35
+ type: "object",
36
+ properties: {},
37
+ },
38
+ },
39
+ {
40
+ name: "read_ledger_file",
41
+ description: "Read a specific debug ledger file",
42
+ inputSchema: {
43
+ type: "object",
44
+ properties: {
45
+ filename: {
46
+ type: "string",
47
+ description: "Ledger file name",
48
+ },
49
+ },
50
+ required: ["filename"],
51
+ },
52
+ },
53
+ ],
54
+ };
55
+ });
56
+ /**
57
+ * Tool execution handler
58
+ */
59
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
60
+ const { name } = request.params;
61
+ // BUSINESS LOGIC IMPLEMENTED IN PRs
62
+ // This skeleton intentionally returns placeholders only
63
+ switch (name) {
64
+ case "list_ledger_files": {
65
+ const files = listLedgerFiles();
66
+ return {
67
+ content: [
68
+ {
69
+ type: "text",
70
+ text: JSON.stringify(files, null, 2),
71
+ },
72
+ ],
73
+ };
74
+ }
75
+ case "read_ledger_file": {
76
+ const { filename } = request.params.arguments;
77
+ const assembledContext = assembleLedgerContext(filename);
78
+ return {
79
+ content: [
80
+ {
81
+ type: "text",
82
+ text: assembledContext,
83
+ },
84
+ ],
85
+ };
86
+ }
87
+ default:
88
+ throw new Error(`Unknown tool: ${name}`);
89
+ }
90
+ });
91
+ /**
92
+ * Server bootstrap
93
+ */
94
+ async function main() {
95
+ const transport = new StdioServerTransport();
96
+ await server.connect(transport);
97
+ }
98
+ main().catch((error) => {
99
+ console.error("debug-ledger MCP server failed to start:", error);
100
+ process.exit(1);
101
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "debug-ledger-mcp",
3
+ "version": "0.1.0",
4
+ "description": "Read-only debug memory for AI — a repo-local ledger of past bugs, rejected fixes, and historical constraints so AI debugs with context, not amnesia.",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "bin": {
10
+ "debug-ledger-mcp": "./dist/mcp/server.js"
11
+ },
12
+ "files": [
13
+ "dist/"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "start": "node dist/mcp/server.js",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@types/node": "^25.3.0",
23
+ "typescript": "^5.9.3"
24
+ },
25
+ "dependencies": {
26
+ "@modelcontextprotocol/sdk": "^1.27.1"
27
+ }
28
+ }