@reinsjs/brain 0.8.8 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @reinsjs/brain
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f8a3550: `budget()` pauses with `code: "reins.budget"` (`BUDGET_PAUSE_CODE`; pass `code: (hits) => string` to compute your own; pause codes are lowercase, so lowercase a dimension name before using it) and `compact()` pauses on its consecutive-compaction limit with `code: "reins.compact_stalled"` (`COMPACT_STALLED_PAUSE_CODE`). Both still use `reason: "budget"`; the code is what tells them apart afterwards.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [f8a3550]
12
+ - @reinsjs/core@0.15.0
13
+
3
14
  ## 0.8.8
4
15
 
5
16
  ### Patch Changes
package/README.md CHANGED
@@ -35,13 +35,13 @@ const agent = createAgent({
35
35
  | module | what the model gets | what it costs you |
36
36
  | --- | --- | --- |
37
37
  | `perception()` | A `system_note` at the end of the timeline with context usage, history length and budget headroom, in coarse tiers so it does not change every turn (cache-friendly). Calibrated against the last real `budget_usage`. | nothing |
38
- | `compact()` | A `compact` tool: the model summarizes a range of old turns itself; the summary carries a manifest of the folded tool results and a `recall({ seq })` tool fetches any of them back verbatim. When the window passes 75% and the model has not compacted since the last fold, it appends a note asking the model to compact first, and asks once more, more bluntly, at 80% (`decidedBy: "forced"`; `force: false` turns this off, `force: { at, render, directive }` tunes it — `at` takes one ratio or an ascending list). The request is marked as a directive, so lowerings deliver it as a tagged user note even where mid-conversation system messages are accepted: some upstreams accept those but do not act on instructions inside them. If the model still does not compact, a threshold fallback at 85% folds the oldest turns down to 60%. **Recommended on** since 2026-09-10: measured on DeepSeek and Claude, recall stayed at 100% while tokens went down. | a `BlobStore` is not required |
38
+ | `compact()` | A `compact` tool: the model summarizes a range of old turns itself; the summary carries a manifest of the folded tool results and a `recall({ seq })` tool fetches any of them back verbatim. When the window passes 75% and the model has not compacted since the last fold, it appends a note asking the model to compact first, and asks once more, more bluntly, at 80% (`decidedBy: "forced"`; `force: false` turns this off, `force: { at, render, directive }` tunes it — `at` takes one ratio or an ascending list). The request is marked as a directive, so lowerings deliver it as a tagged user note even where mid-conversation system messages are accepted: some upstreams accept those but do not act on instructions inside them. If the model still does not compact, a threshold fallback at 85% folds the oldest turns down to 60%. Compacting `maxConsecutive` (default 3) times in a row without a turn of progress pauses the run with `reason: "budget"` and `code: "reins.compact_stalled"`. **Recommended on** since 2026-09-10: measured on DeepSeek and Claude, recall stayed at 100% while tokens went down. | a `BlobStore` is not required |
39
39
  | `pins()` | Host-declared constraints (static text or extracted from the conversation) plus a `pin` tool. Pinned notes survive compaction and are re-injected when they scroll out. A host spec can also be a **resident snapshot** (`{ name, snapshot }`, sync or async): taken at the start of each segment — the session's first turn and the first turn after every compaction — and appended only when it differs from the copy in view, so an index of the model's memory stays at hand without being rewritten mid-task (see below). | nothing |
40
40
  | `spill()` | Tool results above a size limit are stored whole in the `BlobStore`; the model sees head + tail + a blob id and pages through with `fetch_blob`. Without a `BlobStore` the module warns once and passes results through unchanged (no silent truncation). | a `BlobStore` |
41
41
  | `handoff()` | A `handoff` tool: the model writes a summary and next steps and moves to a fresh session; visible pins travel along. The mechanics (new session, opening note) are in the core loop. **Off by default** — turn it on when tasks routinely outlive one context window. | host must rebind the UI to the new session (`onHandoff`) |
42
42
  | `memory()` | A `memory` tool shaped like Anthropic's `memory_20250818` (view / create / str_replace / insert / delete / rename under `/memories`). Every operation leaves a `memory_op` event. Isolation is by `namespace`, invisible to the model. If your store routes memory into layers (`/memories/personal`, `/memories/project`, …), declare them as `directories` so an empty layer views as an empty directory instead of "does not exist", and shows up when the model views `/memories`. **Off by default.** | a `MemoryStore` |
43
43
  | `approval()` | A deny → ask → allow policy pipeline in `beforeTool`. `deny` leaves an `approval_decision` and blocks; `ask` pauses the run for a human; `allow` leaves no event. Default policy `byRisk`: tools without a declared `risk` are treated as medium and **ask** — mark read-only tools `risk: "low"`. Policy evaluation errors deny (fail-closed). `ttlMs` gives approvals a lifetime: one that arrives later than that (measured between the `approval_request` and the host's `approval_decision` on the timeline) is not honoured — the call is denied with `by: "approval.expired"` and a message telling the model it may re-issue the call for a fresh approval. | nothing |
44
- | `budget()` | Five limits — `contextTokens`, `totalTokens`, `turns`, `toolCalls`, `wallMs` — checked in `onTurnEnd`. Hitting one while the model wants to continue pauses the run with `reason: "budget"`; resuming starts a fresh run budget. `totalTokens` includes what sub-agents spent through `asTool`. | nothing |
44
+ | `budget()` | Five limits — `contextTokens`, `totalTokens`, `turns`, `toolCalls`, `wallMs` — checked in `onTurnEnd`. Hitting one while the model wants to continue pauses the run with `reason: "budget"` and `code: "reins.budget"` (pass `code: (hits) => string` to compute your own — pause codes are lowercase, so lowercase a dimension name before using it); resuming starts a fresh run budget. `totalTokens` includes what sub-agents spent through `asTool`. | nothing |
45
45
  | `skills()` | [Agent Skills](https://agentskills.io) with progressive disclosure: the system prompt carries only a menu (each `SKILL.md`'s `name` + `description`); the model reads a skill, or one of its supporting files, with `skill_read({ name, path?, range? })`, and the text lands in the timeline as a `tool_result` — so compaction, `recall` and spill apply to it unchanged. Skills are host-authored, so `skill_read` results are trusted like the system prompt (no `<untrusted>` marker). Skills that fail the spec (bad `name`, missing `description`) are skipped with one warning; no `source`, no valid skill, or a host tool already named `skill_read` means nothing is registered (one warning). **Opt-in**: give it a `source`. | a `SkillSource` — the read-only half of any `MemoryStore` (see below), `fsSkillSource(dir)` from `@reinsjs/brain/node` for a folder of `<name>/SKILL.md`, or `inlineSkills({ "code-review": "---\nname: code-review\ndescription: How we review PRs.\n---\n\n1. …" })` for bundled strings (Workers) — the object key must equal the frontmatter `name` |
46
46
  | `lazyTools()` | Tool discovery for large tool tables — the consumer of `Tool.lazy`. Tools marked `lazy: true` appear in the system prompt only as a menu (`name: one-line summary`, first line of the description by default); the model loads the ones a task needs with `tool_find({ names })`, which returns each tool's full description and input schema, and from the next turn on those tools are in the request's tool list. Which tools are loaded is rebuilt from the timeline (the `tool_find` calls and their non-error results), so pause / resume, later runs on the same session and process restarts agree. Calling a listed-but-unloaded tool is blocked with a pointer to `tool_find`. The menu is built from the tools bound *before* this socket — the host's and those of sockets registered earlier, e.g. `mcpTools({ override: (t, info) => info.annotations?.readOnlyHint ? { ...t, lazy: true } : false })` — so register `lazyTools()` last; `lazy` tools from later sockets are never hidden, one warning names them. No `lazy` tool bound before it, or a tool already named `tool_find`: nothing registered, one warning. **Opt-in**: install it. | `summarize(tool)` to replace the default summary, `summaryChars` (160), `maxPerCall` (20), `rules`, `warn` |
47
47
  | `haltOnFailure()` | Models put several calls in one reply to save round trips, and the order is often a dependency: update the item, *then* tell the team it is ready. The model cannot make the second call conditional on the first — it does not see results inside one reply. With this module, once a call in the batch has failed (or is still waiting for approval or a client result), the calls after it are not run: each gets an error result naming the earlier call and asking the model to handle it first. Tool call ids stay one-to-one, nothing is executed, nothing counts toward the `toolCalls` budget. `counts(result)` picks which failures matter, `applies(call, tool)` which later calls to hold back (e.g. let `risk: "low"` reads run). Register it **first**. **Opt-in.** | nothing |
package/dist/index.d.ts CHANGED
@@ -154,8 +154,8 @@ declare const APPROVAL_EXPIRY_RULE = "- An approval can expire if it arrives too
154
154
  * contextTokens(单次请求送进模型的上下文大小)、totalTokens(本次 run 累计输入 + 输出)、turns、toolCalls、wallMs。
155
155
  *
156
156
  * 做法:`onTurnEnd` 里对照 `ctx.budget`(循环在模型调用后已更新 tokensSpent / wallMs / lastUsage),任一维 **用量 ≥ 上限**
157
- * 即返回 `{ pause: { reason: "budget", note } }`,循环 append `run_paused(reason=budget)` 并以 paused 返回,note 进
158
- * `Interruption` 给宿主看。只在模型本轮还要继续(有工具调用)时拦:模型已经收尾作答的轮,循环本来就要停,
157
+ * 即返回 `{ pause: { reason: "budget", code, note } }`,循环 append `run_paused(reason=budget)` 并以 paused 返回,note 进
158
+ * `Interruption` 给宿主看;原因码 `code`(缺省 `BUDGET_PAUSE_CODE`)随暂停落库,事后与"连续整理失败""宿主自己的配额"分得开。只在模型本轮还要继续(有工具调用)时拦:模型已经收尾作答的轮,循环本来就要停,
159
159
  * 把一个自然结束的 run 改成"暂停"只会让宿主续跑一个没事可做的会话。
160
160
  *
161
161
  * 上限是**每次 run** 的:宿主续跑(同一 sessionId 再起 runLoop)即视为再批一份预算,`ctx.budget` 从零计。
@@ -189,8 +189,16 @@ interface BudgetOptions {
189
189
  limits: BudgetLimits;
190
190
  /** 暂停说明(给宿主看,进 Interruption.note);缺省英文一句话列出触顶的维度 */
191
191
  note?: (hits: readonly BudgetHit[]) => string;
192
+ /**
193
+ * 暂停原因码(AdRate 建议 16),缺省恒为 `BUDGET_PAUSE_CODE`。缺省不把维度编进码里:可能多维同时触顶,一个码装不下;
194
+ * 要按维度区分的宿主在这里自己算(如 `(hits) => \`acme.budget.${hits[0].dimension.toLowerCase()}\``——维度名带大写,要先转小写)。
195
+ * 返回值须满足 core 的 `PAUSE_CODE_RE`(只收小写),否则码被丢掉、记一条非终结 `core.error`,暂停照常
196
+ */
197
+ code?: (hits: readonly BudgetHit[]) => string;
192
198
  }
193
199
  declare const BUDGET_SOCKET_NAME = "budget";
200
+ /** 本模块暂停时的缺省原因码(`reins.` 前缀留给内置来源) */
201
+ declare const BUDGET_PAUSE_CODE = "reins.budget";
194
202
  /** 上限必须是正的有限数;构造期就拒绝,免得跑起来才发现"0 上限"把一切都拦了 */
195
203
  declare function assertLimits(limits: BudgetLimits): void;
196
204
  /** 各维当前用量;contextTokens 没有真实用量(还没请求过)时为 undefined */
@@ -406,6 +414,8 @@ interface CompactOptions {
406
414
  }
407
415
  declare const COMPACT_SOCKET_NAME = "compact";
408
416
  declare const DEFAULT_MAX_CONSECUTIVE_COMPACTIONS = 3;
417
+ /** 连续整理达到上限而暂停时的原因码(AdRate 建议 16):reason 仍是 budget,靠它与预算触顶分开 */
418
+ declare const COMPACT_STALLED_PAUSE_CODE = "reins.compact_stalled";
409
419
  declare const COMPACT_INPUT_SCHEMA: {
410
420
  readonly type: "object";
411
421
  readonly properties: {
@@ -1590,4 +1600,4 @@ interface StopAfterOptions {
1590
1600
  }
1591
1601
  declare function stopAfter(opts: StopAfterOptions): Socket;
1592
1602
 
1593
- export { APPROVAL_EXPIRY_RULE, APPROVAL_POLICY_IDS, APPROVAL_RULES, APPROVAL_SOCKET_NAME, type ApprovalOptions, BUDGET_SOCKET_NAME, type BudgetDimension, type BudgetHit, type BudgetLimits, type BudgetOptions, COMPACT_INPUT_SCHEMA, COMPACT_REQUEST_RULE, COMPACT_RULES, COMPACT_SOCKET_NAME, COMPACT_TOOL_DESCRIPTION, COMPACT_TOOL_NAME, type CompactArgs, type CompactOptions, type CompactPlan, type CompactRequestInfo, DEFAULT_FORCE_AT, DEFAULT_HANDOFF_REASON, DEFAULT_LAZY_SUMMARY_CHARS, DEFAULT_MAX_CONSECUTIVE_COMPACTIONS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MAX_PIN_TEXT_LENGTH, DEFAULT_MAX_RESULT_TOKENS, DEFAULT_MAX_SUMMARY_CHARS, DEFAULT_MAX_VIEW_CHARS, DEFAULT_PERCEPTION_THRESHOLDS, DEFAULT_PIN_OVERSHOOT_TOLERANCE, DEFAULT_PREVIEW_CHARS, DEFAULT_PREVIEW_LINES, DEFAULT_SKILLS_ROOT, DEFAULT_SKILL_READ_CHARS, DEFAULT_TOOL_FIND_MAX, type ExpiredApproval, FETCH_BLOB_INPUT_SCHEMA, FETCH_BLOB_TOOL_DESCRIPTION, FETCH_BLOB_TOOL_NAME, type FetchBlobArgs, type ForceOptions, HALT_ON_FAILURE_SOCKET_NAME, HANDOFF_INPUT_SCHEMA, HANDOFF_RULES, HANDOFF_SOCKET_NAME, HANDOFF_TOOL_DESCRIPTION, HANDOFF_TOOL_NAME, type HaltOnFailureOptions, type HandoffArgs, type HandoffOptions, type InlineSkill, type InlineSkillsOptions, LAZY_TOOLS_SOCKET_NAME, LAZY_TOOL_RULES, type LazyToolMenu, type LazyToolMenuEntry, type LazyToolsOptions, type LimitDimension, type LoadedSkill, MANIFEST_DEFAULT_EXCLUDE, MANIFEST_HEADING, MAX_MEMORY_PATH_LENGTH, MAX_SKILL_DESCRIPTION_CHARS, MEMORY_COMMANDS, MEMORY_INPUT_SCHEMA, MEMORY_ROOT, MEMORY_RULES, MEMORY_SOCKET_NAME, MEMORY_TOOL_DESCRIPTION, MEMORY_TOOL_NAME, type ManifestOptions, type MemoryCommand, type MemoryFs, type MemoryLimits, type MemoryOp, type MemoryOptions, type MemoryOutcome, PERCEPTION_SOCKET_NAME, PINS_SOCKET_NAME, PIN_INPUT_SCHEMA, PIN_RULES, PIN_TOOL_DESCRIPTION, PIN_TOOL_NAME, type ParsedSkill, type PerceptionLimits, type PerceptionOptions, type PerceptionReading, type PinArgs, type PinMeta, type PinNote, type PinSpec, type PinsOptions, type PlanOptions, type PolicyCall, type PolicyOutcome, type PolicyRule, type PolicyRuleSpec, type PolicyVerdict, type Preview, type PreviewOptions, RECALL_INPUT_SCHEMA, RECALL_TOOL_DESCRIPTION, RECALL_TOOL_NAME, type ReadingOptions, type ReadingThresholds, type RecallArgs, SKILLS_SOCKET_NAME, SKILL_FILE_NAME, SKILL_NAME_RE, SKILL_READ_INPUT_SCHEMA, SKILL_READ_TOOL_DESCRIPTION, SKILL_READ_TOOL_NAME, SKILL_RULES, SPILL_BLOB_MIME, SPILL_RULES, SPILL_SOCKET_NAME, STOP_AFTER_SOCKET_NAME, type SkillFrontmatter, type SkillMenu, type SkillMenuEntry, type SkillReadInput, type SkillsOptions, type SpillOptions, type StopAfterOptions, TOOL_FIND_INPUT_SCHEMA, TOOL_FIND_TOOL_DESCRIPTION, TOOL_FIND_TOOL_NAME, type TextMeasure, type TextTokenEstimator, type Tier, type ToolFindInput, approval, assertAscending, assertLimits, assertSkillsRoot, bindMemoryFs, budget, budgetUsedOf, byteLength, carriedPins, checkBudget, clipEndByTokens, compact, compactNumber, compactRequestedSinceLastCompaction, compactRequestsSinceLastCompaction, composeHandoffNote, contextUsageRatio, countLines, countModelTurns, countTier, defaultBudgetNote, defaultSummary, defaultTextTokens, evaluatePolicy, executeMemoryCommand, expandMemoryDirectories, findExpiredApproval, findModelPin, fmt, globToRegExp, haltOnFailure, haltedText, handoff, humanSize, inlineSkills, isCompactRequest, isModelCompaction, isPinNoteEvent, isSnapshotPin, isTextMime, isUnder, lastHostPin, lastVisiblePerceptionNote, lastVisibleUserMessage, lazyMenuOf, lazyTools, loadSkillMenu, measureText, memory, modelActedSinceLastCompaction, normalizeRule, parseCompactArgs, parseFetchBlobArgs, parseHandoffArgs, parseMemoryCommand, parsePinArgs, parseRecallArgs, parseSkillMarkdown, parseSkillReadInput, parseToolFindInput, percent, perception, pinInputSchema, pinMetaOf, pinToolDescription, pins, planCompaction, previewOf, rangeTier, readPerception, recallResult, recallTool, renderCompactRequest, renderCompactionSummary, renderLazyToolMenu, renderLoadedTool, renderPerception, renderSkillMenu, renderToolFindResult, resolveMemoryPath, revealedLazyTools, segmentTimelineByTurn, skills, spill, stopAfter, sumSessionTokens, summarizeTool, timelineSoFar, toolFindResultBound, toolReferenceOf, trailingCompactionRun, unfinishedHandoffArgs };
1603
+ export { APPROVAL_EXPIRY_RULE, APPROVAL_POLICY_IDS, APPROVAL_RULES, APPROVAL_SOCKET_NAME, type ApprovalOptions, BUDGET_PAUSE_CODE, BUDGET_SOCKET_NAME, type BudgetDimension, type BudgetHit, type BudgetLimits, type BudgetOptions, COMPACT_INPUT_SCHEMA, COMPACT_REQUEST_RULE, COMPACT_RULES, COMPACT_SOCKET_NAME, COMPACT_STALLED_PAUSE_CODE, COMPACT_TOOL_DESCRIPTION, COMPACT_TOOL_NAME, type CompactArgs, type CompactOptions, type CompactPlan, type CompactRequestInfo, DEFAULT_FORCE_AT, DEFAULT_HANDOFF_REASON, DEFAULT_LAZY_SUMMARY_CHARS, DEFAULT_MAX_CONSECUTIVE_COMPACTIONS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MAX_PIN_TEXT_LENGTH, DEFAULT_MAX_RESULT_TOKENS, DEFAULT_MAX_SUMMARY_CHARS, DEFAULT_MAX_VIEW_CHARS, DEFAULT_PERCEPTION_THRESHOLDS, DEFAULT_PIN_OVERSHOOT_TOLERANCE, DEFAULT_PREVIEW_CHARS, DEFAULT_PREVIEW_LINES, DEFAULT_SKILLS_ROOT, DEFAULT_SKILL_READ_CHARS, DEFAULT_TOOL_FIND_MAX, type ExpiredApproval, FETCH_BLOB_INPUT_SCHEMA, FETCH_BLOB_TOOL_DESCRIPTION, FETCH_BLOB_TOOL_NAME, type FetchBlobArgs, type ForceOptions, HALT_ON_FAILURE_SOCKET_NAME, HANDOFF_INPUT_SCHEMA, HANDOFF_RULES, HANDOFF_SOCKET_NAME, HANDOFF_TOOL_DESCRIPTION, HANDOFF_TOOL_NAME, type HaltOnFailureOptions, type HandoffArgs, type HandoffOptions, type InlineSkill, type InlineSkillsOptions, LAZY_TOOLS_SOCKET_NAME, LAZY_TOOL_RULES, type LazyToolMenu, type LazyToolMenuEntry, type LazyToolsOptions, type LimitDimension, type LoadedSkill, MANIFEST_DEFAULT_EXCLUDE, MANIFEST_HEADING, MAX_MEMORY_PATH_LENGTH, MAX_SKILL_DESCRIPTION_CHARS, MEMORY_COMMANDS, MEMORY_INPUT_SCHEMA, MEMORY_ROOT, MEMORY_RULES, MEMORY_SOCKET_NAME, MEMORY_TOOL_DESCRIPTION, MEMORY_TOOL_NAME, type ManifestOptions, type MemoryCommand, type MemoryFs, type MemoryLimits, type MemoryOp, type MemoryOptions, type MemoryOutcome, PERCEPTION_SOCKET_NAME, PINS_SOCKET_NAME, PIN_INPUT_SCHEMA, PIN_RULES, PIN_TOOL_DESCRIPTION, PIN_TOOL_NAME, type ParsedSkill, type PerceptionLimits, type PerceptionOptions, type PerceptionReading, type PinArgs, type PinMeta, type PinNote, type PinSpec, type PinsOptions, type PlanOptions, type PolicyCall, type PolicyOutcome, type PolicyRule, type PolicyRuleSpec, type PolicyVerdict, type Preview, type PreviewOptions, RECALL_INPUT_SCHEMA, RECALL_TOOL_DESCRIPTION, RECALL_TOOL_NAME, type ReadingOptions, type ReadingThresholds, type RecallArgs, SKILLS_SOCKET_NAME, SKILL_FILE_NAME, SKILL_NAME_RE, SKILL_READ_INPUT_SCHEMA, SKILL_READ_TOOL_DESCRIPTION, SKILL_READ_TOOL_NAME, SKILL_RULES, SPILL_BLOB_MIME, SPILL_RULES, SPILL_SOCKET_NAME, STOP_AFTER_SOCKET_NAME, type SkillFrontmatter, type SkillMenu, type SkillMenuEntry, type SkillReadInput, type SkillsOptions, type SpillOptions, type StopAfterOptions, TOOL_FIND_INPUT_SCHEMA, TOOL_FIND_TOOL_DESCRIPTION, TOOL_FIND_TOOL_NAME, type TextMeasure, type TextTokenEstimator, type Tier, type ToolFindInput, approval, assertAscending, assertLimits, assertSkillsRoot, bindMemoryFs, budget, budgetUsedOf, byteLength, carriedPins, checkBudget, clipEndByTokens, compact, compactNumber, compactRequestedSinceLastCompaction, compactRequestsSinceLastCompaction, composeHandoffNote, contextUsageRatio, countLines, countModelTurns, countTier, defaultBudgetNote, defaultSummary, defaultTextTokens, evaluatePolicy, executeMemoryCommand, expandMemoryDirectories, findExpiredApproval, findModelPin, fmt, globToRegExp, haltOnFailure, haltedText, handoff, humanSize, inlineSkills, isCompactRequest, isModelCompaction, isPinNoteEvent, isSnapshotPin, isTextMime, isUnder, lastHostPin, lastVisiblePerceptionNote, lastVisibleUserMessage, lazyMenuOf, lazyTools, loadSkillMenu, measureText, memory, modelActedSinceLastCompaction, normalizeRule, parseCompactArgs, parseFetchBlobArgs, parseHandoffArgs, parseMemoryCommand, parsePinArgs, parseRecallArgs, parseSkillMarkdown, parseSkillReadInput, parseToolFindInput, percent, perception, pinInputSchema, pinMetaOf, pinToolDescription, pins, planCompaction, previewOf, rangeTier, readPerception, recallResult, recallTool, renderCompactRequest, renderCompactionSummary, renderLazyToolMenu, renderLoadedTool, renderPerception, renderSkillMenu, renderToolFindResult, resolveMemoryPath, revealedLazyTools, segmentTimelineByTurn, skills, spill, stopAfter, sumSessionTokens, summarizeTool, timelineSoFar, toolFindResultBound, toolReferenceOf, trailingCompactionRun, unfinishedHandoffArgs };
package/dist/index.js CHANGED
@@ -210,6 +210,7 @@ ${APPROVAL_EXPIRY_RULE}` : options.rules;
210
210
  // src/budget/budget.ts
211
211
  import { contextTokensOf } from "@reinsjs/core";
212
212
  var BUDGET_SOCKET_NAME = "budget";
213
+ var BUDGET_PAUSE_CODE = "reins.budget";
213
214
  function assertLimits(limits) {
214
215
  for (const [dimension, limit] of Object.entries(limits)) {
215
216
  if (limit === void 0) continue;
@@ -260,7 +261,9 @@ function budget(opts) {
260
261
  if (!continuing.get(ctx)) return void 0;
261
262
  const hits = checkBudget(ctx.budget, opts.limits);
262
263
  if (hits.length === 0) return void 0;
263
- return { pause: { reason: "budget", note: note(hits) } };
264
+ return {
265
+ pause: { reason: "budget", code: opts.code ? opts.code(hits) : BUDGET_PAUSE_CODE, note: note(hits) }
266
+ };
264
267
  }
265
268
  };
266
269
  }
@@ -700,6 +703,7 @@ function contextUsageRatio(ctx) {
700
703
  // src/compact/compact.ts
701
704
  var COMPACT_SOCKET_NAME = "compact";
702
705
  var DEFAULT_MAX_CONSECUTIVE_COMPACTIONS = 3;
706
+ var COMPACT_STALLED_PAUSE_CODE = "reins.compact_stalled";
703
707
  var COMPACT_INPUT_SCHEMA = {
704
708
  type: "object",
705
709
  properties: {
@@ -845,6 +849,7 @@ function compact(opts = {}) {
845
849
  return {
846
850
  pause: {
847
851
  reason: "budget",
852
+ code: COMPACT_STALLED_PAUSE_CODE,
848
853
  note: `Context was compacted ${total} times in a row without a turn of progress in between (limit ${maxConsecutive}). Either the window is still too small after folding, or the model is looping on compact. Paused for the host to inspect.`
849
854
  }
850
855
  };
@@ -2963,11 +2968,13 @@ export {
2963
2968
  APPROVAL_POLICY_IDS,
2964
2969
  APPROVAL_RULES,
2965
2970
  APPROVAL_SOCKET_NAME,
2971
+ BUDGET_PAUSE_CODE,
2966
2972
  BUDGET_SOCKET_NAME,
2967
2973
  COMPACT_INPUT_SCHEMA,
2968
2974
  COMPACT_REQUEST_RULE,
2969
2975
  COMPACT_RULES,
2970
2976
  COMPACT_SOCKET_NAME,
2977
+ COMPACT_STALLED_PAUSE_CODE,
2971
2978
  COMPACT_TOOL_DESCRIPTION,
2972
2979
  COMPACT_TOOL_NAME,
2973
2980
  DEFAULT_FORCE_AT,