@linxiraos/pi-agent-core 1.5.13 → 1.5.15

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 (46) hide show
  1. package/CHANGELOG.md +51 -47
  2. package/README.md +7 -9
  3. package/THIRD-PARTY-NOTICES.txt +1 -1
  4. package/dist/types/agent-loop.d.ts +22 -0
  5. package/dist/types/agent.d.ts +21 -10
  6. package/dist/types/compaction/anthropic.d.ts +5 -6
  7. package/dist/types/compaction/bedrock.d.ts +3 -2
  8. package/dist/types/compaction/compaction-v2-streaming.d.ts +7 -3
  9. package/dist/types/compaction/compaction.d.ts +14 -2
  10. package/dist/types/compaction/entries.d.ts +2 -0
  11. package/dist/types/compaction/messages.d.ts +5 -2
  12. package/dist/types/compaction/openai.d.ts +3 -0
  13. package/dist/types/compaction/tool-protection.d.ts +1 -1
  14. package/dist/types/output-budget.d.ts +13 -0
  15. package/dist/types/replay-policy.d.ts +15 -1
  16. package/dist/types/sent-tool-definitions.d.ts +6 -3
  17. package/dist/types/telemetry.d.ts +2 -2
  18. package/dist/types/tool-arguments.d.ts +2 -1
  19. package/dist/types/types.d.ts +55 -26
  20. package/package.json +43 -43
  21. package/src/agent-loop.ts +120 -47
  22. package/src/agent.ts +103 -55
  23. package/src/compaction/anthropic.ts +26 -8
  24. package/src/compaction/bedrock.ts +6 -13
  25. package/src/compaction/branch-summarization.ts +2 -0
  26. package/src/compaction/compaction-v2-streaming.ts +22 -12
  27. package/src/compaction/compaction.ts +83 -7
  28. package/src/compaction/entries.ts +2 -0
  29. package/src/compaction/messages.ts +8 -2
  30. package/src/compaction/openai.ts +28 -24
  31. package/src/compaction/prompts/branch-summary.md +6 -0
  32. package/src/compaction/prompts/compaction-summary.md +9 -0
  33. package/src/compaction/prompts/compaction-turn-prefix.md +2 -0
  34. package/src/compaction/prompts/compaction-update-summary.md +10 -0
  35. package/src/compaction/prompts/handoff-document.md +9 -0
  36. package/src/compaction/prompts/handoff-summary-context.md +2 -1
  37. package/src/compaction/tool-protection.ts +8 -4
  38. package/src/compaction/utils.ts +1 -1
  39. package/src/output-budget.ts +31 -2
  40. package/src/replay-policy.ts +38 -3
  41. package/src/sent-tool-definitions.ts +20 -10
  42. package/src/speculative-execution.ts +29 -5
  43. package/src/telemetry.ts +31 -23
  44. package/src/tokenizer.ts +8 -1
  45. package/src/tool-arguments.ts +2 -1
  46. package/src/types.ts +54 -22
@@ -23,7 +23,7 @@
23
23
  * cheap pass-throughs.
24
24
  */
25
25
  import { type Api, type AssistantMessage, type Context, type Message, type Model, type OneshotRetryOptions, type ServiceTier, type SimpleStreamOptions, type StopReason, type ToolChoice, type Usage } from "@linxiraos/pi-ai";
26
- import { type Attributes, type AttributeValue, type Span, SpanKind, SpanStatusCode, type Tracer, trace } from "@opentelemetry/api";
26
+ import type { Attributes, AttributeValue, Span, SpanKind, SpanStatusCode, Tracer } from "@opentelemetry/api";
27
27
  import { AgentRunCollector, type AgentRunCoverage, type AgentRunSummary, type ToolStatus } from "./run-collector.js";
28
28
  import type { AgentTool } from "./types.js";
29
29
  /** Default tracer name. Override via {@link AgentTelemetryConfig.tracerName}. */
@@ -677,4 +677,4 @@ export declare function recordHandoff(telemetry: AgentTelemetry | undefined, opt
677
677
  */
678
678
  export declare function setSpanAttribute(span: Span | undefined, key: string, value: AttributeValue): void;
679
679
  /** Re-exports so consumers can write hooks without depending on @opentelemetry/api directly. */
680
- export { type Attributes, type Span, SpanKind, SpanStatusCode, type Tracer, trace };
680
+ export type { Attributes, Span, SpanKind, SpanStatusCode, Tracer };
@@ -5,7 +5,8 @@ import type { AgentTool } from "./types.js";
5
5
  * - `"parsed"`: a provider stream parsed the arguments, so `__parseError` is a
6
6
  * genuine parse-failure sentinel and is never handed to a tool.
7
7
  * - `"payload"`: the arguments are a payload the model wrote (eval tool bridge,
8
- * `xd://` device content), so those keys are forged and only stripped.
8
+ * a tool command line parsed into arguments), so those keys are forged and
9
+ * only stripped.
9
10
  */
10
11
  export type ToolArgumentSource = "parsed" | "payload";
11
12
  /**
@@ -1,4 +1,4 @@
1
- import type { ApiKey, AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Context, Effort, ImageContent, Message, Model, ServiceTier, SimpleStreamOptions, Static, streamSimple, TextContent, Tool, ToolCallProviderMetadata, ToolChoice, ToolResultMessage, ToolResultProviderMetadata, TSchema } from "@linxiraos/pi-ai";
1
+ import type { ApiKey, AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Context, CursorExecHandlers, Effort, ImageContent, Message, Model, ServiceTier, SimpleStreamOptions, Static, streamSimple, TextContent, Tool, ToolCallProviderMetadata, ToolChoice, ToolResultMessage, ToolResultProviderMetadata, TSchema } from "@linxiraos/pi-ai";
2
2
  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";
@@ -76,6 +76,11 @@ export type AgentPreModelCallResult = AgentPreModelCallStop | undefined;
76
76
  * request, or nothing to proceed; the signal aborts with the run.
77
77
  */
78
78
  export type AgentBeforeModelCall = (context: Context, signal?: AbortSignal) => AgentPreModelCallResult | void | Promise<AgentPreModelCallResult | void>;
79
+ /** The tool-call shape a {@link SoftToolRequirement} inspects. */
80
+ export type SoftToolCall = {
81
+ name: string;
82
+ arguments?: Record<string, unknown>;
83
+ };
79
84
  /**
80
85
  * A soft tool requirement: the host wants `toolName` called before the loop
81
86
  * runs other tools or yields, but WITHOUT paying the forced-`toolChoice` cost
@@ -101,13 +106,16 @@ export interface SoftToolRequirement {
101
106
  /**
102
107
  * Per-call compliance check: a turn satisfies the requirement only when every
103
108
  * tool call passes. Defaults to `name === toolName`. Lets a host demand a
104
- * specific invocation shape (e.g. `write` targeting a virtual device path)
105
- * instead of any call to `toolName`. Escalation still forces `toolName`.
109
+ * specific invocation shape (e.g. a `bash` call running a particular tool
110
+ * command) instead of any call to `toolName`. Escalation still forces `toolName`.
106
111
  */
107
- satisfies?(toolCall: {
108
- name: string;
109
- arguments?: Record<string, unknown>;
110
- }): boolean;
112
+ satisfies?(toolCall: SoftToolCall): boolean;
113
+ /**
114
+ * Skipped-result text for a call to `toolName` that fails `satisfies`. Without
115
+ * it, that call gets the generic notice asking for a `toolName` call, which
116
+ * repeats the call the model just made instead of naming the invocation needed.
117
+ */
118
+ unsatisfiedNotice?(toolCall: SoftToolCall): string;
111
119
  /** Host-owned reminder messages, injected once per `id` activation. */
112
120
  reminder: AgentMessage[];
113
121
  }
@@ -140,6 +148,8 @@ export interface SteeringQueueState {
140
148
  * Configuration for the agent loop.
141
149
  */
142
150
  export interface AgentLoopConfig extends SimpleStreamOptions {
151
+ /** Resolve the host bridge only when dispatching to the Cursor transport. */
152
+ loadCursorExecHandlers?: () => Promise<CursorExecHandlers>;
143
153
  model: Model;
144
154
  /** Reports whether this loop has reached a safe process-pause boundary. */
145
155
  onPauseChange?: (paused: boolean) => void;
@@ -168,7 +178,7 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
168
178
  */
169
179
  metadataResolver?: (provider: string) => Record<string, unknown> | undefined;
170
180
  /**
171
- * Converts AgentMessage[] to LLM-compatible Message[] before each LLM call.
181
+ * Converts AgentMessage[] to LLM-compatible Message[] for the model receiving this call.
172
182
  *
173
183
  * Each AgentMessage must be converted to a UserMessage, AssistantMessage, or ToolResultMessage
174
184
  * that the LLM can understand. AgentMessages that cannot be converted (e.g., UI-only notifications,
@@ -190,7 +200,7 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
190
200
  * })
191
201
  * ```
192
202
  */
193
- convertToLlm: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
203
+ convertToLlm: (messages: AgentMessage[], model: Model) => Message[] | Promise<Message[]>;
194
204
  /**
195
205
  * Optional transform applied to the context before `convertToLlm`.
196
206
  *
@@ -214,7 +224,7 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
214
224
  * normalization, and append-only context handling, but before telemetry capture
215
225
  * and provider send.
216
226
  */
217
- transformProviderContext?: (context: Context, model: Model) => Context | Promise<Context>;
227
+ transformProviderContext?: (context: Context, model: Model, signal?: AbortSignal) => Context | Promise<Context>;
218
228
  /** Remembers sent tool definitions to fill {@link Context.inactiveTools}. */
219
229
  sentToolDefinitions?: SentToolDefinitions;
220
230
  /**
@@ -263,6 +273,14 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
263
273
  * {@link getSteeringMessages}.
264
274
  */
265
275
  waitForSteeringMessages?: (signal?: AbortSignal) => Promise<void>;
276
+ /**
277
+ * Aborted just before the host aborts the run when running tools should keep
278
+ * their work: raises the active tool batch's cooperative
279
+ * {@link ToolCallContext.steeringSignal} (source `"user"`) in either
280
+ * {@link interruptMode}, so a tool that can (auto-background bash/eval)
281
+ * moves its work into a background job instead of being killed.
282
+ */
283
+ detachSignal?: AbortSignal;
266
284
  /**
267
285
  * Called when live steering dequeues messages via {@link getSteeringMessages}
268
286
  * for the response being streamed. The loop records them in the transcript
@@ -280,8 +298,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
280
298
  */
281
299
  hasIrcInterrupts?: () => boolean | Promise<boolean>;
282
300
  /**
283
- * Peeks whether a background completion (finished job, exited supervised
284
- * process) is queued for aside injection at the next boundary.
301
+ * Peeks whether a background notice (finished job, exited supervised
302
+ * process, output a running job was asked to report) is queued for aside
303
+ * injection at the next boundary.
285
304
  *
286
305
  * Same rules as {@link hasIrcInterrupts}: non-consuming, only cuts
287
306
  * *interruptible* waits short, in either interruptMode. Without
@@ -383,8 +402,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
383
402
  /**
384
403
  * Resolve a tool call whose name matched no advertised tool (including
385
404
  * `customWireName` aliases). Lets hosts route calls to tools they expose
386
- * through side transports (e.g. `xd://` device mounts) instead of failing
387
- * with "Tool not found". Returning `undefined` keeps the failure.
405
+ * through a side transport (e.g. mounted tool commands run through `bash`)
406
+ * instead of failing with "Tool not found". Returning `undefined` keeps the failure.
388
407
  *
389
408
  * `advertised` is the very snapshot exact-name dispatch just searched — the
390
409
  * set offered to THIS request. A host must resolve against it rather than
@@ -396,9 +415,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
396
415
  resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
397
416
  /**
398
417
  * Names reachable through {@link resolveFallbackTool} but absent from the
399
- * advertised set (e.g. `xd://` device mounts). Consulted only to name a
400
- * plausible target when a call misses, so a mis-transcribed device call is
401
- * recoverable; never a dispatch source.
418
+ * advertised set (e.g. mounted tool commands run through `bash`). Consulted
419
+ * only to name a plausible target when a call misses, so a mis-transcribed
420
+ * command name is recoverable; never a dispatch source.
402
421
  */
403
422
  suggestFallbackToolNames?: () => Iterable<string>;
404
423
  /**
@@ -551,6 +570,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
551
570
  * post-turn steering.
552
571
  */
553
572
  onTurnEnd?: (messages: AgentMessage[], signal?: AbortSignal, context?: AgentTurnEndContext) => Promise<void> | void;
573
+ /** Called synchronously when the loop pushes `turn_end` onto the event stream. */
574
+ onTurnEndEmitted?: () => void;
554
575
  /**
555
576
  * Called once an assistant message is finalized from the model stream, before
556
577
  * it is appended to the context, emitted as `message_end`, or its tool calls
@@ -968,9 +989,9 @@ export type ToolTier = "read" | "write" | "exec";
968
989
  /**
969
990
  * How an enabled tool is presented to the model. `"essential"` tools are exposed
970
991
  * as normal top-level tools. `"discoverable"` tools are removed from the top-level
971
- * schema and either mounted under `xd://` device URLs (when that transport is
972
- * active) or surfaced through BM25 tool search — keeping their schemas off every
973
- * request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
992
+ * schema and either mounted as a tool command in the `bash` tool (when that
993
+ * tool is active) or surfaced through BM25 tool search — keeping their schemas
994
+ * off every request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
974
995
  * provider availability) decides whether a tool is enabled; `loadMode` only
975
996
  * decides how an enabled tool is presented.
976
997
  */
@@ -990,11 +1011,6 @@ export type ToolApprovalDecision = ToolTier | {
990
1011
  reason?: string;
991
1012
  override?: boolean;
992
1013
  policy?: "allow" | "deny" | "prompt";
993
- /** User-policy key for this decision. When set, `tools.approval.<policyKey>`
994
- * is consulted instead of `tools.approval.<tool.name>`. Lets a dispatcher
995
- * tool (e.g. `write` for an `xd://` device call) scope user allow/deny/
996
- * prompt policies to the tool it dispatches into. */
997
- policyKey?: string;
998
1014
  };
999
1015
  export type ToolApproval = ToolApprovalDecision | ((args: unknown, context?: AgentToolContext) => ToolApprovalDecision);
1000
1016
  /**
@@ -1053,9 +1069,16 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
1053
1069
  * obtains by delegating to this native tool through `ctx.invokeTool` follow this tool's contract.
1054
1070
  */
1055
1071
  readonly delegationGuidance?: string;
1072
+ /**
1073
+ * Whether `command` is traffic this tool must run itself rather than shell work: the transport
1074
+ * host (`bash`) answers true for a line made only of session tool commands, which nothing else
1075
+ * can dispatch. A same-name extension replacement routes such a call back here instead of
1076
+ * executing it, so mounted tools keep working behind an override that does not delegate.
1077
+ */
1078
+ servesToolCommandLine?(command: string): boolean;
1056
1079
  /**
1057
1080
  * On-demand documentation topics (`topic → markdown`), readable as
1058
- * `xd://<tool>/<topic>`. Lets a tool keep large sub-surfaces out of its
1081
+ * `help://<tool>/<topic>`. Lets a tool keep large sub-surfaces out of its
1059
1082
  * description and advertise only a one-line pointer per topic.
1060
1083
  */
1061
1084
  docTopics?(): Readonly<Record<string, string>>;
@@ -1163,6 +1186,12 @@ export interface AgentContext {
1163
1186
  systemPrompt: string[];
1164
1187
  messages: AgentMessage[];
1165
1188
  tools?: AgentTool<any>[];
1189
+ /**
1190
+ * Inactive tools that may become active later in the conversation. A provider that announces tool changes
1191
+ * in-band (Anthropic `tool_addition`) declares them from the first request, so activating one leaves the
1192
+ * cached prefix intact. See {@link SentToolDefinitions.withInactiveTools}.
1193
+ */
1194
+ standbyTools?: AgentTool<any>[];
1166
1195
  }
1167
1196
  /**
1168
1197
  * Events emitted by the Agent for UI updates.
package/package.json CHANGED
@@ -1,56 +1,27 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@linxiraos/pi-agent-core",
4
- "version": "1.5.13",
3
+ "version": "1.5.15",
5
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
+ "keywords": [
6
+ "agent",
7
+ "ai",
8
+ "llm",
9
+ "state-management",
10
+ "transport"
11
+ ],
6
12
  "homepage": "https://linxira-os.github.io/zeta/",
13
+ "bugs": {
14
+ "url": "https://github.com/Linxira-OS/linxira-zeta/issues"
15
+ },
16
+ "license": "MIT",
7
17
  "author": "Linxira-OS",
8
18
  "contributors": [
9
19
  "Mario Zechner"
10
20
  ],
11
- "license": "MIT",
12
21
  "repository": {
13
- "directory": "packages/agent",
22
+ "type": "git",
14
23
  "url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
15
- "type": "git"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/Linxira-OS/linxira-zeta/issues"
19
- },
20
- "keywords": [
21
- "ai",
22
- "agent",
23
- "llm",
24
- "transport",
25
- "state-management"
26
- ],
27
- "main": "./src/index.ts",
28
- "types": "./dist/types/index.d.ts",
29
- "scripts": {
30
- "check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
31
- "check:types": "bun check --no-script -p tsconfig.json",
32
- "lint": "oxlint .",
33
- "test": "bun test --parallel",
34
- "fix": "oxlint --fix --fix-suggestions . && bun run fmt",
35
- "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
36
- },
37
- "dependencies": {
38
- "@linxiraos/pi-ai": "1.5.13",
39
- "@linxiraos/pi-catalog": "1.5.13",
40
- "@linxiraos/pi-natives": "1.5.13",
41
- "@linxiraos/pi-utils": "1.5.13",
42
- "@linxiraos/pi-wire": "1.5.13",
43
- "@linxiraos/zeta-compact": "1.5.13",
44
- "@opentelemetry/api": "^1.9.1"
45
- },
46
- "devDependencies": {
47
- "@linxiraos/zeta-schema": "1.5.13",
48
- "@opentelemetry/context-async-hooks": "2.9.0",
49
- "@opentelemetry/sdk-trace-base": "2.9.0",
50
- "@types/bun": "1.4.4"
51
- },
52
- "engines": {
53
- "bun": ">=1.4.4"
24
+ "directory": "packages/agent"
54
25
  },
55
26
  "files": [
56
27
  "src",
@@ -60,6 +31,9 @@
60
31
  "THIRD-PARTY-NOTICES.txt",
61
32
  "dist/types"
62
33
  ],
34
+ "type": "module",
35
+ "main": "./src/index.ts",
36
+ "types": "./dist/types/index.d.ts",
63
37
  "exports": {
64
38
  ".": {
65
39
  "types": "./dist/types/index.d.ts",
@@ -77,5 +51,31 @@
77
51
  "types": "./dist/types/*.d.ts",
78
52
  "import": "./src/*.ts"
79
53
  }
54
+ },
55
+ "scripts": {
56
+ "check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
57
+ "check:types": "bun check --no-script -p tsconfig.json",
58
+ "lint": "oxlint .",
59
+ "test": "bun test --parallel",
60
+ "fix": "oxlint --fix --fix-suggestions . && bun run fmt",
61
+ "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
62
+ },
63
+ "dependencies": {
64
+ "@linxiraos/pi-ai": "1.5.15",
65
+ "@linxiraos/pi-catalog": "1.5.15",
66
+ "@linxiraos/pi-natives": "1.5.15",
67
+ "@linxiraos/pi-utils": "1.5.15",
68
+ "@linxiraos/pi-wire": "1.5.15",
69
+ "@linxiraos/zeta-compact": "1.5.15",
70
+ "@opentelemetry/api": "^1.9.1"
71
+ },
72
+ "devDependencies": {
73
+ "@linxiraos/zeta-schema": "1.5.15",
74
+ "@opentelemetry/context-async-hooks": "2.9.0",
75
+ "@opentelemetry/sdk-trace-base": "2.9.0",
76
+ "@types/bun": "1.4.4"
77
+ },
78
+ "engines": {
79
+ "bun": ">=1.4.4"
80
80
  }
81
81
  }