@gr8ful/spf 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -4
- package/assets/defaults/spf.config.yaml +6 -0
- package/assets/prompts/reviewer/system.md +1 -1
- package/assets/skill/SKILL.md +1 -0
- package/assets/skill/cookbooks/authoring_chains.md +90 -7
- package/assets/skill/cookbooks/ocr_reviewer.md +196 -0
- package/assets/skill/cookbooks/roster.md +15 -4
- package/assets/skill/cookbooks/spf_overview.md +1 -0
- package/assets/skill/references/config.md +69 -4
- package/assets/skill/references/observability.md +11 -2
- package/assets/templates/ts-flue-ollama.spf.config.yaml +67 -0
- package/assets/templates/ts.spf.config.yaml +5 -0
- package/dist/chains/context.d.ts +30 -0
- package/dist/chains/index.d.ts +94 -10
- package/dist/chains/index.js +70 -5
- package/dist/chains/repo_chains.d.ts +139 -0
- package/dist/chains/repo_chains.js +428 -0
- package/dist/chains/simple_sdlc.d.ts +74 -1
- package/dist/chains/simple_sdlc.js +134 -4
- package/dist/chains/steps.d.ts +215 -20
- package/dist/chains/steps.js +429 -61
- package/dist/cli/ask.d.ts +14 -1
- package/dist/cli/ask.js +32 -2
- package/dist/cli/commands/doctor.d.ts +1 -1
- package/dist/cli/commands/doctor.js +319 -11
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.js +78 -1
- package/dist/cli/commands/list.js +42 -5
- package/dist/cli/commands/run.js +25 -2
- package/dist/cli/commands/watch.d.ts +18 -0
- package/dist/cli/commands/watch.js +147 -10
- package/dist/cli/index.js +60 -3
- package/dist/cli/interview.js +65 -10
- package/dist/core/agent_cc.d.ts +40 -1
- package/dist/core/agent_cc.js +51 -4
- package/dist/core/agent_flue.js +28 -4
- package/dist/core/agents.d.ts +8 -0
- package/dist/core/agents.js +43 -3
- package/dist/core/data_types.d.ts +104 -4
- package/dist/core/data_types.js +99 -2
- package/dist/core/git_helper.d.ts +29 -0
- package/dist/core/git_helper.js +41 -1
- package/dist/core/ollama_provider.d.ts +70 -0
- package/dist/core/ollama_provider.js +208 -0
- package/dist/core/otel.d.ts +352 -0
- package/dist/core/otel.js +793 -0
- package/dist/core/providers.js +4 -0
- package/dist/core/refine.js +11 -3
- package/dist/core/session.js +39 -2
- package/dist/core/tracer.d.ts +31 -2
- package/dist/core/tracer.js +69 -11
- package/dist/core/watch.d.ts +11 -0
- package/dist/core/watch.js +17 -2
- package/dist/test/chains.test.js +8 -3
- package/dist/test/data_types.test.js +140 -2
- package/dist/test/git_helper.test.d.ts +1 -0
- package/dist/test/git_helper.test.js +59 -0
- package/dist/test/hermetic_git.d.ts +1 -0
- package/dist/test/hermetic_git.js +22 -0
- package/dist/test/init_command.test.d.ts +14 -1
- package/dist/test/init_command.test.js +54 -1
- package/dist/test/interview.test.d.ts +15 -1
- package/dist/test/interview.test.js +127 -0
- package/dist/test/ollama_provider.test.d.ts +1 -0
- package/dist/test/ollama_provider.test.js +103 -0
- package/dist/test/otel.test.d.ts +26 -0
- package/dist/test/otel.test.js +512 -0
- package/dist/test/refine.test.js +64 -1
- package/dist/test/repo_chains.test.d.ts +21 -0
- package/dist/test/repo_chains.test.js +416 -0
- package/dist/test/signoff.test.d.ts +1 -0
- package/dist/test/signoff.test.js +329 -0
- package/dist/test/ui_server.test.d.ts +7 -1
- package/dist/test/ui_server.test.js +1 -0
- package/dist/test/watch.test.js +124 -1
- package/package.json +5 -5
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry span export (v1): a config-gated, lossy, fire-and-forget
|
|
3
|
+
* PROJECTION of the trace SQLite already holds. Read this header before
|
|
4
|
+
* changing anything here — every paragraph is a constraint that survived an
|
|
5
|
+
* adversarial review, not a preference.
|
|
6
|
+
*
|
|
7
|
+
* WHAT THIS IS NOT. It is not a second source of truth and it is not in any
|
|
8
|
+
* control path. `tracer.ts` (files + SQLite, synchronous) remains THE record;
|
|
9
|
+
* this module is a tail-call fan-out off its write methods. Export can never
|
|
10
|
+
* affect a phase, a gate, or a run outcome — "agent proposes, code disposes"
|
|
11
|
+
* is untouched because export cannot dispose of anything. Nothing in here may
|
|
12
|
+
* ever throw into a caller, block a caller, or be awaited by a caller other
|
|
13
|
+
* than the two shutdown paths named under LIFECYCLE below.
|
|
14
|
+
*
|
|
15
|
+
* SPANS ONLY. No `resourceMetrics`, no `resourceLogs`. The OTLP metrics data
|
|
16
|
+
* model (temporality, monotonicity, cumulative-vs-delta) is exactly where a
|
|
17
|
+
* hand-rolled encoder produces numbers a backend silently misreads, and a
|
|
18
|
+
* wrong cost number is worse than no cost number. Token counts and dollars
|
|
19
|
+
* ride as span ATTRIBUTES instead. Do not "just add metrics" here.
|
|
20
|
+
*
|
|
21
|
+
* EXPLICIT CONFIG ONLY. Activation requires `observability.otel.endpoint` in
|
|
22
|
+
* the config file. This module NEVER reads `OTEL_EXPORTER_OTLP_ENDPOINT` or
|
|
23
|
+
* any other ambient exporter variable: an unrelated shell variable inherited
|
|
24
|
+
* from a CI image or a coworker's dotfiles must not be able to turn a repo's
|
|
25
|
+
* telemetry egress on. (`SPF_CLAUDE_CMD` is not a precedent for the opposite:
|
|
26
|
+
* that variable is SPF-namespaced and only redirects a LOCAL subprocess — it
|
|
27
|
+
* moves no data off the machine.)
|
|
28
|
+
*
|
|
29
|
+
* ATTRIBUTE ALLOWLIST — exfiltration is the top risk here, because
|
|
30
|
+
* `EventRecord.payload` carries the repository's own source code (tool args,
|
|
31
|
+
* result snippets, diffs, prompts, envelope contents, the operator's request
|
|
32
|
+
* text). The allowlist, in full: phase name/kind/owner/status/seq/attempt,
|
|
33
|
+
* chain name, adw_id, agent name/model/coding_agent, gate name + passed +
|
|
34
|
+
* violation COUNT, token counts (UsageBreakdown fields) + costs, durations
|
|
35
|
+
* (implied by span start/end), and event TYPE. Everything else is excluded by
|
|
36
|
+
* construction, not by filtering:
|
|
37
|
+
* - This module reads `EventRecord.payload` for FINITE NUMBERS ONLY (see
|
|
38
|
+
* `numOrNull`) and only under known UsageBreakdown/cost keys. A string can
|
|
39
|
+
* never reach an attribute through the payload path. Do not add a
|
|
40
|
+
* `stringValue` read from `payload` — that single line is the whole
|
|
41
|
+
* exfiltration bug.
|
|
42
|
+
* - Agent model/coding_agent come from the typed `AgentConfig` handed to
|
|
43
|
+
* `recordAgentSession` (config data), NOT from the `agent_start` payload.
|
|
44
|
+
* - Tool spans are named from `record.name`'s prefix up to the first ":"
|
|
45
|
+
* (see `toolSpanName`). The full `record.name` is a HUMAN LABEL built from
|
|
46
|
+
* real tool arguments (`agent_flue.ts`'s `labelFor` -> "bash: cat
|
|
47
|
+
* src/secret.ts") and must never be exported verbatim.
|
|
48
|
+
* - `Phase.error` is NOT exported. It is an agent- and repo-derived string.
|
|
49
|
+
* A failed phase span carries status ERROR with no message.
|
|
50
|
+
* - `tracer.sessionRequest`, `tracer.envelopeRow`, `tracer.processStart/End`
|
|
51
|
+
* have deliberately NO fan-out: the operator's request text, envelope
|
|
52
|
+
* contents, and pids are all outside the allowlist. Do not add one.
|
|
53
|
+
*
|
|
54
|
+
* SPAN MODEL. One run (adw_id) = one trace. Root span = the run. Each phase =
|
|
55
|
+
* a child span of the root, using `runner.ts`'s real `started_at`/`ended_at`.
|
|
56
|
+
* Each agent call (`agent_start`..`agent_end`, with its UsageBreakdown) = a
|
|
57
|
+
* CHILD span of its phase: a phase-only tree cannot answer "which agent call
|
|
58
|
+
* burned the tokens", which is the question this feature exists for.
|
|
59
|
+
* `tool_call` events (they carry real timing) = child spans of the open agent
|
|
60
|
+
* call where attributable, else of the phase. `handoff`/`error` become a span
|
|
61
|
+
* EVENT on the phase span, with allowlisted attributes only. `gate_pass`/
|
|
62
|
+
* `gate_fail` do NOT (see `recordGate` below, which carries the structured
|
|
63
|
+
* verdict instead). `log` is dropped outright — a console line is redundant
|
|
64
|
+
* with the phase span itself and would only crowd out `handoff`/`error` in
|
|
65
|
+
* the per-phase event cap (see BACKPRESSURE and `MAX_EVENTS_PER_SPAN`). Any
|
|
66
|
+
* event type not named above is dropped, fail-closed, by `recordEvent`.
|
|
67
|
+
*
|
|
68
|
+
* IDS ARE A BESPOKE CONVENTION, documented so nobody mistakes it for the OTel
|
|
69
|
+
* SDK's random-id behavior: trace-id = first 32 hex of sha256(adw_id),
|
|
70
|
+
* span-id = first 16 hex of sha256(a stable key — `phase_id` for a phase,
|
|
71
|
+
* `agent:<phase_id>:<agent>:<n>` for an agent call, `tool:<phase_id>:<event_id>`
|
|
72
|
+
* for a tool call). Determinism means a re-export of the same run lands on the
|
|
73
|
+
* same ids instead of duplicating the trace, and a child span can name its
|
|
74
|
+
* parent's id without waiting for the parent to be emitted.
|
|
75
|
+
* `EventRecord.parent_id` is structurally ALWAYS EMPTY today (SPF's phases are
|
|
76
|
+
* flat siblings; nothing writes nesting), so there is no recorded hierarchy to
|
|
77
|
+
* mine — the parenting above is reconstructed from phase_id + agent-call
|
|
78
|
+
* bracketing, and that is the only reason it needs reconstructing at all.
|
|
79
|
+
*
|
|
80
|
+
* PHASE SPANS ARE EMITTED AT PHASE END ONLY. A hung or killed phase is
|
|
81
|
+
* therefore INVISIBLE to the backend (its buffered span events die with it),
|
|
82
|
+
* while SQLite still shows it as `running`. Deliberate v1 trade: streaming a
|
|
83
|
+
* span at phase start would require mutating an already-sent span, which OTLP
|
|
84
|
+
* has no notion of. Recorded here so it is a known gap, not a surprise.
|
|
85
|
+
*
|
|
86
|
+
* INBOUND TRACEPARENT. When a valid W3C `traceparent` is present in the
|
|
87
|
+
* environment, its trace-id becomes this run's trace-id and the run's root
|
|
88
|
+
* span is parented under its span-id, so an SPF run joins the CI trace that
|
|
89
|
+
* launched it instead of hanging as an orphan root. Reading `traceparent` is
|
|
90
|
+
* NOT ambient activation: with no `observability.otel` config, nothing is
|
|
91
|
+
* constructed and nothing is sent, traceparent or not. Garbage is rejected
|
|
92
|
+
* silently (see `parseTraceparent`) — a malformed variable must degrade to
|
|
93
|
+
* "own root", never to an error.
|
|
94
|
+
*
|
|
95
|
+
* LIFECYCLE (copied from `notify/notifier.ts`'s discipline). A module-level
|
|
96
|
+
* LIVE registry holds every exporter this process created; `flushAll()` is
|
|
97
|
+
* awaited in `src/cli/index.ts`'s existing `finally` block next to
|
|
98
|
+
* `notify.flushAll()`, AND `session.ts`'s signal handler runs a bounded,
|
|
99
|
+
* timeout-capped drain before its `process.exit(128+n)` (notify does NOT do
|
|
100
|
+
* that second one today — its in-flight webhooks are dropped on SIGTERM; only
|
|
101
|
+
* the otel path is fixed here, on purpose, to keep this change to one seam).
|
|
102
|
+
* Send failures log ONE line for the life of the exporter, with the endpoint
|
|
103
|
+
* and every header VALUE redacted, and are then swallowed.
|
|
104
|
+
*
|
|
105
|
+
* BACKPRESSURE. `tracer.event()` fires per tool call on a hot path, so raw
|
|
106
|
+
* promise-per-span fire-and-forget is a memory bug, not a style choice.
|
|
107
|
+
* Spans go into a BOUNDED queue (`MAX_QUEUED_SPANS`, drop-OLDEST) and leave in
|
|
108
|
+
* batches (`BATCH_SPANS`, or `FLUSH_INTERVAL_MS`, whichever comes first) via an
|
|
109
|
+
* UNREF'D timer that can never hold the process open. Dropped spans are
|
|
110
|
+
* counted, reported once as a warn line, and exported as a resource attribute
|
|
111
|
+
* on the final flush so the gap is visible in the backend too. The size
|
|
112
|
+
* trigger schedules a timer rather than flushing inline, which also means a
|
|
113
|
+
* synchronous burst of thousands of events exercises the bound (see the queue
|
|
114
|
+
* test) instead of interleaving sends.
|
|
115
|
+
*
|
|
116
|
+
* WIRE FORMAT is hand-rolled OTLP/HTTP with a JSON body — no new npm
|
|
117
|
+
* dependency for an optional, lossy projection. The shape that matters:
|
|
118
|
+
* `{resourceSpans:[{resource:{attributes:[KeyValue]},scopeSpans:[{scope,spans:[Span]}]}]}`,
|
|
119
|
+
* every attribute value wrapped in an AnyValue (`{stringValue}`/`{intValue}`/
|
|
120
|
+
* `{doubleValue}`/`{boolValue}`), trace/span ids as lowercase hex strings, and
|
|
121
|
+
* every uint64 nanosecond timestamp AS A STRING (a JSON number would lose
|
|
122
|
+
* precision past 2^53 and backends reject it). `src/test/otel.test.ts` pins
|
|
123
|
+
* this shape against an in-process receiver.
|
|
124
|
+
*/
|
|
125
|
+
import type { AgentConfig, EventRecord, GateReport, OTelConfig, Phase, SFConfig } from "./data_types.ts";
|
|
126
|
+
/** trace-id = first 32 hex of sha256(adw_id). Bespoke convention — see the header. */
|
|
127
|
+
export declare function traceIdFor(adwId: string): string;
|
|
128
|
+
/** span-id = first 16 hex of sha256(key), where key is a phase_id or a synthetic child key. */
|
|
129
|
+
export declare function spanIdFor(key: string): string;
|
|
130
|
+
export interface TraceParent {
|
|
131
|
+
traceId: string;
|
|
132
|
+
spanId: string;
|
|
133
|
+
sampled: boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Strict W3C `traceparent` parse: `00-<32 hex>-<16 hex>-<2 hex>`, lowercase,
|
|
137
|
+
* exact lengths, neither id all-zero. Anything else — a wrong version, an
|
|
138
|
+
* uppercase digest, a truncated id, an empty string, unset — returns null and
|
|
139
|
+
* the run keeps its own root. Never throws, never logs: a malformed CI
|
|
140
|
+
* variable is not this module's problem to report.
|
|
141
|
+
*/
|
|
142
|
+
export declare function parseTraceparent(value: string | undefined | null): TraceParent | null;
|
|
143
|
+
/**
|
|
144
|
+
* The two env vars CI systems actually set. Reading them is not activation —
|
|
145
|
+
* see INBOUND TRACEPARENT in the header.
|
|
146
|
+
*/
|
|
147
|
+
export declare function inboundTraceparent(env?: NodeJS.ProcessEnv): TraceParent | null;
|
|
148
|
+
/**
|
|
149
|
+
* The configured endpoint is used AS GIVEN when it already names a path — the
|
|
150
|
+
* operator's URL is not ours to rewrite. A bare origin (`http://host:4318`,
|
|
151
|
+
* or a trailing "/") gets the standard OTLP/HTTP traces path appended, because
|
|
152
|
+
* that is the one guess with a single right answer. Returns the input
|
|
153
|
+
* unchanged if it does not parse as a URL; the config schema rejects those
|
|
154
|
+
* first, so this is only belt-and-braces for direct callers.
|
|
155
|
+
*/
|
|
156
|
+
export declare function resolveTracesUrl(endpoint: string): string;
|
|
157
|
+
/**
|
|
158
|
+
* A printable form of the endpoint for `spf doctor`: origin + path only.
|
|
159
|
+
* Userinfo (`https://user:token@host/...`) and the query string are dropped —
|
|
160
|
+
* both are places a credential is routinely smuggled into a URL.
|
|
161
|
+
*/
|
|
162
|
+
export declare function endpointLabel(endpoint: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* ISO-8601 -> uint64 nanoseconds AS A STRING (see WIRE FORMAT). Unparseable,
|
|
165
|
+
* missing, or pre-epoch input falls back to `fallbackMs`, because a span with
|
|
166
|
+
* a nonsense timestamp is rejected wholesale by most backends while a span
|
|
167
|
+
* with an approximate one is still useful.
|
|
168
|
+
*/
|
|
169
|
+
export declare function nanosFromIso(iso: string | null | undefined, fallbackMs?: number): string;
|
|
170
|
+
/**
|
|
171
|
+
* The safe half of a `tool_call` event's name. `record.name` for a tool call is
|
|
172
|
+
* a human label built FROM THE TOOL'S ARGUMENTS ("bash: cat src/secret.ts",
|
|
173
|
+
* "read: /etc/hosts"); only the part before the first ":" is the tool's own
|
|
174
|
+
* identity. Also clipped and character-restricted so a hand-rolled event name
|
|
175
|
+
* can't smuggle a payload through as a span name.
|
|
176
|
+
*/
|
|
177
|
+
export declare function toolSpanName(eventName: string | undefined | null): string;
|
|
178
|
+
/**
|
|
179
|
+
* Redact every secret from a log line. The endpoint and each header VALUE are
|
|
180
|
+
* passed in; `fetch` failures routinely embed the URL they attempted, and a
|
|
181
|
+
* proxy error can echo a header. One-line rule: nothing configured under
|
|
182
|
+
* `observability.otel` ever reaches a log.
|
|
183
|
+
*/
|
|
184
|
+
export declare function redact(message: string, secrets: Array<string | undefined>): string;
|
|
185
|
+
export interface OtelExporterInit {
|
|
186
|
+
/** The validated `observability.otel` block. Its presence IS the activation switch. */
|
|
187
|
+
cfg: OTelConfig;
|
|
188
|
+
adwId: string;
|
|
189
|
+
/** The CLI chain name, from `session.ts` — allowlisted, config-declared. */
|
|
190
|
+
chainName: string;
|
|
191
|
+
/** Injectable for tests; defaults to stderr, exactly like `Notifier`'s. */
|
|
192
|
+
log?: (message: string) => void;
|
|
193
|
+
/** Injectable for tests; defaults to `process.env`. Only ever read for `traceparent`. */
|
|
194
|
+
env?: NodeJS.ProcessEnv;
|
|
195
|
+
}
|
|
196
|
+
export declare class OtelExporter {
|
|
197
|
+
private readonly cfg;
|
|
198
|
+
private readonly adwId;
|
|
199
|
+
private readonly chainName;
|
|
200
|
+
private readonly serviceName;
|
|
201
|
+
private readonly url;
|
|
202
|
+
private readonly log;
|
|
203
|
+
private readonly traceId;
|
|
204
|
+
/** "" unless an inbound traceparent parented this run — see INBOUND TRACEPARENT. */
|
|
205
|
+
private readonly rootParentSpanId;
|
|
206
|
+
private readonly rootSpanId;
|
|
207
|
+
private queue;
|
|
208
|
+
private dropped;
|
|
209
|
+
private droppedEvents;
|
|
210
|
+
private warnedDrops;
|
|
211
|
+
private loggedFailure;
|
|
212
|
+
private timer;
|
|
213
|
+
private timerDelay;
|
|
214
|
+
private pending;
|
|
215
|
+
/** Span events buffered until their phase span exists. Key "" = the root run span. */
|
|
216
|
+
private bufferedEvents;
|
|
217
|
+
/**
|
|
218
|
+
* Phases whose span has already gone out. Events DO arrive after a phase
|
|
219
|
+
* span is emitted — `run.finish()`'s `not_accepted` error names the last
|
|
220
|
+
* phase — and a span already on the wire cannot grow an event, so those are
|
|
221
|
+
* re-homed onto the root run span instead of accumulating in a buffer that
|
|
222
|
+
* nothing will ever drain.
|
|
223
|
+
*/
|
|
224
|
+
private emittedPhases;
|
|
225
|
+
/** `<phase_id><agent>` -> the open agent call, for closing it and parenting tool spans. */
|
|
226
|
+
private openAgents;
|
|
227
|
+
/** How many times an agent has been called in a phase, so a retry gets its own span id. */
|
|
228
|
+
private agentCalls;
|
|
229
|
+
/** agent name -> config metadata, from `recordAgentSession` (typed config, never a payload). */
|
|
230
|
+
private agentMeta;
|
|
231
|
+
private runStartedAtMs;
|
|
232
|
+
private rootEmitted;
|
|
233
|
+
constructor(init: OtelExporterInit);
|
|
234
|
+
/** `tracer.sessionStart` — only the run's clock; the engineer name is not allowlisted. */
|
|
235
|
+
recordSessionStart(startedAtIso?: string | null): void;
|
|
236
|
+
/**
|
|
237
|
+
* `tracer.event` — the one hot seam. Dispatch, in full:
|
|
238
|
+
* phase_start/phase_end -> ignored (the phase span's own boundaries say it)
|
|
239
|
+
* agent_start -> open an agent call
|
|
240
|
+
* agent_end -> emit the agent-call child span, with usage
|
|
241
|
+
* tool_call -> emit a tool child span (real timing, safe name)
|
|
242
|
+
* gate_pass/gate_fail -> ignored HERE; `recordGate` carries the structured
|
|
243
|
+
* GateReport for the same gate, and doubling it
|
|
244
|
+
* would put two span events on every gate
|
|
245
|
+
* handoff/error -> a span event buffered onto the phase span
|
|
246
|
+
* log -> dropped: a console line adds nothing beyond
|
|
247
|
+
* `spf.event.type`/`name`, and buffering it would
|
|
248
|
+
* crowd `handoff`/`error` out of the per-phase cap
|
|
249
|
+
* (see MAX_EVENTS_PER_SPAN)
|
|
250
|
+
* anything else -> dropped. The dispatch is fail-closed on purpose:
|
|
251
|
+
* a future EventRecord.type whose `name` is
|
|
252
|
+
* derived from agent output must not fall through
|
|
253
|
+
* to export by default.
|
|
254
|
+
*/
|
|
255
|
+
recordEvent(record: EventRecord, eventId: string, tsIso: string): void;
|
|
256
|
+
/**
|
|
257
|
+
* `tracer.phaseUpsert` — the phase's END is the emit point (see PHASE SPANS
|
|
258
|
+
* ARE EMITTED AT PHASE END ONLY). The start-of-phase upsert has no
|
|
259
|
+
* `ended_at` and is skipped, which also makes this idempotent-ish: a
|
|
260
|
+
* re-upsert of the same finished phase re-emits a span with the SAME id, so
|
|
261
|
+
* a backend overwrites rather than duplicates.
|
|
262
|
+
*/
|
|
263
|
+
recordPhase(phase: Phase): void;
|
|
264
|
+
/**
|
|
265
|
+
* `tracer.gateRow` — the verdict and its SIZE, never its content. A
|
|
266
|
+
* violation string quotes the agent's own claim and the repo's files; only
|
|
267
|
+
* the count crosses the wire.
|
|
268
|
+
*/
|
|
269
|
+
recordGate(phase: Phase, gate: string, report: GateReport, attempt: number): void;
|
|
270
|
+
/**
|
|
271
|
+
* `tracer.agentSessionRow` — the typed source for an agent's model and
|
|
272
|
+
* backend. Load-bearing, not decoration: it is written BEFORE the
|
|
273
|
+
* `agent_end` event (see `agents.ts`), which is what lets the agent-call
|
|
274
|
+
* span carry model/coding_agent without ever reading the `agent_start`
|
|
275
|
+
* payload. `session_id` is NOT exported (it is a coding-agent handle, not a
|
|
276
|
+
* measure).
|
|
277
|
+
*/
|
|
278
|
+
recordAgentSession(agent: AgentConfig): void;
|
|
279
|
+
/**
|
|
280
|
+
* `tracer.sessionFinish` — emits the root run span exactly once. Called
|
|
281
|
+
* twice on some paths (a failing phase finalizes, then `finish()` does), and
|
|
282
|
+
* the guard is why that is harmless.
|
|
283
|
+
*/
|
|
284
|
+
recordSessionFinish(ok: boolean): void;
|
|
285
|
+
/** Queued spans and spans/events dropped so far. For tests and diagnostics. */
|
|
286
|
+
stats(): {
|
|
287
|
+
queued: number;
|
|
288
|
+
dropped: number;
|
|
289
|
+
droppedEvents: number;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* The exact JSON body the next flush would POST, without sending or
|
|
293
|
+
* draining. This is the seam `src/test/otel.test.ts` uses to prove the
|
|
294
|
+
* allowlist holds — the assertion is on the literal bytes, so any future
|
|
295
|
+
* attribute that leaks a payload fails a test rather than a review.
|
|
296
|
+
*/
|
|
297
|
+
pendingJson(): string;
|
|
298
|
+
private enqueue;
|
|
299
|
+
private schedule;
|
|
300
|
+
private track;
|
|
301
|
+
/**
|
|
302
|
+
* Send whatever is queued. Never throws, never rejects: a failed export is a
|
|
303
|
+
* single redacted log line and a swallowed error, because the alternative is
|
|
304
|
+
* an observability feature that can fail a run.
|
|
305
|
+
*/
|
|
306
|
+
flush(isFinal?: boolean): Promise<void>;
|
|
307
|
+
/**
|
|
308
|
+
* Drain: flush, then await anything already in flight, all under one hard
|
|
309
|
+
* budget. Never throws. Called from the CLI's `finally` and from
|
|
310
|
+
* `session.ts`'s signal handler (with a tighter budget there).
|
|
311
|
+
*/
|
|
312
|
+
drain(budgetMs?: number): Promise<void>;
|
|
313
|
+
private emitRootSpan;
|
|
314
|
+
private agentKey;
|
|
315
|
+
private openAgentCall;
|
|
316
|
+
private closeAgentCall;
|
|
317
|
+
/**
|
|
318
|
+
* Tool spans carry REAL elapsed time (the tracker records started_at/ended_at
|
|
319
|
+
* per call), which is the whole reason they are spans and not span events.
|
|
320
|
+
* Parented under the open agent call when one is attributable — the agent
|
|
321
|
+
* name comes from `payload.agent`, and it is used ONLY as a map lookup key,
|
|
322
|
+
* never written to an attribute, so an unexpected value yields "no parent
|
|
323
|
+
* found" rather than an exported string.
|
|
324
|
+
*/
|
|
325
|
+
private emitToolSpan;
|
|
326
|
+
private bufferSpanEvent;
|
|
327
|
+
private takeBufferedEvents;
|
|
328
|
+
private payloadFor;
|
|
329
|
+
private logFailureOnce;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Build an exporter from `cfg.observability.otel`, or `null` when it is
|
|
333
|
+
* absent — the same optional-dependency shape as `resolveNotifier`, so every
|
|
334
|
+
* call site is `otel?.record...()` and never a conditional branch. `null` is
|
|
335
|
+
* the default for every repo that has not configured an endpoint, and no
|
|
336
|
+
* environment variable can change that (see EXPLICIT CONFIG ONLY).
|
|
337
|
+
*/
|
|
338
|
+
export declare function resolveOtelExporter(cfg: SFConfig, opts: {
|
|
339
|
+
adwId: string;
|
|
340
|
+
chainName: string;
|
|
341
|
+
log?: (message: string) => void;
|
|
342
|
+
env?: NodeJS.ProcessEnv;
|
|
343
|
+
}): OtelExporter | null;
|
|
344
|
+
/**
|
|
345
|
+
* Drain every exporter this process created, under one budget. A no-op when
|
|
346
|
+
* otel is unconfigured. Called from `src/cli/index.ts`'s `finally` (next to
|
|
347
|
+
* `notify.flushAll()`) and, with a tighter budget, from `session.ts`'s signal
|
|
348
|
+
* handler. Never throws.
|
|
349
|
+
*/
|
|
350
|
+
export declare function flushAll(budgetMs?: number): Promise<void>;
|
|
351
|
+
/** Tests only: forget every registered exporter so cases cannot leak into each other. */
|
|
352
|
+
export declare function resetLiveForTest(): void;
|