@danforthh/aimprint-sync 1.0.0 → 1.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 (2) hide show
  1. package/dist/index.js +32 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -132,6 +132,16 @@ if (!WORKER_URL || !SYNC_TOKEN) {
132
132
  console.error(" SYNC_TOKEN=your-sync-token");
133
133
  process.exit(1);
134
134
  }
135
+ try {
136
+ const u = new URL(WORKER_URL);
137
+ if (u.protocol !== "https:" && u.hostname !== "localhost" && u.hostname !== "127.0.0.1") {
138
+ console.error(`Error: WORKER_URL must use https:// (got ${u.protocol})`);
139
+ process.exit(1);
140
+ }
141
+ } catch {
142
+ console.error("Error: WORKER_URL is not a valid URL");
143
+ process.exit(1);
144
+ }
135
145
  var CLAUDE_PROJECTS_DIR = import_node_path2.default.join(import_node_os2.default.homedir(), ".claude", "projects");
136
146
  var REAL_PROJECTS_DIR = (() => {
137
147
  try {
@@ -142,19 +152,24 @@ var REAL_PROJECTS_DIR = (() => {
142
152
  })();
143
153
  var MACHINE = import_node_os2.default.hostname();
144
154
  var BATCH_SIZE = 100;
145
- function estimateCost(model, input, output, cacheRead, cacheCreation) {
146
- const p = {
147
- "claude-fable-5": [10, 50, 1, 12.5],
148
- "claude-opus-4-8": [5, 25, 0.5, 6.25],
149
- "claude-opus-4-7": [5, 25, 0.5, 6.25],
150
- "claude-opus-4-6": [5, 25, 0.5, 6.25],
151
- "claude-opus-4-5": [5, 25, 0.5, 6.25],
152
- "claude-sonnet-4-6": [3, 15, 0.3, 3.75],
153
- "claude-sonnet-4-5": [3, 15, 0.3, 3.75],
154
- "claude-haiku-4-5": [1, 5, 0.1, 1.25]
155
- };
156
- const [pi, po, pr, pc] = p[model] ?? [3, 15, 0.3, 3.75];
157
- return (input * pi + output * po + cacheRead * pr + cacheCreation * pc) / 1e6;
155
+ function detectLineSepSize(filePath) {
156
+ const buf = Buffer.alloc(1024);
157
+ let fd;
158
+ try {
159
+ fd = import_node_fs2.default.openSync(filePath, "r");
160
+ const n = import_node_fs2.default.readSync(fd, buf, 0, 1024, 0);
161
+ for (let i = 0; i < n - 1; i++) {
162
+ if (buf[i] === 13 && buf[i + 1] === 10) return 2;
163
+ }
164
+ return 1;
165
+ } catch {
166
+ return 1;
167
+ } finally {
168
+ if (fd !== void 0) try {
169
+ import_node_fs2.default.closeSync(fd);
170
+ } catch {
171
+ }
172
+ }
158
173
  }
159
174
  var TICKET_RE = /\b(PROTOP-\d+|PORTV4-\d+|NODE20-\d+)\b/i;
160
175
  function extractTicket(branch) {
@@ -165,6 +180,7 @@ function extractTicket(branch) {
165
180
  async function parseFile(filePath, offset) {
166
181
  const stat = import_node_fs2.default.statSync(filePath);
167
182
  if (stat.size <= offset) return { records: /* @__PURE__ */ new Map(), sessions: /* @__PURE__ */ new Map(), newOffset: offset };
183
+ const sepSize = detectLineSepSize(filePath);
168
184
  const fd = import_node_fs2.default.openSync(filePath, "r");
169
185
  const stream = import_node_fs2.default.createReadStream(filePath, { start: offset, fd, autoClose: true });
170
186
  const rl = import_node_readline.default.createInterface({ input: stream, crlfDelay: Infinity });
@@ -173,7 +189,7 @@ async function parseFile(filePath, offset) {
173
189
  let newOffset = offset;
174
190
  const lastUserMessage = /* @__PURE__ */ new Map();
175
191
  for await (const line of rl) {
176
- newOffset += Buffer.byteLength(line + "\n");
192
+ newOffset += Buffer.byteLength(line) + sepSize;
177
193
  if (!line.trim()) continue;
178
194
  let d;
179
195
  try {
@@ -273,7 +289,8 @@ async function parseFile(filePath, offset) {
273
289
  cache_read: cacheR,
274
290
  cache_creation: cacheC,
275
291
  is_sidechain: d.isSidechain ? 1 : 0,
276
- cost_usd: estimateCost(sess.model, input, output, cacheR, cacheC),
292
+ cost_usd: 0,
293
+ // worker recomputes server-side from its own pricing table
277
294
  request_category: reqCategory
278
295
  });
279
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danforthh/aimprint-sync",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Sync Claude Code token logs to your Aimprint dashboard",
5
5
  "type": "commonjs",
6
6
  "bin": {