@rivus/agent 0.14.3 → 0.15.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/README.md +1 -1
- package/dist/acp.js +1 -2
- package/dist/bootstrap/pi-feishu.d.ts +2 -2
- package/dist/bootstrap/pi-feishu.js +4119 -389
- package/dist/chunks/agent-loop.d.ts +55 -300
- package/dist/chunks/agent-loop.js +3 -1123
- package/dist/chunks/background-session-authority.js +230 -0
- package/dist/chunks/background-session-control-input.js +51 -0
- package/dist/chunks/background-session-service.d.ts +382 -0
- package/dist/chunks/index.d.ts +1294 -515
- package/dist/chunks/pi-tool-proxy.d.ts +22 -90
- package/dist/chunks/pi.js +60 -20
- package/dist/chunks/rivus-agent-definition-resolver.js +508 -0
- package/dist/chunks/rivus-daemon-cli.js +3004 -3164
- package/dist/chunks/rivus-model-management-wire.js +344 -0
- package/dist/chunks/rivus-plugin-testkit.d.ts +175 -2
- package/dist/chunks/rivus-plugin-testkit.js +11 -4
- package/dist/chunks/rivus-skill.d.ts +95 -0
- package/dist/chunks/rivus-tool.js +158 -0
- package/dist/chunks/sha256-digest.js +2 -7
- package/dist/chunks/src.js +13402 -8264
- package/dist/cli.js +901 -698
- package/dist/index.d.ts +7 -8
- package/dist/index.js +8 -9
- package/dist/mcp.d.ts +46 -7
- package/dist/mcp.js +145 -19
- package/dist/pi.d.ts +5 -4
- package/dist/pi.js +1 -1
- package/examples/pi-feishu-deployment.bootstrap.ts +557 -462
- package/package.json +9 -7
- package/skills/runtime-management/SKILL.md +61 -0
- package/dist/chunks/api.d.ts +0 -70
- package/dist/chunks/api.js +0 -471
- package/dist/chunks/api2.d.ts +0 -387
- package/dist/chunks/api2.js +0 -1331
- package/dist/chunks/api3.d.ts +0 -402
- package/dist/chunks/module.js +0 -267
- package/dist/chunks/pi-skill-tool.js +0 -460
- package/dist/chunks/spi.d.ts +0 -1
- package/dist/chunks/spi.js +0 -2
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ot as RivusToolRisk, rt as RivusToolGrantSet } from "./api2.js";
|
|
1
|
+
import { y as RivusToolRisk } from "./rivus-skill.js";
|
|
3
2
|
import { Effect } from "effect";
|
|
4
3
|
import { TSchema } from "typebox";
|
|
5
4
|
|
|
6
|
-
//#region src/
|
|
5
|
+
//#region src/core/application/tool-execution/authority/invocation-authority-registry.d.ts
|
|
6
|
+
type InvocationMemoryScope = "conversation" | "agent-private" | "project" | "shared-user-profile";
|
|
7
|
+
interface InvocationMemoryAuthority {
|
|
8
|
+
readonly audience: "group" | "private";
|
|
9
|
+
readonly conversationId?: string;
|
|
10
|
+
readonly projectId?: string;
|
|
11
|
+
readonly scopes: ReadonlyArray<InvocationMemoryScope>;
|
|
12
|
+
readonly subjectId: string;
|
|
13
|
+
readonly tenantId: string;
|
|
14
|
+
}
|
|
15
|
+
interface InvocationToolGrantSet {
|
|
16
|
+
readonly revision: string;
|
|
17
|
+
readonly toolIds: ReadonlyArray<string>;
|
|
18
|
+
}
|
|
7
19
|
interface InvocationAuthorityRef {
|
|
8
20
|
readonly id: string;
|
|
9
21
|
}
|
|
@@ -13,84 +25,21 @@ interface InvocationAuthority {
|
|
|
13
25
|
readonly conversationId?: string;
|
|
14
26
|
readonly endpointId?: string;
|
|
15
27
|
readonly instanceId: string;
|
|
16
|
-
readonly memory?:
|
|
28
|
+
readonly memory?: InvocationMemoryAuthority;
|
|
17
29
|
readonly runId: string;
|
|
18
30
|
readonly sessionKey: string;
|
|
19
31
|
readonly sourceMessageId: string;
|
|
20
32
|
readonly tenantKey: string;
|
|
21
|
-
readonly toolGrantSet:
|
|
33
|
+
readonly toolGrantSet: InvocationToolGrantSet;
|
|
22
34
|
}
|
|
23
35
|
declare class InvalidInvocationAuthority extends Error {
|
|
24
36
|
readonly name = "InvalidInvocationAuthority";
|
|
25
37
|
}
|
|
26
38
|
//#endregion
|
|
27
|
-
//#region src/
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/modules/tool-execution/domain/operation/tool-operation.d.ts
|
|
31
|
-
interface ToolOperationBinding {
|
|
32
|
-
readonly agentId: string;
|
|
33
|
-
readonly inputDigest: string;
|
|
34
|
-
readonly instanceId: string;
|
|
35
|
-
readonly sourceMessageId: string;
|
|
36
|
-
readonly toolId: string;
|
|
37
|
-
readonly toolVersion: string;
|
|
38
|
-
}
|
|
39
|
-
type ToolOperationState = {
|
|
40
|
-
readonly status: "pending";
|
|
41
|
-
} | {
|
|
42
|
-
readonly result: unknown;
|
|
43
|
-
readonly status: "completed";
|
|
44
|
-
} | {
|
|
45
|
-
readonly reason: string;
|
|
46
|
-
readonly status: "reconciliation-required";
|
|
47
|
-
} | {
|
|
48
|
-
readonly status: "aborted";
|
|
49
|
-
};
|
|
50
|
-
interface ToolOperationReconciliationAction {
|
|
51
|
-
readonly actorId: string;
|
|
52
|
-
readonly at: string;
|
|
53
|
-
readonly note: string;
|
|
54
|
-
}
|
|
55
|
-
interface ToolOperationReconciliation extends ToolOperationReconciliationAction {
|
|
56
|
-
readonly outcome: "applied" | "not-applied";
|
|
57
|
-
}
|
|
58
|
-
interface ToolOperationRecord {
|
|
59
|
-
readonly binding: ToolOperationBinding;
|
|
60
|
-
readonly operationId: string;
|
|
61
|
-
readonly reconciliation?: ToolOperationReconciliation;
|
|
62
|
-
readonly revision: number;
|
|
63
|
-
readonly state: ToolOperationState;
|
|
64
|
-
}
|
|
65
|
-
type ToolOperationReconciliationOutcome = {
|
|
66
|
-
readonly result: unknown;
|
|
67
|
-
readonly status: "applied";
|
|
68
|
-
} | {
|
|
69
|
-
readonly status: "not-applied";
|
|
70
|
-
};
|
|
71
|
-
type ToolOperationBeginResult = {
|
|
72
|
-
readonly status: "acquired";
|
|
73
|
-
} | {
|
|
74
|
-
readonly result: unknown;
|
|
75
|
-
readonly status: "completed";
|
|
76
|
-
} | {
|
|
77
|
-
readonly status: "blocked";
|
|
78
|
-
readonly reason: string;
|
|
79
|
-
};
|
|
80
|
-
type ToolOperationInspectResult = {
|
|
81
|
-
readonly status: "missing";
|
|
82
|
-
} | {
|
|
83
|
-
readonly result: unknown;
|
|
84
|
-
readonly status: "completed";
|
|
85
|
-
} | {
|
|
86
|
-
readonly status: "blocked";
|
|
87
|
-
readonly reason: string;
|
|
88
|
-
};
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/modules/tool-execution/application/authority/invocation-authority-registry.d.ts
|
|
91
|
-
declare function createInvocationAuthority(authority: InvocationAuthority): InvocationAuthorityRef;
|
|
39
|
+
//#region src/core/application/tool-execution/authority/tool-risk-policy.d.ts
|
|
40
|
+
type ToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
|
|
92
41
|
//#endregion
|
|
93
|
-
//#region src/
|
|
42
|
+
//#region src/core/application/tool-execution/brokerage/tool-broker-ports.d.ts
|
|
94
43
|
interface AuthorizationPolicyState {
|
|
95
44
|
readonly epoch: number;
|
|
96
45
|
readonly revokedToolIds: ReadonlyArray<string>;
|
|
@@ -107,10 +56,8 @@ interface ToolApprovalRequest {
|
|
|
107
56
|
readonly callId: string;
|
|
108
57
|
readonly toolId: string;
|
|
109
58
|
readonly toolVersion: string;
|
|
110
|
-
readonly risk:
|
|
59
|
+
readonly risk: ToolRisk;
|
|
111
60
|
}
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/modules/tool-execution/application/brokerage/tool-broker.d.ts
|
|
114
61
|
interface ToolExecutionRequest {
|
|
115
62
|
readonly approvalId?: string;
|
|
116
63
|
readonly authority: InvocationAuthorityRef;
|
|
@@ -120,21 +67,6 @@ interface ToolExecutionRequest {
|
|
|
120
67
|
readonly toolId: string;
|
|
121
68
|
readonly version: string;
|
|
122
69
|
}
|
|
123
|
-
declare class ToolInvocationDenied extends Error {
|
|
124
|
-
readonly name = "ToolInvocationDenied";
|
|
125
|
-
}
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/modules/tool-execution/domain/input/stable-tool-input.d.ts
|
|
128
|
-
declare class InvalidStableJson extends Error {
|
|
129
|
-
readonly name: string;
|
|
130
|
-
}
|
|
131
|
-
declare class InvalidToolInput extends InvalidStableJson {
|
|
132
|
-
readonly name = "InvalidToolInput";
|
|
133
|
-
}
|
|
134
|
-
declare function normalizeStableJson(value: unknown): unknown;
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region src/modules/tool-execution/application/brokerage/tool-input-digest.d.ts
|
|
137
|
-
declare function createToolInputDigest(input: unknown): string;
|
|
138
70
|
//#endregion
|
|
139
71
|
//#region src/adapters/pi/tool-execution/pi-tool-definition.d.ts
|
|
140
72
|
type PiToolContent = {
|
|
@@ -185,4 +117,4 @@ interface PiToolApprovalGateway {
|
|
|
185
117
|
requestApproval(request: PiToolApprovalRequest): Promise<void>;
|
|
186
118
|
}
|
|
187
119
|
//#endregion
|
|
188
|
-
export {
|
|
120
|
+
export { PiToolResult as a, ToolExecutionRequest as c, InvocationAuthorityRef as d, PiToolDefinition as i, InvalidInvocationAuthority as l, PiToolApprovalRequest as n, AuthorizationPolicyState as o, PiToolContent as r, ToolApprovalRequest as s, PiToolApprovalGateway as t, InvocationAuthority as u };
|
package/dist/chunks/pi.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { l as toEffectAgentLoopInput } from "./agent-loop.js";
|
|
2
|
-
import "./
|
|
3
|
-
import {
|
|
2
|
+
import { i as requiresToolApproval, s as createToolInputDigest$1, u as createInvocationAuthority } from "./rivus-tool.js";
|
|
3
|
+
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
7
|
import { DefaultResourceLoader, SettingsManager, createReadToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { realpathSync, statSync } from "node:fs";
|
|
9
8
|
import { Unsafe } from "typebox";
|
|
9
|
+
import { realpathSync, statSync } from "node:fs";
|
|
10
10
|
//#region src/adapters/pi/skills/pi-skill-read-tool.ts
|
|
11
11
|
var ProjectSkillReadDenied = class extends Error {
|
|
12
12
|
name = "ProjectSkillReadDenied";
|
|
@@ -164,13 +164,62 @@ const PI_BEHAVIOR_SETTING_KEYS = Object.freeze([
|
|
|
164
164
|
"websocketConnectTimeoutMs"
|
|
165
165
|
]);
|
|
166
166
|
async function createPiSessionResources(options) {
|
|
167
|
-
const settingsManager = createSanitizedSettingsManager(options.cwd, options.agentDir);
|
|
168
|
-
|
|
167
|
+
const settingsManager = createSanitizedSettingsManager(options.cwd, options.agentDir, options.settingsOverrides);
|
|
168
|
+
let skillPaths = await resolveSkillPaths(options);
|
|
169
|
+
let currentResourceLoader = createResourceLoader(options, settingsManager, skillPaths);
|
|
170
|
+
await currentResourceLoader.reload();
|
|
171
|
+
let skillNames = validatePiSkillCatalog(currentResourceLoader.getSkills());
|
|
172
|
+
const resourceLoader = createResourceLoaderFacade(() => currentResourceLoader, settingsManager);
|
|
173
|
+
return {
|
|
174
|
+
get skillNames() {
|
|
175
|
+
return skillNames;
|
|
176
|
+
},
|
|
177
|
+
get skillPaths() {
|
|
178
|
+
return skillPaths;
|
|
179
|
+
},
|
|
180
|
+
refresh: async () => {
|
|
181
|
+
const nextSkillPaths = await resolveSkillPaths(options);
|
|
182
|
+
const nextResourceLoader = createResourceLoader(options, settingsManager, nextSkillPaths);
|
|
183
|
+
await nextResourceLoader.reload();
|
|
184
|
+
const nextSkillNames = validatePiSkillCatalog(nextResourceLoader.getSkills());
|
|
185
|
+
skillPaths = nextSkillPaths;
|
|
186
|
+
currentResourceLoader = nextResourceLoader;
|
|
187
|
+
skillNames = nextSkillNames;
|
|
188
|
+
},
|
|
189
|
+
withSessionOptions: (sessionOptions) => Object.freeze({
|
|
190
|
+
...sessionOptions,
|
|
191
|
+
agentDir: options.agentDir,
|
|
192
|
+
cwd: options.cwd,
|
|
193
|
+
resourceLoader,
|
|
194
|
+
settingsManager
|
|
195
|
+
})
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function createResourceLoaderFacade(getCurrent, settingsManager) {
|
|
199
|
+
return {
|
|
200
|
+
extendResources: (paths) => getCurrent().extendResources(paths),
|
|
201
|
+
getAgentsFiles: () => getCurrent().getAgentsFiles(),
|
|
202
|
+
getAppendSystemPrompt: () => getCurrent().getAppendSystemPrompt(),
|
|
203
|
+
getAppendSystemPromptSources: () => getCurrent().getAppendSystemPromptSources(),
|
|
204
|
+
getExtensions: () => getCurrent().getExtensions(),
|
|
205
|
+
getPrompts: () => getCurrent().getPrompts(),
|
|
206
|
+
getSkills: () => getCurrent().getSkills(),
|
|
207
|
+
getSystemPrompt: () => getCurrent().getSystemPrompt(),
|
|
208
|
+
getSystemPromptSource: () => getCurrent().getSystemPromptSource(),
|
|
209
|
+
getThemes: () => getCurrent().getThemes(),
|
|
210
|
+
reload: (reloadOptions) => getCurrent().reload(reloadOptions),
|
|
211
|
+
settingsManager
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async function resolveSkillPaths(options) {
|
|
215
|
+
return resolvePiSkillSources({
|
|
169
216
|
agentDir: options.agentDir,
|
|
170
217
|
homeDirectory: options.homeDirectory,
|
|
171
218
|
...options.projectSkillPaths ? { projectSkillPaths: options.projectSkillPaths } : {}
|
|
172
219
|
});
|
|
173
|
-
|
|
220
|
+
}
|
|
221
|
+
function createResourceLoader(options, settingsManager, skillPaths) {
|
|
222
|
+
return new DefaultResourceLoader({
|
|
174
223
|
agentDir: options.agentDir,
|
|
175
224
|
additionalSkillPaths: [...skillPaths],
|
|
176
225
|
...options.appendSystemPromptOverride ? { appendSystemPromptOverride: options.appendSystemPromptOverride } : {},
|
|
@@ -183,23 +232,11 @@ async function createPiSessionResources(options) {
|
|
|
183
232
|
settingsManager,
|
|
184
233
|
...options.systemPromptOverride ? { systemPromptOverride: options.systemPromptOverride } : {}
|
|
185
234
|
});
|
|
186
|
-
await resourceLoader.reload();
|
|
187
|
-
const skillNames = validatePiSkillCatalog(resourceLoader.getSkills());
|
|
188
|
-
return Object.freeze({
|
|
189
|
-
skillNames,
|
|
190
|
-
skillPaths,
|
|
191
|
-
withSessionOptions: (sessionOptions) => Object.freeze({
|
|
192
|
-
...sessionOptions,
|
|
193
|
-
agentDir: options.agentDir,
|
|
194
|
-
cwd: options.cwd,
|
|
195
|
-
resourceLoader,
|
|
196
|
-
settingsManager
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
235
|
}
|
|
200
|
-
function createSanitizedSettingsManager(cwd, agentDir) {
|
|
236
|
+
function createSanitizedSettingsManager(cwd, agentDir, settingsOverrides) {
|
|
201
237
|
const fileSettings = SettingsManager.create(cwd, agentDir, { projectTrusted: false }).getGlobalSettings();
|
|
202
238
|
const behaviorSettings = Object.fromEntries(PI_BEHAVIOR_SETTING_KEYS.flatMap((key) => fileSettings[key] === void 0 ? [] : [[key, fileSettings[key]]]));
|
|
239
|
+
for (const key of PI_BEHAVIOR_SETTING_KEYS) if (settingsOverrides?.[key] !== void 0) behaviorSettings[key] = settingsOverrides[key];
|
|
203
240
|
return SettingsManager.inMemory(behaviorSettings, { projectTrusted: false });
|
|
204
241
|
}
|
|
205
242
|
//#endregion
|
|
@@ -294,6 +331,9 @@ function createPiToolProxyDefinitions$1(options) {
|
|
|
294
331
|
};
|
|
295
332
|
});
|
|
296
333
|
}
|
|
334
|
+
function createToolInputDigest(input) {
|
|
335
|
+
return createToolInputDigest$1(input, createSha256Digest);
|
|
336
|
+
}
|
|
297
337
|
function createPiToolNameResolver$1(tools) {
|
|
298
338
|
const toolIdsByPiName = new Map(tools.map((tool) => [toPiToolName(tool.id), tool.id]));
|
|
299
339
|
return (toolName) => toolIdsByPiName.get(toolName) ?? toolName;
|