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