Search by

voku / agent-graph

voku

Deterministic SQLite graph indexing and shared SQLite runtime support for coding-agent tooling.

Package info

github.com/voku/agent-graph

pkg:composer/voku/agent-graph

Statistics

Installs: 103 390

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 1

0.3.3 2026-11-18 22:31 UTC

README

Your coding agent's code graph should give the same answer twice and fail closed on a database it cannot trust. agent-graph is a small, deterministic SQLite graph index for PHP coding-agent tools that does exactly that, without loading the whole graph into memory.

You get:

  • Same input, same answers. Relation and target order are preserved; neighbours and bounded, cycle-safe traversal are deterministic, and scripts/compare-benchmark.sh fails when a change alters any query-result checksum.
  • Fail-closed reads. GraphStore::openReadOnly() rejects a missing database, missing graph tables or a schema version other than the current one, and never modifies the file; every graph records the owner's source revision and fingerprint so a stale graph can be detected.
  • Verified vector runtime. A pinned sqlite-vec v0.1.9 loadable extension for Linux x86_64 and arm64, resolved only after its SHA-256 matches the bundled manifest (null on other platforms). An explicit AGENT_GRAPH_SQLITE_VEC override path is used as given, without those checks.

Part of Agent Loop — a deterministic, local-first workflow for coding agents: approved Contracts, explicit next actions, evidence before "done". This package owns domain-neutral graph storage/query mechanics and the shared SQLite runtime assets used by agent-map (code relations) and agent-learning (learning lineage).

Quickstart

composer require voku/agent-graph

Requires PHP 8.2 or newer (composer.json: php >=8.2) and the pdo and pdo_sqlite extensions, which composer.json declares because the store opens SQLite through PDO.

<?php

require __DIR__ . '/vendor/autoload.php';

use voku\AgentGraph\Graph\GraphRelation;
use voku\AgentGraph\Graph\TraversalDirection;
use voku\AgentGraph\Sqlite\GraphStore;

// Write: replace the complete derived graph in one transaction.
$store = new GraphStore(__DIR__ . '/graph.sqlite');
$store->replace(
    [
        new GraphRelation('r1', 'App\Controller', 'calls', ['App\Service']),
        new GraphRelation('r2', 'App\Service', 'calls', ['App\Repository', 'App\Logger']),
    ],
    sourceRevision: 'abc123',          // opaque owner identity of the canonical data
    sourceFingerprint: 'sha256:example',
);

// Read: open read-only and query.
$graph = GraphStore::openReadOnly(__DIR__ . '/graph.sqlite');

$graph->incoming('App\Service');   // [GraphRelation r1]
$graph->neighbours('App\Service'); // ['App\Controller', 'App\Logger', 'App\Repository']

$result = $graph->traverse('App\Controller', TraversalDirection::OUTGOING, maximumDepth: 2);
$result->nodeIds;                  // ['App\Service', 'App\Repository', 'App\Logger']
$result->depthOf('App\Logger');    // 2
$result->truncated;                // false

$graph->sourceRevision();          // 'abc123'

The values in the comments are the real results of running this snippet.

How it works

  • Owners write ordered, grouped GraphRelation values once with GraphStore::replace() (one transaction); readers query indexed incoming/outgoing/neighbour lookups without loading the graph into PHP memory.
  • advanceProvenanceIfUnchanged() skips the rewrite when a rebuild produced exactly the same ordered relations.
  • Schema version 2 (0.3.0) shrank a 200k-relation graph by about 40% (51.7 → 30.9 MB) with unchanged query results, ordering and public API (CHANGELOG).
  • The store does not decide what an edge means; domain owners do. Coming from 0.2.x? Read the upgrade note.

Documentation

I want to… Read
Write and query a graph, see every read method GraphStore and the SQLite relation store
Validate an in-memory projection before storing it Structural graph contract
Upgrade a 0.2.x graph to schema v2 Upgrading from 0.2.x to 0.3.0
Load sqlite-vec or supply my own binary sqlite-vec runtime
Know what this package will never own Scope and boundaries
Run benchmarks or find where code lives Development
See what changed in each release CHANGELOG
Check third-party licensing Third-party notices

All pages: docs/README.md.

Part of the Agent Loop toolchain

Each package owns one concern and can be used on its own. voku/agent-loop composes them into one governed workflow.

Package Owns
agent-loop Task Contracts, lifecycle, next actions, validation and review gates
agent-kanban Git-native Markdown board and card semantics
agent-session Per-task working memory, decisions and checkpoints
agent-map Read-only repository symbol maps and typed edit plans
agent-edit Transactional, verified application of edit plans
agent-graph Deterministic SQLite graph index and runtime
agent-recall-compiler Bounded task context (Recall) and prompt recipes
agent-learning Reviewable findings, proposals and durable guidance
agent-skills Portable engineering skills for coding agents
agent-ui Local server-rendered control plane for humans
agent-decision Experimental bounded, advisory-only decision helper
agent-dotfiles Shell dotfiles for non-interactive agent shells

Development

composer install
composer ci   # composer validate --strict, PHPUnit, PHPStan

CI runs this on PHP 8.2 to 8.5 and additionally checks benchmark parity against a released tag. Benchmarks and the source layout: docs/development.md.

License

MIT, see LICENSE. The bundled sqlite-vec binaries (upstream dual Apache-2.0/MIT) are redistributed under MIT terms; see third-party notices.