patram 0.7.0 → 0.9.0

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 (140) hide show
  1. package/bin/patram.js +2 -2
  2. package/lib/{parse-cli-color-options.js → cli/color-options.js} +2 -2
  3. package/lib/cli/command-helpers.js +35 -0
  4. package/lib/cli/commands/check.js +73 -0
  5. package/lib/cli/commands/fields.js +57 -0
  6. package/lib/cli/commands/queries.js +41 -0
  7. package/lib/cli/commands/query.js +239 -0
  8. package/lib/cli/commands/refs.js +72 -0
  9. package/lib/cli/commands/show.js +58 -0
  10. package/lib/{cli-help-metadata.js → cli/help-metadata.js} +54 -15
  11. package/lib/cli/main.js +76 -0
  12. package/lib/{parse-cli-arguments-helpers.js → cli/parse-arguments-helpers.js} +18 -11
  13. package/lib/{parse-cli-arguments.js → cli/parse-arguments.js} +12 -12
  14. package/lib/{parse-cli-query-pagination.js → cli/query-pagination.js} +2 -2
  15. package/lib/{render-cli-help.js → cli/render-help.js} +4 -4
  16. package/lib/{resolve-output-mode.js → cli/resolve-output-mode.js} +2 -2
  17. package/lib/cli/test-helpers.js +30 -0
  18. package/lib/config/defaults.d.ts +10 -0
  19. package/lib/config/defaults.js +80 -0
  20. package/lib/config/load-patram-config.d.ts +76 -0
  21. package/lib/config/load-patram-config.js +315 -0
  22. package/lib/config/load-patram-config.types.d.ts +45 -0
  23. package/lib/{patram-config.d.ts → config/patram-config.d.ts} +31 -31
  24. package/lib/{patram-config.js → config/patram-config.js} +3 -3
  25. package/lib/{patram-config.types.d.ts → config/patram-config.types.d.ts} +1 -1
  26. package/lib/{resolve-patram-graph-config.d.ts → config/resolve-patram-graph-config.d.ts} +2 -2
  27. package/lib/{resolve-patram-graph-config.js → config/resolve-patram-graph-config.js} +3 -3
  28. package/lib/{load-patram-config.d.ts → config/schema.d.ts} +147 -191
  29. package/lib/config/schema.js +324 -0
  30. package/lib/{source-file-defaults.d.ts → config/source-file-defaults.d.ts} +0 -1
  31. package/lib/{source-file-defaults.js → config/source-file-defaults.js} +1 -1
  32. package/lib/config/validation.d.ts +27 -0
  33. package/lib/config/validation.js +615 -0
  34. package/lib/directive-validation-test-helpers.js +1 -1
  35. package/lib/{build-graph-identity.d.ts → graph/build-graph-identity.d.ts} +2 -2
  36. package/lib/{build-graph-identity.js → graph/build-graph-identity.js} +1 -1
  37. package/lib/{build-graph.d.ts → graph/build-graph.d.ts} +3 -3
  38. package/lib/{build-graph.js → graph/build-graph.js} +17 -13
  39. package/lib/{build-graph.types.d.ts → graph/build-graph.types.d.ts} +1 -1
  40. package/lib/graph/check-directive-metadata.d.ts +23 -0
  41. package/lib/{check-directive-metadata.js → graph/check-directive-metadata.js} +7 -7
  42. package/lib/graph/check-directive-path-target.d.ts +32 -0
  43. package/lib/{check-directive-path-target.js → graph/check-directive-path-target.js} +4 -4
  44. package/lib/graph/check-directive-value.d.ts +19 -0
  45. package/lib/{check-directive-value.js → graph/check-directive-value.js} +3 -3
  46. package/lib/graph/check-graph.d.ts +29 -0
  47. package/lib/{check-graph.js → graph/check-graph.js} +6 -6
  48. package/lib/graph/directive-diagnostics.d.ts +20 -0
  49. package/lib/{directive-diagnostics.js → graph/directive-diagnostics.js} +2 -2
  50. package/lib/graph/directive-type-rules.d.ts +18 -0
  51. package/lib/{directive-type-rules.js → graph/directive-type-rules.js} +3 -3
  52. package/lib/{document-node-identity.d.ts → graph/document-node-identity.d.ts} +2 -2
  53. package/lib/{document-node-identity.js → graph/document-node-identity.js} +2 -2
  54. package/lib/graph/inspect-reverse-references.d.ts +22 -0
  55. package/lib/graph/inspect-reverse-references.js +184 -0
  56. package/lib/{load-project-graph.d.ts → graph/load-project-graph.d.ts} +10 -10
  57. package/lib/{load-project-graph.js → graph/load-project-graph.js} +12 -12
  58. package/lib/{parse-where-clause.types.d.ts → graph/parse-where-clause.types.d.ts} +1 -1
  59. package/lib/{query-graph.d.ts → graph/query/execute.d.ts} +11 -11
  60. package/lib/{query-graph.js → graph/query/execute.js} +12 -12
  61. package/lib/{query-inspection.d.ts → graph/query/inspect.d.ts} +10 -8
  62. package/lib/{query-inspection.js → graph/query/inspect.js} +16 -17
  63. package/lib/{parse-where-clause.d.ts → graph/query/parse.d.ts} +6 -6
  64. package/lib/{parse-where-clause.js → graph/query/parse.js} +2 -2
  65. package/lib/graph/query/resolve.d.ts +30 -0
  66. package/lib/{resolve-where-clause.js → graph/query/resolve.js} +1 -1
  67. package/lib/graph/reverse-reference-test-helpers.d.ts +55 -0
  68. package/lib/graph/reverse-reference-test-helpers.js +76 -0
  69. package/lib/{command-output.js → output/command-output.js} +6 -5
  70. package/lib/{derived-summary.js → output/derived-summary.js} +7 -7
  71. package/lib/output/layout-incoming-references.js +105 -0
  72. package/lib/output/layout-incoming-summary-lines.js +16 -0
  73. package/lib/{layout-stored-queries.js → output/layout-stored-queries.js} +9 -9
  74. package/lib/{list-queries.js → output/list-queries.js} +1 -1
  75. package/lib/{render-check-output.js → output/render-check-output.js} +1 -1
  76. package/lib/{render-field-discovery.js → output/render-field-discovery.js} +3 -3
  77. package/lib/output/render-output-view.js +56 -0
  78. package/lib/{render-json-output.js → output/renderers/json.js} +92 -63
  79. package/lib/{render-plain-output.js → output/renderers/plain.js} +62 -7
  80. package/lib/{render-rich-output.js → output/renderers/rich.js} +69 -8
  81. package/lib/{resolve-check-target.js → output/resolve-check-target.js} +1 -1
  82. package/lib/{render-rich-source.js → output/rich-source/render.js} +6 -6
  83. package/lib/{show-document.js → output/show-document.js} +54 -16
  84. package/lib/{render-output-view.js → output/view-model/index.js} +56 -47
  85. package/lib/{write-paged-output.js → output/write-paged-output.js} +9 -5
  86. package/lib/{claim-helpers.d.ts → parse/claim-helpers.d.ts} +2 -2
  87. package/lib/{parse-jsdoc-claims.d.ts → parse/jsdoc/parse-jsdoc-claims.d.ts} +2 -2
  88. package/lib/{parse-jsdoc-claims.js → parse/jsdoc/parse-jsdoc-claims.js} +9 -9
  89. package/lib/{parse-jsdoc-prose.d.ts → parse/jsdoc/parse-jsdoc-prose.d.ts} +1 -1
  90. package/lib/{parse-jsdoc-prose.js → parse/jsdoc/parse-jsdoc-prose.js} +1 -1
  91. package/lib/{parse-markdown-claims.d.ts → parse/markdown/parse-markdown-claims.d.ts} +3 -3
  92. package/lib/{parse-markdown-claims.js → parse/markdown/parse-markdown-claims.js} +8 -8
  93. package/lib/{parse-markdown-directives.d.ts → parse/markdown/parse-markdown-directives.d.ts} +2 -2
  94. package/lib/{parse-markdown-directives.js → parse/markdown/parse-markdown-directives.js} +3 -3
  95. package/lib/{parse-claims.d.ts → parse/parse-claims.d.ts} +4 -13
  96. package/lib/{parse-claims.js → parse/parse-claims.js} +18 -26
  97. package/lib/{parse-claims.types.d.ts → parse/parse-claims.types.d.ts} +1 -1
  98. package/lib/{tagged-fenced-block-error.d.ts → parse/tagged-fenced/tagged-fenced-block-error.d.ts} +2 -2
  99. package/lib/{tagged-fenced-block-parser.d.ts → parse/tagged-fenced/tagged-fenced-block-parser.d.ts} +3 -3
  100. package/lib/{tagged-fenced-blocks.d.ts → parse/tagged-fenced/tagged-fenced-blocks.d.ts} +7 -7
  101. package/lib/{tagged-fenced-blocks.js → parse/tagged-fenced/tagged-fenced-blocks.js} +3 -3
  102. package/lib/{parse-yaml-claims.d.ts → parse/yaml/parse-yaml-claims.d.ts} +4 -4
  103. package/lib/{parse-yaml-claims.js → parse/yaml/parse-yaml-claims.js} +22 -13
  104. package/lib/patram.d.ts +29 -28
  105. package/lib/patram.js +5 -6
  106. package/lib/{discover-fields.js → scan/discover-fields.js} +9 -8
  107. package/lib/scan/list-repo-files.d.ts +16 -0
  108. package/lib/{list-source-files.js → scan/list-repo-files.js} +2 -35
  109. package/lib/{list-source-files.d.ts → scan/list-source-files.d.ts} +4 -11
  110. package/lib/scan/list-source-files.js +45 -0
  111. package/package.json +8 -7
  112. package/lib/build-graph.types.ts +0 -27
  113. package/lib/discover-fields.types.ts +0 -52
  114. package/lib/load-patram-config.js +0 -1215
  115. package/lib/load-patram-config.types.d.ts +0 -45
  116. package/lib/load-patram-config.types.ts +0 -56
  117. package/lib/output-view.types.d.ts +0 -80
  118. package/lib/output-view.types.ts +0 -96
  119. package/lib/overlay-graph.d.ts +0 -43
  120. package/lib/overlay-graph.js +0 -191
  121. package/lib/parse-claims.types.ts +0 -41
  122. package/lib/parse-cli-arguments.types.ts +0 -69
  123. package/lib/parse-where-clause.types.ts +0 -87
  124. package/lib/patram-cli.js +0 -528
  125. package/lib/patram-config.types.ts +0 -22
  126. package/lib/tagged-fenced-blocks.types.ts +0 -38
  127. /package/lib/{format-derived-summary-row.js → output/format-derived-summary-row.js} +0 -0
  128. /package/lib/{format-node-header.js → output/format-node-header.js} +0 -0
  129. /package/lib/{format-output-item-block.js → output/format-output-item-block.js} +0 -0
  130. /package/lib/{format-output-metadata.js → output/format-output-metadata.js} +0 -0
  131. /package/lib/{claim-helpers.js → parse/claim-helpers.js} +0 -0
  132. /package/lib/{parse-jsdoc-blocks.d.ts → parse/jsdoc/parse-jsdoc-blocks.d.ts} +0 -0
  133. /package/lib/{parse-jsdoc-blocks.js → parse/jsdoc/parse-jsdoc-blocks.js} +0 -0
  134. /package/lib/{tagged-fenced-block-error.js → parse/tagged-fenced/tagged-fenced-block-error.js} +0 -0
  135. /package/lib/{tagged-fenced-block-markdown.d.ts → parse/tagged-fenced/tagged-fenced-block-markdown.d.ts} +0 -0
  136. /package/lib/{tagged-fenced-block-markdown.js → parse/tagged-fenced/tagged-fenced-block-markdown.js} +0 -0
  137. /package/lib/{tagged-fenced-block-metadata.d.ts → parse/tagged-fenced/tagged-fenced-block-metadata.d.ts} +0 -0
  138. /package/lib/{tagged-fenced-block-metadata.js → parse/tagged-fenced/tagged-fenced-block-metadata.js} +0 -0
  139. /package/lib/{tagged-fenced-block-parser.js → parse/tagged-fenced/tagged-fenced-block-parser.js} +0 -0
  140. /package/lib/{tagged-fenced-blocks.types.d.ts → parse/tagged-fenced/tagged-fenced-blocks.types.d.ts} +0 -0
@@ -1,15 +1,16 @@
1
1
  /* eslint-disable max-lines */
2
2
  /**
3
- * @import { GraphNode } from './build-graph.types.ts';
4
- * @import { PatramClaim } from './parse-claims.types.ts';
5
- * @import { PatramDiagnostic } from './load-patram-config.types.ts';
3
+ * @import { BuildGraphResult, GraphNode } from '../graph/build-graph.types.ts';
4
+ * @import { PatramClaim } from '../parse/parse-claims.types.ts';
5
+ * @import { PatramDiagnostic } from '../config/load-patram-config.types.ts';
6
6
  */
7
7
 
8
8
  import { readFile } from 'node:fs/promises';
9
9
  import { posix, relative, resolve } from 'node:path';
10
10
 
11
- import { resolveDocumentNodeId } from './build-graph-identity.js';
12
- import { parseSourceFile } from './parse-claims.js';
11
+ import { resolveDocumentNodeId } from '../graph/build-graph-identity.js';
12
+ import { inspectReverseReferences } from '../graph/inspect-reverse-references.js';
13
+ import { parseSourceFile } from '../parse/parse-claims.js';
13
14
 
14
15
  /**
15
16
  * Show command document rendering.
@@ -19,22 +20,23 @@ import { parseSourceFile } from './parse-claims.js';
19
20
  *
20
21
  * Kind: output
21
22
  * Status: active
22
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
23
- * Decided by: ../docs/decisions/show-output.md
24
- * Decided by: ../docs/decisions/source-rendering.md
23
+ * Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
24
+ * Decided by: ../../docs/decisions/show-output.md
25
+ * Decided by: ../../docs/decisions/source-rendering.md
25
26
  * @patram
26
27
  * @see {@link ./render-output-view.js}
27
- * @see {@link ../docs/decisions/show-output.md}
28
+ * @see {@link ../../docs/decisions/show-output.md}
28
29
  */
29
30
 
30
31
  /**
31
32
  * @param {string} requested_file_path
32
33
  * @param {string} project_directory
33
- * @param {import('./build-graph.types.ts').BuildGraphResult} graph
34
+ * @param {BuildGraphResult} graph
34
35
  * @returns {Promise<
35
36
  * | {
36
37
  * success: true;
37
38
  * value: {
39
+ * incoming_summary: Record<string, number>;
38
40
  * path: string;
39
41
  * rendered_source: string;
40
42
  * resolved_links: Array<{
@@ -93,6 +95,7 @@ export async function loadShowOutput(
93
95
  source_file_path,
94
96
  source_text,
95
97
  parse_result.claims,
98
+ graph,
96
99
  graph.document_node_ids,
97
100
  graph.nodes,
98
101
  ),
@@ -103,14 +106,16 @@ export async function loadShowOutput(
103
106
  * @param {string} source_file_path
104
107
  * @param {string} source_text
105
108
  * @param {PatramClaim[]} claims
106
- * @param {import('./build-graph.types.ts').BuildGraphResult['document_node_ids']} document_node_ids
109
+ * @param {BuildGraphResult} graph
110
+ * @param {import('../graph/build-graph.types.ts').BuildGraphResult['document_node_ids']} document_node_ids
107
111
  * @param {Record<string, GraphNode>} graph_nodes
108
- * @returns {{ path: string, rendered_source: string, resolved_links: Array<{ label: string, reference: number, target: { kind?: string, path: string, status?: string, title: string } }>, source: string }}
112
+ * @returns {{ incoming_summary: Record<string, number>, path: string, rendered_source: string, resolved_links: Array<{ label: string, reference: number, target: { kind?: string, path: string, status?: string, title: string } }>, source: string }}
109
113
  */
110
114
  function createShowOutput(
111
115
  source_file_path,
112
116
  source_text,
113
117
  claims,
118
+ graph,
114
119
  document_node_ids,
115
120
  graph_nodes,
116
121
  ) {
@@ -125,8 +130,15 @@ function createShowOutput(
125
130
  graph_nodes,
126
131
  ),
127
132
  );
133
+ const reverse_references = inspectReverseReferences(
134
+ graph,
135
+ source_file_path,
136
+ undefined,
137
+ undefined,
138
+ );
128
139
 
129
140
  return {
141
+ incoming_summary: summarizeIncomingReferences(reverse_references.incoming),
130
142
  path: source_file_path,
131
143
  rendered_source: renderResolvedSource(
132
144
  source_text,
@@ -207,7 +219,7 @@ function renderResolvedSourceLine(
207
219
  * @param {string} source_file_path
208
220
  * @param {PatramClaim} claim
209
221
  * @param {number} reference
210
- * @param {import('./build-graph.types.ts').BuildGraphResult['document_node_ids']} document_node_ids
222
+ * @param {import('../graph/build-graph.types.ts').BuildGraphResult['document_node_ids']} document_node_ids
211
223
  * @param {Record<string, GraphNode>} graph_nodes
212
224
  * @returns {{ label: string, reference: number, target: { kind?: string, path: string, status?: string, title: string } }}
213
225
  */
@@ -269,12 +281,23 @@ function getScalarGraphField(field_value) {
269
281
  * @returns {{ kind?: string, path: string, status?: string, title: string }}
270
282
  */
271
283
  function createResolvedLinkTarget(target_node, target_path, fallback_title) {
272
- return {
273
- kind: getResolvedLinkTargetKind(target_node),
284
+ /** @type {{ kind?: string, path: string, status?: string, title: string }} */
285
+ const resolved_target = {
274
286
  path: getResolvedLinkTargetPath(target_node, target_path),
275
- status: getScalarGraphField(target_node?.status),
276
287
  title: getScalarGraphField(target_node?.title) ?? fallback_title,
277
288
  };
289
+ const target_kind = getResolvedLinkTargetKind(target_node);
290
+ const target_status = getScalarGraphField(target_node?.status);
291
+
292
+ if (target_kind) {
293
+ resolved_target.kind = target_kind;
294
+ }
295
+
296
+ if (target_status) {
297
+ resolved_target.status = target_status;
298
+ }
299
+
300
+ return resolved_target;
278
301
  }
279
302
 
280
303
  /**
@@ -355,6 +378,21 @@ function trimTrailingLineBreaks(value) {
355
378
  return value.replace(/\n+$/du, '');
356
379
  }
357
380
 
381
+ /**
382
+ * @param {Record<string, GraphNode[]>} incoming
383
+ * @returns {Record<string, number>}
384
+ */
385
+ function summarizeIncomingReferences(incoming) {
386
+ /** @type {Record<string, number>} */
387
+ const incoming_summary = {};
388
+
389
+ for (const relation_name of Object.keys(incoming)) {
390
+ incoming_summary[relation_name] = incoming[relation_name].length;
391
+ }
392
+
393
+ return incoming_summary;
394
+ }
395
+
358
396
  /**
359
397
  * @param {unknown} error
360
398
  * @returns {error is NodeJS.ErrnoException}
@@ -1,31 +1,12 @@
1
1
  /**
2
- * @import { BuildGraphResult, GraphNode } from './build-graph.types.ts';
3
- * @import { DerivedSummaryEvaluator } from './derived-summary.js';
4
- * @import { PatramRepoConfig } from './load-patram-config.types.ts';
5
- * @import { ParsedCliArguments } from './parse-cli-arguments.types.ts';
6
- * @import { OutputDerivedSummary, OutputMetadataField, OutputNodeItem, OutputResolvedLinkItem, OutputResolvedLinkTarget, OutputStoredQueryItem, OutputView, ResolvedOutputMode, ShowOutputView } from './output-view.types.ts';
2
+ * @import { BuildGraphResult, GraphNode } from '../../graph/build-graph.types.ts';
3
+ * @import { DerivedSummaryEvaluator } from '../derived-summary.js';
4
+ * @import { PatramRepoConfig } from '../../config/load-patram-config.types.ts';
5
+ * @import { OutputDerivedSummary, OutputMetadataField, OutputNodeItem, OutputResolvedLinkItem, OutputResolvedLinkTarget, OutputStoredQueryItem, OutputView, RefsOutputView, ShowOutputView } from '../output-view.types.ts';
7
6
  */
8
7
  /* eslint-disable max-lines */
9
8
 
10
- import { renderJsonOutput } from './render-json-output.js';
11
- import { renderPlainOutput } from './render-plain-output.js';
12
- import { renderRichOutput } from './render-rich-output.js';
13
- import { resolveDocumentNodeId } from './build-graph-identity.js';
14
-
15
- /**
16
- * Shared command output views.
17
- *
18
- * Normalizes `query`, `queries`, and `show` results into renderer-specific
19
- * output models.
20
- *
21
- * Kind: output
22
- * Status: active
23
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
24
- * Decided by: ../docs/decisions/cli-output-architecture.md
25
- * @patram
26
- * @see {@link ./show-document.js}
27
- * @see {@link ../docs/decisions/cli-output-architecture.md}
28
- */
9
+ import { resolveDocumentNodeId } from '../../graph/build-graph-identity.js';
29
10
 
30
11
  /**
31
12
  * Create a shared output view from one command result.
@@ -49,13 +30,13 @@ export function createOutputView(command_name, command_items, command_options) {
49
30
  );
50
31
  }
51
32
 
52
- throw new Error(`Unsupported output view command "${command_name}".`);
33
+ throw new Error('Unsupported output view command.');
53
34
  }
54
35
 
55
36
  /**
56
37
  * Create a shared output view for the show command.
57
38
  *
58
- * @param {{ path: string, rendered_source: string, resolved_links: Array<{ label: string, reference: number, target: { kind?: string, path: string, status?: string, title: string } }>, source: string }} show_output
39
+ * @param {{ incoming_summary: Record<string, number>, path: string, rendered_source: string, resolved_links: Array<{ label: string, reference: number, target: { kind?: string, path: string, status?: string, title: string } }>, source: string }} show_output
59
40
  * @param {{ derived_summary_evaluator?: DerivedSummaryEvaluator, document_node_ids?: BuildGraphResult['document_node_ids'], graph_nodes?: BuildGraphResult['nodes'], repo_config?: PatramRepoConfig }=} command_options
60
41
  * @returns {ShowOutputView}
61
42
  */
@@ -78,6 +59,7 @@ export function createShowOutputView(show_output, command_options = {}) {
78
59
  )
79
60
  : undefined,
80
61
  hints: [],
62
+ incoming_summary: show_output.incoming_summary,
81
63
  items: show_output.resolved_links.map((resolved_link) =>
82
64
  createResolvedLinkOutputItem(resolved_link, command_options),
83
65
  ),
@@ -92,30 +74,43 @@ export function createShowOutputView(show_output, command_options = {}) {
92
74
  }
93
75
 
94
76
  /**
95
- * Render one shared output view through the resolved renderer.
77
+ * Create a shared output view for the refs command.
96
78
  *
97
- * @param {OutputView} output_view
98
- * @param {ResolvedOutputMode} output_mode
99
- * @param {ParsedCliArguments} parsed_arguments
100
- * @returns {Promise<string>}
79
+ * @param {{ incoming: Record<string, GraphNode[]>, node: GraphNode }} refs_output
80
+ * @param {{ derived_summary_evaluator?: DerivedSummaryEvaluator, repo_config?: PatramRepoConfig }=} command_options
81
+ * @returns {RefsOutputView}
101
82
  */
102
- export async function renderOutputView(
103
- output_view,
104
- output_mode,
105
- parsed_arguments,
106
- ) {
107
- if (output_mode.renderer_name === 'json') {
108
- return renderJsonOutput(output_view);
109
- }
110
-
111
- if (output_mode.renderer_name === 'plain') {
112
- return renderPlainOutput(output_view);
83
+ export function createRefsOutputView(refs_output, command_options = {}) {
84
+ /** @type {Record<string, OutputNodeItem[]>} */
85
+ const incoming = {};
86
+
87
+ for (const relation_name of Object.keys(refs_output.incoming)) {
88
+ incoming[relation_name] = refs_output.incoming[relation_name].map(
89
+ (graph_node) =>
90
+ createOutputNodeItem(
91
+ graph_node,
92
+ command_options.derived_summary_evaluator?.evaluate(graph_node) ??
93
+ null,
94
+ command_options.repo_config?.fields ?? {},
95
+ ),
96
+ );
113
97
  }
114
98
 
115
- return renderRichOutput(output_view, {
116
- color_enabled: output_mode.color_enabled,
117
- color_mode: parsed_arguments.color_mode,
118
- });
99
+ return {
100
+ command: 'refs',
101
+ hints: [],
102
+ incoming,
103
+ node: createOutputNodeItem(
104
+ refs_output.node,
105
+ command_options.derived_summary_evaluator?.evaluate(refs_output.node) ??
106
+ null,
107
+ command_options.repo_config?.fields ?? {},
108
+ ),
109
+ summary: {
110
+ count: countIncomingReferenceItems(incoming),
111
+ kind: 'incoming_reference_list',
112
+ },
113
+ };
119
114
  }
120
115
 
121
116
  /**
@@ -130,7 +125,7 @@ function createQueryOutputView(graph_nodes, command_options = {}) {
130
125
  command: 'query',
131
126
  hints:
132
127
  command_options.hints ??
133
- (total_count === 0 ? ['Try: patram query --where "$class=task"'] : []),
128
+ (total_count === 0 ? ["Try: patram query --where '$class=task'"] : []),
134
129
  items: graph_nodes.map((graph_node) =>
135
130
  createOutputNodeItem(
136
131
  graph_node,
@@ -168,6 +163,20 @@ function createStoredQueriesOutputView(stored_queries) {
168
163
  };
169
164
  }
170
165
 
166
+ /**
167
+ * @param {Record<string, OutputNodeItem[]>} incoming
168
+ * @returns {number}
169
+ */
170
+ function countIncomingReferenceItems(incoming) {
171
+ let count = 0;
172
+
173
+ for (const output_items of Object.values(incoming)) {
174
+ count += output_items.length;
175
+ }
176
+
177
+ return count;
178
+ }
179
+
171
180
  /**
172
181
  * @param {GraphNode} graph_node
173
182
  * @param {OutputDerivedSummary | null} derived_summary
@@ -42,10 +42,10 @@ async function writeOutputThroughPager(
42
42
 
43
43
  await writeToPagerInput(pager_process.stdin, output_text);
44
44
 
45
- const [exit_code, signal_code] = await Promise.race([
46
- close_promise,
47
- error_promise,
48
- ]);
45
+ const pager_result = /** @type {[number | null, NodeJS.Signals | null]} */ (
46
+ await Promise.race([close_promise, error_promise])
47
+ );
48
+ const [exit_code, signal_code] = pager_result;
49
49
 
50
50
  if (exit_code === 0) {
51
51
  return;
@@ -72,7 +72,11 @@ function writeToPagerInput(pager_input, output_text) {
72
72
  return;
73
73
  }
74
74
 
75
- reject(error);
75
+ reject(
76
+ error instanceof Error
77
+ ? error
78
+ : new Error('Pager input failed with a non-Error rejection.'),
79
+ );
76
80
  });
77
81
  pager_input.end(output_text, 'utf8', resolve);
78
82
  });
@@ -16,5 +16,5 @@ export function createClaim(file_path: string, claim_number: number, claim_type:
16
16
  * @returns {string}
17
17
  */
18
18
  export function getFileExtension(file_path: string): string;
19
- import type { PatramClaimFields } from './parse-claims.types.ts';
20
- import type { PatramClaim } from './parse-claims.types.ts';
19
+ import type { PatramClaimFields } from './parse-claims.types.d.ts';
20
+ import type { PatramClaim } from './parse-claims.types.d.ts';
@@ -5,5 +5,5 @@
5
5
  * @returns {ParseSourceFileResult}
6
6
  */
7
7
  export function parseJsdocClaims(parse_input: ParseClaimsInput): ParseSourceFileResult;
8
- import type { ParseClaimsInput } from './parse-claims.types.ts';
9
- import type { ParseSourceFileResult } from './parse-claims.types.ts';
8
+ import type { ParseClaimsInput } from '../parse-claims.types.d.ts';
9
+ import type { ParseSourceFileResult } from '../parse-claims.types.d.ts';
@@ -1,20 +1,20 @@
1
1
  /**
2
- * @import { PatramDiagnostic } from './load-patram-config.types.ts';
3
- * @import { ParseClaimsInput, ParseSourceFileResult, PatramClaimFields } from './parse-claims.types.ts';
2
+ * @import { PatramDiagnostic } from '../../config/load-patram-config.types.ts';
3
+ * @import { ParseClaimsInput, ParseSourceFileResult, PatramClaimFields } from '../parse-claims.types.ts';
4
4
  */
5
5
 
6
6
  import {
7
7
  createClaim,
8
8
  getFileExtension,
9
9
  isPathLikeTarget,
10
- } from './claim-helpers.js';
11
- import { normalizeDirectiveName } from './parse-markdown-directives.js';
10
+ } from '../claim-helpers.js';
11
+ import { normalizeDirectiveName } from '../markdown/parse-markdown-directives.js';
12
12
  import { collectJsdocBlocks } from './parse-jsdoc-blocks.js';
13
13
  import {
14
14
  createJsdocProseClaimEntries,
15
15
  pushJsdocParagraph,
16
16
  } from './parse-jsdoc-prose.js';
17
- import { JSDOC_SOURCE_FILE_EXTENSIONS } from './source-file-defaults.js';
17
+ import { JSDOC_SOURCE_FILE_EXTENSIONS } from '../../config/source-file-defaults.js';
18
18
 
19
19
  /**
20
20
  * JSDoc @patram claim parsing.
@@ -24,11 +24,11 @@ import { JSDOC_SOURCE_FILE_EXTENSIONS } from './source-file-defaults.js';
24
24
  *
25
25
  * Kind: parse
26
26
  * Status: active
27
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
28
- * Decided by: ../docs/decisions/jsdoc-metadata-directive-syntax.md
27
+ * Tracked in: ../../../docs/plans/v0/source-anchor-dogfooding.md
28
+ * Decided by: ../../../docs/decisions/jsdoc-metadata-directive-syntax.md
29
29
  * @patram
30
- * @see {@link ./parse-claims.js}
31
- * @see {@link ../docs/decisions/jsdoc-metadata-directive-syntax.md}
30
+ * @see {@link ../parse-claims.js}
31
+ * @see {@link ../../../docs/decisions/jsdoc-metadata-directive-syntax.md}
32
32
  */
33
33
 
34
34
  const JSDOC_EXTENSIONS = new Set(JSDOC_SOURCE_FILE_EXTENSIONS);
@@ -25,4 +25,4 @@ export function createJsdocProseClaimEntries(file_path: string, prose_paragraphs
25
25
  claim_type: string;
26
26
  order: number;
27
27
  }>;
28
- import type { PatramClaimFields } from './parse-claims.types.ts';
28
+ import type { PatramClaimFields } from '../parse-claims.types.d.ts';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @import { PatramClaimFields } from './parse-claims.types.ts';
2
+ * @import { PatramClaimFields } from '../parse-claims.types.ts';
3
3
  */
4
4
 
5
5
  const JSDOC_SENTENCE_PATTERN = /^(.+?[.!?])(?:\s+|$)([\s\S]*)$/du;
@@ -9,6 +9,6 @@ export function parseMarkdownClaims(parse_input: ParseClaimsInput, parse_options
9
9
  claims: PatramClaim[];
10
10
  diagnostics: PatramDiagnostic[];
11
11
  };
12
- import type { ParseClaimsInput } from './parse-claims.types.ts';
13
- import type { PatramClaim } from './parse-claims.types.ts';
14
- import type { PatramDiagnostic } from './load-patram-config.types.ts';
12
+ import type { ParseClaimsInput } from '../parse-claims.types.d.ts';
13
+ import type { PatramClaim } from '../parse-claims.types.d.ts';
14
+ import type { PatramDiagnostic } from '../../config/load-patram-config.types.d.ts';
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @import { PatramClaim, ParseClaimsInput, PatramClaimFields } from './parse-claims.types.ts';
3
- * @import { PatramDiagnostic } from './load-patram-config.types.ts';
2
+ * @import { PatramClaim, ParseClaimsInput, PatramClaimFields } from '../parse-claims.types.ts';
3
+ * @import { PatramDiagnostic } from '../../config/load-patram-config.types.ts';
4
4
  */
5
5
 
6
- import { createClaim, isPathLikeTarget } from './claim-helpers.js';
6
+ import { createClaim, isPathLikeTarget } from '../claim-helpers.js';
7
7
  import {
8
8
  matchHiddenDirectiveFields,
9
9
  matchVisibleDirectiveFields,
@@ -18,12 +18,12 @@ import {
18
18
  *
19
19
  * Kind: parse
20
20
  * Status: active
21
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
22
- * Decided by: ../docs/decisions/markdown-metadata-directive-syntax.md
23
- * Decided by: ../docs/decisions/markdown-link-claim-scope.md
21
+ * Tracked in: ../../../docs/plans/v0/source-anchor-dogfooding.md
22
+ * Decided by: ../../../docs/decisions/markdown-metadata-directive-syntax.md
23
+ * Decided by: ../../../docs/decisions/markdown-link-claim-scope.md
24
24
  * @patram
25
- * @see {@link ./parse-claims.js}
26
- * @see {@link ../docs/decisions/markdown-metadata-directive-syntax.md}
25
+ * @see {@link ../parse-claims.js}
26
+ * @see {@link ../../../docs/decisions/markdown-metadata-directive-syntax.md}
27
27
  */
28
28
 
29
29
  const HEADING_PATTERN = /^#\s+(.+)$/du;
@@ -30,5 +30,5 @@ export function matchHiddenDirectiveFields(file_path: string, line: string, line
30
30
  * @returns {string}
31
31
  */
32
32
  export function normalizeDirectiveName(directive_label: string): string;
33
- import type { PatramDiagnostic } from './load-patram-config.types.ts';
34
- import type { PatramClaimFields } from './parse-claims.types.ts';
33
+ import type { PatramDiagnostic } from '../../config/load-patram-config.types.d.ts';
34
+ import type { PatramClaimFields } from '../parse-claims.types.d.ts';
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @import { MarkdownDirectiveStyle, PatramClaimFields } from './parse-claims.types.ts';
3
- * @import { PatramDiagnostic } from './load-patram-config.types.ts';
2
+ * @import { MarkdownDirectiveStyle, PatramClaimFields } from '../parse-claims.types.ts';
3
+ * @import { PatramDiagnostic } from '../../config/load-patram-config.types.ts';
4
4
  */
5
5
 
6
- import { parseYamlDirectiveFields } from './parse-yaml-claims.js';
6
+ import { parseYamlDirectiveFields } from '../yaml/parse-yaml-claims.js';
7
7
 
8
8
  const FRONT_MATTER_BOUNDARY_PATTERN = /^---$/du;
9
9
  const MARKDOWN_HIDDEN_DIRECTIVE_PATTERN =
@@ -8,16 +8,6 @@
8
8
  export function parseSourceFile(parse_input: ParseClaimsInput, parse_options?: {
9
9
  multi_value_directive_names?: ReadonlySet<string>;
10
10
  }): ParseSourceFileResult;
11
- /**
12
- * Parse a file into neutral Patram claims.
13
- *
14
- * @param {ParseClaimsInput} parse_input
15
- * @param {{ multi_value_directive_names?: ReadonlySet<string> }} [parse_options]
16
- * @returns {PatramClaim[]}
17
- */
18
- export function parseClaims(parse_input: ParseClaimsInput, parse_options?: {
19
- multi_value_directive_names?: ReadonlySet<string>;
20
- }): PatramClaim[];
21
11
  /**
22
12
  * Build parser options from repo config.
23
13
  *
@@ -35,6 +25,7 @@ export function createParseOptions(repo_config: {
35
25
  } | undefined): {
36
26
  multi_value_directive_names: Set<string>;
37
27
  };
38
- import type { ParseClaimsInput } from './parse-claims.types.ts';
39
- import type { ParseSourceFileResult } from './parse-claims.types.ts';
40
- import type { PatramClaim } from './parse-claims.types.ts';
28
+ export type ClaimOrigin = import("./parse-claims.types.d.ts").ClaimOrigin;
29
+ export type ParseClaimsInput = import("./parse-claims.types.d.ts").ParseClaimsInput;
30
+ export type ParseSourceFileResult = import("./parse-claims.types.d.ts").ParseSourceFileResult;
31
+ export type PatramClaim = import("./parse-claims.types.d.ts").PatramClaim;
@@ -1,15 +1,18 @@
1
- /**
2
- * @import { ParseClaimsInput, ParseSourceFileResult, PatramClaim } from './parse-claims.types.ts';
3
- */
4
-
5
1
  import { getFileExtension } from './claim-helpers.js';
6
- import { parseJsdocClaims } from './parse-jsdoc-claims.js';
7
- import { parseMarkdownClaims } from './parse-markdown-claims.js';
8
- import { parseYamlClaims } from './parse-yaml-claims.js';
2
+ import { parseJsdocClaims } from './jsdoc/parse-jsdoc-claims.js';
3
+ import { parseMarkdownClaims } from './markdown/parse-markdown-claims.js';
4
+ import { parseYamlClaims } from './yaml/parse-yaml-claims.js';
9
5
  import {
10
6
  MARKDOWN_SOURCE_FILE_EXTENSIONS,
11
7
  YAML_SOURCE_FILE_EXTENSIONS,
12
- } from './source-file-defaults.js';
8
+ } from '../config/source-file-defaults.js';
9
+
10
+ /**
11
+ * @typedef {import('./parse-claims.types.ts').ClaimOrigin} ClaimOrigin
12
+ * @typedef {import('./parse-claims.types.ts').ParseClaimsInput} ParseClaimsInput
13
+ * @typedef {import('./parse-claims.types.ts').ParseSourceFileResult} ParseSourceFileResult
14
+ * @typedef {import('./parse-claims.types.ts').PatramClaim} PatramClaim
15
+ */
13
16
 
14
17
  /**
15
18
  * Source claim dispatch.
@@ -19,14 +22,14 @@ import {
19
22
  *
20
23
  * Kind: parse
21
24
  * Status: active
22
- * Uses Term: ../docs/reference/terms/claim.md
23
- * Uses Term: ../docs/reference/terms/document.md
24
- * Tracked in: ../docs/plans/v0/source-anchor-dogfooding.md
25
- * Decided by: ../docs/decisions/jsdoc-metadata-directive-syntax.md
26
- * Implements: ../docs/tasks/v0/parse-claims.md
25
+ * Uses Term: ../../docs/reference/terms/claim.md
26
+ * Uses Term: ../../docs/reference/terms/document.md
27
+ * Tracked in: ../../docs/plans/v0/source-anchor-dogfooding.md
28
+ * Decided by: ../../docs/decisions/jsdoc-metadata-directive-syntax.md
29
+ * Implements: ../../docs/tasks/v0/parse-claims.md
27
30
  * @patram
28
- * @see {@link ./parse-markdown-claims.js}
29
- * @see {@link ./parse-jsdoc-claims.js}
31
+ * @see {@link ./markdown/parse-markdown-claims.js}
32
+ * @see {@link ./jsdoc/parse-jsdoc-claims.js}
30
33
  */
31
34
 
32
35
  const MARKDOWN_EXTENSIONS = new Set(MARKDOWN_SOURCE_FILE_EXTENSIONS);
@@ -53,17 +56,6 @@ export function parseSourceFile(parse_input, parse_options) {
53
56
  return parseJsdocClaims(parse_input);
54
57
  }
55
58
 
56
- /**
57
- * Parse a file into neutral Patram claims.
58
- *
59
- * @param {ParseClaimsInput} parse_input
60
- * @param {{ multi_value_directive_names?: ReadonlySet<string> }} [parse_options]
61
- * @returns {PatramClaim[]}
62
- */
63
- export function parseClaims(parse_input, parse_options) {
64
- return parseSourceFile(parse_input, parse_options).claims;
65
- }
66
-
67
59
  /**
68
60
  * Build parser options from repo config.
69
61
  *
@@ -1,4 +1,4 @@
1
- import type { PatramDiagnostic } from './load-patram-config.types.ts';
1
+ import type { PatramDiagnostic } from '../config/load-patram-config.types.d.ts';
2
2
  export type MarkdownDirectiveStyle = 'front_matter' | 'visible_line' | 'list_item' | 'hidden_tag';
3
3
  export interface ParseClaimsInput {
4
4
  path: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @import { TaggedFencedBlockError } from './tagged-fenced-blocks.types.ts';
2
+ * @import { TaggedFencedBlockError } from './tagged-fenced-blocks.types.d.ts';
3
3
  */
4
4
  /**
5
5
  * @param {string} code
@@ -7,4 +7,4 @@
7
7
  * @returns {TaggedFencedBlockError}
8
8
  */
9
9
  export function createTaggedFencedBlockError(code: string, message: string): TaggedFencedBlockError;
10
- import type { TaggedFencedBlockError } from './tagged-fenced-blocks.types.ts';
10
+ import type { TaggedFencedBlockError } from './tagged-fenced-blocks.types.d.ts';
@@ -56,6 +56,6 @@ export type TaggedBlockScannerState = {
56
56
  pending_tag_set: PendingTagSet | null;
57
57
  title: string;
58
58
  };
59
- import type { TaggedFencedBlocksInput } from './tagged-fenced-blocks.types.ts';
60
- import type { TaggedFencedBlockFile } from './tagged-fenced-blocks.types.ts';
61
- import type { TaggedFencedBlock } from './tagged-fenced-blocks.types.ts';
59
+ import type { TaggedFencedBlocksInput } from './tagged-fenced-blocks.types.d.ts';
60
+ import type { TaggedFencedBlockFile } from './tagged-fenced-blocks.types.d.ts';
61
+ import type { TaggedFencedBlock } from './tagged-fenced-blocks.types.d.ts';
@@ -6,10 +6,10 @@
6
6
  *
7
7
  * Kind: parse
8
8
  * Status: active
9
- * Tracked in: ../docs/plans/v0/tagged-fenced-block-extraction.md
10
- * Decided by: ../docs/decisions/tagged-fenced-block-extraction.md
9
+ * Tracked in: ../../../docs/plans/v0/tagged-fenced-block-extraction.md
10
+ * Decided by: ../../../docs/decisions/tagged-fenced-block-extraction.md
11
11
  * @patram
12
- * @see {@link ../docs/decisions/tagged-fenced-block-extraction.md}
12
+ * @see {@link ../../../docs/decisions/tagged-fenced-block-extraction.md}
13
13
  */
14
14
  /**
15
15
  * @param {TaggedFencedBlocksInput} input
@@ -33,7 +33,7 @@ export function selectTaggedBlocks(blocks: TaggedFencedBlock[], criteria: Tagged
33
33
  * @returns {TaggedFencedBlock}
34
34
  */
35
35
  export function selectTaggedBlock(blocks: TaggedFencedBlock[], criteria: TaggedFencedBlockCriteria): TaggedFencedBlock;
36
- import type { TaggedFencedBlocksInput } from './tagged-fenced-blocks.types.ts';
37
- import type { TaggedFencedBlockFile } from './tagged-fenced-blocks.types.ts';
38
- import type { TaggedFencedBlock } from './tagged-fenced-blocks.types.ts';
39
- import type { TaggedFencedBlockCriteria } from './tagged-fenced-blocks.types.ts';
36
+ import type { TaggedFencedBlocksInput } from './tagged-fenced-blocks.types.d.ts';
37
+ import type { TaggedFencedBlockFile } from './tagged-fenced-blocks.types.d.ts';
38
+ import type { TaggedFencedBlock } from './tagged-fenced-blocks.types.d.ts';
39
+ import type { TaggedFencedBlockCriteria } from './tagged-fenced-blocks.types.d.ts';
@@ -20,10 +20,10 @@ import { extractTaggedFencedBlocksFromSource } from './tagged-fenced-block-parse
20
20
  *
21
21
  * Kind: parse
22
22
  * Status: active
23
- * Tracked in: ../docs/plans/v0/tagged-fenced-block-extraction.md
24
- * Decided by: ../docs/decisions/tagged-fenced-block-extraction.md
23
+ * Tracked in: ../../../docs/plans/v0/tagged-fenced-block-extraction.md
24
+ * Decided by: ../../../docs/decisions/tagged-fenced-block-extraction.md
25
25
  * @patram
26
- * @see {@link ../docs/decisions/tagged-fenced-block-extraction.md}
26
+ * @see {@link ../../../docs/decisions/tagged-fenced-block-extraction.md}
27
27
  */
28
28
 
29
29
  /**