claude-rpc 0.24.0 → 0.24.1
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/package.json +1 -1
- package/src/insights.js +13 -9
- package/src/version.js +1 -1
package/package.json
CHANGED
package/src/insights.js
CHANGED
|
@@ -274,22 +274,26 @@ export function generateInsights(aggregate, opts = {}) {
|
|
|
274
274
|
|
|
275
275
|
if (!C.length) return ['Not enough data yet — keep coding and check back tomorrow.'];
|
|
276
276
|
|
|
277
|
-
//
|
|
278
|
-
//
|
|
277
|
+
// Weighted random draw WITHOUT replacement. Weight sets how often (and how
|
|
278
|
+
// early) a line tends to surface, but every run is a genuinely fresh mix —
|
|
279
|
+
// including the top line — rather than the same weight-sorted five. Default
|
|
280
|
+
// seed = clock → fresh each run; pass opts.seed for a deterministic order.
|
|
281
|
+
// Topic keeps near-duplicates (two streak lines, etc.) out of the same draw.
|
|
279
282
|
const rand = rng(opts.seed != null ? opts.seed : Date.now());
|
|
280
|
-
for (const c of C) c.score = c.w + rand() * 22;
|
|
281
|
-
C.sort((x, y) => y.score - x.score);
|
|
282
|
-
|
|
283
|
-
// Take the top `limit`, but at most one line per topic so near-duplicates
|
|
284
|
-
// (two streak lines, peak-weekday + weekday-rhythm) never appear together.
|
|
285
283
|
const limit = opts.limit ?? 5;
|
|
284
|
+
const pool = C.slice();
|
|
286
285
|
const seen = new Set();
|
|
287
286
|
const out = [];
|
|
288
|
-
|
|
287
|
+
while (out.length < limit && pool.length) {
|
|
288
|
+
let total = 0;
|
|
289
|
+
for (const c of pool) total += c.w;
|
|
290
|
+
let r = rand() * total;
|
|
291
|
+
let idx = 0;
|
|
292
|
+
while (idx < pool.length - 1 && (r -= pool[idx].w) > 0) idx++;
|
|
293
|
+
const [c] = pool.splice(idx, 1);
|
|
289
294
|
if (c.topic && seen.has(c.topic)) continue;
|
|
290
295
|
if (c.topic) seen.add(c.topic);
|
|
291
296
|
out.push(c.text);
|
|
292
|
-
if (out.length >= limit) break;
|
|
293
297
|
}
|
|
294
298
|
return out;
|
|
295
299
|
}
|