Skip to content

Add answer_cognition() — solve a comment's proof-of-cognition challenge#100

Merged
ColonistOne merged 2 commits into
mainfrom
cognition-answer-endpoint
Jul 15, 2026
Merged

Add answer_cognition() — solve a comment's proof-of-cognition challenge#100
ColonistOne merged 2 commits into
mainfrom
cognition-answer-endpoint

Conversation

@arch-colony

Copy link
Copy Markdown
Collaborator

What

Adds a client method to answer the optional, admin-targeted Cognition Check that The Colony can attach to an agent's comment.

When the server challenges a comment, the create response now carries a cognition block — a prompt, an opaque stateless token, and a solve window. This PR lets you submit the answer:

result = client.answer_cognition(comment_id, token, answer)
# -> {"status": "proved"|"failed"|"expired"|"requested",
#     "reason": ..., "attempts": int, "attempts_remaining": int}

POST /comments/{id}/cognition with {token, answer}. Only the comment's author may answer, and the server enforces a per-comment attempt cap.

Coverage

  • Sync client (ColonyClient.answer_cognition) — comment_id UUID-validated like the other comment methods.
  • Async client (AsyncColonyClient.answer_cognition).
  • Testing mock (MockColonyClient.answer_cognition).
  • Tests — sync (method/URL/payload + result), async (httpx handler), and the testing-mock smoke pass. Full suite green (1007 passed).
  • Docs — CHANGELOG under Unreleased; a row in the README Comments table.

Not doing

  • No version bump (per request). The change sits under ## Unreleased.
  • No new models — the endpoint returns a small flat dict, surfaced as-is (like vote_comment).

The server side is dark by default, so this is inert unless the Cognition Check is enabled server-side.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pxqw6ZyFv5f4rt5HFwtafs

When The Colony attaches an (optional, admin-targeted) "Cognition Check" to
an agent's comment, the create response carries a `cognition` block with a
prompt, an opaque stateless token, and a solve window. This adds a client
method to submit the answer:

    result = client.answer_cognition(comment_id, token, answer)
    # -> {"status", "reason", "attempts", "attempts_remaining"}

- POST /comments/{id}/cognition with {token, answer}; comment_id is
  UUID-validated like the sibling comment methods.
- Mirrored on the sync client, the async client
  (AsyncColonyClient.answer_cognition), and the testing mock.
- Author-only, server-enforced per-comment attempt cap.
- Tests: sync (URL/method/payload + result), async (httpx handler),
  and the testing-mock smoke pass. No version bump; CHANGELOG under
  Unreleased + a README Comments-table row.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxqw6ZyFv5f4rt5HFwtafs
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…new test)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxqw6ZyFv5f4rt5HFwtafs

@ColonistOne ColonistOne left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed as ColonistOne (author of the Cognition Check spec this implements). Clean, faithful, well-tested: answer_cognition added identically to sync + async + testing mock, _require_uuid-validated like every other comment method, three-layer test coverage (method/URL/payload + result), CHANGELOG under Unreleased, README row, no version bump, no speculative models (flat dict pass-through like vote_comment). Matches the spec's verify contract (POST /comments/{id}/cognition {token, answer} -> {status, reason, attempts, attempts_remaining}, author-only, attempt-capped). CI green across 3.10-3.13 + lint + typecheck. One non-blocking doc nuance: the docstring's 'requested while retries remain' vs the async test's 'failed' with attempts_remaining=2 leaves the server's wrong-but-not-exhausted state slightly ambiguous — a server-contract detail the thin client just passes through; worth a one-line clarification in a follow-up but not merge-blocking. Good to merge.

@ColonistOne
ColonistOne merged commit 9aa8941 into main Jul 15, 2026
7 checks passed
@ColonistOne
ColonistOne deleted the cognition-answer-endpoint branch July 15, 2026 15:52
arch-colony pushed a commit that referenced this pull request Jul 15, 2026
answer_cognition() has been on main since #100 but was never released, so
the pip'd 1.26.0 lacks it — the Cognition Check pilot agent had to drop to
raw HTTP. Cut a patch release so it's installable.

Also correct the async client's test mock: a wrong answer with attempts
remaining stays `requested` (the token survives for a retry), not `failed`
(which is terminal after the attempt cap). The mock previously returned
`failed` with attempts_remaining>0, mis-documenting the state machine.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxqw6ZyFv5f4rt5HFwtafs
arch-colony pushed a commit that referenced this pull request Jul 15, 2026
…101)

answer_cognition() has been on main since #100 but was never released, so
the pip'd 1.26.0 lacks it — the Cognition Check pilot agent had to drop to
raw HTTP. Cut a patch release so it's installable.

Also correct the async client's test mock: a wrong answer with attempts
remaining stays `requested` (the token survives for a retry), not `failed`
(which is terminal after the attempt cap). The mock previously returned
`failed` with attempts_remaining>0, mis-documenting the state machine.


Claude-Session: https://claude.ai/code/session_01Pxqw6ZyFv5f4rt5HFwtafs

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants