@helpfeel/cosense-cli 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
import { resolveCredential } from '../lib/settings.ts';
|
|
17
17
|
|
|
18
18
|
export const browsePageSummary =
|
|
19
|
-
'
|
|
19
|
+
'単一ページを読む。メタデータ+アイコン記法+テロメア+Infobox+本文をAIが読みやすい形式で出力する。行permalink (`#<lineId>`) 付きなら該当行をマークする';
|
|
20
20
|
|
|
21
|
-
export const browsePageHelp = `browsePage -
|
|
21
|
+
export const browsePageHelp = `browsePage - 単一ページを読む。メタデータ+アイコン記法+テロメア+Infobox+本文をAIが読みやすい形式で出力する。行permalink (#<lineId>) 付きなら該当行をマークする
|
|
22
22
|
|
|
23
23
|
Usage:
|
|
24
24
|
cosense browsePage <pageUrl>
|
|
@@ -46,6 +46,12 @@ Usage:
|
|
|
46
46
|
lines[] を最終更新者でグルーピングし、 displayName 更新期間 YYYY/M/D 〜 YYYY/M/D N行更新
|
|
47
47
|
の形式で行数降順に全員出力
|
|
48
48
|
|
|
49
|
+
## Infobox
|
|
50
|
+
このページ本文から抜き出された Infobox を出力する。各 Infobox を ### <title> の
|
|
51
|
+
見出しと - キー: 値 の箇条書きで表す。値はCosense記法のまま。
|
|
52
|
+
hallucination または truncated と判定された Infobox は除外する。
|
|
53
|
+
0件の場合はセクションごと省略
|
|
54
|
+
|
|
49
55
|
## 本文
|
|
50
56
|
各行の text を改行で結合。fragment 指定行のみ末尾に #<lineId> を付与
|
|
51
57
|
|
|
@@ -56,7 +62,7 @@ Usage:
|
|
|
56
62
|
このページの 1-hop 近傍ページタイトル一覧。 1-hop が 0 件なら区切り線ごと省略
|
|
57
63
|
|
|
58
64
|
persistent: false の時:
|
|
59
|
-
|
|
65
|
+
メタデータ・アイコン・テロメア・Infoboxは省略。 (このページはまだ作成されていません) と
|
|
60
66
|
本文(テンプレート)と Related Pages を出力する
|
|
61
67
|
|
|
62
68
|
URLに #<lineId> fragmentが指定された時:
|
|
@@ -81,6 +87,13 @@ interface UserRef {
|
|
|
81
87
|
displayName?: string;
|
|
82
88
|
}
|
|
83
89
|
|
|
90
|
+
interface InfoboxResult {
|
|
91
|
+
title?: string;
|
|
92
|
+
infobox?: Record<string, string>;
|
|
93
|
+
hallucination?: boolean;
|
|
94
|
+
truncated?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
84
97
|
interface PageData {
|
|
85
98
|
id?: string;
|
|
86
99
|
commitId?: string;
|
|
@@ -102,6 +115,7 @@ interface PageData {
|
|
|
102
115
|
users?: UserRef[];
|
|
103
116
|
lines?: PageLine[];
|
|
104
117
|
icons?: string[];
|
|
118
|
+
infoboxResult?: InfoboxResult[];
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
const LINE_ID_PATTERN = /^[0-9a-f]{24}$/;
|
|
@@ -224,6 +238,23 @@ const renderTelomere = (
|
|
|
224
238
|
return `## テロメアのサマリー\n\n${lines.join('\n')}`;
|
|
225
239
|
};
|
|
226
240
|
|
|
241
|
+
const renderInfobox = (results: InfoboxResult[] | undefined): string | null => {
|
|
242
|
+
if (!results) return null;
|
|
243
|
+
const blocks: string[] = [];
|
|
244
|
+
for (const result of results) {
|
|
245
|
+
// hallucination=AI補完の不確実値、truncated=抽出失敗で値が不完全。どちらも
|
|
246
|
+
// 信頼できないので丸ごと除外する
|
|
247
|
+
if (result.hallucination || result.truncated) continue;
|
|
248
|
+
const rows = Object.entries(result.infobox ?? {}).map(
|
|
249
|
+
([key, value]) => `- ${key}: ${value}`
|
|
250
|
+
);
|
|
251
|
+
if (rows.length === 0) continue;
|
|
252
|
+
blocks.push(`### ${result.title ?? ''}\n\n${rows.join('\n')}`);
|
|
253
|
+
}
|
|
254
|
+
if (blocks.length === 0) return null;
|
|
255
|
+
return `## Infobox\n\n${blocks.join('\n\n')}`;
|
|
256
|
+
};
|
|
257
|
+
|
|
227
258
|
interface BodyRender {
|
|
228
259
|
body: string;
|
|
229
260
|
matchedFragment: boolean;
|
|
@@ -324,6 +355,9 @@ export const browsePage = async (args: string[]): Promise<void> => {
|
|
|
324
355
|
const telomereSection = renderTelomere(telomere, userMap);
|
|
325
356
|
if (telomereSection) sections.push(telomereSection);
|
|
326
357
|
|
|
358
|
+
const infoboxSection = renderInfobox(page.infoboxResult);
|
|
359
|
+
if (infoboxSection) sections.push(infoboxSection);
|
|
360
|
+
|
|
327
361
|
sections.push(`## 本文\n\n${body}`);
|
|
328
362
|
|
|
329
363
|
const related = renderRelatedPages(hopValue);
|
|
@@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { parseProjectUrlStrict } from '../lib/parseUrl.ts';
|
|
4
4
|
import { requestJson } from '../lib/request.ts';
|
|
5
|
-
import {
|
|
5
|
+
import { resolveCredential } from '../lib/settings.ts';
|
|
6
6
|
|
|
7
7
|
export const previewEditSummary =
|
|
8
8
|
'ページ編集opsをdry-runしてpreviewIdを取得する';
|
|
@@ -56,7 +56,7 @@ stdinから受け取る入力形式(既存ページ編集モード, JSON):
|
|
|
56
56
|
|
|
57
57
|
HTTPエラー:
|
|
58
58
|
HTTP 401 認証なし
|
|
59
|
-
HTTP 403
|
|
59
|
+
HTTP 403 権限不足(PAT利用時、projectのmemberでない 等)
|
|
60
60
|
HTTP 404 pageId に対応するpageが存在しない / pageId が不正な形式
|
|
61
61
|
HTTP 409 {"error":"NotFastForward","latest":...}
|
|
62
62
|
preview生成後にページが更新された。最新stateを再取得して ops を作り直す必要がある
|
|
@@ -384,8 +384,8 @@ export const previewEdit = async (args: string[]): Promise<void> => {
|
|
|
384
384
|
}
|
|
385
385
|
const { changes, newLineIds, updatedLineIds } = translateOps(ops);
|
|
386
386
|
|
|
387
|
-
//
|
|
388
|
-
const credential =
|
|
387
|
+
// projectに紐づくService Accountがあればそれを、無ければPATを使う(読み取りと同じ)
|
|
388
|
+
const credential = resolveCredential(origin, projectName);
|
|
389
389
|
|
|
390
390
|
const apiUrl = `${origin}/api/pages/v2/${projectName}/page-edit-for-ai/preview`;
|
|
391
391
|
const requestBody = pageId ? { pageId, changes } : { changes };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encodeTitleForUrl } from '../lib/encodeTitle.ts';
|
|
2
2
|
import { parseProjectUrlStrict } from '../lib/parseUrl.ts';
|
|
3
3
|
import { requestJson } from '../lib/request.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { resolveCredential } from '../lib/settings.ts';
|
|
5
5
|
|
|
6
6
|
export const submitEditSummary =
|
|
7
7
|
'previewEditで取得したpreviewIdを使ってページ編集を確定する';
|
|
@@ -26,7 +26,7 @@ Usage:
|
|
|
26
26
|
HTTPエラー:
|
|
27
27
|
HTTP 400 preview を生成した時と違う project の URL を渡している
|
|
28
28
|
HTTP 401 認証なし
|
|
29
|
-
HTTP 403
|
|
29
|
+
HTTP 403 権限不足(PAT利用時、projectのmemberでない 等)
|
|
30
30
|
HTTP 404 preview が見つからない / 期限切れ (5分) / 既にconsume済み / 他userのpreview
|
|
31
31
|
HTTP 409 {"error":"NotFastForward","latest":...}
|
|
32
32
|
preview生成後にページが更新された。最新stateを再取得して ops を作り直し、
|
|
@@ -50,8 +50,8 @@ export const submitEdit = async (args: string[]): Promise<void> => {
|
|
|
50
50
|
|
|
51
51
|
const { origin, projectName } = parseProjectUrlStrict(projectUrl);
|
|
52
52
|
const apiUrl = `${origin}/api/pages/v2/${projectName}/page-edit-for-ai/submit`;
|
|
53
|
-
//
|
|
54
|
-
const credential =
|
|
53
|
+
// projectに紐づくService Accountがあればそれを、無ければPATを使う(読み取りと同じ)
|
|
54
|
+
const credential = resolveCredential(origin, projectName);
|
|
55
55
|
const response = (await requestJson(apiUrl, {
|
|
56
56
|
credential,
|
|
57
57
|
method: 'POST',
|