Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions plugins/financial-advisor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* inference rules, budgets, goals, reports, and contextual advice.
*/

import type { RadixPlugin } from '@plures/pares-radix';
import type { RadixPlugin, PluginContext } from '@plures/pares-radix';
import { recurringAmountPattern } from './rules/recurring-amount.js';
import { vendorClustering } from './rules/vendor-clustering.js';
import { refundDetection } from './rules/refund-detection.js';
import { taxVarianceDetection } from './rules/tax-variance.js';
import { setPluginContext, clearPluginContext } from './lib/context.js';

const financialAdvisor: RadixPlugin = {
id: 'financial-advisor',
Expand Down Expand Up @@ -219,13 +220,15 @@ const financialAdvisor: RadixPlugin = {

constraints: [],

async onActivate() {
async onActivate(ctx: PluginContext) {
console.log('[financial-advisor] Plugin activated');
// TODO: Initialize PluresDB collections, load inference rules
setPluginContext(ctx);
// TODO: load inference rules into inference engine
Comment on lines +223 to +226

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

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

onActivate stores the plugin context globally, but onDeactivate does not clear it. This can leave a stale PluginContext reachable from pages after the plugin is deactivated. Consider clearing the singleton in onDeactivate (after adding a clear/reset helper in lib/context.ts).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was already applied in f19f265onDeactivate now calls clearPluginContext(), and clearPluginContext was added to lib/context.ts in the same commit.

},

async onDeactivate() {
console.log('[financial-advisor] Plugin deactivated');
clearPluginContext();
},

async onDataExport() {
Expand Down
35 changes: 35 additions & 0 deletions plugins/financial-advisor/src/lib/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Account types and helpers for the fa-accounts PluresDB collection.
*/

export type AccountType = 'checking' | 'savings' | 'credit' | 'investment';

export interface Account {
id: string;
name: string;
institution: string;
type: AccountType;
balance: number;
createdAt: string;
updatedAt: string;
}

export const FA_ACCOUNTS_COLLECTION = 'fa-accounts';

export function generateAccountId(): string {
return `acct-${crypto.randomUUID()}`;
}

export const ACCOUNT_TYPE_LABELS: Record<AccountType, string> = {
checking: 'Checking',
savings: 'Savings',
credit: 'Credit Card',
investment: 'Investment',
};

export const ACCOUNT_TYPE_ICONS: Record<AccountType, string> = {
checking: '🏦',
savings: '💰',
credit: '💳',
investment: '📈',
};
24 changes: 24 additions & 0 deletions plugins/financial-advisor/src/lib/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Plugin context singleton for financial-advisor.
*
* `setPluginContext` is called from `onActivate` so that Svelte page
* components can retrieve the PluresDB data API, notify API, etc.
* without needing Svelte's own `setContext` / `getContext` mechanism
* (which is scoped to component trees and unavailable in lifecycle hooks).
*/

import type { PluginContext } from '@plures/pares-radix';

let _context: PluginContext | null = null;

export function setPluginContext(ctx: PluginContext): void {
_context = ctx;
}

Comment thread
kayodebristol marked this conversation as resolved.
export function clearPluginContext(): void {
_context = null;
}

export function getPluginContext(): PluginContext | null {
return _context;
}
Loading
Loading