Commit graph

72 commits

Author SHA1 Message Date
b86714db6e Merge pull request 'docs: add PHPDoc to AgentDetection patterns' (#59) from docs/agent-detection-phpdoc into main
Some checks failed
CI / PHP 8.3 (push) Failing after 1m19s
CI / PHP 8.4 (push) Failing after 1m20s
Reviewed-on: #59
2026-02-23 12:04:17 +00:00
Claude
6cd9ca09d7
style: fix pint issues in ContentService and AgentToolRegistryTest
Some checks failed
CI / PHP 8.3 (push) Failing after 1m50s
CI / PHP 8.4 (push) Failing after 1m50s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:58:52 +00:00
darbs-claude
e47998bc15 docs: add PHPDoc to AgentDetection patterns
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m21s
CI / PHP 8.3 (pull_request) Failing after 1m23s
Document each PROVIDER_PATTERNS entry with real User-Agent examples,
add inline comments to BROWSER_INDICATORS and NON_AGENT_BOTS with
categorised UA examples, document MCP_TOKEN_HEADER with token format
details, and add class-level usage examples and detection priority
ordering.

Closes #31
Refs: DOC-001

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:56:57 +00:00
Claude
938081f2f5
fix: resolve 14 test failures across 3 test files
Some checks failed
CI / PHP 8.4 (push) Failing after 1m33s
CI / PHP 8.3 (push) Failing after 1m35s
ProcessContentTaskTest: set mock properties directly instead of
shouldReceive('__get') which doesn't reliably intercept property
access on Mockery mocks of non-existent classes.

HasStreamParsing: fix parseJSONStream chunked read bug where the
inner parse loop restarted at position 0 with stale state from
a previous partial parse. Track scan position across chunks.

AgentDetection: fix Postman regex \bPostman\b → \bPostman/ so it
matches PostmanRuntime (no word boundary between n and R).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:48:29 +00:00
5fa46104f4 Merge pull request 'fix: validate API keys on AgenticManager init' (#57) from fix/validate-api-keys-on-init into main
Some checks failed
CI / PHP 8.3 (push) Failing after 1m25s
CI / PHP 8.4 (push) Failing after 1m28s
Reviewed-on: #57
2026-02-23 11:41:12 +00:00
6b7a7ade15 Merge pull request 'fix: improve workspace context error messages' (#56) from fix/workspace-context-errors into main
Some checks failed
CI / PHP 8.3 (push) Failing after 1m29s
CI / PHP 8.4 (push) Failing after 1m27s
Reviewed-on: #56
2026-02-23 11:39:41 +00:00
968cbcdd63 Merge pull request 'fix: add batch failure recovery to ContentService' (#55) from fix/batch-failure-recovery into main
Some checks failed
CI / PHP 8.4 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
Reviewed-on: #55
2026-02-23 11:39:31 +00:00
f528f94d68 Merge pull request 'fix: add error handling to ClaudeService streaming' (#54) from fix/stream-error-handling into main
Some checks failed
CI / PHP 8.4 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
Reviewed-on: #54
2026-02-23 11:39:17 +00:00
8ade82587d Merge pull request 'perf: cache permitted tools per API key' (#53) from perf/cache-permitted-tools-per-api-key into main
Some checks failed
CI / PHP 8.4 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
Reviewed-on: #53
2026-02-23 11:39:06 +00:00
darbs-claude
c315fc43c6 fix: validate API keys on AgenticManager init (#29)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m47s
CI / PHP 8.4 (pull_request) Failing after 1m46s
Log a warning for each AI provider registered without an API key so
that misconfiguration is surfaced at boot time (not silently on the
first API call).  Each message names the environment variable to set:

  ANTHROPIC_API_KEY  – Claude
  GOOGLE_AI_API_KEY  – Gemini
  OPENAI_API_KEY     – OpenAI

Providers without a key remain registered but are marked unavailable
via isAvailable(), preserving backward compatibility.

- Add Log::warning() calls in registerProviders() for empty keys
- Extend AgenticManagerTest with a dedicated 'API key validation
  warnings' describe block (7 new test cases)
- Update DX-002 in TODO.md as resolved

Closes #29

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:39:01 +00:00
ff34ede167 Merge pull request 'perf: optimize AgentPhase dependency checking with batch query' (#52) from perf/optimize-agent-phase-dependency-checking into main
Some checks failed
CI / PHP 8.4 (push) Has been cancelled
CI / PHP 8.3 (push) Has been cancelled
Reviewed-on: #52
2026-02-23 11:38:54 +00:00
darbs-claude
6748e6cd84 fix: improve workspace context error messages (closes #28)
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m39s
CI / PHP 8.3 (pull_request) Failing after 1m42s
Updated workspace_id error messages in all MCP tools to include
actionable guidance and a documentation link. Affected tools:
PlanCreate, PlanGet, PlanList, StateSet, StateGet, StateList,
SessionStart.

Resolves DX-001 from TODO.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:28:32 +00:00
darbs-claude
78bdebcaaa fix: add batch failure recovery to ContentService (#27)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m24s
CI / PHP 8.4 (pull_request) Failing after 1m27s
- Track progress in a per-batch JSON state file after each article so
  a mid-run crash leaves a recoverable checkpoint
- Add `maxRetries` parameter to generateBatch() with per-article retry
  loop (default: 1 extra attempt)
- Add `resumeBatch()` to re-process only failed/pending articles,
  skipping those already successfully generated in a prior run
- Add `loadBatchProgress()` public method for inspecting state
- State stores per-article status, attempt counts, error messages,
  and timestamps for full observability

Tests: 6 new scenarios covering state persistence, resume capability,
retry logic, and the no-state error case

Closes #27

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:17:56 +00:00
darbs-claude
77e4ae6bad fix: add error handling to ClaudeService streaming (#26)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m53s
CI / PHP 8.4 (pull_request) Failing after 1m52s
Wrap stream() in try/catch to prevent silent failures.
On exception, log the error and yield a structured error event:
  ['type' => 'error', 'message' => string]

Adds tests for connection errors, runtime exceptions, error event
format, and Log::error invocation. Closes ERR-001 in TODO.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 11:04:07 +00:00
darbs-claude
a352f697a9 perf: cache permitted tools per API key (closes #24)
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m23s
CI / PHP 8.3 (pull_request) Failing after 1m27s
Cache the list of permitted tool names in `AgentToolRegistry::forApiKey()`
using a 1-hour TTL to avoid O(n) filtering on every request (PERF-002).

- Add `Cache::remember()` in `forApiKey()` storing tool names keyed by API
  key ID (`agent_tool_registry:api_key:{id}`)
- Add `flushCacheForApiKey(int|string $id)` for explicit invalidation
- Add `CACHE_TTL` constant (3600 s) for easy tuning
- Invalidate cache in `AgentApiKeyService::updatePermissions()` and `revoke()`
  so permission changes take effect immediately
- Add `tests/Unit/AgentToolRegistryTest.php` covering cache hit/miss,
  per-key isolation, scope filtering, TTL constant, and flush behaviour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 10:54:12 +00:00
darbs-claude
909c2da6df perf: replace N+1 find() with whereIn batch lookup in checkDependencies()
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m48s
CI / PHP 8.3 (pull_request) Failing after 2m0s
Resolves #23

- Replace per-dependency `AgentPhase::find()` loop with a single
  `AgentPhase::whereIn('id', $dependencies)->get()` call, reducing
  query count from N to 1 for any number of dependencies
- Short-circuit early when dependencies list is empty to avoid
  unnecessary query at all
- Add tests: empty deps, skipped-dep passthrough, single-query
  assertion, blocker shape validation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 10:40:00 +00:00
Claude
fcdeace290
ci: retrigger
Some checks failed
CI / PHP 8.3 (push) Failing after 2m2s
CI / PHP 8.4 (push) Failing after 2m1s
2026-02-23 07:09:43 +00:00
Claude
d88095780e
fix: use closure-based __get for mock property access
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Replace individual __get expectations with a single closure that handles
all property access. Fixes ErrorException on undefined property access
with Mockery mocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 07:02:04 +00:00
Claude
f2f27ec766 style: fix pint code style issues
Some checks failed
CI / PHP 8.3 (push) Failing after 2m8s
CI / PHP 8.4 (push) Failing after 1m58s
2026-02-23 06:42:24 +00:00
db0cc0abad Merge pull request 'fix: add missing database indexes' (#51) from fix/add-missing-indexes into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #51
2026-02-23 06:38:15 +00:00
darbs-claude
764728759d fix: add missing database indexes (closes #21)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m36s
CI / PHP 8.4 (pull_request) Failing after 1m41s
- Verify agent_sessions.session_id: unique() constraint creates an
  implicit unique index (agent_sessions_session_id_unique) which is
  sufficient for string lookups; no additional index required
- Drop redundant agent_plans_slug_index: the unique() constraint on
  slug already provides agent_plans_slug_unique covering all lookups
- Add compound (workspace_id, slug) index on agent_plans for the
  common routing pattern WHERE workspace_id = ? AND slug = ?
- Verify agent_workspace_states.key: already indexed via ->index('key')
  in migration 000003; no additional index required
- Mark DB-002 as resolved in TODO.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:29:14 +00:00
Claude
2f3314a418
Merge branch 'main' of ssh://forge.lthn.ai:2223/core/php-agentic
Some checks failed
CI / PHP 8.3 (push) Failing after 1m36s
CI / PHP 8.4 (push) Failing after 1m39s
2026-02-23 06:26:58 +00:00
Claude
769c888d74 ci: run unit tests only (feature tests need full app) 2026-02-23 06:26:41 +00:00
00a7e2f4ef Merge pull request 'refactor: namespace cache keys to prevent collisions' (#50) from refactor/namespace-cache-keys into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #50
2026-02-23 06:21:34 +00:00
Claude
e0f9a87673 test: fix TestCase to use Orchestra Testbench for CI
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
2026-02-23 06:20:06 +00:00
darbs-claude
7fba0955e4 refactor: namespace cache keys to prevent collisions (closes #20)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m35s
CI / PHP 8.4 (pull_request) Failing after 1m31s
Replace hardcoded cache key in ForAgentsController with a config-based
key (`mcp.cache.for_agents_key`) and configurable TTL
(`mcp.cache.for_agents_ttl`). This prevents collisions with other modules
or packages that might use the same flat cache key.

- Add `cacheKey()` method on ForAgentsController, reads from config
- Add `cache` section to config.php with default key and TTL
- Dynamic Cache-Control max-age now follows the configured TTL
- Add ForAgentsControllerTest covering key customisation,
  cache storage, invalidation, TTL, and response structure

Refs: TODO.md CQ-003

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:18:30 +00:00
Claude
c6e52bd74c test: fix TestCase to use Orchestra Testbench for CI 2026-02-23 06:18:30 +00:00
b75b1b8191 Merge pull request 'refactor: unify ApiKeyManager to use AgentApiKey model' (#49) from refactor/api-key-manager-model into main
Some checks failed
CI / PHP 8.3 (push) Has been cancelled
CI / PHP 8.4 (push) Has been cancelled
Reviewed-on: #49
2026-02-23 06:10:45 +00:00
48547dc214 Merge pull request 'test: add job tests for BatchContentGeneration and ProcessContentTask' (#41) from test/job-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #41
2026-02-23 06:09:51 +00:00
411d7decac Merge pull request 'refactor(jobs): remove processOutput stub from ProcessContentTask' (#47) from refactor/remove-process-content-task-stub into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #47
2026-02-23 06:09:22 +00:00
darbs-claude
6ebd527204 refactor: unify ApiKeyManager to use AgentApiKey model (#19)
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m35s
CI / PHP 8.3 (pull_request) Failing after 1m46s
Switch View/Modal/Admin/ApiKeyManager.php from Core\Api\Models\ApiKey
to Core\Mod\Agentic\Models\AgentApiKey and AgentApiKeyService, bringing
the workspace-owner admin UI into consistency with all other services.

Changes:
- Replace Core\Api\Models\ApiKey import with AgentApiKey + AgentApiKeyService
- Use AgentApiKeyService::create() for key generation
- Use AgentApiKey::forWorkspace() scoping in revokeKey() and render()
- Rename newKeyScopes → newKeyPermissions, toggleScope → togglePermission
- Expose availablePermissions() from AgentApiKey for the create form
- Update blade template: permissions field, getMaskedKey(), togglePermission,
  dynamic permission checkboxes from AgentApiKey::availablePermissions()
- Add tests/Feature/ApiKeyManagerTest.php with integration coverage
- Mark CQ-002 resolved in TODO.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 06:09:05 +00:00
c4af06bc02 Merge pull request 'refactor: add Builder return types to all Eloquent query scopes' (#46) from refactor/scope-return-types into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #46
2026-02-23 06:09:01 +00:00
f97d862f27 Merge pull request 'test: add PromptVersion model tests' (#45) from test/prompt-version-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #45
2026-02-23 06:08:50 +00:00
075aa05ee4 Merge pull request 'test: add AgentDetection service unit tests' (#44) from test/agent-detection-service into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #44
2026-02-23 06:08:40 +00:00
143aee7d42 Merge pull request 'test: add unit tests for HasRetry and HasStreamParsing traits' (#43) from test/service-trait-concerns into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #43
2026-02-23 06:08:25 +00:00
3c65e99727 Merge pull request 'test: add Livewire component tests for 12 admin components' (#42) from test/livewire-component-tests into main
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Reviewed-on: #42
2026-02-23 06:08:10 +00:00
Claude
d58222cf81 ci: v5 trigger
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
2026-02-23 05:56:05 +00:00
Claude
ae2fdc39dc ci: retrigger workflow
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
2026-02-23 05:48:46 +00:00
Claude
004fee2100 ci: add composer config for path repositories (v5)
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
2026-02-23 05:45:55 +00:00
darbs-claude
003c16c1cd refactor(jobs): remove processOutput stub from ProcessContentTask
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m1s
CI / PHP 8.4 (pull_request) Failing after 59s
The processOutput() method was a stub with no implementation. The
ContentProcessingService dependency it accepted is from the external
host-uk/core package and its API is not available here. Content
is already persisted via markCompleted() so no output processing
was ever performed.

Removes:
- processOutput() stub method
- ContentProcessingService import and handle() parameter
- target_type/target_id guard block that called the stub

Adds unit tests covering: prompt validation, entitlement checks,
provider availability, task completion metadata, usage recording,
and template variable interpolation.

Closes #17

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 05:45:46 +00:00
darbs-claude
2bc17efa47 refactor: add Builder return types to all Eloquent query scopes
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 1m11s
CI / PHP 8.4 (pull_request) Failing after 1m2s
Add `Builder $query` parameter type and `: Builder` return type to
18 query scopes across 8 model files. Import `Illuminate\Database\Eloquent\Builder`
in each affected model.

Affected models: Task, AgentSession, AgentApiKey, AgentPhase, AgentPlan,
Prompt, AgentWorkspaceState, WorkspaceState.

Closes #16

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 05:32:38 +00:00
Claude
9e142f79af
fix(ci): hard-code sister package clone instead of PHP parsing
Some checks failed
CI / PHP 8.3 (push) Failing after 57s
CI / PHP 8.4 (push) Failing after 56s
Direct git clone of ../php-framework avoids shell escaping
issues with dynamic PHP-based path extraction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 05:31:47 +00:00
Claude
52b4ee42d2
fix(ci): use single-quoted PHP to avoid shell escaping issues
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
Switch php -r argument to single quotes so PHP dollar signs
are not interpreted by bash. Pipe output to while-read loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 05:24:29 +00:00
Claude
478e0b8009
fix(ci): correct bash escaping in dependency checkout step
Some checks are pending
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
The PHP variables inside php -r need \$ escaping, but shell
variables outside need bare $ for command substitution and
variable expansion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 05:19:20 +00:00
darbs-claude
1abc4af519 test: add PromptVersion model tests
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 56s
CI / PHP 8.4 (pull_request) Failing after 58s
Add Feature test covering PromptVersion creation, relationships (prompt,
creator), restore() rollback method, and version history tracking. Also
add idempotent migration for prompts and prompt_versions tables required
by the test suite.

Closes #15
2026-02-23 05:18:37 +00:00
Claude
5fc54516bf
ci: inline workflow to bypass reusable workflow cache
Some checks failed
CI / PHP 8.4 (push) Waiting to run
CI / PHP 8.3 (push) Has been cancelled
The Forgejo act runner caches reusable workflow definitions,
preventing updates from being picked up. Inline the workflow
with dependency checkout step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 05:11:52 +00:00
Claude
d1d28d7bd6
ci: trigger rebuild with fixed reusable workflow
Some checks failed
CI / tests (push) Failing after 1m17s
The reusable php-test.yml now detects pest/phpunit/pint availability
and clones path dependencies using the runner token.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 04:57:18 +00:00
Claude
3f905583a8
chore: fix pint code style and add test config
Some checks failed
CI / tests (push) Failing after 1m9s
Add phpunit.xml for standalone test execution.
Apply Laravel Pint formatting fixes across all source files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 03:50:09 +00:00
darbs-claude
964d6cdeb3 test: add AgentDetection service unit tests
Some checks failed
CI / tests (pull_request) Failing after 1m1s
Adds tests/Unit/AgentDetectionTest.php covering:
- User-Agent pattern matching for all AI providers (Anthropic, OpenAI,
  Google, Meta, Mistral) with model detection
- Browser UA detection returning notAnAgent (Chrome, Firefox, Safari, Edge)
- Non-agent bot detection (Googlebot, Bingbot, curl, python-requests, etc.)
- Edge cases: null, empty, whitespace-only, and generic programmatic UAs
- Structured MCP token parsing (provider:model:secret format)
- MCP header priority over User-Agent in HTTP requests
- Provider validation via isValidProvider() and getValidProviders()
- isAgentUserAgent() shorthand behaviour
- Each pattern documented with real-world UA examples

Closes #13

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 01:40:47 +00:00
darbs-claude
9c50d29c19 test: add unit tests for HasRetry and HasStreamParsing traits (#12)
Some checks failed
CI / tests (pull_request) Failing after 1m8s
- tests/Unit/Concerns/HasRetryTest.php: covers withRetry success paths,
  max retry limits, non-retryable 4xx errors, exponential backoff with
  sleep verification, Retry-After header, and calculateDelay formula
- tests/Unit/Concerns/HasStreamParsingTest.php: covers parseSSEStream
  (basic extraction, [DONE] termination, line-type skipping, invalid
  JSON, chunked reads) and parseJSONStream (single/multiple objects,
  nesting, escaped strings, extractor filtering, chunked reads)

Closes #12

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 01:28:07 +00:00