Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9b5d1e6
WIP: sharp-raven-604
briansrls Apr 30, 2026
e2f29e6
WIP: sharp-raven-604
briansrls Apr 30, 2026
06c1b5d
WIP: sharp-raven-604
briansrls Apr 30, 2026
589dc18
WIP: sharp-raven-604
briansrls Apr 30, 2026
0d927a1
merge main into session/sharp-raven-604
briansrls Apr 30, 2026
05d0de4
WIP: sharp-raven-604
briansrls Apr 30, 2026
2093dbb
WIP: sharp-raven-604
briansrls Apr 30, 2026
e459b85
regen bootstrap after std.effects import path fix
briansrls Apr 30, 2026
3df10af
merge main
briansrls Apr 30, 2026
3d994a8
WIP: sharp-raven-604
briansrls Apr 30, 2026
4a94f8d
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
5910cab
chore: apply cargo fmt
briansrls Apr 30, 2026
3893e36
merge main; resolve manifest conflict (keep services row)
briansrls Apr 30, 2026
b3e513c
WIP: sharp-raven-604
briansrls Apr 30, 2026
b0d1ffb
regen bootstrap + refresh parse manifest after merge
briansrls Apr 30, 2026
c1f8ffa
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
27287a4
WIP: sharp-raven-604
briansrls Apr 30, 2026
271f5c3
merge main; resolve bootstrap+manifest conflicts
briansrls Apr 30, 2026
ac85e45
WIP: sharp-raven-604
briansrls Apr 30, 2026
d39c9d4
WIP: sharp-raven-604
briansrls Apr 30, 2026
33fb48e
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
9169155
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
090b8b6
PR-α: wrap Operation.callable in CallableRef (typed wrapper, mirrors …
briansrls Apr 30, 2026
b4ba9f9
chore: apply cargo fmt
briansrls Apr 30, 2026
66c6b1c
doc: align test comments with CallableRef wrapper (cosmetic)
briansrls Apr 30, 2026
921d05a
merge main; take theirs on bootstrap (re-regen follows)
briansrls Apr 30, 2026
7cac46e
regen bootstrap after merge main
briansrls Apr 30, 2026
5516db5
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
a5003a6
T-Substrate-AnthropicSchemaMirror: v3 typed mirror for Anthropic Mess…
briansrls Apr 30, 2026
053679e
WIP: sharp-raven-604
briansrls Apr 30, 2026
7519fa2
chore: apply cargo fmt
briansrls Apr 30, 2026
bc7bc2e
anthropic_schema lockstep: couple expected labels to v2 source + opti…
briansrls Apr 30, 2026
63e845a
anthropic_schema lockstep: bidirectional set equality + structural op…
briansrls Apr 30, 2026
3c8b660
chore: apply cargo fmt
briansrls Apr 30, 2026
faac2b6
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
1468cba
fix clippy: use char array in split (manual char comparison lint)
briansrls Apr 30, 2026
92e1965
WIP: sharp-raven-604
briansrls Apr 30, 2026
2eaa1b1
anthropic_schema lockstep: per-variant payload field+optionality cove…
briansrls Apr 30, 2026
1e08a24
chore: apply cargo fmt
briansrls Apr 30, 2026
3c6c0e7
WIP: sharp-raven-604
briansrls Apr 30, 2026
c47cede
chore: apply cargo fmt
briansrls Apr 30, 2026
ee78939
WIP: sharp-raven-604
briansrls Apr 30, 2026
b41143f
anthropic_schema lockstep: type-expression equality (records + varian…
briansrls Apr 30, 2026
365e57f
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
dff070b
anthropic_schema lockstep: also reject Arrow declarations (fn leak gu…
briansrls Apr 30, 2026
6613e08
chore: apply cargo fmt
briansrls Apr 30, 2026
c22c800
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
1219c5d
T-Substrate-AnthropicMessagesCallable: fn anthropic_messages declaration
briansrls Apr 30, 2026
bc1b027
chore: apply cargo fmt
briansrls Apr 30, 2026
88feef8
chore: restore comment/test adjacency in SG-0 census (cosmetic)
briansrls Apr 30, 2026
c74a9de
anthropic_messages: pin Unparsed body + correct file header prose
briansrls Apr 30, 2026
00387e4
regen bootstrap: re-sync byte spans after anthropic_messages.dag head…
briansrls Apr 30, 2026
a69ed2d
Merge remote-tracking branch 'origin/main' into session/sharp-raven-604
briansrls Apr 30, 2026
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
2,998 changes: 1,501 additions & 1,497 deletions src/v3/compiler/src/bootstrap_generated.rs

Large diffs are not rendered by default.

2,832 changes: 1,418 additions & 1,414 deletions src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/v3/compiler/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#[path = "integration/common/mod.rs"]
mod common;

#[path = "integration/anthropic_messages_callable_test.rs"]
mod anthropic_messages_callable_test;
#[path = "integration/anthropic_schema_lockstep_test.rs"]
mod anthropic_schema_lockstep_test;
#[path = "integration/bridge_lower_helpers_patch_zero_residual_test.rs"]
Expand Down
221 changes: 221 additions & 0 deletions src/v3/compiler/tests/integration/anthropic_messages_callable_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//! **Layer:** integration
//!
//! T-Substrate-AnthropicMessagesCallable shape ratchet.
//!
//! Pins the `fn anthropic_messages` declaration in
//! `src/v3/std/anthropic_messages.dag` so PR-β can rebase against a
//! stable callable target via `CallableRef.decl`. Asserts:
//!
//! - The declaration resolves in the full bootstrap and is `Arrow`-shaped.
//! - Parameter labels and types match the v3 mirror in
//! `v3.std.anthropic_schema` plus kernel `Secret` / `String` / `Int` /
//! `Float?` / `String?` for the primitives the v2 source carries.
//! - Output type is `AnthropicMessages200Body` (the 200 response slot,
//! per the v2 `response { 200 => … }` row).
//! - The declaration is acceptable as a `CallableRef` target, i.e.
//! `Operation.callable: CallableRef` with `decl` set to
//! `anthropic_messages`'s id resolves structurally (the field type
//! reach matches the substrate-level `DeclarationRef` admits-anything
//! policy that PR-β fixture load fail-closes against).
//! - No `Operation` / `data anthropic_operations` row leaks here; that
//! stays Grounding-owned in PR-β.

use v3_compiler::dag::{ArrowBody, Dag, DeclarationId, TypeConnective};
use v3_compiler::generated_full_bootstrap_dag;

fn arrow_inputs_output(dag: &Dag, name: &str) -> (Vec<DeclarationId>, DeclarationId) {
let decl = dag
.declaration_by_name(name)
.unwrap_or_else(|| panic!("`{name}` missing from full bootstrap"));
match &decl.connective {
TypeConnective::Arrow { inputs, output, .. } => (inputs.clone(), *output),
other => panic!("`{name}` is not an Arrow: {other:?}"),
}
}

/// Reuse the same canonicalization rule as the schema-mirror lockstep:
/// named declarations canonicalize as their surface name; anonymous
/// `Cardinality(AtMostOne, T)` and `Instantiation { template, args }`
/// unfold.
fn canonical_ty(dag: &Dag, ty: DeclarationId) -> String {
let decl = dag.declaration(ty);
if let Some(name) = decl.name.as_deref() {
return name.to_string();
}
match &decl.connective {
TypeConnective::Cardinality(p) => format!("{}?", canonical_ty(dag, p.element())),
TypeConnective::Instantiation {
template,
arguments,
} => {
let template_name = dag
.declaration(*template)
.name
.clone()
.unwrap_or_else(|| canonical_ty(dag, *template));
if arguments.is_empty() {
template_name
} else {
let args: Vec<String> = arguments
.iter()
.map(|a| canonical_ty(dag, a.value))
.collect();
format!("{}<{}>", template_name, args.join(", "))
}
}
_ => "<anon>".to_string(),
}
}

#[test]
fn anthropic_messages_is_arrow_shaped() {
let dag = generated_full_bootstrap_dag();
let decl = dag
.declaration_by_name("anthropic_messages")
.expect("`anthropic_messages` missing from full bootstrap");
assert!(
matches!(decl.connective, TypeConnective::Arrow { .. }),
"`anthropic_messages` must be `Arrow`-shaped so `CallableRef.decl` \
can target an actual callable signature, not a `data` row or a \
type alias. Got: {:?}",
decl.connective
);
}

#[test]
fn anthropic_messages_parameter_types_match_v2_source_via_v3_mirror() {
// Expected canonical parameter types in declaration order. These
// mirror `dsl/extdeps/llm/anthropic.dag:182-187` modulo the two
// documented honesty-preserving simplifications:
// - `max_tokens: Int` (v2 `Int = 4096`; v3 has no parameter
// defaults — the default is a caller-side fold, not a v3
// callable contract change).
// - return is the 200 body only (`AnthropicMessages200Body`);
// error responses are PR-β's response/wire lockstep concern.
let dag = generated_full_bootstrap_dag();
let (inputs, _output) = arrow_inputs_output(&dag, "anthropic_messages");
let actual: Vec<String> = inputs.iter().map(|id| canonical_ty(&dag, *id)).collect();
let expected: Vec<&str> = vec![
"Secret",
"String",
"List<AnthropicChatMessage>",
"Int",
"Float?",
"String?",
];
assert_eq!(
actual,
expected.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
"anthropic_messages parameter types diverged from the v2 \
operation Messages signature."
);
}

#[test]
fn anthropic_messages_returns_anthropic_messages_200_body() {
let dag = generated_full_bootstrap_dag();
let (_inputs, output) = arrow_inputs_output(&dag, "anthropic_messages");
let output_canonical = canonical_ty(&dag, output);
assert_eq!(
output_canonical, "AnthropicMessages200Body",
"anthropic_messages must return `AnthropicMessages200Body` \
(the v2 `response 200 =>` slot from \
`dsl/extdeps/llm/anthropic.dag`). Error-response carriers are \
deferred to PR-β's response/wire lockstep lane."
);
}

#[test]
fn anthropic_messages_is_acceptable_callable_ref_target() {
// `CallableRef { decl: DeclarationRef }` — `DeclarationRef` admits
// any declaration at the substrate level (the same #1175 residual
// `MethodRef` carries). The PR-β fixture-load boundary check that
// every `Operation.callable.decl` resolves to an `Arrow`-shaped
// declaration (the actual callable contract) is what this test
// pre-validates: `anthropic_messages` IS an Arrow with a non-empty
// input list and a typed output, which is the property PR-β's
// fail-closed boundary will verify.
let dag = generated_full_bootstrap_dag();
let decl = dag
.declaration_by_name("anthropic_messages")
.expect("`anthropic_messages` missing from full bootstrap");
let (inputs, output) = match &decl.connective {
TypeConnective::Arrow { inputs, output, .. } => (inputs, *output),
other => panic!("`anthropic_messages` is not an Arrow: {other:?}"),
};
assert!(
!inputs.is_empty(),
"callable target for `Operation.callable.decl` must carry the \
operation's input list — anthropic_messages with empty inputs \
is structurally unfit."
);
let output_decl = dag.declaration(output);
assert!(
output_decl.name.is_some(),
"callable output should resolve to a named declaration, so PR-β \
lockstep against the response/wire lane has a real type to \
project. Got anonymous output: {:?}",
output_decl.connective
);
}

#[test]
fn anthropic_messages_body_is_unparsed() {
// The `host anthropic_messages` body lowers as
// `ArrowBody::Unparsed(span)` in the bootstrap, not as
// `ExternalRealization` / `UserDefined` / `NoBody` / `Pending`.
// The pipeline-stage `host parse` / `host lower` patch
// (`bootstrap.rs:256`) is pipeline-specific; service-operation
// callables don't have an equivalent and don't get one in this
// PR (per #1130 dispatch — no producerless realization carrier).
// Pinning the actual body class makes the substrate fact match the
// file header's prose; a silent rewrite in either direction would
// fail closed here.
let dag = generated_full_bootstrap_dag();
let decl = dag
.declaration_by_name("anthropic_messages")
.expect("`anthropic_messages` missing from full bootstrap");
let body = match &decl.connective {
TypeConnective::Arrow { body, .. } => body,
other => panic!("`anthropic_messages` is not an Arrow: {other:?}"),
};
assert!(
matches!(body, ArrowBody::Unparsed(_)),
"`anthropic_messages` body must be `ArrowBody::Unparsed(...)` in \
this slice (the honest substrate state for `host anthropic_messages` \
without a service-operation realization patch). Got: {body:?}. \
If this rewrites to `ExternalRealization`, that means a producerless \
realization carrier landed — re-validate against the #1130 dispatch \
before relaxing this ratchet."
);
}

#[test]
fn anthropic_messages_dag_authors_no_operation_rows() {
// The `Operation` row that closes the callable-to-source-identity
// edge (`callable: { decl: anthropic_messages }, inputs: …,
// endpoint: { method: POST, path: parse_path_template("/v1/messages"), … }`)
// is Grounding-owned PR-β work in a sibling
// `src/v3/std/anthropic_operations.dag`. Reject any `data` row
// landing in `anthropic_messages.dag` (which would mean a
// producerless `Operation` row or other parallel-surface scaffold
// leaked here).
let dag = generated_full_bootstrap_dag();
let leaks: Vec<String> = dag
.declarations()
.iter()
.filter(|d| d.span.file == "src/v3/std/anthropic_messages.dag")
.filter(|d| d.value_body.is_some())
.map(|d| {
d.name
.clone()
.unwrap_or_else(|| format!("DeclarationId({:?})", d.id))
})
.collect();
assert!(
leaks.is_empty(),
"anthropic_messages.dag is callable-decl authority only; no \
`data` rows allowed. PR-β authors operation rows in a sibling \
file. Found: {leaks:?}."
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ src/v3/spec/python.dag 89 582347 2fe9185bf19030a5
src/v3/spec/rust.dag 147 1229942 cf14d578f8e6e598
src/v3/spec/v3_l1.dag 8 2246 57294d687b4753f4
src/v3/std/algebra.dag 42 303630 8be5b86cc9520bc3
src/v3/std/anthropic_messages.dag 5 6056 25140dcf6faa8e6b
src/v3/std/anthropic_schema.dag 8 20682 cdd44a074743988b
src/v3/std/clean_emission.dag 15 23867 e7bc1e6145f4781e
src/v3/std/computation.dag 18 36754 8023f388c3fb0918
Expand Down
3 changes: 2 additions & 1 deletion src/v3/compiler/tests/integration/sg0_census_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ const EXPECTED_HAND_AUTHORED_TEST: &[&str] = &[
"src/v3/compiler/tests/boundary/m2_emit_multi_field_struct_variant_test.rs",
"src/v3/compiler/tests/determinism_test.rs",
"src/v3/compiler/tests/integration.rs",
"src/v3/compiler/tests/integration/anthropic_messages_callable_test.rs",
"src/v3/compiler/tests/integration/anthropic_schema_lockstep_test.rs",
// PB Tier-2 lower-helper exact-string patch class (#1014): zero-residual receipt +
// source ratchet; see `bridge_lower_helpers_patch_zero_residual_test.rs` module docs.
"src/v3/compiler/tests/integration/anthropic_schema_lockstep_test.rs",
"src/v3/compiler/tests/integration/bridge_lower_helpers_patch_zero_residual_test.rs",
// R2 PB canonical-lens bridge ratchet (PR #1183 — disposition for
// `bridge_canonical_lens_name_dispatch_retired`). Pins the remaining
Expand Down
92 changes: 92 additions & 0 deletions src/v3/std/anthropic_messages.dag
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module v3.std.anthropic_messages

import std.types { Secret }
import std.list { List }
import v3.std.anthropic_schema {
AnthropicChatMessage,
AnthropicMessages200Body
}

// T-Substrate-AnthropicMessagesCallable — service-operation callable
// declaration precursor for the Anthropic Messages REST operation. The
// real top-level callable that PR-β's `anthropic_operations: List<Operation>`
// row will reference via `Operation.callable.decl`, satisfying the
// `CallableRef` typed-edge requirement (#1246, #1261).
//
// Authority source for the signature is `dsl/extdeps/llm/anthropic.dag`'s
// `service llm.Anthropic { operation Messages { … } }` block at lines
// 180-203. The v3 mirror types in `v3.std.anthropic_schema` (#1261) carry
// the input/output structural fidelity that lets this callable land
// honestly — without the schema mirror, the only options were primitive-
// only signatures (forbidden as fake-by-omission) or wholesale v2 service
// parser ingestion (forbidden as out-of-scope). Both stops are documented
// in #1130's STOP+PING chain that produced #1261.
//
// **Signature shape vs. v2 source.** Two intentional simplifications
// preserve honesty at the v3 layer rather than introducing fake structure:
//
// 1. `max_tokens: Int` here vs `max_tokens: Int = 4096` in v2.
// v3's function-decl surface does not carry parameter defaults; the
// v2 default is a caller-side convenience that PR-β fixture rows
// surface (or that downstream consumers fold in). The v3 callable
// requires `max_tokens` explicitly, which is structurally stricter
// than the v2 default but does not invent a fake type — `Int` is
// the right type, only the optionality story differs.
// 2. The 4xx/5xx response carriers (`AnthropicErrorShape`) are not on
// the typed return; the callable returns the 200 body
// (`AnthropicMessages200Body`) per v2's `response { 200 => … }`
// slot. Error-response handling lives with the operation-row
// response/wire lockstep lane (PR-β scope, sibling to the row authoring
// Grounding owns).
//
// **Body — actual state and bound.** `host anthropic_messages` lowers
// to `ArrowBody::Unparsed(span)` in the bootstrap, NOT to
// `ArrowBody::ExternalRealization`. The pipeline-stage pattern in
// `src/v3/compiler/pipeline.dag` (`host parse` / `host lower` / etc.)
// gets its body rewritten to `ExternalRealization(realization_id)` by
// a hard-coded post-processing loop in
// `src/v3/compiler/src/bootstrap.rs:256` keyed by stage name; that
// patch is pipeline-specific and does not fire here. Without an
// equivalent service-operation realization patch (which would require
// authoring a `CompilerHostRealization`-style data row whose only job
// is to satisfy a binding-carrier slot — exactly the producerless
// parallel surface the dispatch explicitly rejects), the body remains
// `Unparsed`.
//
// `Unparsed` is the honest temporary state for this callable: v3 can
// type-check the `Arrow` (parameters + output) but does not resolve a
// realization. PR-β consumers (`Operation.callable.decl`) read the
// signature only — the body is not on the consumer surface. The
// shape ratchet at
// `src/v3/compiler/tests/integration/anthropic_messages_callable_test.rs::anthropic_messages_body_is_unparsed`
// pins this fact so a silent rewrite to `ExternalRealization` /
// `UserDefined` / `NoBody` fails closed.
//
// **Bound on the unparsed-body state.** The dissolution trigger below
// (v3 service-DSL parse/load surface) closes both this body class
// and the schema mirror it depends on. Until then, the body stays
// `Unparsed` and the ratchet enforces it.
//
// **Out of scope.** The `Operation` row that closes the
// callable-to-source-identity edge (`callable: { decl: anthropic_messages },
// inputs: …, endpoint: { method: POST, path: parse_path_template("/v1/messages"),
// … }`) is Grounding-owned PR-β work in a sibling
// `src/v3/std/anthropic_operations.dag` file. Grounding can rebase
// #1252 against this PR's `anthropic_messages` decl id directly via
// `CallableRef.decl`.
//
// **Dissolution.** Same trigger as `anthropic_schema.dag`: when v3
// grows a service-DSL parse/load surface that ingests
// `dsl/extdeps/llm/*.dag` with full structural fidelity, the v2
// source becomes the only authority and this callable
// declaration retires alongside the schema mirror it references.
fn anthropic_messages(
api_key: Secret,
model: String,
messages: List<AnthropicChatMessage>,
max_tokens: Int,
temperature: Float?,
system: String?
) -> AnthropicMessages200Body {
host anthropic_messages
}
Loading