@defai.digital/ax-cli 3.8.6 → 3.8.7

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 (108) hide show
  1. package/.ax-cli/CUSTOM.md +97 -0
  2. package/.ax-cli/auto-accept-audit.json +1302 -0
  3. package/.ax-cli/index.json +43 -0
  4. package/.ax-cli/memory.json +55 -0
  5. package/.ax-cli/settings.json +12 -0
  6. package/ax.config.json +303 -0
  7. package/config-defaults/models.yaml +0 -24
  8. package/config-defaults/settings.yaml +13 -16
  9. package/dist/agent/dependency-resolver.js +22 -1
  10. package/dist/agent/dependency-resolver.js.map +1 -1
  11. package/dist/agent/llm-agent.d.ts +12 -0
  12. package/dist/agent/llm-agent.js +64 -29
  13. package/dist/agent/llm-agent.js.map +1 -1
  14. package/dist/agent/subagent.js +4 -0
  15. package/dist/agent/subagent.js.map +1 -1
  16. package/dist/analyzers/architecture/project-structure-scanner.js +6 -2
  17. package/dist/analyzers/architecture/project-structure-scanner.js.map +1 -1
  18. package/dist/checkpoint/manager.js +18 -4
  19. package/dist/checkpoint/manager.js.map +1 -1
  20. package/dist/checkpoint/storage.d.ts +6 -0
  21. package/dist/checkpoint/storage.js +90 -45
  22. package/dist/checkpoint/storage.js.map +1 -1
  23. package/dist/commands/mcp.js +14 -2
  24. package/dist/commands/mcp.js.map +1 -1
  25. package/dist/commands/setup.js +2 -2
  26. package/dist/commands/setup.js.map +1 -1
  27. package/dist/commands/status.js +36 -10
  28. package/dist/commands/status.js.map +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/llm/client.d.ts +9 -0
  32. package/dist/llm/client.js +306 -45
  33. package/dist/llm/client.js.map +1 -1
  34. package/dist/llm/types.d.ts +1 -47
  35. package/dist/llm/types.js +0 -18
  36. package/dist/llm/types.js.map +1 -1
  37. package/dist/mcp/client-v2.d.ts +3 -0
  38. package/dist/mcp/client-v2.js +85 -19
  39. package/dist/mcp/client-v2.js.map +1 -1
  40. package/dist/mcp/health.js +1 -1
  41. package/dist/mcp/health.js.map +1 -1
  42. package/dist/planner/plan-storage.js +3 -2
  43. package/dist/planner/plan-storage.js.map +1 -1
  44. package/dist/planner/types.d.ts +6 -6
  45. package/dist/schemas/index.d.ts +2 -2
  46. package/dist/tools/bash.js +30 -6
  47. package/dist/tools/bash.js.map +1 -1
  48. package/dist/tools/search.js +12 -13
  49. package/dist/tools/search.js.map +1 -1
  50. package/dist/tools/text-editor.d.ts +46 -0
  51. package/dist/tools/text-editor.js +455 -11
  52. package/dist/tools/text-editor.js.map +1 -1
  53. package/dist/tools/todo-tool.js +2 -2
  54. package/dist/tools/todo-tool.js.map +1 -1
  55. package/dist/tools/web-search/cache.js +1 -1
  56. package/dist/tools/web-search/cache.js.map +1 -1
  57. package/dist/tools/web-search/engines/stackoverflow.d.ts +30 -0
  58. package/dist/tools/web-search/engines/stackoverflow.js +130 -0
  59. package/dist/tools/web-search/engines/stackoverflow.js.map +1 -0
  60. package/dist/tools/web-search/engines/wikipedia.d.ts +27 -0
  61. package/dist/tools/web-search/engines/wikipedia.js +112 -0
  62. package/dist/tools/web-search/engines/wikipedia.js.map +1 -0
  63. package/dist/tools/web-search/router.d.ts +2 -0
  64. package/dist/tools/web-search/router.js +29 -4
  65. package/dist/tools/web-search/router.js.map +1 -1
  66. package/dist/tools/web-search/web-search-tool.js +17 -1
  67. package/dist/tools/web-search/web-search-tool.js.map +1 -1
  68. package/dist/ui/components/chat-input.js +10 -1
  69. package/dist/ui/components/chat-input.js.map +1 -1
  70. package/dist/ui/components/chat-interface.js +1 -0
  71. package/dist/ui/components/chat-interface.js.map +1 -1
  72. package/dist/ui/hooks/use-input-history.js +20 -12
  73. package/dist/ui/hooks/use-input-history.js.map +1 -1
  74. package/dist/utils/api-error.d.ts +61 -0
  75. package/dist/utils/api-error.js +176 -0
  76. package/dist/utils/api-error.js.map +1 -0
  77. package/dist/utils/auto-accept-logger.js +3 -3
  78. package/dist/utils/auto-accept-logger.js.map +1 -1
  79. package/dist/utils/config-loader.js +27 -2
  80. package/dist/utils/config-loader.js.map +1 -1
  81. package/dist/utils/history-migration.js +5 -4
  82. package/dist/utils/history-migration.js.map +1 -1
  83. package/dist/utils/path-helpers.d.ts +8 -0
  84. package/dist/utils/path-helpers.js +34 -0
  85. package/dist/utils/path-helpers.js.map +1 -0
  86. package/dist/utils/retry-helper.d.ts +61 -0
  87. package/dist/utils/retry-helper.js +206 -0
  88. package/dist/utils/retry-helper.js.map +1 -0
  89. package/dist/utils/token-counter.d.ts +5 -0
  90. package/dist/utils/token-counter.js +17 -1
  91. package/dist/utils/token-counter.js.map +1 -1
  92. package/package.json +1 -1
  93. package/packages/schemas/dist/index.d.ts +14 -0
  94. package/packages/schemas/dist/index.d.ts.map +1 -0
  95. package/packages/schemas/dist/index.js +19 -0
  96. package/packages/schemas/dist/index.js.map +1 -0
  97. package/packages/schemas/dist/public/core/brand-types.d.ts +308 -0
  98. package/packages/schemas/dist/public/core/brand-types.d.ts.map +1 -0
  99. package/packages/schemas/dist/public/core/brand-types.js +243 -0
  100. package/packages/schemas/dist/public/core/brand-types.js.map +1 -0
  101. package/packages/schemas/dist/public/core/enums.d.ts +227 -0
  102. package/packages/schemas/dist/public/core/enums.d.ts.map +1 -0
  103. package/packages/schemas/dist/public/core/enums.js +222 -0
  104. package/packages/schemas/dist/public/core/enums.js.map +1 -0
  105. package/packages/schemas/dist/public/core/id-types.d.ts +286 -0
  106. package/packages/schemas/dist/public/core/id-types.d.ts.map +1 -0
  107. package/packages/schemas/dist/public/core/id-types.js +136 -0
  108. package/packages/schemas/dist/public/core/id-types.js.map +1 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @ax-cli/schemas - Single Source of Truth Type System
3
+ *
4
+ * This package provides centralized Zod schemas, brand types, and enums
5
+ * for the entire ax-cli ecosystem.
6
+ *
7
+ * SECURITY: All exports are controlled. Internal helpers are not exposed.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ export { brand, unbrand, isBranded, createBrandFactory, type __brand, type Brand, type ExtractBrand, type ExtractBase, } from './public/core/brand-types.js';
12
+ export { ApiResponseId, ToolCallId, ToolCallIdSchema, ModelId, ModelIdSchema, TenantId, ApiKeyId, MCPServerId, MCPServerIdSchema, UsageRecordId, PlanId, SessionId, RequestId, type ApiResponseId as ApiResponseIdType, type ToolCallId as ToolCallIdType, type ModelId as ModelIdType, type TenantId as TenantIdType, type ApiKeyId as ApiKeyIdType, type MCPServerId as MCPServerIdType, type UsageRecordId as UsageRecordIdType, type PlanId as PlanIdType, type SessionId as SessionIdType, type RequestId as RequestIdType, } from './public/core/id-types.js';
13
+ export { MessageRoleEnum, FinishReasonEnum, TransportEnum, EditorCommandEnum, type MessageRole, type FinishReason, type Transport, type EditorCommand, } from './public/core/enums.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,kBAAkB,EAClB,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,SAAS,EACT,SAAS,EACT,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,UAAU,IAAI,cAAc,EACjC,KAAK,OAAO,IAAI,WAAW,EAC3B,KAAK,QAAQ,IAAI,YAAY,EAC7B,KAAK,QAAQ,IAAI,YAAY,EAC7B,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,MAAM,IAAI,UAAU,EACzB,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,SAAS,IAAI,aAAa,GAChC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @ax-cli/schemas - Single Source of Truth Type System
3
+ *
4
+ * This package provides centralized Zod schemas, brand types, and enums
5
+ * for the entire ax-cli ecosystem.
6
+ *
7
+ * SECURITY: All exports are controlled. Internal helpers are not exposed.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ // Core brand type utilities
12
+ export { brand, unbrand, isBranded, createBrandFactory, } from './public/core/brand-types.js';
13
+ // ID Brand Types
14
+ export { ApiResponseId, ToolCallId, ToolCallIdSchema, ModelId, ModelIdSchema, TenantId, ApiKeyId, MCPServerId, MCPServerIdSchema, UsageRecordId, PlanId, SessionId, RequestId, } from './public/core/id-types.js';
15
+ // Centralized Enums
16
+ export { MessageRoleEnum, FinishReasonEnum, TransportEnum, EditorCommandEnum, } from './public/core/enums.js';
17
+ // Additional exports will be added as we implement them:
18
+ // - Domain schemas (Usage, API, MCP)
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,4BAA4B;AAC5B,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,kBAAkB,GAKnB,MAAM,8BAA8B,CAAC;AAEtC,iBAAiB;AACjB,OAAO,EACL,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,SAAS,EACT,SAAS,GAWV,MAAM,2BAA2B,CAAC;AAEnC,oBAAoB;AACpB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GAKlB,MAAM,wBAAwB,CAAC;AAEhC,yDAAyD;AACzD,qCAAqC"}
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Brand Types Utilities for @ax-cli/schemas
3
+ *
4
+ * CRITICAL SECURITY WARNING:
5
+ * =========================
6
+ * Brand types are COMPILE-TIME ONLY markers. They provide ZERO runtime validation.
7
+ *
8
+ * **YOU MUST VALIDATE ALL INPUTS AT SYSTEM BOUNDARIES**
9
+ *
10
+ * Unsafe usage (WILL FAIL IN PRODUCTION):
11
+ * ```typescript
12
+ * const tenantId = userInput as TenantId; // ❌ NO RUNTIME VALIDATION!
13
+ * ```
14
+ *
15
+ * Safe usage (REQUIRED):
16
+ * ```typescript
17
+ * const result = TenantId.parse(userInput); // ✅ Validates with Zod
18
+ * if (result.success) {
19
+ * const tenantId = result.data; // Type-safe AND runtime-safe
20
+ * }
21
+ * ```
22
+ *
23
+ * WHEN TO USE BRAND TYPES:
24
+ * - Preventing ID mixing at compile time (ApiKeyId vs TenantId)
25
+ * - Enforcing domain boundaries in function signatures
26
+ * - Type-level documentation of intent
27
+ *
28
+ * WHEN TO VALIDATE:
29
+ * - API boundaries (HTTP requests, MCP inputs)
30
+ * - File I/O (reading configs, user settings)
31
+ * - Database queries (WHERE clauses with user IDs)
32
+ * - Environment variables
33
+ * - Command-line arguments
34
+ *
35
+ * PERFORMANCE:
36
+ * Brand types have ZERO runtime cost. They are erased during compilation.
37
+ *
38
+ * @module brand-types
39
+ * @see {@link https://github.com/microsoft/TypeScript/issues/4895|TypeScript Nominal Types}
40
+ */
41
+ /**
42
+ * Unique symbol used as a phantom type marker for branding.
43
+ * This symbol is exported for type compatibility but cannot be accessed at runtime,
44
+ * making it impossible to forge branded types without using the
45
+ * provided constructor functions.
46
+ *
47
+ * @internal
48
+ */
49
+ export declare const __brand: unique symbol;
50
+ /**
51
+ * Brand<T, B> creates a "nominal type" from a structural type.
52
+ *
53
+ * TypeScript uses structural typing by default:
54
+ * ```typescript
55
+ * type UserId = string;
56
+ * type TenantId = string;
57
+ *
58
+ * const user: UserId = "user-123";
59
+ * const tenant: TenantId = user; // ✅ No error! Strings are compatible.
60
+ * ```
61
+ *
62
+ * Brand types enforce nominal typing:
63
+ * ```typescript
64
+ * type UserId = Brand<string, 'UserId'>;
65
+ * type TenantId = Brand<string, 'TenantId'>;
66
+ *
67
+ * const user = brand<string, 'UserId'>("user-123");
68
+ * const tenant: TenantId = user; // ❌ Compile error! Incompatible brands.
69
+ * ```
70
+ *
71
+ * @template T - The base type (string, number, etc.)
72
+ * @template B - The brand identifier (unique string literal)
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * type ApiKeyId = Brand<string, 'ApiKeyId'>;
77
+ * type TenantId = Brand<string, 'TenantId'>;
78
+ *
79
+ * function updateUsage(apiKeyId: ApiKeyId, tenantId: TenantId) {
80
+ * // This function signature makes it impossible to swap arguments
81
+ * }
82
+ *
83
+ * const apiKey = brand<string, 'ApiKeyId'>("ak_123");
84
+ * const tenant = brand<string, 'TenantId'>("tn_456");
85
+ *
86
+ * updateUsage(apiKey, tenant); // ✅ Correct
87
+ * updateUsage(tenant, apiKey); // ❌ Compile error!
88
+ * updateUsage("ak_123", "tn_456"); // ❌ Compile error!
89
+ * ```
90
+ */
91
+ export type Brand<T, B extends string> = T & {
92
+ readonly [__brand]: B;
93
+ };
94
+ /**
95
+ * Creates a branded value.
96
+ *
97
+ * WARNING: This function performs NO VALIDATION. It is a type-level assertion only.
98
+ *
99
+ * Use this ONLY in trusted contexts after validation:
100
+ * - Inside schema .transform() after Zod validation
101
+ * - After database queries that return validated data
102
+ * - In test fixtures with known-good values
103
+ *
104
+ * DO NOT use with user input directly:
105
+ * ```typescript
106
+ * // ❌ UNSAFE - No validation!
107
+ * const userId = brand<string, 'UserId'>(req.body.userId);
108
+ *
109
+ * // ✅ SAFE - Validated first
110
+ * const result = UserIdSchema.safeParse(req.body.userId);
111
+ * if (result.success) {
112
+ * const userId = result.data; // Already branded by schema
113
+ * }
114
+ * ```
115
+ *
116
+ * @template T - The base type
117
+ * @template B - The brand identifier
118
+ * @param value - The value to brand
119
+ * @returns The same value, but with a brand type
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // Safe usage in tests
124
+ * const mockTenantId = brand<string, 'TenantId'>("test-tenant-123");
125
+ *
126
+ * // Safe usage after validation
127
+ * const schema = z.string().uuid().transform(v => brand<string, 'TenantId'>(v));
128
+ * const tenantId = schema.parse(userInput); // Validated AND branded
129
+ * ```
130
+ */
131
+ export declare function brand<T, B extends string>(value: T): Brand<T, B>;
132
+ /**
133
+ * Type guard to check if a value is already branded with a specific brand.
134
+ *
135
+ * NOTE: This only works if the value was created using the brand() function.
136
+ * It CANNOT detect fake brands created with `as` casts.
137
+ *
138
+ * @template T - The base type
139
+ * @template B - The brand identifier
140
+ * @param value - The value to check
141
+ * @returns true if the value has the correct brand (compile-time only)
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const value: string | TenantId = getTenantId();
146
+ *
147
+ * if (isBranded<string, 'TenantId'>(value)) {
148
+ * const tenantId: TenantId = value; // TypeScript knows it's branded
149
+ * }
150
+ * ```
151
+ */
152
+ export declare function isBranded<T, B extends string>(_value: unknown): _value is Brand<T, B>;
153
+ /**
154
+ * Removes the brand from a branded type, returning the base type.
155
+ *
156
+ * Use this when you need to pass a branded value to a function that
157
+ * expects the base type (e.g., logging, serialization).
158
+ *
159
+ * @template T - The base type
160
+ * @template B - The brand identifier
161
+ * @param value - The branded value
162
+ * @returns The same value, but with the brand removed
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const tenantId: TenantId = getTenantId();
167
+ *
168
+ * // Pass to function expecting plain string
169
+ * console.log(unbrand(tenantId)); // string, not TenantId
170
+ *
171
+ * // Serialize to JSON
172
+ * const json = JSON.stringify({ id: unbrand(tenantId) });
173
+ * ```
174
+ */
175
+ export declare function unbrand<T, B extends string>(value: Brand<T, B>): T;
176
+ /**
177
+ * Utility type to extract the brand identifier from a branded type.
178
+ *
179
+ * @template T - The branded type
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * type TenantId = Brand<string, 'TenantId'>;
184
+ * type BrandName = ExtractBrand<TenantId>; // 'TenantId'
185
+ * ```
186
+ */
187
+ export type ExtractBrand<T> = T extends Brand<unknown, infer B> ? B : never;
188
+ /**
189
+ * Utility type to extract the base type from a branded type.
190
+ *
191
+ * @template T - The branded type
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * type TenantId = Brand<string, 'TenantId'>;
196
+ * type BaseType = ExtractBase<TenantId>; // string
197
+ * ```
198
+ */
199
+ export type ExtractBase<T> = T extends Brand<infer U, string> ? U : T;
200
+ /**
201
+ * Creates a type-safe brand factory with validation.
202
+ *
203
+ * This is the RECOMMENDED way to create brand types with runtime validation.
204
+ *
205
+ * @template T - The base type
206
+ * @template B - The brand identifier
207
+ * @param schema - Zod schema for validation
208
+ * @param brandName - The brand identifier
209
+ * @returns Object with parse, create, and is methods
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * import { z } from 'zod';
214
+ *
215
+ * const TenantId = createBrandFactory(
216
+ * z.string().uuid(),
217
+ * 'TenantId'
218
+ * );
219
+ *
220
+ * // Type-safe parsing with validation
221
+ * const result = TenantId.parse(userInput);
222
+ * if (result.success) {
223
+ * const tenantId = result.data; // Brand<string, 'TenantId'>
224
+ * }
225
+ *
226
+ * // Create new ID
227
+ * const newId = TenantId.create(); // Generates UUID
228
+ *
229
+ * // Type guard
230
+ * if (TenantId.is(value)) {
231
+ * // value is Brand<string, 'TenantId'>
232
+ * }
233
+ * ```
234
+ */
235
+ export declare function createBrandFactory<T, B extends string>(schema: {
236
+ parse: (input: unknown) => T;
237
+ safeParse: (input: unknown) => {
238
+ success: boolean;
239
+ data?: T;
240
+ error?: unknown;
241
+ };
242
+ }, brandName: B): {
243
+ /**
244
+ * The Zod schema with brand transformation.
245
+ */
246
+ schema: {
247
+ parse: (input: unknown) => Brand<T, B>;
248
+ safeParse: (input: unknown) => {
249
+ success: true;
250
+ data: Brand<T, B>;
251
+ } | {
252
+ success: false;
253
+ error: unknown;
254
+ };
255
+ };
256
+ /**
257
+ * Parse and validate input, returning branded value.
258
+ * Throws on validation failure.
259
+ */
260
+ parse: (input: unknown) => Brand<T, B>;
261
+ /**
262
+ * Type guard to check if a value is this brand.
263
+ */
264
+ is: (value: unknown) => value is Brand<T, B>;
265
+ /**
266
+ * Brand name identifier.
267
+ */
268
+ brandName: B;
269
+ };
270
+ /**
271
+ * BEST PRACTICES SUMMARY:
272
+ * =======================
273
+ *
274
+ * 1. ALWAYS validate at boundaries:
275
+ * - API inputs: Use Zod schemas
276
+ * - Database outputs: Use Zod schemas
277
+ * - File I/O: Use Zod schemas
278
+ * - CLI args: Use Zod schemas
279
+ *
280
+ * 2. NEVER cast to brand types:
281
+ * ❌ const id = userInput as TenantId;
282
+ * ✅ const id = TenantIdSchema.parse(userInput);
283
+ *
284
+ * 3. Use createBrandFactory for all brand types:
285
+ * - Provides validation
286
+ * - Provides type guards
287
+ * - Centralizes brand creation
288
+ *
289
+ * 4. Document which functions validate:
290
+ * ```typescript
291
+ * // @validates TenantId - performs Zod validation
292
+ * function parseTenantId(input: string): TenantId {
293
+ * return TenantIdSchema.parse(input);
294
+ * }
295
+ *
296
+ * // @assumes TenantId - no validation, requires validated input
297
+ * function formatTenantId(id: TenantId): string {
298
+ * return `tenant:${unbrand(id)}`;
299
+ * }
300
+ * ```
301
+ *
302
+ * 5. Test brand type enforcement:
303
+ * ```typescript
304
+ * // Should fail to compile
305
+ * const apiKey: ApiKeyId = getTenantId(); // ❌
306
+ * ```
307
+ */
308
+ //# sourceMappingURL=brand-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand-types.d.ts","sourceRoot":"","sources":["../../../src/public/core/brand-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAEhE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC3C,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAIvB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAElE;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EACpD,MAAM,EAAE;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;IAAC,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,EACxH,SAAS,EAAE,CAAC;IAGV;;OAEG;;uBAEc,OAAO,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;2BAIjB,OAAO,KAAG;YAAE,OAAO,EAAE,IAAI,CAAC;YAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SAAE,GAAG;YAAE,OAAO,EAAE,KAAK,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE;;IASxG;;;OAGG;mBACY,OAAO,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAKpC;;OAEG;gBACS,OAAO,KAAG,KAAK,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAK1C;;OAEG;;EAGN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG"}
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Brand Types Utilities for @ax-cli/schemas
3
+ *
4
+ * CRITICAL SECURITY WARNING:
5
+ * =========================
6
+ * Brand types are COMPILE-TIME ONLY markers. They provide ZERO runtime validation.
7
+ *
8
+ * **YOU MUST VALIDATE ALL INPUTS AT SYSTEM BOUNDARIES**
9
+ *
10
+ * Unsafe usage (WILL FAIL IN PRODUCTION):
11
+ * ```typescript
12
+ * const tenantId = userInput as TenantId; // ❌ NO RUNTIME VALIDATION!
13
+ * ```
14
+ *
15
+ * Safe usage (REQUIRED):
16
+ * ```typescript
17
+ * const result = TenantId.parse(userInput); // ✅ Validates with Zod
18
+ * if (result.success) {
19
+ * const tenantId = result.data; // Type-safe AND runtime-safe
20
+ * }
21
+ * ```
22
+ *
23
+ * WHEN TO USE BRAND TYPES:
24
+ * - Preventing ID mixing at compile time (ApiKeyId vs TenantId)
25
+ * - Enforcing domain boundaries in function signatures
26
+ * - Type-level documentation of intent
27
+ *
28
+ * WHEN TO VALIDATE:
29
+ * - API boundaries (HTTP requests, MCP inputs)
30
+ * - File I/O (reading configs, user settings)
31
+ * - Database queries (WHERE clauses with user IDs)
32
+ * - Environment variables
33
+ * - Command-line arguments
34
+ *
35
+ * PERFORMANCE:
36
+ * Brand types have ZERO runtime cost. They are erased during compilation.
37
+ *
38
+ * @module brand-types
39
+ * @see {@link https://github.com/microsoft/TypeScript/issues/4895|TypeScript Nominal Types}
40
+ */
41
+ /**
42
+ * Creates a branded value.
43
+ *
44
+ * WARNING: This function performs NO VALIDATION. It is a type-level assertion only.
45
+ *
46
+ * Use this ONLY in trusted contexts after validation:
47
+ * - Inside schema .transform() after Zod validation
48
+ * - After database queries that return validated data
49
+ * - In test fixtures with known-good values
50
+ *
51
+ * DO NOT use with user input directly:
52
+ * ```typescript
53
+ * // ❌ UNSAFE - No validation!
54
+ * const userId = brand<string, 'UserId'>(req.body.userId);
55
+ *
56
+ * // ✅ SAFE - Validated first
57
+ * const result = UserIdSchema.safeParse(req.body.userId);
58
+ * if (result.success) {
59
+ * const userId = result.data; // Already branded by schema
60
+ * }
61
+ * ```
62
+ *
63
+ * @template T - The base type
64
+ * @template B - The brand identifier
65
+ * @param value - The value to brand
66
+ * @returns The same value, but with a brand type
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Safe usage in tests
71
+ * const mockTenantId = brand<string, 'TenantId'>("test-tenant-123");
72
+ *
73
+ * // Safe usage after validation
74
+ * const schema = z.string().uuid().transform(v => brand<string, 'TenantId'>(v));
75
+ * const tenantId = schema.parse(userInput); // Validated AND branded
76
+ * ```
77
+ */
78
+ export function brand(value) {
79
+ return value;
80
+ }
81
+ /**
82
+ * Type guard to check if a value is already branded with a specific brand.
83
+ *
84
+ * NOTE: This only works if the value was created using the brand() function.
85
+ * It CANNOT detect fake brands created with `as` casts.
86
+ *
87
+ * @template T - The base type
88
+ * @template B - The brand identifier
89
+ * @param value - The value to check
90
+ * @returns true if the value has the correct brand (compile-time only)
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const value: string | TenantId = getTenantId();
95
+ *
96
+ * if (isBranded<string, 'TenantId'>(value)) {
97
+ * const tenantId: TenantId = value; // TypeScript knows it's branded
98
+ * }
99
+ * ```
100
+ */
101
+ export function isBranded(_value) {
102
+ // At runtime, branded types are indistinguishable from their base type
103
+ // This function exists only for type narrowing
104
+ return true;
105
+ }
106
+ /**
107
+ * Removes the brand from a branded type, returning the base type.
108
+ *
109
+ * Use this when you need to pass a branded value to a function that
110
+ * expects the base type (e.g., logging, serialization).
111
+ *
112
+ * @template T - The base type
113
+ * @template B - The brand identifier
114
+ * @param value - The branded value
115
+ * @returns The same value, but with the brand removed
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const tenantId: TenantId = getTenantId();
120
+ *
121
+ * // Pass to function expecting plain string
122
+ * console.log(unbrand(tenantId)); // string, not TenantId
123
+ *
124
+ * // Serialize to JSON
125
+ * const json = JSON.stringify({ id: unbrand(tenantId) });
126
+ * ```
127
+ */
128
+ export function unbrand(value) {
129
+ return value;
130
+ }
131
+ /**
132
+ * Creates a type-safe brand factory with validation.
133
+ *
134
+ * This is the RECOMMENDED way to create brand types with runtime validation.
135
+ *
136
+ * @template T - The base type
137
+ * @template B - The brand identifier
138
+ * @param schema - Zod schema for validation
139
+ * @param brandName - The brand identifier
140
+ * @returns Object with parse, create, and is methods
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * import { z } from 'zod';
145
+ *
146
+ * const TenantId = createBrandFactory(
147
+ * z.string().uuid(),
148
+ * 'TenantId'
149
+ * );
150
+ *
151
+ * // Type-safe parsing with validation
152
+ * const result = TenantId.parse(userInput);
153
+ * if (result.success) {
154
+ * const tenantId = result.data; // Brand<string, 'TenantId'>
155
+ * }
156
+ *
157
+ * // Create new ID
158
+ * const newId = TenantId.create(); // Generates UUID
159
+ *
160
+ * // Type guard
161
+ * if (TenantId.is(value)) {
162
+ * // value is Brand<string, 'TenantId'>
163
+ * }
164
+ * ```
165
+ */
166
+ export function createBrandFactory(schema, brandName) {
167
+ return {
168
+ /**
169
+ * The Zod schema with brand transformation.
170
+ */
171
+ schema: {
172
+ parse: (input) => {
173
+ const validated = schema.parse(input);
174
+ return brand(validated);
175
+ },
176
+ safeParse: (input) => {
177
+ const result = schema.safeParse(input);
178
+ if (result.success) {
179
+ return { success: true, data: brand(result.data) };
180
+ }
181
+ return { success: false, error: result.error };
182
+ },
183
+ },
184
+ /**
185
+ * Parse and validate input, returning branded value.
186
+ * Throws on validation failure.
187
+ */
188
+ parse: (input) => {
189
+ const validated = schema.parse(input);
190
+ return brand(validated);
191
+ },
192
+ /**
193
+ * Type guard to check if a value is this brand.
194
+ */
195
+ is: (value) => {
196
+ const result = schema.safeParse(value);
197
+ return result.success;
198
+ },
199
+ /**
200
+ * Brand name identifier.
201
+ */
202
+ brandName,
203
+ };
204
+ }
205
+ /**
206
+ * BEST PRACTICES SUMMARY:
207
+ * =======================
208
+ *
209
+ * 1. ALWAYS validate at boundaries:
210
+ * - API inputs: Use Zod schemas
211
+ * - Database outputs: Use Zod schemas
212
+ * - File I/O: Use Zod schemas
213
+ * - CLI args: Use Zod schemas
214
+ *
215
+ * 2. NEVER cast to brand types:
216
+ * ❌ const id = userInput as TenantId;
217
+ * ✅ const id = TenantIdSchema.parse(userInput);
218
+ *
219
+ * 3. Use createBrandFactory for all brand types:
220
+ * - Provides validation
221
+ * - Provides type guards
222
+ * - Centralizes brand creation
223
+ *
224
+ * 4. Document which functions validate:
225
+ * ```typescript
226
+ * // @validates TenantId - performs Zod validation
227
+ * function parseTenantId(input: string): TenantId {
228
+ * return TenantIdSchema.parse(input);
229
+ * }
230
+ *
231
+ * // @assumes TenantId - no validation, requires validated input
232
+ * function formatTenantId(id: TenantId): string {
233
+ * return `tenant:${unbrand(id)}`;
234
+ * }
235
+ * ```
236
+ *
237
+ * 5. Test brand type enforcement:
238
+ * ```typescript
239
+ * // Should fail to compile
240
+ * const apiKey: ApiKeyId = getTenantId(); // ❌
241
+ * ```
242
+ */
243
+ //# sourceMappingURL=brand-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brand-types.js","sourceRoot":"","sources":["../../../src/public/core/brand-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAuDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,KAAK,CAAsB,KAAQ;IACjD,OAAO,KAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CACvB,MAAe;IAEf,uEAAuE;IACvE,+CAA+C;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,OAAO,CAAsB,KAAkB;IAC7D,OAAO,KAAU,CAAC;AACpB,CAAC;AA4BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAwH,EACxH,SAAY;IAEZ,OAAO;QACL;;WAEG;QACH,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,KAAc,EAAe,EAAE;gBACrC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACtC,OAAO,KAAK,CAAO,SAAS,CAAC,CAAC;YAChC,CAAC;YACD,SAAS,EAAE,CAAC,KAAc,EAA6E,EAAE;gBACvG,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACvC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACnB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAO,MAAM,CAAC,IAAS,CAAC,EAAE,CAAC;gBAChE,CAAC;gBACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;YACjD,CAAC;SACF;QAED;;;WAGG;QACH,KAAK,EAAE,CAAC,KAAc,EAAe,EAAE;YACrC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACtC,OAAO,KAAK,CAAO,SAAS,CAAC,CAAC;QAChC,CAAC;QAED;;WAEG;QACH,EAAE,EAAE,CAAC,KAAc,EAAwB,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACvC,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;QAED;;WAEG;QACH,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG"}