@opencorelabs/lucidity 0.3.0 → 0.6.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 (512) hide show
  1. package/README.md +9 -2
  2. package/dist/assets/speech/licenses/FluidAudio/LICENSE +201 -0
  3. package/dist/assets/speech/licenses/FluidAudio/ThirdPartyLicenses/fastcluster-LICENSE.md +11 -0
  4. package/dist/assets/speech/licenses/FluidAudio/ThirdPartyLicenses/vbx-LICENSE.md +201 -0
  5. package/dist/assets/speech/lucidity-speech +0 -0
  6. package/dist/automations/agent.d.ts +16 -0
  7. package/dist/automations/agent.d.ts.map +1 -0
  8. package/dist/automations/agent.js +196 -0
  9. package/dist/automations/cli.d.ts +4 -0
  10. package/dist/automations/cli.d.ts.map +1 -0
  11. package/dist/automations/cli.js +44 -0
  12. package/dist/automations/connections.d.ts +11 -0
  13. package/dist/automations/connections.d.ts.map +1 -0
  14. package/dist/automations/connections.js +74 -0
  15. package/dist/automations/designer.d.ts +39 -0
  16. package/dist/automations/designer.d.ts.map +1 -0
  17. package/dist/automations/designer.js +450 -0
  18. package/dist/automations/history.d.ts +4 -0
  19. package/dist/automations/history.d.ts.map +1 -0
  20. package/dist/automations/history.js +57 -0
  21. package/dist/automations/learning.d.ts +19 -0
  22. package/dist/automations/learning.d.ts.map +1 -0
  23. package/dist/automations/learning.js +121 -0
  24. package/dist/automations/pinterest.d.ts +21 -0
  25. package/dist/automations/pinterest.d.ts.map +1 -0
  26. package/dist/automations/pinterest.js +113 -0
  27. package/dist/automations/service.d.ts +42 -0
  28. package/dist/automations/service.d.ts.map +1 -0
  29. package/dist/automations/service.js +406 -0
  30. package/dist/automations/setup.d.ts +3 -0
  31. package/dist/automations/setup.d.ts.map +1 -0
  32. package/dist/automations/setup.js +48 -0
  33. package/dist/automations/skill.d.ts +3 -0
  34. package/dist/automations/skill.d.ts.map +1 -0
  35. package/dist/automations/skill.js +29 -0
  36. package/dist/automations/store.d.ts +13 -0
  37. package/dist/automations/store.d.ts.map +1 -0
  38. package/dist/automations/store.js +46 -0
  39. package/dist/chat/server.d.ts +2 -0
  40. package/dist/chat/server.d.ts.map +1 -1
  41. package/dist/chat/server.js +46 -2
  42. package/dist/coding/commandContext.d.ts +6 -0
  43. package/dist/coding/commandContext.d.ts.map +1 -0
  44. package/dist/coding/commandContext.js +20 -0
  45. package/dist/coding/runCodeTurn.d.ts +12 -2
  46. package/dist/coding/runCodeTurn.d.ts.map +1 -1
  47. package/dist/coding/runCodeTurn.js +49 -19
  48. package/dist/coding/worktree.d.ts +3 -4
  49. package/dist/coding/worktree.d.ts.map +1 -1
  50. package/dist/coding/worktree.js +3 -4
  51. package/dist/config.d.ts +4 -0
  52. package/dist/config.d.ts.map +1 -1
  53. package/dist/config.js +20 -3
  54. package/dist/decisions/cli.d.ts +2 -0
  55. package/dist/decisions/cli.d.ts.map +1 -0
  56. package/dist/decisions/cli.js +106 -0
  57. package/dist/decisions/client.d.ts +20 -0
  58. package/dist/decisions/client.d.ts.map +1 -0
  59. package/dist/decisions/client.js +41 -0
  60. package/dist/handoff.d.ts +11 -0
  61. package/dist/handoff.d.ts.map +1 -0
  62. package/dist/handoff.js +21 -0
  63. package/dist/index.js +179 -40
  64. package/dist/jobs/briefing.js +1 -1
  65. package/dist/jobs/extraction.d.ts.map +1 -1
  66. package/dist/jobs/extraction.js +112 -22
  67. package/dist/jobs/fastModeReview.d.ts +39 -0
  68. package/dist/jobs/fastModeReview.d.ts.map +1 -0
  69. package/dist/jobs/fastModeReview.js +192 -0
  70. package/dist/jobs/voiceReview.d.ts +24 -0
  71. package/dist/jobs/voiceReview.d.ts.map +1 -0
  72. package/dist/jobs/voiceReview.js +128 -0
  73. package/dist/mcp/clients.d.ts +5 -0
  74. package/dist/mcp/clients.d.ts.map +1 -1
  75. package/dist/mcp/clients.js +1 -1
  76. package/dist/mcp/config.d.ts +3 -1
  77. package/dist/mcp/config.d.ts.map +1 -1
  78. package/dist/mcp/config.js +48 -6
  79. package/dist/mcp/paired.js +1 -0
  80. package/dist/notesContext.d.ts.map +1 -1
  81. package/dist/notesContext.js +3 -2
  82. package/dist/room/client.d.ts +20 -7
  83. package/dist/room/client.d.ts.map +1 -1
  84. package/dist/room/client.js +262 -45
  85. package/dist/room/computer.d.ts.map +1 -1
  86. package/dist/room/computer.js +8 -0
  87. package/dist/room/context.d.ts +3 -2
  88. package/dist/room/context.d.ts.map +1 -1
  89. package/dist/room/context.js +10 -3
  90. package/dist/room/turnQueue.d.ts +40 -0
  91. package/dist/room/turnQueue.d.ts.map +1 -0
  92. package/dist/room/turnQueue.js +301 -0
  93. package/dist/skills/lucidity-automations/SKILL.md +54 -0
  94. package/dist/speech/captures.d.ts +30 -0
  95. package/dist/speech/captures.d.ts.map +1 -0
  96. package/dist/speech/captures.js +209 -0
  97. package/dist/speech/fluidAudio.d.ts +28 -0
  98. package/dist/speech/fluidAudio.d.ts.map +1 -0
  99. package/dist/speech/fluidAudio.js +182 -0
  100. package/dist/speech/service.d.ts +14 -0
  101. package/dist/speech/service.d.ts.map +1 -0
  102. package/dist/speech/service.js +88 -0
  103. package/dist/speech/types.d.ts +19 -0
  104. package/dist/speech/types.d.ts.map +1 -0
  105. package/dist/speech/types.js +1 -0
  106. package/dist/turnLog.d.ts +1 -0
  107. package/dist/turnLog.d.ts.map +1 -1
  108. package/dist/turnLog.js +3 -0
  109. package/native/speech/Package.resolved +15 -0
  110. package/native/speech/Package.swift +16 -0
  111. package/native/speech/Sources/lucidity-speech/Speech.swift +81 -0
  112. package/package.json +6 -2
  113. package/src/automations/agent.ts +239 -0
  114. package/src/automations/cli.ts +52 -0
  115. package/src/automations/connections.ts +83 -0
  116. package/src/automations/designer.ts +594 -0
  117. package/src/automations/history.ts +59 -0
  118. package/src/automations/learning.ts +180 -0
  119. package/src/automations/pinterest.ts +146 -0
  120. package/src/automations/service.ts +505 -0
  121. package/src/automations/setup.ts +71 -0
  122. package/src/automations/skill.ts +40 -0
  123. package/src/automations/store.ts +63 -0
  124. package/src/chat/server.ts +62 -3
  125. package/src/coding/commandContext.ts +29 -0
  126. package/src/coding/runCodeTurn.ts +65 -21
  127. package/src/coding/worktree.ts +3 -4
  128. package/src/config.ts +29 -2
  129. package/src/decisions/cli.ts +136 -0
  130. package/src/decisions/client.ts +62 -0
  131. package/src/handoff.ts +28 -0
  132. package/src/index.ts +196 -67
  133. package/src/jobs/briefing.ts +1 -1
  134. package/src/jobs/extraction.ts +157 -32
  135. package/src/jobs/fastModeReview.ts +221 -0
  136. package/src/jobs/voiceReview.ts +156 -0
  137. package/src/mcp/clients.ts +1 -1
  138. package/src/mcp/config.ts +56 -6
  139. package/src/mcp/paired.ts +1 -0
  140. package/src/notesContext.ts +3 -2
  141. package/src/room/client.ts +316 -52
  142. package/src/room/computer.ts +8 -0
  143. package/src/room/context.ts +12 -3
  144. package/src/room/turnQueue.ts +358 -0
  145. package/src/speech/captures.ts +265 -0
  146. package/src/speech/fluidAudio.ts +242 -0
  147. package/src/speech/service.ts +108 -0
  148. package/src/speech/types.ts +13 -0
  149. package/src/turnLog.ts +4 -0
  150. package/vendor/decisions/LICENSE +662 -0
  151. package/vendor/decisions/dist/capture.d.ts +79 -0
  152. package/vendor/decisions/dist/capture.js +183 -0
  153. package/vendor/decisions/dist/command.d.ts +202 -0
  154. package/vendor/decisions/dist/command.js +750 -0
  155. package/vendor/decisions/dist/gate.d.ts +12 -0
  156. package/vendor/decisions/dist/gate.js +18 -0
  157. package/vendor/decisions/dist/index.d.ts +5 -0
  158. package/vendor/decisions/dist/index.js +5 -0
  159. package/vendor/decisions/dist/jev.d.ts +15 -0
  160. package/vendor/decisions/dist/jev.js +242 -0
  161. package/vendor/decisions/dist/types.d.ts +67 -0
  162. package/vendor/decisions/dist/types.js +1 -0
  163. package/vendor/decisions/package.json +22 -0
  164. package/vendor/decisions/src/capture.ts +199 -0
  165. package/vendor/decisions/src/command.ts +836 -0
  166. package/vendor/decisions/src/gate.ts +32 -0
  167. package/vendor/decisions/src/index.ts +5 -0
  168. package/vendor/decisions/src/jev.ts +293 -0
  169. package/vendor/decisions/src/types.ts +79 -0
  170. package/vendor/mcp-server/README.md +6 -1
  171. package/vendor/mcp-server/dist/client.d.ts +1 -0
  172. package/vendor/mcp-server/dist/client.d.ts.map +1 -1
  173. package/vendor/mcp-server/dist/client.js +8 -0
  174. package/vendor/mcp-server/dist/commentProvider.d.ts +3 -0
  175. package/vendor/mcp-server/dist/commentProvider.d.ts.map +1 -0
  176. package/vendor/mcp-server/dist/commentProvider.js +10 -0
  177. package/vendor/mcp-server/dist/index.js +21 -6
  178. package/vendor/mcp-server/dist/tools/automations.d.ts +6 -0
  179. package/vendor/mcp-server/dist/tools/automations.d.ts.map +1 -0
  180. package/vendor/mcp-server/dist/tools/automations.js +163 -0
  181. package/vendor/mcp-server/dist/tools/commandEventFormat.d.ts +52 -0
  182. package/vendor/mcp-server/dist/tools/commandEventFormat.d.ts.map +1 -0
  183. package/vendor/mcp-server/dist/tools/commandEventFormat.js +83 -0
  184. package/vendor/mcp-server/dist/tools/commandEvents.d.ts +3 -0
  185. package/vendor/mcp-server/dist/tools/commandEvents.d.ts.map +1 -0
  186. package/vendor/mcp-server/dist/tools/commandEvents.js +21 -0
  187. package/vendor/mcp-server/dist/tools/comments.d.ts.map +1 -1
  188. package/vendor/mcp-server/dist/tools/comments.js +25 -4
  189. package/vendor/mcp-server/dist/tools/index.d.ts +2 -0
  190. package/vendor/mcp-server/dist/tools/index.d.ts.map +1 -1
  191. package/vendor/mcp-server/dist/tools/index.js +2 -0
  192. package/vendor/mcp-server/dist/tools/journal.d.ts +3 -0
  193. package/vendor/mcp-server/dist/tools/journal.d.ts.map +1 -0
  194. package/vendor/mcp-server/dist/tools/journal.js +131 -0
  195. package/vendor/mcp-server/dist/tools/taskActivity.d.ts +3 -0
  196. package/vendor/mcp-server/dist/tools/taskActivity.d.ts.map +1 -0
  197. package/vendor/mcp-server/dist/tools/taskActivity.js +32 -0
  198. package/vendor/mcp-server/dist/tools/taskOccurrences.d.ts +3 -0
  199. package/vendor/mcp-server/dist/tools/taskOccurrences.d.ts.map +1 -0
  200. package/vendor/mcp-server/dist/tools/taskOccurrences.js +12 -0
  201. package/vendor/mcp-server/dist/tools/taskTrash.d.ts +3 -0
  202. package/vendor/mcp-server/dist/tools/taskTrash.d.ts.map +1 -0
  203. package/vendor/mcp-server/dist/tools/taskTrash.js +21 -0
  204. package/vendor/mcp-server/dist/tools/tasks.d.ts.map +1 -1
  205. package/vendor/mcp-server/dist/tools/tasks.js +67 -27
  206. package/vendor/mcp-server/package.json +5 -1
  207. package/vendor/mcp-server/src/client.ts +10 -0
  208. package/vendor/mcp-server/src/commentProvider.ts +9 -0
  209. package/vendor/mcp-server/src/index.ts +20 -6
  210. package/vendor/mcp-server/src/tools/automations.ts +199 -0
  211. package/vendor/mcp-server/src/tools/commandEventFormat.ts +108 -0
  212. package/vendor/mcp-server/src/tools/commandEvents.ts +27 -0
  213. package/vendor/mcp-server/src/tools/comments.ts +24 -3
  214. package/vendor/mcp-server/src/tools/index.ts +2 -0
  215. package/vendor/mcp-server/src/tools/journal.ts +168 -0
  216. package/vendor/mcp-server/src/tools/taskActivity.ts +55 -0
  217. package/vendor/mcp-server/src/tools/taskOccurrences.ts +26 -0
  218. package/vendor/mcp-server/src/tools/taskTrash.ts +23 -0
  219. package/vendor/mcp-server/src/tools/tasks.ts +66 -30
  220. package/vendor/notes/dist/index.d.ts +2 -0
  221. package/vendor/notes/dist/index.d.ts.map +1 -1
  222. package/vendor/notes/dist/index.js +2 -0
  223. package/vendor/notes/dist/journal-backend.d.ts +4 -0
  224. package/vendor/notes/dist/journal-backend.d.ts.map +1 -0
  225. package/vendor/notes/dist/journal-backend.js +33 -0
  226. package/vendor/notes/dist/journal.d.ts +7 -0
  227. package/vendor/notes/dist/journal.d.ts.map +1 -0
  228. package/vendor/notes/dist/journal.js +173 -0
  229. package/vendor/notes/dist/vault.d.ts.map +1 -1
  230. package/vendor/notes/dist/vault.js +6 -1
  231. package/vendor/notes/src/index.ts +2 -0
  232. package/vendor/notes/src/journal-backend.ts +53 -0
  233. package/vendor/notes/src/journal.ts +194 -0
  234. package/vendor/notes/src/vault.ts +9 -1
  235. package/vendor/runtime/README.md +4 -0
  236. package/vendor/runtime/dist/executor/claudeAgent.d.ts +2 -0
  237. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  238. package/vendor/runtime/dist/executor/claudeAgent.js +113 -8
  239. package/vendor/runtime/dist/executor/claudeCode.d.ts.map +1 -1
  240. package/vendor/runtime/dist/executor/claudeCode.js +8 -4
  241. package/vendor/runtime/dist/executor/codex.d.ts +2 -0
  242. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  243. package/vendor/runtime/dist/executor/codex.js +213 -11
  244. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +2 -0
  245. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -0
  246. package/vendor/runtime/dist/executor/codexProtocol/PlanType.js +2 -0
  247. package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.d.ts +6 -0
  248. package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.d.ts.map +1 -0
  249. package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.js +2 -0
  250. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +26 -0
  251. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -0
  252. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.js +2 -0
  253. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.d.ts +2 -0
  254. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.d.ts.map +1 -0
  255. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.js +2 -0
  256. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.d.ts +27 -0
  257. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.d.ts.map +1 -0
  258. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.js +2 -0
  259. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.d.ts +2 -0
  260. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.d.ts.map +1 -0
  261. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.js +2 -0
  262. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.d.ts +13 -0
  263. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.d.ts.map +1 -0
  264. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.js +2 -0
  265. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.d.ts +2 -0
  266. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.d.ts.map +1 -0
  267. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.js +2 -0
  268. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +20 -0
  269. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -0
  270. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.js +2 -0
  271. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.d.ts +6 -0
  272. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.d.ts.map +1 -0
  273. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.js +2 -0
  274. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.d.ts +2 -0
  275. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.d.ts.map +1 -0
  276. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.js +2 -0
  277. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +12 -0
  278. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -0
  279. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.js +2 -0
  280. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.d.ts +17 -0
  281. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.d.ts.map +1 -0
  282. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.js +2 -0
  283. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.d.ts +5 -0
  284. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.d.ts.map +1 -0
  285. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.js +2 -0
  286. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.d.ts +5 -0
  287. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.d.ts.map +1 -0
  288. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.js +2 -0
  289. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.d.ts +18 -0
  290. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.d.ts.map +1 -0
  291. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.js +2 -0
  292. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.d.ts +22 -0
  293. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.d.ts.map +1 -0
  294. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.js +2 -0
  295. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.d.ts +2 -0
  296. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.d.ts.map +1 -0
  297. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.js +2 -0
  298. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.d.ts +9 -0
  299. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.d.ts.map +1 -0
  300. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.js +2 -0
  301. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.d.ts +8 -0
  302. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.d.ts.map +1 -0
  303. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.js +2 -0
  304. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.d.ts +5 -0
  305. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.d.ts.map +1 -0
  306. package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.js +2 -0
  307. package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.d.ts +7 -0
  308. package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.d.ts.map +1 -0
  309. package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.js +2 -0
  310. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.d.ts +5 -0
  311. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.d.ts.map +1 -0
  312. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.js +2 -0
  313. package/vendor/runtime/dist/executor/health.d.ts +1 -0
  314. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  315. package/vendor/runtime/dist/executor/health.js +3 -0
  316. package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
  317. package/vendor/runtime/dist/executor/liveTurns.js +3 -0
  318. package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
  319. package/vendor/runtime/dist/executor/providerRouter.js +2 -1
  320. package/vendor/runtime/dist/executor/types.d.ts +8 -0
  321. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  322. package/vendor/runtime/dist/harness/index.d.ts +1 -0
  323. package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
  324. package/vendor/runtime/dist/harness/index.js +35 -1
  325. package/vendor/runtime/dist/harness/types.d.ts +4 -1
  326. package/vendor/runtime/dist/harness/types.d.ts.map +1 -1
  327. package/vendor/runtime/dist/index.d.ts +2 -1
  328. package/vendor/runtime/dist/index.d.ts.map +1 -1
  329. package/vendor/runtime/dist/index.js +2 -0
  330. package/vendor/runtime/dist/journal/context.d.ts +18 -0
  331. package/vendor/runtime/dist/journal/context.d.ts.map +1 -1
  332. package/vendor/runtime/dist/journal/context.js +19 -5
  333. package/vendor/runtime/dist/prompts/briefing.d.ts +4 -7
  334. package/vendor/runtime/dist/prompts/briefing.d.ts.map +1 -1
  335. package/vendor/runtime/dist/prompts/briefing.js +61 -12
  336. package/vendor/runtime/dist/prompts/cardStatement.d.ts +7 -0
  337. package/vendor/runtime/dist/prompts/cardStatement.d.ts.map +1 -0
  338. package/vendor/runtime/dist/prompts/cardStatement.js +52 -0
  339. package/vendor/runtime/dist/prompts/chat.d.ts +1 -0
  340. package/vendor/runtime/dist/prompts/chat.d.ts.map +1 -1
  341. package/vendor/runtime/dist/prompts/chat.js +15 -1
  342. package/vendor/runtime/dist/prompts/projectCapture.d.ts +7 -0
  343. package/vendor/runtime/dist/prompts/projectCapture.d.ts.map +1 -0
  344. package/vendor/runtime/dist/prompts/projectCapture.js +31 -0
  345. package/vendor/runtime/src/executor/claudeAgent.ts +133 -7
  346. package/vendor/runtime/src/executor/claudeCode.ts +6 -4
  347. package/vendor/runtime/src/executor/codex.ts +280 -20
  348. package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +5 -0
  349. package/vendor/runtime/src/executor/codexProtocol/v2/CreditsSnapshot.ts +5 -0
  350. package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +25 -0
  351. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitReachedType.ts +5 -0
  352. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCredit.ts +27 -0
  353. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCreditStatus.ts +5 -0
  354. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCreditsSummary.ts +14 -0
  355. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetType.ts +5 -0
  356. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +14 -0
  357. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitWindow.ts +5 -0
  358. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewDelivery.ts +5 -0
  359. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +12 -0
  360. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewTarget.ts +9 -0
  361. package/vendor/runtime/src/executor/codexProtocol/v2/SkillDependencies.ts +6 -0
  362. package/vendor/runtime/src/executor/codexProtocol/v2/SkillErrorInfo.ts +5 -0
  363. package/vendor/runtime/src/executor/codexProtocol/v2/SkillInterface.ts +14 -0
  364. package/vendor/runtime/src/executor/codexProtocol/v2/SkillMetadata.ts +17 -0
  365. package/vendor/runtime/src/executor/codexProtocol/v2/SkillScope.ts +5 -0
  366. package/vendor/runtime/src/executor/codexProtocol/v2/SkillToolDependency.ts +5 -0
  367. package/vendor/runtime/src/executor/codexProtocol/v2/SkillsListEntry.ts +7 -0
  368. package/vendor/runtime/src/executor/codexProtocol/v2/SkillsListResponse.ts +6 -0
  369. package/vendor/runtime/src/executor/codexProtocol/v2/SpendControlLimitSnapshot.ts +5 -0
  370. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSetNameParams.ts +5 -0
  371. package/vendor/runtime/src/executor/health.ts +3 -0
  372. package/vendor/runtime/src/executor/liveTurns.ts +3 -0
  373. package/vendor/runtime/src/executor/providerRouter.ts +2 -1
  374. package/vendor/runtime/src/executor/types.ts +8 -0
  375. package/vendor/runtime/src/harness/index.ts +40 -6
  376. package/vendor/runtime/src/harness/types.ts +4 -1
  377. package/vendor/runtime/src/index.ts +4 -1
  378. package/vendor/runtime/src/journal/context.ts +40 -7
  379. package/vendor/runtime/src/prompts/briefing.ts +62 -17
  380. package/vendor/runtime/src/prompts/cardStatement.ts +64 -0
  381. package/vendor/runtime/src/prompts/chat.ts +25 -3
  382. package/vendor/runtime/src/prompts/projectCapture.ts +51 -0
  383. package/vendor/shared/dist/agentCommands.d.ts +22 -0
  384. package/vendor/shared/dist/agentCommands.d.ts.map +1 -0
  385. package/vendor/shared/dist/agentCommands.js +11 -0
  386. package/vendor/shared/dist/automationTemplates.d.ts +37 -0
  387. package/vendor/shared/dist/automationTemplates.d.ts.map +1 -0
  388. package/vendor/shared/dist/automationTemplates.js +48 -0
  389. package/vendor/shared/dist/automations.d.ts +1052 -0
  390. package/vendor/shared/dist/automations.d.ts.map +1 -0
  391. package/vendor/shared/dist/automations.js +300 -0
  392. package/vendor/shared/dist/cardStatement.d.ts +28 -0
  393. package/vendor/shared/dist/cardStatement.d.ts.map +1 -0
  394. package/vendor/shared/dist/cardStatement.js +37 -0
  395. package/vendor/shared/dist/cardStudio.d.ts +756 -0
  396. package/vendor/shared/dist/cardStudio.d.ts.map +1 -0
  397. package/vendor/shared/dist/cardStudio.js +297 -0
  398. package/vendor/shared/dist/commandLocal.d.ts +218 -0
  399. package/vendor/shared/dist/commandLocal.d.ts.map +1 -0
  400. package/vendor/shared/dist/commandLocal.js +662 -0
  401. package/vendor/shared/dist/commandText.d.ts +12 -0
  402. package/vendor/shared/dist/commandText.d.ts.map +1 -0
  403. package/vendor/shared/dist/commandText.js +21 -0
  404. package/vendor/shared/dist/commands.d.ts +1516 -0
  405. package/vendor/shared/dist/commands.d.ts.map +1 -0
  406. package/vendor/shared/dist/commands.js +231 -0
  407. package/vendor/shared/dist/computer.d.ts +9 -9
  408. package/vendor/shared/dist/computer.d.ts.map +1 -1
  409. package/vendor/shared/dist/computer.js +11 -2
  410. package/vendor/shared/dist/constants.d.ts +3 -3
  411. package/vendor/shared/dist/constants.d.ts.map +1 -1
  412. package/vendor/shared/dist/constants.js +9 -2
  413. package/vendor/shared/dist/githubContributions.d.ts +93 -0
  414. package/vendor/shared/dist/githubContributions.d.ts.map +1 -0
  415. package/vendor/shared/dist/githubContributions.js +54 -0
  416. package/vendor/shared/dist/habitContributions.d.ts +26 -0
  417. package/vendor/shared/dist/habitContributions.d.ts.map +1 -0
  418. package/vendor/shared/dist/habitContributions.js +119 -0
  419. package/vendor/shared/dist/index.d.ts +26 -2
  420. package/vendor/shared/dist/index.d.ts.map +1 -1
  421. package/vendor/shared/dist/index.js +23 -2
  422. package/vendor/shared/dist/journal-migration.d.ts +29 -0
  423. package/vendor/shared/dist/journal-migration.d.ts.map +1 -0
  424. package/vendor/shared/dist/journal-migration.js +73 -0
  425. package/vendor/shared/dist/journal-vault.d.ts +414 -0
  426. package/vendor/shared/dist/journal-vault.d.ts.map +1 -0
  427. package/vendor/shared/dist/journal-vault.js +972 -0
  428. package/vendor/shared/dist/projectCapture.d.ts +73 -0
  429. package/vendor/shared/dist/projectCapture.d.ts.map +1 -0
  430. package/vendor/shared/dist/projectCapture.js +66 -0
  431. package/vendor/shared/dist/quickAdd.d.ts +90 -0
  432. package/vendor/shared/dist/quickAdd.d.ts.map +1 -0
  433. package/vendor/shared/dist/quickAdd.js +260 -0
  434. package/vendor/shared/dist/recurrence.d.ts +44 -0
  435. package/vendor/shared/dist/recurrence.d.ts.map +1 -0
  436. package/vendor/shared/dist/recurrence.js +37 -0
  437. package/vendor/shared/dist/reminderWords.d.ts +11 -0
  438. package/vendor/shared/dist/reminderWords.d.ts.map +1 -0
  439. package/vendor/shared/dist/reminderWords.js +63 -0
  440. package/vendor/shared/dist/schemas/comment.d.ts +13 -1
  441. package/vendor/shared/dist/schemas/comment.d.ts.map +1 -1
  442. package/vendor/shared/dist/schemas/comment.js +5 -0
  443. package/vendor/shared/dist/schemas/conversation.d.ts +3 -3
  444. package/vendor/shared/dist/schemas/harness.d.ts +922 -59
  445. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  446. package/vendor/shared/dist/schemas/harness.js +122 -3
  447. package/vendor/shared/dist/schemas/journal.d.ts +10 -0
  448. package/vendor/shared/dist/schemas/journal.d.ts.map +1 -1
  449. package/vendor/shared/dist/schemas/journal.js +10 -2
  450. package/vendor/shared/dist/schemas/notification.d.ts +1 -1
  451. package/vendor/shared/dist/schemas/organization.d.ts +3 -2
  452. package/vendor/shared/dist/schemas/organization.d.ts.map +1 -1
  453. package/vendor/shared/dist/schemas/organization.js +3 -2
  454. package/vendor/shared/dist/schemas/proposal.d.ts +7 -3
  455. package/vendor/shared/dist/schemas/proposal.d.ts.map +1 -1
  456. package/vendor/shared/dist/schemas/proposal.js +2 -1
  457. package/vendor/shared/dist/schemas/request.d.ts +44 -4
  458. package/vendor/shared/dist/schemas/request.d.ts.map +1 -1
  459. package/vendor/shared/dist/schemas/task.d.ts +83 -8
  460. package/vendor/shared/dist/schemas/task.d.ts.map +1 -1
  461. package/vendor/shared/dist/schemas/task.js +20 -2
  462. package/vendor/shared/dist/schemas/timeSession.d.ts +2 -2
  463. package/vendor/shared/dist/smartCapture.d.ts +60 -0
  464. package/vendor/shared/dist/smartCapture.d.ts.map +1 -0
  465. package/vendor/shared/dist/smartCapture.js +56 -0
  466. package/vendor/shared/dist/speech.d.ts +39 -0
  467. package/vendor/shared/dist/speech.d.ts.map +1 -0
  468. package/vendor/shared/dist/speech.js +36 -0
  469. package/vendor/shared/dist/spokenNames.d.ts +25 -0
  470. package/vendor/shared/dist/spokenNames.d.ts.map +1 -0
  471. package/vendor/shared/dist/spokenNames.js +120 -0
  472. package/vendor/shared/dist/taskActivity.d.ts +76 -0
  473. package/vendor/shared/dist/taskActivity.d.ts.map +1 -0
  474. package/vendor/shared/dist/taskActivity.js +27 -0
  475. package/vendor/shared/dist/vault-search.d.ts +50 -0
  476. package/vendor/shared/dist/vault-search.d.ts.map +1 -0
  477. package/vendor/shared/dist/vault-search.js +177 -0
  478. package/vendor/shared/dist/voiceCapture.d.ts +32 -0
  479. package/vendor/shared/dist/voiceCapture.d.ts.map +1 -0
  480. package/vendor/shared/dist/voiceCapture.js +29 -0
  481. package/vendor/shared/package.json +4 -0
  482. package/vendor/shared/src/agentCommands.ts +35 -0
  483. package/vendor/shared/src/automationTemplates.ts +54 -0
  484. package/vendor/shared/src/automations.ts +329 -0
  485. package/vendor/shared/src/cardStatement.ts +49 -0
  486. package/vendor/shared/src/cardStudio.ts +340 -0
  487. package/vendor/shared/src/commandLocal.ts +738 -0
  488. package/vendor/shared/src/commandText.ts +25 -0
  489. package/vendor/shared/src/commands.ts +253 -0
  490. package/vendor/shared/src/computer.ts +23 -6
  491. package/vendor/shared/src/constants.ts +9 -2
  492. package/vendor/shared/src/githubContributions.ts +70 -0
  493. package/vendor/shared/src/habitContributions.ts +144 -0
  494. package/vendor/shared/src/index.ts +42 -1
  495. package/vendor/shared/src/journal-migration.ts +130 -0
  496. package/vendor/shared/src/journal-vault.ts +1240 -0
  497. package/vendor/shared/src/projectCapture.ts +86 -0
  498. package/vendor/shared/src/quickAdd.ts +310 -0
  499. package/vendor/shared/src/recurrence.ts +37 -0
  500. package/vendor/shared/src/reminderWords.ts +54 -0
  501. package/vendor/shared/src/schemas/comment.ts +5 -0
  502. package/vendor/shared/src/schemas/harness.ts +144 -7
  503. package/vendor/shared/src/schemas/journal.ts +15 -6
  504. package/vendor/shared/src/schemas/organization.ts +3 -2
  505. package/vendor/shared/src/schemas/proposal.ts +6 -1
  506. package/vendor/shared/src/schemas/task.ts +20 -2
  507. package/vendor/shared/src/smartCapture.ts +67 -0
  508. package/vendor/shared/src/speech.ts +44 -0
  509. package/vendor/shared/src/spokenNames.ts +128 -0
  510. package/vendor/shared/src/taskActivity.ts +34 -0
  511. package/vendor/shared/src/vault-search.ts +243 -0
  512. package/vendor/shared/src/voiceCapture.ts +34 -0
@@ -0,0 +1,662 @@
1
+ import { COMMAND_DESTINATIONS, DESTINATION_PARENTS, ORGANIZATION_DESTINATIONS } from './commands.js';
2
+ import { normalizeInstruction, proposeClauses } from './commandText.js';
3
+ /**
4
+ * What people call each screen besides its label. Matched after `key()`, so no "my", "the" or
5
+ * "screen", and in either number (see `otherNumber`), so "chat" also covers "chats".
6
+ */
7
+ const ALIASES = {
8
+ dash: ['home', 'go home', 'main'],
9
+ search: ['task list', 'search'],
10
+ today: ['todays tasks', 'tasks for today', 'whats due today'],
11
+ inbox: [],
12
+ projects: ['project list', 'list of projects'],
13
+ milestones: ['milestone list', 'list of milestones'],
14
+ notes: [],
15
+ journal: ['voice journal'],
16
+ habits: [],
17
+ chat: ['chat', 'chats', 'direct messages', 'dms'],
18
+ code: ['coding'],
19
+ team: ['organizations', 'orgs'],
20
+ standups: ['stand up', 'daily standup', 'daily stand up', 'scrum'],
21
+ procurement: ['purchase requests', 'purchase orders', 'purchases', 'procurement requests'],
22
+ notifications: ['alerts'],
23
+ settings: ['preferences'],
24
+ voice: ['voice and speech', 'speech'],
25
+ computer: ['my computer', 'my mac'],
26
+ computer_settings: ['mac settings', 'lucid settings'],
27
+ automations: ['schedules', 'scheduled jobs'],
28
+ trash: ['deleted tasks', 'bin'],
29
+ apple_watch: ['watch'],
30
+ tab_bar: ['tab bar settings', 'bottom bar'],
31
+ organizations: ['manage organizations'],
32
+ api_key: ['api keys'],
33
+ profile: ['my profile'],
34
+ edit_profile: ['profile settings'],
35
+ connections: ['people', 'contacts'],
36
+ review: ['review queue', 'proposals', 'suggestions'],
37
+ weekly_review: ['weekly review', 'week review', 'my week'],
38
+ focus: ['focus mode', 'focus timer'],
39
+ card_studio: ['cards', 'add cards', 'dashboard cards'],
40
+ ask_lucid: ['ask lucid', 'lucid chat'],
41
+ };
42
+ /** Lowercase, accents and emoji gone, punctuation as spaces: "Finance 💵" is "finance". */
43
+ function fold(s) {
44
+ return s
45
+ .normalize('NFKD')
46
+ .replace(/[̀-ͯ]/g, '')
47
+ .toLowerCase()
48
+ .replace(/&/g, ' and ')
49
+ .replace(/['’]/g, '')
50
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
51
+ .trim();
52
+ }
53
+ const DETERMINERS = /^(?:(?:all|of|my|the|our|your) )+/;
54
+ const SCREEN_WORDS = / (?:page|screen|tab|view|section)$/;
55
+ /** Applied to what was said and to every name alike, so "The Plan" still matches "open the plan". */
56
+ const key = (folded) => folded.replace(DETERMINERS, '').replace(SCREEN_WORDS, '').trim();
57
+ /**
58
+ * The same words with the last one in the other number: "milestone" and "milestones", "category"
59
+ * and "categories", "launch" and "launches". People say either, and speech recognition drops a plural "s" often enough
60
+ * that "open tasks" reached the phone as "open task".
61
+ */
62
+ function otherNumber(words) {
63
+ const i = words.lastIndexOf(' ') + 1;
64
+ const head = words.slice(0, i);
65
+ const last = words.slice(i);
66
+ if (/[^aeiou]ies$/.test(last))
67
+ return head + last.slice(0, -3) + 'y';
68
+ if (/(?:ch|sh|x|z|ss)es$/.test(last))
69
+ return head + last.slice(0, -2);
70
+ if (/[^s]s$/.test(last))
71
+ return head + last.slice(0, -1);
72
+ if (/[^aeiou]y$/.test(last))
73
+ return head + last.slice(0, -1) + 'ies';
74
+ if (/(?:ch|sh|x|z|s)$/.test(last))
75
+ return head + last + 'es';
76
+ return head + last + 's';
77
+ }
78
+ const LEAD = new RegExp('^(?:(?:i (?:want|wanna|need|would like|d like) to |lets |let me )?' +
79
+ '(?:(?:go|take me|bring me|get me|navigate|jump|switch|head|move)(?: back)?(?: over)? (?:to|into)|back to|' +
80
+ 'open(?: up)?|show(?: me)?|bring up|pull up|view|display|see))(?: |$)');
81
+ const TRAILING = /(?: (?:please|now|right now|for me|thanks|thank you))+$/;
82
+ const KIND_HINT = /^(?:(project|milestone) (.+)|(.+) (project|milestone))$/;
83
+ /**
84
+ * Every way of naming a place. The first place to claim a phrase keeps it, most specific first: a
85
+ * top-level place's own words, then a nested place's own words, then the pairs a nested place makes
86
+ * with its parent's words ("voice settings", "settings voice"). So "organizations" stays the Teams
87
+ * tab while "organization settings" is the Settings screen, and a new nested place is reachable by
88
+ * those pairs without writing any of them.
89
+ */
90
+ const DESTINATIONS = new Map();
91
+ {
92
+ const words = (d) => [d.label, ...ALIASES[d.key]];
93
+ const claim = (phrase, place) => {
94
+ const k = key(fold(phrase));
95
+ if (!DESTINATIONS.has(k))
96
+ DESTINATIONS.set(k, place);
97
+ };
98
+ const nested = COMMAND_DESTINATIONS.filter((d) => DESTINATION_PARENTS[d.key]);
99
+ for (const d of COMMAND_DESTINATIONS)
100
+ if (!DESTINATION_PARENTS[d.key])
101
+ for (const w of words(d))
102
+ claim(w, d.key);
103
+ for (const d of nested)
104
+ for (const w of words(d))
105
+ claim(w, d.key);
106
+ for (const d of nested) {
107
+ const parent = COMMAND_DESTINATIONS.find((p) => p.key === DESTINATION_PARENTS[d.key]);
108
+ // The other number too, as the first word of a pair: "organization settings".
109
+ for (const w of words(d).flatMap((w) => [w, otherNumber(key(fold(w)))])) {
110
+ for (const under of words(parent)) {
111
+ claim(`${w} ${under}`, d.key);
112
+ claim(`${under} ${w}`, d.key);
113
+ claim(`${w} in ${under}`, d.key);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ function named(context, name, only) {
119
+ const pick = (list, kind) => only && only !== kind ? [] : list
120
+ .filter((t) => key(fold(t.name)) === name)
121
+ .map((t) => ({ kind: 'open', item: { kind, id: t.id, title: t.name } }));
122
+ return [...pick(context.projects, 'project'), ...pick(context.milestones, 'milestone')];
123
+ }
124
+ const BACK = /^(?:(?:please )?(?:go|take me|bring me|get me|navigate|head) )?back(?: (?:to )?(?:the )?(?:previous|last) (?:screen|page|one))?$|^(?:go |take me )?(?:to )?(?:the )?previous (?:screen|page)$/;
125
+ const ORDINAL_WORDS = {
126
+ first: 1, second: 2, third: 3, fourth: 4, fifth: 5, sixth: 6, seventh: 7, eighth: 8, ninth: 9, tenth: 10,
127
+ one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10,
128
+ };
129
+ // "mile" is "milestone" with its end dropped by speech recognition: "Open second Mile" went to Jev
130
+ // and took 4.1 s on 2026-09-26, the slowest turn of that window.
131
+ const ORDINAL = /^(?:the )?(first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|last|\d{1,2}(?:st|nd|rd|th))(?: (task|project|milestone|mile|one|item|result)s?)?$/;
132
+ const NUMBERED = /^(task|project|milestone|mile|item|result|number)(?: number)? (\d{1,2}|one|two|three|four|five|six|seven|eight|nine|ten)$/;
133
+ /** "in it", "here", "on the screen": where the list is, which is the screen either way. */
134
+ const ON_SCREEN = / (?:in it|on it|here|in here|on (?:the|this|my) (?:screen|page|list)|in (?:the|this) (?:list|project|milestone))$/;
135
+ /**
136
+ * "the first task", "the second one", "task number 3", "the last project": a position in a list,
137
+ * with or without a verb in front. Null when the words are anything more than that.
138
+ */
139
+ export function ordinalReference(text) {
140
+ let said = fold(normalizeInstruction(text));
141
+ const lead = LEAD.exec(said);
142
+ if (lead)
143
+ said = said.slice(lead[0].length);
144
+ said = said.replace(TRAILING, '').replace(ON_SCREEN, '').trim();
145
+ const kindOf = (word) => word === 'mile' ? 'milestone' : word === 'task' || word === 'project' || word === 'milestone' ? word : undefined;
146
+ const ordinal = ORDINAL.exec(said);
147
+ if (ordinal) {
148
+ const [, which, kind] = ordinal;
149
+ const position = which === 'last' ? 'last' : (ORDINAL_WORDS[which] ?? parseInt(which, 10));
150
+ return { position, ...(kindOf(kind) ? { kind: kindOf(kind) } : {}) };
151
+ }
152
+ const numbered = NUMBERED.exec(said);
153
+ if (numbered) {
154
+ const [, kind, n] = numbered;
155
+ return { position: ORDINAL_WORDS[n] ?? parseInt(n, 10), ...(kindOf(kind) ? { kind: kindOf(kind) } : {}) };
156
+ }
157
+ return null;
158
+ }
159
+ /** The item a reference points at among `items`, counting only the kind it names. */
160
+ export function pickByOrdinal(items, ref) {
161
+ const pool = ref.kind ? items.filter((item) => item.kind === ref.kind) : items;
162
+ const index = ref.position === 'last' ? pool.length - 1 : ref.position - 1;
163
+ return index >= 0 && index < pool.length ? pool[index] : null;
164
+ }
165
+ /** One clause, carried out on the phone if it is certainly a place or a name. Null means ask Jev. */
166
+ export function resolveLocalCommand(text, context) {
167
+ let said = fold(normalizeInstruction(text));
168
+ if (BACK.test(said.replace(TRAILING, '').trim()))
169
+ return { kind: 'back' };
170
+ const lead = LEAD.exec(said);
171
+ if (lead)
172
+ said = said.slice(lead[0].length);
173
+ said = said.replace(TRAILING, '').trim();
174
+ const target = key(said);
175
+ if (!target)
176
+ return null;
177
+ // "the Lucidity project": look among projects only, then fall back to the words as a whole name
178
+ // for a project that is actually called "Side Project".
179
+ const hint = KIND_HINT.exec(said);
180
+ if (hint) {
181
+ const kind = (hint[1] ?? hint[4]);
182
+ const name = key(hint[2] ?? hint[3]);
183
+ for (const form of [name, otherNumber(name)]) {
184
+ const found = named(context, form, kind);
185
+ if (found.length === 1)
186
+ return found[0];
187
+ if (found.length > 1)
188
+ return null;
189
+ }
190
+ }
191
+ // "Neucleosoft procurement", "standups for Neucleosoft": a place of one named organization.
192
+ const inOrganization = organizationPlace(target, context.organizations ?? []);
193
+ if (inOrganization)
194
+ return inOrganization;
195
+ // Exactly what was said first, then the other number, so a project called "Notes" is still
196
+ // told apart from the Notes screen before "note" is ever read as either.
197
+ for (const form of [target, otherNumber(target)]) {
198
+ const items = named(context, form);
199
+ const destination = DESTINATIONS.get(form);
200
+ if (destination)
201
+ return items.length ? null : { kind: 'navigate', destination };
202
+ // A bare name could be the start of anything ("Lucidity" as a task title); it needs "open".
203
+ if (items.length)
204
+ return (lead || hint) && items.length === 1 ? items[0] : null;
205
+ }
206
+ // "open the first task in it": the screen's own list. Needs the verb, like a bare name does.
207
+ const ref = lead ? ordinalReference(text) : null;
208
+ const item = ref && context.onScreen ? pickByOrdinal(context.onScreen, ref) : null;
209
+ if (item)
210
+ return { kind: 'open', item: { kind: item.kind, id: item.id, title: item.title } };
211
+ return null;
212
+ }
213
+ /**
214
+ * The first step of an instruction when the phone can carry it out itself, and the clauses left
215
+ * after it, which each get the same chance in turn. `single` is a clause already split off.
216
+ */
217
+ export function planLocally(text, context, single = false) {
218
+ const clauses = single ? [] : proposeClauses(text);
219
+ const step = resolveLocalCommand(clauses[0] ?? text, context);
220
+ return step ? { step, rest: clauses.slice(1) } : null;
221
+ }
222
+ const placeOf = (words) => {
223
+ const place = DESTINATIONS.get(words) ?? DESTINATIONS.get(otherNumber(words));
224
+ return place && ORGANIZATION_DESTINATIONS.includes(place) ? place : undefined;
225
+ };
226
+ function organizationPlace(target, organizations) {
227
+ for (const org of organizations) {
228
+ const name = key(fold(org.name));
229
+ if (!name)
230
+ continue;
231
+ for (const prefix of [`${name} `, `${name}s `]) {
232
+ const place = target.startsWith(prefix) ? placeOf(target.slice(prefix.length)) : undefined;
233
+ if (place)
234
+ return { kind: 'navigate', destination: place, organizationId: org.id };
235
+ }
236
+ const at = new RegExp(` (?:for|in|of|at|from) ${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`).exec(target);
237
+ const place = at ? placeOf(target.slice(0, at.index)) : undefined;
238
+ if (place)
239
+ return { kind: 'navigate', destination: place, organizationId: org.id };
240
+ }
241
+ return null;
242
+ }
243
+ /**
244
+ * Which organization "open procurement" means: the one named, else the one on screen (a Team page,
245
+ * an organization's profile), else the one selected on the Team tab, else the only one there is.
246
+ * With several and nothing to go on, the caller asks.
247
+ */
248
+ export function organizationFor(step, where) {
249
+ if (step.kind !== 'navigate' || !ORGANIZATION_DESTINATIONS.includes(step.destination))
250
+ return null;
251
+ const known = (id) => (id ? where.organizations.find((o) => o.id === id) : undefined);
252
+ const organization = known(step.organizationId) ?? known(where.onScreen) ?? known(where.selected)
253
+ ?? (where.organizations.length === 1 ? where.organizations[0] : undefined);
254
+ if (organization)
255
+ return { step: { ...step, organizationId: organization.id }, organization };
256
+ return { choose: [...where.organizations] };
257
+ }
258
+ /** The reply for a step done on the phone, worded as the API words it. */
259
+ export function describeLocalStep(step) {
260
+ if (step.kind === 'back')
261
+ return 'Going back.';
262
+ if (step.kind === 'open')
263
+ return `Opening “${step.item.title}”.`;
264
+ return `Opening ${COMMAND_DESTINATIONS.find((d) => d.key === step.destination)?.label ?? step.destination}.`;
265
+ }
266
+ /**
267
+ * Instructions that are certainly a new task: "add", "create", "capture", "remind me to", "new
268
+ * task". Stricter than the words Jev is offered, since here nothing checks the guess: a bare
269
+ * "new" would turn "new york trip" into "york trip".
270
+ */
271
+ /** How a task is named once it is announced: "called X", "and call it X", ", name it X". */
272
+ const NAMING = "(?:,? (?:and )?(?:call it|calling it|called|name it|named|title it|titled|saying|that says|say|to))?";
273
+ /** "here", "in this project": the place on screen, which is where the task goes anyway. */
274
+ const HERE = "(?:here|in here|over here|(?:to|in|into|on|under|for) (?:this|the current) (?:project|list|page|screen|milestone))";
275
+ const ADD_LEAD = new RegExp('^(?:(?:add|create|capture|jot down|note down)(?: (?:a|an))?(?: new)?(?: (?:task|to-?do|item|reminder))?' + `(?: ${HERE})?` + NAMING +
276
+ '|new (?:task|to-?do|reminder)' + NAMING +
277
+ '|(?:make|set) (?:a|an) (?:task|to-?do|reminder)' + NAMING +
278
+ '|remind me to|remember to)(?=\\s|$)\\s*[:,\\-–]?\\s*', 'i');
279
+ /**
280
+ * What people say before "add" or "create" without changing what they ask: "let's create a new
281
+ * task", "I want you to add ...". Only stripped in front of an add, so "I need to call mom" is
282
+ * still left to Jev.
283
+ */
284
+ const ADD_OPENER = /^(?:(?:so|ok|okay|alright|right)\s+)?(?:let'?s|let us|go ahead and|i(?:'d| would)? like(?: you)? to|i want(?: you)? to|i need you to|i wanna|please)\s+/i;
285
+ const NOT_A_TASK = /^(?:add|create|make|new|set up)\s+(?:(?:a|an)\s+)?(?:new\s+)?(?:project|milestone|note|habit|journal|comment|sub[\s-]?tasks?|description|details)\b/i;
286
+ /**
287
+ * The words of a new task when the instruction is certainly one ("add buy milk tomorrow" gives
288
+ * "buy milk tomorrow"), an empty string when it names no task at all ("add a new task"), and null
289
+ * when it isn't an add.
290
+ */
291
+ export function addedTaskWords(text) {
292
+ const said = normalizeInstruction(text).replace(/\s+/g, ' ').replace(ADD_OPENER, '');
293
+ if (NOT_A_TASK.test(said))
294
+ return null;
295
+ const lead = ADD_LEAD.exec(said);
296
+ if (!lead)
297
+ return null;
298
+ const words = said.slice(lead[0].length).replace(new RegExp(`[\\s,]*\\b${HERE}$`, 'i'), '').trim();
299
+ // "add a few tasks to this project" asks for several, not one called "Few tasks to ...".
300
+ return SEVERAL.test(words) ? null : words;
301
+ }
302
+ const SEVERAL = /^(?:a\s+)?(?:few|some|several|multiple|couple(?:\s+of)?|more|other|\d+|two|three|four|five|ten)\s+(?:new\s+|more\s+)?(?:tasks|items|to-?dos|things|reminders)\b|^(?:tasks|items|to-?dos)\b/i;
303
+ const PLACE_WORDS = new Set(['to', 'in', 'into', 'on', 'under', 'for']);
304
+ /**
305
+ * A project named at the end of a new task, the way it is said rather than typed: "buy milk to the
306
+ * shopping list", "fix login in Lucidity", "call the bank for the finance project". Returns the
307
+ * words without it. Null when no project matches, or when two do.
308
+ */
309
+ export function spokenProject(words, projects) {
310
+ const parts = words.trim().split(/\s+/);
311
+ const names = projects.map((p) => ({ p, name: key(fold(p.name)) }));
312
+ // Longest first, so "to the shopping list" wins over "list".
313
+ for (let i = 1; i < parts.length - 1; i++) {
314
+ if (!PLACE_WORDS.has(fold(parts[i])))
315
+ continue;
316
+ const said = key(fold(parts.slice(i + 1).join(' ')));
317
+ const forms = new Set([said, otherNumber(said)]);
318
+ const bare = said.replace(/ (?:project|list)$/, '');
319
+ if (bare !== said)
320
+ [bare, otherNumber(bare)].forEach((f) => forms.add(f));
321
+ const found = [...new Map(names.filter((n) => forms.has(n.name)).map((n) => [n.p.id, n.p])).values()];
322
+ if (found.length > 1)
323
+ return null;
324
+ if (found.length === 1)
325
+ return { projectId: found[0].id, projectName: found[0].name, words: parts.slice(0, i).join(' ') };
326
+ }
327
+ return null;
328
+ }
329
+ /** Said on its own, these close Act. Anything longer ("stop the timer task") is an instruction. */
330
+ const DISMISSALS = new Set([
331
+ 'done', 'im done', 'i am done', 'all done', 'thats all', 'thats it', 'thats everything',
332
+ 'stop', 'stop listening', 'close', 'close it', 'cancel', 'never mind', 'nevermind', 'forget it',
333
+ 'bye', 'bye bye', 'goodbye', 'good bye', 'see you', 'thanks', 'thank you', 'no thanks',
334
+ 'no thank you', 'nothing', 'nothing else', 'exit', 'dismiss', 'go away', 'quit',
335
+ ]);
336
+ const DISMISSAL_OPENER = /^(?:ok|okay|alright|all right|great|cool|perfect|fine|no|nope)\s+/;
337
+ const DISMISSAL_CLOSER = /\s+(?:thanks|thank you|bye|for now|jev|lucid)$/;
338
+ /** Whether what was said means "I'm finished with Act" rather than an instruction. */
339
+ export function isDismissal(text) {
340
+ const said = fold(text);
341
+ if (DISMISSALS.has(said))
342
+ return true;
343
+ const core = said.replace(DISMISSAL_OPENER, '').replace(DISMISSAL_CLOSER, '').replace(DISMISSAL_CLOSER, '').trim();
344
+ return DISMISSALS.has(core);
345
+ }
346
+ const THIS = '(?:this task|this one|the task|it|this|that)';
347
+ const CLEAR_DUE = new RegExp(`^(?:remove|clear|delete|drop|take off|get rid of)(?: ${THIS}s?)? (?:the |its )?(?:due date|deadline|date)$`);
348
+ const DELETE_THIS = new RegExp(`^(?:delete|remove|trash|bin|get rid of) ${THIS}$`);
349
+ // "Close the task" said over an open sheet means the sheet: it completed a task on 2026-09-26.
350
+ const CLOSE_THIS = new RegExp(`^(?:close|dismiss|hide|shut) (?:${THIS}|the sheet|this sheet|the details)$`);
351
+ const COMPLETE_THIS = new RegExp(`^(?:(?:complete|finish|tick off) ${THIS}|tick ${THIS} off|(?:mark|set) ${THIS} (?:as )?(?:done|complete|completed|finished)|(?:its|this is|thats) done)$`);
352
+ const REOPEN_THIS = new RegExp(`^(?:reopen(?: ${THIS})?|(?:mark|set) ${THIS} (?:as )?(?:not done|incomplete|open|undone))$`);
353
+ const START_THIS = new RegExp(`^(?:(?:start|begin)(?: working on)? ${THIS}|(?:mark|set) ${THIS} (?:as )?(?:in progress|started))$`);
354
+ const BLOCKED_THIS = new RegExp(`^(?:(?:mark|set|flag) ${THIS} (?:as )?blocked|block ${THIS}|(?:${THIS} is|its) blocked)$`);
355
+ const DEFERRED_THIS = new RegExp(`^(?:defer ${THIS}|(?:mark|set) ${THIS} (?:as )?deferred|put ${THIS} on hold|(?:${THIS} is|its) (?:deferred|on hold))$`);
356
+ const PENDING_THIS = new RegExp(`^(?:unblock ${THIS}|(?:mark|set) ${THIS} (?:as )?(?:pending|not started|to do|todo)|(?:stop working on|pause) ${THIS}|take ${THIS} off hold)$`);
357
+ const FREQUENCY = '(daily|weekly|monthly|yearly|annually|(?:every|each) (?:day|week|month|year))';
358
+ const REPEAT_THIS = [
359
+ new RegExp(`^(?:(?:make|set|have) ${THIS} (?:to )?|${THIS} )?(?:repeat|recur|repeats|recurs|repeating|recurring)(?: ${THIS})? ${FREQUENCY}$`),
360
+ new RegExp(`^(?:make|set) ${THIS} (?:to )?(?:a )?(?:recurring |repeating )?${FREQUENCY}(?: task| thing)?$`),
361
+ new RegExp(`^set (?:the )?(?:repeat|recurrence) to ${FREQUENCY}$`),
362
+ ];
363
+ const STOP_REPEAT = new RegExp(`^(?:(?:stop|dont|do not) (?:make ${THIS} )?(?:repeat|recur)(?:ing)?(?: ${THIS})?|(?:remove|clear|turn off|cancel) (?:the )?(?:repeat|recurrence|recurring)|(?:make|set) ${THIS} (?:not repeat|non recurring|a one off(?: task)?|one off)|no repeat|set (?:the )?repeat to never)$`);
364
+ function frequencyOf(words) {
365
+ if (/day|daily/.test(words))
366
+ return 'daily';
367
+ if (/week/.test(words))
368
+ return 'weekly';
369
+ if (/month/.test(words))
370
+ return 'monthly';
371
+ return 'yearly';
372
+ }
373
+ /** "remind me to ..." is a new task, so a reminder needs anything but "to" after it. */
374
+ const REMIND_THIS = new RegExp(`^(?:remind me(?: about ${THIS})?|(?:set|add|put|create)(?: a| an)? reminder(?: (?:on|for) ${THIS})?|(?:change|move|update|set) (?:the |my )?reminder(?: (?:on|for) ${THIS})?(?: to)?)(?: (?!to )(.+))?$`);
375
+ const CLEAR_REMINDER = new RegExp(`^(?:(?:remove|clear|delete|cancel|turn off) (?:the |my |its )?reminder(?: (?:on|for|from) ${THIS})?|(?:dont|do not) remind me(?: about ${THIS})?|no reminder)$`);
376
+ const MILESTONE_THIS = [
377
+ new RegExp(`^(?:move|add|put|file|assign|attach)(?: ${THIS})? (?:to|into|in|under|on) (?:the |my )?(?:milestone (.+)|(.+) milestone)$`),
378
+ new RegExp(`^(?:set|change) (?:the |its )?milestone(?: of ${THIS})? to (?:the )?(.+?)(?: milestone)?$`),
379
+ ];
380
+ const CLEAR_MILESTONE = new RegExp(`^(?:(?:remove|take) ${THIS} (?:out of|from|off) (?:the |its )?milestone|(?:remove|clear) (?:the |its )?milestone|no milestone)$`);
381
+ const ON_SCREEN_TASK = '(?:the |this )?(first|second|third|fourth|fifth|last) (?:task|one)';
382
+ const READ_FIELD = new RegExp(`^(?:read|tell me|what is|whats|what are|show me|say)(?: out)?(?: me)?(?: the| its)? (description|details|comments?)(?: (?:of|on|for|in) (?:${THIS}|${ON_SCREEN_TASK}))?(?: out)?$`);
383
+ const READ_TASK = new RegExp(`^(?:read(?: out)?(?: me)? (?:${THIS}|${ON_SCREEN_TASK})(?: out| to me)?|what does ${THIS} say|whats (?:in |on )?${THIS})$`);
384
+ /**
385
+ * The one item in `list` called `words` as people say names: without "the" or emoji, in either
386
+ * number. Null when none is, or when two are.
387
+ */
388
+ export function namedTarget(list, words) {
389
+ const said = key(fold(words));
390
+ const forms = new Set([said, otherNumber(said)]);
391
+ const found = list.filter((t) => forms.has(key(fold(t.name))));
392
+ return found.length === 1 ? found[0] : null;
393
+ }
394
+ /**
395
+ * Priority by name, on the task sheet's slider: 100 to 1000 in steps of 100, lower first. Nothing
396
+ * else in the app names these levels; the numbers are where each word lands on that slider.
397
+ */
398
+ const PRIORITY_LEVELS = {
399
+ urgent: 100, critical: 100, highest: 100, top: 100, 'very high': 100,
400
+ high: 200, important: 200,
401
+ medium: 500, normal: 500, default: 500, average: 500,
402
+ low: 800,
403
+ lowest: 1000, 'very low': 1000,
404
+ };
405
+ const LEVEL_WORDS = Object.keys(PRIORITY_LEVELS).sort((a, b) => b.length - a.length).join('|');
406
+ const LEVEL_NUMBER = '\\d{1,4}|one|two|three|four|five|six|seven|eight|nine|ten';
407
+ const PRIORITY_THIS = [
408
+ // A number needs the word "priority" next to it: "make it 5" could be a time.
409
+ new RegExp(`^(?:set|change|make|update|put|give ${THIS})(?: the| its| a)? priority(?: of ${THIS})?(?: to| at| as| of)? (${LEVEL_WORDS}|${LEVEL_NUMBER})$`),
410
+ new RegExp(`^(?:make|mark|set|flag|put|give) ${THIS} (?:to |as |at )?(?:a |an )?(?:(${LEVEL_WORDS})(?: priority)?|(${LEVEL_NUMBER}) priority|priority (${LEVEL_WORDS}|${LEVEL_NUMBER}))$`),
411
+ new RegExp(`^(?:${THIS} is|its) (?:a |an )?(?:(${LEVEL_WORDS})(?: priority)?|(${LEVEL_NUMBER}) priority)$`),
412
+ new RegExp(`^(?:a |an )?(?:(${LEVEL_WORDS}|${LEVEL_NUMBER}) priority|priority (${LEVEL_WORDS}|${LEVEL_NUMBER}))$`),
413
+ ];
414
+ /** 1 to 10 are steps of the slider ("priority 3" is 300); larger numbers are the value itself. */
415
+ function priorityOf(said) {
416
+ const level = PRIORITY_LEVELS[said];
417
+ if (level)
418
+ return level;
419
+ const n = ORDINAL_WORDS[said] ?? parseInt(said, 10);
420
+ if (!Number.isFinite(n) || n < 1)
421
+ return null;
422
+ const value = n <= 10 ? n * 100 : n;
423
+ return value <= 1000 ? value : null;
424
+ }
425
+ const MOVE_THIS = new RegExp(`^(?:move|add|put|file|send|shift)(?: ${THIS})? (?:to|into|in|under) (?:the |my )?(?:projects? )?(.+)$`);
426
+ const DUE_THIS = new RegExp(`^(?:(?:add|set|put|give ${THIS}|change|update|make)(?: a| the| its)? (?:due date|deadline|due|date)|(?:make|set) ${THIS} due|(?:its|this is|make it|it is) due|due|reschedule(?: ${THIS})?|postpone(?: ${THIS})?|(?:move|push|shift) ${THIS}(?: back)?)(?: (?:to|for|as|on|by|till|until|at))?(?: (.+))?$`);
427
+ /**
428
+ * Where the words of a comment or subtask begin, read from what was said rather than folded, so
429
+ * they keep their capitals and punctuation: "saying", "that", a colon, or nothing at all.
430
+ */
431
+ const ON_THIS = String.raw `(?:\s+(?:on|to|for|under|in)\s+${THIS})?`;
432
+ // A bare space before the words, unless what follows names another task ("add a comment to car
433
+ // wash saying ..."): that one is Jev's to find, not the open task's.
434
+ const SAYING = String.raw `(?:\s*[:,\-–]\s*|\s+(?:saying|that says|which says|says|reading|that reads|that)\b[\s:,]*|\s+(?!(?:to|on|for|in|under|about|of)\s)|$)`;
435
+ const COMMENT = new RegExp(String.raw `^(?:(?:add|leave|post|write|put|make|drop)\s+(?:a\s+|an\s+)?(?:new\s+|quick\s+)?comment|comment)${ON_THIS}${SAYING}(.*)$`, 'i');
436
+ const DESCRIPTION = String.raw `(?:the\s+|its\s+)?(?:description|details)`;
437
+ const DESCRIBE_APPEND = new RegExp(String.raw `^(?:add|append|put|write)\s+(?:this\s+)?(?:to|onto|in|into)\s+${DESCRIPTION}${ON_THIS}${SAYING}(.*)$`, 'i');
438
+ const DESCRIBE_APPEND_AFTER = new RegExp(String.raw `^(?:add|append)\s+(.+?)\s+to\s+${DESCRIPTION}$`, 'i');
439
+ const DESCRIBE_ADD = new RegExp(String.raw `^(?:(?:add|write|put|give\s+it)\s+(?:a\s+|an\s+|the\s+|some\s+)?(?:new\s+)?(?:description|details)|description)${ON_THIS}${SAYING}(.*)$`, 'i');
440
+ const DESCRIBE_SET = new RegExp(String.raw `^(?:set|change|update|replace|edit|rewrite)\s+${DESCRIPTION}(?:\s+(?:of|on|for)\s+${THIS})?(?:\s+(?:to|as|with))?${SAYING}(.*)$`, 'i');
441
+ const CLEAR_DESCRIPTION = new RegExp(String.raw `^(?:remove|clear|delete|erase|wipe)\s+${DESCRIPTION}(?:\s+(?:of|on|from)\s+${THIS})?$`, 'i');
442
+ const RENAME = new RegExp(String.raw `^(?:rename(?:\s+${THIS})?(?:\s+(?:to|as))?|(?:change|update|set|edit|fix)\s+(?:the\s+|its\s+)?(?:title|name)(?:\s+(?:of\s+)?${THIS})?(?:\s+(?:to|as))?|(?:call|retitle|title)\s+(?:this\s+task|this|it)(?:\s+(?:to|as))?)${SAYING}(.*)$`, 'i');
443
+ const RENAME_OWN = new RegExp(String.raw `^rename\s+(?:${THIS}\b|to\b|as\b)`, 'i');
444
+ const SUBTASK = new RegExp(String.raw `^(?:(?:add|create|make|new|put)\s+)?(?:a\s+|an\s+|some\s+)?(?:new\s+)?sub[\s-]?task(s)?${ON_THIS}(?:\s*[:,\-–]\s*|\s+(?:called|named|saying|titled|to)\b[\s:,]*|\s+|$)(.*)$`, 'i');
445
+ /** Said words as a title or a comment: trimmed, with a capital first letter. */
446
+ function spoken(words) {
447
+ const t = words.replace(/^[\s,;:\-–]+|[\s,;:\-–]+$/g, '');
448
+ return t ? t[0].toUpperCase() + t.slice(1) : '';
449
+ }
450
+ /**
451
+ * What an instruction changes about the task that's open, when it doesn't name another one. Null
452
+ * when it isn't one of these, or names a project that doesn't exist; that goes to Jev as before.
453
+ * Dates come back as words for the caller to read (`due` with empty words: "add a due date").
454
+ */
455
+ export function taskEdit(text, projects, milestones = []) {
456
+ const raw = normalizeInstruction(text);
457
+ const comment = COMMENT.exec(raw);
458
+ if (comment)
459
+ return { kind: 'comment', text: spoken(comment[1] ?? '') };
460
+ const subtask = SUBTASK.exec(raw);
461
+ if (subtask) {
462
+ // "add subtasks pack, book flights and call the hotel" is three; a single subtask keeps its "and".
463
+ const words = subtask[2] ?? '';
464
+ // "add a subtask to car wash: buy soap" names the parent; "to call the bank" is the subtask.
465
+ if (/sub[\s-]?tasks?\s+to\s/i.test(raw) && /:|\bsaying\b/i.test(words))
466
+ return null;
467
+ const titles = (subtask[1] ? words.split(/\s*,\s*(?:and\s+)?|\s+and\s+/i) : [words]).map(spoken).filter(Boolean);
468
+ return { kind: 'subtasks', titles: titles.slice(0, 10) };
469
+ }
470
+ if (CLEAR_DESCRIPTION.test(raw))
471
+ return { kind: 'clearDescription' };
472
+ const append = DESCRIBE_APPEND.exec(raw) ?? DESCRIBE_APPEND_AFTER.exec(raw);
473
+ if (append)
474
+ return { kind: 'describe', text: spoken(append[1] ?? ''), mode: 'append' };
475
+ const set = DESCRIBE_SET.exec(raw);
476
+ if (set)
477
+ return { kind: 'describe', text: spoken(set[1] ?? ''), mode: 'set' };
478
+ const add = DESCRIBE_ADD.exec(raw);
479
+ if (add)
480
+ return { kind: 'describe', text: spoken(add[1] ?? ''), mode: 'add' };
481
+ const rename = RENAME.exec(raw);
482
+ if (rename) {
483
+ // "rename car wash to wash the car" names the task being renamed: Jev's to find.
484
+ const another = /^rename\s/i.test(raw) && !RENAME_OWN.test(raw) && /\s(?:to|as)\s/i.test(rename[1] ?? '');
485
+ return another ? null : { kind: 'rename', title: spoken(rename[1] ?? '') };
486
+ }
487
+ const said = fold(raw).replace(TRAILING, '').trim();
488
+ if (CLEAR_DUE.test(said))
489
+ return { kind: 'clearDue' };
490
+ if (DELETE_THIS.test(said))
491
+ return { kind: 'delete' };
492
+ if (CLOSE_THIS.test(said))
493
+ return { kind: 'close' };
494
+ if (COMPLETE_THIS.test(said))
495
+ return { kind: 'status', status: 'complete' };
496
+ if (REOPEN_THIS.test(said))
497
+ return { kind: 'status', status: 'reopen' };
498
+ if (START_THIS.test(said))
499
+ return { kind: 'status', status: 'start' };
500
+ if (BLOCKED_THIS.test(said))
501
+ return { kind: 'status', status: 'blocked' };
502
+ if (DEFERRED_THIS.test(said))
503
+ return { kind: 'status', status: 'deferred' };
504
+ if (PENDING_THIS.test(said))
505
+ return { kind: 'status', status: 'pending' };
506
+ for (const form of PRIORITY_THIS) {
507
+ const m = form.exec(said);
508
+ const words = m?.slice(1).find(Boolean);
509
+ const priority = words ? priorityOf(words) : null;
510
+ if (priority)
511
+ return { kind: 'priority', priority };
512
+ }
513
+ if (STOP_REPEAT.test(said))
514
+ return { kind: 'repeat', frequency: null };
515
+ for (const form of REPEAT_THIS) {
516
+ const m = form.exec(said);
517
+ if (m)
518
+ return { kind: 'repeat', frequency: frequencyOf(m[1]) };
519
+ }
520
+ if (CLEAR_REMINDER.test(said))
521
+ return { kind: 'clearReminder' };
522
+ const remind = REMIND_THIS.exec(said);
523
+ if (remind)
524
+ return { kind: 'remind', words: (remind[1] ?? '').trim() };
525
+ const readField = READ_FIELD.exec(said);
526
+ const readTask = readField ? null : READ_TASK.exec(said);
527
+ if (readField || readTask) {
528
+ const what = readField ? (readField[1].startsWith('comment') ? 'comments' : 'description') : 'all';
529
+ const which = readField ? readField[2] : readTask[1];
530
+ const position = which === 'last' ? 'last' : which ? ORDINAL_WORDS[which] : undefined;
531
+ return { kind: 'read', what, ...(position ? { position } : {}) };
532
+ }
533
+ if (CLEAR_MILESTONE.test(said))
534
+ return { kind: 'milestone', name: null };
535
+ for (const form of MILESTONE_THIS) {
536
+ const m = form.exec(said);
537
+ const name = m?.slice(1).find(Boolean);
538
+ if (name)
539
+ return { kind: 'milestone', name };
540
+ }
541
+ // "move it to Lucidity" is a project, "move it to tomorrow" a date: a project name decides.
542
+ const move = MOVE_THIS.exec(said);
543
+ if (move) {
544
+ // The whole name first ("Shopping List"), then without a trailing "project" or "list".
545
+ const whole = key(move[1]);
546
+ const bare = whole.replace(/ (?:project|list)$/, '');
547
+ if (bare === 'inbox')
548
+ return { kind: 'move', projectId: null, projectName: null };
549
+ const forms = [whole, otherNumber(whole), bare, otherNumber(bare)];
550
+ const found = forms.flatMap((form) => projects.filter((p) => key(fold(p.name)) === form));
551
+ const unique = [...new Map(found.map((p) => [p.id, p])).values()];
552
+ if (unique.length === 1)
553
+ return { kind: 'move', projectId: unique[0].id, projectName: unique[0].name };
554
+ // Not a project, but a milestone: "move it to Q3 launch".
555
+ if (!unique.length && namedTarget(milestones, move[1]))
556
+ return { kind: 'milestone', name: move[1] };
557
+ // "the moon project" is a project that doesn't exist, not a date.
558
+ if (unique.length > 1 || bare !== whole)
559
+ return null;
560
+ }
561
+ const due = DUE_THIS.exec(said);
562
+ if (due)
563
+ return { kind: 'due', words: (due[1] ?? '').trim() };
564
+ return null;
565
+ }
566
+ // Groups: 1 "this"/"a" before "project", 2 a name after it, 3 a name before it.
567
+ const PROJECT_REF = String.raw `(?:(?:the|my)\s+)?(?:(this|that|a|the|my)\s+project|project\s+(.+?)|(.+?)\s+project)`;
568
+ const DELETE_PROJECT = new RegExp(String.raw `^(?:delete|remove|trash|get rid of)\s+${PROJECT_REF}$`, 'i');
569
+ const ARCHIVE_PROJECT = new RegExp(String.raw `^archive\s+(?:${PROJECT_REF}|(?:(?:the|my)\s+)?(.+))$`, 'i');
570
+ const RENAME_PROJECT = new RegExp(String.raw `^rename\s+${PROJECT_REF}\s+(?:to|as)\s+(.+)$`, 'i');
571
+ export function projectEdit(text, projects, here = null) {
572
+ const raw = normalizeInstruction(text);
573
+ const which = (named, pronoun) => {
574
+ // "archive it" on a project's screen: the same as "this project".
575
+ if (named && /^(?:it|this|that)$/i.test(named.trim()))
576
+ return which(undefined, 'this');
577
+ if (named)
578
+ return { project: namedTarget(projects, named), name: named.trim() };
579
+ // "this project" is the one on screen; "a project" names none.
580
+ if (pronoun && /^(?:this|that)$/i.test(pronoun) && here)
581
+ return { project: here, name: here.name };
582
+ return { project: null, name: '' };
583
+ };
584
+ const rename = RENAME_PROJECT.exec(raw);
585
+ if (rename)
586
+ return { kind: 'renameProject', ...which(rename[2] ?? rename[3], rename[1]), to: spoken(rename[4]) };
587
+ const del = DELETE_PROJECT.exec(raw);
588
+ if (del)
589
+ return { kind: 'deleteProject', ...which(del[2] ?? del[3], del[1]) };
590
+ const archive = ARCHIVE_PROJECT.exec(raw);
591
+ if (archive)
592
+ return { kind: 'archiveProject', ...which(archive[2] ?? archive[3] ?? archive[4], archive[1]) };
593
+ return null;
594
+ }
595
+ const YES = new Set(['yes', 'yeah', 'yep', 'yup', 'sure', 'ok', 'okay', 'confirm', 'do it', 'go ahead', 'yes please', 'please do']);
596
+ /**
597
+ * Which offered choice a spoken answer picks, besides by position: "yes" takes the first, and a
598
+ * word that starts exactly one choice's label ("archive", "delete it") takes that one.
599
+ */
600
+ export function choiceBySaying(labels, text) {
601
+ const said = fold(normalizeInstruction(text)).replace(TRAILING, '').trim();
602
+ if (YES.has(said))
603
+ return labels.length ? 0 : null;
604
+ const verb = said.split(' ')[0];
605
+ if (!verb || said.split(' ').length > 3)
606
+ return null;
607
+ const hits = labels.map((l, i) => (fold(l).split(' ')[0] === verb ? i : -1)).filter((i) => i >= 0);
608
+ return hits.length === 1 ? hits[0] : null;
609
+ }
610
+ /** The next words, read as the answer to `question` rather than as an instruction. */
611
+ export function answerTo(question, text) {
612
+ const words = normalizeInstruction(text);
613
+ switch (question) {
614
+ case 'due': return { kind: 'due', words };
615
+ case 'comment': return { kind: 'comment', text: spoken(words) };
616
+ case 'subtask': return { kind: 'subtasks', titles: [spoken(words)] };
617
+ case 'title': return { kind: 'rename', title: spoken(words) };
618
+ case 'description': return { kind: 'describe', text: spoken(words), mode: 'add' };
619
+ case 'newDescription': return { kind: 'describe', text: spoken(words), mode: 'set' };
620
+ case 'reminder': return { kind: 'remind', words };
621
+ }
622
+ }
623
+ /**
624
+ * Edits Jev can't carry out, so only the phone can, and only to a task it knows. With no task
625
+ * open they must not go to Jev, which reads "add a comment ..." as a new task called "Comment ...".
626
+ */
627
+ export function phoneOnlyEdit(edit) {
628
+ if (edit.kind === 'status')
629
+ return ['blocked', 'deferred', 'pending'].includes(edit.status);
630
+ return !['due', 'clearDue', 'move', 'delete'].includes(edit.kind);
631
+ }
632
+ /** A priority named anywhere in an instruction ("mark car wash as high priority"), for Jev's steps. */
633
+ export function priorityIn(text) {
634
+ const said = fold(normalizeInstruction(text));
635
+ const m = new RegExp(`(?:^| )(?:priority (?:of |to |at |as )?(${LEVEL_WORDS}|${LEVEL_NUMBER})|(${LEVEL_WORDS}|${LEVEL_NUMBER}) priority|(urgent|critical|important))(?: |$)`).exec(said);
636
+ const words = m?.slice(1).find(Boolean);
637
+ return words ? priorityOf(words) : null;
638
+ }
639
+ /**
640
+ * How often an instruction says a task repeats, from anywhere in it: null when it says to stop,
641
+ * undefined when it says neither.
642
+ */
643
+ export function frequencyIn(text) {
644
+ const said = fold(normalizeInstruction(text));
645
+ if (/\b(?:stop|dont|do not|no longer|never|not)\b.*\b(?:repeat|recur)|\b(?:remove|clear|cancel|turn off)\b.*\b(?:repeat|recurrence)/.test(said))
646
+ return null;
647
+ const m = new RegExp(`(?:^| )${FREQUENCY}(?: |$)`).exec(said);
648
+ return m ? frequencyOf(m[1]) : undefined;
649
+ }
650
+ /**
651
+ * Words that start an edit of an existing task ("add a comment ...", "add subtasks ..."), which
652
+ * must never become a new task whoever read them.
653
+ */
654
+ export function isTaskEditPhrase(text) {
655
+ const said = normalizeInstruction(text).replace(ADD_OPENER, '');
656
+ return /^(?:(?:add|leave|post|write|put|create|make|new)\s+(?:a\s+|an\s+|some\s+)?(?:new\s+)?(?:comment|sub[\s-]?tasks?|description|details)|comment)\b/i.test(said);
657
+ }
658
+ /** How a priority reads in a reply: "high priority", or "priority 300" between the named levels. */
659
+ export function priorityLabel(priority) {
660
+ const names = { 100: 'top priority', 200: 'high priority', 500: 'normal priority', 800: 'low priority', 1000: 'lowest priority' };
661
+ return names[priority] ?? `priority ${priority}`;
662
+ }