@vibeflow-tools/cli 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/chunk-GEQ64RVF.js +7 -0
  3. package/dist/chunk-IUZWZWMW.js +7 -0
  4. package/dist/chunk-NRMCK2HM.js +7 -0
  5. package/dist/chunk-PCPVP4ZD.js +7 -0
  6. package/dist/chunk-XO547RIH.js +7 -0
  7. package/dist/cli/chunk-GEQ64RVF.js +7 -0
  8. package/dist/cli/chunk-IUZWZWMW.js +7 -0
  9. package/dist/cli/chunk-NRMCK2HM.js +7 -0
  10. package/dist/cli/chunk-PCPVP4ZD.js +7 -0
  11. package/dist/cli/chunk-XO547RIH.js +7 -0
  12. package/dist/cli/files-GOVXPMB5.js +2 -0
  13. package/dist/cli/files-LTK2TDC2.js +2 -0
  14. package/dist/cli/files-MEEV7E6V.js +2 -0
  15. package/dist/cli/files-R6YCYMTI.js +2 -0
  16. package/dist/cli/files-SUCOSQAO.js +2 -0
  17. package/dist/cli/index.js +384 -197
  18. package/dist/client/kanban-browser.js +23 -12
  19. package/dist/client/kanban.css +1 -1
  20. package/dist/client/overlay-browser.js +5 -4
  21. package/dist/files-GOVXPMB5.js +2 -0
  22. package/dist/files-LTK2TDC2.js +2 -0
  23. package/dist/files-MEEV7E6V.js +2 -0
  24. package/dist/files-R6YCYMTI.js +2 -0
  25. package/dist/files-SUCOSQAO.js +2 -0
  26. package/dist/index.js +384 -197
  27. package/package.json +7 -2
  28. package/dist/chunk-252RNKHM.js +0 -2
  29. package/dist/chunk-43MUGU6Z.js +0 -67
  30. package/dist/chunk-4Y62J4KR.js +0 -438
  31. package/dist/chunk-6ABTC7IA.js +0 -482
  32. package/dist/chunk-7K2VHAWF.js +0 -569
  33. package/dist/chunk-BKTZSHJS.js +0 -2
  34. package/dist/chunk-BQLZVQ4E.js +0 -2
  35. package/dist/chunk-F57OXWVU.js +0 -33
  36. package/dist/chunk-I2OSZY66.js +0 -803
  37. package/dist/chunk-JKC6MUZ4.js +0 -558
  38. package/dist/chunk-KKBXVPTJ.js +0 -2
  39. package/dist/chunk-LK3IGDR6.js +0 -438
  40. package/dist/chunk-MKOKIWTN.js +0 -569
  41. package/dist/chunk-MW4OS3IK.js +0 -438
  42. package/dist/chunk-NRPOXSY6.js +0 -568
  43. package/dist/chunk-NUM3G22J.js +0 -569
  44. package/dist/chunk-O564QSMS.js +0 -569
  45. package/dist/chunk-OAGEPYIT.js +0 -535
  46. package/dist/chunk-PHBHAIHA.js +0 -33
  47. package/dist/chunk-PK737AKV.js +0 -560
  48. package/dist/chunk-TWAAPROG.js +0 -822
  49. package/dist/chunk-XF2CNPE4.js +0 -803
  50. package/dist/cli/chunk-252RNKHM.js +0 -2
  51. package/dist/cli/chunk-43MUGU6Z.js +0 -67
  52. package/dist/cli/chunk-4Y62J4KR.js +0 -438
  53. package/dist/cli/chunk-6ABTC7IA.js +0 -482
  54. package/dist/cli/chunk-7K2VHAWF.js +0 -569
  55. package/dist/cli/chunk-BKTZSHJS.js +0 -2
  56. package/dist/cli/chunk-BQLZVQ4E.js +0 -2
  57. package/dist/cli/chunk-F57OXWVU.js +0 -33
  58. package/dist/cli/chunk-I2OSZY66.js +0 -803
  59. package/dist/cli/chunk-JKC6MUZ4.js +0 -558
  60. package/dist/cli/chunk-KKBXVPTJ.js +0 -2
  61. package/dist/cli/chunk-LK3IGDR6.js +0 -438
  62. package/dist/cli/chunk-MKOKIWTN.js +0 -569
  63. package/dist/cli/chunk-MW4OS3IK.js +0 -438
  64. package/dist/cli/chunk-NRPOXSY6.js +0 -568
  65. package/dist/cli/chunk-NUM3G22J.js +0 -569
  66. package/dist/cli/chunk-O564QSMS.js +0 -569
  67. package/dist/cli/chunk-OAGEPYIT.js +0 -535
  68. package/dist/cli/chunk-PHBHAIHA.js +0 -33
  69. package/dist/cli/chunk-PK737AKV.js +0 -560
  70. package/dist/cli/chunk-TWAAPROG.js +0 -822
  71. package/dist/cli/chunk-XF2CNPE4.js +0 -803
  72. package/dist/cli/files-27OYPA7W.js +0 -20
  73. package/dist/cli/files-2TK74THO.js +0 -22
  74. package/dist/cli/files-3RDDXUOS.js +0 -2
  75. package/dist/cli/files-7275M2PW.js +0 -20
  76. package/dist/cli/files-D3YPV7QT.js +0 -20
  77. package/dist/cli/files-FER4UZ4X.js +0 -22
  78. package/dist/cli/files-H4FRDKJV.js +0 -22
  79. package/dist/cli/files-IJZVMROA.js +0 -22
  80. package/dist/cli/files-IX5QZQHC.js +0 -2
  81. package/dist/cli/files-KH3UEFN7.js +0 -20
  82. package/dist/cli/files-LTDT5ZFT.js +0 -22
  83. package/dist/cli/files-O4WJLFMU.js +0 -2
  84. package/dist/cli/files-OYO6A6MZ.js +0 -22
  85. package/dist/cli/files-R6QHQBH4.js +0 -22
  86. package/dist/cli/files-UCALOYWZ.js +0 -22
  87. package/dist/cli/files-UWZP7P6B.js +0 -2
  88. package/dist/cli/files-VIDLQM7Y.js +0 -20
  89. package/dist/cli/files-X2RDLF3W.js +0 -22
  90. package/dist/cli/files-XVDNOAZB.js +0 -22
  91. package/dist/cli/workspace-NB6BACZA.js +0 -12
  92. package/dist/cli/workspace-X2NGGGTQ.js +0 -12
  93. package/dist/cli/workspace-X4QXECQQ.js +0 -12
  94. package/dist/files-27OYPA7W.js +0 -20
  95. package/dist/files-2TK74THO.js +0 -22
  96. package/dist/files-3RDDXUOS.js +0 -2
  97. package/dist/files-7275M2PW.js +0 -20
  98. package/dist/files-D3YPV7QT.js +0 -20
  99. package/dist/files-FER4UZ4X.js +0 -22
  100. package/dist/files-H4FRDKJV.js +0 -22
  101. package/dist/files-IJZVMROA.js +0 -22
  102. package/dist/files-IX5QZQHC.js +0 -2
  103. package/dist/files-KH3UEFN7.js +0 -20
  104. package/dist/files-LTDT5ZFT.js +0 -22
  105. package/dist/files-O4WJLFMU.js +0 -2
  106. package/dist/files-OYO6A6MZ.js +0 -22
  107. package/dist/files-R6QHQBH4.js +0 -22
  108. package/dist/files-UCALOYWZ.js +0 -22
  109. package/dist/files-UWZP7P6B.js +0 -2
  110. package/dist/files-VIDLQM7Y.js +0 -20
  111. package/dist/files-X2RDLF3W.js +0 -22
  112. package/dist/files-XVDNOAZB.js +0 -22
  113. package/dist/workspace-NB6BACZA.js +0 -12
  114. package/dist/workspace-X2NGGGTQ.js +0 -12
  115. package/dist/workspace-X4QXECQQ.js +0 -12
@@ -1,803 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/core/files.ts
4
- import {
5
- readdirSync as readdirSync2,
6
- writeFileSync as writeFileSync2,
7
- readFileSync as readFileSync2,
8
- unlinkSync as unlinkSync2,
9
- statSync,
10
- mkdirSync as mkdirSync2,
11
- existsSync as existsSync3
12
- } from "fs";
13
- import { join as join3, basename, isAbsolute } from "path";
14
-
15
- // src/core/types.ts
16
- var ANNOTATION_TAGS = [
17
- "TODO",
18
- "FEATURE",
19
- "VARIANT",
20
- "KEEP",
21
- "QUESTION",
22
- "CONTEXT"
23
- ];
24
- var PROTO_DIR = ".proto";
25
- var TASKS_DIR = "tasks";
26
- var COMMENTS_DIR = "comments";
27
- var FILES_DIR = "tasks/files";
28
- var AGENTS_DIR = "agents";
29
- var SCREENSHOTS_DIR = "tasks/screenshots";
30
- var CONFIG_FILE = "config.json";
31
-
32
- // src/core/tasks.ts
33
- import {
34
- existsSync as existsSync2,
35
- readFileSync,
36
- writeFileSync,
37
- mkdirSync,
38
- readdirSync,
39
- unlinkSync,
40
- renameSync
41
- } from "fs";
42
- import { join as join2, extname } from "path";
43
- import { randomBytes } from "crypto";
44
-
45
- // src/core/tasks-legacy.ts
46
- import { existsSync } from "fs";
47
- import { join } from "path";
48
- var VALID_STATUSES = ["backlog", "todo", "in-progress", "review", "done"];
49
- function parseFrontMatter(content) {
50
- const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
51
- if (!match) return { frontMatter: {}, body: content.trim() };
52
- const yaml = match[1];
53
- const body = match[2].trim();
54
- const frontMatter = {};
55
- for (const line of yaml.split("\n")) {
56
- const colonIdx = line.indexOf(":");
57
- if (colonIdx === -1) continue;
58
- const key = line.slice(0, colonIdx).trim();
59
- let value = line.slice(colonIdx + 1).trim();
60
- if (value.startsWith("'") && value.endsWith("'") || value.startsWith('"') && value.endsWith('"')) {
61
- value = value.slice(1, -1);
62
- }
63
- frontMatter[key] = value;
64
- }
65
- return { frontMatter, body };
66
- }
67
- function parseTask(content) {
68
- const { frontMatter, body } = parseFrontMatter(content);
69
- if (!frontMatter.id || !frontMatter.selector) {
70
- return null;
71
- }
72
- const titleMatch = body.match(/^#\s+(.+)/m);
73
- const title = titleMatch ? titleMatch[1].trim() : "Untitled";
74
- const description = body.replace(/^#\s+.+\n*/m, "").trim();
75
- return {
76
- id: frontMatter.id,
77
- title,
78
- description,
79
- status: VALID_STATUSES.includes(frontMatter.status) ? frontMatter.status : "todo",
80
- url: frontMatter.url || void 0,
81
- selector: frontMatter.selector,
82
- cssSelector: frontMatter.cssSelector || void 0,
83
- file: frontMatter.file || void 0,
84
- line: frontMatter.line ? Number(frontMatter.line) : void 0,
85
- col: frontMatter.col ? Number(frontMatter.col) : void 0,
86
- component: frontMatter.component || void 0,
87
- type: frontMatter.type || void 0,
88
- priority: frontMatter.priority || void 0,
89
- reportBack: frontMatter.reportBack === "true" ? true : void 0,
90
- created: frontMatter.created || (/* @__PURE__ */ new Date()).toISOString(),
91
- updated: frontMatter.updated || void 0,
92
- comments: [],
93
- files: []
94
- };
95
- }
96
-
97
- // src/core/tasks-embeddings.ts
98
- var EMBED_MODEL = "nomic-embed-text";
99
- var DEFAULT_OLLAMA_URL = "http://localhost:11434";
100
- var MAX_EMBED_CHARS = 500;
101
- function taskToEmbedText(task) {
102
- const parts = [task.title];
103
- if (task.type) parts.push(task.type);
104
- if (task.description) {
105
- const cleaned = task.description.replace(/[|✅❌]/g, " ").replace(/\s+/g, " ").trim();
106
- parts.push(cleaned);
107
- }
108
- return parts.join(" \u2014 ").slice(0, MAX_EMBED_CHARS);
109
- }
110
- function taskTitleEmbedText(task) {
111
- return task.title.slice(0, MAX_EMBED_CHARS);
112
- }
113
- function taskDescriptionEmbedText(task) {
114
- const cleaned = (task.description ?? "").replace(/[|✅❌]/g, " ").replace(/\s+/g, " ").trim();
115
- return cleaned.slice(0, MAX_EMBED_CHARS);
116
- }
117
- function cosineSimilarity(a, b) {
118
- if (!a.length || !b.length || a.length !== b.length) return 0;
119
- let dot = 0;
120
- let normA = 0;
121
- let normB = 0;
122
- for (let i = 0; i < a.length; i += 1) {
123
- dot += a[i] * b[i];
124
- normA += a[i] * a[i];
125
- normB += b[i] * b[i];
126
- }
127
- if (normA === 0 || normB === 0) return 0;
128
- return dot / (Math.sqrt(normA) * Math.sqrt(normB));
129
- }
130
- function tokenize(text) {
131
- return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter(Boolean);
132
- }
133
- function bm25LikeScore(query, documents) {
134
- const queryTerms = tokenize(query);
135
- if (queryTerms.length === 0 || documents.length === 0) return documents.map(() => 0);
136
- const docsTerms = documents.map((d) => tokenize(d));
137
- const avgDocLen = docsTerms.reduce((acc, t) => acc + t.length, 0) / Math.max(1, docsTerms.length);
138
- const k1 = 1.2;
139
- const b = 0.75;
140
- const df = /* @__PURE__ */ new Map();
141
- for (const term of queryTerms) {
142
- let seen = 0;
143
- for (const doc of docsTerms) {
144
- if (doc.includes(term)) seen += 1;
145
- }
146
- df.set(term, seen);
147
- }
148
- return docsTerms.map((doc) => {
149
- if (doc.length === 0) return 0;
150
- let score = 0;
151
- for (const term of queryTerms) {
152
- const freq = doc.filter((t) => t === term).length;
153
- if (!freq) continue;
154
- const docFreq = df.get(term) ?? 0;
155
- const idf = Math.log(1 + (documents.length - docFreq + 0.5) / (docFreq + 0.5));
156
- const tf = freq * (k1 + 1) / (freq + k1 * (1 - b + b * (doc.length / Math.max(1, avgDocLen))));
157
- score += idf * tf;
158
- }
159
- return score;
160
- });
161
- }
162
- function reciprocalRankFusion(ranks, k = 60) {
163
- const fused = /* @__PURE__ */ new Map();
164
- for (const rankMap of ranks) {
165
- for (const [taskId, rank] of rankMap.entries()) {
166
- const prev = fused.get(taskId) ?? 0;
167
- fused.set(taskId, prev + 1 / (k + rank));
168
- }
169
- }
170
- return fused;
171
- }
172
- function buildRankMap(scores) {
173
- const sorted = scores.slice().sort((a, b) => b.score - a.score).map((row) => row.taskId);
174
- const rank = /* @__PURE__ */ new Map();
175
- sorted.forEach((taskId, idx) => rank.set(taskId, idx + 1));
176
- return rank;
177
- }
178
- function computeMetadataBoost(entry, options = {}) {
179
- let boost = 1;
180
- const statusBoost = options.statusBoost?.[entry.status];
181
- const priorityBoost = entry.priority ? options.priorityBoost?.[entry.priority] : void 0;
182
- if (statusBoost) boost *= statusBoost;
183
- if (priorityBoost) boost *= priorityBoost;
184
- const halfLife = options.recencyHalfLifeDays ?? 45;
185
- const refDate = entry.updated ?? entry.created;
186
- const ageDays = Math.max(0, (Date.now() - new Date(refDate).getTime()) / (1e3 * 60 * 60 * 24));
187
- const recencyBoost = Math.exp(-Math.log(2) * ageDays / Math.max(1, halfLife));
188
- boost *= 0.7 + 0.3 * recencyBoost;
189
- if (options.pageScope) {
190
- boost *= entry.url === options.pageScope ? 1.25 : 0.92;
191
- }
192
- return boost;
193
- }
194
- function rankHybridResults(args) {
195
- const { entries, query, queryVectorTitle, queryVectorDescription, queryVectorCombined, options = {} } = args;
196
- const docs = entries.map((e) => `${e.title} ${e.description}`.trim());
197
- const lexical = bm25LikeScore(query, docs);
198
- const denseScores = entries.map((entry) => {
199
- const title = cosineSimilarity(queryVectorTitle, entry.vectors.title);
200
- const description = cosineSimilarity(queryVectorDescription, entry.vectors.description);
201
- const combined = cosineSimilarity(queryVectorCombined, entry.vectors.combined);
202
- return {
203
- taskId: entry.taskId,
204
- score: combined * 0.5 + title * 0.35 + description * 0.15
205
- };
206
- });
207
- const lexicalScores = entries.map((entry, idx) => ({ taskId: entry.taskId, score: lexical[idx] ?? 0 }));
208
- const fused = reciprocalRankFusion([
209
- buildRankMap(denseScores),
210
- buildRankMap(lexicalScores)
211
- ]);
212
- return entries.map((entry) => {
213
- const base = fused.get(entry.taskId) ?? 0;
214
- const boost = computeMetadataBoost(entry, options);
215
- return {
216
- taskId: entry.taskId,
217
- score: base * boost
218
- };
219
- }).sort((a, b) => b.score - a.score);
220
- }
221
- async function generateEmbedding(text, ollamaUrl = DEFAULT_OLLAMA_URL, model = EMBED_MODEL) {
222
- const res = await fetch(`${ollamaUrl}/api/embed`, {
223
- method: "POST",
224
- headers: { "Content-Type": "application/json" },
225
- body: JSON.stringify({ model, input: text })
226
- });
227
- if (!res.ok) throw new Error(`Ollama embed error: ${res.status} ${res.statusText}`);
228
- const data = await res.json();
229
- const vec = data.embeddings?.[0] ?? data.embedding;
230
- if (!vec || !Array.isArray(vec)) throw new Error("No embedding returned by Ollama");
231
- return vec;
232
- }
233
-
234
- // src/core/tasks.ts
235
- function generateTaskId() {
236
- return randomBytes(15).toString("hex");
237
- }
238
- function getTasksDir(projectDir) {
239
- return join2(projectDir, PROTO_DIR, TASKS_DIR);
240
- }
241
- function migrateLegacyTaskAssetFolders(projectDir) {
242
- const protoRoot = join2(projectDir, PROTO_DIR);
243
- const legacyFilesDir = join2(protoRoot, "files");
244
- const nextFilesDir = join2(protoRoot, FILES_DIR);
245
- const legacyScreenshotsDir = join2(protoRoot, "screenshots");
246
- const nextScreenshotsDir = join2(protoRoot, SCREENSHOTS_DIR);
247
- if (existsSync2(legacyFilesDir)) {
248
- mkdirSync(nextFilesDir, { recursive: true });
249
- for (const entry of readdirSync(legacyFilesDir)) {
250
- const from = join2(legacyFilesDir, entry);
251
- const to = join2(nextFilesDir, entry);
252
- if (existsSync2(to)) continue;
253
- try {
254
- renameSync(from, to);
255
- } catch {
256
- }
257
- }
258
- }
259
- if (existsSync2(legacyScreenshotsDir)) {
260
- mkdirSync(nextScreenshotsDir, { recursive: true });
261
- for (const entry of readdirSync(legacyScreenshotsDir)) {
262
- const from = join2(legacyScreenshotsDir, entry);
263
- const to = join2(nextScreenshotsDir, entry);
264
- if (existsSync2(to)) continue;
265
- try {
266
- renameSync(from, to);
267
- } catch {
268
- }
269
- }
270
- }
271
- }
272
- function ensureTaskDirs(projectDir) {
273
- migrateLegacyTaskAssetFolders(projectDir);
274
- mkdirSync(getTasksDir(projectDir), { recursive: true });
275
- mkdirSync(join2(projectDir, PROTO_DIR, SCREENSHOTS_DIR), { recursive: true });
276
- }
277
- function getDateSubdir(isoDate) {
278
- return isoDate.slice(0, 10);
279
- }
280
- function getTaskFilePath(projectDir, taskId, created) {
281
- const tasksDir = getTasksDir(projectDir);
282
- if (created) {
283
- return join2(tasksDir, getDateSubdir(created), `${taskId}.json`);
284
- }
285
- return join2(tasksDir, `${taskId}.json`);
286
- }
287
- function findTaskFilePath(projectDir, taskId) {
288
- const tasksDir = getTasksDir(projectDir);
289
- if (!existsSync2(tasksDir)) return null;
290
- for (const entry of readdirSync(tasksDir, { withFileTypes: true })) {
291
- if (entry.isDirectory()) {
292
- const candidate = join2(tasksDir, entry.name, `${taskId}.json`);
293
- if (existsSync2(candidate)) return candidate;
294
- } else if (entry.name === `${taskId}.json`) {
295
- return join2(tasksDir, entry.name);
296
- }
297
- }
298
- return null;
299
- }
300
- function normalizeTask(raw) {
301
- const normalizedType = (() => {
302
- if (typeof raw.type !== "string") return void 0;
303
- const t = raw.type.trim();
304
- if (!t || t === "[object Object]") return void 0;
305
- return t;
306
- })();
307
- return {
308
- id: String(raw.id ?? ""),
309
- title: String(raw.title ?? "Untitled"),
310
- description: String(raw.description ?? ""),
311
- status: VALID_STATUSES.includes(raw.status) ? raw.status : "todo",
312
- url: raw.url ? String(raw.url) : void 0,
313
- selector: (() => {
314
- const sel = String(raw.selector ?? "/");
315
- if (raw.file && !raw.cssSelector && sel.startsWith(String(raw.file))) {
316
- return raw.url ? String(raw.url) : "/";
317
- }
318
- return sel;
319
- })(),
320
- cssSelector: raw.cssSelector && String(raw.cssSelector) !== String(raw.selector ?? "/") ? String(raw.cssSelector) : void 0,
321
- file: raw.file ? String(raw.file) : void 0,
322
- line: raw.line != null ? Number(raw.line) : void 0,
323
- col: raw.col != null ? Number(raw.col) : void 0,
324
- component: raw.component ? String(raw.component) : void 0,
325
- type: normalizedType,
326
- priority: raw.priority ? String(raw.priority) : void 0,
327
- ...raw.reportBack === true && { reportBack: true },
328
- agent: raw.agent ? String(raw.agent) : void 0,
329
- model: raw.model ? String(raw.model) : void 0,
330
- author: raw.author ? String(raw.author) : void 0,
331
- commit: raw.commit ? String(raw.commit) : void 0,
332
- commits: Array.isArray(raw.commits) ? raw.commits.map((c) => ({
333
- sha: String(c.sha ?? ""),
334
- message: String(c.message ?? ""),
335
- timestamp: String(c.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
336
- })) : void 0,
337
- created: String(raw.created ?? (/* @__PURE__ */ new Date()).toISOString()),
338
- updated: raw.updated ? String(raw.updated) : void 0,
339
- comments: Array.isArray(raw.comments) ? raw.comments.map((c) => ({
340
- ...c,
341
- // Normalize legacy 'content' field → 'text' (some older agent comments used 'content')
342
- text: c.text ?? c.content ?? ""
343
- })) : [],
344
- files: Array.isArray(raw.files) ? raw.files.map((f) => {
345
- if (typeof f === "string") {
346
- return { name: f, addedAt: (/* @__PURE__ */ new Date()).toISOString() };
347
- }
348
- return {
349
- name: String(f.name ?? ""),
350
- addedAt: String(f.addedAt ?? (/* @__PURE__ */ new Date()).toISOString()),
351
- linkedPath: f.linkedPath ? String(f.linkedPath) : void 0,
352
- mimeType: f.mimeType ? String(f.mimeType) : void 0
353
- };
354
- }).filter((f) => f.name) : [],
355
- screenshot: raw.screenshot ? String(raw.screenshot) : void 0
356
- };
357
- }
358
- function writeTaskJson(projectDir, task) {
359
- const dateDir = join2(getTasksDir(projectDir), getDateSubdir(task.created));
360
- mkdirSync(dateDir, { recursive: true });
361
- const filePath = join2(dateDir, `${task.id}.json`);
362
- writeFileSync(filePath, JSON.stringify(task, null, 2), "utf-8");
363
- }
364
- function createTask(projectDir, input) {
365
- const normalizedPriority = (() => {
366
- const raw = (input.priority ?? "").trim().toLowerCase();
367
- if (raw === "critical") return "Critical";
368
- if (raw === "high") return "High";
369
- if (raw === "low") return "Low";
370
- return "Medium";
371
- })();
372
- const task = {
373
- ...input,
374
- priority: normalizedPriority,
375
- id: generateTaskId(),
376
- created: (/* @__PURE__ */ new Date()).toISOString(),
377
- comments: [],
378
- files: []
379
- };
380
- writeTaskJson(projectDir, task);
381
- queueAutoEmbeddingRefresh(projectDir, task);
382
- return task;
383
- }
384
- function readTaskFile(filePath) {
385
- try {
386
- const content = readFileSync(filePath, "utf-8");
387
- if (filePath.endsWith(".json")) {
388
- const raw = JSON.parse(content);
389
- if (!raw || typeof raw !== "object" || !("id" in raw)) return null;
390
- return normalizeTask(raw);
391
- }
392
- return parseTask(content);
393
- } catch {
394
- return null;
395
- }
396
- }
397
- function collectTaskFiles(projectDir) {
398
- const tasksDir = getTasksDir(projectDir);
399
- if (!existsSync2(tasksDir)) return [];
400
- const results = [];
401
- for (const entry of readdirSync(tasksDir, { withFileTypes: true })) {
402
- if (entry.isDirectory()) {
403
- const dateDir = join2(tasksDir, entry.name);
404
- for (const file of readdirSync(dateDir)) {
405
- if (extname(file) === ".json") {
406
- const filePath = join2(dateDir, file);
407
- const task = readTaskFile(filePath);
408
- if (task) results.push({ task, filePath });
409
- }
410
- }
411
- } else if (extname(entry.name) === ".json") {
412
- const filePath = join2(tasksDir, entry.name);
413
- const task = readTaskFile(filePath);
414
- if (task) results.push({ task, filePath });
415
- }
416
- }
417
- return results.sort((a, b) => {
418
- const aDate = a.task.updated ?? a.task.created;
419
- const bDate = b.task.updated ?? b.task.created;
420
- return new Date(bDate).getTime() - new Date(aDate).getTime();
421
- });
422
- }
423
- function listTasks(projectDir) {
424
- return collectTaskFiles(projectDir).map(({ task }) => task);
425
- }
426
- function listTasksWithPaths(projectDir) {
427
- return collectTaskFiles(projectDir).map(({ task, filePath }) => ({ ...task, filePath }));
428
- }
429
- function updateTask(projectDir, taskId, updates) {
430
- const existingPath = findTaskFilePath(projectDir, taskId);
431
- const task = existingPath ? readTaskFile(existingPath) : null;
432
- if (!task) return null;
433
- const updated = { ...task, ...updates, updated: (/* @__PURE__ */ new Date()).toISOString() };
434
- writeTaskJson(projectDir, updated);
435
- if (existingPath && existingPath !== getTaskFilePath(projectDir, taskId, updated.created)) {
436
- try {
437
- unlinkSync(existingPath);
438
- } catch {
439
- }
440
- }
441
- queueAutoEmbeddingRefresh(projectDir, updated);
442
- return updated;
443
- }
444
- function deleteTask(projectDir, taskId) {
445
- const filePath = findTaskFilePath(projectDir, taskId);
446
- if (!filePath) return false;
447
- unlinkSync(filePath);
448
- return true;
449
- }
450
- function formatTaskForAgent(task, comments, files) {
451
- return {
452
- id: task.id,
453
- status: task.status,
454
- title: task.title,
455
- description: task.description,
456
- ...task.url && { url: task.url },
457
- selector: task.selector,
458
- ...task.file && { file: task.file },
459
- ...task.line != null && { line: task.line },
460
- ...task.col != null && { col: task.col },
461
- ...task.component && { component: task.component },
462
- ...task.type && { type: task.type },
463
- ...task.priority && { priority: task.priority },
464
- ...comments && comments.length > 0 && { structuredComments: comments },
465
- ...files && files.length > 0 && { linkedFiles: files },
466
- ...task.reportBack && { reportBack: true },
467
- created: task.created
468
- };
469
- }
470
- var embeddingWriteQueue = Promise.resolve();
471
- function queueAutoEmbeddingRefresh(projectDir, task) {
472
- if (process.env.NODE_ENV === "test" && process.env.PROTO_AUTO_EMBED !== "1") {
473
- return;
474
- }
475
- embeddingWriteQueue = embeddingWriteQueue.then(async () => {
476
- try {
477
- const [titleVec, descVec, combinedVec] = await Promise.all([
478
- generateEmbedding(taskTitleEmbedText(task), DEFAULT_OLLAMA_URL, EMBED_MODEL),
479
- generateEmbedding(taskDescriptionEmbedText(task), DEFAULT_OLLAMA_URL, EMBED_MODEL),
480
- generateEmbedding(taskToEmbedText(task), DEFAULT_OLLAMA_URL, EMBED_MODEL)
481
- ]);
482
- const current = readEmbeddingIndex(projectDir);
483
- const byTaskId = new Map(current.entries.map((entry) => [entry.taskId, entry]));
484
- byTaskId.set(task.id, {
485
- taskId: task.id,
486
- title: task.title,
487
- description: task.description ?? "",
488
- status: task.status,
489
- priority: task.priority,
490
- url: task.url,
491
- created: task.created,
492
- updated: task.updated,
493
- vectors: {
494
- title: titleVec,
495
- description: descVec,
496
- combined: combinedVec
497
- }
498
- });
499
- writeEmbeddingIndex(projectDir, {
500
- model: EMBED_MODEL,
501
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
502
- entries: Array.from(byTaskId.values())
503
- });
504
- } catch (e) {
505
- const msg = e instanceof Error ? e.message : String(e);
506
- console.error(`[Proto] Background embedding error for task ${task.id}: ${msg}`);
507
- }
508
- }).catch((e) => {
509
- const msg = e instanceof Error ? e.message : String(e);
510
- console.error(`[Proto] Embedding queue error: ${msg}`);
511
- });
512
- }
513
- function getEmbeddingIndexPath(projectDir) {
514
- return join2(projectDir, PROTO_DIR, "embeddings", "index.bin");
515
- }
516
- function readEmbeddingIndex(projectDir) {
517
- const indexPath = getEmbeddingIndexPath(projectDir);
518
- if (!existsSync2(indexPath)) {
519
- return { model: EMBED_MODEL, generatedAt: "", entries: [] };
520
- }
521
- try {
522
- const raw = JSON.parse(readFileSync(indexPath, "utf-8"));
523
- return {
524
- model: raw.model ?? EMBED_MODEL,
525
- generatedAt: raw.generatedAt ?? "",
526
- entries: Array.isArray(raw.entries) ? raw.entries : []
527
- };
528
- } catch {
529
- return { model: EMBED_MODEL, generatedAt: "", entries: [] };
530
- }
531
- }
532
- function writeEmbeddingIndex(projectDir, payload) {
533
- const indexPath = getEmbeddingIndexPath(projectDir);
534
- mkdirSync(join2(projectDir, PROTO_DIR, "embeddings"), { recursive: true });
535
- writeFileSync(indexPath, JSON.stringify(payload), "utf-8");
536
- }
537
- async function searchTasksHybrid(projectDir, args, ollamaUrl = DEFAULT_OLLAMA_URL, model = EMBED_MODEL) {
538
- const index = readEmbeddingIndex(projectDir);
539
- if (index.entries.length === 0) return [];
540
- const queryVector = await generateEmbedding(args.query, ollamaUrl, model);
541
- const ranked = rankHybridResults({
542
- entries: index.entries,
543
- query: args.query,
544
- queryVectorTitle: queryVector,
545
- queryVectorDescription: queryVector,
546
- queryVectorCombined: queryVector,
547
- options: {
548
- pageScope: args.pageScope,
549
- statusBoost: {
550
- "in-progress": 1.2,
551
- review: 1.1,
552
- todo: 1.05
553
- },
554
- priorityBoost: {
555
- Critical: 1.35,
556
- High: 1.2,
557
- Medium: 1.05
558
- }
559
- }
560
- });
561
- const tasksById = new Map(listTasks(projectDir).map((t) => [t.id, t]));
562
- const limit = Math.max(1, args.limit ?? 10);
563
- return ranked.slice(0, limit).map((row) => ({ task: tasksById.get(row.taskId), score: row.score })).filter((row) => !!row.task);
564
- }
565
- function migrateTasksFromMd(projectDir) {
566
- const tasksDir = getTasksDir(projectDir);
567
- const commentsDir = join2(projectDir, PROTO_DIR, COMMENTS_DIR);
568
- if (!existsSync2(tasksDir)) return 0;
569
- const mdFiles = readdirSync(tasksDir).filter((f) => extname(f) === ".md");
570
- let migrated = 0;
571
- for (const mdFile of mdFiles) {
572
- const mdPath = join2(tasksDir, mdFile);
573
- try {
574
- const legacyTask = parseTask(readFileSync(mdPath, "utf-8"));
575
- if (!legacyTask) continue;
576
- if (findTaskFilePath(projectDir, legacyTask.id)) {
577
- unlinkSync(mdPath);
578
- continue;
579
- }
580
- const commentsPath = join2(commentsDir, `${legacyTask.id}.json`);
581
- let comments = [];
582
- if (existsSync2(commentsPath)) {
583
- try {
584
- const raw = JSON.parse(readFileSync(commentsPath, "utf-8"));
585
- if (Array.isArray(raw)) {
586
- comments = raw.map((c, i) => ({
587
- ...c,
588
- id: c.id || String(Date.now() + i).slice(-10)
589
- }));
590
- }
591
- } catch {
592
- }
593
- }
594
- const newTask = {
595
- ...legacyTask,
596
- comments,
597
- files: []
598
- };
599
- writeTaskJson(projectDir, newTask);
600
- unlinkSync(mdPath);
601
- migrated++;
602
- } catch {
603
- }
604
- }
605
- return migrated;
606
- }
607
-
608
- // src/core/files.ts
609
- var LINKED_MANIFEST = ".linked.json";
610
- function getFilesDir(projectDir, taskId) {
611
- return join3(projectDir, PROTO_DIR, FILES_DIR, taskId);
612
- }
613
- function ensureFilesDir(projectDir, taskId) {
614
- mkdirSync2(getFilesDir(projectDir, taskId), { recursive: true });
615
- }
616
- function readLinked(projectDir, taskId) {
617
- const manifestPath = join3(getFilesDir(projectDir, taskId), LINKED_MANIFEST);
618
- if (!existsSync3(manifestPath)) return [];
619
- try {
620
- return JSON.parse(readFileSync2(manifestPath, "utf-8"));
621
- } catch {
622
- return [];
623
- }
624
- }
625
- function getTaskFileRefs(projectDir, taskId) {
626
- const filePath = findTaskFilePath(projectDir, taskId);
627
- const task = filePath ? readTaskFile(filePath) : null;
628
- if (!task?.files || task.files.length === 0) return [];
629
- return task.files;
630
- }
631
- function setTaskFileRefs(projectDir, taskId, refs) {
632
- updateTask(projectDir, taskId, { files: refs });
633
- }
634
- function migrateLegacyLinkedRefs(projectDir, taskId) {
635
- const refs = getTaskFileRefs(projectDir, taskId);
636
- const manifestPath = join3(getFilesDir(projectDir, taskId), LINKED_MANIFEST);
637
- if (!existsSync3(manifestPath)) return refs;
638
- const legacy = readLinked(projectDir, taskId);
639
- if (legacy.length === 0) {
640
- try {
641
- unlinkSync2(manifestPath);
642
- } catch {
643
- }
644
- return refs;
645
- }
646
- const next = refs.slice();
647
- let added = false;
648
- for (const entry of legacy) {
649
- if (!next.find((f) => f.linkedPath === entry.path || f.name === entry.name && f.linkedPath)) {
650
- next.push({
651
- name: entry.name,
652
- linkedPath: entry.path,
653
- addedAt: (/* @__PURE__ */ new Date()).toISOString()
654
- });
655
- added = true;
656
- }
657
- }
658
- if (added) {
659
- setTaskFileRefs(projectDir, taskId, next);
660
- }
661
- try {
662
- unlinkSync2(manifestPath);
663
- } catch {
664
- }
665
- return next;
666
- }
667
- function listFiles(projectDir, taskId) {
668
- const dir = getFilesDir(projectDir, taskId);
669
- const refs = migrateLegacyLinkedRefs(projectDir, taskId);
670
- const byName = /* @__PURE__ */ new Map();
671
- for (const ref of refs) {
672
- if (ref.linkedPath && existsSync3(ref.linkedPath)) {
673
- const stat = statSync(ref.linkedPath);
674
- byName.set(ref.name, {
675
- name: ref.name,
676
- size: stat.size,
677
- url: `/api/tasks/${taskId}/files/${encodeURIComponent(ref.name)}`,
678
- linkedPath: ref.linkedPath,
679
- createdAt: stat.mtime.toISOString()
680
- });
681
- continue;
682
- }
683
- const uploadedPath = join3(dir, ref.name);
684
- if (existsSync3(uploadedPath)) {
685
- const stat = statSync(uploadedPath);
686
- byName.set(ref.name, {
687
- name: ref.name,
688
- size: stat.size,
689
- url: `/api/tasks/${taskId}/files/${encodeURIComponent(ref.name)}`,
690
- createdAt: stat.mtime.toISOString()
691
- });
692
- }
693
- }
694
- if (existsSync3(dir)) {
695
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
696
- if (!entry.isFile() || entry.name === LINKED_MANIFEST || byName.has(entry.name)) continue;
697
- const fullPath = join3(dir, entry.name);
698
- const stat = statSync(fullPath);
699
- byName.set(entry.name, {
700
- name: entry.name,
701
- size: stat.size,
702
- url: `/api/tasks/${taskId}/files/${encodeURIComponent(entry.name)}`,
703
- createdAt: stat.mtime.toISOString()
704
- });
705
- }
706
- }
707
- return Array.from(byName.values());
708
- }
709
- function saveFile(projectDir, taskId, filename, data) {
710
- const safe = basename(filename);
711
- ensureFilesDir(projectDir, taskId);
712
- writeFileSync2(join3(getFilesDir(projectDir, taskId), safe), data);
713
- const refs = migrateLegacyLinkedRefs(projectDir, taskId);
714
- if (!refs.find((f) => f.name === safe && !f.linkedPath)) {
715
- refs.push({ name: safe, addedAt: (/* @__PURE__ */ new Date()).toISOString() });
716
- setTaskFileRefs(projectDir, taskId, refs);
717
- }
718
- return {
719
- name: safe,
720
- size: data.length,
721
- url: `/api/tasks/${taskId}/files/${encodeURIComponent(safe)}`
722
- };
723
- }
724
- function linkFile(projectDir, taskId, absolutePath) {
725
- if (!isAbsolute(absolutePath)) return null;
726
- if (!existsSync3(absolutePath)) return null;
727
- const stat = statSync(absolutePath);
728
- if (!stat.isFile()) return null;
729
- const name = basename(absolutePath);
730
- const refs = migrateLegacyLinkedRefs(projectDir, taskId);
731
- if (!refs.find((f) => f.linkedPath === absolutePath)) {
732
- refs.push({
733
- name,
734
- linkedPath: absolutePath,
735
- addedAt: (/* @__PURE__ */ new Date()).toISOString()
736
- });
737
- setTaskFileRefs(projectDir, taskId, refs);
738
- }
739
- return {
740
- name,
741
- size: stat.size,
742
- url: `/api/tasks/${taskId}/files/${encodeURIComponent(name)}`,
743
- linkedPath: absolutePath
744
- };
745
- }
746
- function deleteFile(projectDir, taskId, filename) {
747
- const safe = basename(filename);
748
- const refs = migrateLegacyLinkedRefs(projectDir, taskId);
749
- const idx = refs.findIndex((f) => f.name === safe);
750
- if (idx !== -1) {
751
- const [removed] = refs.splice(idx, 1);
752
- setTaskFileRefs(projectDir, taskId, refs);
753
- if (removed && !removed.linkedPath) {
754
- const uploadedPath = join3(getFilesDir(projectDir, taskId), safe);
755
- if (existsSync3(uploadedPath)) unlinkSync2(uploadedPath);
756
- }
757
- return true;
758
- }
759
- const filePath = join3(getFilesDir(projectDir, taskId), safe);
760
- if (!existsSync3(filePath)) return false;
761
- unlinkSync2(filePath);
762
- return true;
763
- }
764
- function getFilePath(projectDir, taskId, filename) {
765
- const safe = basename(filename);
766
- const linkedRef = migrateLegacyLinkedRefs(projectDir, taskId).find((f) => f.name === safe && f.linkedPath);
767
- if (linkedRef?.linkedPath && existsSync3(linkedRef.linkedPath)) return linkedRef.linkedPath;
768
- const filePath = join3(getFilesDir(projectDir, taskId), safe);
769
- return existsSync3(filePath) ? filePath : null;
770
- }
771
- function getFileCount(projectDir, taskId) {
772
- return listFiles(projectDir, taskId).length;
773
- }
774
-
775
- export {
776
- ANNOTATION_TAGS,
777
- PROTO_DIR,
778
- AGENTS_DIR,
779
- SCREENSHOTS_DIR,
780
- CONFIG_FILE,
781
- generateTaskId,
782
- ensureTaskDirs,
783
- getTaskFilePath,
784
- findTaskFilePath,
785
- createTask,
786
- readTaskFile,
787
- listTasks,
788
- listTasksWithPaths,
789
- updateTask,
790
- deleteTask,
791
- formatTaskForAgent,
792
- searchTasksHybrid,
793
- migrateTasksFromMd,
794
- getFilesDir,
795
- ensureFilesDir,
796
- listFiles,
797
- saveFile,
798
- linkFile,
799
- deleteFile,
800
- getFilePath,
801
- getFileCount
802
- };
803
- //# sourceMappingURL=chunk-XF2CNPE4.js.map