Skip to content

v4.2.3: task-metadata hook moves to PreToolUse(TaskCreate) - #63

Merged
NOGIT007 merged 2 commits into
mainfrom
fix/task-hook-envelope-agnostic
May 12, 2026
Merged

NOGIT007 merged 2 commits into
mainfrom
fix/task-hook-envelope-agnostic

Conversation

@NOGIT007

@NOGIT007 NOGIT007 commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR landed in two iterations driven by what the diagnostic dump revealed:

v4.2.2 (commit 7555fb3) — Made the extractor envelope-agnostic and added on-rejection payload dump to $TMPDIR/code-et-task-hook/last-rejected.json. Necessary instrumentation because auto-mode (correctly) refused to let an agent self-modify a plugin hook to capture the live payload.

v4.2.3 (commit 94117e2) — The dump revealed the actual bug: hook was wired to the TaskCreated lifecycle event, whose payload is flat (task_id, task_subject, task_description) with no tool_input or metadata. Every well-formed call was rejected because the script read a field lifecycle events never carry. Moved to PreToolUse matched on TaskCreate — fires before task creation with raw tool_input (including metadata) intact, per TaskCreate's tool schema.

Both layers stay: v4.2.2's extractor + rejection dump are kept as defence-in-depth for the next time the envelope drifts.

Test plan

  • bats code-et-implementer/tests/task-created-tag-check.bats — 14/14 pass (7 original + 5 envelope-shape regressions from 4.2.2 + 2 new PreToolUse-envelope regressions).
  • Manual smoke: real PreToolUse(TaskCreate) envelope with metadata → exit 0; same envelope without metadata → exit 2 + dump written.
  • After merge: /plugin update code in the blocked session, retry the failing TaskCreate call — should pass when metadata is supplied, reject pre-creation when omitted.

🤖 Generated with Claude Code

NOGIT007 and others added 2 commits May 12, 2026 14:36
… reject

v4.2.1 normalised stringified `tool_input.metadata` but the same hook kept
rejecting valid TaskCreate calls in other sessions. Direct shell tests
passed; the live harness still failed — symptom of a different envelope
shape we couldn't see, because auto-mode (correctly) refuses to let an
agent self-modify a plugin hook to capture the live payload.

Make `scripts/task-created-tag-check.sh` envelope-agnostic. Extraction
tries, in order: `tool_input.metadata` (object or JSON-string),
`tool_input` (fields flattened directly), `.metadata` (no wrapper),
payload-as-string parsed once, then a deep search across the JSON tree
for `user_story` / `layer`. Whatever shape the harness uses, valid
metadata is found.

On rejection, write the raw payload + extraction trace to
`$TMPDIR/code-et-task-hook/last-rejected.json` and reference that path
in the error message. Next failure leaves the actual envelope on disk
— no wrapper script, no auto-mode prompt.

Twelve bats payload-shape regressions pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
v4.2.2's diagnostic dump captured the live payload and revealed the
real bug: the hook was wired to the TaskCreated *lifecycle* event,
which fires after the task is in the store with a flat envelope
(session_id, hook_event_name, task_id, task_subject, task_description)
— no tool_input, no metadata. Every well-formed TaskCreate was getting
rejected because the script read a field that lifecycle events never
carry.

TaskCreate's tool schema confirms metadata is a top-level call param,
so the correct hook is PreToolUse matched on TaskCreate. Fires before
the task is created with raw tool_input (including metadata) intact —
agents that forget metadata get rejected pre-creation instead of
orphaning a malformed task, and the existing extractor's first path
(.tool_input.metadata) now matches the real envelope on the first try.

Keeps v4.2.2's envelope-agnostic extractor and rejection-time payload
dump — both still pay off the next time the contract drifts. Two new
bats cases cover the real PreToolUse(TaskCreate) envelope (14/14).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NOGIT007 NOGIT007 changed the title v4.2.2: TaskCreated hook accepts any envelope, dumps payload on reject v4.2.3: task-metadata hook moves to PreToolUse(TaskCreate) May 12, 2026
@NOGIT007
NOGIT007 merged commit d239845 into main May 12, 2026
1 check passed
@NOGIT007
NOGIT007 deleted the fix/task-hook-envelope-agnostic branch May 12, 2026 12:51
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