@kashscript/hudhud 0.1.0
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/LICENSE +133 -0
- package/README.md +67 -0
- package/dist/adapters/prisma.d.ts +170 -0
- package/dist/adapters/prisma.d.ts.map +1 -0
- package/dist/adapters/prisma.js +185 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/anchor/index.d.ts +55 -0
- package/dist/anchor/index.d.ts.map +1 -0
- package/dist/anchor/index.js +97 -0
- package/dist/anchor/index.js.map +1 -0
- package/dist/certificate/certificate.d.ts +115 -0
- package/dist/certificate/certificate.d.ts.map +1 -0
- package/dist/certificate/certificate.js +221 -0
- package/dist/certificate/certificate.js.map +1 -0
- package/dist/certificate/html.d.ts +10 -0
- package/dist/certificate/html.d.ts.map +1 -0
- package/dist/certificate/html.js +141 -0
- package/dist/certificate/html.js.map +1 -0
- package/dist/certificate/index.d.ts +3 -0
- package/dist/certificate/index.d.ts.map +1 -0
- package/dist/certificate/index.js +5 -0
- package/dist/certificate/index.js.map +1 -0
- package/dist/did-registry/index.d.ts +3 -0
- package/dist/did-registry/index.d.ts.map +1 -0
- package/dist/did-registry/index.js +10 -0
- package/dist/did-registry/index.js.map +1 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/exception/index.d.ts +97 -0
- package/dist/exception/index.d.ts.map +1 -0
- package/dist/exception/index.js +144 -0
- package/dist/exception/index.js.map +1 -0
- package/dist/identity/index.d.ts +33 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +36 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger/event-schema.d.ts +97 -0
- package/dist/ledger/event-schema.d.ts.map +1 -0
- package/dist/ledger/event-schema.js +54 -0
- package/dist/ledger/event-schema.js.map +1 -0
- package/dist/ledger/index.d.ts +7 -0
- package/dist/ledger/index.d.ts.map +1 -0
- package/dist/ledger/index.js +14 -0
- package/dist/ledger/index.js.map +1 -0
- package/dist/ledger/mutex.d.ts +9 -0
- package/dist/ledger/mutex.d.ts.map +1 -0
- package/dist/ledger/mutex.js +36 -0
- package/dist/ledger/mutex.js.map +1 -0
- package/dist/ledger/store.d.ts +31 -0
- package/dist/ledger/store.d.ts.map +1 -0
- package/dist/ledger/store.js +66 -0
- package/dist/ledger/store.js.map +1 -0
- package/dist/ledger/writer.d.ts +69 -0
- package/dist/ledger/writer.d.ts.map +1 -0
- package/dist/ledger/writer.js +167 -0
- package/dist/ledger/writer.js.map +1 -0
- package/dist/mcp/allowlist.d.ts +53 -0
- package/dist/mcp/allowlist.d.ts.map +1 -0
- package/dist/mcp/allowlist.js +65 -0
- package/dist/mcp/allowlist.js.map +1 -0
- package/dist/mcp/client.d.ts +68 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +198 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +5 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/privacy/index.d.ts +21 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +96 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/runtime/dispatcher.d.ts +27 -0
- package/dist/runtime/dispatcher.d.ts.map +1 -0
- package/dist/runtime/dispatcher.js +66 -0
- package/dist/runtime/dispatcher.js.map +1 -0
- package/dist/runtime/escalation.d.ts +98 -0
- package/dist/runtime/escalation.d.ts.map +1 -0
- package/dist/runtime/escalation.js +188 -0
- package/dist/runtime/escalation.js.map +1 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +9 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/runner.d.ts +78 -0
- package/dist/runtime/runner.d.ts.map +1 -0
- package/dist/runtime/runner.js +145 -0
- package/dist/runtime/runner.js.map +1 -0
- package/dist/scope/index.d.ts +19 -0
- package/dist/scope/index.d.ts.map +1 -0
- package/dist/scope/index.js +44 -0
- package/dist/scope/index.js.map +1 -0
- package/dist/sop/compiler.d.ts +36 -0
- package/dist/sop/compiler.d.ts.map +1 -0
- package/dist/sop/compiler.js +54 -0
- package/dist/sop/compiler.js.map +1 -0
- package/dist/sop/index.d.ts +3 -0
- package/dist/sop/index.d.ts.map +1 -0
- package/dist/sop/index.js +5 -0
- package/dist/sop/index.js.map +1 -0
- package/dist/sop/service.d.ts +40 -0
- package/dist/sop/service.d.ts.map +1 -0
- package/dist/sop/service.js +140 -0
- package/dist/sop/service.js.map +1 -0
- package/package.json +112 -0
- package/src/adapters/prisma.ts +310 -0
- package/src/anchor/index.ts +149 -0
- package/src/certificate/certificate.ts +340 -0
- package/src/certificate/html.ts +156 -0
- package/src/certificate/index.ts +4 -0
- package/src/did-registry/index.ts +11 -0
- package/src/errors.ts +79 -0
- package/src/exception/index.ts +244 -0
- package/src/identity/index.ts +82 -0
- package/src/index.ts +33 -0
- package/src/ledger/event-schema.ts +61 -0
- package/src/ledger/index.ts +22 -0
- package/src/ledger/mutex.ts +37 -0
- package/src/ledger/store.ts +86 -0
- package/src/ledger/writer.ts +249 -0
- package/src/mcp/allowlist.ts +102 -0
- package/src/mcp/client.ts +284 -0
- package/src/mcp/index.ts +4 -0
- package/src/privacy/index.ts +123 -0
- package/src/runtime/dispatcher.ts +96 -0
- package/src/runtime/escalation.ts +292 -0
- package/src/runtime/index.ts +14 -0
- package/src/runtime/runner.ts +227 -0
- package/src/scope/index.ts +59 -0
- package/src/sop/compiler.ts +99 -0
- package/src/sop/index.ts +4 -0
- package/src/sop/service.ts +184 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/certificate/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,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;;8BAE1I,IAAI,CAAC,QAAQ,CAAC,MAAM;;eAEnC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;MAGjD,OAAO;;;;kCAIqB,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;kCACnC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;kCACnB,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,0BAA0B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC;;;wBAGhF,GAAG,CAAC,MAAM,CAAC,uGAAuG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;;qBAE9I,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/certificate/index.ts"],"names":[],"mappings":"AAEA,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/certificate/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAAiF;AACjF,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/did-registry/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @kashscript/hudhud/did-registry — DID → Ed25519 public-key resolution
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// The DID registry the ledger verifies actor signatures against. The interface
|
|
5
|
+
// + in-memory reference live in `@kashscript/attest` (seeded from the same
|
|
6
|
+
// Oreoasis `did-registry.ts` in M1); hudhud re-exports them so ventures reach
|
|
7
|
+
// the registry through the runtime, and add a durable/PDS resolver at swap.
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export { InMemoryDidRegistry } from "@kashscript/attest";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/did-registry/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wEAAwE;AACxE,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Base class for every error this package throws. */
|
|
2
|
+
export declare class HudhudError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
/** Thrown when an SOP manual cannot be compiled (cycle, malformed goto, empty). */
|
|
7
|
+
export declare class SopCompilationError extends HudhudError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/** Thrown when an MCP tool call exceeds the hard timeout. */
|
|
11
|
+
export declare class McpTimeoutError extends HudhudError {
|
|
12
|
+
readonly timeoutMs: number;
|
|
13
|
+
constructor(timeoutMs: number, message: string);
|
|
14
|
+
}
|
|
15
|
+
/** The security-violation discriminants raised at MCP dispatch time. */
|
|
16
|
+
export type McpSecurityViolationReason = "TOOL_NOT_ALLOWLISTED" | "ARG_NOT_ALLOWED" | "REQUIRED_ARG_MISSING" | "TOOL_NAME_MALFORMED" | "SCOPE_VIOLATION" | "CIRCUIT_OPEN";
|
|
17
|
+
/** Thrown when a dispatch is refused by the allowlist / scope / breaker gates.
|
|
18
|
+
* `track` mirrors the Oreoasis four-track wire vocabulary. */
|
|
19
|
+
export declare class McpSecurityViolationError extends HudhudError {
|
|
20
|
+
readonly reason: McpSecurityViolationReason;
|
|
21
|
+
readonly track: "error" | "security";
|
|
22
|
+
constructor(reason: McpSecurityViolationReason, message: string, track?: "error" | "security");
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when a required exception classification is missing/invalid — the
|
|
25
|
+
* mandatory `failureClass` gate (no "unclassified" state is representable). */
|
|
26
|
+
export declare class ExceptionClassificationError extends HudhudError {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
/** Thrown by the ForensicLedgerService append pipeline (stepIndex mismatch,
|
|
30
|
+
* signature-verify failure, store write failure). Ledger *tamper* detected by
|
|
31
|
+
* the forensic scan surfaces as attest's `TamperError`, not this. */
|
|
32
|
+
export declare class LedgerAppendError extends HudhudError {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAWA,sDAAsD;AACtD,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,mFAAmF;AACnF,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,6DAA6D;AAC7D,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBACf,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK/C;AAED,wEAAwE;AACxE,MAAM,MAAM,0BAA0B,GAClC,sBAAsB,GACtB,iBAAiB,GACjB,sBAAsB,GACtB,qBAAqB,GACrB,iBAAiB,GACjB,cAAc,CAAC;AAEnB;+DAC+D;AAC/D,qBAAa,yBAA0B,SAAQ,WAAW;IACxD,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC;gBACzB,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,GAAG,UAAuB;CAM1G;AAED;gFACgF;AAChF,qBAAa,4BAA6B,SAAQ,WAAW;gBAC/C,OAAO,EAAE,MAAM;CAI5B;AAED;;sEAEsE;AACtE,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @kashscript/hudhud — provider-neutral error vocabulary
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// Replaces the Oreoasis `@oreoasis/ks-bridge` exception classes with neutral
|
|
5
|
+
// `Hudhud*Error`s. A consuming venture maps them to its own HTTP envelope at
|
|
6
|
+
// its perimeter (ADR-0016 guard b); this package never emits a venture code.
|
|
7
|
+
//
|
|
8
|
+
// Ledger tamper is surfaced by `@kashscript/attest`'s `TamperError` (the ledger
|
|
9
|
+
// runs on attest) — hudhud does not re-declare it.
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/** Base class for every error this package throws. */
|
|
12
|
+
export class HudhudError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
constructor(code, message) {
|
|
15
|
+
super(`[${code}] ${message}`);
|
|
16
|
+
this.name = "HudhudError";
|
|
17
|
+
this.code = code;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Thrown when an SOP manual cannot be compiled (cycle, malformed goto, empty). */
|
|
21
|
+
export class SopCompilationError extends HudhudError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super("SOP_COMPILATION", message);
|
|
24
|
+
this.name = "SopCompilationError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Thrown when an MCP tool call exceeds the hard timeout. */
|
|
28
|
+
export class McpTimeoutError extends HudhudError {
|
|
29
|
+
timeoutMs;
|
|
30
|
+
constructor(timeoutMs, message) {
|
|
31
|
+
super("MCP_TIMEOUT", message);
|
|
32
|
+
this.name = "McpTimeoutError";
|
|
33
|
+
this.timeoutMs = timeoutMs;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Thrown when a dispatch is refused by the allowlist / scope / breaker gates.
|
|
37
|
+
* `track` mirrors the Oreoasis four-track wire vocabulary. */
|
|
38
|
+
export class McpSecurityViolationError extends HudhudError {
|
|
39
|
+
reason;
|
|
40
|
+
track;
|
|
41
|
+
constructor(reason, message, track = "security") {
|
|
42
|
+
super("MCP_SECURITY_VIOLATION", message);
|
|
43
|
+
this.name = "McpSecurityViolationError";
|
|
44
|
+
this.reason = reason;
|
|
45
|
+
this.track = track;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Thrown when a required exception classification is missing/invalid — the
|
|
49
|
+
* mandatory `failureClass` gate (no "unclassified" state is representable). */
|
|
50
|
+
export class ExceptionClassificationError extends HudhudError {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super("EXCEPTION_CLASSIFICATION", message);
|
|
53
|
+
this.name = "ExceptionClassificationError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Thrown by the ForensicLedgerService append pipeline (stepIndex mismatch,
|
|
57
|
+
* signature-verify failure, store write failure). Ledger *tamper* detected by
|
|
58
|
+
* the forensic scan surfaces as attest's `TamperError`, not this. */
|
|
59
|
+
export class LedgerAppendError extends HudhudError {
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super("LEDGER_APPEND", message);
|
|
62
|
+
this.name = "LedgerAppendError";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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G,KAAK,CAAC;IACrB,CAAC;CACF;AAED;gFACgF;AAChF,MAAM,OAAO,4BAA6B,SAAQ,WAAW;IAC3D,YAAY,OAAe;QACzB,KAAK,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAED;;sEAEsE;AACtE,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** The failure classes. No "unclassified": classification is mandatory. */
|
|
2
|
+
export declare const FAILURE_CLASSES: readonly ["judgment", "gap-filling", "ambiguous"];
|
|
3
|
+
export type FailureClass = (typeof FAILURE_CLASSES)[number];
|
|
4
|
+
/** DST so a classification signature can't replay as a ledger/attestation sig.
|
|
5
|
+
* Neutral default; a venture passes its own DST at swap for wire-compat. */
|
|
6
|
+
export declare const HUDHUD_EXCEPTION_CLASSIFICATION_DST: "kash-exception-classification-v1\n";
|
|
7
|
+
export declare const EXCEPTION_CLASSIFICATION_SCHEMA_VERSION: "exception-classification/1";
|
|
8
|
+
/** The mandatory gate — throws `ExceptionClassificationError` if `value` is
|
|
9
|
+
* absent/empty or not one of the classes. NOT merely the TS type. */
|
|
10
|
+
export declare function assertFailureClass(value: unknown): asserts value is FailureClass;
|
|
11
|
+
export interface ExceptionClassificationInput {
|
|
12
|
+
readonly failureClass: FailureClass;
|
|
13
|
+
readonly failureTag: string;
|
|
14
|
+
readonly workflowId: string;
|
|
15
|
+
readonly sopVersion: string;
|
|
16
|
+
readonly inputRef: string;
|
|
17
|
+
readonly contentHash: string;
|
|
18
|
+
readonly model: string;
|
|
19
|
+
readonly modelVersion: string;
|
|
20
|
+
readonly resolutionSummary: string;
|
|
21
|
+
readonly resolutionActionRefs: ReadonlyArray<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface ClassificationSignedEnvelope {
|
|
24
|
+
readonly alg: "ed25519";
|
|
25
|
+
readonly sig: string;
|
|
26
|
+
readonly dst: string;
|
|
27
|
+
readonly kid: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ExceptionClassificationRecord {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly schemaVersion: string;
|
|
32
|
+
readonly timestampIso: string;
|
|
33
|
+
readonly workflowId: string;
|
|
34
|
+
readonly sopVersion: string;
|
|
35
|
+
readonly inputRef: string;
|
|
36
|
+
readonly contentHash: string;
|
|
37
|
+
readonly model: string;
|
|
38
|
+
readonly modelVersion: string;
|
|
39
|
+
readonly failureClass: FailureClass;
|
|
40
|
+
readonly failureTag: string;
|
|
41
|
+
readonly operatorDid: string;
|
|
42
|
+
readonly resolutionSummary: string;
|
|
43
|
+
readonly resolutionActionRefs: ReadonlyArray<string>;
|
|
44
|
+
readonly escalationId: string | null;
|
|
45
|
+
readonly signoffLedgerStepIndex: number | null;
|
|
46
|
+
readonly signedEnvelope: ClassificationSignedEnvelope;
|
|
47
|
+
}
|
|
48
|
+
/** Mint + sign a classification record (id/timestamp minted into the signed
|
|
49
|
+
* payload). Throws the mandatory gate if `failureClass` is missing/invalid. */
|
|
50
|
+
export declare function buildSignedClassification(input: ExceptionClassificationInput, operator: {
|
|
51
|
+
readonly did: string;
|
|
52
|
+
readonly privateKey: Uint8Array;
|
|
53
|
+
}, link?: {
|
|
54
|
+
readonly escalationId?: string | null;
|
|
55
|
+
readonly signoffLedgerStepIndex?: number | null;
|
|
56
|
+
}): Promise<ExceptionClassificationRecord>;
|
|
57
|
+
/** Verify a record's operator signature. Returns false on a well-formed mismatch. */
|
|
58
|
+
export declare function verifyClassificationSignature(record: ExceptionClassificationRecord, operatorPublicKey: Uint8Array): Promise<boolean>;
|
|
59
|
+
export interface ExceptionClassificationStore {
|
|
60
|
+
append(record: ExceptionClassificationRecord): Promise<void>;
|
|
61
|
+
history(): Promise<ReadonlyArray<ExceptionClassificationRecord>>;
|
|
62
|
+
latest(): Promise<ExceptionClassificationRecord | null>;
|
|
63
|
+
byWorkflow(workflowId: string): Promise<ReadonlyArray<ExceptionClassificationRecord>>;
|
|
64
|
+
}
|
|
65
|
+
export declare class InMemoryExceptionClassificationStore implements ExceptionClassificationStore {
|
|
66
|
+
private readonly rows;
|
|
67
|
+
append(record: ExceptionClassificationRecord): Promise<void>;
|
|
68
|
+
history(): Promise<ReadonlyArray<ExceptionClassificationRecord>>;
|
|
69
|
+
latest(): Promise<ExceptionClassificationRecord | null>;
|
|
70
|
+
byWorkflow(workflowId: string): Promise<ReadonlyArray<ExceptionClassificationRecord>>;
|
|
71
|
+
}
|
|
72
|
+
export declare const EXCEPTION_DATASET_FORMAT_VERSION: "kash-exception-dataset/1";
|
|
73
|
+
export interface ExceptionClassificationDatasetExport {
|
|
74
|
+
readonly formatVersion: string;
|
|
75
|
+
readonly exportedAtIso: string;
|
|
76
|
+
readonly count: number;
|
|
77
|
+
readonly records: ReadonlyArray<ExceptionClassificationRecord>;
|
|
78
|
+
}
|
|
79
|
+
/** Bundle the dataset for hand-off (records carry their own signatures). */
|
|
80
|
+
export declare function exportExceptionClassificationDataset(records: ReadonlyArray<ExceptionClassificationRecord>, exportedAtIso?: string): ExceptionClassificationDatasetExport;
|
|
81
|
+
export interface WorkflowMonthCount {
|
|
82
|
+
readonly workflowId: string;
|
|
83
|
+
readonly month: string;
|
|
84
|
+
readonly count: number;
|
|
85
|
+
}
|
|
86
|
+
export interface ExceptionClassificationStats {
|
|
87
|
+
readonly total: number;
|
|
88
|
+
readonly classMix: Record<FailureClass, number>;
|
|
89
|
+
readonly perWorkflow: ReadonlyArray<{
|
|
90
|
+
readonly workflowId: string;
|
|
91
|
+
readonly count: number;
|
|
92
|
+
}>;
|
|
93
|
+
readonly perWorkflowOverTime: ReadonlyArray<WorkflowMonthCount>;
|
|
94
|
+
}
|
|
95
|
+
/** Class mix + per-workflow (+ over-time) exception counts (the rate numerator). */
|
|
96
|
+
export declare function computeExceptionClassificationStats(records: ReadonlyArray<ExceptionClassificationRecord>): ExceptionClassificationStats;
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exception/index.ts"],"names":[],"mappings":"AAiBA,2EAA2E;AAC3E,eAAO,MAAM,eAAe,mDAAoD,CAAC;AACjF,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5D;6EAC6E;AAC7E,eAAO,MAAM,mCAAmC,EAAG,oCAA6C,CAAC;AACjG,eAAO,MAAM,uCAAuC,EAAG,4BAAqC,CAAC;AAc7F;sEACsE;AACtE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAWhF;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,oBAAoB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,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,MAAiC,GAC/C,oCAAoC,CAEtC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,QAAQ,CAAC,mBAAmB,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;CACjE;AAQD,oFAAoF;AACpF,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,aAAa,CAAC,6BAA6B,CAAC,GACpD,4BAA4B,CAoB9B"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @kashscript/hudhud/exception — signed exception-classification dataset
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// The appreciating record of WHERE frontier models fail on real inputs and HOW
|
|
5
|
+
// a human resolved it. Two invariants make it an asset, not a log line:
|
|
6
|
+
// 1. MANDATORY — `failureClass` is required with NO "unclassified" member and
|
|
7
|
+
// NO default; `assertFailureClass` is the runtime belt (an untyped caller
|
|
8
|
+
// still cannot resolve without classifying).
|
|
9
|
+
// 2. SIGNED — the operator's Ed25519 key signs the record over its EXACT
|
|
10
|
+
// bytes (`id` + `timestampIso` minted INTO the signed payload).
|
|
11
|
+
// Ported from the oreoasis-core-host engine (M5); the DST is neutralized, the
|
|
12
|
+
// error reuses hudhud's `ExceptionClassificationError`, id generation inlined.
|
|
13
|
+
// ============================================================================
|
|
14
|
+
import { signEvent, verifyEvent } from "@kashscript/identity-core";
|
|
15
|
+
import { ExceptionClassificationError } from "../errors";
|
|
16
|
+
/** The failure classes. No "unclassified": classification is mandatory. */
|
|
17
|
+
export const FAILURE_CLASSES = ["judgment", "gap-filling", "ambiguous"];
|
|
18
|
+
/** DST so a classification signature can't replay as a ledger/attestation sig.
|
|
19
|
+
* Neutral default; a venture passes its own DST at swap for wire-compat. */
|
|
20
|
+
export const HUDHUD_EXCEPTION_CLASSIFICATION_DST = "kash-exception-classification-v1\n";
|
|
21
|
+
export const EXCEPTION_CLASSIFICATION_SCHEMA_VERSION = "exception-classification/1";
|
|
22
|
+
const SIGN_HEADER = { kind: "exception-classification/1" };
|
|
23
|
+
let lastIdMicros = 0;
|
|
24
|
+
function newRecordId() {
|
|
25
|
+
let micros = Date.now() * 1000;
|
|
26
|
+
if (micros <= lastIdMicros)
|
|
27
|
+
micros = lastIdMicros + 1;
|
|
28
|
+
lastIdMicros = micros;
|
|
29
|
+
const rand = crypto.getRandomValues(new Uint8Array(6));
|
|
30
|
+
let hex = "";
|
|
31
|
+
for (const b of rand)
|
|
32
|
+
hex += b.toString(16).padStart(2, "0");
|
|
33
|
+
return `exc_${micros.toString(36)}_${hex}`;
|
|
34
|
+
}
|
|
35
|
+
/** The mandatory gate — throws `ExceptionClassificationError` if `value` is
|
|
36
|
+
* absent/empty or not one of the classes. NOT merely the TS type. */
|
|
37
|
+
export function assertFailureClass(value) {
|
|
38
|
+
if (value === undefined || value === null || value === "") {
|
|
39
|
+
throw new ExceptionClassificationError(`FAILURE_CLASS_REQUIRED — an exception cannot be resolved without a failureClass (one of ${FAILURE_CLASSES.join(" | ")})`);
|
|
40
|
+
}
|
|
41
|
+
if (!FAILURE_CLASSES.includes(value)) {
|
|
42
|
+
throw new ExceptionClassificationError(`FAILURE_CLASS_INVALID — failureClass must be one of ${FAILURE_CLASSES.join(" | ")} (got ${String(value)})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function unsignedOf(record) {
|
|
46
|
+
const { signedEnvelope: _drop, ...rest } = record;
|
|
47
|
+
return rest;
|
|
48
|
+
}
|
|
49
|
+
/** Mint + sign a classification record (id/timestamp minted into the signed
|
|
50
|
+
* payload). Throws the mandatory gate if `failureClass` is missing/invalid. */
|
|
51
|
+
export async function buildSignedClassification(input, operator, link = {}) {
|
|
52
|
+
assertFailureClass(input.failureClass);
|
|
53
|
+
const unsigned = {
|
|
54
|
+
id: newRecordId(),
|
|
55
|
+
schemaVersion: EXCEPTION_CLASSIFICATION_SCHEMA_VERSION,
|
|
56
|
+
timestampIso: new Date().toISOString(),
|
|
57
|
+
workflowId: input.workflowId,
|
|
58
|
+
sopVersion: input.sopVersion,
|
|
59
|
+
inputRef: input.inputRef,
|
|
60
|
+
contentHash: input.contentHash,
|
|
61
|
+
model: input.model,
|
|
62
|
+
modelVersion: input.modelVersion,
|
|
63
|
+
failureClass: input.failureClass,
|
|
64
|
+
failureTag: input.failureTag,
|
|
65
|
+
operatorDid: operator.did,
|
|
66
|
+
resolutionSummary: input.resolutionSummary,
|
|
67
|
+
resolutionActionRefs: [...input.resolutionActionRefs],
|
|
68
|
+
escalationId: link.escalationId ?? null,
|
|
69
|
+
signoffLedgerStepIndex: link.signoffLedgerStepIndex ?? null,
|
|
70
|
+
};
|
|
71
|
+
const signed = await signEvent(SIGN_HEADER, unsigned, operator.privateKey, {
|
|
72
|
+
dst: HUDHUD_EXCEPTION_CLASSIFICATION_DST,
|
|
73
|
+
encoding: "hex",
|
|
74
|
+
kid: operator.did,
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
...unsigned,
|
|
78
|
+
signedEnvelope: { alg: "ed25519", sig: signed.sig, dst: HUDHUD_EXCEPTION_CLASSIFICATION_DST, kid: operator.did },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Verify a record's operator signature. Returns false on a well-formed mismatch. */
|
|
82
|
+
export async function verifyClassificationSignature(record, operatorPublicKey) {
|
|
83
|
+
return verifyEvent({
|
|
84
|
+
header: SIGN_HEADER,
|
|
85
|
+
body: unsignedOf(record),
|
|
86
|
+
signature: {
|
|
87
|
+
alg: "ed25519",
|
|
88
|
+
sig: record.signedEnvelope.sig,
|
|
89
|
+
dst: record.signedEnvelope.dst,
|
|
90
|
+
encoding: "hex",
|
|
91
|
+
kid: record.signedEnvelope.kid,
|
|
92
|
+
},
|
|
93
|
+
}, operatorPublicKey);
|
|
94
|
+
}
|
|
95
|
+
export class InMemoryExceptionClassificationStore {
|
|
96
|
+
rows = [];
|
|
97
|
+
async append(record) {
|
|
98
|
+
this.rows.push(record);
|
|
99
|
+
}
|
|
100
|
+
async history() {
|
|
101
|
+
return [...this.rows];
|
|
102
|
+
}
|
|
103
|
+
async latest() {
|
|
104
|
+
return this.rows.length === 0 ? null : this.rows[this.rows.length - 1];
|
|
105
|
+
}
|
|
106
|
+
async byWorkflow(workflowId) {
|
|
107
|
+
return this.rows.filter((r) => r.workflowId === workflowId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ── Export + stats ─────────────────────────────────────────────────────────
|
|
111
|
+
export const EXCEPTION_DATASET_FORMAT_VERSION = "kash-exception-dataset/1";
|
|
112
|
+
/** Bundle the dataset for hand-off (records carry their own signatures). */
|
|
113
|
+
export function exportExceptionClassificationDataset(records, exportedAtIso = new Date().toISOString()) {
|
|
114
|
+
return { formatVersion: EXCEPTION_DATASET_FORMAT_VERSION, exportedAtIso, count: records.length, records: [...records] };
|
|
115
|
+
}
|
|
116
|
+
function emptyClassMix() {
|
|
117
|
+
const mix = {};
|
|
118
|
+
for (const c of FAILURE_CLASSES)
|
|
119
|
+
mix[c] = 0;
|
|
120
|
+
return mix;
|
|
121
|
+
}
|
|
122
|
+
/** Class mix + per-workflow (+ over-time) exception counts (the rate numerator). */
|
|
123
|
+
export function computeExceptionClassificationStats(records) {
|
|
124
|
+
const classMix = emptyClassMix();
|
|
125
|
+
const perWorkflow = new Map();
|
|
126
|
+
const perWfMonth = new Map();
|
|
127
|
+
for (const r of records) {
|
|
128
|
+
classMix[r.failureClass] += 1;
|
|
129
|
+
perWorkflow.set(r.workflowId, (perWorkflow.get(r.workflowId) ?? 0) + 1);
|
|
130
|
+
const key = `${r.workflowId} ${r.timestampIso.slice(0, 7)}`;
|
|
131
|
+
perWfMonth.set(key, (perWfMonth.get(key) ?? 0) + 1);
|
|
132
|
+
}
|
|
133
|
+
const perWorkflowArr = [...perWorkflow.entries()]
|
|
134
|
+
.map(([workflowId, count]) => ({ workflowId, count }))
|
|
135
|
+
.sort((a, b) => (a.workflowId < b.workflowId ? -1 : 1));
|
|
136
|
+
const perWorkflowOverTime = [...perWfMonth.entries()]
|
|
137
|
+
.map(([key, count]) => {
|
|
138
|
+
const [workflowId, month] = key.split(" ");
|
|
139
|
+
return { workflowId: workflowId, month: month, count };
|
|
140
|
+
})
|
|
141
|
+
.sort((a, b) => (a.workflowId === b.workflowId ? (a.month < b.month ? -1 : 1) : a.workflowId < b.workflowId ? -1 : 1));
|
|
142
|
+
return { total: records.length, classMix, perWorkflow: perWorkflowArr, perWorkflowOverTime };
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exception/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,yEAAyE;AACzE,+EAA+E;AAC/E,+EAA+E;AAC/E,wEAAwE;AACxE,gFAAgF;AAChF,+EAA+E;AAC/E,kDAAkD;AAClD,2EAA2E;AAC3E,qEAAqE;AACrE,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAE/E,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAEzD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,WAAW,CAAU,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ks } from "@kashscript/identity-server";
|
|
2
|
+
/** The delegation the accountable identity carries: the agent acting for the owner. */
|
|
3
|
+
export interface AccountableActor {
|
|
4
|
+
/** The resource owner — a did:kash root (the token `sub`). */
|
|
5
|
+
readonly owner: string;
|
|
6
|
+
/** The delegated agent — a did:kash (the token `act.sub`). */
|
|
7
|
+
readonly agent: string;
|
|
8
|
+
}
|
|
9
|
+
export type AccountableIdentityReason = "MALFORMED_TOKEN" | "MALFORMED_CLAIMS" | "UNSUPPORTED_ALG" | "UNSUPPORTED_TOKEN_TYPE" | "KEY_NOT_FOUND" | "SIGNATURE_INVALID" | "EXPIRED" | "NOT_YET_VALID" | "ISSUER_MISMATCH" | "AUDIENCE_MISMATCH" | "MISSING_OWNER_BINDING";
|
|
10
|
+
export interface AccountableIdentityResult {
|
|
11
|
+
readonly ok: boolean;
|
|
12
|
+
readonly reason: AccountableIdentityReason | null;
|
|
13
|
+
/** The `{ owner, agent }` binding — present whenever the signature verified. */
|
|
14
|
+
readonly actor: AccountableActor | null;
|
|
15
|
+
/** The token's granted scope, if any. */
|
|
16
|
+
readonly scope: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface VerifyAccountableIdentityOptions {
|
|
19
|
+
/** RFC 8707: this runtime's canonical resource URI. REQUIRED. */
|
|
20
|
+
readonly expectedAudience: string;
|
|
21
|
+
readonly expectedIssuer?: string;
|
|
22
|
+
/** Resolve the signer key by `kid` from this JWKS (else self-certifying did:kash). */
|
|
23
|
+
readonly jwks?: Jwks;
|
|
24
|
+
readonly nowSec?: number;
|
|
25
|
+
readonly clockSkewSeconds?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Verify an agent access token and extract the accountable actor. The runtime
|
|
29
|
+
* uses `actor.agent` as the ledger actor DID for autonomous actions and
|
|
30
|
+
* `actor.owner` as the delegating principal.
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifyAccountableIdentity(token: string, opts: VerifyAccountableIdentityOptions): Promise<AccountableIdentityResult>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BAAyB,CAAC,CAkBpC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @kashscript/hudhud/identity — the accountable-identity gate (MCP OAuth 2.1)
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// Replaces Oreoasis's bespoke HS256 / sovereign-session auth with
|
|
5
|
+
// `@kashscript/identity-server` agent tokens (RFC 9068 + 8707 + 8693): the
|
|
6
|
+
// runtime accepts an audience-bound, agent→owner-delegated access token, and
|
|
7
|
+
// extracts the accountable actor `{ owner, agent }` for the ledger. The bespoke
|
|
8
|
+
// JWT + revocation paths are deleted; revocation, if a venture needs it, is a
|
|
9
|
+
// venture-side store. `AUDIENCE_MISMATCH` covers the closeout-aud-revocation
|
|
10
|
+
// behaviour.
|
|
11
|
+
// ============================================================================
|
|
12
|
+
import { verifyAgentToken } from "@kashscript/identity-server";
|
|
13
|
+
/**
|
|
14
|
+
* Verify an agent access token and extract the accountable actor. The runtime
|
|
15
|
+
* uses `actor.agent` as the ledger actor DID for autonomous actions and
|
|
16
|
+
* `actor.owner` as the delegating principal.
|
|
17
|
+
*/
|
|
18
|
+
export async function verifyAccountableIdentity(token, opts) {
|
|
19
|
+
const res = await verifyAgentToken(token, {
|
|
20
|
+
expectedAudience: opts.expectedAudience,
|
|
21
|
+
...(opts.expectedIssuer !== undefined ? { expectedIssuer: opts.expectedIssuer } : {}),
|
|
22
|
+
...(opts.jwks !== undefined ? { jwks: opts.jwks } : {}),
|
|
23
|
+
...(opts.nowSec !== undefined ? { nowSec: opts.nowSec } : {}),
|
|
24
|
+
...(opts.clockSkewSeconds !== undefined ? { clockSkewSeconds: opts.clockSkewSeconds } : {}),
|
|
25
|
+
});
|
|
26
|
+
const scope = typeof res.claims?.scope === "string" ? res.claims.scope : null;
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
// audit r1 F6: never hand back a consumable actor from a FAILED verification.
|
|
29
|
+
// identity-server still surfaces `ownerBinding` on post-signature failures
|
|
30
|
+
// (expired / wrong-audience) for logging, but the runtime must not attribute
|
|
31
|
+
// ledger rows to a binding whose token is invalid — make misuse unrepresentable.
|
|
32
|
+
return { ok: false, reason: res.reason, actor: null, scope };
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, reason: null, actor: res.ownerBinding, scope };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,kEAAkE;AAClE,2EAA2E;AAC3E,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,aAAa;AACb,+EAA+E;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AA2C/D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,KAAa,EACb,IAAsC;IAEtC,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,KAAK,EAAE;QACxC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,GAAG,CAAC,IAAI,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5F,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,OAAO,GAAG,CAAC,MAAM,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9E,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,8EAA8E;QAC9E,2EAA2E;QAC3E,6EAA6E;QAC7E,iFAAiF;QACjF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./errors";
|
|
2
|
+
export * from "./sop";
|
|
3
|
+
export * from "./privacy";
|
|
4
|
+
export * from "./mcp";
|
|
5
|
+
export * from "./scope";
|
|
6
|
+
export * from "./ledger";
|
|
7
|
+
export * from "./anchor";
|
|
8
|
+
export * from "./exception";
|
|
9
|
+
export * from "./certificate";
|
|
10
|
+
export * from "./did-registry";
|
|
11
|
+
export * from "./identity";
|
|
12
|
+
export * from "./runtime";
|
|
13
|
+
/** The hudhud protocol/package version (M5 initial cut). */
|
|
14
|
+
export declare const HUDHUD_VERSION: "0.1.0";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,4DAA4D;AAC5D,eAAO,MAAM,cAAc,EAAG,OAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @kashscript/hudhud — the Agent Protocol (accountable agent runtime)
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// The generic, venture-neutral engine lifted from the oreoasis-core-host (M5 of
|
|
5
|
+
// the Manifestation): SOP compilation, MCP governance (allowlist + circuit
|
|
6
|
+
// breaker + PII redaction), scope gating, a signed action ledger + chain anchor
|
|
7
|
+
// (on @kashscript/attest), exception classification, work certificates
|
|
8
|
+
// (AIUC-1/DSSE), a DID registry, an identity gate (identity-server agent
|
|
9
|
+
// tokens), and the neuron-backed execution runtime. SOP CONTENT, fixtures,
|
|
10
|
+
// routes, storage schemas, and text UIs stay venture-side (guard b).
|
|
11
|
+
//
|
|
12
|
+
// Subpath entries (`./errors`, `./sop`, `./mcp`, `./privacy`, `./scope`,
|
|
13
|
+
// `./ledger`, `./anchor`, `./exception`, `./certificate`, `./did-registry`,
|
|
14
|
+
// `./identity`, `./runtime`, `./adapters/prisma`) mirror these modules; this
|
|
15
|
+
// root barrel re-exports the whole non-adapter surface. The durable Prisma
|
|
16
|
+
// adapters are import-gated behind `@kashscript/hudhud/adapters/prisma`.
|
|
17
|
+
// ============================================================================
|
|
18
|
+
export * from "./errors";
|
|
19
|
+
export * from "./sop";
|
|
20
|
+
export * from "./privacy";
|
|
21
|
+
export * from "./mcp";
|
|
22
|
+
export * from "./scope";
|
|
23
|
+
export * from "./ledger";
|
|
24
|
+
export * from "./anchor";
|
|
25
|
+
export * from "./exception";
|
|
26
|
+
export * from "./certificate";
|
|
27
|
+
export * from "./did-registry";
|
|
28
|
+
export * from "./identity";
|
|
29
|
+
export * from "./runtime";
|
|
30
|
+
/** The hudhud protocol/package version (M5 initial cut). */
|
|
31
|
+
export const HUDHUD_VERSION = "0.1.0";
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,sEAAsE;AACtE,+EAA+E;AAC/E,gFAAgF;AAChF,2EAA2E;AAC3E,gFAAgF;AAChF,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,qEAAqE;AACrE,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,yEAAyE;AACzE,+EAA+E;AAE/E,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAG,OAAgB,CAAC"}
|