Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: add epic search and token expiry detection to JIRA service

Adam Eivy8911ff60b305
diff --git a/.changelog/v0.14.x.md b/.changelog/v0.14.x.md
index 00185a03bc..4b27b87627 100644
--- a/.changelog/v0.14.x.md
+++ b/.changelog/v0.14.x.md
@@ -52,6 +52,11 @@ This release adds Ghostty terminal theme integration and a project update workfl
- **`boardId` field on app JIRA config** — new field in the app edit modal and validation schema so sprint lookup can be driven by app config instead of hardcoded values
- **`scripts/jira-create-ticket.js` CLI** — standalone script that imports JIRA services directly, reads app config, auto-resolves the active sprint, and creates tickets with all fields (project, assignee, sprint, epic, story points, labels) in one call; used by the `/ticket` Claude Code skill
+### JIRA Epic Search & Token Expiry Detection
+- **`GET /api/jira/instances/:id/projects/:key/epics?q=`** — new endpoint to search epics by name in a project; the CLI ticket creator uses this to resolve fuzzy epic names (e.g., "grace support") to JIRA keys
+- **`--epic` accepts search terms** — the CLI script now accepts either a JIRA key (`CONTECH-1553`) or a name search (`"grace support"`) and auto-resolves to the best-matching epic
+- **Token expiry detection** — JIRA client interceptor detects when the API returns an HTML login page instead of JSON and throws a clear "token expired" error instead of crashing
+
### JIRA Integration in Task & Agent UI
- **"Create JIRA ticket" checkbox on task creation** — when the selected app has JIRA enabled, a checkbox auto-appears and defaults to checked; the flag flows through to task metadata for downstream ticket creation
- **JIRA ticket badge on agent cards** — running and completed agents display a linked JIRA ticket ID badge when a ticket was created, with a direct link to the ticket in JIRA
diff --git a/scripts/jira-create-ticket.js b/scripts/jira-create-ticket.js
index 2a80b4bdf5..8f6f2514ca 100755
--- a/scripts/jira-create-ticket.js
+++ b/scripts/jira-create-ticket.js
@@ -13,11 +13,12 @@
* --points Story points (default: 1)
* --sprint Use current active sprint (default: true)
* --no-sprint Skip sprint assignment
- * --epic Override epic key (default: from app config)
+ * --epic Epic key (CONTECH-123) or search term ("grace support") to find by name
* --assignee Override assignee (default: from app config)
*
* Example:
* node scripts/jira-create-ticket.js --app portos --summary "Research MXF video" --points 1
+ * node scripts/jira-create-ticket.js --app grace --summary "Fix login" --epic "grace support"
*/
import { dirname, join } from 'path';
@@ -54,7 +55,7 @@ function parseArgs() {
--type Issue type (Task, Bug, Story, Spike)
--points Story points (default: 1)
--no-sprint Skip sprint assignment
- --epic Override epic key
+ --epic Epic key (CONTECH-123) or search term ("grace support")
--assignee Override assignee`);
process.exit(0);
}
@@ -99,6 +100,35 @@ async function getActiveSprintId(instanceId, boardId) {
return sprint.id;
}
+/**
+ * Resolve an epic from either a key (CONTECH-123) or a search term ("grace support")
+ */
+async function resolveEpic(instanceId, projectKey, epicInput) {
+ if (!epicInput) return undefined;
+
+ // If it looks like a JIRA key (e.g. CONTECH-123), use it directly
+ if (/^[A-Z]+-\d+$/.test(epicInput)) {
+ console.log(`📌 Epic: ${epicInput}`);
+ return epicInput;
+ }
+
+ // Otherwise search for it by name
+ const epics = await jiraService.searchEpics(instanceId, projectKey, epicInput);
+ if (!epics.length) {
+ console.error(`⚠️ No epics found matching "${epicInput}"`);
+ return undefined;
+ }
+
+ if (epics.length === 1) {
+ console.log(`📌 Epic: ${epics[0].key} — ${epics[0].summary}`);
+ return epics[0].key;
+ }
+
+ // Multiple matches — pick the best one (first result, most relevant)
+ console.log(`📌 Epic: ${epics[0].key} — ${epics[0].summary} (${epics.length} matches, using best)`);
+ return epics[0].key;
+}
+
async function main() {
const args = parseArgs();
@@ -116,6 +146,13 @@ async function main() {
sprintId = await getActiveSprintId(jira.instanceId, jira.boardId);
}
+ // Resolve epic — CLI arg overrides app config, both support search terms
+ const epicKey = await resolveEpic(
+ jira.instanceId,
+ jira.projectKey,
+ args.epic || jira.epicKey || undefined
+ );
+
const ticketData = {
projectKey: jira.projectKey,
summary: args.summary,
@@ -123,7 +160,7 @@ async function main() {
issueType: args.type || jira.issueType || 'Task',
assignee: args.assignee || jira.assignee || undefined,
storyPoints: args.points,
- epicKey: args.epic || jira.epicKey || undefined,
+ epicKey,
labels: jira.labels || [],
sprint: sprintId || undefined
};
diff --git a/server/routes/jira.js b/server/routes/jira.js
index 3f0b941d8f..f4b79d3c9e 100644
--- a/server/routes/jira.js
+++ b/server/routes/jira.js
@@ -234,4 +234,21 @@ router.get('/instances/:instanceId/boards/:boardId/sprints', async (req, res, ne
}
});
+/**
+ * GET /api/jira/instances/:instanceId/projects/:projectKey/epics?q=search
+ * Search for epics by name in a project
+ */
+router.get('/instances/:instanceId/projects/:projectKey/epics', async (req, res, next) => {
+ try {
+ const epics = await jiraService.searchEpics(
+ req.params.instanceId,
+ req.params.projectKey,
+ req.query.q || ''
+ );
+ res.json(epics);
+ } catch (error) {
+ next(error);
+ }
+});
+
export default router;
diff --git a/server/services/jira.js b/server/services/jira.js
index 682d9bb65e..b29aff029f 100644
--- a/server/services/jira.js
+++ b/server/services/jira.js
@@ -74,7 +74,7 @@ export async function deleteInstance(instanceId) {
* Create axios client for JIRA instance
*/
function createJiraClient(instance) {
- return axios.create({
+ const client = axios.create({
baseURL: instance.baseUrl,
headers: {
'Authorization': `Bearer ${instance.apiToken}`,
@@ -86,6 +86,18 @@ function createJiraClient(instance) {
}),
timeout: 30000
});
+
+ // Detect expired token (JIRA returns HTML login page instead of JSON)
+ client.interceptors.response.use(response => {
+ if (typeof response.data === 'string' && response.data.includes('<!DOCTYPE')) {
+ const err = new Error('JIRA token expired — received login page instead of JSON. Regenerate your PAT.');
+ err.status = 401;
+ throw err;
+ }
+ return response;
+ });
+
+ return client;
}
/**
@@ -332,6 +344,35 @@ export async function getActiveSprints(instanceId, boardId) {
}));
}
+/**
+ * Search for epics in a JIRA project by name
+ */
+export async function searchEpics(instanceId, projectKey, query) {
+ const config = await getInstances();
+ const instance = config.instances[instanceId];
+
+ if (!instance) {
+ throw new Error(`JIRA instance ${instanceId} not found`);
+ }
+
+ const client = createJiraClient(instance);
+ const jql = `project = "${projectKey}" AND issuetype = Epic AND summary ~ "${query}" ORDER BY updated DESC`;
+
+ const response = await client.get('/rest/api/2/search', {
+ params: {
+ jql,
+ fields: 'summary,status',
+ maxResults: 10
+ }
+ });
+
+ return response.data.issues.map(issue => ({
+ key: issue.key,
+ summary: issue.fields.summary,
+ status: issue.fields.status.name
+ }));
+}
+
export default {
getInstances,
saveInstances,
@@ -344,5 +385,6 @@ export default {
addComment,
transitionTicket,
getMyCurrentSprintTickets,
- getActiveSprints
+ getActiveSprints,
+ searchEpics
};