@aid-framework/ir 0.0.0 → 0.1.48
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 +201 -0
- package/README.md +199 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/build.d.ts +74 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +1079 -0
- package/dist/build.js.map +1 -0
- package/dist/capabilities.d.ts +65 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +176 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/catalog/index.d.ts +36 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +43 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/catalog/models.json +52 -0
- package/dist/diagnostics.d.ts +90 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +103 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/gates/agents.d.ts +34 -0
- package/dist/gates/agents.d.ts.map +1 -0
- package/dist/gates/agents.js +233 -0
- package/dist/gates/agents.js.map +1 -0
- package/dist/gates/capability.d.ts +15 -0
- package/dist/gates/capability.d.ts.map +1 -0
- package/dist/gates/capability.js +81 -0
- package/dist/gates/capability.js.map +1 -0
- package/dist/gates/contract.d.ts +35 -0
- package/dist/gates/contract.d.ts.map +1 -0
- package/dist/gates/contract.js +19 -0
- package/dist/gates/contract.js.map +1 -0
- package/dist/gates/cost.d.ts +40 -0
- package/dist/gates/cost.d.ts.map +1 -0
- package/dist/gates/cost.js +167 -0
- package/dist/gates/cost.js.map +1 -0
- package/dist/gates/deploy.d.ts +23 -0
- package/dist/gates/deploy.d.ts.map +1 -0
- package/dist/gates/deploy.js +44 -0
- package/dist/gates/deploy.js.map +1 -0
- package/dist/gates/eval-coverage.d.ts +11 -0
- package/dist/gates/eval-coverage.d.ts.map +1 -0
- package/dist/gates/eval-coverage.js +50 -0
- package/dist/gates/eval-coverage.js.map +1 -0
- package/dist/gates/guardrails.d.ts +24 -0
- package/dist/gates/guardrails.d.ts.map +1 -0
- package/dist/gates/guardrails.js +112 -0
- package/dist/gates/guardrails.js.map +1 -0
- package/dist/gates/hitl.d.ts +17 -0
- package/dist/gates/hitl.d.ts.map +1 -0
- package/dist/gates/hitl.js +40 -0
- package/dist/gates/hitl.js.map +1 -0
- package/dist/gates/index.d.ts +66 -0
- package/dist/gates/index.d.ts.map +1 -0
- package/dist/gates/index.js +77 -0
- package/dist/gates/index.js.map +1 -0
- package/dist/gates/memory.d.ts +13 -0
- package/dist/gates/memory.d.ts.map +1 -0
- package/dist/gates/memory.js +67 -0
- package/dist/gates/memory.js.map +1 -0
- package/dist/gates/normalize.d.ts +26 -0
- package/dist/gates/normalize.d.ts.map +1 -0
- package/dist/gates/normalize.js +228 -0
- package/dist/gates/normalize.js.map +1 -0
- package/dist/gates/orchestration.d.ts +17 -0
- package/dist/gates/orchestration.d.ts.map +1 -0
- package/dist/gates/orchestration.js +46 -0
- package/dist/gates/orchestration.js.map +1 -0
- package/dist/gates/referential.d.ts +12 -0
- package/dist/gates/referential.d.ts.map +1 -0
- package/dist/gates/referential.js +554 -0
- package/dist/gates/referential.js.map +1 -0
- package/dist/gates/security.d.ts +22 -0
- package/dist/gates/security.d.ts.map +1 -0
- package/dist/gates/security.js +225 -0
- package/dist/gates/security.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/policy/ast.d.ts +61 -0
- package/dist/policy/ast.d.ts.map +1 -0
- package/dist/policy/ast.js +48 -0
- package/dist/policy/ast.js.map +1 -0
- package/dist/policy/index.d.ts +7 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +4 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/lexer.d.ts +27 -0
- package/dist/policy/lexer.d.ts.map +1 -0
- package/dist/policy/lexer.js +147 -0
- package/dist/policy/lexer.js.map +1 -0
- package/dist/policy/parser.d.ts +15 -0
- package/dist/policy/parser.d.ts.map +1 -0
- package/dist/policy/parser.js +202 -0
- package/dist/policy/parser.js.map +1 -0
- package/dist/predicate/ast.d.ts +125 -0
- package/dist/predicate/ast.d.ts.map +1 -0
- package/dist/predicate/ast.js +111 -0
- package/dist/predicate/ast.js.map +1 -0
- package/dist/predicate/index.d.ts +7 -0
- package/dist/predicate/index.d.ts.map +1 -0
- package/dist/predicate/index.js +4 -0
- package/dist/predicate/index.js.map +1 -0
- package/dist/predicate/lexer.d.ts +30 -0
- package/dist/predicate/lexer.d.ts.map +1 -0
- package/dist/predicate/lexer.js +176 -0
- package/dist/predicate/lexer.js.map +1 -0
- package/dist/predicate/parser.d.ts +16 -0
- package/dist/predicate/parser.d.ts.map +1 -0
- package/dist/predicate/parser.js +317 -0
- package/dist/predicate/parser.js.map +1 -0
- package/dist/schema/ir.schema.json +1144 -0
- package/dist/serialize.d.ts +15 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +53 -0
- package/dist/serialize.js.map +1 -0
- package/dist/shapes.d.ts +671 -0
- package/dist/shapes.d.ts.map +1 -0
- package/dist/shapes.js +159 -0
- package/dist/shapes.js.map +1 -0
- package/package.json +44 -14
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate 5 — security. Fail-closed by default.
|
|
3
|
+
*
|
|
4
|
+
* The asymmetry is deliberate: a tool that writes or destroys and declares no `auth`
|
|
5
|
+
* is an error rather than a warning, because the safe reading of "no policy" is "no
|
|
6
|
+
* access", never "open access". Every rule this gate states is now live: the one it
|
|
7
|
+
* used to suppress is enforced below.
|
|
8
|
+
*
|
|
9
|
+
* The same asymmetry covers retrieval: a store reaches its backing service through
|
|
10
|
+
* `env:NAME`, so a connection string that appears literally in the IR is an error. No
|
|
11
|
+
* required gate touches a database -- the rule reads the declarations, never the store.
|
|
12
|
+
*/
|
|
13
|
+
import { sensitiveNames } from '../build.js';
|
|
14
|
+
import { IR_DIAGNOSTIC_CODES } from '../diagnostics.js';
|
|
15
|
+
import { reporter } from './contract.js';
|
|
16
|
+
/** Builtins whose presence means the policy actually authenticates the caller. */
|
|
17
|
+
const AUTHENTICATING_BUILTINS = ['isAuthenticated', 'hasRole', 'hasScope'];
|
|
18
|
+
/** The one uri form a store may carry: a reference into the environment. */
|
|
19
|
+
const ENV_REFERENCE = /^env:[A-Z][A-Z0-9_]{0,63}$/;
|
|
20
|
+
/**
|
|
21
|
+
* A uri whose authority carries userinfo, i.e. a credential inlined before the host.
|
|
22
|
+
* The userinfo cannot span a `/`, so a path segment that contains `@` is not a match.
|
|
23
|
+
*/
|
|
24
|
+
const URI_USERINFO = /^[a-z][a-z0-9+.-]*:\/\/[^/@\s]*@/i;
|
|
25
|
+
/**
|
|
26
|
+
* Empty, and empty on purpose. This was Phase 0's one suppressed rule:
|
|
27
|
+
*
|
|
28
|
+
* check: 'security/input-output-guardrails'
|
|
29
|
+
* reason: 'Phase 0 has no guardrail runtime, so whether a pipeline routes model
|
|
30
|
+
* input and output through a guardrail cannot be enforced; §7.4 defers
|
|
31
|
+
* the rule to the phase that ships one'
|
|
32
|
+
*
|
|
33
|
+
* It is no longer suppressed. Spec v0.2 makes `guardrails` declarable, so the question
|
|
34
|
+
* "does an endpoint that hands untrusted text to a model route it through an input
|
|
35
|
+
* guardrail?" can be answered from the declarations, and `checkInputGuardrails`
|
|
36
|
+
* answers it for every spec that can declare one. A 0.1 document predates the section
|
|
37
|
+
* and stays exempt — that is the version check, not a suppression entry, and the check
|
|
38
|
+
* says so in its own comment. What still has no runtime is *evaluating* the policy; that
|
|
39
|
+
* is the guardrails engine's layer, and a declared policy is the most this layer can
|
|
40
|
+
* honestly require.
|
|
41
|
+
*/
|
|
42
|
+
const SUPPRESSED = [];
|
|
43
|
+
export function securityGate(ir, options) {
|
|
44
|
+
const diagnostics = [];
|
|
45
|
+
const report = reporter(options);
|
|
46
|
+
for (const tool of ir.tools) {
|
|
47
|
+
checkToolAuth(tool, diagnostics, report);
|
|
48
|
+
}
|
|
49
|
+
checkRedaction(ir, diagnostics, report);
|
|
50
|
+
checkStoreSecrets(ir, diagnostics, report);
|
|
51
|
+
checkInputGuardrails(ir, diagnostics, report);
|
|
52
|
+
const tools = new Map(ir.tools.map((tool) => [tool.id, tool]));
|
|
53
|
+
for (const pipeline of ir.pipelines) {
|
|
54
|
+
checkUnauthenticatedPath(pipeline, tools, diagnostics, report);
|
|
55
|
+
}
|
|
56
|
+
return { diagnostics, suppressed: SUPPRESSED };
|
|
57
|
+
}
|
|
58
|
+
function checkToolAuth(tool, diagnostics, report) {
|
|
59
|
+
const mutates = tool.sideEffects === 'write' || tool.sideEffects === 'destructive';
|
|
60
|
+
if (mutates && tool.auth === undefined) {
|
|
61
|
+
diagnostics.push(report.error({
|
|
62
|
+
code: IR_DIAGNOSTIC_CODES.securityMissingAuth,
|
|
63
|
+
message: `the security gate rejected this tool: "${tool.id}" has sideEffects "${tool.sideEffects}" but declares no auth, so it is callable by anyone`,
|
|
64
|
+
path: ['tools', tool.id, 'auth'],
|
|
65
|
+
hint: "declare a policy such as isAuthenticated() and hasScope('x')",
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
if (tool.sideEffects === 'destructive' && !tool.requiresConfirmation) {
|
|
69
|
+
diagnostics.push(report.error({
|
|
70
|
+
code: IR_DIAGNOSTIC_CODES.securityMissingConfirmation,
|
|
71
|
+
message: `the security gate rejected this tool: "${tool.id}" is destructive but does not require confirmation`,
|
|
72
|
+
path: ['tools', tool.id, 'requiresConfirmation'],
|
|
73
|
+
hint: 'set requiresConfirmation: true',
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A trace config that is on must redact every field the IR marks as sensitive. An
|
|
79
|
+
* absent config is the builder's default (which redacts the whole sensitive set), so
|
|
80
|
+
* only a *declared* config can under-cover.
|
|
81
|
+
*/
|
|
82
|
+
function checkRedaction(ir, diagnostics, report) {
|
|
83
|
+
const sensitive = sensitiveNames(ir);
|
|
84
|
+
if (sensitive.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
checkRedactSet(ir.observability, sensitive, ['observability', 'redact'], diagnostics, report);
|
|
87
|
+
for (const pipeline of ir.pipelines) {
|
|
88
|
+
checkRedactSet(pipeline.observability, sensitive, ['pipelines', pipeline.id, 'observability', 'redact'], diagnostics, report);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function checkRedactSet(observability, sensitive, path, diagnostics, report) {
|
|
92
|
+
if (!observability.trace)
|
|
93
|
+
return;
|
|
94
|
+
const missing = sensitive.filter((name) => !observability.redact.includes(name));
|
|
95
|
+
if (missing.length === 0)
|
|
96
|
+
return;
|
|
97
|
+
diagnostics.push(report.error({
|
|
98
|
+
code: IR_DIAGNOSTIC_CODES.securityRedactionIncomplete,
|
|
99
|
+
message: `the security gate rejected this trace config: it is on but does not redact ${missing.join(', ')}, which the spec marks as sensitive`,
|
|
100
|
+
path,
|
|
101
|
+
hint: `add ${missing.join(', ')} to redact, or turn tracing off`,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A retrieval store is a connection to something outside the app, so the only form a
|
|
106
|
+
* store `uri` may take is a reference into the environment. A literal DSN in the IR is
|
|
107
|
+
* a credential in the IR: it is serialized into the golden files, printed by any tool
|
|
108
|
+
* that reads them, and committed. The check is repeated here rather than left to the
|
|
109
|
+
* spec schema because the IR is a published contract that a non-TypeScript producer can
|
|
110
|
+
* write directly.
|
|
111
|
+
*
|
|
112
|
+
* A retriever's `source.uri` is legitimately a literal -- a path, or a bucket URL for
|
|
113
|
+
* the reserved kinds -- so it is not restricted to `env:`. What it may not do is inline
|
|
114
|
+
* a credential into the authority, which is what the userinfo scan catches.
|
|
115
|
+
*/
|
|
116
|
+
function checkStoreSecrets(ir, diagnostics, report) {
|
|
117
|
+
for (const store of ir.stores) {
|
|
118
|
+
if (store.uri === undefined || ENV_REFERENCE.test(store.uri))
|
|
119
|
+
continue;
|
|
120
|
+
diagnostics.push(report.error({
|
|
121
|
+
code: IR_DIAGNOSTIC_CODES.securityStoreSecret,
|
|
122
|
+
message: `the security gate rejected this store: "${store.id}" declares uri "${store.uri}", a literal connection string; a store reaches its backing service through env:NAME, so the value stays out of the IR`,
|
|
123
|
+
path: ['stores', store.id, 'uri'],
|
|
124
|
+
hint: 'set uri to env:<NAME> and provide the value through the environment',
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
for (const retriever of ir.retrievers) {
|
|
128
|
+
if (!URI_USERINFO.test(retriever.source.uri))
|
|
129
|
+
continue;
|
|
130
|
+
diagnostics.push(report.error({
|
|
131
|
+
code: IR_DIAGNOSTIC_CODES.securityStoreSecret,
|
|
132
|
+
message: `the security gate rejected this source: "${retriever.id}" declares a uri with an inline credential in its authority, which the IR would then carry everywhere it is written`,
|
|
133
|
+
path: ['retrievers', retriever.id, 'source', 'uri'],
|
|
134
|
+
hint: 'drop the credentials from the uri and supply them through the environment',
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A pipeline behind an HTTP trigger must not reach a write or destructive tool
|
|
140
|
+
* through a policy that does not authenticate. A tool with *no* auth at all is
|
|
141
|
+
* already an error wherever it is used, so this narrows to the case that rule cannot
|
|
142
|
+
* see: auth is declared, but it is not an authentication predicate.
|
|
143
|
+
*/
|
|
144
|
+
function checkUnauthenticatedPath(pipeline, tools, diagnostics, report) {
|
|
145
|
+
const trigger = pipeline.trigger;
|
|
146
|
+
if (trigger.kind !== 'http')
|
|
147
|
+
return;
|
|
148
|
+
pipeline.steps.forEach((step, index) => {
|
|
149
|
+
if (step.kind !== 'tool')
|
|
150
|
+
return;
|
|
151
|
+
const tool = tools.get(step.tool);
|
|
152
|
+
if (tool === undefined)
|
|
153
|
+
return;
|
|
154
|
+
if (tool.sideEffects !== 'write' && tool.sideEffects !== 'destructive')
|
|
155
|
+
return;
|
|
156
|
+
if (tool.auth === undefined || policyAuthenticates(tool.auth))
|
|
157
|
+
return;
|
|
158
|
+
diagnostics.push(report.error({
|
|
159
|
+
code: IR_DIAGNOSTIC_CODES.securityUnauthenticatedPath,
|
|
160
|
+
message: `the security gate rejected this endpoint: the ${trigger.method.toUpperCase()} ${trigger.path} trigger reaches "${tool.id}", which ${tool.sideEffects === 'write' ? 'writes' : 'destroys'} and whose declared policy does not authenticate the caller`,
|
|
161
|
+
path: ['pipelines', pipeline.id, 'steps', index, 'tool'],
|
|
162
|
+
hint: `give "${tool.id}" a policy built from ${AUTHENTICATING_BUILTINS.join(', ')}`,
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* §7.4, now live: an HTTP endpoint hands untrusted text straight to a model, so the IR
|
|
168
|
+
* has to show a guardrail that inspects it first. "Untrusted" is the HTTP trigger and
|
|
169
|
+
* only that trigger — a scheduled job and a manual run carry no caller-supplied text,
|
|
170
|
+
* and demanding a guardrail for them would be a declaration with nothing to inspect.
|
|
171
|
+
*
|
|
172
|
+
* The discriminator is the declared spec version, not the number of declared guardrails.
|
|
173
|
+
* A spec written against v0.1 predates the section and cannot opt into it, and
|
|
174
|
+
* retroactively failing every such project is a breaking change rather than a safety
|
|
175
|
+
* improvement. A spec written against v0.2 *can* declare guardrails, so declaring none
|
|
176
|
+
* is a decision rather than an inability, and it is not a reason to stay silent: an
|
|
177
|
+
* endpoint that hands caller text to a model with no input-stage guardrail fails the
|
|
178
|
+
* gate either way. Keying this on the declaration count instead would let a v0.2 spec
|
|
179
|
+
* buy an exemption by simply omitting the section.
|
|
180
|
+
*
|
|
181
|
+
* What this layer still does not do is *evaluate* the policy; that is the guardrails
|
|
182
|
+
* engine's layer (L3). A declared policy is the most this layer can honestly require,
|
|
183
|
+
* and making the declaration itself unconditional is the engine layer's call.
|
|
184
|
+
*/
|
|
185
|
+
function checkInputGuardrails(ir, diagnostics, report) {
|
|
186
|
+
if (ir.specVersion === '0.1')
|
|
187
|
+
return;
|
|
188
|
+
if (!ir.guardrails.some((guardrail) => guardrail.stages.includes('input'))) {
|
|
189
|
+
for (const pipeline of ir.pipelines) {
|
|
190
|
+
const trigger = pipeline.trigger;
|
|
191
|
+
if (trigger.kind !== 'http')
|
|
192
|
+
continue;
|
|
193
|
+
const generate = pipeline.steps.find((step) => step.kind === 'generate');
|
|
194
|
+
if (generate === undefined)
|
|
195
|
+
continue;
|
|
196
|
+
diagnostics.push(report.error({
|
|
197
|
+
code: IR_DIAGNOSTIC_CODES.securityInputGuardrail,
|
|
198
|
+
message: `the security gate rejected this endpoint: the ${trigger.method.toUpperCase()} ${trigger.path} trigger passes caller-supplied text to prompt "${generate.prompt}", but the specification declares no guardrail with an "input" stage`,
|
|
199
|
+
path: ['pipelines', pipeline.id, 'steps', pipeline.steps.indexOf(generate)],
|
|
200
|
+
hint: 'declare a guardrail with stages: [input]',
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* True when the policy mentions a builtin that establishes caller identity. `not` is
|
|
207
|
+
* deliberately not transparent: `not isAuthenticated()` denies what it names, so
|
|
208
|
+
* treating it as authenticating would be the fail-open reading.
|
|
209
|
+
*/ export function policyAuthenticates(node) {
|
|
210
|
+
switch (node.kind) {
|
|
211
|
+
case 'call':
|
|
212
|
+
return (AUTHENTICATING_BUILTINS.includes(node.name) ||
|
|
213
|
+
node.args.some(policyAuthenticates));
|
|
214
|
+
case 'comparison':
|
|
215
|
+
return policyAuthenticates(node.left) || policyAuthenticates(node.right);
|
|
216
|
+
case 'and':
|
|
217
|
+
case 'or':
|
|
218
|
+
return policyAuthenticates(node.left) || policyAuthenticates(node.right);
|
|
219
|
+
case 'not':
|
|
220
|
+
return false;
|
|
221
|
+
default:
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 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
|
1
|
+
/**
|
|
2
|
+
* `@aid-framework/ir` — the packed intermediate representation, its builder, its build-time
|
|
3
|
+
* gates, the canonical serializer, and the PolicyExpr front end.
|
|
4
|
+
*
|
|
5
|
+
* The public entry point layer 3 (`generator-sdk`) consumes: `buildIR` turns a
|
|
6
|
+
* parsed spec value into an `IR`, `runGates` decides whether that IR is buildable
|
|
7
|
+
* for a set of target capability declarations, and `serializeIR` renders it as
|
|
8
|
+
* canonical JSON whose bytes are a function of identity alone.
|
|
9
|
+
*/
|
|
10
|
+
export type { BuildContext, BuildOptions, BuildResult } from './build.js';
|
|
11
|
+
export { asArray, asBoolean, asNumber, asRecord, asString, asStringArray, buildEvalTarget, buildIR, buildTypeRef, DEFAULT_EVAL_MAX_REGRESSION, DEFAULT_EVAL_SAMPLES, DEFAULT_IDEMPOTENCY, DEFAULT_TARGET, DEFAULT_TOOL_RETRIES, DEFAULT_TOOL_TIMEOUT_MS, isBindingName, isSensitiveName, sensitiveNames, sortedKeys, templatePlaceholders, } from './build.js';
|
|
12
|
+
export type { DeferredCapability, ModelCapability, RequiredCapability } from './capabilities.js';
|
|
13
|
+
export { CAPABILITY_DERIVATIONS, DEFERRED_CAPABILITIES, deriveRequiredCapabilities, isModelCapability, isRequiredCapability, MODEL_CAPABILITIES, REQUIRED_CAPABILITIES, resolveRequiredCapability, SPEC_MODEL_CAPABILITY_MAP, TARGET_CAPABILITY_ALIASES, } from './capabilities.js';
|
|
14
|
+
export type { CatalogModel, TargetCapabilityDeclarations } from './catalog/index.js';
|
|
15
|
+
export { CATALOG_VERSION, catalogCostProfile, catalogCostProfiles, catalogModel, PHASE_0_TARGET_CAPABILITIES, phase0TargetCapabilities, } from './catalog/index.js';
|
|
16
|
+
export type { IrDiagnostic, IrDiagnosticCode } from './diagnostics.js';
|
|
17
|
+
export { IR_DIAGNOSTIC_CODES, irError, irWarning, offsetPosition, withPosition, } from './diagnostics.js';
|
|
18
|
+
export type { EvalCostEstimate, Gate, GateId, GateName, GateOptions, GateReporter, GateResult, GateRunResult, ModelCostEstimate, SuppressedCheck, } from './gates/index.js';
|
|
19
|
+
export { capabilityGate, costGate, diffPaths, estimateEvalCost, evalCoverageGate, GATES, isNormalized, normalize, normalizeGate, policyAuthenticates, referentialGate, reporter, runGates, securityGate, } from './gates/index.js';
|
|
20
|
+
export type { ComparisonOperator, LexResult, PolicyBuiltin, PolicyCall, PolicyComparison, PolicyContext, PolicyExpr, PolicyLogical, PolicyNode, PolicyNot, PolicyOperand, PolicyParseResult, PolicyToken, PolicyTokenType, } from './policy/index.js';
|
|
21
|
+
export { COMPARISON_OPERATORS, formatPolicyExpr, isPolicyBuiltin, POLICY_BUILTIN_ARITY, POLICY_BUILTINS, parsePolicyExpr, tokenize, tokenText, } from './policy/index.js';
|
|
22
|
+
export type { OrderingOperator, PredicateBuiltin, PredicateCall, PredicateCaseId, PredicateComparison, PredicateContext, PredicateExpr, PredicateInvalid, PredicateLexResult, PredicateLogical, PredicateMetadata, PredicateNode, PredicateNot, PredicateOperator, PredicateParseResult, PredicatePath, PredicatePathRoot, PredicatePrediction, PredicateToken, PredicateTokenType, } from './predicate/index.js';
|
|
23
|
+
export { formatPredicateExpr, isOrderingOperator, isPredicateBuiltin, ORDERING_OPERATORS, PREDICATE_BUILTIN_ARITY, PREDICATE_BUILTINS, PREDICATE_OPERATORS, PREDICATE_PATHS, parsePredicateExpr, predicateIsBoolean, tokenizePredicate, } from './predicate/index.js';
|
|
24
|
+
export { CANONICAL_INDENT, canonicalJson, serializeIR } from './serialize.js';
|
|
25
|
+
export type { AgentEngine, AgentOnBudgetExhausted, AgentShape, AgentStep, BranchStep, CompositeStep, CostProfile, DeploymentShape, EmbeddingShape, EmitStep, ErrorPolicy, EvalDataset, EvalGate, EvalShape, EvalTarget, EvalTargetKind, GenerateStep, GuardrailShape, GuardStep, Idempotency, IR, IrCollection, MapStep, MemoryShape, MetricShape, ModelLimits, ModelParams, ModelShape, ObservabilityShape, ParallelStep, PipelineShape, PipelineTrigger, PrimitiveType, ProjectShape, PromptOutput, PromptShape, PromptVariable, Provider, ReduceStep, RerankStep, RetrieverShape, RetrieveStep, RuntimeShape, SideEffects, StepInput, StepInputValue, StepShape, ToolHandler, ToolShape, ToolStep, Trait, TypeField, TypeRef, TypeShape, VectorStoreShape, } from './shapes.js';
|
|
26
|
+
export { AGENT_ENGINES, AGENT_ON_BUDGET_EXHAUSTED, COMPOSITE_STEP_KINDS, DEFAULT_MAX_CONTEXT_TOKENS, DEFAULT_OBSERVABILITY, DEFAULT_RUNTIME, EVAL_TARGET_KINDS, IR_COLLECTIONS, IR_ONLY_COLLECTIONS, IR_VERSION, isCompositeStep, isProvider, MAX_STEP_DEPTH, modelIdentity, NON_COLLECTION_SECTIONS, PHASE_0_PROVIDERS, POPULATED_COLLECTION_BY_SECTION, PRIMITIVE_TYPES, PROVIDERS, pipelineIdentity, promptIdentity, toolIdentity, } from './shapes.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,eAAe,EACf,OAAO,EACP,YAAY,EACZ,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,uBAAuB,EACvB,aAAa,EACb,eAAe,EACf,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,EACjB,oBAA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,EACrB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,+BAA+B,EAC/B,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@aid-framework/ir` — the packed intermediate representation, its builder, its build-time
|
|
3
|
+
* gates, the canonical serializer, and the PolicyExpr front end.
|
|
4
|
+
*
|
|
5
|
+
* The public entry point layer 3 (`generator-sdk`) consumes: `buildIR` turns a
|
|
6
|
+
* parsed spec value into an `IR`, `runGates` decides whether that IR is buildable
|
|
7
|
+
* for a set of target capability declarations, and `serializeIR` renders it as
|
|
8
|
+
* canonical JSON whose bytes are a function of identity alone.
|
|
9
|
+
*/
|
|
10
|
+
export { asArray, asBoolean, asNumber, asRecord, asString, asStringArray, buildEvalTarget, buildIR, buildTypeRef, DEFAULT_EVAL_MAX_REGRESSION, DEFAULT_EVAL_SAMPLES, DEFAULT_IDEMPOTENCY, DEFAULT_TARGET, DEFAULT_TOOL_RETRIES, DEFAULT_TOOL_TIMEOUT_MS, isBindingName, isSensitiveName, sensitiveNames, sortedKeys, templatePlaceholders, } from './build.js';
|
|
11
|
+
export { CAPABILITY_DERIVATIONS, DEFERRED_CAPABILITIES, deriveRequiredCapabilities, isModelCapability, isRequiredCapability, MODEL_CAPABILITIES, REQUIRED_CAPABILITIES, resolveRequiredCapability, SPEC_MODEL_CAPABILITY_MAP, TARGET_CAPABILITY_ALIASES, } from './capabilities.js';
|
|
12
|
+
export { CATALOG_VERSION, catalogCostProfile, catalogCostProfiles, catalogModel, PHASE_0_TARGET_CAPABILITIES, phase0TargetCapabilities, } from './catalog/index.js';
|
|
13
|
+
export { IR_DIAGNOSTIC_CODES, irError, irWarning, offsetPosition, withPosition, } from './diagnostics.js';
|
|
14
|
+
export { capabilityGate, costGate, diffPaths, estimateEvalCost, evalCoverageGate, GATES, isNormalized, normalize, normalizeGate, policyAuthenticates, referentialGate, reporter, runGates, securityGate, } from './gates/index.js';
|
|
15
|
+
export { COMPARISON_OPERATORS, formatPolicyExpr, isPolicyBuiltin, POLICY_BUILTIN_ARITY, POLICY_BUILTINS, parsePolicyExpr, tokenize, tokenText, } from './policy/index.js';
|
|
16
|
+
export { formatPredicateExpr, isOrderingOperator, isPredicateBuiltin, ORDERING_OPERATORS, PREDICATE_BUILTIN_ARITY, PREDICATE_BUILTINS, PREDICATE_OPERATORS, PREDICATE_PATHS, parsePredicateExpr, predicateIsBoolean, tokenizePredicate, } from './predicate/index.js';
|
|
17
|
+
export { CANONICAL_INDENT, canonicalJson, serializeIR } from './serialize.js';
|
|
18
|
+
export { AGENT_ENGINES, AGENT_ON_BUDGET_EXHAUSTED, COMPOSITE_STEP_KINDS, DEFAULT_MAX_CONTEXT_TOKENS, DEFAULT_OBSERVABILITY, DEFAULT_RUNTIME, EVAL_TARGET_KINDS, IR_COLLECTIONS, IR_ONLY_COLLECTIONS, IR_VERSION, isCompositeStep, isProvider, MAX_STEP_DEPTH, modelIdentity, NON_COLLECTION_SECTIONS, PHASE_0_PROVIDERS, POPULATED_COLLECTION_BY_SECTION, PRIMITIVE_TYPES, PROVIDERS, pipelineIdentity, promptIdentity, toolIdentity, } from './shapes.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,eAAe,EACf,OAAO,EACP,YAAY,EACZ,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,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d,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,+BAA+B,EAC/B,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyExpr AST. Phase 0 supports exactly this grammar and anything else is a
|
|
3
|
+
* validation error, never a silent pass. The AST is plain JSON so it can be
|
|
4
|
+
* embedded in the IR and interpreted by any target without a second parser.
|
|
5
|
+
*
|
|
6
|
+
* expression := or
|
|
7
|
+
* or := and ('or' and)*
|
|
8
|
+
* and := comparison ('and' comparison)*
|
|
9
|
+
* comparison := unary (('==' | '!=' | '<' | '<=' | '>' | '>=') unary)?
|
|
10
|
+
* unary := 'not' unary | primary
|
|
11
|
+
* primary := 'true' | 'false' | string | number | call | '(' expression ')'
|
|
12
|
+
* call := builtin '(' (operand (',' operand)*)? ')'
|
|
13
|
+
* operand := primary
|
|
14
|
+
*
|
|
15
|
+
* Precedence, tightest first: `not`, comparison, `and`, `or`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const POLICY_BUILTINS: readonly ['hasRole', 'hasScope', 'isAuthenticated'];
|
|
18
|
+
export type PolicyBuiltin = (typeof POLICY_BUILTINS)[number];
|
|
19
|
+
export declare const COMPARISON_OPERATORS: readonly ['==', '!=', '<=', '>=', '<', '>'];
|
|
20
|
+
export type ComparisonOperator = (typeof COMPARISON_OPERATORS)[number];
|
|
21
|
+
/** A state predicate call. Arguments are nodes; only the builtins above are accepted. */
|
|
22
|
+
export interface PolicyCall {
|
|
23
|
+
kind: 'call';
|
|
24
|
+
name: PolicyBuiltin;
|
|
25
|
+
args: PolicyNode[];
|
|
26
|
+
}
|
|
27
|
+
export interface PolicyComparison {
|
|
28
|
+
kind: 'comparison';
|
|
29
|
+
op: ComparisonOperator;
|
|
30
|
+
left: PolicyNode;
|
|
31
|
+
right: PolicyNode;
|
|
32
|
+
}
|
|
33
|
+
export interface PolicyLogical {
|
|
34
|
+
kind: 'and' | 'or';
|
|
35
|
+
left: PolicyNode;
|
|
36
|
+
right: PolicyNode;
|
|
37
|
+
}
|
|
38
|
+
export interface PolicyNot {
|
|
39
|
+
kind: 'not';
|
|
40
|
+
operand: PolicyNode;
|
|
41
|
+
}
|
|
42
|
+
export type PolicyNode = PolicyCall | PolicyComparison | PolicyLogical | PolicyNot | {
|
|
43
|
+
kind: 'string';
|
|
44
|
+
value: string;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'number';
|
|
47
|
+
value: number;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'boolean';
|
|
50
|
+
value: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** An argument position: any node, including a nested call. */
|
|
53
|
+
export type PolicyOperand = PolicyNode;
|
|
54
|
+
/** A parsed policy expression; always a node, never the source string. */
|
|
55
|
+
export type PolicyExpr = PolicyNode;
|
|
56
|
+
/** Arity of each builtin; the parser rejects any other argument count. */
|
|
57
|
+
export declare const POLICY_BUILTIN_ARITY: Record<PolicyBuiltin, number>;
|
|
58
|
+
export declare function isPolicyBuiltin(name: string): name is PolicyBuiltin;
|
|
59
|
+
/** Renders an AST back to a normalized source form, for diagnostic messages. */
|
|
60
|
+
export declare function formatPolicyExpr(node: PolicyNode): string;
|
|
61
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/policy/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,eAAe,YAAI,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAU,CAAC;AAEnF,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,eAAO,MAAM,oBAAoB,YAAI,IAAI,EAAE,IAAI,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a,CAEnE;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAkBzD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyExpr AST. Phase 0 supports exactly this grammar and anything else is a
|
|
3
|
+
* validation error, never a silent pass. The AST is plain JSON so it can be
|
|
4
|
+
* embedded in the IR and interpreted by any target without a second parser.
|
|
5
|
+
*
|
|
6
|
+
* expression := or
|
|
7
|
+
* or := and ('or' and)*
|
|
8
|
+
* and := comparison ('and' comparison)*
|
|
9
|
+
* comparison := unary (('==' | '!=' | '<' | '<=' | '>' | '>=') unary)?
|
|
10
|
+
* unary := 'not' unary | primary
|
|
11
|
+
* primary := 'true' | 'false' | string | number | call | '(' expression ')'
|
|
12
|
+
* call := builtin '(' (operand (',' operand)*)? ')'
|
|
13
|
+
* operand := primary
|
|
14
|
+
*
|
|
15
|
+
* Precedence, tightest first: `not`, comparison, `and`, `or`.
|
|
16
|
+
*/
|
|
17
|
+
export const POLICY_BUILTINS = ['hasRole', 'hasScope', 'isAuthenticated'];
|
|
18
|
+
export const COMPARISON_OPERATORS = ['==', '!=', '<=', '>=', '<', '>'];
|
|
19
|
+
/** Arity of each builtin; the parser rejects any other argument count. */
|
|
20
|
+
export const POLICY_BUILTIN_ARITY = {
|
|
21
|
+
hasRole: 1,
|
|
22
|
+
hasScope: 1,
|
|
23
|
+
isAuthenticated: 0,
|
|
24
|
+
};
|
|
25
|
+
export function isPolicyBuiltin(name) {
|
|
26
|
+
return POLICY_BUILTINS.includes(name);
|
|
27
|
+
}
|
|
28
|
+
/** Renders an AST back to a normalized source form, for diagnostic messages. */
|
|
29
|
+
export function formatPolicyExpr(node) {
|
|
30
|
+
switch (node.kind) {
|
|
31
|
+
case 'string':
|
|
32
|
+
return JSON.stringify(node.value);
|
|
33
|
+
case 'number':
|
|
34
|
+
return String(node.value);
|
|
35
|
+
case 'boolean':
|
|
36
|
+
return node.value ? 'true' : 'false';
|
|
37
|
+
case 'call':
|
|
38
|
+
return `${node.name}(${node.args.map(formatPolicyExpr).join(', ')})`;
|
|
39
|
+
case 'comparison':
|
|
40
|
+
return `${formatPolicyExpr(node.left)} ${node.op} ${formatPolicyExpr(node.right)}`;
|
|
41
|
+
case 'and':
|
|
42
|
+
case 'or':
|
|
43
|
+
return `(${formatPolicyExpr(node.left)} ${node.kind} ${formatPolicyExpr(node.right)})`;
|
|
44
|
+
case 'not':
|
|
45
|
+
return `not ${formatPolicyExpr(node.operand)}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/policy/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAU,CAAC;AAInF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AA4ChF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAkC;IACjE,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,eAAe,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAQ,eAAqC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAAC,IAAgB;IAC/C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACvC,KAAK,MAAM;YACT,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACvE,KAAK,YAAY;YACf,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrF,KAAK,KAAK,CAAC;QACX,KAAK,IAAI;YACP,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QACzF,KAAK,KAAK;YACR,OAAO,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACnD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ComparisonOperator, PolicyBuiltin, PolicyCall, PolicyComparison, PolicyExpr, PolicyLogical, PolicyNode, PolicyNot, PolicyOperand, } from './ast.js';
|
|
2
|
+
export { COMPARISON_OPERATORS, formatPolicyExpr, isPolicyBuiltin, POLICY_BUILTIN_ARITY, POLICY_BUILTINS, } from './ast.js';
|
|
3
|
+
export type { LexResult, PolicyContext, PolicyToken, PolicyTokenType } from './lexer.js';
|
|
4
|
+
export { tokenize, tokenText } from './lexer.js';
|
|
5
|
+
export type { PolicyParseResult } from './parser.js';
|
|
6
|
+
export { parsePolicyExpr } from './parser.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyExpr lexer. Tracks byte offsets so every diagnostic can point at the
|
|
3
|
+
* offending span. Never throws: malformed input yields tokens plus diagnostics.
|
|
4
|
+
*/
|
|
5
|
+
import type { DiagnosticPath } from '@aid-framework/spec';
|
|
6
|
+
import { IR_DIAGNOSTIC_CODES, type IrDiagnostic } from '../diagnostics.js';
|
|
7
|
+
export type PolicyTokenType = 'boolean' | 'number' | 'string' | 'identifier' | 'operator' | 'lparen' | 'rparen' | 'comma' | 'eof';
|
|
8
|
+
export interface PolicyToken {
|
|
9
|
+
type: PolicyTokenType;
|
|
10
|
+
/** Decoded value for literals and identifiers; the raw text for operators. */
|
|
11
|
+
value: string | number | boolean;
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}
|
|
15
|
+
export interface PolicyContext {
|
|
16
|
+
path?: DiagnosticPath;
|
|
17
|
+
file?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LexResult {
|
|
20
|
+
tokens: PolicyToken[];
|
|
21
|
+
diagnostics: IrDiagnostic[];
|
|
22
|
+
}
|
|
23
|
+
export declare function policyDiagnostic(source: string, context: PolicyContext, offset: number, code: (typeof IR_DIAGNOSTIC_CODES)[keyof typeof IR_DIAGNOSTIC_CODES], message: string, hint?: string): IrDiagnostic;
|
|
24
|
+
export declare function tokenize(source: string, context?: PolicyContext): LexResult;
|
|
25
|
+
/** The token's text as written, for messages. */
|
|
26
|
+
export declare function tokenText(token: PolicyToken): string;
|
|
27
|
+
//# sourceMappingURL=lexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../../src/policy/lexer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,mBAAmB,EACnB,KAAK,YAAY,EAIlB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,KAAK,CAAC;AAEV,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,WAAW,EAAE,YAAY,EAAE,CAAC;CAC7B;AAID,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,EACpE,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,YAAY,CAOd;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,SAAS,CA0F/E;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAIpD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyExpr lexer. Tracks byte offsets so every diagnostic can point at the
|
|
3
|
+
* offending span. Never throws: malformed input yields tokens plus diagnostics.
|
|
4
|
+
*/
|
|
5
|
+
import { IR_DIAGNOSTIC_CODES, irError, offsetPosition, withPosition, } from '../diagnostics.js';
|
|
6
|
+
const KEYWORDS = new Set(['true', 'false', 'and', 'or', 'not']);
|
|
7
|
+
export function policyDiagnostic(source, context, offset, code, message, hint) {
|
|
8
|
+
const { line, column } = offsetPosition(source, offset);
|
|
9
|
+
return withPosition(irError({ code, message, path: context.path, hint }), {
|
|
10
|
+
file: context.file,
|
|
11
|
+
line,
|
|
12
|
+
column,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function tokenize(source, context = {}) {
|
|
16
|
+
const tokens = [];
|
|
17
|
+
const diagnostics = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
while (index < source.length) {
|
|
20
|
+
const char = source[index];
|
|
21
|
+
if (char === ' ' || char === '\t' || char === '\n' || char === '\r') {
|
|
22
|
+
index += 1;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (char === '(' || char === ')' || char === ',') {
|
|
26
|
+
const type = char === '(' ? 'lparen' : char === ')' ? 'rparen' : 'comma';
|
|
27
|
+
tokens.push({ type, value: char, start: index, end: index + 1 });
|
|
28
|
+
index += 1;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (char === '"' || char === "'") {
|
|
32
|
+
const end = scanString(source, index, char);
|
|
33
|
+
if (end === -1) {
|
|
34
|
+
diagnostics.push(policyDiagnostic(source, context, index, IR_DIAGNOSTIC_CODES.policyUnterminatedString, 'unterminated string literal', 'close the string with the same quote character it opened with'));
|
|
35
|
+
index = source.length;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
tokens.push({
|
|
39
|
+
type: 'string',
|
|
40
|
+
value: decodeString(source.slice(index + 1, end - 1)),
|
|
41
|
+
start: index,
|
|
42
|
+
end,
|
|
43
|
+
});
|
|
44
|
+
index = end;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (char >= '0' && char <= '9') {
|
|
48
|
+
const end = scanNumber(source, index);
|
|
49
|
+
tokens.push({ type: 'number', value: Number(source.slice(index, end)), start: index, end });
|
|
50
|
+
index = end;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (isIdentifierStart(char)) {
|
|
54
|
+
const end = scanIdentifier(source, index);
|
|
55
|
+
const text = source.slice(index, end);
|
|
56
|
+
if (text === 'true' || text === 'false') {
|
|
57
|
+
tokens.push({ type: 'boolean', value: text === 'true', start: index, end });
|
|
58
|
+
}
|
|
59
|
+
else if (KEYWORDS.has(text)) {
|
|
60
|
+
tokens.push({ type: 'operator', value: text, start: index, end });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
tokens.push({ type: 'identifier', value: text, start: index, end });
|
|
64
|
+
}
|
|
65
|
+
index = end;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const pair = source.slice(index, index + 2);
|
|
69
|
+
if (pair === '==' || pair === '!=' || pair === '<=' || pair === '>=') {
|
|
70
|
+
tokens.push({ type: 'operator', value: pair, start: index, end: index + 2 });
|
|
71
|
+
index += 2;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (char === '<' || char === '>') {
|
|
75
|
+
tokens.push({ type: 'operator', value: char, start: index, end: index + 1 });
|
|
76
|
+
index += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
diagnostics.push(policyDiagnostic(source, context, index, IR_DIAGNOSTIC_CODES.policySyntax, `unexpected character ${JSON.stringify(char)}`, 'PolicyExpr supports literals, comparisons, and/or/not, parentheses, and the hasRole/hasScope/isAuthenticated builtins'));
|
|
80
|
+
index += 1;
|
|
81
|
+
}
|
|
82
|
+
tokens.push({ type: 'eof', value: '', start: source.length, end: source.length });
|
|
83
|
+
return { tokens, diagnostics };
|
|
84
|
+
}
|
|
85
|
+
/** The token's text as written, for messages. */
|
|
86
|
+
export function tokenText(token) {
|
|
87
|
+
if (token.type === 'string')
|
|
88
|
+
return JSON.stringify(token.value);
|
|
89
|
+
if (token.type === 'boolean')
|
|
90
|
+
return String(token.value);
|
|
91
|
+
return String(token.value);
|
|
92
|
+
}
|
|
93
|
+
function scanString(source, start, quote) {
|
|
94
|
+
let index = start + 1;
|
|
95
|
+
while (index < source.length) {
|
|
96
|
+
const char = source[index];
|
|
97
|
+
if (char === '\\') {
|
|
98
|
+
index += 2;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (char === quote)
|
|
102
|
+
return index + 1;
|
|
103
|
+
index += 1;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
function decodeString(raw) {
|
|
108
|
+
let decoded = '';
|
|
109
|
+
for (let index = 0; index < raw.length; index += 1) {
|
|
110
|
+
const char = raw[index];
|
|
111
|
+
if (char === '\\' && index + 1 < raw.length) {
|
|
112
|
+
const next = raw[index + 1];
|
|
113
|
+
decoded += next === 'n' ? '\n' : next === 't' ? '\t' : next === 'r' ? '\r' : next;
|
|
114
|
+
index += 1;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
decoded += char;
|
|
118
|
+
}
|
|
119
|
+
return decoded;
|
|
120
|
+
}
|
|
121
|
+
function scanNumber(source, start) {
|
|
122
|
+
let index = start;
|
|
123
|
+
while (index < source.length && isDigit(source[index]))
|
|
124
|
+
index += 1;
|
|
125
|
+
if (index < source.length && source[index] === '.') {
|
|
126
|
+
index += 1;
|
|
127
|
+
while (index < source.length && isDigit(source[index]))
|
|
128
|
+
index += 1;
|
|
129
|
+
}
|
|
130
|
+
return index;
|
|
131
|
+
}
|
|
132
|
+
function scanIdentifier(source, start) {
|
|
133
|
+
let index = start;
|
|
134
|
+
while (index < source.length && isIdentifierPart(source[index]))
|
|
135
|
+
index += 1;
|
|
136
|
+
return index;
|
|
137
|
+
}
|
|
138
|
+
function isDigit(char) {
|
|
139
|
+
return char >= '0' && char <= '9';
|
|
140
|
+
}
|
|
141
|
+
function isIdentifierStart(char) {
|
|
142
|
+
return (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || char === '_';
|
|
143
|
+
}
|
|
144
|
+
function isIdentifierPart(char) {
|
|
145
|
+
return isIdentifierStart(char) || isDigit(char);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=lexer.js.map
|