scorpiox-bot-plugin-filesystem
←ui.htmlhtml
290 lines · 13 KBHEADBlameDownload
1<!DOCTYPE html>
2<html lang="en"><head><meta charset="utf-8">
3<meta name="viewport" content="width=device-width,initial-scale=1">
4<title>filesystem</title>
5<!--TOKENS-->
6<style>
7*{box-sizing:border-box}
8html,body{margin:0}
9body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;
10 line-height:1.5;-webkit-font-smoothing:antialiased}
11.wrap{max-width:1080px;margin:0 auto;padding:16px}
12.card{background:var(--surface);border:1px solid var(--line);border-radius:14px;
13 padding:16px;margin-bottom:14px}
14h1{font-size:17px;margin:0 0 2px;letter-spacing:-.01em}
15h2{font-size:12px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;
16 color:var(--text-2);margin:0 0 12px}
17.sub{color:var(--text-2);font-size:12.5px;margin:0 0 14px}
18.grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:14px}
19@media(max-width:860px){.grid{grid-template-columns:minmax(0,1fr)}}
20.row{display:flex;gap:8px;align-items:center}
21.row.wraprow{flex-wrap:wrap}
22input[type=text]{flex:1;min-width:0;background:var(--input-bg);color:var(--text);
23 border:1px solid var(--line);border-radius:9px;padding:8px 10px;font-family:var(--mono);
24 font-size:12.5px;outline:none}
25input[type=text]:focus{border-color:var(--blue)}
26button{background:var(--surface-2);color:var(--text);border:1px solid var(--line);
27 border-radius:9px;padding:7px 12px;font-family:inherit;font-size:12.5px;font-weight:600;
28 cursor:pointer;flex:0 0 auto}
29button:hover{background:var(--surface-hover);border-color:var(--line-2)}
30button:active{transform:scale(.98)}
31button.primary{background:var(--blue);border-color:transparent;color:#fff}
32button.danger{color:var(--red)}
33ul.roots{list-style:none;margin:0;padding:0}
34ul.roots li{display:flex;align-items:center;gap:10px;padding:9px 10px;
35 border:1px solid var(--line);border-radius:10px;margin-bottom:7px;background:var(--bg-2)}
36ul.roots li .p{flex:1;min-width:0;font-family:var(--mono);font-size:12.5px;
37 overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
38ul.roots li .note{font-size:11px;color:var(--text-2);flex:0 0 auto}
39ul.roots li .note.warn{color:var(--orange)}
40ul.roots li .note.bad{color:var(--red)}
41.pill{font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase;
42 padding:2px 7px;border-radius:980px;border:1px solid var(--line);color:var(--text-2);flex:0 0 auto}
43.pill.rw{color:var(--green);border-color:rgba(48,209,88,.35)}
44.pill.ro{color:var(--teal);border-color:rgba(100,210,255,.35)}
45table.tools{width:100%;border-collapse:collapse;font-size:12.5px}
46table.tools th{text-align:left;font-size:10.5px;letter-spacing:.08em;text-transform:uppercase;
47 color:var(--text-2);font-weight:700;padding:0 8px 6px 0;border-bottom:1px solid var(--line)}
48table.tools td{padding:7px 8px 7px 0;border-bottom:1px solid var(--line);vertical-align:top}
49table.tools tr:last-child td{border-bottom:0}
50table.tools td.n{font-family:var(--mono);font-size:12px;white-space:nowrap}
51table.tools td.d{color:var(--text-2);font-size:11.5px}
52.sw{position:relative;width:38px;height:22px;flex:0 0 auto;border-radius:980px;
53 background:var(--surface-2);border:1px solid var(--line);cursor:pointer;padding:0}
54.sw[aria-checked=true]{background:var(--green);border-color:transparent}
55.sw i{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;
56 background:#fff;transition:transform .16s var(--ease)}
57.sw[aria-checked=true] i{transform:translateX(16px)}
58pre{margin:0;background:var(--code-bg);border:1px solid var(--line);border-radius:10px;
59 padding:10px 12px;font-family:var(--mono);font-size:11.5px;white-space:pre-wrap;
60 word-break:break-all;max-height:220px;overflow:auto}
61.kv{display:flex;flex-wrap:wrap;gap:6px 16px;font-size:12px;color:var(--text-2);margin:0 0 12px}
62.kv b{color:var(--text);font-weight:600;font-family:var(--mono)}
63.msg{font-size:12.5px;padding:8px 10px;border-radius:9px;margin:0 0 10px;display:none}
64.msg.show{display:block}
65.msg.ok{background:rgba(48,209,88,.12);color:var(--green);border:1px solid rgba(48,209,88,.3)}
66.msg.err{background:rgba(255,69,58,.12);color:var(--red);border:1px solid rgba(255,69,58,.3)}
67.msg.warn{background:rgba(255,159,10,.12);color:var(--orange);border:1px solid rgba(255,159,10,.3)}
68a{color:var(--blue);text-decoration:none}
69.hint{font-size:11.5px;color:var(--text-2);margin:8px 0 0}
70.nomargin{margin-bottom:0}
71</style>
72</head><body>
73<div class="wrap">
74
75<div class="card">
76 <h1>filesystem</h1>
77 <p class="sub">Allowlisted filesystem tools for your node, over MCP. Every path is
78 canonicalised on disk and must land inside a directory you list here. Nothing
79 outside them is readable or writable, and symlinks that point out are refused.</p>
80 <div class="kv" id="kv">
81 <span>plugin <b>plugin_filesystem</b></span>
82 <span>version <b id="kver">–</b></span>
83 <span>kind <b>mcp</b></span>
84 <span>config <b id="kfile">–</b></span>
85 </div>
86 <div class="msg" id="msg"></div>
87 <div class="hint">Server-rendered summary below; the controls need JavaScript and the
88 node password the bot already holds.</div>
89 <pre id="noscript">Allowed roots and permissions are read from
90~/.scorpiox/connectors/plugin_filesystem/roots.json
91(override with the FS_ALLOWED_ROOTS environment variable).</pre>
92</div>
93
94<div class="grid">
95
96 <div class="card">
97 <h2>Allowed directories</h2>
98 <ul class="roots" id="roots"><li><span class="p">loading…</span></li></ul>
99 <div class="row" style="margin-top:10px">
100 <input type="text" id="newroot" placeholder="/absolute/path/to/a/directory"
101 autocomplete="off" spellcheck="false">
102 <button class="primary" id="btnadd">Allow</button>
103 </div>
104 <p class="hint">Absolute paths only, no <code>..</code>. A directory that does not
105 exist yet is refused here so a typo cannot quietly widen the sandbox. Paths shown
106 in orange resolve elsewhere (a symlink or a mount) — the canonical form is what the
107 tools check.</p>
108 </div>
109
110 <div class="card">
111 <h2>Tool permissions</h2>
112 <table class="tools"><thead><tr><th>Tool</th><th></th></tr></thead>
113 <tbody id="tools"><tr><td class="d" colspan="2">loading…</td></tr></tbody></table>
114 <p class="hint">Disabled tools answer with a refusal instead of running, so an agent
115 gets an explanation rather than a missing tool. <b>list_allowed_directories</b>
116 cannot be switched off — it is how you diagnose a refusal.</p>
117 </div>
118
119</div>
120
121<div class="card">
122 <h2>Sandbox boundary test</h2>
123 <div class="row wraprow">
124 <input type="text" id="testpath" placeholder="/absolute/path/you/want/to/check"
125 autocomplete="off" spellcheck="false">
126 <button id="btntest">Test path</button>
127 </div>
128 <div id="testout" style="margin-top:10px"></div>
129 <p class="hint">Reports exactly what a tool would see: allowed or not, the canonical
130 path, and the rule that refused it. Use it before blaming a tool for a path that
131 was never in scope.</p>
132</div>
133
134<div class="card">
135 <h2>Register with the connector router</h2>
136 <pre id="snippet">{}</pre>
137 <p class="hint">The node's single <b>sx-connector-mcp</b> router reads this file and
138 exposes every installed MCP connector through four meta-tools, so the agent's tool
139 budget stays flat no matter how many connectors you install.</p>
140</div>
141
142</div>
143<script>
144var q=new URLSearchParams(location.search);
145var node=q.get('node')||'';
146var sid=q.get('id')||'';
147var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||
148 localStorage.getItem('bot_active_pwd')||'';
149var HUB=q.get('plugin')||'';
150
151/* Two call routes; this is the most common plugin bug.
152 * served through the hub (/plugins?plugin=plugin_filesystem&node=..)
153 * -> call the hub proxy back: /plugins?plugin=..&action=..
154 * opened directly on the node
155 * -> the plugin IS the route: /plugin_filesystem?action=..
156 * Calling /plugins?plugin= on the node returns the discovery list, not us. */
157function url(action,extra){
158 return (HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_filesystem')+
159 '?action='+encodeURIComponent(action)+
160 (extra?('&'+extra):'')+
161 (node?'&node='+encodeURIComponent(node):'')+
162 (sid?'&id='+encodeURIComponent(sid):'')+
163 (pwd?'&pwd='+encodeURIComponent(pwd):'');
164}
165function api(action,extra){
166 var h=pwd?{'X-Bot-Password':pwd}:{};
167 return fetch(url(action,extra),{headers:h}).then(function(r){
168 return r.json().then(function(j){return {status:r.status,body:j};});
169 });
170}
171var msgEl=document.getElementById('msg');
172function say(text,kind){
173 msgEl.textContent=text;
174 msgEl.className='msg show '+(kind||'ok');
175 clearTimeout(say._t);
176 say._t=setTimeout(function(){msgEl.className='msg';},4200);
177}
178function esc(s){
179 return String(s==null?'':s).replace(/[&<>"]/g,function(c){
180 return {'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c];
181 });
182}
183
184function renderStatus(st){
185 document.getElementById('kver').textContent=st.version||'';
186 document.getElementById('kfile').textContent=st.roots_file||'';
187 document.getElementById('noscript').textContent=
188 'config: '+(st.roots_file||'(not yet written)')+'\n'+
189 'source: '+(st.config_source||'')+'\n'+
190 'roots: '+((st.roots||[]).length
191 ? (st.roots||[]).map(function(r){return r.canonical;}).join('\n ')
192 : '(none - nothing is reachable)');
193 document.getElementById('snippet').textContent=JSON.stringify(
194 {mcpServers:{filesystem:{
195 command:'~/.scorpiox/plugins/plugin_filesystem',
196 args:['--mcp'],
197 slug:'filesystem'}}},null,2);
198}
199function renderRoots(roots){
200 var ul=document.getElementById('roots');
201 ul.innerHTML='';
202 if(!roots||!roots.length){
203 ul.innerHTML='<li><span class="p">No allowed directories — the plugin can read and '+
204 'write nothing. Add one below.</span></li>';
205 return;
206 }
207 roots.forEach(function(r){
208 var li=document.createElement('li');
209 var note='',cls='';
210 if(!r.exists){note='missing';cls='bad';}
211 else if(!r.is_dir){note='not a directory';cls='bad';}
212 else if(r.drift){note='→ '+r.canonical;cls='warn';}
213 li.innerHTML='<span class="p" title="'+esc(r.canonical)+'">'+esc(r.configured||r.canonical)+
214 '</span>'+(note?'<span class="note '+cls+'">'+esc(note)+'</span>':'')+
215 '<button class="danger" data-rm="'+esc(r.canonical)+'">Remove</button>';
216 ul.appendChild(li);
217 });
218 Array.prototype.forEach.call(ul.querySelectorAll('[data-rm]'),function(b){
219 b.addEventListener('click',function(){
220 api('roots_remove','path='+encodeURIComponent(b.getAttribute('data-rm'))).then(function(x){
221 if(x.body&&x.body.ok){say('Removed '+b.getAttribute('data-rm'));refresh();}
222 else say((x.body&&x.body.error)||('HTTP '+x.status),'err');
223 });
224 });
225 });
226}
227function renderTools(tools){
228 var tb=document.getElementById('tools');
229 tb.innerHTML='';
230 tools.forEach(function(t){
231 var tr=document.createElement('tr');
232 tr.innerHTML='<td class="n">'+esc(t.name)+'</td>'+
233 '<td class="d">'+esc(t.read_only?'read-only':(t.destructive?'writes':'creates'))+'</td>'+
234 '<td class="d">'+esc(t.description.slice(0,64))+'…</td>'+
235 '<td style="text-align:right"><button class="sw" role="switch" data-t="'+esc(t.name)+
236 '" aria-checked="'+(t.enabled?'true':'false')+'"><i></i></button></td>';
237 tb.appendChild(tr);
238 });
239 Array.prototype.forEach.call(tb.querySelectorAll('.sw'),function(b){
240 b.addEventListener('click',function(){
241 var on=b.getAttribute('aria-checked')!=='true';
242 api('permissions_set','tool='+encodeURIComponent(b.getAttribute('data-t'))+
243 '&enabled='+(on?'true':'false')).then(function(x){
244 if(x.body&&x.body.ok){b.setAttribute('aria-checked',on?'true':'false');
245 say((on?'Enabled ':'Disabled ')+b.getAttribute('data-t'));}
246 else say((x.body&&x.body.error)||('HTTP '+x.status),'err');
247 });
248 });
249 });
250}
251function renderTest(x){
252 var el=document.getElementById('testout');
253 if(!x||!x.body||!x.body.ok){el.innerHTML='';return;}
254 var b=x.body;
255 el.innerHTML='<div class="msg show '+(b.allowed?'ok':'warn')+'">'+
256 (b.allowed?'ALLOWED':'REFUSED')+' — '+esc(b.path)+
257 (b.canonical?(' → <span style="font-family:var(--mono)">'+esc(b.canonical)+'</span>'):'')+
258 ' — '+esc(b.reason||'')+'</div>';
259}
260function refresh(){
261 api('status').then(function(x){
262 if(!x.body||!x.body.ok){say((x.body&&x.body.error)||('HTTP '+x.status),'err');return;}
263 renderStatus(x.body);
264 });
265 api('roots').then(function(x){if(x.body&&x.body.ok)renderRoots(x.body.roots);});
266 api('tools').then(function(x){if(x.body&&x.body.ok)renderTools(x.body.tools);});
267}
268document.getElementById('btnadd').addEventListener('click',function(){
269 var v=document.getElementById('newroot').value.trim();
270 if(!v){say('Type a directory path first','warn');return;}
271 api('roots_add','path='+encodeURIComponent(v)).then(function(x){
272 if(x.body&&x.body.ok){say('Allowed '+x.body.added);
273 document.getElementById('newroot').value='';refresh();}
274 else say((x.body&&x.body.error)||('HTTP '+x.status),'err');
275 });
276});
277document.getElementById('newroot').addEventListener('keydown',function(e){
278 if(e.key==='Enter')document.getElementById('btnadd').click();
279});
280document.getElementById('btntest').addEventListener('click',function(){
281 var v=document.getElementById('testpath').value.trim();
282 if(!v){say('Type a path to test','warn');return;}
283 api('sandbox_test','path='+encodeURIComponent(v)).then(function(x){renderTest(x);});
284});
285document.getElementById('testpath').addEventListener('keydown',function(e){
286 if(e.key==='Enter')document.getElementById('btntest').click();
287});
288refresh();
289</script>
290</body></html>