@walkhi/code-relax 0.1.0-beta.30 → 0.1.0-beta.32
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 +95 -89
- package/dist/bin/cleanup-accounts.mjs +63 -63
- package/dist/bin/codex-remote.mjs +374 -367
- package/dist/bin/manage-relay-admin.mjs +20 -20
- package/dist/bin/migrate-relay-db.mjs +109 -109
- package/dist/bin/publish-android-release.mjs +63 -58
- package/dist/bin/publish-harmony-release.mjs +46 -0
- package/dist/bin/release-upload-server.mjs +174 -0
- package/dist/bin/self-relay-admin.mjs +8 -8
- package/dist/bin/self-relay-demo.mjs +33 -33
- package/dist/bin/self-relay-server.mjs +66 -66
- package/dist/build-platform.json +1 -1
- package/dist/get-lan-networks.ps1 +40 -40
- package/dist/get-shared-service-url.ps1 +6 -6
- package/dist/shared/app-server-events.cjs +422 -412
- package/dist/shared/code-browser.cjs +159 -159
- package/dist/shared/file-changes.cjs +31 -31
- package/dist/shared/file-citations.cjs +117 -117
- package/dist/shared/file-mentions.cjs +92 -92
- package/dist/shared/message-delivery.cjs +54 -54
- package/dist/shared/p2p-data-channel.cjs +72 -72
- package/dist/shared/p2p-diagnostics.cjs +28 -28
- package/dist/shared/p2p-file-channel.cjs +78 -74
- package/dist/shared/plan-pricing.cjs +32 -32
- package/dist/shared/question-attention.cjs +69 -0
- package/dist/shared/server-requests.cjs +219 -219
- package/dist/shared/timeline-sync.cjs +173 -173
- package/dist/skills/code-relax/SKILL.md +22 -22
- package/dist/src/archived-threads.mjs +22 -0
- package/dist/src/background-process.mjs +18 -18
- package/dist/src/bounded-process-log.mjs +63 -63
- package/dist/src/celsius-client.mjs +107 -107
- package/dist/src/code-browser.mjs +100 -100
- package/dist/src/desktop-launcher.mjs +46 -46
- package/dist/src/dots-approval-timeline.mjs +99 -99
- package/dist/src/dots-avatar.mjs +42 -42
- package/dist/src/dots-chat-projection.mjs +50 -50
- package/dist/src/dots-chat-server.mjs +461 -461
- package/dist/src/dots-message-images.mjs +319 -319
- package/dist/src/dots-profile.mjs +77 -77
- package/dist/src/dots-room-activity.mjs +94 -94
- package/dist/src/dots-room-client.mjs +135 -135
- package/dist/src/dots-room-projection.mjs +94 -94
- package/dist/src/dots-schedules.mjs +66 -66
- package/dist/src/dots-summary-tasks.mjs +32 -32
- package/dist/src/dots-task-catalog.mjs +430 -430
- package/dist/src/dots-task-files.mjs +52 -52
- package/dist/src/execution-health.mjs +26 -26
- package/dist/src/file-transfer-range.mjs +22 -22
- package/dist/src/file-upload-session.mjs +130 -130
- package/dist/src/hosted-history-app-server.mjs +103 -103
- package/dist/src/hosted-history-cache.mjs +113 -113
- package/dist/src/lan-socket-server.mjs +265 -263
- package/dist/src/managed-app-server.mjs +244 -244
- package/dist/src/message-images.mjs +9 -9
- package/dist/src/message-upload-files.mjs +74 -74
- package/dist/src/onboarding.mjs +12 -12
- package/dist/src/plan-pricing.mjs +47 -47
- package/dist/src/platform/README.md +12 -12
- package/dist/src/platform/codex-protocol.mjs +46 -46
- package/dist/src/platform/codex-runtime.mjs +3 -3
- package/dist/src/platform/credential-store.mjs +3 -3
- package/dist/src/platform/desktop-host.mjs +3 -3
- package/dist/src/platform/desktop-project-registration.mjs +3 -3
- package/dist/src/platform/desktop-project-store.mjs +208 -149
- package/dist/src/platform/file-opener.mjs +9 -0
- package/dist/src/platform/linux/README.md +3 -3
- package/dist/src/platform/linux/codex-runtime.mjs +56 -0
- package/dist/src/platform/linux/credential-store.mjs +28 -0
- package/dist/src/platform/linux/desktop-host.mjs +83 -0
- package/dist/src/platform/linux/desktop-installation.mjs +36 -0
- package/dist/src/platform/linux/desktop-project-registration.mjs +11 -0
- package/dist/src/platform/linux/network-info.mjs +11 -0
- package/dist/src/platform/linux/process.mjs +42 -0
- package/dist/src/platform/linux/project-locations.mjs +17 -0
- package/dist/src/platform/linux/resident-startup.mjs +52 -0
- package/dist/src/platform/linux/retained-runtime.mjs +76 -0
- package/dist/src/platform/linux/service-host.mjs +18 -0
- package/dist/src/platform/linux/system.mjs +49 -0
- package/dist/src/platform/linux/user-environment.mjs +7 -0
- package/dist/src/platform/macos/README.md +3 -3
- package/dist/src/platform/macos/codex-runtime.mjs +125 -125
- package/dist/src/platform/macos/credential-store.mjs +10 -10
- package/dist/src/platform/macos/desktop-host.mjs +82 -82
- package/dist/src/platform/macos/desktop-project-registration.mjs +11 -10
- package/dist/src/platform/macos/network-info.mjs +8 -28
- package/dist/src/platform/macos/project-locations.mjs +8 -8
- package/dist/src/platform/macos/resident-startup.mjs +84 -84
- package/dist/src/platform/macos/retained-runtime.mjs +127 -127
- package/dist/src/platform/macos/service-host.mjs +18 -18
- package/dist/src/platform/macos/system.mjs +29 -29
- package/dist/src/platform/macos/user-environment.mjs +7 -7
- package/dist/src/platform/native-package.mjs +58 -46
- package/dist/src/platform/network-info.mjs +3 -3
- package/dist/src/platform/path-identity.mjs +5 -5
- package/dist/src/platform/posix/network-candidates.mjs +23 -0
- package/dist/src/platform/posix/runtime-paths.mjs +25 -25
- package/dist/src/platform/project-locations.mjs +3 -3
- package/dist/src/platform/runtime-paths.mjs +8 -8
- package/dist/src/platform/select.mjs +5 -5
- package/dist/src/platform/service-host.mjs +3 -3
- package/dist/src/platform/user-environment.mjs +3 -3
- package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
- package/dist/src/platform/windows/activate-desktop.ps1 +48 -48
- package/dist/src/platform/windows/background-process.mjs +30 -30
- package/dist/src/platform/windows/codex-runtime.mjs +215 -215
- package/dist/src/platform/windows/credential-store.mjs +27 -27
- package/dist/src/platform/windows/credential-store.ps1 +49 -49
- package/dist/src/platform/windows/desktop-helper.mjs +179 -179
- package/dist/src/platform/windows/desktop-host.mjs +58 -58
- package/dist/src/platform/windows/desktop-info.ps1 +14 -14
- package/dist/src/platform/windows/desktop-project-registration.mjs +4 -4
- package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
- package/dist/src/platform/windows/desktop-shortcuts.ps1 +21 -21
- package/dist/src/platform/windows/dots-profile.mjs +49 -49
- package/dist/src/platform/windows/launch-worker.mjs +41 -41
- package/dist/src/platform/windows/network-info.mjs +34 -34
- package/dist/src/platform/windows/project-locations.mjs +16 -16
- package/dist/src/platform/windows/resident-start.js +20 -20
- package/dist/src/platform/windows/resident-start.ps1 +7 -7
- package/dist/src/platform/windows/resident-startup.ps1 +83 -83
- package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
- package/dist/src/platform/windows/runtime-paths.mjs +20 -20
- package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
- package/dist/src/platform/windows/service-host.mjs +31 -31
- package/dist/src/platform/windows/start-hidden-console.ps1 +49 -49
- package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
- package/dist/src/platform/windows/user-environment.mjs +50 -50
- package/dist/src/platform/windows/user-environment.ps1 +41 -41
- package/dist/src/project-archive.mjs +30 -0
- package/dist/src/project-create.mjs +121 -119
- package/dist/src/project-management.mjs +59 -69
- package/dist/src/project-remove.mjs +55 -0
- package/dist/src/project-update.mjs +56 -0
- package/dist/src/runtime-discovery.mjs +47 -47
- package/dist/src/self-relay/account-cleanup.mjs +30 -30
- package/dist/src/self-relay/account-connections.mjs +52 -52
- package/dist/src/self-relay/admin-cloud.mjs +101 -101
- package/dist/src/self-relay/admin-page.mjs +80 -80
- package/dist/src/self-relay/admin-server.mjs +74 -74
- package/dist/src/self-relay/admin-state.mjs +127 -127
- package/dist/src/self-relay/admin-style.mjs +14 -14
- package/dist/src/self-relay/android-releases.mjs +61 -61
- package/dist/src/self-relay/client.mjs +61 -61
- package/dist/src/self-relay/connector.mjs +439 -438
- package/dist/src/self-relay/debug-allowlist.mjs +33 -33
- package/dist/src/self-relay/demo.mjs +37 -37
- package/dist/src/self-relay/device-info.mjs +27 -0
- package/dist/src/self-relay/device-store.mjs +92 -84
- package/dist/src/self-relay/diagnostics.mjs +54 -54
- package/dist/src/self-relay/email-accounts.mjs +183 -183
- package/dist/src/self-relay/file-wire.mjs +13 -13
- package/dist/src/self-relay/lan-authorizations.mjs +71 -42
- package/dist/src/self-relay/lifecycle.mjs +264 -250
- package/dist/src/self-relay/long-pairing.mjs +40 -40
- package/dist/src/self-relay/mysql-state.mjs +118 -105
- package/dist/src/self-relay/p2p-probe.mjs +159 -159
- package/dist/src/self-relay/privacy-page.mjs +26 -26
- package/dist/src/self-relay/public-releases.mjs +52 -0
- package/dist/src/self-relay/rtc-file-bridge.mjs +41 -41
- package/dist/src/self-relay/server.mjs +1006 -932
- package/dist/src/self-relay/usage-daily.mjs +55 -55
- package/dist/src/self-relay/usage-meter.mjs +141 -141
- package/dist/src/self-relay/windows-route-helper.mjs +75 -75
- package/dist/src/self-relay/wire.mjs +36 -36
- package/dist/src/server.mjs +1861 -1778
- package/dist/src/service-control.mjs +82 -82
- package/dist/src/service-doctor.mjs +110 -110
- package/dist/src/service-health.mjs +33 -33
- package/dist/src/service-install.mjs +91 -91
- package/dist/src/service-lifecycle.mjs +138 -138
- package/dist/src/service-restart.mjs +81 -81
- package/dist/src/shared-app-server.mjs +615 -611
- package/dist/src/shared-catalog.mjs +132 -132
- package/dist/src/shared-recovery.mjs +146 -146
- package/dist/src/shared-thread-stream.mjs +164 -164
- package/dist/src/skill-install.mjs +51 -51
- package/dist/src/thread-title-generation.mjs +150 -150
- package/dist/src/turn-model-history.mjs +47 -47
- package/dist/src/usage-reset.mjs +17 -17
- package/dist/src/workstation-downloads.mjs +120 -120
- package/dist/tools/rtc-route-helper.ps1 +99 -99
- package/dist/tools/start-rtc-route-helper.ps1 +15 -15
- package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
- package/dist/web/vendor/markdown-it.umd.min.js +13 -13
- package/package.json +7 -6
- package/tools/postinstall.mjs +127 -127
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import mysql from 'mysql2/promise';
|
|
4
|
-
|
|
5
|
-
const path = process.env.RELAY_MYSQL_CONFIG_FILE;
|
|
6
|
-
const action = process.argv[2];
|
|
7
|
-
const email = (process.argv[3] || '').trim().toLowerCase();
|
|
8
|
-
if (!path || !['--grant', '--revoke', '--list'].includes(action) ||
|
|
9
|
-
(action !== '--list' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))) {
|
|
10
|
-
throw new Error('Use --grant EMAIL, --revoke EMAIL or --list with RELAY_MYSQL_CONFIG_FILE');
|
|
11
|
-
}
|
|
12
|
-
const db = await mysql.createConnection({ ...JSON.parse(fs.readFileSync(path, 'utf8')),
|
|
13
|
-
dateStrings: true, timezone: 'Z', multipleStatements: false });
|
|
14
|
-
try {
|
|
15
|
-
if (action === '--grant') await db.execute(`INSERT INTO relay_admin_emails (email,granted_at)
|
|
16
|
-
VALUES (?,UTC_TIMESTAMP(3)) ON DUPLICATE KEY UPDATE email=VALUES(email)`, [email]);
|
|
17
|
-
else if (action === '--revoke') await db.execute('DELETE FROM relay_admin_emails WHERE email=?', [email]);
|
|
18
|
-
const [rows] = await db.query('SELECT email FROM relay_admin_emails ORDER BY email');
|
|
19
|
-
console.log(JSON.stringify({ admins: rows.map(row => row.email) }));
|
|
20
|
-
} finally { await db.end(); }
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import mysql from 'mysql2/promise';
|
|
4
|
+
|
|
5
|
+
const path = process.env.RELAY_MYSQL_CONFIG_FILE;
|
|
6
|
+
const action = process.argv[2];
|
|
7
|
+
const email = (process.argv[3] || '').trim().toLowerCase();
|
|
8
|
+
if (!path || !['--grant', '--revoke', '--list'].includes(action) ||
|
|
9
|
+
(action !== '--list' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))) {
|
|
10
|
+
throw new Error('Use --grant EMAIL, --revoke EMAIL or --list with RELAY_MYSQL_CONFIG_FILE');
|
|
11
|
+
}
|
|
12
|
+
const db = await mysql.createConnection({ ...JSON.parse(fs.readFileSync(path, 'utf8')),
|
|
13
|
+
dateStrings: true, timezone: 'Z', multipleStatements: false });
|
|
14
|
+
try {
|
|
15
|
+
if (action === '--grant') await db.execute(`INSERT INTO relay_admin_emails (email,granted_at)
|
|
16
|
+
VALUES (?,UTC_TIMESTAMP(3)) ON DUPLICATE KEY UPDATE email=VALUES(email)`, [email]);
|
|
17
|
+
else if (action === '--revoke') await db.execute('DELETE FROM relay_admin_emails WHERE email=?', [email]);
|
|
18
|
+
const [rows] = await db.query('SELECT email FROM relay_admin_emails ORDER BY email');
|
|
19
|
+
console.log(JSON.stringify({ admins: rows.map(row => row.email) }));
|
|
20
|
+
} finally { await db.end(); }
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import mysql from 'mysql2/promise';
|
|
6
|
-
import { relaySchemaVersions } from '../database/versions.mjs';
|
|
7
|
-
import { deviceStore } from '../src/self-relay/device-store.mjs';
|
|
8
|
-
import { relayAdminState } from '../src/self-relay/admin-state.mjs';
|
|
9
|
-
|
|
10
|
-
const command = process.argv[2];
|
|
11
|
-
if (!['--schema', '--import', '--check'].includes(command) || !process.env.RELAY_MYSQL_CONFIG_FILE) {
|
|
12
|
-
throw new Error('Use --schema, --import or --check with RELAY_MYSQL_CONFIG_FILE');
|
|
13
|
-
}
|
|
14
|
-
const config = JSON.parse(fs.readFileSync(process.env.RELAY_MYSQL_CONFIG_FILE, 'utf8'));
|
|
15
|
-
const db = await mysql.createConnection({ ...config, dateStrings: true, timezone: 'Z', multipleStatements: false });
|
|
16
|
-
const sqlTime = value => value.replace('T', ' ').replace(/Z$/, '');
|
|
17
|
-
const migrations = relaySchemaVersions;
|
|
18
|
-
try {
|
|
19
|
-
if (command === '--schema') {
|
|
20
|
-
const [existing] = await db.query("SHOW TABLES LIKE 'schema_migrations'");
|
|
21
|
-
const [applied] = existing.length ? await db.query('SELECT version, sha256 FROM schema_migrations') : [[]];
|
|
22
|
-
const known = new Map(applied.map(row => [row.version, row.sha256]));
|
|
23
|
-
if (known.size !== applied.length || [...known.keys()].some(version => !migrations.includes(version))) throw new Error('Unexpected schema version');
|
|
24
|
-
for (const version of migrations) {
|
|
25
|
-
const source = fs.readFileSync(fileURLToPath(new URL(`../database/${version}.sql`, import.meta.url)), 'utf8');
|
|
26
|
-
const sha256 = createHash('sha256').update(source).digest('hex');
|
|
27
|
-
if (known.has(version)) {
|
|
28
|
-
if (known.get(version) !== sha256) throw new Error(`Migration changed: ${version}`);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (version !== migrations[0] && !known.has(migrations[migrations.indexOf(version) - 1])) throw new Error('Previous migration missing');
|
|
32
|
-
const statements = source.split('\n').filter(line => !line.trimStart().startsWith('--')).join('\n');
|
|
33
|
-
for (const statement of statements.split(';').map(item => item.trim()).filter(Boolean)) await db.query(statement);
|
|
34
|
-
await db.execute('INSERT INTO schema_migrations (version, sha256) VALUES (?,?)', [version, sha256]);
|
|
35
|
-
known.set(version, sha256);
|
|
36
|
-
console.log(JSON.stringify({ schema: version, sha256 }));
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
const [versions] = await db.query('SELECT version FROM schema_migrations');
|
|
40
|
-
if (!versions.some(row => row.version === '001_relay_core') || versions.some(row => !migrations.includes(row.version))) throw new Error('Unexpected schema version');
|
|
41
|
-
if (command === '--check') {
|
|
42
|
-
const names = ['computers', 'mobile_authorizations', 'official_computers', 'announcements', 'relay_settings', 'users', 'user_login_identities'];
|
|
43
|
-
if (versions.some(row => row.version === '002_email_accounts')) names.push('email_login_challenges', 'user_sessions', 'email_send_limits');
|
|
44
|
-
if (versions.some(row => row.version === '003_relay_usage')) names.push('relay_admin_emails', 'relay_usage_settings', 'relay_usage_totals', 'relay_usage_computer_totals', 'relay_usage_entitlements', 'relay_usage_budgets', 'relay_usage_computer_budgets', 'relay_usage_sessions');
|
|
45
|
-
if (versions.some(row => row.version === '004_relay_usage_actions')) names.push('relay_usage_actions');
|
|
46
|
-
if (versions.some(row => row.version === '006_relay_diagnostics')) names.push('relay_diagnostics');
|
|
47
|
-
if (versions.some(row => row.version === '007_relay_usage_daily')) names.push('relay_usage_user_days', 'relay_usage_computer_days');
|
|
48
|
-
const counts = {};
|
|
49
|
-
for (const name of names) { const [rows] = await db.query(`SELECT COUNT(*) AS count FROM ${name}`); counts[name] = rows[0].count; }
|
|
50
|
-
if (process.env.RELAY_STATE_FILE && process.env.RELAY_ADMIN_STATE_FILE) {
|
|
51
|
-
const devices = deviceStore(process.env.RELAY_STATE_FILE).entries();
|
|
52
|
-
const admin = relayAdminState(process.env.RELAY_ADMIN_STATE_FILE, 8).read();
|
|
53
|
-
const expected = { computers: devices.length,
|
|
54
|
-
mobile_authorizations: devices.reduce((sum, item) => sum + item.clients.length, 0),
|
|
55
|
-
official_computers: devices.filter(item => item.officialComputer).length,
|
|
56
|
-
announcements: admin.announcements.length, relay_settings: 1 };
|
|
57
|
-
if (Object.keys(expected).some(name => counts[name] !== expected[name])) throw new Error('Imported row counts differ from JSON');
|
|
58
|
-
const [saved] = await db.query('SELECT id,host_hash,status,revision FROM computers');
|
|
59
|
-
const original = new Map(devices.map(item => [item.id, item]));
|
|
60
|
-
for (const row of saved) {
|
|
61
|
-
const item = original.get(row.id);
|
|
62
|
-
if (!item || item.hostHash !== row.host_hash || item.status !== row.status || item.revision !== Number(row.revision)) {
|
|
63
|
-
throw new Error('Imported computer identity differs from JSON');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const [authorized] = await db.query('SELECT computer_id,client_id,credential_hash FROM mobile_authorizations');
|
|
67
|
-
for (const row of authorized) {
|
|
68
|
-
const item = original.get(row.computer_id)?.clients.find(client => client.id === row.client_id);
|
|
69
|
-
if (!item || item.hash !== row.credential_hash) throw new Error('Imported mobile authorization differs from JSON');
|
|
70
|
-
}
|
|
71
|
-
const [settings] = await db.query('SELECT max_relay_sessions FROM relay_settings WHERE id=1');
|
|
72
|
-
if (settings[0]?.max_relay_sessions !== admin.maxRelaySessions) throw new Error('Imported relay setting differs from JSON');
|
|
73
|
-
console.log(JSON.stringify({ verified: true, counts }));
|
|
74
|
-
} else console.log(JSON.stringify(counts));
|
|
75
|
-
} else {
|
|
76
|
-
const stateFile = process.env.RELAY_STATE_FILE, adminFile = process.env.RELAY_ADMIN_STATE_FILE;
|
|
77
|
-
if (!stateFile || !adminFile) throw new Error('RELAY_STATE_FILE and RELAY_ADMIN_STATE_FILE required for import');
|
|
78
|
-
const devices = deviceStore(stateFile).entries();
|
|
79
|
-
const admin = relayAdminState(adminFile, 8).read();
|
|
80
|
-
const [existing] = await db.query('SELECT (SELECT COUNT(*) FROM computers) AS computers, (SELECT COUNT(*) FROM relay_settings) AS settings');
|
|
81
|
-
if (existing[0].computers || existing[0].settings) throw new Error('Import target is not empty');
|
|
82
|
-
await db.beginTransaction();
|
|
83
|
-
try {
|
|
84
|
-
for (const item of devices) {
|
|
85
|
-
await db.execute('INSERT INTO computers (id,host_hash,status,revision,created_at,updated_at) VALUES (?,?,?,?,?,?)',
|
|
86
|
-
[item.id, item.hostHash, item.status, item.revision, sqlTime(item.createdAt), sqlTime(item.updatedAt)]);
|
|
87
|
-
for (const client of item.clients) await db.execute(
|
|
88
|
-
'INSERT INTO mobile_authorizations (computer_id,client_id,credential_hash,created_at,updated_at) VALUES (?,?,?,?,?)',
|
|
89
|
-
[item.id, client.id, client.hash, sqlTime(client.createdAt), sqlTime(client.updatedAt)]);
|
|
90
|
-
if (item.officialComputer) {
|
|
91
|
-
const official = item.officialComputer;
|
|
92
|
-
await db.execute('INSERT INTO official_computers (computer_id,environment_id,name,hostname,updated_at) VALUES (?,?,?,?,?)',
|
|
93
|
-
[item.id, official.environmentId, official.name, official.hostname, sqlTime(official.updatedAt)]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
await db.execute('INSERT INTO relay_settings (id,max_relay_sessions,updated_at) VALUES (1,?,UTC_TIMESTAMP(3))', [admin.maxRelaySessions]);
|
|
97
|
-
for (const item of admin.announcements) await db.execute(
|
|
98
|
-
'INSERT INTO announcements (id,title,message,status,created_at,updated_at,published_at) VALUES (?,?,?,?,?,?,?)',
|
|
99
|
-
[item.id, item.title, item.message, item.status, sqlTime(item.createdAt), sqlTime(item.updatedAt),
|
|
100
|
-
item.publishedAt ? sqlTime(item.publishedAt) : null]);
|
|
101
|
-
await db.commit();
|
|
102
|
-
} catch (error) { await db.rollback(); throw error; }
|
|
103
|
-
console.log(JSON.stringify({ imported: true, computers: devices.length,
|
|
104
|
-
mobileAuthorizations: devices.reduce((sum, item) => sum + item.clients.length, 0),
|
|
105
|
-
officialComputers: devices.filter(item => item.officialComputer).length,
|
|
106
|
-
announcements: admin.announcements.length }));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} finally { await db.end(); }
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import mysql from 'mysql2/promise';
|
|
6
|
+
import { relaySchemaVersions } from '../database/versions.mjs';
|
|
7
|
+
import { deviceStore } from '../src/self-relay/device-store.mjs';
|
|
8
|
+
import { relayAdminState } from '../src/self-relay/admin-state.mjs';
|
|
9
|
+
|
|
10
|
+
const command = process.argv[2];
|
|
11
|
+
if (!['--schema', '--import', '--check'].includes(command) || !process.env.RELAY_MYSQL_CONFIG_FILE) {
|
|
12
|
+
throw new Error('Use --schema, --import or --check with RELAY_MYSQL_CONFIG_FILE');
|
|
13
|
+
}
|
|
14
|
+
const config = JSON.parse(fs.readFileSync(process.env.RELAY_MYSQL_CONFIG_FILE, 'utf8'));
|
|
15
|
+
const db = await mysql.createConnection({ ...config, dateStrings: true, timezone: 'Z', multipleStatements: false });
|
|
16
|
+
const sqlTime = value => value.replace('T', ' ').replace(/Z$/, '');
|
|
17
|
+
const migrations = relaySchemaVersions;
|
|
18
|
+
try {
|
|
19
|
+
if (command === '--schema') {
|
|
20
|
+
const [existing] = await db.query("SHOW TABLES LIKE 'schema_migrations'");
|
|
21
|
+
const [applied] = existing.length ? await db.query('SELECT version, sha256 FROM schema_migrations') : [[]];
|
|
22
|
+
const known = new Map(applied.map(row => [row.version, row.sha256]));
|
|
23
|
+
if (known.size !== applied.length || [...known.keys()].some(version => !migrations.includes(version))) throw new Error('Unexpected schema version');
|
|
24
|
+
for (const version of migrations) {
|
|
25
|
+
const source = fs.readFileSync(fileURLToPath(new URL(`../database/${version}.sql`, import.meta.url)), 'utf8');
|
|
26
|
+
const sha256 = createHash('sha256').update(source).digest('hex');
|
|
27
|
+
if (known.has(version)) {
|
|
28
|
+
if (known.get(version) !== sha256) throw new Error(`Migration changed: ${version}`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (version !== migrations[0] && !known.has(migrations[migrations.indexOf(version) - 1])) throw new Error('Previous migration missing');
|
|
32
|
+
const statements = source.split('\n').filter(line => !line.trimStart().startsWith('--')).join('\n');
|
|
33
|
+
for (const statement of statements.split(';').map(item => item.trim()).filter(Boolean)) await db.query(statement);
|
|
34
|
+
await db.execute('INSERT INTO schema_migrations (version, sha256) VALUES (?,?)', [version, sha256]);
|
|
35
|
+
known.set(version, sha256);
|
|
36
|
+
console.log(JSON.stringify({ schema: version, sha256 }));
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
const [versions] = await db.query('SELECT version FROM schema_migrations');
|
|
40
|
+
if (!versions.some(row => row.version === '001_relay_core') || versions.some(row => !migrations.includes(row.version))) throw new Error('Unexpected schema version');
|
|
41
|
+
if (command === '--check') {
|
|
42
|
+
const names = ['computers', 'mobile_authorizations', 'official_computers', 'announcements', 'relay_settings', 'users', 'user_login_identities'];
|
|
43
|
+
if (versions.some(row => row.version === '002_email_accounts')) names.push('email_login_challenges', 'user_sessions', 'email_send_limits');
|
|
44
|
+
if (versions.some(row => row.version === '003_relay_usage')) names.push('relay_admin_emails', 'relay_usage_settings', 'relay_usage_totals', 'relay_usage_computer_totals', 'relay_usage_entitlements', 'relay_usage_budgets', 'relay_usage_computer_budgets', 'relay_usage_sessions');
|
|
45
|
+
if (versions.some(row => row.version === '004_relay_usage_actions')) names.push('relay_usage_actions');
|
|
46
|
+
if (versions.some(row => row.version === '006_relay_diagnostics')) names.push('relay_diagnostics');
|
|
47
|
+
if (versions.some(row => row.version === '007_relay_usage_daily')) names.push('relay_usage_user_days', 'relay_usage_computer_days');
|
|
48
|
+
const counts = {};
|
|
49
|
+
for (const name of names) { const [rows] = await db.query(`SELECT COUNT(*) AS count FROM ${name}`); counts[name] = rows[0].count; }
|
|
50
|
+
if (process.env.RELAY_STATE_FILE && process.env.RELAY_ADMIN_STATE_FILE) {
|
|
51
|
+
const devices = deviceStore(process.env.RELAY_STATE_FILE).entries();
|
|
52
|
+
const admin = relayAdminState(process.env.RELAY_ADMIN_STATE_FILE, 8).read();
|
|
53
|
+
const expected = { computers: devices.length,
|
|
54
|
+
mobile_authorizations: devices.reduce((sum, item) => sum + item.clients.length, 0),
|
|
55
|
+
official_computers: devices.filter(item => item.officialComputer).length,
|
|
56
|
+
announcements: admin.announcements.length, relay_settings: 1 };
|
|
57
|
+
if (Object.keys(expected).some(name => counts[name] !== expected[name])) throw new Error('Imported row counts differ from JSON');
|
|
58
|
+
const [saved] = await db.query('SELECT id,host_hash,status,revision FROM computers');
|
|
59
|
+
const original = new Map(devices.map(item => [item.id, item]));
|
|
60
|
+
for (const row of saved) {
|
|
61
|
+
const item = original.get(row.id);
|
|
62
|
+
if (!item || item.hostHash !== row.host_hash || item.status !== row.status || item.revision !== Number(row.revision)) {
|
|
63
|
+
throw new Error('Imported computer identity differs from JSON');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const [authorized] = await db.query('SELECT computer_id,client_id,credential_hash FROM mobile_authorizations');
|
|
67
|
+
for (const row of authorized) {
|
|
68
|
+
const item = original.get(row.computer_id)?.clients.find(client => client.id === row.client_id);
|
|
69
|
+
if (!item || item.hash !== row.credential_hash) throw new Error('Imported mobile authorization differs from JSON');
|
|
70
|
+
}
|
|
71
|
+
const [settings] = await db.query('SELECT max_relay_sessions FROM relay_settings WHERE id=1');
|
|
72
|
+
if (settings[0]?.max_relay_sessions !== admin.maxRelaySessions) throw new Error('Imported relay setting differs from JSON');
|
|
73
|
+
console.log(JSON.stringify({ verified: true, counts }));
|
|
74
|
+
} else console.log(JSON.stringify(counts));
|
|
75
|
+
} else {
|
|
76
|
+
const stateFile = process.env.RELAY_STATE_FILE, adminFile = process.env.RELAY_ADMIN_STATE_FILE;
|
|
77
|
+
if (!stateFile || !adminFile) throw new Error('RELAY_STATE_FILE and RELAY_ADMIN_STATE_FILE required for import');
|
|
78
|
+
const devices = deviceStore(stateFile).entries();
|
|
79
|
+
const admin = relayAdminState(adminFile, 8).read();
|
|
80
|
+
const [existing] = await db.query('SELECT (SELECT COUNT(*) FROM computers) AS computers, (SELECT COUNT(*) FROM relay_settings) AS settings');
|
|
81
|
+
if (existing[0].computers || existing[0].settings) throw new Error('Import target is not empty');
|
|
82
|
+
await db.beginTransaction();
|
|
83
|
+
try {
|
|
84
|
+
for (const item of devices) {
|
|
85
|
+
await db.execute('INSERT INTO computers (id,host_hash,status,revision,created_at,updated_at) VALUES (?,?,?,?,?,?)',
|
|
86
|
+
[item.id, item.hostHash, item.status, item.revision, sqlTime(item.createdAt), sqlTime(item.updatedAt)]);
|
|
87
|
+
for (const client of item.clients) await db.execute(
|
|
88
|
+
'INSERT INTO mobile_authorizations (computer_id,client_id,credential_hash,created_at,updated_at) VALUES (?,?,?,?,?)',
|
|
89
|
+
[item.id, client.id, client.hash, sqlTime(client.createdAt), sqlTime(client.updatedAt)]);
|
|
90
|
+
if (item.officialComputer) {
|
|
91
|
+
const official = item.officialComputer;
|
|
92
|
+
await db.execute('INSERT INTO official_computers (computer_id,environment_id,name,hostname,updated_at) VALUES (?,?,?,?,?)',
|
|
93
|
+
[item.id, official.environmentId, official.name, official.hostname, sqlTime(official.updatedAt)]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await db.execute('INSERT INTO relay_settings (id,max_relay_sessions,updated_at) VALUES (1,?,UTC_TIMESTAMP(3))', [admin.maxRelaySessions]);
|
|
97
|
+
for (const item of admin.announcements) await db.execute(
|
|
98
|
+
'INSERT INTO announcements (id,title,message,status,created_at,updated_at,published_at) VALUES (?,?,?,?,?,?,?)',
|
|
99
|
+
[item.id, item.title, item.message, item.status, sqlTime(item.createdAt), sqlTime(item.updatedAt),
|
|
100
|
+
item.publishedAt ? sqlTime(item.publishedAt) : null]);
|
|
101
|
+
await db.commit();
|
|
102
|
+
} catch (error) { await db.rollback(); throw error; }
|
|
103
|
+
console.log(JSON.stringify({ imported: true, computers: devices.length,
|
|
104
|
+
mobileAuthorizations: devices.reduce((sum, item) => sum + item.clients.length, 0),
|
|
105
|
+
officialComputers: devices.filter(item => item.officialComputer).length,
|
|
106
|
+
announcements: admin.announcements.length }));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} finally { await db.end(); }
|
|
@@ -1,58 +1,63 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { createHash } from 'node:crypto';
|
|
5
|
-
import { androidReleaseStorage } from '../relay-admin/android-release-storage.mjs';
|
|
6
|
-
import { readAndroidCatalog } from '../src/self-relay/android-releases.mjs';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { androidReleaseStorage } from '../relay-admin/android-release-storage.mjs';
|
|
6
|
+
import { readAndroidCatalog } from '../src/self-relay/android-releases.mjs';
|
|
7
|
+
import { readPublicManifest, updatePublicAndroid } from '../src/self-relay/public-releases.mjs';
|
|
8
|
+
|
|
9
|
+
// This administrative command runs only on the deployment host; no keys cross SSH.
|
|
10
|
+
const [apkFile, metadataFile, mode] = process.argv.slice(2);
|
|
11
|
+
if (mode && mode !== '--existing-object') throw new Error('Invalid publication mode');
|
|
12
|
+
if (!apkFile || !metadataFile) throw new Error('Usage: publish-android-release.mjs APK METADATA');
|
|
13
|
+
const storage = androidReleaseStorage('/etc/codex-relay/android-releases.json', '/etc/codex-relay/tencent-monitor.json');
|
|
14
|
+
const metadata = JSON.parse(fs.readFileSync(metadataFile, 'utf8'));
|
|
15
|
+
if (metadata.packageName !== 'com.walkhi.codexremote' || !/^[a-f0-9]{64}$/.test(metadata.certificateSha256)) throw new Error('Invalid APK identity');
|
|
16
|
+
const { certificateSha256: expectedCertificate } = JSON.parse(fs.readFileSync('/etc/codex-relay/android-releases.json', 'utf8'));
|
|
17
|
+
if (!/^[a-f0-9]{64}$/.test(expectedCertificate) || metadata.certificateSha256 !== expectedCertificate) throw new Error('APK signing certificate does not match release configuration');
|
|
18
|
+
const bytes = fs.readFileSync(apkFile), sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
19
|
+
if (sha256 !== metadata.sha256 || bytes.length !== metadata.size) throw new Error('Uploaded APK integrity mismatch');
|
|
20
|
+
const { versionCode, versionName, size, notes, certificateSha256 } = metadata;
|
|
21
|
+
const release = { versionCode, versionName, size, sha256, notes, certificateSha256,
|
|
22
|
+
objectKey: `code-relax/android/${versionCode}/Code-Relax-${sha256.slice(0, 16)}.apk` };
|
|
23
|
+
const catalogFile = storage.catalogFile, temporary = catalogFile + '.new', lock = catalogFile + '.lock';
|
|
24
|
+
const lockHandle = fs.openSync(lock, 'wx', 0o600);
|
|
25
|
+
try {
|
|
26
|
+
readPublicManifest();
|
|
27
|
+
const catalog = fs.existsSync(catalogFile) ? readAndroidCatalog(catalogFile) : { releases: [] };
|
|
28
|
+
const previous = catalog.releases.find(item => item.versionCode === versionCode);
|
|
29
|
+
if (previous && previous.sha256 !== sha256) throw new Error('A different APK already uses this versionCode');
|
|
30
|
+
if (catalog.latestVersionCode > versionCode) throw new Error('Refusing to publish an older version as latest');
|
|
31
|
+
const next = { latestVersionCode: versionCode, releases: [...catalog.releases.filter(item => item.versionCode !== versionCode), release] };
|
|
32
|
+
fs.writeFileSync(temporary, JSON.stringify(next, null, 2) + '\n', { mode: 0o640 });
|
|
33
|
+
readAndroidCatalog(temporary);
|
|
34
|
+
if (!previous && mode !== '--existing-object') {
|
|
35
|
+
await new Promise((resolve, reject) => storage.cos.putObject({ ...storage.object(release), Body: bytes,
|
|
36
|
+
ContentLength: bytes.length, ContentType: 'application/vnd.android.package-archive',
|
|
37
|
+
ContentDisposition: `attachment; filename="Code-Relax-${versionName}.apk"`
|
|
38
|
+
}, (error, value) => error ? reject(error) : resolve(value)));
|
|
39
|
+
}
|
|
40
|
+
// Validate the exact signed GET that website and App use, before switching latest.
|
|
41
|
+
const ticket = await storage.signDownload(release);
|
|
42
|
+
const response = await fetch(ticket.url, { signal: AbortSignal.timeout(120000) });
|
|
43
|
+
if (!response.ok) throw new Error(`Signed download failed: HTTP ${response.status}`);
|
|
44
|
+
const downloaded = Buffer.from(await response.arrayBuffer());
|
|
45
|
+
if (downloaded.length !== size || createHash('sha256').update(downloaded).digest('hex') !== sha256) throw new Error('Stored APK integrity mismatch');
|
|
46
|
+
const unsigned = new URL(ticket.url); unsigned.search = '';
|
|
47
|
+
const denied = await fetch(unsigned, { method: 'HEAD', signal: AbortSignal.timeout(15000) });
|
|
48
|
+
if (denied.status !== 403) throw new Error(`Private object check failed: HTTP ${denied.status}`);
|
|
49
|
+
const owner = fs.statSync(path.dirname(catalogFile));
|
|
50
|
+
fs.chownSync(temporary, owner.uid, owner.gid);
|
|
51
|
+
fs.renameSync(temporary, catalogFile);
|
|
52
|
+
updatePublicAndroid(release);
|
|
53
|
+
console.log(JSON.stringify({ published: true, versionCode, versionName, size, sha256, unsignedStatus: denied.status,
|
|
54
|
+
entry: 'https://www.coderelax.cn/code-relax/android' }));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// COS errors can carry signed request details. Keep CLI output credential-free.
|
|
57
|
+
console.error('Android publication failed:', error?.code || (error?.name === 'Error' ? error.message : 'storage-request-failed'));
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
} finally {
|
|
60
|
+
fs.closeSync(lockHandle);
|
|
61
|
+
fs.unlinkSync(lock);
|
|
62
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
63
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { androidReleaseStorage } from '../relay-admin/android-release-storage.mjs';
|
|
6
|
+
import { readHarmonyConfig, hapName, validateHarmonyMetadata, checkHarmonyVersion,
|
|
7
|
+
verifyHarmony, activateHarmony } from '../relay-admin/harmony-release.mjs';
|
|
8
|
+
|
|
9
|
+
// Local PowerShell releases use the same verifier, COS objects and activation as GitHub CD.
|
|
10
|
+
const directory = path.resolve(process.argv[2] || '');
|
|
11
|
+
if (!process.argv[2]) throw Error('Usage: publish-harmony-release.mjs DIRECTORY');
|
|
12
|
+
let stage = 'metadata';
|
|
13
|
+
try {
|
|
14
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(directory, 'manifest.json5'), 'utf8')).app;
|
|
15
|
+
const config = readHarmonyConfig();
|
|
16
|
+
const metadata = { packageName: manifest.bundleName, versionCode: manifest.versionCode,
|
|
17
|
+
versionName: manifest.versionName, certificateSha256: config.certificateSha256 };
|
|
18
|
+
if (!Number.isSafeInteger(metadata.versionCode) || metadata.versionCode <= 0
|
|
19
|
+
|| !/^\d+\.\d+\.\d+$/.test(metadata.versionName)) throw Error();
|
|
20
|
+
metadata.files = [hapName(metadata), 'manifest.json5', 'icon.png'].map(name => {
|
|
21
|
+
const bytes = fs.readFileSync(path.join(directory, name));
|
|
22
|
+
return { name, size: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
23
|
+
contentMd5: createHash('md5').update(bytes).digest('base64') };
|
|
24
|
+
});
|
|
25
|
+
Object.assign(metadata, { size: metadata.files[0].size, sha256: metadata.files[0].sha256,
|
|
26
|
+
contentMd5: metadata.files[0].contentMd5 });
|
|
27
|
+
validateHarmonyMetadata(metadata, config);
|
|
28
|
+
checkHarmonyVersion(metadata);
|
|
29
|
+
stage = 'signature';
|
|
30
|
+
await verifyHarmony(directory, metadata, config);
|
|
31
|
+
const storage = androidReleaseStorage('/etc/codex-relay/android-releases.json', '/etc/codex-relay/tencent-monitor.json');
|
|
32
|
+
const keys = metadata.files.map(f => `code-relax/harmony/${metadata.versionCode}/${f.name}`);
|
|
33
|
+
stage = 'upload';
|
|
34
|
+
for (const [i, file] of metadata.files.entries()) {
|
|
35
|
+
await new Promise((resolve, reject) => storage.cos.putObject({ ...storage.object({ objectKey: keys[i] }),
|
|
36
|
+
Body: fs.createReadStream(path.join(directory, file.name)), ContentLength: file.size,
|
|
37
|
+
ContentMD5: file.contentMd5, ContentType: i === 1 ? 'application/json' : i === 2 ? 'image/png' : 'application/octet-stream',
|
|
38
|
+
Headers: { 'x-cos-forbid-overwrite': 'true' }
|
|
39
|
+
}, (error, result) => error ? reject(error) : resolve(result)));
|
|
40
|
+
}
|
|
41
|
+
stage = 'publication';
|
|
42
|
+
console.log(JSON.stringify(await activateHarmony(metadata, storage, keys)));
|
|
43
|
+
} catch {
|
|
44
|
+
console.error(`Harmony publication failed at ${stage}; inspect objects and current version before retrying.`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
}
|