@qvac/harness 1.0.0-rc.12 → 1.0.0-rc.14
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 +29 -0
- package/README.md +3 -1
- package/dist-lib/index.js +0 -1
- package/dist-lib/lib/agent/follow.js +9 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +13 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +21 -12
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +19 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +11 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +16 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +8 -2
- package/dist-lib/lib/capabilities/completion-engine/driver.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.js +39 -23
- package/dist-lib/lib/capabilities/completion-engine/event-mailbox.d.ts +20 -0
- package/dist-lib/lib/capabilities/completion-engine/event-mailbox.js +110 -0
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +40 -20
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +3 -3
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +16 -0
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +2 -0
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +17 -2
- package/dist-lib/lib/capabilities/tool-turns.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-turns.js +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- package/dist-lib/lib/connect.js +4 -2
- package/dist-lib/lib/contract/completion.d.ts +2 -1
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/fold/index.d.ts +3 -2
- package/dist-lib/lib/fold/index.js +7 -6
- package/dist-lib/lib/helpers/goal-check.d.ts +12 -0
- package/dist-lib/lib/helpers/goal-check.js +89 -7
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/input-budget.d.ts +8 -0
- package/dist-lib/lib/helpers/input-budget.js +9 -0
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +1 -1
- package/dist-lib/lib/machine/completion/actions/completion.js +34 -14
- package/dist-lib/lib/machine/completion/actions/tools.js +19 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -0
- package/dist-lib/lib/machine/completion/rules.js +14 -5
- package/dist-lib/lib/machine/completion/types.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.d.ts +1 -0
- package/dist-lib/lib/plugins/registry.js +49 -10
- package/dist-lib/lib/residency/index.js +2 -0
- package/dist-lib/lib/serve.js +56 -15
- package/dist-lib/lib/tools/files/glob.js +2 -2
- package/dist-lib/lib/tools/files/read-file.js +134 -15
- package/dist-lib/lib/tools/fs/walk.d.ts +1 -0
- package/dist-lib/lib/tools/fs/walk.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +11 -2
- package/dist-lib/lib/tools/http-request.js +28 -11
- package/dist-lib/lib/tools/office.d.ts +1 -1
- package/dist-lib/lib/tools/office.js +34 -12
- package/dist-lib/lib/wire.js +23 -3
- package/dist-lib/plugins/knowledge/index.d.ts +3 -0
- package/dist-lib/plugins/knowledge/index.js +5 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
- package/dist-lib/plugins/knowledge/manifest.js +86 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +45 -8
- package/dist-lib/plugins/knowledge/store.js +428 -166
- package/dist-lib/plugins/mcp/call.js +10 -3
- package/dist-lib/plugins/mcp/protocol.d.ts +4 -1
- package/dist-lib/plugins/mcp/protocol.js +11 -10
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.js +2 -2
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/python/index.d.ts +3 -1
- package/dist-lib/plugins/python/index.js +4 -1
- package/dist-lib/plugins/python/language.js +2 -2
- package/dist-lib/plugins/python/python-adapter.d.ts +2 -1
- package/dist-lib/plugins/python/python-adapter.js +8 -1
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/schema/harness.js +4 -2
- package/dist-lib/spec/hrpc/messages.js +19 -4
- package/dist-lib/spec/hyperschema/index.js +19 -4
- package/dist-lib/spec/hyperschema/schema.json +12 -1
- package/dist-lib/spec/hyperschema/types.d.ts +2 -0
- package/package.json +28 -19
- package/scripts/addon-externals.cjs +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -461,6 +461,13 @@ breaking change is listed under Changed and Removed.
|
|
|
461
461
|
|
|
462
462
|
### Changed
|
|
463
463
|
|
|
464
|
+
- A goal with host checks that test behaviour stops asking the model for checks
|
|
465
|
+
of its own after two goal turns it ignored. From then on the plan and the host
|
|
466
|
+
checks meet it, and a check the model names later still gates it. A goal with
|
|
467
|
+
no host checks keeps asking. (#682) When every host check only tests that a
|
|
468
|
+
file exists (`test -s`, `[ -f ... ]`), the ask stays until the model names a
|
|
469
|
+
check or a passing test runner, test script or inline assertion proves the
|
|
470
|
+
result; that run is held as a check of its own. (#686)
|
|
464
471
|
- A host reaches the drive protocol it serves, the skill catalog and the
|
|
465
472
|
user-plugin import map through named entries: `@qvac/harness/drive`
|
|
466
473
|
(`DriveRequest`, `DriveResponse`, `DriveEntry`, `GrantedDrive`, `DriveOpFn`,
|
|
@@ -1080,6 +1087,28 @@ breaking change is listed under Changed and Removed.
|
|
|
1080
1087
|
|
|
1081
1088
|
### Fixed
|
|
1082
1089
|
|
|
1090
|
+
- `tools/list` through `mcp_call` comes back as a line per tool, with each
|
|
1091
|
+
argument's type and allowed values, and `params.names` gives the tools named
|
|
1092
|
+
whole. Asana's 52 tools were 148 KB, so the model saw 5 of them cut or waited
|
|
1093
|
+
minutes for the whole listing on every round; the summary is 14 KB. See
|
|
1094
|
+
[the decision record](./docs/decisions/2026-10-29-mcp-call-lists-a-servers-tools-a-line-each.md).
|
|
1095
|
+
(QVAC-21896)
|
|
1096
|
+
- An MCP response, from `mcp_call` or a named server tool, is cut to the same
|
|
1097
|
+
share of the context window as an `http_request` body, and a cut carries the
|
|
1098
|
+
same `truncated` field, instead of a fixed 8 KB with a marker. The cut keeps
|
|
1099
|
+
JSON parseable and keeps the fields after a bulky one, and the body is no
|
|
1100
|
+
longer re-indented before it is measured. Asana's `tools/list` came back as
|
|
1101
|
+
5 of its tools and a task as its custom fields without its name, so the
|
|
1102
|
+
asana skill guessed arguments for 8 to 11 calls and often never answered.
|
|
1103
|
+
(QVAC-21896)
|
|
1104
|
+
- A cut string inside a JSON response is measured as it serializes, so a body
|
|
1105
|
+
of escaped text (newlines, quotes) stays within the room instead of coming
|
|
1106
|
+
back at up to twice the budget while `truncated.keptChars` reported the
|
|
1107
|
+
budget, and a short field after it still fits.
|
|
1108
|
+
- The last tool round pushes `WRAP_UP_NUDGE` (a host's `wording.wrapUp`), which asks for a
|
|
1109
|
+
plain-text answer, instead of the nudge that offers "the next tool": with the grammar off
|
|
1110
|
+
Qwen3.5-2B wrote that call as text and answered "I ran out of steps" (24 → 1 of 396 runs).
|
|
1111
|
+
- The runaway cap also counts tool markup in think blocks, closed or not.
|
|
1083
1112
|
- A tool call whose arguments a model wrote as something other than an object, such as a
|
|
1084
1113
|
string, no longer fails the run with a raw `TypeError`. The call is answered with an error
|
|
1085
1114
|
the model reads, and the tool never runs.
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
<a href="#plugins">Plugins</a> ·
|
|
23
23
|
<a href="#examples">Examples</a> ·
|
|
24
24
|
<a href="#host-it">Host it</a> ·
|
|
25
|
+
<a href="docs/runtime-support.md">Runtime support</a> ·
|
|
25
26
|
<a href="#development">Development</a>
|
|
26
27
|
</p>
|
|
27
28
|
|
|
@@ -195,7 +196,8 @@ run going until every step is done or a budget runs out. A goal's `checks` are c
|
|
|
195
196
|
is judged by, and until they pass each goal turn names the check and the output of its failed run.
|
|
196
197
|
On a run with a tool that takes a `command`, the model must also name its own checks under a
|
|
197
198
|
`Checks:` line, and the goal is met only once every check, the host's and the model's, ran in a
|
|
198
|
-
call's `command` and exited 0
|
|
199
|
+
call's `command` and exited 0. With host checks, the ask stops after two goal turns the model
|
|
200
|
+
ignores, and from then on the plan and the host checks meet the goal. `checksProve: true` says the host
|
|
199
201
|
checks prove the task: the goal is met on them alone and the model is not asked for its own. It has
|
|
200
202
|
no effect without checks. With no tool that takes a `command` and no host checks, the goal ends when the plan is done; host
|
|
201
203
|
checks need a tool that takes a `command`, or the goal runs to its budget.
|
package/dist-lib/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { platform, totalmem } from 'os';
|
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import ReadyResource from 'ready-resource';
|
|
5
5
|
import { HarnessError } from './lib/errors.js';
|
|
6
|
-
import { androidCpuPlacement } from './lib/hardware/cpu-placement.js';
|
|
7
6
|
import { probeGpuStats } from './lib/hardware/gpu-probe.js';
|
|
8
7
|
import { probeCapabilityProfile } from './lib/hardware/capability-probe.js';
|
|
9
8
|
import { Lifecycle } from './lib/lifecycle/index.js';
|
|
@@ -150,9 +150,16 @@ function resumedHop(runId, agents) {
|
|
|
150
150
|
? { index: Number(match[2]), id: match[3], root: match[1] }
|
|
151
151
|
: null;
|
|
152
152
|
}
|
|
153
|
-
const TRANSFER_NOTE =
|
|
153
|
+
const TRANSFER_NOTE = '\n\n[Transferred from ';
|
|
154
154
|
export function untransferred(text) {
|
|
155
|
-
|
|
155
|
+
const at = text.lastIndexOf(TRANSFER_NOTE);
|
|
156
|
+
return at !== -1 && text.endsWith(']') && isNote(text.slice(at + TRANSFER_NOTE.length, -1))
|
|
157
|
+
? text.slice(0, at)
|
|
158
|
+
: text;
|
|
159
|
+
}
|
|
160
|
+
function isNote(note) {
|
|
161
|
+
const colon = note.indexOf(': ');
|
|
162
|
+
return colon !== -1 && !note.slice(0, colon).includes(']') && !note.includes('\n');
|
|
156
163
|
}
|
|
157
164
|
function noted(messages, note) {
|
|
158
165
|
const last = messages.findLastIndex((message) => message.role === 'user');
|
|
@@ -11,7 +11,7 @@ import { runToolCall } from './execute.js';
|
|
|
11
11
|
import { toolCaller } from '../tool-caller.js';
|
|
12
12
|
import { loadSkill } from './loading-skill.js';
|
|
13
13
|
import { failureResultRef, storeFailureResult } from '../../../helpers/failure-result.js';
|
|
14
|
-
import { runsCheck } from '../../../helpers/goal-check.js';
|
|
14
|
+
import { provesResult, runsCheck } from '../../../helpers/goal-check.js';
|
|
15
15
|
const CHECK_OUTPUT_CHARS = 2000;
|
|
16
16
|
export const executing = async function executing(input) {
|
|
17
17
|
const { emit, input: deps, context } = input;
|
|
@@ -55,6 +55,7 @@ export const executing = async function executing(input) {
|
|
|
55
55
|
endedRun: succeeded && plan.resolved.tool.endsRun === true ? true : undefined,
|
|
56
56
|
durationMs: settled.durationMs,
|
|
57
57
|
checked: settled.checked,
|
|
58
|
+
proved: settled.proved,
|
|
58
59
|
plan: planned ? Agent.planSteps(callArgs) : undefined,
|
|
59
60
|
leftPlanMode: planned && context.planMode && call.leavesPlan ? true : undefined
|
|
60
61
|
};
|
|
@@ -205,6 +206,9 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
|
|
|
205
206
|
output: executed.output
|
|
206
207
|
})
|
|
207
208
|
: undefined,
|
|
209
|
+
proved: executed.executed && succeeded && context.goal
|
|
210
|
+
? proofRun(callArgs.command, executed.output)
|
|
211
|
+
: undefined,
|
|
208
212
|
entry: toolResultHistoryEntry({
|
|
209
213
|
name: call.name,
|
|
210
214
|
id: resultTurnId,
|
|
@@ -220,6 +224,12 @@ function checksRun({ goal }, { command, passed, output }) {
|
|
|
220
224
|
if (!ran.length) {
|
|
221
225
|
return undefined;
|
|
222
226
|
}
|
|
223
|
-
|
|
224
|
-
|
|
227
|
+
return ran.map(({ name }) => ({ name, passed, output: outputTail(output) }));
|
|
228
|
+
}
|
|
229
|
+
function proofRun(command, output) {
|
|
230
|
+
const name = typeof command === 'string' ? provesResult(command) : undefined;
|
|
231
|
+
return name ? { name, passed: true, output: outputTail(output) } : undefined;
|
|
232
|
+
}
|
|
233
|
+
function outputTail(output) {
|
|
234
|
+
return textsOf(historyPayload(output)).join('\n').trim().slice(-CHECK_OUTPUT_CHARS);
|
|
225
235
|
}
|
|
@@ -82,7 +82,7 @@ export async function loadSkill({ emit, input: deps, context }, plan) {
|
|
|
82
82
|
else {
|
|
83
83
|
session.loadedFilesThisTurn.add(fileKey);
|
|
84
84
|
}
|
|
85
|
-
session.reselectTools?.(new Set([...loadedSkills(context, session), skillName]));
|
|
85
|
+
session.reselectTools?.(new Set([...loadedSkills(context, session), skillName]), context.history);
|
|
86
86
|
const skill = session.inContextSkills.find(({ name }) => name === skillName);
|
|
87
87
|
const loads = skillLoadTurns(skill, {
|
|
88
88
|
sent: session.sdkTools,
|
|
@@ -2,7 +2,7 @@ import { Agent } from '../../../agent/index.js';
|
|
|
2
2
|
import { spliceFrom } from '../splice.js';
|
|
3
3
|
import { AbortedError } from '../../../helpers/race-abort.js';
|
|
4
4
|
import { currentTimeAnnotation, lastUserContent } from '../../../prompt.js';
|
|
5
|
-
import { explicitWebSearchQuery, lastUserImages, modelTurns, withTurnContext } from '../turns.js';
|
|
5
|
+
import { explicitWebSearchQuery, knowledgeExcerpt, knowledgeSources, lastUserImages, modelTurns, withTurnContext } from '../turns.js';
|
|
6
6
|
import { HookHalt } from '../../../helpers/engine-error.js';
|
|
7
7
|
import { stripControlTokens } from '../../../helpers/control-tokens.js';
|
|
8
8
|
import { fixableInSkills, skillInContext } from '../../skill-entry.js';
|
|
@@ -15,7 +15,7 @@ import { logToolPrompt } from '../../tool-prompt-log.js';
|
|
|
15
15
|
import { toolContext } from './execution-plan.js';
|
|
16
16
|
import { knowledgeSearch } from './retrieving.js';
|
|
17
17
|
import { detachJson } from '../../../helpers/detach-json.js';
|
|
18
|
-
import { GOAL_CHECKS_ASK, GOAL_PROOF_ASK } from '../../../helpers/goal-check.js';
|
|
18
|
+
import { asksChecks, GOAL_CHECKS_ASK, GOAL_PROOF_ASK } from '../../../helpers/goal-check.js';
|
|
19
19
|
function offeredTools(tools, model) {
|
|
20
20
|
const profile = model ? modelNameToCapabilityProfile(model) : undefined;
|
|
21
21
|
return tools.filter(({ minCapabilityProfile: min }) => !min || (profile !== undefined && meetsMinCapabilityProfile(profile, min)));
|
|
@@ -38,7 +38,7 @@ function takesCommand(tools) {
|
|
|
38
38
|
return tools.some((tool) => 'command' in tool.parameters.properties);
|
|
39
39
|
}
|
|
40
40
|
function checksAsk({ goal }, checkable) {
|
|
41
|
-
if (!goal || !checkable
|
|
41
|
+
if (!goal || !asksChecks({ ...goal, checkable })) {
|
|
42
42
|
return [];
|
|
43
43
|
}
|
|
44
44
|
return [{ role: 'user', content: goal.checks.length ? GOAL_PROOF_ASK : GOAL_CHECKS_ASK }];
|
|
@@ -116,8 +116,6 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
116
116
|
const { skillsSelected } = activation;
|
|
117
117
|
const sent = reconstruct ? context.history[0] : undefined;
|
|
118
118
|
let systemContent = sent && 'role' in sent && sent.role === 'system' ? sent.content : system.text;
|
|
119
|
-
const promptPrefix = promptPrefixHash({ system: systemContent, tools: renderedTools(sdkTools) });
|
|
120
|
-
const promptParts = promptUsageParts({ system, toolSchemas: renderedTools(sdkTools) });
|
|
121
119
|
const logSelection = (prefix) => {
|
|
122
120
|
logToolPrompt({
|
|
123
121
|
promptPrefix: prefix,
|
|
@@ -136,25 +134,26 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
136
134
|
toolOps: session.grantedOps
|
|
137
135
|
});
|
|
138
136
|
};
|
|
139
|
-
session.reselectTools = (loaded) => {
|
|
137
|
+
session.reselectTools = (loaded, history) => {
|
|
140
138
|
const reselected = callable(loaded);
|
|
141
139
|
const names = reselected.map((tool) => tool.name).join();
|
|
142
140
|
const changed = names !== session.enabled.map((tool) => tool.name).join();
|
|
143
141
|
if (changed) {
|
|
144
142
|
session.enabled = reselected;
|
|
145
143
|
}
|
|
146
|
-
const
|
|
144
|
+
const tools = renderedTools(sdkTools, history);
|
|
145
|
+
const prefix = promptPrefixHash({ system: systemContent, tools });
|
|
147
146
|
if (changed) {
|
|
148
147
|
logSelection(prefix);
|
|
149
148
|
}
|
|
150
149
|
return prefix;
|
|
151
150
|
};
|
|
152
|
-
session.preloadSystem = (skill) => {
|
|
151
|
+
session.preloadSystem = (skill, history) => {
|
|
153
152
|
const systemParts = resolved.systemFor(new Set([...loadedSkills, skill]));
|
|
154
153
|
systemContent = systemParts.text;
|
|
155
154
|
session.promptParts = promptUsageParts({
|
|
156
155
|
system: systemParts,
|
|
157
|
-
toolSchemas: renderedTools(sdkTools)
|
|
156
|
+
toolSchemas: renderedTools(sdkTools, history)
|
|
158
157
|
});
|
|
159
158
|
return systemContent;
|
|
160
159
|
};
|
|
@@ -168,8 +167,14 @@ async function prepare({ input, context, reconstruct, source, emit }) {
|
|
|
168
167
|
const history = firstTurn
|
|
169
168
|
? withSystem([...withTurnContext(messages, { time, ...added }), ...checks])
|
|
170
169
|
: [...context.history];
|
|
170
|
+
const promptPrefix = promptPrefixHash({
|
|
171
|
+
system: systemContent,
|
|
172
|
+
tools: renderedTools(sdkTools, history)
|
|
173
|
+
});
|
|
174
|
+
const promptParts = promptUsageParts({ system, toolSchemas: renderedTools(sdkTools, history) });
|
|
171
175
|
if (firstTurn && !reconstruct && messages.some((turn) => turn.role === 'user')) {
|
|
172
|
-
|
|
176
|
+
const sources = hits.length ? knowledgeSources(hits) : undefined;
|
|
177
|
+
emit({ type: 'context', context: { time, ...added }, sources, round: context.round });
|
|
173
178
|
}
|
|
174
179
|
const sources = firstTurn
|
|
175
180
|
? hits.map((hit) => session.outbound.facts('tool-result', hit.text))
|
|
@@ -234,7 +239,7 @@ function bareTurn(messages) {
|
|
|
234
239
|
function addedContext(hits, notes) {
|
|
235
240
|
const added = {};
|
|
236
241
|
if (hits.length > 0) {
|
|
237
|
-
added.excerpts = hits.map(
|
|
242
|
+
added.excerpts = hits.map(knowledgeExcerpt);
|
|
238
243
|
}
|
|
239
244
|
if (notes !== undefined) {
|
|
240
245
|
added.notes = notes;
|
|
@@ -245,9 +250,13 @@ function knowledgeHits(deps, context, messages) {
|
|
|
245
250
|
if (context.round > 0 || context.directSearchDone) {
|
|
246
251
|
return Promise.resolve([]);
|
|
247
252
|
}
|
|
253
|
+
const { typedText } = deps.args;
|
|
248
254
|
return knowledgeSearch(deps, {
|
|
249
255
|
id: `${context.runId}:round-${context.round}:prepare:knowledge`,
|
|
250
|
-
|
|
256
|
+
focus: deps.args.knowledge?.focus,
|
|
257
|
+
text: typedText === undefined
|
|
258
|
+
? Agent.untransferred(lastUserContent(messages))
|
|
259
|
+
: stripControlTokens(typedText)
|
|
251
260
|
});
|
|
252
261
|
}
|
|
253
262
|
function prepareSession(session, prepared) {
|
|
@@ -5,6 +5,7 @@ export declare const retrieving: CompletionActor<RetrievingOutput>;
|
|
|
5
5
|
interface KnowledgeSearch {
|
|
6
6
|
id: string;
|
|
7
7
|
text: string;
|
|
8
|
+
focus?: readonly string[] | undefined;
|
|
8
9
|
}
|
|
9
|
-
export declare function knowledgeSearch({ args, services, operations }: CompletionDeps, { id, text }: KnowledgeSearch): Promise<KnowledgeHit[]>;
|
|
10
|
+
export declare function knowledgeSearch({ args, services, operations }: CompletionDeps, { id, text, focus }: KnowledgeSearch): Promise<KnowledgeHit[]>;
|
|
10
11
|
export {};
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { AbortedError } from '../../../helpers/race-abort.js';
|
|
2
|
+
import { stripControlTokens } from '../../../helpers/control-tokens.js';
|
|
2
3
|
import { isFailureResultReference } from '../../../helpers/failure-result.js';
|
|
3
4
|
import { HarnessLog } from '../../../log.js';
|
|
4
5
|
import { errorMessage } from '../../../guards.js';
|
|
5
6
|
import { spliceFrom } from '../splice.js';
|
|
6
|
-
import { turnText } from '../turns.js';
|
|
7
|
+
import { knowledgeExcerpt, knowledgeSources, turnText } from '../turns.js';
|
|
7
8
|
export const retrieving = async function retrieving({ input, context, emit }) {
|
|
8
9
|
const { history, edgeInputs } = context;
|
|
9
10
|
const at = history.findLastIndex((entry) => !isFailureResultReference(entry) && entry.role === 'user');
|
|
10
11
|
const turn = history[at];
|
|
12
|
+
const typed = edgeInputs.at(-1)?.text;
|
|
11
13
|
const hits = turn && !isFailureResultReference(turn)
|
|
12
14
|
? await knowledgeSearch(input, {
|
|
13
15
|
id: `${context.runId}:round-${context.round}:input:knowledge`,
|
|
14
|
-
text: turn.content
|
|
16
|
+
text: typed === undefined ? turn.content : stripControlTokens(typed)
|
|
15
17
|
})
|
|
16
18
|
: [];
|
|
17
|
-
const excerpts = hits.map(
|
|
19
|
+
const excerpts = hits.map(knowledgeExcerpt);
|
|
18
20
|
for (const [index, queued] of edgeInputs.entries()) {
|
|
19
|
-
const
|
|
20
|
-
const turnContext = { ...queued.context, ...
|
|
21
|
+
const found = index === edgeInputs.length - 1 && excerpts.length > 0;
|
|
22
|
+
const turnContext = found ? { ...queued.context, excerpts } : { ...queued.context };
|
|
21
23
|
if (Object.keys(turnContext).length > 0) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const sources = found ? knowledgeSources(hits) : undefined;
|
|
25
|
+
const event = {
|
|
26
|
+
type: 'context',
|
|
27
|
+
context: turnContext,
|
|
28
|
+
sources,
|
|
29
|
+
round: context.round
|
|
30
|
+
};
|
|
31
|
+
emit(queued.id === undefined ? event : { ...event, id: queued.id });
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
34
|
if (!turn || isFailureResultReference(turn) || hits.length === 0) {
|
|
@@ -34,9 +41,10 @@ export const retrieving = async function retrieving({ input, context, emit }) {
|
|
|
34
41
|
sources: hits.map((hit) => input.session.outbound.facts('tool-result', hit.text))
|
|
35
42
|
};
|
|
36
43
|
};
|
|
37
|
-
export function knowledgeSearch({ args, services, operations }, { id, text }) {
|
|
44
|
+
export function knowledgeSearch({ args, services, operations }, { id, text, focus }) {
|
|
38
45
|
const knowledge = services?.knowledge;
|
|
39
46
|
const scopes = args.knowledge?.scopes ?? [];
|
|
47
|
+
const k = args.knowledge?.k;
|
|
40
48
|
const query = text.trim();
|
|
41
49
|
if (!knowledge ||
|
|
42
50
|
scopes.length === 0 ||
|
|
@@ -46,7 +54,7 @@ export function knowledgeSearch({ args, services, operations }, { id, text }) {
|
|
|
46
54
|
}
|
|
47
55
|
const search = async () => {
|
|
48
56
|
try {
|
|
49
|
-
return await knowledge.search({ text: query, scopes, signal: args.signal });
|
|
57
|
+
return await knowledge.search({ text: query, scopes, focus, k, signal: args.signal });
|
|
50
58
|
}
|
|
51
59
|
catch (error) {
|
|
52
60
|
if (args.signal?.aborted || error instanceof AbortedError) {
|
|
@@ -59,7 +67,7 @@ export function knowledgeSearch({ args, services, operations }, { id, text }) {
|
|
|
59
67
|
return operations.operation({
|
|
60
68
|
id,
|
|
61
69
|
name: 'knowledge:search',
|
|
62
|
-
args: { scopes: [...scopes].sort() },
|
|
70
|
+
args: { scopes: [...scopes].sort(), focus: focus && [...focus].sort(), k },
|
|
63
71
|
effect: 'read'
|
|
64
72
|
}, search, undefined, args.signal);
|
|
65
73
|
}
|
|
@@ -60,8 +60,8 @@ export const skillStep = {
|
|
|
60
60
|
const content = String(result.content);
|
|
61
61
|
session.loadedThisTurn.add(name);
|
|
62
62
|
session.skillIcon = skillEmojiFrom(session.inContextSkills, name) ?? session.skillIcon;
|
|
63
|
-
const typed = withSystem(annotateCompletionHistoryLastUserTime(context.history, new Date(session.startedAt)), session.preloadSystem?.(name));
|
|
64
|
-
session.reselectTools?.(new Set([...loadedSkills(context, session), name]));
|
|
63
|
+
const typed = withSystem(annotateCompletionHistoryLastUserTime(context.history, new Date(session.startedAt)), session.preloadSystem?.(name, context.history));
|
|
64
|
+
session.reselectTools?.(new Set([...loadedSkills(context, session), name]), context.history);
|
|
65
65
|
const called = directToolHistory(typed, {
|
|
66
66
|
tool: step.tool,
|
|
67
67
|
id: step.id,
|
|
@@ -12,7 +12,7 @@ interface RunRoundOptions {
|
|
|
12
12
|
agent?: AgentConfig | undefined;
|
|
13
13
|
kind: RoundKind;
|
|
14
14
|
args: Omit<RoundArgs, 'live' | 'knownTools'>;
|
|
15
|
-
session: Pick<Session, 'liveRound' | 'enabled' | 'runId'>;
|
|
15
|
+
session: Pick<Session, 'liveRound' | 'enabled' | 'runId' | 'promptParts'>;
|
|
16
16
|
emit: (event: CompletionEvent) => void;
|
|
17
17
|
}
|
|
18
18
|
export interface AssembleAnswerOptions {
|
|
@@ -3,6 +3,8 @@ import { inferenceCall, recordWholeRound, runRecoveredRound } from '../round.js'
|
|
|
3
3
|
import { ModelRound } from '../model-round.js';
|
|
4
4
|
import { ToolSets } from '../tool-sets.js';
|
|
5
5
|
import { AbortedError } from '../../../helpers/race-abort.js';
|
|
6
|
+
import { renderedTools } from '../../sdk-tool.js';
|
|
7
|
+
import { toolSchemaChars } from '../../usage-breakdown.js';
|
|
6
8
|
export async function forwardStream({ stream, emit }) {
|
|
7
9
|
try {
|
|
8
10
|
while (true) {
|
|
@@ -37,6 +39,12 @@ export async function runRound({ sdk, modelRound, agent, kind, args, session, em
|
|
|
37
39
|
emit
|
|
38
40
|
});
|
|
39
41
|
session.liveRound = null;
|
|
42
|
+
if (session.promptParts) {
|
|
43
|
+
session.promptParts = {
|
|
44
|
+
...session.promptParts,
|
|
45
|
+
toolSchemas: toolSchemaChars(renderedTools(args.tools, round.history))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
40
48
|
return round;
|
|
41
49
|
}
|
|
42
50
|
catch (error) {
|
|
@@ -79,6 +87,8 @@ async function remoteRound({ port, agent, kind, args, runId, emit }) {
|
|
|
79
87
|
promptPrefix: args.promptPrefix,
|
|
80
88
|
continuationNudge: args.continuationNudge,
|
|
81
89
|
deliveredNudge: args.deliveredNudge,
|
|
90
|
+
goalNudge: args.goalNudge,
|
|
91
|
+
wrapUpNudge: args.wrapUpNudge,
|
|
82
92
|
unforced: args.unforced
|
|
83
93
|
}, { signal: args.signal, emit });
|
|
84
94
|
return {
|
|
@@ -86,6 +96,7 @@ async function remoteRound({ port, agent, kind, args, runId, emit }) {
|
|
|
86
96
|
final: result.final,
|
|
87
97
|
history: args.history,
|
|
88
98
|
cacheable: true,
|
|
99
|
+
keyed: args.cacheKey !== undefined,
|
|
89
100
|
unproven: result.unproven ?? null,
|
|
90
101
|
replay: result.replay ?? null,
|
|
91
102
|
reasoningDeltas: result.reasoningDeltas,
|
|
@@ -7,7 +7,8 @@ import { clipRawCall, recoverMarkupToolCalls, recoverPrintedSkillLoad, recoverSk
|
|
|
7
7
|
import { unquoteArg } from '../../../helpers/model-args.js';
|
|
8
8
|
import { Agent } from '../../../agent/index.js';
|
|
9
9
|
import { loadedTools } from '../../sdk-tool.js';
|
|
10
|
-
import {
|
|
10
|
+
import { requestPromptPrefix } from '../../prompt-prefix.js';
|
|
11
|
+
import { FILE_DELIVERED_NUDGE, GOAL_CONTINUATION_NUDGE, TOOL_CONTINUATION_NUDGE, WRAP_UP_NUDGE } from '../../tool-turns.js';
|
|
11
12
|
import { HarnessLog } from '../../../log.js';
|
|
12
13
|
import { toolDialectFor } from '../../../models/model-catalog.js';
|
|
13
14
|
import { loadedSkills } from '../session.js';
|
|
@@ -45,6 +46,7 @@ export const streaming = async function streaming({ emit, input: { sdk, args, se
|
|
|
45
46
|
replay: recovered.replay,
|
|
46
47
|
history: recovered.history ? spliceFrom(context.history, recovered.history) : undefined,
|
|
47
48
|
cacheable: recovered.cacheable,
|
|
49
|
+
keyed: recovered.keyed,
|
|
48
50
|
cut: recovered.cut
|
|
49
51
|
};
|
|
50
52
|
};
|
|
@@ -93,7 +95,10 @@ async function generateStreamingRound({ sdk, args, session, operations, context,
|
|
|
93
95
|
session.runBudget.responseRoomChars = responseRoomChars(recovered.ctxSize ?? args.ctxSize, recovered.final.stats?.cacheTokens);
|
|
94
96
|
const durationMs = Date.now() - prepared.startedAt;
|
|
95
97
|
logRoundStats({ round: context.round, durationMs, recovered });
|
|
96
|
-
|
|
98
|
+
const promptPrefix = recovered.history
|
|
99
|
+
? requestPromptPrefix(recovered.history, session.sdkTools)
|
|
100
|
+
: prepared.promptPrefix;
|
|
101
|
+
return { recovered, promptPrefix, thinkingText, durationMs };
|
|
97
102
|
}
|
|
98
103
|
function logRoundStats({ round, durationMs, recovered }) {
|
|
99
104
|
HarnessLog.debug('round stats', Object.assign({ round, wallMs: durationMs }, recovered.final.stats));
|
|
@@ -105,7 +110,7 @@ function prepareStreamingRound({ args, session, operations, context }) {
|
|
|
105
110
|
: (context.cacheKey ?? undefined);
|
|
106
111
|
const model = args.model;
|
|
107
112
|
const toolDialect = model ? toolDialectFor(model) : undefined;
|
|
108
|
-
const promptPrefix = session.reselectTools?.(loadedSkills(context, session)) ?? context.promptPrefix;
|
|
113
|
+
const promptPrefix = session.reselectTools?.(loadedSkills(context, session), context.history) ?? context.promptPrefix;
|
|
109
114
|
HarnessLog.debug('round start', {
|
|
110
115
|
round: context.round,
|
|
111
116
|
turns: context.history.length,
|
|
@@ -121,6 +126,8 @@ function prepareStreamingRound({ args, session, operations, context }) {
|
|
|
121
126
|
failureResults: context.failureResults,
|
|
122
127
|
continuationNudge: context.policy.continuationNudge,
|
|
123
128
|
deliveredNudge: context.policy.deliveredNudge,
|
|
129
|
+
goalNudge: context.policy.goalNudge,
|
|
130
|
+
wrapUpNudge: context.policy.wrapUpNudge,
|
|
124
131
|
tools: session.sdkTools,
|
|
125
132
|
...roundGenerationParams(context, session, responseFormat),
|
|
126
133
|
responseFormat,
|
|
@@ -175,7 +182,12 @@ function planned(context, params) {
|
|
|
175
182
|
}
|
|
176
183
|
return plans(context.history) ? params : { ...params, reasoning_budget: 0 };
|
|
177
184
|
}
|
|
178
|
-
const NUDGES = new Set([
|
|
185
|
+
const NUDGES = new Set([
|
|
186
|
+
TOOL_CONTINUATION_NUDGE,
|
|
187
|
+
FILE_DELIVERED_NUDGE,
|
|
188
|
+
WRAP_UP_NUDGE,
|
|
189
|
+
GOAL_CONTINUATION_NUDGE
|
|
190
|
+
]);
|
|
179
191
|
const FAILED_RESULT = /"error"\s*:|"exitCode"\s*:\s*[1-9]/;
|
|
180
192
|
function plans(history) {
|
|
181
193
|
for (const entry of [...history].reverse()) {
|
|
@@ -5,6 +5,7 @@ import { roundFold } from './streaming.js';
|
|
|
5
5
|
import { degenerateAnswer } from '../../../helpers/run-outcome.js';
|
|
6
6
|
import { stripToolCallMarkup } from '../../../helpers/tool-call-markup.js';
|
|
7
7
|
import { materializeCompletionHistory } from '../../tool-turns.js';
|
|
8
|
+
import { requestPromptPrefix } from '../../prompt-prefix.js';
|
|
8
9
|
import { toolDialectFor } from '../../../models/model-catalog.js';
|
|
9
10
|
import { loadedSkills } from '../session.js';
|
|
10
11
|
import { CompletionMachine } from '../../../machine/index.js';
|
|
@@ -14,7 +15,7 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
|
|
|
14
15
|
const cacheKey = !args.replaysContext && carriesRunOnlyText(context.history)
|
|
15
16
|
? undefined
|
|
16
17
|
: (context.cacheKey ?? undefined);
|
|
17
|
-
const promptPrefix = session.reselectTools?.(loadedSkills(context, session)) ?? context.promptPrefix;
|
|
18
|
+
const promptPrefix = session.reselectTools?.(loadedSkills(context, session), context.history) ?? context.promptPrefix;
|
|
18
19
|
const startedAt = Date.now();
|
|
19
20
|
const recovered = await runRound({
|
|
20
21
|
sdk,
|
|
@@ -29,6 +30,8 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
|
|
|
29
30
|
failureResults: context.failureResults,
|
|
30
31
|
continuationNudge: context.policy.continuationNudge,
|
|
31
32
|
deliveredNudge: context.policy.deliveredNudge,
|
|
33
|
+
goalNudge: context.policy.goalNudge,
|
|
34
|
+
wrapUpNudge: context.policy.wrapUpNudge,
|
|
32
35
|
tools: session.sdkTools,
|
|
33
36
|
generationParams: wrapUpParams(session.generationParams),
|
|
34
37
|
toolDialect: args.model ? toolDialectFor(args.model) : undefined,
|
|
@@ -58,7 +61,9 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
|
|
|
58
61
|
return {
|
|
59
62
|
contentText,
|
|
60
63
|
thinkingText: '',
|
|
61
|
-
promptPrefix
|
|
64
|
+
promptPrefix: recovered.history
|
|
65
|
+
? requestPromptPrefix(recovered.history, session.sdkTools)
|
|
66
|
+
: promptPrefix,
|
|
62
67
|
toolCalls: [],
|
|
63
68
|
stats: recovered.final.stats,
|
|
64
69
|
stopReason: recovered.final.stopReason,
|
|
@@ -69,6 +74,7 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
|
|
|
69
74
|
replay,
|
|
70
75
|
history: recovered.history ? spliceFrom(context.history, recovered.history) : undefined,
|
|
71
76
|
cacheable: recovered.cacheable,
|
|
77
|
+
keyed: recovered.keyed,
|
|
72
78
|
response: replay || contentText || fallbackResponse
|
|
73
79
|
};
|
|
74
80
|
};
|
|
@@ -9,7 +9,7 @@ import { runEngine } from './engine.js';
|
|
|
9
9
|
import { didDrainTimeOut, raceDrain } from '../../helpers/drain.js';
|
|
10
10
|
import { RunLog } from '../../run-log/index.js';
|
|
11
11
|
import { stableStringify } from '../../helpers/stable-stringify.js';
|
|
12
|
-
import { checkGoal, checkMaxToolRounds, FILE_DELIVERED_NUDGE, GOAL_CONTINUATION_NUDGE, GOAL_STALLED_NUDGE, GOAL_ROUNDS, MAX_TOOL_ROUNDS, TOOL_CONTEXT_BOUNDARY_MESSAGE, TOOL_CONTINUATION_NUDGE, TOOL_CUT_OFF_MESSAGE, TOOL_DENIED_MESSAGE, TOOL_REPEATED_MESSAGE, TOOL_ROUND_CUT_MESSAGE, TOOL_UNCHANGED_MESSAGE } from '../tool-turns.js';
|
|
12
|
+
import { checkGoal, checkMaxToolRounds, FILE_DELIVERED_NUDGE, GOAL_CONTINUATION_NUDGE, GOAL_STALLED_NUDGE, GOAL_ROUNDS, MAX_TOOL_ROUNDS, TOOL_CONTEXT_BOUNDARY_MESSAGE, TOOL_CONTINUATION_NUDGE, WRAP_UP_NUDGE, TOOL_CUT_OFF_MESSAGE, TOOL_DENIED_MESSAGE, TOOL_REPEATED_MESSAGE, TOOL_ROUND_CUT_MESSAGE, TOOL_UNCHANGED_MESSAGE } from '../tool-turns.js';
|
|
13
13
|
import { createSession } from './session.js';
|
|
14
14
|
import { captureFacts } from './durable.js';
|
|
15
15
|
import { completionPorts } from './ports.js';
|
|
@@ -355,6 +355,7 @@ function runPolicy({ maxToolRounds, goal, wording }) {
|
|
|
355
355
|
maxToolRounds: checkMaxToolRounds(goal?.rounds ?? maxToolRounds ?? (goal ? GOAL_ROUNDS : MAX_TOOL_ROUNDS)),
|
|
356
356
|
continuationNudge: wording?.toolContinuation ?? TOOL_CONTINUATION_NUDGE,
|
|
357
357
|
deliveredNudge: wording?.fileDelivered ?? FILE_DELIVERED_NUDGE,
|
|
358
|
+
wrapUpNudge: wording?.wrapUp ?? WRAP_UP_NUDGE,
|
|
358
359
|
deniedMessage: wording?.toolDenied ?? TOOL_DENIED_MESSAGE,
|
|
359
360
|
cutOffMessage: wording?.toolCutOff ?? TOOL_CUT_OFF_MESSAGE,
|
|
360
361
|
contextBoundaryMessage: wording?.toolContextBoundary ?? TOOL_CONTEXT_BOUNDARY_MESSAGE,
|