@code-yeongyu/senpi-agent-core 2026.8.12 → 2026.8.13

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 (153) hide show
  1. package/README.md +13 -7
  2. package/dist/agent-loop.js +5 -1
  3. package/dist/agent-loop.js.map +1 -1
  4. package/dist/agent.d.ts +3 -1
  5. package/dist/agent.d.ts.map +1 -1
  6. package/dist/agent.js +8 -0
  7. package/dist/agent.js.map +1 -1
  8. package/dist/harness/agent-harness.d.ts +452 -96
  9. package/dist/harness/agent-harness.d.ts.map +1 -1
  10. package/dist/harness/agent-harness.js +162 -1005
  11. package/dist/harness/agent-harness.js.map +1 -1
  12. package/dist/harness/compaction/branch-summarization.d.ts +13 -6
  13. package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  14. package/dist/harness/compaction/branch-summarization.js +10 -14
  15. package/dist/harness/compaction/branch-summarization.js.map +1 -1
  16. package/dist/harness/compaction/compaction.d.ts +14 -17
  17. package/dist/harness/compaction/compaction.d.ts.map +1 -1
  18. package/dist/harness/compaction/compaction.js +23 -36
  19. package/dist/harness/compaction/compaction.js.map +1 -1
  20. package/dist/harness/env/nodejs.d.ts +1 -0
  21. package/dist/harness/env/nodejs.d.ts.map +1 -1
  22. package/dist/harness/env/nodejs.js +23 -7
  23. package/dist/harness/env/nodejs.js.map +1 -1
  24. package/dist/harness/messages.d.ts +3 -3
  25. package/dist/harness/messages.d.ts.map +1 -1
  26. package/dist/harness/messages.js +3 -3
  27. package/dist/harness/messages.js.map +1 -1
  28. package/dist/harness/prompt-templates.d.ts.map +1 -1
  29. package/dist/harness/prompt-templates.js +4 -9
  30. package/dist/harness/prompt-templates.js.map +1 -1
  31. package/dist/harness/reducer.d.ts +100 -0
  32. package/dist/harness/reducer.d.ts.map +1 -0
  33. package/dist/harness/reducer.js +414 -0
  34. package/dist/harness/reducer.js.map +1 -0
  35. package/dist/harness/result.d.ts +40 -0
  36. package/dist/harness/result.d.ts.map +1 -0
  37. package/dist/harness/result.js +41 -0
  38. package/dist/harness/result.js.map +1 -0
  39. package/dist/harness/session/context.d.ts +22 -0
  40. package/dist/harness/session/context.d.ts.map +1 -0
  41. package/dist/harness/session/context.js +67 -0
  42. package/dist/harness/session/context.js.map +1 -0
  43. package/dist/harness/session/index.d.ts +7 -0
  44. package/dist/harness/session/index.d.ts.map +1 -0
  45. package/dist/harness/session/index.js +6 -0
  46. package/dist/harness/session/index.js.map +1 -0
  47. package/dist/harness/session/jsonl/codec.d.ts +8 -0
  48. package/dist/harness/session/jsonl/codec.d.ts.map +1 -0
  49. package/dist/harness/session/jsonl/codec.js +190 -0
  50. package/dist/harness/session/jsonl/codec.js.map +1 -0
  51. package/dist/harness/session/jsonl/errors.d.ts +5 -0
  52. package/dist/harness/session/jsonl/errors.d.ts.map +1 -0
  53. package/dist/harness/session/jsonl/errors.js +11 -0
  54. package/dist/harness/session/jsonl/errors.js.map +1 -0
  55. package/dist/harness/session/jsonl/repo.d.ts +23 -0
  56. package/dist/harness/session/jsonl/repo.d.ts.map +1 -0
  57. package/dist/harness/session/jsonl/repo.js +129 -0
  58. package/dist/harness/session/jsonl/repo.js.map +1 -0
  59. package/dist/harness/session/jsonl/storage.d.ts +43 -0
  60. package/dist/harness/session/jsonl/storage.d.ts.map +1 -0
  61. package/dist/harness/session/jsonl/storage.js +206 -0
  62. package/dist/harness/session/jsonl/storage.js.map +1 -0
  63. package/dist/harness/session/jsonl/types.d.ts +38 -0
  64. package/dist/harness/session/jsonl/types.d.ts.map +1 -0
  65. package/dist/harness/session/jsonl/types.js +2 -0
  66. package/dist/harness/session/jsonl/types.js.map +1 -0
  67. package/dist/harness/session/jsonl.d.ts +3 -0
  68. package/dist/harness/session/jsonl.d.ts.map +1 -0
  69. package/dist/harness/session/jsonl.js +2 -0
  70. package/dist/harness/session/jsonl.js.map +1 -0
  71. package/dist/harness/session/memory.d.ts +44 -0
  72. package/dist/harness/session/memory.d.ts.map +1 -0
  73. package/dist/harness/session/memory.js +142 -0
  74. package/dist/harness/session/memory.js.map +1 -0
  75. package/dist/harness/session/search.d.ts +19 -0
  76. package/dist/harness/session/search.d.ts.map +1 -0
  77. package/dist/harness/session/search.js +41 -0
  78. package/dist/harness/session/search.js.map +1 -0
  79. package/dist/harness/session/session.d.ts +43 -38
  80. package/dist/harness/session/session.d.ts.map +1 -1
  81. package/dist/harness/session/session.js +186 -304
  82. package/dist/harness/session/session.js.map +1 -1
  83. package/dist/harness/session/state.d.ts +65 -0
  84. package/dist/harness/session/state.d.ts.map +1 -0
  85. package/dist/harness/session/state.js +320 -0
  86. package/dist/harness/session/state.js.map +1 -0
  87. package/dist/harness/session/testing/conformance.d.ts +4 -0
  88. package/dist/harness/session/testing/conformance.d.ts.map +1 -0
  89. package/dist/harness/session/testing/conformance.js +743 -0
  90. package/dist/harness/session/testing/conformance.js.map +1 -0
  91. package/dist/harness/session/testing/index.d.ts +3 -0
  92. package/dist/harness/session/testing/index.d.ts.map +1 -0
  93. package/dist/harness/session/testing/index.js +2 -0
  94. package/dist/harness/session/testing/index.js.map +1 -0
  95. package/dist/harness/session/testing/types.d.ts +14 -0
  96. package/dist/harness/session/testing/types.d.ts.map +1 -0
  97. package/dist/harness/session/testing/types.js +2 -0
  98. package/dist/harness/session/testing/types.js.map +1 -0
  99. package/dist/harness/session/types.d.ts +333 -0
  100. package/dist/harness/session/types.d.ts.map +1 -0
  101. package/dist/harness/session/types.js +9 -0
  102. package/dist/harness/session/types.js.map +1 -0
  103. package/dist/harness/skills.js +21 -19
  104. package/dist/harness/skills.js.map +1 -1
  105. package/dist/harness/telemetry.d.ts +1221 -0
  106. package/dist/harness/telemetry.d.ts.map +1 -0
  107. package/dist/harness/telemetry.js +508 -0
  108. package/dist/harness/telemetry.js.map +1 -0
  109. package/dist/harness/types.d.ts +8 -485
  110. package/dist/harness/types.d.ts.map +1 -1
  111. package/dist/harness/types.js +4 -16
  112. package/dist/harness/types.js.map +1 -1
  113. package/dist/harness/utils/truncate.js.map +1 -1
  114. package/dist/index.d.ts +10 -9
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +7 -8
  117. package/dist/index.js.map +1 -1
  118. package/dist/proxy.d.ts +1 -1
  119. package/dist/proxy.d.ts.map +1 -1
  120. package/dist/proxy.js +1 -0
  121. package/dist/proxy.js.map +1 -1
  122. package/dist/types.d.ts +6 -0
  123. package/dist/types.d.ts.map +1 -1
  124. package/dist/types.js.map +1 -1
  125. package/package.json +9 -2
  126. package/dist/harness/session/array-session-reader.d.ts +0 -3
  127. package/dist/harness/session/array-session-reader.d.ts.map +0 -1
  128. package/dist/harness/session/array-session-reader.js +0 -70
  129. package/dist/harness/session/array-session-reader.js.map +0 -1
  130. package/dist/harness/session/fork.d.ts +0 -4
  131. package/dist/harness/session/fork.d.ts.map +0 -1
  132. package/dist/harness/session/fork.js +0 -22
  133. package/dist/harness/session/fork.js.map +0 -1
  134. package/dist/harness/session/jsonl-store.d.ts +0 -13
  135. package/dist/harness/session/jsonl-store.d.ts.map +0 -1
  136. package/dist/harness/session/jsonl-store.js +0 -304
  137. package/dist/harness/session/jsonl-store.js.map +0 -1
  138. package/dist/harness/session/keyed-operation-queue.d.ts +0 -17
  139. package/dist/harness/session/keyed-operation-queue.d.ts.map +0 -1
  140. package/dist/harness/session/keyed-operation-queue.js +0 -60
  141. package/dist/harness/session/keyed-operation-queue.js.map +0 -1
  142. package/dist/harness/session/memory-store.d.ts +0 -6
  143. package/dist/harness/session/memory-store.d.ts.map +0 -1
  144. package/dist/harness/session/memory-store.js +0 -107
  145. package/dist/harness/session/memory-store.js.map +0 -1
  146. package/dist/harness/session/repository.d.ts +0 -28
  147. package/dist/harness/session/repository.d.ts.map +0 -1
  148. package/dist/harness/session/repository.js +0 -61
  149. package/dist/harness/session/repository.js.map +0 -1
  150. package/dist/harness/session/search-backend.d.ts +0 -8
  151. package/dist/harness/session/search-backend.d.ts.map +0 -1
  152. package/dist/harness/session/search-backend.js +0 -22
  153. package/dist/harness/session/search-backend.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAEhB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EAExB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACX,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,iCAAiC,EACjC,gBAAgB,GAChB,MAAM,8BAA8B,CAAC;AAEtC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Ec,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,uBAAuB,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC7E,MAAM,MAAM,qBAAqB,CAAC,IAAI,SAAS,UAAU,IAAI,kCAAkC,CAC9F,OAAO,mBAAmB,EAC1B,IAAI,CACJ,CAAC;AACF,MAAM,MAAM,mBAAmB,CAAC,IAAI,SAAS,UAAU,IAAI,gCAAgC,CAC1F,OAAO,mBAAmB,EAC1B,IAAI,CACJ,CAAC;AACF,MAAM,MAAM,gBAAgB,CAAC,IAAI,SAAS,UAAU,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,IAA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C,IAAI,SAAS,eAAe,IAAI,gCAAgC,CACpG,OAAO,wBAAwB,EAC/B,IAAI,CACJ,CAAC;AACF,MAAM,MAAM,qBAAqB,CAAC,IAAI,SAAS,eAAe,IAAI,0BAA0B,CAAC,IAAI,CAAC,GACjG,wBAAwB,CAAC,IAAI,CAAC,CAAC;AAChC,MAAM,MAAM,oBAAoB,CAAC,IAAI,SAAS,eAAe,IAAI,4BAA4B,CAC5F,OAAO,wBAAwB,EAC/B,IAAI,CACJ,CAAC;AACF,MAAM,MAAM,0BAA0B,CACrC,IAAI,SAAS,eAAe,EAC5B,SAAS,SAAS,oBAAoB,CAAC,IAAI,CAAC,IACzC,kCAAkC,CAAC,OAAO,wBAAwB,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;AACzF,MAAM,MAAM,oBAAoB,CAAC,IAAI,SAAS,eAAe,IAAI,mBAAmB,CACnF,OAAO,wBAAwB,EAC/B,IAAI,CACJ,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,wBAAwB,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEpF,wBAAgB,gBAAgB,CAC/B,IAAI,SAAS,eAAe,EAC5B,KAAK,CAAC,UAAU,SAAS,0BAA0B,CAAC,IAAI,CAAC,EACzD,MAAM,EAEN,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,wBAAwB,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,EAClF,QAAQ,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GACtE,OAAO,CAAC,MAAM,CAAC,CAIjB"}
@@ -0,0 +1,508 @@
1
+ export const AI_TELEMETRY_SCHEMA = {
2
+ version: 1,
3
+ spans: {
4
+ "pi.ai.request": {
5
+ description: "One logical request to an AI provider",
6
+ parents: { kind: "any" },
7
+ startAttributes: {
8
+ "pi.ai.operation": {
9
+ type: "string",
10
+ required: true,
11
+ values: ["stream", "fetch_deferred", "cancel_deferred", "generate_images"],
12
+ description: "Logical provider operation",
13
+ },
14
+ "pi.ai.provider": {
15
+ type: "string",
16
+ required: true,
17
+ description: "Selected provider id",
18
+ },
19
+ "pi.ai.model": {
20
+ type: "string",
21
+ required: true,
22
+ description: "Requested model id",
23
+ },
24
+ "pi.ai.api": {
25
+ type: "string",
26
+ required: true,
27
+ description: "Provider API id",
28
+ },
29
+ "pi.ai.streaming": {
30
+ type: "boolean",
31
+ required: true,
32
+ description: "Whether this operation returns a stream",
33
+ },
34
+ "pi.ai.deferred": {
35
+ type: "boolean",
36
+ required: false,
37
+ description: "Whether the operation requests or participates in deferred execution",
38
+ },
39
+ },
40
+ endAttributes: {
41
+ "pi.ai.response.model": { type: "string", description: "Concrete response model" },
42
+ "pi.ai.response.id": {
43
+ type: "string",
44
+ cardinality: "high",
45
+ description: "Provider response id",
46
+ },
47
+ "pi.ai.response.stop_reason": {
48
+ type: "string",
49
+ values: ["stop", "length", "tool_use", "error", "aborted", "deferred"],
50
+ description: "Normalized terminal response reason",
51
+ },
52
+ "pi.ai.http.status_code": { type: "number", description: "Final HTTP status" },
53
+ "pi.ai.usage.input_tokens": { type: "number", description: "Reported input tokens" },
54
+ "pi.ai.usage.output_tokens": { type: "number", description: "Reported output tokens" },
55
+ "pi.ai.usage.cache_read_tokens": { type: "number", description: "Reported cache-read tokens" },
56
+ "pi.ai.usage.cache_write_tokens": {
57
+ type: "number",
58
+ description: "Reported cache-write tokens",
59
+ },
60
+ "pi.ai.usage.reasoning_tokens": { type: "number", description: "Reported reasoning tokens" },
61
+ "pi.ai.usage.total_tokens": { type: "number", description: "Reported total tokens" },
62
+ "pi.ai.usage.cost": { type: "number", description: "Reported total cost" },
63
+ "pi.ai.stream.chunk_count": { type: "number", description: "Streamed update chunk count" },
64
+ "pi.ai.stream.time_to_first_chunk_ms": {
65
+ type: "number",
66
+ description: "Elapsed milliseconds to first update chunk",
67
+ },
68
+ "pi.ai.error.type": {
69
+ type: "string",
70
+ cardinality: "low",
71
+ description: "Provider or transport error class",
72
+ },
73
+ },
74
+ status: { default: "ok", errorWhen: "The operation throws or returns an error result" },
75
+ },
76
+ },
77
+ };
78
+ export function startAiSpan(telemetryContext, name, attributes, callback) {
79
+ return telemetryContext.startSpan({ name, attributes }, (span) => callback(span));
80
+ }
81
+ const HOOK_NAMES = [
82
+ "before_run",
83
+ "before_resume",
84
+ "before_run_end",
85
+ "transform_context",
86
+ "before_request",
87
+ "before_payload",
88
+ "after_response",
89
+ "before_tool",
90
+ "after_tool",
91
+ "before_compaction",
92
+ "before_navigation",
93
+ ];
94
+ const EVENT_TYPES = [
95
+ "run_start",
96
+ "run_resume",
97
+ "run_suspend",
98
+ "run_abort",
99
+ "run_end",
100
+ "fault",
101
+ "handler_error",
102
+ "turn_start",
103
+ "turn_end",
104
+ "retry_scheduled",
105
+ "retry_start",
106
+ "retry_end",
107
+ "message_start",
108
+ "message_update",
109
+ "message_end",
110
+ "tool_start",
111
+ "tool_update",
112
+ "tool_end",
113
+ "entry_added",
114
+ "write_pending",
115
+ "queue_update",
116
+ "fact_update",
117
+ "config_update",
118
+ "compaction_start",
119
+ "compaction_end",
120
+ "navigation_start",
121
+ "navigation_end",
122
+ "lane_created",
123
+ "usage",
124
+ ];
125
+ const operationStartAttributes = {
126
+ "pi.session.id": {
127
+ type: "string",
128
+ required: true,
129
+ cardinality: "high",
130
+ description: "Session id",
131
+ },
132
+ "pi.lane.name": {
133
+ type: "string",
134
+ required: true,
135
+ cardinality: "high",
136
+ description: "Lane name",
137
+ },
138
+ "pi.operation.id": {
139
+ type: "string",
140
+ required: true,
141
+ cardinality: "high",
142
+ description: "Durable operation id",
143
+ },
144
+ "pi.operation.recovery": {
145
+ type: "boolean",
146
+ required: true,
147
+ description: "Whether this invocation resumes durable work",
148
+ },
149
+ };
150
+ const operationErrorAttributes = {
151
+ "pi.error.code": {
152
+ type: "string",
153
+ cardinality: "low",
154
+ description: "Stable operation error code",
155
+ },
156
+ "pi.error.type": {
157
+ type: "string",
158
+ cardinality: "low",
159
+ description: "Low-cardinality operation error class",
160
+ },
161
+ };
162
+ export const HARNESS_TELEMETRY_SCHEMA = {
163
+ version: 1,
164
+ spans: {
165
+ "pi.harness.run": {
166
+ description: "One admitted in-process run invocation",
167
+ parents: { kind: "root_or_external" },
168
+ startAttributes: {
169
+ ...operationStartAttributes,
170
+ "pi.operation.kind": {
171
+ type: "string",
172
+ required: true,
173
+ values: ["run"],
174
+ description: "Run operation kind",
175
+ },
176
+ },
177
+ endAttributes: {
178
+ "pi.operation.outcome": {
179
+ type: "string",
180
+ values: ["completed", "aborted", "failed", "suspended"],
181
+ description: "Run invocation outcome",
182
+ },
183
+ ...operationErrorAttributes,
184
+ },
185
+ status: { default: "ok", errorWhen: "The run fails or throws" },
186
+ },
187
+ "pi.harness.compaction": {
188
+ description: "One admitted in-process manual compaction invocation",
189
+ parents: { kind: "root_or_external" },
190
+ startAttributes: {
191
+ ...operationStartAttributes,
192
+ "pi.operation.kind": {
193
+ type: "string",
194
+ required: true,
195
+ values: ["compaction"],
196
+ description: "Compaction operation kind",
197
+ },
198
+ },
199
+ endAttributes: {
200
+ "pi.operation.outcome": {
201
+ type: "string",
202
+ values: ["completed", "declined", "aborted", "failed"],
203
+ description: "Compaction invocation outcome",
204
+ },
205
+ ...operationErrorAttributes,
206
+ },
207
+ status: { default: "ok", errorWhen: "The compaction fails or throws" },
208
+ },
209
+ "pi.harness.navigation": {
210
+ description: "One admitted in-process navigation invocation",
211
+ parents: { kind: "root_or_external" },
212
+ startAttributes: {
213
+ ...operationStartAttributes,
214
+ "pi.operation.kind": {
215
+ type: "string",
216
+ required: true,
217
+ values: ["navigation"],
218
+ description: "Navigation operation kind",
219
+ },
220
+ },
221
+ endAttributes: {
222
+ "pi.operation.outcome": {
223
+ type: "string",
224
+ values: ["completed", "declined", "aborted", "failed"],
225
+ description: "Navigation invocation outcome",
226
+ },
227
+ ...operationErrorAttributes,
228
+ },
229
+ status: { default: "ok", errorWhen: "The navigation fails or throws" },
230
+ },
231
+ "pi.harness.checkpoint": {
232
+ description: "One run checkpoint",
233
+ parents: { kind: "spans", spans: ["pi.harness.run"] },
234
+ startAttributes: {
235
+ "pi.lane.name": {
236
+ type: "string",
237
+ required: true,
238
+ cardinality: "high",
239
+ description: "Lane name",
240
+ },
241
+ "pi.operation.id": {
242
+ type: "string",
243
+ required: true,
244
+ cardinality: "high",
245
+ description: "Durable operation id",
246
+ },
247
+ "pi.checkpoint.kind": {
248
+ type: "string",
249
+ required: true,
250
+ values: ["normal", "failure_drain", "abort_reconcile"],
251
+ description: "Checkpoint purpose",
252
+ },
253
+ },
254
+ endAttributes: {},
255
+ status: { default: "ok", errorWhen: "Checkpoint work throws" },
256
+ },
257
+ "pi.harness.turn": {
258
+ description: "One assistant response and its tool batch",
259
+ parents: { kind: "spans", spans: ["pi.harness.run"] },
260
+ startAttributes: {
261
+ "pi.lane.name": {
262
+ type: "string",
263
+ required: true,
264
+ cardinality: "high",
265
+ description: "Lane name",
266
+ },
267
+ "pi.operation.id": {
268
+ type: "string",
269
+ required: true,
270
+ cardinality: "high",
271
+ description: "Durable operation id",
272
+ },
273
+ "pi.turn.id": {
274
+ type: "string",
275
+ required: true,
276
+ cardinality: "high",
277
+ description: "Invocation-local turn id",
278
+ },
279
+ },
280
+ endAttributes: {},
281
+ status: { default: "ok", errorWhen: "Turn work throws" },
282
+ },
283
+ "pi.harness.step": {
284
+ description: "One durable retry attempt",
285
+ parents: {
286
+ kind: "spans",
287
+ spans: ["pi.harness.turn", "pi.harness.checkpoint", "pi.harness.compaction", "pi.harness.navigation"],
288
+ },
289
+ startAttributes: {
290
+ "pi.lane.name": {
291
+ type: "string",
292
+ required: true,
293
+ cardinality: "high",
294
+ description: "Lane name",
295
+ },
296
+ "pi.operation.id": {
297
+ type: "string",
298
+ required: true,
299
+ cardinality: "high",
300
+ description: "Durable operation id",
301
+ },
302
+ "pi.step.kind": {
303
+ type: "string",
304
+ required: true,
305
+ values: ["assistant", "compaction", "branch_summary"],
306
+ description: "Retryable step kind",
307
+ },
308
+ "pi.step.attempt": {
309
+ type: "number",
310
+ required: true,
311
+ description: "One-based durable attempt number",
312
+ },
313
+ "pi.compaction.reason": {
314
+ type: "string",
315
+ required: false,
316
+ values: ["manual", "threshold", "overflow"],
317
+ description: "Compaction trigger",
318
+ },
319
+ },
320
+ endAttributes: {
321
+ "pi.step.outcome": {
322
+ type: "string",
323
+ values: ["succeeded", "retry", "failed", "aborted", "deferred", "overflow"],
324
+ description: "Attempt outcome",
325
+ },
326
+ },
327
+ status: { default: "ok", errorWhen: "The attempt retries, fails, or throws" },
328
+ },
329
+ "pi.harness.tool": {
330
+ description: "One raw phase-2 tool execution",
331
+ parents: { kind: "spans", spans: ["pi.harness.turn", "pi.harness.run"] },
332
+ startAttributes: {
333
+ "pi.lane.name": {
334
+ type: "string",
335
+ required: true,
336
+ cardinality: "high",
337
+ description: "Lane name",
338
+ },
339
+ "pi.operation.id": {
340
+ type: "string",
341
+ required: true,
342
+ cardinality: "high",
343
+ description: "Durable operation id",
344
+ },
345
+ "pi.turn.id": {
346
+ type: "string",
347
+ required: false,
348
+ cardinality: "high",
349
+ description: "Invocation-local live turn id",
350
+ },
351
+ "pi.tool.name": {
352
+ type: "string",
353
+ required: true,
354
+ description: "Tool name",
355
+ },
356
+ "pi.tool.call_id": {
357
+ type: "string",
358
+ required: true,
359
+ cardinality: "high",
360
+ description: "Tool call id",
361
+ },
362
+ "pi.tool.replay": {
363
+ type: "string",
364
+ required: true,
365
+ values: ["never", "safe"],
366
+ description: "Declared replay policy",
367
+ },
368
+ "pi.tool.recovery": {
369
+ type: "boolean",
370
+ required: true,
371
+ description: "Whether this is recovery execution",
372
+ },
373
+ },
374
+ endAttributes: {
375
+ "pi.tool.is_error": {
376
+ type: "boolean",
377
+ description: "Whether raw phase-2 execution returned an error",
378
+ },
379
+ },
380
+ status: { default: "ok", errorWhen: "Raw phase-2 execution returns an error" },
381
+ },
382
+ "pi.harness.hook": {
383
+ description: "One registered hook handler invocation",
384
+ parents: { kind: "any" },
385
+ startAttributes: {
386
+ "pi.lane.name": {
387
+ type: "string",
388
+ required: true,
389
+ cardinality: "high",
390
+ description: "Lane name",
391
+ },
392
+ "pi.operation.id": {
393
+ type: "string",
394
+ required: false,
395
+ cardinality: "high",
396
+ description: "Durable operation id when accepted",
397
+ },
398
+ "pi.hook.name": {
399
+ type: "string",
400
+ required: true,
401
+ values: HOOK_NAMES,
402
+ description: "Hook name",
403
+ },
404
+ "pi.hook.registration_id": {
405
+ type: "string",
406
+ required: false,
407
+ description: "Stable hook registration id",
408
+ },
409
+ },
410
+ endAttributes: {
411
+ "pi.hook.outcome": {
412
+ type: "string",
413
+ values: ["completed", "skipped", "blocked", "failed"],
414
+ description: "Handler outcome",
415
+ },
416
+ },
417
+ status: { default: "ok", errorWhen: "The handler throws" },
418
+ },
419
+ "pi.harness.sleep": {
420
+ description: "One retry delay",
421
+ parents: { kind: "spans", spans: ["pi.harness.step", "pi.harness.run"] },
422
+ startAttributes: {
423
+ "pi.operation.id": {
424
+ type: "string",
425
+ required: true,
426
+ cardinality: "high",
427
+ description: "Durable operation id",
428
+ },
429
+ "pi.sleep.delay_ms": {
430
+ type: "number",
431
+ required: true,
432
+ description: "Requested delay in milliseconds",
433
+ },
434
+ },
435
+ endAttributes: {
436
+ "pi.sleep.outcome": {
437
+ type: "string",
438
+ values: ["elapsed", "aborted"],
439
+ description: "Delay outcome",
440
+ },
441
+ },
442
+ status: { default: "ok", errorWhen: "Sleep work throws" },
443
+ },
444
+ "pi.harness.event_handler": {
445
+ description: "One passive event listener invocation",
446
+ parents: { kind: "any" },
447
+ startAttributes: {
448
+ "pi.event.type": {
449
+ type: "string",
450
+ required: true,
451
+ cardinality: "low",
452
+ values: EVENT_TYPES,
453
+ description: "Delivered harness event type",
454
+ },
455
+ "pi.lane.name": {
456
+ type: "string",
457
+ required: false,
458
+ cardinality: "high",
459
+ description: "Lane name for lane-scoped events",
460
+ },
461
+ },
462
+ endAttributes: {},
463
+ status: { default: "ok", errorWhen: "The listener throws" },
464
+ },
465
+ "pi.session.write": {
466
+ description: "One committed session mutation",
467
+ parents: { kind: "any" },
468
+ startAttributes: {
469
+ "pi.lane.name": {
470
+ type: "string",
471
+ required: true,
472
+ cardinality: "high",
473
+ description: "Lane name",
474
+ },
475
+ "pi.operation.id": {
476
+ type: "string",
477
+ required: false,
478
+ cardinality: "high",
479
+ description: "Durable operation id when accepted",
480
+ },
481
+ "pi.session.mutation": {
482
+ type: "string",
483
+ required: true,
484
+ values: ["entry", "record", "lane", "fact"],
485
+ description: "Session mutation kind",
486
+ },
487
+ "pi.session.item_type": {
488
+ type: "string",
489
+ required: false,
490
+ description: "Entry, record, lane, or fact subtype",
491
+ },
492
+ },
493
+ endAttributes: {
494
+ "pi.session.seq": {
495
+ type: "number",
496
+ description: "Committed session sequence when exposed",
497
+ },
498
+ },
499
+ status: { default: "ok", errorWhen: "Storage rejects the mutation" },
500
+ },
501
+ },
502
+ };
503
+ /** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */
504
+ export const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA];
505
+ export function startHarnessSpan(telemetryContext, name, attributes, callback) {
506
+ return telemetryContext.startSpan({ name, attributes }, (span) => callback(span));
507
+ }
508
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAyCA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE;QACN,eAAe,EAAE;YAChB,WAAW,EAAE,uCAAuC;YACpD,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YACxB,eAAe,EAAE;gBAChB,iBAAiB,EAAE;oBAClB,IAAI,EAAE,QAAQ;oBACd,QAAQ,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Content":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetryContext,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span) => callback(span as AiTelemetrySpan<Name>));\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_resume\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"run_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"write_pending\",\n\t\"queue_update\",\n\t\"fact_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"failure_drain\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Stable hook registration id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.step\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session mutation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.mutation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"entry\", \"record\", \"lane\", \"fact\"],\n\t\t\t\t\tdescription: \"Session mutation kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Entry, record, lane, or fact subtype\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Committed session sequence when exposed\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the mutation\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>),\n\t);\n}\n"]}