@s-hirano-ist/s-scripts 4.2.0 → 4.4.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.
@@ -1,37 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- deleteCollection,
5
- getQdrantClient
6
- } from "../chunk-J4VLH4VA.js";
4
+ runCli
5
+ } from "../chunk-KKWRXAAY.js";
7
6
  import "../chunk-JZOR5GA2.js";
8
7
 
9
8
  // src/rag/delete-collection.ts
10
- async function main() {
11
- const collectionName = process.argv[2];
12
- if (!collectionName) {
13
- console.error(
14
- "Usage: rag-delete-collection <collection-name>\nExample: rag-delete-collection knowledge_v1"
15
- );
16
- process.exit(1);
17
- }
18
- if (!process.env.QDRANT_URL) {
19
- throw new Error("QDRANT_URL environment variable is required.");
20
- }
21
- const qdrant = getQdrantClient();
22
- const collections = await qdrant.getCollections();
23
- const exists = collections.collections.some((c) => c.name === collectionName);
24
- if (!exists) {
25
- console.log(
26
- `Collection "${collectionName}" does not exist. Nothing to delete.`
27
- );
28
- return;
29
- }
30
- console.log(`Deleting collection "${collectionName}"...`);
31
- await deleteCollection(collectionName);
32
- console.log(`Collection "${collectionName}" deleted successfully.`);
33
- }
34
- main().catch((error) => {
35
- console.error("Failed to delete collection:", error);
36
- process.exit(1);
9
+ await runCli("rag-delete-collection", async () => {
10
+ const { main } = await import("../chunk-67LIMNXH.js");
11
+ await main();
37
12
  });
@@ -1,386 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- parseMarkdownFrontmatter
5
- } from "../chunk-HDYQV2Y2.js";
6
- import {
7
- globPaths
8
- } from "../chunk-AJMTRCPJ.js";
9
- import {
10
- RAG_CONFIG,
11
- deletePointsByChunkIds,
12
- ensureCollection,
13
- getCollectionStats,
14
- getExistingHashes,
15
- listAllChunkIds,
16
- upsertPoints
17
- } from "../chunk-J4VLH4VA.js";
4
+ runCli
5
+ } from "../chunk-KKWRXAAY.js";
18
6
  import "../chunk-JZOR5GA2.js";
19
7
 
20
- // ../search/dist/chunker.js
21
- import { createHash } from "node:crypto";
22
- function generateHash(content) {
23
- return createHash("sha256").update(content).digest("hex").slice(0, 16);
24
- }
25
- function generateChunkId(docId, index) {
26
- return `${docId}#${index}`;
27
- }
28
- function parseJsonArticle(filePath, content) {
29
- const json = JSON.parse(content);
30
- const docId = `file:${filePath}`;
31
- const chunks = [];
32
- for (let i = 0; i < json.body.length; i++) {
33
- const item = json.body[i];
34
- const textParts = [];
35
- if (item.title)
36
- textParts.push(item.title);
37
- if (item.ogTitle && item.ogTitle !== item.title)
38
- textParts.push(item.ogTitle);
39
- if (item.ogDescription)
40
- textParts.push(item.ogDescription);
41
- if (item.quote)
42
- textParts.push(item.quote);
43
- const text = textParts.join("\n");
44
- if (!text.trim())
45
- continue;
46
- const chunkId = generateChunkId(docId, i);
47
- chunks.push({
48
- type: "bookmark_json",
49
- content_type: "articles",
50
- top_heading: json.heading,
51
- doc_id: docId,
52
- chunk_id: chunkId,
53
- title: item.title || item.ogTitle || "Untitled",
54
- url: item.url,
55
- heading_path: [json.heading],
56
- text,
57
- content_hash: generateHash(text)
58
- });
59
- }
60
- return chunks;
61
- }
62
- function parseFrontmatter(content) {
63
- const parsed = parseMarkdownFrontmatter(content);
64
- const frontmatter = {
65
- heading: typeof parsed.data.heading === "string" ? parsed.data.heading : "unknown"
66
- };
67
- if (typeof parsed.data.description === "string") {
68
- frontmatter.description = parsed.data.description;
69
- }
70
- if (typeof parsed.data.draft === "boolean") {
71
- frontmatter.draft = parsed.data.draft;
72
- }
73
- return { frontmatter, body: parsed.content };
74
- }
75
- function pushPreambleSection(state) {
76
- if (state.preambleContent.trim()) {
77
- state.sections.push({
78
- headingPath: [],
79
- title: "",
80
- content: state.preambleContent,
81
- level: 0
82
- });
83
- }
84
- }
85
- function handleHeadingLine(state, headingMatch) {
86
- if (!state.preambleDone) {
87
- state.preambleDone = true;
88
- pushPreambleSection(state);
89
- }
90
- if (state.currentSection?.content.trim()) {
91
- state.sections.push(state.currentSection);
92
- }
93
- const level = headingMatch[1].length;
94
- const title = headingMatch[2];
95
- const headingStack = state.headingStack;
96
- let top = headingStack.at(-1);
97
- while (top && top.level >= level) {
98
- headingStack.pop();
99
- top = headingStack.at(-1);
100
- }
101
- headingStack.push({ level, title });
102
- state.currentSection = {
103
- headingPath: headingStack.map((h) => h.title),
104
- title,
105
- content: "",
106
- level
107
- };
108
- }
109
- function splitMarkdownByHeadings(content) {
110
- const state = {
111
- sections: [],
112
- currentSection: null,
113
- headingStack: [],
114
- // Preamble buffer (content before first H2/H3)
115
- preambleContent: "",
116
- preambleDone: false
117
- };
118
- for (const line of content.split("\n")) {
119
- if (/^#\s+\S/u.test(line)) {
120
- continue;
121
- }
122
- const headingMatch = /^(#{2,3})\s+(\S.*)$/u.exec(line);
123
- if (headingMatch) {
124
- handleHeadingLine(state, headingMatch);
125
- } else if (!state.preambleDone) {
126
- state.preambleContent += `${line}
127
- `;
128
- } else if (state.currentSection) {
129
- state.currentSection.content += `${line}
130
- `;
131
- }
132
- }
133
- if (!state.preambleDone) {
134
- pushPreambleSection(state);
135
- }
136
- if (state.currentSection?.content.trim()) {
137
- state.sections.push(state.currentSection);
138
- }
139
- return state.sections;
140
- }
141
- function splitByParagraphs(text, maxLength) {
142
- if (text.length <= maxLength) {
143
- return [text];
144
- }
145
- const paragraphs = text.split(/\n{2,}/u);
146
- const chunks = [];
147
- let currentChunk = "";
148
- for (const para of paragraphs) {
149
- if (currentChunk.length + para.length > maxLength && currentChunk) {
150
- chunks.push(currentChunk.trim());
151
- currentChunk = para;
152
- } else {
153
- currentChunk += (currentChunk ? "\n\n" : "") + para;
154
- }
155
- }
156
- if (currentChunk.trim()) {
157
- chunks.push(currentChunk.trim());
158
- }
159
- return chunks;
160
- }
161
- function parseMarkdownWithDocId(docId, content, contentType = "notes") {
162
- const { frontmatter, body } = parseFrontmatter(content);
163
- const chunks = [];
164
- if (frontmatter.draft) {
165
- return [];
166
- }
167
- const sections = splitMarkdownByHeadings(body);
168
- let chunkIndex = 0;
169
- for (const section of sections) {
170
- const textChunks = splitByParagraphs(section.content, RAG_CONFIG.chunking.maxChunkLength);
171
- for (const text of textChunks) {
172
- if (!text.trim())
173
- continue;
174
- const isPreamble = section.level === 0 && section.title === "";
175
- const sectionTitle = isPreamble ? frontmatter.description ?? frontmatter.heading : section.title;
176
- const fullHeadingPath = isPreamble ? [frontmatter.heading] : [frontmatter.heading, ...section.headingPath];
177
- const chunkId = generateChunkId(docId, chunkIndex);
178
- chunks.push({
179
- type: "markdown_note",
180
- content_type: contentType,
181
- top_heading: frontmatter.heading,
182
- doc_id: docId,
183
- chunk_id: chunkId,
184
- title: sectionTitle,
185
- heading_path: fullHeadingPath,
186
- text,
187
- content_hash: generateHash(text)
188
- });
189
- chunkIndex++;
190
- }
191
- }
192
- return chunks;
193
- }
194
- function parseMarkdown(filePath, content, contentType = "notes") {
195
- return parseMarkdownWithDocId(`file:${filePath}`, content, contentType);
196
- }
197
-
198
- // ../search/dist/ingest.js
199
- import { setTimeout } from "node:timers/promises";
200
- var BATCH_SIZE = 20;
201
- var MAX_RETRIES = 3;
202
- var RETRY_DELAY_MS = 2e3;
203
- async function withRetry(fn, retries = MAX_RETRIES) {
204
- for (let i = 0; i < retries; i++) {
205
- try {
206
- return await fn();
207
- } catch (error) {
208
- if (i === retries - 1)
209
- throw error;
210
- console.log(` Retry ${i + 1}/${retries} after error...`);
211
- await setTimeout(RETRY_DELAY_MS);
212
- }
213
- }
214
- throw new Error("Unreachable");
215
- }
216
- async function ingestChunks(chunks, options) {
217
- console.log(`Total chunks: ${chunks.length}
218
- `);
219
- let changedChunks;
220
- let skippedChunks;
221
- if (options.force) {
222
- changedChunks = chunks;
223
- skippedChunks = 0;
224
- } else {
225
- console.log("Checking for changes...");
226
- const chunkIds = chunks.map((c) => c.chunk_id);
227
- const existingHashes = await getExistingHashes(chunkIds);
228
- changedChunks = chunks.filter((chunk) => {
229
- const existingHash = existingHashes.get(chunk.chunk_id);
230
- return existingHash !== chunk.content_hash;
231
- });
232
- skippedChunks = chunks.length - changedChunks.length;
233
- }
234
- console.log(`Changed chunks: ${changedChunks.length}`);
235
- console.log(`Skipped (unchanged): ${skippedChunks}
236
- `);
237
- if (changedChunks.length === 0) {
238
- console.log("No changes detected. Done!");
239
- return {
240
- totalChunks: chunks.length,
241
- changedChunks: 0,
242
- skippedChunks
243
- };
244
- }
245
- console.log("Upserting to Qdrant...");
246
- let processed = 0;
247
- for (let i = 0; i < changedChunks.length; i += BATCH_SIZE) {
248
- const batch = changedChunks.slice(i, i + BATCH_SIZE);
249
- const points = batch.map((chunk) => ({
250
- id: chunk.chunk_id,
251
- text: chunk.text,
252
- payload: chunk
253
- }));
254
- await withRetry(() => upsertPoints(points));
255
- processed += batch.length;
256
- console.log(` Progress: ${processed}/${changedChunks.length}`);
257
- await setTimeout(100);
258
- }
259
- return {
260
- totalChunks: chunks.length,
261
- changedChunks: changedChunks.length,
262
- skippedChunks
263
- };
264
- }
265
- async function pruneOrphans(currentChunkIds) {
266
- const existingIds = await listAllChunkIds();
267
- const currentSet = new Set(currentChunkIds);
268
- const orphanIds = existingIds.filter((id) => !currentSet.has(id));
269
- console.log(`Existing Qdrant chunks: ${existingIds.length}`);
270
- console.log(`Orphan chunks to delete: ${orphanIds.length}`);
271
- if (orphanIds.length === 0) {
272
- return { deletedCount: 0 };
273
- }
274
- let deleted = 0;
275
- for (let i = 0; i < orphanIds.length; i += BATCH_SIZE) {
276
- const batch = orphanIds.slice(i, i + BATCH_SIZE);
277
- await withRetry(() => deletePointsByChunkIds(batch));
278
- deleted += batch.length;
279
- console.log(` Prune progress: ${deleted}/${orphanIds.length}`);
280
- await setTimeout(100);
281
- }
282
- return { deletedCount: deleted };
283
- }
284
-
285
- // src/rag/ingest.ts
286
- import { readFileSync } from "node:fs";
287
-
288
- // src/rag/ingest-config.ts
289
- var INGEST_CONFIG = {
290
- paths: {
291
- notes: "markdown/note/**/*.md",
292
- books: "markdown/book/**/*.md",
293
- articles: "json/article/**/*.json"
294
- }
295
- };
296
-
297
8
  // src/rag/ingest.ts
298
- async function listFiles() {
299
- const files = [];
300
- const articleFiles = await globPaths(INGEST_CONFIG.paths.articles);
301
- for (const path of articleFiles) {
302
- files.push({ path, type: "json", contentType: "articles" });
303
- }
304
- const noteFiles = await globPaths(INGEST_CONFIG.paths.notes);
305
- for (const path of noteFiles) {
306
- files.push({ path, type: "markdown", contentType: "notes" });
307
- }
308
- const bookFiles = await globPaths(INGEST_CONFIG.paths.books);
309
- for (const path of bookFiles) {
310
- files.push({ path, type: "markdown", contentType: "books" });
311
- }
312
- return files;
313
- }
314
- function parseFile(file) {
315
- const content = readFileSync(file.path, "utf-8");
316
- if (file.type === "json") {
317
- return parseJsonArticle(file.path, content);
318
- }
319
- return parseMarkdown(file.path, content, file.contentType);
320
- }
321
- async function ingest(flags) {
322
- console.log("Starting ingest...\n");
323
- if (flags.dryRun) {
324
- console.log("Dry-run mode: no writes to Qdrant\n");
325
- } else {
326
- await ensureCollection();
327
- const initialStats = await getCollectionStats();
328
- console.log(`Initial points count: ${initialStats.pointsCount}
329
- `);
330
- }
331
- if (flags.force) {
332
- console.log("Force mode enabled: skipping change detection\n");
333
- }
334
- const files = await listFiles();
335
- const articleCount = files.filter((f) => f.contentType === "articles").length;
336
- const noteCount = files.filter((f) => f.contentType === "notes").length;
337
- const bookCount = files.filter((f) => f.contentType === "books").length;
338
- console.log(`Found ${files.length} files to process`);
339
- console.log(` - Articles: ${articleCount}`);
340
- console.log(` - Notes: ${noteCount}`);
341
- console.log(` - Books: ${bookCount}
342
- `);
343
- console.log("Parsing files...");
344
- const allChunks = [];
345
- for (const file of files) {
346
- try {
347
- const chunks = parseFile(file);
348
- allChunks.push(...chunks);
349
- } catch (error) {
350
- console.error(`Error parsing ${file.path}:`, error);
351
- }
352
- }
353
- console.log(`Total chunks parsed: ${allChunks.length}`);
354
- if (flags.dryRun) {
355
- console.log("Dry-run complete. Skipping upsert and prune.");
356
- return;
357
- }
358
- const result = await ingestChunks(allChunks, { force: flags.force });
359
- const pruneResult = await pruneOrphans(allChunks.map((c) => c.chunk_id));
360
- const finalStats = await getCollectionStats();
361
- console.log(`
362
- Final points count: ${finalStats.pointsCount}`);
363
- console.log(
364
- `Ingest completed! (${result.changedChunks} changed, ${result.skippedChunks} skipped, ${pruneResult.deletedCount} pruned)`
365
- );
366
- }
367
- async function main() {
368
- if (!process.env.QDRANT_URL) {
369
- console.error("QDRANT_URL environment variable is required.");
370
- process.exit(1);
371
- }
372
- const flags = {
373
- force: process.argv.includes("--force"),
374
- dryRun: process.argv.includes("--dry-run")
375
- };
376
- try {
377
- await ingest(flags);
378
- } catch (error) {
379
- console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
380
- process.exit(2);
381
- }
382
- }
383
- main().catch((error) => {
384
- console.error(error);
385
- process.exit(2);
9
+ await runCli("rag-ingest", async () => {
10
+ const { main } = await import("../chunk-BTI7M2UJ.js");
11
+ await main();
386
12
  });
@@ -1,91 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
3
3
  import {
4
- ensureCollection,
5
- search
6
- } from "../chunk-J4VLH4VA.js";
4
+ runCli
5
+ } from "../chunk-KKWRXAAY.js";
7
6
  import "../chunk-JZOR5GA2.js";
8
7
 
9
8
  // src/rag/search.ts
10
- function parseArgs() {
11
- const args = process.argv.slice(2);
12
- const options = {};
13
- const positional = [];
14
- for (let i = 0; i < args.length; i++) {
15
- const arg = args[i];
16
- if (arg === "--top-k" && i + 1 < args.length) {
17
- options.topK = Number(args[++i]);
18
- } else if (arg === "--type" && i + 1 < args.length) {
19
- options.type = args[++i];
20
- } else if (arg === "--heading" && i + 1 < args.length) {
21
- options.heading = args[++i];
22
- } else if (arg === "--content-type" && i + 1 < args.length) {
23
- const value = args[++i];
24
- const types = value.split(",");
25
- options.contentType = types.length === 1 ? types[0] : types;
26
- } else {
27
- positional.push(arg);
28
- }
29
- }
30
- const query = positional.join(" ");
31
- if (!query) {
32
- console.error(
33
- "Usage: rag-search <query> [--top-k N] [--type markdown_note|bookmark_json] [--heading HEADING] [--content-type articles|books|notes]"
34
- );
35
- process.exit(1);
36
- }
37
- return { query, options };
38
- }
39
- async function searchContent(query, options = {}) {
40
- const results = await search(query, {
41
- topK: options.topK,
42
- filter: {
43
- type: options.type,
44
- top_heading: options.heading,
45
- content_type: options.contentType
46
- }
47
- });
48
- return { results, query, totalResults: results.length };
49
- }
50
- async function search2() {
51
- const { query, options } = parseArgs();
52
- console.log(`Searching for: "${query}"`);
53
- if (options.topK) console.log(` top-k: ${options.topK}`);
54
- if (options.type) console.log(` type: ${options.type}`);
55
- if (options.heading) console.log(` heading: ${options.heading}`);
56
- if (options.contentType)
57
- console.log(
58
- ` content-type: ${Array.isArray(options.contentType) ? options.contentType.join(",") : options.contentType}`
59
- );
60
- console.log();
61
- await ensureCollection();
62
- const response = await searchContent(query, options);
63
- console.log(`Found ${response.totalResults} results:
64
- `);
65
- for (const [i, result] of response.results.entries()) {
66
- console.log(`--- Result ${i + 1} (score: ${result.score.toFixed(4)}) ---`);
67
- console.log(`Title: ${result.title}`);
68
- if (result.url) console.log(`URL: ${result.url}`);
69
- console.log(`Type: ${result.type}`);
70
- console.log(`Content-Type: ${result.content_type}`);
71
- console.log(`Heading: ${result.heading_path.join(" > ")}`);
72
- console.log(`
73
- ${result.text}
74
- `);
75
- }
76
- }
77
- async function main() {
78
- if (!process.env.QDRANT_URL) {
79
- throw new Error("QDRANT_URL environment variable is required.");
80
- }
81
- try {
82
- await search2();
83
- } catch (error) {
84
- console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
85
- process.exit(1);
86
- }
87
- }
88
- main().catch((error) => {
89
- console.error(error);
90
- process.exit(1);
9
+ await runCli("rag-search", async () => {
10
+ const { main } = await import("../chunk-SFKQ2RAP.js");
11
+ await main();
91
12
  });
@@ -9,28 +9,22 @@ import {
9
9
  makeUserId
10
10
  } from "./chunk-RLAYINCA.js";
11
11
  import {
12
- createPushoverService
13
- } from "./chunk-7PVU2Z32.js";
12
+ cliNotifications,
13
+ runCli
14
+ } from "./chunk-KKWRXAAY.js";
14
15
  import "./chunk-JZOR5GA2.js";
15
16
 
16
17
  // src/reset-articles.ts
17
18
  async function main() {
18
19
  const env = {
19
20
  DATABASE_URL: process.env.DATABASE_URL,
20
- PUSHOVER_URL: process.env.PUSHOVER_URL,
21
- PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
22
- PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
23
21
  USERNAME_TO_EXPORT: process.env.USERNAME_TO_EXPORT
24
22
  };
25
23
  if (Object.values(env).some((v) => !v)) {
26
24
  throw new Error("Required environment variables are not set.");
27
25
  }
28
26
  const prisma = createPrismaClient(env.DATABASE_URL ?? "");
29
- const notificationService = createPushoverService({
30
- url: env.PUSHOVER_URL ?? "",
31
- userKey: env.PUSHOVER_USER_KEY ?? "",
32
- appToken: env.PUSHOVER_APP_TOKEN ?? ""
33
- });
27
+ const notificationService = cliNotifications;
34
28
  const userId = makeUserId(env.USERNAME_TO_EXPORT ?? "");
35
29
  async function resetArticles() {
36
30
  const commandRepository = createArticlesCommandRepository(prisma);
@@ -45,18 +39,9 @@ async function main() {
45
39
  await resetArticles();
46
40
  await notificationService.notifyInfo("reset-articles completed", {
47
41
  caller: "reset-articles"
48
- }).catch((error) => console.error("\u901A\u77E5\u5931\u6557:", error));
49
- } catch (error) {
50
- console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
51
- await notificationService.notifyError(`reset-articles failed: ${String(error)}`, {
52
- caller: "reset-articles"
53
- }).catch((notifyError) => console.error("\u901A\u77E5\u5931\u6557:", notifyError));
54
- process.exitCode = 1;
42
+ });
55
43
  } finally {
56
44
  await prisma.$disconnect();
57
45
  }
58
46
  }
59
- main().catch((error) => {
60
- console.error(error);
61
- process.exit(1);
62
- });
47
+ await runCli("reset-articles", main);
@@ -9,28 +9,22 @@ import {
9
9
  makeUserId
10
10
  } from "./chunk-RLAYINCA.js";
11
11
  import {
12
- createPushoverService
13
- } from "./chunk-7PVU2Z32.js";
12
+ cliNotifications,
13
+ runCli
14
+ } from "./chunk-KKWRXAAY.js";
14
15
  import "./chunk-JZOR5GA2.js";
15
16
 
16
17
  // src/reset-books.ts
17
18
  async function main() {
18
19
  const env = {
19
20
  DATABASE_URL: process.env.DATABASE_URL,
20
- PUSHOVER_URL: process.env.PUSHOVER_URL,
21
- PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
22
- PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
23
21
  USERNAME_TO_EXPORT: process.env.USERNAME_TO_EXPORT
24
22
  };
25
23
  if (Object.values(env).some((v) => !v)) {
26
24
  throw new Error("Required environment variables are not set.");
27
25
  }
28
26
  const prisma = createPrismaClient(env.DATABASE_URL ?? "");
29
- const notificationService = createPushoverService({
30
- url: env.PUSHOVER_URL ?? "",
31
- userKey: env.PUSHOVER_USER_KEY ?? "",
32
- appToken: env.PUSHOVER_APP_TOKEN ?? ""
33
- });
27
+ const notificationService = cliNotifications;
34
28
  const userId = makeUserId(env.USERNAME_TO_EXPORT ?? "");
35
29
  async function resetBooks() {
36
30
  const commandRepository = createBooksCommandRepository(prisma);
@@ -45,18 +39,9 @@ async function main() {
45
39
  await resetBooks();
46
40
  await notificationService.notifyInfo("reset-books completed", {
47
41
  caller: "reset-books"
48
- }).catch((error) => console.error("\u901A\u77E5\u5931\u6557:", error));
49
- } catch (error) {
50
- console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
51
- await notificationService.notifyError(`reset-books failed: ${String(error)}`, {
52
- caller: "reset-books"
53
- }).catch((notifyError) => console.error("\u901A\u77E5\u5931\u6557:", notifyError));
54
- process.exitCode = 1;
42
+ });
55
43
  } finally {
56
44
  await prisma.$disconnect();
57
45
  }
58
46
  }
59
- main().catch((error) => {
60
- console.error(error);
61
- process.exit(1);
62
- });
47
+ await runCli("reset-books", main);
@@ -9,28 +9,22 @@ import {
9
9
  makeUserId
10
10
  } from "./chunk-RLAYINCA.js";
11
11
  import {
12
- createPushoverService
13
- } from "./chunk-7PVU2Z32.js";
12
+ cliNotifications,
13
+ runCli
14
+ } from "./chunk-KKWRXAAY.js";
14
15
  import "./chunk-JZOR5GA2.js";
15
16
 
16
17
  // src/reset-images.ts
17
18
  async function main() {
18
19
  const env = {
19
20
  DATABASE_URL: process.env.DATABASE_URL,
20
- PUSHOVER_URL: process.env.PUSHOVER_URL,
21
- PUSHOVER_USER_KEY: process.env.PUSHOVER_USER_KEY,
22
- PUSHOVER_APP_TOKEN: process.env.PUSHOVER_APP_TOKEN,
23
21
  USERNAME_TO_EXPORT: process.env.USERNAME_TO_EXPORT
24
22
  };
25
23
  if (Object.values(env).some((v) => !v)) {
26
24
  throw new Error("Required environment variables are not set.");
27
25
  }
28
26
  const prisma = createPrismaClient(env.DATABASE_URL ?? "");
29
- const notificationService = createPushoverService({
30
- url: env.PUSHOVER_URL ?? "",
31
- userKey: env.PUSHOVER_USER_KEY ?? "",
32
- appToken: env.PUSHOVER_APP_TOKEN ?? ""
33
- });
27
+ const notificationService = cliNotifications;
34
28
  const userId = makeUserId(env.USERNAME_TO_EXPORT ?? "");
35
29
  async function resetImages() {
36
30
  const commandRepository = createImagesCommandRepository(prisma);
@@ -45,18 +39,9 @@ async function main() {
45
39
  await resetImages();
46
40
  await notificationService.notifyInfo("reset-images completed", {
47
41
  caller: "reset-images"
48
- }).catch((error) => console.error("\u901A\u77E5\u5931\u6557:", error));
49
- } catch (error) {
50
- console.error("\u274C \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:", error);
51
- await notificationService.notifyError(`reset-images failed: ${String(error)}`, {
52
- caller: "reset-images"
53
- }).catch((notifyError) => console.error("\u901A\u77E5\u5931\u6557:", notifyError));
54
- process.exitCode = 1;
42
+ });
55
43
  } finally {
56
44
  await prisma.$disconnect();
57
45
  }
58
46
  }
59
- main().catch((error) => {
60
- console.error(error);
61
- process.exit(1);
62
- });
47
+ await runCli("reset-images", main);