perttool 0.7.1 → 0.8.1

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 (229) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/README.md +98 -18
  3. package/dist/actuals/lifecycle.d.ts +6 -20
  4. package/dist/actuals/lifecycle.d.ts.map +1 -1
  5. package/dist/actuals/lifecycle.js +5 -176
  6. package/dist/actuals/lifecycle.js.map +1 -1
  7. package/dist/actuals/reduction.d.ts +20 -0
  8. package/dist/actuals/reduction.d.ts.map +1 -0
  9. package/dist/actuals/reduction.js +175 -0
  10. package/dist/actuals/reduction.js.map +1 -0
  11. package/dist/analysis/service.d.ts +33 -0
  12. package/dist/analysis/service.d.ts.map +1 -0
  13. package/dist/analysis/service.js +153 -0
  14. package/dist/analysis/service.js.map +1 -0
  15. package/dist/analysis/target-temporal-input.d.ts +88 -0
  16. package/dist/analysis/target-temporal-input.d.ts.map +1 -0
  17. package/dist/analysis/target-temporal-input.js +249 -0
  18. package/dist/analysis/target-temporal-input.js.map +1 -0
  19. package/dist/analysis/temporal-deadline.d.ts +1 -1
  20. package/dist/analysis/temporal-deadline.d.ts.map +1 -1
  21. package/dist/analysis/temporal-precedence.d.ts +1 -1
  22. package/dist/analysis/temporal-precedence.d.ts.map +1 -1
  23. package/dist/analysis/temporal-precedence.js +1 -1
  24. package/dist/analysis/temporal-precedence.js.map +1 -1
  25. package/dist/analysis/temporal-resource.d.ts +1 -1
  26. package/dist/analysis/temporal-resource.d.ts.map +1 -1
  27. package/dist/analysis/temporal-resource.js +1 -1
  28. package/dist/analysis/temporal-resource.js.map +1 -1
  29. package/dist/application/advance-history.d.ts +2 -1
  30. package/dist/application/advance-history.d.ts.map +1 -1
  31. package/dist/application/advance-history.js +1 -1
  32. package/dist/application/advance-history.js.map +1 -1
  33. package/dist/application/analyze.d.ts +1 -32
  34. package/dist/application/analyze.d.ts.map +1 -1
  35. package/dist/application/analyze.js +1 -152
  36. package/dist/application/analyze.js.map +1 -1
  37. package/dist/application/check.d.ts +1 -42
  38. package/dist/application/check.d.ts.map +1 -1
  39. package/dist/application/check.js +1 -109
  40. package/dist/application/check.js.map +1 -1
  41. package/dist/application/cli-facade.d.ts +85 -0
  42. package/dist/application/cli-facade.d.ts.map +1 -0
  43. package/dist/application/cli-facade.js +108 -0
  44. package/dist/application/cli-facade.js.map +1 -0
  45. package/dist/application/contract6-mutation.js +2 -2
  46. package/dist/application/contract6-mutation.js.map +1 -1
  47. package/dist/application/contract7-mermaid.d.ts.map +1 -1
  48. package/dist/application/contract7-mermaid.js +3 -3
  49. package/dist/application/contract7-mermaid.js.map +1 -1
  50. package/dist/application/contract7-source.d.ts +1 -7
  51. package/dist/application/contract7-source.d.ts.map +1 -1
  52. package/dist/application/contract7-source.js +4 -12
  53. package/dist/application/contract7-source.js.map +1 -1
  54. package/dist/application/editor-dag-focus.d.ts +52 -0
  55. package/dist/application/editor-dag-focus.d.ts.map +1 -0
  56. package/dist/application/editor-dag-focus.js +132 -0
  57. package/dist/application/editor-dag-focus.js.map +1 -0
  58. package/dist/application/format.js +2 -2
  59. package/dist/application/format.js.map +1 -1
  60. package/dist/application/mutate.d.ts +1 -26
  61. package/dist/application/mutate.d.ts.map +1 -1
  62. package/dist/application/mutate.js +1 -205
  63. package/dist/application/mutate.js.map +1 -1
  64. package/dist/application/next.js +2 -2
  65. package/dist/application/next.js.map +1 -1
  66. package/dist/application/target-actuals-advance.js +2 -2
  67. package/dist/application/target-actuals-advance.js.map +1 -1
  68. package/dist/application/target-actuals-analysis.js +2 -2
  69. package/dist/application/target-actuals-analysis.js.map +1 -1
  70. package/dist/application/target-actuals-mutation.d.ts.map +1 -1
  71. package/dist/application/target-actuals-mutation.js +6 -5
  72. package/dist/application/target-actuals-mutation.js.map +1 -1
  73. package/dist/application/target-assurance-analysis.js +2 -2
  74. package/dist/application/target-assurance-analysis.js.map +1 -1
  75. package/dist/application/target-assurance-write.d.ts +2 -1
  76. package/dist/application/target-assurance-write.d.ts.map +1 -1
  77. package/dist/application/target-assurance-write.js +36 -12
  78. package/dist/application/target-assurance-write.js.map +1 -1
  79. package/dist/application/target-governance-mutation.js +2 -2
  80. package/dist/application/target-governance-mutation.js.map +1 -1
  81. package/dist/application/target-historical-graph.d.ts +124 -0
  82. package/dist/application/target-historical-graph.d.ts.map +1 -0
  83. package/dist/application/target-historical-graph.js +547 -0
  84. package/dist/application/target-historical-graph.js.map +1 -0
  85. package/dist/application/target-mutate.d.ts +1 -17
  86. package/dist/application/target-mutate.d.ts.map +1 -1
  87. package/dist/application/target-mutate.js +1 -159
  88. package/dist/application/target-mutate.js.map +1 -1
  89. package/dist/application/target-project-history.d.ts +2 -1
  90. package/dist/application/target-project-history.d.ts.map +1 -1
  91. package/dist/application/target-project-history.js +3 -3
  92. package/dist/application/target-project-history.js.map +1 -1
  93. package/dist/application/target-temporal-analysis.js +2 -2
  94. package/dist/application/target-temporal-analysis.js.map +1 -1
  95. package/dist/application/target-temporal-input.d.ts +1 -87
  96. package/dist/application/target-temporal-input.d.ts.map +1 -1
  97. package/dist/application/target-temporal-input.js +1 -248
  98. package/dist/application/target-temporal-input.js.map +1 -1
  99. package/dist/application/target-unit-migration-candidate.js +2 -2
  100. package/dist/application/target-unit-migration-candidate.js.map +1 -1
  101. package/dist/assurance/advance.d.ts.map +1 -1
  102. package/dist/assurance/advance.js +15 -5
  103. package/dist/assurance/advance.js.map +1 -1
  104. package/dist/assurance/canonical.js +2 -2
  105. package/dist/assurance/canonical.js.map +1 -1
  106. package/dist/assurance/compatibility.js +2 -2
  107. package/dist/assurance/compatibility.js.map +1 -1
  108. package/dist/assurance/mermaid.d.ts +4 -2
  109. package/dist/assurance/mermaid.d.ts.map +1 -1
  110. package/dist/assurance/mermaid.js +11 -7
  111. package/dist/assurance/mermaid.js.map +1 -1
  112. package/dist/assurance/mutation.d.ts.map +1 -1
  113. package/dist/assurance/mutation.js +9 -23
  114. package/dist/assurance/mutation.js.map +1 -1
  115. package/dist/cli.js +66 -26
  116. package/dist/cli.js.map +1 -1
  117. package/dist/command/assurance-discovery.d.ts.map +1 -1
  118. package/dist/command/assurance-discovery.js +62 -2
  119. package/dist/command/assurance-discovery.js.map +1 -1
  120. package/dist/command/assurance-usage.d.ts.map +1 -1
  121. package/dist/command/assurance-usage.js +11 -0
  122. package/dist/command/assurance-usage.js.map +1 -1
  123. package/dist/conversion/mermaid-import.js +3 -3
  124. package/dist/conversion/mermaid-import.js.map +1 -1
  125. package/dist/conversion/mermaid.d.ts +1 -1
  126. package/dist/conversion/mermaid.d.ts.map +1 -1
  127. package/dist/conversion/mermaid.js +4 -4
  128. package/dist/conversion/mermaid.js.map +1 -1
  129. package/dist/core/index.d.ts +33 -0
  130. package/dist/core/index.d.ts.map +1 -0
  131. package/dist/core/index.js +13 -0
  132. package/dist/core/index.js.map +1 -0
  133. package/dist/core/source.d.ts +8 -0
  134. package/dist/core/source.d.ts.map +1 -0
  135. package/dist/core/source.js +11 -0
  136. package/dist/core/source.js.map +1 -0
  137. package/dist/formatter/source-formatter.d.ts +1 -1
  138. package/dist/formatter/source-formatter.d.ts.map +1 -1
  139. package/dist/formatter/source-formatter.js +1 -1
  140. package/dist/formatter/source-formatter.js.map +1 -1
  141. package/dist/guidance/validator.js +2 -2
  142. package/dist/guidance/validator.js.map +1 -1
  143. package/dist/help/assurance-guide.d.ts.map +1 -1
  144. package/dist/help/assurance-guide.js +78 -0
  145. package/dist/help/assurance-guide.js.map +1 -1
  146. package/dist/history/git-probe.d.ts +71 -0
  147. package/dist/history/git-probe.d.ts.map +1 -1
  148. package/dist/history/git-probe.js +517 -0
  149. package/dist/history/git-probe.js.map +1 -1
  150. package/dist/history/historical-graph.d.ts +174 -0
  151. package/dist/history/historical-graph.d.ts.map +1 -0
  152. package/dist/history/historical-graph.js +870 -0
  153. package/dist/history/historical-graph.js.map +1 -0
  154. package/dist/history/historical-transition.d.ts +311 -0
  155. package/dist/history/historical-transition.d.ts.map +1 -0
  156. package/dist/history/historical-transition.js +998 -0
  157. package/dist/history/historical-transition.js.map +1 -0
  158. package/dist/history/project-history.d.ts.map +1 -1
  159. package/dist/history/project-history.js +2 -2
  160. package/dist/history/project-history.js.map +1 -1
  161. package/dist/index.d.ts +2 -0
  162. package/dist/index.d.ts.map +1 -1
  163. package/dist/index.js +1 -0
  164. package/dist/index.js.map +1 -1
  165. package/dist/io/document-file.js +2 -2
  166. package/dist/io/document-file.js.map +1 -1
  167. package/dist/io/safe-write.js +1 -1
  168. package/dist/io/safe-write.js.map +1 -1
  169. package/dist/model/sha256.d.ts +5 -0
  170. package/dist/model/sha256.d.ts.map +1 -0
  171. package/dist/model/sha256.js +105 -0
  172. package/dist/model/sha256.js.map +1 -0
  173. package/dist/mutation/advance.js +3 -3
  174. package/dist/mutation/advance.js.map +1 -1
  175. package/dist/mutation/diagnostics.d.ts +2 -2
  176. package/dist/mutation/diagnostics.d.ts.map +1 -1
  177. package/dist/mutation/diagnostics.js.map +1 -1
  178. package/dist/mutation/planner.d.ts +27 -0
  179. package/dist/mutation/planner.d.ts.map +1 -0
  180. package/dist/mutation/planner.js +206 -0
  181. package/dist/mutation/planner.js.map +1 -0
  182. package/dist/mutation/source.d.ts +2 -1
  183. package/dist/mutation/source.d.ts.map +1 -1
  184. package/dist/mutation/source.js +14 -0
  185. package/dist/mutation/source.js.map +1 -1
  186. package/dist/mutation/target-planner.d.ts +18 -0
  187. package/dist/mutation/target-planner.d.ts.map +1 -0
  188. package/dist/mutation/target-planner.js +160 -0
  189. package/dist/mutation/target-planner.js.map +1 -0
  190. package/dist/mutation/task.d.ts.map +1 -1
  191. package/dist/mutation/task.js +19 -11
  192. package/dist/mutation/task.js.map +1 -1
  193. package/dist/mutation/types.d.ts +1 -1
  194. package/dist/mutation/types.d.ts.map +1 -1
  195. package/dist/node/historical-host.d.ts +6 -0
  196. package/dist/node/historical-host.d.ts.map +1 -0
  197. package/dist/node/historical-host.js +8 -0
  198. package/dist/node/historical-host.js.map +1 -0
  199. package/dist/node/host.d.ts +3 -0
  200. package/dist/node/host.d.ts.map +1 -0
  201. package/dist/node/host.js +48 -0
  202. package/dist/node/host.js.map +1 -0
  203. package/dist/node/index.d.ts +2 -0
  204. package/dist/node/index.d.ts.map +1 -0
  205. package/dist/node/index.js +2 -0
  206. package/dist/node/index.js.map +1 -0
  207. package/dist/ports/node-host.d.ts +41 -0
  208. package/dist/ports/node-host.d.ts.map +1 -0
  209. package/dist/ports/node-host.js +2 -0
  210. package/dist/ports/node-host.js.map +1 -0
  211. package/dist/recommendation/override.d.ts +40 -2
  212. package/dist/recommendation/override.d.ts.map +1 -1
  213. package/dist/recommendation/override.js +5 -6
  214. package/dist/recommendation/override.js.map +1 -1
  215. package/dist/schema/registry.d.ts.map +1 -1
  216. package/dist/schema/registry.js +1 -0
  217. package/dist/schema/registry.js.map +1 -1
  218. package/dist/semantic/check.d.ts +43 -0
  219. package/dist/semantic/check.d.ts.map +1 -0
  220. package/dist/semantic/check.js +110 -0
  221. package/dist/semantic/check.js.map +1 -0
  222. package/dist/session/document-session.d.ts +109 -0
  223. package/dist/session/document-session.d.ts.map +1 -0
  224. package/dist/session/document-session.js +432 -0
  225. package/dist/session/document-session.js.map +1 -0
  226. package/dist/version.d.ts +1 -1
  227. package/dist/version.js +1 -1
  228. package/package.json +18 -4
  229. package/schemas/Perttool.HistoricalGraphResult.v1.schema.json +654 -0
@@ -0,0 +1,124 @@
1
+ import { type HistoricalCheckpointV1, type HistoricalLinearCauseRecordV1, type HistoricalLinearCoreResultV1, type HistoricalLineageV1, type HistoricalTimelineV1 } from "../history/historical-graph.js";
2
+ import type { HistoricalGitEvidenceOutcome, HistoricalGitEvidenceRequest, HistoricalGitEvidenceResult } from "../history/git-probe.js";
3
+ import { type Diagnostic } from "../model/diagnostics.js";
4
+ import type { DurationUnit } from "../model/units.js";
5
+ export declare const TARGET_HISTORICAL_GRAPH_CLI_CONTRACT_VERSION: 7;
6
+ export declare const TARGET_HISTORICAL_GRAPH_SCHEMA_VERSION: "Perttool.HistoricalGraphResult.v1";
7
+ export type HistoricalGraphAncestryProfileV1 = "first_parent" | "three_way";
8
+ export type HistoricalGraphViewV1 = "snapshot" | "lineage" | "timeline";
9
+ export type HistoricalGraphAnalysisModeV1 = "none" | "precedence" | "resource" | "both";
10
+ export type HistoricalGraphStatusV1 = "complete" | "incomplete" | "unavailable";
11
+ export interface HistoricalGraphRequestV1 {
12
+ readonly targetPath: string;
13
+ readonly requestedEndpoint?: string;
14
+ readonly lowerBoundary?: string;
15
+ readonly ancestryProfile?: HistoricalGraphAncestryProfileV1;
16
+ readonly view?: HistoricalGraphViewV1;
17
+ readonly snapshotCommitId?: string;
18
+ readonly analysisMode?: HistoricalGraphAnalysisModeV1;
19
+ readonly maxDiagnostics?: number;
20
+ readonly expectedSourceDigest?: string;
21
+ }
22
+ export interface HistoricalGraphGitEvidencePortV1 {
23
+ readonly probe: (request: HistoricalGitEvidenceRequest) => Promise<HistoricalGitEvidenceOutcome>;
24
+ }
25
+ export type HistoricalGraphPublicCauseV1 = HistoricalLinearCauseRecordV1 | {
26
+ readonly cause: "git_unavailable" | "unsupported_ancestry_profile";
27
+ readonly commit_id: null;
28
+ readonly subject: "evidence";
29
+ readonly limit: null;
30
+ readonly actual: null;
31
+ };
32
+ export interface HistoricalGraphAnalysisExactValueV1 {
33
+ readonly numerator: string;
34
+ readonly denominator: string;
35
+ readonly unit: DurationUnit;
36
+ }
37
+ export interface HistoricalGraphAnalysisV1 {
38
+ readonly status: "not_requested" | "complete" | "unavailable";
39
+ readonly mode: HistoricalGraphAnalysisModeV1;
40
+ readonly checkpoint_commit_id: string | null;
41
+ readonly source_digest: string | null;
42
+ readonly document_id: string | null;
43
+ readonly grammar_version: number | null;
44
+ readonly precision: number;
45
+ readonly duration_unit: DurationUnit | null;
46
+ readonly milestones: readonly {
47
+ readonly source_id: string;
48
+ readonly occurrence_id: string;
49
+ readonly earliest: HistoricalGraphAnalysisExactValueV1;
50
+ readonly latest: HistoricalGraphAnalysisExactValueV1;
51
+ readonly slack: HistoricalGraphAnalysisExactValueV1;
52
+ readonly critical: boolean;
53
+ }[];
54
+ readonly edges: readonly {
55
+ readonly source_id: string;
56
+ readonly occurrence_id: string;
57
+ readonly kind: "task" | "gate";
58
+ readonly precedence: {
59
+ readonly earliest_start: HistoricalGraphAnalysisExactValueV1;
60
+ readonly earliest_finish: HistoricalGraphAnalysisExactValueV1;
61
+ readonly latest_start: HistoricalGraphAnalysisExactValueV1;
62
+ readonly latest_finish: HistoricalGraphAnalysisExactValueV1;
63
+ readonly total_float: HistoricalGraphAnalysisExactValueV1;
64
+ readonly free_float: HistoricalGraphAnalysisExactValueV1;
65
+ readonly critical: boolean;
66
+ readonly driving: boolean;
67
+ } | null;
68
+ readonly resource: {
69
+ readonly scheduled_start: HistoricalGraphAnalysisExactValueV1;
70
+ readonly scheduled_finish: HistoricalGraphAnalysisExactValueV1;
71
+ readonly resource_delay: HistoricalGraphAnalysisExactValueV1;
72
+ readonly schedule_critical: boolean;
73
+ } | null;
74
+ }[];
75
+ readonly precedence: {
76
+ readonly makespan: HistoricalGraphAnalysisExactValueV1;
77
+ readonly critical_milestone_occurrence_ids: readonly string[];
78
+ readonly critical_task_occurrence_ids: readonly string[];
79
+ readonly critical_gate_occurrence_ids: readonly string[];
80
+ readonly representative_path_occurrence_ids: readonly string[];
81
+ } | null;
82
+ readonly resource: {
83
+ readonly algorithm_id: "parallel-sgs";
84
+ readonly algorithm_version: 1;
85
+ readonly optimal: false;
86
+ readonly makespan: HistoricalGraphAnalysisExactValueV1;
87
+ readonly resource_delay: HistoricalGraphAnalysisExactValueV1;
88
+ readonly schedule_critical_task_occurrence_ids: readonly string[];
89
+ } | null;
90
+ readonly diagnostics: readonly Diagnostic[];
91
+ readonly diagnostic_codes: readonly string[];
92
+ }
93
+ export interface TargetHistoricalGraphResultV1 {
94
+ readonly schemaVersion: typeof TARGET_HISTORICAL_GRAPH_SCHEMA_VERSION;
95
+ readonly cliContractVersion: typeof TARGET_HISTORICAL_GRAPH_CLI_CONTRACT_VERSION;
96
+ readonly toolVersion: string;
97
+ readonly operation: "dag.history";
98
+ readonly ok: boolean;
99
+ readonly source: string;
100
+ readonly sourceDigest: string | null;
101
+ readonly documentId: string | null;
102
+ readonly status: HistoricalGraphStatusV1;
103
+ readonly request: {
104
+ readonly requested_endpoint: string;
105
+ readonly requested_lower_boundary: string | null;
106
+ readonly ancestry_profile: HistoricalGraphAncestryProfileV1;
107
+ readonly view: HistoricalGraphViewV1;
108
+ readonly snapshot_commit_id: string | null;
109
+ readonly analysis_mode: HistoricalGraphAnalysisModeV1;
110
+ };
111
+ readonly evidence: HistoricalGitEvidenceResult | null;
112
+ readonly linear: HistoricalLinearCoreResultV1 | null;
113
+ readonly snapshot: HistoricalCheckpointV1 | null;
114
+ readonly lineage: HistoricalLineageV1 | null;
115
+ readonly timeline: HistoricalTimelineV1 | null;
116
+ readonly analysis: HistoricalGraphAnalysisV1;
117
+ readonly causes: readonly HistoricalGraphPublicCauseV1[];
118
+ readonly diagnostics: readonly Diagnostic[];
119
+ readonly diagnosticsTruncated: boolean;
120
+ }
121
+ export declare function inspectTargetHistoricalGraphFile(request: HistoricalGraphRequestV1, gitEvidence: HistoricalGraphGitEvidencePortV1): Promise<TargetHistoricalGraphResultV1>;
122
+ export declare function targetHistoricalGraphResultToJson(value: TargetHistoricalGraphResultV1): Readonly<Record<string, unknown>>;
123
+ export declare function renderTargetHistoricalGraphText(value: TargetHistoricalGraphResultV1): string;
124
+ //# sourceMappingURL=target-historical-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target-historical-graph.d.ts","sourceRoot":"","sources":["../../src/application/target-historical-graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,sBAAsB,EAE3B,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EAGxB,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,E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G,IAAI,CAAC;IACtD,QAAQ,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACrD,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,4BAA4B,EAAE,CAAC;IACzD,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;CACxC;AA2YD,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,gCAAgC,GAC5C,OAAO,CAAC,6BAA6B,CAAC,CAgExC;AA2FD,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,6BAA6B,GACnC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuEnC;AAQD,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,6BAA6B,GACnC,MAAM,CAyCR"}
@@ -0,0 +1,547 @@
1
+ import { analyzeDocument, } from "./contract7-assurance.js";
2
+ import { HISTORICAL_DAG_MODEL_ID, HISTORICAL_DAG_MODEL_VERSION, HISTORICAL_LINEAR_CORE_LIMITS, reconstructHistoricalLinearHistory, } from "../history/historical-graph.js";
3
+ import { HISTORICAL_TRANSITION_MODEL_VERSION, } from "../history/historical-transition.js";
4
+ import { limitDiagnostics, normalizeMaxDiagnostics, sortDiagnostics, } from "../model/diagnostics.js";
5
+ import { TOOL_VERSION } from "../version.js";
6
+ export const TARGET_HISTORICAL_GRAPH_CLI_CONTRACT_VERSION = 7;
7
+ export const TARGET_HISTORICAL_GRAPH_SCHEMA_VERSION = "Perttool.HistoricalGraphResult.v1";
8
+ const TARGET_HISTORICAL_GIT_EVIDENCE_LIMITS = Object.freeze({
9
+ inspectedCommits: 2_048,
10
+ rawBytesPerSnapshot: 8_388_608,
11
+ aggregateRawSnapshotBytes: 134_217_728,
12
+ });
13
+ function deepFreeze(value) {
14
+ if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
15
+ for (const child of Object.values(value)) {
16
+ deepFreeze(child);
17
+ }
18
+ Object.freeze(value);
19
+ }
20
+ return value;
21
+ }
22
+ function publicCause(cause) {
23
+ return Object.freeze({
24
+ cause,
25
+ commit_id: null,
26
+ subject: "evidence",
27
+ limit: null,
28
+ actual: null,
29
+ });
30
+ }
31
+ function causeDiagnostic(cause, status) {
32
+ const code = cause.cause === "unsupported_ancestry_profile"
33
+ ? "PTHDG-106"
34
+ : cause.cause === "repository_race"
35
+ ? "PTHDG-105"
36
+ : cause.cause === "hard_limit"
37
+ ? "PTHDG-104"
38
+ : cause.cause === "event_payload_changed" ||
39
+ cause.cause === "identity_ambiguous" ||
40
+ cause.cause === "ambiguous_edit" ||
41
+ cause.cause === "noncanonical_removal" ||
42
+ cause.cause === "topology_conflict" ||
43
+ cause.cause === "lineage_cycle"
44
+ ? "PTHDG-103"
45
+ : cause.cause === "source_missing" ||
46
+ cause.cause === "source_invalid" ||
47
+ cause.cause === "grammar_unsupported" ||
48
+ cause.cause === "syntax_invalid" ||
49
+ cause.cause === "semantic_invalid" ||
50
+ cause.cause === "assurance_withheld" ||
51
+ cause.cause === "shallow_origin"
52
+ ? "PTHDG-102"
53
+ : "PTHDG-101";
54
+ const category = code === "PTHDG-101"
55
+ ? "historical repository or revision request is unavailable"
56
+ : code === "PTHDG-102"
57
+ ? "historical source continuity is incomplete"
58
+ : code === "PTHDG-103"
59
+ ? "historical semantic lineage is conflicted"
60
+ : code === "PTHDG-104"
61
+ ? "historical graph hard limit was exceeded"
62
+ : code === "PTHDG-105"
63
+ ? "historical repository binding changed during capture"
64
+ : "historical ancestry profile is unsupported";
65
+ return Object.freeze({
66
+ code,
67
+ severity: status === "unavailable" ? "error" : "warning",
68
+ message: `${category}: ${cause.cause}`,
69
+ helpTopic: "historical-dag",
70
+ data: Object.freeze({
71
+ cause: cause.cause,
72
+ commit_id: cause.commit_id,
73
+ subject: cause.subject,
74
+ limit: cause.limit,
75
+ actual: cause.actual,
76
+ }),
77
+ });
78
+ }
79
+ function requestProjection(request) {
80
+ return Object.freeze({
81
+ requested_endpoint: request.requestedEndpoint ?? "HEAD",
82
+ requested_lower_boundary: request.lowerBoundary ?? null,
83
+ ancestry_profile: request.ancestryProfile ?? "first_parent",
84
+ view: request.view ?? "lineage",
85
+ snapshot_commit_id: request.snapshotCommitId ?? null,
86
+ analysis_mode: request.analysisMode ?? "none",
87
+ });
88
+ }
89
+ function emptyAnalysis(mode, status, checkpointCommitId = null) {
90
+ return deepFreeze({
91
+ status,
92
+ mode,
93
+ checkpoint_commit_id: checkpointCommitId,
94
+ source_digest: null,
95
+ document_id: null,
96
+ grammar_version: null,
97
+ precision: 3,
98
+ duration_unit: null,
99
+ milestones: [],
100
+ edges: [],
101
+ precedence: null,
102
+ resource: null,
103
+ diagnostics: [],
104
+ diagnostic_codes: [],
105
+ });
106
+ }
107
+ function exact(value, unit) {
108
+ return Object.freeze({
109
+ numerator: value.numerator.toString(),
110
+ denominator: value.denominator.toString(),
111
+ unit,
112
+ });
113
+ }
114
+ function occurrenceMap(graph) {
115
+ return new Map(graph.occurrences.map((occurrence) => [
116
+ `${occurrence.entity_kind}\u0000${occurrence.source_id}`,
117
+ occurrence,
118
+ ]));
119
+ }
120
+ function occurrenceId(occurrences, kind, sourceId) {
121
+ return occurrences.get(`${kind}\u0000${sourceId}`)?.occurrence_id ?? null;
122
+ }
123
+ function analysisProjection(result, checkpoint) {
124
+ if (!result.ok || result.durationUnit === null) {
125
+ return deepFreeze({
126
+ ...emptyAnalysis(result.mode, "unavailable", checkpoint.commit_id),
127
+ source_digest: checkpoint.source_digest,
128
+ document_id: result.documentId,
129
+ grammar_version: result.grammarVersion,
130
+ precision: result.precision,
131
+ diagnostics: result.diagnostics,
132
+ diagnostic_codes: result.diagnostics.map(({ code }) => code),
133
+ });
134
+ }
135
+ const unit = result.durationUnit;
136
+ const occurrences = occurrenceMap(checkpoint.graph);
137
+ const milestoneTimings = new Map((result.precedence?.milestones ?? []).map((value) => [value.id, value]));
138
+ const edgeTimings = new Map((result.precedence?.edges ?? []).map((value) => [value.id, value]));
139
+ const scheduledTasks = new Map((result.resource?.tasks ?? []).map((value) => [value.id, value]));
140
+ const scheduleCritical = new Set(result.resource?.scheduleCritical.taskIds ?? []);
141
+ const milestones = checkpoint.graph.occurrences.flatMap((occurrence) => {
142
+ if (occurrence.entity_kind !== "milestone" || occurrence.occurrence_id === null) {
143
+ return [];
144
+ }
145
+ const timing = milestoneTimings.get(occurrence.source_id);
146
+ return timing === undefined
147
+ ? []
148
+ : [{
149
+ source_id: occurrence.source_id,
150
+ occurrence_id: occurrence.occurrence_id,
151
+ earliest: exact(timing.earliest, unit),
152
+ latest: exact(timing.latest, unit),
153
+ slack: exact(timing.slack, unit),
154
+ critical: timing.slack.numerator === 0n,
155
+ }];
156
+ });
157
+ const edges = checkpoint.graph.occurrences.flatMap((occurrence) => {
158
+ if ((occurrence.entity_kind !== "task" && occurrence.entity_kind !== "gate") ||
159
+ occurrence.occurrence_id === null)
160
+ return [];
161
+ const timing = edgeTimings.get(occurrence.source_id);
162
+ const scheduled = occurrence.entity_kind === "task"
163
+ ? scheduledTasks.get(occurrence.source_id)
164
+ : undefined;
165
+ return [{
166
+ source_id: occurrence.source_id,
167
+ occurrence_id: occurrence.occurrence_id,
168
+ kind: occurrence.entity_kind,
169
+ precedence: timing === undefined
170
+ ? null
171
+ : {
172
+ earliest_start: exact(timing.es, unit),
173
+ earliest_finish: exact(timing.ef, unit),
174
+ latest_start: exact(timing.ls, unit),
175
+ latest_finish: exact(timing.lf, unit),
176
+ total_float: exact(timing.totalFloat, unit),
177
+ free_float: exact(timing.freeFloat, unit),
178
+ critical: timing.isCritical,
179
+ driving: timing.isDriving,
180
+ },
181
+ resource: scheduled === undefined
182
+ ? null
183
+ : {
184
+ scheduled_start: exact(scheduled.start, unit),
185
+ scheduled_finish: exact(scheduled.finish, unit),
186
+ resource_delay: exact(scheduled.resourceWait, unit),
187
+ schedule_critical: scheduleCritical.has(occurrence.source_id),
188
+ },
189
+ }];
190
+ });
191
+ const ids = (kind, sourceIds) => sourceIds.flatMap((sourceId) => {
192
+ const id = occurrenceId(occurrences, kind, sourceId);
193
+ return id === null ? [] : [id];
194
+ });
195
+ return deepFreeze({
196
+ status: "complete",
197
+ mode: result.mode,
198
+ checkpoint_commit_id: checkpoint.commit_id,
199
+ source_digest: checkpoint.source_digest,
200
+ document_id: result.documentId,
201
+ grammar_version: result.grammarVersion,
202
+ precision: result.precision,
203
+ duration_unit: unit,
204
+ milestones,
205
+ edges,
206
+ precedence: result.precedence === null
207
+ ? null
208
+ : {
209
+ makespan: exact(result.precedence.makespan, unit),
210
+ critical_milestone_occurrence_ids: ids("milestone", result.precedence.critical.milestoneIds),
211
+ critical_task_occurrence_ids: ids("task", result.precedence.critical.taskIds),
212
+ critical_gate_occurrence_ids: ids("gate", result.precedence.critical.gateIds),
213
+ representative_path_occurrence_ids: result.precedence.critical.representativePath.edgeIds.flatMap((sourceId) => {
214
+ const task = occurrenceId(occurrences, "task", sourceId);
215
+ if (task !== null)
216
+ return [task];
217
+ const gate = occurrenceId(occurrences, "gate", sourceId);
218
+ return gate === null ? [] : [gate];
219
+ }),
220
+ },
221
+ resource: result.resource === null
222
+ ? null
223
+ : {
224
+ algorithm_id: result.resource.algorithm.id,
225
+ algorithm_version: result.resource.algorithm.version,
226
+ optimal: result.resource.algorithm.optimal,
227
+ makespan: exact(result.resource.makespan, unit),
228
+ resource_delay: exact(result.resource.resourceDelay, unit),
229
+ schedule_critical_task_occurrence_ids: ids("task", result.resource.scheduleCritical.taskIds),
230
+ },
231
+ diagnostics: result.diagnostics,
232
+ diagnostic_codes: result.diagnostics.map(({ code }) => code),
233
+ });
234
+ }
235
+ function selectedAnalysisCheckpoint(linear, view) {
236
+ const commitId = view === "snapshot"
237
+ ? linear.selected_snapshot_commit_id
238
+ : linear.resolved_endpoint;
239
+ return commitId === null
240
+ ? null
241
+ : linear.checkpoints.find(({ commit_id }) => commit_id === commitId) ?? null;
242
+ }
243
+ function runAnalysis(evidence, linear, view, mode) {
244
+ if (mode === "none")
245
+ return emptyAnalysis(mode, "not_requested");
246
+ const checkpoint = selectedAnalysisCheckpoint(linear, view);
247
+ if (checkpoint === null)
248
+ return emptyAnalysis(mode, "unavailable");
249
+ const snapshot = evidence.snapshots.find(({ commitId }) => commitId === checkpoint.commit_id);
250
+ if (snapshot?.source === null || snapshot?.source === undefined) {
251
+ return emptyAnalysis(mode, "unavailable", checkpoint.commit_id);
252
+ }
253
+ let text;
254
+ try {
255
+ text = new TextDecoder("utf-8", {
256
+ fatal: true,
257
+ ignoreBOM: true,
258
+ }).decode(snapshot.source);
259
+ }
260
+ catch {
261
+ return emptyAnalysis(mode, "unavailable", checkpoint.commit_id);
262
+ }
263
+ return analysisProjection(analyzeDocument(text, {
264
+ mode,
265
+ maxPaths: 1,
266
+ precision: 3,
267
+ maxDiagnostics: 100,
268
+ }), checkpoint);
269
+ }
270
+ function viewStatus(linear, view) {
271
+ if (linear.status === "unavailable")
272
+ return "unavailable";
273
+ if (linear.status === "incomplete")
274
+ return "incomplete";
275
+ if (view === "snapshot") {
276
+ return linear.selected_snapshot === null ? "incomplete" : "complete";
277
+ }
278
+ if (view === "lineage") {
279
+ return linear.lineage === null ? "incomplete" : "complete";
280
+ }
281
+ return linear.timeline === null || linear.status !== "complete"
282
+ ? "incomplete"
283
+ : "complete";
284
+ }
285
+ function result(request, values) {
286
+ const projectedRequest = requestProjection(request);
287
+ const maximum = normalizeMaxDiagnostics(request.maxDiagnostics);
288
+ const diagnostics = sortDiagnostics([
289
+ ...values.causes.map((cause) => causeDiagnostic(cause, values.status)),
290
+ ...values.analysis.diagnostics,
291
+ ]);
292
+ const limited = limitDiagnostics(diagnostics, maximum);
293
+ const selected = values.linear?.selected_snapshot ?? null;
294
+ const endpointSnapshot = values.evidence?.snapshots.find(({ commitId }) => commitId === values.evidence?.resolvedEndpoint);
295
+ const sourceDigest = projectedRequest.view === "snapshot"
296
+ ? selected?.source_digest ?? null
297
+ : endpointSnapshot?.sourceDigest ?? null;
298
+ return deepFreeze({
299
+ schemaVersion: TARGET_HISTORICAL_GRAPH_SCHEMA_VERSION,
300
+ cliContractVersion: TARGET_HISTORICAL_GRAPH_CLI_CONTRACT_VERSION,
301
+ toolVersion: TOOL_VERSION,
302
+ operation: "dag.history",
303
+ ok: values.status !== "unavailable",
304
+ source: request.targetPath,
305
+ sourceDigest,
306
+ documentId: selected?.graph.project_id ??
307
+ values.linear?.checkpoints.at(-1)?.graph.project_id ?? null,
308
+ status: values.status,
309
+ request: projectedRequest,
310
+ evidence: values.evidence,
311
+ linear: values.linear,
312
+ snapshot: projectedRequest.view === "snapshot" ? selected : null,
313
+ lineage: projectedRequest.view === "lineage"
314
+ ? values.linear?.lineage ?? null
315
+ : null,
316
+ timeline: projectedRequest.view === "timeline"
317
+ ? values.linear?.timeline ?? null
318
+ : null,
319
+ analysis: values.analysis,
320
+ causes: [...values.causes],
321
+ diagnostics: limited.diagnostics,
322
+ diagnosticsTruncated: limited.truncated,
323
+ });
324
+ }
325
+ export async function inspectTargetHistoricalGraphFile(request, gitEvidence) {
326
+ const projectedRequest = requestProjection(request);
327
+ if (projectedRequest.ancestry_profile !== "first_parent") {
328
+ return result(request, {
329
+ evidence: null,
330
+ linear: null,
331
+ analysis: emptyAnalysis(projectedRequest.analysis_mode, projectedRequest.analysis_mode === "none"
332
+ ? "not_requested"
333
+ : "unavailable"),
334
+ status: "unavailable",
335
+ causes: [publicCause("unsupported_ancestry_profile")],
336
+ });
337
+ }
338
+ const evidence = await gitEvidence.probe({
339
+ targetPath: request.targetPath,
340
+ ...(request.expectedSourceDigest === undefined
341
+ ? {}
342
+ : { expectedSourceDigest: request.expectedSourceDigest }),
343
+ ...(request.requestedEndpoint === undefined
344
+ ? {}
345
+ : { requestedEndpoint: request.requestedEndpoint }),
346
+ ...(request.lowerBoundary === undefined
347
+ ? {}
348
+ : { lowerBoundary: request.lowerBoundary }),
349
+ });
350
+ if (!evidence.ok) {
351
+ return result(request, {
352
+ evidence: null,
353
+ linear: null,
354
+ analysis: emptyAnalysis(projectedRequest.analysis_mode, projectedRequest.analysis_mode === "none"
355
+ ? "not_requested"
356
+ : "unavailable"),
357
+ status: "unavailable",
358
+ causes: [publicCause("git_unavailable")],
359
+ });
360
+ }
361
+ const linear = reconstructHistoricalLinearHistory(evidence, {
362
+ ...(request.snapshotCommitId === undefined
363
+ ? {}
364
+ : { snapshotCommitId: request.snapshotCommitId }),
365
+ });
366
+ const analysis = runAnalysis(evidence, linear, projectedRequest.view, projectedRequest.analysis_mode);
367
+ let status = viewStatus(linear, projectedRequest.view);
368
+ if (status === "complete" && analysis.status === "unavailable") {
369
+ status = "incomplete";
370
+ }
371
+ return result(request, {
372
+ evidence,
373
+ linear,
374
+ analysis,
375
+ status,
376
+ causes: linear.causes,
377
+ });
378
+ }
379
+ function positionToJson(position) {
380
+ return {
381
+ offset: position.offset,
382
+ line: position.line,
383
+ column: position.column,
384
+ };
385
+ }
386
+ function bindingToJson(binding) {
387
+ return {
388
+ repository_id: binding.repository_id,
389
+ repository_relative_path: binding.repository_relative_path,
390
+ commit_id: binding.commit_id,
391
+ blob_id: binding.blob_id,
392
+ source_digest: binding.source_digest,
393
+ range: {
394
+ start: positionToJson(binding.range.start),
395
+ end: positionToJson(binding.range.end),
396
+ },
397
+ declaration_kind: binding.declaration_kind,
398
+ source_id: binding.source_id,
399
+ owner_path: binding.owner_path,
400
+ };
401
+ }
402
+ function checkpointSummary(checkpoint) {
403
+ return {
404
+ commit_id: checkpoint.commit_id,
405
+ parent_commit_ids: checkpoint.parent_commit_ids,
406
+ blob_id: checkpoint.blob_id,
407
+ source_digest: checkpoint.source_digest,
408
+ recorded_at: checkpoint.recorded_at,
409
+ is_merge_commit: checkpoint.is_merge_commit,
410
+ segment_ordinal: checkpoint.segment_ordinal,
411
+ assurance: checkpoint.assurance,
412
+ semantic_digest: checkpoint.semantic_digest,
413
+ topology_epoch_id: checkpoint.graph.topology_epoch_id,
414
+ transition: checkpoint.transition,
415
+ occurrence_count: checkpoint.graph.occurrences.length,
416
+ source_binding_count: checkpoint.source_bindings.length,
417
+ };
418
+ }
419
+ function snapshotToJson(snapshot) {
420
+ return snapshot === null
421
+ ? null
422
+ : {
423
+ ...checkpointSummary(snapshot),
424
+ graph: snapshot.graph,
425
+ };
426
+ }
427
+ function allSourceBindings(linear) {
428
+ if (linear === null)
429
+ return [];
430
+ return linear.checkpoints.flatMap(({ source_bindings }) => source_bindings.map(bindingToJson));
431
+ }
432
+ function diagnosticToJson(diagnostic) {
433
+ return {
434
+ code: diagnostic.code,
435
+ severity: diagnostic.severity,
436
+ message: diagnostic.message,
437
+ entity_id: diagnostic.entityId ?? null,
438
+ span: null,
439
+ related: [],
440
+ help_topic: null,
441
+ guide_topic: diagnostic.helpTopic ?? null,
442
+ expected_syntax: null,
443
+ fixes: [],
444
+ data: diagnostic.data ?? {},
445
+ };
446
+ }
447
+ export function targetHistoricalGraphResultToJson(value) {
448
+ const evidence = value.evidence;
449
+ const linear = value.linear;
450
+ const { diagnostics: _analysisDiagnostics, ...analysis } = value.analysis;
451
+ return {
452
+ schema_version: value.schemaVersion,
453
+ cli_contract_version: value.cliContractVersion,
454
+ tool_version: value.toolVersion,
455
+ operation: value.operation,
456
+ ok: value.ok,
457
+ document_id: value.documentId,
458
+ source: value.source,
459
+ source_digest: value.sourceDigest,
460
+ diagnostics: value.diagnostics.map(diagnosticToJson),
461
+ diagnostics_truncated: value.diagnosticsTruncated,
462
+ model: HISTORICAL_DAG_MODEL_ID,
463
+ model_version: HISTORICAL_DAG_MODEL_VERSION,
464
+ transition_model_version: HISTORICAL_TRANSITION_MODEL_VERSION,
465
+ status: value.status,
466
+ request: value.request,
467
+ evidence: {
468
+ status: evidence?.status ?? "unavailable",
469
+ ancestry_profile: "first_parent",
470
+ object_format: evidence?.objectFormat ?? null,
471
+ repository_id: evidence?.repositoryId ?? null,
472
+ repository_relative_path: evidence?.repositoryRelativePath ?? null,
473
+ repository_read_snapshot_id: evidence?.repositoryReadSnapshotId ?? null,
474
+ requested_endpoint: value.request.requested_endpoint,
475
+ resolved_endpoint: evidence?.resolvedEndpoint ?? null,
476
+ requested_lower_boundary: value.request.requested_lower_boundary,
477
+ resolved_lower_boundary: evidence?.resolvedLowerBoundary ?? null,
478
+ oldest_inspected_commit_id: evidence?.oldestInspectedCommitId ?? null,
479
+ inspected_commit_ids: evidence?.inspectedCommitIds ?? [],
480
+ aggregate_raw_snapshot_bytes: evidence?.aggregateRawSnapshotBytes ?? 0,
481
+ },
482
+ effective_checkpoint_id: linear?.effective_checkpoint_id ?? null,
483
+ selected_snapshot_commit_id: linear?.selected_snapshot_commit_id ??
484
+ value.request.snapshot_commit_id ??
485
+ evidence?.resolvedEndpoint ??
486
+ value.request.requested_endpoint,
487
+ checkpoints: linear?.checkpoints.map(checkpointSummary) ?? [],
488
+ snapshot: snapshotToJson(value.snapshot),
489
+ lineage: value.lineage,
490
+ timeline: value.timeline,
491
+ analysis,
492
+ source_bindings: allSourceBindings(linear),
493
+ causes: value.causes,
494
+ limits: {
495
+ inspected_commits: evidence?.limits.inspectedCommits ??
496
+ TARGET_HISTORICAL_GIT_EVIDENCE_LIMITS.inspectedCommits,
497
+ raw_bytes_per_snapshot: evidence?.limits.rawBytesPerSnapshot ??
498
+ TARGET_HISTORICAL_GIT_EVIDENCE_LIMITS.rawBytesPerSnapshot,
499
+ aggregate_raw_snapshot_bytes: evidence?.limits.aggregateRawSnapshotBytes ??
500
+ TARGET_HISTORICAL_GIT_EVIDENCE_LIMITS.aggregateRawSnapshotBytes,
501
+ entity_value_epochs: linear?.limits.entityValueEpochs ??
502
+ HISTORICAL_LINEAR_CORE_LIMITS.entityValueEpochs,
503
+ transition_records: linear?.limits.transitionRecords ??
504
+ HISTORICAL_LINEAR_CORE_LIMITS.transitionRecords,
505
+ rendered_graph_occurrences: linear?.limits.renderedGraphOccurrences ??
506
+ HISTORICAL_LINEAR_CORE_LIMITS.renderedGraphOccurrences,
507
+ historical_source_bindings: linear?.limits.historicalSourceBindings ??
508
+ HISTORICAL_LINEAR_CORE_LIMITS.historicalSourceBindings,
509
+ },
510
+ };
511
+ }
512
+ function textExact(value) {
513
+ return `${value.numerator}/${value.denominator}:${value.unit}`;
514
+ }
515
+ export function renderTargetHistoricalGraphText(value) {
516
+ const linear = value.linear;
517
+ const lines = [
518
+ `HISTORICAL_GRAPH status=${value.status} view=${value.request.view} ancestry=${value.request.ancestry_profile} endpoint=${value.evidence?.resolvedEndpoint ?? "-"} lower=${value.evidence?.resolvedLowerBoundary ?? "-"} selected=${linear?.selected_snapshot_commit_id ?? "-"}`,
519
+ ];
520
+ for (const checkpoint of linear?.checkpoints ?? []) {
521
+ lines.push(`CHECKPOINT commit=${checkpoint.commit_id} segment=${checkpoint.segment_ordinal} transition=${checkpoint.transition.class} topology=${checkpoint.graph.topology_epoch_id ?? "-"} occurrences=${checkpoint.graph.occurrences.length} assurance=${checkpoint.assurance}`);
522
+ }
523
+ const occurrences = value.snapshot?.graph.occurrences ??
524
+ value.lineage?.occurrences ?? [];
525
+ for (const occurrence of occurrences) {
526
+ const semantic = occurrence.semantic;
527
+ const label = occurrence.entity_kind === "task"
528
+ ? "plan" in semantic ? semantic.plan.title : occurrence.source_id
529
+ : occurrence.entity_kind === "gate"
530
+ ? "reason" in semantic ? semantic.reason : occurrence.source_id
531
+ : "title" in semantic ? semantic.title : occurrence.source_id;
532
+ const timing = occurrence.entity_kind === "task" &&
533
+ "plan" in semantic && semantic.plan.timing.kind === "duration"
534
+ ? ` duration=${textExact(semantic.plan.timing.value)}`
535
+ : "";
536
+ lines.push(`OCCURRENCE id=${occurrence.occurrence_id ?? "-"} kind=${occurrence.entity_kind} source_id=${occurrence.source_id} from=${occurrence.from_occurrence_id ?? "-"} to=${occurrence.to_occurrence_id ?? "-"} retired_at=${occurrence.retired_at_commit_id ?? "-"}${timing} label=${JSON.stringify(label)}`);
537
+ }
538
+ for (const entry of value.timeline?.entries ?? []) {
539
+ lines.push(`TIMELINE commit=${entry.commit_id} validity=${entry.validity} segment=${entry.segment_ordinal ?? "-"} transition=${entry.transition?.class ?? "-"} topology=${entry.topology_epoch_id ?? "-"}`);
540
+ }
541
+ lines.push(`ANALYSIS status=${value.analysis.status} mode=${value.analysis.mode} checkpoint=${value.analysis.checkpoint_commit_id ?? "-"} precedence=${value.analysis.precedence === null ? "-" : textExact(value.analysis.precedence.makespan)} resource=${value.analysis.resource === null ? "-" : textExact(value.analysis.resource.makespan)}`);
542
+ for (const cause of value.causes) {
543
+ lines.push(`CAUSE ${cause.cause} subject=${cause.subject} commit=${cause.commit_id ?? "-"} limit=${cause.limit ?? "-"} actual=${cause.actual ?? "-"}`);
544
+ }
545
+ return `${lines.join("\n")}\n`;
546
+ }
547
+ //# sourceMappingURL=target-historical-graph.js.map