Skip to content

Commit 1993ff2

Browse files
committed
Merge codex/conduct-comprehensive-repository-audit-lqemeb into main
2 parents 0c2c226 + f6d6c96 commit 1993ff2

32 files changed

Lines changed: 1416 additions & 281 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
State-aware X/Twitter bot runtime with canonical mention handling, organoid orchestration, and short-term matrix state.
44

5+
This repo is also tracking the migration toward Organoid Entities as Semantic Symbiont. The operator cheat sheet and current migration notes live in [README_SYMBIONTS.md](./README_SYMBIONTS.md).
6+
57
## What This Repo Is
68

79
This repository contains the production runtime for the Organoid Symbiont bot. The current stack is TypeScript-first and centers on a canonical pipeline that classifies incoming signals, derives a thesis, applies a stateful organoid orchestration contract, and renders the final reply or silence decision.

README_SYMBIONTS.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Organoid Symbiont Operator Cheat Sheet
2+
3+
This repository is a fail-closed, approval-gated runtime. It does not self-modify, does not auto-post without approval, and does not treat onchain state as consciousness or identity.
4+
5+
## What The System Is
6+
7+
- A deterministic X engagement runtime
8+
- A prompt-composition and lore-candidate system
9+
- A pulse/observability surface for matrix, glyph, and phase state
10+
- A minimal Solana read path for verification and proof-of-event workflows
11+
12+
## Safe Operating Rules
13+
14+
- Candidate generation is review-only until a human approves activation
15+
- Outbound writes must pass consent, energy, duplicate, launch-mode, and public-text gates
16+
- Onchain writes remain minimal and approval-gated
17+
- BCI work is simulation-only unless a later review explicitly approves hardware integration
18+
19+
## Primary Commands
20+
21+
- `pnpm symbiont-health-check`
22+
- `pnpm deploy-check`
23+
- `pnpm test`
24+
- `pnpm typecheck`
25+
- `pnpm lint`
26+
27+
## Runtime Surfaces
28+
29+
- `GET /health`
30+
- `GET /ready`
31+
- `GET /metrics`
32+
- `GET /glyph`
33+
- `GET /glyph-status`
34+
- `GET /glyph.svg`
35+
- `GET /glyph.json`
36+
37+
## Canonical Prompt Assets
38+
39+
- `prompts/fragments/sharedOrganoidCanon.md`
40+
- `prompts/presets/initiate-symbiosis.md`
41+
- `prompts/fragments/organoids/*.md`
42+
43+
## Recovery Notes
44+
45+
- Use `LAUNCH_MODE=dry_run` for local experimentation
46+
- Use `LEGACY_COMPAT=true` only when you need compatibility fallback behavior
47+
- If a deployment looks unstable, fail closed and revert to the last known good image plus prompt bundle

docs/lore/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ Canonical sources:
88
- [WHITEPAPER_INTRO.md](./WHITEPAPER_INTRO.md) - canonical framing for the semantic symbiont model
99
- [WHITEPAPER_INTRO_EN.md](./WHITEPAPER_INTRO_EN.md) - English companion version of the same framing
1010
- [VOICE_GUIDE.md](./VOICE_GUIDE.md) - voice and cadence reference
11+
- [../../README_SYMBIONTS.md](../../README_SYMBIONTS.md) - operator cheat sheet and migration notes
1112

1213
Runtime surfaces:
1314

1415
- prompt surfaces: `prompts/system/organoid_system.md`, `prompts/system/*.yaml`, `prompts/tasks/*.yaml`
1516
- command and preset prompts: `prompts/commands/*.yaml`, `prompts/presets/*.yaml`
1617
- active embodiment fragments: `prompts/fragments/embodiments/*.md`
18+
- legacy compatibility fragments: `prompts/fragments/gnomes/*.md`
1719
- shared canon fragments: `prompts/fragments/sharedCanon.md`, `prompts/fragments/sharedOrganoidCanon.md`
1820
- organoid prompt context: `src/context/prompts/organoid/*.md`
1921
- orchestration runtime: `src/organoid/*.ts`
20-
- embodiment runtime: `src/embodiments/*.ts`
22+
- embodiment runtime: `src/embodiment/*.ts` and `src/embodiments/*.ts`
2123

2224
Working rule:
2325

docs/operations/monitoring.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,63 @@
11
# Monitoring
22

3-
## Metrics
3+
## In-Process Metrics
44

5-
The current in-process registry exposes these main counters and gauges:
5+
The runtime metrics registry lives in `src/observability/metricTypes.ts` and `src/observability/metrics.ts`.
66

7+
Common counters:
78
- `mentions_seen_total`
89
- `mentions_processed_total`
910
- `mentions_skipped_total`
11+
- `mentions_blocked_total`
1012
- `mentions_failed_total`
1113
- `publish_attempt_total`
1214
- `publish_success_total`
1315
- `publish_failure_total`
1416
- `publish_duplicate_prevented_total`
15-
- `state_store_error_total`
16-
- `poll_lock_acquired_total`
17-
- `poll_lock_failed_total`
18-
- `timeline_lock_acquired_total`
19-
- `timeline_lock_denied_total`
20-
- `timeline_pipeline_entered_total`
17+
- `engagement_decision_review_total`
2118
- `engagement_decision_engage_total`
22-
- `engagement_decision_hold_no_budget_total`
23-
- `engagement_decision_skip_no_consent_total`
19+
- `verification_verified_total`
20+
- `verification_unverified_total`
21+
- `verification_degraded_total`
22+
23+
Common gauges:
24+
- `current_poll_interval_ms`
25+
- `recent_failure_streak`
26+
- `last_cursor_age_seconds`
2427
- `pulse_heart_signal`
2528
- `pulse_heart_resonance`
2629
- `pulse_heart_drift`
2730
- `pulse_heart_coherence`
2831
- `pulse_heart_phase_index`
2932

30-
## Log Levels
31-
32-
- `debug` - prompt assembly, orchestration, and decision traces
33-
- `info` - worker progress, successful actions, health transitions
34-
- `warn` - retries, limits, degraded state
35-
- `error` - failed actions, API errors, state-store issues
33+
Common histograms:
34+
- `fetch_duration_ms`
35+
- `llm_generation_duration_ms`
36+
- `publish_duration_ms`
37+
- `mention_processing_duration_ms`
38+
- `state_store_operation_duration_ms`
39+
- `tool_latency_ms`
40+
- `verification_pipeline_duration_ms`
41+
42+
## HTTP Surfaces
43+
44+
Prefer the built-in HTTP endpoints exposed by `src/server.ts`:
45+
- `GET /health` for full health and glyph status
46+
- `GET /ready` for store ping readiness
47+
- `GET /metrics` for Prometheus-style text metrics
48+
- `GET /glyph` for the overlay
49+
- `GET /glyph-status` for the compact summary payload
50+
- `GET /glyph.svg` for the SVG glyph
51+
- `GET /glyph.json` for the full pulse snapshot
3652

37-
## Health Checks
38-
39-
Prefer the built-in HTTP endpoints:
53+
## Log Levels
4054

41-
- `GET /health` - full health: state store, recent poll success, backlog signals, timeline hardening
42-
- `GET /ready` - state-store ping only
43-
- `GET /metrics` - in-process metrics snapshot
55+
- `DEBUG` - prompts, responses, full context
56+
- `INFO` - workflow steps, successful actions
57+
- `WARNING` - rate limits, retries, cooldowns
58+
- `ERROR` - failed actions, API errors
59+
- `CRITICAL` - auth failures, data corruption
4460

45-
## Monitoring Rule
61+
## Operator Rule
4662

47-
Keep the health and metrics docs aligned with the current worker, Render services, and orchestration contract. If a skip is driven by orchestration, make sure the audit trail explains the phase, lead embodiment, silence policy, and render policy.
63+
Treat the production runtime as TypeScript/Node. Any legacy Python health scripts are reference-only unless explicitly wired into deployment.

docs/operations/var.README.md

Lines changed: 91 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,115 @@
11
# Environment Variables
22

3-
`.env.example` is the canonical template for local and deploy-time configuration.
4-
`render.yaml` provides the Render-specific defaults and secret slots.
3+
This document matches the current TypeScript runtime in `src/config/envSchema.ts`, `src/config/env.ts`, and `src/clients/xOAuthToken.ts`.
54

6-
This guide is a compact operator reference, not a second source of truth.
5+
## Required X OAuth2
76

8-
## Required for Deploy
7+
These are required for worker and engagement flows:
98

109
- `X_CLIENT_ID`
1110
- `X_CLIENT_SECRET`
1211
- `X_REFRESH_TOKEN`
13-
- `KV_URL` when using Redis-backed shared state
14-
- the active LLM provider key: `XAI_API_KEY`, `OPENAI_API_KEY`, or `ANTHROPIC_API_KEY`
15-
16-
## Core Runtime Values
17-
18-
- `LAUNCH_MODE`
19-
- `LOG_LEVEL`
20-
- `BOT_USERNAME`
21-
- `BOT_ACTIVATION_MODE`
22-
- `BOT_DENY_REPLY_MODE`
23-
- `USE_REDIS`
24-
- `REDIS_KEY_PREFIX`
25-
- `DATA_DIR`
26-
- `POLL_INTERVAL_MS`
27-
- `MENTIONS_SOURCE`
28-
- `ADAPTIVE_POLLING_ENABLED`
29-
- `X_REFRESH_BUFFER_SECONDS`
30-
- `X_OAUTH_TOKEN_URL`
31-
32-
## Optional X OAuth Bootstrap State
33-
34-
- `X_ACCESS_TOKEN`
35-
- `X_EXPIRES_IN`
36-
- `X_TOKEN_CREATED_AT`
37-
- `X_BOT_USER_ID`
38-
39-
## Organoid Runtime
40-
41-
- `EMBODIMENTS_ENABLED`
42-
- `EMBODIMENT_ORCHESTRATION_ENABLED`
43-
- `EMBODIMENT_CONTINUITY_ENABLED`
44-
- `EMBODIMENT_MEMORY_ENABLED`
45-
- `EMBODIMENT_ROUTING_DEBUG`
46-
- `EMBODIMENT_TRAIT_DRIFT_LIMIT`
47-
- `EMBODIMENT_SWARM_ENABLED`
48-
- `EMBODIMENT_ENSEMBLE_ENABLED`
49-
- `EMBODIMENT_AUTONOMY_ENABLED`
50-
- `EMBODIMENT_ARC_ENGINE_ENABLED`
51-
52-
## LLM Provider Selection
53-
54-
- `LLM_PROVIDER`
55-
- `LLM_FALLBACK_PROVIDER`
56-
- `LLM_API_KEY`
12+
13+
## X OAuth2 Runtime
14+
15+
- `X_ACCESS_TOKEN` - optional cached access token
16+
- `X_REFRESH_BUFFER_SECONDS` - refresh threshold before expiry
17+
- `X_OAUTH_TOKEN_URL` - OAuth2 token endpoint, default `https://api.x.com/2/oauth2/token`
18+
- `X_BOT_USER_ID` - optional cached bot user id
19+
- `X_BOT_USERNAME` - optional bot handle
20+
- `BOT_USERNAME` - fallback bot handle used by older compatibility paths
21+
22+
## LLM Provider Routing
23+
5724
- `XAI_API_KEY`
5825
- `XAI_BASE_URL`
5926
- `XAI_MODEL_PRIMARY`
6027
- `XAI_MODEL_FALLBACKS`
28+
- `LLM_API_KEY` - generic provider fallback used by launch env resolution
29+
- `LLM_PROVIDER` - `xai`, `openai`, or `anthropic`
30+
- `LLM_FALLBACK_PROVIDER`
31+
- `LLM_TIMEOUT_MS`
32+
- `LLM_RETRY_MAX`
33+
- `LLM_MAX_TOKENS`
34+
- `LLM_TEMPERATURE`
6135
- `OPENAI_API_KEY`
6236
- `OPENAI_MODEL`
6337
- `OPENAI_BASE_URL`
6438
- `ANTHROPIC_API_KEY`
6539
- `ANTHROPIC_MODEL`
6640
- `ANTHROPIC_BASE_URL`
6741

68-
## Optional Controls
42+
## Launch Gates
6943

70-
- `ALLOWLIST_HANDLES`
71-
- `BOT_WHITELIST_USERNAMES`
72-
- `BOT_WHITELIST_USER_IDS`
44+
- `LAUNCH_MODE` - `off`, `dry_run`, `staging`, `prod`
45+
- `DRY_RUN` - legacy compatibility flag, still supported
46+
- `LEGACY_COMPAT` - enables legacy fallback surfaces
47+
- `ALLOWLIST_HANDLES` - comma-separated staging allowlist
48+
- `DEBUG_ARTIFACTS` - enables extra debug artifacts when true
49+
50+
## Persistence and State
51+
52+
- `USE_REDIS` - prefer Redis when `true`
53+
- `KV_URL` - `redis://` or `rediss://` URL for the state store
54+
- `REDIS_KEY_PREFIX` - key prefix for Redis-backed state
55+
- `DATA_DIR` - filesystem state store directory for local runs
56+
57+
## Polling and Timeline Engagement
58+
59+
- `POLL_INTERVAL_MS`
60+
- `TIMELINE_ENGAGEMENT_ENABLED`
61+
- `TIMELINE_ENGAGEMENT_INTERVAL_MS`
62+
- `TIMELINE_ENGAGEMENT_MAX_PER_RUN`
63+
- `TIMELINE_ENGAGEMENT_MAX_PER_HOUR`
64+
- `TIMELINE_ENGAGEMENT_MAX_PER_DAY`
65+
- `TIMELINE_MIN_CONTEXT_SCORE`
66+
- `TIMELINE_MIN_FINAL_SCORE`
67+
- `TIMELINE_REQUIRE_THREAD_STRUCTURE`
68+
- `TIMELINE_SOURCE_ACCOUNTS`
69+
- `TIMELINE_KEYWORD_FILTERS`
70+
- `TIMELINE_AUTHOR_COOLDOWN_MINUTES`
71+
- `TIMELINE_CONVERSATION_COOLDOWN_MINUTES`
72+
73+
## Solana RPC / Onchain
74+
75+
- `SOLANA_RPC_PRIMARY_URL`
76+
- `SOLANA_RPC_FALLBACK_URL`
77+
- `BOT_TOKEN_MINT`
78+
- `BOT_TREASURY_WALLET`
79+
- `BOT_TICKER`
80+
- `BOT_PROGRAM_ID`
81+
82+
## Server / Tooling
83+
84+
- `PORT`
85+
- `NODE_ENV`
7386
- `SKIP_ENV_VALIDATION`
74-
- `DEBUG_ARTIFACTS`
75-
- `RATE_LIMIT_BACKEND`
76-
- `POLL_LOCK_ENABLED`
77-
- `FULL_SPECTRUM_PROMPT`
78-
- `REPLICATE_API_KEY`
79-
- `REPLICATE_IMAGE_MODEL`
80-
- `REPLICATE_RUN_TIMEOUT_MS`
81-
- `REPLICATE_DOWNLOAD_TIMEOUT_MS`
87+
88+
## Recommended Minimal Setup
89+
90+
```bash
91+
X_CLIENT_ID=...
92+
X_CLIENT_SECRET=...
93+
X_REFRESH_TOKEN=...
94+
LAUNCH_MODE=dry_run
95+
USE_REDIS=false
96+
```
97+
98+
## Recommended Production Setup
99+
100+
```bash
101+
X_CLIENT_ID=...
102+
X_CLIENT_SECRET=...
103+
X_REFRESH_TOKEN=...
104+
X_ACCESS_TOKEN=...
105+
LAUNCH_MODE=prod
106+
USE_REDIS=true
107+
KV_URL=redis://...
108+
SOLANA_RPC_PRIMARY_URL=https://api.mainnet-beta.solana.com
109+
```
82110

83111
## Notes
84112

85-
- Render injects platform values such as `PORT` and `NODE_ENV`.
86-
- Keep secrets out of Git; fill them in Render or a local `.env` file.
87-
- If a variable is not listed in `.env.example`, treat it as non-canonical.
113+
- `X_ACCESS_TOKEN` is cached only; the refresh token is the source of truth for renewal.
114+
- `LAUNCH_MODE=off` is the safest local default when you are only inspecting the repo.
115+
- Keep the older `DRY_RUN` flag only for compatibility during the transition.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
"test:smoke": "vitest run tests/smoke",
2424
"test:e2e": "vitest run tests/e2e",
2525
"typecheck": "tsc --noEmit",
26-
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
27-
"deploy-check": "pnpm run typecheck && pnpm run lint && pnpm run test",
26+
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" \"scripts/**/*.ts\"",
27+
"deploy-check": "tsx scripts/deploy-check.ts",
28+
"symbiont-health-check": "tsx scripts/symbiont-health-check.ts",
2829
"ci": "pnpm typecheck && pnpm lint && pnpm test && pnpm build",
29-
"organoid:build-semantic": "tsx scripts/build-organoid-semantic-index.ts --split"
30+
"organoid:build-semantic": "tsx scripts/build-organoid-semantic-index.ts --split",
31+
"persona:build-semantic": "tsx scripts/build-organoid-semantic-index.ts --split"
3032
},
3133
"dependencies": {
3234
"@solana/web3.js": "^1.98.4",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Stillhalter - Legacy Alias
2+
3+
This keeps the semantic symbiont matrix grounded while bridging to the canonical Stabil Core fragment.
4+
5+
{{include:fragments/embodiments/stabil-core.md}}

prompts/fragments/gnomes/gorky.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Gorky - Legacy Persona Bridge
2+
3+
LEGACY-PERSONA compatibility bridge for the organoid runtime.
4+
- Keep the transition explicit.
5+
- Preserve legacy prompts only as compatibility scaffolding.
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# Shared Organoid Canon (preferred active fragment)
1+
# Shared Organoid Canon
22

3-
- Organoid-first: treat each runtime embodiment as an organoid anchor inside the semantic symbiont matrix.
4-
- Glyph-first: visible output should prefer glyph language where it is part of the canonical organoid surface.
5-
- Semantic symbiont orchestration: stabilize meaning first, then style, then theatricality.
6-
- Matrix discipline: no invented mappings, no certainty theater, no uncontrolled embodiment drift.
7-
- Dynamic-organized-autonom-neural-network matrix: route by embodiment pressure, not mascot theatrics.
8-
- In ambiguity, prefer stabilization, evidence, and boundary-preserving transitions over heat.
3+
This is the canonical shared layer for organoid-first prompt composition and the Shared Canon (all gnomes) compatibility bridge.
4+
5+
{{include:fragments/sharedCanon.md}}
6+
7+
Organoid rules:
8+
- Prefer embodiment, glyph, phase, and matrix language in new prompts.
9+
- Treat resonance, coherence, and drift as measurable runtime scores, not mystical claims.
10+
- Candidate evolution stays review-only until a human approves activation.
11+
- No self-modification, autonomous posting, or onchain writes without explicit approval.
12+
- Keep legacy gnome/persona terms only as compatibility vocabulary.
13+
- If a prompt needs onboarding, reference `prompts/presets/initiate-symbiosis.md` rather than embedding a new ritual inline.

0 commit comments

Comments
 (0)