devguard 0.1.0 → 0.2.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.
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSearchEntries = registerSearchEntries;
4
+ const zod_1 = require("zod");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ function registerSearchEntries(server) {
8
+ server.tool("search_entries", "Search diary entries by keyword or date range. Returns matching sections from the diary so you can find past decisions, issues, or context without reading every entry.", {
9
+ project_path: zod_1.z.string().describe("Absolute path to the project directory"),
10
+ query: zod_1.z.string().describe("Keyword or phrase to search for (case-insensitive)"),
11
+ from_date: zod_1.z
12
+ .string()
13
+ .optional()
14
+ .describe("Start date filter (YYYY-MM-DD). Only entries on or after this date."),
15
+ to_date: zod_1.z
16
+ .string()
17
+ .optional()
18
+ .describe("End date filter (YYYY-MM-DD). Only entries on or before this date."),
19
+ }, async ({ project_path, query, from_date, to_date, }) => {
20
+ const dir = (0, path_1.join)(project_path, ".devguard", "entries");
21
+ if (!(0, fs_1.existsSync)(dir)) {
22
+ return {
23
+ content: [{ type: "text", text: "No diary entries found." }],
24
+ };
25
+ }
26
+ let files = (0, fs_1.readdirSync)(dir)
27
+ .filter((f) => f.endsWith(".md"))
28
+ .sort()
29
+ .reverse();
30
+ // Date filtering
31
+ if (from_date) {
32
+ files = files.filter((f) => f.replace(".md", "") >= from_date);
33
+ }
34
+ if (to_date) {
35
+ files = files.filter((f) => f.replace(".md", "") <= to_date);
36
+ }
37
+ const queryLower = query.toLowerCase();
38
+ const matches = [];
39
+ for (const file of files) {
40
+ const content = (0, fs_1.readFileSync)((0, path_1.join)(dir, file), "utf-8");
41
+ if (!content.toLowerCase().includes(queryLower))
42
+ continue;
43
+ const date = file.replace(".md", "");
44
+ // Split into sessions and find matching ones
45
+ const sessions = content.split(/---\s*\n\s*<!--\s*session:/);
46
+ const matchingSections = [];
47
+ for (const session of sessions) {
48
+ if (session.toLowerCase().includes(queryLower)) {
49
+ // Extract a concise snippet around the match
50
+ const lines = session.split("\n");
51
+ const matchingLines = lines.filter((l) => l.toLowerCase().includes(queryLower));
52
+ matchingSections.push(matchingLines.slice(0, 5).join("\n"));
53
+ }
54
+ }
55
+ if (matchingSections.length > 0) {
56
+ matches.push(`### ${date}\n${matchingSections.join("\n...\n")}`);
57
+ }
58
+ }
59
+ if (matches.length === 0) {
60
+ return {
61
+ content: [
62
+ {
63
+ type: "text",
64
+ text: `No entries matching "${query}"${from_date ? ` from ${from_date}` : ""}${to_date ? ` to ${to_date}` : ""}.`,
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ return {
70
+ content: [
71
+ {
72
+ type: "text",
73
+ text: `**Search results for "${query}" (${matches.length} entries):**\n\n${matches.join("\n\n---\n\n")}`,
74
+ },
75
+ ],
76
+ };
77
+ });
78
+ }
@@ -4,13 +4,13 @@ exports.registerSetup = registerSetup;
4
4
  const zod_1 = require("zod");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
- const INSTRUCTION = `After completing a task, switching branches, or making a significant commit, call the devguard write_entry tool to log what was done and what's next.`;
7
+ const INSTRUCTION = `After completing a task, switching branches, or making a significant commit, call the devdiary write_entry tool to log what was done and what's next.`;
8
8
  const CONFIG_FILES = ["CLAUDE.md", ".cursorrules"];
9
9
  function hasInstruction(content) {
10
- return content.includes("devguard write_entry");
10
+ return content.includes("devdiary write_entry");
11
11
  }
12
12
  function registerSetup(server) {
13
- server.tool("setup", "Add devguard's auto-logging instruction to your project's CLAUDE.md or .cursorrules. Run once per project — it appends the instruction so your AI writes diary entries automatically.", {
13
+ server.tool("setup", "Add devdiary's auto-logging instruction to your project's CLAUDE.md or .cursorrules. Run once per project — it appends the instruction so your AI writes diary entries automatically.", {
14
14
  project_path: zod_1.z.string().describe("Absolute path to the project directory"),
15
15
  target: zod_1.z
16
16
  .enum(["CLAUDE.md", ".cursorrules", "auto"])
@@ -42,7 +42,7 @@ function registerSetup(server) {
42
42
  content: [
43
43
  {
44
44
  type: "text",
45
- text: `Already set up — ${targetFile} already contains the devguard instruction.`,
45
+ text: `Already set up — ${targetFile} already contains the devdiary instruction.`,
46
46
  },
47
47
  ],
48
48
  };
@@ -60,7 +60,7 @@ function registerSetup(server) {
60
60
  content: [
61
61
  {
62
62
  type: "text",
63
- text: `Done — added devguard instruction to ${targetFile}. Your AI will now log diary entries automatically.`,
63
+ text: `Done — added devdiary instruction to ${targetFile}. Your AI will now log diary entries automatically.`,
64
64
  },
65
65
  ],
66
66
  };
@@ -59,10 +59,14 @@ function registerWriteEntry(server) {
59
59
  ? git.getBranch(project_path)
60
60
  : "unknown";
61
61
  const now = new Date().toISOString();
62
+ const commit = git.isGitRepo(project_path)
63
+ ? git.getHeadCommitHash(project_path)
64
+ : "none";
62
65
  const sections = [
63
66
  `---`,
64
67
  `date: ${now}`,
65
68
  `branch: ${branch}`,
69
+ `commit: ${commit}`,
66
70
  `summary: "${summary}"`,
67
71
  `---`,
68
72
  "",
@@ -81,7 +85,10 @@ function registerWriteEntry(server) {
81
85
  sections.push("", "## Next Steps", next_steps);
82
86
  }
83
87
  const content = sections.join("\n") + "\n";
84
- const filePath = storage.writeEntry(project_path, content);
88
+ const isMainBranch = branch === "main" || branch === "master";
89
+ const filePath = isMainBranch
90
+ ? storage.writeEntry(project_path, content)
91
+ : storage.writeBranchEntry(project_path, branch, content);
85
92
  return {
86
93
  content: [
87
94
  {
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.autoSetup = autoSetup;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
- const GITIGNORE_ENTRY = ".devguard/";
7
- const INSTRUCTION = `After completing a task, switching branches, or making a significant commit, call the devguard write_entry tool to log what was done and what's next.`;
6
+ const GITIGNORE_ENTRY = ".devdiary/";
7
+ const INSTRUCTION = `After completing a task, switching branches, or making a significant commit, call the devdiary write_entry tool to log what was done and what's next.`;
8
8
  function autoSetup(projectPath) {
9
9
  addToGitignore(projectPath);
10
10
  addInstruction(projectPath);
@@ -20,7 +20,7 @@ function addToGitignore(projectPath) {
20
20
  else {
21
21
  (0, fs_1.writeFileSync)(gitignorePath, `${GITIGNORE_ENTRY}\n`, "utf-8");
22
22
  }
23
- console.error(`devguard: added ${GITIGNORE_ENTRY} to .gitignore`);
23
+ console.error(`devdiary: added ${GITIGNORE_ENTRY} to .gitignore`);
24
24
  }
25
25
  function addInstruction(projectPath) {
26
26
  const claudeMd = (0, path_1.join)(projectPath, "CLAUDE.md");
@@ -43,12 +43,12 @@ function addInstruction(projectPath) {
43
43
  // Already has it?
44
44
  if ((0, fs_1.existsSync)(targetPath)) {
45
45
  const content = (0, fs_1.readFileSync)(targetPath, "utf-8");
46
- if (content.includes("devguard write_entry"))
46
+ if (content.includes("devdiary write_entry"))
47
47
  return;
48
48
  (0, fs_1.appendFileSync)(targetPath, `\n\n# Dev Diary\n\n${INSTRUCTION}\n`, "utf-8");
49
49
  }
50
50
  else {
51
51
  (0, fs_1.writeFileSync)(targetPath, `# Dev Diary\n\n${INSTRUCTION}\n`, "utf-8");
52
52
  }
53
- console.error(`devguard: added auto-logging instruction to ${targetName}`);
53
+ console.error(`devdiary: added auto-logging instruction to ${targetName}`);
54
54
  }
@@ -0,0 +1,19 @@
1
+ import { CommitNode } from "./git.js";
2
+ import { DiaryEntry } from "./storage.js";
3
+ export interface BranchData {
4
+ name: string;
5
+ isCurrent: boolean;
6
+ isMain: boolean;
7
+ summary: string;
8
+ ahead: number;
9
+ behind: number;
10
+ commits: CommitNode[];
11
+ filesChanged: number;
12
+ diaryEntries: DiaryEntry[];
13
+ }
14
+ export interface GitEvent {
15
+ type: "fork" | "merge" | "new";
16
+ label: string;
17
+ branch: string;
18
+ }
19
+ export declare function generateAndOpenBranchMap(projectPath: string, branches: BranchData[], events: GitEvent[]): string;