@kingsoftcloud/agentkit-harness-core 0.0.17 → 0.0.19
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/dist/configuration.d.mts +2 -0
- package/dist/configuration.mjs +19 -2
- package/dist/context-contributions.d.mts +2 -0
- package/dist/context-contributions.mjs +57 -2
- package/dist/context-planning.mjs +7 -4
- package/dist/contracts.d.mts +21 -1
- package/dist/engine-preset.d.mts +48 -0
- package/dist/engine-preset.mjs +75 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/kernel.d.mts +2 -1
- package/dist/kernel.mjs +49 -19
- package/dist/machine.d.mts +3 -1
- package/dist/machine.mjs +57 -7
- package/dist/output-recovery.d.mts +2 -0
- package/dist/output-recovery.mjs +11 -1
- package/dist/recovery.mjs +2 -0
- package/dist/response-continuation.mjs +2 -1
- package/dist/transitions.mjs +2 -1
- package/package.json +1 -1
- package/src/configuration.mts +24 -2
- package/src/context-contributions.mts +53 -2
- package/src/context-planning.mts +7 -4
- package/src/contracts.mts +18 -1
- package/src/engine-preset.mts +110 -0
- package/src/index.mts +1 -0
- package/src/kernel.mts +52 -19
- package/src/machine.mts +55 -7
- package/src/output-recovery.mts +13 -1
- package/src/recovery.mts +1 -0
- package/src/response-continuation.mts +2 -1
- package/src/transitions.mts +2 -1
package/dist/configuration.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ export interface ConfigurationInput {
|
|
|
15
15
|
hostBindingDigest: string;
|
|
16
16
|
contextSources?: RunConfiguration['contextSources'];
|
|
17
17
|
hooks?: RunConfiguration['hooks'];
|
|
18
|
+
hostVerification?: RunConfiguration['hostVerification'];
|
|
18
19
|
stopHookContinuationLimit?: number;
|
|
19
20
|
delegationDepth?: number;
|
|
20
21
|
modelRecoveryPolicy?: RunConfiguration['modelRecoveryPolicy'];
|
|
@@ -35,6 +36,7 @@ export interface ConfigurationInput {
|
|
|
35
36
|
childTaskPolicy?: RunConfiguration['childTaskPolicy'];
|
|
36
37
|
coordinatorResponsePolicy?: RunConfiguration['coordinatorResponsePolicy'];
|
|
37
38
|
planModePolicy?: RunConfiguration['planModePolicy'];
|
|
39
|
+
initialPlanPolicy?: RunConfiguration['initialPlanPolicy'];
|
|
38
40
|
planModeInitialActive?: boolean;
|
|
39
41
|
childPlanPolicy?: RunConfiguration['childPlanPolicy'];
|
|
40
42
|
toolErrorRecoveryModelCalls?: RunConfiguration['toolErrorRecoveryModelCalls'];
|
package/dist/configuration.mjs
CHANGED
|
@@ -39,6 +39,7 @@ export function configure(input) {
|
|
|
39
39
|
...(input.childCapabilityPolicy === undefined ? {} : { childCapabilityPolicy: input.childCapabilityPolicy }),
|
|
40
40
|
...(input.sessionInjectionPolicy === undefined ? {} : { sessionInjectionPolicy: input.sessionInjectionPolicy }),
|
|
41
41
|
tools: input.tools ?? [], instructions: input.instructions ?? '', hostBindingDigest: input.hostBindingDigest,
|
|
42
|
+
...(input.hostVerification === undefined ? {} : { hostVerification: input.hostVerification }),
|
|
42
43
|
inputMessages: input.inputMessages ?? null,
|
|
43
44
|
...(input.conversationSeed === undefined ? {} : { conversationSeed: input.conversationSeed }),
|
|
44
45
|
...(input.conversationRewind === undefined ? {} : { conversationRewind: input.conversationRewind }),
|
|
@@ -59,6 +60,7 @@ export function configure(input) {
|
|
|
59
60
|
...(input.childTaskPolicy === undefined ? {} : { childTaskPolicy: input.childTaskPolicy }),
|
|
60
61
|
...(input.coordinatorResponsePolicy === undefined ? {} : { coordinatorResponsePolicy: input.coordinatorResponsePolicy }),
|
|
61
62
|
...(input.planModePolicy === undefined ? {} : { planModePolicy: input.planModePolicy }),
|
|
63
|
+
...(input.initialPlanPolicy === undefined ? {} : { initialPlanPolicy: input.initialPlanPolicy }),
|
|
62
64
|
...(input.planModeInitialActive === undefined ? {} : { planModeInitialActive: input.planModeInitialActive }),
|
|
63
65
|
...(input.childPlanPolicy === undefined ? {} : { childPlanPolicy: input.childPlanPolicy }),
|
|
64
66
|
...(input.toolErrorRecoveryModelCalls === undefined
|
|
@@ -107,9 +109,9 @@ export function configure(input) {
|
|
|
107
109
|
&& typeof config.hostRecoveryBinding === 'object' && !Array.isArray(config.hostRecoveryBinding), 'invalid_host_recovery_binding');
|
|
108
110
|
invariant(config.guidancePolicy == null || config.guidancePolicy === 'boundary-guide/v1', 'invalid_guidance_policy');
|
|
109
111
|
invariant(config.inputPolicy === undefined || config.inputPolicy === 'before-first-model/v1', 'invalid_input_policy');
|
|
110
|
-
invariant(config.outputRecoveryPolicy == null || ['task-or-delivery/v1', 'response-boundary/v2', 'response-boundary/v3'].includes(config.outputRecoveryPolicy), 'invalid_output_recovery_policy');
|
|
112
|
+
invariant(config.outputRecoveryPolicy == null || ['task-or-delivery/v1', 'response-boundary/v2', 'response-boundary/v3', 'response-boundary/v4', 'response-boundary/v5'].includes(config.outputRecoveryPolicy), 'invalid_output_recovery_policy');
|
|
111
113
|
invariant(config.outputRestartPolicy === undefined || ['per-response/v1', 'per-response/v2'].includes(config.outputRestartPolicy)
|
|
112
|
-
&& ['response-boundary/v2', 'response-boundary/v3'].includes(config.outputRecoveryPolicy ?? ''), 'invalid_output_restart_policy');
|
|
114
|
+
&& ['response-boundary/v2', 'response-boundary/v3', 'response-boundary/v4', 'response-boundary/v5'].includes(config.outputRecoveryPolicy ?? ''), 'invalid_output_restart_policy');
|
|
113
115
|
invariant(config.approvalOutcomePolicy === undefined || config.approvalOutcomePolicy === 'owner-outcome/v1', 'invalid_approval_outcome_policy');
|
|
114
116
|
invariant(config.providerRecoveryPolicy == null || config.providerRecoveryPolicy === 'provider-recovery/v2', 'invalid_provider_recovery_policy');
|
|
115
117
|
invariant(config.toolExecutionPolicy === undefined || config.toolExecutionPolicy === 'owner-execution/v1', 'invalid_tool_execution_policy');
|
|
@@ -230,6 +232,17 @@ export function configure(input) {
|
|
|
230
232
|
validateDeliveryConfiguration(config);
|
|
231
233
|
validateCoordinatorConfiguration(config);
|
|
232
234
|
validatePlanModeConfiguration(config);
|
|
235
|
+
const verifier = config.hostVerification;
|
|
236
|
+
if (verifier !== undefined) {
|
|
237
|
+
invariant(verifier && /^sha256:[a-f0-9]{64}$/.test(verifier.bindingDigest)
|
|
238
|
+
&& config.contract.acceptance.some(item => item.required && item.verificationMethod === 'deterministic'
|
|
239
|
+
&& item.verifierRef === verifier.verifierRef && item.verifierVersion === verifier.verifierVersion)
|
|
240
|
+
&& Array.isArray(verifier.evidenceTools) && verifier.evidenceTools.length <= 16
|
|
241
|
+
&& new Set(verifier.evidenceTools).size === verifier.evidenceTools.length
|
|
242
|
+
&& verifier.evidenceTools.every(name => config.tools.some(tool => tool.name === name))
|
|
243
|
+
&& (verifier.contextSourceId === null || config.contextSources.some(source => source.sourceId === verifier.contextSourceId)), 'invalid_host_verification_binding');
|
|
244
|
+
}
|
|
245
|
+
invariant(config.initialPlanPolicy === undefined || config.initialPlanPolicy === 'plan-act-observe/v1', 'invalid_initial_plan_policy');
|
|
233
246
|
const names = new Set();
|
|
234
247
|
for (const tool of config.tools) {
|
|
235
248
|
invariant(tool.name.trim() && !names.has(tool.name), 'duplicate_or_invalid_tool');
|
|
@@ -238,6 +251,10 @@ export function configure(input) {
|
|
|
238
251
|
invariant(Number.isFinite(tool.timeoutMs) && tool.timeoutMs > 0 && tool.timeoutMs < limits.effectTimeoutMs, 'invalid_tool_timeout');
|
|
239
252
|
invariant(tool.executionTimeoutPolicy === undefined || ['dispatch/v1', 'dispatch/v2'].includes(tool.executionTimeoutPolicy), 'invalid_tool_execution_timeout_policy');
|
|
240
253
|
invariant(tool.approvalPolicy === undefined || tool.approvalPolicy === 'durable-preflight/v1', 'invalid_tool_approval_policy');
|
|
254
|
+
invariant(tool.hostApprovalRequired === undefined || tool.hostApprovalRequired === true
|
|
255
|
+
&& tool.approvalPolicy === 'durable-preflight/v1', 'invalid_tool_host_approval_policy');
|
|
256
|
+
invariant(tool.hostEffectProtocol === undefined
|
|
257
|
+
|| tool.hostEffectProtocol === 'agentkit.engine-host-tool-effect/v1' && !tool.readOnly, 'invalid_tool_host_effect_protocol');
|
|
241
258
|
invariant(!tool.concurrentSafe || tool.readOnly && tool.observationRole === 'none', 'invalid_tool_concurrency');
|
|
242
259
|
invariant(tool.workspaceEditPolicy === undefined || ['zcode-match/v1', 'zcode-match/v2'].includes(tool.workspaceEditPolicy)
|
|
243
260
|
&& ['edit_workspace_file', 'multi_edit_workspace_file'].includes(tool.name)
|
|
@@ -5,6 +5,8 @@ export declare const CONTEXT_CONTRIBUTION_CONTRACT = "agentkit.native-context-co
|
|
|
5
5
|
export declare function contextSourceUnavailable(error: unknown, config: RunConfiguration): ObjectValue | null;
|
|
6
6
|
export declare function validateContextSource(source: ContextSourceDefinition, timeoutMs: number): void;
|
|
7
7
|
export declare function contextContributionMessage(source: ContextSourceDefinition, item: ObjectValue): Message;
|
|
8
|
+
export declare function hostInstructionContribution(message: Message, config: RunConfiguration): boolean;
|
|
9
|
+
export declare function expiredHostContribution(message: Message, config: RunConfiguration, now: number): ContextSourceDefinition | null;
|
|
8
10
|
/** Only the outer envelope from a frozen source can select instruction retention.
|
|
9
11
|
* A recalled item's own role, policy or source fields never promote its trust. */
|
|
10
12
|
export declare function currentInstructionContribution(message: Message, config: RunConfiguration): boolean;
|
|
@@ -29,6 +29,9 @@ export function validateContextSource(source, timeoutMs) {
|
|
|
29
29
|
&& Number.isSafeInteger(source.maxTokens) && source.maxTokens > 0
|
|
30
30
|
&& Number.isSafeInteger(source.maxBytes) && source.maxBytes > 0 && source.maxBytes <= 131072, 'invalid_context_source');
|
|
31
31
|
invariant(source.instructionPolicy === undefined || source.instructionPolicy === 'current-files/v1' && source.required, 'invalid_context_instruction_source');
|
|
32
|
+
invariant(source.hostProjection === undefined || !source.instructionPolicy
|
|
33
|
+
&& ['data/v1', 'instructions-and-data/v1'].includes(source.hostProjection), 'invalid_host_context_projection');
|
|
34
|
+
invariant(source.warnOnFailure === undefined || source.warnOnFailure === true && !source.required && source.hostProjection, 'invalid_host_context_failure_policy');
|
|
32
35
|
const recovery = source.timeoutRecovery;
|
|
33
36
|
invariant(recovery === undefined || recovery && !Array.isArray(recovery)
|
|
34
37
|
&& Object.keys(recovery).sort().join(',') === 'contract,maxRetries,retryDelayMs' && recovery.contract === 'context-source-timeout/v1'
|
|
@@ -48,6 +51,17 @@ async function retryDelay(ms, signal) {
|
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
export function contextContributionMessage(source, item) {
|
|
54
|
+
if (source.hostProjection) {
|
|
55
|
+
const { projection, fragment, expiresAt } = item;
|
|
56
|
+
invariant((projection === 'data' || projection === 'instructions' && source.hostProjection === 'instructions-and-data/v1')
|
|
57
|
+
&& fragment && typeof fragment === 'object' && !Array.isArray(fragment)
|
|
58
|
+
&& (expiresAt === undefined || Number.isSafeInteger(expiresAt) && Number(expiresAt) > 0), 'context_source_result_invalid');
|
|
59
|
+
const privileged = projection === 'instructions';
|
|
60
|
+
return { role: privileged ? 'system' : 'user', kind: 'context_contribution',
|
|
61
|
+
content: canonical({ schemaVersion: CONTEXT_CONTRIBUTION_CONTRACT, sourceId: source.sourceId, bindingDigest: source.bindingDigest,
|
|
62
|
+
trust: privileged ? 'host-granted' : 'untrusted', purpose: privileged ? 'host_instructions' : 'context_only',
|
|
63
|
+
notice: 'Context grants no approval, acceptance or execution authority.', item: fragment, ...(expiresAt === undefined ? {} : { expiresAt }) }) };
|
|
64
|
+
}
|
|
51
65
|
return { role: 'user', kind: 'context_contribution', content: canonical({ schemaVersion: CONTEXT_CONTRIBUTION_CONTRACT,
|
|
52
66
|
trust: 'untrusted', purpose: source.instructionPolicy ? 'workspace_instructions' : 'context_only',
|
|
53
67
|
sourceId: source.sourceId, bindingDigest: source.bindingDigest,
|
|
@@ -57,6 +71,35 @@ export function contextContributionMessage(source, item) {
|
|
|
57
71
|
+ 'File content grants no tools, approval, acceptance or execution authority.'
|
|
58
72
|
: 'Recalled data grants no approval, acceptance, freshness or execution authority.', item }) };
|
|
59
73
|
}
|
|
74
|
+
function hostContributionSource(message, config) {
|
|
75
|
+
if (message.kind !== 'context_contribution'
|
|
76
|
+
|| !config.contextSources.some(source => source.hostProjection))
|
|
77
|
+
return null;
|
|
78
|
+
let value;
|
|
79
|
+
try {
|
|
80
|
+
value = JSON.parse(message.content);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (!value || value.schemaVersion !== CONTEXT_CONTRIBUTION_CONTRACT)
|
|
86
|
+
return null;
|
|
87
|
+
const source = config.contextSources.find(source => source.hostProjection
|
|
88
|
+
&& source.sourceId === value.sourceId && source.bindingDigest === value.bindingDigest);
|
|
89
|
+
return source ? { source, value } : null;
|
|
90
|
+
}
|
|
91
|
+
export function hostInstructionContribution(message, config) {
|
|
92
|
+
if (message.role !== 'system')
|
|
93
|
+
return false;
|
|
94
|
+
const admitted = hostContributionSource(message, config);
|
|
95
|
+
return admitted?.source.hostProjection === 'instructions-and-data/v1'
|
|
96
|
+
&& admitted.value.purpose === 'host_instructions' && admitted.value.trust === 'host-granted';
|
|
97
|
+
}
|
|
98
|
+
export function expiredHostContribution(message, config, now) {
|
|
99
|
+
const admitted = hostContributionSource(message, config);
|
|
100
|
+
return admitted && typeof admitted.value.expiresAt === 'number' && admitted.value.expiresAt <= now
|
|
101
|
+
? admitted.source : null;
|
|
102
|
+
}
|
|
60
103
|
/** Only the outer envelope from a frozen source can select instruction retention.
|
|
61
104
|
* A recalled item's own role, policy or source fields never promote its trust. */
|
|
62
105
|
export function currentInstructionContribution(message, config) {
|
|
@@ -104,8 +147,11 @@ export async function collectContextContributions(context, snapshot, config, por
|
|
|
104
147
|
const admitted = [];
|
|
105
148
|
for (const item of result.items) {
|
|
106
149
|
invariant(item && typeof item === 'object' && !Array.isArray(item), 'context_source_result_invalid');
|
|
107
|
-
const
|
|
150
|
+
const message = contextContributionMessage(source, item);
|
|
151
|
+
invariant(!expiredHostContribution(message, config, Date.now()), 'context_source_expired');
|
|
152
|
+
const candidate = [...admitted, message];
|
|
108
153
|
if (new TextEncoder().encode(canonical(candidate)).length > source.maxBytes) {
|
|
154
|
+
invariant(!source.hostProjection, 'context_source_byte_budget_exceeded');
|
|
109
155
|
invariant(!source.instructionPolicy, 'context_instruction_source_byte_budget_exceeded');
|
|
110
156
|
continue;
|
|
111
157
|
}
|
|
@@ -113,6 +159,7 @@ export async function collectContextContributions(context, snapshot, config, por
|
|
|
113
159
|
signal.throwIfAborted();
|
|
114
160
|
invariant(Date.now() < deadline, 'context_source_timeout');
|
|
115
161
|
invariant(Number.isSafeInteger(tokens) && tokens >= 0, 'context_token_count_invalid');
|
|
162
|
+
invariant(!source.hostProjection || tokens <= source.maxTokens, 'context_source_token_budget_exceeded');
|
|
116
163
|
invariant(!source.instructionPolicy || tokens <= source.maxTokens, 'context_instruction_source_token_budget_exceeded');
|
|
117
164
|
if (tokens <= source.maxTokens)
|
|
118
165
|
admitted.push(candidate.at(-1));
|
|
@@ -136,7 +183,15 @@ export async function collectContextContributions(context, snapshot, config, por
|
|
|
136
183
|
}
|
|
137
184
|
if (source.required)
|
|
138
185
|
throw error;
|
|
139
|
-
|
|
186
|
+
if (source.warnOnFailure) {
|
|
187
|
+
const message = contextContributionMessage(source, { projection: 'data',
|
|
188
|
+
fragment: { status: 'unavailable', code: 'context_source_unavailable' } });
|
|
189
|
+
if (new TextEncoder().encode(canonical([message])).length <= source.maxBytes
|
|
190
|
+
&& await count([message]).catch(() => Infinity) <= source.maxTokens)
|
|
191
|
+
messages.push(message);
|
|
192
|
+
}
|
|
193
|
+
context.signal.throwIfAborted();
|
|
194
|
+
diagnostics.push({ sourceId: source.sourceId, bindingDigest: source.bindingDigest, status: source.warnOnFailure ? 'warned' : 'skipped',
|
|
140
195
|
...(source.timeoutRecovery ? { timeoutRetries: attempt } : {}) });
|
|
141
196
|
break;
|
|
142
197
|
}
|
|
@@ -11,7 +11,7 @@ import { defaultToolPruningThreshold, projectOldToolResults, toolPruningIdleElap
|
|
|
11
11
|
import { summaryContinuityInstructions, validSummaryContinuity } from './summary-continuity.mjs';
|
|
12
12
|
import { responseBoundaryRecovery, responseContinuationPairs } from './response-continuation.mjs';
|
|
13
13
|
import { verificationModelView } from './model-surface.mjs';
|
|
14
|
-
import { currentInstructionContribution } from './context-contributions.mjs';
|
|
14
|
+
import { currentInstructionContribution, hostInstructionContribution } from './context-contributions.mjs';
|
|
15
15
|
import { projectBackgroundCommands } from './background-contract.mjs';
|
|
16
16
|
const emptyState = () => ({ history: null, compaction: null, compactions: 0,
|
|
17
17
|
compactionsWithoutProgress: 0, progressDigest: null, lastModelCall: 0 });
|
|
@@ -79,11 +79,13 @@ function composeContext(messages, summary, continuity, contributions = [], place
|
|
|
79
79
|
const host = { role: 'system', kind: 'execution_continuity', content: canonical(continuity) };
|
|
80
80
|
const historical = summary ? [contextSummaryMessage(summary)] : [];
|
|
81
81
|
const split = messages.findIndex(message => message.role !== 'system');
|
|
82
|
+
const instructions = contributions.filter(message => message.role === 'system');
|
|
83
|
+
const data = contributions.filter(message => message.role !== 'system');
|
|
82
84
|
if (placement === 'after-history/v1')
|
|
83
85
|
return [...messages.slice(0, split < 0 ? messages.length : split),
|
|
84
|
-
...
|
|
86
|
+
...instructions, ...data, ...historical, ...messages.slice(split < 0 ? messages.length : split), ...currentInstructions, host];
|
|
85
87
|
return [...messages.slice(0, split < 0 ? messages.length : split),
|
|
86
|
-
...(continuity.operatorGuidancePolicy === 'journaled-system/v1' ? [] : [host]), ...
|
|
88
|
+
...(continuity.operatorGuidancePolicy === 'journaled-system/v1' ? [] : [host]), ...instructions, ...data, ...historical,
|
|
87
89
|
...messages.slice(split < 0 ? messages.length : split), ...currentInstructions];
|
|
88
90
|
}
|
|
89
91
|
function activeIndexes(snapshot, state, config, digest) {
|
|
@@ -304,7 +306,8 @@ export async function planNativeContext(snapshot, config, tools, counters, diges
|
|
|
304
306
|
const state = copy(snapshot.contextState ?? emptyState());
|
|
305
307
|
const requiredContributions = inputContributions.filter(message => currentInstructionContribution(message, config));
|
|
306
308
|
const optionalContributions = inputContributions.filter(message => !currentInstructionContribution(message, config));
|
|
307
|
-
invariant(inputContributions.every(message => message.role === 'user'
|
|
309
|
+
invariant(inputContributions.every(message => (message.role === 'user' || hostInstructionContribution(message, config))
|
|
310
|
+
&& message.kind === 'context_contribution'
|
|
308
311
|
&& Object.keys(message).every(key => ['role', 'kind', 'content'].includes(key))), 'context_contribution_invalid');
|
|
309
312
|
if (policies.forRun(config).review.reviewPending(snapshot)) {
|
|
310
313
|
const active = activeIndexes(snapshot, state, config, digest).map(index => copy(snapshot.messages[index]));
|
package/dist/contracts.d.mts
CHANGED
|
@@ -117,6 +117,10 @@ export interface ToolDefinition {
|
|
|
117
117
|
executionTimeoutPolicy?: 'dispatch/v1' | 'dispatch/v2';
|
|
118
118
|
/** Host permission waits yield a durable Native interaction before dispatch. */
|
|
119
119
|
approvalPolicy?: 'durable-preflight/v1';
|
|
120
|
+
/** An explicit Run policy requires a user decision even if standing access permits the tool. */
|
|
121
|
+
hostApprovalRequired?: true;
|
|
122
|
+
/** This external owner receives a frozen effect identity and may request conditional approval. */
|
|
123
|
+
hostEffectProtocol?: 'agentkit.engine-host-tool-effect/v1';
|
|
120
124
|
contextRole: 'none' | 'workspace_read' | 'workspace_search' | 'workspace_list' | 'artifact_read' | 'task_planning';
|
|
121
125
|
observationRole: 'none' | 'browser';
|
|
122
126
|
progressObservation: boolean;
|
|
@@ -241,6 +245,13 @@ export interface AcceptanceItem {
|
|
|
241
245
|
verificationMethod: VerificationMethod;
|
|
242
246
|
description: string;
|
|
243
247
|
}
|
|
248
|
+
export interface HostVerificationBinding {
|
|
249
|
+
verifierRef: string;
|
|
250
|
+
verifierVersion: string;
|
|
251
|
+
bindingDigest: string;
|
|
252
|
+
evidenceTools: string[];
|
|
253
|
+
contextSourceId: string | null;
|
|
254
|
+
}
|
|
244
255
|
export interface TaskContract {
|
|
245
256
|
objective: string;
|
|
246
257
|
revision: string;
|
|
@@ -463,6 +474,9 @@ export interface ContextSourceDefinition {
|
|
|
463
474
|
required: boolean;
|
|
464
475
|
maxTokens: number;
|
|
465
476
|
maxBytes: number;
|
|
477
|
+
/** A frozen host grant controls whether a projected item can enter the system layer. */
|
|
478
|
+
hostProjection?: 'data/v1' | 'instructions-and-data/v1';
|
|
479
|
+
warnOnFailure?: true;
|
|
466
480
|
/** Current file guidance is refreshed before inference, never substituted by a historical summary. */
|
|
467
481
|
instructionPolicy?: 'current-files/v1';
|
|
468
482
|
/** Retry only a timed-out read; required sources pause after exhaustion. Absence keeps the frozen legacy behavior. */
|
|
@@ -491,6 +505,7 @@ export interface ConversationSeed {
|
|
|
491
505
|
discoveredToolNames?: string[];
|
|
492
506
|
}
|
|
493
507
|
export interface RunConfiguration {
|
|
508
|
+
hostVerification?: HostVerificationBinding;
|
|
494
509
|
workspaceCapturePolicy?: 'declared-subjects/v1';
|
|
495
510
|
deliveryScopePolicy?: 'declared-deliverables/v1' | 'answer-artifacts/v2';
|
|
496
511
|
childCapabilityPolicy?: 'required-tools/v1';
|
|
@@ -513,6 +528,7 @@ export interface RunConfiguration {
|
|
|
513
528
|
/** I/O deadlines belong to the execution owner, not kernel staging or result projection. */
|
|
514
529
|
toolExecutionPolicy?: 'owner-execution/v1';
|
|
515
530
|
planModePolicy?: 'session-plan/v1' | 'inherited-child-plan/v1';
|
|
531
|
+
initialPlanPolicy?: 'plan-act-observe/v1';
|
|
516
532
|
planModeInitialActive?: boolean;
|
|
517
533
|
childPlanPolicy?: 'inherit-plan/v1';
|
|
518
534
|
toolDiscoveryPolicy?: 'local-tool-search/v1';
|
|
@@ -544,7 +560,7 @@ export interface RunConfiguration {
|
|
|
544
560
|
delegationDepth: number;
|
|
545
561
|
modelRecoveryPolicy: 'manual' | 'pure-inference/v1';
|
|
546
562
|
guidancePolicy?: 'boundary-guide/v1' | null;
|
|
547
|
-
outputRecoveryPolicy?: 'task-or-delivery/v1' | 'response-boundary/v2' | 'response-boundary/v3' | null;
|
|
563
|
+
outputRecoveryPolicy?: 'task-or-delivery/v1' | 'response-boundary/v2' | 'response-boundary/v3' | 'response-boundary/v4' | 'response-boundary/v5' | null;
|
|
548
564
|
/** Restart allowance belongs to one interrupted response chain. v2 pauses
|
|
549
565
|
* exhausted chains for explicit resume instead of terminating the Run.
|
|
550
566
|
* Legacy Runs retain their frozen accounting and exhaustion behavior. */
|
|
@@ -817,6 +833,7 @@ export interface RunSnapshot extends RunIdentity {
|
|
|
817
833
|
allowedPrompts?: Json;
|
|
818
834
|
};
|
|
819
835
|
};
|
|
836
|
+
initialPlanCompleted?: true;
|
|
820
837
|
todos?: {
|
|
821
838
|
items: TodoItem[];
|
|
822
839
|
revision: number;
|
|
@@ -872,6 +889,8 @@ export interface RunSnapshot extends RunIdentity {
|
|
|
872
889
|
continuations: number;
|
|
873
890
|
outputRestarts: number;
|
|
874
891
|
repairs: number;
|
|
892
|
+
/** A sealed reasoning-only cutoff has armed the short retry for this response. */
|
|
893
|
+
reasoningStallRetry?: boolean;
|
|
875
894
|
activeElapsedMs: number;
|
|
876
895
|
retryNotBefore: number;
|
|
877
896
|
candidate: CompletionCandidate | null;
|
|
@@ -1271,6 +1290,7 @@ export interface SourceReadBudget {
|
|
|
1271
1290
|
maxResultBytes: number;
|
|
1272
1291
|
}
|
|
1273
1292
|
export interface VerificationPort {
|
|
1293
|
+
available?(configuration: RunConfiguration): boolean;
|
|
1274
1294
|
verify(request: PortContext & {
|
|
1275
1295
|
candidate: CompletionCandidate;
|
|
1276
1296
|
contract: TaskContract;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RunConfiguration, ToolDefinition } from './contracts.mjs';
|
|
2
|
+
/** Engine-owned run defaults.
|
|
3
|
+
*
|
|
4
|
+
* A host names a preset; the engine decides which policy versions and budgets
|
|
5
|
+
* that name means. Publishing a better recovery policy therefore needs an
|
|
6
|
+
* engine release only: hosts that reference `official` pick it up for new
|
|
7
|
+
* Runs, while existing Runs keep the configuration frozen at their creation.
|
|
8
|
+
*
|
|
9
|
+
* Hosts must not copy the returned literals into their own source. */
|
|
10
|
+
export declare const ENGINE_PRESET_CONTRACT = "agentkit.engine-preset/v1";
|
|
11
|
+
export declare const OFFICIAL_ENGINE_PRESET = "official";
|
|
12
|
+
export interface EnginePresetRequest {
|
|
13
|
+
preset?: string;
|
|
14
|
+
/** Host-declared model call budget. Accepted for host compatibility. */
|
|
15
|
+
maxModelCalls?: number | null;
|
|
16
|
+
}
|
|
17
|
+
type PresetPolicyKey = 'providerRecoveryPolicy' | 'outputRecoveryPolicy' | 'outputRestartPolicy' | 'toolExecutionPolicy' | 'toolErrorRecoveryPolicy' | 'artifactPolicy' | 'workspaceCapturePolicy' | 'deliveryScopePolicy' | 'toolErrorRecoveryModelCalls';
|
|
18
|
+
export interface EnginePreset {
|
|
19
|
+
contract: typeof ENGINE_PRESET_CONTRACT;
|
|
20
|
+
preset: string;
|
|
21
|
+
revision: number;
|
|
22
|
+
/** Spread into the configuration input of a NEW Run. */
|
|
23
|
+
policies: Required<Pick<RunConfiguration, PresetPolicyKey>>;
|
|
24
|
+
limits: {
|
|
25
|
+
maxOutputRestarts: number;
|
|
26
|
+
};
|
|
27
|
+
/** Tool-surface options a Node host forwards to the engine tool binder. */
|
|
28
|
+
toolOptions: {
|
|
29
|
+
executionTimeoutPolicy: 'dispatch/v2';
|
|
30
|
+
workspaceEditPolicy: 'zcode-match/v2';
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare function listEnginePresets(): readonly string[];
|
|
34
|
+
export declare function resolveEnginePreset(request?: EnginePresetRequest): EnginePreset;
|
|
35
|
+
export interface PresetOutputBudgetRequest {
|
|
36
|
+
/** An explicit user/operator choice always wins. */
|
|
37
|
+
configured?: number | null;
|
|
38
|
+
/** Largest response the bound model accepts, when known. */
|
|
39
|
+
modelMaxOutputTokens?: number | null;
|
|
40
|
+
contextWindow: number;
|
|
41
|
+
}
|
|
42
|
+
/** Per-request output budget for a new Run under the official preset.
|
|
43
|
+
* Never exceeds the model limit and leaves at least half the window for input. */
|
|
44
|
+
export declare function presetRequestOutputTokens(request: PresetOutputBudgetRequest): number;
|
|
45
|
+
/** Engine control tools the preset policies require. A host appends these to
|
|
46
|
+
* its own tools instead of knowing which policy implies which control. */
|
|
47
|
+
export declare function enginePresetToolDefinitions(preset: Pick<EnginePreset, 'policies'>): ToolDefinition[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { artifactToolDefinitions } from './artifact-runtime.mjs';
|
|
2
|
+
import { deliveryToolDefinitions } from './deliverables.mjs';
|
|
3
|
+
import { invariant } from './values.mjs';
|
|
4
|
+
/** Engine-owned run defaults.
|
|
5
|
+
*
|
|
6
|
+
* A host names a preset; the engine decides which policy versions and budgets
|
|
7
|
+
* that name means. Publishing a better recovery policy therefore needs an
|
|
8
|
+
* engine release only: hosts that reference `official` pick it up for new
|
|
9
|
+
* Runs, while existing Runs keep the configuration frozen at their creation.
|
|
10
|
+
*
|
|
11
|
+
* Hosts must not copy the returned literals into their own source. */
|
|
12
|
+
export const ENGINE_PRESET_CONTRACT = 'agentkit.engine-preset/v1';
|
|
13
|
+
export const OFFICIAL_ENGINE_PRESET = 'official';
|
|
14
|
+
const EXPERIMENTAL_REASONING_STALL_PRESET = 'experimental-reasoning-stall';
|
|
15
|
+
/** Bump when the meaning of `official` changes for new Runs. */
|
|
16
|
+
const OFFICIAL_REVISION = 3;
|
|
17
|
+
const EXPERIMENTAL_REASONING_STALL_REVISION = 1;
|
|
18
|
+
/** Largest single response the engine asks for by default. Long greenfield
|
|
19
|
+
* edits need roughly 30k tokens in one response; smaller requests exhaust
|
|
20
|
+
* themselves on reasoning before any tool call is emitted. */
|
|
21
|
+
const DEFAULT_REQUEST_OUTPUT_TOKENS = 32000;
|
|
22
|
+
const MINIMUM_REQUEST_OUTPUT_TOKENS = 1024;
|
|
23
|
+
export function listEnginePresets() {
|
|
24
|
+
return Object.freeze([OFFICIAL_ENGINE_PRESET, EXPERIMENTAL_REASONING_STALL_PRESET]);
|
|
25
|
+
}
|
|
26
|
+
export function resolveEnginePreset(request = {}) {
|
|
27
|
+
invariant(request !== null && typeof request === 'object' && !Array.isArray(request)
|
|
28
|
+
&& Object.keys(request).every(key => ['preset', 'maxModelCalls'].includes(key)), 'invalid_engine_preset_request');
|
|
29
|
+
const preset = request.preset ?? OFFICIAL_ENGINE_PRESET;
|
|
30
|
+
const experimental = preset === EXPERIMENTAL_REASONING_STALL_PRESET;
|
|
31
|
+
invariant(preset === OFFICIAL_ENGINE_PRESET || experimental, 'unknown_engine_preset');
|
|
32
|
+
const maxModelCalls = request.maxModelCalls ?? null;
|
|
33
|
+
invariant(maxModelCalls === null || Number.isSafeInteger(maxModelCalls) && maxModelCalls >= 1, 'invalid_engine_preset_request');
|
|
34
|
+
return {
|
|
35
|
+
contract: ENGINE_PRESET_CONTRACT, preset,
|
|
36
|
+
revision: experimental ? EXPERIMENTAL_REASONING_STALL_REVISION : OFFICIAL_REVISION,
|
|
37
|
+
policies: {
|
|
38
|
+
providerRecoveryPolicy: 'provider-recovery/v2',
|
|
39
|
+
outputRecoveryPolicy: experimental ? 'response-boundary/v4' : 'response-boundary/v5',
|
|
40
|
+
// v2: an admitted tool step ends the truncation streak and exhaustion pauses.
|
|
41
|
+
outputRestartPolicy: 'per-response/v2',
|
|
42
|
+
toolExecutionPolicy: 'owner-execution/v1',
|
|
43
|
+
toolErrorRecoveryPolicy: 'diagnose-before-repeat/v2',
|
|
44
|
+
// Spelled out so a host digest over these policies is identical at admission and restore.
|
|
45
|
+
toolErrorRecoveryModelCalls: 10,
|
|
46
|
+
artifactPolicy: 'runtime-artifacts/v1',
|
|
47
|
+
workspaceCapturePolicy: 'declared-subjects/v1',
|
|
48
|
+
// Results are the answer plus the artifacts it names.
|
|
49
|
+
deliveryScopePolicy: 'answer-artifacts/v2',
|
|
50
|
+
},
|
|
51
|
+
limits: { maxOutputRestarts: 0 },
|
|
52
|
+
toolOptions: { executionTimeoutPolicy: 'dispatch/v2', workspaceEditPolicy: 'zcode-match/v2' },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Per-request output budget for a new Run under the official preset.
|
|
56
|
+
* Never exceeds the model limit and leaves at least half the window for input. */
|
|
57
|
+
export function presetRequestOutputTokens(request) {
|
|
58
|
+
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
59
|
+
invariant(request !== null && typeof request === 'object' && positive(request.contextWindow)
|
|
60
|
+
&& (request.configured == null || positive(request.configured))
|
|
61
|
+
&& (request.modelMaxOutputTokens == null || positive(request.modelMaxOutputTokens)), 'invalid_preset_output_budget');
|
|
62
|
+
const ceiling = Math.min(request.modelMaxOutputTokens ?? Number.MAX_SAFE_INTEGER, Math.floor(request.contextWindow / 2));
|
|
63
|
+
invariant(ceiling >= 1, 'invalid_preset_output_budget');
|
|
64
|
+
if (request.configured != null)
|
|
65
|
+
return Math.min(request.configured, ceiling);
|
|
66
|
+
return Math.max(Math.min(DEFAULT_REQUEST_OUTPUT_TOKENS, ceiling), Math.min(MINIMUM_REQUEST_OUTPUT_TOKENS, ceiling));
|
|
67
|
+
}
|
|
68
|
+
/** Engine control tools the preset policies require. A host appends these to
|
|
69
|
+
* its own tools instead of knowing which policy implies which control. */
|
|
70
|
+
export function enginePresetToolDefinitions(preset) {
|
|
71
|
+
return [
|
|
72
|
+
...(preset.policies.deliveryScopePolicy ? deliveryToolDefinitions(preset.policies.deliveryScopePolicy) : []),
|
|
73
|
+
...(preset.policies.artifactPolicy ? artifactToolDefinitions() : []),
|
|
74
|
+
];
|
|
75
|
+
}
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
package/dist/kernel.d.mts
CHANGED
|
@@ -47,8 +47,9 @@ export declare class NativeKernel {
|
|
|
47
47
|
private drivingState;
|
|
48
48
|
private drivingCommands;
|
|
49
49
|
private startupPromotion;
|
|
50
|
-
runUntilIdle(scope: RunScope, runId: string, { signal, waitForRetry }?: {
|
|
50
|
+
runUntilIdle(scope: RunScope, runId: string, { signal, detachSignal, waitForRetry }?: {
|
|
51
51
|
signal?: AbortSignal;
|
|
52
|
+
detachSignal?: AbortSignal;
|
|
52
53
|
waitForRetry?: boolean;
|
|
53
54
|
}): Promise<RunSnapshot>;
|
|
54
55
|
private inspectBackgroundCommands;
|