cicy-code 2.3.326 → 2.3.328
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/bin/cicy-code.js +70 -12
- package/package.json +5 -5
package/bin/cicy-code.js
CHANGED
|
@@ -21,7 +21,7 @@ const os = require('os');
|
|
|
21
21
|
const path = require('path');
|
|
22
22
|
|
|
23
23
|
const rawArgs = process.argv.slice(2);
|
|
24
|
-
const { email: cloudEmail, args } =
|
|
24
|
+
const { email: cloudEmail, team: cloudTeam, args } = takeCloudArgs(rawArgs);
|
|
25
25
|
const PORT = process.env.PORT || '8008';
|
|
26
26
|
const CLOUD_ORIGIN = (process.env.CICY_CLOUD_ORIGIN || 'https://cicy-ai.com').replace(/\/$/, '');
|
|
27
27
|
|
|
@@ -56,7 +56,7 @@ main().catch((err) => {
|
|
|
56
56
|
|
|
57
57
|
async function main() {
|
|
58
58
|
let cloudEnv = {};
|
|
59
|
-
if (cloudEmail) cloudEnv = await cloudLogin(cloudEmail);
|
|
59
|
+
if (cloudEmail) cloudEnv = await cloudLogin(cloudEmail, cloudTeam);
|
|
60
60
|
if (!isUtility) ensurePortFree(PORT);
|
|
61
61
|
const child = spawn(binPath, args, {
|
|
62
62
|
stdio: 'inherit',
|
|
@@ -68,9 +68,10 @@ async function main() {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function
|
|
71
|
+
function takeCloudArgs(input) {
|
|
72
72
|
const output = [];
|
|
73
73
|
let email = '';
|
|
74
|
+
let team = '';
|
|
74
75
|
for (let i = 0; i < input.length; i += 1) {
|
|
75
76
|
const value = input[i];
|
|
76
77
|
if (value === '--email') {
|
|
@@ -78,6 +79,11 @@ function takeEmailArg(input) {
|
|
|
78
79
|
i += 1;
|
|
79
80
|
} else if (value.startsWith('--email=')) {
|
|
80
81
|
email = value.slice('--email='.length).trim().toLowerCase();
|
|
82
|
+
} else if (value === '--team') {
|
|
83
|
+
team = String(input[i + 1] || '').trim();
|
|
84
|
+
i += 1;
|
|
85
|
+
} else if (value.startsWith('--team=')) {
|
|
86
|
+
team = value.slice('--team='.length).trim();
|
|
81
87
|
} else {
|
|
82
88
|
output.push(value);
|
|
83
89
|
}
|
|
@@ -85,21 +91,34 @@ function takeEmailArg(input) {
|
|
|
85
91
|
if (email && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
|
|
86
92
|
throw new Error('invalid --email address');
|
|
87
93
|
}
|
|
88
|
-
|
|
94
|
+
if (team && !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/.test(team)) {
|
|
95
|
+
throw new Error('invalid --team identifier');
|
|
96
|
+
}
|
|
97
|
+
return { email, team, args: output };
|
|
89
98
|
}
|
|
90
99
|
|
|
91
|
-
async function cloudLogin(email) {
|
|
100
|
+
async function cloudLogin(email, requestedTeam) {
|
|
92
101
|
const credentialPath = cloudCredentialPath();
|
|
93
102
|
const saved = readJSON(credentialPath);
|
|
94
103
|
const instanceId = String(saved.instance_id || '').trim() ||
|
|
95
104
|
`code-${crypto.randomBytes(18).toString('hex')}`;
|
|
105
|
+
const teamId = requestedTeam || String(saved.team_id || '').trim() || `team-${Date.now()}`;
|
|
96
106
|
let token = saved.email === email ? String(saved.token || '') : '';
|
|
97
107
|
|
|
98
108
|
if (token) {
|
|
99
109
|
try {
|
|
100
|
-
await registerCloudInstance(token, instanceId);
|
|
110
|
+
await registerCloudInstance(token, instanceId, teamId);
|
|
111
|
+
writeCredential(credentialPath, {
|
|
112
|
+
...saved,
|
|
113
|
+
email,
|
|
114
|
+
instance_id: instanceId,
|
|
115
|
+
team_id: teamId,
|
|
116
|
+
token,
|
|
117
|
+
cloud_origin: CLOUD_ORIGIN,
|
|
118
|
+
updated_at: new Date().toISOString(),
|
|
119
|
+
});
|
|
101
120
|
console.log(`cicy-code: CiCy Cloud connected as ${email}`);
|
|
102
|
-
return cloudEnvironment(email, instanceId, token);
|
|
121
|
+
return cloudEnvironment(email, instanceId, teamId, token);
|
|
103
122
|
} catch {
|
|
104
123
|
token = '';
|
|
105
124
|
}
|
|
@@ -108,7 +127,14 @@ async function cloudLogin(email) {
|
|
|
108
127
|
const state = crypto.randomBytes(32).toString('hex');
|
|
109
128
|
await requestJSON('/api/auth/email/request', {
|
|
110
129
|
method: 'POST',
|
|
111
|
-
body: {
|
|
130
|
+
body: {
|
|
131
|
+
email,
|
|
132
|
+
state,
|
|
133
|
+
flow: 'desktop_poll',
|
|
134
|
+
lang: preferredLanguage(),
|
|
135
|
+
...loginRequestInfo(instanceId),
|
|
136
|
+
teamId,
|
|
137
|
+
},
|
|
112
138
|
});
|
|
113
139
|
console.log(`cicy-code: login email sent to ${email}`);
|
|
114
140
|
console.log('cicy-code: click the link in the email; waiting for confirmation…');
|
|
@@ -122,26 +148,57 @@ async function cloudLogin(email) {
|
|
|
122
148
|
throw new Error('email login expired; start cicy-code again');
|
|
123
149
|
}
|
|
124
150
|
token = String(result.token);
|
|
125
|
-
await registerCloudInstance(token, instanceId);
|
|
151
|
+
await registerCloudInstance(token, instanceId, teamId);
|
|
126
152
|
writeCredential(credentialPath, {
|
|
127
153
|
email,
|
|
128
154
|
instance_id: instanceId,
|
|
155
|
+
team_id: teamId,
|
|
129
156
|
token,
|
|
130
157
|
cloud_origin: CLOUD_ORIGIN,
|
|
131
158
|
updated_at: new Date().toISOString(),
|
|
132
159
|
});
|
|
133
160
|
console.log(`cicy-code: login successful; this device is now bound to ${email}`);
|
|
134
|
-
return cloudEnvironment(email, instanceId, token);
|
|
161
|
+
return cloudEnvironment(email, instanceId, teamId, token);
|
|
135
162
|
}
|
|
136
163
|
throw new Error('email login timed out; start cicy-code again');
|
|
137
164
|
}
|
|
138
165
|
|
|
139
|
-
|
|
166
|
+
function loginRequestInfo(instanceId) {
|
|
167
|
+
const cpus = os.cpus();
|
|
168
|
+
const cpu = cpus.length > 0 ? String(cpus[0].model || '').trim() : '';
|
|
169
|
+
let gpu = '';
|
|
170
|
+
try {
|
|
171
|
+
gpu = execSync('nvidia-smi --query-gpu=name,memory.total --format=csv,noheader', {
|
|
172
|
+
encoding: 'utf8',
|
|
173
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
174
|
+
timeout: 3000,
|
|
175
|
+
}).trim();
|
|
176
|
+
} catch {}
|
|
177
|
+
let clientVersion = '';
|
|
178
|
+
try {
|
|
179
|
+
clientVersion = String(require('../package.json').version || '');
|
|
180
|
+
} catch {}
|
|
181
|
+
return {
|
|
182
|
+
platform: isColab() ? 'colab' : process.platform,
|
|
183
|
+
system: `${os.type()} ${os.release()}`.trim(),
|
|
184
|
+
arch: process.arch,
|
|
185
|
+
runtime: isColab() ? 'colab' : (process.env.GITHUB_ACTIONS === 'true' ? 'github-actions' : 'native'),
|
|
186
|
+
hostname: os.hostname(),
|
|
187
|
+
instanceId,
|
|
188
|
+
clientVersion,
|
|
189
|
+
cpu,
|
|
190
|
+
memory: `${Math.round(os.totalmem() / 1024 / 1024)} MB`,
|
|
191
|
+
gpu,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function registerCloudInstance(token, instanceId, teamId) {
|
|
140
196
|
await requestJSON('/api/code/instances/register', {
|
|
141
197
|
method: 'POST',
|
|
142
198
|
token,
|
|
143
199
|
body: {
|
|
144
200
|
instanceId,
|
|
201
|
+
teamId,
|
|
145
202
|
platform: isColab() ? 'colab' : process.platform,
|
|
146
203
|
arch: process.arch,
|
|
147
204
|
runtime: isColab() ? 'colab' : 'native',
|
|
@@ -150,11 +207,12 @@ async function registerCloudInstance(token, instanceId) {
|
|
|
150
207
|
});
|
|
151
208
|
}
|
|
152
209
|
|
|
153
|
-
function cloudEnvironment(email, instanceId, token) {
|
|
210
|
+
function cloudEnvironment(email, instanceId, teamId, token) {
|
|
154
211
|
return {
|
|
155
212
|
CICY_CLOUD_ORIGIN: CLOUD_ORIGIN,
|
|
156
213
|
CICY_CLOUD_EMAIL: email,
|
|
157
214
|
CICY_CLOUD_INSTANCE_ID: instanceId,
|
|
215
|
+
CICY_CLOUD_TEAM_ID: teamId,
|
|
158
216
|
CICY_CLOUD_TOKEN: token,
|
|
159
217
|
};
|
|
160
218
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.3.
|
|
6
|
+
"version": "2.3.328",
|
|
7
7
|
"description": "CiCy Code - AI-powered development environment",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "cicybot",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"bin/cicy-code.js"
|
|
17
17
|
],
|
|
18
18
|
"optionalDependencies": {
|
|
19
|
-
"cicy-code-darwin-arm64": "2.3.
|
|
20
|
-
"cicy-code-darwin-x64": "2.3.
|
|
21
|
-
"cicy-code-linux-arm64": "2.3.
|
|
22
|
-
"cicy-code-linux-x64": "2.3.
|
|
19
|
+
"cicy-code-darwin-arm64": "2.3.328",
|
|
20
|
+
"cicy-code-darwin-x64": "2.3.328",
|
|
21
|
+
"cicy-code-linux-arm64": "2.3.328",
|
|
22
|
+
"cicy-code-linux-x64": "2.3.328"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|