@cortex-agent/server 2026.10.21 → 2026.10.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/defaults/context/projects/AGENTS.md +1 -1
- package/defaults/gitignore +3 -3
- package/defaults/hooks/new-session-hook.mjs +1 -1
- package/defaults/hooks/status-md-guard.mjs +6 -6
- package/defaults/plugins/cortex-system/plugin.json +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
- package/defaults/rules/agents-md.md +1 -1
- package/defaults/rules/issues-md.md +1 -1
- package/defaults/rules/meta-conventions.md +3 -3
- package/defaults/rules/mission-md.md +1 -1
- package/defaults/rules/status-md.md +1 -1
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +3 -1
- package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
- package/dist/agent-adapter/claude/mcp-config.js +11 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +2 -1
- package/dist/agent-adapter/claude/turn-machine.js +8 -5
- package/dist/agent-adapter/continuation-phase.d.ts +6 -3
- package/dist/agent-adapter/continuation-phase.js +8 -3
- package/dist/agent-adapter/run-events.d.ts +4 -0
- package/dist/agent-adapter/types.d.ts +9 -2
- package/dist/build-info.json +1 -0
- package/dist/client-bundle/client.mjs +10 -5
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/claude-credentials.d.ts +6 -0
- package/dist/core/claude-credentials.js +11 -0
- package/dist/core/gateway-generator.d.ts +17 -0
- package/dist/core/gateway-generator.js +42 -4
- package/dist/core/hook-bus.d.ts +1 -1
- package/dist/core/hook-bus.js +1 -8
- package/dist/core/locales/en.d.ts +1 -0
- package/dist/core/locales/slices/init.d.ts +1 -0
- package/dist/core/locales/slices/init.js +2 -0
- package/dist/core/log.d.ts +3 -0
- package/dist/core/log.js +18 -1
- package/dist/core/settings-spec.d.ts +5 -0
- package/dist/core/settings-spec.js +4 -0
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/environment-types.d.ts +1 -6
- package/dist/domain/agents/environments/registry.js +3 -2
- package/dist/domain/agents/environments/schema.d.ts +3 -2
- package/dist/domain/agents/environments/schema.js +4 -3
- package/dist/domain/auth/auth-watch.js +48 -18
- package/dist/domain/mcp/tools/context.d.ts +0 -1
- package/dist/domain/mcp/tools/context.js +0 -1
- package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
- package/dist/domain/monitor/event-loop-monitor.js +5 -1
- package/dist/domain/plugins/authoring.d.ts +8 -1
- package/dist/domain/plugins/authoring.js +24 -9
- package/dist/domain/plugins/runtime-gc.d.ts +7 -0
- package/dist/domain/plugins/runtime-gc.js +52 -19
- package/dist/domain/plugins/runtime.js +2 -1
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-manager.js +6 -1
- package/dist/domain/runs/retryable-errors.js +3 -1
- package/dist/domain/runs/service.d.ts +0 -9
- package/dist/domain/runs/service.js +29 -15
- package/dist/domain/scheduling/builtin-job-controller.d.ts +3 -1
- package/dist/domain/scheduling/builtin-job-controller.js +5 -2
- package/dist/domain/scheduling/builtin-jobs.js +7 -0
- package/dist/domain/scheduling/scheduler.js +14 -5
- package/dist/domain/system/server-update-check.js +2 -1
- package/dist/domain/telemetry/bus-collector.d.ts +3 -0
- package/dist/domain/telemetry/bus-collector.js +22 -0
- package/dist/domain/telemetry/child-exit.d.ts +11 -0
- package/dist/domain/telemetry/child-exit.js +36 -0
- package/dist/domain/telemetry/client-kind.d.ts +4 -0
- package/dist/domain/telemetry/client-kind.js +7 -0
- package/dist/domain/telemetry/crash-limits.d.ts +15 -0
- package/dist/domain/telemetry/crash-limits.js +50 -0
- package/dist/domain/telemetry/crash.d.ts +25 -0
- package/dist/domain/telemetry/crash.js +70 -0
- package/dist/domain/telemetry/daily-upload.d.ts +5 -0
- package/dist/domain/telemetry/daily-upload.js +20 -0
- package/dist/domain/telemetry/daily.d.ts +5 -0
- package/dist/domain/telemetry/daily.js +104 -0
- package/dist/domain/telemetry/endpoint.d.ts +7 -0
- package/dist/domain/telemetry/endpoint.js +40 -0
- package/dist/domain/telemetry/envelope.d.ts +6 -0
- package/dist/domain/telemetry/envelope.js +35 -0
- package/dist/domain/telemetry/error-digest.d.ts +7 -0
- package/dist/domain/telemetry/error-digest.js +43 -0
- package/dist/domain/telemetry/funnel.d.ts +6 -0
- package/dist/domain/telemetry/funnel.js +22 -0
- package/dist/domain/telemetry/gate.d.ts +19 -0
- package/dist/domain/telemetry/gate.js +67 -0
- package/dist/domain/telemetry/heartbeat.d.ts +17 -0
- package/dist/domain/telemetry/heartbeat.js +49 -0
- package/dist/domain/telemetry/info.d.ts +9 -0
- package/dist/domain/telemetry/info.js +12 -0
- package/dist/domain/telemetry/init-answer.d.ts +12 -0
- package/dist/domain/telemetry/init-answer.js +42 -0
- package/dist/domain/telemetry/install-id.d.ts +5 -0
- package/dist/domain/telemetry/install-id.js +42 -0
- package/dist/domain/telemetry/normalize.d.ts +33 -0
- package/dist/domain/telemetry/normalize.js +88 -0
- package/dist/domain/telemetry/outbox.d.ts +18 -0
- package/dist/domain/telemetry/outbox.js +93 -0
- package/dist/domain/telemetry/panic-group.d.ts +4 -0
- package/dist/domain/telemetry/panic-group.js +51 -0
- package/dist/domain/telemetry/paths.d.ts +7 -0
- package/dist/domain/telemetry/paths.js +11 -0
- package/dist/domain/telemetry/redact.d.ts +18 -0
- package/dist/domain/telemetry/redact.js +109 -0
- package/dist/domain/telemetry/rollup-types.d.ts +81 -0
- package/dist/domain/telemetry/rollup-types.js +31 -0
- package/dist/domain/telemetry/rollup.d.ts +16 -0
- package/dist/domain/telemetry/rollup.js +102 -0
- package/dist/domain/telemetry/schema.d.ts +931 -0
- package/dist/domain/telemetry/schema.js +275 -0
- package/dist/domain/telemetry/service.d.ts +34 -0
- package/dist/domain/telemetry/service.js +146 -0
- package/dist/domain/telemetry/state.d.ts +17 -0
- package/dist/domain/telemetry/state.js +29 -0
- package/dist/domain/telemetry/turns.d.ts +17 -0
- package/dist/domain/telemetry/turns.js +176 -0
- package/dist/domain/telemetry/upgrade.d.ts +14 -0
- package/dist/domain/telemetry/upgrade.js +87 -0
- package/dist/domain/telemetry/uploader.d.ts +21 -0
- package/dist/domain/telemetry/uploader.js +82 -0
- package/dist/domain/telemetry/usage.d.ts +25 -0
- package/dist/domain/telemetry/usage.js +153 -0
- package/dist/domain/telemetry/web-report.d.ts +8 -0
- package/dist/domain/telemetry/web-report.js +15 -0
- package/dist/domain/ui-service/app-router.d.ts +69 -25
- package/dist/domain/ui-service/app-router.js +9 -2
- package/dist/domain/ui-service/input-schemas.d.ts +68 -4
- package/dist/domain/ui-service/input-schemas.js +9 -1
- package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
- package/dist/domain/ui-service/mutate/approvals.js +3 -2
- package/dist/domain/ui-service/mutate/plugin-packages.js +1 -1
- package/dist/domain/ui-service/mutate/telemetry.d.ts +5 -0
- package/dist/domain/ui-service/mutate/telemetry.js +6 -0
- package/dist/domain/ui-service/query/approvals.js +4 -3
- package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
- package/dist/domain/ui-service/query/machine-probe.js +3 -2
- package/dist/domain/ui-service/query/models.d.ts +3 -0
- package/dist/domain/ui-service/query/models.js +47 -30
- package/dist/domain/ui-service/query/plugin-source.js +4 -3
- package/dist/domain/ui-service/query/sessions.js +1 -0
- package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
- package/dist/domain/ui-service/query/telemetry.js +4 -0
- package/dist/domain/ui-service/trpc.d.ts +8 -3
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +20 -2
- package/dist/domain/ui-service/ui-service.d.ts +33 -4
- package/dist/domain/ui-service/ui-service.js +19 -18
- package/dist/entry/app.js +20 -2
- package/dist/entry/cli-help.js +27 -14
- package/dist/entry/daemon.d.ts +1 -1
- package/dist/entry/daemon.js +86 -72
- package/dist/entry/init.d.ts +3 -0
- package/dist/entry/init.js +50 -28
- package/dist/entry/shutdown.js +3 -0
- package/dist/entry/signal-cli.js +8 -11
- package/dist/entry/start-ui-http.js +40 -18
- package/dist/entry/telemetry-wiring.d.ts +12 -0
- package/dist/entry/telemetry-wiring.js +56 -0
- package/dist/entry/ui-cli.d.ts +0 -11
- package/dist/entry/ui-cli.js +42 -33
- package/dist/events/event-types.d.ts +1 -4
- package/dist/orchestration/routing/message-router.js +2 -0
- package/dist/orchestration/routing/webhook.js +2 -0
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +17 -0
- package/dist/orchestration/waitpoint-ingress.js +3 -0
- package/dist/platform/ui-http/ui-auth-routes.d.ts +2 -0
- package/dist/platform/ui-http/ui-auth-routes.js +9 -2
- package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
- package/dist/platform/ui-http/ui-device-routes.js +81 -0
- package/dist/platform/ui-http/ui-devices.d.ts +24 -0
- package/dist/platform/ui-http/ui-devices.js +107 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +10 -3
- package/dist/platform/ui-http/ui-http-server.js +11 -7
- package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
- package/dist/platform/ui-http/ui-pairing.js +98 -0
- package/dist/store/gitignore-migration.d.ts +2 -0
- package/dist/store/gitignore-migration.js +16 -0
- package/dist/store/hook-registry.d.ts +1 -1
- package/dist/store/hook-registry.js +11 -6
- package/dist/store/session-registry-journal.js +3 -0
- package/dist/store/version-migrations.d.ts +5 -0
- package/dist/store/version-migrations.js +117 -80
- package/dist/tui/components/Dashboard.js +4 -3
- package/dist/tui/hooks/useDashboardData.js +1 -1
- package/package.json +3 -3
- package/web/dist/assets/{board-math-css-CB4GJ6qO.js → board-math-css-spk7yR6n.js} +1 -1
- package/web/dist/assets/index-BQ69u-92.css +1 -0
- package/web/dist/assets/{index-cIGFv27z.js → index-CKNLatCd.js} +1 -1
- package/web/dist/assets/index-CkzWfC98.js +525 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CaSZPg_H.css +0 -1
- package/web/dist/assets/index-CzOR7Edh.js +0 -522
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { INSTALL_ID_FILE } from './paths.js';
|
|
5
|
+
const cache = new Map();
|
|
6
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
7
|
+
export function isInstallId(value) {
|
|
8
|
+
return typeof value === 'string' && UUID_RE.test(value);
|
|
9
|
+
}
|
|
10
|
+
function readInstallId(file) {
|
|
11
|
+
try {
|
|
12
|
+
const value = readFileSync(file, 'utf8').trim();
|
|
13
|
+
return isInstallId(value) ? value.toLowerCase() : null;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function writeInstallId(file, id) {
|
|
20
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
21
|
+
writeFileSync(file, `${id}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
22
|
+
}
|
|
23
|
+
/** The random per-install id, created on first use. Carries no machine or user information. */
|
|
24
|
+
export function getInstallId(file = INSTALL_ID_FILE) {
|
|
25
|
+
const onDisk = readInstallId(file);
|
|
26
|
+
const id = onDisk ?? cache.get(file) ?? randomUUID();
|
|
27
|
+
if (!onDisk) {
|
|
28
|
+
try {
|
|
29
|
+
writeInstallId(file, id);
|
|
30
|
+
}
|
|
31
|
+
catch { /* unwritable home: the id lives for this process */ }
|
|
32
|
+
}
|
|
33
|
+
cache.set(file, id);
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
/** Take over an id generated elsewhere (the desktop shell hands its own to `cortex init`). */
|
|
37
|
+
export function adoptInstallId(id, file = INSTALL_ID_FILE) {
|
|
38
|
+
if (!isInstallId(id))
|
|
39
|
+
throw new Error('install id must be a UUID');
|
|
40
|
+
writeInstallId(file, id.toLowerCase());
|
|
41
|
+
cache.set(file, id.toLowerCase());
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public names an upload may carry: the PI SDK's bundled static catalog plus Cortex's own Claude
|
|
3
|
+
* list. Anything else a user configured (custom providers, local or dynamically listed models,
|
|
4
|
+
* third-party MCP tools) is replaced by a placeholder.
|
|
5
|
+
*/
|
|
6
|
+
export interface NameCatalog {
|
|
7
|
+
piProviders: ReadonlySet<string>;
|
|
8
|
+
/** `provider/model` pairs from the static catalog. */
|
|
9
|
+
piModels: ReadonlySet<string>;
|
|
10
|
+
/** Every model id in the static catalog, any provider (gateway-routed Claude Code). */
|
|
11
|
+
modelIds: ReadonlySet<string>;
|
|
12
|
+
/** User-defined PI providers (models.json) → their API kind. */
|
|
13
|
+
customProviders: ReadonlyMap<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/** A public name made to fit the wire identifier shape. */
|
|
16
|
+
export declare function toIdent(name: string): string;
|
|
17
|
+
export declare function normalizeTool(name: string): string;
|
|
18
|
+
export interface NormalizedProvider {
|
|
19
|
+
provider: string;
|
|
20
|
+
customApi: string | null;
|
|
21
|
+
}
|
|
22
|
+
export declare function normalizeProvider(backend: 'claude' | 'pi', provider: string, catalog: NameCatalog): NormalizedProvider;
|
|
23
|
+
export declare function normalizeModel(backend: 'claude' | 'pi', provider: string, model: string, catalog: NameCatalog): string;
|
|
24
|
+
/** Heartbeat provider list: built-ins as-is, user-defined ones as `custom`, deduplicated. */
|
|
25
|
+
export declare function normalizeProviderList(providers: string[], catalog: NameCatalog): string[];
|
|
26
|
+
interface CatalogModel {
|
|
27
|
+
provider: string;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function buildNameCatalog(models: CatalogModel[], customProviders: Map<string, string>): NameCatalog;
|
|
31
|
+
/** Built once per UTC day, at the first upload that needs it; never on a turn's hot path. */
|
|
32
|
+
export declare function loadNameCatalog(day: string, modelsPath?: string): Promise<NameCatalog>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { ANTHROPIC_MODELS } from '../../core/anthropic-models.js';
|
|
5
|
+
import { loadPiSdk } from '../../core/pi-sdk.js';
|
|
6
|
+
import { readCustomProviderEntries, USER_PI_MODELS_PATH } from '../pi-providers/models-json-store.js';
|
|
7
|
+
import { TELEMETRY_CUSTOM, TELEMETRY_MCP_OTHER, TELEMETRY_OTHER } from './schema.js';
|
|
8
|
+
/** Built-in tool names of Claude Code and PI (plus the tools Cortex registers on PI). */
|
|
9
|
+
const BUILTIN_TOOLS = new Set([
|
|
10
|
+
'Bash', 'Read', 'Write', 'Edit', 'MultiEdit', 'Grep', 'Glob', 'LS', 'WebFetch', 'WebSearch',
|
|
11
|
+
'AskUserQuestion', 'EnterPlanMode', 'ExitPlanMode', 'TodoWrite', 'Skill', 'Agent', 'Task',
|
|
12
|
+
'TaskOutput', 'TaskStop', 'NotebookEdit', 'NotebookRead', 'BashOutput', 'KillShell', 'KillBash',
|
|
13
|
+
'SlashCommand', 'ToolSearch', 'ListMcpResourcesTool', 'ReadMcpResourceTool',
|
|
14
|
+
'bash', 'read', 'write', 'edit', 'grep', 'glob', 'find', 'ls', 'powershell', 'web_fetch',
|
|
15
|
+
'web_search', 'todo_write', 'skill', 'agent', 'agent_stop',
|
|
16
|
+
]);
|
|
17
|
+
const NOT_IDENT_CHARS = /[^A-Za-z0-9._:/@[\]-]/g;
|
|
18
|
+
/** A public name made to fit the wire identifier shape. */
|
|
19
|
+
export function toIdent(name) {
|
|
20
|
+
return name.replace(NOT_IDENT_CHARS, '_').slice(0, 80) || TELEMETRY_OTHER;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeTool(name) {
|
|
23
|
+
if (BUILTIN_TOOLS.has(name))
|
|
24
|
+
return name;
|
|
25
|
+
if (name.startsWith('mcp__cortex-'))
|
|
26
|
+
return toIdent(name);
|
|
27
|
+
return name.startsWith('mcp__') ? TELEMETRY_MCP_OTHER : TELEMETRY_OTHER;
|
|
28
|
+
}
|
|
29
|
+
export function normalizeProvider(backend, provider, catalog) {
|
|
30
|
+
if (backend === 'claude')
|
|
31
|
+
return { provider: 'anthropic', customApi: null };
|
|
32
|
+
if (catalog.customProviders.has(provider)) {
|
|
33
|
+
return { provider: TELEMETRY_CUSTOM, customApi: toIdent(catalog.customProviders.get(provider)) };
|
|
34
|
+
}
|
|
35
|
+
return { provider: catalog.piProviders.has(provider) ? provider : TELEMETRY_OTHER, customApi: null };
|
|
36
|
+
}
|
|
37
|
+
export function normalizeModel(backend, provider, model, catalog) {
|
|
38
|
+
if (backend === 'claude') {
|
|
39
|
+
const known = ANTHROPIC_MODELS.includes(model) || catalog.modelIds.has(model.replace(/\[1m\]$/, ''));
|
|
40
|
+
return known ? toIdent(model) : TELEMETRY_OTHER;
|
|
41
|
+
}
|
|
42
|
+
if (catalog.customProviders.has(provider))
|
|
43
|
+
return TELEMETRY_CUSTOM;
|
|
44
|
+
return catalog.piModels.has(`${provider}/${model}`) ? toIdent(model) : TELEMETRY_OTHER;
|
|
45
|
+
}
|
|
46
|
+
/** Heartbeat provider list: built-ins as-is, user-defined ones as `custom`, deduplicated. */
|
|
47
|
+
export function normalizeProviderList(providers, catalog) {
|
|
48
|
+
return [...new Set(providers.map((name) => normalizeProvider('pi', name, catalog).provider))];
|
|
49
|
+
}
|
|
50
|
+
function customProviderApis(modelsPath) {
|
|
51
|
+
const entries = readCustomProviderEntries(modelsPath);
|
|
52
|
+
return new Map(Object.entries(entries).map(([name, entry]) => [name, String(entry.api)]));
|
|
53
|
+
}
|
|
54
|
+
/** Read the SDK's bundled catalog without the user's auth, models.json or network. */
|
|
55
|
+
async function loadStaticModels() {
|
|
56
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-telemetry-catalog-'));
|
|
57
|
+
try {
|
|
58
|
+
const authPath = path.join(dir, 'auth.json');
|
|
59
|
+
writeFileSync(authPath, '');
|
|
60
|
+
const sdk = await loadPiSdk();
|
|
61
|
+
const runtime = await sdk.ModelRuntime.create({
|
|
62
|
+
authPath, modelsPath: path.join(dir, 'absent', 'models.json'), allowModelNetwork: false,
|
|
63
|
+
});
|
|
64
|
+
return runtime.getAllModels().map((model) => ({ provider: String(model.provider), id: String(model.id) }));
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
rmSync(dir, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function buildNameCatalog(models, customProviders) {
|
|
71
|
+
return {
|
|
72
|
+
piProviders: new Set(models.map((model) => model.provider)),
|
|
73
|
+
piModels: new Set(models.map((model) => `${model.provider}/${model.id}`)),
|
|
74
|
+
modelIds: new Set(models.map((model) => model.id)),
|
|
75
|
+
customProviders,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
let cached = null;
|
|
79
|
+
/** Built once per UTC day, at the first upload that needs it; never on a turn's hot path. */
|
|
80
|
+
export function loadNameCatalog(day, modelsPath = USER_PI_MODELS_PATH) {
|
|
81
|
+
if (cached?.day === day)
|
|
82
|
+
return cached.catalog;
|
|
83
|
+
const catalog = loadStaticModels()
|
|
84
|
+
.catch(() => [])
|
|
85
|
+
.then((models) => buildNameCatalog(models, customProviderApis(modelsPath)));
|
|
86
|
+
cached = { day, catalog };
|
|
87
|
+
return catalog;
|
|
88
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TelemetryEvent } from './schema.js';
|
|
2
|
+
/** The outbox never grows past this; the oldest lines go first. */
|
|
3
|
+
export declare const OUTBOX_MAX_BYTES: number;
|
|
4
|
+
/** Keep the newest lines that fit in `budget` bytes. */
|
|
5
|
+
export declare function newestWithin(lines: string[], budget: number): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Append one event synchronously, so a process about to die still leaves it on disk. Invalid
|
|
8
|
+
* events are refused. Never throws.
|
|
9
|
+
*/
|
|
10
|
+
export declare function appendToOutbox(event: TelemetryEvent, file?: string, maxBytes?: number): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Everything waiting to be sent, oldest first. New appends go to a fresh outbox file meanwhile
|
|
13
|
+
* (another process may append while an upload runs); `settleOutbox` writes back what is left.
|
|
14
|
+
*/
|
|
15
|
+
export declare function takeOutbox(file?: string): TelemetryEvent[];
|
|
16
|
+
/** Record what an upload attempt could not deliver; an empty list clears the pending file. */
|
|
17
|
+
export declare function settleOutbox(unsent: TelemetryEvent[], file?: string): void;
|
|
18
|
+
export declare function wipeOutbox(file?: string): void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { OUTBOX_FILE } from './paths.js';
|
|
4
|
+
import { TelemetryEventSchema } from './schema.js';
|
|
5
|
+
/** The outbox never grows past this; the oldest lines go first. */
|
|
6
|
+
export const OUTBOX_MAX_BYTES = 2 * 1024 * 1024;
|
|
7
|
+
const TRIM_TARGET_BYTES = Math.floor(OUTBOX_MAX_BYTES * 0.75);
|
|
8
|
+
function sendingFile(file) {
|
|
9
|
+
return `${file.slice(0, -'.jsonl'.length)}.sending.jsonl`;
|
|
10
|
+
}
|
|
11
|
+
function readLines(file) {
|
|
12
|
+
try {
|
|
13
|
+
return readFileSync(file, 'utf8').split('\n').filter((line) => line.trim() !== '');
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Keep the newest lines that fit in `budget` bytes. */
|
|
20
|
+
export function newestWithin(lines, budget) {
|
|
21
|
+
let used = 0;
|
|
22
|
+
let start = lines.length;
|
|
23
|
+
while (start > 0 && used + Buffer.byteLength(lines[start - 1]) + 1 <= budget) {
|
|
24
|
+
start -= 1;
|
|
25
|
+
used += Buffer.byteLength(lines[start]) + 1;
|
|
26
|
+
}
|
|
27
|
+
return lines.slice(start);
|
|
28
|
+
}
|
|
29
|
+
function writeLines(file, lines) {
|
|
30
|
+
if (lines.length === 0)
|
|
31
|
+
return void rmSync(file, { force: true });
|
|
32
|
+
writeFileSync(file, `${lines.join('\n')}\n`, 'utf8');
|
|
33
|
+
}
|
|
34
|
+
function enforceCap(file, maxBytes) {
|
|
35
|
+
if (statSync(file).size <= maxBytes)
|
|
36
|
+
return;
|
|
37
|
+
writeLines(file, newestWithin(readLines(file), Math.floor(maxBytes * 0.75)));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Append one event synchronously, so a process about to die still leaves it on disk. Invalid
|
|
41
|
+
* events are refused. Never throws.
|
|
42
|
+
*/
|
|
43
|
+
export function appendToOutbox(event, file = OUTBOX_FILE, maxBytes = OUTBOX_MAX_BYTES) {
|
|
44
|
+
const parsed = TelemetryEventSchema.safeParse(event);
|
|
45
|
+
if (!parsed.success)
|
|
46
|
+
return false;
|
|
47
|
+
try {
|
|
48
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
49
|
+
appendFileSync(file, `${JSON.stringify(parsed.data)}\n`, 'utf8');
|
|
50
|
+
enforceCap(file, maxBytes);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Everything waiting to be sent, oldest first. New appends go to a fresh outbox file meanwhile
|
|
59
|
+
* (another process may append while an upload runs); `settleOutbox` writes back what is left.
|
|
60
|
+
*/
|
|
61
|
+
export function takeOutbox(file = OUTBOX_FILE) {
|
|
62
|
+
const sending = sendingFile(file);
|
|
63
|
+
if (existsSync(file)) {
|
|
64
|
+
const moved = `${file}.${process.pid}.tmp`;
|
|
65
|
+
try {
|
|
66
|
+
renameSync(file, moved);
|
|
67
|
+
writeLines(sending, newestWithin([...readLines(sending), ...readLines(moved)], TRIM_TARGET_BYTES));
|
|
68
|
+
rmSync(moved, { force: true });
|
|
69
|
+
}
|
|
70
|
+
catch { /* leave both files for the next attempt */ }
|
|
71
|
+
}
|
|
72
|
+
return readLines(sending).flatMap((line) => parseEvent(line));
|
|
73
|
+
}
|
|
74
|
+
function parseEvent(line) {
|
|
75
|
+
try {
|
|
76
|
+
const parsed = TelemetryEventSchema.safeParse(JSON.parse(line));
|
|
77
|
+
return parsed.success ? [parsed.data] : [];
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Record what an upload attempt could not deliver; an empty list clears the pending file. */
|
|
84
|
+
export function settleOutbox(unsent, file = OUTBOX_FILE) {
|
|
85
|
+
try {
|
|
86
|
+
writeLines(sendingFile(file), unsent.map((event) => JSON.stringify(event)));
|
|
87
|
+
}
|
|
88
|
+
catch { /* retried next time */ }
|
|
89
|
+
}
|
|
90
|
+
export function wipeOutbox(file = OUTBOX_FILE) {
|
|
91
|
+
rmSync(file, { force: true });
|
|
92
|
+
rmSync(sendingFile(file), { force: true });
|
|
93
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The reportable form of a panic location's file, or null when none can be derived safely. */
|
|
2
|
+
export declare function panicFile(raw: string): string | null;
|
|
3
|
+
/** `panic@<file>:<line>` from the panic message, else from the backtrace, else `panic@unknown`. */
|
|
4
|
+
export declare function panicGroupKey(message: string, stack: string): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Group keys for native shell panics. The shell's panic hook formats its message as
|
|
2
|
+
// `<text> at <file>:<line>:<col>`; the file is relative for the shell's own crate (`src/setup.rs`) and
|
|
3
|
+
// absolute for dependencies and the standard library. Only the source-relative part is kept, so a
|
|
4
|
+
// key never carries a home directory, user name or checkout location.
|
|
5
|
+
const MESSAGE_LOCATION_RE = / at (\S+):(\d+):\d+\s*$/;
|
|
6
|
+
const FRAME_LOCATION_RE = /^\s*at (\S+):(\d+):\d+\s*$/;
|
|
7
|
+
const SAFE_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
|
|
8
|
+
/** A published crate directory in the cargo registry (`tauri-2.1.0`). */
|
|
9
|
+
const CRATE_DIR_RE = /^[A-Za-z0-9_-]+-\d+\.\d+\.\d+[A-Za-z0-9.+-]*$/;
|
|
10
|
+
/** A standard library crate under the toolchain's `library/` directory. */
|
|
11
|
+
const STD_CRATE_RE = /^(?:core|std|alloc|proc_macro|test)$/;
|
|
12
|
+
const MAX_FILE_LENGTH = 120;
|
|
13
|
+
function isRelative(file) {
|
|
14
|
+
return !/^(?:[A-Za-z]:\/|\/|~)/.test(file);
|
|
15
|
+
}
|
|
16
|
+
function safePath(file) {
|
|
17
|
+
const segments = file.split('/');
|
|
18
|
+
const safe = segments.every((segment) => SAFE_SEGMENT_RE.test(segment) && segment !== '..');
|
|
19
|
+
return safe && file.length <= MAX_FILE_LENGTH ? file : null;
|
|
20
|
+
}
|
|
21
|
+
/** `src/...` of an absolute path, prefixed with the crate directory when that is public. */
|
|
22
|
+
function sourceRelative(file) {
|
|
23
|
+
const at = file.lastIndexOf('/src/');
|
|
24
|
+
if (at < 0)
|
|
25
|
+
return null;
|
|
26
|
+
const parent = file.slice(0, at).split('/').pop() ?? '';
|
|
27
|
+
const publicCrate = CRATE_DIR_RE.test(parent) || (file.includes('/library/') && STD_CRATE_RE.test(parent));
|
|
28
|
+
return publicCrate ? `${parent}/${file.slice(at + 1)}` : file.slice(at + 1);
|
|
29
|
+
}
|
|
30
|
+
/** The reportable form of a panic location's file, or null when none can be derived safely. */
|
|
31
|
+
export function panicFile(raw) {
|
|
32
|
+
const file = raw.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
33
|
+
return safePath(isRelative(file) ? file : sourceRelative(file) ?? '');
|
|
34
|
+
}
|
|
35
|
+
function locationKey(match) {
|
|
36
|
+
const file = match ? panicFile(match[1]) : null;
|
|
37
|
+
return file ? `panic@${file}:${match[2]}` : null;
|
|
38
|
+
}
|
|
39
|
+
/** First backtrace frame in the shell's own crate (a relative path); library frames come first. */
|
|
40
|
+
function ownFrameKey(stack) {
|
|
41
|
+
for (const line of stack.split('\n')) {
|
|
42
|
+
const match = FRAME_LOCATION_RE.exec(line);
|
|
43
|
+
if (match && isRelative(match[1].replace(/\\/g, '/')))
|
|
44
|
+
return locationKey(match);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** `panic@<file>:<line>` from the panic message, else from the backtrace, else `panic@unknown`. */
|
|
49
|
+
export function panicGroupKey(message, stack) {
|
|
50
|
+
return locationKey(MESSAGE_LOCATION_RE.exec(message)) ?? ownFrameKey(stack) ?? 'panic@unknown';
|
|
51
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Everything telemetry keeps on disk lives here; nothing outside it is written. */
|
|
2
|
+
export declare const TELEMETRY_DIR: string;
|
|
3
|
+
export declare const INSTALL_ID_FILE: string;
|
|
4
|
+
export declare const OUTBOX_FILE: string;
|
|
5
|
+
export declare const STATE_FILE: string;
|
|
6
|
+
export declare const ROLLUP_PREFIX = "rollup-";
|
|
7
|
+
export declare function rollupFile(day: string, dir?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { STORE_DIR } from '../../core/paths.js';
|
|
3
|
+
/** Everything telemetry keeps on disk lives here; nothing outside it is written. */
|
|
4
|
+
export const TELEMETRY_DIR = path.join(STORE_DIR, 'telemetry');
|
|
5
|
+
export const INSTALL_ID_FILE = path.join(TELEMETRY_DIR, 'install-id');
|
|
6
|
+
export const OUTBOX_FILE = path.join(TELEMETRY_DIR, 'outbox.jsonl');
|
|
7
|
+
export const STATE_FILE = path.join(TELEMETRY_DIR, 'state.json');
|
|
8
|
+
export const ROLLUP_PREFIX = 'rollup-';
|
|
9
|
+
export function rollupFile(day, dir = TELEMETRY_DIR) {
|
|
10
|
+
return path.join(dir, `${ROLLUP_PREFIX}${day}.json`);
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What redaction must recognize on this machine. Injected in tests. */
|
|
2
|
+
export interface RedactionContext {
|
|
3
|
+
installRoot: string;
|
|
4
|
+
homeDir: string;
|
|
5
|
+
username: string;
|
|
6
|
+
hostname: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const MAX_MESSAGE_CHARS = 300;
|
|
9
|
+
export declare const MAX_STACK_FRAMES = 30;
|
|
10
|
+
export declare const MAX_STACK_CHARS = 8000;
|
|
11
|
+
export declare function defaultRedactionContext(): RedactionContext;
|
|
12
|
+
/** Apply every rule. Order matters: Cortex's own paths become relative before any path is cut. */
|
|
13
|
+
export declare function redactText(text: string, ctx?: RedactionContext): string;
|
|
14
|
+
export declare function redactMessage(text: string, ctx?: RedactionContext): string;
|
|
15
|
+
/** Redacted stack: the header line plus at most 30 frames, within the size cap. */
|
|
16
|
+
export declare function redactStack(stack: string, ctx?: RedactionContext): string;
|
|
17
|
+
/** Grouping key: error name + the first frame in Cortex's own code (function and file). */
|
|
18
|
+
export declare function groupKeyOf(errorName: string, redactedStack: string): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { INSTALL_ROOT } from '../../core/paths.js';
|
|
3
|
+
export const MAX_MESSAGE_CHARS = 300;
|
|
4
|
+
export const MAX_STACK_FRAMES = 30;
|
|
5
|
+
export const MAX_STACK_CHARS = 8_000;
|
|
6
|
+
function safeUsername() {
|
|
7
|
+
try {
|
|
8
|
+
return os.userInfo().username;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function defaultRedactionContext() {
|
|
15
|
+
return { installRoot: INSTALL_ROOT, homeDir: os.homedir(), username: safeUsername(), hostname: os.hostname() };
|
|
16
|
+
}
|
|
17
|
+
function escapeRegExp(text) {
|
|
18
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
19
|
+
}
|
|
20
|
+
/** Both separator spellings of a directory, longest first, for literal matching. */
|
|
21
|
+
function spellings(dir) {
|
|
22
|
+
const forward = dir.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
23
|
+
const back = forward.replace(/\//g, '\\');
|
|
24
|
+
return [...new Set([forward, back])].filter((item) => item.length > 1);
|
|
25
|
+
}
|
|
26
|
+
/** Cortex's own files keep their path relative to the install root (`dist/domain/...`). */
|
|
27
|
+
function relativizeInstallRoot(text, installRoot) {
|
|
28
|
+
let out = text;
|
|
29
|
+
for (const root of spellings(installRoot)) {
|
|
30
|
+
const pattern = new RegExp(`(?:file:\\/\\/\\/?)?${escapeRegExp(root)}([\\\\/][^\\s:'"()<>]*)`, 'g');
|
|
31
|
+
out = out.replace(pattern, (_match, rest) => rest.slice(1).replace(/\\/g, '/'));
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
const URL_RE = /\b([a-z][a-z0-9+.-]*):\/\/([^\s/?#'"()<>]*)([^\s?#'"()<>]*)(?:[?#][^\s'"()<>]*)?/gi;
|
|
36
|
+
const KEEP_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
37
|
+
/** URLs keep scheme and path; the host becomes `<host>`, query, fragment and userinfo go. */
|
|
38
|
+
function redactUrls(text) {
|
|
39
|
+
return text.replace(URL_RE, (_match, scheme, authority, pathPart) => {
|
|
40
|
+
const host = authority.replace(/^[^@]*@/, '');
|
|
41
|
+
const bare = host.replace(/:\d+$/, '').toLowerCase();
|
|
42
|
+
const keep = scheme.toLowerCase() === 'cortexui' || KEEP_HOSTS.has(bare);
|
|
43
|
+
if (scheme.toLowerCase() === 'file')
|
|
44
|
+
return '<path>';
|
|
45
|
+
return `${scheme}://${keep ? host : '<host>'}${pathPart}`;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
49
|
+
const PREFIXED_KEY_RE = /\b(?:sk|pk|rk|ghp|gho|ghs|ghu|github_pat|xox[abposr]|glpat|AKIA|AIza)[-_A-Za-z0-9]{8,}/g;
|
|
50
|
+
const HEX_RE = /\b[0-9a-fA-F]{32,}\b/g;
|
|
51
|
+
const B64_RE = /[A-Za-z0-9+_=-]{32,}/g;
|
|
52
|
+
const IPV4_RE = /\b(?!127\.0\.0\.1\b)(?!0\.0\.0\.0\b)(?:\d{1,3}\.){3}\d{1,3}\b/g;
|
|
53
|
+
function redactSecrets(text) {
|
|
54
|
+
return text
|
|
55
|
+
.replace(EMAIL_RE, '<email>')
|
|
56
|
+
.replace(PREFIXED_KEY_RE, '<secret>')
|
|
57
|
+
.replace(HEX_RE, '<secret>')
|
|
58
|
+
.replace(B64_RE, (run) => (/\d/.test(run) && /[A-Za-z]/.test(run) ? '<secret>' : run))
|
|
59
|
+
.replace(IPV4_RE, '<ip>');
|
|
60
|
+
}
|
|
61
|
+
const POSIX_PATH_RE = /(?<![\w.:/\\<>-])\/(?:[^\s:'"()<>,;]+)/g;
|
|
62
|
+
const WINDOWS_PATH_RE = /\b[A-Za-z]:[\\/][^\s:'"()<>,;]*/g;
|
|
63
|
+
const UNC_PATH_RE = /\\\\[^\s\\:'"()<>]+\\[^\s:'"()<>,;]*/g;
|
|
64
|
+
function redactAbsolutePaths(text) {
|
|
65
|
+
return text.replace(UNC_PATH_RE, '<path>').replace(WINDOWS_PATH_RE, '<path>').replace(POSIX_PATH_RE, '<path>');
|
|
66
|
+
}
|
|
67
|
+
/** Literal leftovers: the home directory, user name and host name anywhere in the text. */
|
|
68
|
+
function redactIdentity(text, ctx) {
|
|
69
|
+
let out = text;
|
|
70
|
+
for (const home of spellings(ctx.homeDir))
|
|
71
|
+
out = out.split(home).join('<home>');
|
|
72
|
+
const names = [[ctx.hostname, '<host>'], [ctx.username, '<user>']];
|
|
73
|
+
// Longest first: a host name often contains the user name.
|
|
74
|
+
for (const [value, label] of [...names].sort((a, b) => b[0].length - a[0].length)) {
|
|
75
|
+
if (value.length < 3)
|
|
76
|
+
continue;
|
|
77
|
+
out = out.replace(new RegExp(`(?<![A-Za-z0-9])${escapeRegExp(value)}(?![A-Za-z0-9])`, 'gi'), label);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** Apply every rule. Order matters: Cortex's own paths become relative before any path is cut. */
|
|
82
|
+
export function redactText(text, ctx = defaultRedactionContext()) {
|
|
83
|
+
const relative = relativizeInstallRoot(text, ctx.installRoot);
|
|
84
|
+
return redactIdentity(redactAbsolutePaths(redactSecrets(redactUrls(relative))), ctx);
|
|
85
|
+
}
|
|
86
|
+
export function redactMessage(text, ctx) {
|
|
87
|
+
return redactText(text, ctx).slice(0, MAX_MESSAGE_CHARS);
|
|
88
|
+
}
|
|
89
|
+
/** Redacted stack: the header line plus at most 30 frames, within the size cap. */
|
|
90
|
+
export function redactStack(stack, ctx) {
|
|
91
|
+
const lines = redactText(stack, ctx).split('\n');
|
|
92
|
+
const header = lines.findIndex((line) => /^\s*at\s/.test(line));
|
|
93
|
+
const frames = header === -1 ? lines.slice(0, MAX_STACK_FRAMES + 1) : lines.slice(0, header + MAX_STACK_FRAMES);
|
|
94
|
+
return frames.join('\n').slice(0, MAX_STACK_CHARS);
|
|
95
|
+
}
|
|
96
|
+
const OWN_FRAME_RE = /^\s*at\s+(?:(\S+)\s+)?\(?((?:dist|src)\/[^\s:()]+)/;
|
|
97
|
+
const WEB_FRAME_RE = /(?:^|[\s@(])((?:[a-z]+:\/\/[^\s/]+)?\/assets\/[^\s:()]+)/;
|
|
98
|
+
/** Grouping key: error name + the first frame in Cortex's own code (function and file). */
|
|
99
|
+
export function groupKeyOf(errorName, redactedStack) {
|
|
100
|
+
for (const line of redactedStack.split('\n')) {
|
|
101
|
+
const own = OWN_FRAME_RE.exec(line);
|
|
102
|
+
if (own)
|
|
103
|
+
return `${errorName}@${own[2]}${own[1] ? `#${own[1]}` : ''}`.slice(0, 200);
|
|
104
|
+
const web = WEB_FRAME_RE.exec(line);
|
|
105
|
+
if (web)
|
|
106
|
+
return `${errorName}@${web[1].replace(/^[a-z]+:\/\/[^/]+/, '')}`.slice(0, 200);
|
|
107
|
+
}
|
|
108
|
+
return `${errorName}@unknown`.slice(0, 200);
|
|
109
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type TURN_FAILURE_CLASSES } from './schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* One UTC day of aggregates as kept on this machine. Names are raw here (the user's own disk);
|
|
4
|
+
* they are normalized only when the day is turned into an upload (see daily.ts).
|
|
5
|
+
*/
|
|
6
|
+
export interface RawTurnRow {
|
|
7
|
+
backend: 'claude' | 'pi';
|
|
8
|
+
provider: string;
|
|
9
|
+
model: string;
|
|
10
|
+
billing: 'plan' | 'api' | null;
|
|
11
|
+
outcomes: {
|
|
12
|
+
completed: number;
|
|
13
|
+
failed: number;
|
|
14
|
+
cancelled: number;
|
|
15
|
+
rateLimited: number;
|
|
16
|
+
};
|
|
17
|
+
failures: Partial<Record<(typeof TURN_FAILURE_CLASSES)[number], number>>;
|
|
18
|
+
retries: number;
|
|
19
|
+
fallbacks: number;
|
|
20
|
+
ttftMs: number[];
|
|
21
|
+
durationS: number[];
|
|
22
|
+
contextPctAtEnd: number[];
|
|
23
|
+
compactions: {
|
|
24
|
+
auto: number;
|
|
25
|
+
manual: number;
|
|
26
|
+
};
|
|
27
|
+
tokens: {
|
|
28
|
+
input: number;
|
|
29
|
+
output: number;
|
|
30
|
+
cacheRead: number;
|
|
31
|
+
cacheWrite: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface OutcomeCounts {
|
|
35
|
+
completed: number;
|
|
36
|
+
failed: number;
|
|
37
|
+
cancelled: number;
|
|
38
|
+
}
|
|
39
|
+
export interface RawErrorSample {
|
|
40
|
+
module: string;
|
|
41
|
+
groupKey: string;
|
|
42
|
+
message: string;
|
|
43
|
+
count: number;
|
|
44
|
+
}
|
|
45
|
+
export interface RawRollup {
|
|
46
|
+
day: string;
|
|
47
|
+
turns: Record<string, RawTurnRow>;
|
|
48
|
+
features: Record<string, number>;
|
|
49
|
+
messagesByChannel: Record<string, number>;
|
|
50
|
+
uiOps: Record<string, number>;
|
|
51
|
+
tools: Record<string, {
|
|
52
|
+
calls: number;
|
|
53
|
+
errors: number;
|
|
54
|
+
}>;
|
|
55
|
+
agent: {
|
|
56
|
+
userInterrupts: number;
|
|
57
|
+
superseded: number;
|
|
58
|
+
/** Turns per session id today; only the histogram of the counts is uploaded. */
|
|
59
|
+
sessionTurns: Record<string, number>;
|
|
60
|
+
workers: OutcomeCounts;
|
|
61
|
+
subagents: OutcomeCounts;
|
|
62
|
+
};
|
|
63
|
+
perf: {
|
|
64
|
+
startups: Array<Record<string, number>>;
|
|
65
|
+
eventLoopP99s: number[];
|
|
66
|
+
web: {
|
|
67
|
+
loads: number;
|
|
68
|
+
ttfbMs: number[];
|
|
69
|
+
firstRenderMs: number[];
|
|
70
|
+
interactiveMs: number[];
|
|
71
|
+
};
|
|
72
|
+
sseReconnects: number;
|
|
73
|
+
remoteClientDisconnects: number;
|
|
74
|
+
};
|
|
75
|
+
errors: {
|
|
76
|
+
byModule: Record<string, number>;
|
|
77
|
+
samples: RawErrorSample[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export declare function emptyTurnRow(backend: RawTurnRow['backend'], provider: string, model: string, billing: RawTurnRow['billing']): RawTurnRow;
|
|
81
|
+
export declare function emptyRollup(day: string): RawRollup;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { emptyHistogram } from './schema.js';
|
|
2
|
+
export function emptyTurnRow(backend, provider, model, billing) {
|
|
3
|
+
return {
|
|
4
|
+
backend, provider, model, billing,
|
|
5
|
+
outcomes: { completed: 0, failed: 0, cancelled: 0, rateLimited: 0 },
|
|
6
|
+
failures: {}, retries: 0, fallbacks: 0,
|
|
7
|
+
ttftMs: emptyHistogram('ttftMs'),
|
|
8
|
+
durationS: emptyHistogram('turnDurationS'),
|
|
9
|
+
contextPctAtEnd: emptyHistogram('contextPct'),
|
|
10
|
+
compactions: { auto: 0, manual: 0 },
|
|
11
|
+
tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const outcomes = () => ({ completed: 0, failed: 0, cancelled: 0 });
|
|
15
|
+
export function emptyRollup(day) {
|
|
16
|
+
return {
|
|
17
|
+
day, turns: {}, features: {}, messagesByChannel: {}, uiOps: {}, tools: {},
|
|
18
|
+
agent: { userInterrupts: 0, superseded: 0, sessionTurns: {}, workers: outcomes(), subagents: outcomes() },
|
|
19
|
+
perf: {
|
|
20
|
+
startups: [],
|
|
21
|
+
eventLoopP99s: [],
|
|
22
|
+
web: {
|
|
23
|
+
loads: 0, ttfbMs: emptyHistogram('webLoadMs'),
|
|
24
|
+
firstRenderMs: emptyHistogram('webLoadMs'), interactiveMs: emptyHistogram('webLoadMs'),
|
|
25
|
+
},
|
|
26
|
+
sseReconnects: 0,
|
|
27
|
+
remoteClientDisconnects: 0,
|
|
28
|
+
},
|
|
29
|
+
errors: { byModule: {}, samples: [] },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RawRollup } from './rollup-types.js';
|
|
2
|
+
export declare function utcDay(at: number): string;
|
|
3
|
+
/** Tests point the store at their own directory and clock. */
|
|
4
|
+
export declare function configureRollupStore(next: {
|
|
5
|
+
dir?: string;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
}): void;
|
|
8
|
+
/** Apply one change to today's aggregates; a no-op while telemetry is inactive. */
|
|
9
|
+
export declare function updateRollup(change: (rollup: RawRollup) => void): void;
|
|
10
|
+
export declare function recordEventLoopP99(rollup: RawRollup, p99Ms: number): void;
|
|
11
|
+
export declare function persistRollup(): void;
|
|
12
|
+
/** Finished days, oldest first; their files are removed by `dropRollupDay` once queued. */
|
|
13
|
+
export declare function finishedRollups(now?: number): RawRollup[];
|
|
14
|
+
export declare function dropRollupDay(day: string): void;
|
|
15
|
+
export declare function wipeRollups(): void;
|
|
16
|
+
export declare function rollupDir(): string;
|