Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

55 lines
2.1 KiB
JavaScript

// VSCode-style user settings.json reader for Trae SOLO.
//
// settings-read — parse and pretty-print
// ~/Library/Application Support/TRAE SOLO/User/settings.json
//
// Trae SOLO follows VSCode's JSONC settings convention (line/block comments
// + trailing commas allowed).
import * as fs from 'node:fs';
import * as path from 'node:path';
import { cli, Strategy } from '@jackwener/opencli/registry';
import {
CommandExecutionError,
EmptyResultError,
} from '@jackwener/opencli/errors';
import { TRAE_APP_SUPPORT } from './_fs.js';
const TRAE_SETTINGS_JSON = path.join(TRAE_APP_SUPPORT, 'User/settings.json');
cli({
site: 'trae-solo',
name: 'settings-read',
access: 'read',
description: 'Parse and pretty-print Trae SOLO user settings.json (~/Library/Application Support/TRAE SOLO/User/settings.json). Handles VSCode JSONC syntax (line comments + trailing commas).',
domain: 'localhost',
strategy: Strategy.LOCAL,
browser: false,
args: [],
columns: ['Field', 'Value'],
func: async () => {
if (!fs.existsSync(TRAE_SETTINGS_JSON)) {
throw new EmptyResultError('trae-solo settings-read', `settings.json not found: ${TRAE_SETTINGS_JSON}`);
}
const raw = fs.readFileSync(TRAE_SETTINGS_JSON, 'utf-8');
// Strip JSONC: line comments + block comments + trailing commas.
const stripped = raw
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/^\s*\/\/.*$/gm, '')
.replace(/([^:"])\/\/.*$/gm, '$1')
.replace(/,(\s*[}\]])/g, '$1');
let obj;
try { obj = JSON.parse(stripped); } catch (e) {
throw new CommandExecutionError(`Failed to parse settings.json: ${e.message}`, '');
}
const rows = [];
for (const [k, v] of Object.entries(obj)) {
rows.push({ Field: k, Value: typeof v === 'object' ? JSON.stringify(v) : String(v) });
}
if (!rows.length) {
throw new EmptyResultError('trae-solo settings-read', 'settings.json is empty (or contains only defaults).');
}
return rows;
},
});