@trazum/core 3.0.0 → 3.0.2

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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/claude-model-pricing.d.ts +73 -0
  3. package/dist/claude-model-pricing.d.ts.map +1 -0
  4. package/dist/claude-model-pricing.js +208 -0
  5. package/dist/claude-model-pricing.js.map +1 -0
  6. package/dist/config-schema.d.ts +14 -1
  7. package/dist/config-schema.d.ts.map +1 -1
  8. package/dist/config-schema.js +24 -0
  9. package/dist/config-schema.js.map +1 -1
  10. package/dist/index.d.ts +13 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +10 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/node.d.ts +1 -1
  15. package/dist/node.d.ts.map +1 -1
  16. package/dist/node.js +1 -1
  17. package/dist/node.js.map +1 -1
  18. package/dist/otlp.d.ts +103 -0
  19. package/dist/otlp.d.ts.map +1 -1
  20. package/dist/otlp.js +185 -0
  21. package/dist/otlp.js.map +1 -1
  22. package/dist/partner-model-id.d.ts +26 -0
  23. package/dist/partner-model-id.d.ts.map +1 -0
  24. package/dist/partner-model-id.js +60 -0
  25. package/dist/partner-model-id.js.map +1 -0
  26. package/dist/plan-edit.d.ts +99 -0
  27. package/dist/plan-edit.d.ts.map +1 -0
  28. package/dist/plan-edit.js +142 -0
  29. package/dist/plan-edit.js.map +1 -0
  30. package/dist/plan.d.ts +63 -2
  31. package/dist/plan.d.ts.map +1 -1
  32. package/dist/plan.js +55 -0
  33. package/dist/plan.js.map +1 -1
  34. package/dist/pricing.d.ts +19 -0
  35. package/dist/pricing.d.ts.map +1 -1
  36. package/dist/pricing.js +32 -0
  37. package/dist/pricing.js.map +1 -1
  38. package/dist/prometheus.d.ts +42 -0
  39. package/dist/prometheus.d.ts.map +1 -0
  40. package/dist/prometheus.js +112 -0
  41. package/dist/prometheus.js.map +1 -0
  42. package/dist/receipt.d.ts +2 -1
  43. package/dist/receipt.d.ts.map +1 -1
  44. package/dist/receipt.js +11 -1
  45. package/dist/receipt.js.map +1 -1
  46. package/dist/session-waste.d.ts +145 -0
  47. package/dist/session-waste.d.ts.map +1 -0
  48. package/dist/session-waste.js +489 -0
  49. package/dist/session-waste.js.map +1 -0
  50. package/dist/structure.js +3 -3
  51. package/dist/structure.js.map +1 -1
  52. package/dist/tokenizer.d.ts +9 -0
  53. package/dist/tokenizer.d.ts.map +1 -1
  54. package/dist/tokenizer.js +1 -1
  55. package/dist/tokenizer.js.map +1 -1
  56. package/dist/verify.d.ts +11 -1
  57. package/dist/verify.d.ts.map +1 -1
  58. package/dist/verify.js +54 -0
  59. package/dist/verify.js.map +1 -1
  60. package/dist/walk.d.ts +14 -0
  61. package/dist/walk.d.ts.map +1 -1
  62. package/dist/walk.js +35 -0
  63. package/dist/walk.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/claude-model-pricing.ts +245 -0
  66. package/src/config-schema.ts +44 -0
  67. package/src/index.ts +46 -4
  68. package/src/node.ts +1 -1
  69. package/src/otlp.ts +281 -0
  70. package/src/partner-model-id.ts +69 -0
  71. package/src/plan-edit.ts +180 -0
  72. package/src/plan.ts +104 -3
  73. package/src/pricing.ts +33 -0
  74. package/src/prometheus.ts +131 -0
  75. package/src/receipt.ts +16 -2
  76. package/src/session-waste.ts +570 -0
  77. package/src/structure.ts +3 -3
  78. package/src/tokenizer.ts +1 -1
  79. package/src/verify.ts +78 -2
  80. package/src/walk.ts +33 -0
package/src/verify.ts CHANGED
@@ -32,7 +32,14 @@ export type VerifyOutcome = 'arrived' | 'not-arrived' | 'cannot-tell';
32
32
  * the fields the detection needs is the team's, and "not recorded" must not
33
33
  * read as "fixed".
34
34
  */
35
- export type CannotTellReason = 'workload-vanished' | 'fields-stopped' | 'tier-not-recorded';
35
+ export type CannotTellReason =
36
+ | 'workload-vanished'
37
+ | 'fields-stopped'
38
+ | 'tier-not-recorded'
39
+ /** An `edit-file` action, checked where nothing could read the file: a browser, an HTTP body. */
40
+ | 'file-not-read'
41
+ /** The file is neither the one the plan saw nor the one it promised: it moved on. */
42
+ | 'file-changed';
36
43
 
37
44
  export interface VerifiedAction {
38
45
  /** The plan's action, verbatim — the prediction being judged. */
@@ -111,14 +118,83 @@ function perCall(breakdown: { calls: number; inputTokens: number; cacheReadToken
111
118
  };
112
119
  }
113
120
 
121
+ /**
122
+ * An edit is checked twice: in the tree, then in the log.
123
+ *
124
+ * The file has to hold the text the plan promised, by hash. A file still
125
+ * holding the text the plan saw did not get the edit, which is a broken
126
+ * promise; a file holding something else moved on in a way the plan did not
127
+ * write, and that cannot be told, failing the gate the way a log that stopped
128
+ * recording its fields does. Then the workload's input per call in the newer
129
+ * log is held to the baseline the plan recorded: shorter is arrived, not
130
+ * shorter is not.
131
+ */
132
+ function verifyEdit(
133
+ action: PlanAction,
134
+ report: UsageProfileReport,
135
+ files: ReadonlyMap<string, string | null> | undefined,
136
+ ): VerifiedAction {
137
+ const edit = action.detail.edit;
138
+ const now = edit === undefined || files === undefined || !files.has(edit.path) ? undefined : files.get(edit.path);
139
+ if (edit === undefined || now === undefined) {
140
+ return { action, outcome: 'cannot-tell', reason: 'file-not-read', observed: {}, attribution: null, gateFailing: false };
141
+ }
142
+ if (now === edit.beforeSha256) {
143
+ return { action, outcome: 'not-arrived', reason: null, observed: { file: 'as-planned-from' }, attribution: null, gateFailing: true };
144
+ }
145
+ if (now !== edit.afterSha256) {
146
+ return {
147
+ action,
148
+ outcome: 'cannot-tell',
149
+ reason: 'file-changed',
150
+ observed: { file: now === null ? 'missing' : 'other' },
151
+ attribution: null,
152
+ gateFailing: true,
153
+ };
154
+ }
155
+ const slice = report.byLabelAndModel.find(
156
+ (s) => s.label === action.label && s.model === action.model && s.breakdown.calls > 0,
157
+ );
158
+ if (slice === undefined) {
159
+ return { action, outcome: 'cannot-tell', reason: 'workload-vanished', observed: { file: 'edited' }, attribution: null, gateFailing: false };
160
+ }
161
+ const after = perCall(slice.breakdown);
162
+ const before = action.detail.baseline?.inputPerCallTokens;
163
+ const shorter = before !== undefined && after.inputPerCallTokens < before;
164
+ return {
165
+ action,
166
+ outcome: shorter ? 'arrived' : 'not-arrived',
167
+ reason: null,
168
+ observed: {
169
+ file: 'edited',
170
+ inputPerCallTokens: after.inputPerCallTokens,
171
+ inputPerCallTokensBefore: before ?? null,
172
+ },
173
+ attribution: attributionFrom(action, after),
174
+ gateFailing: !shorter,
175
+ };
176
+ }
177
+
114
178
  export function verifyPlan(
115
179
  plan: PlanDocument & { createdAt?: string },
116
180
  report: UsageProfileReport,
117
- options: { currentPricingLastReviewed: string },
181
+ options: {
182
+ currentPricingLastReviewed: string;
183
+ /**
184
+ * For `edit-file` actions: the SHA-256 of each file as it is now, by the
185
+ * plan's path, or null for a file that is not there. Whoever can read
186
+ * the files supplies it; a path missing from it cannot be told.
187
+ */
188
+ files?: ReadonlyMap<string, string | null>;
189
+ },
118
190
  ): PlanVerification {
119
191
  const actions: VerifiedAction[] = [];
120
192
 
121
193
  for (const action of plan.actions) {
194
+ if (action.kind === 'edit-file') {
195
+ actions.push(verifyEdit(action, report, options.files));
196
+ continue;
197
+ }
122
198
  const slices = slicesForLabel(report, action.label);
123
199
  const total = slices.reduce((sum, s) => sum + s.breakdown.totalUsd, 0);
124
200
  const allCalls = slices.reduce((sum, s) => sum + s.breakdown.calls, 0);
package/src/walk.ts CHANGED
@@ -147,3 +147,36 @@ export async function walkPrompts(root: string, options: WalkOptions = {}): Prom
147
147
  files.sort();
148
148
  return { files, truncated };
149
149
  }
150
+
151
+ /**
152
+ * Whether `walkPrompts` would list this path, without reading a directory.
153
+ *
154
+ * `trazum check --base` (#785) lists the base branch's files from git, not
155
+ * from the disk, and has to keep exactly the ones the walk would have kept
156
+ * at the head: a file the walk skips at the head and this kept at the base
157
+ * would read as a prompt the pull request deleted. So the walk's rules are
158
+ * stated a second time here, beside the walk, and `walk-ignore.test.js`
159
+ * holds the two to the same answer over one tree.
160
+ *
161
+ * `relPath` is relative to the walk root, with `/` separators. The cap on
162
+ * the number of files is the walk's business and is not judged here.
163
+ */
164
+ export function walkIncludes(relPath: string, options: WalkOptions = {}): boolean {
165
+ const extensions = (options.extensions ?? DEFAULT_EXTENSIONS).map((value) => value.toLowerCase());
166
+ const maxDepth = options.maxDepth ?? MAX_WALK_DEPTH;
167
+ const ignore = options.ignore ?? [];
168
+ const excluded = (path: string): boolean =>
169
+ ignore.some((pattern) => matchGlob(pattern, path) || matchGlob(pattern, `${path}/`));
170
+
171
+ const segments = relPath.split('/');
172
+ const name = segments[segments.length - 1] ?? '';
173
+ if (segments.some((segment) => segment === '' || segment.startsWith('.'))) return false;
174
+ const directories = segments.slice(0, -1);
175
+ if (directories.length > maxDepth) return false;
176
+ for (let i = 0; i < directories.length; i++) {
177
+ if (SKIPPED_DIRECTORIES.has(directories[i]!)) return false;
178
+ if (excluded(directories.slice(0, i + 1).join('/'))) return false;
179
+ }
180
+ if (!extensions.includes(extname(name).toLowerCase())) return false;
181
+ return !excluded(relPath);
182
+ }