@jjh32456/longlive 2.2.0 → 2.3.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 +79 -0
- package/QUICKSTART.md +7 -7
- package/README.en.md +13 -1
- package/README.md +26 -8
- package/SPEC.md +6 -5
- package/build-info.json +132 -67
- package/cordis.patch.yml +1 -0
- package/docs/ARCHITECTURE.md +6 -3
- package/docs/CONFIG.md +25 -1
- package/docs/FAQ.md +2 -2
- package/docs/FEATURES.md +104 -2
- package/docs/INDEX-FRESHNESS.md +8 -1
- package/docs/OPERATIONS.md +63 -2
- package/docs/QUICKSTART.md +2 -2
- package/docs/README.en.md +1 -1
- package/docs/TROUBLESHOOTING.md +1 -1
- package/package.json +10 -2
- package/scripts/assert-install.mjs +124 -0
- package/scripts/backlog-report.mjs +98 -0
- package/scripts/install-230.mjs +787 -0
- package/scripts/lib/eng-common.mjs +428 -0
- package/scripts/rebuild-index.mjs +148 -0
- package/scripts/restore-drill.mjs +351 -0
- package/scripts/run-autoresolve.mjs +123 -0
- package/scripts/watchdog-230.mjs +379 -0
- package/src/features.js +14 -0
- package/src/gate/action-gate.js +234 -45
- package/src/memory/backup-retention.mjs +823 -0
- package/src/memory/cards.js +73 -12
- package/src/memory/conflict-scan.mjs +356 -0
- package/src/memory/conflicts.js +202 -9
- package/src/memory/consolidate.js +100 -13
- package/src/memory/decay.js +133 -19
- package/src/memory/event-index.js +62 -4
- package/src/memory/forget-scheduler.mjs +303 -0
- package/src/memory/forget-v2.js +94 -8
- package/src/memory/index-cache.mjs +216 -0
- package/src/memory/index.js +149 -15
- package/src/memory/lock.js +53 -12
- package/src/memory/maintenance.js +172 -17
- package/src/memory/recall-feedback.mjs +159 -17
- package/src/memory/state.js +446 -38
- package/src/memory/task-state.mjs +569 -0
- package/src/recall/brain.mjs +8 -1
- package/src/recall/continuity-volatile.mjs +131 -1
- package/src/tools.js +108 -33
- package/src/ui/routes-readonly.js +63 -5
|
@@ -23,6 +23,11 @@ import path from 'node:path';
|
|
|
23
23
|
import { createHash } from 'node:crypto';
|
|
24
24
|
|
|
25
25
|
import { lastUserTextFromMessages, selectProcedures } from './brain.mjs';
|
|
26
|
+
import {
|
|
27
|
+
createTaskStateStore,
|
|
28
|
+
isTaskStateRelated,
|
|
29
|
+
TASK_STATE_INJECT_MAX_CHARS,
|
|
30
|
+
} from '../memory/task-state.mjs';
|
|
26
31
|
|
|
27
32
|
// ── 契约常量(改动即契约变更,需同步 PLAN-v0.4 §0/§2)────────────────────────
|
|
28
33
|
|
|
@@ -260,7 +265,7 @@ function pushSegment(state, raw, perSegmentMax) {
|
|
|
260
265
|
* 通用块拼装:第一行固定、人格头/位置/读卡摘要/卡正文按优先级吃预算。
|
|
261
266
|
* 预算不足时从后往前被裁;始终保证返回 text.length ≤ cap。
|
|
262
267
|
*/
|
|
263
|
-
function composeBlock({ firstLine, cap, personaHeader, positionLine, cards, procedures, replayLine, mode }) {
|
|
268
|
+
function composeBlock({ firstLine, cap, personaHeader, positionLine, taskStateLine, cards, procedures, replayLine, mode }) {
|
|
264
269
|
const limit = Math.max(1, Math.floor(Number(cap) || 1));
|
|
265
270
|
const state = { text: hardTrim(firstLine, limit), cap: limit };
|
|
266
271
|
if (replayLine) pushLine(state, replayLine);
|
|
@@ -268,6 +273,8 @@ function composeBlock({ firstLine, cap, personaHeader, positionLine, cards, proc
|
|
|
268
273
|
pushLine(state, `你是谁:${collapseLine(personaHeader)}`);
|
|
269
274
|
}
|
|
270
275
|
if (positionLine) pushLine(state, positionLine);
|
|
276
|
+
// W2.4:跨会话/压缩后的任务状态接续行,紧跟位置行(不抢首行安全声明,不挤掉读卡正文)。
|
|
277
|
+
if (taskStateLine) pushSegment(state, taskStateLine, TASK_STATE_INJECT_MAX_CHARS);
|
|
271
278
|
const titles = (Array.isArray(cards) ? cards : [])
|
|
272
279
|
.map((card) => collapseLine(card && card.title))
|
|
273
280
|
.filter(Boolean)
|
|
@@ -295,6 +302,7 @@ export function composeVolatileBlock({
|
|
|
295
302
|
cap = STEP1_MAX_CHARS,
|
|
296
303
|
personaHeader = '',
|
|
297
304
|
positionLine = '',
|
|
305
|
+
taskStateLine = null,
|
|
298
306
|
cards = [],
|
|
299
307
|
replayReason = null,
|
|
300
308
|
step = 1,
|
|
@@ -309,6 +317,7 @@ export function composeVolatileBlock({
|
|
|
309
317
|
cap: effectiveCap,
|
|
310
318
|
personaHeader,
|
|
311
319
|
positionLine: positionLine || buildPositionLine({ turn, step, sessionId, mode }),
|
|
320
|
+
taskStateLine,
|
|
312
321
|
cards,
|
|
313
322
|
procedures,
|
|
314
323
|
replayLine: replayReason ? buildReplayLine(replayReason, mode) : null,
|
|
@@ -330,6 +339,7 @@ export function composeFallbackBlock({
|
|
|
330
339
|
mode = 'degraded',
|
|
331
340
|
personaHeader = '',
|
|
332
341
|
positionLine = '',
|
|
342
|
+
taskStateLine = null,
|
|
333
343
|
cards = [],
|
|
334
344
|
replayReason = null,
|
|
335
345
|
step = 1,
|
|
@@ -342,6 +352,7 @@ export function composeFallbackBlock({
|
|
|
342
352
|
cap: effectiveCap,
|
|
343
353
|
personaHeader,
|
|
344
354
|
positionLine: positionLine || buildPositionLine({ turn, step, sessionId, mode }),
|
|
355
|
+
taskStateLine,
|
|
345
356
|
cards,
|
|
346
357
|
replayLine: replayReason ? buildReplayLine(replayReason, mode) : null,
|
|
347
358
|
mode,
|
|
@@ -707,6 +718,17 @@ export function createContinuityVolatile(options = {}) {
|
|
|
707
718
|
procedures: ctx.procedures,
|
|
708
719
|
drop: ctx.drop,
|
|
709
720
|
fail: ctx.fail,
|
|
721
|
+
// W2.4 任务状态:captured/noop/fail + 是否 rehydrate + 捕获摘要(不含用户原文,隐私边界 F8)。
|
|
722
|
+
taskState: ctx.taskState
|
|
723
|
+
? {
|
|
724
|
+
mode: ctx.taskState.mode,
|
|
725
|
+
reason: ctx.taskState.reason,
|
|
726
|
+
rehydrate: ctx.taskState.rehydrate === true,
|
|
727
|
+
injected: ctx.taskState.injected === true,
|
|
728
|
+
chars: toInt(ctx.taskState.chars, 0),
|
|
729
|
+
capture: ctx.taskState.capture,
|
|
730
|
+
}
|
|
731
|
+
: null,
|
|
710
732
|
ms: Math.max(0, Math.round(clock() - startedAt)),
|
|
711
733
|
};
|
|
712
734
|
emit(record);
|
|
@@ -742,6 +764,99 @@ export function createContinuityVolatile(options = {}) {
|
|
|
742
764
|
return result;
|
|
743
765
|
}
|
|
744
766
|
|
|
767
|
+
/**
|
|
768
|
+
* W2.4 任务状态(task-state):先读上一次落盘的机器可读任务状态(跨会话/压缩后的接续来源),
|
|
769
|
+
* 再捕获本步状态落盘(幂等)。只在新会话首步 / 进程重启后的首步 rehydrate,避免与
|
|
770
|
+
* 2.0 工作帧(同会话每轮 ≤300 字)重复注入。任何异常都不外抛,只记 fail。
|
|
771
|
+
*/
|
|
772
|
+
function taskStateForStep({ decision, sessionId, turn, step, subagent, tracking, userText }) {
|
|
773
|
+
try {
|
|
774
|
+
if (subagent) {
|
|
775
|
+
return { mode: 'off', reason: 'E_TASK_STATE_SUBAGENT_SKIP', rehydrate: false, injected: false, chars: 0, text: '', capture: null };
|
|
776
|
+
}
|
|
777
|
+
if (typeof config.memoryRoot !== 'string' || config.memoryRoot.trim() === '') {
|
|
778
|
+
return { mode: 'off', reason: 'E_NO_MEMORY_ROOT', rehydrate: false, injected: false, chars: 0, text: '', capture: null };
|
|
779
|
+
}
|
|
780
|
+
// 任务状态时间戳必须用真实时间:continuity 的 clock()(nowMillis(config.now)) 在未注入时钟时
|
|
781
|
+
// 会返回 0(Number(null) 语义),若直接透传,状态 updatedAt 会写成 1970 且「过期」永远判新鲜。
|
|
782
|
+
const taskClock = () => {
|
|
783
|
+
try {
|
|
784
|
+
const value = clock();
|
|
785
|
+
if (Number.isFinite(value) && value > 0) return value;
|
|
786
|
+
} catch {
|
|
787
|
+
/* fall through */
|
|
788
|
+
}
|
|
789
|
+
return Date.now();
|
|
790
|
+
};
|
|
791
|
+
const store = createTaskStateStore({ memoryRoot: config.memoryRoot, now: taskClock });
|
|
792
|
+
const messages = Array.isArray(decision.messages) ? decision.messages : [];
|
|
793
|
+
const previous = store.read();
|
|
794
|
+
let rehydrate = { inject: false, reason: null };
|
|
795
|
+
if (step === 1) {
|
|
796
|
+
if (!previous.ok || !previous.exists) {
|
|
797
|
+
rehydrate = { inject: false, reason: previous.code || 'E_TASK_STATE_ABSENT' };
|
|
798
|
+
} else if (!previous.fresh) {
|
|
799
|
+
rehydrate = { inject: false, reason: 'E_TASK_STATE_STALE' };
|
|
800
|
+
} else {
|
|
801
|
+
const related = isTaskStateRelated(previous.state, userText);
|
|
802
|
+
// 新会话(sessionId 变了)或本进程首次观测到该会话(宿重启 / truncate 后重开)才接续。
|
|
803
|
+
const restarted = previous.state.sessionId !== sessionId || tracking.firstObservation === true;
|
|
804
|
+
if (!related.related) rehydrate = { inject: false, reason: 'E_TASK_STATE_UNRELATED', related };
|
|
805
|
+
else if (!restarted) rehydrate = { inject: false, reason: 'E_TASK_STATE_SAME_SESSION', related };
|
|
806
|
+
else rehydrate = { inject: true, reason: related.reason, related };
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
rehydrate = { inject: false, reason: 'E_TASK_STATE_STEP_GT_1' };
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const captured = store.capture({
|
|
813
|
+
sessionId,
|
|
814
|
+
turn,
|
|
815
|
+
step,
|
|
816
|
+
messages,
|
|
817
|
+
previous: previous.ok ? previous.state : null,
|
|
818
|
+
// 同一会话继续 or 新会话仍在同一话题 → 继承触达文件;跨到新话题 → 只留本轮文件。
|
|
819
|
+
keepAnchors:
|
|
820
|
+
(previous.ok && previous.exists && previous.state.sessionId === sessionId) ||
|
|
821
|
+
(rehydrate.related ? rehydrate.related.related === true : false),
|
|
822
|
+
});
|
|
823
|
+
let text = '';
|
|
824
|
+
if (rehydrate.inject) {
|
|
825
|
+
// 用捕获后的最新状态渲染(doing/nextStep/anchor 已合并本轮信息)。
|
|
826
|
+
const rendered = store.renderLine({ allowStale: true });
|
|
827
|
+
text = rendered.ok ? rendered.text : '';
|
|
828
|
+
if (text === '') rehydrate = { ...rehydrate, inject: false, reason: rendered.code || 'E_TASK_STATE_EMPTY' };
|
|
829
|
+
}
|
|
830
|
+
const fields = captured.ok ? captured.fields : null;
|
|
831
|
+
return {
|
|
832
|
+
mode: captured.ok ? (captured.written ? 'captured' : 'noop') : 'fail',
|
|
833
|
+
reason: rehydrate.inject ? rehydrate.reason : (captured.ok ? rehydrate.reason : captured.code),
|
|
834
|
+
rehydrate: rehydrate.inject === true,
|
|
835
|
+
injected: rehydrate.inject === true && text !== '',
|
|
836
|
+
chars: text.length,
|
|
837
|
+
text,
|
|
838
|
+
capture: fields
|
|
839
|
+
? {
|
|
840
|
+
doing: fields.doing ?? '',
|
|
841
|
+
waitingFor: fields.waitingFor ?? null,
|
|
842
|
+
nextStep: fields.nextStep ?? '',
|
|
843
|
+
anchorFiles: Array.isArray(fields.anchorFiles) ? fields.anchorFiles.slice(0, 5) : [],
|
|
844
|
+
}
|
|
845
|
+
: null,
|
|
846
|
+
};
|
|
847
|
+
} catch (error) {
|
|
848
|
+
return {
|
|
849
|
+
mode: 'fail',
|
|
850
|
+
reason: errorCode(error, 'E_TASK_STATE_INTERNAL'),
|
|
851
|
+
rehydrate: false,
|
|
852
|
+
injected: false,
|
|
853
|
+
chars: 0,
|
|
854
|
+
text: '',
|
|
855
|
+
capture: null,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
745
860
|
async function fallbackPath(payload, decision, ctx, opts) {
|
|
746
861
|
const step1Only = opts.step1Only !== false;
|
|
747
862
|
const baseMode = opts.mode || 'degraded';
|
|
@@ -794,6 +909,7 @@ export function createContinuityVolatile(options = {}) {
|
|
|
794
909
|
mode: baseMode,
|
|
795
910
|
personaHeader: resolvePersona(config, payload),
|
|
796
911
|
positionLine: buildPositionLine({ turn: ctx.turn, step: ctx.step, sessionId: ctx.sessionId, mode: baseMode }),
|
|
912
|
+
taskStateLine: ctx.taskState && ctx.taskState.injected ? ctx.taskState.text : null,
|
|
797
913
|
cards,
|
|
798
914
|
replayReason: ctx.replay,
|
|
799
915
|
step: ctx.step,
|
|
@@ -885,6 +1001,7 @@ export function createContinuityVolatile(options = {}) {
|
|
|
885
1001
|
cap,
|
|
886
1002
|
personaHeader: resolvePersona(config, payload),
|
|
887
1003
|
positionLine: buildPositionLine({ turn: ctx.turn, step: ctx.step, sessionId: ctx.sessionId, mode: 'volatile' }),
|
|
1004
|
+
taskStateLine: ctx.taskState && ctx.taskState.injected ? ctx.taskState.text : null,
|
|
888
1005
|
cards,
|
|
889
1006
|
procedures,
|
|
890
1007
|
replayReason: ctx.replay,
|
|
@@ -980,6 +1097,7 @@ export function createContinuityVolatile(options = {}) {
|
|
|
980
1097
|
userText: '',
|
|
981
1098
|
drop: 0,
|
|
982
1099
|
fail: 0,
|
|
1100
|
+
taskState: null,
|
|
983
1101
|
};
|
|
984
1102
|
try {
|
|
985
1103
|
if (!decision || typeof decision !== 'object') {
|
|
@@ -1009,6 +1127,18 @@ export function createContinuityVolatile(options = {}) {
|
|
|
1009
1127
|
});
|
|
1010
1128
|
ctx.replay = replay;
|
|
1011
1129
|
|
|
1130
|
+
// W2.4:任务状态机——捕获本步「在做什么/等什么/下一步」,并在新会话首步按需 rehydrate。
|
|
1131
|
+
// 与 volatile/fallback 选择无关:即使宿主无哨兵走回落块,任务状态也照样捕获与接续。
|
|
1132
|
+
ctx.taskState = taskStateForStep({
|
|
1133
|
+
decision,
|
|
1134
|
+
sessionId,
|
|
1135
|
+
turn,
|
|
1136
|
+
step,
|
|
1137
|
+
subagent,
|
|
1138
|
+
tracking,
|
|
1139
|
+
userText: ctx.userText,
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1012
1142
|
const hostVolatile = probeHost(typeof globalThis !== 'undefined' ? globalThis : undefined);
|
|
1013
1143
|
if (hostVolatile) {
|
|
1014
1144
|
return await volatilePath(payload, decision, ctx);
|
package/src/tools.js
CHANGED
|
@@ -41,7 +41,7 @@ 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';
|
|
44
|
+
import { memoryFeedback, recordRecallUsage, applyFeedbackRanking } from './memory/recall-feedback.mjs';
|
|
45
45
|
import { memoryConflicts } from './memory/conflicts.js';
|
|
46
46
|
import { memoryWake as wakeTool } from './memory/wake-bridge.mjs';
|
|
47
47
|
import { withWriteEvidence as landWithWriteEvidence, UNIMPLEMENTED_CODE as LAND_UNIMPLEMENTED_CODE } from './memory/land.mjs';
|
|
@@ -59,7 +59,7 @@ import { liveUpdate, liveList, liveGet, livePrune } from './live.js';
|
|
|
59
59
|
import { sessionIdOfLogFile } from './live-target.js';
|
|
60
60
|
import { privacyScan } from './recall/privacy.mjs';
|
|
61
61
|
import { appendGateLog } from './recall/gate-log.mjs';
|
|
62
|
-
import { ACTION_KEYWORDS } from './gate/action-gate.js';
|
|
62
|
+
import { ACTION_KEYWORDS, actionKindsForText } from './gate/action-gate.js';
|
|
63
63
|
import { searchEventsFts, searchEventsReadOnly } from './memory/event-index.js';
|
|
64
64
|
import {
|
|
65
65
|
buildTurnItems,
|
|
@@ -2022,8 +2022,11 @@ function memoryTool(name, fn) {
|
|
|
2022
2022
|
}
|
|
2023
2023
|
|
|
2024
2024
|
/**
|
|
2025
|
-
* 2.
|
|
2026
|
-
*
|
|
2025
|
+
* 2.3.0 动作前回忆门(lane gate-feedback):
|
|
2026
|
+
* - 回执兜底(RT P1-1):动作类 query 的 memory_recall 成功返回即写 gate='action'/ok 回执,
|
|
2027
|
+
* 不再要求命中 procedures/ 卡——procedureNames 可空,evidence 记 actionKind/动作词/query 长度。
|
|
2028
|
+
* - 回执记 actionKind(逗号分隔、可多类),动作门按同 kind 匹配(RT P1-3)。
|
|
2029
|
+
* - 隐私:evidence 不写 query 原文,只写 queryChars + 命中的动作词。
|
|
2027
2030
|
* 只读召回本身不变(不写卡、不建 INDEX);回执写失败一律 fail-open,绝不影响召回结果。
|
|
2028
2031
|
*/
|
|
2029
2032
|
function withActionGateReceipt(name, invoke) {
|
|
@@ -2038,28 +2041,94 @@ function withActionGateReceipt(name, invoke) {
|
|
|
2038
2041
|
};
|
|
2039
2042
|
}
|
|
2040
2043
|
|
|
2044
|
+
function turnOfConfig(config) {
|
|
2045
|
+
if (Number.isInteger(config?.turn) && config.turn >= 0) return config.turn;
|
|
2046
|
+
const execTurn = config?.exec?.turn;
|
|
2047
|
+
return Number.isInteger(execTurn) && execTurn >= 0 ? execTurn : null;
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
/**
|
|
2051
|
+
* W2.1(D20)召回反馈接线:memory_recall 成功返回后
|
|
2052
|
+
* 1. 写 used 标记(账本 feedback.jsonl,只记卡路径/query 长度/动作类别,不记 query 原文);
|
|
2053
|
+
* 2. 把上一轮 up/down 反馈反映到本次排序(无反馈时 identity)。
|
|
2054
|
+
* best-effort:任何一步失败都不得影响召回结果。
|
|
2055
|
+
*/
|
|
2056
|
+
/**
|
|
2057
|
+
* D20 used 标记只在反馈账本已存在时追加(用户已开始用 memory_feedback 后)。
|
|
2058
|
+
* 默认的 memory_recall 仍是只读:不建 .longlive/、不写盘(M28「recall must be read-only」契约)。
|
|
2059
|
+
*/
|
|
2060
|
+
function feedbackLedgerPresent(memoryRoot) {
|
|
2061
|
+
if (typeof memoryRoot !== 'string' || memoryRoot === '') return false;
|
|
2062
|
+
try {
|
|
2063
|
+
return fs.existsSync(path.join(memoryRoot, '.longlive', 'hardgate', 'feedback.jsonl'));
|
|
2064
|
+
} catch {
|
|
2065
|
+
return false;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
function withRecallFeedback(name, invoke) {
|
|
2070
|
+
return (args, config) => {
|
|
2071
|
+
const result = invoke(args, config);
|
|
2072
|
+
try {
|
|
2073
|
+
if (!result || result.ok !== true || !Array.isArray(result.results) || result.results.length === 0) return result;
|
|
2074
|
+
const memoryRoot = memRoot(config, process.env);
|
|
2075
|
+
if (typeof memoryRoot !== 'string' || memoryRoot === '') return result;
|
|
2076
|
+
const query = typeof args?.query === 'string' ? args.query : '';
|
|
2077
|
+
const caller = resolveCallerSessionId(config);
|
|
2078
|
+
const turn = turnOfConfig(config);
|
|
2079
|
+
if (feedbackLedgerPresent(memoryRoot)) {
|
|
2080
|
+
try {
|
|
2081
|
+
recordRecallUsage({
|
|
2082
|
+
memoryRoot,
|
|
2083
|
+
cards: result.results.map((row) => (typeof row?.path === 'string' ? row.path : '')).filter(Boolean),
|
|
2084
|
+
queryChars: query.length,
|
|
2085
|
+
queryKinds: actionKindsForText(query),
|
|
2086
|
+
sessionId: caller.id ?? undefined,
|
|
2087
|
+
turn,
|
|
2088
|
+
});
|
|
2089
|
+
} catch {
|
|
2090
|
+
/* used 标记写失败只影响反馈统计,不影响召回 */
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
try {
|
|
2094
|
+
result.results = applyFeedbackRanking(memoryRoot, result.results);
|
|
2095
|
+
} catch {
|
|
2096
|
+
/* 排序微调失败时保留原排序(确定性优先于反馈) */
|
|
2097
|
+
}
|
|
2098
|
+
} catch {
|
|
2099
|
+
/* 反馈接线整体 fail-open */
|
|
2100
|
+
}
|
|
2101
|
+
return result;
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2041
2105
|
function writeActionGateReceipt(name, args, result, config) {
|
|
2042
2106
|
if (!result || result.ok !== true || !Array.isArray(result.results)) return;
|
|
2043
2107
|
const query = typeof args?.query === 'string' ? args.query : '';
|
|
2044
2108
|
if (query.trim() === '') return;
|
|
2045
|
-
const
|
|
2046
|
-
if (
|
|
2047
|
-
const procedures = result.results
|
|
2048
|
-
.filter((row) => row && typeof row.path === 'string' && row.path.startsWith('procedures/'))
|
|
2049
|
-
.map((row) => (typeof row.title === 'string' && row.title.trim() !== '' ? row.title.trim() : row.path));
|
|
2050
|
-
if (procedures.length === 0) return;
|
|
2109
|
+
const kinds = actionKindsForText(query);
|
|
2110
|
+
if (kinds.length === 0) return;
|
|
2051
2111
|
if (!isPlainObject(config)) return;
|
|
2052
2112
|
const memoryRoot = memRoot(config, process.env);
|
|
2053
2113
|
if (typeof memoryRoot !== 'string' || memoryRoot === '') return;
|
|
2054
|
-
const
|
|
2114
|
+
const caller = resolveCallerSessionId(config);
|
|
2115
|
+
const matchedKeywords = ACTION_KEYWORDS.filter((keyword) => query.toLowerCase().includes(keyword.toLowerCase()));
|
|
2116
|
+
const procedures = result.results
|
|
2117
|
+
.filter((row) => row && typeof row.path === 'string' && row.path.startsWith('procedures/'))
|
|
2118
|
+
.map((row) => (typeof row.title === 'string' && row.title.trim() !== '' ? row.title.trim() : row.path));
|
|
2055
2119
|
appendGateLog(memoryRoot, {
|
|
2056
|
-
sessionId,
|
|
2120
|
+
sessionId: caller.id,
|
|
2121
|
+
turn: turnOfConfig(config),
|
|
2057
2122
|
gate: 'action',
|
|
2058
2123
|
decision: 'ok',
|
|
2059
2124
|
reason: `recall-tool:${name}`,
|
|
2060
2125
|
evidence: [
|
|
2061
2126
|
'source=memory_recall_tool',
|
|
2062
|
-
`
|
|
2127
|
+
`actionKind=${kinds.join(',')}`,
|
|
2128
|
+
`actionWords=${matchedKeywords.join('|')}`,
|
|
2129
|
+
`queryChars=${query.length}`,
|
|
2130
|
+
`resultCount=${result.results.length}`,
|
|
2131
|
+
...(procedures.length > 0 ? [`procedureNames=${procedures.slice(0, 2).join('|')}`] : []),
|
|
2063
2132
|
],
|
|
2064
2133
|
});
|
|
2065
2134
|
}
|
|
@@ -2998,7 +3067,7 @@ export const TOOLS = [
|
|
|
2998
3067
|
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(本地卡召回)。' },
|
|
2999
3068
|
},
|
|
3000
3069
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3001
|
-
invoke: withActionGateReceipt('memory_recall', memoryTool('memory_recall', memoryRecall)),
|
|
3070
|
+
invoke: withActionGateReceipt('memory_recall', memoryTool('memory_recall', withRecallFeedback('memory_recall', memoryRecall))),
|
|
3002
3071
|
},
|
|
3003
3072
|
{
|
|
3004
3073
|
name: 'memory_recall_v2',
|
|
@@ -3115,29 +3184,35 @@ export const TOOLS = [
|
|
|
3115
3184
|
{
|
|
3116
3185
|
name: 'memory_feedback',
|
|
3117
3186
|
description:
|
|
3118
|
-
'Recall feedback (D20): record one real use of a card
|
|
3119
|
-
'
|
|
3120
|
-
'
|
|
3121
|
-
'
|
|
3122
|
-
'
|
|
3187
|
+
'Recall feedback (D20): record one real use of a card. up = salience +0.5 (clamped 0..5, never lowers); ' +
|
|
3188
|
+
'down = strength -0.5 (clamped 0..9) and never lowers salience; rollback restores one earlier entry by ' +
|
|
3189
|
+
'entryId; status reports the bounded feedback.jsonl (<=2000 rows / 180d, <=2 up/down per round). Every ' +
|
|
3190
|
+
'accepted write lands in <memoryRoot>/.longlive/hardgate/feedback.jsonl and leaves one gate="d20" audit row ' +
|
|
3191
|
+
'in the gate-log (store + audit are both verifiable; rollback never touches the card prose). ' +
|
|
3192
|
+
'Actions return {ok, action, field, before, after, entryId, perRound, total} so a later rollback can cite ' +
|
|
3193
|
+
'the exact entryId. Fail-closed: an unknown card, a missing entryId, a duplicate rollback or a missing ' +
|
|
3194
|
+
'memoryRoot throws instead of reporting a fake success.',
|
|
3123
3195
|
parameters: {
|
|
3124
|
-
action: { type: 'string', enum: ['status', 'up', 'down', 'rollback'], description: 'status = read-only
|
|
3125
|
-
card: { type: 'string', description: 'Card path (relative to memoryRoot) the feedback is about.' },
|
|
3126
|
-
|
|
3196
|
+
action: { type: 'string', enum: ['status', 'up', 'down', 'rollback'], description: 'status = read-only ledger report; up/down/rollback = write one feedback row (+ audit; rollback restores by entryId).' },
|
|
3197
|
+
card: { type: 'string', description: 'Card path (relative to memoryRoot) the feedback is about (up/down).' },
|
|
3198
|
+
path: { type: 'string', description: 'Alias of card (kept for older callers).' },
|
|
3199
|
+
entryId: { type: 'string', description: 'rollback only: entryId returned by an earlier up/down call.' },
|
|
3200
|
+
reason: { type: 'string', description: 'Short reason stored with the feedback row (not written to the audit log).' },
|
|
3127
3201
|
},
|
|
3128
3202
|
output: { schema: { type: 'object', additionalProperties: true }, render: (_a, value) => OUTPUT_TEXT(value) },
|
|
3129
|
-
invoke: memoryTool('memory_feedback', (args) => {
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
status: 'UNSET',
|
|
3134
|
-
implemented: false,
|
|
3135
|
-
code: 'E_HG_RECALL_FEEDBACK_UNIMPLEMENTED',
|
|
3136
|
-
batch: 'D',
|
|
3137
|
-
message: 'memory_feedback 的落盘存储属于后续批次;本批只登记工具入口,不写 feedback.jsonl。',
|
|
3138
|
-
};
|
|
3203
|
+
invoke: memoryTool('memory_feedback', (args, config) => {
|
|
3204
|
+
const memoryRoot = memRoot(config, process.env);
|
|
3205
|
+
if (typeof memoryRoot !== 'string' || memoryRoot === '') {
|
|
3206
|
+
throw memoryError('E_MEMORY_ROOT_UNSET', 'memory_feedback 需要 memoryRoot(config.memoryRoot / $DSH_LONGLIVE_MEMORY_ROOT)');
|
|
3139
3207
|
}
|
|
3140
|
-
|
|
3208
|
+
const caller = resolveCallerSessionId(config);
|
|
3209
|
+
return memoryFeedback({
|
|
3210
|
+
...args,
|
|
3211
|
+
card: typeof args.card === 'string' && args.card !== '' ? args.card : args.path,
|
|
3212
|
+
memoryRoot,
|
|
3213
|
+
sessionId: caller.id ?? undefined,
|
|
3214
|
+
turn: turnOfConfig(config) ?? undefined,
|
|
3215
|
+
});
|
|
3141
3216
|
}),
|
|
3142
3217
|
},
|
|
3143
3218
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// src/ui/routes-readonly.js — M2-F 面板只读数据面(
|
|
1
|
+
// src/ui/routes-readonly.js — M2-F 面板只读数据面(28 条 /api/longlive/*)
|
|
2
2
|
//
|
|
3
3
|
// 契约(MEMORY-RECALL-V2-PROPOSAL v2.6.3 §12.3 / §12.7-G2/G3/G4 / §12.11-R9):
|
|
4
|
-
//
|
|
4
|
+
// 28 条只读路由,全部过同一道能力令牌门(panel-auth),面板只走 HTTP、
|
|
5
5
|
// 不直连 SQLite、不读 `.longlive/` 之外的路径。
|
|
6
6
|
// #16 GET /api/longlive/integrity 返回 R8 manifest 校验状态;ok=false 时
|
|
7
7
|
// **只读展示保留**,动作面由 actions.js 判 401 E_PANEL_INTEGRITY。
|
|
@@ -24,6 +24,13 @@ import { readRecallLogRows, summarizeRecallRows } from '../recall/explain.mjs';
|
|
|
24
24
|
import { readChannels } from '../role/channels.js';
|
|
25
25
|
import { readAttentionView, readPersonalityView, readRelationshipsView } from '../role/readers.js';
|
|
26
26
|
import { readHandoffBoard } from '../handoff/store.js';
|
|
27
|
+
import {
|
|
28
|
+
renderTaskStateLine,
|
|
29
|
+
sanitizeAnchorFile,
|
|
30
|
+
sanitizeTaskText,
|
|
31
|
+
TASK_STATE_FRESH_MS,
|
|
32
|
+
TASK_STATE_SCHEMA,
|
|
33
|
+
} from '../memory/task-state.mjs';
|
|
27
34
|
|
|
28
35
|
import { REVIEW_SCHEMA, normalizeReviewRow } from './actions.js';
|
|
29
36
|
|
|
@@ -33,7 +40,7 @@ export const EVENTS_LIMIT_MAX = 200;
|
|
|
33
40
|
export const LOG_LIMIT_MAX = 200;
|
|
34
41
|
|
|
35
42
|
/** Producer module that will fill each file in later M2 slices (Gate-1 honesty). */
|
|
36
|
-
/** R4 P1-6:
|
|
43
|
+
/** R4 P1-6:28 条只读路由的显式 id 预留表(先冻结名字与 id,实现按表注册,不改号段)。 */
|
|
37
44
|
export const ROUTE_ID_BY_NAME = Object.freeze({
|
|
38
45
|
flags: 1,
|
|
39
46
|
board: 2,
|
|
@@ -65,6 +72,8 @@ export const ROUTE_ID_BY_NAME = Object.freeze({
|
|
|
65
72
|
personality: 26,
|
|
66
73
|
// 27 release-check:channels
|
|
67
74
|
channels: 27,
|
|
75
|
+
// 28 W5 体验:workframe(2.3.0 W2.4 task-state 只读展示)
|
|
76
|
+
workframe: 28,
|
|
68
77
|
})
|
|
69
78
|
|
|
70
79
|
export const READONLY_ROUTES = Object.freeze([
|
|
@@ -97,6 +106,8 @@ export const READONLY_ROUTES = Object.freeze([
|
|
|
97
106
|
{ id: 26, path: '/api/longlive/personality', schema: 'personality/v1', producer: 'src/role/personality.js(state-truth)', dynamic: false },
|
|
98
107
|
// #27 channels:release-check 注册(state-truth 只提供 src/role/channels.js#readChannels 读取器)。
|
|
99
108
|
{ id: 27, path: '/api/longlive/channels', schema: 'channels/v1', producer: 'src/role/channels.js#readChannels(state-truth 读取器)+ release-check 注册 #27', dynamic: false },
|
|
109
|
+
// #28 workframe:W5 体验只读展示(W2.4 写 `.longlive/workframe/current.json`;面板不新增写路径)。
|
|
110
|
+
{ id: 28, path: '/api/longlive/workframe', schema: 'workframe/v1', producer: 'src/memory/task-state.mjs#createTaskStateStore(W2.4 写、W5 只读展示,脱敏)', dynamic: false },
|
|
100
111
|
]);
|
|
101
112
|
|
|
102
113
|
/** G3 detail route lives under #12 (one logical route, exact list + `/<id>`). */
|
|
@@ -471,6 +482,52 @@ function createDefaultReaders(options) {
|
|
|
471
482
|
personality: () => readPersonalityView({ memoryRoot, now, auditKey }),
|
|
472
483
|
// #27 channels:只读状态(1.8.0 只做宿主内注册与只读,不接真实 QQ 协议,§16.7)。
|
|
473
484
|
channels: () => readChannels({ memoryRoot, now, auditKey }),
|
|
485
|
+
// #28 workframe:只读展示 `.longlive/workframe/current.json`(W2.4 写、W5 面板展示)。
|
|
486
|
+
// 隐私:面板只回显已 scrub 的短字段,再洗一遍;不暴露 store.inspect() 的 memoryRoot/file 绝对路径;
|
|
487
|
+
// anchorFiles 只回 basename;未知字段一律不回显(白名单)。不新增任何写路径。
|
|
488
|
+
workframe: () => {
|
|
489
|
+
const read = readJson(path.join(base, 'workframe', 'current.json'));
|
|
490
|
+
if (!read.ok) {
|
|
491
|
+
return {
|
|
492
|
+
schema: 'workframe/v1',
|
|
493
|
+
present: false,
|
|
494
|
+
code: read.code === 'ENOENT' ? 'E_WORKFRAME_ABSENT' : read.code,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
const raw = read.value && typeof read.value === 'object' && !Array.isArray(read.value) ? read.value : null;
|
|
498
|
+
if (raw === null || raw.schema !== TASK_STATE_SCHEMA) {
|
|
499
|
+
return { schema: 'workframe/v1', present: false, code: 'E_WORKFRAME_SCHEMA' };
|
|
500
|
+
}
|
|
501
|
+
const updatedMs = typeof raw.updatedAt === 'string' ? Date.parse(raw.updatedAt) : NaN;
|
|
502
|
+
const ageMs = Number.isFinite(updatedMs) ? Math.max(0, now().getTime() - updatedMs) : null;
|
|
503
|
+
const waiting = raw.waitingFor;
|
|
504
|
+
const waitingFor =
|
|
505
|
+
waiting && typeof waiting === 'object' && (waiting.kind === 'decision' || waiting.kind === 'question')
|
|
506
|
+
&& typeof waiting.text === 'string' && waiting.text.trim() !== ''
|
|
507
|
+
? { kind: waiting.kind, text: sanitizeTaskText(waiting.text, { maxChars: 60 }) }
|
|
508
|
+
: null;
|
|
509
|
+
const anchorFiles = Array.isArray(raw.anchorFiles)
|
|
510
|
+
? [...new Set(raw.anchorFiles.map((file) => sanitizeAnchorFile(file)).filter(Boolean))].slice(0, 5)
|
|
511
|
+
: [];
|
|
512
|
+
const view = {
|
|
513
|
+
schema: 'workframe/v1',
|
|
514
|
+
present: true,
|
|
515
|
+
// 24h 之外标 stale(与 W2.4 注入的新鲜度窗口同口径),仍只读展示,不让旧任务“假装新鲜”。
|
|
516
|
+
fresh: ageMs !== null && ageMs <= TASK_STATE_FRESH_MS,
|
|
517
|
+
stale: !(ageMs !== null && ageMs <= TASK_STATE_FRESH_MS),
|
|
518
|
+
updatedAt: Number.isFinite(updatedMs) ? new Date(updatedMs).toISOString() : null,
|
|
519
|
+
ageMs,
|
|
520
|
+
sessionId: sanitizeTaskText(raw.sessionId, { maxChars: 64 }),
|
|
521
|
+
turn: Number.isInteger(raw.turn) && raw.turn >= 0 ? raw.turn : 0,
|
|
522
|
+
step: Number.isInteger(raw.step) && raw.step >= 0 ? raw.step : 0,
|
|
523
|
+
frameId: typeof raw.frameId === 'string' ? sanitizeTaskText(raw.frameId, { maxChars: 32 }) : null,
|
|
524
|
+
doing: sanitizeTaskText(raw.doing),
|
|
525
|
+
waitingFor,
|
|
526
|
+
nextStep: sanitizeTaskText(raw.nextStep),
|
|
527
|
+
anchorFiles,
|
|
528
|
+
};
|
|
529
|
+
return { ...view, preview: renderTaskStateLine(view) };
|
|
530
|
+
},
|
|
474
531
|
integrity: () => {
|
|
475
532
|
if (options.integrity && typeof options.integrity.status === 'function') {
|
|
476
533
|
return { schema: 'integrity/v1', ...options.integrity.status() };
|
|
@@ -643,6 +700,7 @@ export function createReadonlyRouter(options = {}) {
|
|
|
643
700
|
[25, () => readers.relationships()],
|
|
644
701
|
[26, () => readers.personality()],
|
|
645
702
|
[27, () => readers.channels()],
|
|
703
|
+
[28, () => readers.workframe()],
|
|
646
704
|
]);
|
|
647
705
|
for (const route of READONLY_ROUTES) {
|
|
648
706
|
if (!HANDLERS_BY_ID.has(route.id)) {
|
|
@@ -673,7 +731,7 @@ function warnOnce(key, error) {
|
|
|
673
731
|
}
|
|
674
732
|
|
|
675
733
|
/**
|
|
676
|
-
* Register the
|
|
734
|
+
* Register the 28 read-only routes on the host Web server.
|
|
677
735
|
* A profile without a Web server simply gets no route; activation never depends on it.
|
|
678
736
|
*/
|
|
679
737
|
export function registerReadonlyRoutes(ctx, options = {}) {
|
|
@@ -737,7 +795,7 @@ export function registerReadonlyRoutes(ctx, options = {}) {
|
|
|
737
795
|
}
|
|
738
796
|
}
|
|
739
797
|
// G3 detail route (`/api/longlive/distill/<id>`) is served by a prefix
|
|
740
|
-
// route so it does not widen the documented
|
|
798
|
+
// route so it does not widen the documented 28-route count.
|
|
741
799
|
try {
|
|
742
800
|
const dispose = webServer.register({ kind: 'prefix', path: DISTILL_DETAIL_PREFIX, handler: handleRequest });
|
|
743
801
|
if (typeof dispose === 'function' && typeof webCtx.effect === 'function') {
|