@myagentroam/agent 0.13.29 → 0.13.31
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/index.js +1 -8
- package/dist/runtime/context/gc-candidates-web.js +11 -9
- package/dist/runtime/context/gc-candidates.js +10 -2
- package/dist/runtime/events.d.ts +1 -1
- package/dist/session/context-gc-checkpoint.js +21 -13
- package/dist/session/context-gc-contract.d.ts +1 -1
- package/dist/session/context-gc-observations.js +6 -6
- package/dist/session/context-gc-replacements.js +1 -0
- package/dist/session/context-gc-todo.d.ts +9 -1
- package/dist/session/context-gc-todo.js +42 -2
- package/dist/tools/agent/{todo-read.d.ts → todo-tool.d.ts} +3 -4
- package/dist/tools/agent/todo-tool.js +84 -0
- package/dist/tools/agent/todo.d.ts +1 -1
- package/dist/tools/agent/todo.js +1 -1
- package/dist/tools/code-mode/index.js +2 -0
- package/dist/tools/output-projection.d.ts +2 -1
- package/dist/tools/output-projection.js +12 -2
- package/dist/tools/registry.js +3 -7
- package/package.json +1 -1
- package/dist/tools/agent/todo-read.js +0 -13
- package/dist/tools/agent/todo-write.d.ts +0 -16
- package/dist/tools/agent/todo-write.js +0 -68
package/dist/prompts/index.js
CHANGED
|
@@ -10,14 +10,7 @@ export function buildSystemPrompt(input) {
|
|
|
10
10
|
}
|
|
11
11
|
export function buildSystemPromptSections(input) {
|
|
12
12
|
const toolNames = new Set(input.tools);
|
|
13
|
-
const hasLongRunningCapability = [
|
|
14
|
-
'exec',
|
|
15
|
-
'todo_read',
|
|
16
|
-
'todo_write',
|
|
17
|
-
'agent_start',
|
|
18
|
-
'agent_wait',
|
|
19
|
-
'agent_stop'
|
|
20
|
-
].some((name) => toolNames.has(name));
|
|
13
|
+
const hasLongRunningCapability = ['exec', 'todo', 'agent_start', 'agent_wait', 'agent_stop'].some((name) => toolNames.has(name));
|
|
21
14
|
const values = [
|
|
22
15
|
['identity', identityPrompt()],
|
|
23
16
|
['instruction-priority', instructionPriorityPrompt],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { contextGcTargetKey } from '../../session/context-gc-checkpoint.js';
|
|
2
|
-
import { completedTodoWrite, todoInputReplacement, todoSnapshotReplacement, visibleTodoSnapshot } from '../../session/context-gc-todo.js';
|
|
2
|
+
import { completedTodoWrite, isTodoRead, todoInputReplacement, todoSnapshotReplacement, visibleTodoSnapshot } from '../../session/context-gc-todo.js';
|
|
3
3
|
import { contextGcWebOutputReplacement, contextGcToolOutputReplacement, contextGcSkillOutputReplacement, hasGenericContextGcPreview, isGenericContextGcTool } from '../../session/context-gc-replacements.js';
|
|
4
4
|
import { CONTEXT_GC_TEXT_PROTECTION_ROLLOUTS, contextGcProtectionMature } from '../../session/context-gc-protection.js';
|
|
5
5
|
import { targetFor, isRecord } from './gc-candidates.js';
|
|
@@ -111,20 +111,21 @@ export function collectToolOutputCandidates(input, groups, existingTargets, cand
|
|
|
111
111
|
eligible.push(candidate);
|
|
112
112
|
}
|
|
113
113
|
const writes = input.records.flatMap((record) => {
|
|
114
|
-
const fact = completedTodoWrite(record);
|
|
114
|
+
const fact = completedTodoWrite(record, input.records);
|
|
115
115
|
return fact ? [{ record, ...fact }] : [];
|
|
116
116
|
});
|
|
117
117
|
for (const group of groups.values()) {
|
|
118
118
|
if (group.failed || !group.completed || !group.call || group.call.message.role !== 'tool_call')
|
|
119
119
|
continue;
|
|
120
|
-
const ownWrite = completedTodoWrite(group.completed);
|
|
121
|
-
const snapshot = group.toolName
|
|
120
|
+
const ownWrite = completedTodoWrite(group.completed, input.records);
|
|
121
|
+
const snapshot = isTodoRead(group.toolName, group.call.message.arguments) &&
|
|
122
|
+
group.result?.message.role === 'tool'
|
|
122
123
|
? visibleTodoSnapshot(group.result.message.content)
|
|
123
124
|
: undefined;
|
|
124
|
-
const currentRevision =
|
|
125
|
+
const currentRevision = ownWrite?.revision ?? snapshot?.revision;
|
|
125
126
|
if (currentRevision === undefined)
|
|
126
127
|
continue;
|
|
127
|
-
const targetEntry =
|
|
128
|
+
const targetEntry = ownWrite ? group.call : group.result;
|
|
128
129
|
if (!targetEntry)
|
|
129
130
|
continue;
|
|
130
131
|
const target = targetFor(targetEntry.record, targetEntry.message);
|
|
@@ -132,6 +133,7 @@ export function collectToolOutputCandidates(input, groups, existingTargets, cand
|
|
|
132
133
|
continue;
|
|
133
134
|
const successor = writes
|
|
134
135
|
.filter((write) => write.revision > currentRevision &&
|
|
136
|
+
write.record.sequence > group.completed.sequence &&
|
|
135
137
|
contextGcProtectionMature(input.protection.after(Math.max(target.sequence, group.completed.sequence, write.record.sequence))))
|
|
136
138
|
.sort((a, b) => b.revision - a.revision)[0];
|
|
137
139
|
if (!successor)
|
|
@@ -139,13 +141,13 @@ export function collectToolOutputCandidates(input, groups, existingTargets, cand
|
|
|
139
141
|
const evidenceSequence = successor.record.sequence;
|
|
140
142
|
const observedRollouts = input.protection.after(Math.max(target.sequence, group.completed.sequence, evidenceSequence)).rollouts;
|
|
141
143
|
let replacement;
|
|
142
|
-
if (group.toolName === 'todo_write') {
|
|
144
|
+
if (ownWrite && (group.toolName === 'todo_write' || group.toolName === 'todo')) {
|
|
143
145
|
const args = group.call.message.arguments;
|
|
144
146
|
if (!isRecord(args) || !Array.isArray(args.items))
|
|
145
147
|
continue;
|
|
146
148
|
replacement = {
|
|
147
149
|
kind: 'TOOL_CALL_INPUT',
|
|
148
|
-
toolName:
|
|
150
|
+
toolName: group.toolName,
|
|
149
151
|
callId: group.callId,
|
|
150
152
|
target,
|
|
151
153
|
replacementArguments: todoInputReplacement(currentRevision, args.items.length, successor.revision),
|
|
@@ -160,7 +162,7 @@ export function collectToolOutputCandidates(input, groups, existingTargets, cand
|
|
|
160
162
|
continue;
|
|
161
163
|
replacement = {
|
|
162
164
|
kind: 'TOOL_OUTPUT',
|
|
163
|
-
toolName:
|
|
165
|
+
toolName: group.toolName,
|
|
164
166
|
callId: group.callId,
|
|
165
167
|
target,
|
|
166
168
|
replacementContent: todoSnapshotReplacement(currentRevision, snapshot.count, successor.revision),
|
|
@@ -15,8 +15,11 @@ export function buildToolGroups(records, messages, sources) {
|
|
|
15
15
|
};
|
|
16
16
|
for (const [index, message] of messages.entries()) {
|
|
17
17
|
const record = sources[index];
|
|
18
|
-
if (message.role === 'tool_call' && message.callId && message.name)
|
|
19
|
-
group(message.callId, message.name)
|
|
18
|
+
if (message.role === 'tool_call' && message.callId && message.name) {
|
|
19
|
+
const current = group(message.callId, message.name);
|
|
20
|
+
current.toolName = message.name;
|
|
21
|
+
current.call = { message, record };
|
|
22
|
+
}
|
|
20
23
|
else if (message.role === 'tool' && message.callId)
|
|
21
24
|
group(message.callId).result = { message, record };
|
|
22
25
|
else if (message.role === 'provider') {
|
|
@@ -34,6 +37,11 @@ export function buildToolGroups(records, messages, sources) {
|
|
|
34
37
|
if (typeof callId !== 'string' || typeof toolName !== 'string')
|
|
35
38
|
continue;
|
|
36
39
|
const current = group(callId, toolName);
|
|
40
|
+
if (current.call &&
|
|
41
|
+
(record.sequence <= current.call.record.sequence ||
|
|
42
|
+
record.executionId !== current.call.record.executionId ||
|
|
43
|
+
toolName !== current.toolName))
|
|
44
|
+
continue;
|
|
37
45
|
if (type === 'tool.completed')
|
|
38
46
|
current.completed = record;
|
|
39
47
|
else if (type === 'tool.failed')
|
package/dist/runtime/events.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ export type AgentEvent = AgentEventBase & ({
|
|
|
113
113
|
summaryTruncated?: boolean;
|
|
114
114
|
outputTruncation?: 'HEAD' | 'SOURCE';
|
|
115
115
|
artifacts?: readonly AgentToolArtifact[];
|
|
116
|
-
data?: CodeCellEventData | import('../tools/contracts.js').ExecResult | Omit<import('../tools/contracts.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/contracts.js').ApplyPatchResult | import('../tools/contracts.js').ReadEventData | import('../tools/contracts.js').ViewImageResult | import('../tools/contracts.js').SleepResult | Readonly<Record<string, unknown>> | import('./public-tool-metadata.js').PublicToolMetadata;
|
|
116
|
+
data?: CodeCellEventData | import('../tools/contracts.js').ExecResult | Omit<import('../tools/contracts.js').ExecResult, 'stdout' | 'stderr'> | import('../tools/contracts.js').ApplyPatchResult | import('../tools/contracts.js').ReadEventData | import('../tools/contracts.js').ViewImageResult | import('../tools/contracts.js').SleepResult | import('../tools/contracts.js').TodoSnapshot | Readonly<Record<string, unknown>> | import('./public-tool-metadata.js').PublicToolMetadata;
|
|
117
117
|
} | {
|
|
118
118
|
type: 'tool.failed';
|
|
119
119
|
resultExtensions?: readonly import('../tools/result-extension-contract.js').ToolResultExtension[];
|
|
@@ -2,7 +2,7 @@ import { posix, win32 } from 'node:path';
|
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
3
|
import { inlineMediaGcAnchored, parseInlineMediaGc } from './inline-media.js';
|
|
4
4
|
import { buildContextGcProtection, contextGcProtectionMature } from './context-gc-protection.js';
|
|
5
|
-
import { completedTodoWrite, todoInputReplacement, todoSnapshotReplacement, visibleTodoSnapshot } from './context-gc-todo.js';
|
|
5
|
+
import { completedTodoWrite, todoWriteForCall, isTodoRead, isTodoWrite, todoInputReplacement, todoSnapshotReplacement, visibleTodoSnapshot } from './context-gc-todo.js';
|
|
6
6
|
import { contextGcRetainedInputMarkup } from './context-gc-markup.js';
|
|
7
7
|
import { codeCallEvidence, codePartialPatchCallEvidence, callsFromRecord, codeObservationEvidence, observationsFromRecord, retainedCodeInputs } from './context-gc-observations.js';
|
|
8
8
|
import { parseReadContextOutput } from '../prompts/read-context.js';
|
|
@@ -205,10 +205,12 @@ export function validateContextGcCheckpoint(records, record, workspace = session
|
|
|
205
205
|
const anchors = replacement.kind === 'READ_OUTPUT_ITEMS'
|
|
206
206
|
? replacement.items.map((item) => Math.max(replacement.target.sequence, item.evidenceSequence))
|
|
207
207
|
: [Math.max(replacement.target.sequence, ...evidence)];
|
|
208
|
-
if (replacement.kind === 'TOOL_CALL_INPUT' &&
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
if (replacement.kind === 'TOOL_CALL_INPUT' &&
|
|
209
|
+
['todo_write', 'todo'].includes(replacement.toolName)) {
|
|
210
|
+
const source = recordsBySequence.get(replacement.target.sequence);
|
|
211
|
+
const own = todoWriteForCall(records, source);
|
|
212
|
+
if (own)
|
|
213
|
+
anchors[0] = Math.max(anchors[0], own.record.sequence);
|
|
212
214
|
}
|
|
213
215
|
if ((replacement.kind === 'TOOL_CALL_INPUT' && replacement.toolName === 'code_exec') ||
|
|
214
216
|
(replacement.kind === 'CODE_MODE_OUTPUT' && !replacement.target.observationId)) {
|
|
@@ -372,14 +374,15 @@ function replacementMatchesRecords(replacement, records, recordsBySequence, work
|
|
|
372
374
|
result !== undefined &&
|
|
373
375
|
isDeepStrictEqual(replacement.replacementArguments, contextGcApplyPatchInputReplacement(source.payload.arguments, result)));
|
|
374
376
|
}
|
|
375
|
-
if (replacement.kind === 'TOOL_CALL_INPUT' &&
|
|
376
|
-
|
|
377
|
-
const original =
|
|
377
|
+
if (replacement.kind === 'TOOL_CALL_INPUT' &&
|
|
378
|
+
isTodoWrite(replacement.toolName, source.payload.arguments)) {
|
|
379
|
+
const original = todoWriteForCall(records, source);
|
|
378
380
|
const successorRecord = recordsBySequence.get(replacement.evidenceSequence);
|
|
379
|
-
const successor = successorRecord && completedTodoWrite(successorRecord);
|
|
381
|
+
const successor = successorRecord && completedTodoWrite(successorRecord, records);
|
|
380
382
|
const args = source.payload.arguments;
|
|
381
383
|
return (original !== undefined &&
|
|
382
384
|
successor !== undefined &&
|
|
385
|
+
successorRecord.sequence > original.record.sequence &&
|
|
383
386
|
successor.revision > original.revision &&
|
|
384
387
|
isRecord(args) &&
|
|
385
388
|
Array.isArray(args.items) &&
|
|
@@ -481,16 +484,19 @@ function replacementMatchesRecords(replacement, records, recordsBySequence, work
|
|
|
481
484
|
!applied.retainedToolNames.includes(name)));
|
|
482
485
|
})) && successors.some((item) => item.sequence === replacement.evidenceSequence));
|
|
483
486
|
}
|
|
484
|
-
if (replacement.toolName === 'todo_read') {
|
|
485
|
-
const original = successfulToolEvidence(records, recordsBySequence, source.sequence,
|
|
487
|
+
if (replacement.toolName === 'todo_read' || replacement.toolName === 'todo') {
|
|
488
|
+
const original = successfulToolEvidence(records, recordsBySequence, source.sequence, replacement.toolName, replacement.callId);
|
|
486
489
|
const successorRecord = recordsBySequence.get(replacement.evidenceSequence);
|
|
487
|
-
const successor = successorRecord && completedTodoWrite(successorRecord);
|
|
490
|
+
const successor = successorRecord && completedTodoWrite(successorRecord, records);
|
|
488
491
|
const snapshot = typeof source.payload.content === 'string'
|
|
489
492
|
? visibleTodoSnapshot(source.payload.content)
|
|
490
493
|
: undefined;
|
|
491
494
|
return (original !== undefined &&
|
|
495
|
+
isRecord(original.call.payload) &&
|
|
496
|
+
isTodoRead(replacement.toolName, original.call.payload.arguments) &&
|
|
492
497
|
snapshot !== undefined &&
|
|
493
498
|
successor !== undefined &&
|
|
499
|
+
successorRecord.sequence > original.completed.sequence &&
|
|
494
500
|
successor.revision > snapshot.revision &&
|
|
495
501
|
replacement.replacementContent ===
|
|
496
502
|
todoSnapshotReplacement(snapshot.revision, snapshot.count, successor.revision));
|
|
@@ -958,7 +964,8 @@ function isContextGcReplacement(value) {
|
|
|
958
964
|
value.toolName === 'exec' ||
|
|
959
965
|
value.toolName === 'exec_wait' ||
|
|
960
966
|
value.toolName === 'code_exec' ||
|
|
961
|
-
value.toolName === 'todo_write'
|
|
967
|
+
value.toolName === 'todo_write' ||
|
|
968
|
+
value.toolName === 'todo') &&
|
|
962
969
|
value.target.toolName === value.toolName &&
|
|
963
970
|
Array.isArray(value.providerAliasTargets) &&
|
|
964
971
|
value.providerAliasTargets.every((target) => isContextGcTarget(target) &&
|
|
@@ -1028,6 +1035,7 @@ function isContextGcReplacement(value) {
|
|
|
1028
1035
|
isNonemptyString(value.toolName) &&
|
|
1029
1036
|
(value.toolName === 'skill' ||
|
|
1030
1037
|
value.toolName === 'todo_read' ||
|
|
1038
|
+
value.toolName === 'todo' ||
|
|
1031
1039
|
value.toolName === 'tool_search' ||
|
|
1032
1040
|
isGenericContextGcTool(value.toolName)) &&
|
|
1033
1041
|
(value.target.toolName === undefined || value.target.toolName === value.toolName) &&
|
|
@@ -50,7 +50,7 @@ export type ContextGcReplacement = {
|
|
|
50
50
|
readonly evidenceSequences: readonly number[];
|
|
51
51
|
} | {
|
|
52
52
|
readonly kind: 'TOOL_CALL_INPUT';
|
|
53
|
-
readonly toolName: 'apply_patch' | 'exec' | 'exec_wait' | 'code_exec' | 'todo_write';
|
|
53
|
+
readonly toolName: 'apply_patch' | 'exec' | 'exec_wait' | 'code_exec' | 'todo_write' | 'todo';
|
|
54
54
|
readonly callId: string;
|
|
55
55
|
readonly target: ContextGcTarget;
|
|
56
56
|
readonly replacementArguments: unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { completedTodoWrite, todoInputReplacement } from './context-gc-todo.js';
|
|
1
|
+
import { completedTodoWrite, isTodoWrite, todoInputReplacement, todoWriteForCall } from './context-gc-todo.js';
|
|
2
2
|
import { terminalExecLifecycles } from './context-gc-exec-lifecycle.js';
|
|
3
3
|
import { contextGcPatchResultFromCompletedPayload, contextGcPatchResultFromFailedPayload, contextGcExecInputReplacement, normalizeContextGcExecResult } from './context-gc-replacements.js';
|
|
4
4
|
import { parseCodeCalls, parseObservations } from './code-observation-projection.js';
|
|
@@ -235,19 +235,19 @@ export function retainedCodeInputs(records, parentCallId, todoEvidenceMature, ex
|
|
|
235
235
|
if (!execOptions?.selected || execOptions.selected(call.callId, call.toolName, summary))
|
|
236
236
|
return [{ callId: call.callId, toolName: call.toolName, input: summary }];
|
|
237
237
|
}
|
|
238
|
-
if (call.toolName
|
|
238
|
+
if (isTodoWrite(call.toolName, actualInput) &&
|
|
239
239
|
todoEvidenceMature &&
|
|
240
240
|
isRecord(actualInput) &&
|
|
241
241
|
Array.isArray(actualInput.items)) {
|
|
242
|
-
const
|
|
243
|
-
const original = originalRecord && completedTodoWrite(originalRecord);
|
|
242
|
+
const original = todoWriteForCall(records, record);
|
|
244
243
|
const successor = original &&
|
|
245
244
|
records
|
|
246
245
|
.flatMap((item) => {
|
|
247
|
-
const fact = completedTodoWrite(item);
|
|
246
|
+
const fact = completedTodoWrite(item, records);
|
|
248
247
|
return fact &&
|
|
248
|
+
item.sequence > original.record.sequence &&
|
|
249
249
|
fact.revision > original.revision &&
|
|
250
|
-
todoEvidenceMature(
|
|
250
|
+
todoEvidenceMature(original.record, item)
|
|
251
251
|
? [{ record: item, ...fact }]
|
|
252
252
|
: [];
|
|
253
253
|
})
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { SessionRecord } from './record-contract.js';
|
|
2
2
|
export declare function todoRevision(value: unknown): number | undefined;
|
|
3
3
|
/** A successful write is a domain fact even if its output was not observed. */
|
|
4
|
-
export declare function completedTodoWrite(record: SessionRecord): {
|
|
4
|
+
export declare function completedTodoWrite(record: SessionRecord, records?: readonly SessionRecord[]): {
|
|
5
5
|
callId: string;
|
|
6
6
|
revision: number;
|
|
7
7
|
} | undefined;
|
|
8
|
+
/** Bind a write fact to this invocation, never an earlier occurrence of its call ID. */
|
|
9
|
+
export declare function todoWriteForCall(records: readonly SessionRecord[], call: SessionRecord): {
|
|
10
|
+
callId: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
record: SessionRecord;
|
|
13
|
+
} | undefined;
|
|
14
|
+
export declare function isTodoWrite(toolName: unknown, input: unknown): boolean;
|
|
15
|
+
export declare function isTodoRead(toolName: unknown, input: unknown): boolean;
|
|
8
16
|
export declare function visibleTodoSnapshot(content: string): {
|
|
9
17
|
revision: number;
|
|
10
18
|
count: number;
|
|
@@ -7,16 +7,56 @@ export function todoRevision(value) {
|
|
|
7
7
|
: undefined;
|
|
8
8
|
}
|
|
9
9
|
/** A successful write is a domain fact even if its output was not observed. */
|
|
10
|
-
export function completedTodoWrite(record) {
|
|
10
|
+
export function completedTodoWrite(record, records = []) {
|
|
11
11
|
if (record.type !== 'tool.completed' ||
|
|
12
12
|
!object(record.payload) ||
|
|
13
13
|
record.payload.type !== 'tool.completed' ||
|
|
14
|
-
record.payload.toolName
|
|
14
|
+
!['todo_write', 'todo'].includes(String(record.payload.toolName)) ||
|
|
15
15
|
typeof record.payload.callId !== 'string')
|
|
16
16
|
return undefined;
|
|
17
|
+
if (record.payload.toolName === 'todo') {
|
|
18
|
+
const callId = record.payload.callId;
|
|
19
|
+
const parentCallId = record.payload.parentCallId;
|
|
20
|
+
const started = records.findLast((item) => item.sequence < record.sequence &&
|
|
21
|
+
item.executionId === record.executionId &&
|
|
22
|
+
item.type === 'tool.started' &&
|
|
23
|
+
object(item.payload) &&
|
|
24
|
+
item.payload.callId === callId &&
|
|
25
|
+
item.payload.parentCallId === parentCallId &&
|
|
26
|
+
item.payload.toolName === 'todo');
|
|
27
|
+
if (!started || !object(started.payload) || !isTodoWrite('todo', started.payload.input))
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
17
30
|
const revision = todoRevision(record.payload.data);
|
|
18
31
|
return revision === undefined ? undefined : { callId: record.payload.callId, revision };
|
|
19
32
|
}
|
|
33
|
+
/** Bind a write fact to this invocation, never an earlier occurrence of its call ID. */
|
|
34
|
+
export function todoWriteForCall(records, call) {
|
|
35
|
+
if (!object(call.payload) || typeof call.payload.callId !== 'string')
|
|
36
|
+
return undefined;
|
|
37
|
+
const { callId, parentCallId } = call.payload;
|
|
38
|
+
const toolName = call.type === 'tool.started' ? call.payload.toolName : call.payload.name;
|
|
39
|
+
const input = call.type === 'tool.started' ? call.payload.input : call.payload.arguments;
|
|
40
|
+
if (!isTodoWrite(toolName, input))
|
|
41
|
+
return undefined;
|
|
42
|
+
const terminal = records.find((record) => record.sequence > call.sequence &&
|
|
43
|
+
record.executionId === call.executionId &&
|
|
44
|
+
(record.type === 'tool.completed' || record.type === 'tool.failed') &&
|
|
45
|
+
object(record.payload) &&
|
|
46
|
+
record.payload.callId === callId &&
|
|
47
|
+
record.payload.parentCallId === parentCallId &&
|
|
48
|
+
record.payload.toolName === toolName);
|
|
49
|
+
if (!terminal)
|
|
50
|
+
return undefined;
|
|
51
|
+
const fact = completedTodoWrite(terminal, records);
|
|
52
|
+
return fact ? { record: terminal, ...fact } : undefined;
|
|
53
|
+
}
|
|
54
|
+
export function isTodoWrite(toolName, input) {
|
|
55
|
+
return (toolName === 'todo_write' || (toolName === 'todo' && object(input) && input.action === 'write'));
|
|
56
|
+
}
|
|
57
|
+
export function isTodoRead(toolName, input) {
|
|
58
|
+
return (toolName === 'todo_read' || (toolName === 'todo' && object(input) && input.action === 'read'));
|
|
59
|
+
}
|
|
20
60
|
export function visibleTodoSnapshot(content) {
|
|
21
61
|
try {
|
|
22
62
|
const value = JSON.parse(content);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { ClientToolDefinition } from '../contracts.js';
|
|
2
2
|
import type { ToolRuntimeContext } from '../runtime-context.js';
|
|
3
|
-
/**
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
export declare function executeTodoRead(context: ToolRuntimeContext): Promise<{
|
|
3
|
+
/** Owns the model-facing Todo contract; Session state and restoration belong to TodoStore. */
|
|
4
|
+
export declare const todoToolDefinition: ClientToolDefinition;
|
|
5
|
+
export declare function executeTodo(arguments_: unknown, context: ToolRuntimeContext): Promise<{
|
|
7
6
|
content: string;
|
|
8
7
|
data: {
|
|
9
8
|
revision: number;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AgentError } from '../../error.js';
|
|
2
|
+
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
3
|
+
/** Owns the model-facing Todo contract; Session state and restoration belong to TodoStore. */
|
|
4
|
+
export const todoToolDefinition = {
|
|
5
|
+
name: 'todo',
|
|
6
|
+
allowedCallers: ['direct', 'programmatic'],
|
|
7
|
+
parallelSafety: 'safe',
|
|
8
|
+
description: 'Read or replace this session’s Todo list. action=read returns revision and all items; omit items. action=write requires the complete items array (empty clears it), replaces the entire list, and returns revision/count; no prior read or revision precondition is required. Preserve stable IDs and statuses when continuing the same objective; replace old items for a materially different objective. Do not retain completed items from an earlier objective. Use only for coordination-heavy work, not straightforward bounded tasks. Keep at most one in_progress item and update only after meaningful stage changes. When an independent substantive tool call is ready, include it in the same response instead of spending a response only on Todo bookkeeping.',
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
action: { type: 'string', enum: ['read', 'write'] },
|
|
13
|
+
items: {
|
|
14
|
+
type: 'array',
|
|
15
|
+
description: 'Required for write; omit for read. The complete replacement list.',
|
|
16
|
+
maxItems: TOOL_EXECUTION_LIMITS.todoMaxItems,
|
|
17
|
+
items: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
id: { type: 'string', minLength: 1, maxLength: 128 },
|
|
21
|
+
step: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
minLength: 1,
|
|
24
|
+
maxLength: TOOL_EXECUTION_LIMITS.todoMaxTextCharacters
|
|
25
|
+
},
|
|
26
|
+
status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] }
|
|
27
|
+
},
|
|
28
|
+
required: ['id', 'step', 'status'],
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
required: ['action'],
|
|
34
|
+
additionalProperties: false
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export async function executeTodo(arguments_, context) {
|
|
38
|
+
const input = parseTodoInput(arguments_);
|
|
39
|
+
if (input.action === 'read') {
|
|
40
|
+
const todo = context.todo.read();
|
|
41
|
+
return { content: JSON.stringify(todo), data: todo };
|
|
42
|
+
}
|
|
43
|
+
const todo = context.todo.write(input);
|
|
44
|
+
await context.emit({ type: 'todo.updated', revision: todo.revision, items: todo.items });
|
|
45
|
+
return {
|
|
46
|
+
content: JSON.stringify({ revision: todo.revision, count: todo.items.length }),
|
|
47
|
+
data: todo
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function parseTodoInput(value) {
|
|
51
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
52
|
+
return invalid();
|
|
53
|
+
const input = value;
|
|
54
|
+
if (Object.keys(input).some((key) => !['action', 'items'].includes(key)))
|
|
55
|
+
return invalid();
|
|
56
|
+
if (input.action === 'read') {
|
|
57
|
+
if (input.items != null)
|
|
58
|
+
return invalid();
|
|
59
|
+
return { action: 'read' };
|
|
60
|
+
}
|
|
61
|
+
if (input.action !== 'write' ||
|
|
62
|
+
!Array.isArray(input.items) ||
|
|
63
|
+
input.items.length > TOOL_EXECUTION_LIMITS.todoMaxItems)
|
|
64
|
+
return invalid();
|
|
65
|
+
const items = input.items.map((item) => {
|
|
66
|
+
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
67
|
+
return invalid();
|
|
68
|
+
const record = item;
|
|
69
|
+
if (Object.keys(record).some((key) => !['id', 'step', 'status'].includes(key)) ||
|
|
70
|
+
typeof record.id !== 'string' ||
|
|
71
|
+
record.id.trim().length === 0 ||
|
|
72
|
+
record.id.length > 128 ||
|
|
73
|
+
typeof record.step !== 'string' ||
|
|
74
|
+
record.step.trim().length === 0 ||
|
|
75
|
+
record.step.length > TOOL_EXECUTION_LIMITS.todoMaxTextCharacters ||
|
|
76
|
+
!['pending', 'in_progress', 'completed'].includes(String(record.status)))
|
|
77
|
+
return invalid();
|
|
78
|
+
return { id: record.id, step: record.step, status: record.status };
|
|
79
|
+
});
|
|
80
|
+
return { action: 'write', items };
|
|
81
|
+
}
|
|
82
|
+
function invalid() {
|
|
83
|
+
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Todo input is invalid.');
|
|
84
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TodoItem, type TodoSnapshot } from '../../session/todo.js';
|
|
2
2
|
export type { TodoItem, TodoSnapshot } from '../../session/todo.js';
|
|
3
|
-
/**
|
|
3
|
+
/** Owns the Session Todo snapshot and revision across Executions and restored history. */
|
|
4
4
|
export declare class TodoStore {
|
|
5
5
|
#private;
|
|
6
6
|
static restore(snapshot: TodoSnapshot): TodoStore;
|
package/dist/tools/agent/todo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentError } from '../../error.js';
|
|
2
2
|
import { normalizeTodoItems, todoItemsFromSnapshot } from '../../session/todo.js';
|
|
3
|
-
/**
|
|
3
|
+
/** Owns the Session Todo snapshot and revision across Executions and restored history. */
|
|
4
4
|
export class TodoStore {
|
|
5
5
|
#revision = 0;
|
|
6
6
|
#items = [];
|
|
@@ -366,6 +366,7 @@ export class CodeModeTool {
|
|
|
366
366
|
'exec',
|
|
367
367
|
'exec_wait',
|
|
368
368
|
'apply_patch',
|
|
369
|
+
'todo',
|
|
369
370
|
'todo_read',
|
|
370
371
|
'todo_write',
|
|
371
372
|
'agent_start',
|
|
@@ -507,6 +508,7 @@ export class CodeModeTool {
|
|
|
507
508
|
truncated: output.truncated === true,
|
|
508
509
|
data: [
|
|
509
510
|
'apply_patch',
|
|
511
|
+
'todo',
|
|
510
512
|
'todo_read',
|
|
511
513
|
'todo_write',
|
|
512
514
|
'agent_start',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ApplyPatchResult, ApplyPatchPartialResult, CodeCellEventData, ExecResult, AgentToolArtifact, ToolExecutionResult, ReadEventData, ViewImageResult } from './contracts.js';
|
|
2
2
|
import type { ToolRuntimeImage } from './runtime-context.js';
|
|
3
3
|
import type { SleepResult } from './agent/sleep.js';
|
|
4
|
+
import { type TodoSnapshot } from '../session/todo.js';
|
|
4
5
|
import { type PublicToolMetadata } from '../runtime/public-tool-metadata.js';
|
|
5
6
|
import type { ModelImage } from '../model/image.js';
|
|
6
7
|
/** Copy an explicitly public JSON object without exposing the full tool result. */
|
|
@@ -20,7 +21,7 @@ export declare function publicOutputTruncation(toolName: string, data: unknown):
|
|
|
20
21
|
export declare function publicEventOutputData<T>(data: T): T;
|
|
21
22
|
export declare function liveOutputTruncation(output: import('./contracts.js').ExecOutputSnapshot): 'HEAD' | 'SOURCE' | undefined;
|
|
22
23
|
/** Project only known, validated tool result shapes into public structured events. */
|
|
23
|
-
export declare function structuredToolEventData(toolName: string, value: unknown): CodeCellEventData | ExecResult | ApplyPatchResult | ReadEventData | ViewImageResult | SleepResult | PublicToolMetadata | undefined;
|
|
24
|
+
export declare function structuredToolEventData(toolName: string, value: unknown): CodeCellEventData | ExecResult | ApplyPatchResult | ReadEventData | ViewImageResult | SleepResult | TodoSnapshot | PublicToolMetadata | undefined;
|
|
24
25
|
/** Partial patch facts are allowlisted; arbitrary error details never become public event data. */
|
|
25
26
|
export declare function structuredToolFailureData(toolName: string, error: unknown): ApplyPatchPartialResult | undefined;
|
|
26
27
|
export declare function structuredToolArtifacts(value: readonly AgentToolArtifact[] | undefined): readonly AgentToolArtifact[] | undefined;
|
|
@@ -3,6 +3,7 @@ import { parseApplyPatchResult, parseApplyPatchPartialResult } from './shared/pa
|
|
|
3
3
|
import { AGENT_EXECUTION_POLICY } from '../runtime/execution-policy.js';
|
|
4
4
|
import { countModelTokens, countTextLines, truncateModelText } from '../runtime/token-budget.js';
|
|
5
5
|
import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
|
|
6
|
+
import { todoItemsFromSnapshot } from '../session/todo.js';
|
|
6
7
|
import { publicToolMetadata } from '../runtime/public-tool-metadata.js';
|
|
7
8
|
/** Copy an explicitly public JSON object without exposing the full tool result. */
|
|
8
9
|
export function publicExtensionToolEventData(value) {
|
|
@@ -212,6 +213,15 @@ export function liveOutputTruncation(output) {
|
|
|
212
213
|
export function structuredToolEventData(toolName, value) {
|
|
213
214
|
if (!isRecord(value))
|
|
214
215
|
return undefined;
|
|
216
|
+
if (toolName === 'todo') {
|
|
217
|
+
const items = todoItemsFromSnapshot(value);
|
|
218
|
+
return Number.isSafeInteger(value.revision) && value.revision >= 0 && items
|
|
219
|
+
? {
|
|
220
|
+
revision: value.revision,
|
|
221
|
+
items: items.map(({ id, step, status }) => ({ id, step, status }))
|
|
222
|
+
}
|
|
223
|
+
: undefined;
|
|
224
|
+
}
|
|
215
225
|
const metadata = publicToolMetadata(toolName, value);
|
|
216
226
|
if (metadata !== undefined)
|
|
217
227
|
return metadata;
|
|
@@ -282,7 +292,7 @@ export function structuredToolEventData(toolName, value) {
|
|
|
282
292
|
...(Array.isArray(value.calls)
|
|
283
293
|
? {
|
|
284
294
|
calls: value.calls.filter((entry) => isRecord(entry) &&
|
|
285
|
-
['apply_patch', 'todo_read', 'todo_write'].includes(String(entry.toolName)))
|
|
295
|
+
['apply_patch', 'todo', 'todo_read', 'todo_write'].includes(String(entry.toolName)))
|
|
286
296
|
}
|
|
287
297
|
: {}),
|
|
288
298
|
...(Array.isArray(value.observations)
|
|
@@ -290,7 +300,7 @@ export function structuredToolEventData(toolName, value) {
|
|
|
290
300
|
observations: value.observations.filter((entry) => isRecord(entry) &&
|
|
291
301
|
entry.type === 'tool_result' &&
|
|
292
302
|
isRecord(entry.source) &&
|
|
293
|
-
['apply_patch', 'todo_read', 'todo_write'].includes(String(entry.source.toolName)))
|
|
303
|
+
['apply_patch', 'todo', 'todo_read', 'todo_write'].includes(String(entry.source.toolName)))
|
|
294
304
|
}
|
|
295
305
|
: {})
|
|
296
306
|
});
|
package/dist/tools/registry.js
CHANGED
|
@@ -4,9 +4,7 @@ import { execToolDefinition, execWaitToolDefinition } from './local/exec.js';
|
|
|
4
4
|
import { executeQuestion, questionToolDefinition } from './agent/question.js';
|
|
5
5
|
import { readToolDefinition } from './local/read.js';
|
|
6
6
|
import { executeSkill, skillToolDefinition } from './agent/skill.js';
|
|
7
|
-
|
|
8
|
-
// import { executeTodoRead, todoReadToolDefinition } from './agent/todo-read.js';
|
|
9
|
-
// import { executeTodoWrite, todoWriteToolDefinition } from './agent/todo-write.js';
|
|
7
|
+
import { executeTodo, todoToolDefinition } from './agent/todo-tool.js';
|
|
10
8
|
import { executeToolSearch, toolSearchToolDefinition } from './mcp/tool-search.js';
|
|
11
9
|
import { viewImageToolDefinition } from './local/view-image.js';
|
|
12
10
|
import { smartCompactToolDefinition, executeSmartCompact } from './agent/smart-compact.js';
|
|
@@ -22,8 +20,7 @@ export const BUILTIN_TOOL_DEFINITIONS = [
|
|
|
22
20
|
codeExecWaitToolDefinition,
|
|
23
21
|
applyPatchToolDefinition,
|
|
24
22
|
questionToolDefinition,
|
|
25
|
-
|
|
26
|
-
// todoWriteToolDefinition,
|
|
23
|
+
todoToolDefinition,
|
|
27
24
|
smartCompactToolDefinition,
|
|
28
25
|
sleepToolDefinition
|
|
29
26
|
];
|
|
@@ -32,7 +29,6 @@ export const AGENT_TOOL_HANDLERS = new Map([
|
|
|
32
29
|
['sleep', executeSleep],
|
|
33
30
|
['smart_compact', executeSmartCompact],
|
|
34
31
|
['tool_search', executeToolSearch],
|
|
35
|
-
|
|
36
|
-
// ['todo_write', executeTodoWrite],
|
|
32
|
+
['todo', executeTodo],
|
|
37
33
|
['question', executeQuestion]
|
|
38
34
|
]);
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** @deprecated Unregistered legacy Todo tool; retained until Todo compatibility is removed. */
|
|
2
|
-
export const todoReadToolDefinition = {
|
|
3
|
-
name: 'todo_read',
|
|
4
|
-
allowedCallers: ['direct', 'programmatic'],
|
|
5
|
-
parallelSafety: 'safe',
|
|
6
|
-
description: 'Read this session’s current Todo revision and items when you need the existing list. A prior read is not required to write Todo. Do not read an empty or new Todo merely to decide whether straightforward bounded work needs one.',
|
|
7
|
-
inputSchema: { type: 'object', properties: {}, additionalProperties: false }
|
|
8
|
-
};
|
|
9
|
-
/** @deprecated Internal legacy handler; not registered as a callable tool. */
|
|
10
|
-
export function executeTodoRead(context) {
|
|
11
|
-
const plan = context.todo.read();
|
|
12
|
-
return Promise.resolve({ content: JSON.stringify(plan), data: plan });
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from '../contracts.js';
|
|
2
|
-
import type { ToolRuntimeContext } from '../runtime-context.js';
|
|
3
|
-
/** @deprecated Unregistered legacy Todo tool; retained until Todo compatibility is removed. */
|
|
4
|
-
export declare const todoWriteToolDefinition: ClientToolDefinition;
|
|
5
|
-
/** @deprecated Internal legacy handler; not registered as a callable tool. */
|
|
6
|
-
export declare function executeTodoWrite(arguments_: unknown, context: ToolRuntimeContext): Promise<{
|
|
7
|
-
content: string;
|
|
8
|
-
data: {
|
|
9
|
-
revision: number;
|
|
10
|
-
items: {
|
|
11
|
-
id: string;
|
|
12
|
-
step: string;
|
|
13
|
-
status: "pending" | "in_progress" | "completed";
|
|
14
|
-
}[];
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { AgentError } from '../../error.js';
|
|
2
|
-
import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
|
|
3
|
-
/** @deprecated Unregistered legacy Todo tool; retained until Todo compatibility is removed. */
|
|
4
|
-
export const todoWriteToolDefinition = {
|
|
5
|
-
name: 'todo_write',
|
|
6
|
-
allowedCallers: ['direct', 'programmatic'],
|
|
7
|
-
parallelSafety: 'safe',
|
|
8
|
-
description: 'Replace this session’s entire Todo list with the supplied items; no prior read is required. Preserve stable IDs and statuses only when extending the same objective. For a materially different objective, include only the new objective’s items. Do not retain completed items from an earlier objective; when all current items are completed, default a substantive new request to replacement unless the user explicitly asks to continue, extend, verify, or follow up. Use only after Todo has been chosen for coordination-heavy work; straightforward bounded work does not need it. Keep at most one in_progress item and update statuses after meaningful stage changes. When another substantive tool call is already ready and does not depend on the Todo result, include both in the same model response instead of spending a response only for Todo bookkeeping.',
|
|
9
|
-
inputSchema: {
|
|
10
|
-
type: 'object',
|
|
11
|
-
properties: {
|
|
12
|
-
items: {
|
|
13
|
-
type: 'array',
|
|
14
|
-
maxItems: TOOL_EXECUTION_LIMITS.todoMaxItems,
|
|
15
|
-
items: {
|
|
16
|
-
type: 'object',
|
|
17
|
-
properties: {
|
|
18
|
-
id: { type: 'string' },
|
|
19
|
-
step: { type: 'string', maxLength: TOOL_EXECUTION_LIMITS.todoMaxTextCharacters },
|
|
20
|
-
status: { enum: ['pending', 'in_progress', 'completed'] }
|
|
21
|
-
},
|
|
22
|
-
required: ['id', 'step', 'status'],
|
|
23
|
-
additionalProperties: false
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
required: ['items'],
|
|
28
|
-
additionalProperties: false
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
/** @deprecated Internal legacy handler; not registered as a callable tool. */
|
|
32
|
-
export async function executeTodoWrite(arguments_, context) {
|
|
33
|
-
const value = parseTodoWriteInput(arguments_);
|
|
34
|
-
const todo = context.todo.write(value);
|
|
35
|
-
await context.emit({ type: 'todo.updated', revision: todo.revision, items: todo.items });
|
|
36
|
-
return {
|
|
37
|
-
content: JSON.stringify({ revision: todo.revision, count: todo.items.length }),
|
|
38
|
-
data: todo
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function parseTodoWriteInput(value) {
|
|
42
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
43
|
-
return invalid();
|
|
44
|
-
const input = value;
|
|
45
|
-
if (Object.keys(input).some((key) => key !== 'items') ||
|
|
46
|
-
!Array.isArray(input.items) ||
|
|
47
|
-
input.items.length > TOOL_EXECUTION_LIMITS.todoMaxItems)
|
|
48
|
-
return invalid();
|
|
49
|
-
const items = input.items.map((item) => {
|
|
50
|
-
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
51
|
-
return invalid();
|
|
52
|
-
const record = item;
|
|
53
|
-
if (Object.keys(record).some((key) => !['id', 'step', 'status'].includes(key)) ||
|
|
54
|
-
typeof record.id !== 'string' ||
|
|
55
|
-
record.id.trim().length === 0 ||
|
|
56
|
-
record.id.length > 128 ||
|
|
57
|
-
typeof record.step !== 'string' ||
|
|
58
|
-
record.step.trim().length === 0 ||
|
|
59
|
-
record.step.length > TOOL_EXECUTION_LIMITS.todoMaxTextCharacters ||
|
|
60
|
-
!['pending', 'in_progress', 'completed'].includes(String(record.status)))
|
|
61
|
-
return invalid();
|
|
62
|
-
return { id: record.id, step: record.step, status: record.status };
|
|
63
|
-
});
|
|
64
|
-
return { items };
|
|
65
|
-
}
|
|
66
|
-
function invalid() {
|
|
67
|
-
throw new AgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Todo input is invalid.');
|
|
68
|
-
}
|