Files
ClawdDotNet/src/ClawdDotNet.Core/Config/UnitConfig.cs
T
RichardandClaude Opus 5.5 68e723a9c0 Kontrollpflicht der Leitung: Stichproben gegen das Audit (#693)
A lead looks at the runs of the agents it leads - held against the task and
against what the engine stamped, never by asking the agent.

- RunInspector (Core/Inspection): the mechanical check and first profile of
  the inspector foundation (#204). Flags failed runs, tool errors, refusals,
  unfinished calls, tasks answered with bookkeeping alone, and operations the
  agent names but never called in the run (the 2026-09-14 pattern).
- SpotChecks: picks runs per unit (rate, denser for new agents, new models and
  after a failure, daily cap), deterministic by run id; one task per lead.
- Escalation tool: spot_checks, inspect_run, check_done, propose_measure.
  Measures go to a human; nothing is carried out automatically. A security
  suspicion is its own case, not a personnel matter.
- Organisation view: settings per unit, recent checks, measures to decide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 11:40:20 +02:00

143 lines
5.7 KiB
C#

using System.Text.Json.Serialization;
namespace ClawdDotNet.Core.Config;
/// <summary>
/// #683: A unit — department, team, group — as a node in the organisation tree.
///
/// <para><b>Stored in the instance configuration, next to the agents.</b> An agent's tools
/// already live there; a unit's rules belong beside them, so the truth about an agent is in
/// one place. Every structural change is written to the audit log by the administration,
/// which is what the concept asked the database for.</para>
///
/// <para><b>No value here overrides an agent at run time</b> (Organisation-Konzept, section
/// 3). <see cref="Defaults"/> are only the starting values for agents that join;
/// <see cref="ToolCeiling"/> is checked when an agent's tools are written, never laid over
/// them while it runs. What stands at the agent is what applies.</para>
/// </summary>
public sealed class UnitConfig
{
[JsonPropertyName("id")]
public string Id { get; set; } = "";
[JsonPropertyName("name")]
public string Name { get; set; } = "";
/// <summary>The parent unit; <c>null</c> for a top-level unit.</summary>
[JsonPropertyName("parentId")]
public string? ParentId { get; set; }
/// <summary>
/// The agent leading this unit — one of its members. May be empty: then the nearest
/// unit above that has a lead takes over.
/// </summary>
[JsonPropertyName("leaderAgentId")]
public string? LeaderAgentId { get; set; }
/// <summary>What the unit exists for — the top of every task chain in it (#714).</summary>
[JsonPropertyName("goal")]
public string Goal { get; set; } = "";
/// <summary>
/// The tools members of this unit may have at most; <c>null</c> means no ceiling. A
/// ceiling applies to sub-units as well — the effective ceiling is the intersection
/// along the path to the root.
/// </summary>
[JsonPropertyName("toolCeiling")]
public List<string>? ToolCeiling { get; set; }
/// <summary>Starting values for agents that join this unit.</summary>
[JsonPropertyName("defaults")]
public UnitDefaults Defaults { get; set; } = new();
/// <summary>
/// #687: What the lead of this unit may approve for the agents below it; <c>null</c> means
/// nothing — every approval goes to a human. Set only by a human.
/// </summary>
[JsonPropertyName("approvals")]
public UnitApprovals? Approvals { get; set; }
/// <summary>
/// #693: How often the lead of this unit looks at the runs of the agents it leads;
/// <c>null</c> means no spot checks. Set only by a human — checks cost the lead's runs.
/// </summary>
[JsonPropertyName("inspection")]
public UnitInspection? Inspection { get; set; }
}
/// <summary>
/// #693: The spot checks of a unit's lead. Which run is checked is decided by the run id, not
/// by chance — the same run gets the same answer on every pass, and nobody can tell from inside
/// a run whether it will be looked at.
/// </summary>
public sealed class UnitInspection
{
/// <summary>Share of ordinary runs that are checked, 0 to 1.</summary>
[JsonPropertyName("rate")]
public double Rate { get; set; } = 0.1;
/// <summary>Share for a new agent, a new model, or the run after a failure.</summary>
[JsonPropertyName("denseRate")]
public double DenseRate { get; set; } = 0.5;
/// <summary>How long an agent counts as new after its first run.</summary>
[JsonPropertyName("newDays")]
public int NewDays { get; set; } = 7;
/// <summary>Checks a day for the whole unit — a lead that checks everything doubles the unit's costs.</summary>
[JsonPropertyName("perDay")]
public int PerDay { get; set; } = 5;
}
/// <summary>
/// #687: The limits within which a unit's lead approves instead of the human. They belong to
/// the unit, not to the lead as a person — otherwise the power moves with an agent that changes
/// its post, and a vacant lead would have none.
/// </summary>
public sealed class UnitApprovals
{
/// <summary>
/// The operations the lead may approve: <c>Tool.operation</c>, or <c>Tool</c> for all of its
/// operations. A sub-unit can grant no more than every unit above it that grants anything.
/// </summary>
[JsonPropertyName("operations")]
public List<string> Operations { get; set; } = [];
/// <summary>Approvals the lead may give in 24 hours; beyond that the human decides.</summary>
[JsonPropertyName("perDay")]
public int PerDay { get; set; } = 20;
/// <summary>How long the lead has; after that the call is the human's alone.</summary>
[JsonPropertyName("hours")]
public double Hours { get; set; } = 4;
[JsonIgnore]
public TimeSpan Window => TimeSpan.FromHours(Math.Clamp(Hours, 0.25, 72));
/// <summary>Whether this grant covers the operation.</summary>
public bool Covers(string tool, string? operation)
=> Operations.Any(o => string.Equals(o, tool, StringComparison.OrdinalIgnoreCase)
|| (!string.IsNullOrWhiteSpace(operation)
&& string.Equals(o, $"{tool}.{operation}", StringComparison.OrdinalIgnoreCase)));
}
/// <summary>
/// #683: What an agent gets when it joins a unit. <c>null</c> leaves the agent's own value.
/// Changing these does not touch existing members — writing a value into them is a
/// separate, previewed step.
/// </summary>
public sealed class UnitDefaults
{
[JsonPropertyName("model")]
public string? Model { get; set; }
[JsonPropertyName("dailyCostUsd")]
public decimal? DailyCostUsd { get; set; }
[JsonPropertyName("dailyTokens")]
public long? DailyTokens { get; set; }
[JsonPropertyName("whenExhausted")]
public string? WhenExhausted { get; set; }
}