@helpfeel/cosense-cli 1.15.0 → 1.16.1
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/README.md +4 -0
- package/package.json +5 -5
- package/src/commands/browsePage.ts +24 -7
- package/src/commands/browsePageChanges.ts +7 -2
- package/src/commands/submitEdit.ts +11 -6
- package/src/lib/encodeTitle.ts +17 -11
package/README.md
CHANGED
|
@@ -45,4 +45,8 @@ cosense --help
|
|
|
45
45
|
|
|
46
46
|
- install [direnv](https://direnv.net/)
|
|
47
47
|
- run `npm install`
|
|
48
|
+
- install [Codex CLI](https://github.com/openai/codex) and run `codex login`
|
|
49
|
+
- modelは `gpt-5.6-sol`、reasoning effortは `high` 以上を推奨
|
|
48
50
|
- run `claude` or `codex`
|
|
51
|
+
|
|
52
|
+
Claude Codeでこのディレクトリをtrustすると、開発フローで使うpluginが `.claude/settings.json` によりインストールされる。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpfeel/cosense-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"description": "Cosense (旧Scrapbox) のページを読み・調べ・編集するAgent Skillのハーネス",
|
|
5
5
|
"homepage": "https://github.com/helpfeel/cosense-cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"format": "oxfmt"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"tsx": "4.23.
|
|
27
|
+
"tsx": "4.23.15"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "24.13.
|
|
30
|
+
"@types/node": "24.13.6",
|
|
31
31
|
"npm-run-all": "4.1.5",
|
|
32
|
-
"oxfmt": "0.
|
|
33
|
-
"oxlint": "1.
|
|
32
|
+
"oxfmt": "0.70.0",
|
|
33
|
+
"oxlint": "1.85.0",
|
|
34
34
|
"typescript": "7.0.2"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { enrichTimestampsOf } from '../lib/enrichTimestamps.ts';
|
|
2
|
+
import {
|
|
3
|
+
encodeTitleForReadableLink,
|
|
4
|
+
encodeTitleForUrl
|
|
5
|
+
} from '../lib/encodeTitle.ts';
|
|
2
6
|
import { applyFileMarkup, fetchFileMarkups } from '../lib/fileMarkup.ts';
|
|
3
7
|
import { renderLiterateDatabase } from '../lib/literateDatabase.ts';
|
|
4
8
|
import { parsePageUrl } from '../lib/parseUrl.ts';
|
|
@@ -34,9 +38,11 @@ Usage:
|
|
|
34
38
|
# <title>
|
|
35
39
|
|
|
36
40
|
## メタデータ
|
|
37
|
-
タイトル / pageId / commitId / 作成日時 / 最終更新日時 /
|
|
38
|
-
被リンク数 / pageRank / views / snapshot / 行数 / 文字数 /
|
|
39
|
-
関わったユーザー
|
|
41
|
+
タイトル / URL / Readable link / pageId / commitId / 作成日時 / 最終更新日時 /
|
|
42
|
+
最終アクセス日時 / 被リンク数 / pageRank / views / snapshot / 行数 / 文字数 /
|
|
43
|
+
作成者 / 最終更新者 / 関わったユーザー
|
|
44
|
+
URL はタイトルをパーセントエンコードしたページURL
|
|
45
|
+
Readable link は日本語等を生で残した同じページのURL(Cosenseの「Copy readable link」相当)
|
|
40
46
|
pageId はページの不変ID、commitId は閲覧時点の最新コミット。共同編集中に
|
|
41
47
|
ページを見失ったら、これらを browsePageChanges に渡して変更(リネーム含む)を辿れる
|
|
42
48
|
|
|
@@ -90,8 +96,8 @@ Usage:
|
|
|
90
96
|
## 1 hop link(表に載っていないページ) に出力する
|
|
91
97
|
|
|
92
98
|
persistent: false の時:
|
|
93
|
-
|
|
94
|
-
本文(テンプレート)と Related Pages を出力する
|
|
99
|
+
アイコン・テロメア・Infoboxは省略し、メタデータはURLとReadable linkだけを出力する。
|
|
100
|
+
(このページはまだ作成されていません) と 本文(テンプレート)と Related Pages を出力する
|
|
95
101
|
|
|
96
102
|
URLに #<lineId> fragmentが指定された時:
|
|
97
103
|
タイトル直後に判定結果を1行出力する。
|
|
@@ -206,9 +212,15 @@ const buildTelomere = (lines: PageLine[]): TelomereEntry[] => {
|
|
|
206
212
|
return [...byUser.values()].sort((a, b) => b.lineCount - a.lineCount);
|
|
207
213
|
};
|
|
208
214
|
|
|
209
|
-
const renderMetadata = (
|
|
215
|
+
const renderMetadata = (
|
|
216
|
+
page: PageData,
|
|
217
|
+
pageUrl: string,
|
|
218
|
+
readableLink: string
|
|
219
|
+
): string => {
|
|
210
220
|
const items: string[] = [];
|
|
211
221
|
if (typeof page.title === 'string') items.push(`- タイトル: ${page.title}`);
|
|
222
|
+
items.push(`- URL: ${pageUrl}`);
|
|
223
|
+
items.push(`- Readable link: ${readableLink}`);
|
|
212
224
|
if (typeof page.id === 'string') items.push(`- pageId: ${page.id}`);
|
|
213
225
|
if (typeof page.commitId === 'string') {
|
|
214
226
|
items.push(`- commitId: ${page.commitId}`);
|
|
@@ -358,10 +370,15 @@ export const browsePage = async (args: string[]): Promise<void> => {
|
|
|
358
370
|
|
|
359
371
|
const title = page.title ?? '';
|
|
360
372
|
const persistent = page.persistent !== false;
|
|
373
|
+
const pageUrl = `${origin}/${projectName}/${encodeTitleForUrl(title)}`;
|
|
374
|
+
const readableLink = `${origin}/${projectName}/${encodeTitleForReadableLink(title)}`;
|
|
361
375
|
const sections: string[] = [`# ${title}`];
|
|
362
376
|
|
|
363
377
|
if (!persistent) {
|
|
364
378
|
sections.push('(このページはまだ作成されていません)');
|
|
379
|
+
sections.push(
|
|
380
|
+
`## メタデータ\n\n- URL: ${pageUrl}\n- Readable link: ${readableLink}`
|
|
381
|
+
);
|
|
365
382
|
const { body } = renderBody(page.lines ?? [], null, new Map());
|
|
366
383
|
sections.push(`## 本文(テンプレート)\n\n${body}`);
|
|
367
384
|
const related = renderRelatedPages(hopValue, page);
|
|
@@ -409,7 +426,7 @@ export const browsePage = async (args: string[]): Promise<void> => {
|
|
|
409
426
|
]);
|
|
410
427
|
enrichPageUsers(page, userMap);
|
|
411
428
|
|
|
412
|
-
sections.push(renderMetadata(page));
|
|
429
|
+
sections.push(renderMetadata(page, pageUrl, readableLink));
|
|
413
430
|
|
|
414
431
|
const iconsSection = renderHumanIcons(page.icons, userMap);
|
|
415
432
|
if (iconsSection) sections.push(iconsSection);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
encodeTitleForReadableLink,
|
|
3
|
+
encodeTitleForUrl
|
|
4
|
+
} from '../lib/encodeTitle.ts';
|
|
2
5
|
import { formatTimestamp } from '../lib/formatTimestamp.ts';
|
|
3
6
|
import { parseProjectUrlStrict } from '../lib/parseUrl.ts';
|
|
4
7
|
import { requestJson } from '../lib/request.ts';
|
|
@@ -32,7 +35,7 @@ Usage:
|
|
|
32
35
|
出力形式(Markdown plain text。JSONではない):
|
|
33
36
|
# ページ変更履歴
|
|
34
37
|
pageId / 範囲(--since より後か全履歴か)/ commit数 / title change(変更後タイトル、無ければ なし)
|
|
35
|
-
タイトルが変わっていた時のみ、新URLも出力する
|
|
38
|
+
タイトルが変わっていた時のみ、新URLと新Readable linkも出力する
|
|
36
39
|
## 変更
|
|
37
40
|
時系列の変更イベントを「<日時>\t<誰>が<何を>」の形(TAB区切り)で列挙する。
|
|
38
41
|
同一行への連続した編集は1件にまとめ、変更前→最終のテキストを示す。
|
|
@@ -231,6 +234,8 @@ export const browsePageChanges = async (args: string[]): Promise<void> => {
|
|
|
231
234
|
if (latestTitle !== undefined) {
|
|
232
235
|
const newUrl = `${origin}/${projectName}/${encodeTitleForUrl(latestTitle)}`;
|
|
233
236
|
meta.push(`- 新URL: ${newUrl}`);
|
|
237
|
+
const newReadableLink = `${origin}/${projectName}/${encodeTitleForReadableLink(latestTitle)}`;
|
|
238
|
+
meta.push(`- 新Readable link: ${newReadableLink}`);
|
|
234
239
|
}
|
|
235
240
|
sections.push(meta.join('\n'));
|
|
236
241
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
encodeTitleForReadableLink,
|
|
3
|
+
encodeTitleForUrl
|
|
4
|
+
} from '../lib/encodeTitle.ts';
|
|
2
5
|
import { parseProjectUrlStrict } from '../lib/parseUrl.ts';
|
|
3
6
|
import { requestJson } from '../lib/request.ts';
|
|
4
7
|
import { resolveCredential } from '../lib/settings.ts';
|
|
@@ -18,11 +21,12 @@ Usage:
|
|
|
18
21
|
戻り値(plain text):
|
|
19
22
|
commitId: <生成されたcommitのID>
|
|
20
23
|
title: <実際に書き込まれたpage title>
|
|
21
|
-
url: <作成または更新された page の URL
|
|
24
|
+
url: <作成または更新された page の URL。タイトルはパーセントエンコード済み>
|
|
25
|
+
readableLink: <同じ page の URL。日本語等を生で残す(Cosenseの「Copy readable link」相当)>
|
|
22
26
|
|
|
23
|
-
url はサーバーが返す title から再構築される。 同名ページが既に存在する場合、
|
|
24
|
-
|
|
25
|
-
title/url にはその suffix が反映される。
|
|
27
|
+
url と readableLink はサーバーが返す title から再構築される。 同名ページが既に存在する場合、
|
|
28
|
+
サーバーはタイトルに auto-suffix を付ける (新規作成でも既存ページのタイトル変更でも起きる)。
|
|
29
|
+
title/url/readableLink にはその suffix が反映される。
|
|
26
30
|
|
|
27
31
|
既存ページのタイトルが変わった編集では、続けて以下を出力する:
|
|
28
32
|
titleChanged: "<変更前title>" -> "<変更後title>"
|
|
@@ -89,8 +93,9 @@ export const submitEdit = async (args: string[]): Promise<void> => {
|
|
|
89
93
|
);
|
|
90
94
|
}
|
|
91
95
|
const url = `${origin}/${projectName}/${encodeTitleForUrl(title)}`;
|
|
96
|
+
const readableLink = `${origin}/${projectName}/${encodeTitleForReadableLink(title)}`;
|
|
92
97
|
process.stdout.write(
|
|
93
|
-
`commitId: ${response.commitId}\ntitle: ${title}\nurl: ${url}\n`
|
|
98
|
+
`commitId: ${response.commitId}\ntitle: ${title}\nurl: ${url}\nreadableLink: ${readableLink}\n`
|
|
94
99
|
);
|
|
95
100
|
|
|
96
101
|
// titleChangedはサーバーが対応している場合のみ返る
|
package/src/lib/encodeTitle.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// cosense server の route match (`/:projectName/:title`, `:title=[^/]+`) を満たすため
|
|
4
|
-
// title 内の `/` は `%2F` 必須。 URL syntax を破壊する `%` `?` `#` も percent-encode する。
|
|
5
|
-
// space は cosense convention で `_` に置換。
|
|
1
|
+
// 非ASCIIを生で残すと、`%2F`等と混ざったURLをmacOSのターミナルが開く時に`%`が再エンコードされ、別のページに飛ぶ
|
|
2
|
+
// 半角スペースはCosenseの慣習で`_`に置換する
|
|
6
3
|
export const encodeTitleForUrl = (title: string): string => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
|
|
4
|
+
// 孤立サロゲートが残っているとencodeURIComponentが例外を投げる
|
|
5
|
+
return encodeURIComponent(title.toWellFormed().replace(/ /g, '_')).replace(
|
|
6
|
+
// encodeURIComponentが残すRFC 3986の予約文字。括弧はMarkdownリンクのリンク先を、`'`はshellのクォートを壊しうる
|
|
7
|
+
/[!'()*]/g,
|
|
8
|
+
c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
|
|
9
|
+
);
|
|
13
10
|
};
|
|
11
|
+
|
|
12
|
+
// Cosenseの「Copy readable link」と同じく、日本語等を生で残して人が読めるURLにする
|
|
13
|
+
// URLパーサーは`\`を`/`と解釈し、末尾のC0制御文字を取り除く。空白文字と`<>`は貼った先でURLの自動リンクを途中で切り、`'`はshellのクォートを壊す。これらを`/` `%` `?` `#`と共にエスケープする
|
|
14
|
+
export const encodeTitleForReadableLink = (title: string): string =>
|
|
15
|
+
title
|
|
16
|
+
.replace(/ /g, '_')
|
|
17
|
+
.replace(/[/%?#\\<>\p{Cc}]|\s/gu, c => encodeURIComponent(c))
|
|
18
|
+
// encodeURIComponentは`'`をエスケープしない
|
|
19
|
+
.replace(/'/g, '%27');
|