@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.
Files changed (138) hide show
  1. package/LICENSE +133 -0
  2. package/README.md +67 -0
  3. package/dist/adapters/prisma.d.ts +170 -0
  4. package/dist/adapters/prisma.d.ts.map +1 -0
  5. package/dist/adapters/prisma.js +185 -0
  6. package/dist/adapters/prisma.js.map +1 -0
  7. package/dist/anchor/index.d.ts +55 -0
  8. package/dist/anchor/index.d.ts.map +1 -0
  9. package/dist/anchor/index.js +97 -0
  10. package/dist/anchor/index.js.map +1 -0
  11. package/dist/certificate/certificate.d.ts +115 -0
  12. package/dist/certificate/certificate.d.ts.map +1 -0
  13. package/dist/certificate/certificate.js +221 -0
  14. package/dist/certificate/certificate.js.map +1 -0
  15. package/dist/certificate/html.d.ts +10 -0
  16. package/dist/certificate/html.d.ts.map +1 -0
  17. package/dist/certificate/html.js +141 -0
  18. package/dist/certificate/html.js.map +1 -0
  19. package/dist/certificate/index.d.ts +3 -0
  20. package/dist/certificate/index.d.ts.map +1 -0
  21. package/dist/certificate/index.js +5 -0
  22. package/dist/certificate/index.js.map +1 -0
  23. package/dist/did-registry/index.d.ts +3 -0
  24. package/dist/did-registry/index.d.ts.map +1 -0
  25. package/dist/did-registry/index.js +10 -0
  26. package/dist/did-registry/index.js.map +1 -0
  27. package/dist/errors.d.ts +35 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +65 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/exception/index.d.ts +97 -0
  32. package/dist/exception/index.d.ts.map +1 -0
  33. package/dist/exception/index.js +144 -0
  34. package/dist/exception/index.js.map +1 -0
  35. package/dist/identity/index.d.ts +33 -0
  36. package/dist/identity/index.d.ts.map +1 -0
  37. package/dist/identity/index.js +36 -0
  38. package/dist/identity/index.js.map +1 -0
  39. package/dist/index.d.ts +15 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +32 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/ledger/event-schema.d.ts +97 -0
  44. package/dist/ledger/event-schema.d.ts.map +1 -0
  45. package/dist/ledger/event-schema.js +54 -0
  46. package/dist/ledger/event-schema.js.map +1 -0
  47. package/dist/ledger/index.d.ts +7 -0
  48. package/dist/ledger/index.d.ts.map +1 -0
  49. package/dist/ledger/index.js +14 -0
  50. package/dist/ledger/index.js.map +1 -0
  51. package/dist/ledger/mutex.d.ts +9 -0
  52. package/dist/ledger/mutex.d.ts.map +1 -0
  53. package/dist/ledger/mutex.js +36 -0
  54. package/dist/ledger/mutex.js.map +1 -0
  55. package/dist/ledger/store.d.ts +31 -0
  56. package/dist/ledger/store.d.ts.map +1 -0
  57. package/dist/ledger/store.js +66 -0
  58. package/dist/ledger/store.js.map +1 -0
  59. package/dist/ledger/writer.d.ts +69 -0
  60. package/dist/ledger/writer.d.ts.map +1 -0
  61. package/dist/ledger/writer.js +167 -0
  62. package/dist/ledger/writer.js.map +1 -0
  63. package/dist/mcp/allowlist.d.ts +53 -0
  64. package/dist/mcp/allowlist.d.ts.map +1 -0
  65. package/dist/mcp/allowlist.js +65 -0
  66. package/dist/mcp/allowlist.js.map +1 -0
  67. package/dist/mcp/client.d.ts +68 -0
  68. package/dist/mcp/client.d.ts.map +1 -0
  69. package/dist/mcp/client.js +198 -0
  70. package/dist/mcp/client.js.map +1 -0
  71. package/dist/mcp/index.d.ts +3 -0
  72. package/dist/mcp/index.d.ts.map +1 -0
  73. package/dist/mcp/index.js +5 -0
  74. package/dist/mcp/index.js.map +1 -0
  75. package/dist/privacy/index.d.ts +21 -0
  76. package/dist/privacy/index.d.ts.map +1 -0
  77. package/dist/privacy/index.js +96 -0
  78. package/dist/privacy/index.js.map +1 -0
  79. package/dist/runtime/dispatcher.d.ts +27 -0
  80. package/dist/runtime/dispatcher.d.ts.map +1 -0
  81. package/dist/runtime/dispatcher.js +66 -0
  82. package/dist/runtime/dispatcher.js.map +1 -0
  83. package/dist/runtime/escalation.d.ts +98 -0
  84. package/dist/runtime/escalation.d.ts.map +1 -0
  85. package/dist/runtime/escalation.js +188 -0
  86. package/dist/runtime/escalation.js.map +1 -0
  87. package/dist/runtime/index.d.ts +7 -0
  88. package/dist/runtime/index.d.ts.map +1 -0
  89. package/dist/runtime/index.js +9 -0
  90. package/dist/runtime/index.js.map +1 -0
  91. package/dist/runtime/runner.d.ts +78 -0
  92. package/dist/runtime/runner.d.ts.map +1 -0
  93. package/dist/runtime/runner.js +145 -0
  94. package/dist/runtime/runner.js.map +1 -0
  95. package/dist/scope/index.d.ts +19 -0
  96. package/dist/scope/index.d.ts.map +1 -0
  97. package/dist/scope/index.js +44 -0
  98. package/dist/scope/index.js.map +1 -0
  99. package/dist/sop/compiler.d.ts +36 -0
  100. package/dist/sop/compiler.d.ts.map +1 -0
  101. package/dist/sop/compiler.js +54 -0
  102. package/dist/sop/compiler.js.map +1 -0
  103. package/dist/sop/index.d.ts +3 -0
  104. package/dist/sop/index.d.ts.map +1 -0
  105. package/dist/sop/index.js +5 -0
  106. package/dist/sop/index.js.map +1 -0
  107. package/dist/sop/service.d.ts +40 -0
  108. package/dist/sop/service.d.ts.map +1 -0
  109. package/dist/sop/service.js +140 -0
  110. package/dist/sop/service.js.map +1 -0
  111. package/package.json +112 -0
  112. package/src/adapters/prisma.ts +310 -0
  113. package/src/anchor/index.ts +149 -0
  114. package/src/certificate/certificate.ts +340 -0
  115. package/src/certificate/html.ts +156 -0
  116. package/src/certificate/index.ts +4 -0
  117. package/src/did-registry/index.ts +11 -0
  118. package/src/errors.ts +79 -0
  119. package/src/exception/index.ts +244 -0
  120. package/src/identity/index.ts +82 -0
  121. package/src/index.ts +33 -0
  122. package/src/ledger/event-schema.ts +61 -0
  123. package/src/ledger/index.ts +22 -0
  124. package/src/ledger/mutex.ts +37 -0
  125. package/src/ledger/store.ts +86 -0
  126. package/src/ledger/writer.ts +249 -0
  127. package/src/mcp/allowlist.ts +102 -0
  128. package/src/mcp/client.ts +284 -0
  129. package/src/mcp/index.ts +4 -0
  130. package/src/privacy/index.ts +123 -0
  131. package/src/runtime/dispatcher.ts +96 -0
  132. package/src/runtime/escalation.ts +292 -0
  133. package/src/runtime/index.ts +14 -0
  134. package/src/runtime/runner.ts +227 -0
  135. package/src/scope/index.ts +59 -0
  136. package/src/sop/compiler.ts +99 -0
  137. package/src/sop/index.ts +4 -0
  138. package/src/sop/service.ts +184 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runtime/runner.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8CAA8C;AAC9C,+EAA+E;AAC/E,qEAAqE;AACrE,0EAA0E;AAC1E,gFAAgF;AAChF,6EAA6E;AAC7E,+EAA+E;AAC/E,yEAAyE;AACzE,2DAA2D;AAC3D,+EAA+E;AAE/E,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAM9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AA0DtD,MAAM,OAAO,cAAc;IACI;IAA7B,YAA6B,IAAwB;QAAxB,SAAI,GAAJ,IAAI,CAAoB;IAAG,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAC,KAAuB;QAC/B,OAAO,IAAI,CAAC,aAAa,CAAC;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAA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E,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,EAAE;QAC/F,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE;QACpJ,WAAW,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,wBAAwB,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE;KACpJ,CAAC;IACF,OAAO,MAAmC,CAAC;AAC7C,CAAC;AAED;;mEAEmE;AACnE,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,MAAM,IAAI,GAAG;QACX,QAAQ,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,IAAI,EAAE,oBAAoB,SAAS,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,4BAA4B,EAAE;KAClJ,CAAC;IACF,OAAO,IAA8B,CAAC;AACxC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** A session's authorization scope. RESTRICTED is the conservative default —
2
+ * a misconfigured spawn never inherits admin privilege. */
3
+ export type SessionScope = "RESTRICTED" | "UNRESTRICTED";
4
+ /** Tool-name prefixes treated as administrative (config-extensible by callers). */
5
+ export declare const ADMINISTRATIVE_TOOL_PREFIXES: ReadonlyArray<string>;
6
+ /** Whether `toolName` names an administrative tool. audit r1 F5: match a bare
7
+ * namespace marker (`admin`, `internal`, …) as a DELIMITER-BOUNDED leading token
8
+ * of ANY `.`-segment — case-insensitively — so `admin.reset`, `Admin.Reset`,
9
+ * `acme.admin.wipe`, AND `billing.admin_reset` / `billing.admin-reset` are all
10
+ * caught, not only a literal `admin.` prefix. `administrate.report` is NOT
11
+ * administrative (the marker must end at a `_`/`-`/`:` boundary or the segment
12
+ * end). Prefixes may be passed with or without a trailing dot. */
13
+ export declare function isAdministrativeTool(toolName: string, prefixes?: ReadonlyArray<string>): boolean;
14
+ /**
15
+ * Assert `scope` permits dispatching `toolName`. RESTRICTED sessions refuse
16
+ * administrative tools with `McpSecurityViolationError("SCOPE_VIOLATION")`.
17
+ */
18
+ export declare function assertScopeAllowsTool(scope: SessionScope, toolName: string, prefixes?: ReadonlyArray<string>): void;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scope/index.ts"],"names":[],"mappings":"AAYA;4DAC4D;AAC5D,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,cAAc,CAAC;AAEzD,mFAAmF;AACnF,eAAO,MAAM,4BAA4B,EAAE,aAAa,CAAC,MAAM,CAAmD,CAAC;AAEnH;;;;;;mEAMmE;AACnE,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,aAAa,CAAC,MAAM,CAAgC,GAC7D,OAAO,CAYT;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,aAAa,CAAC,MAAM,CAAgC,GAC7D,IAAI,CAON"}
@@ -0,0 +1,44 @@
1
+ // ============================================================================
2
+ // @kashscript/hudhud/scope — session scope-gating (tool authorization)
3
+ // ----------------------------------------------------------------------------
4
+ // Dual-scope segregation: a RESTRICTED session (consumer-facing) may not
5
+ // dispatch administrative tools; an UNRESTRICTED session (internal) may. The
6
+ // gate reads the tool name only — no business branching. Ported from the
7
+ // oreoasis-core-host engine (M5); the venture's B2C/B2B labels map onto
8
+ // RESTRICTED/UNRESTRICTED.
9
+ // ============================================================================
10
+ import { McpSecurityViolationError } from "../errors";
11
+ /** Tool-name prefixes treated as administrative (config-extensible by callers). */
12
+ export const ADMINISTRATIVE_TOOL_PREFIXES = ["admin.", "internal.", "operator.", "kernel."];
13
+ /** Whether `toolName` names an administrative tool. audit r1 F5: match a bare
14
+ * namespace marker (`admin`, `internal`, …) as a DELIMITER-BOUNDED leading token
15
+ * of ANY `.`-segment — case-insensitively — so `admin.reset`, `Admin.Reset`,
16
+ * `acme.admin.wipe`, AND `billing.admin_reset` / `billing.admin-reset` are all
17
+ * caught, not only a literal `admin.` prefix. `administrate.report` is NOT
18
+ * administrative (the marker must end at a `_`/`-`/`:` boundary or the segment
19
+ * end). Prefixes may be passed with or without a trailing dot. */
20
+ export function isAdministrativeTool(toolName, prefixes = ADMINISTRATIVE_TOOL_PREFIXES) {
21
+ const markers = prefixes.map((p) => (p.endsWith(".") ? p.slice(0, -1) : p).toLowerCase());
22
+ for (const seg of toolName.toLowerCase().split(".")) {
23
+ for (const marker of markers) {
24
+ if (seg === marker)
25
+ return true;
26
+ if (seg.startsWith(marker)) {
27
+ const next = seg.charAt(marker.length);
28
+ if (next === "_" || next === "-" || next === ":")
29
+ return true;
30
+ }
31
+ }
32
+ }
33
+ return false;
34
+ }
35
+ /**
36
+ * Assert `scope` permits dispatching `toolName`. RESTRICTED sessions refuse
37
+ * administrative tools with `McpSecurityViolationError("SCOPE_VIOLATION")`.
38
+ */
39
+ export function assertScopeAllowsTool(scope, toolName, prefixes = ADMINISTRATIVE_TOOL_PREFIXES) {
40
+ if (scope === "RESTRICTED" && isAdministrativeTool(toolName, prefixes)) {
41
+ throw new McpSecurityViolationError("SCOPE_VIOLATION", `RESTRICTED session may not dispatch administrative tool "${toolName}"`);
42
+ }
43
+ }
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scope/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAC/E,yEAAyE;AACzE,6EAA6E;AAC7E,yEAAyE;AACzE,wEAAwE;AACxE,2BAA2B;AAC3B,+EAA+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jC,iBAAiB,EACjB,4DAA4D,QAAQ,GAAG,CACxE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,36 @@
1
+ export interface TaskDagNode {
2
+ readonly id: string;
3
+ readonly type: "step";
4
+ readonly text: string;
5
+ readonly sourceLine: number;
6
+ }
7
+ export interface TaskDagEdge {
8
+ readonly from: string;
9
+ readonly to: string;
10
+ }
11
+ export interface TaskDag {
12
+ readonly nodes: ReadonlyArray<TaskDagNode>;
13
+ readonly edges: ReadonlyArray<TaskDagEdge>;
14
+ readonly meta: {
15
+ readonly compilerName: "kash-structural-v1";
16
+ readonly compilerVersion: string;
17
+ readonly sourceLineCount: number;
18
+ readonly sopSha256: string;
19
+ };
20
+ }
21
+ export interface CompileSopInput {
22
+ readonly sopText: string;
23
+ /** Optional — used by the line-indexed diagnostics. */
24
+ readonly sopHint?: string;
25
+ }
26
+ export interface CompileSopOutput {
27
+ readonly taskDag: TaskDag;
28
+ /** sha256 of the raw input text. */
29
+ readonly sopSha256: string;
30
+ }
31
+ /**
32
+ * Compile an SOP into a TaskDAG. Throws `SopCompilationError` if the text is
33
+ * empty/whitespace-only or contains no numbered/bulleted steps.
34
+ */
35
+ export declare function compileSopStructural(input: CompileSopInput): Promise<CompileSopOutput>;
36
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/sop/compiler.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;QAC5C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;QACjC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;QACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH;AAOD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAsC5F"}
@@ -0,0 +1,54 @@
1
+ // ============================================================================
2
+ // @kashscript/hudhud/sop — deterministic SOP → TaskDAG compiler
3
+ // ----------------------------------------------------------------------------
4
+ // Compiles operational SOPs structurally: numbered/bulleted list items become
5
+ // DAG nodes; sequential edges chain them. PURE — same input → same output →
6
+ // same SHA-256, so the SOP corpus is content-addressable (the dedupe
7
+ // invariant). The output mirrors the neuron `TaskDAG {nodes, edges, meta}` so
8
+ // an LLM-backed decomposer can swap in without touching downstream code.
9
+ //
10
+ // Ported from the oreoasis-core-host engine (M5, ADR-0016); the content hash
11
+ // uses attest's `sha256Hex`, and the compiler label is neutralized.
12
+ // ============================================================================
13
+ import { sha256Hex } from "@kashscript/attest";
14
+ import { SopCompilationError } from "../errors";
15
+ const STRUCTURAL_COMPILER_VERSION = "1.0.0";
16
+ /** Match leading numbered list / bullet markers. */
17
+ const LIST_ITEM_PATTERN = /^\s*(?:\d+[.)]|[-*•])\s+(.+)$/;
18
+ /**
19
+ * Compile an SOP into a TaskDAG. Throws `SopCompilationError` if the text is
20
+ * empty/whitespace-only or contains no numbered/bulleted steps.
21
+ */
22
+ export async function compileSopStructural(input) {
23
+ const lines = input.sopText.split(/\r?\n/);
24
+ if (input.sopText.trim().length === 0) {
25
+ throw new SopCompilationError("SOP text is empty or whitespace-only — at least one step required");
26
+ }
27
+ const nodes = [];
28
+ for (let i = 0; i < lines.length; i++) {
29
+ const match = LIST_ITEM_PATTERN.exec(lines[i]);
30
+ if (match) {
31
+ nodes.push({ id: `n${nodes.length + 1}`, type: "step", text: match[1].trim(), sourceLine: i + 1 });
32
+ }
33
+ }
34
+ if (nodes.length === 0) {
35
+ throw new SopCompilationError("No numbered/bulleted steps detected — structural compiler requires `1.` / `-` / `*` / `•` prefixes");
36
+ }
37
+ const edges = [];
38
+ for (let i = 0; i < nodes.length - 1; i++) {
39
+ edges.push({ from: nodes[i].id, to: nodes[i + 1].id });
40
+ }
41
+ const sopSha256 = await sha256Hex(new TextEncoder().encode(input.sopText));
42
+ const taskDag = {
43
+ nodes,
44
+ edges,
45
+ meta: {
46
+ compilerName: "kash-structural-v1",
47
+ compilerVersion: STRUCTURAL_COMPILER_VERSION,
48
+ sourceLineCount: lines.length,
49
+ sopSha256,
50
+ },
51
+ };
52
+ return { taskDag, sopSha256 };
53
+ }
54
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/sop/compiler.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gEAAgE;AAChE,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,qEAAqE;AACrE,8EAA8E;AAC9E,yEAAyE;AACzE,EAAE;AACF,6EAA6E;AAC7E,oEAAoE;AACpE,+EAA+E;AAE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CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAY;QACvB,KAAK;QACL,KAAK;QACL,IAAI,EAAE;YACJ,YAAY,EAAE,oBAAoB;YAClC,eAAe,EAAE,2BAA2B;YAC5C,eAAe,EAAE,KAAK,CAAC,MAAM;YAC7B,SAAS;SACV;KACF,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./compiler";
2
+ export * from "./service";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sop/index.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ // @kashscript/hudhud/sop — deterministic SOP → TaskDAG compiler + the
2
+ // goto/cycle-detecting service. Content-addressable via attest's sha256Hex.
3
+ export * from "./compiler";
4
+ export * from "./service";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sop/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { LLMProvider } from "@kashscript/neuron/kernel";
2
+ import type { TaskDag, TaskDagEdge, TaskDagNode } from "./compiler";
3
+ export interface SopCompilerServiceOptions {
4
+ /** Seam for the deferred LLM decomposer wire-up (not yet invoked). */
5
+ readonly llmProvider?: LLMProvider;
6
+ readonly llmModel?: string;
7
+ }
8
+ export interface CompiledCorporateManual {
9
+ readonly taskDag: TaskDag;
10
+ readonly sopSha256: string;
11
+ readonly institutionDid: string;
12
+ readonly version: string;
13
+ }
14
+ export declare class SopCompilerService {
15
+ private readonly llmBackendActive;
16
+ constructor(opts?: SopCompilerServiceOptions);
17
+ /** Whether an LLM provider seam is plumbed. */
18
+ hasLlmBackend(): boolean;
19
+ /** Compile a corporate manual into a content-addressable TaskDAG.
20
+ * @throws SopCompilationError on nil / empty / cyclical input. */
21
+ compileCorporateManual(institutionDid: string, rawText: string, version: string): Promise<CompiledCorporateManual>;
22
+ }
23
+ interface GotoEdge {
24
+ readonly from: string;
25
+ readonly to: string;
26
+ readonly sourceLine: number;
27
+ }
28
+ /** Scan every node's text for `goto N` markers → edges to `n${N}` (unknown
29
+ * targets silently dropped; self-loops emitted so the detector catches them). */
30
+ export declare function extractGotoEdges(nodes: ReadonlyArray<TaskDagNode>): ReadonlyArray<GotoEdge>;
31
+ interface CycleReport {
32
+ readonly path: ReadonlyArray<string>;
33
+ readonly closingFrom: string;
34
+ readonly closingTo: string;
35
+ }
36
+ /** DFS cycle detector (iterative; CLRS white/gray/black). Returns the first
37
+ * cycle or null. Deterministic node order for reproducible diagnostics. */
38
+ export declare function detectCycle(nodes: ReadonlyArray<TaskDagNode>, edges: ReadonlyArray<TaskDagEdge>): CycleReport | null;
39
+ export {};
40
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/sop/service.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,WAAW,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
1
+ // ============================================================================
2
+ // @kashscript/hudhud/sop — SopCompilerService (goto + cycle detection)
3
+ // ----------------------------------------------------------------------------
4
+ // Wraps the deterministic structural compiler with: an LLM-provider seam (the
5
+ // deferred decomposer wire-up; not yet invoked), a `goto N` back-reference
6
+ // parser that turns explicit jump markers into DAG edges, and a DFS cycle
7
+ // detector that refuses to emit a DAG the executor could not schedule. Ported
8
+ // from the oreoasis-core-host engine (M5); errors neutralized, DID validation
9
+ // via attest's KASH_DID_PATTERN.
10
+ // ============================================================================
11
+ import { KASH_DID_PATTERN } from "@kashscript/attest";
12
+ import { SopCompilationError } from "../errors";
13
+ import { compileSopStructural } from "./compiler";
14
+ /** Match `goto N`, `goto step N`, `go to step N`, `→ step N`. Captures `N`. */
15
+ const GOTO_MARKER_PATTERN = /(?:goto|go\s+to|→)\s*(?:step\s*)?(\d{1,4})/gi;
16
+ /** Semver MAJOR.MINOR.PATCH. */
17
+ const SEMVER_PATTERN = /^\d+\.\d+\.\d+$/;
18
+ export class SopCompilerService {
19
+ llmBackendActive;
20
+ constructor(opts = {}) {
21
+ this.llmBackendActive = opts.llmProvider !== undefined;
22
+ }
23
+ /** Whether an LLM provider seam is plumbed. */
24
+ hasLlmBackend() {
25
+ return this.llmBackendActive;
26
+ }
27
+ /** Compile a corporate manual into a content-addressable TaskDAG.
28
+ * @throws SopCompilationError on nil / empty / cyclical input. */
29
+ async compileCorporateManual(institutionDid, rawText, version) {
30
+ if (typeof institutionDid !== "string" || institutionDid.length === 0) {
31
+ throw new SopCompilationError("institutionDid is required (non-empty did:kash:… identifier)");
32
+ }
33
+ if (!KASH_DID_PATTERN.test(institutionDid)) {
34
+ throw new SopCompilationError("institutionDid is not a valid did:kash:… identifier");
35
+ }
36
+ if (typeof version !== "string" || version.length === 0 || !SEMVER_PATTERN.test(version)) {
37
+ throw new SopCompilationError("version must be a semver MAJOR.MINOR.PATCH string");
38
+ }
39
+ if (typeof rawText !== "string") {
40
+ throw new SopCompilationError("rawText is required and must be a string");
41
+ }
42
+ // Structural compile (throws SopCompilationError on empty / no steps).
43
+ const { taskDag: structural, sopSha256 } = await compileSopStructural({
44
+ sopText: rawText,
45
+ sopHint: `version=${version} institutionDid=${institutionDid.slice(0, 24)}`,
46
+ });
47
+ const extraEdges = extractGotoEdges(structural.nodes);
48
+ const allEdges = [
49
+ ...structural.edges,
50
+ ...extraEdges.map((e) => ({ from: e.from, to: e.to })),
51
+ ];
52
+ const cycle = detectCycle(structural.nodes, allEdges);
53
+ if (cycle !== null) {
54
+ throw new SopCompilationError(`SOP TaskDAG contains a cycle: ${cycle.path.join(" → ")} (closing edge ${cycle.closingFrom} → ${cycle.closingTo})`);
55
+ }
56
+ const taskDag = { nodes: structural.nodes, edges: allEdges, meta: structural.meta };
57
+ return { taskDag, sopSha256, institutionDid, version };
58
+ }
59
+ }
60
+ /** Scan every node's text for `goto N` markers → edges to `n${N}` (unknown
61
+ * targets silently dropped; self-loops emitted so the detector catches them). */
62
+ export function extractGotoEdges(nodes) {
63
+ const idSet = new Set(nodes.map((n) => n.id));
64
+ const out = [];
65
+ for (const node of nodes) {
66
+ GOTO_MARKER_PATTERN.lastIndex = 0;
67
+ const matches = node.text.matchAll(GOTO_MARKER_PATTERN);
68
+ const seen = new Set();
69
+ for (const m of matches) {
70
+ const targetN = Number.parseInt(m[1], 10);
71
+ if (!Number.isFinite(targetN) || targetN <= 0)
72
+ continue;
73
+ const targetId = `n${targetN}`;
74
+ if (!idSet.has(targetId))
75
+ continue;
76
+ const key = `${node.id}→${targetId}`;
77
+ if (seen.has(key))
78
+ continue;
79
+ seen.add(key);
80
+ out.push({ from: node.id, to: targetId, sourceLine: node.sourceLine });
81
+ }
82
+ }
83
+ return out;
84
+ }
85
+ /** DFS cycle detector (iterative; CLRS white/gray/black). Returns the first
86
+ * cycle or null. Deterministic node order for reproducible diagnostics. */
87
+ export function detectCycle(nodes, edges) {
88
+ const adj = new Map();
89
+ for (const n of nodes)
90
+ adj.set(n.id, []);
91
+ for (const e of edges)
92
+ adj.get(e.from)?.push(e.to);
93
+ const colour = new Map();
94
+ for (const n of nodes)
95
+ colour.set(n.id, "white");
96
+ const stack = [];
97
+ const onStack = new Set();
98
+ function dfs(start) {
99
+ const work = [{ id: start, childIndex: 0 }];
100
+ colour.set(start, "gray");
101
+ stack.push(start);
102
+ onStack.add(start);
103
+ while (work.length > 0) {
104
+ const frame = work[work.length - 1];
105
+ const children = adj.get(frame.id) ?? [];
106
+ if (frame.childIndex >= children.length) {
107
+ colour.set(frame.id, "black");
108
+ onStack.delete(frame.id);
109
+ stack.pop();
110
+ work.pop();
111
+ continue;
112
+ }
113
+ const next = children[frame.childIndex];
114
+ frame.childIndex += 1;
115
+ const nc = colour.get(next);
116
+ if (nc === "gray") {
117
+ const idx = stack.indexOf(next);
118
+ const path = idx >= 0 ? stack.slice(idx) : [next];
119
+ path.push(next);
120
+ return { path, closingFrom: frame.id, closingTo: next };
121
+ }
122
+ if (nc === "white") {
123
+ colour.set(next, "gray");
124
+ stack.push(next);
125
+ onStack.add(next);
126
+ work.push({ id: next, childIndex: 0 });
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+ for (const n of nodes) {
132
+ if (colour.get(n.id) !== "white")
133
+ continue;
134
+ const cycle = dfs(n.id);
135
+ if (cycle !== null)
136
+ return cycle;
137
+ }
138
+ return null;
139
+ }
140
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/sop/service.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAC/E,8EAA8E;AAC9E,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,iCAAiC;AACjC,+EAA+E;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MA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G,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChC,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAClD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC1D,CAAC;YACD,IAAI,EAAE,KAAK,OAAO,EAAE,CAAC;gBACnB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAClB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO;YAAE,SAAS;QAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "name": "@kashscript/hudhud",
3
+ "version": "0.1.0",
4
+ "description": "The Agent Protocol — the accountable agent runtime. SOP compiler, MCP allowlist + circuit breaker, PII-redaction interceptor, a signed action ledger + forensic scan (on @kashscript/attest), exception classification, AIUC-1 work certificates, DID registry, and a neuron-kernel work runtime. Agent auth via @kashscript/identity-server MCP OAuth 2.1 tokens. Ventures import hudhud, never raw neuron. Commercial (SSLA Schedule B).",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./errors": {
15
+ "types": "./dist/errors.d.ts",
16
+ "import": "./dist/errors.js",
17
+ "default": "./dist/errors.js"
18
+ },
19
+ "./sop": {
20
+ "types": "./dist/sop/index.d.ts",
21
+ "import": "./dist/sop/index.js",
22
+ "default": "./dist/sop/index.js"
23
+ },
24
+ "./mcp": {
25
+ "types": "./dist/mcp/index.d.ts",
26
+ "import": "./dist/mcp/index.js",
27
+ "default": "./dist/mcp/index.js"
28
+ },
29
+ "./privacy": {
30
+ "types": "./dist/privacy/index.d.ts",
31
+ "import": "./dist/privacy/index.js",
32
+ "default": "./dist/privacy/index.js"
33
+ },
34
+ "./scope": {
35
+ "types": "./dist/scope/index.d.ts",
36
+ "import": "./dist/scope/index.js",
37
+ "default": "./dist/scope/index.js"
38
+ },
39
+ "./ledger": {
40
+ "types": "./dist/ledger/index.d.ts",
41
+ "import": "./dist/ledger/index.js",
42
+ "default": "./dist/ledger/index.js"
43
+ },
44
+ "./anchor": {
45
+ "types": "./dist/anchor/index.d.ts",
46
+ "import": "./dist/anchor/index.js",
47
+ "default": "./dist/anchor/index.js"
48
+ },
49
+ "./exception": {
50
+ "types": "./dist/exception/index.d.ts",
51
+ "import": "./dist/exception/index.js",
52
+ "default": "./dist/exception/index.js"
53
+ },
54
+ "./certificate": {
55
+ "types": "./dist/certificate/index.d.ts",
56
+ "import": "./dist/certificate/index.js",
57
+ "default": "./dist/certificate/index.js"
58
+ },
59
+ "./did-registry": {
60
+ "types": "./dist/did-registry/index.d.ts",
61
+ "import": "./dist/did-registry/index.js",
62
+ "default": "./dist/did-registry/index.js"
63
+ },
64
+ "./identity": {
65
+ "types": "./dist/identity/index.d.ts",
66
+ "import": "./dist/identity/index.js",
67
+ "default": "./dist/identity/index.js"
68
+ },
69
+ "./runtime": {
70
+ "types": "./dist/runtime/index.d.ts",
71
+ "import": "./dist/runtime/index.js",
72
+ "default": "./dist/runtime/index.js"
73
+ },
74
+ "./adapters/prisma": {
75
+ "types": "./dist/adapters/prisma.d.ts",
76
+ "import": "./dist/adapters/prisma.js",
77
+ "default": "./dist/adapters/prisma.js"
78
+ }
79
+ },
80
+ "dependencies": {
81
+ "@kashscript/identity-core": "0.3.1",
82
+ "@kashscript/attest": "0.1.0",
83
+ "@kashscript/identity-server": "0.1.0",
84
+ "@kashscript/neuron": "0.1.1"
85
+ },
86
+ "peerDependencies": {
87
+ "zod": "^3.23.8"
88
+ },
89
+ "files": [
90
+ "dist",
91
+ "src",
92
+ "README.md",
93
+ "LICENSE"
94
+ ],
95
+ "scripts": {
96
+ "build": "tsc -p tsconfig.json",
97
+ "typecheck": "tsc --noEmit",
98
+ "typecheck:test": "tsc --noEmit -p tsconfig.test.json",
99
+ "test": "bun run typecheck:test && bun test",
100
+ "clean": "rm -rf dist .turbo"
101
+ },
102
+ "devDependencies": {
103
+ "zod": "^3.23.8",
104
+ "typescript": "^5.6.3",
105
+ "@types/bun": "^1.2.5"
106
+ },
107
+ "license": "SEE LICENSE IN LICENSE",
108
+ "publishConfig": {
109
+ "access": "public",
110
+ "registry": "https://registry.npmjs.org/"
111
+ }
112
+ }