@helpfeel/cosense-cli 1.19.0 → 1.20.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/package.json +3 -3
- package/src/cli.ts +12 -4
- package/src/commands/deleteFile.ts +1 -1
- package/src/commands/downloadFile.ts +1 -1
- package/src/commands/list1hopLinks.ts +4 -4
- package/src/commands/list2hopLinks.ts +2 -2
- package/src/commands/listPages.ts +1 -1
- package/src/commands/listProjects.ts +1 -1
- package/src/commands/previewEdit.ts +3 -0
- package/src/commands/readPage.ts +2 -1
- package/src/commands/search1hopLinks.ts +14 -6
- package/src/commands/search2hopLinks.ts +14 -6
- package/src/commands/searchFullText.ts +13 -5
- package/src/commands/submitEdit.ts +4 -2
- package/src/commands/whoami.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpfeel/cosense-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "Cosense (旧Scrapbox) のページを読み・調べ・編集するAgent Skillのハーネス",
|
|
5
5
|
"homepage": "https://github.com/helpfeel/cosense-cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "24.19.2",
|
|
31
31
|
"npm-run-all": "4.1.5",
|
|
32
|
-
"oxfmt": "0.
|
|
33
|
-
"oxlint": "1.
|
|
32
|
+
"oxfmt": "0.78.0",
|
|
33
|
+
"oxlint": "1.93.0",
|
|
34
34
|
"typescript": "7.0.2"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
package/src/cli.ts
CHANGED
|
@@ -134,6 +134,8 @@ interface CommandSpec {
|
|
|
134
134
|
handler: (args: string[]) => Promise<void>;
|
|
135
135
|
summary: string;
|
|
136
136
|
help: string;
|
|
137
|
+
// handlerが、引数の -- より後ろを位置引数として読むコマンド
|
|
138
|
+
acceptsSeparator?: boolean;
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
const packageJsonPath = join(
|
|
@@ -237,17 +239,20 @@ const commands: Record<string, CommandSpec> = {
|
|
|
237
239
|
searchFullText: {
|
|
238
240
|
handler: searchFullText,
|
|
239
241
|
summary: searchFullTextSummary,
|
|
240
|
-
help: searchFullTextHelp
|
|
242
|
+
help: searchFullTextHelp,
|
|
243
|
+
acceptsSeparator: true
|
|
241
244
|
},
|
|
242
245
|
search1hopLinks: {
|
|
243
246
|
handler: search1hopLinks,
|
|
244
247
|
summary: search1hopLinksSummary,
|
|
245
|
-
help: search1hopLinksHelp
|
|
248
|
+
help: search1hopLinksHelp,
|
|
249
|
+
acceptsSeparator: true
|
|
246
250
|
},
|
|
247
251
|
search2hopLinks: {
|
|
248
252
|
handler: search2hopLinks,
|
|
249
253
|
summary: search2hopLinksSummary,
|
|
250
|
-
help: search2hopLinksHelp
|
|
254
|
+
help: search2hopLinksHelp,
|
|
255
|
+
acceptsSeparator: true
|
|
251
256
|
},
|
|
252
257
|
previewEdit: {
|
|
253
258
|
handler: previewEdit,
|
|
@@ -313,7 +318,10 @@ if (!spec) {
|
|
|
313
318
|
process.exit(2);
|
|
314
319
|
}
|
|
315
320
|
|
|
316
|
-
|
|
321
|
+
// acceptsSeparatorのコマンドでは、-- より後ろの --help はhandlerに渡す引数である
|
|
322
|
+
const separatorIndex = spec.acceptsSeparator ? rest.indexOf('--') : -1;
|
|
323
|
+
const helpArgs = separatorIndex === -1 ? rest : rest.slice(0, separatorIndex);
|
|
324
|
+
if (helpArgs.includes('--help')) {
|
|
317
325
|
process.stdout.write(`${spec.help}\n`);
|
|
318
326
|
process.exit(0);
|
|
319
327
|
}
|
|
@@ -18,7 +18,7 @@ Usage:
|
|
|
18
18
|
出力(JSON):
|
|
19
19
|
success boolean 削除に成功したらtrue
|
|
20
20
|
|
|
21
|
-
削除後、ファイルが所属するproject内でこのファイルを埋め込んでいるページの本文はサーバーが自動修正するため、クライアント側での本文修正は不要。
|
|
21
|
+
削除後、ファイルが所属するproject内でこのファイルを埋め込んでいるページの本文はサーバーが自動修正するため、クライアント側での本文修正は不要。success が true でも、本文の修正が終わっているとは限らない。
|
|
22
22
|
|
|
23
23
|
例:
|
|
24
24
|
cosense deleteFile 'https://scrapbox.io/files/5f151efbacbb17001a58f120.pdf'
|
|
@@ -15,7 +15,7 @@ Usage:
|
|
|
15
15
|
<outputPath> 保存先ファイルパス。既存ファイルは上書きする。親ディレクトリは自動作成しない
|
|
16
16
|
|
|
17
17
|
オプション:
|
|
18
|
-
--thumbnail 縮小版(thumbnail)を取得する。thumbnail
|
|
18
|
+
--thumbnail 縮小版(thumbnail)を取得する。jpeg/png以外のファイルにはthumbnailが無く、原本が返る。jpeg/pngでも、thumbnailが作られていないファイルは取得に失敗する。その時は --thumbnail を外して原本を取得する
|
|
19
19
|
--project <projectUrl> Service Account認証で取得する時に、ファイルが属するprojectのURLを指定する(例: https://scrapbox.io/example)。省略時はPersonal Access Tokenを使う
|
|
20
20
|
|
|
21
21
|
出力(JSON):
|
|
@@ -15,16 +15,16 @@ Usage:
|
|
|
15
15
|
|
|
16
16
|
戻り値(top-levelの主なkey):
|
|
17
17
|
links1hop Array<Link> 1-hop近傍のページ配列
|
|
18
|
-
charsCount number
|
|
18
|
+
charsCount number links1hop のページの文字数の合計
|
|
19
19
|
hasBackLinksOrIcons boolean 被リンク・アイコン参照があるか
|
|
20
20
|
kcsControlTagsLc string[] 制御タグ
|
|
21
|
-
pagination object
|
|
21
|
+
pagination object { perPage, total, hasNext, nextId }
|
|
22
22
|
|
|
23
23
|
各 Link の field:
|
|
24
|
-
id, title, titleLc, image, descriptions(冒頭数行),
|
|
24
|
+
id, title, titleLc, image, descriptions?(冒頭数行),
|
|
25
25
|
linksLc(リンク記法のtitleLc配列), linked(被リンク数), pageRank,
|
|
26
26
|
infoboxDefinition, infoboxDisableLinks,
|
|
27
|
-
created, updated, accessed, lastAccessed (string), charsCount,
|
|
27
|
+
created, updated, accessed, lastAccessed? (string | null), charsCount,
|
|
28
28
|
user (作成者 User), lastUpdateUser (最終更新者 User | null), users (更新者リスト Array<User>),
|
|
29
29
|
relation 'outgoing' | 'incoming' | 'bidirectional'
|
|
30
30
|
outgoing 対象ページが参照しているページ(正リンク)
|
|
@@ -16,12 +16,12 @@ Usage:
|
|
|
16
16
|
戻り値(top-levelの主なkey):
|
|
17
17
|
links2hop Array<Link> 2-hop近傍のページ配列
|
|
18
18
|
hiddenHeadwordsLc string[] 非表示のヘッドワード
|
|
19
|
-
pagination object
|
|
19
|
+
pagination object { perPage, total, hasNext, nextId }
|
|
20
20
|
|
|
21
21
|
各 Link の field:
|
|
22
22
|
id, title, titleLc, image, descriptions, linksLc, linked, pageRank,
|
|
23
23
|
infoboxDefinition, infoboxDisableLinks,
|
|
24
|
-
created, updated, accessed, lastAccessed (string), charsCount,
|
|
24
|
+
created, updated, accessed, lastAccessed? (string | null), charsCount,
|
|
25
25
|
user (作成者 User), lastUpdateUser (最終更新者 User | null), users (更新者リスト Array<User>)
|
|
26
26
|
|
|
27
27
|
User の field(user / lastUpdateUser / users[] で共通):
|
|
@@ -43,7 +43,7 @@ Usage:
|
|
|
43
43
|
user (作成者 User), lastUpdateUser (最終更新者 User | null), users (更新者リスト Array<User>),
|
|
44
44
|
pin (pinned page なら正の値), views, linked,
|
|
45
45
|
linesCount, charsCount,
|
|
46
|
-
created, updated, accessed, lastAccessed (string)
|
|
46
|
+
created, updated, accessed, lastAccessed? (string | null)
|
|
47
47
|
|
|
48
48
|
User の field(user / lastUpdateUser / users[] で共通):
|
|
49
49
|
id string Cosense内部のID
|
|
@@ -24,7 +24,7 @@ Project の field:
|
|
|
24
24
|
loginStrategies Array<string> 認証方法(google / microsoft / saml / email 等)
|
|
25
25
|
plan string? 課金plan名
|
|
26
26
|
additionalPlans { [planName]: boolean } 追加plan
|
|
27
|
-
alert
|
|
27
|
+
alert string? project内に表示される通知
|
|
28
28
|
usersCount number メンバー数
|
|
29
29
|
isMember boolean 自分がメンバーか
|
|
30
30
|
billingId string? billing ID
|
|
@@ -65,6 +65,9 @@ HTTPエラー:
|
|
|
65
65
|
HTTP 404 pageId に対応するpageが存在しない / pageId が不正な形式
|
|
66
66
|
HTTP 409 {"error":"NotFastForward","latest":...}
|
|
67
67
|
preview生成後にページが更新された。最新stateを再取得して ops を作り直す必要がある
|
|
68
|
+
HTTP 413 1回の編集が大きすぎる。Cosense APIに送るJSONの全体で、約100KBまで。text の他に、
|
|
69
|
+
挿入・置換・削除する行ごとに行のID等が加わるので、短い行が多い編集でも上限を超える。
|
|
70
|
+
編集を複数回に分ける
|
|
68
71
|
HTTP 422 ops が不正/存在しないlineId/replace に多行textを渡した等
|
|
69
72
|
`;
|
|
70
73
|
|
package/src/commands/readPage.ts
CHANGED
|
@@ -16,7 +16,8 @@ Usage:
|
|
|
16
16
|
|
|
17
17
|
戻り値(top-levelの主なkey):
|
|
18
18
|
title string ページタイトル
|
|
19
|
-
persistent boolean 実体のあるページなら true。false
|
|
19
|
+
persistent boolean 実体のあるページなら true。false は未作成の新規ページ(関連ページリストは存在する場合がある)。
|
|
20
|
+
false の時は、id / commitId / linked / created / updated / accessed / user / lastUpdateUser / users が無い
|
|
20
21
|
id string ページID (persistent: true の時のみ)
|
|
21
22
|
commitId string 最新コミットID (persistent: true の時のみ)
|
|
22
23
|
lines Array<Line> 本文の行配列。Line = { id, text, user, created, updated } (id および user/timestamp 系は persistent: true の時のみ)
|
|
@@ -16,16 +16,18 @@ Usage:
|
|
|
16
16
|
|
|
17
17
|
オプション:
|
|
18
18
|
--or 複数語のいずれかにマッチするページを返す(既定はAND)
|
|
19
|
+
-- これより後ろを全て位置引数として読む。-- で始まる <query> を渡す時にその前に置き、オプションはこれより前に置く
|
|
19
20
|
|
|
20
21
|
例:
|
|
21
22
|
cosense search1hopLinks https://scrapbox.io/shokai/カレー "うどん ラーメン" --or
|
|
22
23
|
|
|
23
24
|
戻り値(top-levelの主なkey):
|
|
24
|
-
links1hop Array<Link> query
|
|
25
|
-
ほか list1hopLinks と同じ top-level key
|
|
25
|
+
links1hop Array<Link> query にマッチした1-hop近傍ページ
|
|
26
|
+
ほか list1hopLinks と同じ top-level key。charsCount と pagination は、絞り込む前の値
|
|
26
27
|
|
|
27
|
-
各 Link の field(list1hopLinks
|
|
28
|
-
|
|
28
|
+
各 Link の field(list1hopLinksとの違い):
|
|
29
|
+
descriptions? マッチした箇所がある時は、冒頭数行ではなく、その抜粋
|
|
30
|
+
search? { words, excludes }。query から読み取った、検索の語と除外の語
|
|
29
31
|
`;
|
|
30
32
|
|
|
31
33
|
const parseArgs = (
|
|
@@ -34,11 +36,17 @@ const parseArgs = (
|
|
|
34
36
|
const usage = 'Usage: cosense search1hopLinks <pageUrl> <query> [--or]';
|
|
35
37
|
let or = false;
|
|
36
38
|
const positional: string[] = [];
|
|
37
|
-
for (const arg of args) {
|
|
39
|
+
for (const [i, arg] of args.entries()) {
|
|
40
|
+
if (arg === '--') {
|
|
41
|
+
positional.push(...args.slice(i + 1));
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
38
44
|
if (arg === '--or') {
|
|
39
45
|
or = true;
|
|
40
46
|
} else if (arg.startsWith('--')) {
|
|
41
|
-
throw new Error(
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Unknown option: ${arg}\nIf <query> starts with --, put -- before <query> and place all options before --.\n${usage}`
|
|
49
|
+
);
|
|
42
50
|
} else {
|
|
43
51
|
positional.push(arg);
|
|
44
52
|
}
|
|
@@ -16,16 +16,18 @@ Usage:
|
|
|
16
16
|
|
|
17
17
|
オプション:
|
|
18
18
|
--or 複数語のいずれかにマッチするページを返す(既定はAND)
|
|
19
|
+
-- これより後ろを全て位置引数として読む。-- で始まる <query> を渡す時にその前に置き、オプションはこれより前に置く
|
|
19
20
|
|
|
20
21
|
例:
|
|
21
22
|
cosense search2hopLinks https://scrapbox.io/shokai/カレー "うどん ラーメン" --or
|
|
22
23
|
|
|
23
24
|
戻り値(top-levelの主なkey):
|
|
24
|
-
links2hop Array<Link> query
|
|
25
|
-
ほか list2hopLinks と同じ top-level key
|
|
25
|
+
links2hop Array<Link> query にマッチした2-hop近傍ページ
|
|
26
|
+
ほか list2hopLinks と同じ top-level key。pagination は、絞り込む前の値
|
|
26
27
|
|
|
27
|
-
各 Link の field(list2hopLinks
|
|
28
|
-
|
|
28
|
+
各 Link の field(list2hopLinksとの違い):
|
|
29
|
+
descriptions マッチした箇所がある時は、冒頭数行ではなく、その抜粋
|
|
30
|
+
search? { words, excludes }。query から読み取った、検索の語と除外の語
|
|
29
31
|
`;
|
|
30
32
|
|
|
31
33
|
const parseArgs = (
|
|
@@ -34,11 +36,17 @@ const parseArgs = (
|
|
|
34
36
|
const usage = 'Usage: cosense search2hopLinks <pageUrl> <query> [--or]';
|
|
35
37
|
let or = false;
|
|
36
38
|
const positional: string[] = [];
|
|
37
|
-
for (const arg of args) {
|
|
39
|
+
for (const [i, arg] of args.entries()) {
|
|
40
|
+
if (arg === '--') {
|
|
41
|
+
positional.push(...args.slice(i + 1));
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
38
44
|
if (arg === '--or') {
|
|
39
45
|
or = true;
|
|
40
46
|
} else if (arg.startsWith('--')) {
|
|
41
|
-
throw new Error(
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Unknown option: ${arg}\nIf <query> starts with --, put -- before <query> and place all options before --.\n${usage}`
|
|
49
|
+
);
|
|
42
50
|
} else {
|
|
43
51
|
positional.push(arg);
|
|
44
52
|
}
|
|
@@ -18,15 +18,17 @@ Usage:
|
|
|
18
18
|
オプション:
|
|
19
19
|
--or 複数語のいずれかにマッチするページを返す(既定はAND)
|
|
20
20
|
--sort <pageRank|updated> 並び順(既定はpageRank)
|
|
21
|
+
-- これより後ろを全て位置引数として読む。-- で始まる <query> を渡す時にその前に置き、オプションはこれより前に置く
|
|
21
22
|
|
|
22
23
|
例:
|
|
23
24
|
cosense searchFullText https://scrapbox.io/shokai/ "デザイン 設計 design UI UX プロトタイプ" --or
|
|
25
|
+
cosense searchFullText https://scrapbox.io/shokai/ --or -- "--force --no-verify"
|
|
24
26
|
|
|
25
27
|
戻り値(top-levelの主なkey):
|
|
26
28
|
projectName string プロジェクト名
|
|
27
29
|
searchQuery string 実行されたクエリ
|
|
28
|
-
count number
|
|
29
|
-
limit number
|
|
30
|
+
count number pages の件数。ヒットの総数ではない
|
|
31
|
+
limit number 検索する件数の上限
|
|
30
32
|
pages Array<Page> マッチしたページの配列
|
|
31
33
|
existsExactTitleMatch boolean タイトル完全一致がある場合 true
|
|
32
34
|
|
|
@@ -43,8 +45,8 @@ Usage:
|
|
|
43
45
|
pageRank number PageRank
|
|
44
46
|
linesCount number 行数
|
|
45
47
|
charsCount number 文字数
|
|
46
|
-
words string[]
|
|
47
|
-
lines string[]
|
|
48
|
+
words string[] query から読み取った検索の語
|
|
49
|
+
lines string[] マッチした箇所の抜粋。タイトルの行や、本文の要約になる事がある
|
|
48
50
|
|
|
49
51
|
User の field(user / lastUpdateUser / users[] で共通):
|
|
50
52
|
id string Cosense内部のID
|
|
@@ -85,6 +87,10 @@ const parseArgs = (args: string[]): ParsedArgs => {
|
|
|
85
87
|
const positional: string[] = [];
|
|
86
88
|
for (let i = 0; i < args.length; i += 1) {
|
|
87
89
|
const arg = args[i] as string;
|
|
90
|
+
if (arg === '--') {
|
|
91
|
+
positional.push(...args.slice(i + 1));
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
88
94
|
if (arg === '--or') {
|
|
89
95
|
or = true;
|
|
90
96
|
} else if (arg === '--sort') {
|
|
@@ -98,7 +104,9 @@ const parseArgs = (args: string[]): ParsedArgs => {
|
|
|
98
104
|
sort = value;
|
|
99
105
|
i += 1;
|
|
100
106
|
} else if (arg.startsWith('--')) {
|
|
101
|
-
throw new Error(
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Unknown option: ${arg}\nIf <query> starts with --, put -- before <query> and place all options before --.\n${usage}`
|
|
109
|
+
);
|
|
102
110
|
} else {
|
|
103
111
|
positional.push(arg);
|
|
104
112
|
}
|
|
@@ -38,7 +38,8 @@ Usage:
|
|
|
38
38
|
deleted: true
|
|
39
39
|
|
|
40
40
|
HTTPエラー:
|
|
41
|
-
HTTP 400 preview を生成した時と違う project の URL
|
|
41
|
+
HTTP 400 preview を生成した時と違う project の URL を渡している。 previewId は consume される。
|
|
42
|
+
previewEdit / previewDelete からやり直す必要がある
|
|
42
43
|
HTTP 401 認証なし
|
|
43
44
|
HTTP 403 権限不足(PAT利用時、projectのmemberでない 等)
|
|
44
45
|
HTTP 404 preview が見つからない / 期限切れ (5分) / 既にconsume済み / 他userのpreview
|
|
@@ -51,7 +52,8 @@ HTTPエラー:
|
|
|
51
52
|
HTTP 409 {"error":"DuplicateTitle"}
|
|
52
53
|
preview→submit の間に他人が同名ページを作った (race condition)
|
|
53
54
|
|
|
54
|
-
previewId は1回限り (consume-on-submit)。submit
|
|
55
|
+
previewId は1回限り (consume-on-submit)。submit がエラーを返した時も、consume されている事がある。
|
|
56
|
+
consume 済み・5分 expire 後は HTTP 404。
|
|
55
57
|
`;
|
|
56
58
|
|
|
57
59
|
interface SubmitResponse {
|
package/src/commands/whoami.ts
CHANGED
|
@@ -15,12 +15,12 @@ Usage:
|
|
|
15
15
|
|
|
16
16
|
戻り値(top-levelの主なkey):
|
|
17
17
|
id string Cosense内部のID
|
|
18
|
-
name string
|
|
18
|
+
name string? ログイン名
|
|
19
19
|
displayName string 表示名
|
|
20
|
-
email string
|
|
20
|
+
email string? メールアドレス
|
|
21
21
|
photo string アイコン画像URL
|
|
22
22
|
provider string 認証プロバイダ(google / microsoft / saml 等)
|
|
23
|
-
pageFilters Array<{type, value}>
|
|
23
|
+
pageFilters Array<{type, value?}> page list filter設定
|
|
24
24
|
created string 作成時刻
|
|
25
25
|
updated string 更新時刻
|
|
26
26
|
`;
|