Initial commit: Grounded Flutter frontend
A to-do app that doesn't believe you — an enforcement layer rather than a
neutral ledger.
Architecture ported from Autoreceptives/Frontend/Receptive: stacked MVVM with
the mandatory 4-file screen pattern, one ParentViewModel owning the loading /
network / error overlays and the handleError decision tree, one AppDataManager
gateway, dio comms carrying the three identity headers, secure storage with
random-suffixed keys, and a single-chokepoint Navigator. Package root and Dart
package name are both Grounded; org is nya.
The enforcement engine, one unit per formula in utils/:
- DebtEngine w(class) x severity(d) x decay(t), sublinear severity so old
misses cannot swamp the score; abandonment 2x with 30-day
decay immunity; late complete retains 30%
- StandingEngine Good -> Warned -> Grounded -> Lockdown, derived not set;
Grounded replaces home with the overdue queue
- CapacityEngine blocks over-scheduling against p50 of historically completed
minutes, with a learned per-category estimation multiplier
- IntegrityEngine session integrity, weekly volume, plyometric contact ceiling
and enforced recovery gaps
- ExcuseAnalyser on-device excuse clustering plus the confrontation copy
- GuardrailEngine distress detection and rationed amnesty
- ToneEngine all enforcement copy, so the tone cap lives in one place
CommitmentEvent is append-only and is the source of truth rather than the
status field, which is what makes honest history and excuse analysis possible.
Goals contain commitments via parentId, and a task can be run from a
full-screen runner that derives elapsed time from wall-clock so screen-off
cannot lose time. Backgrounding pauses the clock and is counted. The runner is
mirrored into an ongoing notification, with alarm-class full-screen intents
reserved for non-negotiables.
Design language, fonts, icon and native splash are in place; Mason bricks are
retargeted to this project and verified end-to-end.
flutter analyze lib/ reports no errors.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mfu2gQLSFN21YRBcU2NrTt
This commit is contained in:
186
frontend/bricks/internal_memory/hooks/post_gen.dart
Normal file
186
frontend/bricks/internal_memory/hooks/post_gen.dart
Normal file
@@ -0,0 +1,186 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:mason/mason.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
void run(HookContext context) async {
|
||||
final logger = context.logger;
|
||||
final String functionName = context.vars['function_name'] ?? '';
|
||||
final String requestObject = context.vars['request_object'] ?? '';
|
||||
|
||||
final cName = functionName.camelCase;
|
||||
final pName = functionName.pascalCase;
|
||||
final uName = functionName.snakeCase.toUpperCase();
|
||||
|
||||
final secureKeyValue = _generateSecureKey(uName);
|
||||
|
||||
String projectName = 'your_project';
|
||||
final pubspecFile = File('pubspec.yaml');
|
||||
if (pubspecFile.existsSync()) {
|
||||
final doc = loadYaml(pubspecFile.readAsStringSync());
|
||||
projectName = doc['name'] ?? projectName;
|
||||
}
|
||||
|
||||
final bool isList = requestObject.startsWith('List<');
|
||||
final bool isString = requestObject.toLowerCase() == 'string';
|
||||
|
||||
String baseType = requestObject;
|
||||
if (isList) {
|
||||
baseType = requestObject.substring(5, requestObject.length - 1);
|
||||
}
|
||||
|
||||
final files = [
|
||||
'lib/Grounded/memory/ConnectInternalMemory.dart',
|
||||
'lib/Grounded/memory/InternalMemory.dart',
|
||||
'lib/Grounded/informatics/AppDataManager.dart'
|
||||
];
|
||||
|
||||
String? importLine;
|
||||
String? importFileName;
|
||||
if (!isString) {
|
||||
final result = await _findClassData(baseType, projectName);
|
||||
importLine = result?['line'];
|
||||
importFileName = result?['fileName'];
|
||||
}
|
||||
|
||||
// --- Implementation Logic ---
|
||||
String getLogic = "";
|
||||
String setLogic = "";
|
||||
|
||||
if (isString) {
|
||||
getLogic = "return await groundedStorage.read(key: $uName) ?? '';";
|
||||
setLogic = "await groundedStorage.write(key: $uName, value: data);";
|
||||
} else if (isList) {
|
||||
getLogic = '''
|
||||
final dataString = await groundedStorage.read(key: $uName);
|
||||
if (dataString != null && dataString.isNotEmpty) {
|
||||
return (jsonDecode(dataString) as List)
|
||||
.map((item) => $baseType.fromJson(item))
|
||||
.toList();
|
||||
}
|
||||
return [];''';
|
||||
setLogic = '''
|
||||
final jsonString = jsonEncode(data.map((item) => item.toJson()).toList());
|
||||
await groundedStorage.write(key: $uName, value: jsonString);''';
|
||||
} else {
|
||||
getLogic = '''
|
||||
final jsonString = await groundedStorage.read(key: $uName);
|
||||
if (jsonString != null && jsonString.isNotEmpty) {
|
||||
return $baseType.fromJson(jsonDecode(jsonString));
|
||||
}
|
||||
return $baseType();''';
|
||||
setLogic = '''
|
||||
await groundedStorage.write(key: $uName, value: jsonEncode(data.toJson()));''';
|
||||
}
|
||||
|
||||
// --- 1. ConnectInternalMemory (No space between the pair) ---
|
||||
final interfaceCode = " Future<$requestObject> get$pName();\n Future set$pName($requestObject data);";
|
||||
await _inject(files[0], interfaceCode, logger, importLine: importLine, importFileName: importFileName, duplicateCheck: "get$pName()");
|
||||
|
||||
// --- 2. InternalMemory (Key spacing at TOP) ---
|
||||
final String keyLine = '\n\n static const String $uName = "$secureKeyValue";\n';
|
||||
final String methods = '''
|
||||
@override
|
||||
Future<$requestObject> get$pName() async {
|
||||
$getLogic
|
||||
}
|
||||
|
||||
@override
|
||||
Future set$pName($requestObject data) async {
|
||||
$setLogic
|
||||
}''';
|
||||
|
||||
await _injectInternalMemory(files[1], keyLine, methods, logger, importLine: importLine, importFileName: importFileName, duplicateCheck: "get$pName()");
|
||||
|
||||
// --- 3. AppDataManager ---
|
||||
final String wrapper = '''
|
||||
@override
|
||||
Future<$requestObject> get$pName() async {
|
||||
return await connectInternalMemory.get$pName();
|
||||
}
|
||||
|
||||
@override
|
||||
Future set$pName($requestObject data) async {
|
||||
return await connectInternalMemory.set$pName(data);
|
||||
}''';
|
||||
await _inject(files[2], wrapper, logger, importLine: importLine, importFileName: importFileName, duplicateCheck: "get$pName()");
|
||||
|
||||
// --- 4. Format ---
|
||||
try {
|
||||
await Process.run('dart', ['format', 'lib/Grounded/']);
|
||||
} catch (_) {}
|
||||
|
||||
logger.success('✨ Internal Memory synced with corrected spacing.');
|
||||
}
|
||||
|
||||
String _generateSecureKey(String base) {
|
||||
final random = Random.secure();
|
||||
final values = List<int>.generate(12, (i) => random.nextInt(256));
|
||||
return "${base}_${base64Url.encode(values).replaceAll('=', '').substring(0, 16)}";
|
||||
}
|
||||
|
||||
Future<Map<String, String>?> _findClassData(String className, String projectName) async {
|
||||
final dir = Directory('lib');
|
||||
if (!dir.existsSync()) return null;
|
||||
for (var f in dir.listSync(recursive: true)) {
|
||||
if (f is File && f.path.endsWith('.dart')) {
|
||||
final content = await f.readAsString();
|
||||
if (content.contains('class $className')) {
|
||||
return {
|
||||
'line': "import 'package:$projectName/${f.path.replaceFirst('lib/', '')}';",
|
||||
'fileName': f.path.split('/').last,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _inject(String path, String content, Logger logger, {String? importLine, String? importFileName, String? duplicateCheck}) async {
|
||||
final file = File(path);
|
||||
if (!await file.exists()) return;
|
||||
String fileContent = await file.readAsString();
|
||||
if (duplicateCheck != null && fileContent.contains(duplicateCheck)) return;
|
||||
|
||||
if (importLine != null && importFileName != null && !fileContent.contains(importFileName)) {
|
||||
fileContent = "$importLine\n$fileContent";
|
||||
}
|
||||
|
||||
final lastBrace = fileContent.lastIndexOf('}');
|
||||
if (lastBrace != -1) {
|
||||
// Inject with double newlines between previous content and new content
|
||||
fileContent = fileContent.substring(0, lastBrace).trimRight() + '\n\n$content\n' + fileContent.substring(lastBrace);
|
||||
await file.writeAsString(fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _injectInternalMemory(String path, String keyLine, String methods, Logger logger, {String? importLine, String? importFileName, String? duplicateCheck}) async {
|
||||
final file = File(path);
|
||||
if (!await file.exists()) return;
|
||||
String content = await file.readAsString();
|
||||
|
||||
if (duplicateCheck != null && content.contains(duplicateCheck)) return;
|
||||
|
||||
if (importLine != null && importFileName != null && !content.contains(importFileName)) {
|
||||
content = "$importLine\n$content";
|
||||
}
|
||||
|
||||
if (!content.contains("import 'dart:convert';")) {
|
||||
content = "import 'dart:convert';\n$content";
|
||||
}
|
||||
|
||||
// Inject Key at the top with forced extra spacing
|
||||
final classStart = content.indexOf('{');
|
||||
if (classStart != -1) {
|
||||
content = content.substring(0, classStart + 1) + "$keyLine" + content.substring(classStart + 1);
|
||||
}
|
||||
|
||||
// Inject Methods at the bottom
|
||||
final lastBrace = content.lastIndexOf('}');
|
||||
if (lastBrace != -1) {
|
||||
content = content.substring(0, lastBrace).trimRight() + "\n\n$methods\n" + content.substring(lastBrace);
|
||||
}
|
||||
|
||||
await file.writeAsString(content);
|
||||
}
|
||||
8
frontend/bricks/internal_memory/hooks/pubspec.yaml
Normal file
8
frontend/bricks/internal_memory/hooks/pubspec.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: internal_memory_hooks
|
||||
description: Hooks for internal_memory.
|
||||
publish_to: none
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
dependencies:
|
||||
mason: ^0.1.0-dev.51
|
||||
yaml: ^3.1.2
|
||||
Reference in New Issue
Block a user