From 005f745a0021c771c21acda853c9e0998ce123e0 Mon Sep 17 00:00:00 2001 From: Michael Neale Date: Mon, 16 Sep 2024 18:35:04 +1000 Subject: [PATCH] feat: jira toolkit (#59) Co-authored-by: Bradley Axen --- .goosehints | 3 +++ README.md | 2 ++ pyproject.toml | 1 + src/goose/toolkit/jira.py | 26 ++++++++++++++++++++++++++ src/goose/toolkit/prompts/jira.jinja | 21 +++++++++++++++++++++ tests/test_jira.py | 24 ++++++++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 .goosehints create mode 100644 src/goose/toolkit/jira.py create mode 100644 src/goose/toolkit/prompts/jira.jinja create mode 100644 tests/test_jira.py diff --git a/.goosehints b/.goosehints new file mode 100644 index 000000000..f445dda0e --- /dev/null +++ b/.goosehints @@ -0,0 +1,3 @@ +This is a python CLI app that uses UV. Read CONTRIBUTING.md for information on how to build and test it as needed. +Some key concepts are that it is run as a command line interface, dependes on the "ai-exchange" package, and has the concept of toolkits which are ways that its behavior can be extended. Look in src/goose and tests. +Once the user has UV installed it should be able to be used effectively along with uvx to run tasks as needed \ No newline at end of file diff --git a/README.md b/README.md index 873e31ee7..375723424 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,8 @@ Rules designed to control or manage the output of the model. Moderators that cur * `screen`: for letting goose take a look at your screen to help debug or work on designs (gives goose eyes) * `github`: for awareness and suggestions on how to use github * `repo_context`: for summarizing and understanding a repository you are working in. +* `jira`: for working with JIRA (issues, backlogs, tasks, bugs etc) + #### Configuring goose per repo diff --git a/pyproject.toml b/pyproject.toml index dcdc37893..de5b28ecc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ goose-ai = "goose.module_name" [project.entry-points."goose.toolkit"] developer = "goose.toolkit.developer:Developer" github = "goose.toolkit.github:Github" +jira = "goose.toolkit.jira:Jira" screen = "goose.toolkit.screen:Screen" repo_context = "goose.toolkit.repo_context.repo_context:RepoContext" diff --git a/src/goose/toolkit/jira.py b/src/goose/toolkit/jira.py new file mode 100644 index 000000000..a6cda8b6d --- /dev/null +++ b/src/goose/toolkit/jira.py @@ -0,0 +1,26 @@ +from exchange import Message # type: ignore +from goose.toolkit.base import tool # type: ignore +import re +from goose.toolkit.base import Toolkit + + +class Jira(Toolkit): + """Provides an additional prompt on how to interact with Jira""" + + def system(self) -> str: + """Retrieve detailed configuration and procedural guidelines for Jira operations""" + template_content = Message.load("prompts/jira.jinja").text + return template_content + + @tool + def is_jira_issue(self, issue_key: str) -> str: + """ + Checks if a given string is a valid JIRA issue key. + Use this if it looks like the user is asking about a JIRA issue. + + Args: + issue_key (str): The potential Jira issue key to be validated. + + """ + pattern = r"[A-Z]+-\d+" + return bool(re.match(pattern, issue_key)) diff --git a/src/goose/toolkit/prompts/jira.jinja b/src/goose/toolkit/prompts/jira.jinja new file mode 100644 index 000000000..65dcad9ee --- /dev/null +++ b/src/goose/toolkit/prompts/jira.jinja @@ -0,0 +1,21 @@ +You can interact with jira issues via the `jira` command line generally. +If it fails to auth, prompt the user to run `jira init` in a separate terminal and then try again. + +Typically when someone requests you to look at a ticket, they mean to view +not just the top level comments and history, but also the comments nested within that ticket and status. + +Some usages are for looking up a JIRA backlog, or looking up a JIRA issue. +Use the tool is_jira_issue if not sure that a string that looks like a jira issue is. + +Use `jira --help` if not sure of command line options. + +If the jira command line is not installed, you can install it as follows: + +On macos: +```sh +brew tap ankitpokhrel/jira-cli +brew install jira-cli +``` + +On other operating systems or for alternative installation methods, refer to the instructions here: +https://github.com/ankitpokhrel/jira-cli diff --git a/tests/test_jira.py b/tests/test_jira.py new file mode 100644 index 000000000..16e23ae49 --- /dev/null +++ b/tests/test_jira.py @@ -0,0 +1,24 @@ +import pytest +from goose.toolkit.jira import Jira + + +@pytest.fixture +def jira_toolkit(): + return Jira(None) + + +def test_jira_system_prompt(jira_toolkit): + prompt = jira_toolkit.system() + print("System Prompt:\n", prompt) + # Ensure Jinja template syntax isn't present in the loaded prompt + # Ensure both installation instructions are present in the prompt + assert "macos" in prompt + assert "On other operating systems or for alternative installation methods" in prompt + + +def test_is_jira_issue(jira_toolkit): + valid_jira_issue = "PROJ-123" + invalid_jira_issue = "INVALID_ISSUE" + # Ensure the regex correctly identifies valid JIRA issues + assert jira_toolkit.is_jira_issue(valid_jira_issue) + assert not jira_toolkit.is_jira_issue(invalid_jira_issue)