@femtomc/mu-server 26.2.69 → 26.2.71

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 (58) hide show
  1. package/README.md +7 -3
  2. package/dist/api/activities.d.ts +2 -0
  3. package/dist/api/activities.js +160 -0
  4. package/dist/api/config.d.ts +2 -0
  5. package/dist/api/config.js +45 -0
  6. package/dist/api/control_plane.d.ts +2 -0
  7. package/dist/api/control_plane.js +28 -0
  8. package/dist/api/cron.d.ts +2 -0
  9. package/dist/api/cron.js +182 -0
  10. package/dist/api/events.js +77 -19
  11. package/dist/api/forum.js +52 -18
  12. package/dist/api/heartbeats.d.ts +2 -0
  13. package/dist/api/heartbeats.js +211 -0
  14. package/dist/api/identities.d.ts +2 -0
  15. package/dist/api/identities.js +103 -0
  16. package/dist/api/issues.js +120 -33
  17. package/dist/api/runs.d.ts +2 -0
  18. package/dist/api/runs.js +207 -0
  19. package/dist/cli.js +58 -3
  20. package/dist/config.d.ts +4 -21
  21. package/dist/config.js +24 -75
  22. package/dist/control_plane.d.ts +7 -114
  23. package/dist/control_plane.js +238 -654
  24. package/dist/control_plane_bootstrap_helpers.d.ts +16 -0
  25. package/dist/control_plane_bootstrap_helpers.js +85 -0
  26. package/dist/control_plane_contract.d.ts +176 -0
  27. package/dist/control_plane_contract.js +1 -0
  28. package/dist/control_plane_reload.d.ts +63 -0
  29. package/dist/control_plane_reload.js +525 -0
  30. package/dist/control_plane_run_outbox.d.ts +7 -0
  31. package/dist/control_plane_run_outbox.js +52 -0
  32. package/dist/control_plane_run_queue_coordinator.d.ts +48 -0
  33. package/dist/control_plane_run_queue_coordinator.js +327 -0
  34. package/dist/control_plane_telegram_generation.d.ts +27 -0
  35. package/dist/control_plane_telegram_generation.js +520 -0
  36. package/dist/control_plane_wake_delivery.d.ts +50 -0
  37. package/dist/control_plane_wake_delivery.js +123 -0
  38. package/dist/cron_request.d.ts +8 -0
  39. package/dist/cron_request.js +65 -0
  40. package/dist/index.d.ts +7 -2
  41. package/dist/index.js +4 -1
  42. package/dist/run_queue.d.ts +95 -0
  43. package/dist/run_queue.js +817 -0
  44. package/dist/run_supervisor.d.ts +20 -0
  45. package/dist/run_supervisor.js +25 -1
  46. package/dist/server.d.ts +12 -49
  47. package/dist/server.js +365 -2128
  48. package/dist/server_program_orchestration.d.ts +38 -0
  49. package/dist/server_program_orchestration.js +254 -0
  50. package/dist/server_routing.d.ts +31 -0
  51. package/dist/server_routing.js +230 -0
  52. package/dist/server_runtime.d.ts +30 -0
  53. package/dist/server_runtime.js +43 -0
  54. package/dist/server_types.d.ts +3 -0
  55. package/dist/server_types.js +16 -0
  56. package/dist/session_lifecycle.d.ts +11 -0
  57. package/dist/session_lifecycle.js +149 -0
  58. package/package.json +7 -6
@@ -0,0 +1,65 @@
1
+ export function parseCronTarget(body) {
2
+ const targetKind = typeof body.target_kind === "string" ? body.target_kind.trim().toLowerCase() : "";
3
+ if (targetKind === "run") {
4
+ const jobId = typeof body.run_job_id === "string" ? body.run_job_id.trim() : "";
5
+ const rootIssueId = typeof body.run_root_issue_id === "string" ? body.run_root_issue_id.trim() : "";
6
+ if (!jobId && !rootIssueId) {
7
+ return {
8
+ target: null,
9
+ error: "run target requires run_job_id or run_root_issue_id",
10
+ };
11
+ }
12
+ return {
13
+ target: {
14
+ kind: "run",
15
+ job_id: jobId || null,
16
+ root_issue_id: rootIssueId || null,
17
+ },
18
+ error: null,
19
+ };
20
+ }
21
+ if (targetKind === "activity") {
22
+ const activityId = typeof body.activity_id === "string" ? body.activity_id.trim() : "";
23
+ if (!activityId) {
24
+ return {
25
+ target: null,
26
+ error: "activity target requires activity_id",
27
+ };
28
+ }
29
+ return {
30
+ target: {
31
+ kind: "activity",
32
+ activity_id: activityId,
33
+ },
34
+ error: null,
35
+ };
36
+ }
37
+ return {
38
+ target: null,
39
+ error: "target_kind must be run or activity",
40
+ };
41
+ }
42
+ export function hasCronScheduleInput(body) {
43
+ return (body.schedule != null ||
44
+ body.schedule_kind != null ||
45
+ body.at_ms != null ||
46
+ body.at != null ||
47
+ body.every_ms != null ||
48
+ body.anchor_ms != null ||
49
+ body.expr != null ||
50
+ body.tz != null);
51
+ }
52
+ export function cronScheduleInputFromBody(body) {
53
+ if (body.schedule && typeof body.schedule === "object" && !Array.isArray(body.schedule)) {
54
+ return { ...body.schedule };
55
+ }
56
+ return {
57
+ kind: typeof body.schedule_kind === "string" ? body.schedule_kind : undefined,
58
+ at_ms: body.at_ms,
59
+ at: body.at,
60
+ every_ms: body.every_ms,
61
+ anchor_ms: body.anchor_ms,
62
+ expr: body.expr,
63
+ tz: body.tz,
64
+ };
65
+ }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,10 @@ export type { ControlPlaneActivityEvent, ControlPlaneActivityEventKind, ControlP
2
2
  export { ControlPlaneActivitySupervisor } from "./activity_supervisor.js";
3
3
  export type { MuConfig, MuConfigPatch, MuConfigPresence } from "./config.js";
4
4
  export { applyMuConfigPatch, DEFAULT_MU_CONFIG, getMuConfigPath, muConfigPresence, normalizeMuConfig, readMuConfigFile, redactMuConfigSecrets, writeMuConfigFile, } from "./config.js";
5
- export type { ActiveAdapter, ControlPlaneConfig, ControlPlaneHandle, ControlPlaneSessionLifecycle, ControlPlaneSessionMutationAction, ControlPlaneSessionMutationResult, } from "./control_plane.js";
5
+ export type { ActiveAdapter, ControlPlaneConfig, ControlPlaneHandle, ControlPlaneSessionLifecycle, ControlPlaneSessionMutationAction, ControlPlaneSessionMutationResult, InterRootQueuePolicy, NotifyOperatorsOpts, NotifyOperatorsResult, OrchestrationQueueState, WakeDeliveryEvent, WakeNotifyContext, WakeNotifyDecision, } from "./control_plane_contract.js";
6
+ export { DEFAULT_INTER_ROOT_QUEUE_POLICY, normalizeInterRootQueuePolicy, ORCHESTRATION_QUEUE_ALLOWED_TRANSITIONS, ORCHESTRATION_QUEUE_INVARIANTS, } from "./control_plane_contract.js";
7
+ export type { DurableRunQueueClaimOpts, DurableRunQueueEnqueueOpts, DurableRunQueueOpts, DurableRunQueueSnapshot, DurableRunQueueState, DurableRunQueueTransitionOpts, RunQueueReconcilePlan, } from "./run_queue.js";
8
+ export { DurableRunQueue, queueStatesForRunStatusFilter, reconcileRunQueue, RUN_QUEUE_RECONCILE_INVARIANTS, runQueuePath, runSnapshotFromQueueSnapshot, runStatusFromQueueState, } from "./run_queue.js";
6
9
  export { bootstrapControlPlane, detectAdapters } from "./control_plane.js";
7
10
  export type { CronProgramLifecycleAction, CronProgramLifecycleEvent, CronProgramOperationResult, CronProgramRegistryOpts, CronProgramSnapshot, CronProgramStatusSnapshot, CronProgramTarget, CronProgramTickEvent, CronProgramWakeMode, } from "./cron_programs.js";
8
11
  export { CronProgramRegistry } from "./cron_programs.js";
@@ -15,4 +18,6 @@ export { HeartbeatProgramRegistry } from "./heartbeat_programs.js";
15
18
  export type { ActivityHeartbeatSchedulerOpts, HeartbeatRunResult, HeartbeatTickHandler, } from "./heartbeat_scheduler.js";
16
19
  export { ActivityHeartbeatScheduler } from "./heartbeat_scheduler.js";
17
20
  export type { ServerContext, ServerInstanceOptions, ServerOptions, ServerRuntime, ServerRuntimeCapabilities, ServerRuntimeOptions, } from "./server.js";
18
- export { composeServerRuntime, createContext, createProcessSessionLifecycle, createServerFromRuntime, } from "./server.js";
21
+ export { composeServerRuntime, createContext, createServerFromRuntime } from "./server.js";
22
+ export type { ShellCommandResult, ShellCommandRunner } from "./session_lifecycle.js";
23
+ export { createProcessSessionLifecycle } from "./session_lifecycle.js";
package/dist/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  export { ControlPlaneActivitySupervisor } from "./activity_supervisor.js";
2
2
  export { applyMuConfigPatch, DEFAULT_MU_CONFIG, getMuConfigPath, muConfigPresence, normalizeMuConfig, readMuConfigFile, redactMuConfigSecrets, writeMuConfigFile, } from "./config.js";
3
+ export { DEFAULT_INTER_ROOT_QUEUE_POLICY, normalizeInterRootQueuePolicy, ORCHESTRATION_QUEUE_ALLOWED_TRANSITIONS, ORCHESTRATION_QUEUE_INVARIANTS, } from "./control_plane_contract.js";
4
+ export { DurableRunQueue, queueStatesForRunStatusFilter, reconcileRunQueue, RUN_QUEUE_RECONCILE_INVARIANTS, runQueuePath, runSnapshotFromQueueSnapshot, runStatusFromQueueState, } from "./run_queue.js";
3
5
  export { bootstrapControlPlane, detectAdapters } from "./control_plane.js";
4
6
  export { CronProgramRegistry } from "./cron_programs.js";
5
7
  export { computeNextScheduleRunAtMs, normalizeCronSchedule } from "./cron_schedule.js";
6
8
  export { CronTimerRegistry } from "./cron_timer.js";
7
9
  export { HeartbeatProgramRegistry } from "./heartbeat_programs.js";
8
10
  export { ActivityHeartbeatScheduler } from "./heartbeat_scheduler.js";
9
- export { composeServerRuntime, createContext, createProcessSessionLifecycle, createServerFromRuntime, } from "./server.js";
11
+ export { composeServerRuntime, createContext, createServerFromRuntime } from "./server.js";
12
+ export { createProcessSessionLifecycle } from "./session_lifecycle.js";
@@ -0,0 +1,95 @@
1
+ import type { JsonlStore } from "@femtomc/mu-core";
2
+ import { type InterRootQueuePolicy, type InterRootQueueReconcilePlan, type OrchestrationQueueState } from "@femtomc/mu-orchestrator";
3
+ import type { ControlPlaneRunMode, ControlPlaneRunSnapshot, ControlPlaneRunStatus } from "./run_supervisor.js";
4
+ export type DurableRunQueueState = OrchestrationQueueState;
5
+ export type DurableRunQueueSnapshot = {
6
+ v: 1;
7
+ queue_id: string;
8
+ dedupe_key: string;
9
+ mode: ControlPlaneRunMode;
10
+ state: DurableRunQueueState;
11
+ prompt: string | null;
12
+ root_issue_id: string | null;
13
+ max_steps: number;
14
+ command_id: string | null;
15
+ source: "command" | "api";
16
+ job_id: string | null;
17
+ started_at_ms: number | null;
18
+ updated_at_ms: number;
19
+ finished_at_ms: number | null;
20
+ exit_code: number | null;
21
+ pid: number | null;
22
+ last_progress: string | null;
23
+ created_at_ms: number;
24
+ revision: number;
25
+ applied_operation_ids: string[];
26
+ };
27
+ export type DurableRunQueueOpts = {
28
+ repoRoot: string;
29
+ nowMs?: () => number;
30
+ store?: JsonlStore<unknown>;
31
+ maxOperationIds?: number;
32
+ };
33
+ export type DurableRunQueueEnqueueOpts = {
34
+ mode: ControlPlaneRunMode;
35
+ prompt: string | null;
36
+ rootIssueId: string | null;
37
+ maxSteps?: number;
38
+ commandId?: string | null;
39
+ source: "command" | "api";
40
+ dedupeKey: string;
41
+ operationId?: string | null;
42
+ nowMs?: number;
43
+ };
44
+ export type DurableRunQueueTransitionOpts = {
45
+ queueId: string;
46
+ toState: DurableRunQueueState;
47
+ operationId?: string | null;
48
+ nowMs?: number;
49
+ };
50
+ export type DurableRunQueueClaimOpts = {
51
+ queueId?: string | null;
52
+ operationId?: string | null;
53
+ nowMs?: number;
54
+ };
55
+ export declare function runStatusFromQueueState(state: DurableRunQueueState): ControlPlaneRunStatus;
56
+ export declare function queueStatesForRunStatusFilter(status: string | null | undefined): DurableRunQueueState[] | null;
57
+ export type RunQueueReconcilePlan = InterRootQueueReconcilePlan;
58
+ export declare const RUN_QUEUE_RECONCILE_INVARIANTS: readonly ["ORCH-INTER-ROOT-RECON-001: one queue snapshot + policy yields one deterministic activation/launch plan.", "ORCH-INTER-ROOT-RECON-002: activation order is FIFO (`created_at_ms`, then `queue_id`) with per-root slot dedupe.", "ORCH-INTER-ROOT-RECON-003: sequential policy admits <=1 occupied root; parallel admits <=max_active_roots roots.", "ORCH-INTER-ROOT-RECON-004: launch candidates are active rows without bound job ids, one launch per root slot."];
59
+ /**
60
+ * Server adapter wrapper around the orchestrator-owned inter-root planner.
61
+ */
62
+ export declare function reconcileRunQueue(rows: readonly DurableRunQueueSnapshot[], policy: InterRootQueuePolicy): RunQueueReconcilePlan;
63
+ export declare function runQueuePath(repoRoot: string): string;
64
+ export declare function runSnapshotFromQueueSnapshot(queue: DurableRunQueueSnapshot, runtime?: ControlPlaneRunSnapshot | null): ControlPlaneRunSnapshot;
65
+ export declare class DurableRunQueue {
66
+ #private;
67
+ constructor(opts: DurableRunQueueOpts);
68
+ enqueue(opts: DurableRunQueueEnqueueOpts): Promise<DurableRunQueueSnapshot>;
69
+ claim(opts?: DurableRunQueueClaimOpts): Promise<DurableRunQueueSnapshot | null>;
70
+ activate(opts: DurableRunQueueClaimOpts): Promise<DurableRunQueueSnapshot | null>;
71
+ transition(opts: DurableRunQueueTransitionOpts): Promise<DurableRunQueueSnapshot>;
72
+ bindRunSnapshot(opts: {
73
+ queueId: string;
74
+ run: ControlPlaneRunSnapshot;
75
+ operationId?: string | null;
76
+ nowMs?: number;
77
+ }): Promise<DurableRunQueueSnapshot>;
78
+ applyRunSnapshot(opts: {
79
+ run: ControlPlaneRunSnapshot;
80
+ queueId?: string | null;
81
+ operationId?: string | null;
82
+ nowMs?: number;
83
+ createIfMissing?: boolean;
84
+ }): Promise<DurableRunQueueSnapshot | null>;
85
+ get(idOrRoot: string): Promise<DurableRunQueueSnapshot | null>;
86
+ list(opts?: {
87
+ states?: readonly DurableRunQueueState[];
88
+ limit?: number;
89
+ }): Promise<DurableRunQueueSnapshot[]>;
90
+ listRunSnapshots(opts?: {
91
+ status?: string;
92
+ limit?: number;
93
+ runtimeByJobId?: Map<string, ControlPlaneRunSnapshot>;
94
+ }): Promise<ControlPlaneRunSnapshot[]>;
95
+ }