@deepseek-ai/dsh-tool-goal 0.2.2-alpha.3 → 0.2.2-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.i18n.yaml CHANGED
@@ -30,8 +30,8 @@
30
30
  en: 4e9fdb5a89f4baa3
31
31
  zh: 50d182467ae1f3a7
32
32
  /deepseek-ai-dsh-tool-goal/understand-the-implementation/design:
33
- en: 1c51463a2abd9514
34
- zh: b02fbbd125d96bf6
33
+ en: 3e0735d353de2137
34
+ zh: 58b6fede85818840
35
35
  /deepseek-ai-dsh-tool-goal/understand-the-implementation/source-map:
36
36
  en: 4d5c648787409868
37
37
  zh: b4938bfe660f18aa
package/README.md CHANGED
@@ -68,7 +68,7 @@ This section explains how the tools enforce authority and render output; the obs
68
68
 
69
69
  ### Design
70
70
 
71
- - **Authority at execution.** The plugin requires `agents` and reads turn state through `turnBoundaryOf(session)`. Every call resolves the exact live agent, its inherited `AgentRegistry` initiator, running status, and an open turn; `create`, `edit`, `pause`, and `resume` additionally require an accepted `{ kind: 'user' }` message or steering event in a runtime-root agent's current turn. A durable paused goal fails the `resume` action with `GOAL_TOOL_RESUME_PAUSED`; the user-facing command or Web control owns that transition. Durable fork lineage does not demote a resumed root; live subagent ownership does.
71
+ - **Authority at execution.** The plugin requires `agents` and reads turn state through `turnBoundaryOf(session)`. Every call resolves the exact live agent, its inherited `AgentRegistry` initiator, running status, and an open turn; `create`, `edit`, `pause`, and `resume` additionally require an accepted `{ kind: 'user' }` message or steering event in a runtime-root agent's current turn. A durable paused goal fails the `resume` action with `GOAL_TOOL_RESUME_PAUSED`; the user-facing command or Web control owns that transition. A Session with `origin: 'subagent'` cannot supply direct-human authority; historical ordinary forks with `parentSession` remain eligible.
72
72
  - **Host attestation of human input.** `{ kind: 'user' }` is assigned by `Agent.followup()` and `steer()` when their caller omits a source, so plugins, schedulers, and other non-human producers must pass their own source rather than inheriting human authority.
73
73
  - **System-prompt guidance with the configured threshold.** The package registers one `tool:goal` system-prompt section whose fixed text interpolates `blockedAfterConsecutiveRounds`; the same value is the hard lower bound enforced at execution.
74
74
  - **Wrap-up context for terminal rounds.** A successful autonomous `complete` or `blocked` defers a closing `<goal_complete>` or `<goal_blocked>` instruction so the model addresses the user once before the turn ends; direct-human mutations never defer this context.
package/README.zh.md CHANGED
@@ -68,7 +68,7 @@ kind: "package-reference"
68
68
 
69
69
  ### 设计
70
70
 
71
- - **执行时权限。** 插件依赖 `agents`,并通过 `turnBoundaryOf(session)` 读取轮次状态。每次调用都解析精确活跃 agent、其继承的 `AgentRegistry` initiator、running 状态与开放轮次;`create`、`edit`、`pause` 和 `resume` 还要求运行时根 agent 的当前轮次中存在已接受的 `{ kind: 'user' }` 消息或 steering 事件。持久的 paused goal 会让 `resume` 以 `GOAL_TOOL_RESUME_PAUSED` 失败;面向用户的命令或 Web 控件拥有该转换。持久 fork 谱系不会降低已恢复根 agent 的等级;活跃 subagent 所有权会降低。
71
+ - **执行时权限。** 插件依赖 `agents`,并通过 `turnBoundaryOf(session)` 读取轮次状态。每次调用都解析精确活跃 agent、其继承的 `AgentRegistry` initiator、running 状态与开放轮次;`create`、`edit`、`pause` 和 `resume` 还要求运行时根 agent 的当前轮次中存在已接受的 `{ kind: 'user' }` 消息或 steering 事件。持久的 paused goal 会让 `resume` 以 `GOAL_TOOL_RESUME_PAUSED` 失败;面向用户的命令或 Web 控件拥有该转换。`origin: 'subagent'` 的 Session 不能提供直接人类权限;带有 `parentSession` 的历史普通 fork 仍可提供。
72
72
  - **人类输入的宿主证明。** `Agent.followup()` 与 `steer()` 会在调用方省略 source 时分配 `{ kind: 'user' }`,因此插件、调度器与其他非人类生产方必须传入自己的 source,不能继承人类权限。
73
73
  - **带配置阈值的系统提示词指引。** 本包注册一个 `tool:goal` 系统提示词章节,其固定文本插入 `blockedAfterConsecutiveRounds`;同一数值就是执行时强制执行的硬下限。
74
74
  - **终局 Round 的结束上下文。** 成功的自主 `complete` 或 `blocked` 会延后一条 `<goal_complete>` 或 `<goal_blocked>` 结束指令,让模型在轮次结束前向用户做一次交代;人类直接变更绝不会延后该上下文。
package/lib/index.js CHANGED
@@ -47,7 +47,7 @@ function someOpenTurnEvent(execution, predicate) {
47
47
  * producers must supply their own source rather than inheriting this authority.
48
48
  */
49
49
  function hasDirectHumanInput(ctx, execution) {
50
- if (!ctx.agents.roots().includes(execution.agent)) return false;
50
+ if (ctx.agents.get(execution.agent.id) !== execution.agent || execution.agent.session.header.origin === "subagent") return false;
51
51
  return someOpenTurnEvent(execution, (event) => event.type === "user/message" && event.data.source.kind === "user");
52
52
  }
53
53
  /** Whether this turn is the current goal's exact admitted round. */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../../src/authority.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,wGAAwG;AACxG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAA;IACxC,QAAQ,CAAC,gBAAgB,EAAE,UAAU,CAAA;CACtC;AAED,yDAAyD;AACzD,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GACjC;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAA;AAqB5D;;;;;GAKG;AACH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,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EACzG,OAAO,EACP,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC;YACvD,CAAC,CAAC,IAAI,CAAC,cAAc;YACrB,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;gBACjD,CAAC,CAAC,IAAI,CAAC,SAAS;gBAChB,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CACxG;KACF,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapup.d.ts","sourceRoot":"","sources":["../../src/wrapup.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAMxD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAwB7F"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapup.js","sourceRoot":"","sources":["../../src/wrapup.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAI/E,MAAM,SAAS,GACb,uFAAuF;MACrF,uEAAuE,CAAA;AAE3E;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB,EAAE,aAAsB;IAC3E,MAAM,OAAO,GAAG,cAAc,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAA;IAC3D,MAAM,IAAI,GAAG,aAAa,KAAK,SAAS;QACtC,CAAC,CAAC,mBAAmB;cACjB,OAAO;cACP,mFAAmF;cACnF,qFAAqF;cACrF,oFAAoF;cACpF,SAAS;cACT,qFAAqF;cACrF,wFAAwF;cACxF,kBAAkB;QACtB,CAAC,CAAC,kBAAkB;cAChB,OAAO;cACP,YAAY,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI;cAC7C,kFAAkF;cAClF,uFAAuF;cACvF,wFAAwF;cACxF,YAAY;cACZ,SAAS;cACT,kFAAkF;cAClF,0CAA0C;cAC1C,iBAAiB,CAAA;IACvB,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-tool-goal",
3
3
  "description": "Model-facing same-session goal tools with execution-time authority checks",
4
- "version": "0.2.2-alpha.3",
4
+ "version": "0.2.2-rc.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -25,34 +25,37 @@
25
25
  "files": [
26
26
  "locale/*.json",
27
27
  "lib/index.js",
28
- "lib/types/**/*.d.ts"
28
+ "lib/types/**/*.d.ts",
29
+ "lib/types/**/*.d.ts.map",
30
+ "lib/**/*.js.map",
31
+ "src"
29
32
  ],
30
33
  "license": "MIT",
31
34
  "peerDependencies": {
32
- "@deepseek-ai/dsh-agent": "0.2.2-alpha.3",
33
- "@deepseek-ai/dsh-goal": "0.2.2-alpha.3",
34
- "@deepseek-ai/dsh-llm": "0.2.2-alpha.3",
35
- "@deepseek-ai/dsh-session": "0.2.2-alpha.3",
36
- "@deepseek-ai/dsh-system-prompt": "0.2.2-alpha.3",
37
- "@deepseek-ai/dsh-tools": "0.2.2-alpha.3",
38
- "@deepseek-ai/cordis": "~4.0.6-alpha.2"
35
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.2",
36
+ "@deepseek-ai/dsh-goal": "0.2.2-rc.2",
37
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
38
+ "@deepseek-ai/dsh-session": "0.2.2-rc.2",
39
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
40
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
41
+ "@deepseek-ai/cordis": "~4.1.0"
39
42
  },
40
43
  "dependencies": {
41
- "@deepseek-ai/schemastery": "~3.18.6-alpha.2"
44
+ "@deepseek-ai/schemastery": "~3.19.0"
42
45
  },
43
46
  "devDependencies": {
44
- "@deepseek-ai/cordis-plugin-loader": "~1.0.7-alpha.2",
45
- "@deepseek-ai/dsh-agent": "0.2.2-alpha.3",
46
- "@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-alpha.3",
47
- "@deepseek-ai/dsh-agent-loop": "0.2.2-alpha.3",
48
- "@deepseek-ai/dsh-goal": "0.2.2-alpha.3",
49
- "@deepseek-ai/dsh-llm": "0.2.2-alpha.3",
50
- "@deepseek-ai/dsh-session": "0.2.2-alpha.3",
51
- "@deepseek-ai/dsh-system-prompt": "0.2.2-alpha.3",
52
- "@deepseek-ai/dsh-tool-executor-native": "0.2.2-alpha.3",
53
- "@deepseek-ai/dsh-tool-testkit": "0.2.2-alpha.3",
54
- "@deepseek-ai/dsh-tools": "0.2.2-alpha.3",
55
- "@deepseek-ai/cordis": "~4.0.6-alpha.2",
56
- "@deepseek-ai/dsh-session-projection": "0.2.2-alpha.3"
47
+ "@deepseek-ai/cordis-plugin-loader": "~1.1.0",
48
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.2",
49
+ "@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.2",
50
+ "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.2",
51
+ "@deepseek-ai/dsh-goal": "0.2.2-rc.2",
52
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
53
+ "@deepseek-ai/dsh-session": "0.2.2-rc.2",
54
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
55
+ "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.2",
56
+ "@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.2",
57
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
58
+ "@deepseek-ai/cordis": "~4.1.0",
59
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.2"
57
60
  }
58
61
  }
@@ -0,0 +1,117 @@
1
+ /** Execution-time authority checks for the model-facing goal tools. */
2
+
3
+ import type { Context } from '@deepseek-ai/cordis'
4
+ import type { Agent } from '@deepseek-ai/dsh-agent'
5
+ import type { GoalView } from '@deepseek-ai/dsh-goal'
6
+ import { HarnessError } from '@deepseek-ai/dsh-llm'
7
+ import type { SessionEvent, SessionSeq } from '@deepseek-ai/dsh-session'
8
+ import type { ToolRunContext } from '@deepseek-ai/dsh-tools'
9
+
10
+ /** The calling agent plus the immutable event cut and open-turn start seq used for authority checks. */
11
+ export interface GoalToolExecution {
12
+ readonly agent: Agent
13
+ readonly events: readonly SessionEvent[]
14
+ readonly openTurnStartSeq: SessionSeq
15
+ }
16
+
17
+ /** Hard authority granted to one state-changing call. */
18
+ export type GoalToolAuthority =
19
+ | { readonly kind: 'direct-human' }
20
+ | { readonly kind: 'goal-round'; readonly goal: GoalView }
21
+
22
+ /** Throw one structured tool-policy failure. */
23
+ function reject(message: string, code = 'GOAL_TOOL_AUTHORITY_REQUIRED'): never {
24
+ throw new HarnessError(message, code)
25
+ }
26
+
27
+ /** Resolve the immutable event cut and open-turn boundary without copying the turn suffix. */
28
+ function openTurnEvents(
29
+ ctx: Context,
30
+ agent: Agent,
31
+ ): Pick<GoalToolExecution, 'events' | 'openTurnStartSeq'> {
32
+ // oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
33
+ const events = agent.session.snapshotEvents()
34
+ const boundary = ctx.agents.turnBoundaryOf(agent.session)
35
+ if (boundary.openTurnStartSeq === null) {
36
+ reject('goal tools require an open model turn', 'GOAL_TOOL_DRIVER_REQUIRED')
37
+ }
38
+ return { events, openTurnStartSeq: boundary.openTurnStartSeq }
39
+ }
40
+
41
+ /**
42
+ * Resolve and authenticate the calling agent and its driver boundary.
43
+ * @param ctx - Context carrying the live agent registry.
44
+ * @param exec - Tool execution metadata supplied by the registry.
45
+ * @returns The authenticated agent, immutable event cut, and open-turn boundary.
46
+ */
47
+ export function goalToolExecution(ctx: Context, exec: ToolRunContext): GoalToolExecution {
48
+ const agent = exec.agent
49
+ if (agent === undefined) {
50
+ return reject('goal tools require a calling agent', 'GOAL_TOOL_AGENT_REQUIRED')
51
+ }
52
+ if (ctx.agents.get(agent.id) !== agent || agent.status !== 'running'
53
+ || ctx.agents.currentInitiator() !== agent) {
54
+ return reject(
55
+ 'goal tools require the exact live calling agent inside its active driver',
56
+ 'GOAL_TOOL_DRIVER_REQUIRED',
57
+ )
58
+ }
59
+ return { agent, ...openTurnEvents(ctx, agent) }
60
+ }
61
+
62
+ /** Whether the captured open turn contains an event accepted by `predicate`. */
63
+ function someOpenTurnEvent(
64
+ execution: GoalToolExecution,
65
+ predicate: (event: SessionEvent) => boolean,
66
+ ): boolean {
67
+ for (let seq = execution.openTurnStartSeq + 1; seq < execution.events.length; seq += 1) {
68
+ const event = execution.events[seq]
69
+ if (event !== undefined && predicate(event)) return true
70
+ }
71
+ return false
72
+ }
73
+
74
+ /**
75
+ * Whether host-attested human input appears in the current root-agent turn.
76
+ * An omitted `Agent.followup()` / `steer()` source resolves to `user`, so non-human
77
+ * producers must supply their own source rather than inheriting this authority.
78
+ */
79
+ function hasDirectHumanInput(ctx: Context, execution: GoalToolExecution): boolean {
80
+ if (ctx.agents.get(execution.agent.id) !== execution.agent || execution.agent.session.header.origin === 'subagent') return false
81
+ return someOpenTurnEvent(execution, event =>
82
+ event.type === 'user/message' && event.data.source.kind === 'user')
83
+ }
84
+
85
+ /** Whether this turn is the current goal's exact admitted round. */
86
+ function isMatchingGoalRound(execution: GoalToolExecution, goal: GoalView): boolean {
87
+ return someOpenTurnEvent(execution, event => event.type === 'user/message'
88
+ && event.data.source.kind === 'goal'
89
+ && event.data.source.goalId === goal.id
90
+ && event.data.source.revision === goal.revision
91
+ && event.data.source.round === goal.roundsStarted)
92
+ }
93
+
94
+ /**
95
+ * Require authority originating in a human message accepted by a runtime root.
96
+ * @param ctx - Context carrying the live agent graph.
97
+ * @param execution - Authenticated current tool execution.
98
+ */
99
+ export function requireDirectHuman(ctx: Context, execution: GoalToolExecution): void {
100
+ if (hasDirectHumanInput(ctx, execution)) return
101
+ reject('this goal operation requires a direct human turn on a top-level agent')
102
+ }
103
+
104
+ /**
105
+ * Resolve completion authority from either direct human input or the exact goal round.
106
+ * @param ctx - Context carrying live agents and goal state.
107
+ * @param execution - Authenticated current tool execution.
108
+ * @returns The direct-human or exact-goal-round authority grant.
109
+ */
110
+ export function completionAuthority(ctx: Context, execution: GoalToolExecution): GoalToolAuthority {
111
+ if (hasDirectHumanInput(ctx, execution)) return { kind: 'direct-human' }
112
+ const goal = ctx.goals.get(execution.agent)
113
+ if (goal !== undefined && isMatchingGoalRound(execution, goal)) {
114
+ return { kind: 'goal-round', goal }
115
+ }
116
+ return reject('complete and blocked require a direct human turn or the current goal round')
117
+ }
package/src/index.ts ADDED
@@ -0,0 +1,324 @@
1
+ /**
2
+ * Model-facing `get_goal`, `create_goal`, and `update_goal` tools over the
3
+ * persisted same-session goal domain.
4
+ * @module @deepseek-ai/dsh-tool-goal
5
+ */
6
+
7
+ import type { Context } from '@deepseek-ai/cordis'
8
+ import z from '@deepseek-ai/schemastery'
9
+ import { GoalId } from '@deepseek-ai/dsh-goal'
10
+ import type { GoalRef, GoalView } from '@deepseek-ai/dsh-goal'
11
+ import { boundContextSummary, createUserMessage, HarnessError } from '@deepseek-ai/dsh-llm'
12
+ import type { ContextFormed } from '@deepseek-ai/dsh-llm'
13
+ declare module '@deepseek-ai/dsh-llm' {
14
+ interface MessageSourceMap {
15
+ 'tool-goal': { kind: 'tool-goal' } & ContextFormed
16
+ }
17
+ }
18
+
19
+ import { defineTool } from '@deepseek-ai/dsh-tools'
20
+ import type { GenericCallView } from '@deepseek-ai/dsh-tools'
21
+ import {
22
+ completionAuthority,
23
+ goalToolExecution,
24
+ requireDirectHuman,
25
+ } from './authority.ts'
26
+ import { renderWrapupContext } from './wrapup.ts'
27
+
28
+ export const name = 'tool-goal'
29
+ export const inject = ['agents', 'goals', 'tools', 'systemPrompt']
30
+
31
+ /** Model policy and hard lower bounds for goal-state updates. */
32
+ export interface Config {
33
+ /** Minimum admitted goal rounds before the model may self-report `blocked`. */
34
+ blockedAfterConsecutiveRounds?: number
35
+ }
36
+
37
+ /** Schemastery config for the goal-tool policy. */
38
+ export const Config: z<Config> = z.object({
39
+ blockedAfterConsecutiveRounds: z.number().step(1).min(1).default(3),
40
+ })
41
+
42
+ /** Fully materialized tool policy. */
43
+ interface ResolvedConfig {
44
+ readonly blockedAfterConsecutiveRounds: number
45
+ }
46
+
47
+ type UpdateAction = 'edit' | 'pause' | 'resume' | 'complete' | 'blocked'
48
+
49
+ const UPDATE_ACTIONS: UpdateAction[] = ['edit', 'pause', 'resume', 'complete', 'blocked']
50
+
51
+ const CREATE_DESCRIPTION =
52
+ 'Create a persisted goal that keeps this session working across automatic continuation rounds. '
53
+ + 'Use it when the direct human request is a long-running objective, even if the user did not say "goal"; '
54
+ + 'not for single-turn work.'
55
+
56
+ const GET_DESCRIPTION = 'Read the current session goal, including the id and revision that update_goal requires.'
57
+
58
+ /** Canonical goal-tool output, matching the existing compact Native JSON. */
59
+ type GoalToolValue =
60
+ | { goal: null }
61
+ | {
62
+ goal: {
63
+ id: string
64
+ revision: number
65
+ objective: string
66
+ phase: GoalView['phase']
67
+ roundsStarted: number
68
+ maxGoalRounds: number
69
+ blockedReason?: { code: string; message: string }
70
+ }
71
+ activation: GoalView['activation']
72
+ }
73
+
74
+ const GOAL_VALUE_SCHEMA = {
75
+ oneOf: [
76
+ {
77
+ type: 'object',
78
+ additionalProperties: false,
79
+ properties: {
80
+ goal: { type: 'null', required: true },
81
+ },
82
+ },
83
+ {
84
+ type: 'object',
85
+ additionalProperties: false,
86
+ properties: {
87
+ goal: {
88
+ type: 'object',
89
+ additionalProperties: false,
90
+ required: true,
91
+ properties: {
92
+ id: { type: 'string', required: true },
93
+ revision: { type: 'integer', required: true },
94
+ objective: { type: 'string', required: true },
95
+ phase: { type: 'string', required: true, enum: ['active', 'paused', 'blocked', 'complete'] },
96
+ roundsStarted: { type: 'integer', required: true },
97
+ maxGoalRounds: { type: 'integer', required: true },
98
+ blockedReason: {
99
+ type: 'object',
100
+ additionalProperties: false,
101
+ properties: {
102
+ code: { type: 'string', required: true },
103
+ message: { type: 'string', required: true },
104
+ },
105
+ },
106
+ },
107
+ },
108
+ activation: { type: 'string', required: true, enum: ['armed', 'disarmed'] },
109
+ },
110
+ },
111
+ ],
112
+ } as const
113
+
114
+ /** Render policy guidance with its deployment-selected blocked threshold. */
115
+ function guidance(blockedAfter: number): string {
116
+ return 'create_goal may infer goal intent from a direct human request in any language. '
117
+ + 'After session resume or fork, an active goal is disarmed: when '
118
+ + 'a human asks to continue or resume in any wording or language, use update_goal action '
119
+ + 'resume to rearm it. Mark complete only when the objective is actually achieved. Mark '
120
+ + `blocked only after the same blocking condition persists for at least ${blockedAfter} `
121
+ + 'consecutive goal rounds, and report that concrete condition in blocked_reason; difficulty, uncertainty, '
122
+ + 'or useful remaining work is not blocked.'
123
+ }
124
+
125
+ /** Validate config even when apply is called directly outside Loader normalization. */
126
+ function resolveConfig(config: Config): ResolvedConfig {
127
+ const blockedAfter = config.blockedAfterConsecutiveRounds ?? 3
128
+ if (!Number.isSafeInteger(blockedAfter) || blockedAfter < 1) {
129
+ throw new TypeError('blockedAfterConsecutiveRounds must be a positive safe integer')
130
+ }
131
+ return { blockedAfterConsecutiveRounds: blockedAfter }
132
+ }
133
+
134
+ /** Whether optional text is meaningful rather than a strict-schema empty filler. */
135
+ function hasText(value: string | undefined): value is string {
136
+ return value !== undefined && value !== ''
137
+ }
138
+
139
+ /** Whether an optional round cap is meaningful rather than a strict-schema zero filler. */
140
+ function hasRoundCap(value: number | undefined): value is number {
141
+ return value !== undefined && value !== 0
142
+ }
143
+
144
+ /** Build the exact compare-and-set ref from model arguments. */
145
+ function goalRef(goalId: string, revision: number): GoalRef {
146
+ if (goalId.length === 0 || goalId !== goalId.trim()
147
+ || !Number.isSafeInteger(revision) || revision < 1) {
148
+ throw new HarnessError(
149
+ 'goal_id must be non-empty and revision must be a positive safe integer',
150
+ 'GOAL_TOOL_INVALID_UPDATE',
151
+ )
152
+ }
153
+ return { id: GoalId(goalId), revision }
154
+ }
155
+
156
+ /** Stable compact model result; activation is an observation, not replay state. */
157
+ function goalValue(goal: GoalView | undefined): GoalToolValue {
158
+ if (goal === undefined) return { goal: null }
159
+ return {
160
+ goal: {
161
+ id: goal.id,
162
+ revision: goal.revision,
163
+ objective: goal.objective,
164
+ phase: goal.phase,
165
+ roundsStarted: goal.roundsStarted,
166
+ maxGoalRounds: goal.maxGoalRounds,
167
+ ...goal.blockedReason === undefined ? {} : {
168
+ blockedReason: { code: goal.blockedReason.code, message: goal.blockedReason.message },
169
+ },
170
+ },
171
+ activation: goal.activation,
172
+ }
173
+ }
174
+
175
+ /** Reusable canonical output declaration for all three goal controls. */
176
+ const GOAL_OUTPUT = {
177
+ schema: GOAL_VALUE_SCHEMA,
178
+ render: (_args: unknown, value: GoalToolValue) => [{ type: 'text' as const, text: JSON.stringify(value) }],
179
+ }
180
+
181
+ /** Generic, args-only pending presentation shared by the goal tools. */
182
+ function present(title: string, kind: 'read' | 'other', rawInput?: unknown): GenericCallView {
183
+ return { card: 'generic', title, kind, ...rawInput === undefined ? {} : { rawInput } }
184
+ }
185
+
186
+ /** Register the three Codex-shaped goal tools and their shared policy section. */
187
+ export function apply(ctx: Context, config: Config): void {
188
+ const resolved = resolveConfig(config)
189
+ ctx.systemPrompt.section({
190
+ name: 'tool:goal',
191
+ order: ctx.systemPrompt.getSectionOrder('TOOL_GOAL'),
192
+ text: guidance(resolved.blockedAfterConsecutiveRounds),
193
+ })
194
+
195
+ ctx.tools.register(defineTool({
196
+ name: 'get_goal',
197
+ description: GET_DESCRIPTION,
198
+ parameters: {},
199
+ output: GOAL_OUTPUT,
200
+ execute(_args, exec) {
201
+ const execution = goalToolExecution(ctx, exec)
202
+ return Promise.resolve(goalValue(ctx.goals.get(execution.agent)))
203
+ },
204
+ presentCall: () => present('Read current goal', 'read'),
205
+ }))
206
+
207
+ ctx.tools.register(defineTool({
208
+ name: 'create_goal',
209
+ description: CREATE_DESCRIPTION,
210
+ parameters: {
211
+ objective: {
212
+ type: 'string',
213
+ required: true,
214
+ description: 'The concrete completion objective inferred from the direct human request.',
215
+ },
216
+ max_goal_rounds: {
217
+ type: 'number',
218
+ description: 'Optional positive safe-integer limit on automatic continuation rounds.',
219
+ },
220
+ },
221
+ output: GOAL_OUTPUT,
222
+ execute(args, exec) {
223
+ const execution = goalToolExecution(ctx, exec)
224
+ requireDirectHuman(ctx, execution)
225
+ const goal = ctx.goals.create(execution.agent, {
226
+ objective: args.objective,
227
+ ...args.max_goal_rounds === undefined ? {} : { maxGoalRounds: args.max_goal_rounds },
228
+ })
229
+ return Promise.resolve(goalValue(goal))
230
+ },
231
+ presentCall: args => present('Create goal', 'other', args.objective),
232
+ }))
233
+
234
+ ctx.tools.register(defineTool({
235
+ name: 'update_goal',
236
+ description: 'Update the current goal.',
237
+ parameters: {
238
+ goal_id: { type: 'string', required: true, description: 'Exact id returned by get_goal.' },
239
+ revision: { type: 'number', required: true, description: 'Exact positive revision returned by get_goal.' },
240
+ action: {
241
+ type: 'string',
242
+ required: true,
243
+ enum: UPDATE_ACTIONS,
244
+ description: 'edit, pause, and resume require a direct top-level human request. complete and blocked are also allowed '
245
+ + 'during an automatic continuation of this goal; blocked is rejected before the configured minimum round count.',
246
+ },
247
+ objective: { type: 'string', description: 'Replacement objective; valid only with action edit.' },
248
+ max_goal_rounds: { type: 'number', description: 'Replacement cap; valid only with action edit.' },
249
+ blocked_reason: {
250
+ type: 'string',
251
+ description: 'Required only with action blocked: the concrete condition that persisted across rounds and blocks progress.',
252
+ },
253
+ },
254
+ output: GOAL_OUTPUT,
255
+ execute(args, exec) {
256
+ const execution = goalToolExecution(ctx, exec)
257
+ const ref = goalRef(args.goal_id, args.revision)
258
+ if (args.action === 'edit') {
259
+ requireDirectHuman(ctx, execution)
260
+ const goal = ctx.goals.edit(execution.agent, ref, {
261
+ ...hasText(args.objective) ? { objective: args.objective } : {},
262
+ ...hasRoundCap(args.max_goal_rounds) ? { maxGoalRounds: args.max_goal_rounds } : {},
263
+ })
264
+ return Promise.resolve(goalValue(goal))
265
+ }
266
+ if (args.action === 'pause' || args.action === 'resume') {
267
+ requireDirectHuman(ctx, execution)
268
+ const current = ctx.goals.get(execution.agent)
269
+ if (args.action === 'resume' && current?.id === ref.id && current.revision === ref.revision
270
+ && current.phase === 'paused') {
271
+ throw new HarnessError(
272
+ 'the model cannot resume a paused goal; the user must resume it',
273
+ 'GOAL_TOOL_RESUME_PAUSED',
274
+ )
275
+ }
276
+ const goal = args.action === 'pause'
277
+ ? ctx.goals.pause(execution.agent, ref)
278
+ : ctx.goals.resume(execution.agent, ref)
279
+ return Promise.resolve(goalValue(goal))
280
+ }
281
+ const authority = completionAuthority(ctx, execution)
282
+ if (args.action === 'blocked'
283
+ && (args.blocked_reason === undefined || args.blocked_reason.trim().length === 0)) {
284
+ throw new HarnessError('blocked_reason is required with action blocked', 'GOAL_TOOL_INVALID_UPDATE')
285
+ }
286
+ if (args.action === 'blocked' && authority.kind === 'goal-round'
287
+ && authority.goal.roundsStarted < resolved.blockedAfterConsecutiveRounds) {
288
+ throw new HarnessError(
289
+ `blocked requires at least ${resolved.blockedAfterConsecutiveRounds} consecutive goal rounds; `
290
+ + `current round is ${authority.goal.roundsStarted}`,
291
+ 'GOAL_TOOL_BLOCK_THRESHOLD',
292
+ )
293
+ }
294
+ const goal = args.action === 'complete'
295
+ ? ctx.goals.complete(execution.agent, ref)
296
+ : ctx.goals.block(execution.agent, ref, {
297
+ code: 'model-reported',
298
+ message: args.blocked_reason as string,
299
+ })
300
+ if (authority.kind === 'goal-round') {
301
+ exec.deferContext(createUserMessage({
302
+ content: args.action === 'complete'
303
+ ? renderWrapupContext(goal.objective)
304
+ : renderWrapupContext(goal.objective, args.blocked_reason as string),
305
+ source: {
306
+ kind: 'tool-goal',
307
+ form: 'notice',
308
+ summary: boundContextSummary(`${args.action as string}: ${goal.objective}`),
309
+ },
310
+ }))
311
+ }
312
+ return Promise.resolve(goalValue(goal))
313
+ },
314
+ presentCall: args => present(
315
+ `${args.action === 'blocked' ? 'Mark' : args.action.charAt(0).toUpperCase() + args.action.slice(1)} goal`,
316
+ 'other',
317
+ args.action === 'blocked' && hasText(args.blocked_reason)
318
+ ? args.blocked_reason
319
+ : args.action === 'edit' && hasText(args.objective)
320
+ ? args.objective
321
+ : args.action === 'edit' && hasRoundCap(args.max_goal_rounds) ? args.max_goal_rounds : args.goal_id,
322
+ ),
323
+ }))
324
+ }
package/src/wrapup.ts ADDED
@@ -0,0 +1,41 @@
1
+ /** Model-visible wrap-up instruction for a terminal autonomous goal update. */
2
+
3
+ import type { ContentBlock } from '@deepseek-ai/dsh-llm'
4
+
5
+ const GROUNDING =
6
+ 'Report only what earlier rounds and tool results in this session actually establish; '
7
+ + 'when a detail is not in the session, say so instead of inventing it. '
8
+
9
+ /**
10
+ * Render the closing-message instruction injected after an autonomous goal
11
+ * round reports `complete` or `blocked`, replacing the former hard turn stop
12
+ * so the model still addresses the user once before the turn ends.
13
+ * @param objective - the terminal goal's objective, echoed for grounding.
14
+ * @param blockedReason - the validated report for `blocked`; omitted for `complete`.
15
+ * @returns a fresh one-block context for `ToolRunContext.deferContext()`.
16
+ */
17
+ export function renderWrapupContext(objective: string, blockedReason?: string): ContentBlock[] {
18
+ const heading = `Objective: ${JSON.stringify(objective)}\n`
19
+ const text = blockedReason === undefined
20
+ ? '<goal_complete>\n'
21
+ + heading
22
+ + 'The goal is marked complete and this autonomous run is ending. Write the closing '
23
+ + 'message to the user now: state the outcome, summarize what was done and how it was '
24
+ + 'verified, and point to the concrete results (files, commits, or other artifacts). '
25
+ + GROUNDING
26
+ + 'Note anything the user should review or do next. Address the user directly. Do not '
27
+ + "call any more tools in this run; further work waits for the user's next instruction.\n"
28
+ + '</goal_complete>'
29
+ : '<goal_blocked>\n'
30
+ + heading
31
+ + `Blocked: ${JSON.stringify(blockedReason)}\n`
32
+ + 'The goal is marked blocked and this autonomous run is ending. Write the closing '
33
+ + 'message to the user now: state what has been completed so far, describe the concrete '
34
+ + 'blocking condition and what you tried, and say exactly what you need from the user to '
35
+ + 'continue. '
36
+ + GROUNDING
37
+ + 'Address the user directly. Do not call any more tools in this run; further work '
38
+ + "waits for the user's next instruction.\n"
39
+ + '</goal_blocked>'
40
+ return [{ type: 'text', text }]
41
+ }