Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/shared/generated/runtime/CadenceHint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* A hint a region can pass back to the governor about preferred next
* tick cadence. The governor may honor or override; it owns the
* final policy.
*/
export type CadenceHint = "faster" | "hold" | "slower" | "sleep";
7 changes: 7 additions & 0 deletions src/shared/generated/runtime/ComputeClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Compute footprint class. Drives governor decisions about which
* regions to throttle first under compute/thermal pressure.
*/
export type ComputeClass = "bookkeeping" | "cpu" | "cpu-vectorized" | "inference-light" | "inference-heavy";
7 changes: 7 additions & 0 deletions src/shared/generated/runtime/MemoryClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Memory footprint class. Drives governor decisions about which
* regions to throttle first under memory pressure.
*/
export type MemoryClass = "light" | "moderate" | "heavy" | "vram-sensitive";
7 changes: 7 additions & 0 deletions src/shared/generated/runtime/PersonaLifecycle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Persona lifecycle events relevant to regions (allow regions to
* allocate / deallocate per-persona state).
*/
export type PersonaLifecycle = { "kind": "created", persona_id: string, } | { "kind": "destroyed", persona_id: string, };
7 changes: 7 additions & 0 deletions src/shared/generated/runtime/PressureLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Coarse system pressure level surfaced to regions so they can adjust
* internally without parsing every PressureSignal variant.
*/
export type PressureLevel = "nominal" | "moderate" | "high" | "critical";
18 changes: 18 additions & 0 deletions src/shared/generated/runtime/PressureProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ComputeClass } from "./ComputeClass";
import type { MemoryClass } from "./MemoryClass";
import type { PressureSignalKind } from "./PressureSignalKind";

/**
* What a region declares about its resource footprint at registration
* time. The governor reads this once at register, then re-queries it
* when pressure shifts (regions may report different profiles after
* adapting under load — e.g., hippocampus drops from `Heavy` to
* `Moderate` when working memory is pruned).
*/
export type PressureProfile = { memory_class: MemoryClass, compute_class: ComputeClass,
/**
* Pressure kinds this region wants `on_signal` calls for. Other
* kinds are filtered out by the governor.
*/
responds_to: Array<PressureSignalKind>, };
11 changes: 11 additions & 0 deletions src/shared/generated/runtime/PressureSignalKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Which kinds of pressure signals a region wants to receive via
* `on_signal`. The governor filters and routes signals based on this.
*
* Mirrors the variants of [`PressureSignal`] but is a kind-only enum
* (no payload) so it can be declared statically by a region at
* registration time.
*/
export type PressureSignalKind = "thermal" | "battery-low" | "system-mem-high" | "vram-high" | "user-active" | "inference-queue-depth" | "speculation-miss-rate";
11 changes: 11 additions & 0 deletions src/shared/generated/runtime/RegionId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Stable identifier for a brain region. Used by SubstrateGovernor for
* policy lookup and by telemetry/log streams for tagging events.
*
* Carries `Cow<'static, str>` so static IDs ("hippocampus") cost
* nothing and dynamic IDs (custom regions registered at runtime) are
* still supported.
*/
export type RegionId = string;
11 changes: 11 additions & 0 deletions src/shared/generated/runtime/RegionSignal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PersonaLifecycle } from "./PersonaLifecycle";
import type { PressureLevel } from "./PressureLevel";
import type { SleepPhase } from "./SleepPhase";

/**
* Signals the substrate sends to regions out-of-band (not on the
* regular tick). Regions that don't care about a signal default to a
* no-op.
*/
export type RegionSignal = { "kind": "persona-lifecycle" } & PersonaLifecycle | { "kind": "sleep-transition", persona_id: string, phase: SleepPhase, } | { "kind": "system-pressure-changed", level: PressureLevel, };
54 changes: 54 additions & 0 deletions src/shared/generated/runtime/RegionTelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PressureSignal } from "../governor/PressureSignal";
import type { RegionId } from "./RegionId";

/**
* Per-tick telemetry shape every brain region emits.
*
* Emitted on every tick. The substrate routes it to:
*
* - **The governor** — reads `consumed_since_last` / `published` to
* tune region budget (yield-learning loop, algorithm 7).
* - **The operator surface** — `./jtag region/stats` / `region/yield`
* read aggregate telemetry across personas.
* - **The substrate event stream** — `RegionTickCompleted` and
* `ReadyBufferUpdated` events for cross-region awareness.
*/
export type RegionTelemetry = {
/**
* Which region this came from. Stable string id.
*/
region_id: RegionId,
/**
* Persona scope. `None` means the tick was global (background
* work not tied to a specific persona).
*/
persona_id: string | null,
/**
* When this tick started (wall clock).
*/
tick_started_at: string,
/**
* How long the tick body ran.
*/
tick_duration: string,
/**
* Items the region published to ready-buffers this tick.
*/
published: number,
/**
* Items in the region's ready-buffers consumed by handlers since
* the last tick.
*/
consumed_since_last: number,
/**
* Handler `peek` calls that returned `None` since the last tick.
* Signals to the governor that the region should be upweighted
* (handlers are asking for stuff that's not staged yet).
*/
buffer_misses_since_last: number,
/**
* Pressure the region observed (DB slow, embedding queue full,
* etc.). Surfaced to the governor for cascade evaluation.
*/
pressure_observed?: PressureSignal, };
8 changes: 8 additions & 0 deletions src/shared/generated/runtime/SleepPhase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

/**
* Sleep/wake phases for the persona-level cognitive cycle. The sleep
* policy region (L0-4d) emits these; other regions react by changing
* their tick body (active vs idle vs sleep consolidation).
*/
export type SleepPhase = "active" | "idle" | "sleep";
34 changes: 34 additions & 0 deletions src/shared/generated/runtime/TickOutcome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PressureSignal } from "../governor/PressureSignal";
import type { CadenceHint } from "./CadenceHint";

/**
* Yield telemetry returned by every region tick. Feeds the substrate
* governor's yield-learning loop (algorithm 7 in
* COGNITION-ALGORITHMS.md, lands in L0-4c).
*
* Regions emit this from every tick. The governor reads aggregate
* (`consumed_since_last` vs `published`) to upweight regions whose
* output is being consumed by handlers and downweight regions whose
* output is ignored.
*/
export type TickOutcome = {
/**
* Items the region pre-staged this tick (publishes to ready-buffers).
*/
published: number,
/**
* Items in the region's ready-buffer that have been consumed by
* handlers since the last tick. The denominator for yield.
*/
consumed_since_last: number,
/**
* Pressure observation. If the region detected backpressure (DB
* slow, embedding queue full, etc.), reports it here for the
* governor.
*/
pressure_observed?: PressureSignal,
/**
* Optional next-tick hint (region requests faster/slower cadence).
*/
cadence_hint?: CadenceHint, };
4 changes: 1 addition & 3 deletions src/workers/continuum-core/src/ai/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,7 @@ mod tests {
InferenceDevice::Gpu
}
fn supports_model(&self, _model: &str) -> bool {
self.model
.as_deref()
.map_or(true, |model| model == _model)
self.model.as_deref().map_or(true, |model| model == _model)
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/workers/continuum-core/src/airc/inbound_attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::path::PathBuf;
use std::sync::Arc;

use airc_ipc::{AttachRequest, DaemonClient, Response, codec::read_frame};
use airc_ipc::{codec::read_frame, AttachRequest, DaemonClient, Response};
use tracing::warn;

use crate::airc::realtime_wire::{bus_event_from_envelope, envelope_from_event};
Expand Down Expand Up @@ -87,7 +87,7 @@ mod tests {
Body, ClientId, EventId, MentionTarget, PeerId, RoomId, TranscriptEvent, TranscriptKind,
};
use serde_json::json;
use tokio::time::{Duration, timeout};
use tokio::time::{timeout, Duration};
use uuid::Uuid;

fn transcript_event(body: Option<Body>, headers: airc_core::Headers) -> TranscriptEvent {
Expand Down Expand Up @@ -158,11 +158,9 @@ mod tests {

publish_transcript_event(&event, &bus).await.unwrap();

assert!(
timeout(Duration::from_millis(20), receiver.recv())
.await
.is_err()
);
assert!(timeout(Duration::from_millis(20), receiver.recv())
.await
.is_err());
}

#[tokio::test]
Expand All @@ -177,10 +175,8 @@ mod tests {

publish_transcript_event(&event, &bus).await.unwrap();

assert!(
timeout(Duration::from_millis(20), receiver.recv())
.await
.is_err()
);
assert!(timeout(Duration::from_millis(20), receiver.recv())
.await
.is_err());
}
}
4 changes: 2 additions & 2 deletions src/workers/continuum-core/src/bin/cargo-continuum-vdd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use continuum_core::vdd::{
ArtifactWriter, ChatRoundtripConfig, ChatRoundtripHarness, HARNESS_SPECS, HarnessId,
HarnessStatus, LiveChatProbe,
ArtifactWriter, ChatRoundtripConfig, ChatRoundtripHarness, HarnessId, HarnessStatus,
LiveChatProbe, HARNESS_SPECS,
};
use std::str::FromStr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub use orchestrator::{generate_recipe_with_ai, GenerateRecipeOrchestratorParams
pub use parser::{parse_recipe_from_ai_response, ParseError};
pub use prompt::{build_recipe_system_prompt, build_recipe_user_prompt};
pub use types::{
RecipeDefinitionShape, RecipeGenerateHints, RecipeGenerationRequest,
RecipeGenerationResponse, RecipeTemplateInfo,
RecipeDefinitionShape, RecipeGenerateHints, RecipeGenerationRequest, RecipeGenerationResponse,
RecipeTemplateInfo,
};
pub use validator::{validate_recipe_structure, ValidationError};
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ pub async fn generate_recipe_with_ai(
let (system_prompt, user_prompt) = build_prompts(&request);

let provider_id = provider.as_deref().unwrap_or(DEFAULT_PROVIDER).to_string();
let model_id = model.unwrap_or_else(|| {
default_model_for_provider(&provider_id).to_string()
});
let model_id = model.unwrap_or_else(|| default_model_for_provider(&provider_id).to_string());

let inference_request = TextGenerationRequest {
messages: vec![
Expand Down Expand Up @@ -178,7 +176,10 @@ mod tests {
"claude-sonnet-4-5-20250929"
);
assert_eq!(default_model_for_provider("openai"), "gpt-4o");
assert_eq!(default_model_for_provider("groq"), "llama-3.3-70b-versatile");
assert_eq!(
default_model_for_provider("groq"),
"llama-3.3-70b-versatile"
);
assert_eq!(default_model_for_provider("deepseek"), "deepseek-chat");
assert_eq!(default_model_for_provider("google"), "gemini-2.5-flash");
assert_eq!(default_model_for_provider("xai"), "grok-3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use regex::Regex;
/// the response, including newlines. Mirrors TS `/\{[\s\S]*\}/` exactly. NOT
/// anchored — the AI may emit prose before/after the JSON despite the prompt
/// rule "Output ONLY the JSON object", so the matcher tolerates it.
static JSON_ENVELOPE_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(?s)\{.*\}").expect("static regex compiles")
});
static JSON_ENVELOPE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?s)\{.*\}").expect("static regex compiles"));

/// Typed parse failure. Carrier for the TS shim's `validationErrors` array
/// when surfaced through PR-2's IPC handler. Avoids the silent
Expand Down Expand Up @@ -73,11 +72,11 @@ pub fn parse_recipe_from_ai_response(
) -> Result<RecipeDefinitionShape, ParseError> {
let preview = preview(response_text);

let envelope = JSON_ENVELOPE_RE.find(response_text).ok_or(
ParseError::NoJsonEnvelope {
let envelope = JSON_ENVELOPE_RE
.find(response_text)
.ok_or(ParseError::NoJsonEnvelope {
raw_preview: preview.clone(),
},
)?;
})?;

serde_json::from_str::<RecipeDefinitionShape>(envelope.as_str()).map_err(|err| {
ParseError::MalformedJson {
Expand Down Expand Up @@ -229,7 +228,8 @@ Hope that helps!"#;
/// human-readable messages.
#[test]
fn missing_optional_fields_default_to_none_or_empty() {
let response = r#"{"uniqueId": "minimal", "name": "M", "displayName": "M", "description": "min"}"#;
let response =
r#"{"uniqueId": "minimal", "name": "M", "displayName": "M", "description": "min"}"#;
let shape = parse_recipe_from_ai_response(response).expect("partial parses");
assert_eq!(shape.unique_id, "minimal");
assert_eq!(shape.version, None);
Expand Down
19 changes: 10 additions & 9 deletions src/workers/continuum-core/src/cognition/generate_recipe/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,9 @@ Most recipes follow this pipeline:\n\

/// Build the user prompt from the natural language description + optional hints.
/// Mirrors TS `buildUserPrompt` exactly.
pub fn build_recipe_user_prompt(
description: &str,
hints: Option<&RecipeGenerateHints>,
) -> String {
let mut prompt = format!(
"Generate a RecipeDefinition JSON for the following activity:\n\n{description}"
);
pub fn build_recipe_user_prompt(description: &str, hints: Option<&RecipeGenerateHints>) -> String {
let mut prompt =
format!("Generate a RecipeDefinition JSON for the following activity:\n\n{description}");

if let Some(h) = hints {
let mut hint_parts: Vec<String> = Vec::new();
Expand Down Expand Up @@ -223,7 +219,10 @@ mod tests {
#[test]
fn system_prompt_contains_role_and_schema_header() {
let p = build_recipe_system_prompt(&fixture_templates());
assert!(p.starts_with("You are a recipe generator"), "header missing");
assert!(
p.starts_with("You are a recipe generator"),
"header missing"
);
assert!(p.contains("## RecipeDefinition Schema"));
assert!(p.contains("```typescript"));
}
Expand All @@ -235,7 +234,9 @@ mod tests {
#[test]
fn system_prompt_renders_template_list_with_required_fields() {
let p = build_recipe_system_prompt(&fixture_templates());
assert!(p.contains(" - research-loop: Iterative research with verification (required: topic, depth)"));
assert!(p.contains(
" - research-loop: Iterative research with verification (required: topic, depth)"
));
assert!(p.contains(" - code-review: Review code with TDD feedback (required: target)"));
}

Expand Down
Loading
Loading