feat(web): declare the remaining context forms on every shipped producer
Four values complete the vocabulary, so the opaque body is reached only by producers that genuinely promise no shape. `snapshot` — current state a later snapshot supersedes. system-prompt now exposes `renderContextSections()`, the named contributions `renderContextSnapshot()` already joins for the model, so the body attributes each part to the subsystem that produced it instead of re-splitting joined prose. The runtime snapshot, time-context, and tmux-context declare it. `notice` — a one-off account of what just happened, declared by tool-tasks, goal state changes, tool-goal wrap-up, plan-mode switches, and repeat-tool-guard. Its `summary` rides the COLLAPSED row: these five are the majority of shipped producers and none of them needs expanding to be read. The task summary bounds itself because its inputs are unbounded caller text. `relay` — a message another agent addressed to this one; both subagent sources declare it and the body names the sender above what it said. `recall` — material lifted from another session's log. session-reference needed no new field: its references already record retained and omitted counts and the truncation flag, which the body shows first, because recalled context is bounded on the way in. `ContextFormed` is now discriminated by `form`, so a producer cannot declare a shape without the facts that shape is presented from — a notice without its summary, or a snapshot without its sections, fails to compile. Only the two hook bridges stay opaque, by design: their content is whatever an external program printed, so no shape can be promised for it. Unknown kinds and unreadable records land there too.
This commit is contained in:
@@ -61,6 +61,13 @@ export type GoalChangeMeta = GoalSnapshotChangeMeta | GoalClearChangeMeta
|
||||
/** Message attribution for durable goal state and continuation rounds. */
|
||||
export interface GoalMessageSource {
|
||||
readonly kind: 'goal'
|
||||
/**
|
||||
* Round-zero state changes are `notice`-form contexts; a continuation round
|
||||
* carries the objective forward as ordinary context and declares no form.
|
||||
*/
|
||||
readonly form?: 'notice'
|
||||
/** Present with `form`: one-line account of the mutation. */
|
||||
readonly summary?: string
|
||||
readonly goalId: GoalId
|
||||
readonly revision: number
|
||||
/** Zero for state changes; positive for admitted continuation rounds. */
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
goalChangeRef,
|
||||
} from './fold.ts'
|
||||
import type { GoalFoldState } from './fold.ts'
|
||||
import { renderGoalChange } from './render.ts'
|
||||
import { goalChangeSummary, renderGoalChange } from './render.ts'
|
||||
import {
|
||||
GOAL_CHANGE_VERSION,
|
||||
GoalError,
|
||||
@@ -568,7 +568,15 @@ export class GoalService extends Service {
|
||||
try {
|
||||
agent.inject(createUserMessage({
|
||||
content: renderGoalChange(change),
|
||||
source: { kind: 'goal', goalId: ref.id, revision: ref.revision, round: 0, change },
|
||||
source: {
|
||||
kind: 'goal',
|
||||
goalId: ref.id,
|
||||
revision: ref.revision,
|
||||
round: 0,
|
||||
change,
|
||||
form: 'notice',
|
||||
summary: goalChangeSummary(change),
|
||||
},
|
||||
}))
|
||||
} catch (error: unknown) {
|
||||
const index = cache.pending.indexOf(pending)
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
||||
import type { GoalChangeMeta } from './domain.ts'
|
||||
|
||||
/**
|
||||
* One-line account of a goal mutation for the `notice` form's collapsed row.
|
||||
* @param change - durable goal change carried by the message source.
|
||||
* @returns the operation and, for a surviving goal, its objective.
|
||||
*/
|
||||
export function goalChangeSummary(change: GoalChangeMeta): string {
|
||||
// The row header already names the producer, so the account does not repeat it.
|
||||
return change.operation === 'clear'
|
||||
? change.operation
|
||||
: `${change.operation}: ${change.goal.objective}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a complete goal snapshot or clear tombstone without hidden prose.
|
||||
* @param change - durable goal change carried by the message source.
|
||||
|
||||
@@ -315,7 +315,12 @@ export function apply(ctx: Context, config: Config): void {
|
||||
content: args.action === 'complete'
|
||||
? renderWrapupContext(goal.objective)
|
||||
: renderWrapupContext(goal.objective, args.blocked_reason as string),
|
||||
source: { kind: 'plugin', plugin: 'tool-goal' },
|
||||
source: {
|
||||
kind: 'plugin',
|
||||
plugin: 'tool-goal',
|
||||
form: 'notice',
|
||||
summary: `${args.action as string}: ${goal.objective}`,
|
||||
},
|
||||
}))
|
||||
}
|
||||
return Promise.resolve(goalValue(goal))
|
||||
|
||||
@@ -372,7 +372,12 @@ describe('goal tool state transitions', () => {
|
||||
expect(complete.concludesTurn).toBeUndefined()
|
||||
const contexts = complete.additionalContexts ?? []
|
||||
expect(contexts).toHaveLength(1)
|
||||
expect(contexts[0]?.source).toEqual({ kind: 'plugin', plugin: 'tool-goal' })
|
||||
expect(contexts[0]?.source).toEqual({
|
||||
kind: 'plugin',
|
||||
plugin: 'tool-goal',
|
||||
form: 'notice',
|
||||
summary: 'complete: pause cleanly',
|
||||
})
|
||||
const block = contexts[0]?.content[0]
|
||||
if (block?.type !== 'text') throw new Error('expected one text wrap-up block')
|
||||
expect(block.text).toContain('<goal_complete>')
|
||||
|
||||
Reference in New Issue
Block a user