Skip to content

Expose model preparation, compaction, history and usage operations - #1912

Closed
eric8810 wants to merge 19 commits into
eric/1292-domain-loop-promptfrom
eric/1292-domain-context
Closed

eric8810 wants to merge 19 commits into
eric/1292-domain-loop-promptfrom
eric/1292-domain-context

Conversation

@eric8810

@eric8810 eric8810 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1292

Implementation

Depends on #1911. Both PRs register operations on the same branch contextPreparation service.

  • Loop → prepareModelHost.prepare.
  • ContextPreparation → prepareContextHost.prepare.
  • Session context usage and PromptSuggestion → contextUsage.read.
  • Context model limits and token accounting → contextModelHost.
  • Compaction → compactionStrategyHost.
  • Loop and ContextPreparation → historyRenderer.
  • Branch contextPreparation.prepare and validate share the native preparation and validation logic. ModelProvider validates the same request, and the Loop’s fixed-cutoff projection remains available to the Timeline consumer.

Final API

Caller / operation Contract
Loop → PrepareModelHost prepare({turnId, requestId, history, availableTools}) → ModelSettings, with pinned tool definitions in order.
ContextPreparation → PrepareContextHost prepare({request, source:{turnId, requestId, through}}, cancelled) → ModelRequest.
Context accounting and compaction → ContextModelHost describe(model facts) → {contextWindow, outputTokens, thresholdTokens, algorithm?}, count(request) → tokens, contributions({model, fixed?, messages}) → {algorithm, fixed?, messages}, estimate({model, algorithm, contribution}) → tokens.
Loop and ContextPreparation → CompactionStrategyHost describe(model facts) → {name, replacementSize}; compact(input, cancelled) → completed, skipped or failed with StrategyDiagnostics. Input carries history, checkpoint, request, legal cuts, trigger, budgets, prior diagnostics and model facts.
Loop and ContextPreparation → HistoryRenderer context({branchId, through}) → ContextHistory, renderedContext({branchId, through}) → {context, history: HistoryEntry[]}, snapshot({context, retainFrom, anchor}) → RecoverySnapshot, streamCheckpoint({branchId, through, retainFrom, batch}) → ProjectionCheckpoint, renderedStream({branchId, through, batch}) → StreamedContext, snapshotFromCheckpoint({checkpoint, anchor}) → RecoverySnapshot.
Loop and ModelProvider → ContextPreparation prepare({source: ContextPrepareData, projection?}, cancelled) → ModelRequest, validate({requestId, request}, cancelled) → void. Reuse the prepared projection at the original cutoff.
ContextPreparation and usage readers → ContextUsage read({through?}, cancelled) → {through, contextWindow, outputTokens, thresholdTokens, estimatedInputTokens, baselineSource}.

Acceptance

  • Verify replay, recovery snapshots, pinned tools, counting, cutoff, bounded reads and compaction results.
  • Confirm native and foreign calls use the same owner; verify relevant replies, errors, cancellation and unload. Update bindings, generated catalog and declarations where affected.
  • Resolve the current internal entries: prepareModelHost, prepareContextHost, contextModelHost, compactionStrategyHost, historyRenderer, contextPreparation, contextUsage.

Owner contract · Baseline catalog

@eric8810 eric8810 mentioned this pull request Nov 20, 2026
6 of 45 tasks
@eric8810
eric8810 changed the base branch from main to eric/1292-domain-loop-prompt November 20, 2026 15:35
…to impl-1912-context

# Conflicts:
#	crates/dim-agent-capabilities/src/context_preparation.rs
#	docs/architecture/rust-agent/generated/catalog.md
#	npm/branch-services.d.ts
@eric8810
eric8810 marked this pull request as ready for review November 21, 2026 16:23
@eric8810
eric8810 marked this pull request as draft November 21, 2026 16:56
@eric8810

Copy link
Copy Markdown
Collaborator Author

未完成所有者调查就开始的改动,关闭。后续按 #2015 的扫描结论重新设计,对应 #2025、#2027。分支保留,供重新设计时参考。

@eric8810 eric8810 closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant