From c8187ab6c0022276d9736be192f59c0ed304539c Mon Sep 17 00:00:00 2001 From: Qi Pan <43341456+Pan-Qi@users.noreply.github.com> Date: Tue, 21 Jul 2026 20:12:14 +1000 Subject: [PATCH 1/3] AI Custom Code agent --- .github/agents/custom-code.agent.md | 28 ++ .../instructions/agent-safety.instructions.md | 13 + .../instructions/custom-code.instructions.md | 23 ++ .github/prompts/opsx-apply.prompt.md | 153 +++++++++ .github/prompts/opsx-archive.prompt.md | 157 ++++++++++ .github/prompts/opsx-explore.prompt.md | 171 +++++++++++ .github/prompts/opsx-propose.prompt.md | 106 +++++++ .github/prompts/opsx-sync.prompt.md | 140 +++++++++ .github/prompts/opsx-update.prompt.md | 78 +++++ .../SKILL.md | 275 +++++++++++++++++ .../skills/common-custom-code-router/SKILL.md | 137 +++++++++ .../SKILL.md | 244 +++++++++++++++ .../SKILL.md | 239 +++++++++++++++ .../common-live-test-from-help/SKILL.md | 49 +++ .../references/live-test-template.md | 87 ++++++ .github/skills/openspec-apply-change/SKILL.md | 161 ++++++++++ .../skills/openspec-archive-change/SKILL.md | 118 +++++++ .github/skills/openspec-explore/SKILL.md | 290 ++++++++++++++++++ .github/skills/openspec-propose/SKILL.md | 114 +++++++ .github/skills/openspec-sync-specs/SKILL.md | 148 +++++++++ .../skills/openspec-update-change/SKILL.md | 86 ++++++ .gitignore | 4 + doc/ai_custom_code.md | 78 +++++ openspec/changes/.gitkeep | 0 openspec/config.yaml | 37 +++ openspec/specs/.gitkeep | 0 26 files changed, 2936 insertions(+) create mode 100644 .github/agents/custom-code.agent.md create mode 100644 .github/instructions/agent-safety.instructions.md create mode 100644 .github/instructions/custom-code.instructions.md create mode 100644 .github/prompts/opsx-apply.prompt.md create mode 100644 .github/prompts/opsx-archive.prompt.md create mode 100644 .github/prompts/opsx-explore.prompt.md create mode 100644 .github/prompts/opsx-propose.prompt.md create mode 100644 .github/prompts/opsx-sync.prompt.md create mode 100644 .github/prompts/opsx-update.prompt.md create mode 100644 .github/skills/common-aaz-custom-code-generation/SKILL.md create mode 100644 .github/skills/common-custom-code-router/SKILL.md create mode 100644 .github/skills/common-legacy-non-sdk-custom-code-generation/SKILL.md create mode 100644 .github/skills/common-legacy-sdk-backed-custom-code-generation/SKILL.md create mode 100644 .github/skills/common-live-test-from-help/SKILL.md create mode 100644 .github/skills/common-live-test-from-help/references/live-test-template.md create mode 100644 .github/skills/openspec-apply-change/SKILL.md create mode 100644 .github/skills/openspec-archive-change/SKILL.md create mode 100644 .github/skills/openspec-explore/SKILL.md create mode 100644 .github/skills/openspec-propose/SKILL.md create mode 100644 .github/skills/openspec-sync-specs/SKILL.md create mode 100644 .github/skills/openspec-update-change/SKILL.md create mode 100644 doc/ai_custom_code.md create mode 100644 openspec/changes/.gitkeep create mode 100644 openspec/config.yaml create mode 100644 openspec/specs/.gitkeep diff --git a/.github/agents/custom-code.agent.md b/.github/agents/custom-code.agent.md new file mode 100644 index 00000000000..8cfce6eea97 --- /dev/null +++ b/.github/agents/custom-code.agent.md @@ -0,0 +1,28 @@ +--- +name: custom-code-agent +description: "Use when adding or modifying Azure CLI command module custom code, including AAZ subclass custom, legacy SDK-backed custom, and legacy non-SDK custom." +--- + +You are a focused coding sub-agent for Azure CLI command module custom code. + +Goals: +- Add or modify command logic in custom.py. +- Register commands in commands.py. +- Update argument definitions in _params.py. +- Keep command help in _help.py consistent. + +Rules: +- Prefer small, targeted edits. +- Before editing custom code, use `common-custom-code-router` unless the route is already recorded in an OpenSpec design or is otherwise unambiguous from local evidence. +- If an OpenSpec design records the route and implementation plan, follow it. Do not choose a different route during implementation unless the design is updated. +- Use the selected route to apply exactly one generation workflow: `common-aaz-custom-code-generation`, `common-legacy-sdk-backed-custom-code-generation`, or `common-legacy-non-sdk-custom-code-generation`. +- Preserve existing command behavior unless the request asks for a change. +- Update tests when behavior changes. +- Do not edit generated AAZ files under `aaz/latest` unless the user explicitly asks to modify generated output and accepts regeneration risk. +- Ignore local/personal memory by default and do not rely on it for behavior decisions. +- Use only user request, current session context, and repository-tracked guidance as authoritative inputs. +- Do not create, edit, or delete files outside this repository unless the user explicitly asks and confirms. +- When creating skills in this workflow, only add module-specific skills. +- Module skill names must follow `module-`. +- Treat agent instructions as az-cli level guidance, not module-local policy. +- If a requested specification looks general and reusable across modules, ask to align with the owner alias `bernardpan` before finalizing it as agent-level policy. diff --git a/.github/instructions/agent-safety.instructions.md b/.github/instructions/agent-safety.instructions.md new file mode 100644 index 00000000000..36ba635ed63 --- /dev/null +++ b/.github/instructions/agent-safety.instructions.md @@ -0,0 +1,13 @@ +--- +applyTo: "**" +description: "Global safety and scope rules for all agents in this repository." +--- + +When handling tasks in this repository: + +- Treat repository files and in-session user instructions as the primary source of truth. +- Ignore local/personal memory by default unless the user explicitly asks to use memory content. +- Do not create, edit, or delete files outside this repository unless the user explicitly asks and confirms. +- Do not modify machine-level/user-level settings (for example shell profile, global git config, VS Code user settings) unless explicitly requested. +- Avoid destructive operations by default; ask for confirmation before deleting resources or running irreversible commands. +- Keep edits minimal and scoped to the user request. diff --git a/.github/instructions/custom-code.instructions.md b/.github/instructions/custom-code.instructions.md new file mode 100644 index 00000000000..406c1480ca5 --- /dev/null +++ b/.github/instructions/custom-code.instructions.md @@ -0,0 +1,23 @@ +--- +applyTo: "src/azure-cli/azure/cli/command_modules/**/{custom.py,commands.py,_params.py,_help.py}" +description: "Guidance for editing Azure CLI command module custom code files." +--- + +When editing Azure CLI command modules: + +- Keep command registration, parameters, and handlers in sync. +- If a new command is added, wire it in commands.py and define args in _params.py. +- Keep return shapes compatible with existing CLI output patterns. +- Keep help/examples aligned with command behavior. +- Prefer concise error messages through CLIError when user input is invalid. +- Keep these instructions at az-cli level; do not add module-specific policy here. +- If a new rule appears to be a general specification, sync with owner in the Azure CLI team before promoting it to shared instruction guidance. + +Before generating or modifying custom code, read and apply these repository docs: + +- doc/authoring_command_modules/authoring_commands.md (command registration patterns, custom command wiring, argument and validator conventions) +- doc/command_guidelines.md (CLI UX and argument design expectations) +- doc/error_handling_guidelines.md (preferred Azure CLI error types and patterns) +- doc/authoring_help.md (help authoring format in _help.py/help.yaml) +- doc/reference_doc_guidelines.md (example quality and formatting requirements) +- doc/authoring_tests.md (test coverage and scenario test expectations) diff --git a/.github/prompts/opsx-apply.prompt.md b/.github/prompts/opsx-apply.prompt.md new file mode 100644 index 00000000000..c83b479f783 --- /dev/null +++ b/.github/prompts/opsx-apply.prompt.md @@ -0,0 +1,153 @@ +--- +description: Implement tasks from an OpenSpec change (Experimental) +--- + +Implement tasks from an OpenSpec change. + +**Store selection:** If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run `openspec store list --json` to discover registered store ids, then pass `--store ` on the commands that read or write specs and changes (`new change`, `status`, `instructions`, `list`, `show`, `validate`, `archive`, `doctor`, `context`). Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local `openspec/` root. + +**Input**: Optionally specify a change name (e.g., `/opsx:apply add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes. + +**Steps** + +1. **Select the change** + + If a name is provided, use it. Otherwise: + - Infer from conversation context if the user mentioned a change + - Auto-select if only one active change exists + - If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select + + Always announce: "Using change: " and how to override (e.g., `/opsx:apply `). + +2. **Check status to understand the schema** + ```bash + openspec status --change "" --json + ``` + Parse the JSON to understand: + - `schemaName`: The workflow being used (e.g., "spec-driven") + - `planningHome`, `changeRoot`, and `actionContext`: planning scope and edit constraints + - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others) + +3. **Get apply instructions** + + ```bash + openspec instructions apply --change "" --json + ``` + + This returns: + - `contextFiles`: artifact ID -> array of concrete file paths (varies by schema) + - Progress (total, complete, remaining) + - Task list with status + - Dynamic instruction based on current state + + **Handle states:** + - If `state: "blocked"` (missing artifacts): show message, suggest using `/opsx:continue` + - If `state: "all_done"`: congratulate, suggest archive + - Otherwise: proceed to implementation + +4. **Read context files** + + Read every file path listed under `contextFiles` from the apply instructions output. + The files depend on the schema being used: + - **spec-driven**: proposal, specs, design, tasks + - Other schemas: follow the contextFiles from CLI output + +5. **Show current progress** + + Display: + - Schema being used + - Progress: "N/M tasks complete" + - Remaining tasks overview + - Dynamic instruction from CLI + +6. **Implement tasks (loop until done or blocked)** + + For each pending task: + - Show which task is being worked on + - Make the code changes required + - Keep changes minimal and focused + - Mark task complete in the tasks file: `- [ ]` → `- [x]` + - Continue to next task + + **Pause if:** + - Task is unclear → ask for clarification + - Implementation reveals a design issue → suggest updating artifacts + - Error or blocker encountered → report and wait for guidance + - User interrupts + +7. **On completion or pause, show status** + + Display: + - Tasks completed this session + - Overall progress: "N/M tasks complete" + - If all done: suggest archive + - If paused: explain why and wait for guidance + +**Output During Implementation** + +``` +## Implementing: (schema: ) + +Working on task 3/7: +[...implementation happening...] +✓ Task complete + +Working on task 4/7: +[...implementation happening...] +✓ Task complete +``` + +**Output On Completion** + +``` +## Implementation Complete + +**Change:** +**Schema:** +**Progress:** 7/7 tasks complete ✓ + +### Completed This Session +- [x] Task 1 +- [x] Task 2 +... + +All tasks complete! You can archive this change with `/opsx:archive`. +``` + +**Output On Pause (Issue Encountered)** + +``` +## Implementation Paused + +**Change:** +**Schema:** +**Progress:** 4/7 tasks complete + +### Issue Encountered + + +**Options:** +1.