@myagentroam/agent 0.9.82 → 0.9.83
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/prompts/compact.js +5 -4
- package/dist/prompts/index.d.ts +1 -3
- package/dist/prompts/index.js +1 -5
- package/dist/prompts/resources.d.ts +2 -1
- package/dist/prompts/resources.js +21 -10
- package/dist/sdk/agent.js +91 -44
- package/dist/subagent/session-controller.js +8 -7
- package/dist/tools/agent-wait.js +1 -1
- package/package.json +1 -1
package/dist/prompts/compact.js
CHANGED
|
@@ -9,7 +9,7 @@ Preserve, when present:
|
|
|
9
9
|
- confirmed decisions, constraints, interfaces, invariants, assumptions that still matter, and exact identifiers;
|
|
10
10
|
- completed actions and edits with exact file paths, symbols, commands, migrations, or external state changes;
|
|
11
11
|
- verification actually run and its result, important tool evidence, reproducible errors, failed approaches and what they proved;
|
|
12
|
-
- unresolved questions, blockers, risks, uncommitted changes, Todo/plan state, pending approvals
|
|
12
|
+
- unresolved questions, blockers, risks, uncommitted changes, Todo/plan state, and pending approvals;
|
|
13
13
|
- the next concrete action and the evidence still required before completion.
|
|
14
14
|
|
|
15
15
|
Distinguish clearly between completed, attempted, planned, inferred, and unverified work. Newer user instructions override older ones; retain superseded instructions only when needed to explain current state. Never invent completion, test results, file contents, permissions, or external effects.
|
|
@@ -17,6 +17,7 @@ Distinguish clearly between completed, attempted, planned, inferred, and unverif
|
|
|
17
17
|
Remove aggressively:
|
|
18
18
|
- greetings, acknowledgements, progress chatter, repeated instructions, repeated status, and conclusions already represented once;
|
|
19
19
|
- user-level, project-level, or directory-level AGENTS.md instructions and constraints derived only from those files, because the next Execution reloads and replaces them separately;
|
|
20
|
+
- retained process/Subagent inventory, IDs, status, commands, cwd, and reuse instructions, because Runtime reloads and replaces that state separately;
|
|
20
21
|
- raw long logs, large source excerpts, verbose tool payloads, duplicated search/read output, and implementation detail recoverable from named files or commands;
|
|
21
22
|
- abandoned hypotheses and failed attempts that do not constrain the next action;
|
|
22
23
|
- hidden reasoning, secrets, credentials, authorization values, and unrelated conversation.
|
|
@@ -52,7 +53,7 @@ branch changed -> inherited_evidence=unverified
|
|
|
52
53
|
- direct user/caller authorization、prohibition、exclusion 保留 exact action/scope,不概括成更宽泛边界。
|
|
53
54
|
|
|
54
55
|
2. 当前状态 / Current state
|
|
55
|
-
- 对象:file、symbol、feature、migration、test、worktree、
|
|
56
|
+
- 对象:file、symbol、feature、migration、test、worktree、selected Skill、Todo/plan、approval、external side effect。retained process/subagent inventory 由 Runtime 重建,不进入 IR。
|
|
56
57
|
- 分离 completion(pending / in_progress / completed / blocked)、epistemic(observed / verified / inferred / proposed / disproved)、freshness(current / stale / superseded)、scope(turn / worktree / base / branch / external system);仅在消歧时标注。
|
|
57
58
|
- 明确 completed、not started、unverified、active。相同精度下选择更短状态原子;中文、English 均可,如 根因已证、edit=pending、tests=not run。
|
|
58
59
|
- selected Skill | 保留仍适用的 skill name + 续作必需约束;Todo/plan | 保留 revision、item/status、当前最小 step。
|
|
@@ -70,7 +71,7 @@ branch changed -> inherited_evidence=unverified
|
|
|
70
71
|
- 下一 Agent 无法使用、仅供 local storage validation 的 integrity hash:删除。
|
|
71
72
|
|
|
72
73
|
5. 未闭环 / Open loops
|
|
73
|
-
- unresolved、unverified、blocker、pending approval
|
|
74
|
+
- unresolved、unverified、blocker、pending approval、Todo/plan current step、仍需 evidence。
|
|
74
75
|
- 只保留已确定的最小 next action + preconditions;不复制可重算的长 plan。
|
|
75
76
|
|
|
76
77
|
编译规则:
|
|
@@ -85,7 +86,7 @@ observed HEAD、validated base、target commit、current worktree 不得折叠
|
|
|
85
86
|
|
|
86
87
|
语言:标题/一般叙述跟随 latest active user instructions 和当前任务主语言;每条 record 按局部精度与密度选择中文、English 或 mixed phrasing。保留 established term/exact identifier,不为语言统一展开或翻译。English codebase 不等于 English handoff。
|
|
87
88
|
|
|
88
|
-
删除 greetings、progress chatter、过程叙事、重复事实、无剩余约束的 superseded hypothesis、长日志、source body、verbose payload、可从精确 path/command 廉价恢复的正文。删除 user/project/directory AGENTS.md 正文及仅由这些文件派生的 constraint,包括其中 exclusions;下一 Execution
|
|
89
|
+
删除 greetings、progress chatter、过程叙事、重复事实、无剩余约束的 superseded hypothesis、长日志、source body、verbose payload、可从精确 path/command 廉价恢复的正文。删除 user/project/directory AGENTS.md 正文及仅由这些文件派生的 constraint,包括其中 exclusions;下一 Execution 会重新加载并整体替换。删除 retained process/Subagent inventory、ID、status、command、cwd 和 reuse instruction;Runtime 会重新加载并替换。不得保留 hidden reasoning、secret、credential、无关内容。
|
|
89
90
|
|
|
90
91
|
只输出 compact Markdown IR。`;
|
|
91
92
|
}
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ExecutionMode } from '../sdk/types.js';
|
|
2
2
|
import { type ExecutionBudgetPromptState } from './execution-budget.js';
|
|
3
|
-
import { type RetainedSessionResources } from './resources.js';
|
|
4
3
|
import { type CurrentAgentModel, type SubagentModelOption } from './subagent.js';
|
|
5
|
-
export declare const MAR_AGENT_PROMPT_VERSION = "1.
|
|
4
|
+
export declare const MAR_AGENT_PROMPT_VERSION = "1.50";
|
|
6
5
|
export declare function buildSystemPrompt(input: {
|
|
7
6
|
mode: ExecutionMode;
|
|
8
7
|
platform: string;
|
|
@@ -16,7 +15,6 @@ export declare function buildSystemPrompt(input: {
|
|
|
16
15
|
tools: readonly string[];
|
|
17
16
|
currentAgentModel?: CurrentAgentModel;
|
|
18
17
|
subagentModels?: readonly SubagentModelOption[];
|
|
19
|
-
retainedSessionResources?: RetainedSessionResources;
|
|
20
18
|
executionBudget?: ExecutionBudgetPromptState;
|
|
21
19
|
highDensityCompaction?: boolean;
|
|
22
20
|
extension?: string | undefined;
|
package/dist/prompts/index.js
CHANGED
|
@@ -3,10 +3,9 @@ import { environmentPrompt, identityPrompt, instructionPriorityPrompt, workspace
|
|
|
3
3
|
import { executionBudgetPrompt } from './execution-budget.js';
|
|
4
4
|
import { modePrompt } from './modes.js';
|
|
5
5
|
import { outputStylePrompt } from './output.js';
|
|
6
|
-
import { retainedSessionResourcesPrompt } from './resources.js';
|
|
7
6
|
import { subagentModelOptionsPrompt, subagentPrompt, currentAgentModelPrompt } from './subagent.js';
|
|
8
7
|
import { interactionPrompt, longRunningPrompt, safetyPrompt, toolUsagePrompt, workflowPrompt } from './workflow.js';
|
|
9
|
-
export const MAR_AGENT_PROMPT_VERSION = '1.
|
|
8
|
+
export const MAR_AGENT_PROMPT_VERSION = '1.50';
|
|
10
9
|
export function buildSystemPrompt(input) {
|
|
11
10
|
const toolNames = new Set(input.tools);
|
|
12
11
|
const hasLongRunningCapability = [
|
|
@@ -28,9 +27,6 @@ export function buildSystemPrompt(input) {
|
|
|
28
27
|
environmentPrompt(input),
|
|
29
28
|
input.tools.length > 0 ? toolUsagePrompt(input.tools) : '',
|
|
30
29
|
hasLongRunningCapability ? longRunningPrompt(input.tools) : '',
|
|
31
|
-
input.retainedSessionResources
|
|
32
|
-
? retainedSessionResourcesPrompt(input.retainedSessionResources)
|
|
33
|
-
: '',
|
|
34
30
|
input.executionBudget ? executionBudgetPrompt(input.executionBudget) : '',
|
|
35
31
|
modePrompt(input.mode, {
|
|
36
32
|
questionAvailable: toolNames.has('question'),
|
|
@@ -12,4 +12,5 @@ export interface RetainedSessionResources {
|
|
|
12
12
|
description: string;
|
|
13
13
|
}[];
|
|
14
14
|
}
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function retainedSessionResourcesSnapshot(input: RetainedSessionResources): string | undefined;
|
|
16
|
+
export declare function retainedSessionResourcesUpdate(snapshot: string | undefined, previousSnapshot: string | undefined, previousMayContainResources?: boolean): string | undefined;
|
|
@@ -1,31 +1,42 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function retainedSessionResourcesSnapshot(input) {
|
|
2
2
|
if (input.processes.length === 0 && input.subagents.length === 0)
|
|
3
|
-
return
|
|
3
|
+
return undefined;
|
|
4
|
+
const processes = [...input.processes].sort((left, right) => left.processId.localeCompare(right.processId));
|
|
5
|
+
const subagents = [...input.subagents].sort((left, right) => left.agentId.localeCompare(right.agentId));
|
|
4
6
|
return [
|
|
5
7
|
'# Retained Session resources',
|
|
6
8
|
'These resources belong to this Session and survived the previous Execution. Reuse their stable IDs instead of starting duplicate processes or subagents.',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
: 'Cancelling a managed process releases that process resource.',
|
|
10
|
-
input.subagents.length === 0
|
|
9
|
+
processes.length === 0 ? '' : 'Cancelling a managed process releases that process resource.',
|
|
10
|
+
subagents.length === 0
|
|
11
11
|
? ''
|
|
12
12
|
: 'agent_cancel stops only the current child turn and retains its Session for later messages or explicit deletion.',
|
|
13
13
|
input.idleTtlMs === undefined
|
|
14
14
|
? ''
|
|
15
15
|
: `When the Session becomes idle again, unclaimed resources are retained for up to ${input.idleTtlMs} ms.`,
|
|
16
|
-
|
|
16
|
+
processes.length === 0
|
|
17
17
|
? ''
|
|
18
18
|
: [
|
|
19
19
|
'Managed processes:',
|
|
20
|
-
...
|
|
20
|
+
...processes.map((process) => `- processId: ${process.processId}; status: ${process.status}; cwd: ${process.cwd}; command: ${process.command}`)
|
|
21
21
|
].join('\n'),
|
|
22
|
-
|
|
22
|
+
subagents.length === 0
|
|
23
23
|
? ''
|
|
24
24
|
: [
|
|
25
25
|
'Subagents:',
|
|
26
|
-
...
|
|
26
|
+
...subagents.map((task) => `- agentId: ${task.agentId}; status: ${task.status}; description: ${task.description}`)
|
|
27
27
|
].join('\n')
|
|
28
28
|
]
|
|
29
29
|
.filter(Boolean)
|
|
30
30
|
.join('\n');
|
|
31
31
|
}
|
|
32
|
+
export function retainedSessionResourcesUpdate(snapshot, previousSnapshot, previousMayContainResources = false) {
|
|
33
|
+
if (!previousMayContainResources && snapshot === previousSnapshot)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (!snapshot)
|
|
36
|
+
return previousSnapshot || previousMayContainResources
|
|
37
|
+
? 'The previously provided retained Session resources no longer apply. No retained processes or subagents remain.'
|
|
38
|
+
: undefined;
|
|
39
|
+
return previousSnapshot || previousMayContainResources
|
|
40
|
+
? `This replaces all previously provided retained Session resources.\n\n${snapshot}`
|
|
41
|
+
: snapshot;
|
|
42
|
+
}
|
package/dist/sdk/agent.js
CHANGED
|
@@ -18,6 +18,7 @@ import { DEFAULT_COMPACTION_FOCUS, CompactionOperation, buildCompactionInput, bu
|
|
|
18
18
|
import { buildSystemPrompt, MAR_AGENT_PROMPT_VERSION } from '../prompts/index.js';
|
|
19
19
|
import { buildEnvironmentContext } from '../prompts/core.js';
|
|
20
20
|
import { modelOutputContinuationMessage } from '../prompts/output.js';
|
|
21
|
+
import { retainedSessionResourcesSnapshot, retainedSessionResourcesUpdate } from '../prompts/resources.js';
|
|
21
22
|
import { environmentContextUpdate, restoreEnvironmentState } from '../runtime/environment-context.js';
|
|
22
23
|
import { childSubagentInstruction } from '../prompts/subagent.js';
|
|
23
24
|
import { sessionTitlePrompt } from '../prompts/title.js';
|
|
@@ -249,22 +250,24 @@ export async function createMarAgent(options) {
|
|
|
249
250
|
const sessionState = await store.readExecutionState(sessionId);
|
|
250
251
|
const todo = TodoStore.restore(sessionState.todo);
|
|
251
252
|
const contextRecords = sessionState.contextRecords;
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
let
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
generation:
|
|
253
|
+
const contextualWorldStateGeneration = latestContextualWorldStateGeneration(contextRecords);
|
|
254
|
+
const restoredContextualWorldState = sessionRuntime.contextualWorldState;
|
|
255
|
+
let contextualWorldState;
|
|
256
|
+
if (restoredContextualWorldState === undefined ||
|
|
257
|
+
restoredContextualWorldState.generation !== contextualWorldStateGeneration) {
|
|
258
|
+
contextualWorldState = {
|
|
259
|
+
generation: contextualWorldStateGeneration,
|
|
259
260
|
initialized: false,
|
|
260
|
-
|
|
261
|
+
instructionSnapshot: undefined,
|
|
262
|
+
resourceSnapshot: undefined,
|
|
261
263
|
entries: []
|
|
262
264
|
};
|
|
263
|
-
sessionRuntime.
|
|
265
|
+
sessionRuntime.contextualWorldState = contextualWorldState;
|
|
264
266
|
}
|
|
265
267
|
else
|
|
266
|
-
|
|
268
|
+
contextualWorldState = restoredContextualWorldState;
|
|
267
269
|
const compactMayContainAgentInstructions = contextRecords.some((record) => compactSummaryFromCheckpoint(record) !== undefined);
|
|
270
|
+
const compactMayContainRetainedResources = compactHistoryMayContainRetainedResources(contextRecords);
|
|
268
271
|
const restored = await restoreMessages(store, sessionId, contextRecords, {
|
|
269
272
|
includeImages: mode !== 'compact'
|
|
270
273
|
});
|
|
@@ -462,29 +465,29 @@ export async function createMarAgent(options) {
|
|
|
462
465
|
agentInstructionInsertIndex &&
|
|
463
466
|
messages[agentInstructionInsertIndex - 1]?.contextKind === 'environment')
|
|
464
467
|
agentInstructionInsertIndex--;
|
|
465
|
-
if (!contextualInstructions.initialized ||
|
|
466
|
-
contextualInstructions.snapshot !== currentInstructionSnapshot) {
|
|
467
|
-
const content = renderAgentInstructions(instructionEntries, compactMayContainAgentInstructions || contextualInstructions.entries.length > 0);
|
|
468
|
-
if (content !== undefined)
|
|
469
|
-
contextualInstructions.entries.push({
|
|
470
|
-
index: agentInstructionInsertIndex,
|
|
471
|
-
content
|
|
472
|
-
});
|
|
473
|
-
contextualInstructions.snapshot = currentInstructionSnapshot;
|
|
474
|
-
contextualInstructions.initialized = true;
|
|
475
|
-
}
|
|
476
468
|
const tools = withCodeModeResultTypes(availableTools.filter((tool) => tool.name !== 'skill' || (instructionContext?.skills.size ?? 0) > 0));
|
|
477
469
|
const executionTools = tools;
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
470
|
+
const loadRetainedSessionResources = async () => {
|
|
471
|
+
const hostResources = (await options.host.listSessionResources?.(sessionId)) ?? {
|
|
472
|
+
processes: []
|
|
473
|
+
};
|
|
474
|
+
return {
|
|
475
|
+
...(hostResources.idleTtlMs === undefined
|
|
476
|
+
? {}
|
|
477
|
+
: { idleTtlMs: hostResources.idleTtlMs }),
|
|
478
|
+
processes: hostResources.processes,
|
|
479
|
+
subagents: subagents?.listSessionResources() ?? []
|
|
480
|
+
};
|
|
487
481
|
};
|
|
482
|
+
let currentResourceSnapshot = retainedSessionResourcesSnapshot(await loadRetainedSessionResources());
|
|
483
|
+
contextualWorldState = updateContextualWorldState(contextualWorldState, agentInstructionInsertIndex, {
|
|
484
|
+
instructionSnapshot: currentInstructionSnapshot,
|
|
485
|
+
instructionContent: renderAgentInstructions(instructionEntries, compactMayContainAgentInstructions ||
|
|
486
|
+
contextualWorldState.instructionSnapshot !== undefined),
|
|
487
|
+
resourceSnapshot: currentResourceSnapshot,
|
|
488
|
+
previousMayContainResources: compactMayContainRetainedResources
|
|
489
|
+
});
|
|
490
|
+
sessionRuntime.contextualWorldState = contextualWorldState;
|
|
488
491
|
const buildExecutionSystemPrompt = (availableTools = executionTools, promptMode = mode) => buildSystemPrompt({
|
|
489
492
|
mode: promptMode,
|
|
490
493
|
platform: description.platform,
|
|
@@ -512,7 +515,6 @@ export async function createMarAgent(options) {
|
|
|
512
515
|
reasoningEfforts: configuration.reasoningEfforts
|
|
513
516
|
}))
|
|
514
517
|
: [],
|
|
515
|
-
retainedSessionResources,
|
|
516
518
|
highDensityCompaction: selectedModel.highDensityCompaction,
|
|
517
519
|
...(rolloutBudget?.active
|
|
518
520
|
? {
|
|
@@ -537,7 +539,9 @@ export async function createMarAgent(options) {
|
|
|
537
539
|
if (mode === 'compact') {
|
|
538
540
|
const compactSystemPrompt = initialSystemPrompt;
|
|
539
541
|
const compactHistory = [...messages];
|
|
540
|
-
const projectedHistory = normalizeMessagesForModel(
|
|
542
|
+
const projectedHistory = normalizeMessagesForModel(insertContextualWorldState(compactHistory, contextualWorldState.entries, {
|
|
543
|
+
excludeResources: true
|
|
544
|
+
}), { supportsImages: false });
|
|
541
545
|
const nativeMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
542
546
|
focus: input.prompt,
|
|
543
547
|
highDensityCompaction: selectedModel.highDensityCompaction
|
|
@@ -593,7 +597,9 @@ export async function createMarAgent(options) {
|
|
|
593
597
|
let compactSummary = '';
|
|
594
598
|
const compactSystemPrompt = buildExecutionSystemPrompt(executionTools, 'run');
|
|
595
599
|
const compactHistory = retainCurrent ? messages.slice(0, -1) : messages;
|
|
596
|
-
const projectedHistory = normalizeMessagesForModel(
|
|
600
|
+
const projectedHistory = normalizeMessagesForModel(insertContextualWorldState(compactHistory, contextualWorldState.entries, {
|
|
601
|
+
excludeResources: true
|
|
602
|
+
}), { supportsImages: false });
|
|
597
603
|
const nativeCompactMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
598
604
|
highDensityCompaction: selectedModel.highDensityCompaction
|
|
599
605
|
});
|
|
@@ -686,8 +692,14 @@ export async function createMarAgent(options) {
|
|
|
686
692
|
.filter((message) => message.kind === 'user_input')
|
|
687
693
|
.map((message) => message.content);
|
|
688
694
|
agentInstructionInsertIndex = Math.max(0, messages.length - 1);
|
|
689
|
-
|
|
690
|
-
|
|
695
|
+
currentResourceSnapshot = retainedSessionResourcesSnapshot(await loadRetainedSessionResources());
|
|
696
|
+
contextualWorldState = resetContextualWorldState(compactRecord.recordId, agentInstructionInsertIndex, {
|
|
697
|
+
instructionSnapshot: currentInstructionSnapshot,
|
|
698
|
+
instructionContent: renderAgentInstructions(instructionEntries, true),
|
|
699
|
+
resourceSnapshot: currentResourceSnapshot,
|
|
700
|
+
previousMayContainResources: compactSummary.includes('# Retained Session resources')
|
|
701
|
+
});
|
|
702
|
+
sessionRuntime.contextualWorldState = contextualWorldState;
|
|
691
703
|
sessionRuntime.responsesChain = undefined;
|
|
692
704
|
lastServerContextTokens = undefined;
|
|
693
705
|
lastServerUsage = undefined;
|
|
@@ -726,7 +738,7 @@ export async function createMarAgent(options) {
|
|
|
726
738
|
.update(stableJson({
|
|
727
739
|
modelId: selectedModel.id,
|
|
728
740
|
systemPrompt,
|
|
729
|
-
|
|
741
|
+
contextualWorldState: contextualWorldState.entries,
|
|
730
742
|
tools: roundTools,
|
|
731
743
|
reasoningEffort
|
|
732
744
|
}))
|
|
@@ -745,7 +757,7 @@ export async function createMarAgent(options) {
|
|
|
745
757
|
: undefined;
|
|
746
758
|
const modelMessages = mode === 'compact'
|
|
747
759
|
? normalizeMessagesForModel(requestContextMessages, { supportsImages: false })
|
|
748
|
-
: normalizeMessagesForModel(
|
|
760
|
+
: normalizeMessagesForModel(insertContextualWorldState(requestContextMessages, contextualWorldState.entries), {
|
|
749
761
|
supportsImages: selectedModel.inputCapabilities.includes('IMAGE')
|
|
750
762
|
});
|
|
751
763
|
let sawModelSemanticEvent = false;
|
|
@@ -1167,8 +1179,14 @@ export async function createMarAgent(options) {
|
|
|
1167
1179
|
if (agentInstructionInsertIndex &&
|
|
1168
1180
|
messages[agentInstructionInsertIndex - 1]?.contextKind === 'environment')
|
|
1169
1181
|
agentInstructionInsertIndex--;
|
|
1170
|
-
|
|
1171
|
-
|
|
1182
|
+
currentResourceSnapshot = retainedSessionResourcesSnapshot(await loadRetainedSessionResources());
|
|
1183
|
+
contextualWorldState = resetContextualWorldState(latestContextualWorldStateGeneration(committed.records), agentInstructionInsertIndex, {
|
|
1184
|
+
instructionSnapshot: currentInstructionSnapshot,
|
|
1185
|
+
instructionContent: renderAgentInstructions(instructionEntries, committed.records.some((record) => compactSummaryFromCheckpoint(record) !== undefined)),
|
|
1186
|
+
resourceSnapshot: currentResourceSnapshot,
|
|
1187
|
+
previousMayContainResources: compactHistoryMayContainRetainedResources(committed.records)
|
|
1188
|
+
});
|
|
1189
|
+
sessionRuntime.contextualWorldState = contextualWorldState;
|
|
1172
1190
|
}
|
|
1173
1191
|
}
|
|
1174
1192
|
if (controller.signal.aborted) {
|
|
@@ -1764,17 +1782,19 @@ function modelIdFromPayload(payload, key = 'modelId') {
|
|
|
1764
1782
|
const value = payload[key];
|
|
1765
1783
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
1766
1784
|
}
|
|
1767
|
-
function
|
|
1785
|
+
function insertContextualWorldState(messages, entries, options = {}) {
|
|
1768
1786
|
const result = [...messages];
|
|
1769
1787
|
let offset = 0;
|
|
1770
1788
|
for (const entry of entries) {
|
|
1789
|
+
if (options.excludeResources && entry.kind === 'resources')
|
|
1790
|
+
continue;
|
|
1771
1791
|
const insertionIndex = Math.max(0, Math.min(entry.index + offset, result.length));
|
|
1772
1792
|
result.splice(insertionIndex, 0, { role: 'user', content: entry.content });
|
|
1773
1793
|
offset++;
|
|
1774
1794
|
}
|
|
1775
1795
|
return result;
|
|
1776
1796
|
}
|
|
1777
|
-
function
|
|
1797
|
+
function latestContextualWorldStateGeneration(records) {
|
|
1778
1798
|
let generation;
|
|
1779
1799
|
for (const record of records)
|
|
1780
1800
|
if (record.type === 'context.gc.completed' ||
|
|
@@ -1782,12 +1802,39 @@ function latestContextualInstructionGeneration(records) {
|
|
|
1782
1802
|
generation = record.recordId;
|
|
1783
1803
|
return generation;
|
|
1784
1804
|
}
|
|
1785
|
-
function
|
|
1805
|
+
function compactHistoryMayContainRetainedResources(records) {
|
|
1806
|
+
return records.some((record) => compactSummaryFromCheckpoint(record)?.includes('# Retained Session resources'));
|
|
1807
|
+
}
|
|
1808
|
+
function updateContextualWorldState(state, index, current) {
|
|
1809
|
+
const entries = [...state.entries];
|
|
1810
|
+
if (!state.initialized || state.instructionSnapshot !== current.instructionSnapshot) {
|
|
1811
|
+
if (current.instructionContent !== undefined)
|
|
1812
|
+
entries.push({ index, kind: 'instructions', content: current.instructionContent });
|
|
1813
|
+
}
|
|
1814
|
+
const resourceContent = retainedSessionResourcesUpdate(current.resourceSnapshot, state.initialized ? state.resourceSnapshot : undefined, !state.initialized && current.previousMayContainResources);
|
|
1815
|
+
if (resourceContent !== undefined)
|
|
1816
|
+
entries.push({ index, kind: 'resources', content: resourceContent });
|
|
1817
|
+
return {
|
|
1818
|
+
generation: state.generation,
|
|
1819
|
+
initialized: true,
|
|
1820
|
+
instructionSnapshot: current.instructionSnapshot,
|
|
1821
|
+
resourceSnapshot: current.resourceSnapshot,
|
|
1822
|
+
entries
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
function resetContextualWorldState(generation, index, current) {
|
|
1826
|
+
const entries = [];
|
|
1827
|
+
if (current.instructionContent !== undefined)
|
|
1828
|
+
entries.push({ index, kind: 'instructions', content: current.instructionContent });
|
|
1829
|
+
const resourceContent = retainedSessionResourcesUpdate(current.resourceSnapshot, undefined, current.previousMayContainResources);
|
|
1830
|
+
if (resourceContent !== undefined)
|
|
1831
|
+
entries.push({ index, kind: 'resources', content: resourceContent });
|
|
1786
1832
|
return {
|
|
1787
1833
|
generation,
|
|
1788
1834
|
initialized: true,
|
|
1789
|
-
|
|
1790
|
-
|
|
1835
|
+
instructionSnapshot: current.instructionSnapshot,
|
|
1836
|
+
resourceSnapshot: current.resourceSnapshot,
|
|
1837
|
+
entries
|
|
1791
1838
|
};
|
|
1792
1839
|
}
|
|
1793
1840
|
function contextualInstructionInsertIndex(messages) {
|
|
@@ -160,9 +160,9 @@ export class SubagentSessionController {
|
|
|
160
160
|
if (waitFor === 'completion') {
|
|
161
161
|
const completed = await this.#waitForCompletion(state, waitMs, options.signal);
|
|
162
162
|
options.signal?.throwIfAborted();
|
|
163
|
-
const includeLatestMessage =
|
|
163
|
+
const includeLatestMessage = this.#hasUnreadMessage(state);
|
|
164
164
|
const includeTerminalDetails = completed ? this.#observeTerminal(state) : false;
|
|
165
|
-
if (
|
|
165
|
+
if (includeLatestMessage)
|
|
166
166
|
this.#observeLatestMessage(state);
|
|
167
167
|
return {
|
|
168
168
|
...this.#snapshot(state, { includeLatestMessage, includeTerminalDetails }),
|
|
@@ -244,12 +244,13 @@ export class SubagentSessionController {
|
|
|
244
244
|
}
|
|
245
245
|
const completed = await this.#waitForAnyCompletion(live, waitMs, options.signal);
|
|
246
246
|
options.signal?.throwIfAborted();
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
const state = completed ?? this.#oldestUnreadMessage(live) ?? live.at(-1);
|
|
248
|
+
const includeLatestMessage = this.#hasUnreadMessage(state);
|
|
249
|
+
const includeTerminalDetails = completed ? this.#observeTerminal(state) : false;
|
|
250
|
+
if (includeLatestMessage)
|
|
251
|
+
this.#observeLatestMessage(state);
|
|
251
252
|
return {
|
|
252
|
-
...this.#snapshot(
|
|
253
|
+
...this.#snapshot(state, {
|
|
253
254
|
includeLatestMessage,
|
|
254
255
|
includeTerminalDetails
|
|
255
256
|
}),
|
package/dist/tools/agent-wait.js
CHANGED
|
@@ -3,7 +3,7 @@ import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
|
|
|
3
3
|
export const agentWaitToolDefinition = {
|
|
4
4
|
name: 'agent_wait',
|
|
5
5
|
parallelSafety: 'serial',
|
|
6
|
-
description: 'Read or wait a bounded time for a child agent result. waitFor defaults to "completion"; use "message" only when a fresh public commentary/final message would change the next decision. Omit agentId to wait for whichever live child returns first, matching Codex-style untargeted waiting and avoiding UUID transcription; provide the exact agentId returned by agent_start only when observing a specific child. If no child is live, untargeted waiting reads the most recently created child. For an exec processId, use exec with action:"poll" instead. Omitting waitMs waits up to 30 seconds by default; waitMs=0 returns the current snapshot immediately. Positive waits range up to 5 minutes, and positive values below 10 seconds are raised to 10 seconds. When blocked on a live child result, prefer one 300000 ms completion wait rather than repeated short waits. Every result includes waitOutcome as snapshot, message, completion, or timeout plus the real agentId and description. A message or first terminal completion result includes the newly observed latest public commentary/final message;
|
|
6
|
+
description: 'Read or wait a bounded time for a child agent result. waitFor defaults to "completion"; use "message" only when a fresh public commentary/final message would change the next decision. Omit agentId to wait for whichever live child returns first, matching Codex-style untargeted waiting and avoiding UUID transcription; provide the exact agentId returned by agent_start only when observing a specific child. If no child is live, untargeted waiting reads the most recently created child. For an exec processId, use exec with action:"poll" instead. Omitting waitMs waits up to 30 seconds by default; waitMs=0 returns the current snapshot immediately. Positive waits range up to 5 minutes, and positive values below 10 seconds are raised to 10 seconds. When blocked on a live child result, prefer one 300000 ms completion wait rather than repeated short waits. Every result includes waitOutcome as snapshot, message, completion, or timeout plus the real agentId and description. A message, timeout with unread progress, or first terminal completion result includes the newly observed latest public commentary/final message; snapshots and repeated observations omit previously observed message text. latestActivity can still identify a public message or bounded tool started/completed/failed status. A queued or running result is not completion. A message wait consumes only the latest unread public message in the current Session runtime; tool activity does not wake it, and parent cancellation preserves unread progress for a later Execution. Do not use message waits as heartbeat checks or request progress merely to confirm that a child is still running. First terminal results include bounded summary, changedFiles, verification, and read evidence with path/line ranges; use that evidence to avoid repeating the full exploration, while independently checking consequential edits and claims.',
|
|
7
7
|
inputSchema: {
|
|
8
8
|
type: 'object',
|
|
9
9
|
properties: {
|