@patodo/localapp 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 (527) hide show
  1. package/.localapp-artifact.json +2731 -0
  2. package/LICENSE +21 -0
  3. package/README.md +288 -0
  4. package/bin/localapp.mjs +34182 -0
  5. package/package.json +21 -0
  6. package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
  7. package/runtime/native/adapter-manifest.json +85 -0
  8. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
  9. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  10. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  11. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  12. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
  13. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  14. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  15. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  16. package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
  17. package/runtime/native/linux-x64/localapp-notifications +0 -0
  18. package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
  19. package/runtime/native/win32-x64/localapp-native.exe +0 -0
  20. package/runtime/server/.localapp-server-runtime.json +133 -0
  21. package/runtime/server/bin/server-cli.cjs +8343 -0
  22. package/runtime/server/bin/server.mjs +8 -0
  23. package/runtime/server/bin/worker.cjs +144339 -0
  24. package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
  25. package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
  26. package/runtime/server/node_modules/sql.js/package.json +58 -0
  27. package/runtime/server/package.json +11 -0
  28. package/runtime/server/runner/localapp-runner.mjs +324 -0
  29. package/runtime/server/web/404.html +1 -0
  30. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
  31. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
  32. package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
  33. package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
  34. package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
  35. package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
  36. package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
  37. package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
  38. package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
  39. package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
  40. package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
  41. package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
  42. package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
  43. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
  44. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
  45. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
  46. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
  47. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
  48. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
  49. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
  50. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
  51. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
  52. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
  53. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
  54. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
  55. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
  56. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
  57. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
  58. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
  59. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
  60. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
  61. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
  62. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
  63. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
  64. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
  65. package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
  66. package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
  67. package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
  68. package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
  69. package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
  70. package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
  71. package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
  72. package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
  73. package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
  74. package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
  75. package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
  76. package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  77. package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
  78. package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
  79. package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
  80. package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
  81. package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
  82. package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
  83. package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
  84. package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
  85. package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
  86. package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
  87. package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
  88. package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
  89. package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
  90. package/runtime/server/web/home/redline-launch-hero.png +0 -0
  91. package/runtime/server/web/inbox.html +1 -0
  92. package/runtime/server/web/inbox.txt +27 -0
  93. package/runtime/server/web/index.html +1 -0
  94. package/runtime/server/web/index.txt +27 -0
  95. package/runtime/server/web/my/analytics.html +1 -0
  96. package/runtime/server/web/my/analytics.txt +27 -0
  97. package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
  98. package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
  99. package/runtime/server/web/my/apps.html +1 -0
  100. package/runtime/server/web/my/apps.txt +27 -0
  101. package/runtime/server/web/my/dashboard.html +1 -0
  102. package/runtime/server/web/my/dashboard.txt +27 -0
  103. package/runtime/server/web/my/device-actions.html +1 -0
  104. package/runtime/server/web/my/device-actions.txt +24 -0
  105. package/runtime/server/web/my/device-notifications.html +1 -0
  106. package/runtime/server/web/my/device-notifications.txt +24 -0
  107. package/runtime/server/web/my/favorites.html +1 -0
  108. package/runtime/server/web/my/favorites.txt +27 -0
  109. package/runtime/server/web/my/groups.html +1 -0
  110. package/runtime/server/web/my/groups.txt +27 -0
  111. package/runtime/server/web/my/info.html +1 -0
  112. package/runtime/server/web/my/info.txt +27 -0
  113. package/runtime/server/web/my/keys.html +1 -0
  114. package/runtime/server/web/my/keys.txt +27 -0
  115. package/runtime/server/web/my/orgs.html +1 -0
  116. package/runtime/server/web/my/orgs.txt +27 -0
  117. package/runtime/server/web/my/pages.html +1 -0
  118. package/runtime/server/web/my/pages.txt +27 -0
  119. package/runtime/server/web/my/peers.html +1 -0
  120. package/runtime/server/web/my/peers.txt +24 -0
  121. package/runtime/server/web/my/recent.html +1 -0
  122. package/runtime/server/web/my/recent.txt +27 -0
  123. package/runtime/server/web/my/settings.html +1 -0
  124. package/runtime/server/web/my/settings.txt +27 -0
  125. package/runtime/server/web/my/studio.html +1 -0
  126. package/runtime/server/web/my/studio.txt +24 -0
  127. package/runtime/server/web/my/subscriptions.html +1 -0
  128. package/runtime/server/web/my/subscriptions.txt +27 -0
  129. package/runtime/server/web/my/system.html +1 -0
  130. package/runtime/server/web/my/system.txt +24 -0
  131. package/runtime/server/web/my/tasks.html +1 -0
  132. package/runtime/server/web/my/tasks.txt +24 -0
  133. package/runtime/server/web/my/users.html +1 -0
  134. package/runtime/server/web/my/users.txt +27 -0
  135. package/runtime/server/web/my.html +1 -0
  136. package/runtime/server/web/my.txt +27 -0
  137. package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
  138. package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
  139. package/runtime/server/web/platform-shell-preview.html +1 -0
  140. package/runtime/server/web/platform-shell-preview.txt +23 -0
  141. package/runtime/server/web/setup.html +1 -0
  142. package/runtime/server/web/setup.txt +23 -0
  143. package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
  144. package/template/.claude/skills/localapp/SKILL.md +80 -0
  145. package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
  146. package/template/.claude/skills/localapp-business/SKILL.md +325 -0
  147. package/template/.claude/skills/localapp-data/SKILL.md +381 -0
  148. package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
  149. package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
  150. package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
  151. package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
  152. package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
  153. package/template/AGENTS.md +33 -0
  154. package/template/CLAUDE.md +117 -0
  155. package/template/ISSUES.md +32 -0
  156. package/template/backend/resources/work_items/mutations.json +83 -0
  157. package/template/backend/resources/work_items/queries.json +83 -0
  158. package/template/backend/resources/work_items/schema.json +31 -0
  159. package/template/backend/schemas/mutations.schema.json +15 -0
  160. package/template/backend/schemas/queries.schema.json +36 -0
  161. package/template/backend/schemas/resource-schema.schema.json +25 -0
  162. package/template/components.json +25 -0
  163. package/template/index.html +12 -0
  164. package/template/migrations/001_work_items.sql +6 -0
  165. package/template/package.json +70 -0
  166. package/template/postcss.config.js +5 -0
  167. package/template/runtime/dev-shell.tsx +6398 -0
  168. package/template/runtime/hooks/use-mobile.ts +19 -0
  169. package/template/runtime/issue-reference.ts +44 -0
  170. package/template/runtime/lib/utils.ts +6 -0
  171. package/template/runtime/package.json +14 -0
  172. package/template/runtime/platform-capabilities.json +109 -0
  173. package/template/runtime/sdk/agent/package.json +51 -0
  174. package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
  175. package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
  176. package/template/runtime/sdk/agent/src/context.ts +56 -0
  177. package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
  178. package/template/runtime/sdk/agent/src/index.ts +19 -0
  179. package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
  180. package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
  181. package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
  182. package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
  183. package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
  184. package/template/runtime/sdk/agent/src/tools.ts +70 -0
  185. package/template/runtime/sdk/agent/src/types.ts +27 -0
  186. package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
  187. package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
  188. package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
  189. package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
  190. package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
  191. package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
  192. package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
  193. package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
  194. package/template/runtime/sdk/agent/tsconfig.json +18 -0
  195. package/template/runtime/sdk/agent/vitest.config.ts +8 -0
  196. package/template/runtime/sdk/backend/package.json +15 -0
  197. package/template/runtime/sdk/backend/src/index.ts +92 -0
  198. package/template/runtime/sdk/backend/tsconfig.json +8 -0
  199. package/template/runtime/sdk/core/package.json +15 -0
  200. package/template/runtime/sdk/core/src/client.ts +317 -0
  201. package/template/runtime/sdk/core/src/collaboration.ts +66 -0
  202. package/template/runtime/sdk/core/src/desktop.ts +469 -0
  203. package/template/runtime/sdk/core/src/device.ts +112 -0
  204. package/template/runtime/sdk/core/src/index.ts +6 -0
  205. package/template/runtime/sdk/core/src/invalidate.ts +40 -0
  206. package/template/runtime/sdk/core/src/types.ts +108 -0
  207. package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
  208. package/template/runtime/sdk/core/tests/client.test.ts +424 -0
  209. package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
  210. package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
  211. package/template/runtime/sdk/core/tests/device.test.ts +69 -0
  212. package/template/runtime/sdk/core/tsconfig.json +17 -0
  213. package/template/runtime/sdk/react/package.json +34 -0
  214. package/template/runtime/sdk/react/src/client.ts +7 -0
  215. package/template/runtime/sdk/react/src/components/can.tsx +24 -0
  216. package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
  217. package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
  218. package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
  219. package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
  220. package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
  221. package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
  222. package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
  223. package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
  224. package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
  225. package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
  226. package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
  227. package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
  228. package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
  229. package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
  230. package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
  231. package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
  232. package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
  233. package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
  234. package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
  235. package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
  236. package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
  237. package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
  238. package/template/runtime/sdk/react/src/index.ts +40 -0
  239. package/template/runtime/sdk/react/src/permissions.ts +94 -0
  240. package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
  241. package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
  242. package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
  243. package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
  244. package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
  245. package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
  246. package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
  247. package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
  248. package/template/runtime/sdk/react/tsconfig.json +18 -0
  249. package/template/runtime/sdk/react/vitest.config.ts +9 -0
  250. package/template/runtime/sdk/react/vitest.setup.ts +6 -0
  251. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
  252. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
  253. package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
  254. package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
  255. package/template/runtime/server-core/dist/index.d.ts +19 -0
  256. package/template/runtime/server-core/dist/index.d.ts.map +1 -0
  257. package/template/runtime/server-core/dist/index.js +35 -0
  258. package/template/runtime/server-core/dist/index.js.map +1 -0
  259. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
  260. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
  261. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
  262. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
  263. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
  264. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
  265. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
  266. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
  267. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
  268. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
  269. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
  270. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
  271. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
  272. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
  273. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
  274. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
  275. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
  276. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
  277. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
  278. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
  279. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
  280. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
  281. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
  282. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
  283. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
  284. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
  285. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
  286. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
  287. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
  288. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
  289. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
  290. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
  291. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
  292. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
  293. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
  294. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
  295. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
  296. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
  297. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
  298. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
  299. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
  300. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
  301. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
  302. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
  303. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
  304. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
  305. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
  306. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
  307. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
  308. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
  309. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
  310. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
  311. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
  312. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
  313. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
  314. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
  315. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
  316. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
  317. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
  318. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
  319. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
  320. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
  321. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
  322. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
  323. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
  324. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
  325. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
  326. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
  327. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
  328. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
  329. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
  330. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
  331. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
  332. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
  333. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
  334. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
  335. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
  336. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
  337. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
  338. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
  339. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
  340. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
  341. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
  342. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
  343. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
  344. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
  345. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
  346. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
  347. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
  348. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
  349. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
  350. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
  351. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
  352. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
  353. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
  354. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
  355. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
  356. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
  357. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
  358. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
  359. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
  360. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
  361. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
  362. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
  363. package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
  364. package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
  365. package/template/runtime/server-core/dist/lib/access-control.js +138 -0
  366. package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
  367. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
  368. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
  369. package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
  370. package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
  371. package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
  372. package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
  373. package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
  374. package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
  375. package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
  376. package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
  377. package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
  378. package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
  379. package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
  380. package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
  381. package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
  382. package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
  383. package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
  384. package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
  385. package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
  386. package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
  387. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
  388. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
  389. package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
  390. package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
  391. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
  392. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
  393. package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
  394. package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
  395. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
  396. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
  397. package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
  398. package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
  399. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
  400. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
  401. package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
  402. package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
  403. package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
  404. package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
  405. package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
  406. package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
  407. package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
  408. package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
  409. package/template/runtime/server-core/dist/lib/migrations.js +180 -0
  410. package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
  411. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
  412. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
  413. package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
  414. package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
  415. package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
  416. package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
  417. package/template/runtime/server-core/dist/lib/record-access.js +81 -0
  418. package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
  419. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
  420. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
  421. package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
  422. package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
  423. package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
  424. package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
  425. package/template/runtime/server-core/dist/lib/transitions.js +142 -0
  426. package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
  427. package/template/runtime/server-core/dist/types/models.d.ts +163 -0
  428. package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
  429. package/template/runtime/server-core/dist/types/models.js +3 -0
  430. package/template/runtime/server-core/dist/types/models.js.map +1 -0
  431. package/template/runtime/server-core/package.json +24 -0
  432. package/template/runtime/styles/preset.css +282 -0
  433. package/template/runtime/sync-template-command.cjs +19 -0
  434. package/template/runtime/sync-template.cjs +71 -0
  435. package/template/runtime/tsconfig.base.json +20 -0
  436. package/template/runtime/version.json +3 -0
  437. package/template/runtime/vite-plugin.mjs +309 -0
  438. package/template/src/App.tsx +273 -0
  439. package/template/src/components/ui/accordion.tsx +79 -0
  440. package/template/src/components/ui/alert-dialog.tsx +197 -0
  441. package/template/src/components/ui/alert.tsx +76 -0
  442. package/template/src/components/ui/aspect-ratio.tsx +11 -0
  443. package/template/src/components/ui/avatar.tsx +110 -0
  444. package/template/src/components/ui/badge.tsx +49 -0
  445. package/template/src/components/ui/breadcrumb.tsx +122 -0
  446. package/template/src/components/ui/button-group.tsx +83 -0
  447. package/template/src/components/ui/button.tsx +67 -0
  448. package/template/src/components/ui/calendar.tsx +221 -0
  449. package/template/src/components/ui/card.tsx +103 -0
  450. package/template/src/components/ui/carousel.tsx +240 -0
  451. package/template/src/components/ui/chart.tsx +373 -0
  452. package/template/src/components/ui/checkbox.tsx +31 -0
  453. package/template/src/components/ui/collapsible.tsx +33 -0
  454. package/template/src/components/ui/combobox.tsx +299 -0
  455. package/template/src/components/ui/command.tsx +193 -0
  456. package/template/src/components/ui/context-menu.tsx +261 -0
  457. package/template/src/components/ui/dialog.tsx +168 -0
  458. package/template/src/components/ui/direction.tsx +22 -0
  459. package/template/src/components/ui/drawer.tsx +132 -0
  460. package/template/src/components/ui/dropdown-menu.tsx +269 -0
  461. package/template/src/components/ui/empty.tsx +104 -0
  462. package/template/src/components/ui/field.tsx +238 -0
  463. package/template/src/components/ui/hover-card.tsx +42 -0
  464. package/template/src/components/ui/input-group.tsx +154 -0
  465. package/template/src/components/ui/input-otp.tsx +87 -0
  466. package/template/src/components/ui/input.tsx +19 -0
  467. package/template/src/components/ui/item.tsx +196 -0
  468. package/template/src/components/ui/kbd.tsx +26 -0
  469. package/template/src/components/ui/label.tsx +22 -0
  470. package/template/src/components/ui/menubar.tsx +280 -0
  471. package/template/src/components/ui/native-select.tsx +61 -0
  472. package/template/src/components/ui/navigation-menu.tsx +164 -0
  473. package/template/src/components/ui/pagination.tsx +129 -0
  474. package/template/src/components/ui/popover.tsx +87 -0
  475. package/template/src/components/ui/progress.tsx +31 -0
  476. package/template/src/components/ui/radio-group.tsx +42 -0
  477. package/template/src/components/ui/resizable.tsx +50 -0
  478. package/template/src/components/ui/scroll-area.tsx +53 -0
  479. package/template/src/components/ui/select.tsx +192 -0
  480. package/template/src/components/ui/separator.tsx +26 -0
  481. package/template/src/components/ui/sheet.tsx +145 -0
  482. package/template/src/components/ui/sidebar.tsx +700 -0
  483. package/template/src/components/ui/skeleton.tsx +13 -0
  484. package/template/src/components/ui/slider.tsx +59 -0
  485. package/template/src/components/ui/sonner.tsx +47 -0
  486. package/template/src/components/ui/spinner.tsx +10 -0
  487. package/template/src/components/ui/switch.tsx +33 -0
  488. package/template/src/components/ui/table.tsx +114 -0
  489. package/template/src/components/ui/tabs.tsx +90 -0
  490. package/template/src/components/ui/textarea.tsx +18 -0
  491. package/template/src/components/ui/toggle-group.tsx +89 -0
  492. package/template/src/components/ui/toggle.tsx +45 -0
  493. package/template/src/components/ui/tooltip.tsx +57 -0
  494. package/template/src/hooks/use-mobile.ts +3 -0
  495. package/template/src/index.css +4 -0
  496. package/template/src/lib/utils.ts +3 -0
  497. package/template/src/main.tsx +10 -0
  498. package/template/src/vite-env.d.ts +1 -0
  499. package/template/template.gitignore +10 -0
  500. package/template/template.npmrc +1 -0
  501. package/template/tests/agent-context.test.ts +69 -0
  502. package/template/tests/agent-guidance-template.test.ts +49 -0
  503. package/template/tests/agent-runtime.test.ts +198 -0
  504. package/template/tests/agent-tools.test.ts +150 -0
  505. package/template/tests/agent-use-agent.test.ts +86 -0
  506. package/template/tests/assistant-ui-adapter.test.ts +211 -0
  507. package/template/tests/business-modeling-template.test.ts +71 -0
  508. package/template/tests/client.test.ts +382 -0
  509. package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
  510. package/template/tests/dev-shell-context.test.tsx +40 -0
  511. package/template/tests/dev-shell-template.test.ts +2593 -0
  512. package/template/tests/invalidation.test.ts +126 -0
  513. package/template/tests/main-tsx.test.ts +28 -0
  514. package/template/tests/media-preview-template.test.ts +21 -0
  515. package/template/tests/mutations.test.ts +224 -0
  516. package/template/tests/react.test.ts +302 -0
  517. package/template/tests/redirect.test.ts +51 -0
  518. package/template/tests/skill-docs.test.ts +76 -0
  519. package/template/tests/state-transitions-template.test.ts +61 -0
  520. package/template/tests/template-ui.test.ts +145 -0
  521. package/template/tests/upload.test.ts +143 -0
  522. package/template/tests/vite-plugin.test.ts +426 -0
  523. package/template/tests/vite-proxy-security.test.ts +153 -0
  524. package/template/tsconfig.json +11 -0
  525. package/template/vite.config.ts +7 -0
  526. package/template/vitest.config.ts +16 -0
  527. package/template/vitest.setup.ts +1 -0
@@ -0,0 +1,195 @@
1
+ LocalApp Agent 工具编写指南。当编写或修改 useAgent({ tools }) 的自定义工具时,或用户提到"agent 工具"、"自定义工具"、"写操作工具"、"agent tool"时触发。提供正确的工具编写模式,确保 agent 通过前端组件操作数据而非直接调 API。
2
+
3
+ # Agent 工具编写模式
4
+
5
+ ## 核心原则:通过前端组件操作,不直接调 API
6
+
7
+ Agent 的写操作必须通过 React 状态管理和 SDK Hook(useCreate、useUpdate、useDelete)执行,不能直接用 fetch 调 REST API。
8
+
9
+ 原因:
10
+ 1. **权限一致性** — SDK Hook 内部走的 API 调用带完整的校验和 ACL,和用户手动操作表单走同一路径
11
+ 2. **用户可见性** — 操作前端组件意味着用户能看到表单在填、数据在变,agent 不是在后台默默改数据库
12
+ 3. **状态一致性** — React 状态和数据库状态保持同步,不会出现 UI 显示的和数据库不一致
13
+
14
+ ## 正确模式
15
+
16
+ ### 模式一:表单填写 + 提交
17
+
18
+ 适合有表单的应用。Agent 分两步操作:先填字段,再提交表单。
19
+
20
+ ```tsx
21
+ import { useState } from "react";
22
+
23
+ function App() {
24
+ const [formData, setFormData] = useState({ title: "", content: "" });
25
+ const { create } = useCreate("posts");
26
+ const { refresh } = useList("posts");
27
+
28
+ const handleSubmit = async (e: React.FormEvent) => {
29
+ e.preventDefault();
30
+ await create(formData);
31
+ setFormData({ title: "", content: "" });
32
+ refresh();
33
+ };
34
+
35
+ const agent = useAgent({
36
+ tools: {
37
+ fillField: {
38
+ description: "填写表单中的指定字段",
39
+ parameters: {
40
+ field: { type: "string", required: true, description: "字段名" },
41
+ value: { type: "string", required: true, description: "要填写的值" },
42
+ },
43
+ execute: async (args) => {
44
+ setFormData(prev => ({ ...prev, [args.field as string]: args.value }));
45
+ return `已填写 ${args.field}`;
46
+ },
47
+ },
48
+ submitForm: {
49
+ description: "提交当前表单",
50
+ parameters: {},
51
+ execute: async () => {
52
+ if (!formData.title) return "缺少必填字段: title";
53
+ await create(formData);
54
+ setFormData({ title: "", content: "" });
55
+ refresh();
56
+ return "提交成功";
57
+ },
58
+ },
59
+ },
60
+ systemHint: "用户会描述想要提交的内容,先用 fillField 填好表单,再用 submitForm 提交。",
61
+ });
62
+
63
+ return (
64
+ <div style={{ display: "flex", height: "100vh" }}>
65
+ <div style={{ flex: 1 }}>
66
+ <form onSubmit={handleSubmit}>
67
+ <input value={formData.title} onChange={e => setFormData(p => ({...p, title: e.target.value}))} />
68
+ <input value={formData.content} onChange={e => setFormData(p => ({...p, content: e.target.value}))} />
69
+ <button type="submit">提交</button>
70
+ </form>
71
+ </div>
72
+ <div style={{ width: 400 }}>
73
+ <AgentChat agent={agent} />
74
+ </div>
75
+ </div>
76
+ );
77
+ }
78
+ ```
79
+
80
+ ### 模式二:直接操作数据
81
+
82
+ 适合没有表单、直接管理数据的场景(如列表页删除、切换状态)。
83
+
84
+ ```tsx
85
+ function App() {
86
+ const { create } = useCreate("todos");
87
+ const { update } = useUpdate("todos");
88
+ const { remove } = useDelete("todos");
89
+ const { rows, refresh } = useList("todos");
90
+
91
+ const agent = useAgent({
92
+ tools: {
93
+ addTodo: {
94
+ description: "添加待办事项",
95
+ parameters: {
96
+ title: { type: "string", required: true, description: "标题" },
97
+ },
98
+ execute: async (args) => {
99
+ await create({ title: args.title as string, done: false });
100
+ refresh();
101
+ return `已添加: ${args.title}`;
102
+ },
103
+ },
104
+ toggleTodo: {
105
+ description: "切换待办事项的完成状态",
106
+ parameters: {
107
+ id: { type: "number", required: true, description: "待办 ID" },
108
+ },
109
+ execute: async (args) => {
110
+ const todo = rows.find(r => r.id === args.id);
111
+ if (!todo) return `未找到 ID ${args.id}`;
112
+ await update(args.id as number, { done: !todo.done });
113
+ refresh();
114
+ return `已${todo.done ? "取消完成" : "完成"}: ${todo.title}`;
115
+ },
116
+ },
117
+ deleteTodo: {
118
+ description: "删除待办事项",
119
+ parameters: {
120
+ id: { type: "number", required: true, description: "待办 ID" },
121
+ },
122
+ execute: async (args) => {
123
+ await remove(args.id as number);
124
+ refresh();
125
+ return `已删除 ID ${args.id}`;
126
+ },
127
+ },
128
+ },
129
+ systemHint: "用户会要求管理待办事项,使用工具执行操作。",
130
+ });
131
+
132
+ // ...render
133
+ }
134
+ ```
135
+
136
+ ## 反模式:直接 fetch 调 API
137
+
138
+ ```tsx
139
+ // ❌ 错误:绕过了 React 状态和 SDK Hook
140
+ const agent = useAgent({
141
+ tools: {
142
+ createPost: {
143
+ description: "创建文章",
144
+ parameters: { title: { type: "string", required: true } },
145
+ execute: async (args) => {
146
+ const res = await fetch("/api/posts", {
147
+ method: "POST",
148
+ headers: { "Content-Type": "application/json" },
149
+ body: JSON.stringify(args),
150
+ });
151
+ return res.json();
152
+ },
153
+ },
154
+ },
155
+ });
156
+ ```
157
+
158
+ 这会导致:
159
+ - 前端 UI 不更新(React 状态不知道数据变了)
160
+ - 用户看不到 agent 做了什么
161
+ - 绕过了 SDK 内置的路径解析(detectBasePath)和错误处理
162
+
163
+ ## 工具函数闭包安全性
164
+
165
+ `useAgent` 内部通过 `optionsRef.current` 延迟引用工具函数。组件每次重渲染时,工具 `execute` 函数自动获取最新的闭包值(state、props、Hook 返回值等)。
166
+
167
+ **你不需要用 `useCallback` 包裹 `execute` 函数。** 直接使用组件作用域中的变量,它们始终是最新的:
168
+
169
+ ```tsx
170
+ const [count, setCount] = useState(0);
171
+ const { rows } = useList("todos");
172
+
173
+ const agent = useAgent({
174
+ tools: {
175
+ getState: {
176
+ description: "获取当前状态",
177
+ parameters: {},
178
+ execute: async () => {
179
+ // count 和 rows 始终是最新值,无需担心闭包过期
180
+ return `当前计数: ${count}, 待办数: ${rows.length}`;
181
+ },
182
+ },
183
+ },
184
+ });
185
+ ```
186
+
187
+ 这种设计确保了 Agent 回调中访问的 React 状态与 UI 渲染的状态完全一致。
188
+
189
+ ## 工具设计检查清单
190
+
191
+ 1. 写操作工具是否调用了 `useCreate`/`useUpdate`/`useDelete` 的返回函数?
192
+ 2. 操作后是否调用了 `refresh()` 刷新列表?
193
+ 3. 表单填写工具是否通过 `setState` 更新 React 状态?
194
+ 4. 没有直接使用 `fetch` 调 REST API?
195
+ 5. `systemHint` 是否指导 LLM 使用正确的工具调用顺序?
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: localapp
3
+ description: Use when creating, developing, checking, installing, publishing, synchronizing, or Browser-testing an application whose project contains manifest.json and targets a LocalApp Server.
4
+ ---
5
+
6
+ # LocalApp application workflow
7
+
8
+ Treat local and remote deployments as the same Server product. The application owns React/TypeScript, migrations and backend contracts; the Server owns identity, authorization, files, notifications, Issues and operational state.
9
+
10
+ ## Project gate
11
+
12
+ Confirm `manifest.json`, `package.json`, `migrations/` and `backend/` before editing. If the project does not exist, create it from the installed npm package:
13
+
14
+ ```bash
15
+ mkdir -p tmp
16
+ cd tmp
17
+ localapp init my-app
18
+ cd my-app
19
+ ```
20
+
21
+ Run those commands from the repository root. Keep generated projects, Server data, uploads and downloads under that repository's `tmp/` during local acceptance; never use the operating-system temp directory.
22
+
23
+ ## Development loop
24
+
25
+ 1. Write the migration and backend contract before UI code that consumes it.
26
+ 2. Use `localapp dev` and the SDK; do not add an application-private backend.
27
+ 3. Run application tests and `localapp check --json`.
28
+ 4. Install with `localapp app install --target <profile>`.
29
+ 5. Read `ownerId` and `name` from the JSON result, then open `<serverUrl>/<ownerId>/<name>/` with the in-app Browser.
30
+ 6. Verify DOM, console, core reads/writes and each relevant identity boundary.
31
+
32
+ `/serve/<owner>/<app>/` is only the raw resource/API base for diagnostics. Never use it as acceptance evidence.
33
+
34
+ ## Supported CLI
35
+
36
+ | Intent | Command |
37
+ | --- | --- |
38
+ | Start local daemon | `localapp server` |
39
+ | Inspect lifecycle | `localapp server status` / `logs` |
40
+ | Run foreground Server | `localapp server run` |
41
+ | Save a Server profile | `localapp login <url> --profile <name>` |
42
+ | Inspect profile identity | `localapp whoami --profile <name>` |
43
+ | Develop | `localapp dev` |
44
+ | Check | `localapp check --json` |
45
+ | Build portable package | `localapp build --package` |
46
+ | Install/update | `localapp app install --target <name>` |
47
+ | Sync version | `localapp app sync --target <source> --peer <peer>` |
48
+ | Sync version and data | add `--with-data --confirm-app <exact-name>` |
49
+ | Refresh managed template | `localapp sync-template` |
50
+ | Permanently take ownership | `localapp eject-template` |
51
+
52
+ For a repository-local acceptance daemon, set `LOCALAPP_SUPPORT_DIR`, `LOCALAPP_RUNTIME_DIR` and `LOCALAPP_DATA_DIR` to absolute subdirectories of the repository `tmp/` before running `localapp server`. Read its `status.server.listenUrl`, complete first-run setup in the Browser, create an API Key, then save that URL and key with `localapp login <url> --api-key <key> --profile local` before using `--target local`.
53
+
54
+ `app sync --target <source-profile> --peer <server-peer>` asks the Server selected by the CLI profile to synchronize to a peer configured inside that Server. A peer name is not a CLI profile name.
55
+
56
+ Only top-level `localapp --help` is currently supported. Consult this table or the installed package documentation for subcommand options; do not invent a command from older LocalApp documentation.
57
+
58
+ ## Contracts and security
59
+
60
+ - Maintain `backend/resources/<resource>/{schema,queries,mutations}.json` directly.
61
+ - Parameterize SQL and bind resource ownership to the authenticated user.
62
+ - Keep API Keys out of application source, Scheme URLs, logs and Browser state.
63
+ - Use SDK content upload/download URLs; never construct storage paths.
64
+ - Device Actions execute only on the computer that activates `localapp://`; the URL carries only an opaque ticket.
65
+ - Native notifications are Server inbox events delivered by the daemon, not a browser API owned by the application.
66
+
67
+ ## Media applications
68
+
69
+ For image/PDF flows, use authenticated content upload, store metadata only, provide accessible loading/error/keyboard states, release object URLs, and verify downloaded bytes. Use the template-pinned `react-pdf`, `pdfjs-dist` worker and image lightbox packages.
70
+
71
+ ## Completion contract
72
+
73
+ Do not claim the application is usable until all are true:
74
+
75
+ - tests and `localapp check --json` pass;
76
+ - installation returns `serverUrl`, `ownerId` and `name`, from which the formal `/<ownerId>/<name>/` URL is formed;
77
+ - a fresh in-app Browser tab renders without unexplained console errors;
78
+ - core user journeys persist and reload;
79
+ - unauthorized and cross-user access fail correctly;
80
+ - no credentials, runtime data or machine-external temp paths are packaged.
@@ -0,0 +1,299 @@
1
+ ---
2
+ name: localapp-auth
3
+ description: >
4
+ LocalApp 认证与权限控制指南——用户身份查询、登录跳转、访问控制配置。
5
+ 当用户要在 LocalApp 项目中处理用户登录状态、权限控制、根据登录状态显示不同内容、
6
+ 配置页面访问权限、设置路由级权限时触发。
7
+ 也适用于用户说"登录"、"权限"、"认证"、"只有自己能看"、"需要登录才能访问"、
8
+ "访问控制"、"角色"等场景。
9
+ ---
10
+
11
+ # LocalApp 认证与权限
12
+
13
+ LocalApp 内置用户认证和双层访问控制,不需要写后端代码。
14
+
15
+ ## 用户身份
16
+
17
+ ### useMe() — 查询当前访客
18
+
19
+ ```tsx
20
+ import { useMe } from "@localapp/sdk-react";
21
+
22
+ function App() {
23
+ const { me, loading, error } = useMe();
24
+ // me: { id: string, name: string } | null
25
+ // 未登录时 me 为 null
26
+
27
+ if (loading) return <p>加载中...</p>;
28
+
29
+ return (
30
+ <div>
31
+ {me
32
+ ? <p>欢迎, {me.name}!</p>
33
+ : <p>请登录后继续</p>}
34
+ </div>
35
+ );
36
+ }
37
+ ```
38
+
39
+ 应用运行在 LocalApp native shell 内,`useMe` 自动检测平台 session cookie,无需额外配置。
40
+
41
+ ### redirectToLogin() — 在当前应用打开平台登录框
42
+
43
+ ```tsx
44
+ import { redirectToLogin } from "@localapp/sdk";
45
+
46
+ // 点击按钮跳转
47
+ <button onClick={redirectToLogin}>登录</button>
48
+
49
+ // 检测到未登录自动跳转
50
+ if (error?.status === 401) {
51
+ redirectToLogin();
52
+ }
53
+ ```
54
+
55
+ 在当前 native shell 页面原地打开平台登录框,登录成功后自动返回并继续访问当前应用。DevShell 中会打开“开发工具 → 身份”面板供开发者选择模拟身份。若当前页面没有 Shell,则回退到平台首页。应用不需要也不得直接操作平台 DOM。
56
+
57
+ ## 访问控制
58
+
59
+ 两层权限,声明式配置:
60
+
61
+ ```
62
+ ┌─────────────────────────────────────────────┐
63
+ │ 页面级 (pageAccess) │
64
+ │ "谁能看到这个页面" │
65
+ │ ┌─────────────────────────────────────┐ │
66
+ │ │ 路由级 (routeAccess) │ │
67
+ │ │ "谁能操作特定数据" │ │
68
+ │ └─────────────────────────────────────┘ │
69
+ └─────────────────────────────────────────────┘
70
+ ```
71
+
72
+ ### 四种访问级别
73
+
74
+ | 级别 | 说明 |
75
+ |------|------|
76
+ | `public` | 任何人可访问,包括未登录用户 |
77
+ | `authenticated` | 需要登录 |
78
+ | `owner` | 仅页面所有者 |
79
+ | `acl` | 指定用户列表 |
80
+
81
+ ACL 格式:`{ "level": "acl", "acl": ["alice", "bob"] }`
82
+
83
+ ### 页面级权限
84
+
85
+ 控制谁能看到整个页面。通过 API 设置:
86
+
87
+ ```bash
88
+ # 设为需要登录才能访问
89
+ # PUT /api/pages/<page-name>
90
+ # Body: { "pageAccess": { "level": "authenticated" } }
91
+ ```
92
+
93
+ 或者通过 CLI(如果有对应命令的话),也可以在 `localapp pages info` 查看当前设置。
94
+
95
+ ### 路由级权限
96
+
97
+ 控制谁能对特定数据表执行 CRUD 操作。表结构通过 SQL migration 创建:
98
+
99
+ ```sql
100
+ CREATE TABLE comments (
101
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
102
+ content TEXT NOT NULL,
103
+ created_by TEXT
104
+ );
105
+ ```
106
+
107
+ 权限通过 `manifest.json` 的 `db.defaultAccess` 和 `manifest.business` 指定:
108
+ ```json
109
+ {
110
+ "db": {
111
+ "mode": "crud",
112
+ "defaultAccess": {
113
+ "read": "public",
114
+ "create": "authenticated",
115
+ "update": "owner",
116
+ "delete": "owner"
117
+ }
118
+ },
119
+ "business": {
120
+ "comments": {
121
+ "ownerField": "created_by",
122
+ "recordAccess": { "update": "owner", "delete": "owner" }
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ `routeAccess` 支持的键:`read` / `create` / `update` / `delete`
129
+
130
+ ### manifest.json 全局默认权限
131
+
132
+ 当 schema 没有指定 routeAccess 时,使用 manifest.json 的全局默认:
133
+
134
+ ```json
135
+ {
136
+ "db": {
137
+ "mode": "crud",
138
+ "defaultAccess": {
139
+ "read": "public",
140
+ "create": "authenticated",
141
+ "update": "owner",
142
+ "delete": "owner"
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ ### 记录级权限(recordAccess)
149
+
150
+ routeAccess 控制的是"谁能对这张表执行 CRUD",recordAccess 进一步控制"具体哪些记录可见/可改"。在 schema `business.recordAccess` 中声明:
151
+
152
+ ```json
153
+ "business": {
154
+ "ownerField": "created_by",
155
+ "recordAccess": {
156
+ "read": { "mode": "ownerField", "field": "created_by" },
157
+ "update": { "mode": "ownerField", "field": "created_by", "when": { "status": ["draft"] } }
158
+ }
159
+ }
160
+ ```
161
+
162
+ 后端 CRUD 自动执行;前端用 `usePermissions()` / `<Can>` 同步判断 UI。详细约定见 `localapp-business.md`。
163
+
164
+ ### 开发模式验证身份和权限
165
+
166
+ 运行 `localapp dev` 后,用 Dev Toolkit 的 **Identity** 分区切换 `dev-user` / `alice` / `bob` / 未登录,验证:
167
+
168
+ - `useMe()` 是否返回当前模拟用户或 `null`
169
+ - `defaultFrom: "currentUser.id"` 是否由后端自动填充
170
+ - `recordAccess` owner / assignee / acl 策略是否过滤列表、详情和按钮
171
+ - 未登录用户创建含 `defaultFrom` 的记录是否返回 401
172
+
173
+ 切换身份后 DevShell 会派发 `localapp:dev-context-changed`,数据 hooks 会自动刷新;不要为了测试权限在 React 里手动伪造用户字段。
174
+
175
+ ## 前端权限判断(UI 展示)
176
+
177
+ 后端访问控制是安全边界;前端用以下 API 决定显示哪些按钮:
178
+
179
+ ### usePermissions() — 记录级权限判断
180
+
181
+ ```tsx
182
+ import { usePermissions } from "@localapp/sdk-react";
183
+ import type { DataSchemaLike } from "@localapp/sdk-react";
184
+
185
+ const schema: DataSchemaLike = {
186
+ business: {
187
+ ownerField: "created_by",
188
+ recordAccess: {
189
+ update: { mode: "ownerField", field: "created_by", when: { status: ["draft"] } },
190
+ },
191
+ },
192
+ };
193
+
194
+ function LeaveRow({ leave }: { leave: Leave }) {
195
+ const { can, loading } = usePermissions();
196
+ if (loading) return null;
197
+ const editable = can("update", leave, schema);
198
+ return (
199
+ <div>
200
+ <span>{leave.title}</span>
201
+ {editable && <button>编辑</button>}
202
+ </div>
203
+ );
204
+ }
205
+ ```
206
+
207
+ ### `<Can>` 组件 — 声明式权限渲染
208
+
209
+ ```tsx
210
+ import { Can } from "@localapp/sdk-react";
211
+
212
+ <Can action="update" record={leave} schema={schema} fallback={<span>已锁定</span>}>
213
+ <button>编辑</button>
214
+ </Can>
215
+ ```
216
+
217
+ `fallback` 可选,默认不渲染任何内容。
218
+
219
+ **重要**:`usePermissions()` 和 `<Can>` 仅用于 UI 展示判断(如隐藏不可用的按钮),
220
+ 后端 CRUD API 才是记录级权限的安全边界。即使前端隐藏了按钮,直接调用 API
221
+ 仍会经过完整的权限校验。
222
+
223
+ ## 常见模式
224
+
225
+ ### 根据登录状态显示不同内容
226
+
227
+ ```tsx
228
+ import { useMe } from "@localapp/sdk-react";
229
+ import { redirectToLogin } from "@localapp/sdk";
230
+
231
+ function App() {
232
+ const { me, loading } = useMe();
233
+
234
+ if (loading) return <p>加载中...</p>;
235
+
236
+ return (
237
+ <div>
238
+ {me ? (
239
+ <p>欢迎回来, {me.name}!</p>
240
+ ) : (
241
+ <p>请 <button onClick={redirectToLogin}>登录</button> 后继续</p>
242
+ )}
243
+ </div>
244
+ );
245
+ }
246
+ ```
247
+
248
+ ### 未登录自动跳转
249
+
250
+ ```tsx
251
+ import { useList } from "@localapp/sdk-react";
252
+ import { redirectToLogin } from "@localapp/sdk";
253
+
254
+ function PrivatePage() {
255
+ const { rows, loading, error } = useList("posts");
256
+
257
+ if (error?.status === 401) {
258
+ redirectToLogin();
259
+ return <p>正在跳转登录...</p>;
260
+ }
261
+ if (error?.status === 403) {
262
+ return <p>你没有权限访问此页面</p>;
263
+ }
264
+ if (loading) return <p>加载中...</p>;
265
+
266
+ return <ul>{rows.map(p => <li key={p.id}>{p.title}</li>)}</ul>;
267
+ }
268
+ ```
269
+
270
+ ### 错误处理
271
+
272
+ 所有 Hook 返回 `error` 字段,类型为 `LocalAppError`:
273
+
274
+ ```tsx
275
+ import { LocalAppError } from "@localapp/sdk";
276
+
277
+ // 查询 Hook
278
+ const { error } = useList("posts");
279
+ if (error) {
280
+ if (error.status === 401) { /* 未登录 */ }
281
+ if (error.status === 403) { /* 无权限 */ }
282
+ if (error.status === 404) { /* 资源不存在 */ }
283
+ }
284
+
285
+ // 变更 Hook 用 try/catch
286
+ try {
287
+ await create({ title: "Hello" });
288
+ } catch (e) {
289
+ if (e instanceof LocalAppError && e.status === 401) {
290
+ redirectToLogin();
291
+ }
292
+ }
293
+ ```
294
+
295
+ 常见状态码:
296
+ - `401` — 未登录
297
+ - `403` — 已登录但无权限
298
+ - `404` — 资源不存在
299
+ - `0` — 网络错误