@code-yeongyu/senpi-agent-core 2026.9.29 → 2026.10.1-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 (285) hide show
  1. package/README.md +49 -20
  2. package/dist/agent-loop.d.ts +27 -3
  3. package/dist/agent-loop.js +192 -56
  4. package/dist/agent.d.ts +21 -7
  5. package/dist/agent.js +38 -18
  6. package/dist/harness/execution/tools.d.ts +1 -1
  7. package/dist/harness/execution/tools.js +0 -2
  8. package/dist/harness/messages.js +1 -0
  9. package/dist/harness/pico3/bash.d.ts +10 -0
  10. package/dist/harness/pico3/bash.js +25 -0
  11. package/dist/harness/pico3/bounded.d.ts +21 -0
  12. package/dist/harness/pico3/bounded.js +95 -0
  13. package/dist/harness/pico3/chord.d.ts +41 -0
  14. package/dist/harness/pico3/chord.js +147 -0
  15. package/dist/harness/pico3/context.d.ts +16 -0
  16. package/dist/harness/pico3/context.js +88 -0
  17. package/dist/harness/pico3/harness.d.ts +198 -0
  18. package/dist/harness/pico3/harness.js +645 -0
  19. package/dist/harness/pico3/hooks.d.ts +10 -0
  20. package/dist/harness/pico3/hooks.js +33 -0
  21. package/dist/harness/pico3/index.d.ts +19 -0
  22. package/dist/harness/pico3/index.js +15 -0
  23. package/dist/harness/pico3/jsonl.d.ts +58 -0
  24. package/dist/harness/pico3/jsonl.js +322 -0
  25. package/dist/harness/pico3/kinds/collapse.d.ts +49 -0
  26. package/dist/harness/pico3/kinds/collapse.js +191 -0
  27. package/dist/harness/pico3/kinds/entries.d.ts +78 -0
  28. package/dist/harness/pico3/kinds/entries.js +13 -0
  29. package/dist/harness/pico3/kinds/frames.d.ts +9 -0
  30. package/dist/harness/pico3/kinds/frames.js +75 -0
  31. package/dist/harness/pico3/kinds/generation.d.ts +94 -0
  32. package/dist/harness/pico3/kinds/generation.js +504 -0
  33. package/dist/harness/pico3/kinds/job.d.ts +44 -0
  34. package/dist/harness/pico3/kinds/job.js +143 -0
  35. package/dist/harness/pico3/kinds/plugin.d.ts +15 -0
  36. package/dist/harness/pico3/kinds/plugin.js +35 -0
  37. package/dist/harness/pico3/kinds/post-tools.d.ts +22 -0
  38. package/dist/harness/pico3/kinds/post-tools.js +145 -0
  39. package/dist/harness/pico3/kinds/task-api.d.ts +3 -0
  40. package/dist/harness/pico3/kinds/task-api.js +45 -0
  41. package/dist/harness/pico3/kinds/tool.d.ts +43 -0
  42. package/dist/harness/pico3/kinds/tool.js +373 -0
  43. package/dist/harness/pico3/legacy-tracker.d.ts +11 -0
  44. package/dist/harness/pico3/legacy-tracker.js +39 -0
  45. package/dist/harness/pico3/membrane.d.ts +23 -0
  46. package/dist/harness/pico3/membrane.js +140 -0
  47. package/dist/harness/pico3/memory.d.ts +53 -0
  48. package/dist/harness/pico3/memory.js +265 -0
  49. package/dist/harness/pico3/scheduler.d.ts +49 -0
  50. package/dist/harness/pico3/scheduler.js +437 -0
  51. package/dist/harness/pico3/session.d.ts +264 -0
  52. package/dist/harness/pico3/session.js +1328 -0
  53. package/dist/harness/pico3/system.d.ts +126 -0
  54. package/dist/harness/pico3/system.js +244 -0
  55. package/dist/harness/pico3/types.d.ts +973 -0
  56. package/dist/harness/pico3/types.js +94 -0
  57. package/dist/harness/pico3/view.d.ts +34 -0
  58. package/dist/harness/pico3/view.js +404 -0
  59. package/dist/harness/runtime/drive/tool-placement.js +2 -27
  60. package/dist/harness/telemetry.d.ts +36 -36
  61. package/dist/harness/tools/image.js +1 -1
  62. package/dist/harness/utils/read-folders/index.d.ts +2 -2
  63. package/dist/harness/utils/read-folders/index.js +2 -2
  64. package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.js +1 -1
  65. package/dist/proxy.d.ts +2 -2
  66. package/dist/types.d.ts +111 -34
  67. package/package.json +10 -5
  68. package/dist/agent-loop.d.ts.map +0 -1
  69. package/dist/agent-loop.js.map +0 -1
  70. package/dist/agent.d.ts.map +0 -1
  71. package/dist/agent.js.map +0 -1
  72. package/dist/assistant-terminal-state.d.ts.map +0 -1
  73. package/dist/assistant-terminal-state.js.map +0 -1
  74. package/dist/empty-assistant-recovery.d.ts.map +0 -1
  75. package/dist/empty-assistant-recovery.js.map +0 -1
  76. package/dist/harness/agent-harness.d.ts.map +0 -1
  77. package/dist/harness/agent-harness.js.map +0 -1
  78. package/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
  79. package/dist/harness/compaction/branch-summarization.js.map +0 -1
  80. package/dist/harness/compaction/compaction.d.ts.map +0 -1
  81. package/dist/harness/compaction/compaction.js.map +0 -1
  82. package/dist/harness/compaction/utils.d.ts.map +0 -1
  83. package/dist/harness/compaction/utils.js.map +0 -1
  84. package/dist/harness/config.d.ts.map +0 -1
  85. package/dist/harness/config.js.map +0 -1
  86. package/dist/harness/context.d.ts.map +0 -1
  87. package/dist/harness/context.js.map +0 -1
  88. package/dist/harness/env/nodejs.d.ts.map +0 -1
  89. package/dist/harness/env/nodejs.js.map +0 -1
  90. package/dist/harness/events.d.ts.map +0 -1
  91. package/dist/harness/events.js.map +0 -1
  92. package/dist/harness/execution/assistant.d.ts.map +0 -1
  93. package/dist/harness/execution/assistant.js.map +0 -1
  94. package/dist/harness/execution/effect-gate.d.ts.map +0 -1
  95. package/dist/harness/execution/effect-gate.js.map +0 -1
  96. package/dist/harness/execution/tools.d.ts.map +0 -1
  97. package/dist/harness/execution/tools.js.map +0 -1
  98. package/dist/harness/hooks.d.ts.map +0 -1
  99. package/dist/harness/hooks.js.map +0 -1
  100. package/dist/harness/messages.d.ts.map +0 -1
  101. package/dist/harness/messages.js.map +0 -1
  102. package/dist/harness/prompt-templates.d.ts.map +0 -1
  103. package/dist/harness/prompt-templates.js.map +0 -1
  104. package/dist/harness/result.d.ts.map +0 -1
  105. package/dist/harness/result.js.map +0 -1
  106. package/dist/harness/runtime/drive/boundary.d.ts.map +0 -1
  107. package/dist/harness/runtime/drive/boundary.js.map +0 -1
  108. package/dist/harness/runtime/drive/checkpoint.d.ts.map +0 -1
  109. package/dist/harness/runtime/drive/checkpoint.js.map +0 -1
  110. package/dist/harness/runtime/drive/deferred.d.ts.map +0 -1
  111. package/dist/harness/runtime/drive/deferred.js.map +0 -1
  112. package/dist/harness/runtime/drive/generation.d.ts.map +0 -1
  113. package/dist/harness/runtime/drive/generation.js.map +0 -1
  114. package/dist/harness/runtime/drive/reconcile.d.ts.map +0 -1
  115. package/dist/harness/runtime/drive/reconcile.js.map +0 -1
  116. package/dist/harness/runtime/drive/recovery.d.ts.map +0 -1
  117. package/dist/harness/runtime/drive/recovery.js.map +0 -1
  118. package/dist/harness/runtime/drive/response.d.ts.map +0 -1
  119. package/dist/harness/runtime/drive/response.js.map +0 -1
  120. package/dist/harness/runtime/drive/retry.d.ts.map +0 -1
  121. package/dist/harness/runtime/drive/retry.js.map +0 -1
  122. package/dist/harness/runtime/drive/structural.d.ts.map +0 -1
  123. package/dist/harness/runtime/drive/structural.js.map +0 -1
  124. package/dist/harness/runtime/drive/terminal.d.ts.map +0 -1
  125. package/dist/harness/runtime/drive/terminal.js.map +0 -1
  126. package/dist/harness/runtime/drive/tool-placement.d.ts.map +0 -1
  127. package/dist/harness/runtime/drive/tool-placement.js.map +0 -1
  128. package/dist/harness/runtime/drive/tools.d.ts.map +0 -1
  129. package/dist/harness/runtime/drive/tools.js.map +0 -1
  130. package/dist/harness/runtime/drive.d.ts.map +0 -1
  131. package/dist/harness/runtime/drive.js.map +0 -1
  132. package/dist/harness/runtime/harness.d.ts.map +0 -1
  133. package/dist/harness/runtime/harness.js.map +0 -1
  134. package/dist/harness/runtime/index.d.ts.map +0 -1
  135. package/dist/harness/runtime/index.js.map +0 -1
  136. package/dist/harness/runtime/lane.d.ts.map +0 -1
  137. package/dist/harness/runtime/lane.js.map +0 -1
  138. package/dist/harness/runtime/progress.d.ts.map +0 -1
  139. package/dist/harness/runtime/progress.js.map +0 -1
  140. package/dist/harness/runtime/reducer.d.ts.map +0 -1
  141. package/dist/harness/runtime/reducer.js.map +0 -1
  142. package/dist/harness/runtime/restore.d.ts.map +0 -1
  143. package/dist/harness/runtime/restore.js.map +0 -1
  144. package/dist/harness/runtime/transcript.d.ts.map +0 -1
  145. package/dist/harness/runtime/transcript.js.map +0 -1
  146. package/dist/harness/runtime/types.d.ts.map +0 -1
  147. package/dist/harness/runtime/types.js.map +0 -1
  148. package/dist/harness/session/commit.d.ts.map +0 -1
  149. package/dist/harness/session/commit.js.map +0 -1
  150. package/dist/harness/session/context.d.ts.map +0 -1
  151. package/dist/harness/session/context.js.map +0 -1
  152. package/dist/harness/session/fork-policy.d.ts.map +0 -1
  153. package/dist/harness/session/fork-policy.js.map +0 -1
  154. package/dist/harness/session/fork.d.ts.map +0 -1
  155. package/dist/harness/session/fork.js.map +0 -1
  156. package/dist/harness/session/in-memory-storage-state.d.ts.map +0 -1
  157. package/dist/harness/session/in-memory-storage-state.js.map +0 -1
  158. package/dist/harness/session/index.d.ts.map +0 -1
  159. package/dist/harness/session/index.js.map +0 -1
  160. package/dist/harness/session/jsonl/codec.d.ts.map +0 -1
  161. package/dist/harness/session/jsonl/codec.js.map +0 -1
  162. package/dist/harness/session/jsonl/fork.d.ts.map +0 -1
  163. package/dist/harness/session/jsonl/fork.js.map +0 -1
  164. package/dist/harness/session/jsonl/index.d.ts.map +0 -1
  165. package/dist/harness/session/jsonl/index.js.map +0 -1
  166. package/dist/harness/session/jsonl/io.d.ts.map +0 -1
  167. package/dist/harness/session/jsonl/io.js.map +0 -1
  168. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +0 -1
  169. package/dist/harness/session/jsonl/legacy-v3.js.map +0 -1
  170. package/dist/harness/session/jsonl/repo.d.ts.map +0 -1
  171. package/dist/harness/session/jsonl/repo.js.map +0 -1
  172. package/dist/harness/session/jsonl/storage.d.ts.map +0 -1
  173. package/dist/harness/session/jsonl/storage.js.map +0 -1
  174. package/dist/harness/session/jsonl/types.d.ts.map +0 -1
  175. package/dist/harness/session/jsonl/types.js.map +0 -1
  176. package/dist/harness/session/memory.d.ts.map +0 -1
  177. package/dist/harness/session/memory.js.map +0 -1
  178. package/dist/harness/session/mutation-line.d.ts.map +0 -1
  179. package/dist/harness/session/mutation-line.js.map +0 -1
  180. package/dist/harness/session/session.d.ts.map +0 -1
  181. package/dist/harness/session/session.js.map +0 -1
  182. package/dist/harness/session/testing/benchmark/datasets.d.ts.map +0 -1
  183. package/dist/harness/session/testing/benchmark/datasets.js.map +0 -1
  184. package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +0 -1
  185. package/dist/harness/session/testing/benchmark/session-repo.js.map +0 -1
  186. package/dist/harness/session/testing/benchmark/storage.d.ts.map +0 -1
  187. package/dist/harness/session/testing/benchmark/storage.js.map +0 -1
  188. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +0 -1
  189. package/dist/harness/session/testing/conformance/session-repo.js.map +0 -1
  190. package/dist/harness/session/testing/conformance/storage.d.ts.map +0 -1
  191. package/dist/harness/session/testing/conformance/storage.js.map +0 -1
  192. package/dist/harness/session/testing/gating-storage.d.ts.map +0 -1
  193. package/dist/harness/session/testing/gating-storage.js.map +0 -1
  194. package/dist/harness/session/testing/index.d.ts.map +0 -1
  195. package/dist/harness/session/testing/index.js.map +0 -1
  196. package/dist/harness/session/testing/instrumented-storage.d.ts.map +0 -1
  197. package/dist/harness/session/testing/instrumented-storage.js.map +0 -1
  198. package/dist/harness/session/testing/storage-decorator.d.ts.map +0 -1
  199. package/dist/harness/session/testing/storage-decorator.js.map +0 -1
  200. package/dist/harness/session/testing/types.d.ts.map +0 -1
  201. package/dist/harness/session/testing/types.js.map +0 -1
  202. package/dist/harness/session/types.d.ts.map +0 -1
  203. package/dist/harness/session/types.js.map +0 -1
  204. package/dist/harness/session/values.d.ts.map +0 -1
  205. package/dist/harness/session/values.js.map +0 -1
  206. package/dist/harness/skills.d.ts.map +0 -1
  207. package/dist/harness/skills.js.map +0 -1
  208. package/dist/harness/system-prompt.d.ts.map +0 -1
  209. package/dist/harness/system-prompt.js.map +0 -1
  210. package/dist/harness/telemetry.d.ts.map +0 -1
  211. package/dist/harness/telemetry.js.map +0 -1
  212. package/dist/harness/tools/bash.d.ts.map +0 -1
  213. package/dist/harness/tools/bash.js.map +0 -1
  214. package/dist/harness/tools/edit-diff.d.ts.map +0 -1
  215. package/dist/harness/tools/edit-diff.js.map +0 -1
  216. package/dist/harness/tools/edit.d.ts.map +0 -1
  217. package/dist/harness/tools/edit.js.map +0 -1
  218. package/dist/harness/tools/file-mutation-queue.d.ts.map +0 -1
  219. package/dist/harness/tools/file-mutation-queue.js.map +0 -1
  220. package/dist/harness/tools/image.d.ts.map +0 -1
  221. package/dist/harness/tools/image.js.map +0 -1
  222. package/dist/harness/tools/index.d.ts.map +0 -1
  223. package/dist/harness/tools/index.js.map +0 -1
  224. package/dist/harness/tools/path-utils.d.ts.map +0 -1
  225. package/dist/harness/tools/path-utils.js.map +0 -1
  226. package/dist/harness/tools/post-mutate.d.ts.map +0 -1
  227. package/dist/harness/tools/post-mutate.js.map +0 -1
  228. package/dist/harness/tools/read.d.ts.map +0 -1
  229. package/dist/harness/tools/read.js.map +0 -1
  230. package/dist/harness/tools/tool-context.d.ts.map +0 -1
  231. package/dist/harness/tools/tool-context.js.map +0 -1
  232. package/dist/harness/tools/write.d.ts.map +0 -1
  233. package/dist/harness/tools/write.js.map +0 -1
  234. package/dist/harness/types.d.ts.map +0 -1
  235. package/dist/harness/types.js.map +0 -1
  236. package/dist/harness/utils/adaptive-publisher.d.ts.map +0 -1
  237. package/dist/harness/utils/adaptive-publisher.js.map +0 -1
  238. package/dist/harness/utils/output-capture.d.ts.map +0 -1
  239. package/dist/harness/utils/output-capture.js.map +0 -1
  240. package/dist/harness/utils/read-folders/brace-scanner.d.ts.map +0 -1
  241. package/dist/harness/utils/read-folders/brace-scanner.js.map +0 -1
  242. package/dist/harness/utils/read-folders/compose.d.ts.map +0 -1
  243. package/dist/harness/utils/read-folders/compose.js.map +0 -1
  244. package/dist/harness/utils/read-folders/header-protection.d.ts.map +0 -1
  245. package/dist/harness/utils/read-folders/header-protection.js.map +0 -1
  246. package/dist/harness/utils/read-folders/index.d.ts.map +0 -1
  247. package/dist/harness/utils/read-folders/index.js.map +0 -1
  248. package/dist/harness/utils/read-folders/lexical-context.d.ts.map +0 -1
  249. package/dist/harness/utils/read-folders/lexical-context.js.map +0 -1
  250. package/dist/harness/utils/read-folders/lexical-spans.d.ts.map +0 -1
  251. package/dist/harness/utils/read-folders/lexical-spans.js.map +0 -1
  252. package/dist/harness/utils/read-folders/prepare.d.ts.map +0 -1
  253. package/dist/harness/utils/read-folders/prepare.js.map +0 -1
  254. package/dist/harness/utils/read-folders/tree-sitter/engine.d.ts.map +0 -1
  255. package/dist/harness/utils/read-folders/tree-sitter/engine.js.map +0 -1
  256. package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.d.ts.map +0 -1
  257. package/dist/harness/utils/read-folders/tree-sitter/grammar-assets.js.map +0 -1
  258. package/dist/harness/utils/read-folders/tree-sitter/syntax.d.ts.map +0 -1
  259. package/dist/harness/utils/read-folders/tree-sitter/syntax.js.map +0 -1
  260. package/dist/harness/utils/read-folders/types.d.ts.map +0 -1
  261. package/dist/harness/utils/read-folders/types.js.map +0 -1
  262. package/dist/harness/utils/segmented-read-view.d.ts.map +0 -1
  263. package/dist/harness/utils/segmented-read-view.js.map +0 -1
  264. package/dist/harness/utils/shell-output.d.ts.map +0 -1
  265. package/dist/harness/utils/shell-output.js.map +0 -1
  266. package/dist/harness/utils/truncate.d.ts.map +0 -1
  267. package/dist/harness/utils/truncate.js.map +0 -1
  268. package/dist/harness/utils/usage.d.ts.map +0 -1
  269. package/dist/harness/utils/usage.js.map +0 -1
  270. package/dist/index.d.ts.map +0 -1
  271. package/dist/index.js.map +0 -1
  272. package/dist/node.d.ts.map +0 -1
  273. package/dist/node.js.map +0 -1
  274. package/dist/proxy.d.ts.map +0 -1
  275. package/dist/proxy.js.map +0 -1
  276. package/dist/search/index.d.ts.map +0 -1
  277. package/dist/search/index.js.map +0 -1
  278. package/dist/stream-fn.d.ts.map +0 -1
  279. package/dist/stream-fn.js.map +0 -1
  280. package/dist/tool-arguments.d.ts.map +0 -1
  281. package/dist/tool-arguments.js.map +0 -1
  282. package/dist/tool-name-alias.d.ts.map +0 -1
  283. package/dist/tool-name-alias.js.map +0 -1
  284. package/dist/types.d.ts.map +0 -1
  285. package/dist/types.js.map +0 -1
@@ -0,0 +1,78 @@
1
+ import type { AssistantMessage, ToolResultMessage, UserMessage } from "@earendil-works/pi-ai";
2
+ import type { Entry, EntryKind, Id, JsonValue, SystemMessage, ToolControl } from "../types.ts";
3
+ export type UserEntry = Entry & {
4
+ kind: "pi.user";
5
+ model: [UserMessage];
6
+ data?: {
7
+ continuation: true;
8
+ from: Id;
9
+ };
10
+ };
11
+ export type AssistantEntry = Entry & {
12
+ kind: "pi.assistant";
13
+ model: [AssistantMessage];
14
+ data: {
15
+ attempt: number;
16
+ };
17
+ };
18
+ export type ToolResultEntry = Entry & {
19
+ kind: "pi.tool_result";
20
+ model: [ToolResultMessage];
21
+ data: {
22
+ details?: JsonValue;
23
+ diagnostics?: JsonValue;
24
+ control?: ToolControl;
25
+ truncated?: {
26
+ bytes: number;
27
+ lines: number;
28
+ };
29
+ };
30
+ };
31
+ export type SystemEntry = Entry & {
32
+ kind: "pi.system";
33
+ model: [SystemMessage];
34
+ data: {
35
+ baseline: boolean;
36
+ };
37
+ };
38
+ export type NoticeEntry = Entry & {
39
+ kind: "pi.notice";
40
+ model: [UserMessage];
41
+ };
42
+ export type UsageEntry = Entry & {
43
+ kind: "pi.usage";
44
+ data: {
45
+ attempt: number;
46
+ usage?: AssistantMessage["usage"];
47
+ error: string;
48
+ };
49
+ };
50
+ export type SummaryEntry = Entry & {
51
+ kind: "pi.summary";
52
+ model: [UserMessage];
53
+ data: {
54
+ through: Id;
55
+ };
56
+ head: Id;
57
+ };
58
+ export type HandoffEntry = Entry & {
59
+ kind: "pi.handoff";
60
+ model: [UserMessage];
61
+ head: Id;
62
+ };
63
+ export type ResetEntry = Entry & {
64
+ kind: "pi.reset";
65
+ head: Id;
66
+ };
67
+ export declare const entries: {
68
+ readonly user: EntryKind<UserEntry>;
69
+ readonly assistant: EntryKind<AssistantEntry>;
70
+ readonly toolResult: EntryKind<ToolResultEntry>;
71
+ readonly system: EntryKind<SystemEntry>;
72
+ readonly notice: EntryKind<NoticeEntry>;
73
+ readonly usage: EntryKind<UsageEntry>;
74
+ readonly summary: EntryKind<SummaryEntry>;
75
+ readonly handoff: EntryKind<HandoffEntry>;
76
+ readonly reset: EntryKind<ResetEntry>;
77
+ };
78
+ //# sourceMappingURL=entries.d.ts.map
@@ -0,0 +1,13 @@
1
+ const coreEntry = (kind) => Object.freeze({ kind, is: (entry) => entry?.kind === kind });
2
+ export const entries = {
3
+ user: coreEntry("pi.user"),
4
+ assistant: coreEntry("pi.assistant"),
5
+ toolResult: coreEntry("pi.tool_result"),
6
+ system: coreEntry("pi.system"),
7
+ notice: coreEntry("pi.notice"),
8
+ usage: coreEntry("pi.usage"),
9
+ summary: coreEntry("pi.summary"),
10
+ handoff: coreEntry("pi.handoff"),
11
+ reset: coreEntry("pi.reset"),
12
+ };
13
+ //# sourceMappingURL=entries.js.map
@@ -0,0 +1,9 @@
1
+ import type { AssistantMessage, AssistantMessageFrame } from "@earendil-works/pi-ai";
2
+ /**
3
+ * Apply one encoded frame to the tracked output. Same switch as pi-ai's
4
+ * reduceAssistantMessageFrames (the test oracle); no buffering, no second copy.
5
+ */
6
+ export declare function applyFrame(o: {
7
+ message?: AssistantMessage;
8
+ }, frame: AssistantMessageFrame): void;
9
+ //# sourceMappingURL=frames.d.ts.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Apply one encoded frame to the tracked output. Same switch as pi-ai's
3
+ * reduceAssistantMessageFrames (the test oracle); no buffering, no second copy.
4
+ */
5
+ export function applyFrame(o, frame) {
6
+ if (frame.type === "start") {
7
+ o.message = frame.partial; // the encoder's clone
8
+ return;
9
+ }
10
+ const m = o.message;
11
+ if (m === undefined)
12
+ throw new Error(`${frame.type} before start`);
13
+ const c = m.content;
14
+ switch (frame.type) {
15
+ case "text_start":
16
+ c[frame.contentIndex] = { ...frame.content };
17
+ return;
18
+ case "text_delta":
19
+ c[frame.contentIndex].text += frame.delta;
20
+ return;
21
+ case "text_end": {
22
+ const b = c[frame.contentIndex];
23
+ b.text = frame.content;
24
+ delete b.textSignature;
25
+ if (frame.textSignature !== undefined)
26
+ b.textSignature = frame.textSignature;
27
+ return;
28
+ }
29
+ case "thinking_start":
30
+ c[frame.contentIndex] = { ...frame.content };
31
+ return;
32
+ case "thinking_delta":
33
+ c[frame.contentIndex].thinking += frame.delta;
34
+ return;
35
+ case "thinking_end": {
36
+ const b = c[frame.contentIndex];
37
+ b.thinking = frame.content;
38
+ delete b.thinkingSignature;
39
+ delete b.redacted;
40
+ if (frame.thinkingSignature !== undefined)
41
+ b.thinkingSignature = frame.thinkingSignature;
42
+ if (frame.redacted !== undefined)
43
+ b.redacted = frame.redacted;
44
+ return;
45
+ }
46
+ case "toolcall_start":
47
+ c[frame.contentIndex] = { ...frame.toolCall };
48
+ return;
49
+ case "toolcall_checkpoint":
50
+ c[frame.contentIndex].arguments = safeParse(frame.json);
51
+ return;
52
+ case "toolcall_delta":
53
+ return; // arguments materialise at checkpoint/end; deltas only feed the encoder's own json buffer
54
+ case "toolcall_end": {
55
+ const b = c[frame.contentIndex];
56
+ b.id = frame.id;
57
+ b.name = frame.name;
58
+ b.arguments = frame.arguments;
59
+ if (frame.thoughtSignature !== undefined)
60
+ b.thoughtSignature = frame.thoughtSignature;
61
+ if (frame.namespace !== undefined)
62
+ b.namespace = frame.namespace;
63
+ return;
64
+ }
65
+ }
66
+ }
67
+ function safeParse(json) {
68
+ try {
69
+ return JSON.parse(json);
70
+ }
71
+ catch {
72
+ return {};
73
+ }
74
+ }
75
+ //# sourceMappingURL=frames.js.map
@@ -0,0 +1,94 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import type { AssistantMessage, DeferredHandle } from "@earendil-works/pi-ai";
3
+ import { type SystemInstructionsHooks } from "../system.ts";
4
+ import { type CoreKind, type HookInfo, type HookResult, type Id, type ModelRef, type RequestMessage, type RetryPolicy, type Stored, type ThinkingLevel } from "../types.ts";
5
+ export type GenerationInput = {
6
+ inputs: Id[];
7
+ };
8
+ /** Captured once at `prepared`; carried unchanged except `attempt`. */
9
+ type Prep = {
10
+ cutoff: Id;
11
+ system: Id | null;
12
+ model: ModelRef;
13
+ thinkingLevel: ThinkingLevel;
14
+ tools: string[];
15
+ retry: RetryPolicy;
16
+ attempt: number;
17
+ };
18
+ export type GenerationCheckpoint = ({
19
+ phase: "prepared";
20
+ } & Prep) | ({
21
+ phase: "requesting";
22
+ } & Prep) | ({
23
+ phase: "retrying";
24
+ untilMs: number;
25
+ lastError: string;
26
+ } & Prep) | ({
27
+ phase: "deferred";
28
+ handle: Stored<DeferredHandle>;
29
+ pollAt: number;
30
+ } & Prep);
31
+ export type GenerationResult = {
32
+ assistant: Id;
33
+ tools: Id[];
34
+ postTools?: Id;
35
+ successor?: Id;
36
+ };
37
+ export type GenerationFailure = {
38
+ reason: "provider" | "overflow" | "retries_exhausted" | "no_model";
39
+ detail: string;
40
+ assistant?: Id;
41
+ };
42
+ /** Display-only assistant entries (provider error, aborted partial) carry the message here, never in `model`. */
43
+ export type DisplayAssistantData = {
44
+ attempt: number;
45
+ display: Stored<AssistantMessage>;
46
+ reason: "error" | "aborted";
47
+ };
48
+ /** Hook points this kind calls. Register with `h.hooks(namespace, kinds.generation, { … })`. */
49
+ export interface GenerationHooks extends SystemInstructionsHooks {
50
+ /** Before every request (also on retry and recovery). Chain. */
51
+ beforeRequest(request: {
52
+ messages: RequestMessage[];
53
+ }, info: HookInfo & {
54
+ cutoff: Id;
55
+ }, ctx: Context): HookResult<{
56
+ messages: RequestMessage[];
57
+ }>;
58
+ /** Every terminal provider message, before classification. Observer. */
59
+ afterResponse(message: AssistantMessage, info: HookInfo & {
60
+ attempt: number;
61
+ }, ctx: Context): void | Promise<void>;
62
+ /** On a final answer with nothing queued. First `{ continue }` wins and starts a continuation. */
63
+ onYield(answer: AssistantMessage, info: HookInfo, ctx: Context): HookResult<{
64
+ continue: string;
65
+ }>;
66
+ }
67
+ /** Configuration this kind reads, with defaults. `model` has none: absent → failed/no_model. */
68
+ export declare const generationConfig: {
69
+ readonly rewindable: {
70
+ readonly model: ModelRef | undefined;
71
+ readonly thinkingLevel: ThinkingLevel;
72
+ readonly selectedTools: string[];
73
+ readonly profile: string;
74
+ };
75
+ readonly sticky: {
76
+ readonly retry: RetryPolicy;
77
+ };
78
+ };
79
+ export declare const generation: CoreKind<GenerationInput, GenerationCheckpoint, GenerationResult, GenerationFailure, {
80
+ assistant?: Id;
81
+ }, GenerationHooks, typeof generationConfig>;
82
+ type RetryDecision = {
83
+ kind: "retry";
84
+ untilMs: number;
85
+ } | {
86
+ kind: "fail";
87
+ reason: "provider" | "retries_exhausted";
88
+ };
89
+ export declare function retryDecision(cp: {
90
+ retry: RetryPolicy;
91
+ attempt: number;
92
+ }, message: AssistantMessage | null, now: number): RetryDecision;
93
+ export {};
94
+ //# sourceMappingURL=generation.d.ts.map