@dzhechkov/harness-core 0.4.2 → 0.4.3

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 (42) hide show
  1. package/.dz-manifest.json +104 -28
  2. package/README.md +3 -2
  3. package/dist/backlog.d.ts +35 -0
  4. package/dist/backlog.d.ts.map +1 -1
  5. package/dist/backlog.js +167 -3
  6. package/dist/backlog.js.map +1 -1
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/loop-plan-graph.d.ts +49 -0
  12. package/dist/loop-plan-graph.d.ts.map +1 -0
  13. package/dist/loop-plan-graph.js +128 -0
  14. package/dist/loop-plan-graph.js.map +1 -0
  15. package/dist/loop-plan.d.ts.map +1 -1
  16. package/dist/loop-plan.js +13 -15
  17. package/dist/loop-plan.js.map +1 -1
  18. package/dist/model-recommender.d.ts +91 -0
  19. package/dist/model-recommender.d.ts.map +1 -0
  20. package/dist/model-recommender.js +186 -0
  21. package/dist/model-recommender.js.map +1 -0
  22. package/dist/registry.d.ts.map +1 -1
  23. package/dist/registry.js +4 -1
  24. package/dist/registry.js.map +1 -1
  25. package/dist/trace-bundle.d.ts +209 -0
  26. package/dist/trace-bundle.d.ts.map +1 -0
  27. package/dist/trace-bundle.js +601 -0
  28. package/dist/trace-bundle.js.map +1 -0
  29. package/dist/usage.d.ts +7 -0
  30. package/dist/usage.d.ts.map +1 -1
  31. package/dist/usage.js +30 -2
  32. package/dist/usage.js.map +1 -1
  33. package/package.json +3 -3
  34. package/sbom.json +217 -27
  35. package/src/backlog.ts +176 -3
  36. package/src/index.ts +3 -0
  37. package/src/loop-plan-graph.ts +132 -0
  38. package/src/loop-plan.ts +13 -15
  39. package/src/model-recommender.ts +228 -0
  40. package/src/registry.ts +4 -1
  41. package/src/trace-bundle.ts +743 -0
  42. package/src/usage.ts +42 -2
package/src/usage.ts CHANGED
@@ -128,6 +128,13 @@ export interface WeeklyResetAnchor {
128
128
  readonly weekday: number; // local Date#getDay(): Sun=0, Mon=1, ...
129
129
  readonly hour: number;
130
130
  readonly minute: number;
131
+ /** Explicit UTC offset in minutes (e.g. `+03:00` → 180). When present, the boundary is an
132
+ * ABSOLUTE instant, immune to the server's timezone. When absent (legacy `Wed 08:59`), the
133
+ * boundary is computed in server-local time — PROVEN wrong when the machine's tz differs from
134
+ * the account's reset tz (idea c8513be9: the same wall-clock instant produced window starts a
135
+ * WEEK apart under UTC vs Europe/Moscow, so the counter held the old week for hours after the
136
+ * real reset while printing the "correct" clock time). */
137
+ readonly offsetMinutes?: number;
131
138
  }
132
139
 
133
140
  /** Optional, plan-dependent calibration limits from `.dz/config.json`. Absent ⇒ pct is `null`. */
@@ -231,17 +238,31 @@ function hasOwn(obj: object, key: string): boolean {
231
238
  }
232
239
 
233
240
  function canonicalWeeklyResetAnchor(anchor: WeeklyResetAnchor): string {
234
- return `${DAY_TO_WEEKDAY[anchor.weekday] ?? 'Wed'} ${String(anchor.hour).padStart(2, '0')}:${String(anchor.minute).padStart(2, '0')}`;
241
+ const base = `${DAY_TO_WEEKDAY[anchor.weekday] ?? 'Wed'} ${String(anchor.hour).padStart(2, '0')}:${String(anchor.minute).padStart(2, '0')}`;
242
+ // The offset MUST survive canonicalization: this function silently dropped it on first
243
+ // implementation, degrading a pinned absolute instant back to the server-tz form the offset
244
+ // exists to escape (idea c8513be9 — caught live: the pin landed, the warning kept firing).
245
+ if (anchor.offsetMinutes === undefined) return base;
246
+ const sign = anchor.offsetMinutes < 0 ? '-' : '+';
247
+ const abs = Math.abs(anchor.offsetMinutes);
248
+ return `${base} ${sign}${String(Math.floor(abs / 60)).padStart(2, '0')}:${String(abs % 60).padStart(2, '0')}`;
235
249
  }
236
250
 
237
251
  export function parseWeeklyResetAnchor(anchor: string): WeeklyResetAnchor | null {
238
- const m = /^\s*(sun|mon|tue|wed|thu|fri|sat)\s+(\d{1,2}):(\d{2})\s*$/i.exec(anchor);
252
+ const m = /^\s*(sun|mon|tue|wed|thu|fri|sat)\s+(\d{1,2}):(\d{2})(?:\s+([+-])(\d{2}):(\d{2}))?\s*$/i.exec(anchor);
239
253
  if (!m) return null;
240
254
  const weekday = WEEKDAY_TO_DAY[m[1]!.toLowerCase()];
241
255
  const hour = Number(m[2]);
242
256
  const minute = Number(m[3]);
243
257
  if (weekday === undefined || !Number.isInteger(hour) || !Number.isInteger(minute)) return null;
244
258
  if (hour < 0 || hour > 23 || minute < 0 || minute > 59) return null;
259
+ if (m[4] !== undefined) {
260
+ const offH = Number(m[5]);
261
+ const offM = Number(m[6]);
262
+ if (!Number.isInteger(offH) || !Number.isInteger(offM) || offH > 14 || offM > 59) return null;
263
+ const sign = m[4] === '-' ? -1 : 1;
264
+ return { weekday, hour, minute, offsetMinutes: sign * (offH * 60 + offM) };
265
+ }
245
266
  return { weekday, hour, minute };
246
267
  }
247
268
 
@@ -250,6 +271,25 @@ export function weeklyWindowFor(nowMs: number, anchor: string): UsageWindow | nu
250
271
  const parsed = parseWeeklyResetAnchor(anchor);
251
272
  if (!parsed) return null;
252
273
 
274
+ if (parsed.offsetMinutes !== undefined) {
275
+ // ABSOLUTE-instant math (idea c8513be9): shift into the anchor's fixed offset, do the weekday
276
+ // arithmetic with UTC getters, shift back. No local-Date call ⇒ the boundary cannot move with
277
+ // the server's timezone — the property the legacy branch below demonstrably lacks.
278
+ const offMs = parsed.offsetMinutes * 60_000;
279
+ const shifted = new Date(nowMs + offMs);
280
+ const boundaryShifted = Date.UTC(
281
+ shifted.getUTCFullYear(),
282
+ shifted.getUTCMonth(),
283
+ shifted.getUTCDate() + (parsed.weekday - shifted.getUTCDay()),
284
+ parsed.hour,
285
+ parsed.minute,
286
+ 0,
287
+ 0,
288
+ );
289
+ let startedAtMs = boundaryShifted - offMs;
290
+ if (startedAtMs > nowMs) startedAtMs -= 7 * 24 * 60 * 60_000;
291
+ return { startedAtMs, resetsAtMs: startedAtMs + 7 * 24 * 60 * 60_000 };
292
+ }
253
293
  const now = new Date(nowMs);
254
294
  const candidate = new Date(
255
295
  now.getFullYear(),