@rivus/agent 0.15.1 → 0.16.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,15 +1,15 @@
1
+ import { i as resolvePiSessionToolNames, l as validatePiSkillCommand, m as createPiBashTool, n as createPiToolProxyDefinitions, p as createPiSkillReadTools, r as createPiSessionResources, t as createPiToolNameResolver } from "../chunks/pi.js";
1
2
  import { d as resolveInvocationAuthority, r as createPiSkillRuntime, s as createToolInputDigest, u as createInvocationAuthority } from "../chunks/rivus-tool.js";
2
3
  import { $t as openJsonlRecoveryControl, A as createScheduledAutomation, An as createLangfuseAgentTelemetry, Bn as createFeishuTopicContextResolver, Dn as createPiAgentLoop, Dt as createBackgroundSessionHostTools, Ei as openJsonFeishuSessionStore, En as createPiSessionRegistry, Gi as readPersistenceFile, Hi as ToolInvocationDenied, Ii as createFeishuCardDeliveryReconciler, In as createJsonlAgentEventLog, Ji as mergePiProviderModelDeclaration, Jt as createFeishuPresentationPreparation, K as createRivusMemoryToolDescriptor, Ki as isRecord$4, Lt as createBackgroundSessionService, Nt as openJsonlBackgroundSessionDeliveryStore, Oi as openJsonlFeishuInboxRepository, Ot as createBackgroundSessionSupervisor, Pi as openJsonlFeishuCardDeliveryLedger, Qr as createUuidRunIds, Si as createJsonFetchRequest, Ti as createSessionScheduler, Tn as readAutomationPresentation, Ui as createToolBroker, Un as createConfiguredFeishuTextReplySender, W as createProjectMemoryPromptPreparer, Wi as openJsonlToolOperationLedger, Wn as createConfiguredFeishuCardRolloverRuntime, Xt as createAgentHarnessPooledRuntime, Yi as writeAtomicTextFile, Yt as createFeishuDeploymentEndpoint, Zr as createSystemClock, an as createAgentsMdInstructionsProvider, bn as createJsonFileFeishuCardTargetRegistry, c as createConfiguredFeishuAutomationCardSender, d as createHumanInteractionToolApprovalGateway, en as openJsonlToolOperationLedger$1, f as createHumanInteractionEndpointRegistry, g as loadRivusDeploymentManifest, hr as createLazyFeishuWebSocketEventDispatcher, ht as resolveFeishuDeliveryChatId, ii as createAgentHarness, j as AUTOMATION_SUPPRESSION_PREFIX, jn as resolveLangfuseTelemetryConfig, jt as openJsonlBackgroundSessionRepository, k as openJsonAutomationTickRepository, l as createRoutedHumanInteractionToolApprovalService, mn as createFeishuCotPublisher, mt as createConfiguredFeishuBackgroundSessionDelivery, n as createConfiguredFeishuHumanInteractionPresenter, o as createJsonlHumanInteractionRepository, on as createWorkspaceRootHandle, qi as mergePiProviderBaseUrlOverride, t as createHumanInteractionService, tn as createToolBroker$1, tr as createConfiguredFeishuOpenApiClient, u as createHumanInteractionModelChangeApproval, wt as resolveBackgroundSessionSupervisorIntervalMs, z as openJsonlAgentMemoryService } from "../chunks/src.js";
3
4
  import { I as resolveFeishuEndpointCredentials, J as migrateRivusModelManagementConfig, K as installRivusModelManagementCliLauncher, U as runDeploymentProcessEffect, X as loadMergedLocalEnvFile, Y as parseRivusModelManagementHomeConfig, q as installRivusRuntimeManagementSkill } from "../chunks/rivus-daemon-cli.js";
4
5
  import { t as createSha256Digest } from "../chunks/sha256-digest.js";
5
6
  import { a as toRivusModelManagementSubmission, i as projectRivusModelCliResponse, r as parseRivusModelManagementWireRequest, t as createRivusModelManagementFailure } from "../chunks/rivus-model-management-wire.js";
6
7
  import { f as createBackgroundSessionStepSourceMessageId } from "../chunks/background-session-authority.js";
7
- import { i as resolvePiSessionToolNames, l as validatePiSkillCommand, n as createPiToolProxyDefinitions, p as createPiSkillReadTools, r as createPiSessionResources, t as createPiToolNameResolver } from "../chunks/pi.js";
8
8
  import { Effect, Either } from "effect";
9
9
  import { createHash, randomUUID } from "node:crypto";
10
10
  import { chmod, mkdir, open, readFile, realpath, rename, stat, unlink } from "node:fs/promises";
11
11
  import { delimiter, dirname, isAbsolute, join, relative, resolve } from "node:path";
12
- import { ModelRuntime, SessionManager, SettingsManager, createAgentSession, createBashToolDefinition, defineTool, estimateTokens } from "@earendil-works/pi-coding-agent";
12
+ import { ModelRuntime, SessionManager, SettingsManager, createAgentSession, estimateTokens } from "@earendil-works/pi-coding-agent";
13
13
  import { homedir } from "node:os";
14
14
  import { fileURLToPath } from "node:url";
15
15
  import { Type } from "typebox";
@@ -155,26 +155,29 @@ function createPiManagedSessionContext(options) {
155
155
  if (input.invocation?.kind === "feishu" && input.invocation.allowedActorOpenIds.length === 1) context = options.contexts.issue(input);
156
156
  },
157
157
  deactivate,
158
- tool: defineTool(createBashToolDefinition(options.cwd, { spawnHook: (spawn) => {
159
- const { RIVUS_MODEL_CONTEXT: _context, RIVUS_MODEL_SOCKET: _socket, ...baseEnv } = spawn.env;
160
- const prepared = {
161
- ...spawn,
162
- env: {
163
- ...baseEnv,
164
- PATH: [
165
- options.binDirectory,
166
- dirname(options.nodeExecutable),
167
- baseEnv.PATH
168
- ].filter(Boolean).join(delimiter),
169
- RIVUS_MODEL_MANAGEMENT_ENABLED: "true",
170
- RIVUS_MODEL_SOCKET: options.socketPath
171
- }
172
- };
173
- return context ? createPiModelManagementBashSpawnHook({
174
- context,
175
- socketPath: options.socketPath
176
- })(prepared) : prepared;
177
- } }))
158
+ tool: createPiBashTool(options.cwd, {
159
+ ...options.bashToolOptions,
160
+ spawnHook: (spawn) => {
161
+ const { RIVUS_MODEL_CONTEXT: _context, RIVUS_MODEL_SOCKET: _socket, ...baseEnv } = spawn.env;
162
+ const prepared = {
163
+ ...spawn,
164
+ env: {
165
+ ...baseEnv,
166
+ PATH: [
167
+ options.binDirectory,
168
+ dirname(options.nodeExecutable),
169
+ baseEnv.PATH
170
+ ].filter(Boolean).join(delimiter),
171
+ RIVUS_MODEL_MANAGEMENT_ENABLED: "true",
172
+ RIVUS_MODEL_SOCKET: options.socketPath
173
+ }
174
+ };
175
+ return context ? createPiModelManagementBashSpawnHook({
176
+ context,
177
+ socketPath: options.socketPath
178
+ })(prepared) : prepared;
179
+ }
180
+ })
178
181
  };
179
182
  }
180
183
  //#endregion
@@ -4054,13 +4057,6 @@ async function createRivusDeploymentAdapters(context) {
4054
4057
  }) : void 0;
4055
4058
  const sessionRegistry = createPiSessionRegistry({ createSession: async (firstInput) => {
4056
4059
  let activeInput = firstInput;
4057
- const managedContext = management?.enabled && runContexts && input.definition.runtimeToolGrantSet.toolIds.includes("bash") ? createPiManagedSessionContext({
4058
- binDirectory: management.binDirectory,
4059
- contexts: runContexts.registry,
4060
- cwd: workingDirectory,
4061
- nodeExecutable: process.execPath,
4062
- socketPath: management.socketPath
4063
- }) : void 0;
4064
4060
  const resources = await createPiSessionResources({
4065
4061
  agentDir: PI_AGENT_DIR,
4066
4062
  appendSystemPromptOverride: () => [workspaceInstructions.content, skillRuntime.prompt].filter((content) => content.length > 0),
@@ -4069,8 +4065,17 @@ async function createRivusDeploymentAdapters(context) {
4069
4065
  ...input.projectSpace ? { projectSkillPaths: input.projectSpace.skillPaths } : {},
4070
4066
  systemPromptOverride: () => input.definition.systemPrompt
4071
4067
  });
4068
+ const managedContext = management?.enabled && runContexts && input.definition.runtimeToolGrantSet.toolIds.includes("bash") ? createPiManagedSessionContext({
4069
+ ...resources.bashToolOptions ? { bashToolOptions: resources.bashToolOptions } : {},
4070
+ binDirectory: management.binDirectory,
4071
+ contexts: runContexts.registry,
4072
+ cwd: workingDirectory,
4073
+ nodeExecutable: process.execPath,
4074
+ socketPath: management.socketPath
4075
+ }) : void 0;
4076
+ const bashTool = input.definition.runtimeToolGrantSet.toolIds.includes("bash") ? managedContext?.tool ?? createPiBashTool(workingDirectory, resources.bashToolOptions) : void 0;
4072
4077
  const customTools = [
4073
- ...managedContext ? [managedContext.tool] : [],
4078
+ ...bashTool ? [bashTool] : [],
4074
4079
  ...createPiSkillReadTools({
4075
4080
  cwd: workingDirectory,
4076
4081
  runtimeToolIds: input.definition.runtimeToolGrantSet.toolIds,
@@ -4088,7 +4093,7 @@ async function createRivusDeploymentAdapters(context) {
4088
4093
  }),
4089
4094
  ...skillRuntime.tool ? [skillRuntime.tool] : []
4090
4095
  ];
4091
- const activeToolNames = resolvePiSessionToolNames(managedContext ? input.definition.runtimeToolGrantSet.toolIds.filter((toolId) => toolId !== "bash") : input.definition.runtimeToolGrantSet.toolIds, customTools);
4096
+ const activeToolNames = resolvePiSessionToolNames(bashTool ? input.definition.runtimeToolGrantSet.toolIds.filter((toolId) => toolId !== "bash") : input.definition.runtimeToolGrantSet.toolIds, customTools);
4092
4097
  const result = await createAgentSession(resources.withSessionOptions({
4093
4098
  ...piOptions,
4094
4099
  ...management?.enabled ? management.runtime.getSessionOptions() : {},
@@ -4115,6 +4120,7 @@ async function createRivusDeploymentAdapters(context) {
4115
4120
  } });
4116
4121
  const unregisterModels = management?.enabled ? management.runtime.registerSessionRegistry(sessionRegistry) : void 0;
4117
4122
  const loop = createPiAgentLoop({
4123
+ supportsSteering: true,
4118
4124
  disposeSessionAfterRun: false,
4119
4125
  ...management?.enabled ? { runBoundary: management.boundary } : {},
4120
4126
  ...telemetry ? { modelContentObserver: telemetry.modelContentObserver } : {},
@@ -416,7 +416,8 @@ interface AgentLoopInput {
416
416
  readonly steering?: AgentSteeringChannel;
417
417
  }
418
418
  interface AgentSteeringChannel {
419
- next(): Promise<string>;
419
+ next(signal?: AbortSignal): Promise<string>;
420
+ close?(): Promise<readonly string[]>;
420
421
  }
421
422
  interface AgentLoop {
422
423
  run(input: AgentLoopInput): Stream.Stream<AgentLoopEvent, unknown>;
@@ -117,14 +117,20 @@ function toEffectAgentLoopInput(input) {
117
117
  const { steering, ...rest } = input;
118
118
  return {
119
119
  ...rest,
120
- ...steering ? { steering: { next: () => Effect.promise(() => steering.next()) } } : {}
120
+ ...steering ? { steering: {
121
+ ...steering.close ? { close: () => Effect.promise(() => steering.close()) } : {},
122
+ next: () => Effect.promise((signal) => steering.next(signal))
123
+ } } : {}
121
124
  };
122
125
  }
123
126
  function toCompatibilityAgentLoopInput(input) {
124
127
  const { steering, ...rest } = input;
125
128
  return {
126
129
  ...rest,
127
- ...steering ? { steering: { next: () => Effect.runPromise(steering.next()) } } : {}
130
+ ...steering ? { steering: {
131
+ ...steering.close ? { close: () => Effect.runPromise(steering.close()) } : {},
132
+ next: (signal) => Effect.runPromise(steering.next(), { signal })
133
+ } } : {}
128
134
  };
129
135
  }
130
136
  function isPromiseLike(value) {
@@ -1808,6 +1808,7 @@ interface FeishuCardRolloverOptions {
1808
1808
  readonly createSuccessor: (request: FeishuCardRolloverSuccessorRequest) => Effect.Effect<FeishuCardRolloverTarget, unknown>;
1809
1809
  readonly leaseMs?: number;
1810
1810
  readonly observe?: (event: FeishuCardRolloverEvent) => void;
1811
+ readonly progressDisplay?: ConversationProgressDisplay;
1811
1812
  readonly publisher: FeishuCardRolloverStreamPublisher;
1812
1813
  readonly store: FeishuCardPresentationStore;
1813
1814
  }
@@ -2989,6 +2990,10 @@ interface PiSessionManager {
2989
2990
  }
2990
2991
  interface PiAgentSession {
2991
2992
  abort?: () => Promise<void> | void;
2993
+ /** Native queue operations required when the loop opts into steering. */
2994
+ steer?(text: string): Promise<void> | void;
2995
+ readonly isStreaming?: boolean;
2996
+ clearQueue?(): unknown;
2992
2997
  setModel?(model: unknown): Promise<void> | void;
2993
2998
  setThinkingLevel?(level: string): void;
2994
2999
  waitForIdle?(): Promise<void>;
@@ -3003,6 +3008,7 @@ interface PiCreateAgentSessionResult {
3003
3008
  readonly session: PiAgentSession;
3004
3009
  }
3005
3010
  interface PiSdkAgentLoopOptions<TSessionOptions = unknown> {
3011
+ readonly supportsSteering?: boolean;
3006
3012
  readonly createAgentSession: (options: TSessionOptions | undefined) => Promise<PiCreateAgentSessionResult> | PiCreateAgentSessionResult;
3007
3013
  readonly sessionOptions?: TSessionOptions;
3008
3014
  }
@@ -3018,6 +3024,7 @@ interface PiAgentSessionHandle {
3018
3024
  readonly refreshResources?: () => Promise<void> | void;
3019
3025
  }
3020
3026
  interface PiAgentLoopOptions {
3027
+ readonly supportsSteering?: boolean;
3021
3028
  readonly resolveSession: (input: AgentLoopInput) => Promise<PiAgentSessionHandle> | PiAgentSessionHandle;
3022
3029
  readonly modelContentObserver?: AgentModelContentObserver;
3023
3030
  readonly disposeSessionAfterRun?: boolean;
package/dist/chunks/pi.js CHANGED
@@ -4,9 +4,39 @@ import { t as createSha256Digest } from "./sha256-digest.js";
4
4
  import { createHash } from "node:crypto";
5
5
  import { readFile, realpath, stat } from "node:fs/promises";
6
6
  import { isAbsolute, join, relative } from "node:path";
7
- import { DefaultResourceLoader, SettingsManager, createReadToolDefinition } from "@earendil-works/pi-coding-agent";
7
+ import { DefaultResourceLoader, SettingsManager, createBashToolDefinition, createReadToolDefinition, defineTool } from "@earendil-works/pi-coding-agent";
8
8
  import { Unsafe } from "typebox";
9
9
  import { realpathSync, statSync } from "node:fs";
10
+ //#region src/adapters/pi/tool-execution/pi-bash-tool.ts
11
+ const DEFAULT_TIMEOUT_SECONDS = 120;
12
+ /** Keep Pi's native execution, rendering and abort cleanup with a bounded default. */
13
+ function createPiBashTool(cwd, options) {
14
+ const { commandPrefix, shellPath, spawnHook } = options ?? {};
15
+ const tool = createBashToolDefinition(cwd, {
16
+ ...commandPrefix === void 0 ? {} : { commandPrefix },
17
+ ...shellPath === void 0 ? {} : { shellPath },
18
+ ...spawnHook === void 0 ? {} : { spawnHook }
19
+ });
20
+ return defineTool({
21
+ ...tool,
22
+ description: `${tool.description} Defaults to ${DEFAULT_TIMEOUT_SECONDS} seconds when timeout is omitted; set an explicit positive timeout for longer commands.`,
23
+ parameters: {
24
+ ...tool.parameters,
25
+ properties: {
26
+ ...tool.parameters.properties,
27
+ timeout: {
28
+ ...tool.parameters.properties.timeout,
29
+ description: `Timeout in seconds (optional, defaults to ${DEFAULT_TIMEOUT_SECONDS})`
30
+ }
31
+ }
32
+ },
33
+ execute: (id, args, signal, onUpdate, context) => tool.execute(id, {
34
+ ...args,
35
+ timeout: args.timeout === void 0 ? DEFAULT_TIMEOUT_SECONDS : args.timeout
36
+ }, signal, onUpdate, context)
37
+ });
38
+ }
39
+ //#endregion
10
40
  //#region src/adapters/pi/skills/pi-skill-read-tool.ts
11
41
  var ProjectSkillReadDenied = class extends Error {
12
42
  name = "ProjectSkillReadDenied";
@@ -165,12 +195,19 @@ const PI_BEHAVIOR_SETTING_KEYS = Object.freeze([
165
195
  ]);
166
196
  async function createPiSessionResources(options) {
167
197
  const settingsManager = createSanitizedSettingsManager(options.cwd, options.agentDir, options.settingsOverrides);
198
+ const commandPrefix = settingsManager.getShellCommandPrefix();
199
+ const shellPath = settingsManager.getShellPath();
200
+ const bashToolOptions = commandPrefix === void 0 && shellPath === void 0 ? void 0 : Object.freeze({
201
+ ...commandPrefix === void 0 ? {} : { commandPrefix },
202
+ ...shellPath === void 0 ? {} : { shellPath }
203
+ });
168
204
  let skillPaths = await resolveSkillPaths(options);
169
205
  let currentResourceLoader = createResourceLoader(options, settingsManager, skillPaths);
170
206
  await currentResourceLoader.reload();
171
207
  let skillNames = validatePiSkillCatalog(currentResourceLoader.getSkills());
172
208
  const resourceLoader = createResourceLoaderFacade(() => currentResourceLoader, settingsManager);
173
209
  return {
210
+ ...bashToolOptions === void 0 ? {} : { bashToolOptions },
174
211
  get skillNames() {
175
212
  return skillNames;
176
213
  },
@@ -366,4 +403,4 @@ function createPiToolNameResolver(tools) {
366
403
  return createPiToolNameResolver$1(tools);
367
404
  }
368
405
  //#endregion
369
- export { InvalidPiSkillSource as a, validatePiSkillCatalog as c, createPiProjectSkillReadTool as d, createPiSkillReadTool as f, resolvePiSessionToolNames as i, validatePiSkillCommand as l, createPiToolProxyDefinitions as n, resolvePiSkillSources as o, createPiSkillReadTools as p, createPiSessionResources as r, InvalidPiSkillCatalog as s, createPiToolNameResolver as t, ProjectSkillReadDenied as u };
406
+ export { InvalidPiSkillSource as a, validatePiSkillCatalog as c, createPiProjectSkillReadTool as d, createPiSkillReadTool as f, resolvePiSessionToolNames as i, validatePiSkillCommand as l, createPiBashTool as m, createPiToolProxyDefinitions as n, resolvePiSkillSources as o, createPiSkillReadTools as p, createPiSessionResources as r, InvalidPiSkillCatalog as s, createPiToolNameResolver as t, ProjectSkillReadDenied as u };
@@ -2350,7 +2350,7 @@ function createProcessDeploymentAdapterPorts(factories, runEffect) {
2350
2350
  runtimeFactory: { create: (input) => Effect.tryPromise({
2351
2351
  try: () => Promise.resolve(factories.createRuntime(input)),
2352
2352
  catch: toError$3
2353
- }).pipe(Effect.map((runtime) => toDeploymentRuntime(runtime, runEffect))) }
2353
+ }).pipe(Effect.map((runtime) => toEffectAgentRuntime(runtime, runEffect))) }
2354
2354
  };
2355
2355
  }
2356
2356
  function adaptEndpointFactory(create, input, runEffect) {
@@ -2408,19 +2408,6 @@ function adaptBackgroundSessionFactory(create, input, runEffect) {
2408
2408
  catch: toError$3
2409
2409
  });
2410
2410
  }
2411
- function toDeploymentRuntime(runtime, runEffect) {
2412
- const adapted = toEffectAgentRuntime(runtime, runEffect);
2413
- const cancel = adapted.cancel?.bind(adapted);
2414
- const dispose = adapted.dispose?.bind(adapted);
2415
- const steer = adapted.steer?.bind(adapted);
2416
- return {
2417
- ...adapted.concurrency ? { concurrency: adapted.concurrency } : {},
2418
- ...cancel ? { cancel: (input) => cancel(input).pipe(Effect.mapError(toError$3)) } : {},
2419
- ...dispose ? { dispose: () => dispose().pipe(Effect.mapError(toError$3)) } : {},
2420
- run: (input) => adapted.run(input).pipe(Effect.mapError(toError$3)),
2421
- ...steer ? { steer: (input) => steer(input).pipe(Effect.mapError(toError$3)) } : {}
2422
- };
2423
- }
2424
2411
  function toLifecycleAdapter(adapter) {
2425
2412
  return {
2426
2413
  running: () => adapter.running(),
@@ -79,6 +79,18 @@ declare class InvalidRivusPlugin extends Error {
79
79
  readonly name = "InvalidRivusPlugin";
80
80
  }
81
81
  //#endregion
82
+ //#region src/core/application/automation/presentation/automation-line-chart.d.ts
83
+ interface AutomationLineChart {
84
+ readonly title: string;
85
+ readonly labels: ReadonlyArray<string>;
86
+ readonly unit: string;
87
+ readonly seriesLayout?: "overlay" | "separate";
88
+ readonly series: ReadonlyArray<{
89
+ readonly name: string;
90
+ readonly values: ReadonlyArray<number>;
91
+ }>;
92
+ }
93
+ //#endregion
82
94
  //#region src/core/application/automation/presentation/automation-presentation.d.ts
83
95
  declare const AUTOMATION_PRESENTATION_SCHEMA_VERSION: 1;
84
96
  type AutomationPresentationKind = "daily-ai" | "generic" | "industry" | "news" | "subscriptions";
@@ -97,6 +109,7 @@ interface AutomationPresentationSection {
97
109
  readonly title: string;
98
110
  }
99
111
  interface AutomationPresentation {
112
+ readonly lineChart?: AutomationLineChart;
100
113
  readonly footnote?: string;
101
114
  readonly kind?: AutomationPresentationKind;
102
115
  readonly meta: ReadonlyArray<string>;
@@ -106,6 +119,7 @@ interface AutomationPresentation {
106
119
  readonly title: string;
107
120
  }
108
121
  interface AutomationPresentationInput {
122
+ readonly lineChart?: AutomationLineChart;
109
123
  readonly footnote?: string;
110
124
  readonly kind?: AutomationPresentationKind;
111
125
  readonly meta?: ReadonlyArray<string>;