@kingsoftcloud/agentkit-harness-core 0.0.15 → 0.0.16

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.
@@ -9,6 +9,9 @@ export interface BackgroundCommandState {
9
9
  ref: BackgroundCommandRef;
10
10
  notified: boolean;
11
11
  }
12
+ /** Bound a read view without retiring any durable command ownership. Prefer
13
+ * commands whose completion has not been accounted for, then recent history. */
14
+ export declare function projectBackgroundCommands(rows: readonly BackgroundCommandState[], limit: number, recentLimit?: number): BackgroundCommandState[];
12
15
  export interface BackgroundCommandRequest extends Omit<PortContext, 'signal'> {
13
16
  schemaVersion: typeof BACKGROUND_COMMAND_CONTRACT;
14
17
  cursor: string;
@@ -1,5 +1,19 @@
1
1
  import { copy, invariant } from './values.mjs';
2
2
  export const BACKGROUND_COMMAND_CONTRACT = 'agentkit.background-command-observation/v1';
3
+ /** Bound a read view without retiring any durable command ownership. Prefer
4
+ * commands whose completion has not been accounted for, then recent history. */
5
+ export function projectBackgroundCommands(rows, limit, recentLimit = limit) {
6
+ const outstanding = [], recent = [];
7
+ for (let index = rows.length - 1; index >= 0 && outstanding.length < limit; index--) {
8
+ if (rows[index].notified === true) {
9
+ if (recent.length < recentLimit)
10
+ recent.push(index);
11
+ }
12
+ else
13
+ outstanding.push(index);
14
+ }
15
+ return [...outstanding, ...recent.slice(0, limit - outstanding.length)].sort((a, b) => a - b).map(index => rows[index]);
16
+ }
3
17
  function object(input) {
4
18
  invariant(input !== null && typeof input === 'object' && !Array.isArray(input), 'invalid_background_command_object');
5
19
  return copy(input);
@@ -99,7 +99,12 @@ export interface ChildLifecyclePort {
99
99
  }): Promise<{
100
100
  childRunIds: string[];
101
101
  }>;
102
- /** Host teardown is independent of a parent's write lease. */
102
+ /** Dispose Host ownership without canceling an idle, resumable parent or its children. */
103
+ closeRun?(request: {
104
+ scope: RunScope;
105
+ runId: string;
106
+ }): Promise<void>;
107
+ /** Release terminal or explicitly canceled work, canceling any live descendants. */
103
108
  releaseRun?(request: {
104
109
  scope: RunScope;
105
110
  runId: string;
@@ -12,6 +12,7 @@ import { summaryContinuityInstructions, validSummaryContinuity } from './summary
12
12
  import { responseBoundaryRecovery, responseContinuationPairs } from './response-continuation.mjs';
13
13
  import { verificationModelView } from './model-surface.mjs';
14
14
  import { currentInstructionContribution } from './context-contributions.mjs';
15
+ import { projectBackgroundCommands } from './background-contract.mjs';
15
16
  const emptyState = () => ({ history: null, compaction: null, compactions: 0,
16
17
  compactionsWithoutProgress: 0, progressDigest: null, lastModelCall: 0 });
17
18
  export const contextMessageRef = (message, index, digest) => `message:${index}:${digest(message)}`;
@@ -39,6 +40,7 @@ export function contextContinuity(snapshot, config, policies = new NativePolicyR
39
40
  const scopedEvidence = config.modelSurface?.verificationProjection === 'readable-evidence/v1';
40
41
  const canReadArtifacts = config.artifactPolicy === 'runtime-artifacts/v1' && config.tools.some(tool => tool.name === 'ArtifactRead'
41
42
  && (config.contract.allowedToolNames === null || config.contract.allowedToolNames.includes(tool.name)));
43
+ const commands = projectBackgroundCommands(snapshot.backgroundCommands, 32, 8);
42
44
  return copy({ schemaVersion: scopedEvidence ? 'agentkit.native-context-continuity/v2' : 'agentkit.native-context-continuity/v1', authority: 'host_record', goal: snapshot.goal,
43
45
  ...(snapshot.todos ? { todos: snapshot.todos.items, todoRevision: snapshot.todos.revision } : {}),
44
46
  ...(snapshot.planMode ? { planMode: snapshot.planMode, planModeGuidance: policies.forRun(config).planning.planModeGuidance(snapshot, config) } : {}),
@@ -54,7 +56,8 @@ export function contextContinuity(snapshot, config, policies = new NativePolicyR
54
56
  childBudgetReservations: snapshot.childBudgetReservations ?? [], childRunIds: snapshot.childRunIds ?? [],
55
57
  childApproval: snapshot.childApproval ?? null,
56
58
  children: snapshot.children.map(child => ({ runId: child.runId, state: child.state, notified: child.notified })),
57
- backgroundCommands: snapshot.backgroundCommands.map(command => ({ ...command.ref, notified: command.notified })),
59
+ backgroundCommands: commands.map(command => ({ ...command.ref, notified: command.notified })),
60
+ ...(commands.length < snapshot.backgroundCommands.length ? { omittedBackgroundCommands: snapshot.backgroundCommands.length - commands.length } : {}),
58
61
  verification: scopedEvidence ? verificationModelView(snapshot.verification, canReadArtifacts ? snapshot.artifactRefs : []) : snapshot.verification,
59
62
  hostBindingDigest: config.hostBindingDigest,
60
63
  ...(snapshot.executionBudgetObservation ? { executionBudget: snapshot.executionBudgetObservation } : {}),
@@ -154,7 +154,8 @@ export function reduceCommand(snapshot, command, pending = null, bindings = {})
154
154
  ? { reason: null, continuations: 0, outputRestarts: 0 } : {}),
155
155
  ...(bindings.configuration?.approvalOutcomePolicy === APPROVAL_OUTCOME_POLICY
156
156
  && ['approval_rejected', 'approval_cancelled', 'approval_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}),
157
- ...(['provider_unavailable', 'context_summary_unavailable', 'child_paused'].includes(snapshot.reason ?? '') ? { reason: null } : {}) };
157
+ ...(['provider_unavailable', 'context_summary_unavailable', 'context_source_unavailable', 'child_paused']
158
+ .includes(snapshot.reason ?? '') ? { reason: null } : {}) };
158
159
  break;
159
160
  case 'submit_interaction': {
160
161
  const pending = snapshot.pendingInteraction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-core",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Host-independent Native Harness contracts, transitions and durable execution.",
@@ -4,6 +4,18 @@ import { copy, invariant } from './values.mjs';
4
4
  export const BACKGROUND_COMMAND_CONTRACT = 'agentkit.background-command-observation/v1' as const;
5
5
  export interface BackgroundCommandRef { taskId: string; sourceRunId: string; operationKey: string }
6
6
  export interface BackgroundCommandState { ref: BackgroundCommandRef; notified: boolean }
7
+ /** Bound a read view without retiring any durable command ownership. Prefer
8
+ * commands whose completion has not been accounted for, then recent history. */
9
+ export function projectBackgroundCommands(rows: readonly BackgroundCommandState[], limit: number,
10
+ recentLimit = limit): BackgroundCommandState[] {
11
+ const outstanding: number[] = [], recent: number[] = [];
12
+ for (let index = rows.length - 1; index >= 0 && outstanding.length < limit; index--) {
13
+ if (rows[index]!.notified === true) {
14
+ if (recent.length < recentLimit) recent.push(index);
15
+ } else outstanding.push(index);
16
+ }
17
+ return [...outstanding, ...recent.slice(0, limit - outstanding.length)].sort((a, b) => a - b).map(index => rows[index]!);
18
+ }
7
19
  export interface BackgroundCommandRequest extends Omit<PortContext, 'signal'> {
8
20
  schemaVersion: typeof BACKGROUND_COMMAND_CONTRACT; cursor: string; refs: BackgroundCommandRef[];
9
21
  }
@@ -61,7 +61,9 @@ export interface ChildLifecyclePort {
61
61
  /** Read already sealed child facts after a lost parent claim. Never starts, approves or cancels execution. */
62
62
  reconcile?(request: ChildLifecycleRequest): Promise<ChildLifecycleResult | null>;
63
63
  readyChildren?(request: ChildReadyRequest & { signal: AbortSignal }): Promise<{ childRunIds: string[] }>;
64
- /** Host teardown is independent of a parent's write lease. */
64
+ /** Dispose Host ownership without canceling an idle, resumable parent or its children. */
65
+ closeRun?(request: { scope: RunScope; runId: string }): Promise<void>;
66
+ /** Release terminal or explicitly canceled work, canceling any live descendants. */
65
67
  releaseRun?(request: { scope: RunScope; runId: string }): Promise<void>;
66
68
  interruptedReceipts?(request: { scope: RunScope; runId: string; parentOperationKey: string }): Promise<{
67
69
  parentOperationKey: string; parentToolCallId: string; result: ToolResult;
@@ -14,6 +14,7 @@ import { summaryContinuityInstructions, validSummaryContinuity } from './summary
14
14
  import { responseBoundaryRecovery, responseContinuationPairs } from './response-continuation.mjs';
15
15
  import { verificationModelView } from './model-surface.mjs';
16
16
  import { currentInstructionContribution } from './context-contributions.mjs';
17
+ import { projectBackgroundCommands } from './background-contract.mjs';
17
18
 
18
19
  export interface ContextCounters {
19
20
  /** Clock observation for this journaled context effect; never recomputed during counting. */
@@ -46,6 +47,7 @@ export function contextContinuity(snapshot: RunSnapshot, config: RunConfiguratio
46
47
  const scopedEvidence = config.modelSurface?.verificationProjection === 'readable-evidence/v1';
47
48
  const canReadArtifacts = config.artifactPolicy === 'runtime-artifacts/v1' && config.tools.some(tool => tool.name === 'ArtifactRead'
48
49
  && (config.contract.allowedToolNames === null || config.contract.allowedToolNames.includes(tool.name)));
50
+ const commands = projectBackgroundCommands(snapshot.backgroundCommands, 32, 8);
49
51
  return copy({ schemaVersion: scopedEvidence ? 'agentkit.native-context-continuity/v2' : 'agentkit.native-context-continuity/v1', authority: 'host_record', goal: snapshot.goal,
50
52
  ...(snapshot.todos ? { todos: snapshot.todos.items, todoRevision: snapshot.todos.revision } : {}),
51
53
  ...(snapshot.planMode ? { planMode: snapshot.planMode, planModeGuidance: policies.forRun(config).planning.planModeGuidance(snapshot, config) } : {}),
@@ -61,7 +63,8 @@ export function contextContinuity(snapshot: RunSnapshot, config: RunConfiguratio
61
63
  childBudgetReservations: snapshot.childBudgetReservations ?? [], childRunIds: snapshot.childRunIds ?? [],
62
64
  childApproval: snapshot.childApproval ?? null,
63
65
  children: snapshot.children.map(child => ({ runId: child.runId, state: child.state, notified: child.notified })),
64
- backgroundCommands: snapshot.backgroundCommands.map(command => ({ ...command.ref, notified: command.notified })),
66
+ backgroundCommands: commands.map(command => ({ ...command.ref, notified: command.notified })),
67
+ ...(commands.length < snapshot.backgroundCommands.length ? { omittedBackgroundCommands: snapshot.backgroundCommands.length - commands.length } : {}),
65
68
  verification: scopedEvidence ? verificationModelView(snapshot.verification,
66
69
  canReadArtifacts ? snapshot.artifactRefs : []) : snapshot.verification,
67
70
  hostBindingDigest: config.hostBindingDigest,
@@ -149,7 +149,8 @@ export function reduceCommand(snapshot: RunSnapshot, command: RunCommand, pendin
149
149
  ? { reason: null, continuations: 0, outputRestarts: 0 } : {}),
150
150
  ...(bindings.configuration?.approvalOutcomePolicy === APPROVAL_OUTCOME_POLICY
151
151
  && ['approval_rejected', 'approval_cancelled', 'approval_unavailable'].includes(snapshot.reason ?? '') ? { reason: null } : {}),
152
- ...(['provider_unavailable', 'context_summary_unavailable', 'child_paused'].includes(snapshot.reason ?? '') ? { reason: null } : {}) };
152
+ ...(['provider_unavailable', 'context_summary_unavailable', 'context_source_unavailable', 'child_paused']
153
+ .includes(snapshot.reason ?? '') ? { reason: null } : {}) };
153
154
  break;
154
155
  case 'submit_interaction': {
155
156
  const pending = snapshot.pendingInteraction;