talentos 1.4.10 → 1.4.12
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/README.md +3 -3
- package/dist/agent/adapters.js +207 -14
- package/dist/agent/codex-policy.js +22 -0
- package/dist/agent/codex-probe.js +114 -30
- package/dist/agent/gemini-login.js +74 -0
- package/dist/agent/gemini-policy.js +91 -0
- package/dist/agent/gemini-probe.js +308 -0
- package/dist/agent/mcp-entry.js +22 -9
- package/dist/agent/native/approvals.js +15 -11
- package/dist/agent/native/codex-launch.js +3 -0
- package/dist/agent/native/config.js +4 -2
- package/dist/agent/native/gate.js +160 -8
- package/dist/agent/native/hook-entry.js +33 -8
- package/dist/agent/native/launch.js +3 -0
- package/dist/agent/native/native-issue.js +3 -3
- package/dist/agent/native/policy.js +62 -14
- package/dist/agent/native/probe.js +13 -1
- package/dist/agent/native/touch.js +33 -1
- package/dist/agent/node-floor.js +140 -0
- package/dist/agent/provider-failure.js +2 -2
- package/dist/agent/provider-login.js +134 -0
- package/dist/agent/room-profile.js +41 -4
- package/dist/agent/serve.js +75 -9
- package/dist/agent-config.js +6 -1
- package/dist/agent-http.js +57 -0
- package/dist/agent-link.js +4 -2
- package/dist/agent-session.js +137 -0
- package/dist/args.js +1 -0
- package/dist/client.js +11 -2
- package/dist/commands/agent-native.js +0 -3
- package/dist/commands/agent-serve.js +7 -2
- package/dist/commands/agent-session.js +160 -0
- package/dist/commands/agent.js +37 -3
- package/dist/commands/init.js +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/gateway-install.js +50 -11
- package/dist/index.js +13 -4
- package/dist/install.js +39 -14
- package/dist/mcp-proxy.js +30 -2
- package/dist/provider-binary.js +12 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { rm } from "node:fs/promises";
|
|
3
|
+
import { readFile, rm } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { writePrivateFile, } from "../../agent-config.js";
|
|
@@ -8,12 +8,12 @@ import { providerPathEnv, resolveProviderBinary, } from "../../provider-binary.j
|
|
|
8
8
|
import { codexFenceEligible, codexFenceVersion, codexUnsupportedMessage, } from "./codex-fence.js";
|
|
9
9
|
import { codexFenceProbeCached, ensureCodexFenceProbe, } from "./codex-fence-probe.js";
|
|
10
10
|
import { codexDisqualifier, codexOwnerContextPresent } from "./codex-owner.js";
|
|
11
|
-
import { NATIVE_FALLBACK_FILE, NATIVE_FILE, readNativeConfig, } from "./config.js";
|
|
11
|
+
import { enableNative, NATIVE_FALLBACK_FILE, NATIVE_FILE, NATIVE_OFF_FILE, readNativeConfig, repoRoot, rootProblem, } from "./config.js";
|
|
12
12
|
import { ownerContextPresent } from "./context.js";
|
|
13
13
|
import { claudeDisqualifier } from "./disqualify.js";
|
|
14
14
|
import { loginShellEnv } from "./env.js";
|
|
15
|
-
import { ensureOwnerNativeProbe } from "./probe.js";
|
|
16
|
-
import { readProjects } from "./projects.js";
|
|
15
|
+
import { ensureOwnerNativeProbe, ownerNativeProbeCached } from "./probe.js";
|
|
16
|
+
import { readProjects, registerRoot } from "./projects.js";
|
|
17
17
|
import { prepareWorkspace } from "./workspace.js";
|
|
18
18
|
const WHITESPACE = /\s+/u;
|
|
19
19
|
const exec = promisify(execFile);
|
|
@@ -21,10 +21,11 @@ const ENV_TTL_MS = 10 * 60_000;
|
|
|
21
21
|
const ENV_MAX_STALE_MS = 60 * 60_000;
|
|
22
22
|
const RETRY_MS = 10 * 60_000;
|
|
23
23
|
export const UNKNOWN_PROJECT = "That project isn't set up on this computer, so I'm working room-only.";
|
|
24
|
-
export const NO_PROJECT = "No project is
|
|
24
|
+
export const NO_PROJECT = "No project folder is chosen on this computer yet, so I'm working room-only. The owner can choose one in the agent settings.";
|
|
25
25
|
export const MISSING_PROJECT = "That project's folder isn't available on this computer, so I'm working room-only.";
|
|
26
|
-
export const NATIVE_OFF = "
|
|
27
|
-
export const NOT_READY = "The safety check for
|
|
26
|
+
export const NATIVE_OFF = "Computer access is off. Its owner can allow it in the agent settings.";
|
|
27
|
+
export const NOT_READY = "The safety check for this computer has not passed yet. Its owner can check the agent settings.";
|
|
28
|
+
export const CLAUDE_CHANGED = "Claude Code changed on this computer since its safety check, so I'm working room-only until it passes again.";
|
|
28
29
|
export const PREPARE_FAILED = "Something went wrong preparing your setup on this computer.";
|
|
29
30
|
export const LOCAL_BASE = "Couldn't get the latest code, so I started from your local copy.";
|
|
30
31
|
/**
|
|
@@ -41,15 +42,131 @@ export class NativeGate {
|
|
|
41
42
|
// last heartbeat. Until it arrives, a Codex is never probed or reported ready.
|
|
42
43
|
codexTested;
|
|
43
44
|
retryAt = 0;
|
|
45
|
+
syncing;
|
|
44
46
|
env;
|
|
45
47
|
agent;
|
|
46
48
|
directory;
|
|
49
|
+
hookEntry;
|
|
47
50
|
home;
|
|
48
51
|
constructor(input) {
|
|
52
|
+
this.hookEntry = input.hookEntry;
|
|
49
53
|
this.agent = input.agent;
|
|
50
54
|
this.directory = input.directory;
|
|
51
55
|
this.home = input.home;
|
|
52
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The owner's own choice in the app (a level above No access) authorizes the
|
|
59
|
+
* setup `talentos agent native enable` used to need a local yes for: the same
|
|
60
|
+
* folder rules and readiness checks, with no command. `null` is No access
|
|
61
|
+
* (instant), `undefined` an older server. A local `native off` holds until a
|
|
62
|
+
* later app choice (`enabledAt` newer than it).
|
|
63
|
+
*/
|
|
64
|
+
syncComputerSetup(choice) {
|
|
65
|
+
// A project request's heartbeat can overlap the regular one: one setup at a time.
|
|
66
|
+
this.syncing = (this.syncing ?? Promise.resolve())
|
|
67
|
+
.then(() => this.applyComputerSetup(choice))
|
|
68
|
+
.catch(() => undefined);
|
|
69
|
+
return this.syncing;
|
|
70
|
+
}
|
|
71
|
+
async applyComputerSetup(choice) {
|
|
72
|
+
if (choice === undefined) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (choice === null) {
|
|
76
|
+
await rm(join(this.directory, NATIVE_FILE), { force: true });
|
|
77
|
+
this.codexIssue = undefined;
|
|
78
|
+
this.probe = "none";
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (choice.enabledAt <= (await this.localOffAt())) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const stored = await readNativeConfig(this.directory);
|
|
86
|
+
let config = stored && !rootProblem(stored, this.home) ? stored : undefined;
|
|
87
|
+
if (stored && !config) {
|
|
88
|
+
// The folder went missing or was replaced: another project the owner
|
|
89
|
+
// added takes over; with none, the card asks for a folder.
|
|
90
|
+
config = await this.otherProject(stored.root);
|
|
91
|
+
}
|
|
92
|
+
else if (!config) {
|
|
93
|
+
config = await this.chooseWorkspace();
|
|
94
|
+
await registerRoot(this.directory, config);
|
|
95
|
+
}
|
|
96
|
+
if (!config) {
|
|
97
|
+
throw new Error("workspace");
|
|
98
|
+
}
|
|
99
|
+
if (config !== stored) {
|
|
100
|
+
this.probe = "none";
|
|
101
|
+
}
|
|
102
|
+
this.codexIssue =
|
|
103
|
+
this.codexIssue?.code === "workspace" ? undefined : this.codexIssue;
|
|
104
|
+
this.refresh();
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
this.codexIssue = { code: "workspace" };
|
|
108
|
+
this.probe = "failed";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async localOffAt() {
|
|
112
|
+
try {
|
|
113
|
+
const at = JSON.parse(await readFile(join(this.directory, NATIVE_OFF_FILE), "utf8"));
|
|
114
|
+
return typeof at === "number" ? at : Number.POSITIVE_INFINITY;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async otherProject(broken) {
|
|
121
|
+
for (const project of await readProjects(this.directory)) {
|
|
122
|
+
if (project.root === broken || rootProblem(project, this.home)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
return await enableNative({
|
|
127
|
+
agentId: this.agent.agentId,
|
|
128
|
+
directory: this.directory,
|
|
129
|
+
home: this.home,
|
|
130
|
+
kind: project.kind,
|
|
131
|
+
name: this.agent.name,
|
|
132
|
+
root: project.root,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// The next project.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Where it works: the repo it was connected from, else its existing first
|
|
143
|
+
* project, else ~/TalentOS/<name>-<id>. A refused folder (home, credentials)
|
|
144
|
+
* falls through to the managed folder rather than leaving it unset.
|
|
145
|
+
*/
|
|
146
|
+
async chooseWorkspace() {
|
|
147
|
+
const connected = this.agent.connectCwd
|
|
148
|
+
? await repoRoot(this.agent.connectCwd)
|
|
149
|
+
: undefined;
|
|
150
|
+
const existing = (await readProjects(this.directory))[0];
|
|
151
|
+
const chosen = connected
|
|
152
|
+
? { root: connected }
|
|
153
|
+
: existing && { kind: existing.kind, root: existing.root };
|
|
154
|
+
const input = {
|
|
155
|
+
agentId: this.agent.agentId,
|
|
156
|
+
directory: this.directory,
|
|
157
|
+
home: this.home,
|
|
158
|
+
name: this.agent.name,
|
|
159
|
+
};
|
|
160
|
+
if (chosen) {
|
|
161
|
+
try {
|
|
162
|
+
return await enableNative({ ...input, ...chosen });
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Too broad or unavailable: use the managed folder below.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return await enableNative(input);
|
|
169
|
+
}
|
|
53
170
|
/** The owner's yes exists on this computer (a file, so `native off` is instant). */
|
|
54
171
|
optedIn() {
|
|
55
172
|
return existsSync(join(this.directory, NATIVE_FILE));
|
|
@@ -68,7 +185,9 @@ export class NativeGate {
|
|
|
68
185
|
}
|
|
69
186
|
/** Why an opted-in computer can't use full setup, for the heartbeat. */
|
|
70
187
|
issue() {
|
|
71
|
-
return this.optedIn()
|
|
188
|
+
return this.optedIn() || this.codexIssue?.code === "workspace"
|
|
189
|
+
? this.codexIssue
|
|
190
|
+
: undefined;
|
|
72
191
|
}
|
|
73
192
|
/** Whether to tell the plane this computer is ready (heartbeat). */
|
|
74
193
|
reportable() {
|
|
@@ -100,6 +219,7 @@ export class NativeGate {
|
|
|
100
219
|
return;
|
|
101
220
|
}
|
|
102
221
|
this.probe = "failed";
|
|
222
|
+
this.codexIssue ??= { code: "setup_checks" };
|
|
103
223
|
// A failing provider is not re-probed on every heartbeat.
|
|
104
224
|
this.retryAt = Date.now() + RETRY_MS;
|
|
105
225
|
});
|
|
@@ -141,8 +261,10 @@ export class NativeGate {
|
|
|
141
261
|
await ensureOwnerNativeProbe({
|
|
142
262
|
binary,
|
|
143
263
|
cachePath: join(this.directory, "native-probe.json"),
|
|
264
|
+
hookEntry: this.hookEntry,
|
|
144
265
|
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
145
266
|
});
|
|
267
|
+
this.codexIssue = undefined;
|
|
146
268
|
}
|
|
147
269
|
/**
|
|
148
270
|
* The login-shell env. Within ten minutes of a capture it is reused. For the
|
|
@@ -225,6 +347,13 @@ export class NativeGate {
|
|
|
225
347
|
return;
|
|
226
348
|
}
|
|
227
349
|
const env = await this.loginEnv();
|
|
350
|
+
// Claude: an update in place replaces the binary the probe proved, so it is
|
|
351
|
+
// checked again per job (a stat and a --version, never the probe itself).
|
|
352
|
+
if (this.agent.provider !== "codex" && !(await this.claudeUnchanged(env))) {
|
|
353
|
+
this.probe = "none";
|
|
354
|
+
fell(CLAUDE_CHANGED);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
228
357
|
// Codex: the per-job fence checks come before any workspace is created.
|
|
229
358
|
const codex = this.agent.provider === "codex"
|
|
230
359
|
? await this.codexReady(env, job.codexTested)
|
|
@@ -295,6 +424,29 @@ export class NativeGate {
|
|
|
295
424
|
workspace,
|
|
296
425
|
};
|
|
297
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Per Claude owner job: the binary answering now is the one the cached probe
|
|
429
|
+
* proved (realpath, mtime, version). On a change the job runs room-only and
|
|
430
|
+
* the next heartbeat re-probes.
|
|
431
|
+
*/
|
|
432
|
+
async claudeUnchanged(env) {
|
|
433
|
+
try {
|
|
434
|
+
const binary = resolveProviderBinary(this.agent.provider, this.agent.providerPath);
|
|
435
|
+
const { stdout } = await exec(binary, ["--version"], {
|
|
436
|
+
env: { ...env, PATH: providerPathEnv(binary, this.home) },
|
|
437
|
+
timeout: 5000,
|
|
438
|
+
});
|
|
439
|
+
return await ownerNativeProbeCached({
|
|
440
|
+
binary,
|
|
441
|
+
cachePath: join(this.directory, "native-probe.json"),
|
|
442
|
+
hookEntry: this.hookEntry,
|
|
443
|
+
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
298
450
|
/** Per Codex owner job: the binary, its catalog and ~/.codex, or undefined. */
|
|
299
451
|
async codexReady(env, tested) {
|
|
300
452
|
// Fail closed: a claim without the server's list (an older server) never
|
|
@@ -22,7 +22,26 @@ export const HOLD_MS = 14 * 60_000;
|
|
|
22
22
|
const TOUCH_MS = 20_000;
|
|
23
23
|
export const HOOK_FAILED = "The room safety check could not run, so this action is blocked. Tell the owner and do not retry.";
|
|
24
24
|
const DECLINED = "The owner declined this. Do not retry or work around it; say in your reply what you were trying to do.";
|
|
25
|
+
// The sheet's labels (agent-permissions-dialog.tsx), by the class names the
|
|
26
|
+
// server sends when an Off setting refused an ask (#13236).
|
|
27
|
+
const OFF_LABELS = {
|
|
28
|
+
edit: "Edit files and local git",
|
|
29
|
+
outside: "Outside tools",
|
|
30
|
+
push: "Push to GitHub",
|
|
31
|
+
terminal: "Other terminal commands",
|
|
32
|
+
tests: "Run tests and builds",
|
|
33
|
+
};
|
|
25
34
|
const NO_ANSWER = "The owner did not answer in time. Do not retry; say in your reply what you wanted to do.";
|
|
35
|
+
/** The refusal for an Off setting, or the plain decline when none is named. */
|
|
36
|
+
function refusal(refusedBy) {
|
|
37
|
+
const labels = (refusedBy ?? []).flatMap((name) => OFF_LABELS[name] ?? []);
|
|
38
|
+
if (labels.length === 0) {
|
|
39
|
+
return DECLINED;
|
|
40
|
+
}
|
|
41
|
+
const last = labels.pop();
|
|
42
|
+
const names = labels.length > 0 ? `${labels.join(", ")} and ${last}` : last;
|
|
43
|
+
return `${names} ${labels.length > 0 ? "are" : "is"} Off for this agent, so this is blocked. Nobody declined it. Do not retry or work around it; tell the owner which setting blocks it, and say in your reply what you were trying to do.`;
|
|
44
|
+
}
|
|
26
45
|
function target(input) {
|
|
27
46
|
const raw = [input.command, input.file_path, input.path].find((value) => typeof value === "string");
|
|
28
47
|
// Arguments may hold secrets: keep the first words only.
|
|
@@ -91,22 +110,22 @@ function holdForOwner(socketPath, ask, holdMs) {
|
|
|
91
110
|
const info = lstatSync(socketPath);
|
|
92
111
|
if (!info.isSocket() ||
|
|
93
112
|
(process.getuid && info.uid !== process.getuid())) {
|
|
94
|
-
resolve("expired");
|
|
113
|
+
resolve({ answer: "expired" });
|
|
95
114
|
return;
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
catch {
|
|
99
|
-
resolve("expired");
|
|
118
|
+
resolve({ answer: "expired" });
|
|
100
119
|
return;
|
|
101
120
|
}
|
|
102
121
|
let settled = false;
|
|
103
122
|
let received = "";
|
|
104
|
-
const finish = (answer) => {
|
|
123
|
+
const finish = (answer, refusedBy) => {
|
|
105
124
|
if (!settled) {
|
|
106
125
|
settled = true;
|
|
107
126
|
socket.destroy();
|
|
108
127
|
clearTimeout(timer);
|
|
109
|
-
resolve(answer);
|
|
128
|
+
resolve({ answer, refusedBy });
|
|
110
129
|
}
|
|
111
130
|
};
|
|
112
131
|
const socket = connect(socketPath);
|
|
@@ -124,8 +143,10 @@ function holdForOwner(socketPath, ask, holdMs) {
|
|
|
124
143
|
received += chunk;
|
|
125
144
|
if (received.includes("\n")) {
|
|
126
145
|
try {
|
|
127
|
-
const { status } = JSON.parse(received.split("\n")[0] ?? "");
|
|
128
|
-
finish(status === "approved" || status === "denied" ? status : "expired")
|
|
146
|
+
const { refusedBy, status } = JSON.parse(received.split("\n")[0] ?? "");
|
|
147
|
+
finish(status === "approved" || status === "denied" ? status : "expired", Array.isArray(refusedBy)
|
|
148
|
+
? refusedBy.filter((name) => typeof name === "string")
|
|
149
|
+
: undefined);
|
|
129
150
|
}
|
|
130
151
|
catch {
|
|
131
152
|
finish("expired");
|
|
@@ -161,13 +182,17 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
161
182
|
const policy = {
|
|
162
183
|
dirty: existsSync(join(jobDir, "dirty")),
|
|
163
184
|
home: context.home,
|
|
185
|
+
roomId: context.roomId,
|
|
186
|
+
roomFileIds: context.roomFileIds,
|
|
187
|
+
triggerId: context.triggerId,
|
|
164
188
|
writeRoots: context.writeRoots,
|
|
165
189
|
};
|
|
166
190
|
verdict = classifyCall(call, policy);
|
|
167
191
|
const touches = touchesPrivate(call, policy, verdict.allow);
|
|
168
192
|
const taints = taintsJob(call, policy, verdict.allow ? undefined : verdict.ask);
|
|
169
193
|
if (!verdict.allow && verdict.ask && context.askSocket) {
|
|
170
|
-
|
|
194
|
+
const held = await holdForOwner(context.askSocket, verdict.ask, holdMs);
|
|
195
|
+
asked = held.answer;
|
|
171
196
|
if (asked === "approved") {
|
|
172
197
|
// An approved action may change files; later runs ask accordingly (R5).
|
|
173
198
|
verdict = { allow: true, mutates: true };
|
|
@@ -175,7 +200,7 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
175
200
|
else {
|
|
176
201
|
verdict = {
|
|
177
202
|
allow: false,
|
|
178
|
-
reason: asked === "denied" ?
|
|
203
|
+
reason: asked === "denied" ? refusal(held.refusedBy) : NO_ANSWER,
|
|
179
204
|
tier: verdict.tier,
|
|
180
205
|
};
|
|
181
206
|
}
|
|
@@ -50,6 +50,9 @@ export async function prepareOwnerLaunch(input) {
|
|
|
50
50
|
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
51
51
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
52
52
|
home: input.home,
|
|
53
|
+
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
54
|
+
...(input.roomFileIds ? { roomFileIds: input.roomFileIds } : {}),
|
|
55
|
+
...(input.triggerId ? { triggerId: input.triggerId } : {}),
|
|
53
56
|
writeRoots: input.workspace.writeRoots,
|
|
54
57
|
}));
|
|
55
58
|
await writePrivateFile(join(jobDir, "settings.json"), JSON.stringify({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const ROOM_ONLY_STATUS = "Codex is answering room-only: full setup isn't available on that computer right now.";
|
|
2
2
|
/** The neutral room line when an owner job runs room-only, for either provider. */
|
|
3
|
-
export const roomOnlyStatus = (provider) => provider === "
|
|
4
|
-
?
|
|
5
|
-
:
|
|
3
|
+
export const roomOnlyStatus = (provider) => provider === "claude_code"
|
|
4
|
+
? "Claude Code is answering room-only: full setup isn't available on that computer right now."
|
|
5
|
+
: ROOM_ONLY_STATUS;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from "node:fs";
|
|
2
|
-
import { basename, dirname, join, sep } from "node:path";
|
|
3
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
3
4
|
import { ROOM_LOCAL_TOOLS, ROOM_TOOLS } from "../codex-policy.js";
|
|
4
5
|
import { canonical, inGitDir, isInside, protectedPaths, protectedReason, reachesProtected, WRITE_PROTECTED_SEGMENTS, } from "./paths.js";
|
|
5
6
|
import { parseShell } from "./shell.js";
|
|
@@ -888,6 +889,10 @@ function hookSetup(ctx) {
|
|
|
888
889
|
for (const [, value] of configText(config, ctx.home).matchAll(HOOKS_PATH)) {
|
|
889
890
|
if (value) {
|
|
890
891
|
folders.push(canonical(value, top, ctx.home));
|
|
892
|
+
// Husky locates the user script from $0, before following folder links.
|
|
893
|
+
setup.folders.push(value === "~" || value.startsWith("~/")
|
|
894
|
+
? join(ctx.home, value.slice(1))
|
|
895
|
+
: resolve(top, value));
|
|
891
896
|
}
|
|
892
897
|
}
|
|
893
898
|
}
|
|
@@ -937,16 +942,59 @@ function hookConfig(real, ctx, content) {
|
|
|
937
942
|
PACKAGE_HOOK_KEY.test(content) ||
|
|
938
943
|
PACKAGE_HOOK_KEY.test(readText(real))));
|
|
939
944
|
}
|
|
940
|
-
//
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
945
|
+
// Pull includes both paths: config can select rebase without a CLI flag.
|
|
946
|
+
const GIT_HOOKS = {
|
|
947
|
+
commit: [
|
|
948
|
+
"pre-commit",
|
|
949
|
+
"prepare-commit-msg",
|
|
950
|
+
"commit-msg",
|
|
951
|
+
"post-commit",
|
|
952
|
+
"post-rewrite",
|
|
953
|
+
],
|
|
954
|
+
push: ["pre-push"],
|
|
955
|
+
checkout: ["post-checkout"],
|
|
956
|
+
switch: ["post-checkout"],
|
|
957
|
+
restore: ["post-checkout"],
|
|
958
|
+
pull: [
|
|
959
|
+
"post-merge",
|
|
960
|
+
"pre-merge-commit",
|
|
961
|
+
"prepare-commit-msg",
|
|
962
|
+
"commit-msg",
|
|
963
|
+
"pre-rebase",
|
|
964
|
+
"post-rewrite",
|
|
965
|
+
"post-checkout",
|
|
966
|
+
],
|
|
967
|
+
};
|
|
968
|
+
// Husky 9.1.7 exits before loading init code when the user's script is absent.
|
|
969
|
+
// Pin both helper and stub: a replacement may run code without that script.
|
|
970
|
+
const HUSKY_HELPER_SHA256 = "70200b200ca709b0622784f93839a5b2872333a917a09afddefd7dc2d8cdc680";
|
|
971
|
+
const HUSKY_STUB = '#!/usr/bin/env sh\n. "$(dirname "$0")/h"';
|
|
972
|
+
function hookMayExist(path) {
|
|
973
|
+
try {
|
|
974
|
+
statSync(path);
|
|
975
|
+
return true;
|
|
976
|
+
}
|
|
977
|
+
catch (error) {
|
|
978
|
+
return error.code !== "ENOENT";
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
function gitHookRuns(folder, name) {
|
|
982
|
+
const hook = join(folder, name);
|
|
983
|
+
if (!hookMayExist(hook)) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
return (readText(hook) !== HUSKY_STUB ||
|
|
987
|
+
createHash("sha256")
|
|
988
|
+
.update(readText(join(folder, "h")))
|
|
989
|
+
.digest("hex") !== HUSKY_HELPER_SHA256 ||
|
|
990
|
+
hookMayExist(join(dirname(folder), name)));
|
|
991
|
+
}
|
|
992
|
+
function gitRunsHooks(sub, ctx) {
|
|
993
|
+
const hooks = GIT_HOOKS[sub];
|
|
994
|
+
if (!hooks) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
return hookSetup(ctx).folders.some((folder) => hooks.some((name) => gitHookRuns(folder, name)));
|
|
950
998
|
}
|
|
951
999
|
// A clone into a folder that holds a hooks folder or a hook config's target
|
|
952
1000
|
// fills it from the clone (#13118).
|
|
@@ -1019,12 +1067,12 @@ function shellAsk(command, ctx) {
|
|
|
1019
1067
|
holdsHooks(word.text, ctx)))) {
|
|
1020
1068
|
tier = 1;
|
|
1021
1069
|
}
|
|
1022
|
-
// R5 for
|
|
1070
|
+
// R5 for git hooks (#13115, #13440): after an edit, hooks load configs
|
|
1023
1071
|
// and tests the model may have changed, so it also needs the owner's tests
|
|
1024
1072
|
// consent. The server reads `run:hooks` as the tests class.
|
|
1025
1073
|
return {
|
|
1026
|
-
kind:
|
|
1027
|
-
?
|
|
1074
|
+
kind: tier === 2 && ctx.dirty && gitRunsHooks(sub, ctx)
|
|
1075
|
+
? `git:${sub} + run:hooks`
|
|
1028
1076
|
: `git:${sub}`,
|
|
1029
1077
|
tier,
|
|
1030
1078
|
};
|
|
@@ -443,7 +443,7 @@ export async function probeOwnerNative(input) {
|
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
|
-
function cacheKey(binary, version, hookEntry) {
|
|
446
|
+
export function cacheKey(binary, version, hookEntry) {
|
|
447
447
|
const real = realpathSync.native(binary);
|
|
448
448
|
return createHash("sha256")
|
|
449
449
|
.update(JSON.stringify([
|
|
@@ -455,6 +455,18 @@ function cacheKey(binary, version, hookEntry) {
|
|
|
455
455
|
]))
|
|
456
456
|
.digest("hex");
|
|
457
457
|
}
|
|
458
|
+
/** Whether the cached pass still names this exact binary, version, probe and hook code. */
|
|
459
|
+
export async function ownerNativeProbeCached(input) {
|
|
460
|
+
try {
|
|
461
|
+
const cached = JSON.parse(await readFile(input.cachePath, "utf8"));
|
|
462
|
+
return (cached.ok === true &&
|
|
463
|
+
cached.key ===
|
|
464
|
+
cacheKey(input.binary, input.version, input.hookEntry ?? HOOK_ENTRY));
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
458
470
|
/** Cached probe: re-proves only when the binary, its version, the probe or the hook code changed. */
|
|
459
471
|
export async function ensureOwnerNativeProbe(input) {
|
|
460
472
|
const hookEntry = input.hookEntry ?? HOOK_ENTRY;
|
|
@@ -12,6 +12,9 @@ import { parseShell } from "./shell.js";
|
|
|
12
12
|
// workspace, a command the policy had to ask about, a tool we do not know)
|
|
13
13
|
// counts as touched.
|
|
14
14
|
const ROOM_SERVER_PREFIX = "mcp__talentos_room__";
|
|
15
|
+
// The room tools that reach beyond a room's own id: `list_rooms` has no roomId
|
|
16
|
+
// and names every room the agent can reach.
|
|
17
|
+
const ALL_ROOMS_TOOL = `${ROOM_SERVER_PREFIX}list_rooms`;
|
|
15
18
|
// Tools that read files by path; the path decides.
|
|
16
19
|
const PATH_TOOLS = new Set(["Glob", "Grep", "LS", "NotebookRead", "Read"]);
|
|
17
20
|
const EDIT_TOOLS = new Set(["Edit", "MultiEdit", "NotebookEdit", "Write"]);
|
|
@@ -37,6 +40,33 @@ const PATH_START = /[/~]/u;
|
|
|
37
40
|
function text(value) {
|
|
38
41
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
39
42
|
}
|
|
43
|
+
// A room tool aimed at another room reads words the server's "alone" check does
|
|
44
|
+
// not cover: it judges the job's own room only (#13436). A job whose room is
|
|
45
|
+
// unknown fails closed, so every room read taints.
|
|
46
|
+
function readsOtherRoom(call, jobRoomId) {
|
|
47
|
+
if (call.tool === ALL_ROOMS_TOOL) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const aimed = call.toolInput.roomId;
|
|
51
|
+
return aimed !== undefined && aimed !== jobRoomId;
|
|
52
|
+
}
|
|
53
|
+
// read_file and read_app_state name no room, so the id has to: only a file id
|
|
54
|
+
// the packet listed for the job's room, or an attachment of the message that
|
|
55
|
+
// started the job (the owner's own words), stays inside it (#13471). A read by
|
|
56
|
+
// versionId or another messageId, or a job with no list, fails closed.
|
|
57
|
+
const BY_ID_TOOLS = new Set(["read_file", "read_app_state"].map((name) => ROOM_SERVER_PREFIX + name));
|
|
58
|
+
function readsOtherRoomFile(call, context) {
|
|
59
|
+
if (!BY_ID_TOOLS.has(call.tool)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const { artifactId, messageId } = call.toolInput;
|
|
63
|
+
if (messageId !== undefined) {
|
|
64
|
+
return !(artifactId === undefined &&
|
|
65
|
+
typeof messageId === "string" &&
|
|
66
|
+
messageId === context.triggerId);
|
|
67
|
+
}
|
|
68
|
+
return !(typeof artifactId === "string" && context.roomFileIds?.includes(artifactId));
|
|
69
|
+
}
|
|
40
70
|
export function touchesPrivate(call, context, allowedByPolicy) {
|
|
41
71
|
// The policy had to ask the owner: it is outward, irreversible or unknown, and
|
|
42
72
|
// once approved it may read anything.
|
|
@@ -52,7 +82,9 @@ export function touchesPrivate(call, context, allowedByPolicy) {
|
|
|
52
82
|
return context.writeRoots.some((root) => isInside(real, root));
|
|
53
83
|
};
|
|
54
84
|
if (tool.startsWith("mcp__")) {
|
|
55
|
-
return !tool.startsWith(ROOM_SERVER_PREFIX)
|
|
85
|
+
return (!tool.startsWith(ROOM_SERVER_PREFIX) ||
|
|
86
|
+
readsOtherRoom(call, context.roomId) ||
|
|
87
|
+
readsOtherRoomFile(call, context));
|
|
56
88
|
}
|
|
57
89
|
if (NEUTRAL_TOOLS.has(tool)) {
|
|
58
90
|
return false;
|