@jigyasudham/veto 3.0.0 → 3.1.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/LICENSE +21 -21
- package/README.md +630 -589
- package/dist/agents/llm-runner.js +57 -57
- package/dist/cli/statusline.js +2 -2
- package/dist/cli.js +57 -26
- package/dist/cli.js.map +1 -1
- package/dist/memory/decisions.js +1 -1
- package/dist/memory/local.js +144 -144
- package/dist/memory/schema.js +228 -228
- package/dist/memory/sync.js +25 -25
- package/dist/router/implicit-outcomes.js +4 -4
- package/dist/router/learning-updater.js +45 -45
- package/dist/server.js +1 -1
- package/dist/tools/compact.js +3 -3
- package/dist/transcripts/archive.js +5 -5
- package/dist/transcripts/cache.d.ts +66 -0
- package/dist/transcripts/cache.d.ts.map +1 -0
- package/dist/transcripts/cache.js +0 -0
- package/dist/transcripts/cache.js.map +1 -0
- package/dist/transcripts/chunk.d.ts +26 -0
- package/dist/transcripts/chunk.d.ts.map +1 -0
- package/dist/transcripts/chunk.js +54 -0
- package/dist/transcripts/chunk.js.map +1 -0
- package/dist/transcripts/embed.d.ts +58 -0
- package/dist/transcripts/embed.d.ts.map +1 -0
- package/dist/transcripts/embed.js +303 -0
- package/dist/transcripts/embed.js.map +1 -0
- package/dist/transcripts/ingest.d.ts.map +1 -1
- package/dist/transcripts/ingest.js +14 -7
- package/dist/transcripts/ingest.js.map +1 -1
- package/dist/transcripts/manage.d.ts.map +1 -1
- package/dist/transcripts/manage.js +6 -0
- package/dist/transcripts/manage.js.map +1 -1
- package/dist/transcripts/mapping.js +5 -5
- package/dist/transcripts/pyramid.js +2 -2
- package/dist/transcripts/recall.d.ts +7 -0
- package/dist/transcripts/recall.d.ts.map +1 -1
- package/dist/transcripts/recall.js +25 -3
- package/dist/transcripts/recall.js.map +1 -1
- package/dist/transcripts/schema.d.ts +11 -1
- package/dist/transcripts/schema.d.ts.map +1 -1
- package/dist/transcripts/schema.js +126 -94
- package/dist/transcripts/schema.js.map +1 -1
- package/dist/transcripts/search.d.ts +35 -0
- package/dist/transcripts/search.d.ts.map +1 -1
- package/dist/transcripts/search.js +232 -34
- package/dist/transcripts/search.js.map +1 -1
- package/dist/transcripts/vectors.d.ts +40 -0
- package/dist/transcripts/vectors.d.ts.map +1 -0
- package/dist/transcripts/vectors.js +203 -0
- package/dist/transcripts/vectors.js.map +1 -0
- package/package.json +70 -61
- package/server.json +23 -23
- package/dist/skills/development/skill-api-design.d.ts +0 -15
- package/dist/skills/development/skill-api-design.d.ts.map +0 -1
- package/dist/skills/development/skill-api-design.js +0 -313
- package/dist/skills/development/skill-api-design.js.map +0 -1
- package/dist/skills/development/skill-auth.d.ts +0 -15
- package/dist/skills/development/skill-auth.d.ts.map +0 -1
- package/dist/skills/development/skill-auth.js +0 -255
- package/dist/skills/development/skill-auth.js.map +0 -1
- package/dist/skills/development/skill-ci-cd.d.ts +0 -2
- package/dist/skills/development/skill-ci-cd.d.ts.map +0 -1
- package/dist/skills/development/skill-ci-cd.js +0 -2
- package/dist/skills/development/skill-ci-cd.js.map +0 -1
- package/dist/skills/development/skill-crud.d.ts +0 -15
- package/dist/skills/development/skill-crud.d.ts.map +0 -1
- package/dist/skills/development/skill-crud.js +0 -193
- package/dist/skills/development/skill-crud.js.map +0 -1
- package/dist/skills/development/skill-db-schema.d.ts +0 -2
- package/dist/skills/development/skill-db-schema.d.ts.map +0 -1
- package/dist/skills/development/skill-db-schema.js +0 -2
- package/dist/skills/development/skill-db-schema.js.map +0 -1
- package/dist/skills/development/skill-docker.d.ts +0 -2
- package/dist/skills/development/skill-docker.d.ts.map +0 -1
- package/dist/skills/development/skill-docker.js +0 -2
- package/dist/skills/development/skill-docker.js.map +0 -1
- package/dist/skills/development/skill-env-setup.d.ts +0 -2
- package/dist/skills/development/skill-env-setup.d.ts.map +0 -1
- package/dist/skills/development/skill-env-setup.js +0 -2
- package/dist/skills/development/skill-env-setup.js.map +0 -1
- package/dist/skills/development/skill-scaffold.d.ts +0 -15
- package/dist/skills/development/skill-scaffold.d.ts.map +0 -1
- package/dist/skills/development/skill-scaffold.js +0 -299
- package/dist/skills/development/skill-scaffold.js.map +0 -1
- package/dist/skills/intelligence/skill-complexity-score.d.ts +0 -15
- package/dist/skills/intelligence/skill-complexity-score.d.ts.map +0 -1
- package/dist/skills/intelligence/skill-complexity-score.js +0 -66
- package/dist/skills/intelligence/skill-complexity-score.js.map +0 -1
- package/dist/skills/intelligence/skill-cost-track.d.ts +0 -14
- package/dist/skills/intelligence/skill-cost-track.d.ts.map +0 -1
- package/dist/skills/intelligence/skill-cost-track.js +0 -36
- package/dist/skills/intelligence/skill-cost-track.js.map +0 -1
- package/dist/skills/intelligence/skill-learning-loop.d.ts +0 -15
- package/dist/skills/intelligence/skill-learning-loop.d.ts.map +0 -1
- package/dist/skills/intelligence/skill-learning-loop.js +0 -66
- package/dist/skills/intelligence/skill-learning-loop.js.map +0 -1
- package/dist/skills/intelligence/skill-pattern-detect.d.ts +0 -14
- package/dist/skills/intelligence/skill-pattern-detect.d.ts.map +0 -1
- package/dist/skills/intelligence/skill-pattern-detect.js +0 -35
- package/dist/skills/intelligence/skill-pattern-detect.js.map +0 -1
- package/dist/skills/intelligence/skill-rate-watch.d.ts +0 -15
- package/dist/skills/intelligence/skill-rate-watch.d.ts.map +0 -1
- package/dist/skills/intelligence/skill-rate-watch.js +0 -58
- package/dist/skills/intelligence/skill-rate-watch.js.map +0 -1
- package/dist/skills/memory/skill-context-compress.d.ts +0 -15
- package/dist/skills/memory/skill-context-compress.d.ts.map +0 -1
- package/dist/skills/memory/skill-context-compress.js +0 -82
- package/dist/skills/memory/skill-context-compress.js.map +0 -1
- package/dist/skills/memory/skill-cross-sync.d.ts +0 -15
- package/dist/skills/memory/skill-cross-sync.d.ts.map +0 -1
- package/dist/skills/memory/skill-cross-sync.js +0 -88
- package/dist/skills/memory/skill-cross-sync.js.map +0 -1
- package/dist/skills/memory/skill-decision-log.d.ts +0 -15
- package/dist/skills/memory/skill-decision-log.d.ts.map +0 -1
- package/dist/skills/memory/skill-decision-log.js +0 -103
- package/dist/skills/memory/skill-decision-log.js.map +0 -1
- package/dist/skills/memory/skill-session-restore.d.ts +0 -15
- package/dist/skills/memory/skill-session-restore.d.ts.map +0 -1
- package/dist/skills/memory/skill-session-restore.js +0 -39
- package/dist/skills/memory/skill-session-restore.js.map +0 -1
- package/dist/skills/memory/skill-session-save.d.ts +0 -15
- package/dist/skills/memory/skill-session-save.d.ts.map +0 -1
- package/dist/skills/memory/skill-session-save.js +0 -74
- package/dist/skills/memory/skill-session-save.js.map +0 -1
- package/dist/skills/quality/skill-accessibility.d.ts +0 -2
- package/dist/skills/quality/skill-accessibility.d.ts.map +0 -1
- package/dist/skills/quality/skill-accessibility.js +0 -2
- package/dist/skills/quality/skill-accessibility.js.map +0 -1
- package/dist/skills/quality/skill-code-review.d.ts +0 -15
- package/dist/skills/quality/skill-code-review.d.ts.map +0 -1
- package/dist/skills/quality/skill-code-review.js +0 -60
- package/dist/skills/quality/skill-code-review.js.map +0 -1
- package/dist/skills/quality/skill-docs-gen.d.ts +0 -2
- package/dist/skills/quality/skill-docs-gen.d.ts.map +0 -1
- package/dist/skills/quality/skill-docs-gen.js +0 -2
- package/dist/skills/quality/skill-docs-gen.js.map +0 -1
- package/dist/skills/quality/skill-perf-audit.d.ts +0 -2
- package/dist/skills/quality/skill-perf-audit.d.ts.map +0 -1
- package/dist/skills/quality/skill-perf-audit.js +0 -2
- package/dist/skills/quality/skill-perf-audit.js.map +0 -1
- package/dist/skills/quality/skill-security-scan.d.ts +0 -15
- package/dist/skills/quality/skill-security-scan.d.ts.map +0 -1
- package/dist/skills/quality/skill-security-scan.js +0 -67
- package/dist/skills/quality/skill-security-scan.js.map +0 -1
- package/dist/skills/quality/skill-test-suite.d.ts +0 -15
- package/dist/skills/quality/skill-test-suite.d.ts.map +0 -1
- package/dist/skills/quality/skill-test-suite.js +0 -274
- package/dist/skills/quality/skill-test-suite.js.map +0 -1
- package/dist/skills/workflow/skill-deploy.d.ts +0 -2
- package/dist/skills/workflow/skill-deploy.d.ts.map +0 -1
- package/dist/skills/workflow/skill-deploy.js +0 -2
- package/dist/skills/workflow/skill-deploy.js.map +0 -1
- package/dist/skills/workflow/skill-git-workflow.d.ts +0 -2
- package/dist/skills/workflow/skill-git-workflow.d.ts.map +0 -1
- package/dist/skills/workflow/skill-git-workflow.js +0 -2
- package/dist/skills/workflow/skill-git-workflow.js.map +0 -1
- package/dist/skills/workflow/skill-rollback.d.ts +0 -2
- package/dist/skills/workflow/skill-rollback.d.ts.map +0 -1
- package/dist/skills/workflow/skill-rollback.js +0 -2
- package/dist/skills/workflow/skill-rollback.js.map +0 -1
- package/dist/skills/workflow/skill-task-breakdown.d.ts +0 -2
- package/dist/skills/workflow/skill-task-breakdown.d.ts.map +0 -1
- package/dist/skills/workflow/skill-task-breakdown.js +0 -2
- package/dist/skills/workflow/skill-task-breakdown.js.map +0 -1
|
@@ -5,7 +5,7 @@ import { getConfig } from '../memory/config.js';
|
|
|
5
5
|
// ─── Record ───────────────────────────────────────────────────────────────────
|
|
6
6
|
export function recordOutcome(taskType, complexity, modelTier, agent, outputQuality, tokensUsed = 0, fileExt) {
|
|
7
7
|
const db = getDb();
|
|
8
|
-
db.prepare(`INSERT INTO learning_data (id, task_type, complexity, model_tier, output_quality, tokens_used, agent)
|
|
8
|
+
db.prepare(`INSERT INTO learning_data (id, task_type, complexity, model_tier, output_quality, tokens_used, agent)
|
|
9
9
|
VALUES (?, ?, ?, ?, ?, ?, ?)`).run(randomUUID(), taskType, complexity, modelTier, outputQuality, tokensUsed, agent);
|
|
10
10
|
// Predictive routing: track agent quality per file extension and task type keyword
|
|
11
11
|
if (agent && agent !== 'dynamic' && outputQuality > 0) {
|
|
@@ -50,8 +50,8 @@ export function getRecommendedAgent(taskType, fileExt) {
|
|
|
50
50
|
const db = getDb();
|
|
51
51
|
// Try file extension match first (more specific)
|
|
52
52
|
if (fileExt) {
|
|
53
|
-
const rows = db.prepare(`SELECT pattern_key, pattern_val, confidence, seen_count FROM patterns
|
|
54
|
-
WHERE pattern_key LIKE ? AND seen_count >= 3
|
|
53
|
+
const rows = db.prepare(`SELECT pattern_key, pattern_val, confidence, seen_count FROM patterns
|
|
54
|
+
WHERE pattern_key LIKE ? AND seen_count >= 3
|
|
55
55
|
ORDER BY confidence DESC LIMIT 1`).all(`file_agent:${fileExt.toLowerCase()}:%`);
|
|
56
56
|
if (rows.length > 0 && rows[0].confidence >= 0.7)
|
|
57
57
|
return rows[0].pattern_val;
|
|
@@ -59,8 +59,8 @@ export function getRecommendedAgent(taskType, fileExt) {
|
|
|
59
59
|
// Fall back to task keyword match
|
|
60
60
|
const keyword = taskType.toLowerCase().split(/[\s_-]/)[0];
|
|
61
61
|
if (keyword) {
|
|
62
|
-
const rows = db.prepare(`SELECT pattern_key, pattern_val, confidence, seen_count FROM patterns
|
|
63
|
-
WHERE pattern_key LIKE ? AND seen_count >= 3
|
|
62
|
+
const rows = db.prepare(`SELECT pattern_key, pattern_val, confidence, seen_count FROM patterns
|
|
63
|
+
WHERE pattern_key LIKE ? AND seen_count >= 3
|
|
64
64
|
ORDER BY confidence DESC LIMIT 1`).all(`task_agent:${keyword}:%`);
|
|
65
65
|
if (rows.length > 0 && rows[0].confidence >= 0.7)
|
|
66
66
|
return rows[0].pattern_val;
|
|
@@ -70,7 +70,7 @@ export function getRecommendedAgent(taskType, fileExt) {
|
|
|
70
70
|
// ─── Stats ────────────────────────────────────────────────────────────────────
|
|
71
71
|
export function getLearningStats() {
|
|
72
72
|
const db = getDb();
|
|
73
|
-
const rows = db.prepare(`SELECT model_tier, COUNT(*) as count, AVG(output_quality) as avg_quality
|
|
73
|
+
const rows = db.prepare(`SELECT model_tier, COUNT(*) as count, AVG(output_quality) as avg_quality
|
|
74
74
|
FROM learning_data GROUP BY model_tier`).all();
|
|
75
75
|
const total_tasks = rows.reduce((sum, r) => sum + r.count, 0);
|
|
76
76
|
const tier_breakdown = {};
|
|
@@ -85,16 +85,16 @@ export function getLearningStats() {
|
|
|
85
85
|
}
|
|
86
86
|
export function getAgentPerformanceStats() {
|
|
87
87
|
const db = getDb();
|
|
88
|
-
const rows = db.prepare(`
|
|
89
|
-
SELECT agent,
|
|
90
|
-
COUNT(*) as task_count,
|
|
91
|
-
AVG(output_quality) as avg_quality,
|
|
92
|
-
AVG(tokens_used) as avg_tokens,
|
|
93
|
-
SUM(CASE WHEN output_quality < 60 THEN 1 ELSE 0 END) as low_quality_count
|
|
94
|
-
FROM learning_data
|
|
95
|
-
WHERE agent IS NOT NULL
|
|
96
|
-
GROUP BY agent
|
|
97
|
-
ORDER BY avg_quality ASC
|
|
88
|
+
const rows = db.prepare(`
|
|
89
|
+
SELECT agent,
|
|
90
|
+
COUNT(*) as task_count,
|
|
91
|
+
AVG(output_quality) as avg_quality,
|
|
92
|
+
AVG(tokens_used) as avg_tokens,
|
|
93
|
+
SUM(CASE WHEN output_quality < 60 THEN 1 ELSE 0 END) as low_quality_count
|
|
94
|
+
FROM learning_data
|
|
95
|
+
WHERE agent IS NOT NULL
|
|
96
|
+
GROUP BY agent
|
|
97
|
+
ORDER BY avg_quality ASC
|
|
98
98
|
`).all();
|
|
99
99
|
return rows.map(r => ({
|
|
100
100
|
agent: r.agent,
|
|
@@ -107,23 +107,23 @@ export function getAgentPerformanceStats() {
|
|
|
107
107
|
}
|
|
108
108
|
export function getTaskTypeBreakdown() {
|
|
109
109
|
const db = getDb();
|
|
110
|
-
const rows = db.prepare(`
|
|
111
|
-
SELECT task_type,
|
|
112
|
-
COUNT(*) as count,
|
|
113
|
-
AVG(complexity) as avg_complexity,
|
|
114
|
-
AVG(output_quality) as avg_quality,
|
|
115
|
-
model_tier as dominant_tier
|
|
116
|
-
FROM learning_data
|
|
117
|
-
GROUP BY task_type, model_tier
|
|
118
|
-
HAVING COUNT(*) = (
|
|
119
|
-
SELECT MAX(c) FROM (
|
|
120
|
-
SELECT COUNT(*) as c FROM learning_data l2
|
|
121
|
-
WHERE l2.task_type = learning_data.task_type
|
|
122
|
-
GROUP BY l2.model_tier
|
|
123
|
-
)
|
|
124
|
-
)
|
|
125
|
-
ORDER BY count DESC
|
|
126
|
-
LIMIT 50
|
|
110
|
+
const rows = db.prepare(`
|
|
111
|
+
SELECT task_type,
|
|
112
|
+
COUNT(*) as count,
|
|
113
|
+
AVG(complexity) as avg_complexity,
|
|
114
|
+
AVG(output_quality) as avg_quality,
|
|
115
|
+
model_tier as dominant_tier
|
|
116
|
+
FROM learning_data
|
|
117
|
+
GROUP BY task_type, model_tier
|
|
118
|
+
HAVING COUNT(*) = (
|
|
119
|
+
SELECT MAX(c) FROM (
|
|
120
|
+
SELECT COUNT(*) as c FROM learning_data l2
|
|
121
|
+
WHERE l2.task_type = learning_data.task_type
|
|
122
|
+
GROUP BY l2.model_tier
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
ORDER BY count DESC
|
|
126
|
+
LIMIT 50
|
|
127
127
|
`).all();
|
|
128
128
|
return rows.map(r => {
|
|
129
129
|
// Under-tiered: task scored high quality but at a tier below what complexity suggests
|
|
@@ -142,15 +142,15 @@ export function getTaskTypeBreakdown() {
|
|
|
142
142
|
export function getCouncilInsights() {
|
|
143
143
|
const db = getDb();
|
|
144
144
|
// Correlate council approvals (GREEN/YELLOW) with debugging sessions that came after
|
|
145
|
-
const rows = db.prepare(`
|
|
146
|
-
SELECT co.verdict, co.task, co.debated_at,
|
|
147
|
-
d.decision as related_decision, d.made_at as decision_at
|
|
148
|
-
FROM council_outcomes co
|
|
149
|
-
LEFT JOIN decisions d ON d.session_id = co.session_id
|
|
150
|
-
AND d.decision LIKE '%debug%' OR d.decision LIKE '%fix%' OR d.decision LIKE '%bug%'
|
|
151
|
-
WHERE co.verdict IN ('GREEN', 'YELLOW')
|
|
152
|
-
ORDER BY co.debated_at DESC
|
|
153
|
-
LIMIT 30
|
|
145
|
+
const rows = db.prepare(`
|
|
146
|
+
SELECT co.verdict, co.task, co.debated_at,
|
|
147
|
+
d.decision as related_decision, d.made_at as decision_at
|
|
148
|
+
FROM council_outcomes co
|
|
149
|
+
LEFT JOIN decisions d ON d.session_id = co.session_id
|
|
150
|
+
AND d.decision LIKE '%debug%' OR d.decision LIKE '%fix%' OR d.decision LIKE '%bug%'
|
|
151
|
+
WHERE co.verdict IN ('GREEN', 'YELLOW')
|
|
152
|
+
ORDER BY co.debated_at DESC
|
|
153
|
+
LIMIT 30
|
|
154
154
|
`).all();
|
|
155
155
|
return rows.map(r => {
|
|
156
156
|
let days_to_debug = null;
|
|
@@ -273,9 +273,9 @@ export function recordRoutingFeedback(opts) {
|
|
|
273
273
|
const now = new Date().toISOString();
|
|
274
274
|
const expiresAt = new Date(Date.now() + FEEDBACK_TTL_DAYS * 86_400_000).toISOString();
|
|
275
275
|
const task_hash = opts.task.toLowerCase().replace(/\s+/g, '_').slice(0, 40);
|
|
276
|
-
db.prepare(`
|
|
277
|
-
INSERT INTO routing_feedback (id, task_hash, task_snippet, complexity, model_tier, agent, outcome, session_id, recorded_at, expires_at)
|
|
278
|
-
VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?)
|
|
276
|
+
db.prepare(`
|
|
277
|
+
INSERT INTO routing_feedback (id, task_hash, task_snippet, complexity, model_tier, agent, outcome, session_id, recorded_at, expires_at)
|
|
278
|
+
VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?)
|
|
279
279
|
`).run(id, task_hash, opts.task.slice(0, 100), opts.complexity, opts.model_tier, opts.agent ?? null, opts.session_id ?? null, now, expiresAt);
|
|
280
280
|
return id;
|
|
281
281
|
}
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Veto MCP Server —
|
|
2
|
+
// Veto MCP Server — 93 tools, LLM council + auto-learning router
|
|
3
3
|
// Suppress node:sqlite experimental warning — it would corrupt the MCP stdio protocol
|
|
4
4
|
process.removeAllListeners('warning');
|
|
5
5
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
package/dist/tools/compact.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Compact tool surface — progressive disclosure for clients where
|
|
2
|
-
// schemas would burn ~
|
|
1
|
+
// Compact tool surface — progressive disclosure for clients where 93 tool
|
|
2
|
+
// schemas would burn ~20K context tokens before the user types a word.
|
|
3
3
|
//
|
|
4
4
|
// In compact mode (VETO_COMPACT=1 or config compact_tools=true) ListTools
|
|
5
5
|
// exposes only a small first-class set plus two meta-tools: veto_find_tools
|
|
@@ -22,7 +22,7 @@ const FIRST_CLASS = [
|
|
|
22
22
|
export const META_TOOL_DEFINITIONS = [
|
|
23
23
|
{
|
|
24
24
|
name: 'veto_find_tools',
|
|
25
|
-
description: 'Searches the full Veto catalog (
|
|
25
|
+
description: 'Searches the full Veto catalog (93 tools: agents, reviews, advisors, generators, memory, learning, git, workflow) by keyword and returns matching tool schemas. Compact mode exposes only core tools up front — call this first to discover the right tool, then invoke it via veto_call.',
|
|
26
26
|
inputSchema: {
|
|
27
27
|
type: 'object',
|
|
28
28
|
properties: {
|
|
@@ -79,14 +79,14 @@ export async function captureSession(opts = {}) {
|
|
|
79
79
|
if (existing) {
|
|
80
80
|
// Content changed (grew): overwrite the row, reset the index watermark AND
|
|
81
81
|
// parser_version so Step 6 re-derives events from the new bytes.
|
|
82
|
-
db.prepare(`UPDATE archives SET archive_path=?, content_sha256=?, source_bytes=?, archive_bytes=?,
|
|
83
|
-
project_dir=COALESCE(?, project_dir), veto_session_id=COALESCE(?, veto_session_id),
|
|
82
|
+
db.prepare(`UPDATE archives SET archive_path=?, content_sha256=?, source_bytes=?, archive_bytes=?,
|
|
83
|
+
project_dir=COALESCE(?, project_dir), veto_session_id=COALESCE(?, veto_session_id),
|
|
84
84
|
updated_at=?, indexed_through_seq=0, parser_version=0 WHERE id=?`).run(archivePath, sha256, bytes, archiveBytes, proj, opts.vetoSessionId ?? null, now, id);
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
db.prepare(`INSERT INTO archives (id, source, source_session_id, project_dir, veto_session_id, archive_path,
|
|
88
|
-
content_sha256, source_bytes, archive_bytes, source_format_hint, parser_version, indexed_through_seq,
|
|
89
|
-
captured_at, updated_at)
|
|
87
|
+
db.prepare(`INSERT INTO archives (id, source, source_session_id, project_dir, veto_session_id, archive_path,
|
|
88
|
+
content_sha256, source_bytes, archive_bytes, source_format_hint, parser_version, indexed_through_seq,
|
|
89
|
+
captured_at, updated_at)
|
|
90
90
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, ?, ?)`).run(id, source, sessionId, proj, opts.vetoSessionId ?? null, archivePath, sha256, bytes, archiveBytes, formatHint, now, now);
|
|
91
91
|
}
|
|
92
92
|
return {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type DocCache = {
|
|
2
|
+
/** Highest doc id; arrays below are indexed by doc id, so length is maxId+1. */
|
|
3
|
+
maxId: number;
|
|
4
|
+
/** Token count per doc, for BM25 length normalization. */
|
|
5
|
+
len: Int32Array;
|
|
6
|
+
project: (string | null)[];
|
|
7
|
+
session: string[];
|
|
8
|
+
/** Doc count and average length, for BM25's corpus statistics. */
|
|
9
|
+
count: number;
|
|
10
|
+
avgdl: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* How many leading dimensions the cheap first pass scores.
|
|
14
|
+
*
|
|
15
|
+
* potion applies PCA, so dimensions arrive ordered by variance and a prefix is
|
|
16
|
+
* unusually informative. Scoring a prefix costs a quarter of a full dot
|
|
17
|
+
* product and, combined with the tail norm, yields an exact upper bound via
|
|
18
|
+
* Cauchy-Schwarz: |tail contribution| <= ||q_tail|| * ||d_tail||. Chunks whose
|
|
19
|
+
* BEST possible score cannot reach the current cutoff are skipped without ever
|
|
20
|
+
* being fully scored — exact, never a recall loss, unlike an ANN index.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PREFIX_DIMS = 64;
|
|
23
|
+
export type VectorCache = {
|
|
24
|
+
dim: number;
|
|
25
|
+
count: number;
|
|
26
|
+
/** count * dim, row-major — one contiguous allocation, not one per chunk. */
|
|
27
|
+
data: Int8Array;
|
|
28
|
+
/** L2 norm of each int8 row. */
|
|
29
|
+
norms: Float32Array;
|
|
30
|
+
/** L2 norm of dims [PREFIX_DIMS, dim) per row — the tail a prefix scan has
|
|
31
|
+
* not yet seen. Enables an exact Cauchy-Schwarz bound (see PREFIX_DIMS). */
|
|
32
|
+
tailNorms: Float32Array;
|
|
33
|
+
docIds: Int32Array;
|
|
34
|
+
chunkIdx: Int32Array;
|
|
35
|
+
};
|
|
36
|
+
/** Drop both caches. MUST be called after anything that mutates the index. */
|
|
37
|
+
export declare function resetCaches(): void;
|
|
38
|
+
export declare function getDocCache(): DocCache;
|
|
39
|
+
export declare function getVectorCache(): VectorCache;
|
|
40
|
+
/**
|
|
41
|
+
* A lookup table of in-scope doc ids, built from the cached metadata rather
|
|
42
|
+
* than a per-query SQL round trip. Returns null when no filter applies.
|
|
43
|
+
*
|
|
44
|
+
* Memoized per scope: building it walks every doc id doing string comparisons,
|
|
45
|
+
* which at 41k docs is a real per-query cost, and consecutive queries almost
|
|
46
|
+
* always share a scope. Cleared with the caches it is derived from.
|
|
47
|
+
*/
|
|
48
|
+
export declare function scopeMask(docs: DocCache, opts: {
|
|
49
|
+
projectDir?: string;
|
|
50
|
+
sourceSessionId?: string;
|
|
51
|
+
}): Uint8Array | null;
|
|
52
|
+
/**
|
|
53
|
+
* Reusable per-document accumulators for the vector scan.
|
|
54
|
+
*
|
|
55
|
+
* Allocating these per query costs hundreds of kilobytes of zero-fill on every
|
|
56
|
+
* search. They are handed back dirty by contract — the caller resets only the
|
|
57
|
+
* entries it touched, which is proportional to matches rather than to the id
|
|
58
|
+
* space.
|
|
59
|
+
*/
|
|
60
|
+
export declare function scoreScratch(maxId: number): {
|
|
61
|
+
score: Float32Array;
|
|
62
|
+
chunk: Int32Array;
|
|
63
|
+
};
|
|
64
|
+
/** Sentinel for "this document has not been scored in this query". */
|
|
65
|
+
export declare const EMPTY_SCORE = -2;
|
|
66
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/transcripts/cache.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,QAAQ,GAAG;IACrB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,EAAE,SAAS,CAAC;IAChB,gCAAgC;IAChC,KAAK,EAAE,YAAY,CAAC;IACpB;iFAC6E;IAC7E,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AAKF,8EAA8E;AAC9E,wBAAgB,WAAW,IAAI,IAAI,CAMlC;AAED,wBAAgB,WAAW,IAAI,QAAQ,CA8BtC;AAED,wBAAgB,cAAc,IAAI,WAAW,CAkC5C;AAID;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,UAAU,GAAG,IAAI,CAcnB;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG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;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC;QACvD,aAAa,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9D,aAAa,GAAG,IAAI,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAc,EAAE,CAAC;AACzD,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Bump on ANY boundary change — forces stored vectors to be re-derived. */
|
|
2
|
+
export declare const CHUNKER_VERSION = 1;
|
|
3
|
+
/** Validated by the paraphrase-gate prototype. Not a tuning knob: changing
|
|
4
|
+
* these invalidates the experiment that justified the semantic layer. */
|
|
5
|
+
export declare const WINDOW_CHARS = 240;
|
|
6
|
+
export declare const STRIDE_CHARS = 120;
|
|
7
|
+
/** Input-size guard, not a tuning knob (C2). A pathological event must not be
|
|
8
|
+
* able to emit unbounded rows; the tail is dropped and stays lexically
|
|
9
|
+
* searchable via BM25, which indexes the whole text regardless. */
|
|
10
|
+
export declare const MAX_WINDOWS_PER_EVENT = 64;
|
|
11
|
+
export type Chunk = {
|
|
12
|
+
index: number;
|
|
13
|
+
/** UTF-16 offsets into the source text, so a hit can aim a snippet (C6). */
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Split `text` into overlapping windows.
|
|
20
|
+
*
|
|
21
|
+
* Events at or under the window emit exactly one chunk covering the whole
|
|
22
|
+
* text — the median event is ~205 chars, so most events produce a single row
|
|
23
|
+
* and the vector count stays proportional to content, not to event count.
|
|
24
|
+
*/
|
|
25
|
+
export declare function chunkText(text: string): Chunk[];
|
|
26
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/transcripts/chunk.ts"],"names":[],"mappings":"AAYA,4EAA4E;AAC5E,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;0EAC0E;AAC1E,eAAO,MAAM,YAAY,MAAM,CAAC;AAChC,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC;;oEAEoE;AACpE,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAWF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CAc/C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Chunking for the semantic layer (VERSION-3 item 6, Phase B).
|
|
2
|
+
//
|
|
3
|
+
// One vector per event demonstrably FAILS the paraphrase gate: mean-pooling a
|
|
4
|
+
// 1,936-char event dilutes the one sentence that answers the question down to
|
|
5
|
+
// ~5% of the vector, and it never surfaces. Splitting events into overlapping
|
|
6
|
+
// windows and scoring each event by its BEST window fixed that — the whole
|
|
7
|
+
// reason this file exists (council outcome 9b0595ad, spec §11 amendment).
|
|
8
|
+
//
|
|
9
|
+
// Boundaries here are a compatibility surface: they are pinned by golden tests
|
|
10
|
+
// (C1), and CHUNKER_VERSION must be bumped if any of it changes, because
|
|
11
|
+
// stored vectors are only meaningful against the chunker that produced them.
|
|
12
|
+
/** Bump on ANY boundary change — forces stored vectors to be re-derived. */
|
|
13
|
+
export const CHUNKER_VERSION = 1;
|
|
14
|
+
/** Validated by the paraphrase-gate prototype. Not a tuning knob: changing
|
|
15
|
+
* these invalidates the experiment that justified the semantic layer. */
|
|
16
|
+
export const WINDOW_CHARS = 240;
|
|
17
|
+
export const STRIDE_CHARS = 120;
|
|
18
|
+
/** Input-size guard, not a tuning knob (C2). A pathological event must not be
|
|
19
|
+
* able to emit unbounded rows; the tail is dropped and stays lexically
|
|
20
|
+
* searchable via BM25, which indexes the whole text regardless. */
|
|
21
|
+
export const MAX_WINDOWS_PER_EVENT = 64;
|
|
22
|
+
/** Never split a surrogate pair: a lone surrogate would corrupt normalization
|
|
23
|
+
* and produce a vector for text that does not exist. Boundaries move forward
|
|
24
|
+
* off a low surrogate, which keeps the result deterministic. */
|
|
25
|
+
function safeBoundary(text, i) {
|
|
26
|
+
if (i <= 0 || i >= text.length)
|
|
27
|
+
return i;
|
|
28
|
+
const c = text.charCodeAt(i);
|
|
29
|
+
return c >= 0xdc00 && c <= 0xdfff ? i + 1 : i;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Split `text` into overlapping windows.
|
|
33
|
+
*
|
|
34
|
+
* Events at or under the window emit exactly one chunk covering the whole
|
|
35
|
+
* text — the median event is ~205 chars, so most events produce a single row
|
|
36
|
+
* and the vector count stays proportional to content, not to event count.
|
|
37
|
+
*/
|
|
38
|
+
export function chunkText(text) {
|
|
39
|
+
if (text.length === 0)
|
|
40
|
+
return [];
|
|
41
|
+
if (text.length <= WINDOW_CHARS) {
|
|
42
|
+
return [{ index: 0, start: 0, end: text.length, text }];
|
|
43
|
+
}
|
|
44
|
+
const out = [];
|
|
45
|
+
for (let raw = 0; raw < text.length && out.length < MAX_WINDOWS_PER_EVENT; raw += STRIDE_CHARS) {
|
|
46
|
+
const start = safeBoundary(text, raw);
|
|
47
|
+
const end = safeBoundary(text, Math.min(start + WINDOW_CHARS, text.length));
|
|
48
|
+
out.push({ index: out.length, start, end, text: text.slice(start, end) });
|
|
49
|
+
if (end >= text.length)
|
|
50
|
+
break;
|
|
51
|
+
}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IAC1D,CAAC;IAED,MAAM,GAAG,GAAY,EAAE,CAAC;IACxB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,qBAAqB,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/F,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5E,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1E,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type Header = {
|
|
2
|
+
format: string;
|
|
3
|
+
upstream: {
|
|
4
|
+
model_id: string;
|
|
5
|
+
revision: string;
|
|
6
|
+
};
|
|
7
|
+
vocab_size: number;
|
|
8
|
+
dim: number;
|
|
9
|
+
inference: {
|
|
10
|
+
add_special_tokens: boolean;
|
|
11
|
+
pooling: string;
|
|
12
|
+
normalize: boolean;
|
|
13
|
+
per_token_weights: unknown;
|
|
14
|
+
};
|
|
15
|
+
tokenizer: {
|
|
16
|
+
strip_accents_effective: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type Model = {
|
|
20
|
+
header: Header;
|
|
21
|
+
dim: number;
|
|
22
|
+
/** Row-major int8 table, vocab_size * dim. */
|
|
23
|
+
table: Int8Array;
|
|
24
|
+
/** One scale per row: row_f32 = table[row] * scales[row]. */
|
|
25
|
+
scales: Float32Array;
|
|
26
|
+
vocab: Map<string, number>;
|
|
27
|
+
unkId: number | undefined;
|
|
28
|
+
prefix: string;
|
|
29
|
+
maxWordChars: number;
|
|
30
|
+
lowercase: boolean;
|
|
31
|
+
stripAccents: boolean;
|
|
32
|
+
cleanText: boolean;
|
|
33
|
+
handleChineseChars: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Token ids for `text`, with no special tokens added (the shipped contract). */
|
|
36
|
+
export declare function tokenizeForEmbedding(text: string, model?: Model): number[];
|
|
37
|
+
/**
|
|
38
|
+
* Embed `text` into a unit-length vector.
|
|
39
|
+
*
|
|
40
|
+
* Gather each token's row, dequantize it by that row's scale, mean-pool, then
|
|
41
|
+
* L2-normalize. Text with no tokens (empty or punctuation-free-of-vocab)
|
|
42
|
+
* yields the zero vector rather than NaN — upstream's behaviour, and the
|
|
43
|
+
* reason the epsilon is in the denominator.
|
|
44
|
+
*/
|
|
45
|
+
export declare function embed(text: string, model?: Model): Float32Array;
|
|
46
|
+
/** Cosine similarity of two unit vectors — a dot product, given the inputs. */
|
|
47
|
+
export declare function cosine(a: Float32Array, b: Float32Array): number;
|
|
48
|
+
/** True when the model package resolves and its payload passes validation. */
|
|
49
|
+
export declare function embeddingsAvailable(): boolean;
|
|
50
|
+
/** Upstream model id + revision of the loaded payload, for recall provenance. */
|
|
51
|
+
export declare function modelProvenance(): {
|
|
52
|
+
model_id: string;
|
|
53
|
+
revision: string;
|
|
54
|
+
};
|
|
55
|
+
/** Drop the cached table. Tests only — production loads once per process. */
|
|
56
|
+
export declare function resetModelCache(): void;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/transcripts/embed.ts"],"names":[],"mappings":"AA6BA,KAAK,MAAM,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QAAE,QAAQ,E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