diff --git a/src/components/AppDialog.tsx b/src/components/AppDialog.tsx index ca9ea11d..c43ce499 100644 --- a/src/components/AppDialog.tsx +++ b/src/components/AppDialog.tsx @@ -37,6 +37,7 @@ import { CircleHelp, } from 'lucide-react'; import type { NostrEvent } from '@nostrify/nostrify'; +import { nip19 } from 'nostr-tools'; interface AppDialogProps { projectId: string; @@ -54,6 +55,8 @@ interface AppFormData { tTags: string[]; supportedKinds: string[]; webHandlers: Array<{ url: string; type: string }>; + ngitRepo: string; + nsiteDeployment: string; } /** Parse a kind 31990 event into form data */ @@ -82,6 +85,9 @@ function eventToFormData(event: NostrEvent): AppFormData { .map(([, v]) => v) .filter(Boolean); + const ngitATag = event.tags.find(([t, v]) => t === 'a' && v?.startsWith('30617:'))?.[1] ?? ''; + const nsiteATag = event.tags.find(([t, v]) => t === 'a' && v?.startsWith('35128:'))?.[1] ?? ''; + return { name: metadata.name ?? '', about: metadata.about ?? '', @@ -92,6 +98,8 @@ function eventToFormData(event: NostrEvent): AppFormData { tTags, supportedKinds, webHandlers, + ngitRepo: aTagToNaddr(ngitATag), + nsiteDeployment: aTagToNaddr(nsiteATag), }; } @@ -115,9 +123,36 @@ function emptyFormData(projectId: string): AppFormData { tTags: [], supportedKinds: [], webHandlers: [], + ngitRepo: '', + nsiteDeployment: '', }; } +/** Convert a "kind:pubkey:identifier" a-tag value to an naddr string, or return '' on failure. */ +function aTagToNaddr(aTag: string): string { + try { + const [kindStr, pubkey, ...rest] = aTag.split(':'); + const kind = parseInt(kindStr); + const identifier = rest.join(':'); + if (!kind || !pubkey || !identifier) return ''; + return nip19.naddrEncode({ kind, pubkey, identifier }); + } catch { + return ''; + } +} + +/** Convert an naddr string to a "kind:pubkey:identifier" a-tag value, or return '' on failure. */ +function naddrToATag(naddr: string): string { + try { + const decoded = nip19.decode(naddr.trim()); + if (decoded.type !== 'naddr') return ''; + const { kind, pubkey, identifier } = decoded.data; + return `${kind}:${pubkey}:${identifier}`; + } catch { + return ''; + } +} + /** Read a file from VFS as a UTF-8 string, returning null if it doesn't exist. */ async function readVfsText(fs: { readFile(path: string, options: { encoding: string }): Promise }, path: string): Promise { try { @@ -389,6 +424,8 @@ export function AppDialog({ projectId, open, onOpenChange }: AppDialogProps) { tTags: formData.tTags, supportedKinds: formData.supportedKinds, webHandlers: formData.webHandlers, + ngitRepo: naddrToATag(formData.ngitRepo), + nsiteDeployment: naddrToATag(formData.nsiteDeployment), }, { fs, cwd, pubkey: user.pubkey }, ); @@ -633,6 +670,40 @@ export function AppDialog({ projectId, open, onOpenChange }: AppDialogProps) {

+ {/* ngit Repository */} +
+ + updateField('ngitRepo', e.target.value)} + placeholder="naddr1..." + disabled={isSaving} + className={formData.ngitRepo && !naddrToATag(formData.ngitRepo) ? 'border-destructive focus-visible:ring-destructive' : ''} + /> + {formData.ngitRepo && !naddrToATag(formData.ngitRepo) && ( +

Invalid naddr

+ )} +

naddr of the ngit repository (kind 30617). Auto-detected from git remote if left blank.

+
+ + {/* nsite Deployment */} +
+ + updateField('nsiteDeployment', e.target.value)} + placeholder="naddr1..." + disabled={isSaving} + className={formData.nsiteDeployment && !naddrToATag(formData.nsiteDeployment) ? 'border-destructive focus-visible:ring-destructive' : ''} + /> + {formData.nsiteDeployment && !naddrToATag(formData.nsiteDeployment) && ( +

Invalid naddr

+ )} +

naddr of the nsite deployment (kind 35128). Auto-detected from .nsite/config.json if left blank.

+
+ {/* Tags */}
diff --git a/src/lib/appEvent.ts b/src/lib/appEvent.ts index 4ed67c5a..4a65f624 100644 --- a/src/lib/appEvent.ts +++ b/src/lib/appEvent.ts @@ -15,6 +15,10 @@ export interface AppEventInput { tTags?: string[]; supportedKinds?: string[]; webHandlers?: Array<{ url: string; type?: string }>; + /** Explicit "a" tag value for the ngit repo (kind:pubkey:identifier). Overrides auto-detection from git remote. */ + ngitRepo?: string; + /** Explicit "a" tag value for the nsite deployment (kind:pubkey:identifier). Overrides auto-detection from .nsite/config.json. */ + nsiteDeployment?: string; } /** The content and tags for a kind 31990 event, ready to be signed/published. */ @@ -92,8 +96,10 @@ export async function buildAppEvent( } } - // If origin remote is a nostr:// URI owned by the given pubkey, add an "a" tag for the repo - if (opts?.fs && opts.cwd && opts.pubkey) { + // Add "a" tag for the ngit repo — use explicit override if provided, otherwise auto-detect from git remote + if (input.ngitRepo?.trim()) { + tags.push(['a', input.ngitRepo.trim()]); + } else if (opts?.fs && opts.cwd && opts.pubkey) { try { const remotes = await git.listRemotes({ fs: opts.fs, dir: opts.cwd }); const originUrl = remotes.find(r => r.remote === 'origin')?.url; @@ -108,8 +114,10 @@ export async function buildAppEvent( } } - // If an nsite deployment exists, add an "a" tag referencing the kind 35128 site manifest event - if (opts?.fs && opts.cwd && opts.pubkey) { + // Add "a" tag for the nsite deployment — use explicit override if provided, otherwise auto-detect from .nsite/config.json + if (input.nsiteDeployment?.trim()) { + tags.push(['a', input.nsiteDeployment.trim()]); + } else if (opts?.fs && opts.cwd && opts.pubkey) { try { const nsiteConfig = await readNsiteVfsConfig(opts.fs, opts.cwd); if (nsiteConfig?.id) {