Engineering Practices for Building Desktop Tools with AI Coding Assistants
This article explains how to use an AI coding assistant to build a desktop batch tool, using a utility that extracts audio from videos as an example. It covers how to turn requirements into checkable acceptance criteria, keep long-running work off the GUI main thread, review generated code, handle errors and progress reporting, and verify behavior with a short manual test list. The approach is not tied to any specific model or coding product.
From “Code That Compiles” to “Code That Runs”
Many teams already use AI coding assistants for scripts, APIs, and documentation. Desktop software, however, is held to a much higher standard. A desktop program is more than a set of functions. It needs a file list, input and output options, start and exit controls, progress and status feedback, and clear error messages when something fails. Furthermore, tasks such as conversion, transcoding, and batch scanning often take anywhere from a few seconds to several minutes. If this work runs directly on the UI main thread, the window stops redrawing and buttons stop responding. Users then assume the program has crashed. Therefore, “no errors” is only part of the bar. The real requirements are whether the full set of requirements is met, whether long-running work is decoupled from UI refresh, and whether exception paths can recover.
The following uses a typical small tool, “batch extracting audio from videos,” as an example to show how to write requirements, how to review generated results, and how to turn a single generation into maintainable engineering practice. The article is not tied to any specific model or coding product, and the principles apply to most AI-assisted coding scenarios.
Write Acceptance Criteria as a Checklist
Vague prompts produce vague implementations. Instead of asking for “a good-to-use converter,” break the constraints into verifiable items:
- Input: Support common container formats, and accept both single files and whole directories. Directory input should be scanned recursively, and entries without permission or in an unrecognized format should be skipped.
- Output: Cover at least two mainstream categories, compressed audio and lossless audio, and let the user choose an output directory. If no directory is specified, show an explicit default instead of silently writing to an uncertain location.
- Interface: File list, format options, Start, Clear, and Exit. The progress bar reflects overall progress, and the status bar shows the current file and stage.
- Robustness: Do not silently overwrite files with the same name. Append a sequence number instead. If the external media processing component is missing, check for it before conversion and prompt the user to install it or configure its path, rather than failing halfway through.
- Interaction: The window remains movable, and conversion can be cancelled during processing. A single file failure is logged and does not stop the batch, unless the user explicitly asks to stop on the first error.
- Technical constraints: Use the team’s existing programming language and GUI framework. Do not introduce dependencies that have not been reviewed.
Listing “no freezing” as a separate acceptance item works better than a general requirement such as “runs smoothly.” Add observable criteria. While a batch job runs, the window title or status bar should keep updating. The Cancel button should respond within a few hundred milliseconds. The progress should not stay at the same percentage for a long time without a text explanation.
The Core of a Responsive UI: Who Owns the Main Thread
A GUI typically has one main thread that runs the event loop. It handles redrawing, input, and timers. Any synchronous file scan, process wait, or large block read or write that occupies this thread causes the event queue to back up. The window then appears frozen.
A sound structure has three layers:
- The UI layer only collects parameters, displays the list, receives progress messages, and handles start and stop commands.
- The scheduling layer processes files one by one in a background worker or task queue. It limits concurrency so that launching too many external processes at once does not saturate the disk or CPU.
- The media processing layer calls the conversion capability already installed on the machine, reads return codes and standard error output, and maps the result to success, skipped, or failed.
Background threads should not modify UI controls directly. Instead, a background thread places the completed count, current file name, error text, and whether the job has ended into a thread-safe queue. The main thread then pulls messages from the queue on a timer and updates the controls. This avoids cross-thread drawing, and it makes cancellation straightforward. The main thread sets a cancellation flag, the work loop checks the flag before starting each file, and it terminates the current child process where possible.
The following pseudocode illustrates the structure only. It does not represent the API of any particular framework:
on_start():params = read_form()if not media_tool_available(params.tool_path):show_error("Media processing component not found")returnset_running(true)start_worker(params)worker(params):files = expand_inputs(params.inputs) # recursive, deduplicated, filteredtotal = len(files)for i, src in enumerate(files):if cancelled():post(status="Cancelled", done=i, total=total)returndst = unique_output_path(params.out_dir, src, params.format)code, err = convert_one(src, dst, params)post(progress=i + 1, total=total, file=src, ok=(code == 0), err=err)post(status="Done")on_ui_tick():while msg = poll():update_progress(msg)append_log(msg)if msg.finished:set_running(false)
When reviewing generated code, search first for three problems. Check whether the conversion function is called synchronously inside a button callback, whether a worker thread directly manipulates window objects, and whether cancellation only disables the button without actually notifying the work loop. These three checks say more about whether a model understands desktop programs than the line count does.
Make the “Extra” Details Explicit Requirements
A fairly complete generation often adds recursive directory scanning, format completion, duplicate-name protection, and runtime environment checks on its own. These are not decorative features. They are basic safeguards for a batch tool:
- Recursive scanning needs a depth or count limit. It should ignore hidden directories, system directories, and the output directory itself, so that newly generated audio files are not picked up as inputs and do not cause a runaway loop.
- The format list must match what the conversion layer actually supports. Every option shown in the interface needs a matching branch in the conversion parameters. Otherwise, a user can select a format that then fails to run.
- Overwrite policies must be predictable. Appending a sequence number, adding a timestamp, or writing into a separate subdirectory are all valid options. The status bar should state the final path so users can verify it.
- Environment checks should run before the first task in a batch. They should distinguish between cases such as “component not found,” “no execute permission,” and “version too old to parse the arguments.” Error messages should tell the user what to check next, not just display a raw return code.
If the generated code includes behaviors you did not ask for, add them to the requirements document and test cases right away. Otherwise, a later prompt revision might quietly remove them. The value of AI generation is that it speeds up the first version. Engineering quality still depends on a checklist that locks in the intended behavior.
Error Handling, Progress, and Default Directories: Ask Questions That Can Be Falsified
Code that compiles only shows that the syntax and dependencies are roughly correct. It does not show that the behavior is correct. Use a small number of targeted questions and real test runs to pin down the semantics.
The default output directory is a typical example. A reasonable default is either the directory the user selects or a fixed subdirectory beside each source file. The current program directory is a poor choice, because its meaning changes with shortcuts, scheduled tasks, and different working directories. This can write files to unexpected locations. The interface should show the resolved absolute path as read-only text. The help text should also explain which rule applies when no directory is selected, whether the directory is created when it does not exist, and whether the whole batch stops when permission is denied.
The progress bar also needs a defined meaning. Dividing progress evenly by file count is the most intuitive approach, but long and short videos take very different amounts of time, so users may feel the progress bar is misleading. A safer approach is to base the main progress on file count and show the elapsed time of the current file in the status bar. If the underlying conversion tool provides a time ratio, use it as secondary progress. When no reliable ratio is available, do not display a fabricated percentage.
Error messages should include at least the source file name, target path, failed stage, and an actionable suggestion. After a batch finishes, show counts of succeeded, failed, and skipped files, and let the user save the log as a text file for later troubleshooting. A failed file should not leave a partial output behind. Write to a temporary file first, rename it to the final name only after success, and delete the temporary file on failure. This way, a rerun does not mistake a corrupted file for a valid result.
Suggested Verification Order
You do not need a complex test framework. Walking through the following steps by hand usually exposes the main defects:
- Start with an empty list. The tool should show a message, not enter an infinite loop.
- Run one very short sample. Confirm the format, path, and exit code.
- Use a directory that contains unrecognized files. These should be skipped and logged, and the remaining files should continue processing.
- Use a target file that already exists.
