sentinelayer-cli 0.45.0 → 0.46.1
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 +2 -1
- package/package.json +1 -1
- package/src/agents/agent-id-path.js +57 -0
- package/src/agents/jules/tools/runtime-audit.js +2 -1
- package/src/agents/shared-tools/shell.js +9 -0
- package/src/ai/aidenid.js +11 -10
- package/src/ai/client.js +2 -1
- package/src/audit/orchestrator.js +7 -1
- package/src/audit/registry.js +9 -1
- package/src/auth/credential-destinations.js +57 -13
- package/src/auth/http.js +4 -0
- package/src/auth/service.js +4 -3
- package/src/board/evidence-resolvers.js +15 -3
- package/src/cli.js +10 -0
- package/src/commands/ai/identity-lifecycle.js +4 -3
- package/src/commands/chat.js +4 -1
- package/src/commands/session.js +4 -3
- package/src/daemon/ast-parser-layer.js +8 -3
- package/src/daemon/callgraph-overlay.js +7 -2
- package/src/legacy-cli.js +4 -1
- package/src/mcp/session-stdio-server.js +13 -9
- package/src/net/gh-api-path.js +68 -0
- package/src/net/url-path.js +41 -0
- package/src/program-lookup.js +54 -0
- package/src/review/dd-report-email-client.js +2 -3
- package/src/review/local-review.js +11 -5
- package/src/scan/gh-secrets.js +4 -1
- package/src/session/admission-access.js +17 -8
- package/src/session/admission.js +12 -5
- package/src/session/agent-registry.js +4 -5
- package/src/session/checkpoints.js +4 -3
- package/src/session/file-locks.js +8 -6
- package/src/session/invitations.js +2 -1
- package/src/session/listener-process.js +6 -7
- package/src/session/live-source.js +2 -3
- package/src/session/paths.js +51 -2
- package/src/session/store.js +3 -3
- package/src/session/sync.js +34 -26
- package/src/session/tickets.js +13 -6
- package/src/session/title-sync.js +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { extname, resolve as resolvePath } from "node:path";
|
|
3
4
|
import { promisify } from "node:util";
|
|
4
5
|
|
|
5
6
|
import { parse } from "@babel/parser";
|
|
@@ -149,7 +150,7 @@ async function resolvePythonExecutable() {
|
|
|
149
150
|
pythonExecutablePromise = (async () => {
|
|
150
151
|
for (const executable of PYTHON_EXECUTABLE_CANDIDATES) {
|
|
151
152
|
try {
|
|
152
|
-
await execFileAsync(executable, ["--version"], { timeout: 5000 });
|
|
153
|
+
await execFileAsync(executable, ["--version"], { timeout: 5000, cwd: os.tmpdir() });
|
|
153
154
|
return executable;
|
|
154
155
|
} catch {
|
|
155
156
|
continue;
|
|
@@ -193,9 +194,13 @@ async function parsePythonAstSpecifiers(absolutePath = "") {
|
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
try {
|
|
196
|
-
|
|
197
|
+
// Isolated (-I: no script or working directory on sys.path, no PYTHON* variables) and run from
|
|
198
|
+
// a neutral directory, so a repository's own ast.py or json.py is never imported; the file to
|
|
199
|
+
// parse is passed as an argument.
|
|
200
|
+
const { stdout } = await execFileAsync(executable, ["-I", "-c", PYTHON_AST_SCRIPT, resolvePath(absolutePath)], {
|
|
197
201
|
timeout: 10000,
|
|
198
202
|
maxBuffer: 1024 * 1024,
|
|
203
|
+
cwd: os.tmpdir(),
|
|
199
204
|
});
|
|
200
205
|
const parsed = JSON.parse(String(stdout || "{}"));
|
|
201
206
|
const specifiers = Array.isArray(parsed.specifiers) ? parsed.specifiers : [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import fsp from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
3
4
|
import path, { extname } from "node:path";
|
|
4
5
|
import { promisify } from "node:util";
|
|
5
6
|
|
|
@@ -370,7 +371,7 @@ async function resolvePythonExecutable() {
|
|
|
370
371
|
pythonExecutablePromise = (async () => {
|
|
371
372
|
for (const executable of PYTHON_EXECUTABLE_CANDIDATES) {
|
|
372
373
|
try {
|
|
373
|
-
await execFileAsync(executable, ["--version"], { timeout: 5000 });
|
|
374
|
+
await execFileAsync(executable, ["--version"], { timeout: 5000, cwd: os.tmpdir() });
|
|
374
375
|
return executable;
|
|
375
376
|
} catch {
|
|
376
377
|
continue;
|
|
@@ -454,9 +455,13 @@ async function parsePythonCallgraph(absolutePath = "", content = "", normalizedL
|
|
|
454
455
|
};
|
|
455
456
|
}
|
|
456
457
|
try {
|
|
457
|
-
|
|
458
|
+
// Isolated (-I: no script or working directory on sys.path, no PYTHON* variables) and run from
|
|
459
|
+
// a neutral directory, so a repository's own ast.py or json.py is never imported; the file to
|
|
460
|
+
// parse is passed as an argument.
|
|
461
|
+
const { stdout } = await execFileAsync(executable, ["-I", "-c", PYTHON_CALLGRAPH_SCRIPT, path.resolve(absolutePath)], {
|
|
458
462
|
timeout: 15000,
|
|
459
463
|
maxBuffer: 1024 * 1024,
|
|
464
|
+
cwd: os.tmpdir(),
|
|
460
465
|
});
|
|
461
466
|
const parsed = JSON.parse(String(stdout || "{}"));
|
|
462
467
|
return {
|
package/src/legacy-cli.js
CHANGED
|
@@ -31,6 +31,7 @@ import { normalizeAgentEvent } from "./events/schema.js";
|
|
|
31
31
|
import { collectCodebaseIngest, formatIngestSummary } from "./ingest/engine.js";
|
|
32
32
|
import { getExpressTemplate, getPackageJsonTemplate, buildReadmeContent } from "./scaffold/templates.js";
|
|
33
33
|
import { generateScaffold } from "./scaffold/generator.js";
|
|
34
|
+
import { isGhRepoSlug } from "./net/gh-api-path.js";
|
|
34
35
|
import {
|
|
35
36
|
getCoordinationEtiquetteItems,
|
|
36
37
|
renderCoordinationNumberedList,
|
|
@@ -117,8 +118,10 @@ function normalizeRepoSlug(value) {
|
|
|
117
118
|
return String(value || "").trim().replace(/\.git$/i, "");
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
// Exactly owner/repo as GitHub names them (src/net/gh-api-path.js): the slug goes into gh API
|
|
122
|
+
// paths and --repo values, and into the clone and remote URLs.
|
|
120
123
|
function isValidRepoSlug(value) {
|
|
121
|
-
return
|
|
124
|
+
return isGhRepoSlug(normalizeRepoSlug(value));
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
function getRepoNameFromSlug(value) {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "./cli-command-tools.js";
|
|
10
10
|
import { appendToStream, readStream } from "../session/stream.js";
|
|
11
11
|
import { listFileLocks, lockFile, unlockFile } from "../session/file-locks.js";
|
|
12
|
+
import { resolveSessionDir } from "../session/paths.js";
|
|
12
13
|
import { eventMatchesAgent } from "../session/listener.js";
|
|
13
14
|
import { isSessionControlEvent } from "../session/control-events.js";
|
|
14
15
|
import { buildObservations } from "../session/recall/observations.js";
|
|
@@ -594,11 +595,14 @@ async function readSessionHistoryWindow({
|
|
|
594
595
|
};
|
|
595
596
|
}
|
|
596
597
|
|
|
597
|
-
|
|
598
|
+
// A native tool's session id also names its local session directory, so it is held to the
|
|
599
|
+
// session-id rule here, before any request is sent or any file is read or written.
|
|
600
|
+
function requireSessionId(input = {}, { targetPath } = {}) {
|
|
598
601
|
const sessionId = normalizeString(input.sessionId || input.session_id || input.session);
|
|
599
602
|
if (!sessionId) {
|
|
600
603
|
throw new Error("sessionId is required.");
|
|
601
604
|
}
|
|
605
|
+
resolveSessionDir(sessionId, { targetPath });
|
|
602
606
|
return sessionId;
|
|
603
607
|
}
|
|
604
608
|
|
|
@@ -712,7 +716,7 @@ async function runSessionAction({
|
|
|
712
716
|
targetPath,
|
|
713
717
|
createSessionMessageActionFn,
|
|
714
718
|
} = {}) {
|
|
715
|
-
const sessionId = requireSessionId(input);
|
|
719
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
716
720
|
const agentId = requireAgentId(input);
|
|
717
721
|
const normalizedActionType = normalizeSessionMessageActionType(actionType || input.actionType || input.action_type);
|
|
718
722
|
const target = requireSessionActionTarget(input);
|
|
@@ -995,7 +999,7 @@ export function createSessionMcpToolHandlers({
|
|
|
995
999
|
};
|
|
996
1000
|
const handlers = {
|
|
997
1001
|
async poll_inbox(input = {}) {
|
|
998
|
-
const sessionId = requireSessionId(input);
|
|
1002
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
999
1003
|
const agentId = requireAgentId(input);
|
|
1000
1004
|
const cursor = normalizeString(input.cursor || input.after || input.since) || null;
|
|
1001
1005
|
const limit = normalizeLimit(input.limit);
|
|
@@ -1071,7 +1075,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1071
1075
|
},
|
|
1072
1076
|
|
|
1073
1077
|
async read_history(input = {}) {
|
|
1074
|
-
const sessionId = requireSessionId(input);
|
|
1078
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1075
1079
|
const cursor = normalizeString(input.cursor || input.after || input.since) || null;
|
|
1076
1080
|
const beforeSequence = normalizeOptionalPositiveInteger(
|
|
1077
1081
|
input.beforeSequence || input.before_sequence,
|
|
@@ -1164,7 +1168,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1164
1168
|
},
|
|
1165
1169
|
|
|
1166
1170
|
async send_message(input = {}) {
|
|
1167
|
-
const sessionId = requireSessionId(input);
|
|
1171
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1168
1172
|
const agentId = requireAgentId(input);
|
|
1169
1173
|
const recipients = normalizeRecipients(input.to || input.recipient || input.recipients);
|
|
1170
1174
|
const agent = buildAgentEnvelope(agentId, input);
|
|
@@ -1223,7 +1227,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1223
1227
|
},
|
|
1224
1228
|
|
|
1225
1229
|
async session_lock(input = {}) {
|
|
1226
|
-
const sessionId = requireSessionId(input);
|
|
1230
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1227
1231
|
const agentId = requireAgentId(input);
|
|
1228
1232
|
const files = normalizeFileList(input.files || input.file || input.paths);
|
|
1229
1233
|
const intent = normalizeString(input.intent || input.reason);
|
|
@@ -1257,7 +1261,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1257
1261
|
},
|
|
1258
1262
|
|
|
1259
1263
|
async session_unlock(input = {}) {
|
|
1260
|
-
const sessionId = requireSessionId(input);
|
|
1264
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1261
1265
|
const agentId = requireAgentId(input);
|
|
1262
1266
|
const files = normalizeFileList(input.files || input.file || input.paths);
|
|
1263
1267
|
const reason = normalizeString(input.reason || input.intent) || "manual_release";
|
|
@@ -1290,7 +1294,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1290
1294
|
},
|
|
1291
1295
|
|
|
1292
1296
|
async session_locks(input = {}) {
|
|
1293
|
-
const sessionId = requireSessionId(input);
|
|
1297
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1294
1298
|
const locks = await listFileLocksFn(sessionId, {
|
|
1295
1299
|
targetPath,
|
|
1296
1300
|
});
|
|
@@ -1304,7 +1308,7 @@ export function createSessionMcpToolHandlers({
|
|
|
1304
1308
|
},
|
|
1305
1309
|
|
|
1306
1310
|
async attention_request(input = {}) {
|
|
1307
|
-
const sessionId = requireSessionId(input);
|
|
1311
|
+
const sessionId = requireSessionId(input, { targetPath });
|
|
1308
1312
|
const agentId = requireAgentId(input);
|
|
1309
1313
|
const recipients = normalizeRecipients(input.to || input.recipient || input.recipients);
|
|
1310
1314
|
const agent = buildAgentEnvelope(agentId, {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// gh-api-path.js — the values the CLI puts into GitHub API paths that gh requests.
|
|
2
|
+
//
|
|
3
|
+
// gh sends every request with the signed-in user's GitHub token. The CLI builds `gh api` paths
|
|
4
|
+
// (repos/<owner>/<repo>/...) and passes --repo values that gh turns into paths of its own, so each
|
|
5
|
+
// value is checked for its role before any gh process starts:
|
|
6
|
+
//
|
|
7
|
+
// ghRepoSlug exactly "owner/repo". The owner starts with a letter or digit, then letters,
|
|
8
|
+
// digits, "-" or "_" (Enterprise Managed User names end in "_shortcode"), at most
|
|
9
|
+
// 39 characters. The repository is letters, digits, ".", "_" or "-", at most 100
|
|
10
|
+
// characters, and not "." or "..".
|
|
11
|
+
// ghCommitSha 7 to 40 hexadecimal characters.
|
|
12
|
+
// ghRefSegment a git branch, tag or ref name under git's ref-name rules, not starting with "-",
|
|
13
|
+
// percent-encoded as ONE path segment. A branch name may contain "/", and git also
|
|
14
|
+
// allows "#", "%", "{" and other characters that mean something in a URL or to gh;
|
|
15
|
+
// encoded, they stay inside the segment. GitHub's compare ({base}...{head}) and
|
|
16
|
+
// commits/{ref} endpoints accept a branch name with "/" encoded as %2F.
|
|
17
|
+
//
|
|
18
|
+
// Each returns the value to put in the path, or throws an Error saying what the value must be.
|
|
19
|
+
// These are GitHub-specific rather than a general one-segment encoder: a branch name may contain
|
|
20
|
+
// "/" and still be one segment once encoded, and a slug or a commit SHA has a shape of its own.
|
|
21
|
+
|
|
22
|
+
const OWNER = /^[A-Za-z0-9][A-Za-z0-9_-]{0,38}$/;
|
|
23
|
+
const REPO = /^[A-Za-z0-9._-]{1,100}$/;
|
|
24
|
+
const COMMIT_SHA = /^[0-9A-Fa-f]{7,40}$/;
|
|
25
|
+
// Control characters, space, and the other characters git does not allow in a ref name.
|
|
26
|
+
const REF_FORBIDDEN = /[\u0000-\u0020\u007f-\u009f~^:?*[\\]/;
|
|
27
|
+
|
|
28
|
+
/** True when `value` is exactly "owner/repo" as GitHub names them. */
|
|
29
|
+
export function isGhRepoSlug(value) {
|
|
30
|
+
if (typeof value !== "string") return false;
|
|
31
|
+
const parts = value.split("/");
|
|
32
|
+
if (parts.length !== 2) return false;
|
|
33
|
+
const [owner, repo] = parts;
|
|
34
|
+
return OWNER.test(owner) && REPO.test(repo) && repo !== "." && repo !== "..";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** True when `value` is a valid git branch, tag or ref name that does not start with "-". */
|
|
38
|
+
export function isGitRefName(value) {
|
|
39
|
+
if (typeof value !== "string" || !value || !value.isWellFormed()) return false;
|
|
40
|
+
if (value === "@" || value.includes("..") || value.includes("@{") || value.includes("//")) return false;
|
|
41
|
+
if (REF_FORBIDDEN.test(value)) return false;
|
|
42
|
+
if (value.startsWith("-") || value.startsWith("/") || value.endsWith("/") || value.endsWith(".")) return false;
|
|
43
|
+
return value.split("/").every((part) => !part.startsWith(".") && !part.endsWith(".lock"));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `value` as an owner/repo path, or throws. */
|
|
47
|
+
export function ghRepoSlug(value, { label = "repo" } = {}) {
|
|
48
|
+
if (!isGhRepoSlug(value)) {
|
|
49
|
+
throw new Error(`${label} must be a GitHub repository in owner/repo form.`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `value` as a commit SHA path segment, or throws. */
|
|
55
|
+
export function ghCommitSha(value, { label = "sha" } = {}) {
|
|
56
|
+
if (typeof value !== "string" || !COMMIT_SHA.test(value)) {
|
|
57
|
+
throw new Error(`${label} must be a commit SHA of 7 to 40 hexadecimal characters.`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `value` (a git branch, tag or ref name) percent-encoded as one path segment, or throws. */
|
|
63
|
+
export function ghRefSegment(value, { label = "ref" } = {}) {
|
|
64
|
+
if (!isGitRefName(value)) {
|
|
65
|
+
throw new Error(`${label} must be a valid git branch, tag or ref name.`);
|
|
66
|
+
}
|
|
67
|
+
return encodeURIComponent(value);
|
|
68
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// url-path.js — one identifier, one URL path segment.
|
|
2
|
+
//
|
|
3
|
+
// The CLI puts identifiers into API URL paths: session, admission, ticket, lease, checkpoint, run,
|
|
4
|
+
// token, message, reply, scan and AIdenID ids. urlPathSegment encodes each one as exactly one
|
|
5
|
+
// segment, and refuses a value that cannot be one: empty, "." or "..", or containing "/", "\", a
|
|
6
|
+
// control character or an unpaired surrogate. The URL builders that take ids (the session,
|
|
7
|
+
// ticket, admission and lease URL helpers) take the raw id and call it themselves.
|
|
8
|
+
//
|
|
9
|
+
// tests/unit.url-path-segments.test.mjs holds the census of src/ and says exactly which forms it
|
|
10
|
+
// checks. assertCredentialDestination (src/auth/credential-destinations.js) also checks the path
|
|
11
|
+
// of every URL it sends a credential to.
|
|
12
|
+
|
|
13
|
+
// C0 controls, DEL and C1 controls.
|
|
14
|
+
const CONTROL_CHARACTER = /[\u0000-\u001f\u007f-\u009f]/;
|
|
15
|
+
|
|
16
|
+
/** Whether urlPathSegment accepts `value`. Use it to refuse an id before any request work starts. */
|
|
17
|
+
export function isUrlPathSegment(value) {
|
|
18
|
+
const text = String(value ?? "");
|
|
19
|
+
return (
|
|
20
|
+
text !== "" &&
|
|
21
|
+
text !== "." &&
|
|
22
|
+
text !== ".." &&
|
|
23
|
+
!/[/\\]/.test(text) &&
|
|
24
|
+
!CONTROL_CHARACTER.test(text) &&
|
|
25
|
+
text.isWellFormed()
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `value` encoded as exactly one URL path segment. Refuses an empty value, "." or "..", and a
|
|
31
|
+
* value containing "/", "\", a control character or an unpaired surrogate. "%" is encoded, so
|
|
32
|
+
* "%2e%2e" is sent as "%252e%252e" and stays one literal segment.
|
|
33
|
+
*/
|
|
34
|
+
export function urlPathSegment(value, { label = "identifier" } = {}) {
|
|
35
|
+
if (!isUrlPathSegment(value)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`${label} must be a single URL path segment: not empty, "." or "..", and without "/", "\\" or control characters.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return encodeURIComponent(String(value ?? ""));
|
|
41
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
|
|
3
|
+
// Windows looks up a program named without a path in the working directory before PATH. The CLI
|
|
4
|
+
// runs git, gh, python, npm and other tools by name, often from inside a repository, so it turns
|
|
5
|
+
// that lookup off with NoDefaultCurrentDirectoryInExePath. Node.js spawns through libuv, which
|
|
6
|
+
// honours that variable from libuv 1.48.0 (Node.js 22); an older libuv ignores it. On such a
|
|
7
|
+
// runtime the CLI does not run at all on Windows, rather than run with the lookup on.
|
|
8
|
+
export const MIN_WINDOWS_LIBUV = Object.freeze([1, 48, 0]);
|
|
9
|
+
|
|
10
|
+
function parseVersion(value) {
|
|
11
|
+
const parts = String(value || "").split(".");
|
|
12
|
+
if (parts.length < 2 || parts.length > 3) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const numbers = parts.map((part) => (/^\d+$/.test(part) ? Number(part) : NaN));
|
|
16
|
+
return numbers.every(Number.isInteger) ? [...numbers, 0].slice(0, 3) : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function atLeast(version, minimum) {
|
|
20
|
+
for (let index = 0; index < minimum.length; index += 1) {
|
|
21
|
+
if (version[index] !== minimum[index]) {
|
|
22
|
+
return version[index] > minimum[index];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Turn off working-directory program lookup for this process and the children that inherit its
|
|
30
|
+
* environment. Returns { ok: false, message } instead when this is Windows and the runtime would
|
|
31
|
+
* ignore the setting.
|
|
32
|
+
*/
|
|
33
|
+
export function restrictProgramLookupToPath({
|
|
34
|
+
platform = process.platform,
|
|
35
|
+
libuv = process.versions.uv,
|
|
36
|
+
nodeVersion = process.version,
|
|
37
|
+
env = process.env,
|
|
38
|
+
} = {}) {
|
|
39
|
+
if (platform !== "win32") {
|
|
40
|
+
return { ok: true };
|
|
41
|
+
}
|
|
42
|
+
const version = parseVersion(libuv);
|
|
43
|
+
if (!version || !atLeast(version, MIN_WINDOWS_LIBUV)) {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
message:
|
|
47
|
+
`On Windows, sentinelayer-cli needs Node.js 22 or later (libuv ${MIN_WINDOWS_LIBUV.join(".")} or later). ` +
|
|
48
|
+
`This is Node.js ${nodeVersion} with libuv ${libuv || "unknown"}, which looks up programs in the current ` +
|
|
49
|
+
"directory before PATH. Upgrade Node.js and run the command again.",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
env.NoDefaultCurrentDirectoryInExePath = "1";
|
|
53
|
+
return { ok: true };
|
|
54
|
+
}
|
|
@@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
|
|
3
3
|
import { checkedTransport, credentialFor, isAuthenticated } from "../auth/credential-destinations.js";
|
|
4
4
|
import { resolveActiveAuthSession } from "../auth/service.js";
|
|
5
5
|
import { requestJson } from "../auth/http.js";
|
|
6
|
+
import { urlPathSegment } from "../net/url-path.js";
|
|
6
7
|
|
|
7
8
|
export const DD_REPORT_EMAIL_TIMEOUT_MS = 10_000;
|
|
8
9
|
|
|
@@ -108,9 +109,7 @@ export async function sendDdReportEmail({
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
const apiUrl = normalizeString(session.apiUrl) || "https://api.sentinelayer.com";
|
|
111
|
-
const endpoint = `${apiUrl.replace(/\/+$/, "")}/api/v1/runs/${
|
|
112
|
-
normalizedRunId,
|
|
113
|
-
)}/send-report-email`;
|
|
112
|
+
const endpoint = `${apiUrl.replace(/\/+$/, "")}/api/v1/runs/${urlPathSegment(normalizedRunId, { label: "runId" })}/send-report-email`;
|
|
114
113
|
const idempotencyKey = buildReportEmailIdempotencyKey({
|
|
115
114
|
runId: normalizedRunId,
|
|
116
115
|
to: normalizedTo,
|
|
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import fsp from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
|
+
import { buildScrubbedEnv } from "../agents/shared-tools/shell.js";
|
|
6
7
|
import { resolveOutputRoot } from "../config/service.js";
|
|
7
8
|
import { resolveCodebaseIngest } from "../ingest/engine.js";
|
|
8
9
|
import { runSpecBindingChecks } from "./spec-binding.js";
|
|
@@ -844,6 +845,13 @@ function buildStaticChecks(ingest = {}) {
|
|
|
844
845
|
];
|
|
845
846
|
}
|
|
846
847
|
|
|
848
|
+
// The repository's own scripts run here (lint, typecheck, format check, tests). Running its code is
|
|
849
|
+
// the point; handing it this machine's credentials is not. SentinelLayer, provider, GitHub, cloud
|
|
850
|
+
// and other secret-looking variables are removed from its environment.
|
|
851
|
+
export function staticCheckEnv(env = process.env) {
|
|
852
|
+
return { ...buildScrubbedEnv(env), CI: "1", FORCE_COLOR: "0" };
|
|
853
|
+
}
|
|
854
|
+
|
|
847
855
|
async function executeStaticCheck({ check, targetPath, runDir } = {}) {
|
|
848
856
|
const checksDir = path.join(runDir, "checks");
|
|
849
857
|
await fsp.mkdir(checksDir, { recursive: true });
|
|
@@ -853,11 +861,7 @@ async function executeStaticCheck({ check, targetPath, runDir } = {}) {
|
|
|
853
861
|
cwd: targetPath,
|
|
854
862
|
encoding: "utf-8",
|
|
855
863
|
timeout: STATIC_CHECK_TIMEOUT_MS,
|
|
856
|
-
env:
|
|
857
|
-
...process.env,
|
|
858
|
-
CI: "1",
|
|
859
|
-
FORCE_COLOR: "0",
|
|
860
|
-
},
|
|
864
|
+
env: staticCheckEnv(),
|
|
861
865
|
});
|
|
862
866
|
|
|
863
867
|
const durationMs = Date.now() - startedAt;
|
|
@@ -927,6 +931,8 @@ async function executeStaticCheck({ check, targetPath, runDir } = {}) {
|
|
|
927
931
|
};
|
|
928
932
|
}
|
|
929
933
|
|
|
934
|
+
export const __localReviewForTests = Object.freeze({ executeStaticCheck });
|
|
935
|
+
|
|
930
936
|
async function runStaticAnalysisLayer({ targetPath, ingest, runDir, maxFindings = MAX_FINDINGS } = {}) {
|
|
931
937
|
const checks = buildStaticChecks(ingest);
|
|
932
938
|
const results = [];
|
package/src/scan/gh-secrets.js
CHANGED
|
@@ -2,6 +2,8 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
|
|
5
|
+
import { isGhRepoSlug } from "../net/gh-api-path.js";
|
|
6
|
+
|
|
5
7
|
function getGhCommand() {
|
|
6
8
|
return String(process.env.SENTINELAYER_GH_BIN || "").trim() || "gh";
|
|
7
9
|
}
|
|
@@ -10,8 +12,9 @@ function normalizeRepoSlug(value) {
|
|
|
10
12
|
return String(value || "").trim().replace(/\.git$/i, "");
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
// Exactly owner/repo as GitHub names them: gh turns the --repo value into API paths.
|
|
13
16
|
function isValidRepoSlug(value) {
|
|
14
|
-
return
|
|
17
|
+
return isGhRepoSlug(normalizeRepoSlug(value));
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
function isValidSecretName(value) {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
createSessionMutationHeaders,
|
|
19
19
|
createSessionMutationIdempotencyKey,
|
|
20
20
|
} from "./invitations.js";
|
|
21
|
+
import { urlPathSegment } from "../net/url-path.js";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Approve, deny, revoke and mode changes are the room owner's decisions, made with the
|
|
@@ -84,8 +85,13 @@ async function authContext(targetPath, resolveAuthSession) {
|
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
function admissionsUrl(apiUrl, sessionId
|
|
88
|
-
return `${apiUrl}/api/v1/sessions/${
|
|
88
|
+
function admissionsUrl(apiUrl, sessionId) {
|
|
89
|
+
return `${apiUrl}/api/v1/sessions/${urlPathSegment(sessionId, { label: "sessionId" })}/admissions`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One admission's URL: the raw admission id is encoded here; `route` is a fixed route ("/revoke"). */
|
|
93
|
+
function admissionMemberUrl(apiUrl, sessionId, admissionId, route = "") {
|
|
94
|
+
return `${admissionsUrl(apiUrl, sessionId)}/${urlPathSegment(admissionId, { label: "admissionId" })}${route}`;
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
function boundedIdempotencyKey(value, operation) {
|
|
@@ -96,7 +102,8 @@ function boundedIdempotencyKey(value, operation) {
|
|
|
96
102
|
|
|
97
103
|
async function mutateAdmission(
|
|
98
104
|
sessionId,
|
|
99
|
-
|
|
105
|
+
admissionId,
|
|
106
|
+
route,
|
|
100
107
|
routeId,
|
|
101
108
|
body,
|
|
102
109
|
{
|
|
@@ -110,7 +117,7 @@ async function mutateAdmission(
|
|
|
110
117
|
) {
|
|
111
118
|
const key = boundedIdempotencyKey(idempotencyKey, operationName);
|
|
112
119
|
const auth = await authContext(targetPath, resolveAuthSession);
|
|
113
|
-
const result = await checkedTransport(requestMutation)(
|
|
120
|
+
const result = await checkedTransport(requestMutation)(admissionMemberUrl(auth.apiUrl, sessionId, admissionId, route), {
|
|
114
121
|
method: "POST",
|
|
115
122
|
operationName,
|
|
116
123
|
idempotencyKey: key,
|
|
@@ -163,7 +170,7 @@ export async function getSessionAdmission(
|
|
|
163
170
|
const sid = required(sessionId, "session id");
|
|
164
171
|
const aid = required(admissionId, "admission id");
|
|
165
172
|
const auth = await authContext(targetPath, resolveAuthSession);
|
|
166
|
-
return checkedTransport(requestRead)(
|
|
173
|
+
return checkedTransport(requestRead)(admissionMemberUrl(auth.apiUrl, sid, aid), {
|
|
167
174
|
method: "GET",
|
|
168
175
|
credential: auth.credential,
|
|
169
176
|
});
|
|
@@ -201,7 +208,8 @@ export async function decideSessionAdmission(
|
|
|
201
208
|
await assertOwnerAccessContext();
|
|
202
209
|
return mutateAdmission(
|
|
203
210
|
sid,
|
|
204
|
-
|
|
211
|
+
aid,
|
|
212
|
+
"/decision",
|
|
205
213
|
ROUTES.decision,
|
|
206
214
|
body,
|
|
207
215
|
{
|
|
@@ -233,7 +241,8 @@ export async function revokeSessionAdmission(
|
|
|
233
241
|
await assertOwnerAccessContext();
|
|
234
242
|
return mutateAdmission(
|
|
235
243
|
sid,
|
|
236
|
-
|
|
244
|
+
aid,
|
|
245
|
+
"/revoke",
|
|
237
246
|
ROUTES.revoke,
|
|
238
247
|
normalizedReason ? { reason: normalizedReason } : {},
|
|
239
248
|
{
|
|
@@ -267,7 +276,7 @@ export async function setSessionAdmissionMode(
|
|
|
267
276
|
const key = boundedIdempotencyKey(idempotencyKey, "session.admission_mode");
|
|
268
277
|
const auth = await authContext(targetPath, resolveAuthSession);
|
|
269
278
|
const result = await checkedTransport(requestMutation)(
|
|
270
|
-
`${auth.apiUrl}/api/v1/sessions/${
|
|
279
|
+
`${auth.apiUrl}/api/v1/sessions/${urlPathSegment(sid, { label: "sessionId" })}/admission-mode`,
|
|
271
280
|
{
|
|
272
281
|
method: "POST",
|
|
273
282
|
operationName: "session.admission_mode",
|
package/src/session/admission.js
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
createSessionMutationIdempotencyKey,
|
|
42
42
|
} from "./invitations.js";
|
|
43
43
|
import { resolveSessionPaths } from "./paths.js";
|
|
44
|
+
import { urlPathSegment } from "../net/url-path.js";
|
|
44
45
|
|
|
45
46
|
export const ADMISSION_ACTIONS = Object.freeze([
|
|
46
47
|
"session.read",
|
|
@@ -373,8 +374,14 @@ async function authContext({ targetPath, resolveAuthSession }) {
|
|
|
373
374
|
return { credential: await credentialFor(auth), apiUrl: normalizeString(auth.apiUrl).replace(/\/+$/, "") };
|
|
374
375
|
}
|
|
375
376
|
|
|
376
|
-
|
|
377
|
-
|
|
377
|
+
/** The session's admissions URL; `route` is a fixed collection route ("/self"). */
|
|
378
|
+
function admissionUrl(apiUrl, sessionId, route = "") {
|
|
379
|
+
return `${apiUrl}/api/v1/sessions/${urlPathSegment(sessionId, { label: "sessionId" })}/admissions${route}`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** One admission's URL: the raw admission id is encoded here; `route` is a fixed route ("/claim"). */
|
|
383
|
+
function admissionMemberUrl(apiUrl, sessionId, admissionId, route = "") {
|
|
384
|
+
return `${admissionUrl(apiUrl, sessionId)}/${urlPathSegment(admissionId, { label: "admissionId" })}${route}`;
|
|
378
385
|
}
|
|
379
386
|
|
|
380
387
|
async function mutate(auth, sessionId, routeId, url, body, { requestMutation, operationName, origin }) {
|
|
@@ -530,7 +537,7 @@ export async function runAdmissionJoin(
|
|
|
530
537
|
const deadline = now() + Math.max(0, waitTimeoutMs);
|
|
531
538
|
let polled;
|
|
532
539
|
for (;;) {
|
|
533
|
-
polled = await checkedTransport(requestRead)(
|
|
540
|
+
polled = await checkedTransport(requestRead)(admissionMemberUrl(auth.apiUrl, sid, state.admissionId), {
|
|
534
541
|
method: "GET",
|
|
535
542
|
credential: auth.credential,
|
|
536
543
|
});
|
|
@@ -599,7 +606,7 @@ export async function runAdmissionJoin(
|
|
|
599
606
|
auth,
|
|
600
607
|
sid,
|
|
601
608
|
ROUTE.claim,
|
|
602
|
-
|
|
609
|
+
admissionMemberUrl(auth.apiUrl, sid, state.admissionId, "/claim"),
|
|
603
610
|
{ nonce: fields.nonce, signature: signature.toString("base64url") },
|
|
604
611
|
{ ...deps, operationName: "session.admission_claim" }
|
|
605
612
|
);
|
|
@@ -702,7 +709,7 @@ export async function cancelAdmission(
|
|
|
702
709
|
auth,
|
|
703
710
|
sid,
|
|
704
711
|
ROUTE.cancel,
|
|
705
|
-
|
|
712
|
+
admissionMemberUrl(auth.apiUrl, sid, state.admissionId, "/cancel"),
|
|
706
713
|
undefined,
|
|
707
714
|
{ requestMutation, origin, operationName: "session.admission_cancel" }
|
|
708
715
|
);
|
|
@@ -3,6 +3,7 @@ import fsp from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
|
|
6
|
+
import { resolveAgentIdPath } from "../agents/agent-id-path.js";
|
|
6
7
|
import { STUCK_THRESHOLDS } from "../agents/jules/pulse.js";
|
|
7
8
|
import { inferSessionAgentIdentity } from "./agent-identity.js";
|
|
8
9
|
import { resolveSessionPaths } from "./paths.js";
|
|
@@ -175,12 +176,10 @@ async function writeAgentSnapshot(snapshotPath, snapshot) {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
// <session>/agents/<agentId>.json, refused before any read or write unless the id names one
|
|
180
|
+
// file directly under the agents directory.
|
|
178
181
|
function buildAgentSnapshotPath(paths, agentId) {
|
|
179
|
-
|
|
180
|
-
if (!normalizedAgentId) {
|
|
181
|
-
throw new Error("agentId is required.");
|
|
182
|
-
}
|
|
183
|
-
return path.join(paths.agentsDir, `${normalizedAgentId}.json`);
|
|
182
|
+
return resolveAgentIdPath(paths.agentsDir, normalizeString(agentId), ".json");
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
export function generateAgentId(modelName) {
|
|
@@ -5,6 +5,7 @@ import { checkedTransport, credentialFor, isAuthenticated } from "../auth/creden
|
|
|
5
5
|
import { SentinelayerApiError, requestJson, requestJsonMutation } from "../auth/http.js";
|
|
6
6
|
import { resolveActiveAuthSession } from "../auth/service.js";
|
|
7
7
|
import { pollSessionEventsBefore } from "./sync.js";
|
|
8
|
+
import { urlPathSegment } from "../net/url-path.js";
|
|
8
9
|
|
|
9
10
|
const DEFAULT_API_BASE_URL = "https://api.sentinelayer.com";
|
|
10
11
|
const DEFAULT_CHECKPOINT_LIMIT = 100;
|
|
@@ -442,7 +443,7 @@ export async function listSessionCheckpoints(sessionId, {
|
|
|
442
443
|
const { apiUrl, credential } = await resolveCheckpointApi({ targetPath, resolveAuthSession });
|
|
443
444
|
const params = new URLSearchParams({ limit: String(normalizeLimit(limit)) });
|
|
444
445
|
const response = await request(
|
|
445
|
-
`${apiUrl}/api/v1/sessions/${
|
|
446
|
+
`${apiUrl}/api/v1/sessions/${urlPathSegment(normalizedSessionId, { label: "sessionId" })}/checkpoints?${params.toString()}`,
|
|
446
447
|
{ method: "GET", credential },
|
|
447
448
|
);
|
|
448
449
|
const checkpoints = Array.isArray(response?.checkpoints) ? response.checkpoints : [];
|
|
@@ -522,7 +523,7 @@ export async function createSessionCheckpoint(sessionId, options = {}) {
|
|
|
522
523
|
const { body, idempotencyKey } = buildManualCheckpointPayload(normalizedSessionId, options);
|
|
523
524
|
const { apiUrl, credential } = await resolveCheckpointApi({ targetPath, resolveAuthSession });
|
|
524
525
|
const response = await checkedTransport(requestMutation)(
|
|
525
|
-
`${apiUrl}/api/v1/sessions/${
|
|
526
|
+
`${apiUrl}/api/v1/sessions/${urlPathSegment(normalizedSessionId, { label: "sessionId" })}/checkpoints`,
|
|
526
527
|
{
|
|
527
528
|
operationName: "session-checkpoint-create",
|
|
528
529
|
credential,
|
|
@@ -549,7 +550,7 @@ export async function generateSessionCheckpoint(sessionId, options = {}) {
|
|
|
549
550
|
const { body, idempotencyKey } = buildGenerateCheckpointPayload(normalizedSessionId, options);
|
|
550
551
|
const { apiUrl, credential } = await resolveCheckpointApi({ targetPath, resolveAuthSession });
|
|
551
552
|
const response = await checkedTransport(requestMutation)(
|
|
552
|
-
`${apiUrl}/api/v1/sessions/${
|
|
553
|
+
`${apiUrl}/api/v1/sessions/${urlPathSegment(normalizedSessionId, { label: "sessionId" })}/checkpoints/generate`,
|
|
553
554
|
{
|
|
554
555
|
operationName: "session-checkpoint-generate",
|
|
555
556
|
credential,
|