Files
PaperClipAI/packages/paperclip-runner/generated
DottaandPaperclip 3833e1c8e8 feat(runner): add channel, kvLabels, schemaBlocks, and resultSchemaRef parity to native task tools (#23406)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Native Runner agents coordinate tasks, progress updates, and
searches through semantic protocol tools (`create_task`,
`report_progress`, `search_tasks`, `get_task_context`, and
`get_task_history`)
> - Headless API clients already use channels, key-value labels
(`kvLabels`), validated `<name>@<version>` schema blocks
(`schemaBlocks`), and required completion schemas (`resultSchemaRef`),
while native Runner tools omitted those fields
> - Because native Runner tools omitted those fields, native agents
could not file tasks into channels, filter task searches by channel or
label, attach structured schema blocks to progress updates, or verify
`resultSchemaRef` before completion
> - This pull request adds channel, `kvLabels`, `schemaBlocks`, and
`resultSchemaRef` support across native Runner tool schemas, authority
handlers, completion validation, and `skills/paperclip/SKILL.md`
> - The benefit is full structured-metadata and channel parity for
native Runner agents while preserving strict provider tool schemas,
private channel boundaries, and upgrade-safe receipt replay

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Native Runner task tools (`create_task`, `report_progress`,
`search_tasks`, `get_task_context`, and `get_task_history`), native
deliverable completion checks (`validateNativeDeliverableEvidence`), and
`skills/paperclip/SKILL.md`.

**Subsystem affected**
Cross-cutting (multiple of the above)

**Current behavior**
Currently, native Runner semantic tools (`create_task`,
`report_progress`, and `search_tasks`) do not accept `kvLabels`,
`channel`, `labelFilter`, `schemaBlocks`, or `resultSchemaRef`. Read
tools (`get_task_context`, `get_task_history`, and `search_tasks`) omit
`channelId`, `channelPath`, `kvLabels`, `resultSchemaRef`, and
`schemaBlocks`. In addition, `validateNativeDeliverableEvidence` does
not check `issues.resultSchemaRef` before a native run marks a task
`done`.

**Proposed behavior**
`create_task` accepts optional `kvLabels`, `resultSchemaRef`, and
`channel` inputs and returns `channelId`, `channelPath`, `kvLabels`, and
`resultSchemaRef` on `result.task`. `report_progress` accepts optional
`kvLabels` and `schemaBlocks` inputs and extracts `json
schema=<name>@<version>` fenced blocks from `body` with a single-pass
`O(N)` line scanner. `search_tasks` accepts optional `labelFilter` and
`channel` filters (exact path, subtree prefix, or UUID) while preserving
cursor pagination and private channel access checks. `get_task_context`
and `search_tasks` return `channelId`, `channelPath`, `kvLabels`,
`resultSchemaRef`, and `schemaBlocks`, and `get_task_history` returns
`actorProfile`, `kvLabels`, and `schemaBlocks` (clearing metadata on
quarantined comments for higher-trust readers). When
`issues.resultSchemaRef` is set, `validateNativeDeliverableEvidence`
requires a valid matching JSON payload before completion, and final
reply comments persist valid fenced schema blocks onto
`issue_comments.schema_blocks`.

**Reason and benefit**
Agents running on the native Runner protocol need the same channel
routing, key-value metadata, and structured JSON schema contracts that
REST and headless workflows use. Enforcing `resultSchemaRef` at the
native deliverable gate prevents native runs from closing tasks without
valid structured output.

**Breaking changes**
None. All new tool input and output properties are optional. Existing
tool calls and saved mutation receipts without the new fields continue
to validate and replay without change.

**Additional context**
Tool input schemas use strict provider-portable array entries for
`kvLabels` (`{ key, value }`) and `schemaBlocks` (`{ schema, version,
dataJson }`) so OpenAI/Codex dynamic tools, AgentCore inline schemas,
Ajv strict mode, and RE2 checks all pass without open object maps.

## What Changed

- Extend `create_task`, `report_progress`, and `search_tasks` in
`packages/paperclip-runner/src/protocol-actions/` and
`src/catalog/semantic-action-catalog.ts`, and regenerate contract
manifests, capability YAML/Markdown, capability inventory, and seeded
eval fixtures.
- Add `native-schema-fences.ts`, `native-task-channels.ts`, and
`native-result-schema-gate.ts` (re-exported by
`native-task-metadata.ts`) with a linear `O(N)` single-pass CommonMark
fence scanner (`scanFencedSchemaBlocks`), `kvLabels` normalization,
transactional `schemaBlocks` persistence, a 128 KiB response-wide
`schemaBlocks` budget with truncation metadata, private-channel
authorization helpers, and run-scoped
`assertNativeResultSchemaSatisfied`.
- Update `PaperclipRunnerToolAuthority` (`get_task_context`,
`get_task_history`, `search_tasks`, `#reportProgress`, and
`#createTask`) for read/write parity, private-channel redaction,
quarantined comment `actorProfile`/`kvLabels`/`schemaBlocks` redaction,
and `channel` scope inclusion on filtered searches.
- Wire `assertNativeResultSchemaSatisfied` into
`validateNativeDeliverableEvidence` and persist valid fenced schema
blocks on final reply comments in `native-run-finalizer.ts` and
`run-completion.ts`.
- Document `kvLabels`, `channelPath`, `schemaBlocks`, `resultSchemaRef`,
and `PATCH /api/issues/{issueId}/kv-labels` in
`skills/paperclip/SKILL.md`.
- Add unit, ReDoS linear-time (`< 50ms` on 5,000 unclosed fences),
integration, private-channel, completion-gate, and upgrade-cutover
receipt replay tests.

## Verification

- `pnpm --filter @paperclipai/paperclip-runner typecheck:typescript`
- `pnpm --filter @paperclipai/paperclip-runner check:protocol-manifest`
- `pnpm --filter @paperclipai/paperclip-runner
check:capability-contract`
- `pnpm --filter @paperclipai/paperclip-runner check:semantic-contracts`
- `pnpm --filter @paperclipai/paperclip-runner
check:semantic-action-catalog`
- `pnpm --filter @paperclipai/paperclip-runner check:replay-goldens`
- `pnpm --filter @paperclipai/paperclip-runner test:typescript:prep`
- `pnpm --filter @paperclipai/paperclip-runner check:static`
- `pnpm --filter @paperclipai/paperclip-runner check:api-authority`
- `pnpm --filter @paperclipai/paperclip-runner exec vitest run
src/protocol-actions/collaboration-contracts.test.ts
src/protocol-actions/core-contracts.test.ts
src/catalog/semantic-action-catalog.test.ts
src/contracts/provider-tool-schema-shape.test.ts
src/drivers/runner-tool-bridge.schemas.test.ts
src/evals/native-execution.test.ts
src/semantic-tools/semantic-tools.test.ts
src/mock-core/capability-mock-control-plane-adapter.test.ts`
- `node
packages/paperclip-runner/scripts/contracts/contract-fingerprints.test.mjs`
- `(cd server && node scripts/typecheck-layers.mjs)`
- `node scripts/check-test-budget.mjs`
- `pnpm --filter @paperclipai/server exec vitest run
src/services/native-runtime/native-task-metadata.test.ts
src/services/native-runtime/tool-input-variant-admission.test.ts
src/services/native-runtime/native-completion-feedback.test.ts
src/services/native-runtime/paperclip-runner-tool-authority.test.ts`

## Risks

- **Upgrade-safe run state carry-forward
(`rules/upgrade-safe-run-state.mdc`)**: In-flight native runs started on
a previous release may carry saved `semanticToolReceipts` in
`heartbeat_runs.result_json` for `create_task` and `report_progress`
without `kvLabels`, `resultSchemaRef`, `channel`, or `schemaBlocks`. All
new fields are optional, `#withMutationReceipt` hashes raw caller
`input` without mutating missing keys, and `create_task`
`outputSchema.properties.task.required` is unchanged. Previous-release
receipts replay identically on `recover()` and `execute()` without
re-running effects, verified by a dedicated cutover test in
`paperclip-runner-tool-authority.test.ts`.
- **Markdown scanning safety**: Fenced schema extraction uses a bounded
`O(N)` line scanner (512 KiB max markdown scan, 64 KiB max fence body,
64 max candidate fences, zero multi-line backreference regular
expressions) so untrusted or malformed markdown cannot cause quadratic
backtracking.

## Model Used

- Anthropic Claude Opus 4.6 (`claude-opus-4-6`, extended thinking
enabled, agentic tool use and local command execution)

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-12-01 15:53:37 -06:00
..