@kyaki/agents 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/approvals.d.ts +35 -0
  2. package/dist/approvals.d.ts.map +1 -0
  3. package/dist/approvals.js +93 -0
  4. package/dist/approvals.js.map +1 -0
  5. package/dist/auditor.d.ts +104 -0
  6. package/dist/auditor.d.ts.map +1 -0
  7. package/dist/auditor.js +250 -0
  8. package/dist/auditor.js.map +1 -0
  9. package/dist/continuous-auditor.d.ts +38 -0
  10. package/dist/continuous-auditor.d.ts.map +1 -0
  11. package/dist/continuous-auditor.js +52 -0
  12. package/dist/continuous-auditor.js.map +1 -0
  13. package/dist/index.d.ts +20 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +8 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/market.d.ts +10 -0
  18. package/dist/market.d.ts.map +1 -0
  19. package/dist/market.js +10 -0
  20. package/dist/market.js.map +1 -0
  21. package/dist/procurer.d.ts +54 -0
  22. package/dist/procurer.d.ts.map +1 -0
  23. package/dist/procurer.js +142 -0
  24. package/dist/procurer.js.map +1 -0
  25. package/dist/steward.d.ts +89 -0
  26. package/dist/steward.d.ts.map +1 -0
  27. package/dist/steward.js +121 -0
  28. package/dist/steward.js.map +1 -0
  29. package/dist/treasury.d.ts +134 -0
  30. package/dist/treasury.d.ts.map +1 -0
  31. package/dist/treasury.js +346 -0
  32. package/dist/treasury.js.map +1 -0
  33. package/dist/types.d.ts +47 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +2 -0
  36. package/dist/types.js.map +1 -0
  37. package/package.json +34 -0
  38. package/src/approvals.ts +111 -0
  39. package/src/auditor.ts +342 -0
  40. package/src/continuous-auditor.ts +68 -0
  41. package/src/index.ts +31 -0
  42. package/src/market.ts +11 -0
  43. package/src/procurer.ts +183 -0
  44. package/src/steward.ts +168 -0
  45. package/src/treasury.ts +458 -0
  46. package/src/types.ts +57 -0
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { MockMarket } from './market.js';
2
+ export { ApprovalInbox, signApproval, verifyApproval } from './approvals.js';
3
+ export { ProcurerAgent } from './procurer.js';
4
+ export { Treasurer, StaticFX, TreasuryApprovalInbox, } from './treasury.js';
5
+ export { AuditorAgent, verifyAuditAttestation, } from './auditor.js';
6
+ export { ContinuousAuditor } from './continuous-auditor.js';
7
+ export { Steward, verifyGovernanceAttestation, } from './steward.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAuB,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AACnE,OAAO,EACL,SAAS,EAAE,QAAQ,EAAE,qBAAqB,GAI3C,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EAAE,sBAAsB,GAGrC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAoB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EACL,OAAO,EAAE,2BAA2B,GAErC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * market.ts — Mock RFQ market for demos and tests.
3
+ */
4
+ import type { Market, VendorOffer } from './types.js';
5
+ export declare class MockMarket implements Market {
6
+ private readonly book;
7
+ constructor(book: Record<string, VendorOffer[]>);
8
+ offersFor(needId: string): VendorOffer[];
9
+ }
10
+ //# sourceMappingURL=market.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../src/market.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,qBAAa,UAAW,YAAW,MAAM;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC;IAChE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE;CAGzC"}
package/dist/market.js ADDED
@@ -0,0 +1,10 @@
1
+ export class MockMarket {
2
+ book;
3
+ constructor(book) {
4
+ this.book = book;
5
+ }
6
+ offersFor(needId) {
7
+ return [...(this.book[needId] ?? [])];
8
+ }
9
+ }
10
+ //# sourceMappingURL=market.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"market.js","sourceRoot":"","sources":["../src/market.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,UAAU;IACQ;IAA7B,YAA6B,IAAmC;QAAnC,SAAI,GAAJ,IAAI,CAA+B;IAAG,CAAC;IACpE,SAAS,CAAC,MAAc;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * procurer.ts — The Procurer: first autonomous agent on the Mandate OS.
3
+ * RFQ across vendors, COMPLIANCE-FILTERED sourcing (a cheaper off-policy
4
+ * vendor is refused, not bought), tri-state execution through the policy
5
+ * engine, signed-approval workflow, and a savings report where every claimed
6
+ * saving resolves to a signed transaction id in the hash-chained audit log.
7
+ */
8
+ import { type AgentKeys, type AuditLog, type SpendMandate, type VerificationContext } from '@kyaki/core';
9
+ import { type AutonomyLadder, type OrgSpendLedger, type SpendPolicy } from '@kyaki/policy';
10
+ import { type ApprovalInbox, type SignedApproval } from './approvals.js';
11
+ import type { CommittedSpend } from './auditor.js';
12
+ import type { Market, ProcurementNeed, ProcurementOutcome } from './types.js';
13
+ export interface ProcurerConfig {
14
+ agentKeys: AgentKeys;
15
+ mandate: SpendMandate;
16
+ approvalAbove?: number;
17
+ policy: SpendPolicy;
18
+ ladder?: AutonomyLadder;
19
+ orgLedger?: OrgSpendLedger;
20
+ kernelCtx: VerificationContext;
21
+ market: Market;
22
+ approvals: ApprovalInbox;
23
+ audit?: AuditLog;
24
+ }
25
+ interface PurchaseLine {
26
+ needId: string;
27
+ vendor: string;
28
+ paid: number;
29
+ baseline: number;
30
+ txnId: string;
31
+ }
32
+ export declare class ProcurerAgent {
33
+ private readonly cfg;
34
+ private purchases;
35
+ private committed;
36
+ constructor(cfg: ProcurerConfig);
37
+ private scope;
38
+ private complianceFailure;
39
+ private intentFor;
40
+ run(needs: ProcurementNeed[]): Promise<ProcurementOutcome[]>;
41
+ source(need: ProcurementNeed): Promise<ProcurementOutcome>;
42
+ executeApproved(approvalId: string, approval: SignedApproval): Promise<ProcurementOutcome>;
43
+ /** The signed {intent, mandate} pairs this agent actually committed — the
44
+ * Auditor's input. Surfacing them lets L3 oversight reconcile real output. */
45
+ committedSpends(): CommittedSpend[];
46
+ savingsReport(): {
47
+ lines: PurchaseLine[];
48
+ totalSaved: number;
49
+ totalPaid: number;
50
+ chainValid: boolean;
51
+ };
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=procurer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procurer.d.ts","sourceRoot":"","sources":["../src/procurer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACoB,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EACjD,KAAK,mBAAmB,EACjD,MAAM,aAAa,CAAC;AACrB,OAAO,EACe,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAC/E,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,kBAAk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vG"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * procurer.ts — The Procurer: first autonomous agent on the Mandate OS.
3
+ * RFQ across vendors, COMPLIANCE-FILTERED sourcing (a cheaper off-policy
4
+ * vendor is refused, not bought), tri-state execution through the policy
5
+ * engine, signed-approval workflow, and a savings report where every claimed
6
+ * saving resolves to a signed transaction id in the hash-chained audit log.
7
+ */
8
+ import { createTransactionIntent, } from '@kyaki/core';
9
+ import { evaluateWithPolicy, } from '@kyaki/policy';
10
+ import { verifyApproval } from './approvals.js';
11
+ export class ProcurerAgent {
12
+ cfg;
13
+ purchases = [];
14
+ committed = [];
15
+ constructor(cfg) {
16
+ this.cfg = cfg;
17
+ }
18
+ scope() { return this.cfg.mandate.credentialSubject.scope; }
19
+ complianceFailure(offer, need) {
20
+ const scope = this.scope();
21
+ if (offer.currency !== scope.currency)
22
+ return 'CURRENCY_MISMATCH';
23
+ if (scope.merchantAllowlist && scope.merchantAllowlist.length > 0 && !scope.merchantAllowlist.includes(offer.vendor)) {
24
+ return 'MERCHANT_NOT_ALLOWED';
25
+ }
26
+ if (offer.price > scope.maxPerTransaction)
27
+ return 'AMOUNT_EXCEEDS_PER_TXN_CAP';
28
+ if (need.maxBudget !== undefined && offer.price > need.maxBudget)
29
+ return 'OVER_NEED_BUDGET';
30
+ return null;
31
+ }
32
+ intentFor(offer, need) {
33
+ return createTransactionIntent({
34
+ agent: this.cfg.agentKeys,
35
+ mandateId: this.cfg.mandate.id,
36
+ merchant: offer.vendor,
37
+ amount: offer.price,
38
+ currency: offer.currency,
39
+ ...(need.category ? { category: need.category } : {}),
40
+ description: need.description,
41
+ ...(this.cfg.kernelCtx.now ? { now: this.cfg.kernelCtx.now } : {}),
42
+ });
43
+ }
44
+ async run(needs) {
45
+ const outcomes = [];
46
+ for (const need of needs)
47
+ outcomes.push(await this.source(need));
48
+ return outcomes;
49
+ }
50
+ async source(need) {
51
+ const audit = this.cfg.audit;
52
+ const offers = [...(await this.cfg.market.offersFor(need.id))].sort((a, b) => a.price - b.price);
53
+ const compliant = [];
54
+ const skipped = [];
55
+ for (const offer of offers) {
56
+ const failure = this.complianceFailure(offer, need);
57
+ if (failure === null)
58
+ compliant.push(offer);
59
+ else
60
+ skipped.push({ vendor: offer.vendor, price: offer.price, reason: failure });
61
+ }
62
+ if (compliant.length === 0) {
63
+ audit?.append({ type: 'procurement.refused', needId: need.id, description: need.description, skipped });
64
+ return { need, status: 'no_compliant_vendor', skippedNonCompliant: skipped };
65
+ }
66
+ const best = compliant[0];
67
+ const baseline = compliant[compliant.length - 1].price;
68
+ const temptations = skipped.filter((s) => s.price < best.price);
69
+ const intent = this.intentFor(best, need);
70
+ const result = await evaluateWithPolicy({
71
+ policy: this.cfg.policy, mandate: this.cfg.mandate, intent,
72
+ ...(this.cfg.approvalAbove !== undefined ? { approvalAbove: this.cfg.approvalAbove } : {}),
73
+ ...(this.cfg.ladder ? { ladder: this.cfg.ladder } : {}),
74
+ ...(this.cfg.orgLedger ? { orgLedger: this.cfg.orgLedger } : {}),
75
+ kernelCtx: this.cfg.kernelCtx,
76
+ });
77
+ if (result.decision === 'allow') {
78
+ this.purchases.push({ needId: need.id, vendor: best.vendor, paid: best.price, baseline, txnId: intent.id });
79
+ this.committed.push({ intent, mandate: this.cfg.mandate });
80
+ audit?.append({ type: 'procurement.purchased', needId: need.id, vendor: best.vendor, amount: best.price, currency: best.currency, txnId: intent.id });
81
+ return { need, status: 'purchased', offer: best, txnId: intent.id, ...(temptations.length > 0 ? { skippedNonCompliant: temptations } : {}) };
82
+ }
83
+ if (result.decision === 'escalate') {
84
+ const request = this.cfg.approvals.submit({ intent, mandate: this.cfg.mandate, need, offer: best, reason: result.policy.reasons.join(',') });
85
+ audit?.append({ type: 'procurement.escalated', needId: need.id, vendor: best.vendor, amount: best.price, approvalId: request.id, intentId: intent.id });
86
+ return { need, status: 'pending_approval', offer: best, approvalId: request.id, ...(temptations.length > 0 ? { skippedNonCompliant: temptations } : {}) };
87
+ }
88
+ audit?.append({ type: 'procurement.deferred', needId: need.id, vendor: best.vendor, amount: best.price, reasons: [...result.kernel.reasons, ...result.policy.reasons] });
89
+ return { need, status: 'deferred', offer: best, reasons: [...result.kernel.reasons, ...result.policy.reasons] };
90
+ }
91
+ async executeApproved(approvalId, approval) {
92
+ const request = this.cfg.approvals.get(approvalId);
93
+ if (!request)
94
+ throw new Error(`No approval request ${approvalId}`);
95
+ if (!verifyApproval(approval) || approval.intentId !== request.intent.id) {
96
+ return { need: request.need, status: 'deferred', reasons: ['APPROVAL_SIGNATURE_INVALID'] };
97
+ }
98
+ if (!this.cfg.approvals.markExecuted(approvalId)) {
99
+ return { need: request.need, status: 'deferred', reasons: ['ALREADY_EXECUTED'] };
100
+ }
101
+ const result = await evaluateWithPolicy({
102
+ policy: this.cfg.policy, mandate: this.cfg.mandate, intent: request.intent,
103
+ ...(this.cfg.approvalAbove !== undefined ? { approvalAbove: this.cfg.approvalAbove } : {}),
104
+ humanApproval: approval,
105
+ ...(this.cfg.ladder ? { ladder: this.cfg.ladder } : {}),
106
+ ...(this.cfg.orgLedger ? { orgLedger: this.cfg.orgLedger } : {}),
107
+ kernelCtx: this.cfg.kernelCtx,
108
+ });
109
+ if (result.decision !== 'allow') {
110
+ this.cfg.audit?.append({ type: 'approval.execution_denied', approvalId, intentId: request.intent.id, reasons: [...result.kernel.reasons, ...result.policy.reasons] });
111
+ return { need: request.need, status: 'deferred', offer: request.offer, reasons: [...result.kernel.reasons, ...result.policy.reasons] };
112
+ }
113
+ const offers = [...(await this.cfg.market.offersFor(request.need.id))]
114
+ .filter((o) => this.complianceFailure(o, request.need) === null)
115
+ .sort((a, b) => a.price - b.price);
116
+ const baseline = offers.length > 0 ? offers[offers.length - 1].price : request.offer.price;
117
+ this.purchases.push({ needId: request.need.id, vendor: request.offer.vendor, paid: request.offer.price, baseline, txnId: request.intent.id });
118
+ this.committed.push({ intent: request.intent, mandate: this.cfg.mandate });
119
+ this.cfg.audit?.append({ type: 'approval.executed', approvalId, intentId: request.intent.id, approvedBy: approval.approvedBy, approvalSignature: approval.signature, amount: request.offer.price, vendor: request.offer.vendor });
120
+ return { need: request.need, status: 'purchased', offer: request.offer, txnId: request.intent.id };
121
+ }
122
+ /** The signed {intent, mandate} pairs this agent actually committed — the
123
+ * Auditor's input. Surfacing them lets L3 oversight reconcile real output. */
124
+ committedSpends() {
125
+ return [...this.committed];
126
+ }
127
+ savingsReport() {
128
+ const audit = this.cfg.audit;
129
+ const chainValid = audit ? audit.verifyChain() : false;
130
+ const provenTxnIds = new Set((audit?.entries() ?? [])
131
+ .filter((e) => e.event.type === 'procurement.purchased' || e.event.type === 'approval.executed')
132
+ .map((e) => e.event.txnId ?? e.event.intentId));
133
+ const lines = this.purchases.filter((p) => chainValid && provenTxnIds.has(p.txnId));
134
+ return {
135
+ lines,
136
+ totalSaved: lines.reduce((s, l) => s + (l.baseline - l.paid), 0),
137
+ totalPaid: lines.reduce((s, l) => s + l.paid, 0),
138
+ chainValid,
139
+ };
140
+ }
141
+ }
142
+ //# sourceMappingURL=procurer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procurer.js","sourceRoot":"","sources":["../src/procurer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,uBAAuB,GAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAA2C,MAAM,gBAAgB,CAAC;AAyBzF,MAAM,OAAO,aAAa;IAIK;IAHrB,SAAS,GAAmB,EAAE,CAAC;IAC/B,SAAS,GAAqB,EAAE,CAAC;IAEzC,YAA6B,GAAmB;QAAnB,QAAG,GAAH,GAAG,CAAgB;IAAG,CAAC;IAE5C,KAAK,KAAK,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAE5D,iBAAiB,CAAC,KAAkB,EAAE,IAAqB;QACjE,MAAM,KAAK,GAAG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AmB,CAAC;aAC/F,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAAC,CAAC,KAA+C,CAAC,KAAK,IAAK,CAAC,CAAC,KAA+B,CAAC,QAAQ,CAAC,CACvH,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACpF,OAAO;YACL,KAAK;YACL,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAChE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAChD,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * steward.ts — The Steward: KYA's fourth agent, and the only one that acts on
3
+ * the PRINCIPAL's key.
4
+ *
5
+ * Where the Procurer pushes money outward and the Treasurer moves the balance
6
+ * sheet (both under DELEGATED authority), and the Auditor merely observes, the
7
+ * Steward GRANTS and REVOKES authority itself. It operationalizes KYA's third
8
+ * pillar — "authorization, *revocation*, and audit" — the one with no agent
9
+ * until now. It spends nothing.
10
+ *
11
+ * Two motions:
12
+ * - issueFor(target) — compile a scoped mandate from org policy (L1
13
+ * `compileScope`) and sign it with the principal's key (L0 `issueMandate`),
14
+ * so delegations are born from policy-as-code, not by hand.
15
+ * - govern(report) — read the Auditor's verdict (`report.demoted`, the
16
+ * provably-misbehaving agents) and REVOKE their mandates in the kernel's
17
+ * live revocation registry. The next spend on a revoked mandate is denied
18
+ * by the kernel (`MANDATE_REVOKED`). The Auditor adjusts the autonomy TIER;
19
+ * the Steward terminates the AUTHORITY. Detect → respond, closed.
20
+ *
21
+ * Every issuance and revocation appends to the Steward's own hash-chained
22
+ * governance log, and `attest()` signs its head — so authority changes are
23
+ * themselves tamper-evident, exactly like a mandate, an intent, or an audit.
24
+ */
25
+ import { type AuditLog, type Identity, type RevocationStore, type SpendMandate } from '@kyaki/core';
26
+ import { type SpendPolicy } from '@kyaki/policy';
27
+ import type { AuditReport } from './auditor.js';
28
+ export type AuthorityActionKind = 'issued' | 'revoked' | 'noop';
29
+ export interface AuthorityAction {
30
+ kind: AuthorityActionKind;
31
+ agentDid: string;
32
+ mandateId?: string;
33
+ reasons: string[];
34
+ /** Present on `issued` — the freshly signed delegation. */
35
+ mandate?: SpendMandate;
36
+ }
37
+ export interface GovernanceAttestation {
38
+ type: 'KyaGovernanceAttestation';
39
+ steward: string;
40
+ chainHead: string;
41
+ at: string;
42
+ signature: string;
43
+ }
44
+ /** Re-check a governance attestation offline — tampering with the chain head or
45
+ * the timestamp invalidates it, exactly like a mandate or an audit. */
46
+ export declare function verifyGovernanceAttestation(att: GovernanceAttestation): boolean;
47
+ export interface StewardConfig {
48
+ /** The principal's key — issues and revokes delegated authority. */
49
+ principal: Identity;
50
+ /** The Steward's own key — signs governance attestations. */
51
+ stewardKeys: Identity;
52
+ policy: SpendPolicy;
53
+ /** The kernel's LIVE revocation registry — must be the same instance the
54
+ * agents' VerificationContext consults, or revocation won't bite. */
55
+ revocations: RevocationStore;
56
+ /** The Steward's own lifecycle chain; every issue/revoke is anchored here. */
57
+ governance?: AuditLog;
58
+ now?: Date;
59
+ }
60
+ export declare class Steward {
61
+ private readonly cfg;
62
+ private readonly byAgent;
63
+ private readonly owner;
64
+ constructor(cfg: StewardConfig);
65
+ private now;
66
+ /** Issue a policy-derived, principal-signed mandate for an agent/role. */
67
+ issueFor(target: {
68
+ agentDid: string;
69
+ role?: string;
70
+ }, opts?: {
71
+ validForSeconds?: number;
72
+ }): AuthorityAction;
73
+ /** Register an externally-issued mandate so the Steward can later revoke it. */
74
+ track(mandate: SpendMandate): void;
75
+ mandatesOf(agentDid: string): string[];
76
+ isRevoked(mandateId: string): Promise<boolean>;
77
+ /** Revoke a single mandate in the kernel's live registry, audited. */
78
+ revoke(mandateId: string, reasons: string[]): Promise<AuthorityAction>;
79
+ /**
80
+ * Respond to an audit: revoke the mandates of every agent the Auditor
81
+ * provably caught (`report.demoted`). The Steward enacts the consequence the
82
+ * Auditor's demotion only signals. Idempotent — an already-revoked mandate is
83
+ * a noop, so re-running the same report never double-revokes.
84
+ */
85
+ govern(report: Pick<AuditReport, 'demoted' | 'findings'>): Promise<AuthorityAction[]>;
86
+ /** Sign the governance chain head — the authority-change history, verifiable. */
87
+ attest(): GovernanceAttestation;
88
+ }
89
+ //# sourceMappingURL=steward.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steward.d.ts","sourceRoot":"","sources":["../src/steward.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAEL,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EACtE,MAAM,aAAa,CAAC;AACrB,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,MAAM,CAA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GAAG,UAAU,CAAC,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAoB3F,iFAAiF;IACjF,MAAM,IAAI,qBAAqB;CAWhC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * steward.ts — The Steward: KYA's fourth agent, and the only one that acts on
3
+ * the PRINCIPAL's key.
4
+ *
5
+ * Where the Procurer pushes money outward and the Treasurer moves the balance
6
+ * sheet (both under DELEGATED authority), and the Auditor merely observes, the
7
+ * Steward GRANTS and REVOKES authority itself. It operationalizes KYA's third
8
+ * pillar — "authorization, *revocation*, and audit" — the one with no agent
9
+ * until now. It spends nothing.
10
+ *
11
+ * Two motions:
12
+ * - issueFor(target) — compile a scoped mandate from org policy (L1
13
+ * `compileScope`) and sign it with the principal's key (L0 `issueMandate`),
14
+ * so delegations are born from policy-as-code, not by hand.
15
+ * - govern(report) — read the Auditor's verdict (`report.demoted`, the
16
+ * provably-misbehaving agents) and REVOKE their mandates in the kernel's
17
+ * live revocation registry. The next spend on a revoked mandate is denied
18
+ * by the kernel (`MANDATE_REVOKED`). The Auditor adjusts the autonomy TIER;
19
+ * the Steward terminates the AUTHORITY. Detect → respond, closed.
20
+ *
21
+ * Every issuance and revocation appends to the Steward's own hash-chained
22
+ * governance log, and `attest()` signs its head — so authority changes are
23
+ * themselves tamper-evident, exactly like a mandate, an intent, or an audit.
24
+ */
25
+ import { canonicalBytes, fromBase58, issueMandate, publicKeyFromDid, sign, toBase58, verifySignature, } from '@kyaki/core';
26
+ import { compileScope } from '@kyaki/policy';
27
+ const GENESIS = '0'.repeat(64);
28
+ /** Re-check a governance attestation offline — tampering with the chain head or
29
+ * the timestamp invalidates it, exactly like a mandate or an audit. */
30
+ export function verifyGovernanceAttestation(att) {
31
+ try {
32
+ const { signature, ...doc } = att;
33
+ return verifySignature(fromBase58(signature), canonicalBytes(doc), publicKeyFromDid(att.steward));
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ }
39
+ export class Steward {
40
+ cfg;
41
+ byAgent = new Map(); // agentDid -> mandateIds
42
+ owner = new Map(); // mandateId -> agentDid
43
+ constructor(cfg) {
44
+ this.cfg = cfg;
45
+ }
46
+ now() { return this.cfg.now ?? new Date(); }
47
+ /** Issue a policy-derived, principal-signed mandate for an agent/role. */
48
+ issueFor(target, opts = {}) {
49
+ const compiled = compileScope(this.cfg.policy, {
50
+ agentDid: target.agentDid, ...(target.role ? { role: target.role } : {}),
51
+ });
52
+ const validForSeconds = opts.validForSeconds ?? compiled.validForSeconds;
53
+ const mandate = issueMandate({
54
+ principal: this.cfg.principal, agentDid: target.agentDid, scope: compiled.scope,
55
+ ...(this.cfg.now ? { validFrom: this.cfg.now } : {}),
56
+ ...(validForSeconds !== undefined ? { validForSeconds } : {}),
57
+ });
58
+ this.track(mandate);
59
+ this.cfg.governance?.append({ type: 'authority.issued', mandateId: mandate.id, agentDid: target.agentDid, ruleId: compiled.ruleId }, this.now());
60
+ return { kind: 'issued', agentDid: target.agentDid, mandateId: mandate.id, reasons: [compiled.ruleId], mandate };
61
+ }
62
+ /** Register an externally-issued mandate so the Steward can later revoke it. */
63
+ track(mandate) {
64
+ const agentDid = mandate.credentialSubject.id;
65
+ this.owner.set(mandate.id, agentDid);
66
+ const set = this.byAgent.get(agentDid) ?? new Set();
67
+ set.add(mandate.id);
68
+ this.byAgent.set(agentDid, set);
69
+ }
70
+ mandatesOf(agentDid) {
71
+ return [...(this.byAgent.get(agentDid) ?? [])];
72
+ }
73
+ isRevoked(mandateId) {
74
+ return this.cfg.revocations.isRevoked(mandateId);
75
+ }
76
+ /** Revoke a single mandate in the kernel's live registry, audited. */
77
+ async revoke(mandateId, reasons) {
78
+ const agentDid = this.owner.get(mandateId) ?? '—';
79
+ await this.cfg.revocations.revoke(mandateId);
80
+ this.cfg.governance?.append({ type: 'authority.revoked', mandateId, agentDid, reasons }, this.now());
81
+ return { kind: 'revoked', agentDid, mandateId, reasons };
82
+ }
83
+ /**
84
+ * Respond to an audit: revoke the mandates of every agent the Auditor
85
+ * provably caught (`report.demoted`). The Steward enacts the consequence the
86
+ * Auditor's demotion only signals. Idempotent — an already-revoked mandate is
87
+ * a noop, so re-running the same report never double-revokes.
88
+ */
89
+ async govern(report) {
90
+ const actions = [];
91
+ for (const agentDid of report.demoted) {
92
+ const reasons = report.findings.filter((f) => f.agentDid === agentDid).map((f) => f.code);
93
+ const mandateIds = this.mandatesOf(agentDid);
94
+ if (mandateIds.length === 0) {
95
+ actions.push({ kind: 'noop', agentDid, reasons: ['NO_TRACKED_MANDATE'] });
96
+ continue;
97
+ }
98
+ for (const mandateId of mandateIds) {
99
+ if (await this.cfg.revocations.isRevoked(mandateId)) {
100
+ actions.push({ kind: 'noop', agentDid, mandateId, reasons: ['ALREADY_REVOKED'] });
101
+ continue;
102
+ }
103
+ actions.push(await this.revoke(mandateId, reasons.length > 0 ? reasons : ['AGENT_DEMOTED']));
104
+ }
105
+ }
106
+ return actions;
107
+ }
108
+ /** Sign the governance chain head — the authority-change history, verifiable. */
109
+ attest() {
110
+ const entries = this.cfg.governance?.entries() ?? [];
111
+ const chainHead = entries.length > 0 ? entries[entries.length - 1].hash : GENESIS;
112
+ const doc = {
113
+ type: 'KyaGovernanceAttestation',
114
+ steward: this.cfg.stewardKeys.did,
115
+ chainHead,
116
+ at: this.now().toISOString(),
117
+ };
118
+ return { ...doc, signature: toBase58(sign(canonicalBytes(doc), this.cfg.stewardKeys.privateKey)) };
119
+ }
120
+ }
121
+ //# sourceMappingURL=steward.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steward.js","sourceRoot":"","sources":["../src/steward.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,GAE5F,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAG/D,MAAM,OAAO,GAAG,GA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Ac,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;IACrG,CAAC;CACF"}
@@ -0,0 +1,134 @@
1
+ import { type AgentKeys, type AuditLog, type Identity, type SpendMandate, type TransactionIntent, type VerificationContext } from '@kyaki/core';
2
+ import { type AutonomyLadder, type OrgSpendLedger, type SpendPolicy } from '@kyaki/policy';
3
+ import { type SignedApproval } from './approvals.js';
4
+ export type AccountType = 'operating' | 'reserve' | 'yield';
5
+ export interface Account {
6
+ id: string;
7
+ currency: string;
8
+ balance: number;
9
+ type: AccountType;
10
+ /** Operating accounts keep at least this much; the excess is sweepable. */
11
+ minBuffer?: number;
12
+ }
13
+ export interface Obligation {
14
+ id: string;
15
+ payee: string;
16
+ category: string;
17
+ amount: number;
18
+ currency: string;
19
+ /** Epoch ms. Funded only once `dueAt <= now`. */
20
+ dueAt: number;
21
+ }
22
+ export interface FXProvider {
23
+ /** Units of `to` per one unit of `from`. */
24
+ rate(from: string, to: string): number;
25
+ }
26
+ /** A deterministic FX desk for demos and tests. */
27
+ export declare class StaticFX implements FXProvider {
28
+ private readonly table;
29
+ constructor(table: Record<string, number>);
30
+ rate(from: string, to: string): number;
31
+ }
32
+ export type ActionKind = 'obligation_payment' | 'fx_conversion' | 'liquidity_sweep';
33
+ export type ActionStatus = 'committed' | 'pending_approval' | 'denied' | 'skipped';
34
+ export interface TreasuryAction {
35
+ kind: ActionKind;
36
+ status: ActionStatus;
37
+ accountId: string;
38
+ payee: string;
39
+ category: string;
40
+ /** Amount actually moved, in the SOURCE account's (held) currency. */
41
+ amount: number;
42
+ currency: string;
43
+ obligationId?: string;
44
+ intentId?: string;
45
+ approvalId?: string;
46
+ reasons?: string[];
47
+ }
48
+ export interface CashPosition {
49
+ baseCurrency: string;
50
+ byCurrency: Record<string, number>;
51
+ totalInBase: number;
52
+ nearTermObligationsInBase: number;
53
+ netLiquidityInBase: number;
54
+ }
55
+ export type MovementStatus = 'pending' | 'approved' | 'executing' | 'executed' | 'rejected' | 'failed';
56
+ export interface PendingMovement {
57
+ id: string;
58
+ intent: TransactionIntent;
59
+ mandate: SpendMandate;
60
+ kind: ActionKind;
61
+ accountId: string;
62
+ payee: string;
63
+ category: string;
64
+ amount: number;
65
+ currency: string;
66
+ obligationId?: string;
67
+ reason: string;
68
+ submittedAt: string;
69
+ status: MovementStatus;
70
+ decidedBy?: string;
71
+ decidedAt?: string;
72
+ failureReasons?: string[];
73
+ }
74
+ export declare class TreasuryApprovalInbox {
75
+ private movements;
76
+ submit(input: Omit<PendingMovement, 'id' | 'submittedAt' | 'status'>): PendingMovement;
77
+ get(id: string): PendingMovement | undefined;
78
+ pending(): PendingMovement[];
79
+ all(): PendingMovement[];
80
+ /** The CFO countersigns a parked movement with their own key. */
81
+ approve(id: string, approver: Identity): SignedApproval;
82
+ reject(id: string, approver: Identity): PendingMovement;
83
+ /** Atomic exactly-once gate: 'approved' -> 'executing'. True iff WE won. */
84
+ claimExecution(id: string): boolean;
85
+ confirmExecuted(id: string): void;
86
+ /** Transient deny: stays retryable. */
87
+ revertToApproved(id: string, reasons: string[]): void;
88
+ /** Security failure: terminal AND visible. */
89
+ markFailed(id: string, reasons: string[]): void;
90
+ }
91
+ export interface TreasurerConfig {
92
+ agentKeys: AgentKeys;
93
+ mandate: SpendMandate;
94
+ policy: SpendPolicy;
95
+ accounts: Account[];
96
+ fx: FXProvider;
97
+ baseCurrency: string;
98
+ approvalAbove?: number;
99
+ ladder?: AutonomyLadder;
100
+ orgLedger?: OrgSpendLedger;
101
+ kernelCtx: VerificationContext;
102
+ approvals: TreasuryApprovalInbox;
103
+ audit?: AuditLog;
104
+ }
105
+ export declare class Treasurer {
106
+ private readonly cfg;
107
+ private readonly accounts;
108
+ constructor(cfg: TreasurerConfig);
109
+ account(id: string): Account | undefined;
110
+ /** The signed {intent, mandate} pairs this agent committed — Auditor input. */
111
+ committedSpends(): {
112
+ intent: TransactionIntent;
113
+ mandate: SpendMandate;
114
+ }[];
115
+ private committed;
116
+ private operatingFor;
117
+ private intentFor;
118
+ /**
119
+ * The shared movement pipeline. Balance is debited ONLY on a committed
120
+ * allow. On escalate the movement parks (nothing debited); on deny it
121
+ * aborts (nothing debited). evaluateWithPolicy handles the org-exposure
122
+ * reserve/release and the atomic kernel commit internally.
123
+ */
124
+ private execute;
125
+ /** Fund a single obligation, routing through FX if we don't hold its currency. */
126
+ private fundObligation;
127
+ /** A full treasury cycle: pay due obligations FIRST, then sweep idle cash. */
128
+ runCycle(obligations: Obligation[], now?: Date): Promise<TreasuryAction[]>;
129
+ /** Finalize an escalated movement with a signed CFO approval (two-phase). */
130
+ applyApproval(approvalId: string, approval: SignedApproval): Promise<TreasuryAction>;
131
+ /** Multi-currency cash position, converted to base, net of near-term obligations. */
132
+ cashPosition(obligations: Obligation[], horizonMs?: number, now?: Date): CashPosition;
133
+ }
134
+ //# sourceMappingURL=treasury.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treasury.d.ts","sourceRoot":"","sources":["../src/treasury.ts"],"names":[],"mappings":"AAyBA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAgC,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAInF,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC;IAClB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CA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