rp-telemetry
Capture per-run telemetry that tells us what to improve in the skills and the underlying
Wix tooling. This skill stays active alongside the migration skills for the entire
run; the migration skills themselves are unchanged and know nothing about telemetry.
The one rule that governs everything you record
Observation, not diagnosis. Every field records what was observed — what happened,
what was expected, what actually occurred, where, and how often. Never record a root
cause, a fix, a recommendation, or a workaround-as-solution. There is deliberately no
field for them; the schema rejects unknown fields. Root cause is derived later, at review
time, by a reviewing agent with full context — not asserted by you in the moment.
Three discipline rules apply to every free-text field (what_happened, expected,
actual):
- Types, not instances. Refer to entity types and classes, never specific client
data.
entity_type: "product" — never a product's name, SKU, price, or body text.
- Secret-safe. No credentials, tokens, URLs, config values, or file contents — the
recorder also runs a mechanical scrub as a last line of defense, but do not rely on it.
- Short and structural. A sentence or two, max 400 chars. Prefer stating
expected-vs-actual over narrating. The coded fields carry the structure.
- No remediation narration. "The canonical lib was fixed and re-synced" is a fix
story, not an observation — even when true (dev-mode backports). Record what was
observed to work ("adding fieldsets=FULL returned the field; the lookup succeeded")
and leave the repair to the execution log.
The recorder
All telemetry is persisted through the bundled recorder — never hand-write or edit
run-telemetry.json or telemetry/ files. Run it from this resource directory
(see CONVENTIONS.md), pointing at the active migration project:
node scripts/rp-telemetry.js <command> [...] --project <abs path to migrations/<project>>
The recorder owns everything mechanical: schema validation (it rejects invalid enums and
unknown fields — fix and retry, never guess around it), timestamps, per-class event
folding, the run/attempt/session resume model, the privacy scrub, and the well-formedness
gate at finalize. It prints one JSON result per call; {"ok":false,...} lists exactly
what to fix.
| Call |
When |
start '<dims-json>' |
At run begin — before any other pipeline step. Resumes an unfinalized run automatically. |
dims '<dims-json>' |
Whenever a dimension becomes known mid-run (platform version and extensions after discovery, site_id after provisioning). |
stage start <stage> / stage end <stage> --outcome <outcome> |
At every stage boundary. Outcomes: passed, halted, failed, skipped. |
meter [--api-ms N --model-ms N --script-ms N --input-tokens N …] |
Measured latency/token counts for a stage. Call it whenever you have real numbers; see "Metering" below. |
wait start [--halt <subtype> --skill <s> [--what '<text>']] / wait end |
The moment the run halts for the user, and the moment it resumes. This is how user latency stays out of active_ms — never estimate elapsed time yourself. Pass --halt for a needs-user halt and the recorder emits the paired halt_needs_user event for you. |
record '<event-json>' |
The moment something observable happens (taxonomy below). |
digest --transcript <path> [--offline] |
Just before finalize — a deterministic parse of this run's Claude Code session transcript (cost, turn counts, tool failures, retry loops, hook errors). Never authored by you; --offline re-runs it later against a checkpointed or local transcript for a run that died before calling it. |
finalize '<rollup-json>' |
When the run reaches a terminal state. |
rebuild [--attempt <n>] [--push] |
Only on request, to re-assemble a past run's signal document from its archived journal after a recorder fix — never during a run. --push re-emits the rebuilt run to the BI sink (backfill after an outage; idempotent — the reviewer dedupes at query time). |
status |
To orient after a resume. |
Run lifecycle
start as the first telemetry act of the run, with whatever dimensions are already
known:
node scripts/rp-telemetry.js start '{"source_platform":"wordpress",
"source_site_url":"https://client-site.example","source_acquisition":"public_storefront",
"delivery_mode":"management","destination_strategy":"new_site",
"runtime_env":{"agent_runtime":"claude-code","model":"<model id>"}}' --project <dir>
start on a project with an unfinalized run resumes it (same run, same attempt,
one more session) and closes any open wait interval. start after a finalized run
opens the next attempt. Never try to manage run identity yourself.
Always start on resume, even mid-stage. Besides the session accounting, the
resume is a BI heal point: the recorder re-pushes everything the previous session's
transport may have lost (push failures are journaled, then healed at the next
opportunity — a halted run may never reach finalize, so skipping the resume start
can strand the run's tail in the local journal). status shows bi_backlog: true
when unpushed rows are pending.
source_acquisition is an open set of class tokens, but reuse an established one
(admin_api, public_storefront, public_content, file_export) rather than
minting a synonym — cross-run folding depends on stable tokens.
Skills provenance is auto-stamped — you don't pass it. At start the recorder
stamps two identifiers onto the run so every record can be traced back to the skills
that produced it:
skills_version — the bundle's semver release label (from VERSION). Coarse and
hand-bumped by design; it is the group-by/order-by key that binds issues to a
release line ("all issues on 1.2.x", "regressed since 1.1.0").
skills_commit — the exact source commit the bundle was built from: the precise
vendored snapshot within a release. Many commits ship under one hand-bumped
skills_version, so a run reporting 1.0.0 is otherwise unattributable to the
change that produced its issue. The recorder resolves it, in order of authority,
from the sourceCommit stamped into .publish-manifest.json at publish time (the
only source that works in a partner runtime, and the only correct one once the
bundle is vendored into wix/skills), else a dev-mode git rev-parse --short HEAD
of the source checkout, else null.
Both may be overridden by passing skills_version / skills_commit in the start
dims (a runtime with better provenance than the recorder can infer), but normally you
leave them to auto-resolve.
Stage boundaries as the pipeline moves. Map orchestrator steps to stages like this:
| Stage |
Covers |
config |
Everything before discovery: project resolution, config files, up-front input collection |
discovery |
Source discovery (rp-discovery + source adapter) |
mcp_gate |
The Wix MCP prerequisite gate between discovery and mapping |
mapping |
rp-mapper producing the mapping plan |
mapping_review |
The mapping review checkpoint (user-facing) |
setup_discovery |
rp-setup-discovery |
codegen |
rp-import-codegen |
approval_gate |
The execution-plan approval gate (user-facing) |
setup_provisioning |
Site creation, app installs, collections — rp-execute-setup |
storefront_build |
The website-mode wix-headless build + release; skipped in management mode |
extract |
Source extraction to disk, before any write (rp-execute-import) |
import |
The import writes (rp-execute-import) |
finish |
Verification spot-checks, completion reporting, handoff |
Stages bind to when the work actually runs, not to their canonical order. If the
orchestration runs extraction early (e.g. extract + dry-run before the approval gate,
inside the codegen phase), close the open stage, bracket the extraction in its own
extract stage, then reopen — a stage may be entered more than once, and its
active_ms sums the entries. Booking a real extraction into codegen (and leaving
extract as a milliseconds-long token stage) is exactly the mis-attribution the
extract stage exists to prevent.
When the discovery stage ends, always stamp what it learned:
dims '{"source_platform_version":"...","source_extensions":["..."], "discovered_entity_types":["post","product","event"]}' — pass [] explicitly when
discovery found no extensions (or, improbably, no entity types); a null left behind is
flagged in telemetry_health as source_extensions_null_after_discovery /
discovered_entity_types_null_after_discovery. discovered_entity_types lists every
source entity class discovery found in use — including classes with no Wix target; it
is what finalize cross-checks the volumes rows against, so the "what we couldn't
import" demand signal cannot be silently under-reported.
wait start / wait end around every needs-user halt: credential requests, the
mapping-review checkpoint, the approval gate, any halt-to-needs-user. Pass the halt
class on the same call —
wait start --halt missing_input --skill rp-mapper --what "run halted at the mapping-review checkpoint awaiting approval"
— and the recorder emits the paired halt_needs_user event mechanically; a stalled
wait with no halt event in its stage is flagged in telemetry_health
(wait_without_halt_event:<stage>). If the session is about to end on a halt, leave
the wait open — the resume's start closes it, so overnight user latency lands in
waiting_ms where it belongs. If you resume real work while a wait is open (e.g.
investigating something before the user has answered), wait end first and
wait start again when you go back to waiting — active work must never be booked as
waiting.
record events as they happen (next section). Record in the moment, not
retrospectively — improvisation and halts are only reliably knowable when they occur.
digest --transcript <path to this session's CC transcript> just before finalize.
It parses the Claude Code session transcript, deterministically — no model, no
judgment, nothing for you to say. If it fails, carry on to finalize anyway;
telemetry never blocks a migration.
finalize once, at a terminal state, with the rollup:
node scripts/rp-telemetry.js finalize '{"terminal_state":"completed",
"volumes":[{"entity_type":"product","target":"native","target_surface":"stores/v3",
"discovered":142,"planned":142,"attempted":142,"succeeded":139,"failed":3,
"skipped":0,"already_imported":0}],
"verification":[{"subject":"product","method":"query_back","checked":10,"passed":10,"failed":0}],
"operator_acceptance":"accepted"}' --project <dir>
volumes come from the execution artifacts (manifest, audit log, crosswalk):
planned and target/target_surface from the approved plan;
already_imported is crosswalk-skipped scope from a prior attempt — never fold it
into skipped.
- Include a volume row for every entity type discovery found in use — including
types excluded by user decision or with no clean Wix target (
discovered: N, skipped: N, target: none where no target exists, planned 0 or null). "What we
cannot or chose not to import" must be signal-layer arithmetic, never an evidence
dig — rows only for imported types silently erase the excluded half of the approved
plan. This is enforced mechanically: on a completed run, any class stamped in
discovered_entity_types with no volume row is flagged
volume_row_missing:<type> in telemetry_health.
verification makes the finish step's spot-checks countable. checked: 0 is an
honest "written but unverified" — report it rather than papering over it.
- Do not finalize a halt you expect the user to resume — leave the run unfinalized
with the wait open. Finalize with
halted_needs_user only when the run is genuinely
being closed out in a stalled state. A user who declines the plan is
abandoned_by_user (plus a user_decision event with subtype: declined), never
halted_needs_user or failed.
- Check the returned
bi_push. If it reports failed > 0 or skipped > 0, the
run (or part of it) did not reach the central BI record: retry once with
rebuild --push, and if it still fails, tell the operator in the completion report
that the run exists only locally — never let a run silently vanish from the shared
record. skipped > 0 means RP_TELEMETRY_BI_DISABLED was set during the session;
on a real migration run that env var must never be set. A clean bi_push result
(failed: 0, skipped: 0) means the rows were handed to frog, not that they have
arrived in BI — per bi-sink.js's own transport code, a 2xx is not an ingestion
receipt; only a Trino read-back proves arrival, and no such read-back is available
from inside a run. Report bi_push success as "handed off," never as "confirmed in
BI."
Metering — splitting active_ms into where the time actually went
active_ms alone cannot locate a bottleneck: it is wall-clock between two stage boundaries, fusing
model reasoning + subprocess execution + remote API latency + defect-repair time into one
number. meter splits it, and cost is derived from the token counts.
# a generated script reporting its own measured work
node scripts/rp-telemetry.js meter --api-ms 250000 --api-calls 73 --api-retries 2 --script-ms 1200 --project <dir>
# the agent runtime reporting its own usage for the stage it just finished
node scripts/rp-telemetry.js meter --model-ms 42000 --input-tokens 8000 --output-tokens 1500 --cache-read-tokens 120000 --project <dir>
Derive the API half mechanically — do not hand-count it. After a generated import runs:
node scripts/meter-from-audit.js --project <migration dir> --stage import # --dry-run to preview
It reads logs/import-audit.ndjson and emits measured api_ms / api_calls / api_retries.
It exists because a bulk write logs one audit row per item, each carrying the batch's total
latency — summing rows multiplies one call's latency by its item count, which on a real run
reported 1,050,992 ms of API time inside a stage that only existed for 346,505 ms. The helper
collapses rows per distinct (runId, endpoint, batch, latencyMs), so a batch counts once while
genuinely separate calls each count.
Fields: durations model_ms / api_ms / script_ms; counts input_tokens, output_tokens,
cache_read_tokens, cache_write_tokens, api_calls, api_retries. Defaults to the open stage;
--stage <stage> targets another. Repeated calls accumulate, so each script invocation and each
stage re-entry reports independently.
Rules that keep the numbers trustworthy:
- Measure, never estimate. Every field is a number something actually observed — a script's own
elapsed time, an audit log's summed
latencyMs, the runtime's reported usage. If you do not have
a measurement, omit the field; the gap is reported as unattributed_ms and flagged, which is far
more useful than a guess.
- Do not meter the same interval twice. Meters sum, so re-reporting a stage's API time after a
resume double-counts it. The recorder flags
stage_over_attributed:<stage> when attributed time
exceeds elapsed time, because unattributed_ms clamps at zero and would otherwise hide it.
- Cost is derived, never recorded. Pass
model_pricing_snapshot in the start dims
({ "<model>": { "input_per_mtok": 15, "output_per_mtok": 75, "cache_read_per_mtok": 1.5 } }) and
the rollup computes cost.estimated_cost_usd. A stored dollar figure silently goes wrong when list
prices change; tokens plus a dated snapshot stay recomputable. Without a snapshot, cost is null
with cost_basis: "no_pricing_snapshot" — never a fabricated number.
contained_recovery is derived, not self-reported. Any error or pipeline_defect in a stage
marks it, because a stage that spent its time debugging is the one an agent is least likely to
remember to flag. timing.stages_with_recovery lists them, so a clean run and a thrash are
distinguishable instead of both reading as "this is what the stage costs".
The rollup's timing.agentic_ms vs timing.deterministic_ms (and agentic_share) is the number
that shows whether moving work into deterministic code is paying off. agentic_share is null when
nothing was metered rather than 0, which would falsely read as a fully deterministic run.
Collecting operator_acceptance
At the finish handoff, ask the operator one plain question: does the migrated result look
right to them — accepted, rework_needed, or rejected? Record their answer in
finalize. If the run never reaches finish or they do not answer, it stays unknown.
This is the only field separating "completed and good" from "completed and unusable" —
ask it, but never pressure or interpret; their verdict as given, coarse by design.
Event taxonomy — when to record what
Events are folded per problem class by the recorder (same type + stage + entity type +
API surfaces + app + error code + subtype fold into one event with a count), so record
every occurrence class once and pass count when you observed many at once — e.g. a
generated script reporting 4,000 identical write failures is one record call with
"count": 4000. Distinct problems are distinct subtypes or error codes, not bigger
counts.
Every event needs: event_type, stage (defaults to the open stage), skill (the
active rp-* resource, e.g. "rp-mapper"), severity (blocking | degraded |
cosmetic | info), and what_happened. Add entity_type, wix_api_surface (e.g.
stores/v3), source_api_surface (endpoint class like wp/v2/posts — never a URL),
wix_app_id, and error_code whenever they apply — they are the cross-run group-by keys.
halt_needs_user — the run stopped at a defined needs-user state. Prefer the
mechanical form — wait start --halt <subtype> … emits it for you (lifecycle step 3);
record it yourself only for a halt with no wait interval. subtype: missing_input
(missing/invalid required input or credential) | manual_only (genuinely manual step,
no API) | systemic_failure (systemic failure or data-loss risk).
manual_action_required — the execution plan flagged something as "can't be done,
needs manual action" (e.g. a storage-plan upgrade), whether or not the run halted on
it. subtype: plan_or_billing | dashboard_only | external_dependency | other.
error — an API or script error, including recovered ones. Carry error_code
(required — it is the discriminator; no subtype), retry_count, and recovered.
Record one event per resolved retry chain, after the outcome is known — the final
recovered, the total retry_count — never one call per attempt (per-attempt calls
fold into one class, and the failing first attempt's fields would bury the recovery).
When recovery required a change (not just a retry), actual must record what
change made it succeed, as an observation: "retried with the description as plain
text instead of HTML; the write succeeded" — never "the fix is X". If that change
deviated from the documented path — including a change to a planned command or
value, like simplifying an input the plan specified — also emit a paired
skill_coverage_gap (undocumented_workaround).
fidelity_loss — the migration technically proceeded but lost something.
subtype: dropped_field | unverified_enum | no_target (source entity with no
clean Wix target) | coerced_value. For a loss triggered by specific records, inline
the offending record's sanitized shape in observed_shapes — field names and
types and which field was dropped/coerced, never values.
api_gap — a missing or insufficient Wix API capability. subtype:
missing_api | missing_capability (API exists but cannot express the operation) |
internal_only (capability exists but is not publicly exposed) | other. Carry
wix_api_surface (required) and error_code — that signature is matched centrally
across runs. Never write to any backlog file; the event is the whole per-run
obligation.
skill_coverage_gap — the standing self-report, and the highest-value signal
for improving the skills. Whenever you act beyond what the active skill explicitly
told you to do — you guess a value, work around a missing instruction, resolve an
ambiguity by judgment, or handle a case the skill does not cover — record it at that
moment. subtype: guessed_value | undocumented_workaround |
ambiguous_instruction | path_not_covered. Describe the situation and the action
taken as an observation: "skill did not specify which enum value maps to X, so a value
was chosen to proceed" — never "the skill should add Y". If you are unsure whether
something counts as improvisation, it does — record it.
user_decision — the user's answer at every defined checkpoint or fork: the
mapping-review checkpoint, the approval gate, and intake forks (comments
anonymization, delivery mode, media reachability, …). subtype: accepted |
declined | deferred | amended; decision_point (required) names the fork, e.g.
mapping_review, approval_gate, comments_anonymization. Record the decision, not
the user's reasoning verbatim. An amended acceptance whose change exposed a mapping
problem additionally surfaces that problem as fidelity_loss or
skill_coverage_gap. A declined at a terminal checkpoint pairs with
terminal_state: abandoned_by_user.
pipeline_defect — our own migration machinery misbehaved: not a Wix API error,
not a source failure, not your improvisation. subtype: state_inconsistency (two
pipeline state artifacts disagree) | ordering_violation (a step ran before its
prerequisite's output existed) | record_defect (a pipeline record/log is malformed
or misleading as evidence) | other. Name the artifacts and their states in
what_happened — names and states, never contents.
source_plugin_coverage — which of the source site's plugins we could not resolve,
plus one run-level summary. Record after discovery writes
discovery/plugin-coverage.json.
Record one event per unresolved item only. The unresolved set is: every pending row
(including reason: cannot-tell and unread candidate namespaces), every
requires-development row, and every row carrying blocked[] entries (a
user-file / credential / surface-changed blocker, declined or not). These are the
whole point of this event type — they are the only signal that says which plugin profile
to write next, and without them that ordering is guesswork.
Do not emit a per-row event for anything already resolved: migration-planned rows
with confidence: confirmed, or no-need-to-migrate rows with basis: list or
basis: decision (a human already signed that verdict). On a
55-plugin store that would be ~29 events restating a checked-in list — telemetry with no
information content, which makes the real backlog harder to see, not easier. (A
migration-planned or no-need-to-migrate row that automation derived —
confidence: proposed / basis: proposed — is reported through skill_coverage_gap
(guessed_value), not here.)
Emit exactly one aggregate event per run carrying the distribution: plugins installed,
counts by the four statuses (and by via / confidence for planned rows), blocked counts
by kind, and whether the plugin list was available. That preserves the cross-run view of
how coverage is trending without one event per plugin.
Per-event fields: subtype is the row's status (pending | requires_development) or
blocked for a blocker entry (then also carry the blocker kind); carry the plugin slug
and version, the capability, the read channel, whether the row was recognized, and
source_api_surface as the endpoint class. Slug and version are required — without them
a cross-run view cannot tell which plugin caused what. Plugin slugs and versions are
software identifiers, not client data; still never record site URLs or record contents.
A requires-development row additionally pairs with api_gap, and a lossy via: cms row
with fidelity_loss — this event reports distribution and backlog, never the gap itself.
evidence_refs — rare, not routine
Author every event to be self-sufficient: coded fields + bounded free text +
observed_shapes should let a reviewer triage it without opening any artifact. Add
evidence_refs ({"artifact":"execution-log.md","locator":"## Import"}) only for the
exceptional event whose signal genuinely cannot carry the full observation. Use
project-root-relative paths and prefer section headings as locators (line ranges break
when files regenerate). Never reference secret-bearing config files.
What never to do
- Never hand-write, edit, or re-read
run-telemetry.json or telemetry/ files — the
recorder appends; you only call it.
- Never record client data values, names, URLs beyond the recorded source origin, or
secrets — in any field, including shapes and locators.
- Never record a fix, root cause, or recommendation — observations only.
- Never estimate durations — timing comes from
stage/wait boundary calls.
- Never skip a rejected call: fix the listed fields and retry. Rejections are counted
against telemetry health either way.
- Never create or update improvement/feature-request backlog files during a run — those
are maintained centrally from many runs' telemetry, not per run.
- Never delete or trim project artifacts for telemetry reasons — capture is a
non-destructive view; size is not a reason to drop anything.
1---2name: rp-telemetry3description: Always-active telemetry companion for RePlatform migration runs. Records what happened during a run — halts, errors, fidelity losses, API gaps, skill coverage gaps, user decisions, pipeline defects — through a validated recorder script, plus the run rollup (stages, timings, volumes, verification). Loaded by the orchestrator at run start and kept active for the whole run.4---56# rp-telemetry78Capture per-run telemetry that tells us what to improve in the skills and the underlying9Wix tooling. This skill stays active alongside the migration skills for the **entire**10run; the migration skills themselves are unchanged and know nothing about telemetry.1112## The one rule that governs everything you record1314**Observation, not diagnosis.** Every field records what was observed — what happened,15what was expected, what actually occurred, where, and how often. Never record a root16cause, a fix, a recommendation, or a workaround-as-solution. There is deliberately no17field for them; the schema rejects unknown fields. Root cause is derived later, at review18time, by a reviewing agent with full context — not asserted by you in the moment.1920Three discipline rules apply to every free-text field (`what_happened`, `expected`,21`actual`):2223- **Types, not instances.** Refer to entity *types* and *classes*, never specific client24 data. `entity_type: "product"` — never a product's name, SKU, price, or body text.25- **Secret-safe.** No credentials, tokens, URLs, config values, or file contents — the26 recorder also runs a mechanical scrub as a last line of defense, but do not rely on it.27- **Short and structural.** A sentence or two, max 400 chars. Prefer stating28 expected-vs-actual over narrating. The coded fields carry the structure.29- **No remediation narration.** "The canonical lib was fixed and re-synced" is a fix30 story, not an observation — even when true (dev-mode backports). Record what was31 observed to work ("adding fieldsets=FULL returned the field; the lookup succeeded")32 and leave the repair to the execution log.3334## The recorder3536All telemetry is persisted through the bundled recorder — **never hand-write or edit37`run-telemetry.json` or `telemetry/` files.** Run it from this resource directory38(see `CONVENTIONS.md`), pointing at the active migration project:3940```bash41node scripts/rp-telemetry.js <command> [...] --project <abs path to migrations/<project>>42```4344The recorder owns everything mechanical: schema validation (it rejects invalid enums and45unknown fields — fix and retry, never guess around it), timestamps, per-class event46folding, the run/attempt/session resume model, the privacy scrub, and the well-formedness47gate at finalize. It prints one JSON result per call; `{"ok":false,...}` lists exactly48what to fix.4950| Call | When |51|---|---|52| `start '<dims-json>'` | At run begin — before any other pipeline step. Resumes an unfinalized run automatically. |53| `dims '<dims-json>'` | Whenever a dimension becomes known mid-run (platform version and extensions after discovery, `site_id` after provisioning). |54| `stage start <stage>` / `stage end <stage> --outcome <outcome>` | At every stage boundary. Outcomes: `passed`, `halted`, `failed`, `skipped`. |55| `meter [--api-ms N --model-ms N --script-ms N --input-tokens N …]` | Measured latency/token counts for a stage. Call it whenever you have real numbers; see "Metering" below. |56| `wait start [--halt <subtype> --skill <s> [--what '<text>']]` / `wait end` | The moment the run halts for the user, and the moment it resumes. This is how user latency stays out of `active_ms` — never estimate elapsed time yourself. Pass `--halt` for a needs-user halt and the recorder emits the paired `halt_needs_user` event for you. |57| `record '<event-json>'` | The moment something observable happens (taxonomy below). |58| `digest --transcript <path> [--offline]` | Just before `finalize` — a deterministic parse of this run's Claude Code session transcript (cost, turn counts, tool failures, retry loops, hook errors). Never authored by you; `--offline` re-runs it later against a checkpointed or local transcript for a run that died before calling it. |59| `finalize '<rollup-json>'` | When the run reaches a terminal state. |60| `rebuild [--attempt <n>] [--push]` | Only on request, to re-assemble a past run's signal document from its archived journal after a recorder fix — never during a run. `--push` re-emits the rebuilt run to the BI sink (backfill after an outage; idempotent — the reviewer dedupes at query time). |61| `status` | To orient after a resume. |6263### Run lifecycle64651. **`start`** as the first telemetry act of the run, with whatever dimensions are already66 known:6768 ```bash69 node scripts/rp-telemetry.js start '{"source_platform":"wordpress",70 "source_site_url":"https://client-site.example","source_acquisition":"public_storefront",71 "delivery_mode":"management","destination_strategy":"new_site",72 "runtime_env":{"agent_runtime":"claude-code","model":"<model id>"}}' --project <dir>73 ```7475 `start` on a project with an unfinalized run **resumes** it (same run, same attempt,76 one more session) and closes any open wait interval. `start` after a finalized run77 opens the next attempt. Never try to manage run identity yourself.7879 **Always `start` on resume, even mid-stage.** Besides the session accounting, the80 resume is a BI heal point: the recorder re-pushes everything the previous session's81 transport may have lost (push failures are journaled, then healed at the next82 opportunity — a halted run may never reach finalize, so skipping the resume `start`83 can strand the run's tail in the local journal). `status` shows `bi_backlog: true`84 when unpushed rows are pending.8586 `source_acquisition` is an open set of class tokens, but reuse an established one87 (`admin_api`, `public_storefront`, `public_content`, `file_export`) rather than88 minting a synonym — cross-run folding depends on stable tokens.8990 **Skills provenance is auto-stamped — you don't pass it.** At `start` the recorder91 stamps two identifiers onto the run so every record can be traced back to the skills92 that produced it:9394 - `skills_version` — the bundle's semver release label (from `VERSION`). Coarse and95 hand-bumped by design; it is the group-by/order-by key that binds issues to a96 *release line* ("all issues on 1.2.x", "regressed since 1.1.0").97 - `skills_commit` — the exact source commit the bundle was built from: the precise98 *vendored snapshot* within a release. Many commits ship under one hand-bumped99 `skills_version`, so a run reporting `1.0.0` is otherwise unattributable to the100 change that produced its issue. The recorder resolves it, in order of authority,101 from the `sourceCommit` stamped into `.publish-manifest.json` at publish time (the102 only source that works in a partner runtime, and the only correct one once the103 bundle is vendored into `wix/skills`), else a dev-mode `git rev-parse --short HEAD`104 of the source checkout, else `null`.105106 Both may be overridden by passing `skills_version` / `skills_commit` in the `start`107 dims (a runtime with better provenance than the recorder can infer), but normally you108 leave them to auto-resolve.1091102. **Stage boundaries** as the pipeline moves. Map orchestrator steps to stages like this:111112 | Stage | Covers |113 |---|---|114 | `config` | Everything before discovery: project resolution, config files, up-front input collection |115 | `discovery` | Source discovery (`rp-discovery` + source adapter) |116 | `mcp_gate` | The Wix MCP prerequisite gate between discovery and mapping |117 | `mapping` | `rp-mapper` producing the mapping plan |118 | `mapping_review` | The mapping review checkpoint (user-facing) |119 | `setup_discovery` | `rp-setup-discovery` |120 | `codegen` | `rp-import-codegen` |121 | `approval_gate` | The execution-plan approval gate (user-facing) |122 | `setup_provisioning` | Site creation, app installs, collections — `rp-execute-setup` |123 | `storefront_build` | The `website`-mode `wix-headless` build + release; `skipped` in `management` mode |124 | `extract` | Source extraction to disk, before any write (`rp-execute-import`) |125 | `import` | The import writes (`rp-execute-import`) |126 | `finish` | Verification spot-checks, completion reporting, handoff |127128 Stages bind to **when the work actually runs**, not to their canonical order. If the129 orchestration runs extraction early (e.g. extract + dry-run before the approval gate,130 inside the codegen phase), close the open stage, bracket the extraction in its own131 `extract` stage, then reopen — a stage may be entered more than once, and its132 `active_ms` sums the entries. Booking a real extraction into `codegen` (and leaving133 `extract` as a milliseconds-long token stage) is exactly the mis-attribution the134 `extract` stage exists to prevent.135136 When the `discovery` stage ends, **always** stamp what it learned:137 `dims '{"source_platform_version":"...","source_extensions":["..."],138 "discovered_entity_types":["post","product","event"]}'` — pass `[]` explicitly when139 discovery found no extensions (or, improbably, no entity types); a null left behind is140 flagged in `telemetry_health` as `source_extensions_null_after_discovery` /141 `discovered_entity_types_null_after_discovery`. `discovered_entity_types` lists every142 source entity class discovery found in use — including classes with no Wix target; it143 is what finalize cross-checks the `volumes` rows against, so the "what we couldn't144 import" demand signal cannot be silently under-reported.1451463. **`wait start` / `wait end`** around every needs-user halt: credential requests, the147 mapping-review checkpoint, the approval gate, any halt-to-needs-user. Pass the halt148 class on the same call —149 `wait start --halt missing_input --skill rp-mapper --what "run halted at the mapping-review checkpoint awaiting approval"`150 — and the recorder emits the paired `halt_needs_user` event mechanically; a stalled151 wait with no halt event in its stage is flagged in `telemetry_health`152 (`wait_without_halt_event:<stage>`). If the session is about to end on a halt, leave153 the wait open — the resume's `start` closes it, so overnight user latency lands in154 `waiting_ms` where it belongs. If you resume real work while a wait is open (e.g.155 investigating something before the user has answered), `wait end` first and156 `wait start` again when you go back to waiting — active work must never be booked as157 waiting.1581594. **`record`** events as they happen (next section). Record in the moment, not160 retrospectively — improvisation and halts are only reliably knowable when they occur.1611625. **`digest --transcript <path to this session's CC transcript>`** just before `finalize`.163 It parses the Claude Code session transcript, deterministically — no model, no164 judgment, nothing for you to say. If it fails, carry on to `finalize` anyway;165 telemetry never blocks a migration.1661676. **`finalize`** once, at a terminal state, with the rollup:168169 ```bash170 node scripts/rp-telemetry.js finalize '{"terminal_state":"completed",171 "volumes":[{"entity_type":"product","target":"native","target_surface":"stores/v3",172 "discovered":142,"planned":142,"attempted":142,"succeeded":139,"failed":3,173 "skipped":0,"already_imported":0}],174 "verification":[{"subject":"product","method":"query_back","checked":10,"passed":10,"failed":0}],175 "operator_acceptance":"accepted"}' --project <dir>176 ```177178 - `volumes` come from the execution artifacts (manifest, audit log, crosswalk):179 `planned` and `target`/`target_surface` from the **approved** plan;180 `already_imported` is crosswalk-skipped scope from a prior attempt — never fold it181 into `skipped`.182 - Include a volume row for **every** entity type discovery found in use — including183 types excluded by user decision or with no clean Wix target (`discovered: N,184 skipped: N`, `target: none` where no target exists, `planned` 0 or null). "What we185 cannot or chose not to import" must be signal-layer arithmetic, never an evidence186 dig — rows only for imported types silently erase the excluded half of the approved187 plan. This is enforced mechanically: on a completed run, any class stamped in188 `discovered_entity_types` with no volume row is flagged189 `volume_row_missing:<type>` in `telemetry_health`.190 - `verification` makes the finish step's spot-checks countable. `checked: 0` is an191 honest "written but unverified" — report it rather than papering over it.192 - Do **not** finalize a halt you expect the user to resume — leave the run unfinalized193 with the wait open. Finalize with `halted_needs_user` only when the run is genuinely194 being closed out in a stalled state. A user who declines the plan is195 `abandoned_by_user` (plus a `user_decision` event with `subtype: declined`), never196 `halted_needs_user` or `failed`.197 - **Check the returned `bi_push`.** If it reports `failed > 0` or `skipped > 0`, the198 run (or part of it) did not reach the central BI record: retry once with199 `rebuild --push`, and if it still fails, tell the operator in the completion report200 that the run exists only locally — never let a run silently vanish from the shared201 record. `skipped > 0` means `RP_TELEMETRY_BI_DISABLED` was set during the session;202 on a real migration run that env var must never be set. **A clean `bi_push` result203 (`failed: 0`, `skipped: 0`) means the rows were handed to frog, not that they have204 arrived in BI** — per `bi-sink.js`'s own transport code, a 2xx is not an ingestion205 receipt; only a Trino read-back proves arrival, and no such read-back is available206 from inside a run. Report `bi_push` success as "handed off," never as "confirmed in207 BI."208209### Metering — splitting `active_ms` into where the time actually went210211`active_ms` alone cannot locate a bottleneck: it is wall-clock between two stage boundaries, fusing212**model reasoning + subprocess execution + remote API latency + defect-repair time** into one213number. `meter` splits it, and cost is derived from the token counts.214215```bash216# a generated script reporting its own measured work217node scripts/rp-telemetry.js meter --api-ms 250000 --api-calls 73 --api-retries 2 --script-ms 1200 --project <dir>218# the agent runtime reporting its own usage for the stage it just finished219node scripts/rp-telemetry.js meter --model-ms 42000 --input-tokens 8000 --output-tokens 1500 --cache-read-tokens 120000 --project <dir>220```221222**Derive the API half mechanically — do not hand-count it.** After a generated import runs:223224```bash225node scripts/meter-from-audit.js --project <migration dir> --stage import # --dry-run to preview226```227228It reads `logs/import-audit.ndjson` and emits measured `api_ms` / `api_calls` / `api_retries`.229It exists because a bulk write logs **one audit row per item, each carrying the batch's total230latency** — summing rows multiplies one call's latency by its item count, which on a real run231reported 1,050,992 ms of API time inside a stage that only existed for 346,505 ms. The helper232collapses rows per distinct `(runId, endpoint, batch, latencyMs)`, so a batch counts once while233genuinely separate calls each count.234235Fields: durations `model_ms` / `api_ms` / `script_ms`; counts `input_tokens`, `output_tokens`,236`cache_read_tokens`, `cache_write_tokens`, `api_calls`, `api_retries`. Defaults to the open stage;237`--stage <stage>` targets another. Repeated calls **accumulate**, so each script invocation and each238stage re-entry reports independently.239240Rules that keep the numbers trustworthy:241242- **Measure, never estimate.** Every field is a number something actually observed — a script's own243 elapsed time, an audit log's summed `latencyMs`, the runtime's reported usage. If you do not have244 a measurement, omit the field; the gap is reported as `unattributed_ms` and flagged, which is far245 more useful than a guess.246- **Do not meter the same interval twice.** Meters sum, so re-reporting a stage's API time after a247 resume double-counts it. The recorder flags `stage_over_attributed:<stage>` when attributed time248 exceeds elapsed time, because `unattributed_ms` clamps at zero and would otherwise hide it.249- **Cost is derived, never recorded.** Pass `model_pricing_snapshot` in the `start` dims250 (`{ "<model>": { "input_per_mtok": 15, "output_per_mtok": 75, "cache_read_per_mtok": 1.5 } }`) and251 the rollup computes `cost.estimated_cost_usd`. A stored dollar figure silently goes wrong when list252 prices change; tokens plus a dated snapshot stay recomputable. Without a snapshot, cost is `null`253 with `cost_basis: "no_pricing_snapshot"` — never a fabricated number.254- **`contained_recovery` is derived, not self-reported.** Any `error` or `pipeline_defect` in a stage255 marks it, because a stage that spent its time debugging is the one an agent is least likely to256 remember to flag. `timing.stages_with_recovery` lists them, so a clean run and a thrash are257 distinguishable instead of both reading as "this is what the stage costs".258259The rollup's `timing.agentic_ms` vs `timing.deterministic_ms` (and `agentic_share`) is the number260that shows whether moving work into deterministic code is paying off. `agentic_share` is `null` when261nothing was metered rather than `0`, which would falsely read as a fully deterministic run.262263### Collecting `operator_acceptance`264265At the finish handoff, ask the operator one plain question: does the migrated result look266right to them — `accepted`, `rework_needed`, or `rejected`? Record their answer in267`finalize`. If the run never reaches finish or they do not answer, it stays `unknown`.268This is the only field separating "completed and good" from "completed and unusable" —269ask it, but never pressure or interpret; their verdict as given, coarse by design.270271## Event taxonomy — when to record what272273Events are folded per problem class by the recorder (same type + stage + entity type +274API surfaces + app + error code + subtype fold into one event with a `count`), so record275every occurrence class once and pass `count` when you observed many at once — e.g. a276generated script reporting 4,000 identical write failures is **one** `record` call with277`"count": 4000`. Distinct problems are distinct subtypes or error codes, not bigger278counts.279280Every event needs: `event_type`, `stage` (defaults to the open stage), `skill` (the281active `rp-*` resource, e.g. `"rp-mapper"`), `severity` (`blocking` | `degraded` |282`cosmetic` | `info`), and `what_happened`. Add `entity_type`, `wix_api_surface` (e.g.283`stores/v3`), `source_api_surface` (endpoint class like `wp/v2/posts` — never a URL),284`wix_app_id`, and `error_code` whenever they apply — they are the cross-run group-by keys.2852861. **`halt_needs_user`** — the run stopped at a defined needs-user state. Prefer the287 mechanical form — `wait start --halt <subtype> …` emits it for you (lifecycle step 3);288 record it yourself only for a halt with no wait interval. `subtype`: `missing_input`289 (missing/invalid required input or credential) | `manual_only` (genuinely manual step,290 no API) | `systemic_failure` (systemic failure or data-loss risk).2912922. **`manual_action_required`** — the execution plan flagged something as "can't be done,293 needs manual action" (e.g. a storage-plan upgrade), whether or not the run halted on294 it. `subtype`: `plan_or_billing` | `dashboard_only` | `external_dependency` | `other`.2952963. **`error`** — an API or script error, including recovered ones. Carry `error_code`297 (required — it is the discriminator; no subtype), `retry_count`, and `recovered`.298 Record **one event per resolved retry chain**, after the outcome is known — the final299 `recovered`, the total `retry_count` — never one call per attempt (per-attempt calls300 fold into one class, and the failing first attempt's fields would bury the recovery).301 When recovery required a *change* (not just a retry), `actual` must record **what302 change made it succeed**, as an observation: "retried with the description as plain303 text instead of HTML; the write succeeded" — never "the fix is X". If that change304 deviated from the documented path — including a change to a *planned command or305 value*, like simplifying an input the plan specified — also emit a paired306 `skill_coverage_gap` (`undocumented_workaround`).3073084. **`fidelity_loss`** — the migration technically proceeded but lost something.309 `subtype`: `dropped_field` | `unverified_enum` | `no_target` (source entity with no310 clean Wix target) | `coerced_value`. For a loss triggered by specific records, inline311 the offending record's **sanitized shape** in `observed_shapes` — field names and312 types and which field was dropped/coerced, never values.3133145. **`api_gap`** — a missing or insufficient Wix API capability. `subtype`:315 `missing_api` | `missing_capability` (API exists but cannot express the operation) |316 `internal_only` (capability exists but is not publicly exposed) | `other`. Carry317 `wix_api_surface` (required) and `error_code` — that signature is matched centrally318 across runs. **Never write to any backlog file; the event is the whole per-run319 obligation.**3203216. **`skill_coverage_gap`** — **the standing self-report, and the highest-value signal322 for improving the skills.** Whenever you act beyond what the active skill explicitly323 told you to do — you guess a value, work around a missing instruction, resolve an324 ambiguity by judgment, or handle a case the skill does not cover — record it **at that325 moment**. `subtype`: `guessed_value` | `undocumented_workaround` |326 `ambiguous_instruction` | `path_not_covered`. Describe the situation and the action327 taken as an observation: "skill did not specify which enum value maps to X, so a value328 was chosen to proceed" — never "the skill should add Y". If you are unsure whether329 something counts as improvisation, it does — record it.3303317. **`user_decision`** — the user's answer at every defined checkpoint or fork: the332 mapping-review checkpoint, the approval gate, and intake forks (comments333 anonymization, delivery mode, media reachability, …). `subtype`: `accepted` |334 `declined` | `deferred` | `amended`; `decision_point` (required) names the fork, e.g.335 `mapping_review`, `approval_gate`, `comments_anonymization`. Record the decision, not336 the user's reasoning verbatim. An `amended` acceptance whose change exposed a mapping337 problem additionally surfaces that problem as `fidelity_loss` or338 `skill_coverage_gap`. A `declined` at a terminal checkpoint pairs with339 `terminal_state: abandoned_by_user`.3403418. **`pipeline_defect`** — our own migration machinery misbehaved: not a Wix API error,342 not a source failure, not your improvisation. `subtype`: `state_inconsistency` (two343 pipeline state artifacts disagree) | `ordering_violation` (a step ran before its344 prerequisite's output existed) | `record_defect` (a pipeline record/log is malformed345 or misleading as evidence) | `other`. Name the artifacts and their states in346 `what_happened` — names and states, never contents.3473489. **`source_plugin_coverage`** — which of the source site's plugins we could **not** resolve,349 plus one run-level summary. Record after discovery writes350 `discovery/plugin-coverage.json`.351352 **Record one event per unresolved item only.** The unresolved set is: every `pending` row353 (including `reason: cannot-tell` and unread candidate namespaces), every354 `requires-development` row, and every row carrying `blocked[]` entries (a355 `user-file` / `credential` / `surface-changed` blocker, declined or not). **These are the356 whole point of this event type** — they are the only signal that says which plugin profile357 to write next, and without them that ordering is guesswork.358359 **Do not emit a per-row event for anything already resolved**: `migration-planned` rows360 with `confidence: confirmed`, or `no-need-to-migrate` rows with `basis: list` or361 `basis: decision` (a human already signed that verdict). On a362 55-plugin store that would be ~29 events restating a checked-in list — telemetry with no363 information content, which makes the real backlog harder to see, not easier. (A364 `migration-planned` or `no-need-to-migrate` row that automation *derived* —365 `confidence: proposed` / `basis: proposed` — is reported through `skill_coverage_gap`366 (`guessed_value`), not here.)367368 **Emit exactly one aggregate event per run** carrying the distribution: plugins installed,369 counts by the four statuses (and by `via` / `confidence` for planned rows), blocked counts370 by kind, and whether the plugin list was available. That preserves the cross-run view of371 how coverage is trending without one event per plugin.372373 Per-event fields: `subtype` is the row's status (`pending` | `requires_development`) or374 `blocked` for a blocker entry (then also carry the blocker `kind`); carry the plugin slug375 and version, the capability, the read channel, whether the row was `recognized`, and376 `source_api_surface` as the endpoint class. Slug and version are required — without them377 a cross-run view cannot tell which plugin caused what. Plugin slugs and versions are378 software identifiers, not client data; still never record site URLs or record contents.379380 A `requires-development` row additionally pairs with `api_gap`, and a lossy `via: cms` row381 with `fidelity_loss` — this event reports *distribution and backlog*, never the gap itself.382383### `evidence_refs` — rare, not routine384385Author every event to be **self-sufficient**: coded fields + bounded free text +386`observed_shapes` should let a reviewer triage it without opening any artifact. Add387`evidence_refs` (`{"artifact":"execution-log.md","locator":"## Import"}`) only for the388exceptional event whose signal genuinely cannot carry the full observation. Use389project-root-relative paths and prefer section headings as locators (line ranges break390when files regenerate). Never reference secret-bearing config files.391392## What never to do393394- Never hand-write, edit, or re-read `run-telemetry.json` or `telemetry/` files — the395 recorder appends; you only call it.396- Never record client data values, names, URLs beyond the recorded source origin, or397 secrets — in any field, including shapes and locators.398- Never record a fix, root cause, or recommendation — observations only.399- Never estimate durations — timing comes from `stage`/`wait` boundary calls.400- Never skip a rejected call: fix the listed fields and retry. Rejections are counted401 against telemetry health either way.402- Never create or update improvement/feature-request backlog files during a run — those403 are maintained centrally from many runs' telemetry, not per run.404- Never delete or trim project artifacts for telemetry reasons — capture is a405 non-destructive view; size is not a reason to drop anything.