things-api 0.9.0 → 0.11.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 (261) hide show
  1. package/README.md +57 -12
  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/clock.d.ts +8 -0
  8. package/dist/cli/clock.js +24 -0
  9. package/dist/cli/clock.js.map +1 -0
  10. package/dist/cli/commands/area.d.ts +26 -3
  11. package/dist/cli/commands/area.js +129 -75
  12. package/dist/cli/commands/area.js.map +1 -1
  13. package/dist/cli/commands/doctor.d.ts +1 -1
  14. package/dist/cli/commands/doctor.js +44 -5
  15. package/dist/cli/commands/doctor.js.map +1 -1
  16. package/dist/cli/commands/install-skill.d.ts +45 -0
  17. package/dist/cli/commands/install-skill.js +207 -0
  18. package/dist/cli/commands/install-skill.js.map +1 -0
  19. package/dist/cli/commands/mcp.js +23 -4
  20. package/dist/cli/commands/mcp.js.map +1 -1
  21. package/dist/cli/commands/project.d.ts +18 -1
  22. package/dist/cli/commands/project.js +74 -35
  23. package/dist/cli/commands/project.js.map +1 -1
  24. package/dist/cli/commands/reads.d.ts +15 -2
  25. package/dist/cli/commands/reads.js +459 -165
  26. package/dist/cli/commands/reads.js.map +1 -1
  27. package/dist/cli/commands/repeat-flags.d.ts +20 -0
  28. package/dist/cli/commands/repeat-flags.js +76 -0
  29. package/dist/cli/commands/repeat-flags.js.map +1 -0
  30. package/dist/cli/commands/setup.js +8 -4
  31. package/dist/cli/commands/setup.js.map +1 -1
  32. package/dist/cli/commands/show.js +53 -30
  33. package/dist/cli/commands/show.js.map +1 -1
  34. package/dist/cli/commands/todo.d.ts +1 -1
  35. package/dist/cli/commands/todo.js +20 -13
  36. package/dist/cli/commands/todo.js.map +1 -1
  37. package/dist/cli/commands/writes.js +388 -161
  38. package/dist/cli/commands/writes.js.map +1 -1
  39. package/dist/cli/did-you-mean.d.ts +1 -1
  40. package/dist/cli/excess-args.d.ts +15 -0
  41. package/dist/cli/excess-args.js +51 -0
  42. package/dist/cli/excess-args.js.map +1 -0
  43. package/dist/cli/glyphs.d.ts +55 -2
  44. package/dist/cli/glyphs.js +114 -21
  45. package/dist/cli/glyphs.js.map +1 -1
  46. package/dist/cli/help.d.ts +54 -0
  47. package/dist/cli/help.js +405 -0
  48. package/dist/cli/help.js.map +1 -0
  49. package/dist/cli/main.js +64 -26
  50. package/dist/cli/main.js.map +1 -1
  51. package/dist/cli/move-hint.d.ts +45 -0
  52. package/dist/cli/move-hint.js +196 -0
  53. package/dist/cli/move-hint.js.map +1 -0
  54. package/dist/cli/period.d.ts +9 -8
  55. package/dist/cli/period.js +56 -30
  56. package/dist/cli/period.js.map +1 -1
  57. package/dist/cli/read-driver.d.ts +26 -19
  58. package/dist/cli/read-driver.js +77 -33
  59. package/dist/cli/read-driver.js.map +1 -1
  60. package/dist/cli/render.d.ts +92 -28
  61. package/dist/cli/render.js +333 -103
  62. package/dist/cli/render.js.map +1 -1
  63. package/dist/cli/resolve-invocation.d.ts +42 -4
  64. package/dist/cli/resolve-invocation.js +97 -14
  65. package/dist/cli/resolve-invocation.js.map +1 -1
  66. package/dist/cli/skill-check.d.ts +21 -0
  67. package/dist/cli/skill-check.js +82 -0
  68. package/dist/cli/skill-check.js.map +1 -0
  69. package/dist/cli/skill.d.ts +62 -0
  70. package/dist/cli/skill.js +142 -0
  71. package/dist/cli/skill.js.map +1 -0
  72. package/dist/cli/tag-filters.d.ts +63 -0
  73. package/dist/cli/tag-filters.js +59 -0
  74. package/dist/cli/tag-filters.js.map +1 -0
  75. package/dist/cli/verb-hint.d.ts +25 -0
  76. package/dist/cli/verb-hint.js +163 -0
  77. package/dist/cli/verb-hint.js.map +1 -0
  78. package/dist/cli/version.d.ts +4 -0
  79. package/dist/cli/version.js +18 -0
  80. package/dist/cli/version.js.map +1 -0
  81. package/dist/cli/width.d.ts +135 -0
  82. package/dist/cli/width.js +313 -0
  83. package/dist/cli/width.js.map +1 -0
  84. package/dist/client.d.ts +160 -24
  85. package/dist/client.js +132 -19
  86. package/dist/client.js.map +1 -1
  87. package/dist/config.d.ts +11 -0
  88. package/dist/config.js +3 -0
  89. package/dist/config.js.map +1 -1
  90. package/dist/contracts.d.ts +97 -17
  91. package/dist/contracts.js +44 -1
  92. package/dist/contracts.js.map +1 -1
  93. package/dist/db/fingerprint.d.ts +12 -0
  94. package/dist/db/fingerprint.js +15 -1
  95. package/dist/db/fingerprint.js.map +1 -1
  96. package/dist/db/locate.js +1 -1
  97. package/dist/db/locate.js.map +1 -1
  98. package/dist/diagnose.d.ts +63 -0
  99. package/dist/diagnose.js +38 -1
  100. package/dist/diagnose.js.map +1 -1
  101. package/dist/index.d.ts +36 -5
  102. package/dist/index.js +38 -2
  103. package/dist/index.js.map +1 -1
  104. package/dist/mcp/server.d.ts +9 -1
  105. package/dist/mcp/server.js +1038 -436
  106. package/dist/mcp/server.js.map +1 -1
  107. package/dist/model/clock.d.ts +61 -0
  108. package/dist/model/clock.js +71 -0
  109. package/dist/model/clock.js.map +1 -0
  110. package/dist/model/dates.d.ts +26 -3
  111. package/dist/model/dates.js +84 -3
  112. package/dist/model/dates.js.map +1 -1
  113. package/dist/model/entities.d.ts +48 -10
  114. package/dist/model/entities.js.map +1 -1
  115. package/dist/model/mappers.d.ts +9 -2
  116. package/dist/model/mappers.js +32 -9
  117. package/dist/model/mappers.js.map +1 -1
  118. package/dist/model/serialize.d.ts +28 -0
  119. package/dist/model/serialize.js +80 -0
  120. package/dist/model/serialize.js.map +1 -0
  121. package/dist/model/when-sugar.d.ts +47 -0
  122. package/dist/model/when-sugar.js +45 -0
  123. package/dist/model/when-sugar.js.map +1 -0
  124. package/dist/read/area-view.d.ts +8 -1
  125. package/dist/read/area-view.js +55 -17
  126. package/dist/read/area-view.js.map +1 -1
  127. package/dist/read/detail.d.ts +1 -1
  128. package/dist/read/detail.js +11 -4
  129. package/dist/read/detail.js.map +1 -1
  130. package/dist/read/filter-contract.d.ts +117 -0
  131. package/dist/read/filter-contract.js +78 -0
  132. package/dist/read/filter-contract.js.map +1 -0
  133. package/dist/read/log-boundary.d.ts +1 -1
  134. package/dist/read/log-boundary.js +13 -3
  135. package/dist/read/log-boundary.js.map +1 -1
  136. package/dist/read/predicates.d.ts +30 -0
  137. package/dist/read/predicates.js +30 -0
  138. package/dist/read/predicates.js.map +1 -1
  139. package/dist/read/project-view.d.ts +12 -1
  140. package/dist/read/project-view.js +45 -12
  141. package/dist/read/project-view.js.map +1 -1
  142. package/dist/read/queries.d.ts +152 -7
  143. package/dist/read/queries.js +277 -36
  144. package/dist/read/queries.js.map +1 -1
  145. package/dist/read/sections.d.ts +51 -0
  146. package/dist/read/sections.js +37 -0
  147. package/dist/read/sections.js.map +1 -0
  148. package/dist/read/sidebar-order.js +2 -1
  149. package/dist/read/sidebar-order.js.map +1 -1
  150. package/dist/read/snapshot.d.ts +1 -1
  151. package/dist/read/snapshot.js +9 -2
  152. package/dist/read/snapshot.js.map +1 -1
  153. package/dist/read/tags.d.ts +27 -3
  154. package/dist/read/tags.js +83 -12
  155. package/dist/read/tags.js.map +1 -1
  156. package/dist/read/truncation.d.ts +71 -0
  157. package/dist/read/{pagination.js → truncation.js} +103 -94
  158. package/dist/read/truncation.js.map +1 -0
  159. package/dist/read/views.d.ts +147 -22
  160. package/dist/read/views.js +282 -80
  161. package/dist/read/views.js.map +1 -1
  162. package/dist/surface-copy.d.ts +19 -0
  163. package/dist/surface-copy.js +32 -0
  164. package/dist/surface-copy.js.map +1 -1
  165. package/dist/sync-health.d.ts +78 -0
  166. package/dist/sync-health.js +312 -0
  167. package/dist/sync-health.js.map +1 -0
  168. package/dist/write/accessibility-probe.d.ts +12 -0
  169. package/dist/write/accessibility-probe.js +71 -0
  170. package/dist/write/accessibility-probe.js.map +1 -0
  171. package/dist/write/automation-probe.d.ts +8 -1
  172. package/dist/write/automation-probe.js +16 -1
  173. package/dist/write/automation-probe.js.map +1 -1
  174. package/dist/write/batch.js +5 -2
  175. package/dist/write/batch.js.map +1 -1
  176. package/dist/write/capabilities.d.ts +8 -0
  177. package/dist/write/capabilities.js +13 -6
  178. package/dist/write/capabilities.js.map +1 -1
  179. package/dist/write/commands.d.ts +3 -1
  180. package/dist/write/commands.js +602 -49
  181. package/dist/write/commands.js.map +1 -1
  182. package/dist/write/edit-checklist.js +3 -2
  183. package/dist/write/edit-checklist.js.map +1 -1
  184. package/dist/write/guards.d.ts +2 -7
  185. package/dist/write/guards.js +87 -6
  186. package/dist/write/guards.js.map +1 -1
  187. package/dist/write/heading.js +2 -0
  188. package/dist/write/heading.js.map +1 -1
  189. package/dist/write/lock.d.ts +40 -2
  190. package/dist/write/lock.js +91 -14
  191. package/dist/write/lock.js.map +1 -1
  192. package/dist/write/make-repeating-project.d.ts +4 -0
  193. package/dist/write/make-repeating-project.js +253 -0
  194. package/dist/write/make-repeating-project.js.map +1 -0
  195. package/dist/write/operations.d.ts +145 -1
  196. package/dist/write/operations.js +48 -0
  197. package/dist/write/operations.js.map +1 -1
  198. package/dist/write/pipeline.d.ts +73 -2
  199. package/dist/write/pipeline.js +218 -43
  200. package/dist/write/pipeline.js.map +1 -1
  201. package/dist/write/planner.js +8 -1
  202. package/dist/write/planner.js.map +1 -1
  203. package/dist/write/pre-state.d.ts +105 -3
  204. package/dist/write/pre-state.js +144 -3
  205. package/dist/write/pre-state.js.map +1 -1
  206. package/dist/write/recurrence-rule-blob.d.ts +65 -0
  207. package/dist/write/recurrence-rule-blob.js +150 -0
  208. package/dist/write/recurrence-rule-blob.js.map +1 -0
  209. package/dist/write/reopen.js +3 -2
  210. package/dist/write/reopen.js.map +1 -1
  211. package/dist/write/reorder.js +27 -17
  212. package/dist/write/reorder.js.map +1 -1
  213. package/dist/write/repeat-rule.d.ts +22 -0
  214. package/dist/write/repeat-rule.js +258 -0
  215. package/dist/write/repeat-rule.js.map +1 -0
  216. package/dist/write/reversibility.js +49 -0
  217. package/dist/write/reversibility.js.map +1 -1
  218. package/dist/write/tag-refs.d.ts +47 -0
  219. package/dist/write/tag-refs.js +126 -0
  220. package/dist/write/tag-refs.js.map +1 -0
  221. package/dist/write/undo.d.ts +74 -5
  222. package/dist/write/undo.js +493 -80
  223. package/dist/write/undo.js.map +1 -1
  224. package/dist/write/vectors/registry.d.ts +15 -1
  225. package/dist/write/vectors/registry.js +65 -2
  226. package/dist/write/vectors/registry.js.map +1 -1
  227. package/dist/write/vectors/simulator.d.ts +44 -0
  228. package/dist/write/vectors/simulator.js +1136 -0
  229. package/dist/write/vectors/simulator.js.map +1 -0
  230. package/dist/write/vectors/types.d.ts +154 -3
  231. package/dist/write/vectors/ui-certification.d.ts +54 -0
  232. package/dist/write/vectors/ui-certification.js +43 -0
  233. package/dist/write/vectors/ui-certification.js.map +1 -0
  234. package/dist/write/vectors/ui-drag.d.ts +188 -0
  235. package/dist/write/vectors/ui-drag.js +1095 -0
  236. package/dist/write/vectors/ui-drag.js.map +1 -0
  237. package/dist/write/vectors/ui-recipes.d.ts +83 -0
  238. package/dist/write/vectors/ui-recipes.js +610 -0
  239. package/dist/write/vectors/ui-recipes.js.map +1 -0
  240. package/dist/write/vectors/ui.d.ts +152 -0
  241. package/dist/write/vectors/ui.js +704 -0
  242. package/dist/write/vectors/ui.js.map +1 -0
  243. package/dist/write/verify/delta.d.ts +141 -4
  244. package/dist/write/verify/delta.js +199 -21
  245. package/dist/write/verify/delta.js.map +1 -1
  246. package/dist/write/verify/poller.d.ts +7 -1
  247. package/dist/write/verify/poller.js +21 -1
  248. package/dist/write/verify/poller.js.map +1 -1
  249. package/package.json +18 -3
  250. package/skills/things-cli/SKILL.md +53 -0
  251. package/skills/things-cli/references/contracts.md +41 -0
  252. package/skills/things-cli/references/gui.md +11 -0
  253. package/skills/things-cli/references/model.md +51 -0
  254. package/dist/cli/exit-codes.d.ts +0 -26
  255. package/dist/cli/exit-codes.js +0 -26
  256. package/dist/cli/exit-codes.js.map +0 -1
  257. package/dist/cli/output.d.ts +0 -42
  258. package/dist/cli/output.js +0 -16
  259. package/dist/cli/output.js.map +0 -1
  260. package/dist/read/pagination.d.ts +0 -104
  261. package/dist/read/pagination.js.map +0 -1
@@ -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,KAAK,KAAK,CAAC,CAAC;IAC/D,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;I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C;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