Files
meeting-assistant/MeetingAssistant/Workflow/WorkflowRulesEditorInstructionBuilder.cs
T
codex 250d3b7a1e
PR and Push Build/Test / build-and-test (push) Successful in 16m43s
Generalize settings and logs assistant
2026-05-30 12:57:51 +02:00

80 lines
5.8 KiB
C#

using Microsoft.Extensions.Options;
namespace MeetingAssistant.Workflow;
public interface IWorkflowRulesEditorInstructionBuilder
{
Task<string> BuildAsync(MeetingAssistantOptions options, CancellationToken cancellationToken);
}
public sealed class WorkflowRulesEditorInstructionBuilder : IWorkflowRulesEditorInstructionBuilder
{
private const string DefaultPrompt = """
You are the Meeting Assistant settings and logs assistant.
Your purpose is to help operate Meeting Assistant locally: edit the configured local workflow rules YAML file, manage the local speaker identity database, inspect and update appsettings configuration, and read application logs.
Use the read_rules, search, and write_rules tools for workflow rules. Do not ask for or modify unrelated files.
Read the existing rules before making changes unless the user explicitly asks to replace the whole file.
write_rules appends by default. Pass replace_file=true only when you intentionally replace the complete rules file.
Preserve valid YAML, keep personal/local rules in the configured ignored rules file, and keep changes minimal.
When writing rules, prefer existing rule style and names.
Use read_config_docs before explaining or changing configuration settings unless the setting is already clear from the current conversation.
Use read_config before write_config. write_config replaces the complete appsettings JSON file and must preserve valid JSON. The appsettings file stores environment variable names and local paths, not secret values.
Use read_logs and search_logs to inspect application behavior. Prefer search_logs for known errors or keywords and read_logs tailing for recent startup or runtime context.
Use search_spec and read_spec_file to inspect the OpenSpec product requirements before making behavior claims or configuration changes that depend on intended behavior.
Use list_projects, list_projectfiles, read_projectfile, write_projectfile, and search_projects for project knowledge files under the configured projects folder. These tools are intentionally scoped to existing project folders.
Use create_project when the user wants a new project folder. Prefer seed=recommended unless the user explicitly asks for an empty project or provides AGENTS.md content directly.
Use search_identities and read_identity before changing identities unless the user gives an exact identity id.
Prefer updating identities by id, not by guessed name. If a user asks about names, search first and confirm ambiguity in your final response.
For identity merges, merge the duplicate/source identity into the identity that should remain as target.
Use list_identity_samples before playing, reading, or deleting samples. Use queue_play_identity_sample to let the user hear a sample; do not claim you heard it yourself.
Use read_identity_sample only when the raw base64 WAV is actually useful; prefer list_identity_samples for ordinary inspection.
Delete identities or samples only when the user clearly asked for deletion or cleanup.
Explain the final change briefly after the tools finish.
""";
private readonly ILogger<WorkflowRulesEditorInstructionBuilder> logger;
public WorkflowRulesEditorInstructionBuilder(ILogger<WorkflowRulesEditorInstructionBuilder> logger)
{
this.logger = logger;
}
public async Task<string> BuildAsync(MeetingAssistantOptions options, CancellationToken cancellationToken)
{
var editorOptions = options.WorkflowRulesEditor.ToEffectiveAgentOptions(options.Agent);
var configuredPrompt = string.IsNullOrWhiteSpace(editorOptions.InitialPrompt)
? DefaultPrompt
: editorOptions.InitialPrompt!;
var rulesPath = WorkflowRulesPathResolver.Resolve(options.Automation.RulesPath) ?? "<not configured>";
var docs = await ReadWorkflowDocsAsync(cancellationToken);
return configuredPrompt.Trim() + Environment.NewLine + Environment.NewLine +
$"Configured workflow rules file: {rulesPath}" + Environment.NewLine + Environment.NewLine +
"Configuration tools can read and replace the local appsettings JSON file. Use read_config_docs for the configuration reference." + Environment.NewLine + Environment.NewLine +
"Log tools can read and search the current application-owned log file and four rotated older files under the temp log folder." + Environment.NewLine + Environment.NewLine +
"Spec tools can search and read copied OpenSpec markdown files from openspec/specs." + Environment.NewLine + Environment.NewLine +
"Project tools can create project folders and read, write, list, and search files in configured projects." + Environment.NewLine + Environment.NewLine +
"Speaker identity tools can search/list/read/create/update/delete/merge identities, list/read/delete identity samples, and queue a sample for local playback." + Environment.NewLine + Environment.NewLine +
"Workflow rules reference documentation:" + Environment.NewLine +
"```markdown" + Environment.NewLine +
docs.Trim() + Environment.NewLine +
"```";
}
private async Task<string> ReadWorkflowDocsAsync(CancellationToken cancellationToken)
{
foreach (var path in RuntimeContentLocator.CandidateDocumentationPaths("meeting-workflow-engine.md"))
{
if (File.Exists(path))
{
return await File.ReadAllTextAsync(path, cancellationToken);
}
}
logger.LogWarning("Workflow rules editor could not find docs/meeting-workflow-engine.md for its prompt");
return "Workflow documentation file docs/meeting-workflow-engine.md was not available at runtime.";
}
}