@hearsay-tools/squawk 0.19.0-dev.9292 → 0.19.0-dev.9303

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.
Files changed (79) hide show
  1. package/dist/ci-wait/controller.d.ts +7 -7
  2. package/dist/delegation/transport.d.ts +78 -78
  3. package/dist/features/automations/tools.d.ts +8 -8
  4. package/dist/features/reports/routes.d.ts +2 -2
  5. package/dist/server/activity-routes.d.ts +23 -23
  6. package/dist/server/live-routes.d.ts +6 -6
  7. package/dist/server/live-trace.d.ts +30 -0
  8. package/dist/server/live-trace.js +114 -0
  9. package/dist/server/live-trace.js.map +1 -0
  10. package/dist/server/projects-routes.d.ts +41 -41
  11. package/dist/server/repo-routes.d.ts +39 -39
  12. package/dist/server/runs-routes.d.ts +1008 -1008
  13. package/dist/server/server.d.ts +1430 -1430
  14. package/dist/server/start-server.js +2 -1
  15. package/dist/server/start-server.js.map +1 -1
  16. package/dist/server/ws.d.ts +3 -0
  17. package/dist/server/ws.js +22 -3
  18. package/dist/server/ws.js.map +1 -1
  19. package/package.json +4 -4
  20. package/web/dist/assets/{accounts-section-BHP8K_nY.js → accounts-section-D0fD5_oC.js} +1 -1
  21. package/web/dist/assets/{activity-motion-DEEIuaki.js → activity-motion-Bvti-WsN.js} +1 -1
  22. package/web/dist/assets/{activity-route-vtZmQsDB.js → activity-route-DpCed1FK.js} +1 -1
  23. package/web/dist/assets/{agent-config-section-CbnVaIx7.js → agent-config-section-Dg3CHyQg.js} +1 -1
  24. package/web/dist/assets/{agent-defaults-section-Blxd9IpY.js → agent-defaults-section-DUnbC2jD.js} +1 -1
  25. package/web/dist/assets/{appearance-B_y9StVj.js → appearance-BIkspcin.js} +1 -1
  26. package/web/dist/assets/{archive-on-merge-field-DlChylWt.js → archive-on-merge-field-ums1XG7J.js} +1 -1
  27. package/web/dist/assets/{ask-card-DzWKRJ1x.js → ask-card-BzL2ast4.js} +1 -1
  28. package/web/dist/assets/{automations-route-DxE9u9p0.js → automations-route-DoQyJjq7.js} +1 -1
  29. package/web/dist/assets/{commit-list-SxBDO_q5.js → commit-list-_gC1WeK7.js} +1 -1
  30. package/web/dist/assets/{diff-B6Ye5Xg9.js → diff-C2uXVNqT.js} +2 -2
  31. package/web/dist/assets/{diff-controls-BFQOIJ97.js → diff-controls-Cdyu5VmQ.js} +1 -1
  32. package/web/dist/assets/{diff-view-BkF3xtYW.js → diff-view-CO-DUaDR.js} +1 -1
  33. package/web/dist/assets/{discard-changes-dialog-CaS0koto.js → discard-changes-dialog-DMdSF5NI.js} +1 -1
  34. package/web/dist/assets/{file-preview-ByWn2eDz.js → file-preview-B_hRLwNb.js} +1 -1
  35. package/web/dist/assets/{git-toolbar-COI-N232.js → git-toolbar-CPJHgx_i.js} +1 -1
  36. package/web/dist/assets/{github-CAQJIg-J.js → github-jWNYNhlm.js} +1 -1
  37. package/web/dist/assets/{global-activity-route-99-UqSlC.js → global-activity-route-DEQNisSg.js} +1 -1
  38. package/web/dist/assets/{index-BAXboPqe.js → index-DFbBULI2.js} +4 -4
  39. package/web/dist/assets/{index-B5vWsR62.css → index-DK3IHEql.css} +1 -1
  40. package/web/dist/assets/{markdown-D7p7x8Pe.js → markdown-zOvCJUWD.js} +1 -1
  41. package/web/dist/assets/{option-select-BvsSDWBz.js → option-select-DxfdyXNu.js} +1 -1
  42. package/web/dist/assets/{preferences-section-DkdcKxmS.js → preferences-section-C716_p4g.js} +1 -1
  43. package/web/dist/assets/{preview-pane-connected-B3f0fR6q.js → preview-pane-connected-DLWk_Eig.js} +1 -1
  44. package/web/dist/assets/{project-location-CvZY7aOx.js → project-location-BiihGhiY.js} +1 -1
  45. package/web/dist/assets/{projects-section-DGzDfKN_.js → projects-section-BTk3C5Li.js} +1 -1
  46. package/web/dist/assets/{prompt-templates-section-DbHe-j9Z.js → prompt-templates-section-DcySeJWP.js} +1 -1
  47. package/web/dist/assets/{remote-settings-notice-ByPYNQyB.js → remote-settings-notice-B4FNidkI.js} +1 -1
  48. package/web/dist/assets/{repo-git-4rKalM-L.js → repo-git-CDt8HAv5.js} +1 -1
  49. package/web/dist/assets/{report-reader-IAYhP0KQ.js → report-reader-CBurj3TL.js} +1 -1
  50. package/web/dist/assets/{reports-BP_hajNp.js → reports-Bk1C9SrI.js} +1 -1
  51. package/web/dist/assets/{resources-section-QNbLbu3j.js → resources-section-C5xzoOVU.js} +1 -1
  52. package/web/dist/assets/{review-notes-drafts-CB8u-M0E.js → review-notes-drafts-D-0B4Hfk.js} +1 -1
  53. package/web/dist/assets/{review-panel-Bw8yG2xg.js → review-panel-DxpdPY11.js} +1 -1
  54. package/web/dist/assets/{review-strip-BojRnCkg.js → review-strip-B8iISCGG.js} +1 -1
  55. package/web/dist/assets/{run-diff-CMZgQG9B.js → run-diff-BdPIyvG8.js} +1 -1
  56. package/web/dist/assets/{run-header-D7LZBbaL.js → run-header-UuSi3Rs3.js} +1 -1
  57. package/web/dist/assets/{select-D9BIA_Kn.js → select-B-01knTg.js} +1 -1
  58. package/web/dist/assets/{session-context-section-CxFRidmv.js → session-context-section-Lnl20eGo.js} +1 -1
  59. package/web/dist/assets/{settings-agent-picker-Cy_ZpuNd.js → settings-agent-picker-BMlPxA7u.js} +1 -1
  60. package/web/dist/assets/{settings-save-bar-DzbndGGQ.js → settings-save-bar-C874vU-b.js} +1 -1
  61. package/web/dist/assets/{settings-shell-DS8k_xP6.js → settings-shell-BRURc5-1.js} +1 -1
  62. package/web/dist/assets/{sidebar-section-CY978tNF.js → sidebar-section-DTyi7yiX.js} +1 -1
  63. package/web/dist/assets/{skills-WZ5YRCbF.js → skills-CYWEus3G.js} +1 -1
  64. package/web/dist/assets/{task-changes-Dd2KHRQ6.js → task-changes-T9Ov77_d.js} +1 -1
  65. package/web/dist/assets/{task-commits-De0FVgKP.js → task-commits-Du0Ej96B.js} +1 -1
  66. package/web/dist/assets/{task-file-scope-C_cr_ix-.js → task-file-scope-Cf1g6fmN.js} +1 -1
  67. package/web/dist/assets/{task-files-resMdu9u.js → task-files-DNjY1qDW.js} +1 -1
  68. package/web/dist/assets/{task-github-item-Hz1RbO88.js → task-github-item-CV5xCa1c.js} +1 -1
  69. package/web/dist/assets/{task-thread-D7vUf0g7.js → task-thread-CW7L2byD.js} +1 -1
  70. package/web/dist/assets/{thread-state-Bjh3rImx.js → thread-state-DtyCRKlh.js} +1 -1
  71. package/web/dist/assets/{unified-diff-weWjKedZ.js → unified-diff-BYQqKg7r.js} +1 -1
  72. package/web/dist/assets/{use-finish-run-BuyJkeEN.js → use-finish-run-ChTdSBCK.js} +1 -1
  73. package/web/dist/assets/{use-hand-to-agent-state-CSDPzpM7.js → use-hand-to-agent-state-Cp55yL0Z.js} +1 -1
  74. package/web/dist/assets/use-path-bases-Bfn7xDeC.js +1 -0
  75. package/web/dist/assets/{workflows-DtnnAq4w.js → workflows-Cgm-NY9Q.js} +1 -1
  76. package/web/dist/assets/{workspace-tools-CSLTEwLa.js → workspace-tools-Cm4efDvO.js} +1 -1
  77. package/web/dist/assets/{worktrees-section-Crp31i8F.js → worktrees-section-Bt9waGZ3.js} +1 -1
  78. package/web/dist/index.html +2 -2
  79. package/web/dist/assets/use-path-bases-DgEkRWYi.js +0 -1
@@ -121,9 +121,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
121
121
  } & {
122
122
  "/api/v1/tools/:name": {
123
123
  $post: {
124
- output: never;
124
+ output: {
125
+ code: string;
126
+ message: string;
127
+ };
125
128
  outputFormat: "json";
126
- status: import("hono/utils/http-status").ContentfulStatusCode;
129
+ status: 401;
127
130
  input: {
128
131
  json: unknown;
129
132
  } & {
@@ -146,12 +149,9 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
146
149
  };
147
150
  };
148
151
  } | {
149
- output: {
150
- code: string;
151
- message: string;
152
- };
152
+ output: never;
153
153
  outputFormat: "json";
154
- status: 401;
154
+ status: import("hono/utils/http-status").ContentfulStatusCode;
155
155
  input: {
156
156
  json: unknown;
157
157
  } & {
@@ -2,18 +2,6 @@ import type { DelegationRoutes } from './routes.ts';
2
2
  export declare function createDelegationApp(routes: DelegationRoutes): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, import("hono/types").BlankSchema | import("hono/types").MergeSchemaPath<{
3
3
  "/list": {
4
4
  $get: {
5
- output: {
6
- error: string;
7
- code?: "invalid_input" | undefined;
8
- };
9
- outputFormat: "json";
10
- status: 400;
11
- input: {
12
- query: {
13
- offset?: string | undefined;
14
- };
15
- };
16
- } | {
17
5
  output: {
18
6
  workers: {
19
7
  workerId: string;
@@ -66,6 +54,18 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
66
54
  offset?: string | undefined;
67
55
  };
68
56
  };
57
+ } | {
58
+ output: {
59
+ error: string;
60
+ code?: "invalid_input" | undefined;
61
+ };
62
+ outputFormat: "json";
63
+ status: 400;
64
+ input: {
65
+ query: {
66
+ offset?: string | undefined;
67
+ };
68
+ };
69
69
  };
70
70
  };
71
71
  } & {
@@ -652,18 +652,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
652
652
  } & {
653
653
  "/:workerId": {
654
654
  $get: {
655
- output: {
656
- error: string;
657
- code?: "invalid_input" | undefined;
658
- };
659
- outputFormat: "json";
660
- status: 400;
661
- input: {
662
- param: {
663
- workerId: string;
664
- };
665
- };
666
- } | {
667
655
  output: {
668
656
  workerId: string;
669
657
  settled: boolean;
@@ -788,11 +776,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
788
776
  workerId: string;
789
777
  };
790
778
  };
791
- };
792
- };
793
- } & {
794
- "/:workerId/collect": {
795
- $post: {
779
+ } | {
796
780
  output: {
797
781
  error: string;
798
782
  code?: "invalid_input" | undefined;
@@ -803,10 +787,12 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
803
787
  param: {
804
788
  workerId: string;
805
789
  };
806
- } & {
807
- json: Record<string, never>;
808
790
  };
809
- } | {
791
+ };
792
+ };
793
+ } & {
794
+ "/:workerId/collect": {
795
+ $post: {
810
796
  output: {
811
797
  workerId: string;
812
798
  parentRunId: string;
@@ -931,11 +917,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
931
917
  } & {
932
918
  json: Record<string, never>;
933
919
  };
934
- };
935
- };
936
- } & {
937
- "/:workerId/steer": {
938
- $post: {
920
+ } | {
939
921
  output: {
940
922
  error: string;
941
923
  code?: "invalid_input" | undefined;
@@ -947,11 +929,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
947
929
  workerId: string;
948
930
  };
949
931
  } & {
950
- json: {
951
- text: string;
952
- };
932
+ json: Record<string, never>;
953
933
  };
954
- } | {
934
+ };
935
+ };
936
+ } & {
937
+ "/:workerId/steer": {
938
+ $post: {
955
939
  output: {
956
940
  workerId: string;
957
941
  state: "delivered" | "queued";
@@ -967,11 +951,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
967
951
  text: string;
968
952
  };
969
953
  };
970
- };
971
- };
972
- } & {
973
- "/:workerId/stop": {
974
- $post: {
954
+ } | {
975
955
  output: {
976
956
  error: string;
977
957
  code?: "invalid_input" | undefined;
@@ -983,9 +963,15 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
983
963
  workerId: string;
984
964
  };
985
965
  } & {
986
- json: Record<string, never>;
966
+ json: {
967
+ text: string;
968
+ };
987
969
  };
988
- } | {
970
+ };
971
+ };
972
+ } & {
973
+ "/:workerId/stop": {
974
+ $post: {
989
975
  output: {
990
976
  workerId: string;
991
977
  state: "stopping" | "terminated";
@@ -999,11 +985,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
999
985
  } & {
1000
986
  json: Record<string, never>;
1001
987
  };
1002
- };
1003
- };
1004
- } & {
1005
- "/:workerId/destroy": {
1006
- $post: {
988
+ } | {
1007
989
  output: {
1008
990
  error: string;
1009
991
  code?: "invalid_input" | undefined;
@@ -1015,11 +997,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1015
997
  workerId: string;
1016
998
  };
1017
999
  } & {
1018
- json: {
1019
- discardWork?: true | undefined;
1020
- };
1000
+ json: Record<string, never>;
1021
1001
  };
1022
- } | {
1002
+ };
1003
+ };
1004
+ } & {
1005
+ "/:workerId/destroy": {
1006
+ $post: {
1023
1007
  output: {
1024
1008
  workerId: string;
1025
1009
  state: "complete" | "incomplete";
@@ -1048,6 +1032,22 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1048
1032
  discardWork?: true | undefined;
1049
1033
  };
1050
1034
  };
1035
+ } | {
1036
+ output: {
1037
+ error: string;
1038
+ code?: "invalid_input" | undefined;
1039
+ };
1040
+ outputFormat: "json";
1041
+ status: 400;
1042
+ input: {
1043
+ param: {
1044
+ workerId: string;
1045
+ };
1046
+ } & {
1047
+ json: {
1048
+ discardWork?: true | undefined;
1049
+ };
1050
+ };
1051
1051
  } | {
1052
1052
  output: {
1053
1053
  workerId: string;
@@ -1083,11 +1083,18 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1083
1083
  "/:workerId/summary": {
1084
1084
  $post: {
1085
1085
  output: {
1086
- error: string;
1087
- code?: "invalid_input" | undefined;
1086
+ workerId: string;
1087
+ revision: number;
1088
+ source: "assistant" | "failure";
1089
+ seq: number;
1090
+ totalLines: number;
1091
+ offset: number;
1092
+ lineCount: number;
1093
+ text: string;
1094
+ nextOffset?: number | undefined;
1088
1095
  };
1089
1096
  outputFormat: "json";
1090
- status: 400;
1097
+ status: 200;
1091
1098
  input: {
1092
1099
  param: {
1093
1100
  workerId: string;
@@ -1100,18 +1107,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1100
1107
  };
1101
1108
  } | {
1102
1109
  output: {
1103
- workerId: string;
1104
- revision: number;
1105
- source: "assistant" | "failure";
1106
- seq: number;
1107
- totalLines: number;
1108
- offset: number;
1109
- lineCount: number;
1110
- text: string;
1111
- nextOffset?: number | undefined;
1110
+ error: string;
1111
+ code?: "invalid_input" | undefined;
1112
1112
  };
1113
1113
  outputFormat: "json";
1114
- status: 200;
1114
+ status: 400;
1115
1115
  input: {
1116
1116
  param: {
1117
1117
  workerId: string;
@@ -1128,11 +1128,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1128
1128
  "/:workerId/diff": {
1129
1129
  $get: {
1130
1130
  output: {
1131
- error: string;
1132
- code?: "invalid_input" | undefined;
1131
+ workerId: string;
1132
+ baselineSha: string;
1133
+ diff: string;
1134
+ truncated: boolean;
1133
1135
  };
1134
1136
  outputFormat: "json";
1135
- status: 400;
1137
+ status: 200;
1136
1138
  input: {
1137
1139
  param: {
1138
1140
  workerId: string;
@@ -1140,13 +1142,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
1140
1142
  };
1141
1143
  } | {
1142
1144
  output: {
1143
- workerId: string;
1144
- baselineSha: string;
1145
- diff: string;
1146
- truncated: boolean;
1145
+ error: string;
1146
+ code?: "invalid_input" | undefined;
1147
1147
  };
1148
1148
  outputFormat: "json";
1149
- status: 200;
1149
+ status: 400;
1150
1150
  input: {
1151
1151
  param: {
1152
1152
  workerId: string;
@@ -7,6 +7,10 @@ export declare function invokeScheduleTaskTool(input: unknown): Promise<{
7
7
  }[];
8
8
  isError: boolean;
9
9
  details: {
10
+ ok: false;
11
+ code: "automations_off" | "conflict" | "invalid_request" | "not_found" | "unavailable";
12
+ message: string;
13
+ } | {
10
14
  ok: true;
11
15
  task: {
12
16
  id: string;
@@ -19,10 +23,6 @@ export declare function invokeScheduleTaskTool(input: unknown): Promise<{
19
23
  url?: string | undefined;
20
24
  };
21
25
  note: string;
22
- } | {
23
- ok: false;
24
- code: "automations_off" | "conflict" | "invalid_request" | "not_found" | "unavailable";
25
- message: string;
26
26
  };
27
27
  }>;
28
28
  export declare function formatScheduleTaskTool(answer: Awaited<ReturnType<typeof callScheduleTask>>): {
@@ -32,6 +32,10 @@ export declare function formatScheduleTaskTool(answer: Awaited<ReturnType<typeof
32
32
  }[];
33
33
  isError: boolean;
34
34
  details: {
35
+ ok: false;
36
+ code: "automations_off" | "conflict" | "invalid_request" | "not_found" | "unavailable";
37
+ message: string;
38
+ } | {
35
39
  ok: true;
36
40
  task: {
37
41
  id: string;
@@ -44,10 +48,6 @@ export declare function formatScheduleTaskTool(answer: Awaited<ReturnType<typeof
44
48
  url?: string | undefined;
45
49
  };
46
50
  note: string;
47
- } | {
48
- ok: false;
49
- code: "automations_off" | "conflict" | "invalid_request" | "not_found" | "unavailable";
50
- message: string;
51
51
  };
52
52
  };
53
53
  export declare function invokeScheduledTasksTool(input: unknown): Promise<{
@@ -42,7 +42,7 @@ export declare function createReportsRoutes(): import("hono/hono-base").HonoBase
42
42
  error: string;
43
43
  };
44
44
  outputFormat: "json";
45
- status: 409;
45
+ status: 400;
46
46
  input: {
47
47
  query: {
48
48
  q?: string | undefined;
@@ -55,7 +55,7 @@ export declare function createReportsRoutes(): import("hono/hono-base").HonoBase
55
55
  error: string;
56
56
  };
57
57
  outputFormat: "json";
58
- status: 400;
58
+ status: 409;
59
59
  input: {
60
60
  query: {
61
61
  q?: string | undefined;
@@ -58,29 +58,6 @@ export declare function ciProgressPlugs(): {
58
58
  export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
59
59
  "/workspace/activity": {
60
60
  $get: {
61
- output: {
62
- error: string;
63
- code?: "invalid_input" | undefined;
64
- };
65
- outputFormat: "json";
66
- status: 400;
67
- input: {
68
- query: {
69
- project?: string | undefined;
70
- };
71
- };
72
- } | {
73
- output: {
74
- error: string;
75
- };
76
- outputFormat: "json";
77
- status: 404 | 409 | 503;
78
- input: {
79
- query: {
80
- project?: string | undefined;
81
- };
82
- };
83
- } | {
84
61
  output: {
85
62
  generatedAt: string;
86
63
  projects: {
@@ -331,6 +308,29 @@ export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): impo
331
308
  project?: string | undefined;
332
309
  };
333
310
  };
311
+ } | {
312
+ output: {
313
+ error: string;
314
+ code?: "invalid_input" | undefined;
315
+ };
316
+ outputFormat: "json";
317
+ status: 400;
318
+ input: {
319
+ query: {
320
+ project?: string | undefined;
321
+ };
322
+ };
323
+ } | {
324
+ output: {
325
+ error: string;
326
+ };
327
+ outputFormat: "json";
328
+ status: 404 | 409 | 503;
329
+ input: {
330
+ query: {
331
+ project?: string | undefined;
332
+ };
333
+ };
334
334
  };
335
335
  };
336
336
  }, "/", "/workspace/activity">;
@@ -17,6 +17,12 @@ export declare function createLiveRoutes({ resolveProject, serverGeneration, res
17
17
  output: {
18
18
  generation: string;
19
19
  results: ({
20
+ projectId: string;
21
+ runId: string;
22
+ type: "error" | "reset";
23
+ status: 400 | 404 | 409 | 413 | 503;
24
+ error: string;
25
+ } | {
20
26
  projectId: string;
21
27
  runId: string;
22
28
  type: "batch";
@@ -37,12 +43,6 @@ export declare function createLiveRoutes({ resolveProject, serverGeneration, res
37
43
  cursor: string;
38
44
  afterSeq: number;
39
45
  hasMore: boolean;
40
- } | {
41
- projectId: string;
42
- runId: string;
43
- type: "error" | "reset";
44
- status: 400 | 404 | 409 | 413 | 503;
45
- error: string;
46
46
  })[];
47
47
  };
48
48
  outputFormat: "json";
@@ -0,0 +1,30 @@
1
+ /** Each trace file holds at most this many bytes; then the trace switches to the other file. */
2
+ export declare const LIVE_TRACE_FILE_BYTES: number;
3
+ export type LiveTraceEvent = 'attach' | 'snapshot-start' | 'snapshot-sent' | 'snapshot-failed' | 'snapshot-discarded' | 'publish' | 'detach';
4
+ export interface LiveTraceFields {
5
+ client?: number;
6
+ data?: unknown;
7
+ /** The clients a publish reached at once, and those that held it behind a pending snapshot. */
8
+ sent?: number[];
9
+ held?: number[];
10
+ /** Publishes released right after this snapshot. */
11
+ released?: number;
12
+ }
13
+ /** The hub's opt-in record of what it did per topic, in order. */
14
+ export interface LiveTrace {
15
+ record(event: LiveTraceEvent, topic: string, fields?: LiveTraceFields): void;
16
+ close(): Promise<void>;
17
+ }
18
+ /** The two files a trace writes, in turn. A reader merges both and orders lines by `seq`. */
19
+ export declare function liveTraceFiles(path: string): [string, string];
20
+ /**
21
+ * The trace `HSQ_LIVE_TRACE` (`CEZ_LIVE_TRACE` fallback) asks for, or `undefined` when it is
22
+ * unset. The value is an absolute file path. Lines go through one buffered write stream, so a
23
+ * publish never waits for the disk. Each boot starts the files empty. When one file reaches
24
+ * `fileBytes`, the trace continues in the other file and empties it first, so the trace keeps
25
+ * the newest events in at most twice that size. It switches back to a file only after that
26
+ * file's earlier stream closed; until then it keeps writing the current file up to twice the
27
+ * limit, and then drops lines and records how many it dropped. A relative path or a write error logs one
28
+ * warning and stops the trace; the hub works the same without it.
29
+ */
30
+ export declare function createLiveTrace(env?: NodeJS.ProcessEnv, warn?: (message: string) => void, fileBytes?: number): LiveTrace | undefined;
@@ -0,0 +1,114 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createWriteStream, rmSync } from 'node:fs';
3
+ import { isAbsolute } from 'node:path';
4
+ import { productEnv } from '../core/product-env.js';
5
+ /** Each trace file holds at most this many bytes; then the trace switches to the other file. */
6
+ export const LIVE_TRACE_FILE_BYTES = 10 * 1024 * 1024;
7
+ const PREVIEW_CHARS = 200;
8
+ /** The two files a trace writes, in turn. A reader merges both and orders lines by `seq`. */
9
+ export function liveTraceFiles(path) {
10
+ return [path, `${path}.1`];
11
+ }
12
+ function digest(data) {
13
+ const text = JSON.stringify(data) ?? 'undefined';
14
+ return {
15
+ sha256: createHash('sha256').update(text).digest('hex').slice(0, 16),
16
+ bytes: Buffer.byteLength(text),
17
+ preview: text.slice(0, PREVIEW_CHARS),
18
+ };
19
+ }
20
+ /**
21
+ * The trace `HSQ_LIVE_TRACE` (`CEZ_LIVE_TRACE` fallback) asks for, or `undefined` when it is
22
+ * unset. The value is an absolute file path. Lines go through one buffered write stream, so a
23
+ * publish never waits for the disk. Each boot starts the files empty. When one file reaches
24
+ * `fileBytes`, the trace continues in the other file and empties it first, so the trace keeps
25
+ * the newest events in at most twice that size. It switches back to a file only after that
26
+ * file's earlier stream closed; until then it keeps writing the current file up to twice the
27
+ * limit, and then drops lines and records how many it dropped. A relative path or a write error logs one
28
+ * warning and stops the trace; the hub works the same without it.
29
+ */
30
+ export function createLiveTrace(env = process.env, warn = (message) => console.warn(message), fileBytes = LIVE_TRACE_FILE_BYTES) {
31
+ const path = productEnv('LIVE_TRACE', env)?.trim();
32
+ if (!path)
33
+ return undefined;
34
+ if (!isAbsolute(path)) {
35
+ warn(`squawk: HSQ_LIVE_TRACE must be an absolute file path, got "${path}"; the live-topic trace is off`);
36
+ return undefined;
37
+ }
38
+ const files = liveTraceFiles(path);
39
+ let stopped = false;
40
+ let seq = 0;
41
+ let current = 0;
42
+ let written = 0;
43
+ const streams = [undefined, undefined];
44
+ const ending = [];
45
+ const end = (stream) => { ending.push(new Promise((resolve) => { stream.end(() => resolve()); })); };
46
+ const open = (file) => {
47
+ const stream = createWriteStream(file, { flags: 'w' });
48
+ stream.on('error', (error) => {
49
+ if (stopped)
50
+ return;
51
+ stopped = true;
52
+ warn(`squawk: the live-topic trace stopped: ${error.message}`);
53
+ });
54
+ return stream;
55
+ };
56
+ // The second file belongs to an earlier boot: its `seq` numbers would mix with this boot's.
57
+ try {
58
+ rmSync(files[1], { force: true });
59
+ }
60
+ catch (error) {
61
+ warn(`squawk: the live-topic trace is off: ${error.message}`);
62
+ return undefined;
63
+ }
64
+ let stream = open(files[current]);
65
+ streams[current] = stream;
66
+ let dropped = 0;
67
+ const write = (entry) => {
68
+ const line = `${JSON.stringify(entry)}\n`;
69
+ stream.write(line);
70
+ written += Buffer.byteLength(line);
71
+ };
72
+ /** Lines dropped while a switch waited are counted in one `dropped` line, so a gap is never silent. */
73
+ const flushDropped = () => {
74
+ if (!dropped)
75
+ return;
76
+ seq += 1;
77
+ write({ seq, at: new Date().toISOString(), event: 'dropped', count: dropped });
78
+ dropped = 0;
79
+ };
80
+ return {
81
+ record(event, topic, { data, ...fields } = {}) {
82
+ if (stopped)
83
+ return;
84
+ const body = { at: new Date().toISOString(), event, topic, ...fields, ...(data === undefined ? {} : { data: digest(data) }) };
85
+ const bytes = Buffer.byteLength(`${JSON.stringify({ seq: seq + 1, ...body })}\n`);
86
+ const next = current === 0 ? 1 : 0;
87
+ if (written > 0 && written + bytes > fileBytes) {
88
+ if (streams[next]?.closed ?? true) {
89
+ end(stream);
90
+ current = next;
91
+ stream = open(files[current]);
92
+ streams[current] = stream;
93
+ written = 0;
94
+ }
95
+ else if (written + bytes > 2 * fileBytes) {
96
+ // The other file's stream has not closed yet (a burst): keep the file bounded. A dropped
97
+ // event takes no `seq`, so the count line sits right before the next written event.
98
+ dropped += 1;
99
+ return;
100
+ }
101
+ }
102
+ flushDropped();
103
+ seq += 1;
104
+ write({ seq, ...body });
105
+ },
106
+ close() {
107
+ flushDropped();
108
+ stopped = true;
109
+ end(stream);
110
+ return Promise.all(ending).then(() => undefined);
111
+ },
112
+ };
113
+ }
114
+ //# sourceMappingURL=live-trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-trace.js","sourceRoot":"","sources":["../../src/server/live-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAoB,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,gGAAgG;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,aAAa,GAAG,GAAG,CAAC;AA2B1B,6FAA6F;AAC7F,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,MAAM,CAAC,IAAa;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC;IACjD,OAAO;QACL,MAAM,EAAE,UAAU,C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