Skip to content

feat(guard): planner and main-agent hooks, target-gate scope in every session (S3b 1.1) - #177

Merged
BaaRai merged 1 commit into
mainfrom
feat/target-gate-hooks-scope
Nov 10, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/target-gate-hooks-scope

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Step 1.1 of the S3b phase 1 plan (approval gate for asset targets): hooks on the planner and the main agent, and a target-gate scope in every session. Wiring only. The gate itself (schema, opt-in flag, requests, extraction, resolver, enforcement) is in later steps and not in this PR.

What changes

  • Planner and main agent run with hooks. (*Planner).Plan and (*MainAgent).Chat take a hooks harness.HookRunner parameter, with the same position and typed-nil guard as (*Worker).Execute. Until now their sessions set no hooks, so nothing saw their tool calls before execution.
  • guard.NewTargetOnly(ic). The guard for those two agent kinds. Its applyIntercept runs the target-gate seam and nothing else: no intercept rule, no fallback judge.
  • Task.TargetGuard, built beside Task.Guard in taskFromPG, passed to the planner (regular and final round) and to the main agent.
  • intercept.WithTargetScope / TargetScopeFromContext. The scope is a task id or a conversation id, an Enabled func() bool and a wait bound. It is set at the five session entry points: planner round, final planner round (wait bound 0), main-agent turn, worker intent, conversation turn (chat and retester share it).
  • The planner and main-agent contexts also get intercept.WithTaskContext (agent names planner and mainagent, with an emit that stamps the lane), as the worker context already has.

Behaviour

None changes, for any task or conversation:

  • The seam (Guard.targetGate) allows every call unconditionally. It extracts nothing, resolves nothing, and reads and writes nothing.
  • No task or conversation has an opt-in flag yet, so TargetScope.Enabled is nil (off) at every call site.
  • The hooks now attached to the planner and the main agent are a registry with one PreToolUse handler that returns the empty result: no block, no input rewrite. There is no PostToolUse, Stop or prompt handler on it.
  • Worker and chat keep the same guard, rules and judge. Their contexts carry one more value.
  • The task context added to the planner and the main agent is read only by Interceptor.Log and Interceptor.HandleAsk, which the target-only guard never calls.

Guard.record

Guard.record is not touched, and the target-only guard stays out of it: planner and main-agent calls are not written to any audit ring. The 2000-entry ring of Task.Guard keeps holding worker calls only, and GET /api/audit (which reads Task.Guard) returns what it returned before. The target-only guard also registers no PostToolUse handler, so the failure-attribution counters stay worker-only.

Where this differs from the plan text

  • The scope reader is exported as TargetScopeFromContext (the plan names it targetScopeFromCtx). The tests the plan lists for this step in agent and server have to read the scope from another package.
  • TestChatToolCallReachesHooks: the plan describes recording hooks that block. ChatAgent takes a *guard.Guard (SetGuard), not a hook runner, so the test uses the guard's audit ring as the recorder and a read-only LS call instead of a blocked command. ChatAgent itself is unchanged.
  • intercept.DefaultTargetWaitBound is 300 s, the default the plan recommends in D6. Nothing reads it yet; the final planner round passes 0.

Tests

  • guard: TestTargetOnlyGuardSkipsRules. The target-only guard runs on an interceptor with no database, so any store access would panic; a control shows the full guard does reach the store. No block, no rewritten input, no audit entry, no attribution count.
  • agent: TestPlannerToolCallReachesHooks, TestMainAgentToolCallReachesHooks, TestWorkerToolCallReachesHooks (PostgreSQL, real entry points, scripted provider, blocking recording hooks: the hook sees the call on a context carrying the task scope and the command does not run), TestChatToolCallReachesHooks (no database).
  • server: TestSteerHooksForwardInnerBlock (no database), TestEveryAgentKindCarriesTargetScope (PostgreSQL, table over the five entry points: each session carries its task or conversation scope with the gate off, and the planner and main-agent tool calls land on Task.TargetGuard while the worker's land on Task.Guard), TestFinalPlannerRoundHasZeroWait, TestTargetGateSeamAllowsWithoutDBWrite (through Task.TargetGuard a call that a deny rule blocks and logs on Task.Guard is allowed, with no intercept_pending row and no audit entry).

Local run (Go 1.26.7, PostgreSQL 16.15, freshly created databases): go build ./... and go vet ./... clean; go test -p 1 ./... passes in every package; go test -race -p 1 on the CI package list passes.

… session (S3b 1.1)

Step 1.1 of the S3b phase 1 plan. Wiring only: the approval gate for asset
targets is not enforced yet and no behaviour changes.

- Planner.Plan and MainAgent.Chat take a hooks parameter, like Worker.Execute.
  Their sessions had no hooks, so nothing saw their tool calls before execution.
- guard.NewTargetOnly: the guard for those two agent kinds. It runs the
  target-gate seam only: no intercept rule, no fallback judge, and no entry in
  the audit ring (Guard.record is untouched and not called for these calls).
- Task.TargetGuard, built beside Task.Guard.
- intercept.WithTargetScope / TargetScopeFromContext: task id or conversation
  id, an Enabled func and a wait bound, set at the five session entry points
  (planner round, final planner round with wait bound 0, main-agent turn,
  worker intent, conversation turn).

The seam allows every call and reads and writes nothing. No task or
conversation has an opt-in flag yet, so Enabled is nil (off) everywhere.
@BaaRai
BaaRai merged commit ce9f4d0 into main Nov 10, 2026
4 checks passed
usinfosec pushed a commit to usinfosec/ARTEX that referenced this pull request Nov 17, 2026
- 后端 traffic.Page 改为 PageQuery:新增响应内容(FTS)、路径(url_template)、
  状态码(精确/Nxx 分桶)、响应长度范围筛选,并支持按 ts/status/resp_len 排序
  (尾随 id DESC 保证分页稳定);补 status/resp_len 两个索引(IF NOT EXISTS,旧库自动生效)
- server getTraffic 解析 body/path/status/resp_min/resp_max/sort/order 参数
- 前端流量页新增高级筛选行(响应内容/路径/状态码/长度范围)与可排序表头,
  排序偏好持久化到 localStorage;抽出公共组件 ui/sortable-head
- 仅改动前端页走的 Page,不动 Agent 工具的 query 契约
usinfosec pushed a commit to usinfosec/ARTEX that referenced this pull request Nov 17, 2026
…er-sort

feat(traffic): 流量列表支持内容检索、路径/状态码/长度筛选与列排序 (BaaRai#177)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant