Verweis statt Nacherzaehlung: die Engine stempelt den Ursprung (#697, #677)

- Werkzeugkontext kennt Lauf und Aufgabe des Laufs (RunId, RunTaskId); die
  Delegationskette traegt den Lauf des Aufrufers weiter (RunId, CallerRunId)
- Aufgaben tragen origin_run / origin_task (Datei, DB, Taskboard "Arose from"),
  gestempelt, nie vom Agenten behauptet
- Kommentare nennen den Lauf, in dem sie geschrieben wurden
- Laufbeleg: CallerRunId; Laufansicht fuehrt zu "Delegiert von" und "Delegiert an"
- #677: task_update ersetzt den Rumpf nicht mehr, Abnahmekriterien aendert nur der
  Ersteller; Kommentare der Fremdinhalt-Stufe auf fremden Aufgaben kommen gerahmt an
- WebUI: Herkunft auf der Aufgabenkarte mit Link zum Lauf

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard
2026-09-25 09:27:47 +02:00
co-authored by Claude Opus 5.5
parent 3f90e0d0cd
commit f812dbd856
26 changed files with 493 additions and 47 deletions
+5 -2
View File
@@ -15,7 +15,9 @@ public sealed record RunDetail(
IReadOnlyList<StagedCall> Approvals,
RunTranscript? Transcript,
string? SystemPrompt,
string TranscriptState);
string TranscriptState,
// #697: The runs this one delegated to — the way down to the originals.
IReadOnlyList<RunReceipt>? CalledRuns = null);
/// <summary>
/// Read side of the usage analysis and the prompt history (#660) for both user interfaces.
@@ -58,7 +60,8 @@ public sealed class RunInsights(
transcript?.SystemPromptHash is { } hash && transcripts is not null
? await transcripts.GetSystemPromptAsync(hash, ct)
: null,
TranscriptState(transcript, agentId));
TranscriptState(transcript, agentId),
await audit.ListReceiptsCalledFromAsync(runId, ct));
}
/// <summary>Why there is or is not a transcript - the UI says it instead of showing an empty box.</summary>
@@ -79,6 +79,13 @@ public sealed class AgentActivity
return new RunHandle(this, run);
}
/// <summary>#697: A run in progress, by its id.</summary>
public ActiveRun? Find(string runId)
{
lock (_lock)
return _active.GetValueOrDefault(runId);
}
/// <summary>The runs in progress right now.</summary>
public IReadOnlyList<ActiveRun> ActiveRuns()
{
@@ -121,6 +121,12 @@ public sealed record RunReceipt
public string ResultRef { get; init; } = "";
public DateTime OccurredAt { get; init; }
/// <summary>
/// #697: The run this one was delegated from — stamped by the engine from the delegation
/// chain. With it, a result can be followed back to the run that asked for it.
/// </summary>
public string? CallerRunId { get; init; }
}
/// <summary>
@@ -24,6 +24,9 @@ public interface IAuditRepository
/// <summary>Alle Belege zu einem Task — die Kosten pro Ergebnis (C7).</summary>
Task<IReadOnlyList<RunReceipt>> ListReceiptsForTaskAsync(string taskId, CancellationToken ct);
/// <summary>#697: The runs delegated from a run — the way down to the originals.</summary>
Task<IReadOnlyList<RunReceipt>> ListReceiptsCalledFromAsync(string runId, CancellationToken ct);
/// <summary>
/// #660: All receipts in <c>[fromUtc, toUtc)</c>, oldest first, at most
/// <paramref name="limit"/> - the input of the usage analysis.
@@ -46,11 +46,11 @@ public sealed class SqliteAuditRepository : IAuditRepository
INSERT INTO RunReceipts
(RunId, AgentId, Model, Source, TaskId, Status, StepCount,
PromptTokens, CompletionTokens, CachedTokens, CostUsd, CostIsKnown,
DurationMs, ResultRef, OccurredAt)
DurationMs, ResultRef, OccurredAt, CallerRunId)
VALUES
(@runId, @agentId, @model, @source, @taskId, @status, @stepCount,
@prompt, @completion, @cached, @cost, @costKnown,
@durationMs, @resultRef, @occurredAt)
@durationMs, @resultRef, @occurredAt, @callerRunId)
""";
cmd.Parameters.AddWithValue("@runId", receipt.RunId);
cmd.Parameters.AddWithValue("@agentId", receipt.AgentId);
@@ -67,6 +67,7 @@ public sealed class SqliteAuditRepository : IAuditRepository
cmd.Parameters.AddWithValue("@durationMs", receipt.DurationMs);
cmd.Parameters.AddWithValue("@resultRef", receipt.ResultRef);
cmd.Parameters.AddWithValue("@occurredAt", Format(receipt.OccurredAt));
cmd.Parameters.AddWithValue("@callerRunId", (object?)receipt.CallerRunId ?? DBNull.Value);
await cmd.ExecuteNonQueryAsync(ct);
}, ct);
@@ -117,6 +118,20 @@ public sealed class SqliteAuditRepository : IAuditRepository
return results;
}
public async Task<IReadOnlyList<RunReceipt>> ListReceiptsCalledFromAsync(string runId, CancellationToken ct)
{
await using var conn = await _storage.OpenConnectionAsync(ct);
using var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT " + ReceiptColumns + " FROM RunReceipts WHERE CallerRunId = @runId ORDER BY Id";
cmd.Parameters.AddWithValue("@runId", runId);
var results = new List<RunReceipt>();
await using var reader = await cmd.ExecuteReaderAsync(ct);
while (await reader.ReadAsync(ct))
results.Add(ReadReceipt(reader));
return results;
}
public async Task<IReadOnlyList<RunReceipt>> ListReceiptsForTaskAsync(string taskId, CancellationToken ct)
{
await using var conn = await _storage.OpenConnectionAsync(ct);
@@ -249,7 +264,7 @@ public sealed class SqliteAuditRepository : IAuditRepository
private const string ReceiptColumns =
"Id, RunId, AgentId, Model, Source, TaskId, Status, StepCount, PromptTokens, " +
"CompletionTokens, CachedTokens, CostUsd, CostIsKnown, DurationMs, ResultRef, OccurredAt";
"CompletionTokens, CachedTokens, CostUsd, CostIsKnown, DurationMs, ResultRef, OccurredAt, CallerRunId";
private static async Task<IReadOnlyList<AuditEntry>> ReadEntriesAsync(SqliteCommand cmd, CancellationToken ct)
{
@@ -293,7 +308,8 @@ public sealed class SqliteAuditRepository : IAuditRepository
CostIsKnown = r.GetInt32(12) != 0,
DurationMs = r.GetInt64(13),
ResultRef = r.GetString(14),
OccurredAt = Parse(r.GetString(15))
OccurredAt = Parse(r.GetString(15)),
CallerRunId = r.IsDBNull(16) ? null : r.GetString(16)
};
private static string Format(DateTime value) => value.ToUniversalTime().ToString("O");
+16 -9
View File
@@ -203,7 +203,7 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
var result = await RunCoreAsync(agentConfig, userMessage, instanceId, externalCt, runId, source, chain, recorder);
activity.Complete(result.Status.ToString());
await RecordUsageAsync(agentConfig, result);
await RecordReceiptAsync(runId, agentConfig, result, source ?? AuditSource.Direct, taskId);
await RecordReceiptAsync(runId, agentConfig, result, source ?? AuditSource.Direct, taskId, chain.CallerRunId);
await SaveTranscriptAsync(recorder, runId, agentConfig, result, source ?? AuditSource.Direct, taskId);
return result;
}
@@ -526,7 +526,7 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
var result = await ChatCoreAsync(agentConfig, userMessage, instanceId, runCts.Token, source, runId, chain, recorder);
activity.Complete(result.Status.ToString());
await RecordUsageAsync(agentConfig, result);
await RecordReceiptAsync(runId, agentConfig, result, source, taskId);
await RecordReceiptAsync(runId, agentConfig, result, source, taskId, chain.CallerRunId);
await SaveTranscriptAsync(recorder, runId, agentConfig, result, source ?? AuditSource.Direct, taskId);
return result;
}
@@ -1501,7 +1501,7 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
? default
: JsonDocument.Parse(arguments).RootElement;
var context = BuildToolContext(agentConfig, instanceId, toolName, ct, chain);
var context = BuildToolContext(agentConfig, instanceId, toolName, ct, chain, runId);
// #579: Was das Werkzeug ohnehin verbieten wuerde, kommt gar nicht erst in die
// Freigabeliste. Vorher lag dort z.B. ein Loeschvorschlag eines Agenten, der
@@ -1660,13 +1660,14 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
private AgentToolContext BuildToolContext(
AgentConfig agentConfig, string instanceId, string toolName, CancellationToken ct,
DelegationChain? chain = null)
DelegationChain? chain = null, string? runId = null)
{
var toolConfig = agentConfig.Tools.TryGetValue(toolName, out var cfg)
? cfg.AsReadOnly()
: new Dictionary<string, object?>().AsReadOnly();
var toolLogger = _loggerFactory.CreateLogger($"ClawdDotNet.Tools.{toolName}.Execution");
var baseChain = chain ?? DelegationChain.Root(agentConfig.AgentId);
return new AgentToolContext(
agentConfig.AgentId,
@@ -1680,10 +1681,14 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
this,
_memoryRepository,
_taskRepository,
chain ?? DelegationChain.Root(agentConfig.AgentId))
// #697: The chain carries the caller's run, so a delegated run can name where it came from.
runId is null ? baseChain : baseChain.WithRun(runId))
{
Organisation = CurrentOrganisation(),
Trust = ReportingLine.TrustOf(agentConfig, _toolRegistry.Get)
Trust = ReportingLine.TrustOf(agentConfig, _toolRegistry.Get),
// #697: Where something an agent hands on came from — known to the engine, not claimed by the agent.
RunId = runId,
RunTaskId = runId is null ? null : Activity.Find(runId)?.TaskId
};
}
@@ -1712,7 +1717,7 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
: JsonDocument.Parse(argumentsJson).RootElement;
// #641: Ein Mensch hat genau diesen Aufruf freigegeben.
var context = BuildToolContext(config, _instanceId, tool, ct) with { FreigabeGeprueft = true };
var context = BuildToolContext(config, _instanceId, tool, ct, runId: runId) with { FreigabeGeprueft = true };
var result = await agentTool.ExecuteAsync(input, context, ct);
var status = result.Success ? AuditStatus.Ok : AuditStatus.Error;
@@ -1907,7 +1912,8 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
}
private async Task RecordReceiptAsync(
string runId, AgentConfig agentConfig, AgentRunResult result, string? source, string? taskId)
string runId, AgentConfig agentConfig, AgentRunResult result, string? source, string? taskId,
string? callerRunId = null)
{
if (_auditRepository is null)
return;
@@ -1937,7 +1943,8 @@ public sealed class AgentEngine : IAgentMessageRouter, Staging.IFrozenCallExecut
CostIsKnown = reported is not null || (estimate?.IsKnown ?? false),
DurationMs = (long)result.Duration.TotalMilliseconds,
ResultRef = Cap(result.FinalMessage ?? "", 500),
OccurredAt = DateTime.Now
OccurredAt = DateTime.Now,
CallerRunId = callerRunId
}, CancellationToken.None);
}
catch (Exception ex)
@@ -383,6 +383,13 @@ public sealed class SqliteStorage
// #714: The task a task serves — the goal chain.
SpalteErgaenzen(connection, "Tasks", "ParentId", "TEXT NOT NULL DEFAULT ''");
// #697: The run a delegated run came from.
SpalteErgaenzen(connection, "RunReceipts", "CallerRunId", "TEXT NULL");
// #697: Where a task came from — the run, and the task that run worked on.
SpalteErgaenzen(connection, "Tasks", "OriginRunId", "TEXT NOT NULL DEFAULT ''");
SpalteErgaenzen(connection, "Tasks", "OriginTaskId", "TEXT NOT NULL DEFAULT ''");
// Findet offene Aufrufe beim Start, ohne die ganze Tabelle zu lesen.
using var index = connection.CreateCommand();
index.CommandText = """
@@ -34,11 +34,11 @@ public sealed class SqliteTaskRepository : ITaskRepository
INSERT INTO Tasks
(Id, Title, Status, Type, Priority, Assignee, WhenKind, WhenValue, WhenTz,
RequireApproval, Acceptance, BlockedBy, OnlyWhenMarketOpen, Body, FileName,
ToolName, JobTypeId, LastOccurrence, ClaimToken, ClaimedAt, CreatedAt, UpdatedAt, CreatedBy, ParentId)
ToolName, JobTypeId, LastOccurrence, ClaimToken, ClaimedAt, CreatedAt, UpdatedAt, CreatedBy, ParentId, OriginRunId, OriginTaskId)
VALUES
(@id, @title, @status, @type, @priority, @assignee, @whenKind, @whenValue, @whenTz,
@requireApproval, @acceptance, @blockedBy, @market, @body, @fileName,
@toolName, @jobType, NULL, NULL, NULL, @createdAt, @updatedAt, @createdBy, @parentId);
@toolName, @jobType, NULL, NULL, NULL, @createdAt, @updatedAt, @createdBy, @parentId, @originRun, @originTask);
""";
BindDefinition(insert, task);
insert.Parameters.AddWithValue("@status", TaskText.Of(task.Status));
@@ -62,6 +62,8 @@ public sealed class SqliteTaskRepository : ITaskRepository
FileName = @fileName, ToolName = @toolName, JobTypeId = @jobType,
CreatedBy = CASE WHEN @createdBy = '' THEN CreatedBy ELSE @createdBy END,
ParentId = @parentId,
OriginRunId = CASE WHEN @originRun = '' THEN OriginRunId ELSE @originRun END,
OriginTaskId = CASE WHEN @originTask = '' THEN OriginTaskId ELSE @originTask END,
UpdatedAt = @updatedAt
WHERE Id = @id
""";
@@ -333,7 +335,7 @@ public sealed class SqliteTaskRepository : ITaskRepository
"Id, Title, Status, Type, Priority, Assignee, WhenKind, WhenValue, WhenTz, " +
"RequireApproval, Acceptance, BlockedBy, OnlyWhenMarketOpen, Body, FileName, " +
"ToolName, JobTypeId, LastOccurrence, ClaimToken, ClaimedAt, CreatedAt, UpdatedAt, "
+ "BudgetMissCount, LastBudgetMissAt, DeferredUntil, CatchUpPending, CreatedBy, ParentId";
+ "BudgetMissCount, LastBudgetMissAt, DeferredUntil, CatchUpPending, CreatedBy, ParentId, OriginRunId, OriginTaskId";
private static void BindDefinition(SqliteCommand cmd, TaskItem task)
{
@@ -356,6 +358,9 @@ public sealed class SqliteTaskRepository : ITaskRepository
// #684: a file without it (written by hand, or older) keeps what the database knows.
cmd.Parameters.AddWithValue("@createdBy", task.CreatedBy ?? "");
cmd.Parameters.AddWithValue("@parentId", task.ParentId ?? "");
// #697: Stamped once; a file written by hand, or re-imported, keeps what is known.
cmd.Parameters.AddWithValue("@originRun", task.OriginRunId ?? "");
cmd.Parameters.AddWithValue("@originTask", task.OriginTaskId ?? "");
}
private static async Task<TaskItem?> ReadAsync(SqliteConnection conn, string id, CancellationToken ct)
@@ -408,7 +413,9 @@ public sealed class SqliteTaskRepository : ITaskRepository
DeferredUntil = r.IsDBNull(24) ? null : Parse(r.GetString(24)),
CatchUpPending = r.GetInt32(25) != 0,
CreatedBy = r.GetString(26),
ParentId = r.GetString(27)
ParentId = r.GetString(27),
OriginRunId = r.GetString(28),
OriginTaskId = r.GetString(29)
};
}
@@ -154,6 +154,8 @@ public static class TaskFrontmatter
JobTypeId = scalars.GetValueOrDefault("job_type", ""),
CreatedBy = scalars.GetValueOrDefault("created_by", ""),
ParentId = scalars.GetValueOrDefault("parent", ""),
OriginRunId = scalars.GetValueOrDefault("origin_run", ""),
OriginTaskId = scalars.GetValueOrDefault("origin_task", ""),
Body = body
};
return true;
@@ -175,6 +177,10 @@ public static class TaskFrontmatter
sb.Append($"created_by: {Scalar(task.CreatedBy)}\n");
if (!string.IsNullOrWhiteSpace(task.ParentId))
sb.Append($"parent: {Scalar(task.ParentId)}\n");
if (!string.IsNullOrWhiteSpace(task.OriginRunId))
sb.Append($"origin_run: {Scalar(task.OriginRunId)}\n");
if (!string.IsNullOrWhiteSpace(task.OriginTaskId))
sb.Append($"origin_task: {Scalar(task.OriginTaskId)}\n");
if (task.When is { } w)
{
+10
View File
@@ -242,6 +242,16 @@ public sealed record TaskItem
/// </summary>
public string ParentId { get; init; } = "";
/// <summary>
/// #697: The run in which an agent created this task — stamped by the engine, never taken
/// from the agent. With it, whoever decides can go back to the original without asking:
/// what the agent saw and did when it handed this out. Empty for tasks from a human.
/// </summary>
public string OriginRunId { get; init; } = "";
/// <summary>#697: The task that run was working on, if any — the task this one arose from.</summary>
public string OriginTaskId { get; init; } = "";
/// <summary>A one-time task that was refused for lack of budget and carried over.</summary>
public bool IsCarriedOver => !IsRecurring && BudgetMissCount > 0;
@@ -99,10 +99,16 @@ public sealed class TaskboardService
}
/// <summary>Hängt einen Kommentar (Ergebnis, Kritik) an den Rumpf an.</summary>
public Task<TaskItem?> AddCommentAsync(string id, string author, string text, CancellationToken ct)
/// <param name="runId">
/// #697: The run the comment was written in — stamped by the engine, so a reader can go
/// back to what the author saw instead of relying on the retelling.
/// </param>
public Task<TaskItem?> AddCommentAsync(string id, string author, string text, CancellationToken ct, string? runId = null)
=> UpdateAsync(id, current =>
{
var stamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
if (!string.IsNullOrWhiteSpace(runId))
stamp += $", run {runId}";
var block = $"---\n**{author}** ({stamp}):\n\n{text.Trim()}";
var body = string.IsNullOrWhiteSpace(current.Body) ? block : $"{current.Body.TrimEnd()}\n\n{block}";
return current with { Body = body };
@@ -46,6 +46,12 @@ public sealed record AgentToolContext(
/// #715: The calling agent's trust tier, from its tools. Tools that let an agent write to
/// someone above it check the way up here. Standard in tests and outside the engine.
/// </summary>
/// <summary>#697: The run this call belongs to — for stamping where something came from.</summary>
public string? RunId { get; init; }
/// <summary>#697: The task that run works on, if it was started for one.</summary>
public string? RunTaskId { get; init; }
public global::ClawdDotNet.Core.Organisation.AgentTrust Trust { get; init; }
= global::ClawdDotNet.Core.Organisation.AgentTrust.Standard;
}
+23 -2
View File
@@ -29,7 +29,28 @@ public sealed class DelegationChain
{
private readonly string[] _agents;
private DelegationChain(string[] agents) => _agents = agents;
private DelegationChain(string[] agents, string? runId = null, string? callerRunId = null)
{
_agents = agents;
RunId = runId;
CallerRunId = callerRunId;
}
/// <summary>
/// #697: The run of the last agent in the chain — the one that is handing on. Stamped by
/// the engine when it builds a tool's context, so a delegated run can name the run it
/// came from. <c>null</c> outside a run.
/// </summary>
public string? RunId { get; }
/// <summary>
/// #697: The run of the agent before the last — the run a delegated run was started from.
/// Carried over by <see cref="Append"/>, so the new run can record its origin.
/// </summary>
public string? CallerRunId { get; }
/// <summary>#697: The same chain, stamped with the run of its last agent.</summary>
public DelegationChain WithRun(string runId) => new(_agents, runId, CallerRunId);
/// <summary>Der Anfang: ein Lauf, den niemand delegiert hat.</summary>
public static DelegationChain Root(string agentId) => new([agentId]);
@@ -49,7 +70,7 @@ public sealed class DelegationChain
/// <summary>Die Kette mit einem weiteren Agenten am Ende.</summary>
public DelegationChain Append(string agentId)
=> new([.. _agents, agentId]);
=> new([.. _agents, agentId], runId: null, callerRunId: RunId); // the new agent's run is not known yet
/// <summary>Für Meldungen und Protokoll: <c>A -> B -> C</c>.</summary>
public override string ToString() => string.Join(" -> ", _agents);
@@ -359,6 +359,9 @@
"tasks.boardTopLevel": "Oberste Ebene",
"tasks.parent": "Dient Aufgabe (Eltern)",
"tasks.serves": "dient {id}",
"tasks.origin": "Herkunft",
"tasks.originTask": "bei der Arbeit an {id}",
"tasks.originRun": "Lauf öffnen",
"services.title": "Dienste",
"services.newService": "Neuer Dienst",
@@ -746,6 +749,8 @@
"detail.toolCalls": "Werkzeugaufrufe",
"detail.toolCalls.hint": "Aus dem Audit-Log — auch ohne Verlauf vorhanden.",
"detail.approvals": "Zur Freigabe vorgelegt",
"detail.calledBy": "Delegiert von",
"detail.calledRuns": "Delegiert an",
"timeline.title": "Tokennutzung › Zeitverlauf",
"timeline.chart": "Zeitverlauf",
@@ -359,6 +359,9 @@
"tasks.boardTopLevel": "Top level",
"tasks.parent": "Serves task (parent)",
"tasks.serves": "serves {id}",
"tasks.origin": "Arose from",
"tasks.originTask": "while working on {id}",
"tasks.originRun": "open run",
"services.title": "Services",
"services.newService": "New Service",
@@ -746,6 +749,8 @@
"detail.toolCalls": "Tool calls",
"detail.toolCalls.hint": "From the audit log - available even without a transcript.",
"detail.approvals": "Proposed for approval",
"detail.calledBy": "Delegated from",
"detail.calledRuns": "Delegated to",
"timeline.title": "Token usage › Timeline",
"timeline.chart": "Timeline",
@@ -78,10 +78,26 @@ function buildReceipt(run) {
add("runs.col.cost", r.costIsKnown || r.costUsd > 0 ? formatiereKosten(r.costUsd) : "—");
add("runs.col.duration", formatDuration(r.durationMs));
if (r.result) add("detail.result", r.result);
// #697: the way back to the run that asked for this one.
if (r.callerRunId) add("detail.calledBy", laufLink(r.callerRunId));
}
// #697: and the way down to the runs this one asked.
if (run.calledRuns && run.calledRuns.length > 0) {
const liste = erstelleElement("span", {});
run.calledRuns.forEach((c, i) => {
if (i > 0) liste.append(", ");
liste.append(laufLink(c.runId, `${c.agentId} · ${c.runId.slice(0, 8)}`));
});
add("detail.calledRuns", liste);
}
return erstelleKarte(t("detail.receipt"), [list]);
}
/** #697: A run, linked — its content stays where it is, the reference travels. */
export function laufLink(runId, text) {
return erstelleElement("a", { href: `#/verbrauch/runs/${encodeURIComponent(runId)}`, text: text || runId });
}
function buildTranscriptState(run) {
const text = {
disabled: t("detail.transcript.disabled"),
@@ -9,6 +9,7 @@
import { api } from "../modules/api.js";
import { t } from "../modules/i18n.js";
import { laufLink } from "./run-detail.js";
import {
erstelleElement,
erstelleIcon,
@@ -202,6 +203,19 @@ function erstelleAufgabenKarte(task) {
})
);
// #697: Where the task came from — stamped by the engine, with the way back to the run.
if (task.originRunId || task.originTaskId) {
const herkunft = erstelleElement("p", { klasse: "gedaempft text-klein" }, `${t("tasks.origin")}: `);
const teile = [];
if (task.createdBy) teile.push(task.createdBy);
if (task.originTaskId) teile.push(t("tasks.originTask", { id: task.originTaskId }));
herkunft.append(teile.join(", "));
if (task.originRunId) {
herkunft.append(teile.length > 0 ? " · " : "", laufLink(task.originRunId, t("tasks.originRun")));
}
zeilen.push(herkunft);
}
const letzter = erstelleElement("p", { klasse: "gedaempft text-klein" }, `${t("tasks.lastRun")}: `);
if (task.lastRun) {
letzter.append(
@@ -75,7 +75,7 @@ public sealed class TaskboardTool : IAgentTool
},
"body": {
"type": "string",
"description": "Description/assignment — passed as task instructions to executing agent."
"description": "task_create: description/assignment — passed as task instructions to executing agent. Not in task_update: the body is only ever added to, with task_comment."
},
"assignee": {
"type": "string",
@@ -110,7 +110,7 @@ public sealed class TaskboardTool : IAgentTool
},
"acceptance": {
"type": "string",
"description": "Acceptance criteria against which the result is verified."
"description": "Acceptance criteria against which the result is verified. In task_update only by the task's creator."
},
"parent": {
"type": "string",
@@ -331,7 +331,7 @@ public sealed class TaskboardTool : IAgentTool
await board.AddCommentAsync(
dublette.Id, author,
$"Observed again — {author} wanted to create the same task: \"{title.Trim()}\"",
ct);
ct, context.RunId);
return ToolResult.Fail(
$"Not created: {dublette.Id} \"{dublette.Title}\" has been open since {dublette.CreatedAt:dd.MM. HH:mm} " +
@@ -355,7 +355,10 @@ public sealed class TaskboardTool : IAgentTool
OnlyWhenMarketOpen = GetBool(input, "onlyWhenMarketOpen") ?? false,
// #684: decides the board when the task is for a human or a fresh run.
CreatedBy = author,
ParentId = parent
ParentId = parent,
// #697: Where it came from — the engine's knowledge, never an argument of the agent.
OriginRunId = context.RunId ?? "",
OriginTaskId = context.RunTaskId ?? ""
};
var created = await board.CreateAsync(definition, ct);
@@ -393,10 +396,22 @@ public sealed class TaskboardTool : IAgentTool
return ToolResult.Fail($"No task found with ID '{id}'.");
// #715: No changes of status or fields on the tasks of someone above.
if (await board.GetAsync(id.Trim(), ct) is { } current
&& Upward(AssigneeOf(current), UpwardKind.Change, context) is { } notUp)
var existing = await board.GetAsync(id.Trim(), ct);
if (existing is not null && Upward(AssigneeOf(existing), UpwardKind.Change, context) is { } notUp)
return ToolResult.Fail(notUp);
// #677/#697: The body holds the order and every comment on it. Replacing it would erase
// the trail back to the original — it is only ever added to.
if (input.TryGetProperty("body", out _))
return ToolResult.Fail("The body of a task is not replaced — it holds the order and the whole discussion. " +
"Add to it with task_comment.");
// #677: Whoever is measured against the criteria does not get to move them.
if (existing is not null && input.TryGetProperty("acceptance", out _)
&& !string.Equals(existing.CreatedBy, context.AgentId, StringComparison.OrdinalIgnoreCase))
return ToolResult.Fail("Only the task's creator changes its acceptance criteria. Comment with task_comment " +
"if you think they should change.");
if (!TryReadWhen(input, out var when, out var whenError))
return ToolResult.Fail(whenError!);
var hasWhen = input.TryGetProperty("when", out _);
@@ -408,7 +423,6 @@ public sealed class TaskboardTool : IAgentTool
var result = await board.UpdateAsync(id.Trim(), current => current with
{
Title = GetString(input, "title")?.Trim() ?? current.Title,
Body = GetString(input, "body")?.Trim() ?? current.Body,
Status = ParseStatusFilter(GetString(input, "status")) ?? current.Status,
Type = input.TryGetProperty("type", out _) ? TaskText.Type(GetString(input, "type")) : current.Type,
Priority = GetInt(input, "priority") ?? current.Priority,
@@ -440,15 +454,21 @@ public sealed class TaskboardTool : IAgentTool
// #715: A comment goes up one level at most, and only from the standard tier; reopening
// is a change of status, which never goes up.
if (await board.GetAsync(id.Trim(), ct) is { } target
&& Upward(AssigneeOf(target), GetBool(input, "reopen") == true ? UpwardKind.Change : UpwardKind.Comment, context) is { } notUp)
if (await board.GetAsync(id.Trim(), ct) is not { } target)
return ToolResult.Fail($"No task found with ID '{id}'.");
if (Upward(AssigneeOf(target), GetBool(input, "reopen") == true ? UpwardKind.Change : UpwardKind.Comment, context) is { } notUp)
return ToolResult.Fail(notUp);
var text = GetString(input, "text");
if (string.IsNullOrWhiteSpace(text))
return ToolResult.Fail("'text' is required — what should be commented?");
var result = await board.AddCommentAsync(id.Trim(), author, text.Trim(), ct);
// #715: A comment is part of the body, and the body goes into the assignee's next run. From
// an agent that reads foreign content, on someone else's task, it arrives framed as data.
var commentText = string.Equals(AssigneeOf(target), author, StringComparison.OrdinalIgnoreCase)
? text.Trim()
: ReportingLine.Frame(context.Trust, author, text.Trim());
var result = await board.AddCommentAsync(id.Trim(), author, commentText, ct, context.RunId);
if (result is null)
return ToolResult.Fail($"No task found with ID '{id}'.");
@@ -463,6 +483,19 @@ public sealed class TaskboardTool : IAgentTool
// ─── Darstellung ───
/// <summary>#697: "amazon-lead, while working on t-3, run 4f…" — or <c>null</c> for a task from a human.</summary>
private static string? Origin(TaskItem task)
{
var parts = new List<string>();
if (!string.IsNullOrWhiteSpace(task.CreatedBy))
parts.Add(task.CreatedBy);
if (!string.IsNullOrWhiteSpace(task.OriginTaskId))
parts.Add($"while working on {task.OriginTaskId}");
if (!string.IsNullOrWhiteSpace(task.OriginRunId))
parts.Add($"run {task.OriginRunId}");
return parts.Count == 0 ? null : string.Join(", ", parts);
}
private static string Render(IReadOnlyList<TaskItem> tasks)
{
var sb = new StringBuilder();
@@ -478,6 +511,9 @@ public sealed class TaskboardTool : IAgentTool
block.AppendLine($" Assignee: {task.Assignee} | Priority: {task.Priority}{FormatWhen(task.When)}");
if (!string.IsNullOrWhiteSpace(task.ParentId))
block.AppendLine($" Serves: {task.ParentId}");
// #697: The origin travels with the task; the content stays where it is.
if (Origin(task) is { } origin)
block.AppendLine($" Arose from: {origin}");
if (task.BlockedBy.Count > 0)
block.AppendLine($" Waiting for: {string.Join(", ", task.BlockedBy)}");
+4 -1
View File
@@ -126,7 +126,10 @@ public sealed record TaskDto(
string? ParentId = null,
// #684: the unit whose board the task is on, computed from the organisation; null on the top level.
string? Board = null,
string? BoardPath = null);
string? BoardPath = null,
// #697: where the task came from — stamped by the engine.
string? OriginRunId = null,
string? OriginTaskId = null);
/// <summary>
/// #716: Runs of this task the budget refused — only present while something is open
+3 -1
View File
@@ -160,7 +160,9 @@ internal static class Mapping
task.CatchUpPending, task.IsCarriedOver)
: null,
CreatedBy: string.IsNullOrWhiteSpace(task.CreatedBy) ? null : task.CreatedBy,
ParentId: string.IsNullOrWhiteSpace(task.ParentId) ? null : task.ParentId);
ParentId: string.IsNullOrWhiteSpace(task.ParentId) ? null : task.ParentId,
OriginRunId: string.IsNullOrWhiteSpace(task.OriginRunId) ? null : task.OriginRunId,
OriginTaskId: string.IsNullOrWhiteSpace(task.OriginTaskId) ? null : task.OriginTaskId);
/// <summary>#684: The board of a task, for a list the human sees whole.</summary>
public static TaskDto WithBoard(this TaskDto dto, TaskItem task, Core.Organisation.OrgChart org)
@@ -182,20 +182,16 @@ public static class AnalyticsEndpoints
// ─── Mapping ───
private static RunRowDto ToDto(RunRow row)
{
var r = row.Receipt;
return new RunRowDto(r.RunId, r.AgentId, r.Model, r.Source, r.TaskId, row.TaskTitle, r.Status,
private static RunRowDto ToDto(RunRow row) => Row(row.Receipt, row.TaskTitle);
private static RunRowDto Row(Core.Audit.RunReceipt r, string? taskTitle)
=> new(r.RunId, r.AgentId, r.Model, r.Source, r.TaskId, taskTitle, r.Status,
r.StepCount, r.PromptTokens, r.CompletionTokens, r.CachedTokens, r.CostUsd, r.CostIsKnown,
r.DurationMs, r.ResultRef, r.OccurredAt);
}
r.DurationMs, r.ResultRef, r.OccurredAt, r.CallerRunId);
private static RunDetailDto ToDto(RunDetail d) => new(
d.RunId,
d.Receipt is { } r
? new RunRowDto(r.RunId, r.AgentId, r.Model, r.Source, r.TaskId, d.TaskTitle, r.Status, r.StepCount,
r.PromptTokens, r.CompletionTokens, r.CachedTokens, r.CostUsd, r.CostIsKnown, r.DurationMs, r.ResultRef, r.OccurredAt)
: null,
d.Receipt is { } r ? Row(r, d.TaskTitle) : null,
d.ToolCalls.Select(c => new RunToolCallDto(c.OccurredAt, c.Tool, c.Status.ToString(), c.Arguments, c.Summary, c.DurationMs, c.Source)).ToList(),
d.Approvals.Select(c => c.ToDto()).ToList(),
d.Transcript is { } t
@@ -203,7 +199,8 @@ public static class AnalyticsEndpoints
t.Entries, t.SizeChars, t.Truncated)
: null,
d.SystemPrompt,
d.TranscriptState);
d.TranscriptState,
(d.CalledRuns ?? []).Select(c => Row(c, null)).ToList());
private static PromptHistorySettingsDto SettingsDto(AppHost host)
{
@@ -223,7 +220,9 @@ public static class AnalyticsEndpoints
public sealed record RunRowDto(
string RunId, string AgentId, string Model, string Source, string? TaskId, string? TaskTitle,
string Status, int StepCount, int PromptTokens, int CompletionTokens, int CachedTokens,
decimal CostUsd, bool CostIsKnown, long DurationMs, string Result, DateTime OccurredAt);
decimal CostUsd, bool CostIsKnown, long DurationMs, string Result, DateTime OccurredAt,
// #697: the run this one was delegated from.
string? CallerRunId = null);
public sealed record RunTotalsDto(
int Runs, long PromptTokens, long CompletionTokens, long CachedTokens,
@@ -259,7 +258,9 @@ public sealed record RunDetailDto(
IReadOnlyList<StagedCallDto> Approvals,
TranscriptDto? Transcript,
string? SystemPrompt,
string TranscriptState);
string TranscriptState,
// #697: the runs this one delegated to.
IReadOnlyList<RunRowDto>? CalledRuns = null);
public sealed record TranscriptSummaryDto(
string RunId, string AgentId, string Model, string Source, string? TaskId,