stitchkit 0.127.0 → 0.128.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -6
- package/dist/agent-executor/acp/v1-connect.d.ts +9 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +8 -2
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +8 -0
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +4 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/protocol.d.ts +20 -2
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
- package/dist/agent-executor/claude/session.d.ts +2 -1
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude/transcript.d.ts +7 -4
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +4 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +4 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/protocol.d.ts +26 -2
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/session.d.ts +3 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +71 -0
- package/dist/agent-executor/image-input.d.ts.map +1 -0
- package/dist/agent-executor/session-primitives.d.ts +0 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-runtime/agent-tool.d.ts +21 -7
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
- package/dist/agent-runtime/branch-contract.d.ts +1 -0
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +5 -2
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +9 -9
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +45 -32
- package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts +12 -6
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-source.d.ts +13 -1
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/child-tools.d.ts +64 -0
- package/dist/agent-runtime/child-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-tools.d.ts +82 -5
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-payload.d.ts +12 -0
- package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-read.d.ts +6 -3
- package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-schema.d.ts +50 -8
- package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
- package/dist/agent-runtime/invocations.d.ts +20 -9
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/postgres.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-tools.d.ts +30 -0
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-invocation-payload.d.ts +48 -0
- package/dist/agent-runtime/schemas-invocation-payload.d.ts.map +1 -0
- package/dist/agent-runtime/sql-events.d.ts.map +1 -1
- package/dist/agent-runtime/sql-session.d.ts +11 -0
- package/dist/agent-runtime/sql-session.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
- package/dist/agent-runtime/state-tools.d.ts +55 -0
- package/dist/agent-runtime/state-tools.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/store-create.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +12 -0
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-events.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +7 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/declaration/declaration.d.ts +6 -3
- package/dist/declaration/declaration.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +23 -12
- package/dist/entrypoints/agent-executor/claude-sdk.js +26 -10
- package/dist/entrypoints/agent-executor/claude.js +35 -16
- package/dist/entrypoints/agent-executor/codex.js +81 -21
- package/dist/entrypoints/agent-executor.js +1 -1
- package/dist/entrypoints/agent-runtime/harness.js +5 -6
- package/dist/entrypoints/agent-runtime/openrouter.js +2 -2
- package/dist/entrypoints/agent-runtime/postgres.js +8 -3
- package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +4 -4
- package/dist/entrypoints/agent-runtime/sqlite/node.js +4 -4
- package/dist/entrypoints/agent-runtime/testing.js +6 -6
- package/dist/entrypoints/agent-runtime.d.ts +9 -7
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +246 -199
- package/dist/entrypoints/application/diagnostic-journal.js +4 -4
- package/dist/entrypoints/application/directory-inbox.js +8 -8
- package/dist/entrypoints/cli/publish.js +8 -8
- package/dist/entrypoints/cli.js +10 -9
- package/dist/entrypoints/declaration.js +0 -1
- package/dist/entrypoints/files.js +40 -17
- package/dist/entrypoints/node.js +4 -4
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process.js +1 -1
- package/dist/entrypoints/server.js +7 -7
- package/dist/entrypoints/service-host/macos.js +4 -4
- package/dist/entrypoints/service-host.d.ts +4 -1
- package/dist/entrypoints/service-host.d.ts.map +1 -1
- package/dist/entrypoints/service-host.js +831 -220
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/telegram.js +4 -4
- package/dist/entrypoints/tools/agent.js +4 -3
- package/dist/entrypoints/tools/invoker.js +3 -2
- package/dist/entrypoints/tools/mcp.js +4 -3
- package/dist/entrypoints/tools/toolkit.js +6 -5
- package/dist/entrypoints/tools.d.ts +1 -1
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +10 -8
- package/dist/files/directory-appearance.d.ts +20 -9
- package/dist/files/directory-appearance.d.ts.map +1 -1
- package/dist/files/polled-json.d.ts.map +1 -1
- package/dist/files/regular-file.d.ts +15 -5
- package/dist/files/regular-file.d.ts.map +1 -1
- package/dist/{index-z4k0hqp9.js → index-0gqs8ght.js} +106 -24
- package/dist/{index-caywx1c0.js → index-13dnv6d0.js} +107 -10
- package/dist/{index-a725ayvz.js → index-1qwrczr1.js} +1 -1
- package/dist/{index-xtkw9866.js → index-2c5w2d1d.js} +1 -1
- package/dist/{index-g1q7fwn9.js → index-2nwvn7m2.js} +1 -1
- package/dist/{index-4s2w4g37.js → index-3tnwtz38.js} +80 -2
- package/dist/{index-5e0zsbf7.js → index-4j8efqr3.js} +1 -1
- package/dist/{index-p1m9djt6.js → index-5v5vg85s.js} +1 -1
- package/dist/{index-x90w78yz.js → index-673drwkn.js} +23 -8
- package/dist/{index-7xp05h20.js → index-6wp4dn9d.js} +6 -6
- package/dist/{index-0hdm5sx6.js → index-8x22nprv.js} +6 -2
- package/dist/{index-j13gzgdv.js → index-bz3gn6cs.js} +8 -4
- package/dist/{index-d96c1n1q.js → index-c5gp2gh6.js} +20 -19
- package/dist/{index-wbnpa8z6.js → index-d54npte7.js} +4 -4
- package/dist/{index-kmbpej2y.js → index-emgrmavr.js} +102 -61
- package/dist/{index-bbzvrq66.js → index-g3e57qj6.js} +455 -202
- package/dist/index-gf92hc87.js +100 -0
- package/dist/{index-3djgv3ch.js → index-gzny6zsw.js} +25 -10
- package/dist/{index-3b31z0pc.js → index-hj1zq7mh.js} +12 -6
- package/dist/{index-8xr2eq99.js → index-jfecdk1e.js} +3 -3
- package/dist/{index-dvd1qdwa.js → index-ke02kxsr.js} +3 -3
- package/dist/{index-83n766x4.js → index-m18xm96h.js} +15 -9
- package/dist/{index-qnzhmk2s.js → index-n7f89hjw.js} +90 -47
- package/dist/{index-3agqmmrg.js → index-pn5b11ce.js} +7 -9
- package/dist/{index-3gwp8ez6.js → index-pwskmywy.js} +12 -17
- package/dist/{index-9wh98cpa.js → index-rxnyygke.js} +130 -90
- package/dist/{index-0djnptn8.js → index-rzeezh79.js} +10 -3
- package/dist/{index-nbv44x0x.js → index-s2e3h616.js} +137 -36
- package/dist/{index-5zwac8ft.js → index-t7wa7k12.js} +2 -2
- package/dist/{index-xypxnzhp.js → index-v1mxss62.js} +2 -2
- package/dist/index-vgzhw2zk.js +304 -0
- package/dist/{index-jrka9029.js → index-vmbxj75t.js} +2 -2
- package/dist/{index-j516jaaz.js → index-waa6t4zx.js} +49 -2
- package/dist/{index-fcw255hd.js → index-xv9jb84s.js} +2 -2
- package/dist/{index-dwa6pskj.js → index-y065r8g5.js} +82 -43
- package/dist/internal/bounded-file-confirm.d.ts +32 -0
- package/dist/internal/bounded-file-confirm.d.ts.map +1 -0
- package/dist/internal/bounded-file-read.d.ts +10 -7
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/internal/file-observation.d.ts +5 -1
- package/dist/internal/file-observation.d.ts.map +1 -1
- package/dist/internal/process-instance.d.ts +8 -0
- package/dist/internal/process-instance.d.ts.map +1 -1
- package/dist/internal/unix-socket.d.ts +3 -1
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/server/unix-client.d.ts +7 -0
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/service-host/systemd-inspect.d.ts +3 -1
- package/dist/service-host/systemd-inspect.d.ts.map +1 -1
- package/dist/service-host/systemd-render-shared.d.ts +64 -0
- package/dist/service-host/systemd-render-shared.d.ts.map +1 -0
- package/dist/service-host/systemd-render.d.ts +31 -26
- package/dist/service-host/systemd-render.d.ts.map +1 -1
- package/dist/service-host/systemd-timer-render.d.ts +31 -0
- package/dist/service-host/systemd-timer-render.d.ts.map +1 -0
- package/dist/service-host/systemd-timer-rollback.d.ts +26 -0
- package/dist/service-host/systemd-timer-rollback.d.ts.map +1 -0
- package/dist/service-host/systemd-timer.d.ts +82 -0
- package/dist/service-host/systemd-timer.d.ts.map +1 -0
- package/dist/service-host/systemd-unit-ops.d.ts +26 -0
- package/dist/service-host/systemd-unit-ops.d.ts.map +1 -0
- package/dist/service-host/systemd.d.ts +1 -1
- package/dist/service-host/systemd.d.ts.map +1 -1
- package/dist/tools/access.d.ts +30 -1
- package/dist/tools/access.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -2
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-scan.d.ts +5 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts +11 -5
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +2 -1
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/notices.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -1
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +2 -3
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -3
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -5
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +10 -6
- package/llms/agent-executor-claude-sdk.txt +1 -1
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-runtime.4.txt +21 -9
- package/llms/cli.3.txt +4 -4
- package/llms/cli.txt +1 -0
- package/llms/declaration.txt +2 -2
- package/llms/files.txt +1 -1
- package/llms/node.txt +2 -2
- package/llms/server.5.txt +2 -2
- package/llms/service-host.txt +5 -5
- package/llms/stitchkit.txt +81 -77
- package/llms/tools.3.txt +3 -2
- package/llms/upgrading-0.128.0.txt +147 -0
- package/llms/upgrading.txt +1 -0
- package/llms-full.txt +272 -113
- package/llms.txt +14 -13
- package/package.json +1 -1
- package/dist/index-ajmtxsky.js +0 -193
- package/dist/index-ax3wns1a.js +0 -93
|
@@ -3,19 +3,15 @@ import {
|
|
|
3
3
|
} from "./index-r9kq5ark.js";
|
|
4
4
|
import {
|
|
5
5
|
BoundedFileReadError,
|
|
6
|
-
isNonRegularOpenErrno,
|
|
7
6
|
readBoundedFileFrom,
|
|
8
7
|
readBoundedFileSync
|
|
9
|
-
} from "./index-
|
|
8
|
+
} from "./index-s2e3h616.js";
|
|
10
9
|
import {
|
|
11
10
|
isUnsafeKey
|
|
12
11
|
} from "./index-zsarb5xp.js";
|
|
13
12
|
import {
|
|
14
13
|
formatZodError2
|
|
15
14
|
} from "./index-1eeqpadm.js";
|
|
16
|
-
import {
|
|
17
|
-
errnoOf
|
|
18
|
-
} from "./index-jj9228tt.js";
|
|
19
15
|
import {
|
|
20
16
|
assertPositiveSafeInteger
|
|
21
17
|
} from "./index-kzavdze2.js";
|
|
@@ -84,18 +80,13 @@ function refusalOf(error, path, limit) {
|
|
|
84
80
|
return new RegularFileError2("not-regular", `Not a regular file: ${path}`, options);
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
|
-
if (isNonRegularOpenErrno(errnoOf(error))) {
|
|
88
|
-
return new RegularFileError2("not-regular", `Not a regular file: ${path}`, {
|
|
89
|
-
cause: error
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
83
|
return;
|
|
93
84
|
}
|
|
94
85
|
function retryOn(error, path, limit) {
|
|
95
86
|
const refusal = refusalOf(error, path, limit);
|
|
96
87
|
if (refusal === undefined)
|
|
97
88
|
throw error;
|
|
98
|
-
if (
|
|
89
|
+
if (!(error instanceof BoundedFileReadError) || error.code !== "FILE_CHANGED")
|
|
99
90
|
throw refusal;
|
|
100
91
|
return refusal;
|
|
101
92
|
}
|
|
@@ -111,28 +102,28 @@ function withOneRetry(path, limit, attempt) {
|
|
|
111
102
|
throw retryOn(error, path, limit);
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
|
-
function readRegularFileWithMetaSync(path, options = {}, openFd = openSync) {
|
|
105
|
+
function readRegularFileWithMetaSync(path, options = {}, openFd = openSync, snapshot) {
|
|
115
106
|
const { limit = DEFAULT_JSON_FILE_BYTES2, noFollow, accept } = options;
|
|
116
107
|
assertPositiveSafeInteger("limit", limit);
|
|
117
108
|
assertNoFollowAvailable(path, noFollow);
|
|
118
109
|
const inspect = acceptCheck(accept, path);
|
|
119
110
|
return withOneRetry(path, limit, () => {
|
|
120
|
-
const { bytes, after } = readBoundedFileSync(path, limit, { stable: true, rejectSymlinks: noFollow, inspect }, openFd);
|
|
111
|
+
const { bytes, after } = readBoundedFileSync(path, limit, { stable: true, rejectSymlinks: noFollow, inspect }, openFd, snapshot);
|
|
121
112
|
return { bytes, after };
|
|
122
113
|
});
|
|
123
114
|
}
|
|
124
115
|
function readRegularFileSync2(path, options) {
|
|
125
116
|
return readRegularFileWithMetaSync(path, options).bytes;
|
|
126
117
|
}
|
|
127
|
-
async function
|
|
118
|
+
async function readRegularFileWithMeta(path, options = {}, openDescriptor = open, snapshot) {
|
|
128
119
|
const { limit = DEFAULT_JSON_FILE_BYTES2, noFollow, accept, signal } = options;
|
|
129
120
|
assertPositiveSafeInteger("limit", limit);
|
|
130
121
|
assertNoFollowAvailable(path, noFollow);
|
|
131
122
|
const inspect = acceptCheck(accept, path);
|
|
132
123
|
const attempt = async () => {
|
|
133
124
|
signal?.throwIfAborted();
|
|
134
|
-
const read = await readBoundedFileFrom(path, limit, { stable: true, signal, rejectSymlinks: noFollow, inspect }, openDescriptor);
|
|
135
|
-
return read.bytes;
|
|
125
|
+
const read = await readBoundedFileFrom(path, limit, { stable: true, signal, rejectSymlinks: noFollow, inspect }, openDescriptor, snapshot);
|
|
126
|
+
return { bytes: read.bytes, ...read.after !== undefined && { after: read.after } };
|
|
136
127
|
};
|
|
137
128
|
try {
|
|
138
129
|
return await attempt();
|
|
@@ -145,6 +136,10 @@ async function readRegularFileFromOpen(path, options = {}, openDescriptor = open
|
|
|
145
136
|
throw retryOn(error, path, limit);
|
|
146
137
|
}
|
|
147
138
|
}
|
|
139
|
+
async function readRegularFileFromOpen(path, options = {}, openDescriptor = open, snapshot) {
|
|
140
|
+
const { bytes } = await readRegularFileWithMeta(path, options, openDescriptor, snapshot);
|
|
141
|
+
return bytes;
|
|
142
|
+
}
|
|
148
143
|
function readRegularFile2(path, options) {
|
|
149
144
|
return readRegularFileFromOpen(path, options);
|
|
150
145
|
}
|
|
@@ -197,4 +192,4 @@ function readJsonFileSync2(path, schema, options) {
|
|
|
197
192
|
return validateJsonValue(parseJsonText(decodeJsonText(bytes, path), path), schema, path);
|
|
198
193
|
}
|
|
199
194
|
|
|
200
|
-
export { DEFAULT_JSON_FILE_BYTES2, RegularFileError2, fileIdentity2, fileCacheIdentity, readRegularFileWithMetaSync, readRegularFileSync2,
|
|
195
|
+
export { DEFAULT_JSON_FILE_BYTES2, RegularFileError2, fileIdentity2, fileCacheIdentity, readRegularFileWithMetaSync, readRegularFileSync2, readRegularFileWithMeta, readRegularFile2, decodeJsonText, parseJsonText, validateJsonValue, parseJsonBytes2, readJsonFileSync2 };
|
|
@@ -6,18 +6,14 @@ import {
|
|
|
6
6
|
localVerdict
|
|
7
7
|
} from "./index-dsa676h8.js";
|
|
8
8
|
import {
|
|
9
|
-
objectShapeKeys
|
|
10
|
-
rebuildObject,
|
|
11
|
-
mergeSchemas
|
|
9
|
+
objectShapeKeys
|
|
12
10
|
} from "./index-360j58vb.js";
|
|
13
11
|
import {
|
|
14
12
|
coerceJsonArgs2
|
|
15
13
|
} from "./index-j903yhp4.js";
|
|
16
14
|
import {
|
|
17
15
|
applyToolViewDefaults,
|
|
18
|
-
projectToolView
|
|
19
|
-
assertToolExtensionCompatible,
|
|
20
|
-
projectToolSurface
|
|
16
|
+
projectToolView
|
|
21
17
|
} from "./index-3ypvpkwr.js";
|
|
22
18
|
import {
|
|
23
19
|
runWithRequestContext2,
|
|
@@ -42,6 +38,130 @@ import {
|
|
|
42
38
|
isRecord
|
|
43
39
|
} from "./index-ps3djm8d.js";
|
|
44
40
|
|
|
41
|
+
// src/tools/access.ts
|
|
42
|
+
var TOOL_OPEN_REASONS = ["public", "local-operator", "remote"];
|
|
43
|
+
var TOOL_OPEN_REASON_SET = new Set(TOOL_OPEN_REASONS);
|
|
44
|
+
var inspectOnlyLifecycles = new WeakMap;
|
|
45
|
+
function accessRequiredMessage(entryName) {
|
|
46
|
+
return `${entryName}: access is required — pass { gate } with the auth hook, { open }, or { inspect: true }`;
|
|
47
|
+
}
|
|
48
|
+
function legacyLifecycleMessage(entryName) {
|
|
49
|
+
return `${entryName}: access is required — pass { gate } with the auth hook, { open }, or { inspect: true } ("lifecycle" was replaced by "access")`;
|
|
50
|
+
}
|
|
51
|
+
function inspectForbiddenError(entryName) {
|
|
52
|
+
return new AppError2("FORBIDDEN", {
|
|
53
|
+
message: `${entryName}: mounted with access: { inspect: true } (read-only surface inspection); tool execution is forbidden`,
|
|
54
|
+
status: 403
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function isInspectOnlyLifecycle(lifecycle) {
|
|
58
|
+
return lifecycle !== undefined && inspectOnlyLifecycles.has(lifecycle);
|
|
59
|
+
}
|
|
60
|
+
function inspectOnlyError(lifecycle) {
|
|
61
|
+
if (lifecycle === undefined)
|
|
62
|
+
return;
|
|
63
|
+
const entryName = inspectOnlyLifecycles.get(lifecycle);
|
|
64
|
+
return entryName !== undefined ? inspectForbiddenError(entryName) : undefined;
|
|
65
|
+
}
|
|
66
|
+
function isBeforeHandleHook(value) {
|
|
67
|
+
return typeof value === "function";
|
|
68
|
+
}
|
|
69
|
+
function isAfterHandleHook(value) {
|
|
70
|
+
return typeof value === "function";
|
|
71
|
+
}
|
|
72
|
+
function isToolOpenReason(value) {
|
|
73
|
+
return typeof value === "string" && TOOL_OPEN_REASON_SET.has(value);
|
|
74
|
+
}
|
|
75
|
+
function resolveToolAccess(entryName, config) {
|
|
76
|
+
if (!isRecord(config)) {
|
|
77
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
78
|
+
}
|
|
79
|
+
if (Object.hasOwn(config, "lifecycle")) {
|
|
80
|
+
throw new TypeError(legacyLifecycleMessage(entryName));
|
|
81
|
+
}
|
|
82
|
+
if (!Object.hasOwn(config, "access")) {
|
|
83
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
84
|
+
}
|
|
85
|
+
const { access } = config;
|
|
86
|
+
if (!isRecord(access)) {
|
|
87
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
88
|
+
}
|
|
89
|
+
const hasGate = Object.hasOwn(access, "gate") && access.gate !== undefined;
|
|
90
|
+
const hasOpen = Object.hasOwn(access, "open") && access.open !== undefined;
|
|
91
|
+
const hasInspect = Object.hasOwn(access, "inspect") && access.inspect !== undefined;
|
|
92
|
+
if (Number(hasGate) + Number(hasOpen) + Number(hasInspect) !== 1) {
|
|
93
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
94
|
+
}
|
|
95
|
+
if (hasGate) {
|
|
96
|
+
for (const key of Object.keys(access)) {
|
|
97
|
+
if (key === "gate")
|
|
98
|
+
continue;
|
|
99
|
+
if ((key === "open" || key === "inspect" || key === "afterHandle") && access[key] === undefined)
|
|
100
|
+
continue;
|
|
101
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
102
|
+
}
|
|
103
|
+
const { gate } = access;
|
|
104
|
+
if (!isRecord(gate)) {
|
|
105
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
106
|
+
}
|
|
107
|
+
const { beforeHandle, afterHandle } = gate;
|
|
108
|
+
if (!isBeforeHandleHook(beforeHandle)) {
|
|
109
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
110
|
+
}
|
|
111
|
+
if (afterHandle !== undefined && !isAfterHandleHook(afterHandle)) {
|
|
112
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
113
|
+
}
|
|
114
|
+
return afterHandle !== undefined ? { beforeHandle, afterHandle } : { beforeHandle };
|
|
115
|
+
}
|
|
116
|
+
if (hasInspect) {
|
|
117
|
+
for (const key of Object.keys(access)) {
|
|
118
|
+
if (key === "inspect")
|
|
119
|
+
continue;
|
|
120
|
+
if ((key === "gate" || key === "open" || key === "afterHandle") && access[key] === undefined)
|
|
121
|
+
continue;
|
|
122
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
123
|
+
}
|
|
124
|
+
if (access.inspect !== true) {
|
|
125
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
126
|
+
}
|
|
127
|
+
const lifecycle = {
|
|
128
|
+
beforeHandle() {
|
|
129
|
+
throw inspectForbiddenError(entryName);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
inspectOnlyLifecycles.set(lifecycle, entryName);
|
|
133
|
+
return lifecycle;
|
|
134
|
+
}
|
|
135
|
+
for (const key of Object.keys(access)) {
|
|
136
|
+
if (key === "open" || key === "afterHandle")
|
|
137
|
+
continue;
|
|
138
|
+
if ((key === "gate" || key === "inspect") && access[key] === undefined)
|
|
139
|
+
continue;
|
|
140
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
141
|
+
}
|
|
142
|
+
const { open, afterHandle } = access;
|
|
143
|
+
if (!isToolOpenReason(open)) {
|
|
144
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
145
|
+
}
|
|
146
|
+
if (afterHandle !== undefined && !isAfterHandleHook(afterHandle)) {
|
|
147
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
148
|
+
}
|
|
149
|
+
return afterHandle !== undefined ? { afterHandle } : {};
|
|
150
|
+
}
|
|
151
|
+
function resolveOptionalCliToolAccess(entryName, config) {
|
|
152
|
+
if (!isRecord(config)) {
|
|
153
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
154
|
+
}
|
|
155
|
+
if (Object.hasOwn(config, "lifecycle")) {
|
|
156
|
+
throw new TypeError(legacyLifecycleMessage(entryName));
|
|
157
|
+
}
|
|
158
|
+
const hasManagedSurface = config.services !== undefined || config.runtimeTools !== undefined;
|
|
159
|
+
if (hasManagedSurface || Object.hasOwn(config, "access") && config.access !== undefined) {
|
|
160
|
+
return resolveToolAccess(entryName, config);
|
|
161
|
+
}
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
|
|
45
165
|
// src/tools/execute-args.ts
|
|
46
166
|
import { z } from "zod";
|
|
47
167
|
function parseToolCallArguments(method, callArgs, {
|
|
@@ -178,6 +298,9 @@ var noProgress = async () => {
|
|
|
178
298
|
return;
|
|
179
299
|
};
|
|
180
300
|
async function executeToolMethod(method, call, options = {}) {
|
|
301
|
+
const inspectErr = inspectOnlyError(options.lifecycle);
|
|
302
|
+
if (inspectErr)
|
|
303
|
+
return toolResultFromError(inspectErr);
|
|
181
304
|
const { toolName, context } = call;
|
|
182
305
|
return inToolCallContext({ source: context.source, toolName, method }, () => runToolMethod(method, call, options));
|
|
183
306
|
}
|
|
@@ -386,87 +509,4 @@ async function runToolMethod(method, { toolName, rawArgs, context }, {
|
|
|
386
509
|
}
|
|
387
510
|
}
|
|
388
511
|
|
|
389
|
-
|
|
390
|
-
import { z as z2 } from "zod";
|
|
391
|
-
function applyExtend(base, extra) {
|
|
392
|
-
if (base instanceof z2.ZodObject) {
|
|
393
|
-
assertToolExtensionCompatible(base, extra);
|
|
394
|
-
return rebuildObject(base, { ...extra, ...base.shape });
|
|
395
|
-
}
|
|
396
|
-
return z2.intersection(z2.object(extra), base);
|
|
397
|
-
}
|
|
398
|
-
function contractToolMountable(projected, extend) {
|
|
399
|
-
const method = projected.source;
|
|
400
|
-
const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
|
|
401
|
-
const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
|
|
402
|
-
return {
|
|
403
|
-
method,
|
|
404
|
-
name: projected.name,
|
|
405
|
-
argumentSchema,
|
|
406
|
-
presentationSchema: projected.presentationSchema,
|
|
407
|
-
shouldExtend: projected.shouldExtend
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function collectTools2(service, transport, config = {}) {
|
|
411
|
-
const {
|
|
412
|
-
extend,
|
|
413
|
-
flattenUnionInput = false,
|
|
414
|
-
inputRecursionDepth,
|
|
415
|
-
assertNames = true
|
|
416
|
-
} = config;
|
|
417
|
-
const tools = [];
|
|
418
|
-
for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
|
|
419
|
-
extend,
|
|
420
|
-
flattenUnionInput,
|
|
421
|
-
inputRecursionDepth,
|
|
422
|
-
assertNames,
|
|
423
|
-
assertUniqueNames: false
|
|
424
|
-
})) {
|
|
425
|
-
if (projected.kind !== "contract")
|
|
426
|
-
continue;
|
|
427
|
-
tools.push(contractToolMountable(projected, extend));
|
|
428
|
-
}
|
|
429
|
-
return tools;
|
|
430
|
-
}
|
|
431
|
-
function createToolRunner(config) {
|
|
432
|
-
const extension = config.extend ? {
|
|
433
|
-
schema: z2.object(config.extend.schema),
|
|
434
|
-
resolve: config.extend.resolve
|
|
435
|
-
} : undefined;
|
|
436
|
-
return async function runOneToolCall(tool, rawArgs, context, call) {
|
|
437
|
-
return executeToolMethod(tool.method, {
|
|
438
|
-
toolName: tool.name,
|
|
439
|
-
rawArgs,
|
|
440
|
-
context: { ...config.context, ...context, source: config.source }
|
|
441
|
-
}, {
|
|
442
|
-
hooks: config.hooks,
|
|
443
|
-
lifecycle: config.lifecycle,
|
|
444
|
-
coerceJson: config.coerceJsonArgs ?? true,
|
|
445
|
-
onOutputStrip: config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined,
|
|
446
|
-
extension: tool.shouldExtend ? extension : undefined,
|
|
447
|
-
toolSurface: config.toolSurface ?? false,
|
|
448
|
-
finalizeOutput: call?.finalizeOutput
|
|
449
|
-
});
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
function formatToolError(result, toolName, errorHint) {
|
|
453
|
-
const err = {
|
|
454
|
-
error: result.code,
|
|
455
|
-
retryable: result.retryable ?? isRetryableStatus2(toolErrorFromResult(result).status)
|
|
456
|
-
};
|
|
457
|
-
if (result.details)
|
|
458
|
-
err.details = result.details;
|
|
459
|
-
const hints = [];
|
|
460
|
-
if (result.hint)
|
|
461
|
-
hints.push(result.hint);
|
|
462
|
-
if (errorHint && toolName) {
|
|
463
|
-
const global = errorHint(toolName, result.code);
|
|
464
|
-
if (global)
|
|
465
|
-
hints.push(global);
|
|
466
|
-
}
|
|
467
|
-
if (hints.length > 0)
|
|
468
|
-
err._hint = hints.join(" ");
|
|
469
|
-
return err;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export { parseToolCallArguments, toolResultFromError, toolErrorFromResult, toolCauseFromResult, observed, ToolExecutionControlError2, isToolExecutionControlError2, contractToolMountable, collectTools2, createToolRunner, formatToolError };
|
|
512
|
+
export { isInspectOnlyLifecycle, inspectOnlyError, resolveToolAccess, resolveOptionalCliToolAccess, parseToolCallArguments, toolResultFromError, toolErrorFromResult, toolCauseFromResult, observed, ToolExecutionControlError2, isToolExecutionControlError2, executeToolMethod };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
nextEventSeqByMaximum,
|
|
8
8
|
agentSqlTables,
|
|
9
9
|
createAgentRuntimeStore2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-g3e57qj6.js";
|
|
11
11
|
import {
|
|
12
12
|
canonicalAgentJson2
|
|
13
13
|
} from "./index-9xr44d2g.js";
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
scanSqlRecoverable,
|
|
23
23
|
listSqlConversations,
|
|
24
24
|
pageSqlConversationMessages
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-3tnwtz38.js";
|
|
26
26
|
import {
|
|
27
27
|
rollbackSqliteFailure
|
|
28
28
|
} from "./index-ttexdtjj.js";
|
|
@@ -398,7 +398,14 @@ var sqliteDialect = {
|
|
|
398
398
|
conversationTables: conversationTables(TABLES3),
|
|
399
399
|
messageRowId: "rowid",
|
|
400
400
|
contains: (column) => `instr(${column}, ?) > 0`,
|
|
401
|
-
nextEventSeq: (session, conversationId) => nextEventSeqByMaximum(sqliteDialect, session, conversationId)
|
|
401
|
+
nextEventSeq: (session, conversationId) => nextEventSeqByMaximum(sqliteDialect, session, conversationId),
|
|
402
|
+
async syncUpdatedEventSearch(session, event) {
|
|
403
|
+
if (event.rowId === undefined)
|
|
404
|
+
return;
|
|
405
|
+
await session.run(`DELETE FROM ${TABLES3.events}_fts WHERE rowid = ?`, [event.rowId]);
|
|
406
|
+
await session.run(`INSERT INTO ${TABLES3.events}_fts (rowid, conversation_id, event_seq, occurred_at, body)
|
|
407
|
+
VALUES (?, ?, ?, ?, ?)`, [event.rowId, event.conversationId, event.seq, event.occurredAt, event.payload]);
|
|
408
|
+
}
|
|
402
409
|
};
|
|
403
410
|
function sqliteSession(database) {
|
|
404
411
|
return {
|
|
@@ -39,6 +39,82 @@ import {
|
|
|
39
39
|
readSync
|
|
40
40
|
} from "node:fs";
|
|
41
41
|
import { open } from "node:fs/promises";
|
|
42
|
+
|
|
43
|
+
// src/internal/bounded-file-confirm.ts
|
|
44
|
+
import { lstatSync, statSync } from "node:fs";
|
|
45
|
+
import { lstat, stat } from "node:fs/promises";
|
|
46
|
+
function sameDeviceOrInode(a, b) {
|
|
47
|
+
return typeof a === "bigint" || typeof b === "bigint" ? BigInt(a) === BigInt(b) : a === b;
|
|
48
|
+
}
|
|
49
|
+
function sameSize(statSize, byteLength) {
|
|
50
|
+
return typeof statSize === "bigint" ? statSize === BigInt(byteLength) : statSize === byteLength;
|
|
51
|
+
}
|
|
52
|
+
function isPathSwapErrno(code, rejectSymlinks) {
|
|
53
|
+
return code === "ENOENT" || code === "ENOTDIR" || rejectSymlinks === true && code === "ELOOP";
|
|
54
|
+
}
|
|
55
|
+
function matchesNamedPath(after, named) {
|
|
56
|
+
return named.isFile() && sameDeviceOrInode(after.dev, named.dev) && sameDeviceOrInode(after.ino, named.ino);
|
|
57
|
+
}
|
|
58
|
+
function defaultNamedStat(path, rejectSymlinks) {
|
|
59
|
+
return rejectSymlinks ? lstat(path, { bigint: true }) : stat(path, { bigint: true });
|
|
60
|
+
}
|
|
61
|
+
function defaultNamedStatSync(path, rejectSymlinks) {
|
|
62
|
+
return rejectSymlinks ? lstatSync(path, { bigint: true }) : statSync(path, { bigint: true });
|
|
63
|
+
}
|
|
64
|
+
function isNanosecondStats(info) {
|
|
65
|
+
return typeof info.ino === "bigint" && "mtimeNs" in info && typeof info.mtimeNs === "bigint";
|
|
66
|
+
}
|
|
67
|
+
var observationOf = (info) => ({
|
|
68
|
+
dev: info.dev,
|
|
69
|
+
ino: info.ino,
|
|
70
|
+
size: info.size,
|
|
71
|
+
nlink: info.nlink,
|
|
72
|
+
mtimeMs: info.mtimeMs,
|
|
73
|
+
ctimeMs: info.ctimeMs
|
|
74
|
+
});
|
|
75
|
+
function nsToFloatMs(ns) {
|
|
76
|
+
return Number(ns / 1000000000n) * 1000 + Number(ns % 1000000000n) / 1e6;
|
|
77
|
+
}
|
|
78
|
+
var bigObservation = (info) => ({
|
|
79
|
+
dev: Number(info.dev),
|
|
80
|
+
ino: Number(info.ino),
|
|
81
|
+
size: Number(info.size),
|
|
82
|
+
nlink: Number(info.nlink),
|
|
83
|
+
mtimeMs: nsToFloatMs(info.mtimeNs),
|
|
84
|
+
ctimeMs: nsToFloatMs(info.ctimeNs)
|
|
85
|
+
});
|
|
86
|
+
function toObservation(info) {
|
|
87
|
+
return isNanosecondStats(info) ? bigObservation(info) : observationOf(info);
|
|
88
|
+
}
|
|
89
|
+
function statsViewOf(info) {
|
|
90
|
+
return {
|
|
91
|
+
dev: Number(info.dev),
|
|
92
|
+
ino: Number(info.ino),
|
|
93
|
+
size: Number(info.size),
|
|
94
|
+
nlink: Number(info.nlink),
|
|
95
|
+
mtimeMs: nsToFloatMs(info.mtimeNs),
|
|
96
|
+
ctimeMs: nsToFloatMs(info.ctimeNs),
|
|
97
|
+
mode: Number(info.mode),
|
|
98
|
+
uid: Number(info.uid),
|
|
99
|
+
gid: Number(info.gid),
|
|
100
|
+
isFile: () => info.isFile(),
|
|
101
|
+
isDirectory: () => info.isDirectory?.() ?? false,
|
|
102
|
+
isSymbolicLink: () => info.isSymbolicLink?.() ?? false
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function sameBigStat(before, after, length) {
|
|
106
|
+
return after.isFile() && before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs && before.nlink === after.nlink && before.mode === after.mode && before.uid === after.uid && before.gid === after.gid && BigInt(length) === after.size;
|
|
107
|
+
}
|
|
108
|
+
function sameReadStat(before, after, length) {
|
|
109
|
+
if (isNanosecondStats(before) && isNanosecondStats(after)) {
|
|
110
|
+
return sameBigStat(before, after, length);
|
|
111
|
+
}
|
|
112
|
+
const b = toObservation(before);
|
|
113
|
+
const a = toObservation(after);
|
|
114
|
+
return after.isFile() && b.dev === a.dev && b.ino === a.ino && b.size === a.size && b.mtimeMs === a.mtimeMs && b.ctimeMs === a.ctimeMs && b.nlink === a.nlink && (before.mode === undefined ? undefined : Number(before.mode)) === (after.mode === undefined ? undefined : Number(after.mode)) && (before.uid === undefined ? undefined : Number(before.uid)) === (after.uid === undefined ? undefined : Number(after.uid)) && (before.gid === undefined ? undefined : Number(before.gid)) === (after.gid === undefined ? undefined : Number(after.gid)) && sameSize(after.size, length);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/internal/bounded-file-read.ts
|
|
42
118
|
class BoundedFileReadError extends Error {
|
|
43
119
|
code;
|
|
44
120
|
observation;
|
|
@@ -49,14 +125,6 @@ class BoundedFileReadError extends Error {
|
|
|
49
125
|
this.name = "BoundedFileReadError";
|
|
50
126
|
}
|
|
51
127
|
}
|
|
52
|
-
var observationOf = (info) => ({
|
|
53
|
-
dev: info.dev,
|
|
54
|
-
ino: info.ino,
|
|
55
|
-
size: info.size,
|
|
56
|
-
nlink: info.nlink,
|
|
57
|
-
mtimeMs: info.mtimeMs,
|
|
58
|
-
ctimeMs: info.ctimeMs
|
|
59
|
-
});
|
|
60
128
|
function isNonRegularOpenErrno(code) {
|
|
61
129
|
return code === "EISDIR" || code === "ENXIO" || code === "EOPNOTSUPP";
|
|
62
130
|
}
|
|
@@ -79,11 +147,12 @@ async function openChecked(target, options, openDescriptor) {
|
|
|
79
147
|
throw error;
|
|
80
148
|
}
|
|
81
149
|
try {
|
|
82
|
-
const before = await handle.stat();
|
|
150
|
+
const before = await handle.stat({ bigint: true });
|
|
83
151
|
if (!before.isFile())
|
|
84
152
|
throw new BoundedFileReadError("FILE_NOT_REGULAR", "managed path is not a regular file");
|
|
85
|
-
|
|
86
|
-
|
|
153
|
+
const nlink = typeof before.nlink === "bigint" ? Number(before.nlink) : before.nlink;
|
|
154
|
+
if (options.singleLink && nlink !== 1)
|
|
155
|
+
throw new BoundedFileReadError("FILE_UNSAFE_LINK", "managed file has multiple links", toObservation(before));
|
|
87
156
|
return { handle, before };
|
|
88
157
|
} catch (error) {
|
|
89
158
|
await handle.close().catch(() => {
|
|
@@ -92,35 +161,66 @@ async function openChecked(target, options, openDescriptor) {
|
|
|
92
161
|
throw error;
|
|
93
162
|
}
|
|
94
163
|
}
|
|
95
|
-
function openRegularFile(target, options = {}) {
|
|
96
|
-
|
|
164
|
+
async function openRegularFile(target, options = {}) {
|
|
165
|
+
const { handle, before } = await openChecked(target, options, open);
|
|
166
|
+
return { handle, before: toObservation(before) };
|
|
97
167
|
}
|
|
98
168
|
var tooLarge = (maxBytes, observation) => new BoundedFileReadError("FILE_TOO_LARGE", `file exceeds the ${maxBytes}-byte cap`, observation);
|
|
99
169
|
function readBoundedFile(target, maxBytes, options = {}, openDescriptor = open) {
|
|
100
170
|
return readBoundedFileFrom(target, maxBytes, options, openDescriptor);
|
|
101
171
|
}
|
|
102
|
-
|
|
172
|
+
function confirmNamedPath(after, named) {
|
|
173
|
+
if (!matchesNamedPath(after, named)) {
|
|
174
|
+
throw new BoundedFileReadError("FILE_CHANGED", "managed file path changed during read");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function readBoundedFileFrom(target, maxBytes, options, openDescriptor, snapshot = {}) {
|
|
103
178
|
options.signal?.throwIfAborted();
|
|
104
179
|
const { handle, before } = await openChecked(target, options, openDescriptor);
|
|
105
180
|
return closeAfter(handle, async () => {
|
|
106
181
|
try {
|
|
107
182
|
options.signal?.throwIfAborted();
|
|
108
|
-
|
|
183
|
+
const beforeSize = typeof before.size === "bigint" ? before.size : BigInt(before.size);
|
|
184
|
+
if (beforeSize > BigInt(maxBytes))
|
|
109
185
|
throw tooLarge(maxBytes);
|
|
110
|
-
options.inspect?.(before);
|
|
186
|
+
options.inspect?.(isNanosecondStats(before) ? statsViewOf(before) : before);
|
|
111
187
|
const bytes = await readHandle(handle, maxBytes, options.signal);
|
|
112
|
-
const after = await handle.stat();
|
|
113
|
-
if (options.stable && (before
|
|
188
|
+
const after = await handle.stat({ bigint: true });
|
|
189
|
+
if (options.stable && !sameReadStat(before, after, bytes.length))
|
|
114
190
|
throw new BoundedFileReadError("FILE_CHANGED", "managed file changed during read");
|
|
191
|
+
if (options.stable) {
|
|
192
|
+
options.signal?.throwIfAborted();
|
|
193
|
+
let named;
|
|
194
|
+
try {
|
|
195
|
+
named = snapshot.namedStat ? await snapshot.namedStat(target) : await defaultNamedStat(target, options.rejectSymlinks);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (isPathSwapErrno(errnoOf(error), options.rejectSymlinks)) {
|
|
198
|
+
throw new BoundedFileReadError("FILE_CHANGED", "managed file path changed during read", undefined, {
|
|
199
|
+
cause: error
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
confirmNamedPath(after, named);
|
|
205
|
+
}
|
|
115
206
|
options.signal?.throwIfAborted();
|
|
116
|
-
return {
|
|
207
|
+
return {
|
|
208
|
+
bytes,
|
|
209
|
+
observation: toObservation(after),
|
|
210
|
+
mode: after.mode === undefined ? undefined : Number(after.mode),
|
|
211
|
+
...isNanosecondStats(after) && { after }
|
|
212
|
+
};
|
|
117
213
|
} catch (error) {
|
|
118
214
|
if (error instanceof BoundedFileReadError && error.code === "FILE_TOO_LARGE") {
|
|
119
|
-
const current = await handle.stat().catch(() => {
|
|
215
|
+
const current = await handle.stat({ bigint: true }).catch(() => {
|
|
120
216
|
return;
|
|
121
217
|
});
|
|
122
|
-
if (current?.isFile()
|
|
123
|
-
|
|
218
|
+
if (current?.isFile()) {
|
|
219
|
+
const curObs = toObservation(current);
|
|
220
|
+
const beforeObs = toObservation(before);
|
|
221
|
+
if (curObs.dev === beforeObs.dev && curObs.ino === beforeObs.ino)
|
|
222
|
+
throw tooLarge(maxBytes, curObs);
|
|
223
|
+
}
|
|
124
224
|
}
|
|
125
225
|
throw error;
|
|
126
226
|
}
|
|
@@ -158,18 +258,7 @@ function readFdSync(fd, maxBytes) {
|
|
|
158
258
|
}
|
|
159
259
|
return bytes;
|
|
160
260
|
}
|
|
161
|
-
|
|
162
|
-
dev: Number(info.dev),
|
|
163
|
-
ino: Number(info.ino),
|
|
164
|
-
size: Number(info.size),
|
|
165
|
-
nlink: Number(info.nlink),
|
|
166
|
-
mtimeMs: Number(info.mtimeMs),
|
|
167
|
-
ctimeMs: Number(info.ctimeMs)
|
|
168
|
-
});
|
|
169
|
-
function sameBigStat(before, after, length) {
|
|
170
|
-
return before.dev === after.dev && before.ino === after.ino && before.size === after.size && before.mtimeNs === after.mtimeNs && before.ctimeNs === after.ctimeNs && before.nlink === after.nlink && before.mode === after.mode && before.uid === after.uid && before.gid === after.gid && BigInt(length) === after.size;
|
|
171
|
-
}
|
|
172
|
-
function readBoundedFileSync(target, maxBytes, options = {}, openFd = openSync) {
|
|
261
|
+
function readBoundedFileSync(target, maxBytes, options = {}, openFd = openSync, snapshot = {}) {
|
|
173
262
|
const flags = openReadFlags(options);
|
|
174
263
|
let fd;
|
|
175
264
|
try {
|
|
@@ -191,11 +280,23 @@ function readBoundedFileSync(target, maxBytes, options = {}, openFd = openSync)
|
|
|
191
280
|
try {
|
|
192
281
|
if (before.size > BigInt(maxBytes))
|
|
193
282
|
throw tooLarge(maxBytes);
|
|
194
|
-
options.inspect?.(
|
|
283
|
+
options.inspect?.(statsViewOf(before));
|
|
195
284
|
const bytes = readFdSync(fd, maxBytes);
|
|
196
285
|
const after = fstatSync(fd, { bigint: true });
|
|
197
286
|
if (options.stable && !sameBigStat(before, after, bytes.length))
|
|
198
287
|
throw new BoundedFileReadError("FILE_CHANGED", "managed file changed during read");
|
|
288
|
+
if (options.stable) {
|
|
289
|
+
let named;
|
|
290
|
+
try {
|
|
291
|
+
named = snapshot.namedStatSync ? snapshot.namedStatSync(target) : defaultNamedStatSync(target, options.rejectSymlinks);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (isPathSwapErrno(errnoOf(error), options.rejectSymlinks)) {
|
|
294
|
+
throw new BoundedFileReadError("FILE_CHANGED", "managed file path changed during read", undefined, { cause: error });
|
|
295
|
+
}
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
confirmNamedPath(after, named);
|
|
299
|
+
}
|
|
199
300
|
return { bytes, observation: bigObservation(after), mode: Number(after.mode), after };
|
|
200
301
|
} catch (error) {
|
|
201
302
|
if (error instanceof BoundedFileReadError && error.code === "FILE_TOO_LARGE") {
|
|
@@ -247,4 +348,4 @@ async function readHandle(handle, maxBytes, signal) {
|
|
|
247
348
|
return bytes;
|
|
248
349
|
}
|
|
249
350
|
|
|
250
|
-
export { closeAfter, closeAfterSync, BoundedFileReadError,
|
|
351
|
+
export { closeAfter, closeAfterSync, BoundedFileReadError, openRegularFile, readBoundedFile, readBoundedFileFrom, readBoundedFileSync };
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
syncDirectory,
|
|
5
5
|
publishAtomicFile,
|
|
6
6
|
publishAtomicFileSync
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-2c5w2d1d.js";
|
|
8
8
|
import {
|
|
9
9
|
closeAfter,
|
|
10
10
|
closeAfterSync,
|
|
11
11
|
readBoundedFile,
|
|
12
12
|
readBoundedFileSync
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-s2e3h616.js";
|
|
14
14
|
import {
|
|
15
15
|
stagingPath
|
|
16
16
|
} from "./index-39n02e0q.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ExclusiveLockError2,
|
|
3
3
|
withExclusiveLock2
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-2nwvn7m2.js";
|
|
5
5
|
import {
|
|
6
6
|
writeFileAtomicSync2
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-t7wa7k12.js";
|
|
8
8
|
import {
|
|
9
9
|
fetchGuarded,
|
|
10
10
|
PrivateAddressRefusal,
|