@myagentroam/agent 0.9.75 → 0.9.77

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/cli/main.js CHANGED
@@ -19,7 +19,7 @@ Usage:
19
19
  maragent run <prompt> [--reasoning-effort EFFORT] [--format text|json|stream-json] [--codex-auth-file PATH]
20
20
  maragent resume [sessionId] [--reasoning-effort EFFORT] [--codex-auth-file PATH]
21
21
  maragent sessions list|delete <sessionId>
22
- maragent models list|add|edit|remove|test [id] [--default-reasoning-effort EFFORT] [--code-mode|--no-code-mode] [--responses-encoding standard|lite] [--codex-auth-file PATH]
22
+ maragent models list|add|edit|remove|test [id] [--default-reasoning-effort EFFORT] [--code-mode|--no-code-mode] [--high-density-compaction|--no-high-density-compaction] [--responses-encoding standard|lite] [--codex-auth-file PATH]
23
23
  `;
24
24
  function takeOption(arguments_, name) {
25
25
  const index = arguments_.indexOf(name);
@@ -181,6 +181,7 @@ async function modelsCommand(home, arguments_, codexAuthFile) {
181
181
  : parseReasoningEffort(defaultReasoningEffortOption, '--default-reasoning-effort'),
182
182
  titleGeneration: existing?.titleGeneration ?? false,
183
183
  codeMode: booleanFlag(arguments_, '--code-mode', '--no-code-mode', existing?.codeMode ?? false),
184
+ highDensityCompaction: booleanFlag(arguments_, '--high-density-compaction', '--no-high-density-compaction', existing?.highDensityCompaction ?? false),
184
185
  hostedWebSearch: booleanFlag(arguments_, '--web-search', '--no-web-search', existing?.hostedWebSearch ?? false),
185
186
  ...(responsesTransport === undefined ? {} : { responsesTransport }),
186
187
  ...(responsesEncoding === undefined ? {} : { responsesEncoding }),
@@ -27,6 +27,7 @@ export declare function serializeModel(model: CliModelConfiguration): {
27
27
  defaultReasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
28
28
  titleGeneration: boolean;
29
29
  codeMode: boolean;
30
+ highDensityCompaction: boolean;
30
31
  hostedWebSearch: boolean;
31
32
  responsesEncoding?: "STANDARD" | "LITE" | undefined;
32
33
  enabled: boolean;
@@ -50,6 +51,7 @@ export declare function serializeModel(model: CliModelConfiguration): {
50
51
  defaultReasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
51
52
  titleGeneration: boolean;
52
53
  codeMode: boolean;
54
+ highDensityCompaction: boolean;
53
55
  hostedWebSearch: boolean;
54
56
  responsesEncoding?: "STANDARD" | "LITE" | undefined;
55
57
  enabled: boolean;
@@ -78,6 +78,7 @@ declare const rawModelSchema: z.ZodObject<{
78
78
  }>>;
79
79
  titleGeneration: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
80
80
  codeMode: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
81
+ highDensityCompaction: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
81
82
  hostedWebSearch: z.ZodBoolean;
82
83
  responsesTransport: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
83
84
  transport: z.ZodLiteral<"HTTP">;
@@ -49,6 +49,7 @@ const rawModelSchema = z
49
49
  defaultReasoningEffort: marAgentReasoningEffortSchema.optional(),
50
50
  titleGeneration: z.boolean().optional().default(false),
51
51
  codeMode: z.boolean().optional().default(false),
52
+ highDensityCompaction: z.boolean().optional().default(false),
52
53
  hostedWebSearch: z.boolean(),
53
54
  responsesTransport: rawResponsesTransportSchema.optional(),
54
55
  responsesEncoding: z.enum(['STANDARD', 'LITE']).optional(),
@@ -1 +1,2 @@
1
1
  export declare function compactionPrompt(): string;
2
+ export declare function highDensityCompactionPrompt(): string;
@@ -23,3 +23,69 @@ Remove aggressively:
23
23
 
24
24
  Use compact Markdown with these headings when applicable: Objective, Instructions and constraints, Decisions and facts, Completed work, Verification and evidence, Active state, Open issues and risks, Next action. Omit empty headings. Prefer precise paths, IDs, error codes, and short evidence over narrative. Output only the handoff.`;
25
25
  }
26
+ export function highDensityCompactionPrompt() {
27
+ return `将 visible conversation 编译为供下一 Agent 直接续作的 Textual Continuation IR;原 transcript 将丢弃。This is factual state transfer, not recap, user reply, or new work. 不调用工具、不推进任务、不虚构完成。
28
+
29
+ 目标:在 handoff budget 内最大化 continuation accuracy、信息密度、可恢复性。Token reduction 仅在不损害续作后有价值;必要时约 10K tokens 可接受。
30
+
31
+ IR 不是 prose summary。默认使用最短且无歧义的事实短语、状态原子、精确引用;仅在短语无法说清因果、冲突或边界时使用完整句。优先两种形式:
32
+ <object> | <key>=<value> | <key>=<value>
33
+ <event/condition> -> <effect> | <effect>
34
+ 例如:
35
+ src/discount.js | cause=verified | edit=pending | comment=required | tests=not run
36
+ patch(src/discount.js) -> prior_read=stale | next=re-evidence
37
+ branch changed -> inherited_evidence=unverified
38
+
39
+ 语法:
40
+ - | 并列同一 object 的独立事实;= 表示 current fact/state/constraint;-> 仅表示 cause、invalidation、transition。
41
+ - key 使用最短且无歧义的 established term;value 可为状态原子或短语;enum 默认 lowercase。
42
+ - 使用 required/forbidden/pending 等语义值,不写 YES/NO。省略无续作价值的 unknown 和空字段。
43
+ - 同一 key 只保留已归约的 current value。无法消解:state=conflict | candidates=<short values> | next=re-evidence;不得任选一方。
44
+ - transition effect 优先 <object>.<key>=<value>;object 已唯一明确时可省略,不得省略到歧义。
45
+ - exact path/symbol/ID/command/number/user-designated text 原样保留。值含 |、换行或需逐字保存时,使用紧邻 record 的 Markdown code span/block,不发明 escaping protocol。
46
+ - pending、not run、unverified、failed 不得互换。
47
+
48
+ 按需覆盖五类信息职责,空块省略。双语名称仅解释职责;输出标题只选当前任务合适的一种语言,不同时复制两套。
49
+
50
+ 1. 目标契约 / Goal contract
51
+ - 主目标、当前交付、完成标准、非目标/边界。
52
+ - direct user/caller authorization、prohibition、exclusion 保留 exact action/scope,不概括成更宽泛边界。
53
+
54
+ 2. 当前状态 / Current state
55
+ - 对象:file、symbol、feature、migration、test、worktree、process、subagent、selected Skill、Todo/plan、approval、external side effect。
56
+ - 分离 completion(pending / in_progress / completed / blocked)、epistemic(observed / verified / inferred / proposed / disproved)、freshness(current / stale / superseded)、scope(turn / worktree / base / branch / external system);仅在消歧时标注。
57
+ - 明确 completed、not started、unverified、active。相同精度下选择更短状态原子;中文、English 均可,如 根因已证、edit=pending、tests=not run。
58
+ - selected Skill | 保留仍适用的 skill name + 续作必需约束;Todo/plan | 保留 revision、item/status、当前最小 step。
59
+ - verified claim 后无 source mutation/base/branch change 等 invalidating event:freshness=current | re-diagnosis=not needed。为 patch 获取当前行上下文的 targeted reread 仍可保留,不等同重新调查已证结论。
60
+
61
+ 3. 已定事项 / Settled matters
62
+ - confirmed decision/interface/constraint + 续作仍需的最短理由。
63
+ - disproved/rejected direction + scope/evidence。
64
+ - recovery path、event shape、implementation option、next action 未经 direct evidence 前保持 proposed/unverified。
65
+
66
+ 4. 必要证据 / Necessary evidence
67
+ - 仅保留不可廉价恢复、决定后续判断、记录不可重复 side effect,或精确值影响 correctness 的 evidence;紧邻 claim,绑定 scope/freshness。
68
+ - completed check/result 若决定后续判断:保留 decisive values,或可确定恢复这些值的 exact artifact path/command;不得只留 count/schema。
69
+ - path、symbol/class/function/variable、API/tool/model/provider、JSON key/enum/protocol field、command/arguments、error code、commit hash、callId、sequence、version、number、用户指定原文:原样保留,不翻译、不猜测。
70
+ - 下一 Agent 无法使用、仅供 local storage validation 的 integrity hash:删除。
71
+
72
+ 5. 未闭环 / Open loops
73
+ - unresolved、unverified、blocker、pending approval、活动 process/subagent、Todo/plan current step、仍需 evidence。
74
+ - 只保留已确定的最小 next action + preconditions;不复制可重算的长 plan。
75
+
76
+ 编译规则:
77
+ 1. latest user intent 定目标;newer correction 覆盖 older intent。
78
+ 2. 归约 before -> event -> after;source mutation 或 base/branch change 后 affected read/conclusion stale,除非已有 newer evidence;history replacement 仅使 Responses continuation invalid,不使 factual evidence 自动失效;无 invalidating event 的 verified claim 保持 current;current 取最后已证 after-state 或 later direct observation。
79
+ 3. 每个 continuation object 一条 current record;等价事实去重。
80
+ 4. 仅保留仍约束 open work 的 settled decision/exclusion。
81
+ 5. evidence 绑定 claim;verified conclusion 优先于 raw snapshot/intermediate hypothesis。
82
+ 6. 预算受压时依次保护:目标、当前进度、边界、不可重复副作用、未闭环、必要证据;再删 provenance/可恢复实现细节。
83
+
84
+ observed HEAD、validated base、target commit、current worktree 不得折叠;evidence 只更新直接证明的 axis。跨 axis/base/branch 推导无 direct evidence 时保持 unverified。状态冲突无法归约:保留 conflict + re-evidence,不替模型选择。
85
+
86
+ 语言:标题/一般叙述跟随 latest active user instructions 和当前任务主语言;每条 record 按局部精度与密度选择中文、English 或 mixed phrasing。保留 established term/exact identifier,不为语言统一展开或翻译。English codebase 不等于 English handoff。
87
+
88
+ 删除 greetings、progress chatter、过程叙事、重复事实、无剩余约束的 superseded hypothesis、长日志、source body、verbose payload、可从精确 path/command 廉价恢复的正文。删除 user/project/directory AGENTS.md 正文及仅由这些文件派生的 constraint,包括其中 exclusions;下一 Execution 会重新加载并整体替换。不得保留 hidden reasoning、secret、credential、无关内容。
89
+
90
+ 只输出 compact Markdown IR。`;
91
+ }
@@ -2,7 +2,7 @@ import type { ExecutionMode } from '../sdk/types.js';
2
2
  import { type ExecutionBudgetPromptState } from './execution-budget.js';
3
3
  import { type RetainedSessionResources } from './resources.js';
4
4
  import { type CurrentAgentModel, type SubagentModelOption } from './subagent.js';
5
- export declare const MAR_AGENT_PROMPT_VERSION = "1.43";
5
+ export declare const MAR_AGENT_PROMPT_VERSION = "1.47";
6
6
  export declare function buildSystemPrompt(input: {
7
7
  mode: ExecutionMode;
8
8
  platform: string;
@@ -18,5 +18,6 @@ export declare function buildSystemPrompt(input: {
18
18
  subagentModels?: readonly SubagentModelOption[];
19
19
  retainedSessionResources?: RetainedSessionResources;
20
20
  executionBudget?: ExecutionBudgetPromptState;
21
+ highDensityCompaction?: boolean;
21
22
  extension?: string | undefined;
22
23
  }): string;
@@ -1,4 +1,4 @@
1
- import { compactionPrompt } from './compact.js';
1
+ import { compactionPrompt, highDensityCompactionPrompt } from './compact.js';
2
2
  import { environmentPrompt, identityPrompt, instructionPriorityPrompt, workspaceDisciplinePrompt } from './core.js';
3
3
  import { executionBudgetPrompt } from './execution-budget.js';
4
4
  import { modePrompt } from './modes.js';
@@ -6,7 +6,7 @@ import { outputStylePrompt } from './output.js';
6
6
  import { retainedSessionResourcesPrompt } from './resources.js';
7
7
  import { subagentModelOptionsPrompt, subagentPrompt, currentAgentModelPrompt } from './subagent.js';
8
8
  import { interactionPrompt, longRunningPrompt, safetyPrompt, toolUsagePrompt, workflowPrompt } from './workflow.js';
9
- export const MAR_AGENT_PROMPT_VERSION = '1.43';
9
+ export const MAR_AGENT_PROMPT_VERSION = '1.47';
10
10
  export function buildSystemPrompt(input) {
11
11
  const toolNames = new Set(input.tools);
12
12
  const hasLongRunningCapability = [
@@ -36,7 +36,11 @@ export function buildSystemPrompt(input) {
36
36
  questionAvailable: toolNames.has('question'),
37
37
  forceFinalize: input.executionBudget?.stage === 'exhausted'
38
38
  }),
39
- input.mode === 'compact' ? compactionPrompt() : '',
39
+ input.mode === 'compact'
40
+ ? input.highDensityCompaction
41
+ ? highDensityCompactionPrompt()
42
+ : compactionPrompt()
43
+ : '',
40
44
  toolNames.has('agent_start') ? subagentPrompt : '',
41
45
  toolNames.has('agent_start') ? currentAgentModelPrompt(input.currentAgentModel) : '',
42
46
  toolNames.has('agent_start') ? subagentModelOptionsPrompt(input.subagentModels ?? []) : '',
@@ -1,2 +1,2 @@
1
- export declare const outputStylePrompt = "# Output and communication style\nBe direct, natural, and concise. Match detail and structure to the user's needs and the task's complexity. Lead with the result; include actual verification, material risks, and unfinished work when relevant. Avoid repeating progress, dumping logs, or adding empty sections. For a requested review, lead with actionable findings ordered by severity and file evidence; if none were found, say so and note validation gaps. Preserve exact paths, identifiers, error codes, citations, and useful line locations when they are evidence. Never expose hidden reasoning.";
1
+ export declare const outputStylePrompt = "# Output and communication style\nBe direct, natural, and concise. Default to a brief teammate update rather than a report; expand when the user requests detail or when complexity and multiple distinct findings need grouping or explanation. Lead with the result and report only details that materially support or qualify it, including actual verification, material risks, and unfinished work when relevant. Use plain sentences or a short list for simple results. Avoid unnecessary repetition, repeating progress, dumping logs, or adding empty sections. For a requested review, lead with actionable findings ordered by severity and file evidence; if none were found, say so and note validation gaps. Preserve exact paths, identifiers, error codes, citations, and useful line locations when they are evidence. Never expose hidden reasoning.";
2
2
  export declare const modelOutputContinuationMessage = "Continue the previous response from exactly where it stopped. Do not repeat completed content.";
@@ -1,2 +1,2 @@
1
- export const outputStylePrompt = "# Output and communication style\nBe direct, natural, and concise. Match detail and structure to the user's needs and the task's complexity. Lead with the result; include actual verification, material risks, and unfinished work when relevant. Avoid repeating progress, dumping logs, or adding empty sections. For a requested review, lead with actionable findings ordered by severity and file evidence; if none were found, say so and note validation gaps. Preserve exact paths, identifiers, error codes, citations, and useful line locations when they are evidence. Never expose hidden reasoning.";
1
+ export const outputStylePrompt = '# Output and communication style\nBe direct, natural, and concise. Default to a brief teammate update rather than a report; expand when the user requests detail or when complexity and multiple distinct findings need grouping or explanation. Lead with the result and report only details that materially support or qualify it, including actual verification, material risks, and unfinished work when relevant. Use plain sentences or a short list for simple results. Avoid unnecessary repetition, repeating progress, dumping logs, or adding empty sections. For a requested review, lead with actionable findings ordered by severity and file evidence; if none were found, say so and note validation gaps. Preserve exact paths, identifiers, error codes, citations, and useful line locations when they are evidence. Never expose hidden reasoning.';
2
2
  export const modelOutputContinuationMessage = 'Continue the previous response from exactly where it stopped. Do not repeat completed content.';
@@ -22,7 +22,7 @@ export declare class CompactionOperation {
22
22
  private report;
23
23
  }
24
24
  export declare const DEFAULT_COMPACTION_FOCUS = "Create a durable continuation state for the next model invocation.";
25
- export declare function buildCompactionMessages(evidence: string): ModelMessage[];
25
+ export declare function buildCompactionMessages(evidence: string, highDensityCompaction?: boolean): ModelMessage[];
26
26
  export declare function buildCompactionInput(messages: readonly ModelMessage[], input: {
27
27
  focus?: string;
28
28
  maxTokens: number;
@@ -1,6 +1,6 @@
1
1
  import { MarAgentError } from '../error.js';
2
2
  import { countModelTokens, truncateModelText } from './token-budget.js';
3
- import { compactionPrompt } from '../prompts/compact.js';
3
+ import { compactionPrompt, highDensityCompactionPrompt } from '../prompts/compact.js';
4
4
  const COMPACTION_TIMEOUT_MS = 600_000;
5
5
  const COMPACTION_PROGRESS_INTERVAL_MS = 30_000;
6
6
  /** One deadline spans all model attempts and recovery waits for a single compaction. */
@@ -91,10 +91,13 @@ export class CompactionOperation {
91
91
  }
92
92
  }
93
93
  export const DEFAULT_COMPACTION_FOCUS = 'Create a durable continuation state for the next model invocation.';
94
- export function buildCompactionMessages(evidence) {
94
+ export function buildCompactionMessages(evidence, highDensityCompaction = false) {
95
95
  return [
96
96
  { role: 'user', content: evidence },
97
- { role: 'user', content: compactionPrompt() }
97
+ {
98
+ role: 'user',
99
+ content: highDensityCompaction ? highDensityCompactionPrompt() : compactionPrompt()
100
+ }
98
101
  ];
99
102
  }
100
103
  export function buildCompactionInput(messages, input) {
package/dist/sdk/agent.js CHANGED
@@ -486,6 +486,7 @@ export async function createMarAgent(options) {
486
486
  }))
487
487
  : [],
488
488
  retainedSessionResources,
489
+ highDensityCompaction: selectedModel.highDensityCompaction,
489
490
  ...(rolloutBudget?.active
490
491
  ? {
491
492
  executionBudget: {
@@ -504,14 +505,14 @@ export async function createMarAgent(options) {
504
505
  });
505
506
  const initialSystemPrompt = buildExecutionSystemPrompt();
506
507
  if (mode === 'compact') {
507
- const compactOverheadTokens = estimatedRequestTokens(initialSystemPrompt, buildCompactionMessages(''), []);
508
+ const compactOverheadTokens = estimatedRequestTokens(initialSystemPrompt, buildCompactionMessages('', selectedModel.highDensityCompaction), []);
508
509
  const compactInputTokens = selectedModel.contextWindowTokens - compactOverheadTokens;
509
510
  if (compactInputTokens <= 0)
510
511
  throw new MarAgentError('MAR_AGENT_CONTEXT_LIMIT', 'Compaction prompt exceeds the selected model context window.');
511
512
  messages.splice(0, messages.length, ...buildCompactionMessages(buildCompactionInput(messages, {
512
513
  focus: input.prompt,
513
514
  maxTokens: compactInputTokens
514
- })));
515
+ }), selectedModel.highDensityCompaction));
515
516
  }
516
517
  await store.append(sessionId, {
517
518
  type: 'execution.header',
@@ -539,9 +540,10 @@ export async function createMarAgent(options) {
539
540
  platform: description.platform,
540
541
  workspace: logicalWorkspace,
541
542
  tools: [],
543
+ highDensityCompaction: selectedModel.highDensityCompaction,
542
544
  extension: options.systemInstruction
543
545
  });
544
- const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages(''), []);
546
+ const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages('', selectedModel.highDensityCompaction), []);
545
547
  const compactInputTokens = Math.max(0, selectedModel.contextWindowTokens - compactOverheadTokens);
546
548
  if (compactInputTokens === 0)
547
549
  throw new MarAgentError('MAR_AGENT_CONTEXT_LIMIT', 'Compaction prompt exceeds the selected model context window.');
@@ -561,7 +563,7 @@ export async function createMarAgent(options) {
561
563
  for await (const event of operation.start(selected, {
562
564
  retryState: compactionRetryState,
563
565
  system: compactSystemPrompt,
564
- messages: buildCompactionMessages(compactSource),
566
+ messages: buildCompactionMessages(compactSource, selectedModel.highDensityCompaction),
565
567
  tools: [],
566
568
  allowTools: false,
567
569
  promptCacheKey: sessionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.9.75",
3
+ "version": "0.9.77",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -38,6 +38,7 @@
38
38
  "build": "node ../scripts/clean-build-output.mjs dist && tsc -p tsconfig.json",
39
39
  "typecheck": "tsc -p tsconfig.json --noEmit",
40
40
  "test:unit": "vitest run --config vitest.config.ts test/unit",
41
+ "benchmark:compaction": "node test/e2e/compaction-benchmark.mjs",
41
42
  "test:performance": "vitest run --config vitest.performance.config.ts",
42
43
  "test:memory": "node --expose-gc ./node_modules/vitest/vitest.mjs run --config vitest.memory.config.ts",
43
44
  "test:e2e": "vitest run --config vitest.config.ts test/e2e --no-file-parallelism",