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,437 @@
|
|
|
1
|
+
// ../shared/dist/activity-commands.js
|
|
2
|
+
import { z as z5 } from "zod";
|
|
3
|
+
|
|
4
|
+
// ../shared/dist/activity-schema.js
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var identity = z.string().min(1).max(512).refine((value) => !value.includes("\0"));
|
|
7
|
+
var accountIdSchema = identity.brand();
|
|
8
|
+
var deviceIdSchema = identity.brand();
|
|
9
|
+
var sourceDomainSchema = identity.brand();
|
|
10
|
+
var sourceIdSchema = identity.brand();
|
|
11
|
+
var revisionSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
12
|
+
var timestampSchema = z.number().int().min(-864e13).max(864e13);
|
|
13
|
+
var recordingOrdersSchema = z.record(sourceDomainSchema, revisionSchema).readonly();
|
|
14
|
+
var timeRangeSchema = z.strictObject({
|
|
15
|
+
fromMs: timestampSchema,
|
|
16
|
+
toMs: timestampSchema
|
|
17
|
+
}).refine((value) => value.toMs > value.fromMs).readonly();
|
|
18
|
+
var backfillReferenceSchema = z.strictObject({
|
|
19
|
+
version: revisionSchema.min(1),
|
|
20
|
+
snapshotId: identity,
|
|
21
|
+
journalCut: revisionSchema
|
|
22
|
+
}).readonly();
|
|
23
|
+
var count = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable();
|
|
24
|
+
var runtime = z.enum(["claude-code", "codex", "gemini", "cursor", "omo", "gajae", "openclaw", "unknown"]);
|
|
25
|
+
var sessionFactsSchema = z.strictObject({
|
|
26
|
+
runtime,
|
|
27
|
+
startedMs: timestampSchema,
|
|
28
|
+
endedMs: timestampSchema.nullable(),
|
|
29
|
+
automated: z.boolean().nullable()
|
|
30
|
+
}).readonly();
|
|
31
|
+
var eventFactsSchema = z.strictObject({
|
|
32
|
+
sessionId: sourceIdSchema,
|
|
33
|
+
kind: z.enum([
|
|
34
|
+
"session_start",
|
|
35
|
+
"session_end",
|
|
36
|
+
"prompt",
|
|
37
|
+
"search",
|
|
38
|
+
"load",
|
|
39
|
+
"read_file",
|
|
40
|
+
"native_skill",
|
|
41
|
+
"tool_call",
|
|
42
|
+
"llm_call",
|
|
43
|
+
"error",
|
|
44
|
+
"skill_request"
|
|
45
|
+
]),
|
|
46
|
+
timestampMs: timestampSchema,
|
|
47
|
+
sourceOrder: revisionSchema.nullable(),
|
|
48
|
+
recordingOrders: recordingOrdersSchema,
|
|
49
|
+
sourceKey: sourceIdSchema.nullable(),
|
|
50
|
+
status: z.enum(["in_progress", "succeeded", "failed", "cancelled", "unknown"]),
|
|
51
|
+
inputTokens: count,
|
|
52
|
+
outputTokens: count
|
|
53
|
+
}).readonly();
|
|
54
|
+
var spanFactsSchema = z.strictObject({
|
|
55
|
+
traceId: sourceIdSchema,
|
|
56
|
+
spanId: sourceIdSchema,
|
|
57
|
+
parentSpanId: sourceIdSchema.nullable(),
|
|
58
|
+
sessionId: sourceIdSchema.nullable(),
|
|
59
|
+
startMs: timestampSchema.nullable(),
|
|
60
|
+
endMs: timestampSchema.nullable(),
|
|
61
|
+
recordingOrders: recordingOrdersSchema,
|
|
62
|
+
inputTokens: count,
|
|
63
|
+
outputTokens: count
|
|
64
|
+
}).readonly();
|
|
65
|
+
var mutation = {
|
|
66
|
+
key: sourceIdSchema,
|
|
67
|
+
revision: revisionSchema
|
|
68
|
+
};
|
|
69
|
+
var metadataMutationSchema = z.discriminatedUnion("entity", [
|
|
70
|
+
z.strictObject({ ...mutation, entity: z.literal("session"), facts: sessionFactsSchema }),
|
|
71
|
+
z.strictObject({ ...mutation, entity: z.literal("event"), facts: eventFactsSchema }),
|
|
72
|
+
z.strictObject({ ...mutation, entity: z.literal("span"), facts: spanFactsSchema }),
|
|
73
|
+
z.strictObject({
|
|
74
|
+
...mutation,
|
|
75
|
+
entity: z.literal("tombstone"),
|
|
76
|
+
target: z.enum(["session", "event", "span"])
|
|
77
|
+
})
|
|
78
|
+
]).readonly();
|
|
79
|
+
var activityBatchSchema = z.strictObject({
|
|
80
|
+
schemaVersion: z.literal(1),
|
|
81
|
+
batchId: identity,
|
|
82
|
+
// Account identity comes only from the verified principal, never this payload.
|
|
83
|
+
deviceId: deviceIdSchema,
|
|
84
|
+
sourceDomain: sourceDomainSchema,
|
|
85
|
+
generation: revisionSchema.min(1),
|
|
86
|
+
consentVersion: revisionSchema.min(1),
|
|
87
|
+
projectId: identity,
|
|
88
|
+
rootId: identity.nullable(),
|
|
89
|
+
range: timeRangeSchema,
|
|
90
|
+
backfill: backfillReferenceSchema.nullable(),
|
|
91
|
+
sequence: revisionSchema.min(1),
|
|
92
|
+
journal: z.strictObject({ from: revisionSchema, through: revisionSchema }).refine((range2) => range2.through >= range2.from).readonly(),
|
|
93
|
+
mutations: z.array(metadataMutationSchema).min(1).max(100).readonly()
|
|
94
|
+
}).readonly();
|
|
95
|
+
var contentKinds = [
|
|
96
|
+
"prompt",
|
|
97
|
+
"query",
|
|
98
|
+
"args",
|
|
99
|
+
"error",
|
|
100
|
+
"path",
|
|
101
|
+
"span-attributes",
|
|
102
|
+
"private-skills"
|
|
103
|
+
];
|
|
104
|
+
var contentKindSchema = z.enum(contentKinds);
|
|
105
|
+
var MAX_BATCH_BYTES = 256 * 1024;
|
|
106
|
+
|
|
107
|
+
// ../shared/dist/activity-dashboard.js
|
|
108
|
+
import { z as z4 } from "zod";
|
|
109
|
+
|
|
110
|
+
// ../shared/dist/activity-consent.js
|
|
111
|
+
import { z as z2 } from "zod";
|
|
112
|
+
var retentionSchema = z2.strictObject({
|
|
113
|
+
contentDays: revisionSchema.min(1).default(30),
|
|
114
|
+
projectionDays: revisionSchema.min(1).default(30),
|
|
115
|
+
backupDays: z2.number().int().min(0).max(30).default(30)
|
|
116
|
+
}).readonly();
|
|
117
|
+
var scopeSchema = z2.strictObject({
|
|
118
|
+
deviceId: deviceIdSchema,
|
|
119
|
+
projectIds: z2.array(z2.string().min(1).max(512)).min(1).max(1e3).readonly(),
|
|
120
|
+
rootIds: z2.array(z2.string().min(1).max(512)).max(1e3).readonly()
|
|
121
|
+
}).readonly();
|
|
122
|
+
var common = {
|
|
123
|
+
version: revisionSchema.min(1),
|
|
124
|
+
scope: scopeSchema,
|
|
125
|
+
retention: retentionSchema.default({ contentDays: 30, projectionDays: 30, backupDays: 30 }),
|
|
126
|
+
// Explicit historical consent applies independently to metadata and content.
|
|
127
|
+
backfill: backfillReferenceSchema.unwrap().extend({ range: timeRangeSchema }).readonly().optional()
|
|
128
|
+
};
|
|
129
|
+
var consentSchema = z2.discriminatedUnion("mode", [
|
|
130
|
+
z2.strictObject({ mode: z2.literal("local-only") }),
|
|
131
|
+
z2.strictObject({
|
|
132
|
+
...common,
|
|
133
|
+
mode: z2.literal("metadata"),
|
|
134
|
+
grantedAtMs: timestampSchema
|
|
135
|
+
}),
|
|
136
|
+
z2.strictObject({
|
|
137
|
+
...common,
|
|
138
|
+
mode: z2.literal("managed-content"),
|
|
139
|
+
grantedAtMs: timestampSchema,
|
|
140
|
+
serverProcessingAcknowledged: z2.literal(true),
|
|
141
|
+
contentKinds: z2.array(contentKindSchema).min(1).max(7).readonly(),
|
|
142
|
+
externalModelTransfer: z2.literal(false).default(false)
|
|
143
|
+
})
|
|
144
|
+
]).readonly();
|
|
145
|
+
var defaultConsent = consentSchema.parse({ mode: "local-only" });
|
|
146
|
+
|
|
147
|
+
// ../shared/dist/activity-query.js
|
|
148
|
+
import { z as z3 } from "zod";
|
|
149
|
+
var runtime2 = z3.enum(["claude-code", "codex", "gemini", "cursor", "omo", "gajae", "openclaw", "unknown"]);
|
|
150
|
+
var status = z3.enum(["not_attempted", "in_progress", "succeeded", "failed", "cancelled", "unknown"]);
|
|
151
|
+
var automated = z3.enum(["exclude", "include", "only"]);
|
|
152
|
+
var activityFilterSchema = z3.strictObject({
|
|
153
|
+
from: timestampSchema.optional(),
|
|
154
|
+
to: timestampSchema.optional(),
|
|
155
|
+
runtime: z3.array(runtime2).optional(),
|
|
156
|
+
skill: z3.array(z3.string()).optional(),
|
|
157
|
+
state: z3.array(z3.enum(["loaded", "exposed_only", "no_match", "aborted", "not_used"])).optional(),
|
|
158
|
+
dow: z3.number().int().min(0).max(6).optional(),
|
|
159
|
+
hour: z3.number().int().min(0).max(23).optional(),
|
|
160
|
+
hourSpan: z3.number().int().min(1).max(24).optional(),
|
|
161
|
+
q: z3.string().optional(),
|
|
162
|
+
searchStatus: z3.array(status).optional(),
|
|
163
|
+
loadStatus: z3.array(status).optional(),
|
|
164
|
+
searchResult: z3.array(z3.enum(["candidates_found", "no_candidates"])).optional(),
|
|
165
|
+
automated: z3.enum(["include", "only"]).optional()
|
|
166
|
+
});
|
|
167
|
+
var filter = activityFilterSchema.default({});
|
|
168
|
+
var range = { from: timestampSchema, to: timestampSchema };
|
|
169
|
+
var activityQuerySchema = z3.discriminatedUnion("kind", [
|
|
170
|
+
z3.strictObject({ kind: z3.literal("skills") }),
|
|
171
|
+
z3.strictObject({ kind: z3.literal("workflow-versions"), name: z3.string().min(1).max(64) }),
|
|
172
|
+
z3.strictObject({ kind: z3.literal("sessions"), filter }),
|
|
173
|
+
z3.strictObject({ kind: z3.literal("trace"), sessionId: z3.string().min(1) }),
|
|
174
|
+
z3.strictObject({
|
|
175
|
+
kind: z3.literal("flow"),
|
|
176
|
+
filter,
|
|
177
|
+
unit: z3.enum(["first_load", "all_loads", "search_requests", "load_requests"]).default("first_load"),
|
|
178
|
+
top: z3.number().int().min(1).max(100).default(20)
|
|
179
|
+
}),
|
|
180
|
+
z3.strictObject({
|
|
181
|
+
kind: z3.literal("heatmap"),
|
|
182
|
+
filter,
|
|
183
|
+
tz: z3.string().min(1).max(100),
|
|
184
|
+
weekStart: z3.union([z3.literal(0), z3.literal(1)]).default(1),
|
|
185
|
+
bucketHours: z3.union([z3.literal(1), z3.literal(2), z3.literal(4)]).default(1)
|
|
186
|
+
}),
|
|
187
|
+
z3.strictObject({ kind: z3.literal("skill-week"), filter }),
|
|
188
|
+
z3.strictObject({ kind: z3.literal("stats"), filter }),
|
|
189
|
+
z3.strictObject({
|
|
190
|
+
kind: z3.literal("flows"),
|
|
191
|
+
from: timestampSchema.optional(),
|
|
192
|
+
to: timestampSchema.optional(),
|
|
193
|
+
limit: z3.number().int().min(1).max(100).default(20),
|
|
194
|
+
automated: automated.default("exclude"),
|
|
195
|
+
cursor: z3.strictObject({ orderMs: timestampSchema, id: z3.string().min(1) }).optional()
|
|
196
|
+
}),
|
|
197
|
+
z3.strictObject({
|
|
198
|
+
kind: z3.literal("flow-report"),
|
|
199
|
+
flowId: z3.string().min(1),
|
|
200
|
+
from: timestampSchema.optional(),
|
|
201
|
+
to: timestampSchema.optional(),
|
|
202
|
+
limit: z3.number().int().min(1).max(100).default(100),
|
|
203
|
+
automated: automated.default("exclude")
|
|
204
|
+
}),
|
|
205
|
+
z3.strictObject({
|
|
206
|
+
kind: z3.literal("session-report"),
|
|
207
|
+
sessionId: z3.string().min(1),
|
|
208
|
+
automated: automated.default("exclude")
|
|
209
|
+
}),
|
|
210
|
+
z3.strictObject({
|
|
211
|
+
kind: z3.literal("skill-usage"),
|
|
212
|
+
...range,
|
|
213
|
+
detailLimit: z3.number().int().min(0).max(100).default(20),
|
|
214
|
+
automated: automated.default("exclude")
|
|
215
|
+
})
|
|
216
|
+
]);
|
|
217
|
+
var reportScopeSchema = activityBatchSchema.unwrap().pick({
|
|
218
|
+
deviceId: true,
|
|
219
|
+
sourceDomain: true,
|
|
220
|
+
generation: true,
|
|
221
|
+
consentVersion: true,
|
|
222
|
+
projectId: true,
|
|
223
|
+
rootId: true,
|
|
224
|
+
range: true,
|
|
225
|
+
backfill: true
|
|
226
|
+
});
|
|
227
|
+
var reportRequestSchema = z3.strictObject({
|
|
228
|
+
schemaVersion: z3.literal(1),
|
|
229
|
+
requestId: z3.string().uuid(),
|
|
230
|
+
...reportScopeSchema.shape,
|
|
231
|
+
tz: z3.string().min(1).max(100).default("UTC"),
|
|
232
|
+
query: activityQuerySchema
|
|
233
|
+
}).readonly();
|
|
234
|
+
var sourceRevisionSchema = z3.strictObject({
|
|
235
|
+
sequence: revisionSchema,
|
|
236
|
+
journalThrough: revisionSchema
|
|
237
|
+
}).readonly();
|
|
238
|
+
var reportReferenceSchema = z3.strictObject({
|
|
239
|
+
deviceId: reportScopeSchema.shape.deviceId,
|
|
240
|
+
sourceDomain: reportScopeSchema.shape.sourceDomain,
|
|
241
|
+
generation: reportScopeSchema.shape.generation,
|
|
242
|
+
jobId: z3.string().uuid()
|
|
243
|
+
}).readonly();
|
|
244
|
+
|
|
245
|
+
// ../shared/dist/activity-dashboard.js
|
|
246
|
+
var dashboardSourceSchema = z4.strictObject({
|
|
247
|
+
deviceId: deviceIdSchema,
|
|
248
|
+
sourceDomain: sourceDomainSchema
|
|
249
|
+
}).readonly();
|
|
250
|
+
var timestamp = z4.number().int().min(-864e13).max(864e13);
|
|
251
|
+
var dashboardSourceHeadSchema = dashboardSourceSchema.unwrap().extend({
|
|
252
|
+
sourceSequence: z4.number().int().nonnegative(),
|
|
253
|
+
journalThrough: z4.number().int().nonnegative(),
|
|
254
|
+
runtimeSequence: z4.number().int().positive().nullable(),
|
|
255
|
+
capturedAtMs: timestamp.nullable(),
|
|
256
|
+
receivedAtMs: timestamp.nullable()
|
|
257
|
+
}).readonly();
|
|
258
|
+
var dashboardDeviceSchema = z4.strictObject({
|
|
259
|
+
deviceId: deviceIdSchema,
|
|
260
|
+
createdAt: timestamp,
|
|
261
|
+
revokedAt: timestamp.nullable(),
|
|
262
|
+
consentVersion: z4.number().int().nonnegative(),
|
|
263
|
+
consent: consentSchema
|
|
264
|
+
}).readonly();
|
|
265
|
+
var dashboardProfileSchema = dashboardSourceHeadSchema.unwrap().extend({
|
|
266
|
+
availability: z4.enum(["local-only", "metadata-only", "partial", "awaiting-runtime", "ready", "revoked"])
|
|
267
|
+
}).readonly();
|
|
268
|
+
var dashboardProfilesSchema = z4.strictObject({
|
|
269
|
+
schemaVersion: z4.literal(1),
|
|
270
|
+
ingestEnabled: z4.boolean(),
|
|
271
|
+
devices: z4.array(dashboardDeviceSchema).readonly(),
|
|
272
|
+
profiles: z4.array(dashboardProfileSchema).readonly()
|
|
273
|
+
}).readonly();
|
|
274
|
+
var dashboardQuerySchema = z4.strictObject({
|
|
275
|
+
profile: dashboardSourceSchema,
|
|
276
|
+
requestId: z4.string().uuid(),
|
|
277
|
+
query: activityQuerySchema,
|
|
278
|
+
tz: z4.string().min(1).max(100).default("UTC")
|
|
279
|
+
}).readonly();
|
|
280
|
+
var dashboardReferenceSchema = z4.strictObject({
|
|
281
|
+
profile: dashboardSourceSchema,
|
|
282
|
+
jobId: z4.string().uuid()
|
|
283
|
+
}).readonly();
|
|
284
|
+
var dashboardResultPartRequestSchema = dashboardReferenceSchema.unwrap().extend({
|
|
285
|
+
part: z4.number().int().nonnegative().max(4095)
|
|
286
|
+
}).readonly();
|
|
287
|
+
var dashboardReportStatusSchema = z4.object({
|
|
288
|
+
schemaVersion: z4.literal(1),
|
|
289
|
+
jobId: z4.string().uuid(),
|
|
290
|
+
state: z4.enum(["preparing", "queued", "running", "complete", "failed"]),
|
|
291
|
+
generatedAt: timestamp,
|
|
292
|
+
sourceCapturedAt: timestamp,
|
|
293
|
+
sourceReceivedAt: timestamp.nullable(),
|
|
294
|
+
inputRevision: z4.object({
|
|
295
|
+
sequence: z4.number().int().nonnegative(),
|
|
296
|
+
journalThrough: z4.number().int().nonnegative(),
|
|
297
|
+
runtimeSequence: z4.number().int().positive()
|
|
298
|
+
}).readonly(),
|
|
299
|
+
analysisVersion: z4.number().int().positive(),
|
|
300
|
+
stale: z4.boolean(),
|
|
301
|
+
pending: z4.boolean(),
|
|
302
|
+
error: z4.string().nullable(),
|
|
303
|
+
result: z4.object({
|
|
304
|
+
parts: z4.number().int().positive().max(4096),
|
|
305
|
+
bytes: z4.number().int().positive(),
|
|
306
|
+
hash: z4.string().regex(/^[a-f0-9]{64}$/)
|
|
307
|
+
}).nullable()
|
|
308
|
+
}).readonly();
|
|
309
|
+
var dashboardResultPartSchema = z4.strictObject({
|
|
310
|
+
index: z4.number().int().nonnegative(),
|
|
311
|
+
bytes: z4.number().int().positive(),
|
|
312
|
+
hash: z4.string().regex(/^[a-f0-9]{64}$/),
|
|
313
|
+
body: z4.string().max(2e5)
|
|
314
|
+
}).readonly();
|
|
315
|
+
var dashboardEvalInputSchema = z4.strictObject({
|
|
316
|
+
query: z4.string().min(1).max(64e3),
|
|
317
|
+
expectedUri: z4.string().max(2048).optional(),
|
|
318
|
+
fromTraceId: z4.string().max(512).optional()
|
|
319
|
+
}).readonly();
|
|
320
|
+
var dashboardEvalRequestSchema = z4.strictObject({
|
|
321
|
+
profile: dashboardSourceSchema,
|
|
322
|
+
requestId: z4.string().uuid(),
|
|
323
|
+
input: dashboardEvalInputSchema
|
|
324
|
+
}).readonly();
|
|
325
|
+
var dashboardEvalReceiptSchema = z4.strictObject({
|
|
326
|
+
caseId: z4.string().min(1),
|
|
327
|
+
state: z4.literal("stored"),
|
|
328
|
+
retainedUntilMs: timestamp
|
|
329
|
+
}).readonly();
|
|
330
|
+
|
|
331
|
+
// ../shared/dist/activity-commands.js
|
|
332
|
+
var slug = (max) => z5.string().min(1).max(max).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
|
|
333
|
+
var commandWorkflowStepSchema = z5.strictObject({
|
|
334
|
+
id: slug(64),
|
|
335
|
+
skills: z5.array(z5.string().min(1).max(128)).max(10),
|
|
336
|
+
together: z5.boolean().default(false),
|
|
337
|
+
expectTools: z5.array(z5.string().min(1).max(128)).default([]),
|
|
338
|
+
doneWhen: z5.string().max(500).optional()
|
|
339
|
+
});
|
|
340
|
+
var commandWorkflowSpecSchema = z5.strictObject({
|
|
341
|
+
name: slug(64),
|
|
342
|
+
steps: z5.array(commandWorkflowStepSchema).min(1).max(50)
|
|
343
|
+
}).refine((spec) => new Set(spec.steps.map((step) => step.id)).size === spec.steps.length, {
|
|
344
|
+
message: "step ids must be unique",
|
|
345
|
+
path: ["steps"]
|
|
346
|
+
});
|
|
347
|
+
var sourceOperationSchema = z5.discriminatedUnion("kind", [
|
|
348
|
+
z5.strictObject({ kind: z5.literal("workflow.put"), spec: commandWorkflowSpecSchema }),
|
|
349
|
+
z5.strictObject({
|
|
350
|
+
kind: z5.literal("flow.create"),
|
|
351
|
+
workspaceId: sourceIdSchema.max(128),
|
|
352
|
+
tabId: sourceIdSchema.max(128).optional(),
|
|
353
|
+
spec: z5.strictObject({ name: z5.string().min(1).max(64), version: revisionSchema.min(1).max(1e6).optional() }),
|
|
354
|
+
label: z5.string().max(200).optional()
|
|
355
|
+
}),
|
|
356
|
+
z5.strictObject({
|
|
357
|
+
kind: z5.literal("flow.map-step"),
|
|
358
|
+
flowId: sourceIdSchema,
|
|
359
|
+
paneId: sourceIdSchema.max(128),
|
|
360
|
+
stepId: z5.string().min(1).max(64)
|
|
361
|
+
}),
|
|
362
|
+
z5.strictObject({ kind: z5.literal("flow.end"), flowId: sourceIdSchema }),
|
|
363
|
+
z5.strictObject({
|
|
364
|
+
kind: z5.literal("eval.add"),
|
|
365
|
+
query: z5.string().min(1).max(64e3),
|
|
366
|
+
expectedUri: z5.string().max(2048).optional(),
|
|
367
|
+
fromTraceId: z5.string().max(512).optional()
|
|
368
|
+
})
|
|
369
|
+
]).readonly();
|
|
370
|
+
var commandId = z5.string().uuid();
|
|
371
|
+
var payloadHash = z5.string().regex(/^[a-f0-9]{64}$/);
|
|
372
|
+
var bounded = (value) => new TextEncoder().encode(JSON.stringify(value)).length <= MAX_BATCH_BYTES;
|
|
373
|
+
var sourceCommandRequestSchema = z5.strictObject({
|
|
374
|
+
profile: dashboardSourceSchema,
|
|
375
|
+
commandId,
|
|
376
|
+
baseRevision: revisionSchema,
|
|
377
|
+
operation: sourceOperationSchema
|
|
378
|
+
}).refine(bounded, "command exceeds 256 KiB").readonly();
|
|
379
|
+
var sourceCommandSchema = z5.strictObject({
|
|
380
|
+
accountId: accountIdSchema,
|
|
381
|
+
generation: revisionSchema.min(1),
|
|
382
|
+
deviceId: deviceIdSchema,
|
|
383
|
+
sourceDomain: sourceDomainSchema,
|
|
384
|
+
commandId,
|
|
385
|
+
baseRevision: revisionSchema,
|
|
386
|
+
operation: sourceOperationSchema,
|
|
387
|
+
payloadHash,
|
|
388
|
+
expiresAtMs: timestampSchema,
|
|
389
|
+
consentVersion: revisionSchema.min(1)
|
|
390
|
+
}).readonly();
|
|
391
|
+
var commandResultSchema = z5.strictObject({
|
|
392
|
+
commandId,
|
|
393
|
+
payloadHash,
|
|
394
|
+
state: z5.enum(["applied", "conflict", "rejected"]),
|
|
395
|
+
sourceRevision: revisionSchema,
|
|
396
|
+
result: z5.record(z5.string(), z5.unknown()).nullable(),
|
|
397
|
+
error: z5.string().max(64e3).nullable()
|
|
398
|
+
}).refine(bounded, "result exceeds 256 KiB").readonly();
|
|
399
|
+
var commandStatusSchema = z5.strictObject({
|
|
400
|
+
commandId,
|
|
401
|
+
state: z5.enum(["pending", "applied", "conflict", "rejected"]),
|
|
402
|
+
baseRevision: revisionSchema,
|
|
403
|
+
sourceRevision: revisionSchema.nullable(),
|
|
404
|
+
result: z5.record(z5.string(), z5.unknown()).nullable(),
|
|
405
|
+
error: z5.string().nullable()
|
|
406
|
+
}).readonly();
|
|
407
|
+
var commandStatusRequestSchema = z5.strictObject({
|
|
408
|
+
profile: dashboardSourceSchema,
|
|
409
|
+
commandId
|
|
410
|
+
}).readonly();
|
|
411
|
+
var commandPollRequestSchema = z5.strictObject({ sourceDomain: sourceDomainSchema }).readonly();
|
|
412
|
+
var commandPollResponseSchema = z5.strictObject({ command: sourceCommandSchema.nullable() }).readonly();
|
|
413
|
+
var commandAckSchema = z5.strictObject({
|
|
414
|
+
sourceDomain: sourceDomainSchema,
|
|
415
|
+
...commandResultSchema.unwrap().shape
|
|
416
|
+
}).refine(bounded, "ack exceeds 256 KiB").readonly();
|
|
417
|
+
function canonicalCommandJson(value) {
|
|
418
|
+
const json = JSON.stringify(value, (_key, part) => {
|
|
419
|
+
if (part !== null && typeof part === "object" && !Array.isArray(part)) {
|
|
420
|
+
return Object.fromEntries(Object.entries(part).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
421
|
+
}
|
|
422
|
+
return part;
|
|
423
|
+
});
|
|
424
|
+
if (json === void 0)
|
|
425
|
+
throw new TypeError("command_json_required");
|
|
426
|
+
return json;
|
|
427
|
+
}
|
|
428
|
+
function canonicalCommandPayload(input) {
|
|
429
|
+
return canonicalCommandJson(sourceCommandRequestSchema.parse(input));
|
|
430
|
+
}
|
|
431
|
+
export {
|
|
432
|
+
canonicalCommandPayload,
|
|
433
|
+
commandPollResponseSchema,
|
|
434
|
+
commandResultSchema,
|
|
435
|
+
commandStatusSchema,
|
|
436
|
+
sourceCommandSchema
|
|
437
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mutationSchema, SyncError } from "./tables.js";
|
|
4
|
+
// The standalone local package cannot import TS outside its rootDir or depend on
|
|
5
|
+
// an unpublished sibling package. Keep this boundary aligned with shared/activity-consent;
|
|
6
|
+
// contract tests exercise both parsers. These are NOT new HTTP wire contracts.
|
|
7
|
+
const revision = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
8
|
+
const identity = z.string().min(1).max(512).refine(value => !value.includes("\0"));
|
|
9
|
+
const timestamp = z.number().int().min(-8640000000000000).max(8640000000000000);
|
|
10
|
+
const range = z.strictObject({ fromMs: timestamp, toMs: timestamp })
|
|
11
|
+
.refine(value => value.toMs > value.fromMs);
|
|
12
|
+
const backfill = z.strictObject({
|
|
13
|
+
version: revision.min(1), snapshotId: identity, journalCut: revision,
|
|
14
|
+
});
|
|
15
|
+
export const contentKinds = [
|
|
16
|
+
"prompt", "query", "args", "error", "path", "span-attributes", "private-skills",
|
|
17
|
+
];
|
|
18
|
+
const kind = z.enum(contentKinds);
|
|
19
|
+
const common = {
|
|
20
|
+
version: revision.min(1), grantedAtMs: timestamp,
|
|
21
|
+
scope: z.strictObject({
|
|
22
|
+
deviceId: identity,
|
|
23
|
+
projectIds: z.array(z.string().min(1).max(512)).min(1).max(1000).readonly(),
|
|
24
|
+
rootIds: z.array(z.string().min(1).max(512)).max(1000).readonly(),
|
|
25
|
+
}),
|
|
26
|
+
retention: z.strictObject({
|
|
27
|
+
contentDays: revision.min(1).default(30), projectionDays: revision.min(1).default(30),
|
|
28
|
+
backupDays: z.number().int().min(0).max(30).default(30),
|
|
29
|
+
}).default({ contentDays: 30, projectionDays: 30, backupDays: 30 }),
|
|
30
|
+
backfill: backfill.extend({ range }).optional(),
|
|
31
|
+
};
|
|
32
|
+
export const consentSchema = z.discriminatedUnion("mode", [
|
|
33
|
+
z.strictObject({ mode: z.literal("local-only") }),
|
|
34
|
+
z.strictObject({ ...common, mode: z.literal("metadata") }),
|
|
35
|
+
z.strictObject({ ...common, mode: z.literal("managed-content"),
|
|
36
|
+
serverProcessingAcknowledged: z.literal(true),
|
|
37
|
+
contentKinds: z.array(kind).min(1).max(7).readonly(),
|
|
38
|
+
externalModelTransfer: z.literal(false).default(false) }),
|
|
39
|
+
]);
|
|
40
|
+
export const uploadScopeSchema = z.strictObject({
|
|
41
|
+
deviceId: identity, projectId: identity, rootId: identity.nullable(),
|
|
42
|
+
consentVersion: revision.min(1), fromMs: timestamp, toMs: timestamp,
|
|
43
|
+
contentKinds: z.array(kind).readonly(), backfill: backfill.nullable(),
|
|
44
|
+
});
|
|
45
|
+
export function authorizeUpload(consent, scope) {
|
|
46
|
+
if (consent.mode === "local-only")
|
|
47
|
+
throw new SyncError("consent_required");
|
|
48
|
+
if (scope.deviceId !== consent.scope.deviceId || scope.consentVersion !== consent.version ||
|
|
49
|
+
!consent.scope.projectIds.includes(scope.projectId) ||
|
|
50
|
+
(scope.rootId !== null && !consent.scope.rootIds.includes(scope.rootId))) {
|
|
51
|
+
throw new SyncError("consent_required");
|
|
52
|
+
}
|
|
53
|
+
if (scope.toMs <= scope.fromMs)
|
|
54
|
+
throw new SyncError("range_not_allowed");
|
|
55
|
+
if (scope.contentKinds.length > 0 && (consent.mode !== "managed-content" ||
|
|
56
|
+
scope.contentKinds.some(value => !consent.contentKinds.includes(value)))) {
|
|
57
|
+
throw new SyncError("content_not_allowed");
|
|
58
|
+
}
|
|
59
|
+
if (scope.backfill !== null) {
|
|
60
|
+
const historical = consent.backfill;
|
|
61
|
+
if (historical === undefined || historical.version !== scope.backfill.version ||
|
|
62
|
+
historical.snapshotId !== scope.backfill.snapshotId ||
|
|
63
|
+
historical.journalCut !== scope.backfill.journalCut ||
|
|
64
|
+
scope.fromMs < historical.range.fromMs || scope.toMs > historical.range.toMs) {
|
|
65
|
+
throw new SyncError("range_not_allowed");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (scope.fromMs < consent.grantedAtMs)
|
|
69
|
+
throw new SyncError("range_not_allowed");
|
|
70
|
+
}
|
|
71
|
+
// Closed metadata projection. Arbitrary JSON/text, labels, names, URIs, digests,
|
|
72
|
+
// paths, runtime attributes and spec bodies never pass through this allowlist.
|
|
73
|
+
const metadataColumns = {
|
|
74
|
+
skills: ["mtime_ms", "removed_at"],
|
|
75
|
+
sessions: ["started_at", "ended_at"],
|
|
76
|
+
events: ["ts", "text_length"],
|
|
77
|
+
loads: ["created_at"],
|
|
78
|
+
eval_cases: ["created_at"],
|
|
79
|
+
otel_spans: ["start_ms", "end_ms", "received_at"],
|
|
80
|
+
herdr_workspaces: ["created_ms", "closed_ms"],
|
|
81
|
+
herdr_tabs: ["created_ms", "closed_ms"],
|
|
82
|
+
herdr_panes: ["created_ms", "closed_ms", "last_seen_ms"],
|
|
83
|
+
pane_sessions: ["first_seen_ms", "last_seen_ms"],
|
|
84
|
+
workflow_specs: ["version", "created_ms"],
|
|
85
|
+
flows: ["registered_ms", "ended_ms", "start_order", "end_order"],
|
|
86
|
+
flow_steps: ["registered_ms"],
|
|
87
|
+
load_candidates: ["ts"],
|
|
88
|
+
recording_clock: ["singleton", "position"],
|
|
89
|
+
};
|
|
90
|
+
const timeColumns = {
|
|
91
|
+
skills: ["mtime_ms", "removed_at"], sessions: ["started_at", "ended_at"],
|
|
92
|
+
events: ["ts"], loads: ["created_at"], eval_cases: ["created_at"],
|
|
93
|
+
otel_spans: ["start_ms", "end_ms", "received_at"],
|
|
94
|
+
herdr_workspaces: ["created_ms", "closed_ms"], herdr_tabs: ["created_ms", "closed_ms"],
|
|
95
|
+
herdr_panes: ["created_ms", "closed_ms", "last_seen_ms"],
|
|
96
|
+
pane_sessions: ["first_seen_ms", "last_seen_ms"], workflow_specs: ["created_ms"],
|
|
97
|
+
flows: ["registered_ms", "ended_ms"], flow_steps: ["registered_ms"],
|
|
98
|
+
load_candidates: ["ts"], recording_clock: [],
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Full row images need all raw-content kinds: JSON columns can contain any of
|
|
102
|
+
* them at arbitrary depth. Partial grants get metadata, never regex redaction.
|
|
103
|
+
* Metadata source keys are hashed with their table tag: PKs can be file URIs
|
|
104
|
+
* or user-chosen text. Before-images are local authorization evidence only.
|
|
105
|
+
*/
|
|
106
|
+
export function transformMutation(input, scope) {
|
|
107
|
+
const mutation = mutationSchema.parse(input);
|
|
108
|
+
for (const column of timeColumns[mutation.table]) {
|
|
109
|
+
const value = (mutation.values ?? mutation.beforeValues)?.[column];
|
|
110
|
+
if (typeof value === "number" && (value < scope.fromMs || value >= scope.toMs)) {
|
|
111
|
+
throw new SyncError("range_not_allowed");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (scope.contentKinds.length > 0) {
|
|
115
|
+
if (contentKinds.some(value => !scope.contentKinds.includes(value))) {
|
|
116
|
+
throw new SyncError("content_not_allowed");
|
|
117
|
+
}
|
|
118
|
+
return { ...mutation, beforeValues: null };
|
|
119
|
+
}
|
|
120
|
+
const key = createHash("sha256").update(mutation.table).update("\0").update(mutation.key).digest("hex");
|
|
121
|
+
if (mutation.values === null)
|
|
122
|
+
return { ...mutation, key, beforeValues: null };
|
|
123
|
+
const values = {};
|
|
124
|
+
for (const column of metadataColumns[mutation.table]) {
|
|
125
|
+
const value = mutation.values[column];
|
|
126
|
+
if (value !== undefined)
|
|
127
|
+
values[column] = z.number().finite().nullable().parse(value);
|
|
128
|
+
}
|
|
129
|
+
return { ...mutation, key, values, beforeValues: null };
|
|
130
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { mutationSchema, SyncError } from "./tables.js";
|
|
3
|
+
const cutSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
4
|
+
const headSchema = z.object({ cut: cutSchema, source_domain: z.string() });
|
|
5
|
+
/** Only call outside a source transaction: a cut must never split recursive triggers. */
|
|
6
|
+
export function journalHead(db) {
|
|
7
|
+
if (db.isTransaction)
|
|
8
|
+
throw new SyncError("transaction_active");
|
|
9
|
+
const head = headSchema.parse(db.prepare(`SELECT source_domain,
|
|
10
|
+
COALESCE((SELECT MAX(seq) FROM sync_journal), 0) AS cut FROM sync_identity`).get());
|
|
11
|
+
return { cut: head.cut, sourceDomain: head.source_domain };
|
|
12
|
+
}
|
|
13
|
+
const journalRow = z.object({
|
|
14
|
+
seq: cutSchema, table_name: z.string(), entity_key: z.string(), operation: z.string(),
|
|
15
|
+
source_order: z.number().int().nullable(), row_json: z.string().nullable(),
|
|
16
|
+
before_json: z.string().nullable(),
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Coalesce only inside a caller's fixed, committed cut. Never re-read live rows.
|
|
20
|
+
* Consumers page by returned revision; through must be a head/snapshot cut, not an
|
|
21
|
+
* arbitrary intermediate trigger seq. Old revisions remain available after deletes.
|
|
22
|
+
*/
|
|
23
|
+
export function readJournal(db, range) {
|
|
24
|
+
const head = journalHead(db);
|
|
25
|
+
const after = cutSchema.parse(range.after);
|
|
26
|
+
const through = cutSchema.parse(range.through);
|
|
27
|
+
const limit = z.number().int().min(1).max(100).parse(range.limit ?? 100);
|
|
28
|
+
if (through < after || through > head.cut)
|
|
29
|
+
throw new SyncError("invalid_cut");
|
|
30
|
+
return db.prepare(`SELECT j.* FROM sync_journal j
|
|
31
|
+
WHERE j.seq > ? AND j.seq <= ? AND NOT EXISTS (
|
|
32
|
+
SELECT 1 FROM sync_journal n WHERE n.table_name = j.table_name
|
|
33
|
+
AND n.entity_key = j.entity_key AND n.seq > j.seq AND n.seq <= ?)
|
|
34
|
+
ORDER BY j.seq LIMIT ?`).all(after, through, through, limit).map(raw => {
|
|
35
|
+
const row = journalRow.parse(raw);
|
|
36
|
+
return mutationSchema.parse({
|
|
37
|
+
table: row.table_name, key: row.entity_key, revision: row.seq,
|
|
38
|
+
operation: row.operation, sourceOrder: row.source_order,
|
|
39
|
+
values: row.row_json === null ? null : JSON.parse(row.row_json),
|
|
40
|
+
beforeValues: row.before_json === null ? null : JSON.parse(row.before_json),
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|