import { u as userProfile } from './nexus-schema2-BEd-ol6e.js';
import 'node:fs';
import 'node:path';
import './paths-2M_UxD_H.js';
import './dual-scope-db-ATrwq0LH.js';
import { g as gte, a as and, c as isNull, d as desc, f as asc } from './logger-ChCwlV5k.js';
import './chunk-DDP5xfzh.js';
import 'node:module';
import './indexes-aYlULWG3.js';
import './utils-BvHPJOVk.js';
import 'node:os';
import 'node:events';
import 'node:diagnostics_channel';
import 'fs';
import 'events';
import 'util';
import 'path';
import 'assert';
import 'worker_threads';
import 'module';
import 'node:url';
import 'url';
import 'buffer';
import 'node:child_process';
import 'node:crypto';
import 'node:process';
import 'node:async_hooks';

//#region ../core/dist/nexus/user-profile.js
/**
* User-profile CRUD operations for the NEXUS user_profile table.
*
* Provides the 5 SDK functions for PSYCHE Wave 1 (T1078):
*   - getUserProfileTrait    — fetch a single trait by key
*   - upsertUserProfileTrait — create-or-update a trait
*   - reinforceTrait         — increment reinforcement count + bump confidence
*   - listUserProfile        — list all traits (with optional confidence filter)
*   - supersedeTrait         — mark one trait as superseded by another
*
* All functions accept a `nexusDb` argument (NodeSQLiteDatabase<NexusSchema>)
* to keep them unit-testable without touching the real nexus.db singleton.
* Callers that do not need test isolation may use `getNexusDb()` from
* `packages/core/src/store/nexus-sqlite.ts` directly.
*
* PSYCHE reference: `upstream psyche-lineage · crud/peer.py` (getOrCreate +
* metadata merge pattern) and `models.py` (User metadata attributes).
*
* @task T1078
* @epic T1076
*/
/**
* Convert a DB row into the canonical `UserProfileTrait` wire shape.
* Timestamps are stored as Unix-epoch numbers in the DB and surfaced as ISO
* 8601 strings on the wire contract.
*
* @param row - Raw row from the `user_profile` table.
* @returns Canonical `UserProfileTrait` object.
*/
function rowToTrait(row) {
	return {
		traitKey: row.traitKey,
		traitValue: row.traitValue,
		confidence: row.confidence,
		source: row.source,
		derivedFromMessageId: row.derivedFromMessageId ?? null,
		firstObservedAt: new Date(row.firstObservedAt).toISOString(),
		lastReinforcedAt: new Date(row.lastReinforcedAt).toISOString(),
		reinforcementCount: row.reinforcementCount,
		supersededBy: row.supersededBy ?? null
	};
}
/**
* List all user-profile traits, optionally filtered by minimum confidence.
*
* Only non-superseded traits are returned by default — pass
* `opts.includeSuperseded = true` to include deprecated traits.
*
* @param nexusDb - Drizzle nexus database handle.
* @param opts    - Optional filtering options.
* @returns Array of traits ordered by confidence desc, then traitKey asc.
*/
async function listUserProfile(nexusDb, opts) {
	const minConf = opts?.minConfidence ?? 0;
	const includeSuperseded = opts?.includeSuperseded ?? false;
	return (await nexusDb.select().from(userProfile).where(includeSuperseded ? gte(userProfile.confidence, minConf) : and(gte(userProfile.confidence, minConf), isNull(userProfile.supersededBy))).orderBy(desc(userProfile.confidence), asc(userProfile.traitKey))).map(rowToTrait);
}

export { listUserProfile };
//# sourceMappingURL=user-profile-D3aqqLc0.js.map
