@letsrebase/verify 0.0.0-stage → 0.1.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.
Files changed (49) hide show
  1. package/.claude/commands/rebase-verify.md +118 -0
  2. package/LICENSE +21 -0
  3. package/PRIVACY.md +113 -0
  4. package/README.md +209 -2
  5. package/SECURITY.md +33 -0
  6. package/bin/rebase-verify.mjs +699 -0
  7. package/package.json +38 -4
  8. package/share/practices.json +224 -0
  9. package/share/tech-labels.json +57 -0
  10. package/share/tech-lexicon.json +62 -0
  11. package/src/adapters/claude-code.mjs +225 -0
  12. package/src/adapters/codex.mjs +476 -0
  13. package/src/adapters/cursor.mjs +584 -0
  14. package/src/adapters/kimi.mjs +594 -0
  15. package/src/adapters/omp.mjs +59 -0
  16. package/src/adapters/opencode.mjs +439 -0
  17. package/src/adapters/pi.mjs +414 -0
  18. package/src/adapters/tool-vocab.mjs +15 -0
  19. package/src/agent-run.mjs +10 -0
  20. package/src/agentic-literacy.mjs +211 -0
  21. package/src/agents/acp.mjs +364 -0
  22. package/src/agents/json-answer.mjs +72 -0
  23. package/src/agents/registry.mjs +370 -0
  24. package/src/agents/run.mjs +131 -0
  25. package/src/ai-relationship.mjs +95 -0
  26. package/src/consistency.mjs +357 -0
  27. package/src/days.mjs +45 -0
  28. package/src/digest.mjs +501 -0
  29. package/src/distribution.mjs +54 -0
  30. package/src/enrich.mjs +118 -0
  31. package/src/fingerprint.mjs +134 -0
  32. package/src/forensics.mjs +178 -0
  33. package/src/groundedness.mjs +347 -0
  34. package/src/hub.mjs +136 -0
  35. package/src/intensity.mjs +132 -0
  36. package/src/live-status.mjs +79 -0
  37. package/src/practices-llm.mjs +90 -0
  38. package/src/practices-rules.mjs +295 -0
  39. package/src/practices-sample.mjs +111 -0
  40. package/src/practices.mjs +272 -0
  41. package/src/profile-llm.mjs +249 -0
  42. package/src/profile.mjs +497 -0
  43. package/src/redact.mjs +97 -0
  44. package/src/sources.mjs +91 -0
  45. package/src/submit.mjs +65 -0
  46. package/src/system-text.mjs +3 -0
  47. package/src/tech-usage.mjs +88 -0
  48. package/src/trajectory.mjs +264 -0
  49. package/src/wizard.mjs +411 -0
@@ -0,0 +1,357 @@
1
+ // Pre-submit consistency: the profile's deterministic claims, re-checked.
2
+ //
3
+ // Groundedness (groundedness.mjs) checks that the PROSE tracks the structured
4
+ // data. It cannot catch a coherent tamper: edit the structured numbers AND the
5
+ // prose together and groundedness still passes. These checks close that gap
6
+ // with two layers:
7
+ //
8
+ // 1. STRUCTURE (no logs needed): internal invariants that any honestly
9
+ // generated profile satisfies exactly — projects + otherProjects sum to
10
+ // volume, scores stay in range. The same invariants are re-checked
11
+ // server-side at intake, so editing them client-side buys nothing.
12
+ // 2. LOGS: re-read the logs at submit time and re-derive the facts. The logs
13
+ // are the ground truth the profile claims to describe, and they only ever
14
+ // grow between generation and submission (until retention pruning kicks
15
+ // in). A profile that claims MORE than the logs contain is either tampered
16
+ // or describes logs that were since pruned. Either way: regenerate.
17
+ //
18
+ // Honest limit, stated plainly: everything here runs on the candidate's
19
+ // machine, on the candidate's data. It is a screen, not proof — the same
20
+ // stance as the authenticity score. The durable backstop is the intake
21
+ // re-computing groundedness and structure on the received JSON.
22
+
23
+ import { bandFor, monthSpan } from "./tech-usage.mjs";
24
+ import { labelVocabulary } from "./digest.mjs";
25
+ import { isValidTimezone } from "./days.mjs";
26
+ import { RUBRIC, practicesArtifact } from "./practices-rules.mjs";
27
+
28
+ // { agent, model } as the hub reads it: an agent id of 1-40 [a-z0-9-], a model
29
+ // name of 1-120 printable, non-blank characters, or null.
30
+ const AGENT_ID_RE = /^[a-z0-9-]{1,40}$/;
31
+ function provenanceIssue(v) {
32
+ // printable as Python reads it: no control, format or separator characters except the plain space
33
+ const sound = (s) => typeof s === "string" && [...s].length >= 1 && [...s].length <= 120 && s.trim() !== "" && !/[\p{C}\p{Z}]/u.test(s.replaceAll(" ", ""));
34
+ if (
35
+ v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).sort().join() === "agent,model" &&
36
+ typeof v.agent === "string" && AGENT_ID_RE.test(v.agent) && (v.model === null || sound(v.model))
37
+ ) return null;
38
+ return "must be { agent, model } with an agent of 1 to 40 characters [a-z0-9-] and a model that is null or 1 to 120 printable characters";
39
+ }
40
+
41
+ export function assessStructure(profile) {
42
+ const issues = [];
43
+ const projects = profile?.projects ?? [];
44
+ const others = profile?.otherProjects ?? [];
45
+ const vol = profile?.volume ?? {};
46
+
47
+ const products = projects.length + others.length;
48
+ if (vol.products != null && products !== vol.products) {
49
+ issues.push(`volume.products is ${vol.products} but the profile lists ${products} projects (${projects.length} representative + ${others.length} inventory)`);
50
+ }
51
+
52
+ const sessions = [...projects, ...others].reduce((n, p) => n + (Number(p.sessions) || 0), 0);
53
+ if (vol.sessions != null && sessions !== vol.sessions) {
54
+ issues.push(`volume.sessions is ${vol.sessions} but per-project sessions sum to ${sessions}`);
55
+ }
56
+
57
+ // Coverage invariant: the profile cannot contain more sessions than its
58
+ // sources captured (capture counts include ephemeral sessions the digest
59
+ // later drops, so capture is an upper bound on volume).
60
+ if (Array.isArray(profile?.sources) && profile.sources.length) {
61
+ const captured = profile.sources.reduce((n, s) => n + (Number(s.sessions) || 0), 0);
62
+ if (vol.sessions != null && vol.sessions > captured) {
63
+ issues.push(`volume.sessions is ${vol.sessions} but the sources block records only ${captured} sessions read`);
64
+ }
65
+ }
66
+
67
+ // Day-count invariant: a day cannot be active outside the observed window.
68
+ // Both counts bucket in the same recorded timezone since #8, so this holds
69
+ // by construction in honest output — a violation means a hand-edit.
70
+ const it = profile?.intensity;
71
+ if (it?.activeDays != null && it?.observedDays != null && Number(it.activeDays) > Number(it.observedDays)) {
72
+ issues.push(`intensity.activeDays is ${it.activeDays} but the observed window is only ${it.observedDays} days`);
73
+ }
74
+
75
+ // Orchestration invariants (per project, when the block is present). The
76
+ // orchestration counts are citable in prose (groundedness pools them), so
77
+ // they need the same tamper posture as sessions: every one re-derives from
78
+ // data already in the profile, and an edit that inflates one breaks an
79
+ // equality it cannot also fix. Per-CLI session counts sum to the project's
80
+ // sessions (each session is tagged exactly once), toolCount re-derives from
81
+ // the split ("unknown" is not a distinct CLI), and the two delegation
82
+ // copies agree.
83
+ for (const p of projects) {
84
+ const o = p?.metrics?.orchestration;
85
+ if (!o) continue;
86
+ const tools = o.tools ?? {};
87
+ const toolSum = Object.values(tools).reduce((n, v) => n + (Number(v) || 0), 0);
88
+ if (p.sessions != null && toolSum !== Number(p.sessions)) {
89
+ issues.push(`${p.id}: orchestration.tools sums to ${toolSum} sessions but the project claims ${p.sessions}`);
90
+ }
91
+ // A tools entry with no sessions never touched the product — it can only
92
+ // exist to pad toolCount into a phantom fan-out claim (the sum invariant
93
+ // alone tolerates a smuggled zero).
94
+ for (const [tool, v] of Object.entries(tools)) {
95
+ if (!(Number(v) >= 1)) {
96
+ issues.push(`${p.id}: orchestration.tools.${tool} is ${v} — a CLI with no sessions cannot have touched the product`);
97
+ }
98
+ }
99
+ const knownTools = Object.keys(tools).filter((k) => k !== "unknown").length;
100
+ const derivedCount = Math.max(knownTools, 1);
101
+ if (o.toolCount != null && Number(o.toolCount) !== derivedCount) {
102
+ issues.push(`${p.id}: orchestration.toolCount is ${o.toolCount} but the tools split re-derives ${derivedCount}`);
103
+ }
104
+ if (o.delegation != null && p.metrics?.delegation != null && Number(o.delegation) !== Number(p.metrics.delegation)) {
105
+ issues.push(`${p.id}: metrics.delegation is ${p.metrics.delegation} but orchestration.delegation says ${o.delegation}`);
106
+ }
107
+ }
108
+
109
+ // Tech-usage invariants (block is optional). Each row's band must re-derive
110
+ // from its own counts, counts must be internally possible, and no technology
111
+ // can be in more products or sessions than the profile has.
112
+ const MONTH_RE = /^\d{4}-(0[1-9]|1[0-2])$/;
113
+ const seenTech = new Set();
114
+ const vocabulary = new Set(labelVocabulary());
115
+ const tu = profile?.techUsage;
116
+ if (tu != null) {
117
+ if (!Array.isArray(tu.technologies)) issues.push("techUsage.technologies is not a list");
118
+ if (!isValidTimezone(tu.timezone)) issues.push(`techUsage.timezone "${tu.timezone}" is not a valid IANA timezone`);
119
+ else if (profile?.intensity?.timezone && profile.intensity.timezone !== tu.timezone) {
120
+ issues.push(`techUsage.timezone is ${tu.timezone} but intensity.timezone is ${profile.intensity.timezone}: one generation uses one zone`);
121
+ }
122
+ }
123
+ for (const t of Array.isArray(tu?.technologies) ? tu.technologies : []) {
124
+ const w = `techUsage.${t?.name}`;
125
+ // Names come only from the detector's fixed vocabulary. Anything else could
126
+ // be a client or private name, so it is blocked here (works without logs).
127
+ if (typeof t?.name !== "string" || !vocabulary.has(t.name)) {
128
+ issues.push(`techUsage: "${t?.name}" is not a technology label the stack detection can emit`);
129
+ continue;
130
+ }
131
+ if (seenTech.has(t?.name)) issues.push(`${w}: listed more than once`);
132
+ seenTech.add(t?.name);
133
+ if (!MONTH_RE.test(t?.firstMonth ?? "") || !MONTH_RE.test(t?.lastMonth ?? "") || t.firstMonth > t.lastMonth) {
134
+ issues.push(`${w}: months window ${t?.firstMonth}..${t?.lastMonth} is not a valid range`);
135
+ continue;
136
+ }
137
+ if (!(t.months >= 1) || t.months > monthSpan(t.firstMonth, t.lastMonth)) {
138
+ issues.push(`${w}: ${t.months} months cannot fit between ${t.firstMonth} and ${t.lastMonth}`);
139
+ }
140
+ if (t.band !== bandFor(t)) issues.push(`${w}: band is "${t.band}" but its counts derive "${bandFor(t)}"`);
141
+ if (vol.products != null && t.products > vol.products) issues.push(`${w}: ${t.products} products but the profile has ${vol.products}`);
142
+ if (vol.sessions != null && t.sessions > vol.sessions) issues.push(`${w}: ${t.sessions} sessions but the profile has ${vol.sessions}`);
143
+ if (t.products > t.sessions) issues.push(`${w}: ${t.products} products but only ${t.sessions} sessions`);
144
+ }
145
+
146
+ // Practices invariants (block is optional): a known rubric, ids and methods
147
+ // from the published list, and counts that are possible given the profile.
148
+ const pr = profile?.practices;
149
+ if (pr != null && typeof pr === "object" && "classifiedBy" in pr) {
150
+ const bad = provenanceIssue(pr.classifiedBy);
151
+ if (bad) issues.push(`practices.classifiedBy: ${bad}`);
152
+ }
153
+ if (profile != null && typeof profile === "object" && "generatedBy" in profile) {
154
+ const g = profile.generatedBy;
155
+ if (!g || typeof g !== "object" || Array.isArray(g) || Object.keys(g).join() !== "narrative") {
156
+ issues.push("generatedBy: must be an object with only a narrative entry { agent, model }");
157
+ } else {
158
+ const bad = provenanceIssue(g.narrative);
159
+ if (bad) issues.push(`generatedBy.narrative: ${bad}`);
160
+ }
161
+ }
162
+ if (pr != null) {
163
+ const known = new Map(practicesArtifact().practices.map((x) => [x.id, x.method]));
164
+ if (pr.rubric !== RUBRIC) issues.push(`practices.rubric is "${pr.rubric}" but this tool counts against "${RUBRIC}"`);
165
+ if (!isValidTimezone(pr.timezone)) issues.push(`practices.timezone "${pr.timezone}" is not a valid IANA timezone`);
166
+ else if (profile?.intensity?.timezone && profile.intensity.timezone !== pr.timezone) {
167
+ issues.push(`practices.timezone is ${pr.timezone} but intensity.timezone is ${profile.intensity.timezone}: one generation uses one zone`);
168
+ }
169
+ if (!Array.isArray(pr.items)) issues.push("practices.items is not a list");
170
+ const windowMonths = MONTH_RE.test(profile?.window?.from ?? "") && MONTH_RE.test(profile?.window?.to ?? "") && profile.window.from <= profile.window.to
171
+ ? monthSpan(profile.window.from, profile.window.to) : null;
172
+ const seenIds = new Set();
173
+ for (const x of Array.isArray(pr.items) ? pr.items : []) {
174
+ const w = `practices.${x?.id}`;
175
+ if (typeof x?.id !== "string" || !known.has(x.id)) {
176
+ issues.push(`practices: "${x?.id}" is not a practice of ${RUBRIC}`);
177
+ continue;
178
+ }
179
+ if (seenIds.has(x.id)) issues.push(`${w}: listed more than once`);
180
+ seenIds.add(x.id);
181
+ if (x.method !== known.get(x.id)) issues.push(`${w}: method is "${x.method}" but the list counts it by "${known.get(x.id)}"`);
182
+ const whole = (n) => Number.isInteger(n) && n >= 0;
183
+ const bad = ["seen", "of", "products", "months"].filter((k) => !whole(x[k]));
184
+ if (bad.length) {
185
+ issues.push(`${w}: ${bad.join(", ")} must be whole numbers, 0 or more`);
186
+ continue;
187
+ }
188
+ if (x.seen > x.of) issues.push(`${w}: seen is ${x.seen} but only ${x.of} sessions could show it`);
189
+ if (vol.sessions != null && x.of > vol.sessions) issues.push(`${w}: of is ${x.of} sessions but the profile has ${vol.sessions}`);
190
+ if (x.method === "model" && x.of > 60) issues.push(`${w}: of is ${x.of} but a model practice reads at most 60 sessions`);
191
+ if (vol.products != null && x.products > vol.products) issues.push(`${w}: ${x.products} products but the profile has ${vol.products}`);
192
+ if (x.products > x.seen) issues.push(`${w}: ${x.products} products but seen in only ${x.seen} sessions`);
193
+ if (x.months > x.seen) issues.push(`${w}: ${x.months} months but seen in only ${x.seen} sessions`);
194
+ if (x.seen >= 1 && x.months < 1) issues.push(`${w}: seen in ${x.seen} sessions but months is 0`);
195
+ // months are counted in the profile zone, the window in UTC: an offset of at
196
+ // most 14 hours shifts a month key by at most one.
197
+ if (windowMonths != null && x.months > windowMonths + 1) issues.push(`${w}: ${x.months} months but the profile window spans ${windowMonths}`);
198
+ }
199
+ }
200
+
201
+ const auth = profile?.authenticity?.score;
202
+ if (auth != null && (auth < 0 || auth > 100)) issues.push(`authenticity.score out of range: ${auth}`);
203
+ const ground = profile?.groundedness?.score;
204
+ if (ground != null && (ground < 0 || ground > 100)) issues.push(`groundedness.score out of range: ${ground}`);
205
+
206
+ return { issues };
207
+ }
208
+
209
+ // The submit gate, as one pure function so every consumer (submit --yes,
210
+ // submit --dry-run) blocks on exactly the same conditions. An UNSCORED
211
+ // groundedness (fewer than 4 checkable anchors in the prose) blocks like a
212
+ // low one: prose the screen cannot check at all must not pass the gate that
213
+ // exists to check prose — the intake flags the same case server-side.
214
+ export function submitBlockers({ issues = [], groundedness = null, force = false } = {}) {
215
+ if (force) return [];
216
+ const blockers = [];
217
+ if (issues.length) blockers.push({ kind: "consistency", count: issues.length });
218
+ const score = groundedness?.score;
219
+ if (score == null) blockers.push({ kind: "groundedness-unscored" });
220
+ else if (score < 60) blockers.push({ kind: "groundedness-low", score });
221
+ return blockers;
222
+ }
223
+
224
+ // digestProjects: the per-repo clusters re-derived from the logs right now
225
+ // (buildDigest(readClaudeCode(root)).projects). Profile projects are matched
226
+ // by repoLabel — present locally until submit strips it from the payload. A
227
+ // project whose repoLabel was removed by hand is reported as unverifiable
228
+ // (warning), not as a violation.
229
+ //
230
+ // opts.intensity: the practice-intensity block re-derived from the logs in the
231
+ // profile's RECORDED timezone (computeIntensity(parsed, { tz: profile.intensity
232
+ // .timezone })) — never the machine zone, or a candidate who generated with
233
+ // --tz Europe/Rome and submits from a CI box would be flagged for the bucketing
234
+ // difference, not for any real excess.
235
+ export function assessAgainstLogs(profile, digestProjects, opts = {}) {
236
+ const issues = [];
237
+ const warnings = [];
238
+ const byRepo = new Map((digestProjects ?? []).map((p) => [p.repo, p]));
239
+
240
+ // The gate is one-directional: claims must not EXCEED the logs. Ongoing use
241
+ // only grows the logs, so excess claims have exactly two causes — the logs
242
+ // were pruned after generation (Claude Code's cleanup ages out old
243
+ // sessions), or the file was inflated by hand. Counting them separately
244
+ // lets submit name the common, innocent cause and prescribe the fix.
245
+ let excessClaims = 0;
246
+ const excess = (msg) => { issues.push(msg); excessClaims++; };
247
+
248
+ const vol = profile?.volume ?? {};
249
+ const totalSessions = (digestProjects ?? []).reduce((n, p) => n + (p.sessions || 0), 0);
250
+ const totalInstructions = (digestProjects ?? []).reduce((n, p) => n + (p.userMessages || 0), 0);
251
+ if (vol.products != null && vol.products > (digestProjects?.length ?? 0)) {
252
+ excess(`profile claims ${vol.products} products but the logs contain ${digestProjects?.length ?? 0}`);
253
+ }
254
+ if (vol.sessions != null && vol.sessions > totalSessions) {
255
+ excess(`profile claims ${vol.sessions} sessions but the logs contain ${totalSessions}`);
256
+ }
257
+ if (vol.instructions != null && vol.instructions > totalInstructions) {
258
+ // userMessages is text-filter-derived (framework-injected reminders, tool
259
+ // dumps, and attached-file wrappers are stripped before counting), so a
260
+ // tool update that widens the filter shrinks the re-derivation on
261
+ // unchanged logs — the same innocent third cause dispatchCommands has
262
+ // below. The message names it; the remedy is the same either way:
263
+ // regenerate.
264
+ excess(`profile claims ${vol.instructions} instructions but the logs contain ${totalInstructions} (framework-injected text filtering may also have changed in an update — regenerate)`);
265
+ }
266
+
267
+ for (const p of profile?.projects ?? []) {
268
+ if (!p.repoLabel) {
269
+ warnings.push(`${p.id}: repoLabel removed, cannot re-verify against the logs`);
270
+ continue;
271
+ }
272
+ const d = byRepo.get(p.repoLabel);
273
+ if (!d) {
274
+ issues.push(`${p.id} (${p.repoLabel}): no such project in the logs`);
275
+ continue;
276
+ }
277
+ if ((Number(p.sessions) || 0) > (d.sessions || 0)) {
278
+ excess(`${p.id} (${p.repoLabel}): claims ${p.sessions} sessions, logs show ${d.sessions}`);
279
+ }
280
+ if ((Number(p.landing?.commits) || 0) > (d.landing?.commits || 0)) {
281
+ excess(`${p.id} (${p.repoLabel}): claims ${p.landing.commits} commits, logs show ${d.landing?.commits ?? 0}`);
282
+ }
283
+ // Orchestration counts, same one-directional gate: per-CLI session counts
284
+ // and dispatch counts only grow with ongoing use, so a claim above the
285
+ // re-derivation is pruning or inflation — the numbers groundedness lets
286
+ // the prose cite must also survive re-derivation. dispatchCommands has a
287
+ // third innocent cause the others don't: it is matcher-derived, so a tool
288
+ // update that tightens dispatch detection shrinks the re-derivation on
289
+ // unchanged logs. The message names it; the remedy is the same either
290
+ // way: regenerate.
291
+ const co = p.metrics?.orchestration;
292
+ const dor = d.orchestration;
293
+ if (co && dor) {
294
+ if ((Number(co.dispatchCommands) || 0) > (dor.dispatchCommands || 0)) {
295
+ excess(`${p.id} (${p.repoLabel}): claims ${co.dispatchCommands} agent dispatches, logs re-derive ${dor.dispatchCommands ?? 0} (dispatch detection may also have changed in an update — regenerate)`);
296
+ }
297
+ for (const [tool, n] of Object.entries(co.tools ?? {})) {
298
+ if ((Number(n) || 0) > (dor.tools?.[tool] || 0)) {
299
+ excess(`${p.id} (${p.repoLabel}): claims ${n} sessions via ${tool}, logs show ${dor.tools?.[tool] ?? 0}`);
300
+ }
301
+ }
302
+ if ((Number(co.delegation) || 0) > (dor.delegation || 0)) {
303
+ excess(`${p.id} (${p.repoLabel}): claims ${co.delegation} sub-agent delegations, logs show ${dor.delegation ?? 0}`);
304
+ }
305
+ // toolOverlap is one-directional too: ongoing use can only flip it
306
+ // false -> true, and the flip is exactly what turns "migration" prose
307
+ // into "concurrent fan-out" — a hand-edit worth its own gate.
308
+ if (co.toolOverlap === true && dor.toolOverlap === false) {
309
+ excess(`${p.id} (${p.repoLabel}): claims concurrent multi-CLI use (toolOverlap true) but the logs re-derive disjoint eras`);
310
+ }
311
+ }
312
+ }
313
+
314
+ // Day-based intensity claims, same one-directional gate: pruning ages whole
315
+ // days out of the logs, so the re-derived count can only be SMALLER than an
316
+ // honest claim when sessions were pruned — and ongoing use only adds days.
317
+ const claimed = profile?.intensity;
318
+ const derived = opts.intensity;
319
+ if (claimed && derived) {
320
+ if ((Number(claimed.activeDays) || 0) > (derived.activeDays || 0)) {
321
+ excess(`profile claims ${claimed.activeDays} active days but the logs re-derive ${derived.activeDays} (timezone ${derived.timezone ?? "UTC"})`);
322
+ }
323
+ if ((Number(claimed.longestStreak) || 0) > (derived.longestStreak || 0)) {
324
+ excess(`profile claims a ${claimed.longestStreak}-day streak but the logs re-derive ${derived.longestStreak}`);
325
+ }
326
+ }
327
+
328
+ // Tech usage, same one-directional gate, split by what the logs can prove.
329
+ // HARD (excess claims): the month window. The first month must equal the
330
+ // re-derived one, the last cannot be later, and the claimed month count must
331
+ // fit the re-derived months up to the claimed last month. A narrowed window
332
+ // (a later first month) would otherwise turn a short history into
333
+ // "continuous", so equality is required, not just <=.
334
+ // WARNINGS: what depends on the disk NOW. Stack detection reads dependency
335
+ // manifests as they are today, so a moved or deleted repo can remove a
336
+ // technology or lower its session/product counts with unchanged logs. Those
337
+ // deltas are reported, never block; regenerating clears them.
338
+ const derivedTech = new Map((opts.techUsage?.technologies ?? []).map((t) => [t.name, t]));
339
+ if (Array.isArray(profile?.techUsage?.technologies) && opts.techUsage !== undefined) {
340
+ for (const c of profile.techUsage.technologies) {
341
+ const d = derivedTech.get(c?.name);
342
+ if (!d) {
343
+ warnings.push(`techUsage.${c?.name}: the logs no longer re-derive this technology (stack detection reads repos as they are now, so a moved or deleted repo can change it: regenerate to refresh)`);
344
+ continue;
345
+ }
346
+ if (c.firstMonth !== d.firstMonth) excess(`techUsage.${c.name}: claims first month ${c.firstMonth}, logs re-derive ${d.firstMonth}`);
347
+ if (c.lastMonth > d.lastMonth) excess(`techUsage.${c.name}: claims last month ${c.lastMonth}, logs re-derive ${d.lastMonth}`);
348
+ const fitting = (d.monthList ?? []).filter((m) => m <= c.lastMonth).length;
349
+ if ((Number(c.months) || 0) > fitting) excess(`techUsage.${c.name}: claims ${c.months} months up to ${c.lastMonth}, logs re-derive ${fitting}`);
350
+ for (const k of ["sessions", "products"]) {
351
+ if ((Number(c[k]) || 0) > d[k]) warnings.push(`techUsage.${c.name}: claims ${k === "sessions" ? c[k] + " sessions" : c[k] + " products"}, logs now re-derive ${d[k]} (detection reads repos as they are now)`);
352
+ }
353
+ }
354
+ }
355
+
356
+ return { issues, warnings, excessClaims };
357
+ }
package/src/days.mjs ADDED
@@ -0,0 +1,45 @@
1
+ // Shared active-day definition.
2
+ //
3
+ // One definition, used by BOTH the fingerprint (src/fingerprint.mjs) and the
4
+ // practice-intensity lens (src/intensity.mjs), so the two can never drift apart
5
+ // again. A day is "active" when it carries REAL message activity; days are
6
+ // bucketed in a fixed, recorded timezone so the count re-derives identically on
7
+ // any machine (CONTRIBUTING: determinism — record the offset used). There is NO
8
+ // interpolation across gaps: a long-lived or resumed session marks only the days
9
+ // it actually had a message on, never the idle days between first and last.
10
+
11
+ // Default to UTC: machine-independent, and identical to the historical
12
+ // `new Date(t).toISOString().slice(0,10)` bucketing. A caller may pass an IANA
13
+ // zone (e.g. "Europe/Rome") for a candidate-local count; whatever zone is used
14
+ // is recorded in the profile so the number stays reproducible.
15
+ export const DEFAULT_TZ = "UTC";
16
+
17
+ // Day key (YYYY-MM-DD) in an explicit timezone. Uses Intl with an explicit
18
+ // `timeZone`, so it does NOT depend on the host machine's TZ env or locale.
19
+ // True when `tz` is an IANA zone Intl accepts. Used wherever a RECORDED zone is
20
+ // read back from a profile, so a hand-edited value is reported, not thrown.
21
+ export function isValidTimezone(tz) {
22
+ if (typeof tz !== "string" || !tz) return false;
23
+ try { new Intl.DateTimeFormat("en-CA", { timeZone: tz }).format(0); return true; } catch { return false; }
24
+ }
25
+
26
+ export function dayKeyFor(tz = DEFAULT_TZ) {
27
+ const fmt = new Intl.DateTimeFormat("en-CA", { timeZone: tz });
28
+ return (ts) => fmt.format(new Date(ts));
29
+ }
30
+
31
+ // The set of day keys (in `tz`) that carry real activity. `timestamps` is a
32
+ // flat list of epoch-ms values (one per message); non-finite values are ignored.
33
+ export function activeDayKeys(timestamps, tz = DEFAULT_TZ) {
34
+ const key = dayKeyFor(tz);
35
+ const days = new Set();
36
+ for (const t of timestamps) if (Number.isFinite(t)) days.add(key(t));
37
+ return days;
38
+ }
39
+
40
+ // Month key (YYYY-MM) in an explicit timezone: the first seven characters of
41
+ // the day key, so months and days always bucket the same way for the same --tz.
42
+ export function monthKeyFor(tz = DEFAULT_TZ) {
43
+ const key = dayKeyFor(tz);
44
+ return (ts) => key(ts).slice(0, 7);
45
+ }