@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.
- package/package.json +1 -1
- package/src/agent/fork.ts +7 -0
- package/src/agent/index.ts +1 -0
- package/src/agent/spawn-open.ts +24 -5
- package/src/agent/spawn-request.ts +123 -3
- package/src/agent/spawn.ts +13 -7
- package/src/agent/spawnable-definition.ts +9 -0
- package/src/ask/ask-hash.ts +7 -0
- package/src/catalog/index.ts +5 -3
- package/src/catalog/resolve.ts +184 -0
- package/src/contract/agent-policy.ts +15 -4
- package/src/contract/catalog-resolve.ts +33 -0
- package/src/contract/error-codes.ts +4 -1
- package/src/contract/index.ts +20 -2
- package/src/contract/spawn-options.ts +7 -1
- package/src/contract/system-prompt.ts +88 -0
- package/src/errors.ts +8 -2
- package/src/index.ts +20 -1
- package/src/public-api.ts +17 -0
- package/src/run/run-context.ts +8 -1
- package/src/run/run.ts +3 -0
- package/src/system-prompt/agent-prompt-extension.ts +337 -0
- package/src/system-prompt/agent-prompt.ts +15 -0
- package/src/system-prompt/agent-system-prompt.ts +90 -0
- package/src/system-prompt/append-channel.ts +69 -0
- package/src/system-prompt/define-system-prompt.ts +112 -0
- package/src/system-prompt/index.ts +48 -0
- package/src/system-prompt/prompt-guards.ts +60 -0
- package/src/system-prompt/render-sentinel.ts +75 -0
- package/src/transport/append-env.ts +69 -0
- package/src/transport/index.ts +2 -0
- package/src/transport/live-transport.ts +50 -26
- package/src/transport/pi-state.ts +38 -4
- package/src/transport/transport.ts +4 -1
- package/src/types.ts +8 -0
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
/**
|
|
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";
|