@agenticprimitives/coordination 0.0.0-alpha.2 → 0.0.0-alpha.20

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 (48) hide show
  1. package/README.md +2 -0
  2. package/dist/attribution/index.d.ts +64 -0
  3. package/dist/attribution/index.d.ts.map +1 -0
  4. package/dist/attribution/index.js +141 -0
  5. package/dist/attribution/index.js.map +1 -0
  6. package/dist/attribution/scenarios.d.ts +26 -0
  7. package/dist/attribution/scenarios.d.ts.map +1 -0
  8. package/dist/attribution/scenarios.js +59 -0
  9. package/dist/attribution/scenarios.js.map +1 -0
  10. package/dist/core/commands.d.ts +53 -3
  11. package/dist/core/commands.d.ts.map +1 -1
  12. package/dist/core/commands.js +6 -0
  13. package/dist/core/commands.js.map +1 -1
  14. package/dist/core/events.d.ts +45 -3
  15. package/dist/core/events.d.ts.map +1 -1
  16. package/dist/core/ids.d.ts +4 -0
  17. package/dist/core/ids.d.ts.map +1 -1
  18. package/dist/core/ids.js +2 -0
  19. package/dist/core/ids.js.map +1 -1
  20. package/dist/core/index.d.ts +3 -3
  21. package/dist/core/index.d.ts.map +1 -1
  22. package/dist/core/index.js +1 -1
  23. package/dist/core/index.js.map +1 -1
  24. package/dist/core/reducer.d.ts +17 -2
  25. package/dist/core/reducer.d.ts.map +1 -1
  26. package/dist/core/reducer.js +302 -1
  27. package/dist/core/reducer.js.map +1 -1
  28. package/dist/decisions/index.d.ts +2 -8
  29. package/dist/decisions/index.d.ts.map +1 -1
  30. package/dist/decisions/index.js +1 -1
  31. package/dist/decisions/index.js.map +1 -1
  32. package/dist/decisions/types.d.ts +49 -1
  33. package/dist/decisions/types.d.ts.map +1 -1
  34. package/dist/index.d.ts +7 -3
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/participation/types.d.ts +1 -1
  39. package/dist/participation/types.d.ts.map +1 -1
  40. package/dist/projections/continuation.d.ts +53 -0
  41. package/dist/projections/continuation.d.ts.map +1 -0
  42. package/dist/projections/continuation.js +43 -0
  43. package/dist/projections/continuation.js.map +1 -0
  44. package/dist/projections/index.d.ts +2 -0
  45. package/dist/projections/index.d.ts.map +1 -1
  46. package/dist/projections/index.js +5 -1
  47. package/dist/projections/index.js.map +1 -1
  48. package/package.json +19 -6
@@ -1 +1 @@
1
- {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/core/ids.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAY/F,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,cAAsB,EAAE,KAAa;QAC/C,KAAK,CAAC,2CAA2C,cAAc,WAAW,KAAK,GAAG,CAAC,CAAC;IACtF,CAAC;CACF;AAED,SAAS,IAAI,CAAmB,MAAS,EAAE,MAAc;IACvD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,MAAM,CAAmB,MAAS,EAAE,KAAa;IACxD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAC/D,MAAM,IAAI,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,KAAwB,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAc,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAc,EAAqB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAsB,EAA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AAG,CAAC,KAAa,EAAqB,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpG,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAa,EAAsB,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAmB,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAgB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAgB,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAoB,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAc,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC"}
@@ -1,11 +1,11 @@
1
- export type { AllocationId, CommitmentId, CoordinationPlanId, EndeavorId, EndeavorRequestId, ParticipationId, PlanStepId, ProposalId, RecommendationId, } from './ids.js';
2
- export { CoordinationIdError, assertAllocationId, assertCommitmentId, assertCoordinationPlanId, assertEndeavorId, assertEndeavorRequestId, assertParticipationId, assertPlanStepId, assertProposalId, assertRecommendationId, makeAllocationId, makeCommitmentId, makeCoordinationPlanId, makeEndeavorId, makeEndeavorRequestId, makeParticipationId, makePlanStepId, makeProposalId, makeRecommendationId, } from './ids.js';
1
+ export type { AllocationId, CommitmentId, CoordinationPlanId, EndeavorId, EndeavorRequestId, ParticipationId, PlanStepId, ProposalId, RecommendationId, DecisionId, } from './ids.js';
2
+ export { CoordinationIdError, assertAllocationId, assertCommitmentId, assertCoordinationPlanId, assertEndeavorId, assertEndeavorRequestId, assertParticipationId, assertPlanStepId, assertProposalId, assertRecommendationId, makeAllocationId, makeCommitmentId, makeCoordinationPlanId, makeEndeavorId, makeEndeavorRequestId, makeParticipationId, makePlanStepId, makeProposalId, makeRecommendationId, makeDecisionId, assertDecisionId, } from './ids.js';
3
3
  export type { ContextRef, CoordinationContextSnapshotV1, EndeavorEntryPoint, EndeavorLifecycle, EndeavorRelationKind, EndeavorRelationV1, EndeavorRequestV1, EndeavorV1, ExternalObjectBindingV1, ExternalSyncMode, OutcomeCriterionKind, OutcomeCriterionV1, OutcomeSpecificationV1, } from './types.js';
4
4
  export { COORDINATION_CLASS_IRIS } from './types.js';
5
5
  export type { CoordinationCommandV1 } from './commands.js';
6
6
  export { COORDINATION_COMMAND_KINDS } from './commands.js';
7
7
  export type { CoordinationEventV1 } from './events.js';
8
- export type { CommandValidationResult, CoordinationStateV1, EndeavorRequestStatus, SatisfiedStepV1, } from './reducer.js';
8
+ export type { AttachedRunV1, CommandValidationResult, CoordinationStateV1, EndeavorRequestStatus, SatisfiedStepV1, } from './reducer.js';
9
9
  export { CoordinationEventError, applyCoordinationEvent, initialCoordinationState, planKey, validateCoordinationCommand, } from './reducer.js';
10
10
  export type { ProvenanceActivitySummary, ProvenanceCorrespondenceSummary, ProvenanceEntitySummary, ProvenanceInputsV1, } from './provenance.js';
11
11
  export { deriveProvenanceInputs } from './provenance.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ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zB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,4 +1,4 @@
1
- export { CoordinationIdError, assertAllocationId, assertCommitmentId, assertCoordinationPlanId, assertEndeavorId, assertEndeavorRequestId, assertParticipationId, assertPlanStepId, assertProposalId, assertRecommendationId, makeAllocationId, makeCommitmentId, makeCoordinationPlanId, makeEndeavorId, makeEndeavorRequestId, makeParticipationId, makePlanStepId, makeProposalId, makeRecommendationId, } from './ids.js';
1
+ export { CoordinationIdError, assertAllocationId, assertCommitmentId, assertCoordinationPlanId, assertEndeavorId, assertEndeavorRequestId, assertParticipationId, assertPlanStepId, assertProposalId, assertRecommendationId, makeAllocationId, makeCommitmentId, makeCoordinationPlanId, makeEndeavorId, makeEndeavorRequestId, makeParticipationId, makePlanStepId, makeProposalId, makeRecommendationId, makeDecisionId, assertDecisionId, } from './ids.js';
2
2
  export { COORDINATION_CLASS_IRIS } from './types.js';
3
3
  export { COORDINATION_COMMAND_KINDS } from './commands.js';
4
4
  export { CoordinationEventError, applyCoordinationEvent, initialCoordinationState, planKey, validateCoordinationCommand, } from './reducer.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAiBlB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAS3D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,OAAO,EACP,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAiBlB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAU3D,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,OAAO,EACP,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,9 +1,9 @@
1
- import type { Address } from '@agenticprimitives/types';
1
+ import type { Address, Hex32 } from '@agenticprimitives/types';
2
2
  import type { EntityRef } from '@agenticprimitives/situations';
3
3
  import type { PlanStepId } from './ids.js';
4
4
  import type { EndeavorRequestV1, EndeavorV1, OutcomeSpecificationV1 } from './types.js';
5
5
  import type { CoordinationCommandV1 } from './commands.js';
6
- import type { RecommendationV1 } from '../decisions/types.js';
6
+ import type { DecisionRecordV1, DecisionRequestV1, RecommendationV1 } from '../decisions/types.js';
7
7
  import type { CoordinationEventV1 } from './events.js';
8
8
  import type { CoordinationPlanV1, PlanRevisionRef } from '../planning/types.js';
9
9
  import type { AllocationDecisionV1, ContributionCommitmentV1, ContributionProposalV1, EndeavorParticipationV1 } from '../participation/types.js';
@@ -32,6 +32,21 @@ export interface CoordinationStateV1 {
32
32
  milestones: Record<string, MilestoneAchievementV1>;
33
33
  satisfiedSteps: Record<string, SatisfiedStepV1>;
34
34
  recommendations: Record<string, RecommendationV1>;
35
+ /** Spec 393 — decisions raised for declared approvers, and EVERY record on each, in order (a quorum needs them all). */
36
+ decisionRequests: Record<string, DecisionRequestV1>;
37
+ decisions: Record<string, DecisionRecordV1[]>;
38
+ /** Spec 438 §3 — the harness runs a participant ATTACHED to this endeavor, keyed by runRef so a second
39
+ * attach of the same run is a no-op rather than a duplicate. Coordination stores the reference and the
40
+ * digest; it never reads the run record itself. */
41
+ attachedRuns: Record<string, AttachedRunV1>;
42
+ }
43
+ /** Spec 438 §3 — one run claimed by this endeavor. A REFERENCE: nothing here grants or proves anything about
44
+ * the run; it says a participant asserted the two belong together, and when. */
45
+ export interface AttachedRunV1 {
46
+ runRef: string;
47
+ recordDigest: Hex32;
48
+ attachedBy: Address;
49
+ attachedAt: string;
35
50
  }
36
51
  export declare function initialCoordinationState(): CoordinationStateV1;
37
52
  export type CommandValidationResult = {
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/core/reducer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAA+B,UAAU,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,kBAA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AEoD;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC7C;AAED;iFACiF;AACjF,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,KAAK,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,wBAAwB,IAAI,mBAAmB,CAe9D;AAED,MAAM,MAAM,uBAAuB,GAC/B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,mBAAmB,EAAE,CAAA;CAAE,GAC3C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAG5B;AAED,eAAO,MAAM,OAAO,WAAY,MAAM,YAAY,MAAM,KAAG,MAAiC,CAAC;AA0D7F,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,qBAAqB,GAC7B,uBAAuB,CAo4BzB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,mBAAmB,GACzB,mBAAmB,CAoarB"}
@@ -14,7 +14,10 @@ export function initialCoordinationState() {
14
14
  commitments: {},
15
15
  milestones: {},
16
16
  satisfiedSteps: {},
17
+ attachedRuns: {},
17
18
  recommendations: {},
19
+ decisionRequests: {},
20
+ decisions: {},
18
21
  };
19
22
  }
20
23
  export class CoordinationEventError extends Error {
@@ -48,7 +51,12 @@ function participationStatus(state, address) {
48
51
  }
49
52
  function isSteward(state, address) {
50
53
  const roles = activeRoles(state, address);
51
- return roles.has('coordinator') || roles.has('sponsor');
54
+ // Spec 382 — THE MANAGING PRINCIPAL STEWARDS ITS OWN ENDEAVOR. The organization acting through its own
55
+ // agent (ADR-0054) may invite and allocate on the endeavor it manages, exactly as its coordinator may;
56
+ // adoption asserted the coordinator's participation, never the organization's, so a member's offer
57
+ // could not be admitted by anyone at the organization's own door. Nothing here is authority: an invite
58
+ // or an allocation grants no capability (spec 332 §9 rule 1).
59
+ return roles.has('coordinator') || roles.has('sponsor') || state.endeavor?.managingPrincipal === address;
52
60
  }
53
61
  function endeavorContext(state, endeavorId) {
54
62
  if (!state.endeavor)
@@ -593,6 +601,136 @@ export function validateCoordinationCommand(state, command) {
593
601
  ],
594
602
  };
595
603
  }
604
+ // ═══ Spec 438 §3 ═══════════════════════════════════════════════════════════════════════════════
605
+ case 'AttachRun': {
606
+ const ctx = endeavorContext(state, command.endeavorId);
607
+ if ('reason' in ctx)
608
+ return reject(ctx.reason);
609
+ if (command.runRef.trim().length === 0)
610
+ return reject('attaching a run requires a runRef');
611
+ if (command.actor !== ctx.endeavor.managingPrincipal &&
612
+ participationStatus(state, command.actor) !== 'active') {
613
+ return reject('a run is attached by the managing principal or an active participant');
614
+ }
615
+ const already = state.attachedRuns[command.runRef];
616
+ if (already) {
617
+ // IDEMPOTENT, but only for the SAME record. Re-attaching the same run is the same assertion made
618
+ // twice. A different digest under the same runRef is a different claim and is refused rather than
619
+ // silently overwritten — the attached digest is how a reader tells whether it is the same record.
620
+ if (already.recordDigest !== command.recordDigest) {
621
+ return reject(`run ${command.runRef} is already attached with a different record digest`);
622
+ }
623
+ return { ok: true, events: [] };
624
+ }
625
+ return {
626
+ ok: true,
627
+ events: [
628
+ {
629
+ kind: 'RunAttached',
630
+ eventId: eventId(nextRevision, 'RunAttached'),
631
+ occurredAt: at,
632
+ revision: nextRevision,
633
+ endeavorId: command.endeavorId,
634
+ runRef: command.runRef,
635
+ recordDigest: command.recordDigest,
636
+ attachedBy: command.actor,
637
+ },
638
+ ],
639
+ };
640
+ }
641
+ case 'DischargeCommitment': {
642
+ const ctx = endeavorContext(state, command.endeavorId);
643
+ if ('reason' in ctx)
644
+ return reject(ctx.reason);
645
+ const c = state.commitments[command.commitmentId];
646
+ if (!c)
647
+ return reject(`unknown commitment ${command.commitmentId}`);
648
+ if (c.status !== 'active')
649
+ return reject(`commitment is ${c.status}; only an active commitment discharges`);
650
+ // The rule that gives a discharge its meaning: it CITES something. Without this a discharge is a
651
+ // participant saying "done", which is exactly the claim the evidence was supposed to support.
652
+ if (command.evidenceRefs.length === 0)
653
+ return reject('a discharge must cite receipt references or a satisfied plan step');
654
+ if (command.actor !== c.participant)
655
+ return reject('only the committing participant may discharge their own commitment');
656
+ return {
657
+ ok: true,
658
+ events: [
659
+ {
660
+ kind: 'CommitmentDischarged',
661
+ eventId: eventId(nextRevision, 'CommitmentDischarged'),
662
+ occurredAt: at,
663
+ revision: nextRevision,
664
+ endeavorId: command.endeavorId,
665
+ commitmentId: command.commitmentId,
666
+ evidenceRefs: command.evidenceRefs,
667
+ dischargedBy: command.actor,
668
+ },
669
+ ],
670
+ };
671
+ }
672
+ case 'DeclareBreach': {
673
+ const ctx = endeavorContext(state, command.endeavorId);
674
+ if ('reason' in ctx)
675
+ return reject(ctx.reason);
676
+ const c = state.commitments[command.commitmentId];
677
+ if (!c)
678
+ return reject(`unknown commitment ${command.commitmentId}`);
679
+ if (c.status !== 'active')
680
+ return reject(`commitment is ${c.status}; only an active commitment is breached`);
681
+ if (!isSteward(state, command.actor))
682
+ return reject('only a sponsor/coordinator may declare a breach');
683
+ // A BREACH IS A JUDGMENT ABOUT CONDUCT, so it needs a deadline that has actually passed — and a
684
+ // commitment with no deadline has nothing to be late for. Nothing in this reducer DERIVES a breach:
685
+ // the deadline passing is a precondition of the declaration, never the declaration itself.
686
+ if (!c.bounds?.deadline)
687
+ return reject('this commitment has no deadline; there is nothing to have missed');
688
+ if (!(Date.parse(at) > Date.parse(c.bounds.deadline))) {
689
+ return reject(`the deadline ${c.bounds.deadline} has not passed`);
690
+ }
691
+ return {
692
+ ok: true,
693
+ events: [
694
+ {
695
+ kind: 'CommitmentBreached',
696
+ eventId: eventId(nextRevision, 'CommitmentBreached'),
697
+ occurredAt: at,
698
+ revision: nextRevision,
699
+ endeavorId: command.endeavorId,
700
+ commitmentId: command.commitmentId,
701
+ declaredBy: command.actor,
702
+ ...(command.reason ? { reason: command.reason } : {}),
703
+ },
704
+ ],
705
+ };
706
+ }
707
+ case 'RecordLapse': {
708
+ const ctx = endeavorContext(state, command.endeavorId);
709
+ if ('reason' in ctx)
710
+ return reject(ctx.reason);
711
+ const c = state.commitments[command.commitmentId];
712
+ if (!c)
713
+ return reject(`unknown commitment ${command.commitmentId}`);
714
+ if (c.status !== 'active')
715
+ return reject(`commitment is ${c.status}; only an active commitment lapses`);
716
+ if (!isSteward(state, command.actor))
717
+ return reject('only a sponsor/coordinator may record a lapse');
718
+ return {
719
+ ok: true,
720
+ events: [
721
+ {
722
+ kind: 'CommitmentLapsed',
723
+ eventId: eventId(nextRevision, 'CommitmentLapsed'),
724
+ occurredAt: at,
725
+ revision: nextRevision,
726
+ endeavorId: command.endeavorId,
727
+ commitmentId: command.commitmentId,
728
+ recordedBy: command.actor,
729
+ ...(command.reason ? { reason: command.reason } : {}),
730
+ },
731
+ ],
732
+ };
733
+ }
596
734
  case 'RecordStepSatisfied': {
597
735
  const ctx = endeavorContext(state, command.endeavorId);
598
736
  if ('reason' in ctx)
@@ -770,6 +908,109 @@ export function validateCoordinationCommand(state, command) {
770
908
  ],
771
909
  };
772
910
  }
911
+ case 'RaiseDecisionRequest': {
912
+ const ctx = endeavorContext(state, command.endeavorId);
913
+ if ('reason' in ctx)
914
+ return reject(ctx.reason);
915
+ // Who may raise: the organization (its managing principal, or a steward acting as it) or an active participant.
916
+ if (command.actor !== ctx.endeavor.managingPrincipal && !isSteward(state, command.actor) && participationStatus(state, command.actor) !== 'active') {
917
+ return reject('only the managing principal, a steward or an active participant may raise a decision');
918
+ }
919
+ if (state.decisionRequests[command.decisionId])
920
+ return reject(`decision ${command.decisionId} already raised`);
921
+ const approvers = [...new Set(command.approvers.map((a) => a.toLowerCase()))];
922
+ if (approvers.length === 0)
923
+ return reject('a decision names at least one approver');
924
+ if (!approvers.every((a) => /^0x[0-9a-f]{40}$/.test(a)))
925
+ return reject('an approver is an address');
926
+ if (command.quorum !== undefined && (!Number.isInteger(command.quorum) || command.quorum < 1 || command.quorum > approvers.length))
927
+ return reject('quorum must be between 1 and the number of approvers');
928
+ if (!command.title.trim())
929
+ return reject('a decision has a title');
930
+ if (command.stepIds?.length) {
931
+ const plan = adoptedPlan(state);
932
+ const known = new Set(plan?.steps.map((st) => st.stepId) ?? []);
933
+ for (const id of command.stepIds)
934
+ if (!known.has(id))
935
+ return reject(`step ${id} is not in the adopted plan`);
936
+ }
937
+ const request = {
938
+ schema: 'apcoord/DecisionRequestV1',
939
+ decisionId: command.decisionId,
940
+ endeavorId: command.endeavorId,
941
+ decisionKind: command.decisionKind.trim() || 'decision',
942
+ title: command.title.trim(),
943
+ ...(command.summary?.trim() ? { summary: command.summary.trim() } : {}),
944
+ requestedBy: command.actor,
945
+ requirement: { schema: 'apcoord/ApprovalRequirementV1', approvers, ...(command.quorum !== undefined ? { quorum: command.quorum } : {}) },
946
+ scope: { ...(command.stepIds?.length ? { stepIds: [...command.stepIds] } : {}) },
947
+ requestedAt: at,
948
+ ...(command.dueAt ? { dueAt: command.dueAt } : {}),
949
+ status: 'pending',
950
+ };
951
+ return { ok: true, events: [{ kind: 'DecisionRequested', eventId: eventId(nextRevision, 'DecisionRequested'), endeavorId: command.endeavorId, decisionId: command.decisionId, request, occurredAt: at, revision: nextRevision }] };
952
+ }
953
+ case 'RecordDecision': {
954
+ const ctx = endeavorContext(state, command.endeavorId);
955
+ if ('reason' in ctx)
956
+ return reject(ctx.reason);
957
+ const request = state.decisionRequests[command.decisionId];
958
+ if (!request)
959
+ return reject(`unknown decision ${command.decisionId}`);
960
+ if (request.status !== 'pending')
961
+ return reject(`decision ${command.decisionId} is already decided — a reversal is a new request`);
962
+ if (request.dueAt && Date.parse(at) > Date.parse(request.dueAt))
963
+ return reject(`decision ${command.decisionId} expired at ${request.dueAt}`);
964
+ // THE DECLARED APPROVER, AND ONLY THEM. The managing principal counts when the organization was named
965
+ // (a steward decides as it — the door set the actor); a steward who is not named, whose organization
966
+ // is not named, is refused here in those words. Standing is the door's question; naming is this one's.
967
+ const actor = command.actor.toLowerCase();
968
+ const named = request.requirement.approvers.includes(actor);
969
+ if (!named) {
970
+ const steward = isSteward(state, command.actor);
971
+ return reject(steward ? `${command.actor} is a steward but not a declared approver of decision ${command.decisionId} — steward standing never substitutes` : `${command.actor} is not a declared approver of decision ${command.decisionId}`);
972
+ }
973
+ if (!command.rationale.trim())
974
+ return reject('a decision carries its rationale');
975
+ const prior = state.decisions[command.decisionId] ?? [];
976
+ if (prior.some((r) => r.actor.toLowerCase() === actor && r.outcome !== 'deferred')) {
977
+ return reject(`${command.actor} already recorded their decision on ${command.decisionId} — a reversal is a new request`);
978
+ }
979
+ const record = {
980
+ schema: 'apcoord/DecisionRecordV1',
981
+ decisionId: command.decisionId,
982
+ requestRef: command.decisionId,
983
+ actor: command.actor,
984
+ principal: command.principal ?? command.actor,
985
+ outcome: command.outcome,
986
+ rationale: command.rationale.trim(),
987
+ evidenceRefs: command.evidenceRefs ?? [],
988
+ scope: { endeavorId: command.endeavorId, ...(request.scope.stepIds?.length ? { stepIds: [...request.scope.stepIds] } : {}) },
989
+ decidedAt: at,
990
+ };
991
+ // THE QUORUM, COUNTED (W2): distinct approvers who approved reach it → approved; the approvals still
992
+ // possible cannot reach it → rejected; else the request stays pending for the others. A deferral counts
993
+ // for nothing. Arithmetic over immutable records — the reducer holds no vote.
994
+ const quorum = request.requirement.quorum ?? 1;
995
+ const counted = [...prior.filter((r) => r.outcome !== 'deferred'), record];
996
+ const approved = new Set(counted.filter((r) => r.outcome === 'approved').map((r) => r.actor.toLowerCase())).size;
997
+ const rejected = new Set(counted.filter((r) => r.outcome === 'rejected').map((r) => r.actor.toLowerCase())).size;
998
+ const resolution = command.outcome === 'deferred' ? undefined : approved >= quorum ? 'approved' : request.requirement.approvers.length - rejected < quorum ? 'rejected' : undefined;
999
+ const events = [{ kind: 'DecisionRecorded', eventId: eventId(nextRevision, 'DecisionRecorded'), endeavorId: command.endeavorId, decisionId: command.decisionId, record, ...(resolution ? { resolution } : {}), occurredAt: at, revision: nextRevision }];
1000
+ // A DECLARED CONSEQUENCE (spec 360 / 393 W2): an approval satisfies the DECISION-kind steps the request
1001
+ // was scoped to, citing the record as the evidence — never a contribution step, which is someone's work.
1002
+ if (resolution === 'approved' && request.scope.stepIds?.length) {
1003
+ const plan = adoptedPlan(state);
1004
+ for (const stepId of request.scope.stepIds) {
1005
+ const step = plan?.steps.find((st) => st.stepId === stepId);
1006
+ if (!step || step.kind !== 'decision' || state.satisfiedSteps[stepId] || !ctx.endeavor.adoptedPlanRef)
1007
+ continue;
1008
+ const rev = nextRevision + events.length;
1009
+ events.push({ kind: 'PlanStepSatisfied', eventId: eventId(rev, 'PlanStepSatisfied'), endeavorId: command.endeavorId, stepId, planRef: ctx.endeavor.adoptedPlanRef, evidenceRefs: [{ kind: 'resource', iri: `urn:ap:decision:${command.decisionId}` }], recordedBy: command.actor, occurredAt: at, revision: rev });
1010
+ }
1011
+ }
1012
+ return { ok: true, events };
1013
+ }
773
1014
  case 'ResolveRecommendation': {
774
1015
  const rec = state.recommendations[command.recommendationId];
775
1016
  if (!rec)
@@ -1024,6 +1265,52 @@ export function applyCoordinationEvent(state, event) {
1024
1265
  allocations: { ...state.allocations, [event.allocationId]: allocation },
1025
1266
  };
1026
1267
  }
1268
+ case 'RunAttached': {
1269
+ // Idempotent by runRef: attaching the same run twice is the same assertion, not two.
1270
+ return {
1271
+ ...state,
1272
+ revision: event.revision,
1273
+ endeavor: endeavorAt(event.revision),
1274
+ attachedRuns: {
1275
+ ...state.attachedRuns,
1276
+ [event.runRef]: { runRef: event.runRef, recordDigest: event.recordDigest, attachedBy: event.attachedBy, attachedAt: event.occurredAt },
1277
+ },
1278
+ };
1279
+ }
1280
+ case 'CommitmentDischarged': {
1281
+ const c = state.commitments[event.commitmentId];
1282
+ if (!c)
1283
+ throw new CoordinationEventError(`CommitmentDischarged for unknown commitment ${event.commitmentId}`);
1284
+ // `fulfilled` is the state the reducer has always persisted; discharge is the act that reaches it.
1285
+ return {
1286
+ ...state,
1287
+ revision: event.revision,
1288
+ endeavor: endeavorAt(event.revision),
1289
+ commitments: { ...state.commitments, [event.commitmentId]: { ...c, status: 'fulfilled' } },
1290
+ };
1291
+ }
1292
+ case 'CommitmentBreached': {
1293
+ const c = state.commitments[event.commitmentId];
1294
+ if (!c)
1295
+ throw new CoordinationEventError(`CommitmentBreached for unknown commitment ${event.commitmentId}`);
1296
+ return {
1297
+ ...state,
1298
+ revision: event.revision,
1299
+ endeavor: endeavorAt(event.revision),
1300
+ commitments: { ...state.commitments, [event.commitmentId]: { ...c, status: 'breached' } },
1301
+ };
1302
+ }
1303
+ case 'CommitmentLapsed': {
1304
+ const c = state.commitments[event.commitmentId];
1305
+ if (!c)
1306
+ throw new CoordinationEventError(`CommitmentLapsed for unknown commitment ${event.commitmentId}`);
1307
+ return {
1308
+ ...state,
1309
+ revision: event.revision,
1310
+ endeavor: endeavorAt(event.revision),
1311
+ commitments: { ...state.commitments, [event.commitmentId]: { ...c, status: 'lapsed' } },
1312
+ };
1313
+ }
1027
1314
  case 'ContributionCommitted': {
1028
1315
  const allocation = state.allocations[event.allocationRef];
1029
1316
  if (!allocation)
@@ -1129,6 +1416,20 @@ export function applyCoordinationEvent(state, event) {
1129
1416
  revision: event.revision,
1130
1417
  endeavor: { ...endeavorAt(event.revision), lifecycle: 'abandoned' },
1131
1418
  };
1419
+ case 'DecisionRequested':
1420
+ return { ...state, revision: event.revision, endeavor: endeavorAt(event.revision), decisionRequests: { ...state.decisionRequests, [event.decisionId]: event.request } };
1421
+ case 'DecisionRecorded': {
1422
+ const request = state.decisionRequests[event.decisionId];
1423
+ if (!request)
1424
+ throw new CoordinationEventError(`DecisionRecorded for unknown decision ${event.decisionId}`);
1425
+ return {
1426
+ ...state,
1427
+ revision: event.revision,
1428
+ endeavor: endeavorAt(event.revision),
1429
+ decisionRequests: { ...state.decisionRequests, [event.decisionId]: event.resolution ? { ...request, status: 'decided', outcome: event.resolution } : request },
1430
+ decisions: { ...state.decisions, [event.decisionId]: [...(state.decisions[event.decisionId] ?? []), event.record] },
1431
+ };
1432
+ }
1132
1433
  case 'RecommendationProposed':
1133
1434
  return {
1134
1435
  ...state,