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
package/dist/api/flows.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { flowTree, sessionTree } from "../analysis/tree.js";
|
|
3
|
-
import { aggregateUsage, rangeUsage, sessionUsage } from "../analysis/usage.js";
|
|
4
|
-
import { compareFlow } from "../workflow/compare.js";
|
|
1
|
+
import { AnalysisReportError, buildFlows, buildFlowReport, buildSessionReport, buildSkillUsage, } from "./report-kernel.js";
|
|
5
2
|
import { deny } from "./security.js";
|
|
6
|
-
/** A herdr workspace with no registered flow is addressed as `ws:<workspaceId>`, a registered flow by its own id. */
|
|
7
3
|
export const WORKSPACE_PREFIX = "ws:";
|
|
8
|
-
const MAX_LIMIT = 100;
|
|
9
|
-
const
|
|
10
|
-
const MAX_DETAIL = 100;
|
|
11
|
-
const DEFAULT_DETAIL = 20;
|
|
12
|
-
const DAY_MS = 86_400_000;
|
|
13
|
-
const DEFAULT_RANGE_DAYS = 7;
|
|
14
|
-
// /api/skills/usage analyses every session of its range, so the range itself is what bounds the work.
|
|
15
|
-
const MAX_RANGE_DAYS = 366;
|
|
4
|
+
const MAX_LIMIT = 100, DEFAULT_LIMIT = 20, MAX_DETAIL = 100, DEFAULT_DETAIL = 20;
|
|
5
|
+
const DAY_MS = 86_400_000, DEFAULT_RANGE_DAYS = 7, MAX_RANGE_DAYS = 366;
|
|
16
6
|
class BadQuery extends Error {
|
|
17
7
|
code;
|
|
18
8
|
constructor(code, message) {
|
|
@@ -28,6 +18,21 @@ function handle(log, fn) {
|
|
|
28
18
|
catch (error) {
|
|
29
19
|
if (error instanceof BadQuery)
|
|
30
20
|
return deny(res, 400, error.code, { message: error.message });
|
|
21
|
+
if (error instanceof AnalysisReportError) {
|
|
22
|
+
const id = String(req.params.id);
|
|
23
|
+
if (error.code === "flow_not_found") {
|
|
24
|
+
return deny(res, 404, error.code, { message: `no flow or herdr workspace ${id}` });
|
|
25
|
+
}
|
|
26
|
+
if (error.code === "session_not_found") {
|
|
27
|
+
return deny(res, 404, error.code, { message: `no session ${id}` });
|
|
28
|
+
}
|
|
29
|
+
return deny(res, 404, error.code, {
|
|
30
|
+
message: automatedOf(req.query) === "only"
|
|
31
|
+
? `session ${id} was not automated; drop automated=only to read it`
|
|
32
|
+
: `session ${id} was automated (${error.automated}); pass automated=include to read it`,
|
|
33
|
+
automated: error.automated,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
31
36
|
log(`${req.method} ${req.path} failed: ${error.stack ?? String(error)}`);
|
|
32
37
|
deny(res, 500, "internal_error");
|
|
33
38
|
}
|
|
@@ -56,230 +61,55 @@ function automatedOf(q) {
|
|
|
56
61
|
throw new BadQuery("bad_filter", "automated must be include or only");
|
|
57
62
|
return raw;
|
|
58
63
|
}
|
|
59
|
-
/** from/to are milliseconds, half-open [from, to), as everywhere else in the API. */
|
|
60
64
|
function rangeOf(q, now) {
|
|
61
|
-
const to = intOf(q, "to") ?? now;
|
|
62
|
-
const from = intOf(q, "from") ?? to - DEFAULT_RANGE_DAYS * DAY_MS;
|
|
65
|
+
const to = intOf(q, "to") ?? now, from = intOf(q, "from") ?? to - DEFAULT_RANGE_DAYS * DAY_MS;
|
|
63
66
|
if (from > to)
|
|
64
67
|
throw new BadQuery("bad_filter", "from must not be after to");
|
|
65
68
|
if (to - from > MAX_RANGE_DAYS * DAY_MS)
|
|
66
69
|
throw new BadQuery("bad_filter", `the range must not exceed ${MAX_RANGE_DAYS} days`);
|
|
67
70
|
return { from, to };
|
|
68
71
|
}
|
|
69
|
-
/** Opaque to callers, and tied to the sort key: the ordering time plus the id that breaks its ties. */
|
|
70
|
-
function encodeCursor(row) {
|
|
71
|
-
return Buffer.from(`${row.orderMs}:${row.id}`, "utf8").toString("base64url");
|
|
72
|
-
}
|
|
73
72
|
function decodeCursor(raw) {
|
|
74
73
|
if (raw === undefined || raw === "")
|
|
75
74
|
return undefined;
|
|
76
|
-
const text = Buffer.from(raw, "base64url").toString("utf8");
|
|
77
|
-
const cut = text.
|
|
78
|
-
const orderMs = cut > 0 ? Number(text.slice(0, cut)) : Number.NaN;
|
|
79
|
-
const id = cut > 0 ? text.slice(cut + 1) : "";
|
|
75
|
+
const text = Buffer.from(raw, "base64url").toString("utf8"), cut = text.indexOf(":");
|
|
76
|
+
const orderMs = cut > 0 ? Number(text.slice(0, cut)) : Number.NaN, id = cut > 0 ? text.slice(cut + 1) : "";
|
|
80
77
|
if (!Number.isInteger(orderMs) || id === "")
|
|
81
78
|
throw new BadQuery("bad_cursor", "cursor is not one this endpoint issued");
|
|
82
79
|
return { orderMs, id };
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return true;
|
|
87
|
-
const automated = automation[sessionId] !== undefined;
|
|
88
|
-
return mode === "only" ? automated : !automated;
|
|
89
|
-
}
|
|
90
|
-
function entryOf(row, automation, mode) {
|
|
91
|
-
const links = row.links.filter((link) => link.sessionId === null || keepSession(link.sessionId, automation, mode));
|
|
92
|
-
const sessionIds = [...new Set(links.flatMap((link) => (link.sessionId === null ? [] : [link.sessionId])))];
|
|
93
|
-
let reported = 0;
|
|
94
|
-
let inferred = 0;
|
|
95
|
-
let unlinked = 0;
|
|
96
|
-
for (const link of links) {
|
|
97
|
-
if (link.sessionId === null || link.source === "unlinked")
|
|
98
|
-
unlinked += 1;
|
|
99
|
-
else if (link.source === "inferred:cwd_time")
|
|
100
|
-
inferred += 1;
|
|
101
|
-
else
|
|
102
|
-
reported += 1;
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
id: row.kind === "workspace" ? `${WORKSPACE_PREFIX}${row.workspaceId}` : row.id,
|
|
106
|
-
kind: row.kind, workspaceId: row.workspaceId, tabId: row.tabId, label: row.label, registered: row.kind === "flow",
|
|
107
|
-
spec: row.spec, startedMs: row.startedMs, endedMs: row.endedMs,
|
|
108
|
-
paneIds: row.paneIds, sessionIds,
|
|
109
|
-
counts: { panes: row.paneIds.length, sessions: sessionIds.length },
|
|
110
|
-
attribution: { reported, inferred, unlinked },
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/** The finding of one session under the API's names: `loadedSkills` is `usedSkills`, native activations included. */
|
|
114
|
-
function findingDto(finding) {
|
|
115
|
-
return {
|
|
116
|
-
sessionId: finding.sessionId,
|
|
117
|
-
turns: finding.turns.map(({ loadedSkills, ...turn }) => ({ ...turn, usedSkills: loadedSkills })),
|
|
118
|
-
aggregate: finding.aggregate,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function sessionIdsOf(tree) {
|
|
122
|
-
return tree.tabs.flatMap((tab) => tab.panes.flatMap((pane) => pane.sessions.flatMap((link) => (link.sessionId === null ? [] : [link.sessionId]))));
|
|
123
|
-
}
|
|
124
|
-
/** Drops the links to sessions the automated filter excludes; the pane stays, and the report says what was left out. */
|
|
125
|
-
function filterTree(tree, automation, mode) {
|
|
126
|
-
const excluded = new Map();
|
|
127
|
-
const tabs = tree.tabs.map((tab) => ({
|
|
128
|
-
...tab,
|
|
129
|
-
panes: tab.panes.map((pane) => ({
|
|
130
|
-
...pane,
|
|
131
|
-
sessions: pane.sessions.filter((link) => {
|
|
132
|
-
if (link.sessionId === null || keepSession(link.sessionId, automation, mode))
|
|
133
|
-
return true;
|
|
134
|
-
excluded.set(link.sessionId, { sessionId: link.sessionId, reason: automation[link.sessionId] ?? "not_automated" });
|
|
135
|
-
return false;
|
|
136
|
-
}),
|
|
137
|
-
})),
|
|
138
|
-
}));
|
|
139
|
-
return { tree: { ...tree, tabs }, excluded };
|
|
140
|
-
}
|
|
141
|
-
function sessionsOf(tree) {
|
|
142
|
-
const sessions = new Map((tree.sessions ?? []).map((session) => [session.id, session]));
|
|
143
|
-
for (const tab of tree.tabs) {
|
|
144
|
-
for (const pane of tab.panes) {
|
|
145
|
-
for (const link of pane.sessions)
|
|
146
|
-
if (link.session !== null)
|
|
147
|
-
sessions.set(link.session.id, link.session);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return [...sessions.values()];
|
|
151
|
-
}
|
|
152
|
-
export function registerFlowRoutes(app, deps) {
|
|
153
|
-
const { store, log } = deps;
|
|
154
|
-
/**
|
|
155
|
-
* Registered flows and the herdr workspaces without one, newest first. The page is bounded by `limit`, so the
|
|
156
|
-
* optional from/to filter the ordering time rather than capping the work.
|
|
157
|
-
*/
|
|
81
|
+
/** SQLite and the cloud use the same report DTO assembly over their read adapters. */
|
|
82
|
+
export function registerFlowRoutes(app, { store, log }) {
|
|
158
83
|
app.get("/api/flows", handle(log, (req, res) => {
|
|
159
|
-
const automated = automatedOf(req.query);
|
|
160
|
-
const
|
|
161
|
-
const from = intOf(req.query, "from");
|
|
162
|
-
const to = intOf(req.query, "to");
|
|
84
|
+
const automated = automatedOf(req.query), limit = intOf(req.query, "limit", [1, MAX_LIMIT]) ?? DEFAULT_LIMIT;
|
|
85
|
+
const from = intOf(req.query, "from"), to = intOf(req.query, "to");
|
|
163
86
|
if (from !== undefined && to !== undefined && from > to)
|
|
164
87
|
throw new BadQuery("bad_filter", "from must not be after to");
|
|
165
88
|
const cursor = decodeCursor(one(req.query.cursor));
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const automation = automated === "include" ? {} :
|
|
171
|
-
store.sessionAutomation(page.flatMap((row) => row.links.flatMap((link) => (link.sessionId === null ? [] : [link.sessionId]))));
|
|
172
|
-
res.json({
|
|
173
|
-
generatedAt: Date.now(), from: from ?? null, to: to ?? null, limit, automated,
|
|
174
|
-
flows: page.map((row) => entryOf(row, automation, automated)),
|
|
175
|
-
nextCursor: rows.length > limit && last ? encodeCursor(last) : null,
|
|
176
|
-
});
|
|
89
|
+
res.json(buildFlows(store, {
|
|
90
|
+
automated, limit, ...(from === undefined ? {} : { from }), ...(to === undefined ? {} : { to }),
|
|
91
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
92
|
+
}, Date.now()));
|
|
177
93
|
}));
|
|
178
|
-
/** One flow: the tree (todo 6), per-turn finding (7), per-span usage (8) and the spec comparison (9). */
|
|
179
94
|
app.get("/api/flows/:id", handle(log, (req, res) => {
|
|
180
|
-
const automated = automatedOf(req.query);
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (ref === "outside") {
|
|
186
|
-
const to = intOf(req.query, "to") ?? Date.now() + 1;
|
|
187
|
-
const from = intOf(req.query, "from") ?? to - DEFAULT_RANGE_DAYS * DAY_MS;
|
|
188
|
-
if (from > to)
|
|
189
|
-
throw new BadQuery("bad_filter", "from must not be after to");
|
|
190
|
-
const limit = intOf(req.query, "limit", [1, MAX_LIMIT]) ?? MAX_LIMIT;
|
|
191
|
-
full = { id: "outside", workspaceId: "", label: "outside herdr", registered: false, tabs: [],
|
|
192
|
-
sessions: store.outsideHerdrSessions({ from, to, limit, automated }).flatMap(({ id: sessionId }) => {
|
|
193
|
-
const session = sessionTree(store, sessionId);
|
|
194
|
-
return session ? [session] : [];
|
|
195
|
-
}) };
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
full = flowTree(store, id, eventScope);
|
|
199
|
-
}
|
|
200
|
-
if (!full)
|
|
201
|
-
return deny(res, 404, "flow_not_found", { message: `no flow or herdr workspace ${ref}` });
|
|
202
|
-
// Classify the shared execution population, including explicitly mapped panes on other tabs.
|
|
203
|
-
const comparisonSessionIds = full.registered ? store.flowSessionIds(full.id, eventScope) : [];
|
|
204
|
-
const automation = automated === "include" ? {} : store.sessionAutomation([...sessionIdsOf(full), ...comparisonSessionIds]);
|
|
205
|
-
const flow = full.registered ? store.getFlow(full.id) : undefined;
|
|
206
|
-
const overlaps = flow ? sessionsOf(full).map((session) => ({
|
|
207
|
-
sessionId: session.id, startedBefore: session.startedAt < flow.registeredMs,
|
|
208
|
-
continuesAfter: flow.endedMs !== undefined && (session.endedAt === null || session.endedAt > flow.endedMs),
|
|
209
|
-
})).filter((session) => session.startedBefore || session.continuesAfter) : [];
|
|
210
|
-
const { tree, excluded } = filterTree(full, automation, automated);
|
|
211
|
-
for (const sessionId of comparisonSessionIds) {
|
|
212
|
-
if (keepSession(sessionId, automation, automated))
|
|
213
|
-
continue;
|
|
214
|
-
excluded.set(sessionId, { sessionId, reason: automation[sessionId] ?? "not_automated" });
|
|
95
|
+
const ref = String(req.params.id), automated = automatedOf(req.query);
|
|
96
|
+
const from = ref === "outside" ? intOf(req.query, "from") : undefined;
|
|
97
|
+
const to = ref === "outside" ? intOf(req.query, "to") : undefined;
|
|
98
|
+
if (ref === "outside" && (from ?? (to ?? Date.now() + 1) - DEFAULT_RANGE_DAYS * DAY_MS) > (to ?? Date.now() + 1)) {
|
|
99
|
+
throw new BadQuery("bad_filter", "from must not be after to");
|
|
215
100
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const warningSessions = [...sessions.map((session) => session.id), ...comparisonSessionIds.filter((id) => !excluded.has(id))];
|
|
222
|
-
const unattributedLoads = flow ? store.flowUnattributedLoads(flow.id, warningSessions, eventScope) : store.reconcileLoads({
|
|
223
|
-
readOnly: true,
|
|
224
|
-
from: (ref === "outside" ? intOf(req.query, "from") ?? Date.now() - DEFAULT_RANGE_DAYS * DAY_MS
|
|
225
|
-
: sessions.length === 0 ? 0 : Math.min(...sessions.map((session) => session.startedAt))),
|
|
226
|
-
to: (ref === "outside" ? intOf(req.query, "to") ?? Date.now() + 1 : Date.now() + 1),
|
|
227
|
-
sessionIds: warningSessions,
|
|
228
|
-
});
|
|
229
|
-
res.json({
|
|
230
|
-
generatedAt: Date.now(),
|
|
231
|
-
id: ref === "outside" ? "outside" : tree.registered ? tree.id : `${WORKSPACE_PREFIX}${tree.workspaceId}`,
|
|
232
|
-
kind: ref === "outside" ? "outside_herdr" : tree.registered ? "flow" : "workspace",
|
|
233
|
-
workspaceId: tree.workspaceId, label: tree.label, registered: tree.registered,
|
|
234
|
-
flow: flow ? { registeredMs: flow.registeredMs, endedMs: flow.endedMs ?? null, tabId: flow.tabId ?? null } : null,
|
|
235
|
-
spec: spec ? { id: spec.id, name: spec.name, version: spec.version } : null,
|
|
236
|
-
automated, tree,
|
|
237
|
-
executionScope: eventScope ? { from: eventScope.from, to: eventScope.to, boundary: eventScope.boundary,
|
|
238
|
-
overlaps: overlaps.filter((session) => keepSession(session.sessionId, automation, automated)),
|
|
239
|
-
label: eventScope.boundary === "recorded"
|
|
240
|
-
? "Events scoped by timestamp; persisted recording order resolves equal-time boundaries independently of membership discovery. Delayed interior evidence can still arrive. Session ends are observed separately."
|
|
241
|
-
: "Some boundary ordering is unavailable. Unproven equal-time activity is excluded here; workspace history retains it." } : null,
|
|
242
|
-
finding: { id: tree.id, sessions: findings.map(findingDto), aggregate: aggregateFindings(findings.flatMap((f) => f.turns)) },
|
|
243
|
-
usage: { id: tree.id, sessions: usages, skills: aggregateUsage(usages.flatMap((u) => u.spans)) },
|
|
244
|
-
comparison: tree.registered ? compareFlow(store, tree.id, { excludeSessions: [...excluded.keys()],
|
|
245
|
-
...(eventScope ? { scope: eventScope } : {}) }) ?? null : null,
|
|
246
|
-
excludedSessions: [...excluded.values()],
|
|
247
|
-
unattributedLoads,
|
|
248
|
-
});
|
|
101
|
+
const limit = ref === "outside" ? intOf(req.query, "limit", [1, MAX_LIMIT]) : undefined;
|
|
102
|
+
res.json(buildFlowReport(store, ref, {
|
|
103
|
+
automated, ...(from === undefined ? {} : { from }), ...(to === undefined ? {} : { to }),
|
|
104
|
+
...(limit === undefined ? {} : { limit }),
|
|
105
|
+
}, Date.now()));
|
|
249
106
|
}));
|
|
250
|
-
/** The same finding and usage analysis for one session, whether or not herdr knows a pane for it. */
|
|
251
107
|
app.get("/api/sessions/:id/skill-report", handle(log, (req, res) => {
|
|
252
|
-
|
|
253
|
-
const id = String(req.params.id);
|
|
254
|
-
const unattributedLoads = store.reconcileLoads({ sessionIds: [id], readOnly: true });
|
|
255
|
-
const tree = sessionTree(store, id);
|
|
256
|
-
if (!tree)
|
|
257
|
-
return deny(res, 404, "session_not_found", { message: `no session ${id}` });
|
|
258
|
-
const automation = store.sessionAutomation([id])[id];
|
|
259
|
-
if (!keepSession(id, automation === undefined ? {} : { [id]: automation }, automated)) {
|
|
260
|
-
return deny(res, 404, "automated_excluded", {
|
|
261
|
-
message: automated === "only"
|
|
262
|
-
? `session ${id} was not automated; drop automated=only to read it`
|
|
263
|
-
: `session ${id} was automated (${automation}); pass automated=include to read it`,
|
|
264
|
-
automated: automation ?? null,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
res.json({
|
|
268
|
-
generatedAt: Date.now(), sessionId: tree.id, runtime: tree.runtime, startedAt: tree.startedAt, endedAt: tree.endedAt,
|
|
269
|
-
automated: automation ?? null, tree,
|
|
270
|
-
finding: findingDto(analyzeSession(tree, loadedDigests(store))), usage: sessionUsage(tree),
|
|
271
|
-
unattributedLoads,
|
|
272
|
-
});
|
|
108
|
+
res.json(buildSessionReport(store, String(req.params.id), automatedOf(req.query), Date.now()));
|
|
273
109
|
}));
|
|
274
|
-
/** Per-skill usage over a time range; `sessions` is the detail list `detail` bounds, `skills` covers them all. */
|
|
275
110
|
app.get("/api/skills/usage", handle(log, (req, res) => {
|
|
276
|
-
const automated = automatedOf(req.query);
|
|
277
|
-
const { from, to } = rangeOf(req.query, Date.now());
|
|
111
|
+
const automated = automatedOf(req.query), { from, to } = rangeOf(req.query, Date.now());
|
|
278
112
|
const detailLimit = intOf(req.query, "detail", [0, MAX_DETAIL]) ?? DEFAULT_DETAIL;
|
|
279
|
-
|
|
280
|
-
res.json({
|
|
281
|
-
generatedAt: Date.now(), from, to, automated, detailLimit,
|
|
282
|
-
sessionCount: usage.sessionCount, truncated: usage.truncated, skills: usage.skills, sessions: usage.sessions,
|
|
283
|
-
});
|
|
113
|
+
res.json(buildSkillUsage(store, { from, to, detailLimit, automated }, Date.now()));
|
|
284
114
|
}));
|
|
285
115
|
}
|