@leitwerk-dev/domain 0.2.0 → 0.3.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 (60) hide show
  1. package/dist/actor.d.ts +4 -2
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/domain-model.d.ts +397 -64
  4. package/dist/domain-model.d.ts.map +1 -1
  5. package/dist/index.d.ts +11 -11
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -21
  8. package/dist/index.js.map +1 -1
  9. package/dist/launcher-recent-values.d.ts +5 -0
  10. package/dist/launcher-recent-values.d.ts.map +1 -1
  11. package/dist/markdown-normalize.d.ts +3 -0
  12. package/dist/markdown-normalize.d.ts.map +1 -1
  13. package/dist/number-normalize.d.ts +1 -1
  14. package/dist/number-normalize.d.ts.map +1 -1
  15. package/dist/process-definitions.d.ts +37 -8
  16. package/dist/process-definitions.d.ts.map +1 -1
  17. package/dist/process-model-config.d.ts +18 -0
  18. package/dist/process-model-config.d.ts.map +1 -1
  19. package/dist/process-row-slots.d.ts +14 -0
  20. package/dist/process-row-slots.d.ts.map +1 -1
  21. package/dist/process-state-json.d.ts +13 -0
  22. package/dist/process-state-json.d.ts.map +1 -1
  23. package/dist/repo-locator.d.ts +8 -0
  24. package/dist/repo-locator.d.ts.map +1 -1
  25. package/dist/semantic-entry-refs.d.ts +21 -0
  26. package/dist/semantic-entry-refs.d.ts.map +1 -1
  27. package/dist/startup-observation.d.ts +35 -2
  28. package/dist/startup-observation.d.ts.map +1 -1
  29. package/dist/string-normalize.d.ts +7 -2
  30. package/dist/string-normalize.d.ts.map +1 -1
  31. package/dist/turn-acceptance.d.ts +2 -0
  32. package/dist/turn-acceptance.d.ts.map +1 -1
  33. package/dist/turn-annotations.d.ts +27 -0
  34. package/dist/turn-annotations.d.ts.map +1 -1
  35. package/dist/turn-recovery.d.ts +24 -0
  36. package/dist/turn-recovery.d.ts.map +1 -1
  37. package/dist/turn-start-resolution.d.ts +48 -1
  38. package/dist/turn-start-resolution.d.ts.map +1 -1
  39. package/dist/unknown-record.d.ts +3 -1
  40. package/dist/unknown-record.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/actor.ts +4 -2
  43. package/src/domain-model.ts +428 -72
  44. package/src/index.ts +1 -34
  45. package/src/launcher-recent-values.ts +5 -0
  46. package/src/markdown-normalize.ts +3 -0
  47. package/src/number-normalize.ts +1 -1
  48. package/src/process-definitions.ts +37 -8
  49. package/src/process-model-config.ts +27 -1
  50. package/src/process-row-slots.ts +14 -0
  51. package/src/process-state-json.ts +13 -0
  52. package/src/repo-locator.ts +8 -0
  53. package/src/semantic-entry-refs.ts +21 -0
  54. package/src/startup-observation.ts +35 -2
  55. package/src/string-normalize.ts +7 -2
  56. package/src/turn-acceptance.ts +2 -0
  57. package/src/turn-annotations.ts +27 -0
  58. package/src/turn-recovery.ts +20 -0
  59. package/src/turn-start-resolution.ts +59 -5
  60. package/src/unknown-record.ts +3 -1
@@ -1,4 +1,4 @@
1
- /** First server receipt of a physical worker startup milestone. */
1
+ /** First server receipt of a physical worker startup milestone. @internal */
2
2
  export type StartupMilestone =
3
3
  | "pvc_requested"
4
4
  | "pvc_acknowledged"
@@ -13,35 +13,60 @@ export type StartupMilestone =
13
13
  | "container_started"
14
14
  | "prompt_started"
15
15
  | "first_text";
16
+ /** @internal */
16
17
  export interface StartupObservation {
18
+ /** @internal */
17
19
  workerLeaseId: string;
20
+ /** @internal */
18
21
  milestone: StartupMilestone;
22
+ /** @internal */
19
23
  observedAt: string;
24
+ /** @internal */
20
25
  sourceAt: string | null;
26
+ /** @internal */
21
27
  sourceKind: "server" | "kubernetes_status" | "kubernetes_event";
28
+ /** @internal */
22
29
  objectUid: string | null;
30
+ /** @internal */
23
31
  turnRecordId: string | null;
24
- /** Sampling lower bound, never an exact binding timestamp. */
32
+ /** Sampling lower bound, never an exact binding timestamp. @internal */
25
33
  notBefore: string | null;
34
+ /** @internal */
26
35
  metadata: {
36
+ /** @internal */
27
37
  node?: string;
38
+ /** @internal */
28
39
  imageId?: string;
40
+ /** @internal */
29
41
  image?: string;
42
+ /** @internal */
30
43
  storageClass?: string;
44
+ /** @internal */
31
45
  cpu?: string;
46
+ /** @internal */
32
47
  memory?: string;
48
+ /** @internal */
33
49
  namespace?: string;
50
+ /** @internal */
34
51
  podName?: string;
52
+ /** @internal */
35
53
  precision?: "milliseconds" | "microseconds" | "seconds" | "sampling_interval";
36
54
  };
37
55
  }
56
+ /** @internal */
38
57
  export interface StartupInterval {
58
+ /** @internal */
39
59
  start: string | null;
60
+ /** @internal */
40
61
  end: string | null;
62
+ /** @internal */
41
63
  durationMs: number | null;
64
+ /** @internal */
42
65
  status: "available" | "missing" | "invalid_order";
66
+ /** @internal */
43
67
  clock: "server" | "kubernetes";
44
68
  }
69
+ /** @internal */
45
70
  export function startupInterval(
46
71
  start: string | null | undefined,
47
72
  end: string | null | undefined,
@@ -62,12 +87,20 @@ export function startupInterval(
62
87
  clock,
63
88
  };
64
89
  }
90
+ /** @internal */
65
91
  export interface PhysicalWorkerStart {
92
+ /** @internal */
66
93
  workerLeaseId: string;
94
+ /** @internal */
67
95
  workerId: string;
96
+ /** @internal */
68
97
  turnStartRecordId: string | null;
98
+ /** @internal */
69
99
  turnRecordId: string | null;
100
+ /** @internal */
70
101
  state: string;
102
+ /** @internal */
71
103
  observations: StartupObservation[];
104
+ /** @internal */
72
105
  intervals: Record<string, StartupInterval>;
73
106
  }
@@ -1,3 +1,4 @@
1
+ /** @internal */
1
2
  export function toErrorMessage(error: unknown): string {
2
3
  if (error instanceof Error && error.message.trim() !== "") {
3
4
  return error.message;
@@ -5,20 +6,23 @@ export function toErrorMessage(error: unknown): string {
5
6
  return String(error);
6
7
  }
7
8
 
8
- /** Return non-blank strings verbatim; unlike trimToNull, preserve surrounding whitespace. */
9
+ /** Return non-blank strings verbatim; unlike trimToNull, preserve surrounding whitespace. @internal */
9
10
  export function readNonBlankString(value: unknown): string | null {
10
11
  return typeof value === "string" && value.trim() !== "" ? value : null;
11
12
  }
12
13
 
14
+ /** @internal */
13
15
  export function trimString(value: unknown): string {
14
16
  return typeof value === "string" ? value.trim() : "";
15
17
  }
16
18
 
19
+ /** @internal */
17
20
  export function trimToNull(value: unknown): string | null {
18
21
  const trimmed = trimString(value);
19
22
  return trimmed === "" ? null : trimmed;
20
23
  }
21
24
 
25
+ /** @internal */
22
26
  export function normalizeStringArray(value: unknown): string[] {
23
27
  if (!Array.isArray(value)) {
24
28
  return [];
@@ -33,6 +37,7 @@ export function normalizeStringArray(value: unknown): string[] {
33
37
  * flow diagrams) must route through this so the translation lives in one place
34
38
  * and can later be swapped for a localized lookup.
35
39
  */
40
+ /** @internal */
36
41
  export function humanizeProcessLabel(identifier: unknown): string {
37
42
  return trimString(identifier)
38
43
  .replace(/[_-]+/g, " ")
@@ -50,7 +55,7 @@ const IDENTIFIER_WORD_LABELS: Record<string, string> = {
50
55
  ui: "UI",
51
56
  };
52
57
 
53
- /** Display an identifier with known acronyms, preserving the remaining spelling. */
58
+ /** Display an identifier with known acronyms, preserving the remaining spelling. @internal */
54
59
  export function formatProcessIdentifier(value: string): string {
55
60
  return value
56
61
  .split(/[_-]+/)
@@ -1,3 +1,5 @@
1
+ /** @public */
1
2
  export const TURN_ACCEPTANCE_STATES = ["accepted", "requires_changes", "neutral"] as const;
2
3
 
4
+ /** @public */
3
5
  export type TurnAcceptanceState = (typeof TURN_ACCEPTANCE_STATES)[number];
@@ -4,49 +4,75 @@ import {
4
4
  } from "./semantic-entry-refs.js";
5
5
  import { trimToNull } from "./string-normalize.js";
6
6
 
7
+ /** @internal */
7
8
  export const TURN_ANNOTATION_REFERENCE_KINDS = [
8
9
  "turn_record",
9
10
  "entry",
10
11
  "semantic_entry_ref",
11
12
  ] as const;
12
13
 
14
+ /** @internal */
13
15
  export type TurnAnnotationReferenceKind = (typeof TURN_ANNOTATION_REFERENCE_KINDS)[number];
16
+ /** @internal */
14
17
  export type TurnAnnotationReferenceRole = string;
15
18
 
19
+ /** @internal */
16
20
  export interface TurnRecordAnnotationReference {
21
+ /** @internal */
17
22
  kind: "turn_record";
23
+ /** @internal */
18
24
  turnRecordId: string;
25
+ /** @internal */
19
26
  role: TurnAnnotationReferenceRole | null;
20
27
  }
21
28
 
29
+ /** @internal */
22
30
  export interface EntryTurnAnnotationReference {
31
+ /** @internal */
23
32
  kind: "entry";
33
+ /** @internal */
24
34
  entryId: string;
35
+ /** @internal */
25
36
  role: TurnAnnotationReferenceRole | null;
26
37
  }
27
38
 
39
+ /** @internal */
28
40
  export interface SemanticEntryRefTurnAnnotationReference {
41
+ /** @internal */
29
42
  kind: "semantic_entry_ref";
43
+ /** @internal */
30
44
  ref: ProcessSemanticEntryRefKey;
45
+ /** @internal */
31
46
  role: TurnAnnotationReferenceRole | null;
32
47
  }
33
48
 
49
+ /** @internal */
34
50
  export type TurnAnnotationReference =
35
51
  | TurnRecordAnnotationReference
36
52
  | EntryTurnAnnotationReference
37
53
  | SemanticEntryRefTurnAnnotationReference;
38
54
 
55
+ /** @internal */
39
56
  export interface ProcessTurnAnnotation {
57
+ /** @internal */
40
58
  id: string;
59
+ /** @internal */
41
60
  instanceId: string;
61
+ /** @internal */
42
62
  annotationType: string;
63
+ /** @internal */
43
64
  annotationKey: string | null;
65
+ /** @internal */
44
66
  references: TurnAnnotationReference[];
67
+ /** @internal */
45
68
  payload: Record<string, unknown>;
69
+ /** @internal */
46
70
  createdAt: string;
71
+ /** @internal */
47
72
  updatedAt: string;
48
73
  }
49
74
 
75
+ /** @internal */
50
76
  export function parseTurnAnnotationReference(value: unknown): TurnAnnotationReference | null {
51
77
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
52
78
  return null;
@@ -69,6 +95,7 @@ export function parseTurnAnnotationReference(value: unknown): TurnAnnotationRefe
69
95
  return null;
70
96
  }
71
97
 
98
+ /** @internal */
72
99
  export function parseTurnAnnotationReferences(value: unknown): TurnAnnotationReference[] {
73
100
  if (!Array.isArray(value)) {
74
101
  return [];
@@ -1,8 +1,10 @@
1
1
  import { normalizeStringArray, trimToNull } from "./string-normalize.js";
2
2
  import { isUnknownRecord as isRecord } from "./unknown-record.js";
3
3
 
4
+ /** @internal */
4
5
  export const DEFAULT_CONTINUE_PROMPT = "continue";
5
6
 
7
+ /** @internal */
6
8
  export const FAILED_TURN_RECOVERY_CODES = [
7
9
  "generic_continue",
8
10
  "missing_outcome_tool",
@@ -10,22 +12,32 @@ export const FAILED_TURN_RECOVERY_CODES = [
10
12
  "missing_required_tool_calls",
11
13
  ] as const;
12
14
 
15
+ /** @internal */
13
16
  export type FailedTurnRecoveryCode = (typeof FAILED_TURN_RECOVERY_CODES)[number];
14
17
 
18
+ /** @internal */
15
19
  export interface FailedTurnRecoveryContext {
20
+ /** @internal */
16
21
  strategy: "continue";
22
+ /** @internal */
17
23
  suggestedContinuePrompt: string;
24
+ /** @internal */
18
25
  failureCode: FailedTurnRecoveryCode;
26
+ /** @internal */
19
27
  missingToolNames?: string[];
20
28
  }
21
29
 
30
+ /** @internal */
22
31
  export type FailedTurnRecoveryOverrides = Partial<Omit<FailedTurnRecoveryContext, "strategy">>;
23
32
 
33
+ /** @internal */
24
34
  export const FAILED_TURN_RECOVERY_METADATA_KEY = "failedTurnRecovery";
35
+ /** @internal */
25
36
  export const CONTINUE_PROMPT_METADATA_KEY = "continuePrompt";
26
37
  const TERMINAL_OUTCOME_RECORDING_FAILURE_PREFIX =
27
38
  "Server could not durably record worker turn outcome:";
28
39
 
40
+ /** @internal */
29
41
  export function isFailedTurnRecoveryCode(value: string): value is FailedTurnRecoveryCode {
30
42
  return (FAILED_TURN_RECOVERY_CODES as readonly string[]).includes(value);
31
43
  }
@@ -37,6 +49,7 @@ function normalizeUniqueStringArray(value: unknown): string[] | undefined {
37
49
 
38
50
  export { trimToNull as normalizeContinuePrompt };
39
51
 
52
+ /** @internal */
40
53
  export function createGenericFailedTurnRecoveryContext(
41
54
  overrides: FailedTurnRecoveryOverrides = {},
42
55
  ): FailedTurnRecoveryContext {
@@ -48,8 +61,11 @@ export function createGenericFailedTurnRecoveryContext(
48
61
  };
49
62
  }
50
63
 
64
+ /** @internal */
51
65
  export function inferTerminalRecordingFailedTurnRecoveryContext(input: {
66
+ /** @internal */
52
67
  errorSummary?: string | null;
68
+ /** @internal */
53
69
  errorClass?: string | null;
54
70
  }): FailedTurnRecoveryContext | null {
55
71
  if (
@@ -61,18 +77,22 @@ export function inferTerminalRecordingFailedTurnRecoveryContext(input: {
61
77
  return createGenericFailedTurnRecoveryContext();
62
78
  }
63
79
 
80
+ /** @internal */
64
81
  export function buildFailedTurnRecoveryMetadata(
65
82
  turnRecordId: string,
66
83
  context: FailedTurnRecoveryOverrides = {},
67
84
  ) {
68
85
  return {
86
+ /** @internal */
69
87
  [FAILED_TURN_RECOVERY_METADATA_KEY]: {
88
+ /** @internal */
70
89
  turnRecordId,
71
90
  ...createGenericFailedTurnRecoveryContext(context),
72
91
  },
73
92
  };
74
93
  }
75
94
 
95
+ /** @internal */
76
96
  export function readFailedTurnRecoveryContext(
77
97
  metadata: Record<string, unknown> | null | undefined,
78
98
  expectedTurnRecordId?: string | null,
@@ -5,52 +5,84 @@ import type {
5
5
  ProcessSemanticEntryRefs,
6
6
  } from "./semantic-entry-refs.js";
7
7
 
8
+ /** @internal */
8
9
  export interface ProcessTurnStartFromCurrentLeaf {
10
+ /** @internal */
9
11
  kind: "current_leaf";
10
12
  }
11
13
 
14
+ /** @internal */
12
15
  export interface ProcessTurnStartFromSessionRoot {
13
- /** Start with no persisted Pi entry in context. The kickoff entry has parentId null. */
16
+ /** Start with no persisted Pi entry in context. The kickoff entry has parentId null. @internal */
14
17
  kind: "session_root";
15
18
  }
16
19
 
20
+ /** @internal */
17
21
  export interface ProcessTurnStartFromEntry {
22
+ /** @internal */
18
23
  kind: "entry";
24
+ /** @internal */
19
25
  entryId: string;
20
26
  }
21
27
 
28
+ /** @internal */
22
29
  export type ProcessTurnStartFallback =
23
30
  | ProcessTurnStartFromCurrentLeaf
24
31
  | ProcessTurnStartFromSessionRoot
25
32
  | ProcessTurnStartFromEntry;
26
33
 
34
+ /** @internal */
27
35
  export interface ProcessTurnStartFromSemanticRef {
36
+ /** @internal */
28
37
  kind: "semantic_ref";
38
+ /** @internal */
29
39
  ref: ProcessSemanticEntryRefKey;
40
+ /** @internal */
30
41
  fallback?: ProcessTurnStartSelection;
31
42
  }
32
43
 
44
+ /** @internal */
33
45
  export interface ProcessTurnStartFromProductRef {
46
+ /** @internal */
34
47
  kind: "product_ref";
48
+ /** @internal */
35
49
  productName: string;
50
+ /** @internal */
36
51
  fallback?: ProcessTurnStartSelection;
37
52
  }
38
53
 
54
+ /** @internal */
39
55
  export type ProcessTurnStartSelection =
40
56
  | ProcessTurnStartFallback
41
57
  | ProcessTurnStartFromSemanticRef
42
58
  | ProcessTurnStartFromProductRef;
43
59
 
60
+ /** @internal */
44
61
  export type ProcessTurnStartTarget =
45
- | { kind: "current_leaf" }
46
- | { kind: "entry"; entryId: string }
47
- | { kind: "root" };
48
-
62
+ | {
63
+ /** @internal */
64
+ kind: "current_leaf";
65
+ }
66
+ | {
67
+ /** @internal */
68
+ kind: "entry";
69
+ /** @internal */
70
+ entryId: string;
71
+ }
72
+ | {
73
+ /** @internal */
74
+ kind: "root";
75
+ };
76
+
77
+ /** @internal */
49
78
  export interface ProcessTurnStartResolution {
79
+ /** @internal */
50
80
  forkPiEntryId: string | null;
81
+ /** @internal */
51
82
  startTarget: ProcessTurnStartTarget;
52
83
  }
53
84
 
85
+ /** @internal */
54
86
  export function defaultProcessTurnStartSelection(
55
87
  branchType: ProcessTurnRecordPathType,
56
88
  ): ProcessTurnStartFallback {
@@ -63,13 +95,17 @@ export function defaultProcessTurnStartSelection(
63
95
  }
64
96
  }
65
97
 
98
+ /** @internal */
66
99
  export function resolveProcessTurnStartSelection(input: {
100
+ /** @internal */
67
101
  branchType: ProcessTurnRecordPathType;
102
+ /** @internal */
68
103
  startFrom?: ProcessTurnStartSelection;
69
104
  }): ProcessTurnStartSelection {
70
105
  return input.startFrom ?? defaultProcessTurnStartSelection(input.branchType);
71
106
  }
72
107
 
108
+ /** @internal */
73
109
  export function resolveExistingProcessEntryId(
74
110
  entryId: string | null,
75
111
  entryExists?: ((entryId: string) => boolean) | undefined,
@@ -80,11 +116,17 @@ export function resolveExistingProcessEntryId(
80
116
  return entryExists && !entryExists(entryId) ? null : entryId;
81
117
  }
82
118
 
119
+ /** @internal */
83
120
  export function resolveProcessSemanticRefEntryId(input: {
121
+ /** @internal */
84
122
  ref: keyof ProcessSemanticEntryRefs;
123
+ /** @internal */
85
124
  semanticEntryRefs?: ProcessSemanticEntryRefs | null;
125
+ /** @internal */
86
126
  currentLeafId: string | null;
127
+ /** @internal */
87
128
  rootEntryId: string | null;
129
+ /** @internal */
88
130
  entryExists?: (entryId: string) => boolean;
89
131
  }): string | null {
90
132
  const fromState = resolveExistingProcessEntryId(
@@ -103,9 +145,13 @@ export function resolveProcessSemanticRefEntryId(input: {
103
145
  return null;
104
146
  }
105
147
 
148
+ /** @internal */
106
149
  export function resolveProcessProductRefEntryId(input: {
150
+ /** @internal */
107
151
  productName: string;
152
+ /** @internal */
108
153
  productRefs?: ProcessProductRefs | null;
154
+ /** @internal */
109
155
  entryExists?: (entryId: string) => boolean;
110
156
  }): string | null {
111
157
  const productName = input.productName.trim();
@@ -118,13 +164,21 @@ export function resolveProcessProductRefEntryId(input: {
118
164
  );
119
165
  }
120
166
 
167
+ /** @internal */
121
168
  export function resolveProcessTurnStartTarget(input: {
169
+ /** @internal */
122
170
  branchType: ProcessTurnRecordPathType;
171
+ /** @internal */
123
172
  selection: ProcessTurnStartSelection;
173
+ /** @internal */
124
174
  currentLeafId: string | null;
175
+ /** @internal */
125
176
  rootEntryId: string | null;
177
+ /** @internal */
126
178
  semanticEntryRefs?: ProcessSemanticEntryRefs | null;
179
+ /** @internal */
127
180
  productRefs?: ProcessProductRefs | null;
181
+ /** @internal */
128
182
  entryExists?: (entryId: string) => boolean;
129
183
  }): ProcessTurnStartResolution {
130
184
  switch (input.selection.kind) {
@@ -1,16 +1,18 @@
1
1
  import * as v from "valibot";
2
2
 
3
- /** Parse non-array objects into a fresh record using Valibot's key handling. */
3
+ /** Parse non-array objects into a fresh record using Valibot's key handling. @internal */
4
4
  export const copiedUnknownRecordSchema = v.pipe(
5
5
  v.unknown(),
6
6
  v.check(isUnknownRecord, "Expected object"),
7
7
  v.record(v.string(), v.unknown()),
8
8
  );
9
9
 
10
+ /** @internal */
10
11
  export function isUnknownRecord(value: unknown): value is Record<string, unknown> {
11
12
  return typeof value === "object" && value !== null && !Array.isArray(value);
12
13
  }
13
14
 
15
+ /** @internal */
14
16
  export function asUnknownRecord(value: unknown): Record<string, unknown> | null {
15
17
  return isUnknownRecord(value) ? value : null;
16
18
  }