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