@reinsjs/brain 0.4.0 → 0.6.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 +20 -0
- package/README.md +24 -4
- package/dist/index.d.ts +108 -5
- package/dist/index.js +420 -262
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @reinsjs/brain
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 276988e: Resident snapshots in `pins()`: a host spec can be `{ name, snapshot }`, where `snapshot(ctx)` may be async. It is taken when a segment starts — the session's first turn and the first turn after every compaction (model, forced or threshold) — and appended as a host pin only when it differs from the copy in view; within a segment it is not called again. When it changes after a compaction, the old copy is superseded and dropped from that same turn's request, so the model sees exactly one. Snapshot pins carry `meta.pin.snapshot: true` and are not carried through `handoff` (the new session takes its own). Use it for an index of the model's memory or the item it is working on, so compaction folds the work but not the context the model works from; README has a recipe. The segment helpers `modelActedSinceLastCompaction` and `timelineSoFar` moved to a shared file and are still exported from the same place. Also fixes the README example, which passed `pins({ host })` instead of `pins({ pins })`.
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 0455c28: Deliver `compact`'s request as a directive and ask twice. `SystemNotePayload` gains an optional `directive: true` for notes that ask the model to act; `@reinsjs/lowering-fetch` (all three protocols) and `@reinsjs/lowering-pi` send those as a framed `<system_note>` user message even when the model accepts mid-conversation system messages, and record the landing as `lossy(user-role)`. Measured on a pooled DeepSeek relay, the same request was ignored 4 of 4 times as a mid-conversation system message and followed 5 of 6 times as a framed user note; the official DeepSeek endpoint followed it 6 of 6 either way. Other notes (perception, pins) keep their current landing, and notes already in a log keep theirs, so cached prefixes do not change on upgrade. `compact({ force })` now asks at two lines by default (`at: [0.75, 0.8]`; a single number still works), uses blunter wording on the second request (`CompactRequestInfo.attempt`), skips the turn right after a compaction until the model has acted, and marks requests as directives unless `force.directive` is `false`.
|
|
14
|
+
- 24ba407: Ask the model to compact before the mechanical fallback kicks in. When the real context passes a soft line (`compact({ force: { at } })`, default `0.75` of the window) and nothing has been compacted since the last request, `compact` appends one runtime note at the end asking the model to call `compact` before doing anything else. A compaction made after such a request is recorded as `decidedBy: "forced"` (new value on `CompactionPayload.decidedBy`: the harness picked the timing, the model wrote the summary). The request is made once per segment; if the model ignores it, threshold truncation still folds mechanically at `contextLimit - reserveTokens`. Appending at the end keeps the prompt cache intact, unlike forcing `tool_choice` or narrowing the tool list. Pass `force: false` to turn it off (the default rules then drop the sentence that promises the request); `force.render` customizes the wording. `@reinsjs/eval` counts the new value separately (`CompactionCounts.forced`). The default `COMPACT_RULES` text gains one line, so sessions paused under an older version see a config change on resume.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [0455c28]
|
|
19
|
+
- Updated dependencies [24ba407]
|
|
20
|
+
- Updated dependencies [4a57a7a]
|
|
21
|
+
- @reinsjs/core@0.5.0
|
|
22
|
+
|
|
3
23
|
## 0.4.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ const agent = createAgent({
|
|
|
18
18
|
sockets: [
|
|
19
19
|
perception(), // "you have used 61% of your context" — as a note, not an action
|
|
20
20
|
compact(), // a `compact` tool the model calls when it decides to tidy
|
|
21
|
-
pins({
|
|
21
|
+
pins({ pins: ["Never touch prod without approval"] }),
|
|
22
22
|
spill(), // big tool results go to the BlobStore; the model gets a preview + fetch_blob
|
|
23
23
|
memory({ namespace: () => "/roles/analyst" }),
|
|
24
24
|
// a menu of SKILL.md names in the prompt; the model reads one with skill_read.
|
|
@@ -35,8 +35,8 @@ 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.
|
|
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. | 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 |
|
|
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. **Off by default.** | a `MemoryStore` |
|
|
@@ -49,6 +49,26 @@ const agent = createAgent({
|
|
|
49
49
|
|
|
50
50
|
Any `MemoryStore` (in-memory, `@reinsjs/store-sqlite`, `@reinsjs/store-pg`) is also a `SkillSource`: write `/skills/<name>/SKILL.md` (frontmatter with `name` equal to `<name>` and a `description`) and, optionally, `/skills/<name>/<file>` for supporting files, then pass the same store as `source`. The model's `memory` tool only reaches `/memories`, so one table holds writable private notes and read-only shared skills at once; `memory({ namespace })` prefixes apply to memories only, skills are shared by every principal. `skills()` refuses a `root` that overlaps `/memories` — a skill the model could write itself must never be trusted like the system prompt.
|
|
51
51
|
|
|
52
|
+
### Resident context that survives compaction
|
|
53
|
+
|
|
54
|
+
Compaction folds the conversation, not the system prompt or the tool list, so the model keeps who it is and what it can do. What it loses is context you attached to the conversation — an index of its memory, the item it is working on. Declare that as a resident snapshot instead:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
/** One line per memory file: the index, not the content. The model opens a file with its `memory` tool. */
|
|
58
|
+
function memoryIndex(store: MemoryStore) {
|
|
59
|
+
return async (): Promise<string | undefined> => {
|
|
60
|
+
const paths = await store.list("/memories/")
|
|
61
|
+
if (paths.length === 0) return undefined
|
|
62
|
+
return ["Your memory files (open one with the memory tool):", ...paths.map((p) => `- ${p}`)].join("\n")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const residentContext = (store: MemoryStore) =>
|
|
67
|
+
pins({ pins: [{ name: "memory-index", snapshot: memoryIndex(store) }], tool: false })
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The snapshot is taken when a segment starts: the first turn of the session, and the first turn after each compaction (the model's own, a requested one, or the threshold fallback). Within a segment it is not refreshed — whatever the model wrote to memory is already in its context; after a compaction folds that away, the index is taken again and the old copy disappears in the same turn. If nothing changed, nothing is appended. Changes made by someone else mid-segment show up after the next compaction; use `extract` if you need them live. A snapshot is a pin and occupies context permanently: keep it to an index and short status, and let the model open the details. It is not carried through `handoff` — the new session takes its own. If `snapshot` throws, the run fails; catch inside it and return `undefined` to keep the previous copy instead.
|
|
71
|
+
|
|
52
72
|
## Things that are deliberate
|
|
53
73
|
|
|
54
74
|
- **Sockets run in order, and order matters.** `approval()` belongs last so it judges the arguments after any `rewrite`; `perception()` appends its note at the end of the visible events so the model reads it last.
|
|
@@ -63,6 +83,6 @@ Any `MemoryStore` (in-memory, `@reinsjs/store-sqlite`, `@reinsjs/store-pg`) is a
|
|
|
63
83
|
|
|
64
84
|
## Documentation
|
|
65
85
|
|
|
66
|
-
`docs
|
|
86
|
+
`docs/archive/implementation-plans/2026-09-08-技术方案v1.0.md` §9 (module specs and measurements), `docs/系统全景图_模块盘点/brain.md` (file map), `docs/踩坑记录.md` (pitfalls) — in Chinese, at the repository root.
|
|
67
87
|
|
|
68
88
|
MIT © 2026 NewRate Limited.
|
package/dist/index.d.ts
CHANGED
|
@@ -282,10 +282,82 @@ declare function segmentTimelineByTurn(timeline: readonly Event[]): Event[][];
|
|
|
282
282
|
*/
|
|
283
283
|
declare function trailingCompactionRun(timeline: readonly Event[]): number;
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* "段"的判据(compact 与 pins 共用,2026-10-31 从 compact/request.ts 挪出):段 = 会话开头或最近一次整理
|
|
287
|
+
* (任何 decidedBy,含本轮投影新造的阈值兜底)之后、到下一次整理之前。全部从时间线读,没有跨轮状态:
|
|
288
|
+
* 续跑、跨实例、多 run 的长期会话都一致。
|
|
289
|
+
*
|
|
290
|
+
* - compact 的整理请求:刚整理完、模型还没动过就不请(`modelActedSinceLastCompaction`)
|
|
291
|
+
* - pins 的常驻快照:段起点取一份(`atSegmentStart`)
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 最后一次整理之后模型有没有动过(正文或工具调用);从没整理过算动过。
|
|
296
|
+
* 刚整理完、折后仍在软线以上时,先让模型干一轮活再请,免得整理一结束就被追着连请、撞上连续整理上限
|
|
297
|
+
*/
|
|
298
|
+
declare function modelActedSinceLastCompaction(timeline: readonly Event[]): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* 截至此刻的时间线:本轮开始时的快照 + 本轮新增(投影新造的阈值 compaction、beforeModel 追加的说明)。
|
|
301
|
+
* 后者只在 ctx.events 里、不在 ctx.timeline 里,按 seq 大于快照末尾取出
|
|
302
|
+
*/
|
|
303
|
+
declare function timelineSoFar(ctx: TurnContext): Event[];
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 到线请模型整理(OPT-261030-3):用量过软线、本段还没请过时,在末尾追加一条说明请模型先 compact 再继续。
|
|
307
|
+
*
|
|
308
|
+
* 三层分工(宪法一):模型自决整理是默认路径;它没动、用量过软线 → 这里请它整理(时机框架定、摘要模型写,
|
|
309
|
+
* 记 decidedBy=forced);还不动、过触发线 → core 投影链机械裁剪。
|
|
310
|
+
*
|
|
311
|
+
* 为什么是"末尾追加说明"而不是 tool_choice 强制或收窄工具表(spikes/forced-compact/,两族实测):
|
|
312
|
+
* 追加只动末尾,缓存照命中(DeepSeek 98% / Haiku 5.5 99.3%),模型照做(6/6、3/3);DeepSeek thinking 模式拒绝
|
|
313
|
+
* 一切强制 tool_choice,Haiku 5.5 接受但缓存归零;换工具表两家缓存都崩。
|
|
314
|
+
*
|
|
315
|
+
* 全部判据从时间线读,没有跨轮状态:续跑、多 run 的长期会话都成立。
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 请求整理的缺省各级软线(占 contextLimit 的比例,升序),都低于阈值兜底的缺省触发线 85%。
|
|
320
|
+
* 每段(上次整理之后)每级请一次:过 75% 请第一次,模型没理、过 80% 再请一次,仍不理才留给机械兜底(OPT-261031-1)
|
|
321
|
+
*/
|
|
322
|
+
declare const DEFAULT_FORCE_AT: readonly number[];
|
|
323
|
+
interface CompactRequestInfo {
|
|
324
|
+
/** 本轮真实上下文占窗口的比例,如 "78%" */
|
|
325
|
+
usage: string;
|
|
326
|
+
/** 阈值兜底的触发点,如 "85%"(与感知报的 autoFoldAt 同一口径) */
|
|
327
|
+
autoFoldAt: string;
|
|
328
|
+
/** 本段第几次请求,从 1 起 */
|
|
329
|
+
attempt: number;
|
|
330
|
+
}
|
|
331
|
+
interface ForceOptions {
|
|
332
|
+
/**
|
|
333
|
+
* 软线:真实上下文 ≥ contextLimit × at 时请模型整理。一个数或严格升序的一组,每个取 (0, 1),缺省 [0.75, 0.8]:
|
|
334
|
+
* 每段每级请一次。不低于触发线的级永远不出现(投影先裁了);相邻两级的间隔小于一步能涨的量(spill 单个结果上限 16k)时,后一级可能被跨过
|
|
335
|
+
*/
|
|
336
|
+
at?: number | readonly number[];
|
|
337
|
+
/**
|
|
338
|
+
* 请求说明是否标为指令(`SystemNotePayload.directive`),缺省 true:降级层以带标签的 user 文本送达。
|
|
339
|
+
* 实测号池中转站对中途 system 里的请求 0/4 照做、改成这样 5/6(踩坑 42);官方线路两种都照做
|
|
340
|
+
*/
|
|
341
|
+
directive?: boolean;
|
|
342
|
+
/** 自定义措辞 / 语言;必须是纯函数 */
|
|
343
|
+
render?: (info: CompactRequestInfo) => string;
|
|
344
|
+
}
|
|
345
|
+
/** 缺省说明:明确命令,不是建议(onset-pause 证明"建议在收尾前整理"无效,forced-compact 证明命令有效);第二次起更直接 */
|
|
346
|
+
declare function renderCompactRequest(info: CompactRequestInfo): string;
|
|
347
|
+
/** 某条事件是不是本模块追加的整理请求 */
|
|
348
|
+
declare function isCompactRequest(e: Event): boolean;
|
|
349
|
+
/** 时间线里最后一次整理(任何 decidedBy)之后有没有整理请求 —— "本段已经请过" */
|
|
350
|
+
declare function compactRequestedSinceLastCompaction(timeline: readonly Event[]): boolean;
|
|
351
|
+
/** 最后一次整理之后的整理请求条数 = 本段已用掉几级 */
|
|
352
|
+
declare function compactRequestsSinceLastCompaction(timeline: readonly Event[]): number;
|
|
353
|
+
|
|
354
|
+
/** 本轮真实上下文占窗口的比例:投影估算 + 校准出的固定开销,与感知读数、阈值兜底同一把尺 */
|
|
355
|
+
declare function contextUsageRatio(ctx: TurnContext): number;
|
|
356
|
+
|
|
285
357
|
/**
|
|
286
358
|
* compact —— 自主整理模块(技术方案 §9.2,B2)。
|
|
287
359
|
*
|
|
288
|
-
*
|
|
360
|
+
* 六件事:
|
|
289
361
|
* 1. **工具** `compact({ summary, keep, keepRecentTurns? })`:模型自己决定何时整理、留什么(宪法一)。
|
|
290
362
|
* 工具本身是静态贡献(Socket.tools),整个 run 不变,续跑补齐 pending 时也在场。
|
|
291
363
|
* 2. **规则提示**:静态 systemPrompt 片段(rules.ts),告诉模型什么时候该整理、什么时候别整理。
|
|
@@ -294,6 +366,8 @@ declare function trailingCompactionRun(timeline: readonly Event[]): number;
|
|
|
294
366
|
* 宿主经 LoopConfig.projection.reserveTokens 调;perception 会把这个点告诉模型。
|
|
295
367
|
* 4. **连续上限**:连着整理(模型自决 + 阈值兜底合计)达到 maxConsecutive 次仍没有一轮"正常"工作,
|
|
296
368
|
* 说明卡死了(折叠后仍放不下、或模型在反复整理)→ onTurnEnd 返回 pause(budget) 交宿主处理。
|
|
369
|
+
* 6. **到线请整理**(OPT-261030-3 / OPT-261031-1):过软线(缺省 75%、80% 两级,每段每级一次)→ beforeModel 末尾追加一条
|
|
370
|
+
* 指令类说明(directive,降级层以带标签的 user 文本送达)请模型先整理,照做记 decidedBy=forced;两级都不理就留给第 3 条的机械兜底。见 request.ts。
|
|
297
371
|
* 5. **取回**(E3c):摘要下面列出被折叠的每条工具结果(seq + 工具 + 入参),`recall({ seq })` 工具逐字取回一条。
|
|
298
372
|
* 整理丢细节是机制的代价(模型按自己的重要性判断留东西),清单与取回让丢掉的东西有路可回,见 recall.ts。
|
|
299
373
|
*
|
|
@@ -323,6 +397,12 @@ interface CompactOptions {
|
|
|
323
397
|
manifest?: false | ManifestOptions;
|
|
324
398
|
/** 是否给模型 recall 取回工具(E3c)。缺省 true;false 时清单照列,只是模型自己取不回(宿主另有读法时用) */
|
|
325
399
|
recall?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* 到线请模型整理(OPT-261030-3 / OPT-261031-1):真实上下文过某一级软线(缺省 75%、80%)、且本段(上次整理之后)还没在这一级请过时,
|
|
402
|
+
* 在末尾追加一条指令类说明请模型先 compact 再继续;照做的整理记 decidedBy=forced。刚整理完模型还没动过不请;两级都不理就留给触发线的机械裁剪。
|
|
403
|
+
* 传 false 关闭;传对象调软线与措辞
|
|
404
|
+
*/
|
|
405
|
+
force?: false | ForceOptions;
|
|
326
406
|
}
|
|
327
407
|
declare const COMPACT_SOCKET_NAME = "compact";
|
|
328
408
|
declare const DEFAULT_MAX_CONSECUTIVE_COMPACTIONS = 3;
|
|
@@ -409,7 +489,12 @@ declare const COMPACT_TOOL_NAME = "compact";
|
|
|
409
489
|
declare const RECALL_TOOL_NAME = "recall";
|
|
410
490
|
declare const COMPACT_TOOL_DESCRIPTION: string;
|
|
411
491
|
declare const RECALL_TOOL_DESCRIPTION: string;
|
|
412
|
-
|
|
492
|
+
/**
|
|
493
|
+
* 规则里讲"到线会请你整理"的那一行(OPT-261030-3)。只有开着 compact({ force }) 时才成立,
|
|
494
|
+
* 所以 force: false 且没自定义 rules 时,模块用去掉这一行的版本——告诉模型的事框架必须兑现
|
|
495
|
+
*/
|
|
496
|
+
declare const COMPACT_REQUEST_RULE = "- If the window gets close to full and you have not compacted, the harness will ask you to. Compact then, before anything else: that is the point where your own summary still beats a mechanical one.";
|
|
497
|
+
declare const COMPACT_RULES = "## Managing your context window\nYou have a `compact` tool that folds earlier conversation into a summary you write. Status notes from the harness, if present, tell you how full the window is.\n- Compact when a sub-task is finished or the trajectory has converged and the folded details are no longer needed verbatim. Do it at a natural pause, not while acting on something.\n- Do not compact in the middle of a derivation, while a problem is still unresolved, or when you feel stuck: you would lose exactly the details you still need.\n- The summary replaces everything it folds, including earlier summaries. Carry forward the user's goals and constraints, decisions made and why, the current state, and what comes next. List each fact that must survive in `keep`. The most recent user message and pinned notes survive verbatim on their own; check the pins still say what you need.\n- Keep exact values, not just conclusions: identifiers, status and enum fields you verified, numbers, dates, error codes. \"Checked, all ENABLE\" loses the field values themselves.\n- Nothing folded is lost for good: under each summary the harness lists the folded tool results as `seq N tool(arguments)`, and `recall({ seq })` brings one back verbatim. When asked about a detail your summary did not keep, recall the result that contained it instead of guessing or saying it is gone.\n- If the window gets close to full and you have not compacted, the harness will ask you to. Compact then, before anything else: that is the point where your own summary still beats a mechanical one.\n- If you never compact, the harness folds the oldest turns mechanically once the window nears its limit. Its summary is worse than yours, but it lists the folded tool results the same way.";
|
|
413
498
|
|
|
414
499
|
/**
|
|
415
500
|
* handoff —— 会话交接模块(技术方案 §9.5,B5)。
|
|
@@ -479,7 +564,10 @@ interface HandoffArgs {
|
|
|
479
564
|
declare function parseHandoffArgs(raw: unknown): HandoffArgs;
|
|
480
565
|
/** 新会话 seq 1 的文字(也是旧会话 handoff.summary):摘要 + 编号的下一步 */
|
|
481
566
|
declare function composeHandoffNote(args: Pick<HandoffArgs, "summary" | "nextSteps">): string;
|
|
482
|
-
/**
|
|
567
|
+
/**
|
|
568
|
+
* 模型当前可见、未被取代的 pin,按可见顺序复制成新会话的开场草稿。
|
|
569
|
+
* 常驻快照(pins 的 `snapshot` spec)不带:新会话是新段,由它自己在段起点取一份当前的,而不是带去旧的再被取代
|
|
570
|
+
*/
|
|
483
571
|
declare function carriedPins(ctx: TurnContext): EventDraft[];
|
|
484
572
|
/** 模型当前可见的最后一条用户消息的文字;没有则 undefined */
|
|
485
573
|
declare function lastVisibleUserMessage(events: readonly Event[]): string | undefined;
|
|
@@ -995,6 +1083,11 @@ declare function renderPerception(r: PerceptionReading): string;
|
|
|
995
1083
|
* ToolContext 没有视图),emit `system_note(kind=pin, actor=model, parentId=tool_call)`,再把结果换成回执。
|
|
996
1084
|
* `replaces` 只能指向模型自己钉的(meta.pin.source = "model"):宿主钉的是宿主的约束,模型动不了。
|
|
997
1085
|
*
|
|
1086
|
+
* 宿主声明还有第三种:**常驻快照** `{ name, snapshot }`(2026-10-31,OnSet 建议 5 改写)。给记忆索引、当前条目这类
|
|
1087
|
+
* "会变、但该一直在手边"的内容一个压缩不掉的位置,口径对齐 Claude Code 的常驻记忆索引:开场取一份;段内不刷新
|
|
1088
|
+
* (模型自己写记忆的过程就在上下文里);每次整理后按当前实际再取一份(写记忆的那段被折走了);没变不追加。
|
|
1089
|
+
* 时机从时间线判(shared/segment.ts 的段起点),内容按数据判(与视图里那份逐字比)。
|
|
1090
|
+
*
|
|
998
1091
|
* 说明的 `meta.pin` 记来源与 spec 名(不进模型上下文),判重与 supersede 靠它,回放 / eval 也靠它分辨谁钉的。
|
|
999
1092
|
* 没有 unpin:append-only 日志里"撤销"只能表达为"被新说明取代",模型要撤销就钉一条当前有效的说法去替换旧的。
|
|
1000
1093
|
*/
|
|
@@ -1004,6 +1097,10 @@ declare function renderPerception(r: PerceptionReading): string;
|
|
|
1004
1097
|
* - 字符串:静态文本,名字就是文本本身
|
|
1005
1098
|
* - `{ name, text }`:静态文本,命名(换措辞时名字不变,旧文字会被取代而不是并存)
|
|
1006
1099
|
* - `{ name, extract }`:每轮从上下文抽取;返回 undefined / 空串表示"这轮没新说法",上一条继续生效
|
|
1100
|
+
* - `{ name, snapshot }`:常驻快照,只在段起点取(会话开头、每次整理之后模型动手之前;本段取到过就不再取),
|
|
1101
|
+
* 另外时间线里从没有过本 spec 的 pin 时也取(老会话第一次装上)。可以是异步的(读记忆存储)。
|
|
1102
|
+
* 与视图里那份逐字相同不追加;不同则追加并取代旧的。段内别人改了数据本段看不到,要实时用 `extract`。
|
|
1103
|
+
* 它是 pin、永久占上下文:只放索引与简要状态,正文让模型按需读。抛错照常抛出,想降级就在函数里 catch 返回 undefined
|
|
1007
1104
|
*/
|
|
1008
1105
|
type PinSpec = string | {
|
|
1009
1106
|
name: string;
|
|
@@ -1011,6 +1108,9 @@ type PinSpec = string | {
|
|
|
1011
1108
|
} | {
|
|
1012
1109
|
name: string;
|
|
1013
1110
|
extract: (ctx: TurnContext) => string | undefined;
|
|
1111
|
+
} | {
|
|
1112
|
+
name: string;
|
|
1113
|
+
snapshot: (ctx: TurnContext) => MaybePromise<string | undefined>;
|
|
1014
1114
|
};
|
|
1015
1115
|
interface PinsOptions {
|
|
1016
1116
|
/** 宿主声明的 pin。名字必须唯一 */
|
|
@@ -1031,10 +1131,11 @@ interface PinsOptions {
|
|
|
1031
1131
|
declare const PINS_SOCKET_NAME = "pins";
|
|
1032
1132
|
declare const DEFAULT_MAX_PIN_TEXT_LENGTH = 500;
|
|
1033
1133
|
declare const DEFAULT_PIN_OVERSHOOT_TOLERANCE = 0.2;
|
|
1034
|
-
/** system_note.meta.pin 的形状:谁钉的、宿主 spec
|
|
1134
|
+
/** system_note.meta.pin 的形状:谁钉的、宿主 spec 名;常驻快照另标 snapshot(handoff 据此不带走) */
|
|
1035
1135
|
interface PinMeta {
|
|
1036
1136
|
source: "host" | "model";
|
|
1037
1137
|
spec?: string;
|
|
1138
|
+
snapshot?: true;
|
|
1038
1139
|
}
|
|
1039
1140
|
type PinNote = CoreEventOf<"core.system_note">;
|
|
1040
1141
|
/** 入参 schema;`maxLength` 随 maxTextLength 变,模型下笔前就看得到上限(E3c) */
|
|
@@ -1076,6 +1177,8 @@ interface PinArgs {
|
|
|
1076
1177
|
declare function parsePinArgs(raw: unknown, maxTextLength?: number, overshootTolerance?: number): PinArgs;
|
|
1077
1178
|
declare function isPinNoteEvent(e: Event): e is PinNote;
|
|
1078
1179
|
declare function pinMetaOf(e: PinNote): PinMeta | undefined;
|
|
1180
|
+
/** 是不是常驻快照 pin(handoff 不带走它:新会话是新段,自己取当前的) */
|
|
1181
|
+
declare function isSnapshotPin(e: Event): boolean;
|
|
1079
1182
|
/** 某个宿主 spec 最后一条 pin(从后往前找) */
|
|
1080
1183
|
declare function lastHostPin(events: readonly Event[], spec: string): PinNote | undefined;
|
|
1081
1184
|
/** 模型钉的、文字完全相同的一条(从后往前找) */
|
|
@@ -1409,4 +1512,4 @@ declare function parseFetchBlobArgs(raw: unknown): FetchBlobArgs;
|
|
|
1409
1512
|
declare function isTextMime(mime: string): boolean;
|
|
1410
1513
|
declare function spill(opts?: SpillOptions): Socket;
|
|
1411
1514
|
|
|
1412
|
-
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_RULES, COMPACT_SOCKET_NAME, COMPACT_TOOL_DESCRIPTION, COMPACT_TOOL_NAME, type CompactArgs, type CompactOptions, type CompactPlan, 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, HANDOFF_INPUT_SCHEMA, HANDOFF_RULES, HANDOFF_SOCKET_NAME, HANDOFF_TOOL_DESCRIPTION, HANDOFF_TOOL_NAME, 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, type SkillFrontmatter, type SkillMenu, type SkillMenuEntry, type SkillReadInput, type SkillsOptions, type SpillOptions, 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, composeHandoffNote, countLines, countModelTurns, countTier, defaultBudgetNote, defaultSummary, defaultTextTokens, evaluatePolicy, executeMemoryCommand, findExpiredApproval, findModelPin, fmt, globToRegExp, handoff, humanSize, inlineSkills, isModelCompaction, isPinNoteEvent, isTextMime, isUnder, lastHostPin, lastVisiblePerceptionNote, lastVisibleUserMessage, lazyMenuOf, lazyTools, loadSkillMenu, measureText, memory, normalizeRule, parseCompactArgs, parseFetchBlobArgs, parseHandoffArgs, parseMemoryCommand, parsePinArgs, parseRecallArgs, parseSkillMarkdown, parseSkillReadInput, parseToolFindInput, percent, perception, pinInputSchema, pinMetaOf, pinToolDescription, pins, planCompaction, previewOf, rangeTier, readPerception, recallResult, recallTool, renderCompactionSummary, renderLazyToolMenu, renderLoadedTool, renderPerception, renderSkillMenu, renderToolFindResult, resolveMemoryPath, revealedLazyTools, segmentTimelineByTurn, skills, spill, sumSessionTokens, summarizeTool, toolFindResultBound, toolReferenceOf, trailingCompactionRun, unfinishedHandoffArgs };
|
|
1515
|
+
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, HANDOFF_INPUT_SCHEMA, HANDOFF_RULES, HANDOFF_SOCKET_NAME, HANDOFF_TOOL_DESCRIPTION, HANDOFF_TOOL_NAME, 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, type SkillFrontmatter, type SkillMenu, type SkillMenuEntry, type SkillReadInput, type SkillsOptions, type SpillOptions, 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, findExpiredApproval, findModelPin, fmt, globToRegExp, 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, sumSessionTokens, summarizeTool, timelineSoFar, toolFindResultBound, toolReferenceOf, trailingCompactionRun, unfinishedHandoffArgs };
|