Files
Agent-System/internal/app/intentflow/errors.go
T
weichen 6a3a0dc201 fix(security): harden bypass authz, gate blind spot, command exec, validated_only (review P0/P1)
- FIND-SEC-01: GetUserContext requires session ownership (handler 403 +
  SQL/memory owner filter); in-memory HTTP + isolated-PG regressions
- FIND-ARCH-01: archtest fails closed on untracked table writes (+noise
  exemption) and registers 50 existing writer tables in table_owners
- FIND-SEC-02: Authorizer without pool denies by default; explicit
  NewInMemoryAuthorizer seam opt-in via ALLOW_IN_MEMORY at composition
- FIND-SEC-03: swboot commands run argv-exec (no sh -c) with exact
  basename allowlist match; prefix-spoof and no-shell-eval tests
- FIND-FLOW-01: confirm rejects validated_only plans; ExecuteClaimed
  hard-refuses validated_only steps (new error codes + HTTP mapping)
- FIND-QUAL-01: intentflow.ValidateFlagConsistency fail-fast at Assemble
2026-09-26 02:00:14 +00:00

60 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package intentflow
import "errors"
// Sentinel errors use the public API error codes from the design §9.
var (
ErrPlanNotFoundOrHidden = errors.New("PLAN_NOT_FOUND_OR_HIDDEN")
ErrPlanStaleRevision = errors.New("PLAN_STALE_REVISION")
ErrPlanExpired = errors.New("PLAN_EXPIRED")
ErrPlanDecisionConflict = errors.New("PLAN_DECISION_CONFLICT")
ErrPlanDependencyInvalid = errors.New("PLAN_DEPENDENCY_INVALID")
ErrPlanActionForbidden = errors.New("PLAN_ACTION_FORBIDDEN")
ErrPlanActionVersionConflict = errors.New("PLAN_ACTION_VERSION_CONFLICT")
ErrUnauthenticated = errors.New("ERR_UNAUTHENTICATED")
// FIND-FLOW-01 回归:validated_only(shadow/dry-run)计划的硬边界。
// Confirm 不得把 validated_only 计划推入 executing;执行器也不得
// 对 validated_only 步骤做真实副作用——安全契约由代码硬拒,不依赖
//「没人点 Confirm」。
ErrPlanModeNotConfirmable = errors.New("PLAN_MODE_NOT_CONFIRMABLE")
ErrPlanModeNotExecutable = errors.New("PLAN_MODE_NOT_EXECUTABLE")
)
var errTurnExists = errors.New("intentflow: turn exists")
// ErrorCode returns the stable machine code for a sentinel, or empty.
func ErrorCode(err error) string {
switch {
case errors.Is(err, ErrPlanNotFoundOrHidden):
return "PLAN_NOT_FOUND_OR_HIDDEN"
case errors.Is(err, ErrPlanStaleRevision):
return "PLAN_STALE_REVISION"
case errors.Is(err, ErrPlanExpired):
return "PLAN_EXPIRED"
case errors.Is(err, ErrPlanDecisionConflict):
return "PLAN_DECISION_CONFLICT"
case errors.Is(err, ErrPlanDependencyInvalid):
return "PLAN_DEPENDENCY_INVALID"
case errors.Is(err, ErrPlanActionForbidden):
return "PLAN_ACTION_FORBIDDEN"
case errors.Is(err, ErrPlanActionVersionConflict):
return "PLAN_ACTION_VERSION_CONFLICT"
case errors.Is(err, ErrPlanModeNotConfirmable):
return "PLAN_MODE_NOT_CONFIRMABLE"
case errors.Is(err, ErrPlanModeNotExecutable):
return "PLAN_MODE_NOT_EXECUTABLE"
case errors.Is(err, ErrUnauthenticated):
return "ERR_UNAUTHENTICATED"
case errors.Is(err, ErrSegmentProposalDisabled):
return "SEGMENT_PROPOSAL_DISABLED"
case errors.Is(err, ErrSegmentProposalMalformed):
return "SEGMENT_PROPOSAL_MALFORMED"
case errors.Is(err, ErrSegmentProposalTimeout):
return "SEGMENT_PROPOSAL_TIMEOUT"
case errors.Is(err, ErrSegmentProposalOutOfBounds):
return "SEGMENT_PROPOSAL_OUT_OF_BOUNDS"
default:
return ""
}
}