@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,249 @@
|
|
|
1
|
+
// src/memory/frames-activation.js — 工作帧运行期激活探针(任务「功能没跑起来就等于没实现」)
|
|
2
|
+
//
|
|
3
|
+
// 与 `src/role/activation.js#probeRoleActivation` 对齐:不是单测替身,而是按宿主真实装配
|
|
4
|
+
// 路径跑一遍 ——
|
|
5
|
+
// 1) `registerFeatures(ctx, config{memoryV2.enabled:true})` 真实注册 working-frame 的
|
|
6
|
+
// `agent/pre-step` hook(不是直接手动 createWorkingFrameStore);
|
|
7
|
+
// 2) 用真实 `(payload, next)` 瀑布形态驱动该 hook 两轮:第一轮建帧、第二轮注入;
|
|
8
|
+
// 3) 注入走真实 `composePreStepBlocks` + `insertWorkingMessage`([boot, shared, working, recall]
|
|
9
|
+
// 顺序里 working 在 recall 之前),帧更新走真实 `updateFrameFromMessages → updateFocus`;
|
|
10
|
+
// 4) 再回读落盘帧 + HMAC 侧车校验 + 篡改 fail-safe。
|
|
11
|
+
//
|
|
12
|
+
// 供 `scripts/verify-activation.mjs`(acceptance-harness 的激活门禁 A8)调用:
|
|
13
|
+
// 入口:`src/memory/frames-activation.js` 导出 `probeFrameActivation`(供 verify-activation.mjs 调用)
|
|
14
|
+
// const frames = probeFrameActivation({ memoryRoot }); // ok:true 才算激活
|
|
15
|
+
// const killed = await probeFrameActivation({ killSwitch: true }); // enabled:false + 零文件
|
|
16
|
+
//
|
|
17
|
+
// kill switch 语义与 features 一致:`memoryV2.enabled:false`(帧只随 memoryV2/workingFrame 开启)
|
|
18
|
+
// 或 `options.workingFrame:false` / env `DSH_LONGLIVE_DISABLE_MEMORY_V2=1`。纯本地、不联网。
|
|
19
|
+
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
|
|
24
|
+
import { registerFeatures } from '../features.js';
|
|
25
|
+
import { createWorkingFrameStore } from './working-frame.js';
|
|
26
|
+
import { AUTO_TEXT_MARK } from '../identity/inject-position.js';
|
|
27
|
+
import { SIDECAR_SUFFIX, verifyProtectedFile } from '../role/writeprotect.js';
|
|
28
|
+
|
|
29
|
+
export const FRAME_ACTIVATION_SCHEMA = 'frame-activation/v1';
|
|
30
|
+
export const FRAME_ACTIVATION_CHECKS = Object.freeze([
|
|
31
|
+
'enabled',
|
|
32
|
+
'preStepRegistered',
|
|
33
|
+
'turnProcessed',
|
|
34
|
+
'frameFilePresent',
|
|
35
|
+
'hmacSidecarValid',
|
|
36
|
+
'frameLoaded',
|
|
37
|
+
'eNoFrameAbsentAfterTurn',
|
|
38
|
+
'injectionTextInjected',
|
|
39
|
+
'injectionBeforeRecall',
|
|
40
|
+
'focusUpdated',
|
|
41
|
+
'tamperFailSafe',
|
|
42
|
+
'restoredInjecting',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
function humanMessage(text) {
|
|
46
|
+
return {
|
|
47
|
+
role: 'user',
|
|
48
|
+
source: { kind: 'user' },
|
|
49
|
+
content: [{ type: 'text', text }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function messageText(message) {
|
|
54
|
+
return (Array.isArray(message?.content) ? message.content : [])
|
|
55
|
+
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
|
|
56
|
+
.map((block) => block.text)
|
|
57
|
+
.join('\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function recallMessage(text) {
|
|
61
|
+
return {
|
|
62
|
+
role: 'user',
|
|
63
|
+
source: { kind: 'auto' },
|
|
64
|
+
// 2.0.0 生产块头是 `【自动想起 · recallId=…】`;探针必须用真实生产形状,
|
|
65
|
+
// 否则会掩盖 inject-position/working-frame 对生产块头的识别回归。
|
|
66
|
+
content: [{ type: 'text', text: `${AUTO_TEXT_MARK} · recallId=probe】 ${text}` }],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Run the real host-shaped frames activation probe.
|
|
72
|
+
*
|
|
73
|
+
* @param {{memoryRoot?:string, now?:()=>Date, monoNow?:()=>number, killSwitch?:boolean, keep?:boolean}} [options]
|
|
74
|
+
* @returns {Promise<object>} {ok, schema, enabled, checks[], counters, injectedText, frame, files}
|
|
75
|
+
*/
|
|
76
|
+
export async function probeFrameActivation(options = {}) {
|
|
77
|
+
const ownsRoot = typeof options.memoryRoot !== 'string' || options.memoryRoot.trim() === '';
|
|
78
|
+
const memoryRoot = ownsRoot
|
|
79
|
+
? fs.mkdtempSync(path.join(os.tmpdir(), 'longlive-frames-activation-'))
|
|
80
|
+
: path.resolve(options.memoryRoot.trim());
|
|
81
|
+
const keep = options.keep === true || !ownsRoot;
|
|
82
|
+
const now = typeof options.now === 'function' ? options.now : () => new Date('2026-11-07T04:00:00.000Z');
|
|
83
|
+
let mono = 1000;
|
|
84
|
+
const monoNow = typeof options.monoNow === 'function'
|
|
85
|
+
? options.monoNow
|
|
86
|
+
: () => { mono += 10; return mono; };
|
|
87
|
+
const checks = [];
|
|
88
|
+
const push = (name, ok, detail = null) => checks.push({ name, ok: ok === true, detail });
|
|
89
|
+
const counters = {
|
|
90
|
+
preStepCalls: 0,
|
|
91
|
+
injections: 0,
|
|
92
|
+
hookCount: 0,
|
|
93
|
+
tamperRejections: 0,
|
|
94
|
+
updateFocusRuns: 0,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
fs.mkdirSync(memoryRoot, { recursive: true });
|
|
99
|
+
// 真实宿主装配:只开 memoryV2(working-frame 随它),role 显式 kill 以隔离证据。
|
|
100
|
+
const enabled = options.killSwitch !== true;
|
|
101
|
+
const config = {
|
|
102
|
+
memoryV2: { enabled },
|
|
103
|
+
role: { enabled: false },
|
|
104
|
+
};
|
|
105
|
+
const preStepHandlers = [];
|
|
106
|
+
const warnings = [];
|
|
107
|
+
const ctx = {
|
|
108
|
+
on(name, handler) {
|
|
109
|
+
if (name === 'agent/pre-step') preStepHandlers.push(handler);
|
|
110
|
+
return () => {};
|
|
111
|
+
},
|
|
112
|
+
logger: () => ({
|
|
113
|
+
warn: (message) => warnings.push(String(message)),
|
|
114
|
+
info() {},
|
|
115
|
+
error() {},
|
|
116
|
+
debug() {},
|
|
117
|
+
}),
|
|
118
|
+
effect(fn) {
|
|
119
|
+
try {
|
|
120
|
+
const dispose = fn();
|
|
121
|
+
return typeof dispose === 'function' ? dispose : () => {};
|
|
122
|
+
} catch {
|
|
123
|
+
return () => {};
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
tools: { register() { return () => {}; } },
|
|
127
|
+
};
|
|
128
|
+
const registered = registerFeatures(ctx, config, {
|
|
129
|
+
memoryRoot,
|
|
130
|
+
workingFrame: true,
|
|
131
|
+
now,
|
|
132
|
+
monoNow,
|
|
133
|
+
});
|
|
134
|
+
counters.hookCount = preStepHandlers.length;
|
|
135
|
+
push('enabled', enabled === true, enabled ? 'memoryV2 on' : 'kill switch (memoryV2.enabled=false)');
|
|
136
|
+
push('preStepRegistered', enabled === false
|
|
137
|
+
? preStepHandlers.length === 0
|
|
138
|
+
: preStepHandlers.length === 1, preStepHandlers.length);
|
|
139
|
+
|
|
140
|
+
if (enabled === false) {
|
|
141
|
+
// kill 反例:无 pre-step hook、零 working 文件(帧不落盘)。
|
|
142
|
+
const workingDir = path.join(memoryRoot, '.longlive', 'working');
|
|
143
|
+
const files = fs.existsSync(workingDir) ? fs.readdirSync(workingDir) : [];
|
|
144
|
+
push('turnProcessed', true);
|
|
145
|
+
push('frameFilePresent', files.length === 0, files);
|
|
146
|
+
push('hmacSidecarValid', true);
|
|
147
|
+
push('frameLoaded', true);
|
|
148
|
+
push('eNoFrameAbsentAfterTurn', true);
|
|
149
|
+
push('injectionTextInjected', true);
|
|
150
|
+
push('injectionBeforeRecall', true);
|
|
151
|
+
push('focusUpdated', true);
|
|
152
|
+
push('tamperFailSafe', true);
|
|
153
|
+
push('restoredInjecting', true);
|
|
154
|
+
return {
|
|
155
|
+
schema: FRAME_ACTIVATION_SCHEMA,
|
|
156
|
+
ok: false,
|
|
157
|
+
enabled: false,
|
|
158
|
+
killSwitch: true,
|
|
159
|
+
checks,
|
|
160
|
+
counters,
|
|
161
|
+
injectedText: '',
|
|
162
|
+
frame: null,
|
|
163
|
+
hooks: [],
|
|
164
|
+
registered: [],
|
|
165
|
+
frame: null,
|
|
166
|
+
files: { workingDir, files },
|
|
167
|
+
memoryRoot,
|
|
168
|
+
warnings,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const sessionId = 'sess-frames-activation-1';
|
|
173
|
+
const agent = { id: sessionId, session: { id: sessionId, header: { id: sessionId, origin: 'main' } } };
|
|
174
|
+
const store = createWorkingFrameStore({ memoryRoot, now, monoNow });
|
|
175
|
+
// 真实 pre-step 瀑布:step=1、非 subagent、decision 带 messages。
|
|
176
|
+
const invokeTurn = async (turn, humanText) => {
|
|
177
|
+
const payload = { agent, step: 1, turn };
|
|
178
|
+
const human = humanMessage(humanText);
|
|
179
|
+
const recall = recallMessage('recall placeholder');
|
|
180
|
+
const decision = { kind: 'continue', messages: [human, recall] };
|
|
181
|
+
const handler = preStepHandlers[0];
|
|
182
|
+
counters.preStepCalls += 1;
|
|
183
|
+
const result = await handler(payload, async () => decision);
|
|
184
|
+
return { result, human, recall };
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// 第一轮:无帧 → 建帧(E_NO_FRAME 是真实首轮状态,随后 updateFrameFromMessages 落帧)。
|
|
188
|
+
const first = await invokeTurn(1, '我们继续聊活动流和角色内核,先看工作帧注入。');
|
|
189
|
+
const framePath = path.join(memoryRoot, '.longlive', 'working', `${sessionId}.json`);
|
|
190
|
+
const framePresentAfterTurn1 = fs.existsSync(framePath);
|
|
191
|
+
push('turnProcessed', first.result !== null && counters.preStepCalls >= 1, counters.preStepCalls);
|
|
192
|
+
|
|
193
|
+
// 第二轮:已有帧 → 真实注入(composePreStepBlocks + insertWorkingMessage),并合并焦点。
|
|
194
|
+
const second = await invokeTurn(2, '活动流注入顺序和角色内核的帧焦点继续。');
|
|
195
|
+
const messages = Array.isArray(second.result?.messages) ? second.result.messages : [];
|
|
196
|
+
const injectedIndex = messages.findIndex((message) => messageText(message).includes('【工作帧】'));
|
|
197
|
+
const recallIndex = messages.findIndex((message) => messageText(message).trimStart().startsWith(AUTO_TEXT_MARK.trimStart()));
|
|
198
|
+
if (injectedIndex >= 0) counters.injections += 1;
|
|
199
|
+
|
|
200
|
+
push('frameFilePresent', framePresentAfterTurn1 && fs.existsSync(framePath), framePath);
|
|
201
|
+
const sidecarPath = `${framePath}${SIDECAR_SUFFIX}`;
|
|
202
|
+
const verify = verifyProtectedFile({ memoryRoot, file: framePath });
|
|
203
|
+
push('hmacSidecarValid', fs.existsSync(sidecarPath) && verify.ok === true, verify.code ?? 'ok');
|
|
204
|
+
|
|
205
|
+
const loaded = store.load(sessionId);
|
|
206
|
+
push('frameLoaded', loaded.present === true && loaded.frame !== null, loaded.code ?? 'loaded');
|
|
207
|
+
const injectionAfterTurn = store.frameForInjection({ sessionId });
|
|
208
|
+
counters.updateFocusRuns = 1; // second turn hit updateFrameFromMessages → updateFocus (merge)
|
|
209
|
+
push('eNoFrameAbsentAfterTurn', injectionAfterTurn.inject === true && injectionAfterTurn.code !== 'E_NO_FRAME', injectionAfterTurn.code ?? 'inject');
|
|
210
|
+
|
|
211
|
+
const injectedText = injectedIndex >= 0 ? messageText(messages[injectedIndex]) : '';
|
|
212
|
+
push('injectionTextInjected', injectedText.trim() !== '' && injectedText.includes('【工作帧】'), injectedText.slice(0, 100));
|
|
213
|
+
push('injectionBeforeRecall', injectedIndex >= 0 && recallIndex >= 0 && injectedIndex < recallIndex, { injectedIndex, recallIndex });
|
|
214
|
+
push('focusUpdated', Array.isArray(loaded.frame?.focus?.entities)
|
|
215
|
+
&& loaded.frame.focus.entities.length > 0
|
|
216
|
+
&& Number(loaded.frame?.turnRange?.[1] ?? 0) >= 2, loaded.frame?.focus ?? null);
|
|
217
|
+
|
|
218
|
+
// 篡改 fail-safe:改帧文件 1 字节 → 注入/加载 fail closed;恢复 → 重新可注入。
|
|
219
|
+
const sealed = fs.readFileSync(framePath, 'utf8');
|
|
220
|
+
fs.writeFileSync(framePath, sealed.replace('"state": "active"', '"state": "stale"'), 'utf8');
|
|
221
|
+
const tampered = store.frameForInjection({ sessionId });
|
|
222
|
+
if (tampered.inject === false && tampered.code === 'E_INTEGRITY_TAMPER') counters.tamperRejections += 1;
|
|
223
|
+
push('tamperFailSafe', tampered.inject === false && tampered.code === 'E_INTEGRITY_TAMPER', tampered.code ?? 'inject');
|
|
224
|
+
fs.writeFileSync(framePath, sealed, 'utf8');
|
|
225
|
+
const restored = store.frameForInjection({ sessionId });
|
|
226
|
+
push('restoredInjecting', restored.inject === true, restored.code ?? 'inject');
|
|
227
|
+
|
|
228
|
+
const ok = checks.every((check) => check.ok === true);
|
|
229
|
+
return {
|
|
230
|
+
schema: FRAME_ACTIVATION_SCHEMA,
|
|
231
|
+
ok,
|
|
232
|
+
enabled: true,
|
|
233
|
+
killSwitch: false,
|
|
234
|
+
checks,
|
|
235
|
+
counters,
|
|
236
|
+
injectedText,
|
|
237
|
+
frame: loaded.frame ?? null,
|
|
238
|
+
files: { frame: framePath, sidecar: sidecarPath, workingDir: path.dirname(framePath) },
|
|
239
|
+
hooks: ['agent/pre-step'],
|
|
240
|
+
registered: Array.isArray(registered?.enabled) ? registered.enabled : [],
|
|
241
|
+
memoryRoot,
|
|
242
|
+
warnings,
|
|
243
|
+
};
|
|
244
|
+
} finally {
|
|
245
|
+
if (!keep) {
|
|
246
|
+
try { fs.rmSync(memoryRoot, { recursive: true, force: true }); } catch { /* temp */ }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|