@hasna/todos 0.13.7 → 0.13.8

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.
package/dist/storage.js CHANGED
@@ -4336,6 +4336,7 @@ var init_database = __esm(() => {
4336
4336
 
4337
4337
  // src/lib/sync-utils.ts
4338
4338
  import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync, readdirSync, statSync, writeFileSync } from "fs";
4339
+ import { createHash } from "crypto";
4339
4340
  import { join as join2 } from "path";
4340
4341
  function getHomeDir() {
4341
4342
  return process.env["HOME"] || process.env["USERPROFILE"] || "~";
@@ -4391,7 +4392,40 @@ function appendSyncConflict(metadata, conflict, limit = 5) {
4391
4392
  const next = [conflict, ...current].slice(0, limit);
4392
4393
  return { ...metadata, sync_conflicts: next };
4393
4394
  }
4394
- var HOME;
4395
+ function canonicalize(value) {
4396
+ if (Array.isArray(value))
4397
+ return value.map(canonicalize);
4398
+ if (!value || typeof value !== "object")
4399
+ return value;
4400
+ const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== undefined).sort(([a], [b]) => a.localeCompare(b));
4401
+ return Object.fromEntries(entries.map(([key, entryValue]) => [key, canonicalize(entryValue)]));
4402
+ }
4403
+ function withoutSyncFingerprintMetadata(metadata) {
4404
+ const { [TODO_SYNC_FINGERPRINT_KEY]: _fingerprint, ...rest } = metadata;
4405
+ return rest;
4406
+ }
4407
+ function syncFingerprint(record) {
4408
+ const metadata = withoutSyncFingerprintMetadata(record.metadata || {});
4409
+ const canonical = canonicalize({ ...record, metadata });
4410
+ return `sha256:${createHash("sha256").update(JSON.stringify(canonical)).digest("hex")}`;
4411
+ }
4412
+ function withSyncFingerprint(record) {
4413
+ const metadata = withoutSyncFingerprintMetadata(record.metadata);
4414
+ return {
4415
+ ...record,
4416
+ metadata: {
4417
+ ...metadata,
4418
+ [TODO_SYNC_FINGERPRINT_KEY]: syncFingerprint({ ...record, metadata })
4419
+ }
4420
+ };
4421
+ }
4422
+ function hasSyncFingerprintChanged(record) {
4423
+ const stored = record.metadata?.[TODO_SYNC_FINGERPRINT_KEY];
4424
+ if (typeof stored !== "string" || stored.length === 0)
4425
+ return null;
4426
+ return stored !== syncFingerprint(record);
4427
+ }
4428
+ var TODO_SYNC_FINGERPRINT_KEY = "todos_sync_fingerprint", HOME;
4395
4429
  var init_sync_utils = __esm(() => {
4396
4430
  HOME = process.env["HOME"] || process.env["USERPROFILE"] || "~";
4397
4431
  });
@@ -5502,7 +5536,7 @@ var init_runner_sandbox = __esm(() => {
5502
5536
  });
5503
5537
 
5504
5538
  // src/lib/event-hooks.ts
5505
- import { createHash, randomUUID } from "crypto";
5539
+ import { createHash as createHash2, randomUUID } from "crypto";
5506
5540
  import { appendFileSync, mkdirSync as mkdirSync3 } from "fs";
5507
5541
  import { dirname as dirname3, resolve as resolve6 } from "path";
5508
5542
  import { createConnection } from "net";
@@ -5569,7 +5603,7 @@ function buildEnvelope(type, payload, timestamp2 = new Date().toISOString()) {
5569
5603
  payload: redactValue(payload ?? {}),
5570
5604
  source: { package: "@hasna/todos", local_only: true }
5571
5605
  };
5572
- const digest = createHash("sha256").update(canonicalEvent(base)).digest("hex");
5606
+ const digest = createHash2("sha256").update(canonicalEvent(base)).digest("hex");
5573
5607
  return { ...base, integrity: { algorithm: "sha256", digest } };
5574
5608
  }
5575
5609
  function summarize(value) {
@@ -7479,6 +7513,14 @@ var init_checklists = __esm(() => {
7479
7513
  init_database();
7480
7514
  });
7481
7515
 
7516
+ // src/lib/creator-identity.ts
7517
+ function canonicalAgentRef(value) {
7518
+ return value.trim().toLowerCase();
7519
+ }
7520
+ var init_creator_identity = __esm(() => {
7521
+ init_sync_utils();
7522
+ });
7523
+
7482
7524
  // src/lib/recurrence.ts
7483
7525
  function parseRecurrenceRule(rule) {
7484
7526
  const normalized = rule.trim().toLowerCase();
@@ -8185,6 +8227,11 @@ __export(exports_task_lifecycle, {
8185
8227
  claimOrSteal: () => claimOrSteal,
8186
8228
  claimNextTask: () => claimNextTask
8187
8229
  });
8230
+ function sameHolder(stored, incoming) {
8231
+ if (!stored || !incoming)
8232
+ return false;
8233
+ return canonicalAgentRef(stored) === canonicalAgentRef(incoming);
8234
+ }
8188
8235
  function lockExpiresAt(lockedAt) {
8189
8236
  if (!lockedAt)
8190
8237
  return null;
@@ -8235,13 +8282,13 @@ function startTask(id, agentId, db) {
8235
8282
  const cutoff = lockExpiryCutoff();
8236
8283
  const timestamp2 = now();
8237
8284
  const result = d.run(`UPDATE tasks SET status = 'in_progress', assigned_to = ?, locked_by = ?, locked_at = ?, started_at = COALESCE(started_at, ?), version = version + 1, updated_at = ?
8238
- WHERE id = ? AND status IN ('pending', 'in_progress') AND (locked_by IS NULL OR locked_by = ? OR locked_at < ?)`, [agentId, agentId, timestamp2, timestamp2, timestamp2, id, agentId, cutoff]);
8285
+ WHERE id = ? AND status IN ('pending', 'in_progress') AND (locked_by IS NULL OR LOWER(TRIM(locked_by)) = LOWER(TRIM(?)) OR locked_at < ?)`, [agentId, agentId, timestamp2, timestamp2, timestamp2, id, agentId, cutoff]);
8239
8286
  if (result.changes === 0) {
8240
8287
  const current = getTask(id, d);
8241
8288
  if (!current)
8242
8289
  throw new TaskNotFoundError(id);
8243
8290
  assertStartable(current, agentId);
8244
- if (current.locked_by && current.locked_by !== agentId && !isLockExpired(current.locked_at)) {
8291
+ if (current.locked_by && !sameHolder(current.locked_by, agentId) && !isLockExpired(current.locked_at)) {
8245
8292
  throw new LockError(id, current.locked_by);
8246
8293
  }
8247
8294
  throw new Error(`Task ${id} could not be started because it changed during claim`);
@@ -8266,7 +8313,7 @@ function completeTask(id, agentId, db, options) {
8266
8313
  if (task.status === "cancelled") {
8267
8314
  throw new Error(`Task ${id} is cancelled and cannot be completed`);
8268
8315
  }
8269
- if (agentId && task.locked_by && task.locked_by !== agentId && !isLockExpired(task.locked_at)) {
8316
+ if (agentId && task.locked_by && !sameHolder(task.locked_by, agentId) && !isLockExpired(task.locked_at)) {
8270
8317
  throw new LockError(id, task.locked_by);
8271
8318
  }
8272
8319
  checkCompletionGuard(task, agentId || null, d);
@@ -8388,16 +8435,16 @@ function lockTask(id, agentId, db) {
8388
8435
  error: `Task is ${task.status} and cannot be locked`
8389
8436
  };
8390
8437
  }
8391
- if (task.locked_by === agentId && !isLockExpired(task.locked_at)) {
8438
+ if (sameHolder(task.locked_by, agentId) && !isLockExpired(task.locked_at)) {
8392
8439
  const timestamp3 = now();
8393
- d.run(`UPDATE tasks SET locked_at = ?, updated_at = ?, version = version + 1 WHERE id = ? AND locked_by = ?`, [timestamp3, timestamp3, id, agentId]);
8440
+ d.run(`UPDATE tasks SET locked_at = ?, updated_at = ?, version = version + 1 WHERE id = ? AND LOWER(TRIM(locked_by)) = LOWER(TRIM(?))`, [timestamp3, timestamp3, id, agentId]);
8394
8441
  logTaskChange(id, "lock_renew", "locked_by", agentId, agentId, agentId, d);
8395
8442
  return { success: true, locked_by: agentId, locked_at: timestamp3, expires_at: lockExpiresAt(timestamp3) };
8396
8443
  }
8397
8444
  const cutoff = lockExpiryCutoff();
8398
8445
  const timestamp2 = now();
8399
8446
  const result = d.run(`UPDATE tasks SET locked_by = ?, locked_at = ?, version = version + 1, updated_at = ?
8400
- WHERE id = ? AND status NOT IN ('completed', 'cancelled') AND (locked_by IS NULL OR locked_by = ? OR locked_at < ?)`, [agentId, timestamp2, timestamp2, id, agentId, cutoff]);
8447
+ WHERE id = ? AND status NOT IN ('completed', 'cancelled') AND (locked_by IS NULL OR LOWER(TRIM(locked_by)) = LOWER(TRIM(?)) OR locked_at < ?)`, [agentId, timestamp2, timestamp2, id, agentId, cutoff]);
8401
8448
  if (result.changes === 0) {
8402
8449
  const current = getTask(id, d);
8403
8450
  if (!current)
@@ -8429,7 +8476,7 @@ function unlockTask(id, agentId, db) {
8429
8476
  const task = getTask(id, d);
8430
8477
  if (!task)
8431
8478
  throw new TaskNotFoundError(id);
8432
- if (agentId && task.locked_by && task.locked_by !== agentId) {
8479
+ if (agentId && task.locked_by && !sameHolder(task.locked_by, agentId)) {
8433
8480
  throw new LockError(id, task.locked_by);
8434
8481
  }
8435
8482
  const timestamp2 = now();
@@ -8722,6 +8769,7 @@ var MAX_SPAWN_DEPTH = 10;
8722
8769
  var init_task_lifecycle = __esm(() => {
8723
8770
  init_types();
8724
8771
  init_database();
8772
+ init_creator_identity();
8725
8773
  init_completion_guard();
8726
8774
  init_event_emission_safety();
8727
8775
  init_event_hooks();
@@ -10490,7 +10538,7 @@ var init_boards = __esm(() => {
10490
10538
  });
10491
10539
 
10492
10540
  // src/lib/artifact-store.ts
10493
- import { createHash as createHash2 } from "crypto";
10541
+ import { createHash as createHash3 } from "crypto";
10494
10542
  import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync3, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
10495
10543
  import { basename, dirname as dirname4, join as join5, resolve as resolve7 } from "path";
10496
10544
  import { tmpdir as tmpdir2 } from "os";
@@ -10515,7 +10563,7 @@ function artifactStorePath(relativePath) {
10515
10563
  return join5(artifactStoreRoot(), normalized);
10516
10564
  }
10517
10565
  function sha256(buffer) {
10518
- return createHash2("sha256").update(buffer).digest("hex");
10566
+ return createHash3("sha256").update(buffer).digest("hex");
10519
10567
  }
10520
10568
  function isTextLike(buffer, path) {
10521
10569
  if (buffer.includes(0))
@@ -16425,7 +16473,7 @@ function isCommentRedactionBackfillComplete(result) {
16425
16473
  return !result.dry_run && result.conflicts === 0 && result.remaining_candidates === 0;
16426
16474
  }
16427
16475
  // src/storage/s3-artifacts.ts
16428
- import { createHash as createHash3, createHmac as createHmac2 } from "crypto";
16476
+ import { createHash as createHash4, createHmac as createHmac2 } from "crypto";
16429
16477
  function createTodosS3ArtifactStore(options) {
16430
16478
  const requestFetch = options.fetch ?? fetch;
16431
16479
  const now3 = options.now ?? (() => new Date);
@@ -16597,7 +16645,7 @@ function toAmzDate(date) {
16597
16645
  return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
16598
16646
  }
16599
16647
  function sha256Hex(value) {
16600
- return createHash3("sha256").update(value).digest("hex");
16648
+ return createHash4("sha256").update(value).digest("hex");
16601
16649
  }
16602
16650
  function hmac(key, value) {
16603
16651
  return createHmac2("sha256", key).update(value).digest();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/todos",
3
- "version": "0.13.7",
3
+ "version": "0.13.8",
4
4
  "description": "Universal task management for AI coding agents - CLI + MCP server + interactive TUI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",