@sagentlab/navarch-runtime 0.1.176 → 0.1.178

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.
@@ -225,11 +225,11 @@ class ConversationLoop {
225
225
  ...(shutdownSignal ? { signal: shutdownSignal } : {}),
226
226
  ...this.options.turnOverrides,
227
227
  log: this.log,
228
- prepareWorkspace: async ({ conversationId, repositoryUrl, workingBranch, gitCredential, mode, signal }) => {
228
+ prepareWorkspace: async ({ conversationId, repositoryUrl, workingBranch, gitCredential, gitCredentialUsername, mode, signal }) => {
229
229
  if (!gitCredential)
230
230
  throw new Error("Control plane did not provide the conversation Git credential");
231
231
  const workspace = await (0, workspace_cjs_1.prepareConversationWorkspace)({
232
- workspaceRoot: config.workspaceRoot, conversationId, repositoryUrl, workingBranch, gitCredential, env, signal, mode,
232
+ workspaceRoot: config.workspaceRoot, conversationId, repositoryUrl, workingBranch, gitCredential, gitCredentialUsername, env, signal, mode,
233
233
  ...(this.options.gitRunner ? { runner: this.options.gitRunner } : {}),
234
234
  ...(this.mirrors ? { mirrors: this.mirrors } : {}),
235
235
  });
@@ -282,7 +282,7 @@ async function runConversationTurn(deps, conversationId, turnId) {
282
282
  let outcome = "failed";
283
283
  let metrics = { firstEventMs: null, firstTextMs: null };
284
284
  try {
285
- const repositoryUrl = (0, workspace_cjs_1.validRepositoryUrl)(claim.repository);
285
+ const repositoryUrl = (0, workspace_cjs_1.validRepositoryUrl)(claim.repository, claim.gitCredentialUsername);
286
286
  const snapshot = claim.conversation;
287
287
  let prepared = null;
288
288
  let prompt = "";
@@ -300,7 +300,7 @@ async function runConversationTurn(deps, conversationId, turnId) {
300
300
  prompt = (0, prompt_cjs_1.buildConversationPrompt)(snapshot, journal.turnId, deps.adapter.agentType === "codex");
301
301
  // Older servers omit the working branch: the checkout stays on the default branch.
302
302
  const workingBranch = (0, workspace_cjs_1.validWorkingBranch)(claim.workingBranch);
303
- prepared = await deps.prepareWorkspace({ conversationId, repositoryUrl, workingBranch, gitCredential: claim.gitCredential, mode: snapshot.mode ?? "read_only", signal: controller.signal });
303
+ prepared = await deps.prepareWorkspace({ conversationId, repositoryUrl, workingBranch, gitCredential: claim.gitCredential, gitCredentialUsername: claim.gitCredentialUsername, mode: snapshot.mode ?? "read_only", signal: controller.signal });
304
304
  }
305
305
  catch (error) {
306
306
  if (!run.lost)
@@ -32,16 +32,25 @@ function conversationEnv(base = process.env) {
32
32
  return env;
33
33
  }
34
34
  /**
35
- * Maps the project's stored repository value to a GitHub https clone URL.
35
+ * Maps the project's stored repository value to a validated HTTPS clone URL.
36
+ * A server-supplied username selects Codeup; absent usernames preserve GitHub forms.
36
37
  * The control plane stores a free-form value; the task path accepts
37
38
  * `owner/name`, `git@github.com:owner/name(.git)` and `https://github.com/...`
38
39
  * (lib/navarch/github-repository.ts), and so does this one. Anything else
39
40
  * (another host, `ext::`, `file:`, `-` options, embedded credentials) returns
40
41
  * null, so the runtime never hands an unvalidated string to git.
41
42
  */
42
- function validRepositoryUrl(value) {
43
+ function validRepositoryUrl(value, username) {
43
44
  if (typeof value !== "string" || value.length > 2048 || /[\s\0]/.test(value))
44
45
  return null;
46
+ if (username !== undefined) {
47
+ if (!/^[A-Za-z0-9._@+-]{1,128}$/.test(username))
48
+ return null;
49
+ const match = /^https:\/\/(codeup\.aliyun\.com|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+devops\.aliyuncs\.com)\/([A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*)\/?$/i.exec(value);
50
+ if (!match || match[2].split("/").some(s => s === "." || s === ".."))
51
+ return null;
52
+ return `https://${match[1].toLowerCase()}/${match[2]}`;
53
+ }
45
54
  const fullName = value
46
55
  .replace(/^git@github\.com:/i, "")
47
56
  .replace(/^https:\/\/github\.com\//i, "")
@@ -82,7 +91,7 @@ function conversationRoot(workspaceRoot, conversationId) {
82
91
  * mirror of the repository instead of a full network clone (see mirror.cts).
83
92
  */
84
93
  async function prepareConversationWorkspace(options) {
85
- const url = validRepositoryUrl(options.repositoryUrl);
94
+ const url = validRepositoryUrl(options.repositoryUrl, options.gitCredentialUsername);
86
95
  if (!url)
87
96
  throw new Error("repository URL is not a plain https URL");
88
97
  const branch = validWorkingBranch(options.workingBranch);
@@ -128,10 +137,11 @@ async function prepareConversationWorkspace(options) {
128
137
  GIT_CONFIG_VALUE_0: process.platform === "win32" ? "NUL" : "/dev/null",
129
138
  ...(options.gitCredential ? {
130
139
  NAVARCH_CONVERSATION_GIT_TOKEN: options.gitCredential,
140
+ NAVARCH_CONVERSATION_GIT_USERNAME: options.gitCredentialUsername ?? "x-access-token",
131
141
  GIT_CONFIG_COUNT: "5",
132
142
  GIT_CONFIG_KEY_1: "credential.helper", GIT_CONFIG_VALUE_1: "",
133
143
  GIT_CONFIG_KEY_2: `credential.${url}.helper`,
134
- GIT_CONFIG_VALUE_2: `!f() { if [ "$1" = get ]; then printf '%s\\n' 'username=x-access-token' "password=$NAVARCH_CONVERSATION_GIT_TOKEN"; fi; }; f`,
144
+ GIT_CONFIG_VALUE_2: `!f() { if [ "$1" = get ]; then printf '%s\\n' "username=$NAVARCH_CONVERSATION_GIT_USERNAME" "password=$NAVARCH_CONVERSATION_GIT_TOKEN"; fi; }; f`,
135
145
  GIT_CONFIG_KEY_3: "credential.useHttpPath", GIT_CONFIG_VALUE_3: "true",
136
146
  GIT_CONFIG_KEY_4: "http.followRedirects", GIT_CONFIG_VALUE_4: "false",
137
147
  } : {}),
@@ -154,7 +164,7 @@ async function prepareConversationWorkspace(options) {
154
164
  }
155
165
  if (result.code !== 0) {
156
166
  await node_fs_1.promises.rm(workspace.checkout, { recursive: true, force: true }).catch(() => undefined);
157
- throw new Error(`git clone failed with exit ${result.code}; check the project's GitHub connection and repository access`);
167
+ throw new Error(`git clone failed with exit ${result.code}; check the project's ${options.gitCredentialUsername ? 'Codeup' : 'GitHub'} connection and repository access`);
158
168
  }
159
169
  void options.mirrors?.warm(url, env, options.signal);
160
170
  }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // Reserved provider environment names (docs/navarch/custom-provider-endpoints.md § 3.3.1).
3
+ //
4
+ // Mirrors lib/navarch/provider-secret-names.ts in the control plane, which this
5
+ // standalone package cannot import. The conversion must stay identical to the
6
+ // one in `toEnvMap` (session.cts); a root test
7
+ // (lib/navarch/__tests__/provider-secret-names.test.ts) runs both copies and
8
+ // `toEnvMap` on the same inputs.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ENDPOINT_PROTECTED_ENV_NAMES = void 0;
11
+ exports.providerSecretEnvName = providerSecretEnvName;
12
+ exports.isProtectedProviderSecret = isProtectedProviderSecret;
13
+ /** Environment names the custom endpoint sets. No user secret may produce one. */
14
+ exports.ENDPOINT_PROTECTED_ENV_NAMES = Object.freeze([
15
+ "ANTHROPIC_BASE_URL",
16
+ "OPENAI_BASE_URL",
17
+ "ANTHROPIC_MODEL",
18
+ "ANTHROPIC_AUTH_TOKEN",
19
+ ]);
20
+ /** The environment name `toEnvMap` gives a secret named `name`. */
21
+ function providerSecretEnvName(name) {
22
+ return name.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
23
+ }
24
+ /**
25
+ * True when a user secret named `name` must be refused because its environment
26
+ * name is a protected provider name. On managed machines pass the managed
27
+ * provider secret names; their converted forms are protected too.
28
+ */
29
+ function isProtectedProviderSecret(name, managedProviderNames = []) {
30
+ const protectedNames = new Set([
31
+ ...exports.ENDPOINT_PROTECTED_ENV_NAMES,
32
+ ...Array.from(managedProviderNames, providerSecretEnvName),
33
+ ]);
34
+ return protectedNames.has(providerSecretEnvName(name));
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.176",
3
+ "version": "0.1.178",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",