@nomicfoundation/hardhat-utils 4.1.5 → 4.1.6
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/CHANGELOG.md +6 -0
- package/dist/src/environment.d.ts +39 -0
- package/dist/src/environment.d.ts.map +1 -0
- package/dist/src/environment.js +48 -0
- package/dist/src/environment.js.map +1 -0
- package/package.json +2 -1
- package/src/environment.ts +76 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 4.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#8429](https://github.com/NomicFoundation/hardhat/pull/8429) [`448a980`](https://github.com/NomicFoundation/hardhat/commit/448a9807c962eb02ed81e7ddce2718a0399f2335) Thanks [@marianfe](https://github.com/marianfe)! - Add `detectAgentEnvironment` and `isInteractive` utils
|
|
8
|
+
|
|
3
9
|
## 4.1.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The result of detecting whether the current process is running inside an
|
|
3
|
+
* AI coding agent environment.
|
|
4
|
+
*/
|
|
5
|
+
export interface AgentEnvironment {
|
|
6
|
+
/**
|
|
7
|
+
* True if at least one agent environment was detected.
|
|
8
|
+
*/
|
|
9
|
+
isAgent: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The identifiers of every detected agent, deduplicated.
|
|
12
|
+
*
|
|
13
|
+
* More than one agent can be reported at the same time, as agent sessions
|
|
14
|
+
* can be nested.
|
|
15
|
+
*/
|
|
16
|
+
agents: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Detects whether the current process is running inside an AI coding agent
|
|
20
|
+
* environment, based on the environment variables that those tools set in
|
|
21
|
+
* the shells they spawn.
|
|
22
|
+
*
|
|
23
|
+
* Currently supported: Claude Code and Codex. Other agents that advertise
|
|
24
|
+
* themselves via the generic `AI_AGENT` variable are reported as "unknown".
|
|
25
|
+
*
|
|
26
|
+
* @returns The detected agent environment.
|
|
27
|
+
*/
|
|
28
|
+
export declare function detectAgentEnvironment(): AgentEnvironment;
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether the current process is running interactively, meaning both
|
|
31
|
+
* stdin and stdout are TTYs.
|
|
32
|
+
*
|
|
33
|
+
* This is orthogonal to agent detection, but can be a useful hint of whether
|
|
34
|
+
* the process is running in an automated environment.
|
|
35
|
+
*
|
|
36
|
+
* @returns True if the current process is running interactively.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isInteractive(): boolean;
|
|
39
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAiCzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the current process is running inside an AI coding agent
|
|
3
|
+
* environment, based on the environment variables that those tools set in
|
|
4
|
+
* the shells they spawn.
|
|
5
|
+
*
|
|
6
|
+
* Currently supported: Claude Code and Codex. Other agents that advertise
|
|
7
|
+
* themselves via the generic `AI_AGENT` variable are reported as "unknown".
|
|
8
|
+
*
|
|
9
|
+
* @returns The detected agent environment.
|
|
10
|
+
*/
|
|
11
|
+
export function detectAgentEnvironment() {
|
|
12
|
+
const env = process.env;
|
|
13
|
+
const detectedAgents = [];
|
|
14
|
+
// Claude Code sets these in every shell command it runs
|
|
15
|
+
if (env.CLAUDECODE !== undefined ||
|
|
16
|
+
env.CLAUDE_CODE_ENTRYPOINT !== undefined) {
|
|
17
|
+
detectedAgents.push("claude-code");
|
|
18
|
+
}
|
|
19
|
+
// Codex sets these in the shells it spawns
|
|
20
|
+
if (env.CODEX_THREAD_ID !== undefined ||
|
|
21
|
+
env.CODEX_CI !== undefined ||
|
|
22
|
+
env.CODEX_SANDBOX_NETWORK_DISABLED !== undefined) {
|
|
23
|
+
detectedAgents.push("codex");
|
|
24
|
+
}
|
|
25
|
+
// Generic marker set by some agents alongside their own variables (e.g.
|
|
26
|
+
// Claude Code sets `AI_AGENT=claude-code_<version>_agent`). It is only
|
|
27
|
+
// reported when no known agent matched, to avoid double counting
|
|
28
|
+
if (detectedAgents.length === 0 && env.AI_AGENT !== undefined) {
|
|
29
|
+
detectedAgents.push("unknown");
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
isAgent: detectedAgents.length > 0,
|
|
33
|
+
agents: detectedAgents,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether the current process is running interactively, meaning both
|
|
38
|
+
* stdin and stdout are TTYs.
|
|
39
|
+
*
|
|
40
|
+
* This is orthogonal to agent detection, but can be a useful hint of whether
|
|
41
|
+
* the process is running in an automated environment.
|
|
42
|
+
*
|
|
43
|
+
* @returns True if the current process is running interactively.
|
|
44
|
+
*/
|
|
45
|
+
export function isInteractive() {
|
|
46
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/environment.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAExB,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,wDAAwD;IACxD,IACE,GAAG,CAAC,UAAU,KAAK,SAAS;QAC5B,GAAG,CAAC,sBAAsB,KAAK,SAAS,EACxC,CAAC;QACD,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;IAED,2CAA2C;IAC3C,IACE,GAAG,CAAC,eAAe,KAAK,SAAS;QACjC,GAAG,CAAC,QAAQ,KAAK,SAAS;QAC1B,GAAG,CAAC,8BAA8B,KAAK,SAAS,EAChD,CAAC;QACD,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,wEAAwE;IACxE,uEAAuE;IACvE,iEAAiE;IACjE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC9D,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IAED,OAAO;QACL,OAAO,EAAE,cAAc,CAAC,MAAM,GAAG,CAAC;QAClC,MAAM,EAAE,cAAc;KACvB,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC;AACvE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.6",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/NomicFoundation/hardhat/tree/main/packages/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"./date": "./dist/src/date.js",
|
|
22
22
|
"./debug": "./dist/src/debug.js",
|
|
23
23
|
"./env": "./dist/src/env.js",
|
|
24
|
+
"./environment": "./dist/src/environment.js",
|
|
24
25
|
"./error": "./dist/src/error.js",
|
|
25
26
|
"./eth": "./dist/src/eth.js",
|
|
26
27
|
"./fast-semver": "./dist/src/fast-semver.js",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The result of detecting whether the current process is running inside an
|
|
3
|
+
* AI coding agent environment.
|
|
4
|
+
*/
|
|
5
|
+
export interface AgentEnvironment {
|
|
6
|
+
/**
|
|
7
|
+
* True if at least one agent environment was detected.
|
|
8
|
+
*/
|
|
9
|
+
isAgent: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The identifiers of every detected agent, deduplicated.
|
|
13
|
+
*
|
|
14
|
+
* More than one agent can be reported at the same time, as agent sessions
|
|
15
|
+
* can be nested.
|
|
16
|
+
*/
|
|
17
|
+
agents: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Detects whether the current process is running inside an AI coding agent
|
|
22
|
+
* environment, based on the environment variables that those tools set in
|
|
23
|
+
* the shells they spawn.
|
|
24
|
+
*
|
|
25
|
+
* Currently supported: Claude Code and Codex. Other agents that advertise
|
|
26
|
+
* themselves via the generic `AI_AGENT` variable are reported as "unknown".
|
|
27
|
+
*
|
|
28
|
+
* @returns The detected agent environment.
|
|
29
|
+
*/
|
|
30
|
+
export function detectAgentEnvironment(): AgentEnvironment {
|
|
31
|
+
const env = process.env;
|
|
32
|
+
|
|
33
|
+
const detectedAgents: string[] = [];
|
|
34
|
+
|
|
35
|
+
// Claude Code sets these in every shell command it runs
|
|
36
|
+
if (
|
|
37
|
+
env.CLAUDECODE !== undefined ||
|
|
38
|
+
env.CLAUDE_CODE_ENTRYPOINT !== undefined
|
|
39
|
+
) {
|
|
40
|
+
detectedAgents.push("claude-code");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Codex sets these in the shells it spawns
|
|
44
|
+
if (
|
|
45
|
+
env.CODEX_THREAD_ID !== undefined ||
|
|
46
|
+
env.CODEX_CI !== undefined ||
|
|
47
|
+
env.CODEX_SANDBOX_NETWORK_DISABLED !== undefined
|
|
48
|
+
) {
|
|
49
|
+
detectedAgents.push("codex");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Generic marker set by some agents alongside their own variables (e.g.
|
|
53
|
+
// Claude Code sets `AI_AGENT=claude-code_<version>_agent`). It is only
|
|
54
|
+
// reported when no known agent matched, to avoid double counting
|
|
55
|
+
if (detectedAgents.length === 0 && env.AI_AGENT !== undefined) {
|
|
56
|
+
detectedAgents.push("unknown");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
isAgent: detectedAgents.length > 0,
|
|
61
|
+
agents: detectedAgents,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether the current process is running interactively, meaning both
|
|
67
|
+
* stdin and stdout are TTYs.
|
|
68
|
+
*
|
|
69
|
+
* This is orthogonal to agent detection, but can be a useful hint of whether
|
|
70
|
+
* the process is running in an automated environment.
|
|
71
|
+
*
|
|
72
|
+
* @returns True if the current process is running interactively.
|
|
73
|
+
*/
|
|
74
|
+
export function isInteractive(): boolean {
|
|
75
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
76
|
+
}
|