Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 7 additions & 1 deletion server/src/hephaestus/http/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,20 @@ class ContextEnvelope:

@property
def is_empty(self) -> bool:
"""§7A.3: "an empty or absent envelope is not an error"."""
"""§7A.3: "an empty or absent envelope is not an error".

``view`` names a reference once the operator adds it (issue #13).
Navigation tabs alone are still the blank canvas; a camera token
that the operator explicitly sent is not.
"""
return (
self.part is None
and self.artifact_ref is None
and self.selection_bundle_ref is None
and not self.hidden_labels
and self.section_plane is None
and self.focus is None
and self.view is None
)


Expand Down
16 changes: 12 additions & 4 deletions server/src/hephaestus/http/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,18 @@ def provider_specs_of(file: ProvidersFile) -> list[dict[str, Any]]:
"""The declared specs, normalized for display. **No credential material.**"""
rows: list[dict[str, Any]] = []
for spec in file.providers:
models = [
{"id": str(model.get("id", "")), "name": str(model.get("name", model.get("id", "")))}
for model in _dicts(spec.get("models"))
]
models: list[dict[str, Any]] = []
for model in _dicts(spec.get("models")):
entry: dict[str, Any] = {
"id": str(model.get("id", "")),
"name": str(model.get("name", model.get("id", ""))),
}
# Projected only when the spec declared it. Absence is the named
# "this model has no thinking levels" — the composer maps effort
# from this field and must not invent one.
if model.get("reasoning") is True:
entry["reasoning"] = True
models.append(entry)
row: dict[str, Any] = {
"id": str(spec.get("id", "")),
"kind": str(spec.get("kind", "")),
Expand Down
15 changes: 15 additions & 0 deletions server/tests/test_context_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ def test_the_blank_canvas_composes_nothing(app: Workspace) -> None:
assert body["sources"] == []


def test_an_explicit_view_is_composed_rather_than_collapsed(app: Workspace) -> None:
"""Issue #13: Add current view must change what the agent is told.

Tabs alone remain the blank canvas. A ``view`` the operator sent is a
reference: ``_say_viewport`` already knew the line; collapsing on
``is_empty`` made the composer's disclosure say the agent would hear
nothing.
"""
response = app.post("/context/preview", json={"context": {"view": "iso"}})
assert response.status_code == 200, response.text
body = cast("dict[str, Any]", response.json())
assert "camera view: iso" in body["block"]
assert body["truncated"] is False


def test_composition_is_deterministic_in_the_envelope_and_the_project(app: Workspace) -> None:
"""§7A.3: "deterministic in ``(references, project state)``".

Expand Down
32 changes: 32 additions & 0 deletions server/tests/test_http_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ def test_a_serve_with_no_providers_json_still_reads_and_writes_one(ws: Workspace
assert _config_path(ws).exists()


def test_get_providers_projects_model_ids_and_reasoning_without_house_names(
ws: Workspace,
) -> None:
"""The composer maps model + effort from this document (issue #13).

Identifiers are the spec's own ``models[].id``. ``reasoning`` is projected
only when the spec declared it — absence is the named "no thinking
levels", not a defaulted house effort scale.
"""
with_reasoning = {
**_FAKE_SPEC,
"models": [
{
"id": "heph-fake-model",
"name": "Heph Fake",
"contextWindow": 128000,
"maxTokens": 4096,
"reasoning": True,
}
],
}
written = _write_specs(ws, [with_reasoning])
assert written.status_code == 200, written.text
models = ws.get("/providers").json()["providers"][0]["models"]
assert models == [{"id": "heph-fake-model", "name": "Heph Fake", "reasoning": True}]

_write_specs(ws, [_FAKE_SPEC])
plain = ws.get("/providers").json()["providers"][0]["models"]
assert plain == [{"id": "heph-fake-model", "name": "Heph Fake"}]
assert "reasoning" not in plain[0]


def test_the_written_file_is_0600_created_private(ws: Workspace) -> None:
"""§23.2: ``write_private``, created private, never ``chmod``'ed after.

Expand Down
27 changes: 27 additions & 0 deletions web/e2e/composer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ test.describe("§7A.12 case 1 — the blank canvas reaches the workspace", () =>
await expect(composer).toHaveAttribute("data-composer-state", "idle");
await expect(composer).toHaveAttribute("data-disabled-reason", "null");
await expect(composer).toHaveAttribute("data-profile", "orchestrator");
// Issue #13: model id is the provider's own, never a house name.
await expect(composer.locator("[data-composer-model]")).toHaveAttribute(
"data-composer-model",
"heph-fake-model",
);
await expect(composer.locator("[data-context-add-view]")).toHaveCount(1);

await composer
.locator("[data-composer-input]")
Expand Down Expand Up @@ -157,9 +163,26 @@ test.describe("§7A.12 case 2 — the context envelope", () => {
await expect(partChip).toHaveAttribute("data-context-value", PART);
await expect(composer.locator("[data-context-chips] [data-source]")).toHaveCount(0);

// Issue #13: a selected part projects the two §6.4 DFM controls, not a
// Plan toggle. The fixture starts `[dfm] auto_run = false`.
await expect(composer.locator("[data-composer-dfm]")).toHaveCount(1);
await expect(composer.locator("[data-dfm-auto-run]")).toHaveAttribute("data-dfm-auto-run", "false");
await expect(composer.locator("[data-dfm-auto-run-toggle]")).toHaveCount(1);
await expect(composer.locator("[data-dfm-run]")).toHaveCount(1);

// Every member is opt-out (§7A.3).
await partChip.locator('[data-context-drop="part"]').click();
await expect(partChip).toHaveAttribute("data-context-dropped", "");

// Issue #13: Add current view un-drops the view and opens the advisory
// preview. The server must compose the camera token — a disclosure that
// said the agent would be told nothing would be the client/server
// emptiness predicates disagreeing.
await composer.locator("[data-context-add-view]").click();
const viewChip = composer.locator('[data-context-key="view"]');
await expect(viewChip).not.toHaveAttribute("data-context-dropped", "");
await expect(composer.locator("[data-context-preview]")).toBeVisible();
await expect(composer.locator("[data-context-block]")).toContainText("camera view:");
});

test("the disclosure renders the server's block, and says it is advisory", async ({ page }) => {
Expand Down Expand Up @@ -290,6 +313,10 @@ test.describe("§7A.12 case 6 — no agent runtime", () => {
const path = await composer.locator("[data-attach-path]").getAttribute("data-attach-path");
expect(path).toMatch(/providers\.json$/);

// Named absence: do not render a model picker that reads as a signed-in agent.
await expect(composer.locator("[data-composer-model]")).toHaveCount(0);
await expect(composer.locator("[data-context-add-view]")).toHaveCount(1);

// The serve still answers every read route: `agent_unavailable` is about
// sessions, not about the project.
const project = await fetch(`${baseUrl}/api/v1/project`, {
Expand Down
49 changes: 49 additions & 0 deletions web/src/api/dfm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2026 The Hephaestus Authors
// SPDX-License-Identifier: Apache-2.0
//
// The two DFM writes INTERFACE.md §6.4 keeps apart.
//
// `[dfm] auto_run` is a *project setting*, not a per-message flag, so the
// workspace exposes (a) a **Run DFM** action → `POST /parts/{part}/dfm` and
// (b) a project-settings toggle → `POST /project/config/dfm`. Collapsing them
// into one composer switch would imply a tool argument that does not exist.
// Both routes require an `Idempotency-Key`; the caller owns *when*.

import { apiJson } from "./client";
import type { DfmDocument, DfmRun } from "./types";

export interface DfmAutoRunDocument {
readonly status: "ok";
readonly auto_run: boolean;
}

async function keyedPost<T>(path: string, body: unknown, key: string): Promise<T> {
return apiJson<T>(path, {
method: "POST",
headers: { "Content-Type": "application/json", "Idempotency-Key": key },
body: JSON.stringify(body),
});
}

/** `POST /project/config/dfm` — the `[dfm] auto_run` project-config write. */
export function writeDfmAutoRun(autoRun: boolean, key: string): Promise<DfmAutoRunDocument> {
return keyedPost<DfmAutoRunDocument>("/project/config/dfm", { auto_run: autoRun }, key);
}

/**
* `POST /parts/{part}/dfm` — `run_dfm`, keyed (§2.3).
*
* The body is empty by default: process and pack come from the part's own
* declarations. A caller that has a process from the last run may pass it
* through; this function does not invent one.
*/
export function runDfm(
part: string,
key: string,
body: Readonly<Record<string, unknown>> = {},
): Promise<DfmRun> {
return keyedPost<DfmRun>(`/parts/${encodeURIComponent(part)}/dfm`, body, key);
}

/** Re-export the read document so a call site can name one module. */
export type { DfmDocument };
6 changes: 6 additions & 0 deletions web/src/api/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export type DiscoveryKind = (typeof DISCOVERY_KINDS)[number];
export interface ProviderModel {
readonly id: string;
readonly name: string;
/**
* Present only when the spec declared `reasoning: true`. Absence is the
* named "this model has no thinking levels" — the composer does not invent
* an effort picker for it.
*/
readonly reasoning?: boolean;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions web/src/components/stream/Composer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
flex: 0 0 auto;
}

/* ---- session chrome (issue #13) ------------------------------------ */

.chrome {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
}

.dfm {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-1);
}

/* ---- the context chip row (§7A.3) ---------------------------------- */

.chips {
Expand Down
Loading
Loading