@zaaxch/grasp-cli 0.0.0-stage → 0.2.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/dist/new.js ADDED
@@ -0,0 +1,321 @@
1
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ import { APP_SLUG_REGEX, GraspError } from '@zaaxch/grasp-core';
4
+ import { syncProject } from './sync.js';
5
+ function toDisplayName(slug) {
6
+ return slug
7
+ .split('-')
8
+ .filter(Boolean)
9
+ .map((part) => part[0].toUpperCase() + part.slice(1))
10
+ .join(' ');
11
+ }
12
+ function writeScaffoldFile(rootDir, relPath, content, out) {
13
+ const full = join(rootDir, relPath);
14
+ mkdirSync(resolve(full, '..'), { recursive: true });
15
+ writeFileSync(full, content, 'utf8');
16
+ out.push(relPath);
17
+ }
18
+ /**
19
+ * Scaffolds a new single-package Grasp application repository and locks its infrastructure.
20
+ */
21
+ export async function createNewProject(options) {
22
+ if (!APP_SLUG_REGEX.test(options.name)) {
23
+ throw GraspError.validation('Invalid app slug', [
24
+ {
25
+ path: ['name'],
26
+ message: `App name "${options.name}" must match ${APP_SLUG_REGEX.source}`,
27
+ },
28
+ ]);
29
+ }
30
+ const database = options.database ?? 'mongo';
31
+ const displayName = options.displayName?.trim() || toDisplayName(options.name);
32
+ const domain = options.domain?.trim() || `${options.name}.example.com`;
33
+ const version = options.graspVersion ?? '0.2.0';
34
+ const pkgVer = options.workspaceProtocol ? 'workspace:*' : `^${version}`;
35
+ const parentAbs = resolve(options.parentDir);
36
+ if (!existsSync(parentAbs)) {
37
+ throw GraspError.notFound(`Parent directory does not exist: ${parentAbs}`);
38
+ }
39
+ const rootDir = join(parentAbs, options.name);
40
+ if (existsSync(rootDir) && readdirSync(rootDir).length > 0) {
41
+ throw GraspError.conflict(`Target directory already exists and is not empty: ${rootDir}`);
42
+ }
43
+ mkdirSync(rootDir, { recursive: true });
44
+ const created = [];
45
+ const isMongo = database === 'mongo';
46
+ const dbDep = isMongo ? '@zaaxch/grasp-mongo' : '@zaaxch/grasp-postgres';
47
+ const pkgJson = {
48
+ name: options.name,
49
+ version: '0.1.0',
50
+ private: true,
51
+ type: 'module',
52
+ packageManager: 'pnpm@11.22.0',
53
+ engines: { node: '>=24.0.0' },
54
+ scripts: {
55
+ dev: 'docker compose -f docker-compose.dev.yml up --build',
56
+ 'dev:server': 'node --watch --experimental-strip-types src/server/main.ts',
57
+ 'dev:worker': 'node --watch --experimental-strip-types src/server/worker.ts',
58
+ 'dev:schema': 'node --experimental-strip-types src/server/schema.ts',
59
+ 'dev:ops': 'node --experimental-strip-types src/server/ops.ts',
60
+ 'dev:mcp': 'node --watch --experimental-strip-types src/server/mcp.ts',
61
+ 'dev:web': 'vite',
62
+ 'schema:apply': 'node dist/src/server/schema.js',
63
+ ops: 'node dist/src/server/ops.js',
64
+ 'build:server': 'tsc -p tsconfig.server.json',
65
+ 'build:web': 'vite build',
66
+ build: 'pnpm build:server && pnpm build:web',
67
+ typecheck: 'tsc -p tsconfig.json --noEmit && vue-tsc -p tsconfig.web.json --noEmit',
68
+ test: 'vitest run',
69
+ check: 'grasp check',
70
+ sync: 'grasp sync',
71
+ format: 'prettier --write .',
72
+ },
73
+ dependencies: {
74
+ '@zaaxch/grasp-core': pkgVer,
75
+ [dbDep]: pkgVer,
76
+ '@zaaxch/grasp-server': pkgVer,
77
+ zod: '^4.6.7',
78
+ },
79
+ devDependencies: {
80
+ '@primeuix/themes': '^2.0.3',
81
+ '@tailwindcss/vite': '^4.3.5',
82
+ '@types/node': '^24.19.2',
83
+ '@vitejs/plugin-vue': '^6.0.11',
84
+ '@vue/test-utils': '^2.6.0',
85
+ '@zaaxch/grasp-cli': pkgVer,
86
+ '@zaaxch/grasp-vue': pkgVer,
87
+ firebase: '^13.4.0',
88
+ 'happy-dom': '^21.0.4',
89
+ pinia: '^3.0.4',
90
+ prettier: '^3.10.1',
91
+ primevue: '^4.5.5',
92
+ tailwindcss: '^4.3.5',
93
+ typescript: '^5.9.3',
94
+ vite: '^8.3.8',
95
+ vitest: '^5.1.1',
96
+ vue: '^3.5.46',
97
+ 'vue-router': '^4.6.5',
98
+ 'vue-tsc': '^3.3.14',
99
+ },
100
+ };
101
+ writeScaffoldFile(rootDir, 'package.json', `${JSON.stringify(pkgJson, null, 2)}\n`, created);
102
+ if (!options.workspaceProtocol) {
103
+ writeScaffoldFile(rootDir, 'pnpm-workspace.yaml', `allowBuilds:
104
+ '@firebase/util': false
105
+ esbuild: true
106
+ protobufjs: false
107
+ minimumReleaseAgeExclude:
108
+ - '@zaaxch/*'
109
+ - '@vue/*'
110
+ - nodemailer
111
+ - vue
112
+ `, created);
113
+ }
114
+ writeScaffoldFile(rootDir, 'grasp.config.ts', `import { defineGraspConfig } from '@zaaxch/grasp-core'
115
+
116
+ export default defineGraspConfig({
117
+ app: {
118
+ name: '${options.name}',
119
+ displayName: '${displayName}',
120
+ domain: '${domain}',
121
+ },
122
+ database: '${database}',
123
+ worker: { enabled: true },
124
+ email: { provider: 'disabled' },
125
+ auth: { providers: ['google'] },
126
+ billing: {
127
+ enabled: true,
128
+ freePlan: {
129
+ id: 'free',
130
+ name: 'Starter',
131
+ limits: { maxItems: 5 },
132
+ },
133
+ plans: [
134
+ {
135
+ id: 'pro',
136
+ name: 'Pro',
137
+ rank: 1,
138
+ trialDays: 14,
139
+ prices: {
140
+ month: { envVar: 'STRIPE_PRICE_PRO_MONTH' },
141
+ },
142
+ limits: { maxItems: 100 },
143
+ },
144
+ ],
145
+ },
146
+ ui: {
147
+ layout: 'sidebar',
148
+ },
149
+ allowedDependencies: {
150
+ server: [],
151
+ web: [],
152
+ },
153
+ })
154
+ `, created);
155
+ writeScaffoldFile(rootDir, 'src/contracts/health.contract.ts', `import { defineContract, defineProcedure } from '@zaaxch/grasp-core'
156
+ import { z } from 'zod'
157
+
158
+ export const healthContract = defineContract('health', {
159
+ procedures: {
160
+ status: defineProcedure({
161
+ auth: 'public',
162
+ output: z.object({
163
+ ok: z.boolean(),
164
+ database: z.string(),
165
+ }),
166
+ }),
167
+ },
168
+ })
169
+ `, created);
170
+ writeScaffoldFile(rootDir, 'src/contracts/index.ts', `import { defineAppContract } from '@zaaxch/grasp-core'
171
+ // GRASP:CONTRACTS_IMPORTS
172
+ import { healthContract } from './health.contract.js'
173
+
174
+ export const appContract = defineAppContract({
175
+ // GRASP:CONTRACTS_ENTRIES
176
+ health: healthContract,
177
+ })
178
+
179
+ export type AppContract = typeof appContract
180
+ `, created);
181
+ writeScaffoldFile(rootDir, 'src/server/features/health/health.repo.ts', isMongo
182
+ ? `import { defineCollection } from '@zaaxch/grasp-mongo'
183
+
184
+ export const healthCheckCollection = defineCollection<{ _id: string; checkedAt: Date }>({
185
+ name: 'health_checks',
186
+ })
187
+ `
188
+ : `import { defineTable } from '@zaaxch/grasp-postgres'
189
+
190
+ export const healthChecksTable = defineTable({
191
+ name: 'health_checks',
192
+ migrations: [
193
+ {
194
+ id: '001_init',
195
+ sql: 'CREATE TABLE IF NOT EXISTS health_checks (id TEXT PRIMARY KEY, checked_at TIMESTAMPTZ NOT NULL);',
196
+ },
197
+ ],
198
+ })
199
+ `, created);
200
+ writeScaffoldFile(rootDir, 'src/server/features/health/health.procedures.ts', `import { defineProcedures, defineServerFeature } from '@zaaxch/grasp-server'
201
+ import { healthContract } from '../../../contracts/health.contract.js'
202
+
203
+ export const healthFeature = defineServerFeature({
204
+ handlers: defineProcedures(healthContract, {
205
+ status: async (ctx) => {
206
+ const readiness = await ctx.store.readiness.check()
207
+ return {
208
+ ok: readiness.ok,
209
+ database: ctx.store.kind,
210
+ }
211
+ },
212
+ }),
213
+ })
214
+ `, created);
215
+ writeScaffoldFile(rootDir, 'src/server/features/health/__tests__/health.test.ts', `import { describe, expect, it } from 'vitest'
216
+ import { healthContract } from '../../../../contracts/health.contract.js'
217
+
218
+ describe('health contract', () => {
219
+ it('exposes public status procedure', () => {
220
+ expect(healthContract.procedures.status.auth).toBe('public')
221
+ })
222
+ })
223
+ `, created);
224
+ writeScaffoldFile(rootDir, 'src/server/features/index.ts', isMongo
225
+ ? `import { defineServerFeatures } from '@zaaxch/grasp-server'
226
+ // GRASP:SERVER_IMPORTS
227
+ import { healthFeature } from './health/health.procedures.js'
228
+ import { healthCheckCollection } from './health/health.repo.js'
229
+
230
+ export const registeredCollections = [
231
+ // GRASP:SERVER_TABLES
232
+ healthCheckCollection,
233
+ ]
234
+
235
+ export const serverFeatures = defineServerFeatures([
236
+ // GRASP:SERVER_FEATURES
237
+ healthFeature,
238
+ ])
239
+ `
240
+ : `import { defineServerFeatures } from '@zaaxch/grasp-server'
241
+ // GRASP:SERVER_IMPORTS
242
+ import { healthFeature } from './health/health.procedures.js'
243
+ import { healthChecksTable } from './health/health.repo.js'
244
+
245
+ export const registeredTables = [
246
+ // GRASP:SERVER_TABLES
247
+ healthChecksTable,
248
+ ]
249
+
250
+ export const serverFeatures = defineServerFeatures([
251
+ // GRASP:SERVER_FEATURES
252
+ healthFeature,
253
+ ])
254
+ `, created);
255
+ writeScaffoldFile(rootDir, 'src/web/theme.ts', `import { defineGraspTheme } from '@zaaxch/grasp-vue/theme'
256
+
257
+ export const appTheme = defineGraspTheme({
258
+ cssVariables: {
259
+ 'grasp-brand': '#2563eb',
260
+ },
261
+ })
262
+ `, created);
263
+ writeScaffoldFile(rootDir, 'src/web/styles.css', `@import 'tailwindcss';
264
+ `, created);
265
+ writeScaffoldFile(rootDir, 'src/web/LandingPage.vue', `<script setup lang="ts">
266
+ import { RouterLink } from 'vue-router'
267
+ import config from '../../grasp.config.js'
268
+ </script>
269
+
270
+ <template>
271
+ <main class="mx-auto flex min-h-screen max-w-3xl flex-col items-center justify-center gap-6 p-8 text-center">
272
+ <h1 class="text-4xl font-bold">{{ config.app.displayName }}</h1>
273
+ <p class="text-lg opacity-80">Built on the standardized Grasp application shell.</p>
274
+ <div class="flex gap-3">
275
+ <RouterLink to="/login" class="rounded bg-blue-600 px-4 py-2 text-white">Sign in</RouterLink>
276
+ <RouterLink to="/health" class="rounded border px-4 py-2">Health</RouterLink>
277
+ </div>
278
+ </main>
279
+ </template>
280
+ `, created);
281
+ writeScaffoldFile(rootDir, 'src/web/features/health/views/HealthView.vue', `<script setup lang="ts">
282
+ import { useGraspApi } from '@zaaxch/grasp-vue'
283
+ import { onMounted, ref } from 'vue'
284
+ import type { AppContract } from '../../../../contracts/index.js'
285
+
286
+ const api = useGraspApi<AppContract>()
287
+ const status = ref<{ ok: boolean; database: string } | null>(null)
288
+
289
+ onMounted(async () => {
290
+ status.value = await api.health.status()
291
+ })
292
+ </script>
293
+
294
+ <template>
295
+ <section class="flex flex-col gap-3">
296
+ <h2 class="text-xl font-semibold">System Health</h2>
297
+ <pre v-if="status">{{ status }}</pre>
298
+ </section>
299
+ </template>
300
+ `, created);
301
+ writeScaffoldFile(rootDir, 'src/web/features/index.ts', `import { defineFeatureRoutes, type GraspNavItem } from '@zaaxch/grasp-vue'
302
+ // GRASP:WEB_IMPORTS
303
+ import HealthView from './health/views/HealthView.vue'
304
+
305
+ export const featureNavItems: readonly GraspNavItem[] = [
306
+ // GRASP:WEB_NAV
307
+ { label: 'Health', to: '/health' },
308
+ ]
309
+
310
+ export const featureRoutes = defineFeatureRoutes([
311
+ // GRASP:WEB_ROUTES
312
+ { path: '/health', name: 'health', component: HealthView, meta: { auth: 'required' } },
313
+ ])
314
+ `, created);
315
+ const syncResult = await syncProject({ rootDir, cliVersion: version });
316
+ return {
317
+ rootDir,
318
+ filesCreated: [...created, ...syncResult.written],
319
+ };
320
+ }
321
+ //# sourceMappingURL=new.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.js","sourceRoot":"","sources":["../src/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,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,CACf,OAAO,EACP,8CAA8C,EAC9C;;;;;;;;;;;;;;;;;;;CAmBH,EACG,OAAO,CACR,CAAA;IAED,iBAAiB,CACf,OAAO,EACP,2BAA2B,EAC3B;;;;;;;;;;;;;CAaH,EACG,OAAO,CACR,CAAA;IAED,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAA;IACtE,OAAO;QACL,OAAO;QACP,YAAY,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;KAClD,CAAA;AACH,CAAC"}
package/dist/sync.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ export declare const GRASP_LOCK_FILE = "grasp.lock.json";
2
+ export interface GraspLockManifest {
3
+ readonly schemaVersion: 1;
4
+ readonly cliVersion: string;
5
+ readonly database: 'mongo' | 'postgres';
6
+ readonly uiLayout: string;
7
+ readonly mcpEnabled?: boolean;
8
+ readonly files: Readonly<Record<string, string>>;
9
+ }
10
+ export interface SyncProjectResult {
11
+ readonly ok: boolean;
12
+ readonly written: readonly string[];
13
+ readonly drifted: readonly string[];
14
+ readonly lockFile: string;
15
+ }
16
+ export declare function sha256Hex(content: string): string;
17
+ export declare function normalizeLockedHashInput(relPath: string, content: string): string;
18
+ /**
19
+ * Generates or verifies all byte-locked infrastructure, boot, CI, and agent guidance files.
20
+ */
21
+ export declare function syncProject(options: {
22
+ readonly rootDir: string;
23
+ readonly checkOnly?: boolean;
24
+ readonly cliVersion?: string;
25
+ }): Promise<SyncProjectResult>;
26
+ export declare function readLockManifest(rootDir: string): GraspLockManifest;
27
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,eAAe,oBAAoB,CAAA;AAEhD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,UAAU,CAAA;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACjD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQjF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuE7B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAMnE"}
package/dist/sync.js ADDED
@@ -0,0 +1,94 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ import { GraspError } from '@zaaxch/grasp-core';
5
+ import { loadGraspConfig } from './config-loader.js';
6
+ import { extractLockedAgentsSection, extractLockedGitignoreSection, generateLockedFiles, mergeAgentsWithProductNotes, mergeGitignoreWithProductRules, } from './templates.js';
7
+ export const GRASP_LOCK_FILE = 'grasp.lock.json';
8
+ export function sha256Hex(content) {
9
+ return createHash('sha256').update(content, 'utf8').digest('hex');
10
+ }
11
+ export function normalizeLockedHashInput(relPath, content) {
12
+ if (relPath === 'AGENTS.md') {
13
+ return extractLockedAgentsSection(content);
14
+ }
15
+ if (relPath === '.gitignore') {
16
+ return extractLockedGitignoreSection(content);
17
+ }
18
+ return content;
19
+ }
20
+ /**
21
+ * Generates or verifies all byte-locked infrastructure, boot, CI, and agent guidance files.
22
+ */
23
+ export async function syncProject(options) {
24
+ const absRoot = resolve(options.rootDir);
25
+ const checkOnly = options.checkOnly ?? false;
26
+ const cliVersion = options.cliVersion ?? '0.2.0';
27
+ const config = await loadGraspConfig(absRoot);
28
+ const expectedSpecs = generateLockedFiles(config);
29
+ const lockMap = {};
30
+ const drifted = [];
31
+ const written = [];
32
+ for (const spec of expectedSpecs) {
33
+ const absPath = join(absRoot, spec.path);
34
+ const existing = existsSync(absPath) ? readFileSync(absPath, 'utf8') : undefined;
35
+ let targetContent = spec.content;
36
+ if (spec.path === 'AGENTS.md') {
37
+ targetContent = mergeAgentsWithProductNotes(spec.content, existing);
38
+ }
39
+ else if (spec.path === '.gitignore') {
40
+ targetContent = mergeGitignoreWithProductRules(spec.content, existing);
41
+ }
42
+ const expectedHash = sha256Hex(normalizeLockedHashInput(spec.path, spec.content));
43
+ lockMap[spec.path] = expectedHash;
44
+ const actualHash = existing !== undefined ? sha256Hex(normalizeLockedHashInput(spec.path, existing)) : undefined;
45
+ const exactMatch = spec.path === 'AGENTS.md' || spec.path === '.gitignore'
46
+ ? actualHash === expectedHash
47
+ : existing === targetContent;
48
+ if (!exactMatch) {
49
+ if (checkOnly) {
50
+ drifted.push(spec.path);
51
+ }
52
+ else {
53
+ mkdirSync(dirname(absPath), { recursive: true });
54
+ writeFileSync(absPath, targetContent, 'utf8');
55
+ if (spec.mode === 'executable') {
56
+ chmodSync(absPath, 0o755);
57
+ }
58
+ written.push(spec.path);
59
+ }
60
+ }
61
+ }
62
+ const manifest = {
63
+ schemaVersion: 1,
64
+ cliVersion,
65
+ database: config.database,
66
+ uiLayout: config.ui.layout,
67
+ mcpEnabled: config.mcp.enabled,
68
+ files: lockMap,
69
+ };
70
+ const manifestContent = `${JSON.stringify(manifest, null, 2)}\n`;
71
+ const lockPath = join(absRoot, GRASP_LOCK_FILE);
72
+ const existingLock = existsSync(lockPath) ? readFileSync(lockPath, 'utf8') : undefined;
73
+ if (existingLock !== manifestContent) {
74
+ if (checkOnly) {
75
+ drifted.push(GRASP_LOCK_FILE);
76
+ }
77
+ else {
78
+ writeFileSync(lockPath, manifestContent, 'utf8');
79
+ written.push(GRASP_LOCK_FILE);
80
+ }
81
+ }
82
+ if (checkOnly && drifted.length > 0) {
83
+ return { ok: false, written: [], drifted, lockFile: GRASP_LOCK_FILE };
84
+ }
85
+ return { ok: true, written, drifted: [], lockFile: GRASP_LOCK_FILE };
86
+ }
87
+ export function readLockManifest(rootDir) {
88
+ const lockPath = join(resolve(rootDir), GRASP_LOCK_FILE);
89
+ if (!existsSync(lockPath)) {
90
+ throw GraspError.notFound(`Missing ${GRASP_LOCK_FILE}; run "grasp sync"`);
91
+ }
92
+ return JSON.parse(readFileSync(lockPath, 'utf8'));
93
+ }
94
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OA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AE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;IACvE,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAAA;IACxD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,UAAU,CAAC,QAAQ,CAAC,WAAW,eAAe,oBAAoB,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAsB,CAAA;AACxE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ResolvedGraspConfig } from '@zaaxch/grasp-core';
2
+ export declare const AGENTS_PRODUCT_NOTES_SENTINEL = "<!-- GRASP:PRODUCT_NOTES -->";
3
+ export declare const GITIGNORE_PRODUCT_SENTINEL = "# GRASP:PRODUCT_IGNORES";
4
+ export interface LockedFileSpec {
5
+ readonly path: string;
6
+ readonly content: string;
7
+ readonly mode?: 'executable';
8
+ }
9
+ export declare function extractLockedAgentsSection(content: string): string;
10
+ export declare function mergeAgentsWithProductNotes(lockedTemplate: string, existingContent: string | undefined): string;
11
+ export declare function extractLockedGitignoreSection(content: string): string;
12
+ export declare function mergeGitignoreWithProductRules(lockedTemplate: string, existingContent: string | undefined): string;
13
+ export declare function generateLockedFiles(config: ResolvedGraspConfig): readonly LockedFileSpec[];
14
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,eAAO,MAAM,6BAA6B,iCAAiC,CAAA;AAC3E,eAAO,MAAM,0BAA0B,4BAA4B,CAAA;AAEnE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAC7B;AA0BD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,MAAM,CAOR;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,8BAA8B,CAC5C,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,MAAM,CAOR;AA+1BD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,cAAc,EAAE,CA6gB1F"}