@jjh32456/longlive 2.1.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 +108 -1
- 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 +143 -73
- package/cordis.patch.yml +2 -0
- package/docs/ARCHITECTURE.md +6 -3
- package/docs/CONFIG.md +25 -1
- package/docs/FAQ.md +2 -2
- package/docs/FEATURES.md +125 -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/config.js +7 -0
- package/src/features.js +35 -0
- package/src/gate/action-gate.js +545 -0
- 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 +537 -35
- 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 +179 -16
- package/src/memory/lock.js +53 -12
- package/src/memory/maintenance.js +295 -19
- package/src/memory/recall-feedback.mjs +159 -17
- package/src/memory/recall-v2.js +5 -3
- package/src/memory/recall.js +10 -4
- package/src/memory/state.js +446 -38
- package/src/memory/task-state.mjs +569 -0
- package/src/recall/brain.mjs +55 -6
- package/src/recall/continuity-volatile.mjs +195 -1
- package/src/recall/index.js +8 -0
- package/src/tools.js +141 -21
- package/src/ui/routes-readonly.js +63 -5
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// scripts/watchdog-230.mjs — 2.3.0 / W6-2:世代健康检查 + 重启收据(端口不硬编码)。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要它:宿主每次启动会拿一个随机 Web 端口(同一台机器上连续重启端口不同),
|
|
5
|
+
// 旧的看门狗把端口写死/记住一次就复用,于是重启后可能出现两种误判:
|
|
6
|
+
// A) 端口上是上一世代进程(或别的服务)还活着 → 旧看门狗判「健康」,其实当前世代没起来;
|
|
7
|
+
// B) 端口变了 → 新看门狗以为「挂了」,其实新世代跑得好好的。
|
|
8
|
+
// 本工具把「端口」和「世代号」分开:世代号由启动器写进 generation 状态文件(见下),
|
|
9
|
+
// 健康端点必须回同一个世代号;端口只是从状态文件里读出来的数据,不写死、也不跨世代复用。
|
|
10
|
+
//
|
|
11
|
+
// 世代状态文件(启动器在每次启动后写入;路径默认 <DSH_HOME>/.longlive/generation.json):
|
|
12
|
+
// {
|
|
13
|
+
// "generation": 7, // 单调递增整数,每次宿主启动 +1
|
|
14
|
+
// "port": 42173, // 本次启动的 Web 端口(随机,因世代而异)
|
|
15
|
+
// "pid": 1234, // 可选:宿主进程号
|
|
16
|
+
// "startedAt": "2026-12-05T07:41:24.000Z",
|
|
17
|
+
// "healthPath": "/health" // 可选:健康端点路径,默认 /health
|
|
18
|
+
// }
|
|
19
|
+
// 健康端点应回:{"generation": 7, "pid": 1234, "ok": true}(generation 必须与状态文件一致)。
|
|
20
|
+
//
|
|
21
|
+
// 用法:
|
|
22
|
+
// node scripts/watchdog-230.mjs check --state <generation.json>
|
|
23
|
+
// [--previous-receipt <receipt.json>] [--receipt <out.json>] [--json]
|
|
24
|
+
// [--timeout 2000] [--health-path /health] [--host 127.0.0.1] [--no-mask] [--dry-run]
|
|
25
|
+
//
|
|
26
|
+
// 判决(verdict):
|
|
27
|
+
// healthy HTTP 200 且世代号一致(当前世代活着)
|
|
28
|
+
// restarted_healthy 健康且世代号比上一张收据新(重启成功,收据里记 from→to)
|
|
29
|
+
// stale_generation 端点回的世代号比期望旧(旧世代/残留进程占着端口)→ 必须重启
|
|
30
|
+
// future_generation 端点回的世代号比期望新(状态文件过期)→ 状态文件需刷新
|
|
31
|
+
// unreachable 连不上(端口关了/超时)
|
|
32
|
+
// http_error HTTP 非 200
|
|
33
|
+
// payload_invalid 回包不是 JSON 或缺 generation 字段
|
|
34
|
+
// 退出码:0 = healthy / restarted_healthy;1 = 其余判决(不健康);2 = 配置错误(未发探针)。
|
|
35
|
+
//
|
|
36
|
+
// 隐私:只探 127.0.0.1 回环,不发出网请求;日志与收据默认脱敏(状态文件绝对路径 → <state>)。
|
|
37
|
+
|
|
38
|
+
import http from 'node:http';
|
|
39
|
+
import os from 'node:os';
|
|
40
|
+
import path from 'node:path';
|
|
41
|
+
|
|
42
|
+
import {
|
|
43
|
+
ENGINE,
|
|
44
|
+
codedError,
|
|
45
|
+
exists,
|
|
46
|
+
isMainModule,
|
|
47
|
+
maskText,
|
|
48
|
+
privacyScan,
|
|
49
|
+
readJsonFile,
|
|
50
|
+
stampNow,
|
|
51
|
+
writeJsonAtomic,
|
|
52
|
+
} from './lib/eng-common.mjs';
|
|
53
|
+
|
|
54
|
+
const VERDICT_EXIT = {
|
|
55
|
+
healthy: 0,
|
|
56
|
+
restarted_healthy: 0,
|
|
57
|
+
stale_generation: 1,
|
|
58
|
+
future_generation: 1,
|
|
59
|
+
unreachable: 1,
|
|
60
|
+
http_error: 1,
|
|
61
|
+
payload_invalid: 1,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const MAX_BODY_BYTES = 64 * 1024;
|
|
65
|
+
|
|
66
|
+
function usageError(code, message) {
|
|
67
|
+
const error = codedError(code, message);
|
|
68
|
+
error.exitCode = 2;
|
|
69
|
+
return error;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function defaultStatePath() {
|
|
73
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
74
|
+
return path.join(home, '.longlive', 'generation.json');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function parseArgs(argv) {
|
|
78
|
+
const mode = argv[0] || 'check';
|
|
79
|
+
if (mode === '--help' || mode === '-h') return { mode: 'help' };
|
|
80
|
+
if (mode !== 'check') throw usageError('E_MODE', `unknown mode: ${mode} (only "check")`);
|
|
81
|
+
const options = {
|
|
82
|
+
mode,
|
|
83
|
+
state: null,
|
|
84
|
+
previousReceipt: null,
|
|
85
|
+
receipt: null,
|
|
86
|
+
host: '127.0.0.1',
|
|
87
|
+
healthPath: null,
|
|
88
|
+
timeoutMs: 2000,
|
|
89
|
+
json: false,
|
|
90
|
+
noMask: false,
|
|
91
|
+
dryRun: false,
|
|
92
|
+
};
|
|
93
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
94
|
+
const token = argv[index];
|
|
95
|
+
const take = () => {
|
|
96
|
+
const value = argv[++index];
|
|
97
|
+
if (!value || value.startsWith('--')) throw usageError('E_ARG', `${token} needs a value`);
|
|
98
|
+
return value;
|
|
99
|
+
};
|
|
100
|
+
switch (token) {
|
|
101
|
+
case '--state':
|
|
102
|
+
options.state = take();
|
|
103
|
+
break;
|
|
104
|
+
case '--previous-receipt':
|
|
105
|
+
options.previousReceipt = take();
|
|
106
|
+
break;
|
|
107
|
+
case '--receipt':
|
|
108
|
+
options.receipt = take();
|
|
109
|
+
break;
|
|
110
|
+
case '--host':
|
|
111
|
+
options.host = take();
|
|
112
|
+
break;
|
|
113
|
+
case '--health-path':
|
|
114
|
+
options.healthPath = take();
|
|
115
|
+
break;
|
|
116
|
+
case '--timeout':
|
|
117
|
+
options.timeoutMs = Number(take());
|
|
118
|
+
break;
|
|
119
|
+
case '--json':
|
|
120
|
+
options.json = true;
|
|
121
|
+
break;
|
|
122
|
+
case '--no-mask':
|
|
123
|
+
options.noMask = true;
|
|
124
|
+
break;
|
|
125
|
+
case '--dry-run':
|
|
126
|
+
options.dryRun = true;
|
|
127
|
+
break;
|
|
128
|
+
case '--help':
|
|
129
|
+
case '-h':
|
|
130
|
+
options.help = true;
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
throw usageError('E_ARG', `unknown argument: ${token}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return options;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readGenerationState(file) {
|
|
140
|
+
if (!exists(file)) throw usageError('E_STATE_MISSING', 'generation state file not found');
|
|
141
|
+
let state;
|
|
142
|
+
try {
|
|
143
|
+
state = readJsonFile(file);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw usageError('E_STATE_INVALID', `generation state unreadable (${error.code ?? error.message})`);
|
|
146
|
+
}
|
|
147
|
+
if (!state || typeof state !== 'object') throw usageError('E_STATE_INVALID', 'generation state must be an object');
|
|
148
|
+
const generation = state.generation;
|
|
149
|
+
if (!Number.isInteger(generation) || generation < 1) {
|
|
150
|
+
throw usageError('E_STATE_INVALID', 'generation must be a positive integer');
|
|
151
|
+
}
|
|
152
|
+
const port = state.port;
|
|
153
|
+
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
|
|
154
|
+
throw usageError('E_PORT', 'port must be an integer in 1..65535');
|
|
155
|
+
}
|
|
156
|
+
const healthPath = typeof state.healthPath === 'string' && state.healthPath.startsWith('/') ? state.healthPath : '/health';
|
|
157
|
+
return {
|
|
158
|
+
generation,
|
|
159
|
+
port,
|
|
160
|
+
pid: Number.isInteger(state.pid) ? state.pid : null,
|
|
161
|
+
startedAt: typeof state.startedAt === 'string' ? state.startedAt : null,
|
|
162
|
+
healthPath,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function readPreviousReceipt(file) {
|
|
167
|
+
if (!file) return null;
|
|
168
|
+
if (!exists(file)) return null;
|
|
169
|
+
try {
|
|
170
|
+
return readJsonFile(file);
|
|
171
|
+
} catch {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function probe({ host, port, healthPath, timeoutMs }) {
|
|
177
|
+
return new Promise((resolve) => {
|
|
178
|
+
const started = Date.now();
|
|
179
|
+
const request = http.request(
|
|
180
|
+
{ host, port, path: healthPath, method: 'GET', timeout: timeoutMs, headers: { accept: 'application/json' } },
|
|
181
|
+
(response) => {
|
|
182
|
+
const chunks = [];
|
|
183
|
+
let size = 0;
|
|
184
|
+
let truncated = false;
|
|
185
|
+
response.on('data', (chunk) => {
|
|
186
|
+
size += chunk.length;
|
|
187
|
+
if (size > MAX_BODY_BYTES) {
|
|
188
|
+
truncated = true;
|
|
189
|
+
response.destroy();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
chunks.push(chunk);
|
|
193
|
+
});
|
|
194
|
+
const done = () => {
|
|
195
|
+
const body = Buffer.concat(chunks).toString('utf8');
|
|
196
|
+
resolve({ ok: true, status: response.statusCode ?? 0, body, truncated, latencyMs: Date.now() - started });
|
|
197
|
+
};
|
|
198
|
+
response.on('end', done);
|
|
199
|
+
response.on('close', () => {
|
|
200
|
+
if (size > MAX_BODY_BYTES) done();
|
|
201
|
+
});
|
|
202
|
+
response.on('error', () => resolve({ ok: false, error: 'E_RESPONSE', latencyMs: Date.now() - started }));
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
request.on('timeout', () => {
|
|
206
|
+
request.destroy();
|
|
207
|
+
resolve({ ok: false, error: 'E_TIMEOUT', latencyMs: Date.now() - started });
|
|
208
|
+
});
|
|
209
|
+
request.on('error', (error) => resolve({ ok: false, error: String(error.code ?? 'E_NET'), latencyMs: Date.now() - started }));
|
|
210
|
+
request.end();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function classify(state, probeResult) {
|
|
215
|
+
if (!probeResult.ok) {
|
|
216
|
+
return { verdict: 'unreachable', detail: probeResult.error ?? 'network error' };
|
|
217
|
+
}
|
|
218
|
+
if (probeResult.status !== 200) {
|
|
219
|
+
return { verdict: 'http_error', detail: `HTTP ${probeResult.status}` };
|
|
220
|
+
}
|
|
221
|
+
let payload;
|
|
222
|
+
try {
|
|
223
|
+
payload = JSON.parse(probeResult.body);
|
|
224
|
+
} catch {
|
|
225
|
+
return { verdict: 'payload_invalid', detail: 'health body is not JSON' };
|
|
226
|
+
}
|
|
227
|
+
if (!payload || typeof payload !== 'object' || !Number.isInteger(payload.generation)) {
|
|
228
|
+
return { verdict: 'payload_invalid', detail: 'health body has no integer generation' };
|
|
229
|
+
}
|
|
230
|
+
if (payload.generation === state.generation) return { verdict: 'healthy', detail: `generation ${payload.generation}`, payload };
|
|
231
|
+
if (payload.generation < state.generation) {
|
|
232
|
+
return {
|
|
233
|
+
verdict: 'stale_generation',
|
|
234
|
+
detail: `port answers generation ${payload.generation}, expected ${state.generation} (old generation or leftover process)`,
|
|
235
|
+
payload,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return { verdict: 'future_generation', detail: `port answers generation ${payload.generation}, expected ${state.generation}`, payload };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function sanitizePaths(value, statePath, receiptPath) {
|
|
242
|
+
const roots = [];
|
|
243
|
+
if (statePath) roots.push({ path: statePath, placeholder: '<state>' });
|
|
244
|
+
if (receiptPath) roots.push({ path: receiptPath, placeholder: '<receipt>' });
|
|
245
|
+
const visit = (item) => {
|
|
246
|
+
if (typeof item === 'string') return maskText(item, { roots });
|
|
247
|
+
if (Array.isArray(item)) return item.map(visit);
|
|
248
|
+
if (item && typeof item === 'object') {
|
|
249
|
+
const out = {};
|
|
250
|
+
for (const [key, inner] of Object.entries(item)) out[key] = visit(inner);
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
253
|
+
return item;
|
|
254
|
+
};
|
|
255
|
+
return visit(value);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function runCheck(options) {
|
|
259
|
+
const statePath = options.state ? path.resolve(options.state) : defaultStatePath();
|
|
260
|
+
const report = {
|
|
261
|
+
tool: 'watchdog-230',
|
|
262
|
+
engine: ENGINE,
|
|
263
|
+
mode: 'check',
|
|
264
|
+
ok: false,
|
|
265
|
+
verdict: 'unreachable',
|
|
266
|
+
restartRequired: true,
|
|
267
|
+
state: null,
|
|
268
|
+
observed: null,
|
|
269
|
+
restart: { before: null, after: null, changed: false },
|
|
270
|
+
checks: [],
|
|
271
|
+
at: new Date().toISOString(),
|
|
272
|
+
error: null,
|
|
273
|
+
privacy: { clean: true, hits: [] },
|
|
274
|
+
};
|
|
275
|
+
let exitCode = 1;
|
|
276
|
+
try {
|
|
277
|
+
const state = readGenerationState(statePath);
|
|
278
|
+
const healthUrl = `http://${options.host}:${state.port}${options.healthPath || state.healthPath}`;
|
|
279
|
+
report.state = { generation: state.generation, port: state.port, pid: state.pid, healthUrl, startedAt: state.startedAt };
|
|
280
|
+
report.restart.after = state.generation;
|
|
281
|
+
const previous = readPreviousReceipt(options.previousReceipt);
|
|
282
|
+
const previousGeneration =
|
|
283
|
+
previous && Number.isInteger(previous?.state?.generation)
|
|
284
|
+
? previous.state.generation
|
|
285
|
+
: previous && Number.isInteger(previous?.generation)
|
|
286
|
+
? previous.generation
|
|
287
|
+
: null;
|
|
288
|
+
report.restart.before = previousGeneration;
|
|
289
|
+
report.restart.changed = previousGeneration !== null && previousGeneration !== state.generation;
|
|
290
|
+
|
|
291
|
+
report.checks.push({ id: 'C1', name: '世代状态可读', pass: true, detail: `generation ${state.generation}, port ${state.port}` });
|
|
292
|
+
if (options.dryRun) {
|
|
293
|
+
report.verdict = 'dry_run';
|
|
294
|
+
report.ok = false;
|
|
295
|
+
report.restartRequired = false;
|
|
296
|
+
report.receipt = null;
|
|
297
|
+
report.checks.push({ id: 'C2', name: '探针', pass: true, detail: `would GET ${healthUrl}` });
|
|
298
|
+
throw Object.assign(codedError('E_DRY_RUN', 'dry run'), { exitCode: 0, dryRun: true });
|
|
299
|
+
}
|
|
300
|
+
const probeResult = await probe({ host: options.host, port: state.port, healthPath: options.healthPath || state.healthPath, timeoutMs: options.timeoutMs });
|
|
301
|
+
report.observed = {
|
|
302
|
+
httpStatus: probeResult.status ?? null,
|
|
303
|
+
latencyMs: probeResult.latencyMs ?? null,
|
|
304
|
+
generation: null,
|
|
305
|
+
pid: null,
|
|
306
|
+
error: probeResult.ok ? null : probeResult.error ?? null,
|
|
307
|
+
};
|
|
308
|
+
const verdict = classify(state, probeResult);
|
|
309
|
+
if (verdict.payload) {
|
|
310
|
+
report.observed.generation = verdict.payload.generation;
|
|
311
|
+
report.observed.pid = Number.isInteger(verdict.payload.pid) ? verdict.payload.pid : null;
|
|
312
|
+
}
|
|
313
|
+
report.verdict = verdict.verdict === 'healthy' && report.restart.changed ? 'restarted_healthy' : verdict.verdict;
|
|
314
|
+
report.ok = report.verdict === 'healthy' || report.verdict === 'restarted_healthy';
|
|
315
|
+
report.restartRequired = !report.ok;
|
|
316
|
+
exitCode = VERDICT_EXIT[report.verdict] ?? 1;
|
|
317
|
+
report.checks.push({ id: 'C2', name: '健康端点可达', pass: probeResult.ok && (probeResult.status ?? 0) === 200, detail: verdict.detail });
|
|
318
|
+
report.checks.push({ id: 'C3', name: '世代号一致', pass: report.ok, detail: report.ok ? `generation ${state.generation}` : verdict.detail });
|
|
319
|
+
report.checks.push({
|
|
320
|
+
id: 'C4',
|
|
321
|
+
name: '重启收据(世代更迭)',
|
|
322
|
+
pass: !report.restart.changed || report.ok,
|
|
323
|
+
detail: report.restart.changed ? `generation ${report.restart.before} -> ${report.restart.after}` : 'no previous receipt: single-generation check',
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
report.ok = false;
|
|
327
|
+
if (error.dryRun) {
|
|
328
|
+
report.verdict = 'dry_run';
|
|
329
|
+
report.error = null;
|
|
330
|
+
exitCode = 0;
|
|
331
|
+
} else {
|
|
332
|
+
report.verdict = 'config_error';
|
|
333
|
+
report.error = { code: error.code ?? 'E_FAIL', message: error.message };
|
|
334
|
+
exitCode = error.exitCode ?? 2;
|
|
335
|
+
report.checks.push({ id: 'C0', name: '配置', pass: false, detail: error.message });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const masked = sanitizePaths(report, statePath, options.receipt ? path.resolve(options.receipt) : null);
|
|
339
|
+
const scan = privacyScan(JSON.stringify(masked));
|
|
340
|
+
masked.privacy = { clean: scan.clean, hits: scan.hits, engine: ENGINE.version };
|
|
341
|
+
if (options.receipt && !options.dryRun && masked.verdict !== 'config_error') {
|
|
342
|
+
try {
|
|
343
|
+
writeJsonAtomic(path.resolve(options.receipt), masked);
|
|
344
|
+
} catch {
|
|
345
|
+
/* best effort */
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (options.json) {
|
|
349
|
+
process.stdout.write(`${JSON.stringify(masked, null, 2)}\n`);
|
|
350
|
+
} else {
|
|
351
|
+
const lines = [`watchdog-230: ${masked.verdict}`];
|
|
352
|
+
lines.push(` generation: ${masked.state?.generation ?? '<unknown>'} port: ${masked.state?.port ?? '<unknown>'}`);
|
|
353
|
+
if (masked.restart.before !== null) lines.push(` restart: ${masked.restart.before} -> ${masked.restart.after} (changed: ${masked.restart.changed})`);
|
|
354
|
+
for (const check of masked.checks) lines.push(` [${check.pass ? 'PASS' : 'FAIL'}] ${check.id} ${check.name}: ${check.detail}`);
|
|
355
|
+
if (masked.error) lines.push(` error: [${masked.error.code}] ${masked.error.message}`);
|
|
356
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
357
|
+
}
|
|
358
|
+
return { report: masked, exitCode };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
362
|
+
let options;
|
|
363
|
+
try {
|
|
364
|
+
options = parseArgs(argv);
|
|
365
|
+
} catch (error) {
|
|
366
|
+
process.stderr.write(`watchdog-230: ${error.message}\n`);
|
|
367
|
+
return error.exitCode ?? 2;
|
|
368
|
+
}
|
|
369
|
+
if (options.help) {
|
|
370
|
+
process.stdout.write('usage: node scripts/watchdog-230.mjs check --state <generation.json> [--previous-receipt <r.json>] [--receipt <out.json>] [--json]\n');
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
const { exitCode } = await runCheck(options);
|
|
374
|
+
return exitCode;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (isMainModule(import.meta.url)) {
|
|
378
|
+
process.exit(await main());
|
|
379
|
+
}
|
package/src/config.js
CHANGED
|
@@ -293,6 +293,7 @@ const ZH = {
|
|
|
293
293
|
tiering: '热温冷分层(03):mode = off / shadow / filter(默认 shadow,读取面与 1.8.3 一致);filter 时默认只放行 hot+warm,cold 需显式 tier:\'cold\' 或 tier:\'all\'。子键:mode / hotSessions / hotTurns / hotCardDays / hotCardMax / warmDays / hotDays / maxStaleHours / suppressedCap;归一化在 src/memory/tiers.js#normalizeTiering。',
|
|
294
294
|
proactive: '主动浮现(04):隔 ≥3 小时回来时注入 1 条 ≤300 字的记忆卡线索(默认关闭;开启后默认先 dry-run,只审计不注入)。子键:enabled / dryRun / minSilenceMs / topicMinScore / topicMinHits / topicMinPhraseChars / topicBudgetTokens(渲染预算,按代码点保守上界收紧 maxChars)/ maxItems(硬钳 0..1;0 = 显式关闭,零注入零额度)/ maxChars / dirs / allowFirstTurn / skipSubagents / logMaxLines。',
|
|
295
295
|
handoff: '跨会话交接卡(02):每轮 completed 结束把 目标/已结论/未决/下一步/最近动作 upsert 进源会话的 per-session 卡;新会话首轮按「cwd 门 + 存活门 + 相关性/实质门 + 续接意图(实质 + ≤60min 新鲜 + 唯一近期实质卡)+ 预算 + 认领」选 1 张,注入 ≤281 码点的隐藏消息。默认关闭(字面 enabled:true 才开启);开启后建议先 dryRun:true 只审计不注入。kill switch:DSH_LONGLIVE_DISABLE_HANDOFF=1。子键:enabled / dryRun / maxChars(128..300) / maxAgeHours(1..168) / firstTurnOnly / inject / write / decidedMax(1..3) / relevanceContainShort(0.2..0.8) / relevanceDiceLong(0.1..0.6) / intentBypass / intentFreshMinutes(10..180) / intentSemantics(unique-recent|latest;latest 需产品拍板) / maxIndexFiles(8..256) / auditWindowRows(100..2000) / privacyScan;归一化在 src/handoff/index.js#normalizeHandoffConfig。',
|
|
296
|
+
actionGate: '动作前回忆门(2.2.0,lane-C):高危动作命令(发布 / 插件装卸 / 递归删除 / 回滚 / 硬重置等)执行前,要求 gate-log 里存在同会话的动作类 procedure 卡回执;没有回执直接拒绝并提示先 memory_recall 取卡(默认 enforce;shadow 只记不拦;off 不注册)。子键:enabled / mode;kill switch:DSH_LONGLIVE_DISABLE_ACTION_GATE=1;归一化在 src/gate/action-gate.js#normalizeActionGateConfig。',
|
|
296
297
|
};
|
|
297
298
|
|
|
298
299
|
/** English copy: `en` is the locale fallback chain's base. */
|
|
@@ -537,6 +538,7 @@ const EN = {
|
|
|
537
538
|
tiering: 'Recall tiers (03): mode = off / shadow / filter (default shadow; reads match 1.8.3). In filter mode only hot+warm are visible by default; pass tier:\'cold\' or tier:\'all\' to search cold turns. Keys: mode / hotSessions / hotTurns / hotCardDays / hotCardMax / warmDays / hotDays / maxStaleHours / suppressedCap; normalised in src/memory/tiers.js#normalizeTiering.',
|
|
538
539
|
proactive: 'Proactive surface (04): after a >=3h silence, inject one <=300-char memory-card clue (off by default; when enabled it first runs in dry-run and only audits). Keys: enabled / dryRun / minSilenceMs / topicMinScore / topicMinHits / topicMinPhraseChars / topicBudgetTokens (render budget; a conservative code-point ceiling applied to maxChars) / maxItems (clamped 0..1; 0 = explicitly off: no injection, no quota) / maxChars / dirs / allowFirstTurn / skipSubagents / logMaxLines.',
|
|
539
540
|
handoff: 'Cross-session handoff card (02): after every completed turn, upsert goal/decided/open/next/last-action into the source session latest card; on a new session\'s first step pick one card through cwd gate + liveness gate + relevance/substance gate + continuation intent (substantive + <=60min fresh + unique recent substantive card) + budget + claim, then inject one hidden <=281-code-point message. Off by default (only a literal enabled:true turns it on); enable dryRun:true first to audit without injecting. Kill switch: DSH_LONGLIVE_DISABLE_HANDOFF=1. Keys: enabled / dryRun / maxChars(128..300) / maxAgeHours(1..168) / firstTurnOnly / inject / write / decidedMax(1..3) / relevanceContainShort(0.2..0.8) / relevanceDiceLong(0.1..0.6) / intentBypass / intentFreshMinutes(10..180) / intentSemantics(unique-recent|latest; latest needs sign-off) / maxIndexFiles(8..256) / auditWindowRows(100..2000) / privacyScan; normalised in src/handoff/index.js#normalizeHandoffConfig.',
|
|
541
|
+
actionGate: 'Pre-action recall gate (2.2.0, lane-C): high-risk action commands (publish / plugin install-remove / recursive delete / rollback / hard reset) are denied unless the gate log already holds a same-session procedure-card receipt; the denial tells the agent to call memory_recall first (default enforce; shadow only records; off does not register). Keys: enabled / mode; kill switch: DSH_LONGLIVE_DISABLE_ACTION_GATE=1; normalised in src/gate/action-gate.js#normalizeActionGateConfig.',
|
|
540
542
|
};
|
|
541
543
|
|
|
542
544
|
function schemaOf() {
|
|
@@ -806,6 +808,11 @@ function schemaOf() {
|
|
|
806
808
|
// queueMax/maxFilesPerRun/allowTools/preset/approvalPolicy 走代码默认、只可收紧)。
|
|
807
809
|
// 归一化 + 钳制在 src/memory/wake-bridge.mjs 的 normalizeWakeConfig(越界 clamp + warn +
|
|
808
810
|
// 下次 run 审计 configClamps),接线见 src/features.js 的 registerHardgateWake 块。
|
|
811
|
+
//
|
|
812
|
+
// 2.2.0 动作前回忆门(lane-C)同样 passthrough:config.actionGate 不声明 leaf
|
|
813
|
+
// (节点锁不变),只认 enabled / mode 两个键,归一化在
|
|
814
|
+
// src/gate/action-gate.js#normalizeActionGateConfig,接线见 src/features.js 的
|
|
815
|
+
// registerActionGate 块;文案见上方 ZH/EN.actionGate。
|
|
809
816
|
|
|
810
817
|
d2,
|
|
811
818
|
d6,
|
package/src/features.js
CHANGED
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
releaseCardMarker,
|
|
33
33
|
} from './identity/card-marker.js';
|
|
34
34
|
import { isInsideRoot, memoryError, PATH_CODES } from './memory/paths.js';
|
|
35
|
+
import { registerActionGate } from './gate/action-gate.js';
|
|
36
|
+
// 动作门要排除本插件自己的工具(ownNames),否则同名工具会被误判;TOOLS 是纯数组,
|
|
37
|
+
// 这里只取名字,没有副作用(tools.js 不 import features.js,不存在环)。
|
|
38
|
+
import { TOOLS } from './tools.js';
|
|
35
39
|
import {
|
|
36
40
|
assertInjectionSource,
|
|
37
41
|
injectionSource,
|
|
@@ -192,6 +196,20 @@ export function normalizeFeatureConfig(config = {}) {
|
|
|
192
196
|
// 时才追加该键(值/键原样透传,浅拷贝防外部改写);不带该键时输出仍是上面那 6 键,
|
|
193
197
|
// 既有 defaults 快照(feature-flags deepEqual)逐字节不变。
|
|
194
198
|
if (wake) normalized.hardgate = { wake: { ...wake } };
|
|
199
|
+
// 2.3.0 lane pipeline(W1-4):autoResolve 单元上限 raw 透传(不新增 schemastery
|
|
200
|
+
// 叶子,config schema 153 节点锁不变;同 2.1.0 continuity/readGate 与 hardgate.wake
|
|
201
|
+
// 的做法)。profile 可写顶层 `autoResolve.{maxSpan,maxText}` 或
|
|
202
|
+
// `autoMaintenance.autoResolve.*`,顶层优先;这里只浅拷贝原样透传,数值钳制仍在
|
|
203
|
+
// consolidate.js 的 autoUnitLimits(默认 10 行 / 800 字)。不带该键时输出形状不变。
|
|
204
|
+
const autoResolveTop = value.autoResolve && typeof value.autoResolve === 'object' && !Array.isArray(value.autoResolve)
|
|
205
|
+
? value.autoResolve
|
|
206
|
+
: {};
|
|
207
|
+
const autoResolveNested = maintenance.autoResolve && typeof maintenance.autoResolve === 'object' && !Array.isArray(maintenance.autoResolve)
|
|
208
|
+
? maintenance.autoResolve
|
|
209
|
+
: {};
|
|
210
|
+
if (Object.keys(autoResolveTop).length > 0 || Object.keys(autoResolveNested).length > 0) {
|
|
211
|
+
normalized.autoMaintenance.autoResolve = { ...autoResolveNested, ...autoResolveTop };
|
|
212
|
+
}
|
|
195
213
|
return normalized;
|
|
196
214
|
}
|
|
197
215
|
|
|
@@ -1032,6 +1050,23 @@ export function registerFeatures(ctx, config = {}, options = {}) {
|
|
|
1032
1050
|
}
|
|
1033
1051
|
}
|
|
1034
1052
|
|
|
1053
|
+
// 2.2.0 动作前回忆门(lane-C):默认 enforce。
|
|
1054
|
+
// 与 src/tools.js 里现有 router guard 并列注册;配置走 raw passthrough(schema 节点锁不变),
|
|
1055
|
+
// 归一化在 src/gate/action-gate.js#normalizeActionGateConfig。宿主没有 ctx.tools.guard() 时
|
|
1056
|
+
// 不阻断也不伪造阻断:真实宿主才 warn + gate-log 留痕,测试/简化宿主静默跳过。
|
|
1057
|
+
// memoryRoot 缺省时不注册(动作门需要读 gate-log 回执),不塞任何默认机器路径。
|
|
1058
|
+
{
|
|
1059
|
+
const actionGate = registerActionGate(ctx, {
|
|
1060
|
+
config: config.actionGate && typeof config.actionGate === 'object' ? config.actionGate : undefined,
|
|
1061
|
+
memoryRoot,
|
|
1062
|
+
ownToolNames: TOOLS.map((tool) => tool.name),
|
|
1063
|
+
warn,
|
|
1064
|
+
env: process.env,
|
|
1065
|
+
now: typeof config.now === 'function' ? config.now : undefined,
|
|
1066
|
+
});
|
|
1067
|
+
if (actionGate.registered) enabled.push('actionGate');
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1035
1070
|
if (enabled.length > 0 && logger && typeof logger.info === 'function') {
|
|
1036
1071
|
logger.info(`[longlive] opt-in features: ${enabled.join(', ')}`);
|
|
1037
1072
|
}
|