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.
Files changed (139) hide show
  1. package/.env.example +44 -0
  2. package/.github/workflows/publish.yml +26 -0
  3. package/DEVELOPMENT.md +288 -0
  4. package/LICENSE +201 -0
  5. package/README.md +178 -0
  6. package/dist/cli/commands.d.ts +3 -0
  7. package/dist/cli/commands.d.ts.map +1 -0
  8. package/dist/cli/commands.js +307 -0
  9. package/dist/cli/commands.js.map +1 -0
  10. package/dist/cli/format.d.ts +5 -0
  11. package/dist/cli/format.d.ts.map +1 -0
  12. package/dist/cli/format.js +115 -0
  13. package/dist/cli/format.js.map +1 -0
  14. package/dist/context/index.d.ts +8 -0
  15. package/dist/context/index.d.ts.map +1 -0
  16. package/dist/context/index.js +37 -0
  17. package/dist/context/index.js.map +1 -0
  18. package/dist/dashboard/html.d.ts +17 -0
  19. package/dist/dashboard/html.d.ts.map +1 -0
  20. package/dist/dashboard/html.js +79 -0
  21. package/dist/dashboard/html.js.map +1 -0
  22. package/dist/dashboard/index.html +1245 -0
  23. package/dist/hooks/config.d.ts +19 -0
  24. package/dist/hooks/config.d.ts.map +1 -0
  25. package/dist/hooks/config.js +106 -0
  26. package/dist/hooks/config.js.map +1 -0
  27. package/dist/hooks/git.d.ts +6 -0
  28. package/dist/hooks/git.d.ts.map +1 -0
  29. package/dist/hooks/git.js +73 -0
  30. package/dist/hooks/git.js.map +1 -0
  31. package/dist/hooks/index.d.ts +4 -0
  32. package/dist/hooks/index.d.ts.map +1 -0
  33. package/dist/hooks/index.js +3 -0
  34. package/dist/hooks/index.js.map +1 -0
  35. package/dist/hooks/server.d.ts +16 -0
  36. package/dist/hooks/server.d.ts.map +1 -0
  37. package/dist/hooks/server.js +349 -0
  38. package/dist/hooks/server.js.map +1 -0
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +6 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/otel/config.d.ts +36 -0
  44. package/dist/otel/config.d.ts.map +1 -0
  45. package/dist/otel/config.js +109 -0
  46. package/dist/otel/config.js.map +1 -0
  47. package/dist/otel/index.d.ts +4 -0
  48. package/dist/otel/index.d.ts.map +1 -0
  49. package/dist/otel/index.js +3 -0
  50. package/dist/otel/index.js.map +1 -0
  51. package/dist/otel/receiver.d.ts +10 -0
  52. package/dist/otel/receiver.d.ts.map +1 -0
  53. package/dist/otel/receiver.js +155 -0
  54. package/dist/otel/receiver.js.map +1 -0
  55. package/dist/parser/index.d.ts +4 -0
  56. package/dist/parser/index.d.ts.map +1 -0
  57. package/dist/parser/index.js +3 -0
  58. package/dist/parser/index.js.map +1 -0
  59. package/dist/parser/ingest.d.ts +20 -0
  60. package/dist/parser/ingest.d.ts.map +1 -0
  61. package/dist/parser/ingest.js +98 -0
  62. package/dist/parser/ingest.js.map +1 -0
  63. package/dist/parser/jsonl.d.ts +14 -0
  64. package/dist/parser/jsonl.d.ts.map +1 -0
  65. package/dist/parser/jsonl.js +202 -0
  66. package/dist/parser/jsonl.js.map +1 -0
  67. package/dist/parser/types.d.ts +81 -0
  68. package/dist/parser/types.d.ts.map +1 -0
  69. package/dist/parser/types.js +9 -0
  70. package/dist/parser/types.js.map +1 -0
  71. package/dist/parser/watcher.d.ts +16 -0
  72. package/dist/parser/watcher.d.ts.map +1 -0
  73. package/dist/parser/watcher.js +103 -0
  74. package/dist/parser/watcher.js.map +1 -0
  75. package/dist/pricing/index.d.ts +2 -0
  76. package/dist/pricing/index.d.ts.map +1 -0
  77. package/dist/pricing/index.js +37 -0
  78. package/dist/pricing/index.js.map +1 -0
  79. package/dist/service/index.d.ts +31 -0
  80. package/dist/service/index.d.ts.map +1 -0
  81. package/dist/service/index.js +252 -0
  82. package/dist/service/index.js.map +1 -0
  83. package/dist/storage/db.d.ts +75 -0
  84. package/dist/storage/db.d.ts.map +1 -0
  85. package/dist/storage/db.js +117 -0
  86. package/dist/storage/db.js.map +1 -0
  87. package/dist/storage/index.d.ts +4 -0
  88. package/dist/storage/index.d.ts.map +1 -0
  89. package/dist/storage/index.js +3 -0
  90. package/dist/storage/index.js.map +1 -0
  91. package/dist/storage/repo.d.ts +162 -0
  92. package/dist/storage/repo.d.ts.map +1 -0
  93. package/dist/storage/repo.js +472 -0
  94. package/dist/storage/repo.js.map +1 -0
  95. package/dist/sync/client.d.ts +24 -0
  96. package/dist/sync/client.d.ts.map +1 -0
  97. package/dist/sync/client.js +41 -0
  98. package/dist/sync/client.js.map +1 -0
  99. package/dist/sync/index.d.ts +18 -0
  100. package/dist/sync/index.d.ts.map +1 -0
  101. package/dist/sync/index.js +135 -0
  102. package/dist/sync/index.js.map +1 -0
  103. package/dist/sync/sync.test.d.ts +2 -0
  104. package/dist/sync/sync.test.d.ts.map +1 -0
  105. package/dist/sync/sync.test.js +412 -0
  106. package/dist/sync/sync.test.js.map +1 -0
  107. package/dist/sync/transform.d.ts +80 -0
  108. package/dist/sync/transform.d.ts.map +1 -0
  109. package/dist/sync/transform.js +90 -0
  110. package/dist/sync/transform.js.map +1 -0
  111. package/package.json +50 -0
  112. package/src/cli/commands.ts +332 -0
  113. package/src/cli/format.ts +133 -0
  114. package/src/context/index.ts +42 -0
  115. package/src/dashboard/html.ts +97 -0
  116. package/src/dashboard/index.html +1245 -0
  117. package/src/hooks/config.ts +119 -0
  118. package/src/hooks/git.ts +77 -0
  119. package/src/hooks/index.ts +7 -0
  120. package/src/hooks/server.ts +397 -0
  121. package/src/index.ts +6 -0
  122. package/src/otel/config.ts +141 -0
  123. package/src/otel/index.ts +8 -0
  124. package/src/otel/receiver.ts +183 -0
  125. package/src/parser/index.ts +3 -0
  126. package/src/parser/ingest.ts +119 -0
  127. package/src/parser/jsonl.ts +241 -0
  128. package/src/parser/types.ts +89 -0
  129. package/src/parser/watcher.ts +116 -0
  130. package/src/pricing/index.ts +51 -0
  131. package/src/service/index.ts +272 -0
  132. package/src/storage/db.ts +198 -0
  133. package/src/storage/index.ts +3 -0
  134. package/src/storage/repo.ts +601 -0
  135. package/src/sync/client.ts +63 -0
  136. package/src/sync/index.ts +207 -0
  137. package/src/sync/sync.test.ts +447 -0
  138. package/src/sync/transform.ts +184 -0
  139. 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
+ }