@danypops/vehicle-core 0.16.0 → 0.17.1

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 (123) hide show
  1. package/README.md +12 -0
  2. package/dist/{vehicle-approvals.d.ts → approvals/approval.d.ts} +4 -11
  3. package/dist/{vehicle-approvals.js → approvals/approval.js} +53 -12
  4. package/dist/approvals/index.d.ts +1 -0
  5. package/dist/approvals/index.js +1 -0
  6. package/dist/client/client.d.ts +29 -0
  7. package/dist/client/client.js +1 -0
  8. package/dist/client/index.d.ts +1 -0
  9. package/dist/client/index.js +1 -0
  10. package/dist/content/content.d.ts +32 -0
  11. package/dist/content/content.js +25 -0
  12. package/dist/content/index.d.ts +1 -0
  13. package/dist/content/index.js +1 -0
  14. package/dist/{vehicle-errors.d.ts → errors/error.d.ts} +22 -10
  15. package/dist/{vehicle-errors.js → errors/error.js} +20 -0
  16. package/dist/errors/index.d.ts +1 -0
  17. package/dist/errors/index.js +1 -0
  18. package/dist/events/event.d.ts +42 -0
  19. package/dist/events/event.js +35 -0
  20. package/dist/events/index.d.ts +1 -0
  21. package/dist/events/index.js +1 -0
  22. package/dist/idempotency/index.d.ts +1 -0
  23. package/dist/idempotency/index.js +1 -0
  24. package/dist/idempotency/receipt.d.ts +66 -0
  25. package/dist/idempotency/receipt.js +42 -0
  26. package/dist/index.d.ts +26 -7
  27. package/dist/index.js +26 -7
  28. package/dist/jobs/identity.d.ts +11 -0
  29. package/dist/jobs/identity.js +13 -0
  30. package/dist/jobs/index.d.ts +7 -0
  31. package/dist/jobs/index.js +7 -0
  32. package/dist/jobs/replay.d.ts +8 -0
  33. package/dist/jobs/replay.js +9 -0
  34. package/dist/jobs/retention.d.ts +26 -0
  35. package/dist/jobs/retention.js +39 -0
  36. package/dist/jobs/steer.d.ts +23 -0
  37. package/dist/jobs/steer.js +41 -0
  38. package/dist/jobs/termination.d.ts +5 -0
  39. package/dist/jobs/termination.js +11 -0
  40. package/dist/jobs/wake-log.d.ts +39 -0
  41. package/dist/jobs/wake-log.js +65 -0
  42. package/dist/jobs/wire.d.ts +47 -0
  43. package/dist/jobs/wire.js +1 -0
  44. package/dist/manifest/index.d.ts +1 -0
  45. package/dist/manifest/index.js +1 -0
  46. package/dist/manifest/manifest.d.ts +49 -0
  47. package/dist/manifest/manifest.js +1 -0
  48. package/dist/operations/context.d.ts +52 -0
  49. package/dist/operations/context.js +1 -0
  50. package/dist/operations/effect.d.ts +3 -0
  51. package/dist/operations/effect.js +2 -0
  52. package/dist/operations/index.d.ts +3 -0
  53. package/dist/operations/index.js +3 -0
  54. package/dist/operations/operation.d.ts +98 -0
  55. package/dist/operations/operation.js +79 -0
  56. package/dist/{atomic-json.d.ts → persistence/atomic-json.d.ts} +1 -2
  57. package/dist/{atomic-json.js → persistence/atomic-json.js} +1 -2
  58. package/dist/persistence/index.d.ts +1 -0
  59. package/dist/persistence/index.js +1 -0
  60. package/dist/schedules/index.d.ts +1 -0
  61. package/dist/schedules/index.js +1 -0
  62. package/dist/{vehicle-scheduler.d.ts → schedules/schedule.d.ts} +23 -9
  63. package/dist/schedules/schedule.js +61 -0
  64. package/dist/schemas/codec.d.ts +25 -0
  65. package/dist/schemas/codec.js +7 -0
  66. package/dist/schemas/index.d.ts +4 -0
  67. package/dist/schemas/index.js +4 -0
  68. package/dist/schemas/json.d.ts +7 -0
  69. package/dist/schemas/json.js +14 -0
  70. package/dist/schemas/loose-object.d.ts +20 -0
  71. package/dist/schemas/loose-object.js +73 -0
  72. package/dist/schemas/presentation.d.ts +11 -0
  73. package/dist/schemas/presentation.js +22 -0
  74. package/dist/watches/index.d.ts +1 -0
  75. package/dist/watches/index.js +1 -0
  76. package/dist/{vehicle-watchers.d.ts → watches/registry.d.ts} +2 -9
  77. package/dist/{vehicle-watchers.js → watches/registry.js} +2 -9
  78. package/package.json +5 -1
  79. package/src/{vehicle-approvals.ts → approvals/approval.ts} +47 -13
  80. package/src/approvals/index.ts +1 -0
  81. package/src/client/client.ts +31 -0
  82. package/src/client/index.ts +1 -0
  83. package/src/content/content.ts +46 -0
  84. package/src/content/index.ts +1 -0
  85. package/src/{vehicle-errors.ts → errors/error.ts} +32 -9
  86. package/src/errors/index.ts +1 -0
  87. package/src/events/event.ts +72 -0
  88. package/src/events/index.ts +1 -0
  89. package/src/idempotency/index.ts +1 -0
  90. package/src/idempotency/receipt.ts +97 -0
  91. package/src/index.ts +26 -7
  92. package/src/jobs/identity.ts +13 -0
  93. package/src/jobs/index.ts +7 -0
  94. package/src/jobs/replay.ts +17 -0
  95. package/src/jobs/retention.ts +59 -0
  96. package/src/jobs/steer.ts +49 -0
  97. package/src/jobs/termination.ts +13 -0
  98. package/src/jobs/wake-log.ts +98 -0
  99. package/src/jobs/wire.ts +51 -0
  100. package/src/manifest/index.ts +1 -0
  101. package/src/manifest/manifest.ts +52 -0
  102. package/src/operations/context.ts +56 -0
  103. package/src/operations/effect.ts +3 -0
  104. package/src/operations/index.ts +3 -0
  105. package/src/operations/operation.ts +184 -0
  106. package/src/{atomic-json.ts → persistence/atomic-json.ts} +1 -2
  107. package/src/persistence/index.ts +1 -0
  108. package/src/schedules/index.ts +1 -0
  109. package/src/{vehicle-scheduler.ts → schedules/schedule.ts} +32 -9
  110. package/src/schemas/codec.ts +30 -0
  111. package/src/schemas/index.ts +4 -0
  112. package/src/schemas/json.ts +17 -0
  113. package/src/schemas/loose-object.ts +82 -0
  114. package/src/schemas/presentation.ts +28 -0
  115. package/src/watches/index.ts +1 -0
  116. package/src/{vehicle-watchers.ts → watches/registry.ts} +2 -9
  117. package/dist/vehicle-contract.d.ts +0 -347
  118. package/dist/vehicle-contract.js +0 -219
  119. package/dist/vehicle-jobs.d.ts +0 -159
  120. package/dist/vehicle-jobs.js +0 -182
  121. package/dist/vehicle-scheduler.js +0 -33
  122. package/src/vehicle-contract.ts +0 -563
  123. package/src/vehicle-jobs.ts +0 -305
@@ -1,159 +0,0 @@
1
- /** Pure pieces of Vehicle Jobs: a termination-reason resolver and a bounded wake-log accumulator. Orchestration lives in vehicle-server's VehicleJobStore. */
2
- import type { VehiclePrincipal } from "./vehicle-contract.js";
3
- import type { VehicleFailure } from "./vehicle-errors.js";
4
- export type VehicleJobStatus = "running" | "succeeded" | "failed" | "canceled";
5
- /** Highest precedence first -- an explicit cancel always wins even if the handler also settled around the same time. "orphaned" is a restart-reconciliation outcome: a job that was still "running" when its process died, so nothing ever really failed or succeeded -- the record's own status just goes stale. */
6
- export declare const VEHICLE_JOB_TERMINATION_PRECEDENCE: readonly ["canceled", "timeout", "orphaned", "failed", "succeeded"];
7
- export type VehicleJobTerminationReason = (typeof VEHICLE_JOB_TERMINATION_PRECEDENCE)[number];
8
- export declare function resolveVehicleJobTerminationReason(candidates: readonly VehicleJobTerminationReason[]): VehicleJobTerminationReason;
9
- /** "always" keeps every notification; "transition" drops one identical to the last (hash dedup); "first-only" keeps just the first. */
10
- export type VehicleJobNotifyMode = "always" | "transition" | "first-only";
11
- export interface VehicleJobWakeBudget {
12
- readonly maxCount: number;
13
- readonly maxBytes: number;
14
- }
15
- export type VehicleJobWakeDropReason = "count-budget-exhausted" | "byte-budget-exhausted" | "deduplicated-transition" | "superseded-by-first-only";
16
- export interface VehicleJobWakeEntry {
17
- readonly seq: number;
18
- readonly at: number;
19
- readonly progress: unknown;
20
- }
21
- export interface VehicleJobWakeAppendResult {
22
- readonly accepted: boolean;
23
- readonly entry?: VehicleJobWakeEntry;
24
- readonly dropReason?: VehicleJobWakeDropReason;
25
- }
26
- export interface VehicleJobWakeLogOptions {
27
- readonly notifyMode: VehicleJobNotifyMode;
28
- readonly budget: VehicleJobWakeBudget;
29
- /** Defaults to Date.now. */
30
- readonly now?: () => number;
31
- }
32
- /** Bounds a job's accumulated progress notifications by count+bytes, same discipline as enforcePayloadSize but across a job's whole lifetime. */
33
- export declare class VehicleJobWakeLog {
34
- private readonly options;
35
- private readonly entries;
36
- private usedBytes;
37
- private nextSeq;
38
- private lastHash;
39
- private acceptedFirst;
40
- private readonly now;
41
- constructor(options: VehicleJobWakeLogOptions);
42
- append(progress: unknown): VehicleJobWakeAppendResult;
43
- /** Entries with seq strictly greater than `cursor`. */
44
- since(cursor: number): readonly VehicleJobWakeEntry[];
45
- /** Highest seq issued so far (0 if none accepted yet). */
46
- get cursor(): number;
47
- }
48
- /** Read-only replay side of a wake log -- both a live VehicleJobWakeLog and a restored (no-longer-appendable) job satisfy this with the same tail() semantics. */
49
- export interface VehicleJobWakeLogReader {
50
- since(cursor: number): readonly VehicleJobWakeEntry[];
51
- readonly cursor: number;
52
- }
53
- /** Wraps a fixed, already-finalized list of entries (e.g. restored from disk) in the same reader shape a live VehicleJobWakeLog exposes, so VehicleJobStore.tail() doesn't need to special-case a restored job. */
54
- export declare function createStaticVehicleJobWakeLog(entries: readonly VehicleJobWakeEntry[]): VehicleJobWakeLogReader;
55
- /**
56
- * A job's mid-flight input channel -- the "steer" primitive. Bounded FIFO:
57
- * push() while a handler isn't yet reading buffers up to maxQueueSize, then
58
- * refuses further input rather than growing unboundedly or silently
59
- * overwriting an unread entry. A handler consumes it via `for await (const
60
- * input of context.steerInputs)`, which ends cleanly once close() is
61
- * called (VehicleJobStore does this at job finalization).
62
- */
63
- export interface VehicleJobSteerPushResult {
64
- readonly accepted: boolean;
65
- readonly dropReason?: "queue-full" | "channel-closed";
66
- }
67
- export declare class VehicleJobSteerChannel implements AsyncIterable<unknown> {
68
- private readonly maxQueueSize;
69
- private readonly buffer;
70
- private readonly waiters;
71
- private closed;
72
- constructor(maxQueueSize?: number);
73
- push(value: unknown): VehicleJobSteerPushResult;
74
- /** Ends every pending and future iteration with done:true; further push() calls report "channel-closed". Idempotent. */
75
- close(): void;
76
- [Symbol.asyncIterator](): AsyncIterator<unknown>;
77
- }
78
- /**
79
- * Vehicle Jobs run as in-process promises, not child processes -- there is
80
- * no PID to reuse, but the same identity-confusion risk vstack's
81
- * {pid, startToken, comm} design guards against still applies in a
82
- * generalized form: a persisted job record written by one process
83
- * instance must never be mistaken for one this (possibly restarted)
84
- * instance can still resolve. Each VehicleJobStore construction gets a
85
- * fresh random instanceToken; a persisted record's own stamped token only
86
- * ever matches the instance that wrote it. A mismatch means "the original
87
- * run is gone", the same conclusion vstack's identityMatches() reaches by
88
- * comparing a live process's actual pid/start-time/command against a
89
- * stored snapshot -- this is that same check with no process to inspect.
90
- */
91
- export declare function vehicleJobIdentityMatches(recordInstanceToken: string, currentInstanceToken: string): boolean;
92
- /** Minimal shape selectVehicleJobsForEviction needs from a job record -- kept separate from VehicleJobSnapshot so vehicle-server doesn't have to construct a full snapshot just to ask "should this be swept". */
93
- export interface VehicleJobEvictionCandidate {
94
- readonly jobId: string;
95
- readonly status: VehicleJobStatus;
96
- readonly delivered: boolean;
97
- readonly updatedAt: number;
98
- }
99
- export interface VehicleJobRetentionOptions {
100
- /** Hard cap on total retained job records (of any status). A running job is never evicted regardless of this cap. */
101
- readonly maxRetainedJobs: number;
102
- /** A delivered terminal job becomes eligible for eviction once this many ms have passed since it was delivered (== updatedAt at delivery time). */
103
- readonly deliveredRetentionMs: number;
104
- readonly now: number;
105
- }
106
- /**
107
- * The client-facing wire shapes for Vehicle Jobs -- submit/poll/tail options and results, shared by
108
- * vehicle-server's VehicleJobStore (the orchestration side) and vehicle-client's job-capable clients
109
- * (the calling side), so both halves of the wire agree on one definition instead of two structurally
110
- *-identical copies drifting apart. Every field type referenced here already lives in vehicle-core
111
- * (VehiclePrincipal, VehicleFailure, VehicleJobStatus, ...), which is what makes it safe for these
112
- * shapes to live here too, alongside the rest of Vehicle Jobs' pure pieces.
113
- */
114
- export interface VehicleJobSubmitOptions {
115
- readonly permissions?: readonly string[];
116
- readonly principal?: VehiclePrincipal;
117
- readonly idempotencyKey?: string;
118
- readonly expectedRevision?: string | number;
119
- readonly approvalCapability?: string;
120
- readonly correlationId?: string;
121
- readonly callerSessionId?: string;
122
- readonly callerProjectRoot?: string;
123
- /** Defaults to "transition". */
124
- readonly notifyMode?: VehicleJobNotifyMode;
125
- /** Defaults to background.defaultWakeBudget; clamped to background.maxWakeBudget either way. */
126
- readonly wakeBudget?: VehicleJobWakeBudget;
127
- /** No default -- unset means the job runs until it settles or is canceled. */
128
- readonly maxLifetimeMs?: number;
129
- }
130
- export interface VehicleJobSubmitResult {
131
- readonly jobId: string;
132
- }
133
- export interface VehicleJobSnapshot {
134
- readonly jobId: string;
135
- readonly operationName: string;
136
- readonly operationVersion: number;
137
- readonly status: VehicleJobStatus;
138
- readonly createdAt: number;
139
- readonly updatedAt: number;
140
- readonly delivered: boolean;
141
- readonly terminationReason?: VehicleJobTerminationReason;
142
- readonly output?: unknown;
143
- readonly error?: VehicleFailure;
144
- }
145
- export interface VehicleJobTailResult {
146
- readonly entries: readonly VehicleJobWakeEntry[];
147
- readonly cursor: number;
148
- }
149
- /**
150
- * Pure eviction-selection policy, kept separate from VehicleJobStore's own
151
- * bookkeeping so the bounded-retention rule is independently testable.
152
- * Preference order: (1) delivered and past deliveredRetentionMs, oldest
153
- * first; (2) once still over maxRetainedJobs, any delivered terminal job,
154
- * oldest first; (3) only as a last resort, an undelivered terminal job,
155
- * oldest first -- a real loss (a caller may still want that result), but
156
- * an unbounded store is a worse failure mode. A running job is never a
157
- * candidate.
158
- */
159
- export declare function selectVehicleJobsForEviction(candidates: readonly VehicleJobEvictionCandidate[], options: VehicleJobRetentionOptions): readonly string[];
@@ -1,182 +0,0 @@
1
- /** Pure pieces of Vehicle Jobs: a termination-reason resolver and a bounded wake-log accumulator. Orchestration lives in vehicle-server's VehicleJobStore. */
2
- /** Highest precedence first -- an explicit cancel always wins even if the handler also settled around the same time. "orphaned" is a restart-reconciliation outcome: a job that was still "running" when its process died, so nothing ever really failed or succeeded -- the record's own status just goes stale. */
3
- export const VEHICLE_JOB_TERMINATION_PRECEDENCE = ["canceled", "timeout", "orphaned", "failed", "succeeded"];
4
- export function resolveVehicleJobTerminationReason(candidates) {
5
- if (candidates.length === 0)
6
- throw new Error("resolveVehicleJobTerminationReason requires at least one candidate");
7
- for (const reason of VEHICLE_JOB_TERMINATION_PRECEDENCE) {
8
- if (candidates.includes(reason))
9
- return reason;
10
- }
11
- throw new Error(`Unrecognized Vehicle job termination candidate(s): ${candidates.join(", ")}`);
12
- }
13
- /** Bounds a job's accumulated progress notifications by count+bytes, same discipline as enforcePayloadSize but across a job's whole lifetime. */
14
- export class VehicleJobWakeLog {
15
- options;
16
- entries = [];
17
- usedBytes = 0;
18
- nextSeq = 1;
19
- lastHash;
20
- acceptedFirst = false;
21
- now;
22
- constructor(options) {
23
- this.options = options;
24
- this.now = options.now ?? Date.now;
25
- }
26
- append(progress) {
27
- if (this.options.notifyMode === "first-only" && this.acceptedFirst) {
28
- return { accepted: false, dropReason: "superseded-by-first-only" };
29
- }
30
- const serialized = safeJsonStringify(progress);
31
- if (this.options.notifyMode === "transition") {
32
- const hash = fnv1aHash(serialized);
33
- if (hash === this.lastHash)
34
- return { accepted: false, dropReason: "deduplicated-transition" };
35
- this.lastHash = hash;
36
- }
37
- const bytes = new TextEncoder().encode(serialized).byteLength;
38
- if (this.entries.length >= this.options.budget.maxCount)
39
- return { accepted: false, dropReason: "count-budget-exhausted" };
40
- if (this.usedBytes + bytes > this.options.budget.maxBytes)
41
- return { accepted: false, dropReason: "byte-budget-exhausted" };
42
- const entry = { seq: this.nextSeq++, at: this.now(), progress };
43
- this.entries.push(entry);
44
- this.usedBytes += bytes;
45
- this.acceptedFirst = true;
46
- return { accepted: true, entry };
47
- }
48
- /** Entries with seq strictly greater than `cursor`. */
49
- since(cursor) {
50
- return this.entries.filter((entry) => entry.seq > cursor);
51
- }
52
- /** Highest seq issued so far (0 if none accepted yet). */
53
- get cursor() {
54
- return this.nextSeq - 1;
55
- }
56
- }
57
- function safeJsonStringify(value) {
58
- let serialized;
59
- try {
60
- serialized = JSON.stringify(value);
61
- }
62
- catch (error) {
63
- throw new Error("Vehicle job progress value is not JSON-serializable", { cause: error });
64
- }
65
- if (serialized === undefined)
66
- throw new Error("Vehicle job progress value is not JSON-serializable");
67
- return serialized;
68
- }
69
- /** Non-cryptographic (FNV-1a) -- dedup only. */
70
- function fnv1aHash(value) {
71
- let hash = 0x811c9dc5;
72
- for (let i = 0; i < value.length; i++) {
73
- hash ^= value.charCodeAt(i);
74
- hash = Math.imul(hash, 0x01000193);
75
- }
76
- return (hash >>> 0).toString(16);
77
- }
78
- /** Wraps a fixed, already-finalized list of entries (e.g. restored from disk) in the same reader shape a live VehicleJobWakeLog exposes, so VehicleJobStore.tail() doesn't need to special-case a restored job. */
79
- export function createStaticVehicleJobWakeLog(entries) {
80
- const sorted = [...entries].sort((a, b) => a.seq - b.seq);
81
- const cursor = sorted.length > 0 ? sorted[sorted.length - 1].seq : 0;
82
- return {
83
- since: (cursorArg) => sorted.filter((entry) => entry.seq > cursorArg),
84
- cursor,
85
- };
86
- }
87
- export class VehicleJobSteerChannel {
88
- maxQueueSize;
89
- buffer = [];
90
- waiters = [];
91
- closed = false;
92
- constructor(maxQueueSize = 64) {
93
- this.maxQueueSize = maxQueueSize;
94
- }
95
- push(value) {
96
- if (this.closed)
97
- return { accepted: false, dropReason: "channel-closed" };
98
- const waiter = this.waiters.shift();
99
- if (waiter) {
100
- waiter({ value, done: false });
101
- return { accepted: true };
102
- }
103
- if (this.buffer.length >= this.maxQueueSize)
104
- return { accepted: false, dropReason: "queue-full" };
105
- this.buffer.push(value);
106
- return { accepted: true };
107
- }
108
- /** Ends every pending and future iteration with done:true; further push() calls report "channel-closed". Idempotent. */
109
- close() {
110
- if (this.closed)
111
- return;
112
- this.closed = true;
113
- for (const waiter of this.waiters.splice(0))
114
- waiter({ value: undefined, done: true });
115
- }
116
- [Symbol.asyncIterator]() {
117
- return {
118
- next: () => {
119
- if (this.buffer.length > 0)
120
- return Promise.resolve({ value: this.buffer.shift(), done: false });
121
- if (this.closed)
122
- return Promise.resolve({ value: undefined, done: true });
123
- return new Promise((resolve) => this.waiters.push(resolve));
124
- },
125
- };
126
- }
127
- }
128
- /**
129
- * Vehicle Jobs run as in-process promises, not child processes -- there is
130
- * no PID to reuse, but the same identity-confusion risk vstack's
131
- * {pid, startToken, comm} design guards against still applies in a
132
- * generalized form: a persisted job record written by one process
133
- * instance must never be mistaken for one this (possibly restarted)
134
- * instance can still resolve. Each VehicleJobStore construction gets a
135
- * fresh random instanceToken; a persisted record's own stamped token only
136
- * ever matches the instance that wrote it. A mismatch means "the original
137
- * run is gone", the same conclusion vstack's identityMatches() reaches by
138
- * comparing a live process's actual pid/start-time/command against a
139
- * stored snapshot -- this is that same check with no process to inspect.
140
- */
141
- export function vehicleJobIdentityMatches(recordInstanceToken, currentInstanceToken) {
142
- return recordInstanceToken === currentInstanceToken;
143
- }
144
- /**
145
- * Pure eviction-selection policy, kept separate from VehicleJobStore's own
146
- * bookkeeping so the bounded-retention rule is independently testable.
147
- * Preference order: (1) delivered and past deliveredRetentionMs, oldest
148
- * first; (2) once still over maxRetainedJobs, any delivered terminal job,
149
- * oldest first; (3) only as a last resort, an undelivered terminal job,
150
- * oldest first -- a real loss (a caller may still want that result), but
151
- * an unbounded store is a worse failure mode. A running job is never a
152
- * candidate.
153
- */
154
- export function selectVehicleJobsForEviction(candidates, options) {
155
- const terminal = candidates.filter((candidate) => candidate.status !== "running");
156
- const byAgeAscending = (a, b) => a.updatedAt - b.updatedAt;
157
- const evicted = new Set();
158
- for (const candidate of terminal) {
159
- if (candidate.delivered && options.now - candidate.updatedAt >= options.deliveredRetentionMs)
160
- evicted.add(candidate.jobId);
161
- }
162
- const remainingCount = () => candidates.length - evicted.size;
163
- if (remainingCount() > options.maxRetainedJobs) {
164
- const deliveredOldestFirst = terminal.filter((candidate) => candidate.delivered && !evicted.has(candidate.jobId)).sort(byAgeAscending);
165
- for (const candidate of deliveredOldestFirst) {
166
- if (remainingCount() <= options.maxRetainedJobs)
167
- break;
168
- evicted.add(candidate.jobId);
169
- }
170
- }
171
- if (remainingCount() > options.maxRetainedJobs) {
172
- const undeliveredOldestFirst = terminal
173
- .filter((candidate) => !candidate.delivered && !evicted.has(candidate.jobId))
174
- .sort(byAgeAscending);
175
- for (const candidate of undeliveredOldestFirst) {
176
- if (remainingCount() <= options.maxRetainedJobs)
177
- break;
178
- evicted.add(candidate.jobId);
179
- }
180
- }
181
- return [...evicted];
182
- }
@@ -1,33 +0,0 @@
1
- /** Matches WatchRegistry's own historical default (Lector's MAX_WATCHES_PER_WORKSPACE). */
2
- export const DEFAULT_MAX_SCHEDULES_PER_OWNER = 32;
3
- /** Raised when an owner already has its configured maximum of schedules -- fails closed, the same bounded-resource discipline WatchLimitExceeded already applies to Vehicle Watchers. */
4
- export class VehicleScheduleLimitExceeded extends Error {
5
- owner;
6
- max;
7
- constructor(owner, max) {
8
- super(`owner "${owner}" already has ${max} active schedules -- cancel one before adding another`);
9
- this.owner = owner;
10
- this.max = max;
11
- this.name = "VehicleScheduleLimitExceeded";
12
- }
13
- }
14
- /** The first fire time for a freshly created schedule. */
15
- export function initialFireAt(trigger, now) {
16
- return trigger.kind === "at" ? trigger.at : now + trigger.intervalMs;
17
- }
18
- /** The next fire time after a successful fire, or undefined if the entry (a one-shot "at") should be removed instead of re-armed. */
19
- export function nextFireAtAfterFire(trigger, now) {
20
- return trigger.kind === "every" ? now + trigger.intervalMs : undefined;
21
- }
22
- /**
23
- * Where a restored entry should be re-armed to. A one-shot "at" entry keeps
24
- * its original persisted time (fires as soon as possible if overdue -- the
25
- * one thing it was supposed to do must not be silently lost). A recurring
26
- * "every" entry resumes its normal cadence from now if it fell behind while
27
- * the daemon was down, rather than firing once per missed tick.
28
- */
29
- export function nextFireAtAfterRestore(trigger, persistedNextFireAt, now) {
30
- if (trigger.kind === "at")
31
- return persistedNextFireAt;
32
- return persistedNextFireAt > now ? persistedNextFireAt : now + trigger.intervalMs;
33
- }