@cleocode/cleo 2026.11.16 → 2026.11.17
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/dist/.source-stamp.json +1 -1
- package/dist/cli/{adapter-NQCRE5BJ.js → adapter-5MDCOYGC.js} +3 -3
- package/dist/cli/{add-KVSL4VBU.js → add-O74GFCW4.js} +3 -3
- package/dist/cli/{add-batch-6EJG6UNX.js → add-batch-27TFCIOS.js} +3 -3
- package/dist/cli/{admin-YX62OLYC.js → admin-H2YMRZ2U.js} +3 -3
- package/dist/cli/{admin-PFRGBD5A.js → admin-V2E56CI6.js} +3 -3
- package/dist/cli/{adr-ZIBTTX7Z.js → adr-PRKE6GWP.js} +3 -3
- package/dist/cli/{analyze-ON4OEPDL.js → analyze-TLF7PMOF.js} +3 -3
- package/dist/cli/{archive-ERYQ2FIA.js → archive-5W6MWOHW.js} +3 -3
- package/dist/cli/{archive-stats-SR6TEUWK.js → archive-stats-H53C4UTQ.js} +3 -3
- package/dist/cli/{attention-7QG5ZBTR.js → attention-6QLUR2V5.js} +3 -3
- package/dist/cli/{backup-H6ZZQQ2N.js → backup-4RLHQ7GY.js} +3 -3
- package/dist/cli/{blockers-NPJJSZBY.js → blockers-LWYKTZFY.js} +3 -3
- package/dist/cli/{briefing-3FYOUG64.js → briefing-BDKQA7KW.js} +3 -3
- package/dist/cli/{cancel-HZOTQ4BE.js → cancel-KGN5HAMK.js} +3 -3
- package/dist/cli/{canon-VWCVTFZJ.js → canon-OV5OCASC.js} +18 -1
- package/dist/cli/{cant-3U56IQVJ.js → cant-7453H4YN.js} +5 -2
- package/dist/cli/{check-IIHHVNFI.js → check-A55P2PPJ.js} +3 -3
- package/dist/cli/{check-OLGR5CWG.js → check-XL6T762F.js} +9 -3
- package/dist/cli/{chunk-XP6SX2L3.js → chunk-7QKKXIZO.js} +2 -2
- package/dist/cli/{chunk-ERH4Y5NP.js → chunk-EPTA6JOP.js} +2 -2
- package/dist/cli/{chunk-YOHU4YZR.js → chunk-NW4SOMJC.js} +11 -11
- package/dist/cli/{claim-CMOHFSIP.js → claim-QPQVZFBD.js} +3 -3
- package/dist/cli/{cli-22I3TVQ6.js → cli-AC55E53F.js} +3 -3
- package/dist/cli/{code-RIM7SERA.js → code-CI5QHQPT.js} +2 -2
- package/dist/cli/{complete-OEKCLG3T.js → complete-FKOOFSXS.js} +4 -4
- package/dist/cli/{complexity-53ITDIUI.js → complexity-AWHB37LL.js} +3 -3
- package/dist/cli/{compliance-RDNPKCQ6.js → compliance-GPE7DQIN.js} +3 -3
- package/dist/cli/{config-ITVFMHU5.js → config-NVSCHUVO.js} +3 -3
- package/dist/cli/{consensus-2WSZWPYO.js → consensus-UJOGM2HY.js} +3 -3
- package/dist/cli/{context-WFCFYPJJ.js → context-5LTEY2FN.js} +3 -3
- package/dist/cli/{contribution-RUHPS6FX.js → contribution-LNETN2N2.js} +3 -3
- package/dist/cli/{current-YZ7CGXGT.js → current-4AB4DCP5.js} +3 -3
- package/dist/cli/{daemon-Y5DNGCZZ.js → daemon-5DG4O6RM.js} +3 -3
- package/dist/cli/{dash-SCN7JLBT.js → dash-DKIZBQQE.js} +3 -3
- package/dist/cli/{decompose-NL6F4MBK.js → decompose-YIPLA2KW.js} +3 -3
- package/dist/cli/{decomposition-MD7RHPVV.js → decomposition-NCLNGSYK.js} +3 -3
- package/dist/cli/{delete-A4PTOYQM.js → delete-HCWTH33S.js} +3 -3
- package/dist/cli/{deps-RO4UFLT4.js → deps-G4WH2JHF.js} +3 -3
- package/dist/cli/{detect-L32DK3YN.js → detect-U3FHF7SX.js} +3 -3
- package/dist/cli/{diagnostics-466CWMWE.js → diagnostics-KSP3VSRL.js} +3 -3
- package/dist/cli/{docs-55IQUSXO.js → docs-D74A2C27.js} +2 -2
- package/dist/cli/{docs-WVUFA6BC.js → docs-XCBYSR44.js} +3 -3
- package/dist/cli/{doctor-U7MMUBCQ.js → doctor-QAYWB4LS.js} +3 -3
- package/dist/cli/{done-QVKUCDLN.js → done-BY5AGPQK.js} +4 -4
- package/dist/cli/{export-M2YLRHYD.js → export-US54C7K4.js} +3 -3
- package/dist/cli/{export-tasks-NX3ZBHTR.js → export-tasks-S3HBJJLL.js} +3 -3
- package/dist/cli/{find-PJAXF3TJ.js → find-GI2N4W4C.js} +3 -3
- package/dist/cli/{focus-DRLQTYOQ.js → focus-MBLPBCZP.js} +3 -3
- package/dist/cli/{goal-L23JAJW7.js → goal-B2LOBNAJ.js} +2 -2
- package/dist/cli/{grade-4VRPZKBR.js → grade-N5FOIT77.js} +3 -3
- package/dist/cli/{graph-6AIDY77E.js → graph-OK6YOP42.js} +3 -3
- package/dist/cli/{history-AVZMXXLB.js → history-LJFEFQSM.js} +3 -3
- package/dist/cli/{import-W2OHHAQF.js → import-UB3X43WG.js} +3 -3
- package/dist/cli/{import-tasks-GR4JMDUA.js → import-tasks-KK5JSORJ.js} +3 -3
- package/dist/cli/index.js +114 -102
- package/dist/cli/{inject-ECLIOBLL.js → inject-5ZW5MWK2.js} +3 -3
- package/dist/cli/{intelligence-ZLZ5PFOT.js → intelligence-MBHCYI37.js} +3 -3
- package/dist/cli/{issue-R45TQM5S.js → issue-IFJ2L66E.js} +3 -3
- package/dist/cli/{labels-4ZXIF4AO.js → labels-AUKNPHK2.js} +3 -3
- package/dist/cli/{lifecycle-SS7QFB25.js → lifecycle-UDVHA3GI.js} +3 -3
- package/dist/cli/{list-E45WPC5Y.js → list-ZRSNR4ZT.js} +3 -3
- package/dist/cli/{llm-GJTUSLTS.js → llm-C33IPUZ2.js} +3 -3
- package/dist/cli/{log-XZM76MD2.js → log-WN5Y7YUC.js} +3 -3
- package/dist/cli/{manifest-GNOSRSG5.js → manifest-WQR2MMB4.js} +3 -3
- package/dist/cli/{map-JBELMD75.js → map-6J7HTDDB.js} +3 -3
- package/dist/cli/{memory-BMU4S4Z6.js → memory-5UCRVX2D.js} +3 -3
- package/dist/cli/{memory-GTXFS3CF.js → memory-TQDJULUR.js} +2 -2
- package/dist/cli/{migrate-claude-mem-WVCWM7C3.js → migrate-claude-mem-5LS5ZC4B.js} +3 -3
- package/dist/cli/{next-FR4LSYXV.js → next-4W2VCBLK.js} +3 -3
- package/dist/cli/{nexus-BVHBCN7P.js → nexus-MJAM5QKA.js} +2 -2
- package/dist/cli/{nexus-JEA4WUCA.js → nexus-NRSHSNSD.js} +3 -3
- package/dist/cli/{ops-7R6KUNYR.js → ops-NWEUYPMM.js} +3 -3
- package/dist/cli/{orchestrate-VRV64ICV.js → orchestrate-4JOC5JBH.js} +2 -2
- package/dist/cli/{orchestrate-X7U3FWJS.js → orchestrate-PKP6NGDB.js} +3 -3
- package/dist/cli/{phase-6SG6UXLH.js → phase-FFE3AYXK.js} +3 -3
- package/dist/cli/{pipeline-Z6AYKV6Q.js → pipeline-OMKEFYSV.js} +2 -2
- package/dist/cli/{pivot-QWQCQDWE.js → pivot-MYXAZZOK.js} +3 -3
- package/dist/cli/{plan-GBI3QHHC.js → plan-PP7ZRDEL.js} +3 -3
- package/dist/cli/{playbook-RM3WK56W.js → playbook-3ZJ364AT.js} +3 -3
- package/dist/cli/{promote-AWQS35MC.js → promote-BMEJWJFS.js} +3 -3
- package/dist/cli/{provenance-FHCWD66D.js → provenance-E5YRQR6B.js} +3 -3
- package/dist/cli/{provider-34LLDDWT.js → provider-CPXT43JJ.js} +3 -3
- package/dist/cli/{reason-SVUVYX5J.js → reason-S3IX5MVW.js} +3 -3
- package/dist/cli/{reconcile-FUX6CNSG.js → reconcile-QBQ2J5S7.js} +3 -3
- package/dist/cli/{relates-LGZRMRHL.js → relates-6HDKISVV.js} +3 -3
- package/dist/cli/{release-SXCMV7IT.js → release-RCUUBO7N.js} +3 -3
- package/dist/cli/{reorder-W5SPFBD6.js → reorder-QQM7Q6FL.js} +3 -3
- package/dist/cli/{reparent-ZBGWCXHI.js → reparent-NWPI5GCQ.js} +3 -3
- package/dist/cli/{req-APSYAXJN.js → req-ZTCKOKAJ.js} +3 -3
- package/dist/cli/{research-FUU2C35U.js → research-FDCTCUMM.js} +3 -3
- package/dist/cli/{restore-6WLDSWCZ.js → restore-Q7YO647P.js} +3 -3
- package/dist/cli/{roadmap-UCAHABWQ.js → roadmap-BZHWWL5G.js} +3 -3
- package/dist/cli/{safestop-KZYA7EVU.js → safestop-LPZVMNXG.js} +3 -3
- package/dist/cli/{saga-VAE6KIY4.js → saga-MW5T4GQQ.js} +3 -3
- package/dist/cli/{selfimprove-7G4IJCOX.js → selfimprove-4ZERPHXT.js} +3 -3
- package/dist/cli/{selfimprove-QJNMUYSC.js → selfimprove-C4HWDCM7.js} +2 -2
- package/dist/cli/{sequence-EA2UTXCO.js → sequence-TINZEJ7V.js} +3 -3
- package/dist/cli/{service-KPJHAMZE.js → service-WWCX2GBY.js} +3 -3
- package/dist/cli/{session-RVRWX2L3.js → session-2XGQYSM4.js} +2 -2
- package/dist/cli/{session-WB7DVSLC.js → session-6NWSKFSG.js} +3 -3
- package/dist/cli/{show-PVCBFPKO.js → show-G3GPC23W.js} +3 -3
- package/dist/cli/{skills-FNZZWWEE.js → skills-FV6SVE7L.js} +3 -3
- package/dist/cli/{snapshot-QCJ73HT4.js → snapshot-QH3IRA6F.js} +3 -3
- package/dist/cli/{start-QZC7Z5D7.js → start-S52HD5JV.js} +3 -3
- package/dist/cli/{stats-ZOOYQ655.js → stats-6S4JMDOU.js} +3 -3
- package/dist/cli/{sticky-WHILUII3.js → sticky-UB37G6EL.js} +3 -3
- package/dist/cli/{stop-YWIYWJCQ.js → stop-DJMBHZR2.js} +3 -3
- package/dist/cli/{sync-SSJRDC35.js → sync-BHUVE2CT.js} +3 -3
- package/dist/cli/{tasks-BQBEA4WT.js → tasks-HTOVUBA3.js} +2 -2
- package/dist/cli/{tasks-IQQS7ALI.js → tasks-MXKXRJC4.js} +3 -3
- package/dist/cli/{testing-4GP7PMNX.js → testing-CSM77MCM.js} +3 -3
- package/dist/cli/{token-W7KLVNQG.js → token-SWBMAFNC.js} +3 -3
- package/dist/cli/{update-SGQVA2AF.js → update-MGQ3VOZA.js} +3 -3
- package/dist/cli/{verify-GHGQDG2N.js → verify-E3HKTGZO.js} +3 -3
- package/dist/cli/{worktree-MET3Z6DE.js → worktree-OHZ2HXVY.js} +3 -3
- package/package.json +26 -24
- package/studio-dist/client/_app/immutable/chunks/{YrnMZj7k.js → Bx_Ybdwg.js} +1 -1
- package/studio-dist/client/_app/immutable/chunks/CK74r9qk.js +1 -0
- package/studio-dist/client/_app/immutable/chunks/{DZFfW1AY.js → COvBLBir.js} +1 -1
- package/studio-dist/client/_app/immutable/chunks/{CTsQwvSH.js → CzOru2IQ.js} +1 -1
- package/studio-dist/client/_app/immutable/entry/{app.D7iAIMYE.js → app.DnI5mM73.js} +2 -2
- package/studio-dist/client/_app/immutable/entry/start.CocuF8MJ.js +1 -0
- package/studio-dist/client/_app/immutable/nodes/{0.CTTL9pb7.js → 0.DQ30q-mz.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{1.NlL-0yyn.js → 1.JV0f2m6G.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{15.DfeXPRF7.js → 15.CLlik7BX.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{16.B9rpGS-9.js → 16.3tCwb6mJ.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{17.D-4wCrd4.js → 17.CnYe2cL4.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{18.BFvElp8k.js → 18.CmRvKXU6.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{20.BhzKjQwj.js → 20.Dd8Jncv-.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{24.3Ww_O2X2.js → 24.BKeV5sCP.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{25.DLiJDd6S.js → 25.42FV04bG.js} +2 -2
- package/studio-dist/client/_app/immutable/nodes/{26.BL2xCT2z.js → 26.kdWFFy6h.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{3.yIV9MGfZ.js → 3.C7gybX_c.js} +1 -1
- package/studio-dist/client/_app/version.json +1 -1
- package/studio-dist/server/chunks/{0-CBaP-tAB.js → 0-D5IK1A6a.js} +3 -3
- package/studio-dist/server/chunks/1-BQTnuTNB.js +9 -0
- package/studio-dist/server/chunks/{15-CqaSdvfB.js → 15-1FEj7YLh.js} +3 -3
- package/studio-dist/server/chunks/{16-CiBgTqxt.js → 16-BPExaCbz.js} +3 -3
- package/studio-dist/server/chunks/{17-Cjl51U8K.js → 17-BJDZbxOa.js} +3 -3
- package/studio-dist/server/chunks/{18-RI26Et7D.js → 18-Ctw9hVSr.js} +3 -3
- package/studio-dist/server/chunks/{20-C5LBI5rw.js → 20-DHYBZQXc.js} +3 -3
- package/studio-dist/server/chunks/{24-BgksdGxP.js → 24-DAI0Lyyc.js} +3 -3
- package/studio-dist/server/chunks/{25-C6XphKfR.js → 25-I2HNzAo9.js} +4 -4
- package/studio-dist/server/chunks/{26-XKROMRSr.js → 26-DyIOS9XM.js} +3 -3
- package/studio-dist/server/chunks/{3--F6pC4tk.js → 3-B2xvXVT0.js} +14 -17
- package/studio-dist/server/chunks/{_layout.svelte-BfYzxAIK.js → _layout.svelte-DWyTOQxs.js} +4 -4
- package/studio-dist/server/chunks/{_page.svelte-b1lbAnXJ.js → _page.svelte-B45EpBnX.js} +5 -5
- package/studio-dist/server/chunks/{_page.svelte-DXi_tF5d.js → _page.svelte-B9H6-g06.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-BK2_7OI7.js → _page.svelte-BbyRiKdN.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-DbEk5msU.js → _page.svelte-BnFe-NMP.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-DTzl5cRj.js → _page.svelte-C-87PKFP.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-i1SBn8Io.js → _page.svelte-CEwUAieV.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-BU4w26EA.js → _page.svelte-DXjPWuIN.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-BGkhpLyo.js → _page.svelte-RhWTQFHO.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-CYWmItna.js → _page.svelte-rvUlNZoL.js} +4 -4
- package/studio-dist/server/chunks/{_server.ts-CmOf90SL.js → _server.ts-BoJ3fPMJ.js} +3 -4
- package/studio-dist/server/chunks/{_server.ts-CFMss8Ec.js → _server.ts-C_AxPpt-.js} +4 -5
- package/studio-dist/server/chunks/{_server.ts-CqvUI2a6.js → _server.ts-CwDGVJ2P.js} +2 -2
- package/studio-dist/server/chunks/{_server.ts-CUDHRtqK.js → _server.ts-DSM1bzLc.js} +3 -4
- package/studio-dist/server/chunks/{_server.ts-DfzvMeMr.js → _server.ts-DqCpzs5A.js} +4 -5
- package/studio-dist/server/chunks/{brain-4-tWVd6k.js → brain-BAwmMnA6.js} +2 -2
- package/studio-dist/server/chunks/{client-CZek3kDE.js → client-Br0ikrJg.js} +2 -2
- package/studio-dist/server/chunks/{error.svelte-PDw8rEzH.js → error.svelte-BmmeOJVZ.js} +3 -3
- package/studio-dist/server/chunks/{internal-D__0tFeu.js → internal-qWV_lqaN.js} +2 -2
- package/studio-dist/server/chunks/{src-CeLZUrEE.js → src-DMQE8esV.js} +424 -551
- package/studio-dist/server/chunks/{stores-CWmffjka.js → stores-ClTAlUAW.js} +2 -2
- package/studio-dist/server/index.js +1 -1
- package/studio-dist/server/manifest.js +17 -17
- package/templates/cleoos-hub/pi-extensions/cant-bridge.ts +10 -8
- package/studio-dist/client/_app/immutable/chunks/NHuzFbd2.js +0 -1
- package/studio-dist/client/_app/immutable/entry/start.BN5_FCu4.js +0 -1
- package/studio-dist/server/chunks/1--l5p9Mx5.js +0 -9
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { existsSync, statSync, realpathSync, readFileSync } from 'node:fs';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { openCleoDbSnapshot } from '@cleocode/core/store/open-cleo-db.js';
|
|
4
|
+
import path, { resolve, join, dirname, isAbsolute } from 'node:path';
|
|
5
5
|
import 'node:crypto';
|
|
6
6
|
import os, { hostname, release, arch, platform, homedir } from 'node:os';
|
|
7
7
|
import process$1 from 'node:process';
|
|
8
|
-
import '@cleocode/core/db';
|
|
9
8
|
|
|
10
9
|
function isSafeFilename(filename) {
|
|
11
10
|
if (typeof filename !== "string") return false;
|
|
@@ -743,25 +742,6 @@ function resolveCanonicalCleoDir(projectId) {
|
|
|
743
742
|
//#endregion
|
|
744
743
|
//#region ../brain/dist/src/cleo-home.js
|
|
745
744
|
/**
|
|
746
|
-
* CLEO home + project DB path resolution for `@cleocode/brain`.
|
|
747
|
-
*
|
|
748
|
-
* Path resolution delegates to the `@cleocode/paths` SSoT
|
|
749
|
-
* ({@link getCleoHome}). Project data (tasks.db, brain.db, conduit.db) is
|
|
750
|
-
* resolved via projectId → nexus.db registry lookup
|
|
751
|
-
* ({@link resolveProjectByCwd} + {@link resolveCanonicalCleoDir}), with a
|
|
752
|
-
* `CLEO_ROOT` / `process.cwd()` fallback for non-project contexts.
|
|
753
|
-
*
|
|
754
|
-
* Previously this module imported `env-paths` directly which caused a Windows
|
|
755
|
-
* path mismatch with the rest of the CLEO ecosystem (the CLI used env-paths
|
|
756
|
-
* returning `%LOCALAPPDATA%\cleo\Data` while brain used a bare
|
|
757
|
-
* `%LOCALAPPDATA%\cleo`, looking up `nexus.db` one directory shallower than
|
|
758
|
-
* where it was written). Fixed in T1874 (Closes #102, supersedes #103).
|
|
759
|
-
*
|
|
760
|
-
* @task T1874 (original Windows fix)
|
|
761
|
-
* @task T1886 (migrated to @cleocode/paths SSoT)
|
|
762
|
-
* @task T11040 (verified 2026-05-27: projectId-based resolution confirmed; 72/72 tests pass)
|
|
763
|
-
*/
|
|
764
|
-
/**
|
|
765
745
|
* Returns the project's `.cleo/` directory.
|
|
766
746
|
*
|
|
767
747
|
* Resolution order:
|
|
@@ -784,54 +764,50 @@ function getCleoProjectDir() {
|
|
|
784
764
|
}
|
|
785
765
|
return join(process.env["CLEO_ROOT"] ?? process.cwd(), ".cleo");
|
|
786
766
|
}
|
|
787
|
-
/**
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
767
|
+
/**
|
|
768
|
+
* Returns the absolute path to the project-scope `cleo.db`.
|
|
769
|
+
*
|
|
770
|
+
* It holds the project's `tasks_*`, `brain_*`, `conduit_*` and `nexus_*`
|
|
771
|
+
* (code graph, ADR-090) tables. The legacy `tasks.db`, `brain.db` and
|
|
772
|
+
* `conduit.db` files are decoys and are never read (T12095, T14583).
|
|
773
|
+
*
|
|
774
|
+
* @returns `<project>/.cleo/cleo.db`.
|
|
775
|
+
*/
|
|
776
|
+
function getProjectStorePath() {
|
|
777
|
+
return join(getCleoProjectDir(), "cleo.db");
|
|
794
778
|
}
|
|
795
|
-
/**
|
|
796
|
-
|
|
797
|
-
|
|
779
|
+
/**
|
|
780
|
+
* Returns the absolute path to the global-scope `cleo.db` under CLEO home.
|
|
781
|
+
*
|
|
782
|
+
* It holds the `agent_registry_*` tables; the retired `signaldock.db` and
|
|
783
|
+
* `nexus.db` files are never read (T14583).
|
|
784
|
+
*
|
|
785
|
+
* @returns `<cleoHome>/cleo.db`.
|
|
786
|
+
*/
|
|
787
|
+
function getGlobalStorePath() {
|
|
788
|
+
return join(getCleoHome(), "cleo.db");
|
|
798
789
|
}
|
|
799
790
|
//#endregion
|
|
800
791
|
//#region ../brain/dist/src/db-connections.js
|
|
801
792
|
/**
|
|
802
|
-
* Read-only
|
|
803
|
-
*
|
|
804
|
-
* Uses node:sqlite (Node.js built-in).
|
|
793
|
+
* Read-only store access for the Living Brain substrate adapters.
|
|
805
794
|
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
795
|
+
* The adapters read the consolidated stores, never the legacy per-domain files
|
|
796
|
+
* (`brain.db`, `tasks.db`, `conduit.db`, `nexus.db`, `signaldock.db`), which are
|
|
797
|
+
* decoys or retired (T12095, T14583):
|
|
809
798
|
*
|
|
810
|
-
*
|
|
811
|
-
* the
|
|
812
|
-
*
|
|
813
|
-
* and caching across different ProjectContexts is the precise bug this
|
|
814
|
-
* module's Studio counterpart was rewritten to avoid.
|
|
799
|
+
* - **Project `cleo.db`** (`<project>/.cleo/cleo.db`): `tasks_*`, `brain_*`,
|
|
800
|
+
* `conduit_*` and the `nexus_*` code graph (ADR-090).
|
|
801
|
+
* - **Global `cleo.db`** (`<cleoHome>/cleo.db`): `agent_registry_*`.
|
|
815
802
|
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* ## E4-T5 transition (T11516 · SG-DB-SUBSTRATE-V2)
|
|
821
|
-
*
|
|
822
|
-
* This module now depends on `@cleocode/core` and delegates to
|
|
823
|
-
* {@link openDualScopeDb} for new consolidated `cleo.db` access. The legacy
|
|
824
|
-
* per-domain DB getters ({@link getNexusDb}, {@link getBrainDb}, etc.) still
|
|
825
|
-
* open the old per-domain files via per-line-allowed raw opens because the
|
|
826
|
-
* substrate adapters in this package still target those legacy table schemas.
|
|
827
|
-
* The full exodus to the consolidated `cleo.db` schema happens in E6 (T11249),
|
|
828
|
-
* at which point the per-line `// db-open-allowed` markers and the legacy
|
|
829
|
-
* getters are removed.
|
|
803
|
+
* Every read goes through the store chokepoint's snapshot opener
|
|
804
|
+
* ({@link openCleoDbSnapshot}): a read-only handle with no migrations and no
|
|
805
|
+
* singleton, opened for one read and closed after it. Opening is
|
|
806
|
+
* sub-millisecond, and no handle is cached across project contexts.
|
|
830
807
|
*
|
|
831
808
|
* @task T969
|
|
832
|
-
* @task
|
|
809
|
+
* @task T14583 (consolidated cleo.db through the store chokepoint)
|
|
833
810
|
*/
|
|
834
|
-
var { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
835
811
|
/**
|
|
836
812
|
* Executes a prepared statement and returns rows typed as `T[]`.
|
|
837
813
|
*
|
|
@@ -850,144 +826,61 @@ var { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
|
850
826
|
function allTyped(stmt, ...params) {
|
|
851
827
|
return stmt.all(...params);
|
|
852
828
|
}
|
|
853
|
-
/** Cached nexus.db connection — global, path is machine-scoped. */
|
|
854
|
-
var nexusDb = null;
|
|
855
|
-
/** Cached signaldock.db connection — global, path is machine-scoped. */
|
|
856
|
-
var signaldockDb = null;
|
|
857
|
-
/**
|
|
858
|
-
* Returns a read-only connection to the global nexus.db.
|
|
859
|
-
* Returns null when the file does not exist on disk.
|
|
860
|
-
*
|
|
861
|
-
* @remarks
|
|
862
|
-
* Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045).
|
|
863
|
-
* The raw open is per-line-allowed during the E4 → E6 transition; substrate
|
|
864
|
-
* adapters still target legacy nexus.db table names. Full exodus in E6 (T11249).
|
|
865
|
-
*/
|
|
866
|
-
function getNexusDb() {
|
|
867
|
-
if (nexusDb) return nexusDb;
|
|
868
|
-
const path = getNexusDbPath();
|
|
869
|
-
if (!dbExists(path)) return null;
|
|
870
|
-
nexusDb = new DatabaseSync(path, { open: true });
|
|
871
|
-
applyPerfPragmas(nexusDb);
|
|
872
|
-
return nexusDb;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Returns a read-only connection to the global signaldock.db.
|
|
876
|
-
* Returns null when the file does not exist on disk.
|
|
877
|
-
*
|
|
878
|
-
* @remarks
|
|
879
|
-
* Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045).
|
|
880
|
-
* The raw open is per-line-allowed during the E4 → E6 transition; substrate
|
|
881
|
-
* adapters still target legacy signaldock.db table names. Full exodus in E6 (T11249).
|
|
882
|
-
*/
|
|
883
|
-
function getAgentRegistryDb() {
|
|
884
|
-
if (signaldockDb) return signaldockDb;
|
|
885
|
-
const path = getAgentRegistryDbPath();
|
|
886
|
-
if (!dbExists(path)) return null;
|
|
887
|
-
signaldockDb = new DatabaseSync(path, { open: true });
|
|
888
|
-
applyPerfPragmas(signaldockDb);
|
|
889
|
-
return signaldockDb;
|
|
890
|
-
}
|
|
891
|
-
/**
|
|
892
|
-
* Detect the brain.db malformation signature (T10303) without taking a
|
|
893
|
-
* dependency on `@cleocode/core`. The reader side does NOT auto-recover —
|
|
894
|
-
* recovery is owned by the writer side in `@cleocode/core/store/memory-sqlite.ts`.
|
|
895
|
-
* Reader-side detection returns `null` so substrate adapters degrade
|
|
896
|
-
* gracefully (matches the existing "DB doesn't exist" semantics).
|
|
897
|
-
*
|
|
898
|
-
* @internal — brain-package-local.
|
|
899
|
-
* @task T10303
|
|
900
|
-
*/
|
|
901
|
-
function isMalformationError(err) {
|
|
902
|
-
if (!(err instanceof Error)) return false;
|
|
903
|
-
const code = err.code;
|
|
904
|
-
const errcode = err.errcode;
|
|
905
|
-
if (code === "ERR_SQLITE_ERROR" && errcode === 11) return true;
|
|
906
|
-
return /malformed/i.test(err.message ?? "");
|
|
907
|
-
}
|
|
908
829
|
/**
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
* Each call opens a fresh DatabaseSync against the path stored in `ctx`.
|
|
912
|
-
* Returns null when brain.db does not exist for the project OR when the
|
|
913
|
-
* file is detected as malformed (T10303). Reader-side malformation is
|
|
914
|
-
* handled by returning null — recovery is owned by the writer side in
|
|
915
|
-
* `@cleocode/core/store/memory-sqlite.ts:getBrainDb`, which runs the
|
|
916
|
-
* `recoverMalformedBrainDb()` pipeline before the next process re-opens.
|
|
830
|
+
* Runs `read` against a read-only snapshot of the store at `path`.
|
|
917
831
|
*
|
|
918
|
-
* @param
|
|
919
|
-
*
|
|
920
|
-
* @
|
|
921
|
-
*
|
|
922
|
-
*
|
|
923
|
-
* adapters still target legacy brain.db table names. Full exodus in E6 (T11249).
|
|
832
|
+
* @param path - Absolute path to a consolidated `cleo.db`.
|
|
833
|
+
* @param read - Synchronous read; the handle is closed when it returns.
|
|
834
|
+
* @returns The read's result, or null when the store is missing or cannot be
|
|
835
|
+
* opened (a restore in progress, a malformed file), so the substrate degrades
|
|
836
|
+
* to no nodes.
|
|
924
837
|
*/
|
|
925
|
-
function
|
|
926
|
-
const path = ctx.brainDbPath;
|
|
838
|
+
function readStore(path, read) {
|
|
927
839
|
if (!existsSync(path)) return null;
|
|
840
|
+
let snapshot;
|
|
841
|
+
try {
|
|
842
|
+
snapshot = openCleoDbSnapshot(path, { readOnly: true });
|
|
843
|
+
} catch {
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
928
846
|
try {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
} catch (err) {
|
|
933
|
-
if (isMalformationError(err)) return null;
|
|
934
|
-
throw err;
|
|
847
|
+
return read(snapshot.db);
|
|
848
|
+
} finally {
|
|
849
|
+
snapshot.close();
|
|
935
850
|
}
|
|
936
851
|
}
|
|
937
852
|
/**
|
|
938
|
-
*
|
|
853
|
+
* Runs `read` against the project-scope `cleo.db` named by `ctx`.
|
|
939
854
|
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* @param ctx - The active project context.
|
|
944
|
-
*
|
|
945
|
-
* @remarks
|
|
946
|
-
* Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045).
|
|
947
|
-
* The raw open is per-line-allowed during the E4 → E6 transition; substrate
|
|
948
|
-
* adapters still target legacy tasks.db table names. Full exodus in E6 (T11249).
|
|
855
|
+
* @param ctx - The active project context; `tasksDbPath` names its `cleo.db`.
|
|
856
|
+
* @param read - Synchronous read against the project store.
|
|
857
|
+
* @returns The read's result, or null when the store is missing or unreadable.
|
|
949
858
|
*/
|
|
950
|
-
function
|
|
951
|
-
|
|
952
|
-
if (!existsSync(path)) return null;
|
|
953
|
-
const __db = new DatabaseSync(path, { open: true });
|
|
954
|
-
applyPerfPragmas(__db);
|
|
955
|
-
return __db;
|
|
859
|
+
function readProjectStore(ctx, read) {
|
|
860
|
+
return readStore(ctx.tasksDbPath, read);
|
|
956
861
|
}
|
|
957
862
|
/**
|
|
958
|
-
*
|
|
863
|
+
* Runs `read` against the global-scope `cleo.db` under CLEO home.
|
|
959
864
|
*
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
* carry a dedicated `conduitDbPath` field.
|
|
963
|
-
*
|
|
964
|
-
* Returns null when conduit.db does not exist for the project.
|
|
965
|
-
*
|
|
966
|
-
* @param ctx - The active project context.
|
|
967
|
-
*
|
|
968
|
-
* @remarks
|
|
969
|
-
* Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045).
|
|
970
|
-
* The raw open is per-line-allowed during the E4 → E6 transition; substrate
|
|
971
|
-
* adapters still target legacy conduit.db table names. Full exodus in E6 (T11249).
|
|
865
|
+
* @param read - Synchronous read against the global store.
|
|
866
|
+
* @returns The read's result, or null when the store is missing or unreadable.
|
|
972
867
|
*/
|
|
973
|
-
function
|
|
974
|
-
|
|
975
|
-
if (!existsSync(path)) return null;
|
|
976
|
-
const __db = new DatabaseSync(path, { open: true });
|
|
977
|
-
applyPerfPragmas(__db);
|
|
978
|
-
return __db;
|
|
868
|
+
function readGlobalStore(read) {
|
|
869
|
+
return readStore(getGlobalStorePath(), read);
|
|
979
870
|
}
|
|
980
871
|
//#endregion
|
|
981
872
|
//#region ../brain/dist/src/adapters/agent-registry.js
|
|
982
873
|
/**
|
|
983
874
|
* AGENT-REGISTRY substrate adapter for the Living Brain API.
|
|
984
875
|
*
|
|
985
|
-
* Read-only visualization path. Queries
|
|
986
|
-
*
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
876
|
+
* Read-only visualization path. Queries `agent_registry_agents` in the global
|
|
877
|
+
* `cleo.db` and returns one BrainNode per active agent. The retired standalone
|
|
878
|
+
* `signaldock.db` is never read (T14583).
|
|
879
|
+
*
|
|
880
|
+
* The consolidated store has no declared agent-to-agent social graph
|
|
881
|
+
* (`agent_registry_agent_connections` records transport connections, not
|
|
882
|
+
* pairs), so this adapter emits no edges; agent→agent edges come from the
|
|
883
|
+
* CONDUIT substrate's message pairs.
|
|
991
884
|
*
|
|
992
885
|
* The substrate identifier + node-id prefix were renamed `signaldock` →
|
|
993
886
|
* `agent-registry` under T11622 (display identifiers, decoupled from the physical
|
|
@@ -998,73 +891,46 @@ function getConduitDb(ctx) {
|
|
|
998
891
|
* (assignee), CONDUIT (from/to), and BRAIN (source agent).
|
|
999
892
|
*
|
|
1000
893
|
* @task T11622 (Signaldock → Agent Registry rename; folds T11578 AC2)
|
|
894
|
+
* @task T14583 (read the global cleo.db)
|
|
1001
895
|
*/
|
|
1002
896
|
/**
|
|
1003
|
-
* Converts a UNIX epoch seconds value to an ISO-8601 string.
|
|
1004
|
-
* Returns null when the value is not a finite positive number.
|
|
1005
|
-
*
|
|
1006
|
-
* @param epoch - UNIX timestamp in seconds, or null.
|
|
1007
|
-
* @returns ISO-8601 string or null.
|
|
1008
|
-
*/
|
|
1009
|
-
function epochToIso$1(epoch) {
|
|
1010
|
-
if (epoch === null || !Number.isFinite(epoch) || epoch <= 0) return null;
|
|
1011
|
-
return (/* @__PURE__ */ new Date(epoch * 1e3)).toISOString();
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
897
|
* Returns all BrainNodes and BrainEdges sourced from the Agent Registry.
|
|
1015
898
|
*
|
|
1016
|
-
* Fetches
|
|
1017
|
-
*
|
|
899
|
+
* Fetches the most recently registered active agents. Agent nodes serve as
|
|
900
|
+
* the cross-substrate identity anchors.
|
|
1018
901
|
*
|
|
1019
902
|
* @param options - Query options (limit).
|
|
1020
|
-
* @returns Nodes and edges from the AGENT-REGISTRY substrate.
|
|
903
|
+
* @returns Nodes (and no edges) from the AGENT-REGISTRY substrate.
|
|
1021
904
|
*/
|
|
1022
905
|
function getAgentRegistrySubstrate(options = {}) {
|
|
1023
|
-
const db = getAgentRegistryDb();
|
|
1024
|
-
if (!db) return {
|
|
1025
|
-
nodes: [],
|
|
1026
|
-
edges: []
|
|
1027
|
-
};
|
|
1028
906
|
const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
|
|
1029
907
|
const nodes = [];
|
|
1030
908
|
const edges = [];
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
909
|
+
readGlobalStore((db) => {
|
|
910
|
+
try {
|
|
911
|
+
const agentRows = allTyped(db.prepare(`SELECT agent_id, name, status,
|
|
912
|
+
CASE WHEN typeof(created_at) = 'integer'
|
|
913
|
+
THEN strftime('%Y-%m-%dT%H:%M:%S', created_at, 'unixepoch')
|
|
914
|
+
ELSE strftime('%Y-%m-%dT%H:%M:%S', created_at)
|
|
915
|
+
END AS created_at
|
|
916
|
+
FROM main.agent_registry_agents
|
|
917
|
+
WHERE is_active = 1
|
|
918
|
+
ORDER BY created_at DESC
|
|
919
|
+
LIMIT ?`), perSubstrateLimit);
|
|
920
|
+
for (const row of agentRows) nodes.push({
|
|
1041
921
|
id: `agent-registry:${row.agent_id}`,
|
|
1042
922
|
kind: "agent",
|
|
1043
923
|
substrate: "agent-registry",
|
|
1044
924
|
label: row.name,
|
|
1045
|
-
weight: row.status === "
|
|
1046
|
-
createdAt:
|
|
925
|
+
weight: row.status === "online" ? 1 : .5,
|
|
926
|
+
createdAt: row.created_at,
|
|
1047
927
|
meta: {
|
|
1048
928
|
status: row.status,
|
|
1049
929
|
created_at: row.created_at
|
|
1050
930
|
}
|
|
1051
931
|
});
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
const placeholders = [...agentIds].map(() => "?").join(",");
|
|
1055
|
-
const connRows = allTyped(db.prepare(`SELECT from_agent_id, to_agent_id, connection_type, strength
|
|
1056
|
-
FROM agent_connections
|
|
1057
|
-
WHERE from_agent_id IN (${placeholders})
|
|
1058
|
-
AND to_agent_id IN (${placeholders})`), ...agentIds, ...agentIds);
|
|
1059
|
-
for (const row of connRows) edges.push({
|
|
1060
|
-
source: `agent-registry:${row.from_agent_id}`,
|
|
1061
|
-
target: `agent-registry:${row.to_agent_id}`,
|
|
1062
|
-
type: row.connection_type,
|
|
1063
|
-
weight: row.strength ?? .5,
|
|
1064
|
-
substrate: "agent-registry"
|
|
1065
|
-
});
|
|
1066
|
-
}
|
|
1067
|
-
} catch {}
|
|
932
|
+
} catch {}
|
|
933
|
+
});
|
|
1068
934
|
return {
|
|
1069
935
|
nodes,
|
|
1070
936
|
edges
|
|
@@ -1073,12 +939,32 @@ function getAgentRegistrySubstrate(options = {}) {
|
|
|
1073
939
|
//#endregion
|
|
1074
940
|
//#region ../brain/dist/src/project-context.js
|
|
1075
941
|
/**
|
|
942
|
+
* Project context resolution for the Living Brain substrate.
|
|
943
|
+
*
|
|
944
|
+
* `ProjectContext` carries the resolved absolute path of the project store
|
|
945
|
+
* (`.cleo/cleo.db`) so substrate adapters can route queries to the correct
|
|
946
|
+
* project without depending on SvelteKit request locals.
|
|
947
|
+
*
|
|
948
|
+
* The `ProjectContext` shape defined here is structurally compatible with
|
|
949
|
+
* (i.e. a subtype of) the studio's richer `ProjectContext` in
|
|
950
|
+
* `packages/studio/src/lib/server/project-context.ts`. Studio callers may
|
|
951
|
+
* pass their full context directly; it will satisfy this interface via
|
|
952
|
+
* structural typing.
|
|
953
|
+
*
|
|
954
|
+
* `resolveDefaultProjectContext` derives a fallback context from
|
|
955
|
+
* `CLEO_ROOT` / `process.cwd()` when no explicit context is supplied.
|
|
956
|
+
*
|
|
957
|
+
* @task T969
|
|
958
|
+
* @task T11040 (verified 2026-05-27: resolveProjectByCwd used for projectPath; 72/72 tests pass)
|
|
959
|
+
* @task T14583 (both store paths name the project cleo.db)
|
|
960
|
+
*/
|
|
961
|
+
/**
|
|
1076
962
|
* Resolve the default project context using projectId-based resolution.
|
|
1077
963
|
*
|
|
1078
964
|
* Derives `projectPath` from {@link resolveProjectByCwd} (canonical project
|
|
1079
965
|
* root), falling back to the `.cleo`-relative path for non-project contexts.
|
|
1080
|
-
*
|
|
1081
|
-
* projectId→
|
|
966
|
+
* The store path flows through {@link getCleoProjectDir}, which uses
|
|
967
|
+
* projectId→registry resolution instead of CWD-walk-up (T11040).
|
|
1082
968
|
*
|
|
1083
969
|
* @returns A context whose paths derive from projectId resolution where possible.
|
|
1084
970
|
* @task T11040 — migrate from CWD-walk-up to projectId-based resolution
|
|
@@ -1086,10 +972,12 @@ function getAgentRegistrySubstrate(options = {}) {
|
|
|
1086
972
|
function resolveDefaultProjectContext() {
|
|
1087
973
|
const project = resolveProjectByCwd();
|
|
1088
974
|
const projectDir = getCleoProjectDir();
|
|
975
|
+
const projectPath = project !== null ? project.projectRoot : projectDir.replace(/\/.cleo$/, "");
|
|
976
|
+
const storePath = getProjectStorePath();
|
|
1089
977
|
return {
|
|
1090
|
-
projectPath
|
|
1091
|
-
brainDbPath:
|
|
1092
|
-
tasksDbPath:
|
|
978
|
+
projectPath,
|
|
979
|
+
brainDbPath: storePath,
|
|
980
|
+
tasksDbPath: storePath
|
|
1093
981
|
};
|
|
1094
982
|
}
|
|
1095
983
|
//#endregion
|
|
@@ -1097,7 +985,8 @@ function resolveDefaultProjectContext() {
|
|
|
1097
985
|
/**
|
|
1098
986
|
* BRAIN substrate adapter for the Living Brain API.
|
|
1099
987
|
*
|
|
1100
|
-
* Queries
|
|
988
|
+
* Queries the project `cleo.db` and returns BrainNodes/BrainEdges for all typed
|
|
989
|
+
* memory tables:
|
|
1101
990
|
* observations, decisions, patterns, learnings, plus the graph layer
|
|
1102
991
|
* (brain_page_nodes / brain_page_edges).
|
|
1103
992
|
*
|
|
@@ -1160,7 +1049,7 @@ function taskRefToBrainNodeId(taskRef) {
|
|
|
1160
1049
|
return `tasks:${taskRef.slice(5)}`;
|
|
1161
1050
|
}
|
|
1162
1051
|
/**
|
|
1163
|
-
* Returns all BrainNodes and BrainEdges sourced from
|
|
1052
|
+
* Returns all BrainNodes and BrainEdges sourced from the project `cleo.db`.
|
|
1164
1053
|
*
|
|
1165
1054
|
* Pulls from all four typed memory tables plus brain_page_edges.
|
|
1166
1055
|
* Emits intra-brain edges between loaded nodes, cross-substrate
|
|
@@ -1174,169 +1063,167 @@ function taskRefToBrainNodeId(taskRef) {
|
|
|
1174
1063
|
* @returns Nodes and edges from the BRAIN substrate.
|
|
1175
1064
|
*/
|
|
1176
1065
|
function getBrainSubstrate(options = {}) {
|
|
1177
|
-
const
|
|
1178
|
-
if (!db) return {
|
|
1179
|
-
nodes: [],
|
|
1180
|
-
edges: []
|
|
1181
|
-
};
|
|
1066
|
+
const ctx = options.projectCtx ?? resolveDefaultProjectContext();
|
|
1182
1067
|
const minWeight = options.minWeight ?? 0;
|
|
1183
1068
|
const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
|
|
1184
1069
|
const nodes = [];
|
|
1185
1070
|
const edges = [];
|
|
1186
|
-
|
|
1187
|
-
|
|
1071
|
+
readProjectStore(ctx, (db) => {
|
|
1072
|
+
try {
|
|
1073
|
+
const obsRows = allTyped(db.prepare(`SELECT id, title, quality_score, memory_tier,
|
|
1188
1074
|
strftime('%Y-%m-%dT%H:%M:%S', created_at) AS created_at,
|
|
1189
1075
|
source_session_id, files_modified_json
|
|
1190
|
-
FROM brain_observations
|
|
1076
|
+
FROM main.brain_observations
|
|
1191
1077
|
WHERE (quality_score IS NULL OR quality_score >= ?)
|
|
1192
1078
|
ORDER BY quality_score DESC, created_at DESC
|
|
1193
1079
|
LIMIT ?`), minWeight, Math.ceil(perSubstrateLimit * .4));
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1080
|
+
for (const row of obsRows) nodes.push({
|
|
1081
|
+
id: `brain:${row.id}`,
|
|
1082
|
+
kind: "observation",
|
|
1083
|
+
substrate: "brain",
|
|
1084
|
+
label: row.title,
|
|
1085
|
+
weight: row.quality_score ?? void 0,
|
|
1086
|
+
createdAt: row.created_at,
|
|
1087
|
+
meta: {
|
|
1088
|
+
memory_tier: row.memory_tier,
|
|
1089
|
+
created_at: row.created_at,
|
|
1090
|
+
source_session_id: row.source_session_id
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
const decRows = allTyped(db.prepare(`SELECT id, decision, quality_score, context_task_id,
|
|
1208
1094
|
strftime('%Y-%m-%dT%H:%M:%S', created_at) AS created_at
|
|
1209
|
-
FROM brain_decisions
|
|
1095
|
+
FROM main.brain_decisions
|
|
1210
1096
|
WHERE (quality_score IS NULL OR quality_score >= ?)
|
|
1211
1097
|
ORDER BY quality_score DESC, created_at DESC
|
|
1212
1098
|
LIMIT ?`), minWeight, Math.ceil(perSubstrateLimit * .25));
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1099
|
+
for (const row of decRows) nodes.push({
|
|
1100
|
+
id: `brain:${row.id}`,
|
|
1101
|
+
kind: "decision",
|
|
1102
|
+
substrate: "brain",
|
|
1103
|
+
label: row.decision.slice(0, 100),
|
|
1104
|
+
weight: row.quality_score ?? void 0,
|
|
1105
|
+
createdAt: row.created_at,
|
|
1106
|
+
meta: {
|
|
1107
|
+
context_task_id: row.context_task_id,
|
|
1108
|
+
created_at: row.created_at
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
const patRows = allTyped(db.prepare(`SELECT id, pattern, type, quality_score,
|
|
1226
1112
|
strftime('%Y-%m-%dT%H:%M:%S', extracted_at) AS extracted_at
|
|
1227
|
-
FROM brain_patterns
|
|
1113
|
+
FROM main.brain_patterns
|
|
1228
1114
|
WHERE (quality_score IS NULL OR quality_score >= ?)
|
|
1229
1115
|
ORDER BY quality_score DESC, extracted_at DESC
|
|
1230
1116
|
LIMIT ?`), minWeight, Math.ceil(perSubstrateLimit * .2));
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1117
|
+
for (const row of patRows) nodes.push({
|
|
1118
|
+
id: `brain:${row.id}`,
|
|
1119
|
+
kind: "pattern",
|
|
1120
|
+
substrate: "brain",
|
|
1121
|
+
label: row.pattern.slice(0, 100),
|
|
1122
|
+
weight: row.quality_score ?? void 0,
|
|
1123
|
+
createdAt: row.extracted_at,
|
|
1124
|
+
meta: {
|
|
1125
|
+
pattern_type: row.type,
|
|
1126
|
+
created_at: row.extracted_at
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
const learnRows = allTyped(db.prepare(`SELECT id, insight, quality_score,
|
|
1244
1130
|
strftime('%Y-%m-%dT%H:%M:%S', created_at) AS created_at
|
|
1245
|
-
FROM brain_learnings
|
|
1131
|
+
FROM main.brain_learnings
|
|
1246
1132
|
WHERE (quality_score IS NULL OR quality_score >= ?)
|
|
1247
1133
|
ORDER BY quality_score DESC, created_at DESC
|
|
1248
1134
|
LIMIT ?`), minWeight, Math.ceil(perSubstrateLimit * .15));
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
});
|
|
1258
|
-
const typeIdToBrainNodeId = /* @__PURE__ */ new Map();
|
|
1259
|
-
for (const n of nodes) {
|
|
1260
|
-
const rawId = n.id.slice(6);
|
|
1261
|
-
let typePrefix;
|
|
1262
|
-
if (n.kind === "observation") typePrefix = "observation";
|
|
1263
|
-
else if (n.kind === "decision") typePrefix = "decision";
|
|
1264
|
-
else if (n.kind === "pattern") typePrefix = "pattern";
|
|
1265
|
-
else typePrefix = "learning";
|
|
1266
|
-
typeIdToBrainNodeId.set(`${typePrefix}:${rawId}`, n.id);
|
|
1267
|
-
}
|
|
1268
|
-
const pageEdgeRows = allTyped(db.prepare(`SELECT from_id, to_id, edge_type, weight FROM brain_page_edges`));
|
|
1269
|
-
for (const row of pageEdgeRows) {
|
|
1270
|
-
const sourceBrainNodeId = typeIdToBrainNodeId.get(row.from_id) ?? brainTypeIdToBrainNodeId(row.from_id);
|
|
1271
|
-
if (!sourceBrainNodeId) continue;
|
|
1272
|
-
if (isTaskId(row.to_id)) edges.push({
|
|
1273
|
-
source: sourceBrainNodeId,
|
|
1274
|
-
target: taskRefToBrainNodeId(row.to_id),
|
|
1275
|
-
type: row.edge_type,
|
|
1276
|
-
weight: row.weight ?? .5,
|
|
1277
|
-
substrate: "cross"
|
|
1278
|
-
});
|
|
1279
|
-
else if (isNexusStyleId(row.to_id)) edges.push({
|
|
1280
|
-
source: sourceBrainNodeId,
|
|
1281
|
-
target: `nexus:${row.to_id}`,
|
|
1282
|
-
type: row.edge_type,
|
|
1283
|
-
weight: row.weight ?? .5,
|
|
1284
|
-
substrate: "cross"
|
|
1135
|
+
for (const row of learnRows) nodes.push({
|
|
1136
|
+
id: `brain:${row.id}`,
|
|
1137
|
+
kind: "learning",
|
|
1138
|
+
substrate: "brain",
|
|
1139
|
+
label: row.insight.slice(0, 100),
|
|
1140
|
+
weight: row.quality_score ?? void 0,
|
|
1141
|
+
createdAt: row.created_at,
|
|
1142
|
+
meta: { created_at: row.created_at }
|
|
1285
1143
|
});
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1144
|
+
const typeIdToBrainNodeId = /* @__PURE__ */ new Map();
|
|
1145
|
+
for (const n of nodes) {
|
|
1146
|
+
const rawId = n.id.slice(6);
|
|
1147
|
+
let typePrefix;
|
|
1148
|
+
if (n.kind === "observation") typePrefix = "observation";
|
|
1149
|
+
else if (n.kind === "decision") typePrefix = "decision";
|
|
1150
|
+
else if (n.kind === "pattern") typePrefix = "pattern";
|
|
1151
|
+
else typePrefix = "learning";
|
|
1152
|
+
typeIdToBrainNodeId.set(`${typePrefix}:${rawId}`, n.id);
|
|
1153
|
+
}
|
|
1154
|
+
const pageEdgeRows = allTyped(db.prepare(`SELECT from_id, to_id, edge_type, weight FROM main.brain_page_edges`));
|
|
1155
|
+
for (const row of pageEdgeRows) {
|
|
1156
|
+
const sourceBrainNodeId = typeIdToBrainNodeId.get(row.from_id) ?? brainTypeIdToBrainNodeId(row.from_id);
|
|
1157
|
+
if (!sourceBrainNodeId) continue;
|
|
1158
|
+
if (isTaskId(row.to_id)) edges.push({
|
|
1159
|
+
source: sourceBrainNodeId,
|
|
1160
|
+
target: taskRefToBrainNodeId(row.to_id),
|
|
1161
|
+
type: row.edge_type,
|
|
1162
|
+
weight: row.weight ?? .5,
|
|
1163
|
+
substrate: "cross"
|
|
1164
|
+
});
|
|
1165
|
+
else if (isNexusStyleId(row.to_id)) edges.push({
|
|
1289
1166
|
source: sourceBrainNodeId,
|
|
1290
|
-
target:
|
|
1167
|
+
target: `nexus:${row.to_id}`,
|
|
1291
1168
|
type: row.edge_type,
|
|
1292
1169
|
weight: row.weight ?? .5,
|
|
1293
|
-
substrate: "
|
|
1170
|
+
substrate: "cross"
|
|
1294
1171
|
});
|
|
1172
|
+
else {
|
|
1173
|
+
const targetBrainNodeId = typeIdToBrainNodeId.get(row.to_id) ?? brainTypeIdToBrainNodeId(row.to_id);
|
|
1174
|
+
if (targetBrainNodeId) edges.push({
|
|
1175
|
+
source: sourceBrainNodeId,
|
|
1176
|
+
target: targetBrainNodeId,
|
|
1177
|
+
type: row.edge_type,
|
|
1178
|
+
weight: row.weight ?? .5,
|
|
1179
|
+
substrate: "brain"
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1295
1182
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
if (!sourceBrainNodeId) continue;
|
|
1303
|
-
edges.push({
|
|
1304
|
-
source: sourceBrainNodeId,
|
|
1305
|
-
target: `tasks:${row.task_id}`,
|
|
1306
|
-
type: row.link_type,
|
|
1307
|
-
weight: .7,
|
|
1308
|
-
substrate: "cross"
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
for (const row of obsRows) {
|
|
1312
|
-
if (!row.files_modified_json) continue;
|
|
1313
|
-
let filePaths;
|
|
1314
|
-
try {
|
|
1315
|
-
filePaths = JSON.parse(row.files_modified_json);
|
|
1316
|
-
} catch {
|
|
1317
|
-
continue;
|
|
1318
|
-
}
|
|
1319
|
-
if (!Array.isArray(filePaths)) continue;
|
|
1320
|
-
const sourceBrainNodeId = `brain:${row.id}`;
|
|
1321
|
-
for (const rawPath of filePaths) {
|
|
1322
|
-
if (typeof rawPath !== "string" || rawPath.length === 0) continue;
|
|
1183
|
+
const memLinkRows = allTyped(db.prepare(`SELECT memory_type, memory_id, task_id, link_type
|
|
1184
|
+
FROM main.brain_memory_links`));
|
|
1185
|
+
for (const row of memLinkRows) {
|
|
1186
|
+
const sourceTypeId = `${row.memory_type}:${row.memory_id}`;
|
|
1187
|
+
const sourceBrainNodeId = typeIdToBrainNodeId.get(sourceTypeId) ?? brainTypeIdToBrainNodeId(sourceTypeId);
|
|
1188
|
+
if (!sourceBrainNodeId) continue;
|
|
1323
1189
|
edges.push({
|
|
1324
1190
|
source: sourceBrainNodeId,
|
|
1325
|
-
target: `
|
|
1326
|
-
type:
|
|
1327
|
-
weight: .
|
|
1191
|
+
target: `tasks:${row.task_id}`,
|
|
1192
|
+
type: row.link_type,
|
|
1193
|
+
weight: .7,
|
|
1328
1194
|
substrate: "cross"
|
|
1329
1195
|
});
|
|
1330
1196
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1197
|
+
for (const row of obsRows) {
|
|
1198
|
+
if (!row.files_modified_json) continue;
|
|
1199
|
+
let filePaths;
|
|
1200
|
+
try {
|
|
1201
|
+
filePaths = JSON.parse(row.files_modified_json);
|
|
1202
|
+
} catch {
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
if (!Array.isArray(filePaths)) continue;
|
|
1206
|
+
const sourceBrainNodeId = `brain:${row.id}`;
|
|
1207
|
+
for (const rawPath of filePaths) {
|
|
1208
|
+
if (typeof rawPath !== "string" || rawPath.length === 0) continue;
|
|
1209
|
+
edges.push({
|
|
1210
|
+
source: sourceBrainNodeId,
|
|
1211
|
+
target: `nexus:${rawPath}`,
|
|
1212
|
+
type: "modified_by",
|
|
1213
|
+
weight: .6,
|
|
1214
|
+
substrate: "cross"
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
for (const dec of decRows) if (dec.context_task_id) edges.push({
|
|
1219
|
+
source: `brain:${dec.id}`,
|
|
1220
|
+
target: `tasks:${dec.context_task_id}`,
|
|
1221
|
+
type: "applies_to",
|
|
1222
|
+
weight: .8,
|
|
1223
|
+
substrate: "cross"
|
|
1224
|
+
});
|
|
1225
|
+
} catch {}
|
|
1226
|
+
});
|
|
1340
1227
|
return {
|
|
1341
1228
|
nodes,
|
|
1342
1229
|
edges
|
|
@@ -1347,85 +1234,74 @@ function getBrainSubstrate(options = {}) {
|
|
|
1347
1234
|
/**
|
|
1348
1235
|
* CONDUIT substrate adapter for the Living Brain API.
|
|
1349
1236
|
*
|
|
1350
|
-
* Queries
|
|
1237
|
+
* Queries the project `cleo.db` (`conduit_messages`) and returns
|
|
1238
|
+
* BrainNodes/BrainEdges for agent-to-agent messages.
|
|
1351
1239
|
* Each message becomes a node; `from_agent_id → to_agent_id` becomes an edge.
|
|
1352
|
-
* Co-authoring agent pairs produce cross-substrate edges to
|
|
1240
|
+
* Co-authoring agent pairs produce cross-substrate edges to AGENT-REGISTRY.
|
|
1353
1241
|
*
|
|
1354
1242
|
* Node IDs are prefixed with "conduit:" to prevent collisions.
|
|
1355
1243
|
*/
|
|
1356
1244
|
/**
|
|
1357
|
-
*
|
|
1358
|
-
* Returns null when the value is not a finite positive number.
|
|
1359
|
-
*
|
|
1360
|
-
* @param epoch - UNIX timestamp in seconds.
|
|
1361
|
-
* @returns ISO-8601 string or null.
|
|
1362
|
-
*/
|
|
1363
|
-
function epochToIso(epoch) {
|
|
1364
|
-
if (!Number.isFinite(epoch) || epoch <= 0) return null;
|
|
1365
|
-
return (/* @__PURE__ */ new Date(epoch * 1e3)).toISOString();
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
* Returns all BrainNodes and BrainEdges sourced from conduit.db.
|
|
1245
|
+
* Returns all BrainNodes and BrainEdges sourced from `conduit_messages`.
|
|
1369
1246
|
*
|
|
1370
1247
|
* Fetches the most recent messages (capped at perSubstrateLimit).
|
|
1371
1248
|
* Synthesizes agent→agent edges and cross-substrate agent references
|
|
1372
|
-
* pointing to
|
|
1249
|
+
* pointing to the agent registry.
|
|
1373
1250
|
*
|
|
1374
1251
|
* @param options - Query options (limit).
|
|
1375
1252
|
* @returns Nodes and edges from the CONDUIT substrate.
|
|
1376
1253
|
*/
|
|
1377
1254
|
function getConduitSubstrate(options = {}) {
|
|
1378
|
-
const
|
|
1379
|
-
if (!db) return {
|
|
1380
|
-
nodes: [],
|
|
1381
|
-
edges: []
|
|
1382
|
-
};
|
|
1255
|
+
const ctx = options.projectCtx ?? resolveDefaultProjectContext();
|
|
1383
1256
|
const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
|
|
1384
1257
|
const nodes = [];
|
|
1385
1258
|
const edges = [];
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1259
|
+
readProjectStore(ctx, (db) => {
|
|
1260
|
+
try {
|
|
1261
|
+
const msgRows = allTyped(db.prepare(`SELECT id, content, from_agent_id, to_agent_id,
|
|
1262
|
+
strftime('%Y-%m-%dT%H:%M:%S', created_at) AS created_at, conversation_id
|
|
1263
|
+
FROM main.conduit_messages
|
|
1389
1264
|
ORDER BY created_at DESC
|
|
1390
1265
|
LIMIT ?`), perSubstrateLimit);
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1266
|
+
const agentPairs = /* @__PURE__ */ new Map();
|
|
1267
|
+
for (const row of msgRows) {
|
|
1268
|
+
const label = row.content.length > 80 ? `${row.content.slice(0, 80)}…` : row.content;
|
|
1269
|
+
nodes.push({
|
|
1270
|
+
id: `conduit:${row.id}`,
|
|
1271
|
+
kind: "message",
|
|
1272
|
+
substrate: "conduit",
|
|
1273
|
+
label,
|
|
1274
|
+
createdAt: row.created_at,
|
|
1275
|
+
meta: {
|
|
1276
|
+
from_agent_id: row.from_agent_id,
|
|
1277
|
+
to_agent_id: row.to_agent_id,
|
|
1278
|
+
conversation_id: row.conversation_id,
|
|
1279
|
+
created_at: row.created_at
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
if (row.from_agent_id && row.to_agent_id) {
|
|
1283
|
+
const key = `${row.from_agent_id}→${row.to_agent_id}`;
|
|
1284
|
+
const existing = agentPairs.get(key);
|
|
1285
|
+
if (existing) existing.count++;
|
|
1286
|
+
else agentPairs.set(key, {
|
|
1287
|
+
count: 1,
|
|
1288
|
+
from: row.from_agent_id,
|
|
1289
|
+
to: row.to_agent_id
|
|
1290
|
+
});
|
|
1405
1291
|
}
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1292
|
+
}
|
|
1293
|
+
for (const [, pair] of agentPairs) {
|
|
1294
|
+
const weight = Math.min(1, pair.count / 10);
|
|
1295
|
+
edges.push({
|
|
1296
|
+
source: `agent-registry:${pair.from}`,
|
|
1297
|
+
target: `agent-registry:${pair.to}`,
|
|
1298
|
+
type: "messages",
|
|
1299
|
+
weight,
|
|
1300
|
+
substrate: "cross"
|
|
1415
1301
|
});
|
|
1416
1302
|
}
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
const weight = Math.min(1, pair.count / 10);
|
|
1420
|
-
edges.push({
|
|
1421
|
-
source: `agent-registry:${pair.from}`,
|
|
1422
|
-
target: `agent-registry:${pair.to}`,
|
|
1423
|
-
type: "messages",
|
|
1424
|
-
weight,
|
|
1425
|
-
substrate: "cross"
|
|
1426
|
-
});
|
|
1427
|
-
}
|
|
1428
|
-
} catch {}
|
|
1303
|
+
} catch {}
|
|
1304
|
+
});
|
|
1429
1305
|
return {
|
|
1430
1306
|
nodes,
|
|
1431
1307
|
edges
|
|
@@ -1436,7 +1312,9 @@ function getConduitSubstrate(options = {}) {
|
|
|
1436
1312
|
/**
|
|
1437
1313
|
* NEXUS substrate adapter for the Living Brain API.
|
|
1438
1314
|
*
|
|
1439
|
-
* Queries
|
|
1315
|
+
* Queries the code graph in the project `cleo.db` (`nexus_nodes`,
|
|
1316
|
+
* `nexus_relations`; project-resident per ADR-090) and returns
|
|
1317
|
+
* BrainNodes/BrainEdges for code symbols and files.
|
|
1440
1318
|
* Prioritises high-in-degree nodes (most-called functions, most-imported files)
|
|
1441
1319
|
* since the full nexus graph can exceed 10k nodes.
|
|
1442
1320
|
*
|
|
@@ -1448,28 +1326,25 @@ function mapKind(nexusKind) {
|
|
|
1448
1326
|
return "symbol";
|
|
1449
1327
|
}
|
|
1450
1328
|
/**
|
|
1451
|
-
* Returns all BrainNodes and BrainEdges sourced from
|
|
1329
|
+
* Returns all BrainNodes and BrainEdges sourced from the project code graph.
|
|
1452
1330
|
*
|
|
1453
1331
|
* Fetches the highest in-degree nodes (capped at perSubstrateLimit) and
|
|
1454
1332
|
* all relations between those nodes.
|
|
1455
1333
|
*
|
|
1456
|
-
* @param options - Query options (limit,
|
|
1334
|
+
* @param options - Query options (limit, projectCtx).
|
|
1457
1335
|
* @returns Nodes and edges from the NEXUS substrate.
|
|
1458
1336
|
*/
|
|
1459
1337
|
function getNexusSubstrate(options = {}) {
|
|
1460
|
-
const
|
|
1461
|
-
if (!db) return {
|
|
1462
|
-
nodes: [],
|
|
1463
|
-
edges: []
|
|
1464
|
-
};
|
|
1338
|
+
const ctx = options.projectCtx ?? resolveDefaultProjectContext();
|
|
1465
1339
|
const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
|
|
1466
1340
|
const nodes = [];
|
|
1467
1341
|
const edges = [];
|
|
1468
|
-
|
|
1469
|
-
|
|
1342
|
+
readProjectStore(ctx, (db) => {
|
|
1343
|
+
try {
|
|
1344
|
+
const nodeRows = allTyped(db.prepare(`SELECT n.id, n.kind, COALESCE(n.name, n.label) AS name, n.indexed_at,
|
|
1470
1345
|
COUNT(r.target_id) AS in_degree
|
|
1471
|
-
FROM nexus_nodes n
|
|
1472
|
-
LEFT JOIN nexus_relations r ON r.target_id = n.id
|
|
1346
|
+
FROM main.nexus_nodes n
|
|
1347
|
+
LEFT JOIN main.nexus_relations r ON r.target_id = n.id
|
|
1473
1348
|
WHERE n.kind IN (
|
|
1474
1349
|
'file', 'function', 'method', 'class', 'interface',
|
|
1475
1350
|
'type_alias', 'constant', 'module', 'enum'
|
|
@@ -1477,37 +1352,35 @@ function getNexusSubstrate(options = {}) {
|
|
|
1477
1352
|
GROUP BY n.id
|
|
1478
1353
|
ORDER BY in_degree DESC
|
|
1479
1354
|
LIMIT ?`), perSubstrateLimit);
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
};
|
|
1499
|
-
const relRows = allTyped(db.prepare(`SELECT source_id, target_id, type, confidence
|
|
1500
|
-
FROM nexus_relations
|
|
1355
|
+
for (const row of nodeRows) nodes.push({
|
|
1356
|
+
id: `nexus:${row.id}`,
|
|
1357
|
+
kind: mapKind(row.kind),
|
|
1358
|
+
substrate: "nexus",
|
|
1359
|
+
label: row.name,
|
|
1360
|
+
weight: row.in_degree > 0 ? Math.min(1, row.in_degree / 50) : void 0,
|
|
1361
|
+
createdAt: row.indexed_at ?? null,
|
|
1362
|
+
meta: {
|
|
1363
|
+
nexus_kind: row.kind,
|
|
1364
|
+
in_degree: row.in_degree
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
const nodeIds = new Set(nodes.map((n) => n.id));
|
|
1368
|
+
const rawIds = new Set([...nodeIds].map((id) => id.replace(/^nexus:/, "")));
|
|
1369
|
+
const placeholders = [...rawIds].map(() => "?").join(",");
|
|
1370
|
+
if (rawIds.size === 0) return;
|
|
1371
|
+
const relRows = allTyped(db.prepare(`SELECT source_id, target_id, type, confidence
|
|
1372
|
+
FROM main.nexus_relations
|
|
1501
1373
|
WHERE source_id IN (${placeholders})
|
|
1502
1374
|
AND target_id IN (${placeholders})`), ...rawIds, ...rawIds);
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1375
|
+
for (const row of relRows) edges.push({
|
|
1376
|
+
source: `nexus:${row.source_id}`,
|
|
1377
|
+
target: `nexus:${row.target_id}`,
|
|
1378
|
+
type: row.type,
|
|
1379
|
+
weight: row.confidence ?? .5,
|
|
1380
|
+
substrate: "nexus"
|
|
1381
|
+
});
|
|
1382
|
+
} catch {}
|
|
1383
|
+
});
|
|
1511
1384
|
return {
|
|
1512
1385
|
nodes,
|
|
1513
1386
|
edges
|
|
@@ -1518,7 +1391,9 @@ function getNexusSubstrate(options = {}) {
|
|
|
1518
1391
|
/**
|
|
1519
1392
|
* TASKS substrate adapter for the Living Brain API.
|
|
1520
1393
|
*
|
|
1521
|
-
* Queries
|
|
1394
|
+
* Queries the project `cleo.db` (`tasks_tasks`, `tasks_sessions`,
|
|
1395
|
+
* `tasks_task_relations`, `tasks_task_dependencies`) and returns
|
|
1396
|
+
* BrainNodes/BrainEdges for tasks and sessions.
|
|
1522
1397
|
* Prioritises critical/high priority tasks and active sessions.
|
|
1523
1398
|
*
|
|
1524
1399
|
* Node IDs are prefixed with "tasks:" to prevent collisions.
|
|
@@ -1533,7 +1408,7 @@ function priorityWeight(priority) {
|
|
|
1533
1408
|
}[priority] ?? .25;
|
|
1534
1409
|
}
|
|
1535
1410
|
/**
|
|
1536
|
-
* Returns all BrainNodes and BrainEdges sourced from
|
|
1411
|
+
* Returns all BrainNodes and BrainEdges sourced from the project `cleo.db`.
|
|
1537
1412
|
*
|
|
1538
1413
|
* Fetches tasks ordered by priority, plus recent sessions.
|
|
1539
1414
|
* Synthesizes parent→child, dependency, and relation edges.
|
|
@@ -1542,18 +1417,15 @@ function priorityWeight(priority) {
|
|
|
1542
1417
|
* @returns Nodes and edges from the TASKS substrate.
|
|
1543
1418
|
*/
|
|
1544
1419
|
function getTasksSubstrate(options = {}) {
|
|
1545
|
-
const
|
|
1546
|
-
if (!db) return {
|
|
1547
|
-
nodes: [],
|
|
1548
|
-
edges: []
|
|
1549
|
-
};
|
|
1420
|
+
const ctx = options.projectCtx ?? resolveDefaultProjectContext();
|
|
1550
1421
|
const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
|
|
1551
1422
|
const minWeight = options.minWeight ?? 0;
|
|
1552
1423
|
const nodes = [];
|
|
1553
1424
|
const edges = [];
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1425
|
+
readProjectStore(ctx, (db) => {
|
|
1426
|
+
try {
|
|
1427
|
+
const taskRows = allTyped(db.prepare(`SELECT id, title, status, priority, type, parent_id, created_at
|
|
1428
|
+
FROM main.tasks_tasks
|
|
1557
1429
|
WHERE status NOT IN ('archived', 'cancelled')
|
|
1558
1430
|
ORDER BY
|
|
1559
1431
|
CASE priority
|
|
@@ -1561,81 +1433,82 @@ function getTasksSubstrate(options = {}) {
|
|
|
1561
1433
|
END,
|
|
1562
1434
|
created_at DESC
|
|
1563
1435
|
LIMIT ?`), Math.ceil(perSubstrateLimit * .8));
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
FROM
|
|
1436
|
+
const taskIds = /* @__PURE__ */ new Set();
|
|
1437
|
+
for (const row of taskRows) {
|
|
1438
|
+
const weight = priorityWeight(row.priority);
|
|
1439
|
+
if (weight < minWeight) continue;
|
|
1440
|
+
taskIds.add(row.id);
|
|
1441
|
+
nodes.push({
|
|
1442
|
+
id: `tasks:${row.id}`,
|
|
1443
|
+
kind: "task",
|
|
1444
|
+
substrate: "tasks",
|
|
1445
|
+
label: row.title,
|
|
1446
|
+
weight,
|
|
1447
|
+
createdAt: row.created_at,
|
|
1448
|
+
meta: {
|
|
1449
|
+
status: row.status,
|
|
1450
|
+
priority: row.priority,
|
|
1451
|
+
type: row.type,
|
|
1452
|
+
parent_id: row.parent_id,
|
|
1453
|
+
created_at: row.created_at
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
const sessionRows = allTyped(db.prepare(`SELECT id, status, started_at, ended_at
|
|
1458
|
+
FROM main.tasks_sessions
|
|
1587
1459
|
ORDER BY started_at DESC
|
|
1588
1460
|
LIMIT ?`), Math.ceil(perSubstrateLimit * .2));
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
substrate: "tasks"
|
|
1612
|
-
});
|
|
1613
|
-
if (taskIds.size > 0) {
|
|
1614
|
-
const placeholders = [...taskIds].map(() => "?").join(",");
|
|
1615
|
-
const relRows = allTyped(db.prepare(`SELECT task_id, related_task_id, relation_type
|
|
1616
|
-
FROM task_relations
|
|
1617
|
-
WHERE task_id IN (${placeholders})
|
|
1618
|
-
AND related_task_id IN (${placeholders})`), ...taskIds, ...taskIds);
|
|
1619
|
-
for (const row of relRows) edges.push({
|
|
1620
|
-
source: `tasks:${row.task_id}`,
|
|
1621
|
-
target: `tasks:${row.related_task_id}`,
|
|
1622
|
-
type: row.relation_type,
|
|
1623
|
-
weight: .7,
|
|
1461
|
+
const sessionIds = /* @__PURE__ */ new Set();
|
|
1462
|
+
for (const row of sessionRows) {
|
|
1463
|
+
sessionIds.add(row.id);
|
|
1464
|
+
nodes.push({
|
|
1465
|
+
id: `tasks:${row.id}`,
|
|
1466
|
+
kind: "session",
|
|
1467
|
+
substrate: "tasks",
|
|
1468
|
+
label: `Session ${row.id.slice(-8)}`,
|
|
1469
|
+
weight: row.status === "active" ? .9 : .4,
|
|
1470
|
+
createdAt: row.started_at,
|
|
1471
|
+
meta: {
|
|
1472
|
+
status: row.status,
|
|
1473
|
+
started_at: row.started_at,
|
|
1474
|
+
ended_at: row.ended_at
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
for (const row of taskRows) if (row.parent_id && taskIds.has(row.parent_id)) edges.push({
|
|
1479
|
+
source: `tasks:${row.parent_id}`,
|
|
1480
|
+
target: `tasks:${row.id}`,
|
|
1481
|
+
type: "parent_of",
|
|
1482
|
+
weight: .9,
|
|
1624
1483
|
substrate: "tasks"
|
|
1625
1484
|
});
|
|
1626
|
-
|
|
1627
|
-
|
|
1485
|
+
if (taskIds.size > 0) {
|
|
1486
|
+
const placeholders = [...taskIds].map(() => "?").join(",");
|
|
1487
|
+
const relRows = allTyped(db.prepare(`SELECT task_id, related_to, relation_type
|
|
1488
|
+
FROM main.tasks_task_relations
|
|
1628
1489
|
WHERE task_id IN (${placeholders})
|
|
1629
|
-
AND
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1490
|
+
AND related_to IN (${placeholders})`), ...taskIds, ...taskIds);
|
|
1491
|
+
for (const row of relRows) edges.push({
|
|
1492
|
+
source: `tasks:${row.task_id}`,
|
|
1493
|
+
target: `tasks:${row.related_to}`,
|
|
1494
|
+
type: row.relation_type,
|
|
1495
|
+
weight: .7,
|
|
1496
|
+
substrate: "tasks"
|
|
1497
|
+
});
|
|
1498
|
+
const depRows = allTyped(db.prepare(`SELECT task_id, depends_on
|
|
1499
|
+
FROM main.tasks_task_dependencies
|
|
1500
|
+
WHERE task_id IN (${placeholders})
|
|
1501
|
+
AND depends_on IN (${placeholders})`), ...taskIds, ...taskIds);
|
|
1502
|
+
for (const row of depRows) edges.push({
|
|
1503
|
+
source: `tasks:${row.task_id}`,
|
|
1504
|
+
target: `tasks:${row.depends_on}`,
|
|
1505
|
+
type: "depends_on",
|
|
1506
|
+
weight: .85,
|
|
1507
|
+
substrate: "tasks"
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
} catch {}
|
|
1511
|
+
});
|
|
1639
1512
|
return {
|
|
1640
1513
|
nodes,
|
|
1641
1514
|
edges
|
|
@@ -1670,9 +1543,10 @@ var ADAPTER_MAP = {
|
|
|
1670
1543
|
*
|
|
1671
1544
|
* @param loadedNodeIds - Set of already-loaded node IDs (substrate-prefixed).
|
|
1672
1545
|
* @param edges - All edges collected from substrates (may reference unloaded targets).
|
|
1546
|
+
* @param ctx - Project whose `cleo.db` code graph resolves nexus stubs.
|
|
1673
1547
|
* @returns Array of stub BrainNode objects for missing targets.
|
|
1674
1548
|
*/
|
|
1675
|
-
function loadStubNodesForEdgeTargets(loadedNodeIds, edges) {
|
|
1549
|
+
function loadStubNodesForEdgeTargets(loadedNodeIds, edges, ctx) {
|
|
1676
1550
|
const missingTargetIds = /* @__PURE__ */ new Set();
|
|
1677
1551
|
for (const edge of edges) if (!loadedNodeIds.has(edge.target)) missingTargetIds.add(edge.target);
|
|
1678
1552
|
if (missingTargetIds.size === 0) return [];
|
|
@@ -1693,13 +1567,12 @@ function loadStubNodesForEdgeTargets(loadedNodeIds, edges) {
|
|
|
1693
1567
|
}
|
|
1694
1568
|
const stubs = [];
|
|
1695
1569
|
const nexusStubs = stubsBySubstrate.get("nexus");
|
|
1696
|
-
if (nexusStubs && nexusStubs.length > 0) {
|
|
1697
|
-
|
|
1698
|
-
if (db) try {
|
|
1570
|
+
if (nexusStubs && nexusStubs.length > 0) readProjectStore(ctx, (db) => {
|
|
1571
|
+
try {
|
|
1699
1572
|
const rawNexusIds = nexusStubs.map((id) => id.replace(/^nexus:/, ""));
|
|
1700
1573
|
const placeholders = rawNexusIds.map(() => "?").join(",");
|
|
1701
|
-
const stubRows = allTyped(db.prepare(`SELECT id, kind, name
|
|
1702
|
-
FROM nexus_nodes
|
|
1574
|
+
const stubRows = allTyped(db.prepare(`SELECT id, kind, COALESCE(name, label) AS name
|
|
1575
|
+
FROM main.nexus_nodes
|
|
1703
1576
|
WHERE id IN (${placeholders})`), ...rawNexusIds);
|
|
1704
1577
|
for (const row of stubRows) {
|
|
1705
1578
|
const kind = row.kind === "file" || row.kind === "folder" || row.kind === "module" ? "file" : "symbol";
|
|
@@ -1717,7 +1590,7 @@ function loadStubNodesForEdgeTargets(loadedNodeIds, edges) {
|
|
|
1717
1590
|
});
|
|
1718
1591
|
}
|
|
1719
1592
|
} catch {}
|
|
1720
|
-
}
|
|
1593
|
+
});
|
|
1721
1594
|
for (const [substrate, nodeIds] of stubsBySubstrate) {
|
|
1722
1595
|
if (substrate === "nexus") continue;
|
|
1723
1596
|
for (const nodeId of nodeIds) {
|
|
@@ -1778,7 +1651,7 @@ function getAllSubstrates(options = {}) {
|
|
|
1778
1651
|
uniqueNodes.push(node);
|
|
1779
1652
|
}
|
|
1780
1653
|
const requestedSubstrateSet = options.substrates ? new Set(options.substrates) : null;
|
|
1781
|
-
const stubNodes = loadStubNodesForEdgeTargets(seenIds, allEdges);
|
|
1654
|
+
const stubNodes = loadStubNodesForEdgeTargets(seenIds, allEdges, options.projectCtx ?? resolveDefaultProjectContext());
|
|
1782
1655
|
for (const stubNode of stubNodes) if (!seenIds.has(stubNode.id)) {
|
|
1783
1656
|
if (requestedSubstrateSet && !requestedSubstrateSet.has(stubNode.substrate)) continue;
|
|
1784
1657
|
seenIds.add(stubNode.id);
|
|
@@ -1796,5 +1669,5 @@ function getAllSubstrates(options = {}) {
|
|
|
1796
1669
|
};
|
|
1797
1670
|
}
|
|
1798
1671
|
|
|
1799
|
-
export {
|
|
1800
|
-
//# sourceMappingURL=src-
|
|
1672
|
+
export { getAllSubstrates as g, readProjectStore as r };
|
|
1673
|
+
//# sourceMappingURL=src-DMQE8esV.js.map
|