kibi-mcp 0.2.4 → 0.3.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.
- package/dist/env.js +0 -27
- package/dist/server/docs.js +260 -0
- package/dist/server/session.js +218 -0
- package/dist/server/tools.js +199 -0
- package/dist/server/transport.js +71 -0
- package/dist/server.js +13 -846
- package/dist/tools/check.js +32 -27
- package/dist/tools/delete.js +1 -20
- package/dist/tools/prolog-list.js +2 -38
- package/dist/tools/query.js +1 -255
- package/dist/tools/symbols.js +0 -27
- package/dist/tools/upsert.js +9 -11
- package/dist/tools-config.js +10 -44
- package/dist/workspace.js +3 -42
- package/package.json +3 -3
- package/dist/tools/branch.js +0 -208
- package/dist/tools/context.js +0 -270
- package/dist/tools/coverage-report.js +0 -91
- package/dist/tools/derive.js +0 -311
- package/dist/tools/impact.js +0 -70
- package/dist/tools/list-types.js +0 -75
- package/dist/tools/query-relationships.js +0 -176
- package/dist/tools/suggest-shared-facts.js +0 -138
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Kibi — repo-local, per-branch, queryable long-term memory for software projects
|
|
3
|
-
Copyright (C) 2026 Piotr Franczyk
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Affero General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Affero General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
import { parseAtomList } from "./prolog-list.js";
|
|
19
|
-
/**
|
|
20
|
-
* Handle analyze_shared_facts tool calls
|
|
21
|
-
* Analyzes requirements to suggest shared domain facts for extraction
|
|
22
|
-
*/
|
|
23
|
-
export async function handleSuggestSharedFacts(prolog, args) {
|
|
24
|
-
const minFreq = args.min_frequency ?? 2;
|
|
25
|
-
try {
|
|
26
|
-
// Query all requirements with their text properties
|
|
27
|
-
const reqsResult = await prolog.query("findall([Id,Title], (kb_entity(Id, req, Props), memberchk(title=Title, Props)), Reqs)");
|
|
28
|
-
if (!reqsResult.success || !reqsResult.bindings.Reqs) {
|
|
29
|
-
return {
|
|
30
|
-
content: [{ type: "text", text: "No requirements found in KB" }],
|
|
31
|
-
structuredContent: { suggestions: [], count: 0 },
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
const reqsList = parseAtomList(reqsResult.bindings.Reqs);
|
|
35
|
-
const requirements = [];
|
|
36
|
-
// Parse the list-of-lists format from Prolog
|
|
37
|
-
const reqMatch = reqsList.join("").matchAll(/\[([^,]+),([^\]]+)\]/g);
|
|
38
|
-
if (reqMatch) {
|
|
39
|
-
for (const match of reqMatch) {
|
|
40
|
-
const id = match[1].trim().replace(/^'|'$/g, "");
|
|
41
|
-
const title = match[2].trim().replace(/^'|'$/g, "");
|
|
42
|
-
requirements.push({ id, title, description: title });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// Query all existing facts for context
|
|
46
|
-
const factsResult = await prolog.query("findall([Id,Title], (kb_entity(Id, fact, Props), memberchk(title=Title, Props)), Facts)");
|
|
47
|
-
if (!factsResult.success || !factsResult.bindings.Facts) {
|
|
48
|
-
return {
|
|
49
|
-
content: [{ type: "text", text: "No facts found in KB" }],
|
|
50
|
-
structuredContent: { suggestions: [], count: 0 },
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const factsList = parseAtomList(factsResult.bindings.Facts);
|
|
54
|
-
const existingFacts = new Set();
|
|
55
|
-
const factMatch = factsList.join("").matchAll(/\[([^,]+),([^\]]+)\]/g);
|
|
56
|
-
if (factMatch) {
|
|
57
|
-
for (const match of factMatch) {
|
|
58
|
-
const title = match[2].trim().replace(/^'|'$/g, "");
|
|
59
|
-
existingFacts.add(title.toLowerCase());
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Extract and analyze domain concepts from requirements
|
|
63
|
-
const suggestions = analyzeSharedConcepts(requirements, existingFacts, minFreq);
|
|
64
|
-
return {
|
|
65
|
-
content: [
|
|
66
|
-
{
|
|
67
|
-
type: "text",
|
|
68
|
-
text: `Found ${suggestions.length} potential shared fact(s) to consider creating.`,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
structuredContent: {
|
|
72
|
-
suggestions,
|
|
73
|
-
count: suggestions.length,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
-
throw new Error(`Shared facts analysis failed: ${message}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Lightweight heuristic to identify shared domain concepts
|
|
84
|
-
* Focuses on:
|
|
85
|
-
* - Capitalized terms (possible domain concepts)
|
|
86
|
-
* - Repeated phrases across multiple requirements
|
|
87
|
-
* - Excludes existing facts
|
|
88
|
-
*/
|
|
89
|
-
function analyzeSharedConcepts(requirements, existingFacts, minFreq) {
|
|
90
|
-
const conceptCounts = new Map();
|
|
91
|
-
for (const req of requirements) {
|
|
92
|
-
const originalText = `${req.title} ${req.description || ""}`;
|
|
93
|
-
const text = originalText.toLowerCase();
|
|
94
|
-
// Extract capitalized terms (potential domain concepts)
|
|
95
|
-
// Pattern: words starting with capital letters that aren't at sentence start
|
|
96
|
-
const capitalizedTerms = originalText.matchAll(/\b([A-Z][a-z]+)\b/g);
|
|
97
|
-
// Extract repeated phrases (2+ words)
|
|
98
|
-
// Extract repeated phrases (2+ words)
|
|
99
|
-
const words = text.split(/\s+/).filter(w => w.length > 3);
|
|
100
|
-
for (let i = 0; i < words.length - 1; i++) {
|
|
101
|
-
const phrase = `${words[i]} ${words[i + 1]}`;
|
|
102
|
-
if (!conceptCounts.has(phrase)) {
|
|
103
|
-
conceptCounts.set(phrase, new Set());
|
|
104
|
-
}
|
|
105
|
-
conceptCounts.get(phrase).add(req.id);
|
|
106
|
-
}
|
|
107
|
-
// Also track individual capitalized terms
|
|
108
|
-
for (const match of capitalizedTerms) {
|
|
109
|
-
const lowerTerm = match[1].toLowerCase(); // Get the captured group
|
|
110
|
-
if (!conceptCounts.has(lowerTerm)) {
|
|
111
|
-
conceptCounts.set(lowerTerm, new Set());
|
|
112
|
-
}
|
|
113
|
-
conceptCounts.get(lowerTerm).add(req.id);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// Generate suggestions
|
|
117
|
-
const suggestions = [];
|
|
118
|
-
for (const [concept, reqIds] of conceptCounts) {
|
|
119
|
-
if (reqIds.size >= minFreq) {
|
|
120
|
-
// Skip if this concept already exists as a fact
|
|
121
|
-
if (!existingFacts.has(concept)) {
|
|
122
|
-
suggestions.push({
|
|
123
|
-
concept: capitalizeConcept(concept),
|
|
124
|
-
mentions: reqIds.size,
|
|
125
|
-
requirements: Array.from(reqIds),
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// Sort by frequency (most mentioned first)
|
|
131
|
-
return suggestions.sort((a, b) => b.mentions - a.mentions);
|
|
132
|
-
}
|
|
133
|
-
function capitalizeConcept(concept) {
|
|
134
|
-
return concept
|
|
135
|
-
.split(/\s+/)
|
|
136
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
137
|
-
.join(" ");
|
|
138
|
-
}
|