From 930ae56f406e19be0696d6c97c3251443464076f Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 30 Oct 2025 07:24:05 +0000 Subject: [PATCH] Fix no signer error on git push to nostr remote both from the terminal or chat interface --- src/components/Shakespeare/ChatPane.tsx | 2 +- src/components/Terminal.tsx | 6 ++++-- src/lib/commands/git.ts | 6 ++++++ src/lib/commands/git/push.ts | 6 ++++++ src/lib/tools/ShellTool.ts | 7 +++++-- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 77da01a8..b98939af 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -154,7 +154,7 @@ export const ChatPane = forwardRef(({ nostr_read_protocol: new NostrReadProtocolTool(), nostr_read_nips_index: new NostrReadNipsIndexTool(), nostr_generate_kind: new NostrGenerateKindTool(), - shell: new ShellTool(fs, cwd, git, projectsPath), + shell: new ShellTool(fs, cwd, git, projectsPath, user?.signer), read_console_messages: new ReadConsoleMessagesTool(), }; diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index cdcf73d8..91d48e8e 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -7,6 +7,7 @@ import { ShellTool } from '@/lib/tools/ShellTool'; import { useFS } from '@/hooks/useFS'; import { useFSPaths } from '@/hooks/useFSPaths'; import { useGit } from '@/hooks/useGit'; +import { useCurrentUser } from '@/hooks/useCurrentUser'; import { ansiToHtml, containsAnsiCodes } from '@/lib/ansiToHtml'; interface TerminalProps { @@ -35,10 +36,11 @@ export function Terminal({ projectId, className }: TerminalProps) { const { fs } = useFS(); const { projectsPath } = useFSPaths(); const { git } = useGit(); + const { user } = useCurrentUser(); // Initialize ShellTool useEffect(() => { - shellToolRef.current = new ShellTool(fs, `${projectsPath}/${projectId}`, git, projectsPath); + shellToolRef.current = new ShellTool(fs, `${projectsPath}/${projectId}`, git, projectsPath, user?.signer); // Add welcome message setLines([{ @@ -47,7 +49,7 @@ export function Terminal({ projectId, className }: TerminalProps) { content: `Welcome to Shakespeare Terminal\nType 'help' to see available commands.`, timestamp: new Date() }]); - }, [projectId, fs, git, projectsPath]); + }, [projectId, fs, git, projectsPath, user?.signer]); // Auto-scroll to bottom when new lines are added or execution state changes useEffect(() => { diff --git a/src/lib/commands/git.ts b/src/lib/commands/git.ts index d7758188..78dafe79 100644 --- a/src/lib/commands/git.ts +++ b/src/lib/commands/git.ts @@ -1,6 +1,7 @@ import type { Git } from "../git"; import type { JSRuntimeFS } from "../JSRuntime"; import type { ShellCommand, ShellCommandResult } from "./ShellCommand"; +import type { NostrSigner } from "@nostrify/nostrify"; import { createSuccessResult, createErrorResult } from "./ShellCommand"; // Import subcommands @@ -34,12 +35,14 @@ export interface GitSubcommandOptions { git: Git; fs: JSRuntimeFS; pwd: string; + signer?: NostrSigner; } export interface GitCommandOptions { git: Git; fs: JSRuntimeFS; cwd: string; + signer?: NostrSigner; } /** @@ -54,12 +57,14 @@ export class GitCommand implements ShellCommand { private git: Git; private fs: JSRuntimeFS; private cwd: string; + private signer?: NostrSigner; private subcommands: Map; constructor(options: GitCommandOptions) { this.git = options.git; this.fs = options.fs; this.cwd = options.cwd; + this.signer = options.signer; this.subcommands = new Map(); // Register all subcommands @@ -67,6 +72,7 @@ export class GitCommand implements ShellCommand { git: this.git, fs: this.fs, pwd: this.cwd, + signer: this.signer, }; this.registerSubcommand(new GitInitCommand(subcommandOptions)); diff --git a/src/lib/commands/git/push.ts b/src/lib/commands/git/push.ts index e21502a5..4ce3e7bf 100644 --- a/src/lib/commands/git/push.ts +++ b/src/lib/commands/git/push.ts @@ -1,5 +1,6 @@ import type { JSRuntimeFS } from "../../JSRuntime"; import type { ShellCommandResult } from "../ShellCommand"; +import type { NostrSigner } from "@nostrify/nostrify"; import { createSuccessResult, createErrorResult } from "../ShellCommand"; import type { GitSubcommand, GitSubcommandOptions } from "../git"; import type { Git } from "../../git"; @@ -14,11 +15,13 @@ export class GitPushCommand implements GitSubcommand { private git: Git; private fs: JSRuntimeFS; private pwd: string; + private signer?: NostrSigner; constructor(options: GitSubcommandOptions) { this.git = options.git; this.fs = options.fs; this.pwd = options.pwd; + this.signer = options.signer; } async execute(args: string[]): Promise { @@ -73,6 +76,7 @@ export class GitPushCommand implements GitSubcommand { ref: targetBranch, remoteRef: targetBranch, onAuth: (url) => findCredentialsForRepo(url, settings.credentials), + signer: this.signer, }); return createSuccessResult(`To ${remoteUrl}\n ${targetBranch} -> ${targetBranch}\n`); @@ -85,6 +89,8 @@ export class GitPushCommand implements GitSubcommand { return createErrorResult(`error: failed to push some refs to '${remoteUrl}'\nhint: Updates were rejected because the remote contains work that you do not have locally.`); } else if (error.message.includes('network')) { return createErrorResult('fatal: unable to access remote repository. Please check your network connection.'); + } else if (error.message.includes('Nostr signer is required')) { + return createErrorResult('fatal: Nostr signer is required for pushing to Nostr repositories. Please log in with a Nostr account.'); } } diff --git a/src/lib/tools/ShellTool.ts b/src/lib/tools/ShellTool.ts index 85e4c874..68151f7c 100644 --- a/src/lib/tools/ShellTool.ts +++ b/src/lib/tools/ShellTool.ts @@ -4,6 +4,7 @@ import type { JSRuntimeFS } from "../JSRuntime"; import type { ShellCommand } from "../commands/ShellCommand"; import { Git } from "../git"; import { stripAnsiCodes } from "../ansiToHtml"; +import type { NostrSigner } from "@nostrify/nostrify"; import { CatCommand, CdCommand, @@ -51,6 +52,7 @@ export class ShellTool implements Tool { private git: Git; private commands: Map; private projectsPath: string; + private signer?: NostrSigner; readonly description = "Execute shell commands like cat, ls, cd, pwd, rm, cp, mv, echo, head, tail, grep, find, wc, touch, mkdir, sort, uniq, cut, tr, sed, diff, which, whoami, date, env, clear, git, curl, unzip, hexdump. Supports compound commands with &&, ||, ;, and | operators, and output redirection with > and >> operators"; @@ -60,11 +62,12 @@ export class ShellTool implements Tool { ), }); - constructor(fs: JSRuntimeFS, cwd: string, git: Git, projectsPath: string = '/projects') { + constructor(fs: JSRuntimeFS, cwd: string, git: Git, projectsPath: string = '/projects', signer?: NostrSigner) { this.fs = fs; this.cwd = cwd; this.git = git; this.projectsPath = projectsPath; + this.signer = signer; this.commands = new Map(); // Register available commands @@ -79,7 +82,7 @@ export class ShellTool implements Tool { this.registerCommand(new EchoCommand()); this.registerCommand(new EnvCommand()); this.registerCommand(new FindCommand(fs)); - this.registerCommand(new GitCommand({ git: this.git, fs, cwd: this.cwd })); + this.registerCommand(new GitCommand({ git: this.git, fs, cwd: this.cwd, signer: this.signer })); this.registerCommand(new GrepCommand(fs)); this.registerCommand(new HeadCommand(fs)); this.registerCommand(new HexdumpCommand(fs));