@qvac/harness 1.0.0-rc.5 → 1.0.0-rc.7
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 +245 -23
- package/README.md +19 -7
- package/dist-lib/index.d.ts +5 -3
- package/dist-lib/index.js +43 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +21 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +11 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +10 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +9 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +36 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +9 -11
- package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +15 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +52 -0
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -3
- package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +14 -4
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +9 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +21 -2
- package/dist-lib/lib/capabilities/tool-plan.d.ts +4 -0
- package/dist-lib/lib/capabilities/tool-plan.js +15 -0
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +79 -3
- package/dist-lib/lib/contract/run.d.ts +2 -0
- package/dist-lib/lib/contract-types.d.ts +5 -0
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +6 -0
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +2 -0
- package/dist-lib/lib/helpers/goal-check.js +18 -0
- package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +30 -11
- package/dist-lib/lib/machine/completion/context.js +2 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -1
- package/dist-lib/lib/machine/completion/rules.js +7 -8
- package/dist-lib/lib/machine/completion/types.d.ts +1 -0
- package/dist-lib/lib/models/llm-presets.d.ts +1 -0
- package/dist-lib/lib/models/model-catalog.js +1 -1
- package/dist-lib/lib/models/model-pool.d.ts +4 -0
- package/dist-lib/lib/models/model-pool.js +4 -1
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- package/dist-lib/lib/plugins/registry.d.ts +2 -0
- package/dist-lib/lib/plugins/registry.js +4 -0
- package/dist-lib/lib/prompt.d.ts +2 -1
- package/dist-lib/lib/prompt.js +12 -12
- package/dist-lib/lib/residency/completion-runtime.d.ts +9 -1
- package/dist-lib/lib/residency/completion-runtime.js +29 -26
- package/dist-lib/lib/residency/index.d.ts +4 -0
- package/dist-lib/lib/residency/index.js +6 -1
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/sdk-loader.d.ts +1 -1
- package/dist-lib/lib/sdk-loader.js +30 -6
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +18 -2
- package/dist-lib/lib/serve.js +68 -6
- package/dist-lib/lib/sidecar/index.d.ts +10 -0
- package/dist-lib/lib/sidecar/index.js +35 -3
- package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
- package/dist-lib/lib/sidecar/user-plugins.js +1 -1
- package/dist-lib/lib/tools/files/grep.js +113 -15
- package/dist-lib/lib/tools/fs/edit-match.js +75 -7
- package/dist-lib/lib/tools/fs/search.d.ts +1 -1
- package/dist-lib/lib/tools/fs/search.js +2 -1
- package/dist-lib/lib/tools/http-request.js +1 -0
- package/dist-lib/lib/tools/index.d.ts +2 -1
- package/dist-lib/lib/tools/index.js +2 -2
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- package/dist-lib/lib/wire.d.ts +13 -0
- package/dist-lib/lib/wire.js +44 -1
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +3 -1
- package/dist-lib/plugins/coding/session.js +19 -2
- package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
- package/dist-lib/plugins/egress-proxy/index.js +5 -3
- package/dist-lib/plugins/image/index.js +7 -2
- package/dist-lib/plugins/language-hint/index.js +4 -1
- package/dist-lib/plugins/mcp/server.js +1 -1
- package/dist-lib/plugins/music/index.js +6 -2
- package/dist-lib/plugins/obsidian/readiness.js +2 -2
- package/dist-lib/plugins/obsidian/vault-read.js +17 -16
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/loader.d.ts +1 -0
- package/dist-lib/plugins/python/loader.js +8 -0
- package/dist-lib/plugins/quickjs/index.js +4 -0
- package/dist-lib/plugins/quickjs/runtime.js +8 -3
- package/dist-lib/plugins/run-report/index.js +6 -2
- package/dist-lib/plugins/run-report/layout.js +1 -1
- package/dist-lib/plugins/sandbox-vm/index.js +3 -0
- 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/plugins/speech/audio-resample.js +2 -1
- package/dist-lib/plugins/speech/index.d.ts +1 -0
- package/dist-lib/plugins/speech/index.js +8 -1
- package/dist-lib/plugins/speech/speech-runtime.js +3 -3
- package/dist-lib/plugins/translation/index.d.ts +1 -1
- package/dist-lib/plugins/translation/index.js +7 -3
- package/dist-lib/plugins/translation/translate.d.ts +2 -2
- package/dist-lib/plugins/translation/translate.js +7 -8
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
- package/dist-lib/plugins/walkie-talkie/index.js +13 -5
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
- package/dist-lib/schema/harness.js +12 -2
- package/dist-lib/spec/hrpc/messages.js +208 -150
- package/dist-lib/spec/hyperschema/index.js +208 -150
- package/dist-lib/spec/hyperschema/schema.json +125 -84
- package/dist-lib/spec/hyperschema/types.d.ts +4 -3
- package/package.json +150 -25
|
@@ -3,7 +3,7 @@ import { isRecord } from '../../guards.js';
|
|
|
3
3
|
import { stripToolCallMarkup, toolCallMarkup } from '../../helpers/tool-call-markup.js';
|
|
4
4
|
import { Agent } from '../../agent/index.js';
|
|
5
5
|
import { DIRECT_CALL_ID, PRELOAD_ID_PREFIX, skillLoadedTurn, toolResultHistoryEntry, toolResultTurn } from '../tool-turns.js';
|
|
6
|
-
import {
|
|
6
|
+
import { annotateUserTimes, currentTimeAnnotation } from '../../prompt.js';
|
|
7
7
|
import { isFailureResultReference } from '../../helpers/failure-result.js';
|
|
8
8
|
export function trustedSourcesFrom(history) {
|
|
9
9
|
const sources = [];
|
|
@@ -29,6 +29,7 @@ export function sanitizeTurn(turn, answered = false) {
|
|
|
29
29
|
export function modelTurns(messages, nudge) {
|
|
30
30
|
const turns = [];
|
|
31
31
|
const consumed = new Set();
|
|
32
|
+
const lastUser = messages.findLastIndex((turn) => turn.role === 'user');
|
|
32
33
|
for (const [index, turn] of messages.entries()) {
|
|
33
34
|
if (consumed.has(index)) {
|
|
34
35
|
continue;
|
|
@@ -38,7 +39,8 @@ export function modelTurns(messages, nudge) {
|
|
|
38
39
|
}
|
|
39
40
|
const rendered = modelTurn(withoutHostFields(turn), messages[index + 1]?.role === 'tool');
|
|
40
41
|
if (rendered) {
|
|
41
|
-
|
|
42
|
+
const added = index === lastUser ? turn.context : stampedContext(turn);
|
|
43
|
+
turns.push(added ? { ...rendered, content: turnText(rendered.content, added) } : rendered);
|
|
42
44
|
}
|
|
43
45
|
if (isReplayedResult(turn) && messages[index + 1]?.role === 'assistant') {
|
|
44
46
|
turns.push({ role: 'user', content: nudge });
|
|
@@ -67,13 +69,21 @@ function preloadTurns({ messages, at, nudge, consumed }) {
|
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
function withoutHostFields(turn) {
|
|
70
|
-
if (!('id' in turn) && !('context' in turn))
|
|
72
|
+
if (!('id' in turn) && !('context' in turn) && !('sentAt' in turn)) {
|
|
71
73
|
return turn;
|
|
74
|
+
}
|
|
72
75
|
const rest = { ...turn };
|
|
73
76
|
delete rest.id;
|
|
74
77
|
delete rest.context;
|
|
78
|
+
delete rest.sentAt;
|
|
75
79
|
return rest;
|
|
76
80
|
}
|
|
81
|
+
function stampedContext(turn) {
|
|
82
|
+
if (turn.role !== 'user' || !turn.sentAt || turn.context?.time !== undefined) {
|
|
83
|
+
return turn.context;
|
|
84
|
+
}
|
|
85
|
+
return { ...turn.context, time: currentTimeAnnotation(new Date(turn.sentAt)) };
|
|
86
|
+
}
|
|
77
87
|
function isPreloadId(id) {
|
|
78
88
|
return id.startsWith(PRELOAD_ID_PREFIX);
|
|
79
89
|
}
|
|
@@ -195,7 +205,7 @@ export function annotateCompletionHistoryLastUserTime(history, now) {
|
|
|
195
205
|
if (!entry || isFailureResultReference(entry) || entry.role !== 'user') {
|
|
196
206
|
continue;
|
|
197
207
|
}
|
|
198
|
-
result[index] =
|
|
208
|
+
result[index] = annotateUserTimes([entry], now)[0] ?? entry;
|
|
199
209
|
break;
|
|
200
210
|
}
|
|
201
211
|
return result;
|
|
@@ -8,4 +8,5 @@ export interface DetectLanguageContext {
|
|
|
8
8
|
topK?: number;
|
|
9
9
|
}
|
|
10
10
|
export declare const UNDETERMINED = "und";
|
|
11
|
-
export declare function detectLanguage({ text, topK }: DetectLanguageContext): DetectedLanguage[]
|
|
11
|
+
export declare function detectLanguage({ text, topK }: DetectLanguageContext): Promise<DetectedLanguage[]>;
|
|
12
|
+
export declare function languageName(code: string): Promise<string | null>;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requirePeers } from '../helpers/require-peers.js';
|
|
2
|
+
import { retryMemo } from '../helpers/retry-memo.js';
|
|
2
3
|
export const UNDETERMINED = 'und';
|
|
3
|
-
|
|
4
|
+
const langdetect = retryMemo(() => {
|
|
5
|
+
requirePeers('@qvac/harness language detection', {
|
|
6
|
+
'@qvac/langdetect-text': () => import.meta.resolve('@qvac/langdetect-text')
|
|
7
|
+
});
|
|
8
|
+
return import('@qvac/langdetect-text');
|
|
9
|
+
});
|
|
10
|
+
export async function detectLanguage({ text, topK }) {
|
|
11
|
+
const { detectMultiple, detectOne } = await langdetect();
|
|
4
12
|
if (!topK || topK === 1) {
|
|
5
13
|
const { code, language } = detectOne(text);
|
|
6
14
|
return [{ code, language }];
|
|
@@ -11,3 +19,7 @@ export function detectLanguage({ text, topK }) {
|
|
|
11
19
|
probability
|
|
12
20
|
}));
|
|
13
21
|
}
|
|
22
|
+
export async function languageName(code) {
|
|
23
|
+
const { getLangName } = await langdetect();
|
|
24
|
+
return getLangName(code);
|
|
25
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Tool as SdkTool } from '@qvac/sdk';
|
|
2
|
-
import type { CompletionHistoryEntry, ToolDefinition } from '../contract/index.ts';
|
|
2
|
+
import type { AgentSkill, CompletionHistoryEntry, Message, ToolDefinition } from '../contract/index.ts';
|
|
3
3
|
export declare const TOOL_SEARCH_TOOL_NAME: string;
|
|
4
4
|
export declare function defers(tool: ToolDefinition): boolean;
|
|
5
5
|
export declare function deferredForRun(tool: ToolDefinition): ToolDefinition;
|
|
@@ -7,5 +7,13 @@ export declare function toSdkTool(tool: ToolDefinition): SdkTool;
|
|
|
7
7
|
export declare function toSdkTools(tools: readonly ToolDefinition[]): SdkTool[] | undefined;
|
|
8
8
|
export declare function renderedTools(tools: SdkTool[] | undefined): SdkTool[] | undefined;
|
|
9
9
|
export declare function loadedTools(history: readonly CompletionHistoryEntry[]): Set<string>;
|
|
10
|
+
export declare function loadTurns(sent: readonly SdkTool[] | undefined, names: Iterable<string>, history: readonly CompletionHistoryEntry[]): Message[];
|
|
11
|
+
interface SkillLoad {
|
|
12
|
+
sent: readonly SdkTool[] | undefined;
|
|
13
|
+
enabled: readonly ToolDefinition[];
|
|
14
|
+
history: readonly CompletionHistoryEntry[];
|
|
15
|
+
}
|
|
16
|
+
export declare function skillLoadTurns(skill: Pick<AgentSkill, 'tools'> | undefined, { sent, enabled, history }: SkillLoad): Message[];
|
|
10
17
|
export declare function unloadedTools(tools: readonly ToolDefinition[], history: readonly CompletionHistoryEntry[]): Set<string>;
|
|
11
18
|
export declare function withToolSearch(tools: ToolDefinition[]): ToolDefinition[];
|
|
19
|
+
export {};
|
|
@@ -70,7 +70,7 @@ function field(name, schema, required) {
|
|
|
70
70
|
return `${name}${optional}: ${shape(schema)}${fallback}${description}`;
|
|
71
71
|
}
|
|
72
72
|
export function defers(tool) {
|
|
73
|
-
return tool.defer === true
|
|
73
|
+
return (tool.defer === true || tool.skillGated === true) && !tool.endsRun && !tool.callsTools;
|
|
74
74
|
}
|
|
75
75
|
export function deferredForRun(tool) {
|
|
76
76
|
const deferred = { ...tool, defer: true };
|
|
@@ -94,7 +94,8 @@ export function toSdkTool(tool) {
|
|
|
94
94
|
description: tool.prompt?.description ?? tool.description,
|
|
95
95
|
parameters: sdkParameters(intentParameters(tool, tool.prompt?.parameters ?? tool.parameters))
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
const group = tool.group ?? tool.owningSkill ?? tool.toolset ?? undefined;
|
|
98
|
+
return defers(tool) ? { ...sent, deferLoading: true, group } : sent;
|
|
98
99
|
}
|
|
99
100
|
export function toSdkTools(tools) {
|
|
100
101
|
const searching = tools.some(defers);
|
|
@@ -111,6 +112,24 @@ export function renderedTools(tools) {
|
|
|
111
112
|
export function loadedTools(history) {
|
|
112
113
|
return loadedToolNames(history.filter((entry) => !isFailureResultReference(entry)));
|
|
113
114
|
}
|
|
115
|
+
export function loadTurns(sent, names, history) {
|
|
116
|
+
const turns = [];
|
|
117
|
+
for (const name of new Set(names)) {
|
|
118
|
+
const tool = sent?.find((each) => each.name === name && each.deferLoading === true);
|
|
119
|
+
const seen = [...history, ...turns];
|
|
120
|
+
if (tool && !loadedTools(seen).has(name)) {
|
|
121
|
+
const messages = seen.filter((entry) => !isFailureResultReference(entry));
|
|
122
|
+
const content = executeToolSearch([tool], { query: name, limit: 1 }, messages);
|
|
123
|
+
turns.push({ role: 'tool', content });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return turns;
|
|
127
|
+
}
|
|
128
|
+
export function skillLoadTurns(skill, { sent, enabled, history }) {
|
|
129
|
+
const granted = new Set(skill?.tools.map((entry) => Agent.parseToolGrant(entry).name));
|
|
130
|
+
const names = enabled.filter(({ name }) => granted.has(name)).map(({ name }) => name);
|
|
131
|
+
return loadTurns(sent, names, history);
|
|
132
|
+
}
|
|
114
133
|
export function unloadedTools(tools, history) {
|
|
115
134
|
const loaded = loadedTools(history);
|
|
116
135
|
return new Set(tools.filter((tool) => defers(tool) && !loaded.has(tool.name)).map(({ name }) => name));
|
|
@@ -32,5 +32,9 @@ interface KeyedResolvedCall extends ResolvedCall {
|
|
|
32
32
|
}
|
|
33
33
|
export declare function planToolCall(resolved: KeyedResolvedCall, opts: PlanToolCallOptions): ToolPolicyFacts;
|
|
34
34
|
export declare function skillNameOf(args: Record<string, unknown>): string;
|
|
35
|
+
export declare function withCatalogSkillName<Call extends {
|
|
36
|
+
name: string;
|
|
37
|
+
arguments: Record<string, unknown>;
|
|
38
|
+
}>(call: Call, catalog: readonly CompletionSkillEntry[]): Call;
|
|
35
39
|
export declare function skillFileKey(skillName: string, args: Record<string, unknown>): string | null;
|
|
36
40
|
export {};
|
|
@@ -64,6 +64,21 @@ export function planToolCall(resolved, opts) {
|
|
|
64
64
|
export function skillNameOf(args) {
|
|
65
65
|
return unquoteArg(args.name ?? args.skill_name ?? args.skill);
|
|
66
66
|
}
|
|
67
|
+
export function withCatalogSkillName(call, catalog) {
|
|
68
|
+
if (call.name !== Agent.SKILL_TOOL_NAME)
|
|
69
|
+
return call;
|
|
70
|
+
const asked = skillNameOf(call.arguments).toLowerCase();
|
|
71
|
+
const entry = catalog.find((skill) => skill.name.toLowerCase() === asked) ??
|
|
72
|
+
catalog.find((skill) => skill.displayName?.toLowerCase() === asked) ??
|
|
73
|
+
soleGrantingSkill(catalog, asked);
|
|
74
|
+
return entry && entry.name !== call.arguments.name
|
|
75
|
+
? { ...call, arguments: { ...call.arguments, name: entry.name } }
|
|
76
|
+
: call;
|
|
77
|
+
}
|
|
78
|
+
function soleGrantingSkill(catalog, toolName) {
|
|
79
|
+
const owners = catalog.filter((skill) => skill.tools.some((grant) => Agent.parseToolGrant(grant).name === toolName));
|
|
80
|
+
return owners.length === 1 ? owners[0] : undefined;
|
|
81
|
+
}
|
|
67
82
|
export function skillFileKey(skillName, args) {
|
|
68
83
|
const file = skillFileArg(args);
|
|
69
84
|
return mainFileRequested(skillName, file)
|
|
@@ -5,6 +5,7 @@ import type { CustomModelEntry } from './models/model-catalog.ts';
|
|
|
5
5
|
import { type ModelSourcePreview, type PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
|
|
6
6
|
import type { CapabilityInfo, CompletionContext, CredentialEntry, DetectedLanguage, DetectLanguageContext, DownloadContext, EmbedContext, HarnessContract, HarnessDiagnostics, HarnessEvent, HarnessInfo, HostContext, InfraModel, InvokeContext, ListModelsOptions, ModelInfo, ResolvedSkillCatalogEntry, SkillsOptions, SkillWriteResult, SpeakContext, SpeakResult, SpeakStreamContext, ToolCatalogEntry, TranscribeContext, LoadModelContext, LoadModelResult, MemoryUsage, UnloadModelContext, UnloadModelResult, WarmModelContext, DownloadsAllowedOptions } from './contract-types.ts';
|
|
7
7
|
import type { KnowledgeArtifact, KnowledgeHit, KnowledgeQuery, KnowledgeRemoved, KnowledgeStatus, KnowledgeUpsertResult } from './contract/knowledge.ts';
|
|
8
|
+
import type { ModelRoundIo, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
|
|
8
9
|
import { type EmbedDevice } from './models/embed-config.ts';
|
|
9
10
|
import type { DeleteModelSummary } from './models/model-delete.ts';
|
|
10
11
|
import type { CopyBaseResult, DeleteOverlayResult, ManagedSkill, SkillFileContent } from './tools/skills/overlay-crud.ts';
|
|
@@ -32,6 +33,7 @@ export declare class RemoteHarness extends EventEmitter implements HarnessContra
|
|
|
32
33
|
private _open;
|
|
33
34
|
completion(context: HostContext<CompletionContext | import('./contract-types.ts').ResumeCompletionContext>): AsyncIterable<HarnessEvent>;
|
|
34
35
|
private _hop;
|
|
36
|
+
serveModelRound(request: ModelRoundRequest, io: HostContext<ModelRoundIo>): Promise<ModelRoundResult>;
|
|
35
37
|
invoke(context: HostContext<InvokeContext>): AsyncIterable<HarnessEvent>;
|
|
36
38
|
private _run;
|
|
37
39
|
download(context: HostContext<DownloadContext>): AsyncIterable<HarnessEvent>;
|
package/dist-lib/lib/connect.js
CHANGED
|
@@ -13,6 +13,8 @@ import { checkGoal, checkMaxToolRounds } from './capabilities/tool-turns.js';
|
|
|
13
13
|
import { Agent } from './agent/index.js';
|
|
14
14
|
import { readModelSourcePreview } from './capabilities/preview-model-source.js';
|
|
15
15
|
import { RunLog } from './run-log/index.js';
|
|
16
|
+
import { AbortedError } from './helpers/engine-error.js';
|
|
17
|
+
import { RoundHost } from './round-host.js';
|
|
16
18
|
import { HarnessLog } from './log.js';
|
|
17
19
|
import { assertEmbedDevice } from './models/embed-config.js';
|
|
18
20
|
import { addonTaskType } from './models/model-task.js';
|
|
@@ -23,7 +25,7 @@ import { sweepSpill } from './spill.js';
|
|
|
23
25
|
import { readInstall, readSetup } from './tools/skills/manifest-parse.js';
|
|
24
26
|
import { SKILL_STATE } from './tools/skills/skill-state.js';
|
|
25
27
|
import { asToolset } from './tools/toolsets.js';
|
|
26
|
-
import { fromDownloadWire, fromKnowledgeHitWire, fromKnowledgeStatusWire, fromKnowledgeUpsertResultWire, fromWire, toKnowledgeUpsertWire, unpackVectors } from './wire.js';
|
|
28
|
+
import { fromDownloadWire, roundResultFrom, fromKnowledgeHitWire, fromKnowledgeStatusWire, fromKnowledgeUpsertResultWire, fromWire, toKnowledgeUpsertWire, unpackVectors } from './wire.js';
|
|
27
29
|
export const HARNESS_DIED = 'HARNESS_DIED';
|
|
28
30
|
const PAUSE_GRACE_MS = 10_000;
|
|
29
31
|
export function connectHarness(transport, options = {}) {
|
|
@@ -151,6 +153,12 @@ export class RemoteHarness extends EventEmitter {
|
|
|
151
153
|
if (context.replaysContext) {
|
|
152
154
|
payload.replaysContext = true;
|
|
153
155
|
}
|
|
156
|
+
if (context.modelRound) {
|
|
157
|
+
payload.modelRound = true;
|
|
158
|
+
}
|
|
159
|
+
if (context.roundCut) {
|
|
160
|
+
payload.roundCut = true;
|
|
161
|
+
}
|
|
154
162
|
if (context.maxToolRounds !== undefined && context.maxToolRounds !== 0) {
|
|
155
163
|
payload.maxToolRounds = checkMaxToolRounds(context.maxToolRounds);
|
|
156
164
|
}
|
|
@@ -166,7 +174,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
166
174
|
generationParams: context.generationParams,
|
|
167
175
|
responseFormat: context.responseFormat,
|
|
168
176
|
captureInferenceCalls: context.captureInferenceCalls,
|
|
169
|
-
messages: context.messages?.map(({ role, content, attachments, toolCalls, toolCallId, name, id, context: added }) => ({
|
|
177
|
+
messages: context.messages?.map(({ role, content, attachments, toolCalls, toolCallId, name, id, context: added, sentAt }) => ({
|
|
170
178
|
role,
|
|
171
179
|
content,
|
|
172
180
|
attachments: attachments?.map(({ path: file }) => ({ path: file })),
|
|
@@ -174,7 +182,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
174
182
|
toolCallId,
|
|
175
183
|
name,
|
|
176
184
|
id,
|
|
177
|
-
context: added
|
|
185
|
+
context: added,
|
|
186
|
+
sentAt
|
|
178
187
|
})),
|
|
179
188
|
toolConfigs: context.toolConfigs,
|
|
180
189
|
grantedDirs: context.grantedDirs,
|
|
@@ -182,6 +191,25 @@ export class RemoteHarness extends EventEmitter {
|
|
|
182
191
|
grantedWriteDirs: context.grantedWriteDirs
|
|
183
192
|
}, { ...context, runId });
|
|
184
193
|
}
|
|
194
|
+
async serveModelRound(request, io) {
|
|
195
|
+
const aborted = abortedRound(io.signal);
|
|
196
|
+
const { client } = await Promise.race([this._ensure(), aborted]);
|
|
197
|
+
const duplex = client.completion();
|
|
198
|
+
const stop = () => duplex.destroy();
|
|
199
|
+
io.signal?.addEventListener?.('abort', stop, { once: true });
|
|
200
|
+
try {
|
|
201
|
+
const frame = { type: 'model-round-ask', payload: request };
|
|
202
|
+
encode('@harness/completion-frame', frame);
|
|
203
|
+
duplex.write(frame);
|
|
204
|
+
const served = servedRound(frames(duplex), io);
|
|
205
|
+
served.catch(noop);
|
|
206
|
+
return await Promise.race([served, aborted]);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
io.signal?.removeEventListener?.('abort', stop);
|
|
210
|
+
duplex.destroy();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
185
213
|
async *invoke(context) {
|
|
186
214
|
const agent = context.agent ?? {};
|
|
187
215
|
yield* this._run({
|
|
@@ -268,6 +296,12 @@ export class RemoteHarness extends EventEmitter {
|
|
|
268
296
|
};
|
|
269
297
|
let pauseTimer;
|
|
270
298
|
let started = false;
|
|
299
|
+
const rounds = context.modelRound &&
|
|
300
|
+
new RoundHost(context.modelRound, (frame) => {
|
|
301
|
+
if (!closed) {
|
|
302
|
+
send({ ...frame });
|
|
303
|
+
}
|
|
304
|
+
});
|
|
271
305
|
let failure = null;
|
|
272
306
|
const send = (frame) => {
|
|
273
307
|
if (!duplex)
|
|
@@ -327,6 +361,11 @@ export class RemoteHarness extends EventEmitter {
|
|
|
327
361
|
throw failure;
|
|
328
362
|
}
|
|
329
363
|
started = true;
|
|
364
|
+
context.roundCut?.((note) => {
|
|
365
|
+
if (!closed) {
|
|
366
|
+
send({ type: 'round-cut', message: note });
|
|
367
|
+
}
|
|
368
|
+
});
|
|
330
369
|
if (context.input) {
|
|
331
370
|
void sendInput(context.input, (item) => {
|
|
332
371
|
if (closed)
|
|
@@ -465,6 +504,14 @@ export class RemoteHarness extends EventEmitter {
|
|
|
465
504
|
context.progress?.(event.cleared ? null : { percentage: event.percentage ?? 0 });
|
|
466
505
|
continue;
|
|
467
506
|
}
|
|
507
|
+
if (event.type === 'model-round-ask') {
|
|
508
|
+
rounds?.ask(event.callId ?? '', event.payload);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (event.type === 'model-round-cancel') {
|
|
512
|
+
rounds?.cancel(event.callId ?? '');
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
468
515
|
const wire = fromWire(event);
|
|
469
516
|
if (wire.type === 'aborted' || wire.type === 'paused') {
|
|
470
517
|
emittedAborted = true;
|
|
@@ -494,6 +541,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
494
541
|
clearTimeout(pauseTimer);
|
|
495
542
|
duplex?.destroy();
|
|
496
543
|
closed = true;
|
|
544
|
+
rounds?.close();
|
|
497
545
|
reclaim();
|
|
498
546
|
if (hostLease && leasedRunId && context.runLog) {
|
|
499
547
|
let timer;
|
|
@@ -968,6 +1016,34 @@ function died(message) {
|
|
|
968
1016
|
return Object.assign(new Error(message), { code: HARNESS_DIED });
|
|
969
1017
|
}
|
|
970
1018
|
const noop = () => { };
|
|
1019
|
+
function abortedRound(signal) {
|
|
1020
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
1021
|
+
const abort = () => reject(new AbortedError());
|
|
1022
|
+
if (signal?.aborted) {
|
|
1023
|
+
abort();
|
|
1024
|
+
}
|
|
1025
|
+
signal?.addEventListener?.('abort', abort, { once: true });
|
|
1026
|
+
});
|
|
1027
|
+
aborted.catch(noop);
|
|
1028
|
+
return aborted;
|
|
1029
|
+
}
|
|
1030
|
+
async function servedRound(events, io) {
|
|
1031
|
+
let emit = io.emit;
|
|
1032
|
+
for await (const event of events) {
|
|
1033
|
+
if (io.signal?.aborted)
|
|
1034
|
+
break;
|
|
1035
|
+
if (event.type === 'content' || event.type === 'thinking') {
|
|
1036
|
+
emit({ type: event.type, text: event.text ?? '' });
|
|
1037
|
+
}
|
|
1038
|
+
else if (event.type === 'model-round-retake') {
|
|
1039
|
+
emit = io.retake();
|
|
1040
|
+
}
|
|
1041
|
+
else if (event.type === 'model-round-result') {
|
|
1042
|
+
return roundResultFrom(event);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
throw died('the harness ended a served round without its result');
|
|
1046
|
+
}
|
|
971
1047
|
function abortable(promise, signal) {
|
|
972
1048
|
if (!signal)
|
|
973
1049
|
return promise;
|
|
@@ -18,6 +18,7 @@ export interface Message {
|
|
|
18
18
|
name?: string | null;
|
|
19
19
|
id?: string | null;
|
|
20
20
|
context?: TurnContext | null;
|
|
21
|
+
sentAt?: number | undefined;
|
|
21
22
|
[key: string]: unknown;
|
|
22
23
|
}
|
|
23
24
|
export interface TurnContext {
|
|
@@ -53,6 +54,7 @@ export interface RunGoal {
|
|
|
53
54
|
ms?: number;
|
|
54
55
|
tokens?: number;
|
|
55
56
|
checks?: string[];
|
|
57
|
+
checksProve?: boolean;
|
|
56
58
|
}
|
|
57
59
|
export type ToolEffect = 'read' | 'write';
|
|
58
60
|
export type ToolDecision = 'auto' | 'allowed' | 'denied' | 'skip-all' | 'blocked';
|
|
@@ -2,6 +2,7 @@ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
|
2
2
|
import type { HarnessCapabilityProfile } from '../spec/hyperschema/types.d.ts';
|
|
3
3
|
import type { AccessPolicy, AgentHandoff, ApproveFn, AskUserFn, AttachFn, FetchAttachmentFn, HistoryToolCall, ProgressFn, ResourceDescriptor, ResponseFormat } from './contract/index.ts';
|
|
4
4
|
import type { KvCacheDeletionResult } from './capabilities/kv-cache.ts';
|
|
5
|
+
import type { ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
|
|
5
6
|
import type { ModelSourcePreview, PreviewModelSourceContext } from './capabilities/preview-model-source.ts';
|
|
6
7
|
import type { MemoryBudget } from './hardware/memory-budget.ts';
|
|
7
8
|
import type { EmbedDevice } from './models/embed-config.ts';
|
|
@@ -33,6 +34,7 @@ export type ChatMessage = {
|
|
|
33
34
|
name?: string | null;
|
|
34
35
|
id?: string | null;
|
|
35
36
|
context?: TurnContext | null;
|
|
37
|
+
sentAt?: number | undefined;
|
|
36
38
|
};
|
|
37
39
|
export interface AgentKnobs {
|
|
38
40
|
id?: string;
|
|
@@ -96,6 +98,8 @@ export interface CompletionContext {
|
|
|
96
98
|
requestDigestKey?: Uint8Array;
|
|
97
99
|
signal?: BareAbortSignal;
|
|
98
100
|
input?: AsyncIterable<RunInput>;
|
|
101
|
+
roundCut?: (cut: (note: string) => void) => void;
|
|
102
|
+
modelRound?: ModelRoundPort;
|
|
99
103
|
}
|
|
100
104
|
export interface HostSignal {
|
|
101
105
|
aborted?: boolean;
|
|
@@ -254,6 +258,7 @@ export interface InfraModel {
|
|
|
254
258
|
}
|
|
255
259
|
export interface HarnessContract {
|
|
256
260
|
completion(context: CompletionContext | ResumeCompletionContext): AsyncIterable<HarnessEvent>;
|
|
261
|
+
serveModelRound?(request: ModelRoundRequest, io: ModelRoundIo): Promise<ModelRoundResult>;
|
|
257
262
|
invoke?(context: InvokeContext): AsyncIterable<HarnessEvent>;
|
|
258
263
|
download?(context: DownloadContext): AsyncIterable<HarnessEvent>;
|
|
259
264
|
describe?(): Promise<HarnessInfo | null> | HarnessInfo;
|
package/dist-lib/lib/errors.d.ts
CHANGED
|
@@ -200,6 +200,10 @@ declare const HARNESS_ERRORS: {
|
|
|
200
200
|
readonly code: 102610;
|
|
201
201
|
readonly message: (filePath: string) => string;
|
|
202
202
|
};
|
|
203
|
+
readonly OBSIDIAN_PATH_IS_FOLDER: {
|
|
204
|
+
readonly code: 102611;
|
|
205
|
+
readonly message: (folder: string) => string;
|
|
206
|
+
};
|
|
203
207
|
readonly SKILL_FILE_NOT_FOUND: {
|
|
204
208
|
readonly code: 102701;
|
|
205
209
|
readonly message: (name: string, file: string) => string;
|
package/dist-lib/lib/errors.js
CHANGED
|
@@ -145,6 +145,12 @@ const HARNESS_ERRORS = {
|
|
|
145
145
|
code: 102610,
|
|
146
146
|
message: (filePath) => `Destination already exists: ${filePath}`
|
|
147
147
|
},
|
|
148
|
+
OBSIDIAN_PATH_IS_FOLDER: {
|
|
149
|
+
code: 102611,
|
|
150
|
+
message: (folder) => `"${folder || '.'}" is a folder, not a note. List it with ` +
|
|
151
|
+
(folder ? `\`obsidian files folder="${folder}"\`` : '`obsidian files`') +
|
|
152
|
+
', then read one note by its path.'
|
|
153
|
+
},
|
|
148
154
|
SKILL_FILE_NOT_FOUND: {
|
|
149
155
|
code: 102701,
|
|
150
156
|
message: (name, file) => `ENOENT: ${name}/${file}`
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface CpuPlacement {
|
|
2
|
+
threads: number;
|
|
3
|
+
mask: string;
|
|
4
|
+
}
|
|
5
|
+
export type ReadSysFile = (path: string) => string | null;
|
|
6
|
+
export declare function parseCpuList(list: string): number[];
|
|
7
|
+
export declare function performanceCorePlacement(read?: ReadSysFile, hostPlatform?: string): CpuPlacement | undefined;
|
|
8
|
+
export declare function androidCpuPlacement(): CpuPlacement | undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { platform } from 'os';
|
|
3
|
+
const CPU_ROOT = '/sys/devices/system/cpu';
|
|
4
|
+
function readSysFile(path) {
|
|
5
|
+
try {
|
|
6
|
+
return String(fs.readFileSync(path, 'utf8'));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function cpuRange(part) {
|
|
13
|
+
const [from, to = from] = part.split('-').map(Number);
|
|
14
|
+
if (!Number.isInteger(from) || !Number.isInteger(to) || to < from) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
18
|
+
}
|
|
19
|
+
export function parseCpuList(list) {
|
|
20
|
+
const ranges = list.trim().split(',').map(cpuRange);
|
|
21
|
+
return ranges.some((range) => range === null) ? [] : ranges.flat().filter((cpu) => cpu !== null);
|
|
22
|
+
}
|
|
23
|
+
function readCores(read, possible) {
|
|
24
|
+
return parseCpuList(possible).flatMap((cpu) => {
|
|
25
|
+
const maxFreq = Number(read(`${CPU_ROOT}/cpu${cpu}/cpufreq/cpuinfo_max_freq`)?.trim());
|
|
26
|
+
return Number.isFinite(maxFreq) && maxFreq > 0 ? [{ cpu, maxFreq }] : [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function placementOf(cores) {
|
|
30
|
+
const slowest = Math.min(...cores.map((core) => core.maxFreq));
|
|
31
|
+
const fast = cores.filter((core) => core.maxFreq > slowest);
|
|
32
|
+
if (fast.length === 0) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const mask = fast.reduce((bits, core) => bits | (1n << BigInt(core.cpu)), 0n);
|
|
36
|
+
return { threads: fast.length, mask: mask.toString(16) };
|
|
37
|
+
}
|
|
38
|
+
export function performanceCorePlacement(read = readSysFile, hostPlatform = platform()) {
|
|
39
|
+
if (hostPlatform !== 'android')
|
|
40
|
+
return undefined;
|
|
41
|
+
const possible = read(`${CPU_ROOT}/possible`);
|
|
42
|
+
return possible === null ? undefined : placementOf(readCores(read, possible));
|
|
43
|
+
}
|
|
44
|
+
let cached = null;
|
|
45
|
+
export function androidCpuPlacement() {
|
|
46
|
+
cached ??= { placement: performanceCorePlacement() };
|
|
47
|
+
return cached.placement;
|
|
48
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const MAX_GOAL_CHECKS = 8;
|
|
2
2
|
export declare const GOAL_CHECKS_ASK: string;
|
|
3
|
+
export declare const GOAL_PROOF_ASK: string;
|
|
3
4
|
export declare function namedChecks(text: string): string[];
|
|
5
|
+
export declare function mergeChecks(host: readonly string[], named: readonly string[]): string[];
|
|
4
6
|
export declare function runsCheck(command: string, check: string): boolean;
|
|
@@ -7,6 +7,11 @@ export const GOAL_CHECKS_ASK = '[This goal has no checks yet. Name the commands
|
|
|
7
7
|
'line `Checks:`, then one command per line in backticks, such as `test -s /app/result.json` ' +
|
|
8
8
|
'or `python3 check.py`. Each must exit 0 only once the task is done, with no pipe, ; or && ' +
|
|
9
9
|
'in it. The goal is met only once each of them ran on its own and exited 0.]';
|
|
10
|
+
export const GOAL_PROOF_ASK = '[The checks this goal has so far may only show that the output exists, not that it is right. Name the ' +
|
|
11
|
+
'commands that will prove the result is correct, such as running the program on an input ' +
|
|
12
|
+
"and comparing with what the task asks, or the task's own tests: write a line `Checks:`, " +
|
|
13
|
+
'then one command per line in backticks, with no pipe, ; or && in it. A command that repeats ' +
|
|
14
|
+
'one of those checks does not count. The goal is met only once each check ran on its own and exited 0.]';
|
|
10
15
|
export function namedChecks(text) {
|
|
11
16
|
const lines = text.split('\n');
|
|
12
17
|
const heading = lines.findIndex((line) => CHECKS_HEADING.test(line));
|
|
@@ -28,6 +33,19 @@ export function namedChecks(text) {
|
|
|
28
33
|
}
|
|
29
34
|
return named.slice(0, MAX_GOAL_CHECKS);
|
|
30
35
|
}
|
|
36
|
+
export function mergeChecks(host, named) {
|
|
37
|
+
const known = new Set(host.map(normalize));
|
|
38
|
+
const fresh = named
|
|
39
|
+
.filter((name) => !known.has(normalize(name)))
|
|
40
|
+
.slice(0, host.length ? MAX_GOAL_CHECKS - 1 : MAX_GOAL_CHECKS);
|
|
41
|
+
if (!fresh.length) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return [...host.slice(0, MAX_GOAL_CHECKS - fresh.length), ...fresh];
|
|
45
|
+
}
|
|
46
|
+
function normalize(command) {
|
|
47
|
+
return command.trim().replace(/\s+/g, ' ');
|
|
48
|
+
}
|
|
31
49
|
export function runsCheck(command, check) {
|
|
32
50
|
const wanted = words(check);
|
|
33
51
|
const parts = command.split(SHELL_OPERATOR);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function missingPeers(peers) {
|
|
2
|
+
return Object.keys(peers).filter((name) => !resolves(peers[name]));
|
|
3
|
+
}
|
|
4
|
+
export function requirePeers(subject, peers) {
|
|
5
|
+
const missing = missingPeers(peers);
|
|
6
|
+
if (missing.length === 0) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`${subject} needs ${missing.join(', ')}, not installed (optional peers of @qvac/harness): npm install ${missing.join(' ')}`);
|
|
10
|
+
}
|
|
11
|
+
function resolves(resolve) {
|
|
12
|
+
try {
|
|
13
|
+
resolve?.();
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const code = Reflect.get(Object(error), 'code');
|
|
18
|
+
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hasRoundsLeft } from '../guards/retry.js';
|
|
2
|
-
import { namedChecks } from '../../../helpers/goal-check.js';
|
|
2
|
+
import { mergeChecks, namedChecks } from '../../../helpers/goal-check.js';
|
|
3
3
|
import { activate, applyHistorySplice, applySplice, foldMetrics, goalMet, goalStalled, goalTokensLeft, nudgeWithChecks, nudgeWithPlan, retainFailureResults } from '../rules.js';
|
|
4
4
|
export function startInitialRound({ context, params }) {
|
|
5
5
|
return applyPreparation(context, params);
|
|
@@ -19,9 +19,18 @@ export function startNextRound({ context }) {
|
|
|
19
19
|
}
|
|
20
20
|
export function retryMuteRound(args) {
|
|
21
21
|
const { context } = args;
|
|
22
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
...silentTurn(args, muteReAsk(context)),
|
|
24
|
+
mute: context.mute + 1,
|
|
25
|
+
round: context.round + 1
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function muteReAsk(context) {
|
|
29
|
+
return context.goal && !context.steering.length && !goalMet(context)
|
|
30
|
+
? [{ role: 'user', content: goalTurn(context) }]
|
|
31
|
+
: continuation(context);
|
|
23
32
|
}
|
|
24
|
-
function silentTurn({ context, params }) {
|
|
33
|
+
function silentTurn({ context, params }, reAsk = continuation(context)) {
|
|
25
34
|
if (params.cutOff) {
|
|
26
35
|
return {};
|
|
27
36
|
}
|
|
@@ -29,7 +38,7 @@ function silentTurn({ context, params }) {
|
|
|
29
38
|
history: [
|
|
30
39
|
...context.history,
|
|
31
40
|
{ role: 'assistant', content: params.response?.trim() ?? '' },
|
|
32
|
-
...
|
|
41
|
+
...reAsk
|
|
33
42
|
],
|
|
34
43
|
steering: []
|
|
35
44
|
};
|
|
@@ -142,7 +151,7 @@ export function addKnowledge({ context, params }) {
|
|
|
142
151
|
};
|
|
143
152
|
}
|
|
144
153
|
export function goalTurn({ policy, goal, plan }) {
|
|
145
|
-
return nudgeWithChecks(nudgeWithPlan(`${policy.goalNudge}\nGoal: ${goal?.objective ?? ''}`, plan), goal?.checks ?? [], goal?.checkable);
|
|
154
|
+
return nudgeWithChecks(nudgeWithPlan(`${policy.goalNudge}\nGoal: ${goal?.objective ?? ''}`, plan), goal?.checks ?? [], goal?.checkable && !goal.named);
|
|
146
155
|
}
|
|
147
156
|
export function continueGoal({ context }) {
|
|
148
157
|
const { goal } = context;
|
|
@@ -201,13 +210,16 @@ export function finishWrapRound({ context, params }) {
|
|
|
201
210
|
};
|
|
202
211
|
}
|
|
203
212
|
function adoptChecks(goal, text) {
|
|
204
|
-
if (!goal?.checkable || goal.
|
|
213
|
+
if (!goal?.checkable || goal.named) {
|
|
214
|
+
return goal;
|
|
215
|
+
}
|
|
216
|
+
const host = goal.checks.map((check) => check.name);
|
|
217
|
+
const names = mergeChecks(host, namedChecks(text));
|
|
218
|
+
if (!names.length) {
|
|
205
219
|
return goal;
|
|
206
220
|
}
|
|
207
|
-
const
|
|
208
|
-
return named
|
|
209
|
-
? { ...goal, checks: named.map((name) => ({ name, passed: false, output: null })) }
|
|
210
|
-
: goal;
|
|
221
|
+
const checks = names.map((name) => goal.checks.find((check) => check.name === name) ?? { name, passed: false, output: null });
|
|
222
|
+
return { ...goal, checks, named: true };
|
|
211
223
|
}
|
|
212
224
|
function settledAfterSend(context, params) {
|
|
213
225
|
return params.history && params.history.at < context.history.length
|
|
@@ -249,9 +261,16 @@ export function answerCompletion({ context, params }) {
|
|
|
249
261
|
: history,
|
|
250
262
|
response: params.response || context.response,
|
|
251
263
|
metrics,
|
|
252
|
-
outcome: context.outcome ?? 'answered'
|
|
264
|
+
outcome: metGoalAnswered(context) ? 'answered' : (context.outcome ?? 'answered')
|
|
253
265
|
};
|
|
254
266
|
}
|
|
267
|
+
function metGoalAnswered(context) {
|
|
268
|
+
const round = context.lastRound;
|
|
269
|
+
return (context.outcome === 'mute' &&
|
|
270
|
+
context.goal !== null &&
|
|
271
|
+
goalMet(context) &&
|
|
272
|
+
Boolean(round?.contentText.trim() || round?.replay?.trim()));
|
|
273
|
+
}
|
|
255
274
|
export function failCompletion({ params }) {
|
|
256
275
|
const failure = 'tag' in params
|
|
257
276
|
? params
|