Skip to content

[plugin sdk] Derive tool target paths for hooks#75605

Closed
100yenadmin wants to merge 19 commits into
openclaw:mainfrom
electricsheephq:split/plugin-sdk-tool-derived-paths
Closed

[plugin sdk] Derive tool target paths for hooks#75605
100yenadmin wants to merge 19 commits into
openclaw:mainfrom
electricsheephq:split/plugin-sdk-tool-derived-paths

Conversation

@100yenadmin

Copy link
Copy Markdown
Contributor

Summary

  • Adds a host-owned apply_patch path extractor that derives target paths from add/update/delete/move markers.
  • Adds a small host tool-param parser registry and stamps derivedPaths onto trusted-policy and before_tool_call events.
  • Covers both helper parsing and the real before_tool_call event path so plugins can consume host-derived file facts without re-parsing tool envelopes.

This replaces the consolidated #73384 / #74483 stack with a smaller fresh-main slice. The previous consolidated branch became extremely brittle under constant upstream churn: rebases repeatedly invalidated generated baselines, review threads, and CI assumptions, which made the PR harder to review than the underlying changes warranted. This PR files one hook/seam area at a time so maintainers can review, test, and merge each contract independently without re-opening the whole workflow stack.

Links

Non-goals

  • Does not add host-runtime namespace reads, parent-run tracking, SessionEntry projection, or Control UI/native-page scope.
  • Does not broaden the tool-param parser registry beyond apply_patch.

Test Plan

  • pnpm test src/agents/apply-patch-paths.test.ts src/plugins/host-tool-param-parsers.test.ts src/agents/pi-tools.before-tool-call.e2e.test.ts
  • pnpm check:test-types
  • pnpm lint:core
  • git diff --check
  • npm run check:no-conflict-markers

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds host-derived apply_patch target-path hints to trusted-policy and before_tool_call hook events, plus parser helpers, docs, changelog, API baseline, and focused tests.

Reproducibility: not applicable. this is a feature PR rather than a bug report. Current-main source inspection confirms the requested hook metadata is absent, so verification is PR diff review, SDK contract review, CI, and real behavior proof.

Real behavior proof
Needs real behavior proof before merge: Missing: validation commands are listed, but the contributor still needs to add redacted after-fix runtime proof such as terminal output, logs, screenshots, a recording, or a linked artifact to the PR body for re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Maintainer review is needed because automation cannot provide contributor real-behavior proof, decide public SDK API acceptance, or safely resolve the failing exact-head check and remaining review threads.

Security
Cleared: Cleared: the diff is security-sensitive because it derives path facts for policy hooks, but the current head aligns path resolution with the executor and introduces no concrete supply-chain concern.

Review details

Best possible solution:

Land the additive SDK metadata only after maintainer API review, redacted real setup proof, exact-head checks green or explained, and the remaining review threads addressed or resolved.

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

Not applicable: this is a feature PR rather than a bug report. Current-main source inspection confirms the requested hook metadata is absent, so verification is PR diff review, SDK contract review, CI, and real behavior proof.

Is this the best way to solve the issue?

Yes, subject to approval and proof: a host-owned parser registry with advisory derivedPaths is a narrow additive SDK seam that avoids plugin-side envelope reparsing. It is not merge-ready until proof, CI, and current review-thread follow-up are complete.

Acceptance criteria:

  • Require real behavior proof from a real setup, with private details redacted, then re-run ClawSweeper review.
  • Resolve or explicitly disposition the current review threads noted by the author.
  • Verify exact-head CI, especially the failing macos-swift check.
  • Keep the focused validation path from the PR body: pnpm test src/agents/apply-patch-paths.test.ts src/plugins/host-tool-param-parsers.test.ts src/agents/pi-tools.before-tool-call.e2e.test.ts src/plugins/contracts/host-hooks.contract.test.ts, pnpm plugin-sdk:api:check, pnpm check:test-types, pnpm lint:core, git diff --check, and npm run check:no-conflict-markers.

What I checked:

  • Current main lacks hook metadata: On current main, PluginHookBeforeToolCallEvent exposes toolName, params, runId, and toolCallId, with no derivedPaths field or host tool-param parser files present. (src/plugins/hook-types.ts:422, e1e9cd82c18d)
  • PR adds public event field: PR head adds optional derivedPaths?: readonly string[] with best-effort/non-authoritative SDK contract wording. (src/plugins/hook-types.ts:424, 2caf2b9813dc)
  • PR implements extractor: PR head adds extractApplyPatchTargetPaths, resolving add/update/delete/move markers through cwd or sandbox bridge semantics and de-duplicating normalized targets. (src/agents/apply-patch-paths.ts:135, 2caf2b9813dc)
  • PR wires hook dispatch: PR head derives metadata only when trusted policies or before_tool_call hooks can consume it, passes cwd/sandbox options, and forwards derivedPaths into policy and hook events. (src/agents/pi-tools.before-tool-call.ts:503, 2caf2b9813dc)
  • PR preserves trusted policy facts: PR head copies/freezes incoming derived paths, preserves them for unchanged params, and re-derives only after plain-object trusted-policy param rewrites. (src/plugins/trusted-tool-policy.ts:17, 2caf2b9813dc)
  • No real behavior proof found: The PR body and comments list validation commands, but I found no after-fix terminal output, logs, screenshot, recording, or linked artifact showing the feature running in a real setup; the PR is also labeled triage: needs-real-behavior-proof. (2caf2b9813dc)

Likely related people:

  • 100yenadmin: Merged current-main host-hook foundation and session projection work touch the same hook, trusted-policy, and before-tool-call surfaces this PR extends. (role: host-hook foundation author and adjacent SDK maintainer; confidence: high; commits: 1adaa28dc86b, cb3853587576; files: src/plugins/hook-types.ts, src/plugins/trusted-tool-policy.ts, src/agents/pi-tools.before-tool-call.ts)
  • jalehman: The current-main host-hook foundation and session projection merge commits list jalehman as coauthor/reviewer, making them a likely API-contract reviewer for this SDK seam. (role: host-hook reviewer/coauthor; confidence: high; commits: 1adaa28dc86b, cb3853587576; files: src/plugins/hook-types.ts, src/plugins/trusted-tool-policy.ts, src/agents/pi-tools.before-tool-call.ts)
  • steipete: Recent current-main commits hardened apply_patch and filesystem safety primitives that this PR mirrors for derived path facts. (role: adjacent apply_patch and sandbox path maintainer; confidence: medium; commits: 777c539dafc0, 538605ff44d2; files: src/agents/apply-patch.ts, src/agents/sandbox-paths.ts)

Remaining risk / open question:

  • External-contributor real behavior proof is still missing for the new SDK hook metadata path.
  • Exact-head CI is not fully green because macos-swift is failing.
  • The author explicitly reports unresolved current review threads that still need follow-up before merge.
  • This is a public SDK/API addition and should have maintainer API-contract approval before landing.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 150b869cf8c9.

@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-tool-derived-paths branch from 891ef40 to 11e2a1d Compare May 1, 2026 11:57
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label May 1, 2026
@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-tool-derived-paths branch 2 times, most recently from ac3f694 to a86c942 Compare May 1, 2026 12:21
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Fixed in a86c942080c. Trusted-policy event rebuilding now drops any prior derivedPaths before recomputing from rewritten params, so a rewrite that removes targets cannot leave stale paths for later policies. Added docs and changelog coverage for the public derivedPaths hook metadata. Test: src/plugins/contracts/host-hooks.contract.test.ts covers no-target rewrites clearing stale derived paths. Validation: pnpm test src/agents/apply-patch-paths.test.ts src/plugins/host-tool-param-parsers.test.ts src/agents/pi-tools.before-tool-call.e2e.test.ts src/plugins/contracts/host-hooks.contract.test.ts, pnpm plugin-sdk:api:check, pnpm docs:list, pnpm lint:core, git diff --check, npm run check:no-conflict-markers. pnpm check:test-types is currently blocked by unrelated fresh-main errors in src/commands/onboard-non-interactive.ts.

@100yenadmin
100yenadmin marked this pull request as ready for review May 1, 2026 12:39
Copilot AI review requested due to automatic review settings May 1, 2026 12:39
@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-tool-derived-paths branch from a86c942 to 5861ad6 Compare May 1, 2026 12:41

@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: a86c942080

ℹ️ 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 src/agents/apply-patch-paths.ts 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 host-owned mechanism to derive file target paths (initially for apply_patch) and surfaces those derived facts to plugin tool-policy hooks, so plugins can make path-based decisions without re-parsing tool envelopes.

Changes:

  • Introduce extractApplyPatchTargetPaths() and a small host tool-param parser registry (deriveToolParams) that derives derivedPaths.
  • Plumb derivedPaths through trusted tool policies and before_tool_call hook events (including recomputation after trusted policy param rewrites).
  • Add unit + e2e/contract coverage and update docs/baselines/changelog for the new hook field.

Reviewed changes

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

Show a summary per file
File Description
src/plugins/trusted-tool-policy.ts Rebuild per-policy tool events with host-derived metadata (supports recomputation after param rewrites).
src/plugins/host-tool-param-parsers.ts Adds the host-owned tool param derivation registry (currently apply_patch).
src/plugins/host-tool-param-parsers.test.ts Tests for derivation behavior, empty cases, and malformed params.
src/plugins/hook-types.ts Extends PluginHookBeforeToolCallEvent with optional derivedPaths.
src/plugins/contracts/host-hooks.contract.test.ts Contract coverage for clearing stale derivedPaths across trusted policy rewrites.
src/agents/pi-tools.before-tool-call.ts Computes/stamps derivedPaths onto trusted-policy and before_tool_call events, and recomputes post-rewrite.
src/agents/pi-tools.before-tool-call.e2e.test.ts E2E coverage for derivedPaths propagation and recomputation after trusted policy rewrites.
src/agents/apply-patch-paths.ts Implements lightweight path extraction for apply_patch envelopes.
src/agents/apply-patch-paths.test.ts Unit tests for the extractor across markers, move targets, dedupe, and line endings.
docs/plugins/hooks.md Documents event.derivedPaths for before_tool_call.
docs/.generated/plugin-sdk-api-baseline.sha256 Updates generated SDK API baseline hashes.
CHANGELOG.md Notes new SDK surface: host-derived tool target paths for hooks.

Comment thread src/plugins/trusted-tool-policy.ts Outdated
Comment thread src/plugins/trusted-tool-policy.ts
Comment thread src/plugins/host-tool-param-parsers.ts Outdated
Comment thread src/agents/pi-tools.before-tool-call.ts 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: 535bcb648e

ℹ️ 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 src/agents/apply-patch-paths.ts 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 12 out of 12 changed files in this pull request and generated 3 comments.

Comment thread src/agents/apply-patch-paths.ts
Comment thread src/plugins/trusted-tool-policy.ts Outdated
Comment thread src/plugins/trusted-tool-policy.ts

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 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread src/agents/apply-patch-paths.ts
Comment thread src/agents/apply-patch-paths.ts Outdated
Comment thread src/plugins/host-tool-param-parsers.ts Outdated
Comment thread src/plugins/trusted-tool-policy.ts

@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: 57749fe090

ℹ️ 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 src/agents/apply-patch-paths.ts 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: 4928f6140f

ℹ️ 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 src/agents/apply-patch-paths.ts Outdated
Comment thread src/agents/apply-patch-paths.ts Outdated
@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-tool-derived-paths branch 2 times, most recently from d0df425 to 444daac Compare May 3, 2026 20:48
@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.

@jalehman
jalehman force-pushed the split/plugin-sdk-tool-derived-paths branch from 444daac to bbb77a9 Compare May 4, 2026 18:58
@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-tool-derived-paths branch from bbb77a9 to a6b9699 Compare May 8, 2026 08:25
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 8, 2026
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main 69c1487 (2026-05-08)

Resolved 3 conflicts:

  • CHANGELOG.md — kept upstream's larger change-set; inserted derived-paths entry beside the related #75609 SessionEntry line.
  • docs/.generated/plugin-sdk-api-baseline.sha256 — regenerated via pnpm plugin-sdk:api:gen; pnpm plugin-sdk:api:check now OK.
  • src/agents/pi-tools.before-tool-call.ts — preserved upstream's adjustedParamsByToolCallId import + onToolOutcome field on HookContext, alongside this PR's SandboxFsBridge import + sandbox field.

Force-pushed to split/plugin-sdk-tool-derived-paths at a6b969961c. The 8 unresolved-current review threads from copilot/codex (apply-patch-paths, trusted-tool-policy, host-tool-param-parsers, pi-tools.before-tool-call:503) still need addressing before merge — they were not in scope for this rebase pass.

Upstream changed the default acp.stream.deliveryMode from `live` to
`final_only`. The 4 ACP-streaming tests in dispatch-from-config.test.ts
relied on the old default to exercise the block-streaming path, so they
now never call sendBlockReply. Add explicit `deliveryMode: "live"` to
each affected test config to keep them on the live path.

Mirrors upstream commit ea51160.
@steipete

steipete commented May 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @100yenadmin. I could not push the rebased maintainer fixups back to the fork (403), so I landed this via maintainer replacement #79705.

It keeps the derived apply_patch target-path seam for before_tool_call and trusted policy hooks, preserves the sandbox path bridge / frozen derived arrays / stale derived-path clearing / prototype-key guard hardening, refreshes the SDK API baseline, and carries the docs/changelog update.

Landed in e4bae42.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: XL triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants