refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
84
vendor/laravel/agent-detector/src/AgentDetector.php
vendored
Normal file
84
vendor/laravel/agent-detector/src/AgentDetector.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\AgentDetector;
|
||||
|
||||
class AgentDetector
|
||||
{
|
||||
public const AGENT_ENV_VARS = [
|
||||
'CURSOR_AGENT' => KnownAgent::Cursor,
|
||||
'GEMINI_CLI' => KnownAgent::Gemini,
|
||||
'CODEX_SANDBOX' => KnownAgent::Codex,
|
||||
'CODEX_CI' => KnownAgent::Codex,
|
||||
'CODEX_THREAD_ID' => KnownAgent::Codex,
|
||||
'AUGMENT_AGENT' => KnownAgent::AugmentCli,
|
||||
'OPENCODE_CLIENT' => KnownAgent::Opencode,
|
||||
'OPENCODE' => KnownAgent::Opencode,
|
||||
'AMP_CURRENT_THREAD_ID' => KnownAgent::Amp,
|
||||
'CLAUDECODE' => KnownAgent::Claude,
|
||||
'CLAUDE_CODE' => KnownAgent::Claude,
|
||||
'REPL_ID' => KnownAgent::Replit,
|
||||
'COPILOT_MODEL' => KnownAgent::Copilot,
|
||||
'COPILOT_ALLOW_ALL' => KnownAgent::Copilot,
|
||||
'COPILOT_GITHUB_TOKEN' => KnownAgent::Copilot,
|
||||
'COPILOT_CLI' => KnownAgent::Copilot,
|
||||
'ANTIGRAVITY_AGENT' => KnownAgent::Antigravity,
|
||||
'PI_CODING_AGENT' => KnownAgent::Pi,
|
||||
'KIRO_AGENT_PATH' => KnownAgent::KiroCli,
|
||||
];
|
||||
|
||||
public static function detect(): AgentResult
|
||||
{
|
||||
return self::fromAiAgentEnvVar()
|
||||
?? self::fromKnownEnvVars()
|
||||
?? self::fromFileSystem()
|
||||
?? AgentResult::noAgent();
|
||||
}
|
||||
|
||||
protected static function fromAiAgentEnvVar(): ?AgentResult
|
||||
{
|
||||
$aiAgent = getenv('AI_AGENT');
|
||||
|
||||
if ($aiAgent === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aiAgent = trim($aiAgent);
|
||||
|
||||
if ($aiAgent === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return AgentResult::forAgent(match (true) {
|
||||
in_array($aiAgent, ['github-copilot', 'github-copilot-cli']) => KnownAgent::Copilot,
|
||||
str_starts_with($aiAgent, 'claude-code') => KnownAgent::Claude,
|
||||
default => $aiAgent,
|
||||
});
|
||||
}
|
||||
|
||||
protected static function fromKnownEnvVars(): ?AgentResult
|
||||
{
|
||||
foreach (self::AGENT_ENV_VARS as $envVar => $agent) {
|
||||
if (getenv($envVar) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return AgentResult::forAgent(match ($agent) {
|
||||
KnownAgent::Claude => getenv('CLAUDE_CODE_IS_COWORK') !== false ? KnownAgent::Cowork : KnownAgent::Claude,
|
||||
default => $agent,
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static function fromFileSystem(): ?AgentResult
|
||||
{
|
||||
if (file_exists('/opt/.devin')) {
|
||||
return AgentResult::forAgent(KnownAgent::Devin);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/agent-detector/src/AgentResult.php
vendored
Normal file
30
vendor/laravel/agent-detector/src/AgentResult.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\AgentDetector;
|
||||
|
||||
class AgentResult
|
||||
{
|
||||
public readonly bool $isAgent;
|
||||
|
||||
public function __construct(public readonly ?string $name = null)
|
||||
{
|
||||
$this->isAgent = $name !== null;
|
||||
}
|
||||
|
||||
public static function forAgent(KnownAgent|string $name): self
|
||||
{
|
||||
return new self($name instanceof KnownAgent ? $name->value : $name);
|
||||
}
|
||||
|
||||
public static function noAgent(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function knownAgent(): ?KnownAgent
|
||||
{
|
||||
return KnownAgent::tryFrom($this->name ?? '');
|
||||
}
|
||||
}
|
||||
34
vendor/laravel/agent-detector/src/KnownAgent.php
vendored
Normal file
34
vendor/laravel/agent-detector/src/KnownAgent.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\AgentDetector;
|
||||
|
||||
enum KnownAgent: string
|
||||
{
|
||||
case Cursor = 'cursor';
|
||||
case Claude = 'claude';
|
||||
case Cowork = 'cowork';
|
||||
case Devin = 'devin';
|
||||
case Replit = 'replit';
|
||||
case Gemini = 'gemini';
|
||||
case Codex = 'codex';
|
||||
case V0 = 'v0';
|
||||
case AugmentCli = 'augment-cli';
|
||||
case Opencode = 'opencode';
|
||||
case Amp = 'amp';
|
||||
case Copilot = 'copilot';
|
||||
case Antigravity = 'antigravity';
|
||||
case Pi = 'pi';
|
||||
case KiroCli = 'kiro-cli';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::AugmentCli => 'Augment CLI',
|
||||
self::KiroCli => 'Kiro CLI',
|
||||
self::V0 => 'v0',
|
||||
default => ucfirst($this->value),
|
||||
};
|
||||
}
|
||||
}
|
||||
10
vendor/laravel/agent-detector/src/functions.php
vendored
Normal file
10
vendor/laravel/agent-detector/src/functions.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\AgentDetector;
|
||||
|
||||
function detectAgent(): AgentResult
|
||||
{
|
||||
return AgentDetector::detect();
|
||||
}
|
||||
Reference in New Issue
Block a user