opencode-swarm 7.136.5 → 7.137.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/skills/swarm-pr-review/SKILL.md +35 -3
- package/.opencode/skills/swarm-pr-review/references/prompt-templates.md +7 -3
- package/dist/agents/agent-output-schema.d.ts +2 -2
- package/dist/background/candidate-contract.d.ts +14 -0
- package/dist/cli/{config-doctor-n3hatm9d.js → config-doctor-b9r9rt2c.js} +2 -2
- package/dist/cli/{core-jpjk2qvt.js → core-6w5sd5bc.js} +1 -1
- package/dist/cli/{curation-policy-c4g08bg1.js → curation-policy-ftx2emfw.js} +7 -6
- package/dist/cli/{curator-jc5cc980.js → curator-1sxxtbq7.js} +25 -25
- package/dist/cli/{curator-llm-factory-atfnhbn6.js → curator-llm-factory-yhqbkc5w.js} +25 -25
- package/dist/cli/{evidence-summary-service-nse06dqr.js → evidence-summary-service-85gw9p2m.js} +7 -7
- package/dist/cli/{gate-evidence-kdygjr56.js → gate-evidence-s2kytsrj.js} +4 -4
- package/dist/cli/{guardrail-explain-v6f8efve.js → guardrail-explain-qh1y8jsz.js} +26 -26
- package/dist/cli/{guardrail-log-0mrq14g9.js → guardrail-log-84zffdv3.js} +3 -3
- package/dist/cli/{hive-promoter-wyejhz8b.js → hive-promoter-hpe29xrz.js} +25 -25
- package/dist/cli/{index-eeb35dnx.js → index-1qn2gchc.js} +3 -2
- package/dist/cli/{index-45y0y3xh.js → index-1zrb3vt2.js} +7 -7
- package/dist/cli/{index-d2sf9an1.js → index-5r6kkhd7.js} +4 -4
- package/dist/cli/{index-ne28wyyc.js → index-5wjw05dy.js} +2 -2
- package/dist/cli/{index-xvcctb2t.js → index-7e60c7ay.js} +27 -27
- package/dist/cli/{index-7t3vjw5e.js → index-877ah4kx.js} +1 -1
- package/dist/cli/{index-tncy55bp.js → index-8ehyt3rx.js} +1 -1
- package/dist/cli/{index-hbzh7yyz.js → index-9vqxf9pd.js} +633 -209
- package/dist/cli/{index-6kd0ezgd.js → index-a3gpeb4f.js} +2 -2
- package/dist/cli/{index-nfm9f10v.js → index-b2s3t517.js} +5 -3
- package/dist/cli/{index-8f4346kf.js → index-bxk0a1r9.js} +2 -2
- package/dist/cli/{index-pyz1p8qv.js → index-d67810xe.js} +1 -1
- package/dist/cli/{index-akc6rp3x.js → index-d8rc8c9y.js} +2 -2
- package/dist/cli/{index-hh34tyv7.js → index-dxatvs3f.js} +1 -1
- package/dist/cli/{index-bqan4y2y.js → index-e0nvge1c.js} +2 -2
- package/dist/cli/{index-f5qs217h.js → index-em10pmph.js} +1 -1
- package/dist/cli/{index-j7ja83v5.js → index-gd47gp2q.js} +1 -1
- package/dist/cli/{index-w6j1n5az.js → index-gv00q5gc.js} +1 -1
- package/dist/cli/index-h5sbn1zr.js +1670 -0
- package/dist/cli/{index-vm05set2.js → index-k8y41t4y.js} +4 -4
- package/dist/cli/{index-tr0ctbhq.js → index-m4s91910.js} +5 -5
- package/dist/cli/{index-b3jfcptk.js → index-n3h6rmbe.js} +1 -1
- package/dist/cli/{index-xp2pfbpq.js → index-pbe51g7h.js} +1 -1
- package/dist/cli/{index-kym0cctr.js → index-qy3rgmkc.js} +1 -1
- package/dist/cli/{index-d61h3f3h.js → index-s3j9fsab.js} +2 -2
- package/dist/cli/{index-qhbr4h5n.js → index-t2mv25yf.js} +6 -6
- package/dist/cli/{index-84se71v1.js → index-t5099rx9.js} +3 -3
- package/dist/cli/{index-zzhyws9g.js → index-vft1pg34.js} +1 -1
- package/dist/cli/{index-yj61bped.js → index-zxf5w0jj.js} +3 -3
- package/dist/cli/index.js +25 -25
- package/dist/cli/{knowledge-escalator-2xe8z24p.js → knowledge-escalator-3ds615yq.js} +8 -7
- package/dist/cli/{knowledge-events-wecrshsx.js → knowledge-events-3c0g2xbm.js} +6 -5
- package/dist/cli/{knowledge-link-zr40rnwr.js → knowledge-link-t94b79qe.js} +5 -4
- package/dist/cli/{knowledge-store-9f74whxw.js → knowledge-store-pq43990j.js} +6 -5
- package/dist/cli/{knowledge-validator-4ng7x9dr.js → knowledge-validator-gepda374.js} +9 -8
- package/dist/cli/{pending-delegations-0h5b18p7.js → pending-delegations-kshh66s2.js} +3 -3
- package/dist/cli/{pr-subscriptions-jn0h047q.js → pr-subscriptions-5fpzz4f3.js} +3 -3
- package/dist/cli/{runner-deeswadt.js → runner-9rqc8y3m.js} +5 -5
- package/dist/cli/{scan-cursor-yzj9n225.js → scan-cursor-5hq37qdg.js} +7 -6
- package/dist/cli/{schema-cr1nr1w0.js → schema-mrbyt7dg.js} +1 -1
- package/dist/cli/{scope-persistence-5xc9ntdh.js → scope-persistence-sjz200dt.js} +4 -4
- package/dist/cli/{skill-generator-ybncj9et.js → skill-generator-3gt8em6v.js} +10 -9
- package/dist/cli/{telemetry-6678gya0.js → telemetry-h7h7f0ez.js} +2 -1
- package/dist/cli/{worktree-collision-ownership-wt7cc850.js → worktree-collision-ownership-xzwab4xt.js} +3 -3
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/evidence-schema.d.ts +103 -103
- package/dist/config/plan-schema.d.ts +10 -10
- package/dist/config/schema.d.ts +8 -8
- package/dist/consensus/contracts.d.ts +3 -3
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/model-dispatcher.d.ts +19 -1
- package/dist/evaluation/pr-review-recovery.d.ts +41 -0
- package/dist/evaluation/public-api.d.ts +2 -0
- package/dist/evaluation/runner.d.ts +9 -0
- package/dist/hooks/hive-promoter.d.ts +1 -1
- package/dist/hooks/pr-workflow-gate.d.ts +69 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +225 -225
- package/dist/observability/catalog.d.ts +84 -0
- package/dist/observability/envelope.d.ts +401 -0
- package/dist/observability/ids.d.ts +97 -0
- package/dist/observability/index.d.ts +58 -0
- package/dist/observability/legacy.d.ts +68 -0
- package/dist/observability/observe.d.ts +112 -0
- package/dist/observability/otel-mapping.d.ts +48 -0
- package/dist/observability/relationships.d.ts +44 -0
- package/dist/observability/sampling.d.ts +77 -0
- package/dist/summaries/schema.d.ts +2 -2
- package/dist/telemetry.d.ts +4 -1
- package/dist/tools/dispatch-lanes.d.ts +1 -0
- package/evaluation-fixtures/pr-review-recovery/baseline/SKILL.md +1823 -0
- package/evaluation-fixtures/pr-review-recovery/baseline-manifest.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/environment/score-recovery.cjs +135 -0
- package/evaluation-fixtures/pr-review-recovery/instruction.md +40 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/blind-full-wave-retry/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/contradictory/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/copied-contract/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/critical-without-harm/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/invented-harm/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/malformed/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/missing-reproduction/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/parser-only/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/passing/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/premature-systemic-claim/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/profile-b-fallback/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/underclaimed-harm/model-output.json +1 -0
- package/evaluation-fixtures/pr-review-recovery/scorer-fixtures/unsupported-severity/model-output.json +1 -0
- package/package.json +3 -2
- package/dist/cli/index-cze4bq1x.js +0 -358
|
@@ -0,0 +1,1670 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
exports_external,
|
|
4
|
+
init_zod
|
|
5
|
+
} from "./index-bpmtbmy9.js";
|
|
6
|
+
|
|
7
|
+
// src/telemetry.ts
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import { createWriteStream } from "fs";
|
|
10
|
+
import * as os from "os";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
|
|
13
|
+
// src/observability/catalog.ts
|
|
14
|
+
var CATALOG_TEST_FILE = "tests/unit/observability/catalog-contract.test.ts";
|
|
15
|
+
var ISSUE_SINK = 2047;
|
|
16
|
+
var ISSUE_LIFECYCLE_RETENTION = 2045;
|
|
17
|
+
var ISSUE_COST_RETENTION = 2043;
|
|
18
|
+
var ISSUE_PLAN_EVIDENCE_RETENTION = 2036;
|
|
19
|
+
var NO_WORKFLOW_IDS = Object.freeze([]);
|
|
20
|
+
var NO_CONSUMERS = Object.freeze([]);
|
|
21
|
+
var REQUIRE_SESSION = Object.freeze([
|
|
22
|
+
"hostSessionId"
|
|
23
|
+
]);
|
|
24
|
+
var REQUIRE_SESSION_AND_TASK = Object.freeze([
|
|
25
|
+
"hostSessionId",
|
|
26
|
+
"taskId"
|
|
27
|
+
]);
|
|
28
|
+
var REQUIRE_TASK = Object.freeze(["taskId"]);
|
|
29
|
+
var FORBID_SESSION = Object.freeze([
|
|
30
|
+
"hostSessionId"
|
|
31
|
+
]);
|
|
32
|
+
var CONSUMER_COST_ACCOUNTING = Object.freeze([
|
|
33
|
+
"src/services/cost-accounting.ts:127"
|
|
34
|
+
]);
|
|
35
|
+
var CONSUMER_GATE_STATS = Object.freeze(["src/evaluation/gate-stats.ts:99"]);
|
|
36
|
+
var CONSUMER_HEARTBEAT_LISTENER = Object.freeze(["src/telemetry.ts:153"]);
|
|
37
|
+
function defineEntry(kind, input) {
|
|
38
|
+
const entry = {
|
|
39
|
+
kind,
|
|
40
|
+
category: input.category,
|
|
41
|
+
severity: input.severity,
|
|
42
|
+
privacyClass: input.privacyClass,
|
|
43
|
+
producer: input.producer,
|
|
44
|
+
consumers: input.consumers,
|
|
45
|
+
retentionOwnerIssue: input.retentionOwnerIssue,
|
|
46
|
+
requiredWorkflowIds: input.requiredWorkflowIds ?? NO_WORKFLOW_IDS,
|
|
47
|
+
forbiddenWorkflowIds: input.forbiddenWorkflowIds ?? NO_WORKFLOW_IDS,
|
|
48
|
+
requiresParent: input.requiresParent ?? false,
|
|
49
|
+
allowsLinks: input.allowsLinks ?? true,
|
|
50
|
+
otelMapping: input.otelMapping ?? "none",
|
|
51
|
+
docAnchor: `#${kind}`,
|
|
52
|
+
testFile: CATALOG_TEST_FILE
|
|
53
|
+
};
|
|
54
|
+
if (input.futureOwnerIssue !== undefined) {
|
|
55
|
+
return Object.freeze({
|
|
56
|
+
...entry,
|
|
57
|
+
futureOwnerIssue: input.futureOwnerIssue
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze(entry);
|
|
61
|
+
}
|
|
62
|
+
var CATALOG_SOURCE = [
|
|
63
|
+
[
|
|
64
|
+
"session_started",
|
|
65
|
+
{
|
|
66
|
+
category: "lifecycle",
|
|
67
|
+
severity: "info",
|
|
68
|
+
privacyClass: "pseudonymous",
|
|
69
|
+
producer: "src/telemetry.ts:399",
|
|
70
|
+
consumers: NO_CONSUMERS,
|
|
71
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
72
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
73
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
74
|
+
otelMapping: "openinference"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"session_ended",
|
|
79
|
+
{
|
|
80
|
+
category: "lifecycle",
|
|
81
|
+
severity: "info",
|
|
82
|
+
privacyClass: "pseudonymous",
|
|
83
|
+
producer: "src/telemetry.ts:403",
|
|
84
|
+
consumers: NO_CONSUMERS,
|
|
85
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
86
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
87
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
88
|
+
otelMapping: "openinference"
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
"agent_activated",
|
|
93
|
+
{
|
|
94
|
+
category: "lifecycle",
|
|
95
|
+
severity: "info",
|
|
96
|
+
privacyClass: "pseudonymous",
|
|
97
|
+
producer: "src/telemetry.ts:407",
|
|
98
|
+
consumers: NO_CONSUMERS,
|
|
99
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
100
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
101
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
102
|
+
otelMapping: "openinference"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"task_state_changed",
|
|
107
|
+
{
|
|
108
|
+
category: "lifecycle",
|
|
109
|
+
severity: "info",
|
|
110
|
+
privacyClass: "pseudonymous",
|
|
111
|
+
producer: "src/telemetry.ts:444",
|
|
112
|
+
consumers: NO_CONSUMERS,
|
|
113
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
114
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
115
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK,
|
|
116
|
+
otelMapping: "openinference"
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"phase_changed",
|
|
121
|
+
{
|
|
122
|
+
category: "lifecycle",
|
|
123
|
+
severity: "info",
|
|
124
|
+
privacyClass: "pseudonymous",
|
|
125
|
+
producer: "src/telemetry.ts:492",
|
|
126
|
+
consumers: NO_CONSUMERS,
|
|
127
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
128
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
129
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
130
|
+
otelMapping: "openinference"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"heartbeat",
|
|
135
|
+
{
|
|
136
|
+
category: "lifecycle",
|
|
137
|
+
severity: "debug",
|
|
138
|
+
privacyClass: "pseudonymous",
|
|
139
|
+
producer: "src/telemetry.ts:642",
|
|
140
|
+
consumers: CONSUMER_HEARTBEAT_LISTENER,
|
|
141
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
142
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
143
|
+
allowsLinks: false
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
"turbo_mode_changed",
|
|
148
|
+
{
|
|
149
|
+
category: "lifecycle",
|
|
150
|
+
severity: "info",
|
|
151
|
+
privacyClass: "pseudonymous",
|
|
152
|
+
producer: "src/telemetry.ts:650",
|
|
153
|
+
consumers: NO_CONSUMERS,
|
|
154
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
155
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
156
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"environment_detected",
|
|
161
|
+
{
|
|
162
|
+
category: "lifecycle",
|
|
163
|
+
severity: "info",
|
|
164
|
+
privacyClass: "pseudonymous",
|
|
165
|
+
producer: "src/telemetry.ts:675",
|
|
166
|
+
consumers: NO_CONSUMERS,
|
|
167
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
168
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
169
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
170
|
+
allowsLinks: false
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"delegation_begin",
|
|
175
|
+
{
|
|
176
|
+
category: "delegation",
|
|
177
|
+
severity: "info",
|
|
178
|
+
privacyClass: "pseudonymous",
|
|
179
|
+
producer: "src/telemetry.ts:411",
|
|
180
|
+
consumers: NO_CONSUMERS,
|
|
181
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
182
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
183
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK,
|
|
184
|
+
otelMapping: "genai"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
"delegation_end",
|
|
189
|
+
{
|
|
190
|
+
category: "delegation",
|
|
191
|
+
severity: "info",
|
|
192
|
+
privacyClass: "pseudonymous",
|
|
193
|
+
producer: "src/telemetry.ts:421",
|
|
194
|
+
consumers: CONSUMER_COST_ACCOUNTING,
|
|
195
|
+
retentionOwnerIssue: ISSUE_COST_RETENTION,
|
|
196
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK,
|
|
197
|
+
otelMapping: "genai"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
"model_fallback",
|
|
202
|
+
{
|
|
203
|
+
category: "delegation",
|
|
204
|
+
severity: "notice",
|
|
205
|
+
privacyClass: "pseudonymous",
|
|
206
|
+
producer: "src/telemetry.ts:506",
|
|
207
|
+
consumers: NO_CONSUMERS,
|
|
208
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
209
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
210
|
+
requiredWorkflowIds: REQUIRE_SESSION,
|
|
211
|
+
otelMapping: "genai"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
[
|
|
215
|
+
"gate_passed",
|
|
216
|
+
{
|
|
217
|
+
category: "gate",
|
|
218
|
+
severity: "info",
|
|
219
|
+
privacyClass: "pseudonymous",
|
|
220
|
+
producer: "src/telemetry.ts:453",
|
|
221
|
+
consumers: NO_CONSUMERS,
|
|
222
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
223
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
224
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
[
|
|
228
|
+
"gate_failed",
|
|
229
|
+
{
|
|
230
|
+
category: "gate",
|
|
231
|
+
severity: "warning",
|
|
232
|
+
privacyClass: "pseudonymous",
|
|
233
|
+
producer: "src/telemetry.ts:470",
|
|
234
|
+
consumers: NO_CONSUMERS,
|
|
235
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
236
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
237
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
[
|
|
241
|
+
"gate_parse_error",
|
|
242
|
+
{
|
|
243
|
+
category: "gate",
|
|
244
|
+
severity: "warning",
|
|
245
|
+
privacyClass: "sensitive",
|
|
246
|
+
producer: "src/telemetry.ts:457",
|
|
247
|
+
consumers: NO_CONSUMERS,
|
|
248
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
249
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
250
|
+
requiredWorkflowIds: REQUIRE_TASK,
|
|
251
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
[
|
|
255
|
+
"reviewer_gate_decision",
|
|
256
|
+
{
|
|
257
|
+
category: "gate",
|
|
258
|
+
severity: "info",
|
|
259
|
+
privacyClass: "pseudonymous",
|
|
260
|
+
producer: "src/telemetry.ts:480",
|
|
261
|
+
consumers: CONSUMER_GATE_STATS,
|
|
262
|
+
retentionOwnerIssue: ISSUE_LIFECYCLE_RETENTION,
|
|
263
|
+
requiredWorkflowIds: REQUIRE_SESSION_AND_TASK
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"budget_updated",
|
|
268
|
+
{
|
|
269
|
+
category: "cost",
|
|
270
|
+
severity: "info",
|
|
271
|
+
privacyClass: "pseudonymous",
|
|
272
|
+
producer: "src/telemetry.ts:496",
|
|
273
|
+
consumers: NO_CONSUMERS,
|
|
274
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
275
|
+
retentionOwnerIssue: ISSUE_COST_RETENTION,
|
|
276
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
"hard_limit_hit",
|
|
281
|
+
{
|
|
282
|
+
category: "guardrail",
|
|
283
|
+
severity: "error",
|
|
284
|
+
privacyClass: "pseudonymous",
|
|
285
|
+
producer: "src/telemetry.ts:521",
|
|
286
|
+
consumers: NO_CONSUMERS,
|
|
287
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
288
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
289
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
290
|
+
}
|
|
291
|
+
],
|
|
292
|
+
[
|
|
293
|
+
"revision_limit_hit",
|
|
294
|
+
{
|
|
295
|
+
category: "guardrail",
|
|
296
|
+
severity: "warning",
|
|
297
|
+
privacyClass: "pseudonymous",
|
|
298
|
+
producer: "src/telemetry.ts:530",
|
|
299
|
+
consumers: NO_CONSUMERS,
|
|
300
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
301
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
302
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
"loop_detected",
|
|
307
|
+
{
|
|
308
|
+
category: "guardrail",
|
|
309
|
+
severity: "warning",
|
|
310
|
+
privacyClass: "sensitive",
|
|
311
|
+
producer: "src/telemetry.ts:534",
|
|
312
|
+
consumers: NO_CONSUMERS,
|
|
313
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
314
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
315
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
"scope_violation",
|
|
320
|
+
{
|
|
321
|
+
category: "guardrail",
|
|
322
|
+
severity: "error",
|
|
323
|
+
privacyClass: "sensitive",
|
|
324
|
+
producer: "src/telemetry.ts:630",
|
|
325
|
+
consumers: NO_CONSUMERS,
|
|
326
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
327
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
328
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
329
|
+
}
|
|
330
|
+
],
|
|
331
|
+
[
|
|
332
|
+
"qa_skip_violation",
|
|
333
|
+
{
|
|
334
|
+
category: "guardrail",
|
|
335
|
+
severity: "warning",
|
|
336
|
+
privacyClass: "pseudonymous",
|
|
337
|
+
producer: "src/telemetry.ts:638",
|
|
338
|
+
consumers: NO_CONSUMERS,
|
|
339
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
340
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
341
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
342
|
+
}
|
|
343
|
+
],
|
|
344
|
+
[
|
|
345
|
+
"auto_oversight_escalation",
|
|
346
|
+
{
|
|
347
|
+
category: "guardrail",
|
|
348
|
+
severity: "warning",
|
|
349
|
+
privacyClass: "pseudonymous",
|
|
350
|
+
producer: "src/telemetry.ts:660",
|
|
351
|
+
consumers: NO_CONSUMERS,
|
|
352
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
353
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
354
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
355
|
+
}
|
|
356
|
+
],
|
|
357
|
+
[
|
|
358
|
+
"no_op_strong_warning",
|
|
359
|
+
{
|
|
360
|
+
category: "guardrail",
|
|
361
|
+
severity: "warning",
|
|
362
|
+
privacyClass: "pseudonymous",
|
|
363
|
+
producer: "src/telemetry.ts:548",
|
|
364
|
+
consumers: NO_CONSUMERS,
|
|
365
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
366
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
367
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
368
|
+
}
|
|
369
|
+
],
|
|
370
|
+
[
|
|
371
|
+
"gate_denial_loop",
|
|
372
|
+
{
|
|
373
|
+
category: "guardrail",
|
|
374
|
+
severity: "warning",
|
|
375
|
+
privacyClass: "pseudonymous",
|
|
376
|
+
producer: "src/telemetry.ts:569",
|
|
377
|
+
consumers: NO_CONSUMERS,
|
|
378
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
379
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
380
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
[
|
|
384
|
+
"execution_stall_warning",
|
|
385
|
+
{
|
|
386
|
+
category: "guardrail",
|
|
387
|
+
severity: "warning",
|
|
388
|
+
privacyClass: "pseudonymous",
|
|
389
|
+
producer: "src/telemetry.ts:583",
|
|
390
|
+
consumers: NO_CONSUMERS,
|
|
391
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
392
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
393
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
394
|
+
}
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
"execution_stall_denied",
|
|
398
|
+
{
|
|
399
|
+
category: "guardrail",
|
|
400
|
+
severity: "error",
|
|
401
|
+
privacyClass: "pseudonymous",
|
|
402
|
+
producer: "src/telemetry.ts:600",
|
|
403
|
+
consumers: NO_CONSUMERS,
|
|
404
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
405
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
406
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
407
|
+
}
|
|
408
|
+
],
|
|
409
|
+
[
|
|
410
|
+
"swarm_internals_read_denied",
|
|
411
|
+
{
|
|
412
|
+
category: "guardrail",
|
|
413
|
+
severity: "error",
|
|
414
|
+
privacyClass: "sensitive",
|
|
415
|
+
producer: "src/telemetry.ts:617",
|
|
416
|
+
consumers: NO_CONSUMERS,
|
|
417
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
418
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
419
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
420
|
+
}
|
|
421
|
+
],
|
|
422
|
+
[
|
|
423
|
+
"prm_hard_stop_delivered",
|
|
424
|
+
{
|
|
425
|
+
category: "prm",
|
|
426
|
+
severity: "error",
|
|
427
|
+
privacyClass: "pseudonymous",
|
|
428
|
+
producer: "src/telemetry.ts:752",
|
|
429
|
+
consumers: NO_CONSUMERS,
|
|
430
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
431
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
432
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
[
|
|
436
|
+
"prm_pattern_detected",
|
|
437
|
+
{
|
|
438
|
+
category: "prm",
|
|
439
|
+
severity: "notice",
|
|
440
|
+
privacyClass: "pseudonymous",
|
|
441
|
+
producer: "src/telemetry.ts:690",
|
|
442
|
+
consumers: NO_CONSUMERS,
|
|
443
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
444
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
445
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
446
|
+
}
|
|
447
|
+
],
|
|
448
|
+
[
|
|
449
|
+
"prm_course_correction_injected",
|
|
450
|
+
{
|
|
451
|
+
category: "prm",
|
|
452
|
+
severity: "notice",
|
|
453
|
+
privacyClass: "pseudonymous",
|
|
454
|
+
producer: "src/telemetry.ts:704",
|
|
455
|
+
consumers: NO_CONSUMERS,
|
|
456
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
457
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
458
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
459
|
+
}
|
|
460
|
+
],
|
|
461
|
+
[
|
|
462
|
+
"prm_escalation_triggered",
|
|
463
|
+
{
|
|
464
|
+
category: "prm",
|
|
465
|
+
severity: "warning",
|
|
466
|
+
privacyClass: "pseudonymous",
|
|
467
|
+
producer: "src/telemetry.ts:717",
|
|
468
|
+
consumers: NO_CONSUMERS,
|
|
469
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
470
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
471
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
"prm_hard_stop",
|
|
476
|
+
{
|
|
477
|
+
category: "prm",
|
|
478
|
+
severity: "critical",
|
|
479
|
+
privacyClass: "pseudonymous",
|
|
480
|
+
producer: "src/telemetry.ts:731",
|
|
481
|
+
consumers: NO_CONSUMERS,
|
|
482
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
483
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
484
|
+
requiredWorkflowIds: REQUIRE_SESSION
|
|
485
|
+
}
|
|
486
|
+
],
|
|
487
|
+
[
|
|
488
|
+
"evidence_lock_acquired",
|
|
489
|
+
{
|
|
490
|
+
category: "evidence",
|
|
491
|
+
severity: "info",
|
|
492
|
+
privacyClass: "sensitive",
|
|
493
|
+
producer: "src/evidence/lock.ts:94",
|
|
494
|
+
consumers: NO_CONSUMERS,
|
|
495
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
496
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
497
|
+
requiredWorkflowIds: REQUIRE_TASK,
|
|
498
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
499
|
+
}
|
|
500
|
+
],
|
|
501
|
+
[
|
|
502
|
+
"evidence_lock_contended",
|
|
503
|
+
{
|
|
504
|
+
category: "evidence",
|
|
505
|
+
severity: "notice",
|
|
506
|
+
privacyClass: "sensitive",
|
|
507
|
+
producer: "src/evidence/lock.ts:129",
|
|
508
|
+
consumers: NO_CONSUMERS,
|
|
509
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
510
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
511
|
+
requiredWorkflowIds: REQUIRE_TASK,
|
|
512
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
513
|
+
}
|
|
514
|
+
],
|
|
515
|
+
[
|
|
516
|
+
"evidence_lock_stale_recovered",
|
|
517
|
+
{
|
|
518
|
+
category: "evidence",
|
|
519
|
+
severity: "notice",
|
|
520
|
+
privacyClass: "sensitive",
|
|
521
|
+
producer: "src/evidence/lock.ts:86",
|
|
522
|
+
consumers: NO_CONSUMERS,
|
|
523
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
524
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
525
|
+
requiredWorkflowIds: REQUIRE_TASK,
|
|
526
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
527
|
+
}
|
|
528
|
+
],
|
|
529
|
+
[
|
|
530
|
+
"plan_ledger_cas_retry",
|
|
531
|
+
{
|
|
532
|
+
category: "plan",
|
|
533
|
+
severity: "notice",
|
|
534
|
+
privacyClass: "operational",
|
|
535
|
+
producer: "src/plan/manager.ts:329",
|
|
536
|
+
consumers: NO_CONSUMERS,
|
|
537
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
538
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
539
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
540
|
+
}
|
|
541
|
+
],
|
|
542
|
+
[
|
|
543
|
+
"plan_md_write_failed",
|
|
544
|
+
{
|
|
545
|
+
category: "plan",
|
|
546
|
+
severity: "warning",
|
|
547
|
+
privacyClass: "sensitive",
|
|
548
|
+
producer: "src/plan/manager.ts:1696",
|
|
549
|
+
consumers: NO_CONSUMERS,
|
|
550
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
551
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
552
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
553
|
+
}
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
"snapshot_failed",
|
|
557
|
+
{
|
|
558
|
+
category: "plan",
|
|
559
|
+
severity: "error",
|
|
560
|
+
privacyClass: "sensitive",
|
|
561
|
+
producer: "src/plan/ledger.ts:681",
|
|
562
|
+
consumers: NO_CONSUMERS,
|
|
563
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
564
|
+
retentionOwnerIssue: ISSUE_PLAN_EVIDENCE_RETENTION,
|
|
565
|
+
forbiddenWorkflowIds: FORBID_SESSION
|
|
566
|
+
}
|
|
567
|
+
],
|
|
568
|
+
[
|
|
569
|
+
"agent_conflict_detected",
|
|
570
|
+
{
|
|
571
|
+
category: "conflict",
|
|
572
|
+
severity: "warning",
|
|
573
|
+
privacyClass: "pseudonymous",
|
|
574
|
+
producer: "src/hooks/conflict-resolution.ts:73",
|
|
575
|
+
consumers: NO_CONSUMERS,
|
|
576
|
+
futureOwnerIssue: ISSUE_SINK,
|
|
577
|
+
retentionOwnerIssue: ISSUE_SINK,
|
|
578
|
+
requiredWorkflowIds: Object.freeze([
|
|
579
|
+
"hostSessionId",
|
|
580
|
+
"phaseId"
|
|
581
|
+
])
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
];
|
|
585
|
+
var catalog = {};
|
|
586
|
+
for (const [kind, input] of CATALOG_SOURCE) {
|
|
587
|
+
catalog[kind] = defineEntry(kind, input);
|
|
588
|
+
}
|
|
589
|
+
var EVENT_CATALOG = Object.freeze(catalog);
|
|
590
|
+
var CATALOG_KINDS = Object.freeze(Object.keys(EVENT_CATALOG));
|
|
591
|
+
function getCatalogEntry(kind) {
|
|
592
|
+
return Object.hasOwn(EVENT_CATALOG, kind) ? EVENT_CATALOG[kind] : undefined;
|
|
593
|
+
}
|
|
594
|
+
// src/observability/envelope.ts
|
|
595
|
+
init_zod();
|
|
596
|
+
var OBSERVABILITY_SCHEMA_VERSION = 1;
|
|
597
|
+
var EventCategorySchema = exports_external.enum([
|
|
598
|
+
"lifecycle",
|
|
599
|
+
"delegation",
|
|
600
|
+
"gate",
|
|
601
|
+
"plan",
|
|
602
|
+
"evidence",
|
|
603
|
+
"guardrail",
|
|
604
|
+
"knowledge",
|
|
605
|
+
"cost",
|
|
606
|
+
"prm",
|
|
607
|
+
"conflict",
|
|
608
|
+
"unrecognized"
|
|
609
|
+
]);
|
|
610
|
+
var EventSeveritySchema = exports_external.enum([
|
|
611
|
+
"debug",
|
|
612
|
+
"info",
|
|
613
|
+
"notice",
|
|
614
|
+
"warning",
|
|
615
|
+
"error",
|
|
616
|
+
"critical"
|
|
617
|
+
]);
|
|
618
|
+
var PrivacyClassSchema = exports_external.enum([
|
|
619
|
+
"operational",
|
|
620
|
+
"pseudonymous",
|
|
621
|
+
"sensitive",
|
|
622
|
+
"content"
|
|
623
|
+
]);
|
|
624
|
+
var TimingConfidenceSchema = exports_external.enum([
|
|
625
|
+
"exact",
|
|
626
|
+
"writer-clock",
|
|
627
|
+
"inferred",
|
|
628
|
+
"unknown"
|
|
629
|
+
]);
|
|
630
|
+
var SpanLinkSchema = exports_external.object({
|
|
631
|
+
traceId: exports_external.string(),
|
|
632
|
+
spanId: exports_external.string(),
|
|
633
|
+
kind: exports_external.enum(["resume", "lane", "cross-process", "retry", "parent-batch"]),
|
|
634
|
+
note: exports_external.string().optional()
|
|
635
|
+
});
|
|
636
|
+
var TraceContextSchema = exports_external.object({
|
|
637
|
+
traceId: exports_external.string(),
|
|
638
|
+
spanId: exports_external.string(),
|
|
639
|
+
parentSpanId: exports_external.string().optional(),
|
|
640
|
+
links: exports_external.array(SpanLinkSchema)
|
|
641
|
+
});
|
|
642
|
+
var WorkflowIdsSchema = exports_external.object({
|
|
643
|
+
rootConversationId: exports_external.string().optional(),
|
|
644
|
+
hostSessionId: exports_external.string().optional(),
|
|
645
|
+
swarmSessionId: exports_external.string().optional(),
|
|
646
|
+
taskId: exports_external.string().optional(),
|
|
647
|
+
phaseId: exports_external.string().optional(),
|
|
648
|
+
laneId: exports_external.string().optional(),
|
|
649
|
+
batchId: exports_external.string().optional(),
|
|
650
|
+
resultId: exports_external.string().optional(),
|
|
651
|
+
councilRoundId: exports_external.string().optional(),
|
|
652
|
+
backgroundInvocationId: exports_external.string().optional(),
|
|
653
|
+
knowledgeTraceId: exports_external.string().optional(),
|
|
654
|
+
knowledgeEntryId: exports_external.string().optional(),
|
|
655
|
+
prRunId: exports_external.string().optional()
|
|
656
|
+
});
|
|
657
|
+
var LineageSchema = exports_external.object({
|
|
658
|
+
projectRef: exports_external.string().optional(),
|
|
659
|
+
cohortRef: exports_external.string().optional(),
|
|
660
|
+
worktreeRef: exports_external.string().optional()
|
|
661
|
+
});
|
|
662
|
+
var ProvenanceSchema = exports_external.object({
|
|
663
|
+
pluginVersion: exports_external.string().optional(),
|
|
664
|
+
opencodeVersion: exports_external.string().optional(),
|
|
665
|
+
runtime: exports_external.string().optional(),
|
|
666
|
+
runtimeVersion: exports_external.string().optional(),
|
|
667
|
+
os: exports_external.string().optional(),
|
|
668
|
+
arch: exports_external.string().optional(),
|
|
669
|
+
model: exports_external.string().optional(),
|
|
670
|
+
provider: exports_external.string().optional(),
|
|
671
|
+
gitSha: exports_external.string().optional(),
|
|
672
|
+
configHash: exports_external.string().optional()
|
|
673
|
+
});
|
|
674
|
+
var OutcomeSchema = exports_external.object({
|
|
675
|
+
status: exports_external.enum(["success", "failure", "partial", "unknown"]).optional(),
|
|
676
|
+
reason: exports_external.string().optional(),
|
|
677
|
+
errorName: exports_external.string().optional(),
|
|
678
|
+
errorMessage: exports_external.string().optional(),
|
|
679
|
+
retryIndex: exports_external.number().optional(),
|
|
680
|
+
durationMs: exports_external.number().optional()
|
|
681
|
+
});
|
|
682
|
+
var PolicySchema = exports_external.object({
|
|
683
|
+
sampled: exports_external.boolean(),
|
|
684
|
+
sampleRate: exports_external.number(),
|
|
685
|
+
dropReason: exports_external.string().optional(),
|
|
686
|
+
privacyClass: PrivacyClassSchema
|
|
687
|
+
});
|
|
688
|
+
var LegacyProjectionSchema = exports_external.object({
|
|
689
|
+
sourceStore: exports_external.string(),
|
|
690
|
+
sourceSchemaVersion: exports_external.number().nullable(),
|
|
691
|
+
timingConfidence: TimingConfidenceSchema,
|
|
692
|
+
unknown: exports_external.array(exports_external.string()),
|
|
693
|
+
extra: exports_external.record(exports_external.string(), exports_external.unknown()),
|
|
694
|
+
raw: exports_external.unknown()
|
|
695
|
+
});
|
|
696
|
+
var ObservabilityEventSchema = exports_external.object({
|
|
697
|
+
schemaVersion: exports_external.number(),
|
|
698
|
+
eventId: exports_external.string(),
|
|
699
|
+
kind: exports_external.string(),
|
|
700
|
+
category: EventCategorySchema,
|
|
701
|
+
severity: EventSeveritySchema,
|
|
702
|
+
occurredAt: exports_external.string(),
|
|
703
|
+
observedAt: exports_external.string(),
|
|
704
|
+
writerSequence: exports_external.number(),
|
|
705
|
+
trace: TraceContextSchema,
|
|
706
|
+
workflow: WorkflowIdsSchema,
|
|
707
|
+
lineage: LineageSchema,
|
|
708
|
+
provenance: ProvenanceSchema,
|
|
709
|
+
outcome: OutcomeSchema,
|
|
710
|
+
policy: PolicySchema,
|
|
711
|
+
legacy: LegacyProjectionSchema,
|
|
712
|
+
relationshipViolations: exports_external.array(exports_external.string())
|
|
713
|
+
});
|
|
714
|
+
// src/observability/ids.ts
|
|
715
|
+
import { createHash, randomBytes, randomUUID } from "crypto";
|
|
716
|
+
var TRACE_ID_BYTES = 16;
|
|
717
|
+
var SPAN_ID_BYTES = 8;
|
|
718
|
+
var TRACE_ID_HEX_LENGTH = TRACE_ID_BYTES * 2;
|
|
719
|
+
var SPAN_ID_HEX_LENGTH = SPAN_ID_BYTES * 2;
|
|
720
|
+
var ALL_ZERO_TRACE_ID = "0".repeat(TRACE_ID_HEX_LENGTH);
|
|
721
|
+
var ALL_ZERO_SPAN_ID = "0".repeat(SPAN_ID_HEX_LENGTH);
|
|
722
|
+
var SENTINEL_TRACE_ID = `${"0".repeat(TRACE_ID_HEX_LENGTH - 1)}1`;
|
|
723
|
+
var SENTINEL_SPAN_ID = `${"0".repeat(SPAN_ID_HEX_LENGTH - 1)}1`;
|
|
724
|
+
var MAX_REGENERATION_ATTEMPTS = 4;
|
|
725
|
+
function newTraceId() {
|
|
726
|
+
for (let attempt = 0;attempt < MAX_REGENERATION_ATTEMPTS; attempt++) {
|
|
727
|
+
const hex = randomBytes(TRACE_ID_BYTES).toString("hex");
|
|
728
|
+
if (hex !== ALL_ZERO_TRACE_ID)
|
|
729
|
+
return hex;
|
|
730
|
+
}
|
|
731
|
+
return SENTINEL_TRACE_ID;
|
|
732
|
+
}
|
|
733
|
+
function newSpanId() {
|
|
734
|
+
for (let attempt = 0;attempt < MAX_REGENERATION_ATTEMPTS; attempt++) {
|
|
735
|
+
const hex = randomBytes(SPAN_ID_BYTES).toString("hex");
|
|
736
|
+
if (hex !== ALL_ZERO_SPAN_ID)
|
|
737
|
+
return hex;
|
|
738
|
+
}
|
|
739
|
+
return SENTINEL_SPAN_ID;
|
|
740
|
+
}
|
|
741
|
+
function newEventId() {
|
|
742
|
+
return randomUUID();
|
|
743
|
+
}
|
|
744
|
+
var POOL_DRAWS = 128;
|
|
745
|
+
var POOL_BYTES = (TRACE_ID_BYTES + SPAN_ID_BYTES) * POOL_DRAWS;
|
|
746
|
+
var _pool = Buffer.alloc(0);
|
|
747
|
+
var _poolOffset = Number.POSITIVE_INFINITY;
|
|
748
|
+
function takeIdBytes() {
|
|
749
|
+
const need = TRACE_ID_BYTES + SPAN_ID_BYTES;
|
|
750
|
+
if (_poolOffset + need > _pool.length) {
|
|
751
|
+
_pool = randomBytes(POOL_BYTES);
|
|
752
|
+
_poolOffset = 0;
|
|
753
|
+
}
|
|
754
|
+
const slice = _pool.subarray(_poolOffset, _poolOffset + need);
|
|
755
|
+
_poolOffset += need;
|
|
756
|
+
return slice;
|
|
757
|
+
}
|
|
758
|
+
function newTraceAndSpanId() {
|
|
759
|
+
const buffer = takeIdBytes();
|
|
760
|
+
const traceId = buffer.subarray(0, TRACE_ID_BYTES).toString("hex");
|
|
761
|
+
const spanId = buffer.subarray(TRACE_ID_BYTES).toString("hex");
|
|
762
|
+
if (traceId === ALL_ZERO_TRACE_ID || spanId === ALL_ZERO_SPAN_ID) {
|
|
763
|
+
return { traceId: newTraceId(), spanId: newSpanId() };
|
|
764
|
+
}
|
|
765
|
+
return { traceId, spanId };
|
|
766
|
+
}
|
|
767
|
+
// src/observability/legacy.ts
|
|
768
|
+
var LEGACY_TELEMETRY_SOURCE_STORE = ".swarm/telemetry.jsonl";
|
|
769
|
+
var NON_OBJECT_PAYLOAD_MARKER = "<non-object-payload>";
|
|
770
|
+
var INTROSPECTION_FAILED_MARKER = "<payload-introspection-failed>";
|
|
771
|
+
var LEGACY_ADAPTER_RULES = Object.freeze([
|
|
772
|
+
"Preserve unknown fields: an own key the contract does not recognize is kept under `extra` by reference and is never dropped.",
|
|
773
|
+
"Record the source store and its schema version: `sourceStore` names the file; `sourceSchemaVersion` is the version the store declares.",
|
|
774
|
+
"Preserve originally reported values: values are aliased, never coerced, normalized, rounded, or re-serialized.",
|
|
775
|
+
"Record timing confidence: a time read by the writer at record time is `writer-clock`, never `exact`.",
|
|
776
|
+
"Unknown is not zero: the adapter lists in `unknown` every catalogued key the PRODUCER left undefined, and never itself defaults one to 0, \"\", false, or null. The guarantee stops at the adapter boundary \u2014 a producer that pre-coerces its own defaults defeats it, because the adapter only ever sees the coerced value. The known instance is `delegation_end` (`src/telemetry.ts` `delegationEnd`, pre-existing): it coerces `?? 0` / `?? null` / `?? 'unavailable'` before emitting, so its cost fields can never appear in `unknown`; there, `cost_source: 'unavailable'` is how absence stays recoverable.",
|
|
777
|
+
"Missing lineage stays missing: an absent correlation ID stays `undefined` and is never synthesized to make a join succeed.",
|
|
778
|
+
"Never drop unrecognized fields: no allowlist filter is applied to the payload on the way through."
|
|
779
|
+
]);
|
|
780
|
+
var KNOWN_TELEMETRY_KEYS = Object.freeze({
|
|
781
|
+
session_started: Object.freeze(["sessionId", "agentName"]),
|
|
782
|
+
session_ended: Object.freeze(["sessionId", "reason"]),
|
|
783
|
+
agent_activated: Object.freeze(["sessionId", "agentName", "oldName"]),
|
|
784
|
+
delegation_begin: Object.freeze(["sessionId", "agentName", "taskId"]),
|
|
785
|
+
delegation_end: Object.freeze([
|
|
786
|
+
"sessionId",
|
|
787
|
+
"agentName",
|
|
788
|
+
"taskId",
|
|
789
|
+
"result",
|
|
790
|
+
"tokens_input",
|
|
791
|
+
"tokens_output",
|
|
792
|
+
"tokens_reasoning",
|
|
793
|
+
"tokens_cache",
|
|
794
|
+
"cost_usd",
|
|
795
|
+
"cost_source",
|
|
796
|
+
"model",
|
|
797
|
+
"gate",
|
|
798
|
+
"retry_index"
|
|
799
|
+
]),
|
|
800
|
+
task_state_changed: Object.freeze([
|
|
801
|
+
"sessionId",
|
|
802
|
+
"taskId",
|
|
803
|
+
"newState",
|
|
804
|
+
"oldState"
|
|
805
|
+
]),
|
|
806
|
+
gate_passed: Object.freeze(["sessionId", "gate", "taskId"]),
|
|
807
|
+
gate_parse_error: Object.freeze(["taskId", "errorName", "errorMessage"]),
|
|
808
|
+
gate_failed: Object.freeze(["sessionId", "gate", "taskId", "reason"]),
|
|
809
|
+
reviewer_gate_decision: Object.freeze([
|
|
810
|
+
"sessionId",
|
|
811
|
+
"gate",
|
|
812
|
+
"taskId",
|
|
813
|
+
"blocked",
|
|
814
|
+
"allowed",
|
|
815
|
+
"reasonCode",
|
|
816
|
+
"evidenceKind"
|
|
817
|
+
]),
|
|
818
|
+
phase_changed: Object.freeze(["sessionId", "oldPhase", "newPhase"]),
|
|
819
|
+
budget_updated: Object.freeze(["sessionId", "budgetPct", "agentName"]),
|
|
820
|
+
model_fallback: Object.freeze([
|
|
821
|
+
"sessionId",
|
|
822
|
+
"agentName",
|
|
823
|
+
"fromModel",
|
|
824
|
+
"toModel",
|
|
825
|
+
"reason"
|
|
826
|
+
]),
|
|
827
|
+
hard_limit_hit: Object.freeze([
|
|
828
|
+
"sessionId",
|
|
829
|
+
"agentName",
|
|
830
|
+
"limitType",
|
|
831
|
+
"value"
|
|
832
|
+
]),
|
|
833
|
+
revision_limit_hit: Object.freeze(["sessionId", "agentName"]),
|
|
834
|
+
loop_detected: Object.freeze(["sessionId", "agentName", "loopType"]),
|
|
835
|
+
scope_violation: Object.freeze([
|
|
836
|
+
"sessionId",
|
|
837
|
+
"agentName",
|
|
838
|
+
"file",
|
|
839
|
+
"reason"
|
|
840
|
+
]),
|
|
841
|
+
qa_skip_violation: Object.freeze(["sessionId", "agentName", "skipCount"]),
|
|
842
|
+
heartbeat: Object.freeze(["sessionId"]),
|
|
843
|
+
turbo_mode_changed: Object.freeze(["sessionId", "enabled", "agentName"]),
|
|
844
|
+
auto_oversight_escalation: Object.freeze([
|
|
845
|
+
"sessionId",
|
|
846
|
+
"reason",
|
|
847
|
+
"interactionCount",
|
|
848
|
+
"deadlockCount",
|
|
849
|
+
"phase"
|
|
850
|
+
]),
|
|
851
|
+
environment_detected: Object.freeze([
|
|
852
|
+
"sessionId",
|
|
853
|
+
"hostOS",
|
|
854
|
+
"shellFamily",
|
|
855
|
+
"executionMode"
|
|
856
|
+
]),
|
|
857
|
+
prm_pattern_detected: Object.freeze([
|
|
858
|
+
"sessionId",
|
|
859
|
+
"pattern",
|
|
860
|
+
"severity",
|
|
861
|
+
"category",
|
|
862
|
+
"stepRange"
|
|
863
|
+
]),
|
|
864
|
+
prm_course_correction_injected: Object.freeze([
|
|
865
|
+
"sessionId",
|
|
866
|
+
"pattern",
|
|
867
|
+
"level"
|
|
868
|
+
]),
|
|
869
|
+
prm_escalation_triggered: Object.freeze([
|
|
870
|
+
"sessionId",
|
|
871
|
+
"pattern",
|
|
872
|
+
"level",
|
|
873
|
+
"occurrenceCount"
|
|
874
|
+
]),
|
|
875
|
+
prm_hard_stop: Object.freeze([
|
|
876
|
+
"sessionId",
|
|
877
|
+
"pattern",
|
|
878
|
+
"level",
|
|
879
|
+
"occurrenceCount"
|
|
880
|
+
]),
|
|
881
|
+
no_op_strong_warning: Object.freeze([
|
|
882
|
+
"sessionId",
|
|
883
|
+
"agentName",
|
|
884
|
+
"count",
|
|
885
|
+
"threshold"
|
|
886
|
+
]),
|
|
887
|
+
gate_denial_loop: Object.freeze(["sessionId", "tool", "code", "count"]),
|
|
888
|
+
execution_stall_warning: Object.freeze(["sessionId", "count", "threshold"]),
|
|
889
|
+
execution_stall_denied: Object.freeze([
|
|
890
|
+
"sessionId",
|
|
891
|
+
"tool",
|
|
892
|
+
"count",
|
|
893
|
+
"threshold"
|
|
894
|
+
]),
|
|
895
|
+
swarm_internals_read_denied: Object.freeze(["sessionId", "tool", "target"]),
|
|
896
|
+
prm_hard_stop_delivered: Object.freeze([
|
|
897
|
+
"sessionId",
|
|
898
|
+
"pattern",
|
|
899
|
+
"level",
|
|
900
|
+
"occurrenceCount"
|
|
901
|
+
]),
|
|
902
|
+
evidence_lock_acquired: Object.freeze([
|
|
903
|
+
"directory",
|
|
904
|
+
"evidencePath",
|
|
905
|
+
"agent",
|
|
906
|
+
"taskId",
|
|
907
|
+
"attempt"
|
|
908
|
+
]),
|
|
909
|
+
evidence_lock_contended: Object.freeze([
|
|
910
|
+
"directory",
|
|
911
|
+
"evidencePath",
|
|
912
|
+
"agent",
|
|
913
|
+
"taskId",
|
|
914
|
+
"attempt"
|
|
915
|
+
]),
|
|
916
|
+
evidence_lock_stale_recovered: Object.freeze([
|
|
917
|
+
"directory",
|
|
918
|
+
"evidencePath",
|
|
919
|
+
"agent",
|
|
920
|
+
"taskId",
|
|
921
|
+
"attempt"
|
|
922
|
+
]),
|
|
923
|
+
plan_ledger_cas_retry: Object.freeze([
|
|
924
|
+
"attempt",
|
|
925
|
+
"expectedHashPrefix",
|
|
926
|
+
"delayMs"
|
|
927
|
+
]),
|
|
928
|
+
plan_md_write_failed: Object.freeze(["directory", "error", "timestamp"]),
|
|
929
|
+
snapshot_failed: Object.freeze(["error", "retries", "source"]),
|
|
930
|
+
agent_conflict_detected: Object.freeze([
|
|
931
|
+
"type",
|
|
932
|
+
"timestamp",
|
|
933
|
+
"sessionId",
|
|
934
|
+
"phase",
|
|
935
|
+
"taskId",
|
|
936
|
+
"sourceAgent",
|
|
937
|
+
"targetAgent",
|
|
938
|
+
"conflictType",
|
|
939
|
+
"resolutionPath",
|
|
940
|
+
"summary"
|
|
941
|
+
])
|
|
942
|
+
});
|
|
943
|
+
var EMPTY_EXTRA = Object.freeze({});
|
|
944
|
+
var PROTO_KEY = "__proto__";
|
|
945
|
+
function degradedProjection(marker, data) {
|
|
946
|
+
return {
|
|
947
|
+
sourceStore: LEGACY_TELEMETRY_SOURCE_STORE,
|
|
948
|
+
sourceSchemaVersion: null,
|
|
949
|
+
timingConfidence: "writer-clock",
|
|
950
|
+
unknown: [marker],
|
|
951
|
+
extra: EMPTY_EXTRA,
|
|
952
|
+
raw: data
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
var EMPTY_UNKNOWN = Object.freeze([]);
|
|
956
|
+
var _knownKeySetCache = new WeakMap;
|
|
957
|
+
function knownKeySetFor(knownKeys) {
|
|
958
|
+
const cached = _knownKeySetCache.get(knownKeys);
|
|
959
|
+
if (cached !== undefined)
|
|
960
|
+
return cached;
|
|
961
|
+
const built = new Set(knownKeys);
|
|
962
|
+
_knownKeySetCache.set(knownKeys, built);
|
|
963
|
+
return built;
|
|
964
|
+
}
|
|
965
|
+
function adaptLegacyTelemetryPayload(kind, data, knownKeys) {
|
|
966
|
+
if (data === null || typeof data !== "object") {
|
|
967
|
+
return degradedProjection(NON_OBJECT_PAYLOAD_MARKER, data);
|
|
968
|
+
}
|
|
969
|
+
try {
|
|
970
|
+
const record = data;
|
|
971
|
+
const known = knownKeySetFor(knownKeys);
|
|
972
|
+
const ownKeys = Object.keys(record);
|
|
973
|
+
let extra;
|
|
974
|
+
for (const key of ownKeys) {
|
|
975
|
+
if (known.has(key))
|
|
976
|
+
continue;
|
|
977
|
+
extra ??= {};
|
|
978
|
+
if (key === PROTO_KEY) {
|
|
979
|
+
Object.defineProperty(extra, key, {
|
|
980
|
+
value: record[key],
|
|
981
|
+
enumerable: true,
|
|
982
|
+
writable: true,
|
|
983
|
+
configurable: true
|
|
984
|
+
});
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
extra[key] = record[key];
|
|
988
|
+
}
|
|
989
|
+
let unknownFields;
|
|
990
|
+
for (const key of knownKeys) {
|
|
991
|
+
if (record[key] === undefined) {
|
|
992
|
+
unknownFields ??= [];
|
|
993
|
+
unknownFields.push(key);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return {
|
|
997
|
+
sourceStore: LEGACY_TELEMETRY_SOURCE_STORE,
|
|
998
|
+
sourceSchemaVersion: null,
|
|
999
|
+
timingConfidence: "writer-clock",
|
|
1000
|
+
unknown: unknownFields ?? EMPTY_UNKNOWN,
|
|
1001
|
+
extra: extra ?? EMPTY_EXTRA,
|
|
1002
|
+
raw: data
|
|
1003
|
+
};
|
|
1004
|
+
} catch {
|
|
1005
|
+
return degradedProjection(INTROSPECTION_FAILED_MARKER, data);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function nonEmptyString(value) {
|
|
1009
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
1010
|
+
}
|
|
1011
|
+
function extractWorkflowIds(data) {
|
|
1012
|
+
const ids = {};
|
|
1013
|
+
try {
|
|
1014
|
+
if (data === null || typeof data !== "object")
|
|
1015
|
+
return ids;
|
|
1016
|
+
const record = data;
|
|
1017
|
+
const hostSessionId = nonEmptyString(record.sessionId);
|
|
1018
|
+
if (hostSessionId !== undefined)
|
|
1019
|
+
ids.hostSessionId = hostSessionId;
|
|
1020
|
+
const taskId = nonEmptyString(record.taskId);
|
|
1021
|
+
if (taskId !== undefined)
|
|
1022
|
+
ids.taskId = taskId;
|
|
1023
|
+
const laneId = nonEmptyString(record.laneId);
|
|
1024
|
+
if (laneId !== undefined)
|
|
1025
|
+
ids.laneId = laneId;
|
|
1026
|
+
const batchId = nonEmptyString(record.batchId);
|
|
1027
|
+
if (batchId !== undefined)
|
|
1028
|
+
ids.batchId = batchId;
|
|
1029
|
+
const phase = record.phase;
|
|
1030
|
+
if (typeof phase === "number" && Number.isFinite(phase)) {
|
|
1031
|
+
ids.phaseId = String(phase);
|
|
1032
|
+
} else {
|
|
1033
|
+
const phaseString = nonEmptyString(phase);
|
|
1034
|
+
if (phaseString !== undefined)
|
|
1035
|
+
ids.phaseId = phaseString;
|
|
1036
|
+
}
|
|
1037
|
+
} catch {}
|
|
1038
|
+
return ids;
|
|
1039
|
+
}
|
|
1040
|
+
var RESULT_STATUS_MAP = Object.freeze({
|
|
1041
|
+
success: "success",
|
|
1042
|
+
succeeded: "success",
|
|
1043
|
+
ok: "success",
|
|
1044
|
+
pass: "success",
|
|
1045
|
+
passed: "success",
|
|
1046
|
+
complete: "success",
|
|
1047
|
+
completed: "success",
|
|
1048
|
+
failure: "failure",
|
|
1049
|
+
failed: "failure",
|
|
1050
|
+
fail: "failure",
|
|
1051
|
+
error: "failure",
|
|
1052
|
+
partial: "partial"
|
|
1053
|
+
});
|
|
1054
|
+
function extractOutcome(data) {
|
|
1055
|
+
const outcome = {};
|
|
1056
|
+
try {
|
|
1057
|
+
if (data === null || typeof data !== "object")
|
|
1058
|
+
return outcome;
|
|
1059
|
+
const record = data;
|
|
1060
|
+
const result = nonEmptyString(record.result);
|
|
1061
|
+
if (result !== undefined) {
|
|
1062
|
+
const normalized = result.toLowerCase();
|
|
1063
|
+
outcome.status = Object.hasOwn(RESULT_STATUS_MAP, normalized) ? RESULT_STATUS_MAP[normalized] : "unknown";
|
|
1064
|
+
}
|
|
1065
|
+
const reason = nonEmptyString(record.reason);
|
|
1066
|
+
if (reason !== undefined)
|
|
1067
|
+
outcome.reason = reason;
|
|
1068
|
+
const errorName = nonEmptyString(record.errorName);
|
|
1069
|
+
if (errorName !== undefined)
|
|
1070
|
+
outcome.errorName = errorName;
|
|
1071
|
+
const errorMessage = nonEmptyString(record.errorMessage);
|
|
1072
|
+
if (errorMessage !== undefined)
|
|
1073
|
+
outcome.errorMessage = errorMessage;
|
|
1074
|
+
const retryIndex = record.retry_index;
|
|
1075
|
+
if (typeof retryIndex === "number" && Number.isFinite(retryIndex)) {
|
|
1076
|
+
outcome.retryIndex = retryIndex;
|
|
1077
|
+
}
|
|
1078
|
+
} catch {}
|
|
1079
|
+
return outcome;
|
|
1080
|
+
}
|
|
1081
|
+
// src/observability/relationships.ts
|
|
1082
|
+
var TRACE_ID_PATTERN = /^[0-9a-f]{32}$/;
|
|
1083
|
+
var SPAN_ID_PATTERN = /^[0-9a-f]{16}$/;
|
|
1084
|
+
var RELATIONSHIP_VIOLATION_CODES = Object.freeze({
|
|
1085
|
+
unknownKind: "unknown_kind",
|
|
1086
|
+
requiredWorkflowIdMissing: "required_workflow_id_missing",
|
|
1087
|
+
forbiddenWorkflowIdPresent: "forbidden_workflow_id_present",
|
|
1088
|
+
parentSpanNotAllowed: "parent_span_not_allowed",
|
|
1089
|
+
parentSpanMissing: "parent_span_missing",
|
|
1090
|
+
malformedParentSpanId: "malformed_parent_span_id",
|
|
1091
|
+
linksNotAllowed: "links_not_allowed",
|
|
1092
|
+
malformedLinkTraceId: "malformed_link_trace_id",
|
|
1093
|
+
malformedLinkSpanId: "malformed_link_span_id",
|
|
1094
|
+
validationFailed: "relationship_validation_failed"
|
|
1095
|
+
});
|
|
1096
|
+
function validateEventRelationships(event) {
|
|
1097
|
+
const violations = [];
|
|
1098
|
+
try {
|
|
1099
|
+
const entry = getCatalogEntry(event.kind);
|
|
1100
|
+
const links = Array.isArray(event.trace?.links) ? event.trace.links : [];
|
|
1101
|
+
if (entry === undefined) {
|
|
1102
|
+
violations.push(`${RELATIONSHIP_VIOLATION_CODES.unknownKind}:${event.kind}`);
|
|
1103
|
+
} else {
|
|
1104
|
+
const workflow = event.workflow ?? {};
|
|
1105
|
+
for (const id of entry.requiredWorkflowIds) {
|
|
1106
|
+
if (workflow[id] === undefined) {
|
|
1107
|
+
violations.push(`${RELATIONSHIP_VIOLATION_CODES.requiredWorkflowIdMissing}:${id}`);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
for (const id of entry.forbiddenWorkflowIds) {
|
|
1111
|
+
if (workflow[id] !== undefined) {
|
|
1112
|
+
violations.push(`${RELATIONSHIP_VIOLATION_CODES.forbiddenWorkflowIdPresent}:${id}`);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const parentSpanId = event.trace?.parentSpanId;
|
|
1116
|
+
if (!entry.requiresParent && parentSpanId !== undefined) {
|
|
1117
|
+
violations.push(RELATIONSHIP_VIOLATION_CODES.parentSpanNotAllowed);
|
|
1118
|
+
}
|
|
1119
|
+
if (entry.requiresParent && parentSpanId === undefined) {
|
|
1120
|
+
violations.push(RELATIONSHIP_VIOLATION_CODES.parentSpanMissing);
|
|
1121
|
+
}
|
|
1122
|
+
if (parentSpanId !== undefined && !SPAN_ID_PATTERN.test(String(parentSpanId))) {
|
|
1123
|
+
violations.push(RELATIONSHIP_VIOLATION_CODES.malformedParentSpanId);
|
|
1124
|
+
}
|
|
1125
|
+
if (!entry.allowsLinks && links.length > 0) {
|
|
1126
|
+
violations.push(RELATIONSHIP_VIOLATION_CODES.linksNotAllowed);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
for (let index = 0;index < links.length; index++) {
|
|
1130
|
+
const link = links[index];
|
|
1131
|
+
if (link === undefined || link === null)
|
|
1132
|
+
continue;
|
|
1133
|
+
if (!TRACE_ID_PATTERN.test(String(link.traceId))) {
|
|
1134
|
+
violations.push(`${RELATIONSHIP_VIOLATION_CODES.malformedLinkTraceId}:${index}`);
|
|
1135
|
+
}
|
|
1136
|
+
if (!SPAN_ID_PATTERN.test(String(link.spanId))) {
|
|
1137
|
+
violations.push(`${RELATIONSHIP_VIOLATION_CODES.malformedLinkSpanId}:${index}`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
} catch {
|
|
1141
|
+
return {
|
|
1142
|
+
ok: false,
|
|
1143
|
+
violations: [RELATIONSHIP_VIOLATION_CODES.validationFailed]
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
return violations.length === 0 ? { ok: true } : { ok: false, violations };
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// src/observability/sampling.ts
|
|
1150
|
+
var DEFAULT_SAMPLE_RATE = 1;
|
|
1151
|
+
var SAMPLE_SUFFIX_LENGTH = 8;
|
|
1152
|
+
var SAMPLE_DENOMINATOR = 4294967295;
|
|
1153
|
+
var SAMPLE_SUFFIX_PATTERN = /^[0-9a-f]{8}$/;
|
|
1154
|
+
function shouldSample(traceId, rate) {
|
|
1155
|
+
if (typeof rate !== "number" || !Number.isFinite(rate))
|
|
1156
|
+
return true;
|
|
1157
|
+
if (rate >= 1)
|
|
1158
|
+
return true;
|
|
1159
|
+
if (rate <= 0)
|
|
1160
|
+
return false;
|
|
1161
|
+
if (typeof traceId !== "string" || traceId.length < SAMPLE_SUFFIX_LENGTH) {
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1164
|
+
const suffix = traceId.slice(-SAMPLE_SUFFIX_LENGTH).toLowerCase();
|
|
1165
|
+
if (!SAMPLE_SUFFIX_PATTERN.test(suffix))
|
|
1166
|
+
return true;
|
|
1167
|
+
const value = Number.parseInt(suffix, 16);
|
|
1168
|
+
if (!Number.isFinite(value))
|
|
1169
|
+
return true;
|
|
1170
|
+
return value / SAMPLE_DENOMINATOR < rate;
|
|
1171
|
+
}
|
|
1172
|
+
var METRIC_LABEL_ALLOWLIST = Object.freeze([
|
|
1173
|
+
"kind",
|
|
1174
|
+
"category",
|
|
1175
|
+
"severity",
|
|
1176
|
+
"outcome_status",
|
|
1177
|
+
"cost_source",
|
|
1178
|
+
"privacy_class",
|
|
1179
|
+
"runtime",
|
|
1180
|
+
"os",
|
|
1181
|
+
"provider",
|
|
1182
|
+
"sampled"
|
|
1183
|
+
]);
|
|
1184
|
+
var ALLOWED_LABELS = new Set(METRIC_LABEL_ALLOWLIST);
|
|
1185
|
+
var CARDINALITY_VIOLATION_CODES = Object.freeze({
|
|
1186
|
+
notAllowlisted: "label_not_allowlisted",
|
|
1187
|
+
highCardinalityShape: "high_cardinality_label_shape"
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
// src/observability/observe.ts
|
|
1191
|
+
var _provenance = Object.freeze({});
|
|
1192
|
+
var _lineage = Object.freeze({});
|
|
1193
|
+
var _writerSequence = 0;
|
|
1194
|
+
var _sampleRate = DEFAULT_SAMPLE_RATE;
|
|
1195
|
+
var EMPTY_KNOWN_KEYS = Object.freeze([]);
|
|
1196
|
+
var FALLBACK_EVENT_ID = "00000000-0000-4000-8000-000000000000";
|
|
1197
|
+
var FALLBACK_TRACE_ID = "00000000000000000000000000000001";
|
|
1198
|
+
var FALLBACK_SPAN_ID = "0000000000000001";
|
|
1199
|
+
var FALLBACK_TIMESTAMP = "1970-01-01T00:00:00.000Z";
|
|
1200
|
+
var OBSERVATION_BUILD_FAILED = "observation_build_failed";
|
|
1201
|
+
function nextWriterSequence() {
|
|
1202
|
+
if (_writerSequence >= Number.MAX_SAFE_INTEGER)
|
|
1203
|
+
_writerSequence = 0;
|
|
1204
|
+
_writerSequence += 1;
|
|
1205
|
+
return _writerSequence;
|
|
1206
|
+
}
|
|
1207
|
+
function safeNowIso() {
|
|
1208
|
+
try {
|
|
1209
|
+
return new Date().toISOString();
|
|
1210
|
+
} catch {
|
|
1211
|
+
return FALLBACK_TIMESTAMP;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
function buildFallbackObservation(kind, data, writerSequence) {
|
|
1215
|
+
const now = safeNowIso();
|
|
1216
|
+
return {
|
|
1217
|
+
schemaVersion: OBSERVABILITY_SCHEMA_VERSION,
|
|
1218
|
+
eventId: FALLBACK_EVENT_ID,
|
|
1219
|
+
kind,
|
|
1220
|
+
category: "unrecognized",
|
|
1221
|
+
severity: "error",
|
|
1222
|
+
occurredAt: now,
|
|
1223
|
+
observedAt: now,
|
|
1224
|
+
writerSequence,
|
|
1225
|
+
trace: { traceId: FALLBACK_TRACE_ID, spanId: FALLBACK_SPAN_ID, links: [] },
|
|
1226
|
+
workflow: {},
|
|
1227
|
+
lineage: {},
|
|
1228
|
+
provenance: {},
|
|
1229
|
+
outcome: {},
|
|
1230
|
+
policy: {
|
|
1231
|
+
sampled: shouldSample(FALLBACK_TRACE_ID, _sampleRate),
|
|
1232
|
+
sampleRate: _sampleRate,
|
|
1233
|
+
privacyClass: "operational"
|
|
1234
|
+
},
|
|
1235
|
+
legacy: {
|
|
1236
|
+
sourceStore: LEGACY_TELEMETRY_SOURCE_STORE,
|
|
1237
|
+
sourceSchemaVersion: null,
|
|
1238
|
+
timingConfidence: "unknown",
|
|
1239
|
+
unknown: [],
|
|
1240
|
+
extra: {},
|
|
1241
|
+
raw: data
|
|
1242
|
+
},
|
|
1243
|
+
relationshipViolations: [OBSERVATION_BUILD_FAILED]
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
function createObservation(kind, data) {
|
|
1247
|
+
const writerSequence = nextWriterSequence();
|
|
1248
|
+
try {
|
|
1249
|
+
const entry = getCatalogEntry(kind);
|
|
1250
|
+
const { traceId, spanId } = newTraceAndSpanId();
|
|
1251
|
+
const observedAt = new Date().toISOString();
|
|
1252
|
+
const knownKeys = Object.hasOwn(KNOWN_TELEMETRY_KEYS, kind) ? KNOWN_TELEMETRY_KEYS[kind] : EMPTY_KNOWN_KEYS;
|
|
1253
|
+
const event = {
|
|
1254
|
+
schemaVersion: OBSERVABILITY_SCHEMA_VERSION,
|
|
1255
|
+
eventId: newEventId(),
|
|
1256
|
+
kind,
|
|
1257
|
+
category: entry?.category ?? "unrecognized",
|
|
1258
|
+
severity: entry?.severity ?? "warning",
|
|
1259
|
+
occurredAt: observedAt,
|
|
1260
|
+
observedAt,
|
|
1261
|
+
writerSequence,
|
|
1262
|
+
trace: { traceId, spanId, links: [] },
|
|
1263
|
+
workflow: extractWorkflowIds(data),
|
|
1264
|
+
lineage: _lineage,
|
|
1265
|
+
provenance: _provenance,
|
|
1266
|
+
outcome: extractOutcome(data),
|
|
1267
|
+
policy: {
|
|
1268
|
+
sampled: shouldSample(traceId, _sampleRate),
|
|
1269
|
+
sampleRate: _sampleRate,
|
|
1270
|
+
privacyClass: entry?.privacyClass ?? "operational"
|
|
1271
|
+
},
|
|
1272
|
+
legacy: adaptLegacyTelemetryPayload(kind, data, knownKeys),
|
|
1273
|
+
relationshipViolations: []
|
|
1274
|
+
};
|
|
1275
|
+
const validation = validateEventRelationships(event);
|
|
1276
|
+
if (!validation.ok)
|
|
1277
|
+
event.relationshipViolations = validation.violations;
|
|
1278
|
+
return event;
|
|
1279
|
+
} catch {
|
|
1280
|
+
return buildFallbackObservation(kind, data, writerSequence);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
function toLegacyTelemetryLine(event) {
|
|
1284
|
+
return {
|
|
1285
|
+
timestamp: event.observedAt,
|
|
1286
|
+
event: event.kind,
|
|
1287
|
+
...event.legacy.raw
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
// src/observability/otel-mapping.ts
|
|
1291
|
+
var SWARM_EXTENSION_PREFIX = "swarm.";
|
|
1292
|
+
var OTEL_GENAI_ATTRIBUTES = Object.freeze({
|
|
1293
|
+
kind: "gen_ai.operation.name",
|
|
1294
|
+
"provenance.provider": "gen_ai.system",
|
|
1295
|
+
"provenance.model": "gen_ai.request.model",
|
|
1296
|
+
"legacy.raw.model": "gen_ai.response.model",
|
|
1297
|
+
"legacy.raw.agentName": "gen_ai.agent.name",
|
|
1298
|
+
"workflow.hostSessionId": "gen_ai.conversation.id",
|
|
1299
|
+
"outcome.status": "gen_ai.response.finish_reasons",
|
|
1300
|
+
"legacy.raw.tokens_input": "gen_ai.usage.input_tokens",
|
|
1301
|
+
"legacy.raw.tokens_output": "gen_ai.usage.output_tokens",
|
|
1302
|
+
"legacy.raw.tokens_cache": "gen_ai.usage.cache_read_input_tokens",
|
|
1303
|
+
"legacy.raw.tokens_reasoning": `${SWARM_EXTENSION_PREFIX}gen_ai.usage.reasoning_tokens`,
|
|
1304
|
+
"legacy.raw.cost_usd": `${SWARM_EXTENSION_PREFIX}gen_ai.usage.cost_usd`
|
|
1305
|
+
});
|
|
1306
|
+
var OPENINFERENCE_ATTRIBUTES = Object.freeze({
|
|
1307
|
+
kind: "openinference.span.kind",
|
|
1308
|
+
"provenance.model": "llm.model_name",
|
|
1309
|
+
"provenance.provider": "llm.provider",
|
|
1310
|
+
"legacy.raw.agentName": "agent.name",
|
|
1311
|
+
"workflow.hostSessionId": "session.id",
|
|
1312
|
+
"legacy.raw.tokens_input": "llm.token_count.prompt",
|
|
1313
|
+
"legacy.raw.tokens_output": "llm.token_count.completion",
|
|
1314
|
+
"legacy.raw.tokens_cache": "llm.token_count.prompt_details.cache_read",
|
|
1315
|
+
"legacy.raw.tokens_reasoning": "llm.token_count.completion_details.reasoning",
|
|
1316
|
+
"legacy.raw.cost_usd": `${SWARM_EXTENSION_PREFIX}llm.cost_usd`
|
|
1317
|
+
});
|
|
1318
|
+
var NO_ATTRIBUTES = Object.freeze({});
|
|
1319
|
+
// src/telemetry.ts
|
|
1320
|
+
var _writeStream = null;
|
|
1321
|
+
var _projectDirectory = null;
|
|
1322
|
+
var _listeners = [];
|
|
1323
|
+
var _disabled = false;
|
|
1324
|
+
var _heartbeatTrackingActive = false;
|
|
1325
|
+
var _heartbeatListener = null;
|
|
1326
|
+
var heartbeatTimestamps = new Map;
|
|
1327
|
+
function capHeartbeatMap() {
|
|
1328
|
+
while (heartbeatTimestamps.size >= 500) {
|
|
1329
|
+
const oldestKey = heartbeatTimestamps.keys().next().value;
|
|
1330
|
+
if (oldestKey === undefined)
|
|
1331
|
+
break;
|
|
1332
|
+
heartbeatTimestamps.delete(oldestKey);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
function startHeartbeatTracking() {
|
|
1336
|
+
if (_heartbeatTrackingActive)
|
|
1337
|
+
return;
|
|
1338
|
+
_heartbeatTrackingActive = true;
|
|
1339
|
+
const listener = (event, data) => {
|
|
1340
|
+
if (event !== "heartbeat")
|
|
1341
|
+
return;
|
|
1342
|
+
const payload = data;
|
|
1343
|
+
if (!payload?.sessionId)
|
|
1344
|
+
return;
|
|
1345
|
+
heartbeatTimestamps.set(payload.sessionId, Date.now());
|
|
1346
|
+
capHeartbeatMap();
|
|
1347
|
+
};
|
|
1348
|
+
_heartbeatListener = listener;
|
|
1349
|
+
addTelemetryListener(listener);
|
|
1350
|
+
}
|
|
1351
|
+
function getLastHeartbeat(sessionId) {
|
|
1352
|
+
return heartbeatTimestamps.get(sessionId);
|
|
1353
|
+
}
|
|
1354
|
+
function stopHeartbeatTracking() {
|
|
1355
|
+
_heartbeatTrackingActive = false;
|
|
1356
|
+
if (_heartbeatListener !== null) {
|
|
1357
|
+
const idx = _listeners.indexOf(_heartbeatListener);
|
|
1358
|
+
if (idx >= 0)
|
|
1359
|
+
_listeners.splice(idx, 1);
|
|
1360
|
+
_heartbeatListener = null;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function resetHeartbeatTrackingForTesting() {
|
|
1364
|
+
_heartbeatTrackingActive = false;
|
|
1365
|
+
heartbeatTimestamps.clear();
|
|
1366
|
+
if (_heartbeatListener !== null) {
|
|
1367
|
+
const idx = _listeners.indexOf(_heartbeatListener);
|
|
1368
|
+
if (idx >= 0)
|
|
1369
|
+
_listeners.splice(idx, 1);
|
|
1370
|
+
_heartbeatListener = null;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
var _emitCount = 0;
|
|
1374
|
+
var ROTATION_CHECK_INTERVAL = 50;
|
|
1375
|
+
function resetTelemetryForTesting() {
|
|
1376
|
+
_disabled = false;
|
|
1377
|
+
_projectDirectory = null;
|
|
1378
|
+
_listeners.length = 0;
|
|
1379
|
+
_emitCount = 0;
|
|
1380
|
+
resetHeartbeatTrackingForTesting();
|
|
1381
|
+
if (_writeStream !== null) {
|
|
1382
|
+
_writeStream.end();
|
|
1383
|
+
_writeStream = null;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function initTelemetry(projectDirectory) {
|
|
1387
|
+
if (_writeStream !== null || _disabled) {
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
try {
|
|
1391
|
+
_projectDirectory = projectDirectory;
|
|
1392
|
+
const swarmDir = path.join(projectDirectory, ".swarm");
|
|
1393
|
+
if (!fs.existsSync(swarmDir)) {
|
|
1394
|
+
fs.mkdirSync(swarmDir, { recursive: true });
|
|
1395
|
+
}
|
|
1396
|
+
const telemetryPath = path.join(swarmDir, "telemetry.jsonl");
|
|
1397
|
+
const stream = createWriteStream(telemetryPath, { flags: "a" });
|
|
1398
|
+
stream.on("error", () => {
|
|
1399
|
+
if (_writeStream === stream) {
|
|
1400
|
+
_disabled = true;
|
|
1401
|
+
_writeStream = null;
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
_writeStream = stream;
|
|
1405
|
+
} catch {
|
|
1406
|
+
_disabled = true;
|
|
1407
|
+
_writeStream = null;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
function emit(event, data) {
|
|
1411
|
+
try {
|
|
1412
|
+
if (_disabled || _writeStream === null) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
const canonical = _internals.createObservation(event, data);
|
|
1416
|
+
const line = JSON.stringify(_internals.toLegacyTelemetryLine(canonical)) + os.EOL;
|
|
1417
|
+
const stream = _writeStream;
|
|
1418
|
+
stream.write(line, (err) => {
|
|
1419
|
+
if (err && _writeStream === stream) {
|
|
1420
|
+
_disabled = true;
|
|
1421
|
+
_writeStream = null;
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
for (const listener of _listeners) {
|
|
1425
|
+
try {
|
|
1426
|
+
listener(event, data);
|
|
1427
|
+
} catch {}
|
|
1428
|
+
}
|
|
1429
|
+
_emitCount++;
|
|
1430
|
+
if (_emitCount >= ROTATION_CHECK_INTERVAL) {
|
|
1431
|
+
_emitCount = 0;
|
|
1432
|
+
_internals.rotateTelemetryIfNeeded();
|
|
1433
|
+
}
|
|
1434
|
+
} catch {}
|
|
1435
|
+
}
|
|
1436
|
+
function addTelemetryListener(callback) {
|
|
1437
|
+
_listeners.push(callback);
|
|
1438
|
+
}
|
|
1439
|
+
function rotateTelemetryIfNeeded(maxBytes = 10 * 1024 * 1024) {
|
|
1440
|
+
try {
|
|
1441
|
+
if (_projectDirectory === null) {
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
const telemetryPath = path.join(_projectDirectory, ".swarm", "telemetry.jsonl");
|
|
1445
|
+
if (!fs.existsSync(telemetryPath)) {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const stats = fs.statSync(telemetryPath);
|
|
1449
|
+
if (stats.size < maxBytes) {
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
const rotatedPath = path.join(_projectDirectory, ".swarm", "telemetry.jsonl.1");
|
|
1453
|
+
fs.renameSync(telemetryPath, rotatedPath);
|
|
1454
|
+
if (_writeStream !== null) {
|
|
1455
|
+
_writeStream.end();
|
|
1456
|
+
const stream = createWriteStream(telemetryPath, { flags: "a" });
|
|
1457
|
+
stream.on("error", () => {
|
|
1458
|
+
if (_writeStream === stream) {
|
|
1459
|
+
_disabled = true;
|
|
1460
|
+
_writeStream = null;
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
_writeStream = stream;
|
|
1464
|
+
}
|
|
1465
|
+
} catch {}
|
|
1466
|
+
}
|
|
1467
|
+
var telemetry = {
|
|
1468
|
+
sessionStarted(sessionId, agentName) {
|
|
1469
|
+
_internals.emit("session_started", { sessionId, agentName });
|
|
1470
|
+
},
|
|
1471
|
+
sessionEnded(sessionId, reason) {
|
|
1472
|
+
_internals.emit("session_ended", { sessionId, reason });
|
|
1473
|
+
},
|
|
1474
|
+
agentActivated(sessionId, agentName, oldName) {
|
|
1475
|
+
_internals.emit("agent_activated", { sessionId, agentName, oldName });
|
|
1476
|
+
},
|
|
1477
|
+
delegationBegin(sessionId, agentName, taskId) {
|
|
1478
|
+
_internals.emit("delegation_begin", { sessionId, agentName, taskId });
|
|
1479
|
+
},
|
|
1480
|
+
delegationEnd(sessionId, agentName, taskId, result, costFields) {
|
|
1481
|
+
_internals.emit("delegation_end", {
|
|
1482
|
+
sessionId,
|
|
1483
|
+
agentName,
|
|
1484
|
+
taskId,
|
|
1485
|
+
result,
|
|
1486
|
+
tokens_input: costFields?.tokens_input ?? 0,
|
|
1487
|
+
tokens_output: costFields?.tokens_output ?? 0,
|
|
1488
|
+
tokens_reasoning: costFields?.tokens_reasoning ?? 0,
|
|
1489
|
+
tokens_cache: costFields?.tokens_cache ?? 0,
|
|
1490
|
+
cost_usd: costFields?.cost_usd ?? null,
|
|
1491
|
+
cost_source: costFields?.cost_source ?? "unavailable",
|
|
1492
|
+
model: costFields?.model,
|
|
1493
|
+
gate: costFields?.gate,
|
|
1494
|
+
retry_index: costFields?.retry_index
|
|
1495
|
+
});
|
|
1496
|
+
},
|
|
1497
|
+
taskStateChanged(sessionId, taskId, newState, oldState) {
|
|
1498
|
+
_internals.emit("task_state_changed", {
|
|
1499
|
+
sessionId,
|
|
1500
|
+
taskId,
|
|
1501
|
+
newState,
|
|
1502
|
+
oldState
|
|
1503
|
+
});
|
|
1504
|
+
},
|
|
1505
|
+
gatePassed(sessionId, gate, taskId) {
|
|
1506
|
+
_internals.emit("gate_passed", { sessionId, gate, taskId });
|
|
1507
|
+
},
|
|
1508
|
+
gateParseError(taskId, error) {
|
|
1509
|
+
_internals.emit("gate_parse_error", {
|
|
1510
|
+
taskId,
|
|
1511
|
+
errorName: error.name,
|
|
1512
|
+
errorMessage: error.message.slice(0, 200)
|
|
1513
|
+
});
|
|
1514
|
+
},
|
|
1515
|
+
gateFailed(sessionId, gate, taskId, reason) {
|
|
1516
|
+
_internals.emit("gate_failed", { sessionId, gate, taskId, reason });
|
|
1517
|
+
},
|
|
1518
|
+
reviewerGateDecision(sessionId, taskId, blocked, reasonCode, evidenceKind) {
|
|
1519
|
+
_internals.emit("reviewer_gate_decision", {
|
|
1520
|
+
sessionId,
|
|
1521
|
+
gate: "qa_gate",
|
|
1522
|
+
taskId,
|
|
1523
|
+
blocked,
|
|
1524
|
+
allowed: !blocked,
|
|
1525
|
+
reasonCode,
|
|
1526
|
+
evidenceKind
|
|
1527
|
+
});
|
|
1528
|
+
},
|
|
1529
|
+
phaseChanged(sessionId, oldPhase, newPhase) {
|
|
1530
|
+
_internals.emit("phase_changed", { sessionId, oldPhase, newPhase });
|
|
1531
|
+
},
|
|
1532
|
+
budgetUpdated(sessionId, budgetPct, agentName) {
|
|
1533
|
+
_internals.emit("budget_updated", { sessionId, budgetPct, agentName });
|
|
1534
|
+
},
|
|
1535
|
+
modelFallback(sessionId, agentName, fromModel, toModel, reason) {
|
|
1536
|
+
_internals.emit("model_fallback", {
|
|
1537
|
+
sessionId,
|
|
1538
|
+
agentName,
|
|
1539
|
+
fromModel,
|
|
1540
|
+
toModel,
|
|
1541
|
+
reason
|
|
1542
|
+
});
|
|
1543
|
+
},
|
|
1544
|
+
hardLimitHit(sessionId, agentName, limitType, value) {
|
|
1545
|
+
_internals.emit("hard_limit_hit", {
|
|
1546
|
+
sessionId,
|
|
1547
|
+
agentName,
|
|
1548
|
+
limitType,
|
|
1549
|
+
value
|
|
1550
|
+
});
|
|
1551
|
+
},
|
|
1552
|
+
revisionLimitHit(sessionId, agentName) {
|
|
1553
|
+
_internals.emit("revision_limit_hit", { sessionId, agentName });
|
|
1554
|
+
},
|
|
1555
|
+
loopDetected(sessionId, agentName, loopType) {
|
|
1556
|
+
_internals.emit("loop_detected", { sessionId, agentName, loopType });
|
|
1557
|
+
},
|
|
1558
|
+
noOpStrongWarning(sessionId, agentName, count, threshold) {
|
|
1559
|
+
_internals.emit("no_op_strong_warning", {
|
|
1560
|
+
sessionId,
|
|
1561
|
+
agentName,
|
|
1562
|
+
count,
|
|
1563
|
+
threshold
|
|
1564
|
+
});
|
|
1565
|
+
},
|
|
1566
|
+
gateDenialLoop(sessionId, tool, code, count) {
|
|
1567
|
+
_internals.emit("gate_denial_loop", { sessionId, tool, code, count });
|
|
1568
|
+
},
|
|
1569
|
+
executionStallWarning(sessionId, count, threshold) {
|
|
1570
|
+
_internals.emit("execution_stall_warning", {
|
|
1571
|
+
sessionId,
|
|
1572
|
+
count,
|
|
1573
|
+
threshold
|
|
1574
|
+
});
|
|
1575
|
+
},
|
|
1576
|
+
executionStallDenied(sessionId, tool, count, threshold) {
|
|
1577
|
+
_internals.emit("execution_stall_denied", {
|
|
1578
|
+
sessionId,
|
|
1579
|
+
tool,
|
|
1580
|
+
count,
|
|
1581
|
+
threshold
|
|
1582
|
+
});
|
|
1583
|
+
},
|
|
1584
|
+
swarmInternalsReadDenied(sessionId, tool, target) {
|
|
1585
|
+
_internals.emit("swarm_internals_read_denied", {
|
|
1586
|
+
sessionId,
|
|
1587
|
+
tool,
|
|
1588
|
+
target
|
|
1589
|
+
});
|
|
1590
|
+
},
|
|
1591
|
+
scopeViolation(sessionId, agentName, file, reason) {
|
|
1592
|
+
_internals.emit("scope_violation", { sessionId, agentName, file, reason });
|
|
1593
|
+
},
|
|
1594
|
+
qaSkipViolation(sessionId, agentName, skipCount) {
|
|
1595
|
+
_internals.emit("qa_skip_violation", { sessionId, agentName, skipCount });
|
|
1596
|
+
},
|
|
1597
|
+
heartbeat(sessionId) {
|
|
1598
|
+
_internals.emit("heartbeat", { sessionId });
|
|
1599
|
+
},
|
|
1600
|
+
turboModeChanged(sessionId, enabled, agentName) {
|
|
1601
|
+
_internals.emit("turbo_mode_changed", { sessionId, enabled, agentName });
|
|
1602
|
+
},
|
|
1603
|
+
autoOversightEscalation(sessionId, reason, interactionCount, deadlockCount, phase) {
|
|
1604
|
+
_internals.emit("auto_oversight_escalation", {
|
|
1605
|
+
sessionId,
|
|
1606
|
+
reason,
|
|
1607
|
+
interactionCount,
|
|
1608
|
+
deadlockCount,
|
|
1609
|
+
phase
|
|
1610
|
+
});
|
|
1611
|
+
},
|
|
1612
|
+
environmentDetected(sessionId, hostOS, shellFamily, executionMode) {
|
|
1613
|
+
_internals.emit("environment_detected", {
|
|
1614
|
+
sessionId,
|
|
1615
|
+
hostOS,
|
|
1616
|
+
shellFamily,
|
|
1617
|
+
executionMode
|
|
1618
|
+
});
|
|
1619
|
+
},
|
|
1620
|
+
prmPatternDetected(sessionId, pattern, severity, category, stepRange) {
|
|
1621
|
+
_internals.emit("prm_pattern_detected", {
|
|
1622
|
+
sessionId,
|
|
1623
|
+
pattern,
|
|
1624
|
+
severity,
|
|
1625
|
+
category,
|
|
1626
|
+
stepRange
|
|
1627
|
+
});
|
|
1628
|
+
},
|
|
1629
|
+
prmCourseCorrectionInjected(sessionId, pattern, level) {
|
|
1630
|
+
_internals.emit("prm_course_correction_injected", {
|
|
1631
|
+
sessionId,
|
|
1632
|
+
pattern,
|
|
1633
|
+
level
|
|
1634
|
+
});
|
|
1635
|
+
},
|
|
1636
|
+
prmEscalationTriggered(sessionId, pattern, level, occurrenceCount) {
|
|
1637
|
+
_internals.emit("prm_escalation_triggered", {
|
|
1638
|
+
sessionId,
|
|
1639
|
+
pattern,
|
|
1640
|
+
level,
|
|
1641
|
+
occurrenceCount
|
|
1642
|
+
});
|
|
1643
|
+
},
|
|
1644
|
+
prmHardStop(sessionId, pattern, level, occurrenceCount) {
|
|
1645
|
+
_internals.emit("prm_hard_stop", {
|
|
1646
|
+
sessionId,
|
|
1647
|
+
pattern,
|
|
1648
|
+
level,
|
|
1649
|
+
occurrenceCount
|
|
1650
|
+
});
|
|
1651
|
+
},
|
|
1652
|
+
prmHardStopDelivered(sessionId, pattern, level, occurrenceCount) {
|
|
1653
|
+
_internals.emit("prm_hard_stop_delivered", {
|
|
1654
|
+
sessionId,
|
|
1655
|
+
pattern,
|
|
1656
|
+
level,
|
|
1657
|
+
occurrenceCount
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
var _internals = {
|
|
1662
|
+
telemetry,
|
|
1663
|
+
emit,
|
|
1664
|
+
rotateTelemetryIfNeeded,
|
|
1665
|
+
heartbeatListenerCount: () => _heartbeatListener !== null ? 1 : 0,
|
|
1666
|
+
createObservation,
|
|
1667
|
+
toLegacyTelemetryLine
|
|
1668
|
+
};
|
|
1669
|
+
|
|
1670
|
+
export { startHeartbeatTracking, getLastHeartbeat, stopHeartbeatTracking, resetHeartbeatTrackingForTesting, ROTATION_CHECK_INTERVAL, resetTelemetryForTesting, initTelemetry, emit, addTelemetryListener, rotateTelemetryIfNeeded, telemetry, _internals };
|