@mmmbuto/qwen-code-termux 0.6.3-termux → 0.6.401

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.
@@ -0,0 +1,411 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license
5
+ * Copyright 2025 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+
9
+ import { execSync } from 'node:child_process';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { readFileSync } from 'node:fs';
12
+ import semver from 'semver';
13
+
14
+ function readJson(filePath) {
15
+ return JSON.parse(readFileSync(filePath, 'utf-8'));
16
+ }
17
+
18
+ function getArgs() {
19
+ const args = {};
20
+ process.argv.slice(2).forEach((arg) => {
21
+ if (arg.startsWith('--')) {
22
+ const [key, value] = arg.substring(2).split('=');
23
+ args[key] = value === undefined ? true : value;
24
+ }
25
+ });
26
+ return args;
27
+ }
28
+
29
+ function getVersionFromNPM(distTag) {
30
+ const command = `npm view @qwen-code/qwen-code version --tag=${distTag}`;
31
+ try {
32
+ return execSync(command).toString().trim();
33
+ } catch (error) {
34
+ console.error(
35
+ `Failed to get NPM version for dist-tag "${distTag}": ${error.message}`,
36
+ );
37
+ return '';
38
+ }
39
+ }
40
+
41
+ function getAllVersionsFromNPM() {
42
+ const command = `npm view @qwen-code/qwen-code versions --json`;
43
+ try {
44
+ const versionsJson = execSync(command).toString().trim();
45
+ return JSON.parse(versionsJson);
46
+ } catch (error) {
47
+ console.error(`Failed to get all NPM versions: ${error.message}`);
48
+ return [];
49
+ }
50
+ }
51
+
52
+ function isVersionDeprecated(version) {
53
+ const command = `npm view @qwen-code/qwen-code@${version} deprecated`;
54
+ try {
55
+ const output = execSync(command).toString().trim();
56
+ return output.length > 0;
57
+ } catch (error) {
58
+ // This command shouldn't fail for existing versions, but as a safeguard:
59
+ console.error(
60
+ `Failed to check deprecation status for ${version}: ${error.message}`,
61
+ );
62
+ return false; // Assume not deprecated on error to avoid breaking the release.
63
+ }
64
+ }
65
+
66
+ function detectRollbackAndGetBaseline(npmDistTag) {
67
+ // Get the current dist-tag version
68
+ const distTagVersion = getVersionFromNPM(npmDistTag);
69
+ if (!distTagVersion) return { baseline: '', isRollback: false };
70
+
71
+ // Get all published versions
72
+ const allVersions = getAllVersionsFromNPM();
73
+ if (allVersions.length === 0)
74
+ return { baseline: distTagVersion, isRollback: false };
75
+
76
+ // Filter versions by type to match the dist-tag
77
+ let matchingVersions;
78
+ if (npmDistTag === 'latest') {
79
+ // Stable versions: no prerelease identifiers
80
+ matchingVersions = allVersions.filter(
81
+ (v) => semver.valid(v) && !semver.prerelease(v),
82
+ );
83
+ } else if (npmDistTag === 'preview') {
84
+ // Preview versions: contain -preview
85
+ matchingVersions = allVersions.filter(
86
+ (v) => semver.valid(v) && v.includes('-preview'),
87
+ );
88
+ } else if (npmDistTag === 'nightly') {
89
+ // Nightly versions: contain -nightly
90
+ matchingVersions = allVersions.filter(
91
+ (v) => semver.valid(v) && v.includes('-nightly'),
92
+ );
93
+ } else {
94
+ // For other dist-tags, just use the dist-tag version
95
+ return { baseline: distTagVersion, isRollback: false };
96
+ }
97
+
98
+ if (matchingVersions.length === 0)
99
+ return { baseline: distTagVersion, isRollback: false };
100
+
101
+ // Sort by semver to get a list from highest to lowest
102
+ matchingVersions.sort((a, b) => semver.rcompare(a, b));
103
+
104
+ // Find the highest non-deprecated version
105
+ let highestExistingVersion = '';
106
+ for (const version of matchingVersions) {
107
+ if (!isVersionDeprecated(version)) {
108
+ highestExistingVersion = version;
109
+ break; // Found the one we want
110
+ } else {
111
+ console.error(`Ignoring deprecated version: ${version}`);
112
+ }
113
+ }
114
+
115
+ // If all matching versions were deprecated, fall back to the dist-tag version
116
+ if (!highestExistingVersion) {
117
+ highestExistingVersion = distTagVersion;
118
+ }
119
+
120
+ // Check if we're in a rollback scenario
121
+ const isRollback = semver.gt(highestExistingVersion, distTagVersion);
122
+
123
+ return {
124
+ baseline: isRollback ? highestExistingVersion : distTagVersion,
125
+ isRollback,
126
+ distTagVersion,
127
+ highestExistingVersion,
128
+ };
129
+ }
130
+
131
+ function doesVersionExist(version) {
132
+ // Check NPM
133
+ try {
134
+ const command = `npm view @qwen-code/qwen-code@${version} version 2>/dev/null`;
135
+ const output = execSync(command).toString().trim();
136
+ if (output === version) {
137
+ console.error(`Version ${version} already exists on NPM.`);
138
+ return true;
139
+ }
140
+ } catch (_error) {
141
+ // This is expected if the version doesn't exist.
142
+ }
143
+
144
+ // Check Git tags
145
+ try {
146
+ const command = `git tag -l 'v${version}'`;
147
+ const tagOutput = execSync(command).toString().trim();
148
+ if (tagOutput === `v${version}`) {
149
+ console.error(`Git tag v${version} already exists.`);
150
+ return true;
151
+ }
152
+ } catch (error) {
153
+ console.error(`Failed to check git tags for conflicts: ${error.message}`);
154
+ }
155
+
156
+ // Check GitHub releases
157
+ try {
158
+ const command = `gh release view "v${version}" --json tagName --jq .tagName 2>/dev/null`;
159
+ const output = execSync(command).toString().trim();
160
+ if (output === `v${version}`) {
161
+ console.error(`GitHub release v${version} already exists.`);
162
+ return true;
163
+ }
164
+ } catch (error) {
165
+ const isExpectedNotFound =
166
+ error.message.includes('release not found') ||
167
+ error.message.includes('Not Found') ||
168
+ error.message.includes('not found') ||
169
+ error.status === 1;
170
+ if (!isExpectedNotFound) {
171
+ console.error(
172
+ `Failed to check GitHub releases for conflicts: ${error.message}`,
173
+ );
174
+ }
175
+ }
176
+
177
+ return false;
178
+ }
179
+
180
+ function getAndVerifyTags(npmDistTag, _gitTagPattern) {
181
+ // Detect rollback scenarios and get the correct baseline
182
+ const rollbackInfo = detectRollbackAndGetBaseline(npmDistTag);
183
+ const baselineVersion = rollbackInfo.baseline;
184
+
185
+ if (!baselineVersion) {
186
+ throw new Error(`Unable to determine baseline version for ${npmDistTag}`);
187
+ }
188
+
189
+ if (rollbackInfo.isRollback) {
190
+ // Rollback scenario: warn about the rollback but don't fail
191
+ console.error(
192
+ `Rollback detected! NPM ${npmDistTag} tag is ${rollbackInfo.distTagVersion}, but using ${baselineVersion} as baseline for next version calculation (highest existing version).`,
193
+ );
194
+ }
195
+
196
+ // Not verifying against git tags or GitHub releases as per user request.
197
+
198
+ return {
199
+ latestVersion: baselineVersion,
200
+ latestTag: `v${baselineVersion}`,
201
+ };
202
+ }
203
+
204
+ function getLatestStableReleaseTag() {
205
+ try {
206
+ const { latestTag } = getAndVerifyTags('latest', 'v[0-9].[0-9].[0-9]');
207
+ return latestTag;
208
+ } catch (error) {
209
+ console.error(
210
+ `Failed to determine latest stable release tag: ${error.message}`,
211
+ );
212
+ return '';
213
+ }
214
+ }
215
+
216
+ function promoteNightlyVersion() {
217
+ const { latestVersion } = getAndVerifyTags('nightly', 'v*-nightly*');
218
+ const baseVersion = latestVersion.split('-')[0];
219
+ const versionParts = baseVersion.split('.');
220
+ const major = versionParts[0];
221
+ const minor = versionParts[1] ? parseInt(versionParts[1]) : 0;
222
+ const nextMinor = minor + 1;
223
+ const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
224
+ const gitShortHash = execSync('git rev-parse --short HEAD').toString().trim();
225
+ return {
226
+ releaseVersion: `${major}.${nextMinor}.0-nightly.${date}.${gitShortHash}`,
227
+ npmTag: 'nightly',
228
+ };
229
+ }
230
+
231
+ function getNightlyVersion() {
232
+ const packageJson = readJson('package.json');
233
+ const baseVersion = packageJson.version.split('-')[0];
234
+ const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
235
+ const gitShortHash = execSync('git rev-parse --short HEAD').toString().trim();
236
+ const releaseVersion = `${baseVersion}-nightly.${date}.${gitShortHash}`;
237
+ return {
238
+ releaseVersion,
239
+ npmTag: 'nightly',
240
+ };
241
+ }
242
+
243
+ function validateVersion(version, format, name) {
244
+ const versionRegex = {
245
+ 'X.Y.Z': /^\d+\.\d+\.\d+$/,
246
+ 'X.Y.Z-preview.N': /^\d+\.\d+\.\d+-preview\.\d+$/,
247
+ };
248
+
249
+ if (!versionRegex[format] || !versionRegex[format].test(version)) {
250
+ throw new Error(
251
+ `Invalid ${name}: ${version}. Must be in ${format} format.`,
252
+ );
253
+ }
254
+ }
255
+
256
+ function getStableVersion(args) {
257
+ const { latestVersion: latestPreviewVersion } = getAndVerifyTags(
258
+ 'preview',
259
+ 'v*-preview*',
260
+ );
261
+ let releaseVersion;
262
+ if (args.stable_version_override) {
263
+ const overrideVersion = args.stable_version_override.replace(/^v/, '');
264
+ validateVersion(overrideVersion, 'X.Y.Z', 'stable_version_override');
265
+ releaseVersion = overrideVersion;
266
+ } else {
267
+ releaseVersion = latestPreviewVersion.replace(/-preview.*/, '');
268
+ }
269
+
270
+ return {
271
+ releaseVersion,
272
+ npmTag: 'latest',
273
+ };
274
+ }
275
+
276
+ function getPreviewVersion(args) {
277
+ const { latestVersion: latestNightlyVersion } = getAndVerifyTags(
278
+ 'nightly',
279
+ 'v*-nightly*',
280
+ );
281
+ let releaseVersion;
282
+ if (args.preview_version_override) {
283
+ const overrideVersion = args.preview_version_override.replace(/^v/, '');
284
+ validateVersion(
285
+ overrideVersion,
286
+ 'X.Y.Z-preview.N',
287
+ 'preview_version_override',
288
+ );
289
+ releaseVersion = overrideVersion;
290
+ } else {
291
+ releaseVersion =
292
+ latestNightlyVersion.replace(/-nightly.*/, '') + '-preview.0';
293
+ }
294
+
295
+ return {
296
+ releaseVersion,
297
+ npmTag: 'preview',
298
+ };
299
+ }
300
+
301
+ function getPatchVersion(patchFrom) {
302
+ if (!patchFrom || (patchFrom !== 'stable' && patchFrom !== 'preview')) {
303
+ throw new Error(
304
+ 'Patch type must be specified with --patch-from=stable or --patch-from=preview',
305
+ );
306
+ }
307
+ const distTag = patchFrom === 'stable' ? 'latest' : 'preview';
308
+ const pattern = distTag === 'latest' ? 'v[0-9].[0-9].[0-9]' : 'v*-preview*';
309
+ const { latestVersion } = getAndVerifyTags(distTag, pattern);
310
+
311
+ if (patchFrom === 'stable') {
312
+ // For stable versions, increment the patch number: 0.5.4 -> 0.5.5
313
+ const versionParts = latestVersion.split('.');
314
+ const major = versionParts[0];
315
+ const minor = versionParts[1];
316
+ const patch = versionParts[2] ? parseInt(versionParts[2]) : 0;
317
+ const releaseVersion = `${major}.${minor}.${patch + 1}`;
318
+ return {
319
+ releaseVersion,
320
+ npmTag: distTag,
321
+ };
322
+ } else {
323
+ // For preview versions, increment the preview number: 0.6.0-preview.2 -> 0.6.0-preview.3
324
+ const [version, prereleasePart] = latestVersion.split('-');
325
+ if (!prereleasePart || !prereleasePart.startsWith('preview.')) {
326
+ throw new Error(
327
+ `Invalid preview version format: ${latestVersion}. Expected format like "0.6.0-preview.2"`,
328
+ );
329
+ }
330
+
331
+ const previewNumber = parseInt(prereleasePart.split('.')[1]);
332
+ if (isNaN(previewNumber)) {
333
+ throw new Error(`Could not parse preview number from: ${prereleasePart}`);
334
+ }
335
+
336
+ const releaseVersion = `${version}-preview.${previewNumber + 1}`;
337
+ return {
338
+ releaseVersion,
339
+ npmTag: distTag,
340
+ };
341
+ }
342
+ }
343
+
344
+ export function getVersion(options = {}) {
345
+ const args = { ...getArgs(), ...options };
346
+ const type = args.type || 'nightly';
347
+
348
+ let versionData;
349
+ switch (type) {
350
+ case 'nightly':
351
+ versionData = getNightlyVersion();
352
+ // Nightly versions include a git hash, so conflicts are highly unlikely
353
+ // and indicate a problem. We'll still validate but not auto-increment.
354
+ if (doesVersionExist(versionData.releaseVersion)) {
355
+ throw new Error(
356
+ `Version conflict! Nightly version ${versionData.releaseVersion} already exists.`,
357
+ );
358
+ }
359
+ break;
360
+ case 'promote-nightly':
361
+ versionData = promoteNightlyVersion();
362
+ break;
363
+ case 'stable':
364
+ versionData = getStableVersion(args);
365
+ break;
366
+ case 'preview':
367
+ versionData = getPreviewVersion(args);
368
+ break;
369
+ case 'patch':
370
+ versionData = getPatchVersion(args['patch-from']);
371
+ break;
372
+ default:
373
+ throw new Error(`Unknown release type: ${type}`);
374
+ }
375
+
376
+ // For patchable versions, check for existence and increment if needed.
377
+ if (type === 'stable' || type === 'preview' || type === 'patch') {
378
+ let releaseVersion = versionData.releaseVersion;
379
+ while (doesVersionExist(releaseVersion)) {
380
+ console.error(`Version ${releaseVersion} exists, incrementing.`);
381
+ if (releaseVersion.includes('-preview.')) {
382
+ // Increment preview number: 0.6.0-preview.2 -> 0.6.0-preview.3
383
+ const [version, prereleasePart] = releaseVersion.split('-');
384
+ const previewNumber = parseInt(prereleasePart.split('.')[1]);
385
+ releaseVersion = `${version}-preview.${previewNumber + 1}`;
386
+ } else {
387
+ // Increment patch number: 0.5.4 -> 0.5.5
388
+ const versionParts = releaseVersion.split('.');
389
+ const major = versionParts[0];
390
+ const minor = versionParts[1];
391
+ const patch = parseInt(versionParts[2]);
392
+ releaseVersion = `${major}.${minor}.${patch + 1}`;
393
+ }
394
+ }
395
+ versionData.releaseVersion = releaseVersion;
396
+ }
397
+
398
+ // All checks are done, construct the final result.
399
+ const result = {
400
+ releaseTag: `v${versionData.releaseVersion}`,
401
+ ...versionData,
402
+ };
403
+
404
+ result.previousReleaseTag = getLatestStableReleaseTag();
405
+
406
+ return result;
407
+ }
408
+
409
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
410
+ console.log(JSON.stringify(getVersion(getArgs()), null, 2));
411
+ }
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license
5
+ * Copyright 2025 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+
9
+ import { execSync } from 'node:child_process';
10
+ import { mkdirSync, rmSync } from 'node:fs';
11
+ import { tmpdir } from 'node:os';
12
+ import { join } from 'node:path';
13
+
14
+ const ACTIONLINT_VERSION = '1.7.7';
15
+ const SHELLCHECK_VERSION = '0.11.0';
16
+ const YAMLLINT_VERSION = '1.35.1';
17
+
18
+ const TEMP_DIR = join(tmpdir(), 'qwen-code-linters');
19
+
20
+ function getPlatformArch() {
21
+ const platform = process.platform;
22
+ const arch = process.arch;
23
+ if (platform === 'linux' && arch === 'x64') {
24
+ return {
25
+ actionlint: 'linux_amd64',
26
+ shellcheck: 'linux.x86_64',
27
+ };
28
+ }
29
+ if (platform === 'darwin' && arch === 'x64') {
30
+ return {
31
+ actionlint: 'darwin_amd64',
32
+ shellcheck: 'darwin.x86_64',
33
+ };
34
+ }
35
+ if (platform === 'darwin' && arch === 'arm64') {
36
+ return {
37
+ actionlint: 'darwin_arm64',
38
+ shellcheck: 'darwin.aarch64',
39
+ };
40
+ }
41
+ throw new Error(`Unsupported platform/architecture: ${platform}/${arch}`);
42
+ }
43
+
44
+ const platformArch = getPlatformArch();
45
+
46
+ /**
47
+ * @typedef {{
48
+ * check: string;
49
+ * installer: string;
50
+ * run: string;
51
+ * }}
52
+ */
53
+
54
+ /**
55
+ * @type {{[linterName: string]: Linter}}
56
+ */
57
+ const LINTERS = {
58
+ actionlint: {
59
+ check: 'command -v actionlint',
60
+ installer: `
61
+ mkdir -p "${TEMP_DIR}/actionlint"
62
+ curl -sSLo "${TEMP_DIR}/.actionlint.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_${platformArch.actionlint}.tar.gz"
63
+ tar -xzf "${TEMP_DIR}/.actionlint.tgz" -C "${TEMP_DIR}/actionlint"
64
+ `,
65
+ run: `
66
+ actionlint \
67
+ -color \
68
+ -ignore 'SC2002:' \
69
+ -ignore 'SC2016:' \
70
+ -ignore 'SC2129:' \
71
+ -ignore 'label ".+" is unknown'
72
+ `,
73
+ },
74
+ shellcheck: {
75
+ check: 'command -v shellcheck',
76
+ installer: `
77
+ mkdir -p "${TEMP_DIR}/shellcheck"
78
+ curl -sSLo "${TEMP_DIR}/.shellcheck.txz" "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${platformArch.shellcheck}.tar.xz"
79
+ tar -xf "${TEMP_DIR}/.shellcheck.txz" -C "${TEMP_DIR}/shellcheck" --strip-components=1
80
+ `,
81
+ run: `
82
+ git ls-files | grep -v '^integration-tests/terminal-bench/' | grep -E '^([^.]+|.*\\.(sh|zsh|bash))' | xargs file --mime-type \
83
+ | grep "text/x-shellscript" | awk '{ print substr($1, 1, length($1)-1) }' \
84
+ | xargs shellcheck \
85
+ --check-sourced \
86
+ --enable=all \
87
+ --exclude=SC2002,SC2129,SC2310 \
88
+ --severity=style \
89
+ --format=gcc \
90
+ --color=never | sed -e 's/note:/warning:/g' -e 's/style:/warning:/g'
91
+ `,
92
+ },
93
+ yamllint: {
94
+ check: 'command -v yamllint',
95
+ installer: `pip3 install --user "yamllint==${YAMLLINT_VERSION}"`,
96
+ run: "git ls-files | grep -E '\\.(yaml|yml)' | xargs yamllint --format github",
97
+ },
98
+ };
99
+
100
+ function runCommand(command, stdio = 'inherit') {
101
+ try {
102
+ const env = { ...process.env };
103
+ const nodeBin = join(process.cwd(), 'node_modules', '.bin');
104
+ env.PATH = `${nodeBin}:${TEMP_DIR}/actionlint:${TEMP_DIR}/shellcheck:${env.PATH}`;
105
+ if (process.platform === 'darwin') {
106
+ env.PATH = `${env.PATH}:${process.env.HOME}/Library/Python/3.12/bin`;
107
+ } else if (process.platform === 'linux') {
108
+ env.PATH = `${env.PATH}:${process.env.HOME}/.local/bin`;
109
+ }
110
+ execSync(command, { stdio, env });
111
+ return true;
112
+ } catch (_e) {
113
+ return false;
114
+ }
115
+ }
116
+
117
+ export function setupLinters() {
118
+ console.log('Setting up linters...');
119
+ rmSync(TEMP_DIR, { recursive: true, force: true });
120
+ mkdirSync(TEMP_DIR, { recursive: true });
121
+
122
+ for (const linter in LINTERS) {
123
+ const { check, installer } = LINTERS[linter];
124
+ if (!runCommand(check, 'ignore')) {
125
+ console.log(`Installing ${linter}...`);
126
+ if (!runCommand(installer)) {
127
+ console.error(
128
+ `Failed to install ${linter}. Please install it manually.`,
129
+ );
130
+ process.exit(1);
131
+ }
132
+ }
133
+ }
134
+ console.log('All required linters are available.');
135
+ }
136
+
137
+ export function runESLint() {
138
+ console.log('\nRunning ESLint...');
139
+ if (!runCommand('npm run lint:ci')) {
140
+ process.exit(1);
141
+ }
142
+ }
143
+
144
+ export function runActionlint() {
145
+ console.log('\nRunning actionlint...');
146
+ if (!runCommand(LINTERS.actionlint.run)) {
147
+ process.exit(1);
148
+ }
149
+ }
150
+
151
+ export function runShellcheck() {
152
+ console.log('\nRunning shellcheck...');
153
+ if (!runCommand(LINTERS.shellcheck.run)) {
154
+ process.exit(1);
155
+ }
156
+ }
157
+
158
+ export function runYamllint() {
159
+ console.log('\nRunning yamllint...');
160
+ if (!runCommand(LINTERS.yamllint.run)) {
161
+ process.exit(1);
162
+ }
163
+ }
164
+
165
+ export function runPrettier() {
166
+ console.log('\nRunning Prettier...');
167
+ if (!runCommand('prettier --write .')) {
168
+ process.exit(1);
169
+ }
170
+ }
171
+
172
+ function main() {
173
+ const args = process.argv.slice(2);
174
+
175
+ if (args.includes('--setup')) {
176
+ setupLinters();
177
+ }
178
+ if (args.includes('--eslint')) {
179
+ runESLint();
180
+ }
181
+ if (args.includes('--actionlint')) {
182
+ runActionlint();
183
+ }
184
+ if (args.includes('--shellcheck')) {
185
+ runShellcheck();
186
+ }
187
+ if (args.includes('--yamllint')) {
188
+ runYamllint();
189
+ }
190
+ if (args.includes('--prettier')) {
191
+ runPrettier();
192
+ }
193
+
194
+ if (args.length === 0) {
195
+ setupLinters();
196
+ runESLint();
197
+ runActionlint();
198
+ runShellcheck();
199
+ runYamllint();
200
+ runPrettier();
201
+ console.log('\nAll linting checks passed!');
202
+ }
203
+ }
204
+
205
+ main();