anhedral 0.17.0 → 0.18.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 (105) hide show
  1. package/README.md +33 -68
  2. package/assets/contracts/LICENSE +201 -0
  3. package/assets/contracts/LICENSE.environment +201 -0
  4. package/assets/contracts/LICENSE.operations +201 -0
  5. package/assets/contracts/deployment-provenance.json +15 -0
  6. package/assets/contracts/environment-provenance.json +11 -0
  7. package/assets/contracts/operations-provenance.json +11 -0
  8. package/assets/launch/application.server.ts.txt +13 -0
  9. package/assets/launch/auth-client.ts.txt +4 -0
  10. package/assets/launch/home.tsx.txt +20 -0
  11. package/assets/launch/minimal-application.server.ts.txt +5 -0
  12. package/assets/launch/minimal-server.ts.txt +7 -0
  13. package/assets/launch/request-context.ts.txt +3 -0
  14. package/assets/launch/root.tsx.txt +27 -0
  15. package/assets/launch/router.tsx.txt +21 -0
  16. package/assets/launch/server.ts.txt +13 -0
  17. package/assets/launch/sign-in.tsx.txt +53 -0
  18. package/assets/launch/styles.css.txt +19 -0
  19. package/assets/security/credential-patterns.d.mts +3 -0
  20. package/assets/security/credential-patterns.mjs +59 -0
  21. package/assets/stack/api-index.ts.txt +6 -1
  22. package/assets/stack/event-retention.sql.txt +10 -0
  23. package/assets/stack/stripe.ts.txt +30 -13
  24. package/dist/bin.js +55 -36
  25. package/dist/capabilities.d.ts +1 -1
  26. package/dist/capability-catalog.d.ts +44 -11
  27. package/dist/capability-catalog.js +96 -11
  28. package/dist/capability-command.d.ts +2 -2
  29. package/dist/capability-command.js +178 -27
  30. package/dist/capability-editor.js +6 -5
  31. package/dist/capability-recipes.js +54 -6
  32. package/dist/cli-arguments.d.ts +2 -0
  33. package/dist/cli-arguments.js +101 -50
  34. package/dist/cli-commands.d.ts +1 -1
  35. package/dist/cli-commands.js +30 -6
  36. package/dist/cli-errors.d.ts +18 -0
  37. package/dist/cli-errors.js +63 -0
  38. package/dist/cli-output.d.ts +22 -0
  39. package/dist/cli-output.js +42 -7
  40. package/dist/command-runner.d.ts +1 -0
  41. package/dist/command-runner.js +88 -0
  42. package/dist/command-schema.d.ts +16 -0
  43. package/dist/command-schema.js +390 -21
  44. package/dist/completion.d.ts +2 -0
  45. package/dist/completion.js +201 -0
  46. package/dist/composition.d.ts +35 -0
  47. package/dist/composition.js +28 -0
  48. package/dist/contracts/cli-transport.d.ts +217 -0
  49. package/dist/contracts/cli-transport.js +167 -0
  50. package/dist/contracts/deployment.d.ts +282 -0
  51. package/dist/contracts/deployment.js +234 -0
  52. package/dist/contracts/environment-file.d.ts +7 -0
  53. package/dist/contracts/environment-file.js +112 -0
  54. package/dist/contracts/environment-transport.d.ts +79 -0
  55. package/dist/contracts/environment-transport.js +110 -0
  56. package/dist/contracts/runtime-logs-transport.d.ts +127 -0
  57. package/dist/contracts/runtime-logs-transport.js +50 -0
  58. package/dist/contracts/source-bundle.d.ts +11 -0
  59. package/dist/contracts/source-bundle.js +197 -0
  60. package/dist/contracts/source-profile.d.ts +4 -0
  61. package/dist/contracts/source-profile.js +5 -0
  62. package/dist/contracts/staging-transport.d.ts +79 -0
  63. package/dist/contracts/staging-transport.js +43 -0
  64. package/dist/dependencies.d.ts +10 -1
  65. package/dist/dependencies.js +18 -1
  66. package/dist/index.d.ts +6 -0
  67. package/dist/index.js +4 -0
  68. package/dist/launch.d.ts +21 -0
  69. package/dist/launch.js +250 -0
  70. package/dist/platform-command.d.ts +9 -0
  71. package/dist/platform-command.js +584 -0
  72. package/dist/platform-environment.d.ts +18 -0
  73. package/dist/platform-environment.js +257 -0
  74. package/dist/platform-operations.d.ts +26 -0
  75. package/dist/platform-operations.js +155 -0
  76. package/dist/platform-source.d.ts +8 -0
  77. package/dist/platform-source.js +111 -0
  78. package/dist/platform-state.d.ts +13 -0
  79. package/dist/platform-state.js +207 -0
  80. package/dist/platforms/tanstack.d.ts +8 -0
  81. package/dist/platforms/tanstack.js +155 -0
  82. package/dist/registry/options.js +34 -31
  83. package/dist/registry/usage.d.ts +4 -1
  84. package/dist/registry/usage.js +58 -4
  85. package/dist/scaffold/styling.d.ts +1 -1
  86. package/dist/scaffold/workspace.js +11 -1
  87. package/dist/stack-registry.d.ts +2 -2
  88. package/dist/standard.js +21 -6
  89. package/dist/transaction.js +28 -3
  90. package/dist/ui-command.d.ts +4 -2
  91. package/dist/ui-command.js +79 -38
  92. package/dist/ui-project.d.ts +2 -0
  93. package/dist/ui-project.js +38 -8
  94. package/dist/util.js +40 -61
  95. package/dist/version.d.ts +1 -1
  96. package/dist/version.js +1 -1
  97. package/docs/capabilities.md +22 -88
  98. package/docs/software-factory.md +169 -9
  99. package/docs/stack-standard.md +7 -17
  100. package/docs/ui.md +9 -22
  101. package/package.json +27 -20
  102. package/docs/anhedral-stack.md +0 -12
  103. package/docs/assets/anhedral-stack-light.png +0 -0
  104. package/docs/assets/anhedral-stack.png +0 -0
  105. package/docs/native-ui.md +0 -47
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Anhedral, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ {
2
+ "contractVersion": 1,
3
+ "owner": "anhedral/platform-contracts/deployment",
4
+ "license": "Apache-2.0",
5
+ "sourceRevision": "754509cd760762e0c2e3fb00a644069dc1e2ecaf",
6
+ "files": {
7
+ "cli-transport.ts": "30d184604c8d78ce3b8c88d71b525234d716d40ead278f6aed44a0250aa0d9a4",
8
+ "source-profile.ts": "faf34ae54eb23881c4ec008f9fc59dbf6905fa04a912b66fe4f527a49d4b8490",
9
+ "source-bundle.ts": "99df4874f9337a604da544093215de24f19f136182017be15629f78b5180a52b",
10
+ "deployment.ts": "eb10b9eb771ef8a3f7a014ac473652d33fed6cb82969b3bc8a694dc48e267c0a",
11
+ "fixtures.json": "41803dffca899a95afc9b00fb6a71a317448b6344452d0b0440a8550b5b1f2f7",
12
+ "acceptance.mjs": "8e9d09d924ca7a7843d1578964243266641b09b339ea621b0981a7ccd28d4c5e",
13
+ "LICENSE": "6d89bce3e7760469015287d1b6a45d31ef7924475c9b54eabe974bcce373980b"
14
+ }
15
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "contractVersion": 1,
3
+ "owner": "anhedral/platform-contracts/environment",
4
+ "license": "Apache-2.0",
5
+ "sourceRevision": "0050910091dbc653c12118850af31655075f58c3",
6
+ "files": {
7
+ "environment-transport.ts": "833b61ecb43c2cbc86c15ed07092ddb364469681d03a23af94e805463c201940",
8
+ "environment-file.ts": "29b00c2babab896a6373f93ae5eb2672c00f25862b13b00c20e23a17d2dd83a3",
9
+ "LICENSE": "6d89bce3e7760469015287d1b6a45d31ef7924475c9b54eabe974bcce373980b"
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "contractVersion": 1,
3
+ "owner": "anhedral/platform-contracts/operations",
4
+ "license": "Apache-2.0",
5
+ "sourceRevision": "7ad79c1dfeb2675c98515507f609d95bee9133dd",
6
+ "files": {
7
+ "staging-transport.ts": "b5197c607492d7df912589e2707594210b92f06bf2db6b79931d620af4f49004",
8
+ "runtime-logs-transport.ts": "29f2da5209d2daa1e4edf5c478a0414e89497063503345d805e463e11da1bb78",
9
+ "LICENSE": "6d89bce3e7760469015287d1b6a45d31ef7924475c9b54eabe974bcce373980b"
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ import type { ApplicationContext } from './request-context';
2
+
3
+ export async function readApplicationStatus(context: ApplicationContext): Promise<{ api: boolean | null; authentication: boolean }> {
4
+ try {
5
+ if (!context.api) return { api: false, authentication: __AUTHENTICATION__ };
6
+ const response = await context.api.fetch(new Request('https://api.internal/api/health', { signal: AbortSignal.timeout(5000) }));
7
+ if (!response.ok) return { api: false, authentication: __AUTHENTICATION__ };
8
+ const result: unknown = await response.json();
9
+ return { api: typeof result === 'object' && result !== null && Reflect.get(result, 'ok') === true, authentication: __AUTHENTICATION__ };
10
+ } catch {
11
+ return { api: false, authentication: __AUTHENTICATION__ };
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ import { createAuthClient } from 'better-auth/react';
2
+
3
+ // Relative requests keep authentication on the application's public origin.
4
+ export const authClient = createAuthClient({ basePath: '/api/auth' });
@@ -0,0 +1,20 @@
1
+ import { starterTitle } from '../starter';
2
+ import { createFileRoute, useRouter } from '@tanstack/react-router';
3
+ import { createServerFn } from '@tanstack/react-start';
4
+ import { Button } from '@/components/ui/button';
5
+
6
+ const applicationStatus = createServerFn({ method: 'GET' }).handler(async ({ context }) => {
7
+ const { readApplicationStatus } = await import('../lib/application.server');
8
+ return readApplicationStatus(context);
9
+ });
10
+
11
+ export const Route = createFileRoute('/')({
12
+ loader: () => applicationStatus(),
13
+ component: Home,
14
+ });
15
+
16
+ function Home() {
17
+ const router = useRouter();
18
+ const status = Route.useLoaderData();
19
+ return <section className="stack"><h1>{starterTitle}</h1><p>Your web application is ready to build.</p><p data-rendering="server">Rendered on the server. {status.api === null ? 'Backend not added' : status.api ? 'API: connected' : 'API: unavailable'}.</p>{status.authentication && <a href="/sign-in">Your account</a>}<Button onClick={() => void router.invalidate()}>Check connection</Button></section>;
20
+ }
@@ -0,0 +1,5 @@
1
+ import type { ApplicationContext } from './request-context';
2
+
3
+ export async function readApplicationStatus(_context: ApplicationContext): Promise<{ api: boolean | null; authentication: boolean }> {
4
+ return { api: null, authentication: false };
5
+ }
@@ -0,0 +1,7 @@
1
+ import handler from '@tanstack/react-start/server-entry';
2
+
3
+ export default {
4
+ fetch(request: Request) {
5
+ return handler.fetch(request, { context: {} });
6
+ },
7
+ } satisfies ExportedHandler<Env>;
@@ -0,0 +1,3 @@
1
+ export interface ApplicationContext {
2
+ api?: { fetch(request: Request): Promise<Response> };
3
+ }
@@ -0,0 +1,27 @@
1
+ import { starterTitle } from '../starter';
2
+ import { createRootRoute, HeadContent, Link, Outlet, Scripts } from '@tanstack/react-router';
3
+ import type { ReactNode } from 'react';
4
+ import styles from '../styles.css?url';
5
+
6
+ export const Route = createRootRoute({
7
+ head: () => ({
8
+ meta: [
9
+ { charSet: 'utf-8' },
10
+ { name: 'viewport', content: 'width=device-width, initial-scale=1' },
11
+ { title: starterTitle },
12
+ { name: 'description', content: 'Anhedral web application' },
13
+ ],
14
+ links: [{ rel: 'stylesheet', href: styles }],
15
+ }),
16
+ component: Root,
17
+ notFoundComponent: () => <section className="stack"><h1>Page not found</h1><Link to="/">Return home</Link></section>,
18
+ errorComponent: ({ reset }) => <section className="stack"><h1>Unable to load this page</h1><button type="button" onClick={reset}>Try again</button></section>,
19
+ });
20
+
21
+ function Root() {
22
+ return <Document><main><nav aria-label="Main"><Link to="/">Home</Link></nav><Outlet /></main></Document>;
23
+ }
24
+
25
+ function Document({ children }: { children: ReactNode }) {
26
+ return <html lang="en"><head><HeadContent /></head><body>{children}<Scripts /></body></html>;
27
+ }
@@ -0,0 +1,21 @@
1
+ import { createRouter } from '@tanstack/react-router';
2
+ import { routeTree } from './routeTree.gen';
3
+ import type { ApplicationContext } from './lib/request-context';
4
+
5
+ export function getRouter() {
6
+ return createRouter({ routeTree, scrollRestoration: true });
7
+ }
8
+
9
+ declare module '@tanstack/react-router' {
10
+ interface Register {
11
+ router: ReturnType<typeof getRouter>;
12
+ server: { requestContext: ApplicationContext };
13
+ }
14
+ }
15
+
16
+ // Start's server-function context and Router's server-entry context share this contract.
17
+ declare module '@tanstack/react-start' {
18
+ interface Register {
19
+ server: { requestContext: ApplicationContext };
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ import handler from '@tanstack/react-start/server-entry';
2
+ import { proxyApi } from './lib/api-proxy';
3
+
4
+ export default {
5
+ fetch(request: Request, bindings: Env) {
6
+ const pathname = new URL(request.url).pathname;
7
+ if (pathname === '/api' || pathname.startsWith('/api/')) {
8
+ return proxyApi(request, { binding: bindings.ANHEDRAL_API, development: false });
9
+ }
10
+ // Start retains this server-owned capability only inside the current request.
11
+ return handler.fetch(request, { context: { api: bindings.ANHEDRAL_API } });
12
+ },
13
+ } satisfies ExportedHandler<Env>;
@@ -0,0 +1,53 @@
1
+ import { createFileRoute } from '@tanstack/react-router';
2
+ import { useState, type FormEvent } from 'react';
3
+ import { authClient } from '@/lib/auth-client';
4
+ import { Button } from '@/components/ui/button';
5
+ import { Input } from '@/components/ui/input';
6
+ import { Label } from '@/components/ui/label';
7
+
8
+ export const Route = createFileRoute('/sign-in')({ component: Account });
9
+
10
+ function Account() {
11
+ const { data: session, isPending, error: sessionError, refetch } = authClient.useSession();
12
+ const [creating, setCreating] = useState(false);
13
+ const [busy, setBusy] = useState(false);
14
+ const [error, setError] = useState('');
15
+ async function submit(event: FormEvent<HTMLFormElement>) {
16
+ event.preventDefault();
17
+ if (busy) return;
18
+ const data = new FormData(event.currentTarget);
19
+ const email = String(data.get('email') ?? '');
20
+ const password = String(data.get('password') ?? '');
21
+ setBusy(true);
22
+ setError('');
23
+ try {
24
+ const result = creating
25
+ ? await authClient.signUp.email({ email, password, name: String(data.get('name') ?? '') })
26
+ : await authClient.signIn.email({ email, password });
27
+ if (result.error) setError(result.error.message ?? 'Unable to sign in. Check your details and try again.');
28
+ else await refetch();
29
+ } catch {
30
+ setError('Unable to reach the account service. Try again.');
31
+ } finally {
32
+ setBusy(false);
33
+ }
34
+ }
35
+ async function signOut() {
36
+ if (busy) return;
37
+ setBusy(true);
38
+ setError('');
39
+ try {
40
+ const result = await authClient.signOut();
41
+ if (result.error) setError(result.error.message ?? 'Unable to sign out. Try again.');
42
+ else await refetch();
43
+ } catch {
44
+ setError('Unable to reach the account service. Try again.');
45
+ } finally {
46
+ setBusy(false);
47
+ }
48
+ }
49
+ if (isPending) return <p role="status">Loading your account…</p>;
50
+ if (sessionError) return <section className="stack"><h1>Account unavailable</h1><p role="alert">Unable to load your account. Check that the API and authentication are configured.</p><Button onClick={() => void refetch()}>Try again</Button></section>;
51
+ if (session) return <section className="stack"><h1>Your account</h1><p>{session.user.email}</p>{error && <p role="alert">{error}</p>}<Button disabled={busy} onClick={() => void signOut()}>{busy ? 'Signing out…' : 'Sign out'}</Button></section>;
52
+ return <section className="stack"><h1>{creating ? 'Create an account' : 'Sign in'}</h1><p className="muted">Email and password must be explicitly enabled in the API authentication configuration.</p><form onSubmit={submit}>{creating && <><Label htmlFor="name">Name</Label><Input id="name" name="name" autoComplete="name" required maxLength={160} /></>}<Label htmlFor="email">Email</Label><Input id="email" name="email" type="email" autoComplete="email" required maxLength={254} /><Label htmlFor="password">Password</Label><Input id="password" name="password" type="password" autoComplete={creating ? 'new-password' : 'current-password'} required minLength={8} maxLength={128} />{error && <p role="alert">{error}</p>}<Button type="submit" disabled={busy}>{busy ? 'Working…' : creating ? 'Create account' : 'Sign in'}</Button><Button type="button" variant="ghost" disabled={busy} onClick={() => { setCreating(!creating); setError(''); }}>{creating ? 'Already have an account? Sign in' : 'Create an account'}</Button></form></section>;
53
+ }
@@ -0,0 +1,19 @@
1
+ @import 'tailwindcss';
2
+ @import '@workspace/styling/globals.css';
3
+ @theme inline {
4
+ --color-background: hsl(var(--background)); --color-foreground: hsl(var(--foreground));
5
+ --color-primary: hsl(var(--primary)); --color-primary-foreground: hsl(var(--primary-foreground));
6
+ --color-secondary: hsl(var(--secondary)); --color-secondary-foreground: hsl(var(--secondary-foreground));
7
+ --color-muted: hsl(var(--muted)); --color-muted-foreground: hsl(var(--muted-foreground));
8
+ --color-border: hsl(var(--border)); --color-input: hsl(var(--input)); --color-ring: hsl(var(--ring));
9
+ --color-destructive: hsl(var(--destructive)); --radius-md: var(--radius); --radius-lg: calc(var(--radius) + 2px);
10
+ }
11
+ * { box-sizing: border-box; }
12
+ body { margin: 0; background: hsl(var(--background)); color: hsl(var(--foreground)); font-family: Arial, Helvetica, sans-serif; }
13
+ main { max-width: 64rem; margin: 0 auto; padding: 4rem 1.5rem; }
14
+ nav { display: flex; gap: 1rem; margin-bottom: 3rem; }
15
+ .stack, form { display: grid; gap: 1rem; }
16
+ form { width: 100%; max-width: 26rem; }
17
+ h1 { font-size: 2rem; font-weight: 600; line-height: 1.2; letter-spacing: -.025em; }
18
+ a { color: inherit; }
19
+ .muted { color: hsl(var(--muted-foreground)); }
@@ -0,0 +1,3 @@
1
+ export const CREDENTIAL_PATTERNS: ReadonlyArray<{ id: string; pattern: RegExp }>;
2
+ export function sourceContainsCredential(bytes: Uint8Array): boolean;
3
+ export function isCredentialPlaceholder(id: string, value: string): boolean;
@@ -0,0 +1,59 @@
1
+ // Shared high-confidence credential checks for release artifacts and source uploads.
2
+ // This is defense in depth; the service independently validates untrusted uploads.
3
+ export const CREDENTIAL_PATTERNS = Object.freeze([
4
+ { id: 'cli-session-token', pattern: /\bacl_[a-f0-9]{64}\b/g },
5
+ {
6
+ id: 'device-code',
7
+ pattern: /\bdevice_code["']?[ \t]*[:=][ \t]*["'][A-Za-z0-9_-]{20,191}["']/g,
8
+ },
9
+ { id: 'openai-project-key', pattern: /\bsk-proj-[A-Za-z0-9_-]{30,}/g },
10
+ { id: 'stripe-test-key', pattern: /\b(?:sk|rk)_test_[A-Za-z0-9]{24,}\b/g },
11
+ { id: 'private-key', pattern: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/g },
12
+ {
13
+ id: 'github-token',
14
+ pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})\b/g,
15
+ },
16
+ { id: 'npm-token', pattern: /\bnpm_[A-Za-z0-9]{30,}\b/g },
17
+ { id: 'stripe-live-key', pattern: /\b(?:sk|rk)_live_[A-Za-z0-9]{16,}\b/g },
18
+ { id: 'clerk-secret-key', pattern: /\bsk_(?:test|live)_[A-Za-z0-9_-]{24,}\b/g },
19
+ { id: 'slack-token', pattern: /\bxox[baprs]-[A-Za-z0-9-]{20,}\b/g },
20
+ { id: 'aws-access-key', pattern: /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g },
21
+ { id: 'google-api-key', pattern: /\bAIza[0-9A-Za-z_-]{35}\b/g },
22
+ {
23
+ id: 'credentialed-database-uri',
24
+ pattern:
25
+ /\b(?:postgres(?:ql)?|rediss|mongodb(?:\+srv)?):\/\/[^:/\s"'<>]+:[^@/\s"'<>]{8,}@[^\s/"'<>]+/gi,
26
+ },
27
+ {
28
+ id: 'credential-assignment',
29
+ pattern:
30
+ /\b[A-Z0-9_]*(?:SECRET|TOKEN|PASSWORD|API_KEY|ACCESS_KEY)[A-Z0-9_]*["']?\s*[:=]\s*["']?[A-Za-z0-9+/_=-]{32,}["']?/gi,
31
+ },
32
+ ]);
33
+
34
+ export function isCredentialPlaceholder(id, value) {
35
+ if (
36
+ id === 'credentialed-database-uri' &&
37
+ /^postgres(?:ql)?:\/\/\$\{[^{}]+\}:\$\{[^{}]+\}@\$\{[^{}]+\}$/.test(value)
38
+ )
39
+ return true;
40
+ if (id !== 'credential-assignment') return false;
41
+ const assigned = value.match(/[:=]\s*["']?([^"'\s]+)["']?$/)?.[1]?.toLowerCase();
42
+ return Boolean(
43
+ assigned &&
44
+ (['***', 'change-me', 'changeme', 'example', 'not-a-secret', 'replace-me'].includes(assigned) ||
45
+ /^(?:change|replace)(?:[-_ ]?me)?(?:[-_ ].*)?$/.test(assigned) ||
46
+ /^(?:placeholder|your value|your-value|your_value)$/.test(assigned)),
47
+ );
48
+ }
49
+
50
+ export function sourceContainsCredential(bytes) {
51
+ const text = new TextDecoder().decode(bytes);
52
+ return CREDENTIAL_PATTERNS.some(({ id, pattern }) => {
53
+ pattern.lastIndex = 0;
54
+ for (const match of text.matchAll(pattern)) {
55
+ if (!isCredentialPlaceholder(id, match[0])) return true;
56
+ }
57
+ return false;
58
+ });
59
+ }
@@ -1,5 +1,6 @@
1
1
  import { Hono } from 'hono';
2
2
  import { bodyLimit } from 'hono/body-limit';
3
+ import { HTTPException } from 'hono/http-exception';
3
4
  import { capabilities } from './capabilities';
4
5
  import type { AppEnv } from './environment';
5
6
 
@@ -11,5 +12,9 @@ app.use('/api/*', async (c, next) => {
11
12
  });
12
13
  app.get('/api/health', (c) => c.json({ ok: true }));
13
14
  app.route('/api', capabilities);
14
- app.onError((_error, c) => c.json({ error: 'Application request failed' }, 500));
15
+ app.onError((error, c) =>
16
+ error instanceof HTTPException && error.status < 500
17
+ ? error.getResponse()
18
+ : c.json({ error: 'Application request failed' }, 500),
19
+ );
15
20
  export default app;
@@ -0,0 +1,10 @@
1
+ -- Private event-feed consumer example, never a migration or scheduled CLI task.
2
+ -- Review the owner and cutoff against the active replay window before executing.
3
+ -- Delete at most 100 expired rows belonging to the selected authenticated owner.
4
+ DELETE FROM application_event
5
+ WHERE id IN (
6
+ SELECT id FROM application_event
7
+ WHERE user_id = ? AND created_at < ?
8
+ ORDER BY created_at, id
9
+ LIMIT 100
10
+ );
@@ -99,19 +99,36 @@ export async function stripeEntitled(env: AppEnv['Bindings'], userId: string) {
99
99
  requireMatchingKey(env, config.STRIPE_SECRET_KEY);
100
100
  const stripe = client(config.STRIPE_SECRET_KEY);
101
101
  const subject = userId.replaceAll('\\', '\\\\').replaceAll("'", "\\'");
102
- const found = await stripe.subscriptions.search({
103
- query: "metadata['userId']:'" + subject + "'",
104
- limit: 100,
105
- });
106
- const canonical = await Promise.all(
107
- found.data.map((value) => stripe.subscriptions.retrieve(value.id)),
108
- );
109
- return canonical.some(
110
- (value) =>
111
- value.metadata.userId === userId &&
112
- value.livemode === (billingEnvironment(env) === 'live') &&
113
- activePrice(value, config.STRIPE_PRICE_ID),
114
- );
102
+ let page: string | undefined;
103
+ for (let attempt = 0; attempt < 5; attempt++) {
104
+ const found = await stripe.subscriptions.search({
105
+ query: "metadata['userId']:'" + subject + "'",
106
+ limit: 100,
107
+ ...(page ? { page } : {}),
108
+ });
109
+ // Bound canonical reads; search results alone never grant access.
110
+ for (let offset = 0; offset < found.data.length; offset += 4) {
111
+ const canonical = await Promise.all(
112
+ found.data
113
+ .slice(offset, offset + 4)
114
+ .map((value) => stripe.subscriptions.retrieve(value.id)),
115
+ );
116
+ if (
117
+ canonical.some(
118
+ (value) =>
119
+ value.metadata.userId === userId &&
120
+ value.livemode === (billingEnvironment(env) === 'live') &&
121
+ activePrice(value, config.STRIPE_PRICE_ID),
122
+ )
123
+ )
124
+ return true;
125
+ }
126
+ if (!found.has_more) return false;
127
+ if (!found.next_page || found.next_page === page)
128
+ throw Error('Subscription search is incomplete');
129
+ page = found.next_page;
130
+ }
131
+ throw Error('Subscription search exceeds its bounded page budget');
115
132
  }
116
133
  stripeRoutes.get('/billing/status', requireSession, async (c) => {
117
134
  try {