Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Offer the ticket and the meeting beside it to the assistant

Guido Boyke412143a7981b
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.yml
index d2b166d..3e42c46 100644
--- a/.github/workflows/guards.yml
+++ b/.github/workflows/guards.yml
@@ -640,6 +640,7 @@ jobs:
spec/system/ticket_relations_spec.rb
spec/system/ticket_meeting_panel_spec.rb
spec/system/ticket_meeting_panel_stages_spec.rb
+ spec/system/ticket_meeting_panel_assistant_spec.rb
spec/system/ticket_waiting_list_spec.rb
spec/system/ticket_waiting_filters_spec.rb
spec/services/smart_folder_query_builder_spec.rb
diff --git a/app/javascript/controllers/assistant_panel_controller.js b/app/javascript/controllers/assistant_panel_controller.js
index 126e0a2..4f6391c 100644
--- a/app/javascript/controllers/assistant_panel_controller.js
+++ b/app/javascript/controllers/assistant_panel_controller.js
@@ -419,8 +419,8 @@ export default class extends Controller {
const thread = this.openThreadId()
if (!thread) {
- const context = this.pageContext()
- if (context?.key === referenceKey) {
+ const context = this.pageContexts().find(candidate => candidate.key === referenceKey)
+ if (context) {
this.addDraftReference(context)
if (this.standingKeySet().has(referenceKey)) this.fulfilMeetingIntent(intent, referenceKey)
}
@@ -674,34 +674,43 @@ export default class extends Controller {
//
if (!this.chatFrameSeen) return this.hideOffer()
- const context = this.pageContext()
+ // The page may name more than one object: the ticket and, beside it, its
+ // meeting (doc/ticket_meeting_panel_plan.md, S3). They are offered one after
+ // the other, in page order, through the one strip: taking or refusing the
+ // first brings up the next. Every guard below asks about one of them.
+ const contexts = this.pageContexts()
// 1. the page names no object -- most pages do not.
- if (!context) return this.hideOffer()
+ if (!contexts.length) return this.hideOffer()
// 2. this device has no companion lane, so there is nowhere to show a
// reference and nothing to take it into (same door as toggle/adoptContext).
if (!this.canOpen()) return this.hideOffer()
+ const standing = this.standingReferenceKeys()
+ const standingKeys = this.standingKeySet()
+ // 4. (for the slot) a context that has arrived in the collection is no longer
+ // on its way.
+ if (this.pendingContext && standingKeys.has(this.pendingContext)) this.pendingContext = null
+ // 4b. A context of this page on its WAY into the collection holds the strip
+ // back for ALL of them. Between the click and the stream that brings the
+ // chip back, the thread has no visible reference yet, and any unrelated
+ // frame load in that window re-raises the offer for something that is
+ // already being set (a ticket page brings its own: the lazy timeline
+ // frame reaches the document listener; found as a flaky assertion, kept
+ // as a rule). And offering the NEXT one meanwhile would invite a second
+ // requestSubmit on the same form, which stops the first (adoptContext).
+ // Its settle asks again and the next one comes up then.
+ if (contexts.some(candidate => candidate.key === this.pendingContext)) return this.hideOffer()
// 3. refused for this object -- by hand (dismissOffer, permanent for the tab)
// or by the server (any 422 from the reference route: the limit, or an
// object that no longer resolves). Cleared as soon as the standing set
// shrinks, so a refusal outlives only its own reason.
- if (this.dismissedContexts.has(context.key)) return this.hideOffer()
- if (this.refusedContexts.has(context.key)) return this.hideOffer()
// 4. the reference collection already CONTAINS this very object -- nothing
// to take. Membership, not equality: with more than one entry (S2) the
- // question is whether it is in there, and asking it that way already now
- // keeps the two halves of the offer from being written twice.
- const standing = this.standingReferenceKeys()
- if (this.standingKeySet().has(context.key)) {
- this.pendingContext = null
- return this.hideOffer()
- }
- // 4b. ...or it is on its WAY there. Between the click and the stream that
- // brings the chip back, the thread has no visible reference yet, and any
- // unrelated frame load in that window re-raises the offer for something
- // that is already being set. A ticket page brings its own: the lazy
- // timeline frame reaches the document listener. Found as a flaky
- // assertion, kept as a rule -- it is a flicker either way.
- if (this.pendingContext === context.key) return this.hideOffer()
+ // question is whether it is in there.
+ const context = contexts.find(candidate =>
+ !this.dismissedContexts.has(candidate.key) &&
+ !this.refusedContexts.has(candidate.key) &&
+ !standingKeys.has(candidate.key))
+ if (!context) return this.hideOffer()
// A new conversation holds references in its form until the first message.
// History/settings have neither a thread nor a draft, and offer nothing.
if (!this.openThreadId() && !this.hasDraftReferencesTarget) return this.hideOffer()
@@ -775,8 +784,8 @@ export default class extends Controller {
// connect() closes most of that, but not the frame between a mutation and
// the next repaint. Comparing what the page says NOW against what was
// offered costs one querySelectorAll and is the last word.
- const context = this.pageContext()
- const referenceKey = context?.key === this.offerTarget.dataset.contextId ? context.key : null
+ const offered = this.offerTarget.dataset.contextId
+ const referenceKey = this.pageContexts().some(context => context.key === offered) ? offered : null
// ⚠️ NOT hidden before the guard. The first version hid unconditionally, so a
// click on a stale strip looked EXACTLY like a click that worked: the strip
@@ -834,8 +843,9 @@ export default class extends Controller {
this.offerLabelTarget.removeAttribute("title")
}
- // What the page says it is showing, or null. Searched rather than received:
- // this node is permanent, so nothing ever renders a message to it.
+ // What the page says it is showing: every object it names, in page order and
+ // each once (the ticket's two roots both name it). Searched rather than
+ // received: this node is permanent, so nothing ever renders a message to it.
//
// The panel's own subtree is excluded on purpose -- an answer may well quote a
// ticket, and a citation must never become an offer to re-point the thread.
@@ -846,21 +856,30 @@ export default class extends Controller {
// long as nothing else replaced the frame. The class is the lane's own state
// (.layout.hide-content, the one flag updateLayout writes), and
// observePageContent watches it so the offer follows the ✕ the same way it
- // follows a frame load.
- pageContext() {
- const markers = document.querySelectorAll("[data-assistant-context]")
- for (const marker of markers) {
+ // follows a frame load. The same for a CLOSED third lane (.layout.hide-panel,
+ // the meeting beside a ticket): closing empties that lane too, but the class
+ // flips first, and the class is what the reader sees.
+ pageContexts() {
+ const contexts = []
+ const keys = new Set()
+ for (const marker of document.querySelectorAll("[data-assistant-context]")) {
if (this.element.contains(marker)) continue
if (marker.closest(".layout.hide-content")) continue
+ if (marker.closest(".layout.hide-panel > .column.panel")) continue
const id = marker.dataset.assistantContext
const type = marker.dataset.assistantContextType
const label = marker.dataset.assistantContextLabel
+ if (!id || !type || !label) continue
// The composite key of §7.1, composed HERE and nowhere else on this side:
// the page names a type and an id, the collection is addressed by the pair.
- if (id && type && label) return { key: `${type}:${id}`, label }
+ const key = `${type}:${id}`
+ if (keys.has(key)) continue
+
+ keys.add(key)
+ contexts.push({ key, label })
}
- return null
+ return contexts
}
// Which objects the thread points at right now, read off the chip the server
diff --git a/app/views/organisations/tickets/_meeting_panel.html.erb b/app/views/organisations/tickets/_meeting_panel.html.erb
index 086ddfb..aa6dcd8 100644
--- a/app/views/organisations/tickets/_meeting_panel.html.erb
+++ b/app/views/organisations/tickets/_meeting_panel.html.erb
@@ -2,7 +2,10 @@
<%# The meeting beside the ticket (doc/ticket_meeting_panel_plan.md, S1), the content of
turbo-frame#ticket_meeting_panel in the grid's third lane. Read only: no edit, no delete,
no analyses, no suggestions, no assistant entry point; "Open meeting" leads to the page
- where all of that lives.
+ where all of that lives. It does NAME its meeting to the assistant
+ (assistant_context_attributes, S3): the assistant then offers the ticket and, after
+ it, this meeting, so "what was decided about this ticket?" has both at hand. A name
+ is not an entry point: nothing here writes, the assistant's own strip asks.
meetings: every meeting of this ticket the reader may see (Tickets::LinkedMeetings),
newest first, as tabs in the head; a tab is a plain link, so it loads into this frame.
The close button is the lane's own (NeoTwoColumnGridComponent, layout_toggle#togglePanel);
@@ -11,7 +14,8 @@
<% mp = 'views.organisations.tickets.meeting_panel' %>
<div class="ticket-meeting-panel"
data-controller="ticket-meeting-panel"
- data-ticket-meeting-panel-ticket-id-value="<%= ticket.id %>">
+ data-ticket-meeting-panel-ticket-id-value="<%= ticket.id %>"
+ <%= assistant_context_attributes(meeting) %>>
<%= render 'organisations/tickets/meeting_panel_stage_tabs',
ticket_label: t("#{mp}.ticket_tab", number: ticket.number),
meeting_label: t("#{mp}.meeting_tab", date: l(meeting.occurred_at.to_date, format: :short)) %>
diff --git a/spec/javascript/controllers/assistant_panel_page_contexts.test.js b/spec/javascript/controllers/assistant_panel_page_contexts.test.js
new file mode 100644
index 0000000..58943b5
--- /dev/null
+++ b/spec/javascript/controllers/assistant_panel_page_contexts.test.js
@@ -0,0 +1,101 @@
+// What: the objects a page offers to the assistant (assistant_panel_controller#pageContexts
+// and #offerPageContext), with the meeting open beside a ticket
+// (doc/ticket_meeting_panel_plan.md, S3).
+// Type: node:test over the controller's source with a fake document; no browser.
+// Why: until S3 the panel read only the FIRST marker of the page. With the meeting beside
+// the ticket the page names two objects, and the second one was never offered. And a
+// closed lane must not offer what it no longer shows.
+import { test } from "node:test"
+import assert from "node:assert/strict"
+import { readFileSync } from "node:fs"
+import { runInNewContext } from "node:vm"
+
+const source = readFileSync(new URL("../../../app/javascript/controllers/assistant_panel_controller.js", import.meta.url), "utf8")
+ .replace(/^import .*\n/gm, "")
+ .replace("export default class", "class AssistantPanelController")
+
+// A marker as the page renders it (AssistantContextHelper), sitting inside the given
+// ancestors: closest() answers for the selectors the controller asks about.
+function marker(type, id, label, { insideClosed = [] } = {}) {
+ return {
+ dataset: { assistantContext: id, assistantContextType: type, assistantContextLabel: label },
+ closest: selector => (insideClosed.includes(selector) ? {} : null)
+ }
+}
+
+// The controller runs in its own realm: its arrays are not this realm's arrays.
+const keysOf = controller => Array.from(controller.pageContexts(), context => context.key)
+
+function controllerFor(markers) {
+ const document = { querySelectorAll: () => markers, activeElement: null }
+ const Controller = runInNewContext(`${source}\nAssistantPanelController`, { Controller: class {}, document, Event })
+ const controller = new Controller()
+ controller.element = { contains: () => false }
+ return controller
+}
+
+const TICKET = marker("Ticket", "t1", "#1 Navigation")
+const TICKET_AGAIN = marker("Ticket", "t1", "#1 Navigation")
+const MEETING = marker("Meeting", "m1", "Weekly with the client")
+
+test("names every object of the page once, in page order", () => {
+ const controller = controllerFor([TICKET, TICKET_AGAIN, MEETING])
+
+ assert.deepEqual(keysOf(controller), ["Ticket:t1", "Meeting:m1"])
+})
+
+test("skips what a closed lane or a closed panel still holds", () => {
+ const closedPanel = marker("Meeting", "m1", "Weekly", { insideClosed: [".layout.hide-panel > .column.panel"] })
+ const closedLane = marker("Ticket", "t1", "#1", { insideClosed: [".layout.hide-content"] })
+
+ assert.deepEqual(keysOf(controllerFor([TICKET, closedPanel])), ["Ticket:t1"])
+ assert.deepEqual(keysOf(controllerFor([closedLane, MEETING])), ["Meeting:m1"])
+})
+
+test("skips a marker without id, type or label", () => {
+ assert.deepEqual(keysOf(controllerFor([marker("Ticket", "", "#1"), MEETING])), ["Meeting:m1"])
+})
+
+// offerPageContext with everything around it stubbed: which context does the strip show?
+function offering(markers, { standing = [], pending = null, dismissed = [], refused = [] } = {}) {
+ const controller = controllerFor(markers)
+ controller.hasOfferTarget = true
+ controller.draftSubmitting = () => false
+ controller.chatFrameSeen = true
+ controller.canOpen = () => true
+ controller.openThreadId = () => "thread"
+ controller.hasDraftReferencesTarget = false
+ controller.standingReferenceKeys = () => standing.join(" ") || null
+ controller.standingKeySet = () => new Set(standing)
+ controller.pendingContext = pending
+ controller.dismissedContexts = new Set(dismissed)
+ controller.refusedContexts = new Set(refused)
+ const shown = []
+ controller.showOffer = context => shown.push(context.key)
+ controller.hideOffer = () => shown.push(null)
+ controller.offerPageContext()
+ return { shown: shown.at(-1), controller }
+}
+
+test("offers the ticket first, then the meeting beside it", () => {
+ assert.equal(offering([TICKET, MEETING]).shown, "Ticket:t1")
+ assert.equal(offering([TICKET, MEETING], { standing: ["Ticket:t1"] }).shown, "Meeting:m1")
+ assert.equal(offering([TICKET, MEETING], { standing: ["Ticket:t1", "Meeting:m1"] }).shown, null)
+})
+
+test("offers the meeting when the ticket was refused, by hand or by the server", () => {
+ assert.equal(offering([TICKET, MEETING], { dismissed: ["Ticket:t1"] }).shown, "Meeting:m1")
+ assert.equal(offering([TICKET, MEETING], { refused: ["Ticket:t1"] }).shown, "Meeting:m1")
+})
+
+test("holds the strip back while one of them is on its way, and lets go once it stands", () => {
+ assert.equal(offering([TICKET, MEETING], { pending: "Ticket:t1" }).shown, null)
+
+ const { shown, controller } = offering([TICKET, MEETING], { pending: "Ticket:t1", standing: ["Ticket:t1"] })
+ assert.equal(shown, "Meeting:m1")
+ assert.equal(controller.pendingContext, null)
+})
+
+test("a context on its way elsewhere does not hold back this page's offer", () => {
+ assert.equal(offering([TICKET, MEETING], { pending: "Meeting:other" }).shown, "Ticket:t1")
+})
diff --git a/spec/javascript/controllers/assistant_panel_revision_draft.test.js b/spec/javascript/controllers/assistant_panel_revision_draft.test.js
index 1bce8fe..882b1d9 100644
--- a/spec/javascript/controllers/assistant_panel_revision_draft.test.js
+++ b/spec/javascript/controllers/assistant_panel_revision_draft.test.js
@@ -75,7 +75,7 @@ test("a full draft reference collection explains why an explicit intent was not
controller.open = () => {}
controller.whenComposerReady = callback => callback()
controller.openThreadId = () => null
- controller.pageContext = () => ({ key: "Meeting:c", label: "Meeting C" })
+ controller.pageContexts = () => [{ key: "Meeting:c", label: "Meeting C" }]
let activated = 0
controller.fulfilMeetingIntent = () => activated++
diff --git a/spec/requests/organisations/ticket_meeting_panel_spec.rb b/spec/requests/organisations/ticket_meeting_panel_spec.rb
index 36f4c12..1d2fb17 100644
--- a/spec/requests/organisations/ticket_meeting_panel_spec.rb
+++ b/spec/requests/organisations/ticket_meeting_panel_spec.rb
@@ -88,7 +88,6 @@ RSpec.describe 'Ticket meeting panel', :ci_guard, type: :request do
expect(body).not_to include('<form')
expect(body).not_to include(edit_organisation_project_meeting_path(organisation, project, meeting))
expect(body).not_to include('data-turbo-method')
- expect(body).not_to include('data-assistant-context')
expect(body).not_to include('assistant-trigger')
expect(body).not_to include(ActionView::RecordIdentifier.dom_id(meeting, :ticket_links))
expect(body).not_to include('analyses')
@@ -165,6 +164,32 @@ RSpec.describe 'Ticket meeting panel', :ci_guard, type: :request do
end
end
+ # S3: with the assistant available the panel NAMES its meeting, so the assistant can
+ # offer it after the ticket. A name, not a button: still no trigger.
+ describe 'with the assistant available' do
+ let(:organisation) do
+ create(:organisation, assistant_enabled: true, ai_enabled: true,
+ ai_provider: 'openai', ai_access_token: 'sk-org-own-1234567890abcdef')
+ end
+ let!(:meeting) { meeting_in(project, title: 'Named-Meeting-QX').tap { |m| link(m) } }
+
+ it 'names the meeting to the assistant and offers no trigger' do
+ user = reader
+ ActsAsTenant.with_tenant(organisation) do
+ role = user.memberships.find_by(organisation: organisation).role
+ create(:permission, role: role, category: 'assistant', action: 'use_assistant', allowed: true)
+ end
+ sign_in user
+ panel
+
+ root = Nokogiri::HTML(response.body).at_css('[data-controller~="ticket-meeting-panel"]')
+ expect(root['data-assistant-context']).to eq(meeting.id)
+ expect(root['data-assistant-context-type']).to eq('Meeting')
+ expect(root['data-assistant-context-label']).to include('Named-Meeting-QX')
+ expect(response.body).not_to include('assistant-trigger')
+ end
+ end
+
describe 'several meetings' do
let!(:older) { meeting_in(project, title: 'Older-QX', occurred_at: 3.days.ago).tap { |m| link(m) } }
let!(:newest) { meeting_in(project, title: 'Newest-QX', occurred_at: 1.day.ago).tap { |m| link(m) } }
diff --git a/spec/system/ticket_meeting_panel_assistant_spec.rb b/spec/system/ticket_meeting_panel_assistant_spec.rb
new file mode 100644
index 0000000..ba16ab6
--- /dev/null
+++ b/spec/system/ticket_meeting_panel_assistant_spec.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# The assistant offers the ticket AND the meeting beside it (doc/ticket_meeting_panel_plan.md,
+# S3), clicked for real. Until S3 the assistant read only the first object a page named, so
+# the meeting in the panel was never on offer. The strip offers them one after the other in
+# page order, and a closed panel offers nothing.
+RSpec.describe 'Assistant beside the ticket and its meeting', type: :system do
+ let(:organisation) do
+ create(:organisation, assistant_enabled: true, ai_enabled: true,
+ ai_provider: 'openai', ai_access_token: 'sk-org-own-1234567890abcdef')
+ end
+ let(:user) { create(:user) }
+ let(:project) { create(:project, organisation: organisation) }
+
+ before do
+ driven_by :selenium_chrome_headless_full
+ page.driver.browser.manage.window.resize_to(1600, 900)
+ Prosopite.pause
+ ActsAsTenant.current_tenant = organisation
+ role = create(:admin_role, organisation: organisation)
+ create(:permission, role: role, category: 'assistant', action: 'use_assistant', allowed: true)
+ create(:membership, user: user, organisation: organisation, role: role, active: true)
+ sign_in user
+ end
+
+ # After the before block above: they need its tenant.
+ let!(:ticket) { create(:ticket, project: project, title: 'Navigation for the start page', creator: user) }
+ let!(:meeting) do
+ create(:meeting, project: project, title: 'Weekly with the client', creator: user, occurred_at: 2.days.ago,
+ notes: 'Five menu entries.').tap do |m|
+ m.outgoing_references.create!(organisation: organisation, target: ticket, target_title_snapshot: ticket.display_title)
+ end
+ end
+
+ after do
+ page.driver.browser.manage.window.resize_to(1440, 900)
+ ActsAsTenant.current_tenant = nil
+ Prosopite.resume
+ end
+
+ def offer = page.find('[data-assistant-panel-target="offer"]', visible: :all)
+ def offered = offer['data-context-id']
+ def offer_take = page.find('[data-assistant-panel-target="offerTake"]')
+
+ def collected_keys
+ page.evaluate_script(
+ "(document.querySelector('#assistant_panel [data-reference-keys]')?.dataset.referenceKeys || '').split(' ').filter(Boolean)"
+ )
+ end
+
+ def open_ticket_with_assistant_and_meeting
+ visit organisation_project_tickets_path(organisation, project, ticket_id: ticket.id)
+ expect(page).to have_css("#ticket-content-#{ticket.id}")
+ find('#assistant-panel-trigger').click
+ expect(page).to have_css('body.assistant-panel-open')
+ within("#meeting-references-#{ticket.id}") { click_link 'Weekly with the client' }
+ expect(page).to have_css('aside.column.panel h2', text: 'Weekly with the client')
+ end
+
+ it 'offers the ticket, then the meeting beside it, and collects both' do
+ open_ticket_with_assistant_and_meeting
+
+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Ticket:#{ticket.id}"]))
+ offer_take.click
+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Meeting:#{meeting.id}"]))
+ expect(collected_keys).to eq(["Ticket:#{ticket.id}"])
+
+ offer_take.click
+ expect(page).to have_css('[data-assistant-panel-target="offer"].hidden', visible: :all)
+ expect(collected_keys).to eq(["Ticket:#{ticket.id}", "Meeting:#{meeting.id}"])
+ end
+
+ it 'offers no meeting once the panel is closed' do
+ open_ticket_with_assistant_and_meeting
+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Ticket:#{ticket.id}"]))
+ offer_take.click
+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Meeting:#{meeting.id}"]))
+
+ find('aside.column.panel .panel-close').click
+ expect(page).to have_css('.layout.hide-panel')
+
+ expect(page).to have_css('[data-assistant-panel-target="offer"].hidden', visible: :all)
+ expect(offered).to be_nil
+ end
+end