@nahisaho/katashiro 0.1.6 → 0.1.8
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/AGENTS.md +1 -1
- package/CLAUDE.md +1 -1
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +221 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/cli.ts +236 -0
- package/src/index.ts +2 -1
package/AGENTS.md
CHANGED
package/CLAUDE.md
CHANGED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO CLI - AI Research & Analysis Tool
|
|
4
|
+
*
|
|
5
|
+
* @requirement REQ-CLI-001
|
|
6
|
+
* @design DES-KATASHIRO-001 §2.6 CLI Interface
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { WebSearchClient, WebScraper, TextAnalyzer, EntityExtractor, SummaryGenerator, isOk, isErr, generateId, formatTimestamp } from './index.js';
|
|
10
|
+
/**
|
|
11
|
+
* CLI用にContentオブジェクトを作成
|
|
12
|
+
*/
|
|
13
|
+
function createContent(title, body, url = '') {
|
|
14
|
+
return {
|
|
15
|
+
id: generateId('CLI'),
|
|
16
|
+
type: 'article',
|
|
17
|
+
title,
|
|
18
|
+
body,
|
|
19
|
+
sources: url ? [{
|
|
20
|
+
id: generateId('SRC'),
|
|
21
|
+
url,
|
|
22
|
+
metadata: { title },
|
|
23
|
+
fetchedAt: formatTimestamp()
|
|
24
|
+
}] : [],
|
|
25
|
+
createdAt: formatTimestamp(),
|
|
26
|
+
updatedAt: formatTimestamp(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const program = new Command();
|
|
30
|
+
program
|
|
31
|
+
.name('katashiro')
|
|
32
|
+
.description('KATASHIRO CLI - AI Research & Analysis Tool')
|
|
33
|
+
.version('0.1.8');
|
|
34
|
+
// 検索コマンド
|
|
35
|
+
program
|
|
36
|
+
.command('search <query>')
|
|
37
|
+
.description('Web検索を実行')
|
|
38
|
+
.option('-n, --num <number>', '結果の最大件数', '10')
|
|
39
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
40
|
+
.action(async (query, options) => {
|
|
41
|
+
try {
|
|
42
|
+
const client = new WebSearchClient();
|
|
43
|
+
const result = await client.search(query, { maxResults: parseInt(options.num, 10) });
|
|
44
|
+
if (isErr(result)) {
|
|
45
|
+
console.error('❌ 検索エラー:', result.error.message);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const results = result.value;
|
|
49
|
+
if (options.format === 'json') {
|
|
50
|
+
console.log(JSON.stringify(results, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(`\n🔍 "${query}" の検索結果: ${results.length}件\n`);
|
|
54
|
+
for (const r of results) {
|
|
55
|
+
console.log(`📄 ${r.title}`);
|
|
56
|
+
console.log(` ${r.url}`);
|
|
57
|
+
if (r.snippet) {
|
|
58
|
+
console.log(` ${r.snippet.substring(0, 100)}...`);
|
|
59
|
+
}
|
|
60
|
+
console.log();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// スクレイピングコマンド
|
|
70
|
+
program
|
|
71
|
+
.command('scrape <url>')
|
|
72
|
+
.description('Webページの内容を取得')
|
|
73
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
74
|
+
.option('-s, --summary', '要約を表示', false)
|
|
75
|
+
.action(async (url, options) => {
|
|
76
|
+
try {
|
|
77
|
+
const scraper = new WebScraper();
|
|
78
|
+
const result = await scraper.scrape(url);
|
|
79
|
+
if (isErr(result)) {
|
|
80
|
+
console.error('❌ スクレイプエラー:', result.error.message);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
const page = result.value;
|
|
84
|
+
if (options.format === 'json') {
|
|
85
|
+
console.log(JSON.stringify(page, null, 2));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.log(`\n📄 ${page.title}`);
|
|
89
|
+
console.log(`🔗 ${page.url}`);
|
|
90
|
+
console.log('\n---\n');
|
|
91
|
+
if (options.summary) {
|
|
92
|
+
const summarizer = new SummaryGenerator();
|
|
93
|
+
const content = createContent(page.title, page.content, page.url);
|
|
94
|
+
const summary = await summarizer.generateSummary(content, { maxLength: 500 });
|
|
95
|
+
if (isOk(summary)) {
|
|
96
|
+
console.log('📝 要約:\n');
|
|
97
|
+
console.log(summary.value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.log(page.content.substring(0, 2000));
|
|
102
|
+
if (page.content.length > 2000) {
|
|
103
|
+
console.log(`\n... (${page.content.length - 2000}文字省略)`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// 分析コマンド
|
|
114
|
+
program
|
|
115
|
+
.command('analyze <text>')
|
|
116
|
+
.description('テキストを分析(感情分析)')
|
|
117
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
118
|
+
.action(async (text, options) => {
|
|
119
|
+
try {
|
|
120
|
+
const analyzer = new TextAnalyzer();
|
|
121
|
+
const content = createContent('CLI Input', text);
|
|
122
|
+
const result = await analyzer.analyze(content);
|
|
123
|
+
if (isErr(result)) {
|
|
124
|
+
console.error('❌ 分析エラー:', result.error.message);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
const analysis = result.value;
|
|
128
|
+
if (options.format === 'json') {
|
|
129
|
+
console.log(JSON.stringify(analysis, null, 2));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log('\n📊 テキスト分析結果\n');
|
|
133
|
+
console.log(`💬 感情: ${analysis.sentiment}`);
|
|
134
|
+
console.log(`📈 スコア: ${analysis.score.toFixed(2)}`);
|
|
135
|
+
console.log(`✅ 信頼度: ${(analysis.confidence * 100).toFixed(1)}%`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// エンティティ抽出コマンド
|
|
144
|
+
program
|
|
145
|
+
.command('extract <text>')
|
|
146
|
+
.description('テキストからエンティティを抽出')
|
|
147
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
148
|
+
.action(async (text, options) => {
|
|
149
|
+
try {
|
|
150
|
+
const extractor = new EntityExtractor();
|
|
151
|
+
const entities = await extractor.extract(text);
|
|
152
|
+
if (options.format === 'json') {
|
|
153
|
+
console.log(JSON.stringify(entities, null, 2));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
console.log('\n🔍 エンティティ抽出結果\n');
|
|
157
|
+
if (entities.persons.length > 0) {
|
|
158
|
+
console.log(`👤 人名: ${entities.persons.join(', ')}`);
|
|
159
|
+
}
|
|
160
|
+
if (entities.organizations.length > 0) {
|
|
161
|
+
console.log(`🏢 組織: ${entities.organizations.join(', ')}`);
|
|
162
|
+
}
|
|
163
|
+
if (entities.locations.length > 0) {
|
|
164
|
+
console.log(`📍 場所: ${entities.locations.join(', ')}`);
|
|
165
|
+
}
|
|
166
|
+
if (entities.dates.length > 0) {
|
|
167
|
+
console.log(`📅 日付: ${entities.dates.join(', ')}`);
|
|
168
|
+
}
|
|
169
|
+
if (entities.urls.length > 0) {
|
|
170
|
+
console.log(`🔗 URL: ${entities.urls.join(', ')}`);
|
|
171
|
+
}
|
|
172
|
+
if (entities.emails.length > 0) {
|
|
173
|
+
console.log(`📧 メール: ${entities.emails.join(', ')}`);
|
|
174
|
+
}
|
|
175
|
+
if (entities.phones.length > 0) {
|
|
176
|
+
console.log(`📞 電話: ${entities.phones.join(', ')}`);
|
|
177
|
+
}
|
|
178
|
+
if (entities.money.length > 0) {
|
|
179
|
+
console.log(`💰 金額: ${entities.money.join(', ')}`);
|
|
180
|
+
}
|
|
181
|
+
console.log(`\n📊 合計: ${entities.all.length}件のエンティティ`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
// 要約コマンド
|
|
190
|
+
program
|
|
191
|
+
.command('summarize <text>')
|
|
192
|
+
.description('テキストを要約')
|
|
193
|
+
.option('-l, --length <number>', '要約の最大文字数', '300')
|
|
194
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
195
|
+
.action(async (text, options) => {
|
|
196
|
+
try {
|
|
197
|
+
const summarizer = new SummaryGenerator();
|
|
198
|
+
const content = createContent('CLI Input', text);
|
|
199
|
+
const result = await summarizer.generateSummary(content, { maxLength: parseInt(options.length, 10) });
|
|
200
|
+
if (isErr(result)) {
|
|
201
|
+
const error = result.error;
|
|
202
|
+
console.error('❌ 要約エラー:', error.message);
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
const summary = result.value;
|
|
206
|
+
if (options.format === 'json') {
|
|
207
|
+
console.log(JSON.stringify({ summary, originalLength: text.length }, null, 2));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.log('\n📝 要約結果\n');
|
|
211
|
+
console.log(summary);
|
|
212
|
+
console.log(`\n(元のテキスト: ${text.length}文字 → 要約: ${summary.length}文字)`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
program.parse();
|
|
221
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGpJ;;GAEG;AACH,SAAS,aAAa,CAAC,KAAa,EAAE,IAAY,EAAE,MAAc,EAAE;IAClE,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC;QACrB,IAAI,EAAE,SAAS;QACf,KAAK;QACL,IAAI;QACJ,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBACd,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC;gBACrB,GAAG;gBACH,QAAQ,EAAE,EAAE,KAAK,EAAE;gBACnB,SAAS,EAAE,eAAe,EAAE;aAC7B,CAAC,CAAC,CAAC,CAAC,EAAE;QACP,SAAS,EAAE,eAAe,EAAE;QAC5B,SAAS,EAAE,eAAe,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KAC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AC;YAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACjF,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,MAAM,YAAY,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as core from '@nahisaho/katashiro-core';
|
|
2
|
-
export { Result, ok, err, isOk, isErr, Logger, LogLevel, generateId } from '@nahisaho/katashiro-core';
|
|
2
|
+
export { Result, ok, err, isOk, isErr, Logger, LogLevel, generateId, formatTimestamp } from '@nahisaho/katashiro-core';
|
|
3
|
+
export type { Content, Source, ContentType, ID, Timestamp } from '@nahisaho/katashiro-core';
|
|
3
4
|
export * as collector from '@nahisaho/katashiro-collector';
|
|
4
5
|
export { WebScraper, APIClient, FeedReader, WebSearchClient, MediaExtractor, YouTubeTranscript } from '@nahisaho/katashiro-collector';
|
|
5
6
|
export * as analyzer from '@nahisaho/katashiro-analyzer';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRo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AK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Re-exports all KATASHIRO packages for convenient installation
|
|
3
3
|
// Core - Result types, Logger, utilities
|
|
4
4
|
export * as core from '@nahisaho/katashiro-core';
|
|
5
|
-
export { ok, err, isOk, isErr, Logger, generateId } from '@nahisaho/katashiro-core';
|
|
5
|
+
export { ok, err, isOk, isErr, Logger, generateId, formatTimestamp } from '@nahisaho/katashiro-core';
|
|
6
6
|
// Collector - Web scraping, API, feeds
|
|
7
7
|
export * as collector from '@nahisaho/katashiro-collector';
|
|
8
8
|
export { WebScraper, APIClient, FeedReader, WebSearchClient, MediaExtractor, YouTubeTranscript } from '@nahisaho/katashiro-collector';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,gEAAgE;AAEhE,yCAAyC;AACzC,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAY,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,gEAAgE;AAEhE,yCAAyC;AACzC,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAY,UAAU,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGvH,uCAAuC;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEtI,6CAA6C;AAC7C,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAE/I,gDAAgD;AAChD,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE3J,yCAAyC;AACzC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE5H,wCAAwC;AACxC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nahisaho/katashiro",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "KATASHIRO - VS Code Agent Mode向け情報収集・分析・生成システム(オールインワンパッケージ)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"katashiro": "./dist/cli.js"
|
|
10
|
+
},
|
|
8
11
|
"files": [
|
|
9
12
|
"dist",
|
|
10
13
|
"src",
|
|
@@ -73,12 +76,14 @@
|
|
|
73
76
|
"url": "https://github.com/nahisaho/katashiro/issues"
|
|
74
77
|
},
|
|
75
78
|
"dependencies": {
|
|
76
|
-
"@nahisaho/katashiro-core": "^0.1.0",
|
|
77
|
-
"@nahisaho/katashiro-collector": "^0.1.0",
|
|
78
79
|
"@nahisaho/katashiro-analyzer": "^0.1.0",
|
|
80
|
+
"@nahisaho/katashiro-collector": "^0.1.0",
|
|
81
|
+
"@nahisaho/katashiro-core": "^0.1.0",
|
|
82
|
+
"@nahisaho/katashiro-feedback": "^0.1.0",
|
|
79
83
|
"@nahisaho/katashiro-generator": "^0.1.0",
|
|
80
84
|
"@nahisaho/katashiro-knowledge": "^0.1.0",
|
|
81
|
-
"@nahisaho/katashiro-
|
|
85
|
+
"@nahisaho/katashiro-mcp-server": "^0.1.0",
|
|
86
|
+
"commander": "^12.1.0"
|
|
82
87
|
},
|
|
83
88
|
"engines": {
|
|
84
89
|
"node": ">=20.0.0"
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* KATASHIRO CLI - AI Research & Analysis Tool
|
|
4
|
+
*
|
|
5
|
+
* @requirement REQ-CLI-001
|
|
6
|
+
* @design DES-KATASHIRO-001 §2.6 CLI Interface
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
import { WebSearchClient, WebScraper, TextAnalyzer, EntityExtractor, SummaryGenerator, isOk, isErr, generateId, formatTimestamp } from './index.js';
|
|
11
|
+
import type { Content } from './index.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* CLI用にContentオブジェクトを作成
|
|
15
|
+
*/
|
|
16
|
+
function createContent(title: string, body: string, url: string = ''): Content {
|
|
17
|
+
return {
|
|
18
|
+
id: generateId('CLI'),
|
|
19
|
+
type: 'article',
|
|
20
|
+
title,
|
|
21
|
+
body,
|
|
22
|
+
sources: url ? [{
|
|
23
|
+
id: generateId('SRC'),
|
|
24
|
+
url,
|
|
25
|
+
metadata: { title },
|
|
26
|
+
fetchedAt: formatTimestamp()
|
|
27
|
+
}] : [],
|
|
28
|
+
createdAt: formatTimestamp(),
|
|
29
|
+
updatedAt: formatTimestamp(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const program = new Command();
|
|
34
|
+
|
|
35
|
+
program
|
|
36
|
+
.name('katashiro')
|
|
37
|
+
.description('KATASHIRO CLI - AI Research & Analysis Tool')
|
|
38
|
+
.version('0.1.8');
|
|
39
|
+
|
|
40
|
+
// 検索コマンド
|
|
41
|
+
program
|
|
42
|
+
.command('search <query>')
|
|
43
|
+
.description('Web検索を実行')
|
|
44
|
+
.option('-n, --num <number>', '結果の最大件数', '10')
|
|
45
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
46
|
+
.action(async (query: string, options: { num: string; format: string }) => {
|
|
47
|
+
try {
|
|
48
|
+
const client = new WebSearchClient();
|
|
49
|
+
const result = await client.search(query, { maxResults: parseInt(options.num, 10) });
|
|
50
|
+
|
|
51
|
+
if (isErr(result)) {
|
|
52
|
+
console.error('❌ 検索エラー:', result.error.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const results = result.value;
|
|
57
|
+
|
|
58
|
+
if (options.format === 'json') {
|
|
59
|
+
console.log(JSON.stringify(results, null, 2));
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`\n🔍 "${query}" の検索結果: ${results.length}件\n`);
|
|
62
|
+
for (const r of results) {
|
|
63
|
+
console.log(`📄 ${r.title}`);
|
|
64
|
+
console.log(` ${r.url}`);
|
|
65
|
+
if (r.snippet) {
|
|
66
|
+
console.log(` ${r.snippet.substring(0, 100)}...`);
|
|
67
|
+
}
|
|
68
|
+
console.log();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// スクレイピングコマンド
|
|
78
|
+
program
|
|
79
|
+
.command('scrape <url>')
|
|
80
|
+
.description('Webページの内容を取得')
|
|
81
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
82
|
+
.option('-s, --summary', '要約を表示', false)
|
|
83
|
+
.action(async (url: string, options: { format: string; summary: boolean }) => {
|
|
84
|
+
try {
|
|
85
|
+
const scraper = new WebScraper();
|
|
86
|
+
const result = await scraper.scrape(url);
|
|
87
|
+
|
|
88
|
+
if (isErr(result)) {
|
|
89
|
+
console.error('❌ スクレイプエラー:', result.error.message);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const page = result.value;
|
|
94
|
+
|
|
95
|
+
if (options.format === 'json') {
|
|
96
|
+
console.log(JSON.stringify(page, null, 2));
|
|
97
|
+
} else {
|
|
98
|
+
console.log(`\n📄 ${page.title}`);
|
|
99
|
+
console.log(`🔗 ${page.url}`);
|
|
100
|
+
console.log('\n---\n');
|
|
101
|
+
|
|
102
|
+
if (options.summary) {
|
|
103
|
+
const summarizer = new SummaryGenerator();
|
|
104
|
+
const content = createContent(page.title, page.content, page.url);
|
|
105
|
+
const summary = await summarizer.generateSummary(content, { maxLength: 500 });
|
|
106
|
+
if (isOk(summary)) {
|
|
107
|
+
console.log('📝 要約:\n');
|
|
108
|
+
console.log(summary.value);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
console.log(page.content.substring(0, 2000));
|
|
112
|
+
if (page.content.length > 2000) {
|
|
113
|
+
console.log(`\n... (${page.content.length - 2000}文字省略)`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// 分析コマンド
|
|
124
|
+
program
|
|
125
|
+
.command('analyze <text>')
|
|
126
|
+
.description('テキストを分析(感情分析)')
|
|
127
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
128
|
+
.action(async (text: string, options: { format: string }) => {
|
|
129
|
+
try {
|
|
130
|
+
const analyzer = new TextAnalyzer();
|
|
131
|
+
const content = createContent('CLI Input', text);
|
|
132
|
+
const result = await analyzer.analyze(content);
|
|
133
|
+
|
|
134
|
+
if (isErr(result)) {
|
|
135
|
+
console.error('❌ 分析エラー:', result.error.message);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const analysis = result.value;
|
|
140
|
+
|
|
141
|
+
if (options.format === 'json') {
|
|
142
|
+
console.log(JSON.stringify(analysis, null, 2));
|
|
143
|
+
} else {
|
|
144
|
+
console.log('\n📊 テキスト分析結果\n');
|
|
145
|
+
console.log(`💬 感情: ${analysis.sentiment}`);
|
|
146
|
+
console.log(`📈 スコア: ${analysis.score.toFixed(2)}`);
|
|
147
|
+
console.log(`✅ 信頼度: ${(analysis.confidence * 100).toFixed(1)}%`);
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// エンティティ抽出コマンド
|
|
156
|
+
program
|
|
157
|
+
.command('extract <text>')
|
|
158
|
+
.description('テキストからエンティティを抽出')
|
|
159
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
160
|
+
.action(async (text: string, options: { format: string }) => {
|
|
161
|
+
try {
|
|
162
|
+
const extractor = new EntityExtractor();
|
|
163
|
+
const entities = await extractor.extract(text);
|
|
164
|
+
|
|
165
|
+
if (options.format === 'json') {
|
|
166
|
+
console.log(JSON.stringify(entities, null, 2));
|
|
167
|
+
} else {
|
|
168
|
+
console.log('\n🔍 エンティティ抽出結果\n');
|
|
169
|
+
|
|
170
|
+
if (entities.persons.length > 0) {
|
|
171
|
+
console.log(`👤 人名: ${entities.persons.join(', ')}`);
|
|
172
|
+
}
|
|
173
|
+
if (entities.organizations.length > 0) {
|
|
174
|
+
console.log(`🏢 組織: ${entities.organizations.join(', ')}`);
|
|
175
|
+
}
|
|
176
|
+
if (entities.locations.length > 0) {
|
|
177
|
+
console.log(`📍 場所: ${entities.locations.join(', ')}`);
|
|
178
|
+
}
|
|
179
|
+
if (entities.dates.length > 0) {
|
|
180
|
+
console.log(`📅 日付: ${entities.dates.join(', ')}`);
|
|
181
|
+
}
|
|
182
|
+
if (entities.urls.length > 0) {
|
|
183
|
+
console.log(`🔗 URL: ${entities.urls.join(', ')}`);
|
|
184
|
+
}
|
|
185
|
+
if (entities.emails.length > 0) {
|
|
186
|
+
console.log(`📧 メール: ${entities.emails.join(', ')}`);
|
|
187
|
+
}
|
|
188
|
+
if (entities.phones.length > 0) {
|
|
189
|
+
console.log(`📞 電話: ${entities.phones.join(', ')}`);
|
|
190
|
+
}
|
|
191
|
+
if (entities.money.length > 0) {
|
|
192
|
+
console.log(`💰 金額: ${entities.money.join(', ')}`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log(`\n📊 合計: ${entities.all.length}件のエンティティ`);
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// 要約コマンド
|
|
204
|
+
program
|
|
205
|
+
.command('summarize <text>')
|
|
206
|
+
.description('テキストを要約')
|
|
207
|
+
.option('-l, --length <number>', '要約の最大文字数', '300')
|
|
208
|
+
.option('-f, --format <format>', '出力形式 (json|text)', 'text')
|
|
209
|
+
.action(async (text: string, options: { length: string; format: string }) => {
|
|
210
|
+
try {
|
|
211
|
+
const summarizer = new SummaryGenerator();
|
|
212
|
+
const content = createContent('CLI Input', text);
|
|
213
|
+
const result = await summarizer.generateSummary(content, { maxLength: parseInt(options.length, 10) });
|
|
214
|
+
|
|
215
|
+
if (isErr(result)) {
|
|
216
|
+
const error = result.error as Error;
|
|
217
|
+
console.error('❌ 要約エラー:', error.message);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const summary = result.value;
|
|
222
|
+
|
|
223
|
+
if (options.format === 'json') {
|
|
224
|
+
console.log(JSON.stringify({ summary, originalLength: text.length }, null, 2));
|
|
225
|
+
} else {
|
|
226
|
+
console.log('\n📝 要約結果\n');
|
|
227
|
+
console.log(summary);
|
|
228
|
+
console.log(`\n(元のテキスト: ${text.length}文字 → 要約: ${summary.length}文字)`);
|
|
229
|
+
}
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error('❌ エラー:', error instanceof Error ? error.message : error);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
program.parse();
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
// Core - Result types, Logger, utilities
|
|
5
5
|
export * as core from '@nahisaho/katashiro-core';
|
|
6
|
-
export { Result, ok, err, isOk, isErr, Logger, LogLevel, generateId } from '@nahisaho/katashiro-core';
|
|
6
|
+
export { Result, ok, err, isOk, isErr, Logger, LogLevel, generateId, formatTimestamp } from '@nahisaho/katashiro-core';
|
|
7
|
+
export type { Content, Source, ContentType, ID, Timestamp } from '@nahisaho/katashiro-core';
|
|
7
8
|
|
|
8
9
|
// Collector - Web scraping, API, feeds
|
|
9
10
|
export * as collector from '@nahisaho/katashiro-collector';
|