@namzu/sdk 62.12.0 → 62.13.0
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/CHANGELOG.md +23 -0
- package/dist/connector/index.d.ts +1 -1
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +96 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +488 -13
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +1 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +1 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/tasks.d.ts +40 -0
- package/dist/connector/mcp/tasks.d.ts.map +1 -0
- package/dist/connector/mcp/tasks.js +55 -0
- package/dist/connector/mcp/tasks.js.map +1 -0
- package/dist/constants/mcp/index.d.ts +1 -1
- package/dist/constants/mcp/index.d.ts.map +1 -1
- package/dist/constants/mcp/index.js +5 -0
- package/dist/constants/mcp/index.js.map +1 -1
- package/dist/eval/bootstrap.d.ts +122 -0
- package/dist/eval/bootstrap.d.ts.map +1 -0
- package/dist/eval/bootstrap.js +227 -0
- package/dist/eval/bootstrap.js.map +1 -0
- package/dist/eval/compare.d.ts +109 -0
- package/dist/eval/compare.d.ts.map +1 -0
- package/dist/eval/compare.js +324 -0
- package/dist/eval/compare.js.map +1 -0
- package/dist/eval/disclosure.d.ts +70 -0
- package/dist/eval/disclosure.d.ts.map +1 -0
- package/dist/eval/disclosure.js +64 -0
- package/dist/eval/disclosure.js.map +1 -0
- package/dist/eval/experiment.d.ts +23 -0
- package/dist/eval/experiment.d.ts.map +1 -1
- package/dist/eval/experiment.js +87 -15
- package/dist/eval/experiment.js.map +1 -1
- package/dist/eval/from-turn.d.ts.map +1 -1
- package/dist/eval/from-turn.js +5 -0
- package/dist/eval/from-turn.js.map +1 -1
- package/dist/eval/index.d.ts +13 -2
- package/dist/eval/index.d.ts.map +1 -1
- package/dist/eval/index.js +6 -1
- package/dist/eval/index.js.map +1 -1
- package/dist/eval/report-stats.d.ts +77 -0
- package/dist/eval/report-stats.d.ts.map +1 -0
- package/dist/eval/report-stats.js +184 -0
- package/dist/eval/report-stats.js.map +1 -0
- package/dist/eval/run-options.d.ts +30 -0
- package/dist/eval/run-options.d.ts.map +1 -0
- package/dist/eval/run-options.js +20 -0
- package/dist/eval/run-options.js.map +1 -0
- package/dist/eval/run-summary.d.ts +36 -0
- package/dist/eval/run-summary.d.ts.map +1 -0
- package/dist/eval/run-summary.js +57 -0
- package/dist/eval/run-summary.js.map +1 -0
- package/dist/eval/scorers.d.ts +32 -0
- package/dist/eval/scorers.d.ts.map +1 -1
- package/dist/eval/scorers.js +77 -0
- package/dist/eval/scorers.js.map +1 -1
- package/dist/eval/types.d.ts +74 -0
- package/dist/eval/types.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts +3 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +18 -2
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +7 -2
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +3 -0
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +76 -5
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +15 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +18 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +80 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +18 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/turn/answer-claims.d.ts +52 -0
- package/dist/runtime/query/turn/answer-claims.d.ts.map +1 -0
- package/dist/runtime/query/turn/answer-claims.js +348 -0
- package/dist/runtime/query/turn/answer-claims.js.map +1 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts +7 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +13 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/store/goal/index.d.ts +3 -1
- package/dist/store/goal/index.d.ts.map +1 -1
- package/dist/store/goal/index.js +6 -0
- package/dist/store/goal/index.js.map +1 -1
- package/dist/telemetry/runtime-accessors.d.ts +14 -0
- package/dist/telemetry/runtime-accessors.d.ts.map +1 -1
- package/dist/telemetry/runtime-accessors.js +32 -0
- package/dist/telemetry/runtime-accessors.js.map +1 -1
- package/dist/tools/goal/confirmation.d.ts +154 -0
- package/dist/tools/goal/confirmation.d.ts.map +1 -0
- package/dist/tools/goal/confirmation.js +290 -0
- package/dist/tools/goal/confirmation.js.map +1 -0
- package/dist/tools/goal/index.d.ts +4 -1
- package/dist/tools/goal/index.d.ts.map +1 -1
- package/dist/tools/goal/index.js +27 -2
- package/dist/tools/goal/index.js.map +1 -1
- package/dist/tools/hand-back/index.d.ts +48 -0
- package/dist/tools/hand-back/index.d.ts.map +1 -0
- package/dist/tools/hand-back/index.js +129 -0
- package/dist/tools/hand-back/index.js.map +1 -0
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +15 -1
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +10 -0
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +18 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/goal/index.d.ts +12 -0
- package/dist/types/goal/index.d.ts.map +1 -1
- package/dist/types/session/config.d.ts +8 -0
- package/dist/types/session/config.d.ts.map +1 -1
- package/dist/types/session/hand-back.d.ts +29 -0
- package/dist/types/session/hand-back.d.ts.map +1 -0
- package/dist/types/session/hand-back.js +11 -0
- package/dist/types/session/hand-back.js.map +1 -0
- package/dist/types/session/outcome.d.ts +37 -0
- package/dist/types/session/outcome.d.ts.map +1 -1
- package/dist/types/session/outcome.js.map +1 -1
- package/dist/types/session/turn.d.ts +19 -1
- package/dist/types/session/turn.d.ts.map +1 -1
- package/dist/types/session/turn.js.map +1 -1
- package/package.json +1 -1
- package/src/connector/index.ts +1 -0
- package/src/connector/mcp/client.ts +531 -14
- package/src/connector/mcp/index.ts +1 -0
- package/src/connector/mcp/tasks.ts +81 -0
- package/src/constants/mcp/index.ts +6 -1
- package/src/eval/bootstrap.ts +314 -0
- package/src/eval/compare.ts +473 -0
- package/src/eval/disclosure.ts +136 -0
- package/src/eval/experiment.ts +127 -15
- package/src/eval/from-turn.ts +5 -0
- package/src/eval/index.ts +51 -0
- package/src/eval/report-stats.ts +257 -0
- package/src/eval/run-options.ts +49 -0
- package/src/eval/run-summary.ts +104 -0
- package/src/eval/scorers.ts +83 -0
- package/src/eval/types.ts +76 -0
- package/src/manager/session/turn-recorder.ts +23 -2
- package/src/public-runtime.ts +53 -0
- package/src/public-types.ts +9 -0
- package/src/registry/command/kernel-commands.ts +94 -6
- package/src/runtime/query/index.ts +18 -0
- package/src/runtime/query/iteration/index.ts +85 -1
- package/src/runtime/query/iteration/phases/tool-review.ts +24 -1
- package/src/runtime/query/turn/answer-claims.ts +413 -0
- package/src/runtime/query/turn/outcome-ledger.ts +12 -0
- package/src/store/goal/index.ts +11 -0
- package/src/telemetry/runtime-accessors.ts +29 -0
- package/src/tools/goal/confirmation.ts +375 -0
- package/src/tools/goal/index.ts +37 -1
- package/src/tools/hand-back/index.ts +150 -0
- package/src/tools/schedules/schedule-tool.ts +19 -1
- package/src/tools/schedules/types.ts +10 -0
- package/src/types/connector/mcp.ts +18 -0
- package/src/types/goal/index.ts +13 -0
- package/src/types/session/config.ts +8 -0
- package/src/types/session/hand-back.ts +31 -0
- package/src/types/session/outcome.ts +42 -0
- package/src/types/session/turn.ts +19 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { StaleGoalError } from '../../store/goal/index.js';
|
|
2
|
+
import { showCommand } from '../coordinator/outcome-record.js';
|
|
3
|
+
import { handBackKindSentence, handBackReason } from '../hand-back/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Ending a goal by the record of the work.
|
|
6
|
+
*
|
|
7
|
+
* Today the model's own report ends a goal. With `confirmedBy: 'record'` the
|
|
8
|
+
* kernel first reads the record it keeps of the work (`Turn.outcome`, built
|
|
9
|
+
* from what the tool calls did and never from what the model says) and the
|
|
10
|
+
* goal ends only as that record allows. There is no judge model and no model
|
|
11
|
+
* call beyond the turns themselves: the decision is a pure function over what
|
|
12
|
+
* the model reported, the record and the count of refusals so far.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Times the record may send a goal back to the model before the goal ends as
|
|
16
|
+
* not confirmed. Three: a first refusal normally costs one fix and one rerun of
|
|
17
|
+
* the check, a second covers a fix that did not hold, a third a check that
|
|
18
|
+
* needed a second look; past that the model is looping, and every further
|
|
19
|
+
* refusal costs a model call that has stopped moving the work. The limit is
|
|
20
|
+
* per goal and a host can set its own.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_GOAL_REFUSALS = 3;
|
|
23
|
+
/** The `reasonCode` that makes a `complete` report say that no check exists to run. */
|
|
24
|
+
export const NO_CHECK_REASON_CODE = 'no-check-available';
|
|
25
|
+
/** The record in plain words, without a lead and without a final stop. */
|
|
26
|
+
export function recordSentence(record) {
|
|
27
|
+
if (record === undefined)
|
|
28
|
+
return 'there is no record of this work';
|
|
29
|
+
const named = (command) => command === undefined ? 'a check' : (showCommand(command) ?? 'a command');
|
|
30
|
+
const passedCheck = [...record.checks].reverse().find((check) => check.result === 'passed');
|
|
31
|
+
switch (record.verdict) {
|
|
32
|
+
case 'checked':
|
|
33
|
+
return `${named(passedCheck?.command)} passed and nothing changed after it`;
|
|
34
|
+
case 'unchanged':
|
|
35
|
+
return passedCheck
|
|
36
|
+
? `${named(passedCheck.command)} passed and nothing changed`
|
|
37
|
+
: 'nothing changed and no check ran';
|
|
38
|
+
case 'stale':
|
|
39
|
+
return 'files changed after the last passing check';
|
|
40
|
+
case 'failing': {
|
|
41
|
+
const failed = record.checks.filter((check) => check.result === 'failed');
|
|
42
|
+
const more = failed.length > 1 ? ` (and ${failed.length - 1} more)` : '';
|
|
43
|
+
return `${named(failed[0]?.command)} failed${more}`;
|
|
44
|
+
}
|
|
45
|
+
case 'unchecked':
|
|
46
|
+
return 'files changed and no check ran';
|
|
47
|
+
case 'inconclusive': {
|
|
48
|
+
const masked = record.checks.find((check) => check.result === 'masked');
|
|
49
|
+
if (masked) {
|
|
50
|
+
const how = /(?<!\|)\|(?!\|)/.test(masked.command) ? 'the pipe' : 'the command line';
|
|
51
|
+
return `${named(masked.command)} ran, but ${how} hides whether it passed`;
|
|
52
|
+
}
|
|
53
|
+
const unsettled = record.checks.find((check) => check.result === 'unsettled');
|
|
54
|
+
if (unsettled)
|
|
55
|
+
return `${named(unsettled.command)} ran, but its result was not seen`;
|
|
56
|
+
return 'files changed and no check gave a result that could be read';
|
|
57
|
+
}
|
|
58
|
+
case 'unknown':
|
|
59
|
+
return 'a command ran that may have changed files, and nothing could tell whether it did';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const HOW_TO_SAY_SO = 'To say so, call update_goal with status "blocked" and the reason if the check cannot be made to pass, or with status "complete", reasonCode "no-check-available" and the reason if no check exists here.';
|
|
63
|
+
function refusalNote(record, earlierChanged) {
|
|
64
|
+
switch (record?.verdict) {
|
|
65
|
+
case 'failing':
|
|
66
|
+
return `The record says ${recordSentence(record)}. Fix what it reports and run it again, or say plainly that you could not make it pass. ${HOW_TO_SAY_SO}`;
|
|
67
|
+
case 'stale':
|
|
68
|
+
return `The record says ${recordSentence(record)}. Run the check again, or say plainly that you could not. ${HOW_TO_SAY_SO}`;
|
|
69
|
+
case 'unchecked':
|
|
70
|
+
return `The record says ${recordSentence(record)}. Run the project's check on the files as they are now, or say plainly that no check can be run here. ${HOW_TO_SAY_SO}`;
|
|
71
|
+
case 'inconclusive':
|
|
72
|
+
return `The record says ${recordSentence(record)}. Run the check again on its own so that its result can be read, or say plainly that you could not. ${HOW_TO_SAY_SO}`;
|
|
73
|
+
default:
|
|
74
|
+
return earlierChanged
|
|
75
|
+
? `The record of this round says ${recordSentence(record)}, and an earlier round of this goal changed files. Run the project's check on the files as they are now, or say plainly that you could not. ${HOW_TO_SAY_SO}`
|
|
76
|
+
: `The record says ${recordSentence(record)}. Run the check, or say plainly that you could not. ${HOW_TO_SAY_SO}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What to do with the model's report of a goal, given the record.
|
|
81
|
+
*
|
|
82
|
+
* - The model says it could not: the goal ends `not-confirmed`; it is never
|
|
83
|
+
* pushed again.
|
|
84
|
+
* - The model says no check exists: `stated-not-checked`, unless the record
|
|
85
|
+
* holds a failing or stale check (`not-confirmed`) or a passing one
|
|
86
|
+
* (`confirmed`).
|
|
87
|
+
* - The model says it is met: a passing check with nothing changed after it is
|
|
88
|
+
* `confirmed`; a failing check, files changed after the last pass, files
|
|
89
|
+
* changed and no check, or a check whose result could not be read are refused
|
|
90
|
+
* while refusals remain and `not-confirmed` once they do not; nothing
|
|
91
|
+
* changed, a command that may have changed files (`unknown`) or no record at
|
|
92
|
+
* all is `stated-not-checked`. `unknown` is not refused on purpose: the
|
|
93
|
+
* record keeps it for the whole turn, so no later check could clear it and a
|
|
94
|
+
* refusal would only cost calls until the bound.
|
|
95
|
+
*/
|
|
96
|
+
export function decideGoalConfirmation(input) {
|
|
97
|
+
const { statement, record, refusals, maxRefusals } = input;
|
|
98
|
+
const sentence = recordSentence(record);
|
|
99
|
+
if (statement === 'could-not')
|
|
100
|
+
return { kind: 'end', ending: 'not-confirmed', sentence };
|
|
101
|
+
const verdict = record?.verdict;
|
|
102
|
+
if (verdict === 'checked')
|
|
103
|
+
return { kind: 'end', ending: 'confirmed', sentence };
|
|
104
|
+
if (verdict === 'unchanged' &&
|
|
105
|
+
record?.checks.some((check) => check.result === 'passed' && check.fresh !== false)) {
|
|
106
|
+
return { kind: 'end', ending: 'confirmed', sentence };
|
|
107
|
+
}
|
|
108
|
+
const contradicted = verdict === 'failing' || verdict === 'stale';
|
|
109
|
+
if (statement === 'no-check') {
|
|
110
|
+
return contradicted
|
|
111
|
+
? { kind: 'end', ending: 'not-confirmed', sentence }
|
|
112
|
+
: { kind: 'end', ending: 'stated-not-checked', sentence };
|
|
113
|
+
}
|
|
114
|
+
const earlierChanged = input.earlierRoundsChanged === true;
|
|
115
|
+
const refusable = contradicted ||
|
|
116
|
+
verdict === 'unchecked' ||
|
|
117
|
+
verdict === 'inconclusive' ||
|
|
118
|
+
(verdict === 'unchanged' && earlierChanged);
|
|
119
|
+
if (!refusable)
|
|
120
|
+
return { kind: 'end', ending: 'stated-not-checked', sentence };
|
|
121
|
+
if (refusals >= Math.max(0, maxRefusals)) {
|
|
122
|
+
return { kind: 'end', ending: 'not-confirmed', sentence };
|
|
123
|
+
}
|
|
124
|
+
return { kind: 'refuse', sentence, note: refusalNote(record, earlierChanged) };
|
|
125
|
+
}
|
|
126
|
+
/** The closing line of a goal: which of the three endings it was and, always, what the record held. */
|
|
127
|
+
export function describeGoalEnding(report) {
|
|
128
|
+
if (report.handedBack) {
|
|
129
|
+
return `Goal not confirmed: the model handed the task back to a person (${report.sentence}).`;
|
|
130
|
+
}
|
|
131
|
+
switch (report.ending) {
|
|
132
|
+
case 'confirmed':
|
|
133
|
+
return `Goal confirmed by the record: ${report.sentence}.`;
|
|
134
|
+
case 'stated-not-checked':
|
|
135
|
+
return `Goal stated, not checked: the record cannot confirm it (${report.sentence}).`;
|
|
136
|
+
case 'not-confirmed':
|
|
137
|
+
return `Goal not confirmed: the record says ${report.sentence}.`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Holds, for one session, what the model reported this turn, how many times a
|
|
142
|
+
* goal was sent back, and whether an earlier round of it changed files. All of
|
|
143
|
+
* it lives in memory: a restart begins the count again, which is the cautious
|
|
144
|
+
* side of the bound only in that the model gets its refusals again.
|
|
145
|
+
*/
|
|
146
|
+
export class GoalConfirmation {
|
|
147
|
+
options;
|
|
148
|
+
claims = new Map();
|
|
149
|
+
refusals = new Map();
|
|
150
|
+
changed = new Set();
|
|
151
|
+
endings = new Map();
|
|
152
|
+
constructor(options) {
|
|
153
|
+
this.options = options;
|
|
154
|
+
}
|
|
155
|
+
/** What decides this goal: its own choice, else the host's setting, else the model. */
|
|
156
|
+
confirmedByFor(goal) {
|
|
157
|
+
return goal.confirmedBy ?? this.options.defaultConfirmedBy ?? 'model';
|
|
158
|
+
}
|
|
159
|
+
get maxRefusals() {
|
|
160
|
+
return this.options.maxRefusals ?? DEFAULT_GOAL_REFUSALS;
|
|
161
|
+
}
|
|
162
|
+
/** Refusals given to a goal so far. */
|
|
163
|
+
refusalsFor(goalId) {
|
|
164
|
+
return this.refusals.get(goalId) ?? 0;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The model reported on the goal in the round now running; the record is read
|
|
168
|
+
* when it finishes its answer. Held by goal, because only one round of a goal
|
|
169
|
+
* runs at a time and a round that ends without an answer leaves the goal
|
|
170
|
+
* active: the next report replaces this one.
|
|
171
|
+
*/
|
|
172
|
+
claim(goalId, statement, reason) {
|
|
173
|
+
this.claims.set(goalId, { statement, ...(reason !== undefined ? { reason } : {}) });
|
|
174
|
+
}
|
|
175
|
+
/** The ending the turn's goal came to, once; `undefined` when it did not end here. */
|
|
176
|
+
takeEnding(turnId) {
|
|
177
|
+
const ending = this.endings.get(turnId);
|
|
178
|
+
this.endings.delete(turnId);
|
|
179
|
+
return ending;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The model handed this round's task back to a person: the goal, when this
|
|
183
|
+
* turn is a round of an active one, ends as not confirmed and is left blocked
|
|
184
|
+
* with the reason, whatever it was confirmed by. Nothing for any other turn.
|
|
185
|
+
*/
|
|
186
|
+
async handBack(turnId, handBack) {
|
|
187
|
+
const authority = this.options.resolveAuthority(turnId);
|
|
188
|
+
if (!authority)
|
|
189
|
+
return undefined;
|
|
190
|
+
const goal = await this.options.store.getGoal(authority.sessionId, authority.tenantId);
|
|
191
|
+
if (!goal || goal.id !== authority.id || goal.phase !== 'active')
|
|
192
|
+
return undefined;
|
|
193
|
+
const ref = { id: authority.id, revision: authority.revision };
|
|
194
|
+
try {
|
|
195
|
+
await this.options.store.blockGoal(authority.sessionId, authority.tenantId, ref, {
|
|
196
|
+
code: 'handed-back-to-a-person',
|
|
197
|
+
message: handBackReason(handBack),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (error instanceof StaleGoalError)
|
|
202
|
+
return undefined;
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
const report = {
|
|
206
|
+
goalId: goal.id,
|
|
207
|
+
ending: 'not-confirmed',
|
|
208
|
+
sentence: handBackKindSentence(handBack.kind),
|
|
209
|
+
refusals: this.refusalsFor(goal.id),
|
|
210
|
+
handedBack: handBack,
|
|
211
|
+
};
|
|
212
|
+
this.claims.delete(goal.id);
|
|
213
|
+
this.refusals.delete(goal.id);
|
|
214
|
+
this.changed.delete(goal.id);
|
|
215
|
+
return report;
|
|
216
|
+
}
|
|
217
|
+
/** Drop a report that was never answered for, when its round ends without the turn finishing an answer. */
|
|
218
|
+
forget(goalId) {
|
|
219
|
+
this.claims.delete(goalId);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* For `TurnConfig.outcome.beforeEnd`: the note that sends the model back to
|
|
223
|
+
* the work, or `undefined` when the turn may end. A turn that is not a round
|
|
224
|
+
* of a goal confirmed by the record is never touched.
|
|
225
|
+
*/
|
|
226
|
+
beforeEnd(turnId) {
|
|
227
|
+
return async (read) => {
|
|
228
|
+
const authority = this.options.resolveAuthority(turnId);
|
|
229
|
+
if (!authority)
|
|
230
|
+
return undefined;
|
|
231
|
+
const goal = await this.options.store.getGoal(authority.sessionId, authority.tenantId);
|
|
232
|
+
if (!goal || goal.id !== authority.id || goal.phase !== 'active')
|
|
233
|
+
return undefined;
|
|
234
|
+
if (this.confirmedByFor(goal) !== 'record')
|
|
235
|
+
return undefined;
|
|
236
|
+
const record = await read();
|
|
237
|
+
const claim = this.claims.get(goal.id);
|
|
238
|
+
this.claims.delete(goal.id);
|
|
239
|
+
const changedHere = (record?.changes.total ?? 0) > 0 || record?.changes.outsideKnownTools;
|
|
240
|
+
if (!claim) {
|
|
241
|
+
if (changedHere)
|
|
242
|
+
this.changed.add(goal.id);
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
const decision = decideGoalConfirmation({
|
|
246
|
+
statement: claim.statement,
|
|
247
|
+
record,
|
|
248
|
+
refusals: this.refusalsFor(goal.id),
|
|
249
|
+
maxRefusals: this.maxRefusals,
|
|
250
|
+
earlierRoundsChanged: this.changed.has(goal.id),
|
|
251
|
+
});
|
|
252
|
+
if (changedHere)
|
|
253
|
+
this.changed.add(goal.id);
|
|
254
|
+
if (decision.kind === 'refuse') {
|
|
255
|
+
this.refusals.set(goal.id, this.refusalsFor(goal.id) + 1);
|
|
256
|
+
return decision.note;
|
|
257
|
+
}
|
|
258
|
+
const ref = { id: authority.id, revision: authority.revision };
|
|
259
|
+
try {
|
|
260
|
+
if (decision.ending === 'not-confirmed') {
|
|
261
|
+
const said = claim.reason ? ` The model said: ${claim.reason}` : '';
|
|
262
|
+
await this.options.store.blockGoal(authority.sessionId, authority.tenantId, ref, {
|
|
263
|
+
code: 'not-confirmed-by-record',
|
|
264
|
+
message: `The record says ${decision.sentence}.${said}`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
await this.options.store.completeGoal(authority.sessionId, authority.tenantId, ref);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
// The person changed the goal while the model was answering; what they
|
|
273
|
+
// did stands, and nothing is said about an ending that did not happen.
|
|
274
|
+
if (error instanceof StaleGoalError)
|
|
275
|
+
return undefined;
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
this.endings.set(turnId, {
|
|
279
|
+
goalId: goal.id,
|
|
280
|
+
ending: decision.ending,
|
|
281
|
+
sentence: decision.sentence,
|
|
282
|
+
refusals: this.refusalsFor(goal.id),
|
|
283
|
+
});
|
|
284
|
+
this.refusals.delete(goal.id);
|
|
285
|
+
this.changed.delete(goal.id);
|
|
286
|
+
return undefined;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.js","sourceRoot":"","sources":["../../../src/tools/goal/confirmation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAI1D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE5E;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAEtC,uFAAuF;AACvF,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAA;AAwCxD,0EAA0E;AAC1E,MAAM,UAAU,cAAc,CAAC,MAA+B;IAC7D,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,iCAAiC,CAAA;IAClE,MAA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AAuE;gBACvE,uEAAuE;gBACvE,IAAI,KAAK,YAAY,cAAc;oBAAE,OAAO,SAAS,CAAA;gBACrD,MAAM,KAAK,CAAA;YACZ,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;gBACxB,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;aACnC,CAAC,CAAA;YACF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC5B,OAAO,SAAS,CAAA;QACjB,CAAC,CAAA;IACF,CAAC;CACD"}
|
|
@@ -2,6 +2,7 @@ import { type SessionGoalStore } from '../../store/goal/index.js';
|
|
|
2
2
|
import type { GoalRoundAuthority } from '../../types/goal/index.js';
|
|
3
3
|
import type { TurnId } from '../../types/ids/index.js';
|
|
4
4
|
import type { ToolDefinition } from '../../types/tool/index.js';
|
|
5
|
+
import { type GoalConfirmation } from './confirmation.js';
|
|
5
6
|
export declare const SESSION_GOAL_TOOL_NAMES: readonly ["get_goal", "update_goal"];
|
|
6
7
|
export declare const MIN_GOAL_BLOCK_ROUND = 3;
|
|
7
8
|
/**
|
|
@@ -20,5 +21,7 @@ export declare class GoalRoundAuthorityError extends Error {
|
|
|
20
21
|
* Registration is not authorization. A host must also withhold these names
|
|
21
22
|
* from every non-goal provider request and executor allow-list.
|
|
22
23
|
*/
|
|
23
|
-
export declare function buildSessionGoalTools(store: SessionGoalStore, resolveAuthority: ResolveGoalRoundAuthority
|
|
24
|
+
export declare function buildSessionGoalTools(store: SessionGoalStore, resolveAuthority: ResolveGoalRoundAuthority, options?: {
|
|
25
|
+
readonly confirmation?: GoalConfirmation;
|
|
26
|
+
}): ToolDefinition[];
|
|
24
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/goal/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,KAAK,gBAAgB,EAAkB,MAAM,2BAA2B,CAAA;AACpG,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,2BAA2B,CAAA;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/goal/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,KAAK,gBAAgB,EAAkB,MAAM,2BAA2B,CAAA;AACpG,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,2BAA2B,CAAA;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE/D,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,mBAAmB,CAAA;AAE/E,eAAO,MAAM,uBAAuB,sCAAuC,CAAA;AAC3E,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAA;AAEjG,kFAAkF;AAClF,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,MAAM,EAAE,MAAM;CAI1B;AA2BD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,gBAAgB,EACvB,gBAAgB,EAAE,yBAAyB,EAC3C,OAAO,GAAE;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAA;CAAO,GACxD,cAAc,EAAE,CA0GlB"}
|
package/dist/tools/goal/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { GoalNotFoundError, StaleGoalError } from '../../store/goal/index.js';
|
|
3
3
|
import { defineTool } from '../defineTool.js';
|
|
4
|
+
import { NO_CHECK_REASON_CODE } from './confirmation.js';
|
|
4
5
|
export const SESSION_GOAL_TOOL_NAMES = ['get_goal', 'update_goal'];
|
|
5
6
|
export const MIN_GOAL_BLOCK_ROUND = 3;
|
|
6
7
|
/** A goal tool was reached outside the one turn whose admission authorized it. */
|
|
@@ -35,7 +36,7 @@ function authorityFor(resolveAuthority, turnId) {
|
|
|
35
36
|
* Registration is not authorization. A host must also withhold these names
|
|
36
37
|
* from every non-goal provider request and executor allow-list.
|
|
37
38
|
*/
|
|
38
|
-
export function buildSessionGoalTools(store, resolveAuthority) {
|
|
39
|
+
export function buildSessionGoalTools(store, resolveAuthority, options = {}) {
|
|
39
40
|
const getGoal = defineTool({
|
|
40
41
|
name: 'get_goal',
|
|
41
42
|
description: 'Read the exact completion goal and admitted-round budget that authorized this automatic turn.',
|
|
@@ -80,8 +81,32 @@ export function buildSessionGoalTools(store, resolveAuthority) {
|
|
|
80
81
|
concurrencySafe: false,
|
|
81
82
|
async execute({ status, reasonCode, reason }, context) {
|
|
82
83
|
const authority = authorityFor(resolveAuthority, context.turnId);
|
|
83
|
-
await currentGoal(store, authority);
|
|
84
|
+
const current = await currentGoal(store, authority);
|
|
84
85
|
const ref = { id: authority.id, revision: authority.revision };
|
|
86
|
+
const confirmation = options.confirmation;
|
|
87
|
+
if (confirmation && confirmation.confirmedByFor(current) === 'record') {
|
|
88
|
+
// The report is held until the model finishes its answer; the kernel then
|
|
89
|
+
// reads the record of the work and the goal ends as the record allows.
|
|
90
|
+
if (status === 'complete') {
|
|
91
|
+
confirmation.claim(authority.id, reasonCode === NO_CHECK_REASON_CODE ? 'no-check' : 'met', reason);
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
output: 'Completion reported. This goal is confirmed by the record: when you finish your answer the kernel reads the record of the work done, and the goal ends as that record allows. Give your final answer now.',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (authority.round < MIN_GOAL_BLOCK_ROUND &&
|
|
98
|
+
confirmation.refusalsFor(authority.id) === 0) {
|
|
99
|
+
throw new Error(`A goal cannot be marked blocked before admitted round ${MIN_GOAL_BLOCK_ROUND}, unless the record has already sent it back once; this is round ${authority.round}.`);
|
|
100
|
+
}
|
|
101
|
+
if (!reasonCode || !reason) {
|
|
102
|
+
throw new TypeError('Blocked goal updates require reasonCode and reason.');
|
|
103
|
+
}
|
|
104
|
+
confirmation.claim(authority.id, 'could-not', reason);
|
|
105
|
+
return {
|
|
106
|
+
success: true,
|
|
107
|
+
output: 'Reported as not met. The goal ends as not confirmed when you finish your answer, and the record of the work is shown with your reason. Give your final answer now.',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
85
110
|
if (status === 'complete') {
|
|
86
111
|
const goal = await store.completeGoal(authority.sessionId, authority.tenantId, ref);
|
|
87
112
|
return { success: true, output: 'Goal marked complete.', data: goal };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAyB,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAIpG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAyB,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAIpG,OAAO,EAAE,UAAU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from 'zod';
|
|
2
|
+
import type { HandBack, HandBackKind } from '../../types/session/hand-back.js';
|
|
3
|
+
import type { ToolDefinition } from '../../types/tool/index.js';
|
|
4
|
+
/** The name the model calls. */
|
|
5
|
+
export declare const HAND_BACK_TOOL_NAME = "hand_back_task";
|
|
6
|
+
/** Each of the three sentences is cut to this many characters when it is kept. */
|
|
7
|
+
export declare const HAND_BACK_MAX_CHARS = 800;
|
|
8
|
+
/** What the model is told when the setting is on. One place, added to the static prompt. */
|
|
9
|
+
export declare const HAND_BACK_GUIDANCE = "## Handing a task back\nIf the task cannot be done as specified, call `hand_back_task` instead of forcing a result: it ends the turn and tells a person what blocks you, what you tried and what they must decide or provide. Never weaken, skip, delete or special-case a check to make it pass; if the request and its checks cannot both hold, hand it back. Hand back only what you could not finish.";
|
|
10
|
+
/**
|
|
11
|
+
* What the tool answers when the hand-back was accepted. A saved conversation
|
|
12
|
+
* holds this receipt beside the call, so a reader can tell an accepted call
|
|
13
|
+
* (the turn ended there) from one that was refused.
|
|
14
|
+
*/
|
|
15
|
+
export declare const HAND_BACK_RECEIPT = "Handed back to a person.";
|
|
16
|
+
/** The id of the prompt contribution that carries {@link HAND_BACK_GUIDANCE}. */
|
|
17
|
+
export declare const HAND_BACK_GUIDANCE_CONTRIBUTION_ID = "namzu.hand-back";
|
|
18
|
+
export declare const HandBackInputSchema: z.ZodObject<{
|
|
19
|
+
kind: z.ZodEnum<{
|
|
20
|
+
decision: "decision";
|
|
21
|
+
missing: "missing";
|
|
22
|
+
conflict: "conflict";
|
|
23
|
+
}>;
|
|
24
|
+
blocker: z.ZodString;
|
|
25
|
+
tried: z.ZodString;
|
|
26
|
+
needed: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/**
|
|
29
|
+
* The hand-back a tool call's input holds, or `undefined` when it is not one.
|
|
30
|
+
* Never throws; text is stripped of control and bidirectional characters, whitespace-folded and clipped.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseHandBack(input: unknown): HandBack | undefined;
|
|
33
|
+
/** The kernel's own sentence for a kind; the model's words are never part of it. */
|
|
34
|
+
export declare function handBackKindSentence(kind: HandBackKind): string;
|
|
35
|
+
/** The closing line in the kernel's words: `The model handed the task back: <kind>.` */
|
|
36
|
+
export declare function describeHandBack(handBack: HandBack): string;
|
|
37
|
+
/**
|
|
38
|
+
* The model's three sentences, labelled as the model's, one per line. The
|
|
39
|
+
* labels are the kernel's; every value after a label is the model's own text.
|
|
40
|
+
*/
|
|
41
|
+
export declare function handBackModelLines(handBack: HandBack): readonly string[];
|
|
42
|
+
/** The one-line reason a goal or a scheduled run records. */
|
|
43
|
+
export declare function handBackReason(handBack: HandBack): string;
|
|
44
|
+
/** What a refused sibling call is told in the step that handed the task back. */
|
|
45
|
+
export declare const HAND_BACK_SIBLING_REFUSAL = "Not run: this step handed the task back to a person with hand_back_task, and the turn ends there.";
|
|
46
|
+
/** The tool. Offered only when `TurnConfig.handBack` is on. */
|
|
47
|
+
export declare function buildHandBackTool(): ToolDefinition;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/hand-back/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAG/D,gCAAgC;AAChC,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AAEnD,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,8YAC6V,CAAA;AAE5X;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,6BAA6B,CAAA;AAE3D,iFAAiF;AACjF,eAAO,MAAM,kCAAkC,oBAAoB,CAAA;AAInE,eAAO,MAAM,mBAAmB;;;;;;;;;iBAS9B,CAAA;AAgCF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAalE;AAQD,oFAAoF;AACpF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE/D;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAE3D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,MAAM,EAAE,CAMxE;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEzD;AAED,iFAAiF;AACjF,eAAO,MAAM,yBAAyB,sGAA8G,CAAA;AAEpJ,+DAA+D;AAC/D,wBAAgB,iBAAiB,IAAI,cAAc,CAwBlD"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineTool } from '../defineTool.js';
|
|
3
|
+
/** The name the model calls. */
|
|
4
|
+
export const HAND_BACK_TOOL_NAME = 'hand_back_task';
|
|
5
|
+
/** Each of the three sentences is cut to this many characters when it is kept. */
|
|
6
|
+
export const HAND_BACK_MAX_CHARS = 800;
|
|
7
|
+
/** What the model is told when the setting is on. One place, added to the static prompt. */
|
|
8
|
+
export const HAND_BACK_GUIDANCE = `## Handing a task back
|
|
9
|
+
If the task cannot be done as specified, call \`${HAND_BACK_TOOL_NAME}\` instead of forcing a result: it ends the turn and tells a person what blocks you, what you tried and what they must decide or provide. Never weaken, skip, delete or special-case a check to make it pass; if the request and its checks cannot both hold, hand it back. Hand back only what you could not finish.`;
|
|
10
|
+
/**
|
|
11
|
+
* What the tool answers when the hand-back was accepted. A saved conversation
|
|
12
|
+
* holds this receipt beside the call, so a reader can tell an accepted call
|
|
13
|
+
* (the turn ended there) from one that was refused.
|
|
14
|
+
*/
|
|
15
|
+
export const HAND_BACK_RECEIPT = 'Handed back to a person.';
|
|
16
|
+
/** The id of the prompt contribution that carries {@link HAND_BACK_GUIDANCE}. */
|
|
17
|
+
export const HAND_BACK_GUIDANCE_CONTRIBUTION_ID = 'namzu.hand-back';
|
|
18
|
+
const text = z.string().trim().min(1);
|
|
19
|
+
export const HandBackInputSchema = z.object({
|
|
20
|
+
kind: z
|
|
21
|
+
.enum(['conflict', 'missing', 'decision'])
|
|
22
|
+
.describe('conflict: request and checks disagree. missing: something needed is missing or not allowed. decision: the person must decide.'),
|
|
23
|
+
blocker: text.describe('What blocks you.'),
|
|
24
|
+
tried: text.describe('What you tried.'),
|
|
25
|
+
needed: text.describe('What a person has to decide or provide.'),
|
|
26
|
+
});
|
|
27
|
+
/** Control, invisible-format and bidirectional code points: none of them is text a person reads. */
|
|
28
|
+
const UNSHOWN = [
|
|
29
|
+
[0x0000, 0x001f],
|
|
30
|
+
[0x007f, 0x009f],
|
|
31
|
+
[0x00ad, 0x00ad],
|
|
32
|
+
[0x061c, 0x061c],
|
|
33
|
+
[0x180e, 0x180e],
|
|
34
|
+
[0x200b, 0x200f],
|
|
35
|
+
[0x2028, 0x202e],
|
|
36
|
+
[0x2060, 0x206f],
|
|
37
|
+
[0xfeff, 0xfeff],
|
|
38
|
+
[0xfff9, 0xfffb],
|
|
39
|
+
];
|
|
40
|
+
/** Whitespace-like controls become a space; every other unshown code point is dropped. */
|
|
41
|
+
const cleaned = (value) => {
|
|
42
|
+
let out = '';
|
|
43
|
+
for (const ch of value) {
|
|
44
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
45
|
+
if (code === 0x09 || code === 0x0a || code === 0x0d)
|
|
46
|
+
out += ' ';
|
|
47
|
+
else if (!UNSHOWN.some(([lo, hi]) => code >= lo && code <= hi))
|
|
48
|
+
out += ch;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
};
|
|
52
|
+
const clip = (value) => {
|
|
53
|
+
const flat = cleaned(value).replace(/\s+/g, ' ').trim();
|
|
54
|
+
return flat.length > HAND_BACK_MAX_CHARS ? `${flat.slice(0, HAND_BACK_MAX_CHARS - 1)}…` : flat;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The hand-back a tool call's input holds, or `undefined` when it is not one.
|
|
58
|
+
* Never throws; text is stripped of control and bidirectional characters, whitespace-folded and clipped.
|
|
59
|
+
*/
|
|
60
|
+
export function parseHandBack(input) {
|
|
61
|
+
let value = input;
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
try {
|
|
64
|
+
value = JSON.parse(value);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const parsed = HandBackInputSchema.safeParse(value);
|
|
71
|
+
if (!parsed.success)
|
|
72
|
+
return undefined;
|
|
73
|
+
const { kind, blocker, tried, needed } = parsed.data;
|
|
74
|
+
return { kind, blocker: clip(blocker), tried: clip(tried), needed: clip(needed) };
|
|
75
|
+
}
|
|
76
|
+
const KIND_SENTENCE = {
|
|
77
|
+
conflict: 'the request conflicts with itself or with its checks',
|
|
78
|
+
missing: 'something needed is missing or not allowed',
|
|
79
|
+
decision: 'a decision is needed that belongs to a person',
|
|
80
|
+
};
|
|
81
|
+
/** The kernel's own sentence for a kind; the model's words are never part of it. */
|
|
82
|
+
export function handBackKindSentence(kind) {
|
|
83
|
+
return KIND_SENTENCE[kind] ?? KIND_SENTENCE.decision;
|
|
84
|
+
}
|
|
85
|
+
/** The closing line in the kernel's words: `The model handed the task back: <kind>.` */
|
|
86
|
+
export function describeHandBack(handBack) {
|
|
87
|
+
return `The model handed the task back to a person: ${handBackKindSentence(handBack.kind)}.`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The model's three sentences, labelled as the model's, one per line. The
|
|
91
|
+
* labels are the kernel's; every value after a label is the model's own text.
|
|
92
|
+
*/
|
|
93
|
+
export function handBackModelLines(handBack) {
|
|
94
|
+
return [
|
|
95
|
+
`The model says it is blocked by: ${handBack.blocker}`,
|
|
96
|
+
`It tried: ${handBack.tried}`,
|
|
97
|
+
`It needs a person to: ${handBack.needed}`,
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
/** The one-line reason a goal or a scheduled run records. */
|
|
101
|
+
export function handBackReason(handBack) {
|
|
102
|
+
return `${describeHandBack(handBack).replace(/\.$/, '')}. The model said: ${handBack.blocker}`;
|
|
103
|
+
}
|
|
104
|
+
/** What a refused sibling call is told in the step that handed the task back. */
|
|
105
|
+
export const HAND_BACK_SIBLING_REFUSAL = `Not run: this step handed the task back to a person with ${HAND_BACK_TOOL_NAME}, and the turn ends there.`;
|
|
106
|
+
/** The tool. Offered only when `TurnConfig.handBack` is on. */
|
|
107
|
+
export function buildHandBackTool() {
|
|
108
|
+
return defineTool({
|
|
109
|
+
name: HAND_BACK_TOOL_NAME,
|
|
110
|
+
description: 'Hand the task back to a person when it cannot be done as specified. Ends the turn: nothing else runs after it.',
|
|
111
|
+
inputSchema: HandBackInputSchema,
|
|
112
|
+
category: 'custom',
|
|
113
|
+
permissions: [],
|
|
114
|
+
readOnly: true,
|
|
115
|
+
destructive: false,
|
|
116
|
+
concurrencySafe: false,
|
|
117
|
+
async execute(input) {
|
|
118
|
+
const handBack = parseHandBack(input);
|
|
119
|
+
if (!handBack)
|
|
120
|
+
throw new TypeError('The hand-back needs a kind, a blocker, what was tried and what is needed.');
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
output: `${HAND_BACK_RECEIPT} The turn ends now; nothing more will run and no further answer is needed.`,
|
|
124
|
+
data: handBack,
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/hand-back/index.ts"],"names":[],"mappings":"AAAA,OAAO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AO,EAAE,CAAA;AAC/F,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,MAAM,yBAAyB,GAAG,4DAA4D,mBAAmB,4BAA4B,CAAA;AAEpJ,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB;IAChC,OAAO,UAAU,CAAC;QACjB,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACV,gHAAgH;QACjH,WAAW,EAAE,mBAAmB;QAChC,QAAQ,EAAE,QAAQ;QAClB,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,KAAK;QACtB,KAAK,CAAC,OAAO,CAAC,KAAK;YAClB,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;YACrC,IAAI,CAAC,QAAQ;gBACZ,MAAM,IAAI,SAAS,CAClB,2EAA2E,CAC3E,CAAA;YACF,OAAO;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,GAAG,iBAAiB,4EAA4E;gBACxG,IAAI,EAAE,QAAQ;aACd,CAAA;QACF,CAAC;KACD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/schedules/schedule-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,cAAc,EAAc,MAAM,2BAA2B,CAAA;AAKxF,OAAO,KAAK,EAOX,gBAAgB,EAChB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,kBAAkB,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"schedule-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/schedules/schedule-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,cAAc,EAAc,MAAM,2BAA2B,CAAA;AAKxF,OAAO,KAAK,EAOX,gBAAgB,EAChB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,kBAAkB,aAAa,CAAA;AA8jB5C;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,cAAc,EAAE,CAkC3E"}
|