Files
pulse/internal/ai/tools/execution_profile.go
T
rcourtman 5d53fa7a3d Remove the Assistant mutation handlers nothing calls
pulse_control only plans typed resource actions into Pulse Actions
(executeControlResource -> typedActionPlanner). The handlers that sat
behind the retired model-authored command, file and container paths
stayed in the tree with no production caller: run command, guest
control, app-container control, Docker control and container update,
Kubernetes scale/restart/delete-pod/exec, and file append/write.
registerFileTools was never called either, so pulse_file_edit is not
registered at all; calls to it are denied by the mutation registry
before any tool lookup.

A whole-program reachability run over cmd/... lists each of them as
unreachable, and so is everything only they used: approval-record and
preflight authoring, the command and native-action audit lanes with
their remediation-lock gate and plan-hash helpers, the Docker host
resolvers, and the file write verification. The executor's autonomous
flag, whose only readers were those handlers, goes with them (the
executor's SetAutonomousMode and the flag argument of SetContext).

Delete them with their tests and the constants, types and test helpers
they stranded. The contract prose that described the removed broker now
says that plan freshness and the operator remediation lock are enforced
by internal/actionlifecycle. Two source pins that named deleted code go
(the publishActionCompleted dispatch sites and the pulse_file_edit
declaration), the standards tests drop their expectations of an
ActionPlan construction in action_audit.go and of the legacy app_container
rejection in the deleted file-edit test, and the RA35 evidence entry for
the deleted run-command test goes with them.

Left alone on purpose: the saved autonomous control level and its
entitlement and approval-admission checks, which stay as legacy
compatibility, Service.SetAutonomousMode and the chat clamp,
SetOnActionCompleted and its router wiring (no dispatcher is left, the
contract prose says so), and the protected-guests plumbing.

Rebuilt on current main: the first version had 213 commits of drift.
Two conflicts, both on code this change deletes. tools_control.go takes
the deletion over the Protected guests cleanup that landed inside
executeRunCommand. action_audit_remediation_lock_test.go goes with the
audit lanes, including the test added for the dispatch gate's read
through a succession; that gate is deleted here, and
TestLockMovedBySuccessionStillRefusesTheIDThePreviousGenerationLists in
internal/actionlifecycle covers the same refusal on the live path.
2026-10-11 12:35:28 +01:00

105 lines
4.4 KiB
Go

package tools
import (
"fmt"
"github.com/rcourtman/pulse-go-rewrite/internal/agentcapabilities"
)
// ExecutionProfile is the core-owned, request-local execution posture for
// one Assistant/Patrol run. It is deliberately an opaque integer with no
// JSON tags, string round-trip, or public constructor from external input:
// enterprise and transport code can never serialize, select, or relax a
// profile. Profiles are applied by core call sites only (chat service and
// the investigation adapter), and their policy is enforced twice - during
// provider projection and again at registry execution.
type ExecutionProfile int
const (
// ProfileInteractiveAssistant is the default interactive chat
// posture: the operator's configured control level and autonomy
// govern, and the interactive question tool is available.
ProfileInteractiveAssistant ExecutionProfile = iota
// ProfilePatrolDetection is the scheduled Patrol detection posture:
// non-interactive, no infrastructure mutations, and Pulse-state
// mutations restricted to the finding lifecycle and observer-proposal tools
// (patrol_report_finding / patrol_assess_finding /
// patrol_propose_observer). The legacy direct-resolve alias is deliberately
// absent: all existing-finding closure crosses the assessed lifecycle.
ProfilePatrolDetection
// ProfilePatrolInvestigation is the Patrol investigation posture:
// non-interactive, with no infrastructure mutations. The sole Pulse-state
// write is canonical action planning without approval or execution.
ProfilePatrolInvestigation
)
// Valid reports whether the profile is one of the closed set. Like the
// invocation-class vocabulary, execution profiles are a closed
// vocabulary: an unknown value must be rejected, never silently treated
// as the permissive interactive default.
func (p ExecutionProfile) Valid() bool {
switch p {
case ProfileInteractiveAssistant, ProfilePatrolDetection, ProfilePatrolInvestigation:
return true
default:
return false
}
}
// NonInteractive reports whether the profile forbids interactive user
// input. This is deliberately independent of autonomous mode: suppressing
// questions grants no mutation authority, and mutation policy never
// loosens because a run is interactive. Unknown profiles are treated as
// non-interactive: an unclassifiable posture must never gain the
// interactive default's permissions.
func (p ExecutionProfile) NonInteractive() bool {
return p != ProfileInteractiveAssistant
}
// patrolDetectionPulseStateAllowlist names the only tools whose
// pulse-state mutations the detection profile permits. A blanket
// pulse-state allowance would also permit alert dismissal and knowledge
// writes, which detection has no business performing.
func patrolDetectionPulseStateAllowlist() map[string]bool {
return map[string]bool{
agentcapabilities.PatrolAssessFindingToolName: true,
agentcapabilities.PatrolProposeObserverToolName: true,
agentcapabilities.PatrolReportFindingToolName: true,
}
}
// ApplyExecutionProfile applies the profile's policy to this executor
// instance (normally a request-scoped clone). Both Patrol profiles deny
// infrastructure mutations and mark the executor non-interactive; they
// differ only in pulse-state policy.
// Unknown profiles are rejected outright (panic on programmer error)
// rather than falling through to the interactive default's permissions.
func (e *PulseToolExecutor) ApplyExecutionProfile(profile ExecutionProfile) {
if !profile.Valid() {
panic(fmt.Sprintf("unknown execution profile %d: profiles are a closed vocabulary and cannot default to interactive permissions", int(profile)))
}
e.executionProfile = profile
switch profile {
case ProfilePatrolDetection:
e.denyInfrastructureMutations = true
e.pulseStateAllowlist = patrolDetectionPulseStateAllowlist()
case ProfilePatrolInvestigation:
e.denyInfrastructureMutations = true
e.pulseStateAllowlist = map[string]bool{agentcapabilities.PatrolProposeActionToolName: true}
default:
e.denyInfrastructureMutations = false
// Interactive Assistant is conversation/read/session authority.
// Finding and knowledge lifecycle writes remain explicit product/API
// operations and are never model-invokable.
e.pulseStateAllowlist = map[string]bool{}
}
}
// ExecutionProfile returns the profile applied to this executor instance.
func (e *PulseToolExecutor) ExecutionProfile() ExecutionProfile {
if e == nil {
return ProfileInteractiveAssistant
}
return e.executionProfile
}