planmode 0.3.0 → 0.4.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.
package/src/mcp.ts CHANGED
@@ -17,6 +17,7 @@ import { runDoctor } from "./lib/doctor.js";
17
17
  import { testPackage } from "./lib/tester.js";
18
18
  import { startRecordingAsync, stopRecording, isRecording } from "./lib/recorder.js";
19
19
  import { takeSnapshot } from "./lib/snapshot.js";
20
+ import { addContextRepo, removeContextRepo, reindexContext, getContextSummary, formatSize } from "./lib/context.js";
20
21
  import type { Category } from "./types/index.js";
21
22
 
22
23
  // ── Helpers ──
@@ -784,6 +785,151 @@ server.registerTool(
784
785
  },
785
786
  );
786
787
 
788
+ // -- planmode_context_add --
789
+ server.registerTool(
790
+ "planmode_context_add",
791
+ {
792
+ description: "Add a document directory to the project context. Indexes all text-based files (md, pdf, txt, json, yaml, csv, html, etc.) and stores their metadata in .planmode/context.yaml. The AI can then see what documents are available and read them on demand.",
793
+ inputSchema: {
794
+ path: z.string().describe("Path to the document directory (relative to project or absolute)"),
795
+ name: z.string().optional().describe("Human-readable label for this directory"),
796
+ projectDir: z.string().optional().describe("Project directory (default: current working directory)"),
797
+ },
798
+ },
799
+ async ({ path: dirPath, name, projectDir }) => {
800
+ try {
801
+ const { result, messages } = withCapture(() =>
802
+ addContextRepo(dirPath, { name, projectDir }),
803
+ );
804
+
805
+ const breakdown = result.files.length > 0
806
+ ? `\nTypes: ${getTypeBreakdownText(result)}`
807
+ : "";
808
+
809
+ return textResult(
810
+ formatMessages(
811
+ messages,
812
+ `Added "${name ?? result.repo.path}" — ${result.file_count} file(s), ${formatSize(result.total_size)}${breakdown}`,
813
+ ),
814
+ );
815
+ } catch (err) {
816
+ return errorResult("Error adding context repo", err as Error);
817
+ }
818
+ },
819
+ );
820
+
821
+ // -- planmode_context_remove --
822
+ server.registerTool(
823
+ "planmode_context_remove",
824
+ {
825
+ description: "Remove a document directory from the project context",
826
+ inputSchema: {
827
+ pathOrName: z.string().describe("Path or name of the context repo to remove"),
828
+ projectDir: z.string().optional().describe("Project directory (default: current working directory)"),
829
+ },
830
+ },
831
+ async ({ pathOrName, projectDir }) => {
832
+ try {
833
+ const { messages } = withCapture(() =>
834
+ removeContextRepo(pathOrName, projectDir),
835
+ );
836
+
837
+ return textResult(formatMessages(messages) || `Removed "${pathOrName}" from context.`);
838
+ } catch (err) {
839
+ return errorResult("Error removing context repo", err as Error);
840
+ }
841
+ },
842
+ );
843
+
844
+ // -- planmode_context_list --
845
+ server.registerTool(
846
+ "planmode_context_list",
847
+ {
848
+ description: "List all document directories in the project context with file counts, sizes, and type breakdowns. Use this to see what reference documents are available for the project.",
849
+ inputSchema: {
850
+ detailed: z.boolean().optional().describe("Include full file listings for each repo (default: false, shows only summaries)"),
851
+ projectDir: z.string().optional().describe("Project directory (default: current working directory)"),
852
+ },
853
+ },
854
+ async ({ detailed, projectDir }) => {
855
+ try {
856
+ const summary = getContextSummary(projectDir);
857
+
858
+ if (summary.totalRepos === 0) {
859
+ return textResult("No context repos configured. Use planmode_context_add to add a document directory.");
860
+ }
861
+
862
+ const lines = [
863
+ `**${summary.totalRepos} context repo(s)** — ${summary.totalFiles} file(s), ${formatSize(summary.totalSize)}`,
864
+ "",
865
+ ];
866
+
867
+ for (const repo of summary.repos) {
868
+ lines.push(`### ${repo.name}`);
869
+ lines.push(`- **Path:** ${repo.path}`);
870
+ lines.push(`- **Files:** ${repo.fileCount} (${formatSize(repo.totalSize)})`);
871
+ if (repo.typeBreakdown.length > 0) {
872
+ lines.push(`- **Types:** ${repo.typeBreakdown.join(", ")}`);
873
+ }
874
+ lines.push(`- **Indexed:** ${repo.indexedAt}`);
875
+
876
+ if (detailed) {
877
+ const index = (await import("./lib/context.js")).readContextIndex(projectDir);
878
+ const repoIndex = index.repos.find(
879
+ (r) => r.repo.path === repo.path || r.repo.name === repo.name,
880
+ );
881
+ if (repoIndex && repoIndex.files.length > 0) {
882
+ lines.push("", "**Files:**");
883
+ for (const file of repoIndex.files) {
884
+ lines.push(`- \`${file.path}\` (${file.extension}, ${formatSize(file.size)})`);
885
+ }
886
+ }
887
+ }
888
+
889
+ lines.push("");
890
+ }
891
+
892
+ return textResult(lines.join("\n"));
893
+ } catch (err) {
894
+ return errorResult("Error listing context", err as Error);
895
+ }
896
+ },
897
+ );
898
+
899
+ // -- planmode_context_reindex --
900
+ server.registerTool(
901
+ "planmode_context_reindex",
902
+ {
903
+ description: "Re-scan files in one or all context directories to update the file index",
904
+ inputSchema: {
905
+ pathOrName: z.string().optional().describe("Path or name of a specific repo to reindex (omit to reindex all)"),
906
+ projectDir: z.string().optional().describe("Project directory (default: current working directory)"),
907
+ },
908
+ },
909
+ async ({ pathOrName, projectDir }) => {
910
+ try {
911
+ const { messages } = withCapture(() =>
912
+ reindexContext(pathOrName, projectDir),
913
+ );
914
+
915
+ return textResult(formatMessages(messages) || "Reindex complete.");
916
+ } catch (err) {
917
+ return errorResult("Error reindexing context", err as Error);
918
+ }
919
+ },
920
+ );
921
+
922
+ function getTypeBreakdownText(repoIndex: { files: Array<{ extension: string }> }): string {
923
+ const counts = new Map<string, number>();
924
+ for (const file of repoIndex.files) {
925
+ counts.set(file.extension, (counts.get(file.extension) ?? 0) + 1);
926
+ }
927
+ return Array.from(counts.entries())
928
+ .sort((a, b) => b[1] - a[1])
929
+ .map(([ext, count]) => `${ext}: ${count}`)
930
+ .join(", ");
931
+ }
932
+
787
933
  // ── Resources ──
788
934
 
789
935
  // Expose installed packages as browsable resources
@@ -133,6 +133,34 @@ export interface PlanmodeConfig {
133
133
  };
134
134
  }
135
135
 
136
+ // ── Context (document indexing) ──
137
+
138
+ export interface ContextRepo {
139
+ path: string;
140
+ name?: string;
141
+ added_at: string;
142
+ }
143
+
144
+ export interface IndexedFile {
145
+ path: string;
146
+ extension: string;
147
+ size: number;
148
+ modified_at: string;
149
+ }
150
+
151
+ export interface ContextRepoIndex {
152
+ repo: ContextRepo;
153
+ files: IndexedFile[];
154
+ indexed_at: string;
155
+ file_count: number;
156
+ total_size: number;
157
+ }
158
+
159
+ export interface ContextIndex {
160
+ version: number;
161
+ repos: ContextRepoIndex[];
162
+ }
163
+
136
164
  // ── Resolved package info ──
137
165
 
138
166
  export interface ResolvedPackage {