Public Access
86 lines
7.2 KiB
C#
86 lines
7.2 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 list_recent_summaries, read_summary, read_transcript, read_meeting_note, read_context, and the matching search tools when the user wants help post-processing meeting notes or investigating past meeting artifacts.
|
|
Prefer list_recent_summaries first when the user refers to recent meetings without naming an exact file.
|
|
Use the matching write_summary, write_transcript, write_meeting_note, write_context, and *_frontmatter tools only to repair or post-process meeting artifacts the user asked you to change. Prefer the frontmatter-specific tools when only metadata needs repair.
|
|
Use get_health, get_recording_status, diagnose_current_meeting, merge_recent_speaker_identities, reload_workflow_configuration, diagnose_asr_transcribe_file, and diagnose_asr_diarize_file for diagnostics that would otherwise require local HTTP endpoints.
|
|
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 +
|
|
"Meeting artifact tools can list recent summaries and read/search/write summaries, transcripts, meeting notes, and assistant context files for note post-processing and repair. Prefer frontmatter-specific write tools for metadata-only fixes." + Environment.NewLine + Environment.NewLine +
|
|
"Diagnostic tools mirror the local health, recording status, Outlook metadata, speaker identity merge, workflow reload, and ASR diagnostic endpoints without requiring HTTP." + Environment.NewLine + Environment.NewLine +
|
|
"Speaker identity tools can search/list/read/update/delete/merge identities, refuse sampleless identity creation, list/read/delete identity samples, and queue a sample for local playback. Do not delete the last sample from an identity; delete the identity instead." + 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.";
|
|
}
|
|
|
|
}
|