compound-agent 1.2.0 → 1.2.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 +20 -1
- package/README.md +1 -0
- package/dist/cli.js +161 -12
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +119 -95
- package/dist/mcp.js.map +1 -1
- package/package.json +1 -1
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 } from 'fs';
|
|
8
|
+
import { mkdirSync, unlinkSync, statSync, existsSync } from 'fs';
|
|
9
9
|
import { createRequire } from 'module';
|
|
10
10
|
import { getLlama, resolveModelFile } from 'node-llama-cpp';
|
|
11
11
|
import { homedir } from 'os';
|
|
@@ -717,98 +717,6 @@ 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 \`ca prime\` after compaction, clear, or new session
|
|
724
|
-
|
|
725
|
-
## MCP Tools (ALWAYS USE THESE)
|
|
726
|
-
|
|
727
|
-
**You MUST use MCP tools, NOT CLI commands:**
|
|
728
|
-
|
|
729
|
-
| Tool | Purpose |
|
|
730
|
-
|------|---------|
|
|
731
|
-
| \`memory_search\` | Search lessons - call BEFORE architectural decisions |
|
|
732
|
-
| \`memory_capture\` | Capture lessons - call AFTER corrections or discoveries |
|
|
733
|
-
|
|
734
|
-
## Core Constraints
|
|
735
|
-
|
|
736
|
-
**Default**: Use MCP tools 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 \`memory_search\` BEFORE:
|
|
745
|
-
- Architectural decisions or complex planning
|
|
746
|
-
- Implementing patterns you've done before in this repo
|
|
747
|
-
|
|
748
|
-
**NEVER skip memory_search for complex decisions.** Past mistakes will repeat.
|
|
749
|
-
|
|
750
|
-
## Capture Protocol
|
|
751
|
-
|
|
752
|
-
Call \`memory_capture\` 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
|
-
## CLI (fallback only)
|
|
765
|
-
|
|
766
|
-
When MCP is unavailable: \`ca search "query"\`, \`ca learn "insight"\`, \`ca list\`
|
|
767
|
-
`;
|
|
768
|
-
function formatSource(source) {
|
|
769
|
-
switch (source) {
|
|
770
|
-
case "user_correction":
|
|
771
|
-
return "user correction";
|
|
772
|
-
case "self_correction":
|
|
773
|
-
return "self correction";
|
|
774
|
-
case "test_failure":
|
|
775
|
-
return "test failure";
|
|
776
|
-
case "manual":
|
|
777
|
-
return "manual";
|
|
778
|
-
default:
|
|
779
|
-
return source;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
function formatLessonForPrime(lesson) {
|
|
783
|
-
const date = lesson.created.slice(0, 10);
|
|
784
|
-
const tags = lesson.tags.length > 0 ? ` (${lesson.tags.join(", ")})` : "";
|
|
785
|
-
const source = formatSource(lesson.source);
|
|
786
|
-
return `- **${lesson.insight}**${tags}
|
|
787
|
-
Learned: ${date} via ${source}`;
|
|
788
|
-
}
|
|
789
|
-
async function getPrimeContext(repoRoot) {
|
|
790
|
-
const root = repoRoot ?? getRepoRoot();
|
|
791
|
-
try {
|
|
792
|
-
await syncIfNeeded(root);
|
|
793
|
-
} catch {
|
|
794
|
-
}
|
|
795
|
-
const lessons = await loadSessionLessons(root, 5);
|
|
796
|
-
let output = TRUST_LANGUAGE_TEMPLATE;
|
|
797
|
-
if (lessons.length > 0) {
|
|
798
|
-
const formattedLessons = lessons.map(formatLessonForPrime).join("\n\n");
|
|
799
|
-
output += `
|
|
800
|
-
---
|
|
801
|
-
|
|
802
|
-
# [CRITICAL] Mandatory Recall
|
|
803
|
-
|
|
804
|
-
Critical lessons from past corrections:
|
|
805
|
-
|
|
806
|
-
${formattedLessons}
|
|
807
|
-
`;
|
|
808
|
-
}
|
|
809
|
-
return output;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
720
|
// src/memory/capture/triggers.ts
|
|
813
721
|
var PATTERN_INDICATORS = [
|
|
814
722
|
/\buse\s+.+\s+instead\s+of\b/i,
|
|
@@ -909,12 +817,128 @@ z.object({
|
|
|
909
817
|
summary: AuditSummarySchema,
|
|
910
818
|
timestamp: z.string()
|
|
911
819
|
});
|
|
912
|
-
|
|
913
|
-
// src/index.ts
|
|
914
820
|
var _require = createRequire(import.meta.url);
|
|
915
821
|
var _pkg = _require("../package.json");
|
|
916
822
|
var VERSION = _pkg.version;
|
|
917
823
|
|
|
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
|
+
|
|
918
942
|
// src/mcp.ts
|
|
919
943
|
var DEFAULT_MAX_RESULTS = 5;
|
|
920
944
|
var MIN_INSIGHT_LENGTH = 10;
|