Skip to content

feat(ai): add Mention Note context picker for Vault Notes - #3290

Open
netcatty-bot wants to merge 33 commits into
mainfrom
ai/issue-3289-34016043990
Open

feat(ai): add Mention Note context picker for Vault Notes#3290
netcatty-bot wants to merge 33 commits into
mainfrom
ai/issue-3289-34016043990

Conversation

@netcatty-bot

@netcatty-bot netcatty-bot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds Context → Mention Note to the AI composer. Users can search Vault notes and reference the exact note for summarizing or editing, including notes with identical titles. The conversation stores only the note ID and display title; the agent uses the existing vault_notes_get tool to read current content. A missing note is reported instead of substituting a title match.

Type of Change

  • Bug fix
  • New feature
  • Refactor / code cleanup
  • Documentation update
  • Build / CI change
  • Other (please describe):

Related Issue (optional)

Closes #3289

Changes Made

  • Search by title, content, tags or group and select with mouse or keyboard. Display note chips in the composer and sent messages; repeated selection refreshes the reference.
  • Enable mentions for Catty and idle external MCP agents. Other connection modes show a disabled entry with an explanation; existing draft references cannot be sent when reading is unavailable. External running turns can add notes in the next turn.
  • Preserve exact note IDs in sends and history references. History keeps a compact reference list ahead of prose with one shared read instruction; long user requests and ten-note requests retain their references in bounded external history. Read the latest note before summarizing or editing. Note-only messages are supported.
  • Keep the complete escaped reference block within 1,000 characters at selection and send, reserving space for user prose in the existing 2,000-character external replay. Groups that do not fit show a localized request to select fewer notes; ordinary files are not counted.
  • Reuse existing attachment and draft paths with empty note payloads. No new storage pruning, aggregate attachment budgets, general draft synchronization changes or external prompt truncation logic.

The full PR is 21 files, +516/-28 (net +488): production net +344, tests +144. This replaces the earlier net +1,630 design, a 70% reduction. References resolve current contents, not a frozen snapshot from selection time.

Screenshots / Demo

Verified in a local browser harness using the real AIStateProvider and complete AIChatPanelsHost: open Context → Mention Note; search beta among two Runbook notes; select with Enter; edit Beta while mounted; select it again and confirm one updated chip; send and inspect the resulting user message containing exact ID beta with an empty payload. Empty-note selection and sending also pass. A direct existing Vault-tool check confirms latest-body reads and explicit missing-note failure after deletion.

The harness has no AI provider configured: sending reaches the normal provider-configuration message. No paid model response or packaged Electron end-to-end run was tested.

Testing

  • I have tested these changes locally (npm run dev) — local Vite full-sidebar harness used.
  • Linting passes (npm run lint)
  • Tests pass (npm test) — 11,452 passed, 0 failed, 18 existing environment-gated skips; 11,470 total.
  • Generated capability tool specs are updated when applicable (npm run generate:capability-tools) — not applicable; reuses existing tools.
  • No new console errors or warnings, if this affects app behavior — full packaged application not exercised.

101 focused tests pass on final head 0e43e805553b75fb96e0367b8fab76ac169930d6. The full-suite result above is from the preceding head; the final reference-size guard has focused tests and a browser check confirming a third long-metadata note is rejected with visible feedback and zero draft writes. npm run build passes. tsc --noEmit retains the same 732 pre-existing diagnostics as the merge base after normalizing paths, source locations and prop-count summaries; no new diagnostics. Both independent local reviewers returned CLEAN on the reduced full PR; one additionally verified serialization/restoration of note references alongside ordinary attachments.

The long-request external-recovery regression fails before the fix and passes after. The ten-note recovery regression retains all IDs and a short do-not-edit instruction. Fresh remote review and CI for the final head are running.

Checklist

  • My code follows the existing project style
  • I have added or updated relevant documentation (behavior and verification above)
  • I have not introduced any breaking changes (or I have described them above)

Keep this PR open for maintainer merge after review and checks complete.

@netcatty-bot netcatty-bot added automation:bot-pr PR created or owned by Cursor automation automation:codex-loop Own/bot PR waiting on Codex review↔fix loop triage Touched by Cursor automation labels Sep 6, 2026
@binaricat

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-07T05:05:16.009643Z 0e43e80 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2b4632931

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +115 to +116
const text = decodeVaultNoteAttachment(attachment);
if (!text) return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve empty Vault note mentions in the prompt

When an attached Vault note has an empty body, decodeVaultNoteAttachment validly returns "", but this falsy check drops the entire block, including its title and noteId. Consequently, a request such as “add deployment steps to this note” gives the agent no way to identify the selected empty note; if the composer is also empty, the UI permits sending but submits an empty model prompt. Distinguish decode failure (null) from valid empty content so the note header is retained.

Useful? React with 👍 / 👎.

@binaricat

Copy link
Copy Markdown
Owner

@codex review

Repository owner deleted a comment from binaricat Sep 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a60f75731b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread application/state/vaultNoteAttachment.ts Outdated
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Repository owner deleted a comment from binaricat Sep 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0c272a207

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread application/state/useAIState.ts Outdated
ensureDraftForScope(scopeKey, fallbackAgentId);
updateDraftIfPresent(scopeKey, (draft) => ({
...draft,
attachments: [...draft.attachments, upload],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cap the aggregate size of mentioned notes

The per-note cap added after the earlier size finding still leaves the aggregate payload unbounded: this appends every selection, including repeated selections of the same note. Eight 200k-character ASCII notes—or about four emoji-heavy notes—can place more than 2 MiB of base64 attachment data into one session; serializeSessionsForStorage cannot remove attachments from the sole newest session, so persistence retries fail and the chat remains memory-only and disappears after restart. Enforce a total attachment budget, deduplicate note mentions, or persist only note metadata after the initial turn.

Useful? React with 👍 / 👎.

@binaricat

Copy link
Copy Markdown
Owner

@codex review

Repository owner deleted a comment from binaricat Sep 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 452c2df34c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/AIChatSidePanel.tsx Outdated
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Repository owner deleted a comment from binaricat Sep 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3579a5c3d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread application/state/vaultNoteAttachment.ts Outdated
Comment thread components/AIChatSidePanel.tsx
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Repository owner deleted a comment from binaricat Sep 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

const firstStrippableIndex = protectNewestContinuation ? 1 : 0;
for (
let index = serialized.length - 1;
index >= firstStrippableIndex && jsonLength > budgetBytes;
index -= 1

P2 Badge Strip replay-unused attachments before continuation ciphertext

When the newest session exceeds the storage budget only because of accumulated attachment bodies, protectNewestContinuation is false and this ciphertext-pruning loop includes that newest session before the attachment fallback runs. Since historical attachments are always replayed as metadata placeholders, the serializer can discard their bodies without affecting subsequent turns; instead it may preserve those unused bodies while removing reasoningEncryptedContent, which can make OpenAI Responses tool exchanges unreplayable after restart. Determine continuation protection from the attachment-stripped size or prune attachment bodies before touching the newest session's ciphertext.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@binaricat

Copy link
Copy Markdown
Owner

@codex review

@binaricat

Copy link
Copy Markdown
Owner

@codex review

Please review current head 979dccc. Addressed the fd1b433 review-body finding about continuation preservation: newest-session protection is now calculated from its attachment-stripped size, retaining required reasoning continuation before removing replay-unused note payloads. The regression fails before and passes after; 50 focused tests pass. Two independent local reviewers returned CLEAN; one also verified 192 storage-size combinations. Please give the review result for this exact new head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 979dccc0b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@netcatty-bot
netcatty-bot marked this pull request as ready for review September 7, 2026 04:23
@netcatty-bot netcatty-bot added automation:codex-clean Last Codex review reported clean and removed automation:codex-loop Own/bot PR waiting on Codex review↔fix loop labels Sep 7, 2026
@netcatty-bot

Copy link
Copy Markdown
Collaborator Author

Codex reported no major issues. This PR is marked ready for human review/merge.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 979dccc0b3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +73 to +78
function vaultNoteAttachmentBudgetBytes(attachment: Pick<UploadedFile, "base64Data" | "vaultNoteId">): number {
const idBytes = typeof attachment.vaultNoteId === "string"
? new TextEncoder().encode(attachment.vaultNoteId).length
: 0;
return base64DecodedByteLength(attachment.base64Data) + idBytes;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Count attachment metadata in the draft budget

After the base64 accounting fix, a note-bearing draft can still bypass the aggregate cap by bulk-selecting many empty or tiny files: this helper charges only decoded payload bytes and a Vault ID, while every accepted upload also persists its filename, path, media type, and object structure. Enough zero-byte files therefore have nearly zero budget cost but can push the newest session over the storage limit; attachment-body pruning cannot reduce that metadata-only payload, so persistence can still fail. Include the serialized metadata cost or impose an attachment-count limit.

Useful? React with 👍 / 👎.

@binaricat binaricat added automation:codex-loop Own/bot PR waiting on Codex review↔fix loop and removed automation:codex-clean Last Codex review reported clean labels Sep 7, 2026
@binaricat
binaricat marked this pull request as draft September 7, 2026 04:34
@binaricat

Copy link
Copy Markdown
Owner

@codex review

@binaricat

Copy link
Copy Markdown
Owner

@codex review

Please review current head d8975c6. At the user's request this feature now stores only a note reference (exact ID and title) and directs the agent to the existing vault_notes_get tool for current contents. The prior PR-specific full-body attachment budgets, storage pruning, draft synchronization and external prompt truncation changes have all been removed. Please assess this reduced complete PR, not the superseded snapshot design.

Full diff: 21 files, net +411 (production +302, tests +109), down from +1,630. Full tests: 11,450 passed, zero failures, 18 existing skips. 98 focused tests, lint and build pass; typecheck matches 732 baseline diagnostics with zero additions. Two independent local reviewers returned CLEAN. Full-sidebar browser checks verify exact same-title selection, refresh/deduplication, empty-note sends and stored ID with empty payload. Existing Vault tool checks verify latest content and missing-note failure. No live model response was tested.

Please give the review result for this exact reduced head. Leave the PR unmerged.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8975c6fb2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/ai/ChatInput.tsx Outdated
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Please review current head d78738e. Fixed the reader-availability finding: only Catty or idle external MCP agents can mention notes. Unsupported modes have a disabled entry and localized explanation; send/steer reject existing references and preserve the draft. Running external turns cannot add note references, avoiding settings changes claiming tools unavailable to the active turn. Browser checks verified Skills entry disabled, existing-reference send blocked with visible feedback, and MCP entry enabled. Two independent local reviewers returned CLEAN; 98 focused tests pass.

Keep this scoped to reference-only mentions. No storage/attachment budgets or new CLI surfaces are needed. Full PR is now net +432 lines, down from +1,630. Please report the result for this exact head and leave the PR unmerged.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d78738e96d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/ai/cattyHistoryReplay.ts Outdated
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Please review current head d7ec120. Fixed the long-message replay finding by placing compact JSON note identities ahead of prose and emitting the read instruction once. Actual external-history tests cover a 2,500-character user request and ten notes plus a do-not-edit constraint; both retain the IDs. The long-request test fails before the fix and passes after.

Full reference-only PR: 21 files, +488/-28, net +460 (production +325, tests +135), down 72% from +1,630. No general storage, prompt-limit, draft-budget or CLI expansion. The prior availability gate remains: Catty or idle external MCP agents only; send/steer reject unsupported note references. 100 focused tests pass. Both independent local reviewers returned CLEAN on the complete latest diff. Fresh full-suite verification is running.

Please return the result for this exact head. Leave this PR unmerged.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7ec12037e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread components/ai/cattyHistoryReplay.ts
@binaricat

Copy link
Copy Markdown
Owner

@codex review

Please review current head 0e43e80. Fixed near-limit metadata overflow: the complete escaped note-reference block must fit 1,000 characters at selection and actual send/steer. This keeps all accepted IDs in existing 2,000-character raw replay with space for prose. Too-large reference groups get localized feedback without changing the draft. Ordinary attachments are not counted or restricted; generic history/storage limits remain unchanged.

101 focused tests pass, including long IDs/titles and ordinary 2MB attachments. Browser verification confirms rejecting a third long-metadata note with feedback and zero draft writes. Lint/build pass. Both independent local reviewers returned CLEAN; tests also covered escaped IDs through real history recovery. Complete PR: net +488 (production +344, tests +144), down 70% from +1,630.

Please return the result for this exact head; leave the PR unmerged.

Repository owner deleted a comment from binaricat Sep 7, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 0e43e80555

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@netcatty-bot
netcatty-bot marked this pull request as ready for review September 7, 2026 05:05
@netcatty-bot

Copy link
Copy Markdown
Collaborator Author

Codex reported no major issues. This PR is marked ready for human review/merge.

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

Labels

automation:bot-pr PR created or owned by Cursor automation automation:codex-clean Last Codex review reported clean triage Touched by Cursor automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 支持在 AI 对话上下文中引用指定的 Vault Note

2 participants