@snapback/cli 1.6.0 → 3.0.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.
- package/README.md +121 -22
- package/dist/SkippedTestDetector-AXTMWWHC.js +5 -0
- package/dist/SkippedTestDetector-QLSQV7K7.js +5 -0
- package/dist/analysis-6WTBZJH3.js +6 -0
- package/dist/analysis-C472LUGW.js +2475 -0
- package/dist/auth-UA7I3YE4.js +1446 -0
- package/dist/auto-provision-organization-6YF463TK.js +161 -0
- package/dist/{chunk-FVIYXFCL.js → chunk-4YTE4JEW.js} +2 -3
- package/dist/chunk-5EOPYJ4Y.js +12 -0
- package/dist/{chunk-ARVV3F4K.js → chunk-5SQA44V7.js} +1085 -18
- package/dist/{chunk-RB7H4UQJ.js → chunk-7ADPL4Q3.js} +10 -3
- package/dist/chunk-BE3HNVSV.js +2300 -0
- package/dist/chunk-BWWPGNZ5.js +5842 -0
- package/dist/chunk-CBGOC6RV.js +293 -0
- package/dist/{chunk-7JX6Y4TL.js → chunk-DPWFZNMY.js} +21 -34
- package/dist/{chunk-R7CUQ7CU.js → chunk-E6V6QKS7.js} +317 -33
- package/dist/chunk-GT4ZUCFR.js +111 -0
- package/dist/chunk-NOWJBG6X.js +3654 -0
- package/dist/chunk-O7HMAZ7L.js +3497 -0
- package/dist/chunk-PL4HF4M2.js +593 -0
- package/dist/chunk-V7B37PPD.js +4075 -0
- package/dist/chunk-YVZXPBSV.js +314 -0
- package/dist/chunk-ZBQDE6WJ.js +108 -0
- package/dist/client-RHDS6NOB.js +8 -0
- package/dist/dist-5LR7APG5.js +5 -0
- package/dist/dist-CUHOKNLS.js +12 -0
- package/dist/dist-RJE4RSZJ.js +9 -0
- package/dist/index.js +60568 -36578
- package/dist/local-service-adapter-AB3UYRUK.js +6 -0
- package/dist/pioneer-oauth-hook-V2JKEXM7.js +12 -0
- package/dist/{secure-credentials-IWQB6KU4.js → secure-credentials-UEPG7GWW.js} +2 -3
- package/dist/snapback-dir-MG7DTRMF.js +6 -0
- package/package.json +12 -11
- package/scripts/postinstall.mjs +2 -3
- package/dist/SkippedTestDetector-5WJZKZQ3.js +0 -5
- package/dist/SkippedTestDetector-5WJZKZQ3.js.map +0 -1
- package/dist/analysis-YI4UNUCM.js +0 -6
- package/dist/analysis-YI4UNUCM.js.map +0 -1
- package/dist/chunk-7JX6Y4TL.js.map +0 -1
- package/dist/chunk-ARVV3F4K.js.map +0 -1
- package/dist/chunk-EU2IZPOK.js +0 -13002
- package/dist/chunk-EU2IZPOK.js.map +0 -1
- package/dist/chunk-FVIYXFCL.js.map +0 -1
- package/dist/chunk-R7CUQ7CU.js.map +0 -1
- package/dist/chunk-RB7H4UQJ.js.map +0 -1
- package/dist/chunk-SOABQWAU.js +0 -385
- package/dist/chunk-SOABQWAU.js.map +0 -1
- package/dist/dist-O6EBXLN6.js +0 -5
- package/dist/dist-O6EBXLN6.js.map +0 -1
- package/dist/dist-PJVBBZTF.js +0 -5
- package/dist/dist-PJVBBZTF.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/learning-pruner-QC4CTJDX.js +0 -5
- package/dist/learning-pruner-QC4CTJDX.js.map +0 -1
- package/dist/secure-credentials-IWQB6KU4.js.map +0 -1
- package/dist/snapback-dir-V6MWXIW4.js +0 -5
- package/dist/snapback-dir-V6MWXIW4.js.map +0 -1
|
@@ -0,0 +1,3654 @@
|
|
|
1
|
+
#!/usr/bin/env node --no-warnings=ExperimentalWarning
|
|
2
|
+
import { __name } from './chunk-7ADPL4Q3.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import 'neverthrow';
|
|
5
|
+
import 'crypto';
|
|
6
|
+
import 'eventemitter2';
|
|
7
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
8
|
+
import 'ts-pattern';
|
|
9
|
+
|
|
10
|
+
process.env.SNAPBACK_CLI='true';
|
|
11
|
+
|
|
12
|
+
// ../../packages/contracts/dist/logger.js
|
|
13
|
+
var _loggerFactory = null;
|
|
14
|
+
function getLoggerFactory() {
|
|
15
|
+
return _loggerFactory;
|
|
16
|
+
}
|
|
17
|
+
__name(getLoggerFactory, "getLoggerFactory");
|
|
18
|
+
var LogLevel;
|
|
19
|
+
(function(LogLevel2) {
|
|
20
|
+
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
21
|
+
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
22
|
+
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
23
|
+
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
24
|
+
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
25
|
+
})(LogLevel || (LogLevel = {}));
|
|
26
|
+
function createLogger(options) {
|
|
27
|
+
const { name, level = LogLevel.INFO, timestamps = false } = options;
|
|
28
|
+
const formatMessage = /* @__PURE__ */ __name((levelStr, message) => {
|
|
29
|
+
const prefix = timestamps ? `[${(/* @__PURE__ */ new Date()).toISOString()}] ` : "";
|
|
30
|
+
return `${prefix}[${name}] ${levelStr}: ${message}`;
|
|
31
|
+
}, "formatMessage");
|
|
32
|
+
const formatMeta = /* @__PURE__ */ __name((meta) => {
|
|
33
|
+
if (!meta) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
if (meta instanceof Error) {
|
|
37
|
+
return `
|
|
38
|
+
Error: ${meta.message}
|
|
39
|
+
Stack: ${meta.stack}`;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return `
|
|
43
|
+
${JSON.stringify(meta, null, 2)}`;
|
|
44
|
+
} catch {
|
|
45
|
+
return "\n [Circular or non-serializable metadata]";
|
|
46
|
+
}
|
|
47
|
+
}, "formatMeta");
|
|
48
|
+
return {
|
|
49
|
+
debug(messageOrObj, metaOrMsg) {
|
|
50
|
+
if (level <= LogLevel.DEBUG) {
|
|
51
|
+
if (typeof messageOrObj === "string" && (!metaOrMsg || typeof metaOrMsg === "object")) {
|
|
52
|
+
console.debug(formatMessage("DEBUG", messageOrObj) + formatMeta(metaOrMsg));
|
|
53
|
+
} else if (typeof messageOrObj === "object" && typeof metaOrMsg === "string") {
|
|
54
|
+
console.debug(formatMessage("DEBUG", metaOrMsg) + formatMeta(messageOrObj));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
info(messageOrObj, metaOrMsg) {
|
|
59
|
+
if (level <= LogLevel.INFO) {
|
|
60
|
+
if (typeof messageOrObj === "string" && (!metaOrMsg || typeof metaOrMsg === "object")) {
|
|
61
|
+
console.info(formatMessage("INFO", messageOrObj) + formatMeta(metaOrMsg));
|
|
62
|
+
} else if (typeof messageOrObj === "object" && typeof metaOrMsg === "string") {
|
|
63
|
+
console.info(formatMessage("INFO", metaOrMsg) + formatMeta(messageOrObj));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
warn(messageOrObj, metaOrMsg) {
|
|
68
|
+
if (level <= LogLevel.WARN) {
|
|
69
|
+
if (typeof messageOrObj === "string" && (!metaOrMsg || typeof metaOrMsg === "object")) {
|
|
70
|
+
console.warn(formatMessage("WARN", messageOrObj) + formatMeta(metaOrMsg));
|
|
71
|
+
} else if (typeof messageOrObj === "object" && typeof metaOrMsg === "string") {
|
|
72
|
+
console.warn(formatMessage("WARN", metaOrMsg) + formatMeta(messageOrObj));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
error(messageOrObj, metaOrMsg) {
|
|
77
|
+
if (level <= LogLevel.ERROR) {
|
|
78
|
+
if (typeof messageOrObj === "string" && (!metaOrMsg || typeof metaOrMsg !== "string")) {
|
|
79
|
+
console.error(formatMessage("ERROR", messageOrObj) + formatMeta(metaOrMsg));
|
|
80
|
+
} else if (typeof messageOrObj === "object" && typeof metaOrMsg === "string") {
|
|
81
|
+
console.error(formatMessage("ERROR", metaOrMsg) + formatMeta(messageOrObj));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
__name(createLogger, "createLogger");
|
|
88
|
+
|
|
89
|
+
// ../../packages/contracts/dist/observability/InstrumentationProvider.js
|
|
90
|
+
var NoOpInstrumentationProvider = class _NoOpInstrumentationProvider {
|
|
91
|
+
static {
|
|
92
|
+
__name(this, "NoOpInstrumentationProvider");
|
|
93
|
+
}
|
|
94
|
+
static noopSpan = {
|
|
95
|
+
setAttribute: /* @__PURE__ */ __name(() => {
|
|
96
|
+
}, "setAttribute"),
|
|
97
|
+
setAttributes: /* @__PURE__ */ __name(() => {
|
|
98
|
+
}, "setAttributes"),
|
|
99
|
+
addEvent: /* @__PURE__ */ __name(() => {
|
|
100
|
+
}, "addEvent"),
|
|
101
|
+
setStatus: /* @__PURE__ */ __name(() => {
|
|
102
|
+
}, "setStatus"),
|
|
103
|
+
recordException: /* @__PURE__ */ __name(() => {
|
|
104
|
+
}, "recordException"),
|
|
105
|
+
end: /* @__PURE__ */ __name(() => {
|
|
106
|
+
}, "end"),
|
|
107
|
+
isRecording: /* @__PURE__ */ __name(() => false, "isRecording")
|
|
108
|
+
};
|
|
109
|
+
startSpan(_name, _options) {
|
|
110
|
+
return _NoOpInstrumentationProvider.noopSpan;
|
|
111
|
+
}
|
|
112
|
+
async withSpan(_name, fn, _options) {
|
|
113
|
+
return await fn(_NoOpInstrumentationProvider.noopSpan);
|
|
114
|
+
}
|
|
115
|
+
injectContext(_carrier) {
|
|
116
|
+
}
|
|
117
|
+
extractContext(_carrier) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
recordMetric(_name, _value, _attributes) {
|
|
121
|
+
}
|
|
122
|
+
recordEvent(_name, _attributes) {
|
|
123
|
+
}
|
|
124
|
+
async shutdown() {
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// ../../packages/contracts/dist/api/attribution.js
|
|
129
|
+
function shouldMergeAttribution(existing, incoming) {
|
|
130
|
+
if (existing.source === incoming.source && existing.campaignId === incoming.campaignId) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
__name(shouldMergeAttribution, "shouldMergeAttribution");
|
|
136
|
+
var ApiErrorCodeSchema = z.enum([
|
|
137
|
+
// Authentication (401)
|
|
138
|
+
"AUTH_REQUIRED",
|
|
139
|
+
"AUTH_INVALID_TOKEN",
|
|
140
|
+
"AUTH_EXPIRED_TOKEN",
|
|
141
|
+
"AUTH_INVALID_API_KEY",
|
|
142
|
+
"AUTH_REVOKED_KEY",
|
|
143
|
+
// Authorization (403)
|
|
144
|
+
"FORBIDDEN",
|
|
145
|
+
"PERMISSION_DENIED",
|
|
146
|
+
"PLAN_LIMIT_EXCEEDED",
|
|
147
|
+
"FEATURE_NOT_AVAILABLE",
|
|
148
|
+
"TRIAL_EXPIRED",
|
|
149
|
+
// Validation (400)
|
|
150
|
+
"VALIDATION_ERROR",
|
|
151
|
+
"VALIDATION_MISSING_FIELD",
|
|
152
|
+
"VALIDATION_INVALID_FORMAT",
|
|
153
|
+
"VALIDATION_CONSTRAINT_VIOLATION",
|
|
154
|
+
// Resource Errors (404, 409, 410)
|
|
155
|
+
"RESOURCE_NOT_FOUND",
|
|
156
|
+
"RESOURCE_ALREADY_EXISTS",
|
|
157
|
+
"RESOURCE_DELETED",
|
|
158
|
+
"RESOURCE_CONFLICT",
|
|
159
|
+
"RESOURCE_LOCKED",
|
|
160
|
+
// Rate Limiting (429)
|
|
161
|
+
"RATE_LIMIT_EXCEEDED",
|
|
162
|
+
"RATE_LIMIT_API_KEY",
|
|
163
|
+
"RATE_LIMIT_USER",
|
|
164
|
+
"RATE_LIMIT_IP",
|
|
165
|
+
// Payment/Billing (402)
|
|
166
|
+
"PAYMENT_REQUIRED",
|
|
167
|
+
"PAYMENT_FAILED",
|
|
168
|
+
"SUBSCRIPTION_EXPIRED",
|
|
169
|
+
"SUBSCRIPTION_CANCELLED",
|
|
170
|
+
// External Integration Errors (502, 503)
|
|
171
|
+
"INTEGRATION_UNAVAILABLE",
|
|
172
|
+
"INTEGRATION_TIMEOUT",
|
|
173
|
+
"INTEGRATION_ERROR",
|
|
174
|
+
// Security (400, 403)
|
|
175
|
+
"SECURITY_CSRF_INVALID",
|
|
176
|
+
"SECURITY_CAPTCHA_REQUIRED",
|
|
177
|
+
"SECURITY_CAPTCHA_FAILED",
|
|
178
|
+
"SECURITY_PRIVACY_VIOLATION",
|
|
179
|
+
// Server Errors (500, 503)
|
|
180
|
+
"INTERNAL_ERROR",
|
|
181
|
+
"SERVICE_UNAVAILABLE",
|
|
182
|
+
"DATABASE_ERROR",
|
|
183
|
+
"CONFIGURATION_ERROR",
|
|
184
|
+
// Request Errors (400, 413, 415)
|
|
185
|
+
"BAD_REQUEST",
|
|
186
|
+
"PAYLOAD_TOO_LARGE",
|
|
187
|
+
"UNSUPPORTED_MEDIA_TYPE",
|
|
188
|
+
"METHOD_NOT_ALLOWED"
|
|
189
|
+
]);
|
|
190
|
+
var ValidationErrorDetailSchema = z.object({
|
|
191
|
+
field: z.string().describe("The field path that failed validation"),
|
|
192
|
+
message: z.string().describe("Human-readable error message"),
|
|
193
|
+
code: z.string().optional().describe("Zod error code")
|
|
194
|
+
});
|
|
195
|
+
z.object({
|
|
196
|
+
/** Human-readable error message (safe to display to users) */
|
|
197
|
+
error: z.string(),
|
|
198
|
+
/** Machine-readable error code for programmatic handling */
|
|
199
|
+
code: ApiErrorCodeSchema,
|
|
200
|
+
/** Optional detailed error information */
|
|
201
|
+
details: z.union([
|
|
202
|
+
z.array(ValidationErrorDetailSchema),
|
|
203
|
+
z.record(z.string(), z.unknown())
|
|
204
|
+
]).optional(),
|
|
205
|
+
/** Request ID for support correlation (from X-Request-Id header) */
|
|
206
|
+
requestId: z.string().optional(),
|
|
207
|
+
/** Timestamp when error occurred */
|
|
208
|
+
timestamp: z.string().datetime().optional()
|
|
209
|
+
});
|
|
210
|
+
var ApiTierSchema = z.enum([
|
|
211
|
+
"api_free",
|
|
212
|
+
"api_starter",
|
|
213
|
+
"api_pro",
|
|
214
|
+
"api_enterprise"
|
|
215
|
+
]);
|
|
216
|
+
var ApiFeatureSchema = z.enum([
|
|
217
|
+
// Core analysis features
|
|
218
|
+
"risk_scoring",
|
|
219
|
+
"ai_detection",
|
|
220
|
+
"session_grouping",
|
|
221
|
+
"rollback_validation",
|
|
222
|
+
// Advanced features
|
|
223
|
+
"batch_analysis",
|
|
224
|
+
"webhook_notifications",
|
|
225
|
+
"custom_thresholds",
|
|
226
|
+
"priority_queue",
|
|
227
|
+
// Enterprise features
|
|
228
|
+
"dedicated_instance",
|
|
229
|
+
"sla_guarantee",
|
|
230
|
+
"audit_logs",
|
|
231
|
+
"sso_integration"
|
|
232
|
+
]);
|
|
233
|
+
var RateLimitConfigSchema = z.object({
|
|
234
|
+
requestsPerMinute: z.number().int().positive(),
|
|
235
|
+
requestsPerDay: z.number().int().positive(),
|
|
236
|
+
maxBatchSize: z.number().int().positive(),
|
|
237
|
+
maxPayloadBytes: z.number().int().positive()
|
|
238
|
+
});
|
|
239
|
+
z.object({
|
|
240
|
+
tier: ApiTierSchema,
|
|
241
|
+
name: z.string(),
|
|
242
|
+
description: z.string(),
|
|
243
|
+
features: z.array(ApiFeatureSchema),
|
|
244
|
+
rateLimits: RateLimitConfigSchema,
|
|
245
|
+
priceMonthly: z.number().nonnegative(),
|
|
246
|
+
priceYearly: z.number().nonnegative()
|
|
247
|
+
});
|
|
248
|
+
z.object({
|
|
249
|
+
id: z.string().uuid(),
|
|
250
|
+
key: z.string().regex(/^sb_live_[a-zA-Z0-9]{32}$/, "Invalid API key format"),
|
|
251
|
+
tier: ApiTierSchema,
|
|
252
|
+
organizationId: z.string().uuid().optional(),
|
|
253
|
+
name: z.string().max(100).optional(),
|
|
254
|
+
createdAt: z.coerce.date(),
|
|
255
|
+
expiresAt: z.coerce.date().optional(),
|
|
256
|
+
lastUsedAt: z.coerce.date().optional(),
|
|
257
|
+
isActive: z.boolean().default(true)
|
|
258
|
+
});
|
|
259
|
+
z.object({
|
|
260
|
+
keyId: z.string().uuid(),
|
|
261
|
+
endpoint: z.string(),
|
|
262
|
+
requestCount: z.number().int().nonnegative(),
|
|
263
|
+
bytesProcessed: z.number().int().nonnegative(),
|
|
264
|
+
period: z.enum([
|
|
265
|
+
"minute",
|
|
266
|
+
"hour",
|
|
267
|
+
"day",
|
|
268
|
+
"month"
|
|
269
|
+
]),
|
|
270
|
+
timestamp: z.coerce.date()
|
|
271
|
+
});
|
|
272
|
+
z.object({
|
|
273
|
+
name: z.string().max(100).optional(),
|
|
274
|
+
expiresAt: z.coerce.date().optional()
|
|
275
|
+
});
|
|
276
|
+
var AuthErrorCodeSchema = z.enum([
|
|
277
|
+
"INVALID_CREDENTIALS",
|
|
278
|
+
"USER_NOT_FOUND",
|
|
279
|
+
"EMAIL_NOT_VERIFIED",
|
|
280
|
+
"SESSION_EXPIRED",
|
|
281
|
+
"UNAUTHORIZED",
|
|
282
|
+
"RATE_LIMITED",
|
|
283
|
+
"INVALID_TOKEN",
|
|
284
|
+
"USER_ALREADY_EXISTS",
|
|
285
|
+
"WEAK_PASSWORD",
|
|
286
|
+
"INVALID_EMAIL",
|
|
287
|
+
"OAUTH_ERROR",
|
|
288
|
+
"NETWORK_ERROR",
|
|
289
|
+
"UNKNOWN_ERROR"
|
|
290
|
+
]);
|
|
291
|
+
var AuthErrorSchema = z.object({
|
|
292
|
+
code: AuthErrorCodeSchema,
|
|
293
|
+
message: z.string(),
|
|
294
|
+
details: z.record(z.string(), z.unknown()).optional()
|
|
295
|
+
});
|
|
296
|
+
var UserRoleSchema = z.enum([
|
|
297
|
+
"admin",
|
|
298
|
+
"user",
|
|
299
|
+
"viewer"
|
|
300
|
+
]).nullable();
|
|
301
|
+
var AuthUserSchema = z.object({
|
|
302
|
+
id: z.string(),
|
|
303
|
+
email: z.string().email(),
|
|
304
|
+
name: z.string().nullable(),
|
|
305
|
+
image: z.string().url().nullable().optional(),
|
|
306
|
+
emailVerified: z.boolean(),
|
|
307
|
+
createdAt: z.coerce.date(),
|
|
308
|
+
updatedAt: z.coerce.date(),
|
|
309
|
+
// Role field from database - nullable as not all users have a role assigned
|
|
310
|
+
role: UserRoleSchema.optional()
|
|
311
|
+
});
|
|
312
|
+
var SessionSchema = z.object({
|
|
313
|
+
id: z.string(),
|
|
314
|
+
userId: z.string(),
|
|
315
|
+
expiresAt: z.coerce.date(),
|
|
316
|
+
createdAt: z.coerce.date(),
|
|
317
|
+
updatedAt: z.coerce.date(),
|
|
318
|
+
// Better Auth session metadata
|
|
319
|
+
userAgent: z.string().nullable().optional(),
|
|
320
|
+
ipAddress: z.string().nullable().optional()
|
|
321
|
+
});
|
|
322
|
+
var SessionWithUserSchema = z.object({
|
|
323
|
+
session: SessionSchema,
|
|
324
|
+
user: AuthUserSchema
|
|
325
|
+
});
|
|
326
|
+
z.discriminatedUnion("status", [
|
|
327
|
+
z.object({
|
|
328
|
+
status: z.literal("authenticated"),
|
|
329
|
+
user: AuthUserSchema,
|
|
330
|
+
session: SessionSchema
|
|
331
|
+
}),
|
|
332
|
+
z.object({
|
|
333
|
+
status: z.literal("unauthenticated")
|
|
334
|
+
}),
|
|
335
|
+
z.object({
|
|
336
|
+
status: z.literal("loading")
|
|
337
|
+
})
|
|
338
|
+
]);
|
|
339
|
+
|
|
340
|
+
// ../../packages/contracts/dist/auth/api.js
|
|
341
|
+
var PasswordSchema = z.string().min(8, "Password must be at least 8 characters").regex(/[A-Z]/, "Password must contain at least one uppercase letter").regex(/[a-z]/, "Password must contain at least one lowercase letter").regex(/[0-9]/, "Password must contain at least one number");
|
|
342
|
+
var EmailSchema = z.string().email("Invalid email address").toLowerCase().trim();
|
|
343
|
+
z.object({
|
|
344
|
+
email: EmailSchema,
|
|
345
|
+
password: PasswordSchema,
|
|
346
|
+
name: z.string().min(1, "Name is required").max(100, "Name is too long").trim()
|
|
347
|
+
});
|
|
348
|
+
z.discriminatedUnion("success", [
|
|
349
|
+
z.object({
|
|
350
|
+
success: z.literal(true),
|
|
351
|
+
user: AuthUserSchema
|
|
352
|
+
}),
|
|
353
|
+
z.object({
|
|
354
|
+
success: z.literal(false),
|
|
355
|
+
error: AuthErrorSchema
|
|
356
|
+
})
|
|
357
|
+
]);
|
|
358
|
+
z.object({
|
|
359
|
+
email: EmailSchema,
|
|
360
|
+
password: z.string().min(1, "Password is required"),
|
|
361
|
+
rememberMe: z.boolean().optional().default(false)
|
|
362
|
+
});
|
|
363
|
+
z.discriminatedUnion("success", [
|
|
364
|
+
z.object({
|
|
365
|
+
success: z.literal(true),
|
|
366
|
+
user: AuthUserSchema,
|
|
367
|
+
session: z.object({
|
|
368
|
+
id: z.string(),
|
|
369
|
+
expiresAt: z.coerce.date()
|
|
370
|
+
})
|
|
371
|
+
}),
|
|
372
|
+
z.object({
|
|
373
|
+
success: z.literal(false),
|
|
374
|
+
error: AuthErrorSchema
|
|
375
|
+
})
|
|
376
|
+
]);
|
|
377
|
+
z.union([
|
|
378
|
+
SessionWithUserSchema,
|
|
379
|
+
z.null()
|
|
380
|
+
]);
|
|
381
|
+
z.discriminatedUnion("success", [
|
|
382
|
+
z.object({
|
|
383
|
+
success: z.literal(true)
|
|
384
|
+
}),
|
|
385
|
+
z.object({
|
|
386
|
+
success: z.literal(false),
|
|
387
|
+
error: AuthErrorSchema
|
|
388
|
+
})
|
|
389
|
+
]);
|
|
390
|
+
z.object({
|
|
391
|
+
name: z.string().min(1).max(100).trim().optional(),
|
|
392
|
+
image: z.string().url().optional()
|
|
393
|
+
});
|
|
394
|
+
z.discriminatedUnion("success", [
|
|
395
|
+
z.object({
|
|
396
|
+
success: z.literal(true),
|
|
397
|
+
user: AuthUserSchema
|
|
398
|
+
}),
|
|
399
|
+
z.object({
|
|
400
|
+
success: z.literal(false),
|
|
401
|
+
error: AuthErrorSchema
|
|
402
|
+
})
|
|
403
|
+
]);
|
|
404
|
+
z.object({
|
|
405
|
+
currentPassword: z.string().min(1, "Current password is required"),
|
|
406
|
+
newPassword: PasswordSchema
|
|
407
|
+
});
|
|
408
|
+
z.discriminatedUnion("success", [
|
|
409
|
+
z.object({
|
|
410
|
+
success: z.literal(true)
|
|
411
|
+
}),
|
|
412
|
+
z.object({
|
|
413
|
+
success: z.literal(false),
|
|
414
|
+
error: AuthErrorSchema
|
|
415
|
+
})
|
|
416
|
+
]);
|
|
417
|
+
z.object({
|
|
418
|
+
provider: z.enum([
|
|
419
|
+
"github",
|
|
420
|
+
"google"
|
|
421
|
+
]),
|
|
422
|
+
callbackURL: z.string().url().optional()
|
|
423
|
+
});
|
|
424
|
+
z.object({
|
|
425
|
+
version: z.string(),
|
|
426
|
+
riskClasses: z.record(z.enum([
|
|
427
|
+
"safe",
|
|
428
|
+
"low",
|
|
429
|
+
"medium",
|
|
430
|
+
"high",
|
|
431
|
+
"critical"
|
|
432
|
+
]), z.object({
|
|
433
|
+
description: z.string(),
|
|
434
|
+
defaultSandbox: z.enum([
|
|
435
|
+
"none",
|
|
436
|
+
"basic",
|
|
437
|
+
"strict",
|
|
438
|
+
"isolated"
|
|
439
|
+
]),
|
|
440
|
+
requiresAuth: z.boolean(),
|
|
441
|
+
requiresSnapshot: z.boolean(),
|
|
442
|
+
maxConcurrent: z.number().positive(),
|
|
443
|
+
timeoutMs: z.number().positive(),
|
|
444
|
+
requiresApproval: z.boolean().optional()
|
|
445
|
+
})),
|
|
446
|
+
categories: z.record(z.string(), z.object({
|
|
447
|
+
description: z.string(),
|
|
448
|
+
namespace: z.string(),
|
|
449
|
+
defaultRiskClass: z.enum([
|
|
450
|
+
"safe",
|
|
451
|
+
"low",
|
|
452
|
+
"medium",
|
|
453
|
+
"high",
|
|
454
|
+
"critical"
|
|
455
|
+
])
|
|
456
|
+
})),
|
|
457
|
+
tools: z.array(z.object({
|
|
458
|
+
urn: z.string(),
|
|
459
|
+
name: z.string(),
|
|
460
|
+
description: z.string(),
|
|
461
|
+
category: z.string(),
|
|
462
|
+
riskClass: z.enum([
|
|
463
|
+
"safe",
|
|
464
|
+
"low",
|
|
465
|
+
"medium",
|
|
466
|
+
"high",
|
|
467
|
+
"critical"
|
|
468
|
+
]),
|
|
469
|
+
caps: z.array(z.string()),
|
|
470
|
+
requiredPermissions: z.array(z.string()),
|
|
471
|
+
requiredFeatures: z.array(z.string()),
|
|
472
|
+
minTier: z.enum([
|
|
473
|
+
"free",
|
|
474
|
+
"pro",
|
|
475
|
+
"team",
|
|
476
|
+
"enterprise"
|
|
477
|
+
]).optional(),
|
|
478
|
+
inputSchema: z.object({
|
|
479
|
+
type: z.literal("object"),
|
|
480
|
+
properties: z.record(z.string(), z.any()).optional(),
|
|
481
|
+
required: z.array(z.string()).optional()
|
|
482
|
+
})
|
|
483
|
+
})),
|
|
484
|
+
permissions: z.array(z.object({
|
|
485
|
+
id: z.string(),
|
|
486
|
+
description: z.string(),
|
|
487
|
+
scope: z.enum([
|
|
488
|
+
"workspace",
|
|
489
|
+
"channel",
|
|
490
|
+
"admin"
|
|
491
|
+
]),
|
|
492
|
+
requiresTier: z.enum([
|
|
493
|
+
"free",
|
|
494
|
+
"pro",
|
|
495
|
+
"team",
|
|
496
|
+
"enterprise"
|
|
497
|
+
]).optional()
|
|
498
|
+
})),
|
|
499
|
+
sandboxes: z.record(z.enum([
|
|
500
|
+
"none",
|
|
501
|
+
"basic",
|
|
502
|
+
"strict",
|
|
503
|
+
"isolated"
|
|
504
|
+
]), z.object({
|
|
505
|
+
description: z.string(),
|
|
506
|
+
capabilities: z.array(z.string()),
|
|
507
|
+
restrictions: z.array(z.string()),
|
|
508
|
+
implementation: z.enum([
|
|
509
|
+
"container",
|
|
510
|
+
"vm",
|
|
511
|
+
"process"
|
|
512
|
+
]).optional()
|
|
513
|
+
}))
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// ../../packages/contracts/dist/tiers.js
|
|
517
|
+
function isTierBypassEnabled() {
|
|
518
|
+
return process.env.SNAPBACK_BYPASS_TIER_RESTRICTIONS === "true";
|
|
519
|
+
}
|
|
520
|
+
__name(isTierBypassEnabled, "isTierBypassEnabled");
|
|
521
|
+
function getEffectiveTier(actualTier) {
|
|
522
|
+
if (isTierBypassEnabled()) {
|
|
523
|
+
return "pro";
|
|
524
|
+
}
|
|
525
|
+
return actualTier;
|
|
526
|
+
}
|
|
527
|
+
__name(getEffectiveTier, "getEffectiveTier");
|
|
528
|
+
|
|
529
|
+
// ../../packages/contracts/dist/entitlements.js
|
|
530
|
+
var TIER_FEATURES = {
|
|
531
|
+
free: [
|
|
532
|
+
"api_access"
|
|
533
|
+
],
|
|
534
|
+
pro: [
|
|
535
|
+
"cloud_backup",
|
|
536
|
+
"api_access",
|
|
537
|
+
"advanced_analytics",
|
|
538
|
+
"unlimited_workspaces",
|
|
539
|
+
"cli_full_features"
|
|
540
|
+
],
|
|
541
|
+
team: [
|
|
542
|
+
"cloud_backup",
|
|
543
|
+
"api_access",
|
|
544
|
+
"advanced_analytics",
|
|
545
|
+
"unlimited_workspaces",
|
|
546
|
+
"cli_full_features",
|
|
547
|
+
"team_dashboard",
|
|
548
|
+
"multi_workspace",
|
|
549
|
+
"priority_support"
|
|
550
|
+
],
|
|
551
|
+
enterprise: [
|
|
552
|
+
"cloud_backup",
|
|
553
|
+
"api_access",
|
|
554
|
+
"advanced_analytics",
|
|
555
|
+
"unlimited_workspaces",
|
|
556
|
+
"cli_full_features",
|
|
557
|
+
"team_dashboard",
|
|
558
|
+
"multi_workspace",
|
|
559
|
+
"sso_authentication",
|
|
560
|
+
"audit_logs",
|
|
561
|
+
"priority_support",
|
|
562
|
+
"custom_retention"
|
|
563
|
+
]
|
|
564
|
+
};
|
|
565
|
+
var TIER_LIMITS = {
|
|
566
|
+
free: {
|
|
567
|
+
cloud_backup: 0,
|
|
568
|
+
api_access: 100,
|
|
569
|
+
unlimited_workspaces: 1
|
|
570
|
+
},
|
|
571
|
+
pro: {
|
|
572
|
+
cloud_backup: 100 * 1024,
|
|
573
|
+
api_access: 1e5,
|
|
574
|
+
unlimited_workspaces: null
|
|
575
|
+
},
|
|
576
|
+
team: {
|
|
577
|
+
cloud_backup: 500 * 1024,
|
|
578
|
+
api_access: 1e6,
|
|
579
|
+
unlimited_workspaces: null
|
|
580
|
+
},
|
|
581
|
+
enterprise: {
|
|
582
|
+
cloud_backup: null,
|
|
583
|
+
api_access: null,
|
|
584
|
+
unlimited_workspaces: null
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
function getTierFeatures(tier) {
|
|
588
|
+
const effectiveTier = getEffectiveTier(tier);
|
|
589
|
+
return TIER_FEATURES[effectiveTier] || [];
|
|
590
|
+
}
|
|
591
|
+
__name(getTierFeatures, "getTierFeatures");
|
|
592
|
+
function isFeatureAvailableAtTier(feature, tier) {
|
|
593
|
+
const effectiveTier = getEffectiveTier(tier);
|
|
594
|
+
return TIER_FEATURES[effectiveTier]?.includes(feature) || false;
|
|
595
|
+
}
|
|
596
|
+
__name(isFeatureAvailableAtTier, "isFeatureAvailableAtTier");
|
|
597
|
+
function getTierLimit(tier, feature) {
|
|
598
|
+
const effectiveTier = getEffectiveTier(tier);
|
|
599
|
+
return TIER_LIMITS[effectiveTier]?.[feature] ?? null;
|
|
600
|
+
}
|
|
601
|
+
__name(getTierLimit, "getTierLimit");
|
|
602
|
+
|
|
603
|
+
// ../../packages/contracts/dist/errors/base.js
|
|
604
|
+
function extractErrorCode(error) {
|
|
605
|
+
if (error.code) {
|
|
606
|
+
return error.code;
|
|
607
|
+
}
|
|
608
|
+
if (error.name && error.name !== "Error") {
|
|
609
|
+
return error.name.toUpperCase().replace(/ERROR$/, "").replace(/\s+/g, "_");
|
|
610
|
+
}
|
|
611
|
+
return void 0;
|
|
612
|
+
}
|
|
613
|
+
__name(extractErrorCode, "extractErrorCode");
|
|
614
|
+
|
|
615
|
+
// ../../packages/contracts/dist/errors/domain/base.js
|
|
616
|
+
var ErrorCategory;
|
|
617
|
+
(function(ErrorCategory2) {
|
|
618
|
+
ErrorCategory2["NOT_FOUND"] = "NOT_FOUND";
|
|
619
|
+
ErrorCategory2["VALIDATION"] = "VALIDATION";
|
|
620
|
+
ErrorCategory2["PERMISSION"] = "PERMISSION";
|
|
621
|
+
ErrorCategory2["CONFLICT"] = "CONFLICT";
|
|
622
|
+
ErrorCategory2["EXTERNAL"] = "EXTERNAL";
|
|
623
|
+
ErrorCategory2["INTERNAL"] = "INTERNAL";
|
|
624
|
+
})(ErrorCategory || (ErrorCategory = {}));
|
|
625
|
+
var SnapBackEvent;
|
|
626
|
+
(function(SnapBackEvent2) {
|
|
627
|
+
SnapBackEvent2["SNAPSHOT_CREATED"] = "snapshot:created";
|
|
628
|
+
SnapBackEvent2["SNAPSHOT_DELETED"] = "snapshot:deleted";
|
|
629
|
+
SnapBackEvent2["SNAPSHOT_RESTORED"] = "snapshot:restored";
|
|
630
|
+
SnapBackEvent2["RESTORE_STARTED"] = "snapshot:restore_started";
|
|
631
|
+
SnapBackEvent2["PROTECTION_CHANGED"] = "protection:changed";
|
|
632
|
+
SnapBackEvent2["FILE_PROTECTED"] = "file:protected";
|
|
633
|
+
SnapBackEvent2["FILE_UNPROTECTED"] = "file:unprotected";
|
|
634
|
+
SnapBackEvent2["ANALYSIS_REQUESTED"] = "analysis:requested";
|
|
635
|
+
SnapBackEvent2["ANALYSIS_COMPLETED"] = "analysis:completed";
|
|
636
|
+
})(SnapBackEvent || (SnapBackEvent = {}));
|
|
637
|
+
var QoSLevel;
|
|
638
|
+
(function(QoSLevel2) {
|
|
639
|
+
QoSLevel2[QoSLevel2["BEST_EFFORT"] = 0] = "BEST_EFFORT";
|
|
640
|
+
QoSLevel2[QoSLevel2["AT_LEAST_ONCE"] = 1] = "AT_LEAST_ONCE";
|
|
641
|
+
QoSLevel2[QoSLevel2["EXACTLY_ONCE"] = 2] = "EXACTLY_ONCE";
|
|
642
|
+
})(QoSLevel || (QoSLevel = {}));
|
|
643
|
+
process.env.MCP_QUIET === "1" || process.env.MCP_QUIET === "true";
|
|
644
|
+
|
|
645
|
+
// ../../packages/contracts/dist/telemetry/events.js
|
|
646
|
+
var TELEMETRY_EVENTS = {
|
|
647
|
+
EXTENSION_ACTIVATED: "extension.activated",
|
|
648
|
+
EXTENSION_DEACTIVATED: "extension.deactivated",
|
|
649
|
+
COMMAND_EXECUTION: "command.execution",
|
|
650
|
+
SNAPSHOT_CREATED: "snapshot.created",
|
|
651
|
+
SNAPBACK_USED: "snapback.used",
|
|
652
|
+
RISK_DETECTED: "risk.detected",
|
|
653
|
+
VIEW_ACTIVATED: "view.activated",
|
|
654
|
+
NOTIFICATION_SHOWN: "notification.shown",
|
|
655
|
+
FEATURE_USED: "feature.used",
|
|
656
|
+
ERROR: "error",
|
|
657
|
+
WALKTHROUGH_STEP_COMPLETED: "walkthrough.step.completed",
|
|
658
|
+
ONBOARDING_PROTECTION_ASSIGNED: "onboarding.protection.assigned",
|
|
659
|
+
ONBOARDING_PHASE_PROGRESSED: "onboarding.phase.progressed",
|
|
660
|
+
ONBOARDING_CONTEXTUAL_PROMPT_SHOWN: "onboarding.contextualPrompt.shown",
|
|
661
|
+
SIGNATURE_VERIFICATION_SUCCESS: "signature.verification.success",
|
|
662
|
+
SIGNATURE_VERIFICATION_FAILED: "signature.verification.failed",
|
|
663
|
+
RULES_CACHED_FALLBACK: "rules.cached.fallback",
|
|
664
|
+
// Vitals Events
|
|
665
|
+
VITALS_TRAJECTORY_CHANGED: "vitals_trajectory_changed",
|
|
666
|
+
VITALS_CRITICAL_STATE: "vitals_critical_state",
|
|
667
|
+
VITALS_AUTO_SNAPSHOT: "vitals_auto_snapshot",
|
|
668
|
+
VITALS_NUDGE_SHOWN: "vitals_nudge_shown"
|
|
669
|
+
};
|
|
670
|
+
function validateTelemetryEvent(event) {
|
|
671
|
+
switch (event.event) {
|
|
672
|
+
case TELEMETRY_EVENTS.EXTENSION_ACTIVATED:
|
|
673
|
+
return validateExtensionActivatedEvent(event);
|
|
674
|
+
case TELEMETRY_EVENTS.EXTENSION_DEACTIVATED:
|
|
675
|
+
return validateExtensionDeactivatedEvent(event);
|
|
676
|
+
case TELEMETRY_EVENTS.COMMAND_EXECUTION:
|
|
677
|
+
return validateCommandExecutionEvent(event);
|
|
678
|
+
case TELEMETRY_EVENTS.SNAPSHOT_CREATED:
|
|
679
|
+
return validateSnapshotCreatedEvent(event);
|
|
680
|
+
case TELEMETRY_EVENTS.SNAPBACK_USED:
|
|
681
|
+
return validateSnapBackUsedEvent(event);
|
|
682
|
+
case TELEMETRY_EVENTS.RISK_DETECTED:
|
|
683
|
+
return validateRiskDetectedEvent(event);
|
|
684
|
+
case TELEMETRY_EVENTS.VIEW_ACTIVATED:
|
|
685
|
+
return validateViewActivatedEvent(event);
|
|
686
|
+
case TELEMETRY_EVENTS.NOTIFICATION_SHOWN:
|
|
687
|
+
return validateNotificationShownEvent(event);
|
|
688
|
+
case TELEMETRY_EVENTS.FEATURE_USED:
|
|
689
|
+
return validateFeatureUsedEvent(event);
|
|
690
|
+
case TELEMETRY_EVENTS.ERROR:
|
|
691
|
+
return validateErrorEvent(event);
|
|
692
|
+
case TELEMETRY_EVENTS.WALKTHROUGH_STEP_COMPLETED:
|
|
693
|
+
return validateWalkthroughStepCompletedEvent(event);
|
|
694
|
+
case TELEMETRY_EVENTS.ONBOARDING_PROTECTION_ASSIGNED:
|
|
695
|
+
return validateOnboardingProtectionAssignedEvent(event);
|
|
696
|
+
case TELEMETRY_EVENTS.ONBOARDING_PHASE_PROGRESSED:
|
|
697
|
+
return validateOnboardingPhaseProgressedEvent(event);
|
|
698
|
+
case TELEMETRY_EVENTS.ONBOARDING_CONTEXTUAL_PROMPT_SHOWN:
|
|
699
|
+
return validateOnboardingContextualPromptShownEvent(event);
|
|
700
|
+
case TELEMETRY_EVENTS.SIGNATURE_VERIFICATION_SUCCESS:
|
|
701
|
+
return validateSignatureVerificationSuccessEvent(event);
|
|
702
|
+
case TELEMETRY_EVENTS.SIGNATURE_VERIFICATION_FAILED:
|
|
703
|
+
return validateSignatureVerificationFailedEvent(event);
|
|
704
|
+
case TELEMETRY_EVENTS.RULES_CACHED_FALLBACK:
|
|
705
|
+
return validateRulesCachedFallbackEvent(event);
|
|
706
|
+
case TELEMETRY_EVENTS.VITALS_TRAJECTORY_CHANGED:
|
|
707
|
+
return validateVitalsTrajectoryChangedEvent(event);
|
|
708
|
+
case TELEMETRY_EVENTS.VITALS_CRITICAL_STATE:
|
|
709
|
+
return validateVitalsCriticalStateEvent(event);
|
|
710
|
+
case TELEMETRY_EVENTS.VITALS_AUTO_SNAPSHOT:
|
|
711
|
+
return validateVitalsAutoSnapshotEvent(event);
|
|
712
|
+
case TELEMETRY_EVENTS.VITALS_NUDGE_SHOWN:
|
|
713
|
+
return validateVitalsNudgeShownEvent(event);
|
|
714
|
+
default:
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
__name(validateTelemetryEvent, "validateTelemetryEvent");
|
|
719
|
+
function validateExtensionActivatedEvent(event) {
|
|
720
|
+
return typeof event.properties.version === "string" && typeof event.properties.vscodeVersion === "string";
|
|
721
|
+
}
|
|
722
|
+
__name(validateExtensionActivatedEvent, "validateExtensionActivatedEvent");
|
|
723
|
+
function validateExtensionDeactivatedEvent(event) {
|
|
724
|
+
return Object.keys(event.properties).length === 0;
|
|
725
|
+
}
|
|
726
|
+
__name(validateExtensionDeactivatedEvent, "validateExtensionDeactivatedEvent");
|
|
727
|
+
function validateCommandExecutionEvent(event) {
|
|
728
|
+
return typeof event.properties.command === "string" && typeof event.properties.duration === "number" && typeof event.properties.success === "boolean";
|
|
729
|
+
}
|
|
730
|
+
__name(validateCommandExecutionEvent, "validateCommandExecutionEvent");
|
|
731
|
+
function validateSnapshotCreatedEvent(event) {
|
|
732
|
+
return typeof event.properties.method === "string" && typeof event.properties.filesCount === "number";
|
|
733
|
+
}
|
|
734
|
+
__name(validateSnapshotCreatedEvent, "validateSnapshotCreatedEvent");
|
|
735
|
+
function validateSnapBackUsedEvent(event) {
|
|
736
|
+
return typeof event.properties.filesRestored === "number" && typeof event.properties.duration === "number" && typeof event.properties.success === "boolean";
|
|
737
|
+
}
|
|
738
|
+
__name(validateSnapBackUsedEvent, "validateSnapBackUsedEvent");
|
|
739
|
+
function validateRiskDetectedEvent(event) {
|
|
740
|
+
return typeof event.properties.riskLevel === "string" && Array.isArray(event.properties.patterns) && typeof event.properties.confidence === "number";
|
|
741
|
+
}
|
|
742
|
+
__name(validateRiskDetectedEvent, "validateRiskDetectedEvent");
|
|
743
|
+
function validateViewActivatedEvent(event) {
|
|
744
|
+
return typeof event.properties.viewId === "string";
|
|
745
|
+
}
|
|
746
|
+
__name(validateViewActivatedEvent, "validateViewActivatedEvent");
|
|
747
|
+
function validateNotificationShownEvent(event) {
|
|
748
|
+
return typeof event.properties.notificationType === "string" && (event.properties.actionTaken === null || typeof event.properties.actionTaken === "string");
|
|
749
|
+
}
|
|
750
|
+
__name(validateNotificationShownEvent, "validateNotificationShownEvent");
|
|
751
|
+
function validateFeatureUsedEvent(event) {
|
|
752
|
+
return typeof event.properties.feature === "string";
|
|
753
|
+
}
|
|
754
|
+
__name(validateFeatureUsedEvent, "validateFeatureUsedEvent");
|
|
755
|
+
function validateErrorEvent(event) {
|
|
756
|
+
return typeof event.properties.errorType === "string" && typeof event.properties.errorMessage === "string";
|
|
757
|
+
}
|
|
758
|
+
__name(validateErrorEvent, "validateErrorEvent");
|
|
759
|
+
function validateWalkthroughStepCompletedEvent(event) {
|
|
760
|
+
return typeof event.properties.stepId === "string" && typeof event.properties.stepTitle === "string";
|
|
761
|
+
}
|
|
762
|
+
__name(validateWalkthroughStepCompletedEvent, "validateWalkthroughStepCompletedEvent");
|
|
763
|
+
function validateOnboardingProtectionAssignedEvent(event) {
|
|
764
|
+
return typeof event.properties.level === "string" && typeof event.properties.trigger === "string" && typeof event.properties.fileType === "string" && typeof event.properties.isFirstProtection === "boolean";
|
|
765
|
+
}
|
|
766
|
+
__name(validateOnboardingProtectionAssignedEvent, "validateOnboardingProtectionAssignedEvent");
|
|
767
|
+
function validateOnboardingPhaseProgressedEvent(event) {
|
|
768
|
+
return typeof event.properties.phase === "number" && typeof event.properties.trigger === "string" && Array.isArray(event.properties.unlockedFeatures);
|
|
769
|
+
}
|
|
770
|
+
__name(validateOnboardingPhaseProgressedEvent, "validateOnboardingPhaseProgressedEvent");
|
|
771
|
+
function validateOnboardingContextualPromptShownEvent(event) {
|
|
772
|
+
return typeof event.properties.promptType === "string" && (event.properties.actionTaken === null || typeof event.properties.actionTaken === "string");
|
|
773
|
+
}
|
|
774
|
+
__name(validateOnboardingContextualPromptShownEvent, "validateOnboardingContextualPromptShownEvent");
|
|
775
|
+
function validateSignatureVerificationSuccessEvent(event) {
|
|
776
|
+
return Object.keys(event.properties).length === 0;
|
|
777
|
+
}
|
|
778
|
+
__name(validateSignatureVerificationSuccessEvent, "validateSignatureVerificationSuccessEvent");
|
|
779
|
+
function validateSignatureVerificationFailedEvent(event) {
|
|
780
|
+
return Object.keys(event.properties).length === 0;
|
|
781
|
+
}
|
|
782
|
+
__name(validateSignatureVerificationFailedEvent, "validateSignatureVerificationFailedEvent");
|
|
783
|
+
function validateRulesCachedFallbackEvent(event) {
|
|
784
|
+
return Object.keys(event.properties).length === 0;
|
|
785
|
+
}
|
|
786
|
+
__name(validateRulesCachedFallbackEvent, "validateRulesCachedFallbackEvent");
|
|
787
|
+
var VALID_TRAJECTORIES = [
|
|
788
|
+
"stable",
|
|
789
|
+
"escalating",
|
|
790
|
+
"critical",
|
|
791
|
+
"recovering"
|
|
792
|
+
];
|
|
793
|
+
var VALID_TEMP_LEVELS = [
|
|
794
|
+
"cold",
|
|
795
|
+
"warm",
|
|
796
|
+
"hot",
|
|
797
|
+
"burning"
|
|
798
|
+
];
|
|
799
|
+
function validateVitalsTrajectoryChangedEvent(event) {
|
|
800
|
+
return VALID_TRAJECTORIES.includes(event.properties.previousTrajectory) && VALID_TRAJECTORIES.includes(event.properties.newTrajectory) && typeof event.properties.pressure === "number" && typeof event.properties.oxygen === "number" && VALID_TEMP_LEVELS.includes(event.properties.tempLevel);
|
|
801
|
+
}
|
|
802
|
+
__name(validateVitalsTrajectoryChangedEvent, "validateVitalsTrajectoryChangedEvent");
|
|
803
|
+
function validateVitalsCriticalStateEvent(event) {
|
|
804
|
+
return typeof event.properties.pressure === "number" && typeof event.properties.oxygen === "number" && VALID_TEMP_LEVELS.includes(event.properties.tempLevel) && typeof event.properties.unsnapshotedChanges === "number";
|
|
805
|
+
}
|
|
806
|
+
__name(validateVitalsCriticalStateEvent, "validateVitalsCriticalStateEvent");
|
|
807
|
+
function validateVitalsAutoSnapshotEvent(event) {
|
|
808
|
+
return VALID_TRAJECTORIES.includes(event.properties.trajectory) && typeof event.properties.pressure === "number" && typeof event.properties.oxygen === "number" && typeof event.properties.filesCount === "number";
|
|
809
|
+
}
|
|
810
|
+
__name(validateVitalsAutoSnapshotEvent, "validateVitalsAutoSnapshotEvent");
|
|
811
|
+
function validateVitalsNudgeShownEvent(event) {
|
|
812
|
+
return VALID_TRAJECTORIES.includes(event.properties.trajectory) && typeof event.properties.suggestion === "string" && (event.properties.actionTaken === null || typeof event.properties.actionTaken === "string");
|
|
813
|
+
}
|
|
814
|
+
__name(validateVitalsNudgeShownEvent, "validateVitalsNudgeShownEvent");
|
|
815
|
+
var SeveritySchema = z.enum([
|
|
816
|
+
"critical",
|
|
817
|
+
"high",
|
|
818
|
+
"medium",
|
|
819
|
+
"low",
|
|
820
|
+
"info"
|
|
821
|
+
]);
|
|
822
|
+
var RiskSeveritySchema = z.enum([
|
|
823
|
+
"critical",
|
|
824
|
+
"high",
|
|
825
|
+
"medium",
|
|
826
|
+
"low"
|
|
827
|
+
]);
|
|
828
|
+
var ValidationSeveritySchema = z.enum([
|
|
829
|
+
"critical",
|
|
830
|
+
"warning",
|
|
831
|
+
"info"
|
|
832
|
+
]);
|
|
833
|
+
var BaseIssueSchema = z.object({
|
|
834
|
+
/** Severity level */
|
|
835
|
+
severity: z.union([
|
|
836
|
+
SeveritySchema,
|
|
837
|
+
ValidationSeveritySchema
|
|
838
|
+
]),
|
|
839
|
+
/** Issue type code (e.g., UNSAFE_EVAL, PATH_TRAVERSAL) */
|
|
840
|
+
type: z.string(),
|
|
841
|
+
/** Human-readable message */
|
|
842
|
+
message: z.string(),
|
|
843
|
+
/** Line number (1-indexed) */
|
|
844
|
+
line: z.number().optional(),
|
|
845
|
+
/** Suggested fix */
|
|
846
|
+
fix: z.string().optional()
|
|
847
|
+
});
|
|
848
|
+
BaseIssueSchema.extend({
|
|
849
|
+
severity: ValidationSeveritySchema
|
|
850
|
+
});
|
|
851
|
+
BaseIssueSchema.extend({
|
|
852
|
+
/** Unique identifier for deduplication: analyzer/type/file/line */
|
|
853
|
+
id: z.string(),
|
|
854
|
+
/** Severity level */
|
|
855
|
+
severity: SeveritySchema,
|
|
856
|
+
/** File path where issue was found */
|
|
857
|
+
file: z.string().optional(),
|
|
858
|
+
/** Column number (1-indexed) */
|
|
859
|
+
column: z.number().optional(),
|
|
860
|
+
/** Code snippet showing the issue */
|
|
861
|
+
snippet: z.string().optional(),
|
|
862
|
+
/** Rule ID if from a lint tool */
|
|
863
|
+
rule: z.string().optional()
|
|
864
|
+
});
|
|
865
|
+
z.object({
|
|
866
|
+
/** Whether validation passed */
|
|
867
|
+
passed: z.boolean(),
|
|
868
|
+
/** Issues found */
|
|
869
|
+
issues: z.array(BaseIssueSchema),
|
|
870
|
+
/** Duration in milliseconds */
|
|
871
|
+
duration: z.number().optional()
|
|
872
|
+
});
|
|
873
|
+
var CircuitBreakerStateEnumSchema = z.enum([
|
|
874
|
+
"closed",
|
|
875
|
+
"open",
|
|
876
|
+
"half-open"
|
|
877
|
+
]);
|
|
878
|
+
z.object({
|
|
879
|
+
/** Current state */
|
|
880
|
+
state: CircuitBreakerStateEnumSchema,
|
|
881
|
+
/** Failure count */
|
|
882
|
+
failures: z.number(),
|
|
883
|
+
/** Failure threshold */
|
|
884
|
+
threshold: z.number(),
|
|
885
|
+
/** Last failure timestamp */
|
|
886
|
+
lastFailure: z.number().optional(),
|
|
887
|
+
/** Cooldown period in ms */
|
|
888
|
+
cooldownMs: z.number()
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
// ../../packages/contracts/dist/events/core.js
|
|
892
|
+
extendZodWithOpenApi(z);
|
|
893
|
+
var EVENT_VERSION = "1.0.0";
|
|
894
|
+
var BaseEventSchema = z.object({
|
|
895
|
+
event_version: z.string().default(EVENT_VERSION).openapi({
|
|
896
|
+
example: "1.0.0"
|
|
897
|
+
}),
|
|
898
|
+
timestamp: z.number().default(() => Date.now()).openapi({
|
|
899
|
+
example: 162e10
|
|
900
|
+
})
|
|
901
|
+
});
|
|
902
|
+
var SaveAttemptSchema = BaseEventSchema.extend({
|
|
903
|
+
event: z.literal("save_attempt"),
|
|
904
|
+
properties: z.object({
|
|
905
|
+
protection: z.enum([
|
|
906
|
+
"watch",
|
|
907
|
+
"warn",
|
|
908
|
+
"block"
|
|
909
|
+
]).openapi({
|
|
910
|
+
description: "Protection level applied to the file"
|
|
911
|
+
}),
|
|
912
|
+
severity: z.enum([
|
|
913
|
+
"low",
|
|
914
|
+
"medium",
|
|
915
|
+
"high",
|
|
916
|
+
"critical"
|
|
917
|
+
]).openapi({
|
|
918
|
+
description: "Severity of the risk detected"
|
|
919
|
+
}),
|
|
920
|
+
file_kind: z.string().openapi({
|
|
921
|
+
description: "Type of file being protected",
|
|
922
|
+
example: "typescript"
|
|
923
|
+
}),
|
|
924
|
+
reason: z.string().openapi({
|
|
925
|
+
description: "Reason for the save attempt",
|
|
926
|
+
example: "User tried to save a file with a secret"
|
|
927
|
+
}),
|
|
928
|
+
ai_present: z.boolean().openapi({
|
|
929
|
+
description: "Whether AI was involved in the decision"
|
|
930
|
+
}),
|
|
931
|
+
ai_burst: z.boolean().openapi({
|
|
932
|
+
description: "Whether this was part of an AI burst operation"
|
|
933
|
+
}),
|
|
934
|
+
outcome: z.enum([
|
|
935
|
+
"saved",
|
|
936
|
+
"canceled",
|
|
937
|
+
"blocked"
|
|
938
|
+
]).openapi({
|
|
939
|
+
description: "Outcome of the save attempt"
|
|
940
|
+
})
|
|
941
|
+
})
|
|
942
|
+
}).openapi("SaveAttemptEvent");
|
|
943
|
+
var SnapshotCreatedSchema = BaseEventSchema.extend({
|
|
944
|
+
event: z.literal("snapshot_created"),
|
|
945
|
+
properties: z.object({
|
|
946
|
+
session_id: z.string().openapi({
|
|
947
|
+
description: "Unique identifier for the session",
|
|
948
|
+
example: "sess_12345"
|
|
949
|
+
}),
|
|
950
|
+
snapshot_id: z.string().openapi({
|
|
951
|
+
description: "Unique identifier for the snapshot",
|
|
952
|
+
example: "snap_67890"
|
|
953
|
+
}),
|
|
954
|
+
bytes_original: z.number().openapi({
|
|
955
|
+
description: "Original size of the file in bytes",
|
|
956
|
+
example: 1024
|
|
957
|
+
}),
|
|
958
|
+
bytes_stored: z.number().openapi({
|
|
959
|
+
description: "Size of the stored snapshot in bytes",
|
|
960
|
+
example: 512
|
|
961
|
+
}),
|
|
962
|
+
dedup_hit: z.boolean().openapi({
|
|
963
|
+
description: "Whether deduplication was applied"
|
|
964
|
+
}),
|
|
965
|
+
latency_ms: z.number().openapi({
|
|
966
|
+
description: "Time taken to create the snapshot in milliseconds",
|
|
967
|
+
example: 45
|
|
968
|
+
})
|
|
969
|
+
})
|
|
970
|
+
}).openapi("SnapshotCreatedEvent");
|
|
971
|
+
var SessionFinalizedSchema = BaseEventSchema.extend({
|
|
972
|
+
event: z.literal("session_finalized"),
|
|
973
|
+
properties: z.object({
|
|
974
|
+
session_id: z.string().openapi({
|
|
975
|
+
description: "Unique identifier for the session",
|
|
976
|
+
example: "sess_12345"
|
|
977
|
+
}),
|
|
978
|
+
files: z.array(z.string()).openapi({
|
|
979
|
+
description: "List of files in the session",
|
|
980
|
+
example: [
|
|
981
|
+
"src/index.ts",
|
|
982
|
+
"package.json"
|
|
983
|
+
]
|
|
984
|
+
}),
|
|
985
|
+
triggers: z.array(z.string()).openapi({
|
|
986
|
+
description: "List of triggers that activated during the session",
|
|
987
|
+
example: [
|
|
988
|
+
"save_attempt",
|
|
989
|
+
"risk_detected"
|
|
990
|
+
]
|
|
991
|
+
}),
|
|
992
|
+
duration_ms: z.number().openapi({
|
|
993
|
+
description: "Duration of the session in milliseconds",
|
|
994
|
+
example: 12e4
|
|
995
|
+
}),
|
|
996
|
+
ai_present: z.boolean().openapi({
|
|
997
|
+
description: "Whether AI was involved in the session"
|
|
998
|
+
}),
|
|
999
|
+
ai_burst: z.boolean().openapi({
|
|
1000
|
+
description: "Whether this was part of an AI burst operation"
|
|
1001
|
+
}),
|
|
1002
|
+
highest_severity: z.enum([
|
|
1003
|
+
"info",
|
|
1004
|
+
"low",
|
|
1005
|
+
"medium",
|
|
1006
|
+
"high",
|
|
1007
|
+
"critical"
|
|
1008
|
+
]).openapi({
|
|
1009
|
+
description: "Highest severity of issues in the session"
|
|
1010
|
+
}),
|
|
1011
|
+
// AI detection v1 fields
|
|
1012
|
+
ai_assist_level: z.enum([
|
|
1013
|
+
"none",
|
|
1014
|
+
"light",
|
|
1015
|
+
"medium",
|
|
1016
|
+
"heavy",
|
|
1017
|
+
"unknown"
|
|
1018
|
+
]).optional().openapi({
|
|
1019
|
+
description: "AI assistance level inferred from change patterns",
|
|
1020
|
+
example: "medium"
|
|
1021
|
+
}),
|
|
1022
|
+
ai_confidence_score: z.number().min(0).max(10).optional().openapi({
|
|
1023
|
+
description: "Confidence score for AI detection (0-10)",
|
|
1024
|
+
example: 7.5
|
|
1025
|
+
}),
|
|
1026
|
+
ai_provider: z.enum([
|
|
1027
|
+
"cursor",
|
|
1028
|
+
"claude",
|
|
1029
|
+
"unknown",
|
|
1030
|
+
"none"
|
|
1031
|
+
]).optional().openapi({
|
|
1032
|
+
description: "Detected AI tool/provider",
|
|
1033
|
+
example: "cursor"
|
|
1034
|
+
}),
|
|
1035
|
+
ai_large_insert_count: z.number().int().min(0).optional().openapi({
|
|
1036
|
+
description: "Count of large insertions detected",
|
|
1037
|
+
example: 5
|
|
1038
|
+
}),
|
|
1039
|
+
ai_total_chars: z.number().int().min(0).optional().openapi({
|
|
1040
|
+
description: "Total characters in large insertions",
|
|
1041
|
+
example: 2e3
|
|
1042
|
+
}),
|
|
1043
|
+
context: z.record(z.string(), z.any()).optional().openapi({
|
|
1044
|
+
description: "Additional context for the session"
|
|
1045
|
+
})
|
|
1046
|
+
})
|
|
1047
|
+
}).openapi("SessionFinalizedEvent");
|
|
1048
|
+
var IssueCreatedSchema = BaseEventSchema.extend({
|
|
1049
|
+
event: z.literal("issue_created"),
|
|
1050
|
+
properties: z.object({
|
|
1051
|
+
issue_id: z.string().openapi({
|
|
1052
|
+
description: "Unique identifier for the issue",
|
|
1053
|
+
example: "issue_12345"
|
|
1054
|
+
}),
|
|
1055
|
+
session_id: z.string().openapi({
|
|
1056
|
+
description: "Unique identifier for the session",
|
|
1057
|
+
example: "sess_12345"
|
|
1058
|
+
}),
|
|
1059
|
+
file_kind: z.string().openapi({
|
|
1060
|
+
description: "Type of file where the issue was detected",
|
|
1061
|
+
example: "typescript"
|
|
1062
|
+
}),
|
|
1063
|
+
type: z.enum([
|
|
1064
|
+
"secret",
|
|
1065
|
+
"mock",
|
|
1066
|
+
"phantom"
|
|
1067
|
+
]).openapi({
|
|
1068
|
+
description: "Type of issue detected"
|
|
1069
|
+
}),
|
|
1070
|
+
severity: RiskSeveritySchema.openapi({
|
|
1071
|
+
description: "Severity of the issue"
|
|
1072
|
+
}),
|
|
1073
|
+
recommendation: z.string().openapi({
|
|
1074
|
+
description: "Recommendation for resolving the issue",
|
|
1075
|
+
example: "Remove the secret from the file"
|
|
1076
|
+
}),
|
|
1077
|
+
context: z.record(z.string(), z.any()).optional().openapi({
|
|
1078
|
+
description: "Additional context for the issue"
|
|
1079
|
+
})
|
|
1080
|
+
})
|
|
1081
|
+
}).openapi("IssueCreatedEvent");
|
|
1082
|
+
var IssueResolvedSchema = BaseEventSchema.extend({
|
|
1083
|
+
event: z.literal("issue_resolved"),
|
|
1084
|
+
properties: z.object({
|
|
1085
|
+
issue_id: z.string().openapi({
|
|
1086
|
+
description: "Unique identifier for the issue",
|
|
1087
|
+
example: "issue_12345"
|
|
1088
|
+
}),
|
|
1089
|
+
resolution: z.enum([
|
|
1090
|
+
"fixed",
|
|
1091
|
+
"ignored",
|
|
1092
|
+
"allowlisted"
|
|
1093
|
+
]).openapi({
|
|
1094
|
+
description: "How the issue was resolved"
|
|
1095
|
+
})
|
|
1096
|
+
})
|
|
1097
|
+
}).openapi("IssueResolvedEvent");
|
|
1098
|
+
var SessionRestoredSchema = BaseEventSchema.extend({
|
|
1099
|
+
event: z.literal("session_restored"),
|
|
1100
|
+
properties: z.object({
|
|
1101
|
+
session_id: z.string().openapi({
|
|
1102
|
+
description: "Unique identifier for the session",
|
|
1103
|
+
example: "sess_12345"
|
|
1104
|
+
}),
|
|
1105
|
+
files_restored: z.array(z.string()).openapi({
|
|
1106
|
+
description: "List of files that were restored",
|
|
1107
|
+
example: [
|
|
1108
|
+
"src/index.ts",
|
|
1109
|
+
"package.json"
|
|
1110
|
+
]
|
|
1111
|
+
}),
|
|
1112
|
+
time_to_restore_ms: z.number().openapi({
|
|
1113
|
+
description: "Time taken to restore the session in milliseconds",
|
|
1114
|
+
example: 2500
|
|
1115
|
+
}),
|
|
1116
|
+
reason: z.string().openapi({
|
|
1117
|
+
description: "Reason for the session restoration",
|
|
1118
|
+
example: "User requested rollback"
|
|
1119
|
+
})
|
|
1120
|
+
})
|
|
1121
|
+
}).openapi("SessionRestoredEvent");
|
|
1122
|
+
var PolicyChangedSchema = BaseEventSchema.extend({
|
|
1123
|
+
event: z.literal("policy_changed"),
|
|
1124
|
+
properties: z.object({
|
|
1125
|
+
pattern: z.string().openapi({
|
|
1126
|
+
description: "File pattern that the policy applies to",
|
|
1127
|
+
example: "*.env"
|
|
1128
|
+
}),
|
|
1129
|
+
from: z.enum([
|
|
1130
|
+
"watch",
|
|
1131
|
+
"warn",
|
|
1132
|
+
"block",
|
|
1133
|
+
"unprotected",
|
|
1134
|
+
"unauthenticated",
|
|
1135
|
+
"unaware"
|
|
1136
|
+
]).openapi({
|
|
1137
|
+
description: "Previous protection level"
|
|
1138
|
+
}),
|
|
1139
|
+
to: z.enum([
|
|
1140
|
+
"watch",
|
|
1141
|
+
"warn",
|
|
1142
|
+
"block",
|
|
1143
|
+
"unprotected",
|
|
1144
|
+
"authenticated",
|
|
1145
|
+
"aware"
|
|
1146
|
+
]).openapi({
|
|
1147
|
+
description: "New protection level"
|
|
1148
|
+
}),
|
|
1149
|
+
source: z.string().openapi({
|
|
1150
|
+
description: "Source of the policy change",
|
|
1151
|
+
example: "cli"
|
|
1152
|
+
}),
|
|
1153
|
+
context: z.record(z.string(), z.any()).optional().openapi({
|
|
1154
|
+
description: "Additional context for the policy change"
|
|
1155
|
+
})
|
|
1156
|
+
})
|
|
1157
|
+
}).openapi("PolicyChangedEvent");
|
|
1158
|
+
var AuthProviderSelectedSchema = BaseEventSchema.extend({
|
|
1159
|
+
event: z.literal("auth.provider.selected"),
|
|
1160
|
+
properties: z.object({
|
|
1161
|
+
provider: z.enum([
|
|
1162
|
+
"oauth",
|
|
1163
|
+
"device_flow"
|
|
1164
|
+
]).openapi({
|
|
1165
|
+
description: "Authentication provider selected"
|
|
1166
|
+
}),
|
|
1167
|
+
trigger: z.enum([
|
|
1168
|
+
"user_selected",
|
|
1169
|
+
"fallback",
|
|
1170
|
+
"auto"
|
|
1171
|
+
]).openapi({
|
|
1172
|
+
description: "How the provider was selected"
|
|
1173
|
+
})
|
|
1174
|
+
})
|
|
1175
|
+
}).openapi("AuthProviderSelectedEvent");
|
|
1176
|
+
var AuthBrowserOpenedSchema = BaseEventSchema.extend({
|
|
1177
|
+
event: z.literal("auth.browser.opened"),
|
|
1178
|
+
properties: z.object({
|
|
1179
|
+
method: z.enum([
|
|
1180
|
+
"external_command",
|
|
1181
|
+
"clipboard",
|
|
1182
|
+
"error"
|
|
1183
|
+
]).openapi({
|
|
1184
|
+
description: "Method used to open browser"
|
|
1185
|
+
}),
|
|
1186
|
+
success: z.boolean().openapi({
|
|
1187
|
+
description: "Whether browser was successfully opened"
|
|
1188
|
+
}),
|
|
1189
|
+
error: z.string().optional().openapi({
|
|
1190
|
+
description: "Error message if browser opening failed"
|
|
1191
|
+
})
|
|
1192
|
+
})
|
|
1193
|
+
}).openapi("AuthBrowserOpenedEvent");
|
|
1194
|
+
var AuthCodeEntrySchema = BaseEventSchema.extend({
|
|
1195
|
+
event: z.literal("auth.code.entry"),
|
|
1196
|
+
properties: z.object({
|
|
1197
|
+
code_format: z.enum([
|
|
1198
|
+
"valid",
|
|
1199
|
+
"invalid_chars",
|
|
1200
|
+
"wrong_length"
|
|
1201
|
+
]).openapi({
|
|
1202
|
+
description: "Validity of the entered code format"
|
|
1203
|
+
}),
|
|
1204
|
+
time_to_enter_ms: z.number().openapi({
|
|
1205
|
+
description: "Time taken to enter the code in milliseconds"
|
|
1206
|
+
}),
|
|
1207
|
+
attempts: z.number().int().min(1).openapi({
|
|
1208
|
+
description: "Number of attempts to enter the code correctly"
|
|
1209
|
+
}),
|
|
1210
|
+
code_length: z.number().int().optional().openapi({
|
|
1211
|
+
description: "Length of the entered code"
|
|
1212
|
+
})
|
|
1213
|
+
})
|
|
1214
|
+
}).openapi("AuthCodeEntryEvent");
|
|
1215
|
+
var AuthApprovalReceivedSchema = BaseEventSchema.extend({
|
|
1216
|
+
event: z.literal("auth.approval.received"),
|
|
1217
|
+
properties: z.object({
|
|
1218
|
+
polling_attempts: z.number().int().min(1).openapi({
|
|
1219
|
+
description: "Number of polling attempts before approval"
|
|
1220
|
+
}),
|
|
1221
|
+
total_wait_ms: z.number().openapi({
|
|
1222
|
+
description: "Total time waited for approval in milliseconds"
|
|
1223
|
+
}),
|
|
1224
|
+
device_code_expired: z.boolean().openapi({
|
|
1225
|
+
description: "Whether the device code had expired"
|
|
1226
|
+
})
|
|
1227
|
+
})
|
|
1228
|
+
}).openapi("AuthApprovalReceivedEvent");
|
|
1229
|
+
var WelcomeFeatureViewedSchema = BaseEventSchema.extend({
|
|
1230
|
+
event: z.literal("welcome.feature.viewed"),
|
|
1231
|
+
properties: z.object({
|
|
1232
|
+
feature: z.string().openapi({
|
|
1233
|
+
description: "Feature name shown in welcome panel",
|
|
1234
|
+
example: "ai_detection"
|
|
1235
|
+
}),
|
|
1236
|
+
position: z.number().int().min(0).openapi({
|
|
1237
|
+
description: "Position in feature carousel",
|
|
1238
|
+
example: 0
|
|
1239
|
+
}),
|
|
1240
|
+
trigger: z.enum([
|
|
1241
|
+
"onboarding",
|
|
1242
|
+
"nudge",
|
|
1243
|
+
"manual"
|
|
1244
|
+
]).openapi({
|
|
1245
|
+
description: "How the welcome panel was triggered"
|
|
1246
|
+
})
|
|
1247
|
+
})
|
|
1248
|
+
}).openapi("WelcomeFeatureViewedEvent");
|
|
1249
|
+
var WelcomeActionTriggeredSchema = BaseEventSchema.extend({
|
|
1250
|
+
event: z.literal("welcome.action.triggered"),
|
|
1251
|
+
properties: z.object({
|
|
1252
|
+
action: z.string().openapi({
|
|
1253
|
+
description: "Action triggered by user",
|
|
1254
|
+
example: "try_now"
|
|
1255
|
+
}),
|
|
1256
|
+
feature: z.string().openapi({
|
|
1257
|
+
description: "Feature associated with the action",
|
|
1258
|
+
example: "ai_detection"
|
|
1259
|
+
}),
|
|
1260
|
+
time_viewed_ms: z.number().openapi({
|
|
1261
|
+
description: "How long the feature was viewed before action",
|
|
1262
|
+
example: 2500
|
|
1263
|
+
})
|
|
1264
|
+
})
|
|
1265
|
+
}).openapi("WelcomeActionTriggeredEvent");
|
|
1266
|
+
z.discriminatedUnion("event", [
|
|
1267
|
+
SaveAttemptSchema,
|
|
1268
|
+
SnapshotCreatedSchema,
|
|
1269
|
+
SessionFinalizedSchema,
|
|
1270
|
+
IssueCreatedSchema,
|
|
1271
|
+
IssueResolvedSchema,
|
|
1272
|
+
SessionRestoredSchema,
|
|
1273
|
+
PolicyChangedSchema,
|
|
1274
|
+
AuthProviderSelectedSchema,
|
|
1275
|
+
AuthBrowserOpenedSchema,
|
|
1276
|
+
AuthCodeEntrySchema,
|
|
1277
|
+
AuthApprovalReceivedSchema,
|
|
1278
|
+
WelcomeFeatureViewedSchema,
|
|
1279
|
+
WelcomeActionTriggeredSchema
|
|
1280
|
+
]);
|
|
1281
|
+
|
|
1282
|
+
// ../../packages/contracts/dist/events/accountability.js
|
|
1283
|
+
extendZodWithOpenApi(z);
|
|
1284
|
+
var PerceivedHelpSchema = z.enum([
|
|
1285
|
+
"significantly",
|
|
1286
|
+
"somewhat",
|
|
1287
|
+
"not_really",
|
|
1288
|
+
"blocked"
|
|
1289
|
+
]).openapi({
|
|
1290
|
+
description: "User's perception of how much SnapBack helped"
|
|
1291
|
+
});
|
|
1292
|
+
var ActualChangesSchema = z.object({
|
|
1293
|
+
files_modified: z.number().int().min(0).openapi({
|
|
1294
|
+
description: "Number of files modified during session",
|
|
1295
|
+
example: 5
|
|
1296
|
+
}),
|
|
1297
|
+
lines_added: z.number().int().min(0).openapi({
|
|
1298
|
+
description: "Total lines added",
|
|
1299
|
+
example: 150
|
|
1300
|
+
}),
|
|
1301
|
+
lines_removed: z.number().int().min(0).openapi({
|
|
1302
|
+
description: "Total lines removed",
|
|
1303
|
+
example: 30
|
|
1304
|
+
}),
|
|
1305
|
+
snapshots_used: z.number().int().min(0).openapi({
|
|
1306
|
+
description: "Number of snapshots created or restored",
|
|
1307
|
+
example: 2
|
|
1308
|
+
})
|
|
1309
|
+
}).openapi("ActualChanges");
|
|
1310
|
+
var PreventedIssuesSchema = z.object({
|
|
1311
|
+
rollbacks_avoided: z.number().int().min(0).openapi({
|
|
1312
|
+
description: "Rollbacks avoided due to snapshots",
|
|
1313
|
+
example: 1
|
|
1314
|
+
}),
|
|
1315
|
+
pattern_violations_caught: z.number().int().min(0).openapi({
|
|
1316
|
+
description: "Pattern violations caught before commit",
|
|
1317
|
+
example: 3
|
|
1318
|
+
}),
|
|
1319
|
+
skipped_tests_flagged: z.number().int().min(0).openapi({
|
|
1320
|
+
description: "Skipped tests flagged for attention",
|
|
1321
|
+
example: 2
|
|
1322
|
+
})
|
|
1323
|
+
}).openapi("PreventedIssues");
|
|
1324
|
+
var TierSchema = z.enum([
|
|
1325
|
+
"free",
|
|
1326
|
+
"pro",
|
|
1327
|
+
"team",
|
|
1328
|
+
"enterprise"
|
|
1329
|
+
]).openapi({
|
|
1330
|
+
description: "User's subscription tier"
|
|
1331
|
+
});
|
|
1332
|
+
BaseEventSchema.extend({
|
|
1333
|
+
event: z.literal("session:feedback_submitted"),
|
|
1334
|
+
properties: z.object({
|
|
1335
|
+
// Session identification
|
|
1336
|
+
session_id: z.string().openapi({
|
|
1337
|
+
description: "Unique session identifier",
|
|
1338
|
+
example: "sess_12345"
|
|
1339
|
+
}),
|
|
1340
|
+
session_duration_ms: z.number().int().min(0).openapi({
|
|
1341
|
+
description: "Session duration in milliseconds",
|
|
1342
|
+
example: 36e5
|
|
1343
|
+
}),
|
|
1344
|
+
// User perception
|
|
1345
|
+
perceived_help: PerceivedHelpSchema,
|
|
1346
|
+
// Reality metrics (counts only, no PII)
|
|
1347
|
+
actual_changes: ActualChangesSchema,
|
|
1348
|
+
prevented_issues: PreventedIssuesSchema,
|
|
1349
|
+
// Tier for consent checking
|
|
1350
|
+
tier: TierSchema
|
|
1351
|
+
})
|
|
1352
|
+
}).openapi("AccountabilityEffectEvent");
|
|
1353
|
+
|
|
1354
|
+
// ../../packages/contracts/dist/features.js
|
|
1355
|
+
var FEATURE_FLAGS = {
|
|
1356
|
+
// Core protection features
|
|
1357
|
+
"protection.enabled": true,
|
|
1358
|
+
"protection.auto_checkpoint": true,
|
|
1359
|
+
"protection.pre_save_hook": true,
|
|
1360
|
+
// Risk analysis
|
|
1361
|
+
"risk.guardian_v2": false,
|
|
1362
|
+
"risk.dependency_analysis": true,
|
|
1363
|
+
"risk.deep_analysis": false,
|
|
1364
|
+
"risk.ai_detection": true,
|
|
1365
|
+
// Storage
|
|
1366
|
+
"storage.compression": true,
|
|
1367
|
+
"storage.deduplication": false,
|
|
1368
|
+
"storage.encryption": false,
|
|
1369
|
+
// UI/UX
|
|
1370
|
+
"ui.chat_participant": true,
|
|
1371
|
+
"ui.status_bar": true,
|
|
1372
|
+
"ui.timeline_view": true,
|
|
1373
|
+
// Telemetry
|
|
1374
|
+
"telemetry.detailed_events": false,
|
|
1375
|
+
"telemetry.performance_metrics": true,
|
|
1376
|
+
"telemetry.sampling_rate": 1,
|
|
1377
|
+
// Experimental
|
|
1378
|
+
"experimental.mcp_tools": false,
|
|
1379
|
+
"experimental.recovery_mode": false,
|
|
1380
|
+
// Intelligence Layer (WU-4.1b)
|
|
1381
|
+
"intelligence.layer": false,
|
|
1382
|
+
"intelligence.trust_calibration": false,
|
|
1383
|
+
"intelligence.pattern_library": false,
|
|
1384
|
+
// A/B Testing - DeepScan
|
|
1385
|
+
"deepscan.v2_algorithm": false,
|
|
1386
|
+
"deepscan.enhanced_analysis": false,
|
|
1387
|
+
"deepscan.real_time_processing": false,
|
|
1388
|
+
// Event System Migration
|
|
1389
|
+
"events.eventemitter2": false
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
// ../../packages/contracts/dist/feature-manager.js
|
|
1393
|
+
var logger = createLogger({
|
|
1394
|
+
name: "feature-manager",
|
|
1395
|
+
level: LogLevel.INFO
|
|
1396
|
+
});
|
|
1397
|
+
var FeatureManager = class _FeatureManager {
|
|
1398
|
+
static {
|
|
1399
|
+
__name(this, "FeatureManager");
|
|
1400
|
+
}
|
|
1401
|
+
static instance;
|
|
1402
|
+
flags = /* @__PURE__ */ new Map();
|
|
1403
|
+
posthogClient = null;
|
|
1404
|
+
constructor() {
|
|
1405
|
+
for (const [key, value] of Object.entries(FEATURE_FLAGS)) {
|
|
1406
|
+
this.flags.set(key, value);
|
|
1407
|
+
}
|
|
1408
|
+
this.loadEnvironmentOverrides();
|
|
1409
|
+
}
|
|
1410
|
+
static getInstance() {
|
|
1411
|
+
if (!_FeatureManager.instance) {
|
|
1412
|
+
_FeatureManager.instance = new _FeatureManager();
|
|
1413
|
+
}
|
|
1414
|
+
return _FeatureManager.instance;
|
|
1415
|
+
}
|
|
1416
|
+
isEnabled(flag) {
|
|
1417
|
+
const value = this.flags.get(flag) ?? FEATURE_FLAGS[flag];
|
|
1418
|
+
if (flag === "telemetry.sampling_rate" && typeof value === "number") {
|
|
1419
|
+
return Math.random() < value;
|
|
1420
|
+
}
|
|
1421
|
+
return Boolean(value);
|
|
1422
|
+
}
|
|
1423
|
+
getValue(flag) {
|
|
1424
|
+
return this.flags.get(flag);
|
|
1425
|
+
}
|
|
1426
|
+
setFlag(flag, value) {
|
|
1427
|
+
this.flags.set(flag, value);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Set PostHog client for dynamic feature flag evaluation
|
|
1431
|
+
*/
|
|
1432
|
+
setPostHogClient(client) {
|
|
1433
|
+
this.posthogClient = client;
|
|
1434
|
+
if (client) {
|
|
1435
|
+
logger.info("PostHog client configured");
|
|
1436
|
+
} else {
|
|
1437
|
+
logger.info("PostHog client cleared, falling back to static config");
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Asynchronously check if feature is enabled (with PostHog fallback)
|
|
1442
|
+
* @param flag - Feature flag name
|
|
1443
|
+
* @param userId - User ID for targeting rules (optional)
|
|
1444
|
+
* @param context - Additional context for PostHog targeting (optional)
|
|
1445
|
+
* @returns Promise<boolean> - True if feature is enabled
|
|
1446
|
+
*/
|
|
1447
|
+
async isEnabledAsync(flag, userId, context) {
|
|
1448
|
+
if (this.posthogClient && userId) {
|
|
1449
|
+
try {
|
|
1450
|
+
const defaultSubscriptionTier = process.env.SNAPBACK_DEFAULT_SUBSCRIPTION_TIER || "free";
|
|
1451
|
+
const posthogContext = {
|
|
1452
|
+
subscriptionTier: defaultSubscriptionTier,
|
|
1453
|
+
...context
|
|
1454
|
+
};
|
|
1455
|
+
const result = await this.posthogClient.isFeatureEnabled(flag, userId, posthogContext);
|
|
1456
|
+
if (result !== null && result !== void 0) {
|
|
1457
|
+
logger.info("Feature flag evaluated via PostHog", {
|
|
1458
|
+
flag,
|
|
1459
|
+
userId,
|
|
1460
|
+
enabled: result
|
|
1461
|
+
});
|
|
1462
|
+
return result;
|
|
1463
|
+
}
|
|
1464
|
+
} catch (error) {
|
|
1465
|
+
logger.warn("PostHog feature flag check failed, falling back to static config", {
|
|
1466
|
+
flag,
|
|
1467
|
+
userId,
|
|
1468
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return this.isEnabled(flag);
|
|
1473
|
+
}
|
|
1474
|
+
loadEnvironmentOverrides() {
|
|
1475
|
+
for (const flag of Object.keys(FEATURE_FLAGS)) {
|
|
1476
|
+
const envVar = `SNAPBACK_${flag.replace(/\./g, "_").toUpperCase()}`;
|
|
1477
|
+
const envValue = process.env[envVar];
|
|
1478
|
+
if (envValue !== void 0) {
|
|
1479
|
+
if (envValue === "true" || envValue === "false") {
|
|
1480
|
+
this.flags.set(flag, envValue === "true");
|
|
1481
|
+
} else if (!Number.isNaN(Number(envValue))) {
|
|
1482
|
+
this.flags.set(flag, Number(envValue));
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
reset() {
|
|
1488
|
+
this.flags.clear();
|
|
1489
|
+
this.posthogClient = null;
|
|
1490
|
+
for (const [key, value] of Object.entries(FEATURE_FLAGS)) {
|
|
1491
|
+
this.flags.set(key, value);
|
|
1492
|
+
}
|
|
1493
|
+
this.loadEnvironmentOverrides();
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
// ../../packages/contracts/dist/observability/types.js
|
|
1498
|
+
var SpanStatusCode;
|
|
1499
|
+
(function(SpanStatusCode2) {
|
|
1500
|
+
SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
|
|
1501
|
+
SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
|
|
1502
|
+
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
1503
|
+
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
1504
|
+
var SpanKind;
|
|
1505
|
+
(function(SpanKind2) {
|
|
1506
|
+
SpanKind2[SpanKind2["INTERNAL"] = 0] = "INTERNAL";
|
|
1507
|
+
SpanKind2[SpanKind2["SERVER"] = 1] = "SERVER";
|
|
1508
|
+
SpanKind2[SpanKind2["CLIENT"] = 2] = "CLIENT";
|
|
1509
|
+
SpanKind2[SpanKind2["PRODUCER"] = 3] = "PRODUCER";
|
|
1510
|
+
SpanKind2[SpanKind2["CONSUMER"] = 4] = "CONSUMER";
|
|
1511
|
+
})(SpanKind || (SpanKind = {}));
|
|
1512
|
+
z.object({
|
|
1513
|
+
id: z.string().min(1),
|
|
1514
|
+
source: z.string().min(1),
|
|
1515
|
+
specversion: z.literal("1.0"),
|
|
1516
|
+
type: z.string().min(1),
|
|
1517
|
+
datacontenttype: z.string().optional(),
|
|
1518
|
+
dataschema: z.string().url().optional(),
|
|
1519
|
+
subject: z.string().optional(),
|
|
1520
|
+
time: z.string().datetime().optional(),
|
|
1521
|
+
data: z.unknown().optional(),
|
|
1522
|
+
// SnapBack extensions
|
|
1523
|
+
traceid: z.string().optional(),
|
|
1524
|
+
workspaceid: z.string().optional(),
|
|
1525
|
+
userid: z.string().optional(),
|
|
1526
|
+
sessionid: z.string().optional(),
|
|
1527
|
+
toolurn: z.string().optional(),
|
|
1528
|
+
riskclass: z.enum([
|
|
1529
|
+
"safe",
|
|
1530
|
+
"low",
|
|
1531
|
+
"medium",
|
|
1532
|
+
"high",
|
|
1533
|
+
"critical"
|
|
1534
|
+
]).optional(),
|
|
1535
|
+
sandboxed: z.boolean().optional(),
|
|
1536
|
+
privacysig: z.string().optional()
|
|
1537
|
+
});
|
|
1538
|
+
z.string().regex(/^\d+\.\d+\.\d+(?:-[\w.]+)?$/, "Invalid semver format. Expected: MAJOR.MINOR.PATCH[-prerelease]");
|
|
1539
|
+
var ToolURNSchema = z.string().regex(/^urn:(snapback|openclaw|community|enterprise):[\w-]+:[\w-]+:\d+\.\d+\.\d+(?:-[\w.]+)?$/, "Invalid URN format. Expected: urn:{namespace}:{pluginId}:{capability}:{semver}").brand();
|
|
1540
|
+
|
|
1541
|
+
// ../../packages/contracts/dist/primitives/tool-invocation.js
|
|
1542
|
+
var AGENT_RUNTIMES = [
|
|
1543
|
+
"claude-code",
|
|
1544
|
+
"cursor",
|
|
1545
|
+
"copilot",
|
|
1546
|
+
"openclaw",
|
|
1547
|
+
"windsurf",
|
|
1548
|
+
"cline",
|
|
1549
|
+
"aider",
|
|
1550
|
+
"continue",
|
|
1551
|
+
"unknown"
|
|
1552
|
+
];
|
|
1553
|
+
var SANDBOX_LEVELS = [
|
|
1554
|
+
"none",
|
|
1555
|
+
"basic",
|
|
1556
|
+
"strict",
|
|
1557
|
+
"isolated"
|
|
1558
|
+
];
|
|
1559
|
+
var RISK_CLASSES = [
|
|
1560
|
+
"safe",
|
|
1561
|
+
"low",
|
|
1562
|
+
"medium",
|
|
1563
|
+
"high",
|
|
1564
|
+
"critical"
|
|
1565
|
+
];
|
|
1566
|
+
var CHANNELS = [
|
|
1567
|
+
"api",
|
|
1568
|
+
"mcp",
|
|
1569
|
+
"vscode",
|
|
1570
|
+
"cli",
|
|
1571
|
+
"web",
|
|
1572
|
+
"whatsapp",
|
|
1573
|
+
"telegram",
|
|
1574
|
+
"discord",
|
|
1575
|
+
"slack",
|
|
1576
|
+
"teams",
|
|
1577
|
+
"matrix"
|
|
1578
|
+
];
|
|
1579
|
+
var SessionContextSchema = z.object({
|
|
1580
|
+
/** Channel through which request was made */
|
|
1581
|
+
channel: z.enum(CHANNELS),
|
|
1582
|
+
/** Workspace identifier (local path hash or cloud workspace ID) */
|
|
1583
|
+
workspaceId: z.string().min(1),
|
|
1584
|
+
/** Session ID for request correlation */
|
|
1585
|
+
sessionId: z.string().uuid(),
|
|
1586
|
+
/** OpenClaw session ID if bridged */
|
|
1587
|
+
openclawSessionId: z.string().optional(),
|
|
1588
|
+
/** Channel-specific user identifier */
|
|
1589
|
+
channelUserId: z.string().optional()
|
|
1590
|
+
});
|
|
1591
|
+
var IdentityContextSchema = z.object({
|
|
1592
|
+
/** User ID (authenticated) */
|
|
1593
|
+
userId: z.string().uuid().optional(),
|
|
1594
|
+
/** Anonymous identifier for unauthenticated requests */
|
|
1595
|
+
anonymousId: z.string().optional(),
|
|
1596
|
+
/** Current subscription tier */
|
|
1597
|
+
tier: z.enum([
|
|
1598
|
+
"free",
|
|
1599
|
+
"pro",
|
|
1600
|
+
"team",
|
|
1601
|
+
"enterprise"
|
|
1602
|
+
]).default("free"),
|
|
1603
|
+
/** Enabled features for this user */
|
|
1604
|
+
features: z.array(z.string()).default([]),
|
|
1605
|
+
/** Pre-resolved entitlements (optional, can be fetched) */
|
|
1606
|
+
entitlements: z.object({
|
|
1607
|
+
tier: z.enum([
|
|
1608
|
+
"free",
|
|
1609
|
+
"pro",
|
|
1610
|
+
"team",
|
|
1611
|
+
"enterprise"
|
|
1612
|
+
]),
|
|
1613
|
+
features: z.array(z.string()),
|
|
1614
|
+
limits: z.record(z.string(), z.number().nullable())
|
|
1615
|
+
}).optional(),
|
|
1616
|
+
/** API key identifier (if using API key auth) */
|
|
1617
|
+
apiKeyId: z.string().optional()
|
|
1618
|
+
});
|
|
1619
|
+
var ToolSpecSchema = z.object({
|
|
1620
|
+
/** Tool URN (canonical identifier) */
|
|
1621
|
+
urn: ToolURNSchema,
|
|
1622
|
+
/** Tool risk classification */
|
|
1623
|
+
riskClass: z.enum(RISK_CLASSES),
|
|
1624
|
+
/** Required permissions to invoke this tool */
|
|
1625
|
+
requiredPermissions: z.array(z.string()).default([]),
|
|
1626
|
+
/** Required features (entitlement check) */
|
|
1627
|
+
requiredFeatures: z.array(z.string()).default([]),
|
|
1628
|
+
/** Minimum tier required */
|
|
1629
|
+
minTier: z.enum([
|
|
1630
|
+
"free",
|
|
1631
|
+
"pro",
|
|
1632
|
+
"team",
|
|
1633
|
+
"enterprise"
|
|
1634
|
+
]).optional()
|
|
1635
|
+
});
|
|
1636
|
+
var ExecutionContextSchema = z.object({
|
|
1637
|
+
/** Agent runtime that initiated the call */
|
|
1638
|
+
agentRuntime: z.enum(AGENT_RUNTIMES).default("unknown"),
|
|
1639
|
+
/** Required sandbox level */
|
|
1640
|
+
sandboxLevel: z.enum(SANDBOX_LEVELS).default("basic"),
|
|
1641
|
+
/** Timeout in milliseconds */
|
|
1642
|
+
timeoutMs: z.number().positive().default(3e4),
|
|
1643
|
+
/** Whether to auto-snapshot before execution */
|
|
1644
|
+
snapshotBefore: z.boolean().default(false),
|
|
1645
|
+
/** Maximum concurrent executions allowed */
|
|
1646
|
+
maxConcurrent: z.number().positive().default(1),
|
|
1647
|
+
/** Retry configuration */
|
|
1648
|
+
retry: z.object({
|
|
1649
|
+
maxAttempts: z.number().min(1).max(5).default(1),
|
|
1650
|
+
backoffMs: z.number().min(100).max(3e4).default(1e3)
|
|
1651
|
+
}).optional()
|
|
1652
|
+
});
|
|
1653
|
+
z.object({
|
|
1654
|
+
/** Unique trace ID for request correlation and audit */
|
|
1655
|
+
traceId: z.string().uuid(),
|
|
1656
|
+
/** Timestamp when invocation was created */
|
|
1657
|
+
createdAt: z.coerce.date().default(() => /* @__PURE__ */ new Date()),
|
|
1658
|
+
/** Session context - channel and workspace */
|
|
1659
|
+
session: SessionContextSchema,
|
|
1660
|
+
/** Identity context - who and what permissions */
|
|
1661
|
+
identity: IdentityContextSchema,
|
|
1662
|
+
/** Tool specification - what tool and risk class */
|
|
1663
|
+
tool: ToolSpecSchema,
|
|
1664
|
+
/** Tool arguments (validated against tool's input schema) */
|
|
1665
|
+
args: z.record(z.string(), z.unknown()).default({}),
|
|
1666
|
+
/** Execution context - how to execute */
|
|
1667
|
+
context: ExecutionContextSchema,
|
|
1668
|
+
/**
|
|
1669
|
+
* Metadata for observability and debugging
|
|
1670
|
+
* Not used in execution logic, only for tracing
|
|
1671
|
+
*/
|
|
1672
|
+
metadata: z.object({
|
|
1673
|
+
/** Source surface that created this invocation */
|
|
1674
|
+
source: z.string().optional(),
|
|
1675
|
+
/** Parent trace ID for nested calls */
|
|
1676
|
+
parentTraceId: z.string().uuid().optional(),
|
|
1677
|
+
/** Custom labels for filtering */
|
|
1678
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
1679
|
+
/** Original request payload hash (for audit) */
|
|
1680
|
+
requestHash: z.string().optional()
|
|
1681
|
+
}).optional()
|
|
1682
|
+
});
|
|
1683
|
+
var PipelineStepResultSchema = z.object({
|
|
1684
|
+
/** Step name */
|
|
1685
|
+
step: z.string(),
|
|
1686
|
+
/** Whether step passed */
|
|
1687
|
+
passed: z.boolean(),
|
|
1688
|
+
/** Duration in milliseconds */
|
|
1689
|
+
durationMs: z.number(),
|
|
1690
|
+
/** Error if step failed */
|
|
1691
|
+
error: z.object({
|
|
1692
|
+
code: z.string(),
|
|
1693
|
+
message: z.string(),
|
|
1694
|
+
details: z.unknown().optional()
|
|
1695
|
+
}).optional(),
|
|
1696
|
+
/** Step-specific data */
|
|
1697
|
+
data: z.unknown().optional()
|
|
1698
|
+
});
|
|
1699
|
+
z.object({
|
|
1700
|
+
/** Trace ID from invocation */
|
|
1701
|
+
traceId: z.string().uuid(),
|
|
1702
|
+
/** Whether execution succeeded */
|
|
1703
|
+
success: z.boolean(),
|
|
1704
|
+
/** Result data (if successful) */
|
|
1705
|
+
result: z.unknown().optional(),
|
|
1706
|
+
/** Error details (if failed) */
|
|
1707
|
+
error: z.object({
|
|
1708
|
+
code: z.string(),
|
|
1709
|
+
message: z.string(),
|
|
1710
|
+
step: z.string().optional(),
|
|
1711
|
+
details: z.unknown().optional()
|
|
1712
|
+
}).optional(),
|
|
1713
|
+
/** Pipeline step results */
|
|
1714
|
+
steps: z.array(PipelineStepResultSchema),
|
|
1715
|
+
/** Total execution duration */
|
|
1716
|
+
durationMs: z.number(),
|
|
1717
|
+
/** Snapshot ID if created */
|
|
1718
|
+
snapshotId: z.string().optional(),
|
|
1719
|
+
/** Audit log ID */
|
|
1720
|
+
auditId: z.string().optional()
|
|
1721
|
+
});
|
|
1722
|
+
|
|
1723
|
+
// ../../packages/contracts/dist/primitives/execution-pipeline.js
|
|
1724
|
+
var PIPELINE_STEPS = [
|
|
1725
|
+
"validate",
|
|
1726
|
+
"authenticate",
|
|
1727
|
+
"authorize",
|
|
1728
|
+
"rate_limit",
|
|
1729
|
+
"pre_scan",
|
|
1730
|
+
"lease",
|
|
1731
|
+
"snapshot",
|
|
1732
|
+
"execute",
|
|
1733
|
+
"post_scan",
|
|
1734
|
+
"egress",
|
|
1735
|
+
"audit",
|
|
1736
|
+
"finalize"
|
|
1737
|
+
];
|
|
1738
|
+
z.object({
|
|
1739
|
+
skipSteps: z.array(z.enum(PIPELINE_STEPS)).optional(),
|
|
1740
|
+
timeoutMs: z.number().positive().optional(),
|
|
1741
|
+
continueOnNonCriticalFailure: z.boolean().optional()
|
|
1742
|
+
});
|
|
1743
|
+
z.object({
|
|
1744
|
+
/** Whether the lease was acquired */
|
|
1745
|
+
acquired: z.boolean(),
|
|
1746
|
+
/** Lease ID if acquired */
|
|
1747
|
+
leaseId: z.string().optional(),
|
|
1748
|
+
/** Reason if not acquired */
|
|
1749
|
+
reason: z.string().optional(),
|
|
1750
|
+
/** Conflicting leases if acquisition failed */
|
|
1751
|
+
conflicts: z.array(z.object({
|
|
1752
|
+
leaseId: z.string(),
|
|
1753
|
+
files: z.array(z.string()),
|
|
1754
|
+
heldBy: z.object({
|
|
1755
|
+
agentRuntime: z.enum(AGENT_RUNTIMES),
|
|
1756
|
+
sessionId: z.string()
|
|
1757
|
+
}),
|
|
1758
|
+
expiresAt: z.coerce.date()
|
|
1759
|
+
})).optional()
|
|
1760
|
+
});
|
|
1761
|
+
z.object({
|
|
1762
|
+
/** Whether there are conflicts */
|
|
1763
|
+
hasConflicts: z.boolean(),
|
|
1764
|
+
/** Conflicting files grouped by lease */
|
|
1765
|
+
conflicts: z.array(z.object({
|
|
1766
|
+
leaseId: z.string(),
|
|
1767
|
+
files: z.array(z.string()),
|
|
1768
|
+
heldBy: z.object({
|
|
1769
|
+
agentRuntime: z.enum(AGENT_RUNTIMES),
|
|
1770
|
+
sessionId: z.string()
|
|
1771
|
+
}),
|
|
1772
|
+
expiresAt: z.coerce.date(),
|
|
1773
|
+
/** Whether this conflict is blocking (cannot proceed) */
|
|
1774
|
+
blocking: z.boolean()
|
|
1775
|
+
})),
|
|
1776
|
+
/** Files that are safe to modify */
|
|
1777
|
+
safeFiles: z.array(z.string()),
|
|
1778
|
+
/** Files that are blocked */
|
|
1779
|
+
blockedFiles: z.array(z.string())
|
|
1780
|
+
});
|
|
1781
|
+
z.object({
|
|
1782
|
+
/** Unique lease identifier */
|
|
1783
|
+
leaseId: z.string(),
|
|
1784
|
+
/** Workspace this lease belongs to */
|
|
1785
|
+
workspaceId: z.string(),
|
|
1786
|
+
/** Files covered by this lease */
|
|
1787
|
+
files: z.array(z.string()),
|
|
1788
|
+
/** Agent that holds this lease */
|
|
1789
|
+
agentRuntime: z.enum(AGENT_RUNTIMES),
|
|
1790
|
+
/** Session that holds this lease */
|
|
1791
|
+
sessionId: z.string(),
|
|
1792
|
+
/** Trace ID for correlation */
|
|
1793
|
+
traceId: z.string().optional(),
|
|
1794
|
+
/** When the lease was acquired */
|
|
1795
|
+
acquiredAt: z.coerce.date(),
|
|
1796
|
+
/** When the lease expires */
|
|
1797
|
+
expiresAt: z.coerce.date(),
|
|
1798
|
+
/** Time-to-live in milliseconds */
|
|
1799
|
+
ttlMs: z.number().positive(),
|
|
1800
|
+
/** Whether the lease is still active */
|
|
1801
|
+
active: z.boolean().default(true),
|
|
1802
|
+
/** Number of times the lease has been extended */
|
|
1803
|
+
extensionCount: z.number().default(0)
|
|
1804
|
+
});
|
|
1805
|
+
|
|
1806
|
+
// ../../packages/contracts/dist/saga/tier-upgrade-saga.js
|
|
1807
|
+
var TIER_UPGRADE_SAGA = {
|
|
1808
|
+
sagaType: "tier_upgrade",
|
|
1809
|
+
maxRetries: 3,
|
|
1810
|
+
persistenceInterval: 1e3,
|
|
1811
|
+
steps: [
|
|
1812
|
+
{
|
|
1813
|
+
stepId: "update_subscription",
|
|
1814
|
+
stepName: "Update Subscription in Payment Provider",
|
|
1815
|
+
execute: /* @__PURE__ */ __name(async (_input) => {
|
|
1816
|
+
throw new Error("Not implemented - to be injected");
|
|
1817
|
+
}, "execute"),
|
|
1818
|
+
compensate: /* @__PURE__ */ __name(async (_input, output) => {
|
|
1819
|
+
const typedOutput = output;
|
|
1820
|
+
if (typedOutput?.subscriptionId) ;
|
|
1821
|
+
}, "compensate"),
|
|
1822
|
+
retryable: true,
|
|
1823
|
+
timeout: 3e4
|
|
1824
|
+
},
|
|
1825
|
+
{
|
|
1826
|
+
stepId: "update_user_tier",
|
|
1827
|
+
stepName: "Update User Tier in Database",
|
|
1828
|
+
execute: /* @__PURE__ */ __name(async (_input) => {
|
|
1829
|
+
throw new Error("Not implemented - to be injected");
|
|
1830
|
+
}, "execute"),
|
|
1831
|
+
compensate: /* @__PURE__ */ __name(async (_input, output) => {
|
|
1832
|
+
const typedOutput = output;
|
|
1833
|
+
if (typedOutput?.previousTier) ;
|
|
1834
|
+
}, "compensate"),
|
|
1835
|
+
retryable: true,
|
|
1836
|
+
timeout: 5e3
|
|
1837
|
+
},
|
|
1838
|
+
{
|
|
1839
|
+
stepId: "update_entitlements",
|
|
1840
|
+
stepName: "Update Entitlements with New Tier Features",
|
|
1841
|
+
execute: /* @__PURE__ */ __name(async (_input) => {
|
|
1842
|
+
throw new Error("Not implemented - to be injected");
|
|
1843
|
+
}, "execute"),
|
|
1844
|
+
compensate: /* @__PURE__ */ __name(async (_input, output) => {
|
|
1845
|
+
const typedOutput = output;
|
|
1846
|
+
if (typedOutput?.previousVersion !== void 0) ;
|
|
1847
|
+
}, "compensate"),
|
|
1848
|
+
retryable: true,
|
|
1849
|
+
timeout: 5e3
|
|
1850
|
+
},
|
|
1851
|
+
{
|
|
1852
|
+
stepId: "send_confirmation",
|
|
1853
|
+
stepName: "Send Upgrade Confirmation Email",
|
|
1854
|
+
execute: /* @__PURE__ */ __name(async (_input) => {
|
|
1855
|
+
throw new Error("Not implemented - to be injected");
|
|
1856
|
+
}, "execute"),
|
|
1857
|
+
compensate: /* @__PURE__ */ __name(async (_input, output) => {
|
|
1858
|
+
const typedOutput = output;
|
|
1859
|
+
if (typedOutput?.emailJobId) ;
|
|
1860
|
+
}, "compensate"),
|
|
1861
|
+
retryable: true,
|
|
1862
|
+
timeout: 1e4
|
|
1863
|
+
},
|
|
1864
|
+
{
|
|
1865
|
+
stepId: "emit_event",
|
|
1866
|
+
stepName: "Emit Tier Upgraded Event",
|
|
1867
|
+
execute: /* @__PURE__ */ __name(async (_input) => {
|
|
1868
|
+
throw new Error("Not implemented - to be injected");
|
|
1869
|
+
}, "execute"),
|
|
1870
|
+
// No compensation needed for events (idempotent)
|
|
1871
|
+
retryable: false,
|
|
1872
|
+
timeout: 3e3
|
|
1873
|
+
}
|
|
1874
|
+
]
|
|
1875
|
+
};
|
|
1876
|
+
var DiffChangeSchema = z.object({
|
|
1877
|
+
added: z.boolean().optional().default(false),
|
|
1878
|
+
removed: z.boolean().optional().default(false),
|
|
1879
|
+
value: z.string(),
|
|
1880
|
+
count: z.number().optional()
|
|
1881
|
+
});
|
|
1882
|
+
var RiskScoreSchema = z.object({
|
|
1883
|
+
score: z.number().min(0).max(10),
|
|
1884
|
+
factors: z.array(z.string()),
|
|
1885
|
+
severity: RiskSeveritySchema
|
|
1886
|
+
});
|
|
1887
|
+
z.object({
|
|
1888
|
+
metrics: z.record(z.string(), z.number()),
|
|
1889
|
+
trends: z.record(z.string(), z.array(z.number())),
|
|
1890
|
+
insights: z.array(z.string()),
|
|
1891
|
+
timestamp: z.number(),
|
|
1892
|
+
snapshotRecommendations: z.object({
|
|
1893
|
+
shouldCreateSnapshot: z.boolean(),
|
|
1894
|
+
reason: z.string(),
|
|
1895
|
+
urgency: RiskSeveritySchema,
|
|
1896
|
+
suggestedTiming: z.string()
|
|
1897
|
+
}).optional()
|
|
1898
|
+
});
|
|
1899
|
+
z.object({
|
|
1900
|
+
trigger: z.string().default("manual"),
|
|
1901
|
+
risk: z.number().min(0).max(10).optional(),
|
|
1902
|
+
content: z.string().optional(),
|
|
1903
|
+
files: z.array(z.string()).optional()
|
|
1904
|
+
});
|
|
1905
|
+
z.object({
|
|
1906
|
+
trigger: z.string().default("manual"),
|
|
1907
|
+
risk: z.number().min(0).max(10).optional(),
|
|
1908
|
+
content: z.string().optional()
|
|
1909
|
+
});
|
|
1910
|
+
z.object({
|
|
1911
|
+
id: z.string(),
|
|
1912
|
+
timestamp: z.number(),
|
|
1913
|
+
meta: z.object({
|
|
1914
|
+
trigger: z.string().optional(),
|
|
1915
|
+
risk: z.number().optional()
|
|
1916
|
+
}).optional()
|
|
1917
|
+
});
|
|
1918
|
+
z.object({
|
|
1919
|
+
changes: z.array(DiffChangeSchema)
|
|
1920
|
+
});
|
|
1921
|
+
z.object({
|
|
1922
|
+
before: z.record(z.string(), z.any()),
|
|
1923
|
+
after: z.record(z.string(), z.any())
|
|
1924
|
+
});
|
|
1925
|
+
z.object({
|
|
1926
|
+
message: z.string(),
|
|
1927
|
+
code: z.string().optional(),
|
|
1928
|
+
details: z.any().optional()
|
|
1929
|
+
});
|
|
1930
|
+
var RetrySchema = z.object({
|
|
1931
|
+
retries: z.number().int().min(0).default(2),
|
|
1932
|
+
factor: z.number().min(1).default(2),
|
|
1933
|
+
min: z.number().int().default(250),
|
|
1934
|
+
max: z.number().int().default(1500),
|
|
1935
|
+
jitter: z.boolean().default(true)
|
|
1936
|
+
});
|
|
1937
|
+
var CircuitSchema = z.object({
|
|
1938
|
+
enabled: z.boolean().default(true),
|
|
1939
|
+
errorThresholdPercentage: z.number().int().min(1).max(100).default(50),
|
|
1940
|
+
volumeThreshold: z.number().int().min(1).default(10),
|
|
1941
|
+
timeoutMs: z.number().int().default(5e3),
|
|
1942
|
+
resetMs: z.number().int().default(3e4),
|
|
1943
|
+
rollingCountMs: z.number().int().default(6e4),
|
|
1944
|
+
rollingCountBuckets: z.number().int().default(6)
|
|
1945
|
+
});
|
|
1946
|
+
z.object({
|
|
1947
|
+
timeoutMs: z.number().int().default(5e3),
|
|
1948
|
+
maxConcurrent: z.number().int().min(1).default(4),
|
|
1949
|
+
retry: RetrySchema,
|
|
1950
|
+
circuit: CircuitSchema,
|
|
1951
|
+
batch: z.object({
|
|
1952
|
+
size: z.number().int().min(1).default(5),
|
|
1953
|
+
maxWaitMs: z.number().int().default(150)
|
|
1954
|
+
})
|
|
1955
|
+
});
|
|
1956
|
+
z.object({
|
|
1957
|
+
debounceMs: z.number().int().default(120),
|
|
1958
|
+
awaitWriteFinish: z.object({
|
|
1959
|
+
stabilityThreshold: z.number().int().default(200),
|
|
1960
|
+
pollInterval: z.number().int().default(50)
|
|
1961
|
+
}),
|
|
1962
|
+
ignored: z.array(z.string()).default([
|
|
1963
|
+
"**/{node_modules,.git,.vscode,dist,.next,.nuxt,coverage}/**"
|
|
1964
|
+
])
|
|
1965
|
+
});
|
|
1966
|
+
var PurchaseTypeEnum = z.enum([
|
|
1967
|
+
"ONE_TIME",
|
|
1968
|
+
"SUBSCRIPTION",
|
|
1969
|
+
"addon"
|
|
1970
|
+
]);
|
|
1971
|
+
z.object({
|
|
1972
|
+
id: z.string(),
|
|
1973
|
+
organizationId: z.string().nullable().optional(),
|
|
1974
|
+
userId: z.string().nullable().optional(),
|
|
1975
|
+
type: PurchaseTypeEnum,
|
|
1976
|
+
customerId: z.string(),
|
|
1977
|
+
subscriptionId: z.string().nullable().optional(),
|
|
1978
|
+
productId: z.string(),
|
|
1979
|
+
status: z.string().nullable().optional(),
|
|
1980
|
+
createdAt: z.date(),
|
|
1981
|
+
updatedAt: z.date().nullable().optional()
|
|
1982
|
+
});
|
|
1983
|
+
var SessionSchemaVersion = "sb.session.v1";
|
|
1984
|
+
var ChangeOpSchema = z.enum([
|
|
1985
|
+
"created",
|
|
1986
|
+
"modified",
|
|
1987
|
+
"deleted",
|
|
1988
|
+
"renamed"
|
|
1989
|
+
]);
|
|
1990
|
+
var EOLTypeSchema = z.enum([
|
|
1991
|
+
"lf",
|
|
1992
|
+
"crlf"
|
|
1993
|
+
]);
|
|
1994
|
+
var SessionTriggerSchema = z.enum([
|
|
1995
|
+
"filewatch",
|
|
1996
|
+
"pre-commit",
|
|
1997
|
+
"manual",
|
|
1998
|
+
"idle-finalize"
|
|
1999
|
+
]);
|
|
2000
|
+
var SessionChangeSchema = z.object({
|
|
2001
|
+
/** Relative POSIX path from workspace root */
|
|
2002
|
+
p: z.string(),
|
|
2003
|
+
/** Operation type */
|
|
2004
|
+
op: ChangeOpSchema,
|
|
2005
|
+
/** Prior relative path (for rename operations only) */
|
|
2006
|
+
from: z.string().optional(),
|
|
2007
|
+
/** SHA-256 hash before change (CAS reference) - computed on finalize */
|
|
2008
|
+
hOld: z.string().optional(),
|
|
2009
|
+
/** SHA-256 hash after change (CAS reference) - computed on finalize */
|
|
2010
|
+
hNew: z.string().optional(),
|
|
2011
|
+
/** File size before change (bytes) */
|
|
2012
|
+
sizeBefore: z.number().int().nonnegative().optional(),
|
|
2013
|
+
/** File size after change (bytes) */
|
|
2014
|
+
sizeAfter: z.number().int().nonnegative().optional(),
|
|
2015
|
+
/** Modification time before change (Unix epoch ms) */
|
|
2016
|
+
mtimeBefore: z.number().int().nonnegative().optional(),
|
|
2017
|
+
/** Modification time after change (Unix epoch ms) */
|
|
2018
|
+
mtimeAfter: z.number().int().nonnegative().optional(),
|
|
2019
|
+
/** File permissions before change (Unix mode) */
|
|
2020
|
+
modeBefore: z.number().int().nonnegative().optional(),
|
|
2021
|
+
/** File permissions after change (Unix mode) */
|
|
2022
|
+
modeAfter: z.number().int().nonnegative().optional(),
|
|
2023
|
+
/** Line ending style before change */
|
|
2024
|
+
eolBefore: EOLTypeSchema.optional(),
|
|
2025
|
+
/** Line ending style after change */
|
|
2026
|
+
eolAfter: EOLTypeSchema.optional()
|
|
2027
|
+
});
|
|
2028
|
+
z.object({
|
|
2029
|
+
/** Schema version for backward compatibility */
|
|
2030
|
+
schema: z.literal(SessionSchemaVersion),
|
|
2031
|
+
/** Unique session identifier (CUID) */
|
|
2032
|
+
sessionId: z.string(),
|
|
2033
|
+
/** Session start timestamp (ISO 8601) */
|
|
2034
|
+
startedAt: z.string().datetime(),
|
|
2035
|
+
/** Session end timestamp (ISO 8601) - undefined if active */
|
|
2036
|
+
endedAt: z.string().datetime().optional(),
|
|
2037
|
+
/** VS Code workspace folder URI (multi-root workspace safe) */
|
|
2038
|
+
workspaceUri: z.string(),
|
|
2039
|
+
/** Offline-generated semantic label (never transmitted) */
|
|
2040
|
+
name: z.string().optional(),
|
|
2041
|
+
/** Trigger sources for this session */
|
|
2042
|
+
triggers: z.array(SessionTriggerSchema),
|
|
2043
|
+
/** Total number of file changes in this session */
|
|
2044
|
+
changeCount: z.number().int().nonnegative(),
|
|
2045
|
+
/** Chronological list of file changes */
|
|
2046
|
+
filesChanged: z.array(SessionChangeSchema),
|
|
2047
|
+
/** Array of snapshot IDs created during this session */
|
|
2048
|
+
snapshots: z.array(z.string()).optional()
|
|
2049
|
+
});
|
|
2050
|
+
z.object({
|
|
2051
|
+
sessionId: z.string(),
|
|
2052
|
+
startedAt: z.string().datetime(),
|
|
2053
|
+
endedAt: z.string().datetime().optional(),
|
|
2054
|
+
name: z.string().optional(),
|
|
2055
|
+
changeCount: z.number().int().nonnegative(),
|
|
2056
|
+
triggers: z.array(SessionTriggerSchema)
|
|
2057
|
+
});
|
|
2058
|
+
z.object({
|
|
2059
|
+
/** Only return sessions for this workspace URI */
|
|
2060
|
+
workspaceUri: z.string().optional(),
|
|
2061
|
+
/** Only return active sessions (endedAt is null) */
|
|
2062
|
+
activeOnly: z.boolean().optional(),
|
|
2063
|
+
/** Only return finalized sessions (endedAt is not null) */
|
|
2064
|
+
finalizedOnly: z.boolean().optional(),
|
|
2065
|
+
/** Return sessions that started after this timestamp */
|
|
2066
|
+
after: z.date().optional(),
|
|
2067
|
+
/** Return sessions that started before this timestamp */
|
|
2068
|
+
before: z.date().optional(),
|
|
2069
|
+
/** Maximum number of results */
|
|
2070
|
+
limit: z.number().int().positive().optional(),
|
|
2071
|
+
/** Offset for pagination */
|
|
2072
|
+
offset: z.number().int().nonnegative().optional()
|
|
2073
|
+
});
|
|
2074
|
+
z.object({
|
|
2075
|
+
/** VS Code workspace folder URI */
|
|
2076
|
+
workspaceUri: z.string(),
|
|
2077
|
+
/** Initial trigger sources */
|
|
2078
|
+
triggers: z.array(SessionTriggerSchema).default([
|
|
2079
|
+
"filewatch"
|
|
2080
|
+
]),
|
|
2081
|
+
/** Optional semantic name (generated offline) */
|
|
2082
|
+
name: z.string().optional()
|
|
2083
|
+
});
|
|
2084
|
+
z.object({
|
|
2085
|
+
/** VS Code workspace folder URI (multi-root safe) */
|
|
2086
|
+
workspaceUri: z.string(),
|
|
2087
|
+
/** Idle timeout in milliseconds (default: 15 minutes) */
|
|
2088
|
+
idleMs: z.number().int().positive().default(15 * 6e4),
|
|
2089
|
+
/** Batch size for flushing changes to database (default: 50) */
|
|
2090
|
+
flushBatchSize: z.number().int().positive().default(50),
|
|
2091
|
+
/** Flush interval in milliseconds (default: 5 seconds) */
|
|
2092
|
+
flushIntervalMs: z.number().int().positive().default(5e3),
|
|
2093
|
+
/** Use VS Code file system watcher (default: true) */
|
|
2094
|
+
useVSCodeWatcher: z.boolean().default(true),
|
|
2095
|
+
/** Patterns to ignore (.snapbackignore) */
|
|
2096
|
+
ignorePatterns: z.array(z.string()).default([
|
|
2097
|
+
"node_modules/**",
|
|
2098
|
+
".next/**",
|
|
2099
|
+
"dist/**",
|
|
2100
|
+
"build/**",
|
|
2101
|
+
"coverage/**",
|
|
2102
|
+
".git/**",
|
|
2103
|
+
"*.log",
|
|
2104
|
+
"*.tmp",
|
|
2105
|
+
"*.swp",
|
|
2106
|
+
".DS_Store"
|
|
2107
|
+
]),
|
|
2108
|
+
/** @enterprise User tier (for analytics) */
|
|
2109
|
+
tier: z.enum([
|
|
2110
|
+
"free",
|
|
2111
|
+
"pro"
|
|
2112
|
+
]).default("free"),
|
|
2113
|
+
/** @enterprise Analytics consent (Pro tier only) */
|
|
2114
|
+
consent: z.boolean().default(false)
|
|
2115
|
+
});
|
|
2116
|
+
var ModificationSourceSchema = z.enum([
|
|
2117
|
+
"extension",
|
|
2118
|
+
"mcp",
|
|
2119
|
+
"daemon",
|
|
2120
|
+
"cli"
|
|
2121
|
+
]);
|
|
2122
|
+
var ModificationTypeSchema = z.enum([
|
|
2123
|
+
"create",
|
|
2124
|
+
"update",
|
|
2125
|
+
"delete"
|
|
2126
|
+
]);
|
|
2127
|
+
z.object({
|
|
2128
|
+
/** Absolute path to the modified file */
|
|
2129
|
+
path: z.string().min(1, "Path cannot be empty"),
|
|
2130
|
+
/** Modification timestamp (ms since epoch) */
|
|
2131
|
+
timestamp: z.number().positive("Timestamp must be positive"),
|
|
2132
|
+
/** Type of modification */
|
|
2133
|
+
type: ModificationTypeSchema,
|
|
2134
|
+
/** Lines changed (0 if unknown or delete) */
|
|
2135
|
+
linesChanged: z.number().int().nonnegative().default(0),
|
|
2136
|
+
/** Whether this change was AI-attributed (detected by AIPresenceDetector) */
|
|
2137
|
+
aiAttributed: z.boolean().default(false),
|
|
2138
|
+
/** Which AI tool made the change, if detected (e.g., 'copilot', 'cursor', 'claude') */
|
|
2139
|
+
aiTool: z.string().nullable().default(null),
|
|
2140
|
+
/** Source surface that recorded this modification */
|
|
2141
|
+
source: ModificationSourceSchema
|
|
2142
|
+
});
|
|
2143
|
+
z.object({
|
|
2144
|
+
/** Active extension IDs in the IDE environment */
|
|
2145
|
+
extensionIds: z.array(z.string()).default([]),
|
|
2146
|
+
/** Optional file content to analyze for AI signatures */
|
|
2147
|
+
content: z.string().optional(),
|
|
2148
|
+
/** Character velocity (chars/ms) from burst detection */
|
|
2149
|
+
velocity: z.number().nonnegative().optional(),
|
|
2150
|
+
/** Total characters changed in the operation */
|
|
2151
|
+
charCount: z.number().int().nonnegative().optional()
|
|
2152
|
+
});
|
|
2153
|
+
var AiDetectionOutputSchema = z.object({
|
|
2154
|
+
/** Detected AI tool name, or null if none detected */
|
|
2155
|
+
tool: z.string().nullable(),
|
|
2156
|
+
/** Confidence score (0-1) */
|
|
2157
|
+
confidence: z.number().min(0).max(1),
|
|
2158
|
+
/** Detection method that triggered */
|
|
2159
|
+
method: z.enum([
|
|
2160
|
+
"extension",
|
|
2161
|
+
"velocity",
|
|
2162
|
+
"pattern",
|
|
2163
|
+
"combined"
|
|
2164
|
+
]).nullable(),
|
|
2165
|
+
/** Indicators that contributed to detection */
|
|
2166
|
+
indicators: z.array(z.string()).optional()
|
|
2167
|
+
});
|
|
2168
|
+
z.object({
|
|
2169
|
+
/** Code content to scan for threats */
|
|
2170
|
+
content: z.string()
|
|
2171
|
+
});
|
|
2172
|
+
var ThreatPatternSchema = z.object({
|
|
2173
|
+
/** Description of the threat pattern */
|
|
2174
|
+
description: z.string(),
|
|
2175
|
+
/** Severity score (0-1), where 1 is most critical */
|
|
2176
|
+
severity: z.number().min(0).max(1)
|
|
2177
|
+
});
|
|
2178
|
+
var ThreatDetectionOutputSchema = z.object({
|
|
2179
|
+
/** Total number of threats detected */
|
|
2180
|
+
threatCount: z.number().int().nonnegative(),
|
|
2181
|
+
/** List of detected threat patterns */
|
|
2182
|
+
patterns: z.array(ThreatPatternSchema),
|
|
2183
|
+
/** Overall severity level */
|
|
2184
|
+
severity: z.enum([
|
|
2185
|
+
"none",
|
|
2186
|
+
"low",
|
|
2187
|
+
"medium",
|
|
2188
|
+
"high",
|
|
2189
|
+
"critical"
|
|
2190
|
+
]),
|
|
2191
|
+
/** Aggregated threat score (0-10) */
|
|
2192
|
+
score: z.number().min(0).max(10)
|
|
2193
|
+
});
|
|
2194
|
+
z.object({
|
|
2195
|
+
/** File path being analyzed */
|
|
2196
|
+
filePath: z.string(),
|
|
2197
|
+
/** Number of characters changed */
|
|
2198
|
+
charCount: z.number().int().nonnegative(),
|
|
2199
|
+
/** Timestamp of the change (ms since epoch) */
|
|
2200
|
+
timestamp: z.number().int().positive().optional()
|
|
2201
|
+
});
|
|
2202
|
+
var BurstDetectionOutputSchema = z.object({
|
|
2203
|
+
/** Whether a burst was detected */
|
|
2204
|
+
isBurst: z.boolean(),
|
|
2205
|
+
/** Character velocity (chars/ms) */
|
|
2206
|
+
velocity: z.number().nonnegative(),
|
|
2207
|
+
/** File path analyzed */
|
|
2208
|
+
filePath: z.string(),
|
|
2209
|
+
/** Total characters in the change */
|
|
2210
|
+
charCount: z.number().int().nonnegative(),
|
|
2211
|
+
/** Timestamp of detection */
|
|
2212
|
+
timestamp: z.number().int().positive()
|
|
2213
|
+
});
|
|
2214
|
+
var ComplexityFileInputSchema = z.object({
|
|
2215
|
+
/** File path */
|
|
2216
|
+
path: z.string(),
|
|
2217
|
+
/** File content */
|
|
2218
|
+
content: z.string(),
|
|
2219
|
+
/** Line count of the file */
|
|
2220
|
+
lineCount: z.number().int().nonnegative()
|
|
2221
|
+
});
|
|
2222
|
+
z.object({
|
|
2223
|
+
/** Files to analyze */
|
|
2224
|
+
files: z.array(ComplexityFileInputSchema)
|
|
2225
|
+
});
|
|
2226
|
+
var ComplexityAnalysisOutputSchema = z.object({
|
|
2227
|
+
/** Average complexity score across all files (0-1) */
|
|
2228
|
+
avgComplexity: z.number().min(0).max(1),
|
|
2229
|
+
/** Maximum complexity score of any single file (0-1) */
|
|
2230
|
+
maxComplexity: z.number().min(0).max(1),
|
|
2231
|
+
/** List of files with complexity > 0.7 */
|
|
2232
|
+
highComplexityFiles: z.array(z.string()),
|
|
2233
|
+
/** Number of files analyzed */
|
|
2234
|
+
fileCount: z.number().int().nonnegative(),
|
|
2235
|
+
/** Overall complexity value (same as avgComplexity) */
|
|
2236
|
+
value: z.number().min(0).max(1)
|
|
2237
|
+
});
|
|
2238
|
+
z.object({
|
|
2239
|
+
/** Extension IDs for AI detection */
|
|
2240
|
+
extensionIds: z.array(z.string()).default([]),
|
|
2241
|
+
/** Content to analyze (for threats, AI patterns, complexity) */
|
|
2242
|
+
content: z.string(),
|
|
2243
|
+
/** File path being analyzed */
|
|
2244
|
+
filePath: z.string(),
|
|
2245
|
+
/** Line count (for complexity calculation) */
|
|
2246
|
+
lineCount: z.number().int().nonnegative().optional(),
|
|
2247
|
+
/** Character count (for burst detection) */
|
|
2248
|
+
charCount: z.number().int().nonnegative().optional(),
|
|
2249
|
+
/** Velocity (for AI detection) */
|
|
2250
|
+
velocity: z.number().nonnegative().optional(),
|
|
2251
|
+
/** Timestamp (for burst detection) */
|
|
2252
|
+
timestamp: z.number().int().positive().optional()
|
|
2253
|
+
});
|
|
2254
|
+
z.object({
|
|
2255
|
+
/** Signal name */
|
|
2256
|
+
signal: z.enum([
|
|
2257
|
+
"ai",
|
|
2258
|
+
"threats",
|
|
2259
|
+
"burst",
|
|
2260
|
+
"complexity"
|
|
2261
|
+
]),
|
|
2262
|
+
/** Signal-specific score/value */
|
|
2263
|
+
value: z.number(),
|
|
2264
|
+
/** Whether this signal is considered "triggered" */
|
|
2265
|
+
triggered: z.boolean()
|
|
2266
|
+
});
|
|
2267
|
+
z.object({
|
|
2268
|
+
/** Individual signal results */
|
|
2269
|
+
signals: z.object({
|
|
2270
|
+
ai: AiDetectionOutputSchema,
|
|
2271
|
+
threats: ThreatDetectionOutputSchema,
|
|
2272
|
+
burst: BurstDetectionOutputSchema.optional(),
|
|
2273
|
+
complexity: ComplexityAnalysisOutputSchema
|
|
2274
|
+
}),
|
|
2275
|
+
/** Overall risk score (0-1), weighted combination of all signals */
|
|
2276
|
+
overallRisk: z.number().min(0).max(1),
|
|
2277
|
+
/** Risk level classification */
|
|
2278
|
+
riskLevel: z.enum([
|
|
2279
|
+
"low",
|
|
2280
|
+
"medium",
|
|
2281
|
+
"high",
|
|
2282
|
+
"critical"
|
|
2283
|
+
]),
|
|
2284
|
+
/** Summary of triggered signals */
|
|
2285
|
+
triggeredSignals: z.array(z.enum([
|
|
2286
|
+
"ai",
|
|
2287
|
+
"threats",
|
|
2288
|
+
"burst",
|
|
2289
|
+
"complexity"
|
|
2290
|
+
])),
|
|
2291
|
+
/** Processing time in milliseconds */
|
|
2292
|
+
processingTimeMs: z.number().nonnegative()
|
|
2293
|
+
});
|
|
2294
|
+
var SignalTypeSchema = z.enum([
|
|
2295
|
+
"ai",
|
|
2296
|
+
"threats",
|
|
2297
|
+
"burst",
|
|
2298
|
+
"complexity",
|
|
2299
|
+
"comprehensive"
|
|
2300
|
+
]);
|
|
2301
|
+
z.object({
|
|
2302
|
+
/** Error code */
|
|
2303
|
+
code: z.string(),
|
|
2304
|
+
/** Human-readable error message */
|
|
2305
|
+
message: z.string(),
|
|
2306
|
+
/** Signal type that failed */
|
|
2307
|
+
signal: SignalTypeSchema.optional()
|
|
2308
|
+
});
|
|
2309
|
+
z.object({
|
|
2310
|
+
sessionId: z.string().uuid(),
|
|
2311
|
+
workspaceId: z.string(),
|
|
2312
|
+
startedAt: z.number(),
|
|
2313
|
+
endedAt: z.number().nullable(),
|
|
2314
|
+
durationMs: z.number().nullable(),
|
|
2315
|
+
clientType: z.string(),
|
|
2316
|
+
snapshotCount: z.number().int().min(0),
|
|
2317
|
+
learningCount: z.number().int().min(0),
|
|
2318
|
+
touchedFileCount: z.number().int().min(0),
|
|
2319
|
+
riskScores: z.array(z.number().min(0).max(1))
|
|
2320
|
+
}).strict();
|
|
2321
|
+
var TaskStatusSchema = z.enum([
|
|
2322
|
+
"created",
|
|
2323
|
+
"active",
|
|
2324
|
+
"completed",
|
|
2325
|
+
"abandoned",
|
|
2326
|
+
"failed",
|
|
2327
|
+
"auto-ended",
|
|
2328
|
+
"ceremony_blocked"
|
|
2329
|
+
]);
|
|
2330
|
+
var TaskOutcomeSchema = z.enum([
|
|
2331
|
+
"completed",
|
|
2332
|
+
"abandoned",
|
|
2333
|
+
"failed"
|
|
2334
|
+
]);
|
|
2335
|
+
z.object({
|
|
2336
|
+
/** Monotonic integer ID for system tracking */
|
|
2337
|
+
id: z.number().int().positive(),
|
|
2338
|
+
/** Deterministic kebab-case identifier generated from name */
|
|
2339
|
+
slug: z.string().min(1).max(64),
|
|
2340
|
+
/** Human-readable task name provided by LLM */
|
|
2341
|
+
name: z.string().min(1).max(256),
|
|
2342
|
+
/** Current status of the task */
|
|
2343
|
+
status: TaskStatusSchema,
|
|
2344
|
+
/** Outcome when task was closed (null if active) */
|
|
2345
|
+
outcome: TaskOutcomeSchema.nullable(),
|
|
2346
|
+
/** ISO 8601 timestamp when task was created */
|
|
2347
|
+
createdAt: z.string().datetime(),
|
|
2348
|
+
/** ISO 8601 timestamp when task was last updated */
|
|
2349
|
+
updatedAt: z.string().datetime(),
|
|
2350
|
+
/** ISO 8601 timestamp when task was closed (null if active) */
|
|
2351
|
+
closedAt: z.string().datetime().nullable(),
|
|
2352
|
+
/** JSON-serialized ceremony object (null until task closes) */
|
|
2353
|
+
ceremonyJson: z.string().nullable(),
|
|
2354
|
+
/** Task ID this task explicitly continues from (lineage) */
|
|
2355
|
+
continuesFrom: z.number().int().positive().nullable(),
|
|
2356
|
+
/** Source of migration for legacy sessions */
|
|
2357
|
+
migrationSource: z.enum([
|
|
2358
|
+
"active_session",
|
|
2359
|
+
"completed_session"
|
|
2360
|
+
]).nullable()
|
|
2361
|
+
});
|
|
2362
|
+
var TaskEventTypeSchema = z.enum([
|
|
2363
|
+
"task_created",
|
|
2364
|
+
"task_resumed",
|
|
2365
|
+
"task_ended",
|
|
2366
|
+
"learning_captured",
|
|
2367
|
+
"pulse_recorded",
|
|
2368
|
+
"file_changed",
|
|
2369
|
+
"session_connected",
|
|
2370
|
+
"session_disconnected",
|
|
2371
|
+
"ceremony_blocked",
|
|
2372
|
+
"ceremony_completed"
|
|
2373
|
+
]);
|
|
2374
|
+
z.object({
|
|
2375
|
+
/** Monotonic integer ID */
|
|
2376
|
+
id: z.number().int().positive(),
|
|
2377
|
+
/** Task this event belongs to */
|
|
2378
|
+
taskId: z.number().int().positive(),
|
|
2379
|
+
/** Sequence number within task (monotonically increasing) */
|
|
2380
|
+
seq: z.number().int().nonnegative(),
|
|
2381
|
+
/** Type of event */
|
|
2382
|
+
type: TaskEventTypeSchema,
|
|
2383
|
+
/** JSON-serialized event payload */
|
|
2384
|
+
payloadJson: z.string().nullable(),
|
|
2385
|
+
/** ISO 8601 timestamp when event occurred */
|
|
2386
|
+
timestamp: z.string().datetime()
|
|
2387
|
+
});
|
|
2388
|
+
var FileActionSchema = z.enum([
|
|
2389
|
+
"added",
|
|
2390
|
+
"modified",
|
|
2391
|
+
"deleted"
|
|
2392
|
+
]);
|
|
2393
|
+
var TaskFileSchema = z.object({
|
|
2394
|
+
/** Monotonic integer ID */
|
|
2395
|
+
id: z.number().int().positive(),
|
|
2396
|
+
/** Task this file change belongs to */
|
|
2397
|
+
taskId: z.number().int().positive(),
|
|
2398
|
+
/** Relative POSIX path from workspace root */
|
|
2399
|
+
path: z.string().min(1),
|
|
2400
|
+
/** Type of file operation */
|
|
2401
|
+
action: FileActionSchema,
|
|
2402
|
+
/** SHA-256 hash before change (null for added files) */
|
|
2403
|
+
hashBefore: z.string().nullable(),
|
|
2404
|
+
/** SHA-256 hash after change (null for deleted files) */
|
|
2405
|
+
hashAfter: z.string().nullable(),
|
|
2406
|
+
/** ISO 8601 timestamp when change was detected */
|
|
2407
|
+
timestamp: z.string().datetime()
|
|
2408
|
+
});
|
|
2409
|
+
var LearningCategorySchema = z.enum([
|
|
2410
|
+
"pattern",
|
|
2411
|
+
"gotcha",
|
|
2412
|
+
"decision",
|
|
2413
|
+
"convention",
|
|
2414
|
+
"discovery"
|
|
2415
|
+
]);
|
|
2416
|
+
var LearningConfidenceSchema = z.enum([
|
|
2417
|
+
"low",
|
|
2418
|
+
"medium",
|
|
2419
|
+
"high"
|
|
2420
|
+
]);
|
|
2421
|
+
var TaskLearningSchema = z.object({
|
|
2422
|
+
/** Monotonic integer ID */
|
|
2423
|
+
id: z.number().int().positive(),
|
|
2424
|
+
/** Task this learning belongs to */
|
|
2425
|
+
taskId: z.number().int().positive(),
|
|
2426
|
+
/** SHA-256 hash of content for deduplication */
|
|
2427
|
+
contentHash: z.string().min(1),
|
|
2428
|
+
/** The actual learning content */
|
|
2429
|
+
content: z.string().min(1),
|
|
2430
|
+
/** Where this learning came from */
|
|
2431
|
+
source: z.string().nullable(),
|
|
2432
|
+
/** Confidence level of the insight */
|
|
2433
|
+
confidence: LearningConfidenceSchema,
|
|
2434
|
+
/** ISO 8601 timestamp when learning was captured */
|
|
2435
|
+
timestamp: z.string().datetime()
|
|
2436
|
+
});
|
|
2437
|
+
z.object({
|
|
2438
|
+
/** Monotonic integer ID */
|
|
2439
|
+
id: z.number().int().positive(),
|
|
2440
|
+
/** Task this session belongs to */
|
|
2441
|
+
taskId: z.number().int().positive(),
|
|
2442
|
+
/** Unique session identifier (UUID) */
|
|
2443
|
+
sessionId: z.string().min(1),
|
|
2444
|
+
/** ISO 8601 timestamp when session connected */
|
|
2445
|
+
connectedAt: z.string().datetime(),
|
|
2446
|
+
/** ISO 8601 timestamp when session disconnected (null if active) */
|
|
2447
|
+
disconnectedAt: z.string().datetime().nullable()
|
|
2448
|
+
});
|
|
2449
|
+
var CeremonyMetricsSchema = z.object({
|
|
2450
|
+
/** Number of unique files modified */
|
|
2451
|
+
filesModified: z.number().int().nonnegative(),
|
|
2452
|
+
/** Number of unique files created */
|
|
2453
|
+
filesCreated: z.number().int().nonnegative(),
|
|
2454
|
+
/** Number of files deleted */
|
|
2455
|
+
filesDeleted: z.number().int().nonnegative(),
|
|
2456
|
+
/** Number of learnings captured */
|
|
2457
|
+
learningsCaptured: z.number().int().nonnegative(),
|
|
2458
|
+
/** Number of pulse snapshots recorded */
|
|
2459
|
+
pulsesRecorded: z.number().int().nonnegative(),
|
|
2460
|
+
/** Number of sessions that connected to this task */
|
|
2461
|
+
sessionsCount: z.number().int().nonnegative(),
|
|
2462
|
+
/** Total file operations (sum of all actions) */
|
|
2463
|
+
totalFileOperations: z.number().int().nonnegative()
|
|
2464
|
+
});
|
|
2465
|
+
var CeremonyDurationSchema = z.object({
|
|
2466
|
+
/** ISO 8601 timestamp of first session start */
|
|
2467
|
+
firstSessionStart: z.string().datetime(),
|
|
2468
|
+
/** ISO 8601 timestamp of last session end */
|
|
2469
|
+
lastSessionEnd: z.string().datetime().nullable(),
|
|
2470
|
+
/** Total active time in milliseconds */
|
|
2471
|
+
totalActiveTimeMs: z.number().int().nonnegative()
|
|
2472
|
+
});
|
|
2473
|
+
var QualityGateStatusSchema = z.object({
|
|
2474
|
+
/** Whether all required gates passed */
|
|
2475
|
+
allPassed: z.boolean(),
|
|
2476
|
+
/** Whether audit passed */
|
|
2477
|
+
auditPassed: z.boolean().nullable(),
|
|
2478
|
+
/** Whether lint is clean */
|
|
2479
|
+
lintClean: z.boolean().nullable(),
|
|
2480
|
+
/** Whether tests pass */
|
|
2481
|
+
testsPass: z.boolean().nullable()
|
|
2482
|
+
});
|
|
2483
|
+
var CeremonySchema = z.object({
|
|
2484
|
+
/** Task ID */
|
|
2485
|
+
taskId: z.number().int().positive(),
|
|
2486
|
+
/** Human-readable task name */
|
|
2487
|
+
taskName: z.string().min(1),
|
|
2488
|
+
/** Deterministic slug */
|
|
2489
|
+
slug: z.string().min(1),
|
|
2490
|
+
/** How the task ended */
|
|
2491
|
+
outcome: TaskOutcomeSchema,
|
|
2492
|
+
/** Duration information */
|
|
2493
|
+
duration: CeremonyDurationSchema,
|
|
2494
|
+
/** Derived metrics from accumulated state */
|
|
2495
|
+
metrics: CeremonyMetricsSchema,
|
|
2496
|
+
/** All learnings captured during this task */
|
|
2497
|
+
learnings: z.array(TaskLearningSchema),
|
|
2498
|
+
/** Complete file change log */
|
|
2499
|
+
fileChanges: z.array(TaskFileSchema),
|
|
2500
|
+
/** Quality gate results from most recent pulse */
|
|
2501
|
+
qualityGates: QualityGateStatusSchema,
|
|
2502
|
+
/** LLM-generated summary for context injection into future tasks */
|
|
2503
|
+
briefingForNextTask: z.string().nullable()
|
|
2504
|
+
});
|
|
2505
|
+
var BriefingModeSchema = z.enum([
|
|
2506
|
+
"standard",
|
|
2507
|
+
"comprehensive"
|
|
2508
|
+
]);
|
|
2509
|
+
var BriefingSchema = z.object({
|
|
2510
|
+
/** Summary of most recent completed task's ceremony (1-2 paragraphs) */
|
|
2511
|
+
recentCeremonySummary: z.string().nullable(),
|
|
2512
|
+
/** Top 5 most recent learnings from across all tasks */
|
|
2513
|
+
recentLearnings: z.array(TaskLearningSchema).max(5),
|
|
2514
|
+
/** Any active warnings or known issues from the project */
|
|
2515
|
+
activeWarnings: z.array(z.string()),
|
|
2516
|
+
/** Full ceremony from continued task (if continues parameter provided) */
|
|
2517
|
+
continuedCeremony: CeremonySchema.nullable(),
|
|
2518
|
+
/** Lineage chain (task IDs this task continues from) */
|
|
2519
|
+
lineageChain: z.array(z.number().int().positive())
|
|
2520
|
+
});
|
|
2521
|
+
z.object({
|
|
2522
|
+
/** Human-readable task name from LLM */
|
|
2523
|
+
taskName: z.string().min(1).max(256)
|
|
2524
|
+
});
|
|
2525
|
+
z.object({
|
|
2526
|
+
/** Generated kebab-case slug */
|
|
2527
|
+
slug: z.string().min(1).max(64),
|
|
2528
|
+
/** Whether a counter suffix was added for uniqueness */
|
|
2529
|
+
hasCounterSuffix: z.boolean(),
|
|
2530
|
+
/** Counter value if suffix was added (null otherwise) */
|
|
2531
|
+
counterValue: z.number().int().positive().nullable()
|
|
2532
|
+
});
|
|
2533
|
+
z.object({
|
|
2534
|
+
/** Human-readable task name. SnapBack generates a deterministic slug for matching. */
|
|
2535
|
+
task: z.string().min(1).max(256),
|
|
2536
|
+
/** Task ID or slug of a completed task that this new task continues. */
|
|
2537
|
+
continues: z.string().optional(),
|
|
2538
|
+
/** Level of context to include in the briefing. Default "standard". */
|
|
2539
|
+
mode: BriefingModeSchema.default("standard")
|
|
2540
|
+
});
|
|
2541
|
+
z.object({
|
|
2542
|
+
/** Task ID */
|
|
2543
|
+
taskId: z.number().int().positive(),
|
|
2544
|
+
/** Deterministic slug */
|
|
2545
|
+
slug: z.string().min(1),
|
|
2546
|
+
/** Human-readable task name */
|
|
2547
|
+
name: z.string().min(1),
|
|
2548
|
+
/** Current status */
|
|
2549
|
+
status: TaskStatusSchema,
|
|
2550
|
+
/** Whether this was a resume of an existing task */
|
|
2551
|
+
resumed: z.boolean(),
|
|
2552
|
+
/** Slug of auto-ended task (if any) */
|
|
2553
|
+
autoEnded: z.string().nullable(),
|
|
2554
|
+
/** Contextual briefing from recent work history */
|
|
2555
|
+
briefing: BriefingSchema,
|
|
2556
|
+
/** Number of sessions that have connected to this task */
|
|
2557
|
+
sessionsCount: z.number().int().nonnegative()
|
|
2558
|
+
});
|
|
2559
|
+
var PulseFocusSchema = z.enum([
|
|
2560
|
+
"vitals",
|
|
2561
|
+
"advice"
|
|
2562
|
+
]);
|
|
2563
|
+
var PulseEnrichmentSchema = z.object({
|
|
2564
|
+
/** Patterns, concerns the LLM noticed */
|
|
2565
|
+
observations: z.array(z.string()).optional(),
|
|
2566
|
+
/** Confidence in observations */
|
|
2567
|
+
confidence: LearningConfidenceSchema.optional()
|
|
2568
|
+
});
|
|
2569
|
+
z.object({
|
|
2570
|
+
/** What to focus on. "vitals" returns workspace health diagnostics.
|
|
2571
|
+
* "advice" returns proactive recommendations based on current task context. */
|
|
2572
|
+
focus: PulseFocusSchema.default("vitals"),
|
|
2573
|
+
/** When focus is "advice", a specific question or area.
|
|
2574
|
+
* When focus is "vitals", optional hint about what to prioritize. */
|
|
2575
|
+
query: z.string().optional(),
|
|
2576
|
+
/** LLM-observed context to attach. Additive, not replacing. */
|
|
2577
|
+
enrichment: PulseEnrichmentSchema.optional()
|
|
2578
|
+
});
|
|
2579
|
+
var WorkspaceVitalsSchema = z.object({
|
|
2580
|
+
/** Whether configured tests pass */
|
|
2581
|
+
testsPass: z.boolean().nullable(),
|
|
2582
|
+
/** Whether lint is clean */
|
|
2583
|
+
lintClean: z.boolean().nullable(),
|
|
2584
|
+
/** Whether typecheck passes */
|
|
2585
|
+
typecheckPass: z.boolean().nullable(),
|
|
2586
|
+
/** Git branch name */
|
|
2587
|
+
gitBranch: z.string().nullable(),
|
|
2588
|
+
/** Whether there are uncommitted changes */
|
|
2589
|
+
hasUncommittedChanges: z.boolean(),
|
|
2590
|
+
/** Number of modified files (from git status) */
|
|
2591
|
+
modifiedFilesCount: z.number().int().nonnegative(),
|
|
2592
|
+
/** Error details if any check failed */
|
|
2593
|
+
errorDetails: z.string().nullable()
|
|
2594
|
+
});
|
|
2595
|
+
z.object({
|
|
2596
|
+
/** Whether there is an active task */
|
|
2597
|
+
hasActiveTask: z.boolean(),
|
|
2598
|
+
/** Task ID if active */
|
|
2599
|
+
taskId: z.number().int().positive().nullable(),
|
|
2600
|
+
/** Daemon-collected workspace vitals */
|
|
2601
|
+
vitals: WorkspaceVitalsSchema,
|
|
2602
|
+
/** Whether task is flagged as stale (inactivity timeout exceeded) */
|
|
2603
|
+
isStale: z.boolean(),
|
|
2604
|
+
/** Proactive recommendations (when focus is "advice") */
|
|
2605
|
+
recommendations: z.array(z.string()).optional(),
|
|
2606
|
+
/** Pulse sequence number for this task */
|
|
2607
|
+
pulseSeq: z.number().int().nonnegative()
|
|
2608
|
+
});
|
|
2609
|
+
z.object({
|
|
2610
|
+
/** The learning to capture. Should be a concrete, actionable insight. */
|
|
2611
|
+
insight: z.string().min(1),
|
|
2612
|
+
/** Classification of the learning. Default: inferred by the daemon. */
|
|
2613
|
+
category: LearningCategorySchema.optional(),
|
|
2614
|
+
/** Where this learning came from. Default: "llm-observation". */
|
|
2615
|
+
source: z.string().optional(),
|
|
2616
|
+
/** How confident the LLM is in this insight. Default: "medium". */
|
|
2617
|
+
confidence: LearningConfidenceSchema.default("medium")
|
|
2618
|
+
});
|
|
2619
|
+
z.object({
|
|
2620
|
+
/** Learning ID */
|
|
2621
|
+
learningId: z.number().int().positive(),
|
|
2622
|
+
/** Content hash for deduplication */
|
|
2623
|
+
contentHash: z.string().min(1),
|
|
2624
|
+
/** Whether this was a new learning or duplicate */
|
|
2625
|
+
isNew: z.boolean(),
|
|
2626
|
+
/** Total learnings count for this task */
|
|
2627
|
+
taskLearningsCount: z.number().int().nonnegative()
|
|
2628
|
+
});
|
|
2629
|
+
var SnapbackEndFeedbackSchema = z.object({
|
|
2630
|
+
/** Rating 1-5 */
|
|
2631
|
+
rating: z.number().int().min(1).max(5),
|
|
2632
|
+
/** Optional notes */
|
|
2633
|
+
notes: z.string().optional()
|
|
2634
|
+
});
|
|
2635
|
+
z.object({
|
|
2636
|
+
/** How the task ended */
|
|
2637
|
+
outcome: TaskOutcomeSchema,
|
|
2638
|
+
/** LLM's summary of what was accomplished. Included in ceremony. */
|
|
2639
|
+
summary: z.string().optional(),
|
|
2640
|
+
/** Bypass quality gate blocks. Not recommended. */
|
|
2641
|
+
force: z.boolean().default(false),
|
|
2642
|
+
/** User/LLM feedback on the task experience */
|
|
2643
|
+
feedback: SnapbackEndFeedbackSchema.optional()
|
|
2644
|
+
});
|
|
2645
|
+
z.object({
|
|
2646
|
+
/** Whether the ceremony was blocked by quality gates */
|
|
2647
|
+
blocked: z.boolean(),
|
|
2648
|
+
/** The produced ceremony (null if blocked and force=false) */
|
|
2649
|
+
ceremony: CeremonySchema.nullable(),
|
|
2650
|
+
/** Quality gate failures if blocked */
|
|
2651
|
+
gateFailures: z.object({
|
|
2652
|
+
testsPass: z.boolean().optional(),
|
|
2653
|
+
lintClean: z.boolean().optional(),
|
|
2654
|
+
auditPassed: z.boolean().optional()
|
|
2655
|
+
}).nullable(),
|
|
2656
|
+
/** Instructions to resolve blockage */
|
|
2657
|
+
resolution: z.string().nullable()
|
|
2658
|
+
});
|
|
2659
|
+
var ConfigFileTypeSchema = z.enum([
|
|
2660
|
+
"package",
|
|
2661
|
+
"typescript",
|
|
2662
|
+
"linting",
|
|
2663
|
+
"build",
|
|
2664
|
+
"environment",
|
|
2665
|
+
"testing",
|
|
2666
|
+
"framework",
|
|
2667
|
+
"database",
|
|
2668
|
+
"ci"
|
|
2669
|
+
]);
|
|
2670
|
+
var SupportedLanguageSchema = z.enum([
|
|
2671
|
+
"javascript",
|
|
2672
|
+
"typescript",
|
|
2673
|
+
"python",
|
|
2674
|
+
"universal"
|
|
2675
|
+
]);
|
|
2676
|
+
var FileBaselineSchema = z.object({
|
|
2677
|
+
path: z.string(),
|
|
2678
|
+
hash: z.string(),
|
|
2679
|
+
timestamp: z.number(),
|
|
2680
|
+
size: z.number()
|
|
2681
|
+
});
|
|
2682
|
+
z.object({
|
|
2683
|
+
path: z.string(),
|
|
2684
|
+
type: ConfigFileTypeSchema,
|
|
2685
|
+
language: SupportedLanguageSchema,
|
|
2686
|
+
critical: z.boolean().default(false),
|
|
2687
|
+
baseline: FileBaselineSchema.optional()
|
|
2688
|
+
});
|
|
2689
|
+
z.object({
|
|
2690
|
+
type: z.string(),
|
|
2691
|
+
path: z.string(),
|
|
2692
|
+
name: z.string(),
|
|
2693
|
+
critical: z.boolean().default(false)
|
|
2694
|
+
});
|
|
2695
|
+
z.object({
|
|
2696
|
+
content: z.any(),
|
|
2697
|
+
valid: z.boolean(),
|
|
2698
|
+
error: z.string().optional(),
|
|
2699
|
+
metadata: z.record(z.string(), z.any()).optional()
|
|
2700
|
+
});
|
|
2701
|
+
z.object({
|
|
2702
|
+
valid: z.boolean(),
|
|
2703
|
+
errors: z.array(z.string()).default([]),
|
|
2704
|
+
warnings: z.array(z.string()).default([])
|
|
2705
|
+
});
|
|
2706
|
+
z.object({
|
|
2707
|
+
type: z.enum([
|
|
2708
|
+
"added",
|
|
2709
|
+
"modified",
|
|
2710
|
+
"deleted"
|
|
2711
|
+
]),
|
|
2712
|
+
file: z.string(),
|
|
2713
|
+
timestamp: z.number(),
|
|
2714
|
+
baseline: FileBaselineSchema.optional()
|
|
2715
|
+
});
|
|
2716
|
+
z.object({
|
|
2717
|
+
autoDetect: z.boolean().default(true),
|
|
2718
|
+
watchChanges: z.boolean().default(true),
|
|
2719
|
+
autoProtect: z.boolean().default(true),
|
|
2720
|
+
customPatterns: z.array(z.any()).optional()
|
|
2721
|
+
});
|
|
2722
|
+
z.object({
|
|
2723
|
+
enabled: z.boolean(),
|
|
2724
|
+
patterns: z.array(z.string()).optional(),
|
|
2725
|
+
threshold: z.number().optional(),
|
|
2726
|
+
includePatterns: z.array(z.string()).optional(),
|
|
2727
|
+
excludePatterns: z.array(z.string()).optional()
|
|
2728
|
+
});
|
|
2729
|
+
var ProtectionLevelSchema = z.enum([
|
|
2730
|
+
"watch",
|
|
2731
|
+
"warn",
|
|
2732
|
+
"block"
|
|
2733
|
+
]);
|
|
2734
|
+
z.object({
|
|
2735
|
+
level: ProtectionLevelSchema,
|
|
2736
|
+
icon: z.string(),
|
|
2737
|
+
label: z.string(),
|
|
2738
|
+
description: z.string(),
|
|
2739
|
+
color: z.string(),
|
|
2740
|
+
themeColor: z.string().optional()
|
|
2741
|
+
});
|
|
2742
|
+
var ProtectedFileSchema = z.object({
|
|
2743
|
+
path: z.string(),
|
|
2744
|
+
level: ProtectionLevelSchema,
|
|
2745
|
+
reason: z.string().optional(),
|
|
2746
|
+
addedAt: z.date(),
|
|
2747
|
+
pattern: z.string().optional()
|
|
2748
|
+
});
|
|
2749
|
+
var PatternRuleSchema = z.object({
|
|
2750
|
+
pattern: z.string(),
|
|
2751
|
+
level: ProtectionLevelSchema,
|
|
2752
|
+
reason: z.string().optional(),
|
|
2753
|
+
enabled: z.boolean().default(true)
|
|
2754
|
+
});
|
|
2755
|
+
var ProtectionConfigSchema = z.object({
|
|
2756
|
+
patterns: z.array(PatternRuleSchema).default([]),
|
|
2757
|
+
defaultLevel: ProtectionLevelSchema.default("watch"),
|
|
2758
|
+
enabled: z.boolean().default(true),
|
|
2759
|
+
autoProtectConfigs: z.boolean().default(true)
|
|
2760
|
+
});
|
|
2761
|
+
z.object({
|
|
2762
|
+
config: ProtectionConfigSchema.optional(),
|
|
2763
|
+
persistRegistry: z.boolean().default(true),
|
|
2764
|
+
registryPath: z.string().optional()
|
|
2765
|
+
});
|
|
2766
|
+
z.object({
|
|
2767
|
+
isProtected: z.boolean(),
|
|
2768
|
+
level: ProtectionLevelSchema.optional(),
|
|
2769
|
+
reason: z.string().optional(),
|
|
2770
|
+
file: ProtectedFileSchema.optional()
|
|
2771
|
+
});
|
|
2772
|
+
var DEFAULT_CRITICAL_PATTERNS = Object.freeze([
|
|
2773
|
+
// Dependency locks - wrong versions break builds
|
|
2774
|
+
{
|
|
2775
|
+
pattern: "**/package-lock.json",
|
|
2776
|
+
level: "block",
|
|
2777
|
+
reason: "Lock file - wrong version breaks reproducible Node.js builds"
|
|
2778
|
+
},
|
|
2779
|
+
{
|
|
2780
|
+
pattern: "**/yarn.lock",
|
|
2781
|
+
level: "block",
|
|
2782
|
+
reason: "Lock file - ensures reproducible Yarn installs"
|
|
2783
|
+
},
|
|
2784
|
+
{
|
|
2785
|
+
pattern: "**/pnpm-lock.yaml",
|
|
2786
|
+
level: "block",
|
|
2787
|
+
reason: "Lock file - critical for pnpm monorepos"
|
|
2788
|
+
},
|
|
2789
|
+
{
|
|
2790
|
+
pattern: "**/poetry.lock",
|
|
2791
|
+
level: "block",
|
|
2792
|
+
reason: "Lock file - Python dependency lock"
|
|
2793
|
+
},
|
|
2794
|
+
{
|
|
2795
|
+
pattern: "**/Cargo.lock",
|
|
2796
|
+
level: "block",
|
|
2797
|
+
reason: "Lock file - Rust dependency lock"
|
|
2798
|
+
},
|
|
2799
|
+
{
|
|
2800
|
+
pattern: "**/go.sum",
|
|
2801
|
+
level: "block",
|
|
2802
|
+
reason: "Lock file - Go module checksums"
|
|
2803
|
+
},
|
|
2804
|
+
{
|
|
2805
|
+
pattern: "**/Gemfile.lock",
|
|
2806
|
+
level: "block",
|
|
2807
|
+
reason: "Lock file - Ruby gem dependencies"
|
|
2808
|
+
},
|
|
2809
|
+
{
|
|
2810
|
+
pattern: "**/composer.lock",
|
|
2811
|
+
level: "block",
|
|
2812
|
+
reason: "Lock file - PHP composer dependencies"
|
|
2813
|
+
},
|
|
2814
|
+
// Environment & Secrets - exposing causes immediate security breaches
|
|
2815
|
+
{
|
|
2816
|
+
pattern: "**/.env*",
|
|
2817
|
+
level: "block",
|
|
2818
|
+
reason: "Sensitive environment variables and secrets"
|
|
2819
|
+
},
|
|
2820
|
+
// Core configuration files - wrong changes break builds
|
|
2821
|
+
{
|
|
2822
|
+
pattern: "package.json",
|
|
2823
|
+
level: "warn",
|
|
2824
|
+
reason: "Core Node.js configuration - dependencies and scripts"
|
|
2825
|
+
},
|
|
2826
|
+
{
|
|
2827
|
+
pattern: "tsconfig.json",
|
|
2828
|
+
level: "warn",
|
|
2829
|
+
reason: "TypeScript compiler configuration"
|
|
2830
|
+
},
|
|
2831
|
+
// Infrastructure - controls deployment and infrastructure
|
|
2832
|
+
{
|
|
2833
|
+
pattern: "Dockerfile",
|
|
2834
|
+
level: "warn",
|
|
2835
|
+
reason: "Container image definition"
|
|
2836
|
+
},
|
|
2837
|
+
{
|
|
2838
|
+
pattern: "docker-compose.yml",
|
|
2839
|
+
level: "warn",
|
|
2840
|
+
reason: "Multi-container orchestration"
|
|
2841
|
+
},
|
|
2842
|
+
{
|
|
2843
|
+
pattern: "**/docker-compose.yaml",
|
|
2844
|
+
level: "warn",
|
|
2845
|
+
reason: "Multi-container orchestration (yaml variant)"
|
|
2846
|
+
},
|
|
2847
|
+
{
|
|
2848
|
+
pattern: "**/*.tf",
|
|
2849
|
+
level: "warn",
|
|
2850
|
+
reason: "Terraform infrastructure definitions"
|
|
2851
|
+
},
|
|
2852
|
+
{
|
|
2853
|
+
pattern: ".github/workflows/*.yml",
|
|
2854
|
+
level: "warn",
|
|
2855
|
+
reason: "GitHub Actions CI/CD workflows"
|
|
2856
|
+
},
|
|
2857
|
+
{
|
|
2858
|
+
pattern: ".github/workflows/*.yaml",
|
|
2859
|
+
level: "warn",
|
|
2860
|
+
reason: "GitHub Actions CI/CD workflows (yaml variant)"
|
|
2861
|
+
}
|
|
2862
|
+
]);
|
|
2863
|
+
var EXTENDED_PATTERNS = Object.freeze([
|
|
2864
|
+
// Documentation - passive watching
|
|
2865
|
+
{
|
|
2866
|
+
pattern: "*.md",
|
|
2867
|
+
level: "watch",
|
|
2868
|
+
reason: "Documentation files"
|
|
2869
|
+
},
|
|
2870
|
+
{
|
|
2871
|
+
pattern: "*.txt",
|
|
2872
|
+
level: "watch",
|
|
2873
|
+
reason: "Text files"
|
|
2874
|
+
},
|
|
2875
|
+
{
|
|
2876
|
+
pattern: "README*",
|
|
2877
|
+
level: "watch",
|
|
2878
|
+
reason: "README documentation"
|
|
2879
|
+
},
|
|
2880
|
+
// General configuration files
|
|
2881
|
+
{
|
|
2882
|
+
pattern: "*.json",
|
|
2883
|
+
level: "watch",
|
|
2884
|
+
reason: "JSON configuration files"
|
|
2885
|
+
},
|
|
2886
|
+
{
|
|
2887
|
+
pattern: ".editorconfig",
|
|
2888
|
+
level: "watch",
|
|
2889
|
+
reason: "Editor configuration"
|
|
2890
|
+
},
|
|
2891
|
+
{
|
|
2892
|
+
pattern: ".prettierrc*",
|
|
2893
|
+
level: "watch",
|
|
2894
|
+
reason: "Prettier formatting configuration"
|
|
2895
|
+
},
|
|
2896
|
+
{
|
|
2897
|
+
pattern: ".eslintrc*",
|
|
2898
|
+
level: "watch",
|
|
2899
|
+
reason: "ESLint configuration"
|
|
2900
|
+
},
|
|
2901
|
+
{
|
|
2902
|
+
pattern: ".babelrc",
|
|
2903
|
+
level: "watch",
|
|
2904
|
+
reason: "Babel transpiler configuration"
|
|
2905
|
+
},
|
|
2906
|
+
{
|
|
2907
|
+
pattern: ".gitignore",
|
|
2908
|
+
level: "warn",
|
|
2909
|
+
reason: "Git ignore rules"
|
|
2910
|
+
},
|
|
2911
|
+
// IDE and editor settings
|
|
2912
|
+
{
|
|
2913
|
+
pattern: ".vscode/settings.json",
|
|
2914
|
+
level: "watch",
|
|
2915
|
+
reason: "VS Code settings"
|
|
2916
|
+
},
|
|
2917
|
+
{
|
|
2918
|
+
pattern: ".idea/**",
|
|
2919
|
+
level: "watch",
|
|
2920
|
+
reason: "IDE configuration directory"
|
|
2921
|
+
},
|
|
2922
|
+
// Build tool configurations
|
|
2923
|
+
{
|
|
2924
|
+
pattern: "vite.config.*",
|
|
2925
|
+
level: "warn",
|
|
2926
|
+
reason: "Vite bundler configuration"
|
|
2927
|
+
},
|
|
2928
|
+
{
|
|
2929
|
+
pattern: "webpack.config.*",
|
|
2930
|
+
level: "warn",
|
|
2931
|
+
reason: "Webpack bundler configuration"
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
pattern: "rollup.config.*",
|
|
2935
|
+
level: "warn",
|
|
2936
|
+
reason: "Rollup bundler configuration"
|
|
2937
|
+
},
|
|
2938
|
+
{
|
|
2939
|
+
pattern: "esbuild.config.*",
|
|
2940
|
+
level: "warn",
|
|
2941
|
+
reason: "esbuild bundler configuration"
|
|
2942
|
+
},
|
|
2943
|
+
{
|
|
2944
|
+
pattern: "Makefile",
|
|
2945
|
+
level: "watch",
|
|
2946
|
+
reason: "Make build configuration"
|
|
2947
|
+
},
|
|
2948
|
+
{
|
|
2949
|
+
pattern: "CMakeLists.txt",
|
|
2950
|
+
level: "watch",
|
|
2951
|
+
reason: "CMake build configuration"
|
|
2952
|
+
},
|
|
2953
|
+
// Language-specific package managers and configs
|
|
2954
|
+
{
|
|
2955
|
+
pattern: "requirements.txt",
|
|
2956
|
+
level: "watch",
|
|
2957
|
+
reason: "Python dependencies"
|
|
2958
|
+
},
|
|
2959
|
+
{
|
|
2960
|
+
pattern: "Gemfile",
|
|
2961
|
+
level: "warn",
|
|
2962
|
+
reason: "Ruby gem configuration"
|
|
2963
|
+
},
|
|
2964
|
+
{
|
|
2965
|
+
pattern: "composer.json",
|
|
2966
|
+
level: "warn",
|
|
2967
|
+
reason: "PHP composer configuration"
|
|
2968
|
+
},
|
|
2969
|
+
{
|
|
2970
|
+
pattern: "setup.py",
|
|
2971
|
+
level: "warn",
|
|
2972
|
+
reason: "Python package setup"
|
|
2973
|
+
},
|
|
2974
|
+
{
|
|
2975
|
+
pattern: "pyproject.toml",
|
|
2976
|
+
level: "warn",
|
|
2977
|
+
reason: "Python project configuration"
|
|
2978
|
+
},
|
|
2979
|
+
{
|
|
2980
|
+
pattern: "pom.xml",
|
|
2981
|
+
level: "warn",
|
|
2982
|
+
reason: "Maven Java build configuration"
|
|
2983
|
+
},
|
|
2984
|
+
{
|
|
2985
|
+
pattern: "build.gradle*",
|
|
2986
|
+
level: "warn",
|
|
2987
|
+
reason: "Gradle Java build configuration"
|
|
2988
|
+
},
|
|
2989
|
+
{
|
|
2990
|
+
pattern: "*.csproj",
|
|
2991
|
+
level: "warn",
|
|
2992
|
+
reason: ".NET C# project file"
|
|
2993
|
+
},
|
|
2994
|
+
{
|
|
2995
|
+
pattern: "go.mod",
|
|
2996
|
+
level: "warn",
|
|
2997
|
+
reason: "Go module definition"
|
|
2998
|
+
},
|
|
2999
|
+
{
|
|
3000
|
+
pattern: "Cargo.toml",
|
|
3001
|
+
level: "warn",
|
|
3002
|
+
reason: "Rust package configuration"
|
|
3003
|
+
},
|
|
3004
|
+
{
|
|
3005
|
+
pattern: "bunfig.toml",
|
|
3006
|
+
level: "warn",
|
|
3007
|
+
reason: "Bun runtime configuration"
|
|
3008
|
+
},
|
|
3009
|
+
{
|
|
3010
|
+
pattern: "*.sln",
|
|
3011
|
+
level: "watch",
|
|
3012
|
+
reason: "Visual Studio solution file"
|
|
3013
|
+
},
|
|
3014
|
+
// Kubernetes and container orchestration
|
|
3015
|
+
{
|
|
3016
|
+
pattern: "kubernetes/*.yaml",
|
|
3017
|
+
level: "warn",
|
|
3018
|
+
reason: "Kubernetes manifests"
|
|
3019
|
+
}
|
|
3020
|
+
]);
|
|
3021
|
+
Object.freeze([
|
|
3022
|
+
...DEFAULT_CRITICAL_PATTERNS,
|
|
3023
|
+
...EXTENDED_PATTERNS
|
|
3024
|
+
]);
|
|
3025
|
+
var SnapshotTriggerSchema = z.enum([
|
|
3026
|
+
"manual",
|
|
3027
|
+
"auto",
|
|
3028
|
+
"auto_save",
|
|
3029
|
+
"ai_detected",
|
|
3030
|
+
"ai-detected",
|
|
3031
|
+
"pre_save",
|
|
3032
|
+
"pre-save",
|
|
3033
|
+
"session_start",
|
|
3034
|
+
"session_end",
|
|
3035
|
+
"mcp_snap_start",
|
|
3036
|
+
"cli_protect",
|
|
3037
|
+
"api_request",
|
|
3038
|
+
"engine_internal",
|
|
3039
|
+
"recovery"
|
|
3040
|
+
]);
|
|
3041
|
+
var SnapshotOriginSchema = z.enum([
|
|
3042
|
+
"manual",
|
|
3043
|
+
"auto",
|
|
3044
|
+
"ai-detected",
|
|
3045
|
+
"recovery",
|
|
3046
|
+
"INTERACTIVE",
|
|
3047
|
+
"AUTOMATED"
|
|
3048
|
+
]);
|
|
3049
|
+
var SnapshotReasonCodeSchema = z.enum([
|
|
3050
|
+
// AI detection
|
|
3051
|
+
"AI_DETECTED",
|
|
3052
|
+
// Manual operations
|
|
3053
|
+
"MANUAL_CHECKPOINT",
|
|
3054
|
+
"MANUAL_SAVE",
|
|
3055
|
+
// Risk-based triggers
|
|
3056
|
+
"CRITICAL_FILE",
|
|
3057
|
+
"HIGH_RISK",
|
|
3058
|
+
"RISK_BURST_START",
|
|
3059
|
+
"RISK_LARGE_DELETE",
|
|
3060
|
+
"RISK_MULTI_FILE",
|
|
3061
|
+
// Session lifecycle
|
|
3062
|
+
"SESSION_START",
|
|
3063
|
+
"SESSION_END",
|
|
3064
|
+
"IDLE_FINALIZE",
|
|
3065
|
+
// Rollback operations
|
|
3066
|
+
"PRE_ROLLBACK",
|
|
3067
|
+
// Optimization modes
|
|
3068
|
+
"BURST_MODE"
|
|
3069
|
+
]);
|
|
3070
|
+
var CheckpointTypeSchema = z.enum([
|
|
3071
|
+
"PRE",
|
|
3072
|
+
"POST",
|
|
3073
|
+
"PRE_ROLLBACK"
|
|
3074
|
+
]);
|
|
3075
|
+
var SnapshotSchema = z.object({
|
|
3076
|
+
id: z.string(),
|
|
3077
|
+
timestamp: z.number(),
|
|
3078
|
+
version: z.string().optional().default("1.0"),
|
|
3079
|
+
meta: z.record(z.string(), z.any()).optional(),
|
|
3080
|
+
files: z.array(z.string()).optional(),
|
|
3081
|
+
fileContents: z.record(z.string(), z.string()).optional()
|
|
3082
|
+
});
|
|
3083
|
+
var FileStateSchema = z.object({
|
|
3084
|
+
path: z.string(),
|
|
3085
|
+
content: z.string(),
|
|
3086
|
+
/** SHA-256 hash of content (optional, computed for dedup) */
|
|
3087
|
+
hash: z.string().optional(),
|
|
3088
|
+
/** File size in bytes */
|
|
3089
|
+
size: z.number().optional(),
|
|
3090
|
+
/** Encrypted data (for sensitive files - VSCode format) */
|
|
3091
|
+
encrypted: z.object({
|
|
3092
|
+
/** Initialization vector */
|
|
3093
|
+
iv: z.string(),
|
|
3094
|
+
/** Authentication tag */
|
|
3095
|
+
tag: z.string(),
|
|
3096
|
+
/** Optional: algorithm used (default: aes-256-gcm) */
|
|
3097
|
+
algorithm: z.string().optional()
|
|
3098
|
+
}).optional()
|
|
3099
|
+
});
|
|
3100
|
+
var CompressionCodecSchema = z.enum([
|
|
3101
|
+
"zstd",
|
|
3102
|
+
"gzip",
|
|
3103
|
+
"none"
|
|
3104
|
+
]);
|
|
3105
|
+
var SnapshotFileRefV2Schema = z.object({
|
|
3106
|
+
/** SHA-256 hash of file content (CAS reference) */
|
|
3107
|
+
blobHash: z.string(),
|
|
3108
|
+
/** File size in bytes */
|
|
3109
|
+
size: z.number(),
|
|
3110
|
+
/** Compression codec used (optional, defaults to 'none') */
|
|
3111
|
+
codec: CompressionCodecSchema.optional()
|
|
3112
|
+
});
|
|
3113
|
+
z.object({
|
|
3114
|
+
id: z.string(),
|
|
3115
|
+
timestamp: z.number(),
|
|
3116
|
+
files: z.array(FileStateSchema)
|
|
3117
|
+
});
|
|
3118
|
+
z.enum([
|
|
3119
|
+
"pending",
|
|
3120
|
+
"complete",
|
|
3121
|
+
"failed",
|
|
3122
|
+
"deleted"
|
|
3123
|
+
]);
|
|
3124
|
+
SnapshotSchema.extend({
|
|
3125
|
+
name: z.string(),
|
|
3126
|
+
fileStates: z.array(FileStateSchema).optional(),
|
|
3127
|
+
isProtected: z.boolean(),
|
|
3128
|
+
icon: z.string().optional(),
|
|
3129
|
+
iconColor: z.string().optional()
|
|
3130
|
+
});
|
|
3131
|
+
z.object({
|
|
3132
|
+
id: z.string(),
|
|
3133
|
+
name: z.string(),
|
|
3134
|
+
timestamp: z.number(),
|
|
3135
|
+
fileCount: z.number(),
|
|
3136
|
+
origin: SnapshotOriginSchema.optional(),
|
|
3137
|
+
isProtected: z.boolean(),
|
|
3138
|
+
label: z.string().optional()
|
|
3139
|
+
});
|
|
3140
|
+
z.object({
|
|
3141
|
+
path: z.string(),
|
|
3142
|
+
content: z.string(),
|
|
3143
|
+
action: z.enum([
|
|
3144
|
+
"add",
|
|
3145
|
+
"modify",
|
|
3146
|
+
"delete"
|
|
3147
|
+
])
|
|
3148
|
+
});
|
|
3149
|
+
z.object({
|
|
3150
|
+
/** Description/reason for the snapshot */
|
|
3151
|
+
description: z.string().optional(),
|
|
3152
|
+
/** Whether to protect from auto-deletion */
|
|
3153
|
+
protected: z.boolean().optional(),
|
|
3154
|
+
/** What triggered the snapshot */
|
|
3155
|
+
trigger: SnapshotTriggerSchema.optional(),
|
|
3156
|
+
/** Origin classification for DORA metrics */
|
|
3157
|
+
origin: SnapshotOriginSchema.optional(),
|
|
3158
|
+
/** Time since last file change in ms (DORA lead time metric) */
|
|
3159
|
+
timeSinceLastChangeMs: z.number().optional()
|
|
3160
|
+
});
|
|
3161
|
+
z.object({
|
|
3162
|
+
filePath: z.string().optional(),
|
|
3163
|
+
before: z.date().optional(),
|
|
3164
|
+
after: z.date().optional(),
|
|
3165
|
+
protected: z.boolean().optional(),
|
|
3166
|
+
limit: z.number().int().positive().optional(),
|
|
3167
|
+
offset: z.number().int().nonnegative().optional()
|
|
3168
|
+
});
|
|
3169
|
+
var FileDiffSchema = z.object({
|
|
3170
|
+
path: z.string(),
|
|
3171
|
+
operation: z.enum([
|
|
3172
|
+
"create",
|
|
3173
|
+
"modify",
|
|
3174
|
+
"delete"
|
|
3175
|
+
]),
|
|
3176
|
+
linesAdded: z.number(),
|
|
3177
|
+
linesRemoved: z.number(),
|
|
3178
|
+
preview: z.string(),
|
|
3179
|
+
currentChecksum: z.string().optional(),
|
|
3180
|
+
snapshotChecksum: z.string().optional()
|
|
3181
|
+
});
|
|
3182
|
+
var DiffPreviewSchema = z.object({
|
|
3183
|
+
totalFiles: z.number(),
|
|
3184
|
+
filesCreated: z.number(),
|
|
3185
|
+
filesModified: z.number(),
|
|
3186
|
+
filesDeleted: z.number(),
|
|
3187
|
+
totalLinesAdded: z.number(),
|
|
3188
|
+
totalLinesRemoved: z.number(),
|
|
3189
|
+
diffs: z.array(FileDiffSchema)
|
|
3190
|
+
});
|
|
3191
|
+
var ConflictReportSchema = z.object({
|
|
3192
|
+
path: z.string(),
|
|
3193
|
+
reason: z.string(),
|
|
3194
|
+
currentChecksum: z.string(),
|
|
3195
|
+
snapshotChecksum: z.string()
|
|
3196
|
+
});
|
|
3197
|
+
z.object({
|
|
3198
|
+
success: z.boolean(),
|
|
3199
|
+
restoredFiles: z.array(z.string()),
|
|
3200
|
+
errors: z.array(z.string()).optional(),
|
|
3201
|
+
diffPreview: DiffPreviewSchema.optional(),
|
|
3202
|
+
conflicts: z.array(ConflictReportSchema).optional(),
|
|
3203
|
+
verification: z.object({
|
|
3204
|
+
allVerified: z.boolean(),
|
|
3205
|
+
results: z.array(z.object({
|
|
3206
|
+
path: z.string(),
|
|
3207
|
+
verified: z.boolean(),
|
|
3208
|
+
checksum: z.string(),
|
|
3209
|
+
expected: z.string()
|
|
3210
|
+
}))
|
|
3211
|
+
}).optional()
|
|
3212
|
+
});
|
|
3213
|
+
z.object({
|
|
3214
|
+
enableDeduplication: z.boolean().default(true),
|
|
3215
|
+
namingStrategy: z.enum([
|
|
3216
|
+
"git",
|
|
3217
|
+
"semantic",
|
|
3218
|
+
"timestamp",
|
|
3219
|
+
"custom"
|
|
3220
|
+
]).default("semantic"),
|
|
3221
|
+
autoProtect: z.boolean().default(false),
|
|
3222
|
+
maxSnapshots: z.number().int().positive().optional()
|
|
3223
|
+
});
|
|
3224
|
+
z.object({
|
|
3225
|
+
id: z.string(),
|
|
3226
|
+
path: z.string(),
|
|
3227
|
+
hash: z.string().optional(),
|
|
3228
|
+
size: z.number().optional(),
|
|
3229
|
+
language: z.string().optional(),
|
|
3230
|
+
risk: RiskScoreSchema.optional(),
|
|
3231
|
+
lastModified: z.number().optional(),
|
|
3232
|
+
createdAt: z.number().optional()
|
|
3233
|
+
});
|
|
3234
|
+
z.object({
|
|
3235
|
+
// Core fields (required)
|
|
3236
|
+
id: z.string(),
|
|
3237
|
+
timestamp: z.number(),
|
|
3238
|
+
fileCount: z.number(),
|
|
3239
|
+
// Analytics fields (optional)
|
|
3240
|
+
totalSize: z.number().optional(),
|
|
3241
|
+
riskScore: RiskScoreSchema.optional(),
|
|
3242
|
+
tags: z.array(z.string()).optional(),
|
|
3243
|
+
// V2 Hierarchy fields (from VSCode ManifestV2)
|
|
3244
|
+
/** Sequential snapshot number (1-based, monotonic) */
|
|
3245
|
+
seq: z.number().int().positive().optional(),
|
|
3246
|
+
/** Parent snapshot seq (null for root) */
|
|
3247
|
+
parentSeq: z.number().int().positive().nullable().optional(),
|
|
3248
|
+
/** Parent snapshot ID */
|
|
3249
|
+
parentId: z.string().nullable().optional(),
|
|
3250
|
+
/** Checkpoint type */
|
|
3251
|
+
type: CheckpointTypeSchema.optional(),
|
|
3252
|
+
/** Main file that triggered this snapshot */
|
|
3253
|
+
anchorFile: z.string().optional(),
|
|
3254
|
+
// DORA Metrics fields
|
|
3255
|
+
/** Time since last file change in ms (for lead time metric) */
|
|
3256
|
+
timeSinceLastChangeMs: z.number().optional(),
|
|
3257
|
+
/** Compression ratio achieved (for storage efficiency) */
|
|
3258
|
+
compressionRatio: z.number().optional(),
|
|
3259
|
+
/** Storage size in bytes (after compression) */
|
|
3260
|
+
storageSizeBytes: z.number().optional(),
|
|
3261
|
+
// Origin & Classification
|
|
3262
|
+
/** Origin classification for analytics */
|
|
3263
|
+
origin: SnapshotOriginSchema.optional(),
|
|
3264
|
+
/** Reason codes for explainability */
|
|
3265
|
+
reasons: z.array(SnapshotReasonCodeSchema).optional(),
|
|
3266
|
+
// AI Detection
|
|
3267
|
+
aiDetection: z.object({
|
|
3268
|
+
detected: z.boolean(),
|
|
3269
|
+
tool: z.string().optional(),
|
|
3270
|
+
confidence: z.number().min(0).max(1).optional()
|
|
3271
|
+
}).optional(),
|
|
3272
|
+
// Session linkage
|
|
3273
|
+
/** SnapBack session ID */
|
|
3274
|
+
sessionId: z.string().optional(),
|
|
3275
|
+
/** External task ID (from LLM agent) */
|
|
3276
|
+
taskId: z.string().optional(),
|
|
3277
|
+
// UI fields
|
|
3278
|
+
name: z.string().optional(),
|
|
3279
|
+
icon: z.string().optional()
|
|
3280
|
+
});
|
|
3281
|
+
z.object({
|
|
3282
|
+
/** Schema version - always 2 for V2 */
|
|
3283
|
+
schemaVersion: z.literal(2),
|
|
3284
|
+
/** Unique ID: snap-{timestamp}-{random} */
|
|
3285
|
+
id: z.string(),
|
|
3286
|
+
/** Sequential snapshot number (1-based, monotonic) */
|
|
3287
|
+
seq: z.number().int().positive(),
|
|
3288
|
+
/** Parent snapshot seq (null for root) */
|
|
3289
|
+
parentSeq: z.number().int().positive().nullable(),
|
|
3290
|
+
/** Parent snapshot ID (null for root) */
|
|
3291
|
+
parentId: z.string().nullable(),
|
|
3292
|
+
/** Unix timestamp (ms) */
|
|
3293
|
+
timestamp: z.number(),
|
|
3294
|
+
/** Human-readable name */
|
|
3295
|
+
name: z.string(),
|
|
3296
|
+
/** Checkpoint type */
|
|
3297
|
+
type: CheckpointTypeSchema,
|
|
3298
|
+
/** The main file that triggered this snapshot */
|
|
3299
|
+
anchorFile: z.string(),
|
|
3300
|
+
/** Files in snapshot (path → ref). Empty for PRE checkpoints. */
|
|
3301
|
+
files: z.record(z.string(), SnapshotFileRefV2Schema),
|
|
3302
|
+
/** Optional metadata */
|
|
3303
|
+
metadata: z.object({
|
|
3304
|
+
/** Risk score 0-1 */
|
|
3305
|
+
riskScore: z.number().min(0).max(1).optional(),
|
|
3306
|
+
/** Origin classification */
|
|
3307
|
+
origin: SnapshotOriginSchema.optional(),
|
|
3308
|
+
/** Stable reason codes */
|
|
3309
|
+
reasons: z.array(SnapshotReasonCodeSchema).optional(),
|
|
3310
|
+
/** AI detection info */
|
|
3311
|
+
aiDetection: z.object({
|
|
3312
|
+
detected: z.boolean(),
|
|
3313
|
+
tool: z.string().optional(),
|
|
3314
|
+
confidence: z.number().optional()
|
|
3315
|
+
}).optional(),
|
|
3316
|
+
/** SnapBack session ID */
|
|
3317
|
+
sessionId: z.string().optional(),
|
|
3318
|
+
/** External task ID */
|
|
3319
|
+
taskId: z.string().optional(),
|
|
3320
|
+
/** DORA: Time since last change */
|
|
3321
|
+
timeSinceLastChangeMs: z.number().optional()
|
|
3322
|
+
}).optional()
|
|
3323
|
+
});
|
|
3324
|
+
z.object({
|
|
3325
|
+
/** Unique ID */
|
|
3326
|
+
id: z.string(),
|
|
3327
|
+
/** Unix timestamp (ms) */
|
|
3328
|
+
timestamp: z.number(),
|
|
3329
|
+
/** Human-readable name */
|
|
3330
|
+
name: z.string(),
|
|
3331
|
+
/** Trigger reason */
|
|
3332
|
+
trigger: z.enum([
|
|
3333
|
+
"auto",
|
|
3334
|
+
"manual",
|
|
3335
|
+
"ai-detected",
|
|
3336
|
+
"pre-save"
|
|
3337
|
+
]),
|
|
3338
|
+
/** Main file that triggered snapshot */
|
|
3339
|
+
anchorFile: z.string(),
|
|
3340
|
+
/** Files in snapshot (path → ref) */
|
|
3341
|
+
files: z.record(z.string(), z.object({
|
|
3342
|
+
blob: z.string(),
|
|
3343
|
+
size: z.number()
|
|
3344
|
+
})),
|
|
3345
|
+
/** Optional metadata */
|
|
3346
|
+
metadata: z.object({
|
|
3347
|
+
riskScore: z.number().optional(),
|
|
3348
|
+
aiDetection: z.object({
|
|
3349
|
+
detected: z.boolean(),
|
|
3350
|
+
tool: z.string().optional(),
|
|
3351
|
+
confidence: z.number().optional()
|
|
3352
|
+
}).optional(),
|
|
3353
|
+
sessionId: z.string().optional(),
|
|
3354
|
+
taskId: z.string().optional()
|
|
3355
|
+
}).optional()
|
|
3356
|
+
});
|
|
3357
|
+
z.object({
|
|
3358
|
+
/** Total files in snapshot */
|
|
3359
|
+
totalFiles: z.number().int().nonnegative(),
|
|
3360
|
+
/** New blobs written to storage (not deduplicated) */
|
|
3361
|
+
newBlobsWritten: z.number().int().nonnegative(),
|
|
3362
|
+
/** Files that were deduplicated (already existed in CAS) */
|
|
3363
|
+
dedupedFiles: z.number().int().nonnegative(),
|
|
3364
|
+
/** Deduplication ratio (0-1) - higher means more storage saved */
|
|
3365
|
+
dedupRatio: z.number().min(0).max(1),
|
|
3366
|
+
/** Actual bytes written to storage */
|
|
3367
|
+
bytesWritten: z.number().int().nonnegative(),
|
|
3368
|
+
/** Original size of all files (before dedup) */
|
|
3369
|
+
originalSize: z.number().int().nonnegative(),
|
|
3370
|
+
/** Storage savings in bytes (originalSize - bytesWritten) */
|
|
3371
|
+
bytesSaved: z.number().int().nonnegative()
|
|
3372
|
+
});
|
|
3373
|
+
z.object({
|
|
3374
|
+
workspaceId: z.string(),
|
|
3375
|
+
period: z.object({
|
|
3376
|
+
start: z.number(),
|
|
3377
|
+
end: z.number()
|
|
3378
|
+
}),
|
|
3379
|
+
risk: RiskScoreSchema,
|
|
3380
|
+
fileStats: z.object({
|
|
3381
|
+
total: z.number(),
|
|
3382
|
+
byLanguage: z.record(z.string(), z.number()),
|
|
3383
|
+
byRisk: z.record(z.string(), z.number())
|
|
3384
|
+
}),
|
|
3385
|
+
snapshotStats: z.object({
|
|
3386
|
+
total: z.number(),
|
|
3387
|
+
frequency: z.number(),
|
|
3388
|
+
averageSize: z.number().optional()
|
|
3389
|
+
}),
|
|
3390
|
+
snapshotRecommendations: z.object({
|
|
3391
|
+
shouldCreateSnapshot: z.boolean(),
|
|
3392
|
+
reason: z.string(),
|
|
3393
|
+
urgency: RiskSeveritySchema,
|
|
3394
|
+
suggestedTiming: z.string()
|
|
3395
|
+
}),
|
|
3396
|
+
trends: z.object({
|
|
3397
|
+
risk: z.array(z.object({
|
|
3398
|
+
timestamp: z.number(),
|
|
3399
|
+
score: z.number()
|
|
3400
|
+
})),
|
|
3401
|
+
activity: z.array(z.object({
|
|
3402
|
+
timestamp: z.number(),
|
|
3403
|
+
count: z.number()
|
|
3404
|
+
}))
|
|
3405
|
+
})
|
|
3406
|
+
});
|
|
3407
|
+
var DashboardSnapshotSchema = z.object({
|
|
3408
|
+
id: z.string(),
|
|
3409
|
+
file: z.string(),
|
|
3410
|
+
message: z.string(),
|
|
3411
|
+
time: z.string(),
|
|
3412
|
+
risk: z.enum([
|
|
3413
|
+
"Low",
|
|
3414
|
+
"Medium",
|
|
3415
|
+
"High",
|
|
3416
|
+
"Critical"
|
|
3417
|
+
]),
|
|
3418
|
+
ai: z.string()
|
|
3419
|
+
});
|
|
3420
|
+
var LearningDataSchema = z.object({
|
|
3421
|
+
day: z.string(),
|
|
3422
|
+
learned: z.number()
|
|
3423
|
+
});
|
|
3424
|
+
var AttributionDataSchema = z.object({
|
|
3425
|
+
name: z.string(),
|
|
3426
|
+
value: z.number(),
|
|
3427
|
+
color: z.string()
|
|
3428
|
+
});
|
|
3429
|
+
var DashboardDataSchema = z.object({
|
|
3430
|
+
// Pulse view
|
|
3431
|
+
trustScore: z.number().min(0).max(100),
|
|
3432
|
+
patternsCaught: z.number().int().nonnegative(),
|
|
3433
|
+
activeSessions: z.number().int().nonnegative(),
|
|
3434
|
+
// User context
|
|
3435
|
+
userName: z.string(),
|
|
3436
|
+
userInitials: z.string(),
|
|
3437
|
+
tier: z.string(),
|
|
3438
|
+
// Sessions view
|
|
3439
|
+
snapshots: z.array(DashboardSnapshotSchema),
|
|
3440
|
+
// Intelligence view
|
|
3441
|
+
learningVelocity: z.array(LearningDataSchema),
|
|
3442
|
+
aiAttribution: z.array(AttributionDataSchema),
|
|
3443
|
+
totalLearned: z.number().int().nonnegative(),
|
|
3444
|
+
growthPercentage: z.number().int().nonnegative()
|
|
3445
|
+
});
|
|
3446
|
+
var DashboardDataErrorSchema = z.object({
|
|
3447
|
+
error: z.literal(true),
|
|
3448
|
+
code: z.enum([
|
|
3449
|
+
"UNAUTHORIZED",
|
|
3450
|
+
"NOT_FOUND",
|
|
3451
|
+
"INTERNAL_ERROR"
|
|
3452
|
+
]),
|
|
3453
|
+
message: z.string()
|
|
3454
|
+
});
|
|
3455
|
+
z.union([
|
|
3456
|
+
DashboardDataSchema,
|
|
3457
|
+
DashboardDataErrorSchema
|
|
3458
|
+
]);
|
|
3459
|
+
var PROTECTION_STATUSES = [
|
|
3460
|
+
"active",
|
|
3461
|
+
"inactive"
|
|
3462
|
+
];
|
|
3463
|
+
var RECENT_ACTIVITY_ACTIONS = [
|
|
3464
|
+
"snapshot_created",
|
|
3465
|
+
"recovery_performed",
|
|
3466
|
+
"ai_detected"
|
|
3467
|
+
];
|
|
3468
|
+
var AI_TOOLS = [
|
|
3469
|
+
"copilot",
|
|
3470
|
+
"cursor",
|
|
3471
|
+
"claude",
|
|
3472
|
+
"windsurf"
|
|
3473
|
+
];
|
|
3474
|
+
var RecentActivitySchema = z.object({
|
|
3475
|
+
timestamp: z.number().int().positive(),
|
|
3476
|
+
action: z.enum(RECENT_ACTIVITY_ACTIONS),
|
|
3477
|
+
file: z.string().min(1),
|
|
3478
|
+
ai_tool: z.enum(AI_TOOLS).optional()
|
|
3479
|
+
});
|
|
3480
|
+
var AIActivityBreakdownSchema = z.object({
|
|
3481
|
+
copilot: z.number().int().nonnegative(),
|
|
3482
|
+
cursor: z.number().int().nonnegative(),
|
|
3483
|
+
claude: z.number().int().nonnegative(),
|
|
3484
|
+
windsurf: z.number().int().nonnegative().optional()
|
|
3485
|
+
});
|
|
3486
|
+
var DashboardMetricsSchema = z.object({
|
|
3487
|
+
protection_status: z.enum(PROTECTION_STATUSES),
|
|
3488
|
+
total_snapshots: z.number().int().nonnegative(),
|
|
3489
|
+
total_recoveries: z.number().int().nonnegative(),
|
|
3490
|
+
files_protected: z.number().int().nonnegative(),
|
|
3491
|
+
ai_detection_rate: z.number().min(0).max(100),
|
|
3492
|
+
recent_activity: z.array(RecentActivitySchema).max(10),
|
|
3493
|
+
ai_breakdown: AIActivityBreakdownSchema
|
|
3494
|
+
});
|
|
3495
|
+
var DashboardMetricsErrorSchema = z.object({
|
|
3496
|
+
error: z.literal(true),
|
|
3497
|
+
code: z.enum([
|
|
3498
|
+
"UNAUTHORIZED",
|
|
3499
|
+
"NOT_FOUND",
|
|
3500
|
+
"INTERNAL_ERROR"
|
|
3501
|
+
]),
|
|
3502
|
+
message: z.string()
|
|
3503
|
+
});
|
|
3504
|
+
z.union([
|
|
3505
|
+
DashboardMetricsSchema,
|
|
3506
|
+
DashboardMetricsErrorSchema
|
|
3507
|
+
]);
|
|
3508
|
+
var AI_TOOLS2 = [
|
|
3509
|
+
"cursor",
|
|
3510
|
+
"copilot",
|
|
3511
|
+
"claude"
|
|
3512
|
+
];
|
|
3513
|
+
var EVENT_TYPES = [
|
|
3514
|
+
"ai_detected",
|
|
3515
|
+
"snapshot",
|
|
3516
|
+
"recovery",
|
|
3517
|
+
"quiet"
|
|
3518
|
+
];
|
|
3519
|
+
var RISK_LEVELS = [
|
|
3520
|
+
"high",
|
|
3521
|
+
"medium",
|
|
3522
|
+
"low"
|
|
3523
|
+
];
|
|
3524
|
+
var FILE_CATEGORIES = [
|
|
3525
|
+
"auth",
|
|
3526
|
+
"config",
|
|
3527
|
+
"api",
|
|
3528
|
+
"ui",
|
|
3529
|
+
"lib",
|
|
3530
|
+
"test",
|
|
3531
|
+
"infra",
|
|
3532
|
+
"types",
|
|
3533
|
+
"hooks",
|
|
3534
|
+
"util"
|
|
3535
|
+
];
|
|
3536
|
+
var DAYS_OF_WEEK = [
|
|
3537
|
+
"Mon",
|
|
3538
|
+
"Tue",
|
|
3539
|
+
"Wed",
|
|
3540
|
+
"Thu",
|
|
3541
|
+
"Fri",
|
|
3542
|
+
"Sat",
|
|
3543
|
+
"Sun"
|
|
3544
|
+
];
|
|
3545
|
+
var PIONEER_TIERS = [
|
|
3546
|
+
"Pioneer",
|
|
3547
|
+
"Active Pioneer",
|
|
3548
|
+
"Contributing Pioneer",
|
|
3549
|
+
"Founding Pioneer"
|
|
3550
|
+
];
|
|
3551
|
+
var ProtectionSchema = z.object({
|
|
3552
|
+
score: z.number().min(0).max(100).describe("Protection confidence score (0-100)"),
|
|
3553
|
+
risksPrevented: z.number().int().nonnegative().describe("Count of proactive protections this week"),
|
|
3554
|
+
context: z.string().describe("Human-readable summary of protected areas"),
|
|
3555
|
+
weekLabel: z.string().default("this week").describe("Rolling window label")
|
|
3556
|
+
});
|
|
3557
|
+
var TimelineEventSchema = z.object({
|
|
3558
|
+
hour: z.number().int().min(0).max(23).describe("Hour of day (0-23)"),
|
|
3559
|
+
type: z.enum(EVENT_TYPES).describe("Visual category for dot color"),
|
|
3560
|
+
tool: z.enum(AI_TOOLS2).optional().describe("AI tool detected (if applicable)"),
|
|
3561
|
+
file: z.string().min(1).describe("Relative file path"),
|
|
3562
|
+
risk: z.enum(RISK_LEVELS).describe("Risk tier for this event"),
|
|
3563
|
+
action: z.string().describe("What SnapBack did: auto-protected | monitored | recovered"),
|
|
3564
|
+
blast: z.number().int().nonnegative().optional().describe("Transitive dependency count")
|
|
3565
|
+
});
|
|
3566
|
+
var HeatmapFileSchema = z.object({
|
|
3567
|
+
file: z.string().min(1).describe("Relative file path"),
|
|
3568
|
+
risk: z.number().min(0).max(1).describe("Composite risk score (0-1)"),
|
|
3569
|
+
changes: z.number().int().nonnegative().describe("Change count in rolling window"),
|
|
3570
|
+
aiRatio: z.number().min(0).max(1).describe("Percentage of AI-authored changes (0-1)"),
|
|
3571
|
+
cat: z.enum(FILE_CATEGORIES).describe("File category for color coding")
|
|
3572
|
+
});
|
|
3573
|
+
var AIAttributionSchema = z.object({
|
|
3574
|
+
cursor: z.number().int().nonnegative().describe("Percentage attributed to Cursor"),
|
|
3575
|
+
copilot: z.number().int().nonnegative().describe("Percentage attributed to Copilot"),
|
|
3576
|
+
claude: z.number().int().nonnegative().describe("Percentage attributed to Claude")
|
|
3577
|
+
});
|
|
3578
|
+
var DailyActivitySchema = z.object({
|
|
3579
|
+
day: z.enum(DAYS_OF_WEEK).describe("Day of week"),
|
|
3580
|
+
ai: z.number().int().nonnegative().describe("AI-attributed changes"),
|
|
3581
|
+
human: z.number().int().nonnegative().describe("Human-only changes"),
|
|
3582
|
+
prevented: z.number().int().nonnegative().describe("Proactive protections triggered")
|
|
3583
|
+
});
|
|
3584
|
+
var WeeklyVelocitySchema = z.object({
|
|
3585
|
+
week: z.string().min(1).describe("Week label (e.g., 'W1', 'W2')"),
|
|
3586
|
+
learnings: z.number().int().nonnegative().describe("Cumulative pattern count"),
|
|
3587
|
+
accuracy: z.number().min(0).max(100).describe("AutoDecisionEngine accuracy percentage")
|
|
3588
|
+
});
|
|
3589
|
+
var PioneerSchema = z.object({
|
|
3590
|
+
tier: z.enum(PIONEER_TIERS).describe("Current Pioneer tier"),
|
|
3591
|
+
tierIndex: z.number().int().min(0).max(3).describe("Numeric index for rendering (0-3)"),
|
|
3592
|
+
recentUnlock: z.string().optional().describe("Most recent capability unlocked"),
|
|
3593
|
+
impact: z.string().describe("Cross-user impact statement")
|
|
3594
|
+
});
|
|
3595
|
+
var QuickInsightsSchema = z.object({
|
|
3596
|
+
sessionsThisWeek: z.number().int().nonnegative().describe("Development sessions started"),
|
|
3597
|
+
avgSessionMinutes: z.number().int().nonnegative().describe("Mean session length"),
|
|
3598
|
+
coherencePercent: z.number().min(0).max(100).describe("Session coherence score"),
|
|
3599
|
+
preventedToRecoveredRatio: z.string().describe("Ratio string like '3 : 1'"),
|
|
3600
|
+
fragileFileCount: z.number().int().nonnegative().describe("High-change, high-risk files"),
|
|
3601
|
+
fragileHotspots: z.string().describe("Directory summary like 'auth/ and config/'")
|
|
3602
|
+
});
|
|
3603
|
+
var UserInfoSchema = z.object({
|
|
3604
|
+
name: z.string().nullable().describe("User display name"),
|
|
3605
|
+
email: z.string().email().describe("User email address")
|
|
3606
|
+
});
|
|
3607
|
+
var SessionMetricsSchema = z.object({
|
|
3608
|
+
activeSessionCount: z.number().int().nonnegative().describe("Currently active sessions"),
|
|
3609
|
+
lastActivityTime: z.string().datetime().describe("ISO timestamp of last activity")
|
|
3610
|
+
});
|
|
3611
|
+
var PioneerDashboardSchema = z.object({
|
|
3612
|
+
version: z.literal(1).describe("Schema version for migrations"),
|
|
3613
|
+
computedAt: z.number().int().positive().describe("Unix timestamp when digest was computed"),
|
|
3614
|
+
// User info (from old dashboard)
|
|
3615
|
+
user: UserInfoSchema.describe("Current user information"),
|
|
3616
|
+
sessionMetrics: SessionMetricsSchema.describe("Active session metrics"),
|
|
3617
|
+
protection: ProtectionSchema.describe("Hero section data"),
|
|
3618
|
+
timeline: z.array(TimelineEventSchema).max(24).describe("24h activity timeline"),
|
|
3619
|
+
heatmap: z.array(HeatmapFileSchema).describe("File risk treemap data"),
|
|
3620
|
+
ai: AIAttributionSchema.describe("AI tool attribution"),
|
|
3621
|
+
weekly: z.array(DailyActivitySchema).length(7).describe("Weekly activity bars"),
|
|
3622
|
+
velocity: z.array(WeeklyVelocitySchema).min(4).describe("Learning velocity curve"),
|
|
3623
|
+
pioneer: PioneerSchema.describe("Pioneer journey data"),
|
|
3624
|
+
insights: QuickInsightsSchema.describe("Quick insight cards")
|
|
3625
|
+
});
|
|
3626
|
+
var PioneerDashboardSuccessSchema = z.object({
|
|
3627
|
+
status: z.literal("success"),
|
|
3628
|
+
digest: PioneerDashboardSchema,
|
|
3629
|
+
stalenessMinutes: z.number().int().nonnegative().describe("Minutes since last sync")
|
|
3630
|
+
});
|
|
3631
|
+
var PioneerDashboardEmptySchema = z.object({
|
|
3632
|
+
status: z.literal("empty"),
|
|
3633
|
+
message: z.string().default("No digest synced yet")
|
|
3634
|
+
});
|
|
3635
|
+
var PioneerDashboardErrorSchema = z.object({
|
|
3636
|
+
status: z.literal("error"),
|
|
3637
|
+
code: z.enum([
|
|
3638
|
+
"UNAUTHORIZED",
|
|
3639
|
+
"NOT_FOUND",
|
|
3640
|
+
"INTERNAL_ERROR"
|
|
3641
|
+
]),
|
|
3642
|
+
message: z.string()
|
|
3643
|
+
});
|
|
3644
|
+
z.discriminatedUnion("status", [
|
|
3645
|
+
PioneerDashboardSuccessSchema,
|
|
3646
|
+
PioneerDashboardEmptySchema,
|
|
3647
|
+
PioneerDashboardErrorSchema
|
|
3648
|
+
]);
|
|
3649
|
+
({
|
|
3650
|
+
sessionMetrics: {
|
|
3651
|
+
lastActivityTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
3652
|
+
}});
|
|
3653
|
+
|
|
3654
|
+
export { FEATURE_FLAGS, FeatureManager, LogLevel, NoOpInstrumentationProvider, TIER_UPGRADE_SAGA, createLogger, extractErrorCode, getTierFeatures, getTierLimit, isFeatureAvailableAtTier, shouldMergeAttribution, validateTelemetryEvent };
|