Add support for optional custom instructions in `AddTaskHeaderCommand`
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 18 Jan 2026 20:29:31 +0000 (22:29 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 18 Jan 2026 20:29:31 +0000 (22:29 +0200)
src/main/java/eu/svjatoslav/alyverkko_cli/commands/AddTaskHeaderCommand.java

index d6dc0c7..e108ce0 100644 (file)
@@ -1,4 +1,5 @@
 package eu.svjatoslav.alyverkko_cli.commands;
+
 import eu.svjatoslav.alyverkko_cli.Command;
 import eu.svjatoslav.alyverkko_cli.configuration.Configuration;
 import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper;
@@ -13,8 +14,9 @@ import static eu.svjatoslav.alyverkko_cli.Utils.fileHasToComputeMarker;
 
 /**
  * This command recursively adds a TOCOMPUTE header to all non-hidden files in the current directory
- * that do not already have one. It prompts the user for skill, model, and priority values,
- * validates their existence in the configuration, and then processes the files accordingly.
+ * that do not already have one. It prompts the user for skill, model, priority values,
+ * and optional custom processing instructions, validates their existence in the configuration,
+ * and then processes the files accordingly.
  * <p>
  * Usage:
  * <pre>
@@ -24,9 +26,10 @@ import static eu.svjatoslav.alyverkko_cli.Utils.fileHasToComputeMarker;
  * - Skill name (must exist in skills directory)
  * - Model alias (must exist in configuration models)
  * - Priority value (integer, defaults to 0)
+ * - Custom processing instructions (optional, multi-line input; press Enter twice to finish)
  * <p>
  * After validation, it will process all non-hidden files in the current directory and subdirectories,
- * adding the TOCOMPUTE header at the beginning of files that don't already have one.
+ * adding the TOCOMPUTE header followed by custom instructions (if provided) and the original content.
  */
 public class AddTaskHeaderCommand implements Command {
 
@@ -36,8 +39,8 @@ public class AddTaskHeaderCommand implements Command {
     }
 
     /**
-     * Executes the addheader command. Loads configuration, prompts user for skill, model, and priority,
-     * validates them, and processes all files in the current directory recursively.
+     * Executes the addheader command. Loads configuration, prompts user for skill, model, priority,
+     * and optional custom instructions, validates them, and processes all files in the current directory recursively.
      *
      * @param cliArguments command-line arguments (unused in this command)
      * @throws IOException if file operations fail
@@ -57,8 +60,21 @@ public class AddTaskHeaderCommand implements Command {
         String model = promptForModel(scanner, config);
         int priority = promptForPriority(scanner);
 
+        // Prompt for custom processing instructions
+        System.out.println("\nEnter custom processing instructions (press Enter twice to finish):");
+        StringBuilder customInstructions = new StringBuilder();
+        String line;
+        while (true) {
+            line = scanner.nextLine();
+            // Break on empty line or EOF
+            if (line == null || line.trim().isEmpty()) {
+                break;
+            }
+            customInstructions.append(line).append("\n");
+        }
+
         System.out.println("\nProcessing files in current directory...");
-        processDirectory(new File("."), skill, model, priority);
+        processDirectory(new File("."), skill, model, priority, customInstructions.toString());
         System.out.println("\nProcessing complete!");
     }
 
@@ -140,47 +156,47 @@ public class AddTaskHeaderCommand implements Command {
     /**
      * Recursively processes all files in a directory, skipping hidden files.
      *
-     * @param dir     Directory to process
-     * @param skill   Skill name to include in TOCOMPUTE header
-     * @param model   Model alias to include in TOCOMPUTE header
-     * @param priority Priority value to include in TOCOMPUTE header
+     * @param dir              Directory to process
+     * @param skill            Skill name to include in TOCOMPUTE header
+     * @param model            Model alias to include in TOCOMPUTE header
+     * @param priority         Priority value to include in TOCOMPUTE header
+     * @param customInstructions Optional custom processing instructions to prepend after header
      * @throws IOException if file operations fail
      */
-    private void processDirectory(File dir, String skill, String model, int priority) throws IOException {
+    private void processDirectory(File dir, String skill, String model, int priority, String customInstructions) throws IOException {
         File[] files = dir.listFiles();
         if (files == null) return;
 
         for (File file : files) {
             if (file.isDirectory()) {
-                processDirectory(file, skill, model, priority);
+                processDirectory(file, skill, model, priority, customInstructions);
             } else if (file.isFile() && !file.getName().startsWith(".")) {
-                processFile(file, skill, model, priority);
+                processFile(file, skill, model, priority, customInstructions);
             }
         }
     }
 
     /**
-     * Processes a single file by adding TOCOMPUTE header if not already present.
+     * Processes a single file by adding TOCOMPUTE header with optional custom instructions.
      *
-     * @param file    File to process
-     * @param skill   Skill name for TOCOMPUTE header
-     * @param model   Model alias for TOCOMPUTE header
-     * @param priority Priority value for TOCOMPUTE header
+     * @param file               File to process
+     * @param skill              Skill name for TOCOMPUTE header
+     * @param model              Model alias for TOCOMPUTE header
+     * @param priority           Priority value for TOCOMPUTE header
+     * @param customInstructions Optional custom processing instructions to insert after header
      * @throws IOException if file operations fail
      */
-    private void processFile(File file, String skill, String model, int priority) throws IOException {
-
+    private void processFile(File file, String skill, String model, int priority, String customInstructions) throws IOException {
         if (fileHasToComputeMarker(file)) {
             System.out.println("Skipped (already has header): " + file.getAbsolutePath());
             return;
         }
 
         String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
-        String newContent = String.format("TOCOMPUTE: skill=%s model=%s priority=%d\n%s", skill, model, priority, content);
+        String header = String.format("TOCOMPUTE: skill=%s model=%s priority=%d\n", skill, model, priority);
+        String newContent = header + customInstructions + content;
 
         Files.write(file.toPath(), newContent.getBytes(StandardCharsets.UTF_8));
         System.out.println("Added header: " + file.getAbsolutePath());
     }
-
-
 }