@swmansion/argent 0.15.0 → 0.15.1-next.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.
@@ -2913,6 +2913,7 @@
2913
2913
  const opPillCount = document.getElementById("op-pill-count");
2914
2914
  const revealOffscreenChoices = () => {
2915
2915
  vp.revealOffscreen = true;
2916
+ vp.offscreenRevealed = true; // sticky per-round usage flag for telemetry
2916
2917
  vpRender();
2917
2918
  };
2918
2919
  opShow.addEventListener("click", () => {
@@ -2960,7 +2961,19 @@
2960
2961
  // While the server still reports this round (the agent hasn't opened a new
2961
2962
  // one yet) we hide its proposals/comments so "Request changes" feels final.
2962
2963
  sentRound: -1,
2964
+ // Last round for which we posted the lens:preview_opened trigger. Locally
2965
+ // dedups the ~1.2s poll so we post once per round we actually render in a
2966
+ // visible window (the server dedups across tabs too). See reportPreviewOpened.
2967
+ openReportedRound: -1,
2963
2968
  inspect: false,
2969
+ // Sticky per-round usage flags for telemetry (reset when a new round
2970
+ // loads / after a CLI submit). inspectorUsed: the human opened the
2971
+ // "Add comment" inspector at least once this round (distinct from
2972
+ // `inspect`, the live toggle, which is false again after they close it).
2973
+ // offscreenRevealed: they clicked "Show them"/the pill to reveal
2974
+ // off-screen choices. Both ride the submit POST → lens:round_completed.
2975
+ inspectorUsed: false,
2976
+ offscreenRevealed: false,
2964
2977
  focus: null, // describe node currently spotlighted
2965
2978
  commentFor: null, // describe node a comment-pop is open for
2966
2979
  spot: null, // spotlight layer root (child of mainEl)
@@ -3261,6 +3274,8 @@
3261
3274
  vp.anchors = {};
3262
3275
  vp.revealOffscreen = false;
3263
3276
  vp.offscreenPromptCollapsed = false;
3277
+ vp.inspectorUsed = false; // new round → reset per-round usage flags
3278
+ vp.offscreenRevealed = false;
3264
3279
  if (globalCommentEl) globalCommentEl.value = "";
3265
3280
  if (vp.justCompletedRound === snap.round) {
3266
3281
  /* keep our own success note */
@@ -3290,8 +3305,42 @@
3290
3305
  /* keep last state */
3291
3306
  }
3292
3307
  vpRender();
3308
+ // A human is looking at this round → emit the lens:preview_opened trigger
3309
+ // (deduped locally + server-side per round). Runs after the render so the
3310
+ // round we report is the one now on screen.
3311
+ reportPreviewOpened();
3293
3312
  }
3294
3313
 
3314
+ // Tell the server a human opened/rendered the current round in a VISIBLE
3315
+ // window — the source of `lens:preview_opened`. Gated on visibility so a
3316
+ // forgotten BACKGROUND tab (which keeps polling /variants) never claims an
3317
+ // open with nobody looking, and deduped per round so the ~1.2s poll and
3318
+ // multiple tabs collapse to one. Posts only the round as a trigger; the
3319
+ // server reads the counts/platform from its own snapshot. Fires again on
3320
+ // visibilitychange so a tab foregrounded onto a not-yet-reported round
3321
+ // counts the moment the human actually looks at it.
3322
+ function reportPreviewOpened() {
3323
+ if (document.visibilityState !== "visible") return;
3324
+ const round = vp.round;
3325
+ if (round < 0 || round === vp.openReportedRound) return;
3326
+ // Only a live round is an "open": staged proposals, or a CLI session whose
3327
+ // window is opened up front before any proposal. (Mirrors the server gate.)
3328
+ const liveRound = (vp.proposals && vp.proposals.length > 0) || vp.cliSession;
3329
+ if (!liveRound) return;
3330
+ vp.openReportedRound = round;
3331
+ fetch(`${TOOL_SERVER}/preview/opened`, {
3332
+ method: "POST",
3333
+ headers: { "Content-Type": "application/json" },
3334
+ body: JSON.stringify({ round }),
3335
+ keepalive: true,
3336
+ }).catch(() => {
3337
+ // Best-effort telemetry trigger — a miss just drops one open signal, so
3338
+ // roll back the local dedup and let the next poll re-attempt.
3339
+ if (vp.openReportedRound === round) vp.openReportedRound = -1;
3340
+ });
3341
+ }
3342
+ document.addEventListener("visibilitychange", reportPreviewOpened);
3343
+
3295
3344
  // ── Agent picker (CLI Lens session) ─────────────────────────────────
3296
3345
  // The `argent lens` bridge offers a list of installed agents when more
3297
3346
  // than one is present; the human clicks one and the bridge spawns it.
@@ -4615,6 +4664,7 @@
4615
4664
  }
4616
4665
  function setInspect(on) {
4617
4666
  vp.inspect = on;
4667
+ if (on) vp.inspectorUsed = true; // sticky per-round usage flag for telemetry
4618
4668
  commentBtn.classList.toggle("active", on);
4619
4669
  const commentLabel = on ? "Done commenting" : "Add comment";
4620
4670
  commentBtn.title = commentLabel;
@@ -5221,6 +5271,11 @@
5221
5271
  method: "POST",
5222
5272
  headers: { "Content-Type": "application/json" },
5223
5273
  body: JSON.stringify({
5274
+ // The round this submit was built against. The server rejects it as
5275
+ // stale if the round has since rolled (agent auto-rolled after the
5276
+ // previous submit and a second click landed), so a stale click can't
5277
+ // mint a phantom completion for a round nobody reviewed.
5278
+ round: vp.round,
5224
5279
  selections,
5225
5280
  annotations: vp.annotations.map((a) => ({
5226
5281
  target: a.target,
@@ -5228,6 +5283,9 @@
5228
5283
  comment: a.comment,
5229
5284
  })),
5230
5285
  globalComment: globalCommentEl ? globalCommentEl.value : "",
5286
+ // Privacy-safe per-round UI usage signals → lens:round_completed.
5287
+ inspectorUsed: !!vp.inspectorUsed,
5288
+ offscreenRevealed: !!vp.offscreenRevealed,
5231
5289
  }),
5232
5290
  });
5233
5291
  const body = await res.json().catch(() => ({}));
@@ -5237,6 +5295,11 @@
5237
5295
  vp.justCompletedRound = vp.round;
5238
5296
  setNote(`Sent ${picked} pick(s) + ${annCount} comment(s) to the agent.`, "ok");
5239
5297
  showSuccessToast(picked, annCount);
5298
+ // Round sent → reset the per-round inspector/offscreen usage flags on
5299
+ // BOTH paths (not just CLI): if the agent auto-rolls and a stale click
5300
+ // lands, those flags must not carry into the next round's telemetry.
5301
+ vp.inspectorUsed = false;
5302
+ vp.offscreenRevealed = false;
5240
5303
  // CLI Lens: the round stays open server-side until the agent proposes
5241
5304
  // anew, but the user has "sent" this batch — clear it from the overlay
5242
5305
  // now (and keep it cleared via vp.sentRound in pollVariants, since the
@@ -5328,6 +5391,12 @@
5328
5391
  vp.revealOffscreen = false;
5329
5392
  vp.offscreenPromptCollapsed = false;
5330
5393
  if (globalCommentEl) globalCommentEl.value = "";
5394
+ // NOTE: vp.inspectorUsed / vp.offscreenRevealed are deliberately NOT
5395
+ // reset here. "Clear all" wipes the human's picks/comments for a fresh
5396
+ // start WITHIN the same round; it doesn't undo the fact that they opened
5397
+ // the inspector / revealed off-screen choices this round, so the usage
5398
+ // telemetry must still reflect it. They reset only on a genuine new round
5399
+ // (pollVariants) or after a submit.
5331
5400
  setNote("");
5332
5401
  closeAnnPop();
5333
5402
  vpRender();