@r_masseater/cc-plugin-lib 0.0.1 → 0.0.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/README.md +58 -0
- package/dist/db.d.ts +72 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +109 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/logger.d.ts.map +1 -1
- package/package.json +14 -5
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @r_masseater/cc-plugin-lib
|
|
2
|
+
|
|
3
|
+
Claude Code プラグイン用の共通ユーティリティライブラリ。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @r_masseater/cc-plugin-lib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使い方
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { HookLogger, wrapRun } from "@r_masseater/cc-plugin-lib";
|
|
15
|
+
import { defineHook, runHook } from "cc-hooks-ts";
|
|
16
|
+
|
|
17
|
+
using logger = HookLogger.fromFile(import.meta.filename);
|
|
18
|
+
|
|
19
|
+
const hook = defineHook({
|
|
20
|
+
trigger: { Stop: true },
|
|
21
|
+
run: wrapRun(logger, (context) => {
|
|
22
|
+
logger.info("Hook executed");
|
|
23
|
+
return context.success({});
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (import.meta.main) {
|
|
28
|
+
await runHook(hook);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
### HookLogger
|
|
35
|
+
|
|
36
|
+
ファイルベースのロギングユーティリティ。
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
using logger = HookLogger.fromFile(import.meta.filename);
|
|
40
|
+
|
|
41
|
+
logger.debug("Debug message");
|
|
42
|
+
logger.info("Info message");
|
|
43
|
+
logger.warn("Warning message");
|
|
44
|
+
logger.error("Error message");
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
ログは `~/.claude/hooks/logs/{filename}.log` に出力される。
|
|
48
|
+
|
|
49
|
+
### wrapRun
|
|
50
|
+
|
|
51
|
+
エラーハンドリングラッパー。hookのrun関数をラップして例外をキャッチし、ログ出力する。
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
run: wrapRun(logger, (context) => {
|
|
55
|
+
// エラーが発生しても安全にハンドリングされる
|
|
56
|
+
return context.success({});
|
|
57
|
+
})
|
|
58
|
+
```
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type SQLQueryBindings } from "bun:sqlite";
|
|
2
|
+
type BindParams = SQLQueryBindings[];
|
|
3
|
+
/**
|
|
4
|
+
* テーブル定義
|
|
5
|
+
*/
|
|
6
|
+
export type TableSchema = {
|
|
7
|
+
columns: string;
|
|
8
|
+
indexes?: readonly string[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* テーブルアクセサ
|
|
12
|
+
*/
|
|
13
|
+
export declare class MutilsTable<T> {
|
|
14
|
+
private db;
|
|
15
|
+
private tableName;
|
|
16
|
+
constructor(db: MutilsDB, tableName: string);
|
|
17
|
+
/**
|
|
18
|
+
* 1行取得
|
|
19
|
+
*/
|
|
20
|
+
findOne(where: string, params?: BindParams): T | null;
|
|
21
|
+
/**
|
|
22
|
+
* 全行取得
|
|
23
|
+
*/
|
|
24
|
+
findAll(where?: string, params?: BindParams): T[];
|
|
25
|
+
/**
|
|
26
|
+
* 挿入または更新
|
|
27
|
+
*/
|
|
28
|
+
upsert(data: Record<string, SQLQueryBindings>): void;
|
|
29
|
+
/**
|
|
30
|
+
* 削除
|
|
31
|
+
*/
|
|
32
|
+
delete(where: string, params?: BindParams): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* mutils 共通データベースへのアクセスを提供
|
|
36
|
+
* DB パス: ${cwd}/.agents/mutils/mutils.db
|
|
37
|
+
*/
|
|
38
|
+
export declare class MutilsDB {
|
|
39
|
+
private db;
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* データベースを開く
|
|
43
|
+
* ディレクトリが存在しない場合は作成する
|
|
44
|
+
*/
|
|
45
|
+
static open(cwd?: string): MutilsDB;
|
|
46
|
+
/**
|
|
47
|
+
* テーブルを取得(存在しない場合は作成)
|
|
48
|
+
*/
|
|
49
|
+
table<T>(name: string, schema: TableSchema): MutilsTable<T>;
|
|
50
|
+
/**
|
|
51
|
+
* SQLを実行
|
|
52
|
+
*/
|
|
53
|
+
run(sql: string, params?: BindParams): void;
|
|
54
|
+
/**
|
|
55
|
+
* クエリを実行して1行取得
|
|
56
|
+
*/
|
|
57
|
+
get<T>(sql: string, params?: BindParams): T | null;
|
|
58
|
+
/**
|
|
59
|
+
* クエリを実行して全行取得
|
|
60
|
+
*/
|
|
61
|
+
all<T>(sql: string, params?: BindParams): T[];
|
|
62
|
+
/**
|
|
63
|
+
* データベースを閉じる
|
|
64
|
+
*/
|
|
65
|
+
close(): void;
|
|
66
|
+
/**
|
|
67
|
+
* using 構文対応
|
|
68
|
+
*/
|
|
69
|
+
[Symbol.dispose](): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=db.d.ts.map
|
package/dist/db.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAO7D,KAAK,UAAU,GAAG,gBAAgB,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;G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,IAAI,CAEvB;CACD"}
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const MUTILS_DIR = ".agents/mutils";
|
|
5
|
+
const DB_FILENAME = "mutils.db";
|
|
6
|
+
/**
|
|
7
|
+
* テーブルアクセサ
|
|
8
|
+
*/
|
|
9
|
+
export class MutilsTable {
|
|
10
|
+
db;
|
|
11
|
+
tableName;
|
|
12
|
+
constructor(db, tableName) {
|
|
13
|
+
this.db = db;
|
|
14
|
+
this.tableName = tableName;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 1行取得
|
|
18
|
+
*/
|
|
19
|
+
findOne(where, params = []) {
|
|
20
|
+
return this.db.get(`SELECT * FROM ${this.tableName} WHERE ${where}`, params);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 全行取得
|
|
24
|
+
*/
|
|
25
|
+
findAll(where, params = []) {
|
|
26
|
+
const sql = where
|
|
27
|
+
? `SELECT * FROM ${this.tableName} WHERE ${where}`
|
|
28
|
+
: `SELECT * FROM ${this.tableName}`;
|
|
29
|
+
return this.db.all(sql, params);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 挿入または更新
|
|
33
|
+
*/
|
|
34
|
+
upsert(data) {
|
|
35
|
+
const keys = Object.keys(data);
|
|
36
|
+
const values = Object.values(data);
|
|
37
|
+
const placeholders = keys.map(() => "?").join(", ");
|
|
38
|
+
this.db.run(`INSERT OR REPLACE INTO ${this.tableName} (${keys.join(", ")}) VALUES (${placeholders})`, values);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 削除
|
|
42
|
+
*/
|
|
43
|
+
delete(where, params = []) {
|
|
44
|
+
this.db.run(`DELETE FROM ${this.tableName} WHERE ${where}`, params);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* mutils 共通データベースへのアクセスを提供
|
|
49
|
+
* DB パス: ${cwd}/.agents/mutils/mutils.db
|
|
50
|
+
*/
|
|
51
|
+
export class MutilsDB {
|
|
52
|
+
db;
|
|
53
|
+
constructor(db) {
|
|
54
|
+
this.db = db;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* データベースを開く
|
|
58
|
+
* ディレクトリが存在しない場合は作成する
|
|
59
|
+
*/
|
|
60
|
+
static open(cwd = process.cwd()) {
|
|
61
|
+
const dbDir = path.join(cwd, MUTILS_DIR);
|
|
62
|
+
const dbPath = path.join(dbDir, DB_FILENAME);
|
|
63
|
+
if (!existsSync(dbDir)) {
|
|
64
|
+
mkdirSync(dbDir, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
const db = new Database(dbPath);
|
|
67
|
+
return new MutilsDB(db);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* テーブルを取得(存在しない場合は作成)
|
|
71
|
+
*/
|
|
72
|
+
table(name, schema) {
|
|
73
|
+
this.db.run(`CREATE TABLE IF NOT EXISTS ${name} (${schema.columns})`);
|
|
74
|
+
for (const index of schema.indexes ?? []) {
|
|
75
|
+
this.db.run(index);
|
|
76
|
+
}
|
|
77
|
+
return new MutilsTable(this, name);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* SQLを実行
|
|
81
|
+
*/
|
|
82
|
+
run(sql, params = []) {
|
|
83
|
+
this.db.run(sql, params);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* クエリを実行して1行取得
|
|
87
|
+
*/
|
|
88
|
+
get(sql, params = []) {
|
|
89
|
+
return this.db.query(sql).get(...params);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* クエリを実行して全行取得
|
|
93
|
+
*/
|
|
94
|
+
all(sql, params = []) {
|
|
95
|
+
return this.db.query(sql).all(...params);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* データベースを閉じる
|
|
99
|
+
*/
|
|
100
|
+
close() {
|
|
101
|
+
this.db.close();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* using 構文対応
|
|
105
|
+
*/
|
|
106
|
+
[Symbol.dispose]() {
|
|
107
|
+
this.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export { MutilsDB, MutilsTable } from "./db.js";
|
|
1
2
|
export { HookLogger } from "./logger.js";
|
|
2
3
|
export { wrapRun } from "./wrapRun.js";
|
|
4
|
+
import { MutilsDB } from "./db.js";
|
|
5
|
+
/**
|
|
6
|
+
* データベース接続を取得
|
|
7
|
+
* 毎回新しい接続を返す。using 構文で自動クローズ
|
|
8
|
+
*/
|
|
9
|
+
export declare function getDB(): MutilsDB;
|
|
3
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;GAGG;AACH,wBAAgB,KAAK,IAAI,QAAQ,CAEhC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
export { MutilsDB, MutilsTable } from "./db.js";
|
|
1
2
|
export { HookLogger } from "./logger.js";
|
|
2
3
|
export { wrapRun } from "./wrapRun.js";
|
|
4
|
+
import { MutilsDB } from "./db.js";
|
|
5
|
+
/**
|
|
6
|
+
* データベース接続を取得
|
|
7
|
+
* 毎回新しい接続を返す。using 構文で自動クローズ
|
|
8
|
+
*/
|
|
9
|
+
export function getDB() {
|
|
10
|
+
return MutilsDB.open();
|
|
11
|
+
}
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;GAWG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;GAWG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAI5C;IAED,OAAO,eA6BN;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;IAED,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAiBtB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAM3D;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAM1D;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAM1D;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAM3D;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAM3C;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/cc-plugin-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Common library for Claude Code plugins - logging and error handling utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,26 +11,35 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
15
17
|
"scripts": {
|
|
16
|
-
"build": "
|
|
18
|
+
"build": "tsgo",
|
|
19
|
+
"typecheck": "tsgo --noEmit",
|
|
17
20
|
"check": "biome check",
|
|
18
21
|
"check:fix": "biome check --write",
|
|
19
22
|
"prepublishOnly": "bun run build"
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"pino": "^
|
|
25
|
+
"pino": "^10.1.0"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
28
|
"@biomejs/biome": "^2.3.8",
|
|
26
29
|
"@types/bun": "^1.3.4",
|
|
30
|
+
"@typescript/native-preview": "^7.0.0-dev.20251207.1",
|
|
27
31
|
"typescript": "^5.9.3"
|
|
28
32
|
},
|
|
29
33
|
"repository": {
|
|
30
34
|
"type": "git",
|
|
31
35
|
"url": "https://github.com/masseater/claude-code-plugin"
|
|
32
36
|
},
|
|
33
|
-
"keywords": [
|
|
37
|
+
"keywords": [
|
|
38
|
+
"claude-code",
|
|
39
|
+
"plugin",
|
|
40
|
+
"hooks",
|
|
41
|
+
"logging"
|
|
42
|
+
],
|
|
34
43
|
"author": "masseater",
|
|
35
44
|
"license": "MIT"
|
|
36
45
|
}
|