valent-pipeline 0.1.14 → 0.1.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valent-pipeline",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "v3 multi-agent AI pipeline for software development lifecycle",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env npx tsx
2
+ /**
3
+ * query-kb.ts — Query the pipeline knowledge database from the command line.
4
+ * Used by the Knowledge Agent to answer queries without writing SQL directly.
5
+ *
6
+ * Usage:
7
+ * # Get a specific artifact:
8
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --artifact --story KANBAN-001 --type reqs-brief
9
+ *
10
+ * # Get correction directives for an agent:
11
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --directives --agent BEND
12
+ *
13
+ * # Full-text search across all artifacts:
14
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --search "acceptance criteria for auth"
15
+ *
16
+ * # List all artifacts for a story:
17
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --list --story KANBAN-001
18
+ *
19
+ * # List all stories in the database:
20
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --stories
21
+ *
22
+ * # Get bugs since a date:
23
+ * npx tsx .valent-pipeline/scripts/query-kb.ts --bugs-since 2026-03-01
24
+ *
25
+ * # DB path defaults to .valent-pipeline/pipeline.db, override with --db-path
26
+ */
27
+
28
+ import Database from 'better-sqlite3';
29
+ import { existsSync } from 'fs';
30
+
31
+ const args = process.argv.slice(2);
32
+ const flags: Record<string, string> = {};
33
+ const modes: string[] = [];
34
+
35
+ for (let i = 0; i < args.length; i++) {
36
+ if (args[i].startsWith('--')) {
37
+ const key = args[i].slice(2);
38
+ if (['artifact', 'directives', 'search', 'list', 'stories', 'bugs-since'].includes(key)) {
39
+ if (key === 'search' || key === 'bugs-since') {
40
+ modes.push(key);
41
+ flags[key] = args[++i];
42
+ } else {
43
+ modes.push(key);
44
+ }
45
+ } else if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
46
+ flags[key] = args[++i];
47
+ }
48
+ }
49
+ }
50
+
51
+ const dbPath = flags['db-path'] || '.valent-pipeline/pipeline.db';
52
+
53
+ if (!existsSync(dbPath)) {
54
+ console.error(`Database not found: ${dbPath}`);
55
+ console.error('Run "valent-pipeline db init" to create it.');
56
+ process.exit(1);
57
+ }
58
+
59
+ const db = new Database(dbPath, { readonly: true });
60
+ const mode = modes[0];
61
+
62
+ if (!mode) {
63
+ console.error('Usage: query-kb.ts --artifact|--directives|--search|--list|--stories|--bugs-since');
64
+ process.exit(1);
65
+ }
66
+
67
+ switch (mode) {
68
+ case 'artifact': {
69
+ const storyId = flags['story'];
70
+ const type = flags['type'];
71
+ if (!storyId || !type) {
72
+ console.error('--artifact requires --story and --type');
73
+ process.exit(1);
74
+ }
75
+ const row = db.prepare(
76
+ 'SELECT content, agent, created_at FROM artifacts WHERE story_id = ? AND artifact_type = ?'
77
+ ).get(storyId, type) as { content: string; agent: string; created_at: string } | undefined;
78
+ if (row) {
79
+ console.log(`--- ${type} for ${storyId} (by ${row.agent}, ${row.created_at}) ---`);
80
+ console.log(row.content);
81
+ } else {
82
+ console.log(`No artifact found: story=${storyId}, type=${type}`);
83
+ }
84
+ break;
85
+ }
86
+
87
+ case 'directives': {
88
+ const agent = flags['agent'];
89
+ let rows;
90
+ if (agent) {
91
+ rows = db.prepare(
92
+ "SELECT id, directive, reason FROM correction_directives WHERE target_agent = ? AND status = 'active'"
93
+ ).all(agent) as { id: string; directive: string; reason: string }[];
94
+ } else {
95
+ rows = db.prepare(
96
+ "SELECT id, target_agent, directive, reason FROM correction_directives WHERE status = 'active'"
97
+ ).all() as { id: string; target_agent: string; directive: string; reason: string }[];
98
+ }
99
+ if (rows.length === 0) {
100
+ console.log(agent ? `No active directives for ${agent}` : 'No active correction directives');
101
+ } else {
102
+ for (const r of rows) {
103
+ const target = 'target_agent' in r ? ` [${r.target_agent}]` : '';
104
+ console.log(`${r.id}${target}: ${r.directive}`);
105
+ if (r.reason) console.log(` Reason: ${r.reason}`);
106
+ }
107
+ }
108
+ break;
109
+ }
110
+
111
+ case 'search': {
112
+ const query = flags['search'];
113
+ if (!query) {
114
+ console.error('--search requires a search term');
115
+ process.exit(1);
116
+ }
117
+ const rows = db.prepare(
118
+ "SELECT story_id, agent, artifact_type, snippet(artifacts_fts, 0, '>>>', '<<<', '...', 40) as snippet FROM artifacts_fts WHERE artifacts_fts MATCH ? ORDER BY rank LIMIT 10"
119
+ ).all(query) as { story_id: string; agent: string; artifact_type: string; snippet: string }[];
120
+ if (rows.length === 0) {
121
+ console.log(`No results for: ${query}`);
122
+ } else {
123
+ for (const r of rows) {
124
+ console.log(`[${r.story_id}] ${r.artifact_type} (${r.agent}): ${r.snippet}`);
125
+ }
126
+ }
127
+ break;
128
+ }
129
+
130
+ case 'list': {
131
+ const storyId = flags['story'];
132
+ if (!storyId) {
133
+ console.error('--list requires --story');
134
+ process.exit(1);
135
+ }
136
+ const rows = db.prepare(
137
+ 'SELECT artifact_type, agent, length(content) as size, created_at FROM artifacts WHERE story_id = ? ORDER BY created_at'
138
+ ).all(storyId) as { artifact_type: string; agent: string; size: number; created_at: string }[];
139
+ if (rows.length === 0) {
140
+ console.log(`No artifacts for story ${storyId}`);
141
+ } else {
142
+ console.log(`Artifacts for ${storyId}:`);
143
+ for (const r of rows) {
144
+ console.log(` ${r.artifact_type} (${r.agent}, ${r.size} chars, ${r.created_at})`);
145
+ }
146
+ }
147
+ break;
148
+ }
149
+
150
+ case 'stories': {
151
+ const rows = db.prepare(
152
+ 'SELECT DISTINCT story_id, COUNT(*) as artifact_count FROM artifacts GROUP BY story_id ORDER BY story_id'
153
+ ).all() as { story_id: string; artifact_count: number }[];
154
+ if (rows.length === 0) {
155
+ console.log('No stories in database');
156
+ } else {
157
+ for (const r of rows) {
158
+ console.log(`${r.story_id}: ${r.artifact_count} artifacts`);
159
+ }
160
+ }
161
+ break;
162
+ }
163
+
164
+ case 'bugs-since': {
165
+ const since = flags['bugs-since'];
166
+ if (!since) {
167
+ console.error('--bugs-since requires a date (YYYY-MM-DD)');
168
+ process.exit(1);
169
+ }
170
+ const rows = db.prepare(
171
+ "SELECT story_id, content FROM artifacts WHERE artifact_type = 'bugs' AND created_at > ? ORDER BY created_at"
172
+ ).all(since) as { story_id: string; content: string }[];
173
+ if (rows.length === 0) {
174
+ console.log(`No bugs filed since ${since}`);
175
+ } else {
176
+ for (const r of rows) {
177
+ console.log(`--- Bugs from ${r.story_id} ---`);
178
+ console.log(r.content);
179
+ }
180
+ }
181
+ break;
182
+ }
183
+ }
184
+
185
+ db.close();
@@ -74,9 +74,29 @@ export async function init(options = {}) {
74
74
  console.log(' Created knowledge/correction-directives.yaml');
75
75
  }
76
76
 
77
- // 7. Initialize SQLite DB if sqlite mode
77
+ // 7. Install SQLite dependencies inside .valent-pipeline/
78
78
  if (config.knowledge?.mode === 'sqlite') {
79
- console.log(' SQLite knowledge mode selected. Run "valent-pipeline db init" to create the database.');
79
+ const vpPkgPath = join(pipelineDest, 'package.json');
80
+ if (!fileExists(vpPkgPath)) {
81
+ writeFileSafe(vpPkgPath, JSON.stringify({
82
+ "name": "valent-pipeline-runtime",
83
+ "private": true,
84
+ "description": "Runtime dependencies for valent-pipeline scripts. Do not edit.",
85
+ "dependencies": {
86
+ "better-sqlite3": "^11.0.0",
87
+ "sqlite-vec": "^0.1.0"
88
+ }
89
+ }, null, 2) + '\n');
90
+ }
91
+ console.log(' Installing SQLite dependencies in .valent-pipeline/...');
92
+ const { execSync } = await import('child_process');
93
+ try {
94
+ execSync('npm install --production', { cwd: pipelineDest, stdio: 'pipe' });
95
+ console.log(' Installed better-sqlite3 + sqlite-vec');
96
+ } catch (err) {
97
+ console.warn(' Warning: Failed to install SQLite dependencies. Run "cd .valent-pipeline && npm install" manually.');
98
+ }
99
+ console.log(' Run "valent-pipeline db init" to create the database.');
80
100
  }
81
101
 
82
102
  // 8. Configure Claude settings for agent teams