Merge pull request 'Add -P flag to read prompt from file' (#40) from feature/read-from-file into master

Reviewed-on: https://192.168.8.63/git/darthrubik/drharness/pulls/40
This commit was merged in pull request #40.
This commit is contained in:
2026-07-22 09:10:06 -05:00
4 changed files with 65 additions and 1 deletions
+1
View File
@@ -75,6 +75,7 @@ configuration.
* `-s <name>`: Manually constrain the harness to a specific subset of skills (can be specified multiple times)
* `-i <path>`: Image file to attach to the prompt (can be specified multiple times)
* `-m <prompt>`: The user prompt to send to the agent.
* `-P <file>`: Read the prompt from a file instead of the command line.
* `-M <model>`: Override the Ollama model (e.g., `mistral`, `llama3`).
## ✍️ Editor Integration
+15 -1
View File
@@ -129,6 +129,7 @@ int main(int argc, char** argv) {
char const* file_to_open = nullptr;
std::string auto_temp_file; // Path to auto-generated temp file (if any)
char const* prompt = nullptr;
char const* prompt_file = nullptr;
bool start_new = false;
bool list_models = false;
char const* print_file = nullptr;
@@ -166,6 +167,11 @@ int main(int argc, char** argv) {
consume_arg();
prompt = consume_arg();
}
else if (argv[0] == std::string("-P"))
{
consume_arg();
prompt_file = consume_arg();
}
else if (argv[0] == std::string("-M"))
{
consume_arg();
@@ -277,6 +283,7 @@ int main(int argc, char** argv) {
<< " -i <path> Image file to attach (can be specified multiple times)\n"
<< " -n Start a new conversation (auto-generates temp file if -F not specified)\n"
<< " -m <prompt> Prompt message (required)\n"
<< " -P <file> Read prompt from file\n"
<< " -M <model> Ollama model name\n"
<< " -f Open editor with full history (requires -F)\n"
<< " -l List available tools\n"
@@ -539,7 +546,14 @@ int main(int argc, char** argv) {
std::string final_prompt;
if (prompt) {
if (prompt_file) {
std::ifstream pf(prompt_file);
if (!pf.is_open()) {
std::cerr << "Error: Cannot open prompt file " << prompt_file << "\n";
return 1;
}
final_prompt = std::string((std::istreambuf_iterator<char>(pf)), std::istreambuf_iterator<char>());
} else if (prompt) {
final_prompt = prompt;
} else {
final_prompt = expect_or_exit(run_editor(harness.serialize(), full_history));
+1
View File
@@ -24,6 +24,7 @@ add_dr_test(test_tool_read_multi_modal)
# Add feature validation tests
add_dr_test(test_tool_restrictions)
add_dr_test(test_n_flag)
add_dr_test(test_prompt_file)
add_dr_test(test_load_chat)
add_dr_test(process_reasoning)
add_dr_test(test_skill_scanner)
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
# test_prompt_file.sh - Validates the -P flag reads prompt from file
# Test 1: Basic prompt file reading
echo "This is my prompt from a file" > prompt.txt
be_done 'Response received' | "${DRHARNESS}" -F chat.json -n -P prompt.txt -d
# Verify the prompt from the file was stored in the chat history
STORED_PROMPT=$(dr_result chat.json 0)
if [ "${STORED_PROMPT}" != "This is my prompt from a file" ]; then
echo "FAIL: prompt_file - prompt not read correctly"
echo "Expected: 'This is my prompt from a file'"
echo "Got: '${STORED_PROMPT}'"
exit 1
fi
# Test 2: Multi-line prompt file
cat > multiline_prompt.txt << 'PROMPT'
Line 1
Line 2
Line 3
PROMPT
be_done 'Multi-line response' | "${DRHARNESS}" -F chat2.json -n -P multiline_prompt.txt -d
# Verify multi-line prompt was stored correctly
STORED_PROMPT=$(dr_result chat2.json 0)
EXPECTED_MULTILINE="Line 1
Line 2
Line 3"
if [ "${STORED_PROMPT}" != "${EXPECTED_MULTILINE}" ]; then
echo "FAIL: prompt_file multiline - prompt not read correctly"
echo "Expected:"
echo "${EXPECTED_MULTILINE}"
echo "Got:"
echo "${STORED_PROMPT}"
exit 1
fi
# Test 3: Non-existent file should fail
if "${DRHARNESS}" -F chat3.json -n -P nonexistent.txt -d < /dev/null 2>stderr_output; then
echo "FAIL: prompt_file nonexistent - should have failed"
cat stderr_output
exit 1
fi
echo "PASS: prompt_file"