@code-yeongyu/senpi-agent-core 2026.11.2-2 → 2026.11.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.
@@ -1,5 +1,5 @@
1
1
  import { dropFailedAssistantTurns, retryAssistantCall, uuidv7, } from "@earendil-works/pi-ai";
2
- import { getTelemetryContext } from "../context.js";
2
+ import { getSessionCwd, getTelemetryContext } from "../context.js";
3
3
  import { convertToLlm, createBranchSummaryMessage, createCompactionSummaryMessage } from "../messages.js";
4
4
  import { buildContextEntries, sessionEntryToContextMessages } from "../session/context.js";
5
5
  import { CompactionError, err, ok } from "../types.js";
@@ -58,8 +58,11 @@ function getMessageFromEntryForCompaction(entry) {
58
58
  return getMessageFromEntry(entry);
59
59
  }
60
60
  export function createSummaryRequestOptions(options, context) {
61
+ // Providers such as anthropic-subscription reject a request without the absolute session cwd (#5256).
62
+ const cwd = options.cwd ?? getSessionCwd(context);
61
63
  return {
62
64
  ...options,
65
+ ...(cwd === undefined ? {} : { cwd }),
63
66
  signal: context.abortSignal,
64
67
  telemetryContext: getTelemetryContext(context),
65
68
  cacheRetention: "none",
@@ -2,6 +2,10 @@ import type { Context, ContextKey } from "@earendil-works/chord";
2
2
  import { awaitWithContext, BACKGROUND_CONTEXT, createContextKey, TODO_CONTEXT, withAbortSignal, withCancel, withContextValue, withoutAbortSignal } from "@earendil-works/chord/context";
3
3
  import { type TelemetryContext } from "@earendil-works/pi-telemetry";
4
4
  export { awaitWithContext, BACKGROUND_CONTEXT, type Context, type ContextKey, createContextKey, TODO_CONTEXT, withAbortSignal, withCancel, withContextValue, withoutAbortSignal, };
5
+ /** Return the session working directory attached to a context, if any. */
6
+ export declare function getSessionCwd(context: Context): string | undefined;
7
+ /** Derive a context whose provider requests carry the session working directory. */
8
+ export declare function withSessionCwd(cwd: string | undefined, context: Context): Context;
5
9
  /** Return the telemetry parent attached to a context, or the shared no-op parent. */
6
10
  export declare function getTelemetryContext(context: Context): TelemetryContext;
7
11
  /** Derive a context whose telemetry children use the supplied parent or active span. */
@@ -2,6 +2,15 @@ import { awaitWithContext, BACKGROUND_CONTEXT, createContextKey, TODO_CONTEXT, w
2
2
  import { NOOP_TELEMETRY_CONTEXT } from "@earendil-works/pi-telemetry";
3
3
  export { awaitWithContext, BACKGROUND_CONTEXT, createContextKey, TODO_CONTEXT, withAbortSignal, withCancel, withContextValue, withoutAbortSignal, };
4
4
  const TELEMETRY_CONTEXT_KEY = createContextKey("pi.telemetryContext");
5
+ const SESSION_CWD_CONTEXT_KEY = createContextKey("pi.sessionCwd");
6
+ /** Return the session working directory attached to a context, if any. */
7
+ export function getSessionCwd(context) {
8
+ return context.value(SESSION_CWD_CONTEXT_KEY);
9
+ }
10
+ /** Derive a context whose provider requests carry the session working directory. */
11
+ export function withSessionCwd(cwd, context) {
12
+ return cwd === undefined ? context : withContextValue(SESSION_CWD_CONTEXT_KEY, cwd, context);
13
+ }
5
14
  /** Return the telemetry parent attached to a context, or the shared no-op parent. */
6
15
  export function getTelemetryContext(context) {
7
16
  return context.value(TELEMETRY_CONTEXT_KEY) ?? NOOP_TELEMETRY_CONTEXT;
@@ -133,6 +133,7 @@ async function performGeneration(lane, drive, intent, prepared) {
133
133
  const admitted = withAbortSignal(drive.gate.signal, context);
134
134
  return drive.gate.admit(() => lane.models.streamSimple(prepared.model, aiContext, {
135
135
  ...options,
136
+ ...(lane.session.metadata.cwd === undefined ? {} : { cwd: lane.session.metadata.cwd }),
136
137
  sessionId: `${lane.session.metadata.id}:${lane.name}`,
137
138
  signal: admitted.abortSignal,
138
139
  telemetryContext: getTelemetryContext(admitted),
@@ -1,7 +1,7 @@
1
1
  import { isRetryableAssistantError, retryDelayMs, } from "@earendil-works/pi-ai";
2
2
  import { generateBranchSummaryWithRequest } from "../../compaction/branch-summarization.js";
3
3
  import { compactWithRequest, prepareCompaction, shouldCompact } from "../../compaction/compaction.js";
4
- import { getTelemetryContext, withAbortSignal } from "../../context.js";
4
+ import { getTelemetryContext, withAbortSignal, withSessionCwd } from "../../context.js";
5
5
  import { AbortRequested } from "../../execution/effect-gate.js";
6
6
  import { applyStreamOptionsPatch } from "../../hooks.js";
7
7
  import { insertEntry, insertUsage } from "../../session/commit.js";
@@ -641,6 +641,7 @@ async function performStructuralAttempt(lane, drive, effect, model, preparation)
641
641
  await publishNestedRequestOutcome(lane, drive, intent.value, usageId, response);
642
642
  return response;
643
643
  };
644
+ const summaryContext = withSessionCwd(lane.session.metadata.cwd, drive.context);
644
645
  try {
645
646
  if (summaryKind(effect.task) === "compaction") {
646
647
  if (!("messagesToSummarize" in preparation)) {
@@ -650,7 +651,7 @@ async function performStructuralAttempt(lane, drive, effect, model, preparation)
650
651
  model,
651
652
  customInstructions: effect.task.customInstructions,
652
653
  thinkingLevel: effect.summaryContext.configuration.thinkingLevel,
653
- }, request, drive.context);
654
+ }, request, summaryContext);
654
655
  if (!result.ok) {
655
656
  return {
656
657
  kind: "error",
@@ -667,7 +668,7 @@ async function performStructuralAttempt(lane, drive, effect, model, preparation)
667
668
  if (!("messages" in preparation)) {
668
669
  throw new SessionInvariantError("Branch summary has invalid durable preparation");
669
670
  }
670
- const result = await generateBranchSummaryWithRequest(preparation, { customInstructions: effect.task.customInstructions }, request, drive.context);
671
+ const result = await generateBranchSummaryWithRequest(preparation, { customInstructions: effect.task.customInstructions }, request, summaryContext);
671
672
  if (!result.ok) {
672
673
  return {
673
674
  kind: "error",
@@ -0,0 +1,7 @@
1
+ import { type AssistantMessage, type AssistantMessageEvent } from "@earendil-works/pi-ai";
2
+ import type { ProxyAssistantMessageEvent } from "./proxy.ts";
3
+ /**
4
+ * Process a proxy event and update the partial message.
5
+ */
6
+ export declare function processProxyEvent(proxyEvent: ProxyAssistantMessageEvent, partial: AssistantMessage): AssistantMessageEvent | undefined;
7
+ //# sourceMappingURL=proxy-event-reducer.d.ts.map
@@ -0,0 +1,139 @@
1
+ import { parseStreamingJson, } from "@earendil-works/pi-ai";
2
+ function setRawArguments(partial, contentIndex, content, raw) {
3
+ content.partialJson = raw;
4
+ content.arguments = parseStreamingJson(raw) || {};
5
+ partial.content[contentIndex] = { ...content }; // Trigger reactivity
6
+ }
7
+ /**
8
+ * Process a proxy event and update the partial message.
9
+ */
10
+ export function processProxyEvent(proxyEvent, partial) {
11
+ switch (proxyEvent.type) {
12
+ case "start":
13
+ return { type: "start", partial };
14
+ case "text_start":
15
+ partial.content[proxyEvent.contentIndex] = { type: "text", text: "" };
16
+ return { type: "text_start", contentIndex: proxyEvent.contentIndex, partial };
17
+ case "text_delta": {
18
+ const content = partial.content[proxyEvent.contentIndex];
19
+ if (content?.type === "text") {
20
+ content.text += proxyEvent.delta;
21
+ return {
22
+ type: "text_delta",
23
+ contentIndex: proxyEvent.contentIndex,
24
+ delta: proxyEvent.delta,
25
+ partial,
26
+ };
27
+ }
28
+ throw new Error("Received text_delta for non-text content");
29
+ }
30
+ case "text_end": {
31
+ const content = partial.content[proxyEvent.contentIndex];
32
+ if (content?.type === "text") {
33
+ content.textSignature = proxyEvent.contentSignature;
34
+ return {
35
+ type: "text_end",
36
+ contentIndex: proxyEvent.contentIndex,
37
+ content: content.text,
38
+ partial,
39
+ };
40
+ }
41
+ throw new Error("Received text_end for non-text content");
42
+ }
43
+ case "thinking_start":
44
+ partial.content[proxyEvent.contentIndex] = { type: "thinking", thinking: "" };
45
+ return { type: "thinking_start", contentIndex: proxyEvent.contentIndex, partial };
46
+ case "thinking_delta": {
47
+ const content = partial.content[proxyEvent.contentIndex];
48
+ if (content?.type === "thinking") {
49
+ content.thinking += proxyEvent.delta;
50
+ return {
51
+ type: "thinking_delta",
52
+ contentIndex: proxyEvent.contentIndex,
53
+ delta: proxyEvent.delta,
54
+ partial,
55
+ };
56
+ }
57
+ throw new Error("Received thinking_delta for non-thinking content");
58
+ }
59
+ case "thinking_end": {
60
+ const content = partial.content[proxyEvent.contentIndex];
61
+ if (content?.type === "thinking") {
62
+ content.thinkingSignature = proxyEvent.contentSignature;
63
+ return {
64
+ type: "thinking_end",
65
+ contentIndex: proxyEvent.contentIndex,
66
+ content: content.thinking,
67
+ partial,
68
+ };
69
+ }
70
+ throw new Error("Received thinking_end for non-thinking content");
71
+ }
72
+ case "toolcall_start":
73
+ partial.content[proxyEvent.contentIndex] = {
74
+ type: "toolCall",
75
+ id: proxyEvent.id,
76
+ name: proxyEvent.toolName,
77
+ arguments: {},
78
+ partialJson: "",
79
+ };
80
+ return { type: "toolcall_start", contentIndex: proxyEvent.contentIndex, partial };
81
+ case "toolcall_delta": {
82
+ const content = partial.content[proxyEvent.contentIndex];
83
+ if (content?.type === "toolCall") {
84
+ const raw = content.partialJson + proxyEvent.delta;
85
+ setRawArguments(partial, proxyEvent.contentIndex, content, raw);
86
+ return {
87
+ type: "toolcall_delta",
88
+ contentIndex: proxyEvent.contentIndex,
89
+ delta: proxyEvent.delta,
90
+ partial,
91
+ };
92
+ }
93
+ throw new Error("Received toolcall_delta for non-toolCall content");
94
+ }
95
+ case "message_tool_arguments_reset": {
96
+ const content = partial.content[proxyEvent.contentIndex];
97
+ if (content?.type !== "toolCall")
98
+ throw new Error("Received message_tool_arguments_reset for non-toolCall content");
99
+ setRawArguments(partial, proxyEvent.contentIndex, content, proxyEvent.rawArgumentPrefix);
100
+ return undefined;
101
+ }
102
+ case "toolcall_end": {
103
+ const content = partial.content[proxyEvent.contentIndex];
104
+ if (content?.type === "toolCall") {
105
+ const toolCall = proxyEvent.toolCall ?? content;
106
+ delete toolCall.partialJson;
107
+ partial.content[proxyEvent.contentIndex] = toolCall;
108
+ return {
109
+ type: "toolcall_end",
110
+ contentIndex: proxyEvent.contentIndex,
111
+ toolCall,
112
+ partial,
113
+ };
114
+ }
115
+ return undefined;
116
+ }
117
+ case "done":
118
+ partial.stopReason = proxyEvent.reason;
119
+ partial.usage = proxyEvent.usage;
120
+ if (proxyEvent.providerThinkingLevel !== undefined) {
121
+ partial.providerThinkingLevel = proxyEvent.providerThinkingLevel;
122
+ }
123
+ return { type: "done", reason: proxyEvent.reason, message: partial };
124
+ case "error":
125
+ partial.stopReason = proxyEvent.reason;
126
+ partial.errorMessage = proxyEvent.errorMessage;
127
+ partial.usage = proxyEvent.usage;
128
+ if (proxyEvent.providerThinkingLevel !== undefined) {
129
+ partial.providerThinkingLevel = proxyEvent.providerThinkingLevel;
130
+ }
131
+ return { type: "error", reason: proxyEvent.reason, error: partial };
132
+ default: {
133
+ const _exhaustiveCheck = proxyEvent;
134
+ console.warn(`Unhandled proxy event type: ${proxyEvent.type}`);
135
+ return undefined;
136
+ }
137
+ }
138
+ }
139
+ //# sourceMappingURL=proxy-event-reducer.js.map
package/dist/proxy.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Proxy stream function for apps that route LLM calls through a server.
3
3
  * The server manages auth and proxies requests to LLM providers.
4
4
  */
5
- import { type AssistantMessage, type AssistantMessageEvent, EventStream, type Model, type SimpleStreamOptions, type StopReason, type ToolCall, type TranscriptContext } from "@earendil-works/pi-ai";
5
+ import { type AssistantMessage, type AssistantMessageEvent, type AssistantProgress, EventStream, type Model, type SimpleStreamOptions, type StopReason, type ToolCall, type TranscriptContext } from "@earendil-works/pi-ai";
6
6
  declare class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
7
7
  constructor();
8
8
  }
@@ -42,7 +42,11 @@ export type ProxyAssistantMessageEvent = {
42
42
  type: "toolcall_delta";
43
43
  contentIndex: number;
44
44
  delta: string;
45
- } | {
45
+ }
46
+ /** Replaces the call's raw arguments with `rawArgumentPrefix`; the next delta continues from it (senpi#5300). */
47
+ | Extract<AssistantProgress, {
48
+ type: "message_tool_arguments_reset";
49
+ }> | {
46
50
  /**
47
51
  * Servers SHOULD send the final ToolCall; flagged incomplete calls emit no argument deltas, so delta
48
52
  * reconstruction alone cannot represent them, and metadata such as `namespace` only exists on the final call.
package/dist/proxy.js CHANGED
@@ -3,7 +3,8 @@
3
3
  * The server manages auth and proxies requests to LLM providers.
4
4
  */
5
5
  // Internal import for JSON parsing utility
6
- import { EventStream, parseStreamingJson, } from "@earendil-works/pi-ai";
6
+ import { EventStream, } from "@earendil-works/pi-ai";
7
+ import { processProxyEvent } from "./proxy-event-reducer.js";
7
8
  // Create stream class matching ProxyMessageEventStream
8
9
  class ProxyMessageEventStream extends EventStream {
9
10
  constructor() {
@@ -183,130 +184,4 @@ export function streamProxy(model, context, options) {
183
184
  })();
184
185
  return stream;
185
186
  }
186
- /**
187
- * Process a proxy event and update the partial message.
188
- */
189
- function processProxyEvent(proxyEvent, partial) {
190
- switch (proxyEvent.type) {
191
- case "start":
192
- return { type: "start", partial };
193
- case "text_start":
194
- partial.content[proxyEvent.contentIndex] = { type: "text", text: "" };
195
- return { type: "text_start", contentIndex: proxyEvent.contentIndex, partial };
196
- case "text_delta": {
197
- const content = partial.content[proxyEvent.contentIndex];
198
- if (content?.type === "text") {
199
- content.text += proxyEvent.delta;
200
- return {
201
- type: "text_delta",
202
- contentIndex: proxyEvent.contentIndex,
203
- delta: proxyEvent.delta,
204
- partial,
205
- };
206
- }
207
- throw new Error("Received text_delta for non-text content");
208
- }
209
- case "text_end": {
210
- const content = partial.content[proxyEvent.contentIndex];
211
- if (content?.type === "text") {
212
- content.textSignature = proxyEvent.contentSignature;
213
- return {
214
- type: "text_end",
215
- contentIndex: proxyEvent.contentIndex,
216
- content: content.text,
217
- partial,
218
- };
219
- }
220
- throw new Error("Received text_end for non-text content");
221
- }
222
- case "thinking_start":
223
- partial.content[proxyEvent.contentIndex] = { type: "thinking", thinking: "" };
224
- return { type: "thinking_start", contentIndex: proxyEvent.contentIndex, partial };
225
- case "thinking_delta": {
226
- const content = partial.content[proxyEvent.contentIndex];
227
- if (content?.type === "thinking") {
228
- content.thinking += proxyEvent.delta;
229
- return {
230
- type: "thinking_delta",
231
- contentIndex: proxyEvent.contentIndex,
232
- delta: proxyEvent.delta,
233
- partial,
234
- };
235
- }
236
- throw new Error("Received thinking_delta for non-thinking content");
237
- }
238
- case "thinking_end": {
239
- const content = partial.content[proxyEvent.contentIndex];
240
- if (content?.type === "thinking") {
241
- content.thinkingSignature = proxyEvent.contentSignature;
242
- return {
243
- type: "thinking_end",
244
- contentIndex: proxyEvent.contentIndex,
245
- content: content.thinking,
246
- partial,
247
- };
248
- }
249
- throw new Error("Received thinking_end for non-thinking content");
250
- }
251
- case "toolcall_start":
252
- partial.content[proxyEvent.contentIndex] = {
253
- type: "toolCall",
254
- id: proxyEvent.id,
255
- name: proxyEvent.toolName,
256
- arguments: {},
257
- partialJson: "",
258
- };
259
- return { type: "toolcall_start", contentIndex: proxyEvent.contentIndex, partial };
260
- case "toolcall_delta": {
261
- const content = partial.content[proxyEvent.contentIndex];
262
- if (content?.type === "toolCall") {
263
- content.partialJson += proxyEvent.delta;
264
- content.arguments = parseStreamingJson(content.partialJson) || {};
265
- partial.content[proxyEvent.contentIndex] = { ...content }; // Trigger reactivity
266
- return {
267
- type: "toolcall_delta",
268
- contentIndex: proxyEvent.contentIndex,
269
- delta: proxyEvent.delta,
270
- partial,
271
- };
272
- }
273
- throw new Error("Received toolcall_delta for non-toolCall content");
274
- }
275
- case "toolcall_end": {
276
- const content = partial.content[proxyEvent.contentIndex];
277
- if (content?.type === "toolCall") {
278
- const toolCall = proxyEvent.toolCall ?? content;
279
- delete toolCall.partialJson;
280
- partial.content[proxyEvent.contentIndex] = toolCall;
281
- return {
282
- type: "toolcall_end",
283
- contentIndex: proxyEvent.contentIndex,
284
- toolCall,
285
- partial,
286
- };
287
- }
288
- return undefined;
289
- }
290
- case "done":
291
- partial.stopReason = proxyEvent.reason;
292
- partial.usage = proxyEvent.usage;
293
- if (proxyEvent.providerThinkingLevel !== undefined) {
294
- partial.providerThinkingLevel = proxyEvent.providerThinkingLevel;
295
- }
296
- return { type: "done", reason: proxyEvent.reason, message: partial };
297
- case "error":
298
- partial.stopReason = proxyEvent.reason;
299
- partial.errorMessage = proxyEvent.errorMessage;
300
- partial.usage = proxyEvent.usage;
301
- if (proxyEvent.providerThinkingLevel !== undefined) {
302
- partial.providerThinkingLevel = proxyEvent.providerThinkingLevel;
303
- }
304
- return { type: "error", reason: proxyEvent.reason, error: partial };
305
- default: {
306
- const _exhaustiveCheck = proxyEvent;
307
- console.warn(`Unhandled proxy event type: ${proxyEvent.type}`);
308
- return undefined;
309
- }
310
- }
311
- }
312
187
  //# sourceMappingURL=proxy.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-agent-core",
3
- "version": "2026.11.2-2",
3
+ "version": "2026.11.3-1",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -59,6 +59,8 @@
59
59
  "generate-telemetry-docs": "node scripts/generate-telemetry-docs.ts",
60
60
  "check:telemetry-docs": "node scripts/generate-telemetry-docs.ts --check",
61
61
  "build": "tsc -p tsconfig.build.json",
62
+ "pack:conformance": "bun scripts/pack-conformance-archive.ts",
63
+ "check:conformance-archive": "tsc --noEmit -p scripts/tsconfig.json",
62
64
  "bench:session:timing": "vitest bench --config vitest.benchmark.config.ts",
63
65
  "bench:session:memory": "tsx --tsconfig benchmark/tsconfig.json benchmark/session/loaded-footprint.ts",
64
66
  "bench:session:allocations": "tsx --tsconfig benchmark/tsconfig.json benchmark/session/allocation-profile.ts",
@@ -70,8 +72,8 @@
70
72
  },
71
73
  "dependencies": {
72
74
  "@earendil-works/chord": "0.99.1",
73
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.2-2",
74
- "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.2-2",
75
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-1",
76
+ "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.3-1",
75
77
  "diff": "9.0.0",
76
78
  "ignore": "7.0.9",
77
79
  "typebox": "1.3.34",
@@ -96,6 +98,7 @@
96
98
  "node": ">=24.0.0"
97
99
  },
98
100
  "devDependencies": {
101
+ "@types/bun": "1.4.4",
99
102
  "@types/node": "26.6.2",
100
103
  "@vscode/tree-sitter-wasm": "0.3.1",
101
104
  "@vitest/coverage-v8": "5.0.1",