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