@kontextmind/kxm 0.7.95 → 0.7.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.kxm/README.md +39 -9
- package/CHANGELOG.md +23 -1
- package/README.md +147 -257
- package/SECURITY.md +21 -12
- package/docs/README.md +133 -54
- package/docs/adr/ADR-0002-browser-automation-steel-doks.md +24 -18
- package/docs/adr/ADR-0003-sqlite-only-store.md +100 -0
- package/docs/adr/ADR-0004-edge-identity-authentik.md +99 -0
- package/docs/adr/README.md +33 -0
- package/docs/concepts/architecture.md +262 -0
- package/docs/concepts/data-and-storage.md +194 -0
- package/docs/concepts/trust-model.md +153 -0
- package/docs/contracts/README.md +22 -14
- package/docs/contracts/effects-and-recovery.md +3 -0
- package/docs/contracts/migration.md +2 -2
- package/docs/contracts/routing.md +6 -5
- package/docs/contributing/assignment-runner.md +388 -0
- package/docs/contributing/ci-and-release.md +231 -0
- package/docs/contributing/development.md +362 -0
- package/docs/contributing/harness-routing-internals.md +192 -0
- package/docs/{packages.md → contributing/packages.md} +13 -15
- package/docs/{skills → contributing}/repo-work-delivery.md +20 -21
- package/docs/contributing/test-matrix.md +208 -0
- package/docs/{tui-components.md → contributing/tui-components.md} +30 -22
- package/docs/contributing/writing-docs.md +340 -0
- package/docs/glossary.md +471 -0
- package/docs/guides/agent-skills.md +137 -0
- package/docs/guides/browser-automation.md +160 -0
- package/docs/guides/context-and-memory.md +352 -0
- package/docs/guides/continuous-improvement.md +228 -0
- package/docs/guides/governed-skills.md +173 -0
- package/docs/guides/nous-providers.md +186 -0
- package/docs/guides/peer-messaging.md +304 -0
- package/docs/guides/pi-workers.md +219 -0
- package/docs/guides/provenance-gates.md +313 -0
- package/docs/guides/webhook-workflows.md +399 -0
- package/docs/kb/how-credentials-retrieved-safely.md +38 -12
- package/docs/kb/how-to-capture-and-annotate-section.md +15 -13
- package/docs/kb/how-to-connect-playwright-to-steel.md +16 -11
- package/docs/kb/how-to-recover-expired-session-or-orphan.md +26 -16
- package/docs/kb/how-to-resume-after-mfa.md +19 -11
- package/docs/kb/how-to-take-over-session.md +17 -13
- package/docs/kb/why-authentication-disappeared.md +22 -14
- package/docs/kb/why-automation-opened-different-browser.md +23 -14
- package/docs/kb/why-session-viewer-cannot-control.md +13 -12
- package/docs/operations/backup-and-restore.md +248 -0
- package/docs/operations/deploy.md +307 -0
- package/docs/operations/monitoring.md +209 -0
- package/docs/operations/runtime-sync.md +192 -0
- package/docs/operations/troubleshooting.md +266 -0
- package/docs/operations/upgrade.md +124 -0
- package/docs/prompts/browser-annotate-feedback.md +7 -7
- package/docs/prompts/browser-diagnose-recover.md +11 -10
- package/docs/prompts/browser-explore.md +7 -7
- package/docs/prompts/browser-repro-fix.md +7 -7
- package/docs/prompts/browser-start.md +12 -11
- package/docs/prompts/browser-takeover.md +8 -8
- package/docs/{cli-reference.md → reference/cli-reference.md} +88 -46
- package/docs/{config-reference.md → reference/config-reference.md} +159 -148
- package/docs/reference/configuration.md +299 -0
- package/docs/reference/harness-routing.md +508 -0
- package/docs/reference/http-api.md +203 -0
- package/docs/reference/tools.md +370 -0
- package/docs/{workflow-guide.md → reference/workflow-catalog.md} +92 -153
- package/docs/reference/workflow-definitions.md +286 -0
- package/docs/start/first-workflow.md +287 -0
- package/docs/start/install.md +146 -0
- package/docs/start/quickstart-claude-code.md +405 -0
- package/docs/start/quickstart-pi.md +213 -0
- package/docs/templates/README.md +78 -73
- package/docs/templates/adr.md +13 -13
- package/docs/templates/architecture.md +55 -71
- package/docs/templates/bug-fix.md +13 -16
- package/docs/templates/feature.md +14 -19
- package/docs/templates/handoff.md +44 -46
- package/docs/templates/postmortem.md +30 -43
- package/docs/templates/research.md +15 -20
- package/docs/templates/review.md +49 -50
- package/docs/templates/runbook.md +38 -30
- package/docs/templates/test-plan.md +16 -23
- package/docs/templates/test-report.md +14 -17
- package/examples/README.md +9 -5
- package/examples/provenance-workflow.json +1 -1
- package/examples/webhook-workflows/jira-development.json +59 -0
- package/examples/webhook-workflows/jira-issue-updated.json +12 -0
- package/examples/workflow-signal.ts +4 -5
- package/package.json +1 -1
- package/packages/core/tui/README.md +1 -1
- package/plugins/kxm/.claude-plugin/plugin.json +1 -1
- package/plugins/kxm/README.md +31 -32
- package/plugins/kxm/dist/claude-hook.js +11 -1
- package/plugins/kxm/dist/cli.js +164 -79
- package/plugins/kxm/dist/client.js +3 -1
- package/plugins/kxm/dist/core.js +11 -1
- package/plugins/kxm/dist/extension.js +45 -13
- package/plugins/kxm/dist/mcp-server.js +20 -4
- package/plugins/kxm/dist/runtime-supervisor.js +1 -3
- package/plugins/kxm/dist/runtime.js +18 -4
- package/plugins/kxm/dist/server.js +115 -20
- package/plugins/kxm/package.json +1 -1
- package/plugins/kxm/skills/kxm/references/protocol.md +3 -1
- package/plugins/kxm/skills/kxm-browser-auth/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-browser-diagnostics/SKILL.md +5 -5
- package/plugins/kxm/skills/kxm-browser-explore/SKILL.md +2 -2
- package/plugins/kxm/skills/kxm-browser-session/SKILL.md +10 -13
- package/plugins/kxm/skills/kxm-browser-takeover/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-browser-verify/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-context-memory/SKILL.md +13 -4
- package/plugins/kxm/skills/kxm-hub-ops/SKILL.md +3 -1
- package/plugins/kxm/skills/kxm-mind-setup/SKILL.md +2 -1
- package/plugins/kxm/skills/kxm-project-setup/SKILL.md +31 -54
- package/plugins/kxm/skills/kxm-projects/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-protocol/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-routing-improve/SKILL.md +15 -7
- package/plugins/kxm/skills/kxm-runs/SKILL.md +11 -5
- package/plugins/kxm/skills/kxm-session/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-tasks/SKILL.md +9 -7
- package/plugins/kxm/skills/kxm-workflow/SKILL.md +10 -2
- package/plugins/kxm/src/cli/system.ts +1 -1
- package/plugins/kxm/src/cli/workflows.ts +12 -7
- package/plugins/kxm/src/cli.ts +22 -8
- package/plugins/kxm/src/client.ts +4 -0
- package/plugins/kxm/src/commands.ts +23 -1
- package/plugins/kxm/src/extension.ts +20 -14
- package/plugins/kxm/src/github-watch.ts +8 -5
- package/plugins/kxm/src/hub-env.ts +19 -1
- package/plugins/kxm/src/hub.ts +105 -21
- package/plugins/kxm/src/improve-sources.ts +2 -7
- package/plugins/kxm/src/init-guide-setup.ts +1 -1
- package/plugins/kxm/src/mcp-server.ts +9 -2
- package/plugins/kxm/src/modes.ts +1 -1
- package/plugins/kxm/src/runtime-store.ts +23 -0
- package/plugins/kxm/src/workflow.ts +70 -1
- package/schemas/README.md +1 -1
- package/scripts/smoke-multi-pi.mjs +5 -1
- package/docs/agent-communication-envelopes-and-gates.md +0 -553
- package/docs/agent-skills.md +0 -198
- package/docs/architecture.md +0 -245
- package/docs/assignment-runner.md +0 -264
- package/docs/browser-automation.md +0 -139
- package/docs/configuration.md +0 -437
- package/docs/continuous-improvement.md +0 -226
- package/docs/getting-started.md +0 -277
- package/docs/harness-routing.md +0 -616
- package/docs/kb/qa-authentik-authentication.md +0 -97
- package/docs/kb/qa-extension-install-and-hub-bootstrap.md +0 -85
- package/docs/kb/qa-hub-on-a-public-host.md +0 -48
- package/docs/kb/qa-sqlite-vs-duckdb.md +0 -35
- package/docs/kb/qa-what-the-hub-stores.md +0 -64
- package/docs/kxm-handbook.md +0 -1181
- package/docs/operations.md +0 -510
- package/docs/operator-pi-packages.md +0 -67
- package/docs/provenance-gates.md +0 -295
- package/docs/skills.md +0 -47
- package/docs/test-matrix.md +0 -132
- package/docs/troubleshooting.md +0 -322
- package/docs/webhook-workflows.md +0 -240
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, createHmac } from "node:crypto";
|
|
2
2
|
import {
|
|
3
3
|
IMPROVEMENT_AREAS,
|
|
4
4
|
MAX_MESSAGE_TTL_MS,
|
|
@@ -1386,6 +1386,75 @@ export function workflowDefinitionHash(definition: WebhookWorkflowDefinition): s
|
|
|
1386
1386
|
return createHash("sha256").update(canonicalWorkflowDefinitionJson(definition), "utf8").digest("hex");
|
|
1387
1387
|
}
|
|
1388
1388
|
|
|
1389
|
+
/** The KXM-owned webhook sender contract: every signal callback, and any
|
|
1390
|
+
* workflow start that is not a Jira or GitHub provider delivery. The HMAC
|
|
1391
|
+
* covers a fixed-arity header block and the exact body bytes, so a captured
|
|
1392
|
+
* request cannot be replayed under another delivery ID, against another run
|
|
1393
|
+
* or signal key, or outside the timestamp window. */
|
|
1394
|
+
export const WORKFLOW_WEBHOOK_SIGNATURE_VERSION = "kxm-webhook-v1";
|
|
1395
|
+
export const WORKFLOW_WEBHOOK_MAX_SKEW_SECONDS = 300;
|
|
1396
|
+
|
|
1397
|
+
/** What a signature is bound to. A start names only the definition; a signal
|
|
1398
|
+
* callback also names the run and signal key from its route. */
|
|
1399
|
+
export type WorkflowWebhookScope =
|
|
1400
|
+
| { definitionId: string; runId?: undefined; signalKey?: undefined }
|
|
1401
|
+
| { definitionId: string; runId: string; signalKey: string };
|
|
1402
|
+
|
|
1403
|
+
/** The exact bytes a KXM webhook signature covers: seven newline-terminated
|
|
1404
|
+
* fields (version, kind, timestamp, delivery ID, definition ID, run ID, signal
|
|
1405
|
+
* key; the last two empty for a start) followed by the raw body. No field may
|
|
1406
|
+
* contain a line break, so the encoding is unambiguous. */
|
|
1407
|
+
export function workflowWebhookSignedMaterial(
|
|
1408
|
+
scope: WorkflowWebhookScope,
|
|
1409
|
+
timestamp: string,
|
|
1410
|
+
deliveryId: string,
|
|
1411
|
+
body: string | Uint8Array,
|
|
1412
|
+
): Buffer {
|
|
1413
|
+
const fields = [
|
|
1414
|
+
WORKFLOW_WEBHOOK_SIGNATURE_VERSION,
|
|
1415
|
+
scope.runId === undefined ? "start" : "signal",
|
|
1416
|
+
timestamp,
|
|
1417
|
+
deliveryId,
|
|
1418
|
+
scope.definitionId,
|
|
1419
|
+
scope.runId ?? "",
|
|
1420
|
+
scope.signalKey ?? "",
|
|
1421
|
+
];
|
|
1422
|
+
if (fields.some((field) => /[\r\n]/.test(field))) {
|
|
1423
|
+
throw new ProtocolError(400, "webhook signature fields must not contain line breaks", "webhook_signature_field_invalid");
|
|
1424
|
+
}
|
|
1425
|
+
return Buffer.concat([
|
|
1426
|
+
Buffer.from(`${fields.join("\n")}\n`, "utf8"),
|
|
1427
|
+
typeof body === "string" ? Buffer.from(body, "utf8") : Buffer.from(body),
|
|
1428
|
+
]);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
export function workflowWebhookSignature(
|
|
1432
|
+
secret: string,
|
|
1433
|
+
scope: WorkflowWebhookScope,
|
|
1434
|
+
timestamp: string,
|
|
1435
|
+
deliveryId: string,
|
|
1436
|
+
body: string | Uint8Array,
|
|
1437
|
+
): string {
|
|
1438
|
+
return `sha256=${createHmac("sha256", secret).update(workflowWebhookSignedMaterial(scope, timestamp, deliveryId, body)).digest("hex")}`;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/** Headers for one KXM webhook send. Sign at send time: a transport retry
|
|
1442
|
+
* re-signs with a fresh timestamp and keeps the same delivery ID and body. */
|
|
1443
|
+
export function workflowWebhookHeaders(input: {
|
|
1444
|
+
secret: string;
|
|
1445
|
+
scope: WorkflowWebhookScope;
|
|
1446
|
+
deliveryId: string;
|
|
1447
|
+
body: string;
|
|
1448
|
+
nowMs?: number;
|
|
1449
|
+
}): Record<string, string> {
|
|
1450
|
+
const timestamp = String(Math.floor((input.nowMs ?? Date.now()) / 1_000));
|
|
1451
|
+
return {
|
|
1452
|
+
"x-kxm-delivery-id": input.deliveryId,
|
|
1453
|
+
"x-kxm-timestamp": timestamp,
|
|
1454
|
+
"x-kxm-signature": workflowWebhookSignature(input.secret, input.scope, timestamp, input.deliveryId, input.body),
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1389
1458
|
/** Resolve a declared transition rule for a stage outcome, or undefined when
|
|
1390
1459
|
* the outcome keeps the v0.4 default edges. */
|
|
1391
1460
|
function resolveOutcomeRule(stage: WorkflowStageState, outcomeKey: string): WorkflowTransitionRule | undefined {
|
package/schemas/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Runtime-local records, and JSON events/results for the planned KXM contract.
|
|
|
28
28
|
one validation layer; cross-file references, state-machine semantics,
|
|
29
29
|
permission diffs, model diversity, path portability, and snapshot reproduction
|
|
30
30
|
are deterministic semantic checks described in
|
|
31
|
-
[`docs/contracts/validation.md`](
|
|
31
|
+
[`docs/contracts/validation.md`](../docs/contracts/validation.md).
|
|
32
32
|
|
|
33
33
|
Unknown fields fail closed. A new field requires a reviewed schema revision;
|
|
34
34
|
do not add generic metadata escape hatches to event or synchronization payloads.
|
|
@@ -423,10 +423,14 @@ export async function runRealSmoke(options = {}) {
|
|
|
423
423
|
stage = "workflow-journal-checkpoint";
|
|
424
424
|
const resumedOperator = values["durable-restart-resume"];
|
|
425
425
|
const payload = JSON.stringify({ event: "smoke.requested" });
|
|
426
|
+
// KXM webhook contract (workflowWebhookSignedMaterial in plugins/kxm/src/workflow.ts).
|
|
427
|
+
const deliveryId = `smoke-${randomUUID()}`;
|
|
428
|
+
const timestamp = String(Math.floor(Date.now() / 1_000));
|
|
429
|
+
const signedMaterial = ["kxm-webhook-v1", "start", timestamp, deliveryId, "real-pi-smoke", "", ""].join("\n") + "\n" + payload;
|
|
426
430
|
const started = await api(baseUrl, "/v1/webhooks/real-pi-smoke", {
|
|
427
431
|
method: "POST",
|
|
428
432
|
authToken,
|
|
429
|
-
headers: { "x-
|
|
433
|
+
headers: { "x-kxm-delivery-id": deliveryId, "x-kxm-timestamp": timestamp, "x-kxm-signature": `sha256=${createHmac("sha256", webhookSecret).update(signedMaterial).digest("hex")}` },
|
|
430
434
|
body: payload,
|
|
431
435
|
});
|
|
432
436
|
await api(baseUrl, `/v1/workflows/${encodeURIComponent(started.run.id)}/journal`, {
|
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
# Agent Communication Envelopes, Quality Gates, and Workflow Loops
|
|
2
|
-
|
|
3
|
-
This guide specifies the standard communication envelopes, quality gates, work loop topologies, and structural components used for deterministic agent-to-agent (A2A) handoffs within KXM.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
1. [Architectural Components for Multi-Agent Workflows](#architectural-components-for-multi-agent-workflows)
|
|
8
|
-
2. [Communication Envelopes for Agent Handoffs](#communication-envelopes-for-agent-handoffs)
|
|
9
|
-
3. [Work Loop Topologies](#work-loop-topologies)
|
|
10
|
-
4. [Practical Quality Gate Implementations](#practical-quality-gate-implementations)
|
|
11
|
-
5. [Summary Execution Checklist](#summary-execution-checklist)
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Architectural Components for Multi-Agent Workflows
|
|
16
|
-
|
|
17
|
-
A production multi-agent system is composed of five distinct subsystem layers. For area, workflow and role naming conventions, see the [workflow guide](workflow-guide.md).
|
|
18
|
-
|
|
19
|
-
```text
|
|
20
|
-
+------------------------------------------------------------------------+
|
|
21
|
-
| 1. ORCHESTRATION & STATE |
|
|
22
|
-
| Workflow Engine • Finite State Machine (DAG) • Transition Budgets |
|
|
23
|
-
+-----------------------------------┬------------------------------------+
|
|
24
|
-
|
|
|
25
|
-
v
|
|
26
|
-
+------------------------------------------------------------------------+
|
|
27
|
-
| 2. IDENTITY, ROUTING & CAPABILITIES |
|
|
28
|
-
| Agent Registry • Role Profiles • Tool Policies • Provider Diversity |
|
|
29
|
-
+-----------------------------------┬------------------------------------+
|
|
30
|
-
|
|
|
31
|
-
v
|
|
32
|
-
+------------------------------------------------------------------------+
|
|
33
|
-
| 3. STRUCTURED ENVELOPES & PROVENANCE |
|
|
34
|
-
| Assignment Manifests • Content Hashing (SHA256) • Hub Message Queue |
|
|
35
|
-
+-----------------------------------┬------------------------------------+
|
|
36
|
-
|
|
|
37
|
-
v
|
|
38
|
-
+------------------------------------------------------------------------+
|
|
39
|
-
| 4. DETERMINISTIC QUALITY GATES |
|
|
40
|
-
| Code Gates • Oracle Orbits • Dual-Critic Quorum • Policy Filters |
|
|
41
|
-
+-----------------------------------┬------------------------------------+
|
|
42
|
-
|
|
|
43
|
-
v
|
|
44
|
-
+------------------------------------------------------------------------+
|
|
45
|
-
| 5. OBSERVABILITY & RECOVERY ENGINE |
|
|
46
|
-
| Cost Telemetry • Step Attempt Limits • Back-Edge Relief • RCA Log |
|
|
47
|
-
+------------------------------------------------------------------------+
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Component Responsibility Matrix
|
|
51
|
-
|
|
52
|
-
| Component | Responsibility | Failure Mode Prevented |
|
|
53
|
-
|---|---|---|
|
|
54
|
-
| **Authoritative Coordinator** | Drives the lifecycle DAG, creates attempt-bound steps, and computes plan hashes. | Uncoordinated agent collisions and out-of-order execution. |
|
|
55
|
-
| **Workspace Isolation** | Read/write sandboxing per step (e.g., git branch, worktree, or memory space). | Uncontrolled file overwrite and dirty uncommitted state leakage. |
|
|
56
|
-
| **Durable Journal** | Append-only event store recording plans, decisions, contradictions, and artifacts. | Context amnesia across agent handoffs and non-reproducible runs. |
|
|
57
|
-
| **Routing & Role Policy** | Enforces provider diversity (e.g., Writer != Critic) and cost-tier constraints. | Monoculture bias and assigning expensive frontier models to log parsing. |
|
|
58
|
-
| **Transition Budgeter** | Restricts maximum retries and total edge transitions per workflow run. | Infinite retry loops and runaway token billing. |
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Communication Envelopes for Agent Handoffs
|
|
63
|
-
|
|
64
|
-
In multi-agent systems and production workflow orchestrators, agent handoffs require structured, validated, and deterministic communication envelopes. Passing unstructured text between agents leads to context loss, untracked spend, unprovable reviews, and broken automation loops.
|
|
65
|
-
|
|
66
|
-
### 1. Task Delegation & Context Assignment Envelope (`kxm.assignment-request.v1`)
|
|
67
|
-
|
|
68
|
-
Used by a **Planner / Coordinator** to hand off bounded, non-overlapping work to an **Implementer / Writer Agent**. It encapsulates repository state, strict tool/permission boundaries, and verifiable acceptance criteria.
|
|
69
|
-
|
|
70
|
-
```json
|
|
71
|
-
{
|
|
72
|
-
"schema": "kxm.assignment-request.v1",
|
|
73
|
-
"assignmentId": "asgn_01J7N8K4D9W2X0B6",
|
|
74
|
-
"runId": "run_01J7N8J0P4K7M8Q1",
|
|
75
|
-
"projectId": "proj_kxm_core",
|
|
76
|
-
"stepId": "implement-auth-contracts",
|
|
77
|
-
"attempt": 1,
|
|
78
|
-
"createdAt": "2026-09-06T22:50:00.000Z",
|
|
79
|
-
"expiresAt": "2026-09-06T23:20:00.000Z",
|
|
80
|
-
"routing": {
|
|
81
|
-
"targetRole": "implementer",
|
|
82
|
-
"recommendedModel": "x-ai/grok-4.6",
|
|
83
|
-
"harness": "grok",
|
|
84
|
-
"reasoningEffort": "medium",
|
|
85
|
-
"economicBand": "tier-2"
|
|
86
|
-
},
|
|
87
|
-
"context": {
|
|
88
|
-
"git": {
|
|
89
|
-
"branch": "cursor/auth-contracts-82b9",
|
|
90
|
-
"baseCommit": "e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5",
|
|
91
|
-
"workingDirectory": "/workspace"
|
|
92
|
-
},
|
|
93
|
-
"inputs": [
|
|
94
|
-
{
|
|
95
|
-
"type": "spec",
|
|
96
|
-
"path": "docs/specs/auth-protocol-v2.md",
|
|
97
|
-
"sha256": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
"type": "interface",
|
|
101
|
-
"path": "src/types/auth.ts",
|
|
102
|
-
"sha256": "8f4b23c6d123e4a901928bcde98123ef654321ab987654321fe4567890abcdef"
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
"privateHandoffNotes": "Prior attempt failed on TypeScript strict null checks in SessionTokenValidator. Do not relax tsconfig; explicitly guard undefined header payloads."
|
|
106
|
-
},
|
|
107
|
-
"constraints": {
|
|
108
|
-
"maxTokensOut": 4096,
|
|
109
|
-
"timeoutMs": 1800000,
|
|
110
|
-
"toolPolicy": {
|
|
111
|
-
"allowedTools": ["Read", "Write", "StrReplace", "Shell"],
|
|
112
|
-
"deniedCommands": ["git push --force", "rm -rf", "npm publish"]
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
"acceptanceGate": {
|
|
116
|
-
"command": "npm run verify",
|
|
117
|
-
"deterministicChecks": ["typecheck", "test", "lint:docs", "check:generated"]
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### 2. Standard Worker Result & Execution Envelope (`kxm.worker-result.v1`)
|
|
123
|
-
|
|
124
|
-
Emitted by an **Implementer / Gate Worker** back to the orchestrator upon completion. It couples the outcome with artifact references and deterministic verification evidence.
|
|
125
|
-
|
|
126
|
-
```json
|
|
127
|
-
{
|
|
128
|
-
"schema": "kxm.worker-result.v1",
|
|
129
|
-
"worker": {
|
|
130
|
-
"schema": "kxm.worker.v1",
|
|
131
|
-
"kind": "agent",
|
|
132
|
-
"driver": "ai",
|
|
133
|
-
"name": "grok-writer-01",
|
|
134
|
-
"model": "x-ai/grok-4.6",
|
|
135
|
-
"thinking": "medium"
|
|
136
|
-
},
|
|
137
|
-
"command": "implement-auth-contracts",
|
|
138
|
-
"ok": true,
|
|
139
|
-
"outcome": "passed",
|
|
140
|
-
"createdAt": "2026-09-06T23:04:12.450Z",
|
|
141
|
-
"summary": "Implemented W3C DTCG compliant session validation and token refresh logic passing all verification suites.",
|
|
142
|
-
"changes": {
|
|
143
|
-
"filesModified": [
|
|
144
|
-
"src/auth/session-validator.ts",
|
|
145
|
-
"test/auth/session-validator.test.ts"
|
|
146
|
-
],
|
|
147
|
-
"filesCreated": [
|
|
148
|
-
"src/types/session-tokens.ts"
|
|
149
|
-
],
|
|
150
|
-
"filesDeleted": []
|
|
151
|
-
},
|
|
152
|
-
"artifacts": [
|
|
153
|
-
{
|
|
154
|
-
"name": "unit-test-tap-output",
|
|
155
|
-
"path": "artifacts/test-results.tap",
|
|
156
|
-
"sha256": "d41d8cd98f00b204e9800998ecf8427e100808a94b5e28a6f3b0e2f5b82a7a4f"
|
|
157
|
-
}
|
|
158
|
-
],
|
|
159
|
-
"telemetry": {
|
|
160
|
-
"tokensIn": 18450,
|
|
161
|
-
"tokensOut": 1240,
|
|
162
|
-
"cacheReadTokens": 14200,
|
|
163
|
-
"durationMs": 14820,
|
|
164
|
-
"costUsd": 0.0443
|
|
165
|
-
},
|
|
166
|
-
"verifierOutcome": {
|
|
167
|
-
"gateCommand": "npm run verify",
|
|
168
|
-
"exitCode": 0,
|
|
169
|
-
"passed": true
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### 3. Independent Critic & Quorum Review Envelope (`kxm.review-envelope.v1`)
|
|
175
|
-
|
|
176
|
-
Used in multi-agent critic loops (e.g., dual-critic acceptance between **Claude Fable** and **Codex Sol**). It records structured pass/fail decisions, non-negotiable blockers, and rubric criteria.
|
|
177
|
-
|
|
178
|
-
```json
|
|
179
|
-
{
|
|
180
|
-
"schema": "kxm.review-envelope.v1",
|
|
181
|
-
"reviewId": "rev_01J7N93M2P8Q4R6T",
|
|
182
|
-
"assignmentId": "asgn_01J7N8K4D9W2X0B6",
|
|
183
|
-
"reviewer": {
|
|
184
|
-
"agentName": "claude-fable-critic",
|
|
185
|
-
"role": "architecture_and_permissions",
|
|
186
|
-
"model": "anthropic/claude-fable-5.1"
|
|
187
|
-
},
|
|
188
|
-
"createdAt": "2026-09-06T23:08:45.100Z",
|
|
189
|
-
"verdict": "PASS",
|
|
190
|
-
"summary": "Security boundaries, zero-trust token scopes, and fail-closed error handling verified.",
|
|
191
|
-
"rubricEvaluation": [
|
|
192
|
-
{
|
|
193
|
-
"criterion": "permission_isolation",
|
|
194
|
-
"status": "passed",
|
|
195
|
-
"notes": "Token claims strictly enforce tenant isolation."
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
"criterion": "fail_closed_semantics",
|
|
199
|
-
"status": "passed",
|
|
200
|
-
"notes": "Expired or malformed tokens trigger immediate 401 without stack leakage."
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
"criterion": "backward_compatibility_brake",
|
|
204
|
-
"status": "passed",
|
|
205
|
-
"notes": "Brakes added for legacy header formats; no dual-naming shims introduced."
|
|
206
|
-
}
|
|
207
|
-
],
|
|
208
|
-
"blockers": [],
|
|
209
|
-
"advisoryNotes": [
|
|
210
|
-
"Consider adding rate-limiting telemetry to token revocation endpoints in Phase 4."
|
|
211
|
-
]
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### 4. Peer Request & Workflow Message Context Envelope (`kxm.message-record.v1`)
|
|
216
|
-
|
|
217
|
-
When agents communicate across a central hub (HTTP/SSE), this envelope ensures message delivery, correlation, hop limits, and cryptographic tie-in to the active workflow stage.
|
|
218
|
-
|
|
219
|
-
```json
|
|
220
|
-
{
|
|
221
|
-
"id": "msg_01J7N98K12L3M4N5",
|
|
222
|
-
"project": "proj_kxm_core",
|
|
223
|
-
"from": "agent_coordinator_main",
|
|
224
|
-
"fromName": "Lead Orchestrator",
|
|
225
|
-
"to": "agent_critic_sol",
|
|
226
|
-
"toName": "Codex CLI Critic",
|
|
227
|
-
"delivery": "steer",
|
|
228
|
-
"status": "queued",
|
|
229
|
-
"hops": 1,
|
|
230
|
-
"maxHops": 3,
|
|
231
|
-
"correlationId": "corr_01J7N98K00AA11BB",
|
|
232
|
-
"createdAt": "2026-09-06T23:10:00.000Z",
|
|
233
|
-
"expiresAt": "2026-09-07T23:10:00.000Z",
|
|
234
|
-
"workflowContext": {
|
|
235
|
-
"schema": "pi-mesh.workflow-message-context.v1",
|
|
236
|
-
"runId": "run_01J7N8J0P4K7M8Q1",
|
|
237
|
-
"stageId": "independent_peer_review",
|
|
238
|
-
"requirementKey": "cli_contracts_critic",
|
|
239
|
-
"attempt": 1
|
|
240
|
-
},
|
|
241
|
-
"content": "Please review git diff on branch cursor/auth-contracts-82b9 against OpenAPI 3.1 specifications. Verify schema alignment and CLI argument syntax."
|
|
242
|
-
}
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
### 5. Multi-Stage Incident Diagnostic & RCA Envelope (`kxm.diagnostic-handoff.v1`)
|
|
246
|
-
|
|
247
|
-
Used in debugging pipelines where Tier-0 ingestion models (e.g., `deepseek-v4-flash`) distill huge telemetry dumps before handing off to deep forensic reasoners (e.g., `openai/o3` or `claude-opus-5`).
|
|
248
|
-
|
|
249
|
-
```json
|
|
250
|
-
{
|
|
251
|
-
"schema": "kxm.diagnostic-handoff.v1",
|
|
252
|
-
"incidentId": "inc_20260906_db_deadlock",
|
|
253
|
-
"timestamp": "2026-09-06T23:15:00.000Z",
|
|
254
|
-
"triageLevel": "SEV-1",
|
|
255
|
-
"ingestionSummary": {
|
|
256
|
-
"rawLogSizeMb": 480.5,
|
|
257
|
-
"distilledEventCount": 12,
|
|
258
|
-
"filterModel": "deepseek/deepseek-v4-flash-0731",
|
|
259
|
-
"compressionRatio": "99.2%"
|
|
260
|
-
},
|
|
261
|
-
"isolatedFaultBoundary": {
|
|
262
|
-
"service": "billing-pipeline-worker",
|
|
263
|
-
"subsystem": "pg-transaction-pool",
|
|
264
|
-
"callSite": "src/transactions/settlement.ts:142",
|
|
265
|
-
"exception": "DeadlockDetectedError: Process 41829 waits for ShareLock on transaction 891273"
|
|
266
|
-
},
|
|
267
|
-
"threadContentionTrace": [
|
|
268
|
-
{
|
|
269
|
-
"threadId": "worker-pool-8",
|
|
270
|
-
"holdingLock": "table:invoices (row id: 8941)",
|
|
271
|
-
"waitingOnLock": "table:wallets (row id: 102)"
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
"threadId": "worker-pool-14",
|
|
275
|
-
"holdingLock": "table:wallets (row id: 102)",
|
|
276
|
-
"waitingOnLock": "table:invoices (row id: 8941)"
|
|
277
|
-
}
|
|
278
|
-
],
|
|
279
|
-
"reproContext": {
|
|
280
|
-
"environment": "linux 6.12.94+ / Node 22.19.0",
|
|
281
|
-
"isolatedPayload": {
|
|
282
|
-
"concurrentBatches": 2,
|
|
283
|
-
"settlementIds": ["set_991", "set_992"]
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
"forensicDirective": "Determine lock ordering asymmetry between invoice reconciliation and wallet balance deductions, and draft deterministic mutex/locking patch."
|
|
287
|
-
}
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
---
|
|
291
|
-
|
|
292
|
-
## Work Loop Topologies
|
|
293
|
-
|
|
294
|
-
Agent workflows generally follow one of three operational loop architectures:
|
|
295
|
-
|
|
296
|
-
### Loop Pattern A: The Verification Loop (Plan -> Write -> Gate -> Fix)
|
|
297
|
-
|
|
298
|
-
Used for new feature development, code refactoring, and bug patching.
|
|
299
|
-
|
|
300
|
-
```text
|
|
301
|
-
+---------------+
|
|
302
|
-
| 1. Plan/Spec | (Fable / Architecture Critic)
|
|
303
|
-
+-------┬-------+
|
|
304
|
-
| [Plan Hash Generated: sha256]
|
|
305
|
-
v
|
|
306
|
-
+---------------+
|
|
307
|
-
+--->| 2. Implement | (Grok 4.6 / Qwen Coder)
|
|
308
|
-
| +-------┬-------+
|
|
309
|
-
| | [Emits: kxm.worker-result.v1 + Git Commit]
|
|
310
|
-
| v
|
|
311
|
-
| +---------------+ Passed
|
|
312
|
-
| | 3. Code Gate +-------------> [Step Completed]
|
|
313
|
-
| +-------┬-------+
|
|
314
|
-
| | Failed (Exit Code != 0)
|
|
315
|
-
+------------+ (Max 2 Attempts -> Else Back-Edge to Plan)
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
#### Workflow Definition Example (`workflow.yaml` snippet)
|
|
319
|
-
|
|
320
|
-
```yaml
|
|
321
|
-
steps:
|
|
322
|
-
- id: implement-feature
|
|
323
|
-
kind: agent
|
|
324
|
-
agent: writer-grok
|
|
325
|
-
maxAttempts: 2
|
|
326
|
-
description: "Write code matching the approved plan specification."
|
|
327
|
-
repositories:
|
|
328
|
-
backend: write
|
|
329
|
-
requiredEvidence:
|
|
330
|
-
- key: implementation
|
|
331
|
-
kind: assignment-result
|
|
332
|
-
on:
|
|
333
|
-
passed: verify-gate
|
|
334
|
-
failed:
|
|
335
|
-
target: $terminal
|
|
336
|
-
terminalStatus: failed
|
|
337
|
-
|
|
338
|
-
- id: verify-gate
|
|
339
|
-
kind: gate
|
|
340
|
-
command: "npm run verify"
|
|
341
|
-
description: "Execute compiler check, test suites, and documentation linters."
|
|
342
|
-
on:
|
|
343
|
-
passed: dual-critic-review
|
|
344
|
-
failed:
|
|
345
|
-
target: implement-feature
|
|
346
|
-
backEdgeBudget: 2
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
### Loop Pattern B: Mixture-of-Agents (MOA) Dual-Critic Quorum Loop
|
|
350
|
-
|
|
351
|
-
Used for architectural RFCs, high-stakes security patches, and complex multi-repo deliveries.
|
|
352
|
-
|
|
353
|
-
```text
|
|
354
|
-
+----------------------+
|
|
355
|
-
| 1. Propose Artifact | (Author)
|
|
356
|
-
+----------┬-----------+
|
|
357
|
-
|
|
|
358
|
-
+----------------+----------------+
|
|
359
|
-
v v
|
|
360
|
-
+-----------------+ +-----------------+
|
|
361
|
-
│ Critic A: Fable │ │ Critic B: Sol │
|
|
362
|
-
│ (Architecture) │ │ (CLI/Contracts) │
|
|
363
|
-
+--------┬--------+ +--------┬--------+
|
|
364
|
-
| |
|
|
365
|
-
+----------------┬----------------+
|
|
366
|
-
| [Hub Derive: 2/2 Passed Quorum]
|
|
367
|
-
v
|
|
368
|
-
+-----------------+ Quorum Met
|
|
369
|
-
| Quorum Join +--------------> [Pass to Delivery]
|
|
370
|
-
+--------┬--------+
|
|
371
|
-
| Blockers Present (Dissent)
|
|
372
|
-
v
|
|
373
|
-
+-----------------+
|
|
374
|
-
| 2. Remediation | (Author)
|
|
375
|
-
+-----------------+
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
#### Quorum Policy Configuration (`policy.yaml` snippet)
|
|
379
|
-
|
|
380
|
-
```yaml
|
|
381
|
-
joinPolicy:
|
|
382
|
-
strategy: quorum
|
|
383
|
-
minimumPassed: 2
|
|
384
|
-
cancelRemaining: true
|
|
385
|
-
|
|
386
|
-
producerPolicy:
|
|
387
|
-
minimumProducers: 2
|
|
388
|
-
distinctBy:
|
|
389
|
-
- provider
|
|
390
|
-
- model
|
|
391
|
-
eligibleAgents:
|
|
392
|
-
- claude-fable-critic
|
|
393
|
-
- gpt-sol-critic
|
|
394
|
-
acceptedStatuses:
|
|
395
|
-
- passed
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
### Loop Pattern C: Repro-Before-Oracle Loop
|
|
399
|
-
|
|
400
|
-
Used for production incident triage, race condition diagnosis, and regression repair.
|
|
401
|
-
|
|
402
|
-
```text
|
|
403
|
-
+----------------------+
|
|
404
|
-
| 1. Incident Telemetry|
|
|
405
|
-
+----------┬-----------+
|
|
406
|
-
v
|
|
407
|
-
+----------------------+
|
|
408
|
-
| 2. Reproducer Agent | (Writes isolated test that asserts failure)
|
|
409
|
-
+----------┬-----------+
|
|
410
|
-
v
|
|
411
|
-
+----------------------+ Test Must Fail (Exit != 0)
|
|
412
|
-
| 3. Repro Gate Check +--------------+
|
|
413
|
-
+----------┬-----------+ |
|
|
414
|
-
| Fails to Repro v
|
|
415
|
-
| +----------------------+
|
|
416
|
-
v | 4. Implement Fix |
|
|
417
|
-
[Reject / Re-triage] +----------┬-----------+
|
|
418
|
-
|
|
|
419
|
-
v
|
|
420
|
-
+----------------------+ Test Must Pass (Exit == 0)
|
|
421
|
-
| 5. Oracle Gate Check +-------------> [Deliver Patch]
|
|
422
|
-
+----------------------+
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
---
|
|
426
|
-
|
|
427
|
-
## Practical Quality Gate Implementations
|
|
428
|
-
|
|
429
|
-
A quality gate is a **deterministic barrier** that evaluates evidence against non-negotiable assertions.
|
|
430
|
-
|
|
431
|
-
### Gate 1: The Deterministic Code Gate (Deterministic CLI)
|
|
432
|
-
|
|
433
|
-
This gate runs headless in CI/CD or local sandboxes. It executes code linters, typecheckers, unit tests, and generated asset verifiers.
|
|
434
|
-
|
|
435
|
-
#### Verification Script (`scripts/verify-gate.mjs`)
|
|
436
|
-
|
|
437
|
-
```javascript
|
|
438
|
-
#!/usr/bin/env node
|
|
439
|
-
import { execSync } from "node:child_process";
|
|
440
|
-
import { writeFileSync } from "node:fs";
|
|
441
|
-
|
|
442
|
-
const checks = [
|
|
443
|
-
{ name: "TypeScript Typecheck", cmd: "npx tsc --noEmit" },
|
|
444
|
-
{ name: "Documentation Linter", cmd: "npx markdownlint-cli2 '**/*.md' '#node_modules'" },
|
|
445
|
-
{ name: "Unit & Integration Tests", cmd: "npm test" },
|
|
446
|
-
{ name: "Generated Artifact Drift", cmd: "npm run check:generated" }
|
|
447
|
-
];
|
|
448
|
-
|
|
449
|
-
const results = [];
|
|
450
|
-
let gatePassed = true;
|
|
451
|
-
|
|
452
|
-
for (const check of checks) {
|
|
453
|
-
const start = Date.now();
|
|
454
|
-
try {
|
|
455
|
-
execSync(check.cmd, { stdio: "pipe", encoding: "utf8" });
|
|
456
|
-
results.push({ name: check.name, status: "passed", durationMs: Date.now() - start });
|
|
457
|
-
} catch (error) {
|
|
458
|
-
gatePassed = false;
|
|
459
|
-
results.push({
|
|
460
|
-
name: check.name,
|
|
461
|
-
status: "failed",
|
|
462
|
-
durationMs: Date.now() - start,
|
|
463
|
-
errorOutput: error.stderr || error.stdout || error.message
|
|
464
|
-
});
|
|
465
|
-
break; // Fail-closed immediately
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const gateResultEnvelope = {
|
|
470
|
-
schema: "kxm.worker-result.v1",
|
|
471
|
-
worker: { schema: "kxm.worker.v1", kind: "gate", driver: "code", name: "deterministic-verify-gate" },
|
|
472
|
-
command: "npm run verify",
|
|
473
|
-
ok: gatePassed,
|
|
474
|
-
outcome: gatePassed ? "passed" : "failed",
|
|
475
|
-
createdAt: new Date().toISOString(),
|
|
476
|
-
summary: gatePassed ? "All 4 verification stages passed cleanly." : `Gate failure on stage: ${results.at(-1).name}`,
|
|
477
|
-
checks: results
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
writeFileSync(".kxm/state/gate-result.json", JSON.stringify(gateResultEnvelope, null, 2));
|
|
481
|
-
process.exit(gatePassed ? 0 : 1);
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
### Gate 2: The Multi-Agent Quorum Gate (Hub Verification)
|
|
485
|
-
|
|
486
|
-
Verifies that required review evidence originates from **eligible independent producers** without relying on self-reported agent summaries.
|
|
487
|
-
|
|
488
|
-
#### Quorum Evaluation Logic (`plugins/kxm/src/arbiter.ts` snippet)
|
|
489
|
-
|
|
490
|
-
```typescript
|
|
491
|
-
export interface QuorumRequirement {
|
|
492
|
-
stageId: string;
|
|
493
|
-
minProducers: number;
|
|
494
|
-
distinctProviders: boolean;
|
|
495
|
-
requiredReviews: Array<{ reviewerId: string; provider: string; verdict: "PASS" | "FAIL" }>;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
export function evaluateReviewQuorum(req: QuorumRequirement): { passed: boolean; reason: string } {
|
|
499
|
-
const passingReviews = req.requiredReviews.filter(r => r.verdict === "PASS");
|
|
500
|
-
|
|
501
|
-
if (passingReviews.length < req.minProducers) {
|
|
502
|
-
return {
|
|
503
|
-
passed: false,
|
|
504
|
-
reason: `Quorum incomplete: received ${passingReviews.length}/${req.minProducers} PASS verdicts.`
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (req.distinctProviders) {
|
|
509
|
-
const providers = new Set(passingReviews.map(r => r.provider));
|
|
510
|
-
if (providers.size < req.minProducers) {
|
|
511
|
-
return {
|
|
512
|
-
passed: false,
|
|
513
|
-
reason: "Provider diversity violation: passing reviews must originate from distinct model providers."
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
return { passed: true, reason: "Quorum verified with independent provider consensus." };
|
|
519
|
-
}
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
### Gate 3: The Content & Plan Integrity Gate (SHA-256 Oracle)
|
|
523
|
-
|
|
524
|
-
Ensures that an implementer or delivery agent has not drifted from the exact specification approved during the planning phase.
|
|
525
|
-
|
|
526
|
-
```typescript
|
|
527
|
-
import { createHash } from "node:crypto";
|
|
528
|
-
import { readFileSync } from "node:fs";
|
|
529
|
-
|
|
530
|
-
export function verifyPlanIntegrity(planFilePath: string, expectedPlanHash: string): boolean {
|
|
531
|
-
const fileContent = readFileSync(planFilePath, "utf8");
|
|
532
|
-
const actualHash = createHash("sha256").update(fileContent.trim()).digest("hex");
|
|
533
|
-
|
|
534
|
-
if (actualHash !== expectedPlanHash) {
|
|
535
|
-
throw new Error(
|
|
536
|
-
`Plan Integrity Gate Failed: Expected hash ${expectedPlanHash}, but found ${actualHash}. Specification modified without re-approval.`
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
return true;
|
|
540
|
-
}
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
---
|
|
544
|
-
|
|
545
|
-
## Summary Execution Checklist
|
|
546
|
-
|
|
547
|
-
```text
|
|
548
|
-
[ ] 1. Bounded Context: Is the handoff constrained by an immutable commit SHA and plan hash?
|
|
549
|
-
[ ] 2. Strict Schemas: Do all input/output payloads validate against strict JSON schemas?
|
|
550
|
-
[ ] 3. Provider Independence: Are critics running on different model providers than writers?
|
|
551
|
-
[ ] 4. Deterministic Brakes: Is there a code gate (e.g., npm run verify) before any human review?
|
|
552
|
-
[ ] 5. Finite Transitions: Are back-edge loops capped to <= 2 retry attempts before escalation?
|
|
553
|
-
```
|