knowns 0.3.0 → 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/CHANGELOG.md +21 -0
- package/CLAUDE.md +133 -23
- package/dist/index.js +31868 -17410
- package/dist/mcp/server.js +981 -636
- package/dist/ui/assets/index-BUsOx5xS.css +1 -0
- package/dist/ui/assets/{index-DHWZIcYt.js → index-BqJqFGQL.js} +84 -84
- package/dist/ui/index.html +2 -2
- package/package.json +4 -4
- package/dist/ui/assets/index-BB-qpEBt.css +0 -1
package/dist/mcp/server.js
CHANGED
|
@@ -10073,10 +10073,10 @@ var require_stringify = __commonJS({
|
|
|
10073
10073
|
data = Object.assign({}, file3.data, data);
|
|
10074
10074
|
const open = opts.delimiters[0];
|
|
10075
10075
|
const close = opts.delimiters[1];
|
|
10076
|
-
const
|
|
10076
|
+
const matter5 = engine.stringify(data, options2).trim();
|
|
10077
10077
|
let buf = "";
|
|
10078
|
-
if (
|
|
10079
|
-
buf = newline(open) + newline(
|
|
10078
|
+
if (matter5 !== "{}") {
|
|
10079
|
+
buf = newline(open) + newline(matter5) + newline(close);
|
|
10080
10080
|
}
|
|
10081
10081
|
if (typeof file3.excerpt === "string" && file3.excerpt !== "") {
|
|
10082
10082
|
if (str2.indexOf(file3.excerpt.trim()) === -1) {
|
|
@@ -10182,19 +10182,19 @@ var require_gray_matter = __commonJS({
|
|
|
10182
10182
|
var toFile = require_to_file();
|
|
10183
10183
|
var parse4 = require_parse();
|
|
10184
10184
|
var utils = require_utils2();
|
|
10185
|
-
function
|
|
10185
|
+
function matter5(input, options2) {
|
|
10186
10186
|
if (input === "") {
|
|
10187
10187
|
return { data: {}, content: input, excerpt: "", orig: input };
|
|
10188
10188
|
}
|
|
10189
10189
|
let file3 = toFile(input);
|
|
10190
|
-
const cached2 =
|
|
10190
|
+
const cached2 = matter5.cache[file3.content];
|
|
10191
10191
|
if (!options2) {
|
|
10192
10192
|
if (cached2) {
|
|
10193
10193
|
file3 = Object.assign({}, cached2);
|
|
10194
10194
|
file3.orig = cached2.orig;
|
|
10195
10195
|
return file3;
|
|
10196
10196
|
}
|
|
10197
|
-
|
|
10197
|
+
matter5.cache[file3.content] = file3;
|
|
10198
10198
|
}
|
|
10199
10199
|
return parseMatter(file3, options2);
|
|
10200
10200
|
}
|
|
@@ -10216,7 +10216,7 @@ var require_gray_matter = __commonJS({
|
|
|
10216
10216
|
}
|
|
10217
10217
|
str2 = str2.slice(openLen);
|
|
10218
10218
|
const len = str2.length;
|
|
10219
|
-
const language =
|
|
10219
|
+
const language = matter5.language(str2, opts);
|
|
10220
10220
|
if (language.name) {
|
|
10221
10221
|
file3.language = language.name;
|
|
10222
10222
|
str2 = str2.slice(language.raw.length);
|
|
@@ -10251,24 +10251,24 @@ var require_gray_matter = __commonJS({
|
|
|
10251
10251
|
}
|
|
10252
10252
|
return file3;
|
|
10253
10253
|
}
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
if (typeof file3 === "string") file3 =
|
|
10254
|
+
matter5.engines = engines2;
|
|
10255
|
+
matter5.stringify = function(file3, data, options2) {
|
|
10256
|
+
if (typeof file3 === "string") file3 = matter5(file3, options2);
|
|
10257
10257
|
return stringify(file3, data, options2);
|
|
10258
10258
|
};
|
|
10259
|
-
|
|
10259
|
+
matter5.read = function(filepath, options2) {
|
|
10260
10260
|
const str2 = fs.readFileSync(filepath, "utf8");
|
|
10261
|
-
const file3 =
|
|
10261
|
+
const file3 = matter5(str2, options2);
|
|
10262
10262
|
file3.path = filepath;
|
|
10263
10263
|
return file3;
|
|
10264
10264
|
};
|
|
10265
|
-
|
|
10265
|
+
matter5.test = function(str2, options2) {
|
|
10266
10266
|
return utils.startsWith(str2, defaults(options2).delimiters[0]);
|
|
10267
10267
|
};
|
|
10268
|
-
|
|
10268
|
+
matter5.language = function(str2, options2) {
|
|
10269
10269
|
const opts = defaults(options2);
|
|
10270
10270
|
const open = opts.delimiters[0];
|
|
10271
|
-
if (
|
|
10271
|
+
if (matter5.test(str2)) {
|
|
10272
10272
|
str2 = str2.slice(open.length);
|
|
10273
10273
|
}
|
|
10274
10274
|
const language = str2.slice(0, str2.search(/\r?\n/));
|
|
@@ -10277,17 +10277,18 @@ var require_gray_matter = __commonJS({
|
|
|
10277
10277
|
name: language ? language.trim() : ""
|
|
10278
10278
|
};
|
|
10279
10279
|
};
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10280
|
+
matter5.cache = {};
|
|
10281
|
+
matter5.clearCache = function() {
|
|
10282
|
+
matter5.cache = {};
|
|
10283
10283
|
};
|
|
10284
|
-
module2.exports =
|
|
10284
|
+
module2.exports = matter5;
|
|
10285
10285
|
}
|
|
10286
10286
|
});
|
|
10287
10287
|
|
|
10288
10288
|
// src/mcp/server.ts
|
|
10289
|
-
import {
|
|
10290
|
-
import {
|
|
10289
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
10290
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
10291
|
+
import { join as join8 } from "node:path";
|
|
10291
10292
|
|
|
10292
10293
|
// node_modules/zod/v3/helpers/util.js
|
|
10293
10294
|
var util;
|
|
@@ -29521,7 +29522,7 @@ var Protocol = class {
|
|
|
29521
29522
|
const capturedTransport = this._transport;
|
|
29522
29523
|
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
29523
29524
|
if (handler === void 0) {
|
|
29524
|
-
const
|
|
29525
|
+
const errorResponse2 = {
|
|
29525
29526
|
jsonrpc: "2.0",
|
|
29526
29527
|
id: request.id,
|
|
29527
29528
|
error: {
|
|
@@ -29532,11 +29533,11 @@ var Protocol = class {
|
|
|
29532
29533
|
if (relatedTaskId && this._taskMessageQueue) {
|
|
29533
29534
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
29534
29535
|
type: "error",
|
|
29535
|
-
message:
|
|
29536
|
+
message: errorResponse2,
|
|
29536
29537
|
timestamp: Date.now()
|
|
29537
29538
|
}, capturedTransport?.sessionId).catch((error46) => this._onerror(new Error(`Failed to enqueue error response: ${error46}`)));
|
|
29538
29539
|
} else {
|
|
29539
|
-
capturedTransport?.send(
|
|
29540
|
+
capturedTransport?.send(errorResponse2).catch((error46) => this._onerror(new Error(`Failed to send an error response: ${error46}`)));
|
|
29540
29541
|
}
|
|
29541
29542
|
return;
|
|
29542
29543
|
}
|
|
@@ -29601,7 +29602,7 @@ var Protocol = class {
|
|
|
29601
29602
|
if (abortController.signal.aborted) {
|
|
29602
29603
|
return;
|
|
29603
29604
|
}
|
|
29604
|
-
const
|
|
29605
|
+
const errorResponse2 = {
|
|
29605
29606
|
jsonrpc: "2.0",
|
|
29606
29607
|
id: request.id,
|
|
29607
29608
|
error: {
|
|
@@ -29613,11 +29614,11 @@ var Protocol = class {
|
|
|
29613
29614
|
if (relatedTaskId && this._taskMessageQueue) {
|
|
29614
29615
|
await this._enqueueTaskMessage(relatedTaskId, {
|
|
29615
29616
|
type: "error",
|
|
29616
|
-
message:
|
|
29617
|
+
message: errorResponse2,
|
|
29617
29618
|
timestamp: Date.now()
|
|
29618
29619
|
}, capturedTransport?.sessionId);
|
|
29619
29620
|
} else {
|
|
29620
|
-
await capturedTransport?.send(
|
|
29621
|
+
await capturedTransport?.send(errorResponse2);
|
|
29621
29622
|
}
|
|
29622
29623
|
}).catch((error46) => this._onerror(new Error(`Failed to send response: ${error46}`))).finally(() => {
|
|
29623
29624
|
this._requestHandlerAbortControllers.delete(request.id);
|
|
@@ -31750,9 +31751,95 @@ var FileStore = class {
|
|
|
31750
31751
|
}
|
|
31751
31752
|
};
|
|
31752
31753
|
|
|
31753
|
-
// src/
|
|
31754
|
+
// src/mcp/server.ts
|
|
31755
|
+
var import_gray_matter4 = __toESM(require_gray_matter(), 1);
|
|
31756
|
+
|
|
31757
|
+
// src/utils/notify-server.ts
|
|
31758
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
31759
|
+
import { join as join4 } from "node:path";
|
|
31760
|
+
|
|
31761
|
+
// src/utils/find-project-root.ts
|
|
31754
31762
|
import { existsSync } from "node:fs";
|
|
31755
|
-
import { join as join3 } from "node:path";
|
|
31763
|
+
import { dirname, join as join3 } from "node:path";
|
|
31764
|
+
function findProjectRoot(startPath = process.cwd()) {
|
|
31765
|
+
let currentPath = startPath;
|
|
31766
|
+
for (let i = 0; i < 20; i++) {
|
|
31767
|
+
const knownsPath = join3(currentPath, ".knowns");
|
|
31768
|
+
if (existsSync(knownsPath)) {
|
|
31769
|
+
return currentPath;
|
|
31770
|
+
}
|
|
31771
|
+
const parentPath = dirname(currentPath);
|
|
31772
|
+
if (parentPath === currentPath) {
|
|
31773
|
+
return null;
|
|
31774
|
+
}
|
|
31775
|
+
currentPath = parentPath;
|
|
31776
|
+
}
|
|
31777
|
+
return null;
|
|
31778
|
+
}
|
|
31779
|
+
|
|
31780
|
+
// src/utils/notify-server.ts
|
|
31781
|
+
var DEFAULT_PORT = 6420;
|
|
31782
|
+
function getServerPort() {
|
|
31783
|
+
try {
|
|
31784
|
+
const projectRoot = findProjectRoot();
|
|
31785
|
+
if (!projectRoot) return DEFAULT_PORT;
|
|
31786
|
+
const configPath = join4(projectRoot, ".knowns/config.json");
|
|
31787
|
+
if (!existsSync2(configPath)) return DEFAULT_PORT;
|
|
31788
|
+
const content = readFileSync(configPath, "utf-8");
|
|
31789
|
+
const config2 = JSON.parse(content);
|
|
31790
|
+
const port = config2.settings?.serverPort;
|
|
31791
|
+
return typeof port === "number" ? port : DEFAULT_PORT;
|
|
31792
|
+
} catch {
|
|
31793
|
+
return DEFAULT_PORT;
|
|
31794
|
+
}
|
|
31795
|
+
}
|
|
31796
|
+
async function notifyTaskUpdate(taskId) {
|
|
31797
|
+
try {
|
|
31798
|
+
const port = getServerPort();
|
|
31799
|
+
const response = await fetch(`http://localhost:${port}/api/notify`, {
|
|
31800
|
+
method: "POST",
|
|
31801
|
+
headers: { "Content-Type": "application/json" },
|
|
31802
|
+
body: JSON.stringify({ taskId }),
|
|
31803
|
+
signal: AbortSignal.timeout(1e3)
|
|
31804
|
+
// 1 second timeout
|
|
31805
|
+
});
|
|
31806
|
+
if (response.ok) {
|
|
31807
|
+
}
|
|
31808
|
+
} catch {
|
|
31809
|
+
}
|
|
31810
|
+
}
|
|
31811
|
+
async function notifyDocUpdate(docPath) {
|
|
31812
|
+
try {
|
|
31813
|
+
const port = getServerPort();
|
|
31814
|
+
await fetch(`http://localhost:${port}/api/notify`, {
|
|
31815
|
+
method: "POST",
|
|
31816
|
+
headers: { "Content-Type": "application/json" },
|
|
31817
|
+
body: JSON.stringify({ type: "docs:updated", docPath }),
|
|
31818
|
+
signal: AbortSignal.timeout(1e3)
|
|
31819
|
+
});
|
|
31820
|
+
} catch {
|
|
31821
|
+
}
|
|
31822
|
+
}
|
|
31823
|
+
async function notifyTimeUpdate(active) {
|
|
31824
|
+
try {
|
|
31825
|
+
const port = getServerPort();
|
|
31826
|
+
await fetch(`http://localhost:${port}/api/notify`, {
|
|
31827
|
+
method: "POST",
|
|
31828
|
+
headers: { "Content-Type": "application/json" },
|
|
31829
|
+
body: JSON.stringify({ type: "time:updated", active }),
|
|
31830
|
+
signal: AbortSignal.timeout(1e3)
|
|
31831
|
+
});
|
|
31832
|
+
} catch {
|
|
31833
|
+
}
|
|
31834
|
+
}
|
|
31835
|
+
|
|
31836
|
+
// src/mcp/utils.ts
|
|
31837
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
31838
|
+
import { join as join6 } from "node:path";
|
|
31839
|
+
|
|
31840
|
+
// src/utils/doc-links.ts
|
|
31841
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
31842
|
+
import { join as join5 } from "node:path";
|
|
31756
31843
|
function parseMarkdownLinks(text) {
|
|
31757
31844
|
const linkPattern = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
31758
31845
|
const links = [];
|
|
@@ -31768,7 +31855,7 @@ function parseMarkdownLinks(text) {
|
|
|
31768
31855
|
function resolveDocReferences(content, projectRoot) {
|
|
31769
31856
|
const links = parseMarkdownLinks(content);
|
|
31770
31857
|
const docReferences = [];
|
|
31771
|
-
const docsDir =
|
|
31858
|
+
const docsDir = join5(projectRoot, ".knowns", "docs");
|
|
31772
31859
|
for (const link of links) {
|
|
31773
31860
|
if (link.target.startsWith("http://") || link.target.startsWith("https://")) {
|
|
31774
31861
|
continue;
|
|
@@ -31784,8 +31871,8 @@ function resolveDocReferences(content, projectRoot) {
|
|
|
31784
31871
|
if (!filename.endsWith(".md")) {
|
|
31785
31872
|
filename = `${filename}.md`;
|
|
31786
31873
|
}
|
|
31787
|
-
const resolvedPath =
|
|
31788
|
-
const exists =
|
|
31874
|
+
const resolvedPath = join5(docsDir, filename);
|
|
31875
|
+
const exists = existsSync3(resolvedPath);
|
|
31789
31876
|
docReferences.push({
|
|
31790
31877
|
text: link.text,
|
|
31791
31878
|
filename: link.target,
|
|
@@ -31796,9 +31883,8 @@ function resolveDocReferences(content, projectRoot) {
|
|
|
31796
31883
|
return docReferences;
|
|
31797
31884
|
}
|
|
31798
31885
|
|
|
31799
|
-
// src/mcp/
|
|
31886
|
+
// src/mcp/utils.ts
|
|
31800
31887
|
var import_gray_matter2 = __toESM(require_gray_matter(), 1);
|
|
31801
|
-
var fileStore = new FileStore(process.cwd());
|
|
31802
31888
|
function parseDuration(durationStr) {
|
|
31803
31889
|
let totalSeconds = 0;
|
|
31804
31890
|
const hoursMatch = durationStr.match(/(\d+)h/);
|
|
@@ -31830,7 +31916,7 @@ function formatDuration(seconds) {
|
|
|
31830
31916
|
}
|
|
31831
31917
|
async function fetchLinkedDocs(task) {
|
|
31832
31918
|
const projectRoot = process.cwd();
|
|
31833
|
-
const docsDir =
|
|
31919
|
+
const docsDir = join6(projectRoot, ".knowns", "docs");
|
|
31834
31920
|
const allContent = [task.description || "", task.implementationPlan || "", task.implementationNotes || ""].join("\n");
|
|
31835
31921
|
const docRefs = resolveDocReferences(allContent, projectRoot);
|
|
31836
31922
|
const linkedDocs = [];
|
|
@@ -31838,7 +31924,7 @@ async function fetchLinkedDocs(task) {
|
|
|
31838
31924
|
if (!ref.exists) continue;
|
|
31839
31925
|
try {
|
|
31840
31926
|
const filename = ref.resolvedPath.replace("@.knowns/docs/", "");
|
|
31841
|
-
const filepath =
|
|
31927
|
+
const filepath = join6(docsDir, filename);
|
|
31842
31928
|
const fileContent = await readFile2(filepath, "utf-8");
|
|
31843
31929
|
const { data, content } = (0, import_gray_matter2.default)(fileContent);
|
|
31844
31930
|
linkedDocs.push({
|
|
@@ -31851,6 +31937,28 @@ async function fetchLinkedDocs(task) {
|
|
|
31851
31937
|
}
|
|
31852
31938
|
return linkedDocs;
|
|
31853
31939
|
}
|
|
31940
|
+
function successResponse(data) {
|
|
31941
|
+
return {
|
|
31942
|
+
content: [
|
|
31943
|
+
{
|
|
31944
|
+
type: "text",
|
|
31945
|
+
text: JSON.stringify({ success: true, ...data }, null, 2)
|
|
31946
|
+
}
|
|
31947
|
+
]
|
|
31948
|
+
};
|
|
31949
|
+
}
|
|
31950
|
+
function errorResponse(error46) {
|
|
31951
|
+
return {
|
|
31952
|
+
content: [
|
|
31953
|
+
{
|
|
31954
|
+
type: "text",
|
|
31955
|
+
text: JSON.stringify({ success: false, error: error46 }, null, 2)
|
|
31956
|
+
}
|
|
31957
|
+
]
|
|
31958
|
+
};
|
|
31959
|
+
}
|
|
31960
|
+
|
|
31961
|
+
// src/mcp/handlers/task.ts
|
|
31854
31962
|
var createTaskSchema = external_exports3.object({
|
|
31855
31963
|
title: external_exports3.string(),
|
|
31856
31964
|
description: external_exports3.string().optional(),
|
|
@@ -31881,40 +31989,7 @@ var listTasksSchema = external_exports3.object({
|
|
|
31881
31989
|
var searchTasksSchema = external_exports3.object({
|
|
31882
31990
|
query: external_exports3.string()
|
|
31883
31991
|
});
|
|
31884
|
-
var
|
|
31885
|
-
taskId: external_exports3.string()
|
|
31886
|
-
});
|
|
31887
|
-
var stopTimeSchema = external_exports3.object({
|
|
31888
|
-
taskId: external_exports3.string()
|
|
31889
|
-
});
|
|
31890
|
-
var addTimeSchema = external_exports3.object({
|
|
31891
|
-
taskId: external_exports3.string(),
|
|
31892
|
-
duration: external_exports3.string(),
|
|
31893
|
-
// e.g., "2h", "30m", "1h30m"
|
|
31894
|
-
note: external_exports3.string().optional(),
|
|
31895
|
-
date: external_exports3.string().optional()
|
|
31896
|
-
// ISO date string
|
|
31897
|
-
});
|
|
31898
|
-
var getTimeReportSchema = external_exports3.object({
|
|
31899
|
-
from: external_exports3.string().optional(),
|
|
31900
|
-
// YYYY-MM-DD
|
|
31901
|
-
to: external_exports3.string().optional(),
|
|
31902
|
-
// YYYY-MM-DD
|
|
31903
|
-
groupBy: external_exports3.enum(["task", "label", "status"]).optional()
|
|
31904
|
-
});
|
|
31905
|
-
var server = new Server(
|
|
31906
|
-
{
|
|
31907
|
-
name: "knowns-mcp-server",
|
|
31908
|
-
version: "1.0.0"
|
|
31909
|
-
},
|
|
31910
|
-
{
|
|
31911
|
-
capabilities: {
|
|
31912
|
-
tools: {},
|
|
31913
|
-
resources: {}
|
|
31914
|
-
}
|
|
31915
|
-
}
|
|
31916
|
-
);
|
|
31917
|
-
var tools = [
|
|
31992
|
+
var taskTools = [
|
|
31918
31993
|
{
|
|
31919
31994
|
name: "create_task",
|
|
31920
31995
|
description: "Create a new task with title and optional description, status, priority, labels, and assignee",
|
|
@@ -32007,7 +32082,144 @@ var tools = [
|
|
|
32007
32082
|
},
|
|
32008
32083
|
required: ["query"]
|
|
32009
32084
|
}
|
|
32010
|
-
}
|
|
32085
|
+
}
|
|
32086
|
+
];
|
|
32087
|
+
async function handleCreateTask(args, fileStore2) {
|
|
32088
|
+
const input = createTaskSchema.parse(args);
|
|
32089
|
+
const task = await fileStore2.createTask({
|
|
32090
|
+
title: input.title,
|
|
32091
|
+
description: input.description,
|
|
32092
|
+
status: input.status || "todo",
|
|
32093
|
+
priority: input.priority || "medium",
|
|
32094
|
+
assignee: input.assignee,
|
|
32095
|
+
labels: input.labels || [],
|
|
32096
|
+
parent: input.parent,
|
|
32097
|
+
subtasks: [],
|
|
32098
|
+
acceptanceCriteria: [],
|
|
32099
|
+
timeSpent: 0,
|
|
32100
|
+
timeEntries: []
|
|
32101
|
+
});
|
|
32102
|
+
await notifyTaskUpdate(task.id);
|
|
32103
|
+
return successResponse({
|
|
32104
|
+
task: {
|
|
32105
|
+
id: task.id,
|
|
32106
|
+
title: task.title,
|
|
32107
|
+
status: task.status,
|
|
32108
|
+
priority: task.priority
|
|
32109
|
+
}
|
|
32110
|
+
});
|
|
32111
|
+
}
|
|
32112
|
+
async function handleGetTask(args, fileStore2) {
|
|
32113
|
+
const input = getTaskSchema.parse(args);
|
|
32114
|
+
const task = await fileStore2.getTask(input.taskId);
|
|
32115
|
+
if (!task) {
|
|
32116
|
+
return errorResponse(`Task ${input.taskId} not found`);
|
|
32117
|
+
}
|
|
32118
|
+
const linkedDocs = await fetchLinkedDocs(task);
|
|
32119
|
+
return successResponse({
|
|
32120
|
+
task: {
|
|
32121
|
+
id: task.id,
|
|
32122
|
+
title: task.title,
|
|
32123
|
+
description: task.description,
|
|
32124
|
+
status: task.status,
|
|
32125
|
+
priority: task.priority,
|
|
32126
|
+
assignee: task.assignee,
|
|
32127
|
+
labels: task.labels,
|
|
32128
|
+
acceptanceCriteria: task.acceptanceCriteria,
|
|
32129
|
+
createdAt: task.createdAt,
|
|
32130
|
+
updatedAt: task.updatedAt,
|
|
32131
|
+
linkedDocumentation: linkedDocs
|
|
32132
|
+
}
|
|
32133
|
+
});
|
|
32134
|
+
}
|
|
32135
|
+
async function handleUpdateTask(args, fileStore2) {
|
|
32136
|
+
const input = updateTaskSchema.parse(args);
|
|
32137
|
+
const updates = {};
|
|
32138
|
+
if (input.title) updates.title = input.title;
|
|
32139
|
+
if (input.description) updates.description = input.description;
|
|
32140
|
+
if (input.status) updates.status = input.status;
|
|
32141
|
+
if (input.priority) updates.priority = input.priority;
|
|
32142
|
+
if (input.assignee) updates.assignee = input.assignee;
|
|
32143
|
+
if (input.labels) updates.labels = input.labels;
|
|
32144
|
+
const task = await fileStore2.updateTask(input.taskId, updates);
|
|
32145
|
+
await notifyTaskUpdate(task.id);
|
|
32146
|
+
return successResponse({
|
|
32147
|
+
task: {
|
|
32148
|
+
id: task.id,
|
|
32149
|
+
title: task.title,
|
|
32150
|
+
status: task.status,
|
|
32151
|
+
priority: task.priority
|
|
32152
|
+
}
|
|
32153
|
+
});
|
|
32154
|
+
}
|
|
32155
|
+
async function handleListTasks(args, fileStore2) {
|
|
32156
|
+
const input = listTasksSchema.parse(args);
|
|
32157
|
+
let tasks = await fileStore2.getAllTasks();
|
|
32158
|
+
if (input.status) {
|
|
32159
|
+
tasks = tasks.filter((t) => t.status === input.status);
|
|
32160
|
+
}
|
|
32161
|
+
if (input.priority) {
|
|
32162
|
+
tasks = tasks.filter((t) => t.priority === input.priority);
|
|
32163
|
+
}
|
|
32164
|
+
if (input.assignee) {
|
|
32165
|
+
tasks = tasks.filter((t) => t.assignee === input.assignee);
|
|
32166
|
+
}
|
|
32167
|
+
if (input.label) {
|
|
32168
|
+
tasks = tasks.filter((t) => t.labels.includes(input.label));
|
|
32169
|
+
}
|
|
32170
|
+
return successResponse({
|
|
32171
|
+
count: tasks.length,
|
|
32172
|
+
tasks: tasks.map((t) => ({
|
|
32173
|
+
id: t.id,
|
|
32174
|
+
title: t.title,
|
|
32175
|
+
status: t.status,
|
|
32176
|
+
priority: t.priority,
|
|
32177
|
+
assignee: t.assignee,
|
|
32178
|
+
labels: t.labels
|
|
32179
|
+
}))
|
|
32180
|
+
});
|
|
32181
|
+
}
|
|
32182
|
+
async function handleSearchTasks(args, fileStore2) {
|
|
32183
|
+
const input = searchTasksSchema.parse(args);
|
|
32184
|
+
const tasks = await fileStore2.getAllTasks();
|
|
32185
|
+
const query = input.query.toLowerCase();
|
|
32186
|
+
const results = tasks.filter(
|
|
32187
|
+
(t) => t.title.toLowerCase().includes(query) || t.description?.toLowerCase().includes(query) || t.labels.some((l) => l.toLowerCase().includes(query))
|
|
32188
|
+
);
|
|
32189
|
+
return successResponse({
|
|
32190
|
+
count: results.length,
|
|
32191
|
+
tasks: results.map((t) => ({
|
|
32192
|
+
id: t.id,
|
|
32193
|
+
title: t.title,
|
|
32194
|
+
status: t.status,
|
|
32195
|
+
priority: t.priority
|
|
32196
|
+
}))
|
|
32197
|
+
});
|
|
32198
|
+
}
|
|
32199
|
+
|
|
32200
|
+
// src/mcp/handlers/time.ts
|
|
32201
|
+
var startTimeSchema = external_exports3.object({
|
|
32202
|
+
taskId: external_exports3.string()
|
|
32203
|
+
});
|
|
32204
|
+
var stopTimeSchema = external_exports3.object({
|
|
32205
|
+
taskId: external_exports3.string()
|
|
32206
|
+
});
|
|
32207
|
+
var addTimeSchema = external_exports3.object({
|
|
32208
|
+
taskId: external_exports3.string(),
|
|
32209
|
+
duration: external_exports3.string(),
|
|
32210
|
+
// e.g., "2h", "30m", "1h30m"
|
|
32211
|
+
note: external_exports3.string().optional(),
|
|
32212
|
+
date: external_exports3.string().optional()
|
|
32213
|
+
// ISO date string
|
|
32214
|
+
});
|
|
32215
|
+
var getTimeReportSchema = external_exports3.object({
|
|
32216
|
+
from: external_exports3.string().optional(),
|
|
32217
|
+
// YYYY-MM-DD
|
|
32218
|
+
to: external_exports3.string().optional(),
|
|
32219
|
+
// YYYY-MM-DD
|
|
32220
|
+
groupBy: external_exports3.enum(["task", "label", "status"]).optional()
|
|
32221
|
+
});
|
|
32222
|
+
var timeTools = [
|
|
32011
32223
|
{
|
|
32012
32224
|
name: "start_time",
|
|
32013
32225
|
description: "Start time tracking for a task",
|
|
@@ -32065,7 +32277,173 @@ var tools = [
|
|
|
32065
32277
|
}
|
|
32066
32278
|
}
|
|
32067
32279
|
}
|
|
32068
|
-
}
|
|
32280
|
+
}
|
|
32281
|
+
];
|
|
32282
|
+
async function handleStartTime(args, fileStore2) {
|
|
32283
|
+
const input = startTimeSchema.parse(args);
|
|
32284
|
+
const task = await fileStore2.getTask(input.taskId);
|
|
32285
|
+
if (!task) {
|
|
32286
|
+
return errorResponse(`Task ${input.taskId} not found`);
|
|
32287
|
+
}
|
|
32288
|
+
const activeEntry = task.timeEntries.find((e) => !e.endedAt);
|
|
32289
|
+
if (activeEntry) {
|
|
32290
|
+
return errorResponse("Time tracking already active for this task");
|
|
32291
|
+
}
|
|
32292
|
+
const newEntry = {
|
|
32293
|
+
id: `entry-${Date.now()}`,
|
|
32294
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
32295
|
+
duration: 0,
|
|
32296
|
+
note: "Started via MCP"
|
|
32297
|
+
};
|
|
32298
|
+
await fileStore2.updateTask(input.taskId, {
|
|
32299
|
+
timeEntries: [...task.timeEntries, newEntry]
|
|
32300
|
+
});
|
|
32301
|
+
await notifyTaskUpdate(input.taskId);
|
|
32302
|
+
await notifyTimeUpdate({
|
|
32303
|
+
taskId: input.taskId,
|
|
32304
|
+
taskTitle: task.title,
|
|
32305
|
+
startedAt: newEntry.startedAt.toISOString(),
|
|
32306
|
+
pausedAt: null,
|
|
32307
|
+
totalPausedMs: 0
|
|
32308
|
+
});
|
|
32309
|
+
return successResponse({
|
|
32310
|
+
message: `Started tracking time for task ${input.taskId}`,
|
|
32311
|
+
startedAt: newEntry.startedAt
|
|
32312
|
+
});
|
|
32313
|
+
}
|
|
32314
|
+
async function handleStopTime(args, fileStore2) {
|
|
32315
|
+
const input = stopTimeSchema.parse(args);
|
|
32316
|
+
const task = await fileStore2.getTask(input.taskId);
|
|
32317
|
+
if (!task) {
|
|
32318
|
+
return errorResponse(`Task ${input.taskId} not found`);
|
|
32319
|
+
}
|
|
32320
|
+
const activeIndex = task.timeEntries.findIndex((e) => !e.endedAt);
|
|
32321
|
+
if (activeIndex === -1) {
|
|
32322
|
+
return errorResponse("No active time tracking for this task");
|
|
32323
|
+
}
|
|
32324
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
32325
|
+
const startTime = task.timeEntries[activeIndex].startedAt;
|
|
32326
|
+
const duration3 = Math.floor((endTime.getTime() - new Date(startTime).getTime()) / 1e3);
|
|
32327
|
+
const updatedEntries = [...task.timeEntries];
|
|
32328
|
+
updatedEntries[activeIndex] = {
|
|
32329
|
+
...updatedEntries[activeIndex],
|
|
32330
|
+
endedAt: endTime,
|
|
32331
|
+
duration: duration3
|
|
32332
|
+
};
|
|
32333
|
+
const newTimeSpent = task.timeSpent + duration3;
|
|
32334
|
+
await fileStore2.updateTask(input.taskId, {
|
|
32335
|
+
timeEntries: updatedEntries,
|
|
32336
|
+
timeSpent: newTimeSpent
|
|
32337
|
+
});
|
|
32338
|
+
await notifyTaskUpdate(input.taskId);
|
|
32339
|
+
await notifyTimeUpdate(null);
|
|
32340
|
+
return successResponse({
|
|
32341
|
+
message: `Stopped tracking time for task ${input.taskId}`,
|
|
32342
|
+
duration: formatDuration(duration3),
|
|
32343
|
+
totalTime: formatDuration(newTimeSpent)
|
|
32344
|
+
});
|
|
32345
|
+
}
|
|
32346
|
+
async function handleAddTime(args, fileStore2) {
|
|
32347
|
+
const input = addTimeSchema.parse(args);
|
|
32348
|
+
const task = await fileStore2.getTask(input.taskId);
|
|
32349
|
+
if (!task) {
|
|
32350
|
+
return errorResponse(`Task ${input.taskId} not found`);
|
|
32351
|
+
}
|
|
32352
|
+
const duration3 = parseDuration(input.duration);
|
|
32353
|
+
const startDate = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
32354
|
+
const newEntry = {
|
|
32355
|
+
id: `entry-${Date.now()}`,
|
|
32356
|
+
startedAt: startDate,
|
|
32357
|
+
endedAt: new Date(startDate.getTime() + duration3 * 1e3),
|
|
32358
|
+
duration: duration3,
|
|
32359
|
+
note: input.note || "Added via MCP"
|
|
32360
|
+
};
|
|
32361
|
+
const newTimeSpent = task.timeSpent + duration3;
|
|
32362
|
+
await fileStore2.updateTask(input.taskId, {
|
|
32363
|
+
timeEntries: [...task.timeEntries, newEntry],
|
|
32364
|
+
timeSpent: newTimeSpent
|
|
32365
|
+
});
|
|
32366
|
+
await notifyTaskUpdate(input.taskId);
|
|
32367
|
+
return successResponse({
|
|
32368
|
+
message: `Added ${formatDuration(duration3)} to task ${input.taskId}`,
|
|
32369
|
+
totalTime: formatDuration(newTimeSpent)
|
|
32370
|
+
});
|
|
32371
|
+
}
|
|
32372
|
+
async function handleGetTimeReport(args, fileStore2) {
|
|
32373
|
+
const input = getTimeReportSchema.parse(args);
|
|
32374
|
+
const tasks = await fileStore2.getAllTasks();
|
|
32375
|
+
let fromDate;
|
|
32376
|
+
let toDate;
|
|
32377
|
+
if (input.from) fromDate = new Date(input.from);
|
|
32378
|
+
if (input.to) toDate = new Date(input.to);
|
|
32379
|
+
const taskTimeData = tasks.map((task) => {
|
|
32380
|
+
let totalSeconds = 0;
|
|
32381
|
+
for (const entry of task.timeEntries) {
|
|
32382
|
+
if (entry.endedAt) {
|
|
32383
|
+
const entryDate = new Date(entry.startedAt);
|
|
32384
|
+
if (fromDate && entryDate < fromDate) continue;
|
|
32385
|
+
if (toDate && entryDate > toDate) continue;
|
|
32386
|
+
totalSeconds += entry.duration;
|
|
32387
|
+
}
|
|
32388
|
+
}
|
|
32389
|
+
return {
|
|
32390
|
+
taskId: task.id,
|
|
32391
|
+
title: task.title,
|
|
32392
|
+
status: task.status,
|
|
32393
|
+
labels: task.labels,
|
|
32394
|
+
totalSeconds
|
|
32395
|
+
};
|
|
32396
|
+
}).filter((data) => data.totalSeconds > 0);
|
|
32397
|
+
if (input.groupBy === "label") {
|
|
32398
|
+
const grouped = {};
|
|
32399
|
+
for (const data of taskTimeData) {
|
|
32400
|
+
for (const label of data.labels) {
|
|
32401
|
+
grouped[label] = (grouped[label] || 0) + data.totalSeconds;
|
|
32402
|
+
}
|
|
32403
|
+
if (data.labels.length === 0) {
|
|
32404
|
+
grouped["(no label)"] = (grouped["(no label)"] || 0) + data.totalSeconds;
|
|
32405
|
+
}
|
|
32406
|
+
}
|
|
32407
|
+
return successResponse({
|
|
32408
|
+
groupBy: "label",
|
|
32409
|
+
data: Object.entries(grouped).map(([label, seconds]) => ({
|
|
32410
|
+
label,
|
|
32411
|
+
time: formatDuration(seconds),
|
|
32412
|
+
seconds
|
|
32413
|
+
})),
|
|
32414
|
+
totalSeconds: Object.values(grouped).reduce((a, b) => a + b, 0)
|
|
32415
|
+
});
|
|
32416
|
+
}
|
|
32417
|
+
if (input.groupBy === "status") {
|
|
32418
|
+
const grouped = {};
|
|
32419
|
+
for (const data of taskTimeData) {
|
|
32420
|
+
grouped[data.status] = (grouped[data.status] || 0) + data.totalSeconds;
|
|
32421
|
+
}
|
|
32422
|
+
return successResponse({
|
|
32423
|
+
groupBy: "status",
|
|
32424
|
+
data: Object.entries(grouped).map(([status, seconds]) => ({
|
|
32425
|
+
status,
|
|
32426
|
+
time: formatDuration(seconds),
|
|
32427
|
+
seconds
|
|
32428
|
+
})),
|
|
32429
|
+
totalSeconds: Object.values(grouped).reduce((a, b) => a + b, 0)
|
|
32430
|
+
});
|
|
32431
|
+
}
|
|
32432
|
+
return successResponse({
|
|
32433
|
+
groupBy: "task",
|
|
32434
|
+
data: taskTimeData.map((data) => ({
|
|
32435
|
+
taskId: data.taskId,
|
|
32436
|
+
title: data.title,
|
|
32437
|
+
status: data.status,
|
|
32438
|
+
time: formatDuration(data.totalSeconds),
|
|
32439
|
+
seconds: data.totalSeconds
|
|
32440
|
+
})),
|
|
32441
|
+
totalSeconds: taskTimeData.reduce((sum, data) => sum + data.totalSeconds, 0)
|
|
32442
|
+
});
|
|
32443
|
+
}
|
|
32444
|
+
|
|
32445
|
+
// src/mcp/handlers/board.ts
|
|
32446
|
+
var boardTools = [
|
|
32069
32447
|
{
|
|
32070
32448
|
name: "get_board",
|
|
32071
32449
|
description: "Get current board state with tasks grouped by status",
|
|
@@ -32075,6 +32453,404 @@ var tools = [
|
|
|
32075
32453
|
}
|
|
32076
32454
|
}
|
|
32077
32455
|
];
|
|
32456
|
+
async function handleGetBoard(fileStore2) {
|
|
32457
|
+
const tasks = await fileStore2.getAllTasks();
|
|
32458
|
+
const board = {
|
|
32459
|
+
todo: [],
|
|
32460
|
+
"in-progress": [],
|
|
32461
|
+
"in-review": [],
|
|
32462
|
+
done: [],
|
|
32463
|
+
blocked: []
|
|
32464
|
+
};
|
|
32465
|
+
for (const task of tasks) {
|
|
32466
|
+
if (board[task.status]) {
|
|
32467
|
+
board[task.status].push(task);
|
|
32468
|
+
}
|
|
32469
|
+
}
|
|
32470
|
+
const mapTask = (t) => ({
|
|
32471
|
+
id: t.id,
|
|
32472
|
+
title: t.title,
|
|
32473
|
+
priority: t.priority,
|
|
32474
|
+
assignee: t.assignee,
|
|
32475
|
+
labels: t.labels
|
|
32476
|
+
});
|
|
32477
|
+
return successResponse({
|
|
32478
|
+
board: {
|
|
32479
|
+
todo: board.todo.map(mapTask),
|
|
32480
|
+
"in-progress": board["in-progress"].map(mapTask),
|
|
32481
|
+
"in-review": board["in-review"].map(mapTask),
|
|
32482
|
+
done: board.done.map(mapTask),
|
|
32483
|
+
blocked: board.blocked.map(mapTask)
|
|
32484
|
+
},
|
|
32485
|
+
totalTasks: tasks.length
|
|
32486
|
+
});
|
|
32487
|
+
}
|
|
32488
|
+
|
|
32489
|
+
// src/mcp/handlers/doc.ts
|
|
32490
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
32491
|
+
import { mkdir as mkdir3, readFile as readFile3, readdir as readdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
32492
|
+
import { join as join7 } from "node:path";
|
|
32493
|
+
var import_gray_matter3 = __toESM(require_gray_matter(), 1);
|
|
32494
|
+
var DOCS_DIR = join7(process.cwd(), ".knowns", "docs");
|
|
32495
|
+
var listDocsSchema = external_exports3.object({
|
|
32496
|
+
tag: external_exports3.string().optional()
|
|
32497
|
+
});
|
|
32498
|
+
var getDocSchema = external_exports3.object({
|
|
32499
|
+
path: external_exports3.string()
|
|
32500
|
+
// Document path (filename or folder/filename)
|
|
32501
|
+
});
|
|
32502
|
+
var createDocSchema = external_exports3.object({
|
|
32503
|
+
title: external_exports3.string(),
|
|
32504
|
+
description: external_exports3.string().optional(),
|
|
32505
|
+
content: external_exports3.string().optional(),
|
|
32506
|
+
tags: external_exports3.array(external_exports3.string()).optional(),
|
|
32507
|
+
folder: external_exports3.string().optional()
|
|
32508
|
+
// Optional folder path
|
|
32509
|
+
});
|
|
32510
|
+
var updateDocSchema = external_exports3.object({
|
|
32511
|
+
path: external_exports3.string(),
|
|
32512
|
+
// Document path
|
|
32513
|
+
title: external_exports3.string().optional(),
|
|
32514
|
+
description: external_exports3.string().optional(),
|
|
32515
|
+
content: external_exports3.string().optional(),
|
|
32516
|
+
tags: external_exports3.array(external_exports3.string()).optional(),
|
|
32517
|
+
appendContent: external_exports3.string().optional()
|
|
32518
|
+
// Append to existing content
|
|
32519
|
+
});
|
|
32520
|
+
var searchDocsSchema = external_exports3.object({
|
|
32521
|
+
query: external_exports3.string(),
|
|
32522
|
+
tag: external_exports3.string().optional()
|
|
32523
|
+
});
|
|
32524
|
+
var docTools = [
|
|
32525
|
+
{
|
|
32526
|
+
name: "list_docs",
|
|
32527
|
+
description: "List all documentation files with optional tag filter",
|
|
32528
|
+
inputSchema: {
|
|
32529
|
+
type: "object",
|
|
32530
|
+
properties: {
|
|
32531
|
+
tag: { type: "string", description: "Filter by tag" }
|
|
32532
|
+
}
|
|
32533
|
+
}
|
|
32534
|
+
},
|
|
32535
|
+
{
|
|
32536
|
+
name: "get_doc",
|
|
32537
|
+
description: "Get a documentation file by path (filename or folder/filename)",
|
|
32538
|
+
inputSchema: {
|
|
32539
|
+
type: "object",
|
|
32540
|
+
properties: {
|
|
32541
|
+
path: {
|
|
32542
|
+
type: "string",
|
|
32543
|
+
description: "Document path (e.g., 'readme', 'guides/setup', 'conventions/naming.md')"
|
|
32544
|
+
}
|
|
32545
|
+
},
|
|
32546
|
+
required: ["path"]
|
|
32547
|
+
}
|
|
32548
|
+
},
|
|
32549
|
+
{
|
|
32550
|
+
name: "create_doc",
|
|
32551
|
+
description: "Create a new documentation file",
|
|
32552
|
+
inputSchema: {
|
|
32553
|
+
type: "object",
|
|
32554
|
+
properties: {
|
|
32555
|
+
title: { type: "string", description: "Document title" },
|
|
32556
|
+
description: { type: "string", description: "Document description" },
|
|
32557
|
+
content: { type: "string", description: "Initial content (markdown)" },
|
|
32558
|
+
tags: {
|
|
32559
|
+
type: "array",
|
|
32560
|
+
items: { type: "string" },
|
|
32561
|
+
description: "Document tags"
|
|
32562
|
+
},
|
|
32563
|
+
folder: {
|
|
32564
|
+
type: "string",
|
|
32565
|
+
description: "Folder path (e.g., 'guides', 'patterns/auth')"
|
|
32566
|
+
}
|
|
32567
|
+
},
|
|
32568
|
+
required: ["title"]
|
|
32569
|
+
}
|
|
32570
|
+
},
|
|
32571
|
+
{
|
|
32572
|
+
name: "update_doc",
|
|
32573
|
+
description: "Update an existing documentation file",
|
|
32574
|
+
inputSchema: {
|
|
32575
|
+
type: "object",
|
|
32576
|
+
properties: {
|
|
32577
|
+
path: {
|
|
32578
|
+
type: "string",
|
|
32579
|
+
description: "Document path (e.g., 'readme', 'guides/setup')"
|
|
32580
|
+
},
|
|
32581
|
+
title: { type: "string", description: "New title" },
|
|
32582
|
+
description: { type: "string", description: "New description" },
|
|
32583
|
+
content: { type: "string", description: "Replace content" },
|
|
32584
|
+
tags: {
|
|
32585
|
+
type: "array",
|
|
32586
|
+
items: { type: "string" },
|
|
32587
|
+
description: "New tags"
|
|
32588
|
+
},
|
|
32589
|
+
appendContent: {
|
|
32590
|
+
type: "string",
|
|
32591
|
+
description: "Append to existing content"
|
|
32592
|
+
}
|
|
32593
|
+
},
|
|
32594
|
+
required: ["path"]
|
|
32595
|
+
}
|
|
32596
|
+
},
|
|
32597
|
+
{
|
|
32598
|
+
name: "search_docs",
|
|
32599
|
+
description: "Search documentation by query string",
|
|
32600
|
+
inputSchema: {
|
|
32601
|
+
type: "object",
|
|
32602
|
+
properties: {
|
|
32603
|
+
query: { type: "string", description: "Search query" },
|
|
32604
|
+
tag: { type: "string", description: "Filter by tag" }
|
|
32605
|
+
},
|
|
32606
|
+
required: ["query"]
|
|
32607
|
+
}
|
|
32608
|
+
}
|
|
32609
|
+
];
|
|
32610
|
+
async function ensureDocsDir() {
|
|
32611
|
+
if (!existsSync4(DOCS_DIR)) {
|
|
32612
|
+
await mkdir3(DOCS_DIR, { recursive: true });
|
|
32613
|
+
}
|
|
32614
|
+
}
|
|
32615
|
+
function titleToFilename(title) {
|
|
32616
|
+
return title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
32617
|
+
}
|
|
32618
|
+
async function getAllMdFiles(dir, basePath = "") {
|
|
32619
|
+
const files = [];
|
|
32620
|
+
if (!existsSync4(dir)) {
|
|
32621
|
+
return files;
|
|
32622
|
+
}
|
|
32623
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
32624
|
+
for (const entry of entries) {
|
|
32625
|
+
const fullPath = join7(dir, entry.name);
|
|
32626
|
+
const relativePath = basePath ? join7(basePath, entry.name) : entry.name;
|
|
32627
|
+
if (entry.isDirectory()) {
|
|
32628
|
+
const subFiles = await getAllMdFiles(fullPath, relativePath);
|
|
32629
|
+
files.push(...subFiles);
|
|
32630
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
32631
|
+
files.push(relativePath);
|
|
32632
|
+
}
|
|
32633
|
+
}
|
|
32634
|
+
return files;
|
|
32635
|
+
}
|
|
32636
|
+
async function resolveDocPath(name) {
|
|
32637
|
+
await ensureDocsDir();
|
|
32638
|
+
let filename = name.endsWith(".md") ? name : `${name}.md`;
|
|
32639
|
+
let filepath = join7(DOCS_DIR, filename);
|
|
32640
|
+
if (existsSync4(filepath)) {
|
|
32641
|
+
return { filepath, filename };
|
|
32642
|
+
}
|
|
32643
|
+
filename = `${titleToFilename(name)}.md`;
|
|
32644
|
+
filepath = join7(DOCS_DIR, filename);
|
|
32645
|
+
if (existsSync4(filepath)) {
|
|
32646
|
+
return { filepath, filename };
|
|
32647
|
+
}
|
|
32648
|
+
const allFiles = await getAllMdFiles(DOCS_DIR);
|
|
32649
|
+
const searchName = name.toLowerCase().replace(/\.md$/, "");
|
|
32650
|
+
const matchingFile = allFiles.find((file3) => {
|
|
32651
|
+
const fileNameOnly = file3.toLowerCase().replace(/\.md$/, "");
|
|
32652
|
+
const fileBaseName = file3.split("/").pop()?.toLowerCase().replace(/\.md$/, "");
|
|
32653
|
+
return fileNameOnly === searchName || fileBaseName === searchName || file3 === name;
|
|
32654
|
+
});
|
|
32655
|
+
if (matchingFile) {
|
|
32656
|
+
return {
|
|
32657
|
+
filepath: join7(DOCS_DIR, matchingFile),
|
|
32658
|
+
filename: matchingFile
|
|
32659
|
+
};
|
|
32660
|
+
}
|
|
32661
|
+
return null;
|
|
32662
|
+
}
|
|
32663
|
+
async function handleListDocs(args) {
|
|
32664
|
+
const input = listDocsSchema.parse(args);
|
|
32665
|
+
await ensureDocsDir();
|
|
32666
|
+
const mdFiles = await getAllMdFiles(DOCS_DIR);
|
|
32667
|
+
if (mdFiles.length === 0) {
|
|
32668
|
+
return successResponse({
|
|
32669
|
+
count: 0,
|
|
32670
|
+
docs: [],
|
|
32671
|
+
message: "No documentation files found"
|
|
32672
|
+
});
|
|
32673
|
+
}
|
|
32674
|
+
const docs = [];
|
|
32675
|
+
for (const file3 of mdFiles) {
|
|
32676
|
+
const content = await readFile3(join7(DOCS_DIR, file3), "utf-8");
|
|
32677
|
+
const { data } = (0, import_gray_matter3.default)(content);
|
|
32678
|
+
const metadata = data;
|
|
32679
|
+
if (input.tag && !metadata.tags?.includes(input.tag)) {
|
|
32680
|
+
continue;
|
|
32681
|
+
}
|
|
32682
|
+
docs.push({
|
|
32683
|
+
path: file3.replace(/\.md$/, ""),
|
|
32684
|
+
title: metadata.title || file3.replace(/\.md$/, ""),
|
|
32685
|
+
description: metadata.description,
|
|
32686
|
+
tags: metadata.tags,
|
|
32687
|
+
updatedAt: metadata.updatedAt
|
|
32688
|
+
});
|
|
32689
|
+
}
|
|
32690
|
+
return successResponse({
|
|
32691
|
+
count: docs.length,
|
|
32692
|
+
docs
|
|
32693
|
+
});
|
|
32694
|
+
}
|
|
32695
|
+
async function handleGetDoc(args) {
|
|
32696
|
+
const input = getDocSchema.parse(args);
|
|
32697
|
+
const resolved = await resolveDocPath(input.path);
|
|
32698
|
+
if (!resolved) {
|
|
32699
|
+
return errorResponse(`Documentation not found: ${input.path}`);
|
|
32700
|
+
}
|
|
32701
|
+
const fileContent = await readFile3(resolved.filepath, "utf-8");
|
|
32702
|
+
const { data, content } = (0, import_gray_matter3.default)(fileContent);
|
|
32703
|
+
const metadata = data;
|
|
32704
|
+
return successResponse({
|
|
32705
|
+
doc: {
|
|
32706
|
+
path: resolved.filename.replace(/\.md$/, ""),
|
|
32707
|
+
title: metadata.title,
|
|
32708
|
+
description: metadata.description,
|
|
32709
|
+
tags: metadata.tags,
|
|
32710
|
+
createdAt: metadata.createdAt,
|
|
32711
|
+
updatedAt: metadata.updatedAt,
|
|
32712
|
+
content: content.trim()
|
|
32713
|
+
}
|
|
32714
|
+
});
|
|
32715
|
+
}
|
|
32716
|
+
async function handleCreateDoc(args) {
|
|
32717
|
+
const input = createDocSchema.parse(args);
|
|
32718
|
+
await ensureDocsDir();
|
|
32719
|
+
const filename = `${titleToFilename(input.title)}.md`;
|
|
32720
|
+
let targetDir = DOCS_DIR;
|
|
32721
|
+
let relativePath = filename;
|
|
32722
|
+
if (input.folder) {
|
|
32723
|
+
const folderPath = input.folder.replace(/^\/|\/$/g, "");
|
|
32724
|
+
targetDir = join7(DOCS_DIR, folderPath);
|
|
32725
|
+
relativePath = join7(folderPath, filename);
|
|
32726
|
+
if (!existsSync4(targetDir)) {
|
|
32727
|
+
await mkdir3(targetDir, { recursive: true });
|
|
32728
|
+
}
|
|
32729
|
+
}
|
|
32730
|
+
const filepath = join7(targetDir, filename);
|
|
32731
|
+
if (existsSync4(filepath)) {
|
|
32732
|
+
return errorResponse(`Document already exists: ${relativePath}`);
|
|
32733
|
+
}
|
|
32734
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
32735
|
+
const metadata = {
|
|
32736
|
+
title: input.title,
|
|
32737
|
+
createdAt: now,
|
|
32738
|
+
updatedAt: now
|
|
32739
|
+
};
|
|
32740
|
+
if (input.description) {
|
|
32741
|
+
metadata.description = input.description;
|
|
32742
|
+
}
|
|
32743
|
+
if (input.tags) {
|
|
32744
|
+
metadata.tags = input.tags;
|
|
32745
|
+
}
|
|
32746
|
+
const initialContent = input.content || "# Content\n\nWrite your documentation here.";
|
|
32747
|
+
const fileContent = import_gray_matter3.default.stringify(initialContent, metadata);
|
|
32748
|
+
await writeFile2(filepath, fileContent, "utf-8");
|
|
32749
|
+
await notifyDocUpdate(relativePath);
|
|
32750
|
+
return successResponse({
|
|
32751
|
+
message: `Created documentation: ${relativePath}`,
|
|
32752
|
+
doc: {
|
|
32753
|
+
path: relativePath.replace(/\.md$/, ""),
|
|
32754
|
+
title: metadata.title,
|
|
32755
|
+
description: metadata.description,
|
|
32756
|
+
tags: metadata.tags
|
|
32757
|
+
}
|
|
32758
|
+
});
|
|
32759
|
+
}
|
|
32760
|
+
async function handleUpdateDoc(args) {
|
|
32761
|
+
const input = updateDocSchema.parse(args);
|
|
32762
|
+
const resolved = await resolveDocPath(input.path);
|
|
32763
|
+
if (!resolved) {
|
|
32764
|
+
return errorResponse(`Documentation not found: ${input.path}`);
|
|
32765
|
+
}
|
|
32766
|
+
const fileContent = await readFile3(resolved.filepath, "utf-8");
|
|
32767
|
+
const { data, content } = (0, import_gray_matter3.default)(fileContent);
|
|
32768
|
+
const metadata = data;
|
|
32769
|
+
if (input.title) metadata.title = input.title;
|
|
32770
|
+
if (input.description) metadata.description = input.description;
|
|
32771
|
+
if (input.tags) metadata.tags = input.tags;
|
|
32772
|
+
metadata.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
32773
|
+
let updatedContent = content;
|
|
32774
|
+
if (input.content) {
|
|
32775
|
+
updatedContent = input.content;
|
|
32776
|
+
}
|
|
32777
|
+
if (input.appendContent) {
|
|
32778
|
+
updatedContent = `${content.trimEnd()}
|
|
32779
|
+
|
|
32780
|
+
${input.appendContent}`;
|
|
32781
|
+
}
|
|
32782
|
+
const newFileContent = import_gray_matter3.default.stringify(updatedContent, metadata);
|
|
32783
|
+
await writeFile2(resolved.filepath, newFileContent, "utf-8");
|
|
32784
|
+
await notifyDocUpdate(resolved.filename);
|
|
32785
|
+
return successResponse({
|
|
32786
|
+
message: `Updated documentation: ${resolved.filename}`,
|
|
32787
|
+
doc: {
|
|
32788
|
+
path: resolved.filename.replace(/\.md$/, ""),
|
|
32789
|
+
title: metadata.title,
|
|
32790
|
+
description: metadata.description,
|
|
32791
|
+
tags: metadata.tags,
|
|
32792
|
+
updatedAt: metadata.updatedAt
|
|
32793
|
+
}
|
|
32794
|
+
});
|
|
32795
|
+
}
|
|
32796
|
+
async function handleSearchDocs(args) {
|
|
32797
|
+
const input = searchDocsSchema.parse(args);
|
|
32798
|
+
await ensureDocsDir();
|
|
32799
|
+
const mdFiles = await getAllMdFiles(DOCS_DIR);
|
|
32800
|
+
const query = input.query.toLowerCase();
|
|
32801
|
+
const results = [];
|
|
32802
|
+
for (const file3 of mdFiles) {
|
|
32803
|
+
const fileContent = await readFile3(join7(DOCS_DIR, file3), "utf-8");
|
|
32804
|
+
const { data, content } = (0, import_gray_matter3.default)(fileContent);
|
|
32805
|
+
const metadata = data;
|
|
32806
|
+
if (input.tag && !metadata.tags?.includes(input.tag)) {
|
|
32807
|
+
continue;
|
|
32808
|
+
}
|
|
32809
|
+
const titleMatch = metadata.title?.toLowerCase().includes(query);
|
|
32810
|
+
const descMatch = metadata.description?.toLowerCase().includes(query);
|
|
32811
|
+
const tagMatch = metadata.tags?.some((t) => t.toLowerCase().includes(query));
|
|
32812
|
+
const contentMatch = content.toLowerCase().includes(query);
|
|
32813
|
+
if (titleMatch || descMatch || tagMatch || contentMatch) {
|
|
32814
|
+
let matchContext;
|
|
32815
|
+
if (contentMatch) {
|
|
32816
|
+
const contentLower = content.toLowerCase();
|
|
32817
|
+
const matchIndex = contentLower.indexOf(query);
|
|
32818
|
+
if (matchIndex !== -1) {
|
|
32819
|
+
const start = Math.max(0, matchIndex - 50);
|
|
32820
|
+
const end = Math.min(content.length, matchIndex + query.length + 50);
|
|
32821
|
+
matchContext = `...${content.slice(start, end).replace(/\n/g, " ")}...`;
|
|
32822
|
+
}
|
|
32823
|
+
}
|
|
32824
|
+
results.push({
|
|
32825
|
+
path: file3.replace(/\.md$/, ""),
|
|
32826
|
+
title: metadata.title || file3.replace(/\.md$/, ""),
|
|
32827
|
+
description: metadata.description,
|
|
32828
|
+
tags: metadata.tags,
|
|
32829
|
+
matchContext
|
|
32830
|
+
});
|
|
32831
|
+
}
|
|
32832
|
+
}
|
|
32833
|
+
return successResponse({
|
|
32834
|
+
count: results.length,
|
|
32835
|
+
docs: results
|
|
32836
|
+
});
|
|
32837
|
+
}
|
|
32838
|
+
|
|
32839
|
+
// src/mcp/server.ts
|
|
32840
|
+
var fileStore = new FileStore(process.cwd());
|
|
32841
|
+
var server = new Server(
|
|
32842
|
+
{
|
|
32843
|
+
name: "knowns-mcp-server",
|
|
32844
|
+
version: "1.0.0"
|
|
32845
|
+
},
|
|
32846
|
+
{
|
|
32847
|
+
capabilities: {
|
|
32848
|
+
tools: {},
|
|
32849
|
+
resources: {}
|
|
32850
|
+
}
|
|
32851
|
+
}
|
|
32852
|
+
);
|
|
32853
|
+
var tools = [...taskTools, ...timeTools, ...boardTools, ...docTools];
|
|
32078
32854
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
32079
32855
|
return { tools };
|
|
32080
32856
|
});
|
|
@@ -32082,540 +32858,129 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
32082
32858
|
const { name, arguments: args } = request.params;
|
|
32083
32859
|
try {
|
|
32084
32860
|
switch (name) {
|
|
32085
|
-
|
|
32086
|
-
|
|
32087
|
-
|
|
32088
|
-
|
|
32089
|
-
|
|
32090
|
-
|
|
32091
|
-
|
|
32092
|
-
|
|
32093
|
-
|
|
32094
|
-
|
|
32095
|
-
|
|
32096
|
-
|
|
32097
|
-
|
|
32098
|
-
|
|
32099
|
-
|
|
32100
|
-
return
|
|
32101
|
-
|
|
32102
|
-
|
|
32103
|
-
|
|
32104
|
-
|
|
32105
|
-
|
|
32106
|
-
|
|
32107
|
-
|
|
32108
|
-
|
|
32109
|
-
|
|
32110
|
-
|
|
32111
|
-
|
|
32112
|
-
|
|
32113
|
-
|
|
32114
|
-
|
|
32115
|
-
|
|
32116
|
-
|
|
32117
|
-
|
|
32118
|
-
|
|
32119
|
-
};
|
|
32120
|
-
}
|
|
32121
|
-
case "get_task": {
|
|
32122
|
-
const input = getTaskSchema.parse(args);
|
|
32123
|
-
const task = await fileStore.getTask(input.taskId);
|
|
32124
|
-
if (!task) {
|
|
32125
|
-
return {
|
|
32126
|
-
content: [
|
|
32127
|
-
{
|
|
32128
|
-
type: "text",
|
|
32129
|
-
text: JSON.stringify(
|
|
32130
|
-
{
|
|
32131
|
-
success: false,
|
|
32132
|
-
error: `Task ${input.taskId} not found`
|
|
32133
|
-
},
|
|
32134
|
-
null,
|
|
32135
|
-
2
|
|
32136
|
-
)
|
|
32137
|
-
}
|
|
32138
|
-
]
|
|
32139
|
-
};
|
|
32140
|
-
}
|
|
32141
|
-
const linkedDocs = await fetchLinkedDocs(task);
|
|
32142
|
-
return {
|
|
32143
|
-
content: [
|
|
32144
|
-
{
|
|
32145
|
-
type: "text",
|
|
32146
|
-
text: JSON.stringify(
|
|
32147
|
-
{
|
|
32148
|
-
success: true,
|
|
32149
|
-
task: {
|
|
32150
|
-
id: task.id,
|
|
32151
|
-
title: task.title,
|
|
32152
|
-
description: task.description,
|
|
32153
|
-
status: task.status,
|
|
32154
|
-
priority: task.priority,
|
|
32155
|
-
assignee: task.assignee,
|
|
32156
|
-
labels: task.labels,
|
|
32157
|
-
acceptanceCriteria: task.acceptanceCriteria,
|
|
32158
|
-
createdAt: task.createdAt,
|
|
32159
|
-
updatedAt: task.updatedAt,
|
|
32160
|
-
linkedDocumentation: linkedDocs
|
|
32161
|
-
}
|
|
32162
|
-
},
|
|
32163
|
-
null,
|
|
32164
|
-
2
|
|
32165
|
-
)
|
|
32166
|
-
}
|
|
32167
|
-
]
|
|
32168
|
-
};
|
|
32169
|
-
}
|
|
32170
|
-
case "update_task": {
|
|
32171
|
-
const input = updateTaskSchema.parse(args);
|
|
32172
|
-
const updates = {};
|
|
32173
|
-
if (input.title) updates.title = input.title;
|
|
32174
|
-
if (input.description) updates.description = input.description;
|
|
32175
|
-
if (input.status) updates.status = input.status;
|
|
32176
|
-
if (input.priority) updates.priority = input.priority;
|
|
32177
|
-
if (input.assignee) updates.assignee = input.assignee;
|
|
32178
|
-
if (input.labels) updates.labels = input.labels;
|
|
32179
|
-
const task = await fileStore.updateTask(input.taskId, updates);
|
|
32180
|
-
return {
|
|
32181
|
-
content: [
|
|
32182
|
-
{
|
|
32183
|
-
type: "text",
|
|
32184
|
-
text: JSON.stringify(
|
|
32185
|
-
{
|
|
32186
|
-
success: true,
|
|
32187
|
-
task: {
|
|
32188
|
-
id: task.id,
|
|
32189
|
-
title: task.title,
|
|
32190
|
-
status: task.status,
|
|
32191
|
-
priority: task.priority
|
|
32192
|
-
}
|
|
32193
|
-
},
|
|
32194
|
-
null,
|
|
32195
|
-
2
|
|
32196
|
-
)
|
|
32197
|
-
}
|
|
32198
|
-
]
|
|
32199
|
-
};
|
|
32200
|
-
}
|
|
32201
|
-
case "list_tasks": {
|
|
32202
|
-
const input = listTasksSchema.parse(args);
|
|
32203
|
-
let tasks = await fileStore.getAllTasks();
|
|
32204
|
-
if (input.status) {
|
|
32205
|
-
tasks = tasks.filter((t) => t.status === input.status);
|
|
32206
|
-
}
|
|
32207
|
-
if (input.priority) {
|
|
32208
|
-
tasks = tasks.filter((t) => t.priority === input.priority);
|
|
32209
|
-
}
|
|
32210
|
-
if (input.assignee) {
|
|
32211
|
-
tasks = tasks.filter((t) => t.assignee === input.assignee);
|
|
32212
|
-
}
|
|
32213
|
-
if (input.label) {
|
|
32214
|
-
tasks = tasks.filter((t) => t.labels.includes(input.label));
|
|
32215
|
-
}
|
|
32216
|
-
return {
|
|
32217
|
-
content: [
|
|
32218
|
-
{
|
|
32219
|
-
type: "text",
|
|
32220
|
-
text: JSON.stringify(
|
|
32221
|
-
{
|
|
32222
|
-
success: true,
|
|
32223
|
-
count: tasks.length,
|
|
32224
|
-
tasks: tasks.map((t) => ({
|
|
32225
|
-
id: t.id,
|
|
32226
|
-
title: t.title,
|
|
32227
|
-
status: t.status,
|
|
32228
|
-
priority: t.priority,
|
|
32229
|
-
assignee: t.assignee,
|
|
32230
|
-
labels: t.labels
|
|
32231
|
-
}))
|
|
32232
|
-
},
|
|
32233
|
-
null,
|
|
32234
|
-
2
|
|
32235
|
-
)
|
|
32236
|
-
}
|
|
32237
|
-
]
|
|
32238
|
-
};
|
|
32239
|
-
}
|
|
32240
|
-
case "search_tasks": {
|
|
32241
|
-
const input = searchTasksSchema.parse(args);
|
|
32242
|
-
const tasks = await fileStore.getAllTasks();
|
|
32243
|
-
const query = input.query.toLowerCase();
|
|
32244
|
-
const results = tasks.filter(
|
|
32245
|
-
(t) => t.title.toLowerCase().includes(query) || t.description?.toLowerCase().includes(query) || t.labels.some((l) => l.toLowerCase().includes(query))
|
|
32246
|
-
);
|
|
32247
|
-
return {
|
|
32248
|
-
content: [
|
|
32249
|
-
{
|
|
32250
|
-
type: "text",
|
|
32251
|
-
text: JSON.stringify(
|
|
32252
|
-
{
|
|
32253
|
-
success: true,
|
|
32254
|
-
count: results.length,
|
|
32255
|
-
tasks: results.map((t) => ({
|
|
32256
|
-
id: t.id,
|
|
32257
|
-
title: t.title,
|
|
32258
|
-
status: t.status,
|
|
32259
|
-
priority: t.priority
|
|
32260
|
-
}))
|
|
32261
|
-
},
|
|
32262
|
-
null,
|
|
32263
|
-
2
|
|
32264
|
-
)
|
|
32265
|
-
}
|
|
32266
|
-
]
|
|
32267
|
-
};
|
|
32268
|
-
}
|
|
32269
|
-
case "start_time": {
|
|
32270
|
-
const input = startTimeSchema.parse(args);
|
|
32271
|
-
const task = await fileStore.getTask(input.taskId);
|
|
32272
|
-
if (!task) {
|
|
32273
|
-
return {
|
|
32274
|
-
content: [
|
|
32275
|
-
{
|
|
32276
|
-
type: "text",
|
|
32277
|
-
text: JSON.stringify({
|
|
32278
|
-
success: false,
|
|
32279
|
-
error: `Task ${input.taskId} not found`
|
|
32280
|
-
})
|
|
32281
|
-
}
|
|
32282
|
-
]
|
|
32283
|
-
};
|
|
32284
|
-
}
|
|
32285
|
-
const activeEntry = task.timeEntries.find((e) => !e.endedAt);
|
|
32286
|
-
if (activeEntry) {
|
|
32287
|
-
return {
|
|
32288
|
-
content: [
|
|
32289
|
-
{
|
|
32290
|
-
type: "text",
|
|
32291
|
-
text: JSON.stringify({
|
|
32292
|
-
success: false,
|
|
32293
|
-
error: "Time tracking already active for this task"
|
|
32294
|
-
})
|
|
32295
|
-
}
|
|
32296
|
-
]
|
|
32297
|
-
};
|
|
32298
|
-
}
|
|
32299
|
-
const newEntry = {
|
|
32300
|
-
id: `entry-${Date.now()}`,
|
|
32301
|
-
startedAt: /* @__PURE__ */ new Date(),
|
|
32302
|
-
duration: 0,
|
|
32303
|
-
note: "Started via MCP"
|
|
32304
|
-
};
|
|
32305
|
-
await fileStore.updateTask(input.taskId, {
|
|
32306
|
-
timeEntries: [...task.timeEntries, newEntry]
|
|
32307
|
-
});
|
|
32308
|
-
return {
|
|
32309
|
-
content: [
|
|
32310
|
-
{
|
|
32311
|
-
type: "text",
|
|
32312
|
-
text: JSON.stringify({
|
|
32313
|
-
success: true,
|
|
32314
|
-
message: `Started tracking time for task ${input.taskId}`,
|
|
32315
|
-
startedAt: newEntry.startedAt
|
|
32316
|
-
})
|
|
32317
|
-
}
|
|
32318
|
-
]
|
|
32319
|
-
};
|
|
32320
|
-
}
|
|
32321
|
-
case "stop_time": {
|
|
32322
|
-
const input = stopTimeSchema.parse(args);
|
|
32323
|
-
const task = await fileStore.getTask(input.taskId);
|
|
32324
|
-
if (!task) {
|
|
32325
|
-
return {
|
|
32326
|
-
content: [
|
|
32327
|
-
{
|
|
32328
|
-
type: "text",
|
|
32329
|
-
text: JSON.stringify({
|
|
32330
|
-
success: false,
|
|
32331
|
-
error: `Task ${input.taskId} not found`
|
|
32332
|
-
})
|
|
32333
|
-
}
|
|
32334
|
-
]
|
|
32335
|
-
};
|
|
32336
|
-
}
|
|
32337
|
-
const activeIndex = task.timeEntries.findIndex((e) => !e.endedAt);
|
|
32338
|
-
if (activeIndex === -1) {
|
|
32339
|
-
return {
|
|
32340
|
-
content: [
|
|
32341
|
-
{
|
|
32342
|
-
type: "text",
|
|
32343
|
-
text: JSON.stringify({
|
|
32344
|
-
success: false,
|
|
32345
|
-
error: "No active time tracking for this task"
|
|
32346
|
-
})
|
|
32347
|
-
}
|
|
32348
|
-
]
|
|
32349
|
-
};
|
|
32350
|
-
}
|
|
32351
|
-
const endTime = /* @__PURE__ */ new Date();
|
|
32352
|
-
const startTime = task.timeEntries[activeIndex].startedAt;
|
|
32353
|
-
const duration3 = Math.floor((endTime.getTime() - startTime.getTime()) / 1e3);
|
|
32354
|
-
const updatedEntries = [...task.timeEntries];
|
|
32355
|
-
updatedEntries[activeIndex] = {
|
|
32356
|
-
...updatedEntries[activeIndex],
|
|
32357
|
-
endedAt: endTime,
|
|
32358
|
-
duration: duration3
|
|
32359
|
-
};
|
|
32360
|
-
const newTimeSpent = task.timeSpent + duration3;
|
|
32361
|
-
await fileStore.updateTask(input.taskId, {
|
|
32362
|
-
timeEntries: updatedEntries,
|
|
32363
|
-
timeSpent: newTimeSpent
|
|
32364
|
-
});
|
|
32365
|
-
return {
|
|
32366
|
-
content: [
|
|
32367
|
-
{
|
|
32368
|
-
type: "text",
|
|
32369
|
-
text: JSON.stringify({
|
|
32370
|
-
success: true,
|
|
32371
|
-
message: `Stopped tracking time for task ${input.taskId}`,
|
|
32372
|
-
duration: formatDuration(duration3),
|
|
32373
|
-
totalTime: formatDuration(newTimeSpent)
|
|
32374
|
-
})
|
|
32375
|
-
}
|
|
32376
|
-
]
|
|
32377
|
-
};
|
|
32378
|
-
}
|
|
32379
|
-
case "add_time": {
|
|
32380
|
-
const input = addTimeSchema.parse(args);
|
|
32381
|
-
const task = await fileStore.getTask(input.taskId);
|
|
32382
|
-
if (!task) {
|
|
32383
|
-
return {
|
|
32384
|
-
content: [
|
|
32385
|
-
{
|
|
32386
|
-
type: "text",
|
|
32387
|
-
text: JSON.stringify({
|
|
32388
|
-
success: false,
|
|
32389
|
-
error: `Task ${input.taskId} not found`
|
|
32390
|
-
})
|
|
32391
|
-
}
|
|
32392
|
-
]
|
|
32393
|
-
};
|
|
32394
|
-
}
|
|
32395
|
-
const duration3 = parseDuration(input.duration);
|
|
32396
|
-
const startDate = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
32397
|
-
const newEntry = {
|
|
32398
|
-
id: `entry-${Date.now()}`,
|
|
32399
|
-
startedAt: startDate,
|
|
32400
|
-
endedAt: new Date(startDate.getTime() + duration3 * 1e3),
|
|
32401
|
-
duration: duration3,
|
|
32402
|
-
note: input.note || "Added via MCP"
|
|
32403
|
-
};
|
|
32404
|
-
const newTimeSpent = task.timeSpent + duration3;
|
|
32405
|
-
await fileStore.updateTask(input.taskId, {
|
|
32406
|
-
timeEntries: [...task.timeEntries, newEntry],
|
|
32407
|
-
timeSpent: newTimeSpent
|
|
32408
|
-
});
|
|
32409
|
-
return {
|
|
32410
|
-
content: [
|
|
32411
|
-
{
|
|
32412
|
-
type: "text",
|
|
32413
|
-
text: JSON.stringify({
|
|
32414
|
-
success: true,
|
|
32415
|
-
message: `Added ${formatDuration(duration3)} to task ${input.taskId}`,
|
|
32416
|
-
totalTime: formatDuration(newTimeSpent)
|
|
32417
|
-
})
|
|
32418
|
-
}
|
|
32419
|
-
]
|
|
32420
|
-
};
|
|
32421
|
-
}
|
|
32422
|
-
case "get_time_report": {
|
|
32423
|
-
const input = getTimeReportSchema.parse(args);
|
|
32424
|
-
const tasks = await fileStore.getAllTasks();
|
|
32425
|
-
let fromDate;
|
|
32426
|
-
let toDate;
|
|
32427
|
-
if (input.from) fromDate = new Date(input.from);
|
|
32428
|
-
if (input.to) toDate = new Date(input.to);
|
|
32429
|
-
const taskTimeData = tasks.map((task) => {
|
|
32430
|
-
let totalSeconds = 0;
|
|
32431
|
-
for (const entry of task.timeEntries) {
|
|
32432
|
-
if (entry.endedAt) {
|
|
32433
|
-
const entryDate = new Date(entry.startedAt);
|
|
32434
|
-
if (fromDate && entryDate < fromDate) continue;
|
|
32435
|
-
if (toDate && entryDate > toDate) continue;
|
|
32436
|
-
totalSeconds += entry.duration;
|
|
32437
|
-
}
|
|
32438
|
-
}
|
|
32439
|
-
return {
|
|
32440
|
-
taskId: task.id,
|
|
32441
|
-
title: task.title,
|
|
32442
|
-
status: task.status,
|
|
32443
|
-
labels: task.labels,
|
|
32444
|
-
totalSeconds
|
|
32445
|
-
};
|
|
32446
|
-
}).filter((data) => data.totalSeconds > 0);
|
|
32447
|
-
if (input.groupBy === "label") {
|
|
32448
|
-
const grouped = {};
|
|
32449
|
-
for (const data of taskTimeData) {
|
|
32450
|
-
for (const label of data.labels) {
|
|
32451
|
-
grouped[label] = (grouped[label] || 0) + data.totalSeconds;
|
|
32452
|
-
}
|
|
32453
|
-
if (data.labels.length === 0) {
|
|
32454
|
-
grouped["(no label)"] = (grouped["(no label)"] || 0) + data.totalSeconds;
|
|
32455
|
-
}
|
|
32456
|
-
}
|
|
32457
|
-
return {
|
|
32458
|
-
content: [
|
|
32459
|
-
{
|
|
32460
|
-
type: "text",
|
|
32461
|
-
text: JSON.stringify(
|
|
32462
|
-
{
|
|
32463
|
-
success: true,
|
|
32464
|
-
groupBy: "label",
|
|
32465
|
-
data: Object.entries(grouped).map(([label, seconds]) => ({
|
|
32466
|
-
label,
|
|
32467
|
-
time: formatDuration(seconds),
|
|
32468
|
-
seconds
|
|
32469
|
-
})),
|
|
32470
|
-
totalSeconds: Object.values(grouped).reduce((a, b) => a + b, 0)
|
|
32471
|
-
},
|
|
32472
|
-
null,
|
|
32473
|
-
2
|
|
32474
|
-
)
|
|
32475
|
-
}
|
|
32476
|
-
]
|
|
32477
|
-
};
|
|
32478
|
-
}
|
|
32479
|
-
if (input.groupBy === "status") {
|
|
32480
|
-
const grouped = {};
|
|
32481
|
-
for (const data of taskTimeData) {
|
|
32482
|
-
grouped[data.status] = (grouped[data.status] || 0) + data.totalSeconds;
|
|
32483
|
-
}
|
|
32484
|
-
return {
|
|
32485
|
-
content: [
|
|
32486
|
-
{
|
|
32487
|
-
type: "text",
|
|
32488
|
-
text: JSON.stringify(
|
|
32489
|
-
{
|
|
32490
|
-
success: true,
|
|
32491
|
-
groupBy: "status",
|
|
32492
|
-
data: Object.entries(grouped).map(([status, seconds]) => ({
|
|
32493
|
-
status,
|
|
32494
|
-
time: formatDuration(seconds),
|
|
32495
|
-
seconds
|
|
32496
|
-
})),
|
|
32497
|
-
totalSeconds: Object.values(grouped).reduce((a, b) => a + b, 0)
|
|
32498
|
-
},
|
|
32499
|
-
null,
|
|
32500
|
-
2
|
|
32501
|
-
)
|
|
32502
|
-
}
|
|
32503
|
-
]
|
|
32504
|
-
};
|
|
32505
|
-
}
|
|
32506
|
-
return {
|
|
32507
|
-
content: [
|
|
32508
|
-
{
|
|
32509
|
-
type: "text",
|
|
32510
|
-
text: JSON.stringify(
|
|
32511
|
-
{
|
|
32512
|
-
success: true,
|
|
32513
|
-
groupBy: "task",
|
|
32514
|
-
data: taskTimeData.map((data) => ({
|
|
32515
|
-
taskId: data.taskId,
|
|
32516
|
-
title: data.title,
|
|
32517
|
-
status: data.status,
|
|
32518
|
-
time: formatDuration(data.totalSeconds),
|
|
32519
|
-
seconds: data.totalSeconds
|
|
32520
|
-
})),
|
|
32521
|
-
totalSeconds: taskTimeData.reduce((sum, data) => sum + data.totalSeconds, 0)
|
|
32522
|
-
},
|
|
32523
|
-
null,
|
|
32524
|
-
2
|
|
32525
|
-
)
|
|
32526
|
-
}
|
|
32527
|
-
]
|
|
32528
|
-
};
|
|
32529
|
-
}
|
|
32530
|
-
case "get_board": {
|
|
32531
|
-
const tasks = await fileStore.getAllTasks();
|
|
32532
|
-
const board = {
|
|
32533
|
-
todo: [],
|
|
32534
|
-
"in-progress": [],
|
|
32535
|
-
"in-review": [],
|
|
32536
|
-
done: [],
|
|
32537
|
-
blocked: []
|
|
32538
|
-
};
|
|
32539
|
-
for (const task of tasks) {
|
|
32540
|
-
if (board[task.status]) {
|
|
32541
|
-
board[task.status].push(task);
|
|
32542
|
-
}
|
|
32543
|
-
}
|
|
32544
|
-
return {
|
|
32545
|
-
content: [
|
|
32546
|
-
{
|
|
32547
|
-
type: "text",
|
|
32548
|
-
text: JSON.stringify(
|
|
32549
|
-
{
|
|
32550
|
-
success: true,
|
|
32551
|
-
board: {
|
|
32552
|
-
todo: board.todo.map((t) => ({
|
|
32553
|
-
id: t.id,
|
|
32554
|
-
title: t.title,
|
|
32555
|
-
priority: t.priority,
|
|
32556
|
-
assignee: t.assignee,
|
|
32557
|
-
labels: t.labels
|
|
32558
|
-
})),
|
|
32559
|
-
"in-progress": board["in-progress"].map((t) => ({
|
|
32560
|
-
id: t.id,
|
|
32561
|
-
title: t.title,
|
|
32562
|
-
priority: t.priority,
|
|
32563
|
-
assignee: t.assignee,
|
|
32564
|
-
labels: t.labels
|
|
32565
|
-
})),
|
|
32566
|
-
"in-review": board["in-review"].map((t) => ({
|
|
32567
|
-
id: t.id,
|
|
32568
|
-
title: t.title,
|
|
32569
|
-
priority: t.priority,
|
|
32570
|
-
assignee: t.assignee,
|
|
32571
|
-
labels: t.labels
|
|
32572
|
-
})),
|
|
32573
|
-
done: board.done.map((t) => ({
|
|
32574
|
-
id: t.id,
|
|
32575
|
-
title: t.title,
|
|
32576
|
-
priority: t.priority,
|
|
32577
|
-
assignee: t.assignee,
|
|
32578
|
-
labels: t.labels
|
|
32579
|
-
})),
|
|
32580
|
-
blocked: board.blocked.map((t) => ({
|
|
32581
|
-
id: t.id,
|
|
32582
|
-
title: t.title,
|
|
32583
|
-
priority: t.priority,
|
|
32584
|
-
assignee: t.assignee,
|
|
32585
|
-
labels: t.labels
|
|
32586
|
-
}))
|
|
32587
|
-
},
|
|
32588
|
-
totalTasks: tasks.length
|
|
32589
|
-
},
|
|
32590
|
-
null,
|
|
32591
|
-
2
|
|
32592
|
-
)
|
|
32593
|
-
}
|
|
32594
|
-
]
|
|
32595
|
-
};
|
|
32596
|
-
}
|
|
32861
|
+
// Task handlers
|
|
32862
|
+
case "create_task":
|
|
32863
|
+
return await handleCreateTask(args, fileStore);
|
|
32864
|
+
case "get_task":
|
|
32865
|
+
return await handleGetTask(args, fileStore);
|
|
32866
|
+
case "update_task":
|
|
32867
|
+
return await handleUpdateTask(args, fileStore);
|
|
32868
|
+
case "list_tasks":
|
|
32869
|
+
return await handleListTasks(args, fileStore);
|
|
32870
|
+
case "search_tasks":
|
|
32871
|
+
return await handleSearchTasks(args, fileStore);
|
|
32872
|
+
// Time handlers
|
|
32873
|
+
case "start_time":
|
|
32874
|
+
return await handleStartTime(args, fileStore);
|
|
32875
|
+
case "stop_time":
|
|
32876
|
+
return await handleStopTime(args, fileStore);
|
|
32877
|
+
case "add_time":
|
|
32878
|
+
return await handleAddTime(args, fileStore);
|
|
32879
|
+
case "get_time_report":
|
|
32880
|
+
return await handleGetTimeReport(args, fileStore);
|
|
32881
|
+
// Board handlers
|
|
32882
|
+
case "get_board":
|
|
32883
|
+
return await handleGetBoard(fileStore);
|
|
32884
|
+
// Doc handlers
|
|
32885
|
+
case "list_docs":
|
|
32886
|
+
return await handleListDocs(args);
|
|
32887
|
+
case "get_doc":
|
|
32888
|
+
return await handleGetDoc(args);
|
|
32889
|
+
case "create_doc":
|
|
32890
|
+
return await handleCreateDoc(args);
|
|
32891
|
+
case "update_doc":
|
|
32892
|
+
return await handleUpdateDoc(args);
|
|
32893
|
+
case "search_docs":
|
|
32894
|
+
return await handleSearchDocs(args);
|
|
32597
32895
|
default:
|
|
32598
|
-
return {
|
|
32599
|
-
content: [
|
|
32600
|
-
{
|
|
32601
|
-
type: "text",
|
|
32602
|
-
text: JSON.stringify({
|
|
32603
|
-
success: false,
|
|
32604
|
-
error: `Unknown tool: ${name}`
|
|
32605
|
-
})
|
|
32606
|
-
}
|
|
32607
|
-
]
|
|
32608
|
-
};
|
|
32896
|
+
return errorResponse(`Unknown tool: ${name}`);
|
|
32609
32897
|
}
|
|
32610
32898
|
} catch (error46) {
|
|
32899
|
+
return errorResponse(error46 instanceof Error ? error46.message : String(error46));
|
|
32900
|
+
}
|
|
32901
|
+
});
|
|
32902
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
32903
|
+
const tasks = await fileStore.getAllTasks();
|
|
32904
|
+
const docsDir = join8(process.cwd(), ".knowns", "docs");
|
|
32905
|
+
const taskResources = tasks.map((task) => ({
|
|
32906
|
+
uri: `knowns://task/${task.id}`,
|
|
32907
|
+
name: task.title,
|
|
32908
|
+
mimeType: "application/json",
|
|
32909
|
+
description: `Task #${task.id}: ${task.title}`
|
|
32910
|
+
}));
|
|
32911
|
+
const docResources = [];
|
|
32912
|
+
if (existsSync5(docsDir)) {
|
|
32913
|
+
const { readdir: readdir3 } = await import("node:fs/promises");
|
|
32914
|
+
async function getAllMdFiles2(dir, basePath = "") {
|
|
32915
|
+
const files = [];
|
|
32916
|
+
const entries = await readdir3(dir, { withFileTypes: true });
|
|
32917
|
+
for (const entry of entries) {
|
|
32918
|
+
const fullPath = join8(dir, entry.name);
|
|
32919
|
+
const relativePath = basePath ? join8(basePath, entry.name) : entry.name;
|
|
32920
|
+
if (entry.isDirectory()) {
|
|
32921
|
+
const subFiles = await getAllMdFiles2(fullPath, relativePath);
|
|
32922
|
+
files.push(...subFiles);
|
|
32923
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
32924
|
+
files.push(relativePath);
|
|
32925
|
+
}
|
|
32926
|
+
}
|
|
32927
|
+
return files;
|
|
32928
|
+
}
|
|
32929
|
+
const mdFiles = await getAllMdFiles2(docsDir);
|
|
32930
|
+
for (const file3 of mdFiles) {
|
|
32931
|
+
const filepath = join8(docsDir, file3);
|
|
32932
|
+
const content = await readFile4(filepath, "utf-8");
|
|
32933
|
+
const { data } = (0, import_gray_matter4.default)(content);
|
|
32934
|
+
docResources.push({
|
|
32935
|
+
uri: `knowns://doc/${file3.replace(/\.md$/, "")}`,
|
|
32936
|
+
name: data.title || file3.replace(/\.md$/, ""),
|
|
32937
|
+
mimeType: "text/markdown",
|
|
32938
|
+
description: data.description || `Documentation: ${file3}`
|
|
32939
|
+
});
|
|
32940
|
+
}
|
|
32941
|
+
}
|
|
32942
|
+
return {
|
|
32943
|
+
resources: [...taskResources, ...docResources]
|
|
32944
|
+
};
|
|
32945
|
+
});
|
|
32946
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
32947
|
+
const uri = request.params.uri;
|
|
32948
|
+
const taskMatch = uri.match(/^knowns:\/\/task\/(.+)$/);
|
|
32949
|
+
if (taskMatch) {
|
|
32950
|
+
const taskId = taskMatch[1];
|
|
32951
|
+
const task = await fileStore.getTask(taskId);
|
|
32952
|
+
if (!task) {
|
|
32953
|
+
throw new Error(`Task ${taskId} not found`);
|
|
32954
|
+
}
|
|
32955
|
+
return {
|
|
32956
|
+
contents: [
|
|
32957
|
+
{
|
|
32958
|
+
uri,
|
|
32959
|
+
mimeType: "application/json",
|
|
32960
|
+
text: JSON.stringify(task, null, 2)
|
|
32961
|
+
}
|
|
32962
|
+
]
|
|
32963
|
+
};
|
|
32964
|
+
}
|
|
32965
|
+
const docMatch = uri.match(/^knowns:\/\/doc\/(.+)$/);
|
|
32966
|
+
if (docMatch) {
|
|
32967
|
+
const docPath = docMatch[1];
|
|
32968
|
+
const docsDir = join8(process.cwd(), ".knowns", "docs");
|
|
32969
|
+
const filepath = join8(docsDir, `${docPath}.md`);
|
|
32970
|
+
if (!existsSync5(filepath)) {
|
|
32971
|
+
throw new Error(`Documentation ${docPath} not found`);
|
|
32972
|
+
}
|
|
32973
|
+
const content = await readFile4(filepath, "utf-8");
|
|
32974
|
+
const { data, content: docContent } = (0, import_gray_matter4.default)(content);
|
|
32611
32975
|
return {
|
|
32612
|
-
|
|
32976
|
+
contents: [
|
|
32613
32977
|
{
|
|
32614
|
-
|
|
32978
|
+
uri,
|
|
32979
|
+
mimeType: "text/markdown",
|
|
32615
32980
|
text: JSON.stringify(
|
|
32616
32981
|
{
|
|
32617
|
-
|
|
32618
|
-
|
|
32982
|
+
metadata: data,
|
|
32983
|
+
content: docContent.trim()
|
|
32619
32984
|
},
|
|
32620
32985
|
null,
|
|
32621
32986
|
2
|
|
@@ -32624,48 +32989,28 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
32624
32989
|
]
|
|
32625
32990
|
};
|
|
32626
32991
|
}
|
|
32992
|
+
throw new Error(`Invalid resource URI: ${uri}`);
|
|
32627
32993
|
});
|
|
32628
|
-
|
|
32629
|
-
|
|
32630
|
-
|
|
32631
|
-
resources: tasks.map((task) => ({
|
|
32632
|
-
uri: `knowns://task/${task.id}`,
|
|
32633
|
-
name: task.title,
|
|
32634
|
-
mimeType: "application/json",
|
|
32635
|
-
description: `Task #${task.id}: ${task.title}`
|
|
32636
|
-
}))
|
|
32637
|
-
};
|
|
32638
|
-
});
|
|
32639
|
-
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
32640
|
-
const uri = request.params.uri;
|
|
32641
|
-
const match = uri.match(/^knowns:\/\/task\/(.+)$/);
|
|
32642
|
-
if (!match) {
|
|
32643
|
-
throw new Error(`Invalid resource URI: ${uri}`);
|
|
32994
|
+
async function startMcpServer(options2 = {}) {
|
|
32995
|
+
if (options2.verbose) {
|
|
32996
|
+
console.error("Knowns MCP Server starting...");
|
|
32644
32997
|
}
|
|
32645
|
-
const taskId = match[1];
|
|
32646
|
-
const task = await fileStore.getTask(taskId);
|
|
32647
|
-
if (!task) {
|
|
32648
|
-
throw new Error(`Task ${taskId} not found`);
|
|
32649
|
-
}
|
|
32650
|
-
return {
|
|
32651
|
-
contents: [
|
|
32652
|
-
{
|
|
32653
|
-
uri,
|
|
32654
|
-
mimeType: "application/json",
|
|
32655
|
-
text: JSON.stringify(task, null, 2)
|
|
32656
|
-
}
|
|
32657
|
-
]
|
|
32658
|
-
};
|
|
32659
|
-
});
|
|
32660
|
-
async function main() {
|
|
32661
32998
|
const transport = new StdioServerTransport();
|
|
32662
32999
|
await server.connect(transport);
|
|
32663
|
-
|
|
33000
|
+
if (options2.verbose) {
|
|
33001
|
+
console.error("Knowns MCP Server running on stdio");
|
|
33002
|
+
}
|
|
32664
33003
|
}
|
|
32665
|
-
|
|
32666
|
-
|
|
32667
|
-
|
|
32668
|
-
|
|
33004
|
+
var isStandaloneServer = process.argv[1]?.includes("mcp/server") || process.argv[1]?.includes("mcp\\server");
|
|
33005
|
+
if (isStandaloneServer) {
|
|
33006
|
+
startMcpServer({ verbose: true }).catch((error46) => {
|
|
33007
|
+
console.error("Fatal error:", error46);
|
|
33008
|
+
process.exit(1);
|
|
33009
|
+
});
|
|
33010
|
+
}
|
|
33011
|
+
export {
|
|
33012
|
+
startMcpServer
|
|
33013
|
+
};
|
|
32669
33014
|
/*! Bundled license information:
|
|
32670
33015
|
|
|
32671
33016
|
is-extendable/index.js:
|