@agentprojectcontext/apx 1.77.3 → 1.79.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 (356) hide show
  1. package/README.md +23 -9
  2. package/package.json +12 -12
  3. package/src/core/agent/build-agent-system.js +3 -2
  4. package/src/core/agent/constants.js +3 -2
  5. package/src/core/agent/loop/greeting-guard.js +55 -0
  6. package/src/core/agent/loop/side-effects.js +52 -0
  7. package/src/core/agent/prompt-builder.js +49 -8
  8. package/src/core/agent/run-agent.js +43 -53
  9. package/src/core/agent/security.js +1 -1
  10. package/src/core/agent/self-memory.js +4 -2
  11. package/src/core/agent/skills/index-store.js +2 -2
  12. package/src/core/agent/skills/loader.js +3 -22
  13. package/src/core/agent/super-agent.js +0 -2
  14. package/src/core/agent/tool-summary.js +65 -0
  15. package/src/core/agent/tools/handlers/call-runtime.js +4 -4
  16. package/src/core/agent/tools/handlers/list-commitments.js +80 -0
  17. package/src/core/agent/tools/handlers/list-tasks.js +66 -27
  18. package/src/core/agent/tools/handlers/record-commitment.js +68 -0
  19. package/src/core/agent/tools/handlers/search-sessions.js +1 -1
  20. package/src/core/agent/tools/handlers/send-telegram.js +68 -2
  21. package/src/core/agent/tools/handlers/set-permission-mode.js +11 -4
  22. package/src/core/agent/tools/names.js +64 -0
  23. package/src/core/agent/tools/registry.js +9 -0
  24. package/src/core/agent/tools/tool-call-parser.js +70 -1
  25. package/src/core/apc/context-copy.js +1 -1
  26. package/src/core/apc/frontmatter.js +85 -0
  27. package/src/core/apc/parser.js +9 -21
  28. package/src/core/apc/paths.js +8 -8
  29. package/src/core/apc/scaffold.js +5 -4
  30. package/src/core/channels/telegram/ask-callbacks.js +35 -0
  31. package/src/core/channels/telegram/config.js +201 -0
  32. package/src/core/channels/telegram/dispatch.js +3 -0
  33. package/src/core/channels/telegram/reply.js +30 -5
  34. package/src/core/config/index.js +25 -183
  35. package/src/core/config/paths.js +57 -1
  36. package/src/core/config/redact.js +22 -0
  37. package/src/core/confirmation/adapters/web.js +1 -1
  38. package/src/core/daemon/service.js +238 -0
  39. package/src/core/deck/manifest.js +12 -12
  40. package/src/core/desktop/autostart.js +3 -2
  41. package/src/core/desktop/process.js +4 -4
  42. package/src/core/engines/gemini.js +322 -60
  43. package/src/core/engines/openai-compatible.js +21 -2
  44. package/src/core/engines/presets.js +2 -2
  45. package/src/core/http-tools/browser.js +1 -1
  46. package/src/core/http-tools/catalog.js +551 -0
  47. package/src/core/http-tools/fetch.js +1 -1
  48. package/src/core/http-tools/glob.js +3 -3
  49. package/src/core/http-tools/grep.js +2 -9
  50. package/src/core/http-tools/inline-handlers.js +59 -0
  51. package/src/core/http-tools/registry.js +31 -615
  52. package/src/core/http-tools/search.js +2 -2
  53. package/src/core/identity/self.js +6 -7
  54. package/src/core/identity/telegram.js +3 -3
  55. package/src/core/logging.js +6 -5
  56. package/src/core/mcp/sources.js +12 -16
  57. package/src/core/memory/consolidate.js +225 -0
  58. package/src/core/memory/indexer.js +2 -5
  59. package/src/core/nudge/index.js +192 -0
  60. package/src/core/nudge/policy.js +143 -0
  61. package/src/core/nudge/store.js +141 -0
  62. package/src/core/profiles/bundled/secretary/PROFILE.md +8 -9
  63. package/src/core/profiles/bundled/secretary/config.schema.json +33 -3
  64. package/src/core/profiles/bundled/secretary/routines/day-close.json +7 -3
  65. package/src/core/profiles/bundled/secretary/routines/day-open.json +7 -3
  66. package/src/core/profiles/bundled/secretary/routines/watch.json +13 -0
  67. package/src/core/profiles/lifecycle.js +0 -2
  68. package/src/core/profiles/store.js +2 -7
  69. package/src/core/routines/runner.js +103 -4
  70. package/src/core/routines/signals.js +270 -0
  71. package/src/core/runtime-skills/apx-agency-agents/SKILL.md +2 -2
  72. package/src/core/runtime-skills/apx-profile/SKILL.md +3 -3
  73. package/src/core/runtime-skills/apx-project/SKILL.md +1 -1
  74. package/src/core/runtime-skills/apx-task/SKILL.md +8 -8
  75. package/src/core/runtime-skills/apx-telegram/SKILL.md +4 -4
  76. package/src/core/runtime-skills/apx-voice/SKILL.md +4 -4
  77. package/src/core/runtimes/detect.js +2 -2
  78. package/src/core/sessions/index.js +800 -0
  79. package/src/core/stores/code-sessions.js +3 -14
  80. package/src/core/stores/commitments.js +331 -0
  81. package/src/core/stores/engine-sessions.js +0 -4
  82. package/src/core/stores/messages.js +4 -5
  83. package/src/core/stores/organization.js +9 -11
  84. package/src/core/stores/routines.js +23 -14
  85. package/src/core/stores/runtime-callbacks.js +2 -1
  86. package/src/core/util/json-file.js +128 -0
  87. package/src/core/util/thinking.js +51 -0
  88. package/src/core/vars/sources.js +14 -21
  89. package/src/core/voice/stt-models.js +1 -1
  90. package/src/core/voice/tts.js +5 -4
  91. package/src/host/daemon/api/admin-config.js +5 -5
  92. package/src/host/daemon/api/admin.js +8 -7
  93. package/src/host/daemon/api/agents.js +16 -16
  94. package/src/host/daemon/api/artifact-preview.js +8 -8
  95. package/src/host/daemon/api/artifacts.js +7 -7
  96. package/src/host/daemon/api/code.js +8 -8
  97. package/src/host/daemon/api/commitments.js +135 -0
  98. package/src/host/daemon/api/config.js +6 -6
  99. package/src/host/daemon/api/confirm.js +2 -2
  100. package/src/host/daemon/api/connections.js +2 -2
  101. package/src/host/daemon/api/conversations.js +12 -12
  102. package/src/host/daemon/api/deck.js +6 -6
  103. package/src/host/daemon/api/desktop.js +8 -8
  104. package/src/host/daemon/api/embeddings.js +4 -4
  105. package/src/host/daemon/api/engines.js +8 -7
  106. package/src/host/daemon/api/exec.js +5 -4
  107. package/src/host/daemon/api/files-project.js +6 -6
  108. package/src/host/daemon/api/health.js +2 -2
  109. package/src/host/daemon/api/identity.js +3 -3
  110. package/src/host/daemon/api/inbox.js +2 -2
  111. package/src/host/daemon/api/integrations.js +23 -19
  112. package/src/host/daemon/api/mcps.js +16 -12
  113. package/src/host/daemon/api/messages.js +5 -5
  114. package/src/host/daemon/api/nudges.js +112 -0
  115. package/src/host/daemon/api/organization.js +8 -8
  116. package/src/host/daemon/api/pairing.js +6 -6
  117. package/src/host/daemon/api/plugins.js +3 -3
  118. package/src/host/daemon/api/prefix.js +20 -0
  119. package/src/host/daemon/api/profiles.js +9 -9
  120. package/src/host/daemon/api/projects.js +5 -5
  121. package/src/host/daemon/api/routines.js +32 -8
  122. package/src/host/daemon/api/run.js +2 -2
  123. package/src/host/daemon/api/runtimes.js +6 -6
  124. package/src/host/daemon/api/self-memory.js +50 -0
  125. package/src/host/daemon/api/sessions-search.js +18 -11
  126. package/src/host/daemon/api/sessions.js +6 -6
  127. package/src/host/daemon/api/shared.js +59 -13
  128. package/src/host/daemon/api/skills.js +12 -12
  129. package/src/host/daemon/api/super-agent.js +4 -4
  130. package/src/host/daemon/api/tasks.js +11 -11
  131. package/src/host/daemon/api/telegram.js +61 -24
  132. package/src/host/daemon/api/tools.js +7 -7
  133. package/src/host/daemon/api/top-level.js +7 -7
  134. package/src/host/daemon/api/transcribe.js +6 -6
  135. package/src/host/daemon/api/tts.js +3 -3
  136. package/src/host/daemon/api/vars.js +11 -8
  137. package/src/host/daemon/api/voice.js +9 -7
  138. package/src/host/daemon/api/web.js +28 -32
  139. package/src/host/daemon/api.js +83 -48
  140. package/src/host/daemon/callback-reconciler.js +16 -0
  141. package/src/host/daemon/db.js +1 -1
  142. package/src/host/daemon/desktop-ws.js +7 -3
  143. package/src/host/daemon/index.js +11 -5
  144. package/src/host/daemon/plugins/desktop/index.js +8 -2
  145. package/src/host/daemon/plugins/telegram/index.js +7 -2
  146. package/src/host/daemon/stt-venv.js +20 -81
  147. package/src/host/daemon/wakeup.js +18 -4
  148. package/src/interfaces/acp/index.js +3 -3
  149. package/src/interfaces/acp/session.js +2 -2
  150. package/src/interfaces/cli/commands/a2a.js +2 -2
  151. package/src/interfaces/cli/commands/agent.js +3 -3
  152. package/src/interfaces/cli/commands/artifact.js +13 -13
  153. package/src/interfaces/cli/commands/chat.js +3 -3
  154. package/src/interfaces/cli/commands/command.js +2 -2
  155. package/src/interfaces/cli/commands/commitment.js +154 -0
  156. package/src/interfaces/cli/commands/config.js +4 -4
  157. package/src/interfaces/cli/commands/daemon.js +74 -18
  158. package/src/interfaces/cli/commands/desktop.js +7 -14
  159. package/src/interfaces/cli/commands/exec.js +2 -2
  160. package/src/interfaces/cli/commands/log.js +3 -4
  161. package/src/interfaces/cli/commands/mcp.js +9 -9
  162. package/src/interfaces/cli/commands/memory.js +75 -2
  163. package/src/interfaces/cli/commands/messages.js +5 -5
  164. package/src/interfaces/cli/commands/model.js +0 -18
  165. package/src/interfaces/cli/commands/nudge.js +130 -0
  166. package/src/interfaces/cli/commands/obsidian.js +5 -5
  167. package/src/interfaces/cli/commands/org.js +5 -5
  168. package/src/interfaces/cli/commands/pair.js +6 -6
  169. package/src/interfaces/cli/commands/plugins.js +2 -2
  170. package/src/interfaces/cli/commands/profile.js +10 -10
  171. package/src/interfaces/cli/commands/project-config.js +6 -6
  172. package/src/interfaces/cli/commands/project.js +10 -10
  173. package/src/interfaces/cli/commands/routine.js +8 -9
  174. package/src/interfaces/cli/commands/runtime.js +2 -2
  175. package/src/interfaces/cli/commands/search.js +0 -1
  176. package/src/interfaces/cli/commands/session.js +12 -40
  177. package/src/interfaces/cli/commands/sessions.js +21 -798
  178. package/src/interfaces/cli/commands/setup.js +16 -6
  179. package/src/interfaces/cli/commands/skills.js +1 -2
  180. package/src/interfaces/cli/commands/status.js +3 -3
  181. package/src/interfaces/cli/commands/task.js +8 -8
  182. package/src/interfaces/cli/commands/telegram.js +21 -21
  183. package/src/interfaces/cli/commands/voice.js +6 -6
  184. package/src/interfaces/cli/help/index.js +2245 -0
  185. package/src/interfaces/cli/http.js +9 -4
  186. package/src/interfaces/cli/index.js +14 -2857
  187. package/src/interfaces/cli/routes/acp.js +13 -0
  188. package/src/interfaces/cli/routes/agent.js +27 -0
  189. package/src/interfaces/cli/routes/artifact.js +28 -0
  190. package/src/interfaces/cli/routes/chat.js +11 -0
  191. package/src/interfaces/cli/routes/code.js +11 -0
  192. package/src/interfaces/cli/routes/command.js +21 -0
  193. package/src/interfaces/cli/routes/commitment.js +19 -0
  194. package/src/interfaces/cli/routes/config.js +16 -0
  195. package/src/interfaces/cli/routes/connections.js +11 -0
  196. package/src/interfaces/cli/routes/conversations.js +21 -0
  197. package/src/interfaces/cli/routes/daemon.js +25 -0
  198. package/src/interfaces/cli/routes/desktop.js +20 -0
  199. package/src/interfaces/cli/routes/env.js +13 -0
  200. package/src/interfaces/cli/routes/exec.js +11 -0
  201. package/src/interfaces/cli/routes/identity.js +11 -0
  202. package/src/interfaces/cli/routes/index.js +75 -0
  203. package/src/interfaces/cli/routes/init.js +11 -0
  204. package/src/interfaces/cli/routes/log.js +20 -0
  205. package/src/interfaces/cli/routes/mcp.js +22 -0
  206. package/src/interfaces/cli/routes/memory.js +19 -0
  207. package/src/interfaces/cli/routes/messages.js +16 -0
  208. package/src/interfaces/cli/routes/model.js +11 -0
  209. package/src/interfaces/cli/routes/nudge.js +17 -0
  210. package/src/interfaces/cli/routes/obsidian.js +17 -0
  211. package/src/interfaces/cli/routes/org.js +34 -0
  212. package/src/interfaces/cli/routes/overlay.js +10 -0
  213. package/src/interfaces/cli/routes/pair.js +17 -0
  214. package/src/interfaces/cli/routes/panel.js +16 -0
  215. package/src/interfaces/cli/routes/permission.js +11 -0
  216. package/src/interfaces/cli/routes/plugins.js +21 -0
  217. package/src/interfaces/cli/routes/profile.js +27 -0
  218. package/src/interfaces/cli/routes/project.js +41 -0
  219. package/src/interfaces/cli/routes/restart.js +15 -0
  220. package/src/interfaces/cli/routes/routine.js +28 -0
  221. package/src/interfaces/cli/routes/run.js +11 -0
  222. package/src/interfaces/cli/routes/search.js +11 -0
  223. package/src/interfaces/cli/routes/send.js +11 -0
  224. package/src/interfaces/cli/routes/session.js +26 -0
  225. package/src/interfaces/cli/routes/sessions.js +15 -0
  226. package/src/interfaces/cli/routes/setup.js +18 -0
  227. package/src/interfaces/cli/routes/skills.js +20 -0
  228. package/src/interfaces/cli/routes/status.js +12 -0
  229. package/src/interfaces/cli/routes/task.js +26 -0
  230. package/src/interfaces/cli/routes/telegram.js +39 -0
  231. package/src/interfaces/cli/routes/update.js +24 -0
  232. package/src/interfaces/cli/routes/voice.js +17 -0
  233. package/src/interfaces/desktop/main.js +6 -7
  234. package/src/interfaces/desktop/renderer.js +0 -5
  235. package/src/interfaces/mcp-server/index.js +15 -14
  236. package/src/interfaces/tui/_shims/globals.d.ts +8 -0
  237. package/src/interfaces/tui/tsconfig.json +4 -1
  238. package/src/interfaces/web/README.md +6 -6
  239. package/src/interfaces/web/dist/assets/index-CvEoGtTf.js +849 -0
  240. package/src/interfaces/web/dist/assets/index-CvEoGtTf.js.map +1 -0
  241. package/src/interfaces/web/dist/assets/index-DzBBXFaO.css +1 -0
  242. package/src/interfaces/web/dist/index.html +2 -2
  243. package/src/interfaces/web/package-lock.json +11 -10
  244. package/src/interfaces/web/src/components/AddProjectDialog.tsx +1 -1
  245. package/src/interfaces/web/src/components/Section.tsx +18 -3
  246. package/src/interfaces/web/src/components/agents/AgentFormFields.tsx +1 -1
  247. package/src/interfaces/web/src/components/chat/ChatList.tsx +2 -2
  248. package/src/interfaces/web/src/components/chat/MessageBubble.tsx +13 -0
  249. package/src/interfaces/web/src/components/chat/SkillPicker.tsx +1 -1
  250. package/src/interfaces/web/src/components/code/CodeFileTree.tsx +1 -1
  251. package/src/interfaces/web/src/components/code/CodeTerminal.tsx +1 -1
  252. package/src/interfaces/web/src/components/cron/CronPicker.tsx +196 -0
  253. package/src/interfaces/web/src/components/desktop/DesktopStatusCard.tsx +1 -1
  254. package/src/interfaces/web/src/components/files/FileBrowser.tsx +2 -2
  255. package/src/interfaces/web/src/components/inbox/InboxList.tsx +145 -0
  256. package/src/interfaces/web/src/components/memory/MemoryBrowser.tsx +36 -6
  257. package/src/interfaces/web/src/components/routines/ExecutionsList.tsx +1 -1
  258. package/src/interfaces/web/src/components/routines/RoutineDetail.tsx +16 -4
  259. package/src/interfaces/web/src/components/routines/RoutineEditor.tsx +14 -4
  260. package/src/interfaces/web/src/components/routines/shared.ts +14 -5
  261. package/src/interfaces/web/src/components/settings/DesktopSettingsPanel.tsx +1 -1
  262. package/src/interfaces/web/src/components/settings/MemoryPanel.tsx +1 -1
  263. package/src/interfaces/web/src/components/settings/NudgePanel.tsx +183 -0
  264. package/src/interfaces/web/src/components/settings/ProfilePanel.tsx +36 -12
  265. package/src/interfaces/web/src/components/settings/SkillsInspectorPanel.tsx +1 -1
  266. package/src/interfaces/web/src/components/settings/SkillsManager.tsx +2 -2
  267. package/src/interfaces/web/src/components/tasks/TaskDetailPanel.tsx +1 -1
  268. package/src/interfaces/web/src/components/ui/filter-chips.tsx +47 -0
  269. package/src/interfaces/web/src/components/ui.tsx +1 -0
  270. package/src/interfaces/web/src/constants/index.ts +1 -0
  271. package/src/interfaces/web/src/hooks/useChat.ts +5 -1
  272. package/src/interfaces/web/src/hooks/useDaemonStatus.ts +1 -1
  273. package/src/interfaces/web/src/hooks/useDevices.ts +1 -1
  274. package/src/interfaces/web/src/hooks/useEngines.ts +1 -1
  275. package/src/interfaces/web/src/hooks/useGlobalConfig.ts +2 -2
  276. package/src/interfaces/web/src/hooks/useIdentity.ts +1 -1
  277. package/src/interfaces/web/src/hooks/useInbox.ts +1 -1
  278. package/src/interfaces/web/src/hooks/useNudges.ts +38 -0
  279. package/src/interfaces/web/src/hooks/useProfiles.ts +3 -3
  280. package/src/interfaces/web/src/hooks/useProjects.ts +1 -1
  281. package/src/interfaces/web/src/hooks/useTelegram.ts +3 -3
  282. package/src/interfaces/web/src/hooks/useTokenBootstrap.ts +3 -3
  283. package/src/interfaces/web/src/i18n/en.ts +127 -0
  284. package/src/interfaces/web/src/i18n/es.ts +127 -0
  285. package/src/interfaces/web/src/lib/api/admin.ts +11 -11
  286. package/src/interfaces/web/src/lib/api/agents.ts +14 -14
  287. package/src/interfaces/web/src/lib/api/artifacts.ts +11 -11
  288. package/src/interfaces/web/src/lib/api/code.ts +1 -1
  289. package/src/interfaces/web/src/lib/api/commitments.ts +57 -0
  290. package/src/interfaces/web/src/lib/api/conversations.ts +8 -8
  291. package/src/interfaces/web/src/lib/api/deck.ts +3 -3
  292. package/src/interfaces/web/src/lib/api/desktop.ts +8 -8
  293. package/src/interfaces/web/src/lib/api/embeddings.ts +3 -3
  294. package/src/interfaces/web/src/lib/api/engines.ts +3 -3
  295. package/src/interfaces/web/src/lib/api/filesystem.ts +2 -2
  296. package/src/interfaces/web/src/lib/api/health.ts +1 -1
  297. package/src/interfaces/web/src/lib/api/identity.ts +2 -2
  298. package/src/interfaces/web/src/lib/api/inbox.ts +1 -1
  299. package/src/interfaces/web/src/lib/api/integrations.ts +8 -8
  300. package/src/interfaces/web/src/lib/api/mcps.ts +6 -6
  301. package/src/interfaces/web/src/lib/api/messages.ts +3 -3
  302. package/src/interfaces/web/src/lib/api/notebook.ts +23 -0
  303. package/src/interfaces/web/src/lib/api/nudges.ts +53 -0
  304. package/src/interfaces/web/src/lib/api/organization.ts +7 -7
  305. package/src/interfaces/web/src/lib/api/profiles.ts +8 -8
  306. package/src/interfaces/web/src/lib/api/projectFiles.ts +5 -5
  307. package/src/interfaces/web/src/lib/api/projects.ts +12 -12
  308. package/src/interfaces/web/src/lib/api/routines.ts +7 -7
  309. package/src/interfaces/web/src/lib/api/sessions.ts +2 -2
  310. package/src/interfaces/web/src/lib/api/skills.ts +11 -11
  311. package/src/interfaces/web/src/lib/api/super_agent.ts +3 -3
  312. package/src/interfaces/web/src/lib/api/tasks.ts +12 -12
  313. package/src/interfaces/web/src/lib/api/telegram.ts +14 -14
  314. package/src/interfaces/web/src/lib/api/tools.ts +1 -1
  315. package/src/interfaces/web/src/lib/api/vars.ts +4 -4
  316. package/src/interfaces/web/src/lib/api/voice.ts +6 -6
  317. package/src/interfaces/web/src/lib/cron.ts +196 -0
  318. package/src/interfaces/web/src/lib/when.ts +32 -0
  319. package/src/interfaces/web/src/screens/InboxScreen.tsx +107 -77
  320. package/src/interfaces/web/src/screens/ProjectScreen.tsx +5 -2
  321. package/src/interfaces/web/src/screens/SettingsScreen.tsx +17 -3
  322. package/src/interfaces/web/src/screens/base/AgentDefaultsTab.tsx +1 -1
  323. package/src/interfaces/web/src/screens/base/CommitmentsTab.tsx +239 -0
  324. package/src/interfaces/web/src/screens/base/GlobalTasksTab.tsx +103 -20
  325. package/src/interfaces/web/src/screens/base/LogsTab.tsx +18 -3
  326. package/src/interfaces/web/src/screens/base/SessionsTab.tsx +1 -1
  327. package/src/interfaces/web/src/screens/modules/CodeScreen.tsx +1 -1
  328. package/src/interfaces/web/src/screens/modules/DeckScreen.tsx +1 -1
  329. package/src/interfaces/web/src/screens/modules/DesktopScreen.tsx +1 -1
  330. package/src/interfaces/web/src/screens/modules/VoiceScreen.tsx +1 -1
  331. package/src/interfaces/web/src/screens/project/AgentDetailScreen.tsx +8 -8
  332. package/src/interfaces/web/src/screens/project/AgentsTab.tsx +2 -2
  333. package/src/interfaces/web/src/screens/project/ChatTab.tsx +24 -6
  334. package/src/interfaces/web/src/screens/project/ConfigTab.tsx +1 -1
  335. package/src/interfaces/web/src/screens/project/McpsTab.tsx +3 -3
  336. package/src/interfaces/web/src/screens/project/Overview.tsx +6 -6
  337. package/src/interfaces/web/src/screens/project/RoutinesTab.tsx +15 -13
  338. package/src/interfaces/web/src/screens/project/StructureTab.tsx +1 -1
  339. package/src/interfaces/web/src/screens/project/TasksTab.tsx +1 -1
  340. package/src/interfaces/web/src/screens/project/VarsTab.tsx +1 -1
  341. package/src/interfaces/web/src/types/daemon.ts +10 -1
  342. package/src/interfaces/web/vite.config.ts +13 -18
  343. package/src/interfaces/web/dist/assets/index-BptlbKjU.js +0 -824
  344. package/src/interfaces/web/dist/assets/index-BptlbKjU.js.map +0 -1
  345. package/src/interfaces/web/dist/assets/index-D_EJEA1n.css +0 -1
  346. package/src/skills/apc-context/SKILL.md +0 -159
  347. /package/src/{host/daemon → core}/runtimes/_spawn.js +0 -0
  348. /package/src/{host/daemon → core}/runtimes/aider.js +0 -0
  349. /package/src/{host/daemon → core}/runtimes/antigravity.js +0 -0
  350. /package/src/{host/daemon → core}/runtimes/claude-code.js +0 -0
  351. /package/src/{host/daemon → core}/runtimes/codex.js +0 -0
  352. /package/src/{host/daemon → core}/runtimes/cursor-agent.js +0 -0
  353. /package/src/{host/daemon → core}/runtimes/gemini-cli.js +0 -0
  354. /package/src/{host/daemon → core}/runtimes/index.js +0 -0
  355. /package/src/{host/daemon → core}/runtimes/opencode.js +0 -0
  356. /package/src/{host/daemon → core}/runtimes/qwen-code.js +0 -0
@@ -102,13 +102,13 @@ export const Skills = {
102
102
  qs.set("scope", projectPath);
103
103
  }
104
104
  const q = qs.toString();
105
- return http.get<SkillsList>(q ? `/skills?${q}` : "/skills");
105
+ return http.get<SkillsList>(q ? `/api/skills?${q}` : "/api/skills");
106
106
  },
107
107
 
108
108
  /** Full body + frontmatter of a skill, for the viewer. */
109
109
  detail: (slug: string, projectPath?: string) => {
110
110
  const qs = projectPath ? `?project_path=${encodeURIComponent(projectPath)}` : "";
111
- return http.get<SkillDetail>(`/skills/${encodeURIComponent(slug)}/detail${qs}`);
111
+ return http.get<SkillDetail>(`/api/skills/${encodeURIComponent(slug)}/detail${qs}`);
112
112
  },
113
113
 
114
114
  /**
@@ -118,7 +118,7 @@ export const Skills = {
118
118
  */
119
119
  setEnabled: (body: { slug: string; enabled: boolean | null; scope?: string }) =>
120
120
  http.put<{ ok: boolean; slug: string; scope: string; enabled: boolean | null }>(
121
- "/skills/enabled",
121
+ "/api/skills/enabled",
122
122
  body,
123
123
  ),
124
124
 
@@ -127,39 +127,39 @@ export const Skills = {
127
127
  * that project's .apc/skills/; otherwise in ~/.apx/skills/.
128
128
  */
129
129
  create: (body: { slug: string; description?: string; body?: string; project_path?: string }) =>
130
- http.post<CreateResult>("/skills", body),
130
+ http.post<CreateResult>("/api/skills", body),
131
131
 
132
132
  /** Import a skill from an uploaded .zip (base64-encoded). */
133
133
  importZip: (body: { data: string; project_path?: string }) =>
134
- http.post<CreateResult>("/skills/import/zip", body),
134
+ http.post<CreateResult>("/api/skills/import/zip", body),
135
135
 
136
136
  /** Import a skill by cloning a git repo. */
137
137
  importRepo: (body: { url: string; project_path?: string }) =>
138
- http.post<CreateResult>("/skills/import/repo", body),
138
+ http.post<CreateResult>("/api/skills/import/repo", body),
139
139
 
140
140
  /** Delete a user skill (global or project-scoped). */
141
141
  remove: (slug: string, projectPath?: string) => {
142
142
  const qs = projectPath ? `?project_path=${encodeURIComponent(projectPath)}` : "";
143
- return http.del<{ ok: boolean; slug: string }>(`/skills/${encodeURIComponent(slug)}${qs}`);
143
+ return http.del<{ ok: boolean; slug: string }>(`/api/skills/${encodeURIComponent(slug)}${qs}`);
144
144
  },
145
145
 
146
146
  /** Skill Inspector config + index status. */
147
- inspector: () => http.get<InspectorState>("/skills/inspector"),
147
+ inspector: () => http.get<InspectorState>("/api/skills/inspector"),
148
148
 
149
149
  /** Patch inspector config (toggle / tune thresholds). */
150
150
  updateInspector: (patch: Partial<InspectorConfig>) =>
151
151
  http.put<{ ok: boolean; config: InspectorConfig; index: IndexStatus }>(
152
- "/skills/inspector",
152
+ "/api/skills/inspector",
153
153
  patch,
154
154
  ),
155
155
 
156
156
  /** (Re)build the inspector vector index. */
157
157
  index: (body: { project_path?: string; force?: boolean } = {}) =>
158
- http.post<IndexResult>("/skills/index", body),
158
+ http.post<IndexResult>("/api/skills/index", body),
159
159
 
160
160
  /** Dry-run the inspector for a prompt (forces enabled). */
161
161
  inspect: (prompt: string, projectPath?: string) =>
162
- http.post<InspectResult>("/skills/inspect", {
162
+ http.post<InspectResult>("/api/skills/inspect", {
163
163
  prompt,
164
164
  project_path: projectPath,
165
165
  }),
@@ -14,7 +14,7 @@ export interface SuperAgentSendBody {
14
14
  export const SuperAgent = {
15
15
  send: (pid: string | number, body: SuperAgentSendBody) =>
16
16
  http.post<{ text: string; usage?: unknown; name?: string }>(
17
- `/projects/${pid}/super-agent/chat`,
17
+ `/api/projects/${pid}/super-agent/chat`,
18
18
  body,
19
19
  ),
20
20
  stream: (
@@ -22,8 +22,8 @@ export const SuperAgent = {
22
22
  body: SuperAgentSendBody,
23
23
  onEvent: (ev: ChatStreamEvent) => void,
24
24
  signal?: AbortSignal,
25
- ) => streamNdjson<ChatStreamEvent>(`/projects/${pid}/super-agent/chat/stream`, body, onEvent, signal),
25
+ ) => streamNdjson<ChatStreamEvent>(`/api/projects/${pid}/super-agent/chat/stream`, body, onEvent, signal),
26
26
 
27
27
  summarize: (body: { prompt: string; context_note?: string; model?: string }) =>
28
- http.post<{ text: string; usage?: unknown; name?: string }>("/super-agent/summarize", body),
28
+ http.post<{ text: string; usage?: unknown; name?: string }>("/api/super-agent/summarize", body),
29
29
  };
@@ -18,28 +18,28 @@ export interface TaskSummary {
18
18
  export const Tasks = {
19
19
  // Full sets (no pagination) — unwrapped to plain arrays for non-paged callers.
20
20
  list: (pid: string, state: TaskEntry["state"] | "all" = "open") =>
21
- http.get<unknown>(`/projects/${pid}/tasks?state=${state}`).then((b) => unwrapPage<TaskEntry>(b).items),
21
+ http.get<unknown>(`/api/projects/${pid}/tasks?state=${state}`).then((b) => unwrapPage<TaskEntry>(b).items),
22
22
  global: (state: TaskEntry["state"] | "all" = "open") =>
23
- http.get<unknown>(`/tasks?state=${state}`).then((b) => unwrapPage<GlobalTaskEntry>(b).items),
23
+ http.get<unknown>(`/api/tasks?state=${state}`).then((b) => unwrapPage<GlobalTaskEntry>(b).items),
24
24
  // Server-paginated variants: one project (listPage) or all projects
25
25
  // (globalPage). Each returns the requested window plus the full total.
26
26
  listPage: (pid: string, { state, limit, offset }: { state: TaskEntry["state"] | "all"; limit: number; offset: number }) =>
27
- http.get<unknown>(`/projects/${pid}/tasks?state=${state}&limit=${limit}&offset=${offset}`).then((b) => unwrapPage<TaskEntry>(b)),
27
+ http.get<unknown>(`/api/projects/${pid}/tasks?state=${state}&limit=${limit}&offset=${offset}`).then((b) => unwrapPage<TaskEntry>(b)),
28
28
  globalPage: ({ state, limit, offset, status }: { state: TaskEntry["state"] | "all"; limit: number; offset: number; status?: TaskStatus | "" }) =>
29
29
  http
30
30
  .get<unknown>(
31
- `/tasks?state=${state}&limit=${limit}&offset=${offset}` + (status ? `&status=${status}` : ""),
31
+ `/api/tasks?state=${state}&limit=${limit}&offset=${offset}` + (status ? `&status=${status}` : ""),
32
32
  )
33
33
  .then((b) => unwrapPage<GlobalTaskEntry>(b)),
34
- get: (pid: string, id: string) => http.get<TaskEntry>(`/projects/${pid}/tasks/${id}`),
34
+ get: (pid: string, id: string) => http.get<TaskEntry>(`/api/projects/${pid}/tasks/${id}`),
35
35
  add: (pid: string, body: Partial<TaskEntry>) =>
36
- http.post<TaskEntry>(`/projects/${pid}/tasks`, body),
36
+ http.post<TaskEntry>(`/api/projects/${pid}/tasks`, body),
37
37
  patch: (pid: string, id: string, patch: Partial<TaskEntry>) =>
38
- http.patch<TaskEntry>(`/projects/${pid}/tasks/${id}`, { patch }),
38
+ http.patch<TaskEntry>(`/api/projects/${pid}/tasks/${id}`, { patch }),
39
39
  status: (pid: string, id: string, status: TaskStatus) =>
40
- http.post<TaskEntry>(`/projects/${pid}/tasks/${id}/status`, { status }),
41
- done: (pid: string, id: string) => http.post<TaskEntry>(`/projects/${pid}/tasks/${id}/done`),
42
- drop: (pid: string, id: string) => http.post<TaskEntry>(`/projects/${pid}/tasks/${id}/drop`),
43
- reopen: (pid: string, id: string) => http.post<TaskEntry>(`/projects/${pid}/tasks/${id}/reopen`),
44
- summary: (pid: string) => http.get<TaskSummary>(`/projects/${pid}/tasks-summary`),
40
+ http.post<TaskEntry>(`/api/projects/${pid}/tasks/${id}/status`, { status }),
41
+ done: (pid: string, id: string) => http.post<TaskEntry>(`/api/projects/${pid}/tasks/${id}/done`),
42
+ drop: (pid: string, id: string) => http.post<TaskEntry>(`/api/projects/${pid}/tasks/${id}/drop`),
43
+ reopen: (pid: string, id: string) => http.post<TaskEntry>(`/api/projects/${pid}/tasks/${id}/reopen`),
44
+ summary: (pid: string) => http.get<TaskSummary>(`/api/projects/${pid}/tasks-summary`),
45
45
  };
@@ -21,37 +21,37 @@ export interface TelegramSendBody {
21
21
 
22
22
  export const Telegram = {
23
23
  channels: {
24
- list: () => http.get<TelegramChannelsResponse>("/telegram/channels"),
24
+ list: () => http.get<TelegramChannelsResponse>("/api/telegram/channels"),
25
25
  upsert: (ch: TelegramChannel) =>
26
- http.post<{ channel: TelegramChannel; created: boolean }>("/telegram/channels", ch),
26
+ http.post<{ channel: TelegramChannel; created: boolean }>("/api/telegram/channels", ch),
27
27
  patch: (name: string, body: Partial<TelegramChannel>) =>
28
- http.patch<{ ok: true; channel: TelegramChannel }>(`/telegram/channels/${name}`, body),
28
+ http.patch<{ ok: true; channel: TelegramChannel }>(`/api/telegram/channels/${name}`, body),
29
29
  remove: (name: string) =>
30
- http.del<void>(`/telegram/channels/${encodeURIComponent(name)}`),
30
+ http.del<void>(`/api/telegram/channels/${encodeURIComponent(name)}`),
31
31
  },
32
32
  contacts: {
33
- list: () => http.get<TelegramContactsResponse>("/telegram/contacts"),
33
+ list: () => http.get<TelegramContactsResponse>("/api/telegram/contacts"),
34
34
  patch: (userId: number | string, body: Partial<TelegramContact>) =>
35
35
  http.patch<{ ok: true; contact: TelegramContact }>(
36
- `/telegram/contacts/${encodeURIComponent(String(userId))}`,
36
+ `/api/telegram/contacts/${encodeURIComponent(String(userId))}`,
37
37
  body,
38
38
  ),
39
39
  remove: (userId: number | string) =>
40
- http.del<void>(`/telegram/contacts/${encodeURIComponent(String(userId))}`),
40
+ http.del<void>(`/api/telegram/contacts/${encodeURIComponent(String(userId))}`),
41
41
  },
42
42
  roles: {
43
- list: () => http.get<{ roles: Record<string, TelegramRole> }>("/telegram/roles"),
43
+ list: () => http.get<{ roles: Record<string, TelegramRole> }>("/api/telegram/roles"),
44
44
  set: (name: string, tools: "*" | string[]) =>
45
45
  http.put<{ ok: true; name: string; role: TelegramRole }>(
46
- `/telegram/roles/${encodeURIComponent(name)}`,
46
+ `/api/telegram/roles/${encodeURIComponent(name)}`,
47
47
  { tools },
48
48
  ),
49
49
  remove: (name: string) =>
50
- http.del<void>(`/telegram/roles/${encodeURIComponent(name)}`),
50
+ http.del<void>(`/api/telegram/roles/${encodeURIComponent(name)}`),
51
51
  },
52
- status: () => http.get<TelegramStatus>("/telegram/status"),
53
- start: () => http.post<{ ok: true; status: TelegramStatus }>("/telegram/start"),
54
- stop: () => http.post<{ ok: true; status: TelegramStatus }>("/telegram/stop"),
52
+ status: () => http.get<TelegramStatus>("/api/telegram/status"),
53
+ start: () => http.post<{ ok: true; status: TelegramStatus }>("/api/telegram/start"),
54
+ stop: () => http.post<{ ok: true; status: TelegramStatus }>("/api/telegram/stop"),
55
55
  send: (body: TelegramSendBody) =>
56
- http.post<{ ok: true; message_id: number }>("/telegram/send", body),
56
+ http.post<{ ok: true; message_id: number }>("/api/telegram/send", body),
57
57
  };
@@ -9,5 +9,5 @@ export interface ToolInfo {
9
9
 
10
10
  export const Tools = {
11
11
  // Registry of built-in tools the daemon exposes.
12
- list: () => http.get<ToolInfo[]>("/tools"),
12
+ list: () => http.get<ToolInfo[]>("/api/tools"),
13
13
  };
@@ -20,19 +20,19 @@ export interface VarDetail {
20
20
  export const Vars = {
21
21
  list: (pid: string, opts: { reveal?: boolean } = {}) =>
22
22
  http.get<VarsList>(
23
- `/projects/${pid}/vars${opts.reveal ? "?reveal=1" : ""}`,
23
+ `/api/projects/${pid}/vars${opts.reveal ? "?reveal=1" : ""}`,
24
24
  ),
25
25
  get: (pid: string, name: string, opts: { reveal?: boolean } = {}) =>
26
26
  http.get<VarDetail>(
27
- `/projects/${pid}/vars/${encodeURIComponent(name)}${opts.reveal ? "?reveal=1" : ""}`,
27
+ `/api/projects/${pid}/vars/${encodeURIComponent(name)}${opts.reveal ? "?reveal=1" : ""}`,
28
28
  ),
29
29
  upsert: (pid: string, body: { name: string; value: string; scope?: VarScope }) =>
30
30
  http.post<{ ok: true; name: string; scope: VarScope }>(
31
- `/projects/${pid}/vars`,
31
+ `/api/projects/${pid}/vars`,
32
32
  body,
33
33
  ),
34
34
  remove: (pid: string, name: string, scope: VarScope = "project") =>
35
35
  http.del<void>(
36
- `/projects/${pid}/vars/${encodeURIComponent(name)}?scope=${scope}`,
36
+ `/api/projects/${pid}/vars/${encodeURIComponent(name)}?scope=${scope}`,
37
37
  ),
38
38
  };
@@ -220,7 +220,7 @@ export const TTS_PROVIDER_ORDER: TtsProviderId[] = ["piper", "elevenlabs", "open
220
220
  */
221
221
  export async function fetchTtsAudioUrl(audioPath: string): Promise<string> {
222
222
  const token = getToken();
223
- const res = await fetch(`/voice/tts?path=${encodeURIComponent(audioPath)}`, {
223
+ const res = await fetch(`/api/voice/tts?path=${encodeURIComponent(audioPath)}`, {
224
224
  headers: token ? { authorization: `Bearer ${token}` } : {},
225
225
  });
226
226
  if (!res.ok) {
@@ -233,13 +233,13 @@ export async function fetchTtsAudioUrl(audioPath: string): Promise<string> {
233
233
 
234
234
  export const Voice = {
235
235
  /** List TTS engines + availability + the configured default provider. */
236
- providers: () => http.get<TtsProvidersResponse>("/tts/providers"),
236
+ providers: () => http.get<TtsProvidersResponse>("/api/tts/providers"),
237
237
 
238
238
  /** Detected hardware + the recommended local STT backend (Metal/CUDA/CPU). */
239
- sttHardware: () => http.get<SttHardwareResponse>("/transcribe/hardware"),
239
+ sttHardware: () => http.get<SttHardwareResponse>("/api/transcribe/hardware"),
240
240
 
241
241
  /** Model catalog + on-disk status for a local backend ("faster" | "mlx"). */
242
- sttModels: (backend: string) => http.get<SttModelsResponse>(`/transcribe/models?backend=${backend}`),
242
+ sttModels: (backend: string) => http.get<SttModelsResponse>(`/api/transcribe/models?backend=${backend}`),
243
243
 
244
244
  /**
245
245
  * Synthesize speech. Returns the audio file path (server-side); the web
@@ -247,7 +247,7 @@ export const Voice = {
247
247
  * is irrelevant for the web (the daemon never plays for HTTP callers).
248
248
  */
249
249
  say: (body: { text: string; provider?: string; voice?: string; language?: string; format?: string; style?: string }) =>
250
- http.post<TtsSayResult>("/tts/say", body),
250
+ http.post<TtsSayResult>("/api/tts/say", body),
251
251
 
252
252
  /**
253
253
  * One bidirectional voice turn (STT → agent → TTS). The web uses the
@@ -261,5 +261,5 @@ export const Voice = {
261
261
  provider?: string;
262
262
  voice?: string;
263
263
  language?: string;
264
- }) => http.post<VoiceTurnResult>("/voice/turn", body),
264
+ }) => http.post<VoiceTurnResult>("/api/voice/turn", body),
265
265
  };
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Five-field cron ⇄ human, both directions.
3
+ *
4
+ * `30 8 * * 1-5` is not a thing anyone should have to read to answer "when
5
+ * does my morning message arrive". Two pure functions, one file, so the
6
+ * summary shown in a status line and the picker used in a form can never
7
+ * disagree about what an expression means.
8
+ *
9
+ * Deliberately NOT a general cron library. It covers what APX writes and what
10
+ * the picker produces — fixed time, day-of-week sets, day-of-month, and
11
+ * step values — and says plainly when it does not understand something rather
12
+ * than guessing. `describeCron` returning null is the signal for a surface to
13
+ * fall back to showing the raw expression.
14
+ */
15
+
16
+ export interface CronParts {
17
+ minute: string;
18
+ hour: string;
19
+ dom: string;
20
+ month: string;
21
+ dow: string;
22
+ }
23
+
24
+ /** What a picker edits. */
25
+ export interface CronSelection {
26
+ /** "HH:MM" in the machine's local time. */
27
+ time: string;
28
+ /** 0=Sunday … 6=Saturday. Empty = every day. */
29
+ days: number[];
30
+ /** Run every N hours instead of at a fixed time. 0 = off. */
31
+ everyHours: number;
32
+ }
33
+
34
+ export const DAY_KEYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] as const;
35
+
36
+ export function parseCron(expr: string): CronParts | null {
37
+ const f = String(expr || "").trim().split(/\s+/);
38
+ if (f.length !== 5) return null;
39
+ return { minute: f[0], hour: f[1], dom: f[2], month: f[3], dow: f[4] };
40
+ }
41
+
42
+ // Expand `1-5`, `1,3,5`, `*` and step values like `*/2` into concrete numbers.
43
+ // (Kept as a line comment: a `*/` inside a block comment closes it.)
44
+ function expand(field: string, min: number, max: number): number[] | null {
45
+ const out = new Set<number>();
46
+ for (const part of String(field).split(",")) {
47
+ const step = part.match(/^(.+)\/(\d+)$/);
48
+ const body = step ? step[1] : part;
49
+ const by = step ? Number(step[2]) : 1;
50
+ if (!Number.isFinite(by) || by < 1) return null;
51
+
52
+ let lo: number;
53
+ let hi: number;
54
+ if (body === "*") { lo = min; hi = max; }
55
+ else {
56
+ const range = body.match(/^(\d+)-(\d+)$/);
57
+ if (range) { lo = Number(range[1]); hi = Number(range[2]); }
58
+ else if (/^\d+$/.test(body)) { lo = Number(body); hi = lo; }
59
+ else return null;
60
+ }
61
+ if (lo < min || hi > max || lo > hi) return null;
62
+ for (let v = lo; v <= hi; v += by) out.add(v);
63
+ }
64
+ return [...out].sort((a, b) => a - b);
65
+ }
66
+
67
+ /** Day numbers a cron dow field selects. Cron accepts 7 for Sunday. */
68
+ export function cronDays(dow: string): number[] | null {
69
+ if (dow === "*" || dow === "?") return [];
70
+ const nums = expand(dow.replace(/\b7\b/g, "0"), 0, 6);
71
+ return nums && nums.length ? nums : null;
72
+ }
73
+
74
+ /**
75
+ * A sentence. Returns null when the expression is beyond what this understands
76
+ * — the caller shows the raw cron rather than a confident wrong reading.
77
+ */
78
+ export function describeCron(
79
+ expr: string,
80
+ t: (key: string, vars?: Record<string, string | number>) => string,
81
+ ): string | null {
82
+ const p = parseCron(expr);
83
+ if (!p) return null;
84
+ if (p.month !== "*") return null; // "in March" is not a case APX writes
85
+ if (p.dom !== "*" && p.dow !== "*") return null; // both set is ambiguous in cron itself
86
+
87
+ // Every N hours: `0 */2 * * *`.
88
+ const stepHour = p.hour.match(/^\*\/(\d+)$/);
89
+ if (stepHour && /^\d+$/.test(p.minute)) {
90
+ const n = Number(stepHour[1]);
91
+ return n === 1
92
+ ? t("cron.every_hour", { minute: pad(Number(p.minute)) })
93
+ : t("cron.every_n_hours", { n, minute: pad(Number(p.minute)) });
94
+ }
95
+ // Every N minutes: `*/15 * * * *`.
96
+ const stepMin = p.minute.match(/^\*\/(\d+)$/);
97
+ if (stepMin && p.hour === "*") return t("cron.every_n_minutes", { n: Number(stepMin[1]) });
98
+ if (p.minute === "*" && p.hour === "*") return t("cron.every_minute");
99
+
100
+ const hours = expand(p.hour, 0, 23);
101
+ const minutes = expand(p.minute, 0, 59);
102
+ if (!hours || !minutes || minutes.length !== 1) return null;
103
+
104
+ const at = hours.length === 1
105
+ ? `${pad(hours[0])}:${pad(minutes[0])}`
106
+ : hours.map((h) => `${pad(h)}:${pad(minutes[0])}`).join(", ");
107
+
108
+ if (p.dom !== "*") {
109
+ const doms = expand(p.dom, 1, 31);
110
+ if (!doms || doms.length !== 1) return null;
111
+ return t("cron.monthly", { day: doms[0], at });
112
+ }
113
+
114
+ const days = cronDays(p.dow);
115
+ if (days === null) return null;
116
+ if (!days.length) return t("cron.daily", { at });
117
+
118
+ const weekdays = [1, 2, 3, 4, 5];
119
+ const isWeekdays = days.length === 5 && weekdays.every((d) => days.includes(d));
120
+ if (isWeekdays) return t("cron.weekdays", { at });
121
+ if (days.length === 2 && days.includes(0) && days.includes(6)) return t("cron.weekends", { at });
122
+
123
+ const names = days.map((d) => t(`cron.day_short.${DAY_KEYS[d]}`)).join(", ");
124
+ return t("cron.on_days", { days: names, at });
125
+ }
126
+
127
+ /** Cron → what a picker should show. */
128
+ export function cronToSelection(expr: string): CronSelection {
129
+ const p = parseCron(expr);
130
+ const fallback: CronSelection = { time: "08:00", days: [], everyHours: 0 };
131
+ if (!p) return fallback;
132
+
133
+ const stepHour = p.hour.match(/^\*\/(\d+)$/);
134
+ if (stepHour) {
135
+ return {
136
+ time: `00:${pad(Number(/^\d+$/.test(p.minute) ? p.minute : 0))}`,
137
+ days: [],
138
+ everyHours: Number(stepHour[1]),
139
+ };
140
+ }
141
+ const hours = expand(p.hour, 0, 23);
142
+ const minutes = expand(p.minute, 0, 59);
143
+ const days = cronDays(p.dow);
144
+ return {
145
+ time: hours?.length && minutes?.length ? `${pad(hours[0])}:${pad(minutes[0])}` : fallback.time,
146
+ days: days ?? [],
147
+ everyHours: 0,
148
+ };
149
+ }
150
+
151
+ /** What a picker produces. Always a valid five-field expression. */
152
+ export function selectionToCron(sel: CronSelection): string {
153
+ if (sel.everyHours > 0) {
154
+ const [, mm] = splitTime(sel.time);
155
+ return `${mm} */${clamp(sel.everyHours, 1, 23)} * * *`;
156
+ }
157
+ const [hh, mm] = splitTime(sel.time);
158
+ // Sorted, and 0 kept as 0 — cron accepts both 0 and 7 for Sunday, and
159
+ // writing one form consistently keeps round-tripping stable.
160
+ const dow = sel.days.length && sel.days.length < 7
161
+ ? [...sel.days].sort((a, b) => a - b).join(",")
162
+ : "*";
163
+ return `${mm} ${hh} * * ${dow}`;
164
+ }
165
+
166
+ /** Is this something the pickers can represent without losing information? */
167
+ export function isPickerFriendly(expr: string): boolean {
168
+ const p = parseCron(expr);
169
+ if (!p) return false;
170
+ if (p.month !== "*" || p.dom !== "*") return false;
171
+ return selectionToCron(cronToSelection(expr)) === normalizeCron(expr);
172
+ }
173
+
174
+ /** `30 08 * * 1-5` → `30 8 * * 1,2,3,4,5`, so comparisons are meaningful. */
175
+ export function normalizeCron(expr: string): string {
176
+ const p = parseCron(expr);
177
+ if (!p) return String(expr || "").trim();
178
+ const days = cronDays(p.dow);
179
+ const dow = days && days.length && days.length < 7 ? days.join(",") : "*";
180
+ const one = (f: string) => (/^\d+$/.test(f) ? String(Number(f)) : f);
181
+ return `${one(p.minute)} ${one(p.hour)} ${p.dom} ${p.month} ${dow}`;
182
+ }
183
+
184
+ function splitTime(time: string): [string, string] {
185
+ const m = /^(\d{1,2}):(\d{2})$/.exec(String(time || "").trim());
186
+ if (!m) return ["8", "0"];
187
+ return [String(clamp(Number(m[1]), 0, 23)), String(clamp(Number(m[2]), 0, 59))];
188
+ }
189
+
190
+ function pad(n: number): string {
191
+ return String(n).padStart(2, "0");
192
+ }
193
+
194
+ function clamp(n: number, lo: number, hi: number): number {
195
+ return Math.min(hi, Math.max(lo, Number.isFinite(n) ? n : lo));
196
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * "in 8 hours" / "2 minutes ago".
3
+ *
4
+ * A status row showing two absolute timestamps makes the reader do the
5
+ * arithmetic that the row exists to save them. The absolute value stays
6
+ * available as a tooltip for when the exact minute is what matters.
7
+ */
8
+ type T = (key: string, vars?: Record<string, string | number>) => string;
9
+
10
+ const MINUTE = 60_000;
11
+ const HOUR = 60 * MINUTE;
12
+ const DAY = 24 * HOUR;
13
+
14
+ export function relativeWhen(iso: string, t: T, now: number = Date.now()): string {
15
+ const ms = Date.parse(iso);
16
+ if (!Number.isFinite(ms)) return "—";
17
+ const diff = ms - now;
18
+ const ahead = diff >= 0;
19
+ const abs = Math.abs(diff);
20
+
21
+ // Under a minute reads as "now" in both directions: "in 34 seconds" is
22
+ // precision nobody acts on.
23
+ if (abs < MINUTE) return t("when.now");
24
+
25
+ const [n, unit] =
26
+ abs < HOUR ? [Math.round(abs / MINUTE), "minutes"] :
27
+ abs < DAY ? [Math.round(abs / HOUR), "hours"] :
28
+ [Math.round(abs / DAY), "days"];
29
+
30
+ const amount = t(`when.${unit}`, { n });
31
+ return ahead ? t("when.in", { amount }) : t("when.ago", { amount });
32
+ }