@squidcode/forever-plugin 0.4.0 → 0.5.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/dist/index.js +46 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readFileSync, existsSync } from 'fs';
|
|
|
12
12
|
import { resolve } from 'path';
|
|
13
13
|
const server = new McpServer({
|
|
14
14
|
name: 'forever',
|
|
15
|
-
version: '0.
|
|
15
|
+
version: '0.5.0',
|
|
16
16
|
});
|
|
17
17
|
const machineId = getOrCreateMachineId();
|
|
18
18
|
const sessionId = `${Date.now()}-${randomBytes(4).toString('hex')}`;
|
|
@@ -699,34 +699,59 @@ server.tool('memory_sync_files', 'Sync all shared files for a project — downlo
|
|
|
699
699
|
});
|
|
700
700
|
// Login subcommand
|
|
701
701
|
if (process.argv[2] === 'login') {
|
|
702
|
-
const
|
|
703
|
-
const rl = readline.createInterface({
|
|
704
|
-
input: process.stdin,
|
|
705
|
-
output: process.stdout,
|
|
706
|
-
});
|
|
707
|
-
const ask = (q) => new Promise((resolve) => rl.question(q, resolve));
|
|
702
|
+
const SERVER_URL = 'https://forever.squidcode.com';
|
|
708
703
|
console.log('Forever Plugin Login\n');
|
|
709
|
-
const DEFAULT_SERVER = 'https://forever.squidcode.com';
|
|
710
|
-
const serverUrlInput = await ask(`Server URL [${DEFAULT_SERVER}]: `);
|
|
711
|
-
const serverUrl = serverUrlInput.trim() || DEFAULT_SERVER;
|
|
712
|
-
const email = await ask('Email: ');
|
|
713
|
-
const password = await ask('Password: ');
|
|
714
704
|
try {
|
|
715
705
|
const { default: axios } = await import('axios');
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
console.log(
|
|
706
|
+
// Request a device code
|
|
707
|
+
const codeRes = await axios.post(`${SERVER_URL}/api/auth/device/code`);
|
|
708
|
+
const { device_code, user_code, expires_in } = codeRes.data;
|
|
709
|
+
const authUrl = `${SERVER_URL}/auth/device?code=${user_code}`;
|
|
710
|
+
console.log('Your verification code:\n');
|
|
711
|
+
console.log(` ${user_code}\n`);
|
|
712
|
+
console.log(`Open this URL to authorize:\n ${authUrl}\n`);
|
|
713
|
+
// Try to open browser automatically
|
|
714
|
+
try {
|
|
715
|
+
const { execFileSync } = await import('child_process');
|
|
716
|
+
const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
717
|
+
execFileSync(cmd, [authUrl], { stdio: 'ignore' });
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
// Browser open failed — user can open manually
|
|
721
|
+
}
|
|
722
|
+
console.log('Waiting for authorization...');
|
|
723
|
+
const deadline = Date.now() + expires_in * 1000;
|
|
724
|
+
while (Date.now() < deadline) {
|
|
725
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
726
|
+
try {
|
|
727
|
+
const tokenRes = await axios.post(`${SERVER_URL}/api/auth/device/token`, { device_code });
|
|
728
|
+
const { saveCredentials } = await import('./client.js');
|
|
729
|
+
saveCredentials({
|
|
730
|
+
serverUrl: SERVER_URL,
|
|
731
|
+
token: tokenRes.data.access_token,
|
|
732
|
+
});
|
|
733
|
+
console.log('\nAuthenticated! Credentials saved to ~/.forever/credentials.json');
|
|
734
|
+
process.exit(0);
|
|
735
|
+
}
|
|
736
|
+
catch (err) {
|
|
737
|
+
const msg = err.response?.data?.message;
|
|
738
|
+
if (msg === 'authorization_pending') {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (msg === 'expired_token') {
|
|
742
|
+
console.error('\nCode expired. Please run login again.');
|
|
743
|
+
process.exit(1);
|
|
744
|
+
}
|
|
745
|
+
throw err;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
console.error('\nCode expired. Please run login again.');
|
|
749
|
+
process.exit(1);
|
|
723
750
|
}
|
|
724
751
|
catch (err) {
|
|
725
752
|
console.error('\nLogin failed:', err.response?.data?.message || err.message);
|
|
726
753
|
process.exit(1);
|
|
727
754
|
}
|
|
728
|
-
rl.close();
|
|
729
|
-
process.exit(0);
|
|
730
755
|
}
|
|
731
756
|
// Start MCP server
|
|
732
757
|
const transport = new StdioServerTransport();
|