@rbbtsn0w/adg 0.7.0 → 0.7.1-beta.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.
|
@@ -16,6 +16,28 @@ const CLONE_TIMEOUT_MS = (() => {
|
|
|
16
16
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_CLONE_TIMEOUT_MS;
|
|
17
17
|
})();
|
|
18
18
|
const execFileAsync = promisify(execFile);
|
|
19
|
+
const UNSAFE_INHERITED_GIT_ENV_KEYS = [
|
|
20
|
+
'EDITOR',
|
|
21
|
+
'GIT_ASKPASS',
|
|
22
|
+
'GIT_CONFIG',
|
|
23
|
+
'GIT_CONFIG_COUNT',
|
|
24
|
+
'GIT_CONFIG_GLOBAL',
|
|
25
|
+
'GIT_CONFIG_PARAMETERS',
|
|
26
|
+
'GIT_CONFIG_SYSTEM',
|
|
27
|
+
'GIT_EDITOR',
|
|
28
|
+
'GIT_EXEC_PATH',
|
|
29
|
+
'GIT_EXTERNAL_DIFF',
|
|
30
|
+
'GIT_PAGER',
|
|
31
|
+
'GIT_PROXY_COMMAND',
|
|
32
|
+
'GIT_SEQUENCE_EDITOR',
|
|
33
|
+
'GIT_SSH',
|
|
34
|
+
'GIT_SSH_COMMAND',
|
|
35
|
+
'GIT_TEMPLATE_DIR',
|
|
36
|
+
'PAGER',
|
|
37
|
+
'PREFIX',
|
|
38
|
+
'SSH_ASKPASS',
|
|
39
|
+
];
|
|
40
|
+
const UNSAFE_INHERITED_GIT_ENV_KEY_SET = new Set(UNSAFE_INHERITED_GIT_ENV_KEYS.map((key) => key.toUpperCase()));
|
|
19
41
|
export class GitCloneError extends Error {
|
|
20
42
|
url;
|
|
21
43
|
isTimeout;
|
|
@@ -84,6 +106,30 @@ function isAuthFailure(message) {
|
|
|
84
106
|
message.includes('requested URL returned error: 403') ||
|
|
85
107
|
isGitHubSsoAuthError(message));
|
|
86
108
|
}
|
|
109
|
+
function createGitEnvironment(extraEnv) {
|
|
110
|
+
// ADG patch: hosts such as VS Code inject executable Git helpers (notably
|
|
111
|
+
// GIT_ASKPASS) even when the user has no GitHub account configured.
|
|
112
|
+
// simple-git correctly rejects those inherited hooks as unsafe, but that
|
|
113
|
+
// rejection happened before anonymous public-repository clones could run.
|
|
114
|
+
// Clone from a sanitized copy of the parent environment instead. Normal
|
|
115
|
+
// credential helpers, proxy settings, certificates, and SSH_AUTH_SOCK remain
|
|
116
|
+
// available; only environment entries that can execute or redirect Git are
|
|
117
|
+
// removed. Explicit ADG-controlled overrides are applied afterwards.
|
|
118
|
+
const gitEnv = { ...process.env };
|
|
119
|
+
for (const key of Object.keys(gitEnv)) {
|
|
120
|
+
if (UNSAFE_INHERITED_GIT_ENV_KEY_SET.has(key.toUpperCase())) {
|
|
121
|
+
delete gitEnv[key];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
...gitEnv,
|
|
126
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
127
|
+
// When git-lfs IS installed, tell it not to download LFS content during
|
|
128
|
+
// checkout. See #952 for context and empirical impact.
|
|
129
|
+
GIT_LFS_SKIP_SMUDGE: '1',
|
|
130
|
+
...extraEnv,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
87
133
|
function createGitClient(extraEnv) {
|
|
88
134
|
return simpleGit({
|
|
89
135
|
timeout: { block: CLONE_TIMEOUT_MS },
|
|
@@ -114,20 +160,16 @@ function createGitClient(extraEnv) {
|
|
|
114
160
|
// exactly the intent of the config above. See vendor/skills/PROVENANCE.md.
|
|
115
161
|
unsafe: {
|
|
116
162
|
allowUnsafeFilter: true,
|
|
163
|
+
// Only permits the fixed BatchMode command supplied by the HTTPS auth
|
|
164
|
+
// fallback below; inherited GIT_SSH_COMMAND is removed from gitEnv.
|
|
165
|
+
allowUnsafeSshCommand: true,
|
|
117
166
|
},
|
|
118
167
|
// ADG patch: env must be applied via `.env()`, not as a constructor option.
|
|
119
168
|
// simple-git's factory only reads baseDir/maxConcurrentProcesses/trimmed from
|
|
120
169
|
// the options object and silently drops `env`, so the GIT_TERMINAL_PROMPT /
|
|
121
170
|
// GIT_LFS_SKIP_SMUDGE / GIT_SSH_COMMAND overrides below never reached the
|
|
122
171
|
// spawned git before this. See vendor/skills/PROVENANCE.md.
|
|
123
|
-
}).env(
|
|
124
|
-
...process.env,
|
|
125
|
-
GIT_TERMINAL_PROMPT: '0',
|
|
126
|
-
// When git-lfs IS installed, tell it not to download LFS content during
|
|
127
|
-
// checkout. See #952 for context and empirical impact.
|
|
128
|
-
GIT_LFS_SKIP_SMUDGE: '1',
|
|
129
|
-
...extraEnv,
|
|
130
|
-
});
|
|
172
|
+
}).env(createGitEnvironment(extraEnv));
|
|
131
173
|
}
|
|
132
174
|
async function resetTempDir(dir) {
|
|
133
175
|
await rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
@@ -138,7 +180,7 @@ async function tryGhClone(repo, tempDir, ref) {
|
|
|
138
180
|
try {
|
|
139
181
|
const { stdout, stderr } = await execFileAsync('gh', ['auth', 'status', '-h', 'github.com'], {
|
|
140
182
|
timeout: 5000,
|
|
141
|
-
env:
|
|
183
|
+
env: createGitEnvironment(),
|
|
142
184
|
});
|
|
143
185
|
const statusOutput = `${stdout}${stderr}`;
|
|
144
186
|
if (/Git operations protocol:\s+ssh/i.test(statusOutput)) {
|
|
@@ -151,7 +193,7 @@ async function tryGhClone(repo, tempDir, ref) {
|
|
|
151
193
|
const gitFlags = ref ? ['--depth=1', '--branch', ref] : ['--depth=1'];
|
|
152
194
|
await execFileAsync('gh', ['repo', 'clone', cloneTarget, tempDir, '--', ...gitFlags], {
|
|
153
195
|
timeout: CLONE_TIMEOUT_MS,
|
|
154
|
-
env:
|
|
196
|
+
env: createGitEnvironment(),
|
|
155
197
|
});
|
|
156
198
|
return true;
|
|
157
199
|
}
|
|
@@ -209,7 +251,7 @@ export async function cloneRepo(url, ref) {
|
|
|
209
251
|
try {
|
|
210
252
|
await resetTempDir(tempDir);
|
|
211
253
|
await createGitClient({
|
|
212
|
-
GIT_SSH_COMMAND:
|
|
254
|
+
GIT_SSH_COMMAND: 'ssh -o BatchMode=yes',
|
|
213
255
|
}).clone(repo.sshUrl, tempDir, cloneOptions);
|
|
214
256
|
return tempDir;
|
|
215
257
|
}
|
package/package.json
CHANGED
|
@@ -76,6 +76,7 @@ re-vendoring. Each is marked inline with an `ADG patch:` comment.
|
|
|
76
76
|
| `src/git.ts` → `createGitClient` | Add `unsafe: { allowUnsafeFilter: true }` to `simpleGit(...)` | simple-git ≥3.36 blocks `filter.*.smudge/clean` configs (RCE vector) and fails **every** clone with "Configuring filter.smudge is not permitted without enabling allowUnsafeFilter". The configs here set the LFS filter to EMPTY (disabling it), so opting in is safe and matches their intent. |
|
|
77
77
|
| `src/git.ts` → `import simpleGit from 'simple-git'` | Default → named import `import { simpleGit } from 'simple-git'` | The default import is not callable under ADG's strict root tsconfig (NodeNext + verbatimModuleSyntax, no esModuleInterop); the named export is. Needed for `git.ts` to typecheck when a test imports it (e.g. via `use.ts`). |
|
|
78
78
|
| `src/git.ts` → `createGitClient` env | Pass env via `.env({...})` instead of as a `simpleGit(...)` constructor option | **Latent runtime bug**: simple-git's factory only reads `baseDir`/`maxConcurrentProcesses`/`config`/`trimmed`/plugins from the options object and silently drops `env`, so `GIT_TERMINAL_PROMPT`/`GIT_LFS_SKIP_SMUDGE`/`GIT_SSH_COMMAND` never reached the spawned git (it inherited the full parent env). `.env(object)` is the documented API and sets the executor env actually used at spawn. |
|
|
79
|
+
| `src/git.ts` → `createGitClient` inherited env sanitization | Case-insensitively remove executable/redirecting Git environment hooks and `GIT_CONFIG_PARAMETERS` before constructing the clone client; allow only ADG's fixed SSH BatchMode override | IDEs can inject `GIT_ASKPASS`, `GIT_PAGER`, config overrides, and similar helpers even for users with no GitHub account. simple-git >=3.36 rejects known hooks before an anonymous public clone can run, while mixed-case Windows keys or config parameters could bypass exact-key deletion. Sanitizing them preserves non-interactive public installs without opting arbitrary parent-process commands into execution. |
|
|
79
80
|
| `src/skills.ts` → `parseSkillMd` | Narrow `data.metadata` (frontmatter `unknown`) to `Record<string, unknown> \| undefined` before reading `.internal` / returning it | Behavior-preserving type fix so `skills.ts` typechecks under ADG's strict root tsconfig when reached via `use.ts`/tests. |
|
|
80
81
|
| `src/update.ts` → both `spawnSync` self-CLI re-invokes (+ new `src/self-cli.ts`) | Forward `process.execArgv`, call `skills add` instead of `add`, and wrap in OpenTelemetry CLIENT spans | The child process runs `adg skills add` inside the spawned Node context, ensuring type-stripping flags inherit properly, and OTel spans capture subprocess execution metadata. |
|
|
81
82
|
| `package.json` → `@vercel/detect-agent` dependency (not a vendored-source change) | `^0.1.0` → `^1.2.3` | `src/detect-agent.ts` (upstream, unpatched) imports `AgentResult` and expects `determineAgent(): Promise<AgentResult>` (object API). The stale `0.1.0` pin only exported `determineAgent(): Promise<string \| false>` and no `AgentResult`, which broke typecheck and left `cachedResult.isAgent` always `undefined` at runtime — agent auto-detection (non-interactive mode in `add`/`sync`/`remove`/`find`/`cli`) silently never fired. The `1.x` line restores the API the fork targets, so `detect-agent.ts` needs **no** local patch. Keep this dependency on `1.x` across re-vendoring. |
|