@loomwork/effect-runtime 0.0.0-stage → 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 (53) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +65 -2
  4. package/dist/EffectRuntime.d.ts +121 -0
  5. package/dist/EffectRuntime.d.ts.map +1 -0
  6. package/dist/EffectRuntime.js +422 -0
  7. package/dist/EffectRuntime.js.map +1 -0
  8. package/dist/authz.d.ts +228 -0
  9. package/dist/authz.d.ts.map +1 -0
  10. package/dist/authz.js +281 -0
  11. package/dist/authz.js.map +1 -0
  12. package/dist/effects/A2AEffect.d.ts +14 -0
  13. package/dist/effects/A2AEffect.d.ts.map +1 -0
  14. package/dist/effects/A2AEffect.js +21 -0
  15. package/dist/effects/A2AEffect.js.map +1 -0
  16. package/dist/effects/HumanEffect.d.ts +13 -0
  17. package/dist/effects/HumanEffect.d.ts.map +1 -0
  18. package/dist/effects/HumanEffect.js +21 -0
  19. package/dist/effects/HumanEffect.js.map +1 -0
  20. package/dist/effects/LazyEffect.d.ts +10 -0
  21. package/dist/effects/LazyEffect.d.ts.map +1 -0
  22. package/dist/effects/LazyEffect.js +28 -0
  23. package/dist/effects/LazyEffect.js.map +1 -0
  24. package/dist/effects/LlmEffect.d.ts +27 -0
  25. package/dist/effects/LlmEffect.d.ts.map +1 -0
  26. package/dist/effects/LlmEffect.js +27 -0
  27. package/dist/effects/LlmEffect.js.map +1 -0
  28. package/dist/effects/ToolEffect.d.ts +38 -0
  29. package/dist/effects/ToolEffect.d.ts.map +1 -0
  30. package/dist/effects/ToolEffect.js +31 -0
  31. package/dist/effects/ToolEffect.js.map +1 -0
  32. package/dist/index.d.ts +12 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +30 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/policy.d.ts +76 -0
  37. package/dist/policy.d.ts.map +1 -0
  38. package/dist/policy.js +212 -0
  39. package/dist/policy.js.map +1 -0
  40. package/dist/types.d.ts +416 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +28 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +56 -3
  45. package/src/EffectRuntime.ts +484 -0
  46. package/src/authz.ts +424 -0
  47. package/src/effects/HumanEffect.ts +25 -0
  48. package/src/effects/LazyEffect.ts +25 -0
  49. package/src/effects/LlmEffect.ts +39 -0
  50. package/src/effects/ToolEffect.ts +59 -0
  51. package/src/index.ts +48 -0
  52. package/src/policy.ts +296 -0
  53. package/src/types.ts +428 -0
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LazyEffect = void 0;
4
+ function isHandlerRef(spec) {
5
+ return spec._loomHandlerRef === true;
6
+ }
7
+ class LazyEffect {
8
+ spec;
9
+ kind = "tool";
10
+ resolved;
11
+ constructor(spec) {
12
+ this.spec = spec;
13
+ }
14
+ async execute(input, ctx) {
15
+ if (!this.resolved) {
16
+ if (isHandlerRef(this.spec)) {
17
+ this.resolved = this.spec.fn;
18
+ }
19
+ else {
20
+ const mod = await this.spec();
21
+ this.resolved = mod.default;
22
+ }
23
+ }
24
+ return this.resolved(input, ctx);
25
+ }
26
+ }
27
+ exports.LazyEffect = LazyEffect;
28
+ //# sourceMappingURL=LazyEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LazyEffect.js","sourceRoot":"","sources":["../../src/effects/LazyEffect.ts"],"names":[],"mappings":";;;AAGA,SAAS,YAAY,CAAY,IAA4B;IAC3D,OAAQ,IAA8B,CAAC,eAAe,KAAK,IAAI,CAAC;AAClE,CAAC;AAED,MAAa,UAAU;IAIQ;IAHpB,IAAI,GAAG,MAAe,CAAC;IACxB,QAAQ,CAAmC;IAEnD,YAA6B,IAA4B;QAA5B,SAAI,GAAJ,IAAI,CAAwB;IAAG,CAAC;IAE7D,KAAK,CAAC,OAAO,CAAC,KAAU,EAAE,GAAkB;QAC1C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAA0B,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,MAAO,IAAI,CAAC,IAAiC,EAAE,CAAC;gBAC5D,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;CACF;AAjBD,gCAiBC"}
@@ -0,0 +1,27 @@
1
+ import type { TaintedValue } from "@loomwork/classify";
2
+ import type { Effect, EffectContext, EffectDelta, EffectReasoningHook } from "../types";
3
+ export interface LlmEffectOptions {
4
+ /**
5
+ * Advisory pre-warm — invoked by the kernel ahead of use to keep the
6
+ * provider's connection/model cache hot (see {@link Effect.warm}). Wired by
7
+ * `createLlmEffect` to the provider's `warm()`. Latency-only.
8
+ */
9
+ warm?: () => void | Promise<void>;
10
+ /** ADR 0119 — the configured delta sink the runtime guards (see `Effect.deltaSink`). */
11
+ deltaSink?: (chunk: EffectDelta, ctx: EffectContext) => void;
12
+ /** ADR 0133 D6 - the configured reasoning sink the runtime guards (see `Effect.reasoningSink`). */
13
+ reasoningSink?: (delta: TaintedValue<string>, ctx: EffectContext) => void;
14
+ /** ADR 0133 D7 - what the composition root may ask about the effect's reasoning posture. */
15
+ reasoning?: EffectReasoningHook;
16
+ }
17
+ export declare class LlmEffect<TIn = unknown, TOut = unknown> implements Effect<TIn, TOut> {
18
+ private readonly fn;
19
+ readonly kind: "llm";
20
+ readonly warm?: () => void | Promise<void>;
21
+ readonly deltaSink?: (chunk: EffectDelta, ctx: EffectContext) => void;
22
+ readonly reasoningSink?: (delta: TaintedValue<string>, ctx: EffectContext) => void;
23
+ readonly reasoning?: EffectReasoningHook;
24
+ constructor(fn: (input: TIn, ctx: EffectContext) => Promise<TOut>, options?: LlmEffectOptions);
25
+ execute(input: TIn, ctx: EffectContext): Promise<TOut>;
26
+ }
27
+ //# sourceMappingURL=LlmEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LlmEffect.d.ts","sourceRoot":"","sources":["../../src/effects/LlmEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,wFAAwF;IACxF,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7D,mGAAmG;IACnG,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1E,4FAA4F;IAC5F,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACjC;AAED,qBAAa,SAAS,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO,CAAE,YAAW,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;IAQ9E,OAAO,CAAC,QAAQ,CAAC,EAAE;IAPrB,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IACtE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IACnF,QAAQ,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC;gBAGtB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,EACtE,OAAO,GAAE,gBAAqB;IAQhC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvD"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LlmEffect = void 0;
4
+ class LlmEffect {
5
+ fn;
6
+ kind = "llm";
7
+ warm;
8
+ deltaSink;
9
+ reasoningSink;
10
+ reasoning;
11
+ constructor(fn, options = {}) {
12
+ this.fn = fn;
13
+ if (options.warm !== undefined)
14
+ this.warm = options.warm;
15
+ if (options.deltaSink !== undefined)
16
+ this.deltaSink = options.deltaSink;
17
+ if (options.reasoningSink !== undefined)
18
+ this.reasoningSink = options.reasoningSink;
19
+ if (options.reasoning !== undefined)
20
+ this.reasoning = options.reasoning;
21
+ }
22
+ execute(input, ctx) {
23
+ return this.fn(input, ctx);
24
+ }
25
+ }
26
+ exports.LlmEffect = LlmEffect;
27
+ //# sourceMappingURL=LlmEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LlmEffect.js","sourceRoot":"","sources":["../../src/effects/LlmEffect.ts"],"names":[],"mappings":";;;AAkBA,MAAa,SAAS;IAQD;IAPV,IAAI,GAAG,KAAc,CAAC;IACtB,IAAI,CAA8B;IAClC,SAAS,CAAoD;IAC7D,aAAa,CAA6D;IAC1E,SAAS,CAAuB;IAEzC,YACmB,EAAqD,EACtE,UAA4B,EAAE;QADb,OAAE,GAAF,EAAE,CAAmD;QAGtE,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACxE,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS;YAAE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QACpF,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAC1E,CAAC;IAED,OAAO,CAAC,KAAU,EAAE,GAAkB;QACpC,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF;AApBD,8BAoBC"}
@@ -0,0 +1,38 @@
1
+ import type { Effect, EffectContext, EffectMode, ErrorChannelSchema } from "../types";
2
+ export interface ToolEffectOptions {
3
+ /**
4
+ * K9.3 — declared delivery semantic for this tool (see {@link Effect.idempotent}).
5
+ * `false` = mutating & non-idempotent: recovery parks an unknown-state attempt at
6
+ * EFFECT_INDOUBT instead of silently re-running it. Omit for the legacy
7
+ * at-least-once re-run.
8
+ */
9
+ idempotent?: boolean;
10
+ /**
11
+ * DE-4 — declared failure channels for this tool (see {@link Effect.errors}).
12
+ * Pass the same map declared on the `tool$` contract so the kernel's registry
13
+ * fallback sees it. Omit for legacy untyped failure semantics.
14
+ */
15
+ errors?: Record<string, ErrorChannelSchema>;
16
+ /**
17
+ * ADR 0073 — which invocation seam this tool belongs to. Pass the same value
18
+ * declared on the `tool$` contract; this registered copy is the enforced one.
19
+ * Omit to keep today's behaviour on both seams.
20
+ */
21
+ mode?: EffectMode;
22
+ /**
23
+ * R12 — the sub-resource a call targets, for per-resource authorization (see
24
+ * {@link Effect.resourceOf}). Omit for effect-wide authorization only.
25
+ */
26
+ resourceOf?: (input: any) => string | undefined;
27
+ }
28
+ export declare class ToolEffect<TIn = unknown, TOut = unknown> implements Effect<TIn, TOut> {
29
+ private readonly fn;
30
+ readonly kind: "tool";
31
+ readonly idempotent?: boolean;
32
+ readonly errors?: Record<string, ErrorChannelSchema>;
33
+ readonly mode?: EffectMode;
34
+ readonly resourceOf?: (input: TIn) => string | undefined;
35
+ constructor(fn: (input: TIn, ctx: EffectContext) => Promise<TOut>, options?: ToolEffectOptions);
36
+ execute(input: TIn, ctx: EffectContext): Promise<TOut>;
37
+ }
38
+ //# sourceMappingURL=ToolEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolEffect.d.ts","sourceRoot":"","sources":["../../src/effects/ToolEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEtF,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC5C;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;OAGG;IAEH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,GAAG,SAAS,CAAC;CACjD;AAED,qBAAa,UAAU,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO,CAAE,YAAW,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;IAQ/E,OAAO,CAAC,QAAQ,CAAC,EAAE;IAPrB,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAU;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACrD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,GAAG,SAAS,CAAC;gBAGtC,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,EACtE,OAAO,GAAE,iBAAsB;IAgBjC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvD"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolEffect = void 0;
4
+ class ToolEffect {
5
+ fn;
6
+ kind = "tool";
7
+ idempotent;
8
+ errors;
9
+ mode;
10
+ resourceOf;
11
+ constructor(fn, options = {}) {
12
+ this.fn = fn;
13
+ if (options.idempotent !== undefined) {
14
+ this.idempotent = options.idempotent;
15
+ }
16
+ if (options.errors !== undefined) {
17
+ this.errors = options.errors;
18
+ }
19
+ if (options.mode !== undefined) {
20
+ this.mode = options.mode;
21
+ }
22
+ if (options.resourceOf !== undefined) {
23
+ this.resourceOf = options.resourceOf;
24
+ }
25
+ }
26
+ execute(input, ctx) {
27
+ return this.fn(input, ctx);
28
+ }
29
+ }
30
+ exports.ToolEffect = ToolEffect;
31
+ //# sourceMappingURL=ToolEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolEffect.js","sourceRoot":"","sources":["../../src/effects/ToolEffect.ts"],"names":[],"mappings":";;;AA8BA,MAAa,UAAU;IAQF;IAPV,IAAI,GAAG,MAAe,CAAC;IACvB,UAAU,CAAW;IACrB,MAAM,CAAsC;IAC5C,IAAI,CAAc;IAClB,UAAU,CAAsC;IAEzD,YACmB,EAAqD,EACtE,UAA6B,EAAE;QADd,OAAE,GAAF,EAAE,CAAmD;QAGtE,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACvC,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/B,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAU,EAAE,GAAkB;QACpC,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF;AA5BD,gCA4BC"}
@@ -0,0 +1,12 @@
1
+ export { EffectRuntime } from "./EffectRuntime";
2
+ export { LazyEffect } from "./effects/LazyEffect";
3
+ export { ToolEffect, type ToolEffectOptions } from "./effects/ToolEffect";
4
+ export { LlmEffect, type LlmEffectOptions } from "./effects/LlmEffect";
5
+ export { HumanEffect } from "./effects/HumanEffect";
6
+ export { EffectModeViolationError } from "./types";
7
+ export type { DeltaSink, Effect, EffectDelta, EffectContext, EffectKind, EffectMiddleware, EffectReasoningDefaults, EffectReasoningHook, EffectMode, EffectNext, ErrorChannelSchema, ResourceSnapshot, TransientIdentity, TransientInvokeOptions, Warmer, } from "./types";
8
+ export { CapabilityDeniedError, capabilityIds, GrantTable, DelegationAuthorizer, signDelegation, verifyDelegation, attenuateDelegation, delegationDigest, principalBlocked, principalIdentityKey, identityKeyOf, } from "./authz";
9
+ export { PolicyAuthorizer } from "./policy";
10
+ export type { PolicyRules, PolicyMatchRule, PolicyAuthorizerOptions } from "./policy";
11
+ export type { CapabilityAuthorizer, CapabilityDecision, CapabilityRequest, DelegatedGrant, DelegationAuthorizerOptions, EffectRuntimeOptions, GrantTableOptions, PrincipalChain, } from "./authz";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,YAAY,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACtF,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolicyAuthorizer = exports.identityKeyOf = exports.principalIdentityKey = exports.principalBlocked = exports.delegationDigest = exports.attenuateDelegation = exports.verifyDelegation = exports.signDelegation = exports.DelegationAuthorizer = exports.GrantTable = exports.capabilityIds = exports.CapabilityDeniedError = exports.EffectModeViolationError = exports.HumanEffect = exports.LlmEffect = exports.ToolEffect = exports.LazyEffect = exports.EffectRuntime = void 0;
4
+ var EffectRuntime_1 = require("./EffectRuntime");
5
+ Object.defineProperty(exports, "EffectRuntime", { enumerable: true, get: function () { return EffectRuntime_1.EffectRuntime; } });
6
+ var LazyEffect_1 = require("./effects/LazyEffect");
7
+ Object.defineProperty(exports, "LazyEffect", { enumerable: true, get: function () { return LazyEffect_1.LazyEffect; } });
8
+ var ToolEffect_1 = require("./effects/ToolEffect");
9
+ Object.defineProperty(exports, "ToolEffect", { enumerable: true, get: function () { return ToolEffect_1.ToolEffect; } });
10
+ var LlmEffect_1 = require("./effects/LlmEffect");
11
+ Object.defineProperty(exports, "LlmEffect", { enumerable: true, get: function () { return LlmEffect_1.LlmEffect; } });
12
+ var HumanEffect_1 = require("./effects/HumanEffect");
13
+ Object.defineProperty(exports, "HumanEffect", { enumerable: true, get: function () { return HumanEffect_1.HumanEffect; } });
14
+ var types_1 = require("./types");
15
+ Object.defineProperty(exports, "EffectModeViolationError", { enumerable: true, get: function () { return types_1.EffectModeViolationError; } });
16
+ var authz_1 = require("./authz");
17
+ Object.defineProperty(exports, "CapabilityDeniedError", { enumerable: true, get: function () { return authz_1.CapabilityDeniedError; } });
18
+ Object.defineProperty(exports, "capabilityIds", { enumerable: true, get: function () { return authz_1.capabilityIds; } });
19
+ Object.defineProperty(exports, "GrantTable", { enumerable: true, get: function () { return authz_1.GrantTable; } });
20
+ Object.defineProperty(exports, "DelegationAuthorizer", { enumerable: true, get: function () { return authz_1.DelegationAuthorizer; } });
21
+ Object.defineProperty(exports, "signDelegation", { enumerable: true, get: function () { return authz_1.signDelegation; } });
22
+ Object.defineProperty(exports, "verifyDelegation", { enumerable: true, get: function () { return authz_1.verifyDelegation; } });
23
+ Object.defineProperty(exports, "attenuateDelegation", { enumerable: true, get: function () { return authz_1.attenuateDelegation; } });
24
+ Object.defineProperty(exports, "delegationDigest", { enumerable: true, get: function () { return authz_1.delegationDigest; } });
25
+ Object.defineProperty(exports, "principalBlocked", { enumerable: true, get: function () { return authz_1.principalBlocked; } });
26
+ Object.defineProperty(exports, "principalIdentityKey", { enumerable: true, get: function () { return authz_1.principalIdentityKey; } });
27
+ Object.defineProperty(exports, "identityKeyOf", { enumerable: true, get: function () { return authz_1.identityKeyOf; } });
28
+ var policy_1 = require("./policy");
29
+ Object.defineProperty(exports, "PolicyAuthorizer", { enumerable: true, get: function () { return policy_1.PolicyAuthorizer; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,mDAAkD;AAAzC,wGAAA,UAAU,OAAA;AACnB,mDAA0E;AAAjE,wGAAA,UAAU,OAAA;AACnB,iDAAuE;AAA9D,sGAAA,SAAS,OAAA;AAClB,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,iCAAmD;AAA1C,iHAAA,wBAAwB,OAAA;AAkBjC,iCAYiB;AAXf,8GAAA,qBAAqB,OAAA;AACrB,sGAAA,aAAa,OAAA;AACb,mGAAA,UAAU,OAAA;AACV,6GAAA,oBAAoB,OAAA;AACpB,uGAAA,cAAc,OAAA;AACd,yGAAA,gBAAgB,OAAA;AAChB,4GAAA,mBAAmB,OAAA;AACnB,yGAAA,gBAAgB,OAAA;AAChB,yGAAA,gBAAgB,OAAA;AAChB,6GAAA,oBAAoB,OAAA;AACpB,sGAAA,aAAa,OAAA;AAEf,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,76 @@
1
+ import type { PolicyDefinition } from "@loomwork/core";
2
+ import type { CapabilityAuthorizer, CapabilityDecision, CapabilityRequest } from "./authz";
3
+ /**
4
+ * A single matcher rule (the "rich" form). Every present field must match the
5
+ * request (an omitted field is a wildcard); `deny` flips a match from allow to deny.
6
+ * `effect`/`tenant`/`step` are globs (`*` matches any run of characters).
7
+ */
8
+ export interface PolicyMatchRule {
9
+ /** Glob on the effect (tool) id, e.g. `"external-*"`. */
10
+ effect?: string;
11
+ /** Glob on `principal.tenant`. */
12
+ tenant?: string;
13
+ /** Glob on the step id. */
14
+ step?: string;
15
+ /** When true, a match DENIES (default: a match ALLOWS). */
16
+ deny?: boolean;
17
+ }
18
+ /**
19
+ * The interpreted shape of `PolicyDefinition.rules`. Both forms may be combined:
20
+ * the simple `allow`/`deny` effect lists AND the richer `match` rules. Semantics
21
+ * are deny-wins — see {@link PolicyAuthorizer}.
22
+ */
23
+ export interface PolicyRules {
24
+ /** Effect ids / globs that are permitted (an allow-list restricts to these). */
25
+ allow?: readonly string[];
26
+ /** Effect ids / globs that are forbidden (deny wins over allow). */
27
+ deny?: readonly string[];
28
+ /** Richer matchers, evaluated in order; deny matches win. */
29
+ match?: readonly PolicyMatchRule[];
30
+ }
31
+ export interface PolicyAuthorizerOptions {
32
+ /**
33
+ * App-global policies applied to EVERY request, on top of the per-principal set.
34
+ * (From `defineConfig({ policies })`.)
35
+ */
36
+ global?: readonly PolicyDefinition[];
37
+ /**
38
+ * The authorizer this one composes UNDER — an effect is allowed only if the base
39
+ * ALSO allows (defense in depth). If the base denies, that denial is returned
40
+ * verbatim and the policy rules are never consulted.
41
+ */
42
+ base?: CapabilityAuthorizer;
43
+ /**
44
+ * Which request field identifies the principal whose policies apply. Default: the
45
+ * `workflowId` (a flow is the unit of authority, matching `GrantTable`).
46
+ */
47
+ principal?: (req: CapabilityRequest) => string;
48
+ }
49
+ /**
50
+ * Enforces `policy$` definitions as a {@link CapabilityAuthorizer}. Evaluation over
51
+ * the applicable policies (global ∪ the principal's) is **deny-wins**:
52
+ *
53
+ * 1. any `deny` entry or `deny` match that fires → **denied**;
54
+ * 2. else if an allow-constraint exists (a non-empty `allow` list, or any allow
55
+ * `match` rule) and nothing allows the effect → **denied**;
56
+ * 3. else → **allowed**.
57
+ *
58
+ * A principal with no policies (and no global policies) is allowed — policies are
59
+ * purely additive tightening, so wiring the authorizer never denies an effect that
60
+ * has no policy governing it (the composed `base`, if any, still applies).
61
+ */
62
+ export declare class PolicyAuthorizer implements CapabilityAuthorizer {
63
+ private readonly byPrincipal;
64
+ private readonly global;
65
+ private readonly base;
66
+ private readonly principalOf;
67
+ constructor(policiesByPrincipal: Record<string, readonly PolicyDefinition[]>, options?: PolicyAuthorizerOptions);
68
+ authorize(req: CapabilityRequest): CapabilityDecision;
69
+ private evaluate;
70
+ /**
71
+ * Scan one policy group. Returns a denial (deny-wins → final) or `undefined`, mutating `state`
72
+ * with any allow-list constraint seen. `undefined` policies (no group for the principal) no-op.
73
+ */
74
+ private scan;
75
+ }
76
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE3F;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,gFAAgF;IAChF,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,oEAAoE;IACpE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CACpC;AAuID,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACrC;;;;OAIG;IACH,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,MAAM,CAAC;CAChD;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,oBAAoB;IAC3D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmC;IACxD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;gBAG/D,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC,EAChE,OAAO,GAAE,uBAA4B;IAUvC,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,kBAAkB;IASrD,OAAO,CAAC,QAAQ;IAkBhB;;;OAGG;IACH,OAAO,CAAC,IAAI;CA+Bb"}
package/dist/policy.js ADDED
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ // ── Policy enforcement (policy$ → the K2 protection ring) ─────────────────────
3
+ //
4
+ // A `PolicyAuthorizer` turns declarative `policy$` definitions into per-effect
5
+ // authorization decisions, so a `PolicyDefinition` attached to a flow/agent (or
6
+ // declared app-globally) is actually ENFORCED at the one boundary every side
7
+ // effect flows through (`EffectRuntime.execute`). It composes UNDER an existing
8
+ // authorizer (e.g. a `GrantTable`): an effect runs only if BOTH allow — policy
9
+ // can tighten, never widen, a grant (defense in depth). Pure + synchronous like
10
+ // every authorizer, so the decision is deterministic and replay-safe.
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PolicyAuthorizer = void 0;
13
+ const authz_1 = require("./authz");
14
+ /** Compile a glob (`*` → `.*`) to an anchored RegExp, escaping every other regex metachar. */
15
+ function globToRegExp(glob) {
16
+ const escaped = glob.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
17
+ return new RegExp(`^${escaped}$`);
18
+ }
19
+ function compilePatterns(entries) {
20
+ const exact = new Set();
21
+ const globs = [];
22
+ const qualified = new Map();
23
+ for (const entry of entries) {
24
+ if (entry.includes("*"))
25
+ globs.push(globToRegExp(entry));
26
+ else
27
+ exact.add(entry);
28
+ const colon = entry.indexOf(":");
29
+ if (colon > 0) {
30
+ const prefix = entry.slice(0, colon);
31
+ const list = qualified.get(prefix) ?? [];
32
+ list.push(entry);
33
+ qualified.set(prefix, list);
34
+ }
35
+ }
36
+ const q = new Map();
37
+ for (const [prefix, list] of qualified) {
38
+ const e = new Set();
39
+ const g = [];
40
+ for (const entry of list) {
41
+ if (entry.includes("*"))
42
+ g.push(globToRegExp(entry));
43
+ else
44
+ e.add(entry);
45
+ }
46
+ q.set(prefix, { exact: e, globs: g, qualified: new Map() });
47
+ }
48
+ return { exact, globs, qualified: q };
49
+ }
50
+ function patternSetMatches(set, value) {
51
+ return set.exact.has(value) || set.globs.some((g) => g.test(value));
52
+ }
53
+ /** DENY: stricter is safe — the bare effect id OR the qualified id may trigger it. */
54
+ function denyMatches(set, req) {
55
+ if (patternSetMatches(set, req.toolId))
56
+ return true;
57
+ return req.resource !== undefined && patternSetMatches(set, (0, authz_1.capabilityId)(req));
58
+ }
59
+ /** ALLOW: the bare effect id; the qualified id only through a pattern naming this effect exactly. */
60
+ function allowMatches(set, req) {
61
+ if (patternSetMatches(set, req.toolId))
62
+ return true;
63
+ if (req.resource === undefined)
64
+ return false;
65
+ const q = set.qualified.get(req.toolId);
66
+ return q !== undefined && patternSetMatches(q, (0, authz_1.capabilityId)(req));
67
+ }
68
+ function patternSetEmpty(set) {
69
+ return set.exact.size === 0 && set.globs.length === 0;
70
+ }
71
+ function asRules(rules) {
72
+ // `PolicyDefinition.rules` is a freeform bag; read the fields we interpret and
73
+ // ignore the rest (forward-compatible). Non-array fields degrade to empty.
74
+ const arr = (v) => (Array.isArray(v) ? v : []);
75
+ return {
76
+ allow: arr(rules.allow).filter((x) => typeof x === "string"),
77
+ deny: arr(rules.deny).filter((x) => typeof x === "string"),
78
+ match: arr(rules.match).filter((x) => typeof x === "object" && x !== null),
79
+ };
80
+ }
81
+ function compile(policy) {
82
+ const rules = asRules(policy.rules);
83
+ return {
84
+ allow: compilePatterns(rules.allow ?? []),
85
+ deny: compilePatterns(rules.deny ?? []),
86
+ match: (rules.match ?? []).map((m) => ({
87
+ deny: m.deny === true,
88
+ ...(m.effect !== undefined && {
89
+ effect: globToRegExp(m.effect),
90
+ ...(m.effect.indexOf(":") > 0 && {
91
+ effectQualifiedFor: [m.effect.slice(0, m.effect.indexOf(":"))],
92
+ }),
93
+ }),
94
+ ...(m.tenant !== undefined && { tenant: globToRegExp(m.tenant) }),
95
+ ...(m.step !== undefined && { step: globToRegExp(m.step) }),
96
+ })),
97
+ };
98
+ }
99
+ /**
100
+ * R12 — a DENY rule fires on the bare or qualified id; an ALLOW rule on the qualified id only
101
+ * when its own pattern names this effect exactly before the first `:`.
102
+ */
103
+ function effectMatches(rule, req) {
104
+ if (rule.effect === undefined)
105
+ return true;
106
+ if (rule.effect.test(req.toolId))
107
+ return true;
108
+ if (req.resource === undefined)
109
+ return false;
110
+ if (!rule.deny && !rule.effectQualifiedFor?.includes(req.toolId))
111
+ return false;
112
+ return rule.effect.test((0, authz_1.capabilityId)(req));
113
+ }
114
+ /** A compiled match rule fires when every present field matches the request. */
115
+ function matchFires(rule, req) {
116
+ if (rule.effect && !effectMatches(rule, req))
117
+ return false;
118
+ if (rule.tenant && !rule.tenant.test(req.principal?.tenant ?? ""))
119
+ return false;
120
+ if (rule.step && !rule.step.test(req.stepId))
121
+ return false;
122
+ return true;
123
+ }
124
+ /**
125
+ * Enforces `policy$` definitions as a {@link CapabilityAuthorizer}. Evaluation over
126
+ * the applicable policies (global ∪ the principal's) is **deny-wins**:
127
+ *
128
+ * 1. any `deny` entry or `deny` match that fires → **denied**;
129
+ * 2. else if an allow-constraint exists (a non-empty `allow` list, or any allow
130
+ * `match` rule) and nothing allows the effect → **denied**;
131
+ * 3. else → **allowed**.
132
+ *
133
+ * A principal with no policies (and no global policies) is allowed — policies are
134
+ * purely additive tightening, so wiring the authorizer never denies an effect that
135
+ * has no policy governing it (the composed `base`, if any, still applies).
136
+ */
137
+ class PolicyAuthorizer {
138
+ byPrincipal;
139
+ global;
140
+ base;
141
+ principalOf;
142
+ constructor(policiesByPrincipal, options = {}) {
143
+ this.byPrincipal = new Map(Object.entries(policiesByPrincipal).map(([k, v]) => [k, v.map(compile)]));
144
+ this.global = (options.global ?? []).map(compile);
145
+ this.base = options.base;
146
+ this.principalOf = options.principal ?? ((req) => req.workflowId);
147
+ }
148
+ authorize(req) {
149
+ // Defense in depth: the base authorizer must allow first; its denial is final.
150
+ if (this.base !== undefined) {
151
+ const baseDecision = this.base.authorize(req);
152
+ if (!baseDecision.allowed)
153
+ return baseDecision;
154
+ }
155
+ return this.evaluate(req);
156
+ }
157
+ evaluate(req) {
158
+ // Scan the global group then the principal's group directly — no merged-array allocation on
159
+ // this per-effect hot path. `state` accumulates the allow-list constraint across both groups.
160
+ const state = { constrained: false, allowed: false };
161
+ const denial = this.scan(this.global, req, state) ??
162
+ this.scan(this.byPrincipal.get(this.principalOf(req)), req, state);
163
+ if (denial !== undefined)
164
+ return denial;
165
+ if (state.constrained && !state.allowed) {
166
+ return {
167
+ allowed: false,
168
+ reason: `effect "${(0, authz_1.capabilityId)(req)}" not permitted by policy allow-list`,
169
+ };
170
+ }
171
+ return { allowed: true };
172
+ }
173
+ /**
174
+ * Scan one policy group. Returns a denial (deny-wins → final) or `undefined`, mutating `state`
175
+ * with any allow-list constraint seen. `undefined` policies (no group for the principal) no-op.
176
+ */
177
+ scan(policies, req, state) {
178
+ if (policies === undefined)
179
+ return undefined;
180
+ const deny = {
181
+ allowed: false,
182
+ reason: `effect "${(0, authz_1.capabilityId)(req)}" denied by policy`,
183
+ };
184
+ for (const policy of policies) {
185
+ // (1) deny-wins — an explicit deny list entry.
186
+ if (denyMatches(policy.deny, req))
187
+ return deny;
188
+ // (2) allow-list — its presence restricts to matching effects.
189
+ if (!patternSetEmpty(policy.allow)) {
190
+ state.constrained = true;
191
+ if (allowMatches(policy.allow, req))
192
+ state.allowed = true;
193
+ }
194
+ // (3) rich match rules — deny fires immediately; allow contributes.
195
+ for (const rule of policy.match) {
196
+ const fires = matchFires(rule, req);
197
+ if (rule.deny) {
198
+ if (fires)
199
+ return deny;
200
+ }
201
+ else {
202
+ state.constrained = true;
203
+ if (fires)
204
+ state.allowed = true;
205
+ }
206
+ }
207
+ }
208
+ return undefined;
209
+ }
210
+ }
211
+ exports.PolicyAuthorizer = PolicyAuthorizer;
212
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,sEAAsE;;;AAGtE,mCAAuC;AAiCvC,8FAA8F;AAC9F,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChF,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC;AACpC,CAAC;AAiBD,SAAS,eAAe,CAAC,OAA0B;IACjD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,SAAS,GA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