@a5c-ai/babysitter-sdk 0.0.188-staging.e72bed21 → 0.0.188-staging.f022ecec
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/dist/cli/commands/instructions.d.ts.map +1 -1
- package/dist/cli/commands/instructions.js +30 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +9 -2
- package/dist/governance/authority.d.ts +68 -0
- package/dist/governance/authority.d.ts.map +1 -0
- package/dist/governance/authority.js +136 -0
- package/dist/governance/categories.d.ts +58 -0
- package/dist/governance/categories.d.ts.map +1 -0
- package/dist/governance/categories.js +120 -0
- package/dist/governance/index.d.ts +8 -0
- package/dist/governance/index.d.ts.map +1 -1
- package/dist/governance/index.js +47 -1
- package/dist/governance/mandate.d.ts +83 -0
- package/dist/governance/mandate.d.ts.map +1 -0
- package/dist/governance/mandate.js +180 -0
- package/dist/governance/permissionEvents.d.ts +51 -0
- package/dist/governance/permissionEvents.d.ts.map +1 -0
- package/dist/governance/permissionEvents.js +52 -0
- package/dist/governance/permissionPropagation.d.ts +18 -0
- package/dist/governance/permissionPropagation.d.ts.map +1 -0
- package/dist/governance/permissionPropagation.js +58 -0
- package/dist/governance/postureBridge.d.ts +17 -0
- package/dist/governance/postureBridge.d.ts.map +1 -0
- package/dist/governance/postureBridge.js +117 -0
- package/dist/governance/sandboxBridge.d.ts +49 -0
- package/dist/governance/sandboxBridge.d.ts.map +1 -0
- package/dist/governance/sandboxBridge.js +77 -0
- package/dist/governance/sandboxPolicy.d.ts +51 -0
- package/dist/governance/sandboxPolicy.d.ts.map +1 -0
- package/dist/governance/sandboxPolicy.js +177 -0
- package/dist/harness/claudeCode.d.ts.map +1 -1
- package/dist/harness/claudeCode.js +11 -17
- package/dist/prompts/capabilityProcessMap.d.ts +33 -0
- package/dist/prompts/capabilityProcessMap.d.ts.map +1 -0
- package/dist/prompts/capabilityProcessMap.js +105 -0
- package/dist/prompts/compose.d.ts.map +1 -1
- package/dist/prompts/compose.js +6 -0
- package/dist/prompts/context.d.ts.map +1 -1
- package/dist/prompts/context.js +3 -0
- package/dist/prompts/contextDetect.d.ts +64 -0
- package/dist/prompts/contextDetect.d.ts.map +1 -0
- package/dist/prompts/contextDetect.js +122 -0
- package/dist/prompts/index.d.ts +5 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +13 -2
- package/dist/prompts/parts/index.d.ts +2 -0
- package/dist/prompts/parts/index.d.ts.map +1 -1
- package/dist/prompts/parts/index.js +5 -1
- package/dist/prompts/parts/priorityLadder.d.ts +7 -0
- package/dist/prompts/parts/priorityLadder.d.ts.map +1 -0
- package/dist/prompts/parts/priorityLadder.js +13 -0
- package/dist/prompts/parts/rootCauseGuardrail.d.ts +7 -0
- package/dist/prompts/parts/rootCauseGuardrail.d.ts.map +1 -0
- package/dist/prompts/parts/rootCauseGuardrail.js +13 -0
- package/dist/prompts/strata.d.ts.map +1 -1
- package/dist/prompts/strata.js +2 -0
- package/dist/prompts/templates/coding-philosophy.md +3 -0
- package/dist/prompts/templates/priority-ladder.md +13 -0
- package/dist/prompts/templates/root-cause-guardrail.md +14 -0
- package/dist/prompts/templates/tool-preferences.md +2 -0
- package/dist/prompts/types.d.ts +3 -0
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/runtime/intrinsics/task.d.ts.map +1 -1
- package/dist/runtime/intrinsics/task.js +11 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0BH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;IACvF,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA+JD;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,MAAM,CAAC,CA2HjB"}
|
|
@@ -195,6 +195,12 @@ async function handleInstructionsCommand(args) {
|
|
|
195
195
|
if (!hooksActive) {
|
|
196
196
|
hookOverride.hookDriven = false;
|
|
197
197
|
}
|
|
198
|
+
// Detect execution context (CI, trigger, branch, actor) and derive
|
|
199
|
+
// capability flags so the babysit skill can select context-appropriate
|
|
200
|
+
// library processes when dispatching (e.g. GitHub collaboration,
|
|
201
|
+
// scheduled reporting, local-dev relaxations).
|
|
202
|
+
const executionContext = (0, prompts_1.detectExecutionContext)();
|
|
203
|
+
const capabilityFlags = (0, prompts_1.deriveCapabilityFlags)(executionContext);
|
|
198
204
|
const ctx = factory({
|
|
199
205
|
interactive: args.interactive,
|
|
200
206
|
...libraryInfo,
|
|
@@ -218,6 +224,9 @@ async function handleInstructionsCommand(args) {
|
|
|
218
224
|
promptType: composer.promptType,
|
|
219
225
|
hookDriven: ctx.hookDriven,
|
|
220
226
|
hooksDetected: hooksActive,
|
|
227
|
+
executionContext,
|
|
228
|
+
capabilityFlags,
|
|
229
|
+
suggestedProcesses: (0, prompts_1.processPathsForCapabilities)(capabilityFlags),
|
|
221
230
|
content,
|
|
222
231
|
partsIncluded: composer.partsIncluded,
|
|
223
232
|
}, null, 2));
|
|
@@ -229,7 +238,27 @@ async function handleInstructionsCommand(args) {
|
|
|
229
238
|
// clarifies the JSON output. The text output is self-explanatory
|
|
230
239
|
// from the generated instructions.
|
|
231
240
|
}
|
|
232
|
-
|
|
241
|
+
const activeCapabilities = Object.entries(capabilityFlags)
|
|
242
|
+
.filter(([, v]) => v === true)
|
|
243
|
+
.map(([k]) => k);
|
|
244
|
+
const contextHeader = [
|
|
245
|
+
'## Execution Context',
|
|
246
|
+
'',
|
|
247
|
+
`- CI: \`${executionContext.ci}\``,
|
|
248
|
+
`- Trigger: \`${executionContext.trigger}\``,
|
|
249
|
+
executionContext.branch.ref ? `- Branch: \`${executionContext.branch.ref}\`` : undefined,
|
|
250
|
+
executionContext.repo ? `- Repo: \`${executionContext.repo.owner}/${executionContext.repo.name}\`` : undefined,
|
|
251
|
+
executionContext.actor ? `- Actor: \`${executionContext.actor.login}\`${executionContext.actor.isBot ? ' (bot)' : ''}` : undefined,
|
|
252
|
+
'',
|
|
253
|
+
`Active context capabilities: ${activeCapabilities.length > 0 ? activeCapabilities.map(c => `\`${c}\``).join(', ') : '_(none)_'}`,
|
|
254
|
+
'',
|
|
255
|
+
'When selecting library processes to dispatch, prefer those whose triggers match the active capabilities above.',
|
|
256
|
+
'',
|
|
257
|
+
'---',
|
|
258
|
+
'',
|
|
259
|
+
].filter((l) => l !== undefined).join('\n');
|
|
260
|
+
const processGuide = (0, prompts_1.renderCapabilityProcessGuide)(capabilityFlags);
|
|
261
|
+
console.log(contextHeader + processGuide + content);
|
|
233
262
|
}
|
|
234
263
|
return 0;
|
|
235
264
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,EAAE,QAAQ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|
* Override: set BABYSITTER_LOG_DIR to use a different path.
|
|
160
160
|
*/
|
|
161
161
|
function getGlobalLogDir() {
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const override = process.env.BABYSITTER_LOG_DIR?.trim();
|
|
163
|
+
if (override) {
|
|
164
|
+
if (!path.isAbsolute(override)) {
|
|
165
|
+
const rebased = path.join(os.homedir(), ".a5c", "logs");
|
|
166
|
+
// eslint-disable-next-line no-console
|
|
167
|
+
console.warn(`[babysitter] BABYSITTER_LOG_DIR must be an absolute path; got ${JSON.stringify(override)}. Falling back to ${rebased}. Set an absolute path to silence this warning.`);
|
|
168
|
+
return rebased;
|
|
169
|
+
}
|
|
170
|
+
return path.resolve(override);
|
|
164
171
|
}
|
|
165
172
|
const globalRoot = process.env.BABYSITTER_GLOBAL_STATE_DIR?.trim()
|
|
166
173
|
? path.resolve(process.env.BABYSITTER_GLOBAL_STATE_DIR)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GAP-SEC: Authority Chain system.
|
|
3
|
+
*
|
|
4
|
+
* Models delegation chains from human principals through agent principals,
|
|
5
|
+
* with monotonically narrowing scope at each hop.
|
|
6
|
+
*/
|
|
7
|
+
import type { MandateScope } from './mandate';
|
|
8
|
+
/** A principal (human or agent) in the authority chain. */
|
|
9
|
+
export interface AuthorityPrincipal {
|
|
10
|
+
kind: 'human' | 'agent';
|
|
11
|
+
id: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
}
|
|
14
|
+
/** A single grant of authority from one principal to another. */
|
|
15
|
+
export interface AuthorityGrant {
|
|
16
|
+
from: AuthorityPrincipal;
|
|
17
|
+
to: AuthorityPrincipal;
|
|
18
|
+
scope: MandateScope;
|
|
19
|
+
grantedAt: string;
|
|
20
|
+
revokedAt?: string;
|
|
21
|
+
expiresAt?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A link in the authority chain (wrapping a grant). */
|
|
24
|
+
export interface AuthorityChainLink {
|
|
25
|
+
grant: AuthorityGrant;
|
|
26
|
+
index: number;
|
|
27
|
+
}
|
|
28
|
+
/** A full authority chain from root to leaf. */
|
|
29
|
+
export interface AuthorityChain {
|
|
30
|
+
grants: AuthorityGrant[];
|
|
31
|
+
rootPrincipal: AuthorityPrincipal;
|
|
32
|
+
effectiveScope: MandateScope;
|
|
33
|
+
}
|
|
34
|
+
/** Result of chain validation. */
|
|
35
|
+
export interface AuthorityChainValidationResult {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
reason?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Result of tracing authority to a human root. */
|
|
40
|
+
export interface AuthorityTrace {
|
|
41
|
+
humanPrincipal: AuthorityPrincipal;
|
|
42
|
+
hopCount: number;
|
|
43
|
+
principalPath: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an authority chain from an ordered list of grants.
|
|
47
|
+
* Computes the effective scope as the intersection of all grant scopes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createAuthorityChain(grants: AuthorityGrant[]): AuthorityChain;
|
|
50
|
+
/**
|
|
51
|
+
* Validate an authority chain. Checks:
|
|
52
|
+
* 1. Root must be a human principal.
|
|
53
|
+
* 2. No revoked links.
|
|
54
|
+
* 3. No expired links.
|
|
55
|
+
* 4. Scopes monotonically narrow (no expansion).
|
|
56
|
+
*/
|
|
57
|
+
export declare function validateAuthorityChain(chain: AuthorityChain): AuthorityChainValidationResult;
|
|
58
|
+
/**
|
|
59
|
+
* Attenuate (intersect) two scopes. The result is never wider than either input.
|
|
60
|
+
* Pure function.
|
|
61
|
+
*/
|
|
62
|
+
export declare function attenuateScope(parent: MandateScope, child: MandateScope): MandateScope;
|
|
63
|
+
/**
|
|
64
|
+
* Trace authority back to the human root, returning the human principal,
|
|
65
|
+
* hop count, and full principal path.
|
|
66
|
+
*/
|
|
67
|
+
export declare function traceAuthorityToHuman(chain: AuthorityChain): AuthorityTrace;
|
|
68
|
+
//# sourceMappingURL=authority.d.ts.map
|
|
@@ -0,0 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2BD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,YAAY,CAqBtF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CAW3E"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GAP-SEC: Authority Chain system.
|
|
4
|
+
*
|
|
5
|
+
* Models delegation chains from human principals through agent principals,
|
|
6
|
+
* with monotonically narrowing scope at each hop.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createAuthorityChain = createAuthorityChain;
|
|
10
|
+
exports.validateAuthorityChain = validateAuthorityChain;
|
|
11
|
+
exports.attenuateScope = attenuateScope;
|
|
12
|
+
exports.traceAuthorityToHuman = traceAuthorityToHuman;
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Core functions
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* Create an authority chain from an ordered list of grants.
|
|
18
|
+
* Computes the effective scope as the intersection of all grant scopes.
|
|
19
|
+
*/
|
|
20
|
+
function createAuthorityChain(grants) {
|
|
21
|
+
if (grants.length === 0) {
|
|
22
|
+
throw new Error('Authority chain requires at least one grant');
|
|
23
|
+
}
|
|
24
|
+
const rootPrincipal = grants[0].from;
|
|
25
|
+
// Compute effective scope as intersection of all grant scopes
|
|
26
|
+
let effectiveScope = { ...grants[0].scope, allowedEffectKinds: [...grants[0].scope.allowedEffectKinds] };
|
|
27
|
+
for (let i = 1; i < grants.length; i++) {
|
|
28
|
+
effectiveScope = attenuateScope(effectiveScope, grants[i].scope);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
grants: [...grants],
|
|
32
|
+
rootPrincipal,
|
|
33
|
+
effectiveScope,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate an authority chain. Checks:
|
|
38
|
+
* 1. Root must be a human principal.
|
|
39
|
+
* 2. No revoked links.
|
|
40
|
+
* 3. No expired links.
|
|
41
|
+
* 4. Scopes monotonically narrow (no expansion).
|
|
42
|
+
*/
|
|
43
|
+
function validateAuthorityChain(chain) {
|
|
44
|
+
// 1. Root must be human
|
|
45
|
+
if (chain.rootPrincipal.kind !== 'human') {
|
|
46
|
+
return { valid: false, reason: 'Authority chain must be rooted in a human principal' };
|
|
47
|
+
}
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
for (let i = 0; i < chain.grants.length; i++) {
|
|
50
|
+
const grant = chain.grants[i];
|
|
51
|
+
// 2. No revoked links
|
|
52
|
+
if (grant.revokedAt) {
|
|
53
|
+
return { valid: false, reason: `Grant at index ${i} has been revoked` };
|
|
54
|
+
}
|
|
55
|
+
// 3. No expired links
|
|
56
|
+
if (grant.expiresAt && new Date(grant.expiresAt).getTime() <= now) {
|
|
57
|
+
return { valid: false, reason: `Grant at index ${i} has expired` };
|
|
58
|
+
}
|
|
59
|
+
// 4. Scope must not expand beyond previous grant
|
|
60
|
+
if (i > 0) {
|
|
61
|
+
const parentScope = chain.grants[i - 1].scope;
|
|
62
|
+
const childScope = grant.scope;
|
|
63
|
+
if (!isScopeSubsetOrEqual(parentScope, childScope)) {
|
|
64
|
+
return { valid: false, reason: `Grant at index ${i} expands scope beyond parent` };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { valid: true };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if childScope is a subset of or equal to parentScope.
|
|
72
|
+
*/
|
|
73
|
+
function isScopeSubsetOrEqual(parent, child) {
|
|
74
|
+
// Check effect kinds
|
|
75
|
+
const parentWildcard = parent.allowedEffectKinds.length === 1 && parent.allowedEffectKinds[0] === '*';
|
|
76
|
+
if (!parentWildcard) {
|
|
77
|
+
for (const kind of child.allowedEffectKinds) {
|
|
78
|
+
if (kind === '*') {
|
|
79
|
+
return false; // wildcard child cannot escape non-wildcard parent
|
|
80
|
+
}
|
|
81
|
+
if (!parent.allowedEffectKinds.includes(kind)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Check numeric limits
|
|
87
|
+
if (child.maxIterations > parent.maxIterations)
|
|
88
|
+
return false;
|
|
89
|
+
if (child.maxConcurrentTasks > parent.maxConcurrentTasks)
|
|
90
|
+
return false;
|
|
91
|
+
if (child.timeoutMs > parent.timeoutMs)
|
|
92
|
+
return false;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Attenuate (intersect) two scopes. The result is never wider than either input.
|
|
97
|
+
* Pure function.
|
|
98
|
+
*/
|
|
99
|
+
function attenuateScope(parent, child) {
|
|
100
|
+
const parentWildcard = parent.allowedEffectKinds.length === 1 && parent.allowedEffectKinds[0] === '*';
|
|
101
|
+
const childWildcard = child.allowedEffectKinds.length === 1 && child.allowedEffectKinds[0] === '*';
|
|
102
|
+
let allowedEffectKinds;
|
|
103
|
+
if (parentWildcard && childWildcard) {
|
|
104
|
+
allowedEffectKinds = ['*'];
|
|
105
|
+
}
|
|
106
|
+
else if (parentWildcard) {
|
|
107
|
+
allowedEffectKinds = [...child.allowedEffectKinds];
|
|
108
|
+
}
|
|
109
|
+
else if (childWildcard) {
|
|
110
|
+
allowedEffectKinds = [...parent.allowedEffectKinds];
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
allowedEffectKinds = parent.allowedEffectKinds.filter(k => child.allowedEffectKinds.includes(k));
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
allowedEffectKinds,
|
|
117
|
+
maxIterations: Math.min(parent.maxIterations, child.maxIterations),
|
|
118
|
+
maxConcurrentTasks: Math.min(parent.maxConcurrentTasks, child.maxConcurrentTasks),
|
|
119
|
+
timeoutMs: Math.min(parent.timeoutMs, child.timeoutMs),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Trace authority back to the human root, returning the human principal,
|
|
124
|
+
* hop count, and full principal path.
|
|
125
|
+
*/
|
|
126
|
+
function traceAuthorityToHuman(chain) {
|
|
127
|
+
const principalPath = [chain.grants[0].from.id];
|
|
128
|
+
for (const grant of chain.grants) {
|
|
129
|
+
principalPath.push(grant.to.id);
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
humanPrincipal: chain.rootPrincipal,
|
|
133
|
+
hopCount: chain.grants.length,
|
|
134
|
+
principalPath,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GAP-SEC: Deterministic Policy Categories.
|
|
3
|
+
*
|
|
4
|
+
* Categorizes policy rules into A/B/C/D tiers with distinct enforcement
|
|
5
|
+
* behaviors and wraps the base policy engine with category-aware evaluation.
|
|
6
|
+
*/
|
|
7
|
+
import type { PolicyRule, PolicyEvaluationContext, PolicyDecision } from './types';
|
|
8
|
+
/** Policy category identifiers. */
|
|
9
|
+
export type PolicyCategory = 'A' | 'B' | 'C' | 'D';
|
|
10
|
+
/** A PolicyRule annotated with a category. */
|
|
11
|
+
export interface CategorizedPolicyRule extends PolicyRule {
|
|
12
|
+
category?: PolicyCategory;
|
|
13
|
+
}
|
|
14
|
+
/** Enforcement behavior per category. */
|
|
15
|
+
export interface CategoryEnforcementBehavior {
|
|
16
|
+
category: PolicyCategory;
|
|
17
|
+
description: string;
|
|
18
|
+
immutable: boolean;
|
|
19
|
+
requiresClassification: boolean;
|
|
20
|
+
isFallback: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Extended decision with category metadata. */
|
|
23
|
+
export interface CategorizedPolicyDecision extends PolicyDecision {
|
|
24
|
+
requiresClassification?: boolean;
|
|
25
|
+
usedFallback?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Categorized engine interface. */
|
|
28
|
+
export interface CategorizedPolicyEngine {
|
|
29
|
+
readonly rules: readonly CategorizedPolicyRule[];
|
|
30
|
+
evaluate(context: PolicyEvaluationContext): CategorizedPolicyDecision;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Wrap a plain PolicyRule with a category annotation.
|
|
34
|
+
*/
|
|
35
|
+
export declare function categorizePolicyRule(rule: PolicyRule, category: PolicyCategory): CategorizedPolicyRule;
|
|
36
|
+
/**
|
|
37
|
+
* Infer a category for a rule that lacks one.
|
|
38
|
+
*
|
|
39
|
+
* Heuristic:
|
|
40
|
+
* - rate-limit + deny -> A (critical)
|
|
41
|
+
* - permission + deny -> C (needs classification)
|
|
42
|
+
* - trust-level -> D (fallback)
|
|
43
|
+
* - everything else -> B (advisory)
|
|
44
|
+
*/
|
|
45
|
+
export declare function inferPolicyCategory(rule: PolicyRule): PolicyCategory;
|
|
46
|
+
/**
|
|
47
|
+
* Create a categorized policy engine that evaluates rules with
|
|
48
|
+
* category-aware precedence:
|
|
49
|
+
*
|
|
50
|
+
* 1. Category A (immutable) - evaluated first, cannot be overridden
|
|
51
|
+
* 2. Category B (advisory) - warnings / normal evaluation
|
|
52
|
+
* 3. Category C (classification-required) - denials flagged
|
|
53
|
+
* 4. Category D (fallback) - posture-based fallback
|
|
54
|
+
*
|
|
55
|
+
* Accepts CategorizedPolicyRule[] (rules without a category are auto-inferred).
|
|
56
|
+
*/
|
|
57
|
+
export declare function createCategorizedEngine(rules: CategorizedPolicyRule[]): CategorizedPolicyEngine;
|
|
58
|
+
//# sourceMappingURL=categories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.d.ts","sourceRoot":"","sources":["../../src/governance/categories.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMnF,mCAAmC;AACnC,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEnD,8CAA8C;AAC9C,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED,yCAAyC;AACzC,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,cAAc,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,sBAAsB,EAAE,OAAO,CAAC;IAChC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,gDAAgD;AAChD,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,uBAAuB,GAAG,yBAAyB,CAAC;CACvE;AAiBD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,GAAG,qBAAqB,CAEtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAKpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,uBAAuB,CAuE/F"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GAP-SEC: Deterministic Policy Categories.
|
|
4
|
+
*
|
|
5
|
+
* Categorizes policy rules into A/B/C/D tiers with distinct enforcement
|
|
6
|
+
* behaviors and wraps the base policy engine with category-aware evaluation.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.categorizePolicyRule = categorizePolicyRule;
|
|
10
|
+
exports.inferPolicyCategory = inferPolicyCategory;
|
|
11
|
+
exports.createCategorizedEngine = createCategorizedEngine;
|
|
12
|
+
const engine_1 = require("./engine");
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Category behaviours
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
const _CATEGORY_BEHAVIORS = {
|
|
17
|
+
A: { category: 'A', description: 'Immutable critical rules', immutable: true, requiresClassification: false, isFallback: false },
|
|
18
|
+
B: { category: 'B', description: 'Advisory rules', immutable: false, requiresClassification: false, isFallback: false },
|
|
19
|
+
C: { category: 'C', description: 'Classification-required rules', immutable: false, requiresClassification: true, isFallback: false },
|
|
20
|
+
D: { category: 'D', description: 'Fallback posture-based rules', immutable: false, requiresClassification: false, isFallback: true },
|
|
21
|
+
};
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Core functions
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
/**
|
|
26
|
+
* Wrap a plain PolicyRule with a category annotation.
|
|
27
|
+
*/
|
|
28
|
+
function categorizePolicyRule(rule, category) {
|
|
29
|
+
return { ...rule, category };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Infer a category for a rule that lacks one.
|
|
33
|
+
*
|
|
34
|
+
* Heuristic:
|
|
35
|
+
* - rate-limit + deny -> A (critical)
|
|
36
|
+
* - permission + deny -> C (needs classification)
|
|
37
|
+
* - trust-level -> D (fallback)
|
|
38
|
+
* - everything else -> B (advisory)
|
|
39
|
+
*/
|
|
40
|
+
function inferPolicyCategory(rule) {
|
|
41
|
+
if (rule.kind === 'rate-limit' && rule.action === 'deny')
|
|
42
|
+
return 'A';
|
|
43
|
+
if (rule.kind === 'permission' && rule.action === 'deny')
|
|
44
|
+
return 'C';
|
|
45
|
+
if (rule.kind === 'trust-level')
|
|
46
|
+
return 'D';
|
|
47
|
+
return 'B';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a categorized policy engine that evaluates rules with
|
|
51
|
+
* category-aware precedence:
|
|
52
|
+
*
|
|
53
|
+
* 1. Category A (immutable) - evaluated first, cannot be overridden
|
|
54
|
+
* 2. Category B (advisory) - warnings / normal evaluation
|
|
55
|
+
* 3. Category C (classification-required) - denials flagged
|
|
56
|
+
* 4. Category D (fallback) - posture-based fallback
|
|
57
|
+
*
|
|
58
|
+
* Accepts CategorizedPolicyRule[] (rules without a category are auto-inferred).
|
|
59
|
+
*/
|
|
60
|
+
function createCategorizedEngine(rules) {
|
|
61
|
+
// Ensure every rule has a category
|
|
62
|
+
const categorized = rules.map(r => r.category ? r : { ...r, category: inferPolicyCategory(r) });
|
|
63
|
+
// Partition by category
|
|
64
|
+
const byCategory = { A: [], B: [], C: [], D: [] };
|
|
65
|
+
for (const rule of categorized) {
|
|
66
|
+
byCategory[rule.category].push(rule);
|
|
67
|
+
}
|
|
68
|
+
// Build per-category engines
|
|
69
|
+
const engineA = (0, engine_1.createPolicyEngine)(byCategory.A);
|
|
70
|
+
const engineB = (0, engine_1.createPolicyEngine)(byCategory.B);
|
|
71
|
+
const engineC = (0, engine_1.createPolicyEngine)(byCategory.C);
|
|
72
|
+
const engineD = (0, engine_1.createPolicyEngine)(byCategory.D);
|
|
73
|
+
return {
|
|
74
|
+
rules: Object.freeze([...categorized]),
|
|
75
|
+
evaluate(context) {
|
|
76
|
+
const allWarnings = [];
|
|
77
|
+
// 1. Category A - immutable, first match wins
|
|
78
|
+
if (byCategory.A.length > 0) {
|
|
79
|
+
const decisionA = engineA.evaluate(context);
|
|
80
|
+
allWarnings.push(...decisionA.warnings);
|
|
81
|
+
if (!decisionA.allowed) {
|
|
82
|
+
return { ...decisionA, warnings: allWarnings };
|
|
83
|
+
}
|
|
84
|
+
// If A explicitly allows, still continue to collect warnings from B
|
|
85
|
+
// but A deny is final.
|
|
86
|
+
}
|
|
87
|
+
// 2. Category B - advisory (collect warnings)
|
|
88
|
+
if (byCategory.B.length > 0) {
|
|
89
|
+
const decisionB = engineB.evaluate(context);
|
|
90
|
+
allWarnings.push(...decisionB.warnings);
|
|
91
|
+
// B deny/allow also applies if no A deny
|
|
92
|
+
if (!decisionB.allowed) {
|
|
93
|
+
return { ...decisionB, warnings: allWarnings };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// 3. Category C - requires classification
|
|
97
|
+
if (byCategory.C.length > 0) {
|
|
98
|
+
const decisionC = engineC.evaluate(context);
|
|
99
|
+
allWarnings.push(...decisionC.warnings);
|
|
100
|
+
if (!decisionC.allowed) {
|
|
101
|
+
return { ...decisionC, warnings: allWarnings, requiresClassification: true };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 4. Category D - fallback
|
|
105
|
+
if (byCategory.D.length > 0) {
|
|
106
|
+
const decisionD = engineD.evaluate(context);
|
|
107
|
+
allWarnings.push(...decisionD.warnings);
|
|
108
|
+
if (decisionD.rule) {
|
|
109
|
+
return { ...decisionD, warnings: allWarnings, usedFallback: true };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Default allow
|
|
113
|
+
return {
|
|
114
|
+
allowed: true,
|
|
115
|
+
reason: 'Allowed by default policy',
|
|
116
|
+
warnings: allWarnings,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -9,4 +9,12 @@ export { maxIterationsPolicy, taskKindPolicy, rateLimitPolicy } from './builtins
|
|
|
9
9
|
export { logPolicyDecision, readPolicyDecisionLog } from './logging';
|
|
10
10
|
export { breakpointRulesToPolicies } from './bridge';
|
|
11
11
|
export { buildDecisionTrailEntry, summarizeDecisionTrail, type DecisionTrailEntry, type DecisionTrailOptions, type DecisionTrailSummary, type PolicyEvalRecord, } from './decisionTrail';
|
|
12
|
+
export { createMandate, activateMandate, revokeMandate, deriveMandate, validateMandateForContext, mandateToPolicy, type ExecutionMandate, type MandateScope, type MandateLifecycle, type MandateProvenance, type MandateValidationResult, } from './mandate';
|
|
13
|
+
export { createAuthorityChain, validateAuthorityChain, attenuateScope, traceAuthorityToHuman, type AuthorityPrincipal, type AuthorityGrant, type AuthorityChain, type AuthorityChainLink, type AuthorityTrace, type AuthorityChainValidationResult, } from './authority';
|
|
14
|
+
export { categorizePolicyRule, createCategorizedEngine, inferPolicyCategory, type PolicyCategory, type CategorizedPolicyRule, type CategoryEnforcementBehavior, type CategorizedPolicyDecision, type CategorizedPolicyEngine, } from './categories';
|
|
15
|
+
export { postureToPolicyRules, allPosturesToPolicies, } from './postureBridge';
|
|
16
|
+
export { evaluateSandboxAccess, matchesPattern, composeSandboxPolicies, attenuateSandboxPolicy, type SandboxOperationKind, type SandboxRule, type SandboxPolicy, type SandboxDecision, type SandboxOperation, } from './sandboxPolicy';
|
|
17
|
+
export { sandboxDecisionToInteraction, buildSandboxEvent, inheritSandboxPolicy, type SandboxEvent, } from './sandboxBridge';
|
|
18
|
+
export { createPermissionEvent, aggregateChainEvents, filterEvents, type PermissionEvent, type PermissionEventSource, type CreatePermissionEventOptions, type FilterCriteria, } from './permissionEvents';
|
|
19
|
+
export { formatPermissionForTui, formatPermissionForJsonStream, formatPermissionForCli, createPropagationConfig, shouldPropagate, type PropagationTarget, type PropagationConfig, } from './permissionPropagation';
|
|
12
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/governance/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,Y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,EACtB,cAAc,EACd,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,8BAA8B,GACpC,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC"}
|
package/dist/governance/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralized policy engine for evaluating security rules at effect dispatch.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.summarizeDecisionTrail = exports.buildDecisionTrailEntry = exports.breakpointRulesToPolicies = exports.readPolicyDecisionLog = exports.logPolicyDecision = exports.rateLimitPolicy = exports.taskKindPolicy = exports.maxIterationsPolicy = exports.matchCondition = exports.createPolicyEngine = exports.isStatefulRule = void 0;
|
|
7
|
+
exports.shouldPropagate = exports.createPropagationConfig = exports.formatPermissionForCli = exports.formatPermissionForJsonStream = exports.formatPermissionForTui = exports.filterEvents = exports.aggregateChainEvents = exports.createPermissionEvent = exports.inheritSandboxPolicy = exports.buildSandboxEvent = exports.sandboxDecisionToInteraction = exports.attenuateSandboxPolicy = exports.composeSandboxPolicies = exports.matchesPattern = exports.evaluateSandboxAccess = exports.allPosturesToPolicies = exports.postureToPolicyRules = exports.inferPolicyCategory = exports.createCategorizedEngine = exports.categorizePolicyRule = exports.traceAuthorityToHuman = exports.attenuateScope = exports.validateAuthorityChain = exports.createAuthorityChain = exports.mandateToPolicy = exports.validateMandateForContext = exports.deriveMandate = exports.revokeMandate = exports.activateMandate = exports.createMandate = exports.summarizeDecisionTrail = exports.buildDecisionTrailEntry = exports.breakpointRulesToPolicies = exports.readPolicyDecisionLog = exports.logPolicyDecision = exports.rateLimitPolicy = exports.taskKindPolicy = exports.maxIterationsPolicy = exports.matchCondition = exports.createPolicyEngine = exports.isStatefulRule = void 0;
|
|
8
8
|
var types_1 = require("./types");
|
|
9
9
|
Object.defineProperty(exports, "isStatefulRule", { enumerable: true, get: function () { return types_1.isStatefulRule; } });
|
|
10
10
|
// Engine
|
|
@@ -27,3 +27,49 @@ Object.defineProperty(exports, "breakpointRulesToPolicies", { enumerable: true,
|
|
|
27
27
|
var decisionTrail_1 = require("./decisionTrail");
|
|
28
28
|
Object.defineProperty(exports, "buildDecisionTrailEntry", { enumerable: true, get: function () { return decisionTrail_1.buildDecisionTrailEntry; } });
|
|
29
29
|
Object.defineProperty(exports, "summarizeDecisionTrail", { enumerable: true, get: function () { return decisionTrail_1.summarizeDecisionTrail; } });
|
|
30
|
+
// Mandate system
|
|
31
|
+
var mandate_1 = require("./mandate");
|
|
32
|
+
Object.defineProperty(exports, "createMandate", { enumerable: true, get: function () { return mandate_1.createMandate; } });
|
|
33
|
+
Object.defineProperty(exports, "activateMandate", { enumerable: true, get: function () { return mandate_1.activateMandate; } });
|
|
34
|
+
Object.defineProperty(exports, "revokeMandate", { enumerable: true, get: function () { return mandate_1.revokeMandate; } });
|
|
35
|
+
Object.defineProperty(exports, "deriveMandate", { enumerable: true, get: function () { return mandate_1.deriveMandate; } });
|
|
36
|
+
Object.defineProperty(exports, "validateMandateForContext", { enumerable: true, get: function () { return mandate_1.validateMandateForContext; } });
|
|
37
|
+
Object.defineProperty(exports, "mandateToPolicy", { enumerable: true, get: function () { return mandate_1.mandateToPolicy; } });
|
|
38
|
+
// Authority chain
|
|
39
|
+
var authority_1 = require("./authority");
|
|
40
|
+
Object.defineProperty(exports, "createAuthorityChain", { enumerable: true, get: function () { return authority_1.createAuthorityChain; } });
|
|
41
|
+
Object.defineProperty(exports, "validateAuthorityChain", { enumerable: true, get: function () { return authority_1.validateAuthorityChain; } });
|
|
42
|
+
Object.defineProperty(exports, "attenuateScope", { enumerable: true, get: function () { return authority_1.attenuateScope; } });
|
|
43
|
+
Object.defineProperty(exports, "traceAuthorityToHuman", { enumerable: true, get: function () { return authority_1.traceAuthorityToHuman; } });
|
|
44
|
+
// Categorized policy engine
|
|
45
|
+
var categories_1 = require("./categories");
|
|
46
|
+
Object.defineProperty(exports, "categorizePolicyRule", { enumerable: true, get: function () { return categories_1.categorizePolicyRule; } });
|
|
47
|
+
Object.defineProperty(exports, "createCategorizedEngine", { enumerable: true, get: function () { return categories_1.createCategorizedEngine; } });
|
|
48
|
+
Object.defineProperty(exports, "inferPolicyCategory", { enumerable: true, get: function () { return categories_1.inferPolicyCategory; } });
|
|
49
|
+
// Posture-to-policy bridge
|
|
50
|
+
var postureBridge_1 = require("./postureBridge");
|
|
51
|
+
Object.defineProperty(exports, "postureToPolicyRules", { enumerable: true, get: function () { return postureBridge_1.postureToPolicyRules; } });
|
|
52
|
+
Object.defineProperty(exports, "allPosturesToPolicies", { enumerable: true, get: function () { return postureBridge_1.allPosturesToPolicies; } });
|
|
53
|
+
// Sandbox policy (GAP-SEC-002)
|
|
54
|
+
var sandboxPolicy_1 = require("./sandboxPolicy");
|
|
55
|
+
Object.defineProperty(exports, "evaluateSandboxAccess", { enumerable: true, get: function () { return sandboxPolicy_1.evaluateSandboxAccess; } });
|
|
56
|
+
Object.defineProperty(exports, "matchesPattern", { enumerable: true, get: function () { return sandboxPolicy_1.matchesPattern; } });
|
|
57
|
+
Object.defineProperty(exports, "composeSandboxPolicies", { enumerable: true, get: function () { return sandboxPolicy_1.composeSandboxPolicies; } });
|
|
58
|
+
Object.defineProperty(exports, "attenuateSandboxPolicy", { enumerable: true, get: function () { return sandboxPolicy_1.attenuateSandboxPolicy; } });
|
|
59
|
+
// Sandbox bridge (GAP-SEC-002)
|
|
60
|
+
var sandboxBridge_1 = require("./sandboxBridge");
|
|
61
|
+
Object.defineProperty(exports, "sandboxDecisionToInteraction", { enumerable: true, get: function () { return sandboxBridge_1.sandboxDecisionToInteraction; } });
|
|
62
|
+
Object.defineProperty(exports, "buildSandboxEvent", { enumerable: true, get: function () { return sandboxBridge_1.buildSandboxEvent; } });
|
|
63
|
+
Object.defineProperty(exports, "inheritSandboxPolicy", { enumerable: true, get: function () { return sandboxBridge_1.inheritSandboxPolicy; } });
|
|
64
|
+
// Permission events
|
|
65
|
+
var permissionEvents_1 = require("./permissionEvents");
|
|
66
|
+
Object.defineProperty(exports, "createPermissionEvent", { enumerable: true, get: function () { return permissionEvents_1.createPermissionEvent; } });
|
|
67
|
+
Object.defineProperty(exports, "aggregateChainEvents", { enumerable: true, get: function () { return permissionEvents_1.aggregateChainEvents; } });
|
|
68
|
+
Object.defineProperty(exports, "filterEvents", { enumerable: true, get: function () { return permissionEvents_1.filterEvents; } });
|
|
69
|
+
// Permission propagation
|
|
70
|
+
var permissionPropagation_1 = require("./permissionPropagation");
|
|
71
|
+
Object.defineProperty(exports, "formatPermissionForTui", { enumerable: true, get: function () { return permissionPropagation_1.formatPermissionForTui; } });
|
|
72
|
+
Object.defineProperty(exports, "formatPermissionForJsonStream", { enumerable: true, get: function () { return permissionPropagation_1.formatPermissionForJsonStream; } });
|
|
73
|
+
Object.defineProperty(exports, "formatPermissionForCli", { enumerable: true, get: function () { return permissionPropagation_1.formatPermissionForCli; } });
|
|
74
|
+
Object.defineProperty(exports, "createPropagationConfig", { enumerable: true, get: function () { return permissionPropagation_1.createPropagationConfig; } });
|
|
75
|
+
Object.defineProperty(exports, "shouldPropagate", { enumerable: true, get: function () { return permissionPropagation_1.shouldPropagate; } });
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GAP-SEC: Execution Mandate system.
|
|
3
|
+
*
|
|
4
|
+
* Mandates are scoped, lifecycle-managed authority grants that can be
|
|
5
|
+
* derived (attenuated) and converted to PolicyRule[] for engine evaluation.
|
|
6
|
+
*/
|
|
7
|
+
import type { PolicyRule, PolicyEvaluationContext } from './types';
|
|
8
|
+
/** The set of permissions / limits a mandate grants. */
|
|
9
|
+
export interface MandateScope {
|
|
10
|
+
/** Effect kinds allowed. Array of strings, or ['*'] for wildcard. */
|
|
11
|
+
allowedEffectKinds: string[];
|
|
12
|
+
/** Maximum iterations permitted. */
|
|
13
|
+
maxIterations: number;
|
|
14
|
+
/** Maximum concurrent tasks permitted. */
|
|
15
|
+
maxConcurrentTasks: number;
|
|
16
|
+
/** Timeout in milliseconds. */
|
|
17
|
+
timeoutMs: number;
|
|
18
|
+
}
|
|
19
|
+
/** Lifecycle states of a mandate. */
|
|
20
|
+
export type MandateLifecycle = 'created' | 'active' | 'revoked';
|
|
21
|
+
/** Where this mandate came from. */
|
|
22
|
+
export interface MandateProvenance {
|
|
23
|
+
/** The root mandate ID (self-referential for root mandates). */
|
|
24
|
+
rootMandateId: string;
|
|
25
|
+
/** Chain of mandate IDs from root to parent. */
|
|
26
|
+
derivationChain: string[];
|
|
27
|
+
}
|
|
28
|
+
/** An execution mandate. */
|
|
29
|
+
export interface ExecutionMandate {
|
|
30
|
+
mandateId: string;
|
|
31
|
+
scope: MandateScope;
|
|
32
|
+
grantedBy: string;
|
|
33
|
+
lifecycle: MandateLifecycle;
|
|
34
|
+
provenance: MandateProvenance;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
activatedAt?: string;
|
|
37
|
+
/** High-resolution activation mark (performance.now()) for precise expiry checks. */
|
|
38
|
+
activatedMark?: number;
|
|
39
|
+
revokedAt?: string;
|
|
40
|
+
revokedBy?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CreateMandateOptions {
|
|
43
|
+
scope: MandateScope;
|
|
44
|
+
grantedBy: string;
|
|
45
|
+
}
|
|
46
|
+
export interface RevokeMandateOptions {
|
|
47
|
+
revokedBy: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
}
|
|
50
|
+
export interface DeriveMandateOptions {
|
|
51
|
+
scope: MandateScope;
|
|
52
|
+
grantedBy: string;
|
|
53
|
+
}
|
|
54
|
+
export interface MandateValidationResult {
|
|
55
|
+
valid: boolean;
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a new mandate in the 'created' lifecycle state.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createMandate(options: CreateMandateOptions): ExecutionMandate;
|
|
62
|
+
/**
|
|
63
|
+
* Transition a mandate from 'created' to 'active'.
|
|
64
|
+
*/
|
|
65
|
+
export declare function activateMandate(mandate: ExecutionMandate): ExecutionMandate;
|
|
66
|
+
/**
|
|
67
|
+
* Revoke a mandate. Only active mandates can be revoked.
|
|
68
|
+
*/
|
|
69
|
+
export declare function revokeMandate(mandate: ExecutionMandate, options: RevokeMandateOptions): ExecutionMandate;
|
|
70
|
+
/**
|
|
71
|
+
* Derive a child mandate from an active parent. The child scope must be
|
|
72
|
+
* equal to or narrower than the parent scope (intersection semantics).
|
|
73
|
+
*/
|
|
74
|
+
export declare function deriveMandate(parent: ExecutionMandate, options: DeriveMandateOptions): ExecutionMandate;
|
|
75
|
+
/**
|
|
76
|
+
* Validate whether a mandate permits the given evaluation context.
|
|
77
|
+
*/
|
|
78
|
+
export declare function validateMandateForContext(mandate: ExecutionMandate, ctx: PolicyEvaluationContext): MandateValidationResult;
|
|
79
|
+
/**
|
|
80
|
+
* Convert a mandate's scope into PolicyRule[] for governance engine evaluation.
|
|
81
|
+
*/
|
|
82
|
+
export declare function mandateToPolicy(mandate: ExecutionMandate): PolicyRule[];
|
|
83
|
+
//# sourceMappingURL=mandate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate.d.ts","sourceRoot":"","sources":["../../src/governance/mandate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAMnE,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhE,oCAAoC;AACpC,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,4BAA4B;AAC5B,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC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