From 071aad8e9661a89d886819fbd509273e1f116bc4 Mon Sep 17 00:00:00 2001 From: angellllkr-eng Date: Tue, 9 Jun 2026 11:22:39 +0300 Subject: [PATCH 001/114] archive branch cleanup materials on mind-reply storage --- archive/branch-cleanup-2026-06-09/MANIFEST.md | 79 ++++ .../playbooks/schema.json | 71 ++++ .../src/agents/prompts.md | 111 +++++ .../src/backend/README.md | 33 ++ .../src/backend/audit_log.py | 64 +++ .../src/backend/followup_engine.py | 28 ++ .../src/backend/memory_store.py | 29 ++ .../src/backend/playbook_interpreter.py | 64 +++ .../src/backend/reply_engine.py | 36 ++ .../src/backend/risk_engine.py | 49 +++ .../src/backend/tests/test_decision_layer.py | 122 ++++++ .../src/backend/triage_engine.py | 129 ++++++ .../src/chatgpt-app/README.md | 54 +++ .../src/chatgpt-app/mragent-tools.json | 58 +++ .../src/edge/extension/background.js | 42 ++ .../src/edge/extension/content.js | 78 ++++ .../src/edge/extension/styles.css | 56 +++ .../src/integrations/calendar_connector.py | 60 +++ .../src/integrations/gmail_connector.py | 102 +++++ .../app/api/owner/decision/route.ts | 39 ++ .../app/api/owner/export/route.ts | 46 ++ .../docs/advanced_team_blueprint.md | 65 +++ .../docs/hourly_owner_goal_prompt.md | 37 ++ .../docs/observability_contract.md | 43 ++ .../docs/owner_security_blueprint.md | 48 +++ .../docs/front_end_operating_pack.md | 106 +++++ .../docs/security_owner_decision_report.md | 40 ++ .../lib/request-safety.ts | 64 +++ .../app/agents/page.tsx | 5 + .../app/api/agent/orchestrate/route.ts | 15 + .../app/api/agents/route.ts | 11 + .../components/MOAConsole.tsx | 209 +++++++++ .../docs/MINDREPLY_MULTI_AGENT_BLUEPRINT.md | 87 ++++ .../codex_mindreply-moa-controller/lib/moa.ts | 399 ++++++++++++++++++ .../tests/moa.test.ts | 68 +++ .../app/agent/page.tsx | 25 ++ .../app/api/agent/route.ts | 127 ++++++ .../components/MRAgentChat.tsx | 175 ++++++++ .../components/ai-elements/message.tsx | 25 ++ .../scripts/verify-decision-layer.ts | 78 ++++ .../docs/hourly_owner_goal_prompt.md | 98 +++++ .../docs/security_owner_decision_report.md | 40 ++ .../lib/request-safety.ts | 62 +++ .../scripts/hourly-owner-report-lib.ts | 95 +++++ .../scripts/hourly-owner-report-send.ts | 92 ++++ .../2026-06-09-vercel-quota-guard-followup.md | 68 +++ 46 files changed, 3432 insertions(+) create mode 100644 archive/branch-cleanup-2026-06-09/MANIFEST.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/playbooks/schema.json create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/agents/prompts.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/README.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/audit_log.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/followup_engine.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/memory_store.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/playbook_interpreter.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/reply_engine.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/risk_engine.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/tests/test_decision_layer.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/triage_engine.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/README.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/mragent-tools.json create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/background.js create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/content.js create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/styles.css create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/calendar_connector.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/gmail_connector.py create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/decision/route.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/export/route.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/advanced_team_blueprint.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/hourly_owner_goal_prompt.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/observability_contract.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/owner_security_blueprint.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/front_end_operating_pack.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/security_owner_decision_report.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/lib/request-safety.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/agents/page.tsx create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agent/orchestrate/route.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agents/route.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/components/MOAConsole.tsx create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/docs/MINDREPLY_MULTI_AGENT_BLUEPRINT.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/lib/moa.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/tests/moa.test.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/app/agent/page.tsx create mode 100644 archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/app/api/agent/route.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/components/MRAgentChat.tsx create mode 100644 archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/components/ai-elements/message.tsx create mode 100644 archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/scripts/verify-decision-layer.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/docs/hourly_owner_goal_prompt.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/docs/security_owner_decision_report.md create mode 100644 archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/lib/request-safety.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/scripts/hourly-owner-report-lib.ts create mode 100644 archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/scripts/hourly-owner-report-send.ts create mode 100644 archive/branch-cleanup-2026-06-09/mind-reply/reports/2026-06-09-vercel-quota-guard-followup.md diff --git a/archive/branch-cleanup-2026-06-09/MANIFEST.md b/archive/branch-cleanup-2026-06-09/MANIFEST.md new file mode 100644 index 0000000..4f58c5d --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/MANIFEST.md @@ -0,0 +1,79 @@ +# MindReply Branch Cleanup Archive + +Generated: 2026-06-09 + +This archive preserves selected useful files from cleanup branches before deleting stale GitHub branches. It is stored on `mind-reply`, which is the storage/reference branch. It is not part of production `main`. + +## Branches Reviewed + +- `codespace-super-computing-machine-wv7jrq4q7xjj3vq45` at `705694bd91682fb474e496e2f96f65c62cbf81a4` +- `codex/executive-nervous-system` at `8f8a62592ce15880c769e6b305082f9ed6eac3a7` +- `codex/executive-nervous-system-build` at `b31544b8133f6c1a2518c94345e1e2a141131e02` +- `codex/executive-nervous-system-main-sync` at `fae379006f0d771fbe4780b7782ec57272768c02` +- `codex/executive-nervous-system-rebrand` at `b9800cf331f9fef5afe62365a83659204267069d` +- `codex/full-frontend-platform-pack` at `485c37eac5471c44b53c158e90c01a1ae250188a` +- `codex/hourly-owner-report-current` at `6b4812468f12a8afee0ab38e8889bf1cc75ca035` +- `codex/mindreply-moa-controller` at `54f4e1693ef403a86ff6822555c4f849cab46325` +- `codex/mindreply-moa-main` at `7f74c8d766eb36768d25c2526f5e34560708ba58` +- `codex/mindreply-moa-production-minimal` at `e11090111b37679152bf35162593a219898fe86c` +- `codex/mragent-decision-chat` at `08f0ff3a1b4da034af8de4b5bd966349bc6da5f6` +- `codex/security-revenue-frontend-current` at `8a26cbc967aa57f5d3eb6b19d9e2ff15227d1071` + +## Archived Files + +- `mind-reply` / `reports/2026-06-09-vercel-quota-guard-followup.md` -> `archive/branch-cleanup-2026-06-09/mind-reply/reports/2026-06-09-vercel-quota-guard-followup.md` +- `codex/mindreply-moa-controller` / `components/MOAConsole.tsx` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/components/MOAConsole.tsx` +- `codex/mindreply-moa-controller` / `lib/moa.ts` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/lib/moa.ts` +- `codex/mindreply-moa-controller` / `tests/moa.test.ts` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/tests/moa.test.ts` +- `codex/mindreply-moa-controller` / `docs/MINDREPLY_MULTI_AGENT_BLUEPRINT.md` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/docs/MINDREPLY_MULTI_AGENT_BLUEPRINT.md` +- `codex/mindreply-moa-controller` / `app/api/agent/orchestrate/route.ts` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agent/orchestrate/route.ts` +- `codex/mindreply-moa-controller` / `app/api/agents/route.ts` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agents/route.ts` +- `codex/mindreply-moa-controller` / `app/agents/page.tsx` -> `archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/agents/page.tsx` +- `codex/mragent-decision-chat` / `app/agent/page.tsx` -> `archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/app/agent/page.tsx` +- `codex/mragent-decision-chat` / `app/api/agent/route.ts` -> `archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/app/api/agent/route.ts` +- `codex/mragent-decision-chat` / `components/MRAgentChat.tsx` -> `archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/components/MRAgentChat.tsx` +- `codex/mragent-decision-chat` / `components/ai-elements/message.tsx` -> `archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/components/ai-elements/message.tsx` +- `codex/mragent-decision-chat` / `scripts/verify-decision-layer.ts` -> `archive/branch-cleanup-2026-06-09/codex_mragent-decision-chat/scripts/verify-decision-layer.ts` +- `codex/full-frontend-platform-pack` / `lib/request-safety.ts` -> `archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/lib/request-safety.ts` +- `codex/full-frontend-platform-pack` / `docs/security_owner_decision_report.md` -> `archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/security_owner_decision_report.md` +- `codex/full-frontend-platform-pack` / `docs/front_end_operating_pack.md` -> `archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/front_end_operating_pack.md` +- `codex/security-revenue-frontend-current` / `lib/request-safety.ts` -> `archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/lib/request-safety.ts` +- `codex/security-revenue-frontend-current` / `docs/hourly_owner_goal_prompt.md` -> `archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/docs/hourly_owner_goal_prompt.md` +- `codex/security-revenue-frontend-current` / `docs/security_owner_decision_report.md` -> `archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/docs/security_owner_decision_report.md` +- `codex/security-revenue-frontend-current` / `scripts/hourly-owner-report-lib.ts` -> `archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/scripts/hourly-owner-report-lib.ts` +- `codex/security-revenue-frontend-current` / `scripts/hourly-owner-report-send.ts` -> `archive/branch-cleanup-2026-06-09/codex_security-revenue-frontend-current/scripts/hourly-owner-report-send.ts` +- `codex/executive-nervous-system-build` / `playbooks/schema.json` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/playbooks/schema.json` +- `codex/executive-nervous-system-build` / `src/backend/README.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/README.md` +- `codex/executive-nervous-system-build` / `src/chatgpt-app/README.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/README.md` +- `codex/executive-nervous-system-build` / `src/chatgpt-app/mragent-tools.json` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/mragent-tools.json` +- `codex/executive-nervous-system-build` / `src/agents/prompts.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/agents/prompts.md` +- `codex/executive-nervous-system-build` / `src/backend/audit_log.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/audit_log.py` +- `codex/executive-nervous-system-build` / `src/backend/followup_engine.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/followup_engine.py` +- `codex/executive-nervous-system-build` / `src/backend/memory_store.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/memory_store.py` +- `codex/executive-nervous-system-build` / `src/backend/playbook_interpreter.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/playbook_interpreter.py` +- `codex/executive-nervous-system-build` / `src/backend/reply_engine.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/reply_engine.py` +- `codex/executive-nervous-system-build` / `src/backend/risk_engine.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/risk_engine.py` +- `codex/executive-nervous-system-build` / `src/backend/triage_engine.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/triage_engine.py` +- `codex/executive-nervous-system-build` / `src/backend/tests/test_decision_layer.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/tests/test_decision_layer.py` +- `codex/executive-nervous-system-build` / `src/edge/extension/background.js` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/background.js` +- `codex/executive-nervous-system-build` / `src/edge/extension/content.js` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/content.js` +- `codex/executive-nervous-system-build` / `src/edge/extension/styles.css` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/styles.css` +- `codex/executive-nervous-system-build` / `src/integrations/calendar_connector.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/calendar_connector.py` +- `codex/executive-nervous-system-build` / `src/integrations/gmail_connector.py` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/gmail_connector.py` +- `codex/executive-nervous-system-rebrand` / `docs/advanced_team_blueprint.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/advanced_team_blueprint.md` +- `codex/executive-nervous-system-rebrand` / `docs/observability_contract.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/observability_contract.md` +- `codex/executive-nervous-system-rebrand` / `docs/owner_security_blueprint.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/owner_security_blueprint.md` +- `codex/executive-nervous-system-rebrand` / `docs/hourly_owner_goal_prompt.md` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/hourly_owner_goal_prompt.md` +- `codex/executive-nervous-system-rebrand` / `app/api/owner/decision/route.ts` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/decision/route.ts` +- `codex/executive-nervous-system-rebrand` / `app/api/owner/export/route.ts` -> `archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/export/route.ts` + +## Excluded On Purpose + +- `.env`, `.env.local`, OAuth tokens, webhook URLs, provider secrets, and secret-like files. +- `tokens.yaml` from PR #15 / codespace branch. +- generated build output, `.next`, `*.tsbuildinfo`, `node_modules`, logs, and bulk generated HTML/JS not needed as source-of-truth. +- broad deleted-file snapshots from old branches; Git history remains available until branch deletion, and selected useful sources are archived here. + +## Cleanup Target + +After this archive is pushed, keep only `main` and `mind-reply` branches. diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/playbooks/schema.json b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/playbooks/schema.json new file mode 100644 index 0000000..006408c --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/playbooks/schema.json @@ -0,0 +1,71 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "MindReply Playbook", + "type": "object", + "required": ["playbook_id", "title", "description", "version", "triggers", "decision_tree", "actions", "verification", "audit"], + "properties": { + "playbook_id": { "type": "string", "minLength": 1 }, + "title": { "type": "string", "minLength": 1 }, + "description": { "type": "string", "minLength": 1 }, + "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+$" }, + "triggers": { + "type": "array", + "items": { + "type": "object", + "required": ["type", "pattern"], + "properties": { + "type": { "enum": ["email", "calendar", "file", "webhook", "manual"] }, + "pattern": { "type": "string", "minLength": 1 } + } + } + }, + "decision_tree": { + "type": "object", + "required": ["nodes"], + "properties": { + "nodes": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "condition", "action", "next"], + "properties": { + "id": { "type": "string" }, + "condition": { "type": "string" }, + "action": { "enum": ["reply", "schedule", "resolve", "escalate"] }, + "next": { "type": "array", "items": { "type": "string" } } + } + } + } + } + }, + "actions": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "type", "template_id", "params"], + "properties": { + "id": { "type": "string" }, + "type": { "enum": ["email_template", "api_call", "task_create", "calendar_event", "noop"] }, + "template_id": { "type": "string" }, + "params": { "type": "object" } + } + } + }, + "verification": { + "type": "object", + "required": ["required", "roles"], + "properties": { + "required": { "type": "boolean" }, + "roles": { "type": "array", "items": { "type": "string" } } + } + }, + "audit": { + "type": "object", + "required": ["exportable", "signed"], + "properties": { + "exportable": { "type": "boolean" }, + "signed": { "type": "boolean" } + } + } + } +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/agents/prompts.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/agents/prompts.md new file mode 100644 index 0000000..f4e28a0 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/agents/prompts.md @@ -0,0 +1,111 @@ +# MindReply Agent Prompts + +All agents work inside the Executive Nervous System category. Every output must produce one synthesis and one recommended action. No agent may create alternate paths or expose internal reasoning to the user. + +## Triage Agent + +Role: read the intake and classify importance, urgency, source, and required action. + +Allowed input: + +```json +{ + "input": "string", + "source": "manual | gmail | calendar | extension", + "device_privacy_flag": false, + "playbook_id": "optional string" +} +``` + +Required output: + +```json +{ + "importance": 0, + "urgency": 0, + "required_action": "reply | schedule | resolve | escalate", + "synthesis": "string", + "confidence": 0.82, + "playbook_id": "string" +} +``` + +Escalation behavior: if the intake contains legal, safety, regulatory, clinical, financial-control, or relationship harm signals, return `required_action: "escalate"`. + +## Reply Agent + +Role: prepare one calm reply when the required action is `reply` and risk allows movement. + +Allowed input: + +```json +{ + "input": "string", + "triage": { + "required_action": "reply", + "synthesis": "string", + "playbook_id": "string" + } +} +``` + +Required output: + +```json +{ + "synthesis": "string", + "recommended_action": { + "kind": "reply", + "label": "Send the prepared reply", + "payload": { + "draft": "string" + } + } +} +``` + +Escalation behavior: if risk is high, return no draft and hand the item to the Risk Agent. + +## Follow-Up Agent + +Role: create one timed follow-up when the required action is `schedule`. + +Required output: + +```json +{ + "next_check_timestamp": "ISO string", + "action": "remind | escalate", + "rationale": "string", + "synthesis": "string", + "recommended_action": { + "kind": "schedule | escalate", + "label": "string", + "payload": { + "title": "string", + "starts_at": "ISO string", + "duration_minutes": 15 + } + } +} +``` + +## Risk Agent + +Role: check whether action should be held before movement. + +Required output: + +```json +{ + "risk_level": "low | medium | high", + "level": "low | medium | high", + "reason": "string", + "escalate": true, + "required_verification_roles": ["owner"] +} +``` + +## Shared Rule + +If the input carries legal, safety, regulatory, clinical, financial-control, or relationship risk, the recommended action becomes `escalate`. diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/README.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/README.md new file mode 100644 index 0000000..51e3d0e --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/README.md @@ -0,0 +1,33 @@ +# MindReply Backend Layer + +This directory contains the private Executive Nervous System mechanics. + +## Layers + +- Intake Layer: `triage_engine.py` classifies importance, urgency, source, and required action. +- Action Layer: `reply_engine.py` and `followup_engine.py` produce exactly one next movement. +- Memory Layer: `memory_store.py` stores derived preferences only. Raw input is excluded by default. + +## Four Agents + +- Triage Agent: assigns numeric importance, numeric urgency, required action, and playbook id. +- Reply Agent: creates one calm reply when movement is safe. +- Follow-Up Agent: creates one timed follow-up or escalation event. +- Risk Agent: blocks unsafe movement and requires review where needed. + +## Receipts + +`audit_log.py` writes hash-based receipts with playbook id, version, action, redaction level, and signatures. It must never write raw private text unless a later protected workflow captures explicit consent and retention settings. + +## Playbooks + +`playbook_interpreter.py` loads signed/versioned seed playbooks from `playbooks/seed`. Each playbook must validate against `playbooks/schema.json`. + +## Verification + +Run: + +```bash +python -m unittest discover src +npm run decision:verify +``` diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/audit_log.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/audit_log.py new file mode 100644 index 0000000..0fe47a6 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/audit_log.py @@ -0,0 +1,64 @@ +"""Purpose: append-only privacy-safe audit receipts for executed actions. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +import hashlib +import hmac +import json +import os +import uuid +from datetime import datetime, timezone +from pathlib import Path + + +class AuditLog: + def __init__(self, path: str = "audit.jsonl", signing_key: str | None = None) -> None: + self.path = Path(path) + self.signing_key = signing_key or os.environ.get("MINDREPLY_AUDIT_SIGNING_KEY", "local-dev-signing-key") + + def record( + self, + raw_input: str, + source: str, + action_kind: str, + playbook_id: str = "clear-next-move", + playbook_version: str = "1.0", + synthesis: str = "Decision recorded.", + actor: str = "server", + redaction_level: str = "full", + rationale: str = "One recommended action was produced.", + ) -> dict: + timestamp = datetime.now(timezone.utc).isoformat() + input_hash = hashlib.sha256(raw_input.encode("utf-8")).hexdigest() + receipt = { + "receipt_id": str(uuid.uuid4()), + "timestamp": timestamp, + "playbook_id": playbook_id, + "playbook_version": playbook_version, + "synthesis": synthesis, + "action": action_kind, + "actor": actor, + "input_hash": input_hash, + "source": source, + "redaction_level": redaction_level, + "rationale": rationale, + } + receipt["signatures"] = [{"key_id": "local-dev", "sig": self._sign(receipt)}] + self.path.parent.mkdir(parents=True, exist_ok=True) + with self.path.open("a", encoding="utf-8") as handle: + handle.write(json.dumps(receipt, sort_keys=True) + "\n") + return { + "id": receipt["receipt_id"], + "receipt_id": receipt["receipt_id"], + "timestamp": timestamp, + "source": source, + "playbook_id": playbook_id, + "playbook_version": playbook_version, + "signatures": receipt["signatures"], + } + + def _sign(self, receipt: dict) -> str: + payload = json.dumps({key: value for key, value in receipt.items() if key != "signatures"}, sort_keys=True).encode("utf-8") + return hmac.new(self.signing_key.encode("utf-8"), payload, hashlib.sha256).hexdigest() diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/followup_engine.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/followup_engine.py new file mode 100644 index 0000000..321f297 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/followup_engine.py @@ -0,0 +1,28 @@ +"""Purpose: Action Layer follow-up scheduling for one next check. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +from datetime import datetime, timedelta, timezone + + +class FollowUpEngine: + def schedule(self, triage: dict, minutes_from_now: int = 60, user_preferences: dict | None = None) -> dict: + starts_at = datetime.now(timezone.utc) + timedelta(minutes=minutes_from_now) + action = "escalate" if triage.get("required_action") == "escalate" else "remind" + return { + "next_check_timestamp": starts_at.isoformat(), + "action": action, + "rationale": "One quiet follow-up keeps the item contained.", + "synthesis": triage.get("synthesis") or "The matter needs a timed follow-up.", + "recommended_action": { + "kind": "schedule" if action == "remind" else "escalate", + "label": "Set the follow-up" if action == "remind" else "Hold and review", + "payload": { + "title": "MindReply follow-up", + "starts_at": starts_at.isoformat(), + "duration_minutes": 15, + }, + }, + } diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/memory_store.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/memory_store.py new file mode 100644 index 0000000..ce07416 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/memory_store.py @@ -0,0 +1,29 @@ +"""Purpose: Memory Layer stores derived preferences without raw input. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + + +class MemoryStore: + def __init__(self) -> None: + self._records: dict[str, list[dict]] = {} + + def update(self, user_id: str, raw_input: str, decision: dict) -> dict: + action = decision.get("recommended_action", {}).get("kind", decision.get("required_action", "resolve")) + risk = decision.get("risk", {}).get("level", decision.get("risk_level", "low")) + derived = { + "preferred_action": action, + "tone": "calm", + "follow_up_bias": "contained", + "risk_bias": "review" if risk in {"medium", "high"} else "normal", + "signal_size": "short" if len(raw_input) < 240 else "long", + } + self._records.setdefault(user_id, []).append(derived) + return { + "applied": True, + "summary": "Decision memory adjusted quietly.", + } + + def export(self, user_id: str) -> list[dict]: + return list(self._records.get(user_id, [])) diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/playbook_interpreter.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/playbook_interpreter.py new file mode 100644 index 0000000..e72088b --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/playbook_interpreter.py @@ -0,0 +1,64 @@ +"""Purpose: select one signed/versioned playbook for an intake. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +import json +from pathlib import Path + + +ACTIONS = {"reply", "schedule", "resolve", "escalate"} +REQUIRED_KEYS = {"playbook_id", "title", "description", "version", "triggers", "decision_tree", "actions", "verification", "audit"} + + +class PlaybookInterpreter: + def __init__(self, seed_dir: str | None = None) -> None: + root = Path(__file__).resolve().parents[2] + self.seed_dir = Path(seed_dir) if seed_dir else root / "playbooks" / "seed" + self.playbooks = self._load_playbooks() + + def select(self, raw_input: str) -> dict: + lower = raw_input.lower() + for playbook in self.playbooks: + for trigger in playbook.get("triggers", []): + pattern = str(trigger.get("pattern", "")).lower() + if pattern and pattern in lower: + return self._result(playbook) + return { + "playbook_id": "clear-next-move", + "title": "Clear next move", + "recommended_action": "resolve", + "version": "1.0", + } + + def validate(self, playbook: dict) -> None: + missing = REQUIRED_KEYS - set(playbook.keys()) + if missing: + raise ValueError(f"Playbook missing keys: {sorted(missing)}") + for node in playbook.get("decision_tree", {}).get("nodes", []): + action = node.get("action") + if action not in ACTIONS: + raise ValueError(f"Invalid action: {action}") + if not isinstance(playbook.get("audit", {}).get("signed"), bool): + raise ValueError("Playbook audit.signed must be boolean") + + def _load_playbooks(self) -> list[dict]: + if not self.seed_dir.exists(): + return [] + playbooks: list[dict] = [] + for path in sorted(self.seed_dir.glob("*.json")): + with path.open("r", encoding="utf-8") as handle: + playbook = json.load(handle) + self.validate(playbook) + playbooks.append(playbook) + return playbooks + + def _result(self, playbook: dict) -> dict: + first_node = playbook.get("decision_tree", {}).get("nodes", [{}])[0] + return { + "playbook_id": playbook["playbook_id"], + "title": playbook["title"], + "recommended_action": first_node.get("action", "resolve"), + "version": playbook["version"], + } diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/reply_engine.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/reply_engine.py new file mode 100644 index 0000000..f582afa --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/reply_engine.py @@ -0,0 +1,36 @@ +"""Purpose: Action Layer reply drafting for one calm response. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + + +class ReplyEngine: + def draft(self, raw_input: str, triage: dict, user_profile: dict | None = None) -> dict: + synthesis = triage.get("synthesis") or "The message needs a calm response." + action = triage.get("required_action", "reply") + if action != "reply": + return { + "synthesis": synthesis, + "recommended_action": { + "kind": action, + "label": "Proceed when ready", + "payload": {"rationale": synthesis}, + }, + } + + tone = (user_profile or {}).get("tone", "calm") + draft = self._draft_for_tone(tone) + return { + "synthesis": synthesis, + "recommended_action": { + "kind": "reply", + "label": "Send the prepared reply", + "payload": {"draft": draft}, + }, + } + + def _draft_for_tone(self, tone: str) -> str: + if tone == "formal": + return "Thank you for being direct. I understand the concern and want to keep the next step clear. Let us confirm the decision point and agree the timing." + return "Thank you for being direct. I understand the concern. The next step is to confirm the decision point, protect the relationship, and agree the timing." diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/risk_engine.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/risk_engine.py new file mode 100644 index 0000000..82fb650 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/risk_engine.py @@ -0,0 +1,49 @@ +"""Purpose: Risk Layer validation before movement. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + + +class RiskEngine: + HIGH_RISK_TERMS = { + "threat", + "force", + "blackmail", + "harass", + "illegal", + "self-harm", + "suicide", + "regulator", + "lawsuit", + "breach", + "wire fraud", + } + + MEDIUM_RISK_TERMS = {"complaint", "refund", "termination", "medical", "legal", "fire", "contract", "payment"} + + def assess(self, raw_input: str, context: dict | None = None) -> dict: + lower = raw_input.lower() + if any(term in lower for term in self.HIGH_RISK_TERMS): + return { + "risk_level": "high", + "level": "high", + "reason": "Risk detected before movement.", + "escalate": True, + "required_verification_roles": ["owner"], + } + if any(term in lower for term in self.MEDIUM_RISK_TERMS): + return { + "risk_level": "medium", + "level": "medium", + "reason": "Sensitive context detected; proceed with restraint.", + "escalate": False, + "required_verification_roles": [], + } + return { + "risk_level": "low", + "level": "low", + "reason": "No blocking risk detected.", + "escalate": False, + "required_verification_roles": [], + } diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/tests/test_decision_layer.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/tests/test_decision_layer.py new file mode 100644 index 0000000..8c239d7 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/tests/test_decision_layer.py @@ -0,0 +1,122 @@ +import os +import tempfile +import unittest + +from backend.audit_log import AuditLog +from backend.followup_engine import FollowUpEngine +from backend.memory_store import MemoryStore +from backend.playbook_interpreter import PlaybookInterpreter +from backend.reply_engine import ReplyEngine +from backend.risk_engine import RiskEngine +from backend.triage_engine import TriageEngine + + +class DecisionLayerTests(unittest.TestCase): + def test_triage_returns_exact_numeric_contract(self): + result = TriageEngine().classify( + "A client replied that the fee is too high and they need a careful response today.", + source="manual", + ) + + self.assertEqual( + set(result.keys()), + {"importance", "urgency", "required_action", "synthesis", "confidence", "playbook_id"}, + ) + self.assertEqual(result["required_action"], "reply") + self.assertEqual(result["playbook_id"], "deal-close-assistant") + self.assertIsInstance(result["importance"], int) + self.assertIsInstance(result["urgency"], int) + self.assertGreaterEqual(result["importance"], 0) + self.assertLessEqual(result["importance"], 100) + self.assertGreaterEqual(result["urgency"], 0) + self.assertLessEqual(result["urgency"], 100) + self.assertIn("synthesis", result) + + def test_reply_engine_returns_one_synthesis_and_one_action(self): + triage = { + "synthesis": "Client resistance is about price and trust.", + "required_action": "reply", + "importance": 72, + "urgency": 51, + "playbook_id": "deal-close-assistant", + } + + result = ReplyEngine().draft("Client says the fee is too high.", triage) + + self.assertEqual(set(result.keys()), {"synthesis", "recommended_action"}) + self.assertEqual(result["recommended_action"]["kind"], "reply") + self.assertEqual(set(result["recommended_action"].keys()), {"kind", "label", "payload"}) + self.assertNotIn("option", str(result).lower()) + + def test_followup_engine_creates_single_calendar_payload(self): + result = FollowUpEngine().schedule( + {"synthesis": "The decision needs a quiet check-in.", "required_action": "schedule"}, + minutes_from_now=45, + ) + + self.assertEqual(result["recommended_action"]["kind"], "schedule") + self.assertIn("next_check_timestamp", result) + self.assertIn("starts_at", result["recommended_action"]["payload"]) + self.assertEqual(result["recommended_action"]["payload"]["duration_minutes"], 15) + + def test_risk_engine_escalates_high_risk_input(self): + result = RiskEngine().assess( + "Send a threat to pressure the client into paying today.", + {"required_action": "reply"}, + ) + + self.assertEqual(result["risk_level"], "high") + self.assertEqual(result["level"], "high") + self.assertTrue(result["escalate"]) + self.assertIn("owner", result["required_verification_roles"]) + + def test_memory_store_derives_without_raw_input(self): + store = MemoryStore() + update = store.update( + user_id="owner", + raw_input="This exact private sentence must not be saved.", + decision={"recommended_action": {"kind": "reply"}}, + ) + + self.assertTrue(update["applied"]) + self.assertNotIn("This exact private sentence", str(store.export("owner"))) + + def test_audit_log_writes_signed_hash_receipt(self): + with tempfile.TemporaryDirectory() as directory: + path = os.path.join(directory, "audit.jsonl") + receipt = AuditLog(path).record( + raw_input="Private client text.", + source="manual", + action_kind="reply", + playbook_id="deal-close-assistant", + playbook_version="1.0.0", + synthesis="The client needs price reassurance without overexplaining.", + redaction_level="derived-only", + ) + + self.assertIn("id", receipt) + self.assertEqual(receipt["source"], "manual") + self.assertEqual(receipt["playbook_id"], "deal-close-assistant") + self.assertEqual(receipt["playbook_version"], "1.0.0") + self.assertTrue(receipt["signatures"]) + with open(path, "r", encoding="utf-8") as handle: + content = handle.read() + self.assertIn("input_hash", content) + self.assertIn("signatures", content) + self.assertNotIn("Private client text.", content) + + def test_playbook_interpreter_loads_seed_playbooks(self): + interpreter = PlaybookInterpreter() + result = interpreter.select("The investor asks for the term sheet before Friday.") + + self.assertGreaterEqual(len(interpreter.playbooks), 12) + self.assertEqual( + set(result.keys()), + {"playbook_id", "title", "recommended_action", "version"}, + ) + self.assertEqual(result["playbook_id"], "investor-ir-triage") + self.assertIn(result["recommended_action"], {"reply", "schedule", "resolve", "escalate"}) + + +if __name__ == "__main__": + unittest.main() diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/triage_engine.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/triage_engine.py new file mode 100644 index 0000000..11deae6 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/backend/triage_engine.py @@ -0,0 +1,129 @@ +"""Purpose: deterministic Intake Layer triage for MindReply. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +from dataclasses import dataclass + + +ACTIONS = {"reply", "schedule", "resolve", "escalate"} + + +@dataclass(frozen=True) +class TriageResult: + importance: int + urgency: int + required_action: str + synthesis: str + confidence: float + playbook_id: str + + def to_dict(self) -> dict: + return { + "importance": self.importance, + "urgency": self.urgency, + "required_action": self.required_action, + "synthesis": self.synthesis, + "confidence": self.confidence, + "playbook_id": self.playbook_id, + } + + +class TriageEngine: + HIGH_RISK_TERMS = {"threat", "force", "blackmail", "harass", "illegal", "lawsuit", "regulator", "breach"} + REPLY_TERMS = {"reply", "client", "customer", "email", "message", "fee", "price", "response", "proposal"} + SCHEDULE_TERMS = {"follow up", "check in", "tomorrow", "next week", "calendar", "meeting", "later"} + + def classify( + self, + raw_input: str, + source: str = "manual", + user_context: dict | None = None, + device_privacy_flag: bool = False, + playbook_id: str | None = None, + ) -> dict: + text = " ".join(raw_input.split()).strip() + lower = text.lower() + matched_playbook = playbook_id or self._match_playbook(lower) + action = self._required_action(lower, matched_playbook) + urgency = self._urgency(lower, action) + importance = self._importance(lower, source, matched_playbook, action) + + return TriageResult( + importance=importance, + urgency=urgency, + required_action=action, + synthesis=self._synthesis(text, action), + confidence=0.86 if text else 0.0, + playbook_id=matched_playbook, + ).to_dict() + + def _required_action(self, lower: str, playbook_id: str) -> str: + if any(term in lower for term in self.HIGH_RISK_TERMS) or "risk" in playbook_id: + return "escalate" + if any(term in lower for term in self.SCHEDULE_TERMS): + return "schedule" + if any(term in lower for term in self.REPLY_TERMS): + return "reply" + if playbook_id in {"finance-approval-flow", "compliance-audit-trail", "legal-risk-flag"}: + return "escalate" + return "resolve" + + def _urgency(self, lower: str, action: str) -> int: + score = 35 + if any(term in lower for term in ["today", "urgent", "immediately", "deadline", "now"]): + score += 42 + if action == "escalate": + score += 18 + return min(score, 100) + + def _importance(self, lower: str, source: str, playbook_id: str, action: str) -> int: + score = 48 + if source in {"gmail", "calendar", "extension"}: + score += 6 + if playbook_id != "clear-next-move": + score += 18 + if action == "escalate": + score += 22 + if any(term in lower for term in ["board", "investor", "legal", "wire", "launch"]): + score += 12 + return min(score, 100) + + def _match_playbook(self, lower: str) -> str: + if any(term in lower for term in ["investor", "shareholder", "funding", "term sheet"]): + return "investor-ir-triage" + if any(term in lower for term in ["legal", "lawsuit", "regulator", "contract"]): + return "legal-risk-flag" + if any(term in lower for term in ["press", "journalist", "statement", "crisis"]): + return "pr-crisis-triage" + if any(term in lower for term in ["fee", "price", "proposal", "deal"]): + return "deal-close-assistant" + if any(term in lower for term in ["meeting", "follow up", "next step"]): + return "meeting-outcome-actioner" + if any(term in lower for term in ["audit", "policy", "breach"]): + return "compliance-audit-trail" + if any(term in lower for term in ["client", "customer", "complaint"]): + return "customer-escalation" + if any(term in lower for term in ["candidate", "interview", "hire"]): + return "hiring-decision-helper" + if any(term in lower for term in ["invoice", "payment", "wire", "approval"]): + return "finance-approval-flow" + if any(term in lower for term in ["launch", "release", "ship"]): + return "product-launch-gatekeeper" + if any(term in lower for term in ["family", "personal", "appointment"]): + return "personal-life-triage" + if any(term in lower for term in ["inbox", "newsletter", "fyi"]): + return "exec-inbox-zero" + return "clear-next-move" + + def _synthesis(self, text: str, action: str) -> str: + if not text: + return "No usable input was provided." + if action == "escalate": + return "This carries risk and needs review before movement." + if action == "reply": + return "This needs a calm response that reduces pressure and preserves the relationship." + if action == "schedule": + return "This needs a quiet follow-up moment rather than more wording now." + return "This can be closed with a clear record and no further movement." diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/README.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/README.md new file mode 100644 index 0000000..b86407e --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/README.md @@ -0,0 +1,54 @@ +# MRagent ChatGPT App Scaffold + +This folder defines the developer contract for exposing MRagent as a ChatGPT App or MCP-backed tool surface. + +The public site remains minimal. This scaffold does not include credentials, private strategy, provider keys, or founder-only operating notes. + +## Tool Contract + +`mragent.decision` accepts one text intake and returns the same shape as `POST /api/intake`: + +```json +{ + "synthesis": "string", + "recommendedAction": { + "kind": "reply | schedule | resolve | escalate", + "label": "string", + "payload": {} + }, + "risk": { + "level": "low | medium | high", + "reason": "string", + "escalate": false + }, + "memoryUpdate": { + "applied": true, + "summary": "string" + }, + "receipt": { + "id": "string", + "timestamp": "ISO string", + "source": "manual | gmail | calendar | extension", + "playbookId": "string", + "playbookVersion": "string", + "redactionLevel": "derived-only", + "signature": "string" + } +} +``` + +`mragent.chat` accepts a friendly user message and returns the `/api/agent` response with an addressable receipt. Raw input is not stored by default. + +## Build Notes + +- Keep generated text private to the user session unless explicit consent is captured. +- Never expose provider names, hidden prompts, staffing claims, tokens, or internal strategy. +- Every response must contain one synthesis and one recommended action. +- High-risk text must escalate instead of drafting a response. + +## Deployment + +The live Next.js app already exposes the required endpoints. A future MCP server can import these contracts and proxy to: + +- `POST https://www.mind-reply.com/api/intake` +- `POST https://www.mind-reply.com/api/agent` diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/mragent-tools.json b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/mragent-tools.json new file mode 100644 index 0000000..4332fab --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/chatgpt-app/mragent-tools.json @@ -0,0 +1,58 @@ +{ + "name": "mindreply-mragent", + "version": "0.1.0", + "tools": [ + { + "name": "mragent.decision", + "description": "Return one synthesis, one recommended action, risk, memory update, and receipt for a supplied intake.", + "input_schema": { + "type": "object", + "additionalProperties": false, + "required": ["input"], + "properties": { + "input": { "type": "string", "minLength": 1 }, + "source": { + "type": "string", + "enum": ["manual", "gmail", "calendar", "extension"], + "default": "manual" + }, + "userId": { "type": "string" }, + "consentFullContent": { "type": "boolean", "default": false }, + "devicePrivacyFlag": { "type": "boolean", "default": false } + } + }, + "output_schema": { + "type": "object", + "required": ["synthesis", "recommendedAction", "risk", "memoryUpdate", "receipt"], + "properties": { + "synthesis": { "type": "string" }, + "recommendedAction": { + "type": "object", + "required": ["kind", "label", "payload"], + "properties": { + "kind": { "type": "string", "enum": ["reply", "schedule", "resolve", "escalate"] }, + "label": { "type": "string" }, + "payload": { "type": "object" } + } + }, + "risk": { "type": "object" }, + "memoryUpdate": { "type": "object" }, + "receipt": { "type": "object" } + } + } + }, + { + "name": "mragent.chat", + "description": "Return a friendly MRagent response that still maps to the decision receipt contract.", + "input_schema": { + "type": "object", + "additionalProperties": false, + "required": ["input"], + "properties": { + "input": { "type": "string", "minLength": 1 }, + "userId": { "type": "string" } + } + } + } + ] +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/background.js b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/background.js new file mode 100644 index 0000000..af43a82 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/background.js @@ -0,0 +1,42 @@ +const DEFAULT_ENDPOINT = "https://www.mind-reply.com/api/intake"; + +chrome.runtime.onInstalled.addListener(() => { + chrome.contextMenus.create({ + id: "mindreply-intake", + title: "MindReply: clarify next move", + contexts: ["selection"] + }); +}); + +chrome.contextMenus.onClicked.addListener(async (info, tab) => { + if (!tab?.id || !info.selectionText) return; + const decision = await requestDecision(info.selectionText); + await chrome.tabs.sendMessage(tab.id, { type: "MINDREPLY_DECISION", decision }); +}); + +chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { + if (message?.type !== "MINDREPLY_DECIDE" || !message.text) return false; + requestDecision(message.text) + .then((decision) => sendResponse({ ok: true, decision })) + .catch((error) => sendResponse({ ok: false, error: error.message })); + return true; +}); + +async function requestDecision(text) { + const stored = await chrome.storage.sync.get("endpoint"); + const endpoint = stored.endpoint || DEFAULT_ENDPOINT; + const response = await fetch(endpoint, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + input: text, + source: "extension", + consentFullContent: false, + devicePrivacyFlag: false + }) + }); + if (!response.ok) { + throw new Error(`MindReply request failed with ${response.status}`); + } + return response.json(); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/content.js b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/content.js new file mode 100644 index 0000000..a435c95 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/content.js @@ -0,0 +1,78 @@ +chrome.runtime.onMessage.addListener((message) => { + if (message.type !== "MINDREPLY_DECISION") return; + renderDecision(message.decision); +}); + +document.addEventListener("mouseup", () => { + const selection = window.getSelection()?.toString().trim(); + if (!selection || selection.length < 12) return; + showInlineTrigger(selection); +}); + +function showInlineTrigger(text) { + removeElement("mindreply-inline-trigger"); + const trigger = document.createElement("button"); + trigger.id = "mindreply-inline-trigger"; + trigger.type = "button"; + trigger.textContent = "MindReply"; + trigger.addEventListener("click", () => { + trigger.disabled = true; + chrome.runtime.sendMessage({ type: "MINDREPLY_DECIDE", text }, (response) => { + trigger.remove(); + if (!response?.ok) { + renderError(response?.error || "MindReply could not read that selection."); + return; + } + renderDecision(response.decision); + }); + }); + document.body.appendChild(trigger); +} + +function renderDecision(decision) { + removeElement("mindreply-inline-decision"); + const panel = document.createElement("aside"); + panel.id = "mindreply-inline-decision"; + + const title = document.createElement("strong"); + title.textContent = "MindReply"; + panel.appendChild(title); + + const synthesis = document.createElement("p"); + synthesis.textContent = decision?.synthesis || "One synthesis is ready."; + panel.appendChild(synthesis); + + const action = document.createElement("button"); + action.type = "button"; + action.textContent = decision?.recommendedAction?.label || "Proceed when ready"; + panel.appendChild(action); + + const details = document.createElement("small"); + const risk = decision?.risk?.level || "low"; + const receipt = decision?.receipt?.id || "pending"; + details.textContent = `Risk: ${risk} · Receipt: ${receipt}`; + panel.appendChild(details); + + const close = document.createElement("button"); + close.type = "button"; + close.textContent = "Close"; + close.setAttribute("aria-label", "Close MindReply panel"); + close.addEventListener("click", () => panel.remove()); + panel.appendChild(close); + + document.body.appendChild(panel); +} + +function renderError(message) { + renderDecision({ + synthesis: message, + recommendedAction: { label: "Try again" }, + risk: { level: "low" }, + receipt: { id: "none" } + }); +} + +function removeElement(id) { + const existing = document.getElementById(id); + if (existing) existing.remove(); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/styles.css b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/styles.css new file mode 100644 index 0000000..a9dd711 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/edge/extension/styles.css @@ -0,0 +1,56 @@ +#mindreply-inline-trigger { + position: fixed; + right: 20px; + bottom: 92px; + z-index: 2147483647; + border: 1px solid rgba(201, 169, 97, 0.55); + border-radius: 999px; + padding: 9px 14px; + background: #081121; + color: #f8f5f0; + box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26); + font: 700 13px Inter, system-ui, sans-serif; +} + +#mindreply-inline-decision { + position: fixed; + right: 20px; + bottom: 20px; + z-index: 2147483647; + max-width: min(360px, calc(100vw - 40px)); + padding: 18px; + border: 1px solid rgba(201, 169, 97, 0.45); + border-radius: 14px; + background: #081121; + color: #f8f5f0; + box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); + font-family: Inter, system-ui, sans-serif; +} + +#mindreply-inline-decision p { + margin: 10px 0; + line-height: 1.5; +} + +#mindreply-inline-decision button { + width: 100%; + border: 0; + border-radius: 999px; + padding: 10px 14px; + background: #c9a961; + color: #081121; + font-weight: 700; +} + +#mindreply-inline-decision button + button { + margin-top: 8px; + background: transparent; + color: #cdd6e4; + border: 1px solid rgba(205, 214, 228, 0.26); +} + +#mindreply-inline-decision small { + display: block; + margin: 10px 0; + color: #cdd6e4; +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/calendar_connector.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/calendar_connector.py new file mode 100644 index 0000000..4d46f8d --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/calendar_connector.py @@ -0,0 +1,60 @@ +"""Purpose: calendar adapter for one follow-up or escalation event. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +import json +import os +from datetime import datetime, timedelta, timezone +from pathlib import Path + + +class CalendarConnector: + """Writes a single event payload to an outbox or returns it to a host adapter.""" + + def __init__(self, path: str | None = None, env: dict | None = None) -> None: + self.env = env or os.environ + self.path = Path(path or self.env.get("MINDREPLY_CALENDAR_OUTBOX", "calendar-outbox.jsonl")) + + def ready(self) -> bool: + return bool(self.env.get("MINDREPLY_CALENDAR_PROVIDER") or self.env.get("MINDREPLY_CALENDAR_OUTBOX")) + + def event_from_decision(self, decision: dict, delay_minutes: int = 60, persist: bool = False) -> dict: + action = decision.get("recommendedAction") or decision.get("recommended_action") or {} + kind = action.get("kind", "schedule") + payload = action.get("payload", {}) if isinstance(action.get("payload", {}), dict) else {} + starts_at = payload.get("starts_at") or payload.get("startsAt") or self._timestamp(delay_minutes) + title = payload.get("title") or ("MindReply review" if kind == "escalate" else "MindReply follow-up") + event = { + "title": title, + "starts_at": starts_at, + "duration_minutes": int(payload.get("duration_minutes", 15)), + "kind": "escalation" if kind == "escalate" else "follow_up", + "synthesis": decision.get("synthesis", "Decision receipt available."), + "receipt_id": (decision.get("receipt") or {}).get("id"), + } + if persist: + self._write(event) + return event + + def create_followup(self, title: str, delay_minutes: int = 60, note: str = "", persist: bool = True) -> dict: + event = { + "title": title, + "starts_at": self._timestamp(delay_minutes), + "duration_minutes": 15, + "kind": "follow_up", + "synthesis": note, + "receipt_id": None, + } + if persist: + self._write(event) + return event + + def _timestamp(self, delay_minutes: int) -> str: + return (datetime.now(timezone.utc) + timedelta(minutes=delay_minutes)).isoformat() + + def _write(self, event: dict) -> None: + self.path.parent.mkdir(parents=True, exist_ok=True) + with self.path.open("a", encoding="utf-8") as handle: + handle.write(json.dumps(event, sort_keys=True) + "\n") diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/gmail_connector.py b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/gmail_connector.py new file mode 100644 index 0000000..8477e4a --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-build/src/integrations/gmail_connector.py @@ -0,0 +1,102 @@ +"""Purpose: Gmail/IMAP intake adapter that sends only safe candidates into MindReply. +Local test: python -m unittest discover src +""" + +from __future__ import annotations + +import os +from dataclasses import dataclass +from typing import Iterable + + +@dataclass(frozen=True) +class MailCandidate: + source: str + input: str + consent_full_content: bool + device_privacy_flag: bool + metadata: dict + + def to_intake(self) -> dict: + return { + "source": self.source, + "input": self.input, + "consent_full_content": self.consent_full_content, + "device_privacy_flag": self.device_privacy_flag, + "metadata": self.metadata, + } + + +class GmailConnector: + """Header/snippet-first connector for Gmail or standard IMAP. + + The connector avoids network reads unless the host process has configured + credentials. Raw body text is included only when explicit consent is supplied + for that request. + """ + + REQUIRED_ENV = ("MINDREPLY_IMAP_HOST", "MINDREPLY_IMAP_USER", "MINDREPLY_IMAP_PASSWORD") + + def __init__(self, env: dict | None = None) -> None: + self.env = env or os.environ + + def ready(self) -> bool: + return all(self.env.get(name) for name in self.REQUIRED_ENV) + + def candidate_from_message( + self, + subject: str, + sender: str, + snippet: str, + message_id: str | None = None, + consent_full_content: bool = False, + body: str | None = None, + device_privacy_flag: bool = False, + ) -> dict: + safe_subject = self._compact(subject) + safe_sender = self._compact(sender) + safe_snippet = self._compact(snippet, limit=280) + content = body if consent_full_content and body else f"From: {safe_sender}\nSubject: {safe_subject}\nSnippet: {safe_snippet}" + candidate = MailCandidate( + source="gmail", + input=content, + consent_full_content=bool(consent_full_content and body), + device_privacy_flag=device_privacy_flag, + metadata={ + "message_id": message_id, + "subject_present": bool(safe_subject), + "sender_present": bool(safe_sender), + "body_included": bool(consent_full_content and body), + }, + ) + return candidate.to_intake() + + def fetch_candidates(self, limit: int = 10) -> list[dict]: + """Return candidate payloads when a host process wires IMAP access. + + This repository keeps the connector deterministic and dependency-light. + Production workers can call `candidate_from_message` after reading mail + through their approved Gmail or IMAP client. + """ + + if not self.ready(): + return [] + return [] + + def batch_from_headers(self, messages: Iterable[dict]) -> list[dict]: + return [ + self.candidate_from_message( + subject=str(message.get("subject", "")), + sender=str(message.get("sender", "")), + snippet=str(message.get("snippet", "")), + message_id=message.get("message_id"), + consent_full_content=bool(message.get("consent_full_content", False)), + body=message.get("body"), + device_privacy_flag=bool(message.get("device_privacy_flag", False)), + ) + for message in messages + ] + + def _compact(self, value: str, limit: int = 160) -> str: + compact = " ".join(value.split()) + return compact[:limit] diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/decision/route.ts b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/decision/route.ts new file mode 100644 index 0000000..275abf0 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/decision/route.ts @@ -0,0 +1,39 @@ +import { NextResponse } from "next/server"; + +type ActionKind = "reply" | "schedule" | "resolve" | "escalate"; +type Role = "owner" | "reviewer" | "operator"; +type Redaction = "metadata" | "partial" | "full"; + +const actions = new Set(["reply", "schedule", "resolve", "escalate"]); + +export async function POST(request: Request) { + const body = (await request.json().catch(() => ({}))) as { + owner_email?: string; + role?: Role; + synthesis?: string; + recommended_action?: ActionKind; + consent_granted?: boolean; + redaction_level?: Redaction; + }; + + const ownerEmail = String(body.owner_email ?? "").trim().toLowerCase(); + const role = body.role ?? "owner"; + const action = body.recommended_action && actions.has(body.recommended_action) ? body.recommended_action : "reply"; + const consentGranted = body.consent_granted === true; + const exportAllowed = Boolean(ownerEmail && role === "owner" && consentGranted); + + return NextResponse.json({ + decision_id: crypto.randomUUID(), + timestamp: new Date().toISOString(), + owner_email: ownerEmail, + role, + synthesis: String(body.synthesis ?? "No synthesis provided.").replace(/\s+/g, " ").trim().slice(0, 320), + recommended_action: action, + consent_granted: consentGranted, + redaction_level: body.redaction_level ?? "metadata", + export_allowed: exportAllowed, + reason: exportAllowed + ? "Owner consent verified; export can be prepared." + : "Owner export is held until owner identity and consent are verified.", + }); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/export/route.ts b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/export/route.ts new file mode 100644 index 0000000..505b47b --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/app/api/owner/export/route.ts @@ -0,0 +1,46 @@ +import { NextResponse } from "next/server"; + +type ActionKind = "reply" | "schedule" | "resolve" | "escalate"; + +export async function POST(request: Request) { + const body = (await request.json().catch(() => ({}))) as { + owner_email?: string; + synthesis?: string; + recommended_action?: ActionKind; + redaction_level?: string; + receipt_id?: string; + export_allowed?: boolean; + }; + + if (body.export_allowed !== true) { + return NextResponse.json( + { + prepared: false, + reason: "Owner export is held until owner identity and consent are verified.", + }, + { status: 403 }, + ); + } + + const action = body.recommended_action ?? "reply"; + const bodyText = [ + "MindReply owner decision package", + `Synthesis: ${String(body.synthesis ?? "No synthesis provided.").replace(/\s+/g, " ").trim().slice(0, 320)}`, + `Recommended action: ${action}`, + `Redaction level: ${body.redaction_level ?? "metadata"}`, + `Receipt: ${body.receipt_id ?? crypto.randomUUID()}`, + "Raw content is excluded unless the owner explicitly exports it.", + ].join("\n"); + + return NextResponse.json({ + prepared: true, + export_id: crypto.randomUUID(), + timestamp: new Date().toISOString(), + to: String(body.owner_email ?? "").trim().toLowerCase(), + subject: "MindReply owner decision package", + body: bodyText, + recommended_action: action, + redaction_level: body.redaction_level ?? "metadata", + delivery_status: "prepared", + }); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/advanced_team_blueprint.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/advanced_team_blueprint.md new file mode 100644 index 0000000..009bd47 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/advanced_team_blueprint.md @@ -0,0 +1,65 @@ +# Advanced Team Blueprint + +MindReply keeps one Knowledge Lead and replaces broad agent sprawl with an advanced execution team. + +## Team Shape + +### Knowledge Lead + +Owns category language, playbooks, privacy rules, owner rules, and product memory. + +Friction removed: the owner no longer has to re-explain the category each time. + +Decision simplified: every team lane receives one trusted source of truth. + +Trust built: language, privacy, and owner rules stay consistent. + +Copy resistance: a cheaper copy can imitate screens, but not accumulated category memory and signed operating rules. + +Category fit: this is the nervous system memory layer. + +### Social Signal Lead + +Turns founder updates, proof points, and public pressure into one discreet growth move. + +Friction removed: social presence becomes a single prepared action, not a noisy content calendar. + +Decision simplified: the owner sees one message or one public move. + +Trust built: public language stays calm, precise, and category-safe. + +Copy resistance: the voice compounds through repeated, disciplined proof. + +Category fit: this extends Decision Infrastructure into daily visibility. + +### Expert Trust Lead + +Turns proof, founder notes, privacy claims, and use cases into authority assets. + +Friction removed: sales and trust material no longer starts from a blank page. + +Decision simplified: the team gets one proof-led asset to publish, send, or hold. + +Trust built: every claim is tied to proof, receipt logic, or owner-approved language. + +Copy resistance: trust comes from evidence and restraint, not louder claims. + +Category fit: this makes the Executive Nervous System understandable to serious buyers. + +### Azure Security Lead + +Protects owner access, export consent, receipts, runtime health, and observability. + +Friction removed: security work becomes one control action at a time. + +Decision simplified: high-risk items escalate; healthy items remain quiet. + +Trust built: the owner path, export path, and runtime path are visible and reviewable. + +Copy resistance: infrastructure discipline is harder to copy than a homepage. + +Category fit: this is the protective reflex of the nervous system. + +## Operating Rule + +Each lane returns one synthesis and one recommended action. If the lane cannot reduce the work, it escalates. diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/hourly_owner_goal_prompt.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/hourly_owner_goal_prompt.md new file mode 100644 index 0000000..a467a45 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/hourly_owner_goal_prompt.md @@ -0,0 +1,37 @@ +# Hourly Owner Goal Prompt + +This is private operating context for internal lanes only. + +## Prime Directive + +Revenue-first. Stop builder thinking. Fix only buying friction. Sell Website Completion Package first. + +## Active Lanes + +- Revenue Lead: package, assisted close, pricing copy. +- Frontend Lead: homepage clarity, trust proof, authority layer. +- Deploy Lead: Vercel blocker, build status, domain state. +- Security Lead: secrets, auth and payment safety, redacted owner evidence. +- Growth Lead: LinkedIn and email lines, search intent, ad proof. +- Product Lead: first three-minute value, upgrade trigger. +- Reporting Lead: email and Slack delivery receipt. + +## Hourly Rule + +Each hour returns one synthesis and one recommended action for the owner. + +## Selling Rule + +Lead with Website Completion Package. Every change must reduce buying friction, strengthen the premium authority layer, add trust proof, or make assisted close easier. + +## Priority Rule + +Deprioritize Slack and MCP work unless it closes revenue this hour. + +## Security Boundary + +Reports are private, owner-only, and redacted. No raw client material leaves the workspace. Missing provider secrets create a blocked receipt. + +## Public Boundary + +No public page may claim active internal staff count or reveal internal prompts. diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/observability_contract.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/observability_contract.md new file mode 100644 index 0000000..84bcc72 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/observability_contract.md @@ -0,0 +1,43 @@ +# Observability Contract + +MindReply observability stays quiet. It records system health and owner-critical events without demanding attention. + +## Events + +- intake.received +- action.prepared +- risk.blocked +- memory.updated +- owner.decision.prepared +- owner.export.held +- owner.export.prepared + +## Required Fields + +- event_name +- timestamp +- decision_id +- recommended_action +- redaction_level +- actor_role +- receipt_id + +## Alert Conditions + +- High-risk action without owner review. +- Export request without consent. +- Missing receipt. +- Mail delivery provider unavailable. +- Repeated memory write failure. + +## Friction Removed + +The owner does not need to inspect logs unless a trust boundary is crossed. + +## Decision Simplified + +Every alert maps to one owner action: review, hold, retry, or close. + +## Trust Built + +The system proves when it acted, when it paused, and why. diff --git a/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/owner_security_blueprint.md b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/owner_security_blueprint.md new file mode 100644 index 0000000..79bc440 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_executive-nervous-system-rebrand/docs/owner_security_blueprint.md @@ -0,0 +1,48 @@ +# Owner Security Blueprint + +MindReply can work directly with the owner only through a verified decision path. + +## Owner Decision Rule + +Owner-level execution requires: + +- Verified owner email. +- Explicit consent. +- One synthesis. +- One recommended action. +- Redaction level. +- Signed receipt. + +If any item is missing, export is held. + +## Owner Mail Package + +The owner mail package contains: + +- Source label. +- Synthesis. +- Recommended action. +- Redaction level. +- Receipt identifier. + +Raw content stays excluded unless the owner explicitly exports it. + +## Friction Removed + +The owner no longer needs to inspect every source thread before seeing the decision shape. + +## Decision Simplified + +The owner sees one recommended action and one reason to act, pause, or review. + +## Trust Built + +Every owner package is consented, redacted, and tied to a receipt. + +## Copy Resistance + +A cheaper copy can imitate the screen. It cannot easily reproduce consent history, role gates, redacted receipts, and repeated private behavior. + +## Category Fit + +This is Decision Infrastructure: the layer between input and action, with the owner kept in control. diff --git a/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/front_end_operating_pack.md b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/front_end_operating_pack.md new file mode 100644 index 0000000..bb302ee --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/front_end_operating_pack.md @@ -0,0 +1,106 @@ +# MRagent Front End Operating Pack + +This pack explains how the current MindReply front end works and what each surface is responsible for. + +## Surfaces + +- `/`: the public front door. It now presents immediate operational relief, premium communication intelligence, the paid ladder, trust proof, promotion readiness, and owner-visible observability. +- `/agent`: the live MRagent session. It accepts charged text, explains the slow reply, and returns one synthesis, one recommended move, risk state, memory summary, and a quiet receipt. +- `/pack`: the private completion surface. It shows delivery readiness, revenue truth, promotion queue state, reporting lanes, and confirmed destination status. +- `/privacy`: the restraint page. It explains why raw pressure is not kept as a default record. +- `/mcp`: the ChatGPT App connection surface for Developer Mode. + +## How The Interaction Works + +1. A user places the charged message or hesitation into MRagent. +2. The browser calls `/api/agent` with the message and source. +3. If the model/provider path is unavailable, the app falls back to `/api/intake`. +4. The decision layer returns a structured result: synthesis, mind read, recommended action, risk, memory summary, and receipt. +5. The UI renders the answer through the AI Elements message component, then displays the structured receipt below it. +6. Persistence remains privacy-safe: no raw input is stored by default, and Blob storage is private when configured. + +## Full Front End Map + +The front end is intentionally not a marketing-only page. It is the usable product surface: + +- Hero: `Reclaim 2+ hours daily within 24 hours` plus the first-output promise. +- Authority layer: executive communication intelligence, professional lexicons, tone, structure, empathy, persuasion, and compliance-aware refinement. +- Paid path: free first output, credits/package, Growth, and Pro. +- Trust proof: stored vs not stored, memory consent, sensitive-work review, request safety, and owner logs. +- Promotion readiness: MRadvertisingTeam, assisted close, and revenue-readiness language without fake posting claims. +- Completion pack: delivery status, real revenue counters, report lanes, and blockers. + +## 40-Minute Reporting + +The Codex app heartbeat `mindreply-40-minute-revenue-and-security-updates` runs every 40 minutes and produces a 7-section owner-facing report. + +The report sections are: + +1. Status +2. Changed +3. Security / Owner Decisions +4. Revenue Move +5. Website / Frontend +6. Blocked +7. Next Safe Action + +Delivery is intentionally gated. The report writes to the thread first, then attempts Outlook delivery to `ANGELLLKR@GMAIL.COM`. Slack or other platform posting requires a connected destination and explicit approval in the active thread. + +## Revenue-First Rule + +This week, the priority is not infrastructure breadth. The priority is buying friction: + +- make Website Completion Package the first paid offer; +- keep the first free output visible; +- add trust proof before asking for sensitive input; +- make credits, package, Growth, and Pro visible; +- use assisted close through email, booking, and direct follow-up; +- pause Slack/MCP polish unless it directly closes revenue. + +## Automation Guardrails + +The safe automation posture is: + +- prepare campaign material, do not publish externally without connected accounts and explicit approval; +- report blockers directly instead of pretending an integration works; +- avoid stealth posting, guaranteed reach, or guaranteed revenue language; +- keep deployment work on guarded branches until production approval is explicit; +- keep transaction and revenue counters tied to real sources. + +## Motion Direction + +A Remotion spot should show MindReply without loud product theatrics: + +- Scene 1: a charged message sits on a quiet field. +- Scene 2: the words dim while pressure, protection, risk, and next move become visible. +- Scene 3: one composed reply appears beside a narrow receipt. +- Scene 4: the Completion Pack receives the status without exposing the original text. + +Motion should be restrained: slow fades, precise reveals, no fake revenue, no exaggerated claims. + +## Promotion Positioning + +Promotion should not promise hidden posting, guaranteed revenue, or platform-wide distribution without connected accounts. The safe posture is: + +- publish only where accounts and permissions are real; +- report what was prepared, sent, or blocked; +- keep the language private, elegant, and specific; +- never invent transactions, audience response, or revenue. + +Use this line as the campaign spine: + +> Reclaim the hour. Rescue the message. Keep the receipt narrow. + +## Figma State + +- Existing preview: https://www.figma.com/design/QLximv9mLCIwQB2GPgBgeG +- New direction file: https://www.figma.com/design/PuRHREBbTixXGxPsBEI1yz +- FigJam operating map: https://www.figma.com/board/G0lSiegpqHSoQDpmgoYKDL + +The connected Figma account currently reports a Starter plan with a View seat. That blocks creating new editable files, placing new frames, FigJam edits, and Code Connect mappings from this session. Once an edit-capable seat is available, the next Figma step is to place the editable frames and map them to `app/page.tsx`, `components/MRAgentChat.tsx`, and `app/pack/page.tsx`. + +## Vercel And Observability + +`vercel.json` disables deployments for every branch except `main`, which prevents duplicate preview deployment spam while frontend work is in progress. Production deployment still requires an explicit merge to `main` and a quota-safe release window. + +Vercel Speed Insights is mounted in `app/layout.tsx`. This branch adds structured owner logs for `/api/agent`, `/api/intake`, and `/mcp`: request source, risk state, fallback/persistence status, batch size, rejection reason, and no raw user text. diff --git a/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/security_owner_decision_report.md b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/security_owner_decision_report.md new file mode 100644 index 0000000..2d7dc33 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/docs/security_owner_decision_report.md @@ -0,0 +1,40 @@ +# MindReply Security Owner Decision Report + +Date: 2026-06-09 +Branch: `codex/full-frontend-platform-pack` + +## Status + +A formal Codex Security Deep Security Scan was attempted, but the six delegated discovery worker handles disappeared before a complete round could be collected. Partial artifacts were preserved under the local scan directory, but the round did not meet the Deep Security completion rules, so it must not be represented as a completed deep scan. + +Local artifact root: + +`C:\Users\angel\AppData\Local\Temp\codex-security-scans\MindReply\github-codex-full-frontend-platform-pack_20260609T030000Z` + +## Fixed In This Branch + +- Added `lib/request-safety.ts` with request body limits, text input limits, owner-trusted user id handling, and structured owner logs. +- Updated `/api/agent` to reject missing, invalid, oversized, or too-long input and log safe request status without raw user text. +- Updated `/api/intake` to reject unsafe input and stop trusting client-provided `userId` unless `MINDREPLY_OWNER_API_TOKEN` authorizes the request. +- Updated `/mcp` to reject oversized JSON bodies, limit JSON-RPC batch size, and enforce the same text-input cap before MRagent tool calls. +- Updated the homepage to include the commercial trust layer: what is stored, what is not stored, memory consent, sensitive-work review, and owner-visible telemetry. + +## Owner Decisions Needed + +1. Auth mode for production user accounts: choose the identity provider before storing user-owned memory or payment-linked activity. +2. Owner API token policy: set `MINDREPLY_OWNER_API_TOKEN` only for trusted owner/admin API usage; do not expose it to the browser. +3. Memory consent: decide the exact UX copy and storage rule before enabling persistent long-term memory. +4. Sensitive-work review: decide which legal, finance, executive, or client-facing cases must be held for human review before send-ready output is treated as final. +5. Deep scan rerun: rerun Codex Security only when delegated workers can complete a full six-worker round, or use the ordinary repository security scan workflow as the fallback. + +## Current Expansion Rule + +MindReply can expand through lanes, not uncontrolled automation: + +- Security lane: owner decisions, request safety, privacy proof, scan reports. +- Revenue lane: Website Completion Package, assisted close, pricing ladder, outbound copy. +- Frontend lane: first free output, premium authority layer, trust proof, paid path. +- Integration lane: email, Slack, ChatGPT App, and future auth only when credentials and approval are explicit. +- Observability lane: structured logs and safe status reports without raw sensitive content. + +No public posting, production deployment, credential changes, spending, or destructive operations should occur without explicit owner approval in the active thread. diff --git a/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/lib/request-safety.ts b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/lib/request-safety.ts new file mode 100644 index 0000000..e4f6f1a --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_full-frontend-platform-pack/lib/request-safety.ts @@ -0,0 +1,64 @@ +export const MAX_TEXT_INPUT_CHARS = 8000; +export const MAX_JSON_BODY_BYTES = 32768; +export const MAX_MCP_BATCH_ITEMS = 8; + +export class SafeRequestError extends Error { + status: number; + code: string; + + constructor(status: number, code: string, message: string) { + super(message); + this.name = "SafeRequestError"; + this.status = status; + this.code = code; + } +} + +export async function readJsonRequest(request: Request, maxBytes = MAX_JSON_BODY_BYTES): Promise { + const text = await request.text().catch(() => ""); + if (!text.trim()) throw new SafeRequestError(400, "empty_body", "Request body is required."); + + const bodyBytes = new TextEncoder().encode(text).length; + if (bodyBytes > maxBytes) { + throw new SafeRequestError(413, "body_too_large", `Request body must be ${maxBytes} bytes or smaller.`); + } + + try { + return JSON.parse(text) as unknown; + } catch { + throw new SafeRequestError(400, "invalid_json", "Request body must be valid JSON."); + } +} + +export function assertTextInputWithinLimit(input: string, maxChars = MAX_TEXT_INPUT_CHARS) { + if (input.length > maxChars) { + throw new SafeRequestError(413, "input_too_large", `Input must be ${maxChars} characters or fewer.`); + } +} + +export function trustedClientUserId(request: Request, body: unknown) { + const ownerToken = process.env.MINDREPLY_OWNER_API_TOKEN; + const authorization = request.headers.get("authorization") || ""; + const bearer = authorization.startsWith("Bearer ") ? authorization.slice("Bearer ".length) : ""; + + if (!ownerToken || bearer !== ownerToken) return undefined; + + const record = body && typeof body === "object" ? (body as Record) : {}; + const userId = typeof record.userId === "string" ? record.userId.trim() : ""; + return userId ? userId.slice(0, 128) : undefined; +} + +export function ownerSecurityLog(event: string, details: Record) { + const safeDetails = Object.fromEntries( + Object.entries(details).filter(([, value]) => value !== undefined), + ); + + console.info( + JSON.stringify({ + service: "mindreply", + event, + timestamp: new Date().toISOString(), + ...safeDetails, + }), + ); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/agents/page.tsx b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/agents/page.tsx new file mode 100644 index 0000000..9ef1727 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/agents/page.tsx @@ -0,0 +1,5 @@ +import { redirect } from "next/navigation"; + +export default function AgentsRedirectPage() { + redirect("/agent"); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agent/orchestrate/route.ts b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agent/orchestrate/route.ts new file mode 100644 index 0000000..39fb3b6 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agent/orchestrate/route.ts @@ -0,0 +1,15 @@ +import { NextRequest, NextResponse } from "next/server"; +import { orchestrateGoal } from "@/lib/moa"; + +export async function POST(req: NextRequest) { + try { + const { goal } = await req.json(); + if (!goal || !String(goal).trim()) { + return NextResponse.json({ error: "goal is required" }, { status: 400 }); + } + + return NextResponse.json(orchestrateGoal({ goal: String(goal) })); + } catch { + return NextResponse.json({ error: "Internal server error" }, { status: 500 }); + } +} diff --git a/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agents/route.ts b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agents/route.ts new file mode 100644 index 0000000..d5ac01c --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/app/api/agents/route.ts @@ -0,0 +1,11 @@ +import { NextResponse } from "next/server"; +import { getAgentBlueprint, orchestrateGoal } from "@/lib/moa"; + +export async function GET() { + return NextResponse.json({ + ...getAgentBlueprint(), + orchestration: orchestrateGoal({ + goal: "Stabilize and expand MindReply through the full MOA-controlled specialist layer.", + }), + }); +} diff --git a/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/components/MOAConsole.tsx b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/components/MOAConsole.tsx new file mode 100644 index 0000000..6f0c185 --- /dev/null +++ b/archive/branch-cleanup-2026-06-09/codex_mindreply-moa-controller/components/MOAConsole.tsx @@ -0,0 +1,209 @@ +"use client"; + +import { useMemo, useState } from "react"; +import { AlertTriangle, Bot, CheckCircle2, Copy, Loader2, Network, Play, ShieldCheck } from "lucide-react"; +import type { OrchestratedGoal } from "@/lib/moa"; + +type MOAConsoleProps = { + initialResult: OrchestratedGoal; +}; + +const DEFAULT_GOAL = + "Expand MindReply with secure AI orchestration, visible platform functionality, automation, integrations, and growth support."; + +function ResponseBlock({ children }: { children: string }) { + return ( +
+ {children} +
+ ); +} + +export default function MOAConsole({ initialResult }: MOAConsoleProps) { + const [goal, setGoal] = useState(initialResult.userGoal || DEFAULT_GOAL); + const [result, setResult] = useState(initialResult); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(""); + const [copied, setCopied] = useState(false); + + const routingStats = useMemo(() => { + const primary = result.taskRoutingLayer.filter((agent) => agent.priority === "primary").length; + const support = result.taskRoutingLayer.filter((agent) => agent.priority === "support").length; + const observer = result.taskRoutingLayer.filter((agent) => agent.priority === "observer").length; + + return { primary, support, observer }; + }, [result]); + + async function runOrchestration() { + const trimmed = goal.trim(); + if (!trimmed) { + setError("Enter a goal before running the orchestrator."); + return; + } + + setLoading(true); + setError(""); + + try { + const response = await fetch("/api/agent/orchestrate", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ goal: trimmed }), + }); + const payload = await response.json(); + + if (!response.ok) { + throw new Error(payload.error || "Unable to run orchestration."); + } + + setResult(payload); + } catch (err) { + setError(err instanceof Error ? err.message : "Unable to run orchestration."); + } finally { + setLoading(false); + } + } + + async function copyResult() { + const text = [ + result.finalCombinedResult.summary, + "", + "Next actions:", + ...result.finalCombinedResult.nextActions.map((action) => `- ${action}`), + ].join("\n"); + + await navigator.clipboard.writeText(text); + setCopied(true); + window.setTimeout(() => setCopied(false), 1500); + } + + return ( +
+
+
+
+ +
+
+

MOA Console

+

User goal intake and live task routing

+
+
+ + +