slaunt 0.1.16 → 0.1.18
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 +17 -106
- package/bin/slaunt-hooks.js +96 -0
- package/package.json +9 -59
- package/release/SlauntKillBar.zip +0 -0
- package/release/manifest.json +7 -0
- package/scripts/killbar-portability-check.js +67 -0
- package/scripts/package-killbar-macos.sh +38 -0
- package/src/approval-manager.js +53 -0
- package/src/cli-auth.js +230 -0
- package/src/compact-wordmark.js +13 -0
- package/src/desktop/broker-daemon.js +18 -0
- package/src/desktop/broker-grants.js +37 -0
- package/src/desktop/broker-hook-command.js +23 -0
- package/src/desktop/broker-keychain.js +29 -0
- package/src/desktop/broker-launch-agent.js +34 -0
- package/src/desktop/broker-service.js +40 -0
- package/src/desktop/chat-capture-command.js +7 -0
- package/src/desktop/chat-hook-capture.js +445 -0
- package/src/desktop/claude-lifecycle.js +143 -0
- package/src/desktop/client-identity.js +19 -0
- package/src/desktop/native-claude-broker.js +34 -0
- package/src/desktop/native-claude-connection.js +42 -0
- package/src/desktop/tool-guard-command.js +13 -0
- package/src/desktop/tool-guard.js +225 -0
- package/src/discovery/catalog.js +734 -0
- package/src/full-screen.js +88 -0
- package/src/helper-release.js +27 -0
- package/src/hidden-oauth.js +70 -0
- package/src/independent-grants.js +38 -0
- package/src/install-flow.js +71 -0
- package/src/killbar-background-install.js +47 -0
- package/src/killbar-enrollment.js +74 -0
- package/src/killbar-launch-agent.js +10 -0
- package/src/mcp-identity.js +6 -0
- package/src/native-config.js +150 -0
- package/src/native-oauth.js +33 -0
- package/src/oauth-cohort.js +43 -0
- package/src/pty-wrapper.py +57 -0
- package/src/read-json.js +8 -0
- package/src/setup/client-installer.js +93 -0
- package/src/setup/codex-guard-supervisor.js +34 -0
- package/src/setup/hook-installer.js +496 -0
- package/src/setup/managed-policy.js +26 -0
- package/src/setup/mcp-config-installer.js +204 -0
- package/src/setup-flow.js +66 -0
- package/src/tui.js +205 -0
- package/test/approval-manager.test.js +27 -0
- package/test/broker-grants.test.js +14 -0
- package/test/broker-keychain.test.js +14 -0
- package/test/broker-launch-agent.test.js +15 -0
- package/test/broker-service.test.js +42 -0
- package/test/cli-auth-recovery.test.js +15 -0
- package/test/codex-guard-supervisor.test.js +25 -0
- package/test/full-screen.test.js +49 -0
- package/test/helper-release.test.js +22 -0
- package/test/hidden-oauth.test.js +44 -0
- package/test/hook-installer.test.js +232 -0
- package/test/independent-grants.test.js +16 -0
- package/test/install-flow.test.js +24 -0
- package/test/killbar-background-install.test.js +15 -0
- package/test/killbar-enrollment.test.js +115 -0
- package/test/killbar-launch-agent.test.js +12 -0
- package/test/killbar-portability.test.js +17 -0
- package/test/managed-policy.test.js +18 -0
- package/test/native-claude-broker.test.js +19 -0
- package/test/native-claude-connection.test.js +17 -0
- package/test/native-claude-hooks.test.js +9 -0
- package/test/native-config.test.js +3 -0
- package/test/native-integration.cjs +29 -0
- package/test/native-oauth.test.js +23 -0
- package/test/oauth-cohort.test.js +26 -0
- package/test/tui.test.js +100 -0
- package/LICENSE +0 -201
- package/dist/audit/risk-engine.d.ts +0 -4
- package/dist/audit/risk-engine.d.ts.map +0 -1
- package/dist/audit/risk-engine.js +0 -174
- package/dist/audit/risk-engine.js.map +0 -1
- package/dist/audit/run.d.ts +0 -16
- package/dist/audit/run.d.ts.map +0 -1
- package/dist/audit/run.js +0 -66
- package/dist/audit/run.js.map +0 -1
- package/dist/classification/builtin-catalog.d.ts +0 -3
- package/dist/classification/builtin-catalog.d.ts.map +0 -1
- package/dist/classification/builtin-catalog.js +0 -283
- package/dist/classification/builtin-catalog.js.map +0 -1
- package/dist/classification/catalog.d.ts +0 -10
- package/dist/classification/catalog.d.ts.map +0 -1
- package/dist/classification/catalog.js +0 -194
- package/dist/classification/catalog.js.map +0 -1
- package/dist/classification/classifier.d.ts +0 -3
- package/dist/classification/classifier.d.ts.map +0 -1
- package/dist/classification/classifier.js +0 -64
- package/dist/classification/classifier.js.map +0 -1
- package/dist/classification/public-catalog-config.d.ts +0 -3
- package/dist/classification/public-catalog-config.d.ts.map +0 -1
- package/dist/classification/public-catalog-config.js +0 -5
- package/dist/classification/public-catalog-config.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -220
- package/dist/cli.js.map +0 -1
- package/dist/config/discover.d.ts +0 -8
- package/dist/config/discover.d.ts.map +0 -1
- package/dist/config/discover.js +0 -163
- package/dist/config/discover.js.map +0 -1
- package/dist/config/install.d.ts +0 -10
- package/dist/config/install.d.ts.map +0 -1
- package/dist/config/install.js +0 -143
- package/dist/config/install.js.map +0 -1
- package/dist/config/paths.d.ts +0 -24
- package/dist/config/paths.d.ts.map +0 -1
- package/dist/config/paths.js +0 -90
- package/dist/config/paths.js.map +0 -1
- package/dist/demo.d.ts +0 -4
- package/dist/demo.d.ts.map +0 -1
- package/dist/demo.js +0 -99
- package/dist/demo.js.map +0 -1
- package/dist/explanation/local.d.ts +0 -24
- package/dist/explanation/local.d.ts.map +0 -1
- package/dist/explanation/local.js +0 -667
- package/dist/explanation/local.js.map +0 -1
- package/dist/mcp/introspect.d.ts +0 -14
- package/dist/mcp/introspect.d.ts.map +0 -1
- package/dist/mcp/introspect.js +0 -186
- package/dist/mcp/introspect.js.map +0 -1
- package/dist/presentation/plain-language.d.ts +0 -12
- package/dist/presentation/plain-language.d.ts.map +0 -1
- package/dist/presentation/plain-language.js +0 -120
- package/dist/presentation/plain-language.js.map +0 -1
- package/dist/privacy/redaction.d.ts +0 -2
- package/dist/privacy/redaction.d.ts.map +0 -1
- package/dist/privacy/redaction.js +0 -50
- package/dist/privacy/redaction.js.map +0 -1
- package/dist/report/html.d.ts +0 -4
- package/dist/report/html.d.ts.map +0 -1
- package/dist/report/html.js +0 -101
- package/dist/report/html.js.map +0 -1
- package/dist/tui/analysis-path.d.ts +0 -17
- package/dist/tui/analysis-path.d.ts.map +0 -1
- package/dist/tui/analysis-path.js +0 -184
- package/dist/tui/analysis-path.js.map +0 -1
- package/dist/tui/render.d.ts +0 -4
- package/dist/tui/render.d.ts.map +0 -1
- package/dist/tui/render.js +0 -273
- package/dist/tui/render.js.map +0 -1
- package/dist/tui/splash.d.ts +0 -15
- package/dist/tui/splash.d.ts.map +0 -1
- package/dist/tui/splash.js +0 -130
- package/dist/tui/splash.js.map +0 -1
- package/dist/tui/stream.d.ts +0 -6
- package/dist/tui/stream.d.ts.map +0 -1
- package/dist/tui/stream.js +0 -56
- package/dist/tui/stream.js.map +0 -1
- package/dist/types.d.ts +0 -131
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -8
- package/dist/version.js.map +0 -1
- package/models/APACHE-2.0.txt +0 -202
- package/models/MODEL.json +0 -29
- package/models/NOTICE.md +0 -23
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test=require('node:test'),assert=require('node:assert/strict');
|
|
3
|
+
const {ENDPOINT,authorizedFetch,startNativeClaudeConnection}=require('../src/desktop/native-claude-connection');
|
|
4
|
+
test('broker sends its own credential only to Central and retries one unauthorized response',async()=>{
|
|
5
|
+
const calls=[];const grantProvider={async getFreshTokens(){return {accessToken:'first'};},async refreshAfterUnauthorized(value){assert.equal(value,'first');return {accessToken:'second'};}};
|
|
6
|
+
const request=authorizedFetch({grantProvider,fetchImpl:async req=>{calls.push(req);return new Response('',{status:calls.length===1?401:200});}});
|
|
7
|
+
assert.equal((await request(ENDPOINT,{method:'POST',body:'{}'})).status,200);
|
|
8
|
+
assert.deepEqual(calls.map(r=>r.headers.get('authorization')),['Bearer first','Bearer second']);
|
|
9
|
+
assert.ok(calls.every(r=>r.headers.get('x-slaunt-client')==='claude-code'&&r.redirect==='error'));
|
|
10
|
+
await assert.rejects(request('https://example.com/mcp'),/broker-destination-invalid/);assert.equal(calls.length,2);
|
|
11
|
+
});
|
|
12
|
+
test('connection failure closes resources and does not start a guard',async()=>{
|
|
13
|
+
let clientClosed=false,transportClosed=false;
|
|
14
|
+
const grantProvider={async getFreshTokens(){return {accessToken:'token'};},async refreshAfterUnauthorized(){return {accessToken:'token'};}};
|
|
15
|
+
await assert.rejects(startNativeClaudeConnection({grantProvider,makeClient:()=>({async connect(){throw new Error('offline');},async close(){clientClosed=true;}}),makeTransport:()=>({async close(){transportClosed=true;}})}),/broker-connection-unavailable/);
|
|
16
|
+
assert.ok(clientClosed&&transportClosed);
|
|
17
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test=require('node:test'),assert=require('node:assert/strict');
|
|
3
|
+
const {createClaudeCodeHooks,mergeSlauntHooks}=require('../src/setup/hook-installer');
|
|
4
|
+
test('native Claude hooks connect lifecycle events to the persistent broker and block unavailable guards',()=>{
|
|
5
|
+
const config=createClaudeCodeHooks({nativeBroker:true,broker:{command:process.execPath,args:['--slaunt-mcp-stdio']}});
|
|
6
|
+
for(const event of ['SessionStart','UserPromptSubmit','Stop']){const hook=config.hooks[event][0].hooks[0];assert.equal(hook.type,'command');assert.match(hook.command,/broker-hook-command\.js/);assert.equal(hook.onFailure,'block');}
|
|
7
|
+
const guard=config.hooks.PreToolUse[0].hooks[0];assert.match(guard.command,/tool-guard-command\.js/);assert.equal(guard.onFailure,'block');
|
|
8
|
+
const merged=mergeSlauntHooks(config,config);assert.equal(merged.hooks.PreToolUse.length,1);assert.equal(merged.hooks.UserPromptSubmit.length,1);
|
|
9
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';const test=require('node:test');const assert=require('node:assert/strict');const fs=require('node:fs');const os=require('node:os');const path=require('node:path');const {installNativeConfig,ENDPOINT}=require('../src/native-config');
|
|
2
|
+
test('installs remote config for both clients and preserves unrelated settings',()=>{const home=fs.mkdtempSync(path.join(os.tmpdir(),'slaunt-native-config-'));try{fs.writeFileSync(path.join(home,'.claude.json'),'{"keep":true}');for(const clientId of ['codex-cli','claude-code']){assert.equal(installNativeConfig({clientId,homeDir:home}).status,'installed');assert.equal(installNativeConfig({clientId,homeDir:home}).status,'unchanged');}assert.equal(JSON.parse(fs.readFileSync(path.join(home,'.claude.json'))).keep,true);assert.match(fs.readFileSync(path.join(home,'.codex/config.toml'),'utf8'),new RegExp(ENDPOINT.replace(/[.*+?^${}()|[\]\\]/g,'\\$&')));}finally{fs.rmSync(home,{recursive:true,force:true});}});
|
|
3
|
+
test('refuses an unrelated server under the same name',()=>{const home=fs.mkdtempSync(path.join(os.tmpdir(),'slaunt-native-config-'));try{fs.mkdirSync(path.join(home,'.codex'));fs.writeFileSync(path.join(home,'.codex/config.toml'),'[mcp_servers.slaunt]\ncommand="other"\n');assert.equal(installNativeConfig({clientId:'codex-cli',homeDir:home}).status,'conflict');}finally{fs.rmSync(home,{recursive:true,force:true});}});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const http=require('node:http'),fs=require('node:fs'),os=require('node:os'),path=require('node:path'),cp=require('node:child_process'),crypto=require('node:crypto');
|
|
3
|
+
const {runHiddenLogin}=require('../src/hidden-oauth');
|
|
4
|
+
const {authorizeCohort}=require('../src/oauth-cohort');
|
|
5
|
+
const {createApprovalManager}=require('../src/approval-manager');
|
|
6
|
+
(async()=>{
|
|
7
|
+
const root=fs.mkdtempSync(path.join(os.tmpdir(),'slaunt-oauth-integration-'));
|
|
8
|
+
const expected=new Map();
|
|
9
|
+
const server=http.createServer(async(req,res)=>{
|
|
10
|
+
const base=`http://127.0.0.1:${server.address().port}`;
|
|
11
|
+
const json=(code,data)=>{res.writeHead(code,{'content-type':'application/json'});res.end(JSON.stringify(data));};
|
|
12
|
+
if(req.method==='GET'&&req.url.startsWith('/.well-known/oauth-protected-resource'))return json(200,{resource:base+'/mcp',authorization_servers:[base]});
|
|
13
|
+
if(req.method==='GET'&&(req.url.startsWith('/.well-known/oauth-authorization-server')||req.url.startsWith('/.well-known/openid-configuration')))return json(200,{issuer:base,authorization_endpoint:base+'/authorize',token_endpoint:base+'/token',registration_endpoint:base+'/register',response_types_supported:['code'],grant_types_supported:['authorization_code','refresh_token'],code_challenge_methods_supported:['S256'],token_endpoint_auth_methods_supported:['none'],scopes_supported:['mcp:tools']});
|
|
14
|
+
if(req.method==='POST'&&req.url==='/register'){let s='';for await(const c of req)s+=c;let j=JSON.parse(s);return json(201,{client_id:'test-client',redirect_uris:j.redirect_uris,token_endpoint_auth_method:'none'});}
|
|
15
|
+
if(req.method==='POST'&&req.url==='/token'){let s='';for await(const c of req)s+=c;let f=new URLSearchParams(s);let got=crypto.createHash('sha256').update(f.get('code_verifier')||'').digest('base64url');if(expected.get(f.get('code'))!==got)return json(400,{error:'invalid_grant'});expected.delete(f.get('code'));return json(200,{access_token:'test-access',refresh_token:crypto.randomBytes(24).toString('hex'),token_type:'Bearer',expires_in:3600,scope:'mcp:tools'});}
|
|
16
|
+
res.writeHead(401,{'www-authenticate':`Bearer resource_metadata="${base}/.well-known/oauth-protected-resource/mcp"`});res.end();
|
|
17
|
+
});
|
|
18
|
+
await new Promise(r=>server.listen(0,'127.0.0.1',r));const base=`http://127.0.0.1:${server.address().port}`;
|
|
19
|
+
const env={...process.env,CODEX_HOME:root+'/codex',HOME:root,CLAUDE_CONFIG_DIR:root+'/claude'};fs.mkdirSync(env.CODEX_HOME);fs.writeFileSync(env.CODEX_HOME+'/config.toml',`[mcp_servers.slaunt]\nurl = "${base}/mcp"\n`);
|
|
20
|
+
const add=cp.spawnSync('claude',['mcp','add','--scope','user','--transport','http','slaunt',base+'/mcp'],{env,stdio:'ignore',timeout:15000});
|
|
21
|
+
let failures=0, approvals=0;
|
|
22
|
+
if(add.status!==0){console.log('claude: configuration failed');failures++;}
|
|
23
|
+
else {
|
|
24
|
+
const manager=createApprovalManager({issuer:base,validateClient:async()=>true,issueCallback:async({request})=>{const code=crypto.randomBytes(18).toString('hex');expected.set(code,request.searchParams.get('code_challenge'));const cb=new URL(request.searchParams.get('redirect_uri'));cb.searchParams.set('code',code);cb.searchParams.set('state',request.searchParams.get('state'));return cb.toString();}});
|
|
25
|
+
try { await authorizeCohort({clients:['codex','claude'],issuer:base,timeoutMs:20000,login:opts=>runHiddenLogin({...opts,spawnImpl:(cmd,args,options)=>cp.spawn(cmd,args,{...options,env})}),approve:async requests=>{approvals++;const approval=await manager.create(requests);manager.approve({...approval,principal:'test-user',accepted:true});return manager.redeem(approval);}}); if(approvals!==1)throw new Error('approval-count');console.log('codex and claude: complete after one simulated approval'); }
|
|
26
|
+
catch(e){console.log('cohort: '+e.message);failures++;}
|
|
27
|
+
}
|
|
28
|
+
server.close();fs.rmSync(root,{recursive:true,force:true}); if (failures) process.exitCode=1;
|
|
29
|
+
})().catch(()=>{console.error('integration test failed');process.exitCode=1});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const { installOAuth, ENDPOINT } = require('../src/native-oauth');
|
|
5
|
+
const output = { log(){}, error(){} };
|
|
6
|
+
test('adds and authenticates each client through native OAuth', () => {
|
|
7
|
+
const calls=[];
|
|
8
|
+
const run=(exe,args) => { calls.push([exe,...args]); if(args[1]==='get') return {status:1}; return {status:0}; };
|
|
9
|
+
const results=installOAuth({clients:['codex','claude'],run,output});
|
|
10
|
+
assert.deepEqual(results.map(x=>x.status),['authenticated','authenticated']);
|
|
11
|
+
assert.ok(calls.some(x=>x.join(' ')===`codex mcp add slaunt --url ${ENDPOINT}`));
|
|
12
|
+
assert.ok(calls.some(x=>x.join(' ')==='claude mcp login slaunt'));
|
|
13
|
+
});
|
|
14
|
+
test('preserves a conflicting server and does not log in', () => {
|
|
15
|
+
const calls=[];
|
|
16
|
+
const run=(exe,args) => { calls.push(args); return {status:0,stdout:JSON.stringify({transport:{type:'stdio',command:'example'}})}; };
|
|
17
|
+
const results=installOAuth({clients:['codex'],run,output});
|
|
18
|
+
assert.equal(results[0].status,'conflict'); assert.equal(calls.length,1);
|
|
19
|
+
});
|
|
20
|
+
test('reuses a matching remote server and reports failed OAuth', () => {
|
|
21
|
+
const run=(exe,args) => args[1]==='get' ? {status:0,stdout:JSON.stringify({transport:{type:'streamable_http',url:ENDPOINT}})} : {status:1};
|
|
22
|
+
assert.equal(installOAuth({clients:['codex'],run,output})[0].status,'authentication-failed');
|
|
23
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const { authorizeCohort } = require('../src/oauth-cohort');
|
|
5
|
+
test('collects both client requests and asks for approval once', async () => {
|
|
6
|
+
let approvals = 0; const completed = [];
|
|
7
|
+
const login = async ({executable,authorize}) => { const cb = await authorize({client:executable,authorizationUrl:`request-${executable}`}); completed.push([executable,cb]); };
|
|
8
|
+
await authorizeCohort({clients:['codex','claude'],issuer:'https://example.test',login,approve:async requests => { approvals++; assert.deepEqual(requests.map(x=>x.client),['codex','claude']); return {codex:'callback-codex',claude:'callback-claude'}; }});
|
|
9
|
+
assert.equal(approvals,1); assert.deepEqual(completed,[['codex','callback-codex'],['claude','callback-claude']]);
|
|
10
|
+
});
|
|
11
|
+
test('rejects when approval is denied and does not complete either client', async () => {
|
|
12
|
+
let completed=0;
|
|
13
|
+
const login=async ({executable,authorize})=>{await authorize({client:executable,authorizationUrl:`request-${executable}`});completed++;};
|
|
14
|
+
await assert.rejects(authorizeCohort({clients:['codex','claude'],issuer:'https://example.test',login,approve:async()=>{throw new Error('denied');}}),/cohort-failed/);
|
|
15
|
+
assert.equal(completed,0);
|
|
16
|
+
});
|
|
17
|
+
test('fails closed if one client never produces a request', async () => {
|
|
18
|
+
let approvals=0;
|
|
19
|
+
const login=({executable,authorize})=>executable==='codex'?authorize({client:executable,authorizationUrl:'x'}):new Promise(()=>{});
|
|
20
|
+
await assert.rejects(authorizeCohort({clients:['codex','claude'],issuer:'https://example.test',login,timeoutMs:20,approve:async()=>{approvals++;}}),/cohort-failed/);
|
|
21
|
+
assert.equal(approvals,0);
|
|
22
|
+
});
|
|
23
|
+
test('identifies the failed native client without exposing its error text', async () => {
|
|
24
|
+
const login=async ({executable})=>{if(executable==='codex') throw new Error('sensitive details'); return new Promise(()=>{});};
|
|
25
|
+
await assert.rejects(authorizeCohort({clients:['codex','claude'],issuer:'https://example.test',login,approve:async()=>({})}),error=>error.message==='cohort-failed'&&error.setupStage==='native-login'&&error.setupClient==='codex'&&!JSON.stringify(error).includes('sensitive details'));
|
|
26
|
+
});
|
package/test/tui.test.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const test=require('node:test'),assert=require('node:assert/strict');
|
|
3
|
+
const {PassThrough,Writable}=require('node:stream');
|
|
4
|
+
const {createTerminal,SPLASH_LOGO}=require('../src/tui');
|
|
5
|
+
const {COMPACT_WORDMARK}=require('../src/compact-wordmark');
|
|
6
|
+
const {main}=require('../bin/slaunt-hooks');
|
|
7
|
+
function stream(tty=false){let text='';const output=new Writable({write(chunk,_encoding,done){text+=chunk;done();}});output.isTTY=tty;return {output,text:()=>text};}
|
|
8
|
+
function ttyInput(){const input=new PassThrough();input.isTTY=true;input.isRaw=false;input.setRawMode=value=>{input.isRaw=value;};return input;}
|
|
9
|
+
test('interactive selector supports keyboard selection and restores terminal mode',async()=>{
|
|
10
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',NO_COLOR:'1',SLAUNT_REDUCED_MOTION:'1'}});
|
|
11
|
+
const selection=terminal.selectClients();input.emit('keypress','',{name:'down'});input.emit('keypress','',{name:'return'});assert.equal(await selection,'codex');assert.equal(input.isRaw,false);assert.match(out.text(),/Codex \+ Claude Code \(recommended\)/);assert.match(out.text(),/◇ Which clients/);assert.match(out.text(),/\x1b\[\?25h/);
|
|
12
|
+
});
|
|
13
|
+
test('CI defaults without prompting and reduced motion disables the spinner',async()=>{
|
|
14
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',CI:'1',NO_COLOR:'1'}});assert.equal(await terminal.selectClients(),'both');terminal.progress('Checking');terminal.done('Checked');assert.doesNotMatch(out.text(),/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/);assert.equal(input.isRaw,false);
|
|
15
|
+
});
|
|
16
|
+
test('interactive selector cancels with control-c and restores terminal mode',async()=>{
|
|
17
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm'}});const selection=terminal.selectClients();input.emit('keypress','',{name:'c',ctrl:true});assert.equal(await selection,null);assert.equal(input.isRaw,false);
|
|
18
|
+
});
|
|
19
|
+
test('noninteractive terminal avoids control sequences',async()=>{
|
|
20
|
+
const out=stream(),err=stream();const terminal=createTerminal({input:new PassThrough(),output:out.output,error:err.output,env:{TERM:'dumb'}});await terminal.enter();terminal.banner();terminal.progress('Checking Slaunt');terminal.fail('Not ready','No settings changed.');terminal.close();assert.equal(await terminal.selectClients(),'both');assert.doesNotMatch(out.text()+err.text(),/\x1b/);
|
|
21
|
+
});
|
|
22
|
+
test('full screen uses alternate buffer, restores it and leaves a readable result',async()=>{
|
|
23
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',NO_COLOR:'1',SLAUNT_REDUCED_MOTION:'1'}});
|
|
24
|
+
await terminal.enter();terminal.banner();terminal.fail('Not ready','No settings changed.');terminal.close();terminal.close();
|
|
25
|
+
assert.match(out.text(),/\x1b\[\?1049h/);assert.match(out.text(),/\x1b\[\?1049l/);assert.match(out.text(),/Slaunt: Not ready\nNo settings changed/);assert.equal((out.text().match(/\x1b\[\?1049l/g)||[]).length,1);
|
|
26
|
+
});
|
|
27
|
+
test('splash uses the supplied ASCII art and animates a moving highlight',async()=>{
|
|
28
|
+
const input=ttyInput(),out=stream(true);out.output.columns=80;out.output.rows=24;
|
|
29
|
+
const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm'}});await terminal.enter();terminal.close();
|
|
30
|
+
assert.equal(SPLASH_LOGO.length,8);assert.equal(SPLASH_LOGO[0].trim(),' /$$ /$$'.trim());
|
|
31
|
+
assert.equal(SPLASH_LOGO[7],String.raw`|_______/ |__/ \_______/ \______/ |__/ |__/ \___/`);
|
|
32
|
+
assert.match(out.text(),/\x1b\[1;97m/);assert.ok((out.text().match(/\x1b\[1;97m/g)||[]).length>8);
|
|
33
|
+
});
|
|
34
|
+
test('reduced motion shows a static logo and small terminals use a compact fallback',async()=>{
|
|
35
|
+
const input=ttyInput(),out=stream(true);out.output.columns=80;out.output.rows=24;
|
|
36
|
+
const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',SLAUNT_REDUCED_MOTION:'1'}});await terminal.enter();terminal.close();
|
|
37
|
+
assert.ok(out.text().includes(SPLASH_LOGO[7]));assert.doesNotMatch(out.text(),/\x1b\[1;97m/);
|
|
38
|
+
const small=stream(true);small.output.columns=30;small.output.rows=12;
|
|
39
|
+
const compact=createTerminal({input:ttyInput(),output:small.output,error:small.output,env:{TERM:'xterm',SLAUNT_REDUCED_MOTION:'1'}});await compact.enter();compact.close();assert.match(small.text(),/SLAUNT/);assert.ok(!small.text().includes(SPLASH_LOGO[7]));
|
|
40
|
+
const medium=stream(true);medium.output.columns=45;medium.output.rows=20;
|
|
41
|
+
const tight=createTerminal({input:ttyInput(),output:medium.output,error:medium.output,env:{TERM:'xterm',SLAUNT_REDUCED_MOTION:'1'}});await tight.enter();tight.close();assert.ok(medium.text().includes(COMPACT_WORDMARK[2]));assert.ok(!medium.text().includes(SPLASH_LOGO[7]));
|
|
42
|
+
});
|
|
43
|
+
test('closing the full screen while selecting restores the raw terminal',async()=>{
|
|
44
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',SLAUNT_REDUCED_MOTION:'1'}});
|
|
45
|
+
await terminal.enter();const selection=terminal.selectClients();assert.equal(input.isRaw,true);terminal.close();assert.equal(input.isRaw,false);input.emit('keypress','',{name:'escape'});assert.equal(await selection,null);
|
|
46
|
+
});
|
|
47
|
+
test('resizing redraws the picker and keeps the selection',async()=>{
|
|
48
|
+
const input=ttyInput(),out=stream(true);out.output.columns=80;
|
|
49
|
+
const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',NO_COLOR:'1',SLAUNT_REDUCED_MOTION:'1'}});
|
|
50
|
+
await terminal.enter();const selection=terminal.selectClients();input.emit('keypress','',{name:'down'});out.output.columns=40;out.output.emit('resize');input.emit('keypress','',{name:'return'});
|
|
51
|
+
assert.equal(await selection,'codex');assert.match(out.text(),/Choose clients/);terminal.close();
|
|
52
|
+
});
|
|
53
|
+
test('installer restores the terminal when a client check throws',async()=>{
|
|
54
|
+
const input=ttyInput(),out=stream(true);const terminal=createTerminal({input,output:out.output,error:out.output,env:{TERM:'xterm',SLAUNT_REDUCED_MOTION:'1'}});
|
|
55
|
+
await assert.rejects(main(['install','--client','codex'],{terminal,env:{},probe:async()=>{throw new Error('probe failed');}}),/probe failed/);assert.match(out.text(),/\x1b\[\?1049l/);
|
|
56
|
+
});
|
|
57
|
+
test('installer shows unavailable status and never claims completion',async()=>{
|
|
58
|
+
const events=[];const terminal={banner(){events.push('banner');},progress(x){events.push(x);},done(x){events.push(x);},fail(x,d){events.push(x,d);},stop(){events.push('stop');},async selectClients(){return 'both';}};
|
|
59
|
+
const code=await main(['install'],{terminal,env:{},probe:async()=>true,fetch:async()=>new Response(JSON.stringify({issuer:'https://central-mcp-ccr-production.up.railway.app',slaunt_cli_setup_supported:false}),{status:200})});
|
|
60
|
+
assert.equal(code,1);assert.ok(events.includes('Setup is not yet enabled on Slaunt.'));assert.ok(events.includes('No client settings were changed.'));assert.ok(!events.some(x=>/installed|signed in/i.test(x)));
|
|
61
|
+
});
|
|
62
|
+
test('installer reports cancellation without checking clients or server',async()=>{
|
|
63
|
+
let calls=0;const terminal={banner(){},fail(){},async selectClients(){return null;}};
|
|
64
|
+
assert.equal(await main(['install'],{terminal,env:{},probe:async()=>{calls++;},fetch:async()=>{calls++;}}),130);assert.equal(calls,0);
|
|
65
|
+
});
|
|
66
|
+
test('explicit client invokes the installer with the resolved executable',async()=>{
|
|
67
|
+
const checked=[],events=[];const terminal={banner(){},progress(){},done(x){events.push(x);},fail(x){events.push(x);},stop(){},selectClients(){throw new Error('unexpected prompt');}};
|
|
68
|
+
let options;
|
|
69
|
+
const code=await main(['install','--client','codex'],{terminal,env:{},probe:async client=>{checked.push(client);return '/app/codex';},fetch:async()=>new Response(JSON.stringify({issuer:'https://central-mcp-ccr-production.up.railway.app',slaunt_cli_setup_supported:true}),{status:200}),installFlow:async input=>{options=input;return {installed:true};}});
|
|
70
|
+
assert.equal(code,0);assert.deepEqual(checked,['codex']);assert.deepEqual(options.clients,['codex']);assert.equal(options.executablePaths.codex,'/app/codex');
|
|
71
|
+
});
|
|
72
|
+
test('installer reports a missing packaged helper instead of success',async()=>{
|
|
73
|
+
const events=[];const terminal={banner(){},progress(){},done(){},fail(message){events.push(message);},stop(){}};
|
|
74
|
+
const code=await main(['install','--client','codex'],{terminal,env:{},probe:async()=>true,fetch:async()=>new Response(JSON.stringify({issuer:'https://central-mcp-ccr-production.up.railway.app',slaunt_cli_setup_supported:true})),installFlow:async()=>{throw new Error('killbar-release-missing');}});
|
|
75
|
+
assert.equal(code,1);assert.ok(events.includes('KillBar is missing from this installer.'));
|
|
76
|
+
});
|
|
77
|
+
test('picker discovers clients asynchronously and reuses selected checks',async()=>{
|
|
78
|
+
const events=[],calls=[];let select,resolveCodex,resolveClaude;
|
|
79
|
+
const terminal={interactive:true,banner(){},progress(){},done(){},fail(){},stop(){},close(){},setClientAvailability(client,state){events.push([client,state]);},selectClients(){return new Promise(r=>{select=r;});}};
|
|
80
|
+
const probe=client=>{calls.push(client);return new Promise(r=>{if(client==='codex')resolveCodex=r;else resolveClaude=r;});};
|
|
81
|
+
const run=main(['install'],{terminal,env:{},probe,fetch:async()=>new Response(JSON.stringify({issuer:'https://central-mcp-ccr-production.up.railway.app',slaunt_cli_setup_supported:false}))});
|
|
82
|
+
await new Promise(r=>setImmediate(r));assert.deepEqual(calls,['codex','claude']);assert.equal(typeof select,'function');
|
|
83
|
+
resolveCodex(true);resolveClaude(false);await new Promise(r=>setImmediate(r));
|
|
84
|
+
assert.ok(events.some(([c,s])=>c==='codex'&&s==='installed'));assert.ok(events.some(([c,s])=>c==='claude'&&s==='missing'));
|
|
85
|
+
select('codex');assert.equal(await run,1);assert.deepEqual(calls,['codex','claude']);
|
|
86
|
+
});
|
|
87
|
+
test('detects bundled macOS Codex when the terminal PATH does not include it',async()=>{
|
|
88
|
+
const fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
|
|
89
|
+
const {checkClient,resolveClient}=require('../bin/slaunt-hooks');const dir=await fs.mkdtemp(path.join(os.tmpdir(),'slaunt-codex-probe-'));
|
|
90
|
+
try{
|
|
91
|
+
const bundled=path.join(dir,'codex');await fs.writeFile(bundled,'#!/bin/sh\nexit 0\n',{mode:0o700});
|
|
92
|
+
const options={env:{PATH:dir+'/empty'},platform:'darwin',appCodexPath:bundled};
|
|
93
|
+
assert.equal(await checkClient('codex',options),true);
|
|
94
|
+
assert.equal(await resolveClient('codex',options),bundled);
|
|
95
|
+
assert.equal(await checkClient('claude',options),false);
|
|
96
|
+
assert.equal(await checkClient('codex',{...options,platform:'linux'}),false);
|
|
97
|
+
await fs.writeFile(bundled,'#!/bin/sh\nexit 1\n',{mode:0o700});
|
|
98
|
+
assert.equal(await checkClient('codex',options),false);
|
|
99
|
+
}finally{await fs.rm(dir,{recursive:true,force:true});}
|
|
100
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AuditSummary, ClassifiedTool, Finding, ServerConfig } from '../types.js';
|
|
2
|
-
export declare function analyzeRisks(servers: ServerConfig[], tools: ClassifiedTool[]): Finding[];
|
|
3
|
-
export declare function summarizeAudit(clientCount: number, serverCount: number, tools: ClassifiedTool[], findings: Finding[], serverBindings?: number): AuditSummary;
|
|
4
|
-
//# sourceMappingURL=risk-engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"risk-engine.d.ts","sourceRoot":"","sources":["../../src/audit/risk-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,OAAO,EACP,YAAY,EAEb,MAAM,aAAa,CAAC;AA8BrB,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,EAAE,CA8IxF;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,cAAc,EAAE,EACvB,QAAQ,EAAE,OAAO,EAAE,EACnB,cAAc,SAAc,GAC3B,YAAY,CAcd"}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { basename } from 'node:path';
|
|
2
|
-
const SEVERITY_ORDER = { critical: 5, high: 4, medium: 3, low: 2, info: 1 };
|
|
3
|
-
const SECRET_NAME = /(token|secret|password|private[_-]?key|credential|api[_-]?key)/i;
|
|
4
|
-
function unique(items) {
|
|
5
|
-
return [...new Set(items)];
|
|
6
|
-
}
|
|
7
|
-
function toolCapabilities(tools) {
|
|
8
|
-
return new Set(tools.flatMap((tool) => tool.classification.capabilities));
|
|
9
|
-
}
|
|
10
|
-
function finding(partial) {
|
|
11
|
-
const id = `${partial.severity}:${partial.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')}`;
|
|
12
|
-
return { id, ...partial };
|
|
13
|
-
}
|
|
14
|
-
function isLocalHost(hostname) {
|
|
15
|
-
return ['localhost', '127.0.0.1', '::1'].includes(hostname);
|
|
16
|
-
}
|
|
17
|
-
function packageIsPinned(argument) {
|
|
18
|
-
const packagePart = argument.startsWith('@') ? argument.slice(argument.indexOf('/') + 1) : argument;
|
|
19
|
-
const at = packagePart.lastIndexOf('@');
|
|
20
|
-
if (at < 0)
|
|
21
|
-
return false;
|
|
22
|
-
const version = packagePart.slice(at + 1);
|
|
23
|
-
return /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u.test(version);
|
|
24
|
-
}
|
|
25
|
-
export function analyzeRisks(servers, tools) {
|
|
26
|
-
const findings = [];
|
|
27
|
-
for (const tool of tools.filter((item) => item.classification.capabilities.includes('deploy-production'))) {
|
|
28
|
-
findings.push(finding({
|
|
29
|
-
severity: 'critical',
|
|
30
|
-
title: `${tool.clientLabel} can deploy without an external approval boundary`,
|
|
31
|
-
serverNames: [tool.serverName],
|
|
32
|
-
toolNames: [tool.name],
|
|
33
|
-
access: ['Trigger production deployments'],
|
|
34
|
-
why: 'A production-changing capability is directly exposed to the agent.',
|
|
35
|
-
recommendation: 'Require a human approval policy and restrict deployment scope by environment.',
|
|
36
|
-
clients: [tool.client],
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
for (const client of unique(tools.map((tool) => tool.client))) {
|
|
40
|
-
const clientTools = tools.filter((tool) => tool.client === client);
|
|
41
|
-
const capabilities = toolCapabilities(clientTools);
|
|
42
|
-
if (capabilities.has('execute-shell') && capabilities.has('read-secrets')) {
|
|
43
|
-
const label = clientTools[0]?.clientLabel || client;
|
|
44
|
-
findings.push(finding({
|
|
45
|
-
severity: 'high',
|
|
46
|
-
title: `${label} can execute shell commands and access secrets`,
|
|
47
|
-
serverNames: unique(clientTools
|
|
48
|
-
.filter((tool) => tool.classification.capabilities.some((capability) => ['execute-shell', 'read-secrets'].includes(capability)))
|
|
49
|
-
.map((tool) => tool.serverName)),
|
|
50
|
-
toolNames: unique(clientTools
|
|
51
|
-
.filter((tool) => tool.classification.capabilities.some((capability) => ['execute-shell', 'read-secrets'].includes(capability)))
|
|
52
|
-
.map((tool) => tool.name)),
|
|
53
|
-
access: ['Read credentials', 'Execute commands'],
|
|
54
|
-
why: 'These capabilities can be chained to disclose or misuse credentials.',
|
|
55
|
-
recommendation: 'Separate secret access from command execution and require approval for either boundary.',
|
|
56
|
-
clients: [client],
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const githubByClient = new Map();
|
|
61
|
-
for (const tool of tools.filter((item) => /github/i.test(item.serverName))) {
|
|
62
|
-
const list = githubByClient.get(tool.client) || [];
|
|
63
|
-
list.push(tool);
|
|
64
|
-
githubByClient.set(tool.client, list);
|
|
65
|
-
}
|
|
66
|
-
const broadGithubClients = [...githubByClient.entries()].filter(([, clientTools]) => {
|
|
67
|
-
const capabilities = toolCapabilities(clientTools);
|
|
68
|
-
return capabilities.has('edit-code') && capabilities.has('merge-pull-request');
|
|
69
|
-
});
|
|
70
|
-
if (broadGithubClients.length >= 2) {
|
|
71
|
-
findings.push(finding({
|
|
72
|
-
severity: 'high',
|
|
73
|
-
title: 'Detected clients share broad GitHub permissions',
|
|
74
|
-
serverNames: unique(broadGithubClients.flatMap(([, clientTools]) => clientTools.map((tool) => tool.serverName))),
|
|
75
|
-
toolNames: unique(broadGithubClients.flatMap(([, clientTools]) => clientTools.map((tool) => tool.name))),
|
|
76
|
-
access: ['Edit code', 'Create pull requests', 'Merge pull requests', 'Delete branches or files'],
|
|
77
|
-
why: 'Shared credentials erase role separation between agents.',
|
|
78
|
-
recommendation: 'Assign repository permissions and credentials by agent role.',
|
|
79
|
-
clients: broadGithubClients.map(([client]) => client),
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
for (const server of servers) {
|
|
83
|
-
if (server.url) {
|
|
84
|
-
try {
|
|
85
|
-
const url = new URL(server.url);
|
|
86
|
-
if (url.protocol === 'http:' && !isLocalHost(url.hostname)) {
|
|
87
|
-
findings.push(finding({
|
|
88
|
-
severity: 'critical',
|
|
89
|
-
title: `${server.clientLabel} sends MCP traffic over cleartext HTTP`,
|
|
90
|
-
serverNames: [server.name],
|
|
91
|
-
toolNames: [],
|
|
92
|
-
access: ['MCP requests and responses can cross the network unencrypted'],
|
|
93
|
-
why: 'A network observer could read or alter agent traffic.',
|
|
94
|
-
recommendation: 'Use HTTPS with certificate verification before enabling this server.',
|
|
95
|
-
clients: [server.client],
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
findings.push(finding({
|
|
101
|
-
severity: 'high',
|
|
102
|
-
title: `${server.clientLabel} has an invalid MCP server URL`,
|
|
103
|
-
serverNames: [server.name],
|
|
104
|
-
toolNames: [],
|
|
105
|
-
access: [],
|
|
106
|
-
why: 'The configured endpoint cannot be safely interpreted.',
|
|
107
|
-
recommendation: 'Replace the endpoint with a reviewed HTTPS URL.',
|
|
108
|
-
clients: [server.client],
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const inlineSecretKeys = server.envKeys.filter((key) => SECRET_NAME.test(key) && !/^\$\{.+\}$/u.test(server.env[key] || ''));
|
|
113
|
-
const hasSecretArgument = server.args.some((arg, index) => SECRET_NAME.test(arg) && (/[=:]/u.test(arg) || Boolean(server.args[index + 1] && !server.args[index + 1].startsWith('-'))));
|
|
114
|
-
if (inlineSecretKeys.length > 0 || hasSecretArgument) {
|
|
115
|
-
findings.push(finding({
|
|
116
|
-
severity: 'high',
|
|
117
|
-
title: `${server.clientLabel} stores credential material in an MCP configuration`,
|
|
118
|
-
serverNames: [server.name],
|
|
119
|
-
toolNames: [],
|
|
120
|
-
access: [...inlineSecretKeys.map((key) => `Environment key: ${key}`), ...(hasSecretArgument ? ['Credential-like command argument'] : [])],
|
|
121
|
-
why: 'Plaintext configuration values are exposed to local file readers and backups.',
|
|
122
|
-
recommendation: 'Reference a protected environment variable or operating-system credential store.',
|
|
123
|
-
clients: [server.client],
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
const command = server.command ? basename(server.command).toLowerCase() : '';
|
|
127
|
-
if (['npx', 'pnpx', 'bunx'].includes(command)) {
|
|
128
|
-
const packageArg = server.args.find((arg) => !arg.startsWith('-'));
|
|
129
|
-
if (packageArg && !packageIsPinned(packageArg)) {
|
|
130
|
-
findings.push(finding({
|
|
131
|
-
severity: 'medium',
|
|
132
|
-
title: `${server.name} can resolve an unpinned package at startup`,
|
|
133
|
-
serverNames: [server.name],
|
|
134
|
-
toolNames: [],
|
|
135
|
-
access: ['Execute package registry code'],
|
|
136
|
-
why: 'The code executed by this server can change without a configuration change.',
|
|
137
|
-
recommendation: 'Pin the package to an exact reviewed version and preserve the package-manager lock or integrity data.',
|
|
138
|
-
clients: [server.client],
|
|
139
|
-
}));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const suspiciousUnknowns = tools.filter((item) => item.classification.source === 'unknown' && /admin|execute|trigger|workflow|sync/i.test(item.name));
|
|
144
|
-
if (suspiciousUnknowns.length > 0) {
|
|
145
|
-
findings.push(finding({
|
|
146
|
-
severity: 'medium',
|
|
147
|
-
title: `${suspiciousUnknowns.length} unclassified tools appear state-changing`,
|
|
148
|
-
serverNames: unique(suspiciousUnknowns.map((tool) => tool.serverName)),
|
|
149
|
-
toolNames: unique(suspiciousUnknowns.map((tool) => tool.name)),
|
|
150
|
-
access: ['Potential administrative or execution capability'],
|
|
151
|
-
why: 'No trusted rule explains tools whose names suggest privileged behavior.',
|
|
152
|
-
recommendation: 'Review and classify these tools before leaving them exposed to an agent.',
|
|
153
|
-
clients: unique(suspiciousUnknowns.map((tool) => tool.client)),
|
|
154
|
-
}));
|
|
155
|
-
}
|
|
156
|
-
const deduplicated = [...new Map(findings.map((item) => [`${item.id}:${item.clients.join(',')}:${item.serverNames.join(',')}`, item])).values()];
|
|
157
|
-
return deduplicated.sort((a, b) => SEVERITY_ORDER[b.severity] - SEVERITY_ORDER[a.severity] || a.title.localeCompare(b.title));
|
|
158
|
-
}
|
|
159
|
-
export function summarizeAudit(clientCount, serverCount, tools, findings, serverBindings = serverCount) {
|
|
160
|
-
const highRiskFindings = findings.filter((item) => item.severity === 'critical' || item.severity === 'high').length;
|
|
161
|
-
const penalty = findings.reduce((total, item) => total + ({ critical: 22, high: 12, medium: 5, low: 2, info: 0 }[item.severity]), 0);
|
|
162
|
-
return {
|
|
163
|
-
clientsDetected: clientCount,
|
|
164
|
-
servers: serverCount,
|
|
165
|
-
serverBindings,
|
|
166
|
-
tools: tools.length,
|
|
167
|
-
classified: tools.filter((tool) => tool.classification.source !== 'unknown').length,
|
|
168
|
-
sensitiveCapabilities: tools.filter((tool) => tool.classification.sensitive).length,
|
|
169
|
-
highRiskFindings,
|
|
170
|
-
unclassified: tools.filter((tool) => tool.classification.source === 'unknown').length,
|
|
171
|
-
postureScore: Math.max(0, 100 - penalty),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
//# sourceMappingURL=risk-engine.js.map
|