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,143 @@
|
|
|
1
|
+
import { canonical, isInside } from "./paths.js";
|
|
2
|
+
import { parseShell } from "./shell.js";
|
|
3
|
+
// "Private-touched" (#10987 PR 2b, R12 R1): did this call reach into the owner's
|
|
4
|
+
// own setup, so that what it returns may be private? The server holds back what
|
|
5
|
+
// such a job writes into a room with other people until the owner reviews it.
|
|
6
|
+
//
|
|
7
|
+
// Allowlist-shaped like the policy: a call is NOT private only when it is
|
|
8
|
+
// recognised as staying inside the job's workspace or using the room's own
|
|
9
|
+
// tools. Anything else (any other MCP tool, a web fetch, a read outside the
|
|
10
|
+
// workspace, a command the policy had to ask about, a tool we do not know)
|
|
11
|
+
// counts as touched. A false "touched" costs the owner one tap; a false
|
|
12
|
+
// "untouched" would post private data, so every doubt resolves to touched.
|
|
13
|
+
const ROOM_SERVER_PREFIX = "mcp__talentos_room__";
|
|
14
|
+
// Tools that read files by path; the path decides.
|
|
15
|
+
const PATH_TOOLS = new Set(["Glob", "Grep", "LS", "NotebookRead", "Read"]);
|
|
16
|
+
const EDIT_TOOLS = new Set(["Edit", "MultiEdit", "NotebookEdit", "Write"]);
|
|
17
|
+
// Tools that touch nothing of the owner's: bookkeeping and public web search.
|
|
18
|
+
// Skill and Agent are NOT here: a skill or subagent is owner-level context the
|
|
19
|
+
// hook cannot see into, so calling one counts as touched (R13 P2-d).
|
|
20
|
+
const NEUTRAL_TOOLS = new Set([
|
|
21
|
+
"AskUserQuestion",
|
|
22
|
+
"BashOutput",
|
|
23
|
+
"ExitPlanMode",
|
|
24
|
+
"KillShell",
|
|
25
|
+
"TaskCreate",
|
|
26
|
+
"TaskGet",
|
|
27
|
+
"TaskList",
|
|
28
|
+
"TaskStop",
|
|
29
|
+
"TaskUpdate",
|
|
30
|
+
"TodoWrite",
|
|
31
|
+
"ToolSearch",
|
|
32
|
+
"WebSearch",
|
|
33
|
+
]);
|
|
34
|
+
const GLOB_CHARS = /[*?[{]/u;
|
|
35
|
+
const PATH_START = /[/~]/u;
|
|
36
|
+
function text(value) {
|
|
37
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
38
|
+
}
|
|
39
|
+
export function touchesPrivate(call, context, allowedByPolicy) {
|
|
40
|
+
// The policy had to ask the owner: it is outward, irreversible or unknown, and
|
|
41
|
+
// once approved it may read anything.
|
|
42
|
+
if (!allowedByPolicy) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const { tool, toolInput: input } = call;
|
|
46
|
+
const inside = (path, base = call.cwd) => {
|
|
47
|
+
if (path.startsWith("~") && path !== "~" && !path.startsWith("~/")) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const real = canonical(path, base, context.home);
|
|
51
|
+
return context.writeRoots.some((root) => isInside(real, root));
|
|
52
|
+
};
|
|
53
|
+
if (tool.startsWith("mcp__")) {
|
|
54
|
+
return !tool.startsWith(ROOM_SERVER_PREFIX);
|
|
55
|
+
}
|
|
56
|
+
if (NEUTRAL_TOOLS.has(tool)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (PATH_TOOLS.has(tool) || EDIT_TOOLS.has(tool)) {
|
|
60
|
+
const paths = [
|
|
61
|
+
text(input.file_path),
|
|
62
|
+
text(input.notebook_path),
|
|
63
|
+
text(input.path),
|
|
64
|
+
// A glob pattern is judged by its literal directory prefix.
|
|
65
|
+
tool === "Glob"
|
|
66
|
+
? (text(input.pattern)?.split(GLOB_CHARS)[0] ?? undefined)
|
|
67
|
+
: undefined,
|
|
68
|
+
].filter((path) => path !== undefined);
|
|
69
|
+
if (paths.length === 0) {
|
|
70
|
+
return !inside(".");
|
|
71
|
+
}
|
|
72
|
+
return paths.some((path) => !inside(path));
|
|
73
|
+
}
|
|
74
|
+
if (tool === "Bash") {
|
|
75
|
+
return shellTouchesPrivate(text(input.command), inside, call.cwd, context.home);
|
|
76
|
+
}
|
|
77
|
+
// WebFetch and every tool this list does not know.
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const isRun = (part) => part.startsWith("run:");
|
|
81
|
+
/**
|
|
82
|
+
* Did this call pull untrusted input into the job (Auto mode, R13)? Anything
|
|
83
|
+
* the owner's private setup touch covers, plus web search and any serious
|
|
84
|
+
* (tier 1) action the owner approved. After the first, tests and builds ask
|
|
85
|
+
* again for the rest of the job and the thread.
|
|
86
|
+
*/
|
|
87
|
+
export function taintsJob(call, context, asked) {
|
|
88
|
+
return (call.tool === "WebSearch" ||
|
|
89
|
+
// A test or build the owner (or Auto mode) allowed brings in nothing; any
|
|
90
|
+
// other serious action does.
|
|
91
|
+
(asked?.tier === 1 && !asked.kind.split(" + ").every(isRun)) ||
|
|
92
|
+
touchesPrivate(call, context, true));
|
|
93
|
+
}
|
|
94
|
+
function shellTouchesPrivate(source, inside, cwd, home) {
|
|
95
|
+
const parsed = source ? parseShell(source) : undefined;
|
|
96
|
+
if (!(parsed?.ok && inside("."))) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// `cd dir && ...`: later paths resolve from where the command moved to.
|
|
100
|
+
let base = cwd;
|
|
101
|
+
for (const command of parsed.commands) {
|
|
102
|
+
const words = command.argv.slice(1);
|
|
103
|
+
if (command.argv[0]?.text === "cd") {
|
|
104
|
+
const target = words[0];
|
|
105
|
+
if (!target ||
|
|
106
|
+
words.length > 1 ||
|
|
107
|
+
target.glob ||
|
|
108
|
+
!inside(target.text, base)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
base = canonical(target.text, base, home);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
for (const word of words) {
|
|
115
|
+
if (word.text.startsWith("-")) {
|
|
116
|
+
// `--git-dir=/x` and `-C/x` carry a path inside the flag.
|
|
117
|
+
const start = word.text.search(PATH_START);
|
|
118
|
+
if (start > 0 && !inside(word.text.slice(start), base)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (word.glob) {
|
|
124
|
+
// A relative glob stays in the working directory; anything else cannot
|
|
125
|
+
// be judged from its literal prefix.
|
|
126
|
+
if (PATH_START.test(word.text.charAt(0)) || word.text.includes("..")) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!inside(word.text, base)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const redirect of command.redirects) {
|
|
136
|
+
if (redirect.target.text !== "/dev/null" &&
|
|
137
|
+
!inside(redirect.target.text, base)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mkdirSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { rootProblem } from "./config.js";
|
|
7
|
+
import { canonical, isInside } from "./paths.js";
|
|
8
|
+
const exec = promisify(execFile);
|
|
9
|
+
const safeId = (value, length) => value
|
|
10
|
+
.replace(/[^a-z\d]/giu, "")
|
|
11
|
+
.slice(0, length)
|
|
12
|
+
.toLowerCase() || "thread";
|
|
13
|
+
/**
|
|
14
|
+
* The folder one thread's owner jobs run in. In a repo it is a git worktree the
|
|
15
|
+
* CLI creates (never the model), so the owner's checkout stays untouched; with
|
|
16
|
+
* no repo, or one with no commits yet, a plain per-thread folder under the
|
|
17
|
+
* managed root. Throws when the configured root fails its checks.
|
|
18
|
+
*/
|
|
19
|
+
export async function prepareWorkspace(input) {
|
|
20
|
+
const { config, home } = input;
|
|
21
|
+
const problem = rootProblem(config, home);
|
|
22
|
+
if (problem) {
|
|
23
|
+
throw new Error(problem);
|
|
24
|
+
}
|
|
25
|
+
const thread = safeId(input.threadId, 12);
|
|
26
|
+
const managed = join(home, "TalentOS", "threads");
|
|
27
|
+
let cwd;
|
|
28
|
+
const useWorktree = config.kind === "repo" && (await hasCommit(config.root));
|
|
29
|
+
if (useWorktree) {
|
|
30
|
+
const repo = `${safeId(config.root.split("/").pop() ?? "repo", 20)}-${createHash("sha256").update(config.root).digest("hex").slice(0, 8)}`;
|
|
31
|
+
cwd = join(home, "TalentOS", ".worktrees", repo, thread);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
cwd = join(config.kind === "managed" ? config.root : managed, thread);
|
|
35
|
+
}
|
|
36
|
+
// The folder must resolve inside the TalentOS area or the managed root, and
|
|
37
|
+
// that is checked BEFORE anything is created, so a planted symlink cannot
|
|
38
|
+
// make the CLI build a worktree somewhere else.
|
|
39
|
+
const bases = [join(home, "TalentOS"), config.root].map((base) => canonical(base, home, home));
|
|
40
|
+
const inside = (path) => bases.some((base) => isInside(canonical(path, home, home), base));
|
|
41
|
+
if (!inside(cwd)) {
|
|
42
|
+
throw new Error("The workspace left its folder.");
|
|
43
|
+
}
|
|
44
|
+
if (useWorktree) {
|
|
45
|
+
await ensureWorktree(config.root, cwd, thread);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
mkdirSync(cwd, { recursive: true, mode: 0o700 });
|
|
49
|
+
}
|
|
50
|
+
const real = realpathSync.native(cwd);
|
|
51
|
+
if (!(statSync(real).isDirectory() && inside(real))) {
|
|
52
|
+
throw new Error("The workspace left its folder.");
|
|
53
|
+
}
|
|
54
|
+
return { cwd: real, writeRoots: [real] };
|
|
55
|
+
}
|
|
56
|
+
async function hasCommit(root) {
|
|
57
|
+
try {
|
|
58
|
+
await exec("git", ["rev-parse", "--verify", "HEAD"], {
|
|
59
|
+
cwd: root,
|
|
60
|
+
timeout: 5000,
|
|
61
|
+
});
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function ensureWorktree(root, path, thread) {
|
|
69
|
+
try {
|
|
70
|
+
if (statSync(path).isDirectory()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Missing: create it below.
|
|
76
|
+
}
|
|
77
|
+
mkdirSync(join(path, ".."), { recursive: true, mode: 0o700 });
|
|
78
|
+
const branch = `talentos/${thread}`;
|
|
79
|
+
const options = { cwd: root, timeout: 60_000 };
|
|
80
|
+
try {
|
|
81
|
+
await exec("git", ["worktree", "add", "-b", branch, path, "HEAD"], options);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// The branch survives a deleted folder: reattach it.
|
|
85
|
+
await exec("git", ["worktree", "add", path, branch], options);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/agent/serve.js
CHANGED
|
@@ -2,13 +2,19 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { mkdir, open, readFile, rm } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import { installSharedGateway } from "../gateway-install.js";
|
|
5
|
+
import { installSharedGateway, newerInstalledVersion, } from "../gateway-install.js";
|
|
6
6
|
import { compareGatewayVersions } from "../gateway-version.js";
|
|
7
|
+
import { homeDir } from "../install.js";
|
|
7
8
|
import { runProvider } from "./adapters.js";
|
|
8
9
|
import { AgentGateway, GatewayError } from "./gateway.js";
|
|
10
|
+
import { ApprovalBridge } from "./native/approvals.js";
|
|
11
|
+
import { NativeGate } from "./native/gate.js";
|
|
9
12
|
import { SessionMap } from "./sessions.js";
|
|
10
13
|
const HEARTBEAT_MS = 20_000;
|
|
11
14
|
const LEASE_SAFETY_MS = 55_000;
|
|
15
|
+
// A native job holds a 30 s server lease and is re-derived on every renewal.
|
|
16
|
+
const NATIVE_RENEW_MS = 10_000;
|
|
17
|
+
const NATIVE_SAFETY_MS = 25_000;
|
|
12
18
|
const IDLE_MS = 30 * 60_000;
|
|
13
19
|
export function needsUpdate(current, minimum) {
|
|
14
20
|
if (compareGatewayVersions(minimum, minimum) === undefined) {
|
|
@@ -55,12 +61,14 @@ export async function installGatewayUpdate(directory, minimum, signal) {
|
|
|
55
61
|
signal,
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
|
-
export async function serveAgent(config, directory, version, stop, verify) {
|
|
64
|
+
export async function serveAgent(config, directory, version, stop, verify, options = {}) {
|
|
59
65
|
const release = await acquireLock(directory);
|
|
60
66
|
try {
|
|
61
67
|
const workDir = join(directory, "work"), sessions = new SessionMap(directory), gateway = new AgentGateway(config);
|
|
62
68
|
await mkdir(workDir, { recursive: true, mode: 0o700 });
|
|
63
69
|
const deviceId = randomUUID();
|
|
70
|
+
const gate = options.gate ??
|
|
71
|
+
new NativeGate({ agent: config, directory, home: homeDir() });
|
|
64
72
|
const service = new AbortController();
|
|
65
73
|
const signal = AbortSignal.any([stop, service.signal]);
|
|
66
74
|
let wakeResolve, wakePending = true;
|
|
@@ -81,7 +89,8 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
81
89
|
}
|
|
82
90
|
};
|
|
83
91
|
const heartbeat = async () => {
|
|
84
|
-
|
|
92
|
+
gate.refresh();
|
|
93
|
+
const response = await gateway.request("/agent-gateway/heartbeat", { cliVersion: version, nativeOptIn: gate.reportable() }, signal);
|
|
85
94
|
if (response) {
|
|
86
95
|
minimum = response.cliMinVersion;
|
|
87
96
|
if (response.pendingJobs > 0 || needsUpdate(version, minimum)) {
|
|
@@ -100,7 +109,9 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
100
109
|
.request(`/agent-gateway/jobs/${leased.job.jobId}/renew`, { leaseToken: leased.job.leaseToken }, signal)
|
|
101
110
|
.then(() => {
|
|
102
111
|
if (active === leased) {
|
|
103
|
-
leased.deadline =
|
|
112
|
+
leased.deadline =
|
|
113
|
+
started +
|
|
114
|
+
(leased.job.native ? NATIVE_SAFETY_MS : LEASE_SAFETY_MS);
|
|
104
115
|
}
|
|
105
116
|
})
|
|
106
117
|
.catch((error) => {
|
|
@@ -114,7 +125,12 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
114
125
|
})
|
|
115
126
|
: Promise.resolve(),
|
|
116
127
|
]);
|
|
117
|
-
|
|
128
|
+
// The owner's local `native off` ends a running owner job at once.
|
|
129
|
+
if (active?.job.native && active.owner && !gate.optedIn()) {
|
|
130
|
+
active.cancel.abort();
|
|
131
|
+
}
|
|
132
|
+
await delay(Math.max(1, (active?.job.native ? NATIVE_RENEW_MS : HEARTBEAT_MS) -
|
|
133
|
+
(Date.now() - started)), undefined, { signal }).catch(() => {
|
|
118
134
|
/* Shutdown interrupts the timer. */
|
|
119
135
|
});
|
|
120
136
|
}
|
|
@@ -134,6 +150,12 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
134
150
|
dispose = await gateway.subscribe(wake, () => {
|
|
135
151
|
push = false;
|
|
136
152
|
wake();
|
|
153
|
+
},
|
|
154
|
+
// The owner's Stop lands in a second or two; the renewal is the backstop.
|
|
155
|
+
(jobIds) => {
|
|
156
|
+
if (active && jobIds.includes(active.job.jobId)) {
|
|
157
|
+
active.cancel.abort();
|
|
158
|
+
}
|
|
137
159
|
});
|
|
138
160
|
}
|
|
139
161
|
catch (error) {
|
|
@@ -141,7 +163,25 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
141
163
|
failService(error);
|
|
142
164
|
}
|
|
143
165
|
heartbeats = heartbeatLoop();
|
|
166
|
+
let reexecAfter = 0;
|
|
144
167
|
while (!signal.aborted) {
|
|
168
|
+
// A repair or update installed a newer gateway while this process kept
|
|
169
|
+
// running the old one: exit between turns so the service relaunches on it.
|
|
170
|
+
if (Date.now() >= reexecAfter && process.platform !== "win32") {
|
|
171
|
+
reexecAfter = Date.now() + 60_000;
|
|
172
|
+
const newer = await newerInstalledVersion(dirname(dirname(dirname(directory))), version).catch(() => undefined);
|
|
173
|
+
if (newer) {
|
|
174
|
+
// launchd and systemd relaunch an exited service; a hand-run serve
|
|
175
|
+
// just ends.
|
|
176
|
+
const supervised = Boolean(process.env.INVOCATION_ID ||
|
|
177
|
+
(process.env.XPC_SERVICE_NAME &&
|
|
178
|
+
process.env.XPC_SERVICE_NAME !== "0"));
|
|
179
|
+
console.error(supervised
|
|
180
|
+
? `Gateway ${newer} is installed; restarting from ${version}.`
|
|
181
|
+
: `Gateway ${newer} is installed. Stopping ${version}; run talentos agent serve again to use it.`);
|
|
182
|
+
return newer;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
145
185
|
if (needsUpdate(version, minimum) && Date.now() >= updateAfter) {
|
|
146
186
|
if (process.platform === "win32") {
|
|
147
187
|
throw new Error(`Gateway update required; re-run npx talentos@${minimum} agent serve --agent ${config.agentId}. Windows gateways update in the foreground.`);
|
|
@@ -161,7 +201,7 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
161
201
|
let job;
|
|
162
202
|
const claimStartedAt = Date.now();
|
|
163
203
|
try {
|
|
164
|
-
job = await gateway.request("/agent-gateway/claim", { deviceId }, signal);
|
|
204
|
+
job = await gateway.request("/agent-gateway/claim", { cliVersion: version, deviceId }, signal);
|
|
165
205
|
}
|
|
166
206
|
catch (error) {
|
|
167
207
|
failService(error);
|
|
@@ -170,17 +210,88 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
170
210
|
if (job) {
|
|
171
211
|
lastJobAt = Date.now();
|
|
172
212
|
const cancel = new AbortController();
|
|
173
|
-
|
|
213
|
+
const current = {
|
|
214
|
+
job,
|
|
215
|
+
cancel,
|
|
216
|
+
deadline: claimStartedAt +
|
|
217
|
+
(job.native ? NATIVE_SAFETY_MS : LEASE_SAFETY_MS),
|
|
218
|
+
owner: false,
|
|
219
|
+
};
|
|
220
|
+
active = current;
|
|
174
221
|
let lastStatusAt = 0;
|
|
222
|
+
// Monotonic, so a wall-clock change cannot corrupt the marks.
|
|
223
|
+
const receivedAt = performance.now();
|
|
224
|
+
const timings = {};
|
|
175
225
|
try {
|
|
226
|
+
// An owner job runs the owner's real setup only when the plane
|
|
227
|
+
// confirmed owner authority just now AND this computer is ready;
|
|
228
|
+
// anything less is the room-only profile, as before.
|
|
229
|
+
let owner;
|
|
230
|
+
if (job.native) {
|
|
231
|
+
const post = (statusLine) => gateway
|
|
232
|
+
.request(`/agent-gateway/jobs/${job.jobId}/status`, { leaseToken: job.leaseToken, statusLine }, signal)
|
|
233
|
+
.catch(failService);
|
|
234
|
+
post("Starting on your computer…");
|
|
235
|
+
lastStatusAt = Date.now();
|
|
236
|
+
const [, prepared] = await Promise.all([
|
|
237
|
+
gateway.request(`/agent-gateway/jobs/${job.jobId}/native-confirm`, { leaseToken: job.leaseToken }, signal),
|
|
238
|
+
gate.prepare(job.packet.thread.id).catch(() => undefined),
|
|
239
|
+
]);
|
|
240
|
+
owner = prepared;
|
|
241
|
+
current.owner = Boolean(owner);
|
|
242
|
+
// In a room with other people the server holds what the job
|
|
243
|
+
// posts unless this computer affirms it started clean: none of
|
|
244
|
+
// the owner's own context loaded, every touch reported. Unknown
|
|
245
|
+
// is reviewed, so a missing or failed word costs one tap.
|
|
246
|
+
if (owner && job.native.sharedRoom && owner.context === false) {
|
|
247
|
+
await gateway
|
|
248
|
+
.request(`/agent-gateway/jobs/${job.jobId}/touch-tracked`, { leaseToken: job.leaseToken }, signal)
|
|
249
|
+
.catch(() => undefined);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const sessionKey = owner
|
|
253
|
+
? `${job.packet.thread.id}:owner`
|
|
254
|
+
: job.packet.thread.id;
|
|
255
|
+
const bridge = () => new ApprovalBridge({
|
|
256
|
+
gateway: {
|
|
257
|
+
touch: async (flags) => {
|
|
258
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/private-touch`, { leaseToken: job.leaseToken, ...flags }, signal);
|
|
259
|
+
},
|
|
260
|
+
request: async (ask) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-request`, { leaseToken: job.leaseToken, ...ask }, signal)) ?? { status: "expired" },
|
|
261
|
+
status: async (actionKeys) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-status`, { actionKeys, leaseToken: job.leaseToken }, signal)) ?? [],
|
|
262
|
+
},
|
|
263
|
+
onWaiting: (waiting) => {
|
|
264
|
+
gateway
|
|
265
|
+
.request(`/agent-gateway/jobs/${job.jobId}/status`, {
|
|
266
|
+
leaseToken: job.leaseToken,
|
|
267
|
+
statusLine: waiting
|
|
268
|
+
? "Waiting for your approval…"
|
|
269
|
+
: "Working on your computer…",
|
|
270
|
+
}, signal)
|
|
271
|
+
.catch(failService);
|
|
272
|
+
},
|
|
273
|
+
}).start();
|
|
176
274
|
const result = await runProvider({
|
|
177
275
|
config,
|
|
178
276
|
job,
|
|
179
277
|
workDir,
|
|
180
|
-
|
|
278
|
+
owner: owner && { ...owner, watch: bridge },
|
|
279
|
+
sessionId: await sessions.get(sessionKey),
|
|
181
280
|
signal: AbortSignal.any([signal, cancel.signal]),
|
|
182
281
|
remember: async (sessionId) => {
|
|
183
|
-
await sessions.remember(
|
|
282
|
+
await sessions.remember(sessionKey, sessionId);
|
|
283
|
+
},
|
|
284
|
+
receipts: async (rows) => {
|
|
285
|
+
// The gateway body limit is 32 kB: 50 rows of at most ~250 B.
|
|
286
|
+
for (let at = 0; at < rows.length; at += 50) {
|
|
287
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/receipts`, {
|
|
288
|
+
leaseToken: job.leaseToken,
|
|
289
|
+
rows: rows.slice(at, at + 50),
|
|
290
|
+
}, signal);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
mark: (name) => {
|
|
294
|
+
timings[`${name}Ms`] = Math.round(performance.now() - receivedAt);
|
|
184
295
|
},
|
|
185
296
|
status: (line) => {
|
|
186
297
|
if (Date.now() - lastStatusAt < 1000) {
|
|
@@ -196,7 +307,7 @@ export async function serveAgent(config, directory, version, stop, verify) {
|
|
|
196
307
|
// never become a new provider run or a duplicate final reply.
|
|
197
308
|
while (!(signal.aborted || cancel.signal.aborted)) {
|
|
198
309
|
try {
|
|
199
|
-
await gateway.request(`/agent-gateway/jobs/${job.jobId}/complete`, { leaseToken: job.leaseToken, text: result.text }, signal);
|
|
310
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/complete`, { leaseToken: job.leaseToken, text: result.text, timings }, signal);
|
|
200
311
|
break;
|
|
201
312
|
}
|
|
202
313
|
catch (error) {
|
package/dist/agent-service.js
CHANGED
|
@@ -48,7 +48,13 @@ export async function installAgentService(agent, options = {}) {
|
|
|
48
48
|
const domain = `gui/${options.uid ?? process.getuid?.() ?? 0}`;
|
|
49
49
|
const loaded = run("launchctl", ["print", `${domain}/${name}`]) === 0;
|
|
50
50
|
if (loaded && !changed) {
|
|
51
|
-
|
|
51
|
+
// The plist is unchanged but the CLI it launches may not be: a running
|
|
52
|
+
// service keeps its old code until it restarts. Kickstart bypasses launchd's
|
|
53
|
+
// throttle and relaunches through the launcher onto cli/current.
|
|
54
|
+
return {
|
|
55
|
+
path,
|
|
56
|
+
started: run("launchctl", ["kickstart", "-k", `${domain}/${name}`]) === 0,
|
|
57
|
+
};
|
|
52
58
|
}
|
|
53
59
|
if (loaded) {
|
|
54
60
|
run("launchctl", ["bootout", domain, path]);
|
|
@@ -61,6 +67,13 @@ export async function installAgentService(agent, options = {}) {
|
|
|
61
67
|
if (changed && run("systemctl", ["--user", "daemon-reload"]) !== 0) {
|
|
62
68
|
return { path, started: false };
|
|
63
69
|
}
|
|
70
|
+
// Restart a running service onto the freshly installed CLI; a stopped one is
|
|
71
|
+
// left for `enable --now` to start.
|
|
72
|
+
run("systemctl", [
|
|
73
|
+
"--user",
|
|
74
|
+
"try-restart",
|
|
75
|
+
`talentos-agent@${agent.agentId}.service`,
|
|
76
|
+
]);
|
|
64
77
|
return {
|
|
65
78
|
path,
|
|
66
79
|
started: run("systemctl", [
|
package/dist/args.js
CHANGED
|
@@ -22,6 +22,7 @@ const CLI_OPTIONS = {
|
|
|
22
22
|
url: { type: "string" },
|
|
23
23
|
yes: { type: "boolean" },
|
|
24
24
|
agent: { type: "string" },
|
|
25
|
+
"upload-root": { type: "string" },
|
|
25
26
|
};
|
|
26
27
|
/** Groups whose first positional is a sub-command rather than an argument. */
|
|
27
28
|
const ACTION_GROUPS = new Set(["agent", "mcp", "skills", "memory", "routines"]);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { disableNative, enableNative, readNativeConfig, } from "../agent/native/config.js";
|
|
3
|
+
import { NativeGate } from "../agent/native/gate.js";
|
|
4
|
+
import { agentWorkDir, localAgents, } from "../agent-config.js";
|
|
5
|
+
import { emit } from "../format.js";
|
|
6
|
+
import { homeDir } from "../install.js";
|
|
7
|
+
// `talentos agent native enable | off | status` (#10987): the owner's local yes
|
|
8
|
+
// to "let this agent work on this computer when you ask it in a room". The
|
|
9
|
+
// server still needs the owner's own confirmation in TalentOS; this only
|
|
10
|
+
// records consent on this machine and proves the provider can be guarded.
|
|
11
|
+
async function pickAgent(parsed, home) {
|
|
12
|
+
const agents = await localAgents(home);
|
|
13
|
+
const selector = parsed.options.agent;
|
|
14
|
+
let chosen;
|
|
15
|
+
if (selector) {
|
|
16
|
+
chosen = agents.find((agent) => agent.agentId === selector || agent.name === selector);
|
|
17
|
+
}
|
|
18
|
+
else if (agents.length === 1) {
|
|
19
|
+
chosen = agents[0];
|
|
20
|
+
}
|
|
21
|
+
if (!chosen) {
|
|
22
|
+
throw new Error("Choose a linked agent with `talentos agent native enable --agent <id>`.");
|
|
23
|
+
}
|
|
24
|
+
return chosen;
|
|
25
|
+
}
|
|
26
|
+
const shown = (path, home) => path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
27
|
+
export async function runAgentNative(parsed, home = homeDir()) {
|
|
28
|
+
const action = parsed.args[0];
|
|
29
|
+
if (action !== "enable" && action !== "off" && action !== "status") {
|
|
30
|
+
throw new Error("Use talentos agent native enable | off | status.");
|
|
31
|
+
}
|
|
32
|
+
const agent = await pickAgent(parsed, home);
|
|
33
|
+
const directory = dirname(agentWorkDir(agent.agentId, home));
|
|
34
|
+
if (action === "off") {
|
|
35
|
+
await disableNative(directory);
|
|
36
|
+
emit(`Turned off. ${agent.name} answers with room tools only, and any run in progress stops within seconds.`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (action === "status") {
|
|
40
|
+
const config = await readNativeConfig(directory);
|
|
41
|
+
emit(config
|
|
42
|
+
? `On. ${agent.name} works in ${shown(config.root, home)} when you ask it in a room.`
|
|
43
|
+
: `Off. Run talentos agent native enable to let ${agent.name} use your full setup in rooms.`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (agent.provider !== "claude_code") {
|
|
47
|
+
throw new Error("Full-setup rooms support Claude Code first. Codex is not available yet.");
|
|
48
|
+
}
|
|
49
|
+
const config = await enableNative({
|
|
50
|
+
agentId: agent.agentId,
|
|
51
|
+
cwd: process.cwd(),
|
|
52
|
+
directory,
|
|
53
|
+
home,
|
|
54
|
+
name: agent.name,
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
await new NativeGate({ agent, directory, home }).runProbe();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
await disableNative(directory);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
emit(`I'll work in ${shown(config.root, home)}${config.kind === "repo" ? " (each room thread gets its own copy of the branch)" : ""}. TalentOS will ask you to confirm once.`);
|
|
64
|
+
}
|
package/dist/commands/agent.js
CHANGED
|
@@ -92,6 +92,10 @@ export async function runAgent(parsed, dependencies = {}) {
|
|
|
92
92
|
await import("../agent/mcp-entry.js");
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
+
case "native": {
|
|
96
|
+
const { runAgentNative } = await import("./agent-native.js");
|
|
97
|
+
return await runAgentNative(parsed, dependencies.home);
|
|
98
|
+
}
|
|
95
99
|
case "status":
|
|
96
100
|
case "list":
|
|
97
101
|
return await showAgents(parsed);
|
|
@@ -100,7 +104,7 @@ export async function runAgent(parsed, dependencies = {}) {
|
|
|
100
104
|
case "logs":
|
|
101
105
|
return await showLogs(parsed);
|
|
102
106
|
default:
|
|
103
|
-
throw new Error("Use talentos agent link | repair | status | list | unlink | logs.");
|
|
107
|
+
throw new Error("Use talentos agent link | repair | status | list | unlink | logs | native.");
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
export async function installLinkedAgent(parsed, dependencies = {}) {
|
package/dist/gateway-install.js
CHANGED
|
@@ -217,6 +217,21 @@ async function installLock(root, signal) {
|
|
|
217
217
|
await rm(pending, { force: true });
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* The installed gateway the launcher would run now, when it is a newer, complete
|
|
222
|
+
* version than the one running. `talentos agent repair` swaps `cli/current` but
|
|
223
|
+
* a service that is already running keeps its old code until it restarts, so a
|
|
224
|
+
* serving process asks this between turns and exits to be relaunched on it.
|
|
225
|
+
*/
|
|
226
|
+
export async function newerInstalledVersion(home, running) {
|
|
227
|
+
const root = join(home, ".talentos/cli");
|
|
228
|
+
const active = await readlink(join(root, "current")).catch(() => "");
|
|
229
|
+
if ((compareGatewayVersions(active, running) ?? 0) > 0 &&
|
|
230
|
+
(await installed(join(root, active, "node_modules/talentos"), active))) {
|
|
231
|
+
return active;
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
220
235
|
export async function installSharedGateway(options = {}) {
|
|
221
236
|
const home = options.home ?? homeDir();
|
|
222
237
|
const source = options.source ?? fileURLToPath(new URL("../", import.meta.url));
|
package/dist/mcp-proxy.js
CHANGED
|
@@ -1,17 +1,58 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { UploadRefusal, uploadFile } from "./upload-file.js";
|
|
5
|
+
// The two server steps behind upload_file. The model sees only upload_file.
|
|
6
|
+
const UPLOAD_STEP_TOOLS = new Set(["prepare_upload", "commit_upload"]);
|
|
4
7
|
/**
|
|
5
8
|
* stdio front end for clients that cannot speak streamable HTTP (Codex, older
|
|
6
9
|
* desktop builds). It forwards tool listing and calls verbatim so the tool set
|
|
7
10
|
* an agent sees over stdio is the one the remote server owns.
|
|
8
11
|
*/
|
|
9
|
-
export async function startMcpProxy(client
|
|
12
|
+
export async function startMcpProxy(client,
|
|
13
|
+
// The only folder upload_file reads from: the job's workspace, named by the
|
|
14
|
+
// launcher. Never a tool argument, never this process's own folder; without
|
|
15
|
+
// it upload_file refuses.
|
|
16
|
+
root) {
|
|
10
17
|
const server = new Server({ name: "talentos", version: "1.0.0" }, { capabilities: { tools: {} } });
|
|
11
|
-
server.setRequestHandler(ListToolsRequestSchema, async () =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
19
|
+
const listed = await client.listTools();
|
|
20
|
+
return {
|
|
21
|
+
...listed,
|
|
22
|
+
tools: listed.tools.filter((tool) => !UPLOAD_STEP_TOOLS.has(tool.name)),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
26
|
+
const { name, arguments: args = {} } = request.params;
|
|
27
|
+
if (name === "upload_file") {
|
|
28
|
+
return await runUpload(client, args, root);
|
|
29
|
+
}
|
|
30
|
+
if (UPLOAD_STEP_TOOLS.has(name)) {
|
|
31
|
+
return {
|
|
32
|
+
content: [{ text: "Use upload_file instead.", type: "text" }],
|
|
33
|
+
isError: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return await client.callTool({ name, arguments: args });
|
|
37
|
+
});
|
|
16
38
|
await server.connect(new StdioServerTransport());
|
|
17
39
|
}
|
|
40
|
+
async function runUpload(client, args, root) {
|
|
41
|
+
try {
|
|
42
|
+
const text = await uploadFile(client, {
|
|
43
|
+
path: String(args.path ?? ""),
|
|
44
|
+
roomId: String(args.roomId ?? ""),
|
|
45
|
+
title: typeof args.title === "string" ? args.title : undefined,
|
|
46
|
+
}, root);
|
|
47
|
+
return { content: [{ text, type: "text" }] };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const message = error instanceof UploadRefusal || error instanceof Error
|
|
51
|
+
? error.message
|
|
52
|
+
: "The upload failed.";
|
|
53
|
+
return {
|
|
54
|
+
content: [{ text: message, type: "text" }],
|
|
55
|
+
isError: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|