@atolis-hq/wake 0.4.85 → 0.4.87
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/bootstrap/analytics-reports.js +2 -1
- package/dist/src/bootstrap/composition-root.d.ts +63 -2
- package/dist/src/bootstrap/composition-root.js +47 -4
- package/dist/src/bootstrap/integration-runtime.d.ts +1 -0
- package/dist/src/bootstrap/integration-runtime.js +24 -21
- package/dist/src/bootstrap/surface-applications.d.ts +1 -0
- package/dist/src/bootstrap/surface-applications.js +1 -0
- package/dist/src/bootstrap/surface-cli-applications.d.ts +4 -2
- package/dist/src/bootstrap/surface-cli-applications.js +92 -31
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/application/run-reports.d.ts +7 -0
- package/dist/src/execution/application/run-reports.js +70 -26
- package/dist/src/kernel/contracts/reports.d.ts +3 -1
- package/dist/src/main.d.ts +2 -1
- package/dist/src/main.js +25 -13
- package/dist/src/surfaces/cli/main.d.ts +7 -0
- package/dist/src/surfaces/cli/main.js +26 -8
- package/dist/src/surfaces/web-assets/assets/index--h2bjD5B.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-BuVkTveW.js +0 -1192
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRunBreakdownReport, createRunOutcomesReport, queryRunAnalytics, } from '../execution/index.js';
|
|
1
|
+
import { createRunBreakdownReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
|
|
2
2
|
import { reportWindow } from '../kernel/index.js';
|
|
3
3
|
import { queryWorkCompletionSummary } from '../orchestration/index.js';
|
|
4
4
|
import { sampledMeta } from './surface-api-metadata.js';
|
|
@@ -6,6 +6,7 @@ export function createAnalyticsReports(journal, now) {
|
|
|
6
6
|
const definitions = [
|
|
7
7
|
createRunOutcomesReport(journal),
|
|
8
8
|
createRunBreakdownReport(journal),
|
|
9
|
+
createRunUsageReport(journal),
|
|
9
10
|
];
|
|
10
11
|
return {
|
|
11
12
|
catalogue: () => definitions.map(({ id, title }) => ({ id, title })),
|
|
@@ -3,9 +3,9 @@ import { createPullRequestService, type ActivityRegistry } from '../activities/i
|
|
|
3
3
|
import { OperatorInstructionsService, createArtifactService } from '../artifacts/index.js';
|
|
4
4
|
import { createControlPlaneService, createRunnerControlService, type ActivationScheduler, type ActivationSchedulerSubscriber, type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore, type TriggerConfig, type TriggerService } from '../control-plane/index.js';
|
|
5
5
|
import { createConversationService } from '../conversations/index.js';
|
|
6
|
-
import { RecoveryService, TranscriptStore, createExecutionService, type FakeScenarioResolver, type Runner } from '../execution/index.js';
|
|
6
|
+
import { GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, type FakeScenarioResolver, type Runner } from '../execution/index.js';
|
|
7
7
|
import type { DeliveryService, DurableFakeDeliveryProvider, ExternalDeliveryAdapter, ProviderCompositionFailure, ProviderInstance } from '../integrations/index.js';
|
|
8
|
-
import { type Clock } from '../kernel/index.js';
|
|
8
|
+
import { UlidIdGenerator, type Clock } from '../kernel/index.js';
|
|
9
9
|
import { createOrchestrationService } from '../orchestration/index.js';
|
|
10
10
|
import { createResourceLookup, createResourceService, type ResourceLinkResolver } from '../resources/index.js';
|
|
11
11
|
import { createWorkService } from '../work/index.js';
|
|
@@ -81,4 +81,65 @@ export interface CompositionRoot {
|
|
|
81
81
|
readonly requestImmediatePoll: (adapter: string) => void;
|
|
82
82
|
readonly resolveResourceLink: ResourceLinkResolver;
|
|
83
83
|
}
|
|
84
|
+
export declare function createDiagnosticRoot(wakeRoot: string): Promise<{
|
|
85
|
+
providers: readonly ProviderInstance[];
|
|
86
|
+
providerFailures: readonly ProviderCompositionFailure[];
|
|
87
|
+
config: ResolvedWakeModulesConfig;
|
|
88
|
+
fakeScenarios: FakeScenarioResolver;
|
|
89
|
+
workflowNotices: string[];
|
|
90
|
+
paths: WakePaths;
|
|
91
|
+
maintenance: UpdateMaintenanceLease;
|
|
92
|
+
clock: Clock;
|
|
93
|
+
ids: UlidIdGenerator;
|
|
94
|
+
journal: EventJournal;
|
|
95
|
+
projections: ProjectionStore;
|
|
96
|
+
checkpoints: CheckpointStore;
|
|
97
|
+
processorState: ProcessorStateStore;
|
|
98
|
+
subscriptionRunSerialiser: ProcessorRunSerialiser;
|
|
99
|
+
work: import("../work/index.js").WorkService;
|
|
100
|
+
artifacts: import("../artifacts/index.js").ArtifactService;
|
|
101
|
+
operatorInstructions: OperatorInstructionsService;
|
|
102
|
+
conversations: import("../conversations/index.js").ConversationService;
|
|
103
|
+
resources: import("../resources/index.js").ResourceService;
|
|
104
|
+
pullRequests: import("../activities/index.js").PullRequestService;
|
|
105
|
+
lookup: import("../resources/index.js").ResourceLookup;
|
|
106
|
+
orchestration: import("../orchestration/index.js").OrchestrationService;
|
|
107
|
+
execution: {
|
|
108
|
+
attempt: (activation: import("../execution/index.js").ExecutionActivation, context: import("../execution/index.js").ExecutionAttemptContext) => Promise<import("../execution/index.js").RunView>;
|
|
109
|
+
list: (activationId?: import("../execution/index.js").ExecutionActivation["activationId"]) => Promise<readonly import("../execution/index.js").RunView[]>;
|
|
110
|
+
isLocallyActive: (id: string) => boolean;
|
|
111
|
+
claim: (id: string, owner: string) => Promise<import("../execution/index.js").RunView>;
|
|
112
|
+
renewLease: (id: string, owner: string) => Promise<import("../execution/index.js").RunView>;
|
|
113
|
+
requestCancellation: (id: string, reason: NonNullable<import("../execution/index.js").RunView["cancellation"]>["reason"]) => Promise<import("../execution/index.js").RunView>;
|
|
114
|
+
confirmCancellation: (id: string) => Promise<import("../execution/index.js").RunView>;
|
|
115
|
+
cancelActive: (workflowInstanceIds: readonly string[], reason: NonNullable<import("../execution/index.js").RunView["cancellation"]>["reason"]) => Promise<import("../execution/index.js").RunView[]>;
|
|
116
|
+
shutdown: () => Promise<void>;
|
|
117
|
+
};
|
|
118
|
+
recovery: RecoveryService;
|
|
119
|
+
transcriptStore: TranscriptStore | undefined;
|
|
120
|
+
runnerControls: import("../control-plane/index.js").RunnerControlService;
|
|
121
|
+
controlPlane: import("../control-plane/index.js").ControlPlaneService;
|
|
122
|
+
isRuntimePaused: () => Promise<boolean>;
|
|
123
|
+
activities: ActivityRegistry;
|
|
124
|
+
runners: import("../execution/index.js").RunnerRegistry;
|
|
125
|
+
artifactTriggerContext: {
|
|
126
|
+
provision(item: string): Promise<{
|
|
127
|
+
contextScope?: never;
|
|
128
|
+
sharedReferences?: never;
|
|
129
|
+
currentMemory?: never;
|
|
130
|
+
} | {
|
|
131
|
+
contextScope: string;
|
|
132
|
+
sharedReferences: readonly {
|
|
133
|
+
workItemId: import("../work/index.js").WorkItemId;
|
|
134
|
+
revisionId: string;
|
|
135
|
+
}[];
|
|
136
|
+
currentMemory: {
|
|
137
|
+
workItemId: import("../work/index.js").WorkItemId;
|
|
138
|
+
revisionId: string;
|
|
139
|
+
} | null;
|
|
140
|
+
}>;
|
|
141
|
+
reconcile(): Promise<void>;
|
|
142
|
+
};
|
|
143
|
+
workspaces: GitWorkspaceProvider;
|
|
144
|
+
}>;
|
|
84
145
|
export declare function createCompositionRoot(wakeRoot: string, options?: CompositionRootOptions): Promise<CompositionRoot>;
|
|
@@ -16,7 +16,7 @@ import { createArtifactTriggerContext } from './artifact-trigger-context.js';
|
|
|
16
16
|
import { loadConfig } from './config/load-config.js';
|
|
17
17
|
import { EventProcessorRuntime } from './event-processor-runtime.js';
|
|
18
18
|
import { loadFakeScenarios } from './fake-scenarios.js';
|
|
19
|
-
import { composeIntegrationRuntime } from './integration-runtime.js';
|
|
19
|
+
import { composeIntegrationRuntime, composeProviders } from './integration-runtime.js';
|
|
20
20
|
import { resolveWakePaths } from './paths.js';
|
|
21
21
|
import { composePersistence } from './persistence-composition.js';
|
|
22
22
|
import { createRunnerQuotaReporter } from './runner-quota-reporter.js';
|
|
@@ -30,8 +30,7 @@ const resourceLinkResolvers = {
|
|
|
30
30
|
function resolveResourceLink(externalKey) {
|
|
31
31
|
return resourceLinkResolvers[externalKey.adapter]?.(externalKey) ?? null;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
33
|
+
async function createApplicationServices(wakeRoot, options = {}) {
|
|
35
34
|
const config = options.config ?? (await loadConfig(wakeRoot));
|
|
36
35
|
const fakeScenarios = await loadFakeScenarios(wakeRoot);
|
|
37
36
|
const paths = resolveWakePaths(wakeRoot);
|
|
@@ -39,7 +38,6 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
39
38
|
const clock = options.clock ?? new SystemClock();
|
|
40
39
|
const ids = new UlidIdGenerator();
|
|
41
40
|
const { journal, projections, checkpoints, processorState, subscriptionRunSerialiser } = composePersistence(paths, clock, options);
|
|
42
|
-
const processorRuntime = new EventProcessorRuntime(journal, checkpoints, subscriptionRunSerialiser, clock);
|
|
43
41
|
const work = createWorkService(journal);
|
|
44
42
|
const artifacts = createArtifactService(journal, new FileArtifactStore(paths.artifactsRoot), config.artifacts);
|
|
45
43
|
const artifactContexts = new ArtifactContextService(journal, artifacts);
|
|
@@ -139,6 +137,51 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
139
137
|
ids,
|
|
140
138
|
runners: new Set(Object.values(config.execution.runnerPools).flat()),
|
|
141
139
|
});
|
|
140
|
+
return {
|
|
141
|
+
config,
|
|
142
|
+
fakeScenarios,
|
|
143
|
+
workflowNotices,
|
|
144
|
+
paths,
|
|
145
|
+
maintenance,
|
|
146
|
+
clock,
|
|
147
|
+
ids,
|
|
148
|
+
journal,
|
|
149
|
+
projections,
|
|
150
|
+
checkpoints,
|
|
151
|
+
processorState,
|
|
152
|
+
subscriptionRunSerialiser,
|
|
153
|
+
work,
|
|
154
|
+
artifacts,
|
|
155
|
+
operatorInstructions,
|
|
156
|
+
conversations,
|
|
157
|
+
resources,
|
|
158
|
+
pullRequests,
|
|
159
|
+
lookup,
|
|
160
|
+
orchestration,
|
|
161
|
+
execution,
|
|
162
|
+
recovery,
|
|
163
|
+
transcriptStore,
|
|
164
|
+
runnerControls,
|
|
165
|
+
controlPlane,
|
|
166
|
+
isRuntimePaused,
|
|
167
|
+
activities,
|
|
168
|
+
runners,
|
|
169
|
+
artifactTriggerContext,
|
|
170
|
+
workspaces,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export async function createDiagnosticRoot(wakeRoot) {
|
|
174
|
+
const base = await createApplicationServices(wakeRoot);
|
|
175
|
+
const { instances, failures } = await composeProviders({
|
|
176
|
+
...base,
|
|
177
|
+
wakeRoot,
|
|
178
|
+
providerDefinitions: [gitHubProviderDefinition],
|
|
179
|
+
});
|
|
180
|
+
return { ...base, providers: instances, providerFailures: failures };
|
|
181
|
+
}
|
|
182
|
+
export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
183
|
+
const { config, fakeScenarios, workflowNotices, paths, maintenance, clock, ids, journal, projections, checkpoints, processorState, subscriptionRunSerialiser, work, artifacts, operatorInstructions, conversations, resources, pullRequests, lookup, orchestration, execution, recovery, transcriptStore, runnerControls, controlPlane, isRuntimePaused, activities, runners, artifactTriggerContext, workspaces, } = await createApplicationServices(wakeRoot, options);
|
|
184
|
+
const processorRuntime = new EventProcessorRuntime(journal, checkpoints, subscriptionRunSerialiser, clock);
|
|
142
185
|
const activationScheduler = createActivationScheduler(orchestration, {
|
|
143
186
|
...execution,
|
|
144
187
|
recoverActive: (owner) => recovery.recoverActive(owner, execution.isLocallyActive),
|
|
@@ -54,3 +54,4 @@ export interface IntegrationRuntimeInput {
|
|
|
54
54
|
export declare function composeIntegrationRuntime(input: IntegrationRuntimeInput): Promise<IntegrationRuntime>;
|
|
55
55
|
/** Coalesces provider webhook requests while retaining the source's durable poll semantics. */
|
|
56
56
|
export declare function createImmediatePollRequester(providers: readonly ProviderInstance[], journal: EventJournal, wakeRoot: string): (adapter: string) => void;
|
|
57
|
+
export declare function composeProviders(input: Pick<IntegrationRuntimeInput, 'wakeRoot' | 'config' | 'work' | 'conversations' | 'resources' | 'lookup' | 'pullRequests' | 'journal' | 'orchestration' | 'ids' | 'clock' | 'checkpoints' | 'execution' | 'providerDefinitions'>): Promise<import("../integrations/index.js").ProviderCompositionResult>;
|
|
@@ -22,27 +22,7 @@ export async function composeIntegrationRuntime(input) {
|
|
|
22
22
|
memoryUsage: () => process.memoryUsage(),
|
|
23
23
|
})
|
|
24
24
|
: undefined;
|
|
25
|
-
const
|
|
26
|
-
registry.register(fakeProviderDefinition);
|
|
27
|
-
for (const definition of input.providerDefinitions)
|
|
28
|
-
registry.register(definition);
|
|
29
|
-
const { instances, failures: providerFailures } = registry.compose(await hydrateFakeProviderEvidence(input.wakeRoot, input.config.integrations), {
|
|
30
|
-
publicUiUrl: input.config.surfaces.web.publicUrl,
|
|
31
|
-
providerStateRoot: join(input.wakeRoot, '.wake'),
|
|
32
|
-
work: input.work,
|
|
33
|
-
conversations: input.conversations,
|
|
34
|
-
resources: input.resources,
|
|
35
|
-
resourceLookup: input.lookup,
|
|
36
|
-
pullRequests: input.pullRequests,
|
|
37
|
-
runs: new RunRepository(input.journal),
|
|
38
|
-
orchestration: input.orchestration,
|
|
39
|
-
ids: input.ids,
|
|
40
|
-
clock: input.clock,
|
|
41
|
-
journal: input.journal,
|
|
42
|
-
checkpoints: input.checkpoints,
|
|
43
|
-
routing: createWorkflowRouter(input.config.orchestration),
|
|
44
|
-
conclusion: createWorkCancellationPolicy(input.work, input.orchestration, input.execution, input.clock, input.ids),
|
|
45
|
-
});
|
|
25
|
+
const { instances, failures: providerFailures } = await composeProviders(input);
|
|
46
26
|
const composedProviders = input.fakeDeliveryProvider === undefined
|
|
47
27
|
? instances
|
|
48
28
|
: instances.map((provider) => provider.adapter === 'fake'
|
|
@@ -351,3 +331,26 @@ function createWorkflowRouter(orchestration) {
|
|
|
351
331
|
const fallback = workflowName(orchestration.default);
|
|
352
332
|
return { select: (candidate) => selectWorkflow(candidate, selectors, fallback) };
|
|
353
333
|
}
|
|
334
|
+
export async function composeProviders(input) {
|
|
335
|
+
const registry = new ProviderRegistry();
|
|
336
|
+
registry.register(fakeProviderDefinition);
|
|
337
|
+
for (const definition of input.providerDefinitions)
|
|
338
|
+
registry.register(definition);
|
|
339
|
+
return registry.compose(await hydrateFakeProviderEvidence(input.wakeRoot, input.config.integrations), {
|
|
340
|
+
publicUiUrl: input.config.surfaces.web.publicUrl,
|
|
341
|
+
providerStateRoot: join(input.wakeRoot, '.wake'),
|
|
342
|
+
work: input.work,
|
|
343
|
+
conversations: input.conversations,
|
|
344
|
+
resources: input.resources,
|
|
345
|
+
resourceLookup: input.lookup,
|
|
346
|
+
pullRequests: input.pullRequests,
|
|
347
|
+
runs: new RunRepository(input.journal),
|
|
348
|
+
orchestration: input.orchestration,
|
|
349
|
+
ids: input.ids,
|
|
350
|
+
clock: input.clock,
|
|
351
|
+
journal: input.journal,
|
|
352
|
+
checkpoints: input.checkpoints,
|
|
353
|
+
routing: createWorkflowRouter(input.config.orchestration),
|
|
354
|
+
conclusion: createWorkCancellationPolicy(input.work, input.orchestration, input.execution, input.clock, input.ids),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
@@ -8,3 +8,4 @@ export interface SurfaceApplications {
|
|
|
8
8
|
readonly cli: WakeCliApplications;
|
|
9
9
|
}
|
|
10
10
|
export declare function createSurfaceApplications(root: CompositionRoot, options?: SurfaceApplicationOptions): SurfaceApplications;
|
|
11
|
+
export { runHostCommand } from './surface-cli-applications.js';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type HostBudget, type HostResult } from '../control-plane/index.js';
|
|
2
|
-
import { type ApiApplications, type WakeCliApplications } from '../surfaces/index.js';
|
|
3
|
-
import type
|
|
2
|
+
import { type ApiApplications, type CliOutput, type WakeCliApplications, type WakeCommand } from '../surfaces/index.js';
|
|
3
|
+
import { type CompositionRoot } from './composition-root.js';
|
|
4
4
|
import { type SelfUpdateQuiescePort } from './self-update-application.js';
|
|
5
|
+
/** Host operations never register processors or establish trigger recovery state. */
|
|
6
|
+
export declare function runHostCommand(command: WakeCommand, wakeRoot: string, output: CliOutput): Promise<boolean>;
|
|
5
7
|
export declare function createSurfaceCliApplications(root: CompositionRoot, api: ApiApplications, now: () => string): WakeCliApplications;
|
|
6
8
|
export declare function createRunnerIdleWait(root: Pick<CompositionRoot, 'journal'>, resident: {
|
|
7
9
|
readonly pollBackoffMs: number;
|
|
@@ -9,13 +9,16 @@ import { BuiltInActivityName, agentActivityDefinition } from '../activities/inde
|
|
|
9
9
|
import { FileArtifactMcpSessionStore } from '../artifacts/index.js';
|
|
10
10
|
import { IntakeHost, ResidentHost, TickHost, } from '../control-plane/index.js';
|
|
11
11
|
import { ExecutionFailureCode, RunStatus, isActiveRunStatus, loadPromptTemplate, } from '../execution/index.js';
|
|
12
|
-
import { UlidIdGenerator } from '../kernel/index.js';
|
|
12
|
+
import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
|
|
13
13
|
import { ResourceCorrelationRole, resourceId } from '../resources/index.js';
|
|
14
|
-
import { DockerProcessError, createApiDispatcher, createLoggedDockerCli, createPackagedAssetSource, createPairingGrant, createProcessLogSink, createSandboxDockerPort, createSurfaceHttpServer, describeSandboxStartupFailure, drainProcessOutput, loadOrCreateCredentials, promoteSandboxImage, redeemPairingGrant, replaceAccessKey, runDoctor, runSandbox, runSandboxEntrypoint, runSandboxSetup, runSelfUpdateLatestLoop, runTargetSmoke, serveMcpOverStdio, verifyResidentStart, waitForActiveRuns, waitForever, } from '../surfaces/index.js';
|
|
14
|
+
import { DockerProcessError, WakeOperationalCommand, createApiDispatcher, createLoggedDockerCli, createPackagedAssetSource, createPairingGrant, createProcessLogSink, createSandboxDockerPort, createSurfaceHttpServer, describeSandboxStartupFailure, drainProcessOutput, loadOrCreateCredentials, promoteSandboxImage, redeemPairingGrant, replaceAccessKey, runDoctor, runSandbox, runSandboxEntrypoint, runSandboxSetup, runSelfUpdateLatestLoop, runTargetSmoke, runWakeReadCommand, serveMcpOverStdio, verifyResidentStart, waitForActiveRuns, waitForever, } from '../surfaces/index.js';
|
|
15
15
|
import { WorkStreamKind, workItemId } from '../work/index.js';
|
|
16
16
|
import { createArtifactMcpServerForSession } from './artifact-mcp.js';
|
|
17
|
+
import { createDiagnosticRoot } from './composition-root.js';
|
|
17
18
|
import { loadConfig } from './config/load-config.js';
|
|
18
19
|
import { createNpmUpdatePort } from './npm-update-port.js';
|
|
20
|
+
import { resolveWakePaths } from './paths.js';
|
|
21
|
+
import { composePersistence } from './persistence-composition.js';
|
|
19
22
|
import { runtimeProjectionDefinitions } from './projection-runtime.js';
|
|
20
23
|
import { createRunnerRegistry } from './runner-registry.js';
|
|
21
24
|
import { createOneShotRunnerAdvance, createResidentRunnerAdvance, withFinalProjectionCatchUp, } from './runner-tick-adapter.js';
|
|
@@ -24,9 +27,41 @@ import { createSelfUpdateApplication, } from './self-update-application.js';
|
|
|
24
27
|
import { createSelfUpdateFailureLog } from './self-update-failure-log.js';
|
|
25
28
|
import { createSourceUpdatePort } from './source-update-port.js';
|
|
26
29
|
import { createUpdateLedger } from './update-ledger.js';
|
|
27
|
-
import { UpdateMaintenancePhase } from './update-maintenance-lease.js';
|
|
30
|
+
import { UpdateMaintenancePhase, createUpdateMaintenanceLease, } from './update-maintenance-lease.js';
|
|
28
31
|
import { resolveWakeVersion, wakePackageVersion } from './version.js';
|
|
29
32
|
const execFile = promisify(nodeExecFile);
|
|
33
|
+
/** Host operations never register processors or establish trigger recovery state. */
|
|
34
|
+
export async function runHostCommand(command, wakeRoot, output) {
|
|
35
|
+
if (command.kind === 'sandbox') {
|
|
36
|
+
const root = { config: await loadConfig(wakeRoot), paths: resolveWakePaths(wakeRoot) };
|
|
37
|
+
const arguments_ = withoutOperationalWakeRoot(command.arguments);
|
|
38
|
+
await runSandboxManagement(root, arguments_);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (command.kind === 'doctor' && !command.arguments.includes('--rebuild-projections')) {
|
|
42
|
+
const root = await createDiagnosticRoot(wakeRoot);
|
|
43
|
+
return runWakeReadCommand(command, {
|
|
44
|
+
doctor: async () => runDoctor({
|
|
45
|
+
diagnose: () => doctorDiagnostics(root),
|
|
46
|
+
projections: {
|
|
47
|
+
health: () => projectionHealth(root),
|
|
48
|
+
rebuild: async () => {
|
|
49
|
+
throw new Error('Read-only diagnostics cannot rebuild projections');
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
}, output);
|
|
54
|
+
}
|
|
55
|
+
if (command.kind === 'audit' ||
|
|
56
|
+
(command.kind === 'validate-state' && !command.rebuildProjections)) {
|
|
57
|
+
const stores = composePersistence(resolveWakePaths(wakeRoot), new SystemClock(), {});
|
|
58
|
+
return runWakeReadCommand(command, {
|
|
59
|
+
audit: createAuditApplication(stores),
|
|
60
|
+
validateState: { health: createStateHealth(stores) },
|
|
61
|
+
}, output);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
30
65
|
export function createSurfaceCliApplications(root, api, now) {
|
|
31
66
|
const artifactMcpSessions = new FileArtifactMcpSessionStore(root.paths.artifactsRoot, now);
|
|
32
67
|
const artifactMcpIds = new UlidIdGenerator();
|
|
@@ -120,20 +155,7 @@ export function createSurfaceCliApplications(root, api, now) {
|
|
|
120
155
|
].join('\n');
|
|
121
156
|
},
|
|
122
157
|
},
|
|
123
|
-
audit:
|
|
124
|
-
async read(id) {
|
|
125
|
-
return (await root.journal.readAll(0))
|
|
126
|
-
.filter((event) => event.stream.kind === WorkStreamKind.WorkItem && event.stream.id === id)
|
|
127
|
-
.map((event) => ({
|
|
128
|
-
eventId: event.event.eventId,
|
|
129
|
-
eventType: event.event.eventType,
|
|
130
|
-
occurredAt: event.event.occurredAt,
|
|
131
|
-
stream: `${event.stream.kind}:${event.stream.id}`,
|
|
132
|
-
causationId: event.event.causationId,
|
|
133
|
-
correlationId: event.event.correlationId,
|
|
134
|
-
}));
|
|
135
|
-
},
|
|
136
|
-
},
|
|
158
|
+
audit: createAuditApplication(root),
|
|
137
159
|
correlate: {
|
|
138
160
|
async correlate(resource, work) {
|
|
139
161
|
return root.resources.correlate(resourceId(resource), workItemId(work), ResourceCorrelationRole.Primary, commandContext(`correlate:${resource}:${work}`, now()));
|
|
@@ -481,6 +503,26 @@ async function rollbackSandboxTag(root, docker, image, development) {
|
|
|
481
503
|
await verifyResidentStart(docker, root.config.host.sandbox.containerName, [...wakeInvocation, 'start', '--wake-root', '/wake'].join(' '));
|
|
482
504
|
await promoteSandboxImage(docker, image, root.config.host.sandbox.image);
|
|
483
505
|
}
|
|
506
|
+
async function runSandboxManagement(root, arguments_) {
|
|
507
|
+
const docker = await createSandboxDockerForCommand(root, arguments_);
|
|
508
|
+
await runSandbox(arguments_, docker);
|
|
509
|
+
if (arguments_[0] !== 'update')
|
|
510
|
+
return;
|
|
511
|
+
const maintenance = createUpdateMaintenanceLease(root.paths.wakeRoot);
|
|
512
|
+
if ((await maintenance.read())?.phase !== UpdateMaintenancePhase.Failed)
|
|
513
|
+
return;
|
|
514
|
+
// The new container owns runtime writes; clearFailed still refuses a changed active lease.
|
|
515
|
+
await docker.exec([
|
|
516
|
+
...sandboxWakeInvocation(root),
|
|
517
|
+
WakeOperationalCommand.Maintenance,
|
|
518
|
+
'clear',
|
|
519
|
+
'--failed',
|
|
520
|
+
'--wake-root',
|
|
521
|
+
'/wake',
|
|
522
|
+
'--no-sandbox',
|
|
523
|
+
]);
|
|
524
|
+
}
|
|
525
|
+
// Direct facade consumers also use these; production host reads dispatch before full composition.
|
|
484
526
|
function createOperationalApplications(root) {
|
|
485
527
|
return {
|
|
486
528
|
init: async () => unsupportedOperationalCommand('init'),
|
|
@@ -511,12 +553,7 @@ function createOperationalApplications(root) {
|
|
|
511
553
|
await runSandboxSetup(createSandboxSetupDependencies(root.config.host.sandbox.containerHomeMountPath));
|
|
512
554
|
},
|
|
513
555
|
sandbox: async (arguments_) => {
|
|
514
|
-
await
|
|
515
|
-
// A manual sandbox replacement can recover a previously failed update,
|
|
516
|
-
// but never clear an in-progress self-update owned by another process.
|
|
517
|
-
if (arguments_[0] === 'update' &&
|
|
518
|
-
(await root.maintenance.read())?.phase === UpdateMaintenancePhase.Failed)
|
|
519
|
-
await root.maintenance.clear();
|
|
556
|
+
await runSandboxManagement(root, withoutOperationalWakeRoot(arguments_));
|
|
520
557
|
},
|
|
521
558
|
sandboxEntrypoint: async () => {
|
|
522
559
|
await runSandboxEntrypoint(createSandboxEntrypointDependencies(root));
|
|
@@ -732,7 +769,8 @@ async function checkMaintenanceLease(root, failures) {
|
|
|
732
769
|
const detail = lease.failure === undefined ? '' : ` (${lease.failure})`;
|
|
733
770
|
failures.push(`update maintenance lease is held in phase "${lease.phase}" since ${lease.startedAt}${detail} -- ` +
|
|
734
771
|
'every resident loop stays paused until it is cleared or resumes; run `wake self-update` ' +
|
|
735
|
-
'to retry, or
|
|
772
|
+
'to retry, or run `wake sandbox exec -- wake maintenance clear --failed --wake-root /wake --no-sandbox` ' +
|
|
773
|
+
'from the host if abandoning a failed sandbox update (without a sandbox, run `wake maintenance clear --failed` as the runtime-state owner)');
|
|
736
774
|
}
|
|
737
775
|
async function checkProviders(root, failures, notices) {
|
|
738
776
|
for (const provider of root.providers) {
|
|
@@ -820,12 +858,16 @@ function selfUpdateLoopInterval(arguments_) {
|
|
|
820
858
|
function withoutOperationalWakeRoot(arguments_) {
|
|
821
859
|
const result = [];
|
|
822
860
|
for (let index = 0; index < arguments_.length; index += 1) {
|
|
861
|
+
if (arguments_[index] === '--') {
|
|
862
|
+
result.push(...arguments_.slice(index));
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
823
865
|
if (arguments_[index] !== '--wake-root') {
|
|
824
866
|
result.push(arguments_[index]);
|
|
825
867
|
continue;
|
|
826
868
|
}
|
|
827
869
|
if (arguments_[index + 1] === undefined)
|
|
828
|
-
throw new Error('wake
|
|
870
|
+
throw new Error('wake command requires --wake-root <path>');
|
|
829
871
|
index += 1;
|
|
830
872
|
}
|
|
831
873
|
return result;
|
|
@@ -845,14 +887,17 @@ function optionalOperationalOption(arguments_, option) {
|
|
|
845
887
|
function unsupportedOperationalCommand(command) {
|
|
846
888
|
throw new Error(`wake ${command} has not been composed`);
|
|
847
889
|
}
|
|
890
|
+
function createStateHealth(root) {
|
|
891
|
+
return async () => {
|
|
892
|
+
await root.journal.readAll(0, 1);
|
|
893
|
+
await root.projections.list('work');
|
|
894
|
+
await root.checkpoints.load('surface-health');
|
|
895
|
+
return { journal: 'ok', projections: 'ok', checkpoints: 'ok' };
|
|
896
|
+
};
|
|
897
|
+
}
|
|
848
898
|
function createValidationApplications(root) {
|
|
849
899
|
return {
|
|
850
|
-
|
|
851
|
-
await root.journal.readAll(0, 1);
|
|
852
|
-
await root.projections.list('work');
|
|
853
|
-
await root.checkpoints.load('surface-health');
|
|
854
|
-
return { journal: 'ok', projections: 'ok', checkpoints: 'ok' };
|
|
855
|
-
},
|
|
900
|
+
health: createStateHealth(root),
|
|
856
901
|
async rebuildProjections() {
|
|
857
902
|
for (const definition of runtimeProjectionDefinitions)
|
|
858
903
|
await root.projectionSubscriptions.rebuild(definition);
|
|
@@ -985,3 +1030,19 @@ function runInteractive(command, arguments_) {
|
|
|
985
1030
|
});
|
|
986
1031
|
});
|
|
987
1032
|
}
|
|
1033
|
+
function createAuditApplication(root) {
|
|
1034
|
+
return {
|
|
1035
|
+
async read(id) {
|
|
1036
|
+
return (await root.journal.readAll(0))
|
|
1037
|
+
.filter((event) => event.stream.kind === WorkStreamKind.WorkItem && event.stream.id === id)
|
|
1038
|
+
.map((event) => ({
|
|
1039
|
+
eventId: event.event.eventId,
|
|
1040
|
+
eventType: event.event.eventType,
|
|
1041
|
+
occurredAt: event.event.occurredAt,
|
|
1042
|
+
stream: `${event.stream.kind}:${event.stream.id}`,
|
|
1043
|
+
causationId: event.event.causationId,
|
|
1044
|
+
correlationId: event.event.correlationId,
|
|
1045
|
+
}));
|
|
1046
|
+
},
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.87";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -3,8 +3,14 @@ import { type BreakdownReport, type ReportDefinition, type ReportQuery, type Tim
|
|
|
3
3
|
import type { RunView } from '../contracts/views.js';
|
|
4
4
|
export declare const RunReportId: {
|
|
5
5
|
readonly Outcomes: "run-outcomes-over-time";
|
|
6
|
+
readonly Usage: "token-and-cost-usage";
|
|
6
7
|
readonly Breakdown: "run-breakdowns-by-dimension";
|
|
7
8
|
};
|
|
9
|
+
export declare const RunUsageMeasure: {
|
|
10
|
+
readonly Tokens: "total-tokens";
|
|
11
|
+
readonly CostUsd: "total-cost-usd";
|
|
12
|
+
};
|
|
13
|
+
export declare function createRunUsageReport(journal: EventJournal): ReportDefinition;
|
|
8
14
|
export declare const RunReportDimension: {
|
|
9
15
|
readonly Action: "run-action";
|
|
10
16
|
readonly Stage: "run-stage";
|
|
@@ -37,5 +43,6 @@ export declare function createRunOutcomesReport(journal: EventJournal): ReportDe
|
|
|
37
43
|
export declare function queryRunAnalytics(journal: EventJournal, query: ReportQuery): Promise<{
|
|
38
44
|
report: TimeSeriesReport;
|
|
39
45
|
breakdown: BreakdownReport;
|
|
46
|
+
usage: TimeSeriesReport;
|
|
40
47
|
summary: RunSummary;
|
|
41
48
|
}>;
|
|
@@ -7,8 +7,24 @@ import { RunStatus } from '../contracts/vocabulary.js';
|
|
|
7
7
|
import { foldRunEvent } from '../domain/run.js';
|
|
8
8
|
export const RunReportId = defineClosedVocabulary({
|
|
9
9
|
Outcomes: 'run-outcomes-over-time',
|
|
10
|
+
Usage: 'token-and-cost-usage',
|
|
10
11
|
Breakdown: 'run-breakdowns-by-dimension',
|
|
11
12
|
});
|
|
13
|
+
export const RunUsageMeasure = defineClosedVocabulary({
|
|
14
|
+
Tokens: 'total-tokens',
|
|
15
|
+
CostUsd: 'total-cost-usd',
|
|
16
|
+
});
|
|
17
|
+
const usageSeries = [
|
|
18
|
+
{ id: RunUsageMeasure.Tokens, title: 'Total tokens', unit: 'tokens' },
|
|
19
|
+
{ id: RunUsageMeasure.CostUsd, title: 'Total cost (USD)', unit: 'USD' },
|
|
20
|
+
];
|
|
21
|
+
const usageDescriptor = { id: RunReportId.Usage, title: 'Token and cost usage' };
|
|
22
|
+
export function createRunUsageReport(journal) {
|
|
23
|
+
return {
|
|
24
|
+
...usageDescriptor,
|
|
25
|
+
query: async (query) => (await queryRunAnalytics(journal, query)).usage,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
12
28
|
export const RunReportDimension = defineClosedVocabulary({
|
|
13
29
|
Action: 'run-action',
|
|
14
30
|
Stage: 'run-stage',
|
|
@@ -70,24 +86,17 @@ export function createRunOutcomesReport(journal) {
|
|
|
70
86
|
};
|
|
71
87
|
}
|
|
72
88
|
export async function queryRunAnalytics(journal, query) {
|
|
73
|
-
const grouped =
|
|
74
|
-
for await (const event of scanJournal(journal, query.signal)) {
|
|
75
|
-
const owned = selectRunExecutionEvent(event);
|
|
76
|
-
if (owned === null)
|
|
77
|
-
continue;
|
|
78
|
-
grouped.set(owned.stream.id, foldRunEvent(grouped.get(owned.stream.id) ?? null, owned));
|
|
79
|
-
}
|
|
89
|
+
const grouped = await readRuns(journal, query);
|
|
80
90
|
const from = Date.parse(query.window.from);
|
|
81
91
|
const to = Date.parse(query.window.to);
|
|
82
92
|
const first = Math.floor(from / query.window.bucketMs) * query.window.bucketMs;
|
|
83
93
|
const zero = () => Object.fromEntries(series.map(({ id }) => [id, 0]));
|
|
84
|
-
const buckets =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
94
|
+
const buckets = outcomeBuckets(first, to, query.window.bucketMs);
|
|
95
|
+
const usageBuckets = buckets.map(({ from, to }) => ({
|
|
96
|
+
from,
|
|
97
|
+
to,
|
|
98
|
+
values: { [RunUsageMeasure.Tokens]: 0, [RunUsageMeasure.CostUsd]: 0 },
|
|
99
|
+
}));
|
|
91
100
|
const totals = zero();
|
|
92
101
|
const durations = [];
|
|
93
102
|
const counts = dimensions.map(() => new Map());
|
|
@@ -108,8 +117,13 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
108
117
|
groups.set(value, (groups.get(value) ?? 0) + 1);
|
|
109
118
|
});
|
|
110
119
|
const usage = agentTokenUsage(run.agent?.metadata);
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
const tokens = finiteOrZero(usage.tokens);
|
|
121
|
+
const cost = finiteOrZero(usage.costUsd);
|
|
122
|
+
totalTokens += tokens;
|
|
123
|
+
totalCostUsd += cost;
|
|
124
|
+
const bucket = usageBuckets[Math.floor((start - first) / query.window.bucketMs)];
|
|
125
|
+
bucket.values[RunUsageMeasure.Tokens] += tokens;
|
|
126
|
+
bucket.values[RunUsageMeasure.CostUsd] += cost;
|
|
113
127
|
const duration = runDuration(run);
|
|
114
128
|
if (duration !== null)
|
|
115
129
|
durations.push(duration);
|
|
@@ -123,18 +137,14 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
123
137
|
totals,
|
|
124
138
|
buckets,
|
|
125
139
|
},
|
|
126
|
-
|
|
127
|
-
report:
|
|
140
|
+
usage: {
|
|
141
|
+
report: usageDescriptor,
|
|
128
142
|
window: query.window,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
title,
|
|
133
|
-
rows: [...counts[index].entries()]
|
|
134
|
-
.sort(([a, ac], [b, bc]) => bc - ac || (a < b ? -1 : a > b ? 1 : 0))
|
|
135
|
-
.map(([value, count]) => ({ value, count, share: count / runs })),
|
|
136
|
-
})),
|
|
143
|
+
series: usageSeries,
|
|
144
|
+
totals: { [RunUsageMeasure.Tokens]: totalTokens, [RunUsageMeasure.CostUsd]: totalCostUsd },
|
|
145
|
+
buckets: usageBuckets,
|
|
137
146
|
},
|
|
147
|
+
breakdown: runBreakdown(query, runs, counts),
|
|
138
148
|
summary: {
|
|
139
149
|
runs,
|
|
140
150
|
completed: totals[RunReportOutcome.Completed],
|
|
@@ -155,3 +165,37 @@ function runDuration(run) {
|
|
|
155
165
|
const duration = Date.parse(run.finishedAt) - Date.parse(run.startedAt);
|
|
156
166
|
return Number.isFinite(duration) && duration >= 0 ? duration : null;
|
|
157
167
|
}
|
|
168
|
+
async function readRuns(journal, query) {
|
|
169
|
+
const grouped = new Map();
|
|
170
|
+
for await (const event of scanJournal(journal, query.signal)) {
|
|
171
|
+
const owned = selectRunExecutionEvent(event);
|
|
172
|
+
if (owned === null)
|
|
173
|
+
continue;
|
|
174
|
+
grouped.set(owned.stream.id, foldRunEvent(grouped.get(owned.stream.id) ?? null, owned));
|
|
175
|
+
}
|
|
176
|
+
return grouped;
|
|
177
|
+
}
|
|
178
|
+
function runBreakdown(query, runs, counts) {
|
|
179
|
+
return {
|
|
180
|
+
report: { id: RunReportId.Breakdown, title: 'Run breakdowns by dimension' },
|
|
181
|
+
window: query.window,
|
|
182
|
+
total: runs,
|
|
183
|
+
dimensions: dimensions.map(({ id, title }, index) => ({
|
|
184
|
+
id,
|
|
185
|
+
title,
|
|
186
|
+
rows: [...counts[index].entries()]
|
|
187
|
+
.sort(([a, ac], [b, bc]) => bc - ac || (a < b ? -1 : a > b ? 1 : 0))
|
|
188
|
+
.map(([value, count]) => ({ value, count, share: count / runs })),
|
|
189
|
+
})),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function outcomeBuckets(first, to, bucketMs) {
|
|
193
|
+
const buckets = [];
|
|
194
|
+
for (let start = first; start < to; start += bucketMs)
|
|
195
|
+
buckets.push({
|
|
196
|
+
from: new Date(start).toISOString(),
|
|
197
|
+
to: new Date(start + bucketMs).toISOString(),
|
|
198
|
+
values: Object.fromEntries(series.map(({ id }) => [id, 0])),
|
|
199
|
+
});
|
|
200
|
+
return buckets;
|
|
201
|
+
}
|
|
@@ -23,7 +23,9 @@ export interface ReportDescriptor {
|
|
|
23
23
|
export interface TimeSeriesReport {
|
|
24
24
|
readonly report: ReportDescriptor;
|
|
25
25
|
readonly window: ReportWindow;
|
|
26
|
-
readonly series: readonly ReportDescriptor
|
|
26
|
+
readonly series: readonly (ReportDescriptor & {
|
|
27
|
+
readonly unit?: string;
|
|
28
|
+
})[];
|
|
27
29
|
readonly totals: Readonly<Record<string, number>>;
|
|
28
30
|
readonly buckets: readonly {
|
|
29
31
|
readonly from: string;
|
package/dist/src/main.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { type CliOutput, type WakeCliApplications } from './surfaces/index.js';
|
|
2
|
+
import { type CliOutput, type WakeCliApplications, type WakeCommand } from './surfaces/index.js';
|
|
3
3
|
export interface TargetMainDependencies {
|
|
4
4
|
readonly compose: (wakeRoot: string) => Promise<WakeCliApplications>;
|
|
5
|
+
readonly runHostCommand?: (command: WakeCommand, wakeRoot: string, output: CliOutput) => Promise<boolean>;
|
|
5
6
|
readonly initialise?: (wakeRoot: string) => Promise<unknown>;
|
|
6
7
|
readonly sandboxRuntime?: SandboxRuntimeRouter;
|
|
7
8
|
readonly output: CliOutput;
|