@qvac/harness 1.0.0-rc.20 → 1.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist-lib/index.d.ts +7 -5
- package/dist-lib/index.js +5 -4
- package/dist-lib/lib/agent/resolve.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +8 -6
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +8 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +8 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +3 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +9 -9
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -41
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +4 -133
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +42 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +7 -4
- package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +8 -54
- package/dist-lib/lib/capabilities/tool-turns.js +6 -281
- package/dist-lib/lib/client/index.js +3 -3
- package/dist-lib/lib/connect/abort.d.ts +6 -0
- package/dist-lib/lib/connect/abort.js +52 -0
- package/dist-lib/lib/connect/bridges.d.ts +21 -0
- package/dist-lib/lib/connect/bridges.js +185 -0
- package/dist-lib/lib/connect/decode.d.ts +31 -0
- package/dist-lib/lib/connect/decode.js +114 -0
- package/dist-lib/lib/connect/host-run-log.d.ts +16 -0
- package/dist-lib/lib/connect/host-run-log.js +74 -0
- package/dist-lib/lib/connect/served.d.ts +7 -0
- package/dist-lib/lib/connect/served.js +45 -0
- package/dist-lib/lib/connect.d.ts +3 -3
- package/dist-lib/lib/connect.js +24 -468
- package/dist-lib/lib/context-window.d.ts +13 -7
- package/dist-lib/lib/context-window.js +13 -6
- package/dist-lib/lib/contract/agent.d.ts +12 -1
- package/dist-lib/lib/contract/completion.d.ts +5 -1
- package/dist-lib/lib/contract/drive.d.ts +130 -4
- package/dist-lib/lib/contract/ocr.d.ts +5 -1
- package/dist-lib/lib/contract-types.d.ts +5 -3
- package/dist-lib/lib/errors.js +3 -3
- package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
- package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
- package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
- package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
- package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
- package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
- package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
- package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
- package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
- package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +35 -43
- package/dist-lib/lib/helpers/goal-check.js +34 -406
- package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
- package/dist-lib/lib/helpers/recent-map.js +23 -0
- package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
- package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.js +149 -0
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
- package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +12 -18
- package/dist-lib/lib/machine/completion/actions/completion.js +19 -178
- package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
- package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
- package/dist-lib/lib/machine/completion/actions/prepare.js +2 -1
- package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
- package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
- package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
- package/dist-lib/lib/machine/completion/actions/tools.js +16 -161
- package/dist-lib/lib/machine/completion/context.js +3 -3
- package/dist-lib/lib/machine/completion/implementations.d.ts +2 -2
- package/dist-lib/lib/machine/completion/implementations.js +6 -2
- package/dist-lib/lib/machine/completion/machine.d.ts +2 -2
- package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
- package/dist-lib/lib/machine/completion/metrics.js +68 -0
- package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
- package/dist-lib/lib/machine/completion/nudges.js +33 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +5 -34
- package/dist-lib/lib/machine/completion/rules.js +4 -120
- package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
- package/dist-lib/lib/machine/completion/splice.js +19 -0
- package/dist-lib/lib/machine/completion/types.d.ts +4 -13
- package/dist-lib/lib/machine/index.d.ts +3 -3
- package/dist-lib/lib/machine/index.js +2 -2
- package/dist-lib/lib/media-host.js +2 -2
- package/dist-lib/lib/media-wire.js +2 -2
- package/dist-lib/lib/residency/completion-runtime.d.ts +2 -1
- package/dist-lib/lib/residency/completion-runtime.js +44 -1
- package/dist-lib/lib/residency/index.d.ts +3 -2
- package/dist-lib/lib/residency/index.js +2 -2
- package/dist-lib/lib/round-host.js +3 -3
- package/dist-lib/lib/round-port.js +3 -3
- package/dist-lib/lib/run-log/redact.js +7 -7
- package/dist-lib/lib/serve/completion.d.ts +7 -0
- package/dist-lib/lib/serve/completion.js +553 -0
- package/dist-lib/lib/serve/downloads.d.ts +4 -0
- package/dist-lib/lib/serve/downloads.js +79 -0
- package/dist-lib/lib/serve/models.d.ts +5 -0
- package/dist-lib/lib/serve/models.js +120 -0
- package/dist-lib/lib/serve/noop.d.ts +1 -0
- package/dist-lib/lib/serve/noop.js +1 -0
- package/dist-lib/lib/serve/requests.d.ts +147 -0
- package/dist-lib/lib/serve/requests.js +1 -0
- package/dist-lib/lib/serve/rounds.d.ts +11 -0
- package/dist-lib/lib/serve/rounds.js +67 -0
- package/dist-lib/lib/serve/run-log-start.d.ts +38 -0
- package/dist-lib/lib/serve/run-log-start.js +254 -0
- package/dist-lib/lib/serve/skills.d.ts +32 -0
- package/dist-lib/lib/serve/skills.js +46 -0
- package/dist-lib/lib/serve.d.ts +5 -1
- package/dist-lib/lib/serve.js +14 -1071
- package/dist-lib/lib/skills-host/index.d.ts +4 -2
- package/dist-lib/lib/skills-host/index.js +20 -8
- package/dist-lib/lib/tools/fs/drive.d.ts +1 -17
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +1 -81
- package/dist-lib/lib/tools/fs/scope.d.ts +2 -17
- package/dist-lib/lib/tools/fs/search.d.ts +2 -18
- package/dist-lib/lib/tools/fs/walk.d.ts +1 -5
- package/dist-lib/lib/tools/pdf/build.d.ts +2 -2
- package/dist-lib/lib/tools/pdf/recognize.js +4 -8
- package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
- package/dist-lib/lib/tools/pdf/request.js +4 -4
- package/dist-lib/lib/tools/pdf.d.ts +0 -1
- package/dist-lib/lib/tools/pdf.js +0 -1
- package/dist-lib/lib/tools/skill.js +13 -4
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +3 -0
- package/dist-lib/lib/tools/skills/bundled-dir.js +27 -24
- package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
- package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
- package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
- package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
- package/dist-lib/lib/tools/skills/catalog.d.ts +5 -8
- package/dist-lib/lib/tools/skills/catalog.js +1 -162
- package/dist-lib/lib/tools/skills/index.d.ts +1 -0
- package/dist-lib/lib/tools/skills/index.js +1 -0
- package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
- package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
- package/dist-lib/lib/wire/download.d.ts +10 -0
- package/dist-lib/lib/wire/download.js +35 -0
- package/dist-lib/lib/wire/event.d.ts +41 -0
- package/dist-lib/lib/wire/event.js +306 -0
- package/dist-lib/lib/wire/fields.d.ts +3 -0
- package/dist-lib/lib/wire/fields.js +12 -0
- package/dist-lib/lib/wire/knowledge.d.ts +9 -0
- package/dist-lib/lib/wire/knowledge.js +68 -0
- package/dist-lib/lib/wire/round.d.ts +14 -0
- package/dist-lib/lib/wire/round.js +45 -0
- package/dist-lib/lib/wire/vectors.d.ts +6 -0
- package/dist-lib/lib/wire/vectors.js +33 -0
- package/dist-lib/lib/wire.d.ts +28 -77
- package/dist-lib/lib/wire.js +24 -489
- package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
- package/dist-lib/plugins/ocr/coverage.js +67 -0
- package/dist-lib/plugins/ocr/ocr-runtime.d.ts +4 -2
- package/dist-lib/plugins/ocr/ocr-runtime.js +25 -4
- 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 -1
- package/dist-lib/spec/hrpc/messages.js +25 -1
- package/dist-lib/spec/hyperschema/index.js +25 -1
- package/dist-lib/spec/hyperschema/schema.json +6 -1
- package/dist-lib/spec/hyperschema/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { assign, enqueueActions } from 'xstate';
|
|
2
2
|
import { isFailureResultReference } from '../../helpers/failure-result.js';
|
|
3
3
|
import { approveCompletion, requestApproval } from './actions/approval.js';
|
|
4
|
-
import {
|
|
4
|
+
import { answerCompletion, failCompletion, finishWrapRound, finishRound, wrapCompletion, wrapCutCompletion, wrapDeliveredCompletion, wrapExhaustedCompletion, wrapMuteCompletion, wrapSearchCappedCompletion } from './actions/completion.js';
|
|
5
|
+
import { continueGoal, continueStalledGoal, continueStop, markGoalStalled, settleGoal } from './actions/goal.js';
|
|
5
6
|
import { authorizePrepare, requestPrepare, settlePrepare, settlePrepareFailure } from './actions/prepare.js';
|
|
6
|
-
import {
|
|
7
|
+
import { retryCappedSearch, retryCutRound, retryMalformedRound, retryMuteRound, retryNarratedRound } from './actions/retry-round.js';
|
|
8
|
+
import { rejectCutOffTool, rejectDeniedApproval, rejectPlanModeWrite, rejectRepeatedTool, rejectTool } from './actions/reject-tool.js';
|
|
9
|
+
import { addKnowledge, continueWithFollowUps, startInitialRound, startNextRound } from './actions/rounds.js';
|
|
10
|
+
import { finishBatch, finishDirectTool, finishTool, endRunOnTool, queueDirectSearch, resolveTools, selectNextTool, startDirectTool, startTool } from './actions/tools.js';
|
|
7
11
|
import { allResolvedToolsCapped, canMuteRetry, canRetryCut, canRetryMalformed, canRetryNarrated, canRetrySearchCap, hasQueuedTool, hasRoundsLeft, repeatsBlocked, searchPending } from './guards/retry.js';
|
|
8
12
|
import { goalMet, goalStalled, goalTokensLeft, leadingReads, runsUnasked } from './rules.js';
|
|
9
13
|
function output(event) {
|
|
@@ -204,13 +204,13 @@ declare const createCompletionMachineImplementation: (context?: CompletionContex
|
|
|
204
204
|
params: RejectDeniedApprovalParams;
|
|
205
205
|
} | {
|
|
206
206
|
type: "rejectPlanModeWrite";
|
|
207
|
-
params: import("./actions/
|
|
207
|
+
params: import("./actions/reject-tool.ts").RejectPlanModeWriteParams;
|
|
208
208
|
} | {
|
|
209
209
|
type: "rejectRepeatedTool";
|
|
210
210
|
params: import("./types.ts").RepeatOfFailedCallParams;
|
|
211
211
|
} | {
|
|
212
212
|
type: "rejectTool";
|
|
213
|
-
params: import("./actions/
|
|
213
|
+
params: import("./actions/reject-tool.ts").RejectToolParams;
|
|
214
214
|
} | {
|
|
215
215
|
type: "requestApproval";
|
|
216
216
|
params: import("./types.ts").ApprovalCall;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RoundSpeed, RunBackendUse, ToolSpeed } from '../../contract/run.ts';
|
|
2
|
+
import type { CompletionStats } from './types.ts';
|
|
3
|
+
export interface MetricsState {
|
|
4
|
+
ttft?: number;
|
|
5
|
+
tokens: number;
|
|
6
|
+
timedTokens: number;
|
|
7
|
+
decodeMs: number;
|
|
8
|
+
promptTokens?: number;
|
|
9
|
+
cacheTokens?: number;
|
|
10
|
+
ctxSize?: number | undefined;
|
|
11
|
+
backends?: RunBackendUse[];
|
|
12
|
+
stopReason?: string | undefined;
|
|
13
|
+
rounds: RoundSpeed[];
|
|
14
|
+
tools: ToolSpeed[];
|
|
15
|
+
}
|
|
16
|
+
export interface FinishedRound {
|
|
17
|
+
stats?: CompletionStats | undefined;
|
|
18
|
+
stopReason?: string | undefined;
|
|
19
|
+
durationMs?: number | undefined;
|
|
20
|
+
ctxSize?: number | undefined;
|
|
21
|
+
overflows?: number | undefined;
|
|
22
|
+
reasoningDeltas?: number | undefined;
|
|
23
|
+
keyed?: boolean | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare function foldMetrics(state: MetricsState, round: number, finished: FinishedRound): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { atContextBoundary } from './rules.js';
|
|
2
|
+
export function foldMetrics(state, round, finished) {
|
|
3
|
+
const { stats, stopReason } = finished;
|
|
4
|
+
state.stopReason = stopReason;
|
|
5
|
+
state.rounds = [...state.rounds, roundSpeed(round, finished)];
|
|
6
|
+
if (finished.ctxSize) {
|
|
7
|
+
state.ctxSize = finished.ctxSize;
|
|
8
|
+
}
|
|
9
|
+
if (!stats) {
|
|
10
|
+
if (finished.keyed === false) {
|
|
11
|
+
delete state.cacheTokens;
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (state.ttft === undefined && stats.timeToFirstToken) {
|
|
16
|
+
state.ttft = stats.timeToFirstToken;
|
|
17
|
+
}
|
|
18
|
+
if (stats.generatedTokens) {
|
|
19
|
+
state.tokens += stats.generatedTokens;
|
|
20
|
+
if (stats.tokensPerSecond) {
|
|
21
|
+
state.decodeMs += (stats.generatedTokens / stats.tokensPerSecond) * 1000;
|
|
22
|
+
state.timedTokens += stats.generatedTokens;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (stats.promptTokens !== undefined) {
|
|
26
|
+
state.promptTokens = stats.promptTokens;
|
|
27
|
+
}
|
|
28
|
+
if (stats.cacheTokens !== undefined) {
|
|
29
|
+
state.cacheTokens = stats.cacheTokens;
|
|
30
|
+
}
|
|
31
|
+
if (finished.keyed === false && stats.cacheTokens === undefined) {
|
|
32
|
+
delete state.cacheTokens;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const ROUND_STATS = [
|
|
36
|
+
'promptTokens',
|
|
37
|
+
'cacheTokens',
|
|
38
|
+
'generatedTokens',
|
|
39
|
+
'promptTokensPerSecond',
|
|
40
|
+
'tokensPerSecond',
|
|
41
|
+
'timeToFirstToken',
|
|
42
|
+
'avgConcurrentSeq'
|
|
43
|
+
];
|
|
44
|
+
function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoningDeltas, keyed }) {
|
|
45
|
+
const speed = { round, durationMs: durationMs ?? 0 };
|
|
46
|
+
for (const key of ROUND_STATS) {
|
|
47
|
+
const value = stats?.[key];
|
|
48
|
+
if (value !== undefined) {
|
|
49
|
+
speed[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (keyed === false) {
|
|
53
|
+
speed.cacheTokens = 0;
|
|
54
|
+
}
|
|
55
|
+
if (stopReason) {
|
|
56
|
+
speed.stopReason = stopReason;
|
|
57
|
+
}
|
|
58
|
+
if (overflows) {
|
|
59
|
+
speed.overflows = overflows;
|
|
60
|
+
}
|
|
61
|
+
if (atContextBoundary({ stats, stopReason })) {
|
|
62
|
+
speed.contextBoundary = true;
|
|
63
|
+
}
|
|
64
|
+
if (reasoningDeltas) {
|
|
65
|
+
speed.reasoningDeltas = reasoningDeltas;
|
|
66
|
+
}
|
|
67
|
+
return speed;
|
|
68
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PlanStep } from '../../contract/run.ts';
|
|
2
|
+
import type { GoalCheck as CheckedGoal } from './types.ts';
|
|
3
|
+
export declare function nudgeWithPlan(nudge: string, plan: readonly PlanStep[]): string;
|
|
4
|
+
export declare function imagesShownNote(fileNames: readonly string[]): string;
|
|
5
|
+
export declare function nudgeWithChecks(nudge: string, checks: readonly CheckedGoal[], unnamed?: boolean): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GoalCheck } from '../../helpers/goal-check.js';
|
|
2
|
+
import { isDone } from './rules.js';
|
|
3
|
+
const PLAN_MARKS = {
|
|
4
|
+
pending: '[ ]',
|
|
5
|
+
in_progress: '[>]',
|
|
6
|
+
done: '[x]'
|
|
7
|
+
};
|
|
8
|
+
export function nudgeWithPlan(nudge, plan) {
|
|
9
|
+
if (plan.every(isDone)) {
|
|
10
|
+
return nudge;
|
|
11
|
+
}
|
|
12
|
+
const lines = plan.map(({ step, status }) => `${PLAN_MARKS[status]} ${step}`);
|
|
13
|
+
return `${nudge}\nPlan:\n${lines.join('\n')}`;
|
|
14
|
+
}
|
|
15
|
+
export function imagesShownNote(fileNames) {
|
|
16
|
+
const named = fileNames.map((name) => `"${name}"`).join(', ');
|
|
17
|
+
return fileNames.length === 1
|
|
18
|
+
? `[The image at the start of this turn is ${named}, which a tool above attached. You can see it: use what it shows, with no tool to open it.]`
|
|
19
|
+
: `[The images at the start of this turn are ${named}, which tools above attached. You can see them: use what they show, with no tool to open them.]`;
|
|
20
|
+
}
|
|
21
|
+
export function nudgeWithChecks(nudge, checks, unnamed) {
|
|
22
|
+
if (!checks.length) {
|
|
23
|
+
return unnamed ? `${nudge}\n${GoalCheck.GOAL_CHECKS_ASK}` : nudge;
|
|
24
|
+
}
|
|
25
|
+
const asked = unnamed ? `${nudge}\n${GoalCheck.GOAL_PROOF_ASK}` : nudge;
|
|
26
|
+
const open = checks.filter((check) => !check.passed);
|
|
27
|
+
if (!open.length) {
|
|
28
|
+
return asked;
|
|
29
|
+
}
|
|
30
|
+
const lines = open.map(({ name, output }) => output === null ? `- ${name}: not run yet` : `- ${name}: failed. Its last output:\n${output}`);
|
|
31
|
+
return (`${asked}\nChecks: the goal is met only once each of these runs as its own command and ` +
|
|
32
|
+
`exits 0, with no pipe or ; after it to hide its exit code.\n${lines.join('\n')}`);
|
|
33
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CompletionHistoryEntry,
|
|
1
|
+
import type { CompletionHistoryEntry, PlanStep } from '../../contract/run.ts';
|
|
2
2
|
import { type FailureResultValue } from '../../helpers/failure-result.ts';
|
|
3
|
-
import type { CompletionStats,
|
|
3
|
+
import type { CompletionStats, RunPolicy, SettledCall, CompletionContext, ResolvedCallSnapshot, ToolPreflightFacts } from './types.ts';
|
|
4
4
|
export declare function runsUnasked(facts: Pick<ToolPreflightFacts, 'effect' | 'autoApprove' | 'skipApprovals' | 'permission'>): boolean;
|
|
5
5
|
export declare const MAX_MUTE_ROUNDS = 1;
|
|
6
6
|
export declare const MAX_CUT_ROUNDS = 2;
|
|
@@ -10,52 +10,23 @@ export declare const MAX_UNCHANGED_RESULTS = 3;
|
|
|
10
10
|
export declare const MAX_ROUND_REPEATS = 3;
|
|
11
11
|
export declare const MAX_ROUND_CALLS = 32;
|
|
12
12
|
export declare const MAX_SHOWN_IMAGES = 4;
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function imagesShownNote(fileNames: readonly string[]): string;
|
|
13
|
+
export declare function isDone(step: PlanStep): boolean;
|
|
15
14
|
export declare function goalMet(context: Readonly<CompletionContext>): boolean;
|
|
16
15
|
export declare function casesDue(context: Readonly<CompletionContext>): boolean;
|
|
17
16
|
export declare function checksMet({ plan, goal }: Readonly<CompletionContext>): boolean;
|
|
18
|
-
export declare function nudgeWithChecks(nudge: string, checks: readonly GoalCheck[], unnamed?: boolean): string;
|
|
19
17
|
export declare function goalTokensLeft({ goal, metrics }: Readonly<CompletionContext>): boolean;
|
|
20
18
|
export declare function goalStalled({ outcome }: Readonly<CompletionContext>): boolean;
|
|
21
19
|
export declare function settledSince(settled: CompletionContext['settledResults']): CompletionContext['settledResults'];
|
|
22
20
|
export declare function retainFailureResults(history: readonly CompletionHistoryEntry[], values: Readonly<Record<string, FailureResultValue>>, failedCalls: Readonly<Record<string, SettledCall>>): Record<string, FailureResultValue>;
|
|
23
21
|
export declare function activate(activated: string[], names: readonly string[]): string[];
|
|
24
|
-
|
|
25
|
-
failedCalls?: Readonly<Record<string, SettledCall>>;
|
|
26
|
-
failureResults?: Readonly<Record<string, FailureResultValue>>;
|
|
27
|
-
}
|
|
28
|
-
export declare function applyHistorySplice(context: Readonly<CompletionContext>, splice?: HistorySplice, options?: ApplyHistorySpliceOptions): Pick<CompletionContext, 'history' | 'failureResults'>;
|
|
29
|
-
export interface MetricsState {
|
|
30
|
-
ttft?: number;
|
|
31
|
-
tokens: number;
|
|
32
|
-
timedTokens: number;
|
|
33
|
-
decodeMs: number;
|
|
34
|
-
promptTokens?: number;
|
|
35
|
-
cacheTokens?: number;
|
|
36
|
-
ctxSize?: number | undefined;
|
|
37
|
-
backends?: RunBackendUse[];
|
|
38
|
-
stopReason?: string | undefined;
|
|
39
|
-
rounds: RoundSpeed[];
|
|
40
|
-
tools: ToolSpeed[];
|
|
41
|
-
}
|
|
42
|
-
export interface FinishedRound {
|
|
22
|
+
interface StoppedRound {
|
|
43
23
|
stats?: CompletionStats | undefined;
|
|
44
24
|
stopReason?: string | undefined;
|
|
45
|
-
durationMs?: number | undefined;
|
|
46
|
-
ctxSize?: number | undefined;
|
|
47
|
-
overflows?: number | undefined;
|
|
48
|
-
reasoningDeltas?: number | undefined;
|
|
49
|
-
keyed?: boolean | undefined;
|
|
50
|
-
}
|
|
51
|
-
export declare function foldMetrics(state: MetricsState, round: number, finished: FinishedRound): void;
|
|
52
|
-
type StoppedRound = Pick<FinishedRound, 'stats' | 'stopReason'> & {
|
|
53
25
|
cut?: string | undefined;
|
|
54
|
-
}
|
|
26
|
+
}
|
|
55
27
|
export declare function atContextBoundary({ stats, stopReason }: StoppedRound): boolean;
|
|
56
28
|
export declare function cutShort(round: StoppedRound): boolean;
|
|
57
29
|
export declare function cutOffMessage(policy: RunPolicy, round: StoppedRound | null): string;
|
|
58
30
|
export declare function recordTool(context: Readonly<CompletionContext>, call: ResolvedCallSnapshot | null, durationMs: number | undefined): CompletionContext['metrics'];
|
|
59
31
|
export declare function leadingReads(context: Readonly<CompletionContext>): number;
|
|
60
|
-
export declare function applySplice(history: CompletionHistoryEntry[], splice?: HistorySplice): CompletionHistoryEntry[];
|
|
61
32
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isFailureResultReference } from '../../helpers/failure-result.js';
|
|
2
|
-
import {
|
|
2
|
+
import { GoalCheck } from '../../helpers/goal-check.js';
|
|
3
3
|
export function runsUnasked(facts) {
|
|
4
4
|
if (facts.permission === 'ask')
|
|
5
5
|
return false;
|
|
@@ -16,25 +16,7 @@ export const MAX_UNCHANGED_RESULTS = 3;
|
|
|
16
16
|
export const MAX_ROUND_REPEATS = 3;
|
|
17
17
|
export const MAX_ROUND_CALLS = 32;
|
|
18
18
|
export const MAX_SHOWN_IMAGES = 4;
|
|
19
|
-
|
|
20
|
-
pending: '[ ]',
|
|
21
|
-
in_progress: '[>]',
|
|
22
|
-
done: '[x]'
|
|
23
|
-
};
|
|
24
|
-
export function nudgeWithPlan(nudge, plan) {
|
|
25
|
-
if (plan.every(isDone)) {
|
|
26
|
-
return nudge;
|
|
27
|
-
}
|
|
28
|
-
const lines = plan.map(({ step, status }) => `${PLAN_MARKS[status]} ${step}`);
|
|
29
|
-
return `${nudge}\nPlan:\n${lines.join('\n')}`;
|
|
30
|
-
}
|
|
31
|
-
export function imagesShownNote(fileNames) {
|
|
32
|
-
const named = fileNames.map((name) => `"${name}"`).join(', ');
|
|
33
|
-
return fileNames.length === 1
|
|
34
|
-
? `[The image at the start of this turn is ${named}, which a tool above attached. You can see it: use what it shows, with no tool to open it.]`
|
|
35
|
-
: `[The images at the start of this turn are ${named}, which tools above attached. You can see them: use what they show, with no tool to open them.]`;
|
|
36
|
-
}
|
|
37
|
-
function isDone(step) {
|
|
19
|
+
export function isDone(step) {
|
|
38
20
|
return step.status === 'done';
|
|
39
21
|
}
|
|
40
22
|
function planDone(plan) {
|
|
@@ -57,26 +39,13 @@ function halfLeft({ halfTime, round, policy, goal, metrics }) {
|
|
|
57
39
|
export function checksMet({ plan, goal }) {
|
|
58
40
|
const checks = goal?.checks ?? [];
|
|
59
41
|
return (planDone(plan) &&
|
|
60
|
-
!(goal && asksChecks(goal)) &&
|
|
42
|
+
!(goal && GoalCheck.asksChecks(goal)) &&
|
|
61
43
|
checks.every((check) => check.passed) &&
|
|
62
|
-
(!goal || (deliverableChecked(goal) && !codeUnrun(goal))));
|
|
44
|
+
(!goal || (GoalCheck.deliverableChecked(goal) && !GoalCheck.codeUnrun(goal))));
|
|
63
45
|
}
|
|
64
46
|
function reviewPending(goal) {
|
|
65
47
|
return !!goal?.checkable && (goal.review === 'due' || goal.review === 'asked');
|
|
66
48
|
}
|
|
67
|
-
export function nudgeWithChecks(nudge, checks, unnamed) {
|
|
68
|
-
if (!checks.length) {
|
|
69
|
-
return unnamed ? `${nudge}\n${GOAL_CHECKS_ASK}` : nudge;
|
|
70
|
-
}
|
|
71
|
-
const asked = unnamed ? `${nudge}\n${GOAL_PROOF_ASK}` : nudge;
|
|
72
|
-
const open = checks.filter((check) => !check.passed);
|
|
73
|
-
if (!open.length) {
|
|
74
|
-
return asked;
|
|
75
|
-
}
|
|
76
|
-
const lines = open.map(({ name, output }) => output === null ? `- ${name}: not run yet` : `- ${name}: failed. Its last output:\n${output}`);
|
|
77
|
-
return (`${asked}\nChecks: the goal is met only once each of these runs as its own command and ` +
|
|
78
|
-
`exits 0, with no pipe or ; after it to hide its exit code.\n${lines.join('\n')}`);
|
|
79
|
-
}
|
|
80
49
|
export function goalTokensLeft({ goal, metrics }) {
|
|
81
50
|
return !goal || goal.tokens === null || metrics.tokens < goal.tokens;
|
|
82
51
|
}
|
|
@@ -106,82 +75,6 @@ export function activate(activated, names) {
|
|
|
106
75
|
const added = names.filter((name, at) => !activated.includes(name) && names.indexOf(name) === at);
|
|
107
76
|
return added.length ? [...activated, ...added] : activated;
|
|
108
77
|
}
|
|
109
|
-
export function applyHistorySplice(context, splice, options = {}) {
|
|
110
|
-
const failedCalls = options.failedCalls ?? context.failedCalls;
|
|
111
|
-
const failureResults = options.failureResults ?? context.failureResults;
|
|
112
|
-
const history = applySplice(context.history, splice);
|
|
113
|
-
return {
|
|
114
|
-
history,
|
|
115
|
-
failureResults: retainFailureResults(history, failureResults, failedCalls)
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export function foldMetrics(state, round, finished) {
|
|
119
|
-
const { stats, stopReason } = finished;
|
|
120
|
-
state.stopReason = stopReason;
|
|
121
|
-
state.rounds = [...state.rounds, roundSpeed(round, finished)];
|
|
122
|
-
if (finished.ctxSize) {
|
|
123
|
-
state.ctxSize = finished.ctxSize;
|
|
124
|
-
}
|
|
125
|
-
if (!stats) {
|
|
126
|
-
if (finished.keyed === false) {
|
|
127
|
-
delete state.cacheTokens;
|
|
128
|
-
}
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (state.ttft === undefined && stats.timeToFirstToken) {
|
|
132
|
-
state.ttft = stats.timeToFirstToken;
|
|
133
|
-
}
|
|
134
|
-
if (stats.generatedTokens) {
|
|
135
|
-
state.tokens += stats.generatedTokens;
|
|
136
|
-
if (stats.tokensPerSecond) {
|
|
137
|
-
state.decodeMs += (stats.generatedTokens / stats.tokensPerSecond) * 1000;
|
|
138
|
-
state.timedTokens += stats.generatedTokens;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (stats.promptTokens !== undefined) {
|
|
142
|
-
state.promptTokens = stats.promptTokens;
|
|
143
|
-
}
|
|
144
|
-
if (stats.cacheTokens !== undefined) {
|
|
145
|
-
state.cacheTokens = stats.cacheTokens;
|
|
146
|
-
}
|
|
147
|
-
if (finished.keyed === false && stats.cacheTokens === undefined) {
|
|
148
|
-
delete state.cacheTokens;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const ROUND_STATS = [
|
|
152
|
-
'promptTokens',
|
|
153
|
-
'cacheTokens',
|
|
154
|
-
'generatedTokens',
|
|
155
|
-
'promptTokensPerSecond',
|
|
156
|
-
'tokensPerSecond',
|
|
157
|
-
'timeToFirstToken',
|
|
158
|
-
'avgConcurrentSeq'
|
|
159
|
-
];
|
|
160
|
-
function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoningDeltas, keyed }) {
|
|
161
|
-
const speed = { round, durationMs: durationMs ?? 0 };
|
|
162
|
-
for (const key of ROUND_STATS) {
|
|
163
|
-
const value = stats?.[key];
|
|
164
|
-
if (value !== undefined) {
|
|
165
|
-
speed[key] = value;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (keyed === false) {
|
|
169
|
-
speed.cacheTokens = 0;
|
|
170
|
-
}
|
|
171
|
-
if (stopReason) {
|
|
172
|
-
speed.stopReason = stopReason;
|
|
173
|
-
}
|
|
174
|
-
if (overflows) {
|
|
175
|
-
speed.overflows = overflows;
|
|
176
|
-
}
|
|
177
|
-
if (atContextBoundary({ stats, stopReason })) {
|
|
178
|
-
speed.contextBoundary = true;
|
|
179
|
-
}
|
|
180
|
-
if (reasoningDeltas) {
|
|
181
|
-
speed.reasoningDeltas = reasoningDeltas;
|
|
182
|
-
}
|
|
183
|
-
return speed;
|
|
184
|
-
}
|
|
185
78
|
export function atContextBoundary({ stats, stopReason }) {
|
|
186
79
|
return stopReason === 'length' && stats?.contextBoundary !== false;
|
|
187
80
|
}
|
|
@@ -210,12 +103,3 @@ export function leadingReads(context) {
|
|
|
210
103
|
}
|
|
211
104
|
return keys.size;
|
|
212
105
|
}
|
|
213
|
-
export function applySplice(history, splice) {
|
|
214
|
-
if (!splice) {
|
|
215
|
-
return history;
|
|
216
|
-
}
|
|
217
|
-
if (splice.at === history.length && !splice.messages.length) {
|
|
218
|
-
return history;
|
|
219
|
-
}
|
|
220
|
-
return [...history.slice(0, splice.at), ...splice.messages];
|
|
221
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CompletionHistoryEntry, HistorySplice } from '../../contract/run.ts';
|
|
2
|
+
import type { FailureResultValue } from '../../helpers/failure-result.ts';
|
|
3
|
+
import type { CompletionContext, SettledCall } from './types.ts';
|
|
4
|
+
export interface ApplyHistorySpliceOptions {
|
|
5
|
+
failedCalls?: Readonly<Record<string, SettledCall>>;
|
|
6
|
+
failureResults?: Readonly<Record<string, FailureResultValue>>;
|
|
7
|
+
}
|
|
8
|
+
export declare function applyHistorySplice(context: Readonly<CompletionContext>, splice?: HistorySplice, options?: ApplyHistorySpliceOptions): Pick<CompletionContext, 'history' | 'failureResults'>;
|
|
9
|
+
export declare function applySplice(history: CompletionHistoryEntry[], splice?: HistorySplice): CompletionHistoryEntry[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { retainFailureResults } from './rules.js';
|
|
2
|
+
export function applyHistorySplice(context, splice, options = {}) {
|
|
3
|
+
const failedCalls = options.failedCalls ?? context.failedCalls;
|
|
4
|
+
const failureResults = options.failureResults ?? context.failureResults;
|
|
5
|
+
const history = applySplice(context.history, splice);
|
|
6
|
+
return {
|
|
7
|
+
history,
|
|
8
|
+
failureResults: retainFailureResults(history, failureResults, failedCalls)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function applySplice(history, splice) {
|
|
12
|
+
if (!splice) {
|
|
13
|
+
return history;
|
|
14
|
+
}
|
|
15
|
+
if (splice.at === history.length && !splice.messages.length) {
|
|
16
|
+
return history;
|
|
17
|
+
}
|
|
18
|
+
return [...history.slice(0, splice.at), ...splice.messages];
|
|
19
|
+
}
|
|
@@ -30,7 +30,7 @@ export interface EngineEvent {
|
|
|
30
30
|
export interface EngineFacts extends Record<string, unknown> {
|
|
31
31
|
runBudget: RunBudget;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
interface CompletionMetrics {
|
|
34
34
|
ttft?: number;
|
|
35
35
|
tokens: number;
|
|
36
36
|
timedTokens: number;
|
|
@@ -57,7 +57,7 @@ export interface ApprovalCall {
|
|
|
57
57
|
display?: ToolCallDisplay | null;
|
|
58
58
|
quote?: string | null;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
interface RoundToolCall {
|
|
61
61
|
id: string;
|
|
62
62
|
name: string;
|
|
63
63
|
arguments: Record<string, unknown>;
|
|
@@ -180,7 +180,7 @@ export interface SettledCall {
|
|
|
180
180
|
resultRef: string;
|
|
181
181
|
outcome: ToolExecutionOutcome;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
type RejectedToolResult = {
|
|
184
184
|
result: unknown;
|
|
185
185
|
resultRef?: never;
|
|
186
186
|
} | {
|
|
@@ -199,16 +199,6 @@ export type ToolRejectedPayload = RejectedToolResult & {
|
|
|
199
199
|
source: 'skill' | 'tool-result';
|
|
200
200
|
repeat?: ToolExecutionOutcome;
|
|
201
201
|
};
|
|
202
|
-
export type ToolPolicyRejection = 'skill-already-loaded' | 'skill-unready' | 'skill-unavailable' | 'search-cap' | 'hook-rejected' | 'unknown-tool' | 'validation' | 'outbound-refusal' | 'already-denied' | 'denied-without-approver';
|
|
203
|
-
export type DirectToolRejectedPayload = ToolRejectedPayload & {
|
|
204
|
-
execution: ToolExecutionSnapshot;
|
|
205
|
-
preparation: PreparingPayload;
|
|
206
|
-
};
|
|
207
|
-
export interface ToolStartedPayload {
|
|
208
|
-
call: ResolvedCallSnapshot;
|
|
209
|
-
execution: ToolExecutionSnapshot;
|
|
210
|
-
preparation: PreparingPayload;
|
|
211
|
-
}
|
|
212
202
|
export interface PreparingPayload {
|
|
213
203
|
history?: HistorySplice;
|
|
214
204
|
activated?: string[];
|
|
@@ -490,3 +480,4 @@ export type CompletionMachineEvent = {
|
|
|
490
480
|
context?: TurnContext;
|
|
491
481
|
content?: string;
|
|
492
482
|
};
|
|
483
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { goalStatus } from './completion/actions/
|
|
1
|
+
import { goalStatus } from './completion/actions/goal.ts';
|
|
2
2
|
import { emptyCompletionContext } from './completion/context.ts';
|
|
3
3
|
import { atContextBoundary, cutOffMessage, cutShort, runsUnasked } from './completion/rules.ts';
|
|
4
4
|
import { repeatsBlocked } from './completion/guards/retry.ts';
|
|
@@ -210,13 +210,13 @@ export declare class CompletionMachine {
|
|
|
210
210
|
params: import("./completion/types.ts").RejectDeniedApprovalParams;
|
|
211
211
|
} | {
|
|
212
212
|
type: "rejectPlanModeWrite";
|
|
213
|
-
params: import("./completion/actions/
|
|
213
|
+
params: import("./completion/actions/reject-tool.ts").RejectPlanModeWriteParams;
|
|
214
214
|
} | {
|
|
215
215
|
type: "rejectRepeatedTool";
|
|
216
216
|
params: import("./completion/types.ts").RepeatOfFailedCallParams;
|
|
217
217
|
} | {
|
|
218
218
|
type: "rejectTool";
|
|
219
|
-
params: import("./completion/actions/
|
|
219
|
+
params: import("./completion/actions/reject-tool.ts").RejectToolParams;
|
|
220
220
|
} | {
|
|
221
221
|
type: "requestApproval";
|
|
222
222
|
params: import("./completion/types.ts").ApprovalCall;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { goalStatus } from './completion/actions/
|
|
2
|
-
import { PLAN_MODE_REFUSAL } from './completion/actions/
|
|
1
|
+
import { goalStatus } from './completion/actions/goal.js';
|
|
2
|
+
import { PLAN_MODE_REFUSAL } from './completion/actions/reject-tool.js';
|
|
3
3
|
import { emptyCompletionContext } from './completion/context.js';
|
|
4
4
|
import { createCompletionMachine } from './completion/machine.js';
|
|
5
5
|
import { atContextBoundary, cutOffMessage, cutShort, MAX_ROUND_CALLS, MAX_ROUND_REPEATS, MAX_SHOWN_IMAGES, runsUnasked } from './completion/rules.js';
|
|
@@ -2,7 +2,7 @@ import { AbortController } from 'bare-abort-controller';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { mediaRequestFrom, mediaResultWire } from './media-wire.js';
|
|
4
4
|
import { pushQueue } from './queue.js';
|
|
5
|
-
import {
|
|
5
|
+
import { Wire } from './wire.js';
|
|
6
6
|
export class MediaHost {
|
|
7
7
|
_port;
|
|
8
8
|
_out = pushQueue();
|
|
@@ -22,7 +22,7 @@ export class MediaHost {
|
|
|
22
22
|
void mediaRequestFrom(payload)
|
|
23
23
|
.then((request) => this._port(request, { signal: controller.signal, tick }))
|
|
24
24
|
.then(mediaResultWire)
|
|
25
|
-
.then((wire) => this._settle(callId, wire, wire.path), (err) => this._settle(callId, roundFailureWire(err)));
|
|
25
|
+
.then((wire) => this._settle(callId, wire, wire.path), (err) => this._settle(callId, Wire.roundFailureWire(err)));
|
|
26
26
|
}
|
|
27
27
|
cancel(callId) {
|
|
28
28
|
this._rounds.get(callId)?.abort(undefined);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { isRecord } from './guards.js';
|
|
3
3
|
import { stageFile } from './staging.js';
|
|
4
|
-
import {
|
|
4
|
+
import { Wire } from './wire.js';
|
|
5
5
|
const KINDS = ['image', 'music'];
|
|
6
6
|
export async function mediaRequestWire(request) {
|
|
7
7
|
const { images, ...json } = request;
|
|
@@ -58,7 +58,7 @@ export async function mediaResultFrom(wire) {
|
|
|
58
58
|
if (typeof result.error === 'string') {
|
|
59
59
|
return { error: result.error, code: typeof result.code === 'string' ? result.code : undefined };
|
|
60
60
|
}
|
|
61
|
-
throw roundFailureFrom(wire);
|
|
61
|
+
throw Wire.roundFailureFrom(wire);
|
|
62
62
|
}
|
|
63
63
|
function outputFrom(result, bytes) {
|
|
64
64
|
if (result.kind === 'image') {
|
|
@@ -3,6 +3,7 @@ import type { CompletionArgs } from '../capabilities/completion-engine/index.ts'
|
|
|
3
3
|
import type { CompletionSdk, RoundModelLease, ToolDefinition } from '../contract/index.ts';
|
|
4
4
|
import type { CompletionContext } from '../../index.ts';
|
|
5
5
|
import type { CompletionSkillEntry } from '../capabilities/skill-entry.ts';
|
|
6
|
+
import type { SkillTreeRef } from '../tools/skills/catalog.ts';
|
|
6
7
|
import { type LlmDeviceConfig, type ModelLoadOptions, type ModelLifecycleSdk, type PoolLike } from '../models/model-pool.ts';
|
|
7
8
|
export type CompletionRuntimeRequest = CompletionContext & {
|
|
8
9
|
ctxSize?: number;
|
|
@@ -33,7 +34,7 @@ interface RuntimeResidency {
|
|
|
33
34
|
load(): Promise<CompletionSdk>;
|
|
34
35
|
};
|
|
35
36
|
tools(): readonly ToolDefinition[];
|
|
36
|
-
skills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
37
|
+
skills(agentId: string | null, model: string, trees?: readonly SkillTreeRef[]): Promise<CompletionSkillEntry[]>;
|
|
37
38
|
platform(): string | undefined;
|
|
38
39
|
loadOptions(model: string, agent?: CompletionContext['agent']): ModelLoadOptions;
|
|
39
40
|
deviceConfig(): LlmDeviceConfig;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { HarnessError } from '../errors.js';
|
|
2
|
+
import { errorMessage } from '../guards.js';
|
|
3
|
+
import { raceAbort } from '../helpers/race-abort.js';
|
|
4
|
+
import { materializeSkillTree } from '../tools/skills/skill-tree.js';
|
|
2
5
|
import { createLocalRoots } from '../tools/fs/local.js';
|
|
3
6
|
import { createRemoteRoots } from '../tools/fs/remote.js';
|
|
4
7
|
import { isResident, modelKey, resolveCtxSize } from '../models/model-pool.js';
|
|
@@ -23,6 +26,9 @@ export async function prepareCompletionRuntime(residency, request) {
|
|
|
23
26
|
});
|
|
24
27
|
const acquireRound = roundAcquirer(residency, { model, key, loadOpts, signal });
|
|
25
28
|
const remoteRoots = driveOp && grantedDrives?.length ? createRemoteRoots(grantedDrives, driveOp) : [];
|
|
29
|
+
const shared = [...(request.workspaceSkills ?? []), ...(request.projectSkills ?? [])];
|
|
30
|
+
const skillTrees = await sharedSkillTrees(shared, request);
|
|
31
|
+
const trees = [...skillTrees].map(([name, { root }]) => ({ root, name }));
|
|
26
32
|
return {
|
|
27
33
|
key,
|
|
28
34
|
args: {
|
|
@@ -34,7 +40,8 @@ export async function prepareCompletionRuntime(residency, request) {
|
|
|
34
40
|
messages: projectionModel ? messages : messages.map(({ attachments, ...turn }) => turn),
|
|
35
41
|
requestMessages: messages,
|
|
36
42
|
tools: withRunTools(residency.tools(), request.tools ?? []),
|
|
37
|
-
skillCatalog: await residency.skills(agent?.id ?? null, model),
|
|
43
|
+
skillCatalog: await residency.skills(agent?.id ?? null, model, trees),
|
|
44
|
+
skillTrees,
|
|
38
45
|
platform: residency.platform(),
|
|
39
46
|
fsRoots: [
|
|
40
47
|
...(grantedDirs?.length ? await createLocalRoots(grantedDirs) : []),
|
|
@@ -90,3 +97,39 @@ function withRunTools(builtIn, own) {
|
|
|
90
97
|
const names = new Set(own.map((tool) => tool.name));
|
|
91
98
|
return [...builtIn.filter((tool) => !names.has(tool.name)), ...own];
|
|
92
99
|
}
|
|
100
|
+
async function sharedSkillTrees(skills, { approve, signal }) {
|
|
101
|
+
const byName = new Map();
|
|
102
|
+
for (const skill of [...skills].reverse()) {
|
|
103
|
+
byName.set(skill.name, [...(byName.get(skill.name) ?? []), skill]);
|
|
104
|
+
}
|
|
105
|
+
const layered = new Map();
|
|
106
|
+
for (const [name, candidates] of byName) {
|
|
107
|
+
for (const skill of candidates) {
|
|
108
|
+
const tree = await materializeSkillTree(skill).catch((err) => {
|
|
109
|
+
HarnessLog.warn('skill tree unavailable', { name, err: errorMessage(err) });
|
|
110
|
+
return null;
|
|
111
|
+
});
|
|
112
|
+
if (tree && (await approvedTree(skill, { approve, signal }))) {
|
|
113
|
+
layered.set(name, { root: tree.root });
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return layered;
|
|
119
|
+
}
|
|
120
|
+
async function approvedTree(skill, { approve, signal }) {
|
|
121
|
+
const resource = { kind: 'skill', label: `${skill.name}@${skill.hash}` };
|
|
122
|
+
const call = {
|
|
123
|
+
name: 'skill',
|
|
124
|
+
arguments: { name: skill.name },
|
|
125
|
+
resource,
|
|
126
|
+
effect: 'write'
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
return approve ? (await raceAbort(approve(call), signal)) === true : false;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
HarnessLog.warn('skill tree not approved', { name: skill.name, err: errorMessage(err) });
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
import type { CompletionSkillEntry } from '../capabilities/skill-entry.ts';
|
|
3
|
+
import type { SkillTreeRef } from '../tools/skills/catalog.ts';
|
|
3
4
|
import type { AgentConfig, ToolDefinition } from '../contract/index.ts';
|
|
4
5
|
import type { BorrowedModel } from '../contract/models.ts';
|
|
5
6
|
import type { CapabilityInfo, LoadedModel, LoadModelResult, UnloadModelContext, UnloadModelResult } from '../contract-types.ts';
|
|
@@ -75,7 +76,7 @@ export interface ResidencyOptions {
|
|
|
75
76
|
evictIdle(): Array<Promise<unknown>>;
|
|
76
77
|
unloadIdlePlugins(): Promise<Array<PromiseSettledResult<unknown>>>;
|
|
77
78
|
tools(): readonly ToolDefinition[];
|
|
78
|
-
skills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
79
|
+
skills(agentId: string | null, model: string, trees?: readonly SkillTreeRef[]): Promise<CompletionSkillEntry[]>;
|
|
79
80
|
platform?(): string;
|
|
80
81
|
}
|
|
81
82
|
export declare class Residency {
|
|
@@ -122,7 +123,7 @@ export declare class Residency {
|
|
|
122
123
|
get pool(): PoolLike;
|
|
123
124
|
get status(): ModelStatusCache;
|
|
124
125
|
tools(): readonly ToolDefinition[];
|
|
125
|
-
skills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
126
|
+
skills(agentId: string | null, model: string, trees?: readonly SkillTreeRef[]): Promise<CompletionSkillEntry[]>;
|
|
126
127
|
platform(): string | undefined;
|
|
127
128
|
recreate(): void;
|
|
128
129
|
destroy(): Promise<void> | undefined;
|