devsmind-mcp 2.0.4 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readStaged = readStaged;
37
+ exports.stageEntry = stageEntry;
38
+ exports.clearStaged = clearStaged;
39
+ exports.commitStagedChanges = commitStagedChanges;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const edges_1 = require("./edges");
43
+ const STAGING_FILE = 'history_scratchpad.json';
44
+ function stagingPath(devmindPath) {
45
+ return path.join(path.resolve(devmindPath), STAGING_FILE);
46
+ }
47
+ /** Atomic write (temp file + rename) so an accumulating buffer is never left half-written. */
48
+ function writeBuffer(devmindPath, buf) {
49
+ const target = stagingPath(devmindPath);
50
+ const tmp = `${target}.${process.pid}.tmp`;
51
+ fs.writeFileSync(tmp, JSON.stringify(buf, null, 2), 'utf-8');
52
+ fs.renameSync(tmp, target);
53
+ }
54
+ function readStaged(devmindPath) {
55
+ try {
56
+ const raw = fs.readFileSync(stagingPath(devmindPath), 'utf-8');
57
+ const buf = JSON.parse(raw);
58
+ return Array.isArray(buf.entries) ? buf.entries : [];
59
+ }
60
+ catch {
61
+ return [];
62
+ }
63
+ }
64
+ /** Appends one entry to the buffer and returns the new pending count. */
65
+ function stageEntry(devmindPath, entry) {
66
+ const entries = readStaged(devmindPath);
67
+ entries.push(entry);
68
+ writeBuffer(devmindPath, { entries, updated_at: new Date().toISOString() });
69
+ return entries.length;
70
+ }
71
+ function clearStaged(devmindPath) {
72
+ const target = stagingPath(devmindPath);
73
+ try {
74
+ if (fs.existsSync(target))
75
+ fs.unlinkSync(target);
76
+ }
77
+ catch { /* ignore */ }
78
+ }
79
+ /** Resolves an entry's raw node_id to the canonical `{repo}/relpath#symbol` form. */
80
+ function resolveEntryId(db, entry) {
81
+ if (entry.node_id.includes('#'))
82
+ return entry.node_id;
83
+ const repoRelPath = db.toRepoRelativePath(entry.file_path);
84
+ return `${repoRelPath}#${entry.node_id}`;
85
+ }
86
+ /**
87
+ * Two-pass commit of a batch of staged changes:
88
+ * Pass 1 — upsert every node + write its history entry (so all nodes exist before any edge
89
+ * resolution; forward references within the batch resolve regardless of order).
90
+ * Pass 2 — clear-then-resolve each staged node's OUTGOING edges via the local AST resolver,
91
+ * auto-creating any missing target nodes. Only the staged nodes' own outbound edges
92
+ * are recomputed; every other node's edges are left intact.
93
+ *
94
+ * Idempotent: re-running the same batch yields the same graph (upsert + INSERT OR IGNORE +
95
+ * clear-then-resolve). Callers should clear the buffer only after this returns successfully.
96
+ */
97
+ function commitStagedChanges(db, devmindPath, entries) {
98
+ const stagedIds = [];
99
+ // Pass 1 — nodes + history (+ any explicit connections the caller supplied).
100
+ const explicitEdges = [];
101
+ for (const entry of entries) {
102
+ const nodeId = resolveEntryId(db, entry);
103
+ stagedIds.push(nodeId);
104
+ const name = entry.name || (entry.node_id.includes('.') ? entry.node_id.split('.').pop() : entry.node_id);
105
+ const type = entry.type || (entry.node_id.includes('.') ? 'method' : 'function');
106
+ db.upsertNode({
107
+ id: nodeId,
108
+ name,
109
+ type,
110
+ file_path: entry.file_path,
111
+ signature: entry.signature || null
112
+ });
113
+ db.updateHistory({
114
+ node_id: nodeId,
115
+ code_snapshot: entry.code_snapshot,
116
+ reasoning: entry.reasoning,
117
+ session_id: entry.session_id
118
+ });
119
+ for (const c of entry.connections || []) {
120
+ if (c.target_node_id)
121
+ explicitEdges.push({ source: c.source_node_id || nodeId, target: c.target_node_id });
122
+ }
123
+ }
124
+ // Pass 2 — AST edge resolution for the batch (clear stale outbound edges of staged nodes first).
125
+ const { edgesAdded, missingFilled } = (0, edges_1.resolveEdgesForNodes)(db, devmindPath, stagedIds, { clearSources: true });
126
+ // Apply any explicit edges the caller passed, on top of AST resolution (additive).
127
+ for (const e of explicitEdges) {
128
+ db.addConnection(e.source, e.target);
129
+ }
130
+ return {
131
+ nodes: entries.length,
132
+ history_entries: entries.length,
133
+ edges_added: edgesAdded + explicitEdges.length,
134
+ missing_filled: missingFilled
135
+ };
136
+ }
137
+ //# sourceMappingURL=staging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staging.js","sourceRoot":"","sources":["../../src/db/staging.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,gCAQC;AAGD,gCAKC;AAED,kCAKC;AA2BD,kDAiDC;AAzID,uCAAyB;AACzB,2CAA6B;AAE7B,mCAA+C;AAE/C,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAqB/C,SAAS,WAA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