Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/authority-policy-eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
paths:
- 'src/Authority/**'
- 'src/Policy/**'
- 'packages/policy-engine/**'
- 'evaluations/authority-policy/**'
- 'scripts/authority-policy-eval.php'
- '.github/workflows/authority-policy-eval.yml'
pull_request:
paths:
- 'src/Authority/**'
- 'src/Policy/**'
- 'packages/policy-engine/**'
- 'evaluations/authority-policy/**'
- 'scripts/authority-policy-eval.php'
- '.github/workflows/authority-policy-eval.yml'
Expand Down
72 changes: 46 additions & 26 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: Verify Interaction Engine
on:
pull_request:
push:
branches:
- main
- feature/full-engine-template-upgrade
workflow_dispatch:

permissions:
Expand All @@ -22,40 +19,63 @@ jobs:
- name: Check out source
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: xdebug
tools: composer:v2

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: '24'
cache: npm

- name: Install offline companion toolchain
shell: bash
- name: Validate Composer package metadata
run: composer validate --no-check-publish

- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Install locked JavaScript dependencies
run: npm ci

- name: Run complete engine verification
- name: Verify maintained-file SHA-256 manifest
run: php bin/manifest.php

- name: Run complete PHP and TypeScript verification
shell: bash
run: php bin/verify.php
run: |
set -euo pipefail
mkdir -p coverage
php bin/verify.php | tee coverage/verification.txt

- name: Lint PHP and validate JSON
- name: Generate PHP coverage report
shell: bash
run: |
set -euo pipefail
mkdir -p coverage
PHP_COVERAGE_OUTPUT=coverage/php.json php -dauto_prepend_file=tests/coverage-bootstrap.php tests/run.php | tee coverage/php-tests.txt
test -s coverage/php.json
PHP_COVERAGE_OUTPUT=coverage/policy-php.json php -dauto_prepend_file=tests/coverage-bootstrap.php packages/policy-engine/tests/run.php | tee coverage/policy-php-tests.txt
test -s coverage/policy-php.json

- name: Run 100-case authority evaluation
run: php bin/authority-eval.php coverage/authority-evaluation.json > coverage/authority-evaluation.stdout

php_files=()
while IFS= read -r -d '' file; do
php_files+=("$file")
done < <(find src tests bin routes config database -type f -name '*.php' -print0 2>/dev/null)
for file in "${php_files[@]}"; do
php -l "$file" >/dev/null
done
echo "PHP syntax valid: ${#php_files[@]} files"

json_files=()
while IFS= read -r -d '' file; do
json_files+=("$file")
done < <(find wizards templates resources config reports -type f -name '*.json' -print0 2>/dev/null)
for file in "${json_files[@]}"; do
php -r 'json_decode(file_get_contents($argv[1]), true, 512, JSON_THROW_ON_ERROR);' "$file"
done
echo "JSON valid: ${#json_files[@]} files"
- name: Run measured benchmarks
shell: bash
run: |
set -euo pipefail
php bin/benchmark.php coverage/performance-php.json > coverage/performance-php.stdout
npm run benchmark:offline -- coverage/performance-typescript.json > coverage/performance-typescript.stdout

- name: Store test, coverage, evaluation, and benchmark reports
if: always()
uses: actions/upload-artifact@v4
with:
name: interaction-engine-evidence
path: coverage/
if-no-files-found: warn
retention-days: 30
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

.worktrees/
node_modules/
coverage/
/dist/
/node_modules/
/coverage/
.phpunit.result.cache
.env
.env.*
!.env.example

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Jason Lee

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
163 changes: 59 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,147 +4,102 @@

# Titan Zero Interaction Engine

**A governed interaction runtime for adaptive workflows and authorised business actions, online or offline.**
**A governed workflow runtime that keeps model proposals separate from authorized actions.**

</div>

[![Authority Policy Evaluation](https://github.com/Masterleeaus/Interaction-engine/actions/workflows/authority-policy-eval.yml/badge.svg?branch=main)](https://github.com/Masterleeaus/Interaction-engine/actions/workflows/authority-policy-eval.yml)

## Product architecture and engineering highlights
## Run a governed action in five minutes

A governed interaction runtime that turns chat, voice, mobile, desktop, and API requests into authorized, traceable business workflows.
The standalone policy package and demo need PHP 8.2. They do not need Composer, Laravel, a database, or an API key.

- **Architecture:** Schema-driven wizards and versioned workflow catalogues feed local/hybrid intelligence, tenant-scoped context, capability policies, idempotent execution, and an IndexedDB-based offline companion.
- **Distinctive engineering:** The key boundary is explicit: understanding and recommending do not confer authority. Approval, execution, evidence, and verification are separate stages.

> **Status: module foundation with recorded standalone verification; host deployment readiness remains environment-specific.** The repository includes a cumulative build report and verification scripts. Its report explicitly lists host tenancy, permissions, queues, database compatibility, PWA integration, provider integration, and production-load testing as remaining destination-system checks.

## What it provides

The Interaction Engine connects chat, voice, mobile, desktop, and API experiences to structured workflows, local intelligence, business capabilities, and policy-controlled execution. Understanding user intent does not grant authority: recommendation, approval, and execution remain separate stages.

## Core capabilities

- Schema-driven Universal Wizard Engine with resumable sessions and conditional flows
- Versioned workflow and template catalogues with readiness metadata
- Local and hybrid intelligence components
- Tenant-scoped cognitive events and evidence lineage
- Capability policies, actor context, idempotency, and fail-closed execution
- TypeScript offline companion using IndexedDB and encrypted command envelopes
- OpenAPI contract in `resources/openapi.yaml`

## Template discovery

The catalogue contains 38 definitions: **29 ready templates** and nine drafts. Ready templates reference registered entry wizards and declared capabilities; drafts remain non-executable. The authenticated Laravel catalogue is available at `GET /templates`, with template definitions discovered from `templates/`.

Assurance workflows include **Incident Response** and inspection corrective action.

### Commerce and multi-vertical template pack

The [Commerce and multi-vertical template pack](docs/COMMERCE_MULTI_VERTICAL_TEMPLATE_PACK.md) adds reusable workflows for ordering, fulfilment, inventory, returns, refunds, and vertical-specific service operations. See `reports/workcore-compatibility.json` for engine readiness and host-connection status.
```sh
php bin/demo.php
```

## Architecture
The deterministic proposal is denied first. The demo then simulates a signed owner approval bound to the exact quote data, runs an in-memory draft handler, and records an audit event. That simulated approval is not proof of a real user's identity and cannot mutate a host system.

```text
Chat / Voice / Mobile / Desktop / API
|
v
Interaction Runtime
|
v
Wizard + Templates
|
v
Local Intelligence
|
v
Policy + Capability Layer
|
+-------+-------+
| |
v v
Online host Offline outbox
| |
+-------+-------+
v
Outcomes + Evidence
Titan Zero Interaction Engine — governed quote demo
Proposal: Create a $450 carpet-cleaning quote for Jenny.
Gate before approval: DENY — A valid, scoped and unexpired human approval is required.
Owner approval: VALID
Execution: quote-demo-001 created as a draft for Jenny — AUD 450.00
Audit: capability_executed recorded for quote-demo-001
Summary: denied before approval; approved; executed once; audit entries=1
```

## Technology
## Policy Engine

- PHP 8.2+
- Laravel-compatible Illuminate components
- TypeScript, IndexedDB
- PHP Sodium and AES-GCM
- OpenAPI and JSON/schema-driven definitions
The Policy Engine is the execution boundary. Intent recognition, planning, recommendation, and model proposals do not confer permission. Only a registered capability handler reached after an allowed policy decision can execute an action.

## Installation
- Unknown capabilities fail closed; observe, recommend, and prepare policies cannot execute.
- User-only actions require a human identity and roles from trusted server context, with fresh authentication when configured. The host must not copy identity claims from request or model data.
- Delegated actors must be identified, tenant scoped, and carry every required scope.
- Approval grants are HMAC-SHA256 signed, capability and tenant scoped, time limited, and bound to the action payload by default.
- Numeric limits and registered domain rules run before execution.

The module is intended for a compatible Laravel host. Verify the host version, dependency constraints, migrations, service provider registration, auth/tenant context, queue/cache setup, and route exposure before deployment.
The framework independent package is in [`packages/policy-engine`](packages/policy-engine/README.md). Its `AuthorityLevel`, `CapabilityPolicy`, `ApprovalSigner`, and `PolicyEngine` classes have a focused test suite:

```bash
composer install
npm ci
php bin/verify.php
```sh
php packages/policy-engine/tests/run.php
```

`php bin/verify.php` runs the PHP suites and the TypeScript offline-companion tests. The workflow installs the declared TypeScript toolchain before invoking the same verifier, so a clean checkout does not depend on a globally installed compiler. A prior cumulative build report records historical checks; it is not a substitute for rerunning tests on the current commit or validating a destination host.
Only trusted server-side approval code should issue grants. The host remains responsible for authenticating users, building `_context`, persisting approvals, and recording durable audit evidence.

## Integration requirements
## Current 100-case authority evaluation

A destination system must validate:
The 100 deterministic scenarios cover approval-required, user-only, delegated, prepare-only, and unregistered capabilities. In CI, all 30 expected allows were allowed and all 70 expected denials were denied: zero valid actions were wrongly blocked and zero unauthorized actions passed the gate. The gate-bypassed control forwards unauthorized cases only to a no-op sink.

- host-specific model and service mappings;
- tenant and permission semantics;
- authentication, API exposure, queues, cache, scheduler, and database migration compatibility;
- browser/PWA integration and cloud provider configuration;
- concurrency, load, and production failure behaviour.
See the [100-case evaluation report](reports/authority-evaluation.md) and its [JSON result](reports/authority-evaluation.json). The separate 31-case suite also passed with zero unauthorized allows, zero wrongly denied valid actions, and zero scenario mismatches; see [its report](eval-results/authority-policy-latest.md). Both evaluations exercise the repository policy code directly and do not validate a connected host.

The host business system remains the authority for operational mutations.
## Optional live model proposal

## Repository map
The optional `openai-php/client` adapter returns structured proposal data. `OpenAIActionProposer` only accepts a caller-supplied capability allowlist and rejects authority, approval, identity, tenant, scope, and idempotency fields from model output. The proposal has no handler or policy bypass; the normal Command Bus rechecks trusted context and policy before any registered handler.

- `interactions/`, `wizards/`, `templates/` — interaction and workflow definitions
- `resources/ts/` — device-side offline companion
- `resources/openapi.yaml` — API contract
- `tests/` — runtime and workflow checks
- `docs/`, `reports/` — architecture and verification evidence
```php
$proposal = $proposer->propose($userRequest, ['quotes.create']);
$commands->dispatch(
$proposal->capability,
$proposal->payload + ['_context' => $trustedServerContext],
);
```

The AI and agent-oriented implementation map is in [`docs/AI_ENGINEERING.md`](docs/AI_ENGINEERING.md). It distinguishes deterministic heuristics, optional cloud-model integration, policy enforcement and host-boundary work from claims the repository does not make.
Cloud AI is disabled by default. Set `INTERACTION_AI_ENABLED=true`, `INTERACTION_AI_API_KEY`, and a high-entropy `INTERACTION_APPROVAL_SECRET` (at least 32 characters) in a trusted host environment. To make one live proposal and demonstrate its denial, install the optional SDK with `composer require openai-php/client`, then run `php bin/llm-proposal-demo.php`. It never executes the proposed action. Do not put credentials in a browser, device, or model prompt.

## Security principles
The local-language component is a deterministic **rule-based intent parser**. It extracts supported business intents and entities; it is not a language model.

- Cloud AI is disabled by default.
- Unregistered capabilities fail closed.
- Tenant and actor context are required for consequential execution.
- Offline replay uses the same policy checks as online execution.
- Unsynchronised records remain queued until reconciliation succeeds.
## The 80-engine library

## Reproducible authority policy evaluation
The repository contains 80 engine contracts with matching implementations across executive, cognitive, memory, learning, planning, human interaction, AI infrastructure, and business intelligence. [`docs/ENGINE_LIBRARY_80.md`](docs/ENGINE_LIBRARY_80.md) lists each as `Implemented` or `Partial` with behavior and limits. `Implemented` means the declared operations have executable behavior within the described boundary, not production validation for every host or industry. Heuristics, in-memory stores, and host-schema integrations are labeled accordingly; no engine is listed as interface only.

The authority policy claim is measured directly against `PolicyEngine` using 31 fixed, labelled scenarios covering unknown capabilities, non-executable authority levels, human roles and authentication freshness, signed approval scope and expiry, delegated scopes and numeric limits, and policy callbacks.
## Template discovery

| Test | Allow-all bypass control | Interaction Engine |
| --- | ---: | ---: |
| Blocked requests allowed through | 24 / 24 | 0 / 24 |
| Valid requests wrongly denied | 0 / 7 | 0 / 7 |
| Wrong-tenant approvals accepted | 1 / 1 | 0 / 1 |
The catalogue has 38 definitions: 29 ready templates and nine drafts. Ready templates reference registered entry wizards and declared capabilities; drafts remain non-executable. The authenticated Laravel catalogue is available at `GET /templates`.

The baseline is a deliberately simple allow-all control, not a competing product. The evaluation tests policy decisions only; it does not cover host adapters, persistence, or downstream execution.
The [Commerce and multi-vertical template pack](docs/COMMERCE_MULTI_VERTICAL_TEMPLATE_PACK.md) covers ordering, fulfilment, inventory, returns, refunds, and vertical-specific service workflows. Incident Response and inspection corrective action are included in the assurance workflows. Host compatibility evidence is in [`reports/workcore-compatibility.json`](reports/workcore-compatibility.json); it does not claim a connected production host.

Evaluated on **4 October 2026** with PHP 8.2.34 at commit [`bdbe73c`](https://github.com/Masterleeaus/Interaction-engine/commit/bdbe73cc445b900d29126e081bd5f2341e98ee6f). The fixed scenario corpus uses seed `20261004` and SHA-256 `a1e863c857aa05e70f720224c3f1bb0065f2f1c699fe27e438ce4a64a58ff340`. Reproduce with:
The broader implementation map in [`docs/AI_ENGINEERING.md`](docs/AI_ENGINEERING.md) distinguishes deterministic heuristics, optional cloud-model integration, policy enforcement, and host-boundary work.

```bash
php scripts/authority-policy-eval.php
## Install and verify

The Laravel-compatible module targets PHP 8.2+ and Illuminate 10, 11, or 12. In a compatible host checkout:

```sh
composer install
npm ci
php bin/verify.php
```

The [full scenario report](eval-results/authority-policy-latest.md) records all 31 outcomes; [CI run 37171514412](https://github.com/Masterleeaus/Interaction-engine/actions/runs/37171514412) passed. The initial CI attempt failed before evaluating scenarios because the evaluator resolved the repository root one directory too high; that path bug was corrected before this successful run.
The verifier runs the standalone policy suite, PHP runtime and workflow suites, and TypeScript tests. GitHub Actions also runs PHP and TypeScript coverage, 100 authority cases, and measured benchmarks. See the [CI verification evidence](reports/verification-evidence.md) for the current counts and coverage scope.

## License
The TypeScript offline companion uses IndexedDB and AES-256-GCM for device-side command storage. The test suite uses a memory adapter; browser, database, authentication, and connected-host behavior still require validation in the destination application.

The Composer package declares a proprietary license. Obtain the appropriate rights before external distribution or reuse.
## Measured performance

## Banner
The benchmark scripts measure interaction-definition compilation, duplicate-command handling, and encrypted outbox enqueue/decrypt. The [measured report](benchmarks/performance.md) records sample counts, p50/p95, runtime, commit, and limits; results are a single hosted-CI run, not production capacity claims.

A checked-in project-specific banner is displayed above.
## Repository hygiene, history, and license

This repository is licensed under MIT. Generated `dist/` output and dependencies are build-only and ignored. The risky external tarball import workflow has been removed. Historical import notes and provenance remain on the [`archive/interaction-engine-history` branch](https://github.com/Masterleeaus/Interaction-engine/tree/archive/interaction-engine-history).
Loading
Loading