@kashscript/hudhud 0.1.0 → 0.2.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 +135 -133
- package/README.md +11 -0
- package/dist/certificate/certificate.d.ts +11 -4
- package/dist/certificate/certificate.d.ts.map +1 -1
- package/dist/certificate/certificate.js +21 -18
- package/dist/certificate/certificate.js.map +1 -1
- package/dist/certificate/html.d.ts.map +1 -1
- package/dist/certificate/html.js +1 -2
- package/dist/certificate/html.js.map +1 -1
- package/dist/errors.d.ts +29 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -2
- package/dist/errors.js.map +1 -1
- package/dist/exception/index.d.ts +127 -24
- package/dist/exception/index.d.ts.map +1 -1
- package/dist/exception/index.js +209 -15
- package/dist/exception/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/ledger/writer.d.ts +10 -2
- package/dist/ledger/writer.d.ts.map +1 -1
- package/dist/ledger/writer.js +16 -4
- package/dist/ledger/writer.js.map +1 -1
- package/dist/runtime/escalation.d.ts +5 -0
- package/dist/runtime/escalation.d.ts.map +1 -1
- package/dist/runtime/escalation.js +15 -3
- package/dist/runtime/escalation.js.map +1 -1
- package/dist/sop/compiler.d.ts.map +1 -1
- package/dist/sop/compiler.js +2 -2
- package/dist/sop/compiler.js.map +1 -1
- package/dist/sop/service.d.ts +5 -0
- package/dist/sop/service.d.ts.map +1 -1
- package/dist/sop/service.js +25 -6
- package/dist/sop/service.js.map +1 -1
- package/package.json +3 -3
- package/src/certificate/certificate.ts +25 -17
- package/src/certificate/html.ts +1 -2
- package/src/errors.ts +27 -2
- package/src/exception/index.ts +315 -33
- package/src/index.ts +1 -1
- package/src/ledger/writer.ts +24 -4
- package/src/runtime/escalation.ts +21 -9
- package/src/sop/compiler.ts +2 -1
- package/src/sop/service.ts +30 -5
package/src/sop/service.ts
CHANGED
|
@@ -20,8 +20,15 @@ export interface SopCompilerServiceOptions {
|
|
|
20
20
|
/** Seam for the deferred LLM decomposer wire-up (not yet invoked). */
|
|
21
21
|
readonly llmProvider?: LLMProvider;
|
|
22
22
|
readonly llmModel?: string;
|
|
23
|
+
/** Override the `institutionDid` acceptance policy (default: canonical
|
|
24
|
+
* `did:kash`). A consumer with structured institution DIDs injects its own —
|
|
25
|
+
* DID-string shape is an identity-method policy the consumer owns. */
|
|
26
|
+
readonly isValidInstitutionDid?: (did: string) => boolean;
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
/** Default DID acceptance policy: the canonical `did:kash:<base58btc>` shape. */
|
|
30
|
+
const isCanonicalKashDid = (did: string): boolean => KASH_DID_PATTERN.test(did);
|
|
31
|
+
|
|
25
32
|
export interface CompiledCorporateManual {
|
|
26
33
|
readonly taskDag: TaskDag;
|
|
27
34
|
readonly sopSha256: string;
|
|
@@ -36,9 +43,11 @@ const SEMVER_PATTERN = /^\d+\.\d+\.\d+$/;
|
|
|
36
43
|
|
|
37
44
|
export class SopCompilerService {
|
|
38
45
|
private readonly llmBackendActive: boolean;
|
|
46
|
+
private readonly isValidInstitutionDid: (did: string) => boolean;
|
|
39
47
|
|
|
40
48
|
constructor(opts: SopCompilerServiceOptions = {}) {
|
|
41
49
|
this.llmBackendActive = opts.llmProvider !== undefined;
|
|
50
|
+
this.isValidInstitutionDid = opts.isValidInstitutionDid ?? isCanonicalKashDid;
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
/** Whether an LLM provider seam is plumbed. */
|
|
@@ -54,16 +63,22 @@ export class SopCompilerService {
|
|
|
54
63
|
version: string,
|
|
55
64
|
): Promise<CompiledCorporateManual> {
|
|
56
65
|
if (typeof institutionDid !== "string" || institutionDid.length === 0) {
|
|
57
|
-
throw new SopCompilationError("institutionDid is required (non-empty did:kash:… identifier)"
|
|
66
|
+
throw new SopCompilationError("institutionDid is required (non-empty did:kash:… identifier)", {
|
|
67
|
+
kind: "invalid-institution-did",
|
|
68
|
+
});
|
|
58
69
|
}
|
|
59
|
-
if (!
|
|
60
|
-
throw new SopCompilationError("institutionDid is not a valid did:kash:… identifier"
|
|
70
|
+
if (!this.isValidInstitutionDid(institutionDid)) {
|
|
71
|
+
throw new SopCompilationError("institutionDid is not a valid did:kash:… identifier", {
|
|
72
|
+
kind: "invalid-institution-did",
|
|
73
|
+
});
|
|
61
74
|
}
|
|
62
75
|
if (typeof version !== "string" || version.length === 0 || !SEMVER_PATTERN.test(version)) {
|
|
63
|
-
throw new SopCompilationError("version must be a semver MAJOR.MINOR.PATCH string"
|
|
76
|
+
throw new SopCompilationError("version must be a semver MAJOR.MINOR.PATCH string", {
|
|
77
|
+
kind: "invalid-version",
|
|
78
|
+
});
|
|
64
79
|
}
|
|
65
80
|
if (typeof rawText !== "string") {
|
|
66
|
-
throw new SopCompilationError("rawText is required and must be a string");
|
|
81
|
+
throw new SopCompilationError("rawText is required and must be a string", { kind: "invalid-input" });
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
// Structural compile (throws SopCompilationError on empty / no steps).
|
|
@@ -80,8 +95,18 @@ export class SopCompilerService {
|
|
|
80
95
|
|
|
81
96
|
const cycle = detectCycle(structural.nodes, allEdges);
|
|
82
97
|
if (cycle !== null) {
|
|
98
|
+
// The offending goto lives on the source line of the node whose edge
|
|
99
|
+
// closes the cycle — surface it so a consumer can point at the raw line.
|
|
100
|
+
const closingNode = structural.nodes.find((n) => n.id === cycle.closingFrom);
|
|
83
101
|
throw new SopCompilationError(
|
|
84
102
|
`SOP TaskDAG contains a cycle: ${cycle.path.join(" → ")} (closing edge ${cycle.closingFrom} → ${cycle.closingTo})`,
|
|
103
|
+
{
|
|
104
|
+
kind: "cycle",
|
|
105
|
+
cyclePath: cycle.path,
|
|
106
|
+
closingFrom: cycle.closingFrom,
|
|
107
|
+
closingTo: cycle.closingTo,
|
|
108
|
+
lineIndex: closingNode?.sourceLine ?? null,
|
|
109
|
+
},
|
|
85
110
|
);
|
|
86
111
|
}
|
|
87
112
|
|