@atolis-hq/wake 0.4.105 → 0.4.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/activities/agent/agent-activity.js +7 -0
- package/dist/src/activities/contracts/activity.d.ts +12 -0
- package/dist/src/activities/contracts/event-schema.d.ts +314 -8
- package/dist/src/activities/contracts/event-schema.js +20 -2
- package/dist/src/activities/contracts/events.d.ts +10 -0
- package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
- package/dist/src/activities/contracts/vocabulary.js +2 -0
- package/dist/src/activities/index.d.ts +2 -0
- package/dist/src/activities/index.js +2 -0
- package/dist/src/activities/pr/activity-support.d.ts +1 -1
- package/dist/src/activities/pr/activity-support.js +10 -0
- package/dist/src/activities/pr/application.js +31 -10
- package/dist/src/activities/pr/approve.d.ts +2 -1
- package/dist/src/activities/pr/approve.js +33 -11
- package/dist/src/activities/pr/check-evidence.d.ts +10 -0
- package/dist/src/activities/pr/check-evidence.js +16 -0
- package/dist/src/activities/pr/contracts.d.ts +14 -0
- package/dist/src/activities/pr/event-data.js +5 -1
- package/dist/src/activities/pr/merge.d.ts +2 -1
- package/dist/src/activities/pr/merge.js +54 -38
- package/dist/src/activities/pr/parent-scope.d.ts +65 -0
- package/dist/src/activities/pr/parent-scope.js +24 -0
- package/dist/src/activities/pr/parent-target.d.ts +45 -0
- package/dist/src/activities/pr/parent-target.js +59 -0
- package/dist/src/activities/pr/projection.js +10 -2
- package/dist/src/activities/pr/vocabulary.d.ts +8 -0
- package/dist/src/activities/pr/vocabulary.js +8 -0
- package/dist/src/bootstrap/activity-registry.d.ts +2 -2
- package/dist/src/bootstrap/activity-registry.js +3 -3
- package/dist/src/bootstrap/composition-root.js +12 -3
- package/dist/src/bootstrap/config/root-schema.d.ts +6 -0
- package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
- package/dist/src/bootstrap/delivery-integration.js +46 -0
- package/dist/src/bootstrap/surface-api-delivery.js +27 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
- package/dist/src/control-plane/application/advance-once-dispatch.js +10 -6
- package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
- package/dist/src/conversations/application/conversation-repository.js +3 -1
- package/dist/src/execution/application/execution-service.js +10 -0
- package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
- package/dist/src/execution/application/maintenance-workspaces.js +84 -0
- package/dist/src/execution/application/run-lifecycle.js +1 -0
- package/dist/src/execution/application/run-repository.js +27 -10
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +13 -0
- package/dist/src/execution/contracts/events.js +2 -0
- package/dist/src/execution/contracts/maintenance.d.ts +36 -0
- package/dist/src/execution/contracts/maintenance.js +44 -0
- package/dist/src/execution/contracts/views.d.ts +2 -0
- package/dist/src/execution/contracts/workspace.d.ts +2 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +7 -14
- package/dist/src/integrations/application/delegation-outputs.js +1 -1
- package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
- package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
- package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
- package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
- package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
- package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
- package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
- package/dist/src/integrations/fake/external-source.d.ts +5 -2
- package/dist/src/integrations/fake/external-source.js +12 -2
- package/dist/src/integrations/fake/inbound-translator.js +7 -2
- package/dist/src/integrations/fake/provider.d.ts +17 -0
- package/dist/src/integrations/fake/provider.js +18 -2
- package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
- package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
- package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
- package/dist/src/integrations/github/contracts/events.d.ts +3 -1
- package/dist/src/integrations/github/contracts/events.js +3 -1
- package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
- package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
- package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
- package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/client.js +4 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
- package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
- package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
- package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
- package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
- package/dist/src/orchestration/application/advance-workflow.js +7 -2
- package/dist/src/orchestration/application/deferred-signals.js +2 -6
- package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
- package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
- package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
- package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
- package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
- package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
- package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
- package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
- package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
- package/dist/src/orchestration/application/delivery-preparation.js +7 -2
- package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
- package/dist/src/orchestration/application/orchestration-repository.js +139 -64
- package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
- package/dist/src/orchestration/application/orchestration-service.js +55 -2
- package/dist/src/orchestration/contracts/config.d.ts +6 -0
- package/dist/src/orchestration/contracts/config.js +6 -0
- package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
- package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
- package/dist/src/orchestration/contracts/delivery.js +53 -1
- package/dist/src/orchestration/contracts/event-decoder.js +2 -1
- package/dist/src/orchestration/contracts/event-factory.js +2 -0
- package/dist/src/orchestration/contracts/events.d.ts +3 -1
- package/dist/src/orchestration/contracts/events.js +1 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
- package/dist/src/orchestration/contracts/vocabulary.js +40 -1
- package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
- package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
- package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
- package/dist/src/orchestration/domain/delivery-facts.js +33 -1
- package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
- package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
- package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
- package/dist/src/orchestration/domain/delivery-integration.js +144 -0
- package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
- package/dist/src/orchestration/domain/delivery-qa.js +24 -4
- package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
- package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
- package/dist/src/orchestration/index.d.ts +3 -2
- package/dist/src/orchestration/index.js +1 -1
- package/dist/src/resources/application/resource-lookup.d.ts +2 -1
- package/dist/src/resources/application/resource-lookup.js +3 -11
- package/dist/src/resources/application/resource-repository.js +10 -10
- package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
- package/dist/src/surfaces/api/presenters/execution.js +1 -0
- package/dist/src/surfaces/mcp/delegation.js +5 -1
- package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
- package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +0 -1192
|
@@ -8,7 +8,8 @@ import { formatGitHubResourceKey } from '../contracts/external-key.js';
|
|
|
8
8
|
import { gitHubAssigneeLogins, gitHubLabelNames, } from '../contracts/payloads.js';
|
|
9
9
|
import { GitHubAdapter, GitHubCheckRunStatus, UnknownGitHubIdentity, UnknownGitHubRevision, } from '../contracts/vocabulary.js';
|
|
10
10
|
import { withoutWakeMarkers } from './content-fingerprint.js';
|
|
11
|
-
import {
|
|
11
|
+
import { verifiedCheckSubject } from './pr-check-subject.js';
|
|
12
|
+
import { readPullRequestEvidence, } from './pr-evidence.js';
|
|
12
13
|
export function createGitHubPullRequestSource(input) {
|
|
13
14
|
return {
|
|
14
15
|
async poll(signal) {
|
|
@@ -24,12 +25,14 @@ export async function pullRequestEventsFor(input, signal) {
|
|
|
24
25
|
signal.throwIfAborted();
|
|
25
26
|
const headRevision = fallback(pullRequest.head?.sha, pullRequest.updated_at);
|
|
26
27
|
const [evidence, changedFiles] = await readPullRequestEvidence(input.client, owner, repo, headRevision, pullRequest.number, input.maxResults);
|
|
28
|
+
const checkSubject = await verifiedCheckSubject(input.client, owner, repo, pullRequest, evidence);
|
|
27
29
|
return {
|
|
28
30
|
complete: evidence.complete && changedFiles.complete,
|
|
29
31
|
draft: pullRequestObservation({
|
|
30
32
|
repository: input.repository,
|
|
31
33
|
pullRequest,
|
|
32
34
|
evidence,
|
|
35
|
+
checkSubject,
|
|
33
36
|
changedFiles: changedFiles.files,
|
|
34
37
|
...(input.adapter === undefined ? {} : { adapter: input.adapter }),
|
|
35
38
|
}),
|
|
@@ -57,6 +60,7 @@ function pullRequestObservation(input) {
|
|
|
57
60
|
title: pullRequest.title,
|
|
58
61
|
body: fallback(pullRequest.body, ''),
|
|
59
62
|
state: pullRequestState(pullRequest),
|
|
63
|
+
...mergedRevision(pullRequest),
|
|
60
64
|
mergeability: pullRequest.mergeable === false
|
|
61
65
|
? PullRequestMergeability.Conflicting
|
|
62
66
|
: pullRequest.mergeable === true
|
|
@@ -66,6 +70,7 @@ function pullRequestObservation(input) {
|
|
|
66
70
|
headRevision: revision,
|
|
67
71
|
baseRevision: fallback(pullRequest.base?.sha, UnknownGitHubRevision),
|
|
68
72
|
checks,
|
|
73
|
+
...input.checkSubject,
|
|
69
74
|
actor: {
|
|
70
75
|
id: fallback(pullRequest.user?.login, UnknownGitHubIdentity),
|
|
71
76
|
kind: actorKind(pullRequest.user?.type),
|
|
@@ -198,3 +203,8 @@ const GitHubCommitStatusState = {
|
|
|
198
203
|
Pending: PullRequestCheckState.Pending,
|
|
199
204
|
Success: 'success',
|
|
200
205
|
};
|
|
206
|
+
function mergedRevision(pullRequest) {
|
|
207
|
+
return pullRequestState(pullRequest) === PullRequestState.Merged && pullRequest.merge_commit_sha
|
|
208
|
+
? { mergeRevision: pullRequest.merge_commit_sha }
|
|
209
|
+
: {};
|
|
210
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
import type { GitHubWorkflowRunPayload } from '../contracts/payloads.js';
|
|
3
|
+
import { type createEtagCache } from './etag-cache.js';
|
|
4
|
+
/** Revalidate mutable run attempts; conditional requests reuse unchanged responses. */
|
|
5
|
+
export declare function workflowRunsForSuite(octokit: Octokit, cache: ReturnType<typeof createEtagCache>, owner: string, repo: string, suiteId: number): Promise<readonly GitHubWorkflowRunPayload[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fetchWithEtag } from './etag-cache.js';
|
|
2
|
+
/** Revalidate mutable run attempts; conditional requests reuse unchanged responses. */
|
|
3
|
+
export function workflowRunsForSuite(octokit, cache, owner, repo, suiteId) {
|
|
4
|
+
return fetchWithEtag({
|
|
5
|
+
cache,
|
|
6
|
+
key: `workflow-run-suite:${owner}/${repo}@${suiteId}`,
|
|
7
|
+
request: async (headers) => {
|
|
8
|
+
const response = await octokit.rest.actions.listWorkflowRunsForRepo({
|
|
9
|
+
owner,
|
|
10
|
+
repo,
|
|
11
|
+
check_suite_id: suiteId,
|
|
12
|
+
event: 'pull_request',
|
|
13
|
+
per_page: 100,
|
|
14
|
+
...(headers === undefined ? {} : { headers }),
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
data: response.data.total_count >= 100 ? [] : response.data.workflow_runs,
|
|
18
|
+
...(response.headers.etag === undefined ? {} : { etag: response.headers.etag }),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -33,3 +33,4 @@ export * from './fake/external-source.js';
|
|
|
33
33
|
export * from './fake/provider.js';
|
|
34
34
|
export * from './application/conversation-command-feedback.js';
|
|
35
35
|
export { createDelegationOutputs } from './application/delegation-outputs.js';
|
|
36
|
+
export * from './application/delivery-integration-verification.js';
|
|
@@ -33,3 +33,4 @@ export * from './fake/external-source.js';
|
|
|
33
33
|
export * from './fake/provider.js';
|
|
34
34
|
export * from './application/conversation-command-feedback.js';
|
|
35
35
|
export { createDelegationOutputs } from './application/delegation-outputs.js';
|
|
36
|
+
export * from './application/delivery-integration-verification.js';
|
|
@@ -7,7 +7,7 @@ export type { CausationId, CorrelationId, EventId } from './contracts/identifier
|
|
|
7
7
|
export * from './contracts/processor-state-store.js';
|
|
8
8
|
export * from './projections/projection-processor.js';
|
|
9
9
|
export * from './projections/projection-store.js';
|
|
10
|
-
export * from './runtime/
|
|
10
|
+
export * from './runtime/journal-view.js';
|
|
11
11
|
export * from './runtime/clock.js';
|
|
12
12
|
export * from './runtime/event-processor-host.js';
|
|
13
13
|
export * from './runtime/processor-failure.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AAExC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEjF,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEtF,cAAc,sCAAsC,CAAC;AAErD,cAAc,uCAAuC,CAAC;AAEtD,cAAc,mCAAmC,CAAC;AAElD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AAExC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEjF,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEtF,cAAc,sCAAsC,CAAC;AAErD,cAAc,uCAAuC,CAAC;AAEtD,cAAc,mCAAmC,CAAC;AAElD,cAAc,2BAA2B,CAAC;AAE1C,cAAc,oBAAoB,CAAC;AAEnC,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC;AAE/C,cAAc,+BAA+B,CAAC;AAE9C,cAAc,uCAAuC,CAAC;AAEtD,cAAc,6BAA6B,CAAC;AAE5C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,oCAAoC,CAAC;AAEnD,cAAc,0CAA0C,CAAC;AAEzD,cAAc,yBAAyB,CAAC"}
|
|
@@ -6,7 +6,7 @@ export { causationId, correlationId, eventId } from './contracts/identifiers.js'
|
|
|
6
6
|
export * from './contracts/processor-state-store.js';
|
|
7
7
|
export * from './projections/projection-processor.js';
|
|
8
8
|
export * from './projections/projection-store.js';
|
|
9
|
-
export * from './runtime/
|
|
9
|
+
export * from './runtime/journal-view.js';
|
|
10
10
|
export * from './runtime/clock.js';
|
|
11
11
|
export * from './runtime/event-processor-host.js';
|
|
12
12
|
export * from './runtime/processor-failure.js';
|
package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts
CHANGED
|
@@ -7,6 +7,20 @@ import type { ProjectionDefinition, ProjectionStore } from './projection-store.j
|
|
|
7
7
|
export declare function projectionConsumer<Value>(definition: ProjectionDefinition<Value>): string;
|
|
8
8
|
export declare function createProjectionProcessor<Value>(definition: ProjectionDefinition<Value>, projections: ProjectionStore): EventProcessor;
|
|
9
9
|
export declare function applyProjectionEvent<Value>(definition: ProjectionDefinition<Value>, projections: ProjectionStore, key: string, event: EventEnvelope): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Reads one projected key with read-your-writes consistency: the stored value
|
|
12
|
+
* plus any events the projection processor has not applied yet. The tail starts
|
|
13
|
+
* at the processor's checkpoint, not the key's own last position: everything at
|
|
14
|
+
* or below the checkpoint is already applied for every key, whereas a quiet
|
|
15
|
+
* key's position can trail the head by the whole history. A rebuild resets the
|
|
16
|
+
* checkpoint before it clears the store, so the checkpoint is never ahead of
|
|
17
|
+
* the stored values it vouches for.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readCurrentProjection<Value>(dependencies: {
|
|
20
|
+
readonly journal: Pick<EventJournal, 'readAll'>;
|
|
21
|
+
readonly projections: ProjectionStore;
|
|
22
|
+
readonly checkpoints: Pick<CheckpointStore, 'load'>;
|
|
23
|
+
}, definition: ProjectionDefinition<Value>, key: string): Promise<Value>;
|
|
10
24
|
export declare function applyProjectionBatch<Value>(definition: ProjectionDefinition<Value>, projections: ProjectionStore, events: readonly EventEnvelope[], signal?: AbortSignal): Promise<void>;
|
|
11
25
|
export declare class ProjectionRebuilder {
|
|
12
26
|
private readonly journal;
|
package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection-processor.d.ts","sourceRoot":"","sources":["../../src/projections/projection-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CA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BAAoB,CAAC,KAAK,EAC9C,UAAU,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACvC,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,MAAM,GAAE,WAA0C,GACjD,OAAO,CAAC,IAAI,CAAC,CASf;AAED,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAHZ,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,eAAe,EAC5B,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,sBAAsB;IAGvD,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;YAQhF,aAAa;CAyB5B"}
|
|
@@ -26,6 +26,35 @@ export async function applyProjectionEvent(definition, projections, key, event)
|
|
|
26
26
|
value: definition.project(previous?.value ?? definition.initial(key), event),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
const catchUpBatchSize = 500;
|
|
30
|
+
/**
|
|
31
|
+
* Reads one projected key with read-your-writes consistency: the stored value
|
|
32
|
+
* plus any events the projection processor has not applied yet. The tail starts
|
|
33
|
+
* at the processor's checkpoint, not the key's own last position: everything at
|
|
34
|
+
* or below the checkpoint is already applied for every key, whereas a quiet
|
|
35
|
+
* key's position can trail the head by the whole history. A rebuild resets the
|
|
36
|
+
* checkpoint before it clears the store, so the checkpoint is never ahead of
|
|
37
|
+
* the stored values it vouches for.
|
|
38
|
+
*/
|
|
39
|
+
export async function readCurrentProjection(dependencies, definition, key) {
|
|
40
|
+
// Order matters. The processor writes a key and only then saves the batch
|
|
41
|
+
// checkpoint, so a checkpoint read first can only be older than the stored
|
|
42
|
+
// value read after it: every event at or below it is already in that value.
|
|
43
|
+
// Reading the value first would let events applied in between be skipped.
|
|
44
|
+
const checkpoint = await dependencies.checkpoints.load(projectionConsumer(definition));
|
|
45
|
+
const stored = await dependencies.projections.read(definition.name, key);
|
|
46
|
+
let value = stored?.value ?? definition.initial(key);
|
|
47
|
+
let position = Math.max(stored?.lastGlobalPosition ?? 0, checkpoint);
|
|
48
|
+
for (;;) {
|
|
49
|
+
const events = await dependencies.journal.readAll(position, catchUpBatchSize);
|
|
50
|
+
for (const event of events)
|
|
51
|
+
if (definition.select(event)?.key === key)
|
|
52
|
+
value = definition.project(value, event);
|
|
53
|
+
if (events.length < catchUpBatchSize)
|
|
54
|
+
return value;
|
|
55
|
+
position = events.at(-1).globalPosition;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
29
58
|
export async function applyProjectionBatch(definition, projections, events, signal = new AbortController().signal) {
|
|
30
59
|
throwIfAborted(signal);
|
|
31
60
|
const processor = createProjectionProcessor(definition, projections);
|
|
@@ -54,8 +83,9 @@ export class ProjectionRebuilder {
|
|
|
54
83
|
}
|
|
55
84
|
async rebuildLocked(definition, signal) {
|
|
56
85
|
const consumer = projectionConsumer(definition);
|
|
57
|
-
|
|
86
|
+
// Checkpoint first: a concurrent reader that sees a cleared store must also see a reset checkpoint.
|
|
58
87
|
await this.checkpoints.reset(consumer);
|
|
88
|
+
await this.projections.clear(definition.name);
|
|
59
89
|
const processor = createProjectionProcessor(definition, this.projections);
|
|
60
90
|
if (processor.mode === 'batch')
|
|
61
91
|
throw new Error('Projection processors must handle each event');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EventEnvelope } from '../contracts/events.js';
|
|
2
|
+
import type { EventJournal } from '../store/event-journal.js';
|
|
3
|
+
export declare const JOURNAL_CHANGE_FALLBACK_MS = 30000;
|
|
4
|
+
export interface JournalView<Value> {
|
|
5
|
+
get(): Promise<Value>;
|
|
6
|
+
}
|
|
7
|
+
type ViewJournal = Pick<EventJournal, 'readAll' | 'latestGlobalPosition'>;
|
|
8
|
+
export interface JournalFold<Value> {
|
|
9
|
+
readonly initial: Value;
|
|
10
|
+
/** Returns the value after `events`, which follow everything already folded. Must not mutate `value`: earlier callers may still hold it across awaits. */
|
|
11
|
+
extend(value: Value, events: readonly EventEnvelope[]): Value;
|
|
12
|
+
}
|
|
13
|
+
export declare function foldedJournalView<Value>(journal: ViewJournal, fold: JournalFold<Value>): JournalView<Value>;
|
|
14
|
+
/**
|
|
15
|
+
* Decodes each envelope object once. Journals hand out the same immutable
|
|
16
|
+
* envelope instances while their cache is valid, so repeated stream loads reuse
|
|
17
|
+
* the earlier decode instead of re-running schema validation on every call. A
|
|
18
|
+
* decoder that throws is not memoized and keeps throwing.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decodeOnce<Decoded extends object | null>(decode: (event: EventEnvelope) => Decoded): (event: EventEnvelope) => Decoded;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=journal-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-view.d.ts","sourceRoot":"","sources":["../../src/runtime/journal-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;CACvB;AAED,KAAK,WAAW,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,sBAAsB,CAAC,CAAC;AAE1E,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,0JAA0J;IAC1J,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,KAAK,CAAC;CAC/D;AAWD,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GACvB,WAAW,CAAC,KAAK,CAAC,CA+BpB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,MAAM,GAAG,IAAI,EACtD,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,GACxC,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAQnC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const JOURNAL_CHANGE_FALLBACK_MS = 30_000;
|
|
2
|
+
// The in-process read model for derivations that join across streams or must
|
|
3
|
+
// answer without a durable key (use a ProjectionStore projection for per-key
|
|
4
|
+
// state that must survive restarts). The first call folds history once; every
|
|
5
|
+
// later journal move folds only the events after the position already held, so
|
|
6
|
+
// cost per resident tick is proportional to what changed, never to history.
|
|
7
|
+
// There is deliberately no "re-derive everything when the journal moves" form.
|
|
8
|
+
// Folds are serialised, so every event is applied once and in order however
|
|
9
|
+
// many callers ask at the same time; the value is keyed by the last position
|
|
10
|
+
// actually read, never one sampled beforehand.
|
|
11
|
+
export function foldedJournalView(journal, fold) {
|
|
12
|
+
let state = {
|
|
13
|
+
position: 0,
|
|
14
|
+
value: fold.initial,
|
|
15
|
+
};
|
|
16
|
+
let running;
|
|
17
|
+
return {
|
|
18
|
+
async get() {
|
|
19
|
+
for (;;) {
|
|
20
|
+
const sampled = await journal.latestGlobalPosition();
|
|
21
|
+
if (state.position >= sampled)
|
|
22
|
+
return state.value;
|
|
23
|
+
if (running !== undefined) {
|
|
24
|
+
await running.catch(() => undefined);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const run = (async () => {
|
|
28
|
+
const events = await journal.readAll(state.position);
|
|
29
|
+
if (events.length > 0)
|
|
30
|
+
state = {
|
|
31
|
+
position: events.at(-1).globalPosition,
|
|
32
|
+
value: fold.extend(state.value, events),
|
|
33
|
+
};
|
|
34
|
+
return state.value;
|
|
35
|
+
})().finally(() => {
|
|
36
|
+
if (running === run)
|
|
37
|
+
running = undefined;
|
|
38
|
+
});
|
|
39
|
+
running = run;
|
|
40
|
+
return run;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Decodes each envelope object once. Journals hand out the same immutable
|
|
47
|
+
* envelope instances while their cache is valid, so repeated stream loads reuse
|
|
48
|
+
* the earlier decode instead of re-running schema validation on every call. A
|
|
49
|
+
* decoder that throws is not memoized and keeps throwing.
|
|
50
|
+
*/
|
|
51
|
+
export function decodeOnce(decode) {
|
|
52
|
+
const decoded = new WeakMap();
|
|
53
|
+
return (event) => {
|
|
54
|
+
if (decoded.has(event))
|
|
55
|
+
return decoded.get(event);
|
|
56
|
+
const value = decode(event);
|
|
57
|
+
decoded.set(event, value);
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -25,6 +25,7 @@ export declare class FileEventJournal implements EventJournal {
|
|
|
25
25
|
private runningListing;
|
|
26
26
|
private queuedListing;
|
|
27
27
|
private temporariesReclaimed;
|
|
28
|
+
private lastFullListingMs;
|
|
28
29
|
appendToStream(stream: StreamRef, expectedSequence: number, drafts: readonly EventData[]): Promise<readonly EventEnvelope[]>;
|
|
29
30
|
private nextSegmentFile;
|
|
30
31
|
readStream(stream: StreamRef): Promise<readonly EventEnvelope<EventData<string, unknown>, StreamRef<string, string>>[]>;
|
|
@@ -46,6 +47,7 @@ export declare class FileEventJournal implements EventJournal {
|
|
|
46
47
|
private scan;
|
|
47
48
|
private currentEntries;
|
|
48
49
|
private startListing;
|
|
50
|
+
private nothingNewerThanCache;
|
|
49
51
|
private listSegments;
|
|
50
52
|
private parseIndexedEntries;
|
|
51
53
|
private decodeIndexedRecord;
|
package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-event-journal.d.ts","sourceRoot":"","sources":["../src/file-event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACV,MAAM,qBAAqB,CAAC;AAU7B,MAAM,WAAW,uBAAuB;IACtC,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;CACrD;AAED,MAAM,MAAM,8BAA8B,GAAG,CAC3C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,IAAI,KACf,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,8BAA8B,CAAC;CAC1D;
|
|
1
|
+
{"version":3,"file":"file-event-journal.d.ts","sourceRoot":"","sources":["../src/file-event-journal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACV,MAAM,qBAAqB,CAAC;AAU7B,MAAM,WAAW,uBAAuB;IACtC,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;CACrD;AAED,MAAM,MAAM,8BAA8B,GAAG,CAC3C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,IAAI,KACf,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,8BAA8B,CAAC;CAC1D;AAgBD,qBAAa,gBAAiB,YAAW,YAAY;IAEjD,OAAO,CAAC,QAAQ,CAAC,IA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WhB,OAAO,CAAC,mBAAmB;YAUb,kBAAkB;YAyBlB,WAAW;IAuDzB,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,YAAY;YAQN,eAAe;YAKf,YAAY;YAYZ,IAAI;IAelB,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,YAAY;YAaN,qBAAqB;YAmCrB,YAAY;YAsEZ,mBAAmB;IA0BjC,OAAO,CAAC,mBAAmB;YAwBb,eAAe;CAuD9B"}
|
|
@@ -12,6 +12,11 @@ const createFileSystemWatcher = async (directory, notify) => watch(directory, {
|
|
|
12
12
|
// tick would leave it identical. Younger stamps are re-listed, never trusted.
|
|
13
13
|
const unchangedStampMinAgeMs = 2_500;
|
|
14
14
|
const statBatchSize = 256;
|
|
15
|
+
// Reads may skip the directory listing while a probe for the next segment finds
|
|
16
|
+
// nothing, but never for longer than this: a full listing still bounds how long
|
|
17
|
+
// an unexpected change (a removed segment, an odd clock) can go unnoticed.
|
|
18
|
+
const maxProbeOnlyMs = 5_000;
|
|
19
|
+
const maxProbedDays = 8;
|
|
15
20
|
export class FileEventJournal {
|
|
16
21
|
root;
|
|
17
22
|
clock;
|
|
@@ -53,6 +58,7 @@ export class FileEventJournal {
|
|
|
53
58
|
runningListing;
|
|
54
59
|
queuedListing;
|
|
55
60
|
temporariesReclaimed = false;
|
|
61
|
+
lastFullListingMs = 0;
|
|
56
62
|
async appendToStream(stream, expectedSequence, drafts) {
|
|
57
63
|
if (drafts.length === 0)
|
|
58
64
|
throw new Error('appendToStream requires at least one event');
|
|
@@ -61,7 +67,8 @@ export class FileEventJournal {
|
|
|
61
67
|
await reclaimStaleSegmentTemps(join(this.root, 'events'));
|
|
62
68
|
this.temporariesReclaimed = true;
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
// Positions are assigned from this snapshot, so it must come from a full listing.
|
|
71
|
+
const snapshot = await this.scan(await this.currentEntries({ exhaustive: true }));
|
|
65
72
|
const current = snapshot.events;
|
|
66
73
|
const streamEvents = snapshot.eventsByStream.get(key(stream)) ?? [];
|
|
67
74
|
if (streamEvents.length !== expectedSequence)
|
|
@@ -357,31 +364,73 @@ export class FileEventJournal {
|
|
|
357
364
|
// call. A listing already running may have read the directory before the
|
|
358
365
|
// call, so it cannot answer it; every caller arriving while one runs shares a
|
|
359
366
|
// single follow-up listing. Any number of concurrent reads cost at most two.
|
|
360
|
-
currentEntries() {
|
|
367
|
+
currentEntries(options = {}) {
|
|
368
|
+
if (options.exhaustive === true) {
|
|
369
|
+
const running = this.runningListing;
|
|
370
|
+
return (running === undefined ? Promise.resolve() : running.then(noop, noop)).then(() => this.startListing(true));
|
|
371
|
+
}
|
|
361
372
|
if (this.queuedListing !== undefined)
|
|
362
373
|
return this.queuedListing;
|
|
363
374
|
const running = this.runningListing;
|
|
364
375
|
if (running === undefined)
|
|
365
|
-
return this.startListing();
|
|
376
|
+
return this.startListing(false);
|
|
366
377
|
const queued = running
|
|
367
378
|
.catch(() => undefined)
|
|
368
379
|
.then(() => {
|
|
369
380
|
this.queuedListing = undefined;
|
|
370
|
-
return this.startListing();
|
|
381
|
+
return this.startListing(false);
|
|
371
382
|
});
|
|
372
383
|
this.queuedListing = queued;
|
|
373
384
|
return queued;
|
|
374
385
|
}
|
|
375
|
-
startListing() {
|
|
376
|
-
const run = this.listSegments().finally(() => {
|
|
386
|
+
startListing(exhaustive) {
|
|
387
|
+
const run = this.listSegments(exhaustive).finally(() => {
|
|
377
388
|
if (this.runningListing === run)
|
|
378
389
|
this.runningListing = undefined;
|
|
379
390
|
});
|
|
380
391
|
this.runningListing = run;
|
|
381
392
|
return run;
|
|
382
393
|
}
|
|
383
|
-
|
|
394
|
+
// Segments are immutable, contiguous, and named by the global position of
|
|
395
|
+
// their first event (the first segment of a day is `<day>.jsonl`). When the
|
|
396
|
+
// cache holds L events and is the newest listing, nothing newer exists exactly
|
|
397
|
+
// when no segment for position L+1 exists, which costs a few stats instead of
|
|
398
|
+
// a directory listing proportional to the whole history.
|
|
399
|
+
async nothingNewerThanCache() {
|
|
400
|
+
const cached = this.cached;
|
|
401
|
+
const last = cached?.entries.at(-1);
|
|
402
|
+
if (cached === undefined || last === undefined)
|
|
403
|
+
return false;
|
|
404
|
+
if (Date.now() - this.lastFullListingMs > maxProbeOnlyMs)
|
|
405
|
+
return false;
|
|
406
|
+
if (!sameEntries(cached.entries, this.latestEntries))
|
|
407
|
+
return false;
|
|
408
|
+
const next = String(cached.events.length + 1).padStart(20, '0');
|
|
409
|
+
// A writer names a segment from its own clock, so cover every day between the
|
|
410
|
+
// newest cached segment (or yesterday, for a clock running behind) and
|
|
411
|
+
// tomorrow. A wider gap cannot be probed cheaply, so list the directory.
|
|
412
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
413
|
+
const lastDay = Date.parse(`${last.file.slice(0, 10)}T00:00:00Z`);
|
|
414
|
+
const firstDay = Math.min(lastDay, Date.UTC(...utcDayParts(Date.now() - dayMs)));
|
|
415
|
+
const lastProbedDay = Date.UTC(...utcDayParts(Date.now() + dayMs));
|
|
416
|
+
if (!Number.isFinite(lastDay) || (lastProbedDay - firstDay) / dayMs > maxProbedDays)
|
|
417
|
+
return false;
|
|
418
|
+
const days = [];
|
|
419
|
+
for (let at = firstDay; at <= lastProbedDay; at += dayMs)
|
|
420
|
+
days.push(new Date(at).toISOString().slice(0, 10));
|
|
421
|
+
const candidates = days.flatMap((d) => [`${d}~${next}.jsonl`, `${d}.jsonl`]);
|
|
422
|
+
const unknown = candidates.filter((name) => !this.knownSegments.has(name));
|
|
423
|
+
const found = await Promise.all(unknown.map((name) => stat(join(this.root, 'events', name)).then(() => true, (error) => {
|
|
424
|
+
if (error.code === 'ENOENT')
|
|
425
|
+
return false;
|
|
426
|
+
throw error;
|
|
427
|
+
})));
|
|
428
|
+
return !found.some(Boolean);
|
|
429
|
+
}
|
|
430
|
+
async listSegments(exhaustive) {
|
|
384
431
|
const directory = join(this.root, 'events');
|
|
432
|
+
if (!exhaustive && (await this.nothingNewerThanCache()))
|
|
433
|
+
return this.latestEntries;
|
|
385
434
|
const startedAtMs = Date.now();
|
|
386
435
|
let stamp;
|
|
387
436
|
try {
|
|
@@ -403,15 +452,27 @@ export class FileEventJournal {
|
|
|
403
452
|
this.latestEntries.length === this.knownSegments.size)
|
|
404
453
|
return this.latestEntries;
|
|
405
454
|
// The stamp is taken before the listing so a change during it cannot be hidden.
|
|
406
|
-
|
|
407
|
-
|
|
455
|
+
// One pass over the directory: names already known are only counted, and
|
|
456
|
+
// the set of present names is built only if a known segment has gone missing.
|
|
457
|
+
const listed = await readdir(directory);
|
|
458
|
+
const unseen = [];
|
|
459
|
+
let knownPresent = 0;
|
|
460
|
+
for (const name of listed) {
|
|
461
|
+
if (this.knownSegments.has(name))
|
|
462
|
+
knownPresent += 1;
|
|
463
|
+
else if (segmentName.test(name))
|
|
464
|
+
unseen.push(name);
|
|
465
|
+
}
|
|
408
466
|
let removed = false;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
467
|
+
if (knownPresent !== this.knownSegments.size) {
|
|
468
|
+
const present = new Set(listed);
|
|
469
|
+
for (const name of this.knownSegments.keys())
|
|
470
|
+
if (!present.has(name)) {
|
|
471
|
+
this.knownSegments.delete(name);
|
|
472
|
+
removed = true;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
unseen.sort();
|
|
415
476
|
for (let index = 0; index < unseen.length; index += statBatchSize)
|
|
416
477
|
await Promise.all(unseen.slice(index, index + statBatchSize).map(async (file) => {
|
|
417
478
|
try {
|
|
@@ -424,6 +485,7 @@ export class FileEventJournal {
|
|
|
424
485
|
}
|
|
425
486
|
}));
|
|
426
487
|
this.listing = { stamp, startedAtMs };
|
|
488
|
+
this.lastFullListingMs = startedAtMs;
|
|
427
489
|
const added = unseen.flatMap((file) => this.knownSegments.get(file) ?? []);
|
|
428
490
|
const last = this.latestEntries.at(-1);
|
|
429
491
|
const consistent = this.latestEntries.length + added.length === this.knownSegments.size;
|
|
@@ -593,6 +655,11 @@ function sameEntries(a, b) {
|
|
|
593
655
|
return (entry.file === other.file && entry.size === other.size && entry.mtimeMs === other.mtimeMs);
|
|
594
656
|
})));
|
|
595
657
|
}
|
|
658
|
+
function utcDayParts(ms) {
|
|
659
|
+
const date = new Date(ms);
|
|
660
|
+
return [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()];
|
|
661
|
+
}
|
|
662
|
+
function noop() { }
|
|
596
663
|
const key = (stream) => `${stream.kind}:${stream.id}`;
|
|
597
664
|
function indexEventsByStream(events) {
|
|
598
665
|
const indexed = new Map();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventSourceKind } from '@atolis-hq/eventing';
|
|
2
2
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
3
3
|
import { commandName } from '../contracts/identifiers.js';
|
|
4
|
-
import { WorkflowStatus } from '../contracts/vocabulary.js';
|
|
4
|
+
import { ActivityActivationStatus, WorkflowStatus } from '../contracts/vocabulary.js';
|
|
5
5
|
import { workflowEventData } from '../domain/decision-events.js';
|
|
6
6
|
import { requestChangesResume as decideChangesResume, requestFreshOperatorRetry as decideFreshOperatorRetry, requestOperatorRetry as decideOperatorRetry, requestSupplementalActivity as decideSupplementalActivity, isNeedsClarificationResumeEligible, requestRunnerQuotaRetry, } from '../domain/interpreter.js';
|
|
7
7
|
import { isAuthorisedActor } from '../domain/supplemental-policy.js';
|
|
@@ -50,7 +50,12 @@ export class AdvanceWorkflow {
|
|
|
50
50
|
}
|
|
51
51
|
async markActivationStarted(id, activationId, context) {
|
|
52
52
|
const loaded = await this.repository.load(id);
|
|
53
|
-
|
|
53
|
+
const pending = loaded.view?.pendingActivation;
|
|
54
|
+
if (pending?.activationId !== activationId)
|
|
55
|
+
return loaded.view;
|
|
56
|
+
// Dispatch marks before every attempt; a retried tick must not append a new
|
|
57
|
+
// fact for an activation whose recorded state already says it is running.
|
|
58
|
+
if (pending.status === ActivityActivationStatus.Running)
|
|
54
59
|
return loaded.view;
|
|
55
60
|
const event = workflowEventData({
|
|
56
61
|
eventId: `${context.commandId}:${OrchestrationEventType.ActivityStarted}`,
|
|
@@ -64,15 +64,11 @@ export class DeferredSignals {
|
|
|
64
64
|
return view;
|
|
65
65
|
}
|
|
66
66
|
async hasDeferred() {
|
|
67
|
-
return (await this.repository.
|
|
67
|
+
return (await this.repository.instancesWithDeferredSignals()).size > 0;
|
|
68
68
|
}
|
|
69
69
|
async reconcile(context) {
|
|
70
70
|
// Only instances holding a deferred signal have anything to replay.
|
|
71
|
-
const
|
|
72
|
-
for (const entry of await this.repository.events())
|
|
73
|
-
if (entry.event.eventType === OrchestrationEventType.SignalDeferred)
|
|
74
|
-
deferred.add(entry.stream.id);
|
|
75
|
-
const ids = [...deferred];
|
|
71
|
+
const ids = [...(await this.repository.instancesWithDeferredSignals())];
|
|
76
72
|
if (ids.length === 0)
|
|
77
73
|
return;
|
|
78
74
|
const fenced = await this.fencedAmong(ids);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type CommandContext } from '@atolis-hq/eventing';
|
|
2
|
+
import type { ParentActionRequest } from '../../activities/index.js';
|
|
2
3
|
import { type DelegationCaller } from '../contracts/delegation.js';
|
|
3
4
|
import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
|
|
4
|
-
import { type DeliveryCandidate, type DeliveryCandidateCommand, type DeliveryQa, type DeliveryQaCommand, type DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
5
|
+
import { type DeliveryCandidate, type DeliveryCandidateCommand, type DeliveryMaintenanceCommand, type DeliveryQa, type DeliveryQaCommand, type DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
5
6
|
import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
6
7
|
/**
|
|
7
8
|
* Agent-led parent QA over the delegated delivery. The parent agent chooses what to select,
|
|
@@ -13,7 +14,16 @@ export declare class DeliveryCoordinator {
|
|
|
13
14
|
private readonly repository;
|
|
14
15
|
private readonly dependencies;
|
|
15
16
|
private readonly preparation;
|
|
17
|
+
private readonly integration;
|
|
16
18
|
constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
|
|
19
|
+
authorizeParentAction(request: ParentActionRequest): Promise<import("../../activities/index.js").ParentActionDecision>;
|
|
20
|
+
/** The targets the configured maintenance stage will lease, or undefined for other stages. */
|
|
21
|
+
maintenanceTargets(id: string): Promise<import("../domain/delivery-integration.js").IntegrationTarget[] | undefined>;
|
|
22
|
+
/** Records what the maintaining agent actually produced as a new immutable subject. */
|
|
23
|
+
recordMaintenance(caller: DelegationCaller, input: DeliveryMaintenanceCommand, context: CommandContext): Promise<{
|
|
24
|
+
readonly maintenance: import("../contracts/delivery.js").DeliveryMaintenance;
|
|
25
|
+
readonly replay: boolean;
|
|
26
|
+
}>;
|
|
17
27
|
select(caller: DelegationCaller, input: DeliverySelectionCommand, context: CommandContext): Promise<{
|
|
18
28
|
selection: {
|
|
19
29
|
requestId: string;
|
|
@@ -75,6 +85,13 @@ export declare class DeliveryCoordinator {
|
|
|
75
85
|
outputName: string;
|
|
76
86
|
}[];
|
|
77
87
|
criteria: string[];
|
|
88
|
+
subjects?: {
|
|
89
|
+
childWorkItemId: import("../../work/index.js").WorkItemId;
|
|
90
|
+
outputName: string;
|
|
91
|
+
revision: string;
|
|
92
|
+
pullRequestBase: string;
|
|
93
|
+
baseRevision?: string | undefined;
|
|
94
|
+
}[] | undefined;
|
|
78
95
|
recipe?: string | undefined;
|
|
79
96
|
};
|
|
80
97
|
replay: boolean;
|
|
@@ -105,6 +122,32 @@ export declare class DeliveryCoordinator {
|
|
|
105
122
|
}>;
|
|
106
123
|
/** The inspectable delivery state: selection, staleness, candidate, QA, repair and completion. */
|
|
107
124
|
inspectFor(caller: DelegationCaller): Promise<{
|
|
125
|
+
integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
|
|
126
|
+
maintenance: readonly {
|
|
127
|
+
maintenanceId: string;
|
|
128
|
+
target: {
|
|
129
|
+
childWorkItemId: import("../../work/index.js").WorkItemId;
|
|
130
|
+
outputName: string;
|
|
131
|
+
};
|
|
132
|
+
kind: "rebase" | "retarget" | "resolve-conflicts";
|
|
133
|
+
resourceId: string;
|
|
134
|
+
repositoryResourceId: string;
|
|
135
|
+
previous: {
|
|
136
|
+
revision: string;
|
|
137
|
+
pullRequestBase: string;
|
|
138
|
+
baseRevision?: string | undefined;
|
|
139
|
+
};
|
|
140
|
+
current: {
|
|
141
|
+
revision: string;
|
|
142
|
+
pullRequestBase: string;
|
|
143
|
+
baseRevision?: string | undefined;
|
|
144
|
+
};
|
|
145
|
+
producer: {
|
|
146
|
+
runId: string;
|
|
147
|
+
activationId: string;
|
|
148
|
+
};
|
|
149
|
+
recordedAt?: string | undefined;
|
|
150
|
+
}[];
|
|
108
151
|
required: {
|
|
109
152
|
cohortId: string;
|
|
110
153
|
assignmentId: string;
|
|
@@ -176,6 +219,32 @@ export declare class DeliveryCoordinator {
|
|
|
176
219
|
};
|
|
177
220
|
}>;
|
|
178
221
|
inspect(id: string): Promise<{
|
|
222
|
+
integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
|
|
223
|
+
maintenance: readonly {
|
|
224
|
+
maintenanceId: string;
|
|
225
|
+
target: {
|
|
226
|
+
childWorkItemId: import("../../work/index.js").WorkItemId;
|
|
227
|
+
outputName: string;
|
|
228
|
+
};
|
|
229
|
+
kind: "rebase" | "retarget" | "resolve-conflicts";
|
|
230
|
+
resourceId: string;
|
|
231
|
+
repositoryResourceId: string;
|
|
232
|
+
previous: {
|
|
233
|
+
revision: string;
|
|
234
|
+
pullRequestBase: string;
|
|
235
|
+
baseRevision?: string | undefined;
|
|
236
|
+
};
|
|
237
|
+
current: {
|
|
238
|
+
revision: string;
|
|
239
|
+
pullRequestBase: string;
|
|
240
|
+
baseRevision?: string | undefined;
|
|
241
|
+
};
|
|
242
|
+
producer: {
|
|
243
|
+
runId: string;
|
|
244
|
+
activationId: string;
|
|
245
|
+
};
|
|
246
|
+
recordedAt?: string | undefined;
|
|
247
|
+
}[];
|
|
179
248
|
required: {
|
|
180
249
|
cohortId: string;
|
|
181
250
|
assignmentId: string;
|