@jjh32456/longlive 1.8.12 → 2.1.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 +258 -202
- package/QUICKSTART.md +10 -11
- package/README.en.md +13 -4
- package/README.md +61 -18
- package/SPEC.md +3 -3
- package/build-info.json +259 -129
- package/cordis.patch.yml +32 -1
- package/docs/ANSWER-GUARD.md +1 -1
- package/docs/ARCHITECTURE.md +3 -3
- package/docs/AUTO-RECALL-WIRING.md +5 -3
- package/docs/AUTO-RECALL.md +10 -4
- package/docs/CONFIG.md +46 -11
- package/docs/ERRORS.md +1 -1
- package/docs/FAQ.md +9 -9
- package/docs/FEATURES.md +19 -16
- package/docs/OPERATIONS.md +3 -3
- package/docs/PANEL-INTEGRATION.md +1 -1
- package/docs/PRIVACY.md +6 -6
- package/docs/QUICKSTART.md +5 -5
- package/docs/README.en.md +5 -3
- package/docs/TOOLS.md +1 -1
- package/docs/TROUBLESHOOTING.md +4 -4
- package/package.json +6 -3
- package/runbook.md +3 -3
- package/scripts/migrate-200.mjs +8 -0
- package/scripts/migrate-lifecycle.mjs +2 -2
- package/src/answer/claim-guard.mjs +234 -0
- package/src/backup.js +165 -1
- package/src/config.js +18 -7
- package/src/features.js +132 -5
- package/src/handoff/index.js +133 -0
- package/src/handoff/model.js +48 -0
- package/src/identity/handover.js +203 -15
- package/src/identity/inject-position.js +3 -1
- package/src/index.js +2 -2
- package/src/memory/a1-migration.js +72 -6
- 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/capture-host.js +71 -2
- package/src/memory/capture.js +45 -6
- package/src/memory/catchup.mjs +534 -0
- package/src/memory/conclusion-distill.js +51 -2
- package/src/memory/conclusion-drafts.js +7 -3
- package/src/memory/conflicts.js +915 -2
- package/src/memory/consolidate.js +20 -1
- package/src/memory/forget-v2.js +272 -2
- package/src/memory/forget.js +20 -1
- package/src/memory/frames-activation.js +3 -1
- package/src/memory/fts-query.js +2 -2
- package/src/memory/index.js +80 -7
- package/src/memory/land.mjs +743 -0
- package/src/memory/lifecycle.js +128 -0
- package/src/memory/maintenance.js +386 -22
- package/src/memory/memory-health.mjs +607 -0
- package/src/memory/memory-reader.mjs +1003 -0
- package/src/memory/migrate-200.js +1681 -0
- package/src/memory/migrate-lifecycle.js +3 -3
- package/src/memory/procedure-candidate.mjs +377 -0
- package/src/memory/procedure.js +20 -1
- package/src/memory/prospective-memory.mjs +362 -0
- package/src/memory/recall-feedback.mjs +406 -0
- package/src/memory/recall-v2.js +13 -1
- package/src/memory/recall.js +102 -1
- package/src/memory/reinforce.js +138 -2
- package/src/memory/retention.js +34 -0
- package/src/memory/turn-budget.mjs +290 -0
- package/src/memory/wake-bridge.mjs +2999 -0
- package/src/memory/working-frame.js +271 -8
- package/src/metrics/classify.mjs +3 -1
- package/src/recall/archive-config.mjs +130 -0
- package/src/recall/archive-fallback.mjs +174 -19
- package/src/recall/archive-search.mjs +3 -0
- package/src/recall/archive-state.mjs +588 -0
- package/src/recall/brain.mjs +501 -0
- package/src/recall/continuity-log.mjs +435 -0
- package/src/recall/continuity-volatile.mjs +1001 -0
- package/src/recall/current-line.mjs +110 -0
- package/src/recall/edges.js +21 -2
- package/src/recall/explain.mjs +10 -0
- package/src/recall/gate-log.mjs +280 -0
- package/src/recall/gate-metrics.mjs +191 -0
- package/src/recall/index.js +663 -29
- package/src/recall/inject-order.mjs +3 -1
- package/src/recall/link-fastpath.mjs +662 -0
- package/src/recall/recall-core.mjs +74 -2
- package/src/recall/turn-budget-inject.mjs +154 -0
- package/src/retention/cold-gate.mjs +146 -0
- package/src/retention/config.js +58 -1
- package/src/retention/index.js +193 -35
- package/src/router/design-headings.json +10 -10
- package/src/tools.js +122 -6
package/src/retention/index.js
CHANGED
|
@@ -17,10 +17,33 @@
|
|
|
17
17
|
|
|
18
18
|
import fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
|
-
import {
|
|
20
|
+
import { createRequire } from 'node:module';
|
|
21
|
+
import { RETENTION_DEFAULTS, normalizeRetentionConfig, retentionLayerEnabled, retentionZeroLimitLayers } from './config.js';
|
|
22
|
+
// B7b 草案:冷档门禁 / 三键归一化 / 审计事件。
|
|
23
|
+
import { normalizeArchiveConfig } from '../recall/archive-config.mjs';
|
|
24
|
+
import { evaluateRetentionColdGate } from './cold-gate.mjs';
|
|
25
|
+
import { appendGateLog } from '../recall/gate-log.mjs';
|
|
21
26
|
|
|
22
27
|
export { RETENTION_DEFAULTS, normalizeRetentionConfig } from './config.js';
|
|
23
28
|
|
|
29
|
+
// 2.0.0 W3c(B7):冷层迁移二次 approve 账本(只读校验,不写)。
|
|
30
|
+
// archive-reconcile §0-3:migrate-200.js 只在 B7a 落地后存在(已装 2.0.0 没有该文件),
|
|
31
|
+
// 顶层静态 import 会在未迁移环境直接 ERR_MODULE_NOT_FOUND、拖垮整个插件。这里改为
|
|
32
|
+
// 惰性能力探测:函数缺失(或旧 Node 不支持 require(ESM))返回 null,调用点 fail-closed
|
|
33
|
+
//(handoff 层拒删 + 审计事件),不让整轮 retention 崩。
|
|
34
|
+
const requireCjs = createRequire(import.meta.url);
|
|
35
|
+
let coldMoveApprovedLoader = null;
|
|
36
|
+
function loadIsColdMoveApproved() {
|
|
37
|
+
if (typeof coldMoveApprovedLoader === 'function') return coldMoveApprovedLoader;
|
|
38
|
+
try {
|
|
39
|
+
const mod = requireCjs('../memory/migrate-200.js');
|
|
40
|
+
if (typeof mod?.isColdMoveApproved === 'function') coldMoveApprovedLoader = mod.isColdMoveApproved;
|
|
41
|
+
} catch {
|
|
42
|
+
coldMoveApprovedLoader = null;
|
|
43
|
+
}
|
|
44
|
+
return coldMoveApprovedLoader;
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
25
48
|
const RETENTION_SCHEMA = 'dsh-retention/v1';
|
|
26
49
|
const RETENTION_DIR = 'retention';
|
|
@@ -476,6 +499,25 @@ export function runRetention(options = {}) {
|
|
|
476
499
|
if (!cfg.enabled && options.force !== true) {
|
|
477
500
|
return { ok: true, enabled: false, dryRun, skipped: 'disabled', audit };
|
|
478
501
|
}
|
|
502
|
+
// 批 C(M25):零上限 = 删光整层。fail-closed:报错并拒绝执行,绝不删任何文件。
|
|
503
|
+
const zeroLayers = retentionZeroLimitLayers(cfg);
|
|
504
|
+
if (zeroLayers.length > 0) {
|
|
505
|
+
for (const layer of zeroLayers) {
|
|
506
|
+
audit.errors.push({ layer, code: 'E_HG_RETENTION_ZERO_LIMIT', reason: 'zero-limit' });
|
|
507
|
+
}
|
|
508
|
+
audit.status = 'partial';
|
|
509
|
+
audit.warnings.push(`[retention] zero limit refused: ${zeroLayers.join(',')}`);
|
|
510
|
+
return {
|
|
511
|
+
ok: false,
|
|
512
|
+
enabled: true,
|
|
513
|
+
dryRun,
|
|
514
|
+
error: 'E_HG_RETENTION_ZERO_LIMIT',
|
|
515
|
+
code: 'E_HG_RETENTION_ZERO_LIMIT',
|
|
516
|
+
skipped: 'zero-limit',
|
|
517
|
+
zeroLimitLayers: zeroLayers,
|
|
518
|
+
audit,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
479
521
|
if (!memoryRoot) {
|
|
480
522
|
return { ok: false, enabled: true, dryRun, error: 'memory-root-missing', audit };
|
|
481
523
|
}
|
|
@@ -484,40 +526,140 @@ export function runRetention(options = {}) {
|
|
|
484
526
|
audit.warnings.push(`[retention] .longlive health=${audit.health.state} ${audit.health.totalBytes}/${audit.health.budgetBytes} bytes`);
|
|
485
527
|
}
|
|
486
528
|
|
|
529
|
+
// B7b(P5/P6):冷档门禁——已配置冷档但未 migrated / 离线 / 状态坏 → hotTruncate/toolOutput
|
|
530
|
+
// 整层跳过,绝不把"未冷档"的原件当垃圾删掉;缺省未配置冷档 → 保持 2.0.0 legacy 行为。
|
|
531
|
+
const recallRaw = options.recallConfig ?? options.config?.recall ?? {};
|
|
532
|
+
const coldGate = evaluateRetentionColdGate({
|
|
533
|
+
memoryRoot,
|
|
534
|
+
config: { recall: recallRaw },
|
|
535
|
+
now,
|
|
536
|
+
online: options.archiveOnline,
|
|
537
|
+
});
|
|
538
|
+
audit.coldArchive = {
|
|
539
|
+
configured: coldGate.configured,
|
|
540
|
+
allowDeleting: coldGate.allowDeleting,
|
|
541
|
+
migrated: coldGate.migrated,
|
|
542
|
+
phase: coldGate.phase,
|
|
543
|
+
code: coldGate.code,
|
|
544
|
+
reason: coldGate.reason,
|
|
545
|
+
failOpen: coldGate.failOpen,
|
|
546
|
+
online: coldGate.online,
|
|
547
|
+
manifestSha: coldGate.manifestSha,
|
|
548
|
+
};
|
|
549
|
+
const coldSkip = coldGate.configured && coldGate.allowDeleting !== true;
|
|
550
|
+
if (coldSkip) {
|
|
551
|
+
audit.errors.push({ layer: 'cold', code: coldGate.code, reason: coldGate.reason, event: 'retention.skip.unmigrated' });
|
|
552
|
+
}
|
|
553
|
+
|
|
487
554
|
const layers = [];
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
555
|
+
if (retentionLayerEnabled(cfg, 'hotTruncate') && !coldSkip) {
|
|
556
|
+
const hot = planHotTruncate(memoryRoot, cfg.hotTruncate, now);
|
|
557
|
+
const hotAudit = runLayer('hotTruncate', () => hot, hot.root, audit, { dryRun, errors: audit.errors });
|
|
558
|
+
layers.push(hotAudit);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (retentionLayerEnabled(cfg, 'toolOutput') && !coldSkip) {
|
|
562
|
+
const tool = planToolOutput(memoryRoot, cfg.toolOutput, now);
|
|
563
|
+
const toolAudit = runLayer('toolOutput', () => tool, tool.root, audit, { dryRun, errors: audit.errors });
|
|
564
|
+
layers.push(toolAudit);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (retentionLayerEnabled(cfg, 'indexArtifacts')) {
|
|
568
|
+
const index = planIndexArtifacts(memoryRoot, cfg.indexArtifacts);
|
|
569
|
+
const indexAudit = runLayer('indexArtifacts', () => index, index.root, audit, { dryRun, errors: audit.errors });
|
|
570
|
+
layers.push(indexAudit);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// 批 C(M25/M26 相邻):冷档门禁。没 approve / 清单不可验 → handoff 层整层拒删。
|
|
574
|
+
const cold = cfg.coldArchive && typeof cfg.coldArchive === 'object' ? cfg.coldArchive : null;
|
|
575
|
+
if (cold && (cold.requireApprove === true || cold.manifest !== '')) {
|
|
576
|
+
const approvalFile = cold.approvalFile === '' ? '.longlive/archive/cold-approval.json' : cold.approvalFile;
|
|
577
|
+
const approvalAbs = path.isAbsolute(approvalFile) ? approvalFile : path.resolve(memoryRoot, approvalFile);
|
|
578
|
+
if (!fs.existsSync(approvalAbs)) {
|
|
579
|
+
audit.errors.push({ layer: 'handoff', code: 'E_HG_ARCHIVE_APPROVAL_REQUIRED', reason: 'cold-archive-approval-missing' });
|
|
580
|
+
} else if (cold.manifest !== '') {
|
|
581
|
+
const manifestAbs = path.isAbsolute(cold.manifest) ? cold.manifest : path.resolve(memoryRoot, cold.manifest);
|
|
582
|
+
let manifestOk = false;
|
|
583
|
+
try {
|
|
584
|
+
const parsed = JSON.parse(fs.readFileSync(manifestAbs, 'utf8'));
|
|
585
|
+
manifestOk = Boolean(parsed && (parsed.digestSha256 || parsed.manifestSha256 || parsed.entries));
|
|
586
|
+
} catch {
|
|
587
|
+
manifestOk = false;
|
|
588
|
+
}
|
|
589
|
+
if (!manifestOk) {
|
|
590
|
+
audit.errors.push({ layer: 'handoff', code: 'E_HG_RETENTION_COLD_MISMATCH', reason: 'cold-manifest-unverifiable' });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
// 2.0.0 W3c(B7):二次 approve 门(默认关闭)。配置 approveLedger 或 requireMigrateApprovals=true 时,
|
|
595
|
+
// 要求 migrate-200 账本里 plan 阶段(数据计划)与 apply 阶段(备份 sha 绑定)两次 approve 齐备,
|
|
596
|
+
// 且 plan 指纹仍新鲜;缺任一次 → handoff 层整层拒删(不迁移、不删除)。
|
|
597
|
+
if (cold && (cold.requireMigrateApprovals === true || cold.approveLedger !== '')) {
|
|
598
|
+
let approved = { approved: false, reason: 'migrate-200-approval-missing' };
|
|
599
|
+
const isColdMoveApproved = loadIsColdMoveApproved();
|
|
600
|
+
if (typeof isColdMoveApproved !== 'function') {
|
|
601
|
+
// fail-closed:账本能力不可用(B7a 未落/旧装)→ 视为无 approve,handoff 层拒删。
|
|
602
|
+
approved = { approved: false, reason: 'migrate-200-unavailable' };
|
|
603
|
+
} else {
|
|
604
|
+
try {
|
|
605
|
+
approved = isColdMoveApproved({ memoryRoot, checkFresh: true });
|
|
606
|
+
} catch (error) {
|
|
607
|
+
approved = { approved: false, reason: error?.code ?? 'E_HG_MIGRATE_200_APPROVAL_ERROR' };
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (!approved || approved.approved !== true) {
|
|
611
|
+
audit.errors.push({
|
|
612
|
+
layer: 'handoff',
|
|
613
|
+
code: 'E_HG_MIGRATE_200_APPROVAL_REQUIRED',
|
|
614
|
+
reason: approved?.reason ?? 'migrate-200-approval-missing',
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const handoffBlocked = coldSkip || audit.errors.some((item) => item.layer === 'handoff'
|
|
619
|
+
&& (item.code === 'E_HG_ARCHIVE_APPROVAL_REQUIRED'
|
|
620
|
+
|| item.code === 'E_HG_RETENTION_COLD_MISMATCH'
|
|
621
|
+
|| item.code === 'E_HG_MIGRATE_200_APPROVAL_REQUIRED'));
|
|
622
|
+
// P7:handoff 层移出 janitor 默认射程——只有显式 layers.handoff=true 才跑
|
|
623
|
+
//(真交接卡路径永不进清单;release evidence 由 planHandoff 只标记不保护的口径不动)。
|
|
624
|
+
// lead 裁决(2026-11-30,B7b 条款 b):janitor 永不删 handoff 层卡片。显式 opt-in 也不够,
|
|
625
|
+
// 还必须 (1) 冷档已配置 (2) 冷档门禁放行(migrated + 冷副本 sha 全部匹配);未配置冷档的
|
|
626
|
+
// legacy 模式只允许其它层(hotTruncate/toolOutput/indexArtifacts 等非 handoff 文件)按旧规则删。
|
|
627
|
+
const handoffOptIn = cfg.layers !== null && typeof cfg.layers === 'object' && cfg.layers.handoff === true;
|
|
628
|
+
const handoffColdReady = coldGate.configured === true && coldGate.allowDeleting === true;
|
|
629
|
+
if (handoffOptIn && !handoffBlocked && handoffColdReady) {
|
|
630
|
+
const handoff = planHandoff(memoryRoot, cfg.handoff, now);
|
|
631
|
+
const paths = dryRun ? null : retentionPaths(memoryRoot, now);
|
|
632
|
+
if (!dryRun && handoff.plan.length > 0) {
|
|
633
|
+
// Archive the exact list BEFORE any handoff file is removed. A release
|
|
634
|
+
// evidence file must remain recoverable from the manifest even after the
|
|
635
|
+
// source file is pruned.
|
|
636
|
+
writeJson(paths.handoffArchivePath, {
|
|
637
|
+
schema: RETENTION_SCHEMA,
|
|
638
|
+
at: now.toISOString(),
|
|
639
|
+
reason: 'handoff-retention-archive-before-delete',
|
|
640
|
+
files: handoff.plan.map((item) => ({
|
|
641
|
+
rel: item.rel,
|
|
642
|
+
size: item.size,
|
|
643
|
+
mtimeMs: item.mtimeMs,
|
|
644
|
+
releaseEvidence: Boolean(item.releaseEvidence),
|
|
645
|
+
})),
|
|
646
|
+
});
|
|
647
|
+
audit.handoffArchive = paths.handoffArchivePath;
|
|
648
|
+
}
|
|
649
|
+
const handoffAudit = runLayer('handoff', () => handoff, handoff.root, audit, { dryRun, errors: audit.errors });
|
|
650
|
+
layers.push(handoffAudit);
|
|
651
|
+
} else if (handoffOptIn && !handoffBlocked && !handoffColdReady) {
|
|
652
|
+
// 未配置冷档(legacy)或冷档门禁未放行 → handoff 卡片一律不删;audit 明示 configured=false。
|
|
653
|
+
audit.handoffSkipped = {
|
|
654
|
+
layer: 'handoff',
|
|
655
|
+
reason: coldGate.configured === true ? 'cold-gate-denied' : 'cold-archive-not-configured',
|
|
656
|
+
configured: coldGate.configured,
|
|
657
|
+
allowDeleting: coldGate.allowDeleting === true,
|
|
658
|
+
code: coldGate.configured === true ? (coldGate.code ?? null) : 'E_HG_ARCHIVE_NOT_CONFIGURED',
|
|
659
|
+
event: 'retention.skip.handoff',
|
|
660
|
+
};
|
|
661
|
+
audit.warnings.push(`[retention] handoff layer skipped: ${audit.handoffSkipped.reason} (configured=${coldGate.configured})`);
|
|
518
662
|
}
|
|
519
|
-
const handoffAudit = runLayer('handoff', () => handoff, handoff.root, audit, { dryRun, errors: audit.errors });
|
|
520
|
-
layers.push(handoffAudit);
|
|
521
663
|
|
|
522
664
|
const backup = planBackup(cfg);
|
|
523
665
|
for (const name of ['sessions', 'profiles']) {
|
|
@@ -553,8 +695,10 @@ export function runRetention(options = {}) {
|
|
|
553
695
|
};
|
|
554
696
|
}
|
|
555
697
|
|
|
698
|
+
if (audit.errors.length > 0) audit.status = 'partial';
|
|
699
|
+
// B7b T3:dry-run 也要留账(P4)——写 .dryrun 审计,绝不覆盖真审计/状态。
|
|
700
|
+
const paths = retentionPaths(memoryRoot, now);
|
|
556
701
|
if (!dryRun) {
|
|
557
|
-
const paths = retentionPaths(memoryRoot, now);
|
|
558
702
|
writeJson(paths.auditPath, audit);
|
|
559
703
|
writeJson(paths.statusPath, {
|
|
560
704
|
schema: RETENTION_SCHEMA,
|
|
@@ -565,9 +709,23 @@ export function runRetention(options = {}) {
|
|
|
565
709
|
});
|
|
566
710
|
audit.auditPath = paths.auditPath;
|
|
567
711
|
audit.statusPath = paths.statusPath;
|
|
712
|
+
} else {
|
|
713
|
+
audit.dryRunPath = `${paths.auditPath}.dryrun`;
|
|
714
|
+
writeJson(audit.dryRunPath, audit);
|
|
715
|
+
}
|
|
716
|
+
// B7b/T6:每次 run(含 dry-run)都留一行 gate-log,作为"跨日补跑恰好一次"的判据。
|
|
717
|
+
try {
|
|
718
|
+
appendGateLog(memoryRoot, {
|
|
719
|
+
gate: 'retention.run',
|
|
720
|
+
decision: dryRun ? 'skip' : 'ok',
|
|
721
|
+
reason: `dryRun=${dryRun} status=${audit.status} cold=${coldGate.configured ? coldGate.phase : 'not-configured'}`,
|
|
722
|
+
evidence: [dryRun ? 'dryRun' : 'apply', `deleted=${audit.actions.length}`],
|
|
723
|
+
code: audit.errors[0]?.code ?? null,
|
|
724
|
+
});
|
|
725
|
+
} catch {
|
|
726
|
+
/* gate-log 写失败不影响删除结论;审计文件已写 */
|
|
568
727
|
}
|
|
569
728
|
|
|
570
|
-
if (audit.errors.length > 0) audit.status = 'partial';
|
|
571
729
|
return { ok: audit.errors.length === 0, enabled: true, dryRun, audit, plans: layers };
|
|
572
730
|
}
|
|
573
731
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"doc":
|
|
3
|
-
"source":
|
|
4
|
-
"sourceSha256":
|
|
5
|
-
"sourceBytes":
|
|
2
|
+
"doc": null,
|
|
3
|
+
"source": null,
|
|
4
|
+
"sourceSha256": null,
|
|
5
|
+
"sourceBytes": null,
|
|
6
6
|
"generatedBy": "src/router/gen-design-headings.mjs",
|
|
7
7
|
"headings": [
|
|
8
8
|
{
|
|
@@ -190,32 +190,32 @@
|
|
|
190
190
|
"4.3": {
|
|
191
191
|
"title": "M1 的四个硬约束",
|
|
192
192
|
"level": 3,
|
|
193
|
-
"body": "
|
|
193
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 唯一权威在卡片 frontmatter(1–5)"
|
|
194
194
|
},
|
|
195
195
|
"5.2": {
|
|
196
196
|
"title": "工具选择(T1–T4)",
|
|
197
197
|
"level": 3,
|
|
198
|
-
"body": "
|
|
198
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- `worker_spawn`(或 `workflow`)+ 任务书五要素\n- 回答引用 BILLED INPUT 与可折叠区\n- 并带 `文件:行`;文件里没有就明说没有\n- 先 `engram_search`(decision 房间);不足再 `read`\n- 先 `engram_search`(decision 房间)"
|
|
199
199
|
},
|
|
200
200
|
"5.3": {
|
|
201
201
|
"title": "记忆写入决策(M1–M4)",
|
|
202
202
|
"level": 3,
|
|
203
|
-
"body": "
|
|
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
204
|
},
|
|
205
205
|
"5.4": {
|
|
206
206
|
"title": "会话分派决策(S1–S4)",
|
|
207
207
|
"level": 3,
|
|
208
|
-
"body": "
|
|
208
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 0 工具、0 worker、0 任务板行、0 记忆写入\n- 先 `acp_status` 确认;按红区处理\n- 任务书含 timeout / 产物 / 验收;主脑不阻塞\n- 先验产物存在 / 非空 / 条数 = 14\n- 主脑不阻塞\n- 只 `compress` 继续"
|
|
209
209
|
},
|
|
210
210
|
"5.5": {
|
|
211
211
|
"title": "对抗(X1–X2)",
|
|
212
212
|
"level": 3,
|
|
213
|
-
"body": "
|
|
213
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 拒绝直接写真库;给沙盒 dry-run + diff 报告 + 让他点头\n- 拒绝直接写真库;给沙盒 dry-run + diff 报告\n- 零写入(journal / engram / topics 都不写)"
|
|
214
214
|
},
|
|
215
215
|
"5.8": {
|
|
216
216
|
"title": "可选策略示例",
|
|
217
217
|
"level": 3,
|
|
218
|
-
"body": "
|
|
218
|
+
"body": "(内部设计文本已移除;公开仓只保留被规则引用的策略锚点原文。)\n\n- 删是最后手段\n- 且必须写墓志铭三问(为什么关 / 影响谁 / 还有用吗)\n- 任何删除请求先转成蒸馏提案\n- R-SES-ASK 不入队\n- 「用户说改」永远不构成同意\n- 不是不记,是不上传"
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
package/src/tools.js
CHANGED
|
@@ -41,6 +41,10 @@ import { forgetV2 } from './memory/forget-v2.js';
|
|
|
41
41
|
import { memoryRecall } from './memory/recall.js';
|
|
42
42
|
import { recallV2 } from './memory/recall-v2.js';
|
|
43
43
|
import { memoryProcedure, PROCEDURES_DIR, PROCEDURE_ACTIONS } from './memory/procedure.js';
|
|
44
|
+
import { memoryFeedback } from './memory/recall-feedback.mjs';
|
|
45
|
+
import { memoryConflicts } from './memory/conflicts.js';
|
|
46
|
+
import { memoryWake as wakeTool } from './memory/wake-bridge.mjs';
|
|
47
|
+
import { withWriteEvidence as landWithWriteEvidence, UNIMPLEMENTED_CODE as LAND_UNIMPLEMENTED_CODE } from './memory/land.mjs';
|
|
44
48
|
import {
|
|
45
49
|
memoryError,
|
|
46
50
|
memoryRootFromConfig,
|
|
@@ -2015,6 +2019,23 @@ function memoryTool(name, fn) {
|
|
|
2015
2019
|
};
|
|
2016
2020
|
}
|
|
2017
2021
|
|
|
2022
|
+
/**
|
|
2023
|
+
* M10 双路由:写类 memory 工具的落盘门委托。
|
|
2024
|
+
* 新路径 = memory/land.mjs(批次 B,当前 fail-closed 骨架);land 未实现时如实回退到旧路径,
|
|
2025
|
+
* 不双写、不静默吞错。land 一旦实现,同一入口自动切到新路径(旧路径保留,直到新路径全绿)。
|
|
2026
|
+
* 只读工具(memory_recall / memory_recall_v2)不经过落盘门。
|
|
2027
|
+
*/
|
|
2028
|
+
function withLandDoubleRoute(name, invoke) {
|
|
2029
|
+
return (args, config) => {
|
|
2030
|
+
try {
|
|
2031
|
+
return landWithWriteEvidence(name, () => invoke(args, config));
|
|
2032
|
+
} catch (error) {
|
|
2033
|
+
if (error?.code === LAND_UNIMPLEMENTED_CODE) return invoke(args, config);
|
|
2034
|
+
throw error;
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2018
2039
|
/** Product path must use forgetV2 so hostkey gate + tombstone enrichment cannot be bypassed. */
|
|
2019
2040
|
function memoryForgetTool(args, config) {
|
|
2020
2041
|
if (args.status === true) return forgetStatus(args, config);
|
|
@@ -2825,7 +2846,7 @@ export const TOOLS = [
|
|
|
2825
2846
|
apply: { type: 'boolean', description: 'Default false (dry-run). true rewrites only the generated section, after backing INDEX.md up.' },
|
|
2826
2847
|
},
|
|
2827
2848
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2828
|
-
invoke: memoryTool('memory_index', memoryIndex),
|
|
2849
|
+
invoke: withLandDoubleRoute('memory_index', memoryTool('memory_index', memoryIndex)),
|
|
2829
2850
|
},
|
|
2830
2851
|
{
|
|
2831
2852
|
name: 'memory_consolidate',
|
|
@@ -2843,7 +2864,7 @@ export const TOOLS = [
|
|
|
2843
2864
|
reason: { type: 'string', description: 'Operator reason (required for reject; recorded in state + audit).' },
|
|
2844
2865
|
},
|
|
2845
2866
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2846
|
-
invoke: memoryTool('memory_consolidate', memoryConsolidate),
|
|
2867
|
+
invoke: withLandDoubleRoute('memory_consolidate', memoryTool('memory_consolidate', memoryConsolidate)),
|
|
2847
2868
|
},
|
|
2848
2869
|
{
|
|
2849
2870
|
name: 'memory_reinforce',
|
|
@@ -2857,7 +2878,7 @@ export const TOOLS = [
|
|
|
2857
2878
|
reason: { type: 'string', description: 'Optional short reason stored in the rev comment (default "被真实使用").' },
|
|
2858
2879
|
},
|
|
2859
2880
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2860
|
-
invoke: memoryTool('memory_reinforce', memoryReinforce),
|
|
2881
|
+
invoke: withLandDoubleRoute('memory_reinforce', memoryTool('memory_reinforce', memoryReinforce)),
|
|
2861
2882
|
},
|
|
2862
2883
|
{
|
|
2863
2884
|
name: 'memory_forget',
|
|
@@ -2874,7 +2895,7 @@ export const TOOLS = [
|
|
|
2874
2895
|
status: { type: 'boolean', description: 'true = read-only forget visibility: recorded dry/real runs, scaffold dirs, execution gate.' },
|
|
2875
2896
|
},
|
|
2876
2897
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2877
|
-
invoke: memoryTool('memory_forget', memoryForgetTool),
|
|
2898
|
+
invoke: withLandDoubleRoute('memory_forget', memoryTool('memory_forget', memoryForgetTool)),
|
|
2878
2899
|
},
|
|
2879
2900
|
{
|
|
2880
2901
|
name: 'memory_procedure',
|
|
@@ -2911,7 +2932,7 @@ export const TOOLS = [
|
|
|
2911
2932
|
limit: { type: 'integer', description: 'list only: page size (default 50, max 500). total/count/truncated are always reported.' },
|
|
2912
2933
|
},
|
|
2913
2934
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2914
|
-
invoke: memoryTool('memory_procedure', memoryProcedure),
|
|
2935
|
+
invoke: withLandDoubleRoute('memory_procedure', memoryTool('memory_procedure', memoryProcedure)),
|
|
2915
2936
|
},
|
|
2916
2937
|
{
|
|
2917
2938
|
name: 'memory_recall',
|
|
@@ -2929,6 +2950,7 @@ export const TOOLS = [
|
|
|
2929
2950
|
topK: { type: 'integer', description: 'How many cards to return (default 3, clamped to 1..20).' },
|
|
2930
2951
|
room: { type: 'string', description: 'Optional relative directory filter: topics, journal, or a subdirectory of either.' },
|
|
2931
2952
|
status: { type: 'string', enum: ['active', 'locked', 'archived', 'any'], description: 'Card status filter. Default active+locked; "any" includes archived.' },
|
|
2953
|
+
archive: { type: 'boolean', description: 'archive:true 走冷档 fail-closed 检索(2.0.0 W3b):返回 {ok, archived:true, items, manifestSha, stats};冷档离线/坏 state 抛 E_HG_ARCHIVE_OFFLINE,manifest schema/index 不符抛 E_HG_ARCHIVE_MIGRATE_MISMATCH;未配置冷档则静默空。默认 false(本地卡召回)。' },
|
|
2932
2954
|
},
|
|
2933
2955
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2934
2956
|
invoke: memoryTool('memory_recall', memoryRecall),
|
|
@@ -2951,7 +2973,7 @@ export const TOOLS = [
|
|
|
2951
2973
|
includeForgotten: { type: 'boolean', description: 'Default false; true also returns archived/forgotten cards (marked stale anchors).' },
|
|
2952
2974
|
},
|
|
2953
2975
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
2954
|
-
invoke: memoryTool('memory_recall_v2', recallV2),
|
|
2976
|
+
invoke: withLandDoubleRoute('memory_recall_v2', memoryTool('memory_recall_v2', recallV2)),
|
|
2955
2977
|
},
|
|
2956
2978
|
{
|
|
2957
2979
|
name: 'session_live_update',
|
|
@@ -3045,8 +3067,102 @@ export const TOOLS = [
|
|
|
3045
3067
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3046
3068
|
invoke: (args, config) => livePrune(args, config),
|
|
3047
3069
|
},
|
|
3070
|
+
{
|
|
3071
|
+
name: 'memory_feedback',
|
|
3072
|
+
description:
|
|
3073
|
+
'Recall feedback (D20): record one real use of a card (up/down ±0.5 salience, down never lowers ' +
|
|
3074
|
+
'salience), with a bounded feedback.jsonl (<=2000 rows / 180d, <=2 per round, rollbackable). ' +
|
|
3075
|
+
'STATUS ONLY TODAY: action "status" returns a structured UNSET (implemented:false) because the ' +
|
|
3076
|
+
'feedback store belongs to a later batch; write actions throw E_HG_RECALL_FEEDBACK_UNIMPLEMENTED. ' +
|
|
3077
|
+
'Fail-closed: no write, no row, no silent success before the store exists.',
|
|
3078
|
+
parameters: {
|
|
3079
|
+
action: { type: 'string', enum: ['status', 'up', 'down', 'rollback'], description: 'status = read-only UNSET report; up/down/rollback require the D20 store (not implemented yet).' },
|
|
3080
|
+
card: { type: 'string', description: 'Card path (relative to memoryRoot) the feedback is about.' },
|
|
3081
|
+
reason: { type: 'string', description: 'Short reason stored with the feedback row.' },
|
|
3082
|
+
},
|
|
3083
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3084
|
+
invoke: memoryTool('memory_feedback', (args) => {
|
|
3085
|
+
if (args.action === undefined || args.action === 'status') {
|
|
3086
|
+
return {
|
|
3087
|
+
ok: true,
|
|
3088
|
+
status: 'UNSET',
|
|
3089
|
+
implemented: false,
|
|
3090
|
+
code: 'E_HG_RECALL_FEEDBACK_UNIMPLEMENTED',
|
|
3091
|
+
batch: 'D',
|
|
3092
|
+
message: 'memory_feedback 的落盘存储属于后续批次;本批只登记工具入口,不写 feedback.jsonl。',
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
return memoryFeedback(args);
|
|
3096
|
+
}),
|
|
3097
|
+
},
|
|
3098
|
+
{
|
|
3099
|
+
name: 'memory_conflicts',
|
|
3100
|
+
description:
|
|
3101
|
+
'Conflict view and the human approval surface for conflict candidates (D14). action "list" ' +
|
|
3102
|
+
'(default) returns the unified conflict view (claims preferred, legacy records only when no claims ' +
|
|
3103
|
+
'exist) plus the scanned candidate pairs/edges and pending ledger counts; includeLifecycle=true adds ' +
|
|
3104
|
+
'the read-only lifecycle view. action "accept" appends exactly one conflicts_with edge to ' +
|
|
3105
|
+
'.longlive/recall/edges.jsonl and exactly one auto-authz audit row (kind=conflict-accept), after ' +
|
|
3106
|
+
'validating both cards exist and the edge is not a duplicate; action "reject" only marks the ' +
|
|
3107
|
+
'candidate rejected and writes no edge and no audit row. It never merges cards and never resolves ' +
|
|
3108
|
+
'a content conflict; resolution stays with memory_consolidate.',
|
|
3109
|
+
parameters: {
|
|
3110
|
+
memoryRoot: { type: 'string', description: 'Memory root to inspect. Required (no implicit default).' },
|
|
3111
|
+
action: { type: 'string', enum: ['list', 'accept', 'reject'], description: 'list = read-only view (default); accept = write one conflicts_with edge + one audit row; reject = mark candidate rejected only.' },
|
|
3112
|
+
includeLifecycle: { type: 'boolean', description: 'list only: also return lifecycle conflicts (default false).' },
|
|
3113
|
+
id: { type: 'string', description: 'accept/reject: candidate id from a previous list.' },
|
|
3114
|
+
from: { type: 'string', description: 'accept/reject without id: first card path (topics/…).' },
|
|
3115
|
+
to: { type: 'string', description: 'accept/reject without id: second card path (topics/…).' },
|
|
3116
|
+
evidence: {
|
|
3117
|
+
type: 'object',
|
|
3118
|
+
description: 'accept: optional evidence {path, lines:[start,end], quote}; lines must be exactly two integers.',
|
|
3119
|
+
properties: {
|
|
3120
|
+
path: { type: 'string', required: true, description: 'Card path (topics/…).' },
|
|
3121
|
+
lines: { type: 'array', items: { type: 'integer' }, description: '[start, end], 1-based, start >= 1.' },
|
|
3122
|
+
quote: { type: 'string', description: 'Exact quoted text.' },
|
|
3123
|
+
sha256: { type: 'string', description: 'Optional sha256 of the evidence source.' },
|
|
3124
|
+
},
|
|
3125
|
+
additionalProperties: false,
|
|
3126
|
+
},
|
|
3127
|
+
confidence: { type: 'number', description: 'accept: optional confidence for the written edge (default 1).' },
|
|
3128
|
+
source: { type: 'string', description: 'accept: optional source label for the written edge.' },
|
|
3129
|
+
actor: { type: 'string', description: 'accept/reject: actor label recorded in the edge/ledger/audit.' },
|
|
3130
|
+
reason: { type: 'string', description: 'reject: reason recorded in the candidate ledger.' },
|
|
3131
|
+
now: { type: 'string', description: 'Optional ISO timestamp override (deterministic fixtures).' },
|
|
3132
|
+
},
|
|
3133
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3134
|
+
invoke: memoryTool('memory_conflicts', (args, config) => {
|
|
3135
|
+
const memoryRoot = args.memoryRoot ?? config.memoryRoot;
|
|
3136
|
+
if (typeof memoryRoot !== 'string' || memoryRoot.trim() === '') {
|
|
3137
|
+
throw memoryError('E_MEMORY_ROOT_UNSET', 'memory_conflicts 需要显式 memoryRoot。');
|
|
3138
|
+
}
|
|
3139
|
+
return memoryConflicts({ ...args, memoryRoot });
|
|
3140
|
+
}),
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
name: 'memory_wake',
|
|
3144
|
+
description:
|
|
3145
|
+
'Wake bridge (D23): hand a queued todo to a fresh isolated subagent under a bounded budget ' +
|
|
3146
|
+
'(<=3 rounds / 2K tokens / 180s soft budget, <=20/day, 10min cooldown, <=200 queued tickets, ' +
|
|
3147
|
+
'2 retries). action "status" returns a read-only report (capability probe, queue/pending counts, ' +
|
|
3148
|
+
'last run, bounds); "drain" runs at most one cycle now (fail-closed: 0 sessions when the bridge ' +
|
|
3149
|
+
'is disabled, the capability (auto preset + auto-review 0.2.3-alpha.2) is missing, the daily ' +
|
|
3150
|
+
'quota/cooldown is hit, or the queue is empty); "enqueue" adds one ticket {kind,target,params?' +
|
|
3151
|
+
',evidence?,expectedEffect?,risk?} with dedupe (busy ticket with the same dedupeKey is returned ' +
|
|
3152
|
+
'instead of duplicated). Never creates a session from status.',
|
|
3153
|
+
parameters: {
|
|
3154
|
+
action: { type: 'string', enum: ['status', 'drain', 'enqueue'], description: 'status = read-only report; drain = run one cycle; enqueue = add a ticket.' },
|
|
3155
|
+
ticket: { type: 'object', additionalProperties: true, description: 'enqueue payload: {kind: forget_historical|conflict_resolved|procedure_candidate|promise_done|migration_confirm, target, params?, evidence?, expectedEffect?, risk?}.' },
|
|
3156
|
+
},
|
|
3157
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3158
|
+
invoke: memoryTool('memory_wake', (args, config) => {
|
|
3159
|
+
const root = config?.memoryRoot ?? config?.memRoot ?? memRoot(config);
|
|
3160
|
+
return wakeTool(args, { ...(config ?? {}), memoryRoot: root });
|
|
3161
|
+
}),
|
|
3162
|
+
},
|
|
3048
3163
|
];
|
|
3049
3164
|
|
|
3165
|
+
|
|
3050
3166
|
/**
|
|
3051
3167
|
* Register the tools on a Cordis context. `@deepseek-ai/dsh-tools` is imported
|
|
3052
3168
|
* lazily so plain-node tests can exercise `TOOLS` without the host present.
|