@yaag/runtime 0.23.0 → 0.25.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.
@@ -1,6 +1,11 @@
1
1
  import { REPORT_RESULT_EXTENSION_PATH, REPORT_RESULT_TOOL_NAME } from "../ask-contract/index.ts";
2
2
  import type { AgentProgress } from "../contract/index.ts";
3
3
  import { isThinkingLevel, type ThinkingLevel } from "../model/index.ts";
4
+ import {
5
+ AGENT_PROMPT_EXTENSION_PATH,
6
+ promptNeedsPiDefault,
7
+ SYSTEM_PROMPT_ENV,
8
+ } from "../system-prompt/index.ts";
4
9
  import { SYSTEM_PROMPT_RECORDER_EXTENSION_PATH } from "./system-prompt-recorder.ts";
5
10
  import type {
6
11
  AgentStats,
@@ -17,11 +22,17 @@ export type { AgentProgress } from "../contract/index.ts";
17
22
  export function piCommand(options: OpenOptions, toolProbeExtensionPath?: string): string[] {
18
23
  const cmd = ["pi", "--mode", "rpc"];
19
24
  if (options.model) cmd.push("--model", options.model);
20
- if (options.systemPrompt) cmd.push("--system-prompt", options.systemPrompt);
21
- if (options.thinking !== undefined) cmd.push("--thinking", options.thinking);
22
- if (options.appendSystemPrompt !== undefined) {
23
- cmd.push("--append-system-prompt", options.appendSystemPrompt);
25
+ // A prompt that asks for pi's own default text travels in the environment
26
+ // instead: with no `--system-prompt`, pi builds its default prompt and the
27
+ // prompt extension receives it as `event.systemPrompt` (ADR-0063).
28
+ if (options.systemPrompt && !promptNeedsPiDefault(options.systemPrompt)) {
29
+ cmd.push("--system-prompt", options.systemPrompt);
24
30
  }
31
+ if (options.thinking !== undefined) cmd.push("--thinking", options.thinking);
32
+ // No `--append-system-prompt`: the program's text no longer travels in argv.
33
+ // `append-env.ts` puts it in `YAAG_APPEND_SYSTEM_PROMPT` instead, so pi's
34
+ // flag precedence leaves its own `APPEND_SYSTEM.md` discovery alone and both
35
+ // texts reach the prompt in their own slots (ADR-0059, ADR-0061).
25
36
  appendCapabilities(cmd, options, toolProbeExtensionPath);
26
37
  if (options.sessionDir) cmd.push("--session-dir", options.sessionDir);
27
38
  // `--session` and `--fork` are mutually exclusive in pi, and a resume is the
@@ -32,6 +43,18 @@ export function piCommand(options: OpenOptions, toolProbeExtensionPath?: string)
32
43
  return cmd;
33
44
  }
34
45
 
46
+ /**
47
+ * The environment yaag adds to one Agent process.
48
+ *
49
+ * `YAAG_SYSTEM_PROMPT` is always written, empty when the prompt travels on the
50
+ * flag, so a nested pi can never inherit a stale prompt from its parent.
51
+ */
52
+ export function piEnv(options: OpenOptions): Record<string, string> {
53
+ const prompt = options.systemPrompt;
54
+ const needsEnv = typeof prompt === "string" && prompt !== "" && promptNeedsPiDefault(prompt);
55
+ return { [SYSTEM_PROMPT_ENV]: needsEnv ? prompt : "" };
56
+ }
57
+
35
58
  function appendCapabilities(
36
59
  cmd: string[],
37
60
  options: OpenOptions,
@@ -48,6 +71,17 @@ function appendCapabilities(
48
71
  if (hermetic) {
49
72
  cmd.push("--no-extensions", "--no-context-files", "--no-prompt-templates");
50
73
  }
74
+ // Load order is fixed (ADR-0063): the prompt extension first, then the
75
+ // program extensions, `report_result`, the tool probe, and the recorder last.
76
+ // `before_agent_start` handlers chain in load order, so first means a program
77
+ // extension appends to the already assembled Agent System Prompt.
78
+ //
79
+ // It means the extension receives pi's own default prompt only on the
80
+ // environment channel above: with `--system-prompt` pi takes its
81
+ // `customPrompt` branch, which never builds the guideline prompt (pi
82
+ // `dist/core/system-prompt.js:15-33`). See the header of
83
+ // `agent-prompt-extension.ts` for both channels.
84
+ cmd.push("-e", AGENT_PROMPT_EXTENSION_PATH);
51
85
  for (const path of options.resolvedExtensionPaths ?? []) cmd.push("-e", path);
52
86
  // Every Agent carries the report-result tool, because an Ask declares its
53
87
  // output schema long after the process started and pi loads extensions only
@@ -201,7 +201,10 @@ export interface OpenOptions {
201
201
  readonly inherit?: boolean;
202
202
  /** Deterministic process-start thinking level; omission preserves pi's default. */
203
203
  readonly thinking?: ThinkingLevel;
204
- /** Deterministic process-start text appended to pi's system prompt. */
204
+ /**
205
+ * The text the `programAppend` slot of the Agent System Prompt prints,
206
+ * delivered to the Agent through the environment (ADR-0061).
207
+ */
205
208
  readonly appendSystemPrompt?: string;
206
209
  /** Tool allowlist; an empty list disables all tools. */
207
210
  readonly tools?: readonly string[];
package/src/types.ts CHANGED
@@ -11,10 +11,18 @@ export type {
11
11
  CompactionResult,
12
12
  ForkOptions,
13
13
  Handle,
14
+ LiteralPromptText,
14
15
  ModelError,
16
+ PromptAudience,
17
+ PromptText,
15
18
  ResolvedSpawnOptions,
16
19
  SpawnOptions,
17
20
  SpawnOverrides,
18
21
  StructuredAskOptions,
22
+ SystemPromptAgent,
23
+ SystemPromptBuilder,
24
+ SystemPromptContext,
25
+ SystemPromptDefinition,
26
+ SystemPromptInput,
19
27
  ThinkingLevel,
20
28
  } from "./contract/index.ts";