zozul-cli 0.1.0
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/.env.example +44 -0
- package/.github/workflows/publish.yml +26 -0
- package/DEVELOPMENT.md +288 -0
- package/LICENSE +201 -0
- package/README.md +178 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +307 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/format.d.ts +5 -0
- package/dist/cli/format.d.ts.map +1 -0
- package/dist/cli/format.js +115 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/context/index.d.ts +8 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +37 -0
- package/dist/context/index.js.map +1 -0
- package/dist/dashboard/html.d.ts +17 -0
- package/dist/dashboard/html.d.ts.map +1 -0
- package/dist/dashboard/html.js +79 -0
- package/dist/dashboard/html.js.map +1 -0
- package/dist/dashboard/index.html +1245 -0
- package/dist/hooks/config.d.ts +19 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +106 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/git.d.ts +6 -0
- package/dist/hooks/git.d.ts.map +1 -0
- package/dist/hooks/git.js +73 -0
- package/dist/hooks/git.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/server.d.ts +16 -0
- package/dist/hooks/server.d.ts.map +1 -0
- package/dist/hooks/server.js +349 -0
- package/dist/hooks/server.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/otel/config.d.ts +36 -0
- package/dist/otel/config.d.ts.map +1 -0
- package/dist/otel/config.js +109 -0
- package/dist/otel/config.js.map +1 -0
- package/dist/otel/index.d.ts +4 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +3 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/otel/receiver.d.ts +10 -0
- package/dist/otel/receiver.d.ts.map +1 -0
- package/dist/otel/receiver.js +155 -0
- package/dist/otel/receiver.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +3 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/ingest.d.ts +20 -0
- package/dist/parser/ingest.d.ts.map +1 -0
- package/dist/parser/ingest.js +98 -0
- package/dist/parser/ingest.js.map +1 -0
- package/dist/parser/jsonl.d.ts +14 -0
- package/dist/parser/jsonl.d.ts.map +1 -0
- package/dist/parser/jsonl.js +202 -0
- package/dist/parser/jsonl.js.map +1 -0
- package/dist/parser/types.d.ts +81 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +9 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/parser/watcher.d.ts +16 -0
- package/dist/parser/watcher.d.ts.map +1 -0
- package/dist/parser/watcher.js +103 -0
- package/dist/parser/watcher.js.map +1 -0
- package/dist/pricing/index.d.ts +2 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +37 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/service/index.d.ts +31 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +252 -0
- package/dist/service/index.js.map +1 -0
- package/dist/storage/db.d.ts +75 -0
- package/dist/storage/db.d.ts.map +1 -0
- package/dist/storage/db.js +117 -0
- package/dist/storage/db.js.map +1 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +3 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/repo.d.ts +162 -0
- package/dist/storage/repo.d.ts.map +1 -0
- package/dist/storage/repo.js +472 -0
- package/dist/storage/repo.js.map +1 -0
- package/dist/sync/client.d.ts +24 -0
- package/dist/sync/client.d.ts.map +1 -0
- package/dist/sync/client.js +41 -0
- package/dist/sync/client.js.map +1 -0
- package/dist/sync/index.d.ts +18 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +135 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/sync.test.d.ts +2 -0
- package/dist/sync/sync.test.d.ts.map +1 -0
- package/dist/sync/sync.test.js +412 -0
- package/dist/sync/sync.test.js.map +1 -0
- package/dist/sync/transform.d.ts +80 -0
- package/dist/sync/transform.d.ts.map +1 -0
- package/dist/sync/transform.js +90 -0
- package/dist/sync/transform.js.map +1 -0
- package/package.json +50 -0
- package/src/cli/commands.ts +332 -0
- package/src/cli/format.ts +133 -0
- package/src/context/index.ts +42 -0
- package/src/dashboard/html.ts +97 -0
- package/src/dashboard/index.html +1245 -0
- package/src/hooks/config.ts +119 -0
- package/src/hooks/git.ts +77 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/server.ts +397 -0
- package/src/index.ts +6 -0
- package/src/otel/config.ts +141 -0
- package/src/otel/index.ts +8 -0
- package/src/otel/receiver.ts +183 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/ingest.ts +119 -0
- package/src/parser/jsonl.ts +241 -0
- package/src/parser/types.ts +89 -0
- package/src/parser/watcher.ts +116 -0
- package/src/pricing/index.ts +51 -0
- package/src/service/index.ts +272 -0
- package/src/storage/db.ts +198 -0
- package/src/storage/index.ts +3 -0
- package/src/storage/repo.ts +601 -0
- package/src/sync/client.ts +63 -0
- package/src/sync/index.ts +207 -0
- package/src/sync/sync.test.ts +447 -0
- package/src/sync/transform.ts +184 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SessionRow, TurnRow, ToolUseRow, HookEventRow, TaskTagRow,
|
|
3
|
+
} from "../storage/db.js";
|
|
4
|
+
|
|
5
|
+
// ── API payload types (matches POST /sessions/{id}/sync) ──
|
|
6
|
+
|
|
7
|
+
export type ApiSession = {
|
|
8
|
+
id: string;
|
|
9
|
+
project_path: string | null;
|
|
10
|
+
started_at: string;
|
|
11
|
+
ended_at: string | null;
|
|
12
|
+
total_input_tokens: number;
|
|
13
|
+
total_output_tokens: number;
|
|
14
|
+
total_cache_read_tokens: number;
|
|
15
|
+
total_cache_creation_tokens: number;
|
|
16
|
+
total_cost_usd: number;
|
|
17
|
+
total_turns: number;
|
|
18
|
+
total_duration_ms: number;
|
|
19
|
+
model: string | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ApiTurn = {
|
|
23
|
+
turn_index: number;
|
|
24
|
+
role: string;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
input_tokens: number;
|
|
27
|
+
output_tokens: number;
|
|
28
|
+
cache_read_tokens: number;
|
|
29
|
+
cache_creation_tokens: number;
|
|
30
|
+
cost_usd: number;
|
|
31
|
+
duration_ms: number;
|
|
32
|
+
model: string | null;
|
|
33
|
+
content_text: string | null;
|
|
34
|
+
tool_calls: unknown[] | null;
|
|
35
|
+
is_real_user: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ApiToolUse = {
|
|
39
|
+
turn_index: number | null;
|
|
40
|
+
tool_name: string;
|
|
41
|
+
tool_input: unknown | null;
|
|
42
|
+
tool_result: string | null;
|
|
43
|
+
success: boolean | null;
|
|
44
|
+
duration_ms: number;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type ApiHookEvent = {
|
|
49
|
+
event_name: string;
|
|
50
|
+
timestamp: string;
|
|
51
|
+
payload: unknown;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type ApiTaskTag = {
|
|
55
|
+
turn_index: number | null;
|
|
56
|
+
task: string;
|
|
57
|
+
tagged_at: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ApiOtelMetric = {
|
|
61
|
+
name: string;
|
|
62
|
+
value: number;
|
|
63
|
+
attributes: unknown | null;
|
|
64
|
+
session_id: string | null;
|
|
65
|
+
model: string | null;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type ApiOtelEvent = {
|
|
70
|
+
event_name: string;
|
|
71
|
+
attributes: unknown | null;
|
|
72
|
+
session_id: string | null;
|
|
73
|
+
prompt_id: string | null;
|
|
74
|
+
timestamp: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type SessionSyncPayload = {
|
|
78
|
+
session: ApiSession;
|
|
79
|
+
turns: ApiTurn[];
|
|
80
|
+
tool_uses: ApiToolUse[];
|
|
81
|
+
task_tags: ApiTaskTag[];
|
|
82
|
+
hook_events: ApiHookEvent[];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// ── Safe JSON parse ──
|
|
86
|
+
|
|
87
|
+
function safeJsonParse(value: string | null): unknown | null {
|
|
88
|
+
if (value == null) return null;
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(value);
|
|
91
|
+
} catch {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── Turn lookup: local turn_id → turn_index ──
|
|
97
|
+
|
|
98
|
+
export type TurnLookup = Map<number, number>; // turn_id → turn_index
|
|
99
|
+
|
|
100
|
+
// ── Transform functions ──
|
|
101
|
+
|
|
102
|
+
export function transformSession(row: SessionRow): ApiSession {
|
|
103
|
+
return {
|
|
104
|
+
id: row.id,
|
|
105
|
+
project_path: row.project_path,
|
|
106
|
+
started_at: row.started_at,
|
|
107
|
+
ended_at: row.ended_at,
|
|
108
|
+
total_input_tokens: row.total_input_tokens,
|
|
109
|
+
total_output_tokens: row.total_output_tokens,
|
|
110
|
+
total_cache_read_tokens: row.total_cache_read_tokens,
|
|
111
|
+
total_cache_creation_tokens: row.total_cache_creation_tokens,
|
|
112
|
+
total_cost_usd: row.total_cost_usd,
|
|
113
|
+
total_turns: row.total_turns,
|
|
114
|
+
total_duration_ms: row.total_duration_ms,
|
|
115
|
+
model: row.model,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function transformTurn(row: TurnRow): ApiTurn {
|
|
120
|
+
return {
|
|
121
|
+
turn_index: row.turn_index,
|
|
122
|
+
role: row.role,
|
|
123
|
+
timestamp: row.timestamp,
|
|
124
|
+
input_tokens: row.input_tokens,
|
|
125
|
+
output_tokens: row.output_tokens,
|
|
126
|
+
cache_read_tokens: row.cache_read_tokens,
|
|
127
|
+
cache_creation_tokens: row.cache_creation_tokens,
|
|
128
|
+
cost_usd: row.cost_usd,
|
|
129
|
+
duration_ms: row.duration_ms,
|
|
130
|
+
model: row.model,
|
|
131
|
+
content_text: row.content_text,
|
|
132
|
+
tool_calls: safeJsonParse(row.tool_calls) as unknown[] | null,
|
|
133
|
+
is_real_user: row.is_real_user === 1,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function transformToolUse(row: ToolUseRow, turnLookup: TurnLookup): ApiToolUse {
|
|
138
|
+
return {
|
|
139
|
+
turn_index: row.turn_id != null ? (turnLookup.get(row.turn_id) ?? null) : null,
|
|
140
|
+
tool_name: row.tool_name,
|
|
141
|
+
tool_input: safeJsonParse(row.tool_input),
|
|
142
|
+
tool_result: row.tool_result,
|
|
143
|
+
success: row.success == null ? null : row.success === 1,
|
|
144
|
+
duration_ms: row.duration_ms,
|
|
145
|
+
timestamp: row.timestamp,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function transformHookEvent(row: HookEventRow): ApiHookEvent {
|
|
150
|
+
return {
|
|
151
|
+
event_name: row.event_name,
|
|
152
|
+
timestamp: row.timestamp,
|
|
153
|
+
payload: safeJsonParse(row.payload) ?? row.payload,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function transformTaskTag(row: TaskTagRow, turnLookup: TurnLookup): ApiTaskTag {
|
|
158
|
+
return {
|
|
159
|
+
turn_index: turnLookup.get(row.turn_id) ?? null,
|
|
160
|
+
task: row.task,
|
|
161
|
+
tagged_at: row.tagged_at,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function transformOtelMetric(row: import("../storage/db.js").OtelMetricRow): ApiOtelMetric {
|
|
166
|
+
return {
|
|
167
|
+
name: row.name,
|
|
168
|
+
value: row.value,
|
|
169
|
+
attributes: safeJsonParse(row.attributes),
|
|
170
|
+
session_id: row.session_id,
|
|
171
|
+
model: row.model,
|
|
172
|
+
timestamp: row.timestamp,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function transformOtelEvent(row: import("../storage/db.js").OtelEventRow): ApiOtelEvent {
|
|
177
|
+
return {
|
|
178
|
+
event_name: row.event_name,
|
|
179
|
+
attributes: safeJsonParse(row.attributes),
|
|
180
|
+
session_id: row.session_id,
|
|
181
|
+
prompt_id: row.prompt_id,
|
|
182
|
+
timestamp: row.timestamp,
|
|
183
|
+
};
|
|
184
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|