minimal-agent 0.18.9 → 0.18.11
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/package.json +1 -1
- package/src/advisor/advisorCoordinator.js +30 -6
- package/src/advisor/advisorCoordinator.ts +23 -6
- package/src/advisor/deliveryReview.js +23 -0
- package/src/advisor/deliveryReview.ts +22 -0
- package/src/advisor/presentation.js +3 -1
- package/src/advisor/presentation.ts +4 -1
- package/src/loop/README.md +44 -0
- package/src/loop/deliveryIntent.js +22 -0
- package/src/loop/deliveryIntent.ts +39 -0
- package/src/loop/messages.js +146 -0
- package/src/loop/messages.ts +166 -0
- package/src/loop/options.js +1 -0
- package/src/loop/options.ts +155 -0
- package/src/loop/progressStream.js +40 -0
- package/src/loop/progressStream.ts +44 -0
- package/src/loop/publication.js +94 -0
- package/src/loop/publication.ts +124 -0
- package/src/loop/requestPreparation.js +180 -0
- package/src/loop/requestPreparation.ts +226 -0
- package/src/loop/toolBatch.js +99 -0
- package/src/loop/toolBatch.ts +123 -0
- package/src/loop/toolExecutor.js +304 -0
- package/src/loop/toolExecutor.ts +363 -0
- package/src/loop/toolPresentation.js +135 -0
- package/src/loop/toolPresentation.ts +134 -0
- package/src/loop/toolSemantics.js +45 -0
- package/src/loop/toolSemantics.ts +51 -0
- package/src/loop.js +368 -1111
- package/src/loop.ts +480 -1378
- package/src/tools/advisor/advisor.js +5 -2
- package/src/tools/advisor/advisor.ts +6 -2
- package/src/tools/applypatch/applyPatch.js +1 -1
- package/src/tools/applypatch/applyPatch.ts +1 -1
- package/src/tools/bash/semantics.js +33 -1
- package/src/tools/bash/semantics.ts +27 -1
- package/src/tools/edit/edit.js +11 -15
- package/src/tools/edit/edit.ts +10 -15
- package/src/tools/edit/multi-edit.js +14 -4
- package/src/tools/edit/multi-edit.ts +10 -4
- package/src/tools/read/read.js +91 -47
- package/src/tools/read/read.ts +77 -46
- package/src/tools/shared/diffSummary.js +25 -3
- package/src/tools/shared/diffSummary.ts +23 -3
- package/src/tools/shared/editTransaction.js +45 -0
- package/src/tools/shared/editTransaction.ts +39 -0
- package/src/tools/shared/fileActivity.js +10 -2
- package/src/tools/shared/fileActivity.ts +11 -2
- package/src/tools/shared/fileState.js +2 -0
- package/src/tools/shared/fileState.ts +4 -0
- package/src/tools/shared/readBudget.js +12 -0
- package/src/tools/shared/readBudget.ts +12 -0
- package/src/tools/toolPromptGuides.js +2 -2
- package/src/tools/toolPromptGuides.ts +2 -2
- package/src/tools/types.js +2 -6
- package/src/tools/types.ts +2 -6
- package/src/types.ts +9 -2
|
@@ -16,6 +16,7 @@ export function recordRead(absPath, opts, state = defaultState) {
|
|
|
16
16
|
&& st.size === prev.size;
|
|
17
17
|
const sameRegionUnchanged = sameSnapshot
|
|
18
18
|
&& prev.offset === opts?.offset
|
|
19
|
+
&& prev.column === opts?.column
|
|
19
20
|
&& prev.limit === opts?.limit;
|
|
20
21
|
const reads = sameRegionUnchanged ? (prev.reads ?? 1) + 1 : 1;
|
|
21
22
|
// A bounded Read may be repeated in several adjacent calls. Keep the
|
|
@@ -64,6 +65,7 @@ export function recordRead(absPath, opts, state = defaultState) {
|
|
|
64
65
|
truncated: opts?.truncated ?? false,
|
|
65
66
|
partial,
|
|
66
67
|
offset: opts?.offset,
|
|
68
|
+
column: opts?.column,
|
|
67
69
|
limit: opts?.limit,
|
|
68
70
|
reads,
|
|
69
71
|
...(opts?.contentHash ? { contentHash: opts.contentHash } : {}),
|
|
@@ -7,6 +7,7 @@ export interface FileStateEntry {
|
|
|
7
7
|
truncated: boolean;
|
|
8
8
|
partial: boolean;
|
|
9
9
|
offset?: number;
|
|
10
|
+
column?: number;
|
|
10
11
|
limit?: number;
|
|
11
12
|
reads?: number;
|
|
12
13
|
/** SHA-256 is recorded only for a complete read. */
|
|
@@ -42,6 +43,7 @@ export function recordRead(
|
|
|
42
43
|
truncated?: boolean;
|
|
43
44
|
partial?: boolean;
|
|
44
45
|
offset?: number;
|
|
46
|
+
column?: number;
|
|
45
47
|
limit?: number;
|
|
46
48
|
contentHash?: string;
|
|
47
49
|
range?: FileReadRange;
|
|
@@ -57,6 +59,7 @@ export function recordRead(
|
|
|
57
59
|
&& st.size === prev.size;
|
|
58
60
|
const sameRegionUnchanged = sameSnapshot
|
|
59
61
|
&& prev.offset === opts?.offset
|
|
62
|
+
&& prev.column === opts?.column
|
|
60
63
|
&& prev.limit === opts?.limit;
|
|
61
64
|
const reads = sameRegionUnchanged ? (prev.reads ?? 1) + 1 : 1;
|
|
62
65
|
|
|
@@ -107,6 +110,7 @@ export function recordRead(
|
|
|
107
110
|
truncated: opts?.truncated ?? false,
|
|
108
111
|
partial,
|
|
109
112
|
offset: opts?.offset,
|
|
113
|
+
column: opts?.column,
|
|
110
114
|
limit: opts?.limit,
|
|
111
115
|
reads,
|
|
112
116
|
...(opts?.contentHash ? { contentHash: opts.contentHash } : {}),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Conservative chars/token reservation works for mixed code and CJK text.
|
|
2
|
+
* A response's parallel Read calls share this closure, not separate quotas.
|
|
3
|
+
*/
|
|
4
|
+
export function createReadBudget(remainingTokens) {
|
|
5
|
+
let available = Math.max(0, Math.floor(remainingTokens * 0.5));
|
|
6
|
+
const perRead = Math.min(1_000_000, Math.max(1000, Math.floor(available / 2)));
|
|
7
|
+
return (requested = Math.min(240_000, perRead)) => {
|
|
8
|
+
const granted = Math.min(Math.max(0, requested), perRead, available);
|
|
9
|
+
available -= granted;
|
|
10
|
+
return granted;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Conservative chars/token reservation works for mixed code and CJK text.
|
|
2
|
+
* A response's parallel Read calls share this closure, not separate quotas.
|
|
3
|
+
*/
|
|
4
|
+
export function createReadBudget(remainingTokens: number) {
|
|
5
|
+
let available = Math.max(0, Math.floor(remainingTokens * 0.5));
|
|
6
|
+
const perRead = Math.min(1_000_000, Math.max(1000, Math.floor(available / 2)));
|
|
7
|
+
return (requested = Math.min(240_000, perRead)) => {
|
|
8
|
+
const granted = Math.min(Math.max(0, requested), perRead, available);
|
|
9
|
+
available -= granted;
|
|
10
|
+
return granted;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -88,7 +88,7 @@ export const BUILTIN_TOOL_PROMPT_GUIDES = {
|
|
|
88
88
|
// 测试就是从这次真实回归里补的,锁住"压缩后仍要包含这些内容"而不是简单地
|
|
89
89
|
// 锁住某个具体的压缩产物。
|
|
90
90
|
export const CONTRACT_DESCRIPTION_OVERRIDES = {
|
|
91
|
-
Read: '读取文本、图片、Notebook 或 PDF
|
|
91
|
+
Read: '读取文本、图片、Notebook 或 PDF。offset 从 1 开始;大范围阅读可提高 limit/max_chars,实际预算由 Runtime 分配。按回执 offset/column 续读,不能跳过截断行。PDF 用 pages,一次最多 20 页。',
|
|
92
92
|
Edit: '精确替换已有文本。先 Read 最新内容,old_string 必须唯一;多处相同替换传 replace_all=true。new_string 按字面写入。',
|
|
93
93
|
Write: '创建文件或整体覆盖;新文件可直接写入。覆盖已有文件前须完整 Read(一次全量或分段覆盖全部范围)且内容未变化;仅有局部读取时使用 Edit/ApplyPatch。',
|
|
94
94
|
ApplyPatch: '提交 Codex 格式补丁,必须用 *** Begin Patch / *** End Patch 包络,不接受裸 git diff。支持 Add/Update/Delete File、Move to;路径相对工作区。先校验,写入失败尝试回滚,不保证跨文件断电原子性。',
|
|
@@ -112,7 +112,7 @@ export const CONTRACT_DESCRIPTION_OVERRIDES = {
|
|
|
112
112
|
Advisor: '向无工具权限的顾问模型请求一次结构化第二意见。默认 reviewMode=brief 只给重点短评;完整代码审查用 full,并提供范围、基线和证据。full 不扩大上下文或输出预算,材料不足时必须说明未完成。',
|
|
113
113
|
// 保留决策必填条件,与 schema 的 superRefine 一致;不能只概括成“记录决定”。
|
|
114
114
|
AdvisorDecision: '记录主 Agent 对顾问第二意见的 accept、partial 或 reject 判断;是否采纳由主 Agent 决定,登记不是执行许可。partial 同时填 acceptedPoints/rejectedPoints;reject 填 rejectedPoints,列出被拒绝点及依据;evidenceRefs 只引用真实 tool_call_id,没有引用则记录待验证。登记失败不阻止任务继续。',
|
|
115
|
-
MultiEdit: '同文件有序批量精确替换,先 Read
|
|
115
|
+
MultiEdit: '同文件有序批量精确替换,先 Read 相关范围;全部匹配成功才写盘。old_string 非空且唯一,或显式 replace_all。后续匹配前序生成文本会被拒绝,请合并 edits。操作条数不等于替换次数,diff 预览可能不完整。',
|
|
116
116
|
LSP: '查询定义、引用、类型、符号和诊断。line/character 为 1-based UTF-16;尚未收到诊断不等于没有错误,编辑前读取源码。',
|
|
117
117
|
WebFetch: '读取已知 HTTP(S) URL 的静态文本,HTML 转 Markdown;不执行 JavaScript、不继承登录态。PDF/图片用 Download 后 Read;动态页面用 WebBrowser。',
|
|
118
118
|
WebSearch: 'Tavily 搜索返回标题、URL、片段及可选综合答案,不是完整原文或浏览器。重要结论读取来源正文;按子问题查询,重试改变关键词或来源。recency 控制时效,历史范围用 start_date/end_date,none 关闭自动时效;advanced 更慢,news 偏新闻。需配置 Tavily。',
|
|
@@ -105,7 +105,7 @@ export const BUILTIN_TOOL_PROMPT_GUIDES: Readonly<Record<string, ToolPromptGuide
|
|
|
105
105
|
// 测试就是从这次真实回归里补的,锁住"压缩后仍要包含这些内容"而不是简单地
|
|
106
106
|
// 锁住某个具体的压缩产物。
|
|
107
107
|
export const CONTRACT_DESCRIPTION_OVERRIDES: Readonly<Record<string, string | (() => string)>> = {
|
|
108
|
-
Read: '读取文本、图片、Notebook 或 PDF
|
|
108
|
+
Read: '读取文本、图片、Notebook 或 PDF。offset 从 1 开始;大范围阅读可提高 limit/max_chars,实际预算由 Runtime 分配。按回执 offset/column 续读,不能跳过截断行。PDF 用 pages,一次最多 20 页。',
|
|
109
109
|
Edit: '精确替换已有文本。先 Read 最新内容,old_string 必须唯一;多处相同替换传 replace_all=true。new_string 按字面写入。',
|
|
110
110
|
Write: '创建文件或整体覆盖;新文件可直接写入。覆盖已有文件前须完整 Read(一次全量或分段覆盖全部范围)且内容未变化;仅有局部读取时使用 Edit/ApplyPatch。',
|
|
111
111
|
ApplyPatch: '提交 Codex 格式补丁,必须用 *** Begin Patch / *** End Patch 包络,不接受裸 git diff。支持 Add/Update/Delete File、Move to;路径相对工作区。先校验,写入失败尝试回滚,不保证跨文件断电原子性。',
|
|
@@ -130,7 +130,7 @@ export const CONTRACT_DESCRIPTION_OVERRIDES: Readonly<Record<string, string | ((
|
|
|
130
130
|
Advisor: '向无工具权限的顾问模型请求一次结构化第二意见。默认 reviewMode=brief 只给重点短评;完整代码审查用 full,并提供范围、基线和证据。full 不扩大上下文或输出预算,材料不足时必须说明未完成。',
|
|
131
131
|
// 保留决策必填条件,与 schema 的 superRefine 一致;不能只概括成“记录决定”。
|
|
132
132
|
AdvisorDecision: '记录主 Agent 对顾问第二意见的 accept、partial 或 reject 判断;是否采纳由主 Agent 决定,登记不是执行许可。partial 同时填 acceptedPoints/rejectedPoints;reject 填 rejectedPoints,列出被拒绝点及依据;evidenceRefs 只引用真实 tool_call_id,没有引用则记录待验证。登记失败不阻止任务继续。',
|
|
133
|
-
MultiEdit: '同文件有序批量精确替换,先 Read
|
|
133
|
+
MultiEdit: '同文件有序批量精确替换,先 Read 相关范围;全部匹配成功才写盘。old_string 非空且唯一,或显式 replace_all。后续匹配前序生成文本会被拒绝,请合并 edits。操作条数不等于替换次数,diff 预览可能不完整。',
|
|
134
134
|
LSP: '查询定义、引用、类型、符号和诊断。line/character 为 1-based UTF-16;尚未收到诊断不等于没有错误,编辑前读取源码。',
|
|
135
135
|
WebFetch: '读取已知 HTTP(S) URL 的静态文本,HTML 转 Markdown;不执行 JavaScript、不继承登录态。PDF/图片用 Download 后 Read;动态页面用 WebBrowser。',
|
|
136
136
|
WebSearch: 'Tavily 搜索返回标题、URL、片段及可选综合答案,不是完整原文或浏览器。重要结论读取来源正文;按子问题查询,重试改变关键词或来源。recency 控制时效,历史范围用 start_date/end_date,none 关闭自动时效;advanced 更慢,news 偏新闻。需配置 Tavily。',
|
package/src/tools/types.js
CHANGED
|
@@ -11,11 +11,7 @@ export const DEFAULT_MAX_RESULT_SIZE_CHARS = 30_000;
|
|
|
11
11
|
/** Read 工具默认行数上限(与 kakadeai 主仓库一致) */
|
|
12
12
|
export const MAX_LINES_TO_READ = 2000;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - system prompt + 工具定义 ≈ 30KB
|
|
17
|
-
* - 对话历史 ≈ 100KB
|
|
18
|
-
* - 单次读取安全上限 ≈ 256KB(~64K tokens)
|
|
19
|
-
* 超过此限制请用 offset/limit 分段读。
|
|
14
|
+
* Text input IO ceiling, independent of the model's returned-content budget.
|
|
15
|
+
* Read windows are bounded separately and can reserve runtime context capacity.
|
|
20
16
|
*/
|
|
21
17
|
export const MAX_FILE_SIZE_BYTES = 1024 * 1024 * 1024; // 1 GiB; returned content remains independently bounded
|
package/src/tools/types.ts
CHANGED
|
@@ -14,11 +14,7 @@ export const DEFAULT_MAX_RESULT_SIZE_CHARS = 30_000;
|
|
|
14
14
|
export const MAX_LINES_TO_READ = 2000;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - system prompt + 工具定义 ≈ 30KB
|
|
20
|
-
* - 对话历史 ≈ 100KB
|
|
21
|
-
* - 单次读取安全上限 ≈ 256KB(~64K tokens)
|
|
22
|
-
* 超过此限制请用 offset/limit 分段读。
|
|
17
|
+
* Text input IO ceiling, independent of the model's returned-content budget.
|
|
18
|
+
* Read windows are bounded separately and can reserve runtime context capacity.
|
|
23
19
|
*/
|
|
24
20
|
export const MAX_FILE_SIZE_BYTES = 1024 * 1024 * 1024; // 1 GiB; returned content remains independently bounded
|
package/src/types.ts
CHANGED
|
@@ -291,8 +291,8 @@ export interface FilePatchSummary {
|
|
|
291
291
|
unifiedDiff?: string;
|
|
292
292
|
beforeHash?: string;
|
|
293
293
|
afterHash: string;
|
|
294
|
-
additions
|
|
295
|
-
deletions
|
|
294
|
+
additions?: number;
|
|
295
|
+
deletions?: number;
|
|
296
296
|
truncated: boolean;
|
|
297
297
|
omittedReason?: 'too_large';
|
|
298
298
|
}
|
|
@@ -397,6 +397,9 @@ export interface AdvisorCheckpointMetadata extends AdvisorVersions {
|
|
|
397
397
|
|
|
398
398
|
export interface AdvisorConsultationMetadata extends AdvisorVersions {
|
|
399
399
|
kind: 'advisor_consultation';
|
|
400
|
+
/** Host-recorded trigger, distinct from who emitted the tool call. Absent in old history. */
|
|
401
|
+
triggerSource?: 'checkpoint' | 'model';
|
|
402
|
+
triggerReason?: string;
|
|
400
403
|
consultationId: string;
|
|
401
404
|
checkpoint: AdvisorCheckpoint;
|
|
402
405
|
checkpointKey: string;
|
|
@@ -570,6 +573,10 @@ export type ToolResult = { problem?: ToolProblemOutcome; observation?: ReadObser
|
|
|
570
573
|
* 避免按工具名写特判分支。
|
|
571
574
|
*/
|
|
572
575
|
export interface ToolCallContext {
|
|
576
|
+
/** Run-local host initialization shared with Advisor; never a model argument. */
|
|
577
|
+
advisorConsultation?: AdvisorConsultationMetadata;
|
|
578
|
+
/** Shared per-model-response read allowance; reservations happen before IO. */
|
|
579
|
+
reserveReadChars?: (requested?: number) => number;
|
|
573
580
|
/** Host presentation only; cannot grant tools to a delegated agent. */
|
|
574
581
|
output?: import('./runtime/outputContract.js').OutputContract;
|
|
575
582
|
/** Live effective catalog, including per-turn restrictions. */
|