saeeol 1.2.0 → 1.2.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 (193) hide show
  1. package/package.json +14 -14
  2. package/src/cli/cmd/tui/component/dialog/dialog-agent.tsx +32 -0
  3. package/src/cli/cmd/tui/component/dialog/dialog-command.tsx +190 -0
  4. package/src/cli/cmd/tui/component/dialog/dialog-console-org.tsx +103 -0
  5. package/src/cli/cmd/tui/component/dialog/dialog-go-upsell.tsx +159 -0
  6. package/src/cli/cmd/tui/component/dialog/dialog-mcp.tsx +86 -0
  7. package/src/cli/cmd/tui/component/dialog/dialog-model.tsx +238 -0
  8. package/src/cli/cmd/tui/component/dialog/dialog-provider.tsx +343 -0
  9. package/src/cli/cmd/tui/component/dialog/dialog-session-delete-failed.tsx +103 -0
  10. package/src/cli/cmd/tui/component/dialog/dialog-session-list.tsx +301 -0
  11. package/src/cli/cmd/tui/component/dialog/dialog-session-rename.tsx +35 -0
  12. package/src/cli/cmd/tui/component/dialog/dialog-skill.tsx +37 -0
  13. package/src/cli/cmd/tui/component/dialog/dialog-stash.tsx +87 -0
  14. package/src/cli/cmd/tui/component/dialog/dialog-status.tsx +190 -0
  15. package/src/cli/cmd/tui/component/dialog/dialog-tag.tsx +44 -0
  16. package/src/cli/cmd/tui/component/dialog/dialog-theme-list.tsx +50 -0
  17. package/src/cli/cmd/tui/component/dialog/dialog-variant.tsx +39 -0
  18. package/src/cli/cmd/tui/component/dialog/dialog-workspace-create.tsx +200 -0
  19. package/src/cli/cmd/tui/component/dialog/dialog-workspace-unavailable.tsx +81 -0
  20. package/src/cli/cmd/tui/component/dialog-agent.tsx +1 -32
  21. package/src/cli/cmd/tui/component/dialog-command.tsx +1 -190
  22. package/src/cli/cmd/tui/component/dialog-console-org.tsx +1 -103
  23. package/src/cli/cmd/tui/component/dialog-go-upsell.tsx +1 -159
  24. package/src/cli/cmd/tui/component/dialog-mcp.tsx +1 -86
  25. package/src/cli/cmd/tui/component/dialog-model.tsx +1 -238
  26. package/src/cli/cmd/tui/component/dialog-provider.tsx +1 -343
  27. package/src/cli/cmd/tui/component/dialog-session-delete-failed.tsx +1 -103
  28. package/src/cli/cmd/tui/component/dialog-session-list.tsx +1 -301
  29. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +1 -35
  30. package/src/cli/cmd/tui/component/dialog-skill.tsx +1 -37
  31. package/src/cli/cmd/tui/component/dialog-stash.tsx +1 -87
  32. package/src/cli/cmd/tui/component/dialog-status.tsx +1 -190
  33. package/src/cli/cmd/tui/component/dialog-tag.tsx +1 -44
  34. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +1 -50
  35. package/src/cli/cmd/tui/component/dialog-variant.tsx +1 -39
  36. package/src/cli/cmd/tui/component/dialog-workspace-create.tsx +1 -200
  37. package/src/cli/cmd/tui/component/dialog-workspace-unavailable.tsx +1 -81
  38. package/src/session/compaction-helpers.ts +1 -169
  39. package/src/session/compaction.ts +1 -712
  40. package/src/session/core/compaction/compaction-helpers.ts +169 -0
  41. package/src/session/core/compaction/compaction.ts +712 -0
  42. package/src/session/core/compaction/overflow.ts +28 -0
  43. package/src/session/core/instruction.ts +234 -0
  44. package/src/session/core/llm.ts +504 -0
  45. package/src/session/core/network.ts +392 -0
  46. package/src/session/core/processor.ts +731 -0
  47. package/src/session/core/projectors.ts +139 -0
  48. package/src/session/core/resolve-tools.ts +241 -0
  49. package/src/session/core/retry.ts +149 -0
  50. package/src/session/core/revert.ts +173 -0
  51. package/src/session/core/run-state.ts +110 -0
  52. package/src/session/core/schema.ts +35 -0
  53. package/src/session/core/session-types.ts +160 -0
  54. package/src/session/core/session.sql.ts +124 -0
  55. package/src/session/core/session.ts +948 -0
  56. package/src/session/core/shell-exec.ts +205 -0
  57. package/src/session/core/status.ts +100 -0
  58. package/src/session/core/subtask.ts +268 -0
  59. package/src/session/core/summary.ts +173 -0
  60. package/src/session/core/system.ts +114 -0
  61. package/src/session/core/todo.ts +86 -0
  62. package/src/session/core/user-part.ts +293 -0
  63. package/src/session/instruction.ts +1 -234
  64. package/src/session/llm.ts +1 -504
  65. package/src/session/message/message-errors.ts +83 -0
  66. package/src/session/message/message-parts.ts +89 -0
  67. package/src/session/message/message-query.ts +107 -0
  68. package/src/session/message/message-transform.ts +156 -0
  69. package/src/session/message/message-types.ts +68 -0
  70. package/src/session/message/message-v2.ts +73 -0
  71. package/src/session/message/message.ts +192 -0
  72. package/src/session/message-errors.ts +1 -83
  73. package/src/session/message-parts.ts +1 -89
  74. package/src/session/message-query.ts +1 -107
  75. package/src/session/message-transform.ts +1 -156
  76. package/src/session/message-types.ts +1 -68
  77. package/src/session/message-v2.ts +1 -73
  78. package/src/session/message.ts +1 -192
  79. package/src/session/network.ts +1 -392
  80. package/src/session/overflow.ts +1 -28
  81. package/src/session/processor.ts +1 -731
  82. package/src/session/projectors.ts +2 -139
  83. package/src/session/prompt/prompt-command.ts +93 -0
  84. package/src/session/prompt/prompt-loop.ts +299 -0
  85. package/src/session/prompt/prompt-model.ts +44 -0
  86. package/src/session/prompt/prompt-reminders.ts +120 -0
  87. package/src/session/prompt/prompt-resolve.ts +42 -0
  88. package/src/session/prompt/prompt-schemas.ts +128 -0
  89. package/src/session/prompt/prompt-title.ts +55 -0
  90. package/src/session/prompt/prompt-types.ts +47 -0
  91. package/src/session/prompt/prompt-user-msg.ts +80 -0
  92. package/src/session/prompt/prompt.ts +211 -0
  93. package/src/session/prompt-command.ts +1 -93
  94. package/src/session/prompt-loop.ts +1 -299
  95. package/src/session/prompt-model.ts +1 -44
  96. package/src/session/prompt-reminders.ts +1 -120
  97. package/src/session/prompt-resolve.ts +1 -42
  98. package/src/session/prompt-schemas.ts +1 -128
  99. package/src/session/prompt-title.ts +1 -55
  100. package/src/session/prompt-types.ts +1 -47
  101. package/src/session/prompt-user-msg.ts +1 -80
  102. package/src/session/prompt.ts +1 -211
  103. package/src/session/resolve-tools.ts +1 -241
  104. package/src/session/retry.ts +1 -149
  105. package/src/session/revert.ts +1 -173
  106. package/src/session/run-state.ts +1 -110
  107. package/src/session/schema.ts +1 -35
  108. package/src/session/session-types.ts +1 -160
  109. package/src/session/session.sql.ts +1 -124
  110. package/src/session/session.ts +1 -948
  111. package/src/session/shell-exec.ts +1 -205
  112. package/src/session/status.ts +1 -100
  113. package/src/session/subtask.ts +1 -268
  114. package/src/session/summary.ts +1 -173
  115. package/src/session/system.ts +1 -114
  116. package/src/session/todo.ts +1 -86
  117. package/src/session/user-part.ts +1 -293
  118. package/src/tool/apply_patch.ts +1 -334
  119. package/src/tool/bash.ts +1 -656
  120. package/src/tool/core/external-directory.ts +55 -0
  121. package/src/tool/core/invalid.ts +21 -0
  122. package/src/tool/core/recall.ts +164 -0
  123. package/src/tool/core/recall.txt +12 -0
  124. package/src/tool/core/schema.ts +16 -0
  125. package/src/tool/core/tool.ts +162 -0
  126. package/src/tool/core/truncate.ts +160 -0
  127. package/src/tool/core/truncation-dir.ts +4 -0
  128. package/src/tool/diagnostics.ts +1 -20
  129. package/src/tool/edit-replacers.ts +1 -288
  130. package/src/tool/edit-utils.ts +1 -86
  131. package/src/tool/edit.ts +1 -262
  132. package/src/tool/external-directory.ts +1 -55
  133. package/src/tool/file/apply_patch.ts +334 -0
  134. package/src/tool/file/apply_patch.txt +33 -0
  135. package/src/tool/file/bash.ts +656 -0
  136. package/src/tool/file/bash.txt +119 -0
  137. package/src/tool/file/edit-replacers.ts +288 -0
  138. package/src/tool/file/edit-utils.ts +86 -0
  139. package/src/tool/file/edit.ts +262 -0
  140. package/src/tool/file/edit.txt +10 -0
  141. package/src/tool/file/read.ts +389 -0
  142. package/src/tool/file/read.txt +14 -0
  143. package/src/tool/file/write.ts +114 -0
  144. package/src/tool/file/write.txt +8 -0
  145. package/src/tool/glob.ts +1 -115
  146. package/src/tool/grep.ts +1 -151
  147. package/src/tool/integration/diagnostics.ts +20 -0
  148. package/src/tool/integration/lsp.ts +113 -0
  149. package/src/tool/integration/lsp.txt +24 -0
  150. package/src/tool/integration/mcp-exa.ts +73 -0
  151. package/src/tool/integration/package.ts +168 -0
  152. package/src/tool/integration/registry.ts +375 -0
  153. package/src/tool/invalid.ts +1 -21
  154. package/src/tool/lsp.ts +1 -113
  155. package/src/tool/mcp-exa.ts +1 -73
  156. package/src/tool/package.ts +1 -168
  157. package/src/tool/plan.ts +1 -30
  158. package/src/tool/question.ts +1 -52
  159. package/src/tool/read.ts +1 -389
  160. package/src/tool/recall.ts +1 -164
  161. package/src/tool/registry.ts +1 -375
  162. package/src/tool/schema.ts +1 -16
  163. package/src/tool/search/glob.ts +115 -0
  164. package/src/tool/search/glob.txt +6 -0
  165. package/src/tool/search/grep.ts +151 -0
  166. package/src/tool/search/grep.txt +8 -0
  167. package/src/tool/search/warpgrep.ts +107 -0
  168. package/src/tool/search/warpgrep.txt +10 -0
  169. package/src/tool/search/webfetch.ts +202 -0
  170. package/src/tool/search/webfetch.txt +13 -0
  171. package/src/tool/search/websearch.ts +71 -0
  172. package/src/tool/search/websearch.txt +14 -0
  173. package/src/tool/skill.ts +1 -91
  174. package/src/tool/task.ts +1 -197
  175. package/src/tool/todo.ts +1 -62
  176. package/src/tool/tool.ts +1 -162
  177. package/src/tool/truncate.ts +1 -160
  178. package/src/tool/truncation-dir.ts +1 -4
  179. package/src/tool/warpgrep.ts +1 -107
  180. package/src/tool/webfetch.ts +1 -202
  181. package/src/tool/websearch.ts +1 -71
  182. package/src/tool/workflow/plan-enter.txt +14 -0
  183. package/src/tool/workflow/plan-exit.txt +13 -0
  184. package/src/tool/workflow/plan.ts +30 -0
  185. package/src/tool/workflow/question.ts +52 -0
  186. package/src/tool/workflow/question.txt +11 -0
  187. package/src/tool/workflow/skill.ts +91 -0
  188. package/src/tool/workflow/skill.txt +5 -0
  189. package/src/tool/workflow/task.ts +197 -0
  190. package/src/tool/workflow/task.txt +57 -0
  191. package/src/tool/workflow/todo.ts +62 -0
  192. package/src/tool/workflow/todowrite.txt +167 -0
  193. package/src/tool/write.ts +1 -114
@@ -0,0 +1,169 @@
1
+ import { clamp } from "@saeeol/boxes/clamp"
2
+ import { BusEvent } from "@/bus/bus-event"
3
+ import { SessionID, MessageID } from "../schema"
4
+ import { Provider } from "@/provider/provider"
5
+ import { MessageV2 } from "../../message/message-v2"
6
+ import { Schema, Effect } from "effect"
7
+ import { Config } from "@/config/config"
8
+ import { usable } from "./overflow"
9
+
10
+ export const PRUNE_MINIMUM = 20_000
11
+ export const PRUNE_PROTECT = 40_000
12
+ export const TOOL_OUTPUT_MAX_CHARS = 2_000
13
+ export const PRUNE_PROTECTED_TOOLS = ["skill"]
14
+ export const DEFAULT_TAIL_TURNS = 2
15
+ export const MIN_PRESERVE_RECENT_TOKENS = 2_000
16
+ export const MAX_PRESERVE_RECENT_TOKENS = 8_000
17
+ export const SUMMARY_TEMPLATE = `Output exactly the Markdown structure shown inside <template> and keep the section order unchanged. Do not include the <template> tags in your response.
18
+ <template>
19
+ ## Goal
20
+ - [single-sentence task summary]
21
+
22
+ ## Constraints & Preferences
23
+ - [user constraints, preferences, specs, or "(none)"]
24
+
25
+ ## Progress
26
+ ### Done
27
+ - [completed work or "(none)"]
28
+
29
+ ### In Progress
30
+ - [current work or "(none)"]
31
+
32
+ ### Blocked
33
+ - [blockers or "(none)"]
34
+
35
+ ## Key Decisions
36
+ - [decision and why, or "(none)"]
37
+
38
+ ## Next Steps
39
+ - [ordered next actions or "(none)"]
40
+
41
+ ## Critical Context
42
+ - [important technical facts, errors, open questions, or "(none)"]
43
+
44
+ ## Relevant Files
45
+ - [file or directory path: why it matters, or "(none)"]
46
+ </template>
47
+
48
+ Rules:
49
+ - Keep every section, even when empty.
50
+ - Use terse bullets, not prose paragraphs.
51
+ - Preserve exact file paths, commands, error strings, and identifiers when known.
52
+ - Do not mention the summary process or that context was compacted.`
53
+ export type Turn = {
54
+ start: number
55
+ end: number
56
+ id: MessageID
57
+ }
58
+
59
+ export type Tail = {
60
+ start: number
61
+ id: MessageID
62
+ }
63
+
64
+ export type CompletedCompaction = {
65
+ userIndex: number
66
+ assistantIndex: number
67
+ summary: string | undefined
68
+ }
69
+ export type PruneReason = "normal" | "post-compaction" | "payload-limit"
70
+
71
+ export const Event = {
72
+ Compacted: BusEvent.define(
73
+ "session.compacted",
74
+ Schema.Struct({
75
+ sessionID: SessionID,
76
+ }),
77
+ ),
78
+ }
79
+
80
+ export function summaryText(message: MessageV2.WithParts) {
81
+ const text = message.parts
82
+ .filter((part): part is MessageV2.TextPart => part.type === "text")
83
+ .map((part) => part.text.trim())
84
+ .filter(Boolean)
85
+ .join("\n\n")
86
+ .trim()
87
+ return text || undefined
88
+ }
89
+
90
+ export function completedCompactions(messages: MessageV2.WithParts[]) {
91
+ const users = new Map<MessageID, number>()
92
+ for (let i = 0; i < messages.length; i++) {
93
+ const msg = messages[i]
94
+ if (msg.info.role !== "user") continue
95
+ if (!msg.parts.some((part) => part.type === "compaction")) continue
96
+ users.set(msg.info.id, i)
97
+ }
98
+
99
+ return messages.flatMap((msg, assistantIndex): CompletedCompaction[] => {
100
+ if (msg.info.role !== "assistant") return []
101
+ if (!msg.info.summary || !msg.info.finish || msg.info.error) return []
102
+ const userIndex = users.get(msg.info.parentID)
103
+ if (userIndex === undefined) return []
104
+ return [{ userIndex, assistantIndex, summary: summaryText(msg) }]
105
+ })
106
+ }
107
+
108
+ export function buildPrompt(input: { previousSummary?: string; context: string[] }) {
109
+ const anchor = input.previousSummary
110
+ ? [
111
+ "Update the anchored summary below using the conversation history above.",
112
+ "Preserve still-true details, remove stale details, and merge in the new facts.",
113
+ "<previous-summary>",
114
+ input.previousSummary,
115
+ "</previous-summary>",
116
+ ].join("\n")
117
+ : "Create a new anchored summary from the conversation history above."
118
+ return [anchor, SUMMARY_TEMPLATE, ...input.context].join("\n\n")
119
+ }
120
+
121
+ export function preserveRecentBudget(input: { cfg: Config.Info; model: Provider.Model }) {
122
+ return (
123
+ input.cfg.compaction?.preserve_recent_tokens ??
124
+ clamp(Math.floor(usable(input) * 0.25), MIN_PRESERVE_RECENT_TOKENS, MAX_PRESERVE_RECENT_TOKENS)
125
+ )
126
+ }
127
+
128
+ export function turns(messages: MessageV2.WithParts[]) {
129
+ const result: Turn[] = []
130
+ for (let i = 0; i < messages.length; i++) {
131
+ const msg = messages[i]
132
+ if (msg.info.role !== "user") continue
133
+ if (msg.parts.some((part) => part.type === "compaction")) continue
134
+ result.push({
135
+ start: i,
136
+ end: messages.length,
137
+ id: msg.info.id,
138
+ })
139
+ }
140
+ for (let i = 0; i < result.length - 1; i++) {
141
+ result[i].end = result[i + 1].start
142
+ }
143
+ return result
144
+ }
145
+
146
+ export function splitTurn(input: {
147
+ messages: MessageV2.WithParts[]
148
+ turn: Turn
149
+ model: Provider.Model
150
+ budget: number
151
+ estimate: (input: { messages: MessageV2.WithParts[]; model: Provider.Model }) => Effect.Effect<number>
152
+ }) {
153
+ return Effect.gen(function* () {
154
+ if (input.budget <= 0) return undefined
155
+ if (input.turn.end - input.turn.start <= 1) return undefined
156
+ for (let start = input.turn.start + 1; start < input.turn.end; start++) {
157
+ const size = yield* input.estimate({
158
+ messages: input.messages.slice(start, input.turn.end),
159
+ model: input.model,
160
+ })
161
+ if (size > input.budget) continue
162
+ return {
163
+ start,
164
+ id: input.messages[start]!.info.id,
165
+ } satisfies Tail
166
+ }
167
+ return undefined
168
+ })
169
+ }