scripting-cli 1.2.5 → 1.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Scripting App Command-Line Tool
2
2
 
3
- Welcome to the `scripting-cli`, the command-line tool designed for integrating with the Scripting app. This tool allows you to synchronize and preview your scripts in real-time as you develop them using your favorite desktop editor, such as VSCode.
3
+ Welcome to the `scripting-cli`, the command-line tool designed for integrating with the Scripting app. This tool allows you to synchronize and preview your scripts in real-time as you develop them using your favorite desktop editor (VSCode, Cursor, Windsurf, Zed, WebStorm, Vim, and more).
4
4
 
5
5
  [中文](./README_zh.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
6
6
 
@@ -67,6 +67,107 @@ After connecting, select the script project you want to debug. The Scripting app
67
67
 
68
68
  As you write and save scripts using your desktop editor (e.g., VSCode), the changes will automatically sync with the Scripting app and be executed in real-time—making development and debugging much smoother.
69
69
 
70
+ ## Editor Selection and Config File
71
+
72
+ `scripting-cli` is no longer tied to VSCode. The first time you run `npx scripting-cli start`, you'll be prompted to choose the editor you actually use. Your choice is saved to `scripting.config.json` in your project root so the prompt won't appear again.
73
+
74
+ ### Supported editors
75
+
76
+ VSCode, VSCode Insiders, VSCodium, Cursor, Windsurf, Trae, Zed, WebStorm, IntelliJ IDEA, Fleet, Sublime Text, Nova, Vim, Neovim, Emacs, plus `custom` (any other command) and `none` (disable auto-open).
77
+
78
+ Editors detected on your `PATH` are marked with ✓ and listed first.
79
+
80
+ ### Per-run override
81
+
82
+ ```bash
83
+ # Use Cursor for this run only (does not modify scripting.config.json)
84
+ npx scripting-cli start --editor=cursor
85
+
86
+ # Re-run the interactive selection and overwrite the saved choice
87
+ npx scripting-cli start --reconfigure
88
+ ```
89
+
90
+ ### Config file
91
+
92
+ `scripting-cli` looks for the first config file it finds in this order:
93
+
94
+ ```
95
+ scripting.config.ts
96
+ scripting.config.mts
97
+ scripting.config.cts
98
+ scripting.config.js
99
+ scripting.config.mjs
100
+ scripting.config.cjs
101
+ scripting.config.json
102
+ ```
103
+
104
+ The default file is JSON so the npx flow stays zero-install. TypeScript and JavaScript files are loaded via [jiti](https://github.com/unjs/jiti).
105
+
106
+ ```jsonc
107
+ // scripting.config.json
108
+ {
109
+ "editor": "cursor", // see supported editors above
110
+ "editorCommand": "cursor", // optional, overrides the default command
111
+ "editorArgs": [], // optional, extra CLI args
112
+ "port": 3000,
113
+ "autoOpen": true,
114
+ "generateTsConfig": true, // set to false if you manage tsconfig.json yourself
115
+ "logLevel": "info", // "silent" | "error" | "warn" | "info" | "debug"
116
+ "ignore": ["*.log", "dist", "assets/large.mp4"] // extra paths to exclude from sync
117
+ }
118
+ ```
119
+
120
+ CLI flags take precedence over the config file.
121
+
122
+ ### Excluding files from sync (`ignore`)
123
+
124
+ Synchronization covers **all** files in a script directory — source code, plus
125
+ images, fonts, and any other assets — in both directions (app ⇄ desktop).
126
+ Text files sync with change tracking; everything else is transferred as raw bytes.
127
+
128
+ Dotfiles/dot-directories (such as `.git`, `.vscode`, `.DS_Store`) and `node_modules`
129
+ are **always excluded** by default. Use `ignore` to exclude additional files:
130
+
131
+ ```jsonc
132
+ {
133
+ "ignore": [
134
+ "*.log", // extension glob — matches any file ending in .log
135
+ "dist", // name — matches any file or directory named "dist" at any depth
136
+ "assets/big.mp4" // path — matches this file relative to the script root
137
+ ]
138
+ }
139
+ ```
140
+
141
+ Each entry is matched as one of three forms:
142
+
143
+ - `*.ext` — matches files by extension.
144
+ - a plain name (no `/`) — matches any path segment (file or directory) with that name.
145
+ - a path containing `/` — matches that script-relative path (exact or as a directory prefix).
146
+
147
+ `ignore` applies to both sync directions.
148
+
149
+ ### Type completion (TypeScript config)
150
+
151
+ To get autocomplete in `scripting.config.ts`, install scripting-cli as a dev dependency:
152
+
153
+ ```bash
154
+ npm i -D scripting-cli
155
+ ```
156
+
157
+ Then:
158
+
159
+ ```ts
160
+ // scripting.config.ts
161
+ import { defineConfig } from 'scripting-cli'
162
+
163
+ export default defineConfig({
164
+ editor: 'cursor',
165
+ port: 4000,
166
+ })
167
+ ```
168
+
169
+ You can also use `.ts` without installing the package — `npx scripting-cli start` still loads it via `jiti`. You just won't get IDE type hints.
170
+
70
171
  ## Example Workflow
71
172
 
72
173
  1. Start the local service:
@@ -89,8 +190,9 @@ As you write and save scripts using your desktop editor (e.g., VSCode), the chan
89
190
  ```bash
90
191
  npx scripting-cli start --no-auto-open
91
192
  ```
193
+ * Use `--editor=<key>` to override the configured editor for a single run, or `--reconfigure` to re-run the interactive editor selection.
92
194
  * To use the Bonjour service, ensure your system supports it. On Windows, you may need to install Bonjour manually. Then, use the `--bonjour` option to enable it.
93
- * This tool is ideal for users who prefer desktop editors like VSCode and want seamless code synchronization and debugging with the Scripting app.
195
+ * This tool works with any desktop editor and provides seamless code synchronization and debugging with the Scripting app.
94
196
 
95
197
  ## Troubleshooting
96
198
 
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const yargs_1 = __importDefault(require("yargs/yargs"));
41
+ const helpers_1 = require("yargs/helpers");
42
+ const start_server_1 = require("./start_server");
43
+ (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
44
+ .parserConfiguration({
45
+ "boolean-negation": false
46
+ })
47
+ .command('start', 'Start the scripting-cli server', (yargs) => {
48
+ return yargs
49
+ .options({
50
+ port: {
51
+ alias: ["p"],
52
+ describe: "The port the server listens on",
53
+ type: "number",
54
+ },
55
+ "no-auto-open": {
56
+ type: "boolean",
57
+ describe: "Do not open the index.tsx/widget.tsx file automatically",
58
+ },
59
+ bonjour: {
60
+ type: "boolean",
61
+ describe: "Enable bonjour service",
62
+ },
63
+ editor: {
64
+ type: "string",
65
+ describe: "Override the editor for this run (e.g. vscode, cursor, zed, webstorm)",
66
+ },
67
+ reconfigure: {
68
+ type: "boolean",
69
+ describe: "Force the interactive editor selection again, overwriting the saved config",
70
+ },
71
+ })
72
+ .usage("$0 start [--port=<port>] [--editor=<key>] [--reconfigure] [--no-auto-open] [--bonjour]")
73
+ .example([
74
+ ["$0 start -p=8000", "Start server and listen on 8000"],
75
+ ["$0 start --no-auto-open", "Start server without opening the entry file"],
76
+ ["$0 start --bonjour", "Start server with bonjour service"],
77
+ ["$0 start --editor=cursor", "Use Cursor for this run"],
78
+ ["$0 start --reconfigure", "Reselect the editor interactively"],
79
+ ]);
80
+ }, (argv) => {
81
+ (0, start_server_1.startServer)({
82
+ port: argv.port,
83
+ noAutoOpen: argv['no-auto-open'],
84
+ startBonjourService: argv.bonjour,
85
+ editorOverride: argv.editor,
86
+ reconfigure: argv.reconfigure,
87
+ });
88
+ })
89
+ .command('migrate', 'Migrate the scripts in the workspace root directory to the scripts directory.', (yargs) => {
90
+ return yargs
91
+ .usage("$0 migrate")
92
+ .example([
93
+ ["$0 migrate", "Migrate the scripts in the workspace root directory to the scripts directory."]
94
+ ]);
95
+ }, async () => {
96
+ const { migrateOldFiles } = await Promise.resolve().then(() => __importStar(require('./util')));
97
+ await migrateOldFiles();
98
+ process.exit(0);
99
+ })
100
+ .showHelpOnFail(true)
101
+ .option('help', {
102
+ alias: 'h',
103
+ describe: 'Show help',
104
+ })
105
+ .demandCommand()
106
+ .parse();
@@ -0,0 +1,11 @@
1
+ import { ResolvedConfig, ScriptingConfig } from './types';
2
+ export declare function findConfigFile(cwd?: string): string | null;
3
+ export declare function loadConfigFile(filePath: string): Promise<ScriptingConfig>;
4
+ export declare function saveJsonConfig(config: ScriptingConfig, cwd?: string): string;
5
+ export interface ResolveOptions {
6
+ port?: number;
7
+ noAutoOpen?: boolean;
8
+ editorOverride?: string;
9
+ reconfigure?: boolean;
10
+ }
11
+ export declare function resolveConfig(opts: ResolveOptions): Promise<ResolvedConfig>;
package/dist/config.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findConfigFile = findConfigFile;
7
+ exports.loadConfigFile = loadConfigFile;
8
+ exports.saveJsonConfig = saveJsonConfig;
9
+ exports.resolveConfig = resolveConfig;
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const jiti_1 = require("jiti");
14
+ const editors_1 = require("./editors");
15
+ const prompt_1 = require("./prompt");
16
+ const CONFIG_FILENAMES = [
17
+ 'scripting.config.ts',
18
+ 'scripting.config.mts',
19
+ 'scripting.config.cts',
20
+ 'scripting.config.js',
21
+ 'scripting.config.mjs',
22
+ 'scripting.config.cjs',
23
+ 'scripting.config.json',
24
+ ];
25
+ const DEFAULTS = {
26
+ editor: 'none',
27
+ editorArgs: [],
28
+ port: 3000,
29
+ autoOpen: true,
30
+ generateTsConfig: true,
31
+ logLevel: 'info',
32
+ ignore: [],
33
+ };
34
+ function findConfigFile(cwd = process.cwd()) {
35
+ for (const name of CONFIG_FILENAMES) {
36
+ const p = path_1.default.join(cwd, name);
37
+ if (fs_1.default.existsSync(p))
38
+ return p;
39
+ }
40
+ return null;
41
+ }
42
+ async function loadConfigFile(filePath) {
43
+ if (filePath.endsWith('.json')) {
44
+ const raw = fs_1.default.readFileSync(filePath, 'utf-8');
45
+ try {
46
+ return JSON.parse(raw);
47
+ }
48
+ catch (e) {
49
+ console.log(chalk_1.default.red(`[config] Failed to parse ${path_1.default.basename(filePath)}: ${e}`));
50
+ return {};
51
+ }
52
+ }
53
+ try {
54
+ const jiti = (0, jiti_1.createJiti)(__filename, { interopDefault: true });
55
+ const mod = await jiti.import(filePath, { default: true });
56
+ if (mod && typeof mod === 'object') {
57
+ // jiti returns the default export directly when interopDefault is true
58
+ return mod;
59
+ }
60
+ return {};
61
+ }
62
+ catch (e) {
63
+ console.log(chalk_1.default.red(`[config] Failed to load ${path_1.default.basename(filePath)}: ${e}`));
64
+ return {};
65
+ }
66
+ }
67
+ function saveJsonConfig(config, cwd = process.cwd()) {
68
+ const filePath = path_1.default.join(cwd, 'scripting.config.json');
69
+ fs_1.default.writeFileSync(filePath, JSON.stringify(config, null, 2) + '\n');
70
+ console.log(chalk_1.default.green(`scripting.config.json created.`));
71
+ return filePath;
72
+ }
73
+ function mergeConfig(base, override) {
74
+ return {
75
+ editor: override.editor ?? base.editor,
76
+ editorCommand: override.editorCommand ?? base.editorCommand,
77
+ editorArgs: override.editorArgs ?? base.editorArgs,
78
+ port: override.port ?? base.port,
79
+ autoOpen: override.autoOpen ?? base.autoOpen,
80
+ generateTsConfig: override.generateTsConfig ?? base.generateTsConfig,
81
+ logLevel: override.logLevel ?? base.logLevel,
82
+ ignore: override.ignore ?? base.ignore,
83
+ };
84
+ }
85
+ function resolveDefaults(config) {
86
+ return {
87
+ editor: config.editor ?? DEFAULTS.editor,
88
+ editorCommand: config.editorCommand,
89
+ editorArgs: config.editorArgs ?? DEFAULTS.editorArgs,
90
+ port: config.port ?? DEFAULTS.port,
91
+ autoOpen: config.autoOpen ?? DEFAULTS.autoOpen,
92
+ generateTsConfig: config.generateTsConfig ?? DEFAULTS.generateTsConfig,
93
+ logLevel: config.logLevel ?? DEFAULTS.logLevel,
94
+ ignore: config.ignore ?? DEFAULTS.ignore,
95
+ };
96
+ }
97
+ async function resolveConfig(opts) {
98
+ const cwd = process.cwd();
99
+ const existing = findConfigFile(cwd);
100
+ let fileConfig = {};
101
+ if (existing && !opts.reconfigure) {
102
+ fileConfig = await loadConfigFile(existing);
103
+ console.log(chalk_1.default.gray(`Loaded config from ${path_1.default.basename(existing)}`));
104
+ }
105
+ // First-run or --reconfigure: ask the user.
106
+ // Skip the prompt when --editor is provided non-interactively, or when a config already specifies an editor.
107
+ const needPrompt = opts.reconfigure ||
108
+ (!fileConfig.editor && !opts.editorOverride);
109
+ if (needPrompt) {
110
+ const answers = await (0, prompt_1.promptForEditor)();
111
+ if (answers) {
112
+ fileConfig = { ...fileConfig, ...answers };
113
+ // Persist as JSON for npx-friendliness
114
+ saveJsonConfig(fileConfig, cwd);
115
+ }
116
+ }
117
+ const cliOverride = {};
118
+ if (opts.editorOverride)
119
+ cliOverride.editor = validateEditorKey(opts.editorOverride);
120
+ if (opts.port != null)
121
+ cliOverride.port = opts.port;
122
+ if (opts.noAutoOpen)
123
+ cliOverride.autoOpen = false;
124
+ const merged = mergeConfig(fileConfig, cliOverride);
125
+ return resolveDefaults(merged);
126
+ }
127
+ function validateEditorKey(value) {
128
+ const editor = (0, editors_1.getEditor)(value);
129
+ if (!editor) {
130
+ console.log(chalk_1.default.yellow(`[config] Unknown editor "${value}". Falling back to "none".`));
131
+ return 'none';
132
+ }
133
+ return editor.key;
134
+ }
@@ -0,0 +1,2 @@
1
+ export declare const globalDtsFileName = "global.d.ts";
2
+ export declare const scriptingDtsFileName = "scripting.d.ts";
@@ -0,0 +1,68 @@
1
+ import { FSWatcher } from 'chokidar';
2
+ import { Socket } from 'socket.io';
3
+ import { globalDtsFileName, scriptingDtsFileName } from './const';
4
+ import { ResolvedConfig } from './types';
5
+ export declare class Controller {
6
+ private static instances;
7
+ static create(socket: Socket, config: ResolvedConfig): Controller;
8
+ static get(socketId: string): Controller | undefined;
9
+ watcher: FSWatcher | null;
10
+ scriptName: string | null;
11
+ socket: Socket | null;
12
+ config: ResolvedConfig;
13
+ constructor(socket: Socket, config: ResolvedConfig);
14
+ createWatcher(scriptName: string): void;
15
+ handleSyncScriptFromClient: (data: {
16
+ [globalDtsFileName]: string;
17
+ [scriptingDtsFileName]: string;
18
+ scriptName: string;
19
+ scriptFiles: Record<string, string>;
20
+ }, ack: (result: {
21
+ error?: string;
22
+ success?: boolean;
23
+ }) => void) => Promise<void>;
24
+ handleSyncScriptFromServer: (data: {
25
+ "global.d.ts": string;
26
+ "scripting.d.ts": string;
27
+ scriptName: string;
28
+ }, ack: (result: {
29
+ error?: string;
30
+ scriptFiles?: Record<string, {
31
+ hash: string;
32
+ content: string;
33
+ }>;
34
+ otherFiles?: string[];
35
+ }) => void) => Promise<void>;
36
+ handleLog: (data: {
37
+ scriptName: string;
38
+ content: string;
39
+ isError: boolean;
40
+ }) => void;
41
+ handleOpenFile: (data: {
42
+ scriptName: string;
43
+ relativePath: string;
44
+ }) => Promise<void>;
45
+ handleStopDebugScript: (data: string, ack: (result: boolean) => void) => void;
46
+ handleGetFileContent: (data: {
47
+ scriptName: string;
48
+ relativePath: string;
49
+ }, ack: (result: {
50
+ error?: string;
51
+ content?: string;
52
+ }) => void) => Promise<void>;
53
+ handlePutFileData: (data: {
54
+ scriptName: string;
55
+ relativePath: string;
56
+ data: Buffer;
57
+ }, ack: (result: {
58
+ error?: string;
59
+ success?: boolean;
60
+ }) => void) => Promise<void>;
61
+ handleGetFilePath: (data: {
62
+ scriptName: string;
63
+ relativePath: string;
64
+ }, ack: (result: {
65
+ error?: string;
66
+ filePath?: string;
67
+ }) => void) => Promise<void>;
68
+ }
@@ -10,10 +10,11 @@ const fs_1 = __importDefault(require("fs"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const const_1 = require("./const");
13
+ const editors_1 = require("./editors");
13
14
  class Controller {
14
15
  static instances = new Map();
15
- static create(socket, noAutoOpen) {
16
- const ctrl = new Controller(socket, noAutoOpen);
16
+ static create(socket, config) {
17
+ const ctrl = new Controller(socket, config);
17
18
  Controller.instances.set(socket.id, ctrl);
18
19
  return ctrl;
19
20
  }
@@ -23,9 +24,9 @@ class Controller {
23
24
  watcher = null;
24
25
  scriptName = null;
25
26
  socket = null;
26
- noAutoOpen;
27
- constructor(socket, noAutoOpen) {
28
- this.noAutoOpen = noAutoOpen;
27
+ config;
28
+ constructor(socket, config) {
29
+ this.config = config;
29
30
  this.socket = socket;
30
31
  socket.emit("socketId", socket.id);
31
32
  // socket.on('syncScriptFromClient', this.handleSyncScriptFromClient);
@@ -52,11 +53,11 @@ class Controller {
52
53
  createWatcher(scriptName) {
53
54
  const scriptDir = (0, util_1.getScriptPath)(scriptName);
54
55
  this.watcher = chokidar_1.default.watch(scriptDir, {
55
- ignored: /(^|[\/\\])\../,
56
+ ignored: (filePath) => (0, util_1.isIgnoredPath)((0, util_1.getRelativePath)(scriptDir, filePath), this.config.ignore),
56
57
  persistent: true,
57
58
  });
58
59
  const updateHandler = (filePath) => {
59
- if (filePath.match(/\.(js(x)?|ts(x)?|json|md|txt)$/)) {
60
+ if (!(0, util_1.isBinaryFile)(filePath)) {
60
61
  // send file content md5 hash to client
61
62
  // const content = fs.readFileSync(filePath, 'utf-8');
62
63
  fs_1.default.readFile(filePath, 'utf-8', (err, content) => {
@@ -120,6 +121,9 @@ class Controller {
120
121
  const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
121
122
  (0, util_1.ensureDirectoryExistence)(scriptDir);
122
123
  await Promise.all(Object.entries(data.scriptFiles).map(async ([filename, content]) => {
124
+ if ((0, util_1.isIgnoredPath)(filename, this.config.ignore)) {
125
+ return;
126
+ }
123
127
  const filePath = path_1.default.join(scriptDir, filename);
124
128
  (0, util_1.ensureDirectoryExistence)(filePath);
125
129
  await fs_1.default.promises.writeFile(filePath, content);
@@ -129,13 +133,13 @@ class Controller {
129
133
  ack({
130
134
  success: true,
131
135
  });
132
- if (!this.noAutoOpen) {
133
- // Open the entry file in VSCode after a delay
136
+ if (this.config.autoOpen) {
137
+ // Open the entry file in the configured editor after a delay
134
138
  // to ensure the response is sent. Because the open file command
135
139
  // may suspend the response and cause the client to not receive the ack.
136
140
  setTimeout(() => {
137
141
  const entryFilePath = path_1.default.join(scriptDir, "index.tsx");
138
- (0, util_1.tryOpenFileInVSCode)(entryFilePath);
142
+ (0, editors_1.openFileInEditor)(entryFilePath, this.config);
139
143
  }, 1000);
140
144
  }
141
145
  }
@@ -175,15 +179,15 @@ class Controller {
175
179
  const readDir = async (dir) => {
176
180
  const files = await fs_1.default.promises.readdir(dir, { withFileTypes: true });
177
181
  await Promise.all(files.map(async (file) => {
178
- // ignore .git and .vscode directories
179
- if (file.name.startsWith('.git') || file.name.startsWith('.vscode')) {
182
+ const filePath = path_1.default.join(dir, file.name);
183
+ const relativePath = (0, util_1.getRelativePath)(scriptDir, filePath);
184
+ // Skip default-ignored (dotfiles, node_modules) and user-configured paths.
185
+ if ((0, util_1.isIgnoredPath)(relativePath, this.config.ignore)) {
180
186
  return;
181
187
  }
182
- // only read js, jsx, ts, tsx, json, md, txt files
188
+ // Classify by content: text files sync with hash, others as binary.
183
189
  if (file.isFile()) {
184
- const filePath = path_1.default.join(dir, file.name);
185
- const relativePath = (0, util_1.getRelativePath)(scriptDir, filePath);
186
- if (file.name.match(/\.(js(x)?|ts(x)?|json|md|txt)$/)) {
190
+ if (!(0, util_1.isBinaryFile)(filePath)) {
187
191
  const content = await fs_1.default.promises.readFile(filePath, 'utf-8').catch((err) => {
188
192
  console.log(chalk_1.default.red(`Error reading file: ${err}`));
189
193
  });
@@ -210,13 +214,13 @@ class Controller {
210
214
  otherFiles: otherFiles.length > 0 ? otherFiles : undefined,
211
215
  });
212
216
  this.createWatcher(data.scriptName);
213
- if (!this.noAutoOpen) {
214
- // Open the entry file in VSCode after a delay
217
+ if (this.config.autoOpen) {
218
+ // Open the entry file in the configured editor after a delay
215
219
  // to ensure the response is sent. Because the open file command
216
220
  // may suspend the response and cause the client to not receive the ack.
217
221
  setTimeout(() => {
218
222
  const entryFilePath = path_1.default.join(scriptDir, "index.tsx");
219
- (0, util_1.tryOpenFileInVSCode)(entryFilePath);
223
+ (0, editors_1.openFileInEditor)(entryFilePath, this.config);
220
224
  }, 1000);
221
225
  }
222
226
  }
@@ -237,8 +241,8 @@ class Controller {
237
241
  return;
238
242
  }
239
243
  const filePath = path_1.default.join((0, util_1.getScriptPath)(this.scriptName), data.relativePath);
240
- if (!this.noAutoOpen && fs_1.default.existsSync(filePath)) {
241
- (0, util_1.tryOpenFileInVSCode)(filePath);
244
+ if (this.config.autoOpen && fs_1.default.existsSync(filePath)) {
245
+ (0, editors_1.openFileInEditor)(filePath, this.config);
242
246
  }
243
247
  };
244
248
  handleStopDebugScript = (data, ack) => {
@@ -273,6 +277,45 @@ class Controller {
273
277
  });
274
278
  }
275
279
  };
280
+ handlePutFileData = async (data, ack) => {
281
+ if (this.scriptName !== data.scriptName) {
282
+ ack({
283
+ error: `Script ${data.scriptName} is not initialized`,
284
+ });
285
+ return;
286
+ }
287
+ if ((0, util_1.isIgnoredPath)(data.relativePath, this.config.ignore)) {
288
+ ack({
289
+ error: `Ignored file path: ${data.relativePath}`,
290
+ });
291
+ return;
292
+ }
293
+ const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
294
+ const filePath = path_1.default.join(scriptDir, data.relativePath);
295
+ // Prevent path traversal: the resolved path must stay inside scriptDir.
296
+ const resolved = path_1.default.resolve(filePath);
297
+ if (resolved !== path_1.default.resolve(scriptDir) &&
298
+ !resolved.startsWith(path_1.default.resolve(scriptDir) + path_1.default.sep)) {
299
+ ack({
300
+ error: `Invalid file path: ${data.relativePath}`,
301
+ });
302
+ return;
303
+ }
304
+ try {
305
+ (0, util_1.ensureDirectoryExistence)(filePath);
306
+ await fs_1.default.promises.writeFile(filePath, data.data);
307
+ console.log(`[${chalk_1.default.bold.blue(data.scriptName)}] File uploaded: ${data.relativePath}`);
308
+ ack({
309
+ success: true,
310
+ });
311
+ }
312
+ catch (e) {
313
+ console.log(chalk_1.default.red(`Error writing uploaded file: ${e}`));
314
+ ack({
315
+ error: `Failed to write uploaded file.\n${e}`,
316
+ });
317
+ }
318
+ };
276
319
  handleGetFilePath = async (data, ack) => {
277
320
  if (this.scriptName !== data.scriptName) {
278
321
  ack({
@@ -0,0 +1,18 @@
1
+ import { EditorDescriptor, EditorKey, ResolvedConfig } from './types';
2
+ export declare const EDITORS: EditorDescriptor[];
3
+ export declare function getEditor(key: EditorKey): EditorDescriptor | undefined;
4
+ /**
5
+ * Whether this editor should be marked as "detected" in the picker.
6
+ *
7
+ * Intentionally returns false for:
8
+ * - "custom" / "none": meta options, not real editors
9
+ * - terminal editors (vim/nvim/emacs): typically system-bundled on macOS/Linux,
10
+ * so detection is meaningless — listing them as detected would mislead users
11
+ * into thinking they're their primary editor.
12
+ *
13
+ * GUI editors are detected via PATH command first, then macOS app bundle as fallback.
14
+ */
15
+ export declare function isEditorAvailable(editor: EditorDescriptor): boolean;
16
+ export declare function detectAvailableEditors(): Set<EditorKey>;
17
+ export declare function openFileInEditor(filePath: string, config: ResolvedConfig): void;
18
+ export declare function writeEditorSettings(config: ResolvedConfig): void;