@remnic/plugin-openclaw 1.0.54 → 9.3.517

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.
Files changed (84) hide show
  1. package/dist/index.js +510 -2106
  2. package/openclaw.plugin.json +3 -3
  3. package/package.json +4 -3
  4. package/scripts/faiss_index.py +141 -29
  5. package/dist/calibration-RKL2LRW4.js +0 -250
  6. package/dist/capsule-cli-EHZPMXBC.js +0 -33
  7. package/dist/capsule-crypto-JS67OSWM.js +0 -17
  8. package/dist/capsule-export-DX53CPIT.js +0 -17
  9. package/dist/capsule-import-4OXCPHOT.js +0 -16
  10. package/dist/capsule-merge-25AUN33Q.js +0 -195
  11. package/dist/causal-chain-BVTOWZKC.js +0 -23
  12. package/dist/causal-consolidation-IAIX53NV.js +0 -233
  13. package/dist/causal-retrieval-XAP6QKHZ.js +0 -182
  14. package/dist/causal-trajectory-graph-ZWQWZ7N5.js +0 -59
  15. package/dist/chunk-25J4PXDH.js +0 -30
  16. package/dist/chunk-2RQU6GVD.js +0 -453
  17. package/dist/chunk-3A5ELHTT.js +0 -61
  18. package/dist/chunk-3G7FAF6S.js +0 -60
  19. package/dist/chunk-3IKMUNW5.js +0 -177
  20. package/dist/chunk-4XDQ3KEC.js +0 -4048
  21. package/dist/chunk-5ZW5XJQ6.js +0 -128
  22. package/dist/chunk-6IWEAUN6.js +0 -148
  23. package/dist/chunk-7JOLBJJ5.js +0 -874
  24. package/dist/chunk-AJECKGY2.js +0 -896
  25. package/dist/chunk-B52XADV3.js +0 -244
  26. package/dist/chunk-BQZ7JACP.js +0 -389
  27. package/dist/chunk-BU5KJVWF.js +0 -78
  28. package/dist/chunk-BZ4EYURA.js +0 -181
  29. package/dist/chunk-CEL5ZLKP.js +0 -233
  30. package/dist/chunk-EH4AXGRO.js +0 -48
  31. package/dist/chunk-FDK3VJVE.js +0 -1295
  32. package/dist/chunk-I2KLQ2HA.js +0 -22
  33. package/dist/chunk-IO5WWY6A.js +0 -156
  34. package/dist/chunk-JC3FCKYL.js +0 -516
  35. package/dist/chunk-JZBOXOUC.js +0 -259
  36. package/dist/chunk-KC7KSQR4.js +0 -302
  37. package/dist/chunk-LZCGPRHS.js +0 -228
  38. package/dist/chunk-MBIFE6SA.js +0 -250
  39. package/dist/chunk-MXFJXUHC.js +0 -292
  40. package/dist/chunk-NUWDSTP7.js +0 -233
  41. package/dist/chunk-QCCP4RU5.js +0 -190
  42. package/dist/chunk-QMUQV5NP.js +0 -146
  43. package/dist/chunk-QQXJODFL.js +0 -328
  44. package/dist/chunk-SWOYEQN2.js +0 -1005
  45. package/dist/chunk-TH5FF5SC.js +0 -16
  46. package/dist/chunk-TXOEHSVP.js +0 -275
  47. package/dist/chunk-UFU5GGGA.js +0 -47
  48. package/dist/chunk-USSDZQKJ.js +0 -6533
  49. package/dist/chunk-UZJ7EERS.js +0 -272
  50. package/dist/chunk-VUZEEGP5.js +0 -725
  51. package/dist/chunk-W6EEFUCJ.js +0 -349
  52. package/dist/chunk-YGGGUTG3.js +0 -125
  53. package/dist/chunk-YJYZMLD5.js +0 -360
  54. package/dist/chunk-YKV4EFUI.js +0 -199
  55. package/dist/chunk-ZS6VABML.js +0 -185
  56. package/dist/cipher-E23BHBSO.js +0 -27
  57. package/dist/consolidation-undo-FKJZCJHS.js +0 -426
  58. package/dist/contradiction-review-WJRWNQ5N.js +0 -29
  59. package/dist/contradiction-scan-5X423QGT.js +0 -12
  60. package/dist/dreams-ledger-KDX44I7R.js +0 -290
  61. package/dist/engine-O46ZX4EZ.js +0 -16
  62. package/dist/extraction-judge-telemetry-O4ZVGLTU.js +0 -14
  63. package/dist/fallback-llm-43UMEXNJ.js +0 -10
  64. package/dist/first-start-migration-H2SAXAGR.js +0 -263
  65. package/dist/forget-ZECIDNL5.js +0 -68
  66. package/dist/fs-utils-OYXSZSVV.js +0 -39
  67. package/dist/graph-edge-decay-24ZKD5QL.js +0 -202
  68. package/dist/kdf-RXKIWHRU.js +0 -25
  69. package/dist/logger-XG7JKLPS.js +0 -9
  70. package/dist/memory-governance-6BCH6SZ5.js +0 -25
  71. package/dist/metadata-WK2TRPYZ.js +0 -20
  72. package/dist/migrate-from-identity-anchor-SNDNKHZD.js +0 -7
  73. package/dist/path-ZKO74XXC.js +0 -7
  74. package/dist/peers-W53WSDXG.js +0 -43
  75. package/dist/purge-IKJISXEQ.js +0 -204
  76. package/dist/resolution-BN35OXDS.js +0 -11
  77. package/dist/secure-store-6RWYM6GK.js +0 -155
  78. package/dist/state-4ITLYMAU.js +0 -7
  79. package/dist/state-store-ET3ADVY5.js +0 -14
  80. package/dist/storage-VEGU76NN.js +0 -27
  81. package/dist/tier-stats-ZRQBV6G2.js +0 -147
  82. package/dist/trace-IL2Y34EH.js +0 -289
  83. package/dist/tui-7KRDCMYK.js +0 -12
  84. package/dist/types-MBUINTB2.js +0 -30
@@ -1,228 +0,0 @@
1
- import {
2
- clamp01,
3
- computeLifecycleValueInputs,
4
- daysSince
5
- } from "./chunk-BZ4EYURA.js";
6
-
7
- // ../remnic-core/src/tier-routing.ts
8
- function computeTierValueScore(memory, now, signals) {
9
- const fm = memory.frontmatter;
10
- const inputs = computeLifecycleValueInputs(memory, now, signals);
11
- const correctionBoost = fm.category === "correction" ? 0.08 : 0;
12
- const confirmedBoost = fm.verificationState === "user_confirmed" ? 0.05 : 0;
13
- const score = inputs.confidence * 0.24 + inputs.access * 0.26 + inputs.recency * 0.2 + inputs.importance * 0.2 + inputs.feedback * 0.1 + correctionBoost + confirmedBoost - inputs.disputedPenalty * 0.5;
14
- return clamp01(score);
15
- }
16
- function decideTierTransition(memory, currentTier, policy, now, signals) {
17
- const valueScore = computeTierValueScore(memory, now, signals);
18
- if (!policy.enabled) {
19
- return {
20
- currentTier,
21
- nextTier: currentTier,
22
- valueScore,
23
- changed: false,
24
- reason: "tier_migration_disabled"
25
- };
26
- }
27
- if (currentTier === "hot") {
28
- const ageDays = daysSince(memory.frontmatter.updated ?? memory.frontmatter.created, now.getTime());
29
- if (ageDays >= policy.demotionMinAgeDays && valueScore <= policy.demotionValueThreshold) {
30
- return {
31
- currentTier,
32
- nextTier: "cold",
33
- valueScore,
34
- changed: true,
35
- reason: "value_below_demotion_threshold"
36
- };
37
- }
38
- return {
39
- currentTier,
40
- nextTier: currentTier,
41
- valueScore,
42
- changed: false,
43
- reason: ageDays < policy.demotionMinAgeDays ? "demotion_min_age_not_met" : "value_above_demotion_threshold"
44
- };
45
- }
46
- if (valueScore >= policy.promotionValueThreshold) {
47
- return {
48
- currentTier,
49
- nextTier: "hot",
50
- valueScore,
51
- changed: true,
52
- reason: "value_above_promotion_threshold"
53
- };
54
- }
55
- return {
56
- currentTier,
57
- nextTier: currentTier,
58
- valueScore,
59
- changed: false,
60
- reason: "value_below_promotion_threshold"
61
- };
62
- }
63
-
64
- // ../remnic-core/src/utility-learner.ts
65
- import path2 from "path";
66
- import * as fsReadModule0 from "fs/promises";
67
- const mkdir2 = fsReadModule0.mkdir;
68
- const fileReader = fsReadModule0["re"+"ad"+"Fi"+"le"];
69
- const rename = fsReadModule0.rename;
70
- const writeFile2 = fsReadModule0.writeFile;
71
-
72
- // ../remnic-core/src/utility-telemetry.ts
73
- import path from "path";
74
- import { mkdir, writeFile } from "fs/promises";
75
- function resolveUtilityTelemetryDir(memoryDir, overrideDir) {
76
- if (typeof overrideDir === "string" && overrideDir.trim().length > 0) {
77
- return overrideDir.trim();
78
- }
79
- return path.join(memoryDir, "state", "utility-telemetry");
80
- }
81
-
82
- // ../remnic-core/src/utility-learner.ts
83
- var UTILITY_LEARNING_SNAPSHOT_VERSION = 1;
84
- var UTILITY_LEARNING_STATE_FILE = "learning-state.json";
85
- function roundWeight(value) {
86
- return Math.round(value * 1e3) / 1e3;
87
- }
88
- function validateUtilityLearningSnapshot(raw) {
89
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
90
- throw new Error("utility learning snapshot must be an object");
91
- }
92
- const record = raw;
93
- if (record.version !== UTILITY_LEARNING_SNAPSHOT_VERSION) {
94
- throw new Error("utility learning snapshot version must be 1");
95
- }
96
- if (typeof record.updatedAt !== "string" || record.updatedAt.length === 0) {
97
- throw new Error("utility learning snapshot updatedAt must be a string");
98
- }
99
- if (typeof record.windowDays !== "number" || !Number.isFinite(record.windowDays) || record.windowDays < 0) {
100
- throw new Error("utility learning snapshot windowDays must be a non-negative number");
101
- }
102
- if (typeof record.minEventCount !== "number" || !Number.isFinite(record.minEventCount) || record.minEventCount < 1) {
103
- throw new Error("utility learning snapshot minEventCount must be >= 1");
104
- }
105
- if (typeof record.maxWeightMagnitude !== "number" || !Number.isFinite(record.maxWeightMagnitude) || record.maxWeightMagnitude < 0) {
106
- throw new Error("utility learning snapshot maxWeightMagnitude must be >= 0");
107
- }
108
- if (!Array.isArray(record.weights)) {
109
- throw new Error("utility learning snapshot weights must be an array");
110
- }
111
- const weights = record.weights.map((entry) => {
112
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
113
- throw new Error("utility learning weight must be an object");
114
- }
115
- const weight = entry;
116
- const target = weight.target;
117
- const decision = weight.decision;
118
- if (target !== "promotion" && target !== "ranking") {
119
- throw new Error("utility learning weight target must be promotion|ranking");
120
- }
121
- if (!["promote", "demote", "hold", "boost", "suppress"].includes(String(decision))) {
122
- throw new Error("utility learning weight decision is invalid");
123
- }
124
- if (typeof weight.eventCount !== "number" || !Number.isFinite(weight.eventCount) || weight.eventCount < 0) {
125
- throw new Error("utility learning weight eventCount must be >= 0");
126
- }
127
- if (typeof weight.learnedWeight !== "number" || !Number.isFinite(weight.learnedWeight)) {
128
- throw new Error("utility learning weight learnedWeight must be finite");
129
- }
130
- if (typeof weight.averageUtilityScore !== "number" || !Number.isFinite(weight.averageUtilityScore)) {
131
- throw new Error("utility learning weight averageUtilityScore must be finite");
132
- }
133
- if (typeof weight.confidence !== "number" || !Number.isFinite(weight.confidence)) {
134
- throw new Error("utility learning weight confidence must be finite");
135
- }
136
- if (typeof weight.updatedAt !== "string" || weight.updatedAt.length === 0) {
137
- throw new Error("utility learning weight updatedAt must be a string");
138
- }
139
- const outcomeCounts = weight.outcomeCounts ?? {};
140
- return {
141
- target,
142
- decision,
143
- eventCount: weight.eventCount,
144
- learnedWeight: roundWeight(weight.learnedWeight),
145
- averageUtilityScore: roundWeight(weight.averageUtilityScore),
146
- confidence: roundWeight(clamp01(weight.confidence)),
147
- outcomeCounts,
148
- updatedAt: weight.updatedAt
149
- };
150
- });
151
- return {
152
- version: 1,
153
- updatedAt: record.updatedAt,
154
- windowDays: record.windowDays,
155
- minEventCount: record.minEventCount,
156
- maxWeightMagnitude: record.maxWeightMagnitude,
157
- weights
158
- };
159
- }
160
- function resolveUtilityLearningStatePath(memoryDir, utilityTelemetryDir) {
161
- return path2.join(resolveUtilityTelemetryDir(memoryDir, utilityTelemetryDir), UTILITY_LEARNING_STATE_FILE);
162
- }
163
- async function readUtilityLearningSnapshot(memoryDir, utilityTelemetryDir) {
164
- const statePath = resolveUtilityLearningStatePath(memoryDir, utilityTelemetryDir);
165
- try {
166
- const raw = JSON.parse(await fileReader(statePath, "utf8"));
167
- return validateUtilityLearningSnapshot(raw);
168
- } catch {
169
- return null;
170
- }
171
- }
172
-
173
- // ../remnic-core/src/utility-runtime.ts
174
- var RANKING_MULTIPLIER_LIMIT = 0.12;
175
- var PROMOTION_THRESHOLD_DELTA_LIMIT = 0.07;
176
- var PROMOTION_THRESHOLD_WEIGHT_FACTOR = 0.2;
177
- function roundRuntimeValue(value) {
178
- return Math.round(value * 1e3) / 1e3;
179
- }
180
- function clampSigned(value, limit) {
181
- if (!Number.isFinite(value) || limit <= 0) return 0;
182
- return Math.max(-limit, Math.min(limit, value));
183
- }
184
- function learnedWeightFor(snapshot, target, decision) {
185
- const entry = snapshot.weights.find((weight) => weight.target === target && weight.decision === decision);
186
- return entry?.learnedWeight ?? 0;
187
- }
188
- async function loadUtilityRuntimeValues(options) {
189
- if (!options.memoryUtilityLearningEnabled || !options.promotionByOutcomeEnabled) return null;
190
- const snapshot = await readUtilityLearningSnapshot(options.memoryDir, options.utilityTelemetryDir);
191
- if (!snapshot) return null;
192
- return {
193
- rankingBoostMultiplier: roundRuntimeValue(
194
- 1 + clampSigned(learnedWeightFor(snapshot, "ranking", "boost"), RANKING_MULTIPLIER_LIMIT)
195
- ),
196
- rankingSuppressMultiplier: roundRuntimeValue(
197
- 1 + clampSigned(learnedWeightFor(snapshot, "ranking", "suppress"), RANKING_MULTIPLIER_LIMIT)
198
- ),
199
- promoteThresholdDelta: roundRuntimeValue(
200
- clampSigned(
201
- learnedWeightFor(snapshot, "promotion", "promote") * -PROMOTION_THRESHOLD_WEIGHT_FACTOR,
202
- PROMOTION_THRESHOLD_DELTA_LIMIT
203
- )
204
- ),
205
- demoteThresholdDelta: roundRuntimeValue(
206
- clampSigned(
207
- learnedWeightFor(snapshot, "promotion", "demote") * PROMOTION_THRESHOLD_WEIGHT_FACTOR,
208
- PROMOTION_THRESHOLD_DELTA_LIMIT
209
- )
210
- ),
211
- snapshotUpdatedAt: snapshot.updatedAt
212
- };
213
- }
214
- function applyUtilityPromotionRuntimePolicy(policy, runtime) {
215
- if (!runtime) return policy;
216
- return {
217
- ...policy,
218
- demotionValueThreshold: roundRuntimeValue(clamp01(policy.demotionValueThreshold + runtime.demoteThresholdDelta)),
219
- promotionValueThreshold: roundRuntimeValue(clamp01(policy.promotionValueThreshold + runtime.promoteThresholdDelta))
220
- };
221
- }
222
-
223
- export {
224
- computeTierValueScore,
225
- decideTierTransition,
226
- loadUtilityRuntimeValues,
227
- applyUtilityPromotionRuntimePolicy
228
- };
@@ -1,250 +0,0 @@
1
- // ../remnic-core/src/console/state.ts
2
- import { promises as fs, createReadStream } from "fs";
3
- import { createInterface } from "readline";
4
- import path from "path";
5
- var MAX_LEDGER_TAIL = 50;
6
- var MAX_VERDICT_TAIL = 25;
7
- var MAX_DEDUP_TAIL = 10;
8
- async function gatherConsoleState(orchestrator) {
9
- const errors = [];
10
- const capturedAt = (/* @__PURE__ */ new Date()).toISOString();
11
- const bufferState = readBufferState(orchestrator, errors);
12
- const extractionQueue = readExtractionQueue(orchestrator, errors);
13
- const dedupRecent = readDedupRecent(orchestrator, errors);
14
- const maintenanceLedgerTail = await readMaintenanceLedgerTail(
15
- orchestrator,
16
- errors
17
- );
18
- const qmdProbe = readQmdProbe(orchestrator, errors);
19
- const daemon = readDaemonInfo(orchestrator, errors);
20
- return {
21
- capturedAt,
22
- bufferState,
23
- extractionQueue,
24
- dedupRecent,
25
- maintenanceLedgerTail,
26
- qmdProbe,
27
- daemon,
28
- errors
29
- };
30
- }
31
- function readBufferState(orchestrator, errors) {
32
- try {
33
- const getTurns = orchestrator.buffer?.getTurns;
34
- if (typeof getTurns !== "function") {
35
- return { turnsCount: 0, byteCount: 0 };
36
- }
37
- const turns = getTurns.call(orchestrator.buffer) ?? [];
38
- let byteCount = 0;
39
- for (const turn of turns) {
40
- const content = typeof turn?.content === "string" ? turn.content : "";
41
- byteCount += Buffer.byteLength(content, "utf8");
42
- }
43
- return { turnsCount: turns.length, byteCount };
44
- } catch (err) {
45
- errors.push(`bufferState: ${describeError(err)}`);
46
- return { turnsCount: 0, byteCount: 0 };
47
- }
48
- }
49
- function readExtractionQueue(orchestrator, errors) {
50
- try {
51
- const depth = typeof orchestrator.getConsoleExtractionQueueDepth === "function" ? orchestrator.getConsoleExtractionQueueDepth() : 0;
52
- const verdicts = typeof orchestrator.getConsoleExtractionRecentVerdicts === "function" ? orchestrator.getConsoleExtractionRecentVerdicts() : [];
53
- const recentVerdicts = (verdicts ?? []).slice(-MAX_VERDICT_TAIL).map((v) => ({
54
- ts: typeof v?.ts === "string" ? v.ts : "",
55
- kind: typeof v?.kind === "string" ? v.kind : "unknown",
56
- ...typeof v?.reason === "string" ? { reason: v.reason } : {}
57
- }));
58
- return { depth: Number.isFinite(depth) ? depth : 0, recentVerdicts };
59
- } catch (err) {
60
- errors.push(`extractionQueue: ${describeError(err)}`);
61
- return { depth: 0, recentVerdicts: [] };
62
- }
63
- }
64
- function readDedupRecent(orchestrator, errors) {
65
- try {
66
- if (typeof orchestrator.getConsoleDedupRecentDecisions !== "function") return [];
67
- const raw = orchestrator.getConsoleDedupRecentDecisions() ?? [];
68
- return raw.slice(-MAX_DEDUP_TAIL).map((d) => ({
69
- ts: typeof d?.ts === "string" ? d.ts : "",
70
- decision: typeof d?.decision === "string" ? d.decision : "unknown",
71
- ...typeof d?.fingerprint === "string" ? { fingerprint: d.fingerprint } : {},
72
- ...typeof d?.similarity === "number" && Number.isFinite(d.similarity) ? { similarity: d.similarity } : {}
73
- }));
74
- } catch (err) {
75
- errors.push(`dedupRecent: ${describeError(err)}`);
76
- return [];
77
- }
78
- }
79
- async function streamLedgerTopN(ledgerPath, topN, project) {
80
- let stream;
81
- try {
82
- await fs.stat(ledgerPath);
83
- } catch (err) {
84
- const code = err.code;
85
- if (code === "ENOENT") return [];
86
- throw err;
87
- }
88
- try {
89
- stream = createReadStream(ledgerPath, { encoding: "utf-8" });
90
- } catch (err) {
91
- const code = err.code;
92
- if (code === "ENOENT") return [];
93
- throw err;
94
- }
95
- const rl = createInterface({ input: stream, crlfDelay: Infinity });
96
- const cap = Math.max(1, topN) * 2;
97
- const buf = [];
98
- const truncate = () => {
99
- buf.sort((a, b) => {
100
- const aMs = Date.parse(a.ts);
101
- const bMs = Date.parse(b.ts);
102
- if (Number.isFinite(aMs) && Number.isFinite(bMs)) return bMs - aMs;
103
- if (Number.isFinite(aMs)) return -1;
104
- if (Number.isFinite(bMs)) return 1;
105
- return 0;
106
- });
107
- if (buf.length > topN) buf.length = topN;
108
- };
109
- try {
110
- for await (const line of rl) {
111
- const trimmed = line.trim();
112
- if (!trimmed) continue;
113
- let parsed;
114
- try {
115
- parsed = JSON.parse(trimmed);
116
- } catch {
117
- continue;
118
- }
119
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
120
- continue;
121
- }
122
- const event = project(parsed);
123
- if (event === null) continue;
124
- if (!event.ts || !Number.isFinite(Date.parse(event.ts))) continue;
125
- buf.push(event);
126
- if (buf.length >= cap) truncate();
127
- }
128
- } finally {
129
- rl.close();
130
- stream.close();
131
- }
132
- truncate();
133
- return buf.reverse();
134
- }
135
- function projectLedgerRow(p) {
136
- const ts = typeof p.ts === "string" && p.ts.length > 0 ? p.ts : typeof p.hour === "string" && p.hour.length > 0 ? p.hour : typeof p.rebuiltAt === "string" && p.rebuiltAt.length > 0 ? p.rebuiltAt : "";
137
- const category = typeof p.category === "string" && p.category.length > 0 ? p.category : typeof p.verdictKind === "string" ? "judge-verdict" : typeof p.turnCount === "number" ? "observation" : "unknown";
138
- const summary = summarizeLedgerEvent(p);
139
- return { ts, category, summary };
140
- }
141
- async function readMaintenanceLedgerTail(orchestrator, errors) {
142
- try {
143
- const memoryDir = orchestrator.config?.memoryDir;
144
- if (!memoryDir || typeof memoryDir !== "string") return [];
145
- const ledgerDir = path.join(memoryDir, "state", "observation-ledger");
146
- const verdictsTopN = await streamLedgerTopN(
147
- path.join(ledgerDir, "extraction-judge-verdicts.jsonl"),
148
- MAX_LEDGER_TAIL,
149
- projectLedgerRow
150
- );
151
- const rebuiltTopN = await streamLedgerTopN(
152
- path.join(ledgerDir, "rebuilt-observations.jsonl"),
153
- MAX_LEDGER_TAIL,
154
- projectLedgerRow
155
- );
156
- const events = [...verdictsTopN, ...rebuiltTopN];
157
- if (events.length === 0) return [];
158
- events.sort((a, b) => {
159
- const aMs = Date.parse(a.ts);
160
- const bMs = Date.parse(b.ts);
161
- if (Number.isFinite(aMs) && Number.isFinite(bMs)) return bMs - aMs;
162
- if (Number.isFinite(aMs)) return -1;
163
- if (Number.isFinite(bMs)) return 1;
164
- return 0;
165
- });
166
- const tail = events.slice(0, MAX_LEDGER_TAIL);
167
- return tail.reverse();
168
- } catch (err) {
169
- errors.push(`maintenanceLedgerTail: ${describeError(err)}`);
170
- return [];
171
- }
172
- }
173
- function summarizeLedgerEvent(p) {
174
- const parts = [];
175
- if (typeof p.verdictKind === "string") parts.push(`verdict=${p.verdictKind}`);
176
- if (typeof p.reason === "string" && p.reason.length > 0) {
177
- const trimmed = p.reason.length > 80 ? `${p.reason.slice(0, 80)}\u2026` : p.reason;
178
- parts.push(`reason=${trimmed}`);
179
- }
180
- if (typeof p.candidateCategory === "string") {
181
- parts.push(`cat=${p.candidateCategory}`);
182
- }
183
- if (typeof p.sessionKey === "string" && p.sessionKey.length > 0) {
184
- parts.push(`session=${p.sessionKey}`);
185
- }
186
- if (typeof p.turnCount === "number" && Number.isFinite(p.turnCount)) {
187
- parts.push(`turns=${p.turnCount}`);
188
- }
189
- if (typeof p.userTurns === "number" && Number.isFinite(p.userTurns)) {
190
- parts.push(`u=${p.userTurns}`);
191
- }
192
- if (typeof p.assistantTurns === "number" && Number.isFinite(p.assistantTurns)) {
193
- parts.push(`a=${p.assistantTurns}`);
194
- }
195
- if (parts.length === 0) {
196
- return typeof p.category === "string" ? p.category : "event";
197
- }
198
- return parts.join(" ");
199
- }
200
- function readQmdProbe(orchestrator, errors) {
201
- try {
202
- const qmd = orchestrator.qmd;
203
- if (!qmd) {
204
- return { available: false, daemonMode: false, debug: "qmd unavailable" };
205
- }
206
- const available = typeof qmd.isAvailable === "function" ? qmd.isAvailable() : false;
207
- const daemonMode = typeof qmd.isDaemonMode === "function" ? qmd.isDaemonMode() : false;
208
- const debug = typeof qmd.debugStatus === "function" ? qmd.debugStatus() : "";
209
- return { available, daemonMode, debug };
210
- } catch (err) {
211
- errors.push(`qmdProbe: ${describeError(err)}`);
212
- return { available: false, daemonMode: false, debug: "" };
213
- }
214
- }
215
- function readDaemonInfo(orchestrator, errors) {
216
- try {
217
- if (typeof orchestrator.getConsoleDaemonInfo === "function") {
218
- const info = orchestrator.getConsoleDaemonInfo();
219
- return {
220
- uptimeMs: Number.isFinite(info?.uptimeMs) ? info.uptimeMs : 0,
221
- version: typeof info?.version === "string" ? info.version : "unknown"
222
- };
223
- }
224
- const uptimeMs = Math.round((process.uptime?.() ?? 0) * 1e3);
225
- return { uptimeMs, version: resolvePackageVersion() };
226
- } catch (err) {
227
- errors.push(`daemon: ${describeError(err)}`);
228
- return { uptimeMs: 0, version: "unknown" };
229
- }
230
- }
231
- function resolvePackageVersion() {
232
- try {
233
- const env = process.env?.REMNIC_VERSION;
234
- if (typeof env === "string" && env.length > 0) return env;
235
- } catch {
236
- }
237
- return "unknown";
238
- }
239
- function describeError(err) {
240
- if (err instanceof Error) return err.message;
241
- try {
242
- return String(err);
243
- } catch {
244
- return "unknown error";
245
- }
246
- }
247
-
248
- export {
249
- gatherConsoleState
250
- };