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
10 changes: 10 additions & 0 deletions docs/features/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ Until then the grant is kept as typed and reaches nobody. With sign-in on, **Set
**Tokens** links to Namespaces in your org for giving a person access: a token is for a tool,
agent or script.

**Settings** on a namespace you manage changes its description, visibility, spend caps,
join rule and capture consent. On a memory namespace it also sets the
[proposal policy](memory/writing.md#proposals): the counts of passed and failed graded
runs that mark a proposal ready to accept, and the count of failed graded runs that marks
one ready to reject, which also rejects it when rejecting is automatic. Loom never accepts
a proposal; an admin of the namespace who did not propose it does. The same dialog sets
the extraction
[coverage sweep](memory/extraction.md#operator-extraction-policy) to always, never, or
left to Loom, which runs it only on fact-dense turns.

The dashboard's text follows the
[copy rules](../development/dashboard-design.md#rules-a-change-is-checked-against): its
sentences name what you see, never an operation or an API path; an operation's name shows
Expand Down
5 changes: 3 additions & 2 deletions docs/features/memory/extraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,9 @@ curl -sX POST http://localhost:7777/v1/extraction_policy.set \
passes cannot read it. An extraction under a policy can therefore keep fewer facts
than the same extraction without one. Two settings get more facts from the same turns,
and both follow the policy: `coverage_sweep=true` on the namespace
(`namespace.register`) gives the turns and statements the first pass cited nowhere a
second reading on every ingest, for one more model call, and a call's own
(`namespace.register`, or the namespace's settings in the dashboard) gives the turns
and statements the first pass cited nowhere a second reading on every ingest, for one
more model call, and a call's own
`extraction_instructions` (a prompt suffix of up to 4,096 characters) says what else to
keep. `session.brief_save` never runs its
deterministic builder under a policy
Expand Down
3 changes: 2 additions & 1 deletion docs/features/namespaces-and-sharing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ a live grant on the name.

Re-registering is a partial update: an omitted field keeps its stored value. `tags` is replaced whole. For
`conflict_threshold`, `capture_generation_io` and `coverage_sweep`, omitted keeps the stored choice and an explicit
`null` returns to the server default.
`null` returns to the server default. The namespace's **Settings** in the [dashboard](dashboard.md) set
`proposal_policy` and `coverage_sweep` too.

| Field | What it controls |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/api/admin.register.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { afterEach, describe, expect, it, vi } from "vitest";

// The server keeps a setting a register call omits and reads an explicit null as "return
// to the default", so the client sends the proposal policy and the coverage sweep only
// when the caller set them, null included.
const post = vi.hoisted(() => vi.fn(async () => ({ registered: true, namespace: "team", updated_at: "" })));
vi.mock("../api", async (importOriginal) => ({ ...(await importOriginal<typeof import("../api")>()), post }));
import { registerNamespace } from "./admin";

const id = { org: "acme", namespace: "team" };
const sent = () => {
expect(post).toHaveBeenCalledTimes(1);
const [path, body] = post.mock.calls[0] as unknown as [string, Record<string, unknown>];
expect(path).toBe("/v1/namespace.register");
return body;
};

afterEach(() => vi.clearAllMocks());

describe("registerNamespace", () => {
it("sends coverage_sweep null when set and omits it when not", async () => {
await registerNamespace(id, { owner_email: "owner@example.com", coverage_sweep: null });
const body = sent();
expect("coverage_sweep" in body).toBe(true);
expect(body["coverage_sweep"]).toBeNull();
post.mockClear();

await registerNamespace(id, { owner_email: "owner@example.com" });
expect("coverage_sweep" in sent()).toBe(false);
});

it("sends the proposal policy when set and omits it when not", async () => {
const policy = { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } as const;
await registerNamespace(id, { owner_email: "owner@example.com", proposal_policy: policy });
expect(sent()["proposal_policy"]).toEqual(policy);
post.mockClear();

await registerNamespace(id, { owner_email: "owner@example.com" });
expect("proposal_policy" in sent()).toBe(false);
});
});
27 changes: 27 additions & 0 deletions frontend/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ export interface ConsolidationRunRow {

// ===== Namespace flags =====

/** A namespace's rule for proposals. In either mode the two thresholds mark a proposal
* ready to accept and `reject_after_fails` failed graded runs mark it ready to reject,
* which is checked first (0 never marks one). Under `auto` that count also rejects the
* proposal. No mode accepts one. */
export interface ProposalPolicy {
mode: "manual" | "auto";
min_passes: number;
max_fails: number;
reject_after_fails: number;
}

export interface NamespaceInfo {
namespace: string;
owner_email: string;
Expand All @@ -259,6 +270,11 @@ export interface NamespaceInfo {
/** null/undefined = inherit the server default; false = this namespace declined
* to have its prompt/completion text captured. */
capture_generation_io?: boolean | null;
/** true and false force the extraction coverage sweep on and off; null/undefined leaves
* it to each ingest's density. */
coverage_sweep?: boolean | null;
/** The defaults (manual, 2 passed, 0 failed, never rejects) when none is stored. */
proposal_policy?: ProposalPolicy;
daily_cost_cap_usd?: number;
daily_user_cost_cap_usd?: number;
budget_alert_inbox?: string;
Expand Down Expand Up @@ -317,6 +333,10 @@ export interface NamespaceRegisterFields {
/** Omit to keep the stored value. */
join_policy?: "inherit" | "open" | "approval" | "closed";
capture_generation_io?: boolean | null;
/** Omit to keep the stored choice; null returns it to each ingest's density. */
coverage_sweep?: boolean | null;
/** Omit to keep the stored policy; it is written whole. */
proposal_policy?: ProposalPolicy;
}

type RegisterResult = { registered: boolean; namespace: string; updated_at: string; visibility?: string };
Expand Down Expand Up @@ -353,6 +373,13 @@ export async function registerNamespace(
if (opts.capture_generation_io !== undefined) {
body["capture_generation_io"] = opts.capture_generation_io;
}
// The same rule: omitted keeps the stored value, and a null sweep is sent as null.
if (opts.coverage_sweep !== undefined) {
body["coverage_sweep"] = opts.coverage_sweep;
}
if (opts.proposal_policy !== undefined) {
body["proposal_policy"] = opts.proposal_policy;
}
return post("/v1/namespace.register", body);
}

Expand Down
155 changes: 155 additions & 0 deletions frontend/src/flows/NamespacePolicyControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { forwardRef, useImperativeHandle, useState } from "react";
import { NumberField } from "@clickhouse/click-ui/NumberField";
import { Select } from "@clickhouse/click-ui/Select";
import type { NamespaceInfo, NamespaceRegisterFields, ProposalPolicy } from "../api";
import { oneOf } from "../lib/oneOf";

interface Props {
namespace: NamespaceInfo;
locked: boolean;
save: (patch: Partial<NamespaceRegisterFields>) => Promise<void>;
}

export interface PolicyControlsHandle {
cancelDrafts: () => boolean;
}

// What a namespace with no stored policy runs with.
const DEFAULT_POLICY: ProposalPolicy = { mode: "manual", min_passes: 2, max_fails: 0, reject_after_fails: 0 };

type Count = "min_passes" | "max_fails" | "reject_after_fails";
// The range the server takes for each count.
const LOWEST: Record<Count, number> = { min_passes: 1, max_fails: 0, reject_after_fails: 0 };
const HIGHEST = 1000;
const NO_DRAFTS: Record<Count, string | null> = { min_passes: null, max_fails: null, reject_after_fails: null };

// The stored sweep is true, false or null; a Select's values are strings.
const SWEEP = [
["inherit", "Let Loom decide", null],
["always", "Always", true],
["never", "Never", false],
] as const;

/** A memory namespace's proposal policy and its coverage sweep, in the settings dialog. */
export const NamespacePolicyControls = forwardRef<PolicyControlsHandle, Props>(function NamespacePolicyControls(
{ namespace, locked, save },
ref,
) {
const policy = namespace.proposal_policy ?? DEFAULT_POLICY;
// A count's text while it is being edited; a count with no draft shows the stored one.
const [drafts, setDrafts] = useState(NO_DRAFTS);

// The dialog's Escape handler asks first: Escape restores a typed count before it closes.
useImperativeHandle(
ref,
() => ({
cancelDrafts() {
if (Object.values(drafts).every((text) => text === null)) return false;
setDrafts(NO_DRAFTS);
return true;
},
}),
[drafts],
);

// Blur (and Enter, which blurs) commits a whole number in the count's range that differs
// from the stored one; anything else reverts without a request. The server replaces the
// policy whole, so the other three fields go with it.
const commit = async (count: Count) => {
const text = drafts[count];
if (text === null) return;
const value = Number(text);
const inRange = Number.isInteger(value) && value >= LOWEST[count] && value <= HIGHEST;
if (text.trim() !== "" && inRange && value !== policy[count]) {
await save({ proposal_policy: { ...policy, [count]: value } });
}
setDrafts((current) => ({ ...current, [count]: null }));
};

const countField = (count: Count, id: string, label: string, hintId: string) => (
<NumberField
id={id}
label={label}
aria-describedby={hintId}
min={String(LOWEST[count])}
max={String(HIGHEST)}
step="1"
value={drafts[count] ?? String(policy[count])}
disabled={locked}
onChange={(text) => setDrafts((current) => ({ ...current, [count]: text }))}
onBlur={() => void commit(count)}
onKeyDown={(e) => {
if (e.key === "Enter") e.currentTarget.blur();
}}
/>
);

const sweep = SWEEP.find(([, , stored]) => stored === (namespace.coverage_sweep ?? null)) ?? SWEEP[0];

return (
<>
<fieldset className="min-w-0 space-y-3">
<legend className="mb-1 text-sm text-text">Proposals</legend>
<div>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
{countField("min_passes", "ns-proposal-min-passes", "Passed graded runs needed", "ns-proposal-ready-hint")}
{countField("max_fails", "ns-proposal-max-fails", "Failed graded runs allowed", "ns-proposal-ready-hint")}
</div>
<p id="ns-proposal-ready-hint" className="mt-1.5 text-xs leading-relaxed text-text-muted">
A proposal is marked ready to accept after this many graded runs passed and at most this many failed.
</p>
</div>
{/* A Select, as the dialog's other single choices are: each pick saves. */}
<Select
label="Rejecting"
value={policy.mode}
disabled={locked}
onSelect={(v) => {
const mode = oneOf(["manual", "auto"] as const, v);
if (mode && mode !== policy.mode) void save({ proposal_policy: { ...policy, mode } });
}}
options={[
{ value: "manual", label: "By a person only" },
{ value: "auto", label: "Automatically" },
]}
/>
{/* Shown in both modes: the server marks a proposal ready to reject at this count
whatever the mode, and the stored count rejects once the mode is automatic. */}
<div>
{countField(
"reject_after_fails",
"ns-proposal-reject-after",
policy.mode === "auto" ? "Failed graded runs that reject" : "Failed graded runs that mark ready to reject",
"ns-proposal-reject-hint",
)}
<p id="ns-proposal-reject-hint" className="mt-1.5 text-xs leading-relaxed text-text-muted">
{policy.mode === "auto"
? "Reject a proposal after this many failed graded runs. 0 never rejects."
: "A proposal is marked ready to reject after this many failed graded runs. 0 never marks one."}
</p>
</div>
<p className="m-0 text-xs leading-relaxed text-text-muted">
Loom never accepts a proposal. An admin of this namespace who did not propose it accepts it.
</p>
</fieldset>

<div>
<Select
label="Coverage sweep"
value={sweep[0]}
disabled={locked}
triggerProps={{ "aria-describedby": "ns-coverage-sweep-hint" }}
onSelect={(v) => {
const next = SWEEP.find(([value]) => value === v);
if (next && next[0] !== sweep[0]) void save({ coverage_sweep: next[2] });
}}
options={SWEEP.map(([value, label]) => ({ value, label }))}
/>
<p id="ns-coverage-sweep-hint" className="mt-1.5 text-xs leading-relaxed text-text-muted">
After extracting facts from a conversation, Loom reads the turns no fact came from once more. It finds more
facts in dense material and costs one more model call. Left to Loom, it runs only on fact-dense turns.
</p>
</div>
</>
);
});
Loading
Loading