@trazum/core 2.7.11 → 3.0.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 (115) hide show
  1. package/README.md +1 -1
  2. package/dist/advisories.d.ts +14 -7
  3. package/dist/advisories.d.ts.map +1 -1
  4. package/dist/advisories.js +27 -20
  5. package/dist/advisories.js.map +1 -1
  6. package/dist/budget.d.ts.map +1 -1
  7. package/dist/budget.js +2 -1
  8. package/dist/budget.js.map +1 -1
  9. package/dist/connector.js +1 -1
  10. package/dist/connector.js.map +1 -1
  11. package/dist/conversation.d.ts.map +1 -1
  12. package/dist/conversation.js +4 -2
  13. package/dist/conversation.js.map +1 -1
  14. package/dist/i18n/en.js +2 -2
  15. package/dist/i18n/en.js.map +1 -1
  16. package/dist/i18n/es.js +2 -2
  17. package/dist/i18n/es.js.map +1 -1
  18. package/dist/i18n/types.d.ts +2 -1
  19. package/dist/i18n/types.d.ts.map +1 -1
  20. package/dist/index.d.ts +3 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/input-shape.d.ts.map +1 -1
  25. package/dist/input-shape.js +4 -2
  26. package/dist/input-shape.js.map +1 -1
  27. package/dist/openrouter.d.ts +1 -1
  28. package/dist/openrouter.d.ts.map +1 -1
  29. package/dist/openrouter.js +1 -2
  30. package/dist/openrouter.js.map +1 -1
  31. package/dist/phrases.d.ts +39 -0
  32. package/dist/phrases.d.ts.map +1 -1
  33. package/dist/phrases.js +130 -0
  34. package/dist/phrases.js.map +1 -1
  35. package/dist/pricing-overlay.d.ts +1 -1
  36. package/dist/pricing-overlay.d.ts.map +1 -1
  37. package/dist/pricing-overlay.js +21 -11
  38. package/dist/pricing-overlay.js.map +1 -1
  39. package/dist/pricing.d.ts +33 -6
  40. package/dist/pricing.d.ts.map +1 -1
  41. package/dist/pricing.js +77 -115
  42. package/dist/pricing.js.map +1 -1
  43. package/dist/repeats.d.ts.map +1 -1
  44. package/dist/repeats.js +4 -2
  45. package/dist/repeats.js.map +1 -1
  46. package/dist/reprice.js +1 -1
  47. package/dist/reprice.js.map +1 -1
  48. package/dist/review.js +2 -1
  49. package/dist/review.js.map +1 -1
  50. package/dist/rules.d.ts.map +1 -1
  51. package/dist/rules.js +119 -3
  52. package/dist/rules.js.map +1 -1
  53. package/dist/segment.d.ts +31 -1
  54. package/dist/segment.d.ts.map +1 -1
  55. package/dist/segment.js +128 -2
  56. package/dist/segment.js.map +1 -1
  57. package/dist/session-cost.d.ts.map +1 -1
  58. package/dist/session-cost.js +4 -2
  59. package/dist/session-cost.js.map +1 -1
  60. package/dist/session-ledger.d.ts.map +1 -1
  61. package/dist/session-ledger.js +4 -2
  62. package/dist/session-ledger.js.map +1 -1
  63. package/dist/structure.d.ts +34 -0
  64. package/dist/structure.d.ts.map +1 -1
  65. package/dist/structure.js +143 -12
  66. package/dist/structure.js.map +1 -1
  67. package/dist/truncation-retry.d.ts.map +1 -1
  68. package/dist/truncation-retry.js +4 -2
  69. package/dist/truncation-retry.js.map +1 -1
  70. package/dist/ttl-fit.d.ts.map +1 -1
  71. package/dist/ttl-fit.js +4 -2
  72. package/dist/ttl-fit.js.map +1 -1
  73. package/dist/types.d.ts +17 -7
  74. package/dist/types.d.ts.map +1 -1
  75. package/dist/usage.d.ts.map +1 -1
  76. package/dist/usage.js +13 -12
  77. package/dist/usage.js.map +1 -1
  78. package/dist/watch.d.ts +11 -1
  79. package/dist/watch.d.ts.map +1 -1
  80. package/dist/watch.js.map +1 -1
  81. package/dist/weekly.d.ts +140 -0
  82. package/dist/weekly.d.ts.map +1 -0
  83. package/dist/weekly.js +176 -0
  84. package/dist/weekly.js.map +1 -0
  85. package/dist/write.js +2 -2
  86. package/dist/write.js.map +1 -1
  87. package/package.json +1 -1
  88. package/src/advisories.ts +41 -25
  89. package/src/budget.ts +2 -1
  90. package/src/connector.ts +1 -1
  91. package/src/conversation.ts +4 -2
  92. package/src/i18n/en.ts +2 -2
  93. package/src/i18n/es.ts +2 -2
  94. package/src/i18n/types.ts +2 -1
  95. package/src/index.ts +4 -2
  96. package/src/input-shape.ts +4 -2
  97. package/src/openrouter.ts +1 -2
  98. package/src/phrases.ts +134 -0
  99. package/src/pricing-overlay.ts +23 -14
  100. package/src/pricing.ts +82 -120
  101. package/src/repeats.ts +4 -2
  102. package/src/reprice.ts +1 -1
  103. package/src/review.ts +1 -1
  104. package/src/rules.ts +135 -2
  105. package/src/segment.ts +131 -3
  106. package/src/session-cost.ts +4 -2
  107. package/src/session-ledger.ts +4 -2
  108. package/src/structure.ts +152 -13
  109. package/src/truncation-retry.ts +4 -2
  110. package/src/ttl-fit.ts +4 -2
  111. package/src/types.ts +18 -7
  112. package/src/usage.ts +13 -12
  113. package/src/watch.ts +12 -1
  114. package/src/weekly.ts +281 -0
  115. package/src/write.ts +2 -2
package/src/usage.ts CHANGED
@@ -793,7 +793,7 @@ function readCount(...candidates: unknown[]): Count {
793
793
  }
794
794
 
795
795
  /** Zero for an absent count. Callers reject corrupt ones before reaching this. */
796
- const valueOf = (count: Count): number => (count.kind === 'ok' ? count.value : 0);
796
+ const countOf = (count: Count): number => (count.kind === 'ok' ? count.value : 0);
797
797
 
798
798
  /**
799
799
  * One line of a usage log, or `null` when it is not one.
@@ -1008,23 +1008,23 @@ export function parseUsageLine(line: string): UsageRecord | null {
1008
1008
 
1009
1009
  // Both providers that fold cached tokens into the prompt count, one
1010
1010
  // subtraction. They cannot coexist on a record: the shapes share no field.
1011
- const cached = valueOf(counts.openAiCached!) + valueOf(counts.geminiCached!);
1011
+ const cached = countOf(counts.openAiCached!) + countOf(counts.geminiCached!);
1012
1012
  // Inside the OpenAI total like the cached tokens, and taken out of it the same way.
1013
- const openAiWritten = valueOf(counts.openAiWrite!);
1014
- const flatWrite = valueOf(counts.cacheWrite!);
1015
- const split5m = valueOf(counts.write5m!);
1016
- const split1h = valueOf(counts.write1h!);
1013
+ const openAiWritten = countOf(counts.openAiWrite!);
1014
+ const flatWrite = countOf(counts.cacheWrite!);
1015
+ const split5m = countOf(counts.write5m!);
1016
+ const split1h = countOf(counts.write1h!);
1017
1017
  const hasSplit = counts.write5m!.kind === 'ok' || counts.write1h!.kind === 'ok';
1018
1018
  // OpenAI's lifetimes, taken only when they add up to the writes they split.
1019
1019
  const openAiSplitGiven = counts.openAiWrite30m!.kind === 'ok' || counts.openAiWrite12h!.kind === 'ok';
1020
1020
  const openAiSplitAgrees =
1021
1021
  counts.openAiWrite30m!.kind === 'ok' && counts.openAiWrite12h!.kind === 'ok'
1022
- && valueOf(counts.openAiWrite30m!) + valueOf(counts.openAiWrite12h!) === openAiWritten;
1023
- const openAiLong = openAiSplitAgrees ? valueOf(counts.openAiWrite12h!) : 0;
1022
+ && countOf(counts.openAiWrite30m!) + countOf(counts.openAiWrite12h!) === openAiWritten;
1023
+ const openAiLong = openAiSplitAgrees ? countOf(counts.openAiWrite12h!) : 0;
1024
1024
 
1025
1025
  return {
1026
1026
  model,
1027
- inputTokens: Math.max(0, valueOf(counts.input!) - cached - openAiWritten) + valueOf(counts.geminiToolPrompt!),
1027
+ inputTokens: Math.max(0, countOf(counts.input!) - cached - openAiWritten) + countOf(counts.geminiToolPrompt!),
1028
1028
  cacheReadTokens: counts.cacheRead!.kind === 'ok' ? counts.cacheRead!.value : cached,
1029
1029
  /**
1030
1030
  * The split when the log carries it, the flat number otherwise — and
@@ -1045,7 +1045,7 @@ export function parseUsageLine(line: string): UsageRecord | null {
1045
1045
  * by the model, since the line alone cannot say whose API wrote it.
1046
1046
  */
1047
1047
  writeTtlKnown: hasSplit || (flatWrite === 0 && (openAiSplitGiven ? openAiSplitAgrees : openAiWritten === 0)),
1048
- outputTokens: valueOf(counts.output!) + valueOf(counts.geminiThoughts!),
1048
+ outputTokens: countOf(counts.output!) + countOf(counts.geminiThoughts!),
1049
1049
  /**
1050
1050
  * Trimmed and internally normalised: any whitespace run becomes one space.
1051
1051
  * A label is a workload name, and it is also used as half of structured keys
@@ -1118,7 +1118,7 @@ export function parseUsageLine(line: string): UsageRecord | null {
1118
1118
  ...(record.batch === true || usage.service_tier === 'batch' ? { batch: true as const } : {}),
1119
1119
  /* Said by the record alone: nothing a provider returns names who was waiting. */
1120
1120
  ...(record.interactive === true ? { interactive: true as const } : {}),
1121
- ...(valueOf(webSearch) > 0 ? { webSearchRequests: valueOf(webSearch) } : {}),
1121
+ ...(countOf(webSearch) > 0 ? { webSearchRequests: countOf(webSearch) } : {}),
1122
1122
  ...(openAiSplitGiven && !openAiSplitAgrees ? { writeSplitContradicted: true as const } : {}),
1123
1123
  };
1124
1124
  }
@@ -1251,7 +1251,8 @@ function add(into: UsageBreakdown, record: UsageRecord, catalogue: PricingCatalo
1251
1251
  const priced = effectivePricing(model, at, promptSizeOf(record));
1252
1252
  const { inputPerMTok, outputPerMTok } = priced;
1253
1253
  // Dated, like the rate above: a repriced cache read is part of the reprice.
1254
- const rates = multipliersFor(model, at);
1254
+ // And for the same kind of call: a batch call reads the cache at the Batch table's price.
1255
+ const rates = multipliersFor(model, at, priced);
1255
1256
  const per = (tokens: number, rate: number): number => (tokens / 1_000_000) * rate;
1256
1257
  const recordUsd = (input: number, output: number): number =>
1257
1258
  per(record.inputTokens, input) +
package/src/watch.ts CHANGED
@@ -97,9 +97,20 @@ export interface WatchThresholds {
97
97
  maxCacheLossUsd?: number;
98
98
  }
99
99
 
100
+ /**
101
+ * The part of a priced report a gate is judged against.
102
+ *
103
+ * A connected report (`BucketedReport`) has all of it. So does what is read
104
+ * out of the sessions a coding agent keeps on disk, which has no buckets and
105
+ * is shaped to this instead of being made to pretend it has them.
106
+ */
107
+ export type WatchedReport = Pick<BucketedReport, 'span' | 'byDay'> & {
108
+ total: Pick<BucketedReport['total'], 'totalUsd'>;
109
+ };
110
+
100
111
  export interface WatchOptions {
101
112
  /** Priced measurements for the period being watched. */
102
- report: BucketedReport;
113
+ report: WatchedReport;
103
114
  thresholds: WatchThresholds;
104
115
  /** The cache verdict over the same report, when the caller computed one. */
105
116
  cacheDeltaUsd?: number;
package/src/weekly.ts ADDED
@@ -0,0 +1,281 @@
1
+ /**
2
+ * The week in three paragraphs: what it cost, what moved against the week
3
+ * before, and the three changes worth making first.
4
+ *
5
+ * Nothing here is estimated. The bill and the movement are two measured
6
+ * reports, one per week, priced by the same catalogue; the changes are the
7
+ * ranked actions `buildPlan` already derives from the week's own report, and
8
+ * each carries what was measured before it. A saving that has not happened is
9
+ * a projection and says so; `verify` is what measures it afterwards.
10
+ *
11
+ * **A figure in the summary is a figure in the bill.** The summary is text a
12
+ * person reads in an issue and acts on, so every dollar amount and every
13
+ * percentage it prints has to be one the two reports (or the plan made from
14
+ * them) hold. `billFigures` works the allowed set out from the reports
15
+ * themselves, by a route that shares no code with the builder, and
16
+ * `strayFigures` reads a rendered summary and names what is not in it. The CLI
17
+ * refuses to write a summary with a stray figure in it: a wrong number in a
18
+ * weekly note is worse than no note, because nobody re-adds it.
19
+ *
20
+ * Browser-safe like the rest of the core: reports in, one document out. The
21
+ * words belong to whoever renders it, in the reader's language.
22
+ */
23
+
24
+ import { formatUsd } from './savings.js';
25
+ import type { PlanActionKind, PlanAssumption, PlanDocument } from './plan.js';
26
+ import type { UsageProfileReport } from './usage.js';
27
+
28
+ const DAY_MS = 86_400_000;
29
+ export const WEEK_MS = 7 * DAY_MS;
30
+
31
+ /** How many changes a weekly summary names. Three is the issue's number; more is a list nobody acts on. */
32
+ export const WEEKLY_CHANGES = 3;
33
+ /** How many models the bill and the movement name before saying how many more there are. */
34
+ export const WEEKLY_MODELS = 5;
35
+ export const WEEKLY_MOVERS = 3;
36
+
37
+ /** A window, half-open like every window in the profile: two adjacent weeks share no call. */
38
+ export interface WeekWindow {
39
+ sinceMs: number;
40
+ untilMs: number;
41
+ /** The first UTC day inside it, `YYYY-MM-DD`. */
42
+ firstDay: string;
43
+ /** The last UTC day inside it. */
44
+ lastDay: string;
45
+ }
46
+
47
+ const dayOf = (ms: number): string => new Date(ms).toISOString().slice(0, 10);
48
+
49
+ const windowOf = (sinceMs: number, untilMs: number): WeekWindow => ({
50
+ sinceMs,
51
+ untilMs,
52
+ firstDay: dayOf(sinceMs),
53
+ lastDay: dayOf(untilMs - 1),
54
+ });
55
+
56
+ /**
57
+ * The week ending at `untilMs` and the week before it.
58
+ *
59
+ * Seven days each, back to back, with no overlap and no gap: the week before
60
+ * ends at the instant this one begins.
61
+ */
62
+ export function weekWindows(untilMs: number): { current: WeekWindow; previous: WeekWindow } {
63
+ return {
64
+ current: windowOf(untilMs - WEEK_MS, untilMs),
65
+ previous: windowOf(untilMs - 2 * WEEK_MS, untilMs - WEEK_MS),
66
+ };
67
+ }
68
+
69
+ export interface WeeklyModelRow {
70
+ model: string;
71
+ calls: number;
72
+ usd: number;
73
+ }
74
+
75
+ export interface WeeklyMover {
76
+ model: string;
77
+ previousUsd: number;
78
+ currentUsd: number;
79
+ deltaUsd: number;
80
+ }
81
+
82
+ export interface WeeklyChange {
83
+ rank: number;
84
+ kind: PlanActionKind;
85
+ /** The workload, `UNLABELLED` when the log named none. */
86
+ label: string;
87
+ model: string;
88
+ /** Projected, for route and batch: not measured, and never rendered as if it were. */
89
+ projectedSavingUsd: number | null;
90
+ /** Measured: money already spent on the problem the change fixes. */
91
+ measuredStakeUsd: number | null;
92
+ /** What this workload and model cost this week, measured. Null when the plan did not record it. */
93
+ sliceUsd: number | null;
94
+ sliceCalls: number | null;
95
+ routeTo: string | null;
96
+ /** What the log cannot confirm about this change, as the plan states it. */
97
+ assumes: PlanAssumption[];
98
+ }
99
+
100
+ export interface WeeklySummary {
101
+ current: WeekWindow;
102
+ previous: WeekWindow;
103
+ /** This week's bill: what could be priced, and only that. */
104
+ totalUsd: number;
105
+ calls: number;
106
+ /** Priced models, largest first, at most `WEEKLY_MODELS`; `moreModels` counts the rest. */
107
+ models: WeeklyModelRow[];
108
+ moreModels: number;
109
+ unpricedModels: string[];
110
+ unpricedCalls: number;
111
+ /** Calls with no clock that a windowed report cannot place in any week. */
112
+ undatedExcluded: number;
113
+ /**
114
+ * Against the week before, or null when that week holds no call: a ratio
115
+ * against nothing is not a change, and the summary says there was no week
116
+ * to compare rather than print a number for it.
117
+ */
118
+ comparison: null | {
119
+ previousUsd: number;
120
+ previousCalls: number;
121
+ deltaUsd: number;
122
+ /** Null when the week before cost nothing priced: no percentage of zero. */
123
+ deltaPct: number | null;
124
+ movers: WeeklyMover[];
125
+ };
126
+ /** The first `WEEKLY_CHANGES` actions of the plan, largest money first. */
127
+ changes: WeeklyChange[];
128
+ /** How many actions the plan had in all. */
129
+ changesAvailable: number;
130
+ }
131
+
132
+ const pricedModels = (report: UsageProfileReport): WeeklyModelRow[] =>
133
+ report.byModel
134
+ .filter((row) => !report.unpricedModels.includes(row.model))
135
+ .map((row) => ({ model: row.model, calls: row.breakdown.calls, usd: row.breakdown.totalUsd }));
136
+
137
+ /**
138
+ * Builds the summary from the week's report, the week before's, and the plan
139
+ * made from this week's.
140
+ */
141
+ export function buildWeeklySummary(
142
+ current: UsageProfileReport,
143
+ previous: UsageProfileReport,
144
+ plan: PlanDocument,
145
+ windows: { current: WeekWindow; previous: WeekWindow },
146
+ ): WeeklySummary {
147
+ const models = pricedModels(current);
148
+
149
+ let comparison: WeeklySummary['comparison'] = null;
150
+ if (previous.total.calls > 0) {
151
+ const before = new Map(pricedModels(previous).map((row) => [row.model, row.usd]));
152
+ const now = new Map(models.map((row) => [row.model, row.usd]));
153
+ const movers: WeeklyMover[] = [...new Set([...before.keys(), ...now.keys()])]
154
+ .map((model) => {
155
+ const previousUsd = before.get(model) ?? 0;
156
+ const currentUsd = now.get(model) ?? 0;
157
+ return { model, previousUsd, currentUsd, deltaUsd: currentUsd - previousUsd };
158
+ })
159
+ .filter((row) => row.deltaUsd !== 0)
160
+ .sort((a, b) => Math.abs(b.deltaUsd) - Math.abs(a.deltaUsd) || a.model.localeCompare(b.model))
161
+ .slice(0, WEEKLY_MOVERS);
162
+ const previousUsd = previous.total.totalUsd;
163
+ const deltaUsd = current.total.totalUsd - previousUsd;
164
+ comparison = {
165
+ previousUsd,
166
+ previousCalls: previous.total.calls,
167
+ deltaUsd,
168
+ deltaPct: previousUsd > 0 ? (deltaUsd / previousUsd) * 100 : null,
169
+ movers,
170
+ };
171
+ }
172
+
173
+ const changes: WeeklyChange[] = plan.actions.slice(0, WEEKLY_CHANGES).map((action, index) => ({
174
+ rank: index + 1,
175
+ kind: action.kind,
176
+ label: action.label,
177
+ model: action.model,
178
+ projectedSavingUsd: action.savingUsd,
179
+ measuredStakeUsd: action.stakeUsd,
180
+ sliceUsd: action.detail.baseline?.usd ?? null,
181
+ sliceCalls: action.detail.baseline?.calls ?? null,
182
+ routeTo: action.detail.routeTo?.displayName ?? null,
183
+ assumes: [...action.assumes],
184
+ }));
185
+
186
+ return {
187
+ current: windows.current,
188
+ previous: windows.previous,
189
+ totalUsd: current.total.totalUsd,
190
+ calls: current.total.calls,
191
+ models: models.slice(0, WEEKLY_MODELS),
192
+ moreModels: Math.max(0, models.length - WEEKLY_MODELS),
193
+ unpricedModels: [...current.unpricedModels],
194
+ unpricedCalls: current.unpriced.calls,
195
+ undatedExcluded: current.timeWindow?.undatedExcluded ?? 0,
196
+ comparison,
197
+ changes,
198
+ changesAvailable: plan.actions.length,
199
+ };
200
+ }
201
+
202
+ /** The figures a summary may print, as the strings it prints them as. */
203
+ export interface BillFigures {
204
+ /** Every dollar amount, as `formatUsd` writes it and without a sign. */
205
+ usd: ReadonlySet<string>;
206
+ /** Every percentage, one decimal, without a sign and without the `%`. */
207
+ pct: ReadonlySet<string>;
208
+ }
209
+
210
+ /**
211
+ * What the reports hold, worked out from the reports.
212
+ *
213
+ * It reads the two reports and the plan directly and shares nothing with
214
+ * `buildWeeklySummary`, so a figure the builder gets wrong (a total scaled, a
215
+ * delta taken the wrong way round, a saving summed across actions that
216
+ * overlap) is not in this set and is named by `strayFigures`.
217
+ */
218
+ export function billFigures(
219
+ current: UsageProfileReport,
220
+ previous: UsageProfileReport,
221
+ plan: PlanDocument,
222
+ ): BillFigures {
223
+ const usd = new Set<string>(['$0']);
224
+ const pct = new Set<string>();
225
+ const add = (value: number | null | undefined): void => {
226
+ if (value === null || value === undefined || !Number.isFinite(value)) return;
227
+ usd.add(formatUsd(Math.abs(value)));
228
+ };
229
+
230
+ add(current.total.totalUsd);
231
+ add(previous.total.totalUsd);
232
+ add(current.total.totalUsd - previous.total.totalUsd);
233
+ const rows = (report: UsageProfileReport) => new Map(report.byModel.map((row) => [row.model, row.breakdown.totalUsd]));
234
+ const now = rows(current);
235
+ const before = rows(previous);
236
+ for (const model of new Set([...now.keys(), ...before.keys()])) {
237
+ const a = now.get(model) ?? 0;
238
+ const b = before.get(model) ?? 0;
239
+ add(a);
240
+ add(b);
241
+ add(a - b);
242
+ }
243
+ for (const action of plan.actions) {
244
+ add(action.savingUsd);
245
+ add(action.stakeUsd);
246
+ add(action.detail.baseline?.usd);
247
+ }
248
+ if (previous.total.totalUsd > 0) {
249
+ const change = ((current.total.totalUsd - previous.total.totalUsd) / previous.total.totalUsd) * 100;
250
+ pct.add(Math.abs(change).toFixed(1));
251
+ }
252
+ return { usd, pct };
253
+ }
254
+
255
+ /**
256
+ * Prose a reader sees as prose is checked; what names a workload, a model or a
257
+ * command is not. Those are written between backticks, and a label such as
258
+ * `50% off` is the author's word, not a figure Trazum computed.
259
+ */
260
+ const withoutCode = (text: string): string => text.replace(/`[^`\n]*`/g, '');
261
+
262
+ /**
263
+ * The dollar amounts and percentages in a rendered summary that no report
264
+ * holds. Empty when every one is accounted for.
265
+ */
266
+ export function strayFigures(markdown: string, figures: BillFigures): string[] {
267
+ const prose = withoutCode(markdown);
268
+ const stray: string[] = [];
269
+ for (const [amount] of prose.matchAll(/\$\d[\d,]*(?:\.\d+)?/g)) {
270
+ if (!figures.usd.has(amount)) stray.push(amount);
271
+ }
272
+ for (const [, number] of prose.matchAll(/(\d+(?:\.\d+)?)%/g)) {
273
+ if (number !== undefined && !figures.pct.has(number)) stray.push(`${number}%`);
274
+ }
275
+ return [...new Set(stray)];
276
+ }
277
+
278
+ /** The identifier a weekly summary carries so a re-run replaces it rather than adding a second. */
279
+ export function weeklyMarker(lastDay: string): string {
280
+ return `<!-- trazum-weekly:${lastDay} -->`;
281
+ }
package/src/write.ts CHANGED
@@ -83,7 +83,7 @@ export const OUTPUT_FORMATS = ['prose', 'json', 'list', 'table'] as const;
83
83
  export type OutputFormat = (typeof OUTPUT_FORMATS)[number];
84
84
 
85
85
  const answered = (answers: Answers, id: string): boolean =>
86
- Object.prototype.hasOwnProperty.call(answers, id) && answers[id] !== null;
86
+ Object.hasOwn(answers, id) && answers[id] !== null;
87
87
 
88
88
  const shapeIs = (...formats: readonly OutputFormat[]) => (answers: Answers): boolean => {
89
89
  const shape = answers['output-shape'];
@@ -155,7 +155,7 @@ export interface Interview {
155
155
 
156
156
  export function interview(answers: Answers): Interview {
157
157
  const open = SLOTS.filter((entry) => isOpen(entry, answers));
158
- const has = (entry: Slot) => Object.prototype.hasOwnProperty.call(answers, entry.id);
158
+ const has = (entry: Slot) => Object.hasOwn(answers, entry.id);
159
159
  const unasked = open.filter((entry) => !has(entry));
160
160
  return {
161
161
  next: unasked[0]?.id ?? null,