@leitwerk-dev/process-sdk 0.1.8 → 0.2.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 (171) hide show
  1. package/dist/{chunk-TRQJ5PRM.js → chunk-TA4KO53Q.js} +1 -5
  2. package/dist/chunk-TA4KO53Q.js.map +1 -0
  3. package/dist/{chunk-5RJZ2E7D.js → chunk-WFY2WWZE.js} +2 -6
  4. package/dist/{chunk-5RJZ2E7D.js.map → chunk-WFY2WWZE.js.map} +1 -1
  5. package/dist/core-capabilities.d.ts +76 -34
  6. package/dist/core-capabilities.d.ts.map +1 -1
  7. package/dist/define-process.d.ts +36 -55
  8. package/dist/define-process.d.ts.map +1 -1
  9. package/dist/{extension-api-CqPGRqc9.d.ts → extension-api-CcqZCYJx.d.ts} +160 -74
  10. package/dist/extension-api.d.ts +120 -5
  11. package/dist/extension-api.d.ts.map +1 -1
  12. package/dist/external-action-source.d.ts +7 -0
  13. package/dist/external-action-source.d.ts.map +1 -0
  14. package/dist/external-source-poll.d.ts +15 -0
  15. package/dist/external-source-poll.d.ts.map +1 -0
  16. package/dist/flow.d.ts +92 -110
  17. package/dist/flow.d.ts.map +1 -1
  18. package/dist/fs-utils.d.ts +2 -0
  19. package/dist/fs-utils.d.ts.map +1 -1
  20. package/dist/git-binary.js +25 -33
  21. package/dist/git-binary.js.map +1 -1
  22. package/dist/index.d.ts +21 -9
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4694 -29
  25. package/dist/index.js.map +1 -1
  26. package/dist/integration-http.d.ts +21 -0
  27. package/dist/integration-http.d.ts.map +1 -0
  28. package/dist/json-data.d.ts +3 -0
  29. package/dist/json-data.d.ts.map +1 -0
  30. package/dist/leaf-outcome-renderer.js +74 -64
  31. package/dist/leaf-outcome-renderer.js.map +1 -1
  32. package/dist/leaf-outcomes.d.ts.map +1 -1
  33. package/dist/model-provider.d.ts.map +1 -1
  34. package/dist/pi-config.d.ts +1 -5
  35. package/dist/pi-config.d.ts.map +1 -1
  36. package/dist/pi-config.js +20 -180
  37. package/dist/pi-config.js.map +1 -1
  38. package/dist/process-flow-view.d.ts.map +1 -1
  39. package/dist/process-graph.d.ts +1 -2
  40. package/dist/process-graph.d.ts.map +1 -1
  41. package/dist/process-watcher-source.d.ts +3 -1
  42. package/dist/process-watcher-source.d.ts.map +1 -1
  43. package/dist/project-binding.d.ts +9 -0
  44. package/dist/project-binding.d.ts.map +1 -0
  45. package/dist/registry-utils.d.ts.map +1 -1
  46. package/dist/repository-feedback.d.ts +29 -0
  47. package/dist/repository-feedback.d.ts.map +1 -0
  48. package/dist/repository-git-env.d.ts +2 -0
  49. package/dist/repository-git-env.d.ts.map +1 -1
  50. package/dist/repository-http.d.ts +19 -0
  51. package/dist/repository-http.d.ts.map +1 -0
  52. package/dist/repository-https.d.ts +3 -0
  53. package/dist/repository-https.d.ts.map +1 -0
  54. package/dist/repository-issue-watcher.d.ts +31 -0
  55. package/dist/repository-issue-watcher.d.ts.map +1 -0
  56. package/dist/repository-source-config.d.ts +32 -0
  57. package/dist/repository-source-config.d.ts.map +1 -0
  58. package/dist/repository-types.d.ts +36 -0
  59. package/dist/repository-types.d.ts.map +1 -0
  60. package/dist/review-flow.js +12 -43
  61. package/dist/review-flow.js.map +1 -1
  62. package/dist/runtime-internals.js +18 -2
  63. package/dist/runtime-internals.js.map +1 -1
  64. package/dist/state-helpers.d.ts +3 -2
  65. package/dist/state-helpers.d.ts.map +1 -1
  66. package/dist/subprocess-env.d.ts +1 -0
  67. package/dist/subprocess-env.d.ts.map +1 -1
  68. package/dist/tool-arguments.d.ts +7 -0
  69. package/dist/tool-arguments.d.ts.map +1 -0
  70. package/dist/turn-semantics.d.ts +5 -6
  71. package/dist/turn-semantics.d.ts.map +1 -1
  72. package/dist/types.d.ts +5 -15
  73. package/dist/types.d.ts.map +1 -1
  74. package/package.json +6 -5
  75. package/src/core-capabilities.ts +90 -37
  76. package/src/define-process.ts +231 -277
  77. package/src/extension-api.ts +148 -4
  78. package/src/external-action-source.ts +12 -0
  79. package/src/external-source-poll.ts +49 -0
  80. package/src/flow.ts +427 -646
  81. package/src/fs-utils.ts +17 -2
  82. package/src/index.ts +56 -13
  83. package/src/integration-http.ts +58 -0
  84. package/src/json-data.ts +25 -0
  85. package/src/leaf-outcomes.ts +1 -9
  86. package/src/model-provider.ts +10 -23
  87. package/src/pi-config.ts +1 -6
  88. package/src/process-flow-view.ts +32 -88
  89. package/src/process-graph.ts +25 -54
  90. package/src/process-watcher-source.ts +13 -8
  91. package/src/project-binding.ts +36 -0
  92. package/src/registry-utils.ts +1 -5
  93. package/src/repository-feedback.ts +59 -0
  94. package/src/repository-git-env.ts +34 -0
  95. package/src/repository-http.ts +71 -0
  96. package/src/repository-https.ts +22 -0
  97. package/src/repository-issue-watcher.ts +92 -0
  98. package/src/repository-source-config.ts +60 -0
  99. package/src/repository-types.ts +25 -0
  100. package/src/state-helpers.ts +8 -9
  101. package/src/subprocess-env.ts +6 -0
  102. package/src/tool-arguments.ts +37 -0
  103. package/src/turn-semantics.ts +31 -75
  104. package/src/types.ts +5 -15
  105. package/dist/browser-ui-extension.js +0 -2
  106. package/dist/browser-ui-extension.js.map +0 -1
  107. package/dist/capabilities.js +0 -7
  108. package/dist/capabilities.js.map +0 -1
  109. package/dist/chunk-TRQJ5PRM.js.map +0 -1
  110. package/dist/codecs.js +0 -9
  111. package/dist/codecs.js.map +0 -1
  112. package/dist/commit-message.js +0 -3
  113. package/dist/commit-message.js.map +0 -1
  114. package/dist/core-capabilities.js +0 -6
  115. package/dist/core-capabilities.js.map +0 -1
  116. package/dist/define-process.js +0 -1040
  117. package/dist/define-process.js.map +0 -1
  118. package/dist/event-bus.js +0 -31
  119. package/dist/event-bus.js.map +0 -1
  120. package/dist/extension-api.js +0 -5
  121. package/dist/extension-api.js.map +0 -1
  122. package/dist/flow.js +0 -1565
  123. package/dist/flow.js.map +0 -1
  124. package/dist/form-contract.js +0 -2
  125. package/dist/form-contract.js.map +0 -1
  126. package/dist/fs-utils.js +0 -23
  127. package/dist/fs-utils.js.map +0 -1
  128. package/dist/graph-fragments.js +0 -57
  129. package/dist/graph-fragments.js.map +0 -1
  130. package/dist/host-capabilities.js +0 -42
  131. package/dist/host-capabilities.js.map +0 -1
  132. package/dist/launcher-contract.js +0 -2
  133. package/dist/launcher-contract.js.map +0 -1
  134. package/dist/leaf-outcomes.js +0 -52
  135. package/dist/leaf-outcomes.js.map +0 -1
  136. package/dist/model-provider.js +0 -171
  137. package/dist/model-provider.js.map +0 -1
  138. package/dist/process-definition-internals.js +0 -25
  139. package/dist/process-definition-internals.js.map +0 -1
  140. package/dist/process-flow-view.js +0 -418
  141. package/dist/process-flow-view.js.map +0 -1
  142. package/dist/process-graph.js +0 -213
  143. package/dist/process-graph.js.map +0 -1
  144. package/dist/process-launcher-builder.js +0 -43
  145. package/dist/process-launcher-builder.js.map +0 -1
  146. package/dist/process-watcher-builder.js +0 -40
  147. package/dist/process-watcher-builder.js.map +0 -1
  148. package/dist/process-watcher-source.js +0 -45
  149. package/dist/process-watcher-source.js.map +0 -1
  150. package/dist/registry-utils.js +0 -18
  151. package/dist/registry-utils.js.map +0 -1
  152. package/dist/repository-git-env.js +0 -26
  153. package/dist/repository-git-env.js.map +0 -1
  154. package/dist/server-events.js +0 -2
  155. package/dist/server-events.js.map +0 -1
  156. package/dist/server-process-builder.js +0 -52
  157. package/dist/server-process-builder.js.map +0 -1
  158. package/dist/state-helpers.js +0 -20
  159. package/dist/state-helpers.js.map +0 -1
  160. package/dist/subprocess-env.js +0 -34
  161. package/dist/subprocess-env.js.map +0 -1
  162. package/dist/tool-renderers.js +0 -63
  163. package/dist/tool-renderers.js.map +0 -1
  164. package/dist/turn-semantics.js +0 -365
  165. package/dist/turn-semantics.js.map +0 -1
  166. package/dist/types.js +0 -23
  167. package/dist/types.js.map +0 -1
  168. package/dist/ui-process-builder.js +0 -30
  169. package/dist/ui-process-builder.js.map +0 -1
  170. package/dist/worker-process-builder.js +0 -22
  171. package/dist/worker-process-builder.js.map +0 -1
package/src/fs-utils.ts CHANGED
@@ -18,11 +18,26 @@ export async function atomicWriteUtf8(filePath: string, content: string): Promis
18
18
  }
19
19
  }
20
20
 
21
- export function isEnoent(error: unknown): boolean {
21
+ // The parent itself is not inside: callers require a strict descendant.
22
+ export function isPathInside(parent: string, child: string): boolean {
23
+ const relative = path.relative(parent, child);
24
+ return (
25
+ relative !== "" &&
26
+ relative !== ".." &&
27
+ !relative.startsWith(`..${path.sep}`) &&
28
+ !path.isAbsolute(relative)
29
+ );
30
+ }
31
+
32
+ export function hasErrorCode(error: unknown, code: string): boolean {
22
33
  return (
23
34
  typeof error === "object" &&
24
35
  error !== null &&
25
36
  "code" in error &&
26
- (error as { code?: unknown }).code === "ENOENT"
37
+ (error as { code?: unknown }).code === code
27
38
  );
28
39
  }
40
+
41
+ export function isEnoent(error: unknown): boolean {
42
+ return hasErrorCode(error, "ENOENT");
43
+ }
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ export {
31
31
  type DeferredProcessActivationSnapshot,
32
32
  type DeferredProcessActivationSnapshotQuery,
33
33
  type DeferredProcessActivationSnapshotResult,
34
+ type ExternalObservationInput,
34
35
  type ExternalSourceArmingLike,
35
36
  type ExternalSourceFireInput,
36
37
  type ExternalSourceServiceLike,
@@ -44,7 +45,11 @@ export {
44
45
  type LaunchPlanPreparationIssue,
45
46
  type LaunchPlanPreparationIssueCode,
46
47
  type LaunchPlanPreparationResultLike,
48
+ type LaunchRunServiceLike,
47
49
  type ModelProfileOptionSummaryLike,
50
+ type PollingHandleLike,
51
+ type PollingServiceLike,
52
+ type PollResultLike,
48
53
  type PreparedDeferredProcessActivation,
49
54
  type ProcessActionExecutionOrigin,
50
55
  type ProcessActionExecutionSource,
@@ -55,10 +60,6 @@ export {
55
60
  type ProcessEngineLike,
56
61
  type ProcessEngineResultLike,
57
62
  type ProcessEventRepoLike,
58
- type ProcessLaunchConfigExecutionInput,
59
- type ProcessLaunchExecutionResultLike,
60
- type ProcessLaunchExecutorLike,
61
- type ProcessLaunchFailureStageLike,
62
63
  type ProcessLaunchPlanServiceLike,
63
64
  type ProcessModelSelectionPreviewFailureCode,
64
65
  type ProcessModelSelectionPreviewResultLike,
@@ -67,8 +68,11 @@ export {
67
68
  type ProcessQuestionServiceLike,
68
69
  type ProcessRepoLike,
69
70
  type ProcessWatcherServiceLike,
71
+ type ProgrammaticLaunchRequestLike,
72
+ type ProgrammaticLaunchResultLike,
70
73
  type QueuedProcessInputLike,
71
74
  type RegisteredProcessWatcherLike,
75
+ type WatcherLaunchResultLike,
72
76
  type WorkerSupervisorLike,
73
77
  } from "./core-capabilities.js";
74
78
  export {
@@ -87,6 +91,7 @@ export {
87
91
  humanTurn,
88
92
  type LlmModelPurpose,
89
93
  type LlmTurnDefinition,
94
+ type LlmTurnPreparationContext,
90
95
  llmTurn,
91
96
  type OutcomeRouteOptions,
92
97
  type OutcomeRouteSpec,
@@ -101,6 +106,8 @@ export {
101
106
  type ProcessHumanTurnActionSpec,
102
107
  type ProcessHumanTurnExternalActionSpec,
103
108
  type ProcessLifecycleEffects,
109
+ type ProcessOutcomeBranchSelector,
110
+ type ProcessOutcomeBranchSpec,
104
111
  type ProcessOutcomeEffect,
105
112
  type ProcessOutcomeExecution,
106
113
  type ProcessPatchEffect,
@@ -110,10 +117,6 @@ export {
110
117
  type ProcessTurnEndSpec,
111
118
  resolveHumanTurnView,
112
119
  routeTurnOutcomes,
113
- type ServerAutomaticTurnDefinition,
114
- type ServerAutomaticTurnRestartBehavior,
115
- type ServerAutomaticTurnRunResult,
116
- serverAutomaticTurn,
117
120
  type TurnDefinition,
118
121
  type TurnDefinitionRecord,
119
122
  } from "./define-process.js";
@@ -124,18 +127,22 @@ export type {
124
127
  ExtensionLifecycleHook,
125
128
  ExtensionProcessDefinition,
126
129
  ExternalActionSource,
130
+ ExternalEventDescription,
127
131
  ExternalSourceEffect,
128
132
  ExternalSourceEffectContext,
129
133
  ExternalSourceInputMode,
130
134
  ExternalSourceResolveContext,
131
135
  FormDefinition,
132
136
  FormFieldDefinition,
137
+ GitHttpsCredentialMaterial,
133
138
  GitSshCredentialMaterial,
134
139
  IntegrationToolDefinition,
135
140
  IntegrationToolExecutionContext,
136
141
  LauncherContext,
137
142
  LauncherModelProfileSummary,
138
143
  LauncherVisibility,
144
+ LaunchPreparationCheck,
145
+ LaunchPreparationContext,
139
146
  LeafOutcomeCaptureContext,
140
147
  LeafOutcomeCaptureResult,
141
148
  LeitwerkExtensionManifest,
@@ -172,6 +179,13 @@ export type {
172
179
  ServerTransitionEffect,
173
180
  ServerTransitionRequest,
174
181
  ServerTransitionRuntime,
182
+ TicketCreationCapability,
183
+ TicketCreationDestinationContext,
184
+ TicketCreationDestinationList,
185
+ TicketCreationDestinationProvider,
186
+ TicketCreationDestinationSnapshot,
187
+ TicketCreationDestinationSummary,
188
+ TicketCreationReceipt,
175
189
  UiLauncherConfigResolution,
176
190
  UiLauncherDefinition,
177
191
  UiLauncherResolutionResult,
@@ -184,7 +198,9 @@ export type {
184
198
  WorkerRunHandle,
185
199
  WorkerTurnHandler,
186
200
  } from "./extension-api.js";
187
- export { findUiLauncherById } from "./extension-api.js";
201
+ export { findUiLauncherById, SafeLaunchPreparationError } from "./extension-api.js";
202
+ export { defineExternalActionSource } from "./external-action-source.js";
203
+ export { createExternalSourcePollReporter } from "./external-source-poll.js";
188
204
  export {
189
205
  AutomaticFlowBuilder,
190
206
  AutomaticOutcomeBuilder,
@@ -202,12 +218,12 @@ export {
202
218
  FlowFragmentBuilder,
203
219
  type FlowHumanTurn,
204
220
  type FlowLlmOutcomeEffectContext,
221
+ type FlowLlmPreparationContext,
205
222
  type FlowLlmTurn,
206
223
  FlowProcessBuilder,
207
224
  type FlowPromptContext,
208
225
  type FlowRepoContext,
209
226
  type FlowRepoLookup,
210
- type FlowServerAutomaticTurn,
211
227
  type FlowTurn,
212
228
  flow,
213
229
  HumanActionBuilder,
@@ -219,9 +235,8 @@ export {
219
235
  type PlanFieldOptions,
220
236
  PlanResultBuilder,
221
237
  PublishedResultBuilder,
222
- ServerAutomaticFlowBuilder,
223
238
  } from "./flow.js";
224
- export { atomicWriteUtf8, isEnoent } from "./fs-utils.js";
239
+ export { atomicWriteUtf8, hasErrorCode, isEnoent, isPathInside } from "./fs-utils.js";
225
240
  export {
226
241
  type AcceptedReviewHandoffActionSpec,
227
242
  acceptedReviewHandoffAction,
@@ -235,6 +250,8 @@ export {
235
250
  createCapabilityAccessor,
236
251
  type ProvidedCapability,
237
252
  } from "./host-capabilities.js";
253
+ export { IntegrationHttpClient, IntegrationHttpError } from "./integration-http.js";
254
+ export { parseJsonData } from "./json-data.js";
238
255
  export type {
239
256
  LauncherCardMetadata,
240
257
  LauncherFieldDefinition,
@@ -341,11 +358,36 @@ export {
341
358
  parseProcessWatcherLaunchModelConfig,
342
359
  } from "./process-watcher-source.js";
343
360
  export {
361
+ type RepositoryProjectBinding,
362
+ resolveRepositoryProjectBinding,
363
+ } from "./project-binding.js";
364
+ export {
365
+ normalizeRepositoryFeedback,
366
+ type RepositoryFeedbackItem,
367
+ repositoryFeedbackBatch,
368
+ } from "./repository-feedback.js";
369
+ export {
370
+ clearRepositoryGitHttpsHelpers,
344
371
  clearRepositoryGitSshWrappers,
345
372
  repositoryGitArgs,
346
373
  repositoryGitSubprocessEnv,
374
+ setRepositoryGitHttpsHelper,
347
375
  setRepositoryGitSshWrapper,
348
376
  } from "./repository-git-env.js";
377
+ export { RepositoryHttpClient } from "./repository-http.js";
378
+ export { repositoryHttpsUrl } from "./repository-https.js";
379
+ export {
380
+ matchesRepository,
381
+ parseRepositoryIssueWatcherConfig,
382
+ presentRepositoryIssueWatcherConfig,
383
+ type RepositoryIssueWatcherConfig,
384
+ } from "./repository-issue-watcher.js";
385
+ export {
386
+ parseRepositoryFeedbackConfig,
387
+ parseRepositoryIssueCancelledConfig,
388
+ parseRepositoryPullRequestConfig,
389
+ } from "./repository-source-config.js";
390
+ export type { RepositoryIssue, RepositoryPullRequest } from "./repository-types.js";
349
391
  export {
350
392
  buildPlanSavedEventPayload,
351
393
  buildReviewCompletedEventPayload,
@@ -377,12 +419,14 @@ export {
377
419
  createEmptyStructuralProcessState,
378
420
  parseStructuralProcessState,
379
421
  type StructuralProcessState,
422
+ structuralStateCodec,
380
423
  } from "./state-helpers.js";
381
424
  export {
382
425
  type SubprocessEnvInput,
383
426
  sanitizeWorkerSubprocessEnv,
384
427
  WORKER_SUBPROCESS_SENSITIVE_ENV_KEYS,
385
428
  } from "./subprocess-env.js";
429
+ export { numberArg, objectArg, projectParameters, stringArg } from "./tool-arguments.js";
386
430
  export type {
387
431
  ToolCallRendererDefinition,
388
432
  ToolCallRendererFieldDefinition,
@@ -407,7 +451,6 @@ export {
407
451
  isExternalTurnDefinition,
408
452
  isHumanTurnDefinition,
409
453
  isLlmTurnDefinition,
410
- isServerAutomaticTurnDefinition,
411
454
  resolveLlmTurnRestorePrimaryLeafAfterTurn,
412
455
  resolveLlmTurnStartSelection,
413
456
  validateAutomaticTurnDefinition,
@@ -0,0 +1,58 @@
1
+ /** An HTTP failure without provider response bodies or credentials. */
2
+ export class IntegrationHttpError extends Error {
3
+ constructor(
4
+ readonly status: number,
5
+ message: string,
6
+ ) {
7
+ super(message);
8
+ }
9
+ }
10
+
11
+ /** Shared transport; extensions own endpoint paths, credentials, and response types. */
12
+ export class IntegrationHttpClient {
13
+ constructor(
14
+ private readonly provider: string,
15
+ private readonly baseUrl: string,
16
+ private readonly headers: Record<string, string>,
17
+ private readonly pagination = { key: "per_page", size: 100 },
18
+ ) {}
19
+
20
+ protected async response(path: string, init: RequestInit = {}): Promise<Response> {
21
+ const response = await fetch(`${this.baseUrl}${path}`, {
22
+ ...init,
23
+ headers: {
24
+ ...this.headers,
25
+ ...(init.body ? { "Content-Type": "application/json" } : {}),
26
+ ...init.headers,
27
+ },
28
+ });
29
+ if (!response.ok)
30
+ throw new IntegrationHttpError(
31
+ response.status,
32
+ `${this.provider} ${init.method ?? "GET"} ${path} failed with ${response.status}`,
33
+ );
34
+ return response;
35
+ }
36
+
37
+ protected async request<T>(path: string, init: RequestInit = {}): Promise<T> {
38
+ const response = await this.response(path, init);
39
+ return response.status === 204 ? (undefined as T) : response.json();
40
+ }
41
+
42
+ protected writeJson<T>(path: string, method: string, body: unknown, signal?: AbortSignal) {
43
+ return this.request<T>(path, { method, body: JSON.stringify(body), signal });
44
+ }
45
+
46
+ protected async pages<T>(path: string, signal?: AbortSignal): Promise<T[]> {
47
+ const items: T[] = [];
48
+ const { key, size } = this.pagination;
49
+ for (let page = 1; ; page++) {
50
+ const separator = path.includes("?") ? "&" : "?";
51
+ const batch = await this.request<T[]>(`${path}${separator}${key}=${size}&page=${page}`, {
52
+ signal,
53
+ });
54
+ items.push(...batch);
55
+ if (batch.length < size) return items;
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,25 @@
1
+ /** Validate and detach JSON data without silently dropping unsupported values. */
2
+ export function parseJsonData(
3
+ value: unknown,
4
+ message = "Value must be JSON-serializable",
5
+ ): unknown {
6
+ const ancestors = new Set<object>();
7
+ function parse(value: unknown): unknown {
8
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
9
+ if (typeof value === "number" && Number.isFinite(value)) return value;
10
+ if (!value || typeof value !== "object" || ancestors.has(value)) throw new Error(message);
11
+ ancestors.add(value);
12
+ try {
13
+ if (Array.isArray(value)) return Array.from(value, parse);
14
+ if (
15
+ ![Object.prototype, null].includes(Object.getPrototypeOf(value)) ||
16
+ Object.getOwnPropertySymbols(value).length
17
+ )
18
+ throw new Error(message);
19
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, parse(item)]));
20
+ } finally {
21
+ ancestors.delete(value);
22
+ }
23
+ }
24
+ return parse(value);
25
+ }
@@ -1,15 +1,7 @@
1
+ import { copiedUnknownRecordSchema as unknownRecordSchema } from "@leitwerk-dev/domain";
1
2
  import * as v from "valibot";
2
3
  import type { LeafOutcomeCaptureResult, ProcessLeafOutcomeDefinition } from "./extension-api.js";
3
4
 
4
- const unknownRecordSchema = v.pipe(
5
- v.unknown(),
6
- v.check(
7
- (value) => typeof value === "object" && value !== null && !Array.isArray(value),
8
- "Expected object",
9
- ),
10
- v.record(v.string(), v.unknown()),
11
- );
12
-
13
5
  function isNonEmptyString(value: unknown): value is string {
14
6
  return typeof value === "string" && value.trim() !== "";
15
7
  }
@@ -76,17 +76,11 @@ export function defineProviderOptions<TConfig = unknown>(
76
76
  if (fieldId.trim() === "") {
77
77
  throw new Error("Provider option field ids must not be empty");
78
78
  }
79
- if (
80
- field.minLength !== undefined &&
81
- (!Number.isInteger(field.minLength) || field.minLength < 0)
82
- ) {
83
- throw new Error(`Provider option '${fieldId}' minLength must be a non-negative integer`);
84
- }
85
- if (
86
- field.maxLength !== undefined &&
87
- (!Number.isInteger(field.maxLength) || field.maxLength < 0)
88
- ) {
89
- throw new Error(`Provider option '${fieldId}' maxLength must be a non-negative integer`);
79
+ for (const bound of ["minLength", "maxLength"] as const) {
80
+ const value = field[bound];
81
+ if (value !== undefined && (!Number.isInteger(value) || value < 0)) {
82
+ throw new Error(`Provider option '${fieldId}' ${bound} must be a non-negative integer`);
83
+ }
90
84
  }
91
85
  if (
92
86
  field.minLength !== undefined &&
@@ -446,16 +440,9 @@ export function credentialBasedModelStatuses(
446
440
  credentialStatus: ProviderCredentialStatus,
447
441
  unavailableReason: string,
448
442
  ): readonly ProviderModelStatus[] {
449
- const seen = new Set<string>();
450
- const statuses: ProviderModelStatus[] = [];
451
- for (const configured of configuredModels) {
452
- if (seen.has(configured.modelId)) continue;
453
- seen.add(configured.modelId);
454
- statuses.push({
455
- modelId: configured.modelId,
456
- availability: credentialStatus.available ? "available" : "unavailable",
457
- ...(credentialStatus.available ? {} : { safeReason: unavailableReason }),
458
- });
459
- }
460
- return statuses;
443
+ return [...new Set(configuredModels.map((configured) => configured.modelId))].map((modelId) => ({
444
+ modelId,
445
+ availability: credentialStatus.available ? "available" : "unavailable",
446
+ ...(credentialStatus.available ? {} : { safeReason: unavailableReason }),
447
+ }));
461
448
  }
package/src/pi-config.ts CHANGED
@@ -233,12 +233,7 @@ export function resolveProcessPiConfig(input: {
233
233
  };
234
234
  }
235
235
 
236
- export function resolveTurnActiveToolNames(input: {
237
- turnId: string;
238
- turnDef: LlmTurnDefinition<string, unknown, unknown>;
239
- }): string[] {
240
- return resolveTurnAvailableToolNames(input);
241
- }
236
+ export { resolveTurnAvailableToolNames as resolveTurnActiveToolNames };
242
237
 
243
238
  // Mirror Pi's PI_CODING_AGENT_DIR expansion semantics from
244
239
  // pi-mono/packages/coding-agent/src/config.ts.
@@ -7,17 +7,10 @@ import {
7
7
  type ProcessTurnTerminalLifecycleStatus,
8
8
  type ProcessTurnTransition,
9
9
  type TurnId,
10
+ trimToNull,
10
11
  } from "@leitwerk-dev/domain";
11
12
  import type { ProcessGraphTurnView, ProcessGraphView } from "./process-graph.js";
12
13
 
13
- function trimToNull(value: string | undefined | null): string | null {
14
- if (typeof value !== "string") {
15
- return null;
16
- }
17
- const trimmed = value.trim();
18
- return trimmed === "" ? null : trimmed;
19
- }
20
-
21
14
  /**
22
15
  * Human/operator turns are routing decisions: they pick which path the process
23
16
  * takes but perform no work themselves. They are collapsed out of the flow graph
@@ -52,17 +45,13 @@ function computeRoutingAnchors(
52
45
  graph: ProcessGraphView,
53
46
  routingIds: ReadonlySet<TurnId>,
54
47
  ): Map<TurnId, TurnId> {
55
- const declarationIndex = new Map<TurnId, number>();
56
- [...graph.turns.keys()].forEach((turnId, index) => {
57
- declarationIndex.set(turnId, index);
58
- });
59
-
60
- const happyIndex = new Map<TurnId, number>();
61
- (graph.happyPath ?? []).forEach((turnId, index) => {
62
- if (!happyIndex.has(turnId)) {
63
- happyIndex.set(turnId, index);
64
- }
65
- });
48
+ // Happy-path turns come first, then the remaining turns in declaration order.
49
+ const preferenceIndex = new Map(
50
+ [...new Set([...(graph.happyPath ?? []), ...graph.turns.keys()])].map((turnId, index) => [
51
+ turnId,
52
+ index,
53
+ ]),
54
+ );
66
55
 
67
56
  const workPredecessors = new Map<TurnId, TurnId[]>();
68
57
  const routingPredecessors = new Map<TurnId, TurnId[]>();
@@ -84,22 +73,14 @@ function computeRoutingAnchors(
84
73
  }
85
74
  }
86
75
 
87
- const preferenceKey = (turnId: TurnId): [number, number] => [
88
- happyIndex.get(turnId) ?? Number.POSITIVE_INFINITY,
89
- declarationIndex.get(turnId) ?? Number.POSITIVE_INFINITY,
90
- ];
91
76
  const pickPreferred = (candidates: readonly TurnId[]): TurnId | undefined => {
92
77
  let best: TurnId | undefined;
93
- let bestKey: [number, number] | undefined;
78
+ let bestIndex = Number.POSITIVE_INFINITY;
94
79
  for (const candidate of candidates) {
95
- const key = preferenceKey(candidate);
96
- if (
97
- bestKey === undefined ||
98
- key[0] < bestKey[0] ||
99
- (key[0] === bestKey[0] && key[1] < bestKey[1])
100
- ) {
80
+ const index = preferenceIndex.get(candidate) ?? Number.POSITIVE_INFINITY;
81
+ if (best === undefined || index < bestIndex) {
101
82
  best = candidate;
102
- bestKey = key;
83
+ bestIndex = index;
103
84
  }
104
85
  }
105
86
  return best;
@@ -168,18 +149,16 @@ function redirectTransition(
168
149
  }
169
150
 
170
151
  function dedupeTransitions(transitions: readonly ProcessTurnTransition[]): ProcessTurnTransition[] {
171
- const seen = new Set<string>();
172
- const result: ProcessTurnTransition[] = [];
152
+ const result = new Map<string, ProcessTurnTransition>();
173
153
  for (const transition of transitions) {
174
154
  const label = trimToNull(transition.outcome) ?? trimToNull(transition.trigger);
175
155
  const key = `${transition.nextTurnId ?? ""}|${transition.lifecycleStatus ?? ""}|${label ?? ""}`;
176
- if (seen.has(key)) {
156
+ if (result.has(key)) {
177
157
  continue;
178
158
  }
179
- seen.add(key);
180
- result.push(transition);
159
+ result.set(key, transition);
181
160
  }
182
- return result;
161
+ return [...result.values()];
183
162
  }
184
163
 
185
164
  /**
@@ -197,10 +176,7 @@ export function collapseRoutingTurns(graph: ProcessGraphView): ProcessGraphView
197
176
  routingIds.add(turnId);
198
177
  }
199
178
  }
200
- if (routingIds.size === 0) {
201
- return graph;
202
- }
203
- if (routingIds.size === graph.turns.size) {
179
+ if (routingIds.size === 0 || routingIds.size === graph.turns.size) {
204
180
  return graph;
205
181
  }
206
182
 
@@ -264,29 +240,18 @@ export function collapseRoutingTurns(graph: ProcessGraphView): ProcessGraphView
264
240
  * completing path exists.
265
241
  */
266
242
  function deriveSpine(graph: ProcessGraphView, entry: TurnId): TurnId[] {
267
- const turnsWithCompletedTerminal = new Set<TurnId>();
268
- for (const [turnId, turn] of graph.turns) {
269
- if (turn.transitions.some((transition) => transition.lifecycleStatus === "completed")) {
270
- turnsWithCompletedTerminal.add(turnId);
271
- }
272
- }
273
- if (turnsWithCompletedTerminal.size === 0) {
274
- return [entry];
275
- }
276
-
277
243
  const predecessor = new Map<TurnId, TurnId | null>([[entry, null]]);
278
244
  const queue: TurnId[] = [entry];
279
245
  let goal: TurnId | null = null;
280
- while (queue.length > 0) {
281
- const current = queue.shift() as TurnId;
282
- if (turnsWithCompletedTerminal.has(current)) {
283
- goal = current;
284
- break;
285
- }
246
+ for (const current of queue) {
286
247
  const turn = graph.turns.get(current);
287
248
  if (!turn) {
288
249
  continue;
289
250
  }
251
+ if (turn.transitions.some((transition) => transition.lifecycleStatus === "completed")) {
252
+ goal = current;
253
+ break;
254
+ }
290
255
  for (const transition of turn.transitions) {
291
256
  const next = transition.nextTurnId;
292
257
  if (next === undefined || predecessor.has(next) || !graph.turns.has(next)) {
@@ -360,24 +325,6 @@ function transitionLabel(transition: { outcome?: string; trigger?: string }): st
360
325
  return raw === null ? null : humanizeProcessLabel(raw);
361
326
  }
362
327
 
363
- function buildNode(input: {
364
- turnId: TurnId;
365
- turn: ProcessGraphTurnView;
366
- spineIndex: number | null;
367
- anchorTurnId: TurnId | null;
368
- isEntry: boolean;
369
- }): ProcessFlowNode {
370
- return {
371
- turnId: input.turnId,
372
- description: trimToNull(input.turn.description) ?? input.turnId,
373
- turnType: input.turn.turnType,
374
- role: input.spineIndex === null ? "branch" : "spine",
375
- spineIndex: input.spineIndex,
376
- anchorTurnId: input.spineIndex === null ? input.anchorTurnId : null,
377
- isEntry: input.isEntry,
378
- };
379
- }
380
-
381
328
  /**
382
329
  * Projects a process graph into a spine-first flow view for operator-facing
383
330
  * diagrams. The spine is the declared happy path (or a derived best-effort path
@@ -411,15 +358,15 @@ export function buildProcessFlowView(rawGraph: ProcessGraphView): ProcessFlowVie
411
358
  const nodes: ProcessFlowNode[] = [];
412
359
  for (const [turnId, turn] of graph.turns) {
413
360
  const spineIndex = spineIndexByTurn.get(turnId) ?? null;
414
- nodes.push(
415
- buildNode({
416
- turnId,
417
- turn,
418
- spineIndex,
419
- anchorTurnId: anchorByTurn.get(turnId) ?? null,
420
- isEntry: entrySet.has(turnId),
421
- }),
422
- );
361
+ nodes.push({
362
+ turnId,
363
+ description: trimToNull(turn.description) ?? turnId,
364
+ turnType: turn.turnType,
365
+ role: spineIndex === null ? "branch" : "spine",
366
+ spineIndex,
367
+ anchorTurnId: spineIndex === null ? (anchorByTurn.get(turnId) ?? null) : null,
368
+ isEntry: entrySet.has(turnId),
369
+ });
423
370
  }
424
371
 
425
372
  const edges: ProcessFlowEdge[] = [];
@@ -439,12 +386,9 @@ export function buildProcessFlowView(rawGraph: ProcessGraphView): ProcessFlowVie
439
386
  continue;
440
387
  }
441
388
  const next = transition.nextTurnId;
442
- if (next === undefined) {
443
- continue;
444
- }
445
389
  // Skip self-loops: an edge that leaves and re-enters the same box adds
446
390
  // clutter without conveying additional flow.
447
- if (next === turnId) {
391
+ if (next === undefined || next === turnId) {
448
392
  continue;
449
393
  }
450
394
  const fromIndex = spineIndexByTurn.get(turnId);