| 1 |
-- allium: 3 |
| 2 |
-- executor.allium |
| 3 |
|
| 4 |
-- Scope: host command execution only. |
| 5 |
-- Includes: bash action execution, command result outcomes, post-command state, |
| 6 |
-- base environment snapshots, cancellation, and git-backed feedback. |
| 7 |
-- Excludes: provider request construction and act-turn approval policy. |
| 8 |
|
| 9 |
------------------------------------------------------------ |
| 10 |
-- Value Types |
| 11 |
------------------------------------------------------------ |
| 12 |
|
| 13 |
value Path { |
| 14 |
raw: String |
| 15 |
} |
| 16 |
|
| 17 |
value EnvironmentVariable { |
| 18 |
name: String |
| 19 |
value: String |
| 20 |
} |
| 21 |
|
| 22 |
value EnvironmentSnapshot { |
| 23 |
working_directory: Path |
| 24 |
variables: Set<EnvironmentVariable> |
| 25 |
} |
| 26 |
|
| 27 |
value BashAction { |
| 28 |
command: String |
| 29 |
working_directory: Path |
| 30 |
} |
| 31 |
|
| 32 |
value CommandFeedback { |
| 33 |
changed_files: Set<Path> |
| 34 |
diff: String |
| 35 |
} |
| 36 |
|
| 37 |
------------------------------------------------------------ |
| 38 |
-- Entities and Variants |
| 39 |
------------------------------------------------------------ |
| 40 |
|
| 41 |
entity Executor { |
| 42 |
base_environment: EnvironmentSnapshot? |
| 43 |
} |
| 44 |
|
| 45 |
entity CommandResult { |
| 46 |
action: BashAction |
| 47 |
stdout: String |
| 48 |
stderr: String |
| 49 |
outcome: exit | timeout | cancelled | denied | skipped | error |
| 50 |
exit_code: Integer? when outcome = exit |
| 51 |
message: String? when outcome = error |
| 52 |
post_command_state: EnvironmentSnapshot? |
| 53 |
feedback: CommandFeedback? |
| 54 |
} |
| 55 |
|
| 56 |
entity Host {} |
| 57 |
|
| 58 |
------------------------------------------------------------ |
| 59 |
-- Rules |
| 60 |
------------------------------------------------------------ |
| 61 |
|
| 62 |
rule ExecuteAcceptedBashAction { |
| 63 |
when: ExecuteCommand(host, executor, action) |
| 64 |
|
| 65 |
ensures: |
| 66 |
let result = CommandResult.created( |
| 67 |
action: action, |
| 68 |
stdout: CapturedStdout(action), |
| 69 |
stderr: CapturedStderr(action), |
| 70 |
outcome: CommandOutcome(action) |
| 71 |
) |
| 72 |
if result.outcome = exit: |
| 73 |
result.exit_code = CapturedExitCode(action) |
| 74 |
if PostCommandStateCaptured(action): |
| 75 |
result.post_command_state = CapturedPostCommandState(action) |
| 76 |
} |
| 77 |
|
| 78 |
rule BaseEnvironmentOverridesParentEnvironment { |
| 79 |
when: ExecuteCommand(host, executor, action) |
| 80 |
requires: executor.base_environment != null |
| 81 |
|
| 82 |
ensures: CommandEnvironment(action).variables = executor.base_environment.variables |
| 83 |
} |
| 84 |
|
| 85 |
rule HostControlVariablesAreAddedForExecution { |
| 86 |
when: ExecuteCommand(host, executor, action) |
| 87 |
|
| 88 |
ensures: CommandEnvironment(action).variables = CommandEnvironment(action).variables + HostControlVariables() |
| 89 |
ensures: not StateFileVariable() in CapturedPostCommandState(action).variables |
| 90 |
} |
| 91 |
|
| 92 |
rule CancellationKillsCommandProcessGroup { |
| 93 |
when: CommandCancelled(host, action) |
| 94 |
|
| 95 |
ensures: CommandResult.created( |
| 96 |
action: action, |
| 97 |
outcome: cancelled |
| 98 |
) |
| 99 |
ensures: ProcessGroupTerminated(action) |
| 100 |
} |
| 101 |
|
| 102 |
rule TimeoutRecordsTimeoutOutcome { |
| 103 |
when: CommandTimedOut(host, action) |
| 104 |
|
| 105 |
ensures: CommandResult.created( |
| 106 |
action: action, |
| 107 |
outcome: timeout |
| 108 |
) |
| 109 |
} |
| 110 |
|
| 111 |
rule ErrorRecordsHostExecutionFailure { |
| 112 |
when: HostExecutionFailed(host, action, message) |
| 113 |
|
| 114 |
ensures: CommandResult.created( |
| 115 |
action: action, |
| 116 |
outcome: error, |
| 117 |
message: message |
| 118 |
) |
| 119 |
} |
| 120 |
|
| 121 |
rule AttachFeedbackFromCleanGitBaseline { |
| 122 |
when: ExecuteCommandFromGitBaseline(host, executor, action, baseline) |
| 123 |
requires: baseline.status = clean |
| 124 |
requires: GitChangesExistAfterCommand(action) |
| 125 |
|
| 126 |
ensures: CommandResult{action}.feedback = CommandFeedback{ |
| 127 |
changed_files: ChangedPathsRelativeToFinalWorkingDirectory(action), |
| 128 |
diff: CombinedTrackedDiff(action) |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
rule OmitFeedbackFromDirtyOrUnavailableGitBaseline { |
| 133 |
when: ExecuteCommandFromGitBaseline(host, executor, action, baseline) |
| 134 |
requires: baseline.status = dirty or baseline.status = unavailable |
| 135 |
|
| 136 |
ensures: CommandResult{action}.feedback = null |
| 137 |
} |
| 138 |
|
| 139 |
------------------------------------------------------------ |
| 140 |
-- Actor Declarations |
| 141 |
------------------------------------------------------------ |
| 142 |
|
| 143 |
actor HostActor { |
| 144 |
identified_by: Host where true |
| 145 |
} |
| 146 |
|
| 147 |
------------------------------------------------------------ |
| 148 |
-- Surfaces |
| 149 |
------------------------------------------------------------ |
| 150 |
|
| 151 |
surface CommandExecution { |
| 152 |
facing host: HostActor |
| 153 |
|
| 154 |
context executor: Executor |
| 155 |
|
| 156 |
exposes: |
| 157 |
executor.base_environment |
| 158 |
|
| 159 |
provides: |
| 160 |
ExecuteCommand(host, executor, action) |
| 161 |
CommandCancelled(host, action) |
| 162 |
CommandTimedOut(host, action) |
| 163 |
HostExecutionFailed(host, action, message) |
| 164 |
ExecuteCommandFromGitBaseline(host, executor, action, baseline) |
| 165 |
} |
| 166 |
|
| 167 |
surface CommandResultObservation { |
| 168 |
facing host: HostActor |
| 169 |
|
| 170 |
context result: CommandResult |
| 171 |
|
| 172 |
exposes: |
| 173 |
result.action |
| 174 |
result.stdout |
| 175 |
result.stderr |
| 176 |
result.outcome |
| 177 |
result.exit_code |
| 178 |
result.message |
| 179 |
result.post_command_state |
| 180 |
result.feedback |
| 181 |
} |