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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,11 @@ FodyWeavers.xsd
/temp-schema.json
/data/framework/benchmarks/
/data/framework/exec-sessions.json
/data/framework/logs/
/data/framework/audit/
/data/framework/metrics/
/data/framework/requests/
/data/framework/self-healing/
/data/framework/incidents/open.json
/data/framework/traces/
/data/framework/traces/warm-failures/
39 changes: 29 additions & 10 deletions benchmarks/PhantomApi.Benchmarks/RuntimeBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using BenchmarkDotNet.Attributes;
using Json.Schema;

[MemoryDiagnoser]
public class InstructionBundleCompilerBenchmarks
Expand Down Expand Up @@ -59,7 +60,8 @@ public int GetOrLoad_CacheHit()
public class EndpointMetadataBenchmarks
{
private string _loginMarkdown = null!;
private JsonElement _loginContract;
private JsonSchema _loginSchema = null!;
private JsonElement _sampleResponse;
private string _repoRoot = null!;

[GlobalSetup]
Expand All @@ -68,17 +70,33 @@ public void Setup()
_repoRoot = BenchmarkFixture.RepoRoot;
var endpointPath = Path.Combine(_repoRoot, "instructions", "apps", "task-board", "endpoints", "auth", "login.md");
_loginMarkdown = File.ReadAllText(endpointPath);
using var contractDocument = JsonDocument.Parse("""
_loginSchema = JsonSchema.FromText("""
{
"sessionId": "session_123",
"user": {
"id": "user_1",
"name": "Taylor"
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"token": { "type": "string" },
"userId": { "type": "integer" },
"fullName": { "type": "string" },
"expiresAt": { "type": "string" },
"error": { "type": "string" }
},
"roles": ["admin", "editor"]
"required": ["ok", "token", "userId", "fullName", "expiresAt", "error"],
"additionalProperties": false
}
""");
_loginContract = contractDocument.RootElement.Clone();
using var responseDocument = JsonDocument.Parse("""
{
"ok": true,
"token": "session_123",
"userId": 10,
"fullName": "Taylor Example",
"expiresAt": "2026-03-15T12:00:00Z",
"error": ""
}
""");
_sampleResponse = responseDocument.RootElement.Clone();
}

[Benchmark(Baseline = true)]
Expand All @@ -88,9 +106,10 @@ public string ParseEndpointFrontmatter()
}

[Benchmark]
public string NormalizeResponseExampleToSchema()
public bool ValidateResponseAgainstSchema()
{
return JsonSchemaUtilities.NormalizeToSchemaJson(_loginContract);
var result = _loginSchema.Evaluate(_sampleResponse);
return result.IsValid;
}

[Benchmark]
Expand Down
1 change: 0 additions & 1 deletion data/framework/audit/security.jsonl

This file was deleted.

3 changes: 0 additions & 3 deletions data/framework/incidents/open.json

This file was deleted.

16 changes: 0 additions & 16 deletions data/framework/metrics/counters.json

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/requests/ledger.jsonl

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/self-healing/diagnoses.jsonl

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/self-healing/patches.jsonl

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/self-healing/rollbacks.jsonl

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/self-healing/validations.jsonl

This file was deleted.

1 change: 0 additions & 1 deletion data/framework/traces/events.jsonl

This file was deleted.

20 changes: 13 additions & 7 deletions instructions/apps/bank-api/endpoints/auth/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ Behavior rules:

```json
{
"ok": true,
"token": "session_123",
"userId": 1,
"fullName": "Ada Lovelace",
"accountNumber": "HU100000000000000000000001",
"expiresAt": "2026-03-15T12:00:00Z",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"token": { "type": "string" },
"userId": { "type": "integer" },
"fullName": { "type": "string" },
"accountNumber": { "type": "string" },
"expiresAt": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "token", "userId", "fullName", "accountNumber", "expiresAt", "error"],
"additionalProperties": false
}
```
20 changes: 13 additions & 7 deletions instructions/apps/bank-api/endpoints/bank/deposit.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ Behavior rules:

```json
{
"ok": true,
"userId": 1,
"accountNumber": "HU100000000000000000000001",
"amount": 200,
"balance": 1700,
"message": "Deposit completed.",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"userId": { "type": "integer" },
"accountNumber": { "type": "string" },
"amount": { "type": "number" },
"balance": { "type": "number" },
"message": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "userId", "accountNumber", "amount", "balance", "message", "error"],
"additionalProperties": false
}
```
18 changes: 12 additions & 6 deletions instructions/apps/bank-api/endpoints/bank/get-balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ Behavior rules:

```json
{
"ok": true,
"userId": 1,
"accountNumber": "HU100000000000000000000001",
"currency": "HUF",
"balance": 1500,
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"userId": { "type": "integer" },
"accountNumber": { "type": "string" },
"currency": { "type": "string" },
"balance": { "type": "number" },
"error": { "type": "string" }
},
"required": ["ok", "userId", "accountNumber", "currency", "balance", "error"],
"additionalProperties": false
}
```
22 changes: 14 additions & 8 deletions instructions/apps/bank-api/endpoints/bank/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ Behavior rules:

```json
{
"ok": true,
"userId": 1,
"sourceAccountNumber": "HU100000000000000000000001",
"targetAccountNumber": "HU100000000000000000000002",
"amount": 200,
"sourceBalance": 1300,
"message": "Transfer completed.",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"userId": { "type": "integer" },
"sourceAccountNumber": { "type": "string" },
"targetAccountNumber": { "type": "string" },
"amount": { "type": "number" },
"sourceBalance": { "type": "number" },
"message": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "userId", "sourceAccountNumber", "targetAccountNumber", "amount", "sourceBalance", "message", "error"],
"additionalProperties": false
}
```
20 changes: 13 additions & 7 deletions instructions/apps/bank-api/endpoints/bank/withdraw.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ Behavior rules:

```json
{
"ok": true,
"userId": 1,
"accountNumber": "HU100000000000000000000001",
"amount": 200,
"balance": 1300,
"message": "Withdrawal completed.",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"userId": { "type": "integer" },
"accountNumber": { "type": "string" },
"amount": { "type": "number" },
"balance": { "type": "number" },
"message": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "userId", "accountNumber", "amount", "balance", "message", "error"],
"additionalProperties": false
}
```
18 changes: 12 additions & 6 deletions instructions/apps/task-board/endpoints/auth/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ Behavior rules:

```json
{
"ok": true,
"token": "session_123",
"userId": 10,
"fullName": "Taylor Example",
"expiresAt": "2026-03-15T12:00:00Z",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"token": { "type": "string" },
"userId": { "type": "integer" },
"fullName": { "type": "string" },
"expiresAt": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "token", "userId", "fullName", "expiresAt", "error"],
"additionalProperties": false
}
```
20 changes: 13 additions & 7 deletions instructions/apps/task-board/endpoints/tasks/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ Behavior rules:

```json
{
"ok": true,
"taskId": 101,
"userId": 10,
"title": "Prepare backlog",
"description": "Collect the next iteration items.",
"status": "open",
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"taskId": { "type": "integer" },
"userId": { "type": "integer" },
"title": { "type": "string" },
"description": { "type": "string" },
"status": { "type": "string" },
"error": { "type": "string" }
},
"required": ["ok", "taskId", "userId", "title", "description", "status", "error"],
"additionalProperties": false
}
```
34 changes: 23 additions & 11 deletions instructions/apps/task-board/endpoints/tasks/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@ Behavior rules:

```json
{
"ok": true,
"userId": 10,
"tasks": [
{
"taskId": 100,
"title": "Prepare backlog",
"description": "Collect the next iteration items.",
"status": "open"
}
],
"error": ""
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"userId": { "type": "integer" },
"tasks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"taskId": { "type": "integer" },
"title": { "type": "string" },
"description": { "type": "string" },
"status": { "type": "string" }
},
"required": ["taskId", "title", "description", "status"],
"additionalProperties": false
}
},
"error": { "type": "string" }
},
"required": ["ok", "userId", "tasks", "error"],
"additionalProperties": false
}
```
3 changes: 2 additions & 1 deletion instructions/framework/contract-discipline.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
Response contract rules:

- the first `json` code block in the selected endpoint file is the authoritative response contract
- the first `json` code block must be valid JSON Schema, not an example payload
- return exactly the same property set as the contract
- do not add extra properties
- keep property types aligned with the contract
- use the contract's error-oriented fields when something fails
- contract literal values are examples for shape and type unless the endpoint explicitly states otherwise
- do not rely on contract example inference at runtime; the schema itself is the contract

Framework error contract rules:

Expand Down
Loading