Skip to content

Update PowerShell dev actions and namespace handlers - #2849

Open
Hillary Mutisya (hillary-mutisya) wants to merge 4 commits into
microsoft:mainfrom
hillary-mutisya:actionMode2_part3
Open

Update PowerShell dev actions and namespace handlers#2849
Hillary Mutisya (hillary-mutisya) wants to merge 4 commits into
microsoft:mainfrom
hillary-mutisya:actionMode2_part3

Conversation

@hillary-mutisya

Copy link
Copy Markdown
Collaborator
  • add cancellation, structured failures, bounded repair, and flow reuse
  • register and implement all PowerShell namespaces
  • require confirmation for mutating actions with unattended default-deny
  • extract namespace actions into typed handlers with a shared registry
  • add routing, persistence, concurrency, sandbox, and runtime coverage
  • update Copilot dev-action routing and project documentation

- add cancellation, structured failures, bounded repair, and flow reuse
- register and implement all PowerShell namespaces
- require confirmation for mutating actions with unattended default-deny
- extract namespace actions into typed handlers with a shared registry
- add routing, persistence, concurrency, sandbox, and runtime coverage
- update Copilot dev-action routing and project documentation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the TypeAgent PowerShell dev-action and agent surface to support cancellable, structured, policy-aware execution, with a typed registry of namespace handlers and additional routing/persistence/concurrency/sandbox coverage.

Changes:

  • Add structured PowerShell failure metadata (errorCode/retryable/mayHaveSideEffects) and bounded “repair once” flow repair support.
  • Introduce typed PowerShell namespace action handlers (files/data/archives/processes/services/system/network) with a shared registry, plus manifest/schema/grammar updates.
  • Update Copilot dev-actions hook routing for Windows-only recording, client request IDs, abort-driven cancellation, and longer hook timeout.
Show a summary per file
File Description
ts/packages/dispatcher/dispatcher/src/reasoning/reasoningProfile.ts Updates PowerShell capability guidance to include bounded repair semantics.
ts/packages/copilot-plugin/test/hookDevActions.spec.ts Extends hook tests for Windows-only behavior, abort cancellation, and unattended denial defaults.
ts/packages/copilot-plugin/src/shared/typeagent-client.ts Adjusts ClientIO interaction behavior to default-deny unattended prompts.
ts/packages/copilot-plugin/src/hooks/hook-router.ts Adds SIGINT/SIGTERM abort wiring and passes AbortSignal into dev-actions hook.
ts/packages/copilot-plugin/src/hooks/hook-dev-actions.ts Adds Windows gating, clientRequestId submission, and abort-driven cancellation handling.
ts/packages/copilot-plugin/hooks.json Increases hook timeout to accommodate longer-running dev actions.
ts/packages/agentSdk/src/action.ts Extends ActionResultError with machine-readable errorCode and retry/side-effect metadata.
ts/packages/agents/powershell/test/powerShellStore.spec.ts Validates the new repairAndExecutePowerShellFlow action appears in the schema.
ts/packages/agents/powershell/test/actionHandler.spec.ts Adds namespace registration/execution coverage, confirmation policy tests, cancellation, concurrency, and sandbox/path policy tests.
ts/packages/agents/powershell/src/types/powerShellFailure.mts Introduces structured PowerShell failure creation and execution failure classification.
ts/packages/agents/powershell/src/types/powerShellAgentContext.mts Extracts a typed PowerShellAgentContext interface.
ts/packages/agents/powershell/src/store/powerShellStore.mts Adds RepairAndExecutePowerShellFlow to generated schema/type union list.
ts/packages/agents/powershell/src/schema/scriptActions.mts Adds RepairAndExecutePowerShellFlow type to the PowerShell action schema.
ts/packages/agents/powershell/src/namespaces/system/actionHandler.mts Adds static system namespace handler definitions.
ts/packages/agents/powershell/src/namespaces/services/actionHandler.mts Adds static services namespace handler definitions (with confirmation prompts for mutations).
ts/packages/agents/powershell/src/namespaces/processes/actionHandler.mts Adds static processes namespace handler definitions (with confirmation prompts for mutations).
ts/packages/agents/powershell/src/namespaces/network/actionHandler.mts Adds static network namespace handler definitions.
ts/packages/agents/powershell/src/namespaces/namespaceActionHandler.mts Adds shared handler implementation (sandboxing, confirmation, abort-aware execution).
ts/packages/agents/powershell/src/namespaces/files/filesSchema.agr Refines file grammar patterns (read/show/display variants).
ts/packages/agents/powershell/src/namespaces/files/actionHandler.mts Adds static file namespace handler definitions (with confirmation prompts for mutations).
ts/packages/agents/powershell/src/namespaces/data/dataSchema.agr Refines data grammar patterns for JSON display/read behaviors.
ts/packages/agents/powershell/src/namespaces/data/actionHandler.mts Adds static data namespace handler definitions (with confirmation prompts for mutations).
ts/packages/agents/powershell/src/namespaces/archives/actionHandler.mts Adds static archives namespace handler definitions (with confirmation prompts for mutations).
ts/packages/agents/powershell/src/namespaces/actionHandlerRegistry.mts Adds registry/execution routing for namespace handlers and registration introspection helpers.
ts/packages/agents/powershell/src/manifest.json Registers PowerShell sub-action manifests for additional namespaces.
ts/packages/agents/powershell/src/execution/powershellRunner.mts Adds AbortSignal support and explicit cancellation reporting in ScriptExecutionResult.
ts/packages/agents/powershell/src/actionHandler.mts Refactors PowerShell action handling for namespace routing, flow reuse/locking, repair-once, and abort-aware execution.
ts/packages/agents/powershell/scripts/scriptHost.ps1 Hardens allowed-path expansion and prefix checks to avoid sibling-path bypasses.
ts/packages/agents/powershell/benchmark/scenarios/dev-actions-routing.json Updates routing scenario expectations to include namespace schema identifiers.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (3)

ts/packages/agentSdk/src/action.ts:48

  • Repo convention (ts/CLAUDE.md) asks to avoid em-dashes (—) in comments. Replace the em-dash in this comment with a hyphen to match the style used elsewhere in the file.
    // Rich display to show in place of the plain `error` text (e.g. setup
    // instructions with a config snippet, which need markdown to survive
    // rendering). Optional — clients fall back to `error` when absent.
    errorDisplayContent?: DisplayContent | undefined;

ts/packages/agents/powershell/src/actionHandler.mts:1056

  • This overrides fallbackToReasoning to true for all failures, including powershell.policyDenied, powershell.cancelled, and powershell.partialSideEffects. That defeats the structured failure classification from createPowerShellExecutionFailure and can cause the reasoning loop to treat denied/cancelled actions as retryable.

This issue also appears on line 1196 of the same file.

            if (result.error !== undefined) {
                return { ...result, fallbackToReasoning: true };
            }

ts/packages/agents/powershell/src/actionHandler.mts:1198

  • Same as above: forcing fallbackToReasoning: true on any error masks policyDenied/cancelled/partialSideEffects failures that should not fall back to reasoning or auto-repair.
            if (result.error !== undefined) {
                return { ...result, fallbackToReasoning: true };
            }
  • Files reviewed: 29/29 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment thread ts/packages/agents/powershell/test/actionHandler.spec.ts Outdated
Comment thread ts/packages/copilot-plugin/src/shared/typeagent-client.ts
Comment thread ts/packages/copilot-plugin/src/hooks/hook-dev-actions.ts
exit 1
}
try {
$resolvedPath = Get-CanonicalFileSystemPath $val

@jebrans jebrans Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work for URL's in data like

{
    actionName: "writeFile",
    parameters: {
        path: "C:\\Users\\me\\notes.txt",
        content: "https://example.test/api",
    },
}

@@ -73,26 +113,28 @@ try {
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot highlighted a concern here that Start-Process accepts executable names and resolves them through PATH. So executables outside of allowedPaths can still be run here for example :

 Path = "powershell.exe"  with  Arguments = "-NoProfile -Command Get-Process"

It suggests explicitly declaring which action parameters represent paths. This will allow executable parameters to be resolved to canonical paths and validated, while parameters representing things like library names can properly skipped and not marked as a path.

if ("error" in execution) {
return execution.error;
}
context.abortSignal?.throwIfAborted();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to split up the post-execution work of cancellation check, updateFlowScript(), and recordUsage() and separate their potential failure scenarios.

For example, update failures (after executing) or cancellation triggered after execution (where it may have already changed state) should perhaps return a partialFailure to surface potential side effects (but no rollback). This should probably be separate from script failure scenarios where you do want a rollback.

);
}

case "editPowerShellFlow": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the earlier repair operation it will acquire lock using withFlowMutationLock(flowName), but editPowerShellFlow here does not acquire the lock. So, it is hypothetically possible (but unlikely) that repair + edit can race to mutate. It would probably be a good idea to have edit also acquire lock too.

@GeorgeNgMsft George Ng (GeorgeNgMsft) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments, I think two are optional, but the potential sandbox gap is worth addressing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants