@minko-ai/minko 0.1.0 → 0.1.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.
Files changed (189) hide show
  1. package/README.md +577 -2
  2. package/assets/mascot-preview.png +0 -0
  3. package/assets/mascot-preview.txt +46 -0
  4. package/assets/mascot-source.png +0 -0
  5. package/assets/skills/README.md +21 -0
  6. package/assets/skills/brainstorming/LICENSE +21 -0
  7. package/assets/skills/brainstorming/SKILL.md +316 -0
  8. package/assets/skills/buddhist-method/LICENSE +21 -0
  9. package/assets/skills/buddhist-method/SKILL.md +137 -0
  10. package/assets/skills/buddhist-method/references/ariyasacca-debug.md +57 -0
  11. package/assets/skills/buddhist-method/references/extended-principles.md +100 -0
  12. package/assets/skills/code-humanizer/LICENSE +21 -0
  13. package/assets/skills/code-humanizer/SKILL.md +174 -0
  14. package/assets/skills/code-review/LICENSE +21 -0
  15. package/assets/skills/code-review/SKILL.md +232 -0
  16. package/assets/skills/code-review/reference/angular.md +768 -0
  17. package/assets/skills/code-review/reference/architecture-review-guide.md +472 -0
  18. package/assets/skills/code-review/reference/c.md +890 -0
  19. package/assets/skills/code-review/reference/code-quality-universal.md +488 -0
  20. package/assets/skills/code-review/reference/code-review-best-practices.md +136 -0
  21. package/assets/skills/code-review/reference/common-bugs-checklist.md +302 -0
  22. package/assets/skills/code-review/reference/cpp.md +893 -0
  23. package/assets/skills/code-review/reference/cross-cutting/async-concurrency-patterns.md +515 -0
  24. package/assets/skills/code-review/reference/cross-cutting/error-handling-principles.md +492 -0
  25. package/assets/skills/code-review/reference/cross-cutting/n-plus-one-queries.md +309 -0
  26. package/assets/skills/code-review/reference/cross-cutting/sql-injection-prevention.md +308 -0
  27. package/assets/skills/code-review/reference/cross-cutting/xss-prevention.md +264 -0
  28. package/assets/skills/code-review/reference/csharp.md +525 -0
  29. package/assets/skills/code-review/reference/css-less-sass.md +661 -0
  30. package/assets/skills/code-review/reference/dart.md +670 -0
  31. package/assets/skills/code-review/reference/django.md +985 -0
  32. package/assets/skills/code-review/reference/fastapi.md +580 -0
  33. package/assets/skills/code-review/reference/go.md +993 -0
  34. package/assets/skills/code-review/reference/java.md +409 -0
  35. package/assets/skills/code-review/reference/java8.md +586 -0
  36. package/assets/skills/code-review/reference/kotlin.md +1018 -0
  37. package/assets/skills/code-review/reference/nestjs.md +593 -0
  38. package/assets/skills/code-review/reference/performance-review-guide.md +816 -0
  39. package/assets/skills/code-review/reference/php.md +684 -0
  40. package/assets/skills/code-review/reference/python.md +1073 -0
  41. package/assets/skills/code-review/reference/qt.md +757 -0
  42. package/assets/skills/code-review/reference/react.md +871 -0
  43. package/assets/skills/code-review/reference/ruby.md +964 -0
  44. package/assets/skills/code-review/reference/rust.md +846 -0
  45. package/assets/skills/code-review/reference/security-review-guide.md +494 -0
  46. package/assets/skills/code-review/reference/svelte.md +1064 -0
  47. package/assets/skills/code-review/reference/swift.md +936 -0
  48. package/assets/skills/code-review/reference/typescript.md +1016 -0
  49. package/assets/skills/code-review/reference/vue.md +924 -0
  50. package/assets/skills/code-review/reference/zig.md +440 -0
  51. package/assets/skills/cyclomatic-complexity/LICENSE +201 -0
  52. package/assets/skills/cyclomatic-complexity/SKILL.md +69 -0
  53. package/assets/skills/five-whys/LICENSE +21 -0
  54. package/assets/skills/five-whys/SKILL.md +247 -0
  55. package/assets/skills/five-whys/examples/performance-regression.md +161 -0
  56. package/assets/skills/five-whys/examples/production-incident.md +134 -0
  57. package/assets/skills/five-whys/references/software-patterns.md +284 -0
  58. package/assets/skills/five-whys/references/toyota-origins.md +257 -0
  59. package/assets/skills/systematic-debugging/LICENSE +21 -0
  60. package/assets/skills/systematic-debugging/SKILL.md +283 -0
  61. package/assets/skills/test-driven-development/LICENSE +21 -0
  62. package/assets/skills/test-driven-development/SKILL.md +330 -0
  63. package/assets/skills/verification-before-completion/LICENSE +21 -0
  64. package/assets/skills/verification-before-completion/SKILL.md +120 -0
  65. package/assets/skills/vibe-sec/LICENSE +201 -0
  66. package/assets/skills/vibe-sec/SKILL.md +758 -0
  67. package/assets/skills/writing-plans/LICENSE +21 -0
  68. package/assets/skills/writing-plans/SKILL.md +204 -0
  69. package/bin/minko.js +2 -2
  70. package/dist/agent/approvalTokens.js +224 -0
  71. package/dist/agent/branchLock.js +315 -0
  72. package/dist/agent/compact.js +182 -0
  73. package/dist/agent/context.js +183 -0
  74. package/dist/agent/cron.js +326 -0
  75. package/dist/agent/hooks.js +211 -0
  76. package/dist/agent/lanes.js +511 -0
  77. package/dist/agent/loop.js +337 -0
  78. package/dist/agent/memory.js +159 -0
  79. package/dist/agent/permissions.js +71 -0
  80. package/dist/agent/plan.js +118 -0
  81. package/dist/agent/prompt.js +120 -0
  82. package/dist/agent/subagent.js +67 -0
  83. package/dist/agent/tasks.js +449 -0
  84. package/dist/agent/transcript.js +62 -0
  85. package/dist/agent/workerStore.js +172 -0
  86. package/dist/agent/workerTypes.js +1 -0
  87. package/dist/agent/workers.js +503 -0
  88. package/dist/cli/app.js +261 -0
  89. package/dist/cli/argv.js +206 -0
  90. package/dist/cli/commandsCommand.js +12 -0
  91. package/dist/cli/configCommand.js +170 -0
  92. package/dist/cli/doctorCommand.js +112 -0
  93. package/dist/cli/exportCommand.js +85 -0
  94. package/dist/cli/forkCommand.js +24 -0
  95. package/dist/cli/linkCommand.js +272 -0
  96. package/dist/cli/loginCommand.js +69 -0
  97. package/dist/cli/mcpLoginCommand.js +68 -0
  98. package/dist/cli/pluginCommand.js +113 -0
  99. package/dist/cli/powerCommand.js +174 -0
  100. package/dist/cli/promptFooter.js +74 -0
  101. package/dist/cli/relayCommand.js +38 -0
  102. package/dist/cli/sandboxCommand.js +31 -0
  103. package/dist/cli/serveCommand.js +104 -0
  104. package/dist/cli/statusCommand.js +120 -0
  105. package/dist/cli/tui.js +1104 -0
  106. package/dist/commands/registry.js +99 -0
  107. package/dist/config/paths.js +81 -0
  108. package/dist/config/store.js +605 -0
  109. package/dist/index.js +199 -0
  110. package/dist/link/protocol.js +159 -0
  111. package/dist/link/relay.js +184 -0
  112. package/dist/link/server.js +566 -0
  113. package/dist/link/tunnel.js +90 -0
  114. package/dist/lsp/client.js +340 -0
  115. package/dist/lsp/tool.js +177 -0
  116. package/dist/mcp/client.js +469 -0
  117. package/dist/mcp/httpClient.js +191 -0
  118. package/dist/mcp/server.js +206 -0
  119. package/dist/mcp/tools.js +173 -0
  120. package/dist/oauth/device.js +111 -0
  121. package/dist/oauth/store.js +56 -0
  122. package/dist/plugins/loader.js +291 -0
  123. package/dist/plugins/market.js +98 -0
  124. package/dist/providers/anthropic.js +279 -0
  125. package/dist/providers/factory.js +109 -0
  126. package/dist/providers/openai.js +182 -0
  127. package/dist/providers/retry.js +95 -0
  128. package/dist/providers/sse.js +67 -0
  129. package/dist/providers/types.js +10 -0
  130. package/dist/rag/embeddings.js +171 -0
  131. package/dist/rag/index.js +373 -0
  132. package/dist/rag/server.js +167 -0
  133. package/dist/rag/tool.js +148 -0
  134. package/dist/sandbox/index.js +55 -0
  135. package/dist/sdk/server.js +150 -0
  136. package/dist/sdk/session.js +104 -0
  137. package/dist/session/liveness.js +148 -0
  138. package/dist/session/recorder.js +49 -0
  139. package/dist/session/store.js +171 -0
  140. package/dist/skills/index.js +428 -0
  141. package/dist/theme.js +30 -0
  142. package/dist/tools/fs.js +195 -0
  143. package/dist/tools/notebook.js +109 -0
  144. package/dist/tools/registry.js +32 -0
  145. package/dist/tools/search.js +130 -0
  146. package/dist/tools/shell.js +200 -0
  147. package/dist/tools/structured.js +83 -0
  148. package/dist/tools/types.js +1 -0
  149. package/dist/ui/ansi.js +135 -0
  150. package/dist/ui/banner.js +103 -0
  151. package/dist/ui/input.js +49 -0
  152. package/dist/ui/inputModel.js +113 -0
  153. package/dist/ui/keyboard.js +142 -0
  154. package/dist/ui/mascot.js +34 -0
  155. package/dist/ui/mascotData.js +96 -0
  156. package/dist/ui/md.js +183 -0
  157. package/dist/ui/screen.js +49 -0
  158. package/dist/ui/spinner.js +52 -0
  159. package/dist/ui/transcript.js +287 -0
  160. package/dist/util/clipboard.js +53 -0
  161. package/dist/util/errors.js +50 -0
  162. package/dist/util/version.js +12 -0
  163. package/dist/web/fetch.js +168 -0
  164. package/dist/web/search.js +97 -0
  165. package/package.json +45 -36
  166. package/src/agent/loop.ts +0 -159
  167. package/src/agent/prompt.ts +0 -45
  168. package/src/cli/app.ts +0 -396
  169. package/src/cli/argv.ts +0 -139
  170. package/src/cli/configCommand.ts +0 -175
  171. package/src/config/paths.ts +0 -20
  172. package/src/config/store.ts +0 -149
  173. package/src/index.ts +0 -120
  174. package/src/providers/anthropic.ts +0 -215
  175. package/src/providers/openai.ts +0 -158
  176. package/src/providers/sse.ts +0 -57
  177. package/src/providers/types.ts +0 -59
  178. package/src/session/store.ts +0 -125
  179. package/src/theme.ts +0 -41
  180. package/src/tools/fs.ts +0 -143
  181. package/src/tools/registry.ts +0 -19
  182. package/src/tools/shell.ts +0 -120
  183. package/src/tools/types.ts +0 -26
  184. package/src/ui/ansi.ts +0 -110
  185. package/src/ui/banner.ts +0 -39
  186. package/src/ui/input.ts +0 -54
  187. package/src/ui/md.ts +0 -160
  188. package/src/ui/spinner.ts +0 -58
  189. package/src/util/errors.ts +0 -48
@@ -0,0 +1,440 @@
1
+ # Zig Code Review Guide
2
+
3
+ > Code review guidelines for Zig focusing on explicit memory ownership, error unions, defer/errdefer cleanup, comptime usage, safety-checked operations, C interop, and tests.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Memory & Allocators](#memory--allocators)
8
+ - [Errors & Cleanup](#errors--cleanup)
9
+ - [Pointers, Slices & Optionals](#pointers-slices--optionals)
10
+ - [Comptime & Generics](#comptime--generics)
11
+ - [Safety, Undefined Behavior & Casts](#safety-undefined-behavior--casts)
12
+ - [C Interop](#c-interop)
13
+ - [Testing](#testing)
14
+ - [Style & API Design](#style--api-design)
15
+ - [Review Checklist](#review-checklist)
16
+ - [References](#references)
17
+
18
+ ---
19
+
20
+ ## Memory & Allocators
21
+
22
+ ### Make Allocator Ownership Explicit
23
+
24
+ Zig code should make allocation policy visible. Libraries should usually accept an `std.mem.Allocator` from the caller rather than creating a global allocator internally.
25
+
26
+ ```zig
27
+ const std = @import("std");
28
+
29
+ // ❌ Bad: hides allocation policy and lifetime from callers.
30
+ fn readNamesBad() ![][]const u8 {
31
+ var gpa = std.heap.DebugAllocator(.{}){};
32
+ const allocator = gpa.allocator();
33
+ return try allocator.alloc([]const u8, 10);
34
+ }
35
+
36
+ // ✅ Good: caller chooses allocator and owns the returned memory.
37
+ fn readNames(allocator: std.mem.Allocator) ![][]const u8 {
38
+ return try allocator.alloc([]const u8, 10);
39
+ }
40
+ ```
41
+
42
+ Review questions:
43
+ - Does the caller know who owns allocated memory?
44
+ - Does the API document whether returned slices must be freed?
45
+ - Is the allocator parameter passed through instead of replaced by an internal global allocator?
46
+
47
+ ### Pair Allocations With Cleanup
48
+
49
+ Every allocation path should have a visible cleanup path. Look for missing `defer`, missing `errdefer`, and containers that are initialized but never deinitialized.
50
+
51
+ ```zig
52
+ const std = @import("std");
53
+
54
+ fn collectBad(allocator: std.mem.Allocator) ![]u8 {
55
+ // ❌ Bad: returns a slice whose backing memory is freed as the function exits.
56
+ var bad_list: std.ArrayListUnmanaged(u8) = .empty;
57
+ defer bad_list.deinit(allocator);
58
+ try bad_list.append(allocator, 'a');
59
+ return bad_list.items;
60
+ }
61
+
62
+ fn collect(allocator: std.mem.Allocator) ![]u8 {
63
+ // ✅ Good: `errdefer` cleans up only on failure; success transfers ownership.
64
+ var list: std.ArrayListUnmanaged(u8) = .empty;
65
+ errdefer list.deinit(allocator);
66
+
67
+ try list.append(allocator, 'a');
68
+ try list.append(allocator, 'b');
69
+ return try list.toOwnedSlice(allocator);
70
+ }
71
+ ```
72
+
73
+ Review questions:
74
+ - Is cleanup registered immediately after acquisition?
75
+ - Is `errdefer` used when ownership transfers only on success?
76
+ - Are `deinit` calls paired with all container initializations?
77
+
78
+ ### Choose Allocators Deliberately
79
+
80
+ Allocator choice is part of the design. A review should flag broad use of a debug/general-purpose allocator where a fixed buffer, arena, page allocator, or caller-provided allocator better matches the lifetime.
81
+
82
+ ```zig
83
+ // ❌ Bad: allocation lifetime is scattered across many individual frees.
84
+ const user = try allocator.create(User);
85
+ const events = try allocator.alloc(Event, event_count);
86
+
87
+ // ✅ Good: request/frame-scoped allocations are freed together.
88
+ var arena = std.heap.ArenaAllocator.init(parent_allocator);
89
+ defer arena.deinit();
90
+ const allocator = arena.allocator();
91
+ ```
92
+
93
+ Review questions:
94
+ - Are arena allocations freed at a clear lifetime boundary?
95
+ - Is a test using `std.testing.allocator` to catch leaks?
96
+ - Is a library avoiding policy decisions that belong to its caller?
97
+
98
+ ---
99
+
100
+ ## Errors & Cleanup
101
+
102
+ ### Keep Error Sets Useful
103
+
104
+ Avoid flattening meaningful errors into `anyerror` unless the boundary genuinely needs it. Specific error sets improve API contracts and make callers handle expected failures.
105
+
106
+ ```zig
107
+ // ❌ Bad: erases the expected parse failures behind `anyerror`.
108
+ fn parseDigitAny(input: []const u8) anyerror!u8 {
109
+ if (input.len == 0) return error.EmptyInput;
110
+ if (input[0] < '0' or input[0] > '9') return error.InvalidDigit;
111
+ return input[0] - '0';
112
+ }
113
+
114
+ // ✅ Good: names the domain failures that callers should handle.
115
+ const ParseError = error{
116
+ EmptyInput,
117
+ InvalidDigit,
118
+ };
119
+
120
+ fn parseDigit(input: []const u8) ParseError!u8 {
121
+ if (input.len == 0) return error.EmptyInput;
122
+ if (input[0] < '0' or input[0] > '9') return error.InvalidDigit;
123
+ return input[0] - '0';
124
+ }
125
+ ```
126
+
127
+ Review questions:
128
+ - Are expected domain failures named explicitly?
129
+ - Is `anyerror` only used at integration boundaries?
130
+ - Does the caller preserve context when converting errors?
131
+
132
+ ### Use `try`, `catch`, and `errdefer` Intentionally
133
+
134
+ Blind `catch unreachable` is a code smell unless the invariant is mechanically guaranteed. Prefer propagating errors with `try`, converting them at boundaries, or adding a comment for unreachable invariants.
135
+
136
+ ```zig
137
+ // ❌ Bad: hides a real allocation failure.
138
+ const buffer_bad = allocator.alloc(u8, size) catch unreachable;
139
+
140
+ // ✅ Good: caller can handle OutOfMemory.
141
+ const buffer = try allocator.alloc(u8, size);
142
+ ```
143
+
144
+ Review questions:
145
+ - Does `catch unreachable` mask I/O, allocation, parsing, or user-input errors?
146
+ - Are errors converted close to a boundary where the abstraction changes?
147
+ - Does `errdefer` undo partial state changes on failure?
148
+
149
+ ---
150
+
151
+ ## Pointers, Slices & Optionals
152
+
153
+ ### Prefer Slices Over Pointer Plus Length
154
+
155
+ Slices carry pointer and length together, improving bounds checking and API clarity. Raw pointer plus length should be reserved for FFI or very low-level code.
156
+
157
+ ```zig
158
+ // ❌ Bad: easy to mismatch pointer and length.
159
+ fn checksumRaw(ptr: [*]const u8, len: usize) u32 {
160
+ var sum: u32 = 0;
161
+ for (ptr[0..len]) |byte| sum += byte;
162
+ return sum;
163
+ }
164
+
165
+ // ✅ Good: one value represents the buffer.
166
+ fn checksum(bytes: []const u8) u32 {
167
+ var sum: u32 = 0;
168
+ for (bytes) |byte| sum += byte;
169
+ return sum;
170
+ }
171
+ ```
172
+
173
+ Review questions:
174
+ - Can a raw pointer API become a slice API?
175
+ - Is nullability modeled with `?T` instead of sentinel values?
176
+ - Are pointer lifetimes clear after returning from a function?
177
+
178
+ ### Avoid Returning Pointers to Stack Data
179
+
180
+ Review returned slices and pointers carefully. Zig makes many lifetime issues visible, but reviewers should still check that returned data outlives the function.
181
+
182
+ ```zig
183
+ // ❌ Bad: returned slice points to stack memory.
184
+ fn labelStack() []const u8 {
185
+ var buf: [16]u8 = undefined;
186
+ _ = &buf;
187
+ return buf[0..];
188
+ }
189
+
190
+ // ✅ Good: caller owns the allocated result and can free it.
191
+ fn label(allocator: std.mem.Allocator) ![]u8 {
192
+ return try allocator.dupe(u8, "ready");
193
+ }
194
+ ```
195
+
196
+ Review questions:
197
+ - Does returned memory come from the caller, allocator, static storage, or a stable owner?
198
+ - Does a slice escape after its backing buffer is mutated or freed?
199
+ - Is aliasing intentional and documented for mutable slices?
200
+
201
+ ---
202
+
203
+ ## Comptime & Generics
204
+
205
+ ### Keep Comptime Work Bounded and Readable
206
+
207
+ `comptime` is powerful, but complex compile-time code can make error messages and build times worse. Prefer small generic helpers with clear type contracts.
208
+
209
+ ```zig
210
+ fn RingBuffer(comptime T: type, comptime capacity: usize) type {
211
+ // ✅ Good: invalid generic parameters fail with an actionable message.
212
+ if (capacity == 0) @compileError("capacity must be greater than zero");
213
+
214
+ return struct {
215
+ items: [capacity]T = undefined,
216
+ len: usize = 0,
217
+ };
218
+ }
219
+ ```
220
+
221
+ Review questions:
222
+ - Does `comptime` enforce a real invariant?
223
+ - Are compile errors explicit and actionable?
224
+ - Is reflection code isolated from ordinary runtime logic?
225
+
226
+ ### Avoid Overly Broad `anytype`
227
+
228
+ `anytype` can make APIs flexible, but it can also hide required capabilities. Add comptime checks or prefer concrete interfaces when possible.
229
+
230
+ ```zig
231
+ // ✅ Good: the required writer capability is obvious at the call site.
232
+ fn writeAll(writer: anytype, bytes: []const u8) !void {
233
+ try writer.writeAll(bytes);
234
+ }
235
+ ```
236
+
237
+ Review questions:
238
+ - Is the required shape of `anytype` clear from the function body or docs?
239
+ - Would a concrete type or smaller helper be easier to review?
240
+ - Are compile errors understandable when the wrong type is passed?
241
+
242
+ ---
243
+
244
+ ## Safety, Undefined Behavior & Casts
245
+
246
+ ### Treat `undefined`, `unreachable`, and Casts as Review Hotspots
247
+
248
+ Zig exposes low-level control directly. Review every `undefined`, `unreachable`, `@ptrCast`, `@alignCast`, `@intCast`, and pointer/int conversion.
249
+
250
+ ```zig
251
+ // ❌ Bad: assumes data layout, byte order, length, and alignment without proof.
252
+ const header: *const Header = @ptrCast(@alignCast(bytes.ptr));
253
+
254
+ // ✅ Good: parse fields explicitly and check length before reading.
255
+ if (bytes.len < 4) return error.ShortInput;
256
+ const magic = std.mem.readInt(u16, bytes[0..2], .little);
257
+ const flags = std.mem.readInt(u16, bytes[2..4], .little);
258
+ ```
259
+
260
+ Review questions:
261
+ - Is `undefined` overwritten before being read?
262
+ - Is `unreachable` only used for impossible states, with a nearby explanation when non-obvious?
263
+ - Are casts preceded by checks for layout, range, alignment, size, byte order, and nullability?
264
+
265
+ ### Prefer Checked Arithmetic Unless Wrapping Is Intentional
266
+
267
+ Wrapping operators such as `+%` and `-%` are useful, but they should communicate a deliberate modular arithmetic choice.
268
+
269
+ ```zig
270
+ // ❌ Bad: wrapping silences overflow that should expose a logic bug.
271
+ index = index +% 1;
272
+
273
+ // ✅ Good: checked arithmetic traps on unexpected overflow.
274
+ sum += byte;
275
+
276
+ // ✅ Good: wrapping is intentional for modular hash behavior.
277
+ hash = hash *% 16777619;
278
+ hash = hash +% byte;
279
+ ```
280
+
281
+ Review questions:
282
+ - Is wrapping arithmetic required by an algorithm?
283
+ - Would overflow indicate invalid input or a bug?
284
+ - Are integer width changes explicit and tested around boundaries?
285
+
286
+ ---
287
+
288
+ ## C Interop
289
+
290
+ ### Contain C Boundaries
291
+
292
+ Keep `@cImport`, C pointer handling, and ABI assumptions close to a wrapper layer. Convert C data into Zig types before it spreads through the codebase.
293
+
294
+ ```zig
295
+ const std = @import("std");
296
+
297
+ // ❌ Bad: uses C strlen when no external C boundary is needed.
298
+ fn strlenC(input: [*:0]const u8) usize {
299
+ const c = @cImport({
300
+ @cInclude("string.h");
301
+ });
302
+
303
+ return c.strlen(input);
304
+ }
305
+
306
+ // ✅ Good: use Zig's sentinel-aware standard library helper.
307
+ fn strlenZ(input: [*:0]const u8) usize {
308
+ return std.mem.len(input);
309
+ }
310
+ ```
311
+
312
+ Review questions:
313
+ - Are C pointers represented with the correct Zig pointer type?
314
+ - Are sentinel-terminated strings modeled as sentinel pointers or slices?
315
+ - Are ownership and cleanup rules from the C library documented?
316
+ - Are C error codes converted into Zig error unions near the boundary?
317
+
318
+ ---
319
+
320
+ ## Testing
321
+
322
+ ### Use `std.testing` Assertions and Leak Detection
323
+
324
+ Tests that allocate should use `std.testing.allocator` where practical so leaks are reported by the test runner.
325
+
326
+ ```zig
327
+ const std = @import("std");
328
+
329
+ test "collect returns owned memory on success" {
330
+ const allocator = std.testing.allocator;
331
+ const names = try collect(allocator);
332
+ defer allocator.free(names);
333
+
334
+ try std.testing.expectEqual(@as(usize, 2), names.len);
335
+ }
336
+
337
+ test "collect handles allocation failures cleanly" {
338
+ var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{
339
+ .fail_index = 0,
340
+ });
341
+ try std.testing.expectError(error.OutOfMemory, collect(failing.allocator()));
342
+ }
343
+ ```
344
+
345
+ Review questions:
346
+ - Are allocation-heavy paths covered by tests?
347
+ - Are error paths tested with `std.testing.expectError`?
348
+ - Do tests cover boundary sizes such as empty input, one element, max capacity, and invalid encodings?
349
+
350
+ ### Test Build Modes and Targets When Relevant
351
+
352
+ Behavior can differ across safety modes, targets, and ABIs. For low-level code, ask whether the PR was tested with the intended target and optimization mode.
353
+
354
+ Review questions:
355
+ - Does code rely on debug-only safety checks?
356
+ - Does packed/aligned/extern layout code have target-aware tests?
357
+ - Are endian, pointer-width, and ABI assumptions tested or documented?
358
+
359
+ ---
360
+
361
+ ## Style & API Design
362
+
363
+ ### Follow Zig Naming Conventions
364
+
365
+ Use the official style guide as the baseline: `TitleCase` for types, `camelCase` for functions, and `snake_case` for variables. Avoid redundant words such as `Value`, `Data`, `Manager`, or `State` when the surrounding namespace already provides that meaning.
366
+
367
+ ```zig
368
+ // ❌ Bad: redundant namespace and vague type name.
369
+ pub const json_bad = struct {
370
+ pub const JsonValueManager = struct {};
371
+ };
372
+
373
+ // ✅ Good: name is meaningful in its fully-qualified namespace.
374
+ pub const json = struct {
375
+ pub const Value = union(enum) {};
376
+ };
377
+ ```
378
+
379
+ Review questions:
380
+ - Does the fully-qualified name read naturally?
381
+ - Are file and directory names consistent with the style guide?
382
+ - Are underscore-prefixed declarations avoided unless they come from an external convention?
383
+ - Are public APIs documented with doc comments where helpful?
384
+
385
+ ### Keep Public APIs Small
386
+
387
+ Zig modules often expose declarations directly from files and structs. Review public declarations for accidental exports.
388
+
389
+ Review questions:
390
+ - Should this declaration be `pub`?
391
+ - Is the public API stable enough to expose?
392
+ - Are implementation details hidden behind a smaller surface?
393
+
394
+ ---
395
+
396
+ ## Review Checklist
397
+
398
+ ### Memory & Lifetime
399
+ - [ ] Allocator ownership is explicit.
400
+ - [ ] Allocations have matching `free`, `deinit`, `defer`, or `errdefer`.
401
+ - [ ] Returned slices and pointers outlive the function.
402
+ - [ ] Arena or temporary allocations have a clear lifetime boundary.
403
+
404
+ ### Errors & Cleanup
405
+ - [ ] Expected failures use specific error sets where practical.
406
+ - [ ] `catch unreachable` does not hide real runtime failures.
407
+ - [ ] Partial initialization is rolled back with `errdefer`.
408
+ - [ ] Error conversions happen at abstraction boundaries.
409
+
410
+ ### Pointers & Safety
411
+ - [ ] Raw pointers are justified; slices are used for ordinary buffers.
412
+ - [ ] Casts check size, range, alignment, and nullability.
413
+ - [ ] `undefined` is not read before initialization.
414
+ - [ ] Wrapping arithmetic is intentional and tested.
415
+
416
+ ### Comptime & API Design
417
+ - [ ] `comptime` logic enforces useful invariants.
418
+ - [ ] `anytype` usage has clear expectations.
419
+ - [ ] Public declarations are intentional.
420
+ - [ ] Names follow Zig style conventions.
421
+
422
+ ### C Interop & Portability
423
+ - [ ] C boundaries are isolated behind wrappers.
424
+ - [ ] C ownership and cleanup rules are documented.
425
+ - [ ] Target, endian, pointer-width, and ABI assumptions are tested or documented.
426
+
427
+ ### Tests
428
+ - [ ] Tests use `std.testing.allocator` for allocation-heavy code.
429
+ - [ ] Error paths use `std.testing.expectError`.
430
+ - [ ] Boundary cases are covered.
431
+ - [ ] Relevant build modes and targets are considered.
432
+
433
+ ---
434
+
435
+ ## References
436
+
437
+ - [Zig 0.16.0 Language Reference](https://ziglang.org/documentation/0.16.0/)
438
+ - [Zig 0.16.0 Standard Library documentation](https://ziglang.org/documentation/0.16.0/std/)
439
+ - [Zig 0.16.0 Style Guide](https://ziglang.org/documentation/0.16.0/#Style-Guide)
440
+ - [Choosing an Allocator](https://ziglang.org/documentation/0.16.0/#Choosing-an-Allocator)
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.