Skip to content

Add Incident tools mirroring UserRequest (create, update, search) - #2

Open
agent-qv wants to merge 2 commits into
Combodo:masterfrom
agent-qv:pr/incident-tools
Open

agent-qv wants to merge 2 commits into
Combodo:masterfrom
agent-qv:pr/incident-tools

Conversation

@agent-qv

Copy link
Copy Markdown
Contributor

Adds iTop-create-incident, iTop-update-incident and
iTop-search-incident-by-caller-status-start-date, mirroring the existing
User Request tools and their Twig templates.

The search OQL uses alias I for readability. Its documentation points to
get-class-schema('Incident'), since Incident statuses differ from
User Request statuses.

Base information

Question Answer
Related to a SourceForge thread / Another PR / Combodo ticket? Closes #1
Type of change? Enhancement

Objective

Provide dedicated Incident tools instead of requiring agents to use generic
tools for the common Incident workflow:

  • create an Incident;
  • update an Incident, including its public log;
  • retrieve a caller's Incident history, optionally filtered by status and date.

Proposed solution

Add the three Incident-specific tools and four Twig templates. They mirror the
existing User Request implementation while using the Incident class and its
own status workflow.

Validation

  • git diff --check passes.
  • PHP syntax checks pass for all three changed tool classes.
  • Exercised against an iTop Community Full ITIL instance in a voice-bot support
    workflow.
  • The existing PHPUnit suite fails identically on this branch and on
    upstream/master (two failures and one error in existing
    datamodel/telephone tests).
  • No automated Incident test was added: the current suite has no usable,
    passing datamodel fixture for this workflow.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have tested all changes I made on an iTop instance.
  • A unit test would be relevant, but no reliable existing fixture currently
    covers this Incident workflow.
  • The PR is clear and detailed enough to review without digging into the code.

Checklist of things to do before PR is ready to merge

  • Review the expected Incident fields and status behavior against supported
    iTop versions.
  • Add automated coverage once a suitable datamodel fixture is available.

Adds iTop-create-incident, iTop-update-incident and
iTop-search-incident-by-caller-status-start-date, duplicating the
existing UserRequest tools and their Twig templates. The search OQL
uses alias I instead of U for readability, and its tool docstring
points to get-class-schema('Incident') since Incident statuses differ
from UserRequest's.
Copilot AI balanced review requested due to automatic review settings August 31, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds dedicated Incident creation, update, and caller-history tools mirroring UserRequest workflows.

Changes:

  • Adds Incident create and update tools.
  • Adds filtered Incident search.
  • Adds corresponding JSON and TOON templates.

Reviewed changes

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

Show a summary per file
File Description
src/Tools/core/create/iTopCreateTools.php Registers Incident creation.
src/Tools/core/update/iTopUpdateTools.php Registers Incident updates.
src/Tools/core/get/iTopGetTools.php Adds filtered Incident search.
templates/createIncident-input.json.twig Builds creation requests.
templates/updateIncident-input.json.twig Builds update requests.
templates/searchIncidentFromCallerStatusDate-input.json.twig Builds search queries.
templates/Incident-output.toon.twig Formats Incident results.
Suppressed comments (1)

src/Tools/core/get/iTopGetTools.php:137

  • Any condition value other than the exact string greater_than is silently treated as less_than. A typo therefore reverses the requested date filter instead of producing a validation error; reject values outside the two documented options.
                'condition' => $condition === 'greater_than' ? '>=' : '<=',

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

{
"operation":"core/get",
"class": "Incident",
"key": "SELECT Incident AS I JOIN Person AS P ON I.caller_id = P.id WHERE P.email='{{caller_email}}'{% if statuses !== ''%} AND I.status IN({{ statuses }}){% endif%}{% if start_date !== '' %} AND I.start_date {{ condition }} '{{start_date}}'{% endif%}",
#[McpTool(name: TOOL_PREFIX.'search-incident-by-caller-status-start-date', annotations: new ToolAnnotations(null, true, false, true, false))]
public function searchIncidentByCallerStatusStartDate(#[Schema(format: 'email')] string $caller_email, array $statuses = [], string $start_date = '', string $condition = 'greater_than'): string
{
return $this->runToolFromTemplates('searchIncidentFromCallerStatusDate', 'Incident',
Comment on lines +126 to +127
* @param string $start_date Optional, the start date-time of the Incident (format as a MySQL DateTime (YYYY-MM-DD hh:ii:ss)
* @param string $condition Optional, the condiotnal operator for the start date: either 'greater_than" or 'less_than'
Comment on lines +51 to +53
* @param string $additionalLogEntryHtml An new entry to add to the log of the Incident - NOTE the log entry MUST BE formatted in HTML
* @param string $title Specify the new title for the Incident (leave empty for no change)
* @param string $descriptionHtml Specify the new description for the Incident (leave empty for no change) - NOTE the descriptipon MUST BE formatted in HTML
searchIncidentByCallerStatusStartDate interpolates caller_email/statuses/start_date
into an OQL query string, the same pattern PR Combodo#8 fixes for the pre-existing
UserRequest/Person tools. Combodo#8 can't cover this site (it's based on master before
Incident tools exist), so this PR escapes it locally rather than shipping a new
instance of the same class of issue.

escapeOqlLiteral() is duplicated from Combodo#8 rather than shared, since these are two
independent, isolated proposals - intentional and temporary, to be collapsed into
one definition once both land.
@agent-qv

agent-qv commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

This tool interpolates caller-supplied values into OQL, so it escapes them locally
(latest commit). The same helper is proposed generally in #8, which can't reach this
site since it's based on master from before these Incident tools existed - so the
duplication here is intentional. Whichever of the two PRs lands second, I'll rebase
it to reuse the other's helper instead of carrying two copies. Nothing needed from
you on this - just flagging it for context during review.

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

Labels

None yet

Projects

Status: Pending review

Development

Successfully merging this pull request may close these issues.

Add dedicated Incident tools alongside User Request tools

3 participants