@leitwerk-dev/process-sdk 0.2.1 → 0.3.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 (60) hide show
  1. package/README.md +12 -0
  2. package/dist/{chunk-I7U6HCLN.js → chunk-GVBLXKSR.js} +1 -1
  3. package/dist/chunk-GVBLXKSR.js.map +1 -0
  4. package/dist/core-capabilities.d.ts +2 -0
  5. package/dist/core-capabilities.d.ts.map +1 -1
  6. package/dist/define-process.d.ts +3 -0
  7. package/dist/define-process.d.ts.map +1 -1
  8. package/dist/{extension-api-B4gG5w1K.d.ts → extension-api-DM-AvWOW.d.ts} +211 -14
  9. package/dist/extension-api.d.ts +19 -5
  10. package/dist/extension-api.d.ts.map +1 -1
  11. package/dist/external-source-poll.d.ts +18 -12
  12. package/dist/external-source-poll.d.ts.map +1 -1
  13. package/dist/flow.d.ts +118 -13
  14. package/dist/flow.d.ts.map +1 -1
  15. package/dist/index.d.ts +6 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +647 -82
  18. package/dist/index.js.map +1 -1
  19. package/dist/integration-http.d.ts +4 -4
  20. package/dist/integration-http.d.ts.map +1 -1
  21. package/dist/json-data.d.ts +1 -1
  22. package/dist/json-data.d.ts.map +1 -1
  23. package/dist/mapped-turn.d.ts +185 -0
  24. package/dist/mapped-turn.d.ts.map +1 -0
  25. package/dist/pi-config-public.js +1 -1
  26. package/dist/pi-config.js +1 -1
  27. package/dist/repository-feedback.d.ts +32 -26
  28. package/dist/repository-feedback.d.ts.map +1 -1
  29. package/dist/repository-https.d.ts +1 -1
  30. package/dist/repository-https.d.ts.map +1 -1
  31. package/dist/repository-issue-watcher.d.ts +30 -25
  32. package/dist/repository-issue-watcher.d.ts.map +1 -1
  33. package/dist/repository-source-config.d.ts +29 -44
  34. package/dist/repository-source-config.d.ts.map +1 -1
  35. package/dist/subprocess-env.d.ts +1 -1
  36. package/dist/subprocess-env.d.ts.map +1 -1
  37. package/dist/tool-arguments.d.ts +3 -3
  38. package/dist/tool-arguments.d.ts.map +1 -1
  39. package/dist/turn-semantics.d.ts.map +1 -1
  40. package/dist/types.d.ts +15 -7
  41. package/dist/types.d.ts.map +1 -1
  42. package/package.json +6 -6
  43. package/src/core-capabilities.ts +2 -0
  44. package/src/define-process.ts +83 -0
  45. package/src/extension-api.ts +23 -5
  46. package/src/external-source-poll.ts +65 -11
  47. package/src/flow.ts +448 -31
  48. package/src/index.ts +38 -2
  49. package/src/integration-http.ts +3 -3
  50. package/src/json-data.ts +1 -1
  51. package/src/mapped-turn.ts +386 -0
  52. package/src/repository-feedback.ts +48 -20
  53. package/src/repository-https.ts +1 -1
  54. package/src/repository-issue-watcher.ts +48 -21
  55. package/src/repository-source-config.ts +66 -23
  56. package/src/subprocess-env.ts +1 -1
  57. package/src/tool-arguments.ts +3 -3
  58. package/src/turn-semantics.ts +76 -1
  59. package/src/types.ts +15 -7
  60. package/dist/chunk-I7U6HCLN.js.map +0 -1
@@ -1,7 +1,10 @@
1
1
  import { asUnknownRecord } from "@leitwerk-dev/domain";
2
+ import type { RepositoryFeedbackBatchConfig } from "./repository-feedback.js";
2
3
 
3
- /** Parse common forge source fields, preserving polling defaults and permissive string handling. @internal */
4
- export function parseRepositoryPullRequestConfig(value: unknown) {
4
+ /** Parse common forge source fields, preserving polling defaults and permissive string handling. @public */
5
+ export function parseRepositoryPullRequestConfig(
6
+ value: unknown,
7
+ ): RepositoryPullRequestSourceConfig | null {
5
8
  const config = asUnknownRecord(value) ?? {};
6
9
  if (
7
10
  typeof config.profile !== "string" ||
@@ -15,44 +18,48 @@ export function parseRepositoryPullRequestConfig(value: unknown) {
15
18
  ? config.terminalOutcome
16
19
  : undefined;
17
20
  return {
18
- /** @internal */
21
+ /** @public */
19
22
  profile: config.profile,
20
- /** @internal */
23
+ /** @public */
21
24
  owner: config.owner,
22
- /** @internal */
25
+ /** @public */
23
26
  repo: config.repo,
24
- /** @internal */
27
+ /** @public */
25
28
  prNumber: config.prNumber,
26
- /** @internal */
29
+ /** @public */
27
30
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
28
- /** @internal */
31
+ /** @public */
29
32
  terminalOutcome,
30
- /** @internal */
33
+ /** @public */
31
34
  disabled: config.disabled === true,
32
35
  };
33
36
  }
34
37
 
35
- /** @internal */
36
- export function parseRepositoryFeedbackConfig(value: unknown) {
38
+ /** @public */
39
+ export function parseRepositoryFeedbackConfig(
40
+ value: unknown,
41
+ ): RepositoryFeedbackSourceConfig | null {
37
42
  const base = parseRepositoryPullRequestConfig(value);
38
43
  const config = asUnknownRecord(value) ?? {};
39
44
  if (!base) return null;
40
45
  return {
41
46
  ...base,
42
- /** @internal */
47
+ /** @public */
43
48
  conversationCursor:
44
49
  typeof config.conversationCursor === "number" ? config.conversationCursor : 0,
45
- /** @internal */
50
+ /** @public */
46
51
  reviewCursor: typeof config.reviewCursor === "number" ? config.reviewCursor : 0,
47
- /** @internal */
52
+ /** @public */
48
53
  inlineCursor: typeof config.inlineCursor === "number" ? config.inlineCursor : 0,
49
- /** @internal */
54
+ /** @public */
50
55
  quietPeriodMs: typeof config.quietPeriodMs === "number" ? config.quietPeriodMs : 120_000,
51
56
  };
52
57
  }
53
58
 
54
- /** @internal */
55
- export function parseRepositoryIssueCancelledConfig(value: unknown) {
59
+ /** @public */
60
+ export function parseRepositoryIssueCancelledConfig(
61
+ value: unknown,
62
+ ): RepositoryIssueCancelledSourceConfig | null {
56
63
  const config = asUnknownRecord(value) ?? {};
57
64
  if (
58
65
  typeof config.profile !== "string" ||
@@ -63,17 +70,53 @@ export function parseRepositoryIssueCancelledConfig(value: unknown) {
63
70
  )
64
71
  return null;
65
72
  return {
66
- /** @internal */
73
+ /** @public */
67
74
  profile: config.profile,
68
- /** @internal */
75
+ /** @public */
69
76
  owner: config.owner,
70
- /** @internal */
77
+ /** @public */
71
78
  repo: config.repo,
72
- /** @internal */
79
+ /** @public */
73
80
  issueNumber: config.issueNumber,
74
- /** @internal */
81
+ /** @public */
75
82
  triggerLabel: config.triggerLabel,
76
- /** @internal */
83
+ /** @public */
77
84
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
78
85
  };
79
86
  }
87
+ /** @public */
88
+ export interface RepositoryPullRequestSourceConfig {
89
+ /** @public */
90
+ profile: string;
91
+ /** @public */
92
+ owner: string;
93
+ /** @public */
94
+ repo: string;
95
+ /** @public */
96
+ prNumber: number;
97
+ /** @public */
98
+ pollInterval: string;
99
+ /** @public */
100
+ terminalOutcome: "merged" | "closed" | undefined;
101
+ /** @public */
102
+ disabled: boolean;
103
+ }
104
+ /** @public */
105
+ export interface RepositoryFeedbackSourceConfig
106
+ extends RepositoryPullRequestSourceConfig,
107
+ RepositoryFeedbackBatchConfig {}
108
+ /** @public */
109
+ export interface RepositoryIssueCancelledSourceConfig {
110
+ /** @public */
111
+ profile: string;
112
+ /** @public */
113
+ owner: string;
114
+ /** @public */
115
+ repo: string;
116
+ /** @public */
117
+ issueNumber: number;
118
+ /** @public */
119
+ triggerLabel: string;
120
+ /** @public */
121
+ pollInterval: string;
122
+ }
@@ -34,7 +34,7 @@ const SENSITIVE_ENV_KEYS = new Set<string>([
34
34
  * process itself. Repository scripts, git hooks, package managers, and other
35
35
  * tool subprocesses must not receive them.
36
36
  */
37
- /** @internal */
37
+ /** @public */
38
38
  export function sanitizeWorkerSubprocessEnv(
39
39
  baseEnv: SubprocessEnvInput = process.env,
40
40
  overrides: SubprocessEnvInput = {},
@@ -13,7 +13,7 @@ export function projectParameters(
13
13
  };
14
14
  }
15
15
 
16
- /** @internal */
16
+ /** @public */
17
17
  export function objectArg(
18
18
  value: unknown,
19
19
  message = "Tool arguments must be an object",
@@ -22,7 +22,7 @@ export function objectArg(
22
22
  return value as Record<string, unknown>;
23
23
  }
24
24
 
25
- /** Read required integration-tool arguments at the runtime boundary. @internal */
25
+ /** Read required integration-tool arguments at the runtime boundary. @public */
26
26
  export function stringArg(args: Record<string, unknown>, name: string): string {
27
27
  const value = args[name];
28
28
  if (typeof value !== "string" || !value.trim())
@@ -30,7 +30,7 @@ export function stringArg(args: Record<string, unknown>, name: string): string {
30
30
  return value.trim();
31
31
  }
32
32
 
33
- /** @internal */
33
+ /** @public */
34
34
  export function numberArg(args: Record<string, unknown>, name: string): number {
35
35
  const value = args[name];
36
36
  if (typeof value !== "number" || !Number.isInteger(value) || value <= 0)
@@ -131,7 +131,13 @@ function validateOutcomeTurnResultContract<TParams = unknown, TState = unknown>(
131
131
  }
132
132
 
133
133
  function isValidOutcomeToolArrayItemType(type: unknown): boolean {
134
- return type === "string" || type === "number" || type === "boolean" || type === "object";
134
+ return (
135
+ type === "string" ||
136
+ type === "number" ||
137
+ type === "boolean" ||
138
+ type === "object" ||
139
+ type === "array"
140
+ );
135
141
  }
136
142
 
137
143
  function validateOutcomeToolParameters<TParams = unknown, TState = unknown>(
@@ -321,7 +327,76 @@ export function validateLlmTurnDefinition<
321
327
  }
322
328
 
323
329
  errors.push(...validateOutcomeToolParameters("LLM", turnId, declaredOutcomes));
330
+ errors.push(...validateMappedTurn(turnId, turnDef));
331
+
332
+ return errors;
333
+ }
324
334
 
335
+ function validateMappedTurn<TOutcome extends string, TParams, TState>(
336
+ turnId: string,
337
+ turnDef: LlmTurnDefinition<TOutcome, TParams, TState>,
338
+ ): string[] {
339
+ const mapped = turnDef.forEach;
340
+ if (mapped === undefined) return [];
341
+ const errors: string[] = [];
342
+ for (const name of ["items", "key", "collect"] as const) {
343
+ if (typeof mapped[name] !== "function") {
344
+ errors.push(`Mapped turn '${turnId}' must declare ${name}`);
345
+ }
346
+ }
347
+ for (const name of ["itemCodec", "resultCodec"] as const) {
348
+ const codec = mapped[name];
349
+ if (typeof codec?.parse !== "function" || typeof codec?.serialize !== "function") {
350
+ errors.push(`Mapped turn '${turnId}' must declare ${name}`);
351
+ }
352
+ }
353
+ if (turnDef.turnEnd) {
354
+ errors.push(`Mapped turn '${turnId}' must finish items through outcome tools`);
355
+ }
356
+ if (turnDef.publishedProduct) {
357
+ errors.push(`Mapped turn '${turnId}' cannot publish a product from item turns`);
358
+ }
359
+ const outcomes = Object.entries(turnDef.outcomes ?? {}) as Array<
360
+ [string, ProcessToolOutcomeSpec<TParams, TState>]
361
+ >;
362
+ if (outcomes.length === 0) {
363
+ errors.push(`Mapped turn '${turnId}' must declare at least one outcome tool`);
364
+ }
365
+ for (const [outcomeId, spec] of outcomes) {
366
+ if (
367
+ "branches" in spec ||
368
+ spec.to !== undefined ||
369
+ spec.complete !== undefined ||
370
+ spec.lifecycleStatus !== undefined ||
371
+ spec.effect !== undefined ||
372
+ spec.lifecycleIntent !== undefined ||
373
+ spec.publishedProduct !== undefined
374
+ ) {
375
+ errors.push(
376
+ `Mapped turn '${turnId}' outcome '${outcomeId}' cannot route, change state, or publish`,
377
+ );
378
+ }
379
+ if (typeof mapped.yields?.[outcomeId] !== "function") {
380
+ errors.push(`Mapped turn '${turnId}' outcome '${outcomeId}' must declare a yield`);
381
+ }
382
+ }
383
+ for (const outcomeId of Object.keys(mapped.yields ?? {})) {
384
+ if (!Object.hasOwn(turnDef.outcomes ?? {}, outcomeId)) {
385
+ errors.push(`Mapped turn '${turnId}' yields undeclared outcome '${outcomeId}'`);
386
+ }
387
+ }
388
+ const routing = mapped.routing;
389
+ if (routing?.kind === "static") {
390
+ if ((routing.to === undefined) === (routing.lifecycleStatus === undefined)) {
391
+ errors.push(`Mapped turn '${turnId}' collection must declare exactly one target`);
392
+ }
393
+ } else if (routing?.kind === "branches") {
394
+ if (Object.keys(routing.branches).length === 0 || typeof routing.choose !== "function") {
395
+ errors.push(`Mapped turn '${turnId}' collection routing needs branches and a chooser`);
396
+ }
397
+ } else {
398
+ errors.push(`Mapped turn '${turnId}' must declare a collection route`);
399
+ }
325
400
  return errors;
326
401
  }
327
402
 
package/src/types.ts CHANGED
@@ -81,17 +81,25 @@ export interface ResolvedProcessPiConfig {
81
81
  availableToolNames: string[];
82
82
  }
83
83
 
84
- /** @internal */
84
+ /** @public */
85
85
  export type OutcomeToolParameterType = "string" | "number" | "array" | "boolean" | "object";
86
- /** @internal */
87
- export type OutcomeToolArrayItemType = Exclude<OutcomeToolParameterType, "array">;
88
86
 
89
- /** @internal */
87
+ /** JSON-schema-compatible value declaration nested below an outcome parameter. @public */
90
88
  export interface OutcomeToolArrayItemSpec {
91
- /** @internal */
92
- type: OutcomeToolArrayItemType;
93
- /** @internal */
89
+ /** @public */
90
+ type: OutcomeToolParameterType;
91
+ /** @public */
94
92
  description?: string;
93
+ /** @public */
94
+ minItems?: number;
95
+ /** @public */
96
+ items?: OutcomeToolArrayItemSpec;
97
+ /** @public */
98
+ properties?: Record<string, OutcomeToolArrayItemSpec>;
99
+ /** @public */
100
+ required?: readonly string[];
101
+ /** @public */
102
+ additionalProperties?: boolean;
95
103
  }
96
104
 
97
105
  /** @public */
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/pi-config.ts","../src/types.ts"],"sourcesContent":["import { homedir } from \"node:os\";\nimport type { ConfigSnapshot } from \"@leitwerk-dev/protocol\";\nimport Mustache from \"mustache\";\nimport type { LlmTurnDefinition } from \"./define-process.js\";\nimport {\n\tPI_BUILT_IN_TOOL_NAMES,\n\ttype PiBuiltInToolName,\n\ttype ProcessPiConfig,\n\ttype ResolvedProcessPiConfig,\n} from \"./types.js\";\n\n/** @internal */\ntype TemplateScalar = string | number | boolean;\n/** @internal */\ntype TemplateValue = TemplateScalar | TemplateContext | readonly TemplateValue[] | undefined;\n\n/** @internal */\nexport interface TemplateContext {\n\t/** @internal */\n\t[key: string]: TemplateValue;\n}\n\nfunction isScalarValue(value: unknown): value is string | number | boolean {\n\treturn typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\";\n}\n\nfunction toTemplateContextRecord(value: unknown): TemplateContext {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\treturn {};\n\t}\n\tconst context: TemplateContext = {};\n\tfor (const [key, candidate] of Object.entries(value)) {\n\t\tif (isScalarValue(candidate)) {\n\t\t\tcontext[key] = candidate;\n\t\t}\n\t}\n\treturn context;\n}\n\n/** @internal */\nexport function createTemplateContext(input: {\n\t/** @internal */\n\tparams?: unknown;\n\t/** @internal */\n\tprocess?: {\n\t\t/** @internal */\n\t\tprocessId?: string | null;\n\t\t/** @internal */\n\t\texternalId?: string | null;\n\t\t/** @internal */\n\t\texternalUrl?: string | null;\n\t\t/** @internal */\n\t\tselectedTurnId?: string | null;\n\t};\n\t/** @internal */\n\tprojects?: ReadonlyArray<{\n\t\t/** @internal */\n\t\tkey: string;\n\t\t/** @internal */\n\t\trepoLocator: string;\n\t\t/** @internal */\n\t\tbaseBranch: string;\n\t\t/** @internal */\n\t\tworkBranch?: string | null;\n\t}>;\n}): TemplateContext {\n\tconst context: TemplateContext = {\n\t\t...toTemplateContextRecord(input.params),\n\t};\n\tif (input.process) {\n\t\tcontext.processId = input.process.processId ?? undefined;\n\t\tcontext.externalId = input.process.externalId ?? undefined;\n\t\tcontext.externalUrl = input.process.externalUrl ?? undefined;\n\t\tcontext.selectedTurnId = input.process.selectedTurnId ?? undefined;\n\t}\n\tconst firstProject = input.projects?.[0];\n\tif (firstProject) {\n\t\tcontext.projectKey = firstProject.key;\n\t\tcontext.repositoryUrl = firstProject.repoLocator;\n\t\tcontext.baseBranch = firstProject.baseBranch;\n\t\tcontext.workBranch = firstProject.workBranch ?? undefined;\n\t}\n\treturn context;\n}\n\n/** @internal */\nexport function interpolateTemplate(template: string, context: TemplateContext): string {\n\treturn Mustache.render(template, context);\n}\n\n/** @internal */\ntype TurnToolDefinitionLike =\n\t| {\n\t\t\t/** @internal */\n\t\t\tkind: \"llm\";\n\t\t\t/** @internal */\n\t\t\tavailableTools: readonly PiBuiltInToolName[];\n\t }\n\t| {\n\t\t\t/** @internal */\n\t\t\tkind: string;\n\t };\n\n/** @internal */\ntype ProcessTurnBindingLike = {\n\t/** @internal */\n\tdefinition: TurnToolDefinitionLike;\n};\n\n/** @internal */\ntype ProcessToolSource = TurnToolDefinitionLike | ProcessTurnBindingLike;\n\nfunction isTurnDefinitionSource(source: ProcessToolSource): source is TurnToolDefinitionLike {\n\treturn \"kind\" in source;\n}\n\nfunction resolveToolSourceDefinition(source: ProcessToolSource): TurnToolDefinitionLike {\n\treturn isTurnDefinitionSource(source) ? source : source.definition;\n}\n\n/** @internal */\nexport function validatePiBuiltInToolArray(\n\ttoolNames: readonly unknown[],\n\tcontext: string,\n): string[] {\n\tconst errors: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const rawName of toolNames) {\n\t\tif (typeof rawName !== \"string\") {\n\t\t\terrors.push(`${context} must contain only string tool names`);\n\t\t\tcontinue;\n\t\t}\n\t\tconst name = rawName.trim();\n\t\tif (name === \"\") {\n\t\t\terrors.push(`${context} must not contain empty tool names`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (name !== rawName) {\n\t\t\terrors.push(`${context} must use canonical Pi tool names without surrounding whitespace`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!PI_BUILT_IN_TOOL_NAMES.includes(name as PiBuiltInToolName)) {\n\t\t\terrors.push(\n\t\t\t\t`${context} references unknown Pi tool '${name}'. Expected one of ${PI_BUILT_IN_TOOL_NAMES.join(\", \")}`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (seen.has(name)) {\n\t\t\terrors.push(`${context} must not contain duplicate Pi tool '${name}'`);\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(name);\n\t}\n\treturn errors;\n}\n\n/** @internal */\nexport function resolveTurnAvailableToolNames(input: {\n\t/** @internal */\n\tturnId: string;\n\t/** @internal */\n\tturnDef: LlmTurnDefinition<string, unknown, unknown>;\n}): string[] {\n\tconst errors = validatePiBuiltInToolArray(\n\t\tinput.turnDef.availableTools,\n\t\t`turn '${input.turnId}' availableTools`,\n\t);\n\tif (errors.length > 0) {\n\t\tthrow new Error(errors.join(\"; \"));\n\t}\n\treturn [...input.turnDef.availableTools];\n}\n\n/** @internal */\nexport function collectProcessAvailableToolNames(\n\tturns: Iterable<ProcessToolSource> | undefined,\n): string[] {\n\tconst usedToolNames = new Set<PiBuiltInToolName>();\n\tfor (const source of turns ?? []) {\n\t\tconst definition = resolveToolSourceDefinition(source);\n\t\tif (definition.kind !== \"llm\" || !(\"availableTools\" in definition)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst errors = validatePiBuiltInToolArray(definition.availableTools, \"LLM turn availableTools\");\n\t\tif (errors.length > 0) {\n\t\t\tthrow new Error(errors.join(\"; \"));\n\t\t}\n\t\tfor (const toolName of definition.availableTools) {\n\t\t\tusedToolNames.add(toolName);\n\t\t}\n\t}\n\treturn PI_BUILT_IN_TOOL_NAMES.filter((toolName) => usedToolNames.has(toolName));\n}\n\nconst DEFAULT_TOOL_DESCRIPTIONS: Record<PiBuiltInToolName, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents\",\n\tfind: \"Find files by name/path\",\n\tls: \"List directory contents\",\n};\n\nfunction buildDefaultSystemPrompt(availableToolNames: readonly string[]): string {\n\tconst toolList =\n\t\tavailableToolNames.length > 0\n\t\t\t? availableToolNames\n\t\t\t\t\t.map((toolName) => {\n\t\t\t\t\t\tconst description =\n\t\t\t\t\t\t\tDEFAULT_TOOL_DESCRIPTIONS[toolName as PiBuiltInToolName] ?? \"Built-in Pi tool\";\n\t\t\t\t\t\treturn `- ${toolName}: ${description}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"- No built-in tools are available for this process unless a turn registers custom tools.\";\n\treturn `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.\n\nAvailable built-in tools for this process:\n${toolList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the active turn.\n\nGuidelines:\n- Use only tools that are available in the active turn.\n- Use read/search tools to examine files before editing.\n- Use edit for precise changes when it is available (old text must match exactly).\n- Use write only for new files or complete rewrites when it is available.\n- When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did.\n- Be concise in your responses.\n- Show file paths clearly when working with files.`;\n}\n\n/** @internal */\nexport function resolveProcessPiConfig(input: {\n\t/** @internal */\n\tprocessId: string;\n\t/** @internal */\n\tprocessPiConfig?: ProcessPiConfig;\n\t/** @internal */\n\tturns?: Iterable<ProcessToolSource>;\n\t/** @internal */\n\tconfigSnapshot?: ConfigSnapshot;\n\t/** @internal */\n\ttemplateContext: TemplateContext;\n}): ResolvedProcessPiConfig {\n\tconst processConfig = input.configSnapshot?.process_configs?.[input.processId];\n\tconst processPiOverride = processConfig?.pi;\n\tconst availableToolNames = collectProcessAvailableToolNames(input.turns);\n\n\tconst configSystemPromptTemplate = input.configSnapshot?.pi?.system_prompt_template;\n\tconst systemPromptTemplate =\n\t\tprocessPiOverride?.system_prompt_template ??\n\t\tinput.processPiConfig?.systemPromptTemplate ??\n\t\tconfigSystemPromptTemplate;\n\tconst appendSystemPromptTemplate =\n\t\tprocessPiOverride?.append_system_prompt_template ??\n\t\tinput.processPiConfig?.appendSystemPromptTemplate;\n\n\tconst resolvedSystemPrompt = systemPromptTemplate\n\t\t? interpolateTemplate(systemPromptTemplate, input.templateContext)\n\t\t: buildDefaultSystemPrompt(availableToolNames);\n\tconst sessionCwd = input.processPiConfig?.sessionCwdTemplate\n\t\t? interpolateTemplate(input.processPiConfig.sessionCwdTemplate, input.templateContext).trim()\n\t\t: undefined;\n\n\treturn {\n\t\tsystemPrompt: resolvedSystemPrompt,\n\t\tappendSystemPrompt: appendSystemPromptTemplate\n\t\t\t? interpolateTemplate(appendSystemPromptTemplate, input.templateContext)\n\t\t\t: undefined,\n\t\t...(sessionCwd ? { sessionCwd } : {}),\n\t\tavailableToolNames,\n\t};\n}\n\nexport { resolveTurnAvailableToolNames as resolveTurnActiveToolNames };\n\n// Mirror Pi's PI_CODING_AGENT_DIR expansion semantics from\n// pi-mono/packages/coding-agent/src/config.ts.\n/** @internal */\nexport function expandPiAgentDir(agentDir: string): string {\n\tif (agentDir === \"~\") {\n\t\treturn homedir();\n\t}\n\tif (agentDir.startsWith(\"~/\")) {\n\t\treturn homedir() + agentDir.slice(1);\n\t}\n\treturn agentDir;\n}\n\n/** @internal */\nexport function resolvePiAgentDir(options: {\n\t/** @internal */\n\tagentDir?: string | null;\n\t/** @internal */\n\tconfigSnapshot?: ConfigSnapshot;\n\t/** @internal */\n\tfallbackDir: string;\n}): string {\n\tconst configuredAgentDir =\n\t\ttypeof options.agentDir === \"string\" && options.agentDir.trim() !== \"\"\n\t\t\t? options.agentDir\n\t\t\t: typeof options.configSnapshot?.pi?.agent_dir === \"string\" &&\n\t\t\t\t\toptions.configSnapshot.pi.agent_dir.trim() !== \"\"\n\t\t\t\t? options.configSnapshot.pi.agent_dir\n\t\t\t\t: options.fallbackDir;\n\treturn expandPiAgentDir(configuredAgentDir);\n}\n","import type {\n\tTurnAcceptanceState as DomainTurnAcceptanceState,\n\tProcessTurnRecordPathType,\n\tProcessTurnTerminalLifecycleStatus,\n\tTurnId,\n} from \"@leitwerk-dev/domain\";\nimport type { UsageCostSnapshot, UsageTokenCounts } from \"@leitwerk-dev/protocol\";\n\n/** @internal */\nexport interface TurnOptions {\n\t/** @internal */\n\treset?: boolean;\n}\n\n/** @internal */\nexport interface TurnResult<T extends string = string> {\n\t/** @internal */\n\toutcome: T;\n\t/** @internal */\n\tparams: Record<string, unknown>;\n}\n\n/** @public */\nexport const PI_BUILT_IN_TOOL_NAMES = [\n\t\"read\",\n\t\"bash\",\n\t\"edit\",\n\t\"write\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n] as const;\n/** @public */\nexport type PiBuiltInToolName = (typeof PI_BUILT_IN_TOOL_NAMES)[number];\n\n/** Tool names owned by the worker runtime rather than an integration extension. @internal */\nexport const FRAMEWORK_LLM_TOOL_NAMES = [\n\t\"ask_questions\",\n\t\"markdown_result\",\n\t\"upload_result_images\",\n] as const;\n\n/** Names integration tools cannot use because Pi or the worker runtime owns them. @internal */\nexport const RESERVED_INTEGRATION_TOOL_NAMES = [\n\t...PI_BUILT_IN_TOOL_NAMES,\n\t...FRAMEWORK_LLM_TOOL_NAMES,\n] as const;\n\n/** @public */\nexport interface ProcessPiConfig {\n\t/**\n\t * System prompt template. Rendered with Mustache against runtime context.\n\t * Use {{variableName}} for escaped values and {{{variableName}}} for raw values.\n\t * When omitted, Pi's default system prompt is used.\n\t */\n\t/** @internal */\n\tsystemPromptTemplate?: string;\n\t/**\n\t * Additional text appended after the base system prompt/resources. Rendered\n\t * with Mustache against runtime context.\n\t */\n\t/** @public */\n\tappendSystemPromptTemplate?: string;\n\t/**\n\t * Code-defined Pi session working directory template. Rendered with Mustache\n\t * against runtime context. When omitted, the process workspace root is used.\n\t */\n\t/** @public */\n\tsessionCwdTemplate?: string;\n}\n\n/** @internal */\nexport interface ResolvedProcessPiConfig {\n\t/** @internal */\n\tsystemPrompt?: string;\n\t/** @internal */\n\tappendSystemPrompt?: string;\n\t/** @internal */\n\tsessionCwd?: string;\n\t/** @internal */\n\tavailableToolNames: string[];\n}\n\n/** @internal */\nexport type OutcomeToolParameterType = \"string\" | \"number\" | \"array\" | \"boolean\" | \"object\";\n/** @internal */\nexport type OutcomeToolArrayItemType = Exclude<OutcomeToolParameterType, \"array\">;\n\n/** @internal */\nexport interface OutcomeToolArrayItemSpec {\n\t/** @internal */\n\ttype: OutcomeToolArrayItemType;\n\t/** @internal */\n\tdescription?: string;\n}\n\n/** @public */\nexport interface OutcomeToolParameterSpec {\n\t/** @internal */\n\ttype: OutcomeToolParameterType;\n\t/** @internal */\n\tdescription: string;\n\t/** @internal */\n\trequired?: boolean;\n\t/** @internal */\n\trequiredErrorCode?: string;\n\t/** @internal */\n\tinvalidErrorCode?: string;\n\t/** @internal */\n\tminItems?: number;\n\t/** @internal */\n\tminItemsErrorCode?: string;\n\t/** @internal */\n\tminimum?: number;\n\t/** @internal */\n\tminimumErrorCode?: string;\n\t/** @internal */\n\titems?: OutcomeToolArrayItemSpec;\n\t/** @internal */\n\tenum?: readonly string[];\n}\n\n/** @internal */\nexport interface OutcomeToolSpec {\n\t/** @internal */\n\tdescription: string;\n\t/** @internal */\n\tparameters: Record<string, OutcomeToolParameterSpec>;\n\t/** Product published from this outcome's turn-result markdown, when selected. @internal */\n\tpublishedProduct?: string;\n\t/** Outcome parameter whose markdown value is captured as the turn result. @internal */\n\tturnResultMarkdownParameter?: string;\n\t/** Outcome parameter containing a concise operator-facing summary. @internal */\n\tresultSummaryParameter?: string;\n}\n\n/** @public */\nexport interface PiTreeEntry {\n\t/** @internal */\n\treadonly id: string;\n\t/** @internal */\n\treadonly parentId: string | null;\n\t/** @public */\n\treadonly type: string;\n\t/** @internal */\n\treadonly timestamp: string;\n\t/** @public */\n\treadonly message?: {\n\t\t/** @internal */\n\t\treadonly role?: string;\n\t\t/** @public */\n\t\treadonly content?: unknown;\n\t};\n\t/** Pi custom-message fields. Details are intentionally excluded from model context. @internal */\n\treadonly customType?: string;\n\t/** @public */\n\treadonly content?: unknown;\n\t/** @internal */\n\treadonly details?: unknown;\n\t/** @internal */\n\treadonly targetId?: string;\n\t/** @internal */\n\treadonly label?: string;\n}\n\n/** @internal */\nexport interface PiTreeNode {\n\t/** @internal */\n\treadonly entry: PiTreeEntry;\n\t/** @internal */\n\treadonly children: readonly PiTreeNode[];\n\t/** @internal */\n\treadonly label?: string;\n\t/** @internal */\n\treadonly labelTimestamp?: string;\n}\n\n/** @public */\nexport interface PiTurnExecutionResult {\n\t/** @internal */\n\tstartLeafId: string | null;\n\t/** @internal */\n\tendLeafId: string | null;\n\t/** @internal */\n\tcreatedEntryIds: string[];\n\t/** @internal */\n\tresultEntryId: string;\n\t/** Final assistant markdown captured from the Pi assistant message for this turn, when available. @internal */\n\tassistantMarkdown?: string | null;\n}\n\n/** @internal */\nexport type PiEventType =\n\t| \"turn.start\"\n\t| \"turn.end\"\n\t| \"stream.delta\"\n\t| \"tool.call\"\n\t| \"tool.update\"\n\t| \"tool.result\"\n\t| \"toolcall.start\"\n\t| \"toolcall.delta\"\n\t| \"toolcall.end\"\n\t| \"compaction.start\"\n\t| \"compaction.end\"\n\t| \"label.changed\"\n\t| \"error\"\n\t| \"retry.start\"\n\t| \"retry.end\"\n\t| \"usage\";\n\n/** @internal */\nexport interface PiEvent {\n\t/** @internal */\n\ttype: PiEventType;\n\t/** @internal */\n\tturnId: string;\n\t/** @internal */\n\tdata: Record<string, unknown>;\n\t/** @internal */\n\ttimestamp: string;\n}\n\n/** @internal */\nexport type PiEventHandler = (event: PiEvent) => void;\n\n/** @internal */\nexport type PiSessionDiagnosticLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\n/** @internal */\nexport interface PiSessionDiagnostic {\n\t/** @internal */\n\tlevel: PiSessionDiagnosticLevel;\n\t/** @internal */\n\tcode: string;\n\t/** @internal */\n\tmessage: string;\n\t/** @internal */\n\ttimestamp: string;\n\t/** @internal */\n\tturnId?: string;\n\t/** @internal */\n\tdetails?: Record<string, unknown>;\n}\n\n/** @internal */\nexport type PiSessionDiagnosticHandler = (diagnostic: PiSessionDiagnostic) => void;\n\n/** @public */\nexport interface PiCustomToolExecutionContext {\n\t/** Pi's identity for this exact invocation; stable across the paused call. @public */\n\ttoolCallId: string;\n\t/** Aborted when the active turn is stopped or torn down. @public */\n\tsignal: AbortSignal;\n\t/** Pause model-execution budgets while this custom tool awaits durable operator input. @internal */\n\tsuspendPromptGuards?: () => () => void;\n}\n\n/** @public */\nexport interface PiCustomTool {\n\t/** @public */\n\tname: string;\n\t/** @internal */\n\tdescription: string;\n\t/** @internal */\n\tparameters: Record<string, unknown>;\n\t/** @internal */\n\texecutionMode?: \"sequential\" | \"parallel\";\n\t/** @public */\n\texecute(args: Record<string, unknown>, context?: PiCustomToolExecutionContext): Promise<unknown>;\n}\n\n/** @internal */\nexport interface PiUsageData extends UsageTokenCounts {\n\t/** @internal */\n\tcost: UsageCostSnapshot;\n\t/** @internal */\n\tcacheHitRate: number;\n}\n\n/** @internal */\nexport interface PiRunDetails {\n\t/** @internal */\n\tloadedAgentsFiles: Array<{\n\t\t/** @internal */\n\t\tpath: string;\n\t\t/** @internal */\n\t\tsizeBytes: number;\n\t}>;\n\t/** @internal */\n\tloadedSkills: Array<{\n\t\t/** @internal */\n\t\tname: string;\n\t\t/** @internal */\n\t\tpath: string;\n\t}>;\n\t/** @internal */\n\tavailableToolNames: string[];\n}\n\n/** @internal */\nexport type ProcessCustomTool = PiCustomTool;\n\n/** @public */\nexport interface PiCustomMessageInput {\n\t/** @internal */\n\tcontent: string;\n\t/** @internal */\n\tdetails: unknown;\n\t/** @internal */\n\tdisplay?: boolean;\n}\n\n/** @internal */\nexport type PiTerminalAcknowledgementState =\n\t| \"open\"\n\t| \"outcome_accepted\"\n\t| \"acknowledgement_succeeded\"\n\t| \"acknowledgement_failed_ignored\";\n\n/** @internal */\nexport interface PiTerminalAcknowledgementControl {\n\t/** @internal */\n\treadonly timeoutMs: number;\n\t/** @internal */\n\tstate(): PiTerminalAcknowledgementState;\n\t/** @internal */\n\tisOperatorAbortRequested(): boolean;\n\t/** @internal */\n\tmarkSucceeded(): void;\n\t/** @internal */\n\tmarkFailed(reason: string): void;\n}\n\n/** @public */\nexport interface PiPromptOptions {\n\t/** @public */\n\ttools?: readonly PiCustomTool[];\n\t/** @internal */\n\tactiveTools?: readonly string[];\n\t/** @internal Runtime-only hook used by the worker Pi adapter before a tool executes. */\n\tshouldBlockToolCall?: (toolName: string) => string | null;\n\t/** @internal Guard suspension used by durable interactive tools. */\n\tsuspendPromptGuards?: () => () => void;\n\t/** @internal Runtime-only terminal outcome acknowledgement state. */\n\tterminalAcknowledgement?: PiTerminalAcknowledgementControl;\n}\n\n/** @public */\nexport interface PiTreeHandle {\n\t/** @internal */\n\treadonly sessionId: string;\n\t/** @internal */\n\treadonly treeFile: string;\n\t/** @internal */\n\treadonly isResumed: boolean;\n\n\t/** @internal */\n\tgetRunDetails(): PiRunDetails;\n\t/** @internal */\n\tgetLeafId(): string | null;\n\t/** @internal */\n\tgetEntry(id: string): PiTreeEntry | undefined;\n\t/** @internal */\n\tgetBranch(fromId?: string): PiTreeEntry[];\n\t/** @internal */\n\tgetChildren(parentId: string): PiTreeEntry[];\n\t/** @internal */\n\tgetTree(): PiTreeNode[];\n\t/** @internal */\n\tbranch(entryId: string): void | Promise<void>;\n\t/** @internal */\n\tbranchFromRoot(): void | Promise<void>;\n\t/** @internal */\n\tresetLeaf(): void | Promise<void>;\n\t/**\n\t * Compact the current Pi context. `details` is persisted with the resulting\n\t * compaction entry, but deliberately remains outside model context.\n\t */\n\t/** @internal */\n\tcompact?(customInstructions?: string, details?: unknown): Promise<unknown>;\n\t/** @public */\n\tprompt(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;\n\t/** @public */\n\tpromptLiteral(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;\n\t/** @public */\n\tpromptCustom(\n\t\tinput: PiCustomMessageInput,\n\t\toptions?: PiPromptOptions,\n\t): Promise<PiTurnExecutionResult>;\n\t/** @public */\n\tcontinueTurn(options?: PiPromptOptions): Promise<PiTurnExecutionResult>;\n\t/** @internal */\n\tappendCustomMessage?(input: PiCustomMessageInput): Promise<string>;\n\t/** @internal */\n\tsteer(text: string): Promise<void>;\n\t/** @internal */\n\tabortTurn(): Promise<void>;\n\t/** @internal */\n\tsubscribe(handler: PiEventHandler): () => void;\n\t/** @internal */\n\tsubscribeDiagnostics?(handler: PiSessionDiagnosticHandler): () => void;\n\t/** @internal */\n\tclose(): Promise<void>;\n}\n\n/** @public */\nexport const TURN_CONTEXT_MODES = [\"full\", \"compacted\", \"fresh\", \"fresh_seeded\"] as const;\n/** @public */\nexport type TurnContextMode = (typeof TURN_CONTEXT_MODES)[number];\n\n/** @public */\nexport const TURN_COMPLETION_MODES = [\"turn_end\"] as const;\n/** @public */\nexport type TurnCompletionMode = (typeof TURN_COMPLETION_MODES)[number];\n\n/** @public */\nexport type TurnBranchType = ProcessTurnRecordPathType;\n\n/** @public */\nexport interface TurnResultMarkdownNoneBehavior {\n\t/** @internal */\n\tmode: \"none\";\n}\n\n/** @public */\nexport interface TurnResultMarkdownAssistantOutputBehavior {\n\t/** @internal */\n\tmode: \"assistant_output\";\n\t/** @internal */\n\trequired?: boolean;\n}\n\n/** @public */\nexport interface TurnResultMarkdownToolCallBehavior {\n\t/** @internal */\n\tmode: \"tool_call\";\n\t/** @internal */\n\ttoolName: string;\n\t/** @internal */\n\tsource?: \"arguments\" | \"result\";\n\t/** @internal */\n\tpath: string;\n\t/** @internal */\n\trequired?: boolean;\n}\n\n/** @public */\nexport interface TurnResultMarkdownOutcomeToolArgumentBehavior {\n\t/** @internal */\n\tmode: \"outcome_tool_argument\";\n\t/** @internal */\n\tparameterName: string;\n\t/** @internal */\n\trequired?: boolean;\n}\n\n/** @public */\nexport type TurnResultMarkdownBehavior =\n\t| TurnResultMarkdownNoneBehavior\n\t| TurnResultMarkdownAssistantOutputBehavior\n\t| TurnResultMarkdownToolCallBehavior\n\t| TurnResultMarkdownOutcomeToolArgumentBehavior;\n\n/** @public */\nexport type TurnAcceptanceState = DomainTurnAcceptanceState;\n\n/** @public */\nexport interface ProcessActionSchedulingFixedTurnPreview {\n\t/** @public */\n\tkind: \"fixed_turn\";\n\t/** @public */\n\tturnId: TurnId | null;\n}\n\n/** @public */\nexport interface ProcessActionSchedulingTriggerPreview {\n\t/** @public */\n\tkind: \"trigger\";\n\t/** @internal */\n\ttrigger: string;\n}\n\n/** @public */\nexport interface ProcessActionSchedulingTerminalPreview {\n\t/** @public */\n\tkind: \"terminal\";\n\t/** @internal */\n\tlifecycleStatus: ProcessTurnTerminalLifecycleStatus;\n}\n\n/** @public */\nexport type ProcessActionSchedulingPreview =\n\t| ProcessActionSchedulingFixedTurnPreview\n\t| ProcessActionSchedulingTriggerPreview\n\t| ProcessActionSchedulingTerminalPreview;\n\n/** @public */\nexport type ProcessActionPreviewDefinition = ProcessActionSchedulingPreview;\n\n/** @internal */\nexport interface ProcessActionSchedulingDefinition {\n\t/** @internal */\n\tpreview: ProcessActionSchedulingPreview;\n}\n\n/** @internal */\nexport interface HumanTurnActionView {\n\t/** @internal */\n\tactionId: string;\n\t/** @internal */\n\tacceptanceState: TurnAcceptanceState;\n\t/** @internal */\n\tlabel?: string;\n\t/** @internal */\n\tdescription?: string;\n\t/** @internal */\n\tpreview?: ProcessActionPreviewDefinition;\n\t/** @internal */\n\tscheduling?: ProcessActionSchedulingDefinition;\n}\n\n/** @internal */\nexport interface HumanTurnNotesField {\n\t/** @internal */\n\tid: string;\n\t/** @internal */\n\tlabel: string;\n\t/** @internal */\n\tdescription?: string;\n\t/** @internal */\n\tplaceholder?: string;\n\t/** @internal */\n\trequired?: boolean;\n}\n\n/** @internal */\nexport interface HumanTurnExternalTrigger {\n\t/** @internal */\n\tid: string;\n\t/** @internal */\n\tactionId: string;\n\t/** @internal */\n\tlabel: string;\n\t/** @internal */\n\tdescription: string;\n}\n\n/** @internal */\nexport interface HumanTurnExternalActionView {\n\t/** Process-local arming id exposed to providers and UI. @internal */\n\tid: string;\n\t/** @internal */\n\texternalActionId: string;\n\t/** @internal */\n\tsourceKind: string;\n\t/** @internal */\n\tlabel: string | null;\n\t/** @internal */\n\tdescription: string | null;\n}\n\n/** @internal */\nexport interface EventBus<TEventMap extends object = Record<string, unknown>> {\n\t/** @internal */\n\temit<K extends keyof TEventMap & string>(event: K, data: TEventMap[K]): void;\n\t/** @internal */\n\ton<K extends keyof TEventMap & string>(\n\t\tevent: K,\n\t\thandler: (data: TEventMap[K]) => void | Promise<void>,\n\t): void;\n\t/** @internal */\n\toff<K extends keyof TEventMap & string>(\n\t\tevent: K,\n\t\thandler: (data: TEventMap[K]) => void | Promise<void>,\n\t): void;\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,OAAO,cAAc;;;ACqBd,IAAM,yBAAyB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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