@duckcodeailabs/dql-agent 1.11.10 → 1.12.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/dist/agent-run-engine.d.ts.map +1 -1
- package/dist/agent-run-engine.js +7 -3
- package/dist/agent-run-engine.js.map +1 -1
- package/dist/answer-loop.d.ts +25 -1
- package/dist/answer-loop.d.ts.map +1 -1
- package/dist/answer-loop.js +141 -17
- package/dist/answer-loop.js.map +1 -1
- package/dist/conversation/rolling-summary.d.ts +23 -0
- package/dist/conversation/rolling-summary.d.ts.map +1 -1
- package/dist/conversation/rolling-summary.js +64 -0
- package/dist/conversation/rolling-summary.js.map +1 -1
- package/dist/conversation/session-store.d.ts +18 -2
- package/dist/conversation/session-store.d.ts.map +1 -1
- package/dist/conversation/session-store.js +65 -8
- package/dist/conversation/session-store.js.map +1 -1
- package/dist/conversation/snapshot.d.ts +37 -4
- package/dist/conversation/snapshot.d.ts.map +1 -1
- package/dist/conversation/snapshot.js +115 -6
- package/dist/conversation/snapshot.js.map +1 -1
- package/dist/hints/correction-eval.d.ts.map +1 -1
- package/dist/hints/correction-eval.js +4 -6
- package/dist/hints/correction-eval.js.map +1 -1
- package/dist/hints/dependencies.d.ts +63 -0
- package/dist/hints/dependencies.d.ts.map +1 -0
- package/dist/hints/dependencies.js +196 -0
- package/dist/hints/dependencies.js.map +1 -0
- package/dist/hints/git-store.d.ts +55 -2
- package/dist/hints/git-store.d.ts.map +1 -1
- package/dist/hints/git-store.js +246 -11
- package/dist/hints/git-store.js.map +1 -1
- package/dist/hints/graph.d.ts +17 -0
- package/dist/hints/graph.d.ts.map +1 -0
- package/dist/hints/graph.js +222 -0
- package/dist/hints/graph.js.map +1 -0
- package/dist/hints/lifecycle.d.ts +107 -0
- package/dist/hints/lifecycle.d.ts.map +1 -0
- package/dist/hints/lifecycle.js +415 -0
- package/dist/hints/lifecycle.js.map +1 -0
- package/dist/hints/retrieval.d.ts +13 -1
- package/dist/hints/retrieval.d.ts.map +1 -1
- package/dist/hints/retrieval.js +74 -11
- package/dist/hints/retrieval.js.map +1 -1
- package/dist/hints/store.d.ts +9 -2
- package/dist/hints/store.d.ts.map +1 -1
- package/dist/hints/store.js +155 -15
- package/dist/hints/store.js.map +1 -1
- package/dist/hints/types.d.ts +63 -3
- package/dist/hints/types.d.ts.map +1 -1
- package/dist/hints/types.js +1 -1
- package/dist/hints/types.js.map +1 -1
- package/dist/index.d.ts +17 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/intent-controller.d.ts.map +1 -1
- package/dist/intent-controller.js +24 -3
- package/dist/intent-controller.js.map +1 -1
- package/dist/metadata/catalog.d.ts +32 -0
- package/dist/metadata/catalog.d.ts.map +1 -1
- package/dist/metadata/catalog.js +86 -4
- package/dist/metadata/catalog.js.map +1 -1
- package/dist/metadata/sql-context-validation.d.ts.map +1 -1
- package/dist/metadata/sql-context-validation.js +16 -0
- package/dist/metadata/sql-context-validation.js.map +1 -1
- package/dist/metadata/sql-grounding.d.ts +7 -0
- package/dist/metadata/sql-grounding.d.ts.map +1 -1
- package/dist/metadata/sql-grounding.js +26 -1
- package/dist/metadata/sql-grounding.js.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +32 -9
- package/dist/router.js.map +1 -1
- package/dist/skills/loader.js +1 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/tools/registry.js +5 -5
- package/dist/tools/registry.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { buildLocalContextPack } from '../metadata/catalog.js';
|
|
3
|
+
import { validateSqlAgainstLocalContext } from '../metadata/sql-context-validation.js';
|
|
4
|
+
import { evaluateHint, getCorrectionTraceFromGit, getHintEvaluationFromGit, getHintFromGit, HintLifecycleError, recordCorrectionTrace, reopenHint, requiresEvaluatedApproval, reviewHint, updateHintCandidate, } from './git-store.js';
|
|
5
|
+
import { assessHintFreshness, collectHintDependencies } from './dependencies.js';
|
|
6
|
+
/**
|
|
7
|
+
* Shared correction capture path for the notebook API, CLI runtime, and MCP.
|
|
8
|
+
* Capture remains permissive: unsafe or unresolved corrections are retained as
|
|
9
|
+
* candidates with lifecycle errors, but can never pass approval.
|
|
10
|
+
*/
|
|
11
|
+
export async function recordGovernedCorrection(projectRoot, input, resolveContext = resolveGovernedHintContext) {
|
|
12
|
+
const context = await resolveContext({
|
|
13
|
+
projectRoot,
|
|
14
|
+
question: input.question,
|
|
15
|
+
correctedSql: input.correctedSql,
|
|
16
|
+
scope: input.scope,
|
|
17
|
+
snapshotId: input.snapshotId,
|
|
18
|
+
}).catch((error) => unresolvedContext(input, error));
|
|
19
|
+
const lifecycleErrors = failuresFromChecks(context.checks);
|
|
20
|
+
const requiredEvaluation = input.requiredEvaluation?.trim()
|
|
21
|
+
|| `correction: ${input.question.trim().replace(/\s+/g, ' ').slice(0, 60)}`;
|
|
22
|
+
const evidence = uniqueStrings([
|
|
23
|
+
...(input.evidence ?? []),
|
|
24
|
+
`question: ${input.question}`,
|
|
25
|
+
...(input.correctedSql ? [`corrected SQL: ${compact(input.correctedSql, 400)}`] : []),
|
|
26
|
+
...context.evidence,
|
|
27
|
+
]);
|
|
28
|
+
const hintGuidance = input.hintGuidance?.trim() || deriveCorrectionGuidance(input);
|
|
29
|
+
return recordCorrectionTrace(projectRoot, {
|
|
30
|
+
...input,
|
|
31
|
+
hintGuidance,
|
|
32
|
+
failedRoute: input.failedRoute?.trim() || 'generated_answer',
|
|
33
|
+
evidence,
|
|
34
|
+
snapshotId: context.snapshotId,
|
|
35
|
+
requiredEvaluation,
|
|
36
|
+
dependencies: context.dependencies,
|
|
37
|
+
lifecycleErrors,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Do not let a SQL-only correction silently become the reusable lesson. Older
|
|
42
|
+
* clients may omit `hintGuidance`, so preserve a human-written correction when
|
|
43
|
+
* one exists and otherwise derive a conservative, reviewable instruction.
|
|
44
|
+
*/
|
|
45
|
+
export function deriveCorrectionGuidance(input) {
|
|
46
|
+
const explicit = input.hintGuidance?.trim();
|
|
47
|
+
if (explicit)
|
|
48
|
+
return explicit;
|
|
49
|
+
const correction = input.correction.trim();
|
|
50
|
+
const correctedSql = input.correctedSql?.trim();
|
|
51
|
+
const normalizedCorrection = correction.replace(/\s+/g, ' ');
|
|
52
|
+
const normalizedSql = correctedSql?.replace(/\s+/g, ' ');
|
|
53
|
+
if (!correctedSql || normalizedCorrection !== normalizedSql) {
|
|
54
|
+
return correction;
|
|
55
|
+
}
|
|
56
|
+
const scope = [
|
|
57
|
+
input.scope.domain ? `domain ${input.scope.domain}` : undefined,
|
|
58
|
+
input.scope.metric ? `metric ${input.scope.metric}` : undefined,
|
|
59
|
+
input.scope.dbtModel ? `model ${input.scope.dbtModel}` : undefined,
|
|
60
|
+
input.scope.term ? `term ${input.scope.term}` : undefined,
|
|
61
|
+
input.scope.block ? `block ${input.scope.block}` : undefined,
|
|
62
|
+
].filter(Boolean).join(', ');
|
|
63
|
+
const question = compact(input.question, 120);
|
|
64
|
+
return `For ${scope || 'matching governed questions'}, follow the reviewed corrected SQL pattern captured for "${question}". Confirm the pattern against current certified, dbt, and semantic context.`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Shared fail-closed review path. A v3 approval always creates a fresh
|
|
68
|
+
* evaluation artifact, so a failed attempt remains reviewable and retryable.
|
|
69
|
+
*/
|
|
70
|
+
export async function reviewGovernedHint(projectRoot, input) {
|
|
71
|
+
const hint = getHintFromGit(projectRoot, input.hintId);
|
|
72
|
+
if (!hint)
|
|
73
|
+
return null;
|
|
74
|
+
if (input.decision === 'rejected' || !requiresEvaluatedApproval(projectRoot)) {
|
|
75
|
+
return reviewHint(projectRoot, {
|
|
76
|
+
hintId: input.hintId,
|
|
77
|
+
decision: input.decision,
|
|
78
|
+
reviewer: input.reviewer,
|
|
79
|
+
note: input.note,
|
|
80
|
+
snapshotId: input.snapshotId,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (hint.status !== 'candidate') {
|
|
84
|
+
throw new HintLifecycleError('HINT_NOT_CANDIDATE', `Hint ${hint.id} is ${hint.status}; only candidates can be reviewed.`);
|
|
85
|
+
}
|
|
86
|
+
if (!hint.correctedSql?.trim()) {
|
|
87
|
+
throw new HintLifecycleError('HINT_CORRECTED_SQL_REQUIRED', `Hint ${hint.id} cannot be approved without corrected SQL.`);
|
|
88
|
+
}
|
|
89
|
+
if (!hint.requiredEvaluation || !hint.snapshotId) {
|
|
90
|
+
throw new HintLifecycleError('HINT_PROVENANCE_REQUIRED', `Hint ${hint.id} is missing its required evaluation or immutable snapshot.`);
|
|
91
|
+
}
|
|
92
|
+
const trace = hint.traceId ? getCorrectionTraceFromGit(projectRoot, hint.traceId) : null;
|
|
93
|
+
const question = trace?.question?.trim() || hint.title;
|
|
94
|
+
const resolveContext = input.resolveContext ?? resolveGovernedHintContext;
|
|
95
|
+
const current = await resolveContext({
|
|
96
|
+
projectRoot,
|
|
97
|
+
question,
|
|
98
|
+
correctedSql: hint.correctedSql,
|
|
99
|
+
scope: hint.scope,
|
|
100
|
+
snapshotId: input.snapshotId,
|
|
101
|
+
}).catch((error) => unresolvedContext({ question, scope: hint.scope, correctedSql: hint.correctedSql }, error));
|
|
102
|
+
const freshness = assessHintFreshness({
|
|
103
|
+
dependencies: hint.dependencies,
|
|
104
|
+
snapshotId: hint.snapshotId,
|
|
105
|
+
currentSnapshotId: current.snapshotId,
|
|
106
|
+
currentDependencies: new Map(current.dependencies.map((dependency) => [dependency.id, dependency.fingerprint])),
|
|
107
|
+
});
|
|
108
|
+
const checks = [
|
|
109
|
+
...current.checks,
|
|
110
|
+
{
|
|
111
|
+
name: 'snapshot-current',
|
|
112
|
+
passed: freshness.current,
|
|
113
|
+
evidence: freshness.snapshotCurrent
|
|
114
|
+
? `Current snapshot matches ${hint.snapshotId}.`
|
|
115
|
+
: freshness.dependenciesCurrent
|
|
116
|
+
? `Project snapshot changed from ${hint.snapshotId} to ${current.snapshotId}, but every scoped dependency still matches.`
|
|
117
|
+
: `Candidate snapshot ${hint.snapshotId}; current snapshot ${current.snapshotId}.`,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
checks.push({
|
|
121
|
+
name: 'dependencies-current',
|
|
122
|
+
passed: freshness.dependenciesCurrent,
|
|
123
|
+
evidence: freshness.staleDependencies.length > 0
|
|
124
|
+
? `Changed or missing dependencies: ${freshness.staleDependencies.map((dependency) => dependency.id).join(', ')}.`
|
|
125
|
+
: `${hint.dependencies?.length ?? 0} recorded dependencies match current governed context.`,
|
|
126
|
+
});
|
|
127
|
+
const rowLimit = clampRowLimit(input.rowLimit);
|
|
128
|
+
const executionEvidence = [];
|
|
129
|
+
if (input.executeSql) {
|
|
130
|
+
try {
|
|
131
|
+
const result = await input.executeSql(hint.correctedSql, { rowLimit, question });
|
|
132
|
+
const bounded = Number.isInteger(result.rowCount)
|
|
133
|
+
&& result.rowCount >= 0
|
|
134
|
+
&& result.rowCount <= rowLimit
|
|
135
|
+
&& Array.isArray(result.rows)
|
|
136
|
+
&& result.rows.length <= rowLimit;
|
|
137
|
+
checks.push({
|
|
138
|
+
name: 'bounded-execution',
|
|
139
|
+
passed: bounded,
|
|
140
|
+
evidence: bounded
|
|
141
|
+
? `Compiled and executed read-only SQL with ${result.rowCount} row(s), bounded to ${rowLimit}.`
|
|
142
|
+
: `Execution returned an invalid or unbounded result (rowCount=${String(result.rowCount)}, rows=${result.rows?.length ?? 'unknown'}).`,
|
|
143
|
+
});
|
|
144
|
+
const hasResultShape = Array.isArray(result.columns) && result.columns.length > 0;
|
|
145
|
+
checks.push({
|
|
146
|
+
name: 'result-shape-assertion',
|
|
147
|
+
passed: hasResultShape,
|
|
148
|
+
evidence: hasResultShape
|
|
149
|
+
? `Result columns: ${result.columns.map((column) => typeof column === 'string'
|
|
150
|
+
? column
|
|
151
|
+
: column && typeof column === 'object' && 'name' in column
|
|
152
|
+
? String(column.name ?? '?')
|
|
153
|
+
: '?').join(', ')}.`
|
|
154
|
+
: 'Execution returned no inspectable result columns.',
|
|
155
|
+
});
|
|
156
|
+
executionEvidence.push(`bounded result: rows=${result.rowCount}; columns=${result.columns.length}; limit=${rowLimit}`);
|
|
157
|
+
if (result.executionReceipt) {
|
|
158
|
+
executionEvidence.push(`execution receipt: ${compact(JSON.stringify(result.executionReceipt), 500)}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
checks.push({
|
|
163
|
+
name: 'bounded-execution',
|
|
164
|
+
passed: false,
|
|
165
|
+
evidence: error instanceof Error ? error.message : String(error),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
checks.push({
|
|
171
|
+
name: 'review-evidence-assertion',
|
|
172
|
+
passed: Boolean(input.note?.trim()),
|
|
173
|
+
evidence: input.note?.trim()
|
|
174
|
+
? `Reviewer assertion: ${compact(input.note, 300)}`
|
|
175
|
+
: 'This surface cannot execute the correction; an explicit reviewer evidence note is required.',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
checks.push({
|
|
179
|
+
name: 'human-semantic-approval',
|
|
180
|
+
passed: Boolean(input.reviewer.trim()),
|
|
181
|
+
evidence: `Explicit approval by ${input.reviewer.trim() || 'unknown reviewer'}; execution success alone does not establish semantic correctness.`,
|
|
182
|
+
});
|
|
183
|
+
const evaluated = evaluateHint(projectRoot, {
|
|
184
|
+
hintId: hint.id,
|
|
185
|
+
snapshotId: hint.snapshotId,
|
|
186
|
+
evaluation: hint.requiredEvaluation,
|
|
187
|
+
evaluator: input.reviewer,
|
|
188
|
+
checks,
|
|
189
|
+
evidence: uniqueStrings([
|
|
190
|
+
`candidate snapshot: ${hint.snapshotId}`,
|
|
191
|
+
`current snapshot: ${current.snapshotId}`,
|
|
192
|
+
...current.evidence,
|
|
193
|
+
...executionEvidence,
|
|
194
|
+
]),
|
|
195
|
+
note: input.note,
|
|
196
|
+
});
|
|
197
|
+
if (evaluated.evaluation.status !== 'passed') {
|
|
198
|
+
throw new HintLifecycleError('HINT_EVALUATION_FAILED', `Hint ${hint.id} remains a candidate because evaluation ${evaluated.evaluation.id} failed: ${checks.filter((check) => !check.passed).map((check) => check.name).join(', ')}. The evaluation is persisted and may be rerun after correction.`);
|
|
199
|
+
}
|
|
200
|
+
const reviewed = reviewHint(projectRoot, {
|
|
201
|
+
hintId: hint.id,
|
|
202
|
+
decision: 'approved',
|
|
203
|
+
reviewer: input.reviewer,
|
|
204
|
+
note: input.note,
|
|
205
|
+
snapshotId: hint.snapshotId,
|
|
206
|
+
});
|
|
207
|
+
return reviewed ? { ...reviewed, evaluation: evaluated.evaluation } : null;
|
|
208
|
+
}
|
|
209
|
+
/** CTX-005 / API-003: read-only live inspection used by review surfaces and lifecycle decisions. */
|
|
210
|
+
export async function inspectGovernedHint(projectRoot, input) {
|
|
211
|
+
const hint = getHintFromGit(projectRoot, input.hintId);
|
|
212
|
+
if (!hint)
|
|
213
|
+
return null;
|
|
214
|
+
const trace = hint.traceId ? getCorrectionTraceFromGit(projectRoot, hint.traceId) ?? undefined : undefined;
|
|
215
|
+
const question = trace?.question?.trim() || hint.title;
|
|
216
|
+
const resolveContext = input.resolveContext ?? resolveGovernedHintContext;
|
|
217
|
+
const current = await resolveContext({
|
|
218
|
+
projectRoot,
|
|
219
|
+
question,
|
|
220
|
+
correctedSql: hint.correctedSql,
|
|
221
|
+
scope: hint.scope,
|
|
222
|
+
snapshotId: input.snapshotId,
|
|
223
|
+
}).catch((error) => unresolvedContext({ question, scope: hint.scope, correctedSql: hint.correctedSql }, error));
|
|
224
|
+
const freshness = assessHintFreshness({
|
|
225
|
+
dependencies: hint.dependencies,
|
|
226
|
+
snapshotId: hint.snapshotId,
|
|
227
|
+
currentSnapshotId: current.snapshotId,
|
|
228
|
+
currentDependencies: new Map(current.dependencies.map((dependency) => [dependency.id, dependency.fingerprint])),
|
|
229
|
+
});
|
|
230
|
+
const checks = [
|
|
231
|
+
...current.checks,
|
|
232
|
+
{
|
|
233
|
+
name: 'snapshot-current',
|
|
234
|
+
passed: freshness.current,
|
|
235
|
+
evidence: freshness.snapshotCurrent
|
|
236
|
+
? `Current snapshot matches ${hint.snapshotId}.`
|
|
237
|
+
: freshness.dependenciesCurrent
|
|
238
|
+
? `Project snapshot changed from ${hint.snapshotId ?? '(missing)'} to ${current.snapshotId}, but every scoped dependency still matches.`
|
|
239
|
+
: `Recorded snapshot ${hint.snapshotId ?? '(missing)'}; current snapshot ${current.snapshotId}.`,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'dependencies-current',
|
|
243
|
+
passed: freshness.dependenciesCurrent,
|
|
244
|
+
evidence: freshness.staleDependencies.length > 0
|
|
245
|
+
? `Changed or missing dependencies: ${freshness.staleDependencies.map((dependency) => dependency.id).join(', ')}.`
|
|
246
|
+
: `${hint.dependencies?.length ?? 0} recorded dependencies match current governed context.`,
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
const state = current.snapshotId.startsWith('unverified:')
|
|
250
|
+
? 'unverified'
|
|
251
|
+
: !freshness.current
|
|
252
|
+
? 'stale'
|
|
253
|
+
: checks.some((check) => !check.passed)
|
|
254
|
+
? 'invalid'
|
|
255
|
+
: 'current';
|
|
256
|
+
return {
|
|
257
|
+
hint,
|
|
258
|
+
trace,
|
|
259
|
+
evaluation: hint.evaluationId ? getHintEvaluationFromGit(projectRoot, hint.evaluationId) ?? undefined : undefined,
|
|
260
|
+
currentSnapshotId: current.snapshotId,
|
|
261
|
+
snapshotCurrent: freshness.snapshotCurrent,
|
|
262
|
+
dependenciesCurrent: freshness.dependenciesCurrent,
|
|
263
|
+
driftedDependencies: freshness.staleDependencies,
|
|
264
|
+
checks,
|
|
265
|
+
state,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** CTX-005 / E2E-001: explicit edit revalidates provenance and clears prior evaluation state. */
|
|
269
|
+
export async function editGovernedHintCandidate(projectRoot, input) {
|
|
270
|
+
const hint = getHintFromGit(projectRoot, input.hintId);
|
|
271
|
+
if (!hint)
|
|
272
|
+
return null;
|
|
273
|
+
const trace = hint.traceId ? getCorrectionTraceFromGit(projectRoot, hint.traceId) : null;
|
|
274
|
+
const scope = input.scope ?? hint.scope;
|
|
275
|
+
const correctedSql = input.correctedSql?.trim() || hint.correctedSql;
|
|
276
|
+
const question = trace?.question?.trim() || input.title?.trim() || hint.title;
|
|
277
|
+
const resolveContext = input.resolveContext ?? resolveGovernedHintContext;
|
|
278
|
+
const current = await resolveContext({
|
|
279
|
+
projectRoot,
|
|
280
|
+
question,
|
|
281
|
+
correctedSql,
|
|
282
|
+
scope,
|
|
283
|
+
snapshotId: input.snapshotId,
|
|
284
|
+
}).catch((error) => unresolvedContext({ question, scope, correctedSql }, error));
|
|
285
|
+
return updateHintCandidate(projectRoot, {
|
|
286
|
+
hintId: hint.id,
|
|
287
|
+
title: input.title,
|
|
288
|
+
guidance: input.guidance,
|
|
289
|
+
correctedSql,
|
|
290
|
+
scope,
|
|
291
|
+
snapshotId: current.snapshotId,
|
|
292
|
+
dependencies: current.dependencies,
|
|
293
|
+
lifecycleErrors: failuresFromChecks(current.checks),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/** CTX-005: reopen an applied/retired hint as a non-retrievable candidate against current context. */
|
|
297
|
+
export async function reopenGovernedHint(projectRoot, input) {
|
|
298
|
+
const hint = getHintFromGit(projectRoot, input.hintId);
|
|
299
|
+
if (!hint)
|
|
300
|
+
return null;
|
|
301
|
+
const trace = hint.traceId ? getCorrectionTraceFromGit(projectRoot, hint.traceId) : null;
|
|
302
|
+
const question = trace?.question?.trim() || hint.title;
|
|
303
|
+
const resolveContext = input.resolveContext ?? resolveGovernedHintContext;
|
|
304
|
+
const current = await resolveContext({
|
|
305
|
+
projectRoot,
|
|
306
|
+
question,
|
|
307
|
+
correctedSql: hint.correctedSql,
|
|
308
|
+
scope: hint.scope,
|
|
309
|
+
snapshotId: input.snapshotId,
|
|
310
|
+
}).catch((error) => unresolvedContext({ question, scope: hint.scope, correctedSql: hint.correctedSql }, error));
|
|
311
|
+
return reopenHint(projectRoot, {
|
|
312
|
+
hintId: hint.id,
|
|
313
|
+
reviewer: input.reviewer,
|
|
314
|
+
note: input.note,
|
|
315
|
+
snapshotId: current.snapshotId,
|
|
316
|
+
dependencies: current.dependencies,
|
|
317
|
+
lifecycleErrors: failuresFromChecks(current.checks),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/** Resolve current SQL authorization and content-addressed dependencies. */
|
|
321
|
+
export async function resolveGovernedHintContext(input) {
|
|
322
|
+
const pack = await buildLocalContextPack(input.projectRoot, {
|
|
323
|
+
question: input.question,
|
|
324
|
+
surface: 'hint_lifecycle',
|
|
325
|
+
strictness: 'safe',
|
|
326
|
+
});
|
|
327
|
+
const snapshotId = input.snapshotId?.trim()
|
|
328
|
+
|| pack.freshness.fingerprint
|
|
329
|
+
|| `unverified:${shortHash(`${input.question}\0${input.correctedSql ?? ''}`)}`;
|
|
330
|
+
const collected = collectHintDependencies({
|
|
331
|
+
sql: input.correctedSql,
|
|
332
|
+
scope: input.scope,
|
|
333
|
+
objects: pack.objects,
|
|
334
|
+
relations: pack.allowedSqlContext.relations,
|
|
335
|
+
fallbackFingerprint: pack.freshness.fingerprint ?? undefined,
|
|
336
|
+
});
|
|
337
|
+
const validation = input.correctedSql?.trim()
|
|
338
|
+
? validateSqlAgainstLocalContext(input.correctedSql, pack, {
|
|
339
|
+
dialect: input.scope.dialect,
|
|
340
|
+
question: input.question,
|
|
341
|
+
})
|
|
342
|
+
: null;
|
|
343
|
+
const checks = [
|
|
344
|
+
{
|
|
345
|
+
name: 'corrected-sql-present',
|
|
346
|
+
passed: Boolean(input.correctedSql?.trim()),
|
|
347
|
+
evidence: input.correctedSql?.trim() ? 'Candidate includes corrected SQL.' : 'Candidate has no corrected SQL.',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: 'read-only-sql',
|
|
351
|
+
passed: Boolean(validation && (validation.ok
|
|
352
|
+
|| (validation.code !== 'unsafe_sql' && validation.code !== 'insufficient_context'))),
|
|
353
|
+
evidence: validation?.ok
|
|
354
|
+
? 'Parser accepted a read-only SELECT/WITH statement.'
|
|
355
|
+
: validation?.error ?? 'No SQL was available to parse.',
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'relations-authorized',
|
|
359
|
+
passed: Boolean(validation?.ok) && collected.referencedRelations.length > 0 && collected.unknownRelations.length === 0,
|
|
360
|
+
evidence: collected.unknownRelations.length > 0
|
|
361
|
+
? `Relations outside current governed context: ${collected.unknownRelations.join(', ')}.`
|
|
362
|
+
: collected.referencedRelations.length > 0
|
|
363
|
+
? `Authorized relations: ${collected.referencedRelations.join(', ')}.`
|
|
364
|
+
: validation && !validation.ok
|
|
365
|
+
? validation.error
|
|
366
|
+
: 'No governed relation was referenced.',
|
|
367
|
+
},
|
|
368
|
+
];
|
|
369
|
+
return {
|
|
370
|
+
snapshotId,
|
|
371
|
+
dependencies: collected.dependencies,
|
|
372
|
+
checks,
|
|
373
|
+
evidence: [
|
|
374
|
+
`snapshot: ${snapshotId}`,
|
|
375
|
+
...collected.dependencies.map((dependency) => `dependency: ${dependency.id}@${dependency.fingerprint}`),
|
|
376
|
+
],
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function unresolvedContext(input, error) {
|
|
380
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
381
|
+
return {
|
|
382
|
+
snapshotId: `unverified:${shortHash(`${input.question}\0${input.correctedSql ?? ''}`)}`,
|
|
383
|
+
dependencies: [],
|
|
384
|
+
checks: [
|
|
385
|
+
{ name: 'context-resolved', passed: false, evidence: message },
|
|
386
|
+
{ name: 'relations-authorized', passed: false, evidence: 'Current governed context could not be resolved.' },
|
|
387
|
+
],
|
|
388
|
+
evidence: [`context resolution failed: ${message}`],
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function failuresFromChecks(checks) {
|
|
392
|
+
const at = new Date().toISOString();
|
|
393
|
+
return checks
|
|
394
|
+
.filter((check) => !check.passed)
|
|
395
|
+
.map((check) => ({
|
|
396
|
+
code: `HINT_${check.name.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_FAILED`,
|
|
397
|
+
message: check.evidence || `${check.name} failed.`,
|
|
398
|
+
at,
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
function uniqueStrings(values) {
|
|
402
|
+
return [...new Set(values.map((value) => value.trim()).filter(Boolean))];
|
|
403
|
+
}
|
|
404
|
+
function compact(value, limit) {
|
|
405
|
+
return value.replace(/\s+/g, ' ').trim().slice(0, limit);
|
|
406
|
+
}
|
|
407
|
+
function shortHash(value) {
|
|
408
|
+
return createHash('sha256').update(value).digest('hex').slice(0, 16);
|
|
409
|
+
}
|
|
410
|
+
function clampRowLimit(value) {
|
|
411
|
+
if (!Number.isFinite(value))
|
|
412
|
+
return 200;
|
|
413
|
+
return Math.max(1, Math.min(500, Math.floor(value)));
|
|
414
|
+
}
|
|
415
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/hints/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,UAAU,EACV,yBAAyB,EACzB,UAAU,EACV,mBAAmB,GAIpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,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gB;IACrC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,KAAa;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,aAAa,CAAC,KAAyB;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
* ever returned in normal mode. A hint is applied only within its declared
|
|
9
9
|
* scope (metric / dbt model / domain / dialect / term / block).
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
11
|
+
import { type QuestionScope } from './types.js';
|
|
12
12
|
import type { EmbeddingProvider } from '../embeddings/provider.js';
|
|
13
13
|
export interface AppliedHint {
|
|
14
14
|
hintId: string;
|
|
15
15
|
title: string;
|
|
16
16
|
guidance: string;
|
|
17
17
|
scopeReason: string;
|
|
18
|
+
graphReason?: string;
|
|
18
19
|
score: number;
|
|
19
20
|
correctedSql?: string;
|
|
20
21
|
traceId?: string;
|
|
@@ -28,6 +29,13 @@ export interface HintRetrievalResult {
|
|
|
28
29
|
titles: [string, string];
|
|
29
30
|
reason: string;
|
|
30
31
|
}>;
|
|
32
|
+
/** Approved hints withheld by governance gates, retained for review/repair. */
|
|
33
|
+
excluded: Array<{
|
|
34
|
+
hintId: string;
|
|
35
|
+
title: string;
|
|
36
|
+
reason: 'stale' | 'superseded' | 'conflict';
|
|
37
|
+
detail: string;
|
|
38
|
+
}>;
|
|
31
39
|
}
|
|
32
40
|
export interface RetrieveScopedHintsOptions {
|
|
33
41
|
questionScope: QuestionScope;
|
|
@@ -39,6 +47,10 @@ export interface RetrieveScopedHintsOptions {
|
|
|
39
47
|
alpha?: number;
|
|
40
48
|
embeddingProvider?: EmbeddingProvider;
|
|
41
49
|
indexPath?: string;
|
|
50
|
+
/** Current content fingerprints keyed by persisted dependency id. */
|
|
51
|
+
currentDependencies?: ReadonlyMap<string, string>;
|
|
52
|
+
/** Conservative fallback for older v3 hints without dependency provenance. */
|
|
53
|
+
currentSnapshotId?: string | null;
|
|
42
54
|
}
|
|
43
55
|
/**
|
|
44
56
|
* Retrieve approved scoped hints from the SQLite index. Returns an empty result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../../src/hints/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../../src/hints/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAA4B,KAAK,aAAa,EAAwB,MAAM,YAAY,CAAC;AAEhG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAA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|
import { defaultHintIndexPath } from './git-store.js';
|
|
13
13
|
import { HintStore } from './store.js';
|
|
14
|
+
import { hintsConflict } from './types.js';
|
|
15
|
+
import { assessHintFreshness } from './dependencies.js';
|
|
14
16
|
/**
|
|
15
17
|
* Retrieve approved scoped hints from the SQLite index. Returns an empty result
|
|
16
18
|
* (no error) when the index does not exist yet or no hints match — keeping the
|
|
@@ -19,7 +21,7 @@ import { HintStore } from './store.js';
|
|
|
19
21
|
export async function retrieveScopedHints(projectRoot, options) {
|
|
20
22
|
const indexPath = options.indexPath ?? defaultHintIndexPath(projectRoot);
|
|
21
23
|
if (!existsSync(indexPath))
|
|
22
|
-
return { applied: [], conflicts: [] };
|
|
24
|
+
return { applied: [], conflicts: [], excluded: [] };
|
|
23
25
|
const store = new HintStore(indexPath);
|
|
24
26
|
try {
|
|
25
27
|
const matches = await store.searchApprovedHints({
|
|
@@ -28,19 +30,79 @@ export async function retrieveScopedHints(projectRoot, options) {
|
|
|
28
30
|
alpha: options.alpha,
|
|
29
31
|
embeddingProvider: options.embeddingProvider,
|
|
30
32
|
});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const excluded = [];
|
|
34
|
+
const fresh = matches.filter((match) => {
|
|
35
|
+
const currentDependencies = new Map(options.currentDependencies ?? []);
|
|
36
|
+
if (options.currentSnapshotId) {
|
|
37
|
+
for (const dependency of match.hint.dependencies ?? []) {
|
|
38
|
+
if (dependency.id.startsWith('scope:')) {
|
|
39
|
+
currentDependencies.set(dependency.id, options.currentSnapshotId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const freshness = assessHintFreshness({
|
|
44
|
+
dependencies: match.hint.dependencies,
|
|
45
|
+
snapshotId: match.hint.snapshotId,
|
|
46
|
+
currentDependencies,
|
|
47
|
+
currentSnapshotId: options.currentSnapshotId,
|
|
48
|
+
});
|
|
49
|
+
if (freshness.current)
|
|
50
|
+
return true;
|
|
51
|
+
excluded.push({
|
|
52
|
+
hintId: match.hint.id,
|
|
53
|
+
title: match.hint.title,
|
|
54
|
+
reason: 'stale',
|
|
55
|
+
detail: freshness.staleDependencies.length > 0
|
|
56
|
+
? `Changed or missing dependencies: ${freshness.staleDependencies.map((dependency) => dependency.id).join(', ')}.`
|
|
57
|
+
: `Candidate snapshot ${match.hint.snapshotId} differs from current snapshot ${options.currentSnapshotId}.`,
|
|
58
|
+
});
|
|
59
|
+
return false;
|
|
60
|
+
});
|
|
61
|
+
const eligibleIds = new Set(fresh.map((match) => match.hint.id));
|
|
62
|
+
const supersededIds = new Set(fresh
|
|
63
|
+
.map((match) => match.hint.supersedes)
|
|
64
|
+
.filter((id) => Boolean(id) && eligibleIds.has(id)));
|
|
65
|
+
const unsuperseded = fresh.filter((match) => {
|
|
66
|
+
if (!supersededIds.has(match.hint.id))
|
|
67
|
+
return true;
|
|
68
|
+
excluded.push({
|
|
69
|
+
hintId: match.hint.id,
|
|
70
|
+
title: match.hint.title,
|
|
71
|
+
reason: 'superseded',
|
|
72
|
+
detail: 'A newer eligible approved hint explicitly supersedes this hint.',
|
|
73
|
+
});
|
|
74
|
+
return false;
|
|
75
|
+
});
|
|
76
|
+
const conflictPairs = [];
|
|
77
|
+
for (let left = 0; left < unsuperseded.length; left += 1) {
|
|
78
|
+
for (let right = left + 1; right < unsuperseded.length; right += 1) {
|
|
79
|
+
const a = unsuperseded[left].hint;
|
|
80
|
+
const b = unsuperseded[right].hint;
|
|
81
|
+
if (hintsConflict(a, b))
|
|
82
|
+
conflictPairs.push([a, b]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const conflictingIds = new Set(conflictPairs.flatMap(([a, b]) => [a.id, b.id]));
|
|
86
|
+
for (const match of unsuperseded) {
|
|
87
|
+
if (!conflictingIds.has(match.hint.id))
|
|
88
|
+
continue;
|
|
89
|
+
excluded.push({
|
|
90
|
+
hintId: match.hint.id,
|
|
91
|
+
title: match.hint.title,
|
|
92
|
+
reason: 'conflict',
|
|
93
|
+
detail: 'Overlapping approved hints are withheld until one explicitly supersedes the other.',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const applied = unsuperseded
|
|
97
|
+
.filter((match) => !conflictingIds.has(match.hint.id))
|
|
98
|
+
.slice(0, options.limit ?? 6)
|
|
99
|
+
.map(toAppliedHint);
|
|
100
|
+
const conflicts = conflictPairs.map(([a, b]) => ({
|
|
39
101
|
hintIds: [a.id, b.id],
|
|
40
102
|
titles: [a.title, b.title],
|
|
41
|
-
reason: `Approved hints "${a.title}" and "${b.title}" overlap on scope and
|
|
103
|
+
reason: `Approved hints "${a.title}" and "${b.title}" overlap on scope and are withheld until review resolves the conflict.`,
|
|
42
104
|
}));
|
|
43
|
-
return { applied, conflicts };
|
|
105
|
+
return { applied, conflicts, excluded };
|
|
44
106
|
}
|
|
45
107
|
finally {
|
|
46
108
|
store.close();
|
|
@@ -52,6 +114,7 @@ function toAppliedHint(match) {
|
|
|
52
114
|
title: match.hint.title,
|
|
53
115
|
guidance: match.hint.guidance,
|
|
54
116
|
scopeReason: match.scopeReason,
|
|
117
|
+
graphReason: match.graphReason,
|
|
55
118
|
score: match.score,
|
|
56
119
|
correctedSql: match.hint.correctedSql,
|
|
57
120
|
traceId: match.hint.traceId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../../src/hints/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../../src/hints/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAA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