@jamesaphoenix/tx-core 0.4.3 → 0.4.5
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/db.d.ts.map +1 -1
- package/dist/db.js +8 -2
- package/dist/db.js.map +1 -1
- package/dist/layer.d.ts +3 -3
- package/dist/services/auto-sync-service.d.ts +1 -1
- package/dist/services/cycle-scan-service.d.ts.map +1 -1
- package/dist/services/cycle-scan-service.js +6 -2
- package/dist/services/cycle-scan-service.js.map +1 -1
- package/dist/services/learning-service.d.ts +1 -1
- package/dist/services/orchestrator-service.d.ts +1 -1
- package/dist/services/orchestrator-service.d.ts.map +1 -1
- package/dist/services/orchestrator-service.js +14 -13
- package/dist/services/orchestrator-service.js.map +1 -1
- package/dist/services/retriever-service.d.ts +2 -2
- package/dist/services/sync-service.d.ts.map +1 -1
- package/dist/services/sync-service.js +9 -8
- package/dist/services/sync-service.js.map +1 -1
- package/dist/services/task-service.d.ts.map +1 -1
- package/dist/services/task-service.js +3 -2
- package/dist/services/task-service.js.map +1 -1
- package/dist/services/worker-process.d.ts +1 -1
- package/dist/services/worker-process.d.ts.map +1 -1
- package/dist/services/worker-process.js +9 -2
- package/dist/services/worker-process.js.map +1 -1
- package/dist/worker/run-worker.d.ts +1 -1
- package/package.json +1 -1
- package/dist/mappers/anchor.d.ts +0 -28
- package/dist/mappers/anchor.d.ts.map +0 -1
- package/dist/mappers/anchor.js +0 -105
- package/dist/mappers/anchor.js.map +0 -1
- package/dist/mappers/candidate.d.ts +0 -25
- package/dist/mappers/candidate.d.ts.map +0 -1
- package/dist/mappers/candidate.js +0 -83
- package/dist/mappers/candidate.js.map +0 -1
- package/dist/mappers/edge.d.ts +0 -19
- package/dist/mappers/edge.d.ts.map +0 -1
- package/dist/mappers/edge.js +0 -81
- package/dist/mappers/edge.js.map +0 -1
- package/dist/repo/anchor-repo.d.ts +0 -52
- package/dist/repo/anchor-repo.d.ts.map +0 -1
- package/dist/repo/anchor-repo.js +0 -245
- package/dist/repo/anchor-repo.js.map +0 -1
- package/dist/repo/candidate-repo.d.ts +0 -16
- package/dist/repo/candidate-repo.d.ts.map +0 -1
- package/dist/repo/candidate-repo.js +0 -164
- package/dist/repo/candidate-repo.js.map +0 -1
- package/dist/repo/compaction-repo.d.ts +0 -41
- package/dist/repo/compaction-repo.d.ts.map +0 -1
- package/dist/repo/compaction-repo.js +0 -84
- package/dist/repo/compaction-repo.js.map +0 -1
- package/dist/repo/edge-repo.d.ts +0 -26
- package/dist/repo/edge-repo.d.ts.map +0 -1
- package/dist/repo/edge-repo.js +0 -258
- package/dist/repo/edge-repo.js.map +0 -1
- package/dist/services/anchor-service.d.ts +0 -147
- package/dist/services/anchor-service.d.ts.map +0 -1
- package/dist/services/anchor-service.js +0 -540
- package/dist/services/anchor-service.js.map +0 -1
- package/dist/services/anchor-verification.d.ts +0 -102
- package/dist/services/anchor-verification.d.ts.map +0 -1
- package/dist/services/anchor-verification.js +0 -817
- package/dist/services/anchor-verification.js.map +0 -1
- package/dist/services/ast-grep-service.d.ts +0 -58
- package/dist/services/ast-grep-service.d.ts.map +0 -1
- package/dist/services/ast-grep-service.js +0 -427
- package/dist/services/ast-grep-service.js.map +0 -1
- package/dist/services/candidate-extractor-service.d.ts +0 -56
- package/dist/services/candidate-extractor-service.d.ts.map +0 -1
- package/dist/services/candidate-extractor-service.js +0 -365
- package/dist/services/candidate-extractor-service.js.map +0 -1
- package/dist/services/compaction-service.d.ts +0 -105
- package/dist/services/compaction-service.d.ts.map +0 -1
- package/dist/services/compaction-service.js +0 -369
- package/dist/services/compaction-service.js.map +0 -1
- package/dist/services/edge-service.d.ts +0 -78
- package/dist/services/edge-service.d.ts.map +0 -1
- package/dist/services/edge-service.js +0 -158
- package/dist/services/edge-service.js.map +0 -1
- package/dist/services/feedback-tracker.d.ts +0 -64
- package/dist/services/feedback-tracker.d.ts.map +0 -1
- package/dist/services/feedback-tracker.js +0 -110
- package/dist/services/feedback-tracker.js.map +0 -1
- package/dist/services/graph-expansion.d.ts +0 -158
- package/dist/services/graph-expansion.d.ts.map +0 -1
- package/dist/services/graph-expansion.js +0 -487
- package/dist/services/graph-expansion.js.map +0 -1
- package/dist/services/promotion-service.d.ts +0 -67
- package/dist/services/promotion-service.d.ts.map +0 -1
- package/dist/services/promotion-service.js +0 -151
- package/dist/services/promotion-service.js.map +0 -1
- package/dist/services/swarm-verification.d.ts +0 -104
- package/dist/services/swarm-verification.d.ts.map +0 -1
- package/dist/services/swarm-verification.js +0 -406
- package/dist/services/swarm-verification.js.map +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { DatabaseError } from "../errors.js";
|
|
3
|
-
import { EdgeService } from "./edge-service.js";
|
|
4
|
-
/**
|
|
5
|
-
* Input for recording which learnings were used in a run.
|
|
6
|
-
*/
|
|
7
|
-
export interface LearningUsageFeedback {
|
|
8
|
-
readonly id: number;
|
|
9
|
-
readonly helpful: boolean;
|
|
10
|
-
}
|
|
11
|
-
declare const FeedbackTrackerService_base: Context.TagClass<FeedbackTrackerService, "FeedbackTrackerService", {
|
|
12
|
-
/**
|
|
13
|
-
* Record which learnings were shown to an agent and whether they were helpful.
|
|
14
|
-
* Creates USED_IN_RUN edges in the graph for each learning.
|
|
15
|
-
*
|
|
16
|
-
* @param runId - Unique identifier for the agent run
|
|
17
|
-
* @param learnings - Array of learnings with their helpfulness feedback
|
|
18
|
-
*/
|
|
19
|
-
readonly recordUsage: (runId: string, learnings: readonly LearningUsageFeedback[]) => Effect.Effect<void, DatabaseError>;
|
|
20
|
-
/**
|
|
21
|
-
* Get the feedback score for a learning based on historical usage.
|
|
22
|
-
* Uses Bayesian averaging: (successes + prior) / (total + 2*prior)
|
|
23
|
-
*
|
|
24
|
-
* @param learningId - The learning ID to get feedback score for
|
|
25
|
-
* @returns Score between 0 and 1, with 0.5 being neutral (no feedback)
|
|
26
|
-
*/
|
|
27
|
-
readonly getFeedbackScore: (learningId: number) => Effect.Effect<number, DatabaseError>;
|
|
28
|
-
/**
|
|
29
|
-
* Get feedback scores for multiple learnings in a single batch query.
|
|
30
|
-
* Uses EdgeService.findFromMultipleSources() to avoid N+1 queries.
|
|
31
|
-
*
|
|
32
|
-
* @param learningIds - Array of learning IDs to get feedback scores for
|
|
33
|
-
* @returns Map from learningId to score (0-1, 0.5 is neutral)
|
|
34
|
-
*/
|
|
35
|
-
readonly getFeedbackScores: (learningIds: readonly number[]) => Effect.Effect<ReadonlyMap<number, number>, DatabaseError>;
|
|
36
|
-
}>;
|
|
37
|
-
/**
|
|
38
|
-
* FeedbackTrackerService tracks which learnings were helpful in agent runs
|
|
39
|
-
* via USED_IN_RUN edges. Uses Bayesian scoring to weight future retrievals.
|
|
40
|
-
*
|
|
41
|
-
* Design: DD-016 specifies feedback tracking as part of the graph-expanded
|
|
42
|
-
* retrieval pipeline. Learnings that are marked helpful receive score boosts.
|
|
43
|
-
*/
|
|
44
|
-
export declare class FeedbackTrackerService extends FeedbackTrackerService_base {
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Noop implementation - returns neutral scores and does nothing on record.
|
|
48
|
-
* Used when feedback tracking is disabled or for testing.
|
|
49
|
-
*/
|
|
50
|
-
export declare const FeedbackTrackerServiceNoop: Layer.Layer<FeedbackTrackerService, never, never>;
|
|
51
|
-
/**
|
|
52
|
-
* Live implementation that stores feedback as USED_IN_RUN edges.
|
|
53
|
-
*
|
|
54
|
-
* recordUsage: Creates USED_IN_RUN edges from learning to run.
|
|
55
|
-
* - Weight: 1.0 if helpful, 0.0 if not helpful
|
|
56
|
-
* - Metadata: { position, recordedAt }
|
|
57
|
-
*
|
|
58
|
-
* getFeedbackScore: Calculates Bayesian average from historical edges.
|
|
59
|
-
* - Formula: (helpfulCount + prior * priorWeight) / (totalCount + priorWeight)
|
|
60
|
-
* - Returns 0.5 (neutral) for learnings with no feedback.
|
|
61
|
-
*/
|
|
62
|
-
export declare const FeedbackTrackerServiceLive: Layer.Layer<FeedbackTrackerService, never, EdgeService>;
|
|
63
|
-
export {};
|
|
64
|
-
//# sourceMappingURL=feedback-tracker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feedback-tracker.d.ts","sourceRoot":"","sources":["../../src/services/feedback-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;;IAYG;;;;;;OAMG;0BACmB,CACpB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,qBAAqB,EAAE,KACxC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC;IAEvC;;;;;;OAMG;+BACwB,CACzB,UAAU,EAAE,MAAM,KACf,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAEzC;;;;;;OAMG;gCACyB,CAC1B,WAAW,EAAE,SAAS,MAAM,EAAE,KAC3B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,CAAC;;AA1ClE;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,2BAqCzC;CAAG;AAUN;;;GAGG;AACH,eAAO,MAAM,0BAA0B,mDAUtC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,yDA0FtC,CAAA"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { DatabaseError } from "../errors.js";
|
|
3
|
-
import { EdgeService } from "./edge-service.js";
|
|
4
|
-
/**
|
|
5
|
-
* FeedbackTrackerService tracks which learnings were helpful in agent runs
|
|
6
|
-
* via USED_IN_RUN edges. Uses Bayesian scoring to weight future retrievals.
|
|
7
|
-
*
|
|
8
|
-
* Design: DD-016 specifies feedback tracking as part of the graph-expanded
|
|
9
|
-
* retrieval pipeline. Learnings that are marked helpful receive score boosts.
|
|
10
|
-
*/
|
|
11
|
-
export class FeedbackTrackerService extends Context.Tag("FeedbackTrackerService")() {
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Bayesian scoring constants.
|
|
15
|
-
* Prior of 0.5 means neutral (neither helpful nor unhelpful).
|
|
16
|
-
* Prior weight of 2 provides moderate regularization toward the prior.
|
|
17
|
-
*/
|
|
18
|
-
const BAYESIAN_PRIOR = 0.5;
|
|
19
|
-
const BAYESIAN_PRIOR_WEIGHT = 2;
|
|
20
|
-
/**
|
|
21
|
-
* Noop implementation - returns neutral scores and does nothing on record.
|
|
22
|
-
* Used when feedback tracking is disabled or for testing.
|
|
23
|
-
*/
|
|
24
|
-
export const FeedbackTrackerServiceNoop = Layer.succeed(FeedbackTrackerService, {
|
|
25
|
-
recordUsage: (_runId, _learnings) => Effect.void,
|
|
26
|
-
getFeedbackScore: (_learningId) => Effect.succeed(0.5),
|
|
27
|
-
getFeedbackScores: (learningIds) => Effect.succeed(new Map(learningIds.map((id) => [id, 0.5])))
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Live implementation that stores feedback as USED_IN_RUN edges.
|
|
31
|
-
*
|
|
32
|
-
* recordUsage: Creates USED_IN_RUN edges from learning to run.
|
|
33
|
-
* - Weight: 1.0 if helpful, 0.0 if not helpful
|
|
34
|
-
* - Metadata: { position, recordedAt }
|
|
35
|
-
*
|
|
36
|
-
* getFeedbackScore: Calculates Bayesian average from historical edges.
|
|
37
|
-
* - Formula: (helpfulCount + prior * priorWeight) / (totalCount + priorWeight)
|
|
38
|
-
* - Returns 0.5 (neutral) for learnings with no feedback.
|
|
39
|
-
*/
|
|
40
|
-
export const FeedbackTrackerServiceLive = Layer.effect(FeedbackTrackerService, Effect.gen(function* () {
|
|
41
|
-
const edgeService = yield* EdgeService;
|
|
42
|
-
return {
|
|
43
|
-
recordUsage: (runId, learnings) => Effect.gen(function* () {
|
|
44
|
-
const recordedAt = new Date().toISOString();
|
|
45
|
-
for (let i = 0; i < learnings.length; i++) {
|
|
46
|
-
const learning = learnings[i];
|
|
47
|
-
yield* edgeService.createEdge({
|
|
48
|
-
edgeType: "USED_IN_RUN",
|
|
49
|
-
sourceType: "learning",
|
|
50
|
-
sourceId: learning.id.toString(),
|
|
51
|
-
targetType: "run",
|
|
52
|
-
targetId: runId,
|
|
53
|
-
weight: learning.helpful ? 1.0 : 0.0,
|
|
54
|
-
metadata: {
|
|
55
|
-
position: i,
|
|
56
|
-
recordedAt
|
|
57
|
-
}
|
|
58
|
-
}).pipe(
|
|
59
|
-
// Map ValidationError to DatabaseError - validation errors here would be internal issues
|
|
60
|
-
Effect.mapError(e => e._tag === "ValidationError"
|
|
61
|
-
? new DatabaseError({ cause: e.reason })
|
|
62
|
-
: e));
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
65
|
-
getFeedbackScore: (learningId) => Effect.gen(function* () {
|
|
66
|
-
// Find all USED_IN_RUN edges from this learning
|
|
67
|
-
const edges = yield* edgeService.findFromSource("learning", learningId.toString());
|
|
68
|
-
const usedInRunEdges = edges.filter(e => e.edgeType === "USED_IN_RUN");
|
|
69
|
-
// No feedback = neutral score
|
|
70
|
-
if (usedInRunEdges.length === 0) {
|
|
71
|
-
return BAYESIAN_PRIOR;
|
|
72
|
-
}
|
|
73
|
-
// Count helpful (weight > 0) edges
|
|
74
|
-
const totalCount = usedInRunEdges.length;
|
|
75
|
-
const helpfulCount = usedInRunEdges.filter(e => e.weight > 0).length;
|
|
76
|
-
// Bayesian average: (successes + prior * priorWeight) / (total + priorWeight)
|
|
77
|
-
// = (helpfulCount + 0.5 * 2) / (totalCount + 2)
|
|
78
|
-
// = (helpfulCount + 1) / (totalCount + 2)
|
|
79
|
-
return (helpfulCount + BAYESIAN_PRIOR * BAYESIAN_PRIOR_WEIGHT) / (totalCount + BAYESIAN_PRIOR_WEIGHT);
|
|
80
|
-
}),
|
|
81
|
-
getFeedbackScores: (learningIds) => Effect.gen(function* () {
|
|
82
|
-
// Handle empty input
|
|
83
|
-
if (learningIds.length === 0) {
|
|
84
|
-
return new Map();
|
|
85
|
-
}
|
|
86
|
-
// Batch fetch all edges from all learnings
|
|
87
|
-
const sourceIds = learningIds.map(id => id.toString());
|
|
88
|
-
const edgesBySource = yield* edgeService.findFromMultipleSources("learning", sourceIds);
|
|
89
|
-
// Compute Bayesian score for each learning
|
|
90
|
-
const result = new Map();
|
|
91
|
-
for (const learningId of learningIds) {
|
|
92
|
-
const edges = edgesBySource.get(learningId.toString()) ?? [];
|
|
93
|
-
const usedInRunEdges = edges.filter(e => e.edgeType === "USED_IN_RUN");
|
|
94
|
-
// No feedback = neutral score
|
|
95
|
-
if (usedInRunEdges.length === 0) {
|
|
96
|
-
result.set(learningId, BAYESIAN_PRIOR);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
// Count helpful (weight > 0) edges
|
|
100
|
-
const totalCount = usedInRunEdges.length;
|
|
101
|
-
const helpfulCount = usedInRunEdges.filter(e => e.weight > 0).length;
|
|
102
|
-
// Bayesian average
|
|
103
|
-
const score = (helpfulCount + BAYESIAN_PRIOR * BAYESIAN_PRIOR_WEIGHT) / (totalCount + BAYESIAN_PRIOR_WEIGHT);
|
|
104
|
-
result.set(learningId, score);
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
})
|
|
108
|
-
};
|
|
109
|
-
}));
|
|
110
|
-
//# sourceMappingURL=feedback-tracker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feedback-tracker.js","sourceRoot":"","sources":["../../src/services/feedback-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,O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AAQ;gBACV,CAAC;gBAED,mCAAmC;gBACnC,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAA;gBACxC,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;gBAEpE,mBAAmB;gBACnB,MAAM,KAAK,GAAG,CAAC,YAAY,GAAG,cAAc,GAAG,qBAAqB,CAAC,GAAG,CAAC,UAAU,GAAG,qBAAqB,CAAC,CAAA;gBAC5G,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;YAC/B,CAAC;YAED,OAAO,MAAqC,CAAA;QAC9C,CAAC,CAAC;KACL,CAAA;AACH,CAAC,CAAC,CACH,CAAA"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { EdgeService } from "./edge-service.js";
|
|
3
|
-
import { LearningRepository } from "../repo/learning-repo.js";
|
|
4
|
-
import { AnchorRepository } from "../repo/anchor-repo.js";
|
|
5
|
-
import { DatabaseError, ValidationError } from "../errors.js";
|
|
6
|
-
import type { Learning, EdgeType, LearningId } from "@jamesaphoenix/tx-types";
|
|
7
|
-
/**
|
|
8
|
-
* Seed learning with an initial score for graph expansion.
|
|
9
|
-
* Typically the RRF score from hybrid search.
|
|
10
|
-
*/
|
|
11
|
-
export interface SeedLearning {
|
|
12
|
-
readonly learning: Learning;
|
|
13
|
-
readonly score: number;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Expanded learning with graph traversal metadata.
|
|
17
|
-
*/
|
|
18
|
-
export interface ExpandedLearning {
|
|
19
|
-
readonly learning: Learning;
|
|
20
|
-
/** Number of hops from the nearest seed (0 = direct seed) */
|
|
21
|
-
readonly hops: number;
|
|
22
|
-
/** Score after applying weight decay per hop */
|
|
23
|
-
readonly decayedScore: number;
|
|
24
|
-
/** Path of learning IDs from seed to this learning */
|
|
25
|
-
readonly path: readonly LearningId[];
|
|
26
|
-
/** Edge type that connected this learning (null for seeds) */
|
|
27
|
-
readonly sourceEdge: EdgeType | null;
|
|
28
|
-
/** The edge weight that led to this learning (null for seeds) */
|
|
29
|
-
readonly edgeWeight: number | null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Filter configuration for edge types during graph traversal.
|
|
33
|
-
* Supports include/exclude lists and per-hop overrides.
|
|
34
|
-
*/
|
|
35
|
-
export interface EdgeTypeFilter {
|
|
36
|
-
/** Only traverse these edge types (mutually exclusive with exclude for same types) */
|
|
37
|
-
readonly include?: readonly EdgeType[];
|
|
38
|
-
/** Traverse all edge types except these (mutually exclusive with include for same types) */
|
|
39
|
-
readonly exclude?: readonly EdgeType[];
|
|
40
|
-
/** Depth-specific filter overrides (1-indexed, matching hop number) */
|
|
41
|
-
readonly perHop?: Readonly<Record<number, EdgeTypeFilter>>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Options for graph expansion algorithm.
|
|
45
|
-
*/
|
|
46
|
-
export interface GraphExpansionOptions {
|
|
47
|
-
/** Maximum traversal depth (default: 2) */
|
|
48
|
-
readonly depth?: number;
|
|
49
|
-
/** Score decay factor per hop (default: 0.7) */
|
|
50
|
-
readonly decayFactor?: number;
|
|
51
|
-
/** Maximum nodes to return (default: 100) */
|
|
52
|
-
readonly maxNodes?: number;
|
|
53
|
-
/** Filter by specific edge types (default: all types).
|
|
54
|
-
* Accepts either a simple array for backwards compatibility or EdgeTypeFilter for advanced filtering. */
|
|
55
|
-
readonly edgeTypes?: EdgeTypeFilter | readonly EdgeType[];
|
|
56
|
-
/** Direction of edge traversal (default: "both") */
|
|
57
|
-
readonly direction?: "outbound" | "inbound" | "both";
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Result of graph expansion operation.
|
|
61
|
-
*/
|
|
62
|
-
export interface GraphExpansionResult {
|
|
63
|
-
/** Seeds that were provided as input */
|
|
64
|
-
readonly seeds: readonly ExpandedLearning[];
|
|
65
|
-
/** Learnings discovered through graph expansion (excludes seeds) */
|
|
66
|
-
readonly expanded: readonly ExpandedLearning[];
|
|
67
|
-
/** Total learnings (seeds + expanded) */
|
|
68
|
-
readonly all: readonly ExpandedLearning[];
|
|
69
|
-
/** Statistics about the expansion */
|
|
70
|
-
readonly stats: {
|
|
71
|
-
readonly seedCount: number;
|
|
72
|
-
readonly expandedCount: number;
|
|
73
|
-
readonly maxDepthReached: number;
|
|
74
|
-
readonly nodesVisited: number;
|
|
75
|
-
readonly maxNodesReached: boolean;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Options for file-based graph expansion.
|
|
80
|
-
* Expands from files via IMPORTS and CO_CHANGES_WITH edges to find related learnings.
|
|
81
|
-
* See PRD-016 for specification.
|
|
82
|
-
*/
|
|
83
|
-
export interface FileExpansionOptions {
|
|
84
|
-
/** Maximum traversal depth for file relationships (default: 2) */
|
|
85
|
-
readonly depth?: number;
|
|
86
|
-
/** Score decay factor per hop (default: 0.7) */
|
|
87
|
-
readonly decayFactor?: number;
|
|
88
|
-
/** Maximum learnings to return (default: 100) */
|
|
89
|
-
readonly maxNodes?: number;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* A learning discovered through file-based graph expansion.
|
|
93
|
-
* Contains metadata about how the learning was found via file relationships.
|
|
94
|
-
*/
|
|
95
|
-
export interface FileExpandedLearning {
|
|
96
|
-
readonly learning: Learning;
|
|
97
|
-
/** The source file path that led to this learning */
|
|
98
|
-
readonly sourceFile: string;
|
|
99
|
-
/** Number of hops from the source file (0 = directly anchored to input file) */
|
|
100
|
-
readonly hops: number;
|
|
101
|
-
/** Score after applying weight decay per hop */
|
|
102
|
-
readonly decayedScore: number;
|
|
103
|
-
/** Edge type that connected this learning (ANCHORED_TO for direct, IMPORTS or CO_CHANGES_WITH for expanded) */
|
|
104
|
-
readonly sourceEdge: EdgeType;
|
|
105
|
-
/** Edge weight (null for directly anchored learnings, weight value for IMPORTS/CO_CHANGES_WITH) */
|
|
106
|
-
readonly edgeWeight: number | null;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Result of file-based graph expansion operation.
|
|
110
|
-
*/
|
|
111
|
-
export interface FileExpansionResult {
|
|
112
|
-
/** Learnings directly anchored to the input files (hop 0) */
|
|
113
|
-
readonly anchored: readonly FileExpandedLearning[];
|
|
114
|
-
/** Learnings discovered through file expansion (hops > 0 via IMPORTS/CO_CHANGES_WITH) */
|
|
115
|
-
readonly expanded: readonly FileExpandedLearning[];
|
|
116
|
-
/** All learnings (anchored + expanded), sorted by decayedScore */
|
|
117
|
-
readonly all: readonly FileExpandedLearning[];
|
|
118
|
-
/** Statistics about the expansion */
|
|
119
|
-
readonly stats: {
|
|
120
|
-
readonly inputFileCount: number;
|
|
121
|
-
readonly anchoredCount: number;
|
|
122
|
-
readonly expandedCount: number;
|
|
123
|
-
readonly maxDepthReached: number;
|
|
124
|
-
readonly filesVisited: number;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
declare const GraphExpansionService_base: Context.TagClass<GraphExpansionService, "GraphExpansionService", {
|
|
128
|
-
/**
|
|
129
|
-
* Expand from seed learnings through the knowledge graph.
|
|
130
|
-
* Uses BFS traversal with weight decay per hop.
|
|
131
|
-
* Bidirectional traversal (both incoming and outgoing edges).
|
|
132
|
-
*
|
|
133
|
-
* @param seeds - Learnings to start expansion from, with initial scores
|
|
134
|
-
* @param options - Expansion configuration (depth, decay, limits)
|
|
135
|
-
* @returns Seeds and expanded learnings with traversal metadata
|
|
136
|
-
*/
|
|
137
|
-
readonly expand: (seeds: readonly SeedLearning[], options?: GraphExpansionOptions) => Effect.Effect<GraphExpansionResult, ValidationError | DatabaseError>;
|
|
138
|
-
/**
|
|
139
|
-
* Expand from file paths to find related learnings.
|
|
140
|
-
* First finds learnings ANCHORED_TO the input files, then expands via
|
|
141
|
-
* IMPORTS and CO_CHANGES_WITH edges to find learnings anchored to related files.
|
|
142
|
-
*
|
|
143
|
-
* @param files - File paths to expand from (e.g., ["src/auth.ts", "src/jwt.ts"])
|
|
144
|
-
* @param options - Expansion configuration (depth, decay, limits)
|
|
145
|
-
* @returns Anchored and expanded learnings with file relationship metadata
|
|
146
|
-
*/
|
|
147
|
-
readonly expandFromFiles: (files: readonly string[], options?: FileExpansionOptions) => Effect.Effect<FileExpansionResult, ValidationError | DatabaseError>;
|
|
148
|
-
}>;
|
|
149
|
-
export declare class GraphExpansionService extends GraphExpansionService_base {
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Noop implementation that returns seeds without expansion.
|
|
153
|
-
* Used when graph expansion is disabled or for testing.
|
|
154
|
-
*/
|
|
155
|
-
export declare const GraphExpansionServiceNoop: Layer.Layer<GraphExpansionService, never, never>;
|
|
156
|
-
export declare const GraphExpansionServiceLive: Layer.Layer<GraphExpansionService, never, LearningRepository | AnchorRepository | EdgeService>;
|
|
157
|
-
export {};
|
|
158
|
-
//# sourceMappingURL=graph-expansion.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph-expansion.d.ts","sourceRoot":"","sources":["../../src/services/graph-expansion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,WAAW,EAA0B,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAG7E;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3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