@zaaxch/grasp-cli 0.0.0-stage → 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.
- package/README.md +7 -2
- package/bin/grasp.mjs +5 -0
- package/dist/check.d.ts +22 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +474 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +141 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-loader.d.ts +8 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +49 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/feature.d.ts +15 -0
- package/dist/feature.d.ts.map +1 -0
- package/dist/feature.js +262 -0
- package/dist/feature.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/new.d.ts +19 -0
- package/dist/new.d.ts.map +1 -0
- package/dist/new.js +320 -0
- package/dist/new.js.map +1 -0
- package/dist/sync.d.ts +26 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +79 -0
- package/dist/sync.js.map +1 -0
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +1188 -0
- package/dist/templates.js.map +1 -0
- package/package.json +61 -3
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
export const AGENTS_PRODUCT_NOTES_SENTINEL = '<!-- GRASP:PRODUCT_NOTES -->';
|
|
2
|
+
export function extractLockedAgentsSection(content) {
|
|
3
|
+
const idx = content.indexOf(AGENTS_PRODUCT_NOTES_SENTINEL);
|
|
4
|
+
if (idx === -1)
|
|
5
|
+
return content;
|
|
6
|
+
return content.slice(0, idx + AGENTS_PRODUCT_NOTES_SENTINEL.length) + '\n';
|
|
7
|
+
}
|
|
8
|
+
export function mergeAgentsWithProductNotes(lockedTemplate, existingContent) {
|
|
9
|
+
const lockedPart = extractLockedAgentsSection(lockedTemplate);
|
|
10
|
+
if (!existingContent) {
|
|
11
|
+
return `${lockedPart}\n<!-- Add app-specific product notes below this line. Content above the sentinel is byte-locked by \`grasp sync\`. -->\n`;
|
|
12
|
+
}
|
|
13
|
+
const idx = existingContent.indexOf(AGENTS_PRODUCT_NOTES_SENTINEL);
|
|
14
|
+
if (idx === -1) {
|
|
15
|
+
return `${lockedPart}\n<!-- Add app-specific product notes below this line. Content above the sentinel is byte-locked by \`grasp sync\`. -->\n`;
|
|
16
|
+
}
|
|
17
|
+
const suffix = existingContent.slice(idx + AGENTS_PRODUCT_NOTES_SENTINEL.length);
|
|
18
|
+
return `${lockedPart.replace(/\n$/, '')}${suffix}`;
|
|
19
|
+
}
|
|
20
|
+
function renderServerMainTs(config) {
|
|
21
|
+
const isMongo = config.database === 'mongo';
|
|
22
|
+
const dbImport = isMongo
|
|
23
|
+
? `import { createMongoStore } from '@zaaxch/grasp-mongo'`
|
|
24
|
+
: `import { createPostgresStore } from '@zaaxch/grasp-postgres'`;
|
|
25
|
+
const dbConnect = isMongo
|
|
26
|
+
? ` const mongoUri =
|
|
27
|
+
process.env['MONGODB_URI'] ?? 'mongodb://127.0.0.1:27017/?replicaSet=rs0&directConnection=true'
|
|
28
|
+
const mongoDbName = process.env['MONGODB_DB_NAME'] ?? config.app.name.replace(/-/g, '_')
|
|
29
|
+
const db = await createMongoStore({
|
|
30
|
+
uri: mongoUri,
|
|
31
|
+
dbName: mongoDbName,
|
|
32
|
+
collections: registeredCollections,
|
|
33
|
+
})`
|
|
34
|
+
: ` const postgresUrl = process.env['DATABASE_URL'] ?? 'postgresql://grasp:grasp@127.0.0.1:5432/grasp'
|
|
35
|
+
const db = await createPostgresStore({ connectionString: postgresUrl, tables: registeredTables })`;
|
|
36
|
+
return `import { existsSync } from 'node:fs'
|
|
37
|
+
import { dirname, resolve } from 'node:path'
|
|
38
|
+
import { fileURLToPath } from 'node:url'
|
|
39
|
+
import {
|
|
40
|
+
createBillingService,
|
|
41
|
+
createCompositeAuthVerifier,
|
|
42
|
+
createDevAuthManager,
|
|
43
|
+
createEmailAdapter,
|
|
44
|
+
createFirebaseAuthVerifier,
|
|
45
|
+
createGraspLogger,
|
|
46
|
+
createGraspServer,
|
|
47
|
+
createStripeProvider,
|
|
48
|
+
connectGraspRedis,
|
|
49
|
+
} from '@zaaxch/grasp-server'
|
|
50
|
+
${dbImport}
|
|
51
|
+
import config from '../../grasp.config.js'
|
|
52
|
+
import { appContract } from '../contracts/index.js'
|
|
53
|
+
import { serverFeatures, ${isMongo ? 'registeredCollections' : 'registeredTables'} } from './features/index.js'
|
|
54
|
+
|
|
55
|
+
const logger = createGraspLogger({
|
|
56
|
+
appName: config.app.name,
|
|
57
|
+
level: (process.env['LOG_LEVEL'] as 'info' | 'debug' | 'warn' | 'error' | undefined) ?? 'info',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
async function start(): Promise<void> {
|
|
61
|
+
${dbConnect}
|
|
62
|
+
const redis = await connectGraspRedis({
|
|
63
|
+
url: process.env['REDIS_URL'] ?? 'redis://127.0.0.1:6379',
|
|
64
|
+
})
|
|
65
|
+
const email = createEmailAdapter({ config, env: process.env, logger })
|
|
66
|
+
|
|
67
|
+
const devAuth =
|
|
68
|
+
process.env['NODE_ENV'] !== 'production' && process.env['GRASP_DEV_AUTH'] === 'true'
|
|
69
|
+
? createDevAuthManager(
|
|
70
|
+
process.env['GRASP_DEV_AUTH_SECRET']
|
|
71
|
+
? { secret: process.env['GRASP_DEV_AUTH_SECRET'] }
|
|
72
|
+
: {},
|
|
73
|
+
)
|
|
74
|
+
: undefined
|
|
75
|
+
|
|
76
|
+
const firebase =
|
|
77
|
+
process.env['FIREBASE_PROJECT_ID'] || process.env['GOOGLE_APPLICATION_CREDENTIALS']
|
|
78
|
+
? createFirebaseAuthVerifier({
|
|
79
|
+
...(process.env['FIREBASE_PROJECT_ID']
|
|
80
|
+
? { projectId: process.env['FIREBASE_PROJECT_ID'] }
|
|
81
|
+
: {}),
|
|
82
|
+
...(process.env['GOOGLE_APPLICATION_CREDENTIALS']
|
|
83
|
+
? { serviceAccountPath: process.env['GOOGLE_APPLICATION_CREDENTIALS'] }
|
|
84
|
+
: {}),
|
|
85
|
+
})
|
|
86
|
+
: undefined
|
|
87
|
+
|
|
88
|
+
const auth = createCompositeAuthVerifier({
|
|
89
|
+
...(firebase !== undefined ? { firebase } : {}),
|
|
90
|
+
...(devAuth !== undefined ? { devAuth } : {}),
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const stripeSecret = process.env['STRIPE_SECRET_KEY']?.trim()
|
|
94
|
+
const stripeWebhookSecret = process.env['STRIPE_WEBHOOK_SECRET']?.trim()
|
|
95
|
+
const provider =
|
|
96
|
+
stripeSecret && stripeWebhookSecret
|
|
97
|
+
? createStripeProvider({ secretKey: stripeSecret, webhookSecret: stripeWebhookSecret })
|
|
98
|
+
: undefined
|
|
99
|
+
|
|
100
|
+
const billing = createBillingService({
|
|
101
|
+
config,
|
|
102
|
+
store: db,
|
|
103
|
+
...(provider !== undefined ? { provider } : {}),
|
|
104
|
+
env: process.env,
|
|
105
|
+
...(process.env['APP_BASE_URL'] ? { baseUrl: process.env['APP_BASE_URL'] } : {}),
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
109
|
+
const compiledPublicDir = resolve(__dirname, '..', '..', 'public')
|
|
110
|
+
const publicDir = existsSync(compiledPublicDir)
|
|
111
|
+
? compiledPublicDir
|
|
112
|
+
: resolve(__dirname, '..', '..', 'dist', 'public')
|
|
113
|
+
|
|
114
|
+
const server = createGraspServer({
|
|
115
|
+
config,
|
|
116
|
+
appContract,
|
|
117
|
+
features: serverFeatures,
|
|
118
|
+
store: db,
|
|
119
|
+
db,
|
|
120
|
+
redis,
|
|
121
|
+
auth,
|
|
122
|
+
...(devAuth !== undefined ? { devAuth } : {}),
|
|
123
|
+
billing,
|
|
124
|
+
email,
|
|
125
|
+
logger,
|
|
126
|
+
publicDir,
|
|
127
|
+
trustProxy: process.env['NODE_ENV'] === 'production' ? 1 : false,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const port = Number(process.env['PORT'] ?? 3000)
|
|
131
|
+
await server.listen(port, '0.0.0.0')
|
|
132
|
+
logger.info('Grasp API server listening', { port, database: config.database })
|
|
133
|
+
|
|
134
|
+
let shuttingDown = false
|
|
135
|
+
const shutdown = async (signal: string): Promise<void> => {
|
|
136
|
+
if (shuttingDown) return
|
|
137
|
+
shuttingDown = true
|
|
138
|
+
logger.info('Shutting down Grasp API server', { signal })
|
|
139
|
+
await server.close()
|
|
140
|
+
await redis.close()
|
|
141
|
+
await db.close()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
process.once('SIGINT', () => {
|
|
145
|
+
void shutdown('SIGINT')
|
|
146
|
+
})
|
|
147
|
+
process.once('SIGTERM', () => {
|
|
148
|
+
void shutdown('SIGTERM')
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
void start().catch((err) => {
|
|
153
|
+
logger.error('Fatal server startup error', { error: err })
|
|
154
|
+
process.exitCode = 1
|
|
155
|
+
})
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
function renderServerWorkerTs(config) {
|
|
159
|
+
const isMongo = config.database === 'mongo';
|
|
160
|
+
const dbImport = isMongo
|
|
161
|
+
? `import { createMongoStore } from '@zaaxch/grasp-mongo'`
|
|
162
|
+
: `import { createPostgresStore } from '@zaaxch/grasp-postgres'`;
|
|
163
|
+
const dbConnect = isMongo
|
|
164
|
+
? ` const mongoUri =
|
|
165
|
+
process.env['MONGODB_URI'] ?? 'mongodb://127.0.0.1:27017/?replicaSet=rs0&directConnection=true'
|
|
166
|
+
const mongoDbName = process.env['MONGODB_DB_NAME'] ?? config.app.name.replace(/-/g, '_')
|
|
167
|
+
const db = await createMongoStore({
|
|
168
|
+
uri: mongoUri,
|
|
169
|
+
dbName: mongoDbName,
|
|
170
|
+
collections: registeredCollections,
|
|
171
|
+
})`
|
|
172
|
+
: ` const postgresUrl = process.env['DATABASE_URL'] ?? 'postgresql://grasp:grasp@127.0.0.1:5432/grasp'
|
|
173
|
+
const db = await createPostgresStore({ connectionString: postgresUrl, tables: registeredTables })`;
|
|
174
|
+
return `import {
|
|
175
|
+
connectGraspRedis,
|
|
176
|
+
createEmailAdapter,
|
|
177
|
+
createGraspLogger,
|
|
178
|
+
createGraspWorker,
|
|
179
|
+
} from '@zaaxch/grasp-server'
|
|
180
|
+
${dbImport}
|
|
181
|
+
import config from '../../grasp.config.js'
|
|
182
|
+
import { serverFeatures, ${isMongo ? 'registeredCollections' : 'registeredTables'} } from './features/index.js'
|
|
183
|
+
|
|
184
|
+
const logger = createGraspLogger({
|
|
185
|
+
appName: \`\${config.app.name}-worker\`,
|
|
186
|
+
level: (process.env['LOG_LEVEL'] as 'info' | 'debug' | 'warn' | 'error' | undefined) ?? 'info',
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
async function start(): Promise<void> {
|
|
190
|
+
${dbConnect}
|
|
191
|
+
const redis = await connectGraspRedis({
|
|
192
|
+
url: process.env['REDIS_URL'] ?? 'redis://127.0.0.1:6379',
|
|
193
|
+
})
|
|
194
|
+
const email = createEmailAdapter({ config, env: process.env, logger })
|
|
195
|
+
|
|
196
|
+
const worker = createGraspWorker({
|
|
197
|
+
store: db,
|
|
198
|
+
db,
|
|
199
|
+
redis,
|
|
200
|
+
email,
|
|
201
|
+
logger,
|
|
202
|
+
features: serverFeatures,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
await worker.start()
|
|
206
|
+
logger.info('Grasp worker started', { workerId: worker.workerId })
|
|
207
|
+
|
|
208
|
+
let shuttingDown = false
|
|
209
|
+
const shutdown = async (signal: string): Promise<void> => {
|
|
210
|
+
if (shuttingDown) return
|
|
211
|
+
shuttingDown = true
|
|
212
|
+
logger.info('Stopping Grasp worker', { signal })
|
|
213
|
+
await worker.stop()
|
|
214
|
+
await redis.close()
|
|
215
|
+
await db.close()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
process.once('SIGINT', () => {
|
|
219
|
+
void shutdown('SIGINT')
|
|
220
|
+
})
|
|
221
|
+
process.once('SIGTERM', () => {
|
|
222
|
+
void shutdown('SIGTERM')
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
void start().catch((err) => {
|
|
227
|
+
logger.error('Fatal worker startup error', { error: err })
|
|
228
|
+
process.exitCode = 1
|
|
229
|
+
})
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
function renderServerSchemaTs(config) {
|
|
233
|
+
const isMongo = config.database === 'mongo';
|
|
234
|
+
const dbImport = isMongo
|
|
235
|
+
? `import { createMongoStore } from '@zaaxch/grasp-mongo'`
|
|
236
|
+
: `import { createPostgresStore } from '@zaaxch/grasp-postgres'`;
|
|
237
|
+
const dbConnect = isMongo
|
|
238
|
+
? ` const mongoUri =
|
|
239
|
+
process.env['MONGODB_URI'] ?? 'mongodb://127.0.0.1:27017/?replicaSet=rs0&directConnection=true'
|
|
240
|
+
const mongoDbName = process.env['MONGODB_DB_NAME'] ?? config.app.name.replace(/-/g, '_')
|
|
241
|
+
const db = await createMongoStore({
|
|
242
|
+
uri: mongoUri,
|
|
243
|
+
dbName: mongoDbName,
|
|
244
|
+
collections: registeredCollections,
|
|
245
|
+
})`
|
|
246
|
+
: ` const postgresUrl = process.env['DATABASE_URL'] ?? 'postgresql://grasp:grasp@127.0.0.1:5432/grasp'
|
|
247
|
+
const db = await createPostgresStore({ connectionString: postgresUrl, tables: registeredTables })`;
|
|
248
|
+
return `${dbImport}
|
|
249
|
+
import config from '../../grasp.config.js'
|
|
250
|
+
import { ${isMongo ? 'registeredCollections' : 'registeredTables'} } from './features/index.js'
|
|
251
|
+
|
|
252
|
+
async function apply(): Promise<void> {
|
|
253
|
+
${dbConnect}
|
|
254
|
+
try {
|
|
255
|
+
const result = await db.applySchema()
|
|
256
|
+
console.log(JSON.stringify({ ok: true, applied: result.applied }))
|
|
257
|
+
} finally {
|
|
258
|
+
await db.close()
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
void apply().catch((err) => {
|
|
263
|
+
console.error(err)
|
|
264
|
+
process.exitCode = 1
|
|
265
|
+
})
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
function renderServerOpsTs(config) {
|
|
269
|
+
const isMongo = config.database === 'mongo';
|
|
270
|
+
const dbImport = isMongo
|
|
271
|
+
? `import { createMongoStore } from '@zaaxch/grasp-mongo'`
|
|
272
|
+
: `import { createPostgresStore } from '@zaaxch/grasp-postgres'`;
|
|
273
|
+
const dbConnect = isMongo
|
|
274
|
+
? ` const mongoUri =
|
|
275
|
+
process.env['MONGODB_URI'] ?? 'mongodb://127.0.0.1:27017/?replicaSet=rs0&directConnection=true'
|
|
276
|
+
const mongoDbName = process.env['MONGODB_DB_NAME'] ?? config.app.name.replace(/-/g, '_')
|
|
277
|
+
const db = await createMongoStore({
|
|
278
|
+
uri: mongoUri,
|
|
279
|
+
dbName: mongoDbName,
|
|
280
|
+
collections: registeredCollections,
|
|
281
|
+
})`
|
|
282
|
+
: ` const postgresUrl = process.env['DATABASE_URL'] ?? 'postgresql://grasp:grasp@127.0.0.1:5432/grasp'
|
|
283
|
+
const db = await createPostgresStore({ connectionString: postgresUrl, tables: registeredTables })`;
|
|
284
|
+
return `import {
|
|
285
|
+
createBillingService,
|
|
286
|
+
createDevAuthManager,
|
|
287
|
+
createStripeProvider,
|
|
288
|
+
runGraspOpsCli,
|
|
289
|
+
} from '@zaaxch/grasp-server'
|
|
290
|
+
${dbImport}
|
|
291
|
+
import config from '../../grasp.config.js'
|
|
292
|
+
import { ${isMongo ? 'registeredCollections' : 'registeredTables'} } from './features/index.js'
|
|
293
|
+
|
|
294
|
+
async function main(): Promise<void> {
|
|
295
|
+
${dbConnect}
|
|
296
|
+
try {
|
|
297
|
+
const stripeSecret = process.env['STRIPE_SECRET_KEY']?.trim()
|
|
298
|
+
const stripeWebhookSecret = process.env['STRIPE_WEBHOOK_SECRET']?.trim()
|
|
299
|
+
const provider =
|
|
300
|
+
stripeSecret && stripeWebhookSecret
|
|
301
|
+
? createStripeProvider({ secretKey: stripeSecret, webhookSecret: stripeWebhookSecret })
|
|
302
|
+
: undefined
|
|
303
|
+
const billing = createBillingService({
|
|
304
|
+
config,
|
|
305
|
+
store: db,
|
|
306
|
+
...(provider !== undefined ? { provider } : {}),
|
|
307
|
+
env: process.env,
|
|
308
|
+
})
|
|
309
|
+
const devAuth =
|
|
310
|
+
process.env['NODE_ENV'] !== 'production' && process.env['GRASP_DEV_AUTH'] === 'true'
|
|
311
|
+
? createDevAuthManager(
|
|
312
|
+
process.env['GRASP_DEV_AUTH_SECRET']
|
|
313
|
+
? { secret: process.env['GRASP_DEV_AUTH_SECRET'] }
|
|
314
|
+
: {},
|
|
315
|
+
)
|
|
316
|
+
: undefined
|
|
317
|
+
|
|
318
|
+
const res = await runGraspOpsCli(process.argv.slice(2), {
|
|
319
|
+
config,
|
|
320
|
+
store: db,
|
|
321
|
+
billing,
|
|
322
|
+
...(devAuth !== undefined ? { devAuth } : {}),
|
|
323
|
+
})
|
|
324
|
+
console.log(res.output)
|
|
325
|
+
process.exitCode = res.exitCode
|
|
326
|
+
} finally {
|
|
327
|
+
await db.close()
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
void main().catch((err) => {
|
|
332
|
+
console.error(err instanceof Error ? err.message : String(err))
|
|
333
|
+
process.exitCode = 1
|
|
334
|
+
})
|
|
335
|
+
`;
|
|
336
|
+
}
|
|
337
|
+
function renderWebMainTs(config) {
|
|
338
|
+
const customLayoutImport = config.ui.layout === 'custom' ? `import AppLayout from './AppLayout.vue'\n` : '';
|
|
339
|
+
const layoutOption = config.ui.layout === 'custom' ? ` layoutComponent: AppLayout,\n` : '';
|
|
340
|
+
return `import './styles.css'
|
|
341
|
+
import { createGraspVueApp } from '@zaaxch/grasp-vue'
|
|
342
|
+
import config from '../../grasp.config.js'
|
|
343
|
+
import { appContract } from '../contracts/index.js'
|
|
344
|
+
${customLayoutImport}import LandingPage from './LandingPage.vue'
|
|
345
|
+
import { featureNavItems, featureRoutes } from './features/index.js'
|
|
346
|
+
import { appTheme } from './theme.js'
|
|
347
|
+
|
|
348
|
+
const firebaseApiKey = import.meta.env['VITE_FIREBASE_API_KEY']
|
|
349
|
+
const firebaseProjectId = import.meta.env['VITE_FIREBASE_PROJECT_ID']
|
|
350
|
+
|
|
351
|
+
const app = createGraspVueApp({
|
|
352
|
+
config,
|
|
353
|
+
contract: appContract,
|
|
354
|
+
landingComponent: LandingPage,
|
|
355
|
+
featureRoutes,
|
|
356
|
+
navItems: featureNavItems,
|
|
357
|
+
${layoutOption} theme: appTheme,
|
|
358
|
+
authenticatedHome: featureNavItems[0]?.to ?? '/settings',
|
|
359
|
+
...(firebaseApiKey && firebaseProjectId
|
|
360
|
+
? {
|
|
361
|
+
firebaseConfig: {
|
|
362
|
+
apiKey: firebaseApiKey,
|
|
363
|
+
projectId: firebaseProjectId,
|
|
364
|
+
...(import.meta.env['VITE_FIREBASE_AUTH_DOMAIN']
|
|
365
|
+
? { authDomain: import.meta.env['VITE_FIREBASE_AUTH_DOMAIN'] }
|
|
366
|
+
: {}),
|
|
367
|
+
...(import.meta.env['VITE_FIREBASE_APP_ID']
|
|
368
|
+
? { appId: import.meta.env['VITE_FIREBASE_APP_ID'] }
|
|
369
|
+
: {}),
|
|
370
|
+
},
|
|
371
|
+
}
|
|
372
|
+
: {}),
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
app.mount('#app')
|
|
376
|
+
`;
|
|
377
|
+
}
|
|
378
|
+
function renderDockerComposeDev(config) {
|
|
379
|
+
const dbService = config.database === 'mongo'
|
|
380
|
+
? ` db:
|
|
381
|
+
image: mongo:8
|
|
382
|
+
command: ['--replSet', 'rs0', '--bind_ip_all', '--quiet']
|
|
383
|
+
volumes:
|
|
384
|
+
- grasp_dev_db:/data/db
|
|
385
|
+
healthcheck:
|
|
386
|
+
test:
|
|
387
|
+
[
|
|
388
|
+
'CMD',
|
|
389
|
+
'mongosh',
|
|
390
|
+
'--quiet',
|
|
391
|
+
'--eval',
|
|
392
|
+
"try { if (!rs.status().ok) throw 1; } catch (e) { rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'db:27017'}]}); } if (!db.hello().isWritablePrimary) quit(1);",
|
|
393
|
+
]
|
|
394
|
+
interval: 2s
|
|
395
|
+
timeout: 5s
|
|
396
|
+
retries: 25`
|
|
397
|
+
: ` db:
|
|
398
|
+
image: postgres:17-alpine
|
|
399
|
+
environment:
|
|
400
|
+
POSTGRES_USER: grasp
|
|
401
|
+
POSTGRES_PASSWORD: grasp_dev_password
|
|
402
|
+
POSTGRES_DB: ${config.app.name.replace(/-/g, '_')}
|
|
403
|
+
volumes:
|
|
404
|
+
- grasp_dev_db:/var/lib/postgresql/data
|
|
405
|
+
healthcheck:
|
|
406
|
+
test: ['CMD-SHELL', 'pg_isready -U grasp -d ${config.app.name.replace(/-/g, '_')}']
|
|
407
|
+
interval: 2s
|
|
408
|
+
timeout: 5s
|
|
409
|
+
retries: 25`;
|
|
410
|
+
const dbEnv = config.database === 'mongo'
|
|
411
|
+
? ` MONGODB_URI: mongodb://db:27017/?replicaSet=rs0&directConnection=true
|
|
412
|
+
MONGODB_DB_NAME: ${config.app.name.replace(/-/g, '_')}`
|
|
413
|
+
: ` DATABASE_URL: postgresql://grasp:grasp_dev_password@db:5432/${config.app.name.replace(/-/g, '_')}`;
|
|
414
|
+
const workerService = config.worker.enabled
|
|
415
|
+
? `
|
|
416
|
+
worker:
|
|
417
|
+
build:
|
|
418
|
+
context: .
|
|
419
|
+
dockerfile: Dockerfile.dev
|
|
420
|
+
command: pnpm dev:worker
|
|
421
|
+
depends_on:
|
|
422
|
+
schema-init:
|
|
423
|
+
condition: service_completed_successfully
|
|
424
|
+
redis:
|
|
425
|
+
condition: service_healthy
|
|
426
|
+
volumes:
|
|
427
|
+
- .:/app
|
|
428
|
+
- grasp_dev_node_modules:/app/node_modules
|
|
429
|
+
environment:
|
|
430
|
+
NODE_ENV: development
|
|
431
|
+
${dbEnv}
|
|
432
|
+
REDIS_URL: redis://redis:6379
|
|
433
|
+
GRASP_CAPTURE_EMAILS: 'true'`
|
|
434
|
+
: '';
|
|
435
|
+
return `services:
|
|
436
|
+
${dbService}
|
|
437
|
+
|
|
438
|
+
redis:
|
|
439
|
+
image: redis:7-alpine
|
|
440
|
+
healthcheck:
|
|
441
|
+
test: ['CMD', 'redis-cli', 'ping']
|
|
442
|
+
interval: 2s
|
|
443
|
+
timeout: 5s
|
|
444
|
+
retries: 20
|
|
445
|
+
|
|
446
|
+
schema-init:
|
|
447
|
+
build:
|
|
448
|
+
context: .
|
|
449
|
+
dockerfile: Dockerfile.dev
|
|
450
|
+
command: pnpm dev:schema
|
|
451
|
+
depends_on:
|
|
452
|
+
db:
|
|
453
|
+
condition: service_healthy
|
|
454
|
+
volumes:
|
|
455
|
+
- .:/app
|
|
456
|
+
- grasp_dev_node_modules:/app/node_modules
|
|
457
|
+
environment:
|
|
458
|
+
${dbEnv}
|
|
459
|
+
|
|
460
|
+
api:
|
|
461
|
+
build:
|
|
462
|
+
context: .
|
|
463
|
+
dockerfile: Dockerfile.dev
|
|
464
|
+
command: pnpm dev:server
|
|
465
|
+
depends_on:
|
|
466
|
+
schema-init:
|
|
467
|
+
condition: service_completed_successfully
|
|
468
|
+
redis:
|
|
469
|
+
condition: service_healthy
|
|
470
|
+
ports:
|
|
471
|
+
- '127.0.0.1:3000:3000'
|
|
472
|
+
volumes:
|
|
473
|
+
- .:/app
|
|
474
|
+
- grasp_dev_node_modules:/app/node_modules
|
|
475
|
+
environment:
|
|
476
|
+
NODE_ENV: development
|
|
477
|
+
PORT: '3000'
|
|
478
|
+
${dbEnv}
|
|
479
|
+
REDIS_URL: redis://redis:6379
|
|
480
|
+
GRASP_DEV_AUTH: 'true'
|
|
481
|
+
GRASP_CAPTURE_EMAILS: 'true'
|
|
482
|
+
${workerService}
|
|
483
|
+
|
|
484
|
+
web:
|
|
485
|
+
build:
|
|
486
|
+
context: .
|
|
487
|
+
dockerfile: Dockerfile.dev
|
|
488
|
+
command: pnpm dev:web
|
|
489
|
+
depends_on:
|
|
490
|
+
- api
|
|
491
|
+
ports:
|
|
492
|
+
- '127.0.0.1:5173:5173'
|
|
493
|
+
volumes:
|
|
494
|
+
- .:/app
|
|
495
|
+
- grasp_dev_node_modules:/app/node_modules
|
|
496
|
+
environment:
|
|
497
|
+
GRASP_API_ORIGIN: http://api:3000
|
|
498
|
+
|
|
499
|
+
volumes:
|
|
500
|
+
grasp_dev_db:
|
|
501
|
+
grasp_dev_node_modules:
|
|
502
|
+
`;
|
|
503
|
+
}
|
|
504
|
+
function renderDockerComposeTest(config) {
|
|
505
|
+
const dbService = config.database === 'mongo'
|
|
506
|
+
? ` db:
|
|
507
|
+
image: mongo:8
|
|
508
|
+
command: ['--replSet', 'rs0', '--bind_ip_all', '--quiet']
|
|
509
|
+
tmpfs:
|
|
510
|
+
- /data/db
|
|
511
|
+
healthcheck:
|
|
512
|
+
test:
|
|
513
|
+
[
|
|
514
|
+
'CMD',
|
|
515
|
+
'mongosh',
|
|
516
|
+
'--quiet',
|
|
517
|
+
'--eval',
|
|
518
|
+
"try { if (!rs.status().ok) throw 1; } catch (e) { rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'db:27017'}]}); } if (!db.hello().isWritablePrimary) quit(1);",
|
|
519
|
+
]
|
|
520
|
+
interval: 2s
|
|
521
|
+
timeout: 5s
|
|
522
|
+
retries: 25`
|
|
523
|
+
: ` db:
|
|
524
|
+
image: postgres:17-alpine
|
|
525
|
+
environment:
|
|
526
|
+
POSTGRES_USER: grasp
|
|
527
|
+
POSTGRES_PASSWORD: grasp_test_password
|
|
528
|
+
POSTGRES_DB: grasp_test
|
|
529
|
+
tmpfs:
|
|
530
|
+
- /var/lib/postgresql/data
|
|
531
|
+
healthcheck:
|
|
532
|
+
test: ['CMD-SHELL', 'pg_isready -U grasp -d grasp_test']
|
|
533
|
+
interval: 2s
|
|
534
|
+
timeout: 5s
|
|
535
|
+
retries: 25`;
|
|
536
|
+
const dbEnv = config.database === 'mongo'
|
|
537
|
+
? ` GRASP_TEST_MONGO_URI: mongodb://db:27017/?replicaSet=rs0&directConnection=true`
|
|
538
|
+
: ` GRASP_TEST_POSTGRES_URL: postgresql://grasp:grasp_test_password@db:5432/grasp_test`;
|
|
539
|
+
return `services:
|
|
540
|
+
${dbService}
|
|
541
|
+
|
|
542
|
+
redis:
|
|
543
|
+
image: redis:7-alpine
|
|
544
|
+
healthcheck:
|
|
545
|
+
test: ['CMD', 'redis-cli', 'ping']
|
|
546
|
+
interval: 2s
|
|
547
|
+
timeout: 5s
|
|
548
|
+
retries: 20
|
|
549
|
+
|
|
550
|
+
test:
|
|
551
|
+
build:
|
|
552
|
+
context: .
|
|
553
|
+
dockerfile: Dockerfile.dev
|
|
554
|
+
command: pnpm test
|
|
555
|
+
depends_on:
|
|
556
|
+
db:
|
|
557
|
+
condition: service_healthy
|
|
558
|
+
redis:
|
|
559
|
+
condition: service_healthy
|
|
560
|
+
volumes:
|
|
561
|
+
- .:/app
|
|
562
|
+
- grasp_test_node_modules:/app/node_modules
|
|
563
|
+
environment:
|
|
564
|
+
NODE_ENV: test
|
|
565
|
+
${dbEnv}
|
|
566
|
+
GRASP_TEST_REDIS_URL: redis://redis:6379
|
|
567
|
+
GRASP_DEV_AUTH: 'true'
|
|
568
|
+
GRASP_CAPTURE_EMAILS: 'true'
|
|
569
|
+
|
|
570
|
+
volumes:
|
|
571
|
+
grasp_test_node_modules:
|
|
572
|
+
`;
|
|
573
|
+
}
|
|
574
|
+
function renderDockerComposeProd(config) {
|
|
575
|
+
const dbName = config.app.name.replace(/-/g, '_');
|
|
576
|
+
const dbService = config.database === 'mongo'
|
|
577
|
+
? ` db:
|
|
578
|
+
image: mongo:8
|
|
579
|
+
restart: unless-stopped
|
|
580
|
+
command: ['--replSet', 'rs0', '--bind_ip_all', '--keyFile', '/etc/mongo-keyfile', '--auth']
|
|
581
|
+
environment:
|
|
582
|
+
MONGO_INITDB_ROOT_USERNAME: \${MONGO_ROOT_USER}
|
|
583
|
+
MONGO_INITDB_ROOT_PASSWORD: \${MONGO_ROOT_PASSWORD}
|
|
584
|
+
volumes:
|
|
585
|
+
- \${DATA_DIR}/mongo:/data/db
|
|
586
|
+
- \${SHARED_DIR}/mongo-keyfile:/etc/mongo-keyfile:ro
|
|
587
|
+
healthcheck:
|
|
588
|
+
test: ['CMD', 'mongosh', '--quiet', '--eval', 'db.adminCommand("ping").ok']
|
|
589
|
+
interval: 5s
|
|
590
|
+
timeout: 5s
|
|
591
|
+
retries: 20`
|
|
592
|
+
: ` db:
|
|
593
|
+
image: postgres:17-alpine
|
|
594
|
+
restart: unless-stopped
|
|
595
|
+
environment:
|
|
596
|
+
POSTGRES_USER: \${POSTGRES_ROOT_USER}
|
|
597
|
+
POSTGRES_PASSWORD: \${POSTGRES_ROOT_PASSWORD}
|
|
598
|
+
POSTGRES_DB: ${dbName}
|
|
599
|
+
volumes:
|
|
600
|
+
- \${DATA_DIR}/postgres:/var/lib/postgresql/data
|
|
601
|
+
healthcheck:
|
|
602
|
+
test: ['CMD-SHELL', 'pg_isready -U \${POSTGRES_ROOT_USER} -d ${dbName}']
|
|
603
|
+
interval: 5s
|
|
604
|
+
timeout: 5s
|
|
605
|
+
retries: 20`;
|
|
606
|
+
const dbEnv = config.database === 'mongo'
|
|
607
|
+
? ` MONGODB_URI: mongodb://\${MONGO_APP_USER}:\${MONGO_APP_PASSWORD}@db:27017/${dbName}?authSource=${dbName}&replicaSet=rs0&directConnection=true
|
|
608
|
+
MONGODB_DB_NAME: ${dbName}`
|
|
609
|
+
: ` DATABASE_URL: postgresql://\${POSTGRES_APP_USER}:\${POSTGRES_APP_PASSWORD}@db:5432/${dbName}`;
|
|
610
|
+
const workerService = config.worker.enabled
|
|
611
|
+
? `
|
|
612
|
+
worker:
|
|
613
|
+
image: \${GHCR_IMAGE}:\${IMAGE_TAG}
|
|
614
|
+
restart: unless-stopped
|
|
615
|
+
command: ['node', 'dist/src/server/worker.js']
|
|
616
|
+
env_file:
|
|
617
|
+
- \${SHARED_DIR}/.env.production
|
|
618
|
+
environment:
|
|
619
|
+
NODE_ENV: production
|
|
620
|
+
${dbEnv}
|
|
621
|
+
REDIS_URL: redis://:\${REDIS_PASSWORD}@redis:6379
|
|
622
|
+
depends_on:
|
|
623
|
+
schema-init:
|
|
624
|
+
condition: service_completed_successfully
|
|
625
|
+
redis:
|
|
626
|
+
condition: service_healthy`
|
|
627
|
+
: '';
|
|
628
|
+
return `services:
|
|
629
|
+
caddy:
|
|
630
|
+
image: caddy:2.11.4-alpine
|
|
631
|
+
restart: unless-stopped
|
|
632
|
+
ports:
|
|
633
|
+
- '80:80'
|
|
634
|
+
- '443:443'
|
|
635
|
+
volumes:
|
|
636
|
+
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
|
637
|
+
- \${SHARED_DIR}/caddy/data:/data
|
|
638
|
+
- \${SHARED_DIR}/caddy/config:/config
|
|
639
|
+
depends_on:
|
|
640
|
+
api:
|
|
641
|
+
condition: service_healthy
|
|
642
|
+
|
|
643
|
+
${dbService}
|
|
644
|
+
|
|
645
|
+
redis:
|
|
646
|
+
image: redis:7-alpine
|
|
647
|
+
restart: unless-stopped
|
|
648
|
+
command:
|
|
649
|
+
[
|
|
650
|
+
'redis-server',
|
|
651
|
+
'--requirepass',
|
|
652
|
+
'\${REDIS_PASSWORD}',
|
|
653
|
+
'--appendonly',
|
|
654
|
+
'yes',
|
|
655
|
+
'--appendfsync',
|
|
656
|
+
'everysec',
|
|
657
|
+
'--maxmemory-policy',
|
|
658
|
+
'noeviction',
|
|
659
|
+
]
|
|
660
|
+
volumes:
|
|
661
|
+
- \${DATA_DIR}/redis:/data
|
|
662
|
+
healthcheck:
|
|
663
|
+
test: ['CMD', 'redis-cli', '-a', '\${REDIS_PASSWORD}', 'ping']
|
|
664
|
+
interval: 5s
|
|
665
|
+
timeout: 5s
|
|
666
|
+
retries: 20
|
|
667
|
+
|
|
668
|
+
schema-init:
|
|
669
|
+
image: \${GHCR_IMAGE}:\${IMAGE_TAG}
|
|
670
|
+
command: ['node', 'dist/src/server/schema.js']
|
|
671
|
+
env_file:
|
|
672
|
+
- \${SHARED_DIR}/.env.production
|
|
673
|
+
environment:
|
|
674
|
+
NODE_ENV: production
|
|
675
|
+
${dbEnv}
|
|
676
|
+
depends_on:
|
|
677
|
+
db:
|
|
678
|
+
condition: service_healthy
|
|
679
|
+
|
|
680
|
+
api:
|
|
681
|
+
image: \${GHCR_IMAGE}:\${IMAGE_TAG}
|
|
682
|
+
restart: unless-stopped
|
|
683
|
+
env_file:
|
|
684
|
+
- \${SHARED_DIR}/.env.production
|
|
685
|
+
environment:
|
|
686
|
+
NODE_ENV: production
|
|
687
|
+
PORT: '3000'
|
|
688
|
+
APP_BASE_URL: https://${config.app.domain}
|
|
689
|
+
${dbEnv}
|
|
690
|
+
REDIS_URL: redis://:\${REDIS_PASSWORD}@redis:6379
|
|
691
|
+
healthcheck:
|
|
692
|
+
test:
|
|
693
|
+
[
|
|
694
|
+
'CMD',
|
|
695
|
+
'node',
|
|
696
|
+
'-e',
|
|
697
|
+
"fetch('http://127.0.0.1:3000/api/health').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))",
|
|
698
|
+
]
|
|
699
|
+
interval: 10s
|
|
700
|
+
timeout: 5s
|
|
701
|
+
retries: 10
|
|
702
|
+
depends_on:
|
|
703
|
+
schema-init:
|
|
704
|
+
condition: service_completed_successfully
|
|
705
|
+
redis:
|
|
706
|
+
condition: service_healthy
|
|
707
|
+
${workerService}
|
|
708
|
+
`;
|
|
709
|
+
}
|
|
710
|
+
export function generateLockedFiles(config) {
|
|
711
|
+
const domain = config.app.domain === 'localhost' ? ':80' : config.app.domain;
|
|
712
|
+
const dbName = config.app.name.replace(/-/g, '_');
|
|
713
|
+
const agentsMd = `# ${config.app.displayName} — Grasp Architecture Rules
|
|
714
|
+
|
|
715
|
+
This repository uses the **Grasp** immutable runtime shell.
|
|
716
|
+
|
|
717
|
+
## Non-Negotiable Rules
|
|
718
|
+
|
|
719
|
+
1. **Never edit byte-locked files** listed in \`grasp.lock.json\` (Docker, Compose, Caddyfile, CI workflows, \`src/server/{main,worker,schema,ops}.ts\`, \`src/web/main.ts\`, \`tsconfig*.json\`, \`vite.config.ts\`).
|
|
720
|
+
2. **Never import vendor drivers directly** inside \`src/contracts/\`, \`src/server/features/\`, or \`src/web/features/\`:
|
|
721
|
+
- Banned: \`express\`, \`stripe\`, \`firebase\`, \`firebase-admin\`, \`mongodb\`, \`mongoose\`, \`pg\`, \`postgres\`, \`redis\`, \`ioredis\`, \`axios\`, \`bull\`, \`bullmq\`, \`nodemailer\`, \`winston\`, \`cron-parser\`.
|
|
722
|
+
- Browser feature code must never call global \`fetch\` or \`new EventSource(...)\`; always use \`useGraspApi()\` / \`useGraspShell()\`.
|
|
723
|
+
3. **Directory lockdown**:
|
|
724
|
+
- All backend features live in \`src/server/features/<name>/<name>.{repo,procedures,service,jobs,eraser}.ts\`.
|
|
725
|
+
- \`<feature>.repo.ts\` is strictly private to \`<feature>\`; sibling features must import \`<feature>.service.ts\`.
|
|
726
|
+
- \`src/contracts/\` may only import \`zod\` and \`@zaaxch/grasp-core\`.
|
|
727
|
+
4. **Dependency allowlist**: Every external npm dependency must be declared in \`grasp.config.ts -> allowedDependencies\`.
|
|
728
|
+
5. **Always verify before finishing**: Run \`pnpm check\` (or \`npx grasp check\`), \`pnpm typecheck\`, and \`pnpm test\`.
|
|
729
|
+
|
|
730
|
+
${AGENTS_PRODUCT_NOTES_SENTINEL}
|
|
731
|
+
`;
|
|
732
|
+
const files = [
|
|
733
|
+
{
|
|
734
|
+
path: '.gitignore',
|
|
735
|
+
content: `node_modules/
|
|
736
|
+
dist/
|
|
737
|
+
coverage/
|
|
738
|
+
*.tsbuildinfo
|
|
739
|
+
.env
|
|
740
|
+
.env.*
|
|
741
|
+
!.env.example
|
|
742
|
+
!.env.*.example
|
|
743
|
+
.DS_Store
|
|
744
|
+
`,
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
path: '.gitattributes',
|
|
748
|
+
content: `* text=auto eol=lf
|
|
749
|
+
*.png binary
|
|
750
|
+
*.jpg binary
|
|
751
|
+
*.jpeg binary
|
|
752
|
+
*.gif binary
|
|
753
|
+
*.ico binary
|
|
754
|
+
*.webp binary
|
|
755
|
+
*.pdf binary
|
|
756
|
+
`,
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
path: '.prettierrc.json',
|
|
760
|
+
content: `{
|
|
761
|
+
"semi": false,
|
|
762
|
+
"singleQuote": true,
|
|
763
|
+
"trailingComma": "all",
|
|
764
|
+
"printWidth": 100,
|
|
765
|
+
"tabWidth": 2
|
|
766
|
+
}
|
|
767
|
+
`,
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
path: '.prettierignore',
|
|
771
|
+
content: `node_modules/
|
|
772
|
+
dist/
|
|
773
|
+
coverage/
|
|
774
|
+
pnpm-lock.yaml
|
|
775
|
+
grasp.lock.json
|
|
776
|
+
`,
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
path: 'tsconfig.json',
|
|
780
|
+
content: `{
|
|
781
|
+
"compilerOptions": {
|
|
782
|
+
"target": "ES2023",
|
|
783
|
+
"module": "NodeNext",
|
|
784
|
+
"moduleResolution": "NodeNext",
|
|
785
|
+
"strict": true,
|
|
786
|
+
"noUncheckedIndexedAccess": true,
|
|
787
|
+
"exactOptionalPropertyTypes": true,
|
|
788
|
+
"verbatimModuleSyntax": true,
|
|
789
|
+
"skipLibCheck": true,
|
|
790
|
+
"noEmit": true,
|
|
791
|
+
"types": ["node"]
|
|
792
|
+
},
|
|
793
|
+
"include": ["grasp.config.ts", "src/contracts/**/*.ts", "src/server/**/*.ts"]
|
|
794
|
+
}
|
|
795
|
+
`,
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
path: 'tsconfig.server.json',
|
|
799
|
+
content: `{
|
|
800
|
+
"compilerOptions": {
|
|
801
|
+
"target": "ES2023",
|
|
802
|
+
"module": "NodeNext",
|
|
803
|
+
"moduleResolution": "NodeNext",
|
|
804
|
+
"strict": true,
|
|
805
|
+
"noUncheckedIndexedAccess": true,
|
|
806
|
+
"exactOptionalPropertyTypes": true,
|
|
807
|
+
"verbatimModuleSyntax": true,
|
|
808
|
+
"skipLibCheck": true,
|
|
809
|
+
"rootDir": ".",
|
|
810
|
+
"outDir": "dist",
|
|
811
|
+
"types": ["node"]
|
|
812
|
+
},
|
|
813
|
+
"include": ["grasp.config.ts", "src/contracts/**/*.ts", "src/server/**/*.ts"],
|
|
814
|
+
"exclude": ["src/**/__tests__/**"]
|
|
815
|
+
}
|
|
816
|
+
`,
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
path: 'tsconfig.web.json',
|
|
820
|
+
content: `{
|
|
821
|
+
"compilerOptions": {
|
|
822
|
+
"target": "ES2023",
|
|
823
|
+
"module": "ESNext",
|
|
824
|
+
"moduleResolution": "Bundler",
|
|
825
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
826
|
+
"strict": true,
|
|
827
|
+
"noUncheckedIndexedAccess": true,
|
|
828
|
+
"exactOptionalPropertyTypes": true,
|
|
829
|
+
"verbatimModuleSyntax": true,
|
|
830
|
+
"skipLibCheck": true,
|
|
831
|
+
"noEmit": true,
|
|
832
|
+
"types": ["vite/client", "node"]
|
|
833
|
+
},
|
|
834
|
+
"include": ["grasp.config.ts", "src/contracts/**/*.ts", "src/web/**/*.ts", "src/web/**/*.vue"]
|
|
835
|
+
}
|
|
836
|
+
`,
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
path: 'vitest.config.ts',
|
|
840
|
+
content: `import vue from '@vitejs/plugin-vue'
|
|
841
|
+
import { defineConfig } from 'vitest/config'
|
|
842
|
+
|
|
843
|
+
export default defineConfig({
|
|
844
|
+
plugins: [vue()],
|
|
845
|
+
test: {
|
|
846
|
+
include: ['src/**/__tests__/**/*.test.ts'],
|
|
847
|
+
environment: 'node',
|
|
848
|
+
},
|
|
849
|
+
})
|
|
850
|
+
`,
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
path: 'index.html',
|
|
854
|
+
content: `<!doctype html>
|
|
855
|
+
<html lang="en">
|
|
856
|
+
<head>
|
|
857
|
+
<meta charset="UTF-8" />
|
|
858
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
859
|
+
<title>${config.app.displayName}</title>
|
|
860
|
+
</head>
|
|
861
|
+
<body>
|
|
862
|
+
<div id="app"></div>
|
|
863
|
+
<script type="module" src="/src/web/main.ts"></script>
|
|
864
|
+
</body>
|
|
865
|
+
</html>
|
|
866
|
+
`,
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
path: 'vite.config.ts',
|
|
870
|
+
content: `import tailwindcss from '@tailwindcss/vite'
|
|
871
|
+
import vue from '@vitejs/plugin-vue'
|
|
872
|
+
import { defineConfig } from 'vite'
|
|
873
|
+
|
|
874
|
+
export default defineConfig({
|
|
875
|
+
plugins: [vue(), tailwindcss()],
|
|
876
|
+
build: {
|
|
877
|
+
outDir: 'dist/public',
|
|
878
|
+
emptyOutDir: true,
|
|
879
|
+
},
|
|
880
|
+
server: {
|
|
881
|
+
host: '0.0.0.0',
|
|
882
|
+
port: 5173,
|
|
883
|
+
proxy: {
|
|
884
|
+
'/api': {
|
|
885
|
+
target: process.env['GRASP_API_ORIGIN'] ?? 'http://127.0.0.1:3000',
|
|
886
|
+
changeOrigin: true,
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
},
|
|
890
|
+
})
|
|
891
|
+
`,
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
path: 'src/server/main.ts',
|
|
895
|
+
content: renderServerMainTs(config),
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
path: 'src/server/worker.ts',
|
|
899
|
+
content: renderServerWorkerTs(config),
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
path: 'src/server/schema.ts',
|
|
903
|
+
content: renderServerSchemaTs(config),
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
path: 'src/server/ops.ts',
|
|
907
|
+
content: renderServerOpsTs(config),
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
path: 'src/web/main.ts',
|
|
911
|
+
content: renderWebMainTs(config),
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
path: 'Dockerfile',
|
|
915
|
+
content: `# syntax=docker/dockerfile:1
|
|
916
|
+
FROM node:24-alpine AS build
|
|
917
|
+
WORKDIR /app
|
|
918
|
+
RUN corepack enable && corepack prepare pnpm@11.22.0 --activate
|
|
919
|
+
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
|
920
|
+
RUN pnpm install --frozen-lockfile
|
|
921
|
+
COPY . .
|
|
922
|
+
RUN --mount=type=secret,id=ui_env_production,target=/app/.env.production,required=false \\
|
|
923
|
+
pnpm build
|
|
924
|
+
|
|
925
|
+
FROM node:24-alpine AS prod
|
|
926
|
+
WORKDIR /app
|
|
927
|
+
ENV NODE_ENV=production
|
|
928
|
+
RUN corepack enable && corepack prepare pnpm@11.22.0 --activate
|
|
929
|
+
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
|
930
|
+
RUN pnpm install --prod --frozen-lockfile
|
|
931
|
+
COPY --from=build /app/dist ./dist
|
|
932
|
+
COPY --from=build /app/grasp.config.ts ./grasp.config.ts
|
|
933
|
+
USER node
|
|
934
|
+
EXPOSE 3000
|
|
935
|
+
CMD ["node", "dist/src/server/main.js"]
|
|
936
|
+
`,
|
|
937
|
+
},
|
|
938
|
+
{
|
|
939
|
+
path: 'Dockerfile.dev',
|
|
940
|
+
content: `FROM node:24-alpine
|
|
941
|
+
WORKDIR /app
|
|
942
|
+
RUN corepack enable && corepack prepare pnpm@11.22.0 --activate
|
|
943
|
+
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
|
944
|
+
RUN pnpm install --frozen-lockfile || pnpm install
|
|
945
|
+
COPY . .
|
|
946
|
+
`,
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
path: 'docker-compose.dev.yml',
|
|
950
|
+
content: renderDockerComposeDev(config),
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
path: 'docker-compose.test.yml',
|
|
954
|
+
content: renderDockerComposeTest(config),
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
path: 'docker-compose.yml',
|
|
958
|
+
content: renderDockerComposeProd(config),
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
path: 'Caddyfile',
|
|
962
|
+
content: `${domain} {
|
|
963
|
+
encode zstd gzip
|
|
964
|
+
reverse_proxy api:3000
|
|
965
|
+
}
|
|
966
|
+
`,
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
path: 'deploy/deploy_remote.sh',
|
|
970
|
+
mode: 'executable',
|
|
971
|
+
content: `#!/usr/bin/env bash
|
|
972
|
+
set -euo pipefail
|
|
973
|
+
|
|
974
|
+
IMAGE_TAG="\${1:?Missing 40-char SHA image tag}"
|
|
975
|
+
GHCR_IMAGE="\${2:?Missing GHCR image name}"
|
|
976
|
+
|
|
977
|
+
APP_ROOT="/opt/${config.app.name}"
|
|
978
|
+
CURRENT_DIR="\${APP_ROOT}/current"
|
|
979
|
+
SHARED_DIR="\${APP_ROOT}/shared"
|
|
980
|
+
INFRA_ENV="\${SHARED_DIR}/.env.infrastructure"
|
|
981
|
+
|
|
982
|
+
if [[ ! -f "\${INFRA_ENV}" ]]; then
|
|
983
|
+
echo "Missing \${INFRA_ENV}" >&2
|
|
984
|
+
exit 1
|
|
985
|
+
fi
|
|
986
|
+
|
|
987
|
+
TMP_ENV="\$(mktemp)"
|
|
988
|
+
grep -v -E '^(IMAGE_TAG|GHCR_IMAGE)=' "\${INFRA_ENV}" > "\${TMP_ENV}" || true
|
|
989
|
+
printf 'GHCR_IMAGE=%s\\nIMAGE_TAG=%s\\n' "\${GHCR_IMAGE}" "\${IMAGE_TAG}" >> "\${TMP_ENV}"
|
|
990
|
+
chmod 600 "\${TMP_ENV}"
|
|
991
|
+
mv "\${TMP_ENV}" "\${INFRA_ENV}"
|
|
992
|
+
|
|
993
|
+
cd "\${CURRENT_DIR}"
|
|
994
|
+
docker compose --env-file "\${INFRA_ENV}" config -q
|
|
995
|
+
docker compose --env-file "\${INFRA_ENV}" pull
|
|
996
|
+
docker compose --env-file "\${INFRA_ENV}" up -d --wait
|
|
997
|
+
docker compose --env-file "\${INFRA_ENV}" up -d --force-recreate --no-deps caddy
|
|
998
|
+
`,
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
path: '.env.production.example',
|
|
1002
|
+
content: `FIREBASE_PROJECT_ID=
|
|
1003
|
+
GOOGLE_APPLICATION_CREDENTIALS=/opt/${config.app.name}/shared/firebase-sa.json
|
|
1004
|
+
STRIPE_SECRET_KEY=
|
|
1005
|
+
STRIPE_WEBHOOK_SECRET=
|
|
1006
|
+
RESEND_API_KEY=
|
|
1007
|
+
EMAIL_FROM=noreply@${config.app.domain}
|
|
1008
|
+
LOG_LEVEL=info
|
|
1009
|
+
`,
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
path: '.env.infrastructure.example',
|
|
1013
|
+
content: `SHARED_DIR=/opt/${config.app.name}/shared
|
|
1014
|
+
DATA_DIR=/opt/${config.app.name}/shared/data
|
|
1015
|
+
GHCR_IMAGE=ghcr.io/owner/${config.app.name}
|
|
1016
|
+
IMAGE_TAG=0000000000000000000000000000000000000000
|
|
1017
|
+
REDIS_PASSWORD=change-me
|
|
1018
|
+
${config.database === 'mongo' ? `MONGO_ROOT_USER=root\nMONGO_ROOT_PASSWORD=change-me\nMONGO_APP_USER=${dbName}\nMONGO_APP_PASSWORD=change-me` : `POSTGRES_ROOT_USER=postgres\nPOSTGRES_ROOT_PASSWORD=change-me\nPOSTGRES_APP_USER=${dbName}\nPOSTGRES_APP_PASSWORD=change-me`}
|
|
1019
|
+
`,
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
path: '.github/workflows/release-image.yml',
|
|
1023
|
+
content: `name: Validate and publish release image
|
|
1024
|
+
|
|
1025
|
+
on:
|
|
1026
|
+
pull_request:
|
|
1027
|
+
branches: [main]
|
|
1028
|
+
push:
|
|
1029
|
+
branches: [main]
|
|
1030
|
+
|
|
1031
|
+
permissions:
|
|
1032
|
+
contents: read
|
|
1033
|
+
packages: write
|
|
1034
|
+
|
|
1035
|
+
jobs:
|
|
1036
|
+
validate:
|
|
1037
|
+
runs-on: ubuntu-latest
|
|
1038
|
+
steps:
|
|
1039
|
+
- uses: actions/checkout@v6
|
|
1040
|
+
- uses: pnpm/action-setup@v4
|
|
1041
|
+
with:
|
|
1042
|
+
version: 11.22.0
|
|
1043
|
+
- uses: actions/setup-node@v6
|
|
1044
|
+
with:
|
|
1045
|
+
node-version: 24
|
|
1046
|
+
cache: pnpm
|
|
1047
|
+
- run: pnpm install --frozen-lockfile
|
|
1048
|
+
- run: pnpm check
|
|
1049
|
+
- run: pnpm typecheck
|
|
1050
|
+
- run: pnpm build
|
|
1051
|
+
- run: docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from test
|
|
1052
|
+
|
|
1053
|
+
publish:
|
|
1054
|
+
needs: validate
|
|
1055
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
1056
|
+
runs-on: ubuntu-latest
|
|
1057
|
+
steps:
|
|
1058
|
+
- uses: actions/checkout@v6
|
|
1059
|
+
- uses: docker/login-action@v3
|
|
1060
|
+
with:
|
|
1061
|
+
registry: ghcr.io
|
|
1062
|
+
username: \${{ github.actor }}
|
|
1063
|
+
password: \${{ secrets.GITHUB_TOKEN }}
|
|
1064
|
+
- uses: docker/setup-buildx-action@v3
|
|
1065
|
+
- name: Write UI production env
|
|
1066
|
+
env:
|
|
1067
|
+
UI_ENV_PRODUCTION: \${{ secrets.UI_ENV_PRODUCTION }}
|
|
1068
|
+
run: printf '%s\\n' "$UI_ENV_PRODUCTION" > .env.production.build
|
|
1069
|
+
- uses: docker/build-push-action@v6
|
|
1070
|
+
with:
|
|
1071
|
+
context: .
|
|
1072
|
+
push: true
|
|
1073
|
+
tags: ghcr.io/\${{ github.repository_owner }}/${config.app.name}:\${{ github.sha }}
|
|
1074
|
+
secrets: |
|
|
1075
|
+
"ui_env_production=.env.production.build"
|
|
1076
|
+
`,
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
path: '.github/workflows/deploy.yml',
|
|
1080
|
+
content: `name: Deploy release image to DigitalOcean
|
|
1081
|
+
|
|
1082
|
+
on:
|
|
1083
|
+
workflow_dispatch:
|
|
1084
|
+
inputs:
|
|
1085
|
+
image_tag:
|
|
1086
|
+
description: Full 40-character commit SHA published to ghcr.io
|
|
1087
|
+
required: true
|
|
1088
|
+
type: string
|
|
1089
|
+
|
|
1090
|
+
permissions:
|
|
1091
|
+
contents: read
|
|
1092
|
+
packages: read
|
|
1093
|
+
|
|
1094
|
+
jobs:
|
|
1095
|
+
deploy:
|
|
1096
|
+
runs-on: ubuntu-latest
|
|
1097
|
+
environment: production
|
|
1098
|
+
steps:
|
|
1099
|
+
- run: '[[ "\${{ inputs.image_tag }}" =~ ^[0-9a-f]{40}$ ]]'
|
|
1100
|
+
- uses: actions/checkout@v6
|
|
1101
|
+
with:
|
|
1102
|
+
ref: \${{ inputs.image_tag }}
|
|
1103
|
+
fetch-depth: 0
|
|
1104
|
+
- run: git merge-base --is-ancestor \${{ inputs.image_tag }} origin/main
|
|
1105
|
+
- name: Configure SSH and deploy
|
|
1106
|
+
env:
|
|
1107
|
+
DEPLOY_HOST: \${{ vars.DEPLOY_HOST }}
|
|
1108
|
+
DEPLOY_USER: \${{ vars.DEPLOY_USER }}
|
|
1109
|
+
DEPLOY_SSH_KEY: \${{ secrets.DEPLOY_SSH_KEY }}
|
|
1110
|
+
GHCR_PULL_TOKEN: \${{ secrets.GITHUB_TOKEN }}
|
|
1111
|
+
run: |
|
|
1112
|
+
install -m 700 -d ~/.ssh
|
|
1113
|
+
printf '%s\\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_deploy
|
|
1114
|
+
chmod 600 ~/.ssh/id_deploy
|
|
1115
|
+
ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_deploy "\${DEPLOY_USER}@\${DEPLOY_HOST}" \\
|
|
1116
|
+
"echo '$GHCR_PULL_TOKEN' | docker login ghcr.io -u '\${{ github.actor }}' --password-stdin && install -m 755 -d /opt/${config.app.name}/current/deploy"
|
|
1117
|
+
scp -i ~/.ssh/id_deploy docker-compose.yml Caddyfile "\${DEPLOY_USER}@\${DEPLOY_HOST}:/opt/${config.app.name}/current/"
|
|
1118
|
+
scp -i ~/.ssh/id_deploy deploy/deploy_remote.sh "\${DEPLOY_USER}@\${DEPLOY_HOST}:/opt/${config.app.name}/current/deploy/"
|
|
1119
|
+
ssh -i ~/.ssh/id_deploy "\${DEPLOY_USER}@\${DEPLOY_HOST}" \\
|
|
1120
|
+
"chmod +x /opt/${config.app.name}/current/deploy/deploy_remote.sh && /opt/${config.app.name}/current/deploy/deploy_remote.sh '\${{ inputs.image_tag }}' 'ghcr.io/\${{ github.repository_owner }}/${config.app.name}'"
|
|
1121
|
+
`,
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
path: 'AGENTS.md',
|
|
1125
|
+
content: agentsMd,
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
path: 'CLAUDE.md',
|
|
1129
|
+
content: `# Claude Code Guidance
|
|
1130
|
+
|
|
1131
|
+
Read [AGENTS.md](./AGENTS.md) and the local skills under [\`.agents/skills/\`](./.agents/skills/) before modifying any files in this Grasp project.
|
|
1132
|
+
`,
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
path: '.agents/skills/add-feature/SKILL.md',
|
|
1136
|
+
content: `---
|
|
1137
|
+
name: add-feature
|
|
1138
|
+
description: Scaffold and implement a new full-stack vertical feature slice following Grasp boundaries.
|
|
1139
|
+
---
|
|
1140
|
+
|
|
1141
|
+
1. Run \`npx grasp feature <name>\` (camelCase lowercase start, e.g. \`projects\`).
|
|
1142
|
+
2. Edit \`src/contracts/<name>.contract.ts\` using \`zod\` + \`@zaaxch/grasp-core\`.
|
|
1143
|
+
3. Implement persistence exclusively in \`src/server/features/<name>/<name>.repo.ts\`.
|
|
1144
|
+
4. Implement handlers in \`src/server/features/<name>/<name>.procedures.ts\`.
|
|
1145
|
+
5. Build views under \`src/web/features/<name>/views/\` using \`useGraspApi()\` and PrimeVue 4 + Tailwind.
|
|
1146
|
+
6. Run \`pnpm check && pnpm typecheck && pnpm test\`.
|
|
1147
|
+
`,
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
path: '.agents/skills/add-job/SKILL.md',
|
|
1151
|
+
content: `---
|
|
1152
|
+
name: add-job
|
|
1153
|
+
description: Add a background outbox job or distributed cron schedule to an existing feature slice.
|
|
1154
|
+
---
|
|
1155
|
+
|
|
1156
|
+
1. Create \`src/server/features/<feature>/<feature>.jobs.ts\` using \`defineJob\` / \`defineSchedule\` from \`@zaaxch/grasp-server\`.
|
|
1157
|
+
2. Export jobs/schedules via \`defineServerFeature\` in \`src/server/features/index.ts\`.
|
|
1158
|
+
3. Enqueue jobs transactionally from procedures via \`ctx.jobs.enqueue(job, payload, { tx })\`.
|
|
1159
|
+
`,
|
|
1160
|
+
},
|
|
1161
|
+
{
|
|
1162
|
+
path: '.agents/skills/configure-billing/SKILL.md',
|
|
1163
|
+
content: `---
|
|
1164
|
+
name: configure-billing
|
|
1165
|
+
description: Configure Stripe plans, trial days, limits, and credit packs declaratively.
|
|
1166
|
+
---
|
|
1167
|
+
|
|
1168
|
+
1. Edit \`grasp.config.ts\` under \`billing.freePlan\`, \`billing.plans\`, and \`billing.creditPacks\`.
|
|
1169
|
+
2. Ensure \`freePlan.limits\` and every paid plan share the exact same limit keys.
|
|
1170
|
+
3. Enforce gates via procedure \`entitlement: { minPlan, requireLimit }\`, \`ctx.quota.consumeWithQuota\`, and \`ctx.credits.spendCredits\`.
|
|
1171
|
+
`,
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
path: '.agents/skills/customize-ui/SKILL.md',
|
|
1175
|
+
content: `---
|
|
1176
|
+
name: customize-ui
|
|
1177
|
+
description: Customize app branding, theme tokens, landing page, or AppLayout without mutating the shell.
|
|
1178
|
+
---
|
|
1179
|
+
|
|
1180
|
+
1. Customize PrimeVue preset & CSS variables in \`src/web/theme.ts\` and Tailwind tokens in \`src/web/styles.css\`.
|
|
1181
|
+
2. Edit \`src/web/LandingPage.vue\` for unique marketing/hero UI.
|
|
1182
|
+
3. Set \`ui.layout: 'custom'\` in \`grasp.config.ts\` and create \`src/web/AppLayout.vue\` if custom navigation chrome is needed, then run \`npx grasp sync\`.
|
|
1183
|
+
`,
|
|
1184
|
+
},
|
|
1185
|
+
];
|
|
1186
|
+
return files;
|
|
1187
|
+
}
|
|
1188
|
+
//# sourceMappingURL=templates.js.map
|