@codeledger/engine 0.7.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/dist/ccs/index.d.ts +11 -0
- package/dist/ccs/index.d.ts.map +1 -0
- package/dist/ccs/index.js +10 -0
- package/dist/ccs/index.js.map +1 -0
- package/dist/ccs/score.d.ts +61 -0
- package/dist/ccs/score.d.ts.map +1 -0
- package/dist/ccs/score.js +250 -0
- package/dist/ccs/score.js.map +1 -0
- package/dist/ecl/index.d.ts +9 -0
- package/dist/ecl/index.d.ts.map +1 -0
- package/dist/ecl/index.js +9 -0
- package/dist/ecl/index.js.map +1 -0
- package/dist/ecl/ledger.d.ts +84 -0
- package/dist/ecl/ledger.d.ts.map +1 -0
- package/dist/ecl/ledger.js +235 -0
- package/dist/ecl/ledger.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/iole/expansion-ladder.d.ts +51 -0
- package/dist/iole/expansion-ladder.d.ts.map +1 -0
- package/dist/iole/expansion-ladder.js +153 -0
- package/dist/iole/expansion-ladder.js.map +1 -0
- package/dist/iole/failure-vector.d.ts +21 -0
- package/dist/iole/failure-vector.d.ts.map +1 -0
- package/dist/iole/failure-vector.js +156 -0
- package/dist/iole/failure-vector.js.map +1 -0
- package/dist/iole/index.d.ts +19 -0
- package/dist/iole/index.d.ts.map +1 -0
- package/dist/iole/index.js +17 -0
- package/dist/iole/index.js.map +1 -0
- package/dist/iole/intent-decomposition.d.ts +33 -0
- package/dist/iole/intent-decomposition.d.ts.map +1 -0
- package/dist/iole/intent-decomposition.js +252 -0
- package/dist/iole/intent-decomposition.js.map +1 -0
- package/dist/iole/intent-signature.d.ts +37 -0
- package/dist/iole/intent-signature.d.ts.map +1 -0
- package/dist/iole/intent-signature.js +112 -0
- package/dist/iole/intent-signature.js.map +1 -0
- package/dist/iole/outcome-score.d.ts +25 -0
- package/dist/iole/outcome-score.d.ts.map +1 -0
- package/dist/iole/outcome-score.js +128 -0
- package/dist/iole/outcome-score.js.map +1 -0
- package/dist/isc/index.d.ts +8 -0
- package/dist/isc/index.d.ts.map +1 -0
- package/dist/isc/index.js +8 -0
- package/dist/isc/index.js.map +1 -0
- package/dist/isc/score.d.ts +27 -0
- package/dist/isc/score.d.ts.map +1 -0
- package/dist/isc/score.js +347 -0
- package/dist/isc/score.js.map +1 -0
- package/dist/license/index.d.ts +14 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/index.js +11 -0
- package/dist/license/index.js.map +1 -0
- package/dist/license/parse.d.ts +42 -0
- package/dist/license/parse.d.ts.map +1 -0
- package/dist/license/parse.js +106 -0
- package/dist/license/parse.js.map +1 -0
- package/dist/license/publicKey.d.ts +37 -0
- package/dist/license/publicKey.d.ts.map +1 -0
- package/dist/license/publicKey.js +48 -0
- package/dist/license/publicKey.js.map +1 -0
- package/dist/license/verify.d.ts +33 -0
- package/dist/license/verify.d.ts.map +1 -0
- package/dist/license/verify.js +82 -0
- package/dist/license/verify.js.map +1 -0
- package/dist/orchestrator/index.d.ts +10 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +10 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +44 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +182 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/policy-sim/index.d.ts +8 -0
- package/dist/policy-sim/index.d.ts.map +1 -0
- package/dist/policy-sim/index.js +8 -0
- package/dist/policy-sim/index.js.map +1 -0
- package/dist/policy-sim/simulate.d.ts +18 -0
- package/dist/policy-sim/simulate.d.ts.map +1 -0
- package/dist/policy-sim/simulate.js +61 -0
- package/dist/policy-sim/simulate.js.map +1 -0
- package/dist/provenance/graph.d.ts +42 -0
- package/dist/provenance/graph.d.ts.map +1 -0
- package/dist/provenance/graph.js +139 -0
- package/dist/provenance/graph.js.map +1 -0
- package/dist/provenance/index.d.ts +8 -0
- package/dist/provenance/index.d.ts.map +1 -0
- package/dist/provenance/index.js +8 -0
- package/dist/provenance/index.js.map +1 -0
- package/dist/sce/index.d.ts +15 -0
- package/dist/sce/index.d.ts.map +1 -0
- package/dist/sce/index.js +14 -0
- package/dist/sce/index.js.map +1 -0
- package/dist/sce/slice-builder.d.ts +35 -0
- package/dist/sce/slice-builder.d.ts.map +1 -0
- package/dist/sce/slice-builder.js +198 -0
- package/dist/sce/slice-builder.js.map +1 -0
- package/dist/sce/symbol-graph.d.ts +21 -0
- package/dist/sce/symbol-graph.d.ts.map +1 -0
- package/dist/sce/symbol-graph.js +187 -0
- package/dist/sce/symbol-graph.js.map +1 -0
- package/dist/team-ledger/index.d.ts +8 -0
- package/dist/team-ledger/index.d.ts.map +1 -0
- package/dist/team-ledger/index.js +8 -0
- package/dist/team-ledger/index.js.map +1 -0
- package/dist/team-ledger/ledger.d.ts +48 -0
- package/dist/team-ledger/ledger.d.ts.map +1 -0
- package/dist/team-ledger/ledger.js +208 -0
- package/dist/team-ledger/ledger.js.map +1 -0
- package/dist/team-metrics/index.d.ts +8 -0
- package/dist/team-metrics/index.d.ts.map +1 -0
- package/dist/team-metrics/index.js +8 -0
- package/dist/team-metrics/index.js.map +1 -0
- package/dist/team-metrics/metrics.d.ts +42 -0
- package/dist/team-metrics/metrics.d.ts.map +1 -0
- package/dist/team-metrics/metrics.js +156 -0
- package/dist/team-metrics/metrics.js.map +1 -0
- package/dist/team-policy/index.d.ts +8 -0
- package/dist/team-policy/index.d.ts.map +1 -0
- package/dist/team-policy/index.js +8 -0
- package/dist/team-policy/index.js.map +1 -0
- package/dist/team-policy/policy.d.ts +35 -0
- package/dist/team-policy/policy.d.ts.map +1 -0
- package/dist/team-policy/policy.js +100 -0
- package/dist/team-policy/policy.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CCS — Context Confidence Score
|
|
3
|
+
*
|
|
4
|
+
* Pre-execution certification layer. Computes a deterministic [0,1] score
|
|
5
|
+
* from 5 factors (dependency coverage, test coverage, historical success rate,
|
|
6
|
+
* symbol completeness, expansion level efficiency) and recommends whether to
|
|
7
|
+
* proceed, expand, or block execution.
|
|
8
|
+
*/
|
|
9
|
+
export { computeCcs, CCS_HIGH_THRESHOLD, CCS_MEDIUM_THRESHOLD, CCS_DEFAULT_BLOCK_THRESHOLD, } from './score.js';
|
|
10
|
+
export type { CcsInputs } from './score.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ccs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CCS — Context Confidence Score
|
|
3
|
+
*
|
|
4
|
+
* Pre-execution certification layer. Computes a deterministic [0,1] score
|
|
5
|
+
* from 5 factors (dependency coverage, test coverage, historical success rate,
|
|
6
|
+
* symbol completeness, expansion level efficiency) and recommends whether to
|
|
7
|
+
* proceed, expand, or block execution.
|
|
8
|
+
*/
|
|
9
|
+
export { computeCcs, CCS_HIGH_THRESHOLD, CCS_MEDIUM_THRESHOLD, CCS_DEFAULT_BLOCK_THRESHOLD, } from './score.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ccs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CCS — Context Confidence Score
|
|
3
|
+
*
|
|
4
|
+
* Certifies context BEFORE execution with a deterministic [0,1] score.
|
|
5
|
+
* Computed from 5 weighted factors. No ML, no embeddings.
|
|
6
|
+
*
|
|
7
|
+
* Formula:
|
|
8
|
+
* raw = 0.30 * dependencyCoverage
|
|
9
|
+
* + 0.25 * testCoverageMapping
|
|
10
|
+
* + adjustedHistoricalWeight * historicalSuccessRate (weight scaled by sample size)
|
|
11
|
+
* + 0.15 * symbolCompleteness
|
|
12
|
+
* + 0.10 * (1 - expansionLevelNormalized)
|
|
13
|
+
* - intentConfidencePenalty (0 when confidence >= 0.4)
|
|
14
|
+
* CCS = clamp(raw, 0, 1)
|
|
15
|
+
*
|
|
16
|
+
* Maturity scaling (FIX 1 — prevents early-data instability):
|
|
17
|
+
* historySampleSize < 5 → adjustedHistoricalWeight = 0 (weight redistributed)
|
|
18
|
+
* 5 ≤ size < 20 → weight scales linearly 0 → W_HISTORICAL_SUCCESS
|
|
19
|
+
* size ≥ 20 → full W_HISTORICAL_SUCCESS (0.20) applies
|
|
20
|
+
*
|
|
21
|
+
* Thresholds (FIX 4 — explicit gating policy):
|
|
22
|
+
* >= 0.75 → PROCEED
|
|
23
|
+
* 0.60–0.75 → EXPAND
|
|
24
|
+
* < 0.60 → BLOCK
|
|
25
|
+
*
|
|
26
|
+
* Deterministic: given the same inputs, always returns the same score.
|
|
27
|
+
*/
|
|
28
|
+
import type { ContextBundle, ContextConfidenceScore } from '@codeledger/types';
|
|
29
|
+
export declare const CCS_PROCEED_THRESHOLD = 0.75;
|
|
30
|
+
export declare const CCS_EXPAND_THRESHOLD = 0.6;
|
|
31
|
+
export declare const CCS_HIGH_THRESHOLD = 0.75;
|
|
32
|
+
export declare const CCS_MEDIUM_THRESHOLD = 0.6;
|
|
33
|
+
export declare const CCS_DEFAULT_BLOCK_THRESHOLD = 0.6;
|
|
34
|
+
export interface CcsInputs {
|
|
35
|
+
bundle: ContextBundle;
|
|
36
|
+
/** Task keywords (lowercased) */
|
|
37
|
+
taskKeywords: string[];
|
|
38
|
+
/** Current expansion ladder level (1–4) */
|
|
39
|
+
expansionLevel: number;
|
|
40
|
+
/** Historical pass rate from ECL-lite for this intent (0–1). Default 0.5. */
|
|
41
|
+
historicalSuccessRate: number;
|
|
42
|
+
/**
|
|
43
|
+
* Number of ledger entries that produced historicalSuccessRate.
|
|
44
|
+
* Used for maturity scaling — small samples get reduced weight.
|
|
45
|
+
* Default 0 (empty ledger → weight 0).
|
|
46
|
+
*/
|
|
47
|
+
historySampleSize?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Extraction confidence from IntentObject [0,1].
|
|
50
|
+
* Low confidence reduces CCS slightly (max -0.05 penalty).
|
|
51
|
+
* Default 1.0 (no penalty).
|
|
52
|
+
*/
|
|
53
|
+
intentConfidence?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compute the Context Confidence Score for a bundle.
|
|
57
|
+
*
|
|
58
|
+
* All factor computations are deterministic arithmetic — no randomness.
|
|
59
|
+
*/
|
|
60
|
+
export declare function computeCcs(inputs: CcsInputs): ContextConfidenceScore;
|
|
61
|
+
//# sourceMappingURL=score.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/ccs/score.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EAGvB,MAAM,mBAAmB,CAAC;AAe3B,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,oBAAoB,MAAQ,CAAC;AAI1C,eAAO,MAAM,kBAAkB,OAAiC,CAAC;AACjE,eAAO,MAAM,oBAAoB,MAA8B,CAAC;AAChE,eAAO,MAAM,2BAA2B,MAAuB,CAAC;AAIhE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB,iCAAiC;IACjC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,sBAAsB,CA0EpE"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CCS — Context Confidence Score
|
|
3
|
+
*
|
|
4
|
+
* Certifies context BEFORE execution with a deterministic [0,1] score.
|
|
5
|
+
* Computed from 5 weighted factors. No ML, no embeddings.
|
|
6
|
+
*
|
|
7
|
+
* Formula:
|
|
8
|
+
* raw = 0.30 * dependencyCoverage
|
|
9
|
+
* + 0.25 * testCoverageMapping
|
|
10
|
+
* + adjustedHistoricalWeight * historicalSuccessRate (weight scaled by sample size)
|
|
11
|
+
* + 0.15 * symbolCompleteness
|
|
12
|
+
* + 0.10 * (1 - expansionLevelNormalized)
|
|
13
|
+
* - intentConfidencePenalty (0 when confidence >= 0.4)
|
|
14
|
+
* CCS = clamp(raw, 0, 1)
|
|
15
|
+
*
|
|
16
|
+
* Maturity scaling (FIX 1 — prevents early-data instability):
|
|
17
|
+
* historySampleSize < 5 → adjustedHistoricalWeight = 0 (weight redistributed)
|
|
18
|
+
* 5 ≤ size < 20 → weight scales linearly 0 → W_HISTORICAL_SUCCESS
|
|
19
|
+
* size ≥ 20 → full W_HISTORICAL_SUCCESS (0.20) applies
|
|
20
|
+
*
|
|
21
|
+
* Thresholds (FIX 4 — explicit gating policy):
|
|
22
|
+
* >= 0.75 → PROCEED
|
|
23
|
+
* 0.60–0.75 → EXPAND
|
|
24
|
+
* < 0.60 → BLOCK
|
|
25
|
+
*
|
|
26
|
+
* Deterministic: given the same inputs, always returns the same score.
|
|
27
|
+
*/
|
|
28
|
+
// ─── Weights ─────────────────────────────────────────────────────────────────
|
|
29
|
+
const W_DEPENDENCY_COVERAGE = 0.30;
|
|
30
|
+
const W_TEST_COVERAGE = 0.25;
|
|
31
|
+
const W_HISTORICAL_SUCCESS = 0.20; // max; scaled down by maturity
|
|
32
|
+
const W_SYMBOL_COMPLETENESS = 0.15;
|
|
33
|
+
const W_EXPANSION_EFFICIENCY = 0.10;
|
|
34
|
+
// Maturity thresholds for historical success weight scaling
|
|
35
|
+
const HISTORY_MIN_SAMPLES = 5; // below → weight = 0
|
|
36
|
+
const HISTORY_FULL_SAMPLES = 20; // at or above → full weight
|
|
37
|
+
// Thresholds (FIX 4: tightened + explicit gating)
|
|
38
|
+
export const CCS_PROCEED_THRESHOLD = 0.75; // >= PROCEED
|
|
39
|
+
export const CCS_EXPAND_THRESHOLD = 0.60; // >= EXPAND, < PROCEED
|
|
40
|
+
// < CCS_EXPAND_THRESHOLD → BLOCK
|
|
41
|
+
// Keep old names as aliases for backward compatibility
|
|
42
|
+
export const CCS_HIGH_THRESHOLD = CCS_PROCEED_THRESHOLD;
|
|
43
|
+
export const CCS_MEDIUM_THRESHOLD = CCS_EXPAND_THRESHOLD;
|
|
44
|
+
export const CCS_DEFAULT_BLOCK_THRESHOLD = CCS_EXPAND_THRESHOLD; // now same as expand floor
|
|
45
|
+
/**
|
|
46
|
+
* Compute the Context Confidence Score for a bundle.
|
|
47
|
+
*
|
|
48
|
+
* All factor computations are deterministic arithmetic — no randomness.
|
|
49
|
+
*/
|
|
50
|
+
export function computeCcs(inputs) {
|
|
51
|
+
const { bundle, taskKeywords, expansionLevel, historicalSuccessRate, historySampleSize = 0, intentConfidence = 1.0, } = inputs;
|
|
52
|
+
// Factor 1: Dependency Coverage
|
|
53
|
+
const depCoverage = computeDependencyCoverage(bundle);
|
|
54
|
+
// Factor 2: Test Coverage Mapping
|
|
55
|
+
const testCoverage = computeTestCoverage(bundle);
|
|
56
|
+
// Factor 3: Historical Success Rate — with maturity scaling
|
|
57
|
+
// When sample is small, the historical rate is unreliable. Scale its weight
|
|
58
|
+
// linearly from 0 (< 5 samples) to full (>= 20 samples).
|
|
59
|
+
const histSuccess = clamp(historicalSuccessRate, 0, 1);
|
|
60
|
+
const adjustedHistoricalWeight = computeAdjustedHistoricalWeight(historySampleSize);
|
|
61
|
+
// Redistribute unused historical weight to dep coverage (largest other factor)
|
|
62
|
+
const redistributed = W_HISTORICAL_SUCCESS - adjustedHistoricalWeight;
|
|
63
|
+
// Factor 4: Symbol Completeness
|
|
64
|
+
const symbolComp = computeSymbolCompleteness(bundle, taskKeywords);
|
|
65
|
+
// Factor 5: Expansion Level Efficiency
|
|
66
|
+
const expansionNorm = (expansionLevel - 1) / 3; // [0, 1]
|
|
67
|
+
const expansionPenalty = expansionNorm * 0.3; // max 0.30
|
|
68
|
+
// Intent confidence penalty: low confidence = ambiguous prompt = slight downgrade
|
|
69
|
+
// Max penalty: 0.05 (when intentConfidence = 0)
|
|
70
|
+
const confidencePenalty = (1 - clamp(intentConfidence, 0, 1)) * 0.05;
|
|
71
|
+
const raw = (W_DEPENDENCY_COVERAGE + redistributed) * depCoverage +
|
|
72
|
+
W_TEST_COVERAGE * testCoverage +
|
|
73
|
+
adjustedHistoricalWeight * histSuccess +
|
|
74
|
+
W_SYMBOL_COMPLETENESS * symbolComp +
|
|
75
|
+
W_EXPANSION_EFFICIENCY * (1 - expansionNorm)
|
|
76
|
+
- confidencePenalty;
|
|
77
|
+
const score = clamp(raw, 0, 1);
|
|
78
|
+
const factors = {
|
|
79
|
+
dependencyCoverage: depCoverage,
|
|
80
|
+
testCoverageMapping: testCoverage,
|
|
81
|
+
historicalSuccessRate: histSuccess,
|
|
82
|
+
symbolCompleteness: symbolComp,
|
|
83
|
+
expansionLevelPenalty: expansionPenalty,
|
|
84
|
+
historySampleSize,
|
|
85
|
+
adjustedHistoricalWeight,
|
|
86
|
+
};
|
|
87
|
+
const level = score >= CCS_PROCEED_THRESHOLD
|
|
88
|
+
? 'high'
|
|
89
|
+
: score >= CCS_EXPAND_THRESHOLD
|
|
90
|
+
? 'medium'
|
|
91
|
+
: 'low';
|
|
92
|
+
const issues = collectIssues(factors, bundle, taskKeywords, intentConfidence);
|
|
93
|
+
const { recommendation, suggestedExpansionLevel } = recommendAction(score, expansionLevel, issues);
|
|
94
|
+
return {
|
|
95
|
+
score,
|
|
96
|
+
level,
|
|
97
|
+
factors,
|
|
98
|
+
recommendation,
|
|
99
|
+
suggestedExpansionLevel,
|
|
100
|
+
issues,
|
|
101
|
+
computed_at: new Date().toISOString(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// ─── Maturity Scaling ─────────────────────────────────────────────────────────
|
|
105
|
+
/**
|
|
106
|
+
* Compute the effective historical success weight based on sample size.
|
|
107
|
+
*
|
|
108
|
+
* < HISTORY_MIN_SAMPLES (5) → 0 (too noisy to trust)
|
|
109
|
+
* HISTORY_MIN_SAMPLES..HISTORY_FULL_SAMPLES (5–19) → linear ramp 0 → W_HISTORICAL_SUCCESS
|
|
110
|
+
* >= HISTORY_FULL_SAMPLES (20) → full W_HISTORICAL_SUCCESS
|
|
111
|
+
*/
|
|
112
|
+
function computeAdjustedHistoricalWeight(sampleSize) {
|
|
113
|
+
if (sampleSize < HISTORY_MIN_SAMPLES)
|
|
114
|
+
return 0;
|
|
115
|
+
if (sampleSize >= HISTORY_FULL_SAMPLES)
|
|
116
|
+
return W_HISTORICAL_SUCCESS;
|
|
117
|
+
// Linear interpolation between min and full
|
|
118
|
+
const t = (sampleSize - HISTORY_MIN_SAMPLES) / (HISTORY_FULL_SAMPLES - HISTORY_MIN_SAMPLES);
|
|
119
|
+
return t * W_HISTORICAL_SUCCESS;
|
|
120
|
+
}
|
|
121
|
+
// ─── Factor Computations ──────────────────────────────────────────────────────
|
|
122
|
+
function computeDependencyCoverage(bundle) {
|
|
123
|
+
const relationships = bundle.file_relationships;
|
|
124
|
+
if (!relationships || relationships.length === 0) {
|
|
125
|
+
// No relationship data: assume neutral coverage
|
|
126
|
+
return 0.7;
|
|
127
|
+
}
|
|
128
|
+
const bundlePaths = new Set(bundle.files.map((f) => f.path));
|
|
129
|
+
const targets = new Set(relationships.map((r) => r.to));
|
|
130
|
+
if (targets.size === 0)
|
|
131
|
+
return 1.0;
|
|
132
|
+
let covered = 0;
|
|
133
|
+
for (const t of targets) {
|
|
134
|
+
if (bundlePaths.has(t))
|
|
135
|
+
covered++;
|
|
136
|
+
}
|
|
137
|
+
return covered / targets.size;
|
|
138
|
+
}
|
|
139
|
+
function computeTestCoverage(bundle) {
|
|
140
|
+
const sourceFiles = bundle.files.filter((f) => !f.path.match(/\.(test|spec)\.[tj]sx?$/) && !f.is_stub);
|
|
141
|
+
if (sourceFiles.length === 0)
|
|
142
|
+
return 1.0;
|
|
143
|
+
// A file is "test-covered" if: it has test_relevant reason, or there's a
|
|
144
|
+
// matching .test. file in the bundle
|
|
145
|
+
const testPaths = new Set(bundle.files
|
|
146
|
+
.filter((f) => f.path.match(/\.(test|spec)\.[tj]sx?$/))
|
|
147
|
+
.map((f) => f.path));
|
|
148
|
+
let covered = 0;
|
|
149
|
+
for (const sf of sourceFiles) {
|
|
150
|
+
const hasTestReason = sf.reasons.includes('test_relevant');
|
|
151
|
+
const hasTestInBundle = [...testPaths].some((tp) => tp.includes(sf.path.replace(/\.[tj]sx?$/, '').split('/').pop() ?? ''));
|
|
152
|
+
if (hasTestReason || hasTestInBundle)
|
|
153
|
+
covered++;
|
|
154
|
+
}
|
|
155
|
+
return covered / sourceFiles.length;
|
|
156
|
+
}
|
|
157
|
+
function computeSymbolCompleteness(bundle, keywords) {
|
|
158
|
+
if (keywords.length === 0)
|
|
159
|
+
return 1.0;
|
|
160
|
+
// Check how many keywords appear in: file paths, reason codes, or high scores
|
|
161
|
+
const bundleText = bundle.files
|
|
162
|
+
.map((f) => f.path.toLowerCase() + ' ' + f.reasons.join(' '))
|
|
163
|
+
.join(' ');
|
|
164
|
+
const matched = keywords.filter((kw) => bundleText.includes(kw.toLowerCase()));
|
|
165
|
+
return matched.length / keywords.length;
|
|
166
|
+
}
|
|
167
|
+
// ─── Issue Reporting ──────────────────────────────────────────────────────────
|
|
168
|
+
function collectIssues(factors, bundle, keywords, intentConfidence = 1.0) {
|
|
169
|
+
const issues = [];
|
|
170
|
+
if (factors.dependencyCoverage < 0.6) {
|
|
171
|
+
const missing = getMissingDeps(bundle);
|
|
172
|
+
for (const m of missing.slice(0, 3)) {
|
|
173
|
+
issues.push(`missing dependency: ${m}`);
|
|
174
|
+
}
|
|
175
|
+
if (missing.length > 3) {
|
|
176
|
+
issues.push(`… and ${missing.length - 3} more missing dependencies`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (factors.testCoverageMapping < 0.5) {
|
|
180
|
+
issues.push('test mapping incomplete — less than 50% of source files have linked tests');
|
|
181
|
+
}
|
|
182
|
+
// Historical confidence: report sample size + weight applied
|
|
183
|
+
if (factors.historySampleSize < HISTORY_MIN_SAMPLES) {
|
|
184
|
+
issues.push(`historical data insufficient (${factors.historySampleSize} entries) — success rate weight set to 0 until ${HISTORY_MIN_SAMPLES}+ entries`);
|
|
185
|
+
}
|
|
186
|
+
else if (factors.historySampleSize < HISTORY_FULL_SAMPLES) {
|
|
187
|
+
const pct = (factors.adjustedHistoricalWeight / W_HISTORICAL_SUCCESS * 100).toFixed(0);
|
|
188
|
+
issues.push(`historical data maturing (${factors.historySampleSize} entries) — success rate weight at ${pct}% of full`);
|
|
189
|
+
}
|
|
190
|
+
else if (factors.historicalSuccessRate < 0.4) {
|
|
191
|
+
issues.push(`low historical success rate (${(factors.historicalSuccessRate * 100).toFixed(0)}%) for this intent type`);
|
|
192
|
+
}
|
|
193
|
+
if (intentConfidence < 0.4) {
|
|
194
|
+
issues.push(`low intent confidence (${(intentConfidence * 100).toFixed(0)}%) — task description is ambiguous; consider adding domain or operation keywords`);
|
|
195
|
+
}
|
|
196
|
+
if (factors.symbolCompleteness < 0.5) {
|
|
197
|
+
const unmatched = keywords.filter((kw) => {
|
|
198
|
+
const bundleText = bundle.files
|
|
199
|
+
.map((f) => f.path.toLowerCase() + ' ' + f.reasons.join(' '))
|
|
200
|
+
.join(' ');
|
|
201
|
+
return !bundleText.includes(kw.toLowerCase());
|
|
202
|
+
});
|
|
203
|
+
if (unmatched.length > 0) {
|
|
204
|
+
issues.push(`task keywords not matched in bundle: ${unmatched.slice(0, 4).join(', ')}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (factors.expansionLevelPenalty > 0.15) {
|
|
208
|
+
issues.push(`context expanded to level ${Math.round(factors.expansionLevelPenalty / 0.1) + 1} — earlier iterations were insufficient`);
|
|
209
|
+
}
|
|
210
|
+
if (bundle.confidence?.level === 'low') {
|
|
211
|
+
issues.push('bundle confidence is LOW — run with --expand to increase coverage');
|
|
212
|
+
}
|
|
213
|
+
return issues;
|
|
214
|
+
}
|
|
215
|
+
function getMissingDeps(bundle) {
|
|
216
|
+
if (!bundle.file_relationships)
|
|
217
|
+
return [];
|
|
218
|
+
const bundlePaths = new Set(bundle.files.map((f) => f.path));
|
|
219
|
+
return [...new Set(bundle.file_relationships
|
|
220
|
+
.filter((r) => !bundlePaths.has(r.to))
|
|
221
|
+
.map((r) => r.to))];
|
|
222
|
+
}
|
|
223
|
+
// ─── Recommendation ───────────────────────────────────────────────────────────
|
|
224
|
+
/**
|
|
225
|
+
* Determine the gating recommendation from the CCS score.
|
|
226
|
+
*
|
|
227
|
+
* Policy (FIX 4 — explicit, unambiguous thresholds):
|
|
228
|
+
* >= 0.75 → PROCEED (context is sufficient)
|
|
229
|
+
* 0.60–0.75 → EXPAND (context needs broadening; do NOT block, suggest next level)
|
|
230
|
+
* < 0.60 → BLOCK (context is insufficient; stop unless --force)
|
|
231
|
+
*/
|
|
232
|
+
function recommendAction(score, currentLevel, _issues) {
|
|
233
|
+
if (score >= CCS_PROCEED_THRESHOLD) {
|
|
234
|
+
return { recommendation: 'proceed' };
|
|
235
|
+
}
|
|
236
|
+
if (score >= CCS_EXPAND_THRESHOLD) {
|
|
237
|
+
// Suggest expanding to the next level (max L4)
|
|
238
|
+
return {
|
|
239
|
+
recommendation: 'expand',
|
|
240
|
+
suggestedExpansionLevel: Math.min(currentLevel + 1, 4),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// Below expand threshold → block
|
|
244
|
+
return { recommendation: 'block' };
|
|
245
|
+
}
|
|
246
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
247
|
+
function clamp(v, min, max) {
|
|
248
|
+
return Math.min(max, Math.max(min, v));
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../src/ccs/score.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AASH,gFAAgF;AAEhF,MAAM,qBAAqB,GAAK,IAAI,CAAC;AACrC,MAAM,eAAe,GAAW,IAAI,CAAC;AACrC,MAAM,oBAAoB,GAAM,IAAI,CAAC,CAAC,+BAA+B;AACrE,MAAM,qBAAqB,GAAK,IAAI,CAAC;AACrC,MAAM,sBAAsB,GAAI,IAAI,CAAC;AAErC,4DAA4D;AAC5D,MAAM,mBAAmB,GAAO,CAAC,CAAC,CAAG,qBAAqB;AAC1D,MAAM,oBAAoB,GAAM,EAAE,CAAC,CAAE,4BAA4B;AAEjE,kDAAkD;AAClD,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,CAAC,aAAa;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAI,IAAI,CAAC,CAAC,uBAAuB;AAClE,iCAAiC;AAEjC,uDAAuD;AACvD,MAAM,CAAC,MAAM,kBAAkB,GAAY,qBAAqB,CAAC;AACjE,MAAM,CAAC,MAAM,oBAAoB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AAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECL-Lite — Local Context Ledger
|
|
3
|
+
*
|
|
4
|
+
* Persistent institutional memory for CodeLedger. Records execution cycles
|
|
5
|
+
* to `.codeledger/ecl-lite.jsonl` and provides success/failure indexes that
|
|
6
|
+
* feed deterministic pattern weighting back into the CCS and selector.
|
|
7
|
+
*/
|
|
8
|
+
export { eclPath, recordExecution, buildEntry, loadEntries, buildWeightIndex, historicalSuccessRate, historicalSuccessContext, buildFailureHotspots, ledgerStatus, pruneLedger, ECL_FILENAME, } from './ledger.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ecl/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,eAAe,EACf,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECL-Lite — Local Context Ledger
|
|
3
|
+
*
|
|
4
|
+
* Persistent institutional memory for CodeLedger. Records execution cycles
|
|
5
|
+
* to `.codeledger/ecl-lite.jsonl` and provides success/failure indexes that
|
|
6
|
+
* feed deterministic pattern weighting back into the CCS and selector.
|
|
7
|
+
*/
|
|
8
|
+
export { eclPath, recordExecution, buildEntry, loadEntries, buildWeightIndex, historicalSuccessRate, historicalSuccessContext, buildFailureHotspots, ledgerStatus, pruneLedger, ECL_FILENAME, } from './ledger.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ecl/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,eAAe,EACf,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECL-Lite — Local Context Ledger
|
|
3
|
+
*
|
|
4
|
+
* Provides persistent institutional memory for CodeLedger. Records every
|
|
5
|
+
* execution cycle to `.codeledger/ecl-lite.jsonl` (JSON Lines, append-only).
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Append execution outcomes (success/failure + context used)
|
|
9
|
+
* - Build and query success/failure indexes
|
|
10
|
+
* - Expose ledger status, inspection, and pruning
|
|
11
|
+
*
|
|
12
|
+
* Format: JSON Lines — one EclLiteEntry per line. Human-readable, no SQLite
|
|
13
|
+
* dependency. Safe for concurrent reads; single-writer append model.
|
|
14
|
+
*
|
|
15
|
+
* Deterministic: integer weights only, no floats in the index.
|
|
16
|
+
*/
|
|
17
|
+
import type { EclLiteEntry, EclWeightEntry, FailureHotspot, EclLiteStatus } from '@codeledger/types';
|
|
18
|
+
export declare const ECL_FILENAME = "ecl-lite.jsonl";
|
|
19
|
+
/** Derive the ECL-lite path for a given repo root */
|
|
20
|
+
export declare function eclPath(repoRoot: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Append a new execution cycle entry to the ledger.
|
|
23
|
+
* Creates the file (and `.codeledger/` dir) if they don't exist.
|
|
24
|
+
*/
|
|
25
|
+
export declare function recordExecution(repoRoot: string, entry: EclLiteEntry): void;
|
|
26
|
+
/**
|
|
27
|
+
* Build an EclLiteEntry from the inputs of a completed execution cycle.
|
|
28
|
+
* Computes the contextHash deterministically from the sorted file list.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildEntry(intentSignature: string, files: string[], symbols: string[], expansionLevel: number, outcome: 'success' | 'failure', confidenceScore: number, failureVector?: {
|
|
31
|
+
kind: string;
|
|
32
|
+
implicated_files: string[];
|
|
33
|
+
}, intentCategory?: string): EclLiteEntry;
|
|
34
|
+
/**
|
|
35
|
+
* Load all entries from the ledger.
|
|
36
|
+
* Returns empty array if ledger does not exist or is malformed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadEntries(repoRoot: string): EclLiteEntry[];
|
|
39
|
+
/**
|
|
40
|
+
* Build the success/failure weight index from ledger entries.
|
|
41
|
+
*
|
|
42
|
+
* Uses integer arithmetic only — deterministic, no floats.
|
|
43
|
+
* successWeight++ on each success, failureWeight++ on each failure.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildWeightIndex(entries: EclLiteEntry[]): Map<string, EclWeightEntry>;
|
|
46
|
+
/**
|
|
47
|
+
* Compute the historical success rate for an intent signature.
|
|
48
|
+
* Returns 0.5 (neutral) if no history exists.
|
|
49
|
+
*/
|
|
50
|
+
export declare function historicalSuccessRate(entries: EclLiteEntry[], intentSignature: string): number;
|
|
51
|
+
/**
|
|
52
|
+
* Returns both the historical success rate AND the sample size used.
|
|
53
|
+
*
|
|
54
|
+
* Falls back to category-level aggregation when the specific intent signature
|
|
55
|
+
* has < 5 entries — avoids early-data noise from single-entry signatures.
|
|
56
|
+
*
|
|
57
|
+
* Priority:
|
|
58
|
+
* 1. Exact intentSignature match (>= 5 entries) → specific rate
|
|
59
|
+
* 2. intentCategory match (< 5 exact OR no exact) → category rate
|
|
60
|
+
* 3. No data → 0.5 neutral prior
|
|
61
|
+
*/
|
|
62
|
+
export declare function historicalSuccessContext(entries: EclLiteEntry[], intentSignature: string, intentCategory?: string): {
|
|
63
|
+
rate: number;
|
|
64
|
+
sampleSize: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Build the failure hotspot index — files frequently implicated in failures.
|
|
68
|
+
* Returns hotspots sorted by implicationRate descending.
|
|
69
|
+
*
|
|
70
|
+
* v2.1.1: tracks lastFailureTimestamp per file for recency decay in slice-builder.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildFailureHotspots(entries: EclLiteEntry[]): FailureHotspot[];
|
|
73
|
+
/**
|
|
74
|
+
* Compute overall ledger status summary.
|
|
75
|
+
*/
|
|
76
|
+
export declare function ledgerStatus(repoRoot: string): EclLiteStatus;
|
|
77
|
+
/**
|
|
78
|
+
* Prune old entries to keep the ledger bounded.
|
|
79
|
+
* Keeps the most recent `maxEntries` entries (default 2000).
|
|
80
|
+
* Rewrites the entire file atomically (temp-write then rename not available
|
|
81
|
+
* in pure Node fs sync, so writes to path directly).
|
|
82
|
+
*/
|
|
83
|
+
export declare function pruneLedger(repoRoot: string, maxEntries?: number): number;
|
|
84
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/ecl/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAI3B,eAAO,MAAM,YAAY,mBAAmB,CAAC;AAK7C,qDAAqD;AACrD,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAI3E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,eAAe,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;I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