@mulmoclaude/core 5.12.0 → 5.13.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 (189) hide show
  1. package/assets/helps/presenthtml.md +18 -0
  2. package/assets/helps/spreadsheet.md +6 -6
  3. package/dist/artifacts/paths.cjs +1 -2
  4. package/dist/artifacts/paths.js +1 -2
  5. package/dist/collection/firestore.cjs +1 -2
  6. package/dist/collection/firestore.js +1 -2
  7. package/dist/collection/index.cjs +18 -30
  8. package/dist/collection/index.cjs.map +1 -1
  9. package/dist/collection/index.js +18 -30
  10. package/dist/collection/index.js.map +1 -1
  11. package/dist/collection/paths.cjs +1 -1
  12. package/dist/collection/paths.js +1 -1
  13. package/dist/collection/registry/index.cjs +1 -1
  14. package/dist/collection/registry/index.js +1 -1
  15. package/dist/collection/registry/server/index.cjs +17 -26
  16. package/dist/collection/registry/server/index.cjs.map +1 -1
  17. package/dist/collection/registry/server/index.js +16 -25
  18. package/dist/collection/registry/server/index.js.map +1 -1
  19. package/dist/collection/server/index.cjs +5 -5
  20. package/dist/collection/server/index.js +5 -5
  21. package/dist/collection-watchers/index.cjs +10 -14
  22. package/dist/collection-watchers/index.cjs.map +1 -1
  23. package/dist/collection-watchers/index.js +10 -14
  24. package/dist/collection-watchers/index.js.map +1 -1
  25. package/dist/{discovery-DBJRuDv2.cjs → discovery-CYIV1J5l.cjs} +25 -42
  26. package/dist/{discovery-DBJRuDv2.cjs.map → discovery-CYIV1J5l.cjs.map} +1 -1
  27. package/dist/{discovery-BTl21_hI.js → discovery-duLlygnJ.js} +24 -41
  28. package/dist/{discovery-BTl21_hI.js.map → discovery-duLlygnJ.js.map} +1 -1
  29. package/dist/{dist-CAc42oZn.cjs → dist-734JaRYi.cjs} +2 -4
  30. package/dist/dist-734JaRYi.cjs.map +1 -0
  31. package/dist/{dist-C0oU4X3A.js → dist-BmO4oSQy.js} +2 -4
  32. package/dist/dist-BmO4oSQy.js.map +1 -0
  33. package/dist/errorMessage-D0kR547_.cjs +1 -0
  34. package/dist/errorMessage-TpKxrmeo.js +1 -0
  35. package/dist/{errors-Dgiw-unK.js → errors-0QwjDxsv.js} +3 -4
  36. package/dist/{errors-Dgiw-unK.js.map → errors-0QwjDxsv.js.map} +1 -1
  37. package/dist/{errors-DQr4mDbJ.cjs → errors-B9mCEVG9.cjs} +3 -4
  38. package/dist/{errors-DQr4mDbJ.cjs.map → errors-B9mCEVG9.cjs.map} +1 -1
  39. package/dist/feeds/index.cjs +2 -2
  40. package/dist/feeds/index.js +2 -2
  41. package/dist/feeds/paths.cjs +2 -3
  42. package/dist/feeds/paths.js +1 -2
  43. package/dist/feeds/server/index.cjs +23 -37
  44. package/dist/feeds/server/index.cjs.map +1 -1
  45. package/dist/feeds/server/index.js +22 -36
  46. package/dist/feeds/server/index.js.map +1 -1
  47. package/dist/file-change/index.cjs +2 -3
  48. package/dist/file-change/index.js +1 -2
  49. package/dist/files/index.cjs +136 -11
  50. package/dist/files/index.cjs.map +1 -1
  51. package/dist/files/index.d.ts +1 -0
  52. package/dist/files/index.js +132 -12
  53. package/dist/files/index.js.map +1 -1
  54. package/dist/files/verified.d.ts +28 -0
  55. package/dist/global-config/index.cjs +3 -5
  56. package/dist/global-config/index.cjs.map +1 -1
  57. package/dist/global-config/index.js +3 -5
  58. package/dist/global-config/index.js.map +1 -1
  59. package/dist/google/index.cjs +38 -67
  60. package/dist/google/index.cjs.map +1 -1
  61. package/dist/google/index.js +37 -66
  62. package/dist/google/index.js.map +1 -1
  63. package/dist/{graph-CURotEkH.cjs → graph-BvVMZfDV.cjs} +6 -11
  64. package/dist/{graph-CURotEkH.cjs.map → graph-BvVMZfDV.cjs.map} +1 -1
  65. package/dist/{graph-DBxSOx3v.js → graph-DBbzemby.js} +6 -11
  66. package/dist/{graph-DBxSOx3v.js.map → graph-DBbzemby.js.map} +1 -1
  67. package/dist/{iconGlyph-fSBp6k4J.cjs → iconGlyph-CFOiFsmq.cjs} +2 -3
  68. package/dist/{iconGlyph-fSBp6k4J.cjs.map → iconGlyph-CFOiFsmq.cjs.map} +1 -1
  69. package/dist/{iconGlyph-D8JeNg7R.js → iconGlyph-D9h__VaM.js} +2 -3
  70. package/dist/{iconGlyph-D8JeNg7R.js.map → iconGlyph-D9h__VaM.js.map} +1 -1
  71. package/dist/{ingestTypes-DS9HiR2I.cjs → ingestTypes-CLDvn7kw.cjs} +3 -4
  72. package/dist/{ingestTypes-DS9HiR2I.cjs.map → ingestTypes-CLDvn7kw.cjs.map} +1 -1
  73. package/dist/{ingestTypes-Bs31Xt5c.js → ingestTypes-DuXuSBSn.js} +3 -4
  74. package/dist/{ingestTypes-Bs31Xt5c.js.map → ingestTypes-DuXuSBSn.js.map} +1 -1
  75. package/dist/{itemId-CVrNibwT.cjs → itemId-D2XAQ8RU.cjs} +9 -17
  76. package/dist/{itemId-CVrNibwT.cjs.map → itemId-D2XAQ8RU.cjs.map} +1 -1
  77. package/dist/{itemId-C9s-Jd5s.js → itemId-D_pSpa3U.js} +9 -17
  78. package/dist/{itemId-C9s-Jd5s.js.map → itemId-D_pSpa3U.js.map} +1 -1
  79. package/dist/{listen-CUJyj9V2.cjs → listen-OmfLDX1l.cjs} +3 -4
  80. package/dist/{listen-CUJyj9V2.cjs.map → listen-OmfLDX1l.cjs.map} +1 -1
  81. package/dist/{listen-CnLfYFdW.js → listen-uiEnXcW9.js} +3 -4
  82. package/dist/{listen-CnLfYFdW.js.map → listen-uiEnXcW9.js.map} +1 -1
  83. package/dist/notifier/index.cjs +1 -1
  84. package/dist/notifier/index.js +1 -1
  85. package/dist/{notifier-BF49QNV7.cjs → notifier-CRTk34EC.cjs} +6 -10
  86. package/dist/{notifier-BF49QNV7.cjs.map → notifier-CRTk34EC.cjs.map} +1 -1
  87. package/dist/{notifier-XGAgdX2J.js → notifier-htdf4ekH.js} +6 -10
  88. package/dist/{notifier-XGAgdX2J.js.map → notifier-htdf4ekH.js.map} +1 -1
  89. package/dist/{paths-CkJxNZ7T.js → paths-BMQNHdaJ.js} +2 -3
  90. package/dist/{paths-CkJxNZ7T.js.map → paths-BMQNHdaJ.js.map} +1 -1
  91. package/dist/{paths-C8-jxR0s.cjs → paths-DUHAueEv.cjs} +2 -3
  92. package/dist/{paths-C8-jxR0s.cjs.map → paths-DUHAueEv.cjs.map} +1 -1
  93. package/dist/plugin-vue/i18n.cjs +1 -2
  94. package/dist/plugin-vue/i18n.js +1 -2
  95. package/dist/plugin-vue/index.cjs +9 -17
  96. package/dist/plugin-vue/index.cjs.map +1 -1
  97. package/dist/plugin-vue/index.js +9 -17
  98. package/dist/plugin-vue/index.js.map +1 -1
  99. package/dist/{project-C1ep9pvo.cjs → project-DDTIVEMU.cjs} +2 -3
  100. package/dist/{project-C1ep9pvo.cjs.map → project-DDTIVEMU.cjs.map} +1 -1
  101. package/dist/{project-B0j_Vf_Q.js → project-mU6-xLfy.js} +2 -3
  102. package/dist/{project-B0j_Vf_Q.js.map → project-mU6-xLfy.js.map} +1 -1
  103. package/dist/prompt-files/index.cjs +4 -6
  104. package/dist/prompt-files/index.cjs.map +1 -1
  105. package/dist/prompt-files/index.js +3 -5
  106. package/dist/prompt-files/index.js.map +1 -1
  107. package/dist/{promptSafety-C9uabl9i.js → promptSafety-B8LECAkY.js} +14 -25
  108. package/dist/{promptSafety-C9uabl9i.js.map → promptSafety-B8LECAkY.js.map} +1 -1
  109. package/dist/{promptSafety-CKmqbSTK.cjs → promptSafety-CjxafW2b.cjs} +14 -25
  110. package/dist/{promptSafety-CKmqbSTK.cjs.map → promptSafety-CjxafW2b.cjs.map} +1 -1
  111. package/dist/{relPath-DW8MC8VO.js → relPath-BkKmqiiF.js} +2 -3
  112. package/dist/{relPath-DW8MC8VO.js.map → relPath-BkKmqiiF.js.map} +1 -1
  113. package/dist/{relPath-CTAjGdCL.cjs → relPath-CZiP2S_a.cjs} +3 -4
  114. package/dist/{relPath-CTAjGdCL.cjs.map → relPath-CZiP2S_a.cjs.map} +1 -1
  115. package/dist/remote-host/index.cjs +1 -1
  116. package/dist/remote-host/index.js +1 -1
  117. package/dist/remote-host/server/index.cjs +14 -25
  118. package/dist/remote-host/server/index.cjs.map +1 -1
  119. package/dist/remote-host/server/index.js +14 -25
  120. package/dist/remote-host/server/index.js.map +1 -1
  121. package/dist/{remote-host-BLWjSIZd.cjs → remote-host-BW_eH-Nu.cjs} +4 -6
  122. package/dist/{remote-host-BLWjSIZd.cjs.map → remote-host-BW_eH-Nu.cjs.map} +1 -1
  123. package/dist/{remote-host-5f5LOmDU.js → remote-host-CSeDNbE6.js} +4 -6
  124. package/dist/{remote-host-5f5LOmDU.js.map → remote-host-CSeDNbE6.js.map} +1 -1
  125. package/dist/remote-view/index.cjs +3 -4
  126. package/dist/remote-view/index.js +3 -4
  127. package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-CmQyd0Gu.cjs} +1 -2
  128. package/dist/{root-BvwBUcol.cjs → root-9lRFeXbm.cjs} +10 -6
  129. package/dist/{root-BvwBUcol.cjs.map → root-9lRFeXbm.cjs.map} +1 -1
  130. package/dist/{root-BcS4-Kge.js → root-CqxPNSyK.js} +4 -6
  131. package/dist/{root-BcS4-Kge.js.map → root-CqxPNSyK.js.map} +1 -1
  132. package/dist/scheduler/index.cjs +6 -9
  133. package/dist/scheduler/index.cjs.map +1 -1
  134. package/dist/scheduler/index.js +5 -8
  135. package/dist/scheduler/index.js.map +1 -1
  136. package/dist/{server-ekmEXF9t.cjs → server-ByKWGQn2.cjs} +25 -41
  137. package/dist/{server-ekmEXF9t.cjs.map → server-ByKWGQn2.cjs.map} +1 -1
  138. package/dist/{server-BdRkw2Gh.js → server-CA-alqqN.js} +24 -40
  139. package/dist/{server-BdRkw2Gh.js.map → server-CA-alqqN.js.map} +1 -1
  140. package/dist/skill-bridge/index.cjs +3 -4
  141. package/dist/skill-bridge/index.js +2 -3
  142. package/dist/{slug-BpjumQfe.js → slug-D24AYqCZ.js} +2 -3
  143. package/dist/{slug-BpjumQfe.js.map → slug-D24AYqCZ.js.map} +1 -1
  144. package/dist/{slug-JxgB0ru9.cjs → slug-DVkuPjIv.cjs} +2 -3
  145. package/dist/{slug-JxgB0ru9.cjs.map → slug-DVkuPjIv.cjs.map} +1 -1
  146. package/dist/{templatePath-27vUZowm.cjs → templatePath-BIh7wqgS.cjs} +2 -3
  147. package/dist/{templatePath-27vUZowm.cjs.map → templatePath-BIh7wqgS.cjs.map} +1 -1
  148. package/dist/{templatePath-k_WNbL_Q.js → templatePath-CB3wtVpe.js} +2 -3
  149. package/dist/{templatePath-k_WNbL_Q.js.map → templatePath-CB3wtVpe.js.map} +1 -1
  150. package/dist/{text-CjDbP2O1.js → text-BQAuwKVj.js} +2 -3
  151. package/dist/{text-CjDbP2O1.js.map → text-BQAuwKVj.js.map} +1 -1
  152. package/dist/{text-CaAh9ZSO.cjs → text-BQiyo5R9.cjs} +2 -3
  153. package/dist/{text-CaAh9ZSO.cjs.map → text-BQiyo5R9.cjs.map} +1 -1
  154. package/dist/translation/client.cjs +1 -2
  155. package/dist/translation/client.js +1 -2
  156. package/dist/{types-BKVZrtyc.js → types-BLCZTGW2.js} +4 -7
  157. package/dist/{types-BKVZrtyc.js.map → types-BLCZTGW2.js.map} +1 -1
  158. package/dist/{types-CNqkLT4M.cjs → types-DPycxnDf.cjs} +4 -7
  159. package/dist/{types-CNqkLT4M.cjs.map → types-DPycxnDf.cjs.map} +1 -1
  160. package/dist/utils/fetch.cjs +0 -1
  161. package/dist/utils/fetch.js +0 -1
  162. package/dist/utils/index.cjs +3 -3
  163. package/dist/utils/index.js +3 -3
  164. package/dist/whisper/client.cjs +2 -4
  165. package/dist/whisper/client.cjs.map +1 -1
  166. package/dist/whisper/client.js +2 -4
  167. package/dist/whisper/client.js.map +1 -1
  168. package/dist/whisper/index.cjs +9 -15
  169. package/dist/whisper/index.cjs.map +1 -1
  170. package/dist/whisper/index.js +8 -14
  171. package/dist/whisper/index.js.map +1 -1
  172. package/dist/wiki/index.cjs +5 -7
  173. package/dist/wiki/index.cjs.map +1 -1
  174. package/dist/wiki/index.js +5 -7
  175. package/dist/wiki/index.js.map +1 -1
  176. package/dist/wiki/paths.cjs +3 -4
  177. package/dist/wiki/paths.js +2 -3
  178. package/dist/wiki/server/index.cjs +7 -11
  179. package/dist/wiki/server/index.cjs.map +1 -1
  180. package/dist/wiki/server/index.js +6 -10
  181. package/dist/wiki/server/index.js.map +1 -1
  182. package/dist/workspace-setup/index.js +4 -9
  183. package/dist/workspace-setup/index.js.map +1 -1
  184. package/dist/workspace-setup/slug.js +1 -2
  185. package/package.json +5 -5
  186. package/dist/dist-C0oU4X3A.js.map +0 -1
  187. package/dist/dist-CAc42oZn.cjs.map +0 -1
  188. package/dist/errorMessage-BYNQlnx0.cjs +0 -1
  189. package/dist/errorMessage-DVcsvx02.js +0 -1
@@ -1,4 +1,4 @@
1
- //#region src/collection/core/project.ts
1
+ // src/collection/core/project.ts
2
2
  function withOnlyKeys(item, keep) {
3
3
  const pruned = { ...item };
4
4
  Reflect.ownKeys(pruned).filter((key) => typeof key !== "string" || !keep.has(key)).forEach((key) => Reflect.deleteProperty(pruned, key));
@@ -27,7 +27,6 @@ function mergeIntoExisting(existing, retrieved) {
27
27
  ...retrieved
28
28
  };
29
29
  }
30
- //#endregion
31
30
  Object.defineProperty(exports, "mergeIntoExisting", {
32
31
  enumerable: true,
33
32
  get: function() {
@@ -41,4 +40,4 @@ Object.defineProperty(exports, "projectRecordFields", {
41
40
  }
42
41
  });
43
42
 
44
- //# sourceMappingURL=project-C1ep9pvo.cjs.map
43
+ //# sourceMappingURL=project-DDTIVEMU.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"project-C1ep9pvo.cjs","names":[],"sources":["../src/collection/core/project.ts"],"sourcesContent":["// Field projection over records — the ONE implementation behind both the\n// server store layer (`server/storePage.ts#projectItemFields`) and the\n// remote-view page builder (`remote-view#projectItems`). Isomorphic and\n// dependency-free so either side can import it; extracted to kill the\n// jscpd duplicate the two copies were.\n\n// Pruning a shallow copy keeps the caller's record type; rebuilding the object\n// from `Object.entries` would only ever be a `Record<string, unknown>`.\n// `Reflect.ownKeys` rather than `Object.keys` because the spread also copies\n// enumerable SYMBOL keys, and a symbol can never be one of the requested\n// `fields` — leaving it would return data the caller did not select.\nfunction withOnlyKeys<T extends Record<string, unknown>>(item: T, keep: Set<string>): T {\n const pruned = { ...item };\n Reflect.ownKeys(pruned)\n .filter((key) => typeof key !== \"string\" || !keep.has(key))\n .forEach((key) => Reflect.deleteProperty(pruned, key));\n return pruned;\n}\n\n/** Keep only `fields` (+ `primaryKey`, always) on each record. No `fields`\n * ⇒ records pass through untouched. */\nexport function projectRecordFields<T extends Record<string, unknown>>(items: T[], fields: readonly string[] | undefined, primaryKey: string): T[] {\n if (!fields) return items;\n const keep = new Set([primaryKey, ...fields]);\n return items.map((item) => withOnlyKeys(item, keep));\n}\n\n/** Retrieved values laid over whatever the record already holds.\n *\n * A record file is written whole (`writeItem`), so writing the retrieved item\n * alone would drop every column the retrieval does not produce — a collection\n * could not then carry a local note beside a mirrored item, because the next\n * refresh that touched it would silently delete the note. The retrieved values\n * still win on the fields they cover: those belong to the source.\n *\n * Shared by the Google Calendar pull (#2620) and the feeds ingest (#2696),\n * which had the same bug and only one of the fixes. */\n// Deliberately NOT generic over the record shape: inferring one type from\n// `retrieved` would force `existing` to match it, and \"the stored record has\n// keys the retrieval does not\" is the entire case this exists for.\nexport function mergeIntoExisting(existing: Record<string, unknown> | null, retrieved: Record<string, unknown>): Record<string, unknown> {\n return { ...(existing ?? {}), ...retrieved };\n}\n"],"mappings":";AAWA,SAAS,aAAgD,MAAS,MAAsB;CACtF,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,QAAQ,QAAQ,MAAM,CAAC,CACpB,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAC1D,SAAS,QAAQ,QAAQ,eAAe,QAAQ,GAAG,CAAC;CACvD,OAAO;AACT;;;AAIA,SAAgB,oBAAuD,OAAY,QAAuC,YAAyB;CACjJ,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,uBAAO,IAAI,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;CAC5C,OAAO,MAAM,KAAK,SAAS,aAAa,MAAM,IAAI,CAAC;AACrD;;;;;;;;;;;AAeA,SAAgB,kBAAkB,UAA0C,WAA6D;CACvI,OAAO;EAAE,GAAI,YAAY,CAAC;EAAI,GAAG;CAAU;AAC7C"}
1
+ {"version":3,"file":"project-DDTIVEMU.cjs","names":[],"sources":["../src/collection/core/project.ts"],"sourcesContent":["// Field projection over records — the ONE implementation behind both the\n// server store layer (`server/storePage.ts#projectItemFields`) and the\n// remote-view page builder (`remote-view#projectItems`). Isomorphic and\n// dependency-free so either side can import it; extracted to kill the\n// jscpd duplicate the two copies were.\n\n// Pruning a shallow copy keeps the caller's record type; rebuilding the object\n// from `Object.entries` would only ever be a `Record<string, unknown>`.\n// `Reflect.ownKeys` rather than `Object.keys` because the spread also copies\n// enumerable SYMBOL keys, and a symbol can never be one of the requested\n// `fields` — leaving it would return data the caller did not select.\nfunction withOnlyKeys<T extends Record<string, unknown>>(item: T, keep: Set<string>): T {\n const pruned = { ...item };\n Reflect.ownKeys(pruned)\n .filter((key) => typeof key !== \"string\" || !keep.has(key))\n .forEach((key) => Reflect.deleteProperty(pruned, key));\n return pruned;\n}\n\n/** Keep only `fields` (+ `primaryKey`, always) on each record. No `fields`\n * ⇒ records pass through untouched. */\nexport function projectRecordFields<T extends Record<string, unknown>>(items: T[], fields: readonly string[] | undefined, primaryKey: string): T[] {\n if (!fields) return items;\n const keep = new Set([primaryKey, ...fields]);\n return items.map((item) => withOnlyKeys(item, keep));\n}\n\n/** Retrieved values laid over whatever the record already holds.\n *\n * A record file is written whole (`writeItem`), so writing the retrieved item\n * alone would drop every column the retrieval does not produce — a collection\n * could not then carry a local note beside a mirrored item, because the next\n * refresh that touched it would silently delete the note. The retrieved values\n * still win on the fields they cover: those belong to the source.\n *\n * Shared by the Google Calendar pull (#2620) and the feeds ingest (#2696),\n * which had the same bug and only one of the fixes. */\n// Deliberately NOT generic over the record shape: inferring one type from\n// `retrieved` would force `existing` to match it, and \"the stored record has\n// keys the retrieval does not\" is the entire case this exists for.\nexport function mergeIntoExisting(existing: Record<string, unknown> | null, retrieved: Record<string, unknown>): Record<string, unknown> {\n return { ...(existing ?? {}), ...retrieved };\n}\n"],"mappings":";AAWA,SAAS,aAAgD,MAAS,MAAsB;CACtF,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,QAAQ,QAAQ,MAAM,CAAC,CACpB,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAC1D,SAAS,QAAQ,QAAQ,eAAe,QAAQ,GAAG,CAAC;CACvD,OAAO;AACT;;;AAIA,SAAgB,oBAAuD,OAAY,QAAuC,YAAyB;CACjJ,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,uBAAO,IAAI,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;CAC5C,OAAO,MAAM,KAAK,SAAS,aAAa,MAAM,IAAI,CAAC;AACrD;;;;;;;;;;;AAeA,SAAgB,kBAAkB,UAA0C,WAA6D;CACvI,OAAO;EAAE,GAAI,YAAY,CAAC;EAAI,GAAG;CAAU;AAC7C"}
@@ -1,4 +1,4 @@
1
- //#region src/collection/core/project.ts
1
+ // src/collection/core/project.ts
2
2
  function withOnlyKeys(item, keep) {
3
3
  const pruned = { ...item };
4
4
  Reflect.ownKeys(pruned).filter((key) => typeof key !== "string" || !keep.has(key)).forEach((key) => Reflect.deleteProperty(pruned, key));
@@ -27,7 +27,6 @@ function mergeIntoExisting(existing, retrieved) {
27
27
  ...retrieved
28
28
  };
29
29
  }
30
- //#endregion
31
30
  export { projectRecordFields as n, mergeIntoExisting as t };
32
31
 
33
- //# sourceMappingURL=project-B0j_Vf_Q.js.map
32
+ //# sourceMappingURL=project-mU6-xLfy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project-B0j_Vf_Q.js","names":[],"sources":["../src/collection/core/project.ts"],"sourcesContent":["// Field projection over records — the ONE implementation behind both the\n// server store layer (`server/storePage.ts#projectItemFields`) and the\n// remote-view page builder (`remote-view#projectItems`). Isomorphic and\n// dependency-free so either side can import it; extracted to kill the\n// jscpd duplicate the two copies were.\n\n// Pruning a shallow copy keeps the caller's record type; rebuilding the object\n// from `Object.entries` would only ever be a `Record<string, unknown>`.\n// `Reflect.ownKeys` rather than `Object.keys` because the spread also copies\n// enumerable SYMBOL keys, and a symbol can never be one of the requested\n// `fields` — leaving it would return data the caller did not select.\nfunction withOnlyKeys<T extends Record<string, unknown>>(item: T, keep: Set<string>): T {\n const pruned = { ...item };\n Reflect.ownKeys(pruned)\n .filter((key) => typeof key !== \"string\" || !keep.has(key))\n .forEach((key) => Reflect.deleteProperty(pruned, key));\n return pruned;\n}\n\n/** Keep only `fields` (+ `primaryKey`, always) on each record. No `fields`\n * ⇒ records pass through untouched. */\nexport function projectRecordFields<T extends Record<string, unknown>>(items: T[], fields: readonly string[] | undefined, primaryKey: string): T[] {\n if (!fields) return items;\n const keep = new Set([primaryKey, ...fields]);\n return items.map((item) => withOnlyKeys(item, keep));\n}\n\n/** Retrieved values laid over whatever the record already holds.\n *\n * A record file is written whole (`writeItem`), so writing the retrieved item\n * alone would drop every column the retrieval does not produce — a collection\n * could not then carry a local note beside a mirrored item, because the next\n * refresh that touched it would silently delete the note. The retrieved values\n * still win on the fields they cover: those belong to the source.\n *\n * Shared by the Google Calendar pull (#2620) and the feeds ingest (#2696),\n * which had the same bug and only one of the fixes. */\n// Deliberately NOT generic over the record shape: inferring one type from\n// `retrieved` would force `existing` to match it, and \"the stored record has\n// keys the retrieval does not\" is the entire case this exists for.\nexport function mergeIntoExisting(existing: Record<string, unknown> | null, retrieved: Record<string, unknown>): Record<string, unknown> {\n return { ...(existing ?? {}), ...retrieved };\n}\n"],"mappings":";AAWA,SAAS,aAAgD,MAAS,MAAsB;CACtF,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,QAAQ,QAAQ,MAAM,CAAC,CACpB,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAC1D,SAAS,QAAQ,QAAQ,eAAe,QAAQ,GAAG,CAAC;CACvD,OAAO;AACT;;;AAIA,SAAgB,oBAAuD,OAAY,QAAuC,YAAyB;CACjJ,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,uBAAO,IAAI,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;CAC5C,OAAO,MAAM,KAAK,SAAS,aAAa,MAAM,IAAI,CAAC;AACrD;;;;;;;;;;;AAeA,SAAgB,kBAAkB,UAA0C,WAA6D;CACvI,OAAO;EAAE,GAAI,YAAY,CAAC;EAAI,GAAG;CAAU;AAC7C"}
1
+ {"version":3,"file":"project-mU6-xLfy.js","names":[],"sources":["../src/collection/core/project.ts"],"sourcesContent":["// Field projection over records — the ONE implementation behind both the\n// server store layer (`server/storePage.ts#projectItemFields`) and the\n// remote-view page builder (`remote-view#projectItems`). Isomorphic and\n// dependency-free so either side can import it; extracted to kill the\n// jscpd duplicate the two copies were.\n\n// Pruning a shallow copy keeps the caller's record type; rebuilding the object\n// from `Object.entries` would only ever be a `Record<string, unknown>`.\n// `Reflect.ownKeys` rather than `Object.keys` because the spread also copies\n// enumerable SYMBOL keys, and a symbol can never be one of the requested\n// `fields` — leaving it would return data the caller did not select.\nfunction withOnlyKeys<T extends Record<string, unknown>>(item: T, keep: Set<string>): T {\n const pruned = { ...item };\n Reflect.ownKeys(pruned)\n .filter((key) => typeof key !== \"string\" || !keep.has(key))\n .forEach((key) => Reflect.deleteProperty(pruned, key));\n return pruned;\n}\n\n/** Keep only `fields` (+ `primaryKey`, always) on each record. No `fields`\n * ⇒ records pass through untouched. */\nexport function projectRecordFields<T extends Record<string, unknown>>(items: T[], fields: readonly string[] | undefined, primaryKey: string): T[] {\n if (!fields) return items;\n const keep = new Set([primaryKey, ...fields]);\n return items.map((item) => withOnlyKeys(item, keep));\n}\n\n/** Retrieved values laid over whatever the record already holds.\n *\n * A record file is written whole (`writeItem`), so writing the retrieved item\n * alone would drop every column the retrieval does not produce — a collection\n * could not then carry a local note beside a mirrored item, because the next\n * refresh that touched it would silently delete the note. The retrieved values\n * still win on the fields they cover: those belong to the source.\n *\n * Shared by the Google Calendar pull (#2620) and the feeds ingest (#2696),\n * which had the same bug and only one of the fixes. */\n// Deliberately NOT generic over the record shape: inferring one type from\n// `retrieved` would force `existing` to match it, and \"the stored record has\n// keys the retrieval does not\" is the entire case this exists for.\nexport function mergeIntoExisting(existing: Record<string, unknown> | null, retrieved: Record<string, unknown>): Record<string, unknown> {\n return { ...(existing ?? {}), ...retrieved };\n}\n"],"mappings":";AAWA,SAAS,aAAgD,MAAS,MAAsB;CACtF,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,QAAQ,QAAQ,MAAM,CAAC,CACpB,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAC1D,SAAS,QAAQ,QAAQ,eAAe,QAAQ,GAAG,CAAC;CACvD,OAAO;AACT;;;AAIA,SAAgB,oBAAuD,OAAY,QAAuC,YAAyB;CACjJ,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,uBAAO,IAAI,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;CAC5C,OAAO,MAAM,KAAK,SAAS,aAAa,MAAM,IAAI,CAAC;AACrD;;;;;;;;;;;AAeA,SAAgB,kBAAkB,UAA0C,WAA6D;CACvI,OAAO;EAAE,GAAI,YAAY,CAAC;EAAI,GAAG;CAAU;AAC7C"}
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("../rolldown-runtime-VH7oDXx4.cjs");
3
- const require_dist = require("../dist-CAc42oZn.cjs");
2
+ const require_rolldown_runtime = require("../rolldown-runtime-CmQyd0Gu.cjs");
3
+ const require_dist = require("../dist-734JaRYi.cjs");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
6
6
  node_path = require_rolldown_runtime.__toESM(node_path, 1);
7
7
  let node_crypto = require("node:crypto");
8
- //#region src/prompt-files/split.ts
8
+ // src/prompt-files/split.ts
9
9
  /** Replaced in `promptCompact` with the directory the agent reads the files
10
10
  * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in
11
11
  * MulmoTerminal). */
@@ -97,8 +97,7 @@ function renderToolPrompt(definition, agentFilesDir) {
97
97
  if (!split || agentFilesDir === null) return fullPrompt;
98
98
  return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);
99
99
  }
100
- //#endregion
101
- //#region src/prompt-files/sync.ts
100
+ // src/prompt-files/sync.ts
102
101
  function mergeFiles(target, files) {
103
102
  for (const [name, content] of Object.entries(files)) {
104
103
  if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;
@@ -196,7 +195,6 @@ function syncPromptFiles(root, sources) {
196
195
  problems
197
196
  };
198
197
  }
199
- //#endregion
200
198
  exports.PROMPT_FILES_DIR_PLACEHOLDER = PROMPT_FILES_DIR_PLACEHOLDER;
201
199
  exports.collectPackageFiles = collectPackageFiles;
202
200
  exports.isSafePromptFileName = isSafePromptFileName;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isRecord","path","randomUUID","existsSync","lstatSync"],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC;AACtE;;;;AAKA,SAAgB,kBAAkB,aAAoC;CACpE,MAAM,WAAW,YAAY,MAAM,GAAG;CACtC,IAAI,SAAS,WAAW,GAAG,OAAO,aAAa,KAAK,WAAW,IAAI,cAAc;CACjF,MAAM,CA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,eAAe,GAAG,MAAM,IAAI,MAAM,GAAG,OAAO,cAAc;AAE1G;;;AAIA,SAAS,gBAAgB,MAAc,QAAgB,OAA+C;CACpG,wBAAwB,MAAM,MAAM;CACpC,MAAM,SAASH,UAAAA,QAAK,KAAK,MAAM,GAAG,OAAO,MAAM,GAAG,CAAC;CACnD,MAAM,UAAU,GAAG,OAAO,QAAA,GAAOC,YAAAA,WAAAA,CAAW;CAC5C,IAAI;EACF,aAAa,SAAS,KAAK;EAC3B,OAAO,SAAS,MAAM;CACxB,UAAU;EACR,CAAA,GAAA,QAAA,OAAA,CAAO,SAAS;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CAClD;AACF;AAEA,SAAgB,gBAAgB,MAAc,SAA8D;CAC1G,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,WAA8C,CAAC;CACrD,KAAK,MAAM,CAAC,aAAa,UAAU,oBAAoB,OAAO,GAAG;EAC/D,MAAM,SAAS,kBAAkB,WAAW;EAC5C,IAAI,CAAC,QAAQ,SAAS,KAAK;GAAE;GAAa,SAAS;EAA4C,CAAC;OAC3F,IAAI,aAAa,OAAO,SAAS,KAAK;GAAE;GAAa,SAAS,MAAM;EAAQ,CAAC;OAEhF,IAAI;GACF,gBAAgB,MAAM,QAAQ,MAAM,KAAK;GACzC,QAAQ,IAAI,aAAa,MAAM;EACjC,SAAS,KAAK;GACZ,SAAS,KAAK;IAAE;IAAa,SAAS,mBAAmBD,UAAAA,QAAK,KAAK,MAAM,MAAM,EAAE,IAAI,OAAO,GAAG;GAAI,CAAC;EACtG;CAEJ;CACA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
1
+ {"version":3,"file":"index.cjs","names":["isRecord","path","randomUUID","existsSync","lstatSync"],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,K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0oU4X3A.js";
1
+ import { c as isRecord } from "../dist-BmO4oSQy.js";
2
2
  import { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
- //#region src/prompt-files/split.ts
5
+ // src/prompt-files/split.ts
6
6
  /** Replaced in `promptCompact` with the directory the agent reads the files
7
7
  * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in
8
8
  * MulmoTerminal). */
@@ -94,8 +94,7 @@ function renderToolPrompt(definition, agentFilesDir) {
94
94
  if (!split || agentFilesDir === null) return fullPrompt;
95
95
  return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);
96
96
  }
97
- //#endregion
98
- //#region src/prompt-files/sync.ts
97
+ // src/prompt-files/sync.ts
99
98
  function mergeFiles(target, files) {
100
99
  for (const [name, content] of Object.entries(files)) {
101
100
  if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;
@@ -193,7 +192,6 @@ function syncPromptFiles(root, sources) {
193
192
  problems
194
193
  };
195
194
  }
196
- //#endregion
197
195
  export { PROMPT_FILES_DIR_PLACEHOLDER, collectPackageFiles, isSafePromptFileName, promptFilesSubdir, readPromptSplit, referencedPromptFiles, renderToolPrompt, syncPromptFiles };
198
196
 
199
197
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC;AACtE;;;;AAKA,SAAgB,kBAAkB,aAAoC;CACpE,MAAM,WAAW,YAAY,MAAM,GAAG;CACtC,IAAI,SAAS,WAAW,GAAG,OAAO,aAAa,KAAK,WAAW,IAAI,cAAc;CACjF,MAAM,CAAC,QAAQ,IAAI,OAAO,MAA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WAAW;GAAM,OAAO;EAAK,CAAC;CAClD;AACF;AAEA,SAAgB,gBAAgB,MAAc,SAA8D;CAC1G,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,WAA8C,CAAC;CACrD,KAAK,MAAM,CAAC,aAAa,UAAU,oBAAoB,OAAO,GAAG;EAC/D,MAAM,SAAS,kBAAkB,WAAW;EAC5C,IAAI,CAAC,QAAQ,SAAS,KAAK;GAAE;GAAa,SAAS;EAA4C,CAAC;OAC3F,IAAI,aAAa,OAAO,SAAS,KAAK;GAAE;GAAa,SAAS,MAAM;EAAQ,CAAC;OAEhF,IAAI;GACF,gBAAgB,MAAM,QAAQ,MAAM,KAAK;GACzC,QAAQ,IAAI,aAAa,MAAM;EACjC,SAAS,KAAK;GACZ,SAAS,KAAK;IAAE;IAAa,SAAS,mBAAmB,KAAK,KAAK,MAAM,MAAM,EAAE,IAAI,OAAO,GAAG;GAAI,CAAC;EACtG;CAEJ;CACA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC;AACtE;;;;AAKA,SAAgB,kBAAkB,aAAoC;CACpE,MAAM,WAAW,YAAY,MAAM,GAAG;CACtC,IAAI,SAAS,WAAW,GAAG,OAAO,aAAa,KAAK,WAAW,IAAI,cAAc;CACjF,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM;CAEhC,OADiB,SAAS,WAAW,KAAK,MAAM,WAAW,GAAG,KAAK,aAAa,KAAK,MAAM,MAAM,CAAC,CAAC,KAAK,aAAa,KAAK,IAAI,IAC5G,cAAc;AAClC;AAEA,SAAS,eAAe,OAAiD;CACvE,OAAO,SAAS,KAAK,KAAK,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,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C,IAAI,CAAC,QAAQ,SAAS,KAAK;GAAE;GAAa,SAAS;EAA4C,CAAC;OAC3F,IAAI,aAAa,OAAO,SAAS,KAAK;GAAE;GAAa,SAAS,MAAM;EAAQ,CAAC;OAEhF,IAAI;GACF,gBAAgB,MAAM,QAAQ,MAAM,KAAK;GACzC,QAAQ,IAAI,aAAa,MAAM;EACjC,SAAS,KAAK;GACZ,SAAS,KAAK;IAAE;IAAa,SAAS,mBAAmB,KAAK,KAAK,MAAM,MAAM,EAAE,IAAI,OAAO,GAAG;GAAI,CAAC;EACtG;CAEJ;CACA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
@@ -1,6 +1,6 @@
1
- import { c as isRecord, o as isObj, u as isUnknownArray } from "./dist-C0oU4X3A.js";
2
- import { $ as fieldText, et as fieldTextOrNull } from "./itemId-C9s-Jd5s.js";
3
- //#region src/collection/core/fieldDefaults.ts
1
+ import { c as isRecord, o as isObj, u as isUnknownArray } from "./dist-BmO4oSQy.js";
2
+ import { $ as fieldText, et as fieldTextOrNull } from "./itemId-D_pSpa3U.js";
3
+ // src/collection/core/fieldDefaults.ts
4
4
  /** The starting value for a field, or null when it declares none.
5
5
  *
6
6
  * A `default` outside `values` resolves to null rather than being handed on.
@@ -40,8 +40,7 @@ function firstUnknownDefault(schema) {
40
40
  }
41
41
  return null;
42
42
  }
43
- //#endregion
44
- //#region src/collection/core/actionVisible.ts
43
+ // src/collection/core/actionVisible.ts
45
44
  /** Core matcher:
46
45
  * - no `when` ⇒ always true (visible);
47
46
  * - otherwise true only when `record[when.field]` is present and its
@@ -78,8 +77,7 @@ function agentActionRunKey(actionId, itemId) {
78
77
  function fieldVisible(field, record) {
79
78
  return whenMatches(field.when, record);
80
79
  }
81
- //#endregion
82
- //#region src/collection/core/backlinks.ts
80
+ // src/collection/core/backlinks.ts
83
81
  /** Does `item` reference `recordId` through `via`? Three shapes, tried in
84
82
  * order so the dotted form never regresses an existing flat key:
85
83
  *
@@ -165,8 +163,7 @@ function rollupValue(spec, recordId, sourceItems) {
165
163
  }
166
164
  return total;
167
165
  }
168
- //#endregion
169
- //#region src/collection/core/linkTargets.ts
166
+ // src/collection/core/linkTargets.ts
170
167
  /** Slugs of every collection referenced by a `ref` field — top-level and
171
168
  * one level into `table` sub-fields (nested tables are schema-rejected,
172
169
  * so a single recursion suffices). */
@@ -226,8 +223,7 @@ function linkedSlugsForFields(schema, fields) {
226
223
  if (requested.some(readsEveryLink)) return allLinkedSlugs(schema);
227
224
  return [...new Set(requested.map(directLinkOf).filter((slug) => slug !== null))];
228
225
  }
229
- //#endregion
230
- //#region src/collection/core/where.ts
226
+ // src/collection/core/where.ts
231
227
  /** True when `record[field]` is absent (`undefined`/`null`) — the only case
232
228
  * where `ne` and every other op disagree on the result. */
233
229
  function isMissing(raw) {
@@ -317,8 +313,7 @@ function matchesCond(cond, record, recordsById) {
317
313
  function matchesWhere(where, record, recordsById = {}) {
318
314
  return where.every((cond) => matchesCond(cond, record, recordsById));
319
315
  }
320
- //#endregion
321
- //#region src/collection/core/completion.ts
316
+ // src/collection/core/completion.ts
322
317
  /** True iff the schema declares completion tracking AND `item` is done
323
318
  * under whichever completion form the schema uses (see module doc). */
324
319
  function itemIsDone(schema, item) {
@@ -370,8 +365,7 @@ function chipMatches(chip, schema, item, deriveRecord) {
370
365
  if (field?.type === "boolean") return item[chip.key] === true;
371
366
  return flagFieldValue(deriveRecord(item), chip.key);
372
367
  }
373
- //#endregion
374
- //#region src/collection/core/dynamicIcon.ts
368
+ // src/collection/core/dynamicIcon.ts
375
369
  /** The record with the greatest `String(record[field])` (localeCompare) —
376
370
  * ties keep the first-seen record (stable left-to-right `reduce`). */
377
371
  function latestByField(pool, field) {
@@ -415,8 +409,7 @@ var isDateLikeField = (field) => field.type === "date" || field.type === "dateti
415
409
  function firstDateField(schema) {
416
410
  return Object.entries(schema.fields).find(([, field]) => isDateLikeField(field))?.[0];
417
411
  }
418
- //#endregion
419
- //#region src/collection/core/derivedFormula.ts
412
+ // src/collection/core/derivedFormula.ts
420
413
  function evaluateDerived(formula, ctx) {
421
414
  let tokens;
422
415
  try {
@@ -745,8 +738,7 @@ function toFiniteNumber(value) {
745
738
  }
746
739
  return NaN;
747
740
  }
748
- //#endregion
749
- //#region src/collection/core/ownProp.ts
741
+ // src/collection/core/ownProp.ts
750
742
  /** Read `obj[key]` only when it is an OWN property. A bare `obj[key]` reaches
751
743
  * inherited Object.prototype members, so a dangling ref/embed id like
752
744
  * `"constructor"` or `"__proto__"` resolves to a prototype value (the
@@ -758,8 +750,7 @@ function toFiniteNumber(value) {
758
750
  function ownProp(obj, key) {
759
751
  return Object.hasOwn(obj, key) ? obj[key] : void 0;
760
752
  }
761
- //#endregion
762
- //#region src/collection/core/deriveAll.ts
753
+ // src/collection/core/deriveAll.ts
763
754
  /** Map each `ref` field's stored slug to its loaded target record (or
764
755
  * null when dangling / not loaded), keyed by the LOCAL field name —
765
756
  * the shape `evaluateDerived` reads for `<field>.<col>` derefs. */
@@ -822,14 +813,12 @@ function deriveAll(schema, base, refRecords) {
822
813
  }
823
814
  return enriched;
824
815
  }
825
- //#endregion
826
- //#region src/collection/core/promptSafety.ts
816
+ // src/collection/core/promptSafety.ts
827
817
  /** Max chars kept — the first batch of a validation issue is enough to act on. */
828
818
  var DEFANG_MAX_LEN = 200;
829
819
  function defangForPrompt(value) {
830
820
  return value.replace(/[<>]/g, "").replace(/`/g, "'").replace(/\$\{/g, "$ {").replace(/\s+/g, " ").slice(0, DEFANG_MAX_LEN);
831
821
  }
832
- //#endregion
833
822
  export { schemaDefaults as A, viaMatches as C, whenMatches as D, fieldVisible as E, fieldDefaultValue as O, rollupValue as S, agentActionRunKey as T, uniqueEmbedTargets as _, evaluateDerived as a, coerceNumeric as b, selectDynamicRecord as c, flagFieldValue as d, itemIsDone as f, uniqueBacklinkSources as g, linkedSlugsForFields as h, ownProp as i, firstUnknownDefault as k, chipMatches as l, matchesWhere as m, deriveAll as n, firstDateField as o, toggleChecked as p, resolveRowRefs as r, resolveIcon as s, defangForPrompt as t, completionCoveredByFieldChip as u, uniqueRefTargets as v, actionVisible as w, projectBacklinkRow as x, backlinkRows as y };
834
823
 
835
- //# sourceMappingURL=promptSafety-C9uabl9i.js.map
824
+ //# sourceMappingURL=promptSafety-B8LECAkY.js.map