Skip to main content

meerkat_workgraph/
lib.rs

1#![cfg_attr(target_arch = "wasm32", allow(unused_imports))]
2// The manual `WorkItem` JsonSchema impl (types.rs) expands a large
3// `schemars::json_schema!` literal; the default 128 recursion limit is too
4// small for the K21 inline composite shapes.
5#![recursion_limit = "256"]
6
7#[cfg(target_arch = "wasm32")]
8pub mod tokio {
9    pub use tokio_with_wasm::alias::*;
10}
11
12#[cfg(not(target_arch = "wasm32"))]
13pub use ::tokio;
14
15mod error;
16mod execution_machine;
17mod generated;
18mod machine;
19pub(crate) mod machines;
20mod rest_contract;
21mod service;
22mod store;
23mod surface;
24mod tool_surface;
25mod tools;
26mod types;
27
28pub use error::WorkGraphError;
29pub use execution_machine::{
30    WorkExecutionBindCommit, WorkExecutionLifecycleEffect, WorkExecutionLifecycleState,
31    WorkExecutionMachine, WorkExecutionObservation, WorkExecutionObservationCommit,
32    WorkExecutionTransition,
33};
34pub use machine::{WorkAttentionMachine, WorkGraphMachine, WorkGraphPublicErrorClass};
35pub use rest_contract::{
36    WORKGRAPH_REST_PATHS, WorkGraphRestOperationDescriptor, WorkGraphRestPathDescriptor,
37    WorkGraphRestRoute, workgraph_rest_path_catalog, workgraph_rest_request_response_schema,
38    workgraph_rest_response_schema,
39};
40pub use service::{WorkExecutionBridge, WorkGraphService};
41pub use store::{
42    DisabledWorkGraphStore, MemoryWorkGraphStore, WorkGraphEventFilter, WorkGraphStore,
43    WorkGraphStoreKind,
44};
45#[cfg(not(target_arch = "wasm32"))]
46pub use store::{SqliteWorkGraphStore, WORKGRAPH_DOMAIN, prepare_pre_0_8_10_workgraph_attention};
47pub use surface::wire_workgraph_tools;
48pub use tool_surface::{
49    WORKGRAPH_ATTENTION_DISPATCH_CONTEXT_KEY, WorkGraphToolSurface,
50    validate_workgraph_attention_projection_current, workgraph_attention_continuation_key,
51    workgraph_attention_projection_from_overlay, workgraph_attention_supersession_key,
52    workgraph_attention_turn_append,
53};
54pub use tools::{
55    WorkGraphToolError, WorkGraphToolErrorCode, handle_unscoped_workgraph_tools_call,
56    handle_workgraph_tools_call, unscoped_workgraph_tools_list, workgraph_tools_list,
57};
58pub use types::{
59    AddEvidenceRequest, AttentionBindingRequest, AttentionBindingResult,
60    AttentionContextProjection, AttentionContinueOutcome, AttentionContinueResult,
61    AttentionDelegatedAuthority, AttentionListRequest, AttentionListResult, AttentionPauseRequest,
62    AttentionProjectionPolicy, AttentionProjectionRequest, AttentionProjectionResult,
63    AttentionProjectionText, AttentionPruneRequest, AttentionPruneResult, AttentionReassignRequest,
64    AttentionReassignResult, AttentionResumeRequest, BreakGlassAttentionReassignRequest,
65    ClaimWorkItemRequest, CloseWorkItemRequest, CreateWorkItemRequest, ExternalWorkRef,
66    GoalAttentionTarget, GoalConfirmRequest, GoalConfirmResult, GoalCreateRequest,
67    GoalCreateResult, GoalRequestCloseRequest, GoalRequestCloseResult, GoalStatusRequest,
68    GoalStatusResult, GoalTerminalStatus, LinkWorkItemsRequest, PolicyEscalateRequest,
69    ProjectedAttentionAuthority, PublicGoalCompletionPolicy, PublicGoalCreateRequest,
70    PublicGoalRequestCloseRequest, ReadyWorkFilter, ReleaseWorkItemRequest, UpdateWorkItemRequest,
71    WorkAttentionBinding, WorkAttentionBindingId, WorkAttentionMachineState, WorkAttentionMode,
72    WorkAttentionStatus, WorkAttentionTarget, WorkClaim, WorkCompletionPolicy, WorkEdge,
73    WorkEdgeKind, WorkEvidenceKind, WorkEvidenceRef, WorkExecutionAuthority, WorkExecutionBinding,
74    WorkExecutionBindingFilter, WorkExecutionBindingId, WorkExecutionEvidenceKind,
75    WorkExecutionEvidenceProjection, WorkExecutionMachineState, WorkExecutionTarget,
76    WorkGraphEvent, WorkGraphEventKind, WorkGraphEventsResponse, WorkGraphIdParams,
77    WorkGraphItemsResponse, WorkGraphMachineState, WorkGraphSnapshot, WorkGraphSnapshotFilter,
78    WorkItem, WorkItemFilter, WorkItemId, WorkItemRef, WorkNamespace, WorkOwner, WorkOwnerKey,
79    WorkOwnerKind, WorkPriority, WorkStatus,
80};
81
82pub const WORKGRAPH_CAPABILITY_DISABLED_DESCRIPTION: &str =
83    "config.tools.workgraph_enabled is false";
84
85pub fn workgraph_capability_enabled(config: &meerkat_core::Config) -> bool {
86    config.tools.workgraph_enabled
87}
88
89pub const WORKGRAPH_CAPABILITY_POLICY: meerkat_capabilities::FeatureCapabilityPolicy =
90    meerkat_capabilities::FeatureCapabilityPolicy::new(
91        workgraph_capability_enabled,
92        WORKGRAPH_CAPABILITY_DISABLED_DESCRIPTION,
93    );
94
95pub const fn workgraph_capability_policy() -> meerkat_capabilities::FeatureCapabilityPolicy {
96    WORKGRAPH_CAPABILITY_POLICY
97}
98
99inventory::submit! {
100    meerkat_capabilities::CapabilityRegistration {
101        id: meerkat_capabilities::CapabilityId::WorkGraph,
102        description: "Realm-scoped dependency-aware durable work graph",
103        scope: meerkat_capabilities::CapabilityScope::Universal,
104        requires_feature: None,
105        prerequisites: &[],
106        status_resolver: Some(|config| {
107            let policy = crate::workgraph_capability_policy();
108            if policy.is_enabled(config) {
109                meerkat_capabilities::CapabilityStatus::Available
110            } else {
111                meerkat_capabilities::CapabilityStatus::DisabledByPolicy {
112                    description: policy.disabled_description().into(),
113                }
114            }
115        }),
116    }
117}
118
119#[cfg(feature = "skills")]
120inventory::submit! {
121    meerkat_skills::SkillRegistration {
122        id: "workgraph-workflow",
123        name: "WorkGraph Workflow",
124        description: "How to use WorkGraph for durable commitments, dependencies, claims, and evidence",
125        scope: meerkat_core::skills::SkillScope::Builtin,
126        requires_capabilities: &["work_graph"],
127        body: include_str!("../skills/workgraph-workflow/SKILL.md"),
128        extensions: &[],
129    }
130}
131
132#[doc(hidden)]
133#[cfg(feature = "machine-schema-exports")]
134pub mod machine_schema_exports {
135    pub fn workgraph_lifecycle_schema() -> meerkat_machine_schema::MachineSchema {
136        meerkat_machine_schema::catalog::dsl::workgraph_lifecycle_schema_metadata().attach_to(
137            crate::machines::workgraph_lifecycle::WorkGraphLifecycleMachineState::schema(),
138        )
139    }
140
141    pub fn work_attention_lifecycle_schema() -> meerkat_machine_schema::MachineSchema {
142        meerkat_machine_schema::catalog::dsl::work_attention_lifecycle_schema_metadata().attach_to(
143            crate::machines::work_attention_lifecycle::WorkAttentionLifecycleMachineState::schema(),
144        )
145    }
146}