Skip to content

[docs][plugin sdk] Split host-hook recipes from workflow follow-ups#74853

Closed
100yenadmin wants to merge 1 commit into
openclaw:mainfrom
electricsheephq:docs/plugin-sdk-host-hook-recipes-split
Closed

[docs][plugin sdk] Split host-hook recipes from workflow follow-ups#74853
100yenadmin wants to merge 1 commit into
openclaw:mainfrom
electricsheephq:docs/plugin-sdk-host-hook-recipes-split

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Describe the problem and fix in 2-5 bullets:

  • Problem: OpenClaw's Plugin SDK now has many useful host/workflow seams, but the docs did not give plugin authors or AI agents a single product-neutral recipe map for composing them safely.
  • Why it matters: without a concrete recipe guide, authors either overfit on Plan Mode, miss the grouped SDK namespaces, or try to patch core for workflows that can now be built as plugins.
  • What changed: this PR adds a long-form host-hook recipe page, wires it into docs navigation, links it from the Plugin SDK overview/hooks docs, and refreshes glossary coverage required by docs CI.
  • What did NOT change (scope boundary): this is docs-only. It does not change runtime behavior, plugin permissions, Gateway methods, SDK exports, auth/OAuth provider hooks, or any build/package surface.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Why this PR exists

The SDK surface is no longer just a flat registerTool(...) story. Current OpenClaw has grouped host-hook families for session state, workflow continuation, session controls, agent events, per-run context, and runtime lifecycle cleanup. That is powerful, but it is also easy to misread if the docs only expose API tables.

This PR turns that surface into a recipe book. The new page answers the author-facing question directly:

If I want my plugin to do X, which host-hook contracts do I compose, and what does that look like end-to-end?

The examples are intentionally product-neutral. Plan Mode is one tenant of these seams, not the privileged one. The same contracts can support approval workflows, workspace policy gates, background monitors, setup wizards, review assistants, release workflows, and future bundled plugins.

Reviewer guide

Changed files

File Purpose
docs/plugins/host-hooks-examples.md New recipe guide with 18 host-hook recipes, diagrams, examples, pitfalls, cleanup behavior, and test guidance.
docs/plugins/sdk-overview.md Links the overview page to the new workflow-recipes page and keeps grouped SDK guidance discoverable.
docs/plugins/hooks.md Updates session-extension/next-turn injection examples to grouped namespaces and links to the recipes.
docs/docs.json Adds the new page to the plugin docs navigation.
docs/.i18n/glossary.zh-CN.json Adds required glossary labels, including current-main labels needed for docs:check-i18n-glossary.

How the recipe page is structured

The new page deliberately uses the same structure for every recipe:

  1. What it does
  2. Contract excerpt
  3. Minimal example
  4. Diagram
  5. Real-world example
  6. Common pitfalls

This makes the page usable both for humans and for AI agents that need a stable pattern to follow.

System flow

flowchart LR
  A[Plugin entry: definePluginEntry] --> B[Grouped host-hook APIs]
  B --> C[Session state, actions, UI descriptors]
  B --> D[Next-turn injection, schedules, attachments]
  B --> E[Agent events, run context, lifecycle cleanup]
  C --> F[Workflow plugin recipes]
  D --> F
  E --> F
Loading

Documentation routing

flowchart TD
  Start[Plugin author asks: what can I build?]
  Start --> Tools{Only static agent tools?}
  Tools -->|yes| ToolDocs[Tool Plugins]
  Tools -->|no| Provider{Provider auth, OAuth, runtime auth, model catalog?}
  Provider -->|yes| ProviderDocs[Provider Plugins + Architecture Internals]
  Provider -->|no| Runtime{Host-owned model calls or runtime utilities?}
  Runtime -->|yes| RuntimeDocs[Runtime helpers]
  Runtime -->|no| Hooks[Host-hook examples and recipes]
  Hooks --> Workflow[Approval flows, policy gates, monitors, wizards, review assistants]
Loading

Current grouped host-hook surface covered

Group Authoring surface What the recipe teaches
Session state api.session.state.registerSessionExtension(...) JSON-compatible plugin state, Gateway row projection, optional SessionEntry slot mirrors.
Workflow continuation api.session.workflow.enqueueNextTurnInjection(...) Exactly-once next-turn context for approvals, policy summaries, and command continuations.
Workflow jobs api.session.workflow.registerSessionSchedulerJob(...) Cleanup ownership for plugin-owned scheduler jobs.
Bundled workflow helpers sendSessionAttachment(...), scheduleSessionTurn(...), unscheduleSessionTurnsByTag(...) Host-mediated attachments and Cron-backed scheduled turns, clearly marked bundled-only.
Session controls api.session.controls.registerSessionAction(...) Gateway-mediated action dispatch with scopes, schema validation, and structured results.
Control UI descriptors api.session.controls.registerControlUiDescriptor(...) Data-only UI contribution descriptors; clients own rendering.
Agent events api.agent.events.registerAgentEventSubscription(...), emitAgentEvent(...) Sanitized subscriptions and plugin-id-scoped event emission.
Run context api.runContext.setRunContext(...), getRunContext(...), clearRunContext(...) Per-run JSON-compatible scratch state cleared on terminal lifecycle.
Lifecycle cleanup api.lifecycle.registerRuntimeLifecycle(...) Idempotent cleanup for sockets, timers, watchers, buffers, and external clients.
Adjacent host policy api.registerTrustedToolPolicy(...), api.registerToolMetadata(...), api.registerCommand(...) Trusted policy, inventory metadata, scoped commands, and command continuation patterns.

Pulling directly from the docs

The opening of the new page frames the work this way:

This doc is a recipe book. It does not re-document the API surface; that is the
job of Plugin SDK overview and Plugin hooks. Instead, every section here answers
a single question: if I want my plugin to do X, which host-hook contracts do I
compose, and what does that look like end-to-end?

The quick-start block then gives authors the current grouped API map:

register(api) {
  // Existing surfaces you already know:
  //   api.registerTool(...), api.registerCommand(...), api.on(...)
  //
  // Current grouped host-hook surfaces:
  //   api.session.state.registerSessionExtension(...)
  //   api.session.workflow.enqueueNextTurnInjection(...)
  //   api.session.workflow.registerSessionSchedulerJob(...)
  //   api.session.workflow.sendSessionAttachment(...)        // bundled-only
  //   api.session.workflow.scheduleSessionTurn(...)          // bundled-only
  //   api.session.workflow.unscheduleSessionTurnsByTag(...)  // bundled-only
  //   api.session.controls.registerSessionAction(...)
  //   api.session.controls.registerControlUiDescriptor(...)
  //   api.agent.events.registerAgentEventSubscription(...)
  //   api.agent.events.emitAgentEvent(...)
  //   api.runContext.setRunContext(...) / getRunContext(...) / clearRunContext(...)
  //   api.lifecycle.registerRuntimeLifecycle(...)
}

Two important examples of source-aligned polish in this PR:

  • GatewaySessionRow.pluginExtensions is described as an array of { pluginId, namespace, value } entries, not a nested object. Any nested lookup map is explicitly client-derived.
  • External plugin event emission now uses plugin-id-scoped streams (pluginId or ${pluginId}.*) and calls out that host-reserved streams like lifecycle, assistant, tool, and approval are bundled-only.

How selected recipes work

Session state projection

sequenceDiagram
  autonumber
  participant Plugin
  participant Reg as Registry
  participant Store as Session Store
  participant GW as Gateway
  participant UI as Control UI

  Plugin->>Reg: registerSessionExtension({namespace, project, cleanup})
  Note over Reg,Store: namespace + pluginId now valid for sessions.pluginPatch
  UI->>GW: sessions.pluginPatch({pluginId, namespace, value})
  GW->>Reg: validate pluginId, namespace, and operator.admin scope
  Reg->>Store: write namespaced state
  Store-->>GW: { ok, key, value }
  GW-->>UI: { ok, key, value }
  GW-->>UI: sessions.changed notification
  UI->>GW: refresh session row
  GW->>Plugin: build row projection with project({sessionKey, sessionId, state})
  Plugin-->>GW: pluginExtensions[] projection entry
  GW-->>UI: refreshed row and declared slot mirror when enabled
Loading

Control UI descriptors

Control UI contributions are data-only. The plugin supplies a JSON descriptor; clients own rendering. That keeps plugin code out of client surfaces while still letting plugins expose review cards, budget meters, status panels, settings panels, and action-driven UX.

api.session.controls.registerControlUiDescriptor({
  id: "budget-meter",
  surface: "session",
  label: "Budget",
  description: "Per-session spend tracker",
  placement: "header",
  schema: {
    kind: "meter",
    source: {
      kind: "pluginExtension",
      pluginId: "budget-guard",
      namespace: "budget",
    },
    valuePath: "value.spent",
    capPath: "value.capUsd",
    format: "usd",
    warningRatio: 0.8,
    criticalRatio: 1.0,
  },
});

Session action dispatch

sequenceDiagram
  autonumber
  participant Client
  participant Gateway
  participant Registry
  participant Plugin
  participant Agent

  Client->>Gateway: plugins.sessionAction({pluginId, actionId, sessionKey, payload})
  Gateway->>Registry: find action and requiredScopes
  Gateway->>Gateway: validate caller scopes + JSON schema
  Gateway->>Plugin: handler({pluginId, actionId, sessionKey, payload, client})
  Plugin->>Gateway: { result, continueAgent }
  Gateway-->>Client: { ok:true, result, continueAgent }
  Gateway->>Agent: optional continuation path via next-turn injection
Loading

Event emission contract

The event-emission recipe was tightened after review. External plugins must use plugin-id-scoped streams:

api.agent.events.emitAgentEvent({
  runId,
  sessionKey,
  stream: "review-concierge.review",
  data: {
    phase: "summary-ready",
    filesReviewed: 12,
  },
});

That matches src/plugins/agent-event-emission.ts: external plugins cannot emit host-reserved streams and cannot emit streams owned by another plugin id.

Scope boundaries and non-goals

  • Provider auth, OAuth refresh, external credential overlays, provider usage hooks, and runtime-auth hooks are intentionally routed to sdk-provider-plugins and architecture-internals; this page does not duplicate that provider catalog.
  • Simple static tools are routed to tool-plugins; this page focuses on workflow-style host hooks.
  • Host-owned model calls and runtime utilities are routed to sdk-runtime; this page only points authors there.
  • Open/future follow-up seams such as chat-stream renderers, structured-complete helpers, or compaction interception are not documented as shipped APIs here.
  • The PR does not change TypeScript declarations or runtime semantics. It is a documentation and discoverability PR over current source.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: The Plugin SDK docs now expose the current grouped host-hook APIs, correct plugin event stream scoping, and point authors toward the right adjacent docs for tool plugins, provider/OAuth hooks, and runtime helpers instead of stale companion-PR guidance.
  • Real environment tested: Real OpenClaw checkout at /Volumes/LEXAR/repos/openclaw-host-hook-docs on branch docs/plugin-sdk-host-hook-recipes-split-refresh, plus GitHub Actions docs CI for commit 3465338a09.
  • Exact steps or command run after this patch:
pwd
node scripts/check-docs-mdx.mjs docs/plugins/host-hooks-examples.md docs/plugins/hooks.md docs/plugins/sdk-overview.md
node scripts/format-docs.mjs --check
node scripts/check-docs-i18n-glossary.mjs
node scripts/docs-link-audit.mjs
jq empty docs/docs.json && jq empty docs/.i18n/glossary.zh-CN.json && git diff --check
gh pr checks 74853 -R openclaw/openclaw --watch --interval 10
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
$ pwd
/Volumes/LEXAR/repos/openclaw-host-hook-docs

$ node scripts/check-docs-mdx.mjs docs/plugins/host-hooks-examples.md docs/plugins/hooks.md docs/plugins/sdk-overview.md
Docs MDX check passed (3 files, 176ms).

$ node scripts/format-docs.mjs --check
Docs formatting clean (632 files).

$ node scripts/docs-link-audit.mjs
checked_internal_links=4425
broken_links=0

$ node scripts/check-docs-i18n-glossary.mjs
exited 0
  • Observed result after fix: The changed docs pass MDX parsing, docs formatting, i18n glossary validation, JSON parsing, whitespace validation, and internal link audit locally. GitHub checks for commit 3465338a09 passed after the event-stream wording correction and final docs-consistency polish, including check-docs and Real behavior proof.
  • What was not tested: No browser screenshot of the rendered Mintlify page was captured in this pass; this is docs-only and the repository MDX/link/i18n checks cover the changed docs surface.
  • Before evidence (optional but encouraged): Earlier review identified the old event-emission example as wrong because it used plugin.review; current docs now use review-concierge.review, matching plugin-id-scoped stream policy.

Root Cause (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause: N/A for runtime behavior. Documentation drift came from carrying an older host-hook recipe page across a fast-moving SDK stack and then rebasing it after the grouped host-hook APIs landed.
  • Missing detection / guardrail: Bot review correctly caught one remaining source/doc mismatch around plugin event stream scoping; the updated page now matches emitPluginAgentEvent(...) and the contract tests.
  • Contributing context (if known): The Plugin SDK moved from older flat/companion-PR language to grouped namespaces and shipped workflow seams. The PR body and docs now reflect current source instead of old stack-order assumptions.

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write N/A.

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/plugins/contracts/session-actions.contract.test.ts already covers plugin-id-scoped event emission; docs checks cover the changed Markdown/links/navigation.
  • Scenario the test should lock in: workspace plugin event streams must be scoped to the plugin id or rejected; docs examples should not recommend rejected stream names.
  • Why this is the smallest reliable guardrail: the behavior is already locked by the SDK contract test; the PR only needed doc alignment.
  • Existing test that already covers this (if any): session-actions.contract.test.ts accepts workspace-event-plugin.workflow and rejects other-plugin.workflow for the workspace plugin.
  • If no new test is added, why not: docs-only PR; no runtime behavior changed.

User-visible / Behavior Changes

Plugin authors now get a navigable recipe guide for workflow-style host hooks, linked from Plugin SDK overview, Plugin hooks, and the docs sidebar. Runtime users see no behavior change.

Diagram (if applicable)

Before:
[plugin author] -> [SDK overview table + hook catalog] -> [manual inference / stale stack context]

After:
[plugin author] -> [Host-hook examples] -> [recipe by use case]
                -> [current grouped API] -> [pitfalls + tests + cleanup semantics]

Additional system diagram:

flowchart LR
  Author[Plugin author or AI agent] --> Recipe[Host-hook recipe guide]
  Recipe --> State[Session state + projections]
  Recipe --> Workflow[Next-turn context + scheduler ownership]
  Recipe --> Controls[Actions + Control UI descriptors]
  Recipe --> Events[Agent events + run context]
  Recipe --> Cleanup[Lifecycle cleanup matrix]
  Cleanup --> Tests[Contract-test guidance]
Loading

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS local checkout under /Volumes/LEXAR/repos/openclaw-host-hook-docs; GitHub Actions Ubuntu runner for docs CI.
  • Runtime/container: Node scripts from the existing OpenClaw repo checkout; no new install was performed.
  • Model/provider: N/A
  • Integration/channel (if any): GitHub PR [docs][plugin sdk] Split host-hook recipes from workflow follow-ups #74853 and docs CI.
  • Relevant config (redacted): N/A

Steps

  1. Verify working directory is on Lexar.
  2. Run focused docs MDX, formatting, i18n glossary, and link checks.
  3. Inspect current source/contract tests for event-stream scoping.
  4. Update PR body and comments with reviewer-facing docs excerpts and diagrams.
  5. Push commit 3465338a09 and wait for PR checks.

Expected

  • Docs checks pass locally and in GitHub.
  • PR remains mergeable.
  • Real behavior proof gate passes.
  • PR body follows the repository template and contains enough architecture context for reviewers unfamiliar with the stack.

Actual

  • Local docs checks passed.
  • PR branch updated to 3465338a09.
  • GitHub checks on 3465338a09 passed, including check-docs and Real behavior proof.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Evidence is embedded above under Real behavior proof and includes copied terminal output plus the current GitHub check-docs and Real behavior proof checks for 3465338a09.

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: docs syntax, docs formatting, docs link integrity, i18n glossary coverage, JSON validity, whitespace diff check, PR template completeness, review-thread status, maintainer edit setting.
  • Edge cases checked: stale companion-PR language, non-existent descriptor fields, nested pluginExtensions wording, event stream scoping, non-current API caveats, SessionEntry slot mirror wording, bundled-only helper labeling.
  • What you did not verify: rendered Mintlify screenshot; full local test suite; runtime plugin execution. These were intentionally skipped because this PR is docs-only and local heavyweight suites are discouraged for this workspace.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

The latest ClawSweeper issue-comment finding about plugin.* event streams is addressed in commit 3465338a09: the recipe now uses plugin-id-scoped streams and explains the bundled-only reserved-stream exception.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: A docs recipe could drift from source and teach a non-existent or rejected SDK call.
    • Mitigation: the page now points at the current contract test files, uses grouped APIs from src/plugins/types.ts, and was checked against the event-emission source/contract test after bot review.
  • Risk: The page could blur boundaries between workflow hooks, provider/OAuth hooks, static tool plugins, and runtime helpers.
    • Mitigation: the quick-start and related links explicitly route provider auth/OAuth to provider docs, static tools to Tool Plugins, and host-owned model calls to Runtime helpers.
  • Risk: The docs-only branch could be mistaken for a runtime SDK change.
    • Mitigation: the PR body marks this as docs-only, all security-impact answers are No, and the changed-file list is limited to docs/nav/glossary.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS labels Apr 30, 2026
@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
This PR adds a Plugin SDK host-hook recipes page, links it from plugin docs/navigation, updates hook/overview wording to grouped namespaces, and refreshes zh-CN glossary entries.

Reproducibility: not applicable. this is a docs PR rather than a runtime bug. The high-confidence check is source inspection comparing the new cleanup matrix with runPluginHostCleanup and its contract test.

Real behavior proof
Not applicable: Real behavior proof is not required because this PR only changes files under docs/.

Next step before merge
A narrow docs-only correction remains and can be handled mechanically without product or security judgment.

Security
Cleared: The diff is limited to documentation, docs navigation, and glossary text with no workflow, dependency, script, secret, or package-resolution changes.

Review findings

  • [P2] Document restart as preserving run context — docs/plugins/host-hooks-examples.md:1988-2001
Review details

Best possible solution:

Merge the docs split after the restart cleanup row and explanation match the current run-context lifecycle contract.

Do we have a high-confidence way to reproduce the issue?

Not applicable; this is a docs PR rather than a runtime bug. The high-confidence check is source inspection comparing the new cleanup matrix with runPluginHostCleanup and its contract test.

Is this the best way to solve the issue?

No, not yet. The docs split is the right shape, but the cleanup matrix should be corrected rather than changing runtime behavior.

Full review comments:

  • [P2] Document restart as preserving run context — docs/plugins/host-hooks-examples.md:1988-2001
    The cleanup matrix says restart clears run context, and the note below repeats that it is cleared on restart. Current cleanup only clears run context during restart when a specific runId is provided, and the contract test preserves plugin-wide run context for restart cleanup, so plugin authors would rely on cleanup that does not happen.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.88

Acceptance criteria:

  • node scripts/check-docs-mdx.mjs docs/plugins/host-hooks-examples.md docs/plugins/hooks.md docs/plugins/sdk-overview.md
  • node scripts/format-docs.mjs --check
  • node scripts/docs-link-audit.mjs
  • node scripts/check-docs-i18n-glossary.mjs
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame ties the grouped Plugin SDK API/docs lines used as the review contract to recent commits in the checked-out history. (role: recent area contributor; confidence: medium; commits: b95c8a4d95b7, ae172741e164; files: src/plugins/types.ts, docs/plugins/sdk-overview.md, docs/plugins/hooks.md)
  • 100yenadmin: The related merged host-hook foundation and the active docs split are both tied to this contributor in the PR context, making them a likely routing candidate for source-aligned docs fixes. (role: host-hook stack contributor; confidence: medium; commits: 1adaa28dc86b, 3465338a0952; files: docs/plugins/host-hooks-examples.md, src/plugins/host-hooks.ts, src/plugins/contracts/run-context-lifecycle.contract.test.ts)

Remaining risk / open question:

  • Until the cleanup matrix is corrected, plugin authors may rely on restart clearing run context even though current source and tests preserve plugin-wide run context on restart.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3b39ff43184d.

@100yenadmin
100yenadmin marked this pull request as ready for review April 30, 2026 04:48
Copilot AI review requested due to automatic review settings April 30, 2026 04:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57098df02f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plugins/host-hooks-examples.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Plugin SDK documentation page that collects host-hook “recipe” examples and wires it into the docs navigation + zh-CN glossary, enabling maintainers and plugin authors to reference composition patterns separately from the implementation PR stack.

Changes:

  • Added docs/plugins/host-hooks-examples.md (host-hook recipes/examples page).
  • Added the page to docs/docs.json navigation.
  • Added zh-CN glossary entries for the page title and sidebar label.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
docs/plugins/host-hooks-examples.md New long-form host-hook recipes page with contracts, examples, diagrams, and archetype compositions.
docs/docs.json Adds the new page to the Plugins section nav.
docs/.i18n/glossary.zh-CN.json Adds zh-CN glossary translations for the new page title/sidebar strings.

Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md
Comment thread docs/plugins/host-hooks-examples.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c04613815

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plugins/host-hooks-examples.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e66eb5cc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plugins/host-hooks-examples.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md
@100yenadmin
100yenadmin requested a review from Copilot May 1, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread docs/plugins/host-hooks-examples.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
Comment thread docs/plugins/host-hooks-examples.md Outdated
@100yenadmin
100yenadmin force-pushed the docs/plugin-sdk-host-hook-recipes-split branch from 16c0627 to 2261827 Compare May 3, 2026 19:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22618273b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plugins/host-hooks-examples.md Outdated
@100yenadmin
100yenadmin force-pushed the docs/plugin-sdk-host-hook-recipes-split branch 2 times, most recently from 2ce45c2 to 07fe0d2 Compare May 3, 2026 20:49
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Fixed in 6fea20fb19959c7d5d22c2132729dcf699e511d7. The minimal copyable registerSessionExtension example no longer uses companion-only sessionEntrySlotKey / sessionEntrySlotSchema, and the meter descriptor prose no longer claims web/macOS/iOS ship a stable renderer; it is framed as a companion-client implementation contract. Test: pnpm docs:list; pnpm check:docs; pnpm format:docs:check; git diff --check; npm run check:no-conflict-markers.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@100yenadmin
100yenadmin force-pushed the docs/plugin-sdk-host-hook-recipes-split branch from 6fea20f to a710cbb Compare May 17, 2026 11:58
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: low-signal-docs Candidate: docs-only change looks low signal; maintainer review needed. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context. proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 17, 2026
@clawsweeper clawsweeper Bot added the P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. label May 17, 2026
@100yenadmin
100yenadmin force-pushed the docs/plugin-sdk-host-hook-recipes-split branch from a710cbb to 649ae9e Compare May 17, 2026 12:18
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Reviewer map: what this docs PR teaches

I refreshed the PR body, but I also want the core docs story visible directly in the conversation for reviewers skimming the timeline.

The new page is intentionally a recipe book, not another API table. Its core question is:

If I want my plugin to do X, which host-hook contracts do I compose, and what does that look like end-to-end?

System model

flowchart LR
  A[Plugin entry: definePluginEntry] --> B[Grouped host-hook APIs]
  B --> C[Session state, actions, UI descriptors]
  B --> D[Next-turn injection, schedules, attachments]
  B --> E[Agent events, run context, lifecycle cleanup]
  C --> F[Workflow plugin recipes]
  D --> F
  E --> F
Loading

Author routing

flowchart TD
  Start[Plugin author asks: what can I build?]
  Start --> Tools{Only static agent tools?}
  Tools -->|yes| ToolDocs[Tool Plugins]
  Tools -->|no| Provider{Provider auth, OAuth, runtime auth, model catalog?}
  Provider -->|yes| ProviderDocs[Provider Plugins + Architecture Internals]
  Provider -->|no| Runtime{Host-owned model calls or runtime utilities?}
  Runtime -->|yes| RuntimeDocs[Runtime helpers]
  Runtime -->|no| Hooks[Host-hook examples and recipes]
  Hooks --> Workflow[Approval flows, policy gates, monitors, wizards, review assistants]
Loading

What the recipe page covers

Group Authoring surface What it teaches
Session state api.session.state.registerSessionExtension(...) JSON-compatible plugin state, Gateway row projection, and optional SessionEntry slot mirrors.
Workflow continuation api.session.workflow.enqueueNextTurnInjection(...) Exactly-once next-turn context for approvals, policy summaries, and command continuations.
Session controls api.session.controls.registerSessionAction(...) Gateway-mediated action dispatch with scopes, schema validation, and structured results.
Control UI descriptors api.session.controls.registerControlUiDescriptor(...) Data-only UI contribution descriptors; clients own rendering.
Agent events api.agent.events.registerAgentEventSubscription(...), emitAgentEvent(...) Sanitized subscriptions and plugin-id-scoped event emission.
Run context api.runContext.* Per-run JSON-compatible scratch state cleared on terminal lifecycle.
Lifecycle cleanup api.lifecycle.registerRuntimeLifecycle(...) Idempotent cleanup for sockets, timers, watchers, buffers, and external clients.

The point of the PR is to make the current SDK seams obvious to both humans and AI agents without implying that provider/OAuth hooks, static tool plugins, or runtime helpers belong in this workflow-hook page.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Final review evidence for 649ae9e73f

This pass addressed the remaining source/doc mismatch from the latest ClawSweeper review and rechecked the PR after the force-push.

Review finding resolved

ClawSweeper correctly flagged the event-emission recipe because it used a generic plugin.review stream. Current source requires external plugin event streams to be owned by the emitting plugin:

accepted: stream === pluginId
accepted: stream starts with `${pluginId}.`
rejected: host-reserved streams from external plugins
rejected: streams owned by another plugin id

The docs now use a plugin-id-scoped example:

api.agent.events.emitAgentEvent({
  runId,
  sessionKey,
  stream: "review-concierge.review",
  data: {
    phase: "summary-ready",
    filesReviewed: 12,
  },
});

They also call out that host-reserved streams such as lifecycle, assistant, tool, and approval are bundled-only.

Validation run locally

Working directory: /Volumes/LEXAR/repos/openclaw-host-hook-docs

$ node scripts/check-docs-mdx.mjs docs/plugins/host-hooks-examples.md docs/plugins/hooks.md docs/plugins/sdk-overview.md
Docs MDX check passed (3 files, 176ms).

$ node scripts/format-docs.mjs --check
Docs formatting clean (632 files).

$ node scripts/docs-link-audit.mjs
checked_internal_links=4425
broken_links=0

$ node scripts/check-docs-i18n-glossary.mjs
exited 0

$ jq empty docs/docs.json
exited 0

$ jq empty docs/.i18n/glossary.zh-CN.json
exited 0

$ git diff --check
exited 0

GitHub state after push

Check Result
Head commit 649ae9e73f92a2b2b08aba6e95ff6b13145f3bfe
check-docs Passing
Real behavior proof Passing
CI preflight/security docs-relevant checks Passing
Mergeability MERGEABLE
Maintainer edits maintainerCanModify: true
Review threads 0 unresolved

The PR body has also been expanded to follow the template and now includes the architecture map, source-aligned API coverage table, diagrams, real behavior proof, security impact, verification, and risks/mitigations so reviewers do not need prior context to understand the contribution.

@100yenadmin
100yenadmin force-pushed the docs/plugin-sdk-host-hook-recipes-split branch from 649ae9e to 3465338 Compare May 17, 2026 12:29
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Follow-up polish on latest head 3465338a09

After the final review evidence pass, I did one more source-vs-doc consistency sweep and found two tiny wording issues worth cleaning before merge:

  • The run-context recipe now says explicit grouped api.runContext.* calls require a runId, instead of the looser “top-level on api” phrasing.
  • The cleanup matrix no longer shows pluginExtensions as a nested map. It now says the host removes pluginExtensions[] entries for the plugin, matching the documented Gateway wire shape.

Focused local validation was rerun from /Volumes/LEXAR/repos/openclaw-host-hook-docs:

node scripts/check-docs-mdx.mjs docs/plugins/host-hooks-examples.md docs/plugins/hooks.md docs/plugins/sdk-overview.md
Docs MDX check passed (3 files, 160ms).

node scripts/format-docs.mjs --check
Docs formatting clean (632 files).

node scripts/check-docs-i18n-glossary.mjs
exited 0

node scripts/docs-link-audit.mjs
checked_internal_links=4425
broken_links=0

jq empty docs/docs.json && jq empty docs/.i18n/glossary.zh-CN.json && git diff --check
exited 0

GitHub check-docs and Real behavior proof also pass on 3465338a09.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Closing temporarily for room.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: supplied External PR includes structured after-fix real behavior proof. size: XS triage: low-signal-docs Candidate: docs-only change looks low signal; maintainer review needed. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants