@qvac/harness 1.0.0-rc.10 → 1.0.0-rc.12

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist-lib/index.d.ts +2 -12
  3. package/dist-lib/index.js +8 -2
  4. package/dist-lib/lib/agent/resolve.js +9 -2
  5. package/dist-lib/lib/agent/tools.d.ts +1 -0
  6. package/dist-lib/lib/agent/tools.js +1 -1
  7. package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
  8. package/dist-lib/lib/capabilities/agent-ports.js +7 -1
  9. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +4 -1
  10. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +3 -1
  11. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +12 -5
  12. package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +36 -22
  13. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +24 -5
  14. package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +3 -2
  15. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +18 -3
  16. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +3 -0
  17. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +1 -0
  18. package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -2
  19. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -0
  20. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +2 -1
  21. package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +2 -1
  22. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +9 -0
  23. package/dist-lib/lib/capabilities/completion-engine/round.js +12 -8
  24. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -1
  25. package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
  26. package/dist-lib/lib/capabilities/skill-entry.d.ts +4 -0
  27. package/dist-lib/lib/capabilities/skill-entry.js +28 -1
  28. package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
  29. package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
  30. package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -1
  31. package/dist-lib/lib/capabilities/tool-turns.js +21 -2
  32. package/dist-lib/lib/context-window.d.ts +1 -0
  33. package/dist-lib/lib/context-window.js +6 -0
  34. package/dist-lib/lib/contract/agent.d.ts +4 -0
  35. package/dist-lib/lib/contract/completion.d.ts +2 -0
  36. package/dist-lib/lib/contract/models.d.ts +3 -1
  37. package/dist-lib/lib/contract/run.d.ts +1 -0
  38. package/dist-lib/lib/machine/completion/actions/completion.d.ts +3 -1
  39. package/dist-lib/lib/machine/completion/actions/completion.js +43 -7
  40. package/dist-lib/lib/machine/completion/actions/tools.js +4 -5
  41. package/dist-lib/lib/machine/completion/context.js +1 -0
  42. package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -1
  43. package/dist-lib/lib/machine/completion/guards/retry.js +4 -3
  44. package/dist-lib/lib/machine/completion/implementations.d.ts +2 -0
  45. package/dist-lib/lib/machine/completion/implementations.js +7 -3
  46. package/dist-lib/lib/machine/completion/machine.d.ts +6 -0
  47. package/dist-lib/lib/machine/completion/machine.js +12 -1
  48. package/dist-lib/lib/machine/completion/rules.d.ts +1 -0
  49. package/dist-lib/lib/machine/completion/rules.js +3 -0
  50. package/dist-lib/lib/machine/completion/types.d.ts +5 -0
  51. package/dist-lib/lib/machine/index.d.ts +6 -0
  52. package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
  53. package/dist-lib/lib/models/custom-model-cache.js +3 -0
  54. package/dist-lib/lib/models/gguf-header.d.ts +6 -0
  55. package/dist-lib/lib/models/gguf-header.js +38 -1
  56. package/dist-lib/lib/models/kv-cache.d.ts +2 -0
  57. package/dist-lib/lib/models/kv-cache.js +8 -0
  58. package/dist-lib/lib/models/load-requests.d.ts +9 -0
  59. package/dist-lib/lib/models/load-requests.js +42 -0
  60. package/dist-lib/lib/models/model-handle.d.ts +1 -0
  61. package/dist-lib/lib/models/model-pool.d.ts +2 -1
  62. package/dist-lib/lib/models/model-pool.js +17 -7
  63. package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -0
  64. package/dist-lib/lib/no-redirect-fetch-impl.js +32 -1
  65. package/dist-lib/lib/prompt.d.ts +4 -2
  66. package/dist-lib/lib/prompt.js +16 -5
  67. package/dist-lib/lib/residency/completion-runtime.d.ts +6 -5
  68. package/dist-lib/lib/residency/completion-runtime.js +3 -7
  69. package/dist-lib/lib/residency/index.d.ts +9 -1
  70. package/dist-lib/lib/residency/index.js +38 -8
  71. package/dist-lib/lib/skills-host/index.d.ts +1 -0
  72. package/dist-lib/lib/skills-host/index.js +3 -0
  73. package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
  74. package/dist-lib/lib/tools/attachments/staging.js +11 -0
  75. package/dist-lib/lib/tools/http-request/request.d.ts +3 -1
  76. package/dist-lib/lib/tools/http-request/request.js +2 -1
  77. package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
  78. package/dist-lib/lib/tools/http-request/truncate-response.js +45 -9
  79. package/dist-lib/lib/tools/http-request.js +12 -6
  80. package/dist-lib/lib/tools/office/ops.d.ts +1 -0
  81. package/dist-lib/lib/tools/office/ops.js +5 -1
  82. package/dist-lib/lib/tools/office.d.ts +1 -0
  83. package/dist-lib/lib/tools/office.js +151 -21
  84. package/dist-lib/lib/tools/operations/compile.js +4 -4
  85. package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
  86. package/dist-lib/lib/tools/skills/credential-check.js +3 -0
  87. package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
  88. package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
  89. package/dist-lib/plugins/image/edit-image.js +4 -3
  90. package/dist-lib/plugins/image/generate-image.d.ts +3 -2
  91. package/dist-lib/plugins/image/generate-image.js +87 -64
  92. package/dist-lib/plugins/image/index.js +1 -0
  93. package/dist-lib/plugins/music/generate-music.d.ts +3 -2
  94. package/dist-lib/plugins/music/generate-music.js +68 -47
  95. package/dist-lib/plugins/music/index.js +1 -0
  96. package/dist-lib/plugins/run-report/story.js +4 -1
  97. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  98. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  99. package/package.json +5 -1
package/CHANGELOG.md CHANGED
@@ -21,6 +21,16 @@ breaking change is listed under Changed and Removed.
21
21
 
22
22
  ### Added
23
23
 
24
+ - `isLoading` covers image and music models, and a reply waiting for room. An
25
+ image or music row reads `true` from the request, through any wait for a
26
+ download or for room, until the model is resident or the load fails, and the
27
+ `loading` and `ready` or `error` edges carry `catalogChanged` as a pooled
28
+ load's do. A reply's model, and the chat model a translation runs on, read
29
+ `true` from the request too, so the wait for room before the load shows: with
30
+ no memory cap that wait can run minutes while another reply holds the one
31
+ chat model. The request and the load each send `loading`. A plugin that loads
32
+ its own models counts them through `ModelHost.requests`. Translation pack,
33
+ speech, transcription and embedding rows still read `false`. (#649)
24
34
  - The macOS and Linux sandboxes take `writable`: absolute folders every shell line may write on
25
35
  top of the run's policy, for a toolchain cache outside the project such as Go's build cache.
26
36
  The file tools never see them, they are made at setup if missing, and a denied root still wins.
@@ -437,6 +447,17 @@ breaking change is listed under Changed and Removed.
437
447
  leaves under `@qvac/harness/lib/tools/` are exported for such a host. See the
438
448
  [decision record](docs/decisions/2026-10-25-a-host-shapes-the-harness-through-a-named-module.md).
439
449
  (#629)
450
+ - `ToolDefinition.deliversMany`, for a tool one request may call several times
451
+ for several files. A file it delivers gets the delivered-file nudge but does
452
+ not end the run one tool round later, so "draw a cat, a dog and a bird" made
453
+ one image per round still gets all three. `generate_image` and `edit_image`
454
+ set it. (#610)
455
+ - A skill whose oauth setup route has a `verify` probe and a `credentialKey`
456
+ gets that probe as its `requires.credentialChecks` entry for the key, when
457
+ the skill declares none, so a dead token reads as rejected instead of
458
+ needs-setup. A hand-written check still wins. A credential check may now
459
+ carry a `body`. A `verify` rule keyed on a response field (Spotify Premium)
460
+ still marks the token rejected in the health probe only on 401 or 403.
440
461
 
441
462
  ### Changed
442
463
 
@@ -668,6 +689,14 @@ breaking change is listed under Changed and Removed.
668
689
  unchanged count. A call that returns the same result and folds every few rounds
669
690
  now ends the run at its fourth identical run. The re-read after a fold carries
670
691
  no unchanged note and no progress credit. (#507)
692
+ - A stall no longer ends a goal run that has rounds, time and tokens left. The
693
+ round ends, every unchanged and blocked count restarts, and the goal goes on
694
+ with a turn that adds `wording.goalStalled` to the goal turn; `{call}` names
695
+ the stuck call. Only a met goal or a spent budget ends a goal run, and the
696
+ `GoalStatus` is `stalled` only when a stall came with no budget left. A run
697
+ with no goal still ends on a stall. See the
698
+ [decision record](docs/decisions/2026-10-26-a-stall-continues-a-goal-run-until-its-budget-ends.md).
699
+ (#651)
671
700
  - A wrap-up cut off at the context window answers with the fallback instead of
672
701
  its fragment and emits `round-reset` for what it streamed; a wrap-up
673
702
  cut at its `predict` cap (`contextBoundary: false`) keeps its
@@ -972,6 +1001,10 @@ breaking change is listed under Changed and Removed.
972
1001
  preload with round 0's calls: the harness renders it as its own round first.
973
1002
  A skill that fails to load is noted in the user's turn, sends no call, and
974
1003
  that run is not cached. (#511)
1004
+ - **Breaking** for a host that reads `attachmentId` off a `generate_image` or
1005
+ `edit_image` result, in a chat or from `invoke` with the `image` capability:
1006
+ the image is now `attachments[0]`, `{ attachmentId, fileName, byteLength }`,
1007
+ the shape a delivered file has everywhere else. (#610)
975
1008
 
976
1009
  ### Removed
977
1010
 
@@ -1047,6 +1080,9 @@ breaking change is listed under Changed and Removed.
1047
1080
 
1048
1081
  ### Fixed
1049
1082
 
1083
+ - A tool call whose arguments a model wrote as something other than an object, such as a
1084
+ string, no longer fails the run with a raw `TypeError`. The call is answered with an error
1085
+ the model reads, and the tool never runs.
1050
1086
  - A user plugin loads from the published package: `sharedImports` resolved the harness's own
1051
1087
  files by their `.ts` names, which the compiled `dist-lib` does not ship, so every host that
1052
1088
  loads user plugins from npm failed with `MODULE_NOT_FOUND`. It now names them with its own
@@ -1120,6 +1156,48 @@ breaking change is listed under Changed and Removed.
1120
1156
  round past `maxToolRounds`. (#167)
1121
1157
  - A `FAIL` sent while a run was finishing no longer runs the finishing step and
1122
1158
  its `runEnd` hook again. (#167)
1159
+ - After `generate_image` or `edit_image`, the next round is told the image is
1160
+ attached and shown to the user, as it is after `pdf`, the office tools and
1161
+ `exec`, instead of "call the next tool, or answer". On that nudge Qwen3.5-4B
1162
+ sometimes called `generate_image` again to show the image it had just made,
1163
+ and the chat got two. (#610)
1164
+ - A custom model whose head width a quantized KV block does not divide loads
1165
+ with an `f16` cache instead of failing with "Failed to initialize context"
1166
+ (BeeLLM, head width 40, under the hosts' `q8_0`). (QVAC-27064)
1167
+ - A custom model whose chat template has no `<think>` tag no longer starts its
1168
+ reply inside a think block, so the reply stops streaming as thinking and then
1169
+ repeating as the answer (Qwen2.5-Coder with thinking on). Its reasoning
1170
+ budget is unchanged. (QVAC-27064)
1171
+ - An `http_request` body, or a shaped skill operation response, is cut at a
1172
+ share of the context window instead of a fixed 8 KB: half the room the last
1173
+ round left, at a character per token so Chinese or Japanese text cannot
1174
+ overflow it, and shared by every call in the round. With 11k tokens used of
1175
+ a 51k window that is 20,000 characters where it was 8,192. A cut result
1176
+ carries `truncated`, with the characters kept, the total, the share read and
1177
+ a note that the reply must say so. A Google Doc export came back as its
1178
+ first fragment and the model summarized that as the whole document. See
1179
+ [the decision record](./docs/decisions/2026-10-23-a-tool-response-is-cut-to-the-window-and-says-so.md).
1180
+ - `http_request` gives up once no byte has arrived for 10 seconds, at any
1181
+ point in the request, instead of 10 seconds for the whole response. A body
1182
+ that keeps arriving gets up to 30 seconds, so a large Google Doc export on a
1183
+ slow link finishes, while a server that stops answering still fails as fast
1184
+ as before.
1185
+ - `pptx` skips look-only keys, an invented theme, a body a layout cannot hold
1186
+ and a picture with no upload, listing them in `skipped`, instead of
1187
+ refusing the whole deck. (#527)
1188
+ - A loaded skill's body reaches the model as text under its `[Tool: skill …]`
1189
+ header, with only `name` and `file` on the JSON line, instead of stringified
1190
+ whole. Qwen3.5-4B copied the escaped quotes of `A[\"First step\"]` into its
1191
+ own Mermaid block, which the app then could not render (QVAC-24502). Turns
1192
+ an older harness stringified whole still read as loaded; an existing chat
1193
+ with a replayed skill stub re-reads once after the update. (#639)
1194
+ - A new user-added overlay skill no longer runs a credential health check, so
1195
+ a key it holds is never sent to a probe host it chose. An overlay that
1196
+ shadows a bundled skill keeps its checks, still bound to the bundled
1197
+ allow-list. (#654)
1198
+ - A skill picked with `@` that cannot serve the request, or whose input is not
1199
+ in the chat, now makes the model say so in one sentence instead of calling
1200
+ tools to force it. (#643)
1123
1201
 
1124
1202
  ## [0.8.12] - 2026-10-21
1125
1203
 
@@ -2,7 +2,7 @@ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
2
  import ReadyResource from 'ready-resource';
3
3
  import { Policy } from './lib/policy/index.ts';
4
4
  import type { EngineBoot, EngineStep, RecoveryResolution } from './lib/run-log/index.ts';
5
- import { type ModelRoundIo, type ModelRoundPort, type ModelRoundRequest, type ModelRoundResult } from './lib/capabilities/completion-engine/index.ts';
5
+ import { type CompletionArgs, type ModelRoundIo, type ModelRoundPort, type ModelRoundRequest, type ModelRoundResult } from './lib/capabilities/completion-engine/index.ts';
6
6
  import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, Message, ProgressFn, ResponseFormat, RunGoal, RunInput, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
7
7
  import { type DetectLanguageContext, type DetectedLanguage } from './lib/capabilities/detect-language.ts';
8
8
  import { type Capability } from './lib/capabilities/invoke.ts';
@@ -129,17 +129,7 @@ export interface CompletionContext {
129
129
  planMode?: boolean;
130
130
  deferTools?: boolean;
131
131
  goal?: RunGoal;
132
- wording?: {
133
- toolContinuation?: string;
134
- fileDelivered?: string;
135
- toolDenied?: string;
136
- toolCutOff?: string;
137
- toolRoundCut?: string;
138
- toolContextBoundary?: string;
139
- toolRepeated?: string;
140
- toolUnchanged?: string;
141
- goalContinuation?: string;
142
- };
132
+ wording?: CompletionArgs['wording'];
143
133
  resume?: boolean;
144
134
  recovery?: RecoveryResolution[];
145
135
  model: string;
package/dist-lib/index.js CHANGED
@@ -190,6 +190,7 @@ export class Harness extends ReadyResource {
190
190
  llmLoad,
191
191
  slots,
192
192
  completionModelCap,
193
+ modelsDir: this._modelsDir,
193
194
  sdk: { load: () => this._sdk.load() },
194
195
  loads: this._loads,
195
196
  gate: this._lifecycle,
@@ -225,7 +226,8 @@ export class Harness extends ReadyResource {
225
226
  ],
226
227
  unloadIdlePlugins: () => this._plugins.unloadIdle(),
227
228
  tools: () => this._tools,
228
- skills: (agentId, model) => this._skills.completionSkills(agentId, model)
229
+ skills: (agentId, model) => this._skills.completionSkills(agentId, model),
230
+ platform: () => this._skills.platform
229
231
  });
230
232
  this._embeddings = new Embeddings({
231
233
  device: embedDevice,
@@ -314,12 +316,16 @@ export class Harness extends ReadyResource {
314
316
  this._lifecycle.assertNotClosing();
315
317
  }
316
318
  _modelHost(transcriptionDevice) {
319
+ const residency = () => this._residency;
317
320
  return {
318
321
  transcriptionDevice,
319
322
  sdk: () => this._sdk.load(),
320
323
  track: (load, sdk) => this._loads.track(load, sdk),
321
324
  makeRoom: (signal, busy, srcs) => this._residency.makeRoomForPlugin(signal, busy, srcs),
322
325
  hold: this._hold,
326
+ get requests() {
327
+ return residency().requests;
328
+ },
323
329
  completionModel: (model, signal) => this._residency.borrow(model, signal),
324
330
  emit: (state) => this.emit('model', state),
325
331
  progressState,
@@ -854,7 +860,7 @@ export class Harness extends ReadyResource {
854
860
  throw new Error(UNLOAD_FAILED);
855
861
  }
856
862
  const { modelId } = request;
857
- const { key, acquireRound } = this._residency.servedRound(modelId);
863
+ const { key, acquireRound } = this._residency.servedRound(modelId, request.load);
858
864
  let served;
859
865
  const round = this._lifecycle.trackCompletion((signal) => this._residency.busyStream(async function* () {
860
866
  served = await CompletionEngine.serveModelRound(request, { signal, emit: (event) => io.emit(event), retake: () => io.retake() }, { acquireRound });
@@ -19,7 +19,11 @@ export function resolveAgent(request, ports) {
19
19
  enabledSkills: agent?.enabledSkills ?? []
20
20
  };
21
21
  const activeSkills = request.skills.filter((skill) => skillIsActive(skill.name, toggles));
22
- const mention = ports.mention(userText, activeSkills);
22
+ const unreadySkills = toggles.skillsSelected
23
+ ? (request.unreadySkills ?? []).filter((skill) => skillIsActive(skill.name, toggles))
24
+ : [];
25
+ const listedSkills = [...activeSkills, ...unreadySkills];
26
+ const mention = ports.mention(userText, listedSkills);
23
27
  const activation = {
24
28
  ...toggles,
25
29
  mention: mention?.name ?? null,
@@ -32,6 +36,7 @@ export function resolveAgent(request, ports) {
32
36
  toolsSelected: isSelected(agent?.toolsScope, agent?.enabledTools),
33
37
  allowlist: agent?.enabledTools ?? [],
34
38
  activeSkills,
39
+ listedSkills,
35
40
  grantedNames,
36
41
  grantedOwners,
37
42
  hasRoots: fsRoots.length > 0,
@@ -50,7 +55,8 @@ export function resolveAgent(request, ports) {
50
55
  const systemFor = (loaded) => ports.systemPrompt({
51
56
  bio: agent?.bio,
52
57
  toolNames: select(loaded).map((tool) => tool.name),
53
- skills: activeSkills
58
+ skills: listedSkills,
59
+ platform: request.platform
54
60
  });
55
61
  const enabled = select(activation.loadedSkills);
56
62
  return {
@@ -58,6 +64,7 @@ export function resolveAgent(request, ports) {
58
64
  system: systemFor(activation.loadedSkills),
59
65
  activation,
60
66
  activeSkills,
67
+ listedSkills,
61
68
  mention,
62
69
  preload: mention ?? ports.implicitSkill(userText, activeSkills),
63
70
  grantedOps,
@@ -5,6 +5,7 @@ export interface ToolSelectionInputs {
5
5
  toolsSelected: boolean;
6
6
  allowlist: ReadonlyArray<string>;
7
7
  activeSkills: readonly AgentSkill[];
8
+ listedSkills: readonly AgentSkill[];
8
9
  loadedSkills: ReadonlySet<string>;
9
10
  grantedNames: ReadonlySet<string>;
10
11
  grantedOwners: ReadonlyMap<string, ReadonlySet<string>>;
@@ -11,7 +11,7 @@ export function selectEnabledTools(inputs) {
11
11
  loadedGrantedNames: collectToolGrants(loaded).grantedNames,
12
12
  hasRoots: inputs.hasRoots,
13
13
  hasWriteRoots: inputs.hasWriteRoots,
14
- hasActiveSkills: inputs.activeSkills.length > 0,
14
+ hasActiveSkills: inputs.listedSkills.length > 0,
15
15
  capabilityProfile: inputs.capabilityProfile
16
16
  });
17
17
  }
@@ -1,3 +1,3 @@
1
1
  import type { AgentPorts } from '../contract/index.ts';
2
- import type { CompletionSkillEntry } from './skill-entry.ts';
2
+ import { type CompletionSkillEntry } from './skill-entry.ts';
3
3
  export declare const defaultAgentPorts: AgentPorts<CompletionSkillEntry>;
@@ -1,9 +1,15 @@
1
1
  import { resolveLlmGenerationParams } from '../models/llm-presets.js';
2
2
  import { skillsPromptSection, systemPromptParts } from '../prompt.js';
3
3
  import { resolveImplicitSkill, resolveSkillMention } from '../tools/skills/mention.js';
4
+ import { promptSkill } from './skill-entry.js';
4
5
  export const defaultAgentPorts = {
5
6
  generationParams: resolveLlmGenerationParams,
6
- systemPrompt: ({ bio, toolNames, skills }) => systemPromptParts({ bio, toolNames, skillsSection: skillsPromptSection(skills) }),
7
+ systemPrompt: ({ bio, toolNames, skills, platform }) => systemPromptParts({
8
+ bio,
9
+ toolNames,
10
+ skillsSection: skillsPromptSection(skills.map(promptSkill)),
11
+ platform
12
+ }),
7
13
  mention: resolveSkillMention,
8
14
  implicitSkill: resolveImplicitSkill
9
15
  };
@@ -51,6 +51,7 @@ export const executing = async function executing(input) {
51
51
  stableRead: settled.stableRead,
52
52
  answer: settled.answer,
53
53
  delivered: settled.delivered,
54
+ deliveryEndsRun: settled.deliveryEndsRun,
54
55
  endedRun: succeeded && plan.resolved.tool.endsRun === true ? true : undefined,
55
56
  durationMs: settled.durationMs,
56
57
  checked: settled.checked,
@@ -183,6 +184,7 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
183
184
  }
184
185
  : undefined;
185
186
  const turn = toolResultTurn(call.name, resultTurnId, output);
187
+ const delivered = outcome.kind === 'success' && deliversFile(output);
186
188
  return {
187
189
  deniedKey: [...denied].find((key) => !context.deniedKeys.includes(key)),
188
190
  webSearch: plan.webSearch,
@@ -193,7 +195,8 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
193
195
  settled: digest === undefined ? undefined : { key: callKey, digest },
194
196
  stableRead: plan.resolved.tool.stableRead && plan.effect === 'read' ? true : undefined,
195
197
  answer: succeeded ? answerOf(output) : undefined,
196
- delivered: outcome.kind === 'success' && deliversFile(output) ? true : undefined,
198
+ delivered: delivered ? true : undefined,
199
+ deliveryEndsRun: delivered && plan.resolved.tool.deliversMany !== true ? true : undefined,
197
200
  durationMs: executed.executed ? durationMs : undefined,
198
201
  checked: executed.executed
199
202
  ? checksRun(context, {
@@ -4,6 +4,7 @@ import { detachJson } from '../../../helpers/detach-json.js';
4
4
  import { inspectToolPolicy } from '../tool-execution.js';
5
5
  import { modelTurns, trustedSourcesFrom } from '../turns.js';
6
6
  import { skillNameOf } from '../../tool-plan.js';
7
+ import { unreadySkillState } from '../../skill-entry.js';
7
8
  import { runSpill } from '../../../spill.js';
8
9
  export function resolvedCall(session, call) {
9
10
  const tool = session.enabled.find((tool) => tool.name === call.name);
@@ -21,7 +22,8 @@ export function toolContext({ deps, context, name }) {
21
22
  const { args, session, commitFacts } = deps;
22
23
  return {
23
24
  ...session.toolContext(session.turnImages, context.metrics.ctxSize ?? args.ctxSize, args.signal),
24
- skills: context.activated.filter((skill) => Agent.skillIsActive(skill, session.activation)),
25
+ skills: context.activated.filter((skill) => Agent.skillIsActive(skill, session.activation) &&
26
+ !unreadySkillState(skill, args.skillCatalog ?? [])),
25
27
  skillsLoadedThisTurn: [...session.loadedThisTurn],
26
28
  settings: args.toolConfigs?.[name],
27
29
  toolOps: session.grantedOps,
@@ -5,7 +5,7 @@ import { currentTimeAnnotation, lastUserContent } from '../../../prompt.js';
5
5
  import { explicitWebSearchQuery, 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
- import { skillInContext } from '../../skill-entry.js';
8
+ import { fixableInSkills, skillInContext } from '../../skill-entry.js';
9
9
  import { meetsMinCapabilityProfile, modelNameToCapabilityProfile } from '../../../models/model-catalog-constants.js';
10
10
  import { deferredForRun, defers, renderedTools, TOOL_SEARCH_TOOL_NAME, toSdkTools, withToolSearch } from '../../sdk-tool.js';
11
11
  import { loadedSkillFilesFrom, loadedSkillsFrom } from '../../tool-turns.js';
@@ -48,7 +48,7 @@ export function preparing(source) {
48
48
  }
49
49
  async function prepare({ input, context, reconstruct, source, emit }) {
50
50
  const { args, session } = input;
51
- const { model, agent, thinkingDefault, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, tools: allTools = [], skillCatalog = [], signal, fsRoots = [], fsWriteRoots = [], deferTools } = args;
51
+ const { model, agent, thinkingDefault, generationParams: generationParamsOverride, responseFormat, messages: storedMessages, tools: allTools = [], skillCatalog = [], signal, fsRoots = [], fsWriteRoots = [], deferTools, platform } = args;
52
52
  if (signal?.aborted) {
53
53
  throw new AbortedError();
54
54
  }
@@ -77,7 +77,8 @@ async function prepare({ input, context, reconstruct, source, emit }) {
77
77
  const turnImages = lastUserImages(messages);
78
78
  const loadedSkills = new Set([...loadedSkillsFrom(messages), ...context.activated]);
79
79
  const loadedSkillFiles = loadedSkillFilesFrom(messages);
80
- const inContextSkills = skillCatalog.filter(skillInContext);
80
+ const readySkills = skillCatalog.filter(skillInContext);
81
+ const unreadySkills = skillCatalog.filter((skill) => !skillInContext(skill) && fixableInSkills(skill));
81
82
  const offered = offeredTools(allTools, model);
82
83
  const tools = deferTools ? offered.map(deferredForRun) : offered;
83
84
  const resolved = Agent.resolve({
@@ -90,7 +91,9 @@ async function prepare({ input, context, reconstruct, source, emit }) {
90
91
  messages,
91
92
  userText,
92
93
  tools,
93
- skills: inContextSkills,
94
+ skills: readySkills,
95
+ unreadySkills,
96
+ platform,
94
97
  loadedSkills,
95
98
  fsRoots,
96
99
  fsWriteRoots,
@@ -98,7 +101,11 @@ async function prepare({ input, context, reconstruct, source, emit }) {
98
101
  planMode: context.planMode,
99
102
  policy: session.access
100
103
  }, deferTools ? promptForWholeTools(session.agentPorts, tools) : session.agentPorts);
101
- const { system, activation, activeSkills, mention, grantedOps } = resolved;
104
+ const { system, activation, activeSkills, listedSkills, mention, grantedOps } = resolved;
105
+ const inContextSkills = [
106
+ ...readySkills,
107
+ ...listedSkills.filter((skill) => !skillInContext(skill))
108
+ ];
102
109
  const catalog = withToolSearch(resolved.select(new Set(activeSkills.map(({ name }) => name))));
103
110
  const callable = (loaded) => {
104
111
  const names = new Set(resolved.select(loaded).map(({ name }) => name));
@@ -34,40 +34,54 @@ export function runPrepare(source) {
34
34
  const display = source.display(deps, step);
35
35
  let activity = null;
36
36
  let result;
37
- try {
38
- const executed = await executeCall(tool, step.args, executeContext, {
39
- runId: session.runId,
40
- deniedMessage: context.policy.deniedMessage,
41
- signal: args.signal,
42
- sources: [],
43
- outbound: session.outbound,
44
- pipeline: session.pipeline,
45
- callId: step.id,
37
+ const refusal = source.refusal?.(deps, step) ?? null;
38
+ if (refusal !== null) {
39
+ activity = {
40
+ type: 'tool-activity',
41
+ name: tool.name,
42
+ args: step.args,
43
+ resource: null,
46
44
  effect,
47
- preflight: readyPreflightFromFacts(facts),
48
- display,
49
- onToolActivity: (event) => (activity = event)
50
- });
51
- result = executed.result;
45
+ decision: 'blocked'
46
+ };
47
+ result = { error: refusal };
52
48
  }
53
- catch (error) {
54
- if (error instanceof RecoveryRequired || error instanceof ToolPolicyChanged) {
55
- throw error;
49
+ else {
50
+ try {
51
+ const executed = await executeCall(tool, step.args, executeContext, {
52
+ runId: session.runId,
53
+ deniedMessage: context.policy.deniedMessage,
54
+ signal: args.signal,
55
+ sources: [],
56
+ outbound: session.outbound,
57
+ pipeline: session.pipeline,
58
+ callId: step.id,
59
+ effect,
60
+ preflight: readyPreflightFromFacts(facts),
61
+ display,
62
+ onToolActivity: (event) => (activity = event)
63
+ });
64
+ result = executed.result;
56
65
  }
57
- if (error instanceof AbortedError || args.signal?.aborted) {
58
- throw new AbortedError();
66
+ catch (error) {
67
+ if (error instanceof RecoveryRequired || error instanceof ToolPolicyChanged) {
68
+ throw error;
69
+ }
70
+ if (error instanceof AbortedError || args.signal?.aborted) {
71
+ throw new AbortedError();
72
+ }
73
+ return fail(errorMessage(error));
59
74
  }
60
- return fail(errorMessage(error));
61
75
  }
62
76
  if (args.signal?.aborted) {
63
77
  throw new AbortedError();
64
78
  }
65
- const announce = () => {
79
+ const announce = (shown) => {
66
80
  emit({ type: 'tool-call', name: tool.name, args: step.args, effect: 'read', display });
67
81
  if (activity) {
68
82
  emit(activity);
69
83
  }
70
- emit({ type: 'tool-result', name: tool.name, result });
84
+ emit({ type: 'tool-result', name: tool.name, result: shown });
71
85
  };
72
86
  return source.settle({ deps, context, step, result, announce });
73
87
  };
@@ -2,11 +2,12 @@ import { spliceFrom } from '../splice.js';
2
2
  import { annotateCompletionHistoryLastUserTime, directToolHistory, withLastUserNote } from '../turns.js';
3
3
  import { labelOf, skillEmojiFrom } from '../loop.js';
4
4
  import { loadedSkills } from '../session.js';
5
- import { PRELOAD_ID_PREFIX } from '../../tool-turns.js';
5
+ import { PRELOAD_ID_PREFIX, skillMentionNudge } from '../../tool-turns.js';
6
6
  import { skillLoadTurns } from '../../sdk-tool.js';
7
7
  import { Agent } from '../../../agent/index.js';
8
8
  import { errorMessage, isRecord } from '../../../guards.js';
9
9
  import { isFailureResultReference } from '../../../helpers/failure-result.js';
10
+ import { mentionHandle, unreadySkillMessage, unreadySkillState } from '../../skill-entry.js';
10
11
  export const skillStep = {
11
12
  label: 'Skill loading',
12
13
  propose({ session }, { preload }) {
@@ -23,10 +24,29 @@ export const skillStep = {
23
24
  display({ session }, step) {
24
25
  return labelOf(step.tool, step.args, skillEmojiFrom(session.inContextSkills, skillOf(step)));
25
26
  },
27
+ refusal({ args }, step) {
28
+ const name = skillOf(step);
29
+ const state = unreadySkillState(name, args.skillCatalog ?? []);
30
+ return state ? unreadySkillMessage(name, state) : null;
31
+ },
26
32
  settle({ deps, context, step, result, announce }) {
27
33
  const { session } = deps;
28
34
  const name = skillOf(step);
29
- announce();
35
+ const skill = session.inContextSkills.find((entry) => entry.name === name);
36
+ const mention = skill && session.activation.mention === name ? mentionHandle(skill) : null;
37
+ const output = mention && hasContent(result) ? { ...result, mention } : result;
38
+ announce(output);
39
+ if (unreadySkillState(name, deps.args.skillCatalog ?? [])) {
40
+ const typed = annotateCompletionHistoryLastUserTime(context.history, new Date(session.startedAt));
41
+ const refused = directToolHistory(typed, {
42
+ tool: step.tool,
43
+ id: step.id,
44
+ args: step.args,
45
+ output: result,
46
+ nudge: context.policy.continuationNudge
47
+ });
48
+ return { history: spliceFrom(context.history, refused) };
49
+ }
30
50
  if (!hasContent(result)) {
31
51
  return {
32
52
  failure: fail({
@@ -46,11 +66,10 @@ export const skillStep = {
46
66
  tool: step.tool,
47
67
  id: step.id,
48
68
  args: step.args,
49
- output: result,
50
- nudge: context.policy.continuationNudge
69
+ output,
70
+ nudge: mention ? skillMentionNudge(mention) : context.policy.continuationNudge
51
71
  });
52
72
  const loaded = called.slice(0, -1);
53
- const skill = session.inContextSkills.find((entry) => entry.name === name);
54
73
  const loads = skillLoadTurns(skill, {
55
74
  sent: session.sdkTools,
56
75
  enabled: session.enabled,
@@ -1,4 +1,4 @@
1
- import type { CompletionEvent, CompletionSdk } from '../../../contract/index.ts';
1
+ import type { AgentConfig, CompletionEvent, CompletionSdk } from '../../../contract/index.ts';
2
2
  import { type RecoveredRound, type RoundArgs, type RoundKind } from '../round.ts';
3
3
  import { type ModelRoundPort } from '../model-round.ts';
4
4
  import type { Session } from '../session.ts';
@@ -9,6 +9,7 @@ interface ForwardStreamOptions<Result> {
9
9
  interface RunRoundOptions {
10
10
  sdk: CompletionSdk | undefined;
11
11
  modelRound?: ModelRoundPort | undefined;
12
+ agent?: AgentConfig | undefined;
12
13
  kind: RoundKind;
13
14
  args: Omit<RoundArgs, 'live' | 'knownTools'>;
14
15
  session: Pick<Session, 'liveRound' | 'enabled' | 'runId'>;
@@ -21,6 +22,6 @@ export interface AssembleAnswerOptions {
21
22
  emit: (event: CompletionEvent) => void;
22
23
  }
23
24
  export declare function forwardStream<Result>({ stream, emit }: ForwardStreamOptions<Result>): Promise<Result>;
24
- export declare function runRound({ sdk, modelRound, kind, args, session, emit }: RunRoundOptions): Promise<RecoveredRound>;
25
+ export declare function runRound({ sdk, modelRound, agent, kind, args, session, emit }: RunRoundOptions): Promise<RecoveredRound>;
25
26
  export declare function assembleAnswer({ contentText, replay, landed, emit }: AssembleAnswerOptions): Promise<string>;
26
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { reportUnnamedWrites } from '../loop.js';
2
- import { recordWholeRound, runRecoveredRound } from '../round.js';
2
+ 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';
@@ -17,7 +17,7 @@ export async function forwardStream({ stream, emit }) {
17
17
  await Promise.resolve(stream.return(undefined)).catch(noop);
18
18
  }
19
19
  }
20
- export async function runRound({ sdk, modelRound, kind, args, session, emit }) {
20
+ export async function runRound({ sdk, modelRound, agent, kind, args, session, emit }) {
21
21
  if (args.signal?.aborted)
22
22
  throw new AbortedError();
23
23
  const live = { round: args.round, kind, startedAt: Date.now(), rawChars: 0, reasoningDeltas: 0 };
@@ -26,6 +26,7 @@ export async function runRound({ sdk, modelRound, kind, args, session, emit }) {
26
26
  const round = modelRound
27
27
  ? await remoteRound({
28
28
  port: modelRound,
29
+ agent,
29
30
  kind,
30
31
  args: { ...args, live },
31
32
  runId: session.runId,
@@ -46,14 +47,28 @@ export async function runRound({ sdk, modelRound, kind, args, session, emit }) {
46
47
  throw error;
47
48
  }
48
49
  }
49
- async function remoteRound({ port, kind, args, runId, emit }) {
50
+ async function remoteRound({ port, agent, kind, args, runId, emit }) {
50
51
  const params = await recordWholeRound(args);
52
+ if (args.capture) {
53
+ emit(inferenceCall({
54
+ args,
55
+ droppedTurns: 0,
56
+ modelId: params.modelId,
57
+ params,
58
+ cacheKey: args.cacheKey
59
+ }));
60
+ }
51
61
  const result = await ModelRound.run(port, {
52
62
  runId,
53
63
  round: args.round,
54
64
  kind,
55
65
  attempt: 0,
56
66
  modelId: params.modelId,
67
+ load: agent && {
68
+ ctxSize: agent.ctxSize,
69
+ kvCacheK: agent.kvCacheK,
70
+ kvCacheV: agent.kvCacheV
71
+ },
57
72
  history: params.history,
58
73
  tools: params.tools,
59
74
  toolSet: params.tools && ToolSets.hash(params.tools),
@@ -12,6 +12,7 @@ import { HarnessLog } from '../../../log.js';
12
12
  import { toolDialectFor } from '../../../models/model-catalog.js';
13
13
  import { loadedSkills } from '../session.js';
14
14
  import { CompletionMachine } from '../../../machine/index.js';
15
+ import { responseRoomChars } from '../../../context-window.js';
15
16
  export const streaming = async function streaming({ emit, input: { sdk, args, session, operations }, context }) {
16
17
  const { recovered, promptPrefix, thinkingText, durationMs } = await generateStreamingRound({
17
18
  sdk,
@@ -75,6 +76,7 @@ async function generateStreamingRound({ sdk, args, session, operations, context,
75
76
  const recovered = await runRound({
76
77
  sdk,
77
78
  modelRound: args.modelRound,
79
+ agent: args.agent,
78
80
  kind: 'streaming',
79
81
  session,
80
82
  args: prepared.args,
@@ -88,6 +90,7 @@ async function generateStreamingRound({ sdk, args, session, operations, context,
88
90
  emit(event);
89
91
  }
90
92
  });
93
+ session.runBudget.responseRoomChars = responseRoomChars(recovered.ctxSize ?? args.ctxSize, recovered.final.stats?.cacheTokens);
91
94
  const durationMs = Date.now() - prepared.startedAt;
92
95
  logRoundStats({ round: context.round, durationMs, recovered });
93
96
  return { recovered, promptPrefix: prepared.promptPrefix, thinkingText, durationMs };
@@ -19,6 +19,7 @@ export const wrapUp = async function wrapUp({ emit, input: { sdk, args, session,
19
19
  const recovered = await runRound({
20
20
  sdk,
21
21
  modelRound: args.modelRound,
22
+ agent: args.agent,
22
23
  kind: 'wrap-up',
23
24
  session,
24
25
  args: {
@@ -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_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, 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';
@@ -362,7 +362,8 @@ function runPolicy({ maxToolRounds, goal, wording }) {
362
362
  repeatedCallMessage: wording?.toolRepeated ?? TOOL_REPEATED_MESSAGE,
363
363
  unchangedMessage: wording?.toolUnchanged ?? TOOL_UNCHANGED_MESSAGE,
364
364
  failingMessage: wording?.toolFailing,
365
- goalNudge: wording?.goalContinuation ?? GOAL_CONTINUATION_NUDGE
365
+ goalNudge: wording?.goalContinuation ?? GOAL_CONTINUATION_NUDGE,
366
+ goalStalledNudge: wording?.goalStalled ?? GOAL_STALLED_NUDGE
366
367
  };
367
368
  }
368
369
  function restoredContextMetrics(boot) {