@decionis/agent-safe-pipeline 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/Index.d.ts +12 -0
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +12 -0
- package/dist/Index.js.map +1 -1
- package/dist/decision/DecionisGate.d.ts +6 -1
- package/dist/decision/DecionisGate.d.ts.map +1 -1
- package/dist/decision/DecionisGate.js +61 -11
- package/dist/decision/DecionisGate.js.map +1 -1
- package/dist/decision/DecisionAuthority.d.ts +16 -0
- package/dist/decision/DecisionAuthority.d.ts.map +1 -1
- package/dist/decision/DecisionAuthority.js.map +1 -1
- package/dist/execution/AuthorizationVerifier.d.ts +33 -4
- package/dist/execution/AuthorizationVerifier.d.ts.map +1 -1
- package/dist/execution/AuthorizationVerifier.js +74 -10
- package/dist/execution/AuthorizationVerifier.js.map +1 -1
- package/dist/execution/EffectAdapter.d.ts +117 -0
- package/dist/execution/EffectAdapter.d.ts.map +1 -0
- package/dist/execution/EffectAdapter.js +22 -0
- package/dist/execution/EffectAdapter.js.map +1 -0
- package/dist/execution/ExecutionDeadline.d.ts +35 -0
- package/dist/execution/ExecutionDeadline.d.ts.map +1 -0
- package/dist/execution/ExecutionDeadline.js +52 -0
- package/dist/execution/ExecutionDeadline.js.map +1 -0
- package/dist/execution/ExecutionJournal.d.ts +148 -0
- package/dist/execution/ExecutionJournal.d.ts.map +1 -0
- package/dist/execution/ExecutionJournal.js +157 -0
- package/dist/execution/ExecutionJournal.js.map +1 -0
- package/dist/execution/ExecutionOutcome.d.ts +186 -0
- package/dist/execution/ExecutionOutcome.d.ts.map +1 -0
- package/dist/execution/ExecutionOutcome.js +2 -0
- package/dist/execution/ExecutionOutcome.js.map +1 -0
- package/dist/execution/ExecutionPosture.d.ts +50 -0
- package/dist/execution/ExecutionPosture.d.ts.map +1 -0
- package/dist/execution/ExecutionPosture.js +20 -0
- package/dist/execution/ExecutionPosture.js.map +1 -0
- package/dist/execution/ExecutorEvidence.d.ts +64 -0
- package/dist/execution/ExecutorEvidence.d.ts.map +1 -0
- package/dist/execution/ExecutorEvidence.js +14 -0
- package/dist/execution/ExecutorEvidence.js.map +1 -0
- package/dist/execution/GovernedExecutionRunner.d.ts +309 -0
- package/dist/execution/GovernedExecutionRunner.d.ts.map +1 -0
- package/dist/execution/GovernedExecutionRunner.js +1341 -0
- package/dist/execution/GovernedExecutionRunner.js.map +1 -0
- package/dist/execution/NativeExecutor.d.ts +220 -0
- package/dist/execution/NativeExecutor.d.ts.map +1 -0
- package/dist/execution/NativeExecutor.js +22 -0
- package/dist/execution/NativeExecutor.js.map +1 -0
- package/dist/execution/NativeExecutorSchema.d.ts +387 -0
- package/dist/execution/NativeExecutorSchema.d.ts.map +1 -0
- package/dist/execution/NativeExecutorSchema.js +261 -0
- package/dist/execution/NativeExecutorSchema.js.map +1 -0
- package/dist/execution/PostgresExecutionJournal.d.ts +54 -0
- package/dist/execution/PostgresExecutionJournal.d.ts.map +1 -0
- package/dist/execution/PostgresExecutionJournal.js +131 -0
- package/dist/execution/PostgresExecutionJournal.js.map +1 -0
- package/dist/execution/RegistryExecutor.d.ts +35 -0
- package/dist/execution/RegistryExecutor.d.ts.map +1 -0
- package/dist/execution/RegistryExecutor.js +84 -0
- package/dist/execution/RegistryExecutor.js.map +1 -0
- package/dist/execution/SafeExecutor.d.ts +22 -193
- package/dist/execution/SafeExecutor.d.ts.map +1 -1
- package/dist/execution/SafeExecutor.js +49 -521
- package/dist/execution/SafeExecutor.js.map +1 -1
- package/dist/http/AuthorityPaths.d.ts +51 -0
- package/dist/http/AuthorityPaths.d.ts.map +1 -0
- package/dist/http/AuthorityPaths.js +84 -0
- package/dist/http/AuthorityPaths.js.map +1 -0
- package/dist/shadow/ShadowPipeline.d.ts +3 -1
- package/dist/shadow/ShadowPipeline.d.ts.map +1 -1
- package/dist/shadow/ShadowPipeline.js +3 -3
- package/dist/shadow/ShadowPipeline.js.map +1 -1
- package/dist/testing/Index.d.ts +2 -1
- package/dist/testing/Index.d.ts.map +1 -1
- package/dist/testing/Index.js +2 -1
- package/dist/testing/Index.js.map +1 -1
- package/dist/testing/LocalAuthority.d.ts +35 -1
- package/dist/testing/LocalAuthority.d.ts.map +1 -1
- package/dist/testing/LocalAuthority.js +122 -2
- package/dist/testing/LocalAuthority.js.map +1 -1
- package/dist/testing/SignedSignals.d.ts +150 -0
- package/dist/testing/SignedSignals.d.ts.map +1 -0
- package/dist/testing/SignedSignals.js +291 -0
- package/dist/testing/SignedSignals.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const JOURNAL_VERSION = "agent-safe.attempts/1";
|
|
3
|
+
const identifier = z.string().trim().min(1).max(200);
|
|
4
|
+
const hash = z.string().regex(/^sha256:[0-9a-f]{64}$/);
|
|
5
|
+
/**
|
|
6
|
+
* What the journal records about one attempt, in the order it happens:
|
|
7
|
+
* opened before the executor runs, claimed after the grant is consumed and
|
|
8
|
+
* before the provider is touched, closed once the outcome is known, and
|
|
9
|
+
* reconciled when a lost outcome is resolved later. The intent is stored
|
|
10
|
+
* whole on `ATTEMPT_OPENED`, because reconciliation needs the exact intent
|
|
11
|
+
* it was and nothing less will re-hash to the same value.
|
|
12
|
+
*/
|
|
13
|
+
export const JournalRecordSchema = z.discriminatedUnion("record", [
|
|
14
|
+
z.strictObject({
|
|
15
|
+
record: z.literal("ATTEMPT_OPENED"),
|
|
16
|
+
at: z.string().datetime(),
|
|
17
|
+
intent_id: identifier,
|
|
18
|
+
intent_hash: hash,
|
|
19
|
+
idempotency_key: z.string().trim().min(1).max(180),
|
|
20
|
+
decision_id: identifier,
|
|
21
|
+
dossier_id: identifier,
|
|
22
|
+
caller_principal: identifier.nullable(),
|
|
23
|
+
/** The captured intent, verbatim, so a restart can present it again. */
|
|
24
|
+
intent: z.record(z.string(), z.unknown()),
|
|
25
|
+
}),
|
|
26
|
+
z.strictObject({
|
|
27
|
+
record: z.literal("GRANT_CLAIMED"),
|
|
28
|
+
at: z.string().datetime(),
|
|
29
|
+
intent_id: identifier,
|
|
30
|
+
intent_hash: hash,
|
|
31
|
+
idempotency_key: z.string().trim().min(1).max(180),
|
|
32
|
+
grant_id: identifier,
|
|
33
|
+
expires_at: z.string().datetime(),
|
|
34
|
+
/** SHA-256 over the canonical parameters the handler is about to send. */
|
|
35
|
+
request_digest: hash,
|
|
36
|
+
}),
|
|
37
|
+
z.strictObject({
|
|
38
|
+
record: z.literal("ATTEMPT_CLOSED"),
|
|
39
|
+
at: z.string().datetime(),
|
|
40
|
+
intent_id: identifier,
|
|
41
|
+
intent_hash: hash,
|
|
42
|
+
outcome: z.string().trim().min(1).max(64),
|
|
43
|
+
executed: z.boolean().nullable(),
|
|
44
|
+
finalization: z.enum(["RECORDED", "PENDING", "UNSUPPORTED"]).nullable(),
|
|
45
|
+
}),
|
|
46
|
+
z.strictObject({
|
|
47
|
+
record: z.literal("RECONCILED"),
|
|
48
|
+
at: z.string().datetime(),
|
|
49
|
+
intent_id: identifier,
|
|
50
|
+
intent_hash: hash,
|
|
51
|
+
status: z.enum(["COMPLETED", "DEFINITELY_NOT_EXECUTED", "UNKNOWN_AFTER_DISPATCH", "BLOCKED"]),
|
|
52
|
+
source: z.enum(["STARTUP", "CALLER"]),
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
/** A refusal by the journal: the code, never a path or a value. */
|
|
56
|
+
export class JournalError extends Error {
|
|
57
|
+
code;
|
|
58
|
+
constructor(code) {
|
|
59
|
+
super(code);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.name = "JournalError";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The journal's refusal of a second claim under one idempotency key. */
|
|
65
|
+
export const IDEMPOTENCY_KEY_DISPATCHED = "IDEMPOTENCY_KEY_DISPATCHED";
|
|
66
|
+
/** Folds a stream of records into the attempts still open, oldest first. */
|
|
67
|
+
export function openAttemptsFrom(records) {
|
|
68
|
+
const open = new Map();
|
|
69
|
+
for (const record of records) {
|
|
70
|
+
if (record.record === "ATTEMPT_OPENED") {
|
|
71
|
+
open.set(record.intent_id, {
|
|
72
|
+
intentId: record.intent_id,
|
|
73
|
+
intentHash: record.intent_hash,
|
|
74
|
+
idempotencyKey: record.idempotency_key,
|
|
75
|
+
openedAt: record.at,
|
|
76
|
+
decisionId: record.decision_id,
|
|
77
|
+
dossierId: record.dossier_id,
|
|
78
|
+
grantId: null,
|
|
79
|
+
expiresAt: null,
|
|
80
|
+
callerPrincipal: record.caller_principal,
|
|
81
|
+
state: "OPENED",
|
|
82
|
+
intent: record.intent,
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (record.record === "GRANT_CLAIMED") {
|
|
87
|
+
const attempt = open.get(record.intent_id);
|
|
88
|
+
if (attempt !== undefined) {
|
|
89
|
+
open.set(record.intent_id, {
|
|
90
|
+
...attempt,
|
|
91
|
+
grantId: record.grant_id,
|
|
92
|
+
expiresAt: record.expires_at,
|
|
93
|
+
state: "CLAIMED",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
open.delete(record.intent_id);
|
|
99
|
+
}
|
|
100
|
+
return [...open.values()];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Folds a stream of records into the authorizations one intent was
|
|
104
|
+
* dispatched under, oldest first. Only a claimed attempt was dispatched: one
|
|
105
|
+
* opened and never claimed consumed no grant, and a claim with no opening
|
|
106
|
+
* record names no decision, so neither is anything to reconcile. Closing and
|
|
107
|
+
* reconciling records are ignored, because what an attempt was dispatched
|
|
108
|
+
* under does not change when its outcome becomes known.
|
|
109
|
+
*/
|
|
110
|
+
export function authorizationsFrom(records, intentId) {
|
|
111
|
+
const dispatched = [];
|
|
112
|
+
let opened = null;
|
|
113
|
+
for (const record of records) {
|
|
114
|
+
if (record.intent_id !== intentId)
|
|
115
|
+
continue;
|
|
116
|
+
if (record.record === "ATTEMPT_OPENED")
|
|
117
|
+
opened = record;
|
|
118
|
+
if (record.record === "GRANT_CLAIMED" && opened !== null) {
|
|
119
|
+
dispatched.push({
|
|
120
|
+
decisionId: opened.decision_id,
|
|
121
|
+
dossierId: opened.dossier_id,
|
|
122
|
+
grantId: record.grant_id,
|
|
123
|
+
intentHash: record.intent_hash,
|
|
124
|
+
expiresAt: record.expires_at,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return dispatched;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Folds a stream of records into the authorizations claimed under one
|
|
132
|
+
* idempotency key, oldest first, whichever intent each was opened for. The
|
|
133
|
+
* claim record names the key it was claimed under; the decision comes from
|
|
134
|
+
* the opening record of the same intent, as in `authorizationsFrom`.
|
|
135
|
+
*/
|
|
136
|
+
export function dispatchedUnderFrom(records, idempotencyKey) {
|
|
137
|
+
const dispatched = [];
|
|
138
|
+
const opened = new Map();
|
|
139
|
+
for (const record of records) {
|
|
140
|
+
if (record.record === "ATTEMPT_OPENED")
|
|
141
|
+
opened.set(record.intent_id, record);
|
|
142
|
+
if (record.record !== "GRANT_CLAIMED" || record.idempotency_key !== idempotencyKey)
|
|
143
|
+
continue;
|
|
144
|
+
const opening = opened.get(record.intent_id);
|
|
145
|
+
if (opening === undefined)
|
|
146
|
+
continue;
|
|
147
|
+
dispatched.push({
|
|
148
|
+
decisionId: opening.decision_id,
|
|
149
|
+
dossierId: opening.dossier_id,
|
|
150
|
+
grantId: record.grant_id,
|
|
151
|
+
intentHash: record.intent_hash,
|
|
152
|
+
expiresAt: record.expires_at,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return dispatched;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=ExecutionJournal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionJournal.js","sourceRoot":"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,eAAe,IAAI,MAAM,CAAC,eAAe,KAAK,cAAc;YAAE,SAAS;QAC7F,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,OAAO,KAAK,SAAS;YAAE,SAAS;QACpC,UAAU,CAAC,IAAI,CAAC;YACd,UAAU,EAAE,OAAO,CAAC,WAAW;YAC/B,SAAS,EAAE,OAAO,CAAC,UAAU;YAC7B,OAAO,EAAE,MAAM,CAAC,QAAQ;YACxB,UAAU,EAAE,MAAM,CAAC,WAAW;YAC9B,SAAS,EAAE,MAAM,CAAC,UAAU;SAC7B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { DecisionGate } from "../decision/DecisionAuthority.js";
|
|
2
|
+
import type { CapturedIntent } from "../intent/ExecutionIntent.js";
|
|
3
|
+
import type { ExecutionFinalization, VerifiedAuthorization } from "./AuthorizationVerifier.js";
|
|
4
|
+
import type { ExecutionPermit } from "./NativeExecutor.js";
|
|
5
|
+
/**
|
|
6
|
+
* Every governed run ends in exactly one of these. They answer one question,
|
|
7
|
+
* "may the caller retry the side effect?", and the answers never overlap:
|
|
8
|
+
*
|
|
9
|
+
* | Outcome | Meaning |
|
|
10
|
+
* | ------------------------- | -------------------------------------------------------------- |
|
|
11
|
+
* | `BLOCKED` | No valid execution authority reached the executor |
|
|
12
|
+
* | `HELD` | Admitted; the grant waits, unclaimed, for the native boundary |
|
|
13
|
+
* | `FAILED_BEFORE_DISPATCH` | A grant was consumed and nothing was sent |
|
|
14
|
+
* | `COMPLETED` | The platform effected the action |
|
|
15
|
+
* | `DEFINITELY_NOT_EXECUTED` | The platform was reached and refused; nothing was effected |
|
|
16
|
+
* | `UNKNOWN_AFTER_DISPATCH` | The write left, and nobody can yet say what happened |
|
|
17
|
+
*/
|
|
18
|
+
export type ExecutionOutcome = "BLOCKED" | "HELD" | "FAILED_BEFORE_DISPATCH" | "COMPLETED" | "DEFINITELY_NOT_EXECUTED" | "UNKNOWN_AFTER_DISPATCH";
|
|
19
|
+
export type ExecutionBlockReason = "DECISION_NOT_AUTHORITATIVE" | "DECISION_NOT_ALLOW" | "DOSSIER_MISSING" | "INTENT_BINDING_MISMATCH" | "INTENT_CONFORMANCE_FAILED" | "AUTHORIZATION_MISSING" | "AUTHORIZATION_INVALID" | "RECOVERY_BINDING_MISMATCH" | "RECOVERY_ATTEMPT_UNKNOWN" | "BOUNDARY_MISMATCH" | "WORKLOAD_MISMATCH" | "AUDIT_UNAVAILABLE" | "CAPABILITY_UNAVAILABLE" | "IDEMPOTENCY_KEY_DISPATCHED" | "JOURNAL_UNAVAILABLE";
|
|
20
|
+
/** Where an executor reads back the authorizations it dispatched an intent under. */
|
|
21
|
+
export interface DispatchedAttempts {
|
|
22
|
+
/** Every authorization journaled for this intent, oldest first; none when it was never dispatched here. */
|
|
23
|
+
authorizationsOf(captured: CapturedIntent): Promise<readonly VerifiedAuthorization[]>;
|
|
24
|
+
}
|
|
25
|
+
export type ExecutionPreDispatchFailureReason = "HANDLER_FAILED_BEFORE_DISPATCH" | "AUDIT_UNAVAILABLE" | "JOURNAL_UNAVAILABLE";
|
|
26
|
+
/**
|
|
27
|
+
* What a caller presents back to reconcile an attempt whose outcome was
|
|
28
|
+
* lost. The fields are listed rather than inherited, because this is a
|
|
29
|
+
* versioned wire object: a field that appears on `VerifiedAuthorization`
|
|
30
|
+
* later must be added here deliberately or not at all.
|
|
31
|
+
*/
|
|
32
|
+
export interface ExecutionRecoveryReference {
|
|
33
|
+
readonly version: "agent-safe.recovery/1";
|
|
34
|
+
readonly decisionId: string;
|
|
35
|
+
readonly dossierId: string;
|
|
36
|
+
readonly grantId: string;
|
|
37
|
+
readonly intentHash: string;
|
|
38
|
+
readonly expiresAt: string;
|
|
39
|
+
readonly idempotencyKey: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ExecutionBlockedResult {
|
|
42
|
+
readonly outcome: "BLOCKED";
|
|
43
|
+
readonly executed: false;
|
|
44
|
+
readonly reason: ExecutionBlockReason;
|
|
45
|
+
/** Why, more narrowly, when the runner knows: a capability gap, a journal refusal. */
|
|
46
|
+
readonly code?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Present only when the decision failed closed and the posture is not
|
|
49
|
+
* strict: what the surface may do with an action nobody could decide. The
|
|
50
|
+
* runner itself never writes it; an ungoverned continuation is the
|
|
51
|
+
* surface's act, and the evidence line reports it as one.
|
|
52
|
+
*/
|
|
53
|
+
readonly unavailable?: {
|
|
54
|
+
readonly posture: "BOUNDED_CONTINUITY" | "CUSTOM";
|
|
55
|
+
readonly disposition: "NOT_FORWARDED" | "HELD" | "FORWARDED_UNGOVERNED";
|
|
56
|
+
};
|
|
57
|
+
readonly result: null;
|
|
58
|
+
readonly authorization: null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The provider refused, definitively, after the dispatch boundary. The grant
|
|
62
|
+
* was consumed and the request was sent, and nothing was effected: the
|
|
63
|
+
* outcome is a fact, not an unknown, so there is nothing to reconcile and no
|
|
64
|
+
* recovery reference to present. A caller that wants the action after all
|
|
65
|
+
* needs a fresh decision and a fresh grant, because the refusal was about
|
|
66
|
+
* this attempt.
|
|
67
|
+
*/
|
|
68
|
+
export interface ProviderRefusedResult {
|
|
69
|
+
readonly outcome: "DEFINITELY_NOT_EXECUTED";
|
|
70
|
+
readonly executed: false;
|
|
71
|
+
readonly recovered: false;
|
|
72
|
+
/** The provider's own reason, as the handler reported it. */
|
|
73
|
+
readonly reason: string;
|
|
74
|
+
readonly result: null;
|
|
75
|
+
readonly authorization: VerifiedAuthorization;
|
|
76
|
+
}
|
|
77
|
+
export interface ProviderOutcomeUnknownResult {
|
|
78
|
+
readonly outcome: "UNKNOWN_AFTER_DISPATCH";
|
|
79
|
+
readonly executed: null;
|
|
80
|
+
readonly reason: "PROVIDER_OUTCOME_UNKNOWN";
|
|
81
|
+
readonly result: null;
|
|
82
|
+
readonly authorization: VerifiedAuthorization;
|
|
83
|
+
readonly recovery: ExecutionRecoveryReference;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Every outcome that consumed a grant reports whether the attempt's commit
|
|
87
|
+
* evidence reached the authority. Finalization is evidence, not authority;
|
|
88
|
+
* it never changes `outcome` or `executed`.
|
|
89
|
+
*/
|
|
90
|
+
export type SafeExecutionResult<TResult = unknown> = {
|
|
91
|
+
readonly outcome: "COMPLETED";
|
|
92
|
+
readonly executed: true;
|
|
93
|
+
readonly recovered: false;
|
|
94
|
+
readonly result: TResult;
|
|
95
|
+
readonly authorization: VerifiedAuthorization;
|
|
96
|
+
readonly finalization: ExecutionFinalization;
|
|
97
|
+
} | ExecutionBlockedResult | {
|
|
98
|
+
readonly outcome: "FAILED_BEFORE_DISPATCH";
|
|
99
|
+
readonly executed: false;
|
|
100
|
+
readonly reason: ExecutionPreDispatchFailureReason;
|
|
101
|
+
/** Why the handler refused, when it threw a `PreDispatchRefusal`. */
|
|
102
|
+
readonly code?: string;
|
|
103
|
+
readonly result: null;
|
|
104
|
+
readonly authorization: VerifiedAuthorization;
|
|
105
|
+
readonly finalization: ExecutionFinalization;
|
|
106
|
+
} | (ProviderRefusedResult & {
|
|
107
|
+
readonly finalization: ExecutionFinalization;
|
|
108
|
+
}) | (ProviderOutcomeUnknownResult & {
|
|
109
|
+
readonly finalization: ExecutionFinalization;
|
|
110
|
+
});
|
|
111
|
+
export type FailedBeforeDispatchResult = Extract<SafeExecutionResult<never>, {
|
|
112
|
+
outcome: "FAILED_BEFORE_DISPATCH";
|
|
113
|
+
}>;
|
|
114
|
+
export type ExecutionReconciliationResult<TResult = unknown> = {
|
|
115
|
+
readonly outcome: "COMPLETED";
|
|
116
|
+
readonly executed: true;
|
|
117
|
+
readonly recovered: true;
|
|
118
|
+
readonly result: TResult;
|
|
119
|
+
readonly authorization: VerifiedAuthorization;
|
|
120
|
+
} | {
|
|
121
|
+
readonly outcome: "DEFINITELY_NOT_EXECUTED";
|
|
122
|
+
readonly executed: false;
|
|
123
|
+
readonly recovered: true;
|
|
124
|
+
readonly reason: "PROVIDER_CONFIRMED_NOT_EXECUTED";
|
|
125
|
+
readonly result: null;
|
|
126
|
+
readonly authorization: VerifiedAuthorization;
|
|
127
|
+
} | ExecutionBlockedResult | ProviderOutcomeUnknownResult;
|
|
128
|
+
/**
|
|
129
|
+
* A grant admitted for a later claim. Every check a run makes before it
|
|
130
|
+
* consumes a grant has passed, and nothing has been consumed: the grant is
|
|
131
|
+
* still the authority's to hand out once. Only a hold issues one, only the
|
|
132
|
+
* runner that issued it can claim it, and it is claimed at most once.
|
|
133
|
+
*
|
|
134
|
+
* This is for an effect that another system performs at a moment this
|
|
135
|
+
* process does not choose, such as a card authorization the issuer asks
|
|
136
|
+
* about in milliseconds or a posting an ERP makes when a clerk posts: the
|
|
137
|
+
* decision is made before, the grant waits here, and the claim happens when
|
|
138
|
+
* that system presents its permit.
|
|
139
|
+
*/
|
|
140
|
+
export interface HeldExecution {
|
|
141
|
+
readonly captured: CapturedIntent;
|
|
142
|
+
readonly decision: DecisionGate;
|
|
143
|
+
/** The grant's own expiry: after it there is nothing left to claim. */
|
|
144
|
+
readonly expiresAt: string;
|
|
145
|
+
}
|
|
146
|
+
export interface ExecutionHeldResult {
|
|
147
|
+
readonly outcome: "HELD";
|
|
148
|
+
readonly executed: false;
|
|
149
|
+
readonly result: null;
|
|
150
|
+
readonly authorization: null;
|
|
151
|
+
readonly held: HeldExecution;
|
|
152
|
+
}
|
|
153
|
+
/** A held permit-style execution: the hold, and the permit the native boundary presents. */
|
|
154
|
+
export interface PermitHeldResult extends ExecutionHeldResult {
|
|
155
|
+
readonly permit: ExecutionPermit;
|
|
156
|
+
}
|
|
157
|
+
export type HeldClaimResult = {
|
|
158
|
+
readonly outcome: "CLAIMED";
|
|
159
|
+
readonly authorization: VerifiedAuthorization;
|
|
160
|
+
} | ExecutionBlockedResult | FailedBeforeDispatchResult;
|
|
161
|
+
/** A presented permit, claimed: what the boundary writes with. */
|
|
162
|
+
export type PermitPresentationResult = {
|
|
163
|
+
readonly outcome: "CLAIMED";
|
|
164
|
+
readonly authorization: VerifiedAuthorization;
|
|
165
|
+
readonly permit: ExecutionPermit;
|
|
166
|
+
} | ExecutionBlockedResult | FailedBeforeDispatchResult;
|
|
167
|
+
/**
|
|
168
|
+
* How a held execution's receipt settled it. A receipt is accepted once: a
|
|
169
|
+
* second one, or one for a permit nobody presented, is refused and changes
|
|
170
|
+
* nothing that was recorded.
|
|
171
|
+
*/
|
|
172
|
+
export type ExecutionSettlement<TResult = unknown> = {
|
|
173
|
+
readonly status: "SETTLED";
|
|
174
|
+
readonly outcome: "COMPLETED" | "DEFINITELY_NOT_EXECUTED" | "UNKNOWN_AFTER_DISPATCH";
|
|
175
|
+
readonly executed: boolean | null;
|
|
176
|
+
readonly result: TResult | null;
|
|
177
|
+
readonly reason: string | null;
|
|
178
|
+
readonly authorization: VerifiedAuthorization;
|
|
179
|
+
readonly finalization: ExecutionFinalization;
|
|
180
|
+
/** Present when the receipt left the outcome unknown: what a reconciliation is held against. */
|
|
181
|
+
readonly recovery?: ExecutionRecoveryReference;
|
|
182
|
+
} | {
|
|
183
|
+
readonly status: "REFUSED";
|
|
184
|
+
readonly reason: "RECEIPT_DUPLICATE" | "PERMIT_NOT_PRESENTED";
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=ExecutionOutcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionOutcome.d.ts","sourceRoot":"","sources":["../../src/execution/ExecutionOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,KAAK,E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,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC;IAC9C,QAAQ,CAAC,YAAY,EAAE,qBAAqB,CAAC;IAC7C,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,CAAC,EAAE,0BAA0B,CAAC;CAChD,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,GAAG,sBAAsB,CAAC;CAC/D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionOutcome.js","sourceRoot":"","sources":["../../src/execution/ExecutionOutcome.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { DecisionGate } from "../decision/DecisionAuthority.js";
|
|
2
|
+
import type { CapturedIntent } from "../intent/ExecutionIntent.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a governed surface does with an action when it cannot reach the
|
|
5
|
+
* authority. The vocabulary is Decionis Core's (`FailurePosture`, shared
|
|
6
|
+
* with the AgentSafe gateway), and so is the invariant every posture keeps:
|
|
7
|
+
* failing to reach the authority is never an authorization.
|
|
8
|
+
*
|
|
9
|
+
* - `STRICT`: the action does not run.
|
|
10
|
+
* - `BOUNDED_CONTINUITY`: the surface may let the action continue without
|
|
11
|
+
* an evaluation, ungoverned and never approved, where it was configured
|
|
12
|
+
* for a bounded exposure.
|
|
13
|
+
* - `CUSTOM`: the institution decides, per action.
|
|
14
|
+
*
|
|
15
|
+
* The runner applies posture only to a decision that failed closed: an
|
|
16
|
+
* authority that answered `BLOCK` was reached, and no posture overrides it.
|
|
17
|
+
* And the runner itself never writes without a grant, under any posture: an
|
|
18
|
+
* ungoverned continuation is the surface's own act, which the runner reports
|
|
19
|
+
* as a coverage gap in the evidence line instead of hiding it.
|
|
20
|
+
*/
|
|
21
|
+
export type FailurePosture = "STRICT" | "BOUNDED_CONTINUITY" | "CUSTOM";
|
|
22
|
+
/**
|
|
23
|
+
* What happened to an action the authority could not decide, in the gateway's
|
|
24
|
+
* own tokens: refused, held for someone to look at, or let through
|
|
25
|
+
* ungoverned by the surface.
|
|
26
|
+
*/
|
|
27
|
+
export type UnavailableDisposition = "NOT_FORWARDED" | "HELD" | "FORWARDED_UNGOVERNED";
|
|
28
|
+
/** The authority state an evidence line names: decided, or unreachable. */
|
|
29
|
+
export type AuthorityState = "DECIDED" | "AUTHORITY_UNAVAILABLE";
|
|
30
|
+
export interface PostureContext {
|
|
31
|
+
readonly captured: CapturedIntent;
|
|
32
|
+
readonly decision: DecisionGate;
|
|
33
|
+
}
|
|
34
|
+
export type ExecutionPosture = {
|
|
35
|
+
readonly posture: "STRICT";
|
|
36
|
+
} | {
|
|
37
|
+
readonly posture: "BOUNDED_CONTINUITY";
|
|
38
|
+
} | {
|
|
39
|
+
readonly posture: "CUSTOM";
|
|
40
|
+
/** The institution's choice for one action; it may hold or refuse, never authorize. */
|
|
41
|
+
readonly decide: (context: PostureContext) => UnavailableDisposition;
|
|
42
|
+
};
|
|
43
|
+
export declare const STRICT_POSTURE: ExecutionPosture;
|
|
44
|
+
/**
|
|
45
|
+
* The disposition for an action whose decision failed closed. A custom rule
|
|
46
|
+
* that throws, or answers something else, is `NOT_FORWARDED`: the posture
|
|
47
|
+
* that cannot be read is the strict one.
|
|
48
|
+
*/
|
|
49
|
+
export declare function unavailableDisposition(posture: ExecutionPosture, context: PostureContext): UnavailableDisposition;
|
|
50
|
+
//# sourceMappingURL=ExecutionPosture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionPosture.d.ts","sourceRoot":"","sources":["../../src/execution/ExecutionPosture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,oBAAoB,GAAG,QAAQ,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG,MAAM,GAAG,sBAAsB,CAAC;AAEvF,2EAA2E;AAC3E,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,uBAAuB,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;CACjC;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GAC1C;IACE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,sBAAsB,CAAC;CACtE,CAAC;AAEN,eAAO,MAAM,cAAc,EAAE,gBAAuD,CAAC;AAErF;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,cAAc,GACtB,sBAAsB,CASxB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const STRICT_POSTURE = Object.freeze({ posture: "STRICT" });
|
|
2
|
+
/**
|
|
3
|
+
* The disposition for an action whose decision failed closed. A custom rule
|
|
4
|
+
* that throws, or answers something else, is `NOT_FORWARDED`: the posture
|
|
5
|
+
* that cannot be read is the strict one.
|
|
6
|
+
*/
|
|
7
|
+
export function unavailableDisposition(posture, context) {
|
|
8
|
+
if (posture.posture === "STRICT")
|
|
9
|
+
return "NOT_FORWARDED";
|
|
10
|
+
if (posture.posture === "BOUNDED_CONTINUITY")
|
|
11
|
+
return "FORWARDED_UNGOVERNED";
|
|
12
|
+
try {
|
|
13
|
+
const chosen = posture.decide(context);
|
|
14
|
+
return chosen === "HELD" || chosen === "FORWARDED_UNGOVERNED" ? chosen : "NOT_FORWARDED";
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return "NOT_FORWARDED";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ExecutionPosture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionPosture.js","sourceRoot":"","sources":["../../src/execution/ExecutionPosture.ts"],"names":[],"mappings":"AA+CA,MAAM,CAAC,MAAM,cAAc,GAAqB,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AAErF;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAyB,EACzB,OAAuB;IAEvB,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,eAAe,CAAC;IACzD,IAAI,OAAO,CAAC,OAAO,KAAK,oBAAoB;QAAE,OAAO,sBAAsB,CAAC;IAC5E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,sBAAsB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC;IAC3F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ExecutionFinalization } from "./AuthorizationVerifier.js";
|
|
2
|
+
import type { ExecutionOutcome } from "./ExecutionOutcome.js";
|
|
3
|
+
import type { AuthorityState, FailurePosture, UnavailableDisposition } from "./ExecutionPosture.js";
|
|
4
|
+
import type { NATIVE_EXECUTOR_CONTRACT, ExecutionStyle, ExecutorScope, PlatformId } from "./NativeExecutor.js";
|
|
5
|
+
export declare const EXECUTOR_EVIDENCE_VERSION = "agent-safe.executor-evidence/1";
|
|
6
|
+
/** Which step of a governed execution a line records. */
|
|
7
|
+
export type EvidenceStage = "RUN" | "PRESENTATION" | "SETTLEMENT" | "RECONCILIATION";
|
|
8
|
+
/**
|
|
9
|
+
* One line per step of a governed execution, written by the runner and by
|
|
10
|
+
* nothing else: which executor ran what, under which decision and grant, and
|
|
11
|
+
* how it ended. It is the evidence an operator counts governed writes with,
|
|
12
|
+
* and it carries identifiers, statuses and timings only — never a parameter,
|
|
13
|
+
* a token, a receipt, a credential or a response body. Snake case, because
|
|
14
|
+
* it is a wire object other languages read.
|
|
15
|
+
*/
|
|
16
|
+
export interface ExecutorEvidenceLine {
|
|
17
|
+
readonly version: typeof EXECUTOR_EVIDENCE_VERSION;
|
|
18
|
+
readonly contract: typeof NATIVE_EXECUTOR_CONTRACT;
|
|
19
|
+
readonly at: string;
|
|
20
|
+
readonly stage: EvidenceStage;
|
|
21
|
+
readonly executor: {
|
|
22
|
+
readonly platform: PlatformId;
|
|
23
|
+
readonly version: string;
|
|
24
|
+
readonly style: ExecutionStyle;
|
|
25
|
+
};
|
|
26
|
+
readonly action_type: string;
|
|
27
|
+
readonly intent_id: string;
|
|
28
|
+
readonly intent_hash: string;
|
|
29
|
+
readonly decision_id: string | null;
|
|
30
|
+
readonly dossier_id: string | null;
|
|
31
|
+
readonly verdict: string | null;
|
|
32
|
+
readonly grant_id: string | null;
|
|
33
|
+
/** The step's result: an outcome, or `CLAIMED` for a presented permit. */
|
|
34
|
+
readonly outcome: ExecutionOutcome | "CLAIMED";
|
|
35
|
+
readonly executed: boolean | null;
|
|
36
|
+
readonly reason: string | null;
|
|
37
|
+
readonly code: string | null;
|
|
38
|
+
/** True only when a grant governed the step: held, claimed or consumed. */
|
|
39
|
+
readonly governed: boolean;
|
|
40
|
+
readonly authority_state: AuthorityState;
|
|
41
|
+
readonly posture: FailurePosture;
|
|
42
|
+
/** What became of an action nobody could decide; null when the authority decided. */
|
|
43
|
+
readonly disposition: UnavailableDisposition | null;
|
|
44
|
+
readonly finalization: ExecutionFinalization | null;
|
|
45
|
+
readonly duration_ms: number;
|
|
46
|
+
readonly scope: {
|
|
47
|
+
readonly org_id: string;
|
|
48
|
+
readonly workspace_id: string;
|
|
49
|
+
readonly connection_id: string;
|
|
50
|
+
readonly connection_revision: string;
|
|
51
|
+
readonly environment: "sandbox" | "production";
|
|
52
|
+
} | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where evidence lines go. A sink is told after the fact and may be slow or
|
|
56
|
+
* fail: the runner awaits it, ignores its errors, and never lets it change an
|
|
57
|
+
* outcome, because evidence is not authority.
|
|
58
|
+
*/
|
|
59
|
+
export interface ExecutorEvidenceSink {
|
|
60
|
+
emit(line: ExecutorEvidenceLine): void | Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/** The scope as a line carries it: the connection, never the company or store names. */
|
|
63
|
+
export declare function evidenceScope(scope: ExecutorScope | null): ExecutorEvidenceLine["scope"];
|
|
64
|
+
//# sourceMappingURL=ExecutorEvidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutorEvidence.d.ts","sourceRoot":"","sources":["../../src/execution/ExecutorEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,KAAK,EACV,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,UAAU,EACX,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,yBAAyB,mCAAmC,CAAC;AAE1E,yDAAyD;AACz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CAAC;IACjC,qFAAqF;IACrF,QAAQ,CAAC,WAAW,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACpD,QAAQ,CAAC,YAAY,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACpD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;QACrC,QAAQ,CAAC,WAAW,EAAE,SAAS,GAAG,YAAY,CAAC;KAChD,GAAG,IAAI,CAAC;CACV;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,GAAG,oBAAoB,CAAC,OAAO,CAAC,CASxF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const EXECUTOR_EVIDENCE_VERSION = "agent-safe.executor-evidence/1";
|
|
2
|
+
/** The scope as a line carries it: the connection, never the company or store names. */
|
|
3
|
+
export function evidenceScope(scope) {
|
|
4
|
+
if (scope === null)
|
|
5
|
+
return null;
|
|
6
|
+
return {
|
|
7
|
+
org_id: scope.orgId,
|
|
8
|
+
workspace_id: scope.workspaceId,
|
|
9
|
+
connection_id: scope.connectionId,
|
|
10
|
+
connection_revision: scope.connectionRevision,
|
|
11
|
+
environment: scope.environment,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ExecutorEvidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutorEvidence.js","sourceRoot":"","sources":["../../src/execution/ExecutorEvidence.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,yBAAyB,GAAG,gCAAgC,CAAC;AA6D1E,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,KAA2B;IACvD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,KAAK;QACnB,YAAY,EAAE,KAAK,CAAC,WAAW;QAC/B,aAAa,EAAE,KAAK,CAAC,YAAY;QACjC,mBAAmB,EAAE,KAAK,CAAC,kBAAkB;QAC7C,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC;AACJ,CAAC"}
|