sessioncast-cli 2.4.1 → 2.4.2

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.
@@ -79,13 +79,11 @@ class AgentRunner {
79
79
  }
80
80
  }
81
81
  static async loadConfig(configPath) {
82
- // Check if agent token is available (for relay connection)
83
- const agentToken = (0, config_1.getAgentToken)();
84
82
  // Check environment variable
85
83
  const envPath = process.env.SESSIONCAST_CONFIG || process.env.TMUX_REMOTE_CONFIG;
86
84
  // Try multiple default paths
87
85
  const defaultPaths = [
88
- path.join(process.env.HOME || '', '.sessioncast.yml'),
86
+ (0, config_1.getYmlPath)(),
89
87
  path.join(process.env.HOME || '', '.tmux-remote.yml'),
90
88
  ];
91
89
  let finalPath = configPath || envPath;
@@ -97,66 +95,61 @@ class AgentRunner {
97
95
  }
98
96
  }
99
97
  }
100
- // If no config file found but agent token exists, create default config
101
- if ((!finalPath || !fs.existsSync(finalPath)) && agentToken) {
102
- console.log('Using OAuth authentication');
103
- const machineId = os.hostname();
104
- // Try to fetch optimal relay URL from Platform API
105
- let relayUrl = await AgentRunner.fetchRelayUrlForAgent(agentToken);
106
- if (relayUrl) {
107
- console.log(`Fetched relay URL from Platform API: ${relayUrl}`);
98
+ // Load from yml file if exists
99
+ if (finalPath && fs.existsSync(finalPath)) {
100
+ console.log(`Loading config from: ${finalPath}`);
101
+ const content = fs.readFileSync(finalPath, 'utf-8');
102
+ const ext = path.extname(finalPath).toLowerCase();
103
+ if (ext === '.json') {
104
+ return JSON.parse(content);
108
105
  }
109
106
  else {
110
- relayUrl = (0, config_1.getRelayUrl)();
111
- console.log(`Using default relay URL: ${relayUrl}`);
107
+ return yaml.load(content);
112
108
  }
113
- return {
114
- machineId,
115
- relay: relayUrl,
116
- token: agentToken,
117
- api: {
118
- enabled: false
119
- }
120
- };
121
109
  }
122
- if (!finalPath || !fs.existsSync(finalPath)) {
123
- const isLoggedIn = (0, config_1.getAccessToken)() || (0, config_1.getAgentToken)();
124
- if (isLoggedIn) {
125
- // User is logged in but agent token not yet generated
126
- throw new Error('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' +
127
- ' Agent token not yet generated\n' +
128
- '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n' +
129
- ' Please run `sessioncast login` again to generate an agent token.\n\n' +
130
- ' Or create a config file manually:\n' +
131
- ' $ cat > ~/.sessioncast.yml << \'EOF\'\n' +
132
- ' machineId: my-machine\n' +
133
- ' relay: wss://relay.sessioncast.io/ws\n' +
134
- ' token: agt_YOUR_TOKEN\n' +
135
- ' EOF\n\n' +
136
- '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
137
- }
110
+ // No yml file found - check if we have agent token
111
+ const agentToken = (0, config_1.getAgentToken)();
112
+ if (!agentToken) {
138
113
  throw new Error('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' +
139
114
  ' Not logged in\n' +
140
115
  '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n' +
141
116
  ' Please login first:\n' +
142
117
  ' $ sessioncast login\n\n' +
143
- ' Or create a config file manually:\n' +
144
- ' $ cat > ~/.sessioncast.yml << \'EOF\'\n' +
145
- ' machineId: my-machine\n' +
146
- ' relay: wss://relay.sessioncast.io/ws\n' +
147
- ' token: agt_YOUR_TOKEN\n' +
148
- ' EOF\n\n' +
118
+ ' Or with agent token:\n' +
119
+ ' $ sessioncast login agt_YOUR_TOKEN\n\n' +
149
120
  '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
150
121
  }
151
- console.log(`Loading config from: ${finalPath}`);
152
- const content = fs.readFileSync(finalPath, 'utf-8');
153
- const ext = path.extname(finalPath).toLowerCase();
154
- if (ext === '.json') {
155
- return JSON.parse(content);
122
+ // Create yml file with agent token
123
+ const machineId = os.hostname();
124
+ // Try to fetch optimal relay URL from Platform API
125
+ let relayUrl = await AgentRunner.fetchRelayUrlForAgent(agentToken);
126
+ if (relayUrl) {
127
+ console.log(`Fetched relay URL from Platform API: ${relayUrl}`);
156
128
  }
157
129
  else {
158
- return yaml.load(content);
130
+ relayUrl = (0, config_1.getRelayUrl)();
131
+ console.log(`Using default relay URL: ${relayUrl}`);
159
132
  }
133
+ // Create config object
134
+ const newConfig = {
135
+ machineId,
136
+ relay: relayUrl,
137
+ token: agentToken,
138
+ api: {
139
+ enabled: false
140
+ }
141
+ };
142
+ // Save to yml file
143
+ const ymlPath = (0, config_1.getYmlPath)();
144
+ const ymlContent = yaml.dump(newConfig, {
145
+ indent: 2,
146
+ lineWidth: -1,
147
+ quotingType: '"',
148
+ forceQuotes: false
149
+ });
150
+ fs.writeFileSync(ymlPath, ymlContent, 'utf-8');
151
+ console.log(`Created config file: ${ymlPath}`);
152
+ return newConfig;
160
153
  }
161
154
  async start() {
162
155
  if (this.running)
package/dist/config.d.ts CHANGED
@@ -11,7 +11,19 @@ interface ConfigSchema {
11
11
  machineId?: string;
12
12
  hasSeenWelcome?: boolean;
13
13
  }
14
+ interface YmlConfig {
15
+ machineId?: string;
16
+ relay?: string;
17
+ token?: string;
18
+ api?: {
19
+ enabled?: boolean;
20
+ agentId?: string;
21
+ };
22
+ }
14
23
  declare const config: Conf<ConfigSchema>;
24
+ export declare function getYmlPath(): string;
25
+ export declare function loadYmlConfig(): YmlConfig | null;
26
+ export declare function saveYmlConfig(ymlConfig: YmlConfig): void;
15
27
  export declare function getApiKey(): string | undefined;
16
28
  export declare function setApiKey(key: string): void;
17
29
  export declare function clearApiKey(): void;
package/dist/config.js CHANGED
@@ -1,8 +1,44 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getYmlPath = getYmlPath;
40
+ exports.loadYmlConfig = loadYmlConfig;
41
+ exports.saveYmlConfig = saveYmlConfig;
6
42
  exports.getApiKey = getApiKey;
7
43
  exports.setApiKey = setApiKey;
8
44
  exports.clearApiKey = clearApiKey;
@@ -28,6 +64,10 @@ exports.getConfigPath = getConfigPath;
28
64
  exports.getRawAccessToken = getRawAccessToken;
29
65
  exports.getTokenExpiresAt = getTokenExpiresAt;
30
66
  const conf_1 = __importDefault(require("conf"));
67
+ const fs = __importStar(require("fs"));
68
+ const path = __importStar(require("path"));
69
+ const os = __importStar(require("os"));
70
+ const yaml = __importStar(require("js-yaml"));
31
71
  const config = new conf_1.default({
32
72
  projectName: 'sessioncast',
33
73
  defaults: {
@@ -36,6 +76,34 @@ const config = new conf_1.default({
36
76
  relayUrl: 'wss://relay.sessioncast.io/ws',
37
77
  }
38
78
  });
79
+ // YML file path
80
+ const YML_PATH = path.join(os.homedir(), '.sessioncast.yml');
81
+ function getYmlPath() {
82
+ return YML_PATH;
83
+ }
84
+ // Load config from yml file
85
+ function loadYmlConfig() {
86
+ try {
87
+ if (fs.existsSync(YML_PATH)) {
88
+ const content = fs.readFileSync(YML_PATH, 'utf-8');
89
+ return yaml.load(content);
90
+ }
91
+ }
92
+ catch (e) {
93
+ // Ignore errors
94
+ }
95
+ return null;
96
+ }
97
+ // Save config to yml file
98
+ function saveYmlConfig(ymlConfig) {
99
+ const content = yaml.dump(ymlConfig, {
100
+ indent: 2,
101
+ lineWidth: -1,
102
+ quotingType: '"',
103
+ forceQuotes: false
104
+ });
105
+ fs.writeFileSync(YML_PATH, content, 'utf-8');
106
+ }
39
107
  function getApiKey() {
40
108
  return config.get('apiKey');
41
109
  }
@@ -84,11 +152,29 @@ function setRefreshToken(token) {
84
152
  config.set('refreshToken', token);
85
153
  }
86
154
  // Agent token (for relay connection)
155
+ // Priority: yml > config.json
87
156
  function getAgentToken() {
157
+ // First check yml
158
+ const ymlConfig = loadYmlConfig();
159
+ if (ymlConfig?.token) {
160
+ return ymlConfig.token;
161
+ }
162
+ // Fallback to config.json
88
163
  return config.get('agentToken');
89
164
  }
90
165
  function setAgentToken(token) {
166
+ // Save to config.json (for compatibility)
91
167
  config.set('agentToken', token);
168
+ // Save to yml file
169
+ const ymlConfig = loadYmlConfig() || {};
170
+ ymlConfig.token = token;
171
+ if (!ymlConfig.machineId) {
172
+ ymlConfig.machineId = config.get('machineId') || os.hostname();
173
+ }
174
+ if (!ymlConfig.relay) {
175
+ ymlConfig.relay = config.get('relayUrl');
176
+ }
177
+ saveYmlConfig(ymlConfig);
92
178
  }
93
179
  function getMachineId() {
94
180
  return config.get('machineId');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sessioncast-cli",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "SessionCast CLI - Control your agents from anywhere",
5
5
  "main": "dist/index.js",
6
6
  "bin": {