Repository navigation
feat: persist telemetry queue in ${CLAUDE_PLUGIN_DATA}; fill marketplace description - #83
Conversation
…ace description
- paths.js: root LOG_DIR (queue + lock files) at ${CLAUDE_PLUGIN_DATA} when
available, falling back to PLUGIN_ROOT/logs when unset (byte-identical to
before). Fixes data loss: PLUGIN_ROOT is the install cache dir, wiped ~7 days
after a plugin update, which stranded any un-drained queue.
- transfer.js: migrateLegacyQueue() copies sealed event logs (and seals the
legacy active log) + pending transcripts forward from PLUGIN_ROOT/logs on
first run; best-effort, copy + skip-existing, skips *.sent. Wired into
session_start's prepareSession.
- marketplace.json: fill the empty skillmeter entry description + add a root
marketplace description (clears `claude plugin validate` warning / blank card).
- Bump plugin version to 0.18.0.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThis PR adds persistent, data-root-based path resolution with legacy path fallback in skillmeter's paths module, introduces a ChangesLegacy queue migration to persistent data root
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant SessionStart as session_start.js
participant Transfer as transfer.js
participant FS as Filesystem
SessionStart->>Transfer: migrateLegacyQueue()
Transfer->>FS: check LEGACY_LOG_DIR exists
alt legacy dir missing or same as current
Transfer-->>SessionStart: no-op
else legacy dir present
Transfer->>FS: copy sealed events.jsonl.<timestamp> to LOG_DIR
Transfer->>FS: seal & copy active events.jsonl as new batch
Transfer->>FS: copy pending transcripts to TRANSCRIPTS_PENDING_DIR
Transfer-->>SessionStart: migration complete (errors swallowed)
end
SessionStart->>SessionStart: refreshLicense() / runSessionStartHook()
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
d76d9f6
into
feat/local-dev-config-and-signin-notifier
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@skillmeter/scripts/lib/transfer.js`:
- Around line 332-369: The active-log migration in migrateLegacyQueue re-seals
legacy events.jsonl into a new batch name on every run because it uses
Date.now(), so the existsSync check never stabilizes. Change the events.jsonl
branch to derive the destination batch filename from a stable source attribute
such as the file’s mtime (or another deterministic identifier from src) so
repeated sessions map to the same output path. Keep the sealed-batch handling
and skip-existing behavior intact, and make the fix in migrateLegacyQueue where
the legacy active log is copied into LOG_DIR.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cca18132-c0bb-4433-9e2b-17ef1f8e213f
📒 Files selected for processing (5)
.claude-plugin/marketplace.jsonskillmeter/.claude-plugin/plugin.jsonskillmeter/scripts/lib/paths.jsskillmeter/scripts/lib/transfer.jsskillmeter/scripts/session_start.js
| // One-time forward migration of the durable queue. Older versions (and hosts | ||
| // without CLAUDE_PLUGIN_DATA) kept sealed event logs + pending transcripts under | ||
| // PLUGIN_ROOT/logs, which the host deletes ~7 days after a plugin update. Copy | ||
| // any un-uploaded artifacts into the persistent LOG_DIR so an in-place upgrade | ||
| // doesn't strand them. Best-effort, copy (not move) + skip-existing, so it's | ||
| // safe to run every session and a no-op when the paths coincide. | ||
| function migrateLegacyQueue() { | ||
| if (LEGACY_LOG_DIR === LOG_DIR) return; // CLAUDE_PLUGIN_DATA unavailable | ||
| if (!fs.existsSync(LEGACY_LOG_DIR)) return; | ||
| try { | ||
| fs.mkdirSync(LOG_DIR, { recursive: true }); | ||
| for (const f of fs.readdirSync(LEGACY_LOG_DIR)) { | ||
| const src = path.join(LEGACY_LOG_DIR, f); | ||
| try { if (!fs.statSync(src).isFile()) continue; } catch { continue; } | ||
| if (/^events\.jsonl\.\d+$/.test(f)) { | ||
| // Already-sealed batch → copy under the same name. | ||
| const dest = path.join(LOG_DIR, f); | ||
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | ||
| } else if (f === "events.jsonl") { | ||
| // Seal the legacy active log into a batch the drain recognizes. | ||
| const dest = path.join(LOG_DIR, `events.jsonl.${Date.now()}`); | ||
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | ||
| } | ||
| // Skip *.sent (already delivered) and lock files. | ||
| } | ||
| const legacyPending = path.join(LEGACY_LOG_DIR, "transcripts", "pending"); | ||
| if (fs.existsSync(legacyPending)) { | ||
| fs.mkdirSync(TRANSCRIPTS_PENDING_DIR, { recursive: true }); | ||
| for (const f of fs.readdirSync(legacyPending)) { | ||
| const src = path.join(legacyPending, f); | ||
| try { if (!fs.statSync(src).isFile()) continue; } catch { continue; } | ||
| const dest = path.join(TRANSCRIPTS_PENDING_DIR, f); | ||
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | ||
| } | ||
| } | ||
| } catch {} | ||
| } | ||
|
|
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Active-log migration re-seals the same content every session, causing duplicate uploads.
The sealed-batch branch (Lines 346-349) is idempotent because the destination filename is stable (events.jsonl.<original-suffix>) and gated by existsSync(dest). The active-log branch (Lines 350-354) is not: dest is named from Date.now(), which is different on every call, so existsSync(dest) never actually prevents re-processing. Since the source events.jsonl is copied (not moved/deleted), it stays in LEGACY_LOG_DIR and will be re-sealed into a brand-new batch file on every subsequent session for as long as the legacy directory exists (up to ~7 days post-update, per host cleanup behavior). Each new batch is picked up by the drain/upload path as unseen data, producing duplicate telemetry uploads and unnecessary file growth in LOG_DIR.
Derive the batch name from the source file's stable mtime instead of the current time so the exists-check is meaningful.
🛠️ Proposed fix
for (const f of fs.readdirSync(LEGACY_LOG_DIR)) {
const src = path.join(LEGACY_LOG_DIR, f);
- try { if (!fs.statSync(src).isFile()) continue; } catch { continue; }
+ let stat;
+ try { stat = fs.statSync(src); if (!stat.isFile()) continue; } catch { continue; }
if (/^events\.jsonl\.\d+$/.test(f)) {
// Already-sealed batch → copy under the same name.
const dest = path.join(LOG_DIR, f);
if (!fs.existsSync(dest)) fs.copyFileSync(src, dest);
} else if (f === "events.jsonl") {
- // Seal the legacy active log into a batch the drain recognizes.
- const dest = path.join(LOG_DIR, `events.jsonl.${Date.now()}`);
+ // Seal the legacy active log into a batch the drain recognizes,
+ // keyed by the file's own mtime (not Date.now()) so re-running
+ // migration on a later session doesn't re-seal the same
+ // un-migrated content under a fresh name every time.
+ const dest = path.join(LOG_DIR, `events.jsonl.${Math.floor(stat.mtimeMs)}`);
if (!fs.existsSync(dest)) fs.copyFileSync(src, dest);
}
// Skip *.sent (already delivered) and lock files.
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // One-time forward migration of the durable queue. Older versions (and hosts | |
| // without CLAUDE_PLUGIN_DATA) kept sealed event logs + pending transcripts under | |
| // PLUGIN_ROOT/logs, which the host deletes ~7 days after a plugin update. Copy | |
| // any un-uploaded artifacts into the persistent LOG_DIR so an in-place upgrade | |
| // doesn't strand them. Best-effort, copy (not move) + skip-existing, so it's | |
| // safe to run every session and a no-op when the paths coincide. | |
| function migrateLegacyQueue() { | |
| if (LEGACY_LOG_DIR === LOG_DIR) return; // CLAUDE_PLUGIN_DATA unavailable | |
| if (!fs.existsSync(LEGACY_LOG_DIR)) return; | |
| try { | |
| fs.mkdirSync(LOG_DIR, { recursive: true }); | |
| for (const f of fs.readdirSync(LEGACY_LOG_DIR)) { | |
| const src = path.join(LEGACY_LOG_DIR, f); | |
| try { if (!fs.statSync(src).isFile()) continue; } catch { continue; } | |
| if (/^events\.jsonl\.\d+$/.test(f)) { | |
| // Already-sealed batch → copy under the same name. | |
| const dest = path.join(LOG_DIR, f); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } else if (f === "events.jsonl") { | |
| // Seal the legacy active log into a batch the drain recognizes. | |
| const dest = path.join(LOG_DIR, `events.jsonl.${Date.now()}`); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } | |
| // Skip *.sent (already delivered) and lock files. | |
| } | |
| const legacyPending = path.join(LEGACY_LOG_DIR, "transcripts", "pending"); | |
| if (fs.existsSync(legacyPending)) { | |
| fs.mkdirSync(TRANSCRIPTS_PENDING_DIR, { recursive: true }); | |
| for (const f of fs.readdirSync(legacyPending)) { | |
| const src = path.join(legacyPending, f); | |
| try { if (!fs.statSync(src).isFile()) continue; } catch { continue; } | |
| const dest = path.join(TRANSCRIPTS_PENDING_DIR, f); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } | |
| } | |
| } catch {} | |
| } | |
| // One-time forward migration of the durable queue. Older versions (and hosts | |
| // without CLAUDE_PLUGIN_DATA) kept sealed event logs + pending transcripts under | |
| // PLUGIN_ROOT/logs, which the host deletes ~7 days after a plugin update. Copy | |
| // any un-uploaded artifacts into the persistent LOG_DIR so an in-place upgrade | |
| // doesn't strand them. Best-effort, copy (not move) + skip-existing, so it's | |
| // safe to run every session and a no-op when the paths coincide. | |
| function migrateLegacyQueue() { | |
| if (LEGACY_LOG_DIR === LOG_DIR) return; // CLAUDE_PLUGIN_DATA unavailable | |
| if (!fs.existsSync(LEGACY_LOG_DIR)) return; | |
| try { | |
| fs.mkdirSync(LOG_DIR, { recursive: true }); | |
| for (const f of fs.readdirSync(LEGACY_LOG_DIR)) { | |
| const src = path.join(LEGACY_LOG_DIR, f); | |
| let stat; | |
| try { stat = fs.statSync(src); if (!stat.isFile()) continue; } catch { continue; } | |
| if (/^events\.jsonl\.\d+$/.test(f)) { | |
| // Already-sealed batch → copy under the same name. | |
| const dest = path.join(LOG_DIR, f); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } else if (f === "events.jsonl") { | |
| // Seal the legacy active log into a batch the drain recognizes, | |
| // keyed by the file's own mtime (not Date.now()) so re-running | |
| // migration on a later session doesn't re-seal the same | |
| // un-migrated content under a fresh name every time. | |
| const dest = path.join(LOG_DIR, `events.jsonl.${Math.floor(stat.mtimeMs)}`); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } | |
| // Skip *.sent (already delivered) and lock files. | |
| } | |
| const legacyPending = path.join(LEGACY_LOG_DIR, "transcripts", "pending"); | |
| if (fs.existsSync(legacyPending)) { | |
| fs.mkdirSync(TRANSCRIPTS_PENDING_DIR, { recursive: true }); | |
| for (const f of fs.readdirSync(legacyPending)) { | |
| const src = path.join(legacyPending, f); | |
| try { if (!fs.statSync(src).isFile()) continue; } catch { continue; } | |
| const dest = path.join(TRANSCRIPTS_PENDING_DIR, f); | |
| if (!fs.existsSync(dest)) fs.copyFileSync(src, dest); | |
| } | |
| } | |
| } catch {} | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skillmeter/scripts/lib/transfer.js` around lines 332 - 369, The active-log
migration in migrateLegacyQueue re-seals legacy events.jsonl into a new batch
name on every run because it uses Date.now(), so the existsSync check never
stabilizes. Change the events.jsonl branch to derive the destination batch
filename from a stable source attribute such as the file’s mtime (or another
deterministic identifier from src) so repeated sessions map to the same output
path. Keep the sealed-batch handling and skip-existing behavior intact, and make
the fix in migrateLegacyQueue where the legacy active log is copied into
LOG_DIR.
Follow-up addressing the two HIGH items from the plugin-vs-docs gap audit.
1. Persist the telemetry queue in
${CLAUDE_PLUGIN_DATA}(data-loss fix)The queue (
events.jsonl*,transcripts/pending/*) and lock files lived underPLUGIN_ROOT/logs.PLUGIN_ROOTis the install/cache dir — it changes on every plugin update and the old copy is deleted ~7 days later, stranding any un-drained queue (the new version's retry daemon reads the new path). The docs explicitly warn: "treat it as ephemeral and do not write state here."paths.js:LOG_DIRnow roots at${CLAUDE_PLUGIN_DATA}(host-provided, survives updates) when set; falls back toPLUGIN_ROOT/logswhen unset (older Claude Code, directnode, tests) → byte-identical to before. Lock files live underLOG_DIRso they move automatically.transfer.jsmigrateLegacyQueue(): one-time forward copy of sealed event logs (and seals the legacy active log into a recognized batch) + pending transcripts fromPLUGIN_ROOT/logs. Best-effort, copy + skip-existing, skips*.sent. Wired intosession_start'sprepareSession.~/.skillbench(STATE_DIR) were already durable — only the queue was at risk.2. Fill marketplace description
marketplace.json: theskillmeterentry had"description": ""(blank card in/plugin,validatewarning). Filled it with the plugin description and added a root marketplace description.Housekeeping
Verification
*.sentcorrectly not migrated.LOG_DIRresolution: unset →PLUGIN_ROOT/logs(migration no-op);CLAUDE_PLUGIN_DATAset →<data>/logs(migration active).session_startbehavior unchanged apart from the version bump.node --test skillmeter/test/harness.test.js→ 20/20;claude plugin validate skillmeter→ ✔ passed.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes