@atolis-hq/wake 0.4.106 → 0.4.108

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 (95) hide show
  1. package/dist/src/activities/agent/agent-activity.js +4 -0
  2. package/dist/src/activities/agent/agent-result.js +1 -0
  3. package/dist/src/activities/contracts/activity.d.ts +6 -0
  4. package/dist/src/activities/pr/application.js +23 -9
  5. package/dist/src/activities/pr/approve.js +1 -1
  6. package/dist/src/activities/pr/merge.js +1 -1
  7. package/dist/src/activities/pr/parent-scope.d.ts +8 -2
  8. package/dist/src/activities/pr/parent-scope.js +7 -1
  9. package/dist/src/activities/pr/parent-target.d.ts +2 -2
  10. package/dist/src/activities/pr/parent-target.js +1 -0
  11. package/dist/src/bootstrap/composition-root.js +1 -1
  12. package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
  13. package/dist/src/bootstrap/delivery-integration.js +7 -4
  14. package/dist/src/bootstrap/version.js +1 -1
  15. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
  16. package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
  17. package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
  18. package/dist/src/control-plane/application/dispatch-resources.js +9 -0
  19. package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
  20. package/dist/src/conversations/application/conversation-repository.js +3 -1
  21. package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
  22. package/dist/src/execution/application/change-output-workspaces.js +123 -0
  23. package/dist/src/execution/application/execution-service.js +15 -2
  24. package/dist/src/execution/application/maintenance-workspaces.js +20 -12
  25. package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
  26. package/dist/src/execution/application/run-lifecycle.js +2 -0
  27. package/dist/src/execution/application/run-repository.js +27 -10
  28. package/dist/src/execution/contracts/change-output.d.ts +15 -0
  29. package/dist/src/execution/contracts/change-output.js +12 -0
  30. package/dist/src/execution/contracts/commands.d.ts +5 -0
  31. package/dist/src/execution/contracts/events.d.ts +16 -0
  32. package/dist/src/execution/contracts/events.js +4 -0
  33. package/dist/src/execution/contracts/runner.d.ts +1 -0
  34. package/dist/src/execution/contracts/views.d.ts +3 -0
  35. package/dist/src/execution/contracts/workspace.d.ts +4 -0
  36. package/dist/src/execution/domain/run.js +3 -0
  37. package/dist/src/execution/index.d.ts +1 -0
  38. package/dist/src/execution/index.js +1 -0
  39. package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
  40. package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
  41. package/dist/src/integrations/application/artifact-registration-reactor.js +16 -36
  42. package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
  43. package/dist/src/integrations/application/artifact-verification-source.js +36 -0
  44. package/dist/src/integrations/application/delegation-outputs.js +56 -20
  45. package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
  46. package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
  47. package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
  48. package/dist/src/integrations/contracts/artifact-events.js +1 -0
  49. package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
  50. package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
  51. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
  52. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
  53. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
  54. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
  55. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
  56. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
  57. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
  58. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
  59. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
  60. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
  61. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
  62. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
  63. package/dist/src/orchestration/application/advance-workflow.js +7 -2
  64. package/dist/src/orchestration/application/deferred-signals.js +2 -6
  65. package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
  66. package/dist/src/orchestration/application/delegated-work.js +30 -3
  67. package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
  68. package/dist/src/orchestration/application/delegation-reservation.js +33 -5
  69. package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
  70. package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
  71. package/dist/src/orchestration/application/orchestration-repository.js +139 -64
  72. package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
  73. package/dist/src/orchestration/application/orchestration-service.js +6 -1
  74. package/dist/src/orchestration/contracts/config.d.ts +15 -0
  75. package/dist/src/orchestration/contracts/config.js +8 -1
  76. package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
  77. package/dist/src/orchestration/contracts/delegation.js +11 -5
  78. package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
  79. package/dist/src/orchestration/contracts/vocabulary.js +2 -0
  80. package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
  81. package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
  82. package/dist/src/orchestration/domain/compiler.js +1 -0
  83. package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
  84. package/dist/src/orchestration/domain/delivery-facts.js +4 -2
  85. package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
  86. package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
  87. package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
  88. package/dist/src/orchestration/domain/delivery-selection.js +2 -1
  89. package/dist/src/resources/application/resource-lookup.d.ts +2 -1
  90. package/dist/src/resources/application/resource-lookup.js +3 -11
  91. package/dist/src/resources/application/resource-repository.js +10 -10
  92. package/package.json +1 -1
  93. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
  94. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
  95. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
@@ -0,0 +1,37 @@
1
+ import { PullRequestDenialCode } from '../../activities/index.js';
2
+ import { IntegrationState } from '../contracts/vocabulary.js';
3
+ /** Multiple outputs of one child have no implicit integration order. */
4
+ export function selectIntegrationTarget(assessment, output) {
5
+ if (output === undefined) {
6
+ const owners = assessment.targets.map((target) => target.output.childWorkItemId);
7
+ if (new Set(owners).size !== owners.length)
8
+ return { reason: PullRequestDenialCode.AmbiguousResource };
9
+ return assessment.next === null
10
+ ? { reason: blockReason(assessment.blocking) }
11
+ : { target: assessment.next };
12
+ }
13
+ const matches = assessment.targets.filter((entry) => (output.childWorkItemId === undefined ||
14
+ entry.output.childWorkItemId === output.childWorkItemId) &&
15
+ entry.output.outputName === output.outputName);
16
+ if (matches.length > 1)
17
+ return { reason: PullRequestDenialCode.AmbiguousResource };
18
+ const target = matches[0];
19
+ if (target === undefined)
20
+ return { reason: PullRequestDenialCode.MissingResource };
21
+ return target.state === IntegrationState.Ready ? { target } : { reason: blockReason(target) };
22
+ }
23
+ function blockReason(blocking) {
24
+ switch (blocking?.state) {
25
+ case IntegrationState.Held:
26
+ return PullRequestDenialCode.TargetHeld;
27
+ case IntegrationState.MaintenanceRequired:
28
+ case IntegrationState.AwaitingLowerLayer:
29
+ return PullRequestDenialCode.MaintenanceRequired;
30
+ case IntegrationState.Closed:
31
+ return PullRequestDenialCode.Closed;
32
+ case IntegrationState.Unobserved:
33
+ return PullRequestDenialCode.MissingResource;
34
+ default:
35
+ return PullRequestDenialCode.DeliveryNotReady;
36
+ }
37
+ }
@@ -25,22 +25,27 @@ export function assertCriteriaPreserving(facts, original, assignment) {
25
25
  const unmerged = facts.results
26
26
  .filter((entry) => entry.childWorkItemId === original.workItemId)
27
27
  .flatMap((entry) => entry.outputs.filter(isChange))
28
- .map((output) => output.reference)
29
- .filter((reference) => reference.merged !== true);
30
- for (const reference of unmerged)
31
- assertCarriesContribution(assignment, reference);
28
+ .filter((output) => output.reference.merged !== true);
29
+ for (const output of unmerged) {
30
+ const counterpart = assignment.outputs.find((entry) => entry.name === output.name);
31
+ const repository = counterpart !== undefined && 'kind' in counterpart
32
+ ? (counterpart.repository ?? assignment.repository)
33
+ : assignment.repository;
34
+ assertCarriesContribution(repository, output.reference);
35
+ }
32
36
  }
33
37
  function assertOutputsProvided(original, assignment) {
34
38
  for (const output of original.outputs) {
35
39
  const counterpart = assignment.outputs.find((entry) => entry.name === output.name);
36
40
  if (counterpart === undefined || 'kind' in output !== 'kind' in counterpart)
37
41
  throw invalid(`A replacement must provide the original output ${output.name}`);
42
+ if (output.required !== false && counterpart.required === false)
43
+ throw invalid('A replacement must preserve the original required output ' + output.name);
38
44
  if ('kind' in output && 'kind' in counterpart)
39
45
  assertChangeRequirements(output, counterpart);
40
46
  }
41
47
  }
42
- function assertCarriesContribution(assignment, reference) {
43
- const repository = assignment.repository;
48
+ function assertCarriesContribution(repository, reference) {
44
49
  if (repository?.sourceRevision !== reference.revision)
45
50
  throw invalid(`A replacement must start from the unmerged contribution ${reference.branch}@${reference.revision}`);
46
51
  if (repository.pullRequestBase !== reference.pullRequestBase)
@@ -18,9 +18,10 @@ export function reviseSelection(facts, command) {
18
18
  if (command.expectedRevision !== revision)
19
19
  throw reject(DeliveryRejection.StaleSelection, `Selection is at revision ${revision}, not ${command.expectedRevision}; inspect and retry`);
20
20
  const required = requirements(facts.reservations);
21
+ const available = requirements(facts.reservations, true);
21
22
  const seen = new Set();
22
23
  const entries = command.entries.map((entry) => {
23
- const requirement = required.find((candidate) => candidate.cohortId === entry.cohortId &&
24
+ const requirement = available.find((candidate) => candidate.cohortId === entry.cohortId &&
24
25
  candidate.assignmentId === entry.assignmentId &&
25
26
  candidate.outputName === entry.output.outputName);
26
27
  if (requirement === undefined)
@@ -1,4 +1,4 @@
1
- import type { EventJournal, ProjectionStore } from '@atolis-hq/eventing';
1
+ import { type CheckpointStore, type EventJournal, type ProjectionStore } from '@atolis-hq/eventing';
2
2
  import type { WorkItemId } from '../../work/index.js';
3
3
  import type { ResourceId } from '../contracts/identifiers.js';
4
4
  import type { ExternalResourceKey, ResourceCorrelationView } from '../contracts/views.js';
@@ -14,4 +14,5 @@ export interface ResourceLookup {
14
14
  export declare function createResourceLookup(dependencies: {
15
15
  readonly journal: EventJournal;
16
16
  readonly projections: ProjectionStore;
17
+ readonly checkpoints: Pick<CheckpointStore, 'load'>;
17
18
  }): ResourceLookup;
@@ -1,20 +1,12 @@
1
+ import { readCurrentProjection, } from '@atolis-hq/eventing';
1
2
  import { ResourceEventType, selectResourceEvent } from '../contracts/events.js';
2
3
  import { resourceStream } from '../contracts/streams.js';
3
4
  import { ResourceCorrelationRole } from '../contracts/vocabulary.js';
4
5
  import { externalKeyProjectionKey, resourcesByExternalKeyProjection, workCorrelationsProjection, } from './lookup-projections.js';
5
6
  export function createResourceLookup(dependencies) {
6
- const seeded = async (definition, key) => {
7
- const stored = await dependencies.projections.read(definition.name, key);
8
- let value = stored?.value ?? definition.initial(key);
9
- for (const event of await dependencies.journal.readAll(stored?.lastGlobalPosition ?? 0)) {
10
- if (definition.select(event)?.key === key)
11
- value = definition.project(value, event);
12
- }
13
- return value;
14
- };
15
7
  return {
16
- resourceIdForExternalKey: (externalKey) => seeded(resourcesByExternalKeyProjection, externalKeyProjectionKey(externalKey)),
17
- correlationsForWork: (workItemId) => seeded(workCorrelationsProjection, workItemId),
8
+ resourceIdForExternalKey: (externalKey) => readCurrentProjection(dependencies, resourcesByExternalKeyProjection, externalKeyProjectionKey(externalKey)),
9
+ correlationsForWork: (workItemId) => readCurrentProjection(dependencies, workCorrelationsProjection, workItemId),
18
10
  async primaryCorrelation(resourceId) {
19
11
  const active = new Map();
20
12
  const retracted = [];
@@ -1,17 +1,18 @@
1
- import { cachedJournalView } from '@atolis-hq/eventing';
1
+ import { decodeOnce, foldedJournalView, } from '@atolis-hq/eventing';
2
2
  import { ResourceEventType, decodeResourceEvent, selectResourceEvent, } from '../contracts/events.js';
3
3
  import { resourceStream } from '../contracts/streams.js';
4
4
  import { foldResource } from '../domain/resource.js';
5
+ const selectResource = decodeOnce(selectResourceEvent);
5
6
  export class ResourceRepository {
6
7
  journal;
7
8
  resourceIds;
8
9
  constructor(journal) {
9
10
  this.journal = journal;
10
- this.resourceIds = cachedJournalView(journal, deriveResourceIds);
11
+ this.resourceIds = foldedJournalView(journal, { initial: [], extend: extendResourceIds });
11
12
  }
12
13
  async load(resourceId) {
13
14
  const events = await this.journal.readStream(resourceStream(resourceId));
14
- const owned = events.map(selectResourceEvent).filter((event) => event !== null);
15
+ const owned = events.map(selectResource).filter((event) => event !== null);
15
16
  return { sequence: events.length, resource: foldResource(owned) };
16
17
  }
17
18
  async append(resourceId, expectedSequence, drafts) {
@@ -22,11 +23,10 @@ export class ResourceRepository {
22
23
  return this.resourceIds.get();
23
24
  }
24
25
  }
25
- function deriveResourceIds(events) {
26
- return [
27
- ...new Set(events
28
- .map(selectResourceEvent)
29
- .filter((event) => event?.event.eventType === ResourceEventType.ResourceDiscovered)
30
- .map((event) => event.stream.id)),
31
- ];
26
+ function extendResourceIds(known, events) {
27
+ const discovered = events
28
+ .map(selectResourceEvent)
29
+ .filter((event) => event?.event.eventType === ResourceEventType.ResourceDiscovered)
30
+ .map((event) => event.stream.id);
31
+ return [...new Set([...known, ...discovered])];
32
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.4.106",
3
+ "version": "0.4.108",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,16 +0,0 @@
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 CachedJournalView<Value> {
5
- get(): Promise<Value>;
6
- }
7
- type ViewJournal = Pick<EventJournal, 'readAll' | 'latestGlobalPosition'>;
8
- export declare function cachedJournalView<Value>(journal: ViewJournal, derive: (events: readonly EventEnvelope[]) => Value | Promise<Value>, _now?: () => number): CachedJournalView<Value>;
9
- export interface JournalFold<Value> {
10
- readonly initial: Value;
11
- /** Returns the value after `events`, which follow everything already folded. Must not mutate `value`. */
12
- extend(value: Value, events: readonly EventEnvelope[]): Value;
13
- }
14
- export declare function foldedJournalView<Value>(journal: ViewJournal, fold: JournalFold<Value>): CachedJournalView<Value>;
15
- export {};
16
- //# sourceMappingURL=cached-journal-view.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cached-journal-view.d.ts","sourceRoot":"","sources":["../../src/runtime/cached-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,iBAAiB,CAAC,KAAK;IACtC,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;CACvB;AAED,KAAK,WAAW,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,sBAAsB,CAAC,CAAC;AAe1E,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EACpE,IAAI,GAAE,MAAM,MAAiB,GAC5B,iBAAiB,CAAC,KAAK,CAAC,CAsB1B;AAED,MAAM,WAAW,WAAW,CAAC,KAAK;IAChC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,yGAAyG;IACzG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,KAAK,CAAC;CAC/D;AAMD,wBAAgB,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,GACvB,iBAAiB,CAAC,KAAK,CAAC,CA+B1B"}
@@ -1,79 +0,0 @@
1
- export const JOURNAL_CHANGE_FALLBACK_MS = 30_000;
2
- // Memoizes a full-journal derivation — a fold, decode, or index built from
3
- // every event in history — so a resident loop calling it every tick only
4
- // pays that cost when the journal has actually moved since the last call.
5
- // Same durable position boundary used by projection subscriptions,
6
- // generalized for callers that want a materialized view rather than an
7
- // incremental batch. Depends only on the EventJournal port, not on any
8
- // concrete persistence implementation, so it lives in Eventing rather than
9
- // Persistence; domain and adapter modules may call it directly.
10
- //
11
- // The cached value is keyed by the last position actually read, never by the
12
- // position sampled beforehand, so a value can never be held under a position
13
- // newer than the events it was derived from. Callers that find the journal
14
- // unchanged since a derivation already running share it.
15
- export function cachedJournalView(journal, derive, _now = Date.now) {
16
- let cache;
17
- let inFlight;
18
- return {
19
- async get() {
20
- const sampled = await journal.latestGlobalPosition();
21
- if (cache !== undefined && cache.position >= sampled)
22
- return cache.value;
23
- if (inFlight?.sampled === sampled)
24
- return inFlight.run;
25
- const run = (async () => {
26
- const events = await journal.readAll(0);
27
- const value = await derive(events);
28
- const position = events.at(-1)?.globalPosition ?? 0;
29
- // An older derivation finishing late must not replace a newer one.
30
- if (cache === undefined || position >= cache.position)
31
- cache = { position, value };
32
- return value;
33
- })().finally(() => {
34
- if (inFlight?.run === run)
35
- inFlight = undefined;
36
- });
37
- inFlight = { sampled, run };
38
- return run;
39
- },
40
- };
41
- }
42
- // An incremental counterpart of cachedJournalView for views that can be
43
- // extended event by event: each journal move folds only the new events instead
44
- // of re-deriving history. Folds are serialised, so every event is applied once
45
- // and in order however many callers ask at the same time.
46
- export function foldedJournalView(journal, fold) {
47
- let state = {
48
- position: 0,
49
- value: fold.initial,
50
- };
51
- let running;
52
- return {
53
- async get() {
54
- for (;;) {
55
- const sampled = await journal.latestGlobalPosition();
56
- if (state.position >= sampled)
57
- return state.value;
58
- if (running !== undefined) {
59
- await running.catch(() => undefined);
60
- continue;
61
- }
62
- const run = (async () => {
63
- const events = await journal.readAll(state.position);
64
- if (events.length > 0)
65
- state = {
66
- position: events.at(-1).globalPosition,
67
- value: fold.extend(state.value, events),
68
- };
69
- return state.value;
70
- })().finally(() => {
71
- if (running === run)
72
- running = undefined;
73
- });
74
- running = run;
75
- return run;
76
- }
77
- },
78
- };
79
- }