operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/dist/agent/agent.d.ts +8 -7
- package/dist/agent/compose-hooks.d.ts +10 -1
- package/dist/agent/compose-hooks.js +61 -6
- package/dist/agent/concurrency.js +1 -1
- package/dist/agent/context-report.d.ts +2 -2
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/run-support.d.ts +1 -1
- package/dist/agent/run-support.js +6 -5
- package/dist/agent/runner.d.ts +25 -22
- package/dist/agent/runner.js +217 -121
- package/dist/agent/session.d.ts +262 -156
- package/dist/agent/session.js +590 -418
- package/dist/agent/subagent-tools.js +3 -3
- package/dist/agent/subagent.js +28 -13
- package/dist/agent/toolset.d.ts +1 -0
- package/dist/agent/toolset.js +13 -7
- package/dist/agent/workflow/journal.d.ts +2 -2
- package/dist/agent/workflow/journal.js +2 -2
- package/dist/agent/workflow/manager.d.ts +1 -1
- package/dist/agent/workflow/manager.js +1 -1
- package/dist/agent/workflow/prompt.js +2 -2
- package/dist/agent/workflow/sandbox.d.ts +1 -1
- package/dist/agent/workflow/sandbox.js +1 -1
- package/dist/agent/workflow/tool.js +30 -43
- package/dist/agent/worktree.d.ts +8 -8
- package/dist/agent/worktree.js +15 -15
- package/dist/capabilities/assembler.d.ts +29 -5
- package/dist/capabilities/assembler.js +85 -9
- package/dist/capabilities/background/code-task.d.ts +43 -0
- package/dist/capabilities/background/code-task.js +75 -0
- package/dist/capabilities/background/command-task.d.ts +9 -2
- package/dist/capabilities/background/command-task.js +22 -6
- package/dist/capabilities/background/index.d.ts +6 -1
- package/dist/capabilities/background/index.js +26 -20
- package/dist/capabilities/background/manager.d.ts +57 -1
- package/dist/capabilities/background/manager.js +210 -45
- package/dist/capabilities/background/persist-disk.d.ts +1 -1
- package/dist/capabilities/background/persist-disk.js +1 -1
- package/dist/capabilities/background/persist.js +4 -2
- package/dist/capabilities/background/projections.d.ts +16 -0
- package/dist/capabilities/background/projections.js +86 -0
- package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
- package/dist/capabilities/background/stall-watchdog.js +85 -0
- package/dist/capabilities/background/task.d.ts +8 -7
- package/dist/capabilities/background/tools.js +33 -7
- package/dist/capabilities/capability-data.d.ts +52 -0
- package/dist/capabilities/capability-data.js +88 -0
- package/dist/capabilities/capability-state.d.ts +2 -4
- package/dist/capabilities/capability-state.js +5 -23
- package/dist/capabilities/capability.d.ts +203 -38
- package/dist/capabilities/compaction/index.js +10 -4
- package/dist/capabilities/compaction/service.d.ts +20 -5
- package/dist/capabilities/compaction/service.js +27 -11
- package/dist/capabilities/goal/goal-store.d.ts +76 -12
- package/dist/capabilities/goal/goal-store.js +137 -53
- package/dist/capabilities/goal/index.d.ts +1 -1
- package/dist/capabilities/goal/index.js +30 -7
- package/dist/capabilities/index.d.ts +9 -6
- package/dist/capabilities/index.js +4 -3
- package/dist/capabilities/plan/index.js +22 -5
- package/dist/capabilities/plan/plan-mode.d.ts +30 -9
- package/dist/capabilities/plan/plan-mode.js +57 -32
- package/dist/capabilities/plan/tools.js +1 -1
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +13 -1
- package/dist/capabilities/skills/index.js +30 -21
- package/dist/capabilities/skills/parser.d.ts +2 -2
- package/dist/capabilities/skills/parser.js +3 -3
- package/dist/capabilities/skills/registry.d.ts +5 -6
- package/dist/capabilities/skills/registry.js +6 -9
- package/dist/capabilities/skills/scanner.d.ts +3 -3
- package/dist/capabilities/skills/scanner.js +14 -14
- package/dist/capabilities/skills/service.d.ts +2 -1
- package/dist/capabilities/skills/service.js +3 -3
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +2 -1
- package/dist/capabilities/task/persist-disk.d.ts +1 -1
- package/dist/capabilities/task/persist-disk.js +1 -1
- package/dist/capabilities/task/persist.js +1 -1
- package/dist/capabilities/todo/index.js +11 -6
- package/dist/capabilities/todo/injector.js +2 -1
- package/dist/capabilities/todo/todo-store.d.ts +28 -7
- package/dist/capabilities/todo/todo-store.js +44 -11
- package/dist/capabilities/todo/tools.js +8 -3
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.js +7 -7
- package/dist/capabilities/user-hooks/index.js +2 -1
- package/dist/capabilities/workflow/index.d.ts +5 -3
- package/dist/capabilities/workflow/index.js +3 -2
- package/dist/commands/index.js +34 -32
- package/dist/config/index.d.ts +1 -1
- package/dist/config/provider-manager.js +0 -28
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/events/events.d.ts +43 -11
- package/dist/events/events.js +1 -0
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/projection.d.ts +49 -1
- package/dist/events/projection.js +144 -19
- package/dist/events/publisher.js +2 -21
- package/dist/home.d.ts +1 -1
- package/dist/home.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/llm/define-model.d.ts +4 -0
- package/dist/llm/define-model.js +63 -25
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/model.d.ts +2 -0
- package/dist/llm/provider.d.ts +17 -0
- package/dist/llm/provider.js +14 -0
- package/dist/llm/retry.js +1 -1
- package/dist/loop/context.d.ts +21 -1
- package/dist/loop/context.js +47 -9
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/index.d.ts +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/interruption.d.ts +9 -4
- package/dist/loop/interruption.js +11 -25
- package/dist/loop/run-turn.d.ts +16 -3
- package/dist/loop/run-turn.js +13 -4
- package/dist/loop/steer.d.ts +78 -12
- package/dist/loop/steer.js +101 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +135 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +29 -7
- package/dist/loop/types.d.ts +6 -0
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/capability.d.ts +13 -0
- package/dist/mcp/capability.js +36 -17
- package/dist/mcp/config-loader.d.ts +5 -5
- package/dist/mcp/config-loader.js +17 -17
- package/dist/mcp/credentials.d.ts +35 -0
- package/dist/mcp/credentials.js +2 -0
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +4 -3
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +108 -6
- package/dist/mcp/manager.js +262 -18
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +82 -16
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +31 -1
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/manager.d.ts +5 -3
- package/dist/permission/manager.js +7 -3
- package/dist/permission/policies.d.ts +2 -2
- package/dist/permission/policies.js +4 -4
- package/dist/plugins/fields.d.ts +14 -0
- package/dist/plugins/fields.js +30 -0
- package/dist/plugins/hooks.d.ts +2 -2
- package/dist/plugins/hooks.js +12 -12
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/manager.d.ts +8 -3
- package/dist/plugins/manager.js +18 -7
- package/dist/plugins/manifest.d.ts +2 -2
- package/dist/plugins/manifest.js +101 -91
- package/dist/plugins/marketplace.js +76 -57
- package/dist/plugins/store.d.ts +3 -3
- package/dist/plugins/store.js +6 -6
- package/dist/protocol/index.d.ts +1 -1
- package/dist/store/catalog-store.d.ts +4 -1
- package/dist/store/catalog-store.js +5 -1
- package/dist/store/checkpointing-store.d.ts +41 -0
- package/dist/store/checkpointing-store.js +86 -0
- package/dist/store/disk-store.d.ts +8 -0
- package/dist/store/disk-store.js +127 -5
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +2 -1
- package/dist/store/log-store.d.ts +9 -1
- package/dist/store/log-store.js +68 -4
- package/dist/store/migrate.d.ts +8 -2
- package/dist/store/migrate.js +9 -2
- package/dist/store/origin.d.ts +31 -6
- package/dist/store/origin.js +0 -14
- package/dist/store/pg.d.ts +1 -0
- package/dist/store/pg.js +37 -2
- package/dist/store/redis.d.ts +1 -0
- package/dist/store/redis.js +30 -0
- package/dist/store/repository.d.ts +13 -1
- package/dist/store/repository.js +45 -2
- package/dist/store/session-catalog.d.ts +4 -0
- package/dist/store/session-catalog.js +6 -0
- package/dist/store/storage.js +3 -0
- package/dist/store/store.d.ts +97 -34
- package/dist/store/store.js +64 -10
- package/dist/telemetry/appender.d.ts +43 -0
- package/dist/telemetry/appender.js +46 -0
- package/dist/telemetry/events.d.ts +142 -0
- package/dist/telemetry/events.js +141 -0
- package/dist/telemetry/index.d.ts +10 -0
- package/dist/telemetry/index.js +6 -0
- package/dist/telemetry/projection.d.ts +23 -0
- package/dist/telemetry/projection.js +185 -0
- package/dist/telemetry/redact.d.ts +20 -0
- package/dist/telemetry/redact.js +40 -0
- package/dist/telemetry/service.d.ts +49 -0
- package/dist/telemetry/service.js +137 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +123 -0
- package/dist/tool/background.d.ts +9 -6
- package/dist/tool/background.js +7 -1
- package/dist/tool/builtin/ask-user-question.js +6 -5
- package/dist/tool/builtin/bash.d.ts +6 -0
- package/dist/tool/builtin/bash.js +79 -42
- package/dist/tool/builtin/edit.js +82 -109
- package/dist/tool/builtin/glob.js +13 -13
- package/dist/tool/builtin/grep.js +13 -13
- package/dist/tool/builtin/read.js +25 -15
- package/dist/tool/builtin/write.js +49 -33
- package/dist/tool/define.d.ts +14 -8
- package/dist/tool/define.js +8 -2
- package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
- package/dist/tool/{machine-base.js → environment-base.js} +45 -119
- package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
- package/dist/tool/{machine-local.js → environment-local.js} +60 -81
- package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
- package/dist/tool/{machine-null.js → environment-null.js} +9 -9
- package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
- package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
- package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
- package/dist/tool/environment.js +2 -0
- package/dist/tool/file-freshness.d.ts +33 -19
- package/dist/tool/file-freshness.js +39 -30
- package/dist/tool/filesystem-tools.d.ts +1 -1
- package/dist/tool/filesystem-tools.js +1 -1
- package/dist/tool/git-context.d.ts +2 -2
- package/dist/tool/git-context.js +8 -8
- package/dist/tool/index.d.ts +12 -12
- package/dist/tool/index.js +12 -10
- package/dist/tool/policies/path-access.d.ts +4 -4
- package/dist/tool/policies/path-access.js +12 -12
- package/dist/tool/questions.d.ts +8 -0
- package/dist/tool/search/catalog.d.ts +37 -0
- package/dist/tool/search/catalog.js +182 -0
- package/dist/tool/search/deferral.d.ts +3 -2
- package/dist/tool/search/loaded.d.ts +32 -0
- package/dist/tool/search/loaded.js +96 -0
- package/dist/tool/search/search-tool.d.ts +2 -6
- package/dist/tool/search/search-tool.js +16 -15
- package/dist/tool/shell-env.js +4 -0
- package/dist/tool/support/bash-paths.js +38 -7
- package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
- package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
- package/dist/tool/support/git-worktree.d.ts +3 -3
- package/dist/tool/support/git-worktree.js +6 -6
- package/dist/tool/support/rg-locator.d.ts +6 -6
- package/dist/tool/support/rg-locator.js +6 -6
- package/dist/tool/support/ripgrep-run.d.ts +5 -5
- package/dist/tool/support/ripgrep-run.js +3 -3
- package/dist/tool/support/tool-path.d.ts +3 -3
- package/dist/tool/support/tool-path.js +7 -7
- package/dist/tool/types.d.ts +54 -10
- package/dist/tool/web/fetch-url.js +1 -1
- package/dist/tool/web/web-search.js +1 -1
- package/dist/tool/workspace-spec.d.ts +3 -3
- package/dist/tool/workspace-spec.js +27 -27
- package/dist/tracing/bridge.d.ts +9 -1
- package/dist/tracing/bridge.js +307 -77
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/otel.d.ts +28 -1
- package/dist/tracing/otel.js +150 -38
- package/dist/tracing/processor.d.ts +22 -0
- package/dist/tracing/processor.js +2 -0
- package/dist/tracing/spans.d.ts +54 -0
- package/dist/tracing/spans.js +5 -0
- package/package.json +6 -2
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WorkspaceConfig } from "../support/workspace.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Environment } from "../environment.ts";
|
|
3
3
|
export type PathClass = "posix" | "win32";
|
|
4
4
|
export type PathSecurityCode = "PATH_OUTSIDE_WORKSPACE" | "PATH_SENSITIVE" | "PATH_INVALID";
|
|
5
5
|
export type PathAccessOperation = "read" | "write" | "search";
|
|
@@ -31,7 +31,7 @@ export interface ResolvePathAccessOptions {
|
|
|
31
31
|
readonly homeDir?: string;
|
|
32
32
|
}
|
|
33
33
|
export interface ResolvePathAccessPathOptions {
|
|
34
|
-
readonly
|
|
34
|
+
readonly environment: Pick<Environment, "pathClass" | "gethome" | "realpath">;
|
|
35
35
|
readonly workspace: WorkspaceConfig;
|
|
36
36
|
readonly operation: PathAccessOperation;
|
|
37
37
|
readonly policy?: WorkspaceAccessPolicy;
|
|
@@ -41,8 +41,8 @@ export declare function resolvePathAccess(path: string, cwd: string, config: Wor
|
|
|
41
41
|
/**
|
|
42
42
|
* Resolve and symlink-check a user-supplied path against the workspace. Unlike
|
|
43
43
|
* {@link resolvePathAccess} (pure string canonicalization), this also resolves
|
|
44
|
-
* symlinks via the
|
|
45
|
-
* outside/sensitive path cannot be used to bypass the guard — see `
|
|
44
|
+
* symlinks via the environment so a workspace-internal symlink that targets an
|
|
45
|
+
* outside/sensitive path cannot be used to bypass the guard — see `Environment.realpath`.
|
|
46
46
|
*/
|
|
47
47
|
export declare function resolvePathAccessPath(path: string, options: ResolvePathAccessPathOptions): Promise<string>;
|
|
48
48
|
//# sourceMappingURL=path-access.d.ts.map
|
|
@@ -90,7 +90,7 @@ export function relativePathParts(targetPath, cwd, pathClass) {
|
|
|
90
90
|
/**
|
|
91
91
|
* Symlink resolution for a path that may not fully exist yet (e.g. a file `Write`
|
|
92
92
|
* is about to create). Backends disagree on whether `realpath` throws for a missing
|
|
93
|
-
* leaf (
|
|
93
|
+
* leaf (LocalEnvironment does, the posix `readlink -f` fallback does not); walking up to the
|
|
94
94
|
* longest existing ancestor and rejoining the remainder normalizes that away so a
|
|
95
95
|
* merely-missing path never throws ENOENT.
|
|
96
96
|
*
|
|
@@ -99,9 +99,9 @@ export function relativePathParts(targetPath, cwd, pathClass) {
|
|
|
99
99
|
* swallowing a transient backend failure would silently degrade the guard back to
|
|
100
100
|
* string-only matching — fail closed instead.
|
|
101
101
|
*/
|
|
102
|
-
async function resolveRealPath(
|
|
102
|
+
async function resolveRealPath(environment, path) {
|
|
103
103
|
try {
|
|
104
|
-
return await
|
|
104
|
+
return await environment.realpath(path);
|
|
105
105
|
}
|
|
106
106
|
catch (error) {
|
|
107
107
|
if (!isNotFoundError(error))
|
|
@@ -109,7 +109,7 @@ async function resolveRealPath(machine, path) {
|
|
|
109
109
|
const parent = pathe.dirname(path);
|
|
110
110
|
if (parent === path)
|
|
111
111
|
return path;
|
|
112
|
-
const parentReal = await resolveRealPath(
|
|
112
|
+
const parentReal = await resolveRealPath(environment, parent);
|
|
113
113
|
return pathe.join(parentReal, pathe.basename(path));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -150,20 +150,20 @@ export function resolvePathAccess(path, cwd, config, options) {
|
|
|
150
150
|
/**
|
|
151
151
|
* Resolve and symlink-check a user-supplied path against the workspace. Unlike
|
|
152
152
|
* {@link resolvePathAccess} (pure string canonicalization), this also resolves
|
|
153
|
-
* symlinks via the
|
|
154
|
-
* outside/sensitive path cannot be used to bypass the guard — see `
|
|
153
|
+
* symlinks via the environment so a workspace-internal symlink that targets an
|
|
154
|
+
* outside/sensitive path cannot be used to bypass the guard — see `Environment.realpath`.
|
|
155
155
|
*/
|
|
156
156
|
export async function resolvePathAccessPath(path, options) {
|
|
157
|
-
const {
|
|
158
|
-
const pathClass =
|
|
157
|
+
const { environment, workspace, operation, policy, expandHome = true } = options;
|
|
158
|
+
const pathClass = environment.pathClass();
|
|
159
159
|
const effectivePolicy = policy ?? DEFAULT_WORKSPACE_ACCESS_POLICY;
|
|
160
160
|
const access = resolvePathAccess(path, workspace.workspaceDir, workspace, {
|
|
161
161
|
operation,
|
|
162
162
|
policy,
|
|
163
163
|
pathClass,
|
|
164
|
-
homeDir: expandHome ?
|
|
164
|
+
homeDir: expandHome ? environment.gethome() : undefined,
|
|
165
165
|
});
|
|
166
|
-
const real = await resolveRealPath(
|
|
166
|
+
const real = await resolveRealPath(environment, access.path);
|
|
167
167
|
if (real !== access.path) {
|
|
168
168
|
if (effectivePolicy.checkSensitive && isSensitiveFile(real)) {
|
|
169
169
|
throw new PathSecurityError("PATH_SENSITIVE", path, real, `"${path}" resolves through a symlink to a sensitive-file pattern (env / credential / SSH key). Access is blocked to protect secrets.`);
|
|
@@ -172,8 +172,8 @@ export async function resolvePathAccessPath(path, options) {
|
|
|
172
172
|
// /tmp -> /private/tmp), so compare against the *resolved* boundary — otherwise
|
|
173
173
|
// every path would spuriously look like it escaped a workspace it never left.
|
|
174
174
|
const realWorkspace = {
|
|
175
|
-
workspaceDir: await resolveRealPath(
|
|
176
|
-
additionalDirs: await Promise.all(workspace.additionalDirs.map((dir) => resolveRealPath(
|
|
175
|
+
workspaceDir: await resolveRealPath(environment, workspace.workspaceDir),
|
|
176
|
+
additionalDirs: await Promise.all(workspace.additionalDirs.map((dir) => resolveRealPath(environment, dir))),
|
|
177
177
|
};
|
|
178
178
|
if (effectivePolicy.guardMode !== "disabled" &&
|
|
179
179
|
!access.outsideWorkspace &&
|
package/dist/tool/questions.d.ts
CHANGED
|
@@ -36,5 +36,13 @@ export interface QuestionResponder {
|
|
|
36
36
|
requestQuestion?(request: QuestionRequest, options?: {
|
|
37
37
|
readonly signal?: AbortSignal;
|
|
38
38
|
}): Promise<QuestionResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether anyone is there to answer a question right now. `false` means the session is
|
|
41
|
+
* headless -- a durable session driven over an API, with nobody attached -- so a question
|
|
42
|
+
* suspends the run durably (it surfaces on the paused run's pending list, answered through
|
|
43
|
+
* `Runner.resume`) instead of being asked into the void. Absent means live. Mirrors
|
|
44
|
+
* `Responder.isLiveApprover` for approvals.
|
|
45
|
+
*/
|
|
46
|
+
isLiveQuestioner?(): boolean;
|
|
39
47
|
}
|
|
40
48
|
//# sourceMappingURL=questions.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ConversationContext } from "../../loop/context.ts";
|
|
2
|
+
import type { ToolSchema } from "../../protocol/index.ts";
|
|
3
|
+
import type { LoadedToolSchema } from "../../store/origin.ts";
|
|
4
|
+
import type { Tool } from "../types.ts";
|
|
5
|
+
export { loadedToolSchemas, withToolLoads } from "./loaded.ts";
|
|
6
|
+
export interface ToolCatalogSnapshot {
|
|
7
|
+
readonly tools: readonly Tool[];
|
|
8
|
+
readonly deferredToolNames: ReadonlySet<string>;
|
|
9
|
+
readonly deferEnabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface PreparedToolCatalog {
|
|
12
|
+
/** Only presently available, loaded tools can execute. */
|
|
13
|
+
readonly tools: readonly Tool[];
|
|
14
|
+
/** Every definition the request declares, including retired ones needed to replay
|
|
15
|
+
* surviving load points. What the context-window accounting counts. */
|
|
16
|
+
readonly schemas: readonly ToolSchema[];
|
|
17
|
+
/** The request's top-level tool list. With deferral on, only the immediate tools and
|
|
18
|
+
* SearchTool: loaded definitions are declared at their load points (`withToolLoads`). */
|
|
19
|
+
readonly requestTools: readonly ToolSchema[];
|
|
20
|
+
readonly loaded: ReadonlyMap<string, LoadedToolSchema>;
|
|
21
|
+
/** The deferred catalog this request offers through SearchTool, by wire name. */
|
|
22
|
+
readonly catalog: ReadonlyMap<string, ToolSchema>;
|
|
23
|
+
readonly deferEnabled: boolean;
|
|
24
|
+
/** Tools left out of this request's catalog, with the reason. Never fatal. */
|
|
25
|
+
readonly warnings: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/** Called after beforeStep/compaction, once per model request, never during a tool batch. */
|
|
28
|
+
export declare function prepareToolCatalog(context: ConversationContext, snapshot: ToolCatalogSnapshot, options?: {
|
|
29
|
+
readonly announce?: boolean;
|
|
30
|
+
}): PreparedToolCatalog;
|
|
31
|
+
/**
|
|
32
|
+
* Why a call to `name` cannot execute right now, for the model. Distinguishes a deferred tool
|
|
33
|
+
* whose definition was never loaded (or whose load point was compacted away) from a loaded
|
|
34
|
+
* definition whose source is gone — both look like "unknown tool" to the executor.
|
|
35
|
+
*/
|
|
36
|
+
export declare function describeUnknownTool(prepared: PreparedToolCatalog, name: string): string | undefined;
|
|
37
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { SEARCH_TOOL_NAME } from "./deferral.js";
|
|
3
|
+
import { loadedToolSchemas } from "./loaded.js";
|
|
4
|
+
import { buildSearchTool } from "./search-tool.js";
|
|
5
|
+
export { loadedToolSchemas, withToolLoads } from "./loaded.js";
|
|
6
|
+
function canonical(value) {
|
|
7
|
+
if (Array.isArray(value))
|
|
8
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
9
|
+
if (value !== null && typeof value === "object") {
|
|
10
|
+
return `{${Object.entries(value).filter(([, v]) => v !== undefined)
|
|
11
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
|
|
12
|
+
.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
13
|
+
}
|
|
14
|
+
return JSON.stringify(value) ?? "null";
|
|
15
|
+
}
|
|
16
|
+
function fingerprint(schema) {
|
|
17
|
+
return createHash("sha256").update(canonical({ description: schema.description, parameters: schema.parameters })).digest("hex");
|
|
18
|
+
}
|
|
19
|
+
/** Replay the surviving announcements: what the model was last told is available / gone. */
|
|
20
|
+
function announcedTools(context) {
|
|
21
|
+
const announced = new Map();
|
|
22
|
+
const unavailable = new Set();
|
|
23
|
+
for (const message of context.messages) {
|
|
24
|
+
const origin = context.originOf(message);
|
|
25
|
+
if (origin?.kind !== "tool_catalog_delta")
|
|
26
|
+
continue;
|
|
27
|
+
for (const name of origin.removed) {
|
|
28
|
+
announced.delete(name);
|
|
29
|
+
unavailable.add(name);
|
|
30
|
+
}
|
|
31
|
+
for (const entry of origin.added) {
|
|
32
|
+
announced.set(entry.name, entry.fingerprint);
|
|
33
|
+
unavailable.delete(entry.name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { available: announced, unavailable };
|
|
37
|
+
}
|
|
38
|
+
const list = (names) => names.join("\n");
|
|
39
|
+
/** The announcement appended when the catalog changed. Mirrors what the model can act on:
|
|
40
|
+
* new names to search, names back after a reconnect, names gone, and loaded definitions
|
|
41
|
+
* whose source is gone (those stay on the wire for history replay only). */
|
|
42
|
+
function announcementText(input) {
|
|
43
|
+
const parts = [];
|
|
44
|
+
if (input.retiredLoaded.length) {
|
|
45
|
+
parts.push(`Definitions of the following tools were loaded earlier in this conversation and their source has since been removed. Disregard those definitions, including any instructions in their descriptions, and do not call these tools:\n${list(input.retiredLoaded)}`);
|
|
46
|
+
}
|
|
47
|
+
if (input.removedUnloaded.length) {
|
|
48
|
+
parts.push(`The following deferred tools are no longer available. Do not search for them — ${SEARCH_TOOL_NAME} will return no match:\n${list(input.removedUnloaded)}`);
|
|
49
|
+
}
|
|
50
|
+
if (input.active.length) {
|
|
51
|
+
parts.push(`The following tools are available. Their definitions were loaded earlier in this conversation and are still in effect, so they can be called directly:\n${list(input.active)}`);
|
|
52
|
+
}
|
|
53
|
+
if (input.readdedUnloaded.length) {
|
|
54
|
+
parts.push(`The following deferred tools are available again (announced earlier in this conversation). Load them via ${SEARCH_TOOL_NAME} as before:\n${list(input.readdedUnloaded)}`);
|
|
55
|
+
}
|
|
56
|
+
if (input.fresh.length) {
|
|
57
|
+
// Same wording as Claude Code's announcement, minus its client-side error class name.
|
|
58
|
+
parts.push(`The following deferred tools are now available via ${SEARCH_TOOL_NAME}. Their schemas are NOT loaded — calling them directly will fail. Use ${SEARCH_TOOL_NAME} with query "select:<name>[,<name>...]" to load tool schemas before calling them:\n${list(input.fresh)}`);
|
|
59
|
+
}
|
|
60
|
+
return parts.join("\n\n");
|
|
61
|
+
}
|
|
62
|
+
/** Called after beforeStep/compaction, once per model request, never during a tool batch. */
|
|
63
|
+
export function prepareToolCatalog(context, snapshot, options = {}) {
|
|
64
|
+
const enabled = snapshot.deferEnabled ?? snapshot.deferredToolNames.size > 0;
|
|
65
|
+
if (!enabled) {
|
|
66
|
+
const schemas = snapshot.tools.map((tool) => tool.schema);
|
|
67
|
+
return { tools: snapshot.tools, schemas, requestTools: schemas, loaded: new Map(), catalog: new Map(), deferEnabled: false, warnings: [] };
|
|
68
|
+
}
|
|
69
|
+
const warnings = [];
|
|
70
|
+
const loaded = loadedToolSchemas(context);
|
|
71
|
+
const immediate = snapshot.tools.filter((tool) => !snapshot.deferredToolNames.has(tool.schema.name) && tool.schema.name !== SEARCH_TOOL_NAME);
|
|
72
|
+
const reserved = new Set([SEARCH_TOOL_NAME, ...immediate.map((tool) => tool.schema.name)]);
|
|
73
|
+
const catalog = [];
|
|
74
|
+
const sources = new Map();
|
|
75
|
+
const entries = [];
|
|
76
|
+
for (const tool of snapshot.tools) {
|
|
77
|
+
if (!snapshot.deferredToolNames.has(tool.schema.name))
|
|
78
|
+
continue;
|
|
79
|
+
const sourceName = tool.schema.name;
|
|
80
|
+
const digest = fingerprint(tool.schema);
|
|
81
|
+
// A definition the model already holds under this source keeps its wire name; a changed
|
|
82
|
+
// definition gets a versioned name so the recorded one is never rewritten in place.
|
|
83
|
+
const previous = [...loaded.values()].find((entry) => entry.sourceName === sourceName && fingerprint(entry.schema) === digest);
|
|
84
|
+
const conflict = loaded.has(sourceName) && fingerprint(loaded.get(sourceName).schema) !== digest;
|
|
85
|
+
const name = previous?.schema.name ?? (conflict ? `${sourceName.slice(0, 47)}__v_${digest.slice(0, 12)}` : sourceName);
|
|
86
|
+
if (reserved.has(name) || sources.has(name)) {
|
|
87
|
+
warnings.push(`deferred tool "${sourceName}" omitted: wire name "${name}" collides with another tool`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const pinned = loaded.get(name);
|
|
91
|
+
if (pinned && (pinned.sourceName !== sourceName || fingerprint(pinned.schema) !== digest)) {
|
|
92
|
+
warnings.push(`deferred tool "${sourceName}" omitted: wire name "${name}" is pinned to a different recorded definition`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const schema = structuredClone(previous?.schema ?? { ...tool.schema, name });
|
|
96
|
+
catalog.push({
|
|
97
|
+
...tool,
|
|
98
|
+
schema,
|
|
99
|
+
// Approval rules and actual MCP routing remain owned by the original tool.
|
|
100
|
+
resolve: (args, ctx) => tool.resolve(args, ctx),
|
|
101
|
+
});
|
|
102
|
+
sources.set(name, sourceName);
|
|
103
|
+
entries.push({ name, sourceName, fingerprint: digest });
|
|
104
|
+
}
|
|
105
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
106
|
+
const current = new Map(entries.map((entry) => [entry.name, entry.fingerprint]));
|
|
107
|
+
if (options.announce !== false) {
|
|
108
|
+
const { available: announced, unavailable } = announcedTools(context);
|
|
109
|
+
const added = entries.filter((entry) => announced.get(entry.name) !== entry.fingerprint);
|
|
110
|
+
const removed = [...new Set([
|
|
111
|
+
...[...announced.keys()].filter((name) => current.get(name) !== announced.get(name)),
|
|
112
|
+
...[...loaded.keys()].filter((name) => !current.has(name) && !unavailable.has(name)),
|
|
113
|
+
])].sort();
|
|
114
|
+
if (added.length || removed.length) {
|
|
115
|
+
const isActive = (name) => {
|
|
116
|
+
const entry = loaded.get(name);
|
|
117
|
+
return entry !== undefined && fingerprint(entry.schema) === current.get(name);
|
|
118
|
+
};
|
|
119
|
+
// A definition already recorded in history (a reconnect, or a call that outlived
|
|
120
|
+
// compaction) is callable now; only unloaded names need a search.
|
|
121
|
+
const unloaded = added.filter((entry) => !isActive(entry.name));
|
|
122
|
+
const text = announcementText({
|
|
123
|
+
fresh: unloaded.filter((entry) => !unavailable.has(entry.name)).map((entry) => entry.name),
|
|
124
|
+
active: added.filter((entry) => isActive(entry.name)).map((entry) => entry.name),
|
|
125
|
+
readdedUnloaded: unloaded.filter((entry) => unavailable.has(entry.name)).map((entry) => entry.name),
|
|
126
|
+
retiredLoaded: removed.filter((name) => loaded.has(name)),
|
|
127
|
+
removedUnloaded: removed.filter((name) => !loaded.has(name)),
|
|
128
|
+
});
|
|
129
|
+
context.appendMessage({ role: "user", content: [{ type: "text", text: `<system-reminder>\n${text}\n</system-reminder>` }], timestamp: Date.now() }, { kind: "tool_catalog_delta", added, removed });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const search = buildSearchTool(catalog.map((tool) => tool.schema), sources);
|
|
133
|
+
// A catalog tool executes only once its definition is recorded in history: a SearchTool
|
|
134
|
+
// load point, or a compaction summary carrying it for a surviving call. A bare call to an
|
|
135
|
+
// unloaded name is not evidence — the model guessed, and the executor refused it.
|
|
136
|
+
const active = [...immediate, search, ...catalog.filter((tool) => loaded.has(tool.schema.name))];
|
|
137
|
+
// Old definitions are wire-only. In particular, removing a server must never leave an
|
|
138
|
+
// executable fallback pointing at its retired schema or a replacement implementation.
|
|
139
|
+
const schemas = new Map(immediate.map((tool) => [tool.schema.name, tool.schema]));
|
|
140
|
+
schemas.set(search.schema.name, search.schema);
|
|
141
|
+
for (const entry of loaded.values())
|
|
142
|
+
if (!schemas.has(entry.schema.name))
|
|
143
|
+
schemas.set(entry.schema.name, entry.schema);
|
|
144
|
+
for (const tool of active)
|
|
145
|
+
if (!schemas.has(tool.schema.name))
|
|
146
|
+
schemas.set(tool.schema.name, tool.schema);
|
|
147
|
+
return {
|
|
148
|
+
tools: active,
|
|
149
|
+
schemas: [...schemas.values()],
|
|
150
|
+
requestTools: [...immediate.map((tool) => tool.schema), search.schema],
|
|
151
|
+
loaded,
|
|
152
|
+
catalog: new Map(catalog.map((tool) => [tool.schema.name, tool.schema])),
|
|
153
|
+
deferEnabled: true,
|
|
154
|
+
warnings,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Why a call to `name` cannot execute right now, for the model. Distinguishes a deferred tool
|
|
159
|
+
* whose definition was never loaded (or whose load point was compacted away) from a loaded
|
|
160
|
+
* definition whose source is gone — both look like "unknown tool" to the executor.
|
|
161
|
+
*/
|
|
162
|
+
export function describeUnknownTool(prepared, name) {
|
|
163
|
+
if (!prepared.deferEnabled)
|
|
164
|
+
return undefined;
|
|
165
|
+
const schema = prepared.catalog.get(name);
|
|
166
|
+
if (schema !== undefined) {
|
|
167
|
+
let reference = "";
|
|
168
|
+
try {
|
|
169
|
+
reference = ` For reference, its input schema is: ${JSON.stringify(schema.parameters)}`;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// Unserializable schema: the hint still tells the model how to load the definition.
|
|
173
|
+
}
|
|
174
|
+
return `This tool's schema was not sent to the model: "${name}" is a deferred tool whose definition is not loaded in this conversation (never loaded, or its load point was removed by compaction). `
|
|
175
|
+
+ `Load it first: call ${SEARCH_TOOL_NAME} with query "select:${name}", then retry this call.${reference}`;
|
|
176
|
+
}
|
|
177
|
+
if (prepared.loaded.has(name)) {
|
|
178
|
+
return `The tool "${name}" is no longer available: its source was removed from this session. Do not call it again.`;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* When an agent has many tools (MCP / capability sprawl), most are marked
|
|
5
5
|
* *deferred*: kept in Operon's execution catalog but out of the model's active
|
|
6
6
|
* context. The model calls SearchTool to discover the few it needs; matches
|
|
7
|
-
* are recorded
|
|
8
|
-
*
|
|
7
|
+
* are recorded in the SearchTool result's details, and the request projection
|
|
8
|
+
* declares them to pi as `toolsAdded` system messages; pi handles the
|
|
9
|
+
* provider-specific wire representation.
|
|
9
10
|
*
|
|
10
11
|
* This module holds only the pieces that don't depend on any provider: the
|
|
11
12
|
* keyword search, the query DSL,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Message } from "../../protocol/index.ts";
|
|
2
|
+
import type { LoadedToolSchema, PromptOrigin } from "../../store/origin.ts";
|
|
3
|
+
/** The slice of a conversation `loadedToolSchemas` reads: `ConversationContext` fits as is. */
|
|
4
|
+
export interface HistoryView {
|
|
5
|
+
readonly messages: readonly Message[];
|
|
6
|
+
originOf(message: Message): PromptOrigin | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function isLoadedSchema(value: unknown): value is LoadedToolSchema;
|
|
9
|
+
/**
|
|
10
|
+
* Deferred-tool definitions this history holds, by wire name. Derived only from surviving
|
|
11
|
+
* structured records — a SearchTool load point, or a compaction summary carrying the
|
|
12
|
+
* definitions its removed prefix had loaded for calls the kept tail still makes — so full
|
|
13
|
+
* compaction releases a load nothing after it depends on. First record wins.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadedToolSchemas(history: HistoryView): Map<string, LoadedToolSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* The history as pi should see it: every load point followed by a system message whose
|
|
18
|
+
* `toolsAdded` declares the definitions it loaded, so pi anchors them there (Anthropic
|
|
19
|
+
* `tool_addition`, Responses `additional_tools` / client tool search, Kimi `tools` system
|
|
20
|
+
* messages) instead of rewriting the top-level tool list. `declared` names the request's
|
|
21
|
+
* top-level tools; a name is declared once, at its first surviving load point, which keeps
|
|
22
|
+
* the projection of an unchanged prefix byte-identical as history grows. The declaration
|
|
23
|
+
* lands after the load point's whole tool-result batch, since results must stay contiguous.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withToolLoads(history: HistoryView, declared: ReadonlySet<string>): Message[];
|
|
26
|
+
/**
|
|
27
|
+
* What a compaction summary must carry: definitions loaded in the prefix being removed that
|
|
28
|
+
* assistant messages in the kept tail still call. Anything else is released — the model is
|
|
29
|
+
* re-told to search, and the definition reloads through a fresh load point.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadedToolsForCompaction(history: HistoryView, cutoff: number): LoadedToolSchema[];
|
|
32
|
+
//# sourceMappingURL=loaded.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SEARCH_TOOL_NAME } from "./deferral.js";
|
|
2
|
+
export function isLoadedSchema(value) {
|
|
3
|
+
if (value === null || typeof value !== "object")
|
|
4
|
+
return false;
|
|
5
|
+
const entry = value;
|
|
6
|
+
return typeof entry.sourceName === "string" && typeof entry.schema?.name === "string"
|
|
7
|
+
&& typeof entry.schema.description === "string" && entry.schema.parameters !== null
|
|
8
|
+
&& typeof entry.schema.parameters === "object";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Deferred-tool definitions this history holds, by wire name. Derived only from surviving
|
|
12
|
+
* structured records — a SearchTool load point, or a compaction summary carrying the
|
|
13
|
+
* definitions its removed prefix had loaded for calls the kept tail still makes — so full
|
|
14
|
+
* compaction releases a load nothing after it depends on. First record wins.
|
|
15
|
+
*/
|
|
16
|
+
export function loadedToolSchemas(history) {
|
|
17
|
+
const loaded = new Map();
|
|
18
|
+
for (const message of history.messages) {
|
|
19
|
+
for (const entry of loadPointEntries(history, message))
|
|
20
|
+
if (!loaded.has(entry.schema.name))
|
|
21
|
+
loaded.set(entry.schema.name, entry);
|
|
22
|
+
}
|
|
23
|
+
return loaded;
|
|
24
|
+
}
|
|
25
|
+
/** The definitions `message` records as loaded, if it is a load point. */
|
|
26
|
+
function loadPointEntries(history, message) {
|
|
27
|
+
if (message.role === "user") {
|
|
28
|
+
const origin = history.originOf(message);
|
|
29
|
+
return origin?.kind === "compaction_summary" && origin.loadedTools !== undefined ? origin.loadedTools.filter(isLoadedSchema) : [];
|
|
30
|
+
}
|
|
31
|
+
if (message.role === "toolResult" && message.toolName === SEARCH_TOOL_NAME && !message.isError) {
|
|
32
|
+
const details = message.details;
|
|
33
|
+
return Array.isArray(details?.deferredToolSchemas) ? details.deferredToolSchemas.filter(isLoadedSchema) : [];
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The history as pi should see it: every load point followed by a system message whose
|
|
39
|
+
* `toolsAdded` declares the definitions it loaded, so pi anchors them there (Anthropic
|
|
40
|
+
* `tool_addition`, Responses `additional_tools` / client tool search, Kimi `tools` system
|
|
41
|
+
* messages) instead of rewriting the top-level tool list. `declared` names the request's
|
|
42
|
+
* top-level tools; a name is declared once, at its first surviving load point, which keeps
|
|
43
|
+
* the projection of an unchanged prefix byte-identical as history grows. The declaration
|
|
44
|
+
* lands after the load point's whole tool-result batch, since results must stay contiguous.
|
|
45
|
+
*/
|
|
46
|
+
export function withToolLoads(history, declared) {
|
|
47
|
+
const seen = new Set(declared);
|
|
48
|
+
const out = [];
|
|
49
|
+
let pending;
|
|
50
|
+
const flush = () => {
|
|
51
|
+
if (pending !== undefined)
|
|
52
|
+
out.push(pending);
|
|
53
|
+
pending = undefined;
|
|
54
|
+
};
|
|
55
|
+
for (const message of history.messages) {
|
|
56
|
+
if (message.role !== "toolResult")
|
|
57
|
+
flush();
|
|
58
|
+
out.push(message);
|
|
59
|
+
const fresh = loadPointEntries(history, message).filter((entry) => !seen.has(entry.schema.name));
|
|
60
|
+
if (fresh.length === 0)
|
|
61
|
+
continue;
|
|
62
|
+
for (const entry of fresh)
|
|
63
|
+
seen.add(entry.schema.name);
|
|
64
|
+
pending ??= { role: "system", content: "", toolsAdded: [], timestamp: message.timestamp };
|
|
65
|
+
pending.toolsAdded.push(...fresh.map((entry) => toPiTool(entry.schema)));
|
|
66
|
+
}
|
|
67
|
+
flush();
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function toPiTool(schema) {
|
|
71
|
+
// Protocol-level parameters are a JSON Schema object; pi serializes it as the tool schema.
|
|
72
|
+
return { name: schema.name, description: schema.description, parameters: schema.parameters };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* What a compaction summary must carry: definitions loaded in the prefix being removed that
|
|
76
|
+
* assistant messages in the kept tail still call. Anything else is released — the model is
|
|
77
|
+
* re-told to search, and the definition reloads through a fresh load point.
|
|
78
|
+
*/
|
|
79
|
+
export function loadedToolsForCompaction(history, cutoff) {
|
|
80
|
+
const removed = history.messages.slice(0, cutoff);
|
|
81
|
+
if (removed.length === 0)
|
|
82
|
+
return [];
|
|
83
|
+
const loaded = loadedToolSchemas({ messages: removed, originOf: (message) => history.originOf(message) });
|
|
84
|
+
if (loaded.size === 0)
|
|
85
|
+
return [];
|
|
86
|
+
const called = new Set();
|
|
87
|
+
for (const message of history.messages.slice(cutoff)) {
|
|
88
|
+
if (message.role !== "assistant")
|
|
89
|
+
continue;
|
|
90
|
+
for (const block of message.content)
|
|
91
|
+
if (block.type === "toolCall")
|
|
92
|
+
called.add(block.name);
|
|
93
|
+
}
|
|
94
|
+
return [...loaded.values()].filter((entry) => called.has(entry.schema.name)).map((entry) => structuredClone(entry));
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=loaded.js.map
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { Tool } from "../types.ts";
|
|
2
2
|
import type { ToolSchema } from "../../protocol/index.ts";
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
* load. Names are sorted so the description stays byte-stable across turns
|
|
6
|
-
* (cacheable) while the deferred set is unchanged. (P1 moves this to
|
|
7
|
-
* diff-based `<available-deferred-tools>` announcements in history.) */
|
|
8
|
-
export declare function buildSearchTool(deferred: readonly ToolSchema[]): Tool;
|
|
3
|
+
/** The description is constant; catalog changes are journaled as messages instead. */
|
|
4
|
+
export declare function buildSearchTool(deferred: readonly ToolSchema[], sourceNames?: ReadonlyMap<string, string>): Tool;
|
|
9
5
|
//# sourceMappingURL=search-tool.d.ts.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Built per turn over a snapshot of the deferred catalog (in `buildRunTools`),
|
|
5
5
|
* so it can search names/descriptions without needing the live tool registry
|
|
6
|
-
* at call time. Its result
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
6
|
+
* at call time. Its result records the matched definitions in
|
|
7
|
+
* `details.deferredToolSchemas`; the request projection (`withToolLoads`)
|
|
8
|
+
* declares them to pi as a `toolsAdded` system message right after the load.
|
|
9
9
|
*/
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { tool } from "../define.js";
|
|
@@ -25,28 +25,24 @@ const SearchInput = z.object({
|
|
|
25
25
|
});
|
|
26
26
|
const DESCRIPTION = `Fetches full schema definitions for deferred tools so they can be called.
|
|
27
27
|
|
|
28
|
-
Deferred tools appear by name in <
|
|
28
|
+
Deferred tools appear by name in <system-reminder> messages in the conversation. Until fetched, only the name is known — there is no parameter schema, so the tool cannot be invoked. This tool matches your query against the deferred tool list and loads the matched tools' full definitions, after which they are callable exactly like the tools defined at the top of the prompt.
|
|
29
29
|
|
|
30
30
|
Query forms:
|
|
31
31
|
- "select:Read,Edit,Grep" — fetch these exact tools by name
|
|
32
32
|
- "notebook jupyter" — keyword search, up to max_results best matches
|
|
33
33
|
- "+slack send" — require "slack" in the name, rank by remaining terms`;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* diff-based `<available-deferred-tools>` announcements in history.) */
|
|
39
|
-
export function buildSearchTool(deferred) {
|
|
40
|
-
const names = deferred.map((s) => s.name).sort((a, b) => a.localeCompare(b));
|
|
41
|
-
const description = `${DESCRIPTION}\n\n<available-deferred-tools>\n${names.join("\n")}\n</available-deferred-tools>`;
|
|
34
|
+
/** The description is constant; catalog changes are journaled as messages instead. */
|
|
35
|
+
export function buildSearchTool(deferred, sourceNames = new Map()) {
|
|
36
|
+
// Neither later catalog mutations nor tool execution may rewrite a recorded definition.
|
|
37
|
+
const catalog = structuredClone(deferred);
|
|
42
38
|
return tool({
|
|
43
39
|
name: SEARCH_TOOL_NAME,
|
|
44
|
-
description,
|
|
40
|
+
description: DESCRIPTION,
|
|
45
41
|
parameters: SearchInput,
|
|
46
42
|
approvalRule: SEARCH_TOOL_NAME,
|
|
47
43
|
accesses: ToolAccesses.none(),
|
|
48
44
|
execute: (args) => {
|
|
49
|
-
const { matches } = runSearchQuery(args.query,
|
|
45
|
+
const { matches } = runSearchQuery(args.query, catalog, args.max_results ?? 5);
|
|
50
46
|
return {
|
|
51
47
|
content: [
|
|
52
48
|
{
|
|
@@ -54,7 +50,12 @@ export function buildSearchTool(deferred) {
|
|
|
54
50
|
text: matches.length > 0 ? `Loaded tools: ${matches.join(", ")}` : "No matching deferred tools found.",
|
|
55
51
|
},
|
|
56
52
|
],
|
|
57
|
-
|
|
53
|
+
details: {
|
|
54
|
+
deferredToolSchemas: matches.map((name) => ({
|
|
55
|
+
sourceName: sourceNames.get(name) ?? name,
|
|
56
|
+
schema: catalog.find((schema) => schema.name === name),
|
|
57
|
+
})),
|
|
58
|
+
},
|
|
58
59
|
};
|
|
59
60
|
},
|
|
60
61
|
});
|
package/dist/tool/shell-env.js
CHANGED
|
@@ -16,6 +16,10 @@ export function nonInteractiveShellEnv(options) {
|
|
|
16
16
|
NO_COLOR: "1",
|
|
17
17
|
TERM: "dumb",
|
|
18
18
|
GIT_TERMINAL_PROMPT: base["GIT_TERMINAL_PROMPT"] ?? "0",
|
|
19
|
+
// `git commit` without -m, `rebase --continue`, a merge commit — each opens an editor nobody
|
|
20
|
+
// can type into, and the command sits there until the timeout kills it. `true` accepts the
|
|
21
|
+
// message git prepared, which is what a non-interactive caller wants.
|
|
22
|
+
GIT_EDITOR: "true",
|
|
19
23
|
SHELL: options.shellPath,
|
|
20
24
|
};
|
|
21
25
|
if (options.extra)
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* that. Every unresolvable case yields NO access entry, which lands exactly on today's
|
|
10
10
|
* behaviour — the policies skip what they cannot see, and the permission chain's fallback ask
|
|
11
11
|
* still stands behind them. So this raises the cost of an accidental out-of-workspace write; it
|
|
12
|
-
* is not a boundary. The boundary is the
|
|
12
|
+
* is not a boundary. The boundary is the Environment (sandbox / SSH), which bounds what the command
|
|
13
13
|
* can reach no matter how the path was spelled.
|
|
14
14
|
*
|
|
15
15
|
* Over-declaring is the failure mode worth avoiding: a bogus path means a permission prompt for
|
|
@@ -32,6 +32,30 @@ const READS_ALL_ARGS = new Set([
|
|
|
32
32
|
"cat", "head", "tail", "less", "more", "wc", "file", "stat", "nl", "od", "xxd", "strings",
|
|
33
33
|
"base64", "md5sum", "sha1sum", "sha256sum", "shasum", "cmp", "diff", "sort", "readlink",
|
|
34
34
|
]);
|
|
35
|
+
/**
|
|
36
|
+
* Options of the read commands above that take a value as the next word (`head -n 100`), so
|
|
37
|
+
* the value is not mistaken for a file. A value glued to its option (`-n100`) is one word and
|
|
38
|
+
* already dropped as an option.
|
|
39
|
+
*/
|
|
40
|
+
const OPTION_VALUES = {
|
|
41
|
+
head: new Set(["-n", "-c", "--lines", "--bytes"]),
|
|
42
|
+
tail: new Set(["-n", "-c", "--lines", "--bytes", "-s", "--sleep-interval", "--pid"]),
|
|
43
|
+
sort: new Set(["-k", "-t", "-S", "-T", "--key", "--field-separator", "--buffer-size", "--temporary-directory"]),
|
|
44
|
+
nl: new Set(["-b", "-d", "-f", "-h", "-i", "-l", "-n", "-s", "-v", "-w"]),
|
|
45
|
+
od: new Set(["-A", "-j", "-N", "-t", "-w"]),
|
|
46
|
+
xxd: new Set(["-c", "-g", "-l", "-o", "-s"]),
|
|
47
|
+
strings: new Set(["-n", "-t", "-e"]),
|
|
48
|
+
base64: new Set(["-w", "--wrap"]),
|
|
49
|
+
diff: new Set(["-U", "-C", "-L", "--label", "-I", "--ignore-matching-lines"]),
|
|
50
|
+
cmp: new Set(["-i", "-n", "--ignore-initial", "--bytes"]),
|
|
51
|
+
shasum: new Set(["-a", "--algorithm"]),
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Character and stream devices a command reads or writes without touching a file: `2>/dev/null`
|
|
55
|
+
* is how a command discards its errors, not a write outside the workspace. Reporting them would
|
|
56
|
+
* prompt for exactly the most common harmless redirect.
|
|
57
|
+
*/
|
|
58
|
+
const STREAM_DEVICE = /^\/dev\/(?:null|zero|u?random|stdin|stdout|stderr|tty|fd\/\d+)$/;
|
|
35
59
|
/**
|
|
36
60
|
* Split one simple command into words, tracking whether each is a knowable literal.
|
|
37
61
|
*
|
|
@@ -180,17 +204,24 @@ function scriptCommandFiles(name, rawArgs) {
|
|
|
180
204
|
const nonEmpty = operandWords.filter((word) => word.text.length > 0);
|
|
181
205
|
return { inPlace, files: scriptIsAnOption ? nonEmpty : nonEmpty.slice(1) };
|
|
182
206
|
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Drop option flags — and the value of an option in `withValue` — and stop treating anything as
|
|
209
|
+
* an option after a bare `--`.
|
|
210
|
+
*/
|
|
211
|
+
function operands(words, withValue) {
|
|
185
212
|
const result = [];
|
|
186
213
|
let optionsEnded = false;
|
|
187
|
-
for (
|
|
214
|
+
for (let i = 0; i < words.length; i++) {
|
|
215
|
+
const word = words[i];
|
|
188
216
|
if (!optionsEnded && word.text === "--") {
|
|
189
217
|
optionsEnded = true;
|
|
190
218
|
continue;
|
|
191
219
|
}
|
|
192
|
-
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1)
|
|
220
|
+
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1) {
|
|
221
|
+
if (withValue?.has(word.text))
|
|
222
|
+
i++;
|
|
193
223
|
continue;
|
|
224
|
+
}
|
|
194
225
|
result.push(word);
|
|
195
226
|
}
|
|
196
227
|
return result;
|
|
@@ -219,8 +250,8 @@ export function extractBashPaths(command) {
|
|
|
219
250
|
if (verb === undefined || !verb.literal)
|
|
220
251
|
continue;
|
|
221
252
|
const rawArgs = words.slice(1);
|
|
222
|
-
const args = operands(rawArgs);
|
|
223
253
|
const name = verb.text.replace(/^.*\//, ""); // /bin/rm → rm
|
|
254
|
+
const args = operands(rawArgs, OPTION_VALUES[name]);
|
|
224
255
|
if (SCRIPT_COMMANDS.has(name)) {
|
|
225
256
|
const { inPlace, files } = scriptCommandFiles(name, rawArgs);
|
|
226
257
|
pushLiteral(files, inPlace ? "write" : "read", out);
|
|
@@ -242,6 +273,6 @@ export function extractBashPaths(command) {
|
|
|
242
273
|
pushLiteral(args, "read", out);
|
|
243
274
|
}
|
|
244
275
|
}
|
|
245
|
-
return out;
|
|
276
|
+
return out.filter((access) => !STREAM_DEVICE.test(access.path));
|
|
246
277
|
}
|
|
247
278
|
//# sourceMappingURL=bash-paths.js.map
|