@codeledger/cli 0.9.1 → 0.9.3

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.
Files changed (163) hide show
  1. package/dist/commands/activate.d.ts.map +1 -1
  2. package/dist/commands/activate.js +306 -19
  3. package/dist/commands/activate.js.map +1 -1
  4. package/dist/commands/capsule-change.d.ts +7 -0
  5. package/dist/commands/capsule-change.d.ts.map +1 -0
  6. package/dist/commands/capsule-change.js +177 -0
  7. package/dist/commands/capsule-change.js.map +1 -0
  8. package/dist/commands/ci.js +9 -119
  9. package/dist/commands/ci.js.map +1 -1
  10. package/dist/commands/coordination.js +1 -1
  11. package/dist/commands/coordination.js.map +1 -1
  12. package/dist/commands/dashboard.d.ts +9 -3
  13. package/dist/commands/dashboard.d.ts.map +1 -1
  14. package/dist/commands/dashboard.js +374 -4
  15. package/dist/commands/dashboard.js.map +1 -1
  16. package/dist/commands/features.d.ts.map +1 -1
  17. package/dist/commands/features.js +3 -0
  18. package/dist/commands/features.js.map +1 -1
  19. package/dist/commands/graph.d.ts +7 -3
  20. package/dist/commands/graph.d.ts.map +1 -1
  21. package/dist/commands/graph.js +272 -4
  22. package/dist/commands/graph.js.map +1 -1
  23. package/dist/commands/harvest.d.ts.map +1 -1
  24. package/dist/commands/harvest.js +28 -0
  25. package/dist/commands/harvest.js.map +1 -1
  26. package/dist/commands/init.d.ts.map +1 -1
  27. package/dist/commands/init.js +22 -7
  28. package/dist/commands/init.js.map +1 -1
  29. package/dist/commands/insight.js +2 -1
  30. package/dist/commands/insight.js.map +1 -1
  31. package/dist/commands/mcp.d.ts +14 -0
  32. package/dist/commands/mcp.d.ts.map +1 -0
  33. package/dist/commands/mcp.js +70 -0
  34. package/dist/commands/mcp.js.map +1 -0
  35. package/dist/commands/memory.js +53 -0
  36. package/dist/commands/memory.js.map +1 -1
  37. package/dist/commands/merge-check.d.ts +15 -0
  38. package/dist/commands/merge-check.d.ts.map +1 -0
  39. package/dist/commands/merge-check.js +137 -0
  40. package/dist/commands/merge-check.js.map +1 -0
  41. package/dist/commands/outcome.d.ts.map +1 -1
  42. package/dist/commands/outcome.js +3 -0
  43. package/dist/commands/outcome.js.map +1 -1
  44. package/dist/commands/scan.d.ts.map +1 -1
  45. package/dist/commands/scan.js +9 -2
  46. package/dist/commands/scan.js.map +1 -1
  47. package/dist/commands/serve.js.map +1 -1
  48. package/dist/commands/session-summary.d.ts.map +1 -1
  49. package/dist/commands/session-summary.js +198 -1
  50. package/dist/commands/session-summary.js.map +1 -1
  51. package/dist/commands/setup-ci.js +8 -4
  52. package/dist/commands/setup-ci.js.map +1 -1
  53. package/dist/commands/sync.d.ts +9 -0
  54. package/dist/commands/sync.d.ts.map +1 -0
  55. package/dist/commands/sync.js +157 -0
  56. package/dist/commands/sync.js.map +1 -0
  57. package/dist/commands/verify.d.ts +24 -1
  58. package/dist/commands/verify.d.ts.map +1 -1
  59. package/dist/commands/verify.js +73 -0
  60. package/dist/commands/verify.js.map +1 -1
  61. package/dist/coordination/index.js +26 -9
  62. package/dist/coordination/index.js.map +1 -1
  63. package/dist/ecl/git-sync.d.ts +53 -0
  64. package/dist/ecl/git-sync.d.ts.map +1 -0
  65. package/dist/ecl/git-sync.js +182 -0
  66. package/dist/ecl/git-sync.js.map +1 -0
  67. package/dist/ecl/lifecycle.d.ts +107 -0
  68. package/dist/ecl/lifecycle.d.ts.map +1 -0
  69. package/dist/ecl/lifecycle.js +264 -0
  70. package/dist/ecl/lifecycle.js.map +1 -0
  71. package/dist/ecl/persistence.d.ts +108 -0
  72. package/dist/ecl/persistence.d.ts.map +1 -0
  73. package/dist/ecl/persistence.js +362 -0
  74. package/dist/ecl/persistence.js.map +1 -0
  75. package/dist/ecl/sync.d.ts +43 -0
  76. package/dist/ecl/sync.d.ts.map +1 -0
  77. package/dist/ecl/sync.js +155 -0
  78. package/dist/ecl/sync.js.map +1 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +90 -8
  81. package/dist/index.js.map +1 -1
  82. package/dist/mcp/server.d.ts +20 -0
  83. package/dist/mcp/server.d.ts.map +1 -0
  84. package/dist/mcp/server.js +271 -0
  85. package/dist/mcp/server.js.map +1 -0
  86. package/dist/mcp/skill-template.d.ts +10 -0
  87. package/dist/mcp/skill-template.d.ts.map +1 -0
  88. package/dist/mcp/skill-template.js +75 -0
  89. package/dist/mcp/skill-template.js.map +1 -0
  90. package/dist/memory/context-injection.d.ts.map +1 -1
  91. package/dist/memory/context-injection.js +10 -8
  92. package/dist/memory/context-injection.js.map +1 -1
  93. package/dist/memory/golden-patterns.d.ts +68 -0
  94. package/dist/memory/golden-patterns.d.ts.map +1 -0
  95. package/dist/memory/golden-patterns.js +260 -0
  96. package/dist/memory/golden-patterns.js.map +1 -0
  97. package/dist/memory/policy-artifacts.d.ts.map +1 -1
  98. package/dist/memory/policy-artifacts.js +5 -1
  99. package/dist/memory/policy-artifacts.js.map +1 -1
  100. package/dist/memory/storage.d.ts +4 -1
  101. package/dist/memory/storage.d.ts.map +1 -1
  102. package/dist/memory/storage.js +22 -0
  103. package/dist/memory/storage.js.map +1 -1
  104. package/dist/merge-check/hallucination-guard.d.ts +49 -0
  105. package/dist/merge-check/hallucination-guard.d.ts.map +1 -0
  106. package/dist/merge-check/hallucination-guard.js +228 -0
  107. package/dist/merge-check/hallucination-guard.js.map +1 -0
  108. package/dist/merge-check/intent-registry.d.ts +42 -0
  109. package/dist/merge-check/intent-registry.d.ts.map +1 -0
  110. package/dist/merge-check/intent-registry.js +154 -0
  111. package/dist/merge-check/intent-registry.js.map +1 -0
  112. package/dist/merge-check/sentinel.d.ts +60 -0
  113. package/dist/merge-check/sentinel.d.ts.map +1 -0
  114. package/dist/merge-check/sentinel.js +399 -0
  115. package/dist/merge-check/sentinel.js.map +1 -0
  116. package/dist/prompt-coach/admission.d.ts +31 -0
  117. package/dist/prompt-coach/admission.d.ts.map +1 -0
  118. package/dist/prompt-coach/admission.js +103 -0
  119. package/dist/prompt-coach/admission.js.map +1 -0
  120. package/dist/prompt-coach/feedback.d.ts +49 -0
  121. package/dist/prompt-coach/feedback.d.ts.map +1 -0
  122. package/dist/prompt-coach/feedback.js +177 -0
  123. package/dist/prompt-coach/feedback.js.map +1 -0
  124. package/dist/prompt-coach/format.d.ts +56 -0
  125. package/dist/prompt-coach/format.d.ts.map +1 -0
  126. package/dist/prompt-coach/format.js +162 -0
  127. package/dist/prompt-coach/format.js.map +1 -0
  128. package/dist/prompt-coach/index.d.ts +13 -0
  129. package/dist/prompt-coach/index.d.ts.map +1 -0
  130. package/dist/prompt-coach/index.js +13 -0
  131. package/dist/prompt-coach/index.js.map +1 -0
  132. package/dist/prompt-coach/interactive.d.ts +28 -0
  133. package/dist/prompt-coach/interactive.d.ts.map +1 -0
  134. package/dist/prompt-coach/interactive.js +118 -0
  135. package/dist/prompt-coach/interactive.js.map +1 -0
  136. package/dist/prompt-coach/policy.d.ts +48 -0
  137. package/dist/prompt-coach/policy.d.ts.map +1 -0
  138. package/dist/prompt-coach/policy.js +469 -0
  139. package/dist/prompt-coach/policy.js.map +1 -0
  140. package/dist/prompt-coach/summary.d.ts +56 -0
  141. package/dist/prompt-coach/summary.d.ts.map +1 -0
  142. package/dist/prompt-coach/summary.js +304 -0
  143. package/dist/prompt-coach/summary.js.map +1 -0
  144. package/dist/protected-runtime/core.js +2 -2
  145. package/dist/protected-runtime/core.js.map +1 -1
  146. package/dist/protected-runtime/module-loader.d.ts +6 -6
  147. package/dist/protected-runtime/module-loader.d.ts.map +1 -1
  148. package/dist/protected-runtime/module-loader.js +40 -54
  149. package/dist/protected-runtime/module-loader.js.map +1 -1
  150. package/dist/protected-shell.js +24 -33
  151. package/dist/protected-shell.js.map +1 -1
  152. package/dist/templates/config.d.ts.map +1 -1
  153. package/dist/templates/config.js +14 -49
  154. package/dist/templates/config.js.map +1 -1
  155. package/dist/utils/two-loop.d.ts +36 -0
  156. package/dist/utils/two-loop.d.ts.map +1 -0
  157. package/dist/utils/two-loop.js +75 -0
  158. package/dist/utils/two-loop.js.map +1 -0
  159. package/dist/utils/upgrade-nudge.d.ts +18 -0
  160. package/dist/utils/upgrade-nudge.d.ts.map +1 -0
  161. package/dist/utils/upgrade-nudge.js +57 -0
  162. package/dist/utils/upgrade-nudge.js.map +1 -0
  163. package/package.json +18 -17
@@ -0,0 +1,107 @@
1
+ /**
2
+ * ECL Pattern Lifecycle — Scoring, Retirement, Anti-Patterns
3
+ *
4
+ * This is the module that makes repo memory learn what to trust more
5
+ * and what to trust less.
6
+ *
7
+ * Lifecycle states: emerging → validated → mixed → stale → retired
8
+ *
9
+ * Deterministic confidence formula:
10
+ * confidence = clamp(0.2 + 0.12 * successCount - 0.08 * failCount + 0.03 * min(reuseCount, 10), 0, 1)
11
+ *
12
+ * Status mapping:
13
+ * emerging — low reuse, not enough data
14
+ * validated — repeated successful reuse (confidence >= 0.6, successCount >= 3)
15
+ * mixed — reused but inconsistent outcomes
16
+ * stale — not reused for 30+ days
17
+ * retired — repeatedly harmful or explicitly retired
18
+ *
19
+ * Anti-patterns: recurring behaviors correlated with failure.
20
+ * 3+ negative occurrences → emerging
21
+ * 5+ with high failure rate → watch
22
+ * 7+ confirmed failures → confirmed
23
+ */
24
+ import type { PatternScore, PatternLifecycleStatus, PatternOutcomeLink, AntiPatternRecord } from '@codeledger/types';
25
+ import type { PromotedPattern } from './persistence.js';
26
+ /**
27
+ * Compute a SHA-256 content hash from a deterministically serialized string.
28
+ * Used for conflict-free filenames in Git-mirrored ECL directories.
29
+ */
30
+ export declare function computeContentHash(content: string): string;
31
+ /**
32
+ * Generate a CAS filename: sha256-{hash}.{ext}
33
+ */
34
+ export declare function casFilename(content: string, ext: string): string;
35
+ /**
36
+ * Deterministic confidence formula.
37
+ *
38
+ * Explainable: starts at 0.2 for newly promoted patterns,
39
+ * grows with successful reuse, shrinks modestly with failures,
40
+ * gets a small bonus for total reuse count (capped at 10).
41
+ *
42
+ * One failure doesn't destroy a strong pattern.
43
+ * Multiple successes are needed to validate.
44
+ */
45
+ export declare function computeConfidence(score: PatternScore): number;
46
+ /**
47
+ * Derive lifecycle status from score + timing.
48
+ */
49
+ export declare function deriveStatus(score: PatternScore, staleDays?: number): PatternLifecycleStatus;
50
+ /**
51
+ * Record a reuse event for a pattern.
52
+ * Appends to .codeledger/memory/reuse/{patternId}.jsonl
53
+ */
54
+ export declare function recordPatternReuse(cwd: string, patternId: string, outcome: PatternOutcomeLink): void;
55
+ /**
56
+ * Load reuse history for a pattern.
57
+ */
58
+ export declare function loadReuseHistory(cwd: string, patternId: string): PatternOutcomeLink[];
59
+ /**
60
+ * Compute a PatternScore from reuse history.
61
+ */
62
+ export declare function computeScoreFromHistory(history: PatternOutcomeLink[]): PatternScore;
63
+ /**
64
+ * Update a PromotedPattern's score from its reuse history on disk.
65
+ * Returns the updated pattern (does not write — caller decides).
66
+ */
67
+ export declare function refreshPatternScore(cwd: string, pattern: PromotedPattern): PromotedPattern & {
68
+ score?: PatternScore;
69
+ };
70
+ /**
71
+ * Check if a pattern should be retired based on its score.
72
+ *
73
+ * Retirement rules (deterministic):
74
+ * - failedReuseCount >= 5 AND failedReuseCount > successfulReuseCount → retired
75
+ * - confidenceScore < 0.1 after 5+ reuses → retired
76
+ */
77
+ export declare function shouldRetire(score: PatternScore): boolean;
78
+ /**
79
+ * Get the activation boost weight for a pattern based on its lifecycle status.
80
+ *
81
+ * validated → 1.0 (strong positive influence)
82
+ * emerging → 0.4 (soft hint)
83
+ * mixed → 0.2 (cautious)
84
+ * stale → 0.05 (minimal)
85
+ * retired → 0.0 (no positive influence)
86
+ */
87
+ export declare function activationWeight(status: PatternLifecycleStatus): number;
88
+ /**
89
+ * Write an anti-pattern record.
90
+ */
91
+ export declare function writeAntiPattern(cwd: string, record: AntiPatternRecord): string;
92
+ /**
93
+ * Load all anti-pattern records.
94
+ */
95
+ export declare function loadAntiPatterns(cwd: string): AntiPatternRecord[];
96
+ /**
97
+ * Detect anti-pattern candidates from retired patterns.
98
+ *
99
+ * Rules:
100
+ * 3+ failures → emerging anti-pattern
101
+ * 5+ failures with high failure rate → watch
102
+ * 7+ confirmed failures → confirmed
103
+ */
104
+ export declare function detectAntiPatterns(retiredPatterns: Array<PromotedPattern & {
105
+ score?: PatternScore;
106
+ }>): AntiPatternRecord[];
107
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/ecl/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhE;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAM7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,GAAE,MAAW,GAAG,sBAAsB,CAmBhG;AASD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAIN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAWrF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,YAAY,CAenF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG;IAAE,KAAK,CAAC,EAAE,YAAY,CAAA;CAAE,CAarH;AAID;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAKzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAQvE;AAQD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAQ/E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAcjE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,KAAK,CAAC,eAAe,GAAG;IAAE,KAAK,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC,GACjE,iBAAiB,EAAE,CAgCrB"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * ECL Pattern Lifecycle — Scoring, Retirement, Anti-Patterns
3
+ *
4
+ * This is the module that makes repo memory learn what to trust more
5
+ * and what to trust less.
6
+ *
7
+ * Lifecycle states: emerging → validated → mixed → stale → retired
8
+ *
9
+ * Deterministic confidence formula:
10
+ * confidence = clamp(0.2 + 0.12 * successCount - 0.08 * failCount + 0.03 * min(reuseCount, 10), 0, 1)
11
+ *
12
+ * Status mapping:
13
+ * emerging — low reuse, not enough data
14
+ * validated — repeated successful reuse (confidence >= 0.6, successCount >= 3)
15
+ * mixed — reused but inconsistent outcomes
16
+ * stale — not reused for 30+ days
17
+ * retired — repeatedly harmful or explicitly retired
18
+ *
19
+ * Anti-patterns: recurring behaviors correlated with failure.
20
+ * 3+ negative occurrences → emerging
21
+ * 5+ with high failure rate → watch
22
+ * 7+ confirmed failures → confirmed
23
+ */
24
+ import { createHash } from 'node:crypto';
25
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, appendFileSync } from 'node:fs';
26
+ import { join, dirname } from 'node:path';
27
+ // ─── Content-Addressable Storage ────────────────────────────────────────────
28
+ /**
29
+ * Compute a SHA-256 content hash from a deterministically serialized string.
30
+ * Used for conflict-free filenames in Git-mirrored ECL directories.
31
+ */
32
+ export function computeContentHash(content) {
33
+ return createHash('sha256').update(content).digest('hex').slice(0, 16);
34
+ }
35
+ /**
36
+ * Generate a CAS filename: sha256-{hash}.{ext}
37
+ */
38
+ export function casFilename(content, ext) {
39
+ return `sha256-${computeContentHash(content)}.${ext}`;
40
+ }
41
+ // ─── Confidence Scoring ─────────────────────────────────────────────────────
42
+ /**
43
+ * Deterministic confidence formula.
44
+ *
45
+ * Explainable: starts at 0.2 for newly promoted patterns,
46
+ * grows with successful reuse, shrinks modestly with failures,
47
+ * gets a small bonus for total reuse count (capped at 10).
48
+ *
49
+ * One failure doesn't destroy a strong pattern.
50
+ * Multiple successes are needed to validate.
51
+ */
52
+ export function computeConfidence(score) {
53
+ const base = 0.2;
54
+ const successBoost = 0.12 * score.successfulReuseCount;
55
+ const failurePenalty = 0.08 * score.failedReuseCount;
56
+ const reuseBonus = 0.03 * Math.min(score.reuseCount, 10);
57
+ return Math.max(0, Math.min(1, base + successBoost - failurePenalty + reuseBonus));
58
+ }
59
+ /**
60
+ * Derive lifecycle status from score + timing.
61
+ */
62
+ export function deriveStatus(score, staleDays = 30) {
63
+ // Retired takes precedence (set externally)
64
+ if (score.status === 'retired')
65
+ return 'retired';
66
+ // Stale: not reused for staleDays
67
+ if (score.lastReusedAt) {
68
+ const daysSinceReuse = (Date.now() - new Date(score.lastReusedAt).getTime()) / 86_400_000;
69
+ if (daysSinceReuse > staleDays && score.reuseCount > 0)
70
+ return 'stale';
71
+ }
72
+ // Validated: confidence >= 0.6 AND at least 3 successful reuses
73
+ const confidence = score.confidenceScore ?? computeConfidence(score);
74
+ if (confidence >= 0.6 && score.successfulReuseCount >= 3)
75
+ return 'validated';
76
+ // Mixed: has both successes and failures, or confidence is mediocre
77
+ if (score.failedReuseCount > 0 && score.successfulReuseCount > 0)
78
+ return 'mixed';
79
+ // Emerging: not enough data yet
80
+ return 'emerging';
81
+ }
82
+ // ─── Reuse Recording ────────────────────────────────────────────────────────
83
+ function ensureDir(filePath) {
84
+ const dir = dirname(filePath);
85
+ if (!existsSync(dir))
86
+ mkdirSync(dir, { recursive: true });
87
+ }
88
+ /**
89
+ * Record a reuse event for a pattern.
90
+ * Appends to .codeledger/memory/reuse/{patternId}.jsonl
91
+ */
92
+ export function recordPatternReuse(cwd, patternId, outcome) {
93
+ const filePath = join(cwd, '.codeledger', 'memory', 'reuse', `${patternId}.jsonl`);
94
+ ensureDir(filePath);
95
+ appendFileSync(filePath, JSON.stringify(outcome) + '\n');
96
+ }
97
+ /**
98
+ * Load reuse history for a pattern.
99
+ */
100
+ export function loadReuseHistory(cwd, patternId) {
101
+ const filePath = join(cwd, '.codeledger', 'memory', 'reuse', `${patternId}.jsonl`);
102
+ if (!existsSync(filePath))
103
+ return [];
104
+ try {
105
+ return readFileSync(filePath, 'utf-8')
106
+ .split('\n')
107
+ .filter((l) => l.trim())
108
+ .map((l) => JSON.parse(l));
109
+ }
110
+ catch {
111
+ return [];
112
+ }
113
+ }
114
+ /**
115
+ * Compute a PatternScore from reuse history.
116
+ */
117
+ export function computeScoreFromHistory(history) {
118
+ const score = {
119
+ reuseCount: history.length,
120
+ successfulReuseCount: history.filter((h) => h.outcome === 'success').length,
121
+ failedReuseCount: history.filter((h) => h.outcome === 'failure').length,
122
+ partialReuseCount: history.filter((h) => h.outcome === 'partial').length,
123
+ };
124
+ if (history.length > 0) {
125
+ const latest = history[history.length - 1];
126
+ score.lastReusedAt = latest.reusedAt;
127
+ score.lastOutcome = latest.outcome;
128
+ }
129
+ score.confidenceScore = computeConfidence(score);
130
+ score.status = deriveStatus(score);
131
+ return score;
132
+ }
133
+ /**
134
+ * Update a PromotedPattern's score from its reuse history on disk.
135
+ * Returns the updated pattern (does not write — caller decides).
136
+ */
137
+ export function refreshPatternScore(cwd, pattern) {
138
+ const history = loadReuseHistory(cwd, pattern.id);
139
+ if (history.length === 0) {
140
+ return { ...pattern, score: undefined };
141
+ }
142
+ const score = computeScoreFromHistory(history);
143
+ return {
144
+ ...pattern,
145
+ confidence: score.confidenceScore !== undefined && score.confidenceScore >= 0.6 ? 'high'
146
+ : score.confidenceScore !== undefined && score.confidenceScore >= 0.3 ? 'medium'
147
+ : 'low',
148
+ score,
149
+ };
150
+ }
151
+ // ─── Retirement ─────────────────────────────────────────────────────────────
152
+ /**
153
+ * Check if a pattern should be retired based on its score.
154
+ *
155
+ * Retirement rules (deterministic):
156
+ * - failedReuseCount >= 5 AND failedReuseCount > successfulReuseCount → retired
157
+ * - confidenceScore < 0.1 after 5+ reuses → retired
158
+ */
159
+ export function shouldRetire(score) {
160
+ if (score.reuseCount < 5)
161
+ return false;
162
+ if (score.failedReuseCount >= 5 && score.failedReuseCount > score.successfulReuseCount)
163
+ return true;
164
+ if ((score.confidenceScore ?? computeConfidence(score)) < 0.1 && score.reuseCount >= 5)
165
+ return true;
166
+ return false;
167
+ }
168
+ /**
169
+ * Get the activation boost weight for a pattern based on its lifecycle status.
170
+ *
171
+ * validated → 1.0 (strong positive influence)
172
+ * emerging → 0.4 (soft hint)
173
+ * mixed → 0.2 (cautious)
174
+ * stale → 0.05 (minimal)
175
+ * retired → 0.0 (no positive influence)
176
+ */
177
+ export function activationWeight(status) {
178
+ switch (status) {
179
+ case 'validated': return 1.0;
180
+ case 'emerging': return 0.4;
181
+ case 'mixed': return 0.2;
182
+ case 'stale': return 0.05;
183
+ case 'retired': return 0.0;
184
+ }
185
+ }
186
+ // ─── Anti-Pattern Detection ─────────────────────────────────────────────────
187
+ function antiPatternsDir(cwd) {
188
+ return join(cwd, '.codeledger', 'antipatterns');
189
+ }
190
+ /**
191
+ * Write an anti-pattern record.
192
+ */
193
+ export function writeAntiPattern(cwd, record) {
194
+ const dir = antiPatternsDir(cwd);
195
+ const content = JSON.stringify(record, null, 2);
196
+ const filename = casFilename(`${record.id}:${record.name}`, 'json');
197
+ const filePath = join(dir, filename);
198
+ ensureDir(filePath);
199
+ writeFileSync(filePath, content + '\n');
200
+ return filePath;
201
+ }
202
+ /**
203
+ * Load all anti-pattern records.
204
+ */
205
+ export function loadAntiPatterns(cwd) {
206
+ const dir = antiPatternsDir(cwd);
207
+ if (!existsSync(dir))
208
+ return [];
209
+ try {
210
+ return readdirSync(dir)
211
+ .filter((f) => f.endsWith('.json'))
212
+ .map((f) => {
213
+ try {
214
+ return JSON.parse(readFileSync(join(dir, f), 'utf-8'));
215
+ }
216
+ catch {
217
+ return null;
218
+ }
219
+ })
220
+ .filter((r) => r !== null);
221
+ }
222
+ catch {
223
+ return [];
224
+ }
225
+ }
226
+ /**
227
+ * Detect anti-pattern candidates from retired patterns.
228
+ *
229
+ * Rules:
230
+ * 3+ failures → emerging anti-pattern
231
+ * 5+ failures with high failure rate → watch
232
+ * 7+ confirmed failures → confirmed
233
+ */
234
+ export function detectAntiPatterns(retiredPatterns) {
235
+ const candidates = [];
236
+ for (const pattern of retiredPatterns) {
237
+ const score = pattern.score;
238
+ if (!score || score.failedReuseCount < 3)
239
+ continue;
240
+ const failRate = score.reuseCount > 0
241
+ ? score.failedReuseCount / score.reuseCount
242
+ : 0;
243
+ let status = 'emerging';
244
+ if (score.failedReuseCount >= 7 && failRate > 0.7) {
245
+ status = 'confirmed';
246
+ }
247
+ else if (score.failedReuseCount >= 5 && failRate > 0.5) {
248
+ status = 'watch';
249
+ }
250
+ candidates.push({
251
+ id: `anti-${pattern.id}`,
252
+ name: pattern.name,
253
+ description: `Retired pattern with ${score.failedReuseCount} failures: ${pattern.description}`,
254
+ occurrences: score.reuseCount,
255
+ linkedFailures: score.failedReuseCount,
256
+ lastSeenAt: score.lastReusedAt,
257
+ confidence: status === 'confirmed' ? 'high' : status === 'watch' ? 'medium' : 'low',
258
+ sourceEpisodes: pattern.sourceEpisodes,
259
+ status,
260
+ });
261
+ }
262
+ return candidates;
263
+ }
264
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/ecl/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1G,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAS1C,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,GAAW;IACtD,OAAO,UAAU,kBAAkB,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;AACxD,CAAC;AAED,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAmB;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC;IACjB,MAAM,YAAY,GAAG,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACvD,MAAM,cAAc,GAAG,IAAI,GAAG,KAAK,CAAC,gBAAgB,CAAC;IACrD,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,YAAY,GAAG,cAAc,GAAG,UAAU,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AAM,GAAgC,UAAU,CAAC;QACrD,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,IAAI,QAAQ,GAAG,GAAG,EAAE,CAAC;YAClD,MAAM,GAAG,WAAW,CAAC;QACvB,CAAC;aAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,IAAI,QAAQ,GAAG,GAAG,EAAE,CAAC;YACzD,MAAM,GAAG,OAAO,CAAC;QACnB,CAAC;QAED,UAAU,CAAC,IAAI,CAAC;YACd,EAAE,EAAE,QAAQ,OAAO,CAAC,EAAE,EAAE;YACxB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,wBAAwB,KAAK,CAAC,gBAAgB,cAAc,OAAO,CAAC,WAAW,EAAE;YAC9F,WAAW,EAAE,KAAK,CAAC,UAAU;YAC7B,cAAc,EAAE,KAAK,CAAC,gBAAgB;YACtC,UAAU,EAAE,KAAK,CAAC,YAAY;YAC9B,UAAU,EAAE,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK;YACnF,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * ECL Persistence — Make 💎 Next Real
3
+ *
4
+ * Writes the three durable ECL layers to disk:
5
+ *
6
+ * .codeledger/evidence/{session}.jsonl — append-only session evidence
7
+ * .codeledger/episodes/{session}.json — distilled episode record
8
+ * .codeledger/patterns/{id}.json — promoted patterns from harvest
9
+ *
10
+ * These files are the "owned intelligence" that developers can inspect,
11
+ * share, and that future activations can consult.
12
+ *
13
+ * All writes are local-first. Nothing leaves the machine.
14
+ */
15
+ import type { PatternCandidate, SessionValueSummary, ContextBundle } from '@codeledger/types';
16
+ export declare function evidenceDir(cwd: string): string;
17
+ export declare function episodesDir(cwd: string): string;
18
+ export declare function patternsDir(cwd: string): string;
19
+ export declare function activeDir(cwd: string): string;
20
+ export declare function promptsDir(cwd: string): string;
21
+ /**
22
+ * Migrate legacy active-bundle.md to active/ directory.
23
+ * Backward-compatible: reads from both locations, writes to new.
24
+ */
25
+ export declare function migrateActiveBundle(cwd: string): void;
26
+ /**
27
+ * Resolve the active bundle path — checks new location first, falls back to legacy.
28
+ */
29
+ export declare function resolveActiveBundlePath(cwd: string): string;
30
+ /**
31
+ * Append with fsync — ensures the append is flushed to disk.
32
+ */
33
+ export declare function appendWithFsync(filePath: string, content: string): void;
34
+ /**
35
+ * Write a SessionEvidence record to .codeledger/evidence/{session}.jsonl.
36
+ * Append-only — each session accumulates evidence across activations.
37
+ */
38
+ export declare function writeSessionEvidence(cwd: string, sessionId: string | null, summary: SessionValueSummary, _bundle: ContextBundle, promptCoached: boolean): string;
39
+ /**
40
+ * Generate an EpisodeRecord from a completed session and write to
41
+ * .codeledger/episodes/{session}.json.
42
+ *
43
+ * An episode distills a session into a reusable record: what was the task,
44
+ * what succeeded, what failed, and which files were involved.
45
+ */
46
+ export declare function writeEpisodeRecord(cwd: string, sessionId: string | null, summary: SessionValueSummary): string;
47
+ /** The shape stored in .codeledger/patterns/{id}.json */
48
+ export interface PromotedPattern {
49
+ id: string;
50
+ name: string;
51
+ description: string;
52
+ categories?: string[];
53
+ taskHints?: string[];
54
+ files?: string[];
55
+ symbols?: string[];
56
+ validationPaths?: string[];
57
+ confidence?: 'low' | 'medium' | 'high';
58
+ occurrences?: number;
59
+ sourceEpisodes?: string[];
60
+ lastUsedAt?: string;
61
+ promotedAt: string;
62
+ /** ECL v2: Live scoring metadata */
63
+ score?: import('@codeledger/types').PatternScore;
64
+ /** ECL v2: Ownership + portability boundary */
65
+ ownerScope?: import('@codeledger/types').PatternOwnerScope;
66
+ portability?: import('@codeledger/types').PatternPortability;
67
+ sourceRepoId?: string;
68
+ exportAllowed?: boolean;
69
+ }
70
+ /**
71
+ * Write a promoted pattern to .codeledger/patterns/{id}.json.
72
+ * Called from harvest when the user promotes a candidate.
73
+ */
74
+ export declare function writePromotedPattern(cwd: string, candidate: PatternCandidate, files?: string[], sourceEpisodes?: string[]): string;
75
+ /**
76
+ * Load all promoted patterns from .codeledger/patterns/.
77
+ * Gracefully skips invalid files.
78
+ */
79
+ export declare function loadPromotedPatterns(cwd: string): PromotedPattern[];
80
+ export interface PatternMatch {
81
+ pattern: PromotedPattern;
82
+ relevance: number;
83
+ matchedKeywords: string[];
84
+ matchedFiles: string[];
85
+ }
86
+ /**
87
+ * Score patterns against the incoming task.
88
+ * Deterministic, explainable, no ML.
89
+ *
90
+ * Factors:
91
+ * - Task text keyword overlap with pattern name/description/taskHints (60%)
92
+ * - File path overlap with pattern files (30%)
93
+ * - Confidence level bonus (10%)
94
+ */
95
+ export declare function scorePatternRelevance(task: string, patterns: PromotedPattern[], bundleFiles?: string[], cwd?: string): PatternMatch[];
96
+ /**
97
+ * Count total evidence records across all session files.
98
+ */
99
+ export declare function countEvidenceRecords(cwd: string): number;
100
+ /**
101
+ * Count episode records.
102
+ */
103
+ export declare function countEpisodes(cwd: string): number;
104
+ /**
105
+ * Count promoted patterns.
106
+ */
107
+ export declare function countPatterns(cwd: string): number;
108
+ //# sourceMappingURL=persistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/ecl/persistence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACd,MAAM,mBAAmB,CAAC;AAK3B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC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