claude-code-jsonl-validator 0.0.0 → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/cli.cjs +82 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +62 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/validate-D3RwKa-F.js +78 -0
- package/dist/validate-D3RwKa-F.js.map +1 -0
- package/dist/validate-xB-c5Gv6.cjs +93 -0
- package/package.json +42 -5
- package/index.js +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomachi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# claude-code-jsonl-validator
|
|
2
|
+
|
|
3
|
+
実際の Claude Code JSONL コーパスを、`claude-code-jsonl-parser` が持つ既知スキーマに対して回帰検証する CLI / ライブラリ。
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- **リグレッション検出専用** — 既知スキーマから外れた行を検出し、集計付きで報告する
|
|
8
|
+
- **CLI 1 本で完結** — コーパスのディレクトリを指定するだけ
|
|
9
|
+
- **CI との統合を想定** — 検出時は非 0 の終了コードを返すため、そのまま CI のゲートに使える
|
|
10
|
+
- **プログラムからの利用も可能** — 1 行分の検証・集計処理を個別に import できる
|
|
11
|
+
|
|
12
|
+
## 📦 インストール
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install --save-dev claude-code-jsonl-validator
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 🚀 CLI の使い方
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx claude-code-jsonl-validator /path/to/jsonl-corpus
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
指定したディレクトリ以下の `.jsonl` ファイルを再帰的に読み込み、各行を検証する。
|
|
25
|
+
JSON 構文エラーの行はパーサー側の責務のため無視される。
|
|
26
|
+
|
|
27
|
+
- リグレッションが無い場合: `No regressions. All lines match known schemas.` を表示し、終了コード `0`
|
|
28
|
+
- リグレッションがある場合: `type` ごとに検出件数・種別・代表例を表示し、終了コード `1`
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
[assistant] 3 finding(s)
|
|
32
|
+
schema-mismatch: 3
|
|
33
|
+
- uuid: Required
|
|
34
|
+
|
|
35
|
+
Regression detected. See findings above.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 📖 プログラムからの利用 (上級者向け)
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { validateLine, aggregateReport, hasFindings } from 'claude-code-jsonl-validator'
|
|
42
|
+
|
|
43
|
+
const findings = validateLine(JSON.parse(rawLine))
|
|
44
|
+
const report = aggregateReport(findings)
|
|
45
|
+
if (hasFindings(report)) {
|
|
46
|
+
// type ごとの Finding[] が report に集約されている
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| エクスポート | 用途 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `validateLine(obj)` | パース済み 1 行分のオブジェクトを検証し `Finding[]` を返す |
|
|
53
|
+
| `aggregateReport(findings)` | `Finding[]` を `type` ごとに集約する |
|
|
54
|
+
| `hasFindings(report)` | 集約結果に 1 件でも `Finding` があるかを判定する |
|
|
55
|
+
|
|
56
|
+
## 📑 ライセンス
|
|
57
|
+
|
|
58
|
+
このプロジェクトは [MIT License](./LICENSE) の下で公開されている。
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
const require_validate = require("./validate-xB-c5Gv6.cjs");
|
|
25
|
+
let node_fs = require("node:fs");
|
|
26
|
+
let node_fs_promises = require("node:fs/promises");
|
|
27
|
+
let node_readline = require("node:readline");
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path, 1);
|
|
30
|
+
//#region src/cli.ts
|
|
31
|
+
/** `.jsonl` を再帰収集する。 */
|
|
32
|
+
async function collectJsonl(dir) {
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const entry of await (0, node_fs_promises.readdir)(dir)) {
|
|
35
|
+
const full = node_path.default.join(dir, entry);
|
|
36
|
+
if ((await (0, node_fs_promises.stat)(full)).isDirectory()) out.push(...await collectJsonl(full));
|
|
37
|
+
else if (entry.endsWith(".jsonl")) out.push(full);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
async function main() {
|
|
42
|
+
const corpus = process.argv[2];
|
|
43
|
+
if (!corpus) {
|
|
44
|
+
console.error("Usage: claude-code-jsonl-validator <corpus-dir>");
|
|
45
|
+
process.exit(2);
|
|
46
|
+
}
|
|
47
|
+
const findings = [];
|
|
48
|
+
for (const file of await collectJsonl(corpus)) {
|
|
49
|
+
const rl = (0, node_readline.createInterface)({
|
|
50
|
+
input: (0, node_fs.createReadStream)(file, { encoding: "utf8" }),
|
|
51
|
+
crlfDelay: Infinity
|
|
52
|
+
});
|
|
53
|
+
for await (const raw of rl) {
|
|
54
|
+
if (raw.trim() === "") continue;
|
|
55
|
+
let obj;
|
|
56
|
+
try {
|
|
57
|
+
obj = JSON.parse(raw);
|
|
58
|
+
} catch {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
findings.push(...require_validate.validateLine(obj));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const report = require_validate.aggregateReport(findings);
|
|
65
|
+
for (const [type, bucket] of [...report].toSorted(([a], [b]) => a.localeCompare(b))) {
|
|
66
|
+
console.log(`\n[${type}] ${bucket.length} finding(s)`);
|
|
67
|
+
const byKind = /* @__PURE__ */ new Map();
|
|
68
|
+
for (const f of bucket) byKind.set(f.kind, (byKind.get(f.kind) ?? 0) + 1);
|
|
69
|
+
for (const [kind, n] of byKind) console.log(` ${kind}: ${n}`);
|
|
70
|
+
for (const f of bucket.slice(0, 5)) console.log(` - ${f.message}`);
|
|
71
|
+
}
|
|
72
|
+
if (require_validate.hasFindings(report)) {
|
|
73
|
+
console.error("\nRegression detected. See findings above.");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
console.log("\nNo regressions. All lines match known schemas.");
|
|
77
|
+
}
|
|
78
|
+
main().catch((error) => {
|
|
79
|
+
console.error(error);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as hasFindings, r as validateLine, t as aggregateReport } from "./validate-D3RwKa-F.js";
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { readdir, stat } from "node:fs/promises";
|
|
5
|
+
import { createInterface } from "node:readline";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
/** `.jsonl` を再帰収集する。 */
|
|
9
|
+
async function collectJsonl(dir) {
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const entry of await readdir(dir)) {
|
|
12
|
+
const full = path.join(dir, entry);
|
|
13
|
+
if ((await stat(full)).isDirectory()) out.push(...await collectJsonl(full));
|
|
14
|
+
else if (entry.endsWith(".jsonl")) out.push(full);
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
async function main() {
|
|
19
|
+
const corpus = process.argv[2];
|
|
20
|
+
if (!corpus) {
|
|
21
|
+
console.error("Usage: claude-code-jsonl-validator <corpus-dir>");
|
|
22
|
+
process.exit(2);
|
|
23
|
+
}
|
|
24
|
+
const findings = [];
|
|
25
|
+
for (const file of await collectJsonl(corpus)) {
|
|
26
|
+
const rl = createInterface({
|
|
27
|
+
input: createReadStream(file, { encoding: "utf8" }),
|
|
28
|
+
crlfDelay: Infinity
|
|
29
|
+
});
|
|
30
|
+
for await (const raw of rl) {
|
|
31
|
+
if (raw.trim() === "") continue;
|
|
32
|
+
let obj;
|
|
33
|
+
try {
|
|
34
|
+
obj = JSON.parse(raw);
|
|
35
|
+
} catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
findings.push(...validateLine(obj));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const report = aggregateReport(findings);
|
|
42
|
+
for (const [type, bucket] of [...report].toSorted(([a], [b]) => a.localeCompare(b))) {
|
|
43
|
+
console.log(`\n[${type}] ${bucket.length} finding(s)`);
|
|
44
|
+
const byKind = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const f of bucket) byKind.set(f.kind, (byKind.get(f.kind) ?? 0) + 1);
|
|
46
|
+
for (const [kind, n] of byKind) console.log(` ${kind}: ${n}`);
|
|
47
|
+
for (const f of bucket.slice(0, 5)) console.log(` - ${f.message}`);
|
|
48
|
+
}
|
|
49
|
+
if (hasFindings(report)) {
|
|
50
|
+
console.error("\nRegression detected. See findings above.");
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
console.log("\nNo regressions. All lines match known schemas.");
|
|
54
|
+
}
|
|
55
|
+
main().catch((error) => {
|
|
56
|
+
console.error(error);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
59
|
+
//#endregion
|
|
60
|
+
export {};
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { createReadStream } from 'node:fs'\nimport { readdir, stat } from 'node:fs/promises'\nimport { createInterface } from 'node:readline'\nimport path from 'node:path'\nimport { validateLine, aggregateReport, hasFindings, type Finding } from './validate'\n\n/** `.jsonl` を再帰収集する。 */\nasync function collectJsonl(dir: string): Promise<string[]> {\n const out: string[] = []\n for (const entry of await readdir(dir)) {\n const full = path.join(dir, entry)\n const st = await stat(full)\n if (st.isDirectory()) out.push(...(await collectJsonl(full)))\n else if (entry.endsWith('.jsonl')) out.push(full)\n }\n return out\n}\n\nasync function main(): Promise<void> {\n const corpus = process.argv[2]\n if (!corpus) {\n console.error('Usage: claude-code-jsonl-validator <corpus-dir>')\n process.exit(2)\n }\n\n const findings: Finding[] = []\n for (const file of await collectJsonl(corpus)) {\n const rl = createInterface({\n input: createReadStream(file, { encoding: 'utf8' }),\n crlfDelay: Infinity,\n })\n for await (const raw of rl) {\n if (raw.trim() === '') continue\n let obj: unknown\n try {\n obj = JSON.parse(raw)\n } catch {\n continue // 構文エラーは parser 側の責務。ここでは無視\n }\n findings.push(...validateLine(obj))\n }\n }\n\n const report = aggregateReport(findings)\n for (const [type, bucket] of [...report].toSorted(([a], [b]) => a.localeCompare(b))) {\n console.log(`\\n[${type}] ${bucket.length} finding(s)`)\n const byKind = new Map<string, number>()\n for (const f of bucket) byKind.set(f.kind, (byKind.get(f.kind) ?? 0) + 1)\n for (const [kind, n] of byKind) console.log(` ${kind}: ${n}`)\n // 代表例を数件表示\n for (const f of bucket.slice(0, 5)) console.log(` - ${f.message}`)\n }\n\n if (hasFindings(report)) {\n console.error('\\nRegression detected. See findings above.')\n process.exit(1)\n }\n console.log('\\nNo regressions. All lines match known schemas.')\n}\n\nmain().catch((error: unknown) => {\n console.error(error)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;AAQA,eAAe,aAAa,KAAgC;CAC1D,MAAM,MAAgB,CAAC;CACvB,KAAK,MAAM,SAAS,MAAM,QAAQ,GAAG,GAAG;EACtC,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK;EAEjC,KAAI,MADa,KAAK,IAAI,EAAA,CACnB,YAAY,GAAG,IAAI,KAAK,GAAI,MAAM,aAAa,IAAI,CAAE;OACvD,IAAI,MAAM,SAAS,QAAQ,GAAG,IAAI,KAAK,IAAI;CAClD;CACA,OAAO;AACT;AAEA,eAAe,OAAsB;CACnC,MAAM,SAAS,QAAQ,KAAK;CAC5B,IAAI,CAAC,QAAQ;EACX,QAAQ,MAAM,iDAAiD;EAC/D,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,WAAsB,CAAC;CAC7B,KAAK,MAAM,QAAQ,MAAM,aAAa,MAAM,GAAG;EAC7C,MAAM,KAAK,gBAAgB;GACzB,OAAO,iBAAiB,MAAM,EAAE,UAAU,OAAO,CAAC;GAClD,WAAW;EACb,CAAC;EACD,WAAW,MAAM,OAAO,IAAI;GAC1B,IAAI,IAAI,KAAK,MAAM,IAAI;GACvB,IAAI;GACJ,IAAI;IACF,MAAM,KAAK,MAAM,GAAG;GACtB,QAAQ;IACN;GACF;GACA,SAAS,KAAK,GAAG,aAAa,GAAG,CAAC;EACpC;CACF;CAEA,MAAM,SAAS,gBAAgB,QAAQ;CACvC,KAAK,MAAM,CAAC,MAAM,WAAW,CAAC,GAAG,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,GAAG;EACnF,QAAQ,IAAI,MAAM,KAAK,IAAI,OAAO,OAAO,YAAY;EACrD,MAAM,yBAAS,IAAI,IAAoB;EACvC,KAAK,MAAM,KAAK,QAAQ,OAAO,IAAI,EAAE,OAAO,OAAO,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC;EACxE,KAAK,MAAM,CAAC,MAAM,MAAM,QAAQ,QAAQ,IAAI,KAAK,KAAK,IAAI,GAAG;EAE7D,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG,CAAC,GAAG,QAAQ,IAAI,SAAS,EAAE,SAAS;CACtE;CAEA,IAAI,YAAY,MAAM,GAAG;EACvB,QAAQ,MAAM,4CAA4C;EAC1D,QAAQ,KAAK,CAAC;CAChB;CACA,QAAQ,IAAI,kDAAkD;AAChE;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,KAAK;CACnB,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_validate = require("./validate-xB-c5Gv6.cjs");
|
|
3
|
+
exports.aggregateReport = require_validate.aggregateReport;
|
|
4
|
+
exports.hasFindings = require_validate.hasFindings;
|
|
5
|
+
exports.validateLine = require_validate.validateLine;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/validate.d.ts
|
|
2
|
+
/** 検出種別。 */
|
|
3
|
+
type FindingKind = 'no-type' | 'unknown-type' | 'schema-mismatch' | 'unknown-field';
|
|
4
|
+
/** 1 件の検出。 */
|
|
5
|
+
interface Finding {
|
|
6
|
+
/** 対象 type (type 無しの場合は '<no-type>')。 */
|
|
7
|
+
type: string;
|
|
8
|
+
kind: FindingKind;
|
|
9
|
+
/** unknown-field のときのフィールド名。 */
|
|
10
|
+
field?: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 1 行 (パース済み JSON) を検証して findings を返す。
|
|
15
|
+
*
|
|
16
|
+
* @param obj - パース済みの生 JSON
|
|
17
|
+
*/
|
|
18
|
+
declare function validateLine(obj: unknown): Finding[];
|
|
19
|
+
/**
|
|
20
|
+
* findings を type ごとに集計する。
|
|
21
|
+
*
|
|
22
|
+
* @param findings - 全 findings
|
|
23
|
+
*/
|
|
24
|
+
declare function aggregateReport(findings: Finding[]): Map<string, Finding[]>;
|
|
25
|
+
/**
|
|
26
|
+
* レポートに 1 件でも finding があれば true。
|
|
27
|
+
*
|
|
28
|
+
* @param report - 集計済みレポート
|
|
29
|
+
*/
|
|
30
|
+
declare function hasFindings(report: Map<string, Finding[]>): boolean;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { type Finding, type FindingKind, aggregateReport, hasFindings, validateLine };
|
|
33
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/validate.ts"],"mappings":";;KAGY,WAAA;;UAOK,OAAA;EAPM;EASrB,IAAA;EACA,IAAA,EAAM,WAAW;EAHK;EAKtB,KAAA;EACA,OAAA;AAAA;;;;;;iBAiBc,YAAA,CAAa,GAAA,YAAe,OAAO;AAAnD;;;;AAAmD;AAAnD,iBAoDgB,eAAA,CAAgB,QAAA,EAAU,OAAA,KAAY,GAAA,SAAY,OAAA;;;;;;iBAelD,WAAA,CAAY,MAAA,EAAQ,GAAG,SAAS,OAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/validate.d.ts
|
|
2
|
+
/** 検出種別。 */
|
|
3
|
+
type FindingKind = 'no-type' | 'unknown-type' | 'schema-mismatch' | 'unknown-field';
|
|
4
|
+
/** 1 件の検出。 */
|
|
5
|
+
interface Finding {
|
|
6
|
+
/** 対象 type (type 無しの場合は '<no-type>')。 */
|
|
7
|
+
type: string;
|
|
8
|
+
kind: FindingKind;
|
|
9
|
+
/** unknown-field のときのフィールド名。 */
|
|
10
|
+
field?: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 1 行 (パース済み JSON) を検証して findings を返す。
|
|
15
|
+
*
|
|
16
|
+
* @param obj - パース済みの生 JSON
|
|
17
|
+
*/
|
|
18
|
+
declare function validateLine(obj: unknown): Finding[];
|
|
19
|
+
/**
|
|
20
|
+
* findings を type ごとに集計する。
|
|
21
|
+
*
|
|
22
|
+
* @param findings - 全 findings
|
|
23
|
+
*/
|
|
24
|
+
declare function aggregateReport(findings: Finding[]): Map<string, Finding[]>;
|
|
25
|
+
/**
|
|
26
|
+
* レポートに 1 件でも finding があれば true。
|
|
27
|
+
*
|
|
28
|
+
* @param report - 集計済みレポート
|
|
29
|
+
*/
|
|
30
|
+
declare function hasFindings(report: Map<string, Finding[]>): boolean;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { type Finding, type FindingKind, aggregateReport, hasFindings, validateLine };
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/validate.ts"],"mappings":";;KAGY,WAAA;;UAOK,OAAA;EAPM;EASrB,IAAA;EACA,IAAA,EAAM,WAAW;EAHK;EAKtB,KAAA;EACA,OAAA;AAAA;;;;;;iBAiBc,YAAA,CAAa,GAAA,YAAe,OAAO;AAAnD;;;;AAAmD;AAAnD,iBAoDgB,eAAA,CAAgB,QAAA,EAAU,OAAA,KAAY,GAAA,SAAY,OAAA;;;;;;iBAelD,WAAA,CAAY,MAAA,EAAQ,GAAG,SAAS,OAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { entrySchemas, knownTypeSchema } from "claude-code-jsonl-generator";
|
|
2
|
+
//#region src/validate.ts
|
|
3
|
+
/** 既知 type のスキーマが宣言しているトップレベルキー集合を取り出す。 */
|
|
4
|
+
function knownKeysOf(type) {
|
|
5
|
+
const schema = entrySchemas[type];
|
|
6
|
+
if (!schema?.shape) return void 0;
|
|
7
|
+
return new Set(Object.keys(schema.shape));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 1 行 (パース済み JSON) を検証して findings を返す。
|
|
11
|
+
*
|
|
12
|
+
* @param obj - パース済みの生 JSON
|
|
13
|
+
*/
|
|
14
|
+
function validateLine(obj) {
|
|
15
|
+
const findings = [];
|
|
16
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return [{
|
|
17
|
+
type: "<no-type>",
|
|
18
|
+
kind: "no-type",
|
|
19
|
+
message: "not a JSON object"
|
|
20
|
+
}];
|
|
21
|
+
const record = obj;
|
|
22
|
+
const type = record.type;
|
|
23
|
+
if (typeof type !== "string") return [{
|
|
24
|
+
type: "<no-type>",
|
|
25
|
+
kind: "no-type",
|
|
26
|
+
message: "missing string \"type\""
|
|
27
|
+
}];
|
|
28
|
+
const schema = knownTypeSchema(type);
|
|
29
|
+
if (schema === void 0) return [{
|
|
30
|
+
type,
|
|
31
|
+
kind: "unknown-type",
|
|
32
|
+
message: `unknown type "${type}"`
|
|
33
|
+
}];
|
|
34
|
+
const parsed = schema.safeParse(record);
|
|
35
|
+
if (!parsed.success) for (const issue of parsed.error.issues) findings.push({
|
|
36
|
+
type,
|
|
37
|
+
kind: "schema-mismatch",
|
|
38
|
+
field: issue.path.join(".") || void 0,
|
|
39
|
+
message: `${issue.path.join(".")}: ${issue.message}`
|
|
40
|
+
});
|
|
41
|
+
const known = knownKeysOf(type);
|
|
42
|
+
if (known) {
|
|
43
|
+
for (const key of Object.keys(record)) if (!known.has(key)) findings.push({
|
|
44
|
+
type,
|
|
45
|
+
kind: "unknown-field",
|
|
46
|
+
field: key,
|
|
47
|
+
message: `unknown field "${key}" on type "${type}"`
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return findings;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* findings を type ごとに集計する。
|
|
54
|
+
*
|
|
55
|
+
* @param findings - 全 findings
|
|
56
|
+
*/
|
|
57
|
+
function aggregateReport(findings) {
|
|
58
|
+
const report = /* @__PURE__ */ new Map();
|
|
59
|
+
for (const f of findings) {
|
|
60
|
+
const bucket = report.get(f.type) ?? [];
|
|
61
|
+
bucket.push(f);
|
|
62
|
+
report.set(f.type, bucket);
|
|
63
|
+
}
|
|
64
|
+
return report;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* レポートに 1 件でも finding があれば true。
|
|
68
|
+
*
|
|
69
|
+
* @param report - 集計済みレポート
|
|
70
|
+
*/
|
|
71
|
+
function hasFindings(report) {
|
|
72
|
+
for (const bucket of report.values()) if (bucket.length > 0) return true;
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { hasFindings as n, validateLine as r, aggregateReport as t };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=validate-D3RwKa-F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-D3RwKa-F.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import { entrySchemas, knownTypeSchema } from 'claude-code-jsonl-generator'\n\n/** 検出種別。 */\nexport type FindingKind =\n | 'no-type'\n | 'unknown-type'\n | 'schema-mismatch'\n | 'unknown-field'\n\n/** 1 件の検出。 */\nexport interface Finding {\n /** 対象 type (type 無しの場合は '<no-type>')。 */\n type: string\n kind: FindingKind\n /** unknown-field のときのフィールド名。 */\n field?: string\n message: string\n}\n\n/** 既知 type のスキーマが宣言しているトップレベルキー集合を取り出す。 */\nfunction knownKeysOf(type: string): Set<string> | undefined {\n const schema = (\n entrySchemas as Record<string, { shape?: Record<string, unknown> } | undefined>\n )[type]\n if (!schema?.shape) return undefined\n return new Set(Object.keys(schema.shape))\n}\n\n/**\n * 1 行 (パース済み JSON) を検証して findings を返す。\n *\n * @param obj - パース済みの生 JSON\n */\nexport function validateLine(obj: unknown): Finding[] {\n const findings: Finding[] = []\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [{ type: '<no-type>', kind: 'no-type', message: 'not a JSON object' }]\n }\n const record = obj as Record<string, unknown>\n const type = record.type\n if (typeof type !== 'string') {\n return [{ type: '<no-type>', kind: 'no-type', message: 'missing string \"type\"' }]\n }\n\n const schema = knownTypeSchema(type)\n if (schema === undefined) {\n return [{ type, kind: 'unknown-type', message: `unknown type \"${type}\"` }]\n }\n\n // スキーマ検証 (必須欠落・型不一致)\n const parsed = schema.safeParse(record)\n if (!parsed.success) {\n for (const issue of parsed.error.issues) {\n findings.push({\n type,\n kind: 'schema-mismatch',\n field: issue.path.join('.') || undefined,\n message: `${issue.path.join('.')}: ${issue.message}`,\n })\n }\n }\n\n // 未知フィールド検出 (スキーマが列挙するキー以外)\n const known = knownKeysOf(type)\n if (known) {\n for (const key of Object.keys(record)) {\n if (!known.has(key)) {\n findings.push({\n type,\n kind: 'unknown-field',\n field: key,\n message: `unknown field \"${key}\" on type \"${type}\"`,\n })\n }\n }\n }\n\n return findings\n}\n\n/**\n * findings を type ごとに集計する。\n *\n * @param findings - 全 findings\n */\nexport function aggregateReport(findings: Finding[]): Map<string, Finding[]> {\n const report = new Map<string, Finding[]>()\n for (const f of findings) {\n const bucket = report.get(f.type) ?? []\n bucket.push(f)\n report.set(f.type, bucket)\n }\n return report\n}\n\n/**\n * レポートに 1 件でも finding があれば true。\n *\n * @param report - 集計済みレポート\n */\nexport function hasFindings(report: Map<string, Finding[]>): boolean {\n for (const bucket of report.values()) {\n if (bucket.length > 0) return true\n }\n return false\n}\n"],"mappings":";;;AAoBA,SAAS,YAAY,MAAuC;CAC1D,MAAM,SACJ,aACA;CACF,IAAI,CAAC,QAAQ,OAAO,OAAO,KAAA;CAC3B,OAAO,IAAI,IAAI,OAAO,KAAK,OAAO,KAAK,CAAC;AAC1C;;;;;;AAOA,SAAgB,aAAa,KAAyB;CACpD,MAAM,WAAsB,CAAC;CAC7B,IAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,MAAM,QAAQ,GAAG,GAC9D,OAAO,CAAC;EAAE,MAAM;EAAa,MAAM;EAAW,SAAS;CAAoB,CAAC;CAE9E,MAAM,SAAS;CACf,MAAM,OAAO,OAAO;CACpB,IAAI,OAAO,SAAS,UAClB,OAAO,CAAC;EAAE,MAAM;EAAa,MAAM;EAAW,SAAS;CAAwB,CAAC;CAGlF,MAAM,SAAS,gBAAgB,IAAI;CACnC,IAAI,WAAW,KAAA,GACb,OAAO,CAAC;EAAE;EAAM,MAAM;EAAgB,SAAS,iBAAiB,KAAK;CAAG,CAAC;CAI3E,MAAM,SAAS,OAAO,UAAU,MAAM;CACtC,IAAI,CAAC,OAAO,SACV,KAAK,MAAM,SAAS,OAAO,MAAM,QAC/B,SAAS,KAAK;EACZ;EACA,MAAM;EACN,OAAO,MAAM,KAAK,KAAK,GAAG,KAAK,KAAA;EAC/B,SAAS,GAAG,MAAM,KAAK,KAAK,GAAG,EAAE,IAAI,MAAM;CAC7C,CAAC;CAKL,MAAM,QAAQ,YAAY,IAAI;CAC9B,IAAI;OACG,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,MAAM,IAAI,GAAG,GAChB,SAAS,KAAK;GACZ;GACA,MAAM;GACN,OAAO;GACP,SAAS,kBAAkB,IAAI,aAAa,KAAK;EACnD,CAAC;CAAA;CAKP,OAAO;AACT;;;;;;AAOA,SAAgB,gBAAgB,UAA6C;CAC3E,MAAM,yBAAS,IAAI,IAAuB;CAC1C,KAAK,MAAM,KAAK,UAAU;EACxB,MAAM,SAAS,OAAO,IAAI,EAAE,IAAI,KAAK,CAAC;EACtC,OAAO,KAAK,CAAC;EACb,OAAO,IAAI,EAAE,MAAM,MAAM;CAC3B;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,YAAY,QAAyC;CACnE,KAAK,MAAM,UAAU,OAAO,OAAO,GACjC,IAAI,OAAO,SAAS,GAAG,OAAO;CAEhC,OAAO;AACT"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
let claude_code_jsonl_generator = require("claude-code-jsonl-generator");
|
|
2
|
+
//#region src/validate.ts
|
|
3
|
+
/** 既知 type のスキーマが宣言しているトップレベルキー集合を取り出す。 */
|
|
4
|
+
function knownKeysOf(type) {
|
|
5
|
+
const schema = claude_code_jsonl_generator.entrySchemas[type];
|
|
6
|
+
if (!schema?.shape) return void 0;
|
|
7
|
+
return new Set(Object.keys(schema.shape));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 1 行 (パース済み JSON) を検証して findings を返す。
|
|
11
|
+
*
|
|
12
|
+
* @param obj - パース済みの生 JSON
|
|
13
|
+
*/
|
|
14
|
+
function validateLine(obj) {
|
|
15
|
+
const findings = [];
|
|
16
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return [{
|
|
17
|
+
type: "<no-type>",
|
|
18
|
+
kind: "no-type",
|
|
19
|
+
message: "not a JSON object"
|
|
20
|
+
}];
|
|
21
|
+
const record = obj;
|
|
22
|
+
const type = record.type;
|
|
23
|
+
if (typeof type !== "string") return [{
|
|
24
|
+
type: "<no-type>",
|
|
25
|
+
kind: "no-type",
|
|
26
|
+
message: "missing string \"type\""
|
|
27
|
+
}];
|
|
28
|
+
const schema = (0, claude_code_jsonl_generator.knownTypeSchema)(type);
|
|
29
|
+
if (schema === void 0) return [{
|
|
30
|
+
type,
|
|
31
|
+
kind: "unknown-type",
|
|
32
|
+
message: `unknown type "${type}"`
|
|
33
|
+
}];
|
|
34
|
+
const parsed = schema.safeParse(record);
|
|
35
|
+
if (!parsed.success) for (const issue of parsed.error.issues) findings.push({
|
|
36
|
+
type,
|
|
37
|
+
kind: "schema-mismatch",
|
|
38
|
+
field: issue.path.join(".") || void 0,
|
|
39
|
+
message: `${issue.path.join(".")}: ${issue.message}`
|
|
40
|
+
});
|
|
41
|
+
const known = knownKeysOf(type);
|
|
42
|
+
if (known) {
|
|
43
|
+
for (const key of Object.keys(record)) if (!known.has(key)) findings.push({
|
|
44
|
+
type,
|
|
45
|
+
kind: "unknown-field",
|
|
46
|
+
field: key,
|
|
47
|
+
message: `unknown field "${key}" on type "${type}"`
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return findings;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* findings を type ごとに集計する。
|
|
54
|
+
*
|
|
55
|
+
* @param findings - 全 findings
|
|
56
|
+
*/
|
|
57
|
+
function aggregateReport(findings) {
|
|
58
|
+
const report = /* @__PURE__ */ new Map();
|
|
59
|
+
for (const f of findings) {
|
|
60
|
+
const bucket = report.get(f.type) ?? [];
|
|
61
|
+
bucket.push(f);
|
|
62
|
+
report.set(f.type, bucket);
|
|
63
|
+
}
|
|
64
|
+
return report;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* レポートに 1 件でも finding があれば true。
|
|
68
|
+
*
|
|
69
|
+
* @param report - 集計済みレポート
|
|
70
|
+
*/
|
|
71
|
+
function hasFindings(report) {
|
|
72
|
+
for (const bucket of report.values()) if (bucket.length > 0) return true;
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
Object.defineProperty(exports, "aggregateReport", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function() {
|
|
79
|
+
return aggregateReport;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, "hasFindings", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function() {
|
|
85
|
+
return hasFindings;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "validateLine", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function() {
|
|
91
|
+
return validateLine;
|
|
92
|
+
}
|
|
93
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-jsonl-validator",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Regression-check real Claude Code JSONL corpora against known schemas",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"jsonl",
|
|
8
|
+
"validation"
|
|
9
|
+
],
|
|
5
10
|
"license": "MIT",
|
|
6
11
|
"author": "Tomachi <tomachi@tomacheese.com>",
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/book000/claude-code-jsonl-parser.git"
|
|
14
|
+
"url": "git+https://github.com/book000/claude-code-jsonl-parser.git",
|
|
15
|
+
"directory": "packages/validator"
|
|
10
16
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
17
|
+
"type": "module",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/*.tsbuildinfo"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"bin": {
|
|
26
|
+
"claude-code-jsonl-validator": "./dist/cli.js"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/index.d.cts",
|
|
36
|
+
"default": "./dist/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"zod": "4.4.3",
|
|
42
|
+
"claude-code-jsonl-generator": "0.1.0-beta.1"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsdown",
|
|
46
|
+
"clean": "rimraf dist",
|
|
47
|
+
"lint": "tsc -p tsconfig.test.json"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/index.js
DELETED