You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a gate command that remembers allowed steps between calls - #720
A hook or script runs once per command, so it cannot hold a trace in memory the way the MCP server does. sop-mcp-server gate asks the barrier about one step and keeps the allowed steps in a small file per session. Exit 0 allowed, 1 blocked with the reason and the steps to run first, 2 usage error. A session name cannot contain a path, a blocked step records nothing, and a saved file that no longer matches the runbook is refused instead of trusted.
Seven tests pass with -race, and I ran plan and apply by hand: apply first is blocked, plan is allowed, apply after plan is allowed. This orders steps only. It does not run anything.
cmd/sop-mcp-server/gate.go: The gateSessionRE regular expression (^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$) used to validate session names is effective in preventing path traversal attacks by disallowing characters like /, \, and ... Combined with filepath.Join and strict file permissions (0o700 for directories, 0o600 for files), this ensures session files are stored securely and predictably within the designated state directory.
cmd/sop-mcp-server/gate.go: The saveGateState function implements an atomic write operation using os.CreateTemp followed by os.Rename. This design prevents data corruption or loss in the event of a crash during file writing, ensuring the integrity of the session state.
cmd/sop-mcp-server/gate.go: The loadGateTrace function includes a critical correctness check by replaying all previously recorded steps against the current workflow rules (wf.CheckAndCommit). If any saved step no longer passes the runbook (e.g., due to a runbook update), it returns an error and forces a session reset. This prevents the system from silently operating under outdated or inconsistent rules.
cmd/sop-mcp-server/gate_test.go: The test TestGateRefusesStateThatNoLongerMatchesTheRunbook specifically verifies the robust error handling for cases where saved session state becomes inconsistent with a modified runbook. This is an excellent test for an important edge case and demonstrates strong correctness.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A hook or script runs once per command, so it cannot hold a trace in memory the way the MCP server does. sop-mcp-server gate asks the barrier about one step and keeps the allowed steps in a small file per session. Exit 0 allowed, 1 blocked with the reason and the steps to run first, 2 usage error. A session name cannot contain a path, a blocked step records nothing, and a saved file that no longer matches the runbook is refused instead of trusted.
Seven tests pass with -race, and I ran plan and apply by hand: apply first is blocked, plan is allowed, apply after plan is allowed. This orders steps only. It does not run anything.
Thanks,
Gerard