@neta-art/cohub-cli 10.23.0 → 10.25.0
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 +18 -5
- package/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +309 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2511 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -118
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -64
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2139
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -6
- package/dist/session-status.js +0 -16
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import type { LocalHarness, RuntimeTraceContext } from "@neta-art/cohub";
|
|
2
|
-
export type RuntimeDiagnosticLevel = "debug" | "info" | "warn" | "error";
|
|
3
|
-
export type RuntimeDiagnosticError = {
|
|
4
|
-
name?: string;
|
|
5
|
-
message: string;
|
|
6
|
-
code?: string;
|
|
7
|
-
status?: number;
|
|
8
|
-
syscall?: string;
|
|
9
|
-
hostname?: string;
|
|
10
|
-
causeCode?: string;
|
|
11
|
-
causeMessage?: string;
|
|
12
|
-
causeSyscall?: string;
|
|
13
|
-
causeHostname?: string;
|
|
14
|
-
traceContext?: RuntimeTraceContext;
|
|
15
|
-
stack?: string;
|
|
16
|
-
};
|
|
17
|
-
export type RuntimeDiagnostic = {
|
|
18
|
-
schemaVersion: 1;
|
|
19
|
-
sequence: number;
|
|
20
|
-
timestamp: string;
|
|
21
|
-
elapsedMs: number;
|
|
22
|
-
level: RuntimeDiagnosticLevel;
|
|
23
|
-
component: string;
|
|
24
|
-
event: string;
|
|
25
|
-
runtimeId: string;
|
|
26
|
-
connectionId?: string | null;
|
|
27
|
-
spaceId: string;
|
|
28
|
-
sessionId?: string | null;
|
|
29
|
-
turnId?: string | null;
|
|
30
|
-
harness?: LocalHarness | null;
|
|
31
|
-
traceContext?: RuntimeTraceContext;
|
|
32
|
-
data?: Record<string, unknown>;
|
|
33
|
-
error?: RuntimeDiagnosticError;
|
|
34
|
-
};
|
|
35
|
-
export type RuntimeDiagnosticContext = {
|
|
36
|
-
component?: string;
|
|
37
|
-
connectionId?: string | null;
|
|
38
|
-
requestId?: string | null;
|
|
39
|
-
spaceId?: string;
|
|
40
|
-
sessionId?: string | null;
|
|
41
|
-
turnId?: string | null;
|
|
42
|
-
harness?: LocalHarness | null;
|
|
43
|
-
traceContext?: RuntimeTraceContext;
|
|
44
|
-
};
|
|
45
|
-
export type RuntimeDiagnosticsOptions = {
|
|
46
|
-
root: string;
|
|
47
|
-
runtimeId?: string;
|
|
48
|
-
spaceId: string;
|
|
49
|
-
component?: string;
|
|
50
|
-
logFlushIntervalMs?: number;
|
|
51
|
-
maxLogFileBytes?: number;
|
|
52
|
-
maxTotalLogBytes?: number;
|
|
53
|
-
/** Receives only the redacted event, before asynchronous disk I/O. */
|
|
54
|
-
onEvent?: (event: RuntimeDiagnostic) => void;
|
|
55
|
-
};
|
|
56
|
-
export type ReadRuntimeDiagnosticsOptions = {
|
|
57
|
-
limit?: number;
|
|
58
|
-
};
|
|
59
|
-
export declare const runtimeDiagnosticsDirectory: (root: string) => string;
|
|
60
|
-
export declare const runtimeDiagnosticsPath: (root: string, runtimeId: string) => string;
|
|
61
|
-
export declare function redactDiagnosticString(value: string): string;
|
|
62
|
-
export declare function serializeDiagnosticError(error: unknown): RuntimeDiagnosticError;
|
|
63
|
-
export declare class RuntimeDiagnostics {
|
|
64
|
-
readonly runtimeId: string;
|
|
65
|
-
readonly directory: string;
|
|
66
|
-
readonly logPath: string;
|
|
67
|
-
private readonly spaceId;
|
|
68
|
-
private readonly component;
|
|
69
|
-
private readonly onEvent?;
|
|
70
|
-
private readonly logFlushIntervalMs;
|
|
71
|
-
private readonly maxLogFileBytes;
|
|
72
|
-
private readonly maxTotalLogBytes;
|
|
73
|
-
private readonly startedAtMs;
|
|
74
|
-
private readonly ready;
|
|
75
|
-
private logFile;
|
|
76
|
-
private logFileSize;
|
|
77
|
-
private logFileStartedAt;
|
|
78
|
-
private writeChain;
|
|
79
|
-
private writeBuffer;
|
|
80
|
-
private writeBufferBytes;
|
|
81
|
-
private droppedWriteEvents;
|
|
82
|
-
private writeTimer;
|
|
83
|
-
private sequence;
|
|
84
|
-
private closed;
|
|
85
|
-
constructor(options: RuntimeDiagnosticsOptions);
|
|
86
|
-
log(level: RuntimeDiagnosticLevel, event: string, data?: Record<string, unknown>, context?: RuntimeDiagnosticContext): void;
|
|
87
|
-
close(): Promise<void>;
|
|
88
|
-
private enqueueWrite;
|
|
89
|
-
private scheduleLogFlush;
|
|
90
|
-
private flushLogBuffer;
|
|
91
|
-
private writeEntries;
|
|
92
|
-
private ensureLogFile;
|
|
93
|
-
private rotateLog;
|
|
94
|
-
private enforceLogCapacity;
|
|
95
|
-
}
|
|
96
|
-
export declare class RuntimeDiagnosticReader {
|
|
97
|
-
readonly root: string;
|
|
98
|
-
private readonly files;
|
|
99
|
-
private readonly lastSequenceByRuntime;
|
|
100
|
-
private initialized;
|
|
101
|
-
constructor(root: string);
|
|
102
|
-
read(options?: {
|
|
103
|
-
limit?: number;
|
|
104
|
-
}): Promise<RuntimeDiagnostic[]>;
|
|
105
|
-
}
|
|
106
|
-
export declare function readRuntimeDiagnosticEvents(root: string, options?: ReadRuntimeDiagnosticsOptions): Promise<RuntimeDiagnostic[]>;
|
|
107
|
-
export declare function isValidRuntimeTraceparent(value: string | null | undefined): value is string;
|
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createReadStream } from "node:fs";
|
|
3
|
-
import { mkdir, open, readdir, rename, rm, stat } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { StringDecoder } from "node:string_decoder";
|
|
6
|
-
const DEFAULT_LOG_FLUSH_INTERVAL_MS = 250;
|
|
7
|
-
const MAX_PENDING_LOG_BYTES = 4 * 1024 * 1024;
|
|
8
|
-
const DEFAULT_MAX_LOG_FILE_BYTES = 8 * 1024 * 1024;
|
|
9
|
-
const DEFAULT_MAX_TOTAL_LOG_BYTES = 64 * 1024 * 1024;
|
|
10
|
-
const DEFAULT_MAX_LOG_FILE_AGE_MS = 60 * 60 * 1_000;
|
|
11
|
-
const MAX_VALUE_STRING_LENGTH = 4_096;
|
|
12
|
-
const MAX_EVENT_BYTES = 48 * 1024;
|
|
13
|
-
const SENSITIVE_KEY = /authorization|cookie|password|secret|token|access[_-]?key|refresh[_-]?token/i;
|
|
14
|
-
const TRACEPARENT = /^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/i;
|
|
15
|
-
const diagnosticsDirectoryName = "diagnostics";
|
|
16
|
-
export const runtimeDiagnosticsDirectory = (root) => join(root, diagnosticsDirectoryName);
|
|
17
|
-
export const runtimeDiagnosticsPath = (root, runtimeId) => join(runtimeDiagnosticsDirectory(root), `${runtimeId}.jsonl`);
|
|
18
|
-
function isRecord(value) {
|
|
19
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
20
|
-
}
|
|
21
|
-
function redactUrl(value) {
|
|
22
|
-
try {
|
|
23
|
-
const url = new URL(value);
|
|
24
|
-
// Redaction must not rewrite the string when there is nothing to hide;
|
|
25
|
-
// URL.toString() re-encodes (e.g. quotes from wrapped log lines) and
|
|
26
|
-
// makes healthy URLs look corrupted.
|
|
27
|
-
const sensitive = [...url.searchParams.keys()].some((key) => SENSITIVE_KEY.test(key));
|
|
28
|
-
if (!sensitive)
|
|
29
|
-
return value;
|
|
30
|
-
for (const key of [...url.searchParams.keys()]) {
|
|
31
|
-
if (SENSITIVE_KEY.test(key))
|
|
32
|
-
url.searchParams.set(key, "[REDACTED]");
|
|
33
|
-
}
|
|
34
|
-
return url.toString();
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export function redactDiagnosticString(value) {
|
|
41
|
-
const shortened = value.length > MAX_VALUE_STRING_LENGTH
|
|
42
|
-
? `${value.slice(0, MAX_VALUE_STRING_LENGTH)}…`
|
|
43
|
-
: value;
|
|
44
|
-
return shortened
|
|
45
|
-
.replace(/\bBearer\s+[^\s,;]+/gi, "Bearer [REDACTED]")
|
|
46
|
-
// Trailing quotes/brackets from wrapped log lines are not part of the URL.
|
|
47
|
-
.replace(/\b(rediss?|https?|wss?):\/\/[^\s"'<>]+/gi, (url) => redactUrl(url))
|
|
48
|
-
.replace(/\b(authorization|password|secret|token|access[_-]?key|refresh[_-]?token)([\s:=]+)([^\s,;]+)/gi, "$1$2[REDACTED]");
|
|
49
|
-
}
|
|
50
|
-
function redactValue(value, seen = new WeakSet(), depth = 0) {
|
|
51
|
-
if (value == null || typeof value === "boolean" || typeof value === "number")
|
|
52
|
-
return value;
|
|
53
|
-
if (typeof value === "string")
|
|
54
|
-
return redactDiagnosticString(value);
|
|
55
|
-
if (depth > 5)
|
|
56
|
-
return "[Truncated]";
|
|
57
|
-
if (typeof value !== "object")
|
|
58
|
-
return String(value);
|
|
59
|
-
if (seen.has(value))
|
|
60
|
-
return "[Circular]";
|
|
61
|
-
seen.add(value);
|
|
62
|
-
if (Array.isArray(value))
|
|
63
|
-
return value.slice(0, 64).map((item) => redactValue(item, seen, depth + 1));
|
|
64
|
-
const output = {};
|
|
65
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
66
|
-
output[key] = SENSITIVE_KEY.test(key) ? "[REDACTED]" : redactValue(nested, seen, depth + 1);
|
|
67
|
-
}
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
function normalizeDiagnosticTraceContext(value) {
|
|
71
|
-
if (!isRecord(value))
|
|
72
|
-
return undefined;
|
|
73
|
-
const requestId = typeof value.requestId === "string" && /^[a-zA-Z0-9._:-]{1,128}$/.test(value.requestId)
|
|
74
|
-
? value.requestId
|
|
75
|
-
: undefined;
|
|
76
|
-
const traceId = typeof value.traceId === "string" && /^[0-9a-f]{32}$/i.test(value.traceId) ? value.traceId : undefined;
|
|
77
|
-
const spanId = typeof value.spanId === "string" && /^[0-9a-f]{16}$/i.test(value.spanId) ? value.spanId : undefined;
|
|
78
|
-
const traceparent = typeof value.traceparent === "string" && TRACEPARENT.test(value.traceparent) ? value.traceparent : undefined;
|
|
79
|
-
if (!requestId && !traceId && !spanId && !traceparent)
|
|
80
|
-
return undefined;
|
|
81
|
-
return {
|
|
82
|
-
...(requestId ? { requestId } : {}),
|
|
83
|
-
...(traceId ? { traceId } : {}),
|
|
84
|
-
...(spanId ? { spanId } : {}),
|
|
85
|
-
...(traceparent ? { traceparent } : {}),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
export function serializeDiagnosticError(error) {
|
|
89
|
-
if (!(error instanceof Error))
|
|
90
|
-
return { message: redactDiagnosticString(String(error)) };
|
|
91
|
-
const source = error;
|
|
92
|
-
const result = {
|
|
93
|
-
message: error.message || error.name || "Unknown error",
|
|
94
|
-
...(error.name ? { name: error.name } : {}),
|
|
95
|
-
...(error.stack ? { stack: error.stack } : {}),
|
|
96
|
-
};
|
|
97
|
-
for (const key of ["code", "status", "syscall", "hostname"]) {
|
|
98
|
-
const value = source[key];
|
|
99
|
-
if (typeof value === "string" || typeof value === "number")
|
|
100
|
-
result[key] = value;
|
|
101
|
-
}
|
|
102
|
-
const cause = isRecord(source.cause) ? source.cause : null;
|
|
103
|
-
const traceContext = normalizeDiagnosticTraceContext(source.traceContext);
|
|
104
|
-
if (traceContext)
|
|
105
|
-
result.traceContext = traceContext;
|
|
106
|
-
if (typeof cause?.code === "string")
|
|
107
|
-
result.causeCode = cause.code;
|
|
108
|
-
if (typeof cause?.message === "string")
|
|
109
|
-
result.causeMessage = cause.message;
|
|
110
|
-
if (typeof cause?.syscall === "string")
|
|
111
|
-
result.causeSyscall = cause.syscall;
|
|
112
|
-
if (typeof cause?.hostname === "string")
|
|
113
|
-
result.causeHostname = cause.hostname;
|
|
114
|
-
return redactValue(result);
|
|
115
|
-
}
|
|
116
|
-
function compactEvent(event) {
|
|
117
|
-
let result = redactValue(event);
|
|
118
|
-
if (Buffer.byteLength(JSON.stringify(result), "utf8") <= MAX_EVENT_BYTES)
|
|
119
|
-
return result;
|
|
120
|
-
result = {
|
|
121
|
-
...result,
|
|
122
|
-
data: { truncated: true },
|
|
123
|
-
...(result.error ? { error: { ...result.error, stack: undefined } } : {}),
|
|
124
|
-
};
|
|
125
|
-
if (Buffer.byteLength(JSON.stringify(result), "utf8") <= MAX_EVENT_BYTES)
|
|
126
|
-
return result;
|
|
127
|
-
return {
|
|
128
|
-
...result,
|
|
129
|
-
data: undefined,
|
|
130
|
-
error: result.error ? { message: result.error.message, name: result.error.name } : undefined,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function compareDiagnosticEvents(left, right) {
|
|
134
|
-
if (left.runtimeId === right.runtimeId)
|
|
135
|
-
return left.sequence - right.sequence;
|
|
136
|
-
return left.timestamp.localeCompare(right.timestamp) || left.runtimeId.localeCompare(right.runtimeId) || left.sequence - right.sequence;
|
|
137
|
-
}
|
|
138
|
-
export class RuntimeDiagnostics {
|
|
139
|
-
runtimeId;
|
|
140
|
-
directory;
|
|
141
|
-
logPath;
|
|
142
|
-
spaceId;
|
|
143
|
-
component;
|
|
144
|
-
onEvent;
|
|
145
|
-
logFlushIntervalMs;
|
|
146
|
-
maxLogFileBytes;
|
|
147
|
-
maxTotalLogBytes;
|
|
148
|
-
startedAtMs = Date.now();
|
|
149
|
-
ready;
|
|
150
|
-
logFile = null;
|
|
151
|
-
logFileSize = 0;
|
|
152
|
-
logFileStartedAt = 0;
|
|
153
|
-
writeChain = Promise.resolve();
|
|
154
|
-
writeBuffer = [];
|
|
155
|
-
writeBufferBytes = 0;
|
|
156
|
-
droppedWriteEvents = 0;
|
|
157
|
-
writeTimer = null;
|
|
158
|
-
sequence = 0;
|
|
159
|
-
closed = false;
|
|
160
|
-
constructor(options) {
|
|
161
|
-
this.runtimeId = options.runtimeId ?? randomUUID();
|
|
162
|
-
this.spaceId = options.spaceId;
|
|
163
|
-
this.component = options.component ?? "runtime";
|
|
164
|
-
this.onEvent = options.onEvent;
|
|
165
|
-
this.logFlushIntervalMs = options.logFlushIntervalMs ?? DEFAULT_LOG_FLUSH_INTERVAL_MS;
|
|
166
|
-
this.maxLogFileBytes = options.maxLogFileBytes ?? DEFAULT_MAX_LOG_FILE_BYTES;
|
|
167
|
-
this.maxTotalLogBytes = options.maxTotalLogBytes ?? DEFAULT_MAX_TOTAL_LOG_BYTES;
|
|
168
|
-
this.directory = runtimeDiagnosticsDirectory(options.root);
|
|
169
|
-
this.logPath = runtimeDiagnosticsPath(options.root, this.runtimeId);
|
|
170
|
-
this.ready = mkdir(this.directory, { recursive: true, mode: 0o700 }).then(() => undefined);
|
|
171
|
-
}
|
|
172
|
-
log(level, event, data, context = {}) {
|
|
173
|
-
if (this.closed)
|
|
174
|
-
return;
|
|
175
|
-
const traceContext = normalizeDiagnosticTraceContext(context.traceContext ?? (context.requestId ? { requestId: context.requestId } : undefined));
|
|
176
|
-
const rawError = data?.error;
|
|
177
|
-
const diagnosticError = rawError instanceof Error
|
|
178
|
-
? serializeDiagnosticError(rawError)
|
|
179
|
-
: isRecord(rawError) && typeof rawError.message === "string"
|
|
180
|
-
? redactValue(rawError)
|
|
181
|
-
: typeof rawError === "string"
|
|
182
|
-
? { message: redactDiagnosticString(rawError) }
|
|
183
|
-
: undefined;
|
|
184
|
-
const eventTraceContext = traceContext ?? normalizeDiagnosticTraceContext(diagnosticError?.traceContext);
|
|
185
|
-
const eventData = data ? Object.fromEntries(Object.entries(data).filter(([key]) => key !== "error")) : undefined;
|
|
186
|
-
const value = compactEvent({
|
|
187
|
-
schemaVersion: 1,
|
|
188
|
-
sequence: this.sequence++,
|
|
189
|
-
timestamp: new Date().toISOString(),
|
|
190
|
-
elapsedMs: Date.now() - this.startedAtMs,
|
|
191
|
-
level,
|
|
192
|
-
component: context.component ?? this.component,
|
|
193
|
-
event,
|
|
194
|
-
runtimeId: this.runtimeId,
|
|
195
|
-
...(context.connectionId ? { connectionId: context.connectionId } : {}),
|
|
196
|
-
spaceId: context.spaceId ?? this.spaceId,
|
|
197
|
-
...(context.sessionId ? { sessionId: context.sessionId } : {}),
|
|
198
|
-
...(context.turnId ? { turnId: context.turnId } : {}),
|
|
199
|
-
...(context.harness ? { harness: context.harness } : {}),
|
|
200
|
-
...(eventTraceContext ? { traceContext: eventTraceContext } : {}),
|
|
201
|
-
...(eventData && Object.keys(eventData).length > 0 ? { data: eventData } : {}),
|
|
202
|
-
...(diagnosticError ? { error: diagnosticError } : {}),
|
|
203
|
-
});
|
|
204
|
-
this.enqueueWrite(value);
|
|
205
|
-
this.onEvent?.(value);
|
|
206
|
-
}
|
|
207
|
-
async close() {
|
|
208
|
-
this.closed = true;
|
|
209
|
-
if (this.writeTimer)
|
|
210
|
-
clearTimeout(this.writeTimer);
|
|
211
|
-
this.writeTimer = null;
|
|
212
|
-
await this.flushLogBuffer();
|
|
213
|
-
await this.writeChain;
|
|
214
|
-
if (this.logFile) {
|
|
215
|
-
const file = this.logFile;
|
|
216
|
-
this.logFile = null;
|
|
217
|
-
await file.sync().catch(() => undefined);
|
|
218
|
-
await file.close().catch(() => undefined);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
enqueueWrite(event) {
|
|
222
|
-
let nextEvent = event;
|
|
223
|
-
if (this.droppedWriteEvents > 0) {
|
|
224
|
-
nextEvent = { ...event, data: { ...(event.data ?? {}), droppedDiagnosticsBeforeWrite: this.droppedWriteEvents } };
|
|
225
|
-
this.droppedWriteEvents = 0;
|
|
226
|
-
}
|
|
227
|
-
const line = `${JSON.stringify(nextEvent)}\n`;
|
|
228
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
229
|
-
while (this.writeBufferBytes + bytes > MAX_PENDING_LOG_BYTES && this.writeBuffer.length > 0) {
|
|
230
|
-
const index = this.writeBuffer.findIndex(({ event: queued }) => queued.level === "debug" || queued.level === "info");
|
|
231
|
-
const removed = this.writeBuffer.splice(index >= 0 ? index : 0, 1)[0];
|
|
232
|
-
if (removed) {
|
|
233
|
-
this.writeBufferBytes -= removed.bytes;
|
|
234
|
-
this.droppedWriteEvents += 1;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (this.writeBufferBytes + bytes > MAX_PENDING_LOG_BYTES && nextEvent.level !== "error") {
|
|
238
|
-
this.droppedWriteEvents += 1;
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
this.writeBuffer.push({ event: nextEvent, line, bytes });
|
|
242
|
-
this.writeBufferBytes += bytes;
|
|
243
|
-
if (nextEvent.level === "error" || this.writeBufferBytes >= 64 * 1024)
|
|
244
|
-
void this.flushLogBuffer();
|
|
245
|
-
else
|
|
246
|
-
this.scheduleLogFlush();
|
|
247
|
-
}
|
|
248
|
-
scheduleLogFlush() {
|
|
249
|
-
if (this.writeTimer || this.closed)
|
|
250
|
-
return;
|
|
251
|
-
this.writeTimer = setTimeout(() => {
|
|
252
|
-
this.writeTimer = null;
|
|
253
|
-
void this.flushLogBuffer();
|
|
254
|
-
}, this.logFlushIntervalMs);
|
|
255
|
-
}
|
|
256
|
-
async flushLogBuffer() {
|
|
257
|
-
if (this.writeBuffer.length === 0)
|
|
258
|
-
return this.writeChain;
|
|
259
|
-
const entries = this.writeBuffer;
|
|
260
|
-
this.writeBuffer = [];
|
|
261
|
-
this.writeBufferBytes = 0;
|
|
262
|
-
this.writeChain = this.writeChain.then(() => this.writeEntries(entries)).catch(() => {
|
|
263
|
-
// Local diagnostics must never take down the Runtime.
|
|
264
|
-
});
|
|
265
|
-
return this.writeChain;
|
|
266
|
-
}
|
|
267
|
-
async writeEntries(entries) {
|
|
268
|
-
await this.ready;
|
|
269
|
-
for (const entry of entries) {
|
|
270
|
-
await this.ensureLogFile();
|
|
271
|
-
const shouldRotate = this.logFileSize > 0 && (this.logFileSize + entry.bytes > this.maxLogFileBytes ||
|
|
272
|
-
Date.now() - this.logFileStartedAt >= DEFAULT_MAX_LOG_FILE_AGE_MS);
|
|
273
|
-
if (shouldRotate) {
|
|
274
|
-
await this.rotateLog(entry.event.sequence);
|
|
275
|
-
await this.ensureLogFile();
|
|
276
|
-
}
|
|
277
|
-
await this.logFile?.write(entry.line);
|
|
278
|
-
this.logFileSize += entry.bytes;
|
|
279
|
-
}
|
|
280
|
-
await this.logFile?.sync();
|
|
281
|
-
}
|
|
282
|
-
async ensureLogFile() {
|
|
283
|
-
if (this.logFile)
|
|
284
|
-
return;
|
|
285
|
-
this.logFile = await open(this.logPath, "a", 0o600);
|
|
286
|
-
await this.logFile.chmod(0o600).catch(() => undefined);
|
|
287
|
-
this.logFileSize = (await stat(this.logPath)).size;
|
|
288
|
-
this.logFileStartedAt = Date.now();
|
|
289
|
-
}
|
|
290
|
-
async rotateLog(nextSequence) {
|
|
291
|
-
const file = this.logFile;
|
|
292
|
-
this.logFile = null;
|
|
293
|
-
if (file) {
|
|
294
|
-
await file.sync();
|
|
295
|
-
await file.close();
|
|
296
|
-
}
|
|
297
|
-
await rename(this.logPath, join(this.directory, `${this.runtimeId}-${nextSequence}-${Date.now()}.jsonl`));
|
|
298
|
-
this.logFileSize = 0;
|
|
299
|
-
this.logFileStartedAt = 0;
|
|
300
|
-
await this.enforceLogCapacity();
|
|
301
|
-
}
|
|
302
|
-
async enforceLogCapacity() {
|
|
303
|
-
const names = await readdir(this.directory).catch((error) => {
|
|
304
|
-
if (error.code === "ENOENT")
|
|
305
|
-
return [];
|
|
306
|
-
throw error;
|
|
307
|
-
});
|
|
308
|
-
const files = await Promise.all(names.filter((name) => name.endsWith(".jsonl") && name !== `${this.runtimeId}.jsonl`).map(async (name) => {
|
|
309
|
-
const path = join(this.directory, name);
|
|
310
|
-
const info = await stat(path).catch(() => null);
|
|
311
|
-
return info ? { path, size: info.size, mtimeMs: info.mtimeMs } : null;
|
|
312
|
-
}));
|
|
313
|
-
let total = this.logFileSize + files.reduce((sum, file) => sum + (file?.size ?? 0), 0);
|
|
314
|
-
for (const file of files.filter((value) => value !== null).sort((left, right) => left.mtimeMs - right.mtimeMs)) {
|
|
315
|
-
if (total <= this.maxTotalLogBytes)
|
|
316
|
-
break;
|
|
317
|
-
await rm(file.path, { force: true });
|
|
318
|
-
total -= file.size;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
export class RuntimeDiagnosticReader {
|
|
323
|
-
root;
|
|
324
|
-
files = new Map();
|
|
325
|
-
lastSequenceByRuntime = new Map();
|
|
326
|
-
initialized = false;
|
|
327
|
-
constructor(root) {
|
|
328
|
-
this.root = root;
|
|
329
|
-
}
|
|
330
|
-
async read(options = {}) {
|
|
331
|
-
const directory = runtimeDiagnosticsDirectory(this.root);
|
|
332
|
-
const names = await readdir(directory).catch((error) => {
|
|
333
|
-
if (error.code === "ENOENT")
|
|
334
|
-
return [];
|
|
335
|
-
throw error;
|
|
336
|
-
});
|
|
337
|
-
const fileEntries = await Promise.all(names.filter((value) => value.endsWith(".jsonl")).map(async (name) => {
|
|
338
|
-
const path = join(directory, name);
|
|
339
|
-
const info = await stat(path).catch(() => null);
|
|
340
|
-
return info ? { path, size: info.size, mtimeMs: info.mtimeMs } : null;
|
|
341
|
-
}));
|
|
342
|
-
const events = [];
|
|
343
|
-
for (const file of fileEntries.filter((value) => value !== null).sort((left, right) => left.mtimeMs - right.mtimeMs)) {
|
|
344
|
-
const state = this.files.get(file.path) ?? { offset: 0, partial: "", decoder: new StringDecoder("utf8") };
|
|
345
|
-
if (file.size < state.offset) {
|
|
346
|
-
state.offset = 0;
|
|
347
|
-
state.partial = "";
|
|
348
|
-
state.decoder = new StringDecoder("utf8");
|
|
349
|
-
}
|
|
350
|
-
const stream = createReadStream(file.path, { start: state.offset });
|
|
351
|
-
let bytesRead = 0;
|
|
352
|
-
let text = state.partial;
|
|
353
|
-
for await (const chunk of stream) {
|
|
354
|
-
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
355
|
-
bytesRead += buffer.length;
|
|
356
|
-
text += state.decoder.write(buffer);
|
|
357
|
-
}
|
|
358
|
-
state.offset += bytesRead;
|
|
359
|
-
const lines = text.split("\n");
|
|
360
|
-
state.partial = lines.pop() ?? "";
|
|
361
|
-
this.files.set(file.path, state);
|
|
362
|
-
for (const line of lines) {
|
|
363
|
-
if (!line.trim())
|
|
364
|
-
continue;
|
|
365
|
-
try {
|
|
366
|
-
const value = JSON.parse(line);
|
|
367
|
-
if (isRecord(value) && value.schemaVersion === 1 && typeof value.sequence === "number")
|
|
368
|
-
events.push(value);
|
|
369
|
-
}
|
|
370
|
-
catch {
|
|
371
|
-
// Ignore only the damaged line; source files remain untouched.
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
events.sort(compareDiagnosticEvents);
|
|
376
|
-
const fresh = events.filter((event) => event.sequence > (this.lastSequenceByRuntime.get(event.runtimeId) ?? -1));
|
|
377
|
-
for (const event of fresh)
|
|
378
|
-
this.lastSequenceByRuntime.set(event.runtimeId, event.sequence);
|
|
379
|
-
if (!this.initialized) {
|
|
380
|
-
this.initialized = true;
|
|
381
|
-
const limit = options.limit ?? 100;
|
|
382
|
-
return limit > 0 ? fresh.slice(-limit) : fresh;
|
|
383
|
-
}
|
|
384
|
-
return fresh;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
export async function readRuntimeDiagnosticEvents(root, options = {}) {
|
|
388
|
-
return new RuntimeDiagnosticReader(root).read(options);
|
|
389
|
-
}
|
|
390
|
-
export function isValidRuntimeTraceparent(value) {
|
|
391
|
-
return typeof value === "string" && TRACEPARENT.test(value);
|
|
392
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type CanonicalProjectionMessage, type ContentBlock, type LocalHarness, type NativeProjection, type ProjectionInput, type ProjectionRecord } from "@neta-art/cohub";
|
|
2
|
-
type ToolResult = Extract<ContentBlock, {
|
|
3
|
-
type: "tool_result";
|
|
4
|
-
}>;
|
|
5
|
-
/** Deterministic, UUID-shaped record ids keep re-projection stable without local state. */
|
|
6
|
-
export declare function projectionUuid(key: string): string;
|
|
7
|
-
/** Provider APIs restrict tool ids; hashing keeps call/result pairs linked. */
|
|
8
|
-
export declare function projectionToolId(id: string): string;
|
|
9
|
-
export type ProjectedSegment = {
|
|
10
|
-
role: "user" | "assistant";
|
|
11
|
-
blocks: ContentBlock[];
|
|
12
|
-
message: CanonicalProjectionMessage;
|
|
13
|
-
compactSummary: boolean;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Shared walk for transcript formats whose records form a parent-linked chain. `write` maps one
|
|
17
|
-
* user/assistant segment to native records; ids and parent links are assigned here.
|
|
18
|
-
*/
|
|
19
|
-
export declare function projectChainedSession(input: ProjectionInput, target: LocalHarness, fields: {
|
|
20
|
-
id: string;
|
|
21
|
-
parent: string;
|
|
22
|
-
}, write: (segment: ProjectedSegment) => Record<string, unknown>[]): NativeProjection;
|
|
23
|
-
export declare const projectionMeta: (input: ProjectionInput, message: CanonicalProjectionMessage) => {
|
|
24
|
-
messageId: string;
|
|
25
|
-
turnId: string;
|
|
26
|
-
schema: string;
|
|
27
|
-
spaceId: string;
|
|
28
|
-
sessionId: string;
|
|
29
|
-
};
|
|
30
|
-
export declare const toolResultText: (block: ToolResult) => string;
|
|
31
|
-
/** Session id is stored on every record of these formats. */
|
|
32
|
-
export declare const rebindSessionId: (records: ProjectionRecord[], nativeSessionId: string) => {
|
|
33
|
-
key: string;
|
|
34
|
-
sourceTurnId: string | null;
|
|
35
|
-
sourceMessageId: string | null;
|
|
36
|
-
record: {
|
|
37
|
-
sessionId: string;
|
|
38
|
-
};
|
|
39
|
-
}[];
|
|
40
|
-
export {};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { fingerprintProjectionTurns, isProjectionCompaction, isProjectionPendingGeneration, projectNativeMessageMeta, trimProjectionTurnsToCompaction, } from "@neta-art/cohub";
|
|
3
|
-
/** Deterministic, UUID-shaped record ids keep re-projection stable without local state. */
|
|
4
|
-
export function projectionUuid(key) {
|
|
5
|
-
const hex = createHash("sha256").update(key).digest("hex");
|
|
6
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${((Number.parseInt(hex[16] ?? "0", 16) & 3) | 8).toString(16)}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
7
|
-
}
|
|
8
|
-
/** Provider APIs restrict tool ids; hashing keeps call/result pairs linked. */
|
|
9
|
-
export function projectionToolId(id) {
|
|
10
|
-
return /^[A-Za-z0-9_-]{1,64}$/.test(id) ? id : `call_${createHash("sha256").update(id).digest("hex").slice(0, 32)}`;
|
|
11
|
-
}
|
|
12
|
-
const nonEmpty = (block) => block.type !== "text" || block.text.length > 0;
|
|
13
|
-
/**
|
|
14
|
-
* Splits Cohub messages into alternating native records. A tool call is kept only with its result,
|
|
15
|
-
* because provider APIs reject unpaired calls; dropped content is reported as a projection warning.
|
|
16
|
-
*/
|
|
17
|
-
function segments(message, warnings) {
|
|
18
|
-
const warn = (reason) => warnings.push({ sourceMessageId: message.id, sourceTurnId: message.turnId, reason });
|
|
19
|
-
if (message.content.some((block) => block.type === "image" && block.source.type === "url"))
|
|
20
|
-
warn("external image URL omitted from native projection");
|
|
21
|
-
const visible = message.content.filter((block) => nonEmpty(block) && !(block.type === "image" && block.source.type === "url"));
|
|
22
|
-
if (message.role === "user") {
|
|
23
|
-
const blocks = visible.filter((block) => block.type === "text" || block.type === "image");
|
|
24
|
-
return blocks.length ? [{ role: "user", blocks }] : [];
|
|
25
|
-
}
|
|
26
|
-
const raw = [];
|
|
27
|
-
for (const block of visible) {
|
|
28
|
-
const role = block.type === "tool_result" ? "user" : "assistant";
|
|
29
|
-
if (role === "assistant" && !["text", "tool_use"].includes(block.type))
|
|
30
|
-
continue;
|
|
31
|
-
const last = raw.at(-1);
|
|
32
|
-
if (last?.role === role)
|
|
33
|
-
last.blocks.push(block);
|
|
34
|
-
else
|
|
35
|
-
raw.push({ role, blocks: [block] });
|
|
36
|
-
}
|
|
37
|
-
const paired = [];
|
|
38
|
-
raw.forEach((segment, index) => {
|
|
39
|
-
if (segment.role === "assistant") {
|
|
40
|
-
const results = new Set(raw[index + 1]?.role === "user" ? raw[index + 1]?.blocks.flatMap((block) => block.type === "tool_result" ? [block.tool_use_id] : []) : []);
|
|
41
|
-
const blocks = segment.blocks.filter((block) => block.type !== "tool_use" || results.has(block.id));
|
|
42
|
-
if (blocks.length !== segment.blocks.length)
|
|
43
|
-
warn("tool call without a result omitted from native projection");
|
|
44
|
-
if (blocks.length)
|
|
45
|
-
paired.push({ role: "assistant", blocks });
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const calls = new Set(raw[index - 1]?.role === "assistant" ? raw[index - 1]?.blocks.flatMap((block) => block.type === "tool_use" ? [block.id] : []) : []);
|
|
49
|
-
const blocks = segment.blocks.filter((block) => block.type === "tool_result" && calls.has(block.tool_use_id));
|
|
50
|
-
if (blocks.length !== segment.blocks.length)
|
|
51
|
-
warn("tool result without a call omitted from native projection");
|
|
52
|
-
if (blocks.length)
|
|
53
|
-
paired.push({ role: "user", blocks });
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return paired;
|
|
57
|
-
}
|
|
58
|
-
const compactionText = (message) => message.content.flatMap((block) => block.type === "system_note" ? [block.text] : []).join("\n");
|
|
59
|
-
/**
|
|
60
|
-
* Shared walk for transcript formats whose records form a parent-linked chain. `write` maps one
|
|
61
|
-
* user/assistant segment to native records; ids and parent links are assigned here.
|
|
62
|
-
*/
|
|
63
|
-
export function projectChainedSession(input, target, fields, write) {
|
|
64
|
-
const warnings = [];
|
|
65
|
-
const records = [];
|
|
66
|
-
let parentId = null;
|
|
67
|
-
for (const turn of trimProjectionTurnsToCompaction(input.turns)) {
|
|
68
|
-
for (const message of turn.messages) {
|
|
69
|
-
if (isProjectionPendingGeneration(message))
|
|
70
|
-
continue;
|
|
71
|
-
const parts = isProjectionCompaction(message)
|
|
72
|
-
? compactionText(message) ? [{ role: "user", blocks: [{ type: "text", text: compactionText(message) }], compactSummary: true }] : []
|
|
73
|
-
: message.role === "system" ? [] : segments(message, warnings).map((segment) => ({ ...segment, compactSummary: false }));
|
|
74
|
-
let ordinal = 0;
|
|
75
|
-
for (const part of parts) {
|
|
76
|
-
for (const native of write({ ...part, message })) {
|
|
77
|
-
const key = `${message.id}:${message.turnId}:${ordinal++}`;
|
|
78
|
-
const id = projectionUuid(`${input.sessionId}:${key}`);
|
|
79
|
-
records.push({ key, sourceTurnId: message.turnId, sourceMessageId: message.id, record: { [fields.parent]: parentId, [fields.id]: id, ...native } });
|
|
80
|
-
parentId = id;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const last = input.turns.at(-1);
|
|
86
|
-
return { target, records, cursor: { sourceSequence: last?.sequence ?? null, sourceTurnId: last?.sourceTurnId ?? null, sourceFingerprint: fingerprintProjectionTurns(input.turns) }, warnings };
|
|
87
|
-
}
|
|
88
|
-
export const projectionMeta = (input, message) => ({
|
|
89
|
-
schema: "cohub.projection.v2", spaceId: input.spaceId, sessionId: input.sessionId, ...projectNativeMessageMeta(message),
|
|
90
|
-
});
|
|
91
|
-
export const toolResultText = (block) => typeof block.content === "string"
|
|
92
|
-
? block.content
|
|
93
|
-
: block.content.flatMap((item) => item.type === "text" ? [item.text] : []).join("\n");
|
|
94
|
-
/** Session id is stored on every record of these formats. */
|
|
95
|
-
export const rebindSessionId = (records, nativeSessionId) => records.map((entry) => ({ ...entry, record: { ...entry.record, sessionId: nativeSessionId } }));
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ContentBlock, LocalHarness } from "@neta-art/cohub";
|
|
2
|
-
import type { JsonRecord } from "../json-rpc.js";
|
|
3
|
-
import { type NativeTranscriptTurn, type TranscriptLine } from "../native/transcript.js";
|
|
4
|
-
import type { SessionHeader } from "./types.js";
|
|
5
|
-
/**
|
|
6
|
-
* `<data root>/projects/<project>/<session id>.jsonl`; sub-agent files live in deeper directories. A
|
|
7
|
-
* subdirectory's project name extends its parent's, so a prefix admits them; the header decides ownership.
|
|
8
|
-
*/
|
|
9
|
-
export declare function projectTranscript(path: string, root: string, project: string): boolean;
|
|
10
|
-
export declare function projectDirectory(path: string, root: string, project: string): boolean;
|
|
11
|
-
/** The session id is the file name; the first record carrying a `cwd` names the project. */
|
|
12
|
-
export declare function chainedSessionHeader(path: string, harness: LocalHarness, signal?: AbortSignal): Promise<SessionHeader | null>;
|
|
13
|
-
export declare function readChainedLines(path: string, signal?: AbortSignal): Promise<{
|
|
14
|
-
lines: TranscriptLine[];
|
|
15
|
-
prefixes: Map<number, string>;
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* The branch ending at the file's last linked record, oldest first. These formats only append, so a
|
|
19
|
-
* parent is the latest earlier record with that id: a rewound or repeated id never forms a cycle.
|
|
20
|
-
*/
|
|
21
|
-
export declare function chainBranch(lines: TranscriptLine[], id: (value: JsonRecord) => string, parent: (value: JsonRecord) => string): TranscriptLine[];
|
|
22
|
-
export declare function startTurn(line: TranscriptLine, key: string, parentKey: string | null, userContent: ContentBlock[], cloudTurnId: string): NativeTranscriptTurn;
|
|
23
|
-
/** Every branch record extends the Turn's bytes; only conversation records extend its content. */
|
|
24
|
-
export declare function extendTurn(turn: NativeTranscriptTurn, line: TranscriptLine, content: boolean): void;
|