@ai-agent-forge/agent-forge 0.87.0 → 0.88.0

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.
Files changed (137) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +2 -2
  3. package/dist/bundle/.build-manifest.json +65 -87
  4. package/dist/bundle/chunks/{chunk-BFC2BDVJ.js → chunk-HLJEVRWP.js} +2 -2
  5. package/dist/bundle/chunks/{chunk-MOHOLL3F.js → chunk-YGHQME4V.js} +72 -72
  6. package/dist/bundle/chunks/image-resize-worker.js +2 -2
  7. package/dist/bundle/cli.js +1 -1
  8. package/dist/bundle/client.js +1 -1
  9. package/dist/bundle/index.js +1 -1
  10. package/dist/bundle/rpc-entry.js +1 -1
  11. package/dist/cli/auth-check.d.ts.map +1 -1
  12. package/dist/cli/auth-check.js +14 -2
  13. package/dist/cli/auth-check.js.map +1 -1
  14. package/dist/cli/auth-command.d.ts.map +1 -1
  15. package/dist/cli/auth-command.js +1 -1
  16. package/dist/cli/auth-command.js.map +1 -1
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +3 -2
  19. package/dist/config.js.map +1 -1
  20. package/dist/core/agent-session-compaction.d.ts +6 -10
  21. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  22. package/dist/core/agent-session-compaction.js +7 -111
  23. package/dist/core/agent-session-compaction.js.map +1 -1
  24. package/dist/core/agent-session-internal.d.ts +0 -6
  25. package/dist/core/agent-session-internal.d.ts.map +1 -1
  26. package/dist/core/agent-session-internal.js.map +1 -1
  27. package/dist/core/agent-session-retry.d.ts.map +1 -1
  28. package/dist/core/agent-session-retry.js +0 -1
  29. package/dist/core/agent-session-retry.js.map +1 -1
  30. package/dist/core/agent-session.d.ts +0 -20
  31. package/dist/core/agent-session.d.ts.map +1 -1
  32. package/dist/core/agent-session.js +5 -33
  33. package/dist/core/agent-session.js.map +1 -1
  34. package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +1 -1
  35. package/dist/core/extensions/bootstrap-compaction-policy.js +0 -34
  36. package/dist/core/extensions/bootstrap-compaction-policy.js.map +1 -1
  37. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +1 -1
  38. package/dist/core/extensions/bootstrap-retry-policy.js +2 -2
  39. package/dist/core/extensions/bootstrap-retry-policy.js.map +1 -1
  40. package/dist/core/extensions/provider-failover.d.ts +7 -3
  41. package/dist/core/extensions/provider-failover.d.ts.map +1 -1
  42. package/dist/core/extensions/provider-failover.js +9 -8
  43. package/dist/core/extensions/provider-failover.js.map +1 -1
  44. package/dist/core/facade/coding-agent-facade.d.ts +0 -6
  45. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  46. package/dist/core/facade/coding-agent-facade.js +0 -3
  47. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  48. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
  49. package/dist/core/i18n/locales/zh-cn/cli.js +3 -1
  50. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
  51. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
  52. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +2 -0
  53. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
  54. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -1
  55. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +0 -2
  56. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -1
  57. package/dist/core/model-config.d.ts +0 -1
  58. package/dist/core/model-config.d.ts.map +1 -1
  59. package/dist/core/model-config.js +9 -1
  60. package/dist/core/model-config.js.map +1 -1
  61. package/dist/core/model-runtime.d.ts.map +1 -1
  62. package/dist/core/model-runtime.js +3 -3
  63. package/dist/core/model-runtime.js.map +1 -1
  64. package/dist/core/provider-composer.d.ts +2 -2
  65. package/dist/core/provider-composer.d.ts.map +1 -1
  66. package/dist/core/provider-composer.js +7 -8
  67. package/dist/core/provider-composer.js.map +1 -1
  68. package/dist/core/sdk.d.ts +8 -0
  69. package/dist/core/sdk.d.ts.map +1 -1
  70. package/dist/core/sdk.js +6 -1
  71. package/dist/core/sdk.js.map +1 -1
  72. package/dist/core/settings-manager.d.ts +9 -20
  73. package/dist/core/settings-manager.d.ts.map +1 -1
  74. package/dist/core/settings-manager.js +20 -54
  75. package/dist/core/settings-manager.js.map +1 -1
  76. package/dist/main.d.ts.map +1 -1
  77. package/dist/main.js +3 -2
  78. package/dist/main.js.map +1 -1
  79. package/dist/modes/interactive/components/footer.d.ts +0 -2
  80. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  81. package/dist/modes/interactive/components/footer.js +2 -7
  82. package/dist/modes/interactive/components/footer.js.map +1 -1
  83. package/dist/modes/interactive/components/settings-selector.d.ts +2 -6
  84. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  85. package/dist/modes/interactive/components/settings-selector.js +6 -28
  86. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  87. package/dist/modes/interactive/interactive-mode.d.ts +0 -1
  88. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  89. package/dist/modes/interactive/interactive-mode.js +23 -36
  90. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  91. package/dist/modes/rpc/rpc-client.d.ts +0 -8
  92. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  93. package/dist/modes/rpc/rpc-client.js +0 -12
  94. package/dist/modes/rpc/rpc-client.js.map +1 -1
  95. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  96. package/dist/modes/rpc/rpc-mode.js +0 -9
  97. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  98. package/dist/modes/rpc/rpc-types.d.ts +0 -19
  99. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  100. package/dist/modes/rpc/rpc-types.js.map +1 -1
  101. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +9 -2
  102. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  103. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +23 -0
  104. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  105. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +9 -1
  106. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  107. package/dist/plugins/ecosystem/plugin-bootstrap.js +5 -0
  108. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  109. package/dist/utils/photon.d.ts +2 -2
  110. package/dist/utils/photon.d.ts.map +1 -1
  111. package/dist/utils/photon.js +2 -2
  112. package/dist/utils/photon.js.map +1 -1
  113. package/docs/compaction.md +1 -3
  114. package/docs/docs.json +4 -0
  115. package/docs/index.md +1 -0
  116. package/docs/mcp.md +103 -0
  117. package/docs/models.md +14 -22
  118. package/docs/providers.md +0 -1
  119. package/docs/rpc.md +1 -26
  120. package/docs/sdk.md +4 -6
  121. package/docs/settings.md +9 -12
  122. package/docs/skills.md +1 -9
  123. package/docs/usage.md +1 -1
  124. package/examples/extensions/with-deps/package-lock.json +2 -2
  125. package/examples/extensions/with-deps/package.json +1 -1
  126. package/examples/extensions/with-deps/plugin.json +1 -1
  127. package/examples/sdk/10-settings.ts +2 -4
  128. package/examples/sdk/12-full-control.ts +1 -2
  129. package/package.json +1 -3
  130. package/dist/core/extensions/microcompact.d.ts +0 -80
  131. package/dist/core/extensions/microcompact.d.ts.map +0 -1
  132. package/dist/core/extensions/microcompact.js +0 -134
  133. package/dist/core/extensions/microcompact.js.map +0 -1
  134. package/dist/server/create-harness.d.ts +0 -26
  135. package/dist/server/create-harness.d.ts.map +0 -1
  136. package/dist/server/create-harness.js +0 -106
  137. package/dist/server/create-harness.js.map +0 -1
@@ -1,134 +0,0 @@
1
- /**
2
- * Microcompact (P1 context hygiene): before spending an LLM summarization
3
- * call, elide the BULKY OLD tool results from the LLM context — a pure local
4
- * history transform with zero model cost (the codex/ZCode "microcompact"
5
- * layer). The session file keeps every byte (append-only marker + logical
6
- * transform at context build); only the model-visible context shrinks.
7
- *
8
- * Contract: the marker is a `custom` session entry (`MICROCOMPACT_CUSTOM_TYPE`)
9
- * whose data names the elision point. The projection registered by the
10
- * bootstrap compaction policy plugin (via the PUBLIC
11
- * `api.registerEntryProjection` channel) replaces eligible tool-result
12
- * contents older than that point with a fixed placeholder, so reload and
13
- * token estimation stay consistent with live turns. The kernel applies
14
- * registered projections verbatim and knows nothing about microcompact.
15
- */
16
- import { contentText } from "@agent-forge/ai";
17
- import { estimateTokens } from "../compaction/index.js";
18
- /** Custom entry type carrying the microcompact elision point. */
19
- export const MICROCOMPACT_CUSTOM_TYPE = "microcompact.v1";
20
- /** Replacement content for an elided tool result. */
21
- export const MICROCOMPACT_ELIDED_PLACEHOLDER = "[earlier tool result elided by microcompact]";
22
- /** Tool results shorter than this are not worth eliding (noise, not bulk). */
23
- export const DEFAULT_MIN_ELIDE_CHARS = 200;
24
- /**
25
- * Minimum estimated token relief for a microcompact to fire: below this the
26
- * churn (marker entry + context transition) cannot pay for itself and the
27
- * caller falls through to full LLM compaction.
28
- */
29
- export const MIN_MICROCOMPACT_FREED_TOKENS = 2048;
30
- function isElidableToolResult(message, minChars) {
31
- if (message.role !== "toolResult")
32
- return false;
33
- // 媒体保护:含非 text part(image 等)的 tool result 不 elide——占位符替换会
34
- // 把模型可见上下文中的原图数据抹掉(会话文件虽保真,但投影按 marker 重放,
35
- // 图像不会自行回来),保持"原图常驻直到全量压缩"的现行裁决。
36
- if (Array.isArray(message.content) && message.content.some((part) => part.type !== "text")) {
37
- return false;
38
- }
39
- return contentText(message.content, "").length >= minChars;
40
- }
41
- /**
42
- * Plan one microcompact over the branch path: protect the most recent
43
- * `keepRecentTokens` (estimated) as the verbatim tail, and elide the eligible
44
- * old tool results before that cut. Returns undefined when the caller disabled
45
- * the mechanism (`options.enabled === false`), when there is nothing to elide,
46
- * or when the relief cannot reach the minimum. Deliberately does NOT reuse
47
- * `CompactionSettings`: its `enabled` is the compaction master switch — a
48
- * different gate.
49
- */
50
- export function planMicrocompact(pathEntries, options) {
51
- if (!options.enabled)
52
- return undefined;
53
- const minChars = options.minElideChars ?? DEFAULT_MIN_ELIDE_CHARS;
54
- // Protect the recent tail: walk backwards accumulating estimated tokens,
55
- // cutting before the entry that crosses the budget (same walk as
56
- // findCutPoint, but without turn-boundary subtleties — elision never
57
- // removes entries, only replaces contents, so any cut point is safe).
58
- let accumulated = 0;
59
- let cutIndex = 0;
60
- for (let i = pathEntries.length - 1; i >= 0; i--) {
61
- const entry = pathEntries[i];
62
- const messageTokens = entry.message ? estimateTokens(entry.message) : 0;
63
- if (messageTokens === 0)
64
- continue;
65
- accumulated += messageTokens;
66
- if (accumulated >= options.keepRecentTokens) {
67
- cutIndex = i;
68
- break;
69
- }
70
- }
71
- let freedTokens = 0;
72
- let elidedCount = 0;
73
- for (let i = 0; i < cutIndex; i++) {
74
- const message = pathEntries[i].message;
75
- if (!message || !isElidableToolResult(message, minChars))
76
- continue;
77
- freedTokens +=
78
- estimateTokens(message) -
79
- estimateTokens({ ...message, content: [{ type: "text", text: MICROCOMPACT_ELIDED_PLACEHOLDER }] });
80
- elidedCount += 1;
81
- }
82
- const elideBefore = pathEntries[cutIndex];
83
- if (elidedCount === 0 || freedTokens < MIN_MICROCOMPACT_FREED_TOKENS)
84
- return undefined;
85
- const elideBeforeEntryId = elideBefore?.id;
86
- if (!elideBeforeEntryId)
87
- return undefined;
88
- return { elideBeforeEntryId, freedTokens, elidedCount };
89
- }
90
- /** Resolve the marker data of the LAST microcompact marker in path order. */
91
- export function lastMicrocompactMarker(pathEntries) {
92
- let marker;
93
- for (const entry of pathEntries) {
94
- if (entry.type !== "custom" || entry.customType !== MICROCOMPACT_CUSTOM_TYPE)
95
- continue;
96
- const data = entry.data;
97
- if (typeof data?.elideBeforeEntryId === "string") {
98
- marker = {
99
- elideBeforeEntryId: data.elideBeforeEntryId,
100
- minChars: typeof data.minChars === "number" && data.minChars >= 0 ? data.minChars : DEFAULT_MIN_ELIDE_CHARS,
101
- };
102
- }
103
- }
104
- return marker;
105
- }
106
- /**
107
- * The entry projection backing microcompact: replaces the CONTENT of eligible
108
- * tool results before the marker's cut point with the fixed placeholder, and
109
- * keeps everything else verbatim. Registered through the public
110
- * `api.registerEntryProjection` channel — the same channel any third-party
111
- * context policy uses; the kernel applies it without interpretation.
112
- */
113
- export function applyMicrocompactElision(path) {
114
- const marker = lastMicrocompactMarker(path);
115
- if (marker === undefined)
116
- return path;
117
- const cutIndex = path.findIndex((entry) => entry.id === marker.elideBeforeEntryId);
118
- if (cutIndex <= 0)
119
- return path;
120
- return path.map((entry, index) => {
121
- if (index >= cutIndex || entry.type !== "message")
122
- return entry;
123
- const message = entry.message;
124
- // 与 planMicrocompact 同一判定(长度阈值 + 媒体保护):投影只 elide 规划
125
- // 时认定为可省的 tool result,否则计划与投影对同一历史给出不同结果。
126
- if (!isElidableToolResult(message, marker.minChars))
127
- return entry;
128
- return {
129
- ...entry,
130
- message: { ...message, content: [{ type: "text", text: MICROCOMPACT_ELIDED_PLACEHOLDER }] },
131
- };
132
- });
133
- }
134
- //# sourceMappingURL=microcompact.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"microcompact.js","sourceRoot":"","sources":["../../../src/core/extensions/microcompact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,iEAAiE;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;AAE1D,qDAAqD;AACrD,MAAM,CAAC,MAAM,+BAA+B,GAAG,8CAA8C,CAAC;AAE9F,8EAA8E;AAC9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAiBlD,SAAS,oBAAoB,CAC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ent":["/**\n * Microcompact (P1 context hygiene): before spending an LLM summarization\n * call, elide the BULKY OLD tool results from the LLM context — a pure local\n * history transform with zero model cost (the codex/ZCode \"microcompact\"\n * layer). The session file keeps every byte (append-only marker + logical\n * transform at context build); only the model-visible context shrinks.\n *\n * Contract: the marker is a `custom` session entry (`MICROCOMPACT_CUSTOM_TYPE`)\n * whose data names the elision point. The projection registered by the\n * bootstrap compaction policy plugin (via the PUBLIC\n * `api.registerEntryProjection` channel) replaces eligible tool-result\n * contents older than that point with a fixed placeholder, so reload and\n * token estimation stay consistent with live turns. The kernel applies\n * registered projections verbatim and knows nothing about microcompact.\n */\n\nimport type { AgentMessage } from \"@agent-forge/agent-core\";\nimport { contentText } from \"@agent-forge/ai\";\nimport { estimateTokens } from \"../compaction/index.ts\";\nimport type { SessionEntry } from \"../session-manager.ts\";\n\n/** Custom entry type carrying the microcompact elision point. */\nexport const MICROCOMPACT_CUSTOM_TYPE = \"microcompact.v1\";\n\n/** Replacement content for an elided tool result. */\nexport const MICROCOMPACT_ELIDED_PLACEHOLDER = \"[earlier tool result elided by microcompact]\";\n\n/** Tool results shorter than this are not worth eliding (noise, not bulk). */\nexport const DEFAULT_MIN_ELIDE_CHARS = 200;\n\n/**\n * Minimum estimated token relief for a microcompact to fire: below this the\n * churn (marker entry + context transition) cannot pay for itself and the\n * caller falls through to full LLM compaction.\n */\nexport const MIN_MICROCOMPACT_FREED_TOKENS = 2048;\n\n/** Data carried by a {@link MICROCOMPACT_CUSTOM_TYPE} custom entry. */\nexport interface MicrocompactMarkerData {\n\t/** Entries strictly BEFORE this entry id (path order) are elision candidates. */\n\treadonly elideBeforeEntryId: string;\n\t/** Tool results whose serialized content is shorter are kept verbatim. */\n\treadonly minChars: number;\n}\n\nexport interface MicrocompactPlan {\n\treadonly elideBeforeEntryId: string;\n\t/** Estimated tokens freed by eliding the eligible tool results. */\n\treadonly freedTokens: number;\n\treadonly elidedCount: number;\n}\n\nfunction isElidableToolResult(\n\tmessage: AgentMessage,\n\tminChars: number,\n): message is Extract<AgentMessage, { role: \"toolResult\" }> {\n\tif (message.role !== \"toolResult\") return false;\n\t// 媒体保护:含非 text part(image 等)的 tool result 不 elide——占位符替换会\n\t// 把模型可见上下文中的原图数据抹掉(会话文件虽保真,但投影按 marker 重放,\n\t// 图像不会自行回来),保持\"原图常驻直到全量压缩\"的现行裁决。\n\tif (Array.isArray(message.content) && message.content.some((part) => part.type !== \"text\")) {\n\t\treturn false;\n\t}\n\treturn contentText(message.content, \"\").length >= minChars;\n}\n\n/** Explicit plan options: `enabled` gates THIS mechanism only (microcompact relief), not compaction. */\nexport interface MicrocompactPlanOptions {\n\t/** Whether microcompact relief may fire at all (settings switch AND session cooldown). */\n\tenabled: boolean;\n\t/** Verbatim-protected recent tail budget (estimated tokens). */\n\tkeepRecentTokens: number;\n\t/** Tool results shorter than this are not worth eliding. */\n\tminElideChars?: number;\n}\n\n/**\n * Plan one microcompact over the branch path: protect the most recent\n * `keepRecentTokens` (estimated) as the verbatim tail, and elide the eligible\n * old tool results before that cut. Returns undefined when the caller disabled\n * the mechanism (`options.enabled === false`), when there is nothing to elide,\n * or when the relief cannot reach the minimum. Deliberately does NOT reuse\n * `CompactionSettings`: its `enabled` is the compaction master switch — a\n * different gate.\n */\nexport function planMicrocompact(\n\tpathEntries: readonly { readonly id?: string; readonly type: string; readonly message?: AgentMessage }[],\n\toptions: MicrocompactPlanOptions,\n): MicrocompactPlan | undefined {\n\tif (!options.enabled) return undefined;\n\tconst minChars = options.minElideChars ?? DEFAULT_MIN_ELIDE_CHARS;\n\n\t// Protect the recent tail: walk backwards accumulating estimated tokens,\n\t// cutting before the entry that crosses the budget (same walk as\n\t// findCutPoint, but without turn-boundary subtleties — elision never\n\t// removes entries, only replaces contents, so any cut point is safe).\n\tlet accumulated = 0;\n\tlet cutIndex = 0;\n\tfor (let i = pathEntries.length - 1; i >= 0; i--) {\n\t\tconst entry = pathEntries[i];\n\t\tconst messageTokens = entry.message ? estimateTokens(entry.message) : 0;\n\t\tif (messageTokens === 0) continue;\n\t\taccumulated += messageTokens;\n\t\tif (accumulated >= options.keepRecentTokens) {\n\t\t\tcutIndex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tlet freedTokens = 0;\n\tlet elidedCount = 0;\n\tfor (let i = 0; i < cutIndex; i++) {\n\t\tconst message = pathEntries[i].message;\n\t\tif (!message || !isElidableToolResult(message, minChars)) continue;\n\t\tfreedTokens +=\n\t\t\testimateTokens(message) -\n\t\t\testimateTokens({ ...message, content: [{ type: \"text\", text: MICROCOMPACT_ELIDED_PLACEHOLDER }] });\n\t\telidedCount += 1;\n\t}\n\n\tconst elideBefore = pathEntries[cutIndex];\n\tif (elidedCount === 0 || freedTokens < MIN_MICROCOMPACT_FREED_TOKENS) return undefined;\n\tconst elideBeforeEntryId = elideBefore?.id;\n\tif (!elideBeforeEntryId) return undefined;\n\treturn { elideBeforeEntryId, freedTokens, elidedCount };\n}\n\n/** Resolve the marker data of the LAST microcompact marker in path order. */\nexport function lastMicrocompactMarker(\n\tpathEntries: readonly { readonly type: string; readonly customType?: string; readonly data?: unknown }[],\n): MicrocompactMarkerData | undefined {\n\tlet marker: MicrocompactMarkerData | undefined;\n\tfor (const entry of pathEntries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== MICROCOMPACT_CUSTOM_TYPE) continue;\n\t\tconst data = entry.data as Partial<MicrocompactMarkerData> | undefined;\n\t\tif (typeof data?.elideBeforeEntryId === \"string\") {\n\t\t\tmarker = {\n\t\t\t\telideBeforeEntryId: data.elideBeforeEntryId,\n\t\t\t\tminChars: typeof data.minChars === \"number\" && data.minChars >= 0 ? data.minChars : DEFAULT_MIN_ELIDE_CHARS,\n\t\t\t};\n\t\t}\n\t}\n\treturn marker;\n}\n\n/**\n * The entry projection backing microcompact: replaces the CONTENT of eligible\n * tool results before the marker's cut point with the fixed placeholder, and\n * keeps everything else verbatim. Registered through the public\n * `api.registerEntryProjection` channel — the same channel any third-party\n * context policy uses; the kernel applies it without interpretation.\n */\nexport function applyMicrocompactElision(path: SessionEntry[]): SessionEntry[] {\n\tconst marker = lastMicrocompactMarker(path);\n\tif (marker === undefined) return path;\n\tconst cutIndex = path.findIndex((entry) => entry.id === marker.elideBeforeEntryId);\n\tif (cutIndex <= 0) return path;\n\treturn path.map((entry, index) => {\n\t\tif (index >= cutIndex || entry.type !== \"message\") return entry;\n\t\tconst message = entry.message;\n\t\t// 与 planMicrocompact 同一判定(长度阈值 + 媒体保护):投影只 elide 规划\n\t\t// 时认定为可省的 tool result,否则计划与投影对同一历史给出不同结果。\n\t\tif (!isElidableToolResult(message, marker.minChars)) return entry;\n\t\treturn {\n\t\t\t...entry,\n\t\t\tmessage: { ...message, content: [{ type: \"text\", text: MICROCOMPACT_ELIDED_PLACEHOLDER }] },\n\t\t};\n\t});\n}\n"]}
@@ -1,26 +0,0 @@
1
- import { AgentHarness, type AgentHarnessOptions, type ExecutionEnv, type HarnessTool } from "@agent-forge/agent-core";
2
- import { type BuildSystemPromptOptions } from "../core/system-prompt.ts";
3
- export interface CodingAgentHarnessTool extends HarnessTool {
4
- promptSnippet?: string;
5
- promptGuidelines?: readonly string[];
6
- }
7
- export interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, "toolContext" | "tools"> {
8
- env: ExecutionEnv;
9
- bashCommandPrefix?: string;
10
- /** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */
11
- sessionFile?: string;
12
- tools?: CodingAgentHarnessTool[];
13
- systemPromptOptions?: Omit<BuildSystemPromptOptions, "cwd" | "promptGuidelines" | "selectedTools" | "toolSnippets">;
14
- }
15
- export interface BuildCodingAgentHarnessSystemPromptOptions {
16
- cwd: string;
17
- tools: readonly CodingAgentHarnessTool[];
18
- activeToolNames: readonly string[];
19
- systemPromptOptions?: CreateCodingAgentHarnessOptions["systemPromptOptions"];
20
- }
21
- export declare function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string;
22
- export declare function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions): Promise<{
23
- harness: AgentHarness;
24
- suspended: import("@agent-forge/agent-core").SuspendedOperation[];
25
- }>;
26
- //# sourceMappingURL=create-harness.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-harness.d.ts","sourceRoot":"","sources":["../../src/server/create-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,KAAK,mBAAmB,EAMxB,KAAK,YAAY,EAEjB,KAAK,WAAW,EAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,wBAAwB,EAAqB,MAAM,0BAA0B,CAAC;AAM5F,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAgBD,MAAM,WAAW,+BAAgC,SAAQ,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,OAAO,CAAC;IAC1G,GAAG,EAAE,YAAY,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mGAAmG;IACnG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACjC,mBAAmB,CAAC,EAAE,IAAI,CAAC,wBAAwB,EAAE,KAAK,GAAG,kBAAkB,GAAG,eAAe,GAAG,cAAc,CAAC,CAAC;CACpH;AAED,MAAM,WAAW,0CAA0C;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACzC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,mBAAmB,CAAC,EAAE,+BAA+B,CAAC,qBAAqB,CAAC,CAAC;CAC7E;AAED,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,0CAA0C,GAAG,MAAM,CAsB/G;AAED,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B;;;GAkFtF","sourcesContent":["import {\n\tAgentHarness,\n\ttype AgentHarnessOptions,\n\ttype AgentHarnessTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype ExecutionEnv,\n\ttype ExecutionToolContext,\n\ttype HarnessTool,\n} from \"@agent-forge/agent-core\";\nimport type { Static, TSchema } from \"typebox\";\nimport { type BuildSystemPromptOptions, buildSystemPrompt } from \"../core/system-prompt.ts\";\nimport { bashToolSystemPromptContribution } from \"../core/tools/bash.ts\";\nimport { editToolSystemPromptContribution } from \"../core/tools/edit.ts\";\nimport { readToolSystemPromptContribution } from \"../core/tools/read.ts\";\nimport { writeToolSystemPromptContribution } from \"../core/tools/write.ts\";\n\nexport interface CodingAgentHarnessTool extends HarnessTool {\n\tpromptSnippet?: string;\n\tpromptGuidelines?: readonly string[];\n}\n\nfunction createCodingAgentHarnessTool<TParameters extends TSchema, TDetails>(\n\ttool: AgentHarnessTool<ExecutionToolContext, TParameters, TDetails>,\n\tcontext: ExecutionToolContext,\n\tprompt: Required<Pick<CodingAgentHarnessTool, \"promptSnippet\" | \"promptGuidelines\">>,\n): CodingAgentHarnessTool {\n\treturn {\n\t\t...tool,\n\t\t...prompt,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecute: (toolCallId, params, signal, onUpdate) =>\n\t\t\ttool.execute(toolCallId, params as Static<TParameters>, signal, onUpdate, context),\n\t};\n}\n\nexport interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, \"toolContext\" | \"tools\"> {\n\tenv: ExecutionEnv;\n\tbashCommandPrefix?: string;\n\t/** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */\n\tsessionFile?: string;\n\ttools?: CodingAgentHarnessTool[];\n\tsystemPromptOptions?: Omit<BuildSystemPromptOptions, \"cwd\" | \"promptGuidelines\" | \"selectedTools\" | \"toolSnippets\">;\n}\n\nexport interface BuildCodingAgentHarnessSystemPromptOptions {\n\tcwd: string;\n\ttools: readonly CodingAgentHarnessTool[];\n\tactiveToolNames: readonly string[];\n\tsystemPromptOptions?: CreateCodingAgentHarnessOptions[\"systemPromptOptions\"];\n}\n\nexport function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string {\n\tconst activeTools = options.activeToolNames.flatMap((name) => {\n\t\tconst tool = options.tools.find((candidate) => candidate.name === name);\n\t\treturn tool ? [tool] : [];\n\t});\n\tconst toolSnippets = Object.fromEntries(\n\t\tactiveTools.flatMap((tool) => {\n\t\t\tconst promptSnippet = tool.promptSnippet\n\t\t\t\t?.replace(/[\\r\\n]+/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\treturn promptSnippet ? [[tool.name, promptSnippet]] : [];\n\t\t}),\n\t);\n\tconst promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);\n\treturn buildSystemPrompt({\n\t\t...options.systemPromptOptions,\n\t\tcwd: options.cwd,\n\t\tselectedTools: activeTools.map((tool) => tool.name),\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t});\n}\n\nexport async function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions) {\n\tconst {\n\t\tenv,\n\t\tbashCommandPrefix,\n\t\tsessionFile,\n\t\tsystemPromptOptions,\n\t\ttools: providedTools,\n\t\tactiveToolNames: providedActiveToolNames,\n\t\tsystemPrompt: providedSystemPrompt,\n\t\t...harnessOptions\n\t} = options;\n\tlet harness: AgentHarness | undefined;\n\tconst getHarness = (): AgentHarness => {\n\t\t// v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行\n\t\tif (!harness) throw new Error(\"Coding-agent Harness callback ran before Harness initialization\");\n\t\treturn harness;\n\t};\n\tlet tools = providedTools;\n\tif (tools === undefined) {\n\t\tconst metadata = await options.session.getMetadata();\n\t\tconst toolContext = { env } satisfies ExecutionToolContext;\n\t\ttools = [\n\t\t\tcreateCodingAgentHarnessTool(createReadTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: readToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(\n\t\t\t\tcreateBashTool<ExecutionToolContext>({\n\t\t\t\t\tcommandPrefix: bashCommandPrefix,\n\t\t\t\t\tprepare: async (execution) => {\n\t\t\t\t\t\tconst currentHarness = getHarness();\n\t\t\t\t\t\tconst [model, thinkingLevel] = await Promise.all([\n\t\t\t\t\t\t\tcurrentHarness.getModel(),\n\t\t\t\t\t\t\tcurrentHarness.getThinkingLevel(),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_ID = metadata.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? \"\";\n\t\t\t\t\t\texecution.env.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_MODEL = model.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\ttoolContext,\n\t\t\t\t{\n\t\t\t\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\t\t\t\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateCodingAgentHarnessTool(createEditTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: editToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(createWriteTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: writeToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t];\n\t}\n\tconst activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];\n\tconst systemPrompt =\n\t\tprovidedSystemPrompt ??\n\t\t(async () => {\n\t\t\tconst currentHarness = getHarness();\n\t\t\tconst [currentTools, currentActiveToolNames] = await Promise.all([\n\t\t\t\tcurrentHarness.getTools(),\n\t\t\t\tcurrentHarness.getActiveTools(),\n\t\t\t]);\n\t\t\treturn buildCodingAgentHarnessSystemPrompt({\n\t\t\t\tcwd: env.cwd,\n\t\t\t\ttools: currentTools,\n\t\t\t\tactiveToolNames: currentActiveToolNames,\n\t\t\t\tsystemPromptOptions,\n\t\t\t});\n\t\t});\n\tconst created = await AgentHarness.create({\n\t\t...harnessOptions,\n\t\ttools,\n\t\tactiveToolNames,\n\t\tsystemPrompt,\n\t});\n\tharness = created.harness;\n\treturn created;\n}\n"]}
@@ -1,106 +0,0 @@
1
- import { AgentHarness, createBashTool, createEditTool, createReadTool, createWriteTool, } from "@agent-forge/agent-core";
2
- import { buildSystemPrompt } from "../core/system-prompt.js";
3
- import { bashToolSystemPromptContribution } from "../core/tools/bash.js";
4
- import { editToolSystemPromptContribution } from "../core/tools/edit.js";
5
- import { readToolSystemPromptContribution } from "../core/tools/read.js";
6
- import { writeToolSystemPromptContribution } from "../core/tools/write.js";
7
- function createCodingAgentHarnessTool(tool, context, prompt) {
8
- return {
9
- ...tool,
10
- ...prompt,
11
- constrainedSampling: { type: "json_schema", strict: "prefer" },
12
- execute: (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate, context),
13
- };
14
- }
15
- export function buildCodingAgentHarnessSystemPrompt(options) {
16
- const activeTools = options.activeToolNames.flatMap((name) => {
17
- const tool = options.tools.find((candidate) => candidate.name === name);
18
- return tool ? [tool] : [];
19
- });
20
- const toolSnippets = Object.fromEntries(activeTools.flatMap((tool) => {
21
- const promptSnippet = tool.promptSnippet
22
- ?.replace(/[\r\n]+/g, " ")
23
- .replace(/\s+/g, " ")
24
- .trim();
25
- return promptSnippet ? [[tool.name, promptSnippet]] : [];
26
- }));
27
- const promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);
28
- return buildSystemPrompt({
29
- ...options.systemPromptOptions,
30
- cwd: options.cwd,
31
- selectedTools: activeTools.map((tool) => tool.name),
32
- toolSnippets,
33
- promptGuidelines,
34
- });
35
- }
36
- export async function createCodingAgentHarness(options) {
37
- const { env, bashCommandPrefix, sessionFile, systemPromptOptions, tools: providedTools, activeToolNames: providedActiveToolNames, systemPrompt: providedSystemPrompt, ...harnessOptions } = options;
38
- let harness;
39
- const getHarness = () => {
40
- // v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行
41
- if (!harness)
42
- throw new Error("Coding-agent Harness callback ran before Harness initialization");
43
- return harness;
44
- };
45
- let tools = providedTools;
46
- if (tools === undefined) {
47
- const metadata = await options.session.getMetadata();
48
- const toolContext = { env };
49
- tools = [
50
- createCodingAgentHarnessTool(createReadTool(), toolContext, {
51
- promptSnippet: readToolSystemPromptContribution.snippet,
52
- promptGuidelines: readToolSystemPromptContribution.guidelines,
53
- }),
54
- createCodingAgentHarnessTool(createBashTool({
55
- commandPrefix: bashCommandPrefix,
56
- prepare: async (execution) => {
57
- const currentHarness = getHarness();
58
- const [model, thinkingLevel] = await Promise.all([
59
- currentHarness.getModel(),
60
- currentHarness.getThinkingLevel(),
61
- ]);
62
- execution.env.AGENT_FORGE_SESSION_ID = metadata.id;
63
- execution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? "";
64
- execution.env.AGENT_FORGE_PROVIDER = model.provider;
65
- execution.env.AGENT_FORGE_MODEL = model.id;
66
- execution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;
67
- },
68
- }), toolContext, {
69
- promptSnippet: bashToolSystemPromptContribution.snippet,
70
- promptGuidelines: bashToolSystemPromptContribution.guidelines,
71
- }),
72
- createCodingAgentHarnessTool(createEditTool(), toolContext, {
73
- promptSnippet: editToolSystemPromptContribution.snippet,
74
- promptGuidelines: editToolSystemPromptContribution.guidelines,
75
- }),
76
- createCodingAgentHarnessTool(createWriteTool(), toolContext, {
77
- promptSnippet: writeToolSystemPromptContribution.snippet,
78
- promptGuidelines: writeToolSystemPromptContribution.guidelines,
79
- }),
80
- ];
81
- }
82
- const activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];
83
- const systemPrompt = providedSystemPrompt ??
84
- (async () => {
85
- const currentHarness = getHarness();
86
- const [currentTools, currentActiveToolNames] = await Promise.all([
87
- currentHarness.getTools(),
88
- currentHarness.getActiveTools(),
89
- ]);
90
- return buildCodingAgentHarnessSystemPrompt({
91
- cwd: env.cwd,
92
- tools: currentTools,
93
- activeToolNames: currentActiveToolNames,
94
- systemPromptOptions,
95
- });
96
- });
97
- const created = await AgentHarness.create({
98
- ...harnessOptions,
99
- tools,
100
- activeToolNames,
101
- systemPrompt,
102
- });
103
- harness = created.harness;
104
- return created;
105
- }
106
- //# sourceMappingURL=create-harness.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-harness.js","sourceRoot":"","sources":["../../src/server/create-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EAGZ,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAIf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAiC,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAO3E,SAAS,4BAA4B,CACpC,IAAmE,EACnE,OAA6B,EAC7B,MAAoF,EAC3D;IACzB,OAAO;QACN,GAAG,IAAI;QACP,GAAG,MAAM;QACT,mBAAmB,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;QAC9D,OAA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CAAmC,CAAC;gBAC1C,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,KAAK,EAAE,YAAY;gBACnB,eAAe,EAAE,sBAAsB;gBACvC,mBAAmB;aACnB,CAAC,CAAC;QAAA,CACH,CAAC,CAAC;IACJ,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC;QACzC,GAAG,cAAc;QACjB,KAAK;QACL,eAAe;QACf,YAAY;KACZ,CAAC,CAAC;IACH,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAC1B,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import {\n\tAgentHarness,\n\ttype AgentHarnessOptions,\n\ttype AgentHarnessTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype ExecutionEnv,\n\ttype ExecutionToolContext,\n\ttype HarnessTool,\n} from \"@agent-forge/agent-core\";\nimport type { Static, TSchema } from \"typebox\";\nimport { type BuildSystemPromptOptions, buildSystemPrompt } from \"../core/system-prompt.ts\";\nimport { bashToolSystemPromptContribution } from \"../core/tools/bash.ts\";\nimport { editToolSystemPromptContribution } from \"../core/tools/edit.ts\";\nimport { readToolSystemPromptContribution } from \"../core/tools/read.ts\";\nimport { writeToolSystemPromptContribution } from \"../core/tools/write.ts\";\n\nexport interface CodingAgentHarnessTool extends HarnessTool {\n\tpromptSnippet?: string;\n\tpromptGuidelines?: readonly string[];\n}\n\nfunction createCodingAgentHarnessTool<TParameters extends TSchema, TDetails>(\n\ttool: AgentHarnessTool<ExecutionToolContext, TParameters, TDetails>,\n\tcontext: ExecutionToolContext,\n\tprompt: Required<Pick<CodingAgentHarnessTool, \"promptSnippet\" | \"promptGuidelines\">>,\n): CodingAgentHarnessTool {\n\treturn {\n\t\t...tool,\n\t\t...prompt,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecute: (toolCallId, params, signal, onUpdate) =>\n\t\t\ttool.execute(toolCallId, params as Static<TParameters>, signal, onUpdate, context),\n\t};\n}\n\nexport interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, \"toolContext\" | \"tools\"> {\n\tenv: ExecutionEnv;\n\tbashCommandPrefix?: string;\n\t/** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */\n\tsessionFile?: string;\n\ttools?: CodingAgentHarnessTool[];\n\tsystemPromptOptions?: Omit<BuildSystemPromptOptions, \"cwd\" | \"promptGuidelines\" | \"selectedTools\" | \"toolSnippets\">;\n}\n\nexport interface BuildCodingAgentHarnessSystemPromptOptions {\n\tcwd: string;\n\ttools: readonly CodingAgentHarnessTool[];\n\tactiveToolNames: readonly string[];\n\tsystemPromptOptions?: CreateCodingAgentHarnessOptions[\"systemPromptOptions\"];\n}\n\nexport function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string {\n\tconst activeTools = options.activeToolNames.flatMap((name) => {\n\t\tconst tool = options.tools.find((candidate) => candidate.name === name);\n\t\treturn tool ? [tool] : [];\n\t});\n\tconst toolSnippets = Object.fromEntries(\n\t\tactiveTools.flatMap((tool) => {\n\t\t\tconst promptSnippet = tool.promptSnippet\n\t\t\t\t?.replace(/[\\r\\n]+/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\treturn promptSnippet ? [[tool.name, promptSnippet]] : [];\n\t\t}),\n\t);\n\tconst promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);\n\treturn buildSystemPrompt({\n\t\t...options.systemPromptOptions,\n\t\tcwd: options.cwd,\n\t\tselectedTools: activeTools.map((tool) => tool.name),\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t});\n}\n\nexport async function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions) {\n\tconst {\n\t\tenv,\n\t\tbashCommandPrefix,\n\t\tsessionFile,\n\t\tsystemPromptOptions,\n\t\ttools: providedTools,\n\t\tactiveToolNames: providedActiveToolNames,\n\t\tsystemPrompt: providedSystemPrompt,\n\t\t...harnessOptions\n\t} = options;\n\tlet harness: AgentHarness | undefined;\n\tconst getHarness = (): AgentHarness => {\n\t\t// v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行\n\t\tif (!harness) throw new Error(\"Coding-agent Harness callback ran before Harness initialization\");\n\t\treturn harness;\n\t};\n\tlet tools = providedTools;\n\tif (tools === undefined) {\n\t\tconst metadata = await options.session.getMetadata();\n\t\tconst toolContext = { env } satisfies ExecutionToolContext;\n\t\ttools = [\n\t\t\tcreateCodingAgentHarnessTool(createReadTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: readToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(\n\t\t\t\tcreateBashTool<ExecutionToolContext>({\n\t\t\t\t\tcommandPrefix: bashCommandPrefix,\n\t\t\t\t\tprepare: async (execution) => {\n\t\t\t\t\t\tconst currentHarness = getHarness();\n\t\t\t\t\t\tconst [model, thinkingLevel] = await Promise.all([\n\t\t\t\t\t\t\tcurrentHarness.getModel(),\n\t\t\t\t\t\t\tcurrentHarness.getThinkingLevel(),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_ID = metadata.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? \"\";\n\t\t\t\t\t\texecution.env.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_MODEL = model.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\ttoolContext,\n\t\t\t\t{\n\t\t\t\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\t\t\t\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateCodingAgentHarnessTool(createEditTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: editToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(createWriteTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: writeToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t];\n\t}\n\tconst activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];\n\tconst systemPrompt =\n\t\tprovidedSystemPrompt ??\n\t\t(async () => {\n\t\t\tconst currentHarness = getHarness();\n\t\t\tconst [currentTools, currentActiveToolNames] = await Promise.all([\n\t\t\t\tcurrentHarness.getTools(),\n\t\t\t\tcurrentHarness.getActiveTools(),\n\t\t\t]);\n\t\t\treturn buildCodingAgentHarnessSystemPrompt({\n\t\t\t\tcwd: env.cwd,\n\t\t\t\ttools: currentTools,\n\t\t\t\tactiveToolNames: currentActiveToolNames,\n\t\t\t\tsystemPromptOptions,\n\t\t\t});\n\t\t});\n\tconst created = await AgentHarness.create({\n\t\t...harnessOptions,\n\t\ttools,\n\t\tactiveToolNames,\n\t\tsystemPrompt,\n\t});\n\tharness = created.harness;\n\treturn created;\n}\n"]}