@leitwerk-dev/process-sdk 0.1.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.
- package/dist/LICENSE +13 -0
- package/dist/browser-ui-extension.d.ts +27 -0
- package/dist/browser-ui-extension.d.ts.map +1 -0
- package/dist/browser-ui-extension.js +2 -0
- package/dist/browser-ui-extension.js.map +1 -0
- package/dist/capabilities.d.ts +9 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +7 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-5RJZ2E7D.js +58 -0
- package/dist/chunk-5RJZ2E7D.js.map +1 -0
- package/dist/chunk-ITPH65G6.js +197 -0
- package/dist/chunk-ITPH65G6.js.map +1 -0
- package/dist/chunk-LIIP7FMU.js +48 -0
- package/dist/chunk-LIIP7FMU.js.map +1 -0
- package/dist/codecs.d.ts +3 -0
- package/dist/codecs.d.ts.map +1 -0
- package/dist/codecs.js +9 -0
- package/dist/codecs.js.map +1 -0
- package/dist/commit-message.d.ts +7 -0
- package/dist/commit-message.d.ts.map +1 -0
- package/dist/commit-message.js +3 -0
- package/dist/commit-message.js.map +1 -0
- package/dist/core-capabilities.d.ts +393 -0
- package/dist/core-capabilities.d.ts.map +1 -0
- package/dist/core-capabilities.js +6 -0
- package/dist/core-capabilities.js.map +1 -0
- package/dist/define-process.d.ts +269 -0
- package/dist/define-process.d.ts.map +1 -0
- package/dist/define-process.js +1040 -0
- package/dist/define-process.js.map +1 -0
- package/dist/event-bus.d.ts +3 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +31 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/extension-api-CnlL69Tu.d.ts +1281 -0
- package/dist/extension-api.d.ts +425 -0
- package/dist/extension-api.d.ts.map +1 -0
- package/dist/extension-api.js +5 -0
- package/dist/extension-api.js.map +1 -0
- package/dist/flow.d.ts +456 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +1557 -0
- package/dist/flow.js.map +1 -0
- package/dist/form-contract.d.ts +2 -0
- package/dist/form-contract.d.ts.map +1 -0
- package/dist/form-contract.js +2 -0
- package/dist/form-contract.js.map +1 -0
- package/dist/fs-utils.d.ts +3 -0
- package/dist/fs-utils.d.ts.map +1 -0
- package/dist/fs-utils.js +23 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/git-binary.d.ts +11 -0
- package/dist/git-binary.d.ts.map +1 -0
- package/dist/git-binary.js +38 -0
- package/dist/git-binary.js.map +1 -0
- package/dist/graph-fragments.d.ts +23 -0
- package/dist/graph-fragments.d.ts.map +1 -0
- package/dist/graph-fragments.js +57 -0
- package/dist/graph-fragments.js.map +1 -0
- package/dist/host-capabilities.d.ts +12 -0
- package/dist/host-capabilities.d.ts.map +1 -0
- package/dist/host-capabilities.js +42 -0
- package/dist/host-capabilities.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher-contract.d.ts +2 -0
- package/dist/launcher-contract.d.ts.map +1 -0
- package/dist/launcher-contract.js +2 -0
- package/dist/launcher-contract.js.map +1 -0
- package/dist/leaf-outcome-renderer.d.ts +48 -0
- package/dist/leaf-outcome-renderer.d.ts.map +1 -0
- package/dist/leaf-outcome-renderer.js +69 -0
- package/dist/leaf-outcome-renderer.js.map +1 -0
- package/dist/leaf-outcomes.d.ts +5 -0
- package/dist/leaf-outcomes.d.ts.map +1 -0
- package/dist/leaf-outcomes.js +52 -0
- package/dist/leaf-outcomes.js.map +1 -0
- package/dist/model-provider.d.ts +210 -0
- package/dist/model-provider.d.ts.map +1 -0
- package/dist/model-provider.js +171 -0
- package/dist/model-provider.js.map +1 -0
- package/dist/pi-config.d.ts +59 -0
- package/dist/pi-config.d.ts.map +1 -0
- package/dist/pi-config.js +182 -0
- package/dist/pi-config.js.map +1 -0
- package/dist/process-definition-internals.d.ts +7 -0
- package/dist/process-definition-internals.d.ts.map +1 -0
- package/dist/process-definition-internals.js +25 -0
- package/dist/process-definition-internals.js.map +1 -0
- package/dist/process-flow-view.d.ts +20 -0
- package/dist/process-flow-view.d.ts.map +1 -0
- package/dist/process-flow-view.js +418 -0
- package/dist/process-flow-view.js.map +1 -0
- package/dist/process-graph.d.ts +45 -0
- package/dist/process-graph.d.ts.map +1 -0
- package/dist/process-graph.js +213 -0
- package/dist/process-graph.js.map +1 -0
- package/dist/process-launcher-builder.d.ts +9 -0
- package/dist/process-launcher-builder.d.ts.map +1 -0
- package/dist/process-launcher-builder.js +43 -0
- package/dist/process-launcher-builder.js.map +1 -0
- package/dist/process-watcher-builder.d.ts +10 -0
- package/dist/process-watcher-builder.d.ts.map +1 -0
- package/dist/process-watcher-builder.js +40 -0
- package/dist/process-watcher-builder.js.map +1 -0
- package/dist/registry-utils.d.ts +8 -0
- package/dist/registry-utils.d.ts.map +1 -0
- package/dist/registry-utils.js +18 -0
- package/dist/registry-utils.js.map +1 -0
- package/dist/repository-git-env.d.ts +8 -0
- package/dist/repository-git-env.d.ts.map +1 -0
- package/dist/repository-git-env.js +26 -0
- package/dist/repository-git-env.js.map +1 -0
- package/dist/review-flow.d.ts +10 -0
- package/dist/review-flow.d.ts.map +1 -0
- package/dist/review-flow.js +44 -0
- package/dist/review-flow.js.map +1 -0
- package/dist/runtime-internals.d.ts +3 -0
- package/dist/runtime-internals.d.ts.map +1 -0
- package/dist/runtime-internals.js +3 -0
- package/dist/runtime-internals.js.map +1 -0
- package/dist/server-events.d.ts +84 -0
- package/dist/server-events.d.ts.map +1 -0
- package/dist/server-events.js +2 -0
- package/dist/server-events.js.map +1 -0
- package/dist/server-process-builder.d.ts +11 -0
- package/dist/server-process-builder.d.ts.map +1 -0
- package/dist/server-process-builder.js +52 -0
- package/dist/server-process-builder.js.map +1 -0
- package/dist/state-helpers.d.ts +9 -0
- package/dist/state-helpers.d.ts.map +1 -0
- package/dist/state-helpers.js +20 -0
- package/dist/state-helpers.js.map +1 -0
- package/dist/subprocess-env.d.ts +12 -0
- package/dist/subprocess-env.d.ts.map +1 -0
- package/dist/subprocess-env.js +34 -0
- package/dist/subprocess-env.js.map +1 -0
- package/dist/tool-renderers.d.ts +10 -0
- package/dist/tool-renderers.d.ts.map +1 -0
- package/dist/tool-renderers.js +63 -0
- package/dist/tool-renderers.js.map +1 -0
- package/dist/turn-semantics.d.ts +22 -0
- package/dist/turn-semantics.d.ts.map +1 -0
- package/dist/turn-semantics.js +339 -0
- package/dist/turn-semantics.js.map +1 -0
- package/dist/types.d.ts +295 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/ui-process-builder.d.ts +9 -0
- package/dist/ui-process-builder.d.ts.map +1 -0
- package/dist/ui-process-builder.js +30 -0
- package/dist/ui-process-builder.js.map +1 -0
- package/dist/worker-process-builder.d.ts +10 -0
- package/dist/worker-process-builder.d.ts.map +1 -0
- package/dist/worker-process-builder.js +22 -0
- package/dist/worker-process-builder.js.map +1 -0
- package/package.json +72 -0
- package/src/browser-ui-extension.ts +32 -0
- package/src/capabilities.ts +16 -0
- package/src/codecs.ts +10 -0
- package/src/commit-message.ts +9 -0
- package/src/core-capabilities.ts +526 -0
- package/src/define-process.ts +1879 -0
- package/src/event-bus.ts +35 -0
- package/src/extension-api.ts +600 -0
- package/src/flow.ts +2268 -0
- package/src/form-contract.ts +11 -0
- package/src/fs-utils.ts +28 -0
- package/src/git-binary.ts +40 -0
- package/src/graph-fragments.ts +110 -0
- package/src/host-capabilities.ts +60 -0
- package/src/index.ts +468 -0
- package/src/launcher-contract.ts +8 -0
- package/src/leaf-outcome-renderer.ts +112 -0
- package/src/leaf-outcomes.ts +74 -0
- package/src/model-provider.ts +461 -0
- package/src/pi-config.ts +268 -0
- package/src/process-definition-internals.ts +46 -0
- package/src/process-flow-view.ts +479 -0
- package/src/process-graph.ts +309 -0
- package/src/process-launcher-builder.ts +59 -0
- package/src/process-watcher-builder.ts +72 -0
- package/src/registry-utils.ts +31 -0
- package/src/repository-git-env.ts +35 -0
- package/src/review-flow.ts +66 -0
- package/src/runtime-internals.ts +7 -0
- package/src/server-events.ts +105 -0
- package/src/server-process-builder.ts +90 -0
- package/src/state-helpers.ts +36 -0
- package/src/subprocess-env.ts +48 -0
- package/src/tool-renderers.ts +92 -0
- package/src/turn-semantics.ts +554 -0
- package/src/types.ts +391 -0
- package/src/ui-process-builder.ts +46 -0
- package/src/worker-process-builder.ts +33 -0
package/src/pi-config.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import type { ConfigSnapshot } from "@leitwerk-dev/protocol";
|
|
3
|
+
import Mustache from "mustache";
|
|
4
|
+
import type { LlmTurnDefinition } from "./define-process.js";
|
|
5
|
+
import {
|
|
6
|
+
PI_BUILT_IN_TOOL_NAMES,
|
|
7
|
+
type PiBuiltInToolName,
|
|
8
|
+
type ProcessPiConfig,
|
|
9
|
+
type ResolvedProcessPiConfig,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
type TemplateScalar = string | number | boolean;
|
|
13
|
+
type TemplateValue = TemplateScalar | TemplateContext | readonly TemplateValue[] | undefined;
|
|
14
|
+
|
|
15
|
+
export interface TemplateContext {
|
|
16
|
+
[key: string]: TemplateValue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isScalarValue(value: unknown): value is string | number | boolean {
|
|
20
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toTemplateContextRecord(value: unknown): TemplateContext {
|
|
24
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
const context: TemplateContext = {};
|
|
28
|
+
for (const [key, candidate] of Object.entries(value)) {
|
|
29
|
+
if (isScalarValue(candidate)) {
|
|
30
|
+
context[key] = candidate;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return context;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createTemplateContext(input: {
|
|
37
|
+
params?: unknown;
|
|
38
|
+
process?: {
|
|
39
|
+
processId?: string | null;
|
|
40
|
+
externalId?: string | null;
|
|
41
|
+
externalUrl?: string | null;
|
|
42
|
+
selectedTurnId?: string | null;
|
|
43
|
+
};
|
|
44
|
+
projects?: ReadonlyArray<{
|
|
45
|
+
key: string;
|
|
46
|
+
repoLocator: string;
|
|
47
|
+
baseBranch: string;
|
|
48
|
+
workBranch?: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
}): TemplateContext {
|
|
51
|
+
const context: TemplateContext = {
|
|
52
|
+
...toTemplateContextRecord(input.params),
|
|
53
|
+
};
|
|
54
|
+
if (input.process) {
|
|
55
|
+
context.processId = input.process.processId ?? undefined;
|
|
56
|
+
context.externalId = input.process.externalId ?? undefined;
|
|
57
|
+
context.externalUrl = input.process.externalUrl ?? undefined;
|
|
58
|
+
context.selectedTurnId = input.process.selectedTurnId ?? undefined;
|
|
59
|
+
}
|
|
60
|
+
const firstProject = input.projects?.[0];
|
|
61
|
+
if (firstProject) {
|
|
62
|
+
context.projectKey = firstProject.key;
|
|
63
|
+
context.repositoryUrl = firstProject.repoLocator;
|
|
64
|
+
context.baseBranch = firstProject.baseBranch;
|
|
65
|
+
context.workBranch = firstProject.workBranch ?? undefined;
|
|
66
|
+
}
|
|
67
|
+
return context;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function interpolateTemplate(template: string, context: TemplateContext): string {
|
|
71
|
+
return Mustache.render(template, context);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type TurnToolDefinitionLike =
|
|
75
|
+
| { kind: "llm"; availableTools: readonly PiBuiltInToolName[] }
|
|
76
|
+
| { kind: string };
|
|
77
|
+
|
|
78
|
+
type ProcessTurnBindingLike = {
|
|
79
|
+
definition: TurnToolDefinitionLike;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type ProcessToolSource = TurnToolDefinitionLike | ProcessTurnBindingLike;
|
|
83
|
+
|
|
84
|
+
function isTurnDefinitionSource(source: ProcessToolSource): source is TurnToolDefinitionLike {
|
|
85
|
+
return "kind" in source;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function resolveToolSourceDefinition(source: ProcessToolSource): TurnToolDefinitionLike {
|
|
89
|
+
return isTurnDefinitionSource(source) ? source : source.definition;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function validatePiBuiltInToolArray(
|
|
93
|
+
toolNames: readonly unknown[],
|
|
94
|
+
context: string,
|
|
95
|
+
): string[] {
|
|
96
|
+
const errors: string[] = [];
|
|
97
|
+
const seen = new Set<string>();
|
|
98
|
+
for (const rawName of toolNames) {
|
|
99
|
+
if (typeof rawName !== "string") {
|
|
100
|
+
errors.push(`${context} must contain only string tool names`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const name = rawName.trim();
|
|
104
|
+
if (name === "") {
|
|
105
|
+
errors.push(`${context} must not contain empty tool names`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (name !== rawName) {
|
|
109
|
+
errors.push(`${context} must use canonical Pi tool names without surrounding whitespace`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!PI_BUILT_IN_TOOL_NAMES.includes(name as PiBuiltInToolName)) {
|
|
113
|
+
errors.push(
|
|
114
|
+
`${context} references unknown Pi tool '${name}'. Expected one of ${PI_BUILT_IN_TOOL_NAMES.join(", ")}`,
|
|
115
|
+
);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (seen.has(name)) {
|
|
119
|
+
errors.push(`${context} must not contain duplicate Pi tool '${name}'`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
seen.add(name);
|
|
123
|
+
}
|
|
124
|
+
return errors;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function resolveTurnAvailableToolNames(input: {
|
|
128
|
+
turnId: string;
|
|
129
|
+
turnDef: LlmTurnDefinition<string, unknown, unknown>;
|
|
130
|
+
}): string[] {
|
|
131
|
+
const errors = validatePiBuiltInToolArray(
|
|
132
|
+
input.turnDef.availableTools,
|
|
133
|
+
`turn '${input.turnId}' availableTools`,
|
|
134
|
+
);
|
|
135
|
+
if (errors.length > 0) {
|
|
136
|
+
throw new Error(errors.join("; "));
|
|
137
|
+
}
|
|
138
|
+
return [...input.turnDef.availableTools];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function collectProcessAvailableToolNames(
|
|
142
|
+
turns: Iterable<ProcessToolSource> | undefined,
|
|
143
|
+
): string[] {
|
|
144
|
+
const usedToolNames = new Set<PiBuiltInToolName>();
|
|
145
|
+
for (const source of turns ?? []) {
|
|
146
|
+
const definition = resolveToolSourceDefinition(source);
|
|
147
|
+
if (definition.kind !== "llm" || !("availableTools" in definition)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const errors = validatePiBuiltInToolArray(definition.availableTools, "LLM turn availableTools");
|
|
151
|
+
if (errors.length > 0) {
|
|
152
|
+
throw new Error(errors.join("; "));
|
|
153
|
+
}
|
|
154
|
+
for (const toolName of definition.availableTools) {
|
|
155
|
+
usedToolNames.add(toolName);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return PI_BUILT_IN_TOOL_NAMES.filter((toolName) => usedToolNames.has(toolName));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const DEFAULT_TOOL_DESCRIPTIONS: Record<PiBuiltInToolName, string> = {
|
|
162
|
+
read: "Read file contents",
|
|
163
|
+
bash: "Execute bash commands (ls, grep, find, etc.)",
|
|
164
|
+
edit: "Make surgical edits to files (find exact text and replace)",
|
|
165
|
+
write: "Create or overwrite files",
|
|
166
|
+
grep: "Search file contents",
|
|
167
|
+
find: "Find files by name/path",
|
|
168
|
+
ls: "List directory contents",
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function buildDefaultSystemPrompt(availableToolNames: readonly string[]): string {
|
|
172
|
+
const toolList =
|
|
173
|
+
availableToolNames.length > 0
|
|
174
|
+
? availableToolNames
|
|
175
|
+
.map((toolName) => {
|
|
176
|
+
const description =
|
|
177
|
+
DEFAULT_TOOL_DESCRIPTIONS[toolName as PiBuiltInToolName] ?? "Built-in Pi tool";
|
|
178
|
+
return `- ${toolName}: ${description}`;
|
|
179
|
+
})
|
|
180
|
+
.join("\n")
|
|
181
|
+
: "- No built-in tools are available for this process unless a turn registers custom tools.";
|
|
182
|
+
return `You are an expert coding assistant operating inside pi, a coding agent harness. You help users by using the tools made available for the active turn.
|
|
183
|
+
|
|
184
|
+
Available built-in tools for this process:
|
|
185
|
+
${toolList}
|
|
186
|
+
|
|
187
|
+
In addition to the tools above, you may have access to other custom tools depending on the active turn.
|
|
188
|
+
|
|
189
|
+
Guidelines:
|
|
190
|
+
- Use only tools that are available in the active turn.
|
|
191
|
+
- Use read/search tools to examine files before editing.
|
|
192
|
+
- Use edit for precise changes when it is available (old text must match exactly).
|
|
193
|
+
- Use write only for new files or complete rewrites when it is available.
|
|
194
|
+
- When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did.
|
|
195
|
+
- Be concise in your responses.
|
|
196
|
+
- Show file paths clearly when working with files.`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function resolveProcessPiConfig(input: {
|
|
200
|
+
processId: string;
|
|
201
|
+
processPiConfig?: ProcessPiConfig;
|
|
202
|
+
turns?: Iterable<ProcessToolSource>;
|
|
203
|
+
configSnapshot?: ConfigSnapshot;
|
|
204
|
+
templateContext: TemplateContext;
|
|
205
|
+
}): ResolvedProcessPiConfig {
|
|
206
|
+
const processConfig = input.configSnapshot?.process_configs?.[input.processId];
|
|
207
|
+
const processPiOverride = processConfig?.pi;
|
|
208
|
+
const availableToolNames = collectProcessAvailableToolNames(input.turns);
|
|
209
|
+
|
|
210
|
+
const configSystemPromptTemplate = input.configSnapshot?.pi?.system_prompt_template;
|
|
211
|
+
const systemPromptTemplate =
|
|
212
|
+
processPiOverride?.system_prompt_template ??
|
|
213
|
+
input.processPiConfig?.systemPromptTemplate ??
|
|
214
|
+
configSystemPromptTemplate;
|
|
215
|
+
const appendSystemPromptTemplate =
|
|
216
|
+
processPiOverride?.append_system_prompt_template ??
|
|
217
|
+
input.processPiConfig?.appendSystemPromptTemplate;
|
|
218
|
+
|
|
219
|
+
const resolvedSystemPrompt = systemPromptTemplate
|
|
220
|
+
? interpolateTemplate(systemPromptTemplate, input.templateContext)
|
|
221
|
+
: buildDefaultSystemPrompt(availableToolNames);
|
|
222
|
+
const sessionCwd = input.processPiConfig?.sessionCwdTemplate
|
|
223
|
+
? interpolateTemplate(input.processPiConfig.sessionCwdTemplate, input.templateContext).trim()
|
|
224
|
+
: undefined;
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
systemPrompt: resolvedSystemPrompt,
|
|
228
|
+
appendSystemPrompt: appendSystemPromptTemplate
|
|
229
|
+
? interpolateTemplate(appendSystemPromptTemplate, input.templateContext)
|
|
230
|
+
: undefined,
|
|
231
|
+
...(sessionCwd ? { sessionCwd } : {}),
|
|
232
|
+
availableToolNames,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function resolveTurnActiveToolNames(input: {
|
|
237
|
+
turnId: string;
|
|
238
|
+
turnDef: LlmTurnDefinition<string, unknown, unknown>;
|
|
239
|
+
}): string[] {
|
|
240
|
+
return resolveTurnAvailableToolNames(input);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Mirror Pi's PI_CODING_AGENT_DIR expansion semantics from
|
|
244
|
+
// pi-mono/packages/coding-agent/src/config.ts.
|
|
245
|
+
export function expandPiAgentDir(agentDir: string): string {
|
|
246
|
+
if (agentDir === "~") {
|
|
247
|
+
return homedir();
|
|
248
|
+
}
|
|
249
|
+
if (agentDir.startsWith("~/")) {
|
|
250
|
+
return homedir() + agentDir.slice(1);
|
|
251
|
+
}
|
|
252
|
+
return agentDir;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function resolvePiAgentDir(options: {
|
|
256
|
+
agentDir?: string | null;
|
|
257
|
+
configSnapshot?: ConfigSnapshot;
|
|
258
|
+
fallbackDir: string;
|
|
259
|
+
}): string {
|
|
260
|
+
const configuredAgentDir =
|
|
261
|
+
typeof options.agentDir === "string" && options.agentDir.trim() !== ""
|
|
262
|
+
? options.agentDir
|
|
263
|
+
: typeof options.configSnapshot?.pi?.agent_dir === "string" &&
|
|
264
|
+
options.configSnapshot.pi.agent_dir.trim() !== ""
|
|
265
|
+
? options.configSnapshot.pi.agent_dir
|
|
266
|
+
: options.fallbackDir;
|
|
267
|
+
return expandPiAgentDir(configuredAgentDir);
|
|
268
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ProcessTurnTransition } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { ProcessTurnBinding } from "./extension-api.js";
|
|
3
|
+
|
|
4
|
+
interface ProcessDefinitionInternalRegistry {
|
|
5
|
+
definedProcesses: WeakSet<object>;
|
|
6
|
+
turnTransitions: WeakMap<object, readonly ProcessTurnTransition[]>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const registryKey = Symbol.for("@leitwerk-dev/process-sdk/internal-registry");
|
|
10
|
+
const registryHolder = globalThis as typeof globalThis & {
|
|
11
|
+
[registryKey]?: ProcessDefinitionInternalRegistry;
|
|
12
|
+
};
|
|
13
|
+
if (!registryHolder[registryKey]) {
|
|
14
|
+
registryHolder[registryKey] = {
|
|
15
|
+
definedProcesses: new WeakSet<object>(),
|
|
16
|
+
turnTransitions: new WeakMap<object, readonly ProcessTurnTransition[]>(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const registry = registryHolder[registryKey];
|
|
20
|
+
|
|
21
|
+
export function markDefinedProcess(value: object): void {
|
|
22
|
+
registry.definedProcesses.add(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isDefinedProcess(value: unknown): boolean {
|
|
26
|
+
return typeof value === "object" && value !== null && registry.definedProcesses.has(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function setProcessTurnTransitions(
|
|
30
|
+
binding: object,
|
|
31
|
+
transitions: readonly ProcessTurnTransition[],
|
|
32
|
+
): void {
|
|
33
|
+
registry.turnTransitions.set(
|
|
34
|
+
binding,
|
|
35
|
+
transitions.map((transition) => ({ ...transition })),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getProcessTurnTransitions(
|
|
40
|
+
binding: ProcessTurnBinding<unknown> | undefined,
|
|
41
|
+
): readonly ProcessTurnTransition[] {
|
|
42
|
+
if (!binding) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return registry.turnTransitions.get(binding)?.map((transition) => ({ ...transition })) ?? [];
|
|
46
|
+
}
|