kibi-mcp 0.14.2 → 0.14.3

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.
@@ -1,107 +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 fs from "node:fs";
19
- import path from "node:path";
20
- import { resolveWorkspaceRoot } from "../workspace.js";
21
- // implements REQ-opencode-kibi-briefing-v2
22
- export function writeBriefPendingMarker(args) {
23
- const workspaceRoot = resolveWorkspaceRoot();
24
- const pendingDir = path.join(workspaceRoot, ".kb", "briefs", "pending");
25
- fs.mkdirSync(pendingDir, { recursive: true });
26
- const sessionId = normalizeSessionId(args.sessionId);
27
- const existing = loadExistingMarker(pendingDir, sessionId);
28
- const timestamp = existing?.payload.timestamp ?? Date.now();
29
- const payload = {
30
- sessionId,
31
- timestamp,
32
- branch: resolveMarkerBranch(workspaceRoot),
33
- operation: args.operation,
34
- entityIds: mergeUniqueStrings(existing?.payload.entityIds ?? [], args.entityIds),
35
- relationships: mergeRelationships(existing?.payload.relationships ?? [], args.relationships ?? []),
36
- };
37
- const filePath = existing?.filePath ??
38
- path.join(pendingDir, `${sanitizeSessionId(sessionId)}-${timestamp}.json`);
39
- fs.writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
40
- return payload;
41
- }
42
- function loadExistingMarker(pendingDir, sessionId) {
43
- const prefix = `${sanitizeSessionId(sessionId)}-`;
44
- const matches = fs
45
- .readdirSync(pendingDir, { withFileTypes: true })
46
- .filter((entry) => entry.isFile())
47
- .map((entry) => entry.name)
48
- .filter((name) => name.startsWith(prefix) && name.endsWith(".json"))
49
- .sort();
50
- const latest = matches.at(-1);
51
- if (!latest) {
52
- return null;
53
- }
54
- const filePath = path.join(pendingDir, latest);
55
- const raw = fs.readFileSync(filePath, "utf8");
56
- return {
57
- filePath,
58
- payload: JSON.parse(raw),
59
- };
60
- }
61
- function normalizeSessionId(sessionId) {
62
- const normalized = sessionId?.trim();
63
- return normalized && normalized.length > 0 ? normalized : "unknown";
64
- }
65
- function sanitizeSessionId(sessionId) {
66
- return sessionId.replace(/[\\/:*?"<>|]+/g, "_");
67
- }
68
- function resolveMarkerBranch(workspaceRoot) {
69
- const envBranch = process.env.KIBI_BRANCH?.trim();
70
- if (envBranch) {
71
- return envBranch;
72
- }
73
- const branchesDir = path.join(workspaceRoot, ".kb", "branches");
74
- if (!fs.existsSync(branchesDir)) {
75
- return "unknown";
76
- }
77
- const branches = fs
78
- .readdirSync(branchesDir, { withFileTypes: true })
79
- .filter((entry) => entry.isDirectory())
80
- .map((entry) => entry.name)
81
- .sort();
82
- return branches.length === 1 ? (branches[0] ?? "unknown") : "unknown";
83
- }
84
- function mergeUniqueStrings(existing, incoming) {
85
- const merged = new Set();
86
- for (const value of existing) {
87
- if (value) {
88
- merged.add(value);
89
- }
90
- }
91
- for (const value of incoming) {
92
- if (value) {
93
- merged.add(value);
94
- }
95
- }
96
- return [...merged];
97
- }
98
- function mergeRelationships(existing, incoming) {
99
- const merged = new Map();
100
- for (const relationship of [...existing, ...incoming]) {
101
- if (!relationship.from || !relationship.to || !relationship.type) {
102
- continue;
103
- }
104
- merged.set(`${relationship.type}\u0000${relationship.from}\u0000${relationship.to}`, relationship);
105
- }
106
- return [...merged.values()];
107
- }