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
|
@@ -105,12 +105,12 @@ export const grepTool = defineTool({
|
|
|
105
105
|
params: GrepInput,
|
|
106
106
|
async resolve(args, ctx) {
|
|
107
107
|
const searchPath = args.path !== undefined
|
|
108
|
-
? await resolveToolPath(args.path, ctx.
|
|
109
|
-
: ctx.
|
|
108
|
+
? await resolveToolPath(args.path, ctx.environment, "search", SEARCH_ACCESS_POLICY)
|
|
109
|
+
: ctx.environment.getcwd();
|
|
110
110
|
return {
|
|
111
|
-
display: { title: `Searching for '${args.pattern}' in ${args.path ?? "."}
|
|
111
|
+
display: { title: `Searching for '${args.pattern}' in ${args.path ?? "."}`, pattern: args.pattern, ...(args.path !== undefined ? { path: args.path } : {}) },
|
|
112
112
|
...globApproval("Grep", args.pattern),
|
|
113
|
-
run: (runCtx) => execution(args, runCtx.signal, [searchPath], runCtx.
|
|
113
|
+
run: (runCtx) => execution(args, runCtx.signal, [searchPath], runCtx.environment),
|
|
114
114
|
};
|
|
115
115
|
},
|
|
116
116
|
});
|
|
@@ -123,14 +123,14 @@ class GrepAbortedError extends Error {
|
|
|
123
123
|
function errResult(text) {
|
|
124
124
|
return { content: [{ type: "text", text }], isError: true };
|
|
125
125
|
}
|
|
126
|
-
async function execution(args, signal, searchPaths,
|
|
126
|
+
async function execution(args, signal, searchPaths, environment) {
|
|
127
127
|
if (signal.aborted)
|
|
128
128
|
return errResult("Aborted before search started");
|
|
129
|
-
const pathClass =
|
|
130
|
-
const workspaceDir =
|
|
129
|
+
const pathClass = environment.pathClass();
|
|
130
|
+
const workspaceDir = environment.getcwd();
|
|
131
131
|
let rgPath;
|
|
132
132
|
try {
|
|
133
|
-
rgPath = await resolveRgCommand(
|
|
133
|
+
rgPath = await resolveRgCommand(environment, { signal });
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
136
136
|
if (isAbortError(error))
|
|
@@ -138,13 +138,13 @@ async function execution(args, signal, searchPaths, machine) {
|
|
|
138
138
|
return errResult(rgUnavailableMessage(error));
|
|
139
139
|
}
|
|
140
140
|
const runOptions = { timeoutMs: DEFAULT_TIMEOUT_MS, maxOutputBytes: MAX_OUTPUT_BYTES };
|
|
141
|
-
let outcome = await runRipgrep(
|
|
141
|
+
let outcome = await runRipgrep(environment, buildRgArgs(rgPath, args, searchPaths), signal, runOptions);
|
|
142
142
|
const earlyExit = mapNonResult(outcome);
|
|
143
143
|
if (earlyExit)
|
|
144
144
|
return earlyExit;
|
|
145
145
|
let runResult = outcome.result;
|
|
146
146
|
if (shouldRetryRipgrepEagain(runResult)) {
|
|
147
|
-
outcome = await runRipgrep(
|
|
147
|
+
outcome = await runRipgrep(environment, buildRgArgs(rgPath, args, searchPaths, true), signal, runOptions);
|
|
148
148
|
const retryExit = mapNonResult(outcome);
|
|
149
149
|
if (retryExit)
|
|
150
150
|
return retryExit;
|
|
@@ -173,7 +173,7 @@ async function execution(args, signal, searchPaths, machine) {
|
|
|
173
173
|
try {
|
|
174
174
|
orderedLines =
|
|
175
175
|
mode === "files_with_matches" && !timedOut
|
|
176
|
-
? await sortFilesWithMatchesByMtime(keptLines,
|
|
176
|
+
? await sortFilesWithMatchesByMtime(keptLines, environment, signal)
|
|
177
177
|
: keptLines;
|
|
178
178
|
}
|
|
179
179
|
catch (error) {
|
|
@@ -251,13 +251,13 @@ function shouldRetryRipgrepEagain(result) {
|
|
|
251
251
|
function isEagainRipgrepError(stderr) {
|
|
252
252
|
return stderr.includes("os error 11") || stderr.includes("Resource temporarily unavailable");
|
|
253
253
|
}
|
|
254
|
-
async function sortFilesWithMatchesByMtime(lines,
|
|
254
|
+
async function sortFilesWithMatchesByMtime(lines, environment, signal) {
|
|
255
255
|
const entries = await mapWithConcurrency(lines, MTIME_STAT_CONCURRENCY, signal, async (line, index) => {
|
|
256
256
|
const path = line.kind === "record" ? line.filePath : line.kind === "legacy" ? line.text : undefined;
|
|
257
257
|
let mtime = 0;
|
|
258
258
|
if (path !== undefined) {
|
|
259
259
|
try {
|
|
260
|
-
mtime = (await
|
|
260
|
+
mtime = (await environment.fileInfo(path)).mtimeMs ?? 0;
|
|
261
261
|
}
|
|
262
262
|
catch {
|
|
263
263
|
/* mtime=0 → sort after known files */
|
|
@@ -4,7 +4,7 @@ import { defineTool } from "../define.js";
|
|
|
4
4
|
import { FILE_UNCHANGED_STUB } from "../file-freshness.js";
|
|
5
5
|
import { detectFileType, MEDIA_SNIFF_BYTES } from "../support/file-type.js";
|
|
6
6
|
import { compressImageForModel } from "../support/image-compress.js";
|
|
7
|
-
import { fileVersionFromInfo, fileVersionsMatch, normalizeForCompare, readTextFile } from "../support/
|
|
7
|
+
import { decodeText, fileVersionFromInfo, fileVersionsMatch, normalizeForCompare, readTextFile } from "../support/environment-ops.js";
|
|
8
8
|
import { pathApproval, resolveToolPath } from "../support/tool-path.js";
|
|
9
9
|
import { makeCarriageReturnsVisible } from "./line-endings.js";
|
|
10
10
|
/**
|
|
@@ -171,21 +171,21 @@ export const readTool = defineTool({
|
|
|
171
171
|
description: READ_DESCRIPTION,
|
|
172
172
|
params: ReadInput,
|
|
173
173
|
async resolve(args, ctx) {
|
|
174
|
-
const path = await resolveToolPath(args.path, ctx.
|
|
174
|
+
const path = await resolveToolPath(args.path, ctx.environment, "read");
|
|
175
175
|
return {
|
|
176
176
|
accesses: ToolAccesses.readFile(path),
|
|
177
|
-
display: { title: `Reading ${args.path}
|
|
178
|
-
...pathApproval("Read", ctx.
|
|
177
|
+
display: { title: `Reading ${args.path}`, path: args.path },
|
|
178
|
+
...pathApproval("Read", ctx.environment, path),
|
|
179
179
|
run: (runCtx) => execute(args, path, runCtx),
|
|
180
180
|
};
|
|
181
181
|
},
|
|
182
182
|
});
|
|
183
183
|
async function execute(args, safePath, ctx) {
|
|
184
|
-
const
|
|
184
|
+
const environment = ctx.environment;
|
|
185
185
|
try {
|
|
186
186
|
let info;
|
|
187
187
|
try {
|
|
188
|
-
info = await
|
|
188
|
+
info = await environment.fileInfo(safePath);
|
|
189
189
|
}
|
|
190
190
|
catch (error) {
|
|
191
191
|
if (isFileNotFoundError(error))
|
|
@@ -194,28 +194,36 @@ async function execute(args, safePath, ctx) {
|
|
|
194
194
|
}
|
|
195
195
|
if (info.kind !== "file")
|
|
196
196
|
return err(`"${args.path}" is not a file.`);
|
|
197
|
-
const header = await machine.readBytes(safePath, { length: MEDIA_SNIFF_BYTES });
|
|
198
|
-
const fileType = detectFileType(safePath, header);
|
|
199
|
-
if (fileType.kind === "image")
|
|
200
|
-
return readImageFile(args, safePath, info, machine, fileType.mimeType);
|
|
201
|
-
if (fileType.kind === "unknown")
|
|
202
|
-
return err(notReadableFileOutput(args.path));
|
|
203
197
|
const lineOffset = args.line_offset ?? 1;
|
|
204
198
|
// No `n_lines` means to the end of the file — the byte ceiling is what bounds it.
|
|
205
199
|
const requestedLines = args.n_lines ?? Number.POSITIVE_INFINITY;
|
|
206
200
|
const range = rangeKeyForArgs(args);
|
|
201
|
+
// Dedup before anything is read: an unchanged file answers from the stat alone. A record
|
|
202
|
+
// with a range only ever comes from a successful TEXT read, so skipping the type sniff for
|
|
203
|
+
// it cannot serve the stub for an image.
|
|
207
204
|
const record = ctx.fileLedger?.get(safePath);
|
|
208
205
|
if (record?.range && rangesEqual(record.range, range)) {
|
|
209
206
|
const current = fileVersionFromInfo(info);
|
|
210
207
|
if (fileVersionsMatch(record.version, current))
|
|
211
208
|
return ok(FILE_UNCHANGED_STUB);
|
|
212
209
|
}
|
|
210
|
+
// A file small enough to read whole is read ONCE, and its type sniffed off the front of those
|
|
211
|
+
// same bytes. Sniffing first meant two reads of every text file — free locally, but a second
|
|
212
|
+
// round trip (on a sandbox, a whole extra command) on every remote Read. A large file still
|
|
213
|
+
// gets the sniff alone first, so a binary is refused without pulling all of it across.
|
|
214
|
+
const whole = info.size <= MAX_UNPAGED_FILE_BYTES ? await environment.readBytes(safePath) : undefined;
|
|
215
|
+
const header = whole?.subarray(0, MEDIA_SNIFF_BYTES) ?? (await environment.readBytes(safePath, { length: MEDIA_SNIFF_BYTES }));
|
|
216
|
+
const fileType = detectFileType(safePath, header);
|
|
217
|
+
if (fileType.kind === "image")
|
|
218
|
+
return readImageFile(args, safePath, info, environment, fileType.mimeType, whole);
|
|
219
|
+
if (fileType.kind === "unknown")
|
|
220
|
+
return err(notReadableFileOutput(args.path));
|
|
213
221
|
// After the dedup stub: an unchanged file answers for free no matter how large it is.
|
|
214
222
|
if (args.line_offset === undefined && args.n_lines === undefined && info.size > MAX_UNPAGED_FILE_BYTES) {
|
|
215
223
|
return err(`"${args.path}" is ${String(Math.round(info.size / 1024))} KB, over the ${String(MAX_UNPAGED_FILE_BYTES / 1024)} KB limit for reading a whole file at once. ` +
|
|
216
224
|
"Read a range with `line_offset` (and `n_lines`), or use Grep to find the relevant part first.");
|
|
217
225
|
}
|
|
218
|
-
const rawText = await readTextFile(
|
|
226
|
+
const rawText = whole !== undefined ? decodeText(whole, { errors: "strict" }) : await readTextFile(environment, safePath, { errors: "strict" });
|
|
219
227
|
const outcome = lineOffset < 0
|
|
220
228
|
? readTail(rawText, args.path, lineOffset, requestedLines, range)
|
|
221
229
|
: readForward(rawText, args.path, lineOffset, requestedLines, range);
|
|
@@ -238,7 +246,9 @@ async function execute(args, safePath, ctx) {
|
|
|
238
246
|
return err(error instanceof Error ? error.message : String(error));
|
|
239
247
|
}
|
|
240
248
|
}
|
|
241
|
-
async function readImageFile(args, safePath, info,
|
|
249
|
+
async function readImageFile(args, safePath, info, environment, mimeType,
|
|
250
|
+
/** The file's bytes when the caller already read them whole. */
|
|
251
|
+
preloaded) {
|
|
242
252
|
if (args.line_offset !== undefined || args.n_lines !== undefined) {
|
|
243
253
|
return err("line_offset and n_lines are only supported for text files.");
|
|
244
254
|
}
|
|
@@ -247,7 +257,7 @@ async function readImageFile(args, safePath, info, machine, mimeType) {
|
|
|
247
257
|
if (info.size > MAX_IMAGE_BYTES) {
|
|
248
258
|
return err(`"${args.path}" is ${String(info.size)} bytes, which exceeds the maximum ${String(MAX_IMAGE_MEGABYTES)}MB for image files.`);
|
|
249
259
|
}
|
|
250
|
-
const data = await
|
|
260
|
+
const data = preloaded ?? (await environment.readBytes(safePath));
|
|
251
261
|
// Downsample/re-encode oversized images before sending to the model (best
|
|
252
262
|
// effort; the original bytes are returned unchanged on any failure).
|
|
253
263
|
const compressed = await compressImageForModel(data, mimeType);
|
|
@@ -2,9 +2,8 @@ import { dirname } from "node:path";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ToolAccesses } from "../access.js";
|
|
4
4
|
import { defineTool } from "../define.js";
|
|
5
|
-
import { FileExistsError, StaleFileError } from "../machine.js";
|
|
6
5
|
import { checkFreshness, FILE_MODIFIED_MESSAGE, FILE_NOT_READ_MESSAGE } from "../file-freshness.js";
|
|
7
|
-
import { fileVersionFromInfo, normalizeForCompare } from "../support/
|
|
6
|
+
import { fileVersionFromInfo, normalizeForCompare } from "../support/environment-ops.js";
|
|
8
7
|
import { pathApproval, resolveToolPath } from "../support/tool-path.js";
|
|
9
8
|
import { detectLineEndingStyle, materializeModelText } from "./line-endings.js";
|
|
10
9
|
const WriteInput = z.object({
|
|
@@ -33,35 +32,49 @@ export const writeTool = defineTool({
|
|
|
33
32
|
// payload, an SSH key), projected as `${file_path}: ${content}`.
|
|
34
33
|
toAutoApprovalInput: (args) => `${args.path}: ${args.content}`,
|
|
35
34
|
async resolve(args, ctx) {
|
|
36
|
-
const path = await resolveToolPath(args.path, ctx.
|
|
35
|
+
const path = await resolveToolPath(args.path, ctx.environment, "write");
|
|
37
36
|
return {
|
|
38
37
|
accesses: ToolAccesses.writeFile(path),
|
|
39
|
-
display: { title: `Writing ${args.path}
|
|
40
|
-
...pathApproval("Write", ctx.
|
|
38
|
+
display: { title: `Writing ${args.path}`, path: args.path, content: args.content },
|
|
39
|
+
...pathApproval("Write", ctx.environment, path),
|
|
41
40
|
run: (runCtx) => execute(args, path, runCtx),
|
|
42
41
|
};
|
|
43
42
|
},
|
|
44
43
|
});
|
|
45
44
|
async function execute(args, safePath, ctx) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const environment = ctx.environment;
|
|
46
|
+
let info;
|
|
47
|
+
try {
|
|
48
|
+
// ONE stat for the whole call: it answers "does this file exist" and supplies the
|
|
49
|
+
// version the freshness check needs. The three separate stats this replaced each
|
|
50
|
+
// cost a round trip on a remote backend to re-learn what this one already knows.
|
|
51
|
+
info = await statOrUndefined(environment, safePath);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return errorResult(error instanceof Error ? error.message : String(error));
|
|
55
|
+
}
|
|
56
|
+
// An existing file already proves its parent directory exists; only a new file needs the
|
|
57
|
+
// parent checked — which is the one case the helpful "create it first" message is for.
|
|
58
|
+
if (info === undefined) {
|
|
59
|
+
const parentError = await checkParentDirectory(safePath, environment);
|
|
60
|
+
if (parentError !== undefined)
|
|
61
|
+
return errorResult(parentError);
|
|
62
|
+
}
|
|
50
63
|
try {
|
|
51
64
|
const mode = args.mode ?? "overwrite";
|
|
52
|
-
const info = await statOrUndefined(machine, safePath);
|
|
53
|
-
if (info !== undefined)
|
|
54
|
-
await validateWrite(safePath, ctx);
|
|
55
|
-
const ledger = ctx.fileLedger;
|
|
56
|
-
const record = info !== undefined ? ledger?.get(safePath) : undefined;
|
|
57
65
|
let nextContent = args.content;
|
|
58
66
|
let writtenContent = args.content;
|
|
67
|
+
// Append reads the file to concatenate onto it. Reading BEFORE the freshness check
|
|
68
|
+
// lets that one read serve both: chunked writes (overwrite, then append, append…)
|
|
69
|
+
// would otherwise read the whole file twice per chunk.
|
|
70
|
+
let priorText;
|
|
59
71
|
if (mode === "append") {
|
|
60
72
|
// Append composed from the core members: read-concat-write. Fine for the
|
|
61
73
|
// tool's occasional appends; high-frequency log appends belong elsewhere.
|
|
62
74
|
let prior = "";
|
|
63
75
|
try {
|
|
64
|
-
prior = (await
|
|
76
|
+
prior = (await environment.readBytes(safePath)).toString("utf8");
|
|
77
|
+
priorText = prior;
|
|
65
78
|
}
|
|
66
79
|
catch (error) {
|
|
67
80
|
if (error.code !== "ENOENT")
|
|
@@ -74,13 +87,17 @@ async function execute(args, safePath, ctx) {
|
|
|
74
87
|
: args.content;
|
|
75
88
|
nextContent = prior + writtenContent;
|
|
76
89
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
if (info !== undefined)
|
|
91
|
+
await validateWrite(safePath, info, ctx, priorText);
|
|
92
|
+
// Unconditional: `validateWrite` above already decided this write is allowed against
|
|
93
|
+
// the file as the stat found it. A file appearing (or changing) between that check
|
|
94
|
+
// and this write is the gap documented on Environment.writeText — the record below is
|
|
95
|
+
// what surfaces it to the next Read/Write.
|
|
96
|
+
const result = await environment.writeText(safePath, nextContent);
|
|
97
|
+
ctx.fileLedger?.recordWrite(safePath, {
|
|
98
|
+
// Present only where the backend knew it for free (local); elsewhere the record
|
|
99
|
+
// is decided by the digest below.
|
|
100
|
+
...(result.version !== undefined ? { version: result.version } : {}),
|
|
84
101
|
content: normalizeForCompare(nextContent),
|
|
85
102
|
lineEndings: toLedgerLineEndings(detectLineEndingStyle(nextContent)),
|
|
86
103
|
encoding: "utf8",
|
|
@@ -90,8 +107,6 @@ async function execute(args, safePath, ctx) {
|
|
|
90
107
|
return textResult(`${mode === "append" ? "Appended" : "Wrote"} ${String(bytesWritten)} bytes to ${args.path}`);
|
|
91
108
|
}
|
|
92
109
|
catch (error) {
|
|
93
|
-
if (error instanceof StaleFileError || error instanceof FileExistsError)
|
|
94
|
-
return errorResult(FILE_MODIFIED_MESSAGE);
|
|
95
110
|
const code = error?.code;
|
|
96
111
|
if (code === "ENOENT") {
|
|
97
112
|
return errorResult(`Failed to write ${args.path}: parent directory does not exist.`);
|
|
@@ -105,9 +120,9 @@ function requireLedger(ctx) {
|
|
|
105
120
|
}
|
|
106
121
|
return ctx.fileLedger;
|
|
107
122
|
}
|
|
108
|
-
async function statOrUndefined(
|
|
123
|
+
async function statOrUndefined(environment, path) {
|
|
109
124
|
try {
|
|
110
|
-
return await
|
|
125
|
+
return await environment.fileInfo(path);
|
|
111
126
|
}
|
|
112
127
|
catch (error) {
|
|
113
128
|
const code = error.code;
|
|
@@ -116,10 +131,7 @@ async function statOrUndefined(machine, path) {
|
|
|
116
131
|
throw error;
|
|
117
132
|
}
|
|
118
133
|
}
|
|
119
|
-
async function validateWrite(path, ctx) {
|
|
120
|
-
const info = await statOrUndefined(ctx.machine, path);
|
|
121
|
-
if (info === undefined)
|
|
122
|
-
return;
|
|
134
|
+
async function validateWrite(path, info, ctx, knownContent) {
|
|
123
135
|
const ledger = requireLedger(ctx);
|
|
124
136
|
// "Has this agent seen the file", not "did it see all of it" — see the same gate in
|
|
125
137
|
// edit.ts. Overwriting a file the model only paged through DOES discard the part it
|
|
@@ -133,8 +145,12 @@ async function validateWrite(path, ctx) {
|
|
|
133
145
|
path,
|
|
134
146
|
current: fileVersionFromInfo(info),
|
|
135
147
|
currentContent: async () => {
|
|
148
|
+
// The caller already has the text (append) — re-reading it would double the
|
|
149
|
+
// I/O of every chunk in a chunked write.
|
|
150
|
+
if (knownContent !== undefined)
|
|
151
|
+
return normalizeForCompare(knownContent);
|
|
136
152
|
try {
|
|
137
|
-
return normalizeForCompare((await ctx.
|
|
153
|
+
return normalizeForCompare((await ctx.environment.readBytes(path)).toString(record.encoding));
|
|
138
154
|
}
|
|
139
155
|
catch {
|
|
140
156
|
return undefined;
|
|
@@ -153,11 +169,11 @@ function toLedgerLineEndings(style) {
|
|
|
153
169
|
return "mixed";
|
|
154
170
|
return "LF";
|
|
155
171
|
}
|
|
156
|
-
async function checkParentDirectory(safePath,
|
|
172
|
+
async function checkParentDirectory(safePath, environment) {
|
|
157
173
|
const parent = dirname(safePath);
|
|
158
174
|
let info;
|
|
159
175
|
try {
|
|
160
|
-
info = await
|
|
176
|
+
info = await environment.fileInfo(parent);
|
|
161
177
|
}
|
|
162
178
|
catch (error) {
|
|
163
179
|
if (error.code === "ENOENT") {
|
package/dist/tool/define.d.ts
CHANGED
|
@@ -12,16 +12,19 @@ import type { Tool, ToolAccesses, ToolDisplay, ToolPlan, ToolResolveContext, Too
|
|
|
12
12
|
* `ctx.fileLedger`), plan fields beyond approvalRule/accesses/display, or an
|
|
13
13
|
* args-dependent plan structure.
|
|
14
14
|
*/
|
|
15
|
-
export interface ToolDef<S extends ZodType> {
|
|
15
|
+
export interface ToolDef<S extends ZodType, TContext = unknown> {
|
|
16
16
|
readonly name: string;
|
|
17
17
|
readonly description: string;
|
|
18
18
|
readonly params: S;
|
|
19
|
-
readonly resolve: (args: z.infer<S>, ctx: ToolResolveContext) => ToolPlan | Promise<ToolPlan>;
|
|
19
|
+
readonly resolve: (args: z.infer<S>, ctx: ToolResolveContext<TContext>) => ToolPlan | Promise<ToolPlan>;
|
|
20
20
|
/** Security-relevant projection for the `auto`-mode judge. See `Tool.toAutoApprovalInput`. */
|
|
21
21
|
readonly toAutoApprovalInput?: (args: z.infer<S>) => unknown;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Build a tool from a {@link ToolDef}. See that type's doc for when to prefer {@link tool}.
|
|
25
|
+
* `TContext` declares the host context `ctx.context` carries (see `ToolContextBase.context`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function defineTool<S extends ZodType, TContext = unknown>(def: ToolDef<S, TContext>): Tool;
|
|
25
28
|
export type ToolReturn = string | ToolResultContent | ToolResult;
|
|
26
29
|
/**
|
|
27
30
|
* The simple tool definition (OpenAI-parity function tool): one `execute` plus optional
|
|
@@ -30,17 +33,20 @@ export type ToolReturn = string | ToolResultContent | ToolResult;
|
|
|
30
33
|
* hand; for resolve-time validation or plan fields not exposed here, use
|
|
31
34
|
* {@link defineTool} instead.
|
|
32
35
|
*/
|
|
33
|
-
export interface FunctionToolDef<S extends ZodType> {
|
|
36
|
+
export interface FunctionToolDef<S extends ZodType, TContext = unknown> {
|
|
34
37
|
readonly name: string;
|
|
35
38
|
readonly description: string;
|
|
36
39
|
readonly parameters: S;
|
|
37
|
-
readonly execute: (args: z.infer<S>, ctx: ToolRunContext) => ToolReturn | Promise<ToolReturn>;
|
|
40
|
+
readonly execute: (args: z.infer<S>, ctx: ToolRunContext<TContext>) => ToolReturn | Promise<ToolReturn>;
|
|
38
41
|
readonly approvalRule?: string | ((args: z.infer<S>) => string);
|
|
39
42
|
readonly accesses?: ToolAccesses;
|
|
40
43
|
readonly display?: (args: z.infer<S>) => ToolDisplay;
|
|
41
44
|
/** Security-relevant projection for the `auto`-mode judge. See `Tool.toAutoApprovalInput`. */
|
|
42
45
|
readonly toAutoApprovalInput?: (args: z.infer<S>) => unknown;
|
|
43
46
|
}
|
|
44
|
-
/**
|
|
45
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Build a tool from a {@link FunctionToolDef} — the right default for most tools.
|
|
49
|
+
* `TContext` declares the host context `ctx.context` carries (see `ToolContextBase.context`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function tool<S extends ZodType, TContext = unknown>(def: FunctionToolDef<S, TContext>): Tool;
|
|
46
52
|
//# sourceMappingURL=define.d.ts.map
|
package/dist/tool/define.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Build a tool from a {@link ToolDef}. See that type's doc for when to prefer {@link tool}.
|
|
4
|
+
* `TContext` declares the host context `ctx.context` carries (see `ToolContextBase.context`).
|
|
5
|
+
*/
|
|
3
6
|
export function defineTool(def) {
|
|
4
7
|
const parameters = z.toJSONSchema(def.params);
|
|
5
8
|
return {
|
|
@@ -15,7 +18,10 @@ export function defineTool(def) {
|
|
|
15
18
|
: {}),
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Build a tool from a {@link FunctionToolDef} — the right default for most tools.
|
|
23
|
+
* `TContext` declares the host context `ctx.context` carries (see `ToolContextBase.context`).
|
|
24
|
+
*/
|
|
19
25
|
export function tool(def) {
|
|
20
26
|
const parameters = z.toJSONSchema(def.parameters);
|
|
21
27
|
return {
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Implementer-side base for
|
|
2
|
+
* Implementer-side base for Environment backends.
|
|
3
3
|
*
|
|
4
4
|
* A backend writes only the dumb primitives (the abstract SPI below); this
|
|
5
5
|
* class derives the high-level operations from them:
|
|
6
6
|
*
|
|
7
|
-
* - `
|
|
8
|
-
* write → version stamp, all inside the lock. The lock is the same-process
|
|
9
|
-
* floor of the contract (see Machine docs); the residual gap versus EXTERNAL
|
|
10
|
-
* writers is backend-dependent and can't be closed here. Hosts override for
|
|
11
|
-
* stronger swaps (local: sync critical section; SSH: EXCL create + tmp/rename).
|
|
7
|
+
* - `run`: spawn → cap both streams → escalating kill on timeout/abort.
|
|
12
8
|
* - `realpath`: `readlink -f` via `run` on posix, normpath on win32. Hosts with
|
|
13
9
|
* a native resolver (fs.realpath, SFTP realpath) override for exactness.
|
|
14
10
|
*/
|
|
15
11
|
import type { Readable, Writable } from "node:stream";
|
|
16
|
-
import { type RunCommandResult, type DecodeErrors, type DirEntry, type
|
|
12
|
+
import { type RunCommandResult, type DecodeErrors, type DirEntry, type OsInfo, type ByteRange, type Environment, type RunCommandOptions, type FileInfo, type FileVersion, type WriteTextOptions, type WriteTextResult } from "./environment.ts";
|
|
17
13
|
/**
|
|
18
|
-
* A live OS process, normalized. IMPLEMENTER-SIDE ONLY — this is what {@link
|
|
14
|
+
* A live OS process, normalized. IMPLEMENTER-SIDE ONLY — this is what {@link BaseEnvironment.spawn}
|
|
19
15
|
* hands back so ONE copy of `run`'s read/cap/decode/kill-escalate logic can serve backends
|
|
20
16
|
* whose native process objects disagree on the details: node's `ChildProcess` kills by signal
|
|
21
17
|
* name and reports exit on one event, while an ssh2 `ClientChannel` wants the signal without
|
|
@@ -31,17 +27,22 @@ export interface SpawnedProcess {
|
|
|
31
27
|
/** null while running. Read after a kill to tell "it stopped" from "it ignored us". */
|
|
32
28
|
readonly exitCode: number | null;
|
|
33
29
|
wait(): Promise<number>;
|
|
30
|
+
/**
|
|
31
|
+
* Signal the process AND everything it started. A command reaches us as `sh -c '…'`, so the
|
|
32
|
+
* process we hold is usually just the shell — signalling only it leaves the real command
|
|
33
|
+
* running as an orphan while `run` reports it stopped.
|
|
34
|
+
*/
|
|
34
35
|
kill(signal?: NodeJS.Signals): Promise<void>;
|
|
35
36
|
}
|
|
36
|
-
export declare abstract class
|
|
37
|
+
export declare abstract class BaseEnvironment implements Environment {
|
|
37
38
|
abstract readonly name: string;
|
|
38
|
-
abstract readonly
|
|
39
|
+
abstract readonly osInfo: OsInfo;
|
|
39
40
|
abstract pathClass(): "posix" | "win32";
|
|
40
41
|
abstract normpath(path: string): string;
|
|
41
42
|
abstract gethome(): string;
|
|
42
43
|
abstract getcwd(): string;
|
|
43
|
-
abstract withCwd(cwd: string):
|
|
44
|
-
/** Extra workspace roots (see
|
|
44
|
+
abstract withCwd(cwd: string): Environment;
|
|
45
|
+
/** Extra workspace roots (see Environment.additionalDirs). Default: cwd only. */
|
|
45
46
|
additionalDirs(): readonly string[];
|
|
46
47
|
/**
|
|
47
48
|
* Spawn a live process. IMPLEMENTER-SIDE ONLY — no caller reaches for this; it exists so
|
|
@@ -65,17 +66,6 @@ export declare abstract class BaseMachine implements Machine {
|
|
|
65
66
|
abstract readBytes(path: string, range?: ByteRange): Promise<Buffer>;
|
|
66
67
|
/** Raw unconditional whole-file write — the single write primitive everything else derives from. */
|
|
67
68
|
protected abstract writeBytesRaw(path: string, data: Buffer): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* The write half of the compare-and-swap in `writeTextIfUnchanged`. Default: the same raw
|
|
70
|
-
* write as anywhere else — correct, but a reader racing it can observe a half-written file,
|
|
71
|
-
* and a crash mid-write leaves one behind.
|
|
72
|
-
*
|
|
73
|
-
* Backends that can swap a complete file into place in one indivisible step (write to a
|
|
74
|
-
* sibling temp path, then rename over the target on the same filesystem) override this. It
|
|
75
|
-
* is separate from `writeBytesRaw` because the extra round trip only earns its cost where
|
|
76
|
-
* torn state is observable — which is the CAS path, not every write.
|
|
77
|
-
*/
|
|
78
|
-
protected writeBytesSwap(path: string, data: Buffer): Promise<void>;
|
|
79
69
|
/** Decode with the shared contract: strict UTF-8 throws on invalid bytes (binary detection). */
|
|
80
70
|
protected decodeText(data: Buffer, options?: {
|
|
81
71
|
encoding?: BufferEncoding;
|
|
@@ -102,28 +92,38 @@ export declare abstract class BaseMachine implements Machine {
|
|
|
102
92
|
* contract's other half made loud rather than silent.
|
|
103
93
|
*/
|
|
104
94
|
run(argv: readonly string[], options?: RunCommandOptions): Promise<RunCommandResult>;
|
|
105
|
-
/** SIGTERM, then SIGKILL if it does not exit. Returns whether the process actually stopped. */
|
|
106
95
|
/** How long SIGTERM gets before SIGKILL, and SIGKILL before we give up. Overridable so a
|
|
107
96
|
* backend (or a test) can tighten it; the default matches the shell's own convention. */
|
|
108
97
|
protected sigtermGraceMs: number;
|
|
98
|
+
/**
|
|
99
|
+
* SIGTERM, then SIGKILL. Returns whether the process stopped within its grace.
|
|
100
|
+
*
|
|
101
|
+
* The SIGKILL is UNCONDITIONAL, including on the path where the process exited politely, and
|
|
102
|
+
* that is the whole trick. A command arrives as `sh -c '…'`, so what exits on SIGTERM is
|
|
103
|
+
* usually just the shell; anything it started that trapped the signal keeps running, and a
|
|
104
|
+
* stop that judged by the shell alone would report success over a live orphan.
|
|
105
|
+
*
|
|
106
|
+
* Sending it anyway costs nothing — the signal goes to the process GROUP, and a group with
|
|
107
|
+
* nothing left in it is an ESRCH we ignore. And it costs no TIME, which is the point: a
|
|
108
|
+
* survivor check could tell us whether the second signal is needed, but the answer only ever
|
|
109
|
+
* saves a syscall, while asking it needs a poll loop. Waiting out the grace before killing
|
|
110
|
+
* would cost real time, so we do not do that either: a child still alive after its parent
|
|
111
|
+
* died of SIGTERM has already declined to go quietly, and giving it another five seconds to
|
|
112
|
+
* reconsider is five seconds of a stopped command still holding its port.
|
|
113
|
+
*/
|
|
109
114
|
private escalatingKill;
|
|
110
115
|
/** `spawn` has no cwd parameter; a backend without a native one runs through a subshell. */
|
|
111
116
|
protected withCwdArgv(argv: readonly string[], cwd: string | undefined): string[];
|
|
117
|
+
/**
|
|
118
|
+
* The version the last write produced, for backends that can answer without a round
|
|
119
|
+
* trip. Default: nothing — a remote backend would have to stat for it, and paying that
|
|
120
|
+
* on every write to save a content comparison on the rare write-after-write is the
|
|
121
|
+
* wrong trade (see WriteTextResult.version).
|
|
122
|
+
*/
|
|
123
|
+
protected versionAfterWrite(_path: string): Promise<FileVersion | undefined>;
|
|
112
124
|
writeText(path: string, data: string, options?: WriteTextOptions): Promise<WriteTextResult>;
|
|
113
125
|
/** Exact bytes through the same primitive `writeText` uses — no encoding, no CRLF rewrite. */
|
|
114
126
|
writeBytes(path: string, data: Buffer): Promise<void>;
|
|
115
|
-
protected pathLocks: Map<string, Promise<void>>;
|
|
116
|
-
/** Key identifying "the same file" for the write lock. Backends with real path
|
|
117
|
-
* resolution override so relative and absolute spellings share one lock. */
|
|
118
|
-
protected lockKeyFor(path: string): string;
|
|
119
|
-
protected withPathLock<T>(path: string, body: () => Promise<T>): Promise<T>;
|
|
120
|
-
/**
|
|
121
|
-
* The compare half of writeTextIfUnchanged: throws unless the file still matches
|
|
122
|
-
* `options.expected`. Shared by the base composition and by backend overrides
|
|
123
|
-
* that re-check right before an atomic swap (SshMachine).
|
|
124
|
-
*/
|
|
125
|
-
protected assertUnchanged(path: string, options: WriteTextIfUnchangedOptions, encoding: BufferEncoding): Promise<void>;
|
|
126
|
-
writeTextIfUnchanged(path: string, data: string, options: WriteTextIfUnchangedOptions): Promise<WriteFileResult>;
|
|
127
127
|
/** Deadline for the readlink fallback; a test/backend subclass may shorten it. */
|
|
128
128
|
protected realpathTimeoutMs: number;
|
|
129
129
|
/**
|
|
@@ -135,4 +135,4 @@ export declare abstract class BaseMachine implements Machine {
|
|
|
135
135
|
*/
|
|
136
136
|
realpath(path: string): Promise<string>;
|
|
137
137
|
}
|
|
138
|
-
//# sourceMappingURL=
|
|
138
|
+
//# sourceMappingURL=environment-base.d.ts.map
|