Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

Re-land canvas-apps sync reminder hook, fixed for Claude Code (#335)

Ryan Gammon1304adc17bd5
diff --git a/plugins/canvas-apps/.claude-plugin/plugin.json b/plugins/canvas-apps/.claude-plugin/plugin.json
index 42cb07243..488d411be 100644
--- a/plugins/canvas-apps/.claude-plugin/plugin.json
+++ b/plugins/canvas-apps/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "canvas-apps",
- "version": "2.2.1",
+ "version": "2.2.2",
"description": "Build Power Apps Canvas Apps using the Canvas Authoring MCP server.",
"author": {
"name": "Microsoft",
diff --git a/plugins/canvas-apps/.plugin/plugin.json b/plugins/canvas-apps/.plugin/plugin.json
index 42cb07243..488d411be 100644
--- a/plugins/canvas-apps/.plugin/plugin.json
+++ b/plugins/canvas-apps/.plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "canvas-apps",
- "version": "2.2.1",
+ "version": "2.2.2",
"description": "Build Power Apps Canvas Apps using the Canvas Authoring MCP server.",
"author": {
"name": "Microsoft",
diff --git a/plugins/canvas-apps/AGENTS.md b/plugins/canvas-apps/AGENTS.md
index 3494b7e70..ffaaa7bd1 100644
--- a/plugins/canvas-apps/AGENTS.md
+++ b/plugins/canvas-apps/AGENTS.md
@@ -19,10 +19,15 @@ claude --plugin-dir /path/to/plugins/canvas-apps
## Architecture
```
+.claude-plugin/plugin.json ← Claude Code metadata (mirrors .plugin/plugin.json)
.plugin/plugin.json ← Open Plugins metadata (name, version, keywords)
.mcp.json ← MCP server config (canvas-authoring, auto-registered)
AGENTS.md ← Plugin guidance for AI agents (this file)
CLAUDE.md ← Symlink → AGENTS.md
+hooks.json ← Copilot-format hooks: userPromptTransformed
+hooks/
+ hooks.json ← Claude-format hooks: UserPromptSubmit
+ inject-sync-reminder.cs ← File-based .NET app that emits the sync reminder for both hosts
references/
TechnicalGuide.md ← YAML syntax, control selection, layout strategies, Power Fx patterns
DesignGuide.md ← Aesthetic guidelines, anti-patterns, design process
@@ -38,8 +43,6 @@ skills/
SKILL.md ← Registers the Canvas Authoring MCP server with Claude Code
add-data-source/
SKILL.md ← Guides user to add a data source or connector in Studio, then verifies
- generate-canvas-app/
- SKILL.md ← [DEPRECATED] Redirects to canvas-app
```
## Skills
@@ -75,6 +78,31 @@ The `canvas-authoring` MCP server exposes the following tools:
| `list_data_sources` | Lists all available data sources in the current authoring session |
| `sync_canvas` | Syncs the current coauthoring session state from the server to a local directory, writing all YAML files |
+## Hooks
+
+Both hosts inject a reminder to call `sync_canvas` before acting, so the agent never edits stale
+local `.pa.yaml` files. The reminder is conditional in wording — the agent skips the sync when no
+coauthoring session is active or the request is unrelated to a canvas app.
+
+Registration uses both plugin [hook formats](https://code.visualstudio.com/docs/agent-customization/agent-plugins)
+— Claude-format (`hooks/hooks.json`) and Copilot-format (`hooks.json` at the plugin root) — which
+the hosts read independently:
+
+| Host | Registered in | Event |
+|------|---------------|-------|
+| Claude Code | `hooks/hooks.json` (Claude format) | `UserPromptSubmit` |
+| Copilot CLI | `hooks.json` in the plugin root (Copilot format) | `userPromptTransformed` |
+
+Each host reads only its own file and ignores the other's. Both run
+`hooks/inject-sync-reminder.cs` via `dotnet run --file`, which branches on its stdin payload to
+emit the output shape each host expects.
+
+Keep the two files separate. Claude Code rejects unrecognized hook event names, so putting
+`userPromptTransformed` in `hooks/hooks.json` makes Claude fail to load the plugin, disabling its
+`canvas-authoring` MCP server. Neither manifest should declare a `"hooks"` field: Claude Code
+auto-discovers `hooks/hooks.json`, and pointing at it explicitly is treated as a duplicate hook
+source, which also disables MCP.
+
## Prerequisites
Before the MCP server will start, you need:
diff --git a/plugins/canvas-apps/hooks.json b/plugins/canvas-apps/hooks.json
new file mode 100644
index 000000000..66c19fe68
--- /dev/null
+++ b/plugins/canvas-apps/hooks.json
@@ -0,0 +1,17 @@
+{
+ "version": 1,
+ "description": "Canvas Apps lifecycle hooks (Copilot format)",
+ "hooks": {
+ "userPromptTransformed": [
+ {
+ "hooks": [
+ {
+ "type": "command",
+ "command": "dotnet run --file \"${PLUGIN_ROOT}/hooks/inject-sync-reminder.cs\"",
+ "timeout": 30
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/plugins/canvas-apps/hooks/hooks.json b/plugins/canvas-apps/hooks/hooks.json
new file mode 100644
index 000000000..46562aede
--- /dev/null
+++ b/plugins/canvas-apps/hooks/hooks.json
@@ -0,0 +1,16 @@
+{
+ "description": "Canvas Apps lifecycle hooks",
+ "hooks": {
+ "UserPromptSubmit": [
+ {
+ "hooks": [
+ {
+ "type": "command",
+ "command": "dotnet run --file \"${CLAUDE_PLUGIN_ROOT}/hooks/inject-sync-reminder.cs\"",
+ "timeout": 30
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/plugins/canvas-apps/hooks/inject-sync-reminder.cs b/plugins/canvas-apps/hooks/inject-sync-reminder.cs
new file mode 100644
index 000000000..33e2fbf27
--- /dev/null
+++ b/plugins/canvas-apps/hooks/inject-sync-reminder.cs
@@ -0,0 +1,63 @@
+#:property PublishAot=false
+
+using System.Text.Json;
+
+// Prompt hook for the canvas-apps plugin.
+//
+// The hook injects guidance instead of calling sync_canvas directly because it only
+// receives the session cwd, not the per-app working directory. A blanket sync could
+// overwrite the wrong directory or clobber local edits that have not been pushed.
+const string Reminder =
+ "Canvas Apps coauthoring reminder: " +
+ "Before acting on this request, if a Canvas Authoring session is " +
+ "active (i.e. `connect` has already been called for a canvas app), first call " +
+ "the `sync_canvas` MCP tool targeting the app's working directory to pull the " +
+ "current session state into the local .pa.yaml files. This avoids editing stale " +
+ "YAML. If no coauthoring session is active yet, or this request is unrelated to " +
+ "a canvas app, skip the sync.";
+
+try
+{
+ var rawInput = await Console.In.ReadToEndAsync();
+ string? transformedPrompt = null;
+
+ try
+ {
+ using var input = JsonDocument.Parse(rawInput);
+ if (input.RootElement.ValueKind == JsonValueKind.Object &&
+ input.RootElement.TryGetProperty("transformedPrompt", out var prompt) &&
+ prompt.ValueKind == JsonValueKind.String)
+ {
+ transformedPrompt = prompt.GetString();
+ }
+ }
+ catch (JsonException)
+ {
+ // Hook failures must not block the user's prompt. If parsing fails, emit the
+ // Claude Code additional-context shape (Copilot will ignore it).
+ }
+
+ using var writer = new Utf8JsonWriter(Console.OpenStandardOutput());
+ writer.WriteStartObject();
+
+ if (transformedPrompt is not null)
+ {
+ writer.WriteString(
+ "modifiedTransformedPrompt",
+ $"{transformedPrompt}\n\n{Reminder}");
+ }
+ else
+ {
+ writer.WriteStartObject("hookSpecificOutput");
+ writer.WriteString("hookEventName", "UserPromptSubmit");
+ writer.WriteString("additionalContext", Reminder);
+ writer.WriteEndObject();
+ }
+
+ writer.WriteEndObject();
+ writer.Flush();
+}
+catch
+{
+ // Hooks are advisory and must never prevent the host from processing a prompt.
+}
diff --git a/plugins/canvas-apps/skills/generate-canvas-app/SKILL.md b/plugins/canvas-apps/skills/generate-canvas-app/SKILL.md
deleted file mode 100644
index 62ccaeaca..000000000
--- a/plugins/canvas-apps/skills/generate-canvas-app/SKILL.md
+++ /dev/null
@@ -1,16 +0,0 @@
----
-name: generate-canvas-app
-version: 2.0.0
-description: "[DEPRECATED — use canvas-app instead] Generate a complete Power Apps canvas app."
-author: Microsoft Corporation
-user-invocable: true
-allowed-tools: Read
----
-
-# ⚠️ Deprecated — Use `canvas-app`
-
-This skill has been replaced by the unified **`canvas-app`** skill, which handles both
-creating and editing canvas apps.
-
-Please use `/canvas-app` instead. It will automatically detect that the app is empty and
-run the full generation workflow.