compound-agent 1.2.5 → 1.2.6

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/mcp.js CHANGED
@@ -5,7 +5,7 @@ import { z } from 'zod';
5
5
  import { mkdir, appendFile, readFile } from 'fs/promises';
6
6
  import { join, dirname } from 'path';
7
7
  import { createHash } from 'crypto';
8
- import { mkdirSync, unlinkSync, statSync, existsSync } from 'fs';
8
+ import { mkdirSync, unlinkSync, statSync } from 'fs';
9
9
  import { createRequire } from 'module';
10
10
  import { getLlama, resolveModelFile } from 'node-llama-cpp';
11
11
  import { homedir } from 'os';
@@ -717,6 +717,94 @@ function rankLessons(lessons) {
717
717
  })).sort((a, b) => (b.finalScore ?? 0) - (a.finalScore ?? 0));
718
718
  }
719
719
 
720
+ // src/commands/management-prime.ts
721
+ var TRUST_LANGUAGE_TEMPLATE = `# Compound Agent Active
722
+
723
+ > **Context Recovery**: Run \`npx ca prime\` after compaction, clear, or new session
724
+
725
+ ## CLI Commands (ALWAYS USE THESE)
726
+
727
+ **You MUST use CLI commands for lesson management:**
728
+
729
+ | Command | Purpose |
730
+ |---------|---------|
731
+ | \`npx ca search "query"\` | Search lessons - call BEFORE architectural decisions |
732
+ | \`npx ca learn "insight"\` | Capture lessons - call AFTER corrections or discoveries |
733
+
734
+ ## Core Constraints
735
+
736
+ **Default**: Use CLI commands for lesson management
737
+ **Prohibited**: NEVER edit .claude/lessons/ files directly
738
+
739
+ **Default**: Propose lessons freely after corrections
740
+ **Prohibited**: NEVER propose without quality gate (novel + specific; prefer actionable)
741
+
742
+ ## Retrieval Protocol
743
+
744
+ You MUST call \`npx ca search\` BEFORE:
745
+ - Architectural decisions or complex planning
746
+ - Implementing patterns you've done before in this repo
747
+
748
+ **NEVER skip search for complex decisions.** Past mistakes will repeat.
749
+
750
+ ## Capture Protocol
751
+
752
+ Run \`npx ca learn\` AFTER:
753
+ - User corrects you ("no", "wrong", "actually...")
754
+ - You self-correct after iteration failures
755
+ - Test fails then you fix it
756
+
757
+ **Quality gate** (must pass before capturing):
758
+ - Novel (not already stored)
759
+ - Specific (clear guidance)
760
+ - Actionable (preferred, not mandatory)
761
+
762
+ **Workflow**: Search BEFORE deciding, capture AFTER learning.
763
+ `;
764
+ function formatSource(source) {
765
+ switch (source) {
766
+ case "user_correction":
767
+ return "user correction";
768
+ case "self_correction":
769
+ return "self correction";
770
+ case "test_failure":
771
+ return "test failure";
772
+ case "manual":
773
+ return "manual";
774
+ default:
775
+ return source;
776
+ }
777
+ }
778
+ function formatLessonForPrime(lesson) {
779
+ const date = lesson.created.slice(0, 10);
780
+ const tags = lesson.tags.length > 0 ? ` (${lesson.tags.join(", ")})` : "";
781
+ const source = formatSource(lesson.source);
782
+ return `- **${lesson.insight}**${tags}
783
+ Learned: ${date} via ${source}`;
784
+ }
785
+ async function getPrimeContext(repoRoot) {
786
+ const root = repoRoot ?? getRepoRoot();
787
+ try {
788
+ await syncIfNeeded(root);
789
+ } catch {
790
+ }
791
+ const lessons = await loadSessionLessons(root, 5);
792
+ let output = TRUST_LANGUAGE_TEMPLATE;
793
+ if (lessons.length > 0) {
794
+ const formattedLessons = lessons.map(formatLessonForPrime).join("\n\n");
795
+ output += `
796
+ ---
797
+
798
+ # [CRITICAL] Mandatory Recall
799
+
800
+ Critical lessons from past corrections:
801
+
802
+ ${formattedLessons}
803
+ `;
804
+ }
805
+ return output;
806
+ }
807
+
720
808
  // src/memory/capture/triggers.ts
721
809
  var PATTERN_INDICATORS = [
722
810
  /\buse\s+.+\s+instead\s+of\b/i,
@@ -817,128 +905,12 @@ z.object({
817
905
  summary: AuditSummarySchema,
818
906
  timestamp: z.string()
819
907
  });
908
+
909
+ // src/index.ts
820
910
  var _require = createRequire(import.meta.url);
821
911
  var _pkg = _require("../package.json");
822
912
  var VERSION = _pkg.version;
823
913
 
824
- // src/setup/claude-helpers.ts
825
- function getMcpJsonPath(repoRoot) {
826
- const root = repoRoot ?? getRepoRoot();
827
- return join(root, ".mcp.json");
828
- }
829
- async function readMcpJson(mcpPath) {
830
- if (!existsSync(mcpPath)) {
831
- return {};
832
- }
833
- const content = await readFile(mcpPath, "utf-8");
834
- return JSON.parse(content);
835
- }
836
- async function hasMcpServerInMcpJson(repoRoot) {
837
- const mcpPath = getMcpJsonPath(repoRoot);
838
- const config = await readMcpJson(mcpPath);
839
- const mcpServers = config.mcpServers;
840
- return !!mcpServers?.["compound-agent"];
841
- }
842
-
843
- // src/commands/management-prime.ts
844
- var TRUST_LANGUAGE_TEMPLATE = `# Compound Agent Active
845
-
846
- > **Context Recovery**: Run \`ca prime\` after compaction, clear, or new session
847
-
848
- ## MCP Tools (ALWAYS USE THESE)
849
-
850
- **You MUST use MCP tools, NOT CLI commands:**
851
-
852
- | Tool | Purpose |
853
- |------|---------|
854
- | \`memory_search\` | Search lessons - call BEFORE architectural decisions |
855
- | \`memory_capture\` | Capture lessons - call AFTER corrections or discoveries |
856
-
857
- ## Core Constraints
858
-
859
- **Default**: Use MCP tools for lesson management
860
- **Prohibited**: NEVER edit .claude/lessons/ files directly
861
-
862
- **Default**: Propose lessons freely after corrections
863
- **Prohibited**: NEVER propose without quality gate (novel + specific; prefer actionable)
864
-
865
- ## Retrieval Protocol
866
-
867
- You MUST call \`memory_search\` BEFORE:
868
- - Architectural decisions or complex planning
869
- - Implementing patterns you've done before in this repo
870
-
871
- **NEVER skip memory_search for complex decisions.** Past mistakes will repeat.
872
-
873
- ## Capture Protocol
874
-
875
- Call \`memory_capture\` AFTER:
876
- - User corrects you ("no", "wrong", "actually...")
877
- - You self-correct after iteration failures
878
- - Test fails then you fix it
879
-
880
- **Quality gate** (must pass before capturing):
881
- - Novel (not already stored)
882
- - Specific (clear guidance)
883
- - Actionable (preferred, not mandatory)
884
-
885
- **Workflow**: Search BEFORE deciding, capture AFTER learning.
886
-
887
- ## CLI (fallback only)
888
-
889
- When MCP is unavailable: \`ca search "query"\`, \`ca learn "insight"\`, \`ca list\`
890
- `;
891
- function formatSource(source) {
892
- switch (source) {
893
- case "user_correction":
894
- return "user correction";
895
- case "self_correction":
896
- return "self correction";
897
- case "test_failure":
898
- return "test failure";
899
- case "manual":
900
- return "manual";
901
- default:
902
- return source;
903
- }
904
- }
905
- function formatLessonForPrime(lesson) {
906
- const date = lesson.created.slice(0, 10);
907
- const tags = lesson.tags.length > 0 ? ` (${lesson.tags.join(", ")})` : "";
908
- const source = formatSource(lesson.source);
909
- return `- **${lesson.insight}**${tags}
910
- Learned: ${date} via ${source}`;
911
- }
912
- async function getPrimeContext(repoRoot) {
913
- const root = repoRoot ?? getRepoRoot();
914
- try {
915
- await syncIfNeeded(root);
916
- } catch {
917
- }
918
- const lessons = await loadSessionLessons(root, 5);
919
- let output = TRUST_LANGUAGE_TEMPLATE;
920
- const hasMcp = await hasMcpServerInMcpJson(root);
921
- if (!hasMcp) {
922
- output += `
923
- WARNING: MCP server not registered. Run 'npx ca setup' to enable memory_search/memory_capture tools.
924
-
925
- `;
926
- }
927
- if (lessons.length > 0) {
928
- const formattedLessons = lessons.map(formatLessonForPrime).join("\n\n");
929
- output += `
930
- ---
931
-
932
- # [CRITICAL] Mandatory Recall
933
-
934
- Critical lessons from past corrections:
935
-
936
- ${formattedLessons}
937
- `;
938
- }
939
- return output;
940
- }
941
-
942
914
  // src/mcp.ts
943
915
  var DEFAULT_MAX_RESULTS = 5;
944
916
  var MIN_INSIGHT_LENGTH = 10;