cladogram 0.6.0-beta.2 → 0.6.0-beta.4

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.
@@ -9,6 +9,7 @@ import { editContent, paragraphs, paragraphLocations, contentLocation } from './
9
9
  import { markdownLinks } from '../core/links.js';
10
10
  import { blockMedia, findTargetLineOffset, formatTargetPoint, mediaBlockByIndex, mediaLinkLocations, mediaLinkTitle, mediaPointFits, mediaTargetPoint } from '../core/media-links.js';
11
11
  import { sortDiagnostics, summarizeDiagnostics } from '../core/diagnostics.js';
12
+ import { buildDocumentGraph, buildWorkspaceGraph } from './graph-snapshot.js';
12
13
 
13
14
  const copySnapshot = state => ({ ...state, documents: new Map(state.documents), templates: new Map(state.templates) });
14
15
  const required = (value, name) => { if (value === undefined || value === null || value === '') fail('缺少参数:' + name); return value; };
@@ -454,12 +455,20 @@ export function createWorkspaceService(scope, { documentRoot, readSelection } =
454
455
  }
455
456
  if (args.action === 'init' || args.action === 'inspect') return { ...common, documentRoot: ctx.documents, templateRoot: ctx.templates, ancestorTemplateRoots: ancestorRoots, documents: [...state.documents].map(([file, source]) => ({ file, version: versionOf(source), title: parseDocument(source).doc.title })) };
456
457
  if (args.action === 'validate') { const diagnostics = validate(state, state.documents.keys(), true); return { ...common, valid: !diagnostics.some(d => d.severity === 'error'), diagnostics }; }
458
+ if (args.action === 'graph') {
459
+ if (args.file) {
460
+ safeFile(ctx.documents, args.file);
461
+ if (!state.documents.has(args.file)) fail('文档不存在:' + args.file, 404);
462
+ return { ...common, ...buildDocumentGraph(args.file, state.documents) };
463
+ }
464
+ return { ...common, ...buildWorkspaceGraph(state.documents) };
465
+ }
457
466
  if (args.action === 'search') {
458
467
  const query = required(args.query, 'query').toLowerCase(), hits = [];
459
468
  for (const [file, source] of state.documents) for (const record of records(treeOf(source, file))) if ((file + '\n' + record.node.title + '\n' + record.node.content).toLowerCase().includes(query)) hits.push({ file, ...publicNode(record, args.includeContent === true) });
460
469
  return { ...common, total: hits.length, nodes: hits.slice(args.offset || 0, (args.offset || 0) + (args.limit || 50)) };
461
470
  }
462
- fail('workspace action 支持 init / inspect / validate / search / selection / workspaces。');
471
+ fail('workspace action 支持 init / inspect / validate / search / selection / workspaces / graph。');
463
472
  }
464
473
  if (tool === 'clado_templates' && ['list', 'read'].includes(args.action)) {
465
474
  const scope = args.scope || 'project', visible = scope === 'user' ? { templates: new Map(), userTemplates: userState.templates, userTemplateRoot: user.templates } : state;
@@ -495,6 +504,7 @@ export function createWorkspaceService(scope, { documentRoot, readSelection } =
495
504
  if (tool === 'clado_documents' && args.action === 'list') return { ...common, documents: [...state.documents].filter(([file, source]) => !args.query || (file + source).toLowerCase().includes(args.query.toLowerCase())).map(([file, source]) => { const item = treeOf(source, file); return { file, title: item.doc.title, version: item.version, hasHeader: splitFrontMatter(source).had, cards: item.doc.cards.length, diagnostics: item.diagnostics }; }) };
496
505
  if (tool === 'clado_documents' && args.action === 'read') {
497
506
  safeFile(ctx.documents, args.file); const source = state.documents.get(args.file); if (source === undefined) fail('文档不存在。', 404);
507
+ if (args.view === 'graph') return { ...common, ...buildDocumentGraph(args.file, state.documents) };
498
508
  const item = treeOf(source, args.file), all = records(item), identity = { ...common, file: args.file, version: item.version, title: item.doc.title };
499
509
  if (args.view === 'source') return { ...identity, source };
500
510
  if (args.view === 'summary') return { ...identity, cards: item.doc.cards.length, nodeCount: all.length, hasHeader: splitFrontMatter(source).had, templateId: item.doc.meta.id || null, templateVersion: item.doc.meta.version || null };