@linxiraos/pi-agent-core 1.4.4 → 1.4.7

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/CHANGELOG.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.4.4] - 2026-10-26
3
+ ## [1.4.7] - 2026-10-30
4
4
 
5
- - Released as part of Zeta 1.4.4; no package-specific user-visible changes.
5
+ - Synced with upstream OMP v18.14.0; no package-specific user-visible changes.
6
6
 
7
7
  ## [9.2.2] - 2026-01-31
8
8
 
@@ -134,6 +134,25 @@
134
134
 
135
135
  Initial release under @oh-my-pi scope. See previous releases at [badlogic/pi-mono](https://github.com/badlogic/pi-mono).
136
136
 
137
+ ## [1.4.6] - 2026-10-28
138
+
139
+ ### Breaking Changes
140
+
141
+ - Removed the Bun event-loop workaround utilities from `@oh-my-pi/pi-agent-core/utils/yield`; agent loops no longer insert cooperative sleeps while streaming or between tool calls.
142
+
143
+ ### Added
144
+
145
+ - Added `AgentTool.approvalRestrictionPaths` so tools can report the paths they read, allowing restricted-folder approvals to cover those paths without remembering approval separately for each path.
146
+ - Added `Agent.logContext`, which adds custom context fields to every log record written during an agent run.
147
+
148
+ ## [1.4.5] - 2026-10-28
149
+
150
+ - Synced with upstream OMP v18.13.2: a subagent's final report is no longer consumed as its reply to a peer message that arrived as the run finished; same-workspace peers can message each other.
151
+
152
+ ## [1.4.4] - 2026-10-26
153
+
154
+ - Released as part of Zeta 1.4.4; no package-specific user-visible changes.
155
+
137
156
  ## [1.4.3] - 2026-10-25
138
157
 
139
158
  - Released as part of Zeta 1.4.3; no package-specific user-visible changes.
@@ -3,7 +3,7 @@ import type { Dialect } from "@linxiraos/pi-ai/dialect";
3
3
  import type { HarmonyAuditEvent } from "@linxiraos/pi-ai/utils/harmony-leak";
4
4
  import type { AppendOnlyContextManager } from "./append-only-context.js";
5
5
  import { Tokenizer } from "./tokenizer.js";
6
- import type { AgentBeforeModelCall, AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, AgentState, AgentTool, AgentToolContext, AgentTurnEndContext, AsideMessage, PrepareQueuedMessages, SpeculativeToolExecutionConfig, StreamFn, ToolCallContext, ToolChoiceDirective } from "./types.js";
6
+ import type { AgentBeforeModelCall, AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, AgentState, AgentTool, AgentToolContext, AgentTurnEndContext, AsideBoundary, AsideMessage, PrepareQueuedMessages, SpeculativeToolExecutionConfig, StreamFn, ToolCallContext, ToolChoiceDirective } from "./types.js";
7
7
  export declare class AgentBusyError extends Error {
8
8
  constructor(message?: string);
9
9
  }
@@ -240,6 +240,8 @@ export interface AgentPromptOptions {
240
240
  }
241
241
  export declare class Agent {
242
242
  #private;
243
+ /** True while this unfinished turn is safely parked by the process pause gate. */
244
+ get isPaused(): boolean;
243
245
  streamFn: StreamFn;
244
246
  getApiKey?: (model: Model) => Promise<ApiKey | undefined> | ApiKey | undefined;
245
247
  /** Prepare actual queue deliveries after dequeue gates; commit runs only while ownership remains valid. */
@@ -293,6 +295,11 @@ export declare class Agent {
293
295
  * Set the prompt cache key forwarded to providers.
294
296
  */
295
297
  set promptCacheKey(value: string | undefined);
298
+ /**
299
+ * Fields added to every log record written while this agent runs (the
300
+ * owning session's `sessionId`), so in-process agents' records stay apart.
301
+ */
302
+ logContext: Readonly<Record<string, unknown>> | undefined;
296
303
  /**
297
304
  * Static metadata forwarded to every API request when no resolver is installed
298
305
  * (e.g. `metadata.user_id` for Anthropic session attribution). Setting this
@@ -377,6 +384,13 @@ export declare class Agent {
377
384
  /** Strip tool descriptions from provider-bound specs; read per request. */
378
385
  get pruneToolDescriptions(): boolean;
379
386
  set pruneToolDescriptions(value: boolean);
387
+ /**
388
+ * Whether requests to `model` actually ship description-stripped tool specs.
389
+ * Owned dialects render full definitions in-band, so they never prune; the
390
+ * loop applies the same rule (`pruneToolDescriptions && !ownedDialect`).
391
+ * Context accounting reads this instead of the raw setting.
392
+ */
393
+ prunesToolDescriptions(model: Model | undefined): boolean;
380
394
  /** Inject/strip the intent field on tool calls; applies from the next prompt run. */
381
395
  get intentTracing(): boolean;
382
396
  set intentTracing(value: boolean);
@@ -469,7 +483,7 @@ export declare class Agent {
469
483
  * aborts foreground tools; an interruptible `wait` may end early through the
470
484
  * peek hooks. See `AgentLoopConfig.getAsideMessages`.
471
485
  */
472
- setAsideMessageProvider(fn: (() => AsideMessage[] | Promise<AsideMessage[]>) | undefined): void;
486
+ setAsideMessageProvider(fn: ((boundary: AsideBoundary) => AsideMessage[] | Promise<AsideMessage[]>) | undefined): void;
473
487
  emitExternalEvent(event: AgentEvent): void;
474
488
  setSystemPrompt(v: string[] | string): void;
475
489
  setModel(model: Model): void;
@@ -7,7 +7,8 @@
7
7
  * compaction item as replacement history.
8
8
  */
9
9
  import type { Api, CodexCompactionContext, FetchImpl, Model, ProviderSessionState } from "@linxiraos/pi-ai";
10
- import { type OpenAICodexCompactionBody } from "@linxiraos/pi-ai/providers/openai-codex-responses";
10
+ import type { OpenAICodexCompactionBody } from "@linxiraos/pi-ai/providers/openai-codex-responses";
11
+ import type { CatalogPolicyInputs } from "@linxiraos/pi-catalog/types";
11
12
  /** Retained-message budget Codex uses after streamed V2 compaction. */
12
13
  export declare const V2_RETAINED_MESSAGE_TOKEN_BUDGET = 64000;
13
14
  /** Max retries for V2 streaming compaction on transient stream errors. */
@@ -46,6 +47,15 @@ export declare function getCompactionV2Endpoint(model: Model): string | undefine
46
47
  export declare function shouldUseCompactionV2Streaming(model: Model): model is Model<"openai-responses" | "azure-openai-responses" | "openai-codex-responses">;
47
48
  /** APIs that speak the OpenAI Responses compaction protocol (V1 `/responses/compact` and V2 streaming). */
48
49
  export declare function isOpenAiRemoteCompactionApi(api: Api | undefined): boolean;
50
+ /**
51
+ * Catalog-policy view of a remote compaction request (V1 and V2): the
52
+ * effective adapter (`remoteCompaction.api`) and the wire id the body sends
53
+ * (`remoteCompaction.model`). Under a model override the active lane's
54
+ * `requestModelId` and thinking classification describe a model that never
55
+ * reaches the wire, so they are dropped; `reasoning` stays because the
56
+ * compaction body derives its reasoning config from the active model.
57
+ */
58
+ export declare function remoteCompactionPolicyModel(model: Model): CatalogPolicyInputs;
49
59
  /** Clamp the retained-message budget to Codex's known-safe 64K ceiling. */
50
60
  export declare function resolveCompactionV2RetainedMessageBudget(value: number | undefined): number;
51
61
  /** Build a V2 streaming compaction request from Responses-native history. */
@@ -67,6 +67,18 @@ export interface CompactionSettings {
67
67
  }
68
68
  /** Reserve applied when {@link CompactionSettings.reserveTokens} is unset. */
69
69
  export declare const DEFAULT_RESERVE_TOKENS = 16384;
70
+ /**
71
+ * Hysteresis band under the compaction trigger. Maintenance counts as having
72
+ * resolved threshold pressure only when residual context lands at or below
73
+ * `COMPACTION_RECOVERY_BAND × threshold`. Re-checking against the raw threshold
74
+ * lets a pass keep reclaiming a trickle of the previous turn's output and land
75
+ * just under the line every turn, sustaining the auto-continue dead loop
76
+ * reported in #2275; the same band stops the context-full / snapcompact tail
77
+ * from re-firing on a history whose single most-recent kept turn already
78
+ * exceeds the threshold. {@link prepareCompaction} sizes the kept tail to land
79
+ * inside it.
80
+ */
81
+ export declare const COMPACTION_RECOVERY_BAND = 0.8;
70
82
  /**
71
83
  * Hard ceiling on a generated compaction summary.
72
84
  *
@@ -231,8 +243,15 @@ export interface SummaryOptions {
231
243
  thinkingLevel?: ThinkingLevel;
232
244
  /** Session routing key for remote compaction transports with sticky provider sessions. */
233
245
  sessionId?: string;
234
- /** Prompt-cache key for remote compaction transports that support provider prefix caching. */
246
+ /** Prompt-cache key for conventional summary requests, gated against the summarizing model. */
235
247
  promptCacheKey?: string;
248
+ /**
249
+ * Prompt-cache key for remote compaction requests, gated against the request
250
+ * they send (`remoteCompaction.api`/`model` override, see
251
+ * `remoteCompactionPolicyModel`). Defaults to {@link promptCacheKey} only when
252
+ * omitted; an explicit `undefined` means the remote target gets no key.
253
+ */
254
+ remotePromptCacheKey?: string;
236
255
  /** Mutable provider state used to keep Codex compaction on the live session identity. */
237
256
  providerSessionState?: Map<string, ProviderSessionState>;
238
257
  /** Whether Codex remote compaction should prefer the provider WebSocket transport. */
@@ -30,8 +30,8 @@ export declare const REMOTE_COMPACTION_TIMEOUT_MS = 300000;
30
30
  export declare const CONTEXT_WINDOW_TRUNCATED_OUTPUT_MESSAGE: string;
31
31
  /**
32
32
  * Tokens of stored Responses replacement history. Retained `input_image` parts
33
- * count at their image estimate rather than as base64 text; everything else,
34
- * opaque compaction state included, counts as decoded text.
33
+ * count at their image estimate, not their base64 size. Opaque encrypted state
34
+ * stays excluded, matching ordinary message estimates and remote fit checks.
35
35
  */
36
36
  export declare function countResponsesHistoryTokens(items: unknown[], tokenizer: Tokenizer): number;
37
37
  export interface TrimRemoteCompactionInputResult {
@@ -87,6 +87,13 @@ export interface OpenAiRemoteCompactionRequest {
87
87
  model: string;
88
88
  input: Array<Record<string, unknown>>;
89
89
  instructions: string;
90
+ /**
91
+ * Responses body cache identity. Mirrors the V2 body: the explicit
92
+ * prompt-cache key when supplied (normalized to the 64-char wire limit),
93
+ * else the session-derived cache id — retention-gated through
94
+ * `getOpenAIPromptCacheKey`; absent when it resolves to nothing.
95
+ */
96
+ prompt_cache_key?: string;
90
97
  reasoning?: {
91
98
  context?: string;
92
99
  [key: string]: unknown;
@@ -124,6 +131,13 @@ export declare function requestOpenAiRemoteCompaction(model: Model, apiKey: stri
124
131
  fetch?: FetchImpl;
125
132
  timeoutMs?: number;
126
133
  sessionId?: string;
134
+ /**
135
+ * Explicit prompt-cache identity. Feeds the Go family affinity header
136
+ * (`x-opencode-session`) and the Responses body `prompt_cache_key`
137
+ * under the same KDL gate as the V2 request; an absent/empty key keeps
138
+ * the child conversation id.
139
+ */
140
+ promptCacheKey?: string;
127
141
  providerSessionState?: Map<string, ProviderSessionState>;
128
142
  codexCompaction?: CodexCompactionContext;
129
143
  /** Forwarded to {@link trimRemoteCompactionInputToContextWindow}. */
@@ -15,4 +15,3 @@ export * from "./tool-context.js";
15
15
  export * from "./tokenizer.js";
16
16
  export * from "./tool-arguments.js";
17
17
  export * from "./types.js";
18
- export * from "./utils/yield.js";
@@ -23,6 +23,9 @@ export declare class SpeculativeOperationCoordinator {
23
23
  #private;
24
24
  readonly config: SpeculativeToolExecutionConfig;
25
25
  readonly environment?: CoordinatorEnvironment | undefined;
26
+ /** Observer of existing speculative execution draining; no separate work ledger. */
27
+ onIdle?: () => void;
28
+ get isRunning(): boolean;
26
29
  constructor(config: SpeculativeToolExecutionConfig, environment?: CoordinatorEnvironment | undefined);
27
30
  get maxInFlight(): number;
28
31
  get size(): number;
@@ -9,6 +9,7 @@ export declare function tokenizerEncodingForModel(model: Pick<Model, "tokenizer"
9
9
  type TokenizerModel = Pick<Model, "tokenizer"> & snapcompact.ShapeTarget & {
10
10
  compat?: Model["compat"];
11
11
  thinking?: Model["thinking"];
12
+ reasoning?: boolean;
12
13
  };
13
14
  /** Identity of the reader whose replayed reasoning a {@link Tokenizer} counts; equal keys count it alike. */
14
15
  export declare function reasoningReplayKey(model: TokenizerModel | null | undefined): string;
@@ -33,6 +33,8 @@ export type CommittableAsideMessage = AgentMessage & {
33
33
  * (e.g. dropping late diagnostics a newer edit superseded).
34
34
  */
35
35
  export type AsideMessage = CommittableAsideMessage | (() => CommittableAsideMessage | null);
36
+ /** Where the loop polls asides: after a tool batch (`"work"`) or after a turn without tool calls (`"stop"`). */
37
+ export type AsideBoundary = "work" | "stop";
36
38
  export interface AgentTurnEndContext {
37
39
  /** Assistant/user message that just completed this turn boundary. */
38
40
  message: AgentMessage;
@@ -124,6 +126,8 @@ export interface SteeringQueueState {
124
126
  */
125
127
  export interface AgentLoopConfig extends SimpleStreamOptions {
126
128
  model: Model;
129
+ /** Reports whether this loop has reached a safe process-pause boundary. */
130
+ onPauseChange?: (paused: boolean) => void;
127
131
  /**
128
132
  * When to interrupt tool execution for steering messages.
129
133
  * - "immediate" = cut interruptible waits short and raise the cooperative
@@ -219,7 +223,7 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
219
223
  *
220
224
  * Polled while a tool batch runs (in "wait" mode, only when the batch holds an
221
225
  * interruptible tool) to decide whether to abort in-flight and skip
222
- * not-yet-started *interruptible* waits;
226
+ * not-yet-started *interruptible* waits, unless they handle queued interrupts;
223
227
  * every other already-emitted call still executes and the message injects
224
228
  * at the batch boundary. The queue keeps
225
229
  * owning its messages until the loop reaches the next injection boundary and
@@ -308,8 +312,12 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
308
312
  * should reach the model between requests without waiting for the agent to
309
313
  * fully stop. Returned messages are appended to the context with normal
310
314
  * message events and keep the loop running so the model can react.
315
+ *
316
+ * `boundary` is `"work"` after a tool batch and `"stop"` when the model ended
317
+ * its turn without tool calls; a provider may hold back messages that should
318
+ * not extend a finished turn.
311
319
  */
312
- getAsideMessages?: () => Promise<AsideMessage[]>;
320
+ getAsideMessages?: (boundary: AsideBoundary) => Promise<AsideMessage[]>;
313
321
  /**
314
322
  * Hook fired right before the loop would exit.
315
323
  *
@@ -1048,6 +1056,13 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
1048
1056
  * batch boundary. Honored in both `interruptMode`s.
1049
1057
  */
1050
1058
  interruptible?: boolean | ((args: Partial<Static<TParameters>>) => boolean);
1059
+ /**
1060
+ * An interruptible tool can execute with an already-aborted
1061
+ * `TOOL_INTERRUPT_ABORT_REASON` signal to drain caller-owned wake events.
1062
+ * It must not block when that signal is aborted. External/user cancellation
1063
+ * still prevents execution. Omitted tools keep the usual pre-start skip.
1064
+ */
1065
+ handlesToolInterrupt?: boolean;
1051
1066
  /**
1052
1067
  * Controls how the INTENT_FIELD (`i`) is handled for this tool.
1053
1068
  * - `"require"` (default): `i` is injected and required in the parameter schema.
@@ -1096,6 +1111,11 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
1096
1111
  * approving the call can record them. Omit it (or return `undefined`) and the call prompts by tier.
1097
1112
  */
1098
1113
  approvalCacheTargets?: (args: unknown) => readonly string[] | undefined;
1114
+ /**
1115
+ * Paths a call reads beyond its working directory, matched against restricted folders when it
1116
+ * reports no `approvalCacheTargets`. Unlike cache targets they never key a remembered grant.
1117
+ */
1118
+ approvalRestrictionPaths?: (args: unknown) => readonly string[] | undefined;
1099
1119
  /** The main execution callback for this tool. */
1100
1120
  execute: AgentToolExecFn<TParameters, TDetails, TTheme>;
1101
1121
  /** Optional custom rendering for tool call display (returns UI component) */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@linxiraos/pi-agent-core",
4
- "version": "1.4.4",
4
+ "version": "1.4.7",
5
5
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
6
6
  "homepage": "https://linxira-os.github.io/zeta/",
7
7
  "author": "Linxira-OS",
@@ -35,22 +35,22 @@
35
35
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
36
36
  },
37
37
  "dependencies": {
38
- "@linxiraos/pi-ai": "1.4.4",
39
- "@linxiraos/pi-catalog": "1.4.4",
40
- "@linxiraos/pi-natives": "1.4.4",
41
- "@linxiraos/pi-utils": "1.4.4",
42
- "@linxiraos/pi-wire": "1.4.4",
43
- "@linxiraos/pi-snapcompact": "1.4.4",
38
+ "@linxiraos/pi-ai": "1.4.7",
39
+ "@linxiraos/pi-catalog": "1.4.7",
40
+ "@linxiraos/pi-natives": "1.4.7",
41
+ "@linxiraos/pi-utils": "1.4.7",
42
+ "@linxiraos/pi-wire": "1.4.7",
43
+ "@linxiraos/pi-snapcompact": "1.4.7",
44
44
  "@opentelemetry/api": "^1.9.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@linxiraos/pi-omptype": "1.4.4",
47
+ "@linxiraos/pi-omptype": "1.4.7",
48
48
  "@opentelemetry/context-async-hooks": "^2.9.0",
49
49
  "@opentelemetry/sdk-trace-base": "^2.9.0",
50
- "@types/bun": "1.4.3"
50
+ "@types/bun": "1.4.4"
51
51
  },
52
52
  "engines": {
53
- "bun": ">=1.3.14"
53
+ "bun": ">=1.4.4"
54
54
  },
55
55
  "files": [
56
56
  "src",