66import { execFileSync } from 'node:child_process' ;
77import { writeFile , chmod , access , constants , readFile } from 'node:fs/promises' ;
88import { join , extname } from 'node:path' ;
9- import { initGraph , loadGraph } from '../graph.js' ;
10- import { createEdge , queryEdges , removeEdge } from '../edges.js' ;
11- import { getNodes , getNode , getNodesByPrefix , setNodeProperty , unsetNodeProperty } from '../nodes.js' ;
9+ import { initGraph } from '../graph.js' ;
10+ import { createEdge , removeEdge } from '../edges.js' ;
11+ import { getNode , setNodeProperty , unsetNodeProperty } from '../nodes.js' ;
1212import { computeStatus } from '../status.js' ;
1313import { importFile } from '../import.js' ;
1414import { importFromMarkdown } from '../frontmatter.js' ;
@@ -62,11 +62,11 @@ export async function resolveContext(cwd, envelope) {
6262 let graph ;
6363
6464 if ( asOf === 'HEAD' ) {
65- graph = await loadGraph ( cwd , { writerId : 'ctx-reader' } ) ;
65+ graph = await initGraph ( cwd , { writerId : 'ctx-reader' } ) ;
6666 } else {
6767 // Time-travel: resolve git ref → Lamport tick → materialize
6868 // Use a separate resolver instance so we can materialize a fresh one.
69- const resolver = await loadGraph ( cwd , { writerId : 'ctx-resolver' } ) ;
69+ const resolver = await initGraph ( cwd , { writerId : 'ctx-resolver' } ) ;
7070 const result = await getEpochForRef ( resolver , cwd , asOf ) ;
7171 if ( ! result ) {
7272 throw new Error (
@@ -76,7 +76,7 @@ export async function resolveContext(cwd, envelope) {
7676 }
7777 resolvedTick = result . epoch . tick ;
7878 // materialize({ ceiling }) is destructive — use a dedicated instance
79- graph = await loadGraph ( cwd , { writerId : 'ctx-temporal' } ) ;
79+ graph = await initGraph ( cwd , { writerId : 'ctx-temporal' } ) ;
8080 await graph . materialize ( { ceiling : resolvedTick } ) ;
8181 }
8282
@@ -139,7 +139,7 @@ export async function link(cwd, source, target, opts = {}) {
139139 const tgt = opts . remote ? qualifyNodeId ( target , opts . remote ) : target ;
140140
141141 try {
142- const graph = await loadGraph ( cwd ) ;
142+ const graph = await initGraph ( cwd ) ;
143143 await createEdge ( graph , { source : src , target : tgt , type, confidence : opts . confidence } ) ;
144144 console . log ( success ( `${ src } --[${ type } ]--> ${ tgt } ` ) ) ;
145145 } catch ( err ) {
@@ -208,8 +208,14 @@ export async function view(cwd, viewSpec, opts = {}) {
208208 */
209209export async function list ( cwd , filter = { } ) {
210210 try {
211- const graph = await loadGraph ( cwd ) ;
212- const edges = await queryEdges ( graph , filter ) ;
211+ const graph = await initGraph ( cwd ) ;
212+ const allEdges = await graph . getEdges ( ) ;
213+ const edges = allEdges . filter ( edge => {
214+ if ( filter . source && edge . from !== filter . source ) return false ;
215+ if ( filter . target && edge . to !== filter . target ) return false ;
216+ if ( filter . type && edge . label !== filter . type ) return false ;
217+ return true ;
218+ } ) ;
213219
214220 if ( edges . length === 0 ) {
215221 console . log ( info ( 'No edges found' ) ) ;
@@ -237,7 +243,7 @@ export async function remove(cwd, source, target, opts = {}) {
237243 const type = opts . type ?? 'relates-to' ;
238244
239245 try {
240- const graph = await loadGraph ( cwd ) ;
246+ const graph = await initGraph ( cwd ) ;
241247 await removeEdge ( graph , source , target , type ) ;
242248 console . log ( success ( `Removed: ${ source } --[${ type } ]--> ${ target } ` ) ) ;
243249 } catch ( err ) {
@@ -299,7 +305,7 @@ export async function processCommitCmd(cwd, sha) {
299305 try {
300306 execFileSync ( 'git' , [ 'rev-parse' , '--verify' , sha ] , { cwd, encoding : 'utf-8' } ) ;
301307 const message = execFileSync ( 'git' , [ 'log' , '-1' , '--format=%B' , sha ] , { cwd, encoding : 'utf-8' } ) ;
302- const graph = await loadGraph ( cwd ) ;
308+ const graph = await initGraph ( cwd ) ;
303309 const directives = await processCommit ( graph , { sha, message } ) ;
304310
305311 if ( directives . length > 0 ) {
@@ -340,9 +346,10 @@ export async function nodes(cwd, opts = {}) {
340346 }
341347
342348 // List nodes (optionally filtered by prefix)
349+ const allNodes = await graph . getNodes ( ) ;
343350 const nodeList = opts . prefix
344- ? await getNodesByPrefix ( graph , opts . prefix )
345- : await getNodes ( graph ) ;
351+ ? allNodes . filter ( n => n . startsWith ( opts . prefix + ':' ) )
352+ : allNodes ;
346353
347354 if ( opts . json ) {
348355 outputJson ( 'nodes' , { nodes : nodeList , resolvedContext } ) ;
@@ -398,7 +405,7 @@ export async function at(cwd, ref, opts = {}) {
398405 }
399406
400407 try {
401- const graph = await loadGraph ( cwd ) ;
408+ const graph = await initGraph ( cwd ) ;
402409 const result = await getEpochForRef ( graph , cwd , ref ) ;
403410
404411 if ( ! result ) {
@@ -441,7 +448,7 @@ export async function at(cwd, ref, opts = {}) {
441448 */
442449export async function importCmd ( cwd , filePath , opts = { } ) {
443450 try {
444- const graph = await loadGraph ( cwd ) ;
451+ const graph = await initGraph ( cwd ) ;
445452 const result = await importFile ( graph , filePath , { dryRun : opts . dryRun } ) ;
446453
447454 if ( opts . json ) {
@@ -467,7 +474,7 @@ export async function importCmd(cwd, filePath, opts = {}) {
467474 */
468475export async function importMarkdownCmd ( cwd , pattern , opts = { } ) {
469476 try {
470- const graph = await loadGraph ( cwd ) ;
477+ const graph = await initGraph ( cwd ) ;
471478 const result = await importFromMarkdown ( graph , cwd , pattern , { dryRun : opts . dryRun } ) ;
472479
473480 if ( opts . json ) {
@@ -534,7 +541,7 @@ export async function mergeCmd(cwd, opts = {}) {
534541 }
535542
536543 try {
537- const graph = await loadGraph ( cwd ) ;
544+ const graph = await initGraph ( cwd ) ;
538545 const result = await mergeFromRepo ( graph , opts . from , {
539546 repoName : opts . repoName ,
540547 dryRun : opts . dryRun ,
@@ -594,7 +601,7 @@ export async function doctor(cwd, opts = {}) {
594601 */
595602export async function suggest ( cwd , opts = { } ) {
596603 try {
597- const graph = await loadGraph ( cwd ) ;
604+ const graph = await initGraph ( cwd ) ;
598605 const result = await generateSuggestions ( cwd , graph , {
599606 agent : opts . agent ,
600607 range : opts . context ,
@@ -618,7 +625,7 @@ export async function suggest(cwd, opts = {}) {
618625 */
619626export async function review ( cwd , opts = { } ) {
620627 try {
621- const graph = await loadGraph ( cwd ) ;
628+ const graph = await initGraph ( cwd ) ;
622629
623630 // Batch mode
624631 if ( opts . batch ) {
@@ -736,7 +743,7 @@ export async function set(cwd, nodeId, key, value, opts = {}) {
736743 }
737744
738745 try {
739- const graph = await loadGraph ( cwd ) ;
746+ const graph = await initGraph ( cwd ) ;
740747 const result = await setNodeProperty ( graph , nodeId , key , value ) ;
741748
742749 if ( opts . json ) {
@@ -769,7 +776,7 @@ export async function unsetCmd(cwd, nodeId, key, opts = {}) {
769776 }
770777
771778 try {
772- const graph = await loadGraph ( cwd ) ;
779+ const graph = await initGraph ( cwd ) ;
773780 const result = await unsetNodeProperty ( graph , nodeId , key ) ;
774781
775782 if ( opts . json ) {
@@ -838,7 +845,7 @@ export async function contentSet(cwd, nodeId, filePath, opts = {}) {
838845 const buf = await readFile ( filePath ) ;
839846 const mime = opts . mime ?? MIME_MAP [ extname ( filePath ) . toLowerCase ( ) ] ?? 'application/octet-stream' ;
840847
841- const graph = await loadGraph ( cwd ) ;
848+ const graph = await initGraph ( cwd ) ;
842849 const result = await writeContent ( graph , nodeId , buf , { mime } ) ;
843850
844851 if ( opts . json ) {
@@ -861,7 +868,7 @@ export async function contentSet(cwd, nodeId, filePath, opts = {}) {
861868 */
862869export async function contentShow ( cwd , nodeId , opts = { } ) {
863870 try {
864- const graph = await loadGraph ( cwd ) ;
871+ const graph = await initGraph ( cwd ) ;
865872 const { content, meta } = await readContent ( graph , nodeId ) ;
866873
867874 if ( opts . json ) {
@@ -890,7 +897,7 @@ export async function contentShow(cwd, nodeId, opts = {}) {
890897 */
891898export async function contentMeta ( cwd , nodeId , opts = { } ) {
892899 try {
893- const graph = await loadGraph ( cwd ) ;
900+ const graph = await initGraph ( cwd ) ;
894901 const meta = await getContentMeta ( graph , nodeId ) ;
895902
896903 if ( ! meta ) {
@@ -921,7 +928,7 @@ export async function contentMeta(cwd, nodeId, opts = {}) {
921928 */
922929export async function contentDelete ( cwd , nodeId , opts = { } ) {
923930 try {
924- const graph = await loadGraph ( cwd ) ;
931+ const graph = await initGraph ( cwd ) ;
925932 const result = await deleteContent ( graph , nodeId ) ;
926933
927934 if ( opts . json ) {
0 commit comments