@knpkv/herdr-work 0.3.0 → 0.5.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 (67) hide show
  1. package/README.md +99 -1
  2. package/dist/agent-binding.d.ts +4 -0
  3. package/dist/agent-binding.d.ts.map +1 -0
  4. package/dist/agent-binding.js +26 -0
  5. package/dist/agent-binding.js.map +1 -0
  6. package/dist/errors.d.ts +141 -0
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +97 -0
  9. package/dist/errors.js.map +1 -1
  10. package/dist/goal-family.d.ts +4 -0
  11. package/dist/goal-family.d.ts.map +1 -0
  12. package/dist/goal-family.js +32 -0
  13. package/dist/goal-family.js.map +1 -0
  14. package/dist/index.d.ts +4 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +4 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/internal/agent-binding-admission.d.ts +15 -0
  19. package/dist/internal/agent-binding-admission.d.ts.map +1 -0
  20. package/dist/internal/agent-binding-admission.js +92 -0
  21. package/dist/internal/agent-binding-admission.js.map +1 -0
  22. package/dist/internal/agent-binding-readback.d.ts +55 -0
  23. package/dist/internal/agent-binding-readback.d.ts.map +1 -0
  24. package/dist/internal/agent-binding-readback.js +124 -0
  25. package/dist/internal/agent-binding-readback.js.map +1 -0
  26. package/dist/internal/coordinator-authority.d.ts +62 -0
  27. package/dist/internal/coordinator-authority.d.ts.map +1 -0
  28. package/dist/internal/coordinator-authority.js +214 -0
  29. package/dist/internal/coordinator-authority.js.map +1 -0
  30. package/dist/internal/decision-handoff-migration.d.ts +126 -0
  31. package/dist/internal/decision-handoff-migration.d.ts.map +1 -0
  32. package/dist/internal/decision-handoff-migration.js +51 -0
  33. package/dist/internal/decision-handoff-migration.js.map +1 -0
  34. package/dist/internal/history-validation.d.ts +5 -0
  35. package/dist/internal/history-validation.d.ts.map +1 -0
  36. package/dist/internal/history-validation.js +33 -0
  37. package/dist/internal/history-validation.js.map +1 -0
  38. package/dist/model.d.ts +3109 -51
  39. package/dist/model.d.ts.map +1 -1
  40. package/dist/model.js +340 -11
  41. package/dist/model.js.map +1 -1
  42. package/dist/navigation.d.ts +17 -0
  43. package/dist/navigation.d.ts.map +1 -0
  44. package/dist/navigation.js +62 -0
  45. package/dist/navigation.js.map +1 -0
  46. package/dist/projection.d.ts +660 -0
  47. package/dist/projection.d.ts.map +1 -1
  48. package/dist/projection.js +65 -25
  49. package/dist/projection.js.map +1 -1
  50. package/dist/service.d.ts +1886 -3
  51. package/dist/service.d.ts.map +1 -1
  52. package/dist/service.js +138 -5
  53. package/dist/service.js.map +1 -1
  54. package/dist/sql.d.ts +30 -0
  55. package/dist/sql.d.ts.map +1 -0
  56. package/dist/sql.js +1454 -0
  57. package/dist/sql.js.map +1 -0
  58. package/dist/store.d.ts +1072 -4
  59. package/dist/store.d.ts.map +1 -1
  60. package/dist/store.js +3328 -43
  61. package/dist/store.js.map +1 -1
  62. package/dist/view.d.ts +9 -2
  63. package/dist/view.d.ts.map +1 -1
  64. package/dist/view.js +156 -8
  65. package/dist/view.js.map +1 -1
  66. package/package.json +25 -13
  67. package/src/styles.css +91 -17
package/README.md CHANGED
@@ -4,7 +4,101 @@ Durable fleet work checkpoints and the Rly departure-board projection used by th
4
4
 
5
5
  Each `WorkGoalCheckpoint` stores a complete, Schema-decoded goal state at its exact durable timestamp. `projectWorkSnapshots` selects the latest recorded checkpoint at now, 24 hours, 7 days, and 30 days. A goal does not appear before its creation checkpoint, and missing history is never synthesized.
6
6
 
7
- `WorkStore` persists events in SQLite. Recording the exact same checkpoint again is an idempotent replay; reusing an event ID or goal timestamp with changed content returns `WorkCheckpointConflictError`. `makeWorkService` is the small runtime interface for recording checkpoints and reading all four snapshots.
7
+ `WorkGoal.goalFamily` records a goal as either the canonical member of a family or a superseded member pointing to that canonical goal. Superseded goals leave the active projection only after their durable relation checkpoint. Earlier snapshots still show their previous state, blockers, reviews, and activity. A relation cannot be removed or retargeted, and a superseded goal cannot precede its canonical member.
8
+
9
+ `WorkStore` persists events in SQLite. Recording the exact same checkpoint again is an idempotent replay; reusing an event ID or goal timestamp with changed content returns `WorkCheckpointConflictError`. `makeWorkService` is the small runtime interface for recording checkpoints, reading the current durable lane claim, and reading all four snapshots. A default snapshot atomically reads history with the coordinator-owned agent-binding boundary and observes the later of that logical time and the current clock, so same-tick coordinator checkpoints remain visible without letting an ordinary future checkpoint shift every window; an explicit observation timestamp preserves historical reads. An unknown lane returns `Option.none()`; a stored claim is Schema-decoded and its revision is checked against the durable row.
10
+
11
+ The store preserves safe caller-owned state-directory modes, but rejects
12
+ group- or world-writable POSIX directories and substituted database paths before
13
+ opening the authority database.
14
+
15
+ `WorkStore.appendMany` validates a whole checkpoint batch before one SQLite
16
+ transaction. Reusing its transaction ID with the same batch replays it. A
17
+ changed event with an existing event ID or goal/timestamp returns
18
+ `WorkCheckpointConflictError`; a different batch that passes those checkpoint
19
+ identity checks returns `WorkTransactionConflictError`. `claim` is a durable
20
+ compare-and-set lane claim containing the canonical worktree, branch, exact
21
+ head, owner, parent, phase, authoritative goal ID, operation ID, and expected
22
+ revision. The operation ID replays only its exact committed claim; changed
23
+ content conflicts. Its replay ledger is bounded to 16,384 operations and 2 MiB
24
+ of encoded records while retaining accepted operation identities. A partial
25
+ unique index transactionally permits only one non-shipped lane per goal.
26
+ `activeGoalClaim` reads that authority directly.
27
+
28
+ `bindAgent` is the replay-safe worker-start operation. Its typed request is
29
+ keyed by dispatch request ID and carries the exact lane plus expected revision.
30
+ One SQLite transaction compare-and-sets that lane, stores the full
31
+ `AgentWorkerIdentity`, derives the canonical `AgentConnectTarget`, and appends
32
+ the matching goal checkpoint. Exact replay returns the original binding after
33
+ restart; changed worker content returns `WorkAgentBindingConflictError`.
34
+ Missing, stale, shipped, or terminal goal authority fails without a partial
35
+ lane, checkpoint, or binding write.
36
+
37
+ `handoff` stores a compact, credential-free decision record keyed by coordinator
38
+ session ID for later recovery under a 16,384-row and 2 MiB encoded-byte ledger.
39
+ It includes the active goal and lane, dispatch IDs, blocker details, evidence
40
+ references, and a nonempty credential-free context delta bounded to 4,096
41
+ characters. A new v2 handoff captures the active lane's exact expected revision
42
+ and rejects a stale revision with `WorkDecisionRevisionConflictError`; exact
43
+ replay remains available after that lane advances.
44
+ Both the previous pre-session table and v1 records already stored in the current
45
+ table migrate explicitly: their bounded summary becomes the v2 context delta.
46
+ Migration requires exactly one persisted dispatch binding and keeps that
47
+ binding's expected revision; an unbound v1 handoff cannot borrow the current
48
+ lane revision, and the persisted lane head cannot trail the binding's activated
49
+ revision. The complete `WorkAgentBinding` record must decode and match its
50
+ indexed dispatch, lane, revision, worker, and host, plus its exact immutable
51
+ lane-operation and checkpoint ledger companions, before migration uses that
52
+ authority. A dispatch lineage may remain a strict subset of the decision's
53
+ complete dispatch IDs, while the dispatch and coordinator-metadata lineage
54
+ replicas must agree exactly. Missing lanes, bindings, dispatch replicas, or
55
+ coordinator metadata, malformed records that claim the v1 contract, and contradictory replicas, fail startup with a named
56
+ `WorkStoreError`; no context or revision authority is invented.
57
+ Coordinator-backed migration and current v2 readback additionally require a complete bounded lifecycle,
58
+ the exact running checkpoint, status/tail agreement, a matching handoff goal, and
59
+ a schema-valid Sol route whose metadata agrees with the persisted routed
60
+ discriminator. A Sol route also requires a persisted `agent.delegate` command in
61
+ `review` or `work` mode; the command, route, and Work link are one authority
62
+ binding. A non-null Sol link must remain in lineage and identify an exact
63
+ terminally failed Luna parent with its own complete lifecycle. Duplicate
64
+ pre-session dispatch replicas fail closed. Current v2 readback also decodes the
65
+ authoritative lane claim, requires its goal to remain fixed, requires an exact
66
+ immutable operation-ledger replica, and rejects a lane head older than the
67
+ activated binding; at the binding revision the whole claim must still be exact.
68
+ Luna metadata must retain a null Work link and does not consume the bounded
69
+ Work-decision scan; malformed or non-null Luna links fail closed. Every modern
70
+ dispatch/metadata pair must bind its persisted activity key and command to the
71
+ exact route, routed discriminator, and Work-link form; routed metadata without
72
+ its dispatch fails closed, and every modern routed dispatch must retain exactly one metadata row. Standalone Work
73
+ databases with no coordinator tables remain valid; a partial coordinator table set fails before
74
+ either v1 migration or v2 handoff readback. The SQL adapter creates or upgrades
75
+ Work tables in that same fail-closed transaction and ignores unrelated legacy
76
+ binding or null-route orphan metadata rows. Current v2 dispatch and metadata
77
+ replicas must decode and agree exactly with the authoritative decision handoff;
78
+ dispatch lineage may remain a strict subset of the decision's dispatch set.
79
+ Changed content for the same session
80
+ conflicts, and `coordinatorHandoff` proves restart readback without retaining an
81
+ unbounded transcript. Replay aliases retain fixed-size canonical SHA-256
82
+ identities under a bounded ledger, and lane claims validate Git branch refs
83
+ before persisting their authority.
84
+
85
+ `makeSqliteWorkBridge`, exported from the headless `@knpkv/herdr-work/sql`
86
+ subpath, provides the SQLite-specific dispatch binding used by a coordinator's
87
+ transaction. It inserts the decoded Work handoff and its
88
+ bounded dispatch lineage together, and verifies exact replay without repairing
89
+ an incomplete dispatch, including the referenced decision row. Every lineage
90
+ request must appear in the handoff's dispatch IDs. New bindings require the
91
+ handoff's active, non-shipped lane, authoritative goal, and accepted expected revision; exact
92
+ binding replay remains available after the lane advances. The coordinator must call it inside the same
93
+ transaction as acceptance; `WorkStore.decisions` then recovers the handoff from
94
+ the same database. The server-private durable `AgentWorkerIdentity` record stays
95
+ behind the Work service boundary. Its derived, normalized client-visible
96
+ `AgentConnectTarget` excludes provider credentials and private locators and may
97
+ cross only the authenticated Work UI boundary; neither form may be emitted on
98
+ unauthenticated or public surfaces.
99
+ The same bridge exposes the transaction-owned agent-binding primitive used by
100
+ the coordinator's durable `workerStarted` boundary; callers cannot repair a
101
+ previously partial activation during replay.
8
102
 
9
103
  `WorkBoard` renders these persisted outbound-link forms:
10
104
 
@@ -13,3 +107,7 @@ Each `WorkGoalCheckpoint` stores a complete, Schema-decoded goal state at its ex
13
107
  - `WorkReview.url` — review destination.
14
108
 
15
109
  Every URL uses the credential-free HTTP(S) `LinkUrl` boundary. Provider credentials and private locators never enter these persisted or browser-visible links.
110
+
111
+ `WorkBoard` accepts `externalLinks="enabled"` by default. With `externalLinks="disabled"`, it keeps recorded approval, review, and Connect targets visible as metadata without rendering outbound links for read-only LAN Work.
112
+
113
+ The board shows ten goals initially, filters them by durable status, and reveals ten more per request. A selected or deep-linked goal stays in the active bounded page. Goal details and shipment evidence open on selection and return focus to the selected row when closed. When `navigation` is present, filters, reveal, and close use same-origin links so server-rendered Work remains operable without JavaScript. `WorkNavigationSelection.goalId` may carry an opaque board-state token longer than a persisted `WorkGoalId`; transport callers must decode the selection before validating a goal identity. On narrow screens, rows keep status, title, and summary visible while the detail view owns the remaining metadata.
@@ -0,0 +1,4 @@
1
+ import { WorkAgentBinding, type WorkAgentBindingRequest, type WorkGoalCheckpoint, type WorkLaneClaimed } from "./model.js";
2
+ /** Builds the single checkpoint and lane revision committed when a worker starts. */
3
+ export declare const makeWorkAgentBinding: (request: WorkAgentBindingRequest, currentLane: WorkLaneClaimed, currentCheckpoint: WorkGoalCheckpoint, occurredAt: number) => WorkAgentBinding;
4
+ //# sourceMappingURL=agent-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-binding.d.ts","sourceRoot":"","sources":["../src/agent-binding.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,YAAY,CAAA;AAEnB,qFAAqF;AACrF,eAAO,MAAM,oBAAoB,YACtB,uBAAuB,eACnB,eAAe,qBACT,kBAAkB,cACzB,MAAM,KACjB,gBAqBC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { agentConnectTarget } from "@knpkv/herdr-fleet/model";
2
+ import { Schema } from "effect";
3
+ import { WorkAgentBinding } from "./model.js";
4
+ /** Builds the single checkpoint and lane revision committed when a worker starts. */
5
+ export const makeWorkAgentBinding = (request, currentLane, currentCheckpoint, occurredAt) => Schema.decodeUnknownSync(WorkAgentBinding)({
6
+ version: "herdr.work.agent-binding.v1",
7
+ request,
8
+ lane: {
9
+ ...currentLane,
10
+ operationId: request.dispatchRequestId,
11
+ expectedRevision: request.expectedRevision,
12
+ revision: request.expectedRevision + 1
13
+ },
14
+ checkpoint: {
15
+ eventId: request.dispatchRequestId,
16
+ goal: {
17
+ ...currentCheckpoint.goal,
18
+ agentHierarchy: { agent: request.worker },
19
+ connectTarget: agentConnectTarget(request.worker),
20
+ updatedAt: occurredAt
21
+ },
22
+ occurredAt,
23
+ version: "herdr.work.event.v1"
24
+ }
25
+ });
26
+ //# sourceMappingURL=agent-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-binding.js","sourceRoot":"","sources":["../src/agent-binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EACL,gBAAgB,EAIjB,MAAM,YAAY,CAAA;AAEnB,qFAAqF;AACrF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAAgC,EAChC,WAA4B,EAC5B,iBAAqC,EACrC,UAAkB,EACA,EAAE,CACpB,MAAM,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACzC,OAAO,EAAE,6BAA6B;IACtC,OAAO;IACP,IAAI,EAAE;QACJ,GAAG,WAAW;QACd,WAAW,EAAE,OAAO,CAAC,iBAAiB;QACtC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,QAAQ,EAAE,OAAO,CAAC,gBAAgB,GAAG,CAAC;KACvC;IACD,UAAU,EAAE;QACV,OAAO,EAAE,OAAO,CAAC,iBAAiB;QAClC,IAAI,EAAE;YACJ,GAAG,iBAAiB,CAAC,IAAI;YACzB,cAAc,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE;YACzC,aAAa,EAAE,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC;YACjD,SAAS,EAAE,UAAU;SACtB;QACD,UAAU;QACV,OAAO,EAAE,qBAAqB;KAC/B;CACF,CAAC,CAAA"}
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  import { Schema } from "effect";
2
+ declare const WorkRecoveryContextError_base: Schema.Class<WorkRecoveryContextError, Schema.TaggedStruct<"WorkRecoveryContextError", {
3
+ readonly goalId: Schema.String;
4
+ readonly reason: Schema.Literals<readonly ["invalid_goal_id", "missing_goal"]>;
5
+ }>, import("effect/Cause").YieldableError>;
6
+ export declare class WorkRecoveryContextError extends WorkRecoveryContextError_base {
7
+ }
2
8
  declare const WorkProjectionError_base: Schema.Class<WorkProjectionError, Schema.TaggedStruct<"WorkProjectionError", {
3
9
  readonly cause: Schema.Defect;
4
10
  readonly detail: Schema.String;
@@ -19,5 +25,140 @@ declare const WorkCheckpointConflictError_base: Schema.Class<WorkCheckpointConfl
19
25
  }>, import("effect/Cause").YieldableError>;
20
26
  export declare class WorkCheckpointConflictError extends WorkCheckpointConflictError_base {
21
27
  }
28
+ declare const WorkTransactionConflictError_base: Schema.Class<WorkTransactionConflictError, Schema.TaggedStruct<"WorkTransactionConflictError", {
29
+ readonly transactionId: Schema.String;
30
+ }>, import("effect/Cause").YieldableError>;
31
+ export declare class WorkTransactionConflictError extends WorkTransactionConflictError_base {
32
+ }
33
+ declare const WorkLaneClaimConflictError_base: Schema.Class<WorkLaneClaimConflictError, Schema.TaggedStruct<"WorkLaneClaimConflictError", {
34
+ readonly laneId: Schema.String;
35
+ readonly expectedRevision: Schema.Number;
36
+ readonly actualRevision: Schema.Number;
37
+ }>, import("effect/Cause").YieldableError>;
38
+ export declare class WorkLaneClaimConflictError extends WorkLaneClaimConflictError_base {
39
+ }
40
+ declare const WorkLaneOperationConflictError_base: Schema.Class<WorkLaneOperationConflictError, Schema.TaggedStruct<"WorkLaneOperationConflictError", {
41
+ readonly operationId: Schema.String;
42
+ }>, import("effect/Cause").YieldableError>;
43
+ export declare class WorkLaneOperationConflictError extends WorkLaneOperationConflictError_base {
44
+ }
45
+ declare const WorkLaneGoalConflictError_base: Schema.Class<WorkLaneGoalConflictError, Schema.TaggedStruct<"WorkLaneGoalConflictError", {
46
+ readonly goalId: Schema.String;
47
+ readonly laneId: Schema.String;
48
+ readonly activeLaneId: Schema.String;
49
+ }>, import("effect/Cause").YieldableError>;
50
+ export declare class WorkLaneGoalConflictError extends WorkLaneGoalConflictError_base {
51
+ }
52
+ declare const WorkDecisionHandoffConflictError_base: Schema.Class<WorkDecisionHandoffConflictError, Schema.TaggedStruct<"WorkDecisionHandoffConflictError", {
53
+ readonly handoffId: Schema.String;
54
+ }>, import("effect/Cause").YieldableError>;
55
+ export declare class WorkDecisionHandoffConflictError extends WorkDecisionHandoffConflictError_base {
56
+ }
57
+ declare const WorkDecisionAuthorityConflictError_base: Schema.Class<WorkDecisionAuthorityConflictError, Schema.TaggedStruct<"WorkDecisionAuthorityConflictError", {
58
+ readonly goalId: Schema.String;
59
+ readonly laneId: Schema.String;
60
+ }>, import("effect/Cause").YieldableError>;
61
+ export declare class WorkDecisionAuthorityConflictError extends WorkDecisionAuthorityConflictError_base {
62
+ }
63
+ declare const WorkDecisionRevisionConflictError_base: Schema.Class<WorkDecisionRevisionConflictError, Schema.TaggedStruct<"WorkDecisionRevisionConflictError", {
64
+ readonly laneId: Schema.String;
65
+ readonly expectedRevision: Schema.Number;
66
+ readonly actualRevision: Schema.Number;
67
+ }>, import("effect/Cause").YieldableError>;
68
+ export declare class WorkDecisionRevisionConflictError extends WorkDecisionRevisionConflictError_base {
69
+ }
70
+ declare const WorkCoordinatorHandoffConflictError_base: Schema.Class<WorkCoordinatorHandoffConflictError, Schema.TaggedStruct<"WorkCoordinatorHandoffConflictError", {
71
+ readonly sessionId: Schema.String;
72
+ }>, import("effect/Cause").YieldableError>;
73
+ export declare class WorkCoordinatorHandoffConflictError extends WorkCoordinatorHandoffConflictError_base {
74
+ }
75
+ declare const WorkDispatchHandoffConflictError_base: Schema.Class<WorkDispatchHandoffConflictError, Schema.TaggedStruct<"WorkDispatchHandoffConflictError", {
76
+ readonly dispatchRequestId: Schema.String;
77
+ readonly handoffId: Schema.String;
78
+ }>, import("effect/Cause").YieldableError>;
79
+ export declare class WorkDispatchHandoffConflictError extends WorkDispatchHandoffConflictError_base {
80
+ }
81
+ declare const WorkAgentBindingConflictError_base: Schema.Class<WorkAgentBindingConflictError, Schema.TaggedStruct<"WorkAgentBindingConflictError", {
82
+ readonly dispatchRequestId: Schema.String;
83
+ }>, import("effect/Cause").YieldableError>;
84
+ export declare class WorkAgentBindingConflictError extends WorkAgentBindingConflictError_base {
85
+ }
86
+ declare const WorkAgentBindingAuthorityError_base: Schema.Class<WorkAgentBindingAuthorityError, Schema.TaggedStruct<"WorkAgentBindingAuthorityError", {
87
+ readonly laneId: Schema.String;
88
+ readonly expectedRevision: Schema.Number;
89
+ readonly actualRevision: Schema.Number;
90
+ readonly reason: Schema.Literals<readonly ["missing_lane", "stale_revision", "shipped_lane", "missing_goal", "terminal_goal"]>;
91
+ }>, import("effect/Cause").YieldableError>;
92
+ export declare class WorkAgentBindingAuthorityError extends WorkAgentBindingAuthorityError_base {
93
+ }
94
+ declare const WorkPullRequestLinkError_base: Schema.Class<WorkPullRequestLinkError, Schema.TaggedStruct<"WorkPullRequestLinkError", {
95
+ readonly goalId: Schema.String;
96
+ readonly laneId: Schema.String;
97
+ readonly reason: Schema.Literals<readonly ["missing_provenance", "missing_goal", "missing_lane", "missing_binding", "stale_revision", "head_mismatch", "owner_mismatch", "session_mismatch", "identity_mismatch", "terminal_goal", "operation_conflict", "ambiguous_binding"]>;
98
+ }>, import("effect/Cause").YieldableError>;
99
+ export declare class WorkPullRequestLinkError extends WorkPullRequestLinkError_base {
100
+ }
101
+ declare const WorkAdmissionConflictError_base: Schema.Class<WorkAdmissionConflictError, Schema.TaggedStruct<"WorkAdmissionConflictError", {
102
+ readonly goalId: Schema.String;
103
+ readonly laneId: Schema.String;
104
+ readonly reason: Schema.String;
105
+ }>, import("effect/Cause").YieldableError>;
106
+ export declare class WorkAdmissionConflictError extends WorkAdmissionConflictError_base {
107
+ }
108
+ declare const WorkGoalOwnerMismatchError_base: Schema.Class<WorkGoalOwnerMismatchError, Schema.TaggedStruct<"WorkGoalOwnerMismatchError", {
109
+ readonly goalId: Schema.String;
110
+ readonly laneId: Schema.NullOr<Schema.String>;
111
+ readonly expectedOwner: Schema.Struct<{
112
+ readonly id: Schema.String;
113
+ readonly name: Schema.String;
114
+ }>;
115
+ readonly actualOwner: Schema.Struct<{
116
+ readonly id: Schema.String;
117
+ readonly name: Schema.String;
118
+ }>;
119
+ }>, import("effect/Cause").YieldableError>;
120
+ /** The goal, or its active lane when `laneId` is set, is not owned by the approved source owner. */
121
+ export declare class WorkGoalOwnerMismatchError extends WorkGoalOwnerMismatchError_base {
122
+ }
123
+ declare const WorkGoalRevisionConflictError_base: Schema.Class<WorkGoalRevisionConflictError, Schema.TaggedStruct<"WorkGoalRevisionConflictError", {
124
+ readonly goalId: Schema.String;
125
+ readonly expectedEventId: Schema.String;
126
+ readonly expectedUpdatedAt: Schema.Number;
127
+ readonly actualEventId: Schema.NullOr<Schema.String>;
128
+ readonly actualUpdatedAt: Schema.NullOr<Schema.Number>;
129
+ }>, import("effect/Cause").YieldableError>;
130
+ /** The goal's durable head is not the approved expected event; `actual*` is null when the goal is absent. */
131
+ export declare class WorkGoalRevisionConflictError extends WorkGoalRevisionConflictError_base {
132
+ }
133
+ declare const WorkGoalReassignmentConflictError_base: Schema.Class<WorkGoalReassignmentConflictError, Schema.TaggedStruct<"WorkGoalReassignmentConflictError", {
134
+ readonly approvalJobId: Schema.String;
135
+ readonly reason: Schema.Literals<readonly ["payload_mismatch", "identifier_in_use"]>;
136
+ }>, import("effect/Cause").YieldableError>;
137
+ /** The approval job id already names a different reassignment or another durable record. */
138
+ export declare class WorkGoalReassignmentConflictError extends WorkGoalReassignmentConflictError_base {
139
+ }
140
+ declare const WorkGoalBindingRequiresAgentError_base: Schema.Class<WorkGoalBindingRequiresAgentError, Schema.TaggedStruct<"WorkGoalBindingRequiresAgentError", {
141
+ readonly goalId: Schema.String;
142
+ readonly laneId: Schema.String;
143
+ readonly dispatchRequestId: Schema.String;
144
+ }>, import("effect/Cause").YieldableError>;
145
+ /** The goal's active lane has a started-worker binding, so a reassignment must name the agent that takes it over. */
146
+ export declare class WorkGoalBindingRequiresAgentError extends WorkGoalBindingRequiresAgentError_base {
147
+ }
148
+ declare const WorkGoalAgentTargetConflictError_base: Schema.Class<WorkGoalAgentTargetConflictError, Schema.TaggedStruct<"WorkGoalAgentTargetConflictError", {
149
+ readonly goalId: Schema.String;
150
+ readonly agentId: Schema.String;
151
+ readonly reason: Schema.Literals<readonly ["keep_existing_target", "held_by_other_goal", "held_by_other_lane"]>;
152
+ readonly holderId: Schema.String;
153
+ }>, import("effect/Cause").YieldableError>;
154
+ /**
155
+ * The requested agent target cannot be written. `keep_existing_target`: keeping
156
+ * would leave the previous owner's agent on the goal (`holderId` is that goal).
157
+ * `held_by_other_goal` / `held_by_other_lane`: the new agent is already the
158
+ * current target of another goal, or the authoritative binding of another
159
+ * goal's lane (`holderId` is that goal or lane).
160
+ */
161
+ export declare class WorkGoalAgentTargetConflictError extends WorkGoalAgentTargetConflictError_base {
162
+ }
22
163
  export {};
23
164
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;;;;;;AAE/B,qBAAa,mBAAoB,SAAQ,wBAaxC;CAAG;;;;;AAEJ,qBAAa,cAAe,SAAQ,mBAGnC;CAAG;;;;;;AAEJ,qBAAa,2BAA4B,SAAQ,gCAOhD;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;;;;;AA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ect";
2
+ export class WorkRecoveryContextError extends Schema.TaggedError()("WorkRecoveryContextError", {
3
+ goalId: Schema.String,
4
+ reason: Schema.Literals(["invalid_goal_id", "missing_goal"])
5
+ }) {
6
+ }
2
7
  export class WorkProjectionError extends Schema.TaggedError()("WorkProjectionError", {
3
8
  cause: Schema.Defect(),
4
9
  detail: Schema.String,
@@ -19,4 +24,96 @@ export class WorkCheckpointConflictError extends Schema.TaggedError()("WorkCheck
19
24
  occurredAt: Schema.Number
20
25
  }) {
21
26
  }
27
+ export class WorkTransactionConflictError extends Schema.TaggedError()("WorkTransactionConflictError", { transactionId: Schema.String }) {
28
+ }
29
+ export class WorkLaneClaimConflictError extends Schema.TaggedError()("WorkLaneClaimConflictError", {
30
+ laneId: Schema.String,
31
+ expectedRevision: Schema.Number,
32
+ actualRevision: Schema.Number
33
+ }) {
34
+ }
35
+ export class WorkLaneOperationConflictError extends Schema.TaggedError()("WorkLaneOperationConflictError", { operationId: Schema.String }) {
36
+ }
37
+ export class WorkLaneGoalConflictError extends Schema.TaggedError()("WorkLaneGoalConflictError", { goalId: Schema.String, laneId: Schema.String, activeLaneId: Schema.String }) {
38
+ }
39
+ export class WorkDecisionHandoffConflictError extends Schema.TaggedError()("WorkDecisionHandoffConflictError", { handoffId: Schema.String }) {
40
+ }
41
+ export class WorkDecisionAuthorityConflictError extends Schema.TaggedError()("WorkDecisionAuthorityConflictError", { goalId: Schema.String, laneId: Schema.String }) {
42
+ }
43
+ export class WorkDecisionRevisionConflictError extends Schema.TaggedError()("WorkDecisionRevisionConflictError", { laneId: Schema.String, expectedRevision: Schema.Number, actualRevision: Schema.Number }) {
44
+ }
45
+ export class WorkCoordinatorHandoffConflictError extends Schema.TaggedError()("WorkCoordinatorHandoffConflictError", { sessionId: Schema.String }) {
46
+ }
47
+ export class WorkDispatchHandoffConflictError extends Schema.TaggedError()("WorkDispatchHandoffConflictError", { dispatchRequestId: Schema.String, handoffId: Schema.String }) {
48
+ }
49
+ export class WorkAgentBindingConflictError extends Schema.TaggedError()("WorkAgentBindingConflictError", { dispatchRequestId: Schema.String }) {
50
+ }
51
+ export class WorkAgentBindingAuthorityError extends Schema.TaggedError()("WorkAgentBindingAuthorityError", {
52
+ laneId: Schema.String,
53
+ expectedRevision: Schema.Number,
54
+ actualRevision: Schema.Number,
55
+ reason: Schema.Literals(["missing_lane", "stale_revision", "shipped_lane", "missing_goal", "terminal_goal"])
56
+ }) {
57
+ }
58
+ export class WorkPullRequestLinkError extends Schema.TaggedError()("WorkPullRequestLinkError", {
59
+ goalId: Schema.String,
60
+ laneId: Schema.String,
61
+ reason: Schema.Literals([
62
+ "missing_provenance",
63
+ "missing_goal",
64
+ "missing_lane",
65
+ "missing_binding",
66
+ "stale_revision",
67
+ "head_mismatch",
68
+ "owner_mismatch",
69
+ "session_mismatch",
70
+ "identity_mismatch",
71
+ "terminal_goal",
72
+ "operation_conflict",
73
+ "ambiguous_binding"
74
+ ])
75
+ }) {
76
+ }
77
+ export class WorkAdmissionConflictError extends Schema.TaggedError()("WorkAdmissionConflictError", { goalId: Schema.String, laneId: Schema.String, reason: Schema.String }) {
78
+ }
79
+ /** The goal, or its active lane when `laneId` is set, is not owned by the approved source owner. */
80
+ export class WorkGoalOwnerMismatchError extends Schema.TaggedError()("WorkGoalOwnerMismatchError", {
81
+ goalId: Schema.String,
82
+ laneId: Schema.NullOr(Schema.String),
83
+ expectedOwner: Schema.Struct({ id: Schema.String, name: Schema.String }),
84
+ actualOwner: Schema.Struct({ id: Schema.String, name: Schema.String })
85
+ }) {
86
+ }
87
+ /** The goal's durable head is not the approved expected event; `actual*` is null when the goal is absent. */
88
+ export class WorkGoalRevisionConflictError extends Schema.TaggedError()("WorkGoalRevisionConflictError", {
89
+ goalId: Schema.String,
90
+ expectedEventId: Schema.String,
91
+ expectedUpdatedAt: Schema.Number,
92
+ actualEventId: Schema.NullOr(Schema.String),
93
+ actualUpdatedAt: Schema.NullOr(Schema.Number)
94
+ }) {
95
+ }
96
+ /** The approval job id already names a different reassignment or another durable record. */
97
+ export class WorkGoalReassignmentConflictError extends Schema.TaggedError()("WorkGoalReassignmentConflictError", {
98
+ approvalJobId: Schema.String,
99
+ reason: Schema.Literals(["payload_mismatch", "identifier_in_use"])
100
+ }) {
101
+ }
102
+ /** The goal's active lane has a started-worker binding, so a reassignment must name the agent that takes it over. */
103
+ export class WorkGoalBindingRequiresAgentError extends Schema.TaggedError()("WorkGoalBindingRequiresAgentError", { goalId: Schema.String, laneId: Schema.String, dispatchRequestId: Schema.String }) {
104
+ }
105
+ /**
106
+ * The requested agent target cannot be written. `keep_existing_target`: keeping
107
+ * would leave the previous owner's agent on the goal (`holderId` is that goal).
108
+ * `held_by_other_goal` / `held_by_other_lane`: the new agent is already the
109
+ * current target of another goal, or the authoritative binding of another
110
+ * goal's lane (`holderId` is that goal or lane).
111
+ */
112
+ export class WorkGoalAgentTargetConflictError extends Schema.TaggedError()("WorkGoalAgentTargetConflictError", {
113
+ goalId: Schema.String,
114
+ agentId: Schema.String,
115
+ reason: Schema.Literals(["keep_existing_target", "held_by_other_goal", "held_by_other_lane"]),
116
+ holderId: Schema.String
117
+ }) {
118
+ }
22
119
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,WAAW,EAAuB,CAChF,qBAAqB,EACrB;IACE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC;QACtB,WAAW;QACX,iBAAiB;QACjB,sBAAsB;QACtB,sBAAsB;QACtB,mBAAmB;KACpB,CAAC;CACH,CACF;CAAG;AAEJ,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,EAAkB,CACtE,gBAA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B,EAAE,mBAAmB,CAAC,CAAC;CACnE,CACF;CAAG;AAEJ,qHAAqH;AACrH,MAAM,OAAO,iCAAkC,SAAQ,MAAM,CAAC,WAAW,EAAqC,CAC5G,mCAAmC,EACnC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,CACnF;CAAG;AAEJ;;;;;;GAMG;AACH,MAAM,OAAO,gCAAiC,SAAQ,MAAM,CAAC,WAAW,EAAoC,CAC1G,kCAAkC,EAClC;IACE,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;IAC7F,QAAQ,EAAE,MAAM,CAAC,MAAM;CACxB,CACF;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { WorkProjectionError } from "./errors.js";
2
+ import type { WorkGoalCheckpoint } from "./model.js";
3
+ export declare const validateGoalFamilyHistory: (events: ReadonlyArray<WorkGoalCheckpoint>) => WorkProjectionError | undefined;
4
+ //# sourceMappingURL=goal-family.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goal-family.d.ts","sourceRoot":"","sources":["../src/goal-family.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,YAAY,CAAA;AAKpE,eAAO,MAAM,yBAAyB,WAC5B,aAAa,CAAC,kBAAkB,CAAC,KACxC,mBAAmB,GAAG,SAkCxB,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { WorkProjectionError } from "./errors.js";
2
+ const inconsistency = (detail, cause) => new WorkProjectionError({ cause, detail, reason: "inconsistent_history" });
3
+ export const validateGoalFamilyHistory = (events) => {
4
+ const familyByGoal = new Map();
5
+ const canonicalActivatedAt = new Map();
6
+ const ordered = events.toSorted((left, right) => left.occurredAt - right.occurredAt);
7
+ for (const event of ordered) {
8
+ const family = event.goal.goalFamily;
9
+ const previousFamily = familyByGoal.get(event.goal.id);
10
+ if (previousFamily !== undefined && (family === undefined ||
11
+ family.canonicalGoalId !== previousFamily.canonicalGoalId ||
12
+ family.role !== previousFamily.role)) {
13
+ return inconsistency(`goal ${event.goal.id} changed or removed its goal-family relation`, event);
14
+ }
15
+ if (family !== undefined) {
16
+ familyByGoal.set(event.goal.id, family);
17
+ if (family.role === "canonical" && !canonicalActivatedAt.has(event.goal.id)) {
18
+ canonicalActivatedAt.set(event.goal.id, event.occurredAt);
19
+ }
20
+ }
21
+ }
22
+ for (const event of ordered) {
23
+ const family = event.goal.goalFamily;
24
+ if (family?.role !== "superseded")
25
+ continue;
26
+ const canonicalAt = canonicalActivatedAt.get(family.canonicalGoalId);
27
+ if (canonicalAt === undefined || canonicalAt > event.occurredAt) {
28
+ return inconsistency(`goal ${event.goal.id} was superseded before canonical goal ${family.canonicalGoalId} was recorded`, event);
29
+ }
30
+ }
31
+ };
32
+ //# sourceMappingURL=goal-family.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goal-family.js","sourceRoot":"","sources":["../src/goal-family.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAGjD,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,KAAyB,EAAE,EAAE,CAClE,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC,CAAA;AAE5E,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAAyC,EACR,EAAE;IACnC,MAAM,YAAY,GAAG,IAAI,GAAG,EAA0B,CAAA;IACtD,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAkB,CAAA;IACtD,MAAM,OAAO,GAAG,MAAM,CAAC,QAA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AAW,KAAK,SAAS,IAAI,WAAW,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;YAChE,OAAO,aAAa,CAClB,QAAQ,KAAK,CAAC,IAAI,CAAC,EAAE,yCAAyC,MAAM,CAAC,eAAe,eAAe,EACnG,KAAK,CACN,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
+ export * from "./agent-binding.js";
1
2
  export * from "./errors.js";
2
3
  export * from "./model.js";
4
+ export * from "./navigation.js";
3
5
  export * from "./projection.js";
4
6
  export * from "./service.js";
5
- export * from "./store.js";
7
+ export * from "./sql.js";
8
+ export { WorkStore, type WorkStoreService } from "./store.js";
6
9
  export * from "./view.js";
7
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7D,cAAc,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ export * from "./agent-binding.js";
1
2
  export * from "./errors.js";
2
3
  export * from "./model.js";
4
+ export * from "./navigation.js";
3
5
  export * from "./projection.js";
4
6
  export * from "./service.js";
5
- export * from "./store.js";
7
+ export * from "./sql.js";
8
+ export { WorkStore } from "./store.js";
6
9
  export * from "./view.js";
7
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,SAAS,EAAyB,MAAM,YAAY,CAAA;AAC7D,cAAc,WAAW,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { WorkProjectionError } from "../errors.js";
2
+ import { type WorkGoalCheckpoint } from "../model.js";
3
+ export declare const workAgentBindingLaneOperationMaxRecords = 16384;
4
+ export declare const workAgentBindingLaneOperationMaxBytes: number;
5
+ export declare const workAgentBindingSnapshotEnvelopeMaxBytes: number;
6
+ export declare const workMaximumSnapshotBytesForHistory: (history: ReadonlyArray<WorkGoalCheckpoint>) => number;
7
+ export declare const workAgentBindingMaximumSnapshotBytes: (history: ReadonlyArray<WorkGoalCheckpoint>, candidate: WorkGoalCheckpoint) => number;
8
+ export declare const agentBindingAdmissionError: (input: {
9
+ readonly history: ReadonlyArray<WorkGoalCheckpoint>;
10
+ readonly candidate: WorkGoalCheckpoint;
11
+ readonly operationCount: number;
12
+ readonly operationBytes: number;
13
+ readonly candidateOperationBytes: number;
14
+ }) => WorkProjectionError | undefined;
15
+ //# sourceMappingURL=agent-binding-admission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-binding-admission.d.ts","sourceRoot":"","sources":["../../src/internal/agent-binding-admission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,KAAK,kBAAkB,EAAwB,MAAM,aAAa,CAAA;AAO3E,eAAO,MAAM,uCAAuC,QAAS,CAAA;AAC7D,eAAO,MAAM,qCAAqC,QAAkB,CAAA;AACpE,eAAO,MAAM,wCAAwC,QAMnD,CAAA;AAEF,eAAO,MAAM,kCAAkC,YACpC,aAAa,CAAC,kBAAkB,CAAC,KACzC,MAuCF,CAAA;AAED,eAAO,MAAM,oCAAoC,YACtC,aAAa,CAAC,kBAAkB,CAAC,aAC/B,kBAAkB,KAC5B,MAAqE,CAAA;AAExE,eAAO,MAAM,0BAA0B,UAAW;IAChD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAA;IACnD,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAA;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAA;CACzC,KAAG,mBAAmB,GAAG,SAkCzB,CAAA"}
@@ -0,0 +1,92 @@
1
+ import { fleetResponseBodyMaxBytes } from "@knpkv/herdr-fleet";
2
+ import { WorkProjectionError } from "../errors.js";
3
+ import { workHistoryMaxEvents } from "../model.js";
4
+ import { workHistoryError } from "./history-validation.js";
5
+ const encodedBytes = (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength;
6
+ const maximumTimestamp = 8_640_000_000_000_000;
7
+ export const workAgentBindingLaneOperationMaxRecords = 16_384;
8
+ export const workAgentBindingLaneOperationMaxBytes = 2 * 1024 * 1024;
9
+ export const workAgentBindingSnapshotEnvelopeMaxBytes = encodedBytes({
10
+ observedAt: maximumTimestamp,
11
+ now: { window: "now", observedAt: maximumTimestamp, asOf: maximumTimestamp, goals: [], families: [] },
12
+ day: { window: "day", observedAt: maximumTimestamp, asOf: maximumTimestamp, goals: [], families: [] },
13
+ week: { window: "week", observedAt: maximumTimestamp, asOf: maximumTimestamp, goals: [], families: [] },
14
+ month: { window: "month", observedAt: maximumTimestamp, asOf: maximumTimestamp, goals: [], families: [] }
15
+ });
16
+ export const workMaximumSnapshotBytesForHistory = (history) => {
17
+ const maximumGoalBytes = new Map();
18
+ let encodedGoals = 0;
19
+ const latest = new Map();
20
+ for (const event of history) {
21
+ const { goal } = event;
22
+ const bytes = encodedBytes(goal);
23
+ const previous = maximumGoalBytes.get(goal.id);
24
+ if (previous === undefined) {
25
+ maximumGoalBytes.set(goal.id, bytes);
26
+ encodedGoals += bytes;
27
+ }
28
+ else if (bytes > previous) {
29
+ maximumGoalBytes.set(goal.id, bytes);
30
+ encodedGoals += bytes - previous;
31
+ }
32
+ const previousLatest = latest.get(goal.id);
33
+ if (previousLatest === undefined || previousLatest.occurredAt <= event.occurredAt) {
34
+ latest.set(goal.id, event);
35
+ }
36
+ }
37
+ const separators = Math.max(0, maximumGoalBytes.size - 1);
38
+ const supersededCounts = new Map();
39
+ for (const { goal } of latest.values()) {
40
+ if (goal.goalFamily?.role === "superseded") {
41
+ const count = supersededCounts.get(goal.goalFamily.canonicalGoalId) ?? 0;
42
+ supersededCounts.set(goal.goalFamily.canonicalGoalId, count + 1);
43
+ }
44
+ }
45
+ let canonicalBytesSum = 0;
46
+ let familyGroupsOverheadSum = 0;
47
+ for (const [canonicalGoalId, supersededCount] of supersededCounts) {
48
+ if (supersededCount > 0 && latest.get(canonicalGoalId)?.goal.goalFamily?.role === "canonical") {
49
+ canonicalBytesSum += maximumGoalBytes.get(canonicalGoalId) ?? 0;
50
+ familyGroupsOverheadSum += encodedBytes(canonicalGoalId) + 64;
51
+ }
52
+ }
53
+ const familiesPerWindowBytes = encodedGoals + canonicalBytesSum + familyGroupsOverheadSum + separators;
54
+ return workAgentBindingSnapshotEnvelopeMaxBytes +
55
+ 4 * Math.max(encodedGoals + separators, familiesPerWindowBytes);
56
+ };
57
+ export const workAgentBindingMaximumSnapshotBytes = (history, candidate) => workMaximumSnapshotBytesForHistory([...history, candidate]);
58
+ export const agentBindingAdmissionError = (input) => {
59
+ if (input.history.length >= workHistoryMaxEvents) {
60
+ return new WorkProjectionError({
61
+ cause: input.candidate,
62
+ detail: `work history cannot exceed ${workHistoryMaxEvents} checkpoints`,
63
+ reason: "capacity_exceeded"
64
+ });
65
+ }
66
+ const historyError = workHistoryError([...input.history, input.candidate]);
67
+ if (historyError !== undefined)
68
+ return historyError;
69
+ if (workAgentBindingMaximumSnapshotBytes(input.history, input.candidate) > fleetResponseBodyMaxBytes) {
70
+ return new WorkProjectionError({
71
+ cause: input.candidate,
72
+ detail: `work snapshots cannot exceed ${fleetResponseBodyMaxBytes} encoded bytes`,
73
+ reason: "capacity_exceeded"
74
+ });
75
+ }
76
+ if (input.operationCount >= workAgentBindingLaneOperationMaxRecords) {
77
+ return new WorkProjectionError({
78
+ cause: input.candidate,
79
+ detail: `work lane operation history cannot exceed ${workAgentBindingLaneOperationMaxRecords} operation IDs`,
80
+ reason: "capacity_exceeded"
81
+ });
82
+ }
83
+ if (input.operationBytes + input.candidateOperationBytes >
84
+ workAgentBindingLaneOperationMaxBytes) {
85
+ return new WorkProjectionError({
86
+ cause: input.candidate,
87
+ detail: `work lane operation history cannot exceed ${workAgentBindingLaneOperationMaxBytes} encoded bytes`,
88
+ reason: "capacity_exceeded"
89
+ });
90
+ }
91
+ };
92
+ //# sourceMappingURL=agent-binding-admission.js.map