@bike4mind/cli 0.2.6-fix-cli-mcp-type-mismatch.17119 → 0.2.7-ja-fix-confluence-table-data-5752.17142

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.
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env node
2
+ import "./chunk-PDX44BCA.js";
3
+
4
+ // src/storage/ImageStore.ts
5
+ import { createHash } from "crypto";
6
+ import { mkdirSync, writeFileSync, readFileSync, existsSync, unlinkSync } from "fs";
7
+ import { join, extname, resolve } from "path";
8
+ import { homedir } from "os";
9
+ import Database from "better-sqlite3";
10
+ import sharp from "sharp";
11
+ var ImageStore = class _ImageStore {
12
+ static {
13
+ this.BASE_DIR = join(homedir(), ".bike4mind", "cli");
14
+ }
15
+ static {
16
+ this.IMAGES_DIR = join(_ImageStore.BASE_DIR, "images");
17
+ }
18
+ static {
19
+ this.DB_PATH = join(_ImageStore.BASE_DIR, "images.db");
20
+ }
21
+ static {
22
+ this.RETENTION_DAYS = 7;
23
+ }
24
+ static {
25
+ // Target max size before base64 encoding. Base64 adds ~33% overhead.
26
+ // To stay under 1MB after base64, we need images < 750KB
27
+ this.MAX_RAW_SIZE = 750 * 1024;
28
+ }
29
+ static {
30
+ // 750KB
31
+ // Maximum size before compression to prevent OOM with very large images
32
+ this.MAX_PRECOMPRESS_SIZE = 50 * 1024 * 1024;
33
+ }
34
+ constructor() {
35
+ this.ensureDirectories();
36
+ this.db = new Database(_ImageStore.DB_PATH);
37
+ this.initDatabase();
38
+ try {
39
+ this.cleanupOldImages();
40
+ } catch (err) {
41
+ console.warn("Failed to cleanup old images:", err);
42
+ }
43
+ }
44
+ ensureDirectories() {
45
+ mkdirSync(_ImageStore.BASE_DIR, { recursive: true });
46
+ mkdirSync(_ImageStore.IMAGES_DIR, { recursive: true });
47
+ }
48
+ initDatabase() {
49
+ this.db.exec(`
50
+ CREATE TABLE IF NOT EXISTS images (
51
+ hash TEXT PRIMARY KEY,
52
+ format TEXT NOT NULL,
53
+ size INTEGER NOT NULL,
54
+ timestamp INTEGER NOT NULL,
55
+ uploaded INTEGER NOT NULL DEFAULT 0,
56
+ s3_url TEXT,
57
+ original_filename TEXT
58
+ )
59
+ `);
60
+ }
61
+ /**
62
+ * Store an image locally with content-based hashing for deduplication
63
+ */
64
+ async store(imageData, originalFilename) {
65
+ const { buffer: processedData, format: processedFormat } = await this.processImage(imageData, originalFilename);
66
+ const hash = this.generateHash(processedData);
67
+ const format = processedFormat;
68
+ const ext = format.toLowerCase();
69
+ const localPath = join(_ImageStore.IMAGES_DIR, `${hash}.${ext}`);
70
+ const existing = this.getMetadata(hash);
71
+ if (existing) {
72
+ return {
73
+ hash,
74
+ placeholder: "",
75
+ // Will be set by caller
76
+ localPath,
77
+ metadata: existing
78
+ };
79
+ }
80
+ writeFileSync(localPath, processedData);
81
+ const metadata = {
82
+ hash,
83
+ format,
84
+ size: processedData.length,
85
+ timestamp: Date.now(),
86
+ uploaded: false,
87
+ originalFilename
88
+ };
89
+ this.db.prepare(
90
+ `INSERT INTO images (hash, format, size, timestamp, uploaded, original_filename)
91
+ VALUES (?, ?, ?, ?, ?, ?)`
92
+ ).run(hash, format, metadata.size, metadata.timestamp, 0, originalFilename || null);
93
+ return {
94
+ hash,
95
+ placeholder: "",
96
+ localPath,
97
+ metadata
98
+ };
99
+ }
100
+ /**
101
+ * Get image metadata by hash
102
+ */
103
+ getMetadata(hash) {
104
+ const row = this.db.prepare("SELECT * FROM images WHERE hash = ?").get(hash);
105
+ if (!row) return null;
106
+ return {
107
+ hash: row.hash,
108
+ format: row.format,
109
+ size: row.size,
110
+ timestamp: row.timestamp,
111
+ uploaded: Boolean(row.uploaded),
112
+ s3Url: row.s3_url,
113
+ originalFilename: row.original_filename
114
+ };
115
+ }
116
+ /**
117
+ * Read image data from local cache
118
+ */
119
+ readImage(hash) {
120
+ const metadata = this.getMetadata(hash);
121
+ if (!metadata) return null;
122
+ const localPath = join(_ImageStore.IMAGES_DIR, `${hash}.${metadata.format.toLowerCase()}`);
123
+ const normalizedPath = resolve(localPath);
124
+ if (!normalizedPath.startsWith(resolve(_ImageStore.IMAGES_DIR))) {
125
+ throw new Error("Invalid image path");
126
+ }
127
+ if (!existsSync(localPath)) return null;
128
+ return readFileSync(localPath);
129
+ }
130
+ /**
131
+ * Generate content hash for deduplication
132
+ */
133
+ generateHash(data) {
134
+ return createHash("sha256").update(data).digest("hex").substring(0, 16);
135
+ }
136
+ /**
137
+ * Process image: compress if needed to stay under size limit
138
+ */
139
+ async processImage(data, originalFilename) {
140
+ if (data.length > _ImageStore.MAX_PRECOMPRESS_SIZE) {
141
+ throw new Error(
142
+ `Image too large to process (${Math.round(data.length / 1024 / 1024)}MB). Maximum size is ${_ImageStore.MAX_PRECOMPRESS_SIZE / 1024 / 1024}MB.`
143
+ );
144
+ }
145
+ const originalFormat = this.detectFormat(data, originalFilename);
146
+ if (data.length <= _ImageStore.MAX_RAW_SIZE) {
147
+ return { buffer: data, format: originalFormat };
148
+ }
149
+ let image = sharp(data);
150
+ const metadata = await image.metadata();
151
+ if (!metadata.width || !metadata.height) {
152
+ throw new Error("Unable to read image dimensions");
153
+ }
154
+ const maxDimension = 2048;
155
+ let width = metadata.width;
156
+ let height = metadata.height;
157
+ if (width > maxDimension || height > maxDimension) {
158
+ if (width > height) {
159
+ height = Math.round(height * maxDimension / width);
160
+ width = maxDimension;
161
+ } else {
162
+ width = Math.round(width * maxDimension / height);
163
+ height = maxDimension;
164
+ }
165
+ }
166
+ image = image.resize(width, height);
167
+ let quality = 85;
168
+ let buffer = await image.jpeg({ quality }).toBuffer();
169
+ while (buffer.length > _ImageStore.MAX_RAW_SIZE && quality > 30) {
170
+ quality -= 10;
171
+ buffer = await image.jpeg({ quality }).toBuffer();
172
+ }
173
+ if (buffer.length > _ImageStore.MAX_RAW_SIZE) {
174
+ throw new Error(`Unable to compress image below ${_ImageStore.MAX_RAW_SIZE / 1024}KB limit`);
175
+ }
176
+ return { buffer, format: "jpg" };
177
+ }
178
+ /**
179
+ * Detect image format from buffer or filename
180
+ */
181
+ detectFormat(data, filename) {
182
+ if (data[0] === 137 && data[1] === 80 && data[2] === 78 && data[3] === 71) {
183
+ return "png";
184
+ }
185
+ if (data[0] === 255 && data[1] === 216 && data[2] === 255) {
186
+ return "jpg";
187
+ }
188
+ if (data[0] === 71 && data[1] === 73 && data[2] === 70) {
189
+ return "gif";
190
+ }
191
+ if (data[0] === 82 && data[1] === 73 && data[2] === 70 && data[3] === 70) {
192
+ return "webp";
193
+ }
194
+ if (filename) {
195
+ const ext = extname(filename).substring(1).toLowerCase();
196
+ if (["png", "jpg", "jpeg", "gif", "webp"].includes(ext)) {
197
+ return ext === "jpeg" ? "jpg" : ext;
198
+ }
199
+ }
200
+ return "png";
201
+ }
202
+ /**
203
+ * Clean up images older than retention period
204
+ */
205
+ cleanupOldImages() {
206
+ const cutoffTime = Date.now() - _ImageStore.RETENTION_DAYS * 24 * 60 * 60 * 1e3;
207
+ const oldImages = this.db.prepare("SELECT hash, format FROM images WHERE timestamp < ?").all(cutoffTime);
208
+ for (const { hash, format } of oldImages) {
209
+ const localPath = join(_ImageStore.IMAGES_DIR, `${hash}.${format.toLowerCase()}`);
210
+ if (existsSync(localPath)) {
211
+ unlinkSync(localPath);
212
+ }
213
+ }
214
+ this.db.prepare("DELETE FROM images WHERE timestamp < ?").run(cutoffTime);
215
+ }
216
+ /**
217
+ * Close database connection
218
+ */
219
+ close() {
220
+ this.db.close();
221
+ }
222
+ };
223
+ export {
224
+ ImageStore
225
+ };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-H6SHASMZ.js";
4
+ } from "./chunk-F2LBB4TN.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/artifactExtractor.js
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BadRequestError,
4
4
  secureParameters
5
- } from "./chunk-DNSBC3LO.js";
5
+ } from "./chunk-KPBWTYME.js";
6
6
  import {
7
7
  GenericCreditDeductTransaction,
8
8
  ImageEditUsageTransaction,
@@ -10,7 +10,7 @@ import {
10
10
  RealtimeVoiceUsageTransaction,
11
11
  TextGenerationUsageTransaction,
12
12
  TransferCreditTransaction
13
- } from "./chunk-H6SHASMZ.js";
13
+ } from "./chunk-F2LBB4TN.js";
14
14
 
15
15
  // ../../b4m-core/packages/services/dist/src/creditService/subtractCredits.js
16
16
  import { z } from "zod";
@@ -5041,6 +5041,74 @@ function formatUserList(users) {
5041
5041
  }
5042
5042
 
5043
5043
  // ../../b4m-core/packages/common/dist/src/jira/api.js
5044
+ function wikiMarkupToAdf(text) {
5045
+ const lines = text.split("\n");
5046
+ const content = [];
5047
+ let currentTableRows = [];
5048
+ let inTable = false;
5049
+ for (const line of lines) {
5050
+ const trimmedLine = line.trim();
5051
+ if (trimmedLine.startsWith("||") && trimmedLine.endsWith("||")) {
5052
+ inTable = true;
5053
+ const cells = trimmedLine.slice(2, -2).split("||").map((cell) => cell.trim());
5054
+ const headerRow = {
5055
+ type: "tableRow",
5056
+ content: cells.map((cell) => ({
5057
+ type: "tableHeader",
5058
+ attrs: {},
5059
+ content: [{ type: "paragraph", content: [{ type: "text", text: cell || " " }] }]
5060
+ }))
5061
+ };
5062
+ currentTableRows.push(headerRow);
5063
+ continue;
5064
+ }
5065
+ if (trimmedLine.startsWith("|") && trimmedLine.endsWith("|") && !trimmedLine.startsWith("||")) {
5066
+ inTable = true;
5067
+ const cells = trimmedLine.slice(1, -1).split("|").map((cell) => cell.trim());
5068
+ const dataRow = {
5069
+ type: "tableRow",
5070
+ content: cells.map((cell) => ({
5071
+ type: "tableCell",
5072
+ attrs: {},
5073
+ content: [{ type: "paragraph", content: [{ type: "text", text: cell || " " }] }]
5074
+ }))
5075
+ };
5076
+ currentTableRows.push(dataRow);
5077
+ continue;
5078
+ }
5079
+ if (inTable && currentTableRows.length > 0) {
5080
+ const table = {
5081
+ type: "table",
5082
+ attrs: { isNumberColumnEnabled: false, layout: "default" },
5083
+ content: currentTableRows
5084
+ };
5085
+ content.push(table);
5086
+ currentTableRows = [];
5087
+ inTable = false;
5088
+ }
5089
+ if (trimmedLine) {
5090
+ content.push({
5091
+ type: "paragraph",
5092
+ content: [{ type: "text", text: trimmedLine }]
5093
+ });
5094
+ }
5095
+ }
5096
+ if (currentTableRows.length > 0) {
5097
+ const table = {
5098
+ type: "table",
5099
+ attrs: { isNumberColumnEnabled: false, layout: "default" },
5100
+ content: currentTableRows
5101
+ };
5102
+ content.push(table);
5103
+ }
5104
+ if (content.length === 0) {
5105
+ content.push({ type: "paragraph", content: [{ type: "text", text: " " }] });
5106
+ }
5107
+ return { type: "doc", version: 1, content };
5108
+ }
5109
+ function containsWikiTable(text) {
5110
+ return /^\|\|.+\|\|$/m.test(text) || /^\|(?!\|).+\|$/m.test(text);
5111
+ }
5044
5112
  var JiraApi = class {
5045
5113
  config;
5046
5114
  constructor(config) {
@@ -5120,16 +5188,21 @@ var JiraApi = class {
5120
5188
  ...customFields
5121
5189
  };
5122
5190
  if (description) {
5123
- fields.description = {
5124
- type: "doc",
5125
- version: 1,
5126
- content: [
5127
- {
5128
- type: "paragraph",
5129
- content: [{ type: "text", text: description }]
5130
- }
5131
- ]
5132
- };
5191
+ if (containsWikiTable(description)) {
5192
+ console.log("[JIRA-ADF] Converting wiki table to ADF", { length: description.length });
5193
+ fields.description = wikiMarkupToAdf(description);
5194
+ } else {
5195
+ fields.description = {
5196
+ type: "doc",
5197
+ version: 1,
5198
+ content: [
5199
+ {
5200
+ type: "paragraph",
5201
+ content: [{ type: "text", text: description }]
5202
+ }
5203
+ ]
5204
+ };
5205
+ }
5133
5206
  }
5134
5207
  if (assignee) {
5135
5208
  fields.assignee = { id: assignee };
@@ -5155,16 +5228,21 @@ var JiraApi = class {
5155
5228
  fields.summary = summary;
5156
5229
  }
5157
5230
  if (description) {
5158
- fields.description = {
5159
- type: "doc",
5160
- version: 1,
5161
- content: [
5162
- {
5163
- type: "paragraph",
5164
- content: [{ type: "text", text: description }]
5165
- }
5166
- ]
5167
- };
5231
+ if (containsWikiTable(description)) {
5232
+ console.log("[JIRA-ADF] Converting wiki table to ADF (update)", { length: description.length });
5233
+ fields.description = wikiMarkupToAdf(description);
5234
+ } else {
5235
+ fields.description = {
5236
+ type: "doc",
5237
+ version: 1,
5238
+ content: [
5239
+ {
5240
+ type: "paragraph",
5241
+ content: [{ type: "text", text: description }]
5242
+ }
5243
+ ]
5244
+ };
5245
+ }
5168
5246
  }
5169
5247
  if (labels) {
5170
5248
  fields.labels = labels;
@@ -5324,16 +5402,21 @@ var JiraApi = class {
5324
5402
  issuetype: { name: issueTypeName }
5325
5403
  };
5326
5404
  if (description) {
5327
- fields.description = {
5328
- type: "doc",
5329
- version: 1,
5330
- content: [
5331
- {
5332
- type: "paragraph",
5333
- content: [{ type: "text", text: description }]
5334
- }
5335
- ]
5336
- };
5405
+ if (containsWikiTable(description)) {
5406
+ console.log("[JIRA-ADF] Converting wiki table to ADF (bulk)", { length: description.length });
5407
+ fields.description = wikiMarkupToAdf(description);
5408
+ } else {
5409
+ fields.description = {
5410
+ type: "doc",
5411
+ version: 1,
5412
+ content: [
5413
+ {
5414
+ type: "paragraph",
5415
+ content: [{ type: "text", text: description }]
5416
+ }
5417
+ ]
5418
+ };
5419
+ }
5337
5420
  }
5338
5421
  if (assignee) {
5339
5422
  fields.assignee = { id: assignee };
@@ -6149,6 +6232,8 @@ export {
6149
6232
  formatUser,
6150
6233
  formatTransitionResult,
6151
6234
  formatUserList,
6235
+ wikiMarkupToAdf,
6236
+ containsWikiTable,
6152
6237
  JiraApi,
6153
6238
  getErrorMessage,
6154
6239
  getAtlassianConfig,
@@ -6,12 +6,12 @@ import {
6
6
  getSettingsByNames,
7
7
  obfuscateApiKey,
8
8
  secureParameters
9
- } from "./chunk-DNSBC3LO.js";
9
+ } from "./chunk-KPBWTYME.js";
10
10
  import {
11
11
  ApiKeyType,
12
12
  MementoTier,
13
13
  isSupportedEmbeddingModel
14
- } from "./chunk-H6SHASMZ.js";
14
+ } from "./chunk-F2LBB4TN.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
17
17
  import { z } from "zod";
@@ -16,7 +16,7 @@ import {
16
16
  dayjsConfig_default,
17
17
  extractSnippetMeta,
18
18
  settingsMap
19
- } from "./chunk-H6SHASMZ.js";
19
+ } from "./chunk-F2LBB4TN.js";
20
20
 
21
21
  // ../../b4m-core/packages/utils/dist/src/storage/S3Storage.js
22
22
  import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3";
@@ -7,11 +7,11 @@ import {
7
7
  getSettingsMap,
8
8
  getSettingsValue,
9
9
  secureParameters
10
- } from "./chunk-DNSBC3LO.js";
10
+ } from "./chunk-KPBWTYME.js";
11
11
  import {
12
12
  KnowledgeType,
13
13
  SupportedFabFileMimeTypes
14
- } from "./chunk-H6SHASMZ.js";
14
+ } from "./chunk-F2LBB4TN.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/fabFileService/create.js
17
17
  import { z } from "zod";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  createFabFile,
4
4
  createFabFileSchema
5
- } from "./chunk-YXHQN7SK.js";
6
- import "./chunk-DNSBC3LO.js";
5
+ } from "./chunk-OK3T7VKG.js";
6
+ import "./chunk-KPBWTYME.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-H6SHASMZ.js";
8
+ import "./chunk-F2LBB4TN.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  createFabFile,