@openacp/cli 2026.331.1 → 2026.331.2

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 (181) hide show
  1. package/README.md +2 -1
  2. package/dist/cli.js +24932 -270
  3. package/dist/cli.js.map +1 -1
  4. package/dist/data/registry-snapshot.json +1 -1
  5. package/dist/index.js +17626 -409
  6. package/dist/index.js.map +1 -1
  7. package/package.json +2 -2
  8. package/dist/adapter-ELG3VRZ3.js +0 -14
  9. package/dist/adapter-ELG3VRZ3.js.map +0 -1
  10. package/dist/agent-catalog-UYD26QDK.js +0 -10
  11. package/dist/agent-catalog-UYD26QDK.js.map +0 -1
  12. package/dist/agent-dependencies-ED2ZTUHG.js +0 -23
  13. package/dist/agent-dependencies-ED2ZTUHG.js.map +0 -1
  14. package/dist/agent-registry-YOGP656W.js +0 -8
  15. package/dist/agent-registry-YOGP656W.js.map +0 -1
  16. package/dist/agent-store-5UHZH2XI.js +0 -8
  17. package/dist/agent-store-5UHZH2XI.js.map +0 -1
  18. package/dist/api-client-PEMHYL5U.js +0 -13
  19. package/dist/api-client-PEMHYL5U.js.map +0 -1
  20. package/dist/api-server-DATG2KBR.js +0 -10
  21. package/dist/api-server-DATG2KBR.js.map +0 -1
  22. package/dist/api-server-L5Z7XACW.js +0 -7
  23. package/dist/api-server-L5Z7XACW.js.map +0 -1
  24. package/dist/autostart-CUPZMKKC.js +0 -22
  25. package/dist/autostart-CUPZMKKC.js.map +0 -1
  26. package/dist/chunk-23SRIVG4.js +0 -50
  27. package/dist/chunk-23SRIVG4.js.map +0 -1
  28. package/dist/chunk-2KT6TROD.js +0 -129
  29. package/dist/chunk-2KT6TROD.js.map +0 -1
  30. package/dist/chunk-2R5XM3ES.js +0 -154
  31. package/dist/chunk-2R5XM3ES.js.map +0 -1
  32. package/dist/chunk-3EWTPOF7.js +0 -51
  33. package/dist/chunk-3EWTPOF7.js.map +0 -1
  34. package/dist/chunk-566W6INH.js +0 -83
  35. package/dist/chunk-566W6INH.js.map +0 -1
  36. package/dist/chunk-5WGVYX3C.js +0 -55
  37. package/dist/chunk-5WGVYX3C.js.map +0 -1
  38. package/dist/chunk-7GXEMMEV.js +0 -44
  39. package/dist/chunk-7GXEMMEV.js.map +0 -1
  40. package/dist/chunk-7U6IZIJP.js +0 -186
  41. package/dist/chunk-7U6IZIJP.js.map +0 -1
  42. package/dist/chunk-7YIKTRSM.js +0 -105
  43. package/dist/chunk-7YIKTRSM.js.map +0 -1
  44. package/dist/chunk-7ZCQF6QM.js +0 -27
  45. package/dist/chunk-7ZCQF6QM.js.map +0 -1
  46. package/dist/chunk-AFKX424Q.js +0 -92
  47. package/dist/chunk-AFKX424Q.js.map +0 -1
  48. package/dist/chunk-BYCJQPMN.js +0 -543
  49. package/dist/chunk-BYCJQPMN.js.map +0 -1
  50. package/dist/chunk-CDAUYTVP.js +0 -41
  51. package/dist/chunk-CDAUYTVP.js.map +0 -1
  52. package/dist/chunk-EWVXSTQK.js +0 -6544
  53. package/dist/chunk-EWVXSTQK.js.map +0 -1
  54. package/dist/chunk-FNRSWA2K.js +0 -1
  55. package/dist/chunk-FNRSWA2K.js.map +0 -1
  56. package/dist/chunk-FPKQYCQS.js +0 -776
  57. package/dist/chunk-FPKQYCQS.js.map +0 -1
  58. package/dist/chunk-IZ5UEZF7.js +0 -138
  59. package/dist/chunk-IZ5UEZF7.js.map +0 -1
  60. package/dist/chunk-K6UY5M75.js +0 -653
  61. package/dist/chunk-K6UY5M75.js.map +0 -1
  62. package/dist/chunk-KGAQW6F4.js +0 -106
  63. package/dist/chunk-KGAQW6F4.js.map +0 -1
  64. package/dist/chunk-LGFWH3AE.js +0 -26
  65. package/dist/chunk-LGFWH3AE.js.map +0 -1
  66. package/dist/chunk-LRV56K2M.js +0 -4106
  67. package/dist/chunk-LRV56K2M.js.map +0 -1
  68. package/dist/chunk-MDJHCCFS.js +0 -485
  69. package/dist/chunk-MDJHCCFS.js.map +0 -1
  70. package/dist/chunk-MLF4W5R6.js +0 -101
  71. package/dist/chunk-MLF4W5R6.js.map +0 -1
  72. package/dist/chunk-NHD5XDD2.js +0 -686
  73. package/dist/chunk-NHD5XDD2.js.map +0 -1
  74. package/dist/chunk-NJX75BLK.js +0 -259
  75. package/dist/chunk-NJX75BLK.js.map +0 -1
  76. package/dist/chunk-NOEAJNTK.js +0 -156
  77. package/dist/chunk-NOEAJNTK.js.map +0 -1
  78. package/dist/chunk-ON7HB5O7.js +0 -58
  79. package/dist/chunk-ON7HB5O7.js.map +0 -1
  80. package/dist/chunk-OSBZXY2W.js +0 -126
  81. package/dist/chunk-OSBZXY2W.js.map +0 -1
  82. package/dist/chunk-OYSAN7UX.js +0 -15
  83. package/dist/chunk-OYSAN7UX.js.map +0 -1
  84. package/dist/chunk-P3HHJANC.js +0 -209
  85. package/dist/chunk-P3HHJANC.js.map +0 -1
  86. package/dist/chunk-R2YLDQLI.js +0 -1115
  87. package/dist/chunk-R2YLDQLI.js.map +0 -1
  88. package/dist/chunk-R6KZYF7D.js +0 -231
  89. package/dist/chunk-R6KZYF7D.js.map +0 -1
  90. package/dist/chunk-S64CB6J3.js +0 -98
  91. package/dist/chunk-S64CB6J3.js.map +0 -1
  92. package/dist/chunk-SSLVNCEA.js +0 -236
  93. package/dist/chunk-SSLVNCEA.js.map +0 -1
  94. package/dist/chunk-TGP34LQN.js +0 -681
  95. package/dist/chunk-TGP34LQN.js.map +0 -1
  96. package/dist/chunk-VUSCVRJL.js +0 -229
  97. package/dist/chunk-VUSCVRJL.js.map +0 -1
  98. package/dist/chunk-W26AUH5B.js +0 -61
  99. package/dist/chunk-W26AUH5B.js.map +0 -1
  100. package/dist/chunk-WQCJTU2C.js +0 -84
  101. package/dist/chunk-WQCJTU2C.js.map +0 -1
  102. package/dist/chunk-XRJUS6FE.js +0 -53
  103. package/dist/chunk-XRJUS6FE.js.map +0 -1
  104. package/dist/chunk-YZCKSNRN.js +0 -453
  105. package/dist/chunk-YZCKSNRN.js.map +0 -1
  106. package/dist/chunk-ZIRH6QWW.js +0 -69
  107. package/dist/chunk-ZIRH6QWW.js.map +0 -1
  108. package/dist/chunk-ZSLHHQPQ.js +0 -282
  109. package/dist/chunk-ZSLHHQPQ.js.map +0 -1
  110. package/dist/config-X4UP7H6R.js +0 -13
  111. package/dist/config-X4UP7H6R.js.map +0 -1
  112. package/dist/config-editor-7BENRVG5.js +0 -11
  113. package/dist/config-editor-7BENRVG5.js.map +0 -1
  114. package/dist/config-registry-M3FFWEVM.js +0 -18
  115. package/dist/config-registry-M3FFWEVM.js.map +0 -1
  116. package/dist/context-FVGCU5TI.js +0 -9
  117. package/dist/context-FVGCU5TI.js.map +0 -1
  118. package/dist/core-plugins-JSY2I44L.js +0 -25
  119. package/dist/core-plugins-JSY2I44L.js.map +0 -1
  120. package/dist/daemon-UOSRDEXW.js +0 -34
  121. package/dist/daemon-UOSRDEXW.js.map +0 -1
  122. package/dist/dev-loader-7P3HZCIA.js +0 -37
  123. package/dist/dev-loader-7P3HZCIA.js.map +0 -1
  124. package/dist/doctor-6DLACBR4.js +0 -10
  125. package/dist/doctor-6DLACBR4.js.map +0 -1
  126. package/dist/file-service-FQQYME7M.js +0 -8
  127. package/dist/file-service-FQQYME7M.js.map +0 -1
  128. package/dist/install-cloudflared-LNS5L5FR.js +0 -33
  129. package/dist/install-cloudflared-LNS5L5FR.js.map +0 -1
  130. package/dist/install-context-KZO5FR4D.js +0 -78
  131. package/dist/install-context-KZO5FR4D.js.map +0 -1
  132. package/dist/install-jq-SN4IA5K4.js +0 -31
  133. package/dist/install-jq-SN4IA5K4.js.map +0 -1
  134. package/dist/instance-context-FLCE7VZ4.js +0 -13
  135. package/dist/instance-context-FLCE7VZ4.js.map +0 -1
  136. package/dist/instance-registry-SW5FWKHO.js +0 -7
  137. package/dist/instance-registry-SW5FWKHO.js.map +0 -1
  138. package/dist/integrate-JIEZYDOR.js +0 -371
  139. package/dist/integrate-JIEZYDOR.js.map +0 -1
  140. package/dist/log-YZ243M5G.js +0 -25
  141. package/dist/log-YZ243M5G.js.map +0 -1
  142. package/dist/main-D7M2AKRM.js +0 -697
  143. package/dist/main-D7M2AKRM.js.map +0 -1
  144. package/dist/menu-ALFN37IR.js +0 -15
  145. package/dist/menu-ALFN37IR.js.map +0 -1
  146. package/dist/notifications-MO23S7S3.js +0 -8
  147. package/dist/notifications-MO23S7S3.js.map +0 -1
  148. package/dist/plugin-create-HFKS23JY.js +0 -968
  149. package/dist/plugin-create-HFKS23JY.js.map +0 -1
  150. package/dist/plugin-installer-VSTYZSXC.js +0 -9
  151. package/dist/plugin-installer-VSTYZSXC.js.map +0 -1
  152. package/dist/plugin-registry-6J3YSFHF.js +0 -7
  153. package/dist/plugin-registry-6J3YSFHF.js.map +0 -1
  154. package/dist/plugin-search-MGKAL5JM.js +0 -39
  155. package/dist/plugin-search-MGKAL5JM.js.map +0 -1
  156. package/dist/post-upgrade-F4YPMTUT.js +0 -79
  157. package/dist/post-upgrade-F4YPMTUT.js.map +0 -1
  158. package/dist/read-text-file-DJBTITIB.js +0 -7
  159. package/dist/read-text-file-DJBTITIB.js.map +0 -1
  160. package/dist/registry-client-GTBWLXYU.js +0 -7
  161. package/dist/registry-client-GTBWLXYU.js.map +0 -1
  162. package/dist/security-O4XGN2CM.js +0 -8
  163. package/dist/security-O4XGN2CM.js.map +0 -1
  164. package/dist/settings-manager-B4UN2LAC.js +0 -7
  165. package/dist/settings-manager-B4UN2LAC.js.map +0 -1
  166. package/dist/setup-44WLBIOT.js +0 -989
  167. package/dist/setup-44WLBIOT.js.map +0 -1
  168. package/dist/speech-GHTSWDAN.js +0 -9
  169. package/dist/speech-GHTSWDAN.js.map +0 -1
  170. package/dist/suggest-RST5VOHB.js +0 -36
  171. package/dist/suggest-RST5VOHB.js.map +0 -1
  172. package/dist/telegram-D7ASLVEB.js +0 -7
  173. package/dist/telegram-D7ASLVEB.js.map +0 -1
  174. package/dist/tunnel-ALJDPFDQ.js +0 -10
  175. package/dist/tunnel-ALJDPFDQ.js.map +0 -1
  176. package/dist/tunnel-service-TBAHDXMF.js +0 -755
  177. package/dist/tunnel-service-TBAHDXMF.js.map +0 -1
  178. package/dist/validators-GITLOFXC.js +0 -11
  179. package/dist/validators-GITLOFXC.js.map +0 -1
  180. package/dist/version-AXXV6IV2.js +0 -15
  181. package/dist/version-AXXV6IV2.js.map +0 -1
@@ -1,776 +0,0 @@
1
- import {
2
- ContextManager,
3
- EntireProvider
4
- } from "./chunk-BYCJQPMN.js";
5
- import {
6
- DEFAULT_MAX_TOKENS,
7
- TOKENS_PER_TURN_ESTIMATE
8
- } from "./chunk-NJX75BLK.js";
9
-
10
- // src/plugins/context/index.ts
11
- import * as path2 from "path";
12
-
13
- // src/plugins/context/history/history-context-builder.ts
14
- function selectLevel(turnCount) {
15
- if (turnCount <= 10) return "full";
16
- if (turnCount <= 25) return "balanced";
17
- return "compact";
18
- }
19
- function estimateTokens(text) {
20
- return Math.floor(text.length / 4);
21
- }
22
- function buildHistoryMarkdown(turns, mode) {
23
- if (turns.length === 0) return "";
24
- switch (mode) {
25
- case "full":
26
- return buildFull(turns);
27
- case "balanced":
28
- return buildBalanced(turns);
29
- case "compact":
30
- return buildCompact(turns);
31
- }
32
- }
33
- function buildFull(turns) {
34
- const out = [];
35
- let userIndex = 0;
36
- for (const turn of turns) {
37
- if (turn.role === "user") {
38
- userIndex++;
39
- out.push(`**User [${userIndex}]:**`);
40
- out.push(turn.content ?? "");
41
- if (turn.attachments?.length) {
42
- out.push(turn.attachments.map((a) => `[${a.type}: ${a.fileName}]`).join(" "));
43
- }
44
- out.push("");
45
- } else if (turn.role === "assistant" && turn.steps?.length) {
46
- out.push("**Assistant:**");
47
- for (const step of turn.steps) {
48
- out.push(renderStepFull(step));
49
- }
50
- if (turn.usage) {
51
- const parts = [];
52
- if (turn.usage.tokensUsed) parts.push(`${turn.usage.tokensUsed.toLocaleString()} tokens`);
53
- if (turn.usage.cost) parts.push(`$${turn.usage.cost.amount.toFixed(4)}`);
54
- if (parts.length) out.push(`**Usage**: ${parts.join(", ")}`);
55
- }
56
- out.push("");
57
- out.push("---");
58
- out.push("");
59
- }
60
- }
61
- return out.join("\n");
62
- }
63
- function renderStepFull(step) {
64
- switch (step.type) {
65
- case "thinking":
66
- return `> **Thinking**: ${step.content}
67
- `;
68
- case "text":
69
- return `${step.content}
70
- `;
71
- case "tool_call":
72
- return renderToolCallFull(step);
73
- case "plan":
74
- return renderPlan(step.entries);
75
- case "image":
76
- return `[Image: ${step.mimeType}]
77
- `;
78
- case "audio":
79
- return `[Audio: ${step.mimeType}]
80
- `;
81
- case "resource":
82
- return `[Resource: ${step.name}] ${step.uri}
83
- `;
84
- case "resource_link":
85
- return `[Resource Link: ${step.name}] ${step.uri}
86
- `;
87
- case "mode_change":
88
- return `*Mode changed to: ${step.modeId}*
89
- `;
90
- case "config_change":
91
- return `*Config ${step.configId} set to: ${step.value}*
92
- `;
93
- }
94
- }
95
- function renderToolCallFull(step) {
96
- const lines = [];
97
- const loc = step.locations?.[0];
98
- const locStr = loc ? loc.line ? `${loc.path}:${loc.line}` : loc.path : "";
99
- if (step.diff) {
100
- lines.push(`**[${step.name}]** \`${locStr || step.diff.path}\``);
101
- lines.push("```diff");
102
- if (step.diff.oldText) {
103
- for (const line of step.diff.oldText.split("\n")) lines.push(`- ${line}`);
104
- }
105
- for (const line of step.diff.newText.split("\n")) lines.push(`+ ${line}`);
106
- lines.push("```");
107
- } else {
108
- lines.push(`**[${step.name}]** \`${locStr}\``);
109
- }
110
- if (step.permission) {
111
- lines.push(`*Permission: ${step.permission.outcome}*`);
112
- }
113
- lines.push("");
114
- return lines.join("\n");
115
- }
116
- function renderPlan(entries) {
117
- const lines = ["**Plan:**"];
118
- for (const e of entries) {
119
- const icon = e.status === "completed" || e.status === "done" ? "\u2705" : e.status === "in_progress" ? "\u{1F504}" : "\u2B1C";
120
- lines.push(`${icon} ${e.content} (${e.priority})`);
121
- }
122
- lines.push("");
123
- return lines.join("\n");
124
- }
125
- function buildBalanced(turns) {
126
- const out = [];
127
- let userIndex = 0;
128
- for (const turn of turns) {
129
- if (turn.role === "user") {
130
- userIndex++;
131
- out.push(`**User [${userIndex}]:**`);
132
- out.push(turn.content ?? "");
133
- out.push("");
134
- } else if (turn.role === "assistant" && turn.steps?.length) {
135
- out.push("**Assistant:**");
136
- for (const step of turn.steps) {
137
- if (step.type === "thinking") continue;
138
- if (step.type === "text") {
139
- out.push(step.content);
140
- } else if (step.type === "tool_call") {
141
- out.push(renderToolCallBalanced(step));
142
- } else if (step.type === "plan") {
143
- out.push(renderPlan(step.entries));
144
- } else {
145
- out.push(renderStepFull(step));
146
- }
147
- }
148
- out.push("");
149
- out.push("---");
150
- out.push("");
151
- }
152
- }
153
- return out.join("\n");
154
- }
155
- function renderToolCallBalanced(step) {
156
- const loc = step.locations?.[0];
157
- const locStr = loc ? loc.line ? `${loc.path}:${loc.line}` : loc.path : "";
158
- if (step.diff) {
159
- const oldLines = step.diff.oldText?.split("\n").length ?? 0;
160
- const newLines = step.diff.newText.split("\n").length;
161
- return `- ${step.name} \`${locStr || step.diff.path}\` (-${oldLines}/+${newLines} lines)`;
162
- }
163
- return `- ${step.name} \`${locStr}\``;
164
- }
165
- function buildCompact(turns) {
166
- const out = [];
167
- let i = 0;
168
- while (i < turns.length) {
169
- const turn = turns[i];
170
- if (turn.role === "user") {
171
- const userText = (turn.content ?? "").slice(0, 100);
172
- const nextTurn = turns[i + 1];
173
- if (nextTurn?.role === "assistant" && nextTurn.steps?.length) {
174
- const tools = nextTurn.steps.filter((s) => s.type === "tool_call").map((s) => s.name);
175
- const texts = nextTurn.steps.filter((s) => s.type === "text").map((s) => s.content.slice(0, 80));
176
- const parts = [];
177
- if (tools.length) parts.push(tools.join(", "));
178
- if (texts.length) parts.push(texts.join(" "));
179
- out.push(`User: ${userText} \u2192 Assistant: ${parts.join(" | ")}`);
180
- i += 2;
181
- } else {
182
- out.push(`User: ${userText}`);
183
- i++;
184
- }
185
- } else {
186
- i++;
187
- }
188
- }
189
- return out.join("\n");
190
- }
191
-
192
- // src/plugins/context/history/history-provider.ts
193
- var EMPTY_RESULT = {
194
- markdown: "",
195
- tokenEstimate: 0,
196
- sessionCount: 0,
197
- totalTurns: 0,
198
- mode: "full",
199
- truncated: false,
200
- timeRange: { start: "", end: "" }
201
- };
202
- var HistoryProvider = class {
203
- constructor(store, getSessionRecords) {
204
- this.store = store;
205
- this.getSessionRecords = getSessionRecords;
206
- }
207
- name = "local";
208
- async isAvailable(_repoPath) {
209
- return true;
210
- }
211
- async listSessions(query) {
212
- if (!this.isSupportedType(query.type)) {
213
- return { sessions: [], estimatedTokens: 0 };
214
- }
215
- const candidates = await this.resolveCandidates(query);
216
- const sessions = [];
217
- let estimatedTokens = 0;
218
- for (const record of candidates) {
219
- const history = await this.store.read(record.sessionId);
220
- if (!history) continue;
221
- const turnCount = history.turns.length;
222
- const tokenEstimate = turnCount * TOKENS_PER_TURN_ESTIMATE;
223
- sessions.push(this.toSessionInfo(record, turnCount));
224
- estimatedTokens += tokenEstimate;
225
- }
226
- return { sessions, estimatedTokens };
227
- }
228
- async buildContext(query, options) {
229
- if (!this.isSupportedType(query.type)) {
230
- return { ...EMPTY_RESULT };
231
- }
232
- const maxTokens = options?.maxTokens ?? DEFAULT_MAX_TOKENS;
233
- const candidates = await this.resolveCandidates(query, options?.limit);
234
- const loaded = [];
235
- for (const record of candidates) {
236
- const history = await this.store.read(record.sessionId);
237
- if (history) {
238
- loaded.push({ record, history });
239
- }
240
- }
241
- if (loaded.length === 0) {
242
- return { ...EMPTY_RESULT };
243
- }
244
- const totalTurns = loaded.reduce((sum, s) => sum + s.history.turns.length, 0);
245
- const labelAgent = options?.labelAgent ?? false;
246
- let mode = selectLevel(totalTurns);
247
- let markdown = this.buildMergedMarkdown(loaded, mode, query, labelAgent);
248
- let tokenEstimate = estimateTokens(markdown);
249
- if (tokenEstimate > maxTokens && mode !== "compact") {
250
- mode = "compact";
251
- markdown = this.buildMergedMarkdown(loaded, mode, query, labelAgent);
252
- tokenEstimate = estimateTokens(markdown);
253
- }
254
- let truncated = false;
255
- let activeSessions = [...loaded];
256
- while (tokenEstimate > maxTokens && activeSessions.length > 1) {
257
- activeSessions = activeSessions.slice(0, activeSessions.length - 1);
258
- markdown = this.buildMergedMarkdown(activeSessions, mode, query, labelAgent);
259
- tokenEstimate = estimateTokens(markdown);
260
- truncated = true;
261
- }
262
- const timeRange = this.computeTimeRange(activeSessions.map((s) => s.record));
263
- return {
264
- markdown,
265
- tokenEstimate,
266
- sessionCount: activeSessions.length,
267
- totalTurns: activeSessions.reduce((sum, s) => sum + s.history.turns.length, 0),
268
- mode,
269
- truncated,
270
- timeRange
271
- };
272
- }
273
- // ─── Private helpers ─────────────────────────────────────────────────────────
274
- isSupportedType(type) {
275
- return type === "session" || type === "latest";
276
- }
277
- async resolveCandidates(query, limit) {
278
- const all = this.getSessionRecords();
279
- if (query.type === "session") {
280
- const found = all.find((r) => r.sessionId === query.value);
281
- return found ? [found] : [];
282
- }
283
- const n = limit ?? (parseInt(query.value, 10) || 5);
284
- const sorted = [...all].sort(
285
- (a, b) => new Date(b.lastActiveAt).getTime() - new Date(a.lastActiveAt).getTime()
286
- );
287
- return sorted.slice(0, n);
288
- }
289
- toSessionInfo(record, turnCount) {
290
- return {
291
- checkpointId: "",
292
- sessionIndex: "",
293
- transcriptPath: "",
294
- createdAt: record.createdAt,
295
- endedAt: record.lastActiveAt,
296
- branch: "",
297
- agent: record.agentName,
298
- turnCount,
299
- filesTouched: [],
300
- sessionId: record.sessionId
301
- };
302
- }
303
- buildMergedMarkdown(sessions, mode, query, labelAgent = false) {
304
- if (sessions.length === 0) return "";
305
- const totalTurns = sessions.reduce((sum, s) => sum + s.history.turns.length, 0);
306
- const title = query.type === "session" ? query.value : `latest ${sessions.length} sessions`;
307
- const parts = [];
308
- parts.push(`# Conversation History \u2014 ${title}`);
309
- parts.push(`${sessions.length} sessions | ${totalTurns} turns | mode: ${mode}`);
310
- parts.push("");
311
- for (let i = 0; i < sessions.length; i++) {
312
- const { record, history } = sessions[i];
313
- parts.push(`## Session ${i + 1} \u2014 ${record.agentName} \xB7 ${record.sessionId} (${history.turns.length} turns)`);
314
- parts.push("");
315
- if (labelAgent && history.turns.length > 0) {
316
- const agentTimeline = this.buildAgentTimeline(record);
317
- const labeledMd = this.buildLabeledHistoryMarkdown(history.turns, mode, agentTimeline);
318
- if (labeledMd) {
319
- parts.push(labeledMd);
320
- }
321
- } else {
322
- const sessionMd = buildHistoryMarkdown(history.turns, mode);
323
- if (sessionMd) {
324
- parts.push(sessionMd);
325
- }
326
- }
327
- }
328
- parts.push(
329
- "> **Note:** This conversation history may contain outdated information. Verify current state before acting on past context."
330
- );
331
- return parts.join("\n");
332
- }
333
- /**
334
- * Build a timeline of agent boundaries from the session record.
335
- * Returns sorted entries: [{ agentName, startedAt }] where startedAt is the
336
- * ISO timestamp when that agent started handling the session.
337
- *
338
- * The first agent runs from session creation until the first switch.
339
- * Each agentSwitchHistory entry records when the *previous* agent was switched away,
340
- * so the next agent starts at that switchedAt timestamp.
341
- */
342
- buildAgentTimeline(record) {
343
- const timeline = [];
344
- const firstAgentName = record.firstAgent ?? record.agentName;
345
- timeline.push({ agentName: firstAgentName, switchedAt: 0 });
346
- if (record.agentSwitchHistory && record.agentSwitchHistory.length > 0) {
347
- for (let i = 0; i < record.agentSwitchHistory.length; i++) {
348
- const entry = record.agentSwitchHistory[i];
349
- const switchTime = new Date(entry.switchedAt).getTime();
350
- const nextAgent = i < record.agentSwitchHistory.length - 1 ? record.agentSwitchHistory[i + 1].agentName : record.agentName;
351
- timeline.push({ agentName: nextAgent, switchedAt: switchTime });
352
- }
353
- }
354
- return timeline;
355
- }
356
- /**
357
- * Determine which agent produced a turn based on its timestamp and the agent timeline.
358
- */
359
- resolveAgentForTurn(turnTimestamp, timeline) {
360
- const turnTime = new Date(turnTimestamp).getTime();
361
- for (let i = timeline.length - 1; i >= 0; i--) {
362
- if (turnTime >= timeline[i].switchedAt) {
363
- return timeline[i].agentName;
364
- }
365
- }
366
- return timeline[0].agentName;
367
- }
368
- /**
369
- * Build history markdown with agent labels inserted at agent boundaries.
370
- */
371
- buildLabeledHistoryMarkdown(turns, mode, agentTimeline) {
372
- if (agentTimeline.length <= 1) {
373
- const label = `### [${agentTimeline[0]?.agentName ?? "unknown"}]
374
- `;
375
- const md = buildHistoryMarkdown(turns, mode);
376
- return md ? label + "\n" + md : label;
377
- }
378
- const segments = [];
379
- let currentAgent = "";
380
- for (const turn of turns) {
381
- const agent = this.resolveAgentForTurn(turn.timestamp, agentTimeline);
382
- if (agent !== currentAgent) {
383
- segments.push({ agentName: agent, turns: [] });
384
- currentAgent = agent;
385
- }
386
- segments[segments.length - 1].turns.push(turn);
387
- }
388
- const parts = [];
389
- for (const segment of segments) {
390
- parts.push(`### [${segment.agentName}]`);
391
- parts.push("");
392
- const md = buildHistoryMarkdown(segment.turns, mode);
393
- if (md) {
394
- parts.push(md);
395
- }
396
- }
397
- return parts.join("\n");
398
- }
399
- computeTimeRange(records) {
400
- if (records.length === 0) return { start: "", end: "" };
401
- const dates = records.map((r) => r.createdAt).filter(Boolean);
402
- const ends = records.map((r) => r.lastActiveAt).filter(Boolean);
403
- const start = dates.sort()[0] ?? "";
404
- const end = ends.sort().reverse()[0] ?? "";
405
- return { start, end };
406
- }
407
- };
408
-
409
- // src/plugins/context/history/history-recorder.ts
410
- function toHistoryAttachment(att) {
411
- return {
412
- type: att.type,
413
- fileName: att.fileName,
414
- mimeType: att.mimeType,
415
- size: att.size
416
- };
417
- }
418
- function extractDiff(content) {
419
- if (!Array.isArray(content)) return null;
420
- for (const item of content) {
421
- if (item && typeof item === "object" && item.type === "diff") {
422
- const d = item;
423
- if (typeof d.path === "string" && typeof d.newText === "string") {
424
- const result = {
425
- path: d.path,
426
- newText: d.newText
427
- };
428
- if (typeof d.oldText === "string") result.oldText = d.oldText;
429
- return result;
430
- }
431
- }
432
- }
433
- return null;
434
- }
435
- function extractLocations(locations) {
436
- if (!Array.isArray(locations)) return void 0;
437
- const result = [];
438
- for (const loc of locations) {
439
- if (loc && typeof loc === "object" && typeof loc.path === "string") {
440
- const entry = { path: loc.path };
441
- if (typeof loc.line === "number") entry.line = loc.line;
442
- result.push(entry);
443
- }
444
- }
445
- return result.length > 0 ? result : void 0;
446
- }
447
- var IGNORED_TYPES = /* @__PURE__ */ new Set([
448
- "session_end",
449
- "error",
450
- "system_message",
451
- "commands_update",
452
- "session_info_update",
453
- "model_update",
454
- "user_message_chunk",
455
- "tts_strip"
456
- ]);
457
- var HistoryRecorder = class {
458
- constructor(store) {
459
- this.store = store;
460
- }
461
- states = /* @__PURE__ */ new Map();
462
- onBeforePrompt(sessionId, text, attachments) {
463
- let state = this.states.get(sessionId);
464
- if (!state) {
465
- state = {
466
- history: { version: 1, sessionId, turns: [] },
467
- currentAssistantTurn: null
468
- };
469
- this.states.set(sessionId, state);
470
- }
471
- const userTurn = {
472
- index: state.history.turns.length,
473
- role: "user",
474
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
475
- content: text
476
- };
477
- if (attachments && attachments.length > 0) {
478
- userTurn.attachments = attachments.map(toHistoryAttachment);
479
- }
480
- state.history.turns.push(userTurn);
481
- const assistantTurn = {
482
- index: state.history.turns.length,
483
- role: "assistant",
484
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
485
- steps: []
486
- };
487
- state.history.turns.push(assistantTurn);
488
- state.currentAssistantTurn = assistantTurn;
489
- }
490
- onAfterEvent(sessionId, event) {
491
- const state = this.states.get(sessionId);
492
- if (!state || !state.currentAssistantTurn) return;
493
- const turn = state.currentAssistantTurn;
494
- const steps = turn.steps;
495
- if (IGNORED_TYPES.has(event.type)) return;
496
- switch (event.type) {
497
- case "text": {
498
- const last = steps[steps.length - 1];
499
- if (last && last.type === "text") {
500
- last.content += event.content;
501
- } else {
502
- steps.push({ type: "text", content: event.content });
503
- }
504
- break;
505
- }
506
- case "thought": {
507
- const last = steps[steps.length - 1];
508
- if (last && last.type === "thinking") {
509
- last.content += event.content;
510
- } else {
511
- steps.push({ type: "thinking", content: event.content });
512
- }
513
- break;
514
- }
515
- case "tool_call": {
516
- const step = {
517
- type: "tool_call",
518
- id: event.id,
519
- name: event.name,
520
- status: event.status
521
- };
522
- if (event.kind) step.kind = event.kind;
523
- steps.push(step);
524
- break;
525
- }
526
- case "tool_update": {
527
- const existing = this.findToolCall(steps, event.id);
528
- if (!existing) break;
529
- existing.status = event.status;
530
- if (event.rawInput !== void 0) existing.input = event.rawInput;
531
- if (event.rawOutput !== void 0) existing.output = event.rawOutput;
532
- if (event.content !== void 0) {
533
- const diff = extractDiff(event.content);
534
- if (diff) existing.diff = diff;
535
- }
536
- if (event.locations !== void 0) {
537
- const locs = extractLocations(event.locations);
538
- if (locs) existing.locations = locs;
539
- }
540
- break;
541
- }
542
- case "plan": {
543
- steps.push({
544
- type: "plan",
545
- entries: event.entries.map((e) => ({
546
- content: e.content,
547
- priority: e.priority,
548
- status: e.status
549
- }))
550
- });
551
- break;
552
- }
553
- case "usage": {
554
- turn.usage = {};
555
- if (event.tokensUsed !== void 0) turn.usage.tokensUsed = event.tokensUsed;
556
- if (event.contextSize !== void 0) turn.usage.contextSize = event.contextSize;
557
- if (event.cost) turn.usage.cost = event.cost;
558
- break;
559
- }
560
- case "image_content": {
561
- steps.push({
562
- type: "image",
563
- mimeType: event.mimeType,
564
- filePath: ""
565
- });
566
- break;
567
- }
568
- case "audio_content": {
569
- steps.push({
570
- type: "audio",
571
- mimeType: event.mimeType,
572
- filePath: ""
573
- });
574
- break;
575
- }
576
- case "resource_content": {
577
- const step = {
578
- type: "resource",
579
- uri: event.uri,
580
- name: event.name
581
- };
582
- if (event.text !== void 0) step.text = event.text;
583
- steps.push(step);
584
- break;
585
- }
586
- case "resource_link": {
587
- const step = {
588
- type: "resource_link",
589
- uri: event.uri,
590
- name: event.name
591
- };
592
- if (event.title !== void 0) step.title = event.title;
593
- if (event.description !== void 0)
594
- step.description = event.description;
595
- steps.push(step);
596
- break;
597
- }
598
- case "current_mode_update": {
599
- steps.push({ type: "mode_change", modeId: event.modeId });
600
- break;
601
- }
602
- case "config_option_update": {
603
- for (const opt of event.options) {
604
- steps.push({
605
- type: "config_change",
606
- configId: opt.id,
607
- value: String(opt.currentValue)
608
- });
609
- }
610
- break;
611
- }
612
- }
613
- }
614
- onPermissionResolved(sessionId, requestId, decision) {
615
- const state = this.states.get(sessionId);
616
- if (!state || !state.currentAssistantTurn) return;
617
- const step = this.findToolCall(state.currentAssistantTurn.steps, requestId);
618
- if (!step) return;
619
- step.permission = { requested: true, outcome: decision };
620
- }
621
- async onTurnEnd(sessionId, stopReason) {
622
- const state = this.states.get(sessionId);
623
- if (!state || !state.currentAssistantTurn) return;
624
- state.currentAssistantTurn.stopReason = stopReason;
625
- state.currentAssistantTurn = null;
626
- await this.store.write(state.history);
627
- }
628
- finalize(sessionId) {
629
- this.states.delete(sessionId);
630
- }
631
- getState(sessionId) {
632
- return this.states.get(sessionId);
633
- }
634
- findToolCall(steps, id) {
635
- for (let i = steps.length - 1; i >= 0; i--) {
636
- const s = steps[i];
637
- if (s.type === "tool_call" && s.id === id) return s;
638
- }
639
- return void 0;
640
- }
641
- };
642
-
643
- // src/plugins/context/history/history-store.ts
644
- import fs from "fs";
645
- import path from "path";
646
- var HistoryStore = class {
647
- constructor(dir) {
648
- this.dir = dir;
649
- }
650
- async write(history) {
651
- await fs.promises.mkdir(this.dir, { recursive: true });
652
- const filePath = this.filePath(history.sessionId);
653
- await fs.promises.writeFile(filePath, JSON.stringify(history, null, 2));
654
- }
655
- async read(sessionId) {
656
- const filePath = this.filePath(sessionId);
657
- try {
658
- const raw = await fs.promises.readFile(filePath, "utf-8");
659
- return JSON.parse(raw);
660
- } catch {
661
- return null;
662
- }
663
- }
664
- async exists(sessionId) {
665
- try {
666
- await fs.promises.access(this.filePath(sessionId));
667
- return true;
668
- } catch {
669
- return false;
670
- }
671
- }
672
- async list() {
673
- try {
674
- const files = await fs.promises.readdir(this.dir);
675
- return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(/\.json$/, ""));
676
- } catch {
677
- return [];
678
- }
679
- }
680
- async delete(sessionId) {
681
- try {
682
- await fs.promises.unlink(this.filePath(sessionId));
683
- } catch {
684
- }
685
- }
686
- filePath(sessionId) {
687
- return path.join(this.dir, `${sessionId}.json`);
688
- }
689
- };
690
-
691
- // src/plugins/context/index.ts
692
- var contextPlugin = {
693
- name: "@openacp/context",
694
- version: "1.0.0",
695
- description: "Conversation context management with pluggable providers",
696
- essential: false,
697
- permissions: ["services:register", "middleware:register", "kernel:access"],
698
- async install(ctx) {
699
- const { settings, terminal } = ctx;
700
- await settings.setAll({ enabled: true });
701
- terminal.log.success("Context defaults saved");
702
- },
703
- async configure(ctx) {
704
- const { terminal, settings } = ctx;
705
- const current = await settings.getAll();
706
- const toggle = await terminal.confirm({
707
- message: `Context service is ${current.enabled !== false ? "enabled" : "disabled"}. Toggle?`,
708
- initialValue: false
709
- });
710
- if (toggle) {
711
- const newState = current.enabled === false;
712
- await settings.set("enabled", newState);
713
- terminal.log.success(`Context service ${newState ? "enabled" : "disabled"}`);
714
- }
715
- },
716
- async uninstall(ctx, opts) {
717
- if (opts.purge) {
718
- await ctx.settings.clear();
719
- ctx.terminal.log.success("Context settings cleared");
720
- }
721
- },
722
- async setup(ctx) {
723
- const historyDir = path2.join(ctx.instanceRoot, "history");
724
- const store = new HistoryStore(historyDir);
725
- const recorder = new HistoryRecorder(store);
726
- const sessionManager = ctx.sessions;
727
- const getRecords = () => sessionManager.listRecords();
728
- const cachePath = path2.join(ctx.instanceRoot, "cache", "entire");
729
- const manager = new ContextManager(cachePath);
730
- manager.register(new HistoryProvider(store, getRecords));
731
- manager.register(new EntireProvider());
732
- ctx.registerService("context", manager);
733
- ctx.registerMiddleware("agent:beforePrompt", {
734
- priority: 200,
735
- handler: async (payload, next) => {
736
- recorder.onBeforePrompt(payload.sessionId, payload.text, payload.attachments);
737
- return next();
738
- }
739
- });
740
- ctx.registerMiddleware("agent:afterEvent", {
741
- priority: 200,
742
- handler: async (payload, next) => {
743
- recorder.onAfterEvent(payload.sessionId, payload.event);
744
- return next();
745
- }
746
- });
747
- ctx.registerMiddleware("turn:end", {
748
- priority: 200,
749
- handler: async (payload, next) => {
750
- await recorder.onTurnEnd(payload.sessionId, payload.stopReason);
751
- return next();
752
- }
753
- });
754
- ctx.registerMiddleware("permission:afterResolve", {
755
- priority: 200,
756
- handler: async (payload, next) => {
757
- recorder.onPermissionResolved(payload.sessionId, payload.requestId, payload.decision);
758
- return next();
759
- }
760
- });
761
- ctx.registerMiddleware("session:afterDestroy", {
762
- priority: 200,
763
- handler: async (payload, next) => {
764
- recorder.finalize(payload.sessionId);
765
- return next();
766
- }
767
- });
768
- ctx.log.info("Context service ready (local history + entire providers)");
769
- }
770
- };
771
- var context_default = contextPlugin;
772
-
773
- export {
774
- context_default
775
- };
776
- //# sourceMappingURL=chunk-FPKQYCQS.js.map