@asterxsk/kiln 0.1.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 (263) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -0
  3. package/agent/AGENTS.md +67 -0
  4. package/agent/README.md +5 -0
  5. package/agent/extensions/AGENTS.md +68 -0
  6. package/agent/extensions/ask-user/index.ts +418 -0
  7. package/agent/extensions/ask-user/install.ps1 +23 -0
  8. package/agent/extensions/ask-user/install.sh +21 -0
  9. package/agent/extensions/ask-user/package-lock.json +769 -0
  10. package/agent/extensions/ask-user/package.json +19 -0
  11. package/agent/extensions/ask-user/prompt.ts +45 -0
  12. package/agent/extensions/ask-user/tsconfig.json +7 -0
  13. package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -0
  14. package/agent/extensions/background-terminals/index.ts +627 -0
  15. package/agent/extensions/background-terminals/install.ps1 +23 -0
  16. package/agent/extensions/background-terminals/install.sh +21 -0
  17. package/agent/extensions/background-terminals/manager.test.ts +735 -0
  18. package/agent/extensions/background-terminals/output.test.ts +109 -0
  19. package/agent/extensions/background-terminals/package-lock.json +769 -0
  20. package/agent/extensions/background-terminals/package.json +17 -0
  21. package/agent/extensions/background-terminals/prompt.test.ts +125 -0
  22. package/agent/extensions/background-terminals/ps.test.ts +82 -0
  23. package/agent/extensions/background-terminals/result-delivery.test.ts +44 -0
  24. package/agent/extensions/background-terminals/src/domain.ts +87 -0
  25. package/agent/extensions/background-terminals/src/manager.ts +907 -0
  26. package/agent/extensions/background-terminals/src/output.ts +84 -0
  27. package/agent/extensions/background-terminals/src/prompt.ts +142 -0
  28. package/agent/extensions/background-terminals/src/result-delivery.ts +27 -0
  29. package/agent/extensions/background-terminals/src/runtime.ts +36 -0
  30. package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -0
  31. package/agent/extensions/background-terminals/src/ui/ps.ts +621 -0
  32. package/agent/extensions/background-terminals/tsconfig.json +7 -0
  33. package/agent/extensions/destructive/README.md +31 -0
  34. package/agent/extensions/destructive/index.ts +88 -0
  35. package/agent/extensions/destructive/install.ps1 +23 -0
  36. package/agent/extensions/destructive/install.sh +21 -0
  37. package/agent/extensions/file-search/index.spec.ts +443 -0
  38. package/agent/extensions/file-search/index.ts +459 -0
  39. package/agent/extensions/file-search/install.ps1 +23 -0
  40. package/agent/extensions/file-search/install.sh +21 -0
  41. package/agent/extensions/file-search/package-lock.json +2253 -0
  42. package/agent/extensions/file-search/package.json +23 -0
  43. package/agent/extensions/file-search/src/args.ts +122 -0
  44. package/agent/extensions/file-search/src/binaries.ts +422 -0
  45. package/agent/extensions/file-search/src/output.ts +126 -0
  46. package/agent/extensions/file-search/src/process.ts +146 -0
  47. package/agent/extensions/file-search/src/prompt.ts +52 -0
  48. package/agent/extensions/file-search/tsconfig.json +7 -0
  49. package/agent/extensions/goal/README.md +50 -0
  50. package/agent/extensions/goal/index.ts +155 -0
  51. package/agent/extensions/goal/install.ps1 +23 -0
  52. package/agent/extensions/goal/install.sh +21 -0
  53. package/agent/extensions/modelconf/PLAN.md +915 -0
  54. package/agent/extensions/modelconf/README.md +66 -0
  55. package/agent/extensions/modelconf/index.ts +296 -0
  56. package/agent/extensions/modelconf/install.ps1 +23 -0
  57. package/agent/extensions/modelconf/install.sh +21 -0
  58. package/agent/extensions/modelconf/package-lock.json +1809 -0
  59. package/agent/extensions/modelconf/package.json +13 -0
  60. package/agent/extensions/modelconf/src/fuzzy.ts +26 -0
  61. package/agent/extensions/modelconf/src/glob.ts +13 -0
  62. package/agent/extensions/modelconf/src/persistence.test.ts +46 -0
  63. package/agent/extensions/modelconf/src/persistence.ts +164 -0
  64. package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -0
  65. package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -0
  66. package/agent/extensions/modelconf/tsconfig.json +15 -0
  67. package/agent/extensions/pi-web-access/CHANGELOG.md +690 -0
  68. package/agent/extensions/pi-web-access/LICENSE +21 -0
  69. package/agent/extensions/pi-web-access/README.md +470 -0
  70. package/agent/extensions/pi-web-access/SECURITY.md +5 -0
  71. package/agent/extensions/pi-web-access/activity.ts +101 -0
  72. package/agent/extensions/pi-web-access/auth-fetch.ts +148 -0
  73. package/agent/extensions/pi-web-access/banner.png +0 -0
  74. package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -0
  75. package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -0
  76. package/agent/extensions/pi-web-access/content-find.ts +139 -0
  77. package/agent/extensions/pi-web-access/credential-source.ts +191 -0
  78. package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -0
  79. package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -0
  80. package/agent/extensions/pi-web-access/declared-web-links.ts +173 -0
  81. package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -0
  82. package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -0
  83. package/agent/extensions/pi-web-access/exa.ts +526 -0
  84. package/agent/extensions/pi-web-access/extract.ts +1196 -0
  85. package/agent/extensions/pi-web-access/feature-config.ts +29 -0
  86. package/agent/extensions/pi-web-access/fetch-params.ts +111 -0
  87. package/agent/extensions/pi-web-access/gemini-adc.ts +298 -0
  88. package/agent/extensions/pi-web-access/gemini-api.ts +353 -0
  89. package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -0
  90. package/agent/extensions/pi-web-access/gemini-search.ts +21 -0
  91. package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -0
  92. package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -0
  93. package/agent/extensions/pi-web-access/gemini-web.ts +487 -0
  94. package/agent/extensions/pi-web-access/github-api.ts +197 -0
  95. package/agent/extensions/pi-web-access/github-extract.ts +746 -0
  96. package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -0
  97. package/agent/extensions/pi-web-access/index.ts +1737 -0
  98. package/agent/extensions/pi-web-access/package-lock.json +5808 -0
  99. package/agent/extensions/pi-web-access/package.json +64 -0
  100. package/agent/extensions/pi-web-access/page-query.ts +96 -0
  101. package/agent/extensions/pi-web-access/pdf-extract.ts +409 -0
  102. package/agent/extensions/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
  103. package/agent/extensions/pi-web-access/promise-try.d.ts +7 -0
  104. package/agent/extensions/pi-web-access/query-rewrite.ts +51 -0
  105. package/agent/extensions/pi-web-access/render-search-error.ts +170 -0
  106. package/agent/extensions/pi-web-access/rsc-extract.ts +338 -0
  107. package/agent/extensions/pi-web-access/search-types.ts +20 -0
  108. package/agent/extensions/pi-web-access/source-check.ts +282 -0
  109. package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -0
  110. package/agent/extensions/pi-web-access/storage.ts +521 -0
  111. package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -0
  112. package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -0
  113. package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -0
  114. package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -0
  115. package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -0
  116. package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -0
  117. package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -0
  118. package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -0
  119. package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -0
  120. package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -0
  121. package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -0
  122. package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -0
  123. package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -0
  124. package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -0
  125. package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -0
  126. package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -0
  127. package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -0
  128. package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -0
  129. package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -0
  130. package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -0
  131. package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -0
  132. package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -0
  133. package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -0
  134. package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -0
  135. package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -0
  136. package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -0
  137. package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -0
  138. package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -0
  139. package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -0
  140. package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -0
  141. package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -0
  142. package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -0
  143. package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -0
  144. package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -0
  145. package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -0
  146. package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -0
  147. package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -0
  148. package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -0
  149. package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -0
  150. package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -0
  151. package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -0
  152. package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -0
  153. package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -0
  154. package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -0
  155. package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -0
  156. package/agent/extensions/pi-web-access/tsconfig.json +11 -0
  157. package/agent/extensions/pi-web-access/utils.ts +451 -0
  158. package/agent/extensions/pi-web-access/video-extract.ts +392 -0
  159. package/agent/extensions/pi-web-access/youtube-extract.ts +328 -0
  160. package/agent/extensions/shared/activity-status.ts +31 -0
  161. package/agent/extensions/shared/child-session.test.ts +270 -0
  162. package/agent/extensions/shared/child-session.ts +148 -0
  163. package/agent/extensions/shared/context-utilization.test.ts +48 -0
  164. package/agent/extensions/shared/context-utilization.ts +47 -0
  165. package/agent/extensions/shared/dashboard-state.ts +99 -0
  166. package/agent/extensions/shared/install.ps1 +23 -0
  167. package/agent/extensions/shared/install.sh +21 -0
  168. package/agent/extensions/shared/tool-call-timeout.test.ts +117 -0
  169. package/agent/extensions/shared/tool-call-timeout.ts +104 -0
  170. package/agent/extensions/skillsconf/README.md +74 -0
  171. package/agent/extensions/skillsconf/index.ts +92 -0
  172. package/agent/extensions/skillsconf/install.ps1 +23 -0
  173. package/agent/extensions/skillsconf/install.sh +21 -0
  174. package/agent/extensions/skillsconf/package-lock.json +1809 -0
  175. package/agent/extensions/skillsconf/package.json +18 -0
  176. package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -0
  177. package/agent/extensions/skillsconf/src/delete-skill.ts +45 -0
  178. package/agent/extensions/skillsconf/src/filter.test.ts +80 -0
  179. package/agent/extensions/skillsconf/src/filter.ts +74 -0
  180. package/agent/extensions/skillsconf/src/fuzzy.ts +26 -0
  181. package/agent/extensions/skillsconf/src/persistence.test.ts +72 -0
  182. package/agent/extensions/skillsconf/src/persistence.ts +169 -0
  183. package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -0
  184. package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -0
  185. package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -0
  186. package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -0
  187. package/agent/extensions/skillsconf/tsconfig.json +15 -0
  188. package/agent/extensions/status line/index.ts +282 -0
  189. package/agent/extensions/status line/install.ps1 +23 -0
  190. package/agent/extensions/status line/install.sh +21 -0
  191. package/agent/extensions/subagents/by-the-way.test.ts +29 -0
  192. package/agent/extensions/subagents/claude.test.ts +119 -0
  193. package/agent/extensions/subagents/codex.test.ts +102 -0
  194. package/agent/extensions/subagents/context-usage.test.ts +107 -0
  195. package/agent/extensions/subagents/docs/design-plan.md +568 -0
  196. package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -0
  197. package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -0
  198. package/agent/extensions/subagents/index.ts +779 -0
  199. package/agent/extensions/subagents/install.ps1 +23 -0
  200. package/agent/extensions/subagents/install.sh +21 -0
  201. package/agent/extensions/subagents/manager.test.ts +276 -0
  202. package/agent/extensions/subagents/package-lock.json +2244 -0
  203. package/agent/extensions/subagents/package.json +19 -0
  204. package/agent/extensions/subagents/result-delivery.test.ts +27 -0
  205. package/agent/extensions/subagents/src/backend.ts +73 -0
  206. package/agent/extensions/subagents/src/backends/claude.ts +701 -0
  207. package/agent/extensions/subagents/src/backends/codex.ts +1060 -0
  208. package/agent/extensions/subagents/src/backends/pi.ts +575 -0
  209. package/agent/extensions/subagents/src/backends/stub.ts +300 -0
  210. package/agent/extensions/subagents/src/by-the-way.ts +21 -0
  211. package/agent/extensions/subagents/src/domain.ts +253 -0
  212. package/agent/extensions/subagents/src/format.ts +74 -0
  213. package/agent/extensions/subagents/src/manager.ts +736 -0
  214. package/agent/extensions/subagents/src/prompt.ts +92 -0
  215. package/agent/extensions/subagents/src/result-delivery.ts +20 -0
  216. package/agent/extensions/subagents/src/runtime.ts +53 -0
  217. package/agent/extensions/subagents/src/ui/takeover.ts +583 -0
  218. package/agent/extensions/subagents/src/ui/transcript.ts +201 -0
  219. package/agent/extensions/subagents/takeover.test.ts +29 -0
  220. package/agent/extensions/subagents/tsconfig.json +7 -0
  221. package/agent/extensions/taste/index.ts +443 -0
  222. package/agent/extensions/taste/install.ps1 +23 -0
  223. package/agent/extensions/taste/install.sh +21 -0
  224. package/agent/extensions/todo/AGENTS.md +38 -0
  225. package/agent/extensions/todo/LICENSE +21 -0
  226. package/agent/extensions/todo/config.ts +55 -0
  227. package/agent/extensions/todo/index.ts +151 -0
  228. package/agent/extensions/todo/install.ps1 +23 -0
  229. package/agent/extensions/todo/install.sh +21 -0
  230. package/agent/extensions/todo/locales/de.json +17 -0
  231. package/agent/extensions/todo/locales/en.json +15 -0
  232. package/agent/extensions/todo/locales/es.json +17 -0
  233. package/agent/extensions/todo/locales/fr.json +17 -0
  234. package/agent/extensions/todo/locales/pt-BR.json +17 -0
  235. package/agent/extensions/todo/locales/pt.json +17 -0
  236. package/agent/extensions/todo/locales/ru.json +17 -0
  237. package/agent/extensions/todo/locales/uk.json +17 -0
  238. package/agent/extensions/todo/locales/zh.json +17 -0
  239. package/agent/extensions/todo/package-lock.json +3358 -0
  240. package/agent/extensions/todo/package.json +67 -0
  241. package/agent/extensions/todo/state/i18n-bridge.ts +64 -0
  242. package/agent/extensions/todo/state/invariants.ts +20 -0
  243. package/agent/extensions/todo/state/replay.ts +38 -0
  244. package/agent/extensions/todo/state/selectors.ts +107 -0
  245. package/agent/extensions/todo/state/state-reducer.ts +326 -0
  246. package/agent/extensions/todo/state/state.ts +18 -0
  247. package/agent/extensions/todo/state/store.ts +82 -0
  248. package/agent/extensions/todo/state/task-graph.ts +57 -0
  249. package/agent/extensions/todo/todo-overlay.ts +200 -0
  250. package/agent/extensions/todo/todo.ts +155 -0
  251. package/agent/extensions/todo/tool/response-envelope.ts +109 -0
  252. package/agent/extensions/todo/tool/types.ts +206 -0
  253. package/agent/extensions/todo/verify-ref-system.js +0 -0
  254. package/agent/extensions/todo/view/format.ts +177 -0
  255. package/agent/extensions/trim-context/README.md +54 -0
  256. package/agent/extensions/trim-context/index.ts +487 -0
  257. package/agent/extensions/trim-context/install.ps1 +23 -0
  258. package/agent/extensions/trim-context/install.sh +21 -0
  259. package/agent/install.ps1 +527 -0
  260. package/agent/install.sh +511 -0
  261. package/agent/keybindings.json +7 -0
  262. package/bin/kiln.js +359 -0
  263. package/package.json +21 -0
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@juicesharp/rpiv-todo",
3
+ "version": "1.20.0",
4
+ "description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi-extension",
8
+ "rpiv",
9
+ "todo"
10
+ ],
11
+ "type": "module",
12
+ "license": "MIT",
13
+ "author": "juicesharp",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/juicesharp/rpiv-mono.git",
17
+ "directory": "packages/rpiv-todo"
18
+ },
19
+ "homepage": "https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/juicesharp/rpiv-mono/issues"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "test": "vitest run"
28
+ },
29
+ "files": [
30
+ "config.ts",
31
+ "index.ts",
32
+ "locales/",
33
+ "todo.ts",
34
+ "todo-overlay.ts",
35
+ "LICENSE",
36
+ "README.md",
37
+ "state/invariants.ts",
38
+ "state/i18n-bridge.ts",
39
+ "state/replay.ts",
40
+ "state/selectors.ts",
41
+ "state/state-reducer.ts",
42
+ "state/state.ts",
43
+ "state/store.ts",
44
+ "state/task-graph.ts",
45
+ "tool/response-envelope.ts",
46
+ "tool/types.ts",
47
+ "view/format.ts"
48
+ ],
49
+ "pi": {
50
+ "extensions": [
51
+ "./index.ts"
52
+ ]
53
+ },
54
+ "peerDependencies": {
55
+ "@juicesharp/rpiv-i18n": "*",
56
+ "@earendil-works/pi-ai": "*",
57
+ "@earendil-works/pi-coding-agent": "*",
58
+ "@earendil-works/pi-tui": "*",
59
+ "typebox": "*"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "@juicesharp/rpiv-i18n": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "dependencies": {}
67
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * i18n bridge for rpiv-todo — single thin import surface so every call site
3
+ * routes through one module. Backed by `@juicesharp/rpiv-i18n`'s SDK when
4
+ * available; degrades to canonical-English fallbacks when not.
5
+ *
6
+ * - `t(key, fallback)` is `scope("@juicesharp/rpiv-todo")` if the SDK is
7
+ * installed (live `/languages` updates propagate). If the SDK is missing
8
+ * (standalone install without rpiv-i18n), `t` is an identity passthrough
9
+ * that returns the inline English fallback at every call site, so the
10
+ * extension stays online with English UI.
11
+ * - `formatStatusLabel(status)` resolves a TaskStatus to its locale-aware
12
+ * label via the canonical `status.*` namespace, with the English literal
13
+ * as fallback so nothing renders blank if the namespace isn't registered.
14
+ * This is the SINGLE point of localization for status words — overlay,
15
+ * /todos header, /todos render-call all route through here.
16
+ *
17
+ * Strings are registered ONCE at extension load (see ../index.ts). Call sites
18
+ * MUST use this module at render time — never bake the result into a top-level
19
+ * `const X = formatStatusLabel(...)`.
20
+ */
21
+
22
+ import type { TaskStatus } from "../tool/types.js";
23
+
24
+ export const I18N_NAMESPACE = "@juicesharp/rpiv-todo";
25
+
26
+ type ScopeFn = (key: string, fallback: string) => string;
27
+ type I18nSDK = { scope: (namespace: string) => ScopeFn };
28
+
29
+ // Prefer the live SDK if installed: closures it returns track the active
30
+ // locale, so /languages picker propagates to our render call sites. If the
31
+ // SDK isn't installed (standalone install of this extension without
32
+ // rpiv-i18n), the dynamic import fails, every t(key, fallback) returns the
33
+ // canonical English literal, and the extension stays online.
34
+ //
35
+ // Top-level await is required so a synchronous `t(...)` call from any
36
+ // downstream module sees the resolved scope; ESM module loading awaits this
37
+ // before evaluating any importer.
38
+ let scopeImpl: ScopeFn;
39
+ try {
40
+ const sdk = (await import("@juicesharp/rpiv-i18n")) as I18nSDK;
41
+ scopeImpl = sdk.scope(I18N_NAMESPACE);
42
+ } catch {
43
+ scopeImpl = (_key, fallback) => fallback;
44
+ }
45
+
46
+ export const t: ScopeFn = scopeImpl;
47
+
48
+ const STATUS_LABEL_PENDING = "pending";
49
+ const STATUS_LABEL_IN_PROGRESS = "in progress";
50
+ const STATUS_LABEL_COMPLETED = "completed";
51
+ const STATUS_LABEL_DELETED = "deleted";
52
+
53
+ export function formatStatusLabel(status: TaskStatus): string {
54
+ switch (status) {
55
+ case "pending":
56
+ return t("status.pending", STATUS_LABEL_PENDING);
57
+ case "in_progress":
58
+ return t("status.in_progress", STATUS_LABEL_IN_PROGRESS);
59
+ case "completed":
60
+ return t("status.completed", STATUS_LABEL_COMPLETED);
61
+ case "deleted":
62
+ return t("status.deleted", STATUS_LABEL_DELETED);
63
+ }
64
+ }
@@ -0,0 +1,20 @@
1
+ import type { TaskStatus } from "../tool/types.js";
2
+
3
+ /**
4
+ * Allowed forward transitions per source status. `completed` is one-way to
5
+ * `deleted` (never back to `in_progress`); `deleted` is terminal.
6
+ *
7
+ * Idempotent same→same is checked separately in `isTransitionValid` so this
8
+ * table only enumerates actual transitions.
9
+ */
10
+ export const VALID_TRANSITIONS: Record<TaskStatus, ReadonlySet<TaskStatus>> = {
11
+ pending: new Set(["in_progress", "completed", "deleted"]),
12
+ in_progress: new Set(["pending", "completed", "deleted"]),
13
+ completed: new Set(["deleted"]),
14
+ deleted: new Set(),
15
+ };
16
+
17
+ export function isTransitionValid(from: TaskStatus, to: TaskStatus): boolean {
18
+ if (from === to) return true;
19
+ return VALID_TRANSITIONS[from].has(to);
20
+ }
@@ -0,0 +1,38 @@
1
+ import type { TaskDetails } from "../tool/types.js";
2
+ import { EMPTY_STATE, type TaskState } from "./state.js";
3
+
4
+ /**
5
+ * Discriminator for `details` envelopes that match the persisted `TaskDetails`
6
+ * shape. Defensive — branch entries from older or corrupt sessions are
7
+ * skipped silently.
8
+ */
9
+ export function isTaskDetails(value: unknown): value is TaskDetails {
10
+ if (!value || typeof value !== "object") return false;
11
+ const v = value as Record<string, unknown>;
12
+ return Array.isArray(v.tasks) && typeof v.nextId === "number";
13
+ }
14
+
15
+ /**
16
+ * Walk the current branch in chronological order; the LAST `toolResult` whose
17
+ * `toolName === "todo"` and whose `details` shape matches `TaskDetails` wins
18
+ * (last-write-wins). When no matching entry exists, returns `EMPTY_STATE`.
19
+ *
20
+ * Pure of module state — `index.ts` writes the returned snapshot into the
21
+ * store after this returns. The function explicitly does NOT touch the store
22
+ * cell.
23
+ */
24
+ export function replayFromBranch(ctx: { sessionManager: { getBranch(): Iterable<unknown> } }): TaskState {
25
+ let result: TaskState = { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId };
26
+ for (const entry of ctx.sessionManager.getBranch()) {
27
+ const e = entry as { type?: string; message?: { role?: string; toolName?: string; details?: unknown } };
28
+ if (e.type !== "message") continue;
29
+ const msg = e.message;
30
+ if (msg?.role !== "toolResult" || msg.toolName !== "todo") continue;
31
+ if (!isTaskDetails(msg.details)) continue;
32
+ result = {
33
+ tasks: msg.details.tasks.map((t) => ({ ...t })),
34
+ nextId: msg.details.nextId,
35
+ };
36
+ }
37
+ return result;
38
+ }
@@ -0,0 +1,107 @@
1
+ import type { Task, TaskStatus } from "../tool/types.js";
2
+ import type { TaskState } from "./state.js";
3
+
4
+ /** Tasks excluding deleted tombstones — the canonical "what's visible". */
5
+ export function selectVisibleTasks(state: TaskState): readonly Task[] {
6
+ return state.tasks.filter((t) => t.status !== "deleted");
7
+ }
8
+
9
+ /**
10
+ * Group visible tasks by status. Iteration order at the call site uses
11
+ * (`completed`, `inProgress`, `pending`) to match the `/todos` header part
12
+ * order pinned by `todo.command.test.ts`.
13
+ */
14
+ export interface TasksByStatus {
15
+ pending: readonly Task[];
16
+ inProgress: readonly Task[];
17
+ completed: readonly Task[];
18
+ }
19
+ export function selectTasksByStatus(state: TaskState): TasksByStatus {
20
+ const visible = selectVisibleTasks(state);
21
+ return {
22
+ pending: visible.filter((t) => t.status === "pending"),
23
+ inProgress: visible.filter((t) => t.status === "in_progress"),
24
+ completed: visible.filter((t) => t.status === "completed"),
25
+ };
26
+ }
27
+
28
+ /** Total counts for the overlay heading (`Todos (n/m)`) and `/todos` header. */
29
+ export interface TodoCounts {
30
+ total: number;
31
+ pending: number;
32
+ inProgress: number;
33
+ completed: number;
34
+ }
35
+ export function selectTodoCounts(state: TaskState): TodoCounts {
36
+ const groups = selectTasksByStatus(state);
37
+ return {
38
+ total: groups.pending.length + groups.inProgress.length + groups.completed.length,
39
+ pending: groups.pending.length,
40
+ inProgress: groups.inProgress.length,
41
+ completed: groups.completed.length,
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Whether any visible task carries a `blockedBy` reference. The overlay uses
47
+ * this to gate the `#id` prefix on per-task rows — without at least one
48
+ * `⛓ #N` suffix, the per-row id has no anchor.
49
+ */
50
+ export function selectShowTaskIds(state: TaskState): boolean {
51
+ return selectVisibleTasks(state).some((t) => t.blockedBy && t.blockedBy.length > 0);
52
+ }
53
+
54
+ /**
55
+ * Resolve a task's subject by id from the live state for renderCall's
56
+ * accent label. `undefined` when the id is unknown — caller falls back to
57
+ * `#id` plain rendering.
58
+ */
59
+ export function selectTaskSubjectById(state: TaskState, id: number): string | undefined {
60
+ return state.tasks.find((t) => t.id === id)?.subject;
61
+ }
62
+
63
+ /**
64
+ * Overlay layout decision. Encapsulates the "drop completed first, then
65
+ * truncate non-completed tail" rule pre-refactor lived in
66
+ * `todo-overlay.ts:144-188`. `budget` is the body-slot count (caller passes
67
+ * `MAX_WIDGET_LINES - 1` to reserve the heading row); on overflow the
68
+ * selector reserves one more slot internally for the summary row. Returns
69
+ * the visible task slice plus the overflow summary parts.
70
+ */
71
+ export interface OverlayLayout {
72
+ visible: readonly Task[];
73
+ hiddenCompleted: number;
74
+ truncatedTail: number;
75
+ }
76
+ export function selectOverlayLayout(state: TaskState, budget: number): OverlayLayout {
77
+ const all = selectVisibleTasks(state);
78
+ if (all.length <= budget) {
79
+ return { visible: all, hiddenCompleted: 0, truncatedTail: 0 };
80
+ }
81
+ const innerBudget = budget - 1;
82
+ const nonCompleted = all.filter((t) => t.status !== "completed");
83
+ const totalCompleted = all.length - nonCompleted.length;
84
+ if (nonCompleted.length <= innerBudget) {
85
+ const kept = new Set<Task>(nonCompleted);
86
+ for (const t of all) {
87
+ if (kept.size >= innerBudget) break;
88
+ if (t.status === "completed") kept.add(t);
89
+ }
90
+ const visible = all.filter((t) => kept.has(t));
91
+ const shownCompleted = visible.filter((t) => t.status === "completed").length;
92
+ return { visible, hiddenCompleted: totalCompleted - shownCompleted, truncatedTail: 0 };
93
+ }
94
+ const visible = nonCompleted.slice(0, innerBudget);
95
+ const truncatedTail = nonCompleted.length - innerBudget;
96
+ return { visible, hiddenCompleted: totalCompleted, truncatedTail };
97
+ }
98
+
99
+ /**
100
+ * Helper: whether any visible task is `pending` or `in_progress`. The overlay
101
+ * uses this to pick the heading icon (`accent`+`●` vs `dim`+`○`).
102
+ */
103
+ export function selectHasActive(state: TaskState): boolean {
104
+ return selectVisibleTasks(state).some((t) => t.status === "in_progress" || t.status === "pending");
105
+ }
106
+
107
+ export const ACTIVE_STATUSES: ReadonlySet<TaskStatus> = new Set(["pending", "in_progress"]);
@@ -0,0 +1,326 @@
1
+ import type { Task, TaskAction, TaskMutationParams, TaskStatus } from "../tool/types.js";
2
+ import { isTransitionValid } from "./invariants.js";
3
+ import type { TaskState } from "./state.js";
4
+ import { detectCycle } from "./task-graph.js";
5
+
6
+ /**
7
+ * Reducer outcome. Closed tagged union — adding a new action requires extending
8
+ * this union AND the response-envelope's `formatContent` switch (compiler-
9
+ * enforced exhaustive). Mirrors the `Effect` pattern in
10
+ * `packages/rpiv-ask-user-question/state/state-reducer.ts:14-30`.
11
+ *
12
+ * `error` carries the message in-band so callers can pattern-match on
13
+ * `op.kind === "error"` without a side-channel boolean.
14
+ */
15
+ export type Op =
16
+ | { kind: "create"; ids: number[] }
17
+ | { kind: "update"; results: Array<{ id: number; fromStatus: TaskStatus; toStatus: TaskStatus }> }
18
+ | { kind: "delete"; items: Array<{ id: number; subject: string }> }
19
+ | { kind: "list"; statusFilter?: TaskStatus; includeDeleted: boolean }
20
+ | { kind: "get"; tasks: Task[] }
21
+ | { kind: "clear"; count: number }
22
+ | { kind: "batch"; results: Array<{ index: number; op: Exclude<Op, { kind: "batch" }> }> }
23
+ | { kind: "error"; message: string };
24
+
25
+ export interface ApplyResult {
26
+ state: TaskState;
27
+ op: Op;
28
+ }
29
+
30
+ function errorResult(state: TaskState, message: string): ApplyResult {
31
+ return { state, op: { kind: "error", message } };
32
+ }
33
+
34
+ /**
35
+ * Pure reducer: (state, action, params) → (state, op). Mirrors the
36
+ * `applyTaskMutation` of pre-refactor `todo.ts` minus content/details
37
+ * formatting; the response envelope (`tool/response-envelope.ts`) owns
38
+ * formatting, the store (`state/store.ts`) owns commit.
39
+ *
40
+ * Validation is in-line: structural guards (`subject required`, `id required`,
41
+ * `at least one mutable field`) plus state-aware checks (transition legality,
42
+ * dangling/deleted blockedBy, self-block, cycles). Decision: validation stays
43
+ * in-reducer — see Plan §Decisions §Decision 2.
44
+ */
45
+ export function applyTaskMutation(state: TaskState, action: TaskAction, params: TaskMutationParams): ApplyResult {
46
+ switch (action) {
47
+ case "create": {
48
+ // Plural path: subjects[]
49
+ if (params.subjects?.length) {
50
+ const subjects = params.subjects.filter((s): s is string => typeof s === "string" && s.trim().length > 0);
51
+ if (subjects.length === 0) return errorResult(state, "subjects[] requires at least one non-empty subject");
52
+
53
+ const createdIds: number[] = [];
54
+ let cursor = state;
55
+ for (const subject of subjects) {
56
+ const subResult = applyTaskMutation(cursor, "create", {
57
+ ...params,
58
+ subject,
59
+ subjects: undefined,
60
+ } as TaskMutationParams);
61
+ if (subResult.op.kind === "error") return subResult;
62
+ cursor = subResult.state;
63
+ if (subResult.op.kind === "create") createdIds.push(...subResult.op.ids);
64
+ }
65
+ return { state: cursor, op: { kind: "create", ids: createdIds } };
66
+ }
67
+ if (!params.subject?.trim()) {
68
+ return errorResult(state, "subject required for create");
69
+ }
70
+ if (params.blockedBy?.length) {
71
+ for (const dep of params.blockedBy) {
72
+ const depTask = state.tasks.find((t) => t.id === dep);
73
+ if (!depTask) return errorResult(state, `blockedBy: #${dep} not found`);
74
+ if (depTask.status === "deleted") return errorResult(state, `blockedBy: #${dep} is deleted`);
75
+ }
76
+ }
77
+ const newTask: Task = {
78
+ id: state.nextId,
79
+ subject: params.subject,
80
+ status: "pending",
81
+ };
82
+ if (params.description) newTask.description = params.description;
83
+ if (params.activeForm) newTask.activeForm = params.activeForm;
84
+ if (params.blockedBy?.length) newTask.blockedBy = [...params.blockedBy];
85
+ if (params.owner) newTask.owner = params.owner;
86
+ if (params.metadata) newTask.metadata = { ...params.metadata };
87
+
88
+ const newTasks = [...state.tasks, newTask];
89
+ return {
90
+ state: { tasks: newTasks, nextId: state.nextId + 1 },
91
+ op: { kind: "create", ids: [newTask.id] },
92
+ };
93
+ }
94
+
95
+ case "update": {
96
+ // Plural path: ids[]
97
+ if (params.ids?.length) {
98
+ const results: Array<{ id: number; fromStatus: TaskStatus; toStatus: TaskStatus }> = [];
99
+ let cursor = state;
100
+ for (const id of params.ids) {
101
+ const subResult = applyTaskMutation(cursor, "update", {
102
+ ...params,
103
+ id,
104
+ ids: undefined,
105
+ } as TaskMutationParams);
106
+ if (subResult.op.kind === "error") return subResult;
107
+ cursor = subResult.state;
108
+ if (subResult.op.kind === "update") results.push(subResult.op.results[0]);
109
+ }
110
+ return { state: cursor, op: { kind: "update", results } };
111
+ }
112
+ if (params.id === undefined) return errorResult(state, "id required for update");
113
+ const idx = state.tasks.findIndex((t) => t.id === params.id);
114
+ if (idx === -1) return errorResult(state, `#${params.id} not found`);
115
+ const current = state.tasks[idx];
116
+
117
+ const hasMutation =
118
+ params.subject !== undefined ||
119
+ params.description !== undefined ||
120
+ params.activeForm !== undefined ||
121
+ params.status !== undefined ||
122
+ params.owner !== undefined ||
123
+ params.metadata !== undefined ||
124
+ (params.addBlockedBy && params.addBlockedBy.length > 0) ||
125
+ (params.removeBlockedBy && params.removeBlockedBy.length > 0);
126
+ if (!hasMutation) return errorResult(state, "update requires at least one mutable field");
127
+
128
+ let newStatus = current.status;
129
+ if (params.status !== undefined) {
130
+ if (!isTransitionValid(current.status, params.status)) {
131
+ return errorResult(state, `illegal transition ${current.status} → ${params.status}`);
132
+ }
133
+ newStatus = params.status;
134
+ }
135
+
136
+ let newBlockedBy = current.blockedBy ? [...current.blockedBy] : [];
137
+ if (params.removeBlockedBy?.length) {
138
+ const toRemove = new Set(params.removeBlockedBy);
139
+ newBlockedBy = newBlockedBy.filter((dep) => !toRemove.has(dep));
140
+ }
141
+ if (params.addBlockedBy?.length) {
142
+ for (const dep of params.addBlockedBy) {
143
+ if (dep === current.id) return errorResult(state, `cannot block #${current.id} on itself`);
144
+ const depTask = state.tasks.find((t) => t.id === dep);
145
+ if (!depTask) return errorResult(state, `addBlockedBy: #${dep} not found`);
146
+ if (depTask.status === "deleted") return errorResult(state, `addBlockedBy: #${dep} is deleted`);
147
+ if (!newBlockedBy.includes(dep)) newBlockedBy.push(dep);
148
+ }
149
+ if (detectCycle(state.tasks, current.id, newBlockedBy)) {
150
+ return errorResult(state, "addBlockedBy would create a cycle in the blockedBy graph");
151
+ }
152
+ }
153
+
154
+ let newMetadata = current.metadata;
155
+ if (params.metadata !== undefined) {
156
+ const merged: Record<string, unknown> = { ...(current.metadata ?? {}) };
157
+ for (const [k, v] of Object.entries(params.metadata)) {
158
+ if (v === null) delete merged[k];
159
+ else merged[k] = v;
160
+ }
161
+ newMetadata = Object.keys(merged).length ? merged : undefined;
162
+ }
163
+
164
+ const updated: Task = { ...current, status: newStatus };
165
+ if (params.subject !== undefined) updated.subject = params.subject;
166
+ if (params.description !== undefined) updated.description = params.description;
167
+ if (params.activeForm !== undefined) updated.activeForm = params.activeForm;
168
+ if (params.owner !== undefined) updated.owner = params.owner;
169
+ if (newBlockedBy.length) updated.blockedBy = newBlockedBy;
170
+ else delete updated.blockedBy;
171
+ if (newMetadata === undefined) delete updated.metadata;
172
+ else updated.metadata = newMetadata;
173
+
174
+ const newTasks = [...state.tasks];
175
+ newTasks[idx] = updated;
176
+ return {
177
+ state: { tasks: newTasks, nextId: state.nextId },
178
+ op: { kind: "update", results: [{ id: updated.id, fromStatus: current.status, toStatus: newStatus }] },
179
+ };
180
+ }
181
+
182
+ case "list": {
183
+ return {
184
+ state,
185
+ op: {
186
+ kind: "list",
187
+ includeDeleted: params.includeDeleted === true,
188
+ ...(params.status !== undefined ? { statusFilter: params.status } : {}),
189
+ },
190
+ };
191
+ }
192
+
193
+ case "get": {
194
+ // Plural path: ids[]
195
+ if (params.ids?.length) {
196
+ const tasks: Task[] = [];
197
+ let cursor = state;
198
+ for (const id of params.ids) {
199
+ const subResult = applyTaskMutation(cursor, "get", {
200
+ ...params,
201
+ id,
202
+ ids: undefined,
203
+ } as TaskMutationParams);
204
+ if (subResult.op.kind === "error") return subResult;
205
+ cursor = subResult.state;
206
+ if (subResult.op.kind === "get") tasks.push(subResult.op.tasks[0]);
207
+ }
208
+ return { state: cursor, op: { kind: "get", tasks } };
209
+ }
210
+ if (params.id === undefined) return errorResult(state, "id required for get");
211
+ const task = state.tasks.find((t) => t.id === params.id);
212
+ if (!task) return errorResult(state, `#${params.id} not found`);
213
+ return { state, op: { kind: "get", tasks: [task] } };
214
+ }
215
+
216
+ case "delete": {
217
+ // Plural path: ids[]
218
+ if (params.ids?.length) {
219
+ const items: Array<{ id: number; subject: string }> = [];
220
+ let cursor = state;
221
+ for (const id of params.ids) {
222
+ const subResult = applyTaskMutation(cursor, "delete", {
223
+ ...params,
224
+ id,
225
+ ids: undefined,
226
+ } as TaskMutationParams);
227
+ if (subResult.op.kind === "error") return subResult;
228
+ cursor = subResult.state;
229
+ if (subResult.op.kind === "delete") items.push(subResult.op.items[0]);
230
+ }
231
+ return { state: cursor, op: { kind: "delete", items } };
232
+ }
233
+ if (params.id === undefined) return errorResult(state, "id required for delete");
234
+ const idx = state.tasks.findIndex((t) => t.id === params.id);
235
+ if (idx === -1) return errorResult(state, `#${params.id} not found`);
236
+ const current = state.tasks[idx];
237
+ if (current.status === "deleted") return errorResult(state, `#${current.id} is already deleted`);
238
+ const updated: Task = { ...current, status: "deleted" };
239
+ const newTasks = [...state.tasks];
240
+ newTasks[idx] = updated;
241
+ return {
242
+ state: { tasks: newTasks, nextId: state.nextId },
243
+ op: { kind: "delete", items: [{ id: updated.id, subject: updated.subject }] },
244
+ };
245
+ }
246
+
247
+ case "clear": {
248
+ const count = state.tasks.length;
249
+ return {
250
+ state: { tasks: [], nextId: 1 },
251
+ op: { kind: "clear", count },
252
+ };
253
+ }
254
+
255
+ case "batch": {
256
+ if (!params.items?.length) {
257
+ return errorResult(state, "batch requires at least one item in items[]");
258
+ }
259
+ type BatchOp = Exclude<Op, { kind: "batch" }>;
260
+ const results: Array<{ index: number; op: BatchOp }> = [];
261
+ let currentState = state;
262
+ const refRegistry = new Map<string, number>();
263
+
264
+ for (let i = 0; i < params.items.length; i++) {
265
+ const item = params.items[i];
266
+ const { action: itemAction, as: itemAs, refs: itemRefs, ...itemParams } = item;
267
+
268
+ // Validate "as" labels
269
+ if (itemAs?.length) {
270
+ if (itemAction !== "create") {
271
+ return errorResult(state, `batch item ${i}: "as" only valid for create actions`);
272
+ }
273
+ const taskCount = item.subjects?.length ?? 1;
274
+ if (itemAs.length !== taskCount) {
275
+ return errorResult(state, `batch item ${i}: "as" (${itemAs.length}) must match task count (${taskCount})`);
276
+ }
277
+ for (const label of itemAs) {
278
+ if (refRegistry.has(label)) {
279
+ return errorResult(state, `batch item ${i}: duplicate as label "${label}"`);
280
+ }
281
+ }
282
+ }
283
+
284
+ // Resolve "refs" → ids
285
+ if (itemRefs?.length) {
286
+ const resolvedIds: number[] = [];
287
+ for (const ref of itemRefs) {
288
+ const id = refRegistry.get(ref);
289
+ if (id === undefined) {
290
+ return errorResult(state, `batch item ${i}: ref "${ref}" not defined in earlier items`);
291
+ }
292
+ resolvedIds.push(id);
293
+ }
294
+ itemParams.ids = resolvedIds;
295
+ }
296
+
297
+ // Block list/get in batch (read-only ops)
298
+ if ((itemAction as string) === "list" || (itemAction as string) === "get") {
299
+ return errorResult(state, `batch item ${i}: action "${itemAction}" not allowed in batch (use list/get separately)`);
300
+ }
301
+
302
+ const sub = applyTaskMutation(currentState, itemAction, itemParams as TaskMutationParams);
303
+ if (sub.op.kind === "error") {
304
+ return errorResult(state, `batch item ${i} (${itemAction}): ${(sub.op as { kind: "error"; message: string }).message}`);
305
+ }
306
+ currentState = sub.state;
307
+
308
+ // Register "as" labels after successful create
309
+ if (itemAs?.length && sub.op.kind === "create") {
310
+ sub.op.ids.forEach((id, idx) => {
311
+ if (idx < itemAs.length) {
312
+ refRegistry.set(itemAs[idx], id);
313
+ }
314
+ });
315
+ }
316
+
317
+ results.push({ index: i, op: sub.op as BatchOp });
318
+ }
319
+
320
+ return {
321
+ state: currentState,
322
+ op: { kind: "batch", results },
323
+ };
324
+ }
325
+ }
326
+ }
@@ -0,0 +1,18 @@
1
+ import type { Task } from "../tool/types.js";
2
+
3
+ /**
4
+ * Canonical state for the todo tool. Single source of truth — both the reducer
5
+ * (`state/state-reducer.ts`) and the live store cell (`state/store.ts`) read
6
+ * this shape. Replay (`state/replay.ts`) returns a fresh `TaskState`; the
7
+ * lifecycle handlers in `index.ts` write it via `replaceState`.
8
+ *
9
+ * The shape is intentionally minimal — no derived caches or runtime cells.
10
+ * Selectors in `state/selectors.ts` are pure of `TaskState` and own all
11
+ * derivations (visible/grouped/counted/etc).
12
+ */
13
+ export interface TaskState {
14
+ tasks: Task[];
15
+ nextId: number;
16
+ }
17
+
18
+ export const EMPTY_STATE: TaskState = { tasks: [], nextId: 1 };