@totalreclaw/totalreclaw 3.3.12-rc.2 → 3.3.12-rc.21

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 (87) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/SKILL.md +34 -249
  3. package/api-client.ts +17 -9
  4. package/batch-gate.ts +42 -0
  5. package/billing-cache.ts +25 -20
  6. package/claims-helper.ts +7 -1
  7. package/config.ts +54 -12
  8. package/consolidation.ts +6 -13
  9. package/contradiction-sync.ts +19 -14
  10. package/credential-provider.ts +184 -0
  11. package/crypto.ts +27 -160
  12. package/dist/api-client.js +17 -9
  13. package/dist/batch-gate.js +40 -0
  14. package/dist/billing-cache.js +19 -21
  15. package/dist/claims-helper.js +7 -1
  16. package/dist/config.js +54 -12
  17. package/dist/consolidation.js +6 -15
  18. package/dist/contradiction-sync.js +15 -15
  19. package/dist/credential-provider.js +145 -0
  20. package/dist/crypto.js +17 -137
  21. package/dist/download-ux.js +11 -7
  22. package/dist/embedder-loader.js +266 -0
  23. package/dist/embedding.js +36 -3
  24. package/dist/entry.js +123 -0
  25. package/dist/extractor.js +134 -0
  26. package/dist/fs-helpers.js +116 -241
  27. package/dist/import-adapters/chatgpt-adapter.js +14 -0
  28. package/dist/import-adapters/claude-adapter.js +14 -0
  29. package/dist/import-adapters/gemini-adapter.js +43 -159
  30. package/dist/import-adapters/mcp-memory-adapter.js +14 -0
  31. package/dist/import-state-manager.js +100 -0
  32. package/dist/index.js +1130 -2520
  33. package/dist/llm-client.js +69 -1
  34. package/dist/memory-runtime.js +459 -0
  35. package/dist/native-memory.js +123 -0
  36. package/dist/onboarding-cli.js +3 -2
  37. package/dist/pair-cli.js +1 -1
  38. package/dist/pair-crypto.js +16 -358
  39. package/dist/pair-http.js +147 -4
  40. package/dist/relay.js +140 -0
  41. package/dist/reranker.js +13 -8
  42. package/dist/semantic-dedup.js +5 -7
  43. package/dist/skill-register.js +97 -0
  44. package/dist/subgraph-search.js +3 -1
  45. package/dist/subgraph-store.js +315 -282
  46. package/dist/tool-gating.js +39 -26
  47. package/dist/tools.js +367 -0
  48. package/dist/tr-cli-export-helper.js +103 -0
  49. package/dist/tr-cli.js +220 -127
  50. package/dist/trajectory-poller.js +155 -9
  51. package/dist/vault-crypto.js +551 -0
  52. package/download-ux.ts +12 -6
  53. package/embedder-loader.ts +293 -1
  54. package/embedding.ts +43 -3
  55. package/entry.ts +132 -0
  56. package/extractor.ts +167 -0
  57. package/fs-helpers.ts +166 -292
  58. package/import-adapters/chatgpt-adapter.ts +18 -0
  59. package/import-adapters/claude-adapter.ts +18 -0
  60. package/import-adapters/gemini-adapter.ts +56 -183
  61. package/import-adapters/mcp-memory-adapter.ts +18 -0
  62. package/import-adapters/types.ts +1 -1
  63. package/import-state-manager.ts +139 -0
  64. package/index.ts +1432 -3002
  65. package/llm-client.ts +74 -1
  66. package/memory-runtime.ts +723 -0
  67. package/native-memory.ts +196 -0
  68. package/onboarding-cli.ts +3 -2
  69. package/openclaw.plugin.json +5 -17
  70. package/package.json +7 -4
  71. package/pair-cli.ts +1 -1
  72. package/pair-crypto.ts +41 -483
  73. package/pair-http.ts +194 -5
  74. package/postinstall.mjs +138 -0
  75. package/relay.ts +172 -0
  76. package/reranker.ts +13 -8
  77. package/semantic-dedup.ts +5 -6
  78. package/skill-register.ts +146 -0
  79. package/skill.json +1 -1
  80. package/subgraph-search.ts +3 -1
  81. package/subgraph-store.ts +334 -299
  82. package/tool-gating.ts +39 -26
  83. package/tools.ts +499 -0
  84. package/tr-cli-export-helper.ts +138 -0
  85. package/tr-cli.ts +263 -133
  86. package/trajectory-poller.ts +162 -10
  87. package/vault-crypto.ts +705 -0
@@ -28,6 +28,7 @@
28
28
  */
29
29
  import fs from 'node:fs';
30
30
  import path from 'node:path';
31
+ import { envHomeDir } from './entry.js';
31
32
  // ---------------------------------------------------------------------------
32
33
  // MEMORY.md header ensure
33
34
  // ---------------------------------------------------------------------------
@@ -82,8 +83,7 @@ export function ensureMemoryHeaderFile(workspace, header, markerSubstring = 'Tot
82
83
  * covers the OpenClaw plugin sandbox case where the loaded module
83
84
  * lives at `<pluginRoot>/dist/index.js` while `package.json` lives
84
85
  * at `<pluginRoot>/package.json` (3.3.4-rc.1 fix — without this
85
- * walk-up, the `.loaded.json` manifest gets `version=unknown` and
86
- * all RC-gated logic that depends on the version string fails
86
+ * walk-up, version-dependent logic gets `version=unknown` and fails
87
87
  * silently in production OpenClaw deployments).
88
88
  * - Returns the `version` field, or `null` on any I/O / parse error.
89
89
  *
@@ -471,157 +471,15 @@ export function wipePartialInstall(pluginRootDir) {
471
471
  }
472
472
  }
473
473
  // ---------------------------------------------------------------------------
474
- // Plugin load manifest (.loaded.json / .error.json) — 3.3.2-rc.1 #186
474
+ // Plugin load manifest (.loaded.json / .error.json) — RETIRED Phase 3.4
475
475
  // ---------------------------------------------------------------------------
476
- /**
477
- * Filenames written into the plugin root dir at the end of register() and
478
- * (on failure) from the surrounding try/catch. The presence of `.loaded.json`
479
- * is the canonical filesystem signal that the plugin's register() body ran
480
- * to completion AND the SDK tool/route/hook registries received calls.
481
- *
482
- * Acceptance criteria (issue #186):
483
- * - `cat ~/.openclaw/extensions/totalreclaw/.loaded.json` shows
484
- * `{loadedAt, tools, version}` after every successful gateway start.
485
- * - `cat ~/.openclaw/extensions/totalreclaw/.error.json` shows
486
- * `{loadedAt, error, stack}` if register() threw.
487
- * - Both are overwritten on each register() call so the agent can rely
488
- * on the timestamp matching the most recent gateway start.
489
- *
490
- * Why these MUST be synchronous writes (same constraint as
491
- * `registerHttpRoute` per the comment in index.ts around the route
492
- * registration site): the SDK loader treats register() returning as the
493
- * signal to freeze the registries. An async `fs.promises.writeFile` would
494
- * settle one microtask AFTER the loader has moved on, so the manifest
495
- * could miss tools that registered late OR drop entirely if the gateway
496
- * exits before the microtask runs. `writeFileSync` is the only safe choice.
497
- */
498
- export const PLUGIN_LOADED_MANIFEST = '.loaded.json';
499
- export const PLUGIN_ERROR_MANIFEST = '.error.json';
500
- /**
501
- * Resolve the plugin root dir from the loaded module's directory. The plugin
502
- * is shipped with `dist/index.js` as the entry, so `import.meta.url` resolves
503
- * to `<root>/dist/`. We walk up one level to put the manifests next to
504
- * `package.json`. Defensive: if the caller already passed the root (no
505
- * trailing `dist`), we still return a sensible path.
506
- */
507
- function resolvePluginRootForManifest(pluginDir) {
508
- const base = path.basename(pluginDir);
509
- return base === 'dist' ? path.resolve(pluginDir, '..') : pluginDir;
510
- }
511
- /**
512
- * Write the success manifest. SYNCHRONOUS — the SDK freezes the plugin
513
- * registries the moment register() returns; `fs.promises.writeFile` would
514
- * race that freeze and the manifest could miss late tool registrations or
515
- * never land at all if the process exits before the microtask runs.
516
- *
517
- * Best-effort: returns `true` on success, `false` on any I/O error. Never
518
- * throws — failing to write the manifest is a diagnostic loss, not a
519
- * correctness loss, so we don't propagate.
520
- *
521
- * The manifest is written at mode 0644 (world-readable). It contains no
522
- * secrets — only a timestamp, the (publicly known) tool names, and the
523
- * plugin version. Cleared first so a stale `.error.json` from a previous
524
- * failed boot doesn't survive a successful boot.
525
- */
526
- /**
527
- * Read the existing `.loaded.json` manifest for diagnostic surfaces
528
- * (3.3.7-rc.1 — issue #216). Returns `null` if the manifest is
529
- * missing, unreadable, or malformed. Best-effort: never throws.
530
- *
531
- * Scanner note: this helper lives in fs-helpers.ts (where all fs.*
532
- * operations are consolidated) so the diagnostic slash command in
533
- * `index.ts` doesn't have to introduce a fresh `readFileSync` call —
534
- * the OpenClaw scanner whole-file rule disallows fs.read* next to the
535
- * outbound-request trigger markers that index.ts already has in its
536
- * on-chain submission code paths.
537
- */
538
- export function readPluginLoadedManifest(pluginDir) {
539
- try {
540
- const root = resolvePluginRootForManifest(pluginDir);
541
- const loadedPath = path.join(root, PLUGIN_LOADED_MANIFEST);
542
- if (!fs.existsSync(loadedPath))
543
- return null;
544
- const raw = fs.readFileSync(loadedPath, 'utf-8');
545
- const parsed = JSON.parse(raw);
546
- if (typeof parsed.loadedAt !== 'number' || !Array.isArray(parsed.tools) || typeof parsed.version !== 'string') {
547
- return null;
548
- }
549
- return parsed;
550
- }
551
- catch {
552
- return null;
553
- }
554
- }
555
- export function writePluginManifest(pluginDir, manifest) {
556
- try {
557
- const root = resolvePluginRootForManifest(pluginDir);
558
- if (!fs.existsSync(root))
559
- return false;
560
- const loadedPath = path.join(root, PLUGIN_LOADED_MANIFEST);
561
- const errorPath = path.join(root, PLUGIN_ERROR_MANIFEST);
562
- // Best-effort error-file cleanup — a successful boot supersedes any
563
- // prior failure marker. If the unlink fails (e.g. permission), the
564
- // .loaded.json timestamp still tells the agent which is current.
565
- try {
566
- if (fs.existsSync(errorPath))
567
- fs.unlinkSync(errorPath);
568
- }
569
- catch {
570
- // Swallow — best-effort.
571
- }
572
- // 3.3.7-rc.1 (issue #216) — derive bootCount by reading the prior
573
- // manifest. Lets the user grep `.loaded.json` after a container
574
- // restart to verify register() actually ran. If the prior manifest
575
- // is unreadable we start at 1.
576
- let priorBootCount = 0;
577
- try {
578
- if (fs.existsSync(loadedPath)) {
579
- const prior = JSON.parse(fs.readFileSync(loadedPath, 'utf-8'));
580
- if (typeof prior.bootCount === 'number' && Number.isFinite(prior.bootCount)) {
581
- priorBootCount = prior.bootCount;
582
- }
583
- }
584
- }
585
- catch {
586
- // Swallow — if the prior manifest is corrupt we just start the counter fresh.
587
- }
588
- const enriched = {
589
- ...manifest,
590
- bootCount: priorBootCount + 1,
591
- bootAt: new Date(manifest.loadedAt).toISOString(),
592
- pid: process.pid,
593
- };
594
- fs.writeFileSync(loadedPath, JSON.stringify(enriched, null, 2));
595
- return true;
596
- }
597
- catch {
598
- return false;
599
- }
600
- }
601
- /**
602
- * Write the error manifest. SYNCHRONOUS for the same reason as
603
- * `writePluginManifest`. Called from the try/catch surrounding the
604
- * register() body so the agent has a filesystem signal that the plugin
605
- * registered AT LEAST attempted to load and failed in a specific way.
606
- *
607
- * Does NOT clear `.loaded.json` from a prior successful boot — keeping
608
- * the older success marker around lets the agent see "last good boot was
609
- * X, current boot failed at Y" without spelunking logs. The newer
610
- * `.error.json` timestamp wins as "current state".
611
- */
612
- export function writePluginError(pluginDir, error) {
613
- try {
614
- const root = resolvePluginRootForManifest(pluginDir);
615
- if (!fs.existsSync(root))
616
- return false;
617
- const errorPath = path.join(root, PLUGIN_ERROR_MANIFEST);
618
- fs.writeFileSync(errorPath, JSON.stringify(error, null, 2));
619
- return true;
620
- }
621
- catch {
622
- return false;
623
- }
624
- }
476
+ // The 3.3.2-rc.1 `.loaded.json` / `.error.json` manifest machinery (writer
477
+ // + reader + schema) was fully removed in Phase 3.4. Phase 3.1 already
478
+ // dropped the `writePluginManifest` call from register(); 3.4 retires the
479
+ // remaining reader (`readPluginLoadedManifest`) + the error-path writer
480
+ // (`writePluginError`) + the schema types now that no production path
481
+ // references them. The gateway log is the source of truth for register()
482
+ // failures; `/totalreclaw diag` reports pid + in-memory version only.
625
483
  /**
626
484
  * Drop the `.tr-partial-install` marker into `pluginRootDir`. Idempotent
627
485
  * (overwrites any existing marker) and best-effort — returns `true` on
@@ -933,14 +791,11 @@ export function resolveOnboardingState(credentialsPath, statePath) {
933
791
  * Auto-patch `~/.openclaw/openclaw.json` with the entries required by
934
792
  * OpenClaw 2026.5.x for clean operation (issues #225 + #226 + verbosity):
935
793
  *
936
- * 1. `plugins.slots.memory = "totalreclaw"` (gated on install record)
937
- * Claim the memory slot so the plugin loads instead of deferring to
938
- * the built-in `memory-core` tenant. As of 3.3.9-rc.4 this fix is
939
- * gated on `plugins.installs.totalreclaw.version` being present
940
- * writing the slot without an install record produces a startup
941
- * crash loop ("plugins.slots.memory: plugin not found: totalreclaw")
942
- * that survives container restarts until `openclaw plugins install`
943
- * repopulates the install record.
794
+ * NOTE (rc.20, #402): this helper no longer writes `plugins.slots.memory`
795
+ * (OpenClaw 2026.6.8 claims the memory slot natively on install/enable) nor
796
+ * `plugins.installs` (the former Fix #6 self-heal its record reader
797
+ * discards the whole installs map if any entry fails schema validation).
798
+ * Pre-existing values of both are left untouched. The remaining fixes are:
944
799
  *
945
800
  * 2. `plugins.entries.totalreclaw.hooks.allowConversationAccess = true`
946
801
  * Grant the plugin access to `agent_end` and `before_agent_start`
@@ -954,15 +809,11 @@ export function resolveOnboardingState(credentialsPath, statePath) {
954
809
  * this to "off" on first run for a clean UX. Existing explicit values
955
810
  * ("partial", "block", "progress") are preserved.
956
811
  *
957
- * 4. `plugins.bundledDiscovery = "compat"` (only if unset, and only when
958
- * `plugins.allow` is populated). When `plugins.allow` is a non-empty
959
- * array, OpenClaw 2026.5.x switches the loader into strict-allowlist
960
- * mode and silently rejects non-bundled plugins like totalreclaw
961
- * EVEN IF they are listed in the allow array. Setting
962
- * `bundledDiscovery: "compat"` restores the looser behavior so allow-
963
- * listed non-bundled plugins load. Without this fix, users with
964
- * telegram or any model provider configured before TR install (which
965
- * populates allow) get a silent plugin-skip on every gateway boot.
812
+ * Fix #4 (`plugins.bundledDiscovery="compat"`) and Fix #5 (appending
813
+ * "totalreclaw" to `plugins.allow`) were RETIRED together in rc.20 (#402):
814
+ * native install manages the allowlist, and TR growing it was the only
815
+ * thing that forced strict-allowlist mode (the sole reason the compat
816
+ * workaround existed). Pre-existing values of both keys are left untouched.
966
817
  *
967
818
  * Design constraints
968
819
  * ------------------
@@ -984,8 +835,11 @@ export function resolveOnboardingState(credentialsPath, statePath) {
984
835
  * @param configPath Absolute path to `openclaw.json`.
985
836
  * Defaults to `<home>/.openclaw/openclaw.json`.
986
837
  */
987
- export function patchOpenClawConfig(configPath) {
988
- const home = process.env.HOME ?? '/home/node';
838
+ export function patchOpenClawConfig(configPath,
839
+ // Retained on the signature (register() passes it) but no longer consumed:
840
+ // the Fix #6 install-record self-heal it fed was retired in rc.20 (#402).
841
+ pluginVersion) {
842
+ const home = envHomeDir();
989
843
  const target = configPath ?? path.join(home, '.openclaw', 'openclaw.json');
990
844
  // `'skipped'` when the config file is absent — this host may not be
991
845
  // running OpenClaw, or may use a non-standard config location.
@@ -1000,50 +854,44 @@ export function patchOpenClawConfig(configPath) {
1000
854
  cfg.plugins = {};
1001
855
  }
1002
856
  let mutated = false;
1003
- // --- Fix #1: plugins.slots.memory = "totalreclaw" (gated on install) ---
1004
- //
1005
- // DEFENSIVE GATE (3.3.9-rc.4 — 2026-05-05): only write the slot when
1006
- // the plugin is genuinely INSTALLED (`plugins.installs.totalreclaw`
1007
- // present with a `version`). Writing the slot unconditionally
1008
- // produced a startup crash loop on Pedro's pop-os QA host on
1009
- // 2026-05-05 — after a config reset, `plugins.installs.totalreclaw`
1010
- // was missing but a previously-written `slots.memory = "totalreclaw"`
1011
- // had survived. OpenClaw's startup validator refuses to start with
857
+ // --- Fix #6 (installs self-heal) RETIRED in rc.20 (#402) ---
1012
858
  //
1013
- // Gateway failed to start: Error: Invalid config at openclaw.json.
1014
- // plugins.slots.memory: plugin not found: totalreclaw
1015
- // Run "openclaw doctor --fix" to repair, then retry.
859
+ // patchOpenClawConfig used to fabricate a `plugins.installs.totalreclaw`
860
+ // record (version/spec/source:"self-heal"/installedAt) whenever a version
861
+ // was passed and no record existed. Removed because it was inert at best
862
+ // and harmful at worst on OpenClaw 2026.6.8:
863
+ // (a) the record reader validates the WHOLE installs map against a
864
+ // schema where `source` must be a valid PluginInstallSource — the
865
+ // fabricated `source:"self-heal"` (and any source-less record) fails
866
+ // safeParse, discarding the ENTIRE installs map at load; and
867
+ // (b) the native installer never persists install records into
868
+ // openclaw.json (it strips them via withoutPluginInstallRecords and
869
+ // commits to the SQLite index, which always wins on merge).
870
+ // So the plugin no longer writes `plugins.installs` at all; a pre-existing
871
+ // record is left byte-identical. `pluginVersion` is retained on the
872
+ // signature (register() passes it) but is no longer consumed here.
873
+ void pluginVersion;
874
+ // --- Fix #5 (plugins.allow self-append) RETIRED in rc.20 (#402) ---
1016
875
  //
1017
- // The container restart-loop drained ~13 attempts (12:10-12:23 UTC)
1018
- // until `openclaw plugins install` was re-run and re-populated
1019
- // `plugins.installs.totalreclaw`. With this gate, future installs
1020
- // that wipe `plugins.installs` (config reset, `doctor --fix`,
1021
- // migration tools) cannot regress into the same boot loop — slot is
1022
- // only ever written when the install record exists, and the install
1023
- // record is the install pipeline's authoritative signal that the
1024
- // plugin is on disk and registered with the gateway.
876
+ // patchOpenClawConfig used to append "totalreclaw" to a non-empty
877
+ // `plugins.allow`. Removed as a pair with Fix #4 (below): OpenClaw's native
878
+ // `persistPluginInstall` already calls `addInstalledPluginToAllowlist`, and
879
+ // an empty/absent allowlist means allow-all (no write needed). TR
880
+ // unconditionally growing an allowlist was the very thing that flipped
881
+ // hosts into strict-allowlist enforcement which then required the Fix #4
882
+ // `bundledDiscovery:"compat"` workaround. Dropping both lets native install
883
+ // own the allowlist; existing hosts keep whatever is already on disk.
884
+ // --- Fix #1 (memory-slot write) RETIRED in rc.20 (#402) ---
1025
885
  //
1026
- // The hooks patch (Fix #2) and Telegram streaming patch (Fix #3) are
1027
- // not gated this way they write under `plugins.entries` and
1028
- // `channels` which are inert without an install record, so they can
1029
- // never trip the validator.
1030
- const installsRoot = cfg.plugins.installs;
1031
- const installEntry = typeof installsRoot === 'object' && installsRoot !== null
1032
- ? installsRoot.totalreclaw
1033
- : undefined;
1034
- const pluginIsInstalled = typeof installEntry === 'object'
1035
- && installEntry !== null
1036
- && typeof installEntry.version === 'string'
1037
- && installEntry.version.length > 0;
1038
- if (pluginIsInstalled) {
1039
- if (typeof cfg.plugins.slots !== 'object' || cfg.plugins.slots === null) {
1040
- cfg.plugins.slots = {};
1041
- }
1042
- if (cfg.plugins.slots.memory !== 'totalreclaw') {
1043
- cfg.plugins.slots.memory = 'totalreclaw';
1044
- mutated = true;
1045
- }
1046
- }
886
+ // patchOpenClawConfig used to write `plugins.slots.memory = "totalreclaw"`
887
+ // (install-gated, to dodge a startup crash loop). OpenClaw 2026.6.8 now
888
+ // claims the memory slot NATIVELY during `plugins install`/`enable` (its
889
+ // persistPluginInstall "slot selection" phase), so the hand-written write
890
+ // was redundant on the good path and twice failed in production. The
891
+ // plugin no longer touches the memory slot a pre-existing value is left
892
+ // byte-identical. Fix numbering below is preserved for continuity with the
893
+ // #225/#226 history. The Fix #6 install-record self-heal was retired
894
+ // above too (rc.20, #402).
1047
895
  // --- Fix #2: plugins.entries.totalreclaw.hooks.allowConversationAccess = true ---
1048
896
  if (typeof cfg.plugins.entries !== 'object' || cfg.plugins.entries === null) {
1049
897
  cfg.plugins.entries = {};
@@ -1086,36 +934,15 @@ export function patchOpenClawConfig(configPath) {
1086
934
  }
1087
935
  }
1088
936
  }
1089
- // --- Fix #4: plugins.bundledDiscovery = "compat" (3.3.11-rc.4) ---
1090
- //
1091
- // OpenClaw 2026.5.x: when `plugins.allow` is populated (any non-empty
1092
- // array), the gateway's plugin loader switches into strict-allowlist
1093
- // mode. In strict mode, NON-BUNDLED plugins like totalreclaw are
1094
- // silently rejected even when listed in `plugins.allow`, unless
1095
- // `plugins.bundledDiscovery = "compat"` is explicitly set. Pedro's
1096
- // 2026-05-07 QA on pop-os surfaced this — the gateway booted with only
1097
- // the bundled providers (telegram, device-pair) and skipped totalreclaw
1098
- // despite it being in the allow list. `openclaw doctor --fix` cures it
1099
- // by setting `bundledDiscovery: "compat"`, but users shouldn't need
1100
- // to run doctor manually for the plugin to load.
1101
- //
1102
- // Fix: when `plugins.allow` is a non-empty array AND
1103
- // `plugins.bundledDiscovery` is unset, set it to "compat". If the user
1104
- // explicitly chose "allowlist" (the stricter mode), preserve their
1105
- // choice — only first-run defaults are touched.
937
+ // --- Fix #4 (plugins.bundledDiscovery="compat") RETIRED in rc.20 (#402) ---
1106
938
  //
1107
- // This bug was missed by the auto-QA harness because the harness ran
1108
- // on a fresh canonical container with `plugins.allow=null`, hitting
1109
- // the auto-discover code path. Real users with telegram + a model
1110
- // provider configured before TR install have a populated allow list,
1111
- // hitting the strict-mode path. The auto-QA harness in 3.3.11-rc.4
1112
- // adds a populated-allow scenario to catch future regressions.
1113
- if (Array.isArray(cfg.plugins.allow) && cfg.plugins.allow.length > 0) {
1114
- if (cfg.plugins.bundledDiscovery === undefined) {
1115
- cfg.plugins.bundledDiscovery = 'compat';
1116
- mutated = true;
1117
- }
1118
- }
939
+ // patchOpenClawConfig used to set `plugins.bundledDiscovery = "compat"`
940
+ // whenever `plugins.allow` was populated, to keep non-bundled totalreclaw
941
+ // loadable under strict-allowlist mode. Retired as a pair with Fix #5: the
942
+ // ONLY reason a host was in strict-allowlist mode was that TR itself grew
943
+ // the allowlist (Fix #5). With Fix #5 gone, native install manages the
944
+ // allowlist and this compat workaround is unnecessary. An existing
945
+ // `bundledDiscovery` value on disk is left untouched.
1119
946
  if (!mutated)
1120
947
  return 'unchanged';
1121
948
  // Write back with 2-space indent to match OpenClaw's own write style.
@@ -1126,3 +953,51 @@ export function patchOpenClawConfig(configPath) {
1126
953
  return 'error';
1127
954
  }
1128
955
  }
956
+ const TMPFS_PREFIXES = ['/tmp/', '/dev/shm/', '/run/', '/var/run/'];
957
+ export function checkCredentialsFileMode(credPath, logger) {
958
+ let stat;
959
+ try {
960
+ stat = fs.statSync(credPath);
961
+ }
962
+ catch (err) {
963
+ const code = err.code;
964
+ if (code === 'ENOENT')
965
+ return 'ok';
966
+ logger.warn(`TotalReclaw: could not stat credentials file (${code ?? String(err)}); skipping permission check`);
967
+ return 'stat_error';
968
+ }
969
+ const mode = stat.mode & 0o777;
970
+ if (mode > 0o600) {
971
+ const modeStr = '0' + mode.toString(8);
972
+ logger.error(`TotalReclaw: STARTUP REFUSED — credentials file has insecure permissions (${modeStr}).\n` +
973
+ ` File: ${credPath}\n` +
974
+ ` Fix: chmod 600 "${credPath}"\n` +
975
+ ` Then restart your OpenClaw gateway.\n` +
976
+ ` Current mode ${modeStr} allows other OS users to read your recovery phrase.`);
977
+ return 'insecure';
978
+ }
979
+ try {
980
+ const real = fs.realpathSync(credPath);
981
+ for (const prefix of TMPFS_PREFIXES) {
982
+ if (real.startsWith(prefix)) {
983
+ logger.warn(`TotalReclaw: credentials file is on a volatile/shared path (${real}). ` +
984
+ `It may be lost on reboot or be readable by other processes. ` +
985
+ `Consider moving it to a persistent private directory and updating TOTALRECLAW_CREDENTIALS_PATH.`);
986
+ return 'warned';
987
+ }
988
+ }
989
+ }
990
+ catch {
991
+ // realpathSync can fail on unusual mounts — not actionable here
992
+ }
993
+ return 'ok';
994
+ }
995
+ // ---------------------------------------------------------------------------
996
+ // Pair-pending sentinel — RETIRED Phase 3.4
997
+ // ---------------------------------------------------------------------------
998
+ // The 3.3.13 `~/.totalreclaw/.pair-pending.json` sentinel + its utilities
999
+ // (loadPairPendingFile / writePairPendingFile / deletePairPendingFile /
1000
+ // defaultPairPendingPath / PairPendingFile) were removed in Phase 3.4.
1001
+ // Pairing is now user-initiated QR (`tr pair` CLI / the pair HTTP route)
1002
+ // per the native-integration design — the auto-pair-on-load state machine
1003
+ // that wrote + consumed this sentinel is gone.
@@ -17,6 +17,20 @@ export class ChatGPTAdapter extends BaseImportAdapter {
17
17
  else if (input.file_path) {
18
18
  try {
19
19
  const resolvedPath = input.file_path.replace(/^~/, os.homedir());
20
+ const fileStat = fs.statSync(resolvedPath);
21
+ const fileSizeMB = fileStat.size / (1024 * 1024);
22
+ if (fileSizeMB > 500) {
23
+ errors.push(`File is too large to import: ${fileSizeMB.toFixed(1)}MB exceeds the 500MB cap. ` +
24
+ 'Split the file into smaller chunks and import each separately.');
25
+ return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
26
+ }
27
+ const freeMem = os.freemem();
28
+ if (freeMem < fileStat.size * 2) {
29
+ errors.push(`Not enough free memory: ${(freeMem / (1024 * 1024)).toFixed(0)}MB available, ` +
30
+ `~${Math.ceil(fileStat.size * 2 / (1024 * 1024))}MB needed (2× file size). ` +
31
+ 'Close other applications or split the file.');
32
+ return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
33
+ }
20
34
  content = fs.readFileSync(resolvedPath, 'utf-8');
21
35
  }
22
36
  catch (e) {
@@ -29,6 +29,20 @@ export class ClaudeAdapter extends BaseImportAdapter {
29
29
  else if (input.file_path) {
30
30
  try {
31
31
  const resolvedPath = input.file_path.replace(/^~/, os.homedir());
32
+ const fileStat = fs.statSync(resolvedPath);
33
+ const fileSizeMB = fileStat.size / (1024 * 1024);
34
+ if (fileSizeMB > 500) {
35
+ errors.push(`File is too large to import: ${fileSizeMB.toFixed(1)}MB exceeds the 500MB cap. ` +
36
+ 'Split the file into smaller chunks and import each separately.');
37
+ return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
38
+ }
39
+ const freeMem = os.freemem();
40
+ if (freeMem < fileStat.size * 2) {
41
+ errors.push(`Not enough free memory: ${(freeMem / (1024 * 1024)).toFixed(0)}MB available, ` +
42
+ `~${Math.ceil(fileStat.size * 2 / (1024 * 1024))}MB needed (2× file size). ` +
43
+ 'Close other applications or split the file.');
44
+ return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
45
+ }
32
46
  content = fs.readFileSync(resolvedPath, 'utf-8');
33
47
  }
34
48
  catch (e) {