From 740603436bc6166021bd92be3fd54f76aafef5ec Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Mon, 10 Feb 2025 02:00:11 +0800 Subject: [PATCH] Init --- README.md | 70 ++++++++++++++++ assists/esh-assist.ps1 | 110 +++++++++++++++++++++++++ assists/main.ps1 | 51 ++++++++++++ assists/pwsh-assist.ps1 | 159 ++++++++++++++++++++++++++++++++++++ base.ps1 | 177 ++++++++++++++++++++++++++++++++++++++++ fount-pwsh.psd1 | 146 +++++++++++++++++++++++++++++++++ fount-pwsh.psm1 | 17 ++++ predicate.ps1 | 9 ++ 8 files changed, 739 insertions(+) create mode 100644 README.md create mode 100644 assists/esh-assist.ps1 create mode 100644 assists/main.ps1 create mode 100644 assists/pwsh-assist.ps1 create mode 100644 base.ps1 create mode 100644 fount-pwsh.psd1 create mode 100644 fount-pwsh.psm1 create mode 100644 predicate.ps1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..dcbe924 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# fount-pwsh + +**fount-pwsh** 是一个工具,它可以让你在 PowerShell (pwsh) 或 esh 终端中轻松使用 **Fount**。 +它可以帮你更好地使用 shell,或只是在 shell 里和角色聊天。 + +![图片:fount-pwsh 使用示例](https://github.com/user-attachments/assets/93afee48-93d4-42c7-a5e0-b7f5c93bdee9) + +## 安装 + +使用这个命令安装 `fount-pwsh` 模块: + +```powershell +Install-Module fount-pwsh +``` + +**注意:** `fount-pwsh` 依赖于 [Fount](https://github.com/steve02081504/fount) 工作。 +不过别担心! +如果你还没有安装 Fount,`fount-pwsh` 会在你第一次使用以下命令时 **自动帮你安装 Fount**: + +- `Start-Fount` +- `Set-FountAssist` +- `Install-FountAssist` + +## 配置助手 + +你需要一个支持 **`shellassist` 界面** 的 **Fount 角色**。 + +> [!WARNING] +> **关于 PowerShell 性能** +> +> 在 PowerShell 中,加载 Fount 助手平均需要 **大约 600 毫秒**。 这可能会稍微影响你的 shell 启动速度。 (对于 esh 来说,加载是 **瞬间的**。) +> +> 如果你希望 PowerShell 启动更快,可以考虑将 Fount 助手的加载设置为 **后台加载** (参阅powershell的[事件注册](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/register-engineevent?view=powershell-7.5)和[OnIdle](https://learn.microsoft.com/dotnet/api/system.management.automation.psengineevent.onidle?view=powershellsdk-7.4.0)事件)。 + +**两种方法启用你的助手:** + +**1. 自动配置 (推荐):** + +使用这个命令,可以让 Fount 助手在每次你打开新的 shell 窗口时自动启动并提供帮助: + +```powershell +Install-FountAssist <你的 Fount 用户名> <需要的角色名> +``` + +将 `<你的 Fount 用户名>` 和 `<需要的角色名>` 替换为你实际的 Fount 用户名和角色名称。 + +**2. 手动配置 (适用于高级用户):** + +如果你想手动设置,可以将以下代码添加到你的 **shell profile** 文件中: + +```powershell +Set-FountAssist <你的 Fount 用户名> <需要的角色名> +``` + +## 助手什么时候会出现? + +Fount 助手会在以下这些情况下自动出现: + +- **当你输入了错误的命令时** (如拼写错误)。 +- **当你运行的命令执行失败时** (`$?` 的值为 false)。 +- **当你主动使用 `f` 命令时** + +## 禁用/启用 自动助手 + +你可以使用 `f` 命令来轻松地禁用或启用自动助手功能: + +```powershell +f 0 # 禁用自动助手 (也可以用 f false / f no / f n / f disable) +f 1 # 启用自动助手 (也可以用 f true / f yes / f y / f enable) +``` diff --git a/assists/esh-assist.ps1 b/assists/esh-assist.ps1 new file mode 100644 index 0000000..2e238c7 --- /dev/null +++ b/assists/esh-assist.ps1 @@ -0,0 +1,110 @@ +$EshellUI.ExecutionRecorders.Add({ + if ($Global:FountAssist.last_commaned) { + $Global:FountAssist.last_commaned.output = $($ans | Out-String) -join "`n" + $Global:FountAssist.last_commaned.error = $($err | Out-String) -join "`n" + $Global:FountAssist.shellhistory.Add($Global:FountAssist.last_commaned) | Out-Null + } + $Global:FountAssist.last_commaned = @{ + command = $expr_now + time = Get-Date + } + # keep shellhistory's last 30 records + while ($Global:FountAssist.shellhistory.Count -gt 30) { + $Global:FountAssist.shellhistory.RemoveAt(0) + } + $Global:FountAssist.rejected_commands = [System.Collections.ArrayList]@() +}) | Out-Null +function global:f( + [ValidateScript({ + (IsEnable $_) -or (IsDisable $_) -or (!$_) + })] + $switch +) { + if ($switch -ne $null) { + $Global:FountAssist.Enabled = IsEnable $switch + Write-Host "fount assist is $(@('disabled','enabled')[$Global:FountAssist.Enabled])" + return + } + $requst = @{ + charname = $Global:FountAssist.AssistCharname + UserCharname = $Global:FountAssist.UserCharname + shelltype = "esh(like powershell)" + shellhistory = $Global:FountAssist.shellhistory + command_now = $expr_now + command_error = $($global:expr_err_now | Out-String) -join "`n" + rejected_commands = $Global:FountAssist.rejected_commands + chat_scoped_char_memorys = $Global:FountAssist.chat_scoped_char_memorys + pwd = "$pwd" + } + $result = Invoke-FountShell $Global:FountAssist.FountUsername 'shellassist' $requst + if ($result.chat_scoped_char_memorys) { + $Global:FountAssist.chat_scoped_char_memorys = $result.chat_scoped_char_memorys + } + if ($result.shellhistory) { + $Global:FountAssist.shellhistory = [System.Collections.ArrayList]$result.shellhistory + } + + if ($result.content -or $result.recommend_command) { + Write-Host + } + if ($result.content) { + $Global:FountAssist.shellhistory.Add(@{ + name = $result.name + avatar = $result.avatar + role = "char" + content = $result.content + extension = $result.extension + }) | Out-Null + Write-Host $result.content + } + if ($result.recommend_command) { + # 显示并询问是否执行或重新推荐 + Write-Host "use `"" -NoNewline + Write-Host $result.recommend_command -ForegroundColor Yellow -NoNewline + Write-Host "`" as command? " -NoNewline + Write-Host "[" -NoNewline + Write-Host "enter" -ForegroundColor Green -NoNewline + Write-Host "/" -NoNewline + Write-Host "n" -ForegroundColor Blue -NoNewline + Write-Host " (next)/" -NoNewline + Write-Host "ctrl+c" -ForegroundColor Red -NoNewline + Write-Host "]" + [console]::TreatControlCAsInput = $true + while ($true) { + if ([console]::KeyAvailable) { + $key = [console]::ReadKey($true) + if ($key.Key -eq "Enter") { + [console]::TreatControlCAsInput = $false + $EshellUI.AcceptLine($result.recommend_command) + return + } + if ($key.Key -eq "N") { + $Global:FountAssist.rejected_commands.Add($result.recommend_command) | Out-Null + return f + } + if ($key.Key -eq "C" -and $key.Modifiers -eq "Control") { + return + } + } + } + } +} +$EshellUI.ExecutionHandlers.Add({ + if (!$Global:FountAssist.Enabled) { + return + } + #若当前表达式是合法ps脚本但不是合法命令 + if ($global:bad_expr_now -and $global:expr_ast_now) { + f + return '' #终止当前表达式 + } +}) | Out-Null +$EshellUI.AfterExecutionHandlers.Add({ + if (!$Global:FountAssist.Enabled) { + return + } + #若当前表达式退出值不为0且不在白名单中 + if (-not $? -and $Global:FountAssist.NonZeroReturnWhiteList -notcontains (($expr_now -split '\s')[0])) { + f + } +}) | Out-Null diff --git a/assists/main.ps1 b/assists/main.ps1 new file mode 100644 index 0000000..4e3bedd --- /dev/null +++ b/assists/main.ps1 @@ -0,0 +1,51 @@ +$Global:FountAssist = @{ + Enabled = $true + AssistCharname = $null + FountUsername = $null + shellhistory = [System.Collections.ArrayList]@() + rejected_commands = [System.Collections.ArrayList]@() + chat_scoped_char_memorys = @{} + # 以非0返回值指示信息而非错误的命令 + NonZeroReturnWhiteList = [System.Collections.ArrayList]@('robocopy') +} + +$script:FountAssistInstalled = $false + +function Set-FountAssist { + param ( + $FountUsername, + $AssistCharname + ) + if ($AssistCharname) { $Global:FountAssist.AssistCharname = $AssistCharname } + if ($FountUsername) { $Global:FountAssist.FountUsername = $FountUsername } + Start-Fount background keepalive runshell $Global:FountAssist.FountUsername preload chars $Global:FountAssist.AssistCharname + if ($script:FountAssistInstalled) { + return + } + if ($EshellUI) { + . $PSScriptRoot/esh-assist.ps1 + } + else { + . $PSScriptRoot/pwsh-assist.ps1 + } +} + +function Install-FountAssist { + param ( + $FountUsername, + $AssistCharname + ) + if ($AssistCharname) { $Global:FountAssist.AssistCharname = $AssistCharname } + if ($FountUsername) { $Global:FountAssist.FountUsername = $FountUsername } + if ($EshellUI) { + $EshellUI.FountAssist = "$($Global:FountAssist.FountUsername):$($Global:FountAssist.AssistCharname)" + } + else { + $content = Get-Content $PROFILE -ErrorAction Ignore + $content = $content -split "`n" | Where-Object { $_ -notmatch 'Set-FountAssist' } + $content += "Set-FountAssist $($Global:FountAssist.FountUsername) $($Global:FountAssist.AssistCharname)" + $content = $content -join "`n" + Set-Content $PROFILE $content + } + Set-FountAssist +} diff --git a/assists/pwsh-assist.ps1 b/assists/pwsh-assist.ps1 new file mode 100644 index 0000000..a8c2ffc --- /dev/null +++ b/assists/pwsh-assist.ps1 @@ -0,0 +1,159 @@ +function global:f( + [ValidateScript({ + (IsEnable $_) -or (IsDisable $_) -or (!$_) + })] + $switch +) { + if ($switch -ne $null) { + $Global:FountAssist.Enabled = IsEnable $switch + Write-Host "fount assist is $(@('disabled','enabled')[$Global:FountAssist.Enabled])" + return + } + $requst = @{ + charname = $Global:FountAssist.AssistCharname + UserCharname = $Global:FountAssist.UserCharname + shelltype = "powershell" + shellhistory = $Global:FountAssist.shellhistory + command_now = $Global:FountAssist.last_commaned.command + command_error = $($Error | Select-Object -SkipLast $Global:FountAssist.HistoryErrorCount | Out-String) -join "`n" + rejected_commands = $Global:FountAssist.rejected_commands + chat_scoped_char_memorys = $Global:FountAssist.chat_scoped_char_memorys + pwd = "$pwd" + } + $result = Invoke-FountShell $Global:FountAssist.FountUsername 'shellassist' $requst + if ($result.chat_scoped_char_memorys) { + $Global:FountAssist.chat_scoped_char_memorys = $result.chat_scoped_char_memorys + } + if ($result.shellhistory) { + $Global:FountAssist.shellhistory = [System.Collections.ArrayList]$result.shellhistory + } + + if ($result.content -or $result.recommend_command) { + Write-Host + } + if ($result.content) { + $Global:FountAssist.shellhistory.Add(@{ + name = $result.name + avatar = $result.avatar + role = "char" + content = $result.content + extension = $result.extension + }) | Out-Null + Write-Host $result.content + } + if ($result.recommend_command) { + # 显示并询问是否执行或重新推荐 + Write-Host "use `"" -NoNewline + Write-Host $result.recommend_command -ForegroundColor Yellow -NoNewline + Write-Host "`" as command? " -NoNewline + Write-Host "[" -NoNewline + Write-Host "enter" -ForegroundColor Green -NoNewline + Write-Host "/" -NoNewline + Write-Host "n" -ForegroundColor Blue -NoNewline + Write-Host " (next)/" -NoNewline + Write-Host "ctrl+c" -ForegroundColor Red -NoNewline + Write-Host "]" + [console]::TreatControlCAsInput = $true + while ($true) { + if ([console]::KeyAvailable) { + $key = [console]::ReadKey($true) + if ($key.Key -eq "Enter") { + [console]::TreatControlCAsInput = $false + [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($result.recommend_command) + $StartExecutionTime = Get-Date + Invoke-Expression $result.recommend_command | Out-String | Write-Host + $EndExecutionTime = Get-Date + [PSCustomObject](@{ + CommandLine = $result.recommend_command + ExecutionStatus = "Completed" + StartExecutionTime = $StartExecutionTime + EndExecutionTime = $EndExecutionTime + }) | Add-History + return + } + if ($key.Key -eq "N") { + $Global:FountAssist.rejected_commands.Add($result.recommend_command) | Out-Null + f + return + } + if ($key.Key -eq "C" -and $key.Modifiers -eq "Control") { + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() + return + } + } + } + } +} +$Global:FountAssist.HistoryErrorCount = $Error.Count +Set-PSReadLineKeyHandler -Key Enter -ScriptBlock { + $line = $null + $cursor = $null + [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) + + if ($Global:FountAssist.last_commaned) { + $Global:FountAssist.last_commaned.output = $($ans | Out-String) -join "`n" + $Global:FountAssist.last_commaned.error = $($Error | Select-Object -SkipLast $Global:FountAssist.HistoryErrorCount | Out-String) -join "`n" + $Global:FountAssist.shellhistory.Add($Global:FountAssist.last_commaned) | Out-Null + } + + $Global:FountAssist.last_commaned = @{ + command = $line + time = Get-Date + } + + # keep shellhistory's last 30 records + while ($Global:FountAssist.shellhistory.Count -gt 30) { + $Global:FountAssist.shellhistory.RemoveAt(0) + } + $Global:FountAssist.rejected_commands = [System.Collections.ArrayList]@() + $Global:FountAssist.HistoryErrorCount = $Error.Count + + if (!$Global:FountAssist.Enabled) { + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() + return + } + + $parseError = $null + $ast = [System.Management.Automation.Language.Parser]::ParseInput($line, [ref]$null, [ref]$parseError) + + $bad_expr = $false + if ($parseError) { + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() + return + } + $Commands = $ast.FindAll({param($ast) $ast -is [System.Management.Automation.Language.CommandAst] }, $true) + foreach ($Command in $Commands) { + if (!(Get-Command $Command.CommandElements[0] -ErrorAction Ignore)) { + $bad_expr = $true + break + } + } + + #若当前表达式是合法ps脚本但不是合法命令 + if ($bad_expr) { + f + $YIndexBackup = $host.UI.RawUI.CursorPosition.Y + [Microsoft.PowerShell.PSConsoleReadLine]::CancelLine() + Write-Host "`b`b " -NoNewline + try { + if ($host.UI.RawUI.CursorPosition.Y -ne $YIndexBackup) { + $host.UI.RawUI.CursorPosition = New-Object System.Management.Automation.Host.Coordinates 0, $YIndexBackup + } + } catch { } + Write-Host + } + else { + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() + } +} +if (-not $Global:FountAssist.OriginalPrompt) { + $Global:FountAssist.OriginalPrompt = Get-Content function:\prompt +} +function global:prompt { + if (-not $? -and $Global:FountAssist.NonZeroReturnWhiteList -notcontains (($expr_now -split '\s')[0])) { + if ($Global:FountAssist.Enabled) { + try{ f } catch {} + } + } + & $Global:FountAssist.OriginalPrompt +} diff --git a/base.ps1 b/base.ps1 new file mode 100644 index 0000000..ef43025 --- /dev/null +++ b/base.ps1 @@ -0,0 +1,177 @@ +$script:FountEncoding = [System.Text.Encoding]::UTF8 + +function Get-FountClient($ComputerName = "localhost", $Port = 16698) { + if ($script:FountClient -and $script:FountClient.Connected) { + return $script:FountClient + } + + try { + Write-Verbose "正在尝试连接到 Fount 服务器..." + # 创建新的 TCP 客户端 + $Client = New-Object System.Net.Sockets.TcpClient + $Client.Connect($ComputerName, $Port) + Write-Verbose "成功连接到 Fount 服务器。" + return $Client + } + catch { + Write-Error "与 Fount 服务器建立连接失败: $($_.Exception.Message)" + return $null + } +} + +$script:FountClient = $null +$script:FountStream = $null +function Invoke-FountIPC( + [string]$Type, + [hashtable]$Data, + [string]$ComputerName = "localhost", + [int]$Port = 16698 +) { + # 构建要发送的完整 JSON 对象 + $CommandObject = @{ + type = $Type + data = $Data + } + $JsonCommand = $CommandObject | ConvertTo-Json -Compress -Depth 100 + $JsonCommand += "`n" # 添加换行符作为消息结束符 + + #Write-Host "Sending command:" -ForegroundColor Green + #$CommandObject | ConvertTo-Json -Depth 100 | Write-Host + + try { + # 获取或建立连接 + if (-not $script:FountClient) { + $script:FountClient = Get-FountClient -ComputerName $ComputerName -Port $Port + if (-not $script:FountClient) { + throw "无法连接到 Fount 服务器" + } + } + if (-not $script:FountClient.Connected) { + $script:FountClient.Connect($ComputerName, $Port) + if ($script:FountStream) { + $script:FountStream.Dispose() + } + $script:FountStream = $null + } + if (-not $script:FountStream) { + $script:FountStream = $script:FountClient.GetStream() + } + + # 获取网络流 + $Stream = $script:FountStream + $Encoding = $script:FountEncoding + + # 发送数据 + $Bytes = $Encoding.GetBytes($JsonCommand) + $Stream.Write($Bytes, 0, $Bytes.Length) + $Stream.Flush() + + # 读取响应(支持大响应和分块读取) + $MemoryStream = New-Object System.IO.MemoryStream + $Buffer = New-Object byte[] 4096 + $FoundTerminator = $false + + do { + $Read = $Stream.Read($Buffer, 0, $Buffer.Length) + if ($Read -gt 0) { + $MemoryStream.Write($Buffer, 0, $Read) + # 检查是否包含换行符 + $CurrentData = $Encoding.GetString($MemoryStream.ToArray()) + if ($CurrentData -match "`n") { + $FoundTerminator = $true + break + } + } + } while ($Read -gt 0 -and -not $FoundTerminator) + + # 提取有效响应 + $ResponseString = $Encoding.GetString($MemoryStream.ToArray()) + + # 解析 JSON 响应 + if (-not [string]::IsNullOrEmpty($ResponseString)) { + $result = ConvertFrom-Json -InputObject $ResponseString + #Write-Host "Received response:" -ForegroundColor Green + #$result | ConvertTo-Json -Depth 100 | Write-Host + if ($result.status -ne 'ok') { + Write-Error "与 Fount 服务器通信失败: $($result.message)" + } + else { + return $result.data + } + } + else { + Write-Error "收到空响应" + } + } + catch { + Write-Error "与 Fount 服务器通信失败: $($_.Exception.Message)" + Close-FountClient # 连接出错时关闭连接,以便下次重新连接 + } + finally { + if ($MemoryStream) { + $MemoryStream.Dispose() + } + } +} + +function Start-FountShell { + param( + [Parameter(Mandatory)] + [string]$UserName, + + [Parameter(Mandatory)] + [string]$ShellName, + + [Parameter(ValueFromRemainingArguments)] + [array]$Arguments + ) + + Invoke-FountIPC -Type "runshell" -Data @{ + username = $UserName + shellname = $ShellName + args = $Arguments + } +} + +function Invoke-FountShell { + param ( + [Parameter(Mandatory)] + [string]$UserName, + + [Parameter(Mandatory)] + [string]$ShellName, + + $Data + ) + + Invoke-FountIPC -Type "invokeshell" -Data @{ + username = $UserName + shellname = $ShellName + data = $Data + } +} + +function Install-Fount { + $scriptContent = Invoke-RestMethod https://raw.githubusercontent.com/steve02081504/fount/refs/heads/master/src/runner/main.ps1 + Invoke-Expression "function fountInstaller { $scriptContent }" + fountInstaller @args +} + +function Start-Fount( + [switch] $NoAutoInstall +) { + if (Get-Command fount -ErrorAction SilentlyContinue) { + fount @args + } + elseif (!$NoAutoInstall) { + Install-Fount @args + } + else { + Write-Error "Fount 未安装" + } +} + +function Stop-Fount { + Invoke-FountIPC -Type "shutdown" + Close-FountClient +} diff --git a/fount-pwsh.psd1 b/fount-pwsh.psd1 new file mode 100644 index 0000000..161e8d7 --- /dev/null +++ b/fount-pwsh.psd1 @@ -0,0 +1,146 @@ +# +# Module manifest for module 'fount-pwsh' +# +# Generated by: steve02081504 +# +# Generated on: 2025/2/11 +# + +@{ + + # Script module or binary module file associated with this manifest. + RootModule = 'fount-pwsh.psm1' + + # Version number of this module. + ModuleVersion = '0.0.1' + + # ID used to uniquely identify this module + GUID = '2a16dae2-91d8-4743-952c-94acd1ed7e5a' + + # Author of this module + Author = 'steve02081504' + + # Company or vendor of this module + CompanyName = 'Unknown' + + # Copyright statement for this module + Copyright = '(c) steve02081504. All rights reserved.' + + # Description of the functionality provided by this module + Description = @' +Allows you: +- easily invoke, launch, and install fount in pwsh +- linking fount characters to pwsh for companion and AI assist +'@ + + # Minimum version of the PowerShell engine required by this module + PowerShellVersion = '5.0' + + # Name of the PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # ClrVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = @( + "Set-FountAssist", + "Install-FountAssist", + "Get-FountClient", + "Invoke-FountIPC", + "Start-FountShell", + "Invoke-FountShell", + "Start-Fount", + "Stop-Fount", + "Install-Fount" + ) + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() + + # Variables to export from this module + VariablesToExport = 'FountAssist' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @() + + # DSC resources to export from this module + # DscResourcesToExport = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @( + 'fount', 'AI', 'Artificial-Intelligence', 'Assist', 'FountAssist', 'fount-pwsh', + 'OpenAI', 'GPT', 'ChatGPT', 'Gemini', 'ollama', 'grok', 'cohere' + ) + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/steve02081504/fount-pwsh' + + # A URL to an icon representing this module. + IconUri = 'https://raw.githubusercontent.com/steve02081504/fount/refs/heads/master/src/public/favicon.ico' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} + diff --git a/fount-pwsh.psm1 b/fount-pwsh.psm1 new file mode 100644 index 0000000..01b4b9d --- /dev/null +++ b/fount-pwsh.psm1 @@ -0,0 +1,17 @@ +. $PSScriptRoot/base.ps1 +. $PSScriptRoot/predicate.ps1 +. $PSScriptRoot/assists/main.ps1 + +Export-ModuleMember -Function @( + "Set-FountAssist", + "Install-FountAssist", + "Get-FountClient", + "Invoke-FountIPC", + "Start-FountShell", + "Invoke-FountShell", + "Start-Fount", + "Stop-Fount", + "Install-Fount" +) -Variable @( + "FountAssist" +) diff --git a/predicate.ps1 b/predicate.ps1 new file mode 100644 index 0000000..3598071 --- /dev/null +++ b/predicate.ps1 @@ -0,0 +1,9 @@ +$DisablePredicates = @('off', 'false', 'N', 'No', 'unset', '0', 'disable', '$false') +function IsDisable($value) { + $DisablePredicates -contains "$value" +} + +$EnablePredicates = @('on', 'true', 'Y', 'Yes', 'set', '1', 'enable', '$true') +function IsEnable($value) { + $EnablePredicates -contains "$value" +}