claude-code-jsonl-generator 0.1.0-beta.1 → 0.1.0-beta.3
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 +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ content ブロックのガードなど、手動でキュレーションしてい
|
|
|
29
29
|
|
|
30
30
|
生成物は必ずレビューしてからコミットすること。本リポジトリでは
|
|
31
31
|
`scripts/check-generated-sync.mjs` で `claude-code-jsonl-parser` にコミット済みの
|
|
32
|
-
|
|
32
|
+
生成物と再生成結果が一致しているかをローカルで手動確認できる (CI では実行しない)。
|
|
33
33
|
|
|
34
34
|
## 📖 プログラムからの利用 (上級者向け)
|
|
35
35
|
|
package/dist/cli.cjs
CHANGED
|
@@ -30,7 +30,7 @@ async function main() {
|
|
|
30
30
|
const typeBlocks = [];
|
|
31
31
|
const guardBlocks = [];
|
|
32
32
|
const registry = [];
|
|
33
|
-
for (const [type, samples] of [...scan.samplesByType].toSorted()) {
|
|
33
|
+
for (const [type, samples] of [...scan.samplesByType].toSorted((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)) {
|
|
34
34
|
const shape = require_emit_guards.inferShape(samples);
|
|
35
35
|
const name = `${require_emit_guards.pascalCase(type)}Entry`;
|
|
36
36
|
const fn = `is${require_emit_guards.pascalCase(type)}`;
|
package/dist/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ async function main() {
|
|
|
29
29
|
const typeBlocks = [];
|
|
30
30
|
const guardBlocks = [];
|
|
31
31
|
const registry = [];
|
|
32
|
-
for (const [type, samples] of [...scan.samplesByType].toSorted()) {
|
|
32
|
+
for (const [type, samples] of [...scan.samplesByType].toSorted((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)) {
|
|
33
33
|
const shape = inferShape(samples);
|
|
34
34
|
const name = `${pascalCase(type)}Entry`;
|
|
35
35
|
const fn = `is${pascalCase(type)}`;
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { writeFile, mkdir } from 'node:fs/promises'\nimport path from 'node:path'\nimport { scanCorpus } from './scanner'\nimport { inferShape } from './infer'\nimport { emitInterface, pascalCase } from './emit-types'\nimport { emitGuardFunction } from './emit-guards'\n\n/**\n * 引数を解釈する。`--corpus <dir> --out <parser/src/generated>`。\n *\n * @param argv - process.argv.slice(2)\n */\nfunction parseArgs(argv: string[]): { corpus: string; out: string } {\n let corpus = ''\n let out = ''\n for (let i = 0; i < argv.length; i += 1) {\n if (argv[i] === '--corpus') corpus = argv[i + 1] ?? ''\n else if (argv[i] === '--out') out = argv[i + 1] ?? ''\n }\n if (!corpus || !out) {\n console.error('Usage: claude-code-jsonl-generator --corpus <dir> --out <parser/src/generated>')\n process.exit(2)\n }\n return { corpus, out }\n}\n\nasync function main(): Promise<void> {\n const { corpus, out } = parseArgs(process.argv.slice(2))\n const scan = await scanCorpus(corpus)\n console.error(`scanned: ${scan.totalLines} lines, ${scan.samplesByType.size} types, ${scan.malformedLines} malformed`)\n\n const typeBlocks: string[] = []\n const guardBlocks: string[] = []\n const registry: string[] = []\n for (const [type, samples] of [...scan.samplesByType].toSorted()) {\n const shape = inferShape(samples)\n const name = `${pascalCase(type)}Entry`\n const fn = `is${pascalCase(type)}`\n typeBlocks.push(emitInterface(name, type, shape))\n guardBlocks.push(emitGuardFunction(fn, type, shape))\n registry.push(` '${type}': ${fn},`)\n }\n\n const typesHeader = `/** GENERATED by claude-code-jsonl-generator. Do not edit by hand. */\\n\\n`\n const typesOut = typesHeader + typeBlocks.join('\\n\\n') + '\\n'\n\n const guardsHeader =\n `/** GENERATED by claude-code-jsonl-generator. Do not edit by hand. */\\n\\n` +\n `function isObject(v: unknown): v is Record<string, unknown> {\\n` +\n ` return typeof v === 'object' && v !== null && !Array.isArray(v)\\n}\\n` +\n `function isString(v: unknown): v is string { return typeof v === 'string' }\\n` +\n `function isNumber(v: unknown): v is number { return typeof v === 'number' }\\n` +\n `function isBoolean(v: unknown): v is boolean { return typeof v === 'boolean' }\\n\\n`\n const guardsRegistry =\n `\\n\\nexport const guards = {\\n${registry.join('\\n')}\\n} as const satisfies Record<string, (v: unknown) => boolean>\\n` +\n `export const KNOWN_TYPES = Object.keys(guards) as (keyof typeof guards)[]\\n` +\n `export function guardByType(type: string, v: unknown): boolean | undefined {\\n` +\n ` const g = (guards as Record<string, (x: unknown) => boolean>)[type]\\n` +\n ` return g === undefined ? undefined : g(v)\\n}\\n`\n const guardsOut = guardsHeader + guardBlocks.join('\\n\\n') + guardsRegistry\n\n await mkdir(out, { recursive: true })\n await writeFile(path.join(out,'types.generated.ts'), typesOut, 'utf8')\n await writeFile(path.join(out,'guards.generated.ts'), guardsOut, 'utf8')\n console.error(`written: ${path.join(out,'types.generated.ts')}, ${path.join(out,'guards.generated.ts')}`)\n console.error('NOTE: review the diff before committing. content-block guards / message shapes are curated manually and are not overwritten by this generator.')\n}\n\nmain().catch((error: unknown) => {\n console.error(error)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;AAaA,SAAS,UAAU,MAAiD;CAClE,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GACpC,IAAI,KAAK,OAAO,YAAY,SAAS,KAAK,IAAI,MAAM;MAC/C,IAAI,KAAK,OAAO,SAAS,MAAM,KAAK,IAAI,MAAM;CAErD,IAAI,CAAC,UAAU,CAAC,KAAK;EACnB,QAAQ,MAAM,gFAAgF;EAC9F,QAAQ,KAAK,CAAC;CAChB;CACA,OAAO;EAAE;EAAQ;CAAI;AACvB;AAEA,eAAe,OAAsB;CACnC,MAAM,EAAE,QAAQ,QAAQ,UAAU,QAAQ,KAAK,MAAM,CAAC,CAAC;CACvD,MAAM,OAAO,MAAM,WAAW,MAAM;CACpC,QAAQ,MAAM,YAAY,KAAK,WAAW,UAAU,KAAK,cAAc,KAAK,UAAU,KAAK,eAAe,WAAW;CAErH,MAAM,aAAuB,CAAC;CAC9B,MAAM,cAAwB,CAAC;CAC/B,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,CAAC,MAAM,YAAY,CAAC,GAAG,KAAK,aAAa,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { writeFile, mkdir } from 'node:fs/promises'\nimport path from 'node:path'\nimport { scanCorpus } from './scanner'\nimport { inferShape } from './infer'\nimport { emitInterface, pascalCase } from './emit-types'\nimport { emitGuardFunction } from './emit-guards'\n\n/**\n * 引数を解釈する。`--corpus <dir> --out <parser/src/generated>`。\n *\n * @param argv - process.argv.slice(2)\n */\nfunction parseArgs(argv: string[]): { corpus: string; out: string } {\n let corpus = ''\n let out = ''\n for (let i = 0; i < argv.length; i += 1) {\n if (argv[i] === '--corpus') corpus = argv[i + 1] ?? ''\n else if (argv[i] === '--out') out = argv[i + 1] ?? ''\n }\n if (!corpus || !out) {\n console.error('Usage: claude-code-jsonl-generator --corpus <dir> --out <parser/src/generated>')\n process.exit(2)\n }\n return { corpus, out }\n}\n\nasync function main(): Promise<void> {\n const { corpus, out } = parseArgs(process.argv.slice(2))\n const scan = await scanCorpus(corpus)\n console.error(`scanned: ${scan.totalLines} lines, ${scan.samplesByType.size} types, ${scan.malformedLines} malformed`)\n\n const typeBlocks: string[] = []\n const guardBlocks: string[] = []\n const registry: string[] = []\n for (const [type, samples] of [...scan.samplesByType].toSorted((a, b) =>\n a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0\n )) {\n const shape = inferShape(samples)\n const name = `${pascalCase(type)}Entry`\n const fn = `is${pascalCase(type)}`\n typeBlocks.push(emitInterface(name, type, shape))\n guardBlocks.push(emitGuardFunction(fn, type, shape))\n registry.push(` '${type}': ${fn},`)\n }\n\n const typesHeader = `/** GENERATED by claude-code-jsonl-generator. Do not edit by hand. */\\n\\n`\n const typesOut = typesHeader + typeBlocks.join('\\n\\n') + '\\n'\n\n const guardsHeader =\n `/** GENERATED by claude-code-jsonl-generator. Do not edit by hand. */\\n\\n` +\n `function isObject(v: unknown): v is Record<string, unknown> {\\n` +\n ` return typeof v === 'object' && v !== null && !Array.isArray(v)\\n}\\n` +\n `function isString(v: unknown): v is string { return typeof v === 'string' }\\n` +\n `function isNumber(v: unknown): v is number { return typeof v === 'number' }\\n` +\n `function isBoolean(v: unknown): v is boolean { return typeof v === 'boolean' }\\n\\n`\n const guardsRegistry =\n `\\n\\nexport const guards = {\\n${registry.join('\\n')}\\n} as const satisfies Record<string, (v: unknown) => boolean>\\n` +\n `export const KNOWN_TYPES = Object.keys(guards) as (keyof typeof guards)[]\\n` +\n `export function guardByType(type: string, v: unknown): boolean | undefined {\\n` +\n ` const g = (guards as Record<string, (x: unknown) => boolean>)[type]\\n` +\n ` return g === undefined ? undefined : g(v)\\n}\\n`\n const guardsOut = guardsHeader + guardBlocks.join('\\n\\n') + guardsRegistry\n\n await mkdir(out, { recursive: true })\n await writeFile(path.join(out,'types.generated.ts'), typesOut, 'utf8')\n await writeFile(path.join(out,'guards.generated.ts'), guardsOut, 'utf8')\n console.error(`written: ${path.join(out,'types.generated.ts')}, ${path.join(out,'guards.generated.ts')}`)\n console.error('NOTE: review the diff before committing. content-block guards / message shapes are curated manually and are not overwritten by this generator.')\n}\n\nmain().catch((error: unknown) => {\n console.error(error)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;AAaA,SAAS,UAAU,MAAiD;CAClE,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GACpC,IAAI,KAAK,OAAO,YAAY,SAAS,KAAK,IAAI,MAAM;MAC/C,IAAI,KAAK,OAAO,SAAS,MAAM,KA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