Control method, device, apparatus, storage medium and program product of application program

By introducing an interrupt manager and state machine, and combining application state to execute flexible control operations, the problem of interrupt signal uniformity in the CLI environment is solved, achieving precise interrupt response and input protection, and improving user experience and resource utilization efficiency.

CN122132151APending Publication Date: 2026-06-02UNIONTECH SOFTWARE TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
UNIONTECH SOFTWARE TECH CO LTD
Filing Date
2026-05-06
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

In existing technologies, interrupt signal processing in CLI environments is simplistic and forceful, making it difficult to accurately capture the user's true intent, leading to misoperations and loss of input context.

Method used

By introducing an interrupt manager and a state machine, interrupt commands input by the user are obtained and corresponding control operations are executed in combination with the current state of the application. These operations include interrupt inference tasks, refilling input content, and time window confirmation, thereby achieving dynamic and multi-dimensional interrupt response.

Benefits of technology

It improves the accuracy of interrupt operations, reduces misoperations and input redundancy, enhances user experience and resource utilization efficiency, and reduces the probability of accidental exit.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122132151A_ABST
    Figure CN122132151A_ABST
Patent Text Reader

Abstract

This disclosure relates to a method, apparatus, device, storage medium, and program product for controlling an application. The method includes: during application execution, acquiring a target interrupt instruction input by a user through an interrupt manager; responding to the target interrupt instruction, reading the current state of the application from a state machine through the interrupt manager; determining a target control action corresponding to the current state of the application based on the current state of the application and a state control table through the interrupt manager; and executing the target control action for the application through the interrupt manager. In this way, upon receiving an interrupt instruction, the specific control operation to be executed can be flexibly selected based on the current actual scenario. The interrupt semantics are flexible and diverse, ensuring that the final executed control operation accurately matches the user's true intention.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more specifically, to methods, apparatus, devices, storage media, and program products for controlling applications. Background Technology

[0002] In a command-line interface (CLI), the signal interrupt (SIGINT) is typically triggered by Ctrl+C and is the standard physical signal for program exit. With the integration of Large Language Model (LLM) capabilities into the terminal, users will face more complex asynchronous interaction scenarios. For example, artificial intelligence (AI) may be generating streaming output or automating long-running command sequences.

[0003] In related technologies, the terminal environment's handling of SIGINT is static and one-dimensional. That is, regardless of the user's current input progress or subtask state, the Ctrl+C operation usually kills the current foreground process group or causes the application to exit directly, failing to distinguish whether the user wants to "stop the current AI's verbose reasoning" or "completely exit the application." Therefore, the interrupt semantics in these technologies are brute-force and simplistic, failing to accurately capture the user's true intentions. Summary of the Invention

[0004] This disclosure provides control methods, apparatus, devices, storage media, and program products for applications to at least address the problem in the aforementioned related technologies where interruption semantics are brute-force and singular, making it difficult to accurately capture the user's true thoughts.

[0005] According to a first aspect of the present disclosure, a method for controlling an application is provided. The application includes an interrupt manager and a state machine. The control method includes: during the operation of the application, acquiring a target interrupt instruction input by a user through the interrupt manager; in response to the target interrupt instruction, reading the current state of the application from the state machine through the interrupt manager; determining a target control action corresponding to the current state of the application based on the current state of the application and a state control table through the interrupt manager, wherein the interrupt manager maintains the state control table, and the state control table indicates a mapping relationship between preset application states and corresponding control actions; and executing the target control action for the application through the interrupt manager.

[0006] Optionally, the preset application state includes at least one of the following: the large language model invoked by the application is performing a target inference task, the application is in an idle state, the user is inputting content in the application's input box, and the application is currently executing a system command; wherein, the control action corresponding to the large language model invoked by the application performing a target inference task is to interrupt the target inference task and refill the sent content; the control action corresponding to the idle state is to detect whether an interrupt command is received again within a predetermined time interval; the control action corresponding to the user inputting content in the application's input box is to clear the input box; and the control action corresponding to the application currently executing a system command is to flexibly stop the process and clean up the process.

[0007] Optionally, the application further includes a shadow buffer for caching dialogue content between the user and the large language model through the application; wherein, when the current state of the application is that the large language model invoked by the application is performing a target inference task, the execution of the target control action for the application through the interrupt manager includes: sending an interrupt inference instruction to the large language model through the interrupt manager, so that the large language model interrupts the target inference task based on the interrupt inference instruction; reading the sent dialogue content from the shadow buffer through the interrupt manager, wherein the sent dialogue content is the dialogue content sent by the user through the application to the large language model to instruct the large language model to perform the target inference task; and filling the read sent dialogue content back into the input box of the application through the interrupt manager.

[0008] Optionally, it also includes: displaying a prompt message indicating that the target inference task has been interrupted.

[0009] Optionally, when the application is currently in the idle state, the step of performing the target control action on the application through the interrupt manager includes: detecting whether the interrupt command is received again within the predetermined time interval through the interrupt manager; if the interrupt command is received again within the predetermined time interval, controlling the application to close; otherwise, clearing the input box of the application.

[0010] Optionally, it also includes: displaying a prompt message indicating that the application will be closed if the interrupt command is received again within the predetermined time interval.

[0011] Optionally, when the current state of the application is that the user is entering content in the input box of the application, the step of performing the target control action on the application through the interrupt manager includes: clearing the input box through the interrupt manager.

[0012] Optionally, if the current state of the application is that the application is currently executing a system command, the step of performing the target control action on the application through the interrupt manager includes: monitoring the target process in the application that is executing the system command through the interrupt manager; and cleaning up the target process if it is determined that the target process has finished executing the system command.

[0013] According to a second aspect of the present disclosure, a control device for an application is provided. The application includes an interrupt manager and a state machine. The control device includes: an interrupt instruction acquisition module configured to acquire a target interrupt instruction input by a user through the interrupt manager during the operation of the application; a state reading module configured to read the current state of the application from the state machine through the interrupt manager in response to the target interrupt instruction; an action determination module configured to determine a target control action corresponding to the current state of the application based on the current state of the application and a state control table through the interrupt manager, wherein the interrupt manager maintains the state control table, and the state control table indicates a mapping relationship between preset application states and corresponding control actions; and an action execution module configured to execute the target control action for the application through the interrupt manager.

[0014] Optionally, the preset application state includes at least one of the following: the large language model invoked by the application is performing a target inference task, the application is in an idle state, the user is inputting content in the application's input box, and the application is currently executing a system command; wherein, the control action corresponding to the large language model invoked by the application performing a target inference task is to interrupt the target inference task and refill the sent content; the control action corresponding to the idle state is to detect whether an interrupt command is received again within a predetermined time interval; the control action corresponding to the user inputting content in the application's input box is to clear the input box; and the control action corresponding to the application currently executing a system command is to flexibly stop the process and clean up the process.

[0015] Optionally, the application further includes a shadow buffer for caching dialogue content between the user and the large language model through the application; the action execution module is configured to: when the current state of the application is that the large language model invoked by the application is performing a target inference task, send an interrupt inference instruction to the large language model through the interrupt manager, so that the large language model interrupts the target inference task based on the interrupt inference instruction; read the sent dialogue content from the shadow buffer through the interrupt manager, wherein the sent dialogue content is the dialogue content sent by the user through the application to the large language model to instruct the large language model to perform the target inference task; and fill the input box of the application with the read sent dialogue content through the interrupt manager.

[0016] Optionally, the control device further includes an interruption prompt information display module, configured to display a prompt information indicating that the target inference task has been interrupted.

[0017] Optionally, the action execution module is configured to: when the application is currently in the idle state, detect through the interrupt manager whether the interrupt command is obtained again within the predetermined time interval; if the interrupt command is obtained again within the predetermined time interval, control the application to close; otherwise, clear the input box of the application.

[0018] Optionally, the control device further includes: a shutdown prompt information display module, configured to display a prompt information that the application will be closed if the interrupt command is received again within the predetermined time interval.

[0019] Optionally, the action execution module is configured to clear the input box through the interrupt manager when the current state of the application is that the user is entering content in the input box of the application.

[0020] Optionally, the action execution module is configured to: when the current state of the application is that the application is currently executing a system command, monitor the target process in the application that is executing the system command through the interrupt manager; and when it is determined that the target process has finished executing the system command, clean up the target process.

[0021] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement a control method for an application according to the present disclosure.

[0022] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform a control method for an application according to the present disclosure.

[0023] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements a control method for an application according to the present disclosure.

[0024] The technical solutions provided by the embodiments of this disclosure bring at least the following beneficial effects: In this disclosure, upon receiving an interrupt command, corresponding control operations can be executed based on the current state of the application. This means that the specific control operation to be executed can be flexibly selected based on the current actual scenario. This allows the terminal environment to respond to interrupt commands dynamically and multi-dimensionally, with flexible and diverse interrupt semantics, ensuring that the final executed control operation accurately reflects the user's true intentions.

[0025] According to exemplary embodiments of this disclosure, users can directly edit based on the sent message that has been filled back into the input box, without having to start editing a new message from scratch, which can effectively reduce repetitive input operations and reduce operational redundancy.

[0026] According to exemplary embodiments of this disclosure, by setting a precise protection mechanism for the inference context, namely through shadow buffer technology, atomic-level snapshots of user-unsubmitted intentions can be achieved. This allows for rapid and comprehensive recovery of the user's input context when AI mistakenly triggers automated processes or tasks are unexpectedly interrupted, eliminating the costs of repetitive input and cognitive reconstruction. Furthermore, the "multi-level resilient interruption logic" provided in this disclosure allows the system to respond to user intentions to terminate streaming inference within milliseconds, enabling timely shutdown of useless LLM inference links. This effectively reduces computational overhead and redundant token consumption, thereby achieving dynamically controllable resource conservation and soft interruption response.

[0027] According to an exemplary embodiment of this disclosure, by displaying a prompt message indicating that the inference task has been interrupted, users can promptly understand the current state of the large language model, facilitating quick adjustments to subsequent model invocation strategies.

[0028] According to exemplary embodiments of this disclosure, by introducing a "time window secondary confirmation" anti-accidental touch mechanism and the implicit guidance of rprompt, the original "one-dimensional and violent" exit semantics can be evolved into "fault-tolerant guidance" semantics, which can effectively reduce the probability of accidentally closing applications in complex workflows and enable the operation experience of AI-assisted terminals to achieve production-grade high robustness.

[0029] According to an exemplary embodiment of this disclosure, by displaying a prompt message indicating that the application will be closed if an interrupt command is received again, a buffer time can be given to the user, allowing them time to confirm whether the interrupt command was accidentally triggered or if they genuinely intend to exit the application. This avoids the situation where the user accidentally triggers an interrupt command but exits the application directly, reducing the probability of accidental application exit.

[0030] According to an exemplary embodiment of this disclosure, if a user triggers an interrupt command while entering content in an input box of an application, it indicates that the user may be dissatisfied with the currently entered content and wants to re-enter new content. Therefore, the input box can be cleared directly at this time, avoiding the tedious process of manually deleting the input box content and reducing operational redundancy.

[0031] According to exemplary embodiments of this disclosure, cleaning up the target process only after determining that the target process has finished executing system commands can achieve flexible termination of the process, thereby effectively avoiding the generation of zombie processes.

[0032] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0033] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.

[0034] Figure 1 This is a schematic diagram illustrating an application-controlled elastic scheduling architecture according to exemplary embodiments of the present disclosure; Figure 2 This is a flowchart illustrating a control method for an application according to an exemplary embodiment of the present disclosure; Figure 3 This is a flowchart illustrating a specific implementation of the control process of an application when an interrupt instruction is obtained in a scenario where a large language model is performing a reasoning task according to an exemplary embodiment of the present disclosure; Figure 4 This is a block diagram illustrating a control device for an application according to an exemplary embodiment of the present disclosure; Figure 5This is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure. Detailed Implementation

[0035] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.

[0036] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following examples do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0037] It should be noted that the phrase "at least one of several items" in this disclosure refers to three parallel cases: "any one of the several items", "a combination of any number of the several items", and "all of the several items". For example, "including at least one of A and B" includes the following three parallel cases: (1) including A; (2) including B; (3) including A and B. Another example is "performing at least one of step one and step two", which means the following three parallel cases: (1) performing step one; (2) performing step two; (3) performing both step one and step two.

[0038] As mentioned earlier, in related technologies, interrupt semantics are often brute-force and simplistic. In AI-driven thinking states, traditional interrupts can easily inadvertently damage the parent process, leading to the loss of session context. Furthermore, the interrupt semantics in these technologies also suffer from deficiencies such as a lack of input context protection and weak ability to prevent accidental touches during high-risk operations.

[0039] Lack of input context protection: When a user is entering a complex prompt, if the input is interrupted by AI-triggered autocorrect or plugin tasks, the original input buffer will usually be overwritten or reset, which will cause workflow interruption.

[0040] High-risk operations have weak protection against accidental touches: Operations such as exiting and clearing all inputs usually take effect instantly, lacking an effective "time window secondary confirmation" mechanism, which makes them very easy to be accidentally triggered in the minimalist AI interaction interface.

[0041] To address the aforementioned problems in related technologies, the application control method, apparatus, device, storage medium, and program product provided in this disclosure can execute corresponding control operations based on the current state of the application upon receiving an interrupt command. This means that the specific control operation to be executed can be flexibly selected according to the current actual scenario. In this way, the terminal environment's response to interrupt commands is dynamic and multi-dimensional, meaning the interrupt semantics are flexible and diverse, ensuring that the final executed control operation accurately reflects the user's true intentions.

[0042] Figure 1 This is a schematic diagram illustrating an application-controlled elastic scheduling architecture according to exemplary embodiments of the present disclosure.

[0043] Reference Figure 1 This elastic scheduling architecture can be centered around an Interruption Manager, and the elastic scheduling in this disclosure can rely on core enumerations and state class objects to implement information flow and strong type constraints: 1. State Machine Enumeration (Shell State): Defines the interactive phases of the Shell lifecycle, including but not limited to: Idle (NORMAL), Inputting (INPUTTING), Exit Pending Confirmation (EXIT_PENDING), In Large Language Model Inference (AI_THINKING), and System Command Execution (COMMAND_EXEC), etc.

[0044] 2. Interrupt Action Enumeration: Defines the action instructions that should be assigned after the state machine is matched, such as, but not limited to: Clear input only (CLEAR_INPUT), Request exit and enter confirmation window (REQUEST_EXIT), and soft interrupt inference (INTERRUPT_AI).

[0045] 3. Prompt Config: This can encapsulate the data structure used for the right-hand prompt (rprompt), including the preset prompt text (message) and the confirmation window duration limit (window_seconds). The confirmation window duration limit can be, but is not limited to, 2.0 seconds.

[0046] For example, in scenarios where the application is in an idle state, a secondary confirmation logic with a time window can be introduced. That is, a window_seconds configuration can be introduced, and the application exit operation will only be performed if SIGINT is triggered twice consecutively within the window period.

[0047] In addition, an rprompt-based guidance feedback mechanism can be introduced. For example, in response to receiving a user's Ctrl+C / Esc command, if the interrupt manager determines that the application is currently idle, a "zero-intrusion bootstrap" can be implemented through a right-hand prompt. For instance, during the aforementioned time window, text such as "Press Ctrl+C again to exit the application" can be displayed; this text is the "right-hand prompt," which can improve fault tolerance transparency while maintaining a clean UI.

[0048] 4. Interrupt Manager Class: This is a central management component that internally maintains the current state (_state), timestamp records (_state_start_time), and a shadow buffer (_Shadow Buffer) for context protection. Furthermore, the interrupt manager can utilize thread locks (threading.Lock) to ensure thread safety during polymorphic switching in high-concurrency asynchronous tasks.

[0049] Shadow buffer backup mechanism: Before the AI ​​Shell issues a large model query (ask_oracle), the system can automatically call save_input_buffer to record the current input in memory. For example, for... Figure 1 The AI_THINKING branch can introduce an automatic input refill mechanism after interruption: when a user terminates ongoing AI thinking with Ctrl+C, the system can automatically detect whether there is any residual content in the shadow buffer. If so, the content can be automatically injected into the application's input box during the next Prompt rendering, achieving "zero-loss recovery" of the workflow.

[0050] 5. State-driven flexible cleanup: In the sandbox evaluation (SANDBOX_EVAL) or command execution (COMMAND_EXEC) state, SIGINT can be mapped to a cancellation operation on the LLM cancellation_token, which can avoid the generation of underlying zombie processes.

[0051] Reference Figure 1In response to receiving the user's Ctrl+C / Esc command, the interrupt manager can determine the current state of the application. For example, the interrupt manager can read the application's current state from the state machine. For instance, as mentioned earlier, the application's state can include, but is not limited to: idle, inputting, large language model inference, and system command execution. Furthermore, each state can correspond to its own control action. For example, when the application is currently in the "large language model inference" state, the corresponding control action could be: "interrupt inference and refill the input box"; when the application is currently in the "idle" state, the corresponding control action could be: "enter the exit confirmation window (2.0s)"; when the application is currently in the "inputting" state, the corresponding control action could be: "clear the current input area"; and when the application is currently in the "system command execution" state, the corresponding control action could be: "softly stop the child process and clean up the callback".

[0052] In addition, prompts can be displayed in the "In Reasoning with Large Language Model" and "Idle" states. For example, in the "In Reasoning with Large Language Model" state, the prompt mainly informs the user that the current reasoning task has been interrupted; in the "Idle" state, the prompt mainly informs the user what further actions they need to take before exiting the application.

[0053] Figure 2 This is a flowchart illustrating a control method for an application according to an exemplary embodiment of the present disclosure, the application may include an interrupt manager and a state machine (shell state).

[0054] Reference Figure 2 In step 201, during the application's execution, the target interrupt instruction input by the user can be obtained through the interrupt manager.

[0055] In this disclosure, fine-grained keyboard bindings can be injected into the prompt_toolkit in the front-end user interface layer to preferentially intercept Keys.ControlC and Keys.Escape, thereby delegating processing authority to the interrupt manager and preventing the operating system's native SIGINT from directly and brutally taking over and killing the Python main process.

[0056] In step 202, in response to the acquired target interrupt instruction, the current state of the application can be read from the state machine through the interrupt manager.

[0057] For example, as mentioned above, the current state of the application may include, but is not limited to: idle state, inputting, exit pending confirmation, large language model inference, system command execution, and other core states.

[0058] In step 203, the interrupt manager can determine the target control action corresponding to the current state of the application based on the current state of the application and the state control table. The interrupt manager can maintain the state control table, which indicates the mapping relationship between preset application states and their corresponding control actions.

[0059] For example, the system can maintain an internal state variable _state in real time. When an interrupt signal arrives, instead of executing a hard-coded exit, it can look up the table and execute the corresponding control action (InterruptAction).

[0060] According to an exemplary embodiment of this disclosure, the aforementioned preset application state may include at least one of the following: the large language model invoked by the application is performing a target inference task, the application is in an idle state, the user is entering content in the application's input box, or the application is currently executing a system command.

[0061] In addition, the control action corresponding to the target inference task being performed by the large language model called by the application can be: interrupt the target inference task and refill the sent content; the control action corresponding to the idle state can be: detect whether the interrupt command is received again within a predetermined time interval; the control action corresponding to the user entering content in the application's input box can be: clear the input box; and the control action corresponding to the system command currently being executed by the application can be: flexibly stop the process and clean up the process.

[0062] In step 204, the interrupt manager can be used to perform target control actions on the application.

[0063] According to exemplary embodiments of this disclosure, the application may further include a shadow buffer that can be used to cache dialogue content of a user interacting with a large language model through the application.

[0064] If the application is currently in a state where the large language model invoked by the application is performing a target inference task, an interruption manager can be used to send an interruption inference instruction to the large language model, causing the large language model to interrupt the target inference task based on the interruption instruction. Furthermore, the interruption manager can also read sent dialogue content from the shadow buffer; this sent dialogue content can be the content sent by the user through the application to the large language model to instruct it to perform the target inference task. Next, the interruption manager can use the read sent dialogue content to populate the application's input boxes.

[0065] For example, suppose a user sends a message to the large language model through an application. However, the user feels there is an error in the message or that some content is missing. In this case, the user can press Ctrl+C. The interrupt manager in the application responds to this Ctrl+C command by instructing the large language model to interrupt the inference process based on the sent message. Furthermore, the interrupt manager can read the sent message from the shadow buffer and populate it back into the application's input box. This allows the user to directly edit the sent message already populated in the input box without having to start editing a new message from scratch, effectively reducing repetitive input and operational redundancy.

[0066] It should be noted that this disclosure can introduce a soft interruption handling (Cancellation Token) mechanism for the AI ​​generation layer: when handling the asynchronous scheduling of AI_THINKING, the INTERRUPT_AI behavior mapping can trigger the llm_session.cancellation_token.cancel method, that is, the CancellationReason.USER_INTERRUPT credential can be distributed to the AI ​​model interface through the network flow, so that the long connection of the background Transmission Control Protocol (TCP) can be securely disconnected, and the server can be actively notified to stop the response, preventing the server from continuing to calculate and generating dirty data due to the client disconnecting. Thus, the cancellation exception thrown by the upper layer can be captured by a special structure and can complete the atomic-level safe exit.

[0067] Thus, this disclosure, by setting up a precise protection mechanism for the inference context—namely, through shadow buffer technology—can achieve atomic-level snapshots of user-unsubmitted intentions. This allows for rapid and comprehensive recovery of the user's input context when AI mistakenly triggers automated processes or tasks are unexpectedly interrupted, eliminating the costs of repetitive input and cognitive reconstruction. Furthermore, the "multi-level elastic interruption logic" provided in this disclosure allows the system to respond to user intentions to terminate streaming inference within milliseconds, enabling the timely shutdown of useless LLM inference links. This effectively reduces computational overhead and redundant token consumption, thereby achieving dynamically controllable resource conservation and soft interrupt response.

[0068] According to exemplary embodiments of this disclosure, a prompt message indicating that the target inference task has been interrupted may also be displayed. In this way, by displaying a prompt message indicating that the inference task has been interrupted, users can promptly understand the current state of the large language model, facilitating quick adjustments to subsequent model invocation strategies.

[0069] According to an exemplary embodiment of this disclosure, when the application is currently in an idle state, the interrupt manager can detect whether an interrupt command is received again within a predetermined time interval. If an interrupt command is received again within the predetermined time interval, the application can be closed; otherwise, if no interrupt command is received again within the predetermined time interval, the application's input fields can be cleared.

[0070] This disclosure introduces a proactive monitoring mechanism for interaction windows based on a daemon thread. Specifically, for critical interaction states with window_seconds constraints (e.g., exit confirmation periods), the system can implement high-frequency state monitoring through an asynchronous sampling thread called refresh_in_background. This mechanism decouples user input listening from state lifecycle management and continuously polls the timestamp counter within the interrupt manager. Once a window timeout is determined, a cross-thread trigger can be used to execute the application-level app.invalidate() redraw instruction, effectively ensuring the immediate hiding of interactive prompts and the automatic degradation and reset of the shell state.

[0071] In this way, by introducing a "time window secondary confirmation" anti-accidental touch mechanism and rprompt's implicit guidance, the original "one-dimensional and violent" exit semantics can be evolved into "fault-tolerant guidance" semantics. This can effectively reduce the probability of accidentally closing applications in complex workflows and enable the AI-assisted terminal to achieve production-grade high robustness in its operating experience.

[0072] According to exemplary embodiments of this disclosure, a prompt message indicating that the application will be closed if an interrupt command is received again within a predetermined time interval can also be displayed. By displaying this prompt, the user is given a buffer period to confirm whether the interrupt command was accidentally triggered or if the user genuinely intends to exit the application. This avoids situations where the user accidentally triggers an interrupt command but directly exits the application, reducing the probability of accidental application exit.

[0073] According to an exemplary embodiment of this disclosure, when the application is currently in a state where the user is entering content in the application's input box, the input box can be cleared via the interrupt manager. Thus, if an interrupt command is triggered while the user is entering content in the application's input box, it indicates that the user may be dissatisfied with the current input and wants to re-enter new content. Therefore, the input box can be cleared directly at this time, avoiding the tedious process of manually deleting the input box content and reducing operational redundancy.

[0074] According to an exemplary embodiment of this disclosure, when the application is currently executing a system command, the target process in the application used to execute the system command can be monitored through an interrupt manager. If it is determined that the target process has finished executing the system command, the target process can be cleaned up.

[0075] For example, the system command currently being executed by the application could be a file write command. If an interrupt command is received from the user while the file write process within the application is performing its write task, the execution status of that process can be monitored. Only after confirming that the file write process has completed its task should it be cleaned up. This method of cleaning up the target process only after confirming that it has finished executing the system command allows for flexible process termination, effectively preventing the creation of zombie processes.

[0076] Figure 3 This is a flowchart illustrating a specific implementation of the control process of an application when an interrupt instruction is obtained in a scenario where a large language model is performing a reasoning task according to an exemplary embodiment of the present disclosure.

[0077] Reference Figure 3The application's control process primarily involves data interaction between the interrupt manager, state machine, large language model engine, and shadow buffer. As mentioned earlier, the interrupt manager is mainly used to monitor user-input interrupt commands, determine the current state of the application, and determine and execute control actions that match the current state of the application; the state machine is mainly used to store the application's current state; the large language model engine is mainly used to execute inference services, and this large language model engine can be invoked by the application; the shadow buffer is mainly used to cache the dialogue content between the user and the large language model through the application.

[0078] First, during the backup phase: at any AI trigger point not actively submitted by the user (e.g., automatic error correction suggestions), the system can mirror and back up the characters currently entered by the user to the interrupt manager.

[0079] Then, a state transition can be performed: the system can mark the current state as AI_THINKING. Furthermore, the keyboard listening logic needs to change; the user's Ctrl+C input can no longer be transmitted to the operating system, but can instead be captured by the state machine (shell).

[0080] Next, a polymorphic response can be executed: if the user presses Ctrl+C, the interrupt manager can recognize that the current state is AI_THINKING, and the trigger_interrupt callback function can be executed.

[0081] Then, the inference task of the large language model can be cancelled: the callback function can trigger the cancellation token of LLMSession to safely close the stream connection.

[0082] Next, a seamless refactoring can be performed: when the Shell loop restarts, it detects that `set_restore_input` is True, and can then call `get_and_clear_input_buffer` to inject the backup content into the `default_text` parameter of the next `prompt_toolkit`. At this point, the user perceives: "AI was interrupted, and my input is back."

[0083] Specifically, referring to Figure 3 In step 301, during the application's operation, the user can enter "Analyze file..." in the application's input box.

[0084] In step 302, the state machine can cache (save_input_buffer(“Analyze file…”) the “Analyze file…” input by the user in the application’s input box to the shadow buffer.

[0085] In step 303, the state machine can send the application's state to the interrupt manager as: in large language model inference (set_state(AI_THINKING)).

[0086] In step 304, the state machine can send a request for inference stream to the large language model engine, and the large language model engine can then return "thinking" to the state machine.

[0087] In step 305, if the user feels that the large language model is too verbose, they can enter the Ctrl+C command.

[0088] In step 306, the interrupt manager responds to the user's input of the Ctrl+C command and determines that the current state of the application is: in large language model inference.

[0089] In step 307, the interrupt manager notifies the large language model engine to cancel the inference session (cancellation_token.cancel).

[0090] In step 308, the interrupt manager sends the current state of the application to the state machine as: idle state (set_state(NORMAL)).

[0091] In step 309, the state machine requests the previously cached content from the shadow buffer, and then the shadow buffer can return the backup content to the state machine, that is, the content cached in step 302: "Analyze file..." can be returned to the state machine.

[0092] In step 3010, the state machine can backfill the backup content returned by the shadow buffer, "Analyze file...", into the input box of the application. This allows the user to directly edit the content backfilled into the input box without having to start editing new content from scratch. This effectively reduces repetitive input operations and lowers operational redundancy.

[0093] This disclosure aims to address issues such as "accidental exit, input data loss, and system state chaos" caused by semantic conflicts in interrupt signals when a terminal is processing asynchronous tasks. The core objective is to implement an intelligent interrupt protection mechanism that is "sensitive to the interaction context." Specifically, this disclosure provides "web-like front-end" input security guarantees while maintaining full compatibility with native terminal operating habits through an "asynchronous hook (Key Hook) + input buffer isolation" method. Furthermore, it does not rely on any graphics library, making it a superior technical approach for scenarios where CLI and AI are deeply integrated.

[0094] Figure 4 This is a block diagram illustrating a control device 400 for an application according to an exemplary embodiment of the present disclosure, the application which may include an interrupt manager and a state machine.

[0095] Reference Figure 4 The control device 400 of the application may include an interrupt instruction acquisition module 401, a status reading module 402, an action determination module 403, and an action execution module 404.

[0096] During application execution, the interrupt instruction acquisition module 401 can acquire the target interrupt instruction input by the user through the interrupt manager.

[0097] In response to the acquired target interrupt instruction, the status reading module 402 can read the current state of the application from the state machine through the interrupt manager.

[0098] The action determination module 403 can determine the target control action corresponding to the current state of the application based on the current state of the application and the state control table through the interrupt manager. The interrupt manager can maintain the state control table, which can indicate the mapping relationship between preset application states and their corresponding control actions.

[0099] According to an exemplary embodiment of this disclosure, the aforementioned preset application state may include at least one of the following: the large language model invoked by the application is performing a target inference task, the application is in an idle state, the user is entering content in the application's input box, or the application is currently executing a system command.

[0100] In addition, the control action corresponding to the target inference task being performed by the large language model called by the application can be: interrupt the target inference task and refill the sent content; the control action corresponding to the idle state can be: detect whether the interrupt command is received again within a predetermined time interval; the control action corresponding to the user entering content in the application's input box can be: clear the input box; and the control action corresponding to the system command currently being executed by the application can be: flexibly stop the process and clean up the process.

[0101] The action execution module 404 can execute target control actions for the application through the interrupt manager.

[0102] According to exemplary embodiments of this disclosure, the application may further include a shadow buffer that can be used to cache dialogue content of a user interacting with a large language model through the application.

[0103] When the application is currently in a state where the large language model invoked by the application is performing a target inference task, the action execution module 404 can send an interrupt inference instruction to the large language model through the interrupt manager, causing the large language model to interrupt the target inference task based on the interrupt inference instruction. Furthermore, the action execution module 404 can also read sent dialogue content from the shadow buffer through the interrupt manager. This sent dialogue content can be the dialogue content sent by the user through the application to the large language model to instruct the large language model to perform the target inference task. Next, the action execution module 404 can use the interrupt manager to populate the input boxes in the application with the read sent dialogue content.

[0104] According to an exemplary embodiment of this disclosure, the control device 400 of the application described above may further include an interruption prompt information display module. This interruption prompt information display module can display a prompt message indicating that the target inference task has been interrupted. In this way, by displaying a prompt message indicating that the inference task has been interrupted, the user can promptly understand the current state of the large language model, facilitating quick adjustment of subsequent model invocation strategies.

[0105] According to an exemplary embodiment of this disclosure, when the application is currently in an idle state, the action execution module 404 can detect whether an interrupt command is received again within a predetermined time interval through the interrupt manager. If an interrupt command is received again within the predetermined time interval, the action execution module 404 can control the application to close; otherwise, that is, if no interrupt command is received again within the predetermined time interval, the action execution module 404 can clear the application's input box.

[0106] According to an exemplary embodiment of this disclosure, the control device 400 for the application described above may further include a shutdown prompt information display module. This shutdown prompt information display module can display a prompt message indicating that the application will be closed if an interrupt command is received again within a predetermined time interval.

[0107] According to an exemplary embodiment of this disclosure, when the current state of the application is that the user is entering content in the application's input box, the action execution module 404 can clear the input box through the interrupt manager.

[0108] According to an exemplary embodiment of this disclosure, when the application is currently executing a system command, the action execution module 404 can monitor the target process in the application that is executing the system command through the interrupt manager. If it is determined that the target process has finished executing the system command, the action execution module 404 can clean up the target process.

[0109] Figure 5 This is a block diagram illustrating an electronic device 500 according to an exemplary embodiment of the present disclosure.

[0110] Reference Figure 5 The electronic device 500 includes at least one memory 501 and at least one processor 502. The at least one memory 501 stores instructions that, when executed by the at least one processor 502, execute a control method for an application according to an exemplary embodiment of the present disclosure.

[0111] As an example, electronic device 500 may be a PC, tablet, personal digital assistant, smartphone, or other device capable of executing the aforementioned instructions. Here, electronic device 500 is not necessarily a single electronic device, but may be a collection of any devices or circuits capable of executing the aforementioned instructions (or instruction sets) individually or in combination. Electronic device 500 may also be part of an integrated control system or system manager, or may be configured to interconnect with a portable electronic device locally or remotely (e.g., via wireless transmission) through an interface.

[0112] In electronic device 500, processor 502 may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. By way of example and not limitation, processor may also include analog processors, digital processors, microprocessors, multi-core processors, processor arrays, network processors, etc.

[0113] The processor 502 can execute instructions or code stored in the memory 501, which can also store data. Instructions and data can also be sent and received over a network via a network interface device, which can employ any known transmission protocol.

[0114] The memory 501 may be integrated with the processor 502, for example, by arranging RAM or flash memory within an integrated circuit microprocessor. Alternatively, the memory 501 may include a separate device, such as an external disk drive, a storage array, or other storage device usable by any database system. The memory 501 and the processor 502 may be operatively coupled, or may communicate with each other, for example, via I / O ports, network connections, etc., enabling the processor 502 to read files stored in the memory.

[0115] In addition, electronic device 500 may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of electronic device 500 can be interconnected via a bus and / or network.

[0116] According to exemplary embodiments of this disclosure, a computer-readable storage medium may also be provided, which, when executed by a processor of an electronic device, enables the electronic device to perform the control method of the aforementioned application program. Examples of computer-readable storage media include: read-only memory (ROM), random access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disc storage, hard disk drive (HDD), solid-state drive (SSD), card storage (such as multimedia cards, secure digital (SD) cards, or ultra-fast digital (XD) cards), magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device, hard disk, solid-state drive, and any other device configured to store a computer program and any associated data, data files, and data structures in a non-transitory manner and to provide the computer program and any associated data, data files, and data structures to a processor or computer so that the processor or computer can execute the computer program. The computer program in the aforementioned computer-readable storage medium can run in an environment deployed in computer devices such as clients, hosts, agent devices, servers, etc. Furthermore, in one example, the computer program and any associated data, data files, and data structures are distributed across a networked computer system, such that the computer program and any associated data, data files, and data structures are stored, accessed, and executed in a distributed manner through one or more processors or computers.

[0117] According to exemplary embodiments of the present disclosure, a computer program product may also be provided, including a computer program that, when executed by a processor, implements a control method for an application according to the present disclosure.

[0118] According to the control method, apparatus, device, storage medium, and program product of this disclosure, upon receiving an interrupt command, corresponding control operations can be executed based on the current state of the application. This means that the specific control operation to be executed can be flexibly selected based on the current actual scenario. In this way, the terminal environment's response to interrupt commands is dynamic and multi-dimensional, meaning the interrupt semantics are flexible and diverse, ensuring that the final executed control operation accurately reflects the user's true intentions.

[0119] According to exemplary embodiments of this disclosure, users can directly edit based on the sent message that has been filled back into the input box, without having to start editing a new message from scratch, which can effectively reduce repetitive input operations and reduce operational redundancy.

[0120] According to exemplary embodiments of this disclosure, by setting a precise protection mechanism for the inference context, namely through shadow buffer technology, atomic-level snapshots of user-unsubmitted intentions can be achieved. This allows for rapid and comprehensive recovery of the user's input context when AI mistakenly triggers automated processes or tasks are unexpectedly interrupted, eliminating the costs of repetitive input and cognitive reconstruction. Furthermore, the "multi-level resilient interruption logic" provided in this disclosure allows the system to respond to user intentions to terminate streaming inference within milliseconds, enabling timely shutdown of useless LLM inference links. This effectively reduces computational overhead and redundant token consumption, thereby achieving dynamically controllable resource conservation and soft interruption response.

[0121] According to an exemplary embodiment of this disclosure, by displaying a prompt message indicating that the inference task has been interrupted, users can promptly understand the current state of the large language model, facilitating quick adjustments to subsequent model invocation strategies.

[0122] According to exemplary embodiments of this disclosure, by introducing a "time window secondary confirmation" anti-accidental touch mechanism and the implicit guidance of rprompt, the original "one-dimensional and violent" exit semantics can be evolved into "fault-tolerant guidance" semantics, which can effectively reduce the probability of accidentally closing applications in complex workflows and enable the operation experience of AI-assisted terminals to achieve production-grade high robustness.

[0123] According to an exemplary embodiment of this disclosure, by displaying a prompt message indicating that the application will be closed if an interrupt command is received again, a buffer time can be given to the user, allowing them time to confirm whether the interrupt command was accidentally triggered or if they genuinely intend to exit the application. This avoids the situation where the user accidentally triggers an interrupt command but exits the application directly, reducing the probability of accidental application exit.

[0124] According to an exemplary embodiment of this disclosure, if a user triggers an interrupt command while entering content in an input box of an application, it indicates that the user may be dissatisfied with the currently entered content and wants to re-enter new content. Therefore, the input box can be cleared directly at this time, avoiding the tedious process of manually deleting the input box content and reducing operational redundancy.

[0125] According to exemplary embodiments of this disclosure, cleaning up the target process only after determining that the target process has finished executing system commands can achieve flexible termination of the process, thereby effectively avoiding the generation of zombie processes.

[0126] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.

[0127] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A method for controlling an application, characterized in that, The application includes an interrupt manager and a state machine, and the control method includes: During the operation of the application, the target interrupt command input by the user is obtained through the interrupt manager; In response to the target interrupt instruction, the interrupt manager reads the current state of the application from the state machine; The interrupt manager determines the target control action corresponding to the current state of the application based on the current state of the application and the state control table. The interrupt manager maintains the state control table, which indicates the mapping relationship between preset application states and corresponding control actions. The interrupt manager executes the target control action for the application.

2. The control method as described in claim 1, characterized in that, The preset application state includes at least one of the following: the large language model invoked by the application is performing a target inference task, the application is in an idle state, the user is entering content in the input box of the application, and the application is currently executing a system command. Among them, the control action corresponding to the large language model called by the application performing the target inference task is to interrupt the target inference task and refill the sent content; The control action corresponding to the idle state is to detect whether an interrupt command is received again within a predetermined time interval; The control action corresponding to the user entering content in the input box of the application is to clear the input box; The control action corresponding to the system command currently being executed by the application is to flexibly stop the process and clean it up.

3. The control method as described in claim 2, characterized in that, The application also includes a shadow buffer for caching dialogue content between the user and the large language model through the application; Wherein, when the current state of the application is that the large language model invoked by the application is performing a target inference task, the step of performing the target control action on the application through the interrupt manager includes: The interrupt manager sends an interrupt inference instruction to the large language model, so that the large language model interrupts the target inference task based on the interrupt inference instruction. The interrupt manager reads the sent dialogue content from the shadow buffer, wherein the sent dialogue content is the dialogue content sent by the user through the application to the large language model to instruct the large language model to perform the target reasoning task; The interrupt manager reads the content of the sent conversation and fills it back into the input box of the application.

4. The control method as described in claim 3, characterized in that, Also includes: The system displays a message indicating that the target inference task has been interrupted.

5. The control method as described in claim 2, characterized in that, When the application is currently in the idle state, the execution of the target control action for the application via the interrupt manager includes: The interrupt manager detects whether the interrupt command is received again within the predetermined time interval; If the interrupt command is received again within the predetermined time interval, the application will be shut down. Otherwise, clear the input box of the application.

6. The control method as described in claim 5, characterized in that, Also includes: The system displays a message indicating that the application will be closed if the interrupt command is received again within the predetermined time interval.

7. The control method as described in claim 2, characterized in that, When the application is currently in a state where the user is entering content in the application's input box, the execution of the target control action for the application through the interrupt manager includes: The input box is cleared by the interrupt manager.

8. The control method as described in claim 2, characterized in that, When the application is currently executing a system command, the step of executing the target control action for the application through the interrupt manager includes: The interrupt manager monitors the target process in the application used to execute the system commands. Once it is determined that the target process has finished executing the system command, the target process is cleaned up.

9. A control device for an application, characterized in that, The application includes an interrupt manager and a state machine, and the control device includes: The interrupt instruction acquisition module is configured to acquire the target interrupt instruction input by the user through the interrupt manager during the operation of the application. The state reading module is configured to read the current state of the application from the state machine through the interrupt manager in response to the target interrupt instruction. The action determination module is configured to determine the target control action corresponding to the current state of the application based on the current state of the application and the state control table through the interrupt manager, wherein the interrupt manager maintains the state control table, and the state control table indicates the mapping relationship between preset application states and corresponding control actions; The action execution module is configured to perform the target control action on the application via the interrupt manager.

10. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the control method of the application as described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the control method of the application program as described in any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the control method of the application program as described in any one of claims 1 to 8.