things-api 0.8.0 → 0.10.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 (238) hide show
  1. package/README.md +31 -11
  2. package/dist/audit/log.js +56 -2
  3. package/dist/audit/log.js.map +1 -1
  4. package/dist/audit/schema.d.ts +26 -8
  5. package/dist/audit/schema.js +42 -1
  6. package/dist/audit/schema.js.map +1 -1
  7. package/dist/cli/commands/area.d.ts +34 -2
  8. package/dist/cli/commands/area.js +140 -28
  9. package/dist/cli/commands/area.js.map +1 -1
  10. package/dist/cli/commands/doctor.d.ts +1 -1
  11. package/dist/cli/commands/doctor.js +44 -5
  12. package/dist/cli/commands/doctor.js.map +1 -1
  13. package/dist/cli/commands/mcp.js +23 -4
  14. package/dist/cli/commands/mcp.js.map +1 -1
  15. package/dist/cli/commands/project.d.ts +23 -1
  16. package/dist/cli/commands/project.js +82 -15
  17. package/dist/cli/commands/project.js.map +1 -1
  18. package/dist/cli/commands/reads.d.ts +6 -125
  19. package/dist/cli/commands/reads.js +649 -657
  20. package/dist/cli/commands/reads.js.map +1 -1
  21. package/dist/cli/commands/repeat-flags.d.ts +20 -0
  22. package/dist/cli/commands/repeat-flags.js +76 -0
  23. package/dist/cli/commands/repeat-flags.js.map +1 -0
  24. package/dist/cli/commands/setup.js +2 -3
  25. package/dist/cli/commands/setup.js.map +1 -1
  26. package/dist/cli/commands/show.d.ts +1 -1
  27. package/dist/cli/commands/show.js +169 -18
  28. package/dist/cli/commands/show.js.map +1 -1
  29. package/dist/cli/commands/snapshot.js +1 -1
  30. package/dist/cli/commands/snapshot.js.map +1 -1
  31. package/dist/cli/commands/todo.d.ts +1 -1
  32. package/dist/cli/commands/todo.js +21 -9
  33. package/dist/cli/commands/todo.js.map +1 -1
  34. package/dist/cli/commands/writes.js +378 -148
  35. package/dist/cli/commands/writes.js.map +1 -1
  36. package/dist/cli/did-you-mean.d.ts +29 -0
  37. package/dist/cli/did-you-mean.js +53 -0
  38. package/dist/cli/did-you-mean.js.map +1 -0
  39. package/dist/cli/excess-args.d.ts +15 -0
  40. package/dist/cli/excess-args.js +51 -0
  41. package/dist/cli/excess-args.js.map +1 -0
  42. package/dist/cli/glyphs.d.ts +67 -7
  43. package/dist/cli/glyphs.js +202 -19
  44. package/dist/cli/glyphs.js.map +1 -1
  45. package/dist/cli/help.d.ts +54 -0
  46. package/dist/cli/help.js +355 -0
  47. package/dist/cli/help.js.map +1 -0
  48. package/dist/cli/main.js +36 -21
  49. package/dist/cli/main.js.map +1 -1
  50. package/dist/cli/period.d.ts +39 -0
  51. package/dist/cli/period.js +141 -0
  52. package/dist/cli/period.js.map +1 -0
  53. package/dist/cli/read-driver.d.ts +83 -0
  54. package/dist/cli/read-driver.js +215 -0
  55. package/dist/cli/read-driver.js.map +1 -0
  56. package/dist/cli/render.d.ts +246 -0
  57. package/dist/cli/render.js +806 -0
  58. package/dist/cli/render.js.map +1 -0
  59. package/dist/cli/resolve-invocation.d.ts +116 -0
  60. package/dist/cli/resolve-invocation.js +261 -0
  61. package/dist/cli/resolve-invocation.js.map +1 -0
  62. package/dist/cli/shell-quote.d.ts +9 -0
  63. package/dist/cli/shell-quote.js +12 -0
  64. package/dist/cli/shell-quote.js.map +1 -0
  65. package/dist/cli/tag-filters.d.ts +59 -0
  66. package/dist/cli/tag-filters.js +57 -0
  67. package/dist/cli/tag-filters.js.map +1 -0
  68. package/dist/cli/verb-hint.d.ts +25 -0
  69. package/dist/cli/verb-hint.js +138 -0
  70. package/dist/cli/verb-hint.js.map +1 -0
  71. package/dist/cli/width.d.ts +135 -0
  72. package/dist/cli/width.js +313 -0
  73. package/dist/cli/width.js.map +1 -0
  74. package/dist/client.d.ts +146 -24
  75. package/dist/client.js +106 -16
  76. package/dist/client.js.map +1 -1
  77. package/dist/config.d.ts +11 -0
  78. package/dist/config.js +3 -0
  79. package/dist/config.js.map +1 -1
  80. package/dist/contracts.d.ts +136 -1
  81. package/dist/contracts.js +44 -1
  82. package/dist/contracts.js.map +1 -1
  83. package/dist/db/fingerprint.d.ts +12 -0
  84. package/dist/db/fingerprint.js +15 -1
  85. package/dist/db/fingerprint.js.map +1 -1
  86. package/dist/db/locate.js +1 -1
  87. package/dist/db/locate.js.map +1 -1
  88. package/dist/diagnose.d.ts +63 -0
  89. package/dist/diagnose.js +38 -1
  90. package/dist/diagnose.js.map +1 -1
  91. package/dist/index.d.ts +30 -4
  92. package/dist/index.js +35 -2
  93. package/dist/index.js.map +1 -1
  94. package/dist/mcp/server.d.ts +9 -1
  95. package/dist/mcp/server.js +850 -128
  96. package/dist/mcp/server.js.map +1 -1
  97. package/dist/model/entities.d.ts +40 -7
  98. package/dist/model/entities.js.map +1 -1
  99. package/dist/model/mappers.d.ts +7 -0
  100. package/dist/model/mappers.js +20 -3
  101. package/dist/model/mappers.js.map +1 -1
  102. package/dist/model/occurrences.d.ts +6 -1
  103. package/dist/model/occurrences.js +9 -5
  104. package/dist/model/occurrences.js.map +1 -1
  105. package/dist/model/recurrence.d.ts +17 -8
  106. package/dist/model/recurrence.js.map +1 -1
  107. package/dist/model/serialize.d.ts +28 -0
  108. package/dist/model/serialize.js +80 -0
  109. package/dist/model/serialize.js.map +1 -0
  110. package/dist/model/when-sugar.d.ts +47 -0
  111. package/dist/model/when-sugar.js +45 -0
  112. package/dist/model/when-sugar.js.map +1 -0
  113. package/dist/read/area-view.d.ts +8 -1
  114. package/dist/read/area-view.js +49 -13
  115. package/dist/read/area-view.js.map +1 -1
  116. package/dist/read/caps.d.ts +14 -0
  117. package/dist/read/caps.js +21 -0
  118. package/dist/read/caps.js.map +1 -0
  119. package/dist/read/filter-contract.d.ts +117 -0
  120. package/dist/read/filter-contract.js +78 -0
  121. package/dist/read/filter-contract.js.map +1 -0
  122. package/dist/read/log-boundary.d.ts +9 -4
  123. package/dist/read/log-boundary.js.map +1 -1
  124. package/dist/read/predicates.d.ts +61 -0
  125. package/dist/read/predicates.js +78 -0
  126. package/dist/read/predicates.js.map +1 -0
  127. package/dist/read/project-view.d.ts +12 -1
  128. package/dist/read/project-view.js +39 -8
  129. package/dist/read/project-view.js.map +1 -1
  130. package/dist/read/queries.d.ts +156 -8
  131. package/dist/read/queries.js +261 -38
  132. package/dist/read/queries.js.map +1 -1
  133. package/dist/read/search-rank.d.ts +36 -0
  134. package/dist/read/search-rank.js +31 -0
  135. package/dist/read/search-rank.js.map +1 -0
  136. package/dist/read/sections.d.ts +51 -0
  137. package/dist/read/sections.js +37 -0
  138. package/dist/read/sections.js.map +1 -0
  139. package/dist/read/show-target.d.ts +13 -4
  140. package/dist/read/show-target.js +11 -2
  141. package/dist/read/show-target.js.map +1 -1
  142. package/dist/read/sidebar-order.d.ts +19 -0
  143. package/dist/read/sidebar-order.js +93 -0
  144. package/dist/read/sidebar-order.js.map +1 -0
  145. package/dist/read/tags.d.ts +27 -3
  146. package/dist/read/tags.js +83 -12
  147. package/dist/read/tags.js.map +1 -1
  148. package/dist/read/truncation.d.ts +71 -0
  149. package/dist/read/truncation.js +217 -0
  150. package/dist/read/truncation.js.map +1 -0
  151. package/dist/read/views.d.ts +177 -19
  152. package/dist/read/views.js +390 -213
  153. package/dist/read/views.js.map +1 -1
  154. package/dist/surface-copy.d.ts +42 -0
  155. package/dist/surface-copy.js +55 -0
  156. package/dist/surface-copy.js.map +1 -1
  157. package/dist/sync-health.d.ts +78 -0
  158. package/dist/sync-health.js +312 -0
  159. package/dist/sync-health.js.map +1 -0
  160. package/dist/write/accessibility-probe.d.ts +12 -0
  161. package/dist/write/accessibility-probe.js +63 -0
  162. package/dist/write/accessibility-probe.js.map +1 -0
  163. package/dist/write/automation-probe.d.ts +7 -0
  164. package/dist/write/automation-probe.js +8 -1
  165. package/dist/write/automation-probe.js.map +1 -1
  166. package/dist/write/batch.js +4 -2
  167. package/dist/write/batch.js.map +1 -1
  168. package/dist/write/capabilities.d.ts +8 -0
  169. package/dist/write/capabilities.js +13 -5
  170. package/dist/write/capabilities.js.map +1 -1
  171. package/dist/write/commands.d.ts +2 -0
  172. package/dist/write/commands.js +562 -48
  173. package/dist/write/commands.js.map +1 -1
  174. package/dist/write/edit-checklist.js +3 -2
  175. package/dist/write/edit-checklist.js.map +1 -1
  176. package/dist/write/guards.d.ts +2 -7
  177. package/dist/write/guards.js +64 -6
  178. package/dist/write/guards.js.map +1 -1
  179. package/dist/write/heading.js +2 -0
  180. package/dist/write/heading.js.map +1 -1
  181. package/dist/write/lock.d.ts +40 -2
  182. package/dist/write/lock.js +91 -14
  183. package/dist/write/lock.js.map +1 -1
  184. package/dist/write/make-repeating-project.d.ts +4 -0
  185. package/dist/write/make-repeating-project.js +253 -0
  186. package/dist/write/make-repeating-project.js.map +1 -0
  187. package/dist/write/operations.d.ts +145 -1
  188. package/dist/write/operations.js +48 -0
  189. package/dist/write/operations.js.map +1 -1
  190. package/dist/write/pipeline.d.ts +19 -0
  191. package/dist/write/pipeline.js +109 -26
  192. package/dist/write/pipeline.js.map +1 -1
  193. package/dist/write/pre-state.d.ts +68 -3
  194. package/dist/write/pre-state.js +102 -3
  195. package/dist/write/pre-state.js.map +1 -1
  196. package/dist/write/reopen.js +3 -2
  197. package/dist/write/reopen.js.map +1 -1
  198. package/dist/write/reorder.js +27 -17
  199. package/dist/write/reorder.js.map +1 -1
  200. package/dist/write/repeat-rule.d.ts +22 -0
  201. package/dist/write/repeat-rule.js +258 -0
  202. package/dist/write/repeat-rule.js.map +1 -0
  203. package/dist/write/reversibility.js +49 -0
  204. package/dist/write/reversibility.js.map +1 -1
  205. package/dist/write/tag-refs.d.ts +47 -0
  206. package/dist/write/tag-refs.js +126 -0
  207. package/dist/write/tag-refs.js.map +1 -0
  208. package/dist/write/undo.d.ts +74 -5
  209. package/dist/write/undo.js +494 -80
  210. package/dist/write/undo.js.map +1 -1
  211. package/dist/write/vectors/registry.d.ts +17 -1
  212. package/dist/write/vectors/registry.js +18 -2
  213. package/dist/write/vectors/registry.js.map +1 -1
  214. package/dist/write/vectors/types.d.ts +119 -3
  215. package/dist/write/vectors/ui-certification.d.ts +48 -0
  216. package/dist/write/vectors/ui-certification.js +46 -0
  217. package/dist/write/vectors/ui-certification.js.map +1 -0
  218. package/dist/write/vectors/ui-drag.d.ts +188 -0
  219. package/dist/write/vectors/ui-drag.js +1095 -0
  220. package/dist/write/vectors/ui-drag.js.map +1 -0
  221. package/dist/write/vectors/ui-recipes.d.ts +70 -0
  222. package/dist/write/vectors/ui-recipes.js +558 -0
  223. package/dist/write/vectors/ui-recipes.js.map +1 -0
  224. package/dist/write/vectors/ui.d.ts +137 -0
  225. package/dist/write/vectors/ui.js +656 -0
  226. package/dist/write/vectors/ui.js.map +1 -0
  227. package/dist/write/verify/delta.d.ts +31 -3
  228. package/dist/write/verify/delta.js +22 -6
  229. package/dist/write/verify/delta.js.map +1 -1
  230. package/dist/write/verify/poller.js +1 -0
  231. package/dist/write/verify/poller.js.map +1 -1
  232. package/package.json +1 -1
  233. package/dist/cli/exit-codes.d.ts +0 -26
  234. package/dist/cli/exit-codes.js +0 -26
  235. package/dist/cli/exit-codes.js.map +0 -1
  236. package/dist/cli/output.d.ts +0 -42
  237. package/dist/cli/output.js +0 -16
  238. package/dist/cli/output.js.map +0 -1
@@ -0,0 +1,258 @@
1
+ import { WEEKDAYS, } from "./operations.js";
2
+ const FREQUENCIES = ["daily", "weekly", "monthly", "yearly"];
3
+ /** Weekday name → rule encoding (wd 0 = Sunday). */
4
+ export const WEEKDAY_TO_WD = {
5
+ sunday: 0,
6
+ monday: 1,
7
+ tuesday: 2,
8
+ wednesday: 3,
9
+ thursday: 4,
10
+ friday: 5,
11
+ saturday: 6,
12
+ };
13
+ /** Rule encoding (wd 0..6) → weekday name. */
14
+ export const WD_TO_WEEKDAY = Object.fromEntries(Object.entries(WEEKDAY_TO_WD).map(([name, wd]) => [wd, name]));
15
+ // --------------------------------------------------------------- validation
16
+ function isRecord(v) {
17
+ return typeof v === "object" && v !== null;
18
+ }
19
+ function assertOrdinal(ordinal, where) {
20
+ if (ordinal === "last")
21
+ return;
22
+ if (!Number.isInteger(ordinal) || ordinal < 1 || ordinal > 5) {
23
+ throw new RangeError(`invalid ${where} ordinal ${JSON.stringify(ordinal)} — expected 1–5 or "last"`);
24
+ }
25
+ }
26
+ function assertWeekday(day, where) {
27
+ if (typeof day !== "string" || !WEEKDAYS.includes(day)) {
28
+ throw new RangeError(`invalid ${where} weekday ${JSON.stringify(day)} — expected ${WEEKDAYS.join(" | ")}`);
29
+ }
30
+ }
31
+ /** Validate a month/year day anchor (shared by monthly + yearly). */
32
+ function assertMonthlyAnchor(anchor, where) {
33
+ if (!isRecord(anchor)) {
34
+ throw new RangeError(`${where} must be a day-of-month or nth-weekday anchor`);
35
+ }
36
+ const hasDay = "day" in anchor;
37
+ const hasWeekday = "weekday" in anchor || "ordinal" in anchor;
38
+ if (hasDay && hasWeekday) {
39
+ throw new RangeError(`${where} names both a day-of-month and a weekday — choose one (a day, OR a weekday + ordinal)`);
40
+ }
41
+ if (hasDay) {
42
+ const day = anchor["day"];
43
+ if (day === "last")
44
+ return;
45
+ if (!Number.isInteger(day) || day < 1 || day > 31) {
46
+ throw new RangeError(`invalid ${where} day ${JSON.stringify(day)} — expected 1–31 or "last"`);
47
+ }
48
+ return;
49
+ }
50
+ if (hasWeekday) {
51
+ assertWeekday(anchor["weekday"], where);
52
+ assertOrdinal(anchor["ordinal"], where);
53
+ return;
54
+ }
55
+ throw new RangeError(`${where} must name a day-of-month or a weekday + ordinal`);
56
+ }
57
+ function assertEnds(ends) {
58
+ switch (ends.kind) {
59
+ case "never":
60
+ return;
61
+ case "on-date":
62
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(ends.date)) {
63
+ throw new RangeError(`invalid ends date ${JSON.stringify(ends.date)} — expected YYYY-MM-DD`);
64
+ }
65
+ return;
66
+ case "after":
67
+ if (!Number.isInteger(ends.count) || ends.count < 1 || ends.count > 999) {
68
+ throw new RangeError(`invalid ends count ${ends.count} — expected an integer 1–999`);
69
+ }
70
+ return;
71
+ default: {
72
+ const exhaustive = ends;
73
+ throw new RangeError(`unknown ends bound ${JSON.stringify(exhaustive)}`);
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * Validate the full extended rule vocabulary. The base `{ frequency, interval }`
79
+ * is always checked; every optional field is checked and REFUSED when it does
80
+ * not apply to the chosen frequency (or contradicts another field). Throws a
81
+ * RangeError with a behavioral message on any violation.
82
+ */
83
+ export function assertRepeatRule(params) {
84
+ if (!FREQUENCIES.includes(params.frequency)) {
85
+ throw new RangeError(`invalid frequency "${params.frequency}" — expected ${FREQUENCIES.join(" | ")}`);
86
+ }
87
+ if (!Number.isInteger(params.interval) || params.interval < 1 || params.interval > 99) {
88
+ throw new RangeError(`invalid interval ${params.interval} — expected an integer 1–99`);
89
+ }
90
+ // After-completion has no calendar anchor: the day-of-week / monthly / yearly
91
+ // placements are meaningless when the next date is "N units after completion".
92
+ if (params.afterCompletion === true) {
93
+ if (params.weekdays !== undefined ||
94
+ params.monthly !== undefined ||
95
+ params.yearly !== undefined) {
96
+ throw new RangeError("an after-completion rule has no calendar day — remove weekdays/monthly/yearly, or drop afterCompletion for a fixed schedule");
97
+ }
98
+ }
99
+ if (params.weekdays !== undefined) {
100
+ if (params.frequency !== "weekly") {
101
+ throw new RangeError("weekdays apply only to a weekly rule");
102
+ }
103
+ if (params.weekdays.length === 0) {
104
+ throw new RangeError("weekdays must name at least one day");
105
+ }
106
+ const seen = new Set();
107
+ for (const day of params.weekdays) {
108
+ assertWeekday(day, "weekdays");
109
+ if (seen.has(day))
110
+ throw new RangeError(`weekdays repeats "${day}"`);
111
+ seen.add(day);
112
+ }
113
+ }
114
+ if (params.monthly !== undefined) {
115
+ if (params.frequency !== "monthly") {
116
+ throw new RangeError("monthly anchor applies only to a monthly rule");
117
+ }
118
+ assertMonthlyAnchor(params.monthly, "monthly");
119
+ }
120
+ if (params.yearly !== undefined) {
121
+ if (params.frequency !== "yearly") {
122
+ throw new RangeError("yearly anchor applies only to a yearly rule");
123
+ }
124
+ const month = params.yearly.month;
125
+ if (!Number.isInteger(month) || month < 1 || month > 12) {
126
+ throw new RangeError(`invalid yearly month ${JSON.stringify(month)} — expected 1–12`);
127
+ }
128
+ assertMonthlyAnchor(params.yearly, "yearly");
129
+ }
130
+ if (params.ends !== undefined)
131
+ assertEnds(params.ends);
132
+ if (params.reminder !== undefined) {
133
+ if (!/^\d{1,2}:\d{2}$/.test(params.reminder)) {
134
+ throw new RangeError(`invalid reminder ${JSON.stringify(params.reminder)} — expected HH:mm`);
135
+ }
136
+ // UIC6-g: the Repeat dialog's reminder-time control is an AXDateTimeArea
137
+ // whose committed time CANNOT be set through the Accessibility surface —
138
+ // it ignores AXValue writes (unlike the "ends on date" picker, which
139
+ // honors them) and silently commits its default instead. Rather than write
140
+ // a WRONG reminder time, the op refuses. (Set the reminder in the app after
141
+ // the series exists; every other rule field IS drivable.) See
142
+ // docs/lab/uic6-rule-vocabulary.md and docs/things-app-oddities.md.
143
+ throw new RangeError("a repeat reminder time cannot be set through the GUI vector — Things' reminder picker " +
144
+ "ignores programmatic time entry (UIC6-g); create the series without --reminder and set the " +
145
+ "reminder in the app");
146
+ }
147
+ if (params.startDaysEarlier !== undefined) {
148
+ if (!Number.isInteger(params.startDaysEarlier) || params.startDaysEarlier < 0) {
149
+ throw new RangeError(`invalid startDaysEarlier ${params.startDaysEarlier} — expected an integer ≥ 0`);
150
+ }
151
+ if (params.startDaysEarlier > 0 && params.deadline === false) {
152
+ throw new RangeError("startDaysEarlier requires a deadline (it counts days before the deadline)");
153
+ }
154
+ }
155
+ }
156
+ /** The mutually-exclusive Ends bound of a decoded rule, or null if inexpressible. */
157
+ function endsOf(rule) {
158
+ const hasDate = rule.endDate !== null;
159
+ const hasCount = rule.remainingCount !== null;
160
+ if (hasDate && hasCount)
161
+ return null; // dialog's Ends is single-choice
162
+ if (hasDate)
163
+ return { ends: { kind: "on-date", date: rule.endDate } };
164
+ if (hasCount)
165
+ return { ends: { kind: "after", count: rule.remainingCount } };
166
+ return { ends: { kind: "never" } };
167
+ }
168
+ function monthlyAnchorOf(offset) {
169
+ if (offset.weekday !== undefined) {
170
+ const weekday = WD_TO_WEEKDAY[offset.weekday];
171
+ if (weekday === undefined)
172
+ return null;
173
+ const ord = offset.weekdayOrdinal ?? 1;
174
+ const ordinal = ord === -1 ? "last" : ord;
175
+ if (ordinal !== "last" && (ordinal < 1 || ordinal > 5))
176
+ return null;
177
+ return { weekday, ordinal };
178
+ }
179
+ if (offset.day !== undefined) {
180
+ return { day: offset.day === -1 ? "last" : offset.day };
181
+ }
182
+ return null;
183
+ }
184
+ /**
185
+ * Map a decoded prior rule (+ the template's deadline flag) back onto the
186
+ * extended vocabulary, or return null when the rule falls OUTSIDE what the
187
+ * Repeat dialog can express (the faithfulness boundary — see reversibility.ts).
188
+ * `reminder` is NOT part of the rule blob, so it is never restored here (a
189
+ * documented limitation of the reschedule inverse).
190
+ */
191
+ export function ruleToInverseParams(rule, deadlined) {
192
+ const fields = { frequency: rule.unit, interval: rule.interval };
193
+ const ends = endsOf(rule);
194
+ if (ends === null)
195
+ return null;
196
+ if (ends.ends.kind !== "never")
197
+ fields.ends = ends.ends;
198
+ const afterCompletion = rule.type === "after-completion";
199
+ // Calendar anchors from the offsets.
200
+ const meaningful = rule.offsets.filter((o) => o.day !== undefined || o.weekday !== undefined || o.month !== undefined);
201
+ if (afterCompletion) {
202
+ // After-completion has no calendar anchor in the dialog, so the user can
203
+ // never set one — but Things still writes a NOMINAL offset for the unit
204
+ // (UIC6-e: a weekly-unit after-completion rule carries of=[{wd:0}], a
205
+ // monthly one of=[{dy:0}], etc.). That offset is not user-meaningful and is
206
+ // never round-tripped, so it is IGNORED here (an earlier assumption that
207
+ // after-completion rules carry no offsets was wrong — it would have made
208
+ // every after-completion reschedule-undo spuriously irreversible).
209
+ fields.afterCompletion = true;
210
+ }
211
+ else if (rule.unit === "weekly") {
212
+ const weekdays = [];
213
+ for (const o of meaningful) {
214
+ if (o.weekday === undefined)
215
+ return null;
216
+ const name = WD_TO_WEEKDAY[o.weekday];
217
+ if (name === undefined)
218
+ return null;
219
+ weekdays.push(name);
220
+ }
221
+ if (weekdays.length > 0)
222
+ fields.weekdays = weekdays;
223
+ }
224
+ else if (rule.unit === "monthly") {
225
+ if (meaningful.length > 1)
226
+ return null; // dialog sets ONE monthly anchor
227
+ const only = meaningful[0];
228
+ if (only !== undefined) {
229
+ const anchor = monthlyAnchorOf(only);
230
+ if (anchor === null)
231
+ return null;
232
+ fields.monthly = anchor;
233
+ }
234
+ }
235
+ else if (rule.unit === "yearly") {
236
+ if (meaningful.length > 1)
237
+ return null;
238
+ const only = meaningful[0];
239
+ if (only !== undefined) {
240
+ if (only.month === undefined)
241
+ return null;
242
+ const anchor = monthlyAnchorOf(only);
243
+ if (anchor === null)
244
+ return null;
245
+ fields.yearly = { month: only.month, ...anchor };
246
+ }
247
+ }
248
+ // daily: no offsets.
249
+ // Deadline + start-earlier: ts ≤ 0 in the rule; deadline-ness from the column.
250
+ if (deadlined)
251
+ fields.deadline = true;
252
+ if (rule.startOffsetDays < 0) {
253
+ fields.deadline = true;
254
+ fields.startDaysEarlier = -rule.startOffsetDays;
255
+ }
256
+ return fields;
257
+ }
258
+ //# sourceMappingURL=repeat-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repeat-rule.js","sourceRoot":"","sources":["../../src/write/repeat-rule.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,QAAQ,GAQT,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,GAA+B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEzF,oDAAoD;AACpD,MAAM,CAAC,MAAM,aAAa,GAA4B;IACpD,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF,8CAA8C;AA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C7B,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,gBAAgB,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -125,6 +125,10 @@ export const REVERSIBILITY = {
125
125
  class: "conditional",
126
126
  note: "invertible when pre-ranks were captured (native reorders + bounce summaries that recorded pre-ranks); irreversible for bounce summaries with no recorded pre-ranks",
127
127
  },
128
+ "area.reorder": {
129
+ class: "conditional",
130
+ note: "invertible when the pre-move area order was fully determined (the full ordered area list is captured; the inverse drags the area back before its old successor — order is the invariant that round-trips, index values are not, AXDRAG1-f); irreversible when areas were still unranked (all-zero index) before the move",
131
+ },
128
132
  // ---- headings -----------------------------------------------------------
129
133
  "heading.archive": {
130
134
  class: "reversible-with-loss",
@@ -156,6 +160,51 @@ export const REVERSIBILITY = {
156
160
  class: "irreversible",
157
161
  note: "a created heading has no headless delete surface (heading delete is interactive-only) — archive it in the app instead",
158
162
  },
163
+ "todo.make-repeating": {
164
+ class: "irreversible",
165
+ note: "making a to-do repeat is an identity REPLACEMENT (UI2-a): the original uuid is destroyed and a new template row is born — there is no un-repeat that restores the original",
166
+ },
167
+ "todo.convert-to-project": {
168
+ class: "irreversible",
169
+ note: "converting a to-do to a project is an identity REPLACEMENT (UI2-d): the to-do uuid is destroyed and a new project uuid is born (notes preserved); the app offers no convert-back",
170
+ },
171
+ "project.make-repeating": {
172
+ class: "irreversible",
173
+ note: "making a project repeat is an identity REPLACEMENT (UIC4-b): the original project uuid is destroyed and a new template project is born (area preserved, start normalized to someday) — there is no un-repeat that restores the original",
174
+ },
175
+ "project.create-repeating": {
176
+ class: "irreversible",
177
+ note: "the composite CREATES a project then promotes it (identity replacement, UIC4-b): the created uuid is destroyed by the promote and a new repeating template is born — no automated inverse captures it; delete the resulting repeating project in the app",
178
+ },
179
+ "heading.convert-to-project": {
180
+ class: "irreversible",
181
+ note: "converting a heading to a project is an identity REPLACEMENT (UI2-d): the heading uuid is destroyed, a new project is promoted into the parent's area and children reparent; no convert-back",
182
+ },
183
+ "todo.reschedule-repeat": {
184
+ class: "conditional",
185
+ note: "the rule mutates in place (identity preserved, UI2-b); the FULL rule vocabulary re-drives reschedule with the captured prior rule (weekday set, monthly/yearly anchor, ends bound, deadline/start-offset all restored) — invertible whenever the prior rule was captured, decodable, and within the Repeat dialog's vocabulary; irreversible for a rule the dialog itself cannot produce (two end bounds, a multi-anchor month/year rule, or an after-completion rule with a calendar day). A per-instance reminder time is not part of the captured rule and is not restored",
186
+ },
187
+ "project.reschedule-repeat": {
188
+ class: "conditional",
189
+ note: "the project's rule mutates in place (identity preserved, UIC2-a); re-drives reschedule with the captured prior rule (same faithfulness boundary as todo.reschedule-repeat) — invertible when the prior rule was captured, decodable, and dialog-expressible; irreversible otherwise. A per-instance reminder time is not restored",
190
+ },
191
+ // ---- ui-vector reversible pairs -----------------------------------------
192
+ "todo.pause-repeat": {
193
+ class: "reversible",
194
+ note: "inverse resumes the repeat (UI2-c): pause sets instance-creation paused, keeping the template and rule; resume clears it",
195
+ },
196
+ "todo.resume-repeat": {
197
+ class: "reversible",
198
+ note: "inverse pauses the repeat (UI2-c): the reversible cessation toggle — resume clears the paused flag, pause re-sets it",
199
+ },
200
+ "project.pause-repeat": {
201
+ class: "reversible",
202
+ note: "inverse resumes the project's repeat (UIC2-a): pause sets instance-creation paused, keeping the template and rule; resume clears it",
203
+ },
204
+ "project.resume-repeat": {
205
+ class: "reversible",
206
+ note: "inverse pauses the project's repeat (UIC2-a): resume clears the paused flag, pause re-sets it",
207
+ },
159
208
  };
160
209
  /** The ops whose class is `irreversible` — must equal undo.ts's IRREVERSIBLE keys. */
161
210
  export function irreversibleOps() {
@@ -1 +1 @@
1
- {"version":3,"file":"reversibility.js","sourceRoot":"","sources":["../../src/write/reversibility.ts"],"names":[],"mappings":"AA0CA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAA8C;IACtE,4EAA4E;I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E;IAC5E,iBAAiB,EAAE;QACjB,KAAK,EAAE,sBAAsB;QAC7B,IAAI,EAAE,iMAAiM;KACxM;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,uGAAuG;KAC9G;IAED,4EAA4E;IAC5E,2BAA2B,EAAE;QAC3B,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE,sPAAsP;KAC7P;IAED,4EAA4E;IAC5E,aAAa,EAAE;QACb,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,mEAAmE;KAC1E;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,mEAAmE;KAC1E;IACD,aAAa,EAAE;QACb,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,sEAAsE;KAC7E;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,uHAAuH;KAC9H;CACF,CAAC;AAEF,sFAAsF;AACtF,MAAM,UAAU,eAAe;IAC7B,OAAQ,MAAM,CAAC,IAAI,CAAC,aAAa,CAAqB,CAAC,MAAM,CAC3D,CAAC,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,cAAc,CACnD,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"reversibility.js","sourceRoot":"","sources":["../../src/write/reversibility.ts"],"names":[],"mappings":"AA0CA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAA8C;IACtE,4EAA4E;IAC5E,UAAU,EAAE;QACV,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,uHAAuH;KAC9H;IACD,iBAAiB,EAAE;QACjB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,2GAA2G;KAClH;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,kGAAkG;KACzG;IACD,aAAa,EAAE;QACb,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,wEAAwE;KAC/E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tF,MAAM,UAAU,eAAe;IAC7B,OAAQ,MAAM,CAAC,IAAI,CAAC,aAAa,CAAqB,CAAC,MAAM,CAC3D,CAAC,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,cAAc,CACnD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Tag-reference resolution for the tag-accepting write ops (todo.add,
3
+ * todo.set-tags, project.set-tags, area.add, area.update).
4
+ *
5
+ * A tag value is a NAME — either a plain TITLE or a PATH-qualified
6
+ * `parent/child` name. Tag uuids are a fully internal implementation detail
7
+ * (like checklist ids) and are neither accepted here nor surfaced anywhere.
8
+ *
9
+ * Precedence is LITERAL-OVER-PATH (TAGW1-d: `/` is a legal literal in a tag
10
+ * title, `sl/ash` stored + matched literally): an exact literal title match
11
+ * wins even when the ref contains `/`; only otherwise is the ref split on `/`
12
+ * and resolved as a parent-child chain.
13
+ *
14
+ * The resolver's only job is an EXISTENCE check. Tags are applied by passing
15
+ * the NAME to the app's own write vector (`tags=Name` / `set tag names`), so
16
+ * the APP resolves the name exactly as its GUI does — we never pick a uuid. A
17
+ * name matching ≥1 tag is "known" (the name passes through); a name matching
18
+ * none is reported as missing (the H-UNKNOWN-TAG guard refuses on it). A
19
+ * duplicate-name pair (a Cloud-sync-only pathological state we delegate to the
20
+ * app, matching the GUI) needs no special handling — both share the name.
21
+ */
22
+ import type { DatabaseSync } from "node:sqlite";
23
+ export interface TagResolution {
24
+ /**
25
+ * Resolved leaf titles to apply, de-duplicated, in first-seen order. Only
26
+ * COMPLETE (one per input ref) when `missing` is empty; on a refusal the
27
+ * H-UNKNOWN-TAG guard blocks before these titles are used.
28
+ */
29
+ titles: string[];
30
+ /** Refs that resolved to nothing (unknown tags). */
31
+ missing: string[];
32
+ }
33
+ /** One creation step for `--create-tags`: a `make new tag`, optionally nested. */
34
+ export interface TagCreationStep {
35
+ title: string;
36
+ /** Existing (or already-planned) parent tag title to nest under. */
37
+ parent?: string;
38
+ }
39
+ export declare function resolveTagRefs(db: DatabaseSync, refs: string[]): TagResolution;
40
+ /**
41
+ * Ordered `make new tag` steps to satisfy `--create-tags`: only the tags that
42
+ * are genuinely MISSING, with mkdir-p intermediates for a `parent/child` path
43
+ * (parents first so each child's parent resolves). A ref that already resolves
44
+ * yields no step (idempotent — the TAGW1-c coalesce also makes re-creation a
45
+ * no-op).
46
+ */
47
+ export declare function planTagCreation(db: DatabaseSync, refs: string[]): TagCreationStep[];
@@ -0,0 +1,126 @@
1
+ import { normalizeNameKey, stripThingsUri } from "../read/queries.js";
2
+ function allTags(db) {
3
+ return db.prepare("SELECT uuid, title, parent FROM TMTag").all();
4
+ }
5
+ /** Dedup key for a per-parent planned title (parent title + title). */
6
+ function planKey(parentTitle, title) {
7
+ return `${parentTitle ?? ""}${title}`;
8
+ }
9
+ /**
10
+ * Title-match tiers within a candidate row set: exact -> case-insensitive ->
11
+ * normalized (dash/space-forgiving). Returns the rows of the FIRST tier that
12
+ * matches at all.
13
+ */
14
+ function titleMatches(rows, title) {
15
+ const exact = rows.filter((r) => r.title === title);
16
+ if (exact.length > 0)
17
+ return exact;
18
+ const lower = title.toLowerCase();
19
+ const ci = rows.filter((r) => r.title.toLowerCase() === lower);
20
+ if (ci.length > 0)
21
+ return ci;
22
+ const key = normalizeNameKey(title);
23
+ if (key === "")
24
+ return [];
25
+ return rows.filter((r) => normalizeNameKey(r.title) === key);
26
+ }
27
+ function resolveOne(rows, refRaw) {
28
+ const ref = stripThingsUri(refRaw);
29
+ // Literal title (literal-over-path: this matches `sl/ash` as a whole). A name
30
+ // matching ≥1 tag is "known" — pass the NAME through; the app resolves it.
31
+ const literal = titleMatches(rows, ref);
32
+ if (literal.length >= 1)
33
+ return { kind: "title", title: literal[0].title };
34
+ // Path-qualified `parent/child` — resolve the chain from the root. Duplicate
35
+ // names never refuse: descend into the first match at each level.
36
+ if (ref.includes("/")) {
37
+ const segs = ref.split("/").map((s) => s.trim());
38
+ if (segs.some((s) => s === ""))
39
+ return { kind: "missing" };
40
+ let scope = rows.filter((r) => r.parent === null);
41
+ let leaf = null;
42
+ for (const seg of segs) {
43
+ const hits = titleMatches(scope, seg);
44
+ if (hits.length === 0)
45
+ return { kind: "missing" };
46
+ leaf = hits[0];
47
+ scope = rows.filter((r) => r.parent === leaf.uuid);
48
+ }
49
+ if (leaf !== null)
50
+ return { kind: "title", title: leaf.title };
51
+ }
52
+ return { kind: "missing" };
53
+ }
54
+ export function resolveTagRefs(db, refs) {
55
+ const rows = allTags(db);
56
+ const titles = [];
57
+ const seen = new Set();
58
+ const missing = [];
59
+ for (const ref of refs) {
60
+ const r = resolveOne(rows, ref);
61
+ if (r.kind === "title") {
62
+ if (!seen.has(r.title)) {
63
+ seen.add(r.title);
64
+ titles.push(r.title);
65
+ }
66
+ }
67
+ else {
68
+ missing.push(ref);
69
+ }
70
+ }
71
+ return { titles, missing };
72
+ }
73
+ /**
74
+ * Ordered `make new tag` steps to satisfy `--create-tags`: only the tags that
75
+ * are genuinely MISSING, with mkdir-p intermediates for a `parent/child` path
76
+ * (parents first so each child's parent resolves). A ref that already resolves
77
+ * yields no step (idempotent — the TAGW1-c coalesce also makes re-creation a
78
+ * no-op).
79
+ */
80
+ export function planTagCreation(db, refs) {
81
+ const rows = allTags(db);
82
+ const steps = [];
83
+ // Titles known to exist OR already planned this call, per hierarchy level,
84
+ // so a repeated segment across refs is planned once.
85
+ const planned = new Set();
86
+ for (const refRaw of refs) {
87
+ const ref = stripThingsUri(refRaw);
88
+ if (resolveOne(rows, ref).kind === "title")
89
+ continue;
90
+ if (ref.includes("/")) {
91
+ const segs = ref.split("/").map((s) => s.trim());
92
+ if (segs.some((s) => s === ""))
93
+ continue;
94
+ let scope = rows.filter((r) => r.parent === null);
95
+ let parentTitle;
96
+ for (const seg of segs) {
97
+ const hits = titleMatches(scope, seg);
98
+ if (hits.length >= 1) {
99
+ const hit = hits[0];
100
+ parentTitle = hit.title;
101
+ scope = rows.filter((r) => r.parent === hit.uuid);
102
+ }
103
+ else {
104
+ // Missing -> plan it and descend into a now-empty scope so the
105
+ // remaining segments are all created too.
106
+ const k = planKey(parentTitle, seg);
107
+ if (!planned.has(k)) {
108
+ planned.add(k);
109
+ steps.push(parentTitle === undefined ? { title: seg } : { title: seg, parent: parentTitle });
110
+ }
111
+ parentTitle = seg;
112
+ scope = [];
113
+ }
114
+ }
115
+ }
116
+ else {
117
+ const k = planKey(undefined, ref);
118
+ if (!planned.has(k)) {
119
+ planned.add(k);
120
+ steps.push({ title: ref });
121
+ }
122
+ }
123
+ }
124
+ return steps;
125
+ }
126
+ //# sourceMappingURL=tag-refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tag-refs.js","sourceRoot":"","sources":["../../src/write/tag-refs.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AA0BtE,SAAS,OAAO,CAAC,EAAgB;IAC/B,OAAO,EAAE,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC,GAAG,EAAyB,CAAC;AAC1F,CAAC;AAED,uEAAuE;AACvE,SAAS,OAAO,CAAC,WAA+B,EAAE,KAAa;IAC7D,OAAO,GAAG,WAAW,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,IAAc,EAAE,KAAa;IACjD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;IACpD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,KA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AK,CAAC;oBACxB,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;gBACpD,CAAC;qBAAM,CAAC;oBACN,+DAA+D;oBAC/D,0CAA0C;oBAC1C,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;oBACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;wBACpB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;wBACf,KAAK,CAAC,IAAI,CACR,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CACjF,CAAC;oBACJ,CAAC;oBACD,WAAW,GAAG,GAAG,CAAC;oBAClB,KAAK,GAAG,EAAE,CAAC;gBACb,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { AuditRecord } from "../audit/schema.ts";
1
+ import { type AuditRecord } from "../audit/schema.ts";
2
2
  import type { AnyTask } from "../model/entities.ts";
3
- import type { OperationKind } from "./operations.ts";
3
+ import { type OperationKind } from "./operations.ts";
4
4
  import { type MutationResult, type WriteDeps } from "./pipeline.ts";
5
5
  import { type ReorderResult } from "./reorder.ts";
6
6
  export interface UndoStep {
@@ -21,6 +21,18 @@ export interface UndoStep {
21
21
  detail: string;
22
22
  remediation: string;
23
23
  };
24
+ /**
25
+ * STRUCTURAL axes this step overwrites (getField paths into the decoded
26
+ * target: `status`, `trashed`, `project`/`project.uuid`, `area`/`area.uuid`,
27
+ * `heading.uuid`, `start`/`startDate`/`todaySection`). Before executing,
28
+ * `checkStepPrecondition` verifies the target's CURRENT value on each still
29
+ * equals the recorded `observed` after-value — an out-of-band move/status/
30
+ * schedule change already there blocks rather than being clobbered. Set only
31
+ * for the PRIMARY-target step and only for axes whose after-state `observed`
32
+ * captured (fields absent from `observed` are skipped). Content fields stay
33
+ * on the separate CLOBBER_FIELDS path; the two are checked together.
34
+ */
35
+ guardFields?: string[];
24
36
  };
25
37
  }
26
38
  export interface UndoPlan {
@@ -30,6 +42,7 @@ export interface UndoPlan {
30
42
  op: string;
31
43
  uuid: string | null;
32
44
  actor: string;
45
+ token: string;
33
46
  };
34
47
  kind: "invertible" | "irreversible";
35
48
  steps: UndoStep[];
@@ -47,19 +60,75 @@ export interface UndoItemResult {
47
60
  export interface UndoOptions {
48
61
  /** How many trailing mutations to undo (default 1). */
49
62
  last?: number;
63
+ /**
64
+ * SELECTION filter — undo only mutations recorded under this actor. An exact
65
+ * actor string (e.g. "mcp:claude-code", "mike") or "*" for all actors.
66
+ * Undefined means all (the CLI's global default); the MCP surface defaults it
67
+ * to the connecting client's own derived actor (`mcp:<client>`).
68
+ *
69
+ * Matching is EXACT: `by: "mike"` selects records whose actor is exactly
70
+ * "mike" and never an undo record (`undo:mike`) — inverse mutations are their
71
+ * own actor and are never themselves undo targets. NOT the same as `actor`
72
+ * below, which names who the NEW inverse mutation is attributed to.
73
+ */
74
+ by?: string;
75
+ /**
76
+ * EXACT selection by undo token (from a mutation result's `undoToken`).
77
+ * Undoes precisely that one record, immune to interleaving. Mutually
78
+ * exclusive with `last`/`by` (enforced at the call surfaces).
79
+ */
80
+ txn?: string;
50
81
  dryRun?: boolean;
51
82
  /** Required for inverses that delete areas/tags permanently. */
52
83
  dangerouslyPermanent?: boolean;
84
+ /**
85
+ * Proceed even when the target changed OUTSIDE things-api since the recorded
86
+ * change — bypasses the precondition guard uniformly (both the content-field
87
+ * and the structural axis checks), overwriting whatever an out-of-band edit
88
+ * left. Does NOT bypass the checklist item-level refusal (a separate plan-time
89
+ * mechanism with no faithful forced inverse). "The world moved, overwrite
90
+ * anyway."
91
+ */
92
+ acknowledgeOutOfBandChanges?: boolean;
53
93
  verifyTimeoutMs?: number;
94
+ /** Author RECORDED for the inverse mutation (as `undo:<actor>`); see `by`. */
54
95
  actor?: string;
55
96
  }
56
97
  /** Parse every audit record from the monthly JSONL files, oldest first. */
57
98
  export declare function readAuditRecords(dir: string): AuditRecord[];
99
+ export interface UndoSelector {
100
+ /** How many trailing targets to take (default 1); ignored when `txn` is set. */
101
+ last?: number;
102
+ /** Actor filter: exact actor string, or "*"/undefined for all. */
103
+ by?: string;
104
+ /** Exact undo-token selection: returns the single matching target (or none). */
105
+ txn?: string;
106
+ }
107
+ export interface AuditIntegrity {
108
+ /** Intent records with no later matching final record — a write MAY have landed unrecorded. */
109
+ orphanedIntents: number;
110
+ /** Newest orphaned intent's timestamp (ISO), or null when there are none. */
111
+ newestOrphanIntent: string | null;
112
+ }
113
+ /**
114
+ * Detect crashed writes: INTENT records left without a matching final record.
115
+ * A mutation writes an intent immediately before touching the app and a final
116
+ * record after read-after-write; the two share ts+op+actor+host. An intent
117
+ * with no non-intent sibling on that key means the process died mid-write — the
118
+ * app may have applied the change, but no result was recorded, so the change is
119
+ * invisible to undo. Surfaced by `things doctor` so the user can reconcile.
120
+ */
121
+ export declare function scanAuditIntegrity(records: AuditRecord[]): AuditIntegrity;
58
122
  /**
59
- * The last N undoable targets, NEWEST FIRST (undo unwinds a stack). Only
60
- * successful mutations qualify; inverse mutations (actor `undo:…`) never do.
123
+ * The undoable targets to unwind, NEWEST FIRST (undo unwinds a stack).
124
+ *
125
+ * - `txn` wins when present: the ONE record whose undo token matches (or an
126
+ * empty array — the caller distinguishes not-found from already-undone).
127
+ * - otherwise the last `last` records, optionally narrowed to actor `by`
128
+ * (exact match; "*"/undefined = every actor). `by` NEVER matches an
129
+ * `undo:<actor>` record — those are excluded from undoability entirely.
61
130
  */
62
- export declare function selectUndoTargets(records: AuditRecord[], last: number): AuditRecord[];
131
+ export declare function selectUndoTargets(records: AuditRecord[], selector?: UndoSelector): AuditRecord[];
63
132
  /**
64
133
  * Operations with NO validated inverse surface — reported irreversible on
65
134
  * sight, before any per-record analysis. The reversibility matrix cross-checks