longer-agent 0.1.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 (289) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -0
  3. package/README.zh-CN.md +227 -0
  4. package/agent_templates/executor/agent.yaml +22 -0
  5. package/agent_templates/executor/system_prompt.md +17 -0
  6. package/agent_templates/explorer/agent.yaml +13 -0
  7. package/agent_templates/explorer/system_prompt.md +19 -0
  8. package/agent_templates/main/agent.yaml +7 -0
  9. package/agent_templates/main/system_prompt.md +45 -0
  10. package/configExample.yaml +83 -0
  11. package/dist/agents/agent.d.ts +79 -0
  12. package/dist/agents/agent.d.ts.map +1 -0
  13. package/dist/agents/agent.js +156 -0
  14. package/dist/agents/agent.js.map +1 -0
  15. package/dist/agents/tool-loop.d.ts +140 -0
  16. package/dist/agents/tool-loop.d.ts.map +1 -0
  17. package/dist/agents/tool-loop.js +465 -0
  18. package/dist/agents/tool-loop.js.map +1 -0
  19. package/dist/ask.d.ts +81 -0
  20. package/dist/ask.d.ts.map +1 -0
  21. package/dist/ask.js +34 -0
  22. package/dist/ask.js.map +1 -0
  23. package/dist/auth/openai-oauth.d.ts +66 -0
  24. package/dist/auth/openai-oauth.d.ts.map +1 -0
  25. package/dist/auth/openai-oauth.js +640 -0
  26. package/dist/auth/openai-oauth.js.map +1 -0
  27. package/dist/cli.d.ts +14 -0
  28. package/dist/cli.d.ts.map +1 -0
  29. package/dist/cli.js +254 -0
  30. package/dist/cli.js.map +1 -0
  31. package/dist/commands.d.ts +118 -0
  32. package/dist/commands.d.ts.map +1 -0
  33. package/dist/commands.js +862 -0
  34. package/dist/commands.js.map +1 -0
  35. package/dist/config.d.ts +130 -0
  36. package/dist/config.d.ts.map +1 -0
  37. package/dist/config.js +648 -0
  38. package/dist/config.js.map +1 -0
  39. package/dist/context-rendering.d.ts +69 -0
  40. package/dist/context-rendering.d.ts.map +1 -0
  41. package/dist/context-rendering.js +250 -0
  42. package/dist/context-rendering.js.map +1 -0
  43. package/dist/document-projection.d.ts +12 -0
  44. package/dist/document-projection.d.ts.map +1 -0
  45. package/dist/document-projection.js +75 -0
  46. package/dist/document-projection.js.map +1 -0
  47. package/dist/ephemeral-log.d.ts +15 -0
  48. package/dist/ephemeral-log.d.ts.map +1 -0
  49. package/dist/ephemeral-log.js +173 -0
  50. package/dist/ephemeral-log.js.map +1 -0
  51. package/dist/file-attach.d.ts +89 -0
  52. package/dist/file-attach.d.ts.map +1 -0
  53. package/dist/file-attach.js +571 -0
  54. package/dist/file-attach.js.map +1 -0
  55. package/dist/index.d.ts +29 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +43 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/init-wizard.d.ts +13 -0
  60. package/dist/init-wizard.d.ts.map +1 -0
  61. package/dist/init-wizard.js +328 -0
  62. package/dist/init-wizard.js.map +1 -0
  63. package/dist/log-entry.d.ts +104 -0
  64. package/dist/log-entry.d.ts.map +1 -0
  65. package/dist/log-entry.js +292 -0
  66. package/dist/log-entry.js.map +1 -0
  67. package/dist/log-projection.d.ts +73 -0
  68. package/dist/log-projection.d.ts.map +1 -0
  69. package/dist/log-projection.js +651 -0
  70. package/dist/log-projection.js.map +1 -0
  71. package/dist/mcp-client.d.ts +55 -0
  72. package/dist/mcp-client.d.ts.map +1 -0
  73. package/dist/mcp-client.js +402 -0
  74. package/dist/mcp-client.js.map +1 -0
  75. package/dist/model-selection.d.ts +16 -0
  76. package/dist/model-selection.d.ts.map +1 -0
  77. package/dist/model-selection.js +181 -0
  78. package/dist/model-selection.js.map +1 -0
  79. package/dist/network-retry.d.ts +38 -0
  80. package/dist/network-retry.d.ts.map +1 -0
  81. package/dist/network-retry.js +140 -0
  82. package/dist/network-retry.js.map +1 -0
  83. package/dist/persistence.d.ts +104 -0
  84. package/dist/persistence.d.ts.map +1 -0
  85. package/dist/persistence.js +644 -0
  86. package/dist/persistence.js.map +1 -0
  87. package/dist/primitives/context.d.ts +29 -0
  88. package/dist/primitives/context.d.ts.map +1 -0
  89. package/dist/primitives/context.js +85 -0
  90. package/dist/primitives/context.js.map +1 -0
  91. package/dist/progress.d.ts +51 -0
  92. package/dist/progress.d.ts.map +1 -0
  93. package/dist/progress.js +229 -0
  94. package/dist/progress.js.map +1 -0
  95. package/dist/provider-presets.d.ts +34 -0
  96. package/dist/provider-presets.d.ts.map +1 -0
  97. package/dist/provider-presets.js +181 -0
  98. package/dist/provider-presets.js.map +1 -0
  99. package/dist/providers/anthropic.d.ts +32 -0
  100. package/dist/providers/anthropic.d.ts.map +1 -0
  101. package/dist/providers/anthropic.js +450 -0
  102. package/dist/providers/anthropic.js.map +1 -0
  103. package/dist/providers/base.d.ts +135 -0
  104. package/dist/providers/base.d.ts.map +1 -0
  105. package/dist/providers/base.js +104 -0
  106. package/dist/providers/base.js.map +1 -0
  107. package/dist/providers/glm.d.ts +18 -0
  108. package/dist/providers/glm.d.ts.map +1 -0
  109. package/dist/providers/glm.js +59 -0
  110. package/dist/providers/glm.js.map +1 -0
  111. package/dist/providers/kimi.d.ts +23 -0
  112. package/dist/providers/kimi.d.ts.map +1 -0
  113. package/dist/providers/kimi.js +89 -0
  114. package/dist/providers/kimi.js.map +1 -0
  115. package/dist/providers/minimax.d.ts +20 -0
  116. package/dist/providers/minimax.d.ts.map +1 -0
  117. package/dist/providers/minimax.js +192 -0
  118. package/dist/providers/minimax.js.map +1 -0
  119. package/dist/providers/openai-chat.d.ts +33 -0
  120. package/dist/providers/openai-chat.d.ts.map +1 -0
  121. package/dist/providers/openai-chat.js +543 -0
  122. package/dist/providers/openai-chat.js.map +1 -0
  123. package/dist/providers/openai-responses.d.ts +26 -0
  124. package/dist/providers/openai-responses.d.ts.map +1 -0
  125. package/dist/providers/openai-responses.js +443 -0
  126. package/dist/providers/openai-responses.js.map +1 -0
  127. package/dist/providers/openrouter.d.ts +24 -0
  128. package/dist/providers/openrouter.d.ts.map +1 -0
  129. package/dist/providers/openrouter.js +177 -0
  130. package/dist/providers/openrouter.js.map +1 -0
  131. package/dist/providers/registry.d.ts +7 -0
  132. package/dist/providers/registry.d.ts.map +1 -0
  133. package/dist/providers/registry.js +38 -0
  134. package/dist/providers/registry.js.map +1 -0
  135. package/dist/security/path.d.ts +51 -0
  136. package/dist/security/path.d.ts.map +1 -0
  137. package/dist/security/path.js +187 -0
  138. package/dist/security/path.js.map +1 -0
  139. package/dist/security/sensitive-files.d.ts +3 -0
  140. package/dist/security/sensitive-files.d.ts.map +1 -0
  141. package/dist/security/sensitive-files.js +41 -0
  142. package/dist/security/sensitive-files.js.map +1 -0
  143. package/dist/session.d.ts +446 -0
  144. package/dist/session.d.ts.map +1 -0
  145. package/dist/session.js +4595 -0
  146. package/dist/session.js.map +1 -0
  147. package/dist/settings.d.ts +46 -0
  148. package/dist/settings.d.ts.map +1 -0
  149. package/dist/settings.js +134 -0
  150. package/dist/settings.js.map +1 -0
  151. package/dist/show-context.d.ts +35 -0
  152. package/dist/show-context.d.ts.map +1 -0
  153. package/dist/show-context.js +320 -0
  154. package/dist/show-context.js.map +1 -0
  155. package/dist/skills/loader.d.ts +49 -0
  156. package/dist/skills/loader.d.ts.map +1 -0
  157. package/dist/skills/loader.js +166 -0
  158. package/dist/skills/loader.js.map +1 -0
  159. package/dist/summarize-context.d.ts +29 -0
  160. package/dist/summarize-context.d.ts.map +1 -0
  161. package/dist/summarize-context.js +247 -0
  162. package/dist/summarize-context.js.map +1 -0
  163. package/dist/templates/loader.d.ts +104 -0
  164. package/dist/templates/loader.d.ts.map +1 -0
  165. package/dist/templates/loader.js +514 -0
  166. package/dist/templates/loader.js.map +1 -0
  167. package/dist/tools/basic.d.ts +29 -0
  168. package/dist/tools/basic.d.ts.map +1 -0
  169. package/dist/tools/basic.js +2079 -0
  170. package/dist/tools/basic.js.map +1 -0
  171. package/dist/tools/comm.d.ts +17 -0
  172. package/dist/tools/comm.d.ts.map +1 -0
  173. package/dist/tools/comm.js +192 -0
  174. package/dist/tools/comm.js.map +1 -0
  175. package/dist/tools/web-fetch.d.ts +11 -0
  176. package/dist/tools/web-fetch.d.ts.map +1 -0
  177. package/dist/tools/web-fetch.js +237 -0
  178. package/dist/tools/web-fetch.js.map +1 -0
  179. package/dist/tools/web-search.d.ts +24 -0
  180. package/dist/tools/web-search.d.ts.map +1 -0
  181. package/dist/tools/web-search.js +51 -0
  182. package/dist/tools/web-search.js.map +1 -0
  183. package/dist/tui/app.d.ts +35 -0
  184. package/dist/tui/app.d.ts.map +1 -0
  185. package/dist/tui/app.js +1042 -0
  186. package/dist/tui/app.js.map +1 -0
  187. package/dist/tui/checkbox-picker.d.ts +35 -0
  188. package/dist/tui/checkbox-picker.d.ts.map +1 -0
  189. package/dist/tui/checkbox-picker.js +85 -0
  190. package/dist/tui/checkbox-picker.js.map +1 -0
  191. package/dist/tui/command-picker.d.ts +31 -0
  192. package/dist/tui/command-picker.d.ts.map +1 -0
  193. package/dist/tui/command-picker.js +113 -0
  194. package/dist/tui/command-picker.js.map +1 -0
  195. package/dist/tui/components/ask-panel.d.ts +21 -0
  196. package/dist/tui/components/ask-panel.d.ts.map +1 -0
  197. package/dist/tui/components/ask-panel.js +81 -0
  198. package/dist/tui/components/ask-panel.js.map +1 -0
  199. package/dist/tui/components/conversation-panel.d.ts +68 -0
  200. package/dist/tui/components/conversation-panel.d.ts.map +1 -0
  201. package/dist/tui/components/conversation-panel.js +611 -0
  202. package/dist/tui/components/conversation-panel.js.map +1 -0
  203. package/dist/tui/components/input-panel.d.ts +27 -0
  204. package/dist/tui/components/input-panel.d.ts.map +1 -0
  205. package/dist/tui/components/input-panel.js +725 -0
  206. package/dist/tui/components/input-panel.js.map +1 -0
  207. package/dist/tui/components/logo-panel.d.ts +14 -0
  208. package/dist/tui/components/logo-panel.d.ts.map +1 -0
  209. package/dist/tui/components/logo-panel.js +37 -0
  210. package/dist/tui/components/logo-panel.js.map +1 -0
  211. package/dist/tui/components/plan-panel.d.ts +10 -0
  212. package/dist/tui/components/plan-panel.d.ts.map +1 -0
  213. package/dist/tui/components/plan-panel.js +8 -0
  214. package/dist/tui/components/plan-panel.js.map +1 -0
  215. package/dist/tui/components/status-bar.d.ts +24 -0
  216. package/dist/tui/components/status-bar.d.ts.map +1 -0
  217. package/dist/tui/components/status-bar.js +80 -0
  218. package/dist/tui/components/status-bar.js.map +1 -0
  219. package/dist/tui/input/editor-state.d.ts +22 -0
  220. package/dist/tui/input/editor-state.d.ts.map +1 -0
  221. package/dist/tui/input/editor-state.js +157 -0
  222. package/dist/tui/input/editor-state.js.map +1 -0
  223. package/dist/tui/input/keymap.d.ts +3 -0
  224. package/dist/tui/input/keymap.d.ts.map +1 -0
  225. package/dist/tui/input/keymap.js +72 -0
  226. package/dist/tui/input/keymap.js.map +1 -0
  227. package/dist/tui/input/paste-slots.d.ts +17 -0
  228. package/dist/tui/input/paste-slots.d.ts.map +1 -0
  229. package/dist/tui/input/paste-slots.js +46 -0
  230. package/dist/tui/input/paste-slots.js.map +1 -0
  231. package/dist/tui/input/paste.d.ts +15 -0
  232. package/dist/tui/input/paste.d.ts.map +1 -0
  233. package/dist/tui/input/paste.js +35 -0
  234. package/dist/tui/input/paste.js.map +1 -0
  235. package/dist/tui/input/protocol.d.ts +9 -0
  236. package/dist/tui/input/protocol.d.ts.map +1 -0
  237. package/dist/tui/input/protocol.js +387 -0
  238. package/dist/tui/input/protocol.js.map +1 -0
  239. package/dist/tui/input/sanitize.d.ts +6 -0
  240. package/dist/tui/input/sanitize.d.ts.map +1 -0
  241. package/dist/tui/input/sanitize.js +20 -0
  242. package/dist/tui/input/sanitize.js.map +1 -0
  243. package/dist/tui/input/types.d.ts +18 -0
  244. package/dist/tui/input/types.d.ts.map +1 -0
  245. package/dist/tui/input/types.js +2 -0
  246. package/dist/tui/input/types.js.map +1 -0
  247. package/dist/tui/launch.d.ts +23 -0
  248. package/dist/tui/launch.d.ts.map +1 -0
  249. package/dist/tui/launch.js +104 -0
  250. package/dist/tui/launch.js.map +1 -0
  251. package/dist/tui/theme.d.ts +20 -0
  252. package/dist/tui/theme.d.ts.map +1 -0
  253. package/dist/tui/theme.js +29 -0
  254. package/dist/tui/theme.js.map +1 -0
  255. package/dist/tui/types.d.ts +136 -0
  256. package/dist/tui/types.d.ts.map +1 -0
  257. package/dist/tui/types.js +9 -0
  258. package/dist/tui/types.js.map +1 -0
  259. package/package.json +76 -0
  260. package/prompts/sections/agents_md.md +23 -0
  261. package/prompts/sections/important_log.md +16 -0
  262. package/prompts/sections/system_mechanisms.md +18 -0
  263. package/prompts/tools/apply_patch.md +31 -0
  264. package/prompts/tools/ask.md +18 -0
  265. package/prompts/tools/bash.md +13 -0
  266. package/prompts/tools/bash_background.md +9 -0
  267. package/prompts/tools/bash_output.md +9 -0
  268. package/prompts/tools/check_status.md +3 -0
  269. package/prompts/tools/diff.md +5 -0
  270. package/prompts/tools/edit_file.md +11 -0
  271. package/prompts/tools/glob.md +7 -0
  272. package/prompts/tools/grep.md +20 -0
  273. package/prompts/tools/kill_agent.md +3 -0
  274. package/prompts/tools/kill_shell.md +5 -0
  275. package/prompts/tools/list_dir.md +5 -0
  276. package/prompts/tools/plan.md +252 -0
  277. package/prompts/tools/read_file.md +9 -0
  278. package/prompts/tools/show_context.md +12 -0
  279. package/prompts/tools/skill.md +7 -0
  280. package/prompts/tools/spawn_agent.md +195 -0
  281. package/prompts/tools/summarize_context.md +122 -0
  282. package/prompts/tools/test.md +5 -0
  283. package/prompts/tools/wait.md +17 -0
  284. package/prompts/tools/web_fetch.md +9 -0
  285. package/prompts/tools/web_search.md +5 -0
  286. package/prompts/tools/write_file.md +11 -0
  287. package/skills/.staging/.gitkeep +0 -0
  288. package/skills/explain-code/SKILL.md +15 -0
  289. package/skills/skill-manager/SKILL.md +83 -0
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Log-native summarize_context implementation.
3
+ *
4
+ * The session log is the single source of truth. summarize_context works
5
+ * directly on LogEntry[] and inserts summary entries into the active window.
6
+ */
7
+ import { createSummary } from "./log-entry.js";
8
+ function getLogContextId(entry) {
9
+ if (entry.discarded || entry.summarized)
10
+ return null;
11
+ const ctxId = entry.meta["contextId"];
12
+ if (ctxId === undefined || ctxId === null)
13
+ return null;
14
+ return String(ctxId);
15
+ }
16
+ function isTransparentLogEntry(entry) {
17
+ if (entry.discarded || entry.summarized)
18
+ return true;
19
+ return getLogContextId(entry) === null;
20
+ }
21
+ function buildLogSpatialIndex(entries) {
22
+ const index = new Map();
23
+ for (let i = 0; i < entries.length; i++) {
24
+ const ctxId = getLogContextId(entries[i]);
25
+ if (!ctxId)
26
+ continue;
27
+ registerIndex(index, ctxId, i);
28
+ if (ctxId.includes(".")) {
29
+ registerIndex(index, ctxId.split(".")[0], i);
30
+ }
31
+ }
32
+ return index;
33
+ }
34
+ function registerIndex(index, key, idx) {
35
+ const entry = index.get(key);
36
+ if (entry) {
37
+ if (!entry.indices.includes(idx))
38
+ entry.indices.push(idx);
39
+ return;
40
+ }
41
+ index.set(key, { indices: [idx] });
42
+ }
43
+ function findLastCompactMarkerEntryIdx(entries) {
44
+ for (let i = entries.length - 1; i >= 0; i--) {
45
+ if (entries[i].type === "compact_marker" && !entries[i].discarded)
46
+ return i;
47
+ }
48
+ return -1;
49
+ }
50
+ function collectNearbyLogContextIds(entries, minIdx, maxIdx) {
51
+ const ids = [];
52
+ const seen = new Set();
53
+ const start = Math.max(0, minIdx - 2);
54
+ const end = Math.min(entries.length - 1, maxIdx + 2);
55
+ for (let i = start; i <= end; i++) {
56
+ const ctxId = getLogContextId(entries[i]);
57
+ if (!ctxId || seen.has(ctxId))
58
+ continue;
59
+ seen.add(ctxId);
60
+ ids.push(ctxId);
61
+ }
62
+ return ids;
63
+ }
64
+ function parseOperations(args) {
65
+ const operations = args["operations"] ?? [];
66
+ return operations.map((raw) => ({
67
+ context_ids: (raw["context_ids"] ?? []).map(String),
68
+ summary: typeof raw["summary"] === "string" ? raw["summary"] : "",
69
+ reason: typeof raw["reason"] === "string" && raw["reason"].trim()
70
+ ? raw["reason"]
71
+ : undefined,
72
+ }));
73
+ }
74
+ function validateLogOperation(op, spatialIndex, entries, lastCompactMarkerIdx) {
75
+ const { context_ids, summary } = op;
76
+ if (!context_ids.length) {
77
+ return { valid: false, error: "Empty context_ids array." };
78
+ }
79
+ if (!summary.trim()) {
80
+ return { valid: false, error: "Empty summary. Provide a non-empty summary string." };
81
+ }
82
+ for (const id of context_ids) {
83
+ if (!spatialIndex.has(id)) {
84
+ return { valid: false, error: `context_id "${id}" not found.` };
85
+ }
86
+ }
87
+ const allIndices = new Set();
88
+ for (const id of context_ids) {
89
+ for (const idx of spatialIndex.get(id).indices) {
90
+ allIndices.add(idx);
91
+ }
92
+ }
93
+ const sorted = [...allIndices].sort((a, b) => a - b);
94
+ const minIdx = sorted[0];
95
+ const maxIdx = sorted[sorted.length - 1];
96
+ if (lastCompactMarkerIdx >= 0 && minIdx <= lastCompactMarkerIdx) {
97
+ return {
98
+ valid: false,
99
+ error: "context_id(s) include entries before the last compact marker (not visible to the model).",
100
+ };
101
+ }
102
+ for (let i = minIdx; i <= maxIdx; i++) {
103
+ if (allIndices.has(i))
104
+ continue;
105
+ if (isTransparentLogEntry(entries[i]))
106
+ continue;
107
+ const nearbyIds = collectNearbyLogContextIds(entries, minIdx, maxIdx);
108
+ return {
109
+ valid: false,
110
+ error: `Not spatially contiguous. Current spatial order near that region: ` +
111
+ `${nearbyIds.join(", ")} — did you mean [${context_ids.join(", ")}] ` +
112
+ `to include the gaps, or split into separate operations?`,
113
+ };
114
+ }
115
+ return { valid: true, mergeRange: [minIdx, maxIdx] };
116
+ }
117
+ function executeLogOperation(op, entries, allocateContextId, allocateLogId, turnIndex, validation) {
118
+ const [startIdx, endIdx] = validation.mergeRange;
119
+ const newContextId = allocateContextId();
120
+ const summaryEntryId = allocateLogId();
121
+ let summaryDepth = 1;
122
+ const summarizedContextIds = [];
123
+ for (let i = startIdx; i <= endIdx; i++) {
124
+ const entry = entries[i];
125
+ if (entry.type === "summary") {
126
+ const depth = Number(entry.meta["summaryDepth"] ?? 1);
127
+ summaryDepth = Math.max(summaryDepth, depth + 1);
128
+ }
129
+ const ctxId = getLogContextId(entry);
130
+ if (ctxId && !summarizedContextIds.includes(ctxId)) {
131
+ summarizedContextIds.push(ctxId);
132
+ }
133
+ }
134
+ let display = `[Summary of ${op.context_ids.join(", ")} ]\n`;
135
+ display = display.replace(" )", ")");
136
+ if (op.reason) {
137
+ display += `Reason: ${op.reason}\n`;
138
+ }
139
+ const content = `${display}Summary: ${op.summary}`;
140
+ display += `Summary: ${op.summary}`;
141
+ const summaryEntry = createSummary(summaryEntryId, turnIndex, display, content, newContextId, summarizedContextIds, summaryDepth);
142
+ for (let i = startIdx; i <= endIdx; i++) {
143
+ if (entries[i].discarded)
144
+ continue;
145
+ entries[i].summarized = true;
146
+ entries[i].summarizedBy = summaryEntryId;
147
+ }
148
+ entries.splice(startIdx, 0, summaryEntry);
149
+ return {
150
+ success: true,
151
+ contextIds: op.context_ids,
152
+ newContextId,
153
+ };
154
+ }
155
+ function formatExecutionOutput(ops, results) {
156
+ const succeeded = results.filter((r) => r.success).length;
157
+ const failed = results.filter((r) => !r.success).length;
158
+ const lines = [];
159
+ lines.push(`Operations: ${ops.length} submitted, ${succeeded} succeeded, ${failed} failed.`);
160
+ lines.push("");
161
+ for (const result of results) {
162
+ const idsLabel = result.contextIds.join(", ");
163
+ if (result.success) {
164
+ lines.push(`\u2713 [context_ids: ${idsLabel}] \u2192 Replaced with context_id ${String(result.newContextId)}.`);
165
+ }
166
+ else {
167
+ lines.push(`\u2717 [context_ids: ${idsLabel}] \u2192 Error: ${result.error}`);
168
+ }
169
+ }
170
+ return lines.join("\n");
171
+ }
172
+ /**
173
+ * Truncate long summary text in projected tool arguments.
174
+ * The tool result still keeps the full summary; this only shrinks provider input.
175
+ */
176
+ export function truncateSummaryText(summary, newContextId) {
177
+ if (summary.length <= 100)
178
+ return summary;
179
+ let cutPoint = 100;
180
+ const spaceIdx = summary.indexOf(" ", 100);
181
+ if (spaceIdx >= 0 && spaceIdx <= 150) {
182
+ cutPoint = spaceIdx;
183
+ }
184
+ else {
185
+ cutPoint = Math.min(summary.length, 150);
186
+ }
187
+ const kept = summary.slice(0, cutPoint);
188
+ const ctxRef = newContextId !== undefined ? ` in context_id ${String(newContextId)}` : "";
189
+ return `${kept}...{Truncated, first ${cutPoint} chars kept, full version${ctxRef}}`;
190
+ }
191
+ export function execSummarizeContextOnLog(args, entries, contextIdAllocator, logIdAllocator, turnIndex) {
192
+ const ops = parseOperations(args);
193
+ if (!ops.length) {
194
+ const results = [{
195
+ success: false,
196
+ contextIds: [],
197
+ error: "Error: no operations provided.",
198
+ }];
199
+ return {
200
+ output: "Error: no operations provided.",
201
+ results,
202
+ };
203
+ }
204
+ const spatialIndex = buildLogSpatialIndex(entries);
205
+ const lastCompactMarkerIdx = findLastCompactMarkerEntryIdx(entries);
206
+ const validations = [];
207
+ const orderedResults = new Array(ops.length);
208
+ const claimedIds = new Set();
209
+ for (let opIndex = 0; opIndex < ops.length; opIndex++) {
210
+ const op = ops[opIndex];
211
+ const duplicates = op.context_ids.filter((id) => claimedIds.has(id));
212
+ if (duplicates.length > 0) {
213
+ orderedResults[opIndex] = {
214
+ success: false,
215
+ contextIds: op.context_ids,
216
+ error: `context_id(s) ${duplicates.map((d) => `"${d}"`).join(", ")} already referenced by another operation in this call.`,
217
+ };
218
+ continue;
219
+ }
220
+ const validation = validateLogOperation(op, spatialIndex, entries, lastCompactMarkerIdx);
221
+ if (!validation.valid) {
222
+ orderedResults[opIndex] = {
223
+ success: false,
224
+ contextIds: op.context_ids,
225
+ error: validation.error,
226
+ };
227
+ continue;
228
+ }
229
+ validations.push({ op, validation, opIndex });
230
+ for (const id of op.context_ids)
231
+ claimedIds.add(id);
232
+ }
233
+ validations.sort((a, b) => b.validation.mergeRange[0] - a.validation.mergeRange[0]);
234
+ for (const { op, validation, opIndex } of validations) {
235
+ orderedResults[opIndex] = executeLogOperation(op, entries, contextIdAllocator, logIdAllocator, turnIndex, validation);
236
+ }
237
+ const finalizedResults = orderedResults.map((result, idx) => result ?? ({
238
+ success: false,
239
+ contextIds: ops[idx].context_ids,
240
+ error: "Internal error: missing operation result.",
241
+ }));
242
+ return {
243
+ output: formatExecutionOutput(ops, finalizedResults),
244
+ results: finalizedResults,
245
+ };
246
+ }
247
+ //# sourceMappingURL=summarize-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarize-context.js","sourceRoot":"","sources":["../src/summarize-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAiB,MAAM,gBAAgB,CAAC;AA8B9D,SAAS,eAAe,CAAC,KAAe;IACtC,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,KAAK,GAAI,KAAK,CAAC,IAAgC,CAAC,WAAW,CAAC,CAAC;IACnE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAe;IAC5C,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IACrD,OAAO,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AACzC,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAmB;IAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;IACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK;YAAE,SAAS;QAErB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;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AC,CAAC,CAAC;IACtF,KAAK,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC;QACtD,cAAc,CAAC,OAAO,CAAC,GAAG,mBAAmB,CAC3C,EAAE,EACF,OAAO,EACP,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,UAAU,CACX,CAAC;IACJ,CAAC;IAED,MAAM,gBAAgB,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC;QACtE,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,WAAW;QAChC,KAAK,EAAE,2CAA2C;KACnD,CAAC,CAAC,CAAC;IAEJ,OAAO;QACL,MAAM,EAAE,qBAAqB,CAAC,GAAG,EAAE,gBAAgB,CAAC;QACpD,OAAO,EAAE,gBAAgB;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Agent template loader with multi-file prompt assembly.
3
+ *
4
+ * Provides `loadTemplate` / `loadTemplates` for agent templates.
5
+ *
6
+ * Template folder layout:
7
+ *
8
+ * agent_templates/
9
+ * +-- main/
10
+ * | +-- agent.yaml # required
11
+ * | +-- system_prompt.md # referenced by system_prompt_file
12
+ * | +-- knowledge/ # optional -- files appended to system prompt
13
+ * | +-- style_guide.md
14
+ * +-- executor/
15
+ * +-- agent.yaml
16
+ * +-- system_prompt.md
17
+ *
18
+ * Prompt assembly pipeline (per template):
19
+ *
20
+ * 1. Read core system prompt from system_prompt.md
21
+ * 2. Assemble tool prompts from prompts/tools/{name}.md
22
+ * (ordered by TOOL_PROMPT_ORDER, filtered by template's declared tools)
23
+ * 3. Assemble section prompts from prompts/sections/{name}.md
24
+ * (controlled by template's prompt_sections field)
25
+ * 4. Append knowledge/ files (existing mechanism)
26
+ */
27
+ import { Agent } from "../agents/agent.js";
28
+ import type { Config } from "../config.js";
29
+ import type { MCPClientManager } from "../mcp-client.js";
30
+ /**
31
+ * Canonical ordering for tool prompt assembly.
32
+ * Tools not in this list are appended alphabetically after these.
33
+ */
34
+ export declare const TOOL_PROMPT_ORDER: string[];
35
+ /**
36
+ * Paired tool dependencies.
37
+ * If a tool (key) is in the list, all its required companions (value) must also be present.
38
+ */
39
+ export declare const TOOL_REQUIRES: Record<string, string[]>;
40
+ /**
41
+ * Default tools for custom templates that omit `tools` in agent.yaml.
42
+ * Same set as the executor template.
43
+ */
44
+ export declare const EXECUTOR_DEFAULT_TOOLS: string[];
45
+ /**
46
+ * Load a single agent template from `templateDir`.
47
+ *
48
+ * @param templateDir Path to the template folder (must contain `agent.yaml`).
49
+ * @param config Global Config instance (provides model resolution).
50
+ * @param nameOverride If given, replaces the `name` field from the YAML.
51
+ * @param mcpManager Optional MCP client manager for MCP tool resolution.
52
+ * @param promptsDirs Ordered list of `prompts/` directories (user override first, bundled second).
53
+ * If omitted or empty, no tool/section prompts are assembled.
54
+ * @returns Fully constructed Agent, ready to use.
55
+ */
56
+ export declare function loadTemplate(templateDir: string, config: Config, nameOverride?: string, mcpManager?: MCPClientManager, promptsDirs?: string[]): Agent;
57
+ /**
58
+ * Scan template directories and load all templates with layered override.
59
+ *
60
+ * When both `bundledRoot` and `userRoot` are provided, user templates override
61
+ * bundled templates with the same folder name. User-only templates are also loaded.
62
+ *
63
+ * @param bundledRoot Bundled templates root (always available from the package).
64
+ * @param config Global Config instance.
65
+ * @param mcpManager Optional MCP client manager.
66
+ * @param promptsDirs Ordered prompts directories (user first, bundled second).
67
+ * @param userRoot Optional user override templates root (~/.longeragent/agent_templates/).
68
+ * @returns `{ name: agent }` record.
69
+ */
70
+ export declare function loadTemplates(bundledRoot: string, config: Config, mcpManager?: MCPClientManager, promptsDirs?: string[], userRoot?: string): Record<string, Agent>;
71
+ /**
72
+ * Validate a template directory without loading it.
73
+ * Returns null if valid, or an error message string if invalid.
74
+ */
75
+ export declare function validateTemplate(templateDir: string): string | null;
76
+ /**
77
+ * Resolve the prompts/ directory as a sibling of the templates root.
78
+ * Returns the path if found, or undefined if not.
79
+ */
80
+ export declare function resolvePromptsDir(templatesRoot: string): string | undefined;
81
+ /**
82
+ * Resolve tool names from the `tools` field in agent.yaml.
83
+ *
84
+ * - `"all"` → all tools in TOOL_PROMPT_ORDER
85
+ * - Array of names → as-is
86
+ * - Absent / null → EXECUTOR_DEFAULT_TOOLS (for custom templates)
87
+ */
88
+ export declare function resolveToolNames(spec: Record<string, unknown>): string[];
89
+ /**
90
+ * Validate that paired tool dependencies are satisfied.
91
+ */
92
+ export declare function validateToolDependencies(toolNames: string[]): void;
93
+ /**
94
+ * Read and concatenate tool prompt files in canonical order.
95
+ * For each tool, the first matching file across `promptsDirs` is used (user override first).
96
+ * Tools without a corresponding prompt file are silently skipped.
97
+ */
98
+ export declare function assembleToolPrompts(toolNames: string[], promptsDirs: string[]): string;
99
+ /**
100
+ * Read and concatenate section prompt files.
101
+ * For each section, the first matching file across `promptsDirs` is used.
102
+ */
103
+ export declare function assembleSectionPrompts(sections: string[], promptsDirs: string[]): string;
104
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/templates/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAUzD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAiCrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAIlD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAgB1C,CAAC;AAM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