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.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Offer the meeting after a refusal and only what the reader can see
Guido Boyked17816666d3e
diff --git a/app/javascript/controllers/assistant_panel_controller.js b/app/javascript/controllers/assistant_panel_controller.jsindex 4f6391c..bfa2ea9 100644--- a/app/javascript/controllers/assistant_panel_controller.js+++ b/app/javascript/controllers/assistant_panel_controller.js@@ -686,26 +686,23 @@ export default class extends Controller {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.+ // 3. a write on its WAY into the collection holds the strip back, whichever+ // object it carries. 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 anything meanwhile invites a second requestSubmit on the same+ // form, which stops the first (adoptContext). Its settle asks again. A key+ // 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.- // 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.+ if (this.pendingContext) return this.hideOffer()+ // 4. the first of the page's objects that is still worth offering: not+ // refused -- 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) -- and not already IN the+ // collection (membership, not equality: it holds up to ten).const context = contexts.find(candidate =>!this.dismissedContexts.has(candidate.key) &&!this.refusedContexts.has(candidate.key) &&@@ -715,7 +712,7 @@ export default class extends Controller {// History/settings have neither a thread nor a draft, and offer nothing.if (!this.openThreadId() && !this.hasDraftReferencesTarget) return this.hideOffer()if (this.hasDraftReferencesTarget &&- this.standingKeySet().size >= Number(this.draftReferencesTarget.dataset.referenceLimit)) return this.hideOffer()+ standingKeys.size >= Number(this.draftReferencesTarget.dataset.referenceLimit)) return this.hideOffer()this.showOffer(context, standing)}@@ -827,6 +824,9 @@ export default class extends Controller {// this object", and it outlives a shrinking collection. The server's refusal// says "not now" and is cleared as soon as room appears.this.dismissedContexts.add(referenceKey)+ // The page may name another object (the meeting beside the ticket): it comes+ // up now, not on whatever next touches the page.+ this.offerPageContext()}hideOffer() {@@ -856,16 +856,19 @@ 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. 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.+ // follows a frame load. A closed lane keeps its box (it slides, 0px wide), so+ // the class is the only thing that says so. Everything else the reader cannot+ // see is asked of the browser (checkVisibility): a closed third lane+ // (display:none), and at the narrow stage the column behind the other tab+ // (visibility:hidden, doc/ticket_meeting_panel_plan.md S2). observePageContent+ // watches the grid's attributes that decide this.pageContexts() {const contexts = []const keys = new Set()for (const marker of document.querySelectorAll("[data-assistant-context]")) {if (this.element.contains(marker)) continueif (marker.closest(".layout.hide-content")) continue- if (marker.closest(".layout.hide-panel > .column.panel")) continue+ if (marker.checkVisibility?.({ visibilityProperty: true }) === false) continueconst id = marker.dataset.assistantContextconst type = marker.dataset.assistantContextType@@ -990,8 +993,15 @@ export default class extends Controller {// never sees the ✕. Watched on that one element and that one attribute// rather than every attribute under <main>: the same rAF-coalesced handler,// one more target. A page without a grid has nothing to watch here.+ // The tab in front at the narrow stage is an attribute of the grid as well+ // (ticket_meeting_panel_controller), and so is the stage that makes it count.const layout = main.querySelector(".layout")- if (layout) this.pageObserver.observe(layout, { attributes: true, attributeFilter: ["class"] })+ if (layout) {+ this.pageObserver.observe(layout, {+ attributes: true,+ attributeFilter: ["class", "data-meeting-panel-stage", "data-meeting-panel-tab"]+ })+ }this.observedMain = main}diff --git a/app/models/document.rb b/app/models/document.rbindex 1291a3a..8bb3a86 100644--- a/app/models/document.rb+++ b/app/models/document.rb@@ -66,7 +66,7 @@ class Document < ApplicationRecord# The title as ONE line, cut to `max` (OneLineText), for the assistant's# reference chip and system prompt. ⚠️ Never blank: #title is nil without a# current version, and a blank label is a marker the panel walks past- # (pageContext() wants id, type and label), i.e. a page that offers nothing+ # (pageContexts() wants id, type and label), i.e. a page that offers nothing# and says nothing. The fallback is a word, translated, not the empty string.def one_line_title(max:)one_line(title.presence || I18n.t('models.document.untitled'), max:)diff --git a/spec/helpers/assistant_context_helper_spec.rb b/spec/helpers/assistant_context_helper_spec.rbindex 10c28a2..a9b61b9 100644--- a/spec/helpers/assistant_context_helper_spec.rb+++ b/spec/helpers/assistant_context_helper_spec.rb@@ -148,7 +148,7 @@ RSpec.describe AssistantContextHelper do# The knowledge objects (doc/assistent_wissen_kontext_plan.md, step 1). The# helper itself is type-blind; what these pin is that the registry now names# the two types AND that each has a label -- because a marker WITHOUT a label- # is one the panel skips (pageContext() wants id, type and label together),+ # is one the panel skips (pageContexts() wants id, type and label together),# so an empty label is not a cosmetic gap, it is a missing offer.describe 'the knowledge objects' dolet(:note) do@@ -185,7 +185,7 @@ RSpec.describe AssistantContextHelper doend# Document#title delegates to the current version and is nil without one.- # nil would reach the attribute as "", and "" is what makes pageContext()+ # nil would reach the attribute as "", and "" is what makes pageContexts()# walk past the marker -- the page would be on a document and offer nothing,# silently. So the label falls back to a translated word, in both languages.# A page's own word after the title, inside the chip's bound: the preview ofdiff --git a/spec/javascript/controllers/assistant_panel_page_contexts.test.js b/spec/javascript/controllers/assistant_panel_page_contexts.test.jsindex 58943b5..b779462 100644--- a/spec/javascript/controllers/assistant_panel_page_contexts.test.js+++ b/spec/javascript/controllers/assistant_panel_page_contexts.test.js@@ -16,10 +16,11 @@ const source = readFileSync(new URL("../../../app/javascript/controllers/assista// 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 = [] } = {}) {+function marker(type, id, label, { insideClosed = [], visible = true } = {}) {return {dataset: { assistantContext: id, assistantContextType: type, assistantContextLabel: label },- closest: selector => (insideClosed.includes(selector) ? {} : null)+ closest: selector => (insideClosed.includes(selector) ? {} : null),+ checkVisibility: () => visible}}@@ -44,14 +45,22 @@ test("names every object of the page once, in page order", () => {assert.deepEqual(keysOf(controller), ["Ticket:t1", "Meeting:m1"])})+// A closed lane keeps its box (it slides at 0px), so only its class says it is shut; a+// closed third lane is display:none, which the browser answers (checkVisibility).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 closedPanel = marker("Meeting", "m1", "Weekly", { visible: false })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 the reader cannot see: the column behind the other tab at the narrow stage", () => {+ const behindTheTicket = marker("Meeting", "m1", "Weekly", { visible: false })++ assert.deepEqual(keysOf(controllerFor([TICKET, behindTheTicket])), ["Ticket:t1"])+})+test("skips a marker without id, type or label", () => {assert.deepEqual(keysOf(controllerFor([marker("Ticket", "", "#1"), MEETING])), ["Meeting:m1"])})@@ -96,6 +105,22 @@ test("holds the strip back while one of them is on its way, and lets go once itassert.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")+// Any write on its way holds the strip, not only one of this page's: taking an offer+// submits the same form, and a second requestSubmit stops the first.+test("a context on its way elsewhere holds back this page's offer too", () => {+ assert.equal(offering([TICKET, MEETING], { pending: "Meeting:other" }).shown, null)+})++test("refusing the ticket by hand brings up the meeting", () => {+ const { controller } = offering([TICKET, MEETING])+ const shown = []+ controller.showOffer = context => shown.push(context.key)+ controller.hideOffer = () => shown.push(null)+ controller.offerTarget = { dataset: { contextId: "Ticket:t1" }, contains: () => false }+ controller.focusComposer = () => {}++ controller.dismissOffer()++ assert.equal(shown.at(-1), "Meeting:m1")+ assert.equal(controller.dismissedContexts.has("Ticket:t1"), true)})diff --git a/spec/requests/organisations/ticket_meeting_panel_spec.rb b/spec/requests/organisations/ticket_meeting_panel_spec.rbindex 1d2fb17..a888be4 100644--- a/spec/requests/organisations/ticket_meeting_panel_spec.rb+++ b/spec/requests/organisations/ticket_meeting_panel_spec.rb@@ -89,6 +89,8 @@ RSpec.describe 'Ticket meeting panel', :ci_guard, type: :request doexpect(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('assistant-trigger')+ # Without the assistant (this organisation has none) the panel names nothing to it.+ expect(body).not_to include('data-assistant-context')expect(body).not_to include(ActionView::RecordIdentifier.dom_id(meeting, :ticket_links))expect(body).not_to include('analyses')expect(body).not_to include('ticket_suggestions')diff --git a/spec/system/ticket_meeting_panel_assistant_spec.rb b/spec/system/ticket_meeting_panel_assistant_spec.rbindex ba16ab6..3cf4c17 100644--- a/spec/system/ticket_meeting_panel_assistant_spec.rb+++ b/spec/system/ticket_meeting_panel_assistant_spec.rb@@ -72,6 +72,18 @@ RSpec.describe 'Assistant beside the ticket and its meeting', type: :system doexpect(collected_keys).to eq(["Ticket:#{ticket.id}", "Meeting:#{meeting.id}"])end+ it 'offers what the narrow stage shows in front, and follows the tab' do+ page.driver.browser.manage.window.resize_to(1280, 900)+ open_ticket_with_assistant_and_meeting+ expect(page).to have_css('.layout[data-meeting-panel-stage="narrow"]')++ # The meeting is in front (F6), the ticket behind it: the meeting is offered.+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Meeting:#{meeting.id}"]))++ find('.ticket-meeting-panel__stage-tab', text: "Ticket ##{ticket.number}").click+ expect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Ticket:#{ticket.id}"]))+ end+it 'offers no meeting once the panel is closed' doopen_ticket_with_assistant_and_meetingexpect(page).to have_css(%([data-assistant-panel-target="offer"][data-context-id="Ticket:#{ticket.id}"]))