catence 0.2.1-beta.5 → 0.2.1-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  * Keep these values synchronized with release/manifest.json; release checks
4
4
  * deliberately reject drift before a package can be published.
5
5
  */
6
- export declare const CATENCE_RUNTIME_VERSION = "0.2.1-beta.5";
6
+ export declare const CATENCE_RUNTIME_VERSION = "0.2.1-beta.6";
7
7
  export declare const CATENCE_PROTOCOL_VERSION = 1;
8
8
  export type CatenceRuntimeCapabilities = {
9
9
  mcp: true;
@@ -3,7 +3,7 @@
3
3
  * Keep these values synchronized with release/manifest.json; release checks
4
4
  * deliberately reject drift before a package can be published.
5
5
  */
6
- export const CATENCE_RUNTIME_VERSION = '0.2.1-beta.5';
6
+ export const CATENCE_RUNTIME_VERSION = '0.2.1-beta.6';
7
7
  export const CATENCE_PROTOCOL_VERSION = 1;
8
8
  export function catenceRuntimeHealth() {
9
9
  return {
@@ -37,4 +37,11 @@ export declare function resolveExtractionErrors(paths: CatencePaths, opts?: {
37
37
  * previously mis-parsed nutrition_days/nutrition_items from stored payloads.
38
38
  */
39
39
  export declare function reimportNutrition(paths: CatencePaths): Promise<Record<string, unknown>>;
40
+ /**
41
+ * Re-run normalization over already-captured Garmin weigh-in entities without
42
+ * contacting any provider. Stores synced before beta.5 staged weigh_ins
43
+ * payloads but never projected them to daily_metrics, so this backfills
44
+ * weight_kg from stored payloads. Idempotent upserts make it safe to re-run.
45
+ */
46
+ export declare function reimportWeight(paths: CatencePaths): Promise<Record<string, unknown>>;
40
47
  export {};
@@ -722,6 +722,36 @@ export async function reimportNutrition(paths) {
722
722
  await database.close();
723
723
  }
724
724
  }
725
+ /**
726
+ * Re-run normalization over already-captured Garmin weigh-in entities without
727
+ * contacting any provider. Stores synced before beta.5 staged weigh_ins
728
+ * payloads but never projected them to daily_metrics, so this backfills
729
+ * weight_kg from stored payloads. Idempotent upserts make it safe to re-run.
730
+ */
731
+ export async function reimportWeight(paths) {
732
+ if (!existsSync(paths.database))
733
+ throw new Error('No Catence database exists yet. Complete a sync before re-importing weight.');
734
+ const database = await CatenceDatabase.open(paths);
735
+ try {
736
+ const rows = await database.rows(`SELECT provider, entity_type, remote_id, parent_remote_id, occurred_on, source_updated_at, raw_object_hash,
737
+ cast(payload_json AS VARCHAR) AS payload_json, cast(extension_json AS VARCHAR) AS extension_json
738
+ FROM source_entities
739
+ WHERE provider = 'garmin' AND entity_type = 'body_composition'
740
+ ORDER BY occurred_on, remote_id`);
741
+ for (const row of rows) {
742
+ await importSourceEntity(database, {
743
+ kind: 'source_entity', schemaVersion: 1, provider: row.provider, entityType: row.entity_type,
744
+ remoteId: row.remote_id, parentRemoteId: row.parent_remote_id, occurredOn: row.occurred_on, sourceUpdatedAt: row.source_updated_at,
745
+ rawObjectHash: row.raw_object_hash, payload: parseJsonObject(row.payload_json), extension: parseJsonObject(row.extension_json),
746
+ });
747
+ }
748
+ const weights = (await database.rows(`SELECT count(*) AS count FROM daily_metrics WHERE metric_name = 'weight_kg'`))[0]?.count ?? 0;
749
+ return { reimportedEntities: rows.length, weightObservations: Number(weights) };
750
+ }
751
+ finally {
752
+ await database.close();
753
+ }
754
+ }
725
755
  function parseJsonObject(value) {
726
756
  if (!value)
727
757
  return {};
@@ -2,7 +2,7 @@
2
2
  import { createInterface } from 'node:readline/promises';
3
3
  import { stdin as input, stdout as output } from 'node:process';
4
4
  import { Command } from 'commander';
5
- import { addAthlete, athleteStorePaths, CATENCE_RUNTIME_VERSION, CatenceDatabase, channelForVersion, createDemoStore, dataStatus, defaultCatalogHome, disconnectStravaAccount, fetchNpmDistTags, fetchPypiReleases, hasCommand, importStagedFile, initializeCatalog, isGlobalNpmInstall, linkActivity, loadCatalog, npmGlobalPrefix, planSelfUpdate, readInstalledConsoleVersion, rebuildRetrievalIndex, reimportNutrition, resolveExtractionErrors, resolveAthlete, resolveCatalogPaths, retryDataSync, runSelfUpdateCommand, setAthleteSecret, syncData, syncProgress, connectStrava, connectStravaWithCallback, unlinkActivity, } from '../../runtime/index.js';
5
+ import { addAthlete, athleteStorePaths, CATENCE_RUNTIME_VERSION, CatenceDatabase, channelForVersion, createDemoStore, dataStatus, defaultCatalogHome, disconnectStravaAccount, fetchNpmDistTags, fetchPypiReleases, hasCommand, importStagedFile, initializeCatalog, isGlobalNpmInstall, linkActivity, loadCatalog, npmGlobalPrefix, planSelfUpdate, readInstalledConsoleVersion, rebuildRetrievalIndex, reimportNutrition, reimportWeight, resolveExtractionErrors, resolveAthlete, resolveCatalogPaths, retryDataSync, runSelfUpdateCommand, setAthleteSecret, syncData, syncProgress, connectStrava, connectStravaWithCallback, unlinkActivity, } from '../../runtime/index.js';
6
6
  const program = new Command()
7
7
  .name('catence-data')
8
8
  .description('Athlete-scoped Catence data setup, extraction, and normalization.')
@@ -256,6 +256,10 @@ program.command('reimport-nutrition').description('Re-run normalization over cap
256
256
  const { paths } = await currentAthlete();
257
257
  process.stdout.write(`${JSON.stringify(await reimportNutrition(paths), null, 2)}\n`);
258
258
  });
259
+ program.command('reimport-weight').description('Backfill weight_kg from captured Garmin weigh-in entities without contacting providers.').action(async () => {
260
+ const { paths } = await currentAthlete();
261
+ process.stdout.write(`${JSON.stringify(await reimportWeight(paths), null, 2)}\n`);
262
+ });
259
263
  program
260
264
  .command('import')
261
265
  .description('Import a staged JSONL file (for example a swim-length backfill) into one athlete’s data store.')
@@ -29,7 +29,7 @@ export { WELLNESS_METRICS, WellnessService } from '../core/query/wellness.js';
29
29
  export { jsonSafe, ReadOnlyRepository } from '../core/query/repository.js';
30
30
  export { queryReadOnlyData } from '../core/query/sql-guard.js';
31
31
  export { createDemoStore, demoStoreMetadata } from '../elt/application/demo.js';
32
- export { connectStrava, connectStravaWithCallback, dataStatus, disconnectStravaAccount, initializeDataStore, importStagedFile, linkActivity, rebuildRetrievalIndex, reimportNutrition, resolveExtractionErrors, retryDataSync, syncData, syncProgress, unlinkActivity, } from '../elt/application/management.js';
32
+ export { connectStrava, connectStravaWithCallback, dataStatus, disconnectStravaAccount, initializeDataStore, importStagedFile, linkActivity, rebuildRetrievalIndex, reimportNutrition, reimportWeight, resolveExtractionErrors, retryDataSync, syncData, syncProgress, unlinkActivity, } from '../elt/application/management.js';
33
33
  export type { ProviderChoice } from '../elt/application/management.js';
34
34
  export { DETACHED_SYNC_PROVIDERS, DetachedSyncBusyError, startDetachedSync, } from '../elt/application/detached-sync.js';
35
35
  export type { DetachedSyncHandle, DetachedSyncProvider, DetachedSyncRequest, DetachedSyncSpawner } from '../elt/application/detached-sync.js';
@@ -16,7 +16,7 @@ export { WELLNESS_METRICS, WellnessService } from '../core/query/wellness.js';
16
16
  export { jsonSafe, ReadOnlyRepository } from '../core/query/repository.js';
17
17
  export { queryReadOnlyData } from '../core/query/sql-guard.js';
18
18
  export { createDemoStore, demoStoreMetadata } from '../elt/application/demo.js';
19
- export { connectStrava, connectStravaWithCallback, dataStatus, disconnectStravaAccount, initializeDataStore, importStagedFile, linkActivity, rebuildRetrievalIndex, reimportNutrition, resolveExtractionErrors, retryDataSync, syncData, syncProgress, unlinkActivity, } from '../elt/application/management.js';
19
+ export { connectStrava, connectStravaWithCallback, dataStatus, disconnectStravaAccount, initializeDataStore, importStagedFile, linkActivity, rebuildRetrievalIndex, reimportNutrition, reimportWeight, resolveExtractionErrors, retryDataSync, syncData, syncProgress, unlinkActivity, } from '../elt/application/management.js';
20
20
  export { DETACHED_SYNC_PROVIDERS, DetachedSyncBusyError, startDetachedSync, } from '../elt/application/detached-sync.js';
21
21
  export { buildOpenCodeGoConsoleProfiles, classifyOpenCodeGoModel, fetchOpenCodeGoModelIds, mergeOpenCodeGoConsoleProfiles, OPENCODE_GO_API_BASE_ENV, OPENCODE_GO_API_KEY_ENV, OPENCODE_GO_DEFAULT_BASE_URL, OPENCODE_GO_MESSAGES_API_BASE_ENV, } from '../core/runtime/opencode-go.js';
22
22
  export { CatenceDatabase, openReadOnlyRepository, ReadOnlyDatabaseError } from '../elt/storage/database.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catence",
3
- "version": "0.2.1-beta.5",
3
+ "version": "0.2.1-beta.6",
4
4
  "description": "Local MCP access to normalized Garmin, Intervals.icu, and targeted Strava fitness data.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {