gitnexus 1.6.13-rc.42 → 1.6.13-rc.43

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 CHANGED
@@ -354,6 +354,7 @@ max_concurrency: 1
354
354
  repo_git_timeout: 10s
355
355
  analyze_timeout: 5m
356
356
  analyze_failure_threshold: 3
357
+ # allowed_hosts: [gitlab.mycompany.com]
357
358
  projects:
358
359
  - local_path: /abs/path/to/repos
359
360
  branches: [master, main]
@@ -368,7 +369,7 @@ projects:
368
369
  - git@gitee.com:owner/repo.git
369
370
  ```
370
371
 
371
- `sync_interval_minutes` must be an integer of at least `5`. `local_path` must be an absolute path without traversal; each remote is cloned below it as `host/namespace/repo`, preventing same-basename repositories from colliding. `remote_urls` may use SSH SCP form (`git@host:owner/repo.git`) or HTTPS (`https://host/owner/repo.git`) for github.com, gitlab.com, or gitee.com. The published CLI image includes `openssh-client` so SSH remotes can clone; mount keys and `known_hosts` yourself. An invalid `watch_config.yml` skips auto-sync immediately with the validation error. `repo_git_timeout` applies to each repo clone/pull and defaults to `10s`; a bare number such as `10` is interpreted as seconds, while `10000ms`, `10s`, and `1m` keep their explicit units. It must not exceed one hour or `sync_interval_minutes`, whichever is smaller — so a bare `600000` is rejected, because it means 600000 seconds rather than milliseconds. `analyze_timeout` applies to each isolated analysis worker and defaults to half of `sync_interval_minutes`, but it is independent of polling and may be longer, up to Node's timer limit (`2147483647ms`). A `5` minute poll with `analyze_timeout: 30m` is valid. Auto-sync analysis honors the cloned repo's `.gitnexusrc` embeddings settings; the CLI image still needs `GITNEXUS_EMBEDDING_URL` or a bind-mounted embedding stack because npm is stripped. A tick that arrives while the previous loop is active never overlaps it: ticks coalesce into one immediate follow-up run, which pulls and analyzes the newest commit. If the parent times out and leaves that worker running, the follow-up is deferred to the next interval so a leftover lock holder is not counted as a hard analyze failure. Timeout and `auto-sync stop` request safe cancellation; a worker already in native work exits after it returns to a JS-visible safe point. While waiting, auto-sync reports `cancelling` or `stopping` and keeps its ownership files so another auto-sync cannot take over. The parent waits up to 5 seconds for the worker to exit; after that it stops waiting, releases its ownership files, and leaves the worker to finish and exit on its own rather than killing it mid-write. `auto-sync stop` uses this same control path on macOS and Windows.
372
+ `sync_interval_minutes` must be an integer of at least `5`. `local_path` must be an absolute path without traversal; each remote is cloned below it as `host/namespace/repo`, preventing same-basename repositories from colliding. `remote_urls` may use SSH SCP form (`git@host:owner/repo.git`) or HTTPS (`https://host/owner/repo.git`). Hosts are limited to github.com, gitlab.com, and gitee.com unless listed in top-level `allowed_hosts` (exact DNS names, no wildcards). The published CLI image includes `openssh-client` so SSH remotes can clone; mount keys and `known_hosts` yourself. An invalid `watch_config.yml` skips auto-sync immediately with the validation error. `repo_git_timeout` applies to each repo clone/pull and defaults to `10s`; a bare number such as `10` is interpreted as seconds, while `10000ms`, `10s`, and `1m` keep their explicit units. It must not exceed one hour or `sync_interval_minutes`, whichever is smaller — so a bare `600000` is rejected, because it means 600000 seconds rather than milliseconds. `analyze_timeout` applies to each isolated analysis worker and defaults to half of `sync_interval_minutes`, but it is independent of polling and may be longer, up to Node's timer limit (`2147483647ms`). A `5` minute poll with `analyze_timeout: 30m` is valid. Auto-sync analysis honors the cloned repo's `.gitnexusrc` embeddings settings; the CLI image still needs `GITNEXUS_EMBEDDING_URL` or a bind-mounted embedding stack because npm is stripped. A tick that arrives while the previous loop is active never overlaps it: ticks coalesce into one immediate follow-up run, which pulls and analyzes the newest commit. If the parent times out and leaves that worker running, the follow-up is deferred to the next interval so a leftover lock holder is not counted as a hard analyze failure. Timeout and `auto-sync stop` request safe cancellation; a worker already in native work exits after it returns to a JS-visible safe point. While waiting, auto-sync reports `cancelling` or `stopping` and keeps its ownership files so another auto-sync cannot take over. The parent waits up to 5 seconds for the worker to exit; after that it stops waiting, releases its ownership files, and leaves the worker to finish and exit on its own rather than killing it mid-write. `auto-sync stop` uses this same control path on macOS and Windows.
372
373
 
373
374
  `pdg` is configured per project. `pdg: true` builds and maintains the full CFG, control-dependence, reaching-definition, and taint layers on both initial and incremental analyses. Auto-sync requests staged atomic incremental publication where the analyzer supports it: the old graph remains available to readers until the replacement succeeds, and analysis errors are recorded while the old graph remains intact. Unsupported paths retain the analyzer's existing in-place behavior. Untouched configs that omit `pdg` preserve the existing index mode and cannot silently strip PDG data. Do not paste `pdg: false` from this example onto an existing watch file unless you intend to drop PDG. An explicit `pdg: false` disables PDG and emits a warning before a successful rebuild removes those layers. `overwrite_local_changes` defaults to `false`; a dirty local clone is skipped with an error log, while `true` allows branch fallback to replace local changes and additionally discards untracked files and directories in the clone after checkout — ignored paths, including GitNexus's own `.gitnexus/` storage, are preserved. `max_concurrency` defaults to `1` and is capped at runtime by `floor(availableMemoryGB / 2)` with a minimum of `1`; the effective value is printed at the start of each loop. Each analysis worker's heap cap is the machine-wide cap divided by the number of repositories analyzed in parallel, so concurrent workers share one memory budget instead of each claiming the whole machine. `analyze_failure_threshold` defaults to `3`, must be at least `2`, and pauses repeated failures only for the same repo branch, commit, and requested PDG mode; a new commit, a PDG mode change, or `gitnexus auto-sync reset` clears the block and allows analysis again. Repositories are registered and added to groups by their full remote identity (`host/namespace/repo`), so repositories with the same basename remain distinct. Use `branches` to try branches in order; legacy `branch` remains supported, but the two fields cannot be set together. If all branches are unavailable or time out, watch logs an error, records the repo status, and skips that repo for the loop. Leave `group_name` empty or omit it to skip group add/sync for that project; otherwise create the group first with `gitnexus group create <name>`. `$GITNEXUS_HOME/watch/project_commit_info.txt` is for inspection only; GitNexus stores machine state separately in `$GITNEXUS_HOME/watch/auto-sync-state.json`.
374
375
 
@@ -96,6 +96,9 @@ function defaultSyncConfig(localPath) {
96
96
  'repo_git_timeout: 10s',
97
97
  'analyze_timeout: 5m',
98
98
  'analyze_failure_threshold: 3',
99
+ '# Extra SSH/HTTPS hosts beyond github.com, gitlab.com, and gitee.com.',
100
+ '# Exact DNS names only; wildcards are rejected.',
101
+ '# allowed_hosts: [gitlab.mycompany.com]',
99
102
  'projects:',
100
103
  ` - local_path: ${localPath}`,
101
104
  ' branches: [master, main]',
@@ -106,7 +109,7 @@ function defaultSyncConfig(localPath) {
106
109
  ' overwrite_local_changes: false',
107
110
  ' remote_urls:',
108
111
  ' - git@github.com:owner/repo.git',
109
- ' # HTTPS remotes on github.com, gitlab.com, or gitee.com are also allowed',
112
+ ' # HTTPS remotes are also allowed. Other hosts need top-level allowed_hosts.',
110
113
  ' # - https://github.com/owner/public-repo.git',
111
114
  '',
112
115
  ].join('\n');
@@ -170,7 +170,7 @@ export declare const en: {
170
170
  readonly 'help.command.setup.description': 'One-time setup: configure MCP for Cursor, Claude Code, Antigravity, OpenCode, CodeBuddy, Qoder, Codex, Factory Droid';
171
171
  readonly 'help.command.uninstall.description': 'Reverse `setup`: remove GitNexus MCP entries, skills, and hooks from all detected editors';
172
172
  readonly 'help.command.autoSync.description': 'Control scheduled repository clone/pull and analysis from GITNEXUS_HOME/watch_config.yml';
173
- readonly 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.';
173
+ readonly 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Other hosts need a top-level allowed_hosts list of exact DNS names. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.';
174
174
  readonly 'help.command.watch.description': 'Ambiguous: use `analyze --watch` for local files, or `auto-sync` for scheduled remotes';
175
175
  readonly 'help.watch.details': '\n`gitnexus watch` does not start a watcher.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n';
176
176
  readonly 'error.watch.ambiguous': '`gitnexus watch` is ambiguous.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n';
@@ -172,7 +172,7 @@ export const en = {
172
172
  'help.command.setup.description': 'One-time setup: configure MCP for Cursor, Claude Code, Antigravity, OpenCode, CodeBuddy, Qoder, Codex, Factory Droid',
173
173
  'help.command.uninstall.description': 'Reverse `setup`: remove GitNexus MCP entries, skills, and hooks from all detected editors',
174
174
  'help.command.autoSync.description': 'Control scheduled repository clone/pull and analysis from GITNEXUS_HOME/watch_config.yml',
175
- 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.',
175
+ 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Other hosts need a top-level allowed_hosts list of exact DNS names. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.',
176
176
  'help.command.watch.description': 'Ambiguous: use `analyze --watch` for local files, or `auto-sync` for scheduled remotes',
177
177
  'help.watch.details': '\n`gitnexus watch` does not start a watcher.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n',
178
178
  'error.watch.ambiguous': '`gitnexus watch` is ambiguous.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n',
@@ -171,7 +171,7 @@ export declare const cliResources: {
171
171
  readonly 'help.command.setup.description': 'One-time setup: configure MCP for Cursor, Claude Code, Antigravity, OpenCode, CodeBuddy, Qoder, Codex, Factory Droid';
172
172
  readonly 'help.command.uninstall.description': 'Reverse `setup`: remove GitNexus MCP entries, skills, and hooks from all detected editors';
173
173
  readonly 'help.command.autoSync.description': 'Control scheduled repository clone/pull and analysis from GITNEXUS_HOME/watch_config.yml';
174
- readonly 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.';
174
+ readonly 'help.autoSync.details': '\nActions: init, start (default), restart, stop, status, reset\nConfiguration: GITNEXUS_HOME/watch_config.yml\nRuntime files: GITNEXUS_HOME/watch/watch.pid, watch.mutex, watch.owner.json, watch.status.json, auto-sync-state.json\nRecovery: mutexes with verified dead owners are reclaimed automatically; invalid or legacy mutexes fail closed and require manual removal after confirming no watch process is running.\nWrites: GITNEXUS_HOME/watch/project_commit_info.txt\nRemote URLs: SSH or HTTPS URLs on github.com, gitlab.com, and gitee.com are allowed. Other hosts need a top-level allowed_hosts list of exact DNS names. Invalid watch_config.yml skips auto-sync immediately.\nRuns once immediately, then repeats on sync_interval_minutes.';
175
175
  readonly 'help.command.watch.description': 'Ambiguous: use `analyze --watch` for local files, or `auto-sync` for scheduled remotes';
176
176
  readonly 'help.watch.details': '\n`gitnexus watch` does not start a watcher.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n';
177
177
  readonly 'error.watch.ambiguous': '`gitnexus watch` is ambiguous.\n Local working-tree incremental index: gitnexus analyze --watch\n Scheduled remote clone/pull + analyze: gitnexus auto-sync start\n';
@@ -170,7 +170,7 @@ export const zhCN = {
170
170
  'help.command.setup.description': '一次性设置:为 Cursor、Claude Code、Antigravity、OpenCode、CodeBuddy、Qoder、Codex、Factory Droid 配置 MCP',
171
171
  'help.command.uninstall.description': '撤销 `setup`:从所有检测到的编辑器中移除 GitNexus 的 MCP 配置、技能和钩子',
172
172
  'help.command.autoSync.description': '控制基于 GITNEXUS_HOME/watch_config.yml 的定时 clone/pull 和分析',
173
- 'help.autoSync.details': '\n操作:init、start(默认)、restart、stop、status、reset\n配置:GITNEXUS_HOME/watch_config.yml\n运行时文件:GITNEXUS_HOME/watch/watch.pid、watch.mutex、watch.owner.json、watch.status.json、auto-sync-state.json\n恢复:已验证 owner 退出的 mutex 会自动回收;无效或旧版 mutex 会安全拒绝,确认没有 watch 进程运行后再手动删除。\n写入:GITNEXUS_HOME/watch/project_commit_info.txt\n远程地址:允许 github.com、gitlab.com 和 gitee.com 上的 SSH 或 HTTPS 地址。无效的 watch_config.yml 会立即跳过 auto-sync。\n启动后立即运行一次,之后按 sync_interval_minutes 重复。',
173
+ 'help.autoSync.details': '\n操作:init、start(默认)、restart、stop、status、reset\n配置:GITNEXUS_HOME/watch_config.yml\n运行时文件:GITNEXUS_HOME/watch/watch.pid、watch.mutex、watch.owner.json、watch.status.json、auto-sync-state.json\n恢复:已验证 owner 退出的 mutex 会自动回收;无效或旧版 mutex 会安全拒绝,确认没有 watch 进程运行后再手动删除。\n写入:GITNEXUS_HOME/watch/project_commit_info.txt\n远程地址:允许 github.com、gitlab.com 和 gitee.com 上的 SSH 或 HTTPS 地址。其他主机需在顶层 allowed_hosts 中列出精确 DNS 名称。无效的 watch_config.yml 会立即跳过 auto-sync。\n启动后立即运行一次,之后按 sync_interval_minutes 重复。',
174
174
  'help.command.watch.description': '含义不明确:本地文件请用 `analyze --watch`,定时远程同步请用 `auto-sync`',
175
175
  'help.watch.details': '\n`gitnexus watch` 不会启动监视器。\n 本地工作区增量索引:gitnexus analyze --watch\n 定时远程 clone/pull 并分析:gitnexus auto-sync start\n',
176
176
  'error.watch.ambiguous': '`gitnexus watch` 含义不明确。\n 本地工作区增量索引:gitnexus analyze --watch\n 定时远程 clone/pull 并分析:gitnexus auto-sync start\n',
@@ -1,5 +1,12 @@
1
1
  export declare const AUTO_SYNC_CONFIG_FILE = "watch_config.yml";
2
2
  export declare const DEFAULT_ANALYZE_FAILURE_THRESHOLD = 3;
3
+ /**
4
+ * Name git should resolve. A trailing dot forces an absolute lookup, so a
5
+ * search list cannot answer `git` as `git.<domain>` or retry an FQDN under
6
+ * that domain after NXDOMAIN. A strict IPv4 literal stays undotted: `10.0.0.1.`
7
+ * is a DNS name, not that address.
8
+ */
9
+ export declare function absoluteAutoSyncRemoteUrl(remoteUrl: string): string;
3
10
  export interface AutoSyncProjectConfig {
4
11
  localPath: string;
5
12
  groupName?: string;
@@ -16,6 +23,11 @@ export interface AutoSyncConfig {
16
23
  analyzeTimeoutMs: number;
17
24
  maxConcurrency: number;
18
25
  analyzeFailureThreshold: number;
26
+ /**
27
+ * Extra remote hosts from top-level `allowed_hosts`, already lowercased.
28
+ * Omitted on hand-built configs; treated as none.
29
+ */
30
+ allowedHosts?: readonly string[];
19
31
  projects: AutoSyncProjectConfig[];
20
32
  }
21
33
  export type AutoSyncConfigLoadResult = {
@@ -30,12 +42,12 @@ export declare function getAutoSyncConfigPath(gitnexusDir?: string): string;
30
42
  export declare function parseBranchCandidates(branchValue: unknown): string[];
31
43
  export declare function loadAutoSyncConfig(configPath?: string): Promise<AutoSyncConfigLoadResult>;
32
44
  export declare function parseAutoSyncConfig(content: string, configPath: string): AutoSyncConfig;
33
- export declare function parseAutoSyncRemoteIdentity(remoteUrl: string): {
45
+ export declare function parseAutoSyncRemoteIdentity(remoteUrl: string, allowedHosts?: readonly string[]): {
34
46
  host: string;
35
47
  repoPath: string;
36
48
  };
37
49
  /** Canonical `host/owner/repo` key. Strips one trailing `.git`. Throws on an invalid remote. */
38
- export declare function getAutoSyncRepoIdentity(remoteUrl: string): string;
39
- export declare function validateAutoSyncRemoteUrl(remoteUrl: string): void;
50
+ export declare function getAutoSyncRepoIdentity(remoteUrl: string, allowedHosts?: readonly string[]): string;
51
+ export declare function validateAutoSyncRemoteUrl(remoteUrl: string, allowedHosts?: readonly string[]): void;
40
52
  export declare function validateAutoSyncBranchName(branch: string): void;
41
53
  export declare function parseDurationMs(value: unknown): number;
@@ -14,7 +14,69 @@ const DEFAULT_REPO_GIT_TIMEOUT_MS = 10_000;
14
14
  const DEFAULT_MAX_CONCURRENCY = 1;
15
15
  export const DEFAULT_ANALYZE_FAILURE_THRESHOLD = 3;
16
16
  const MIN_ANALYZE_FAILURE_THRESHOLD = 2;
17
- const ALLOWED_REMOTE_HOSTS = new Set(['github.com', 'gitlab.com', 'gitee.com']);
17
+ const BUILTIN_REMOTE_HOSTS = new Set(['github.com', 'gitlab.com', 'gitee.com']);
18
+ // Exact DNS names only. The host is a directory under local_path, so wildcards,
19
+ // ports, and path characters stay out. A label is 1-63 chars and cannot start
20
+ // or end with a hyphen; the whole name is at most 253 characters.
21
+ // One trailing dot is stripped before this runs: it marks an absolute lookup,
22
+ // it is not a different host.
23
+ const AUTO_SYNC_HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
24
+ /** Lowercase, and drop one trailing root dot so `git.` and `git` are one host. */
25
+ function canonicalAutoSyncHost(host) {
26
+ return host.trim().toLowerCase().replace(/\.$/, '');
27
+ }
28
+ function isStrictDottedQuad(host) {
29
+ const labels = host.split('.');
30
+ if (labels.length !== 4)
31
+ return false;
32
+ return labels.every((label) => /^(0|[1-9]\d{0,2})$/.test(label) && Number(label) <= 255);
33
+ }
34
+ /**
35
+ * Spellings glibc inet_aton dials as a different address than the token
36
+ * (`192.168.1` → 192.168.0.1, `0x7f.0.0.1` / `2130706433` → 127.0.0.1).
37
+ * A strict four-octet address is the address written; listing it is opt-in.
38
+ */
39
+ function isAmbiguousNumericHost(host) {
40
+ const labels = host.split('.');
41
+ if (labels.some((label) => /^0x[0-9a-f]+$/i.test(label) || /^0\d/.test(label)))
42
+ return true;
43
+ return labels.every((label) => /^\d+$/.test(label)) && !isStrictDottedQuad(host);
44
+ }
45
+ function autoSyncHostProblem(host) {
46
+ if (!AUTO_SYNC_HOST_PATTERN.test(host))
47
+ return 'shape';
48
+ if (isAmbiguousNumericHost(host))
49
+ return 'numeric';
50
+ return null;
51
+ }
52
+ function autoSyncHostProblemMessage(problem) {
53
+ return problem === 'numeric'
54
+ ? 'must not use an ambiguous numeric spelling'
55
+ : 'must be a DNS hostname';
56
+ }
57
+ function rewriteAutoSyncRemoteHost(remoteUrl, mapHost) {
58
+ const ssh = /^(git@)([^:\s/]+)(:[^\s]+)$/.exec(remoteUrl);
59
+ if (ssh)
60
+ return `${ssh[1]}${mapHost(ssh[2])}${ssh[3]}`;
61
+ const https = /^(https:\/\/)([^/\s]+)(\/[^\s]+)$/.exec(remoteUrl);
62
+ if (https)
63
+ return `${https[1]}${mapHost(https[2])}${https[3]}`;
64
+ return remoteUrl;
65
+ }
66
+ /**
67
+ * Name git should resolve. A trailing dot forces an absolute lookup, so a
68
+ * search list cannot answer `git` as `git.<domain>` or retry an FQDN under
69
+ * that domain after NXDOMAIN. A strict IPv4 literal stays undotted: `10.0.0.1.`
70
+ * is a DNS name, not that address.
71
+ */
72
+ export function absoluteAutoSyncRemoteUrl(remoteUrl) {
73
+ return rewriteAutoSyncRemoteHost(remoteUrl.trim(), (host) => {
74
+ const canonical = canonicalAutoSyncHost(host);
75
+ if (isStrictDottedQuad(canonical))
76
+ return canonical;
77
+ return `${canonical}.`;
78
+ });
79
+ }
18
80
  /**
19
81
  * A single clone/pull must fit inside one sync interval and inside an hour.
20
82
  * This is also the guard for the unit slip the bare-number rule invites:
@@ -148,6 +210,7 @@ export function parseAutoSyncConfig(content, configPath) {
148
210
  analyzeFailureThreshold < MIN_ANALYZE_FAILURE_THRESHOLD) {
149
211
  errors.push(`analyze_failure_threshold must be an integer >= ${MIN_ANALYZE_FAILURE_THRESHOLD}`);
150
212
  }
213
+ const allowedHosts = parseAllowedAutoSyncHosts(raw.allowed_hosts, errors);
151
214
  const rawProjects = raw.projects;
152
215
  if (!Array.isArray(rawProjects) || rawProjects.length === 0) {
153
216
  errors.push('projects must contain at least one project');
@@ -180,7 +243,7 @@ export function parseAutoSyncConfig(content, configPath) {
180
243
  }
181
244
  for (let urlIndex = 0; urlIndex < remoteUrls.length; urlIndex += 1) {
182
245
  try {
183
- validateAutoSyncRemoteUrl(remoteUrls[urlIndex]);
246
+ validateAutoSyncRemoteUrl(remoteUrls[urlIndex], allowedHosts);
184
247
  }
185
248
  catch (err) {
186
249
  errors.push(`projects[${index}].remote_urls[${urlIndex}] ${err.message}`);
@@ -234,10 +297,39 @@ export function parseAutoSyncConfig(content, configPath) {
234
297
  analyzeTimeoutMs,
235
298
  maxConcurrency,
236
299
  analyzeFailureThreshold,
300
+ allowedHosts,
237
301
  projects,
238
302
  };
239
303
  }
240
- export function parseAutoSyncRemoteIdentity(remoteUrl) {
304
+ function parseAllowedAutoSyncHosts(value, errors) {
305
+ if (value === undefined)
306
+ return [];
307
+ if (!Array.isArray(value)) {
308
+ errors.push('allowed_hosts must be a list of DNS hostnames');
309
+ return [];
310
+ }
311
+ const hosts = [];
312
+ const seen = new Set();
313
+ for (let index = 0; index < value.length; index += 1) {
314
+ const entry = value[index];
315
+ if (typeof entry !== 'string') {
316
+ errors.push(`allowed_hosts[${index}] must be a DNS hostname`);
317
+ continue;
318
+ }
319
+ const host = canonicalAutoSyncHost(entry);
320
+ const problem = autoSyncHostProblem(host);
321
+ if (problem) {
322
+ errors.push(`allowed_hosts[${index}] ${autoSyncHostProblemMessage(problem)}`);
323
+ continue;
324
+ }
325
+ if (seen.has(host))
326
+ continue;
327
+ seen.add(host);
328
+ hosts.push(host);
329
+ }
330
+ return hosts;
331
+ }
332
+ export function parseAutoSyncRemoteIdentity(remoteUrl, allowedHosts) {
241
333
  const trimmed = remoteUrl.trim();
242
334
  if (trimmed.includes('?') || trimmed.includes('#')) {
243
335
  throw new Error('must not include query strings or fragments');
@@ -258,23 +350,38 @@ export function parseAutoSyncRemoteIdentity(remoteUrl) {
258
350
  }
259
351
  }
260
352
  else {
261
- throw new Error('must use an SSH or HTTPS URL on github.com, gitlab.com, or gitee.com');
353
+ throw new Error('must use an SSH or HTTPS URL (git@host:owner/repo or https://host/owner/repo)');
262
354
  }
263
- host = host.toLowerCase();
264
- assertAutoSyncRemotePath(host, repoPath);
355
+ host = canonicalAutoSyncHost(host);
356
+ assertAutoSyncRemotePath(host, repoPath, allowedHosts);
265
357
  return { host, repoPath };
266
358
  }
267
359
  /** Canonical `host/owner/repo` key. Strips one trailing `.git`. Throws on an invalid remote. */
268
- export function getAutoSyncRepoIdentity(remoteUrl) {
269
- const { host, repoPath } = parseAutoSyncRemoteIdentity(remoteUrl);
360
+ export function getAutoSyncRepoIdentity(remoteUrl, allowedHosts) {
361
+ const { host, repoPath } = parseAutoSyncRemoteIdentity(remoteUrl, allowedHosts);
270
362
  return `${host}/${repoPath.replace(/\.git$/i, '')}`;
271
363
  }
272
- export function validateAutoSyncRemoteUrl(remoteUrl) {
273
- parseAutoSyncRemoteIdentity(remoteUrl);
364
+ export function validateAutoSyncRemoteUrl(remoteUrl, allowedHosts) {
365
+ parseAutoSyncRemoteIdentity(remoteUrl, allowedHosts);
274
366
  }
275
- function assertAutoSyncRemotePath(host, repoPath) {
276
- if (!ALLOWED_REMOTE_HOSTS.has(host)) {
277
- throw new Error('host must be one of github.com, gitlab.com, or gitee.com');
367
+ function isPermittedAutoSyncHost(host, allowedHosts) {
368
+ if (BUILTIN_REMOTE_HOSTS.has(host))
369
+ return true;
370
+ if (!allowedHosts)
371
+ return false;
372
+ for (const entry of allowedHosts) {
373
+ if (canonicalAutoSyncHost(entry) === host)
374
+ return true;
375
+ }
376
+ return false;
377
+ }
378
+ function assertAutoSyncRemotePath(host, repoPath, allowedHosts) {
379
+ const problem = autoSyncHostProblem(host);
380
+ if (problem) {
381
+ throw new Error(`host ${autoSyncHostProblemMessage(problem)}`);
382
+ }
383
+ if (!isPermittedAutoSyncHost(host, allowedHosts)) {
384
+ throw new Error('host must be one of github.com, gitlab.com, or gitee.com, or listed in top-level allowed_hosts');
278
385
  }
279
386
  const pathParts = repoPath.split('/');
280
387
  // Every segment becomes a directory component: the namespace segments build
@@ -1 +1 @@
1
- export declare function extractRepoNameFromRemoteUrl(remoteUrl: string): string;
1
+ export declare function extractRepoNameFromRemoteUrl(remoteUrl: string, allowedHosts?: readonly string[]): string;
@@ -1,6 +1,6 @@
1
1
  import { extractRepoName } from '../../server/git-clone.js';
2
2
  import { validateAutoSyncRemoteUrl } from './config.js';
3
- export function extractRepoNameFromRemoteUrl(remoteUrl) {
4
- validateAutoSyncRemoteUrl(remoteUrl);
3
+ export function extractRepoNameFromRemoteUrl(remoteUrl, allowedHosts) {
4
+ validateAutoSyncRemoteUrl(remoteUrl, allowedHosts);
5
5
  return extractRepoName(remoteUrl);
6
6
  }
@@ -40,7 +40,7 @@ export declare function runAutoSyncOnce(config: AutoSyncConfig, options?: {
40
40
  signal?: AbortSignal;
41
41
  onAnalysisCancellationRequested?: () => void;
42
42
  }): Promise<AutoSyncRunResult>;
43
- export declare function getConfiguredRepoPath(project: Pick<AutoSyncProjectConfig, 'localPath'>, repoName: string, remoteUrl?: string): string;
43
+ export declare function getConfiguredRepoPath(project: Pick<AutoSyncProjectConfig, 'localPath'>, repoName: string, remoteUrl?: string, allowedHosts?: readonly string[]): string;
44
44
  export declare function addRepoToGroup(project: Pick<AutoSyncProjectConfig, 'groupName'>, groupPath: string, registryName?: string): Promise<boolean>;
45
45
  export { getAutoSyncRepoIdentity } from './config.js';
46
46
  export declare function syncGroupByName(groupName: string): Promise<void>;
@@ -86,6 +86,7 @@ export async function runAutoSyncOnce(config, options = {}) {
86
86
  repoName,
87
87
  targetDir,
88
88
  timeoutMs: config.repoGitTimeoutMs,
89
+ allowedHosts: config.allowedHosts,
89
90
  deps,
90
91
  logger,
91
92
  });
@@ -254,7 +255,7 @@ export async function runAutoSyncOnce(config, options = {}) {
254
255
  // on the documented branch-fallback path.
255
256
  const placement = await deps.resolveBranchPlacement(repoResult.targetDir, repoResult.branch);
256
257
  await deps.registerRepo(repoResult.targetDir, meta, {
257
- name: getAutoSyncRepoIdentity(repoResult.remoteUrl),
258
+ name: getAutoSyncRepoIdentity(repoResult.remoteUrl, config.allowedHosts),
258
259
  // Omitted rather than passed as undefined, so a primary index is
259
260
  // registered with the same option shape it had before this branch.
260
261
  ...(placement.branch ? { branch: placement.branch } : {}),
@@ -303,7 +304,7 @@ export async function runAutoSyncOnce(config, options = {}) {
303
304
  let groupMembershipOk = false;
304
305
  let membershipAdded = false;
305
306
  try {
306
- membershipAdded = await deps.addRepoToGroup(repoResult.project, getAutoSyncRepoIdentity(repoResult.remoteUrl), getAutoSyncRepoIdentity(repoResult.remoteUrl));
307
+ membershipAdded = await deps.addRepoToGroup(repoResult.project, getAutoSyncRepoIdentity(repoResult.remoteUrl, config.allowedHosts), getAutoSyncRepoIdentity(repoResult.remoteUrl, config.allowedHosts));
307
308
  groupMembershipOk = true;
308
309
  }
309
310
  catch (err) {
@@ -369,10 +370,10 @@ function isRetryableAnalyzeContention(err) {
369
370
  err.code === 'index-lock-timeout' &&
370
371
  err.retryable === true);
371
372
  }
372
- export function getConfiguredRepoPath(project, repoName, remoteUrl) {
373
+ export function getConfiguredRepoPath(project, repoName, remoteUrl, allowedHosts) {
373
374
  if (!remoteUrl)
374
375
  return path.resolve(project.localPath, repoName);
375
- const identity = getAutoSyncRepoIdentity(remoteUrl);
376
+ const identity = getAutoSyncRepoIdentity(remoteUrl, allowedHosts);
376
377
  return path.resolve(project.localPath, ...identity.split('/').slice(0, -1), repoName);
377
378
  }
378
379
  export async function addRepoToGroup(project, groupPath, registryName = groupPath) {
@@ -420,8 +421,8 @@ async function buildWorkItems(config, deps) {
420
421
  }
421
422
  for (const remoteUrl of project.remoteUrls) {
422
423
  try {
423
- const repoName = extractRepoNameFromRemoteUrl(remoteUrl);
424
- const targetDir = getConfiguredRepoPath({ localPath: cloneRoot.root }, repoName, remoteUrl);
424
+ const repoName = extractRepoNameFromRemoteUrl(remoteUrl, config.allowedHosts);
425
+ const targetDir = getConfiguredRepoPath({ localPath: cloneRoot.root }, repoName, remoteUrl, config.allowedHosts);
425
426
  const previous = targetOwners.get(targetDir);
426
427
  if (previous !== undefined) {
427
428
  throw new Error(`Duplicate auto-sync targetDir ${targetDir} for ${previous} and ${remoteUrl}`);
@@ -474,6 +475,9 @@ async function syncFirstAvailableBranch(input) {
474
475
  expectedRepoName: input.repoName,
475
476
  quarantineRoot: input.item.cloneRoot.quarantineRoot,
476
477
  allowAutoSyncSsh: true,
478
+ ...(input.allowedHosts && input.allowedHosts.length > 0
479
+ ? { autoSyncAllowedHosts: input.allowedHosts }
480
+ : {}),
477
481
  timeoutMs: input.timeoutMs,
478
482
  branch,
479
483
  overwriteLocalChanges: input.item.project.overwriteLocalChanges,
@@ -49,7 +49,18 @@ export interface CloneOrPullOptions {
49
49
  allowedCloneRoot?: string;
50
50
  expectedRepoName?: string;
51
51
  quarantineRoot?: string;
52
+ /**
53
+ * Auto-sync clone/pull. DNS names are stored with one trailing dot so a
54
+ * resolver search list cannot replace the allowlisted host. A strict IPv4
55
+ * literal is stored as written.
56
+ */
52
57
  allowAutoSyncSsh?: boolean;
58
+ /**
59
+ * Extra hosts from watch_config.yml `allowed_hosts`. Honored only together
60
+ * with `allowAutoSyncSsh`; built-in github.com, gitlab.com, and gitee.com
61
+ * stay allowed either way.
62
+ */
63
+ autoSyncAllowedHosts?: readonly string[];
53
64
  timeoutMs?: number;
54
65
  branch?: string;
55
66
  overwriteLocalChanges?: boolean;
@@ -14,7 +14,7 @@ import { branchSlug } from '../storage/branch-index.js';
14
14
  import { sanitizeRepoName, stripUrlCredentials } from '../storage/git.js';
15
15
  import { validateGitUrl } from '../core/net/url-guard.js';
16
16
  import { assertDirectoryOwnerAndPermissions, quarantineAutoSyncPartial, } from '../core/auto-sync/path-security.js';
17
- import { getAutoSyncRepoIdentity, validateAutoSyncRemoteUrl } from '../core/auto-sync/config.js';
17
+ import { absoluteAutoSyncRemoteUrl, getAutoSyncRepoIdentity, validateAutoSyncRemoteUrl, } from '../core/auto-sync/config.js';
18
18
  export { validateGitUrl };
19
19
  /**
20
20
  * Root directory for all cloned repositories. Targets must resolve inside this.
@@ -273,9 +273,9 @@ export function normalizeGitUrlForCompare(url) {
273
273
  }
274
274
  }
275
275
  /** Same allowlisted repo across SSH and HTTPS, ignoring a trailing `.git`. */
276
- function sameAllowlistedAutoSyncRepo(left, right) {
276
+ function sameAllowlistedAutoSyncRepo(left, right, allowedHosts) {
277
277
  try {
278
- return getAutoSyncRepoIdentity(left) === getAutoSyncRepoIdentity(right);
278
+ return (getAutoSyncRepoIdentity(left, allowedHosts) === getAutoSyncRepoIdentity(right, allowedHosts));
279
279
  }
280
280
  catch {
281
281
  return false;
@@ -477,9 +477,12 @@ export async function cloneOrPull(url, targetDir, onProgress, options) {
477
477
  // the code path where the repo was cloned. Now it runs unconditionally,
478
478
  // preventing SSRF / blocked-host bypasses even when targetDir already exists.
479
479
  if (options?.allowAutoSyncSsh)
480
- validateAutoSyncRemoteUrl(url);
480
+ validateAutoSyncRemoteUrl(url, options.autoSyncAllowedHosts);
481
481
  else
482
482
  validateGitUrl(url);
483
+ // Fetch uses remote.origin.url, so the absolute name has to be what is
484
+ // stored, not only the clone argv. Non-auto-sync clones keep the given URL.
485
+ const dialUrl = options?.allowAutoSyncSsh ? absoluteAutoSyncRemoteUrl(url) : url;
483
486
  await fs.mkdir(cloneRoot, { recursive: true });
484
487
  if (options?.allowedCloneRoot) {
485
488
  await assertDirectoryOwnerAndPermissions(cloneRoot);
@@ -510,22 +513,22 @@ export async function cloneOrPull(url, targetDir, onProgress, options) {
510
513
  await assertPostRealpathContainment(cloneRoot, safeTarget);
511
514
  let originForCompare = originUrl;
512
515
  if (originUrl &&
513
- normalizeGitUrlForCompare(originUrl) !== normalizeGitUrlForCompare(url) &&
514
- sameAllowlistedAutoSyncRepo(originUrl, url)) {
515
- await runGit(['remote', 'set-url', 'origin', url], safeTarget, {
516
+ normalizeGitUrlForCompare(originUrl) !== normalizeGitUrlForCompare(dialUrl) &&
517
+ sameAllowlistedAutoSyncRepo(originUrl, url, options?.autoSyncAllowedHosts)) {
518
+ await runGit(['remote', 'set-url', 'origin', dialUrl], safeTarget, {
516
519
  timeoutMs: options?.timeoutMs,
517
520
  });
518
- originForCompare = url;
521
+ originForCompare = dialUrl;
519
522
  }
520
523
  // Confirm the existing clone is actually the same repository the caller
521
524
  // requested. Without this check, a pull would silently succeed against
522
525
  // whatever remote the dir was originally cloned from.
523
- await assertRemoteMatchesRequestedUrl(safeTarget, url, options?.timeoutMs, originForCompare ?? undefined);
526
+ await assertRemoteMatchesRequestedUrl(safeTarget, dialUrl, options?.timeoutMs, originForCompare ?? undefined);
524
527
  onProgress?.({ phase: 'pulling', message: 'Pulling latest changes...' });
525
528
  const runGitImpl = options?.runGitForTest ?? runGit;
526
529
  const gitOpts = {
527
530
  token: options?.token,
528
- url,
531
+ url: dialUrl,
529
532
  timeoutMs: options?.timeoutMs,
530
533
  };
531
534
  // Already at the requested pin? Then there is no switch to make, so do
@@ -595,11 +598,11 @@ export async function cloneOrPull(url, targetDir, onProgress, options) {
595
598
  try {
596
599
  const runGitImpl = options?.runGitForTest ?? runGit;
597
600
  const cloneArgs = options?.branch
598
- ? buildBranchCloneArgs(url, safeTarget, options.branch)
599
- : buildCloneArgs(url, safeTarget);
601
+ ? buildBranchCloneArgs(dialUrl, safeTarget, options.branch)
602
+ : buildCloneArgs(dialUrl, safeTarget);
600
603
  await runGitImpl(cloneArgs, undefined, {
601
604
  token: options?.token,
602
- url,
605
+ url: dialUrl,
603
606
  timeoutMs: options?.timeoutMs,
604
607
  });
605
608
  await assertPostRealpathContainment(cloneRoot, safeTarget);
@@ -696,7 +699,8 @@ function resolveGitCredential(options) {
696
699
  return undefined;
697
700
  let host;
698
701
  try {
699
- host = new URL(url).hostname.toLowerCase();
702
+ // One trailing dot is the absolute-lookup marker, same host (`github.com.`).
703
+ host = new URL(url).hostname.toLowerCase().replace(/\.$/, '');
700
704
  }
701
705
  catch {
702
706
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.6.13-rc.42",
3
+ "version": "1.6.13-rc.43",
4
4
  "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
5
  "author": "Abhigyan Patwari",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",