@juicesharp/rpiv-todo 2.14.2 → 2.15.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 (2) hide show
  1. package/package.json +2 -2
  2. package/state/replay.ts +25 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-todo",
3
- "version": "2.14.2",
3
+ "version": "2.15.0",
4
4
  "description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -71,6 +71,6 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@juicesharp/rpiv-config": "^2.14.2"
74
+ "@juicesharp/rpiv-config": "^2.15.0"
75
75
  }
76
76
  }
package/state/replay.ts CHANGED
@@ -1,15 +1,36 @@
1
- import type { TaskDetails } from "../tool/types.ts";
1
+ import type { Task, TaskDetails, TaskStatus } from "../tool/types.ts";
2
2
  import { EMPTY_STATE, type TaskState } from "./state.ts";
3
3
 
4
+ const TASK_STATUSES: ReadonlySet<unknown> = new Set<TaskStatus>(["pending", "in_progress", "completed", "deleted"]);
5
+
6
+ const optional = (value: unknown, valid: (v: unknown) => boolean): boolean => value === undefined || valid(value);
7
+ const isString = (v: unknown): boolean => typeof v === "string";
8
+
9
+ function isTask(value: unknown): value is Task {
10
+ if (!value || typeof value !== "object") return false;
11
+ const t = value as Record<string, unknown>;
12
+ return (
13
+ Number.isSafeInteger(t.id) &&
14
+ typeof t.subject === "string" &&
15
+ TASK_STATUSES.has(t.status) &&
16
+ optional(t.description, isString) &&
17
+ optional(t.activeForm, isString) &&
18
+ optional(t.owner, isString) &&
19
+ optional(t.blockedBy, (v) => Array.isArray(v) && v.every((id) => Number.isSafeInteger(id))) &&
20
+ optional(t.metadata, (v) => typeof v === "object" && v !== null)
21
+ );
22
+ }
23
+
4
24
  /**
5
25
  * Discriminator for `details` envelopes that match the persisted `TaskDetails`
6
- * shape. Defensive — branch entries from older or corrupt sessions are
7
- * skipped silently.
26
+ * shape, down to every task. Defensive — a snapshot from an older or corrupt
27
+ * session (e.g. a `tasks[]` another extension truncated with a marker string)
28
+ * is skipped whole, so replay keeps the last valid one.
8
29
  */
9
30
  export function isTaskDetails(value: unknown): value is TaskDetails {
10
31
  if (!value || typeof value !== "object") return false;
11
32
  const v = value as Record<string, unknown>;
12
- return Array.isArray(v.tasks) && typeof v.nextId === "number";
33
+ return Array.isArray(v.tasks) && v.tasks.every(isTask) && Number.isSafeInteger(v.nextId);
13
34
  }
14
35
 
15
36
  /** Fresh `TaskState` from a persisted snapshot — copies each task so replay never aliases branch data. */