skillar 0.2.1 → 0.3.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/NOTICE +280 -0
- package/README.md +37 -5
- package/dist/analysis/finding.js +8 -190
- package/dist/analysis/kernel.js +896 -0
- package/dist/analysis/tree.js +7 -154
- package/dist/analysis/usage.js +9 -394
- package/dist/api/flows.js +42 -212
- package/dist/api/report-kernel.js +1063 -0
- package/dist/api/routes.js +12 -2
- package/dist/catalog/fields.js +138 -146
- package/dist/catalog/watcher.js +7 -2
- package/dist/cli/init.js +45 -0
- package/dist/cli/main.js +76 -3
- package/dist/cli/private-skills.js +122 -0
- package/dist/cli/serve.js +15 -1
- package/dist/cli/sync.js +124 -0
- package/dist/dashboard/NOTICE +280 -0
- package/dist/dashboard/assets/app.js +737 -275
- package/dist/dashboard/assets/astryx-reset.css +407 -0
- package/dist/dashboard/assets/astryx.css +1077 -0
- package/dist/dashboard/assets/charts.css +54 -0
- package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
- package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
- package/dist/dashboard/assets/controls.css +207 -0
- package/dist/dashboard/assets/overlays.css +132 -0
- package/dist/dashboard/assets/p1.css +135 -0
- package/dist/dashboard/assets/shell.css +71 -0
- package/dist/dashboard/assets/skillar-theme.css +692 -0
- package/dist/dashboard/assets/styles.css +224 -121
- package/dist/dashboard/assets/tokens.css +278 -0
- package/dist/dashboard/assets/widgets.css +83 -0
- package/dist/dashboard/index.html +11 -2
- package/dist/dashboard/viewers/viewers.css +61 -0
- package/dist/ingest/attribution.js +5 -1
- package/dist/ingest/pipeline.js +2 -0
- package/dist/ingest/request-recorder.js +39 -0
- package/dist/mcp/dispatch.js +2 -2
- package/dist/mcp/http.js +43 -3
- package/dist/mcp/skills-extension.js +42 -15
- package/dist/mcp/stdio-proxy.js +24 -3
- package/dist/mcp/tools.js +38 -24
- package/dist/packs/claude-code.js +22 -11
- package/dist/packs/cursor.js +9 -4
- package/dist/packs/gemini.js +9 -4
- package/dist/packs/json-config.js +41 -0
- package/dist/packs/omo.js +15 -6
- package/dist/request-status.js +81 -0
- package/dist/search/fts.js +93 -58
- package/dist/search/fusion.js +49 -47
- package/dist/search/guidance.js +18 -6
- package/dist/search/index.js +291 -70
- package/dist/search/lexical.js +71 -63
- package/dist/server.js +12 -0
- package/dist/skills/apply.js +130 -0
- package/dist/skills/capture.js +54 -0
- package/dist/skills/cloud-plan.js +57 -0
- package/dist/skills/cloud.js +81 -0
- package/dist/skills/fs.js +133 -0
- package/dist/skills/package.js +734 -0
- package/dist/skills/plan.js +83 -0
- package/dist/skills/receipt.js +44 -0
- package/dist/skills/rollback.js +119 -0
- package/dist/skills/transfer.js +51 -0
- package/dist/store/db.js +7 -1
- package/dist/store/execution.js +2 -34
- package/dist/store/export.js +25 -4
- package/dist/store/migrations/007_sync.sql +49 -0
- package/dist/store/migrations/008_connector_commands.sql +12 -0
- package/dist/store/queries.js +33 -7
- package/dist/store/writes.js +38 -5
- package/dist/sync/cloud-blobs.js +175 -0
- package/dist/sync/cloud-commands.js +101 -0
- package/dist/sync/cloud-connection.js +105 -0
- package/dist/sync/cloud-delivery.js +114 -0
- package/dist/sync/cloud-documents.js +103 -0
- package/dist/sync/cloud-export.js +67 -0
- package/dist/sync/cloud-http.js +150 -0
- package/dist/sync/cloud-jobs.js +94 -0
- package/dist/sync/cloud-pending.js +143 -0
- package/dist/sync/cloud-prepare.js +101 -0
- package/dist/sync/cloud-restore.js +136 -0
- package/dist/sync/cloud-rollback.js +24 -0
- package/dist/sync/cloud-runner.js +86 -0
- package/dist/sync/cloud-runtime.js +293 -0
- package/dist/sync/cloud-schema.js +32 -0
- package/dist/sync/cloud-stage.js +112 -0
- package/dist/sync/cloud-wire.js +693 -0
- package/dist/sync/cloud-worker.js +57 -0
- package/dist/sync/cloud.js +157 -0
- package/dist/sync/command-apply.js +140 -0
- package/dist/sync/command-control.js +25 -0
- package/dist/sync/command-wire.js +437 -0
- package/dist/sync/consent.js +130 -0
- package/dist/sync/journal.js +43 -0
- package/dist/sync/outbox.js +134 -0
- package/dist/sync/restore-rows.js +125 -0
- package/dist/sync/restore.js +174 -0
- package/dist/sync/snapshot.js +78 -0
- package/dist/sync/spool-request.js +103 -0
- package/dist/sync/tables.js +27 -0
- package/dist/sync/triggers.js +34 -0
- package/dist/workflow/compare.js +3 -43
- package/docs/cloud-sync.md +94 -0
- package/docs/private-skills.md +75 -0
- package/docs/sync-p4.md +102 -0
- package/docs/sync-restore.md +167 -0
- package/package.json +18 -5
- package/src/store/migrations/007_sync.sql +49 -0
- package/src/store/migrations/008_connector_commands.sql +12 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
// ../shared/dist/deployment-origin.js
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var deploymentOriginSchema = z.url().refine((value) => {
|
|
4
|
+
const url = new URL(value);
|
|
5
|
+
return value === url.origin && (url.protocol === "https:" || value === "http://localhost:8788");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// ../shared/dist/activity-consent.js
|
|
9
|
+
import { z as z3 } from "zod";
|
|
10
|
+
|
|
11
|
+
// ../shared/dist/activity-schema.js
|
|
12
|
+
import { z as z2 } from "zod";
|
|
13
|
+
var identity = z2.string().min(1).max(512).refine((value) => !value.includes("\0"));
|
|
14
|
+
var accountIdSchema = identity.brand();
|
|
15
|
+
var deviceIdSchema = identity.brand();
|
|
16
|
+
var sourceDomainSchema = identity.brand();
|
|
17
|
+
var sourceIdSchema = identity.brand();
|
|
18
|
+
var revisionSchema = z2.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
19
|
+
var timestampSchema = z2.number().int().min(-864e13).max(864e13);
|
|
20
|
+
var recordingOrdersSchema = z2.record(sourceDomainSchema, revisionSchema).readonly();
|
|
21
|
+
var timeRangeSchema = z2.strictObject({
|
|
22
|
+
fromMs: timestampSchema,
|
|
23
|
+
toMs: timestampSchema
|
|
24
|
+
}).refine((value) => value.toMs > value.fromMs).readonly();
|
|
25
|
+
var backfillReferenceSchema = z2.strictObject({
|
|
26
|
+
version: revisionSchema.min(1),
|
|
27
|
+
snapshotId: identity,
|
|
28
|
+
journalCut: revisionSchema
|
|
29
|
+
}).readonly();
|
|
30
|
+
var count = z2.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable();
|
|
31
|
+
var runtime = z2.enum(["claude-code", "codex", "gemini", "cursor", "omo", "gajae", "openclaw", "unknown"]);
|
|
32
|
+
var sessionFactsSchema = z2.strictObject({
|
|
33
|
+
runtime,
|
|
34
|
+
startedMs: timestampSchema,
|
|
35
|
+
endedMs: timestampSchema.nullable(),
|
|
36
|
+
automated: z2.boolean().nullable()
|
|
37
|
+
}).readonly();
|
|
38
|
+
var eventFactsSchema = z2.strictObject({
|
|
39
|
+
sessionId: sourceIdSchema,
|
|
40
|
+
kind: z2.enum([
|
|
41
|
+
"session_start",
|
|
42
|
+
"session_end",
|
|
43
|
+
"prompt",
|
|
44
|
+
"search",
|
|
45
|
+
"load",
|
|
46
|
+
"read_file",
|
|
47
|
+
"native_skill",
|
|
48
|
+
"tool_call",
|
|
49
|
+
"llm_call",
|
|
50
|
+
"error",
|
|
51
|
+
"skill_request"
|
|
52
|
+
]),
|
|
53
|
+
timestampMs: timestampSchema,
|
|
54
|
+
sourceOrder: revisionSchema.nullable(),
|
|
55
|
+
recordingOrders: recordingOrdersSchema,
|
|
56
|
+
sourceKey: sourceIdSchema.nullable(),
|
|
57
|
+
status: z2.enum(["in_progress", "succeeded", "failed", "cancelled", "unknown"]),
|
|
58
|
+
inputTokens: count,
|
|
59
|
+
outputTokens: count
|
|
60
|
+
}).readonly();
|
|
61
|
+
var spanFactsSchema = z2.strictObject({
|
|
62
|
+
traceId: sourceIdSchema,
|
|
63
|
+
spanId: sourceIdSchema,
|
|
64
|
+
parentSpanId: sourceIdSchema.nullable(),
|
|
65
|
+
sessionId: sourceIdSchema.nullable(),
|
|
66
|
+
startMs: timestampSchema.nullable(),
|
|
67
|
+
endMs: timestampSchema.nullable(),
|
|
68
|
+
recordingOrders: recordingOrdersSchema,
|
|
69
|
+
inputTokens: count,
|
|
70
|
+
outputTokens: count
|
|
71
|
+
}).readonly();
|
|
72
|
+
var mutation = {
|
|
73
|
+
key: sourceIdSchema,
|
|
74
|
+
revision: revisionSchema
|
|
75
|
+
};
|
|
76
|
+
var metadataMutationSchema = z2.discriminatedUnion("entity", [
|
|
77
|
+
z2.strictObject({ ...mutation, entity: z2.literal("session"), facts: sessionFactsSchema }),
|
|
78
|
+
z2.strictObject({ ...mutation, entity: z2.literal("event"), facts: eventFactsSchema }),
|
|
79
|
+
z2.strictObject({ ...mutation, entity: z2.literal("span"), facts: spanFactsSchema }),
|
|
80
|
+
z2.strictObject({
|
|
81
|
+
...mutation,
|
|
82
|
+
entity: z2.literal("tombstone"),
|
|
83
|
+
target: z2.enum(["session", "event", "span"])
|
|
84
|
+
})
|
|
85
|
+
]).readonly();
|
|
86
|
+
var activityBatchSchema = z2.strictObject({
|
|
87
|
+
schemaVersion: z2.literal(1),
|
|
88
|
+
batchId: identity,
|
|
89
|
+
// Account identity comes only from the verified principal, never this payload.
|
|
90
|
+
deviceId: deviceIdSchema,
|
|
91
|
+
sourceDomain: sourceDomainSchema,
|
|
92
|
+
generation: revisionSchema.min(1),
|
|
93
|
+
consentVersion: revisionSchema.min(1),
|
|
94
|
+
projectId: identity,
|
|
95
|
+
rootId: identity.nullable(),
|
|
96
|
+
range: timeRangeSchema,
|
|
97
|
+
backfill: backfillReferenceSchema.nullable(),
|
|
98
|
+
sequence: revisionSchema.min(1),
|
|
99
|
+
journal: z2.strictObject({ from: revisionSchema, through: revisionSchema }).refine((range) => range.through >= range.from).readonly(),
|
|
100
|
+
mutations: z2.array(metadataMutationSchema).min(1).max(100).readonly()
|
|
101
|
+
}).readonly();
|
|
102
|
+
var contentKinds = [
|
|
103
|
+
"prompt",
|
|
104
|
+
"query",
|
|
105
|
+
"args",
|
|
106
|
+
"error",
|
|
107
|
+
"path",
|
|
108
|
+
"span-attributes",
|
|
109
|
+
"private-skills"
|
|
110
|
+
];
|
|
111
|
+
var contentKindSchema = z2.enum(contentKinds);
|
|
112
|
+
var MAX_BATCH_BYTES = 256 * 1024;
|
|
113
|
+
function parseActivityBatch(input, options = {}) {
|
|
114
|
+
const parser = options.allowEmptyMetadata === true ? activityBatchSchema.unwrap().extend({
|
|
115
|
+
mutations: z2.array(metadataMutationSchema).max(100).readonly()
|
|
116
|
+
}).readonly() : activityBatchSchema;
|
|
117
|
+
const value = parser.parse(input);
|
|
118
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > MAX_BATCH_BYTES) {
|
|
119
|
+
throw new ActivityContractError("batch_too_large");
|
|
120
|
+
}
|
|
121
|
+
for (const mutation2 of value.mutations) {
|
|
122
|
+
let times;
|
|
123
|
+
switch (mutation2.entity) {
|
|
124
|
+
case "event":
|
|
125
|
+
times = [mutation2.facts.timestampMs];
|
|
126
|
+
break;
|
|
127
|
+
case "session":
|
|
128
|
+
times = [mutation2.facts.startedMs, mutation2.facts.endedMs];
|
|
129
|
+
break;
|
|
130
|
+
case "span":
|
|
131
|
+
times = [mutation2.facts.startMs, mutation2.facts.endMs];
|
|
132
|
+
break;
|
|
133
|
+
case "tombstone":
|
|
134
|
+
times = [];
|
|
135
|
+
break;
|
|
136
|
+
default: {
|
|
137
|
+
const exhaustive = mutation2;
|
|
138
|
+
return exhaustive;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (times.some((time) => time !== null && (time < value.range.fromMs || time >= value.range.toMs))) {
|
|
142
|
+
throw new ActivityContractError("range_not_allowed");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
var ActivityContractError = class extends Error {
|
|
148
|
+
code;
|
|
149
|
+
constructor(code) {
|
|
150
|
+
super(code);
|
|
151
|
+
this.code = code;
|
|
152
|
+
this.name = "ActivityContractError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// ../shared/dist/activity-consent.js
|
|
157
|
+
var retentionSchema = z3.strictObject({
|
|
158
|
+
contentDays: revisionSchema.min(1).default(30),
|
|
159
|
+
projectionDays: revisionSchema.min(1).default(30),
|
|
160
|
+
backupDays: z3.number().int().min(0).max(30).default(30)
|
|
161
|
+
}).readonly();
|
|
162
|
+
var scopeSchema = z3.strictObject({
|
|
163
|
+
deviceId: deviceIdSchema,
|
|
164
|
+
projectIds: z3.array(z3.string().min(1).max(512)).min(1).max(1e3).readonly(),
|
|
165
|
+
rootIds: z3.array(z3.string().min(1).max(512)).max(1e3).readonly()
|
|
166
|
+
}).readonly();
|
|
167
|
+
var common = {
|
|
168
|
+
version: revisionSchema.min(1),
|
|
169
|
+
scope: scopeSchema,
|
|
170
|
+
retention: retentionSchema.default({ contentDays: 30, projectionDays: 30, backupDays: 30 }),
|
|
171
|
+
// Explicit historical consent applies independently to metadata and content.
|
|
172
|
+
backfill: backfillReferenceSchema.unwrap().extend({ range: timeRangeSchema }).readonly().optional()
|
|
173
|
+
};
|
|
174
|
+
var consentSchema = z3.discriminatedUnion("mode", [
|
|
175
|
+
z3.strictObject({ mode: z3.literal("local-only") }),
|
|
176
|
+
z3.strictObject({
|
|
177
|
+
...common,
|
|
178
|
+
mode: z3.literal("metadata"),
|
|
179
|
+
grantedAtMs: timestampSchema
|
|
180
|
+
}),
|
|
181
|
+
z3.strictObject({
|
|
182
|
+
...common,
|
|
183
|
+
mode: z3.literal("managed-content"),
|
|
184
|
+
grantedAtMs: timestampSchema,
|
|
185
|
+
serverProcessingAcknowledged: z3.literal(true),
|
|
186
|
+
contentKinds: z3.array(contentKindSchema).min(1).max(7).readonly(),
|
|
187
|
+
externalModelTransfer: z3.literal(false).default(false)
|
|
188
|
+
})
|
|
189
|
+
]).readonly();
|
|
190
|
+
var defaultConsent = consentSchema.parse({ mode: "local-only" });
|
|
191
|
+
function authorizeUpload(consent, upload) {
|
|
192
|
+
switch (consent.mode) {
|
|
193
|
+
case "local-only":
|
|
194
|
+
throw new ActivityContractError("consent_required");
|
|
195
|
+
case "metadata":
|
|
196
|
+
case "managed-content": {
|
|
197
|
+
if (upload.deviceId !== consent.scope.deviceId || upload.consentVersion !== consent.version || !consent.scope.projectIds.includes(upload.projectId) || upload.rootId !== null && !consent.scope.rootIds.includes(upload.rootId)) {
|
|
198
|
+
throw new ActivityContractError("consent_required");
|
|
199
|
+
}
|
|
200
|
+
if (upload.toMs <= upload.fromMs)
|
|
201
|
+
throw new ActivityContractError("range_not_allowed");
|
|
202
|
+
if (upload.contentKinds.length > 0) {
|
|
203
|
+
if (consent.mode !== "managed-content" || upload.contentKinds.some((kind) => !consent.contentKinds.includes(kind))) {
|
|
204
|
+
throw new ActivityContractError("content_not_allowed");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (upload.backfill !== null) {
|
|
208
|
+
if (consent.backfill === void 0 || upload.backfill.version !== consent.backfill.version || upload.backfill.snapshotId !== consent.backfill.snapshotId || upload.backfill.journalCut !== consent.backfill.journalCut || upload.fromMs < consent.backfill.range.fromMs || upload.toMs > consent.backfill.range.toMs) {
|
|
209
|
+
throw new ActivityContractError("range_not_allowed");
|
|
210
|
+
}
|
|
211
|
+
} else if (upload.fromMs < consent.grantedAtMs) {
|
|
212
|
+
throw new ActivityContractError("range_not_allowed");
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
default: {
|
|
217
|
+
const exhaustive = consent;
|
|
218
|
+
return exhaustive;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ../shared/dist/activity-content.js
|
|
224
|
+
import { z as z4 } from "zod";
|
|
225
|
+
var MAX_CONTENT_CHUNK_BYTES = 128 * 1024;
|
|
226
|
+
var MAX_CONTENT_BYTES = 16 * 1024 * 1024;
|
|
227
|
+
var MAX_CONTENT_CHUNKS = 128;
|
|
228
|
+
var encoder = new TextEncoder();
|
|
229
|
+
var plaintextHashSchema = z4.string().regex(/^[a-f0-9]{64}$/);
|
|
230
|
+
var byteCount = z4.number().int().min(1).max(MAX_CONTENT_CHUNK_BYTES);
|
|
231
|
+
var wireSize = (value) => encoder.encode(JSON.stringify(value)).byteLength <= MAX_BATCH_BYTES;
|
|
232
|
+
var identity2 = activityBatchSchema.unwrap().pick({
|
|
233
|
+
batchId: true,
|
|
234
|
+
deviceId: true,
|
|
235
|
+
sourceDomain: true,
|
|
236
|
+
generation: true,
|
|
237
|
+
consentVersion: true,
|
|
238
|
+
projectId: true,
|
|
239
|
+
rootId: true,
|
|
240
|
+
range: true,
|
|
241
|
+
backfill: true
|
|
242
|
+
}).shape;
|
|
243
|
+
var contentChunkRefSchema = z4.strictObject({
|
|
244
|
+
index: z4.number().int().min(0).max(MAX_CONTENT_CHUNKS - 1),
|
|
245
|
+
plaintextHash: plaintextHashSchema,
|
|
246
|
+
bytes: byteCount,
|
|
247
|
+
revision: revisionSchema
|
|
248
|
+
}).readonly();
|
|
249
|
+
var contentChunkUploadSchema = z4.strictObject({
|
|
250
|
+
...identity2,
|
|
251
|
+
schemaVersion: z4.literal(2),
|
|
252
|
+
...contentChunkRefSchema.unwrap().shape,
|
|
253
|
+
body: z4.string().min(4).max(4 * Math.ceil(MAX_CONTENT_CHUNK_BYTES / 3)).regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)
|
|
254
|
+
}).refine(wireSize, "chunk JSON exceeds 256 KiB").readonly();
|
|
255
|
+
var contentBatchSchema = z4.strictObject({
|
|
256
|
+
...identity2,
|
|
257
|
+
schemaVersion: z4.literal(2),
|
|
258
|
+
sequence: activityBatchSchema.unwrap().shape.sequence,
|
|
259
|
+
journal: activityBatchSchema.unwrap().shape.journal,
|
|
260
|
+
metadataMutations: z4.array(metadataMutationSchema).max(100).readonly(),
|
|
261
|
+
chunks: z4.array(contentChunkRefSchema).min(1).max(MAX_CONTENT_CHUNKS).readonly(),
|
|
262
|
+
contentHash: plaintextHashSchema,
|
|
263
|
+
totalBytes: z4.number().int().min(1).max(MAX_CONTENT_BYTES)
|
|
264
|
+
}).superRefine((batch, ctx) => {
|
|
265
|
+
if (batch.chunks.some((chunk, index) => chunk.index !== index)) {
|
|
266
|
+
ctx.addIssue({ code: "custom", message: "chunk indexes must be ordered and contiguous" });
|
|
267
|
+
}
|
|
268
|
+
if (batch.chunks.reduce((total, chunk) => total + chunk.bytes, 0) !== batch.totalBytes) {
|
|
269
|
+
ctx.addIssue({ code: "custom", message: "chunk byte totals do not match" });
|
|
270
|
+
}
|
|
271
|
+
if (!wireSize(batch))
|
|
272
|
+
ctx.addIssue({ code: "custom", message: "batch JSON exceeds 256 KiB" });
|
|
273
|
+
if (batch.metadataMutations.length > 0) {
|
|
274
|
+
const { chunks, contentHash, totalBytes, metadataMutations, ...common2 } = batch;
|
|
275
|
+
parseActivityBatch({ ...common2, schemaVersion: 1, mutations: metadataMutations });
|
|
276
|
+
}
|
|
277
|
+
}).readonly();
|
|
278
|
+
function parseContentChunkUpload(input) {
|
|
279
|
+
return contentChunkUploadSchema.parse(input);
|
|
280
|
+
}
|
|
281
|
+
function parseContentBatch(input) {
|
|
282
|
+
return contentBatchSchema.parse(input);
|
|
283
|
+
}
|
|
284
|
+
var ContentContractError = class extends Error {
|
|
285
|
+
code;
|
|
286
|
+
constructor(code) {
|
|
287
|
+
super(code);
|
|
288
|
+
this.code = code;
|
|
289
|
+
this.name = "ContentContractError";
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
async function hashContent(bytes) {
|
|
293
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
|
|
294
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
295
|
+
}
|
|
296
|
+
var contentTables = [
|
|
297
|
+
"skills",
|
|
298
|
+
"sessions",
|
|
299
|
+
"events",
|
|
300
|
+
"loads",
|
|
301
|
+
"eval_cases",
|
|
302
|
+
"otel_spans",
|
|
303
|
+
"herdr_workspaces",
|
|
304
|
+
"herdr_tabs",
|
|
305
|
+
"herdr_panes",
|
|
306
|
+
"pane_sessions",
|
|
307
|
+
"workflow_specs",
|
|
308
|
+
"flows",
|
|
309
|
+
"flow_steps",
|
|
310
|
+
"load_candidates",
|
|
311
|
+
"recording_clock"
|
|
312
|
+
];
|
|
313
|
+
var contentTableSchema = z4.enum(contentTables);
|
|
314
|
+
var contentScalarSchema = z4.union([z4.string().max(MAX_CONTENT_BYTES), z4.number().finite(), z4.null()]);
|
|
315
|
+
var contentValuesSchema = z4.record(z4.string(), contentScalarSchema).readonly();
|
|
316
|
+
var numericColumns = {
|
|
317
|
+
skills: ["mtime_ms", "removed_at"],
|
|
318
|
+
sessions: ["started_at", "ended_at"],
|
|
319
|
+
events: ["ts", "text_length"],
|
|
320
|
+
loads: ["created_at"],
|
|
321
|
+
eval_cases: ["created_at"],
|
|
322
|
+
otel_spans: ["start_ms", "end_ms", "received_at"],
|
|
323
|
+
herdr_workspaces: ["created_ms", "closed_ms"],
|
|
324
|
+
herdr_tabs: ["created_ms", "closed_ms"],
|
|
325
|
+
herdr_panes: ["created_ms", "closed_ms", "last_seen_ms"],
|
|
326
|
+
pane_sessions: ["first_seen_ms", "last_seen_ms"],
|
|
327
|
+
workflow_specs: ["version", "created_ms"],
|
|
328
|
+
flows: ["registered_ms", "ended_ms", "start_order", "end_order"],
|
|
329
|
+
flow_steps: ["registered_ms"],
|
|
330
|
+
load_candidates: ["ts"],
|
|
331
|
+
recording_clock: ["singleton", "position"]
|
|
332
|
+
};
|
|
333
|
+
var textColumns = {
|
|
334
|
+
skills: [
|
|
335
|
+
"uri",
|
|
336
|
+
"root_id",
|
|
337
|
+
"name",
|
|
338
|
+
"description",
|
|
339
|
+
"tags_json",
|
|
340
|
+
"when_to_use",
|
|
341
|
+
"examples_json",
|
|
342
|
+
"aliases_ko_json",
|
|
343
|
+
"group_id",
|
|
344
|
+
"group_stage",
|
|
345
|
+
"invocation",
|
|
346
|
+
"body_head",
|
|
347
|
+
"digest",
|
|
348
|
+
"manifest_digest",
|
|
349
|
+
"resources_json"
|
|
350
|
+
],
|
|
351
|
+
sessions: [
|
|
352
|
+
"id",
|
|
353
|
+
"runtime",
|
|
354
|
+
"runtime_session_id",
|
|
355
|
+
"conversation_id",
|
|
356
|
+
"client_name",
|
|
357
|
+
"cwd",
|
|
358
|
+
"first_prompt",
|
|
359
|
+
"end_orders_json"
|
|
360
|
+
],
|
|
361
|
+
events: [
|
|
362
|
+
"id",
|
|
363
|
+
"kind",
|
|
364
|
+
"source",
|
|
365
|
+
"session_id",
|
|
366
|
+
"attribution_method",
|
|
367
|
+
"attribution_reason",
|
|
368
|
+
"runtime",
|
|
369
|
+
"trace_id",
|
|
370
|
+
"load_id",
|
|
371
|
+
"skill_uri",
|
|
372
|
+
"tool_use_id",
|
|
373
|
+
"text",
|
|
374
|
+
"text_digest",
|
|
375
|
+
"data_json",
|
|
376
|
+
"source_key",
|
|
377
|
+
"turn_key",
|
|
378
|
+
"call_id",
|
|
379
|
+
"span_id",
|
|
380
|
+
"recording_orders_json"
|
|
381
|
+
],
|
|
382
|
+
loads: ["load_id", "trace_id", "uri", "manifest_digest", "resources_json"],
|
|
383
|
+
eval_cases: ["id", "query", "expected_uri", "from_trace_id"],
|
|
384
|
+
otel_spans: [
|
|
385
|
+
"trace_id",
|
|
386
|
+
"span_id",
|
|
387
|
+
"parent_span_id",
|
|
388
|
+
"name",
|
|
389
|
+
"runtime",
|
|
390
|
+
"conversation_id",
|
|
391
|
+
"turn_key",
|
|
392
|
+
"call_id",
|
|
393
|
+
"recording_orders_json"
|
|
394
|
+
],
|
|
395
|
+
herdr_workspaces: ["id", "label"],
|
|
396
|
+
herdr_tabs: ["id", "workspace_id", "label"],
|
|
397
|
+
herdr_panes: ["id", "workspace_id", "tab_id", "label", "cwd", "agent"],
|
|
398
|
+
pane_sessions: ["pane_id", "agent", "source", "agent_session_value", "session_id"],
|
|
399
|
+
workflow_specs: ["id", "name", "body_json", "digest"],
|
|
400
|
+
flows: [
|
|
401
|
+
"id",
|
|
402
|
+
"workspace_id",
|
|
403
|
+
"tab_id",
|
|
404
|
+
"spec_id",
|
|
405
|
+
"label",
|
|
406
|
+
"start_event_ids_json",
|
|
407
|
+
"end_event_ids_json",
|
|
408
|
+
"end_sessions_json",
|
|
409
|
+
"end_spans_json",
|
|
410
|
+
"start_order_domain",
|
|
411
|
+
"end_order_domain"
|
|
412
|
+
],
|
|
413
|
+
flow_steps: ["flow_id", "pane_id", "step_id"],
|
|
414
|
+
load_candidates: ["load_id", "session_id"],
|
|
415
|
+
recording_clock: ["domain"]
|
|
416
|
+
};
|
|
417
|
+
var nonTimeColumns = /* @__PURE__ */ new Set(["text_length", "version", "start_order", "end_order", "singleton", "position"]);
|
|
418
|
+
var contentRowSchema = z4.strictObject({
|
|
419
|
+
table: contentTableSchema,
|
|
420
|
+
key: z4.string().max(MAX_CONTENT_BYTES),
|
|
421
|
+
revision: revisionSchema,
|
|
422
|
+
operation: z4.enum(["upsert", "delete"]),
|
|
423
|
+
sourceOrder: z4.number().int().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
424
|
+
values: contentValuesSchema.nullable()
|
|
425
|
+
}).superRefine((row, ctx) => {
|
|
426
|
+
if (row.operation === "delete" !== (row.values === null)) {
|
|
427
|
+
ctx.addIssue({ code: "custom", message: "delete requires null values; upsert requires values" });
|
|
428
|
+
}
|
|
429
|
+
for (const [column, value] of Object.entries(row.values ?? {})) {
|
|
430
|
+
const numeric = numericColumns[row.table].includes(column);
|
|
431
|
+
if (!numeric && !textColumns[row.table].includes(column)) {
|
|
432
|
+
ctx.addIssue({ code: "custom", path: ["values", column], message: "unknown source column" });
|
|
433
|
+
} else if (value !== null && typeof value !== (numeric ? "number" : "string")) {
|
|
434
|
+
ctx.addIssue({ code: "custom", path: ["values", column], message: "incorrect source column type" });
|
|
435
|
+
} else if (numeric && !nonTimeColumns.has(column) && !timestampSchema.nullable().safeParse(value).success) {
|
|
436
|
+
ctx.addIssue({ code: "custom", path: ["values", column], message: "invalid source timestamp" });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}).readonly();
|
|
440
|
+
var contentDocumentSchema = z4.strictObject({
|
|
441
|
+
schemaVersion: z4.literal(2),
|
|
442
|
+
rows: z4.array(contentRowSchema).max(1e4).readonly()
|
|
443
|
+
}).refine((document) => encoder.encode(JSON.stringify(document)).byteLength <= MAX_CONTENT_BYTES, "document exceeds 16 MiB").readonly();
|
|
444
|
+
var localRowSchema = z4.strictObject({
|
|
445
|
+
...contentRowSchema.unwrap().shape,
|
|
446
|
+
beforeValues: contentValuesSchema.nullable().optional()
|
|
447
|
+
}).readonly();
|
|
448
|
+
function granted(consent, kinds) {
|
|
449
|
+
return consent.mode === "managed-content" && kinds.every((kind) => consent.contentKinds.includes(kind));
|
|
450
|
+
}
|
|
451
|
+
function keyKinds(table) {
|
|
452
|
+
return table === "skills" ? ["path", "private-skills"] : ["path"];
|
|
453
|
+
}
|
|
454
|
+
function columnKinds(table, column) {
|
|
455
|
+
if (numericColumns[table].includes(column))
|
|
456
|
+
return [];
|
|
457
|
+
if (column.endsWith("_json"))
|
|
458
|
+
return contentKinds;
|
|
459
|
+
if (table === "sessions" && column === "first_prompt")
|
|
460
|
+
return ["prompt"];
|
|
461
|
+
if (table === "eval_cases" && column === "query")
|
|
462
|
+
return ["query"];
|
|
463
|
+
if (column === "cwd")
|
|
464
|
+
return ["path"];
|
|
465
|
+
if (column === "uri" || column === "skill_uri" || column === "expected_uri") {
|
|
466
|
+
return ["path", "private-skills"];
|
|
467
|
+
}
|
|
468
|
+
if (table === "skills")
|
|
469
|
+
return ["private-skills"];
|
|
470
|
+
return contentKinds;
|
|
471
|
+
}
|
|
472
|
+
function authorizeRows(consent, scope) {
|
|
473
|
+
authorizeUpload(consent, scope);
|
|
474
|
+
}
|
|
475
|
+
function checkTimes(row, scope) {
|
|
476
|
+
for (const column of numericColumns[row.table]) {
|
|
477
|
+
if (nonTimeColumns.has(column))
|
|
478
|
+
continue;
|
|
479
|
+
const value = row.values?.[column];
|
|
480
|
+
if (typeof value === "number" && (value < scope.fromMs || value >= scope.toMs)) {
|
|
481
|
+
throw new ActivityContractError("range_not_allowed");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function allowsColumn(consent, scope, table, column) {
|
|
486
|
+
const kinds = columnKinds(table, column);
|
|
487
|
+
return kinds.length === 0 || granted(consent, kinds) && kinds.every((kind) => scope.contentKinds.includes(kind));
|
|
488
|
+
}
|
|
489
|
+
function allowsKey(consent, scope, table) {
|
|
490
|
+
const kinds = keyKinds(table);
|
|
491
|
+
return granted(consent, kinds) && kinds.every((kind) => scope.contentKinds.includes(kind));
|
|
492
|
+
}
|
|
493
|
+
async function transformContentRows(consent, scope, rows) {
|
|
494
|
+
if (consent.mode === "local-only")
|
|
495
|
+
return null;
|
|
496
|
+
authorizeRows(consent, scope);
|
|
497
|
+
const transformed = [];
|
|
498
|
+
for (const input of rows) {
|
|
499
|
+
const local = localRowSchema.parse(input);
|
|
500
|
+
const { beforeValues, ...wire } = local;
|
|
501
|
+
const row = contentRowSchema.parse(wire);
|
|
502
|
+
checkTimes(row, scope);
|
|
503
|
+
if (beforeValues !== void 0 && beforeValues !== null) {
|
|
504
|
+
checkTimes(contentRowSchema.parse({ ...wire, operation: "upsert", values: beforeValues }), scope);
|
|
505
|
+
}
|
|
506
|
+
const key = allowsKey(consent, scope, row.table) ? row.key : await hashContent(encoder.encode(`${row.table}\0${row.key}`));
|
|
507
|
+
const values = row.values === null ? null : Object.fromEntries(Object.entries(row.values).filter(([column]) => allowsColumn(consent, scope, row.table, column)));
|
|
508
|
+
transformed.push({ ...row, key, values });
|
|
509
|
+
}
|
|
510
|
+
return contentDocumentSchema.parse({ schemaVersion: 2, rows: transformed });
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// ../shared/dist/activity-sync.js
|
|
514
|
+
import { z as z5 } from "zod";
|
|
515
|
+
var MAX_SNAPSHOT_PAGES = 128;
|
|
516
|
+
var MAX_SNAPSHOT_ROWS = 1e4;
|
|
517
|
+
var MAX_SNAPSHOT_BYTES = MAX_CONTENT_BYTES;
|
|
518
|
+
var MAX_SNAPSHOT_PAGE_BYTES = MAX_CONTENT_BYTES;
|
|
519
|
+
var MAX_SNAPSHOT_PAGE_ROWS = 100;
|
|
520
|
+
var id = z5.string().min(1).max(512).refine((value) => !value.includes("\0"));
|
|
521
|
+
var identity3 = activityBatchSchema.unwrap().pick({
|
|
522
|
+
deviceId: true,
|
|
523
|
+
sourceDomain: true,
|
|
524
|
+
generation: true
|
|
525
|
+
}).shape;
|
|
526
|
+
var migrationReferenceSchema = z5.strictObject({
|
|
527
|
+
...identity3,
|
|
528
|
+
snapshotId: id
|
|
529
|
+
}).readonly();
|
|
530
|
+
var snapshotCountsSchema = z5.record(z5.enum(contentTables), revisionSchema);
|
|
531
|
+
var migrationBeginSchema = z5.strictObject({
|
|
532
|
+
...migrationReferenceSchema.unwrap().shape,
|
|
533
|
+
schemaVersion: z5.literal(1),
|
|
534
|
+
purpose: z5.enum(["initial", "backfill"]).default("initial"),
|
|
535
|
+
...activityBatchSchema.unwrap().pick({
|
|
536
|
+
consentVersion: true,
|
|
537
|
+
projectId: true,
|
|
538
|
+
rootId: true,
|
|
539
|
+
range: true
|
|
540
|
+
}).shape,
|
|
541
|
+
backfill: activityBatchSchema.unwrap().shape.backfill,
|
|
542
|
+
cut: revisionSchema,
|
|
543
|
+
pageCount: z5.number().int().min(1).max(MAX_SNAPSHOT_PAGES),
|
|
544
|
+
counts: snapshotCountsSchema,
|
|
545
|
+
snapshotHash: plaintextHashSchema
|
|
546
|
+
}).superRefine((value, ctx) => {
|
|
547
|
+
if (value.backfill !== null && (value.backfill.snapshotId !== value.snapshotId || value.backfill.journalCut !== value.cut)) {
|
|
548
|
+
ctx.addIssue({ code: "custom", message: "backfill must identify this snapshot and cut" });
|
|
549
|
+
}
|
|
550
|
+
if (value.backfill === null && (value.purpose !== "initial" || Object.values(value.counts).some((count2) => count2 !== 0))) {
|
|
551
|
+
ctx.addIssue({ code: "custom", message: "live-only baseline must contain no historical rows" });
|
|
552
|
+
}
|
|
553
|
+
if (Object.values(value.counts).reduce((a, b) => a + b, 0) > MAX_SNAPSHOT_ROWS) {
|
|
554
|
+
ctx.addIssue({ code: "custom", message: "snapshot exceeds row limit" });
|
|
555
|
+
}
|
|
556
|
+
}).readonly();
|
|
557
|
+
var migrationPageSchema = z5.strictObject({
|
|
558
|
+
...migrationReferenceSchema.unwrap().shape,
|
|
559
|
+
index: z5.number().int().min(0).max(MAX_SNAPSHOT_PAGES - 1),
|
|
560
|
+
batchId: id,
|
|
561
|
+
chunks: z5.array(contentChunkRefSchema).min(1).max(128).readonly(),
|
|
562
|
+
contentHash: plaintextHashSchema,
|
|
563
|
+
totalBytes: z5.number().int().positive().max(MAX_SNAPSHOT_PAGE_BYTES),
|
|
564
|
+
counts: snapshotCountsSchema
|
|
565
|
+
}).superRefine((value, ctx) => {
|
|
566
|
+
if (value.chunks.some((part, index) => part.index !== index) || value.chunks.reduce((sum, part) => sum + part.bytes, 0) !== value.totalBytes) {
|
|
567
|
+
ctx.addIssue({ code: "custom", message: "invalid contiguous chunk lengths" });
|
|
568
|
+
}
|
|
569
|
+
}).readonly();
|
|
570
|
+
var statusFields = {
|
|
571
|
+
migration: migrationBeginSchema,
|
|
572
|
+
rollbackRequested: z5.boolean(),
|
|
573
|
+
stagedPages: z5.array(migrationPageSchema).max(MAX_SNAPSHOT_PAGES).readonly()
|
|
574
|
+
};
|
|
575
|
+
var migrationStatusSchema = z5.discriminatedUnion("state", [
|
|
576
|
+
z5.strictObject({ ...statusFields, state: z5.literal("staging"), accepted: z5.literal(false), cursor: z5.null() }),
|
|
577
|
+
z5.strictObject({ ...statusFields, state: z5.literal("abandoned"), accepted: z5.literal(false), cursor: z5.null() }),
|
|
578
|
+
z5.strictObject({
|
|
579
|
+
...statusFields,
|
|
580
|
+
state: z5.literal("complete"),
|
|
581
|
+
accepted: z5.literal(true),
|
|
582
|
+
cursor: z5.strictObject({
|
|
583
|
+
sequence: revisionSchema,
|
|
584
|
+
journalThrough: revisionSchema,
|
|
585
|
+
changeSeq: revisionSchema.min(1)
|
|
586
|
+
}).readonly()
|
|
587
|
+
})
|
|
588
|
+
]).readonly();
|
|
589
|
+
var snapshotPageDocumentSchema = z5.strictObject({
|
|
590
|
+
schemaVersion: contentDocumentSchema.unwrap().shape.schemaVersion,
|
|
591
|
+
rows: z5.array(contentRowSchema).max(MAX_SNAPSHOT_PAGE_ROWS).readonly()
|
|
592
|
+
}).refine((value) => new TextEncoder().encode(JSON.stringify(value)).length <= MAX_SNAPSHOT_PAGE_BYTES, "snapshot page exceeds byte limit").readonly();
|
|
593
|
+
var MigrationContractError = class extends Error {
|
|
594
|
+
code;
|
|
595
|
+
status = 409;
|
|
596
|
+
constructor(code) {
|
|
597
|
+
super(code);
|
|
598
|
+
this.code = code;
|
|
599
|
+
this.name = "MigrationContractError";
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
function canonicalSnapshotRow(row) {
|
|
603
|
+
return JSON.stringify({
|
|
604
|
+
table: row.table,
|
|
605
|
+
key: row.key,
|
|
606
|
+
revision: row.revision,
|
|
607
|
+
operation: row.operation,
|
|
608
|
+
sourceOrder: row.sourceOrder,
|
|
609
|
+
values: row.values === null ? null : Object.fromEntries(Object.entries(row.values).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
async function summarizeSnapshot(rows) {
|
|
613
|
+
if (rows.length > MAX_SNAPSHOT_ROWS)
|
|
614
|
+
throw new MigrationContractError("snapshot_limit");
|
|
615
|
+
const counts = snapshotCountsSchema.parse(Object.fromEntries(contentTables.map((table) => [table, 0])));
|
|
616
|
+
const ordered = [...rows].sort((a, b) => contentTables.indexOf(a.table) - contentTables.indexOf(b.table) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
617
|
+
let previous;
|
|
618
|
+
for (const row of ordered) {
|
|
619
|
+
if (previous?.table === row.table && previous.key === row.key) {
|
|
620
|
+
throw new MigrationContractError("snapshot_integrity");
|
|
621
|
+
}
|
|
622
|
+
counts[row.table]++;
|
|
623
|
+
previous = row;
|
|
624
|
+
}
|
|
625
|
+
const bytes = new TextEncoder().encode(`[${ordered.map(canonicalSnapshotRow).join(",")}]`);
|
|
626
|
+
if (bytes.length > MAX_SNAPSHOT_BYTES)
|
|
627
|
+
throw new MigrationContractError("snapshot_limit");
|
|
628
|
+
return { counts, snapshotHash: await hashContent(bytes), bytes: bytes.length };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ../shared/dist/activity-runtime.js
|
|
632
|
+
import { z as z6 } from "zod";
|
|
633
|
+
var ingestCountersSchema = z6.strictObject({
|
|
634
|
+
accepted: revisionSchema,
|
|
635
|
+
rejected: revisionSchema,
|
|
636
|
+
dropped: revisionSchema,
|
|
637
|
+
lastError: z6.strictObject({ ts: timestampSchema, code: z6.string().min(1).max(512) }).optional()
|
|
638
|
+
});
|
|
639
|
+
var analysisRuntimeSchema = z6.strictObject({
|
|
640
|
+
schemaVersion: z6.literal(1),
|
|
641
|
+
capturedAtMs: timestampSchema,
|
|
642
|
+
activeRequests: z6.array(z6.string().min(1).max(512)).max(1e4),
|
|
643
|
+
ingest: ingestCountersSchema,
|
|
644
|
+
tz: z6.string().min(1).max(100)
|
|
645
|
+
}).readonly();
|
|
646
|
+
var runtimeCommitSchema = z6.strictObject({
|
|
647
|
+
schemaVersion: z6.literal(1),
|
|
648
|
+
...activityBatchSchema.unwrap().pick({
|
|
649
|
+
deviceId: true,
|
|
650
|
+
sourceDomain: true,
|
|
651
|
+
generation: true,
|
|
652
|
+
consentVersion: true,
|
|
653
|
+
projectId: true,
|
|
654
|
+
rootId: true,
|
|
655
|
+
range: true,
|
|
656
|
+
backfill: true
|
|
657
|
+
}).shape,
|
|
658
|
+
batchId: z6.string().uuid(),
|
|
659
|
+
sequence: revisionSchema.min(1),
|
|
660
|
+
sourceCut: revisionSchema,
|
|
661
|
+
capturedAtMs: timestampSchema,
|
|
662
|
+
chunks: z6.array(contentChunkRefSchema).min(1).max(128),
|
|
663
|
+
contentHash: plaintextHashSchema,
|
|
664
|
+
totalBytes: revisionSchema.min(1).max(16 * 1024 * 1024)
|
|
665
|
+
}).readonly();
|
|
666
|
+
export {
|
|
667
|
+
ActivityContractError,
|
|
668
|
+
ContentContractError,
|
|
669
|
+
MAX_CONTENT_BYTES,
|
|
670
|
+
MAX_CONTENT_CHUNK_BYTES,
|
|
671
|
+
MAX_SNAPSHOT_BYTES,
|
|
672
|
+
MAX_SNAPSHOT_PAGES,
|
|
673
|
+
MAX_SNAPSHOT_PAGE_BYTES,
|
|
674
|
+
MAX_SNAPSHOT_ROWS,
|
|
675
|
+
analysisRuntimeSchema,
|
|
676
|
+
authorizeUpload,
|
|
677
|
+
consentSchema,
|
|
678
|
+
contentChunkRefSchema,
|
|
679
|
+
contentDocumentSchema,
|
|
680
|
+
contentKinds,
|
|
681
|
+
deploymentOriginSchema,
|
|
682
|
+
ingestCountersSchema,
|
|
683
|
+
migrationBeginSchema,
|
|
684
|
+
migrationPageSchema,
|
|
685
|
+
migrationReferenceSchema,
|
|
686
|
+
migrationStatusSchema,
|
|
687
|
+
parseContentBatch,
|
|
688
|
+
parseContentChunkUpload,
|
|
689
|
+
runtimeCommitSchema,
|
|
690
|
+
snapshotPageDocumentSchema,
|
|
691
|
+
summarizeSnapshot,
|
|
692
|
+
transformContentRows
|
|
693
|
+
};
|