Add docs/16 for session state machine, incomplete/resume, queue semantics, and agent-loop/harness/MCP gap review. Wire RunOutcome on max-rounds, run_id through audit, TrimMessages/Redact hooks, ConfirmBindHash on write confirm path; session file skeleton without HTTP yet. No push.
30 lines
940 B
Go
30 lines
940 B
Go
package aitools
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ConfirmBindHash 绑定 connection + 规范化语句;改语句则哈希变,须重确认。
|
|
func ConfirmBindHash(connectionID, statement string) string {
|
|
connectionID = strings.TrimSpace(connectionID)
|
|
statement = strings.Join(strings.Fields(strings.TrimSpace(statement)), " ")
|
|
sum := sha256.Sum256([]byte(connectionID + "\n" + statement))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|
|
|
|
// VerifyConfirmBind 校验客户端带回的 bind;空 bind 视为不合法(桌面路径必须带)。
|
|
func VerifyConfirmBind(connectionID, statement, bind string) error {
|
|
bind = strings.TrimSpace(bind)
|
|
if bind == "" {
|
|
return fmt.Errorf("confirmBind required")
|
|
}
|
|
want := ConfirmBindHash(connectionID, statement)
|
|
if !strings.EqualFold(bind, want) {
|
|
return fmt.Errorf("confirmBind mismatch: statement or connection changed; re-confirm required")
|
|
}
|
|
return nil
|
|
}
|