agentic-factory-bridge 1.0.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/README.md +77 -0
- package/bin/cli.js +275 -0
- package/bridge.js +700 -0
- package/install-protocol.ps1 +73 -0
- package/opencode-handler.cmd +137 -0
- package/opencode-launch.ps1 +94 -0
- package/package.json +38 -0
- package/uninstall-protocol.ps1 +16 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ============================================================
|
|
2
|
+
# OpenCode Protocol Handler - Installation Script
|
|
3
|
+
# Registers the opencode:// protocol on Windows
|
|
4
|
+
#
|
|
5
|
+
# Usage: agentic-factory-bridge setup
|
|
6
|
+
# OR: powershell -ExecutionPolicy Bypass -File install-protocol.ps1
|
|
7
|
+
# ============================================================
|
|
8
|
+
|
|
9
|
+
$ErrorActionPreference = "Stop"
|
|
10
|
+
|
|
11
|
+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
12
|
+
$HandlerPath = Join-Path $ScriptDir "opencode-handler.cmd"
|
|
13
|
+
|
|
14
|
+
if (-not (Test-Path $HandlerPath)) {
|
|
15
|
+
Write-Host ""
|
|
16
|
+
Write-Host " ERROR: opencode-handler.cmd not found in $ScriptDir" -ForegroundColor Red
|
|
17
|
+
Write-Host " Make sure this script is in the same folder as opencode-handler.cmd" -ForegroundColor Red
|
|
18
|
+
Write-Host ""
|
|
19
|
+
if (-not [Console]::IsInputRedirected) {
|
|
20
|
+
Read-Host "Press Enter to exit"
|
|
21
|
+
}
|
|
22
|
+
exit 1
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$OpenCodePath = Get-Command opencode -ErrorAction SilentlyContinue
|
|
26
|
+
if (-not $OpenCodePath) {
|
|
27
|
+
Write-Host ""
|
|
28
|
+
Write-Host " WARNING: opencode CLI not found in PATH" -ForegroundColor Yellow
|
|
29
|
+
Write-Host " Install OpenCode: npm install -g opencode" -ForegroundColor Yellow
|
|
30
|
+
Write-Host ""
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Write-Host ""
|
|
34
|
+
Write-Host " ============================================" -ForegroundColor Cyan
|
|
35
|
+
Write-Host " Atos Agentic Factory" -ForegroundColor Cyan
|
|
36
|
+
Write-Host " Registering opencode:// protocol" -ForegroundColor Cyan
|
|
37
|
+
Write-Host " ============================================" -ForegroundColor Cyan
|
|
38
|
+
Write-Host ""
|
|
39
|
+
Write-Host " Handler: $HandlerPath" -ForegroundColor White
|
|
40
|
+
Write-Host ""
|
|
41
|
+
|
|
42
|
+
$ProtocolKey = "HKCU:\Software\Classes\opencode"
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
New-Item -Path $ProtocolKey -Force | Out-Null
|
|
46
|
+
Set-ItemProperty -Path $ProtocolKey -Name "(Default)" -Value "URL:OpenCode Protocol"
|
|
47
|
+
Set-ItemProperty -Path $ProtocolKey -Name "URL Protocol" -Value ""
|
|
48
|
+
|
|
49
|
+
New-Item -Path "$ProtocolKey\DefaultIcon" -Force | Out-Null
|
|
50
|
+
Set-ItemProperty -Path "$ProtocolKey\DefaultIcon" -Name "(Default)" -Value "cmd.exe,0"
|
|
51
|
+
|
|
52
|
+
New-Item -Path "$ProtocolKey\shell\open\command" -Force | Out-Null
|
|
53
|
+
|
|
54
|
+
$Command = "`"$HandlerPath`" `"%1`""
|
|
55
|
+
Set-ItemProperty -Path "$ProtocolKey\shell\open\command" -Name "(Default)" -Value $Command
|
|
56
|
+
|
|
57
|
+
Write-Host " [OK] Protocol opencode:// registered successfully!" -ForegroundColor Green
|
|
58
|
+
Write-Host ""
|
|
59
|
+
Write-Host " You can now use the 'Open with OpenCode' button" -ForegroundColor White
|
|
60
|
+
Write-Host " on the Atos Agentic Factory marketplace." -ForegroundColor White
|
|
61
|
+
Write-Host ""
|
|
62
|
+
Write-Host " To test: open a browser and navigate to:" -ForegroundColor Gray
|
|
63
|
+
Write-Host " opencode://open?agent=build" -ForegroundColor Yellow
|
|
64
|
+
Write-Host ""
|
|
65
|
+
} catch {
|
|
66
|
+
Write-Host " ERROR: Could not register the protocol." -ForegroundColor Red
|
|
67
|
+
Write-Host " Details: $_" -ForegroundColor Red
|
|
68
|
+
Write-Host ""
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (-not [Console]::IsInputRedirected) {
|
|
72
|
+
Read-Host "Press Enter to exit"
|
|
73
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
REM ============================================================
|
|
5
|
+
REM OpenCode Protocol Handler for Atos Agentic Factory
|
|
6
|
+
REM SECURITY: All parameters are sanitized before being passed
|
|
7
|
+
REM to PowerShell to prevent command injection via malicious URLs.
|
|
8
|
+
REM ============================================================
|
|
9
|
+
|
|
10
|
+
set "URL=%~1"
|
|
11
|
+
if not defined URL (
|
|
12
|
+
echo [ERROR] No URL provided.
|
|
13
|
+
exit /b 1
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if "%URL:~-1%"=="/" set "URL=%URL:~0,-1%"
|
|
17
|
+
|
|
18
|
+
REM Extract query string
|
|
19
|
+
set "QUERY="
|
|
20
|
+
for /f "tokens=2 delims=?" %%a in ("%URL%") do set "QUERY=%%a"
|
|
21
|
+
|
|
22
|
+
set "OC_PROMPT="
|
|
23
|
+
set "OC_AGENT="
|
|
24
|
+
set "OC_PROJECT="
|
|
25
|
+
set "OC_MODEL="
|
|
26
|
+
|
|
27
|
+
if defined QUERY (
|
|
28
|
+
for %%p in ("%QUERY:&=" "%") do (
|
|
29
|
+
set "PARAM=%%~p"
|
|
30
|
+
for /f "tokens=1,2 delims==" %%k in ("!PARAM!") do (
|
|
31
|
+
if /i "%%k"=="prompt" set "OC_PROMPT=%%l"
|
|
32
|
+
if /i "%%k"=="agent" set "OC_AGENT=%%l"
|
|
33
|
+
if /i "%%k"=="project" set "OC_PROJECT=%%l"
|
|
34
|
+
if /i "%%k"=="model" set "OC_MODEL=%%l"
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
REM URL-decode parameters (safe subset only)
|
|
40
|
+
if defined OC_PROMPT (
|
|
41
|
+
set "OC_PROMPT=!OC_PROMPT:+= !"
|
|
42
|
+
set "OC_PROMPT=!OC_PROMPT:%%20= !"
|
|
43
|
+
set "OC_PROMPT=!OC_PROMPT:%%3A=:!"
|
|
44
|
+
set "OC_PROMPT=!OC_PROMPT:%%2F=/!"
|
|
45
|
+
set "OC_PROMPT=!OC_PROMPT:%%0A= !"
|
|
46
|
+
)
|
|
47
|
+
if defined OC_AGENT (
|
|
48
|
+
set "OC_AGENT=!OC_AGENT:+= !"
|
|
49
|
+
set "OC_AGENT=!OC_AGENT:%%20= !"
|
|
50
|
+
)
|
|
51
|
+
if defined OC_PROJECT (
|
|
52
|
+
set "OC_PROJECT=!OC_PROJECT:+= !"
|
|
53
|
+
set "OC_PROJECT=!OC_PROJECT:%%20= !"
|
|
54
|
+
set "OC_PROJECT=!OC_PROJECT:%%3A=:!"
|
|
55
|
+
set "OC_PROJECT=!OC_PROJECT:%%2F=/!"
|
|
56
|
+
set "OC_PROJECT=!OC_PROJECT:%%5C=\!"
|
|
57
|
+
)
|
|
58
|
+
if defined OC_MODEL (
|
|
59
|
+
set "OC_MODEL=!OC_MODEL:+= !"
|
|
60
|
+
set "OC_MODEL=!OC_MODEL:%%20= !"
|
|
61
|
+
set "OC_MODEL=!OC_MODEL:%%2F=/!"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
REM ── SECURITY: Strip dangerous characters from all parameters ──
|
|
65
|
+
if defined OC_PROMPT (
|
|
66
|
+
set "OC_PROMPT=!OC_PROMPT:"=!"
|
|
67
|
+
set "OC_PROMPT=!OC_PROMPT:'=!"
|
|
68
|
+
set "OC_PROMPT=!OC_PROMPT:;=!"
|
|
69
|
+
set "OC_PROMPT=!OC_PROMPT:&=!"
|
|
70
|
+
set "OC_PROMPT=!OC_PROMPT:|=!"
|
|
71
|
+
set "OC_PROMPT=!OC_PROMPT:<=!"
|
|
72
|
+
set "OC_PROMPT=!OC_PROMPT:>=!"
|
|
73
|
+
set "OC_PROMPT=!OC_PROMPT:`=!"
|
|
74
|
+
set "OC_PROMPT=!OC_PROMPT:$=!"
|
|
75
|
+
set "OC_PROMPT=!OC_PROMPT:(=!"
|
|
76
|
+
set "OC_PROMPT=!OC_PROMPT:)=!"
|
|
77
|
+
set "OC_PROMPT=!OC_PROMPT:{=!"
|
|
78
|
+
set "OC_PROMPT=!OC_PROMPT:}=!"
|
|
79
|
+
set "OC_PROMPT=!OC_PROMPT:^=!"
|
|
80
|
+
)
|
|
81
|
+
if defined OC_AGENT (
|
|
82
|
+
set "OC_AGENT=!OC_AGENT:"=!"
|
|
83
|
+
set "OC_AGENT=!OC_AGENT:'=!"
|
|
84
|
+
set "OC_AGENT=!OC_AGENT:;=!"
|
|
85
|
+
set "OC_AGENT=!OC_AGENT:&=!"
|
|
86
|
+
set "OC_AGENT=!OC_AGENT:|=!"
|
|
87
|
+
set "OC_AGENT=!OC_AGENT:<=!"
|
|
88
|
+
set "OC_AGENT=!OC_AGENT:>=!"
|
|
89
|
+
set "OC_AGENT=!OC_AGENT:`=!"
|
|
90
|
+
set "OC_AGENT=!OC_AGENT:$=!"
|
|
91
|
+
set "OC_AGENT=!OC_AGENT:(=!"
|
|
92
|
+
set "OC_AGENT=!OC_AGENT:)=!"
|
|
93
|
+
set "OC_AGENT=!OC_AGENT:{=!"
|
|
94
|
+
set "OC_AGENT=!OC_AGENT:}=!"
|
|
95
|
+
set "OC_AGENT=!OC_AGENT:^=!"
|
|
96
|
+
)
|
|
97
|
+
if defined OC_MODEL (
|
|
98
|
+
set "OC_MODEL=!OC_MODEL:"=!"
|
|
99
|
+
set "OC_MODEL=!OC_MODEL:'=!"
|
|
100
|
+
set "OC_MODEL=!OC_MODEL:;=!"
|
|
101
|
+
set "OC_MODEL=!OC_MODEL:&=!"
|
|
102
|
+
set "OC_MODEL=!OC_MODEL:|=!"
|
|
103
|
+
set "OC_MODEL=!OC_MODEL:<=!"
|
|
104
|
+
set "OC_MODEL=!OC_MODEL:>=!"
|
|
105
|
+
set "OC_MODEL=!OC_MODEL:`=!"
|
|
106
|
+
set "OC_MODEL=!OC_MODEL:$=!"
|
|
107
|
+
set "OC_MODEL=!OC_MODEL:(=!"
|
|
108
|
+
set "OC_MODEL=!OC_MODEL:)=!"
|
|
109
|
+
set "OC_MODEL=!OC_MODEL:{=!"
|
|
110
|
+
set "OC_MODEL=!OC_MODEL:}=!"
|
|
111
|
+
set "OC_MODEL=!OC_MODEL:^=!"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
REM ── SECURITY: Validate project path ──
|
|
115
|
+
if defined OC_PROJECT (
|
|
116
|
+
set "OC_PROJECT=!OC_PROJECT:"=!"
|
|
117
|
+
set "OC_PROJECT=!OC_PROJECT:'=!"
|
|
118
|
+
set "OC_PROJECT=!OC_PROJECT:;=!"
|
|
119
|
+
set "OC_PROJECT=!OC_PROJECT:&=!"
|
|
120
|
+
set "OC_PROJECT=!OC_PROJECT:|=!"
|
|
121
|
+
set "OC_PROJECT=!OC_PROJECT:<=!"
|
|
122
|
+
set "OC_PROJECT=!OC_PROJECT:>=!"
|
|
123
|
+
set "OC_PROJECT=!OC_PROJECT:`=!"
|
|
124
|
+
set "OC_PROJECT=!OC_PROJECT:$=!"
|
|
125
|
+
set "OC_PROJECT=!OC_PROJECT:(=!"
|
|
126
|
+
set "OC_PROJECT=!OC_PROJECT:)=!"
|
|
127
|
+
set "OC_PROJECT=!OC_PROJECT:{=!"
|
|
128
|
+
set "OC_PROJECT=!OC_PROJECT:}=!"
|
|
129
|
+
set "OC_PROJECT=!OC_PROJECT:^=!"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if not defined OC_PROJECT set "OC_PROJECT=%USERPROFILE%"
|
|
133
|
+
|
|
134
|
+
REM Pass to PowerShell launcher (parameters are now sanitized)
|
|
135
|
+
powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File "%~dp0opencode-launch.ps1" -Agent "!OC_AGENT!" -Prompt "!OC_PROMPT!" -Model "!OC_MODEL!" -Project "!OC_PROJECT!"
|
|
136
|
+
|
|
137
|
+
exit /b 0
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$Agent = '',
|
|
3
|
+
[string]$Prompt = '',
|
|
4
|
+
[string]$Model = '',
|
|
5
|
+
[string]$Project = ''
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
# ── SECURITY: Sanitize all input parameters ──
|
|
9
|
+
function Sanitize-CmdParam {
|
|
10
|
+
param([string]$Value)
|
|
11
|
+
if (-not $Value) { return '' }
|
|
12
|
+
$Value = $Value -replace '[;&|<>`$(){}!''"^]', ''
|
|
13
|
+
if ($Value.Length -gt 2000) { $Value = $Value.Substring(0, 2000) }
|
|
14
|
+
return $Value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$Agent = Sanitize-CmdParam $Agent
|
|
18
|
+
$Prompt = Sanitize-CmdParam $Prompt
|
|
19
|
+
$Model = Sanitize-CmdParam $Model
|
|
20
|
+
|
|
21
|
+
# ── SECURITY: Validate project path ──
|
|
22
|
+
if ($Project) {
|
|
23
|
+
$Project = Sanitize-CmdParam $Project
|
|
24
|
+
if ($Project -match '\.\.' -or $Project -match '^\\\\') {
|
|
25
|
+
Write-Host "`n ERROR: Invalid project path: '$Project'" -ForegroundColor Red
|
|
26
|
+
Write-Host " Relative paths (..) and UNC paths (\\) are not allowed.`n" -ForegroundColor Red
|
|
27
|
+
Read-Host "Press Enter"
|
|
28
|
+
exit 1
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (-not $Project) { $Project = $env:USERPROFILE }
|
|
32
|
+
|
|
33
|
+
# Find opencode
|
|
34
|
+
$opencode = Join-Path $env:APPDATA 'npm\opencode.cmd'
|
|
35
|
+
if (-not (Test-Path $opencode)) {
|
|
36
|
+
$found = Get-Command opencode -ErrorAction SilentlyContinue
|
|
37
|
+
if ($found) { $opencode = $found.Source }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (-not (Test-Path $opencode)) {
|
|
41
|
+
Write-Host "`n ERROR: opencode not found!`n Install: npm install -g opencode`n" -ForegroundColor Red
|
|
42
|
+
Read-Host "Press Enter"
|
|
43
|
+
exit 1
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# ── SECURITY: Use random temp file name ──
|
|
47
|
+
$randomName = [System.IO.Path]::GetRandomFileName() -replace '\.', ''
|
|
48
|
+
$tempFile = Join-Path $env:TEMP "atos-oc-$randomName.cmd"
|
|
49
|
+
|
|
50
|
+
$lines = @()
|
|
51
|
+
$lines += '@echo off'
|
|
52
|
+
$lines += "title OpenCode - Atos Agentic Factory"
|
|
53
|
+
$lines += "cd /d `"$Project`""
|
|
54
|
+
$lines += 'echo.'
|
|
55
|
+
$lines += 'echo ============================================'
|
|
56
|
+
$lines += 'echo Atos Agentic Factory - OpenCode'
|
|
57
|
+
$lines += 'echo ============================================'
|
|
58
|
+
|
|
59
|
+
$cmdLine = "`"$opencode`""
|
|
60
|
+
|
|
61
|
+
if ($Agent) {
|
|
62
|
+
$lines += "echo Agent : $Agent"
|
|
63
|
+
$cmdLine += " --agent `"$Agent`""
|
|
64
|
+
}
|
|
65
|
+
if ($Prompt) {
|
|
66
|
+
$displayPrompt = $Prompt.Substring(0, [Math]::Min(60, $Prompt.Length))
|
|
67
|
+
$lines += "echo Prompt : $displayPrompt..."
|
|
68
|
+
$cmdLine += " --prompt `"$Prompt`""
|
|
69
|
+
}
|
|
70
|
+
if ($Model) {
|
|
71
|
+
$lines += "echo Model : $Model"
|
|
72
|
+
$cmdLine += " --model `"$Model`""
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$lines += "echo Folder : $Project"
|
|
76
|
+
$lines += 'echo ============================================'
|
|
77
|
+
$lines += 'echo.'
|
|
78
|
+
$lines += "call $cmdLine"
|
|
79
|
+
$lines += 'echo.'
|
|
80
|
+
$lines += 'echo [OpenCode finished]'
|
|
81
|
+
$lines += "del /q `"$tempFile`" 2>nul"
|
|
82
|
+
$lines += 'pause'
|
|
83
|
+
|
|
84
|
+
$lines | Out-File -FilePath $tempFile -Encoding ascii
|
|
85
|
+
|
|
86
|
+
if (-not (Test-Path $Project)) {
|
|
87
|
+
Write-Host "`n WARNING: Folder '$Project' does not exist." -ForegroundColor Yellow
|
|
88
|
+
Write-Host " Launching in default user folder.`n" -ForegroundColor Yellow
|
|
89
|
+
$Project = $env:USERPROFILE
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Start-Process $tempFile -WorkingDirectory $Project
|
|
93
|
+
|
|
94
|
+
exit 0
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentic-factory-bridge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local bridge for Atos Agentic Factory — connects the marketplace to OpenCode CLI on your machine",
|
|
5
|
+
"main": "bridge.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agentic-factory-bridge": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node bridge.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"opencode",
|
|
14
|
+
"bridge",
|
|
15
|
+
"atos",
|
|
16
|
+
"agentic-factory",
|
|
17
|
+
"ai-agents",
|
|
18
|
+
"marketplace"
|
|
19
|
+
],
|
|
20
|
+
"author": "Atos Agentic Factory",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"express": "^4.21.0",
|
|
24
|
+
"cors": "^2.8.5",
|
|
25
|
+
"uuid": "^9.0.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin/",
|
|
32
|
+
"bridge.js",
|
|
33
|
+
"opencode-handler.cmd",
|
|
34
|
+
"opencode-launch.ps1",
|
|
35
|
+
"install-protocol.ps1",
|
|
36
|
+
"uninstall-protocol.ps1"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Uninstall OpenCode Protocol Handler
|
|
2
|
+
# Usage: agentic-factory-bridge uninstall
|
|
3
|
+
# OR: powershell -ExecutionPolicy Bypass -File uninstall-protocol.ps1
|
|
4
|
+
|
|
5
|
+
$ProtocolKey = "HKCU:\Software\Classes\opencode"
|
|
6
|
+
|
|
7
|
+
if (Test-Path $ProtocolKey) {
|
|
8
|
+
Remove-Item -Path $ProtocolKey -Recurse -Force
|
|
9
|
+
Write-Host " [OK] Protocol opencode:// removed." -ForegroundColor Green
|
|
10
|
+
} else {
|
|
11
|
+
Write-Host " Protocol opencode:// was not registered." -ForegroundColor Yellow
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (-not [Console]::IsInputRedirected) {
|
|
15
|
+
Read-Host "Press Enter to exit"
|
|
16
|
+
}
|