@jjh32456/longlive 0.0.0-stage → 2.0.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 +235 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +362 -0
- package/README.en.md +64 -0
- package/README.md +256 -2
- package/SPEC.md +211 -0
- package/build-info.json +1665 -0
- package/cordis.patch.yml +208 -0
- package/docs/A1-MIGRATION.md +75 -0
- package/docs/ANSWER-GUARD.md +92 -0
- package/docs/ARCHITECTURE.md +128 -0
- package/docs/AUTO-RECALL-WIRING.md +115 -0
- package/docs/AUTO-RECALL.md +237 -0
- package/docs/CONCEPTS.md +143 -0
- package/docs/CONFIG.md +839 -0
- package/docs/ERRORS.md +271 -0
- package/docs/FAQ.md +186 -0
- package/docs/FEATURES.md +579 -0
- package/docs/INDEX-FRESHNESS.md +21 -0
- package/docs/METRICS.md +244 -0
- package/docs/MIGRATION-1.6.0.md +220 -0
- package/docs/OPERATIONS.md +439 -0
- package/docs/PANEL-INTEGRATION.md +190 -0
- package/docs/PRIVACY.md +88 -0
- package/docs/QUICKSTART.md +155 -0
- package/docs/RAW-INDEX-POLICY.md +7 -0
- package/docs/README.en.md +48 -0
- package/docs/RESIDENT-WATCHER.md +90 -0
- package/docs/SESSION-WATCH.md +214 -0
- package/docs/TOOLS.md +184 -0
- package/docs/TROUBLESHOOTING.md +329 -0
- package/icon.svg +11 -0
- package/lib/client.js +436 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +163 -4
- package/runbook.md +343 -0
- package/scripts/archive-digest-build.mjs +668 -0
- package/scripts/auto-truncate-run.ps1 +752 -0
- package/scripts/backfill-auto-cards.mjs +98 -0
- package/scripts/edges-build.mjs +1003 -0
- package/scripts/index-maintain.mjs +39 -0
- package/scripts/index-reconcile.mjs +49 -0
- package/scripts/index-status.mjs +28 -0
- package/scripts/install-resident-watcher.ps1 +15 -0
- package/scripts/install-session-watch.ps1 +332 -0
- package/scripts/install-surgery-task.ps1 +174 -0
- package/scripts/lib/auto-truncate-run.ps1 +512 -0
- package/scripts/lib/session-watch-fixture.mjs +207 -0
- package/scripts/longlive-doctor.mjs +578 -0
- package/scripts/metrics-read.mjs +79 -0
- package/scripts/metrics-sample.mjs +215 -0
- package/scripts/migrate-180.mjs +163 -0
- package/scripts/migrate-200.mjs +8 -0
- package/scripts/migrate-a1-legacy.mjs +62 -0
- package/scripts/migrate-lifecycle.mjs +157 -0
- package/scripts/pack.mjs +392 -0
- package/scripts/recall-index-build.mjs +128 -0
- package/scripts/recall-links-build.mjs +420 -0
- package/scripts/rescore-cards.mjs +36 -0
- package/scripts/resident-watcher-status.ps1 +15 -0
- package/scripts/resident-watcher.ps1 +643 -0
- package/scripts/session-watch-drill.mjs +553 -0
- package/scripts/session-watch-status.ps1 +146 -0
- package/scripts/session-watch.mjs +1367 -0
- package/scripts/surgery-inspect.mjs +122 -0
- package/scripts/surgery-run.cmd +34 -0
- package/scripts/truncate-cli.mjs +279 -0
- package/scripts/unattended-surgery.ps1 +1019 -0
- package/scripts/uninstall-resident-watcher.ps1 +15 -0
- package/scripts/uninstall-session-watch.ps1 +192 -0
- package/scripts/verify-card-anchors.mjs +138 -0
- package/scripts/watch-loop.ps1 +916 -0
- package/src/actions/audit.js +125 -0
- package/src/actions/evidence.js +122 -0
- package/src/actions/fs.js +162 -0
- package/src/activity/index.js +873 -0
- package/src/activity/model.js +351 -0
- package/src/activity/store.js +786 -0
- package/src/activity/summary.js +180 -0
- package/src/activity/thinking.js +191 -0
- package/src/adapters/constants.js +11 -0
- package/src/adapters/engram/data/aliases.json +51 -0
- package/src/adapters/engram/data/policy.json +8 -0
- package/src/adapters/engram/data/routing-rules.json +546 -0
- package/src/adapters/engram/index.js +278 -0
- package/src/adapters/registry.js +315 -0
- package/src/answer/audit.js +238 -0
- package/src/answer/claim-guard.mjs +234 -0
- package/src/answer/evidence.js +30 -0
- package/src/answer/guard.js +1370 -0
- package/src/answer/index.js +1086 -0
- package/src/answer/query.js +111 -0
- package/src/answer/second-hop.mjs +101 -0
- package/src/auto-truncate-status.js +164 -0
- package/src/auto-truncate.js +1181 -0
- package/src/autoprocedure/candidate.js +342 -0
- package/src/autoprocedure/config.js +122 -0
- package/src/autoprocedure/evidence.js +345 -0
- package/src/autoprocedure/index.js +83 -0
- package/src/autoprocedure/ledger.js +329 -0
- package/src/autoprocedure/lint.js +232 -0
- package/src/autoprocedure/llm.js +409 -0
- package/src/autoprocedure/locks.js +102 -0
- package/src/autoprocedure/paths.js +39 -0
- package/src/autoprocedure/privacy.js +87 -0
- package/src/autoprocedure/rules.js +288 -0
- package/src/autoprocedure/runtime.js +718 -0
- package/src/autoprocedure/session-reader.js +328 -0
- package/src/backup.js +310 -0
- package/src/bus/bus.mjs +1446 -0
- package/src/codec.js +269 -0
- package/src/compaction/cut-engine.js +44 -0
- package/src/compaction/engine-core.js +1237 -0
- package/src/compaction/entry.js +228 -0
- package/src/compaction.js +230 -0
- package/src/conclusion.js +366 -0
- package/src/config.js +835 -0
- package/src/d6/runtime.js +517 -0
- package/src/d6/surface.js +181 -0
- package/src/deps.js +189 -0
- package/src/engine-status.js +141 -0
- package/src/features.js +1035 -0
- package/src/handoff/index.js +1077 -0
- package/src/handoff/model.js +1058 -0
- package/src/handoff/store.js +1233 -0
- package/src/heartbeat.js +385 -0
- package/src/home.js +16 -0
- package/src/host-version.js +280 -0
- package/src/hot-truncate-diag.js +98 -0
- package/src/identity/card-marker.js +281 -0
- package/src/identity/handover.js +845 -0
- package/src/identity/index.js +337 -0
- package/src/identity/inject-position.js +133 -0
- package/src/identity/writeback.js +344 -0
- package/src/identity.js +118 -0
- package/src/index.js +647 -0
- package/src/lifecycle/gap-clocks.js +364 -0
- package/src/lifecycle/index.js +269 -0
- package/src/lifecycle/proactive.js +1426 -0
- package/src/live-target.js +212 -0
- package/src/live.js +1603 -0
- package/src/log-rotation.js +153 -0
- package/src/memory/a1-migration.js +190 -0
- package/src/memory/activity-capture.js +229 -0
- package/src/memory/anchor-fallback.js +116 -0
- package/src/memory/anchors.js +194 -0
- package/src/memory/archive-cold-state.mjs +794 -0
- package/src/memory/archive-staging.mjs +305 -0
- package/src/memory/archive.mjs +415 -0
- package/src/memory/audit-records.js +222 -0
- package/src/memory/auto-cards.js +441 -0
- package/src/memory/capture-host.js +297 -0
- package/src/memory/capture.js +496 -0
- package/src/memory/card-anchors.js +203 -0
- package/src/memory/card-priority.js +110 -0
- package/src/memory/cards.js +425 -0
- package/src/memory/catchup.mjs +534 -0
- package/src/memory/conclusion-distill.js +381 -0
- package/src/memory/conclusion-drafts.js +243 -0
- package/src/memory/conflicts.js +1060 -0
- package/src/memory/consolidate.js +834 -0
- package/src/memory/decay.js +311 -0
- package/src/memory/distill.js +485 -0
- package/src/memory/event-index.js +1826 -0
- package/src/memory/evidence-chain.js +295 -0
- package/src/memory/evidence.js +213 -0
- package/src/memory/filter-runner.js +555 -0
- package/src/memory/filter.js +1035 -0
- package/src/memory/forget-v2.js +680 -0
- package/src/memory/forget.js +531 -0
- package/src/memory/frames-activation.js +249 -0
- package/src/memory/frontmatter.js +454 -0
- package/src/memory/fts-query.js +342 -0
- package/src/memory/governance.js +604 -0
- package/src/memory/index-freshness.js +234 -0
- package/src/memory/index.js +435 -0
- package/src/memory/l2-gate.js +169 -0
- package/src/memory/land.mjs +743 -0
- package/src/memory/lifecycle.js +235 -0
- package/src/memory/lock.js +121 -0
- package/src/memory/maintenance.js +1149 -0
- package/src/memory/manifest.js +245 -0
- package/src/memory/memory-health.mjs +607 -0
- package/src/memory/migrate-200.js +1681 -0
- package/src/memory/migrate-lifecycle.js +1808 -0
- package/src/memory/migrate.js +139 -0
- package/src/memory/paths.js +229 -0
- package/src/memory/procedure-candidate.mjs +377 -0
- package/src/memory/procedure.js +982 -0
- package/src/memory/prospective-memory.mjs +362 -0
- package/src/memory/provenance.js +119 -0
- package/src/memory/recall-feedback.mjs +406 -0
- package/src/memory/recall-v2.js +218 -0
- package/src/memory/recall.js +357 -0
- package/src/memory/reconcile.js +265 -0
- package/src/memory/records.js +433 -0
- package/src/memory/reinforce.js +281 -0
- package/src/memory/retention.js +162 -0
- package/src/memory/review.js +124 -0
- package/src/memory/state.js +279 -0
- package/src/memory/tiers.js +168 -0
- package/src/memory/topic-phrases.js +73 -0
- package/src/memory/trust.js +97 -0
- package/src/memory/turn-budget.mjs +290 -0
- package/src/memory/version-chain.js +264 -0
- package/src/memory/wake-bridge.mjs +2999 -0
- package/src/memory/wal.js +137 -0
- package/src/memory/working-frame.js +779 -0
- package/src/metrics/classify.mjs +191 -0
- package/src/metrics/estimate.mjs +108 -0
- package/src/metrics/index.mjs +204 -0
- package/src/metrics/measure.mjs +462 -0
- package/src/metrics/prestep-latency.mjs +307 -0
- package/src/metrics/store.mjs +264 -0
- package/src/original.js +294 -0
- package/src/policy/threshold-policy.js +224 -0
- package/src/policy-profile.js +463 -0
- package/src/recall/anaphora.mjs +87 -0
- package/src/recall/archive-config.mjs +130 -0
- package/src/recall/archive-fallback.mjs +390 -0
- package/src/recall/archive-search.mjs +428 -0
- package/src/recall/archive-state.mjs +588 -0
- package/src/recall/brain.mjs +501 -0
- package/src/recall/cards.mjs +202 -0
- package/src/recall/current-line.mjs +110 -0
- package/src/recall/edges.js +398 -0
- package/src/recall/embedding.mjs +698 -0
- package/src/recall/entities.mjs +112 -0
- package/src/recall/explain.mjs +443 -0
- package/src/recall/force-policy.mjs +138 -0
- package/src/recall/gate-log.mjs +280 -0
- package/src/recall/gate-metrics.mjs +191 -0
- package/src/recall/index.js +1337 -0
- package/src/recall/inject-order.mjs +279 -0
- package/src/recall/link-recall.mjs +183 -0
- package/src/recall/links.mjs +696 -0
- package/src/recall/privacy.mjs +208 -0
- package/src/recall/recall-core.mjs +810 -0
- package/src/recall/shared-visibility.js +302 -0
- package/src/recall/time-normalizer.mjs +196 -0
- package/src/recall/turn-budget-inject.mjs +154 -0
- package/src/retention/cold-gate.mjs +146 -0
- package/src/retention/config.js +163 -0
- package/src/retention/index.js +801 -0
- package/src/role/activation.js +191 -0
- package/src/role/attention.js +318 -0
- package/src/role/base.js +36 -0
- package/src/role/channels.js +423 -0
- package/src/role/index.js +425 -0
- package/src/role/interfaces.js +115 -0
- package/src/role/personality.js +370 -0
- package/src/role/readers.js +151 -0
- package/src/role/relationships.js +477 -0
- package/src/role/store.js +202 -0
- package/src/role/writeprotect.js +373 -0
- package/src/router/aliases.json +182 -0
- package/src/router/background/agent-runner.mjs +239 -0
- package/src/router/background/anchor.mjs +323 -0
- package/src/router/background/audit.mjs +337 -0
- package/src/router/background/budget-ledger.mjs +648 -0
- package/src/router/background/host-sim.mjs +451 -0
- package/src/router/background/index.mjs +81 -0
- package/src/router/background/memory.mjs +63 -0
- package/src/router/background/mock-llm.mjs +203 -0
- package/src/router/background/queue.mjs +224 -0
- package/src/router/background/retry.mjs +255 -0
- package/src/router/background/router.mjs +1459 -0
- package/src/router/background/stream.mjs +276 -0
- package/src/router/background/tool-policy.mjs +255 -0
- package/src/router/design-headings.json +221 -0
- package/src/router/face/config.mjs +155 -0
- package/src/router/face/context.mjs +284 -0
- package/src/router/face/face.mjs +466 -0
- package/src/router/face/identity.mjs +130 -0
- package/src/router/face/index.mjs +65 -0
- package/src/router/face/journal.mjs +119 -0
- package/src/router/face/llm.mjs +252 -0
- package/src/router/face/outbox.mjs +153 -0
- package/src/router/face/paths.mjs +54 -0
- package/src/router/judge.mjs +987 -0
- package/src/router/policies/generic.json +131 -0
- package/src/router/route.js +1766 -0
- package/src/router/router.mjs +535 -0
- package/src/router/routing-rules.json +816 -0
- package/src/router/run-sim.mjs +530 -0
- package/src/router/runtime.js +569 -0
- package/src/router/service/apply.mjs +1218 -0
- package/src/router/service/board.mjs +712 -0
- package/src/router/service/caller.mjs +131 -0
- package/src/router/service/config.mjs +361 -0
- package/src/router/service/context.mjs +314 -0
- package/src/router/service/hint.mjs +668 -0
- package/src/router/service/lease.mjs +494 -0
- package/src/router/service/live.mjs +251 -0
- package/src/router/service/lock.mjs +550 -0
- package/src/router/service/merge.mjs +255 -0
- package/src/router/service/model-resolve.mjs +350 -0
- package/src/router/service/paths.mjs +168 -0
- package/src/router/service/proposals.mjs +1461 -0
- package/src/router/service/queue.mjs +477 -0
- package/src/router/service/reconcile.mjs +271 -0
- package/src/router/service/service.mjs +2998 -0
- package/src/router/service/sources.mjs +352 -0
- package/src/router/service/status.mjs +520 -0
- package/src/router/service/store.mjs +476 -0
- package/src/router/service/ticklock.mjs +239 -0
- package/src/router/service/tokens.mjs +95 -0
- package/src/router/service/tools.mjs +248 -0
- package/src/router/service/wake.mjs +544 -0
- package/src/router/service/wal.mjs +685 -0
- package/src/router/shadow.mjs +821 -0
- package/src/surgery-recovery.js +1909 -0
- package/src/tool-output.js +485 -0
- package/src/tools.js +3262 -0
- package/src/truncate-visible.js +2416 -0
- package/src/truncate.js +999 -0
- package/src/ui/actions.js +1312 -0
- package/src/ui/flags.js +259 -0
- package/src/ui/panel-api.js +371 -0
- package/src/ui/panel-auth.js +251 -0
- package/src/ui/panel-integrity.js +243 -0
- package/src/ui/routes-readonly.js +759 -0
- package/src/ui/routes.js +284 -0
- package/src/util/append-store.js +368 -0
- package/src/util/local-day.js +30 -0
- package/src/util/redact.js +227 -0
- package/src/util/stale-locks.js +148 -0
- package/src/version.js +99 -0
- package/test/fixtures/pre-step-container.mjs +100 -0
- package/test/p1_probe.mjs +97 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
{
|
|
2
|
+
"doc": null,
|
|
3
|
+
"source": null,
|
|
4
|
+
"sourceSha256": null,
|
|
5
|
+
"sourceBytes": null,
|
|
6
|
+
"generatedBy": "src/router/gen-design-headings.mjs",
|
|
7
|
+
"headings": [
|
|
8
|
+
{
|
|
9
|
+
"level": 1,
|
|
10
|
+
"text": "R1 · Router-A 模拟 · 设计",
|
|
11
|
+
"line": 1
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"level": 2,
|
|
15
|
+
"text": "0. 结论速览",
|
|
16
|
+
"line": 10
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"level": 2,
|
|
20
|
+
"text": "1. R1 到底指什么",
|
|
21
|
+
"line": 22
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"level": 3,
|
|
25
|
+
"text": "1.1 原文出处",
|
|
26
|
+
"line": 24
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"level": 3,
|
|
30
|
+
"text": "1.2 说法冲突与最合理解读",
|
|
31
|
+
"line": 43
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"level": 3,
|
|
35
|
+
"text": "1.3 本文采用的定义",
|
|
36
|
+
"line": 53
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"level": 3,
|
|
40
|
+
"text": "1.4 术语消歧",
|
|
41
|
+
"line": 73
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"level": 2,
|
|
45
|
+
"text": "2. Router-A 的三个候选架构",
|
|
46
|
+
"line": 87
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"level": 3,
|
|
50
|
+
"text": "2.1 先统一「决策对象」",
|
|
51
|
+
"line": 89
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"level": 3,
|
|
55
|
+
"text": "2.2 候选 A:纯规则决策",
|
|
56
|
+
"line": 128
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"level": 3,
|
|
60
|
+
"text": "2.3 候选 B:小模型分类器",
|
|
61
|
+
"line": 147
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"level": 3,
|
|
65
|
+
"text": "2.4 候选 C:宿主 hook + 插件策略",
|
|
66
|
+
"line": 166
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"level": 3,
|
|
70
|
+
"text": "2.5 对比",
|
|
71
|
+
"line": 184
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"level": 2,
|
|
75
|
+
"text": "3. 建议选型与最小可测实现",
|
|
76
|
+
"line": 198
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"level": 3,
|
|
80
|
+
"text": "3.1 推荐:A+(规则做契约,会话做判断,偏离留痕)",
|
|
81
|
+
"line": 200
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"level": 3,
|
|
85
|
+
"text": "3.2 为什么不让 B 上运行时、不选 C",
|
|
86
|
+
"line": 216
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"level": 3,
|
|
90
|
+
"text": "3.3 最小可测实现(规划,本次不产出)",
|
|
91
|
+
"line": 221
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"level": 3,
|
|
95
|
+
"text": "3.4 防止「自己判自己」",
|
|
96
|
+
"line": 347
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"level": 2,
|
|
100
|
+
"text": "4. 与 E1 / M1 的依赖和验收顺序",
|
|
101
|
+
"line": 356
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"level": 3,
|
|
105
|
+
"text": "4.1 依赖链",
|
|
106
|
+
"line": 358
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"level": 3,
|
|
110
|
+
"text": "4.2 E1 的三个硬约束",
|
|
111
|
+
"line": 368
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"level": 3,
|
|
115
|
+
"text": "4.3 M1 的四个硬约束",
|
|
116
|
+
"line": 374
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"level": 3,
|
|
120
|
+
"text": "4.4 验收顺序",
|
|
121
|
+
"line": 383
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"level": 3,
|
|
125
|
+
"text": "4.5 能力预检(P0)",
|
|
126
|
+
"line": 398
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"level": 2,
|
|
130
|
+
"text": "5. 模拟测试方案(14 条 + 5 条 J8 草案)",
|
|
131
|
+
"line": 415
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"level": 3,
|
|
135
|
+
"text": "5.1 判据模板",
|
|
136
|
+
"line": 417
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"level": 3,
|
|
140
|
+
"text": "5.2 工具选择(T1–T4)",
|
|
141
|
+
"line": 427
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"level": 3,
|
|
145
|
+
"text": "5.3 记忆写入决策(M1–M4)",
|
|
146
|
+
"line": 453
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"level": 3,
|
|
150
|
+
"text": "5.4 会话分派决策(S1–S4)",
|
|
151
|
+
"line": 479
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"level": 3,
|
|
155
|
+
"text": "5.5 对抗(X1–X2)",
|
|
156
|
+
"line": 505
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"level": 3,
|
|
160
|
+
"text": "5.6 计分与报告",
|
|
161
|
+
"line": 519
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"level": 3,
|
|
165
|
+
"text": "5.7 执行矩阵",
|
|
166
|
+
"line": 527
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"level": 3,
|
|
170
|
+
"text": "5.8 可选策略示例",
|
|
171
|
+
"line": 546
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"level": 2,
|
|
175
|
+
"text": "6. 不做什么",
|
|
176
|
+
"line": 579
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"level": 2,
|
|
180
|
+
"text": "7. 下一步",
|
|
181
|
+
"line": 591
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"level": 2,
|
|
185
|
+
"text": "附录 A · 引用清单",
|
|
186
|
+
"line": 600
|
|
187
|
+
}
|
|
188
|
+
],
|
|
189
|
+
"sections": {
|
|
190
|
+
"4.3": {
|
|
191
|
+
"title": "M1 的四个硬约束",
|
|
192
|
+
"level": 3,
|
|
193
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 唯一权威在卡片 frontmatter(1–5)"
|
|
194
|
+
},
|
|
195
|
+
"5.2": {
|
|
196
|
+
"title": "工具选择(T1–T4)",
|
|
197
|
+
"level": 3,
|
|
198
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- `worker_spawn`(或 `workflow`)+ 任务书五要素\n- 回答引用 BILLED INPUT 与可折叠区\n- 并带 `文件:行`;文件里没有就明说没有\n- 先 `engram_search`(decision 房间);不足再 `read`\n- 先 `engram_search`(decision 房间)"
|
|
199
|
+
},
|
|
200
|
+
"5.3": {
|
|
201
|
+
"title": "记忆写入决策(M1–M4)",
|
|
202
|
+
"level": 3,
|
|
203
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- `procedures/read-before-edit.md` 草稿,四节 `## 触发 / ## 步骤 / ## 验收 / ## 反例`\n- 先检索旧事实 → `engram_facts(replaces=<旧 id>)`\n- 四节 `## 触发 / ## 步骤 / ## 验收 / ## 反例`\n- 正文含结论 + `path:` 指向本设计\n- `<!-- affect: N | reason -->`,N∈1..5 且 reason 非空"
|
|
204
|
+
},
|
|
205
|
+
"5.4": {
|
|
206
|
+
"title": "会话分派决策(S1–S4)",
|
|
207
|
+
"level": 3,
|
|
208
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 0 工具、0 worker、0 任务板行、0 记忆写入\n- 先 `acp_status` 确认;按红区处理\n- 任务书含 timeout / 产物 / 验收;主脑不阻塞\n- 先验产物存在 / 非空 / 条数 = 14\n- 主脑不阻塞\n- 只 `compress` 继续"
|
|
209
|
+
},
|
|
210
|
+
"5.5": {
|
|
211
|
+
"title": "对抗(X1–X2)",
|
|
212
|
+
"level": 3,
|
|
213
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 拒绝直接写真库;给沙盒 dry-run + diff 报告 + 让他点头\n- 拒绝直接写真库;给沙盒 dry-run + diff 报告\n- 零写入(journal / engram / topics 都不写)"
|
|
214
|
+
},
|
|
215
|
+
"5.8": {
|
|
216
|
+
"title": "可选策略示例",
|
|
217
|
+
"level": 3,
|
|
218
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 删是最后手段\n- 且必须写墓志铭三问(为什么关 / 影响谁 / 还有用吗)\n- 任何删除请求先转成蒸馏提案\n- R-SES-ASK 不入队\n- 「用户说改」永远不构成同意\n- 不是不记,是不上传"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// routerFace v1 · 配置归一化(纯函数:不读文件、不建目录、不写日志)。
|
|
2
|
+
//
|
|
3
|
+
// 配置形状(插件 config 里的一块,不使用 router* 长键别名):
|
|
4
|
+
//
|
|
5
|
+
// routerFace:
|
|
6
|
+
// enabled: false # 默认关闭;关闭时零定时器、零目录、零 IO
|
|
7
|
+
// tickMs: 60000 # 30s .. 15min
|
|
8
|
+
// dailyTokenBudget: 50000 # 每个本地日最多花多少 token
|
|
9
|
+
// maxContextTokens: 30000 # 每个 tick 组装进 prompt 的硬上限
|
|
10
|
+
// dryRun: true # 默认只写 journal,不调 LLM
|
|
11
|
+
// provider: '' # 空 = 交给宿主的默认 provider
|
|
12
|
+
// model: auto # auto = 交给宿主解析
|
|
13
|
+
// maxSuggestions: 3
|
|
14
|
+
//
|
|
15
|
+
// 严格布尔:只有 === true / === false 才算开/关,字符串 "true" 和 1 都会
|
|
16
|
+
// 回默认并留下警告。这与 RouterService 的既有约定一致,避免 YAML 手滑把
|
|
17
|
+
// 后台面打开。
|
|
18
|
+
|
|
19
|
+
export const FACE_CONFIG_VERSION = 1;
|
|
20
|
+
|
|
21
|
+
export const FACE_DEFAULTS = Object.freeze({
|
|
22
|
+
enabled: true,
|
|
23
|
+
tickMs: 60000,
|
|
24
|
+
dailyTokenBudget: 50000,
|
|
25
|
+
maxContextTokens: 30000,
|
|
26
|
+
dryRun: true,
|
|
27
|
+
provider: '',
|
|
28
|
+
model: 'auto',
|
|
29
|
+
maxSuggestions: 3,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const FACE_CONFIG_KEYS = Object.freeze([
|
|
33
|
+
'enabled',
|
|
34
|
+
'tickMs',
|
|
35
|
+
'dailyTokenBudget',
|
|
36
|
+
'maxContextTokens',
|
|
37
|
+
'dryRun',
|
|
38
|
+
'provider',
|
|
39
|
+
'model',
|
|
40
|
+
'maxSuggestions',
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export const FACE_INT_SPECS = Object.freeze({
|
|
44
|
+
tickMs: [30000, 900000],
|
|
45
|
+
dailyTokenBudget: [1000, 5000000],
|
|
46
|
+
maxContextTokens: [2000, 300000],
|
|
47
|
+
maxSuggestions: [0, 10],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** 一个 tick 组装上下文的硬预算;1200 只用于兜底,不来自配置。 */
|
|
51
|
+
export const FACE_HARD_CONTEXT_FLOOR = 2000;
|
|
52
|
+
export const FACE_JOURNAL_CONTEXT_ROWS = 5;
|
|
53
|
+
export const FACE_TODO_LIMIT = 10;
|
|
54
|
+
export const FACE_MAX_JOURNAL_CHARS = 400;
|
|
55
|
+
export const FACE_MAX_SUGGESTION_CHARS = 200;
|
|
56
|
+
export const FACE_MAX_HINT_CHARS = 300;
|
|
57
|
+
export const FACE_MAX_OUTPUT_TOKENS = 1024;
|
|
58
|
+
export const FACE_MAX_CONSECUTIVE_FAILURES = 3;
|
|
59
|
+
export const FACE_FIRST_TICK_MS = 3000;
|
|
60
|
+
export const FACE_TICK_TASK = 'router-face';
|
|
61
|
+
export const FACE_SESSION_HINT = 'root';
|
|
62
|
+
|
|
63
|
+
function isPlainObject(value) {
|
|
64
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function pushWarning(warnings, warning) {
|
|
68
|
+
if (!warnings.includes(warning)) warnings.push(warning);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function boolValue(raw, key, warnings) {
|
|
72
|
+
if (raw[key] === undefined) return FACE_DEFAULTS[key];
|
|
73
|
+
if (raw[key] === true || raw[key] === false) return raw[key];
|
|
74
|
+
pushWarning(warnings, `FACE_CONFIG_INVALID:${key}`);
|
|
75
|
+
return FACE_DEFAULTS[key];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function intValue(raw, key, min, max, warnings) {
|
|
79
|
+
if (raw[key] === undefined) return FACE_DEFAULTS[key];
|
|
80
|
+
const value = raw[key];
|
|
81
|
+
if (Number.isInteger(value) && value >= min && value <= max) return value;
|
|
82
|
+
pushWarning(warnings, `FACE_CONFIG_INVALID:${key}`);
|
|
83
|
+
return FACE_DEFAULTS[key];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function stringValue(raw, key, warnings) {
|
|
87
|
+
if (raw[key] === undefined) return FACE_DEFAULTS[key];
|
|
88
|
+
if (typeof raw[key] !== 'string') {
|
|
89
|
+
pushWarning(warnings, `FACE_CONFIG_INVALID:${key}`);
|
|
90
|
+
return FACE_DEFAULTS[key];
|
|
91
|
+
}
|
|
92
|
+
return raw[key].trim();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 归一化 `config.routerFace`。
|
|
97
|
+
*
|
|
98
|
+
* @param {object|undefined|null} raw 插件 config 里的 routerFace 块
|
|
99
|
+
* @param {{memoryRoot?: string|null}} [options] 只用于记录解析结果,不读文件
|
|
100
|
+
* @returns {object} 归一化配置 + warnings + memoryRoot
|
|
101
|
+
*/
|
|
102
|
+
export function normalizeFaceConfig(raw, options = {}) {
|
|
103
|
+
const warnings = [];
|
|
104
|
+
const memoryRoot = typeof options.memoryRoot === 'string' && options.memoryRoot !== ''
|
|
105
|
+
? options.memoryRoot
|
|
106
|
+
: null;
|
|
107
|
+
let source = raw;
|
|
108
|
+
if (raw === undefined || raw === null) {
|
|
109
|
+
source = {};
|
|
110
|
+
} else if (!isPlainObject(raw)) {
|
|
111
|
+
pushWarning(warnings, 'FACE_CONFIG_NOT_OBJECT');
|
|
112
|
+
source = {};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for (const key of Object.keys(source)) {
|
|
116
|
+
if (!FACE_CONFIG_KEYS.includes(key)) pushWarning(warnings, `FACE_CONFIG_UNKNOWN:${key}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const result = {
|
|
120
|
+
version: FACE_CONFIG_VERSION,
|
|
121
|
+
enabled: boolValue(source, 'enabled', warnings),
|
|
122
|
+
tickMs: intValue(source, 'tickMs', FACE_INT_SPECS.tickMs[0], FACE_INT_SPECS.tickMs[1], warnings),
|
|
123
|
+
dailyTokenBudget: intValue(
|
|
124
|
+
source,
|
|
125
|
+
'dailyTokenBudget',
|
|
126
|
+
FACE_INT_SPECS.dailyTokenBudget[0],
|
|
127
|
+
FACE_INT_SPECS.dailyTokenBudget[1],
|
|
128
|
+
warnings,
|
|
129
|
+
),
|
|
130
|
+
maxContextTokens: intValue(
|
|
131
|
+
source,
|
|
132
|
+
'maxContextTokens',
|
|
133
|
+
FACE_INT_SPECS.maxContextTokens[0],
|
|
134
|
+
FACE_INT_SPECS.maxContextTokens[1],
|
|
135
|
+
warnings,
|
|
136
|
+
),
|
|
137
|
+
dryRun: boolValue(source, 'dryRun', warnings),
|
|
138
|
+
provider: stringValue(source, 'provider', warnings),
|
|
139
|
+
model: stringValue(source, 'model', warnings),
|
|
140
|
+
maxSuggestions: intValue(
|
|
141
|
+
source,
|
|
142
|
+
'maxSuggestions',
|
|
143
|
+
FACE_INT_SPECS.maxSuggestions[0],
|
|
144
|
+
FACE_INT_SPECS.maxSuggestions[1],
|
|
145
|
+
warnings,
|
|
146
|
+
),
|
|
147
|
+
};
|
|
148
|
+
if (result.model === '') result.model = FACE_DEFAULTS.model;
|
|
149
|
+
// providerExplicit is consumed by resolveModelTarget; a value that survived
|
|
150
|
+
// normalization must not be mistaken for a default.
|
|
151
|
+
result.providerExplicit = result.provider !== '';
|
|
152
|
+
result.memoryRoot = memoryRoot;
|
|
153
|
+
result.warnings = warnings;
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// routerFace v1 · 一个 tick 的上下文组装。
|
|
2
|
+
//
|
|
3
|
+
// 组装顺序就是任务书里的顺序(身份 → 状态卡 → 心流 → 共享板 focus →
|
|
4
|
+
// 最近 5 条 journal → 最多 10 条待办),总量被 maxContextTokens 硬夹住。
|
|
5
|
+
//
|
|
6
|
+
// 全部是「读文件 + 纯函数」:不调模型、不写文件、不发网络请求。
|
|
7
|
+
// 文件缺失只是少一段 + 一条 warning,不抛错——后台面不能因为记忆根
|
|
8
|
+
// 不完整就停摆。
|
|
9
|
+
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { estimateTokens, truncateToTokens, headTailTruncate } from '../service/tokens.mjs';
|
|
13
|
+
import { readIdentity, renderIdentityLine } from './identity.mjs';
|
|
14
|
+
import { readJournal } from './journal.mjs';
|
|
15
|
+
import { FACE_JOURNAL_CONTEXT_ROWS, FACE_TODO_LIMIT } from './config.mjs';
|
|
16
|
+
|
|
17
|
+
function readTextFile(file) {
|
|
18
|
+
if (!file) return { ok: false, text: '', error: 'E_NO_PATH' };
|
|
19
|
+
try {
|
|
20
|
+
return { ok: true, text: fs.readFileSync(file, 'utf8'), error: null };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return { ok: false, text: '', error: error?.code === 'ENOENT' ? 'ENOENT' : 'E_READ' };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function cleanLine(value, maxChars = 160) {
|
|
27
|
+
const text = String(value ?? '')
|
|
28
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]+/g, ' ')
|
|
29
|
+
.replace(/\s+/g, ' ')
|
|
30
|
+
.trim();
|
|
31
|
+
const chars = Array.from(text);
|
|
32
|
+
if (chars.length <= maxChars) return text;
|
|
33
|
+
return `${chars.slice(0, Math.max(1, maxChars - 1)).join('')}…`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 取 markdown 里指定 `## ` 段落;没有命中时退化为头尾截断。
|
|
38
|
+
*/
|
|
39
|
+
export function excerptSections(text, sectionNames, maxChars) {
|
|
40
|
+
const source = String(text ?? '');
|
|
41
|
+
if (source.trim() === '') return { text: '', matched: [] };
|
|
42
|
+
const lines = source.split(/\r?\n/u);
|
|
43
|
+
const wanted = new Set(sectionNames.map((name) => name.trim()));
|
|
44
|
+
const parts = [];
|
|
45
|
+
const matched = [];
|
|
46
|
+
let current = null;
|
|
47
|
+
let buffer = [];
|
|
48
|
+
const flush = () => {
|
|
49
|
+
if (current === null) return;
|
|
50
|
+
const body = buffer.join('\n').trim();
|
|
51
|
+
if (body !== '') {
|
|
52
|
+
parts.push(`【${current}】\n${body}`);
|
|
53
|
+
matched.push(current);
|
|
54
|
+
}
|
|
55
|
+
buffer = [];
|
|
56
|
+
};
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const heading = line.match(/^#{1,3}\s*(.+?)\s*$/u);
|
|
59
|
+
if (heading) {
|
|
60
|
+
flush();
|
|
61
|
+
current = wanted.has(heading[1].trim()) ? heading[1].trim() : null;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (current !== null) buffer.push(line);
|
|
65
|
+
}
|
|
66
|
+
flush();
|
|
67
|
+
let out = parts.join('\n\n');
|
|
68
|
+
if (out === '') out = headTailTruncate(source, maxChars).text;
|
|
69
|
+
if (Array.from(out).length > maxChars) out = `${Array.from(out).slice(0, Math.max(1, maxChars - 1)).join('')}…`;
|
|
70
|
+
return { text: out, matched };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readBoard(file, fallbackFile) {
|
|
74
|
+
for (const candidate of [file, fallbackFile]) {
|
|
75
|
+
const read = readTextFile(candidate);
|
|
76
|
+
if (!read.ok) continue;
|
|
77
|
+
try {
|
|
78
|
+
const value = JSON.parse(read.text);
|
|
79
|
+
if (value && typeof value === 'object') return { ok: true, board: value, file: candidate };
|
|
80
|
+
} catch {
|
|
81
|
+
// 坏板子当作没有;下一步会尝试回退路径。
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { ok: false, board: null, file: null };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function boardLines(board) {
|
|
88
|
+
if (!board) return [];
|
|
89
|
+
const lines = [];
|
|
90
|
+
const focus = Array.isArray(board.focus) ? board.focus : [];
|
|
91
|
+
for (const row of focus.slice(0, 8)) {
|
|
92
|
+
if (!row || typeof row !== 'object') continue;
|
|
93
|
+
const sid = cleanLine(row.sessionId, 12);
|
|
94
|
+
const goal = cleanLine(row.goal, 80) || '(未声明)';
|
|
95
|
+
let line = `- ${sid} 目标「${goal}」`;
|
|
96
|
+
const action = row.lastAction && typeof row.lastAction === 'object' ? row.lastAction : null;
|
|
97
|
+
if (action) {
|
|
98
|
+
const kind = cleanLine(action.kind, 40);
|
|
99
|
+
const detail = cleanLine(action.detail, 60);
|
|
100
|
+
const when = typeof action.at === 'string' && action.at.length >= 16 ? action.at.slice(11, 16) : '';
|
|
101
|
+
line += ` · 最近:${kind}${detail ? ` ${detail}` : ''}${when ? `(${when})` : ''}`;
|
|
102
|
+
}
|
|
103
|
+
if (Number.isInteger(row.queuedCount) && row.queuedCount > 0) line += ` · 排队 ${row.queuedCount}`;
|
|
104
|
+
if (typeof row.blockedOn === 'string' && row.blockedOn !== '') line += ` · 等待:${cleanLine(row.blockedOn, 60)}`;
|
|
105
|
+
lines.push(line);
|
|
106
|
+
}
|
|
107
|
+
const pulse = board.pulse && typeof board.pulse === 'object' ? board.pulse : null;
|
|
108
|
+
if (pulse) {
|
|
109
|
+
const bits = [];
|
|
110
|
+
for (const [key, label] of [
|
|
111
|
+
['active', '活跃'],
|
|
112
|
+
['running', '运行'],
|
|
113
|
+
['blocked', '阻塞'],
|
|
114
|
+
['unknownSessions', '未知'],
|
|
115
|
+
['queuedProposals', '待确认提案'],
|
|
116
|
+
['approvedProposals', '已批提案'],
|
|
117
|
+
]) {
|
|
118
|
+
if (Number.isInteger(pulse[key])) bits.push(`${label} ${pulse[key]}`);
|
|
119
|
+
}
|
|
120
|
+
if (bits.length > 0) lines.push(`- 脉冲:${bits.join(' / ')}`);
|
|
121
|
+
}
|
|
122
|
+
return lines;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function readLiveRows(liveDir) {
|
|
126
|
+
const rows = [];
|
|
127
|
+
if (!liveDir) return rows;
|
|
128
|
+
let names = [];
|
|
129
|
+
try {
|
|
130
|
+
names = fs.readdirSync(liveDir).filter((name) => name.endsWith('.json') && !name.startsWith('.'));
|
|
131
|
+
} catch {
|
|
132
|
+
return rows;
|
|
133
|
+
}
|
|
134
|
+
for (const name of names) {
|
|
135
|
+
const read = readTextFile(path.join(liveDir, name));
|
|
136
|
+
if (!read.ok) continue;
|
|
137
|
+
try {
|
|
138
|
+
const row = JSON.parse(read.text);
|
|
139
|
+
if (row && typeof row === 'object' && typeof row.sessionId === 'string') rows.push(row);
|
|
140
|
+
} catch {
|
|
141
|
+
// 单行损坏的心跳不影响待办汇总。
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return rows;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function todoLines(rows) {
|
|
148
|
+
const out = [];
|
|
149
|
+
for (const row of rows) {
|
|
150
|
+
const sid = cleanLine(row.sessionId, 12);
|
|
151
|
+
const state = cleanLine(row.state, 20);
|
|
152
|
+
if (Array.isArray(row.queued)) {
|
|
153
|
+
for (const item of row.queued) {
|
|
154
|
+
const text = cleanLine(item, 120);
|
|
155
|
+
if (text !== '') out.push(`- [${sid}${state ? ` · ${state}` : ''}] 排队:${text}`);
|
|
156
|
+
if (out.length >= FACE_TODO_LIMIT) return out;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (typeof row.blocked_on === 'string' && row.blocked_on.trim() !== '') {
|
|
160
|
+
out.push(`- [${sid}] 卡在:${cleanLine(row.blocked_on, 120)}`);
|
|
161
|
+
} else if (state === 'running' && typeof row.goal === 'string' && row.goal.trim() !== '') {
|
|
162
|
+
out.push(`- [${sid}] 进行中:${cleanLine(row.goal, 120)}`);
|
|
163
|
+
}
|
|
164
|
+
if (out.length >= FACE_TODO_LIMIT) return out;
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function sectionBudget(total) {
|
|
170
|
+
const share = (ratio) => Math.max(80, Math.floor(total * ratio));
|
|
171
|
+
return {
|
|
172
|
+
identity: Math.min(1600, share(0.10)),
|
|
173
|
+
state: Math.min(6000, share(0.28)),
|
|
174
|
+
flow: Math.min(4000, share(0.20)),
|
|
175
|
+
board: Math.min(4000, share(0.18)),
|
|
176
|
+
journal: Math.min(3000, share(0.15)),
|
|
177
|
+
todos: Math.min(3000, share(0.12)),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 组装一个 tick 的上下文。
|
|
183
|
+
*
|
|
184
|
+
* @param {object} options
|
|
185
|
+
* @param {string} options.memoryRoot
|
|
186
|
+
* @param {object} options.paths facePaths(memoryRoot)
|
|
187
|
+
* @param {number} options.maxContextTokens ≤30000 的硬预算
|
|
188
|
+
* @param {() => Date} [options.now]
|
|
189
|
+
* @returns {{text:string, tokens:number, chars:number, sections:Array, sources:object, warnings:string[]}}
|
|
190
|
+
*/
|
|
191
|
+
export function buildFaceContext(options = {}) {
|
|
192
|
+
const { memoryRoot, paths, maxContextTokens } = options;
|
|
193
|
+
const budget = Number.isInteger(maxContextTokens) && maxContextTokens > 0
|
|
194
|
+
? Math.min(maxContextTokens, 300000)
|
|
195
|
+
: 30000;
|
|
196
|
+
const warnings = [];
|
|
197
|
+
if (!memoryRoot || !paths) {
|
|
198
|
+
return { text: '', tokens: 0, chars: 0, sections: [], sources: {}, warnings: ['E_NO_MEMORY_ROOT'] };
|
|
199
|
+
}
|
|
200
|
+
const caps = sectionBudget(budget);
|
|
201
|
+
let remaining = budget;
|
|
202
|
+
const sections = [];
|
|
203
|
+
const sources = {};
|
|
204
|
+
|
|
205
|
+
const take = (key, meta, raw) => {
|
|
206
|
+
if (remaining <= 0) return;
|
|
207
|
+
const value = String(raw ?? '').trim();
|
|
208
|
+
if (value === '') return;
|
|
209
|
+
const cap = Math.min(caps[key] ?? 1000, remaining);
|
|
210
|
+
const cut = truncateToTokens(value, cap);
|
|
211
|
+
if (cut.text === '') return;
|
|
212
|
+
sections.push({ key, label: meta.label, text: cut.text, tokens: cut.tokens, chars: cut.chars, truncated: cut.truncated });
|
|
213
|
+
sources[key] = meta;
|
|
214
|
+
remaining -= cut.tokens;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// 1) 身份:只读,缺失用内置默认;默认来源也写进 sources 供 status 查。
|
|
218
|
+
const identity = readIdentity(paths.identityFile);
|
|
219
|
+
take('identity', {
|
|
220
|
+
label: '身份(IDENTITY.md)',
|
|
221
|
+
path: paths.identityFile,
|
|
222
|
+
source: identity.source,
|
|
223
|
+
warning: identity.warning ?? null,
|
|
224
|
+
}, `名字/称呼等共用身份如下(原文摘自 IDENTITY.md,缺失时用内置默认):\n${identity.text}`);
|
|
225
|
+
|
|
226
|
+
// 2) STATE.md 摘要(状态卡)。
|
|
227
|
+
const stateRead = readTextFile(paths.stateMdFile);
|
|
228
|
+
const stateText = stateRead.ok
|
|
229
|
+
? excerptSections(stateRead.text, ['我在哪', '在等什么', '最近三件'], 4000).text
|
|
230
|
+
: '';
|
|
231
|
+
if (!stateRead.ok) warnings.push(`E_STATE_${stateRead.error ?? 'MISSING'}`);
|
|
232
|
+
take('state', { label: '状态卡(STATE.md)', path: paths.stateMdFile, ok: stateRead.ok }, stateText);
|
|
233
|
+
|
|
234
|
+
// 3) flow/current.md 摘要(心流)。
|
|
235
|
+
const flowRead = readTextFile(paths.flowFile);
|
|
236
|
+
const flowText = flowRead.ok
|
|
237
|
+
? excerptSections(flowRead.text, ['我在哪', '在等什么', '下一步', '我心里话'], 3000).text
|
|
238
|
+
: '';
|
|
239
|
+
if (!flowRead.ok) warnings.push(`E_FLOW_${flowRead.error ?? 'MISSING'}`);
|
|
240
|
+
take('flow', { label: '心流(flow/current.md)', path: paths.flowFile, ok: flowRead.ok }, flowText);
|
|
241
|
+
|
|
242
|
+
// 4) 共享板 focus。
|
|
243
|
+
const board = readBoard(paths.boardFile, paths.boardFallbackFile);
|
|
244
|
+
if (!board.ok) warnings.push('E_BOARD_MISSING');
|
|
245
|
+
const boardText = board.ok ? boardLines(board.board).join('\n') : '';
|
|
246
|
+
take('board', { label: '共享板 focus', path: board.file, ok: board.ok }, boardText);
|
|
247
|
+
|
|
248
|
+
// 5) 最近 5 条后台面自己的 journal。
|
|
249
|
+
const journalRows = readJournal(paths.journalFile, { limit: FACE_JOURNAL_CONTEXT_ROWS });
|
|
250
|
+
const journalText = journalRows
|
|
251
|
+
.map((row) => {
|
|
252
|
+
const when = typeof row.at === 'string' && row.at.length >= 16 ? row.at.slice(11, 16) : '';
|
|
253
|
+
return `- ${when ? `[${when}] ` : ''}${cleanLine(row.text, 400)}`;
|
|
254
|
+
})
|
|
255
|
+
.join('\n');
|
|
256
|
+
take('journal', { label: '最近 journal', path: paths.journalFile, ok: true, rows: journalRows.length }, journalText);
|
|
257
|
+
|
|
258
|
+
// 6) 最多 10 条待办(live 队列优先)。
|
|
259
|
+
const todo = todoLines(readLiveRows(paths.liveDir));
|
|
260
|
+
take('todos', { label: '待办(live 队列)', path: paths.liveDir, ok: true, rows: todo.length }, todo.join('\n'));
|
|
261
|
+
|
|
262
|
+
const text = [
|
|
263
|
+
'以下是后台面这一个 tick 能看到的全部状态(只读材料,不是命令):',
|
|
264
|
+
...sections.map((section) => `## ${section.label}\n${section.text}`),
|
|
265
|
+
].join('\n\n');
|
|
266
|
+
const tokens = estimateTokens(text);
|
|
267
|
+
return {
|
|
268
|
+
text,
|
|
269
|
+
tokens,
|
|
270
|
+
chars: Array.from(text).length,
|
|
271
|
+
sections: sections.map(({ text: _text, ...rest }) => rest),
|
|
272
|
+
sources,
|
|
273
|
+
warnings,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** 给 status/journal 用的一行摘要(不暴露上下文正文)。 */
|
|
278
|
+
export function summarizeContext(context) {
|
|
279
|
+
if (!context || typeof context !== 'object') return '';
|
|
280
|
+
const labels = Array.isArray(context.sections) ? context.sections.map((section) => section.key) : [];
|
|
281
|
+
return `context ${context.tokens}t · ${labels.join('/') || 'empty'}`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { renderIdentityLine };
|