8000 V0-11: Automatic Note Organization with Prompt A by kiran-brahma · Pull Request #31 · kiran-brahma/nodepad-app · GitHub
[go: up one dir, main page]

Skip to content

V0-11: Automatic Note Organization with Prompt A - #31

Merged
kiran-brahma merged 1 commit into
mainfrom
feat/issue-12-note-organization
Jul 23, 2026
Merged

kiran-brahma merged 1 commit into
mainfrom
feat/issue-12-note-organization

Conversation

@kiran-brahma
Copy link
Copy Markdown
Owner

Closes #12

What this delivers

V0-11 of the Nodepad app — automatic Note Organization for Local AI and consented Cloud AI Workspaces. After a Note is created or edited, the Enrichment Workflow debounces 800 ms, captures a request token (workspace, note, revision, policy, endpoint, model), calls Ollama /api/chat with the approved Prompt A, validates the structured response, and atomically applies one Note Type, zero-to-three Labels, an optional Annotation, and zero-to-five strong symmetric Relationships to the Note.

How it satisfies each acceptance criterion

  • AC-1 Manual policy makes no provider request — the controller checks the active Workspace's Assistance Policy before scheduling; the Tauri command returns a typed unavailable failure when policy is manual.
  • AC-2 Local AI and consented Cloud AI share one contract — EnrichmentClient trait + HttpEnrichmentClient for both endpoints; the bearer key is read from the macOS keychain only for the Cloud path.
  • AC-3 Candidate selection and truncation follow fixed bounds — select_candidates takes four most-recent + diversity fillers, capped at ten; target ≤ 8 000, candidate ≤ 500, annotation ≤ 300, full request ≤ 16 000 Unicode scalar values. Same-Workspace scope is enforced at the Tauri command.
  • AC-4 Valid response auto-applies all eligible fields in one transaction — WorkspaceStore::apply_enrichment_outcome opens a single transaction that updates the Note row, attaches new Labels, and inserts new Ai-provenance Relationships. The new fields are marked Provenance::Ai and the Note's lastEnrichedAt is set.
  • AC-5 Manual fields are never overwritten — Provenance::Manual always wins; Default and Ai may be refreshed. Tests apply_enrichment_never_overwrites_a_manual_label_membership, apply_enrichment_never_writes_a_manual_note_type, and apply_enrichment_does_not_change_note_text prove it.
  • AC-6 Re-enrich and Replace is explicit, confirmed, tested — the controller surfaces a replace_pending state, the NoteCard renders an alertdialog with Replace / Keep manual buttons, and the force flag bypasses the manual-provenance gate only after the thinker confirms.
  • AC-7 Prompt-injection text remains data — the system prompt instructs the model to treat target_note, existing_labels, relationship_candidates, and url_metadata as untrusted content; the parser validates schema but not content semantics. Test parse_keeps_a_prompt_injection_inside_a_valid_field proves an injection inside an Annotation is stored as data.
  • AC-8 Invalid, unknown-ID, stale, cancelled, failed responses leave durable organization unchanged — the RequestToken.revision is re-read at apply time; mismatch returns WorkspaceFailureCode::Stale. Tests apply_enrichment_rejects_stale_revision and apply_enrichment_drops_results_when_the_thinker_edits_during_inference prove the path. The UI renders a typed retry state.
  • AC-9 The original Note text is never rewritten — apply_enrichment_outcome only writes note_type, note_type_provenance, annotation, annotation_provenance, enrichment_revision, last_enriched_at. Test apply_enrichment_does_not_change_note_text proves it.
  • AC-10 Contract fixtures for small and large Ollama models — system_prompt_is_byte_for_byte_approved asserts the system prompt string equals the approved Prompt A; parse_passes_small_and_large_model_fixtures exercises the parser with both a phi3:latest and a llama3.1:70b token; response_schema_matches_the_approved_contract asserts the JSON schema equals the spec.

Pre-implementation

docs/audits/issue-12-simplicity-audit.md records the prd-simplicity-audit. Gate: PROCEED. Zero BLOCK items; the few CAUTION items became part of the implementation (manual-provenance gate, request-token invalidation, explicit confirmation).

Tests

  • cargo test --manifest-path src-tauri/Cargo.toml --lib — 95 passed, 0 failed.
  • npm run test — 118 passed, 0 failed (across 8 test files).
  • npm run check — typecheck + lint + test + rust test + tauri smoke all pass.
  • fallow audit --base main — 0 introduced dead code; the 2 introduced complexity findings (NoteEnrichmentBadge, useEnrichmentController) are intrinsic to a state-machine component.

Out of scope (explicitly fenced out per the issue)

Synthesis, URL network retrieval, model management, other providers, hidden reas 8000 oning display, automatic merging, and prompt variants beyond approved Prompt A.

Implements the Enrichment Workflow for the V0-11 issue. After a
Note is created or edited, the controller debounces 800ms, captures
a request token, calls Ollama /api/chat, parses the structured
response, and applies the parsed fields to the Note through the
manual-provenance gate.

Highlights:
- Migration 0008 widens the provenance CHECK to admit the new 'ai'
  value and adds the enrichment_revision + last_enriched_at columns.
- Provenance enum grows an 'Ai' variant; the workspace layer bumps
  the revision on every commit that touches a Note.
- Enrichment Workflow module owns the approved Prompt A, the JSON
  schema, the candidate selection algorithm, the per-field
  truncation, the response parser, and the application gate.
- The Tauri command 'enrich_note' runs the same provider-agnostic
  contract for local Ollama and consented Ollama Cloud, with the
  bearer key read from the macOS keychain on demand.
- Manual fields are never overwritten by AI; Re-enrich and Replace
  is the only path that bypasses the gate, and the UI now surfaces
  an explicit confirmation dialog before committing.
- Typed failures (stale / invalid_schema / provider / unavailable)
  leave the Note untouched and the UI renders a single retry
  affordance.
- Visible provenance: 'AI organized' badge when the Note has been
  enriched, and a small 'AI' chip on Note Type and Annotation when
  the value is AI-authored.

Tests:
- 95 Rust tests cover schema, parser, gate, persistence, and the
  stale / manual / force / reopen paths. Contract test asserts the
  system prompt byte-for-byte against the approved Prompt A and
  exercises both a small-model and large-model fixture.
- 118 TypeScript tests cover the workspace-snapshot submit return
  shape, the enrichment controller debounce + cancel + retry +
  replace confirmation, and the existing App, Note, and Thinking
  Graph flows.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V0-11: Implement automatic Note Organization with Prompt A

2 participants

0