claude-code-jsonl-generator 0.0.0 → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/cli.cjs +55 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +57 -0
- package/dist/cli.js.map +1 -0
- package/dist/emit-guards-CSDZc-iy.js +244 -0
- package/dist/emit-guards-CSDZc-iy.js.map +1 -0
- package/dist/emit-guards-DWi5YDuA.cjs +312 -0
- package/dist/index.cjs +220 -0
- package/dist/index.d.cts +320 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +320 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +212 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -5
- package/index.js +0 -3
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let node_fs_promises = require("node:fs/promises");
|
|
24
|
+
let node_fs = require("node:fs");
|
|
25
|
+
let node_readline = require("node:readline");
|
|
26
|
+
let node_path = require("node:path");
|
|
27
|
+
node_path = __toESM(node_path, 1);
|
|
28
|
+
//#region src/scanner.ts
|
|
29
|
+
/**
|
|
30
|
+
* `.jsonl` ファイルを再帰収集する。
|
|
31
|
+
*
|
|
32
|
+
* @param dir - 起点ディレクトリ
|
|
33
|
+
* @returns 絶対パス配列
|
|
34
|
+
*/
|
|
35
|
+
async function collectJsonlFiles(dir) {
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const entry of await (0, node_fs_promises.readdir)(dir)) {
|
|
38
|
+
const full = node_path.default.join(dir, entry);
|
|
39
|
+
if ((await (0, node_fs_promises.stat)(full)).isDirectory()) out.push(...await collectJsonlFiles(full));
|
|
40
|
+
else if (entry.endsWith(".jsonl")) out.push(full);
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* コーパスを走査し type ごとに生サンプルを集約する。
|
|
46
|
+
*
|
|
47
|
+
* @param corpusDir - コーパスのルートディレクトリ
|
|
48
|
+
* @param maxSamplesPerType - type ごとの保持上限 (メモリ保護、既定 5000)
|
|
49
|
+
*/
|
|
50
|
+
async function scanCorpus(corpusDir, maxSamplesPerType = 5e3) {
|
|
51
|
+
const samplesByType = /* @__PURE__ */ new Map();
|
|
52
|
+
let totalLines = 0;
|
|
53
|
+
let malformedLines = 0;
|
|
54
|
+
let typelessLines = 0;
|
|
55
|
+
for (const file of await collectJsonlFiles(corpusDir)) {
|
|
56
|
+
const rl = (0, node_readline.createInterface)({
|
|
57
|
+
input: (0, node_fs.createReadStream)(file, { encoding: "utf8" }),
|
|
58
|
+
crlfDelay: Infinity
|
|
59
|
+
});
|
|
60
|
+
for await (const raw of rl) {
|
|
61
|
+
if (raw.trim() === "") continue;
|
|
62
|
+
let obj;
|
|
63
|
+
try {
|
|
64
|
+
obj = JSON.parse(raw);
|
|
65
|
+
} catch {
|
|
66
|
+
malformedLines += 1;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
totalLines += 1;
|
|
70
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj) || typeof obj.type !== "string") {
|
|
71
|
+
typelessLines += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const record = obj;
|
|
75
|
+
const type = record.type;
|
|
76
|
+
const bucket = samplesByType.get(type) ?? [];
|
|
77
|
+
if (bucket.length < maxSamplesPerType) {
|
|
78
|
+
bucket.push(record);
|
|
79
|
+
samplesByType.set(type, bucket);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
samplesByType,
|
|
85
|
+
totalLines,
|
|
86
|
+
malformedLines,
|
|
87
|
+
typelessLines
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/infer.ts
|
|
92
|
+
/**
|
|
93
|
+
* JSON 値の種別を返す。
|
|
94
|
+
*
|
|
95
|
+
* @param v - 対象値
|
|
96
|
+
*/
|
|
97
|
+
function jsonKind(v) {
|
|
98
|
+
if (v === null) return "null";
|
|
99
|
+
if (Array.isArray(v)) return "array";
|
|
100
|
+
const t = typeof v;
|
|
101
|
+
if ([
|
|
102
|
+
"string",
|
|
103
|
+
"number",
|
|
104
|
+
"boolean"
|
|
105
|
+
].includes(t)) return t;
|
|
106
|
+
return "object";
|
|
107
|
+
}
|
|
108
|
+
/** `InferOptions.maxLiterals` 省略時の既定値。 */
|
|
109
|
+
const DEFAULT_MAX_LITERALS = 20;
|
|
110
|
+
/**
|
|
111
|
+
* 同一 type のサンプル群からフィールド形状を推論する。
|
|
112
|
+
*
|
|
113
|
+
* @param samples - 生 JSON オブジェクト配列
|
|
114
|
+
* @param options - 推論オプション
|
|
115
|
+
*/
|
|
116
|
+
function inferShape(samples, options = {}) {
|
|
117
|
+
const maxLiterals = options.maxLiterals ?? DEFAULT_MAX_LITERALS;
|
|
118
|
+
const count = samples.length;
|
|
119
|
+
const presence = /* @__PURE__ */ new Map();
|
|
120
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
121
|
+
const literals = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const sample of samples) for (const [key, value] of Object.entries(sample)) {
|
|
123
|
+
presence.set(key, (presence.get(key) ?? 0) + 1);
|
|
124
|
+
const kset = kinds.get(key) ?? /* @__PURE__ */ new Set();
|
|
125
|
+
const kind = jsonKind(value);
|
|
126
|
+
kset.add(kind);
|
|
127
|
+
kinds.set(key, kset);
|
|
128
|
+
const cur = literals.get(key);
|
|
129
|
+
if (cur === null) {} else if (kind === "string") {
|
|
130
|
+
const set = cur ?? /* @__PURE__ */ new Set();
|
|
131
|
+
set.add(value);
|
|
132
|
+
if (set.size > maxLiterals) literals.set(key, null);
|
|
133
|
+
else literals.set(key, set);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const fields = /* @__PURE__ */ new Map();
|
|
137
|
+
for (const [key, seen] of presence) {
|
|
138
|
+
const lit = literals.get(key);
|
|
139
|
+
const kindSet = kinds.get(key) ?? /* @__PURE__ */ new Set();
|
|
140
|
+
const allString = kindSet.size === 1 && kindSet.has("string");
|
|
141
|
+
fields.set(key, {
|
|
142
|
+
required: seen === count,
|
|
143
|
+
kinds: kindSet,
|
|
144
|
+
literals: allString && lit ? lit : void 0
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
count,
|
|
149
|
+
fields
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/emit-types.ts
|
|
154
|
+
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
155
|
+
const IDENTIFIER_RE$1 = /^[A-Za-z_$][\w$]*$/;
|
|
156
|
+
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
157
|
+
function escapeSingleQuote$1(s) {
|
|
158
|
+
return s.replaceAll("'", String.raw`\'`);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 観測種別集合 (と任意のリテラル集合) を TypeScript 型文字列に写像する。
|
|
162
|
+
*
|
|
163
|
+
* @param kinds - 観測された JSON 種別
|
|
164
|
+
* @param literals - 文字列リテラル集合 (あれば)
|
|
165
|
+
*/
|
|
166
|
+
function tsTypeOf(kinds, literals) {
|
|
167
|
+
const parts = [];
|
|
168
|
+
const mapped = {
|
|
169
|
+
string: "string",
|
|
170
|
+
number: "number",
|
|
171
|
+
boolean: "boolean",
|
|
172
|
+
null: "null",
|
|
173
|
+
array: "unknown[]",
|
|
174
|
+
object: "Record<string, unknown>"
|
|
175
|
+
};
|
|
176
|
+
if (literals && literals.size > 0 && kinds.has("string")) {
|
|
177
|
+
const lits = [...literals].toSorted().map((s) => `'${escapeSingleQuote$1(s)}'`);
|
|
178
|
+
parts.push(`${lits.join(" | ")} | (string & {})`);
|
|
179
|
+
} else if (kinds.has("string")) parts.push("string");
|
|
180
|
+
for (const k of [
|
|
181
|
+
"number",
|
|
182
|
+
"boolean",
|
|
183
|
+
"array",
|
|
184
|
+
"object",
|
|
185
|
+
"null"
|
|
186
|
+
]) if (kinds.has(k)) parts.push(mapped[k]);
|
|
187
|
+
return [...new Set(parts)].join(" | ");
|
|
188
|
+
}
|
|
189
|
+
/** JS 識別子として安全ならそのまま、そうでなければクォートする。 */
|
|
190
|
+
function propKey(name) {
|
|
191
|
+
return IDENTIFIER_RE$1.test(name) ? name : `'${escapeSingleQuote$1(name)}'`;
|
|
192
|
+
}
|
|
193
|
+
/** interface 名として使うため type 文字列を PascalCase 化する (エミッタ内部用)。 */
|
|
194
|
+
function pascalCase(type) {
|
|
195
|
+
return type.split(/[-_]/).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 1 type の interface 文字列を生成する。
|
|
199
|
+
*
|
|
200
|
+
* @param interfaceName - 出力する interface 名 (例 LastPromptEntry)
|
|
201
|
+
* @param type - 判別子文字列 (例 last-prompt)
|
|
202
|
+
* @param shape - 推論結果
|
|
203
|
+
*/
|
|
204
|
+
function emitInterface(interfaceName, type, shape) {
|
|
205
|
+
const lines = [
|
|
206
|
+
`export interface ${interfaceName} {`,
|
|
207
|
+
` _kind: 'known'`,
|
|
208
|
+
` type: '${escapeSingleQuote$1(type)}'`
|
|
209
|
+
];
|
|
210
|
+
for (const [name, field] of shape.fields) {
|
|
211
|
+
if (name === "type") continue;
|
|
212
|
+
const opt = field.required ? "" : "?";
|
|
213
|
+
const tsType = tsTypeOf(field.kinds, field.literals);
|
|
214
|
+
lines.push(` ${propKey(name)}${opt}: ${tsType}`);
|
|
215
|
+
}
|
|
216
|
+
lines.push("}");
|
|
217
|
+
return lines.join("\n");
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/emit-guards.ts
|
|
221
|
+
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
222
|
+
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
223
|
+
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
224
|
+
function escapeSingleQuote(s) {
|
|
225
|
+
return s.replaceAll("'", String.raw`\'`);
|
|
226
|
+
}
|
|
227
|
+
/** 単一種別の required フィールドに対する検査式を返す。 */
|
|
228
|
+
function checkExpr(name, kinds) {
|
|
229
|
+
const access = `v.${IDENTIFIER_RE.test(name) ? name : `['${escapeSingleQuote(name)}']`}`;
|
|
230
|
+
const hasNull = kinds.has("null");
|
|
231
|
+
const nonNull = [...kinds].filter((k) => k !== "null");
|
|
232
|
+
if (nonNull.length !== 1) return `'${escapeSingleQuote(name)}' in v`;
|
|
233
|
+
const kind = nonNull[0];
|
|
234
|
+
const expr = {
|
|
235
|
+
string: `isString(${access})`,
|
|
236
|
+
number: `isNumber(${access})`,
|
|
237
|
+
boolean: `isBoolean(${access})`,
|
|
238
|
+
object: `isObject(${access})`,
|
|
239
|
+
array: `Array.isArray(${access})`
|
|
240
|
+
}[kind];
|
|
241
|
+
if (expr === void 0) return `'${escapeSingleQuote(name)}' in v`;
|
|
242
|
+
return hasNull ? `(${access} === null || ${expr})` : expr;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 1 type のガード関数文字列を生成する。required フィールドのみ検査する。
|
|
246
|
+
*
|
|
247
|
+
* @param fnName - 関数名 (例 isMode)
|
|
248
|
+
* @param type - 判別子
|
|
249
|
+
* @param shape - 推論結果
|
|
250
|
+
*/
|
|
251
|
+
function emitGuardFunction(fnName, type, shape) {
|
|
252
|
+
const checks = [`isObject(v)`, `v.type === '${escapeSingleQuote(type)}'`];
|
|
253
|
+
for (const [name, field] of shape.fields) {
|
|
254
|
+
if (name === "type" || !field.required) continue;
|
|
255
|
+
const expr = checkExpr(name, field.kinds);
|
|
256
|
+
if (expr) checks.push(expr);
|
|
257
|
+
}
|
|
258
|
+
return [
|
|
259
|
+
`function ${fnName}(v: unknown): boolean {`,
|
|
260
|
+
` return ${checks.join(" &&\n ")}`,
|
|
261
|
+
`}`
|
|
262
|
+
].join("\n");
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
Object.defineProperty(exports, "__toESM", {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
get: function() {
|
|
268
|
+
return __toESM;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
Object.defineProperty(exports, "emitGuardFunction", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
get: function() {
|
|
274
|
+
return emitGuardFunction;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, "emitInterface", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function() {
|
|
280
|
+
return emitInterface;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
Object.defineProperty(exports, "inferShape", {
|
|
284
|
+
enumerable: true,
|
|
285
|
+
get: function() {
|
|
286
|
+
return inferShape;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(exports, "jsonKind", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
get: function() {
|
|
292
|
+
return jsonKind;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(exports, "pascalCase", {
|
|
296
|
+
enumerable: true,
|
|
297
|
+
get: function() {
|
|
298
|
+
return pascalCase;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
Object.defineProperty(exports, "scanCorpus", {
|
|
302
|
+
enumerable: true,
|
|
303
|
+
get: function() {
|
|
304
|
+
return scanCorpus;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
Object.defineProperty(exports, "tsTypeOf", {
|
|
308
|
+
enumerable: true,
|
|
309
|
+
get: function() {
|
|
310
|
+
return tsTypeOf;
|
|
311
|
+
}
|
|
312
|
+
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_emit_guards = require("./emit-guards-DWi5YDuA.cjs");
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
//#region src/schemas.ts
|
|
5
|
+
const entryBase = {
|
|
6
|
+
cwd: zod.z.string(),
|
|
7
|
+
entrypoint: zod.z.string(),
|
|
8
|
+
gitBranch: zod.z.string(),
|
|
9
|
+
isSidechain: zod.z.boolean(),
|
|
10
|
+
parentUuid: zod.z.string().nullable(),
|
|
11
|
+
sessionId: zod.z.string(),
|
|
12
|
+
timestamp: zod.z.string(),
|
|
13
|
+
userType: zod.z.string(),
|
|
14
|
+
uuid: zod.z.string(),
|
|
15
|
+
version: zod.z.string()
|
|
16
|
+
};
|
|
17
|
+
/** type 文字列 → 公開 zod スキーマ。 */
|
|
18
|
+
const entrySchemas = {
|
|
19
|
+
assistant: zod.z.object({
|
|
20
|
+
...entryBase,
|
|
21
|
+
type: zod.z.literal("assistant"),
|
|
22
|
+
message: zod.z.object({}).loose(),
|
|
23
|
+
agentId: zod.z.string().optional(),
|
|
24
|
+
agentName: zod.z.string().optional(),
|
|
25
|
+
teamName: zod.z.string().optional(),
|
|
26
|
+
slug: zod.z.string().optional(),
|
|
27
|
+
sessionKind: zod.z.string().optional(),
|
|
28
|
+
session_id: zod.z.string().optional(),
|
|
29
|
+
requestId: zod.z.string().optional(),
|
|
30
|
+
isApiErrorMessage: zod.z.boolean().optional(),
|
|
31
|
+
apiErrorStatus: zod.z.number().optional(),
|
|
32
|
+
error: zod.z.unknown().optional(),
|
|
33
|
+
attributionAgent: zod.z.string().optional(),
|
|
34
|
+
attributionSkill: zod.z.string().optional(),
|
|
35
|
+
attributionPlugin: zod.z.string().optional(),
|
|
36
|
+
attributionMcpServer: zod.z.string().optional(),
|
|
37
|
+
attributionMcpTool: zod.z.string().optional()
|
|
38
|
+
}).loose(),
|
|
39
|
+
user: zod.z.object({
|
|
40
|
+
...entryBase,
|
|
41
|
+
type: zod.z.literal("user"),
|
|
42
|
+
message: zod.z.object({}).loose(),
|
|
43
|
+
agentId: zod.z.string().optional(),
|
|
44
|
+
agentName: zod.z.string().optional(),
|
|
45
|
+
teamName: zod.z.string().optional(),
|
|
46
|
+
slug: zod.z.string().optional(),
|
|
47
|
+
sessionKind: zod.z.string().optional(),
|
|
48
|
+
session_id: zod.z.string().optional(),
|
|
49
|
+
interruptedMessageId: zod.z.string().optional(),
|
|
50
|
+
isCompactSummary: zod.z.boolean().optional(),
|
|
51
|
+
isMeta: zod.z.boolean().optional(),
|
|
52
|
+
isVisibleInTranscriptOnly: zod.z.boolean().optional(),
|
|
53
|
+
mcpMeta: zod.z.unknown().optional(),
|
|
54
|
+
origin: zod.z.object({
|
|
55
|
+
kind: zod.z.string(),
|
|
56
|
+
from: zod.z.string().optional(),
|
|
57
|
+
senderTaskId: zod.z.string().optional()
|
|
58
|
+
}).loose().optional(),
|
|
59
|
+
permissionMode: zod.z.string().optional(),
|
|
60
|
+
planContent: zod.z.string().optional(),
|
|
61
|
+
promptId: zod.z.string().optional(),
|
|
62
|
+
promptSource: zod.z.string().optional(),
|
|
63
|
+
queuePriority: zod.z.string().optional(),
|
|
64
|
+
sourceToolAssistantUUID: zod.z.string().optional(),
|
|
65
|
+
sourceToolUseID: zod.z.string().optional(),
|
|
66
|
+
toolDenialKind: zod.z.string().optional(),
|
|
67
|
+
toolEndsTurn: zod.z.boolean().optional(),
|
|
68
|
+
toolUseResult: zod.z.unknown().optional()
|
|
69
|
+
}).loose(),
|
|
70
|
+
attachment: zod.z.object({
|
|
71
|
+
...entryBase,
|
|
72
|
+
type: zod.z.literal("attachment"),
|
|
73
|
+
attachment: zod.z.object({}).loose(),
|
|
74
|
+
agentId: zod.z.string().optional(),
|
|
75
|
+
agentName: zod.z.string().optional(),
|
|
76
|
+
teamName: zod.z.string().optional(),
|
|
77
|
+
slug: zod.z.string().optional(),
|
|
78
|
+
sessionKind: zod.z.string().optional(),
|
|
79
|
+
session_id: zod.z.string().optional()
|
|
80
|
+
}).loose(),
|
|
81
|
+
system: zod.z.object({
|
|
82
|
+
...entryBase,
|
|
83
|
+
type: zod.z.literal("system"),
|
|
84
|
+
subtype: zod.z.string(),
|
|
85
|
+
agentId: zod.z.string().optional(),
|
|
86
|
+
agentName: zod.z.string().optional(),
|
|
87
|
+
teamName: zod.z.string().optional(),
|
|
88
|
+
slug: zod.z.string().optional(),
|
|
89
|
+
sessionKind: zod.z.string().optional(),
|
|
90
|
+
session_id: zod.z.string().optional(),
|
|
91
|
+
compactMetadata: zod.z.unknown().optional(),
|
|
92
|
+
content: zod.z.unknown().optional(),
|
|
93
|
+
durationMs: zod.z.number().optional(),
|
|
94
|
+
error: zod.z.unknown().optional(),
|
|
95
|
+
hasOutput: zod.z.boolean().optional(),
|
|
96
|
+
hookAdditionalContext: zod.z.unknown().optional(),
|
|
97
|
+
hookCount: zod.z.number().optional(),
|
|
98
|
+
hookErrors: zod.z.unknown().optional(),
|
|
99
|
+
hookInfos: zod.z.unknown().optional(),
|
|
100
|
+
isMeta: zod.z.boolean().optional(),
|
|
101
|
+
level: zod.z.string().optional(),
|
|
102
|
+
logicalParentUuid: zod.z.string().optional(),
|
|
103
|
+
maxRetries: zod.z.number().optional(),
|
|
104
|
+
messageCount: zod.z.number().optional(),
|
|
105
|
+
pendingBackgroundAgentCount: zod.z.number().optional(),
|
|
106
|
+
pendingWorkflowCount: zod.z.number().optional(),
|
|
107
|
+
preventedContinuation: zod.z.boolean().optional(),
|
|
108
|
+
retryAttempt: zod.z.number().optional(),
|
|
109
|
+
retryInMs: zod.z.number().optional(),
|
|
110
|
+
stopReason: zod.z.string().optional(),
|
|
111
|
+
toolUseID: zod.z.string().optional()
|
|
112
|
+
}).loose(),
|
|
113
|
+
mode: zod.z.object({
|
|
114
|
+
type: zod.z.literal("mode"),
|
|
115
|
+
mode: zod.z.string(),
|
|
116
|
+
sessionId: zod.z.string()
|
|
117
|
+
}),
|
|
118
|
+
"permission-mode": zod.z.object({
|
|
119
|
+
type: zod.z.literal("permission-mode"),
|
|
120
|
+
permissionMode: zod.z.string(),
|
|
121
|
+
sessionId: zod.z.string()
|
|
122
|
+
}),
|
|
123
|
+
"ai-title": zod.z.object({
|
|
124
|
+
type: zod.z.literal("ai-title"),
|
|
125
|
+
aiTitle: zod.z.string(),
|
|
126
|
+
sessionId: zod.z.string()
|
|
127
|
+
}),
|
|
128
|
+
"agent-name": zod.z.object({
|
|
129
|
+
type: zod.z.literal("agent-name"),
|
|
130
|
+
agentName: zod.z.string(),
|
|
131
|
+
sessionId: zod.z.string()
|
|
132
|
+
}),
|
|
133
|
+
"agent-setting": zod.z.object({
|
|
134
|
+
type: zod.z.literal("agent-setting"),
|
|
135
|
+
agentSetting: zod.z.string(),
|
|
136
|
+
sessionId: zod.z.string()
|
|
137
|
+
}),
|
|
138
|
+
relocated: zod.z.object({
|
|
139
|
+
type: zod.z.literal("relocated"),
|
|
140
|
+
relocatedCwd: zod.z.string(),
|
|
141
|
+
sessionId: zod.z.string()
|
|
142
|
+
}),
|
|
143
|
+
"last-prompt": zod.z.object({
|
|
144
|
+
type: zod.z.literal("last-prompt"),
|
|
145
|
+
leafUuid: zod.z.string(),
|
|
146
|
+
sessionId: zod.z.string(),
|
|
147
|
+
lastPrompt: zod.z.string().optional()
|
|
148
|
+
}),
|
|
149
|
+
"worktree-state": zod.z.object({
|
|
150
|
+
type: zod.z.literal("worktree-state"),
|
|
151
|
+
worktreeSession: zod.z.object({}).loose().nullable(),
|
|
152
|
+
sessionId: zod.z.string()
|
|
153
|
+
}),
|
|
154
|
+
"bridge-session": zod.z.object({
|
|
155
|
+
type: zod.z.literal("bridge-session"),
|
|
156
|
+
bridgeSessionId: zod.z.string(),
|
|
157
|
+
lastSequenceNum: zod.z.number(),
|
|
158
|
+
sessionId: zod.z.string()
|
|
159
|
+
}),
|
|
160
|
+
"queue-operation": zod.z.object({
|
|
161
|
+
type: zod.z.literal("queue-operation"),
|
|
162
|
+
operation: zod.z.string(),
|
|
163
|
+
sessionId: zod.z.string(),
|
|
164
|
+
timestamp: zod.z.string(),
|
|
165
|
+
content: zod.z.unknown().optional()
|
|
166
|
+
}),
|
|
167
|
+
"pr-link": zod.z.object({
|
|
168
|
+
type: zod.z.literal("pr-link"),
|
|
169
|
+
prNumber: zod.z.number(),
|
|
170
|
+
prRepository: zod.z.string(),
|
|
171
|
+
prUrl: zod.z.string(),
|
|
172
|
+
sessionId: zod.z.string(),
|
|
173
|
+
timestamp: zod.z.string()
|
|
174
|
+
}),
|
|
175
|
+
"frame-link": zod.z.object({
|
|
176
|
+
type: zod.z.literal("frame-link"),
|
|
177
|
+
frameUrl: zod.z.string(),
|
|
178
|
+
path: zod.z.string(),
|
|
179
|
+
sessionId: zod.z.string(),
|
|
180
|
+
timestamp: zod.z.string()
|
|
181
|
+
}),
|
|
182
|
+
"file-history-snapshot": zod.z.object({
|
|
183
|
+
type: zod.z.literal("file-history-snapshot"),
|
|
184
|
+
isSnapshotUpdate: zod.z.boolean(),
|
|
185
|
+
messageId: zod.z.string(),
|
|
186
|
+
snapshot: zod.z.object({}).loose()
|
|
187
|
+
}),
|
|
188
|
+
started: zod.z.object({
|
|
189
|
+
type: zod.z.literal("started"),
|
|
190
|
+
key: zod.z.string(),
|
|
191
|
+
agentId: zod.z.string()
|
|
192
|
+
}),
|
|
193
|
+
result: zod.z.object({
|
|
194
|
+
type: zod.z.literal("result"),
|
|
195
|
+
key: zod.z.string(),
|
|
196
|
+
agentId: zod.z.string(),
|
|
197
|
+
result: zod.z.unknown().refine((v) => v !== void 0, { message: "result フィールドは必須です" })
|
|
198
|
+
})
|
|
199
|
+
};
|
|
200
|
+
/** 既知 type 名の配列。 */
|
|
201
|
+
const KNOWN_TYPES = Object.keys(entrySchemas);
|
|
202
|
+
/**
|
|
203
|
+
* 指定 type のスキーマを返す。未知なら undefined。
|
|
204
|
+
*
|
|
205
|
+
* @param type - 判別子
|
|
206
|
+
*/
|
|
207
|
+
function knownTypeSchema(type) {
|
|
208
|
+
return entrySchemas[type];
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
exports.KNOWN_TYPES = KNOWN_TYPES;
|
|
212
|
+
exports.emitGuardFunction = require_emit_guards.emitGuardFunction;
|
|
213
|
+
exports.emitInterface = require_emit_guards.emitInterface;
|
|
214
|
+
exports.entrySchemas = entrySchemas;
|
|
215
|
+
exports.inferShape = require_emit_guards.inferShape;
|
|
216
|
+
exports.jsonKind = require_emit_guards.jsonKind;
|
|
217
|
+
exports.knownTypeSchema = knownTypeSchema;
|
|
218
|
+
exports.pascalCase = require_emit_guards.pascalCase;
|
|
219
|
+
exports.scanCorpus = require_emit_guards.scanCorpus;
|
|
220
|
+
exports.tsTypeOf = require_emit_guards.tsTypeOf;
|