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;
/**
* 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>
* - 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 {
}
/**
- * 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
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!");
}
/**
* 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());
}
-
-
}