@yanlinglabs/winter-agent-runtime 0.0.27

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 (311) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +41 -0
  3. package/README.md +64 -0
  4. package/dist/checkpoint/file-history.d.ts +81 -0
  5. package/dist/checkpoint/rewind.d.ts +55 -0
  6. package/dist/checkpoint/seam.d.ts +47 -0
  7. package/dist/checkpoint/sink.d.ts +66 -0
  8. package/dist/commands/builtins-listing.d.ts +40 -0
  9. package/dist/commands/resolver.d.ts +103 -0
  10. package/dist/commands/seam.d.ts +53 -0
  11. package/dist/compaction/controller.d.ts +23 -0
  12. package/dist/compaction/retention.d.ts +35 -0
  13. package/dist/compaction/seam.d.ts +115 -0
  14. package/dist/compaction/summarizer.d.ts +79 -0
  15. package/dist/context/agent-listing.d.ts +39 -0
  16. package/dist/context/assembler.d.ts +46 -0
  17. package/dist/context/attachments.d.ts +104 -0
  18. package/dist/context/dynamic-sections.d.ts +31 -0
  19. package/dist/context/git-fixture.d.ts +18 -0
  20. package/dist/context/git-status.d.ts +16 -0
  21. package/dist/context/imports.d.ts +22 -0
  22. package/dist/context/injection.d.ts +53 -0
  23. package/dist/context/memory-key.d.ts +46 -0
  24. package/dist/context/memory.d.ts +28 -0
  25. package/dist/context/minimal-prompt.d.ts +5 -0
  26. package/dist/context/output-styles.d.ts +68 -0
  27. package/dist/context/plan-mode.d.ts +29 -0
  28. package/dist/context/request-layout.d.ts +138 -0
  29. package/dist/context/rules.d.ts +63 -0
  30. package/dist/context/seam.d.ts +136 -0
  31. package/dist/context/tool-epoch.d.ts +118 -0
  32. package/dist/context/winter-code-preset.d.ts +39 -0
  33. package/dist/context/winter-md.d.ts +81 -0
  34. package/dist/embedded-host.d.ts +48 -0
  35. package/dist/embedded-host.js +155 -0
  36. package/dist/embedded-protocol.d.ts +44 -0
  37. package/dist/embedded-worker.d.ts +1 -0
  38. package/dist/embedded-worker.js +74 -0
  39. package/dist/embedded.d.ts +34 -0
  40. package/dist/embedded.js +9 -0
  41. package/dist/engine.d.ts +1298 -0
  42. package/dist/hooks/additional-context.d.ts +21 -0
  43. package/dist/hooks/bounds.d.ts +6 -0
  44. package/dist/hooks/bridge-invoker.d.ts +3 -0
  45. package/dist/hooks/command-invoker.d.ts +52 -0
  46. package/dist/hooks/from-config.d.ts +31 -0
  47. package/dist/hooks/hook-stage.d.ts +25 -0
  48. package/dist/hooks/input-validator.d.ts +6 -0
  49. package/dist/hooks/reducer.d.ts +74 -0
  50. package/dist/hooks/registry.d.ts +33 -0
  51. package/dist/hooks/runner.d.ts +105 -0
  52. package/dist/index-584yahed.js +6037 -0
  53. package/dist/index-97t2rmtf.js +42 -0
  54. package/dist/index-9qgkpv56.js +27183 -0
  55. package/dist/index-bef62z3r.js +437 -0
  56. package/dist/index-rkhh0457.js +187 -0
  57. package/dist/index.d.ts +37 -0
  58. package/dist/index.js +353 -0
  59. package/dist/main.d.ts +1 -0
  60. package/dist/mcp/client.d.ts +105 -0
  61. package/dist/mcp/control-seam.d.ts +25 -0
  62. package/dist/mcp/control.d.ts +5 -0
  63. package/dist/mcp/elicitation.d.ts +35 -0
  64. package/dist/mcp/env.d.ts +12 -0
  65. package/dist/mcp/lifecycle.d.ts +142 -0
  66. package/dist/mcp/output-cap.d.ts +15 -0
  67. package/dist/mcp/state.d.ts +24 -0
  68. package/dist/mcp/test-fixtures.d.ts +88 -0
  69. package/dist/mcp/transports/__fixtures__/stdio-server.d.ts +1 -0
  70. package/dist/mcp/transports/http.d.ts +5 -0
  71. package/dist/mcp/transports/sdk.d.ts +5 -0
  72. package/dist/mcp/transports/sse.d.ts +3 -0
  73. package/dist/mcp/transports/stdio.d.ts +35 -0
  74. package/dist/mcp/winter-server.d.ts +2 -0
  75. package/dist/messaging/reference-adapter.d.ts +88 -0
  76. package/dist/messaging/router.d.ts +8 -0
  77. package/dist/paths/project-dir-name.d.ts +2 -0
  78. package/dist/paths/temp.d.ts +25 -0
  79. package/dist/permissions/approvals.d.ts +107 -0
  80. package/dist/permissions/auto/caches.d.ts +53 -0
  81. package/dist/permissions/auto/config.d.ts +37 -0
  82. package/dist/permissions/auto/engine.d.ts +74 -0
  83. package/dist/permissions/auto/envelope.d.ts +45 -0
  84. package/dist/permissions/auto/inheritance.d.ts +27 -0
  85. package/dist/permissions/edit-recognition.d.ts +30 -0
  86. package/dist/permissions/evaluator.d.ts +284 -0
  87. package/dist/permissions/file-rules.d.ts +384 -0
  88. package/dist/permissions/grammar.d.ts +113 -0
  89. package/dist/permissions/paths.d.ts +32 -0
  90. package/dist/permissions/policy-state.d.ts +64 -0
  91. package/dist/permissions/prompt-stage.d.ts +3 -0
  92. package/dist/permissions/protected.d.ts +54 -0
  93. package/dist/permissions/ruleset.d.ts +134 -0
  94. package/dist/permissions/shell-structure.d.ts +41 -0
  95. package/dist/plugins/bundle.d.ts +100 -0
  96. package/dist/plugins/installed.d.ts +30 -0
  97. package/dist/plugins/loader.d.ts +56 -0
  98. package/dist/plugins/manifest.d.ts +115 -0
  99. package/dist/production-wiring.d.ts +340 -0
  100. package/dist/protocol/channel.d.ts +22 -0
  101. package/dist/provider/advisor-route.d.ts +47 -0
  102. package/dist/provider/bridge.d.ts +124 -0
  103. package/dist/provider/classifier/model-classifier.d.ts +82 -0
  104. package/dist/provider/classifier/prompt.d.ts +62 -0
  105. package/dist/provider/classifier/verdict-schema.d.ts +83 -0
  106. package/dist/provider/credential-api.d.ts +160 -0
  107. package/dist/provider/family-listing.d.ts +27 -0
  108. package/dist/provider/first-party.d.ts +4 -0
  109. package/dist/provider/keychain-store.d.ts +59 -0
  110. package/dist/provider/lean-prompt.d.ts +7 -0
  111. package/dist/provider/mock.d.ts +55 -0
  112. package/dist/provider/scenario-fake.d.ts +96 -0
  113. package/dist/provider/selection.d.ts +115 -0
  114. package/dist/provider/session-provider.d.ts +426 -0
  115. package/dist/provider/slots.d.ts +120 -0
  116. package/dist/provider/stream-frames.d.ts +25 -0
  117. package/dist/provider/tool-secret.d.ts +57 -0
  118. package/dist/rpc/bridge.d.ts +14 -0
  119. package/dist/rpc/mcp-control.d.ts +26 -0
  120. package/dist/runtime.d.ts +14 -0
  121. package/dist/sandbox/profile.d.ts +249 -0
  122. package/dist/sandbox/spawn.d.ts +139 -0
  123. package/dist/settings/env-filter.d.ts +52 -0
  124. package/dist/settings/loaders/hooks.d.ts +44 -0
  125. package/dist/settings/loaders/mcp-config.d.ts +83 -0
  126. package/dist/settings/loaders/plugin-mcp.d.ts +3 -0
  127. package/dist/settings/loaders/strict-plugin-only.d.ts +13 -0
  128. package/dist/settings/resolve.d.ts +2 -0
  129. package/dist/settings/sources.d.ts +2 -0
  130. package/dist/settings/trust.d.ts +36 -0
  131. package/dist/skills/attachment.d.ts +25 -0
  132. package/dist/skills/frontmatter.d.ts +64 -0
  133. package/dist/skills/index.d.ts +16 -0
  134. package/dist/skills/listing.d.ts +89 -0
  135. package/dist/skills/loader.d.ts +104 -0
  136. package/dist/skills/option.d.ts +68 -0
  137. package/dist/skills/permission-rules.d.ts +21 -0
  138. package/dist/skills/runtime.d.ts +21 -0
  139. package/dist/skills/store.d.ts +163 -0
  140. package/dist/store/continuation-attach.d.ts +44 -0
  141. package/dist/store/dialect.d.ts +526 -0
  142. package/dist/store/provider-state.d.ts +188 -0
  143. package/dist/store/resume.d.ts +92 -0
  144. package/dist/structured/ajv-seam.d.ts +7 -0
  145. package/dist/structured/descriptor.d.ts +9 -0
  146. package/dist/structured/seam.d.ts +51 -0
  147. package/dist/structured/validator.d.ts +22 -0
  148. package/dist/subagents/activity.d.ts +13 -0
  149. package/dist/subagents/availability.d.ts +30 -0
  150. package/dist/subagents/builtin-agents.d.ts +37 -0
  151. package/dist/subagents/child-engine.d.ts +198 -0
  152. package/dist/subagents/child-handle.d.ts +344 -0
  153. package/dist/subagents/definitions.d.ts +189 -0
  154. package/dist/subagents/fork.d.ts +55 -0
  155. package/dist/subagents/git-root.d.ts +1 -0
  156. package/dist/subagents/limits.d.ts +28 -0
  157. package/dist/subagents/notification-queue.d.ts +233 -0
  158. package/dist/subagents/plugin-agents.d.ts +5 -0
  159. package/dist/subagents/policy.d.ts +46 -0
  160. package/dist/subagents/register-default-factory.d.ts +66 -0
  161. package/dist/subagents/resolution.d.ts +56 -0
  162. package/dist/subagents/restore.d.ts +9 -0
  163. package/dist/subagents/roster.d.ts +17 -0
  164. package/dist/subagents/test-fakes.d.ts +12 -0
  165. package/dist/subagents/tool-pools.d.ts +69 -0
  166. package/dist/subagents/watchdog.d.ts +13 -0
  167. package/dist/subagents/workspace.d.ts +27 -0
  168. package/dist/testing.d.ts +5 -0
  169. package/dist/testing.js +194 -0
  170. package/dist/tools/background-tasks.d.ts +10 -0
  171. package/dist/tools/descriptors/_shared.d.ts +34 -0
  172. package/dist/tools/descriptors/advisor.d.ts +1 -0
  173. package/dist/tools/descriptors/agent.d.ts +47 -0
  174. package/dist/tools/descriptors/artifact.d.ts +1 -0
  175. package/dist/tools/descriptors/ask-user-question.d.ts +1 -0
  176. package/dist/tools/descriptors/bash.d.ts +20 -0
  177. package/dist/tools/descriptors/claude-design.d.ts +1 -0
  178. package/dist/tools/descriptors/cron-create.d.ts +1 -0
  179. package/dist/tools/descriptors/cron-delete.d.ts +1 -0
  180. package/dist/tools/descriptors/cron-list.d.ts +1 -0
  181. package/dist/tools/descriptors/edit.d.ts +1 -0
  182. package/dist/tools/descriptors/end-conversation.d.ts +1 -0
  183. package/dist/tools/descriptors/enter-plan-mode.d.ts +1 -0
  184. package/dist/tools/descriptors/enter-worktree.d.ts +1 -0
  185. package/dist/tools/descriptors/exit-plan-mode.d.ts +1 -0
  186. package/dist/tools/descriptors/exit-worktree.d.ts +1 -0
  187. package/dist/tools/descriptors/glob.d.ts +1 -0
  188. package/dist/tools/descriptors/grep.d.ts +1 -0
  189. package/dist/tools/descriptors/index.d.ts +59 -0
  190. package/dist/tools/descriptors/list-agents.d.ts +1 -0
  191. package/dist/tools/descriptors/list-mcp-resources-tool.d.ts +1 -0
  192. package/dist/tools/descriptors/lsp.d.ts +1 -0
  193. package/dist/tools/descriptors/monitor.d.ts +1 -0
  194. package/dist/tools/descriptors/notebook-edit.d.ts +1 -0
  195. package/dist/tools/descriptors/powershell.d.ts +1 -0
  196. package/dist/tools/descriptors/projects.d.ts +1 -0
  197. package/dist/tools/descriptors/propose-goal.d.ts +1 -0
  198. package/dist/tools/descriptors/propose-skills.d.ts +1 -0
  199. package/dist/tools/descriptors/push-notification.d.ts +1 -0
  200. package/dist/tools/descriptors/read-mcp-resource-dir-tool.d.ts +1 -0
  201. package/dist/tools/descriptors/read-mcp-resource-tool.d.ts +1 -0
  202. package/dist/tools/descriptors/read-notifications.d.ts +1 -0
  203. package/dist/tools/descriptors/read.d.ts +1 -0
  204. package/dist/tools/descriptors/refresh-mcp-tools.d.ts +1 -0
  205. package/dist/tools/descriptors/remote-trigger.d.ts +1 -0
  206. package/dist/tools/descriptors/repl.d.ts +1 -0
  207. package/dist/tools/descriptors/report-findings.d.ts +1 -0
  208. package/dist/tools/descriptors/schedule-wakeup.d.ts +1 -0
  209. package/dist/tools/descriptors/send-feedback.d.ts +1 -0
  210. package/dist/tools/descriptors/send-message.d.ts +1 -0
  211. package/dist/tools/descriptors/send-user-file.d.ts +1 -0
  212. package/dist/tools/descriptors/share-onboarding-guide.d.ts +1 -0
  213. package/dist/tools/descriptors/show-onboarding-role-picker.d.ts +1 -0
  214. package/dist/tools/descriptors/skill.d.ts +1 -0
  215. package/dist/tools/descriptors/structured-output.d.ts +1 -0
  216. package/dist/tools/descriptors/task-create.d.ts +1 -0
  217. package/dist/tools/descriptors/task-get.d.ts +1 -0
  218. package/dist/tools/descriptors/task-list.d.ts +1 -0
  219. package/dist/tools/descriptors/task-output.d.ts +1 -0
  220. package/dist/tools/descriptors/task-stop.d.ts +1 -0
  221. package/dist/tools/descriptors/task-update.d.ts +1 -0
  222. package/dist/tools/descriptors/todo-write.d.ts +1 -0
  223. package/dist/tools/descriptors/tool-search.d.ts +1 -0
  224. package/dist/tools/descriptors/wait-for-mcp-servers.d.ts +1 -0
  225. package/dist/tools/descriptors/web-fetch.d.ts +8 -0
  226. package/dist/tools/descriptors/web-search.d.ts +15 -0
  227. package/dist/tools/descriptors/winter-list-agents.d.ts +1 -0
  228. package/dist/tools/descriptors/winter-send-message.d.ts +1 -0
  229. package/dist/tools/descriptors/workflow.d.ts +1 -0
  230. package/dist/tools/descriptors/write.d.ts +1 -0
  231. package/dist/tools/impl/_caller.d.ts +14 -0
  232. package/dist/tools/impl/_domains.d.ts +25 -0
  233. package/dist/tools/impl/_exa-client.d.ts +122 -0
  234. package/dist/tools/impl/_exa-session-client.d.ts +23 -0
  235. package/dist/tools/impl/_inner-model.d.ts +135 -0
  236. package/dist/tools/impl/_search-budget.d.ts +36 -0
  237. package/dist/tools/impl/_web-fetch-cache.d.ts +37 -0
  238. package/dist/tools/impl/_web-fetch-html.d.ts +26 -0
  239. package/dist/tools/impl/_web-fetch-net.d.ts +99 -0
  240. package/dist/tools/impl/_web-search-assembler.d.ts +57 -0
  241. package/dist/tools/impl/advisor.d.ts +37 -0
  242. package/dist/tools/impl/agent.d.ts +10 -0
  243. package/dist/tools/impl/ask-user-question.d.ts +5 -0
  244. package/dist/tools/impl/background-task-runtime.d.ts +272 -0
  245. package/dist/tools/impl/bash.d.ts +78 -0
  246. package/dist/tools/impl/cron.d.ts +11 -0
  247. package/dist/tools/impl/edit.d.ts +1 -0
  248. package/dist/tools/impl/enter-plan-mode.d.ts +4 -0
  249. package/dist/tools/impl/enter-worktree.d.ts +25 -0
  250. package/dist/tools/impl/exit-plan-mode.d.ts +4 -0
  251. package/dist/tools/impl/exit-worktree.d.ts +4 -0
  252. package/dist/tools/impl/glob.d.ts +1 -0
  253. package/dist/tools/impl/grep.d.ts +19 -0
  254. package/dist/tools/impl/index.d.ts +37 -0
  255. package/dist/tools/impl/list-agents.d.ts +7 -0
  256. package/dist/tools/impl/list-mcp-resources-tool.d.ts +9 -0
  257. package/dist/tools/impl/monitor.d.ts +66 -0
  258. package/dist/tools/impl/notebook-edit.d.ts +1 -0
  259. package/dist/tools/impl/push-notification.d.ts +4 -0
  260. package/dist/tools/impl/read-ladder.d.ts +25 -0
  261. package/dist/tools/impl/read-mcp-resource-dir-tool.d.ts +9 -0
  262. package/dist/tools/impl/read-mcp-resource-tool.d.ts +9 -0
  263. package/dist/tools/impl/read-notifications.d.ts +5 -0
  264. package/dist/tools/impl/read.d.ts +44 -0
  265. package/dist/tools/impl/refresh-mcp-tools.d.ts +8 -0
  266. package/dist/tools/impl/report-findings.d.ts +1 -0
  267. package/dist/tools/impl/schedule-wakeup.d.ts +2 -0
  268. package/dist/tools/impl/send-message.d.ts +7 -0
  269. package/dist/tools/impl/skill.d.ts +5 -0
  270. package/dist/tools/impl/task-graph.d.ts +1 -0
  271. package/dist/tools/impl/task-output.d.ts +16 -0
  272. package/dist/tools/impl/task-stop.d.ts +11 -0
  273. package/dist/tools/impl/todo-write.d.ts +8 -0
  274. package/dist/tools/impl/tool-search.d.ts +4 -0
  275. package/dist/tools/impl/wait-for-mcp-servers.d.ts +29 -0
  276. package/dist/tools/impl/web-fetch.d.ts +36 -0
  277. package/dist/tools/impl/web-search.d.ts +30 -0
  278. package/dist/tools/impl/workflow.d.ts +5 -0
  279. package/dist/tools/impl/write.d.ts +8 -0
  280. package/dist/tools/paths-seam.d.ts +6 -0
  281. package/dist/tools/read-state.d.ts +12 -0
  282. package/dist/tools/registry.d.ts +423 -0
  283. package/dist/tools/task-graph-store.d.ts +61 -0
  284. package/dist/toolsearch/aliases.d.ts +26 -0
  285. package/dist/toolsearch/exposure.d.ts +30 -0
  286. package/dist/toolsearch/ranking.d.ts +6 -0
  287. package/dist/toolsearch/search.d.ts +45 -0
  288. package/dist/version.d.ts +1 -0
  289. package/dist/version.js +5 -0
  290. package/dist/web/fetchable-url.d.ts +28 -0
  291. package/dist/web/preapproved-hosts.d.ts +52 -0
  292. package/dist/web/private-address.d.ts +55 -0
  293. package/dist/web/session-runtime.d.ts +86 -0
  294. package/dist/workflows/bridge.d.ts +87 -0
  295. package/dist/workflows/budget.d.ts +24 -0
  296. package/dist/workflows/host-registry.d.ts +142 -0
  297. package/dist/workflows/journal.d.ts +29 -0
  298. package/dist/workflows/meta.d.ts +45 -0
  299. package/dist/workflows/registry.d.ts +24 -0
  300. package/dist/workflows/runtime.d.ts +254 -0
  301. package/dist/workflows/sandbox.d.ts +49 -0
  302. package/dist/workflows/script-api.d.ts +58 -0
  303. package/dist/workflows/seam.d.ts +92 -0
  304. package/dist/workflows/semaphore.d.ts +16 -0
  305. package/dist/workflows/store.d.ts +177 -0
  306. package/dist/workflows/subprocess-entry.d.ts +38 -0
  307. package/dist/workflows/subprocess-entry.js +14 -0
  308. package/dist/workflows/transcript.d.ts +56 -0
  309. package/dist/workflows/types.d.ts +84 -0
  310. package/dist/workflows/worker-harness.d.ts +45 -0
  311. package/package.json +76 -0
@@ -0,0 +1,81 @@
1
+ import { type BrandProfile, type SettingSource } from "@yanlinglabs/winter-agent-sdk";
2
+ /**
3
+ * Winter's OWN instructions basename, derived from the default profile rather than spelled.
4
+ *
5
+ * Kept as a named export because it is what every caller that has not threaded a brand still means.
6
+ * A session's actual basename is `input.brand.instructionsFile` inside `discoverWinterMd` below.
7
+ */
8
+ export declare const WINTER_MD_BASENAME: string;
9
+ /**
10
+ * WS-21 §6.3 item 10 (F7): there is NO per-file byte ceiling here any more. Winter used to cap an
11
+ * instructions file at 32 KB (Norma's shipped cap); claude does not truncate `CLAUDE.md`, and the
12
+ * whole point of this workstream is that the two runtimes read the identical file the identical way.
13
+ * Removed rather than widened, so nothing downstream can quietly reintroduce a cap by reading this
14
+ * constant.
15
+ */
16
+ export interface WinterMdBlock {
17
+ /** Absolute path of the file this block came from. */
18
+ path: string;
19
+ /** `local` is the per-directory `<name>.local.md` (claude's `CLAUDE.local.md`), gated on the `local` source. */
20
+ scope: "user" | "project" | "local";
21
+ /**
22
+ * SDK 0.0.16: the file's CONTENT (capped, a literal `<system-reminder>` tag neutralised) --
23
+ * unwrapped, since it now renders as one entry of the index-0 userContext's `claudeMd` value
24
+ * (`renderInstructionsContext`) rather than as its own reminder block.
25
+ */
26
+ text: string;
27
+ }
28
+ /** `<name>.md` -> `<name>.local.md`: claude's `CLAUDE.local.md` convention with the session's own basename. */
29
+ export declare function localInstructionsBasename(instructionsFile: string): string;
30
+ /** TEST-ONLY: throwaway repositories at reused paths need this cleared. Production never calls it. */
31
+ export declare function _clearProjectRootCacheForTests(): void;
32
+ /**
33
+ * The root of the checkout `cwd` lives in -- `git rev-parse --show-toplevel`, which for a LINKED
34
+ * WORKTREE is that worktree's own directory (not the main checkout, and not the common dir).
35
+ * `null` when `cwd` is not inside a repository, or git is unavailable: with no repository there is
36
+ * no defensible upper bound for a parent-walk, so the caller reads the cwd alone rather than
37
+ * climbing toward `/`.
38
+ */
39
+ export declare function projectInstructionRoot(cwd: string): string | null;
40
+ export interface WinterMdInput {
41
+ cwd: string;
42
+ /** The `~/.winter` root. */
43
+ home: string;
44
+ /** Omitted means the pinned default: all three tiers. `[]` reads nothing. */
45
+ settingSources?: readonly SettingSource[];
46
+ /** P7a (D19): the session's brand. Omitted = `WINTER_BRAND`, i.e. today's `WINTER_MD_BASENAME`. */
47
+ brand?: Pick<BrandProfile, "instructionsFile">;
48
+ /**
49
+ * WS-21 §6.3 item 2: UNCONDITIONAL rules (`context/rules.ts`'s `loadRules(...).unconditional`),
50
+ * rendered as additional blocks AFTER every instructions file -- rules are standing context of
51
+ * the identical kind an instructions file is, just organised one file per rule instead of a
52
+ * single instructions basename. A CONDITIONAL rule never belongs here: it rides the on-touch attachment
53
+ * (`conditionalRuleAttachmentProducer`) instead, appearing only once a matching file is touched.
54
+ */
55
+ rules?: readonly {
56
+ path: string;
57
+ tier: "user" | "project";
58
+ content: string;
59
+ }[];
60
+ }
61
+ /**
62
+ * The instructions blocks for a session, in the PINNED ORDER: the user-level file first, then every
63
+ * project file from the repository root down to the cwd, then every unconditional rule.
64
+ *
65
+ * User-first is deliberate. The user's own file under the winter home is standing preference; a
66
+ * project's file is specific to the work in front of the model. Reading the specific thing last
67
+ * matches the outermost-first rule the project walk already follows, so one rule covers the whole
68
+ * ordering rather than two that could drift. Rules come last because they are the most granular
69
+ * tier -- narrower in scope than either instructions file, the same reason a project file already
70
+ * reads after the user's.
71
+ */
72
+ export declare function discoverWinterMd(input: WinterMdInput): WinterMdBlock[];
73
+ export declare const INSTRUCTIONS_CONTEXT_HEADER = "Codebase and user instructions are shown below. Be sure to adhere to these instructions. IMPORTANT: These instructions OVERRIDE any default behavior and you MUST follow them exactly as written.";
74
+ export type InstructionsContextKind = WinterMdBlock["scope"] | "auto-memory";
75
+ export interface InstructionsContextFile {
76
+ path: string;
77
+ kind: InstructionsContextKind;
78
+ content: string;
79
+ }
80
+ /** The `claudeMd` userContext value, or `undefined` when no file has content (the key is then omitted). */
81
+ export declare function renderInstructionsContext(files: readonly InstructionsContextFile[]): string | undefined;
@@ -0,0 +1,48 @@
1
+ import type { SpawnedRuntimeProcess, SpawnRuntimeOptions } from "@yanlinglabs/winter-agent-sdk";
2
+ import type { EmbeddedWorkflowWorkerCommand } from "./embedded-protocol.js";
3
+ export type { EmbeddedHostMessage, EmbeddedWorkerMessage, EmbeddedWorkflowWorkerCommand } from "./embedded-protocol.js";
4
+ /**
5
+ * How long `kill()` lets an aborted session unwind before `terminate()`.
6
+ *
7
+ * The abort itself is fast -- process groups die synchronously, the turn is interrupted, the engine's
8
+ * teardown is milliseconds -- so this is a BACKSTOP for a Worker that cannot answer (stuck in
9
+ * synchronous code, or a turn the interrupt could not reach). Long enough that an ordinary abort always
10
+ * finishes inside it: a graceful end closes the transcript lease and MCP clients, which `terminate()`
11
+ * cannot. A host with its own shutdown budget calls `terminate()` itself when that budget runs out.
12
+ */
13
+ export declare const EMBEDDED_KILL_GRACE_MS = 1500;
14
+ export interface SpawnEmbeddedWorkerOptions {
15
+ /**
16
+ * The Worker entry as THIS host must spell it. In a `bun build --compile` binary that is the plain
17
+ * relative path of the host's own worker file as it was passed to `--compile` (`"./embedded-worker.ts"`
18
+ * beside the main entry) -- a `new URL(…, import.meta.url).href` hangs there. In dev, an absolute path.
19
+ */
20
+ workerEntry: string;
21
+ /** What `query()` handed the spawn hook: `args` (the argv), `env` (the session's whole environment). */
22
+ spawn: SpawnRuntimeOptions;
23
+ /** The workflow worker's spawn command, forwarded to the session (see `workflows/sandbox.ts`). */
24
+ workflowWorkerCommand?: EmbeddedWorkflowWorkerCommand;
25
+ /** Default `EMBEDDED_KILL_GRACE_MS`. */
26
+ killGraceMs?: number;
27
+ /** Test seam over the Worker constructor. The default is `new Worker(entry, { env })`. */
28
+ createWorker?: (entry: string, env: Record<string, string>) => Worker;
29
+ /**
30
+ * Hold the `start` message until this settles (either way). The Worker is constructed at once and
31
+ * buffers stdin meanwhile, but NO engine runs until then. For a host that must not overlap two
32
+ * incarnations of one session on one transcript: every Worker shares the host's pid, so the
33
+ * transcript lease cannot keep them apart -- the host passes the previous incarnation's `exited`.
34
+ */
35
+ startAfter?: Promise<unknown>;
36
+ }
37
+ export interface EmbeddedWorkerProcess extends SpawnedRuntimeProcess {
38
+ /** Hard stop NOW -- the backstop `kill()` arms, exposed for a host whose own budget ran out. Idempotent. */
39
+ terminate(): void;
40
+ /** `running` → (`kill()`) `stopping` → `closed`. `closed` means `exited` has settled. */
41
+ readonly state: "running" | "stopping" | "closed";
42
+ }
43
+ /**
44
+ * Construct the Worker, send `start`, and return the process handle. Never throws for a Worker that
45
+ * fails to LOAD (an unresolvable entry is an `error` event + `close`, measured) -- that surfaces as an
46
+ * exit with code 1 and the reason on `stderr`, which the wrapper maps to "exited before init".
47
+ */
48
+ export declare function spawnEmbeddedWorker(opts: SpawnEmbeddedWorkerOptions): EmbeddedWorkerProcess;
@@ -0,0 +1,155 @@
1
+ import {
2
+ Queue
3
+ } from "./index-97t2rmtf.js";
4
+
5
+ // src/embedded-host.ts
6
+ var EMBEDDED_KILL_GRACE_MS = 1500;
7
+ var CLOSE_AFTER_EXIT_MS = 2000;
8
+ function describeError(event) {
9
+ const e = event;
10
+ if (e?.error instanceof Error && e.error.message !== "")
11
+ return e.error.message;
12
+ if (typeof e?.message === "string" && e.message !== "") {
13
+ const lines = e.message.split(`
14
+ `).map((l) => l.trim()).filter((l) => l !== "");
15
+ const errorLine = lines.find((l) => /^(\w*Error|error):/.test(l));
16
+ return (errorLine ?? lines[0] ?? e.message).slice(0, 500);
17
+ }
18
+ return "unknown worker error";
19
+ }
20
+ function spawnEmbeddedWorker(opts) {
21
+ const stdout = new Queue;
22
+ const stderr = new Queue;
23
+ const graceMs = opts.killGraceMs ?? EMBEDDED_KILL_GRACE_MS;
24
+ let state = "running";
25
+ let exitCode;
26
+ let crashed = false;
27
+ let terminatedByHost = false;
28
+ let stdinEnded = false;
29
+ let graceTimer;
30
+ let closeTimer;
31
+ let settleExited;
32
+ const exited = new Promise((resolve) => {
33
+ settleExited = resolve;
34
+ });
35
+ const worker = (opts.createWorker ?? ((entry, env) => new Worker(entry, { env })))(opts.workerEntry, opts.spawn.env);
36
+ const send = (message) => {
37
+ if (state === "closed")
38
+ return;
39
+ try {
40
+ worker.postMessage(message);
41
+ } catch {}
42
+ };
43
+ const onClosed = () => {
44
+ if (state === "closed")
45
+ return;
46
+ state = "closed";
47
+ if (graceTimer !== undefined)
48
+ clearTimeout(graceTimer);
49
+ if (closeTimer !== undefined)
50
+ clearTimeout(closeTimer);
51
+ stdout.end();
52
+ stderr.end();
53
+ if (crashed)
54
+ settleExited({ code: 1, signal: null });
55
+ else if (exitCode !== undefined)
56
+ settleExited({ code: exitCode, signal: null });
57
+ else if (terminatedByHost)
58
+ settleExited({ code: null, signal: "SIGKILL" });
59
+ else
60
+ settleExited({ code: 1, signal: null });
61
+ };
62
+ const terminate = () => {
63
+ if (state === "closed")
64
+ return;
65
+ if (exitCode === undefined)
66
+ terminatedByHost = true;
67
+ try {
68
+ worker.terminate();
69
+ } catch {}
70
+ };
71
+ worker.onmessage = (event) => {
72
+ const message = event.data;
73
+ switch (message.kind) {
74
+ case "stdout":
75
+ stdout.write(message.chunk);
76
+ return;
77
+ case "stderr":
78
+ stderr.write(message.chunk);
79
+ return;
80
+ case "exit":
81
+ exitCode = message.code;
82
+ closeTimer = setTimeout(terminate, CLOSE_AFTER_EXIT_MS);
83
+ closeTimer.unref?.();
84
+ return;
85
+ }
86
+ };
87
+ worker.onerror = (event) => {
88
+ crashed = exitCode === undefined;
89
+ try {
90
+ event.preventDefault?.();
91
+ } catch {}
92
+ stderr.write(`winter: embedded runtime worker failed: ${describeError(event)}
93
+ `);
94
+ terminate();
95
+ };
96
+ worker.addEventListener("messageerror", () => {
97
+ crashed = exitCode === undefined;
98
+ stderr.write(`winter: embedded runtime worker sent a message the host could not decode
99
+ `);
100
+ terminate();
101
+ });
102
+ worker.addEventListener("close", onClosed);
103
+ const start = { kind: "start", argv: [...opts.spawn.args], ...opts.workflowWorkerCommand !== undefined ? { workflowWorkerCommand: opts.workflowWorkerCommand } : {} };
104
+ if (opts.startAfter === undefined)
105
+ send(start);
106
+ else
107
+ opts.startAfter.then(() => send(start), () => send(start));
108
+ const kill = (_signal) => {
109
+ if (state !== "running") {
110
+ return;
111
+ }
112
+ state = "stopping";
113
+ send({ kind: "abort" });
114
+ if (!stdinEnded) {
115
+ stdinEnded = true;
116
+ send({ kind: "stdin-end" });
117
+ }
118
+ graceTimer = setTimeout(terminate, graceMs);
119
+ graceTimer.unref?.();
120
+ };
121
+ if (opts.spawn.signal !== undefined) {
122
+ if (opts.spawn.signal.aborted)
123
+ kill();
124
+ else
125
+ opts.spawn.signal.addEventListener("abort", () => kill(), { once: true });
126
+ }
127
+ return {
128
+ stdin: {
129
+ write(chunk) {
130
+ if (stdinEnded)
131
+ return;
132
+ send({ kind: "stdin", chunk });
133
+ },
134
+ end() {
135
+ if (stdinEnded)
136
+ return;
137
+ stdinEnded = true;
138
+ send({ kind: "stdin-end" });
139
+ }
140
+ },
141
+ stdout,
142
+ stderr,
143
+ kill,
144
+ terminate,
145
+ exited,
146
+ pid: null,
147
+ get state() {
148
+ return state;
149
+ }
150
+ };
151
+ }
152
+ export {
153
+ EMBEDDED_KILL_GRACE_MS,
154
+ spawnEmbeddedWorker
155
+ };
@@ -0,0 +1,44 @@
1
+ /** A worker-side spawn command (the workflow worker's `(file, args)`), structurally `workflows/sandbox.ts`'s `WorkerCommand`. */
2
+ export interface EmbeddedWorkflowWorkerCommand {
3
+ file: string;
4
+ args: string[];
5
+ }
6
+ /** Host → Worker. `start` is sent exactly once, first; everything else may follow in any order. */
7
+ export type EmbeddedHostMessage = {
8
+ kind: "start";
9
+ /** The same argv a spawned child gets (`--run --config-json <json>`); found by flag NAME, never by position. */
10
+ argv: string[];
11
+ /**
12
+ * The workflow worker's spawn command as the HOST must spell it. Absent = the runtime's own
13
+ * default (`process.execPath __workflow-worker --bridge`), which is WRONG inside a host binary
14
+ * whose main routes `__workflow-worker` somewhere else -- see `workflows/sandbox.ts`.
15
+ */
16
+ workflowWorkerCommand?: EmbeddedWorkflowWorkerCommand;
17
+ } | {
18
+ kind: "stdin";
19
+ chunk: string;
20
+ } | {
21
+ kind: "stdin-end";
22
+ }
23
+ /** The embedded SIGTERM: kill background process groups, end the turn, let the engine return. */
24
+ | {
25
+ kind: "abort";
26
+ };
27
+ /** Worker → Host. `exit` is the last message a healthy Worker posts; the Worker closes right after it. */
28
+ export type EmbeddedWorkerMessage = {
29
+ kind: "stdout";
30
+ chunk: string;
31
+ } | {
32
+ kind: "stderr";
33
+ chunk: string;
34
+ } | {
35
+ kind: "exit";
36
+ code: number;
37
+ };
38
+ /**
39
+ * The request ids of the two control frames an ABORT synthesizes (`embedded.ts`). Fixed strings, not
40
+ * UUIDs, so the output filter can recognise their acknowledgements without state: no host ever
41
+ * mints a request id in this namespace (the wrapper uses `randomUUID()`).
42
+ */
43
+ export declare const EMBEDDED_ABORT_END_INPUT_REQUEST_ID = "embedded-abort:end_input";
44
+ export declare const EMBEDDED_ABORT_INTERRUPT_REQUEST_ID = "embedded-abort:interrupt";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import"./index-9qgkpv56.js";
2
+ import"./index-bef62z3r.js";
3
+ import"./index-584yahed.js";
4
+ import {
5
+ runEmbeddedSession2
6
+ } from "./index-rkhh0457.js";
7
+ import {
8
+ Queue
9
+ } from "./index-97t2rmtf.js";
10
+
11
+ // src/embedded-worker.ts
12
+ import { isMainThread } from "node:worker_threads";
13
+ function post(message) {
14
+ postMessage(message);
15
+ }
16
+ function fenceProcessWideState() {
17
+ const readUmask = process.umask.bind(process);
18
+ process.chdir = (directory) => {
19
+ throw new Error(`process.chdir(${JSON.stringify(directory)}) is refused inside an embedded Winter session: the working directory is process-wide and the host daemon's; pass the session cwd explicitly instead`);
20
+ };
21
+ process.umask = (mask) => {
22
+ if (mask !== undefined)
23
+ throw new Error("process.umask(mask) is refused inside an embedded Winter session: the file-mode mask is process-wide and the host daemon's");
24
+ return readUmask();
25
+ };
26
+ }
27
+ function installEmbeddedWorker() {
28
+ fenceProcessWideState();
29
+ const input = new Queue;
30
+ const abort = new AbortController;
31
+ let started = false;
32
+ const run = async (start) => {
33
+ let code = 1;
34
+ try {
35
+ code = await runEmbeddedSession2({
36
+ argv: start.argv,
37
+ env: process.env,
38
+ input,
39
+ write: (chunk) => post({ kind: "stdout", chunk }),
40
+ writeErr: (chunk) => post({ kind: "stderr", chunk }),
41
+ signal: abort.signal,
42
+ ...start.workflowWorkerCommand !== undefined ? { workflowWorkerCommand: start.workflowWorkerCommand } : {}
43
+ });
44
+ } catch (err) {
45
+ post({ kind: "stderr", chunk: `winter: fatal (embedded worker): ${err instanceof Error ? err.stack ?? err.message : String(err)}
46
+ ` });
47
+ code = 1;
48
+ }
49
+ post({ kind: "exit", code });
50
+ process.exit(code);
51
+ };
52
+ self.onmessage = (event) => {
53
+ const message = event.data;
54
+ switch (message.kind) {
55
+ case "start":
56
+ if (started)
57
+ return;
58
+ started = true;
59
+ run(message);
60
+ return;
61
+ case "stdin":
62
+ input.write(message.chunk);
63
+ return;
64
+ case "stdin-end":
65
+ input.end();
66
+ return;
67
+ case "abort":
68
+ abort.abort();
69
+ return;
70
+ }
71
+ };
72
+ }
73
+ if (!isMainThread)
74
+ installEmbeddedWorker();
@@ -0,0 +1,34 @@
1
+ import { type WorkerCommand } from "./workflows/sandbox.js";
2
+ export interface EmbeddedSessionOptions {
3
+ /** The spawn argv (`--run --config-json <json>`, any leading slots); flags are found by NAME. */
4
+ argv: readonly string[];
5
+ /**
6
+ * The session's environment -- THE ONLY place its homes come from beside the config. A host running
7
+ * this in a Worker passes the Worker's own `process.env` (set by the Worker's `env` option), which is
8
+ * also what Bash/Monitor/stdio-MCP children inherit.
9
+ */
10
+ env: Record<string, string | undefined>;
11
+ /** stdin as text chunks; framing (NDJSON split) happens here, through the one shared codec. */
12
+ input: AsyncIterable<string>;
13
+ /** stdout: receives encoded frames only, never a diagnostic (WS-04 §2/§6). */
14
+ write: (chunk: string) => void;
15
+ /** stderr: wiring warnings and the fatal line. Never a frame. */
16
+ writeErr: (chunk: string) => void;
17
+ /**
18
+ * The embedded SIGTERM. On abort: background process groups are killed at once (as `main.ts`'s
19
+ * SIGTERM handler does), then the engine is told to stop -- the input closes, the running turn is
20
+ * interrupted -- and this function still resolves only after `runEngine` has RETURNED. That last
21
+ * part is the contract a host relies on: the transcript lease is keyed by (projectKey, sessionId)
22
+ * and stamped with the pid, and every Worker shares the host's pid, so the lock cannot tell an old
23
+ * incarnation from a new one. Only "the old engine has returned" makes a resume safe.
24
+ */
25
+ signal?: AbortSignal;
26
+ /** The workflow worker's spawn command for this session (see `setHostWorkflowWorkerCommand`). */
27
+ workflowWorkerCommand?: WorkerCommand;
28
+ }
29
+ /**
30
+ * Run ONE Winter session to completion and return its exit code: `runEngine`'s own code, or `1` when
31
+ * the session could not start (the fatal line is on `writeErr`, mirroring a child that exits before
32
+ * init -- WS-04 §6.1). Never throws.
33
+ */
34
+ export declare function runEmbeddedSession(opts: EmbeddedSessionOptions): Promise<number>;
@@ -0,0 +1,9 @@
1
+ import {
2
+ runEmbeddedSession2
3
+ } from "./index-rkhh0457.js";
4
+ import"./index-584yahed.js";
5
+ import"./index-9qgkpv56.js";
6
+ import"./index-bef62z3r.js";
7
+ export {
8
+ runEmbeddedSession2 as runEmbeddedSession
9
+ };