[Developer] #204 Phase 1 MVP — Flutter app skeleton complete

- Drift 21 tables (8 catalog + 11 user + habit_dose_variants + meta_kv)
  with R1~R10 CHECK constraints and 19 indexes
- 8 hand-crafted seed JSON catalogs in app/assets/seed/
  (refs 84, protocols 34, methodologies 21, frame_patterns 30,
   reward_menu_items 30, break_protocols 8, common_frames 5, diet_patterns 5)
- 6 domain functions: recommend_variant, compute_streak,
  validate_frame_level, active_habit_quota, weekly_minimum_ratio,
  seed_importer (transactional, idempotent)
- 4 vertical-slice Riverpod screens: HabitList, HabitCreate, CheckIn, Streak
- 31 unit tests passing; flutter analyze clean
- OQ-5 streak semantics: missing entry ≠ explicit blank
  (missing = end of history; only TrackerValue.blank triggers Never-miss-twice)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 10:33:03 +09:00
parent 29befe4d97
commit 8fe6a8f378
76 changed files with 29059 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import '../models/habit.dart';
/// R1/R2: max active habits per type.
/// - build: ≤ 3
/// - break: ≤ 1
const int kMaxActiveBuild = 3;
const int kMaxActiveBreak = 1;
class QuotaResult {
final HabitType type;
final int currentCount;
final int limit;
final bool allowed;
const QuotaResult({
required this.type,
required this.currentCount,
required this.limit,
required this.allowed,
});
String get reason {
if (allowed) return 'ok';
return type == HabitType.build
? 'build habit quota reached (≤ $kMaxActiveBuild active)'
: 'break habit quota reached (≤ $kMaxActiveBreak active)';
}
}
/// Pure judgment: caller passes in the current active count.
QuotaResult judgeActiveHabitQuota({
required HabitType type,
required int currentActiveCount,
}) {
final limit = type == HabitType.build ? kMaxActiveBuild : kMaxActiveBreak;
return QuotaResult(
type: type,
currentCount: currentActiveCount,
limit: limit,
allowed: currentActiveCount < limit,
);
}

View File

@@ -0,0 +1,9 @@
/// R6: warn if anchor change happens mid-phase (>= 1 week in).
bool phaseAnchorChangeWarning({
required String phaseStartedAt,
required DateTime now,
}) {
final start = DateTime.parse(phaseStartedAt);
final daysIn = now.difference(start).inDays;
return daysIn >= 7;
}

View File

@@ -0,0 +1,9 @@
/// R4: reward_declaration must be created within phase.started_at + 7 days.
bool validateRewardDeclarationWindow({
required String phaseStartedAt, // YYYY-MM-DD
required DateTime now,
}) {
final start = DateTime.parse(phaseStartedAt);
final cutoff = start.add(const Duration(days: 7));
return !now.isAfter(cutoff);
}

View File

@@ -0,0 +1,2 @@
/// R5: tracker_entry.value must be 'done' or 'blank'.
bool validateTrackerValue(String s) => s == 'done' || s == 'blank';

View File

@@ -0,0 +1,20 @@
import '../models/habit.dart';
/// XOR: build → protocol_id (only); break → break_protocol_id (only).
void assertXorProtocol({
required HabitType type,
required String? protocolId,
required String? breakProtocolId,
}) {
if (type == HabitType.build) {
if (protocolId == null || breakProtocolId != null) {
throw ArgumentError(
'build habit requires protocol_id and no break_protocol_id');
}
} else {
if (breakProtocolId == null || protocolId != null) {
throw ArgumentError(
'break habit requires break_protocol_id and no protocol_id');
}
}
}