Skip to content

feat(openai,agents): GPT-5.4 prompt discipline + personality bridge + injection scanning#67512

Closed
100yenadmin wants to merge 10 commits into
openclaw:mainfrom
electricsheephq:final-sprint/gpt5-openai-prompt-stack
Closed

feat(openai,agents): GPT-5.4 prompt discipline + personality bridge + injection scanning#67512
100yenadmin wants to merge 10 commits into
openclaw:mainfrom
electricsheephq:final-sprint/gpt5-openai-prompt-stack

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Adds a comprehensive prompt overlay for GPT-5.4 that enforces mandatory tool use, personality fidelity, response brevity, and autonomous execution — replacing the model's tendency toward verbose, permission-seeking, corporate-sounding responses. Also introduces a context-file injection scanner (all models) that blocks malicious SOUL.md/AGENTS.md files before they reach the system prompt.

Tracking

What this PR does

Prompt-level changes (GPT-5.4 only)

Injected via prompt-overlay.ts, only activate for OpenAI GPT-5.4. Additive — no existing content removed.

Section Purpose Mechanism
Tool Enforcement Eliminate hallucinated answers for verifiable facts 6 mandatory-tool categories: "NEVER answer from memory, ALWAYS use a tool"
Act-Don't-Ask Stop model from asking permission before obvious actions Concrete examples: port check → check THIS machine, time → run date
Tool Persistence Prevent "I tried once and failed" bail-outs Keep calling tools until task complete AND verified
Verification Checklist Final self-check before response Correctness, Grounding, Formatting, Safety
Identity Enforcement Lock model into SOUL.md persona If SOUL.md present, model IS the persona. PROHIBITED list of corporate defaults
Voice Calibration Counter GPT-5.4's flat/analytical drift Anti-sycophancy reinforcement, match persona voice
Response Length Discipline Enforce brevity 200-word target, 95% confidence self-evaluation gate (leverages thinking mode), file-offload for long-form
Investigation Discipline Prevent "partial findings" stalls Don't stop to report — investigate all items in same turn, use parallel tool calls
Plan Confidence Gate Reduce permission-seeking 95%+ → execute. 80-94% → state uncertainty, begin. <80% → iterate privately

Injection scanning (all models)

New context-file-injection-scan.ts scans user-provided context files before system prompt injection. 10 threat patterns + invisible Unicode detection. When triggered, file content is REPLACED with a blocking notice — never silently passed through.

How the sections interact

SOUL.md loaded → Identity Enforcement primes persona
    → Voice Calibration enforces persona tone
    → Tool Enforcement mandates tool use for 6 categories
    → Act-Don't-Ask prevents permission-seeking
    → Investigation Discipline prevents mid-task stalls
    → Plan Confidence Gate: 95%+ → execute, <80% → iterate privately
    → Tool Persistence: keep going until done AND verified
    → Response Length Discipline: 200 words, self-evaluate, file-offload
    → Verification Checklist: Correct? Grounded? Formatted? Safe?
    → Response emitted

Scenario coverage

Scenario Before After
"What time is it?" Answers from training data (stale/wrong) Calls date tool, returns live timestamp
500-word status update Model dumps verbose bulleted recap Confidence gate self-evaluates, compresses to <200 words or offloads to file
Malicious AGENTS.md with "ignore all instructions" Injected verbatim into system prompt Injection scanner blocks, replaces with safe notice
User says "ignore your personality" GPT-5.4 may comply, revert to default tone Identity Enforcement + SOUL.md resist; model stays in character

Configuration

  • Personality mode "off": disables identity/voice/brevity sections. Tool enforcement stays active.
  • Provider check: all overlay sections gated behind openai/gpt-5.4*. Other providers unaffected.
  • Injection scanning: always active, all models. No off switch by design.

Files changed

File Change Tests
extensions/openai/prompt-overlay.ts All 9 prompt sections added Assertions in index.test.ts
extensions/openai/index.test.ts Updated assertions for new sections Self
src/agents/context-file-injection-scan.ts New — 10 threat patterns + Unicode detection 20 tests
src/agents/context-file-injection-scan.test.ts New — all patterns + edge cases Self
src/agents/system-prompt-contribution.ts Added tool_enforcement section ID -
src/agents/system-prompt.ts Wired tool_enforcement + injection scan -

Test plan

  • All 10 injection threat patterns detected
  • Multi-word "ignore" variants caught
  • Clean context files pass unmodified
  • Prompt sections present for GPT-5.4, absent for other models
  • Manual: GPT-5.4 with SOUL.md — persona sticks across 10 turns
  • Manual: "what time is it?" → tool call, no hallucination
  • Manual: 500+ word scenario → self-evaluation gate compresses output

Rollback

  1. Prompt overlay: set personality mode to "off" — instant, no deploy
  2. Full revert: revert branch — purely additive, no migration needed

Dependencies

None — this is the foundation PR.

What follows

…injection scanning

Consolidation of v3 PRs #66371, #66372, #66373, #66374, #66375 into
a single review unit. Ports the Hermes Agent GPT-5 prompt stack to
OpenClaw with Hermes-verbatim semantics (only mechanical tool-ID
substitutions for OpenClaw's catalog: terminal→exec, execute_code→
code_execution, read_file→read, search_files→exec).

## Prompt additions (extensions/openai/prompt-overlay.ts)

OPENAI_GPT5_TOOL_ENFORCEMENT — Hermes mandatory_tool_use block:
  "NEVER answer these from memory — ALWAYS use a tool" + 7 categories.

OPENAI_GPT5_EXECUTION_BIAS enhanced with 3 Hermes subsections:
  - Act, Don't Ask (prompt_builder.py:221-229)
  - Tool Persistence (prompt_builder.py:198-204)
  - Verification (prompt_builder.py:238-245)

## Architecture (src/agents/system-prompt-contribution.ts)

Add "tool_enforcement" to ProviderSystemPromptSectionId union so
providers can inject mandatory tool-use guidance independently of
execution_bias. GPT-5 overlay uses sectionOverrides.tool_enforcement.

## Security (src/agents/context-file-injection-scan.ts)

Port Hermes's _CONTEXT_THREAT_PATTERNS (prompt_builder.py:36-52):
10 threat patterns + 10 invisible chars. Flagged files are BLOCKED
(content replaced with placeholder), matching Hermes behavior.

## Tests

- index.test.ts: EXPECTED_GPT5_STABLE_PREFIX helper + 7 assertions
  updated for tool_enforcement sectionOverride
- context-file-injection-scan.test.ts: 17 tests covering all patterns,
  false-positive avoidance, and BLOCK behavior

Part of GPT 5.4 Enhancement v3 sprint. Tracking: #66345.
Supersedes: #66371, #66372, #66373, #66374, #66375.
@greptile-apps

greptile-apps Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a GPT-5.4 prompt overlay (extensions/openai/prompt-overlay.ts) covering tool enforcement, execution discipline, persona fidelity, and response brevity, along with a context-file injection scanner (src/agents/context-file-injection-scan.ts) that blocks 10 threat patterns and invisible Unicode before content reaches the system prompt. Both are wired into buildAgentSystemPrompt via the existing ProviderSystemPromptContribution contract. The implementation is well-tested, the Hermes parity rationale is clearly documented, and prior review concerns (ordering, U+200D, deception_hide broadness) are resolved with documented justification. The only remaining gap is an observability one: the production call to sanitizeContextFileForInjection in buildProjectContextSection (system-prompt.ts:118) does not pass an onAllowlistBypass callback, so allowlist-bypass events fire silently in production.

Confidence Score: 5/5

Safe to merge — all findings are P2 (observability gap, not a correctness defect).

The change is additive, well-tested (20+ injection-scanner tests plus full overlay coverage), and all prior P1/P0 review concerns were resolved. The one remaining finding is a missing telemetry callback in the production call site — not a bug, just missing observability.

src/agents/system-prompt.ts — the sanitizeContextFileForInjection call site lacks an onAllowlistBypass callback for audit logging.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/system-prompt.ts
Line: 118-121

Comment:
**Silent allowlist-bypass in production call site**

`sanitizeContextFileForInjection` is called without an `onAllowlistBypass` callback. If any allowlisted file (e.g. `SECURITY.md`, `CONTRIBUTING.md`, `docs/security/**`) happens to contain an actual injection pattern, the bypass fires silently — no log, no telemetry, no user-visible signal. The interface was clearly designed to support this observability hook; it's just not wired up here.

```suggestion
    const sanitizedContent = sanitizeContextFileForInjection(
      sanitizeContextFileContentForPrompt(file.content),
      file.path,
      {
        onAllowlistBypass: (fname, findings) => {
          // TODO: wire to telemetry / logger once one is available
          console.warn(
            `[injection-scan] allowlist bypass: ${fname} contained ${findings.join(", ")}`,
          );
        },
      },
    );
```

Without at least a console warning, it's impossible to distinguish "allowlist working as intended" from "allowlist being exploited by a crafted security doc".

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "fix(agents): #67512 iter-2 — reset state..." | Re-trigger Greptile

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.ts
Comment thread extensions/openai/prompt-overlay.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: 4265ba55b3

ℹ️ 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/context-file-injection-scan.ts
Comment thread extensions/openai/prompt-overlay.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

Adds Hermes-parity GPT‑5 prompt discipline by introducing a dedicated tool_enforcement prompt section, strengthening GPT‑5 execution guidance, and adding prompt-injection scanning for injected workspace context files.

Changes:

  • Add tool_enforcement as a first-class overridable system-prompt section and wire the OpenAI GPT‑5 overlay to supply it.
  • Extend GPT‑5 execution bias text with “Act, Don’t Ask”, tool persistence, and a verification checklist.
  • Add context-file prompt injection scanning (threat regexes + invisible Unicode) and block flagged context file content.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Runs context-file injection sanitization during Project Context rendering; renders new tool_enforcement section after execution_bias.
src/agents/system-prompt-contribution.ts Extends ProviderSystemPromptSectionId to include tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanner + sanitizer that replaces flagged context content with a blocking placeholder.
src/agents/context-file-injection-scan.test.ts Unit tests for injection detection and blocking sanitizer behavior.
extensions/openai/prompt-overlay.ts Adds GPT‑5 tool enforcement block and augments execution-bias guidance; wires tool_enforcement override.
extensions/openai/index.test.ts Updates provider contribution expectations and factors shared GPT‑5 stablePrefix constant.

Comment thread src/agents/system-prompt.ts
Comment thread src/agents/system-prompt.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

This PR advances GPT‑5 system-prompt parity with Hermes by adding a dedicated tool-enforcement prompt section and introducing prompt-injection scanning for workspace context files that are loaded into the agent system prompt.

Changes:

  • Add tool_enforcement as a first-class overridable system-prompt section, wired into the prompt build pipeline and OpenAI GPT‑5 overlay.
  • Port Hermes-style GPT‑5 execution discipline additions (act-don’t-ask, tool persistence, verification checklist) into the OpenAI overlay.
  • Add context-file injection scanning that blocks suspicious context-file content with a placeholder, plus unit tests.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Runs injection sanitization over loaded context files and renders the new tool_enforcement section after execution_bias.
src/agents/system-prompt-contribution.ts Extends ProviderSystemPromptSectionId to include tool_enforcement.
src/agents/context-file-injection-scan.ts Adds a Hermes-ported injection scanner and blocking sanitizer for context file content.
src/agents/context-file-injection-scan.test.ts Adds unit tests covering threat patterns, invisible unicode detection, and blocking behavior.
extensions/openai/prompt-overlay.ts Adds GPT‑5 tool-enforcement block and strengthens execution-bias guidance (act-don’t-ask, persistence, verification).
extensions/openai/index.test.ts Updates expectations for GPT‑5 prompt contributions to include the new tool_enforcement section override.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread extensions/openai/prompt-overlay.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

Adds Hermes-parity prompt guidance for GPT‑5 models by introducing a dedicated tool_enforcement system-prompt section and by scanning injected workspace context files for prompt-injection patterns before including them in the system prompt.

Changes:

  • Add tool_enforcement as a first-class overridable prompt section and wire the OpenAI GPT‑5 overlay to populate it.
  • Introduce context-file prompt-injection scanning with blocking behavior and unit tests.
  • Extend GPT‑5 execution bias guidance (act-don’t-ask, tool persistence, verification) and update provider contribution tests.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Runs context-file injection sanitization during prompt assembly; inserts the new tool_enforcement section after execution_bias.
src/agents/system-prompt-contribution.ts Extends ProviderSystemPromptSectionId union to include tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanner + sanitizer that blocks suspicious context content with a placeholder.
src/agents/context-file-injection-scan.test.ts Unit tests for injection detection and blocking placeholder behavior.
extensions/openai/prompt-overlay.ts Adds GPT‑5 tool enforcement section + expands execution bias guidance; wires into sectionOverrides.
extensions/openai/index.test.ts Updates provider prompt-contribution expectations to include tool_enforcement; factors shared stablePrefix expectation.

Comment thread src/agents/system-prompt.ts Outdated
Comment thread src/agents/context-file-injection-scan.ts Outdated
Eva added 2 commits April 16, 2026 17:02
Filename is interpolated into the BLOCKED string. A crafted file path
containing brackets or newlines could confuse the model about what
content is blocked. Strip ], [, and newlines from the filename.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Merge order: 1/8. See #66345 for the full merge sequence.

Eva added 2 commits April 16, 2026 19:18
…bosity

Additions to the GPT-5.4 prompt overlay (interaction_style, output_contract,
execution_bias sections):

- Identity Enforcement: prime GPT-5.4 to adopt SOUL.md as primary identity,
  ban corporate default patterns
- Voice Calibration: counter flat/analytical drift, anti-sycophancy reinforcement
- Response Length Discipline: 200-word target with 95% confidence self-evaluation
  gate leveraging thinking mode, file-offload for genuine long-form
- Investigation Discipline: prevent partial-findings-then-ask pattern, force
  parallel tool calls for independent lookups
- Plan Confidence Gate: 95%+ → execute without approval, 80-94% → state
  uncertainty and begin, <80% → iterate privately through research
…tterns

The prompt_injection pattern only matched single-qualifier forms like
'ignore all instructions' but missed 'ignore all previous instructions'
(two qualifiers). Changed to allow zero or more qualifier words between
'ignore' and 'instructions'.
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Bravo.

ℹ️ 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".

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

This PR strengthens GPT‑5.4 agent behavior (tool usage discipline, persona fidelity, and brevity) via an OpenAI prompt overlay, and adds a new cross-model context-file prompt-injection scanner that can block unsafe workspace context before it enters the system prompt.

Changes:

  • Introduces a new overridable tool_enforcement system-prompt section and wires it into system prompt assembly.
  • Adds context-file-injection-scan.ts (+ tests) and applies it when rendering injected project context files.
  • Extends the OpenAI GPT‑5.4 prompt overlay with additional execution/voice/brevity directives and corresponding test expectation updates.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Applies injection sanitization to context file contents; adds tool_enforcement section into prompt assembly.
src/agents/system-prompt-contribution.ts Extends provider section override IDs to include tool_enforcement.
src/agents/context-file-injection-scan.ts New scanner + sanitizer for injection patterns, allowlist logic, and filename hardening.
src/agents/context-file-injection-scan.test.ts Unit tests covering threat patterns, allowlist behavior, and filename defense-in-depth.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 overlay text for identity/voice/brevity + new mandatory tool-use section override.
extensions/openai/index.test.ts Updates contribution assertions and adds content checks for the new overlay sections.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.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

Adds GPT‑5.4-specific prompt overlay sections (tool enforcement, execution discipline, persona/voice tightening, brevity rules) and introduces a context-file prompt-injection scanner that sanitizes injected workspace context before it is incorporated into the agent system prompt.

Changes:

  • Add new provider overridable prompt section id tool_enforcement and wire it into the system prompt build pipeline.
  • Add sanitizeContextFileForInjection() + threat-pattern scanning (with tests) and apply it to injected project context file contents/paths.
  • Extend OpenAI GPT‑5 overlay with identity/voice calibration, brevity discipline, execution bias expansions, and mandatory tool-use directives (with updated assertions).

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Runs context-file injection sanitization during project context rendering; sanitizes filename headings; inserts tool_enforcement overridable section.
src/agents/system-prompt-contribution.ts Extends provider section override union with tool_enforcement.
src/agents/context-file-injection-scan.ts New scanner/sanitizer with threat regexes, invisible-unicode detection, and allowlist bypass behavior.
src/agents/context-file-injection-scan.test.ts Unit tests for threat detection, placeholder replacement, allowlist semantics, and path normalization hardening.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 prompt overlay blocks (identity/voice/brevity/execution discipline) and defines OPENAI_GPT5_TOOL_ENFORCEMENT.
extensions/openai/index.test.ts Updates expected OpenAI provider contributions to include tool_enforcement and expands assertion coverage for new overlay text.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.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

This PR strengthens GPT‑5.4 agent behavior via an OpenAI-only prompt overlay (tool enforcement + execution/voice/brevity discipline) and adds a cross-provider context-file injection scanner that blocks suspicious workspace bootstrap content before it’s injected into the system prompt.

Changes:

  • Introduces a new overridable provider prompt section id (tool_enforcement) and wires it into system prompt assembly.
  • Adds sanitizeContextFileForInjection() + tests, and applies it when rendering injected workspace context files.
  • Expands the GPT‑5.4 OpenAI prompt overlay with identity/voice calibration, brevity discipline, investigation discipline, plan-confidence gating, and mandatory tool-use categories (plus updated assertions).

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Applies context-file injection sanitization during project context rendering; adds tool_enforcement section to prompt pipeline.
src/agents/system-prompt-contribution.ts Extends provider section override ids with tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanner + sanitizer with threat regexes, invisible Unicode detection, and allowlist bypass logic.
src/agents/context-file-injection-scan.test.ts New unit tests for detection/sanitization behavior, allowlist behavior, and filename hardening.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 overlay blocks (identity/voice/brevity/execution discipline) and new mandatory tool-use section override.
extensions/openai/index.test.ts Updates provider contribution expectations to include tool_enforcement and asserts presence of new overlay text.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.test.ts
Comment thread src/agents/context-file-injection-scan.ts
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Plan-mode rollout series — status update

This PR is part of a 10-PR plan-mode rollout. The cumulative state ships locally as OpenClaw 2026.4.15 (3a6ec73) from branch feat/plan-channel-parity (= PR #68441 head).

Series overview + landing order: see #68441 (latest comment).

This PR's role in the series: see the original PR description above.

Live test status: covered by the cumulative install — all behaviors from this PR are verified in production-like usage on Telegram + webchat. No regressions detected since the live install (2026-04-18).

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

This PR strengthens GPT‑5.4 agent behavior via a new prompt overlay (tool enforcement + execution/voice/verbosity discipline) and adds a cross-model context-file prompt-injection scanner that can block malicious workspace context before it reaches the system prompt.

Changes:

  • Introduces a new overridable system-prompt section id (tool_enforcement) and wires it into system prompt composition.
  • Adds context file injection scanning + sanitization for injected workspace context, with unit tests.
  • Expands the OpenAI GPT‑5 overlay with identity/voice calibration, brevity rules, investigation discipline, plan confidence gating, and mandatory tool-use categories, plus updated plugin tests.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Sanitizes context-file headings, runs injection scan on context content, and inserts new tool_enforcement overridable section.
src/agents/system-prompt-contribution.ts Extends provider section override ids to include tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanner + allowlist/bypass logic and BLOCKED placeholder generation.
src/agents/context-file-injection-scan.test.ts Unit tests for threat patterns, unicode detection, placeholder behavior, and allowlist behavior.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 prompt overlay blocks (identity/voice/brevity/discipline) and tool enforcement section override.
extensions/openai/index.test.ts Updates assertions to expect tool_enforcement override and new overlay text.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.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

Adds GPT‑5.x/OpenAI-specific prompt overlay sections (tool enforcement + execution/voice/brevity discipline) and introduces a context-file prompt-injection scanner that sanitizes/blocks suspicious workspace context before it is injected into the system prompt.

Changes:

  • Added a new overridable prompt section id (tool_enforcement) and wired it into system prompt assembly.
  • Implemented sanitizeContextFileForInjection() + threat-pattern scanning (with tests) and applied it to injected project context file contents (plus filename heading sanitization).
  • Expanded the OpenAI GPT‑5 overlay with new identity/voice discipline, brevity gating in the output contract, and a mandatory tool-use block; updated plugin tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Runs context-file injection scanning during prompt assembly; sanitizes context filename headings; injects tool_enforcement override section.
src/agents/system-prompt-contribution.ts Extends provider section override ids with tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanner + sanitizer with allowlist support and filename hardening.
src/agents/context-file-injection-scan.test.ts Unit tests covering threat patterns, unicode detection, allowlist behavior, and filename hardening.
extensions/openai/prompt-overlay.ts Adds GPT‑5 tool enforcement section override and expands interaction/output/execution guidance.
extensions/openai/index.test.ts Updates OpenAI provider contribution expectations and adds assertions for new overlay content.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.ts
@100yenadmin

Copy link
Copy Markdown
Contributor Author

📋 Architecture & Status — single source of truth (commit 39e63febad)

The plan-mode rollout now has a durable architecture document at docs/plans/PLAN-MODE-ARCHITECTURE.md that survives session compactions and tracks the full series.

Quick reference:

  • This is one of 10 open PRs in the cumulative plan-mode rollout (PR-A through PR-11 internal sprint numbering).
  • Recommended landing order: 5 waves (see ARCHITECTURE.md "Recommended landing waves").
  • The cumulative branch feat/plan-channel-parity is the LIVE install (OpenClaw 2026.4.15 (39e63fe)).
  • All 10 PRs target upstream main; each carries forward the cumulative diff which inflates the file count beyond Greptile's 100-file review cap.

Resolution path for the file-count inflation: land PRs in dependency order so the cumulative diff naturally shrinks as upstream main absorbs them. No PR closure/reopen needed — that would lose review history without solving the structural cumulative-rollout pattern.

Hardening status (review pass 1):

Newly-resolved escalation (commit 39e63febad): the previously-deferred #3104743333 (Codex P2 — update_plan merge-mode sidebar refresh) is now fixed via option C (re-emit merged steps via existing agent_plan_event channel). New AgentPlanEventData.mergedSteps field carries the full structured plan; UI subscribes via new maybeForwardMergedPlanEvent handler.

Current status of THIS PR specifically: see the existing comments + bot reviews above. Triage + reply pass coming in the next sprint.

cc @copilot @greptile-apps @chatgpt-codex-connector

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create an environment for this repo.

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

This PR strengthens GPT‑5.4 agent behavior via a new prompt overlay (tool enforcement, execution discipline, personality/voice calibration, and brevity) and adds a context-file prompt-injection scanner that can block suspicious workspace context files before they’re inserted into the system prompt.

Changes:

  • Add tool_enforcement as a first-class provider system-prompt section and wire it into system prompt assembly.
  • Introduce context-file-injection-scan.ts (+ tests) and apply it to injected project context files.
  • Expand the OpenAI GPT‑5.4 prompt overlay with identity/voice guidance, brevity discipline, investigation discipline, confidence gating, and mandatory tool-use categories (+ updated tests).

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Sanitizes injected context headings, runs injection scan on injected file content, and adds the tool_enforcement overridable section.
src/agents/system-prompt-contribution.ts Extends provider section override IDs to include tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanning + allowlist bypass logic + filename hardening for blocked placeholders.
src/agents/context-file-injection-scan.test.ts Unit tests for injection patterns, invisible Unicode, allowlist behavior, and filename defenses.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 prompt overlay blocks including mandatory tool use and expanded execution/voice/brevity guidance.
extensions/openai/index.test.ts Updates expected OpenAI provider prompt contribution to include tool_enforcement and new overlay assertions.

Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/context-file-injection-scan.ts
Comment thread src/agents/system-prompt.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

Adds GPT‑5.4-specific prompt overlay sections to improve tool discipline and persona/voice adherence, and introduces a context-file prompt injection scanner that can block suspicious workspace context before it’s embedded into the agent system prompt.

Changes:

  • Add tool_enforcement as a first-class overridable system-prompt section and wire GPT‑5.4’s “Mandatory Tool Use” overlay into it.
  • Add context-file injection scanning during project-context rendering, plus unit tests for threat patterns and filename/path hardening behavior.
  • Expand GPT‑5.4 overlay text (identity/voice, brevity/response discipline, investigation and confidence gates) and update OpenAI plugin tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
src/agents/system-prompt.ts Sanitizes displayed context file paths and runs injection scan on injected context content; inserts new tool_enforcement overridable section.
src/agents/system-prompt-contribution.ts Extends provider section ID union to include tool_enforcement.
src/agents/context-file-injection-scan.ts New injection scanning + sanitization utility with threat regexes, invisible Unicode detection, and filename hardening.
src/agents/context-file-injection-scan.test.ts New test suite covering detection patterns, allowlist behavior, traversal hardening, and filename sanitization.
extensions/openai/prompt-overlay.ts Adds GPT‑5.4 overlay blocks (identity/voice, brevity discipline, investigation discipline, confidence gate) and the new mandatory tool-use section.
extensions/openai/index.test.ts Updates provider contribution assertions and adds expectations for the new overlay content.

Comment on lines +176 to +185
// Allowlist bypass: legitimate security docs that discuss injection patterns
// shouldn't be blocked from loading. Caller can override the default list.
// Bug fix (#67512 hardening): we previously called isAllowlistedPath(filename)
// without forwarding the caller-supplied allowlist, so custom allowlists
// were silently ignored. Now the custom list (if any) is applied.
const allowlist = options.allowlist ?? DEFAULT_ALLOWLIST;
if (isAllowlistedPath(filename, allowlist)) {
options.onAllowlistBypass?.(filename, findings);
return content;
}
Comment on lines +39 to +40
// Multi-line flag (m + s) on these patterns so split-across-newlines
// attacks like "translate X\n into Y and execute" don't bypass detection.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Closing in favor of consolidated PR #68939.

Rationale: this branch was 734 commits behind upstream/main and the
PR's review feedback was firing against a stale base. Rebased the
full 135-commit feature work onto upstream/main @ v2026.4.19-beta.2
(only 5 conflicts to resolve) and consolidated the 10-PR series into
a single umbrella PR for cleaner bot review + faster maintainer
context-loading.

The full iteration history + decision log lives in
docs/plans/PLAN-MODE-ARCHITECTURE.md on the new branch. All
reviewed-and-resolved threads from this PR are honored — see the
architecture doc for what landed where.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants