File size: 9,711 Bytes
2a7f679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# CAP Integration β€” Technical Reference

CAPScore Agent integrates with the CROO Commerce Agent Protocol (CAP) to register capabilities, accept orders, run audit pipelines, and deliver cryptographically-verifiable proof of results.

---

## Order Lifecycle

```
CROO Network                CAPScore cap-provider (TS)      CAPScore API (Python)
    β”‚                               β”‚                               β”‚
    β”‚  WebSocket: new_order         β”‚                               β”‚
    │──────────────────────────────►│                               β”‚
    β”‚                               β”‚  POST /jobs/{capability}      β”‚
    β”‚                               │──────────────────────────────►│
    β”‚                               β”‚                               β”‚ create job (PENDING)
    β”‚                               β”‚  {job_id, status: "pending"}  β”‚
    β”‚                               │◄──────────────────────────────│
    β”‚                               β”‚                               β”‚ background: run workers
    β”‚                               β”‚                               β”‚   - repo_reproducer
    β”‚                               β”‚                               β”‚   - cap_inspector
    β”‚                               β”‚                               β”‚   - claim_verifier
    β”‚                               β”‚                               β”‚   - security_scanner
    β”‚                               β”‚                               β”‚   - readme_rewriter
    β”‚                               β”‚                               β”‚   - demo_coach
    β”‚                               β”‚                               β”‚ compute scorecard
    β”‚                               β”‚  GET /jobs/{job_id} (poll)    β”‚ build proof pack
    β”‚                               │──────────────────────────────►│
    β”‚                               β”‚  {status: "done", scorecard}  β”‚
    β”‚                               │◄──────────────────────────────│
    β”‚                               β”‚                               β”‚
    β”‚  CAP delivery: proof_pack_url β”‚                               β”‚
    │◄──────────────────────────────│                               β”‚
    β”‚                               β”‚                               β”‚
```

---

## SDK Methods Used

### Registration (`registerCapabilities.ts`)

```typescript
import { CROOClient } from "@croo/agent-sdk";

const client = new CROOClient({
  apiKey: process.env.CROO_SDK_KEY,
  agentId: process.env.CAPSCORE_AGENT_ID,
});

// Register all 3 capabilities
await client.registerCapability({
  id: "audit_repository",
  schema: AUDIT_REPO_SCHEMA,
  pricing: { amount: 0.05, currency: "CROO" },
  sla: { max_seconds: 300 },
});

await client.registerCapability({
  id: "audit_agent_listing",
  schema: AUDIT_AGENT_SCHEMA,
  pricing: { amount: 0.08, currency: "CROO" },
  sla: { max_seconds: 480 },
});

await client.registerCapability({
  id: "verify_claims",
  schema: VERIFY_CLAIMS_SCHEMA,
  pricing: { amount: 0.02, currency: "CROO" },
  sla: { max_seconds: 120 },
});
```

### Order Handling (`orderHandler.ts`)

```typescript
client.onOrder(async (order) => {
  const response = await fetch(`${process.env.CAPSCORE_API_URL}/jobs/${order.capability}`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(order.input),
  });
  const job = await response.json();
  
  // Poll until done
  const result = await pollUntilDone(job.job_id);
  
  // Deliver proof via CAP
  await client.deliverProof(order.id, {
    result: result.scorecard,
    proof_pack_url: result.proof_pack_url,
    result_hash: result.result_hash,
  });
});
```

### Proof Delivery (`deliverProof.ts`)

```typescript
await client.deliverProof(orderId, {
  status: "completed",
  output: {
    scorecard: job.scorecard,
    overall_score: job.scorecard.overall_score,
    result_hash: job.result_hash,
    proof_pack_url: job.proof_pack_url,
    a2a_calls: job.a2a_calls,
  },
  proof: {
    hash: job.result_hash,
    algorithm: "sha256",
    canonical: "json-sorted-keys",
  },
});
```

---

## Capability Schemas

### `audit_repository`

```json
{
  "type": "object",
  "required": ["github_url"],
  "properties": {
    "github_url": {
      "type": "string",
      "description": "HTTPS URL of the GitHub repository to audit"
    },
    "branch": {
      "type": "string",
      "default": "main",
      "description": "Branch to audit"
    },
    "run_tests": {
      "type": "boolean",
      "default": true,
      "description": "Whether to attempt running the test suite"
    },
    "run_security_scan": {
      "type": "boolean",
      "default": true,
      "description": "Whether to scan for hardcoded secrets and dangerous patterns"
    },
    "expected_start_command": {
      "type": "string",
      "description": "Optional override for the detected start command"
    }
  },
  "additionalProperties": false
}
```

### `audit_agent_listing`

```json
{
  "type": "object",
  "required": ["agent_listing_url"],
  "properties": {
    "agent_listing_url": {
      "type": "string",
      "description": "CROO Agent Store listing URL"
    },
    "github_url": {
      "type": "string",
      "description": "GitHub repository URL (optional but improves score accuracy)"
    },
    "demo_url": {
      "type": "string",
      "description": "Demo video URL (YouTube, Loom, etc.)"
    },
    "claimed_tracks": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Hackathon tracks the agent is submitted to"
    },
    "depth": {
      "type": "string",
      "enum": ["quick", "standard", "deep"],
      "default": "standard",
      "description": "Audit depth: quick=2min, standard=5min, deep=10min"
    }
  },
  "additionalProperties": false
}
```

### `verify_claims`

```json
{
  "type": "object",
  "required": ["claims"],
  "properties": {
    "claims": {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1,
      "maxItems": 20,
      "description": "List of claims to verify"
    },
    "evidence_urls": {
      "type": "array",
      "items": { "type": "string" },
      "description": "URLs to use as evidence (GitHub, Agent Store, demo video)"
    },
    "strictness": {
      "type": "string",
      "enum": ["lenient", "standard", "strict"],
      "default": "standard",
      "description": "How strictly to evaluate claims"
    }
  },
  "additionalProperties": false
}
```

---

## Output Schema (all capabilities)

```json
{
  "job_id": "capscore_YYYYMMDD_HHMMSS_hex8",
  "status": "done | failed | pending | running",
  "capability": "audit_repository | audit_agent_listing | verify_claims",
  "created_at": "ISO-8601",
  "completed_at": "ISO-8601",
  "scorecard": {
    "overall_score": 84.0,
    "technical_execution": { "score": 85.7, "notes": "...", "checks": [] },
    "a2a_composability":   { "score": 85.7, "notes": "...", "checks": [] },
    "innovation":          { "score": 80.0, "notes": "...", "checks": [] },
    "adoption_readiness":  { "score": 83.3, "notes": "...", "checks": [] },
    "presentation_readiness": { "score": 80.0, "notes": "...", "checks": [] },
    "critical_issues": ["..."],
    "top_fixes": ["..."]
  },
  "result_hash": "sha256:<hex64>",
  "proof_pack_url": "https://<host>/jobs/<job_id>/proof-pack.zip",
  "a2a_calls": [
    {
      "provider_agent": "source-verifier-mock",
      "cap_order_id": "order_sv_001",
      "task": "verify_github_source",
      "result_hash": "sha256:...",
      "status": "cleared",
      "started_at": "ISO-8601",
      "completed_at": "ISO-8601"
    }
  ]
}
```

---

## Proof Delivery Format

When CAPScore delivers a CAP proof to the ordering agent, the payload is:

```json
{
  "status": "completed",
  "output": {
    "scorecard": { "...": "..." },
    "overall_score": 84.0,
    "result_hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924...",
    "proof_pack_url": "https://capscore.croo.network/jobs/.../proof-pack.zip"
  },
  "proof": {
    "hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924...",
    "algorithm": "sha256",
    "canonical": "json-sorted-keys",
    "description": "SHA-256 of canonical JSON (sort_keys=True, no whitespace)"
  }
}
```

The `result_hash` is computed as:

```python
import json, hashlib

canonical = json.dumps(scorecard_dict, sort_keys=True, ensure_ascii=False, separators=(",", ":"))
result_hash = "sha256:" + hashlib.sha256(canonical.encode("utf-8")).hexdigest()
```

Any agent that receives this proof can independently verify it against the downloaded proof pack.

---

## A2A Call Format

When CAPScore calls a sub-agent (e.g., `security-scanner-mock`), it uses:

```typescript
const subResult = await crooClient.placeOrder({
  agentId: "security-scanner-mock",
  capability: "scan_secrets",
  input: { github_url: repoUrl },
  timeout: 120,
});

// Logged in manifest.json as:
{
  "provider_agent": "security-scanner-mock",
  "cap_order_id": "order_sec_001",
  "task": "scan_secrets",
  "result_hash": subResult.proof.hash,
  "status": "cleared",
  "started_at": "...",
  "completed_at": "..."
}
```

Each sub-agent result hash is included in the CAPScore manifest, creating a **chain of provenance** from buyer order to final proof pack.