talentos 1.1.6 → 1.3.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/dist/agent/adapters.js +55 -5
- package/dist/agent/codex-policy.js +5 -0
- package/dist/agent/gateway.js +7 -1
- package/dist/agent/mcp-entry.js +5 -2
- package/dist/agent/native/approvals.js +240 -0
- package/dist/agent/native/codex-owner-probe.js +389 -0
- package/dist/agent/native/codex-owner.js +160 -0
- package/dist/agent/native/config.js +118 -0
- package/dist/agent/native/context.js +92 -0
- package/dist/agent/native/disqualify.js +46 -0
- package/dist/agent/native/env.js +29 -0
- package/dist/agent/native/gate.js +112 -0
- package/dist/agent/native/hook-entry.js +232 -0
- package/dist/agent/native/launch.js +100 -0
- package/dist/agent/native/paths.js +137 -0
- package/dist/agent/native/policy.js +916 -0
- package/dist/agent/native/probe.js +477 -0
- package/dist/agent/native/receipts.js +47 -0
- package/dist/agent/native/shell.js +174 -0
- package/dist/agent/native/touch.js +143 -0
- package/dist/agent/native/workspace.js +87 -0
- package/dist/agent/serve.js +121 -10
- package/dist/agent-service.js +14 -1
- package/dist/args.js +1 -0
- package/dist/commands/agent-native.js +64 -0
- package/dist/commands/agent.js +5 -1
- package/dist/gateway-install.js +15 -0
- package/dist/mcp-proxy.js +47 -6
- package/dist/upload-file.js +172 -0
- package/package.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { lstat, open, realpath } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { basename, isAbsolute, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { canonical, protectedPaths, protectedReason, } from "./agent/native/paths.js";
|
|
8
|
+
// The server caps and re-checks everything (type, size, names, content); this
|
|
9
|
+
// is the client's half of the boundary: only a regular file inside the folder
|
|
10
|
+
// the agent works in, and never a credential store, whatever the model asks.
|
|
11
|
+
export const UPLOAD_BYTES_MAX = 50 * 1024 * 1024;
|
|
12
|
+
const DENIED_SEGMENTS = new Set([
|
|
13
|
+
".aws",
|
|
14
|
+
".azure",
|
|
15
|
+
".docker",
|
|
16
|
+
".git",
|
|
17
|
+
".git-credentials",
|
|
18
|
+
".gnupg",
|
|
19
|
+
".kube",
|
|
20
|
+
".netrc",
|
|
21
|
+
".npmrc",
|
|
22
|
+
".pypirc",
|
|
23
|
+
".ssh",
|
|
24
|
+
".talentos",
|
|
25
|
+
".yarnrc",
|
|
26
|
+
".yarnrc.yml",
|
|
27
|
+
// Provider and hook configuration, inside a workspace as well as in $HOME.
|
|
28
|
+
".claude",
|
|
29
|
+
".codex",
|
|
30
|
+
".cursor",
|
|
31
|
+
".mcp.json",
|
|
32
|
+
]);
|
|
33
|
+
const DENIED_NAME = /^(?:\.env.*|id_(?:rsa|dsa|ecdsa|ed25519).*|credentials?(?:\..*)?|.*\.(?:pem|key|p12|pfx|jks|keystore)|.*_history|\.bash_profile|\.zshenv)$/iu;
|
|
34
|
+
export class UploadRefusal extends Error {
|
|
35
|
+
}
|
|
36
|
+
function refuse(message) {
|
|
37
|
+
throw new UploadRefusal(message);
|
|
38
|
+
}
|
|
39
|
+
function deniedSegment(segments) {
|
|
40
|
+
return segments.find((segment) => DENIED_SEGMENTS.has(segment.toLowerCase()) || DENIED_NAME.test(segment));
|
|
41
|
+
}
|
|
42
|
+
// Opens the file the model named, or refuses. Symlinks are resolved first and
|
|
43
|
+
// the real location must sit inside `root`; the file is then opened without
|
|
44
|
+
// following a final link and the opened descriptor, not the path, is what is
|
|
45
|
+
// measured and read, so a swap between check and read cannot widen access.
|
|
46
|
+
export async function openUploadSource(requested, root, home = homedir()) {
|
|
47
|
+
if (!root) {
|
|
48
|
+
refuse("upload_file needs the job's workspace folder, and this job has none. Create the file with create_file instead, or ask the owner to run you in a workspace.");
|
|
49
|
+
}
|
|
50
|
+
let rootReal;
|
|
51
|
+
try {
|
|
52
|
+
rootReal = await realpath(root);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return refuse("The job's workspace folder is not available.");
|
|
56
|
+
}
|
|
57
|
+
const guard = protectedPaths(home);
|
|
58
|
+
const guarded = (path) => {
|
|
59
|
+
const reason = protectedReason(path, "read", home, guard);
|
|
60
|
+
if (reason) {
|
|
61
|
+
refuse(`That file is in a protected location (${reason}), so it was not uploaded.`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const candidate = resolve(rootReal, requested);
|
|
65
|
+
const lexical = relative(rootReal, candidate).split(sep);
|
|
66
|
+
guarded(candidate);
|
|
67
|
+
guarded(canonical(candidate, rootReal, home));
|
|
68
|
+
const lexicalDenied = deniedSegment(lexical);
|
|
69
|
+
if (lexicalDenied) {
|
|
70
|
+
refuse(`${lexicalDenied} is a credential or configuration file, so it was not uploaded.`);
|
|
71
|
+
}
|
|
72
|
+
let real;
|
|
73
|
+
try {
|
|
74
|
+
real = await realpath(candidate);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return refuse("That file does not exist in your working folder.");
|
|
78
|
+
}
|
|
79
|
+
const inside = relative(rootReal, real);
|
|
80
|
+
if (inside === "" || inside.startsWith("..") || isAbsolute(inside)) {
|
|
81
|
+
refuse("Only files inside your working folder can be uploaded. Copy the file there first.");
|
|
82
|
+
}
|
|
83
|
+
guarded(real);
|
|
84
|
+
const realDenied = deniedSegment(inside.split(sep));
|
|
85
|
+
if (realDenied) {
|
|
86
|
+
refuse(`${realDenied} is a credential or configuration file, so it was not uploaded.`);
|
|
87
|
+
}
|
|
88
|
+
let handle;
|
|
89
|
+
try {
|
|
90
|
+
// biome-ignore lint/suspicious/noBitwiseOperators: open(2) flags combine by OR.
|
|
91
|
+
handle = await open(real, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return refuse("That file could not be opened.");
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const opened = await handle.stat();
|
|
98
|
+
if (!opened.isFile()) {
|
|
99
|
+
refuse("Only regular files can be uploaded, not folders or devices.");
|
|
100
|
+
}
|
|
101
|
+
const atPath = await lstat(real);
|
|
102
|
+
if (atPath.dev !== opened.dev || atPath.ino !== opened.ino) {
|
|
103
|
+
refuse("The file changed while it was being opened. Try again.");
|
|
104
|
+
}
|
|
105
|
+
if (opened.size < 1) {
|
|
106
|
+
refuse("That file is empty.");
|
|
107
|
+
}
|
|
108
|
+
if (opened.size > UPLOAD_BYTES_MAX) {
|
|
109
|
+
refuse(`Files up to ${UPLOAD_BYTES_MAX / 1024 / 1024} MiB can be uploaded. Make it smaller or split it.`);
|
|
110
|
+
}
|
|
111
|
+
const hash = createHash("sha256");
|
|
112
|
+
for await (const chunk of handle.createReadStream({
|
|
113
|
+
autoClose: false,
|
|
114
|
+
start: 0,
|
|
115
|
+
})) {
|
|
116
|
+
hash.update(chunk);
|
|
117
|
+
}
|
|
118
|
+
const stream = () => handle.createReadStream({ autoClose: false, start: 0 });
|
|
119
|
+
return {
|
|
120
|
+
handle,
|
|
121
|
+
name: basename(candidate),
|
|
122
|
+
sha256: hash.digest("hex"),
|
|
123
|
+
size: opened.size,
|
|
124
|
+
stream,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
await handle.close();
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// prepare -> stream the bytes straight to storage -> commit. Nothing about the
|
|
133
|
+
// file's contents passes through the model or an MCP argument.
|
|
134
|
+
export async function uploadFile(client, args, root, fetchImpl = fetch, home = homedir()) {
|
|
135
|
+
const source = await openUploadSource(args.path, root, home);
|
|
136
|
+
try {
|
|
137
|
+
const prepared = await client.call("prepare_upload", {
|
|
138
|
+
filename: source.name,
|
|
139
|
+
roomId: args.roomId,
|
|
140
|
+
sha256: source.sha256,
|
|
141
|
+
sizeBytes: source.size,
|
|
142
|
+
...(args.title ? { title: args.title } : {}),
|
|
143
|
+
});
|
|
144
|
+
if (prepared.data.status === "committed" || !prepared.data.uploadUrl) {
|
|
145
|
+
return prepared.text;
|
|
146
|
+
}
|
|
147
|
+
const response = await fetchImpl(prepared.data.uploadUrl, {
|
|
148
|
+
body: Readable.toWeb(source.stream()),
|
|
149
|
+
duplex: "half",
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Length": String(source.size),
|
|
152
|
+
"Content-Type": "application/octet-stream",
|
|
153
|
+
},
|
|
154
|
+
method: "POST",
|
|
155
|
+
});
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
refuse(`The upload failed (${response.status}). Try again.`);
|
|
158
|
+
}
|
|
159
|
+
const { storageId } = (await response.json());
|
|
160
|
+
if (!storageId) {
|
|
161
|
+
refuse("The upload failed. Try again.");
|
|
162
|
+
}
|
|
163
|
+
const committed = await client.call("commit_upload", {
|
|
164
|
+
sessionId: prepared.data.sessionId,
|
|
165
|
+
storageId,
|
|
166
|
+
});
|
|
167
|
+
return committed.text;
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await source.handle.close();
|
|
171
|
+
}
|
|
172
|
+
}
|
package/package.json
CHANGED